Skip to content

Commit 884cbd7

Browse files
authoredFeb 18, 2025··
Create VertexAI Node CJS and ESM bundles (#8728)
* Create Node CJS and ESM bundles * Add changeset * Run formatter * register version with node
1 parent b92592d commit 884cbd7

File tree

4 files changed

+93
-23
lines changed

4 files changed

+93
-23
lines changed
 

‎.changeset/stale-llamas-hide.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@firebase/vertexai': patch
3+
---
4+
5+
Create Node CJS and ESM bundles.

‎packages/vertexai/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
".": {
1414
"types": "./dist/vertexai-public.d.ts",
1515
"node": {
16-
"require": "./dist/index.cjs.js",
17-
"import": "./dist/esm/index.esm2017.js"
16+
"require": "./dist/index.node.cjs.js",
17+
"import": "./dist/index.node.mjs"
1818
},
1919
"browser": {
2020
"require": "./dist/index.cjs.js",

‎packages/vertexai/rollup.config.js

+33-21
Original file line numberDiff line numberDiff line change
@@ -77,25 +77,37 @@ const browserBuilds = [
7777
}
7878
];
7979

80-
// const nodeBuilds = [
81-
// {
82-
// input: 'index.node.ts',
83-
// output: {
84-
// file: pkg.main,
85-
// format: 'cjs',
86-
// sourcemap: true
87-
// },
88-
// plugins: buildPlugins,
89-
// external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
90-
// },
91-
// {
92-
// input: 'index.node.ts',
93-
// output: [
94-
// { file: pkg.exports['.'].node.import, format: 'es', sourcemap: true }
95-
// ],
96-
// plugins: [...buildPlugins, emitModulePackageFile()],
97-
// external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
98-
// }
99-
// ];
80+
const nodeBuilds = [
81+
{
82+
input: 'src/index.node.ts',
83+
output: {
84+
file: pkg.exports['.'].node.import,
85+
format: 'es',
86+
sourcemap: true
87+
},
88+
plugins: [
89+
...buildPlugins,
90+
replace({
91+
...generateBuildTargetReplaceConfig('esm', 2017)
92+
})
93+
],
94+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
95+
},
96+
{
97+
input: 'src/index.node.ts',
98+
output: {
99+
file: pkg.exports['.'].node.require,
100+
format: 'cjs',
101+
sourcemap: true
102+
},
103+
plugins: [
104+
...buildPlugins,
105+
replace({
106+
...generateBuildTargetReplaceConfig('cjs', 2017)
107+
})
108+
],
109+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
110+
}
111+
];
100112

101-
export default [...browserBuilds];
113+
export default [...browserBuilds, ...nodeBuilds];

‎packages/vertexai/src/index.node.ts

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* The Vertex AI in Firebase Web SDK.
3+
*
4+
* @packageDocumentation
5+
*/
6+
7+
/**
8+
* @license
9+
* Copyright 2025 Google LLC
10+
*
11+
* Licensed under the Apache License, Version 2.0 (the "License");
12+
* you may not use this file except in compliance with the License.
13+
* You may obtain a copy of the License at
14+
*
15+
* http://www.apache.org/licenses/LICENSE-2.0
16+
*
17+
* Unless required by applicable law or agreed to in writing, software
18+
* distributed under the License is distributed on an "AS IS" BASIS,
19+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20+
* See the License for the specific language governing permissions and
21+
* limitations under the License.
22+
*/
23+
24+
import { registerVersion, _registerComponent } from '@firebase/app';
25+
import { VertexAIService } from './service';
26+
import { VERTEX_TYPE } from './constants';
27+
import { Component, ComponentType } from '@firebase/component';
28+
import { name, version } from '../package.json';
29+
30+
function registerVertex(): void {
31+
_registerComponent(
32+
new Component(
33+
VERTEX_TYPE,
34+
(container, { instanceIdentifier: location }) => {
35+
// getImmediate for FirebaseApp will always succeed
36+
const app = container.getProvider('app').getImmediate();
37+
const auth = container.getProvider('auth-internal');
38+
const appCheckProvider = container.getProvider('app-check-internal');
39+
return new VertexAIService(app, auth, appCheckProvider, { location });
40+
},
41+
ComponentType.PUBLIC
42+
).setMultipleInstances(true)
43+
);
44+
45+
registerVersion(name, version, 'node');
46+
// BUILD_TARGET will be replaced by values like esm2017, cjs2017, etc during the compilation
47+
registerVersion(name, version, '__BUILD_TARGET__');
48+
}
49+
50+
registerVertex();
51+
52+
export * from './api';
53+
export * from './public-types';

0 commit comments

Comments
 (0)
Please sign in to comment.