From 795150bfd0ec45894f9e1d600098f61d91f4c9cd Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Fri, 24 Jan 2025 10:54:44 -0500 Subject: [PATCH 1/4] Create Node CJS and ESM bundles --- packages/vertexai/package.json | 4 +-- packages/vertexai/rollup.config.js | 54 ++++++++++++++++++----------- packages/vertexai/src/index.node.ts | 53 ++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 23 deletions(-) create mode 100644 packages/vertexai/src/index.node.ts diff --git a/packages/vertexai/package.json b/packages/vertexai/package.json index 5acf318b6e4..42629b2098e 100644 --- a/packages/vertexai/package.json +++ b/packages/vertexai/package.json @@ -13,8 +13,8 @@ ".": { "types": "./dist/vertexai-public.d.ts", "node": { - "require": "./dist/index.cjs.js", - "import": "./dist/esm/index.esm2017.js" + "require": "./dist/index.node.cjs.js", + "import": "./dist/index.node.mjs" }, "browser": { "require": "./dist/index.cjs.js", diff --git a/packages/vertexai/rollup.config.js b/packages/vertexai/rollup.config.js index 3a1313a6bff..41e492df218 100644 --- a/packages/vertexai/rollup.config.js +++ b/packages/vertexai/rollup.config.js @@ -75,25 +75,37 @@ const browserBuilds = [ } ]; -// const nodeBuilds = [ -// { -// input: 'index.node.ts', -// output: { -// file: pkg.main, -// format: 'cjs', -// sourcemap: true -// }, -// plugins: buildPlugins, -// external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) -// }, -// { -// input: 'index.node.ts', -// output: [ -// { file: pkg.exports['.'].node.import, format: 'es', sourcemap: true } -// ], -// plugins: [...buildPlugins, emitModulePackageFile()], -// external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) -// } -// ]; +const nodeBuilds = [ + { + input: 'src/index.node.ts', + output: { + file: pkg.exports['.'].node.import, + format: 'es', + sourcemap: true + }, + plugins: [ + ...buildPlugins, + replace({ + ...generateBuildTargetReplaceConfig('esm', 2017), + }), + ], + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) + }, + { + input: 'src/index.node.ts', + output: { + file: pkg.exports['.'].node.require, + format: 'cjs', + sourcemap: true + }, + plugins: [ + ...buildPlugins, + replace({ + ...generateBuildTargetReplaceConfig('cjs', 2017), + }) + ], + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) + } +]; -export default [...browserBuilds]; +export default [...browserBuilds, ...nodeBuilds]; diff --git a/packages/vertexai/src/index.node.ts b/packages/vertexai/src/index.node.ts new file mode 100644 index 00000000000..f64783c87a4 --- /dev/null +++ b/packages/vertexai/src/index.node.ts @@ -0,0 +1,53 @@ +/** + * The Vertex AI in Firebase Web SDK. + * + * @packageDocumentation + */ + +/** + * @license + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { registerVersion, _registerComponent } from '@firebase/app'; +import { VertexAIService } from './service'; +import { VERTEX_TYPE } from './constants'; +import { Component, ComponentType } from '@firebase/component'; +import { name, version } from '../package.json'; + +function registerVertex(): void { + _registerComponent( + new Component( + VERTEX_TYPE, + (container, { instanceIdentifier: location }) => { + // getImmediate for FirebaseApp will always succeed + const app = container.getProvider('app').getImmediate(); + const auth = container.getProvider('auth-internal'); + const appCheckProvider = container.getProvider('app-check-internal'); + return new VertexAIService(app, auth, appCheckProvider, { location }); + }, + ComponentType.PUBLIC + ).setMultipleInstances(true) + ); + + registerVersion(name, version); + // BUILD_TARGET will be replaced by values like esm2017, cjs2017, etc during the compilation + registerVersion(name, version, '__BUILD_TARGET__'); +} + +registerVertex(); + +export * from './api'; +export * from './public-types'; From 72917d0dba81ddbb05b61c8c88a4f2625a036586 Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Fri, 24 Jan 2025 10:59:49 -0500 Subject: [PATCH 2/4] Add changeset --- .changeset/stale-llamas-hide.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/stale-llamas-hide.md diff --git a/.changeset/stale-llamas-hide.md b/.changeset/stale-llamas-hide.md new file mode 100644 index 00000000000..b46bcfb9885 --- /dev/null +++ b/.changeset/stale-llamas-hide.md @@ -0,0 +1,5 @@ +--- +'@firebase/vertexai': patch +--- + +Create Node CJS and ESM bundles. From 7e452ad513ab8707de724a80fd54acc54b90588c Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Fri, 24 Jan 2025 11:01:02 -0500 Subject: [PATCH 3/4] Run formatter --- packages/vertexai/rollup.config.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/vertexai/rollup.config.js b/packages/vertexai/rollup.config.js index 41e492df218..66375dfb4c8 100644 --- a/packages/vertexai/rollup.config.js +++ b/packages/vertexai/rollup.config.js @@ -86,22 +86,22 @@ const nodeBuilds = [ plugins: [ ...buildPlugins, replace({ - ...generateBuildTargetReplaceConfig('esm', 2017), - }), + ...generateBuildTargetReplaceConfig('esm', 2017) + }) ], external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) }, { input: 'src/index.node.ts', output: { - file: pkg.exports['.'].node.require, - format: 'cjs', - sourcemap: true - }, + file: pkg.exports['.'].node.require, + format: 'cjs', + sourcemap: true + }, plugins: [ ...buildPlugins, replace({ - ...generateBuildTargetReplaceConfig('cjs', 2017), + ...generateBuildTargetReplaceConfig('cjs', 2017) }) ], external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) From b56a6b3783f6a21c9b8fc0066c900475b0089418 Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Fri, 14 Feb 2025 14:07:12 -0500 Subject: [PATCH 4/4] register version with node --- packages/vertexai/src/index.node.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vertexai/src/index.node.ts b/packages/vertexai/src/index.node.ts index f64783c87a4..6a18788141a 100644 --- a/packages/vertexai/src/index.node.ts +++ b/packages/vertexai/src/index.node.ts @@ -42,7 +42,7 @@ function registerVertex(): void { ).setMultipleInstances(true) ); - registerVersion(name, version); + registerVersion(name, version, 'node'); // BUILD_TARGET will be replaced by values like esm2017, cjs2017, etc during the compilation registerVersion(name, version, '__BUILD_TARGET__'); }