diff --git a/.changeset/chatty-walls-wink.md b/.changeset/chatty-walls-wink.md new file mode 100644 index 00000000000..5b44d444780 --- /dev/null +++ b/.changeset/chatty-walls-wink.md @@ -0,0 +1,5 @@ +--- +'@firebase/util': patch +--- + +Set FirebaseError names to be the calling constructors name. diff --git a/.changeset/large-snakes-march.md b/.changeset/large-snakes-march.md new file mode 100644 index 00000000000..947d6e0b278 --- /dev/null +++ b/.changeset/large-snakes-march.md @@ -0,0 +1,6 @@ +--- +'firebase': major +'@firebase/vertexai': major +--- + +Release VertexAI in Firebase for general availability. diff --git a/.changeset/little-cows-tie.md b/.changeset/little-cows-tie.md new file mode 100644 index 00000000000..988329e2f0e --- /dev/null +++ b/.changeset/little-cows-tie.md @@ -0,0 +1,36 @@ +--- +'@firebase/installations-compat': patch +'@firebase/remote-config-compat': patch +'@firebase/performance-compat': patch +'@firebase/rules-unit-testing': patch +'@firebase/webchannel-wrapper': patch +'@firebase/analytics-compat': patch +'@firebase/app-check-compat': patch +'@firebase/firestore-compat': patch +'@firebase/functions-compat': patch +'@firebase/messaging-compat': patch +'@firebase/database-compat': patch +'@firebase/storage-compat': patch +'@firebase/installations': patch +'@firebase/remote-config': patch +'@firebase/auth-compat': patch +'@firebase/performance': patch +'@firebase/app-compat': patch +'@firebase/analytics': patch +'@firebase/app-check': patch +'@firebase/component': patch +'@firebase/firestore': patch +'@firebase/functions': patch +'@firebase/messaging': patch +'@firebase/database': patch +'firebase': patch +'@firebase/template': patch +'@firebase/vertexai-preview': patch +'@firebase/storage': patch +'@firebase/logger': patch +'@firebase/auth': patch +'@firebase/util': patch +'@firebase/app': patch +--- + +Remove ES5 bundles. The minimum required ES version is now ES2017. diff --git a/.changeset/plenty-beers-decide.md b/.changeset/plenty-beers-decide.md new file mode 100644 index 00000000000..87bc58c3589 --- /dev/null +++ b/.changeset/plenty-beers-decide.md @@ -0,0 +1,13 @@ +--- +'@firebase/rules-unit-testing': patch +'@firebase/firestore-compat': patch +'@firebase/functions-compat': patch +'@firebase/storage-compat': patch +'@firebase/auth-compat': patch +'@firebase/firestore': patch +'@firebase/functions': patch +'@firebase/storage': patch +'@firebase/auth': patch +--- + +Removed dependency on undici and node-fetch in our node bundles, replacing them with the native fetch implementation. diff --git a/.changeset/slimy-cups-promise.md b/.changeset/slimy-cups-promise.md new file mode 100644 index 00000000000..9456c0d5b04 --- /dev/null +++ b/.changeset/slimy-cups-promise.md @@ -0,0 +1,6 @@ +--- +'@firebase/functions-compat': patch +'@firebase/functions': patch +--- + +Remove node bundle from the functions SDK as the node-specific fetch code has been removed in favor of using native fetch throughout the SDK. diff --git a/.github/workflows/canary-deploy.yml b/.github/workflows/canary-deploy.yml index 74364b49cd5..c74bbc78762 100644 --- a/.github/workflows/canary-deploy.yml +++ b/.github/workflows/canary-deploy.yml @@ -70,7 +70,7 @@ jobs: NPM_TOKEN_STORAGE: ${{secrets.NPM_TOKEN_STORAGE}} NPM_TOKEN_STORAGE_TYPES: ${{secrets.NPM_TOKEN_STORAGE_TYPES}} NPM_TOKEN_UTIL: ${{secrets.NPM_TOKEN_UTIL}} - NPM_TOKEN_VERTEXAI_PREVIEW: ${{secrets.NPM_TOKEN_VERTEXAI_PREVIEW}} + NPM_TOKEN_VERTEXAI: ${{secrets.NPM_TOKEN_VERTEXAI}} NPM_TOKEN_WEBCHANNEL_WRAPPER: ${{secrets.NPM_TOKEN_WEBCHANNEL_WRAPPER}} NPM_TOKEN_FIREBASE: ${{secrets.NPM_TOKEN_FIREBASE}} NPM_TOKEN_APP_COMPAT: ${{ secrets.NPM_TOKEN_APP_COMPAT }} diff --git a/.github/workflows/prerelease-manual-deploy.yml b/.github/workflows/prerelease-manual-deploy.yml index a4a96f12e61..a5508db4709 100644 --- a/.github/workflows/prerelease-manual-deploy.yml +++ b/.github/workflows/prerelease-manual-deploy.yml @@ -73,7 +73,7 @@ jobs: NPM_TOKEN_STORAGE: ${{secrets.NPM_TOKEN_STORAGE}} NPM_TOKEN_STORAGE_TYPES: ${{secrets.NPM_TOKEN_STORAGE_TYPES}} NPM_TOKEN_UTIL: ${{secrets.NPM_TOKEN_UTIL}} - NPM_TOKEN_VERTEXAI_PREVIEW: ${{secrets.NPM_TOKEN_VERTEXAI_PREVIEW}} + NPM_TOKEN_VERTEXAI: ${{secrets.NPM_TOKEN_VERTEXAI}} NPM_TOKEN_WEBCHANNEL_WRAPPER: ${{secrets.NPM_TOKEN_WEBCHANNEL_WRAPPER}} NPM_TOKEN_FIREBASE: ${{secrets.NPM_TOKEN_FIREBASE}} NPM_TOKEN_APP_COMPAT: ${{ secrets.NPM_TOKEN_APP_COMPAT }} diff --git a/.github/workflows/release-prod.yml b/.github/workflows/release-prod.yml index 910938c3903..0ff1a0b2185 100644 --- a/.github/workflows/release-prod.yml +++ b/.github/workflows/release-prod.yml @@ -83,7 +83,7 @@ jobs: NPM_TOKEN_STORAGE: ${{secrets.NPM_TOKEN_STORAGE}} NPM_TOKEN_STORAGE_TYPES: ${{secrets.NPM_TOKEN_STORAGE_TYPES}} NPM_TOKEN_UTIL: ${{secrets.NPM_TOKEN_UTIL}} - NPM_TOKEN_VERTEXAI_PREVIEW: ${{secrets.NPM_TOKEN_VERTEXAI_PREVIEW}} + NPM_TOKEN_VERTEXAI: ${{secrets.NPM_TOKEN_VERTEXAI}} NPM_TOKEN_WEBCHANNEL_WRAPPER: ${{secrets.NPM_TOKEN_WEBCHANNEL_WRAPPER}} NPM_TOKEN_FIREBASE: ${{secrets.NPM_TOKEN_FIREBASE}} NPM_TOKEN_APP_COMPAT: ${{ secrets.NPM_TOKEN_APP_COMPAT }} diff --git a/.github/workflows/release-staging.yml b/.github/workflows/release-staging.yml index ee8eee1c0d1..3aa2716b5e2 100644 --- a/.github/workflows/release-staging.yml +++ b/.github/workflows/release-staging.yml @@ -109,7 +109,7 @@ jobs: NPM_TOKEN_STORAGE: ${{secrets.NPM_TOKEN_STORAGE}} NPM_TOKEN_STORAGE_TYPES: ${{secrets.NPM_TOKEN_STORAGE_TYPES}} NPM_TOKEN_UTIL: ${{secrets.NPM_TOKEN_UTIL}} - NPM_TOKEN_VERTEXAI_PREVIEW: ${{secrets.NPM_TOKEN_VERTEXAI_PREVIEW}} + NPM_TOKEN_VERTEXAI: ${{secrets.NPM_TOKEN_VERTEXAI}} NPM_TOKEN_WEBCHANNEL_WRAPPER: ${{secrets.NPM_TOKEN_WEBCHANNEL_WRAPPER}} NPM_TOKEN_FIREBASE: ${{secrets.NPM_TOKEN_FIREBASE}} NPM_TOKEN_APP_COMPAT: ${{ secrets.NPM_TOKEN_APP_COMPAT }} diff --git a/common/api-review/util.api.md b/common/api-review/util.api.md index 91d2f04cb40..99b78c47904 100644 --- a/common/api-review/util.api.md +++ b/common/api-review/util.api.md @@ -213,7 +213,6 @@ export class FirebaseError extends Error { customData?: Record | undefined); readonly code: string; customData?: Record | undefined; - readonly name: string; } // Warning: (ae-missing-release-tag) "FirebaseSignInProvider" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) diff --git a/common/api-review/vertexai-preview.api.md b/common/api-review/vertexai.api.md similarity index 81% rename from common/api-review/vertexai-preview.api.md rename to common/api-review/vertexai.api.md index c965bdde432..a3f7b30b994 100644 --- a/common/api-review/vertexai-preview.api.md +++ b/common/api-review/vertexai.api.md @@ -1,4 +1,4 @@ -## API Report File for "@firebase/vertexai-preview" +## API Report File for "@firebase/vertexai" > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). @@ -9,6 +9,15 @@ import { FirebaseApp } from '@firebase/app'; import { FirebaseAuthTokenData } from '@firebase/auth-interop-types'; import { FirebaseError } from '@firebase/util'; +// @public +export class ArraySchema extends Schema { + constructor(schemaParams: SchemaParams, items: TypedSchema); + // (undocumented) + items: TypedSchema; + // @internal (undocumented) + toJSON(): SchemaRequest; +} + // @public export interface BaseParams { // (undocumented) @@ -19,14 +28,17 @@ export interface BaseParams { // @public export enum BlockReason { - // (undocumented) - BLOCKED_REASON_UNSPECIFIED = "BLOCKED_REASON_UNSPECIFIED", // (undocumented) OTHER = "OTHER", // (undocumented) SAFETY = "SAFETY" } +// @public +export class BooleanSchema extends Schema { + constructor(schemaParams?: SchemaParams); +} + // @public export class ChatSession { // Warning: (ae-forgotten-export) The symbol "ApiSettings" needs to be exported by the entry point index.d.ts @@ -145,8 +157,6 @@ export interface FileDataPart { // @public export enum FinishReason { - // (undocumented) - FINISH_REASON_UNSPECIFIED = "FINISH_REASON_UNSPECIFIED", // (undocumented) MAX_TOKENS = "MAX_TOKENS", // (undocumented) @@ -182,8 +192,6 @@ export enum FunctionCallingMode { // (undocumented) AUTO = "AUTO", // (undocumented) - MODE_UNSPECIFIED = "MODE_UNSPECIFIED", - // (undocumented) NONE = "NONE" } @@ -201,44 +209,9 @@ export interface FunctionCallPart { // @public export interface FunctionDeclaration { - description?: string; + description: string; name: string; - parameters?: FunctionDeclarationSchema; -} - -// @public -export interface FunctionDeclarationSchema { - description?: string; - properties: { - [k: string]: FunctionDeclarationSchemaProperty; - }; - required?: string[]; - type: FunctionDeclarationSchemaType; -} - -// @public -export interface FunctionDeclarationSchemaProperty { - description?: string; - enum?: string[]; - example?: unknown; - format?: string; - items?: FunctionDeclarationSchema; - nullable?: boolean; - properties?: { - [k: string]: FunctionDeclarationSchema; - }; - required?: string[]; - type?: FunctionDeclarationSchemaType; -} - -// @public -export enum FunctionDeclarationSchemaType { - ARRAY = "ARRAY", - BOOLEAN = "BOOLEAN", - INTEGER = "INTEGER", - NUMBER = "NUMBER", - OBJECT = "OBJECT", - STRING = "STRING" + parameters?: ObjectSchemaInterface; } // @public @@ -331,6 +304,7 @@ export interface GenerationConfig { // (undocumented) presencePenalty?: number; responseMimeType?: string; + responseSchema?: TypedSchema | SchemaRequest; // (undocumented) stopSequences?: string[]; // (undocumented) @@ -401,8 +375,6 @@ export interface GroundingMetadata { // @public (undocumented) export enum HarmBlockMethod { - // (undocumented) - HARM_BLOCK_METHOD_UNSPECIFIED = "HARM_BLOCK_METHOD_UNSPECIFIED", // (undocumented) PROBABILITY = "PROBABILITY", // (undocumented) @@ -418,9 +390,7 @@ export enum HarmBlockThreshold { // (undocumented) BLOCK_NONE = "BLOCK_NONE", // (undocumented) - BLOCK_ONLY_HIGH = "BLOCK_ONLY_HIGH", - // (undocumented) - HARM_BLOCK_THRESHOLD_UNSPECIFIED = "HARM_BLOCK_THRESHOLD_UNSPECIFIED" + BLOCK_ONLY_HIGH = "BLOCK_ONLY_HIGH" } // @public @@ -432,15 +402,11 @@ export enum HarmCategory { // (undocumented) HARM_CATEGORY_HATE_SPEECH = "HARM_CATEGORY_HATE_SPEECH", // (undocumented) - HARM_CATEGORY_SEXUALLY_EXPLICIT = "HARM_CATEGORY_SEXUALLY_EXPLICIT", - // (undocumented) - HARM_CATEGORY_UNSPECIFIED = "HARM_CATEGORY_UNSPECIFIED" + HARM_CATEGORY_SEXUALLY_EXPLICIT = "HARM_CATEGORY_SEXUALLY_EXPLICIT" } // @public export enum HarmProbability { - // (undocumented) - HARM_PROBABILITY_UNSPECIFIED = "HARM_PROBABILITY_UNSPECIFIED", // (undocumented) HIGH = "HIGH", // (undocumented) @@ -460,9 +426,7 @@ export enum HarmSeverity { // (undocumented) HARM_SEVERITY_MEDIUM = "HARM_SEVERITY_MEDIUM", // (undocumented) - HARM_SEVERITY_NEGLIGIBLE = "HARM_SEVERITY_NEGLIGIBLE", - // (undocumented) - HARM_SEVERITY_UNSPECIFIED = "HARM_SEVERITY_UNSPECIFIED" + HARM_SEVERITY_NEGLIGIBLE = "HARM_SEVERITY_NEGLIGIBLE" } // @public @@ -478,6 +442,11 @@ export interface InlineDataPart { videoMetadata?: VideoMetadata; } +// @public +export class IntegerSchema extends Schema { + constructor(schemaParams?: SchemaParams); +} + // @public export interface ModelParams extends BaseParams { // (undocumented) @@ -490,6 +459,34 @@ export interface ModelParams extends BaseParams { tools?: Tool[]; } +// @public +export class NumberSchema extends Schema { + constructor(schemaParams?: SchemaParams); +} + +// @public +export class ObjectSchema extends Schema { + constructor(schemaParams: SchemaParams, properties: { + [k: string]: TypedSchema; + }, optionalProperties?: string[]); + // (undocumented) + optionalProperties: string[]; + // (undocumented) + properties: { + [k: string]: TypedSchema; + }; + // @internal (undocumented) + toJSON(): SchemaRequest; +} + +// @public +export interface ObjectSchemaInterface extends SchemaInterface { + // (undocumented) + optionalProperties?: string[]; + // (undocumented) + type: SchemaType.OBJECT; +} + // @public export type Part = TextPart | InlineDataPart | FunctionCallPart | FunctionResponsePart | FileDataPart; @@ -499,7 +496,7 @@ export const POSSIBLE_ROLES: readonly ["user", "model", "function", "system"]; // @public export interface PromptFeedback { // (undocumented) - blockReason: BlockReason; + blockReason?: BlockReason; // (undocumented) blockReasonMessage?: string; // (undocumented) @@ -549,6 +546,82 @@ export interface SafetySetting { threshold: HarmBlockThreshold; } +// @public +export abstract class Schema implements SchemaInterface { + constructor(schemaParams: SchemaInterface); + [key: string]: unknown; + // (undocumented) + static array(arrayParams: SchemaParams & { + items: Schema; + }): ArraySchema; + // (undocumented) + static boolean(booleanParams?: SchemaParams): BooleanSchema; + description?: string; + // (undocumented) + static enumString(stringParams: SchemaParams & { + enum: string[]; + }): StringSchema; + example?: unknown; + format?: string; + // (undocumented) + static integer(integerParams?: SchemaParams): IntegerSchema; + nullable: boolean; + // (undocumented) + static number(numberParams?: SchemaParams): NumberSchema; + // (undocumented) + static object(objectParams: SchemaParams & { + properties: { + [k: string]: Schema; + }; + optionalProperties?: string[]; + }): ObjectSchema; + // (undocumented) + static string(stringParams?: SchemaParams): StringSchema; + // @internal + toJSON(): SchemaRequest; + type: SchemaType; +} + +// @public +export interface SchemaInterface extends SchemaShared { + type: SchemaType; +} + +// @public +export interface SchemaParams extends SchemaShared { +} + +// @public +export interface SchemaRequest extends SchemaShared { + required?: string[]; + type: SchemaType; +} + +// @public +export interface SchemaShared { + // (undocumented) + [key: string]: unknown; + description?: string; + enum?: string[]; + example?: unknown; + format?: string; + items?: T; + nullable?: boolean; + properties?: { + [k: string]: T; + }; +} + +// @public +export enum SchemaType { + ARRAY = "array", + BOOLEAN = "boolean", + INTEGER = "integer", + NUMBER = "number", + OBJECT = "object", + STRING = "string" +} + // @public (undocumented) export interface Segment { // (undocumented) @@ -571,6 +644,15 @@ export interface StartChatParams extends BaseParams { tools?: Tool[]; } +// @public +export class StringSchema extends Schema { + constructor(schemaParams?: SchemaParams, enumValues?: string[]); + // (undocumented) + enum?: string[]; + // @internal (undocumented) + toJSON(): SchemaRequest; +} + // @public export interface TextPart { // (undocumented) @@ -589,9 +671,12 @@ export type Tool = FunctionDeclarationsTool; // @public export interface ToolConfig { // (undocumented) - functionCallingConfig: FunctionCallingConfig; + functionCallingConfig?: FunctionCallingConfig; } +// @public +export type TypedSchema = IntegerSchema | NumberSchema | StringSchema | BooleanSchema | ObjectSchema | ArraySchema; + // @public export interface UsageMetadata { // (undocumented) @@ -616,15 +701,15 @@ export class VertexAIError extends FirebaseError { readonly code: VertexAIErrorCode; // (undocumented) readonly customErrorData?: CustomErrorData | undefined; - // (undocumented) - readonly message: string; } // @public export const enum VertexAIErrorCode { + API_NOT_ENABLED = "api-not-enabled", ERROR = "error", FETCH_ERROR = "fetch-error", INVALID_CONTENT = "invalid-content", + INVALID_SCHEMA = "invalid-schema", NO_API_KEY = "no-api-key", NO_MODEL = "no-model", NO_PROJECT_ID = "no-project-id", diff --git a/config/functions/package.json b/config/functions/package.json index 08a79673e85..9a032e8bb95 100644 --- a/config/functions/package.json +++ b/config/functions/package.json @@ -8,6 +8,6 @@ }, "private": true, "engines": { - "node": "16" + "node": ">=18.0.0" } } diff --git a/config/tsconfig.base.json b/config/tsconfig.base.json index 0bfe24208a8..adbd2e44072 100644 --- a/config/tsconfig.base.json +++ b/config/tsconfig.base.json @@ -5,24 +5,16 @@ "importHelpers": true, "strict": true, "lib": [ - "es5", "dom", - "es2015.promise", - "es2015.symbol", - "es2015.iterable", - "es2015.collection", - "es2015.symbol.wellknown", - "es2015.core", - "es2017.object", - "es2017.string", - "ESNext.WeakRef", + "es2017", + "esnext.WeakRef", ], "module": "ES2015", "moduleResolution": "node", "resolveJsonModule": true, "esModuleInterop": true, "sourceMap": true, - "target": "es5", + "target": "es2017", "typeRoots": [ "../node_modules/@types" ], diff --git a/e2e/karma.conf.js b/e2e/karma.conf.js index 80824d6d548..fb2474f3beb 100644 --- a/e2e/karma.conf.js +++ b/e2e/karma.conf.js @@ -82,7 +82,7 @@ module.exports = function (config) { 'resolveJsonModule': true, 'esModuleInterop': true, 'sourceMap': true, - 'target': 'es5', + 'target': 'es2017', 'importHelpers': true, 'noEmitOnError': true } diff --git a/e2e/package.json b/e2e/package.json index 54a4ca3f292..676498d6142 100644 --- a/e2e/package.json +++ b/e2e/package.json @@ -38,5 +38,8 @@ "webpack": "5.76.0", "webpack-cli": "4.10.0", "webpack-dev-server": "4.11.1" + }, + "engines": { + "node": ">=18.0.0" } } diff --git a/integration/compat-interop/package.json b/integration/compat-interop/package.json index 3491521aadd..2090a7e91b8 100644 --- a/integration/compat-interop/package.json +++ b/integration/compat-interop/package.json @@ -25,5 +25,8 @@ }, "devDependencies": { "typescript": "4.7.4" + }, + "engines": { + "node": ">=18.0.0" } } diff --git a/integration/compat-interop/tsconfig.json b/integration/compat-interop/tsconfig.json index 4da78214594..735f3df7fbd 100644 --- a/integration/compat-interop/tsconfig.json +++ b/integration/compat-interop/tsconfig.json @@ -8,7 +8,7 @@ "moduleResolution": "node", "noImplicitAny": true, "outDir": "dist", - "target": "ES5", + "target": "es2017", "sourceMap": true, "esModuleInterop": true }, diff --git a/integration/compat-typings/package.json b/integration/compat-typings/package.json index 11639312c27..9c0802f888d 100644 --- a/integration/compat-typings/package.json +++ b/integration/compat-typings/package.json @@ -11,5 +11,8 @@ }, "devDependencies": { "typescript": "4.7.4" + }, + "engines": { + "node": ">=18.0.0" } -} \ No newline at end of file +} diff --git a/integration/firebase/package.json b/integration/firebase/package.json index 5dfd652a2a2..a12e233adc7 100644 --- a/integration/firebase/package.json +++ b/integration/firebase/package.json @@ -21,5 +21,8 @@ "mocha": "9.2.2", "npm-run-all": "4.1.5", "typescript": "4.7.4" + }, + "engines": { + "node": ">=18.0.0" } } diff --git a/integration/firebase/tsconfig.json b/integration/firebase/tsconfig.json index 4da78214594..735f3df7fbd 100644 --- a/integration/firebase/tsconfig.json +++ b/integration/firebase/tsconfig.json @@ -8,7 +8,7 @@ "moduleResolution": "node", "noImplicitAny": true, "outDir": "dist", - "target": "ES5", + "target": "es2017", "sourceMap": true, "esModuleInterop": true }, diff --git a/integration/firestore/package.json b/integration/firestore/package.json index c2019dcc442..256569ac012 100644 --- a/integration/firestore/package.json +++ b/integration/firestore/package.json @@ -32,5 +32,8 @@ "typescript": "4.2.2", "webpack": "5.76.0", "webpack-stream": "7.0.0" + }, + "engines": { + "node": ">=18.0.0" } } diff --git a/integration/messaging/package.json b/integration/messaging/package.json index 3431c913b15..d36f0844b9a 100644 --- a/integration/messaging/package.json +++ b/integration/messaging/package.json @@ -15,7 +15,9 @@ "express": "4.19.2", "geckodriver": "2.0.4", "mocha": "9.2.2", - "undici": "6.19.7", "selenium-assistant": "6.1.1" + }, + "engines": { + "node": ">=18.0.0" } } diff --git a/integration/messaging/test/utils/sendMessage.js b/integration/messaging/test/utils/sendMessage.js index 1d2e95054eb..6393e90364c 100644 --- a/integration/messaging/test/utils/sendMessage.js +++ b/integration/messaging/test/utils/sendMessage.js @@ -15,7 +15,6 @@ * limitations under the License. */ -const undici = require('undici'); const FCM_SEND_ENDPOINT = 'https://fcm.googleapis.com/fcm/send'; // Rotatable fcm server key. It's generally a bad idea to expose server keys. The reason is to // simplify testing process (no need to implement server side decryption of git secret). The @@ -28,7 +27,7 @@ module.exports = async payload => { 'Requesting to send an FCM message with payload: ' + JSON.stringify(payload) ); - const response = await undici.fetch(FCM_SEND_ENDPOINT, { + const response = await fetch(FCM_SEND_ENDPOINT, { method: 'POST', body: JSON.stringify(payload), headers: { diff --git a/package.json b/package.json index 7c65287bb20..1d4115799a7 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "author": "Firebase (https://firebase.google.com/)", "license": "Apache-2.0", "engines": { - "node": "^8.13.0 || >=10.10.0" + "node": ">=18.0.0" }, "homepage": "https://github.com/firebase/firebase-js-sdk", "keywords": [ @@ -156,7 +156,6 @@ "tslint": "6.1.3", "typedoc": "0.16.11", "typescript": "4.7.4", - "undici": "6.19.7", "watch": "1.0.2", "webpack": "5.76.0", "yargs": "17.7.2" diff --git a/packages/analytics-compat/package.json b/packages/analytics-compat/package.json index 861e5baf519..62fa41c2029 100644 --- a/packages/analytics-compat/package.json +++ b/packages/analytics-compat/package.json @@ -6,12 +6,10 @@ "main": "dist/index.cjs.js", "browser": "dist/esm/index.esm2017.js", "module": "dist/esm/index.esm2017.js", - "esm5": "dist/esm/index.esm.js", "exports": { ".": { "types": "./dist/src/index.d.ts", "require": "./dist/index.cjs.js", - "esm5": "./dist/esm/index.esm.js", "default": "./dist/esm/index.esm2017.js" }, "./package.json": "./package.json" diff --git a/packages/analytics-compat/rollup.config.js b/packages/analytics-compat/rollup.config.js index 0fccfa7a26c..49b8ac0d21e 100644 --- a/packages/analytics-compat/rollup.config.js +++ b/packages/analytics-compat/rollup.config.js @@ -25,51 +25,33 @@ const deps = Object.keys( Object.assign({}, pkg.peerDependencies, pkg.dependencies) ); -const es5BuildPlugins = [ +const buildPlugins = [ typescriptPlugin({ typescript }), - json() -]; - -const es2017BuildPlugins = [ - typescriptPlugin({ - typescript, - tsconfigOverride: { - compilerOptions: { - target: 'es2017' - } - } - }), json({ preferConst: true }) ]; -const esmBuilds = [ - { - input: 'src/index.ts', - output: { - file: pkg.browser, - format: 'es', - sourcemap: true - }, - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), - plugins: [...es2017BuildPlugins, emitModulePackageFile()] +const esmBuild = { + input: 'src/index.ts', + output: { + file: pkg.browser, + format: 'es', + sourcemap: true }, - { - input: 'src/index.ts', - output: { file: pkg.esm5, format: 'es', sourcemap: true }, - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), - plugins: [...es5BuildPlugins, emitModulePackageFile()] - } -]; + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), + plugins: [...buildPlugins, emitModulePackageFile()] +}; -const cjsBuilds = [ - { - input: 'src/index.ts', - output: { file: pkg.main, format: 'cjs', sourcemap: true }, - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), - plugins: es5BuildPlugins - } -]; +const cjsBuild = { + input: 'src/index.ts', + output: { + file: pkg.main, + format: 'cjs', + sourcemap: true + }, + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), + plugins: buildPlugins +}; -export default [...esmBuilds, ...cjsBuilds]; +export default [esmBuild, cjsBuild]; diff --git a/packages/analytics/package.json b/packages/analytics/package.json index 590ba9c6640..57b08f0e84a 100644 --- a/packages/analytics/package.json +++ b/packages/analytics/package.json @@ -6,12 +6,10 @@ "main": "dist/index.cjs.js", "browser": "dist/esm/index.esm2017.js", "module": "dist/esm/index.esm2017.js", - "esm5": "dist/esm/index.esm.js", "exports": { ".": { "types": "./dist/analytics-public.d.ts", "require": "./dist/index.cjs.js", - "esm5": "./dist/esm/index.esm.js", "default": "./dist/esm/index.esm2017.js" }, "./package.json": "./package.json" diff --git a/packages/analytics/rollup.config.js b/packages/analytics/rollup.config.js index 509b9690c5e..6acafe03b5d 100644 --- a/packages/analytics/rollup.config.js +++ b/packages/analytics/rollup.config.js @@ -27,22 +27,10 @@ const deps = [ ...Object.keys(Object.assign({}, pkg.peerDependencies, pkg.dependencies)) ]; -const es5BuildPlugins = [ +const buildPlugins = [ typescriptPlugin({ typescript }), - json() -]; - -const es2017BuildPlugins = [ - typescriptPlugin({ - typescript, - tsconfigOverride: { - compilerOptions: { - target: 'es2017' - } - } - }), json({ preferConst: true }) ]; @@ -50,16 +38,6 @@ const es2017BuildPlugins = [ * ESM builds */ const esmBuilds = [ - { - input: 'src/index.ts', - output: [{ file: pkg.esm5, format: 'es', sourcemap: true }], - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), - plugins: [ - ...es5BuildPlugins, - replace(generateBuildTargetReplaceConfig('esm', 5)), - emitModulePackageFile() - ] - }, { input: 'src/index.ts', output: { @@ -69,7 +47,7 @@ const esmBuilds = [ }, external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), plugins: [ - ...es2017BuildPlugins, + ...buildPlugins, replace(generateBuildTargetReplaceConfig('esm', 2017)), emitModulePackageFile() ] @@ -82,11 +60,15 @@ const esmBuilds = [ const cjsBuilds = [ { input: 'src/index.ts', - output: [{ file: pkg.main, format: 'cjs', sourcemap: true }], + output: { + file: pkg.main, + format: 'cjs', + sourcemap: true + }, external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), plugins: [ - ...es5BuildPlugins, - replace(generateBuildTargetReplaceConfig('cjs', 5)) + ...buildPlugins, + replace(generateBuildTargetReplaceConfig('cjs', 2017)) ] } ]; diff --git a/packages/analytics/src/index.ts b/packages/analytics/src/index.ts index ed785fba94b..f79725db7bd 100644 --- a/packages/analytics/src/index.ts +++ b/packages/analytics/src/index.ts @@ -66,7 +66,7 @@ function registerAnalytics(): void { ); registerVersion(name, version); - // BUILD_TARGET will be replaced by values like esm5, esm2017, cjs5, etc during the compilation + // BUILD_TARGET will be replaced by values like esm2017, cjs2017, etc during the compilation registerVersion(name, version, '__BUILD_TARGET__'); function internalFactory( diff --git a/packages/app-check-compat/package.json b/packages/app-check-compat/package.json index 8fa928c7c35..464f9e36c25 100644 --- a/packages/app-check-compat/package.json +++ b/packages/app-check-compat/package.json @@ -6,12 +6,10 @@ "main": "dist/index.cjs.js", "browser": "dist/esm/index.esm2017.js", "module": "dist/esm/index.esm2017.js", - "esm5": "dist/esm/index.esm.js", "exports": { ".": { "types": "./dist/src/index.d.ts", "require": "./dist/index.cjs.js", - "esm5": "./dist/esm/index.esm.js", "default": "./dist/esm/index.esm2017.js" }, "./package.json": "./package.json" @@ -67,5 +65,8 @@ ".ts" ], "reportDir": "./coverage/node" + }, + "engines": { + "node": ">=18.0.0" } } diff --git a/packages/app-check-compat/rollup.config.js b/packages/app-check-compat/rollup.config.js index e3cc4ea55de..137f3a27fad 100644 --- a/packages/app-check-compat/rollup.config.js +++ b/packages/app-check-compat/rollup.config.js @@ -25,32 +25,14 @@ const deps = Object.keys( Object.assign({}, pkg.peerDependencies, pkg.dependencies) ); -const es5BuildPlugins = [ +const buildPlugins = [ typescriptPlugin({ typescript }), - json() -]; - -const es2017BuildPlugins = [ - typescriptPlugin({ - typescript, - tsconfigOverride: { - compilerOptions: { - target: 'es2017' - } - } - }), json({ preferConst: true }) ]; const esmBuilds = [ - { - input: 'src/index.ts', - output: { file: pkg.esm5, format: 'es', sourcemap: true }, - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), - plugins: [...es5BuildPlugins, emitModulePackageFile()] - }, { input: 'src/index.ts', output: { @@ -59,16 +41,20 @@ const esmBuilds = [ sourcemap: true }, external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), - plugins: [...es2017BuildPlugins, emitModulePackageFile()] + plugins: [...buildPlugins, emitModulePackageFile()] } ]; const cjsBuilds = [ { input: 'src/index.ts', - output: { file: pkg.main, format: 'cjs', sourcemap: true }, + output: { + file: pkg.main, + format: 'cjs', + sourcemap: true + }, external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), - plugins: es5BuildPlugins + plugins: buildPlugins } ]; diff --git a/packages/app-check/package.json b/packages/app-check/package.json index cdef13bfeba..d74ec9843df 100644 --- a/packages/app-check/package.json +++ b/packages/app-check/package.json @@ -6,12 +6,10 @@ "main": "dist/index.cjs.js", "browser": "dist/esm/index.esm2017.js", "module": "dist/esm/index.esm2017.js", - "esm5": "dist/esm/index.esm.js", "exports": { ".": { "types": "./dist/app-check-public.d.ts", "require": "./dist/index.cjs.js", - "esm5": "./dist/esm/index.esm.js", "default": "./dist/esm/index.esm2017.js" }, "./package.json": "./package.json" @@ -68,5 +66,8 @@ ".ts" ], "reportDir": "./coverage/node" + }, + "engines": { + "node": ">=18.0.0" } } diff --git a/packages/app-check/rollup.config.js b/packages/app-check/rollup.config.js index e3cc4ea55de..137f3a27fad 100644 --- a/packages/app-check/rollup.config.js +++ b/packages/app-check/rollup.config.js @@ -25,32 +25,14 @@ const deps = Object.keys( Object.assign({}, pkg.peerDependencies, pkg.dependencies) ); -const es5BuildPlugins = [ +const buildPlugins = [ typescriptPlugin({ typescript }), - json() -]; - -const es2017BuildPlugins = [ - typescriptPlugin({ - typescript, - tsconfigOverride: { - compilerOptions: { - target: 'es2017' - } - } - }), json({ preferConst: true }) ]; const esmBuilds = [ - { - input: 'src/index.ts', - output: { file: pkg.esm5, format: 'es', sourcemap: true }, - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), - plugins: [...es5BuildPlugins, emitModulePackageFile()] - }, { input: 'src/index.ts', output: { @@ -59,16 +41,20 @@ const esmBuilds = [ sourcemap: true }, external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), - plugins: [...es2017BuildPlugins, emitModulePackageFile()] + plugins: [...buildPlugins, emitModulePackageFile()] } ]; const cjsBuilds = [ { input: 'src/index.ts', - output: { file: pkg.main, format: 'cjs', sourcemap: true }, + output: { + file: pkg.main, + format: 'cjs', + sourcemap: true + }, external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), - plugins: es5BuildPlugins + plugins: buildPlugins } ]; diff --git a/packages/app-compat/package.json b/packages/app-compat/package.json index 3aab3504c04..8a8b39eca7a 100644 --- a/packages/app-compat/package.json +++ b/packages/app-compat/package.json @@ -6,16 +6,12 @@ "main": "dist/index.cjs.js", "browser": "dist/esm/index.esm2017.js", "module": "dist/esm/index.esm2017.js", - "esm5": "dist/esm/index.esm5.js", "lite": "dist/index.lite.js", - "liteesm5": "dist/index.lite.esm5.js", "exports": { ".": { "types": "./dist/app-compat-public.d.ts", "require": "./dist/index.cjs.js", - "esm5": "./dist/esm/index.esm5.js", "lite": "./dist/index.lite.js", - "liteesm5": "./dist/index.lite.esm5.js", "default": "./dist/esm/index.esm2017.js" }, "./package.json": "./package.json" @@ -68,5 +64,8 @@ ".ts" ], "reportDir": "./coverage/node" + }, + "engines": { + "node": ">=18.0.0" } } diff --git a/packages/app-compat/rollup.config.js b/packages/app-compat/rollup.config.js index 055b75f3836..5bc1c799aa2 100644 --- a/packages/app-compat/rollup.config.js +++ b/packages/app-compat/rollup.config.js @@ -25,46 +25,15 @@ const deps = Object.keys( Object.assign({}, pkg.peerDependencies, pkg.dependencies) ); -const es5BuildPlugins = [ +const buildPlugins = [ typescriptPlugin({ typescript, abortOnError: false }), - json() -]; - -const es2017BuildPlugins = [ - typescriptPlugin({ - typescript, - abortOnError: false, - tsconfigOverride: { - compilerOptions: { - target: 'es2017' - } - } - }), - json({ - preferConst: true - }) + json({ preferConst: true }) ]; const esmBuilds = [ - { - input: 'src/index.ts', - output: { file: pkg.esm5, format: 'es', sourcemap: true }, - plugins: [...es5BuildPlugins, emitModulePackageFile()], - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) - }, - { - input: 'src/index.lite.ts', - output: { - file: pkg['liteesm5'], - format: 'es', - sourcemap: true - }, - plugins: es5BuildPlugins, - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) - }, { input: 'src/index.ts', output: { @@ -72,7 +41,7 @@ const esmBuilds = [ format: 'es', sourcemap: true }, - plugins: [...es2017BuildPlugins, emitModulePackageFile()], + plugins: [...buildPlugins, emitModulePackageFile()], external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) }, { @@ -82,7 +51,7 @@ const esmBuilds = [ format: 'es', sourcemap: true }, - plugins: es2017BuildPlugins, + plugins: buildPlugins, external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) } ]; @@ -90,8 +59,12 @@ const esmBuilds = [ const cjsBuilds = [ { input: 'src/index.ts', - output: { file: pkg.main, format: 'cjs', sourcemap: true }, - plugins: es5BuildPlugins, + output: { + file: pkg.main, + format: 'cjs', + sourcemap: true + }, + plugins: buildPlugins, external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) } ]; diff --git a/packages/app/package.json b/packages/app/package.json index c413787ea2c..2cb10dbcbeb 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -6,12 +6,10 @@ "main": "dist/index.cjs.js", "browser": "dist/esm/index.esm2017.js", "module": "dist/esm/index.esm2017.js", - "esm5": "dist/esm/index.esm5.js", "exports": { ".": { "types": "./dist/app-public.d.ts", "require": "./dist/index.cjs.js", - "esm5": "./dist/esm/index.esm5.js", "default": "./dist/esm/index.esm2017.js" }, "./package.json": "./package.json" @@ -68,5 +66,8 @@ ".ts" ], "reportDir": "./coverage/node" + }, + "engines": { + "node": ">=18.0.0" } } diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js index 6900b5f0f4a..ec5a279a1c2 100644 --- a/packages/app/rollup.config.js +++ b/packages/app/rollup.config.js @@ -28,44 +28,17 @@ const deps = Object.keys( Object.assign({}, pkg.peerDependencies, pkg.dependencies) ); -const es5BuildPlugins = [ +const buildPlugins = [ typescriptPlugin({ typescript }), - json() -]; - -const es2017BuildPlugins = [ - typescriptPlugin({ - typescript, - tsconfigOverride: { - compilerOptions: { - target: 'es2017' - } - } - }), - json({ - preferConst: true - }) + json({ preferConst: true }) ]; const esmBuilds = [ /** * Browser Builds */ - { - input: 'src/index.ts', - output: [{ file: pkg.esm5, format: 'es', sourcemap: true }], - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), - plugins: [ - ...es5BuildPlugins, - replace({ - ...generateBuildTargetReplaceConfig('esm', 5), - '__RUNTIME_ENV__': '' - }), - emitModulePackageFile() - ] - }, { input: 'src/index.ts', output: { @@ -75,7 +48,7 @@ const esmBuilds = [ }, external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), plugins: [ - ...es2017BuildPlugins, + ...buildPlugins, replace({ ...generateBuildTargetReplaceConfig('esm', 2017), '__RUNTIME_ENV__': '' @@ -88,12 +61,16 @@ const esmBuilds = [ const cjsBuilds = [ { input: 'src/index.ts', - output: [{ file: pkg.main, format: 'cjs', sourcemap: true }], + output: { + file: pkg.main, + format: 'cjs', + sourcemap: true + }, external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), plugins: [ - ...es5BuildPlugins, + ...buildPlugins, replace({ - ...generateBuildTargetReplaceConfig('cjs', 5), + ...generateBuildTargetReplaceConfig('cjs', 2017), '__RUNTIME_ENV__': 'node' }) ] diff --git a/packages/app/src/registerCoreComponents.ts b/packages/app/src/registerCoreComponents.ts index 744b916e4c0..f0141dbf155 100644 --- a/packages/app/src/registerCoreComponents.ts +++ b/packages/app/src/registerCoreComponents.ts @@ -40,7 +40,7 @@ export function registerCoreComponents(variant?: string): void { // Register `app` package. registerVersion(name, version, variant); - // BUILD_TARGET will be replaced by values like esm5, esm2017, cjs5, etc during the compilation + // BUILD_TARGET will be replaced by values like esm2017, cjs2017, etc during the compilation registerVersion(name, version, '__BUILD_TARGET__'); // Register platform SDK identifier (no version). registerVersion('fire-js', ''); diff --git a/packages/auth-compat/index.node.ts b/packages/auth-compat/index.node.ts index 6d8dd2c07a5..1513148bea9 100644 --- a/packages/auth-compat/index.node.ts +++ b/packages/auth-compat/index.node.ts @@ -23,15 +23,6 @@ */ export * from './index'; import { FetchProvider } from '@firebase/auth/internal'; -import { - fetch as undiciFetch, - Headers as undiciHeaders, - Response as undiciResponse -} from 'undici'; import './index'; -FetchProvider.initialize( - undiciFetch as unknown as typeof fetch, - undiciHeaders as unknown as typeof Headers, - undiciResponse as unknown as typeof Response -); +FetchProvider.initialize(fetch, Headers, Response); diff --git a/packages/auth-compat/karma.conf.js b/packages/auth-compat/karma.conf.js index f3f14e8d1b1..6283ffbc3f1 100644 --- a/packages/auth-compat/karma.conf.js +++ b/packages/auth-compat/karma.conf.js @@ -30,18 +30,6 @@ module.exports = function (config) { // frameworks to use // available frameworks: https://npmjs.org/browse/keyword/karma-adapter frameworks: ['mocha'], - // undici is a fetch polyfill that test helpers call for Node tests, and browser tests should - // ignore its import to avoid compilation errors in those test helpers. - webpack: { - ...webpackBase, - resolve: { - ...webpackBase.resolve, - alias: { - 'undici': false - } - } - }, - client: Object.assign({}, karmaBase.client, getClientConfig()) }); diff --git a/packages/auth-compat/package.json b/packages/auth-compat/package.json index dd69dc9f993..b6366b2f725 100644 --- a/packages/auth-compat/package.json +++ b/packages/auth-compat/package.json @@ -6,7 +6,6 @@ "main": "dist/index.node.cjs.js", "browser": "dist/index.esm2017.js", "module": "dist/index.esm2017.js", - "esm5": "dist/index.esm.js", "exports": { ".": { "types": "./dist/auth-compat/index.d.ts", @@ -15,7 +14,6 @@ "import": "./dist/esm/index.node.esm.js", "require": "./dist/index.node.cjs.js" }, - "esm5": "./dist/index.esm.js", "browser": { "require": "./dist/index.cjs.js", "import": "./dist/index.esm2017.js" @@ -55,7 +53,6 @@ "@firebase/auth-types": "0.12.2", "@firebase/component": "0.6.9", "@firebase/util": "1.10.0", - "undici": "6.19.7", "tslib": "^2.1.0" }, "license": "Apache-2.0", @@ -82,5 +79,8 @@ ".ts" ], "reportDir": "./coverage/node" + }, + "engines": { + "node": ">=18.0.0" } } diff --git a/packages/auth-compat/rollup.config.js b/packages/auth-compat/rollup.config.js index cb3491541c4..b2872f977fd 100644 --- a/packages/auth-compat/rollup.config.js +++ b/packages/auth-compat/rollup.config.js @@ -27,40 +27,9 @@ const deps = Object.keys( Object.assign({}, pkg.peerDependencies, pkg.dependencies) ); -/** - * Common plugins for all builds - */ -const commonPlugins = [json(), resolve()]; - -const es5BuildPlugins = [ - ...commonPlugins, - typescriptPlugin({ - typescript - }) -]; - -const es2017BuildPlugins = [ - ...commonPlugins, - typescriptPlugin({ - typescript, - tsconfigOverride: { - compilerOptions: { - target: 'es2017' - } - } - }) -]; +const buildPlugins = [json(), resolve(), typescriptPlugin({ typescript })]; const browserBuilds = [ - { - input: 'index.ts', - output: [{ file: pkg.esm5, format: 'es', sourcemap: true }], - plugins: es5BuildPlugins, - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), - treeshake: { - moduleSideEffects: false - } - }, { input: 'index.ts', output: { @@ -68,7 +37,7 @@ const browserBuilds = [ format: 'es', sourcemap: true }, - plugins: es2017BuildPlugins, + plugins: buildPlugins, external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), treeshake: { moduleSideEffects: false @@ -81,7 +50,7 @@ const browserBuilds = [ format: 'cjs', sourcemap: true }, - plugins: es2017BuildPlugins, + plugins: buildPlugins, external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), treeshake: { moduleSideEffects: false @@ -92,8 +61,12 @@ const browserBuilds = [ const nodeBuilds = [ { input: 'index.node.ts', - output: [{ file: pkg.main, format: 'cjs', sourcemap: true }], - plugins: es5BuildPlugins, + output: { + file: pkg.main, + format: 'cjs', + sourcemap: true + }, + plugins: buildPlugins, external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), treeshake: { moduleSideEffects: true @@ -104,7 +77,7 @@ const nodeBuilds = [ output: [ { file: pkg.exports['.'].node.import, format: 'es', sourcemap: true } ], - plugins: [...es2017BuildPlugins, emitModulePackageFile()], + plugins: [...buildPlugins, emitModulePackageFile()], external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), treeshake: { moduleSideEffects: true @@ -144,7 +117,7 @@ const umdBuild = { ); }` }, - plugins: [...es5BuildPlugins, uglify()], + plugins: [...buildPlugins, uglify()], external: ['@firebase/app-compat', '@firebase/app'] }; diff --git a/packages/auth/api-extractor.json b/packages/auth/api-extractor.json index ca7e1ee6983..f7279fcac15 100644 --- a/packages/auth/api-extractor.json +++ b/packages/auth/api-extractor.json @@ -1,6 +1,6 @@ { "extends": "../../config/api-extractor.json", - "mainEntryPointFilePath": "/dist/esm5/index.d.ts", + "mainEntryPointFilePath": "/dist/esm2017/index.d.ts", "dtsRollup": { "enabled": true, "untrimmedFilePath": "/dist/.d.ts", diff --git a/packages/auth/cordova/demo/rollup.config.js b/packages/auth/cordova/demo/rollup.config.js index 252e2e6b622..21654b783d2 100644 --- a/packages/auth/cordova/demo/rollup.config.js +++ b/packages/auth/cordova/demo/rollup.config.js @@ -18,28 +18,15 @@ import resolve from '@rollup/plugin-node-resolve'; import strip from '@rollup/plugin-strip'; /** - * Common plugins for all builds + * Browser Build */ -const commonPlugins = [ - strip({ - functions: ['debugAssert.*'] - }) -]; +const esmBuild = { + input: 'src/index.js', + output: [{ file: 'www/dist/bundle.js', format: 'esm', sourcemap: true }], + plugins: [ + strip({ functions: ['debugAssert.*'] }), + resolve({ mainFields: ['module', 'main'] }) + ] +}; -const es5Builds = [ - /** - * Browser Builds - */ - { - input: 'src/index.js', - output: [{ file: 'www/dist/bundle.js', format: 'esm', sourcemap: true }], - plugins: [ - ...commonPlugins, - resolve({ - mainFields: ['module', 'main'] - }) - ] - } -]; - -export default [...es5Builds]; +export default esmBuild; diff --git a/packages/auth/demo/rollup.config.js b/packages/auth/demo/rollup.config.js index 49aff45b419..ce6a2893210 100644 --- a/packages/auth/demo/rollup.config.js +++ b/packages/auth/demo/rollup.config.js @@ -21,17 +21,8 @@ import typescript from 'typescript'; import pkg from './package.json'; -/** - * Common plugins for all builds - */ -const commonPlugins = [ - strip({ - functions: ['debugAssert.*'] - }) -]; - const workerPlugins = [ - ...commonPlugins, + strip({ functions: ['debugAssert.*'] }), resolve({ mainFields: ['webworker', 'module', 'main'] }), @@ -44,7 +35,7 @@ const workerPlugins = [ lib: [ // TODO: remove this 'dom', - 'es2015', + 'es2017', 'webworker' ] } @@ -52,30 +43,33 @@ const workerPlugins = [ }) ]; -const es5Builds = [ - /** - * Browser Builds - */ +const esmBuilds = [ { input: 'src/index.js', output: [{ file: pkg.browser, format: 'esm', sourcemap: true }], plugins: [ - ...commonPlugins, - resolve({ - mainFields: ['module', 'main'] - }) + strip({ functions: ['debugAssert.*'] }), + resolve({ mainFields: ['module', 'main'] }) ] }, { input: 'src/worker/web-worker.ts', - output: [{ file: pkg.webworker, format: 'esm', sourcemap: true }], + output: { + file: pkg.webworker, + format: 'esm', + sourcemap: true + }, plugins: workerPlugins }, { input: 'src/worker/service-worker.ts', - output: [{ file: pkg.serviceworker, format: 'esm', sourcemap: true }], + output: { + file: pkg.serviceworker, + format: 'esm', + sourcemap: true + }, plugins: workerPlugins } ]; -export default [...es5Builds]; +export default [...esmBuilds]; diff --git a/packages/auth/demo/src/worker/tsconfig.json b/packages/auth/demo/src/worker/tsconfig.json index e160c5c6b47..1081b12233f 100644 --- a/packages/auth/demo/src/worker/tsconfig.json +++ b/packages/auth/demo/src/worker/tsconfig.json @@ -2,9 +2,9 @@ "extends": "../../../config/tsconfig.base.json", "compilerOptions": { "outDir": "dist", - "target": "es2015", + "target": "es2017", "lib": [ - "es2015", + "es2017", "webworker" ] }, diff --git a/packages/auth/internal/package.json b/packages/auth/internal/package.json index 8dd06ec9378..4ecfdccbd20 100644 --- a/packages/auth/internal/package.json +++ b/packages/auth/internal/package.json @@ -4,7 +4,9 @@ "main": "../dist/node/internal.js", "module": "../dist/esm2017/internal.js", "browser": "../dist/esm2017/internal.js", - "esm5": "../dist/esm5/internal.js", - "typings": "../dist/esm5/internal/index.d.ts", - "private": true + "typings": "../dist/esm2017/internal/index.d.ts", + "private": true, + "engines": { + "node": ">=18.0.0" + } } diff --git a/packages/auth/karma.conf.js b/packages/auth/karma.conf.js index 1d28c329f55..f8dcd5b0341 100644 --- a/packages/auth/karma.conf.js +++ b/packages/auth/karma.conf.js @@ -27,17 +27,6 @@ module.exports = function (config) { // frameworks to use // available frameworks: https://npmjs.org/browse/keyword/karma-adapter frameworks: ['mocha'], - // undici is a fetch polyfill that test helpers call for Node tests, and browser tests should - // ignore its import to avoid compilation errors in those test helpers. - webpack: { - ...webpackBase, - resolve: { - ...webpackBase.resolve, - alias: { - 'undici': false - } - } - }, client: Object.assign({}, karmaBase.client, getClientConfig(argv)) }); diff --git a/packages/auth/package.json b/packages/auth/package.json index 5cff7192eff..e30312d4b68 100644 --- a/packages/auth/package.json +++ b/packages/auth/package.json @@ -9,8 +9,7 @@ "module": "dist/esm2017/index.js", "cordova": "dist/cordova/index.js", "web-extension": "dist/web-extension-esm2017/index.js", - "webworker": "dist/index.webworker.esm5.js", - "esm5": "dist/esm5/index.js", + "webworker": "dist/index.webworker.js", "exports": { ".": { "types": "./dist/auth-public.d.ts", @@ -29,9 +28,8 @@ }, "webworker": { "types": "./dist/index.webworker.d.ts", - "default": "./dist/index.webworker.esm5.js" + "default": "./dist/index.webworker.js" }, - "esm5": "./dist/esm5/index.js", "browser": { "require": "./dist/browser-cjs/index.js", "import": "./dist/esm2017/index.js" @@ -63,7 +61,6 @@ "types": "./dist/cordova/internal/index.d.ts", "default": "./dist/cordova/internal.js" }, - "esm5": "./dist/esm5/internal.js", "browser": { "require": "./dist/browser-cjs/internal.js", "import": "./dist/esm2017/internal.js" @@ -130,7 +127,6 @@ "@firebase/component": "0.6.9", "@firebase/logger": "0.4.2", "@firebase/util": "1.10.0", - "undici": "6.19.7", "tslib": "^2.1.0" }, "license": "Apache-2.0", @@ -161,5 +157,8 @@ ".ts" ], "reportDir": "./coverage/node" + }, + "engines": { + "node": ">=18.0.0" } } diff --git a/packages/auth/rollup.config.js b/packages/auth/rollup.config.js index 46d3ee0380d..6af229962bd 100644 --- a/packages/auth/rollup.config.js +++ b/packages/auth/rollup.config.js @@ -44,44 +44,13 @@ const nodeAliasPlugin = alias({ ] }); -const es5BuildPlugins = [ +const buildPlugins = [ json(), - strip({ - functions: ['debugAssert.*'] - }), - typescriptPlugin({ - typescript - }) -]; - -const es2017BuildPlugins = [ - json(), - strip({ - functions: ['debugAssert.*'] - }), - typescriptPlugin({ - typescript, - tsconfigOverride: { - compilerOptions: { - target: 'es2017' - } - } - }) + strip({ functions: ['debugAssert.*'] }), + typescriptPlugin({ typescript }) ]; const browserBuilds = [ - { - input: { - index: 'index.ts', - internal: 'internal/index.ts' - }, - output: [{ dir: 'dist/esm5', format: 'es', sourcemap: true }], - plugins: [ - ...es5BuildPlugins, - replace(generateBuildTargetReplaceConfig('esm', 5)) - ], - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) - }, { input: { index: 'index.ts', @@ -93,7 +62,7 @@ const browserBuilds = [ sourcemap: true }, plugins: [ - ...es2017BuildPlugins, + ...buildPlugins, replace(generateBuildTargetReplaceConfig('esm', 2017)) ], external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) @@ -105,7 +74,7 @@ const browserBuilds = [ }, output: [{ dir: 'dist/browser-cjs', format: 'cjs', sourcemap: true }], plugins: [ - ...es2017BuildPlugins, + ...buildPlugins, replace(generateBuildTargetReplaceConfig('cjs', 2017)) ], external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) @@ -124,7 +93,7 @@ const browserWebExtensionBuilds = [ sourcemap: true }, plugins: [ - ...es2017BuildPlugins, + ...buildPlugins, replace(generateBuildTargetReplaceConfig('esm', 2017)), emitModulePackageFile() ], @@ -137,7 +106,7 @@ const browserWebExtensionBuilds = [ }, output: [{ dir: 'dist/web-extension-cjs', format: 'cjs', sourcemap: true }], plugins: [ - ...es2017BuildPlugins, + ...buildPlugins, replace(generateBuildTargetReplaceConfig('cjs', 2017)) ], external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) @@ -153,8 +122,8 @@ const nodeBuilds = [ output: [{ dir: 'dist/node', format: 'cjs', sourcemap: true }], plugins: [ nodeAliasPlugin, - ...es5BuildPlugins, - replace(generateBuildTargetReplaceConfig('cjs', 5)) + ...buildPlugins, + replace(generateBuildTargetReplaceConfig('cjs', 2017)) ], external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) }, @@ -166,7 +135,7 @@ const nodeBuilds = [ output: [{ dir: 'dist/node-esm', format: 'es', sourcemap: true }], plugins: [ nodeAliasPlugin, - ...es2017BuildPlugins, + ...buildPlugins, replace(generateBuildTargetReplaceConfig('esm', 2017)), emitModulePackageFile() ], @@ -179,10 +148,14 @@ const cordovaBuild = { index: 'index.cordova.ts', internal: 'internal/index.ts' }, - output: [{ dir: 'dist/cordova', format: 'es', sourcemap: true }], + output: { + dir: 'dist/cordova', + format: 'es', + sourcemap: true + }, plugins: [ - ...es5BuildPlugins, - replace(generateBuildTargetReplaceConfig('esm', 5)) + ...buildPlugins, + replace(generateBuildTargetReplaceConfig('esm', 2017)) ], external: id => [...deps, 'cordova'].some(dep => id === dep || id.startsWith(`${dep}/`)) @@ -195,8 +168,8 @@ const rnBuild = { }, output: [{ dir: 'dist/rn', format: 'cjs', sourcemap: true }], plugins: [ - ...es5BuildPlugins, - replace(generateBuildTargetReplaceConfig('cjs', 5)) + ...buildPlugins, + replace(generateBuildTargetReplaceConfig('cjs', 2017)) ], external: id => [...deps, 'react-native'].some( @@ -206,7 +179,11 @@ const rnBuild = { const webWorkerBuild = { input: 'index.webworker.ts', - output: [{ file: pkg.webworker, format: 'es', sourcemap: true }], + output: { + file: pkg.webworker, + format: 'es', + sourcemap: true + }, plugins: [ json(), strip({ @@ -218,12 +195,12 @@ const webWorkerBuild = { lib: [ // Remove dom after we figure out why navigator stuff doesn't exist 'dom', - 'es2015', + 'es2017', 'webworker' ] } }), - replace(generateBuildTargetReplaceConfig('esm', 5)) + replace(generateBuildTargetReplaceConfig('esm', 2017)) ], external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) }; diff --git a/packages/auth/src/core/auth/register.ts b/packages/auth/src/core/auth/register.ts index 4b891618d3a..9d0d6b4559d 100644 --- a/packages/auth/src/core/auth/register.ts +++ b/packages/auth/src/core/auth/register.ts @@ -130,6 +130,6 @@ export function registerAuth(clientPlatform: ClientPlatform): void { ); registerVersion(name, version, getVersionForPlatform(clientPlatform)); - // BUILD_TARGET will be replaced by values like esm5, esm2017, cjs5, etc during the compilation + // BUILD_TARGET will be replaced by values like esm2017, cjs2017, etc during the compilation registerVersion(name, version, '__BUILD_TARGET__'); } diff --git a/packages/auth/src/platform_node/index.ts b/packages/auth/src/platform_node/index.ts index 41da18ff643..67618b5b773 100644 --- a/packages/auth/src/platform_node/index.ts +++ b/packages/auth/src/platform_node/index.ts @@ -28,18 +28,9 @@ import { AuthImpl } from '../core/auth/auth_impl'; import { FetchProvider } from '../core/util/fetch_provider'; import { getDefaultEmulatorHost } from '@firebase/util'; -import { - fetch as undiciFetch, - Headers as undiciHeaders, - Response as undiciResponse -} from 'undici'; // Initialize the fetch polyfill, the types are slightly off so just cast and hope for the best -FetchProvider.initialize( - undiciFetch as unknown as typeof fetch, - undiciHeaders as unknown as typeof Headers, - undiciResponse as unknown as typeof Response -); +FetchProvider.initialize(fetch, Headers, Response); // First, we set up the various platform-specific features for Node (register // the version and declare the Node getAuth function) diff --git a/packages/auth/test/helpers/integration/emulator_rest_helpers.ts b/packages/auth/test/helpers/integration/emulator_rest_helpers.ts index 32b9aad2129..5a96d193ee1 100644 --- a/packages/auth/test/helpers/integration/emulator_rest_helpers.ts +++ b/packages/auth/test/helpers/integration/emulator_rest_helpers.ts @@ -15,7 +15,6 @@ * limitations under the License. */ -import { fetch as undiciFetch, RequestInit as undiciRequestInit } from 'undici'; import { getAppConfig, getEmulatorUrl } from './settings'; export interface VerificationSession { @@ -88,9 +87,8 @@ function doFetch(url: string, request?: RequestInit): ReturnType { if (typeof document !== 'undefined') { return fetch(url, request); } else { - return undiciFetch( - url, - request as undiciRequestInit - ) as unknown as ReturnType; + return fetch(url, request as RequestInit) as unknown as ReturnType< + typeof fetch + >; } } diff --git a/packages/component/package.json b/packages/component/package.json index 3ae6f40e90c..1f3b8ad51a8 100644 --- a/packages/component/package.json +++ b/packages/component/package.json @@ -6,12 +6,10 @@ "main": "dist/index.cjs.js", "browser": "dist/esm/index.esm2017.js", "module": "dist/esm/index.esm2017.js", - "esm5": "dist/esm/index.esm5.js", "exports": { ".": { "types": "./dist/index.d.ts", "require": "./dist/index.cjs.js", - "esm5": "./dist/esm/index.esm5.js", "default": "./dist/esm/index.esm2017.js" }, "./package.json": "./package.json" @@ -56,5 +54,8 @@ ".ts" ], "reportDir": "./coverage/node" + }, + "engines": { + "node": ">=18.0.0" } } diff --git a/packages/component/rollup.config.js b/packages/component/rollup.config.js index f0cc1a84e98..11d18692c8c 100644 --- a/packages/component/rollup.config.js +++ b/packages/component/rollup.config.js @@ -24,49 +24,24 @@ const deps = Object.keys( Object.assign({}, pkg.peerDependencies, pkg.dependencies) ); -const es5BuildPlugins = [ - typescriptPlugin({ - typescript - }) -]; +const buildPlugins = [typescriptPlugin({ typescript })]; -const es2017BuildPlugins = [ - typescriptPlugin({ - typescript, - tsconfigOverride: { - compilerOptions: { - target: 'es2017' - } - } - }) -]; +const esmBuild = { + input: 'index.ts', + output: { file: pkg.module, format: 'es', sourcemap: true }, + plugins: [...buildPlugins, emitModulePackageFile()], + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) +}; -const esmBuilds = [ - { - input: 'index.ts', - output: { file: pkg.module, format: 'es', sourcemap: true }, - plugins: [...es2017BuildPlugins, emitModulePackageFile()], - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) +const cjsBuild = { + input: 'index.ts', + output: { + file: pkg.main, + format: 'cjs', + sourcemap: true }, - { - input: 'index.ts', - output: { - file: pkg.esm5, - format: 'es', - sourcemap: true - }, - plugins: [...es5BuildPlugins, emitModulePackageFile()], - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) - } -]; + plugins: buildPlugins, + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) +}; -const cjsBuilds = [ - { - input: 'index.ts', - output: { file: pkg.main, format: 'cjs', sourcemap: true }, - plugins: es5BuildPlugins, - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) - } -]; - -export default [...esmBuilds, ...cjsBuilds]; +export default [esmBuild, cjsBuild]; diff --git a/packages/database-compat/package.json b/packages/database-compat/package.json index 5f554f1644c..be50b28f6fa 100644 --- a/packages/database-compat/package.json +++ b/packages/database-compat/package.json @@ -6,7 +6,6 @@ "main": "dist/index.js", "browser": "dist/index.esm2017.js", "module": "dist/index.esm2017.js", - "esm5": "dist/index.esm5.js", "license": "Apache-2.0", "typings": "dist/database-compat/src/index.d.ts", "files": [ @@ -21,7 +20,6 @@ "import": "./dist/node-esm/index.js", "require": "./dist/index.js" }, - "esm5": "./dist/index.esm5.js", "browser": { "require": "./dist/index.js", "import": "./dist/index.esm2017.js" @@ -69,5 +67,8 @@ }, "bugs": { "url": "https://github.com/firebase/firebase-js-sdk/issues" + }, + "engines": { + "node": ">=18.0.0" } } diff --git a/packages/database-compat/rollup.config.js b/packages/database-compat/rollup.config.js index bba2fba3c44..57ec9aee2ba 100644 --- a/packages/database-compat/rollup.config.js +++ b/packages/database-compat/rollup.config.js @@ -34,24 +34,11 @@ function onWarn(warning, defaultWarn) { defaultWarn(warning); } -const es5BuildPlugins = [ +const buildPlugins = [ typescriptPlugin({ typescript, abortOnError: false }), - json() -]; - -const es2017BuildPlugins = [ - typescriptPlugin({ - typescript, - tsconfigOverride: { - compilerOptions: { - target: 'es2017' - } - }, - abortOnError: false - }), json({ preferConst: true }) ]; @@ -68,7 +55,7 @@ const esmBuilds = [ sourcemap: true } ], - plugins: [...es2017BuildPlugins, emitModulePackageFile()], + plugins: [...buildPlugins, emitModulePackageFile()], treeshake: { moduleSideEffects: false }, @@ -76,24 +63,8 @@ const esmBuilds = [ onwarn: onWarn }, /** - * Browser Builds + * Browser Build */ - { - input: 'src/index.ts', - output: [ - { - file: pkg.esm5, - format: 'es', - sourcemap: true - } - ], - plugins: es5BuildPlugins, - treeshake: { - moduleSideEffects: false - }, - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), - onwarn: onWarn - }, { input: 'src/index.ts', output: [ @@ -103,7 +74,7 @@ const esmBuilds = [ sourcemap: true } ], - plugins: es2017BuildPlugins, + plugins: buildPlugins, treeshake: { moduleSideEffects: false }, @@ -125,7 +96,7 @@ const cjsBuilds = [ sourcemap: true } ], - plugins: es5BuildPlugins, + plugins: buildPlugins, treeshake: { moduleSideEffects: false }, @@ -146,7 +117,7 @@ const cjsBuilds = [ } ], plugins: [ - ...es5BuildPlugins, + ...buildPlugins, resolveModule({ exportConditions: ['standalone'], preferBuiltins: true diff --git a/packages/database/package.json b/packages/database/package.json index 87c405255c7..14f30231f17 100644 --- a/packages/database/package.json +++ b/packages/database/package.json @@ -6,7 +6,6 @@ "main": "dist/index.node.cjs.js", "browser": "dist/index.esm2017.js", "module": "dist/index.esm2017.js", - "esm5": "dist/index.esm5.js", "standalone": "dist/index.standalone.js", "exports": { ".": { @@ -15,7 +14,6 @@ "import": "./dist/node-esm/index.node.esm.js", "require": "./dist/index.node.cjs.js" }, - "esm5": "./dist/index.esm5.js", "standalone": "./dist/index.standalone.js", "browser": { "require": "./dist/index.cjs.js", @@ -78,5 +76,8 @@ ".ts" ], "reportDir": "./coverage/node" + }, + "engines": { + "node": ">=18.0.0" } } diff --git a/packages/database/rollup.config.js b/packages/database/rollup.config.js index 886a177e4d9..293eaf06811 100644 --- a/packages/database/rollup.config.js +++ b/packages/database/rollup.config.js @@ -35,47 +35,15 @@ function onWarn(warning, defaultWarn) { defaultWarn(warning); } -const es5BuildPlugins = [ +const buildPlugins = [ typescriptPlugin({ typescript, abortOnError: false }), - json() -]; - -const es2017BuildPlugins = [ - typescriptPlugin({ - typescript, - tsconfigOverride: { - compilerOptions: { - target: 'es2017' - } - }, - abortOnError: false - }), json({ preferConst: true }) ]; const browserBuilds = [ - { - input: 'src/index.ts', - output: [ - { - file: pkg.esm5, - format: 'es', - sourcemap: true - } - ], - plugins: [ - ...es5BuildPlugins, - replace(generateBuildTargetReplaceConfig('esm', 5)) - ], - treeshake: { - moduleSideEffects: false - }, - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), - onwarn: onWarn - }, { input: 'src/index.ts', output: [ @@ -86,7 +54,7 @@ const browserBuilds = [ } ], plugins: [ - ...es2017BuildPlugins, + ...buildPlugins, replace(generateBuildTargetReplaceConfig('esm', 2017)) ], treeshake: { @@ -105,7 +73,7 @@ const browserBuilds = [ } ], plugins: [ - ...es2017BuildPlugins, + ...buildPlugins, replace(generateBuildTargetReplaceConfig('cjs', 2017)) ], treeshake: { @@ -119,10 +87,14 @@ const browserBuilds = [ const nodeBuilds = [ { input: 'src/index.node.ts', - output: { file: pkg.main, format: 'cjs', sourcemap: true }, + output: { + file: pkg.main, + format: 'cjs', + sourcemap: true + }, plugins: [ - ...es5BuildPlugins, - replace(generateBuildTargetReplaceConfig('cjs', 5)) + ...buildPlugins, + replace(generateBuildTargetReplaceConfig('cjs', 2017)) ], treeshake: { moduleSideEffects: false @@ -138,7 +110,7 @@ const nodeBuilds = [ sourcemap: true }, plugins: [ - ...es2017BuildPlugins, + ...buildPlugins, replace(generateBuildTargetReplaceConfig('esm', 2017)), emitModulePackageFile() ], @@ -154,7 +126,7 @@ const nodeBuilds = [ { input: 'src/index.standalone.ts', output: [{ file: pkg.standalone, format: 'cjs', sourcemap: true }], - plugins: es5BuildPlugins, + plugins: buildPlugins, treeshake: { moduleSideEffects: false }, diff --git a/packages/database/src/register.ts b/packages/database/src/register.ts index cd2be0aaa7e..9322368526b 100644 --- a/packages/database/src/register.ts +++ b/packages/database/src/register.ts @@ -47,6 +47,6 @@ export function registerDatabase(variant?: string): void { ).setMultipleInstances(true) ); registerVersion(name, version, variant); - // BUILD_TARGET will be replaced by values like esm5, esm2017, cjs5, etc during the compilation + // BUILD_TARGET will be replaced by values like esm2017, cjs2017, etc during the compilation registerVersion(name, version, '__BUILD_TARGET__'); } diff --git a/packages/firebase/compat/rollup.config.js b/packages/firebase/compat/rollup.config.js index 4b481b93b1f..1f850011b13 100644 --- a/packages/firebase/compat/rollup.config.js +++ b/packages/firebase/compat/rollup.config.js @@ -284,43 +284,16 @@ const completeBuilds = [ }, plugins: [ sourcemaps(), - resolveModule({ - exportConditions: ['liteesm5', 'esm5'] - }), - typescriptPluginCDN, - json(), - commonjs(), - uglify(uglifyOptions) - ] - }, - /** - * Performance script Build in ES2017 - */ - { - input: `${__dirname}/index.perf.ts`, - output: { - file: 'firebase-performance-standalone-compat.es2017.js', - format: 'umd', - sourcemap: true, - name: GLOBAL_NAME - }, - plugins: [ - sourcemaps(), - resolveModule({ - exportConditions: ['lite'] - }), + resolveModule({ exportConditions: ['lite'] }), rollupTypescriptPlugin({ typescript, tsconfigOverride: { compilerOptions: { - target: 'es2017', declaration: false } } }), - json({ - preferConst: true - }), + json({ preferConst: true }), commonjs(), terser() ] diff --git a/packages/firebase/package.json b/packages/firebase/package.json index 6d1e8b618b8..1565ce91337 100644 --- a/packages/firebase/package.json +++ b/packages/firebase/package.json @@ -215,17 +215,17 @@ }, "default": "./storage/dist/esm/index.esm.js" }, - "./vertexai-preview": { - "types": "./vertexai-preview/dist/vertexai-preview/index.d.ts", + "./vertexai": { + "types": "./vertexai/dist/vertexai/index.d.ts", "node": { - "require": "./vertexai-preview/dist/index.cjs.js", - "import": "./vertexai-preview/dist/index.mjs" + "require": "./vertexai/dist/index.cjs.js", + "import": "./vertexai/dist/index.mjs" }, "browser": { - "require": "./vertexai-preview/dist/index.cjs.js", - "import": "./vertexai-preview/dist/esm/index.esm.js" + "require": "./vertexai/dist/index.cjs.js", + "import": "./vertexai/dist/esm/index.esm.js" }, - "default": "./vertexai-preview/dist/esm/index.esm.js" + "default": "./vertexai/dist/esm/index.esm.js" }, "./compat/analytics": { "types": "./compat/analytics/dist/compat/analytics/index.d.ts", @@ -413,7 +413,7 @@ "@firebase/app-check": "0.8.8", "@firebase/app-check-compat": "0.3.15", "@firebase/util": "1.10.0", - "@firebase/vertexai-preview": "0.0.4" + "@firebase/vertexai": "0.0.4" }, "devDependencies": { "rollup": "2.79.1", @@ -446,7 +446,7 @@ "messaging", "messaging/sw", "database", - "vertexai-preview" + "vertexai" ], "typings": "empty.d.ts" } diff --git a/packages/firebase/vertexai-preview/index.ts b/packages/firebase/vertexai/index.ts similarity index 93% rename from packages/firebase/vertexai-preview/index.ts rename to packages/firebase/vertexai/index.ts index 20d7697c1e0..2645fd3004f 100644 --- a/packages/firebase/vertexai-preview/index.ts +++ b/packages/firebase/vertexai/index.ts @@ -15,4 +15,4 @@ * limitations under the License. */ -export * from '@firebase/vertexai-preview'; +export * from '@firebase/vertexai'; diff --git a/packages/firebase/vertexai-preview/package.json b/packages/firebase/vertexai/package.json similarity index 55% rename from packages/firebase/vertexai-preview/package.json rename to packages/firebase/vertexai/package.json index 9dfe8f0c3fa..20e04a3bbb5 100644 --- a/packages/firebase/vertexai-preview/package.json +++ b/packages/firebase/vertexai/package.json @@ -1,7 +1,7 @@ { - "name": "firebase/vertexai-preview", + "name": "firebase/vertexai", "main": "dist/index.cjs.js", "browser": "dist/esm/index.esm.js", "module": "dist/esm/index.esm.js", - "typings": "dist/vertexai-preview/index.d.ts" + "typings": "dist/vertexai/index.d.ts" } \ No newline at end of file diff --git a/packages/firestore-compat/package.json b/packages/firestore-compat/package.json index 66326ac2edf..2994067a633 100644 --- a/packages/firestore-compat/package.json +++ b/packages/firestore-compat/package.json @@ -7,7 +7,6 @@ "react-native": "dist/index.rn.js", "browser": "dist/index.esm2017.js", "module": "dist/index.esm2017.js", - "esm5": "dist/index.esm5.js", "exports": { ".": { "types": "./dist/src/index.d.ts", @@ -16,7 +15,6 @@ "require": "./dist/index.node.cjs.js" }, "react-native": "./dist/index.rn.js", - "esm5": "./dist/index.esm5.js", "browser": { "require": "./dist/index.cjs.js", "import": "./dist/index.esm2017.js" @@ -74,5 +72,8 @@ }, "bugs": { "url": "https://github.com/firebase/firebase-js-sdk/issues" + }, + "engines": { + "node": ">=18.0.0" } } diff --git a/packages/firestore-compat/rollup.config.js b/packages/firestore-compat/rollup.config.js index ecf6d42ca91..c85af11225f 100644 --- a/packages/firestore-compat/rollup.config.js +++ b/packages/firestore-compat/rollup.config.js @@ -38,14 +38,6 @@ const es2017Plugins = [ json({ preferConst: true }) ]; -const es5Plugins = [ - typescriptPlugin({ - typescript, - transformers: [util.removeAssertTransformer] - }), - json({ preferConst: true }) -]; - const browserBuilds = [ { input: './src/index.ts', @@ -57,18 +49,6 @@ const browserBuilds = [ plugins: es2017Plugins, external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) }, - { - input: './src/index.ts', - output: [ - { - file: pkg.esm5, - format: 'es', - sourcemap: true - } - ], - plugins: es5Plugins, - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) - }, { input: './src/index.ts', output: [ diff --git a/packages/firestore/lite/package.json b/packages/firestore/lite/package.json index dbef6c78d6c..ef362535fdb 100644 --- a/packages/firestore/lite/package.json +++ b/packages/firestore/lite/package.json @@ -6,7 +6,9 @@ "module": "../dist/lite/index.browser.esm2017.js", "browser": "../dist/lite/index.browser.esm2017.js", "react-native": "../dist/lite/index.rn.esm2017.js", - "esm5": "../dist/lite/index.browser.esm5.js", "typings": "../dist/lite/index.d.ts", - "private": true + "private": true, + "engines": { + "node": ">=18.0.0" + } } diff --git a/packages/firestore/package.json b/packages/firestore/package.json index 56f88957734..5268cad97cb 100644 --- a/packages/firestore/package.json +++ b/packages/firestore/package.json @@ -2,7 +2,7 @@ "name": "@firebase/firestore", "version": "4.7.2", "engines": { - "node": ">=10.10.0" + "node": ">=18.0.0" }, "description": "The Cloud Firestore component of the Firebase JS SDK.", "author": "Firebase (https://firebase.google.com/)", @@ -62,7 +62,6 @@ "import": "./dist/index.node.mjs" }, "react-native": "./dist/index.rn.js", - "esm5": "./dist/index.esm5.js", "browser": { "require": "./dist/index.cjs.js", "import": "./dist/index.esm2017.js" @@ -76,7 +75,6 @@ "import": "./dist/lite/index.node.mjs" }, "react-native": "./dist/lite/index.rn.esm2017.js", - "esm5": "./dist/lite/index.browser.esm5.js", "browser": { "require": "./dist/lite/index.cjs.js", "import": "./dist/lite/index.browser.esm2017.js" @@ -90,7 +88,6 @@ "react-native": "dist/index.rn.js", "browser": "dist/index.esm2017.js", "module": "dist/index.esm2017.js", - "esm5": "dist/index.esm5.js", "license": "Apache-2.0", "files": [ "dist", @@ -103,7 +100,6 @@ "@firebase/webchannel-wrapper": "1.0.1", "@grpc/grpc-js": "~1.9.0", "@grpc/proto-loader": "^0.7.8", - "undici": "6.19.7", "tslib": "^2.1.0" }, "peerDependencies": { diff --git a/packages/firestore/rollup.config.js b/packages/firestore/rollup.config.js index 0f6a42205fd..c9604fee55d 100644 --- a/packages/firestore/rollup.config.js +++ b/packages/firestore/rollup.config.js @@ -32,43 +32,29 @@ import pkg from './package.json'; const sourcemaps = require('rollup-plugin-sourcemaps'); const util = require('./rollup.shared'); -const nodePlugins = function () { - return [ - typescriptPlugin({ - typescript, - tsconfigOverride: { - compilerOptions: { - target: 'es2017' - } - }, - cacheDir: tmp.dirSync(), - abortOnError: true, - transformers: [util.removeAssertTransformer] - }), - json({ preferConst: true }), - replace({ - '__GRPC_VERSION__': grpcVersion - }) - ]; -}; +const nodePlugins = [ + typescriptPlugin({ + typescript, + cacheDir: tmp.dirSync(), + abortOnError: true, + transformers: [util.removeAssertTransformer] + }), + json({ preferConst: true }), + replace({ + '__GRPC_VERSION__': grpcVersion + }) +]; -const browserPlugins = function () { - return [ - typescriptPlugin({ - typescript, - tsconfigOverride: { - compilerOptions: { - target: 'es2017' - } - }, - cacheDir: tmp.dirSync(), - abortOnError: true, - transformers: [util.removeAssertAndPrefixInternalTransformer] - }), - json({ preferConst: true }), - terser(util.manglePrivatePropertiesOptions) - ]; -}; +const browserPlugins = [ + typescriptPlugin({ + typescript, + cacheDir: tmp.dirSync(), + abortOnError: true, + transformers: [util.removeAssertAndPrefixInternalTransformer] + }), + json({ preferConst: true }), + terser(util.manglePrivatePropertiesOptions) +]; const allBuilds = [ // Intermediate Node ESM build without build target reporting @@ -81,7 +67,7 @@ const allBuilds = [ format: 'es', sourcemap: true }, - plugins: [alias(util.generateAliasConfig('node')), ...nodePlugins()], + plugins: [alias(util.generateAliasConfig('node')), ...nodePlugins], external: util.resolveNodeExterns, treeshake: { moduleSideEffects: false @@ -97,7 +83,17 @@ const allBuilds = [ sourcemap: true }, plugins: [ - ...util.es2017ToEs5Plugins(/* mangled= */ false), + typescriptPlugin({ + typescript, + tsconfigOverride: { + compilerOptions: { + allowJs: true + } + }, + include: ['dist/**/*.js'], + cacheDir: tmp.dirSync() + }), + sourcemaps(), replace(generateBuildTargetReplaceConfig('cjs', 2017)) ], external: util.resolveNodeExterns, @@ -132,26 +128,7 @@ const allBuilds = [ format: 'es', sourcemap: true }, - plugins: [alias(util.generateAliasConfig('browser')), ...browserPlugins()], - external: util.resolveBrowserExterns, - treeshake: { - moduleSideEffects: false - } - }, - // Convert es2017 build to ES5 - { - input: pkg['browser'], - output: [ - { - file: pkg['esm5'], - format: 'es', - sourcemap: true - } - ], - plugins: [ - ...util.es2017ToEs5Plugins(/* mangled= */ true), - replace(generateBuildTargetReplaceConfig('esm', 5)) - ], + plugins: [alias(util.generateAliasConfig('browser')), ...browserPlugins], external: util.resolveBrowserExterns, treeshake: { moduleSideEffects: false @@ -205,7 +182,7 @@ const allBuilds = [ }, plugins: [ alias(util.generateAliasConfig('rn')), - ...browserPlugins(), + ...browserPlugins, replace(generateBuildTargetReplaceConfig('esm', 2017)) ], external: util.resolveBrowserExterns, diff --git a/packages/firestore/rollup.config.lite.js b/packages/firestore/rollup.config.lite.js index 369a9210262..25209966fe8 100644 --- a/packages/firestore/rollup.config.lite.js +++ b/packages/firestore/rollup.config.lite.js @@ -30,40 +30,26 @@ import { generateBuildTargetReplaceConfig } from '../../scripts/build/rollup_rep const util = require('./rollup.shared'); -const nodePlugins = function () { - return [ - typescriptPlugin({ - typescript, - tsconfigOverride: { - compilerOptions: { - target: 'es2017' - } - }, - cacheDir: tmp.dirSync(), - abortOnError: true, - transformers: [util.removeAssertTransformer] - }), - json({ preferConst: true }) - ]; -}; +const nodePlugins = [ + typescriptPlugin({ + typescript, + cacheDir: tmp.dirSync(), + abortOnError: true, + transformers: [util.removeAssertTransformer] + }), + json({ preferConst: true }) +]; -const browserPlugins = function () { - return [ - typescriptPlugin({ - typescript, - tsconfigOverride: { - compilerOptions: { - target: 'es2017' - } - }, - cacheDir: tmp.dirSync(), - abortOnError: true, - transformers: [util.removeAssertAndPrefixInternalTransformer] - }), - json({ preferConst: true }), - terser(util.manglePrivatePropertiesOptions) - ]; -}; +const browserPlugins = [ + typescriptPlugin({ + typescript, + cacheDir: tmp.dirSync(), + abortOnError: true, + transformers: [util.removeAssertAndPrefixInternalTransformer] + }), + json({ preferConst: true }), + terser(util.manglePrivatePropertiesOptions) +]; const allBuilds = [ // Intermediate Node ESM build without build target reporting @@ -78,7 +64,7 @@ const allBuilds = [ }, plugins: [ alias(util.generateAliasConfig('node_lite')), - ...nodePlugins(), + ...nodePlugins, replace({ '__RUNTIME_ENV__': 'node' }) @@ -101,14 +87,13 @@ const allBuilds = [ typescriptPlugin({ typescript, compilerOptions: { - allowJs: true, - target: 'es5' + allowJs: true }, include: ['dist/lite/*.js'] }), json(), sourcemaps(), - replace(generateBuildTargetReplaceConfig('cjs', 5)) + replace(generateBuildTargetReplaceConfig('cjs', 2017)) ], external: util.resolveNodeExterns, treeshake: { @@ -144,7 +129,7 @@ const allBuilds = [ }, plugins: [ alias(util.generateAliasConfig('browser_lite')), - ...browserPlugins(), + ...browserPlugins, // setting it to empty string because browser is the default env replace({ '__RUNTIME_ENV__': '' @@ -155,25 +140,6 @@ const allBuilds = [ moduleSideEffects: false } }, - // Convert es2017 build to ES5 - { - input: path.resolve('./lite', pkg.browser), - output: [ - { - file: path.resolve('./lite', pkg.esm5), - format: 'es', - sourcemap: true - } - ], - plugins: [ - ...util.es2017ToEs5Plugins(/* mangled= */ true), - replace(generateBuildTargetReplaceConfig('esm', 5)) - ], - external: util.resolveBrowserExterns, - treeshake: { - moduleSideEffects: false - } - }, // Convert es2017 build to CJS { input: path.resolve('./lite', pkg.browser), @@ -222,7 +188,7 @@ const allBuilds = [ }, plugins: [ alias(util.generateAliasConfig('rn_lite')), - ...browserPlugins(), + ...browserPlugins, replace({ ...generateBuildTargetReplaceConfig('esm', 2017), '__RUNTIME_ENV__': 'rn' diff --git a/packages/firestore/rollup.shared.js b/packages/firestore/rollup.shared.js index 44253d24d38..1b33ddf0b1b 100644 --- a/packages/firestore/rollup.shared.js +++ b/packages/firestore/rollup.shared.js @@ -34,10 +34,9 @@ const pkg = require('./package.json'); // This file contains shared utilities for Firestore's rollup builds. // Firestore is released in a number of different build configurations: -// - Browser builds that support persistence in ES5 CJS and ES5 ESM formats and -// ES2017 in ESM format. -// - In-memory Browser builds that support persistence in ES5 CJS and ES5 ESM -// formats and ES2017 in ESM format. +// - Browser builds that support persistence in ES2017 CJS and ESM formats. +// - In-memory Browser builds that support persistence in ES2017 CJS and ESM +// formats. // - A NodeJS build that supports persistence (to be used with an IndexedDb // shim) // - A in-memory only NodeJS build @@ -248,11 +247,6 @@ exports.es2017Plugins = function (platform, mangled = false) { alias(generateAliasConfig(platform)), typescriptPlugin({ typescript, - tsconfigOverride: { - compilerOptions: { - target: 'es2017' - } - }, cacheDir: tmp.dirSync(), transformers: [removeAssertAndPrefixInternalTransformer] }), @@ -264,11 +258,6 @@ exports.es2017Plugins = function (platform, mangled = false) { alias(generateAliasConfig(platform)), typescriptPlugin({ typescript, - tsconfigOverride: { - compilerOptions: { - target: 'es2017' - } - }, cacheDir: tmp.dirSync(), transformers: [removeAssertTransformer] }), @@ -277,50 +266,6 @@ exports.es2017Plugins = function (platform, mangled = false) { } }; -exports.es2017ToEs5Plugins = function (mangled = false) { - if (mangled) { - return [ - typescriptPlugin({ - typescript, - tsconfigOverride: { - compilerOptions: { - allowJs: true - } - }, - include: ['dist/**/*.js'], - cacheDir: tmp.dirSync() - }), - terser({ - output: { - comments: 'all', - beautify: true - }, - // See comment above `manglePrivatePropertiesOptions`. This build did - // not have the identical variable name issue but we should be - // consistent. - mangle: { - reserved: ['_getProvider'] - } - }), - sourcemaps() - ]; - } else { - return [ - typescriptPlugin({ - typescript, - tsconfigOverride: { - compilerOptions: { - allowJs: true - } - }, - include: ['dist/**/*.js'], - cacheDir: tmp.dirSync() - }), - sourcemaps() - ]; - } -}; - exports.es2017PluginsCompat = function ( platform, pathTransformer, @@ -331,11 +276,6 @@ exports.es2017PluginsCompat = function ( alias(generateAliasConfig(platform)), typescriptPlugin({ typescript, - tsconfigOverride: { - compilerOptions: { - target: 'es2017' - } - }, cacheDir: tmp.dirSync(), abortOnError: true, transformers: [ @@ -351,11 +291,6 @@ exports.es2017PluginsCompat = function ( alias(generateAliasConfig(platform)), typescriptPlugin({ typescript, - tsconfigOverride: { - compilerOptions: { - target: 'es2017' - } - }, cacheDir: tmp.dirSync(), abortOnError: true, transformers: [removeAssertTransformer, pathTransformer] diff --git a/packages/firestore/src/api/cache_config.ts b/packages/firestore/src/api/cache_config.ts index fcfe429f554..072c67ec7a4 100644 --- a/packages/firestore/src/api/cache_config.ts +++ b/packages/firestore/src/api/cache_config.ts @@ -63,7 +63,9 @@ class MemoryLocalCacheImpl implements MemoryLocalCache { this._offlineComponentProvider = settings.garbageCollector._offlineComponentProvider; } else { - this._offlineComponentProvider = MemoryOfflineComponentProvider.provider; + this._offlineComponentProvider = { + build: () => new LruGcMemoryOfflineComponentProvider(undefined) + }; } } diff --git a/packages/firestore/src/core/firestore_client.ts b/packages/firestore/src/core/firestore_client.ts index 738348b016a..e2aa19aaba8 100644 --- a/packages/firestore/src/core/firestore_client.ts +++ b/packages/firestore/src/core/firestore_client.ts @@ -64,6 +64,7 @@ import { Aggregate } from './aggregate'; import { NamedQuery } from './bundle'; import { ComponentConfiguration, + LruGcMemoryOfflineComponentProvider, MemoryOfflineComponentProvider, OfflineComponentProvider, OnlineComponentProvider @@ -330,7 +331,7 @@ async function ensureOfflineComponents( logDebug(LOG_TAG, 'Using default OfflineComponentProvider'); await setOfflineComponentProvider( client, - new MemoryOfflineComponentProvider() + new LruGcMemoryOfflineComponentProvider(undefined) ); } } diff --git a/packages/firestore/src/platform/browser_lite/connection.ts b/packages/firestore/src/platform/browser_lite/connection.ts index a6464245441..573f743a882 100644 --- a/packages/firestore/src/platform/browser_lite/connection.ts +++ b/packages/firestore/src/platform/browser_lite/connection.ts @@ -24,5 +24,5 @@ export { newConnectivityMonitor } from '../browser/connection'; /** Initializes the HTTP connection for the REST API. */ export function newConnection(databaseInfo: DatabaseInfo): Connection { - return new FetchConnection(databaseInfo, fetch.bind(null)); + return new FetchConnection(databaseInfo); } diff --git a/packages/firestore/src/platform/browser_lite/fetch_connection.ts b/packages/firestore/src/platform/browser_lite/fetch_connection.ts index cad3c372ad5..d11247c8019 100644 --- a/packages/firestore/src/platform/browser_lite/fetch_connection.ts +++ b/packages/firestore/src/platform/browser_lite/fetch_connection.ts @@ -16,7 +16,6 @@ */ import { Token } from '../../api/credentials'; -import { DatabaseInfo } from '../../core/database_info'; import { Stream } from '../../remote/connection'; import { RestConnection } from '../../remote/rest_connection'; import { mapCodeFromHttpStatus } from '../../remote/rpc_error'; @@ -28,17 +27,6 @@ import { StringMap } from '../../util/types'; * (e.g. `fetch` or a polyfill). */ export class FetchConnection extends RestConnection { - /** - * @param databaseInfo - The connection info. - * @param fetchImpl - `fetch` or a Polyfill that implements the fetch API. - */ - constructor( - databaseInfo: DatabaseInfo, - private readonly fetchImpl: typeof fetch - ) { - super(databaseInfo); - } - openStream( rpcName: string, token: Token | null @@ -56,7 +44,7 @@ export class FetchConnection extends RestConnection { let response: Response; try { - response = await this.fetchImpl(url, { + response = await fetch(url, { method: 'POST', headers, body: requestJson diff --git a/packages/firestore/src/platform/node_lite/connection.ts b/packages/firestore/src/platform/node_lite/connection.ts index e85bb89bc97..7258661c184 100644 --- a/packages/firestore/src/platform/node_lite/connection.ts +++ b/packages/firestore/src/platform/node_lite/connection.ts @@ -15,8 +15,6 @@ * limitations under the License. */ -import { fetch as undiciFetch } from 'undici'; - import { DatabaseInfo } from '../../core/database_info'; import { Connection } from '../../remote/connection'; import { FetchConnection } from '../browser_lite/fetch_connection'; @@ -25,8 +23,5 @@ export { newConnectivityMonitor } from '../browser/connection'; /** Initializes the HTTP connection for the REST API. */ export function newConnection(databaseInfo: DatabaseInfo): Connection { - // undici is meant to be API compatible with `fetch`, but its type doesn't - // match 100%. - // eslint-disable-next-line @typescript-eslint/no-explicit-any - return new FetchConnection(databaseInfo, undiciFetch as any); + return new FetchConnection(databaseInfo); } diff --git a/packages/firestore/src/register.ts b/packages/firestore/src/register.ts index 3abb38c9d86..573ac6f2020 100644 --- a/packages/firestore/src/register.ts +++ b/packages/firestore/src/register.ts @@ -60,6 +60,6 @@ export function registerFirestore( ).setMultipleInstances(true) ); registerVersion(name, version, variant); - // BUILD_TARGET will be replaced by values like esm5, esm2017, cjs5, etc during the compilation + // BUILD_TARGET will be replaced by values like esm2017, cjs2017, etc during the compilation registerVersion(name, version, '__BUILD_TARGET__'); } diff --git a/packages/firestore/test/integration/api/database.test.ts b/packages/firestore/test/integration/api/database.test.ts index 7d025625fe7..81dc7362a22 100644 --- a/packages/firestore/test/integration/api/database.test.ts +++ b/packages/firestore/test/integration/api/database.test.ts @@ -2232,4 +2232,17 @@ apiDescribe('Database', persistence => { }); }); }); + + it('Lru GC is enabled by default.', () => { + const initialData = { key: 'value' }; + return withTestDb(persistence, async db => { + const docRef = doc(collection(db, 'test-collection')); + await setDoc(docRef, initialData); + return getDocFromCache(docRef).then(doc => { + expect(doc.exists()).to.be.true; + expect(doc.metadata.fromCache).to.be.true; + expect(doc.data()).to.deep.equal(initialData); + }); + }); + }); }); diff --git a/packages/firestore/test/integration/util/helpers.ts b/packages/firestore/test/integration/util/helpers.ts index 647360db463..465bc8edd61 100644 --- a/packages/firestore/test/integration/util/helpers.ts +++ b/packages/firestore/test/integration/util/helpers.ts @@ -181,9 +181,7 @@ function apiDescribeInternal( message: string, testSuite: (persistence: PersistenceMode) => void ): void { - const persistenceModes: PersistenceMode[] = [ - new MemoryEagerPersistenceMode() - ]; + const persistenceModes: PersistenceMode[] = [new MemoryLruPersistenceMode()]; if (isPersistenceAvailable()) { persistenceModes.push(new IndexedDbPersistenceMode()); } diff --git a/packages/firestore/test/unit/specs/spec_rpc_error.ts b/packages/firestore/test/unit/specs/spec_rpc_error.ts index 8d4a7073861..0560bdd65db 100644 --- a/packages/firestore/test/unit/specs/spec_rpc_error.ts +++ b/packages/firestore/test/unit/specs/spec_rpc_error.ts @@ -33,7 +33,8 @@ export class RpcError extends Error { this.code = mapRpcCodeFromCode(code); } - // TODO(mikelehen): Error is a function not a class in ES5 so extending it + // TODO(dlarocque): Improve this since we no longer target ES5. + // Error is a function not a class in ES5 so extending it // doesn't really work without hackery. Just manually set .message for now. this.message = message; } diff --git a/packages/functions-compat/package.json b/packages/functions-compat/package.json index 450850f7067..e51aa90e791 100644 --- a/packages/functions-compat/package.json +++ b/packages/functions-compat/package.json @@ -3,23 +3,21 @@ "version": "0.3.14", "description": "", "author": "Firebase (https://firebase.google.com/)", - "main": "dist/index.node.cjs.js", - "browser": "dist/index.esm2017.js", - "module": "dist/index.esm2017.js", - "esm5": "dist/index.esm5.js", + "main": "dist/index.cjs.js", + "browser": "dist/esm/index.esm2017.js", + "module": "dist/esm/index.esm2017.js", "exports": { ".": { "types": "./dist/src/index.d.ts", "node": { - "import": "./dist/node-esm/index.node.esm.js", - "require": "./dist/index.node.cjs.js" + "require": "./dist/index.cjs.js", + "import": "./dist/esm/index.esm2017.js" }, - "esm5": "./dist/index.esm5.js", "browser": { "require": "./dist/index.cjs.js", - "import": "./dist/index.esm2017.js" + "import": "./dist/esm/index.esm2017.js" }, - "default": "./dist/index.esm2017.js" + "default": "./dist/esm/index.esm2017.js" }, "./package.json": "./package.json" }, @@ -57,7 +55,7 @@ "test:all": "run-p --npm-path npm test:browser test:node", "test:browser": "karma start", "test:browser:debug": "karma start --browsers=Chrome --auto-watch", - "test:node": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'src/{,!(browser)/**/}*.test.ts' --file src/index.node.ts --config ../../config/mocharc.node.js", + "test:node": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'src/{,!(browser)/**/}*.test.ts' --config ../../config/mocharc.node.js", "test:emulator": "env FIREBASE_FUNCTIONS_HOST=http://localhost FIREBASE_FUNCTIONS_PORT=5005 run-p --npm-path npm test:node", "trusted-type-check": "tsec -p tsconfig.json --noEmit", "add-compat-overloads": "ts-node-script ../../scripts/build/create-overloads.ts -i ../functions/dist/functions-public.d.ts -o dist/src/index.d.ts -a -r Functions:types.FirebaseFunctions -r FirebaseApp:FirebaseAppCompat --moduleToEnhance @firebase/functions" @@ -75,5 +73,8 @@ ".ts" ], "reportDir": "./coverage/node" + }, + "engines": { + "node": ">=18.0.0" } } diff --git a/packages/functions-compat/rollup.config.js b/packages/functions-compat/rollup.config.js index 949aeebd513..b85c7fa65c3 100644 --- a/packages/functions-compat/rollup.config.js +++ b/packages/functions-compat/rollup.config.js @@ -25,32 +25,14 @@ const deps = Object.keys( Object.assign({}, pkg.peerDependencies, pkg.dependencies) ); -const es5BuildPlugins = [ +const buildPlugins = [ typescriptPlugin({ typescript }), - json() -]; - -const es2017BuildPlugins = [ - typescriptPlugin({ - typescript, - tsconfigOverride: { - compilerOptions: { - target: 'es2017' - } - } - }), json({ preferConst: true }) ]; -const browserBuilds = [ - { - input: 'src/index.ts', - output: { file: pkg.esm5, format: 'es', sourcemap: true }, - plugins: es5BuildPlugins, - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) - }, +const builds = [ { input: 'src/index.ts', output: { @@ -58,36 +40,19 @@ const browserBuilds = [ format: 'es', sourcemap: true }, - plugins: es2017BuildPlugins, + plugins: [...buildPlugins, emitModulePackageFile()], external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) }, { input: 'src/index.ts', output: { - file: './dist/index.cjs.js', + file: pkg.main, format: 'cjs', sourcemap: true }, - plugins: es2017BuildPlugins, - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) - } -]; - -const nodeBuilds = [ - { - input: 'src/index.node.ts', - output: [{ file: pkg.main, format: 'cjs', sourcemap: true }], - plugins: es5BuildPlugins, - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) - }, - { - input: 'src/index.node.ts', - output: [ - { file: pkg.exports['.'].node.import, format: 'es', sourcemap: true } - ], - plugins: [...es2017BuildPlugins, emitModulePackageFile()], + plugins: buildPlugins, external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) } ]; -export default [...browserBuilds, ...nodeBuilds]; +export default builds; diff --git a/packages/functions-compat/src/index.node.ts b/packages/functions-compat/src/index.node.ts deleted file mode 100644 index e7b3c108ac4..00000000000 --- a/packages/functions-compat/src/index.node.ts +++ /dev/null @@ -1,23 +0,0 @@ -/** - * @license - * Copyright 2020 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 firebase from '@firebase/app-compat'; -import { name, version } from '../package.json'; -import { registerFunctions } from './register'; - -registerFunctions(); -firebase.registerVersion(name, version, 'node'); diff --git a/packages/functions/karma.conf.js b/packages/functions/karma.conf.js index 3dc9b7d572c..db9bf05bfe0 100644 --- a/packages/functions/karma.conf.js +++ b/packages/functions/karma.conf.js @@ -26,18 +26,7 @@ module.exports = function (config) { files, // frameworks to use // available frameworks: https://npmjs.org/browse/keyword/karma-adapter - frameworks: ['mocha'], - // undici is a fetch polyfill that test helpers call for Node tests, and browser tests should - // ignore its import to avoid compilation errors in those test helpers. - webpack: { - ...webpackBase, - resolve: { - ...webpackBase.resolve, - alias: { - 'undici': false - } - } - } + frameworks: ['mocha'] }); config.set(karmaConfig); diff --git a/packages/functions/package.json b/packages/functions/package.json index dcad629250c..c739600b5ed 100644 --- a/packages/functions/package.json +++ b/packages/functions/package.json @@ -3,23 +3,21 @@ "version": "0.11.8", "description": "", "author": "Firebase (https://firebase.google.com/)", - "main": "dist/index.node.cjs.js", - "browser": "dist/index.esm2017.js", - "module": "dist/index.esm2017.js", - "esm5": "dist/index.esm.js", + "main": "dist/index.cjs.js", + "browser": "dist/esm/index.esm2017.js", + "module": "dist/esm/index.esm2017.js", "exports": { ".": { "types": "./dist/functions-public.d.ts", "node": { - "import": "./dist/esm-node/index.node.esm.js", - "require": "./dist/index.node.cjs.js" + "import": "./dist/esm/index.esm2017.js", + "require": "./dist/index.cjs.js" }, - "esm5": "./dist/index.esm.js", "browser": { "require": "./dist/index.cjs.js", - "import": "./dist/index.esm2017.js" + "import": "./dist/esm/index.esm2017.js" }, - "default": "./dist/index.esm2017.js" + "default": "./dist/esm/index.esm2017.js" }, "./package.json": "./package.json" }, @@ -38,7 +36,7 @@ "test:all": "run-p --npm-path npm test:browser test:node", "test:browser": "karma start", "test:browser:debug": "karma start --browsers=Chrome --auto-watch", - "test:node": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'src/{,!(browser)/**/}*.test.ts' --file src/index.node.ts --config ../../config/mocharc.node.js", + "test:node": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'src/{,!(browser)/**/}*.test.ts' --file src/index.ts --config ../../config/mocharc.node.js", "test:emulator": "env FIREBASE_FUNCTIONS_EMULATOR_ORIGIN=http://localhost:5005 run-p --npm-path npm test:node", "trusted-type-check": "tsec -p tsconfig.json --noEmit", "api-report": "api-extractor run --local --verbose", @@ -72,7 +70,6 @@ "@firebase/auth-interop-types": "0.2.3", "@firebase/app-check-interop-types": "0.3.2", "@firebase/util": "1.10.0", - "undici": "6.19.7", "tslib": "^2.1.0" }, "nyc": { @@ -80,5 +77,8 @@ ".ts" ], "reportDir": "./coverage/node" + }, + "engines": { + "node": ">=18.0.0" } } diff --git a/packages/functions/rollup.config.js b/packages/functions/rollup.config.js index bb5506ea9b5..8d00f21d755 100644 --- a/packages/functions/rollup.config.js +++ b/packages/functions/rollup.config.js @@ -27,35 +27,14 @@ const deps = Object.keys( Object.assign({}, pkg.peerDependencies, pkg.dependencies) ); -const es5BuildPlugins = [ +const buildPlugins = [ typescriptPlugin({ typescript }), - json() -]; - -const es2017BuildPlugins = [ - typescriptPlugin({ - typescript, - tsconfigOverride: { - compilerOptions: { - target: 'es2017' - } - } - }), json({ preferConst: true }) ]; -const browserBuilds = [ - { - input: 'src/index.ts', - output: [{ file: pkg.esm5, format: 'es', sourcemap: true }], - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), - plugins: [ - ...es5BuildPlugins, - replace(generateBuildTargetReplaceConfig('esm', 5)) - ] - }, +const builds = [ { input: 'src/index.ts', output: { @@ -65,47 +44,24 @@ const browserBuilds = [ }, external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), plugins: [ - ...es2017BuildPlugins, - replace(generateBuildTargetReplaceConfig('esm', 2017)) + ...buildPlugins, + replace(generateBuildTargetReplaceConfig('esm', 2017)), + emitModulePackageFile() ] }, { input: 'src/index.ts', output: { - file: './dist/index.cjs.js', + file: pkg.main, format: 'cjs', sourcemap: true }, external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), plugins: [ - ...es2017BuildPlugins, + ...buildPlugins, replace(generateBuildTargetReplaceConfig('cjs', 2017)) ] } ]; -const nodeBuilds = [ - { - input: 'src/index.node.ts', - output: [{ file: pkg.main, format: 'cjs', sourcemap: true }], - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), - plugins: [ - ...es5BuildPlugins, - replace(generateBuildTargetReplaceConfig('cjs', 5)) - ] - }, - { - input: 'src/index.node.ts', - output: [ - { file: pkg.exports['.'].node.import, format: 'es', sourcemap: true } - ], - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), - plugins: [ - ...es2017BuildPlugins, - replace(generateBuildTargetReplaceConfig('esm', 2017)), - emitModulePackageFile() - ] - } -]; - -export default [...browserBuilds, ...nodeBuilds]; +export default builds; diff --git a/packages/functions/src/config.ts b/packages/functions/src/config.ts index 6c4dac26e6a..8dfadb52b54 100644 --- a/packages/functions/src/config.ts +++ b/packages/functions/src/config.ts @@ -35,10 +35,7 @@ const APP_CHECK_INTERNAL_NAME: AppCheckInternalComponentName = const MESSAGING_INTERNAL_NAME: MessagingInternalComponentName = 'messaging-internal'; -export function registerFunctions( - fetchImpl: typeof fetch, - variant?: string -): void { +export function registerFunctions(variant?: string): void { const factory: InstanceFactory<'functions'> = ( container: ComponentContainer, { instanceIdentifier: regionOrCustomDomain } @@ -55,8 +52,7 @@ export function registerFunctions( authProvider, messagingProvider, appCheckProvider, - regionOrCustomDomain, - fetchImpl + regionOrCustomDomain ); }; @@ -69,6 +65,6 @@ export function registerFunctions( ); registerVersion(name, version, variant); - // BUILD_TARGET will be replaced by values like esm5, esm2017, cjs5, etc during the compilation + // BUILD_TARGET will be replaced by values like esm2017, cjs2017, etc during the compilation registerVersion(name, version, '__BUILD_TARGET__'); } diff --git a/packages/functions/src/index.node.ts b/packages/functions/src/index.node.ts deleted file mode 100644 index 6fb63173957..00000000000 --- a/packages/functions/src/index.node.ts +++ /dev/null @@ -1,23 +0,0 @@ -/** - * @license - * Copyright 2017 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 { registerFunctions } from './config'; -import { fetch as undiciFetch } from 'undici'; - -export * from './api'; - -// eslint-disable-next-line @typescript-eslint/no-explicit-any -registerFunctions(undiciFetch as any, 'node'); diff --git a/packages/functions/src/index.ts b/packages/functions/src/index.ts index 7318b3e64b7..6d404cc8245 100644 --- a/packages/functions/src/index.ts +++ b/packages/functions/src/index.ts @@ -25,4 +25,4 @@ import { registerFunctions } from './config'; export * from './api'; export * from './public-types'; -registerFunctions(fetch.bind(self)); +registerFunctions(); diff --git a/packages/functions/src/service.ts b/packages/functions/src/service.ts index c5fe7fa8a85..986dcbc735d 100644 --- a/packages/functions/src/service.ts +++ b/packages/functions/src/service.ts @@ -104,8 +104,7 @@ export class FunctionsService implements _FirebaseService { authProvider: Provider, messagingProvider: Provider, appCheckProvider: Provider, - regionOrCustomDomain: string = DEFAULT_REGION, - readonly fetchImpl: typeof fetch + regionOrCustomDomain: string = DEFAULT_REGION ) { this.contextProvider = new ContextProvider( authProvider, @@ -212,14 +211,13 @@ export function httpsCallableFromURL( async function postJSON( url: string, body: unknown, - headers: { [key: string]: string }, - fetchImpl: typeof fetch + headers: { [key: string]: string } ): Promise { headers['Content-Type'] = 'application/json'; let response: Response; try { - response = await fetchImpl(url, { + response = await fetch(url, { method: 'POST', body: JSON.stringify(body), headers @@ -296,7 +294,7 @@ async function callAtURL( const failAfterHandle = failAfter(timeout); const response = await Promise.race([ - postJSON(url, body, headers, functionsInstance.fetchImpl), + postJSON(url, body, headers), failAfterHandle.promise, functionsInstance.cancelAllRequests ]); diff --git a/packages/functions/test/utils.ts b/packages/functions/test/utils.ts index 0eb0b678c19..bcf0286b49d 100644 --- a/packages/functions/test/utils.ts +++ b/packages/functions/test/utils.ts @@ -21,7 +21,6 @@ import { FirebaseAuthInternalName } from '@firebase/auth-interop-types'; import { AppCheckInternalComponentName } from '@firebase/app-check-interop-types'; import { FunctionsService } from '../src/service'; import { connectFunctionsEmulator } from '../src/api'; -import { fetch as undiciFetch } from 'undici'; import { MessagingInternalComponentName } from '../../../packages/messaging-interop-types'; export function makeFakeApp(options: FirebaseOptions = {}): FirebaseApp { @@ -58,15 +57,12 @@ export function createTestService( new ComponentContainer('test') ) ): FunctionsService { - const fetchImpl: typeof fetch = - typeof window !== 'undefined' ? fetch.bind(window) : (undiciFetch as any); const functions = new FunctionsService( app, authProvider, messagingProvider, appCheckProvider, - region, - fetchImpl + region ); const useEmulator = !!process.env.FIREBASE_FUNCTIONS_EMULATOR_ORIGIN; if (useEmulator) { diff --git a/packages/installations-compat/package.json b/packages/installations-compat/package.json index bc663d6f2ce..44115221348 100644 --- a/packages/installations-compat/package.json +++ b/packages/installations-compat/package.json @@ -5,12 +5,10 @@ "main": "dist/index.cjs.js", "module": "dist/esm/index.esm2017.js", "browser": "dist/esm/index.esm2017.js", - "esm5": "dist/esm/index.esm.js", "exports": { ".": { "types": "./dist/src/index.d.ts", "require": "./dist/index.cjs.js", - "esm5": "./dist/esm/index.esm.js", "default": "./dist/esm/index.esm2017.js" }, "./package.json": "./package.json" diff --git a/packages/installations-compat/rollup.config.js b/packages/installations-compat/rollup.config.js index dff41008688..839c66d4413 100644 --- a/packages/installations-compat/rollup.config.js +++ b/packages/installations-compat/rollup.config.js @@ -23,45 +23,33 @@ import { emitModulePackageFile } from '../../scripts/build/rollup_emit_module_pa const deps = Object.keys({ ...pkg.peerDependencies, ...pkg.dependencies }); -const es5BuildPlugins = [typescriptPlugin({ typescript }), json()]; -const es2017BuildPlugins = [ +const buildPlugins = [ typescriptPlugin({ - typescript, - tsconfigOverride: { - compilerOptions: { - target: 'es2017' - } - } + typescript }), json({ preferConst: true }) ]; -const esmBuilds = [ - { - input: 'src/index.ts', - output: { file: pkg.esm5, format: 'es', sourcemap: true }, - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), - plugins: [...es5BuildPlugins, emitModulePackageFile()] +const esmBuild = { + input: 'src/index.ts', + output: { + file: pkg.browser, + format: 'es', + sourcemap: true }, - { - input: 'src/index.ts', - output: { - file: pkg.browser, - format: 'es', - sourcemap: true - }, - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), - plugins: [...es2017BuildPlugins, emitModulePackageFile()] - } -]; + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), + plugins: [...buildPlugins, emitModulePackageFile()] +}; -const cjsBuilds = [ - { - input: 'src/index.ts', - output: { file: pkg.main, format: 'cjs', sourcemap: true }, - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), - plugins: es5BuildPlugins - } -]; +const cjsBuild = { + input: 'src/index.ts', + output: { + file: pkg.main, + format: 'cjs', + sourcemap: true + }, + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), + plugins: buildPlugins +}; -export default [...esmBuilds, ...cjsBuilds]; +export default [esmBuild, cjsBuild]; diff --git a/packages/installations/package.json b/packages/installations/package.json index ff6c74bd23d..e6093c759d6 100644 --- a/packages/installations/package.json +++ b/packages/installations/package.json @@ -5,12 +5,10 @@ "main": "dist/index.cjs.js", "module": "dist/esm/index.esm2017.js", "browser": "dist/esm/index.esm2017.js", - "esm5": "dist/esm/index.esm.js", "exports": { ".": { "types": "./dist/installations-public.d.ts", "require": "./dist/index.cjs.js", - "esm5": "./dist/esm/index.esm.js", "default": "./dist/esm/index.esm2017.js" }, "./package.json": "./package.json" diff --git a/packages/installations/rollup.config.js b/packages/installations/rollup.config.js index 70628504fdb..7d083c63320 100644 --- a/packages/installations/rollup.config.js +++ b/packages/installations/rollup.config.js @@ -25,57 +25,40 @@ import { emitModulePackageFile } from '../../scripts/build/rollup_emit_module_pa const deps = [...Object.keys({ ...pkg.peerDependencies, ...pkg.dependencies })]; -const es5BuildPlugins = [typescriptPlugin({ typescript }), json()]; - -const es2017BuildPlugins = [ +const buildPlugins = [ typescriptPlugin({ - typescript, - tsconfigOverride: { - compilerOptions: { - target: 'es2017' - } - } + typescript }), json({ preferConst: true }) ]; -const esmBuilds = [ - { - input: 'src/index.ts', - output: [{ file: pkg.esm5, format: 'es', sourcemap: true }], - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), - plugins: [ - ...es5BuildPlugins, - replace(generateBuildTargetReplaceConfig('esm', 5)), - emitModulePackageFile() - ] +const esmBuild = { + input: 'src/index.ts', + output: { + file: pkg.browser, + format: 'es', + sourcemap: true }, - { - input: 'src/index.ts', - output: { - file: pkg.browser, - format: 'es', - sourcemap: true - }, - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), - plugins: [ - ...es2017BuildPlugins, - replace(generateBuildTargetReplaceConfig('esm', 2017)), - emitModulePackageFile() - ] - } -]; + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), + plugins: [ + ...buildPlugins, + replace(generateBuildTargetReplaceConfig('esm', 2017)), + emitModulePackageFile() + ] +}; -const cjsBuilds = [ - { - input: 'src/index.ts', - output: [{ file: pkg.main, format: 'cjs', sourcemap: true }], - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), - plugins: [ - ...es5BuildPlugins, - replace(generateBuildTargetReplaceConfig('cjs', 5)) - ] - } -]; +const cjsBuild = { + input: 'src/index.ts', + output: { + file: pkg.main, + format: 'cjs', + sourcemap: true + }, + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), + plugins: [ + ...buildPlugins, + replace(generateBuildTargetReplaceConfig('cjs', 2017)) + ] +}; -export default [...esmBuilds, ...cjsBuilds]; +export default [esmBuild, cjsBuild]; diff --git a/packages/installations/src/index.ts b/packages/installations/src/index.ts index c16abc2b0b1..5a70ef10846 100644 --- a/packages/installations/src/index.ts +++ b/packages/installations/src/index.ts @@ -31,5 +31,5 @@ export * from './interfaces/public-types'; registerInstallations(); registerVersion(name, version); -// BUILD_TARGET will be replaced by values like esm5, esm2017, cjs5, etc during the compilation +// BUILD_TARGET will be replaced by values like esm2017, cjs2017, etc during the compilation registerVersion(name, version, '__BUILD_TARGET__'); diff --git a/packages/installations/src/testing/compare-headers.ts b/packages/installations/src/testing/compare-headers.ts index 5b93c14933e..6c3681b3ca0 100644 --- a/packages/installations/src/testing/compare-headers.ts +++ b/packages/installations/src/testing/compare-headers.ts @@ -18,6 +18,7 @@ import { AssertionError, expect } from 'chai'; // Trick TS since it's set to target ES5. +// TODO(dlarocque): Improve this since we no longer target ES5. declare class HeadersWithEntries extends Headers { entries?(): Iterable<[string, string]>; } diff --git a/packages/logger/package.json b/packages/logger/package.json index 4a01f8d5593..14131f73258 100644 --- a/packages/logger/package.json +++ b/packages/logger/package.json @@ -5,12 +5,10 @@ "author": "Firebase (https://firebase.google.com/)", "main": "dist/index.cjs.js", "module": "dist/esm/index.esm2017.js", - "esm5": "dist/esm/index.esm5.js", "exports": { ".": { "types": "./dist/index.d.ts", "require": "./dist/index.cjs.js", - "esm5": "./dist/esm/index.esm5.js", "default": "./dist/esm/index.esm2017.js" }, "./package.json": "./package.json" @@ -55,5 +53,8 @@ ".ts" ], "reportDir": "./coverage/node" + }, + "engines": { + "node": ">=18.0.0" } } diff --git a/packages/logger/rollup.config.js b/packages/logger/rollup.config.js index e6bfbb4efe5..0089b01c801 100644 --- a/packages/logger/rollup.config.js +++ b/packages/logger/rollup.config.js @@ -20,53 +20,32 @@ import typescript from 'typescript'; import pkg from './package.json'; import { emitModulePackageFile } from '../../scripts/build/rollup_emit_module_package_file'; -const es5BuildPlugins = [ - typescriptPlugin({ - typescript - }) -]; - -const es2017BuildPlugins = [ - typescriptPlugin({ - typescript, - tsconfigOverride: { - compilerOptions: { - target: 'es2017' - } - } - }) -]; +const buildPlugins = [typescriptPlugin({ typescript })]; const deps = Object.keys( Object.assign({}, pkg.peerDependencies, pkg.dependencies) ); -const esmBuilds = [ - { - input: 'index.ts', - output: { file: pkg.esm5, format: 'es', sourcemap: true }, - plugins: [...es5BuildPlugins, emitModulePackageFile()], - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) +const esmBuild = { + input: 'index.ts', + output: { + file: pkg.module, + format: 'es', + sourcemap: true }, - { - input: 'index.ts', - output: { - file: pkg.module, - format: 'es', - sourcemap: true - }, - plugins: [...es2017BuildPlugins, emitModulePackageFile()], - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) - } -]; + plugins: [...buildPlugins, emitModulePackageFile()], + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) +}; -const cjsBuilds = [ - { - input: 'index.ts', - output: { file: pkg.main, format: 'cjs', sourcemap: true }, - plugins: es5BuildPlugins, - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) - } -]; +const cjsBuild = { + input: 'index.ts', + output: { + file: pkg.main, + format: 'cjs', + sourcemap: true + }, + plugins: buildPlugins, + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) +}; -export default [...esmBuilds, ...cjsBuilds]; +export default [esmBuild, cjsBuild]; diff --git a/packages/messaging-compat/package.json b/packages/messaging-compat/package.json index 3d529a8eb5b..628d5801668 100644 --- a/packages/messaging-compat/package.json +++ b/packages/messaging-compat/package.json @@ -7,12 +7,10 @@ "main": "dist/index.cjs.js", "browser": "dist/esm/index.esm2017.js", "module": "dist/esm/index.esm2017.js", - "esm5": "dist/esm/index.esm.js", "exports": { ".": { "types": "./dist/src/index.d.ts", "require": "./dist/index.cjs.js", - "esm5": "./dist/esm/index.esm.js", "default": "./dist/esm/index.esm2017.js" }, "./package.json": "./package.json" diff --git a/packages/messaging-compat/rollup.config.js b/packages/messaging-compat/rollup.config.js index 2bc0cecded0..b8a320641fc 100644 --- a/packages/messaging-compat/rollup.config.js +++ b/packages/messaging-compat/rollup.config.js @@ -25,51 +25,33 @@ const deps = Object.keys( Object.assign({}, pkg.peerDependencies, pkg.dependencies) ); -const es5BuildPlugins = [ +const buildPlugins = [ typescriptPlugin({ typescript }), - json() -]; - -const es2017BuildPlugins = [ - typescriptPlugin({ - typescript, - tsconfigOverride: { - compilerOptions: { - target: 'es2017' - } - } - }), json({ preferConst: true }) ]; -const esmBuilds = [ - { - input: 'src/index.ts', - output: { file: pkg.esm5, format: 'es', sourcemap: true }, - plugins: [...es5BuildPlugins, emitModulePackageFile()], - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) +const esmBuild = { + input: 'src/index.ts', + output: { + file: pkg.browser, + format: 'es', + sourcemap: true }, - { - input: 'src/index.ts', - output: { - file: pkg.browser, - format: 'es', - sourcemap: true - }, - plugins: [...es2017BuildPlugins, emitModulePackageFile()], - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) - } -]; + plugins: [...buildPlugins, emitModulePackageFile()], + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) +}; -const cjsBuilds = [ - { - input: 'src/index.ts', - output: { file: pkg.main, format: 'cjs', sourcemap: true }, - plugins: es5BuildPlugins, - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) - } -]; +const cjsBuild = { + input: 'src/index.ts', + output: { + file: pkg.main, + format: 'cjs', + sourcemap: true + }, + plugins: buildPlugins, + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) +}; -export default [...esmBuilds, ...cjsBuilds]; +export default [esmBuild, cjsBuild]; diff --git a/packages/messaging/package.json b/packages/messaging/package.json index 674b2feb246..e191118271f 100644 --- a/packages/messaging/package.json +++ b/packages/messaging/package.json @@ -8,13 +8,11 @@ "module": "dist/esm/index.esm2017.js", "sw": "dist/esm/index.sw.esm2017.js", "sw-main": "dist/index.sw.cjs", - "esm5": "dist/esm/index.esm.js", "exports": { ".": { "types": "./dist/index-public.d.ts", "require": "./dist/index.cjs.js", "module": "./dist/esm/index.esm2017.js", - "esm5": "./dist/esm/index.esm.js", "default": "./dist/esm/index.esm2017.js" }, "./sw": { diff --git a/packages/messaging/rollup.config.js b/packages/messaging/rollup.config.js index 297dc00c46f..506f0d30261 100644 --- a/packages/messaging/rollup.config.js +++ b/packages/messaging/rollup.config.js @@ -27,36 +27,14 @@ const deps = Object.keys( Object.assign({}, pkg.peerDependencies, pkg.dependencies) ); -const es5BuildPlugins = [ +const buildPlugins = [ typescriptPlugin({ typescript }), - json() -]; - -const es2017BuildPlugins = [ - typescriptPlugin({ - typescript, - tsconfigOverride: { - compilerOptions: { - target: 'es2017' - } - } - }), json({ preferConst: true }) ]; const esmBuilds = [ - { - input: 'src/index.ts', - output: { file: pkg.esm5, format: 'es', sourcemap: true }, - plugins: [ - ...es5BuildPlugins, - replace(generateBuildTargetReplaceConfig('esm', 5)), - emitModulePackageFile() - ], - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) - }, { input: 'src/index.ts', output: { @@ -65,7 +43,7 @@ const esmBuilds = [ sourcemap: true }, plugins: [ - ...es2017BuildPlugins, + ...buildPlugins, replace(generateBuildTargetReplaceConfig('esm', 2017)), emitModulePackageFile() ], @@ -74,8 +52,12 @@ const esmBuilds = [ // sw builds { input: 'src/index.sw.ts', - output: { file: pkg.sw, format: 'es', sourcemap: true }, - plugins: es2017BuildPlugins, + output: { + file: pkg.sw, + format: 'es', + sourcemap: true + }, + plugins: buildPlugins, external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) } ]; @@ -83,10 +65,14 @@ const esmBuilds = [ const cjsBuilds = [ { input: 'src/index.ts', - output: [{ file: pkg.main, format: 'cjs', sourcemap: true }], + output: { + file: pkg.main, + format: 'cjs', + sourcemap: true + }, plugins: [ - ...es5BuildPlugins, - replace(generateBuildTargetReplaceConfig('cjs', 5)) + ...buildPlugins, + replace(generateBuildTargetReplaceConfig('cjs', 2017)) ], external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) }, @@ -95,12 +81,13 @@ const cjsBuilds = [ // builds (contingent on updating the `idb` dependency). When we add // ESM Node builds, test with Nuxt and other SSR frameworks to see if // this can then be removed. + // TODO(dlarocque): ask Christina about this { input: 'src/index.sw.ts', output: { file: pkg['sw-main'], format: 'cjs', sourcemap: true }, plugins: [ - ...es5BuildPlugins, - replace(generateBuildTargetReplaceConfig('cjs', 5)) + ...buildPlugins, + replace(generateBuildTargetReplaceConfig('cjs', 2017)) ], external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) } diff --git a/packages/messaging/src/helpers/register.ts b/packages/messaging/src/helpers/register.ts index 7a9176f96d2..ef28cd2edad 100644 --- a/packages/messaging/src/helpers/register.ts +++ b/packages/messaging/src/helpers/register.ts @@ -104,7 +104,7 @@ export function registerMessagingInWindow(): void { ); registerVersion(name, version); - // BUILD_TARGET will be replaced by values like esm5, esm2017, cjs5, etc during the compilation + // BUILD_TARGET will be replaced by values like esm2017, cjs2017, etc during the compilation registerVersion(name, version, '__BUILD_TARGET__'); } diff --git a/packages/messaging/src/testing/compare-headers.ts b/packages/messaging/src/testing/compare-headers.ts index 6f760caf32d..4e6ea3e489d 100644 --- a/packages/messaging/src/testing/compare-headers.ts +++ b/packages/messaging/src/testing/compare-headers.ts @@ -20,6 +20,7 @@ import './setup'; import { expect } from 'chai'; // Trick TS since it's set to target ES5. +// TODO(dlarocque): Improve this since we no longer target ES5. declare class HeadersWithEntries extends Headers { entries?(): Iterable<[string, string]>; } diff --git a/packages/performance-compat/package.json b/packages/performance-compat/package.json index 72a12d37042..0e657021ff6 100644 --- a/packages/performance-compat/package.json +++ b/packages/performance-compat/package.json @@ -6,12 +6,10 @@ "main": "dist/index.cjs.js", "browser": "dist/esm/index.esm2017.js", "module": "dist/esm/index.esm2017.js", - "esm5": "dist/esm/index.esm5.js", "exports": { ".": { "types": "./dist/src/index.d.ts", "require": "./dist/index.cjs.js", - "esm5": "./dist/esm/index.esm5.js", "default": "./dist/esm/index.esm2017.js" }, "./package.json": "./package.json" diff --git a/packages/performance-compat/rollup.config.js b/packages/performance-compat/rollup.config.js index d64b7bb89e5..e52495c401e 100644 --- a/packages/performance-compat/rollup.config.js +++ b/packages/performance-compat/rollup.config.js @@ -25,14 +25,7 @@ const deps = Object.keys( Object.assign({}, pkg.peerDependencies, pkg.dependencies) ); -const es5BuildPlugins = [ - typescriptPlugin({ - typescript - }), - json() -]; - -const es2017BuildPlugins = [ +const buildPlugins = [ typescriptPlugin({ typescript, tsconfigOverride: { @@ -46,32 +39,26 @@ const es2017BuildPlugins = [ }) ]; -const esmBuilds = [ - { - input: 'src/index.ts', - output: { file: pkg.esm5, format: 'es', sourcemap: true }, - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), - plugins: [...es5BuildPlugins, emitModulePackageFile()] +const esmBuild = { + input: 'src/index.ts', + output: { + file: pkg.browser, + format: 'es', + sourcemap: true }, - { - input: 'src/index.ts', - output: { - file: pkg.browser, - format: 'es', - sourcemap: true - }, - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), - plugins: [...es2017BuildPlugins, emitModulePackageFile()] - } -]; + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), + plugins: [...buildPlugins, emitModulePackageFile()] +}; -const cjsBuilds = [ - { - input: 'src/index.ts', - output: { file: pkg.main, format: 'cjs', sourcemap: true }, - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), - plugins: es5BuildPlugins - } -]; +const cjsBuild = { + input: 'src/index.ts', + output: { + file: pkg.main, + format: 'cjs', + sourcemap: true + }, + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), + plugins: buildPlugins +}; -export default [...esmBuilds, ...cjsBuilds]; +export default [esmBuild, cjsBuild]; diff --git a/packages/performance/package.json b/packages/performance/package.json index de60407f2d4..7748cf3d3aa 100644 --- a/packages/performance/package.json +++ b/packages/performance/package.json @@ -6,12 +6,10 @@ "main": "dist/index.cjs.js", "browser": "dist/esm/index.esm2017.js", "module": "dist/esm/index.esm2017.js", - "esm5": "dist/esm/index.esm.js", "exports": { ".": { "types": "./dist/src/index.d.ts", "require": "./dist/index.cjs.js", - "esm5": "./dist/esm/index.esm.js", "default": "./dist/esm/index.esm2017.js" }, "./package.json": "./package.json" diff --git a/packages/performance/rollup.config.js b/packages/performance/rollup.config.js index 4816210933d..4752b5cfc02 100644 --- a/packages/performance/rollup.config.js +++ b/packages/performance/rollup.config.js @@ -27,52 +27,36 @@ const deps = Object.keys( Object.assign({}, pkg.peerDependencies, pkg.dependencies) ); -const es5BuildPlugins = [typescriptPlugin({ typescript }), json()]; -const es2017BuildPlugins = [ +const buildPlugins = [ typescriptPlugin({ - typescript, - tsconfigOverride: { - compilerOptions: { - target: 'es2017' - } - } + typescript }), json({ preferConst: true }) ]; -const esmBuilds = [ - { - input: 'src/index.ts', - output: [{ file: pkg.esm5, format: 'es', sourcemap: true }], - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), - plugins: [ - ...es5BuildPlugins, - replace(generateBuildTargetReplaceConfig('esm', 5)), - emitModulePackageFile() - ] - }, - { - input: 'src/index.ts', - output: [{ file: pkg.browser, format: 'es', sourcemap: true }], - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), - plugins: [ - ...es2017BuildPlugins, - replace(generateBuildTargetReplaceConfig('esm', 2017)), - emitModulePackageFile() - ] - } -]; +const esmBuild = { + input: 'src/index.ts', + output: [{ file: pkg.browser, format: 'es', sourcemap: true }], + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), + plugins: [ + ...buildPlugins, + replace(generateBuildTargetReplaceConfig('esm', 2017)), + emitModulePackageFile() + ] +}; -const cjsBuilds = [ - { - input: 'src/index.ts', - output: [{ file: pkg.main, format: 'cjs', sourcemap: true }], - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), - plugins: [ - ...es5BuildPlugins, - replace(generateBuildTargetReplaceConfig('cjs', 5)) - ] - } -]; +const cjsBuild = { + input: 'src/index.ts', + output: { + file: pkg.main, + format: 'cjs', + sourcemap: true + }, + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), + plugins: [ + ...buildPlugins, + replace(generateBuildTargetReplaceConfig('cjs', 5)) + ] +}; -export default [...esmBuilds, ...cjsBuilds]; +export default [esmBuild, cjsBuild]; diff --git a/packages/performance/src/index.ts b/packages/performance/src/index.ts index 4d3713f0614..4ccb499b368 100644 --- a/packages/performance/src/index.ts +++ b/packages/performance/src/index.ts @@ -137,7 +137,7 @@ function registerPerformance(): void { new Component('performance', factory, ComponentType.PUBLIC) ); registerVersion(name, version); - // BUILD_TARGET will be replaced by values like esm5, esm2017, cjs5, etc during the compilation + // BUILD_TARGET will be replaced by values like esm2017, cjs2017, etc during the compilation registerVersion(name, version, '__BUILD_TARGET__'); } diff --git a/packages/remote-config-compat/package.json b/packages/remote-config-compat/package.json index 1ea2ed030d5..40c7bd6fc9c 100644 --- a/packages/remote-config-compat/package.json +++ b/packages/remote-config-compat/package.json @@ -6,12 +6,10 @@ "main": "dist/index.cjs.js", "browser": "dist/esm/index.esm2017.js", "module": "dist/esm/index.esm2017.js", - "esm5": "dist/esm/index.esm5.js", "exports": { ".": { "types": "./dist/src/index.d.ts", "require": "./dist/index.cjs.js", - "esm5": "./dist/esm/index.esm5.js", "default": "./dist/esm/index.esm2017.js" }, "./package.json": "./package.json" diff --git a/packages/remote-config-compat/rollup.config.js b/packages/remote-config-compat/rollup.config.js index d64b7bb89e5..e52495c401e 100644 --- a/packages/remote-config-compat/rollup.config.js +++ b/packages/remote-config-compat/rollup.config.js @@ -25,14 +25,7 @@ const deps = Object.keys( Object.assign({}, pkg.peerDependencies, pkg.dependencies) ); -const es5BuildPlugins = [ - typescriptPlugin({ - typescript - }), - json() -]; - -const es2017BuildPlugins = [ +const buildPlugins = [ typescriptPlugin({ typescript, tsconfigOverride: { @@ -46,32 +39,26 @@ const es2017BuildPlugins = [ }) ]; -const esmBuilds = [ - { - input: 'src/index.ts', - output: { file: pkg.esm5, format: 'es', sourcemap: true }, - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), - plugins: [...es5BuildPlugins, emitModulePackageFile()] +const esmBuild = { + input: 'src/index.ts', + output: { + file: pkg.browser, + format: 'es', + sourcemap: true }, - { - input: 'src/index.ts', - output: { - file: pkg.browser, - format: 'es', - sourcemap: true - }, - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), - plugins: [...es2017BuildPlugins, emitModulePackageFile()] - } -]; + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), + plugins: [...buildPlugins, emitModulePackageFile()] +}; -const cjsBuilds = [ - { - input: 'src/index.ts', - output: { file: pkg.main, format: 'cjs', sourcemap: true }, - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), - plugins: es5BuildPlugins - } -]; +const cjsBuild = { + input: 'src/index.ts', + output: { + file: pkg.main, + format: 'cjs', + sourcemap: true + }, + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), + plugins: buildPlugins +}; -export default [...esmBuilds, ...cjsBuilds]; +export default [esmBuild, cjsBuild]; diff --git a/packages/remote-config/package.json b/packages/remote-config/package.json index c38dbc0ef26..f089e972b49 100644 --- a/packages/remote-config/package.json +++ b/packages/remote-config/package.json @@ -6,12 +6,10 @@ "main": "dist/index.cjs.js", "browser": "dist/esm/index.esm2017.js", "module": "dist/esm/index.esm2017.js", - "esm5": "dist/esm/index.esm.js", "exports": { ".": { "types": "./dist/remote-config-public.d.ts", "require": "./dist/index.cjs.js", - "esm5": "./dist/esm/index.esm.js", "default": "./dist/esm/index.esm2017.js" }, "./package.json": "./package.json" diff --git a/packages/remote-config/rollup.config.js b/packages/remote-config/rollup.config.js index dba933fa417..a7209c67e09 100644 --- a/packages/remote-config/rollup.config.js +++ b/packages/remote-config/rollup.config.js @@ -26,68 +26,44 @@ import pkg from './package.json'; const deps = Object.keys( Object.assign({}, pkg.peerDependencies, pkg.dependencies) ); -/** - * ES5 Builds - */ -const es5BuildPlugins = [ - typescriptPlugin({ - typescript - }), - json() -]; -const es2017BuildPlugins = [ +const buildPlugins = [ typescriptPlugin({ - typescript, - tsconfigOverride: { - compilerOptions: { - target: 'es2017' - } - } + typescript }), json({ preferConst: true }) ]; -const esmBuilds = [ - { - input: 'src/index.ts', - output: [{ file: pkg.esm5, format: 'es', sourcemap: true }], - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), - plugins: [ - ...es5BuildPlugins, - replace(generateBuildTargetReplaceConfig('esm', 5)), - emitModulePackageFile() - ] +const esmBuild = { + /** + * Browser Build + */ + input: 'src/index.ts', + output: { + file: pkg.browser, + format: 'es', + sourcemap: true }, - { - /** - * Browser Build - */ - input: 'src/index.ts', - output: { - file: pkg.browser, - format: 'es', - sourcemap: true - }, - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), - plugins: [ - ...es2017BuildPlugins, - replace(generateBuildTargetReplaceConfig('esm', 2017)), - emitModulePackageFile() - ] - } -]; + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), + plugins: [ + ...buildPlugins, + replace(generateBuildTargetReplaceConfig('esm', 2017)), + emitModulePackageFile() + ] +}; -const cjsBuilds = [ - { - input: 'src/index.ts', - output: [{ file: pkg.main, format: 'cjs', sourcemap: true }], - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), - plugins: [ - ...es5BuildPlugins, - replace(generateBuildTargetReplaceConfig('cjs', 5)) - ] - } -]; +const cjsBuild = { + input: 'src/index.ts', + output: { + file: pkg.main, + format: 'cjs', + sourcemap: true + }, + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), + plugins: [ + ...buildPlugins, + replace(generateBuildTargetReplaceConfig('cjs', 2017)) + ] +}; -export default [...esmBuilds, ...cjsBuilds]; +export default [esmBuild, cjsBuild]; diff --git a/packages/remote-config/src/register.ts b/packages/remote-config/src/register.ts index ac8a8aae755..ff83e761888 100644 --- a/packages/remote-config/src/register.ts +++ b/packages/remote-config/src/register.ts @@ -52,7 +52,7 @@ export function registerRemoteConfig(): void { ); registerVersion(packageName, version); - // BUILD_TARGET will be replaced by values like esm5, esm2017, cjs5, etc during the compilation + // BUILD_TARGET will be replaced by values like esm2017, cjs2017, etc during the compilation registerVersion(packageName, version, '__BUILD_TARGET__'); function remoteConfigFactory( diff --git a/packages/rules-unit-testing/package.json b/packages/rules-unit-testing/package.json index 70e5b522683..585a0efc5e8 100644 --- a/packages/rules-unit-testing/package.json +++ b/packages/rules-unit-testing/package.json @@ -20,7 +20,7 @@ "./package.json": "./package.json" }, "engines": { - "node": ">=10.10.0" + "node": ">=18.0.0" }, "files": [ "dist" @@ -53,9 +53,5 @@ "typings": "dist/index.d.ts", "bugs": { "url": "https://github.com/firebase/firebase-js-sdk/issues" - }, - "dependencies": { - "node-fetch": "2.6.7", - "@types/node-fetch": "2.6.4" } } diff --git a/packages/rules-unit-testing/rollup.config.js b/packages/rules-unit-testing/rollup.config.js index bd56861015b..5811401fb74 100644 --- a/packages/rules-unit-testing/rollup.config.js +++ b/packages/rules-unit-testing/rollup.config.js @@ -20,23 +20,12 @@ import pkg from './package.json'; import typescript from 'typescript'; import { emitModulePackageFile } from '../../scripts/build/rollup_emit_module_package_file'; -const plugins = [ +const buildPlugins = [ typescriptPlugin({ typescript }) ]; -const es2017BuildPlugins = [ - typescriptPlugin({ - typescript, - tsconfigOverride: { - compilerOptions: { - target: 'es2017' - } - } - }) -]; - const deps = Object.keys( Object.assign({}, pkg.peerDependencies, pkg.dependencies) ); @@ -44,16 +33,22 @@ const deps = Object.keys( export default [ { input: 'index.ts', - output: [{ file: pkg.main, format: 'cjs', sourcemap: true }], - plugins: [...plugins], + output: { + file: pkg.main, + format: 'cjs', + sourcemap: true + }, + plugins: [...buildPlugins], external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) }, { input: 'index.ts', - output: [ - { file: pkg.exports['.'].node.import, format: 'es', sourcemap: true } - ], - plugins: [...es2017BuildPlugins, emitModulePackageFile()], + output: { + file: pkg.exports['.'].node.import, + format: 'es', + sourcemap: true + }, + plugins: [...buildPlugins, emitModulePackageFile()], external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) } ]; diff --git a/packages/rules-unit-testing/src/impl/discovery.ts b/packages/rules-unit-testing/src/impl/discovery.ts index 9798f017241..3c7c20fedad 100644 --- a/packages/rules-unit-testing/src/impl/discovery.ts +++ b/packages/rules-unit-testing/src/impl/discovery.ts @@ -16,7 +16,6 @@ */ import { EmulatorConfig, HostAndPort } from '../public_types'; -import nodeFetch from 'node-fetch'; import { makeUrl, fixHostname } from './url'; /** @@ -27,9 +26,9 @@ import { makeUrl, fixHostname } from './url'; */ export async function discoverEmulators( hub: HostAndPort, - fetch: typeof nodeFetch = nodeFetch + fetchImpl: typeof fetch = fetch ): Promise { - const res = await fetch(makeUrl(hub, '/emulators')); + const res = await fetchImpl(makeUrl(hub, '/emulators')); if (!res.ok) { throw new Error( `HTTP Error ${res.status} when attempting to reach Emulator Hub at ${res.url}, are you sure it is running?` diff --git a/packages/rules-unit-testing/src/impl/rules.ts b/packages/rules-unit-testing/src/impl/rules.ts index 7d4d900367f..fefeb586233 100644 --- a/packages/rules-unit-testing/src/impl/rules.ts +++ b/packages/rules-unit-testing/src/impl/rules.ts @@ -17,7 +17,6 @@ import { HostAndPort } from '../public_types'; import { makeUrl } from './url'; -import fetch from 'node-fetch'; /** * @private diff --git a/packages/rules-unit-testing/src/impl/test_environment.ts b/packages/rules-unit-testing/src/impl/test_environment.ts index cb325912c29..eaafee85060 100644 --- a/packages/rules-unit-testing/src/impl/test_environment.ts +++ b/packages/rules-unit-testing/src/impl/test_environment.ts @@ -15,7 +15,6 @@ * limitations under the License. */ -import fetch from 'node-fetch'; import firebase from 'firebase/compat/app'; import 'firebase/compat/firestore'; import 'firebase/compat/database'; @@ -126,7 +125,7 @@ export class RulesTestEnvironmentImpl implements RulesTestEnvironment { return this.withSecurityRulesDisabled(async context => { const { items } = await context.storage().ref().listAll(); await Promise.all( - items.map(item => { + items.map((item: { delete: () => any }) => { return item.delete(); }) ); diff --git a/packages/rules-unit-testing/src/util.ts b/packages/rules-unit-testing/src/util.ts index c96b22d8597..abcad41ef9b 100644 --- a/packages/rules-unit-testing/src/util.ts +++ b/packages/rules-unit-testing/src/util.ts @@ -21,7 +21,6 @@ import { } from './impl/discovery'; import { fixHostname, makeUrl } from './impl/url'; import { HostAndPort } from './public_types'; -import fetch from 'node-fetch'; /** * Run a setup function with background Cloud Functions triggers disabled. This can be used to diff --git a/packages/rules-unit-testing/test/impl/discovery.test.ts b/packages/rules-unit-testing/test/impl/discovery.test.ts index a2ac2be767b..39b5628ddc2 100644 --- a/packages/rules-unit-testing/test/impl/discovery.test.ts +++ b/packages/rules-unit-testing/test/impl/discovery.test.ts @@ -71,7 +71,7 @@ describe('discoverEmulators()', () => { // Connect to port:0. Should always fail (although error codes may differ among OSes). await expect( discoverEmulators({ host: '127.0.0.1', port: 0 }) - ).to.be.rejectedWith(/EADDRNOTAVAIL|ECONNREFUSED/); + ).to.be.rejectedWith(/EADDRNOTAVAIL|ECONNREFUSED|fetch failed/); }); it('throws if response status is not 2xx', async () => { diff --git a/packages/rules-unit-testing/test/util.test.ts b/packages/rules-unit-testing/test/util.test.ts index 9dc778fb93e..e3b514d6a10 100644 --- a/packages/rules-unit-testing/test/util.test.ts +++ b/packages/rules-unit-testing/test/util.test.ts @@ -165,7 +165,7 @@ describe('assertFails()', () => { describe('withFunctionTriggersDisabled()', () => { it('disabling function triggers does not throw, returns value', async function () { - const fetchSpy = sinon.spy(require('node-fetch'), 'default'); + const fetchSpy = sinon.spy(globalThis, 'fetch'); const res = await withFunctionTriggersDisabled(() => { return Promise.resolve(1234); @@ -176,7 +176,7 @@ describe('withFunctionTriggersDisabled()', () => { }); it('disabling function triggers always re-enables, event when the function throws', async function () { - const fetchSpy = sinon.spy(require('node-fetch'), 'default'); + const fetchSpy = sinon.spy(globalThis, 'fetch'); const res = withFunctionTriggersDisabled(() => { throw new Error('I throw!'); diff --git a/packages/storage-compat/package.json b/packages/storage-compat/package.json index 3bc74ab1a54..35bb7d57f9a 100644 --- a/packages/storage-compat/package.json +++ b/packages/storage-compat/package.json @@ -6,12 +6,10 @@ "main": "./dist/index.cjs.js", "browser": "./dist/esm/index.esm2017.js", "module": "./dist/esm/index.esm2017.js", - "esm5": "./dist/esm/index.esm5.js", "exports": { ".": { "types": "./dist/src/index.d.ts", "require": "./dist/index.cjs.js", - "esm5": "./dist/esm/index.esm5.js", "default": "./dist/esm/index.esm2017.js" }, "./package.json": "./package.json" @@ -63,5 +61,8 @@ }, "bugs": { "url": "https://github.com/firebase/firebase-js-sdk/issues" + }, + "engines": { + "node": ">=18.0.0" } } diff --git a/packages/storage-compat/rollup.config.js b/packages/storage-compat/rollup.config.js index 5aad0883255..59f6282bf5e 100644 --- a/packages/storage-compat/rollup.config.js +++ b/packages/storage-compat/rollup.config.js @@ -25,15 +25,7 @@ const deps = Object.keys( Object.assign({}, pkg.peerDependencies, pkg.dependencies) ); -const es5BuildPlugins = [ - typescriptPlugin({ - typescript, - abortOnError: false - }), - json() -]; - -const es2017BuildPlugins = [ +const buildPlugins = [ typescriptPlugin({ typescript, abortOnError: false, @@ -46,41 +38,26 @@ const es2017BuildPlugins = [ json({ preferConst: true }) ]; -const esmBuilds = [ - { - input: './src/index.ts', - output: { - file: pkg.esm5, - format: 'es', - sourcemap: true - }, - plugins: [...es5BuildPlugins, emitModulePackageFile()], - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) +const esmBuild = { + input: './src/index.ts', + output: { + file: pkg.browser, + format: 'es', + sourcemap: true }, - { - input: './src/index.ts', - output: { - file: pkg.browser, - format: 'es', - sourcemap: true - }, - plugins: [...es2017BuildPlugins, emitModulePackageFile()], - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) - } -]; + plugins: [...buildPlugins, emitModulePackageFile()], + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) +}; -const cjsBuilds = [ - { - input: './src/index.ts', - output: { - file: pkg.main, - format: 'cjs', - sourcemap: true - }, - plugins: [...es5BuildPlugins], - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) - } -]; +const cjsBuild = { + input: './src/index.ts', + output: { + file: pkg.main, + format: 'cjs', + sourcemap: true + }, + plugins: buildPlugins, + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) +}; -// eslint-disable-next-line import/no-default-export -export default [...esmBuilds, ...cjsBuilds]; +export default [esmBuild, cjsBuild]; diff --git a/packages/storage/package.json b/packages/storage/package.json index 97807ce9a21..2ca5f2fff12 100644 --- a/packages/storage/package.json +++ b/packages/storage/package.json @@ -6,7 +6,6 @@ "main": "dist/index.node.cjs.js", "module": "dist/index.esm2017.js", "browser": "dist/index.esm2017.js", - "esm5": "dist/index.esm5.js", "exports": { ".": { "types": "./dist/storage-public.d.ts", @@ -14,7 +13,6 @@ "import": "./dist/node-esm/index.node.esm.js", "default": "./dist/index.node.cjs.js" }, - "esm5": "./dist/index.esm5.js", "browser": { "require": "./dist/index.cjs.js", "import": "./dist/index.esm2017.js" @@ -50,7 +48,6 @@ "dependencies": { "@firebase/util": "1.10.0", "@firebase/component": "0.6.9", - "undici": "6.19.7", "tslib": "^2.1.0" }, "peerDependencies": { @@ -73,5 +70,8 @@ "bugs": { "url": "https://github.com/firebase/firebase-js-sdk/issues" }, - "typings": "dist/src/index.d.ts" + "typings": "dist/src/index.d.ts", + "engines": { + "node": ">=18.0.0" + } } diff --git a/packages/storage/rollup.config.js b/packages/storage/rollup.config.js index 73c9d7561aa..21431d1a2a3 100644 --- a/packages/storage/rollup.config.js +++ b/packages/storage/rollup.config.js @@ -41,44 +41,15 @@ const deps = Object.keys( const nodeDeps = [...deps, 'util']; -const es5Plugins = [ +const buildPlugins = [ typescriptPlugin({ typescript, abortOnError: false }), - json() -]; - -const es2017Plugins = [ - typescriptPlugin({ - typescript, - tsconfigOverride: { - compilerOptions: { - target: 'es2017' - } - }, - abortOnError: false - }), json({ preferConst: true }) ]; const browserBuilds = [ - { - input: './src/index.ts', - output: { file: pkg.esm5, format: 'es', sourcemap: true }, - plugins: [ - alias(generateAliasConfig('browser')), - ...es5Plugins, - replace({ - ...generateBuildTargetReplaceConfig('esm', 5), - '__RUNTIME_ENV__': '' - }) - ], - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), - treeshake: { - moduleSideEffects: false - } - }, { input: './src/index.ts', output: { @@ -88,7 +59,7 @@ const browserBuilds = [ }, plugins: [ alias(generateAliasConfig('browser')), - ...es2017Plugins, + ...buildPlugins, replace({ ...generateBuildTargetReplaceConfig('esm', 2017), '__RUNTIME_ENV__': '' @@ -108,7 +79,7 @@ const browserBuilds = [ }, plugins: [ alias(generateAliasConfig('browser')), - ...es2017Plugins, + ...buildPlugins, replace({ ...generateBuildTargetReplaceConfig('cjs', 2017), '__RUNTIME_ENV__': '' @@ -127,7 +98,7 @@ const browserBuilds = [ ], plugins: [ alias(generateAliasConfig('browser')), - ...es5Plugins, + ...buildPlugins, replace({ ...generateBuildTargetReplaceConfig('cjs', 5), '__RUNTIME_ENV__': '' @@ -150,7 +121,7 @@ const nodeBuilds = [ }, plugins: [ alias(generateAliasConfig('node')), - ...es2017Plugins, + ...buildPlugins, replace({ ...generateBuildTargetReplaceConfig('cjs', 2017), '__RUNTIME_ENV__': 'node' @@ -171,7 +142,7 @@ const nodeBuilds = [ }, plugins: [ alias(generateAliasConfig('node')), - ...es2017Plugins, + ...buildPlugins, replace({ ...generateBuildTargetReplaceConfig('esm', 2017), '__RUNTIME_ENV__': 'node' diff --git a/packages/storage/src/index.ts b/packages/storage/src/index.ts index 1e19f5bf6eb..733a39c9ad8 100644 --- a/packages/storage/src/index.ts +++ b/packages/storage/src/index.ts @@ -70,7 +70,7 @@ function registerStorage(): void { ); //RUNTIME_ENV will be replaced during the compilation to "node" for nodejs and an empty string for browser registerVersion(name, version, '__RUNTIME_ENV__'); - // BUILD_TARGET will be replaced by values like esm5, esm2017, cjs5, etc during the compilation + // BUILD_TARGET will be replaced by values like esm2017, cjs2017, etc during the compilation registerVersion(name, version, '__BUILD_TARGET__'); } diff --git a/packages/storage/src/platform/node/connection.ts b/packages/storage/src/platform/node/connection.ts index d7141e6ef68..c90f664c3b2 100644 --- a/packages/storage/src/platform/node/connection.ts +++ b/packages/storage/src/platform/node/connection.ts @@ -21,7 +21,6 @@ import { ErrorCode } from '../../implementation/connection'; import { internalError } from '../../implementation/error'; -import { fetch as undiciFetch, Headers as undiciHeaders } from 'undici'; /** An override for the text-based Connection. Used in tests. */ let textFactoryOverride: (() => Connection) | null = null; @@ -39,9 +38,8 @@ abstract class FetchConnection protected statusCode_: number | undefined; protected body_: ArrayBuffer | undefined; protected errorText_ = ''; - protected headers_: undiciHeaders | undefined; + protected headers_: Headers | undefined; protected sent_: boolean = false; - protected fetch_ = undiciFetch; constructor() { this.errorCode_ = ErrorCode.NO_ERROR; @@ -59,7 +57,7 @@ abstract class FetchConnection this.sent_ = true; try { - const response = await this.fetch_(url, { + const response = await fetch(url, { method, headers: headers || {}, body: body as NodeJS.ArrayBufferView | string @@ -163,7 +161,7 @@ export class FetchStreamConnection extends FetchConnection< this.sent_ = true; try { - const response = await this.fetch_(url, { + const response = await fetch(url, { method, headers: headers || {}, body: body as NodeJS.ArrayBufferView | string diff --git a/packages/storage/test/node/connection.test.ts b/packages/storage/test/node/connection.test.ts index 32c499f0209..925d1f8f7dc 100644 --- a/packages/storage/test/node/connection.test.ts +++ b/packages/storage/test/node/connection.test.ts @@ -24,9 +24,9 @@ describe('Connections', () => { it('FetchConnection.send() should not reject on network errors', async () => { const connection = new FetchBytesConnection(); - // need the casting here because fetch_ is a private member - stub(connection as any, 'fetch_').rejects(); + const fetchStub = stub(globalThis, 'fetch').rejects(); await connection.send('testurl', 'GET'); expect(connection.getErrorCode()).to.equal(ErrorCode.NETWORK_ERROR); + fetchStub.restore(); }); }); diff --git a/packages/template/package.json b/packages/template/package.json index 9f797e78984..4c4e0b017ea 100644 --- a/packages/template/package.json +++ b/packages/template/package.json @@ -7,7 +7,6 @@ "main": "dist/index.node.cjs.js", "browser": "dist/index.esm2017.js", "module": "dist/index.esm2017.js", - "esm5": "dist/index.esm5.js", "exports": { ".": { "types": "./dist/index.d.ts", @@ -15,7 +14,6 @@ "import": "./dist/node-esm/index.node.esm.js", "require": "./dist/index.node.cjs.js" }, - "esm5": "./dist/index.esm5.js", "browser": { "require": "./dist/index.cjs.js", "import": "./dist/index.esm2017.js" diff --git a/packages/template/rollup.config.js b/packages/template/rollup.config.js index 0417ac2a28d..18ee720efeb 100644 --- a/packages/template/rollup.config.js +++ b/packages/template/rollup.config.js @@ -24,30 +24,9 @@ const deps = Object.keys( Object.assign({}, pkg.peerDependencies, pkg.dependencies) ); -const es5BuildPlugins = [ - typescriptPlugin({ - typescript - }) -]; - -const es2017BuildPlugins = [ - typescriptPlugin({ - typescript, - tsconfigOverride: { - compilerOptions: { - target: 'es2017' - } - } - }) -]; +const buildPlugins = [typescriptPlugin({ typescript })]; const browserBuilds = [ - { - input: 'index.ts', - output: [{ file: pkg.esm5, format: 'es', sourcemap: true }], - plugins: es5BuildPlugins, - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) - }, { input: 'index.ts', output: { @@ -55,7 +34,7 @@ const browserBuilds = [ format: 'es', sourcemap: true }, - plugins: es2017BuildPlugins, + plugins: buildPlugins, external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) }, { @@ -65,7 +44,7 @@ const browserBuilds = [ format: 'cjs', sourcemap: true }, - plugins: es2017BuildPlugins, + plugins: buildPlugins, external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) } ]; @@ -73,16 +52,22 @@ const browserBuilds = [ const nodeBuilds = [ { input: 'index.node.ts', - output: [{ file: pkg.main, format: 'cjs', sourcemap: true }], - plugins: es2017BuildPlugins, + 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: [...es2017BuildPlugins, emitModulePackageFile()], + output: { + file: pkg.exports['.'].node.import, + format: 'es', + sourcemap: true + }, + plugins: [...buildPlugins, emitModulePackageFile()], external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) } ]; diff --git a/packages/util/package.json b/packages/util/package.json index 1ed335d7a95..fa30ebd15d9 100644 --- a/packages/util/package.json +++ b/packages/util/package.json @@ -6,7 +6,6 @@ "main": "dist/index.node.cjs.js", "browser": "dist/index.esm2017.js", "module": "dist/index.esm2017.js", - "esm5": "dist/index.esm5.js", "exports": { ".": { "types": "./dist/util-public.d.ts", @@ -14,7 +13,6 @@ "import": "./dist/node-esm/index.node.esm.js", "require": "./dist/index.node.cjs.js" }, - "esm5": "./dist/index.esm5.js", "browser": { "require": "./dist/index.cjs.js", "import": "./dist/index.esm2017.js" @@ -65,5 +63,8 @@ ".ts" ], "reportDir": "./coverage/node" + }, + "engines": { + "node": ">=18.0.0" } } diff --git a/packages/util/rollup.config.js b/packages/util/rollup.config.js index 8f0d1312bfa..d428092d8ee 100644 --- a/packages/util/rollup.config.js +++ b/packages/util/rollup.config.js @@ -24,30 +24,9 @@ const deps = Object.keys( Object.assign({}, pkg.peerDependencies, pkg.dependencies) ); -const es5BuildPlugins = [ - typescriptPlugin({ - typescript - }) -]; - -const es2017BuildPlugins = [ - typescriptPlugin({ - typescript, - tsconfigOverride: { - compilerOptions: { - target: 'es2017' - } - } - }) -]; +const buildPlugins = [typescriptPlugin({ typescript })]; const browserBuilds = [ - { - input: 'index.ts', - output: [{ file: pkg.esm5, format: 'es', sourcemap: true }], - plugins: es5BuildPlugins, - external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) - }, { input: 'index.ts', output: { @@ -55,7 +34,7 @@ const browserBuilds = [ format: 'es', sourcemap: true }, - plugins: es2017BuildPlugins, + plugins: buildPlugins, external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) }, { @@ -65,7 +44,7 @@ const browserBuilds = [ format: 'cjs', sourcemap: true }, - plugins: es2017BuildPlugins, + plugins: buildPlugins, external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) } ]; @@ -73,16 +52,22 @@ const browserBuilds = [ const nodeBuilds = [ { input: 'index.node.ts', - output: [{ file: pkg.main, format: 'cjs', sourcemap: true }], - plugins: es5BuildPlugins, + 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: [...es2017BuildPlugins, emitModulePackageFile()], + output: { + file: pkg.exports['.'].node.import, + format: 'es', + sourcemap: true + }, + plugins: [...buildPlugins, emitModulePackageFile()], external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) } ]; diff --git a/packages/util/src/crypt.ts b/packages/util/src/crypt.ts index 7cd32125043..bec79d5304d 100644 --- a/packages/util/src/crypt.ts +++ b/packages/util/src/crypt.ts @@ -104,6 +104,7 @@ interface Base64 { // We define it as an object literal instead of a class because a class compiled down to es5 can't // be treeshaked. https://github.com/rollup/rollup/issues/1691 // Static lookup maps, lazily populated by init_() +// TODO(dlarocque): Define this as a class, since we no longer target ES5. export const base64: Base64 = { /** * Maps bytes to characters. diff --git a/packages/util/src/errors.ts b/packages/util/src/errors.ts index 7946d706ea3..8d2780c47ac 100644 --- a/packages/util/src/errors.ts +++ b/packages/util/src/errors.ts @@ -59,8 +59,6 @@ export type ErrorMap = { readonly [K in ErrorCode]: string; }; -const ERROR_NAME = 'FirebaseError'; - export interface StringLike { toString(): string; } @@ -72,9 +70,6 @@ export interface ErrorData { // Based on code from: // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#Custom_Error_Types export class FirebaseError extends Error { - /** The custom name for all FirebaseErrors. */ - readonly name: string = ERROR_NAME; - constructor( /** The error code for this error. */ readonly code: string, @@ -84,8 +79,13 @@ export class FirebaseError extends Error { ) { super(message); + // Set the name of the error to the name of the calling constructor. + this.name = this.constructor.name; + // Fix For ES5 // https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work + // TODO(dlarocque): Replace this with `new.target`: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html#support-for-newtarget + // which we can now use since we no longer target ES5. Object.setPrototypeOf(this, FirebaseError.prototype); // Maintains proper stack trace for where our error was thrown. diff --git a/packages/vertexai/package.json b/packages/vertexai/package.json index 6023c4dc095..4881ea92381 100644 --- a/packages/vertexai/package.json +++ b/packages/vertexai/package.json @@ -1,7 +1,7 @@ { - "name": "@firebase/vertexai-preview", + "name": "@firebase/vertexai", "version": "0.0.4", - "description": "A Firebase SDK for VertexAI (preview)", + "description": "A Firebase SDK for VertexAI", "author": "Firebase (https://firebase.google.com/)", "engines": { "node": ">=18.0.0" @@ -11,7 +11,7 @@ "module": "dist/esm/index.esm2017.js", "exports": { ".": { - "types": "./dist/vertexai-preview-public.d.ts", + "types": "./dist/vertexai-public.d.ts", "node": { "require": "./dist/index.cjs.js", "import": "./dist/esm/index.esm2017.js" @@ -40,7 +40,7 @@ "test:skip-clone": "karma start", "test:browser": "yarn testsetup && karma start", "api-report": "api-extractor run --local --verbose", - "typings:public": "node ../../scripts/build/use_typings.js ./dist/vertexai-preview-public.d.ts", + "typings:public": "node ../../scripts/build/use_typings.js ./dist/vertexai-public.d.ts", "trusted-type-check": "tsec -p tsconfig.json --noEmit" }, "peerDependencies": { diff --git a/packages/vertexai/rollup.config.js b/packages/vertexai/rollup.config.js index 6e99c03e913..3a1313a6bff 100644 --- a/packages/vertexai/rollup.config.js +++ b/packages/vertexai/rollup.config.js @@ -27,14 +27,7 @@ const deps = Object.keys( Object.assign({}, pkg.peerDependencies, pkg.dependencies) ); -const es5BuildPlugins = [ - typescriptPlugin({ - typescript - }), - json() -]; - -const es2017BuildPlugins = [ +const buildPlugins = [ typescriptPlugin({ typescript, tsconfigOverride: { @@ -55,7 +48,7 @@ const browserBuilds = [ sourcemap: true }, plugins: [ - ...es2017BuildPlugins, + ...buildPlugins, replace({ ...generateBuildTargetReplaceConfig('esm', 2017), __PACKAGE_VERSION__: pkg.version @@ -72,7 +65,7 @@ const browserBuilds = [ sourcemap: true }, plugins: [ - ...es2017BuildPlugins, + ...buildPlugins, replace({ ...generateBuildTargetReplaceConfig('cjs', 2017), __PACKAGE_VERSION__: pkg.version @@ -85,8 +78,12 @@ const browserBuilds = [ // const nodeBuilds = [ // { // input: 'index.node.ts', -// output: [{ file: pkg.main, format: 'cjs', sourcemap: true }], -// plugins: es2017BuildPlugins, +// output: { +// file: pkg.main, +// format: 'cjs', +// sourcemap: true +// }, +// plugins: buildPlugins, // external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) // }, // { @@ -94,7 +91,7 @@ const browserBuilds = [ // output: [ // { file: pkg.exports['.'].node.import, format: 'es', sourcemap: true } // ], -// plugins: [...es2017BuildPlugins, emitModulePackageFile()], +// plugins: [...buildPlugins, emitModulePackageFile()], // external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) // } // ]; diff --git a/packages/vertexai/src/api.test.ts b/packages/vertexai/src/api.test.ts index 794c5045012..b6c96923856 100644 --- a/packages/vertexai/src/api.test.ts +++ b/packages/vertexai/src/api.test.ts @@ -39,8 +39,9 @@ describe('Top level API', () => { getGenerativeModel(fakeVertexAI, {} as ModelParams); } catch (e) { expect((e as VertexAIError).code).includes(VertexAIErrorCode.NO_MODEL); - expect((e as VertexAIError).message).equals( - `Must provide a model name. Example: getGenerativeModel({ model: 'my-model-name' })` + expect((e as VertexAIError).message).includes( + `VertexAI: Must provide a model name. Example: ` + + `getGenerativeModel({ model: 'my-model-name' }) (vertexAI/${VertexAIErrorCode.NO_MODEL})` ); } }); @@ -54,7 +55,9 @@ describe('Top level API', () => { } catch (e) { expect((e as VertexAIError).code).includes(VertexAIErrorCode.NO_API_KEY); expect((e as VertexAIError).message).equals( - `The "apiKey" field is empty in the local Firebase config. Firebase VertexAI requires this field to contain a valid API key.` + `VertexAI: The "apiKey" field is empty in the local ` + + `Firebase config. Firebase VertexAI requires this field to` + + ` contain a valid API key. (vertexAI/${VertexAIErrorCode.NO_API_KEY})` ); } }); @@ -70,7 +73,9 @@ describe('Top level API', () => { VertexAIErrorCode.NO_PROJECT_ID ); expect((e as VertexAIError).message).equals( - `The "projectId" field is empty in the local Firebase config. Firebase VertexAI requires this field to contain a valid project ID.` + `VertexAI: The "projectId" field is empty in the local` + + ` Firebase config. Firebase VertexAI requires this field ` + + `to contain a valid project ID. (vertexAI/${VertexAIErrorCode.NO_PROJECT_ID})` ); } }); diff --git a/packages/vertexai/src/api.ts b/packages/vertexai/src/api.ts index 92d5aac7144..23c502895d8 100644 --- a/packages/vertexai/src/api.ts +++ b/packages/vertexai/src/api.ts @@ -26,6 +26,7 @@ import { VertexAIError } from './errors'; import { GenerativeModel } from './models/generative-model'; export { ChatSession } from './methods/chat-session'; +export * from './requests/schema-builder'; export { GenerativeModel }; diff --git a/packages/vertexai/src/constants.ts b/packages/vertexai/src/constants.ts index 97f6d813abc..3ff894f354b 100644 --- a/packages/vertexai/src/constants.ts +++ b/packages/vertexai/src/constants.ts @@ -21,9 +21,9 @@ export const VERTEX_TYPE = 'vertexAI'; export const DEFAULT_LOCATION = 'us-central1'; -export const DEFAULT_BASE_URL = 'https://firebaseml.googleapis.com'; +export const DEFAULT_BASE_URL = 'https://firebasevertexai.googleapis.com'; -export const DEFAULT_API_VERSION = 'v2beta'; +export const DEFAULT_API_VERSION = 'v1beta'; export const PACKAGE_VERSION = version; diff --git a/packages/vertexai/src/errors.ts b/packages/vertexai/src/errors.ts index 46db2fd271f..ad3f9b72f5a 100644 --- a/packages/vertexai/src/errors.ts +++ b/packages/vertexai/src/errors.ts @@ -34,15 +34,15 @@ export class VertexAIError extends FirebaseError { */ constructor( readonly code: VertexAIErrorCode, - readonly message: string, + message: string, readonly customErrorData?: CustomErrorData ) { // Match error format used by FirebaseError from ErrorFactory const service = VERTEX_TYPE; const serviceName = 'VertexAI'; const fullCode = `${service}/${code}`; - const fullMessage = `${serviceName}: ${message} (${fullCode}).`; - super(fullCode, fullMessage); + const fullMessage = `${serviceName}: ${message} (${fullCode})`; + super(code, fullMessage); // FirebaseError initializes a stack trace, but it assumes the error is created from the error // factory. Since we break this assumption, we set the stack trace to be originating from this @@ -56,6 +56,8 @@ export class VertexAIError extends FirebaseError { // Allows instanceof VertexAIError in ES5/ES6 // https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work + // TODO(dlarocque): Replace this with `new.target`: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html#support-for-newtarget + // which we can now use since we no longer target ES5. Object.setPrototypeOf(this, VertexAIError.prototype); // Since Error is an interface, we don't inherit toString and so we define it ourselves. diff --git a/packages/vertexai/src/index.ts b/packages/vertexai/src/index.ts index c8f798ff3c5..5d646e8d9d0 100644 --- a/packages/vertexai/src/index.ts +++ b/packages/vertexai/src/index.ts @@ -49,7 +49,7 @@ function registerVertex(): void { ); registerVersion(name, version); - // BUILD_TARGET will be replaced by values like esm5, esm2017, cjs5, etc during the compilation + // BUILD_TARGET will be replaced by values like esm2017, cjs2017, etc during the compilation registerVersion(name, version, '__BUILD_TARGET__'); } diff --git a/packages/vertexai/src/methods/generate-content.test.ts b/packages/vertexai/src/methods/generate-content.test.ts index 51fa82dccc9..fd12964c4bc 100644 --- a/packages/vertexai/src/methods/generate-content.test.ts +++ b/packages/vertexai/src/methods/generate-content.test.ts @@ -220,4 +220,18 @@ describe('generateContent()', () => { ).to.be.rejectedWith(/400.*invalid argument/); expect(mockFetch).to.be.called; }); + it('api not enabled (403)', async () => { + const mockResponse = getMockResponse( + 'unary-failure-firebasevertexai-api-not-enabled.json' + ); + const mockFetch = stub(globalThis, 'fetch').resolves({ + ok: false, + status: 403, + json: mockResponse.json + } as Response); + await expect( + generateContent(fakeApiSettings, 'model', fakeRequestParams) + ).to.be.rejectedWith(/firebasevertexai\.googleapis.*my-project/); + expect(mockFetch).to.be.called; + }); }); diff --git a/packages/vertexai/src/requests/request.test.ts b/packages/vertexai/src/requests/request.test.ts index 16a1ece2c7e..da32ec7d59c 100644 --- a/packages/vertexai/src/requests/request.test.ts +++ b/packages/vertexai/src/requests/request.test.ts @@ -24,6 +24,7 @@ import { ApiSettings } from '../types/internal'; import { DEFAULT_API_VERSION } from '../constants'; import { VertexAIErrorCode } from '../types'; import { VertexAIError } from '../errors'; +import { getMockResponse } from '../../test-utils/mock-response'; use(sinonChai); use(chaiAsPromised); @@ -243,7 +244,7 @@ describe('request methods', () => { false, '', { - timeout: 0 + timeout: 180000 } ); } catch (e) { @@ -357,4 +358,28 @@ describe('request methods', () => { expect(fetchStub).to.be.calledOnce; }); }); + it('Network error, API not enabled', async () => { + const mockResponse = getMockResponse( + 'unary-failure-firebasevertexai-api-not-enabled.json' + ); + const fetchStub = stub(globalThis, 'fetch').resolves( + mockResponse as Response + ); + try { + await makeRequest( + 'models/model-name', + Task.GENERATE_CONTENT, + fakeApiSettings, + false, + '' + ); + } catch (e) { + expect((e as VertexAIError).code).to.equal( + VertexAIErrorCode.API_NOT_ENABLED + ); + expect((e as VertexAIError).message).to.include('my-project'); + expect((e as VertexAIError).message).to.include('googleapis.com'); + } + expect(fetchStub).to.be.calledOnce; + }); }); diff --git a/packages/vertexai/src/requests/request.ts b/packages/vertexai/src/requests/request.ts index eac99a23038..8c563d8ccfc 100644 --- a/packages/vertexai/src/requests/request.ts +++ b/packages/vertexai/src/requests/request.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { RequestOptions, VertexAIErrorCode } from '../types'; +import { ErrorDetails, RequestOptions, VertexAIErrorCode } from '../types'; import { VertexAIError } from '../errors'; import { ApiSettings } from '../types/internal'; import { @@ -151,6 +151,34 @@ export async function makeRequest( } catch (e) { // ignored } + if ( + response.status === 403 && + errorDetails.some( + (detail: ErrorDetails) => detail.reason === 'SERVICE_DISABLED' + ) && + errorDetails.some((detail: ErrorDetails) => + ( + detail.links as Array> + )?.[0]?.description.includes( + 'Google developers console API activation' + ) + ) + ) { + throw new VertexAIError( + VertexAIErrorCode.API_NOT_ENABLED, + `The Vertex AI for Firebase SDK requires the Firebase Vertex AI API ` + + `firebasevertexai.googleapis.com to be enabled for your ` + + `project. Get started in the Firebase Console` + + ` (https://console.firebase.google.com/project/${url.apiSettings.project}/genai/vertex)` + + ` or verify that the API is enabled in the Google Cloud` + + ` Console (https://console.developers.google.com/apis/api/firebasevertexai.googleapis.com/overview?project=${url.apiSettings.project}).`, + { + status: response.status, + statusText: response.statusText, + errorDetails + } + ); + } throw new VertexAIError( VertexAIErrorCode.FETCH_ERROR, `Error fetching from ${url}: [${response.status} ${response.statusText}] ${message}`, @@ -165,6 +193,7 @@ export async function makeRequest( let err = e as Error; if ( (e as VertexAIError).code !== VertexAIErrorCode.FETCH_ERROR && + (e as VertexAIError).code !== VertexAIErrorCode.API_NOT_ENABLED && e instanceof Error ) { err = new VertexAIError( @@ -186,11 +215,13 @@ export async function makeRequest( */ function buildFetchOptions(requestOptions?: RequestOptions): RequestInit { const fetchOptions = {} as RequestInit; + let timeoutMillis = 180 * 1000; // default: 180 s if (requestOptions?.timeout && requestOptions?.timeout >= 0) { - const abortController = new AbortController(); - const signal = abortController.signal; - setTimeout(() => abortController.abort(), requestOptions.timeout); - fetchOptions.signal = signal; + timeoutMillis = requestOptions.timeout; } + const abortController = new AbortController(); + const signal = abortController.signal; + setTimeout(() => abortController.abort(), timeoutMillis); + fetchOptions.signal = signal; return fetchOptions; } diff --git a/packages/vertexai/src/requests/schema-builder.test.ts b/packages/vertexai/src/requests/schema-builder.test.ts new file mode 100644 index 00000000000..b95acaae9f1 --- /dev/null +++ b/packages/vertexai/src/requests/schema-builder.test.ts @@ -0,0 +1,393 @@ +/** + * @license + * Copyright 2024 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 { expect, use } from 'chai'; +import sinonChai from 'sinon-chai'; +import { Schema } from './schema-builder'; +import { VertexAIErrorCode } from '../types'; + +use(sinonChai); + +describe('Schema builder', () => { + it('builds integer schema', () => { + const schema = Schema.integer(); + expect(schema.toJSON()).to.eql({ + type: 'integer', + nullable: false + }); + }); + it('builds integer schema with options and overrides', () => { + const schema = Schema.integer({ nullable: true, format: 'int32' }); + expect(schema.toJSON()).to.eql({ + type: 'integer', + format: 'int32', + nullable: true + }); + }); + it('builds number schema', () => { + const schema = Schema.number(); + expect(schema.toJSON()).to.eql({ + type: 'number', + nullable: false + }); + }); + it('builds number schema with options and unknown options', () => { + const schema = Schema.number({ format: 'float', futureOption: 'test' }); + expect(schema.toJSON()).to.eql({ + type: 'number', + format: 'float', + futureOption: 'test', + nullable: false + }); + }); + it('builds boolean schema', () => { + const schema = Schema.boolean(); + expect(schema.toJSON()).to.eql({ + type: 'boolean', + nullable: false + }); + }); + it('builds string schema', () => { + const schema = Schema.string({ description: 'hey' }); + expect(schema.toJSON()).to.eql({ + type: 'string', + description: 'hey', + nullable: false + }); + }); + it('builds enumString schema', () => { + const schema = Schema.enumString({ + example: 'east', + enum: ['east', 'west'] + }); + expect(schema.toJSON()).to.eql({ + type: 'string', + example: 'east', + enum: ['east', 'west'], + nullable: false + }); + }); + it('builds an object schema', () => { + const schema = Schema.object({ + properties: { + 'someInput': Schema.string() + } + }); + expect(schema.toJSON()).to.eql({ + type: 'object', + nullable: false, + properties: { + 'someInput': { + type: 'string', + nullable: false + } + }, + required: ['someInput'] + }); + }); + it('builds an object schema with optional properties', () => { + const schema = Schema.object({ + properties: { + 'someInput': Schema.string(), + 'someBool': Schema.boolean() + }, + optionalProperties: ['someBool'] + }); + expect(schema.toJSON()).to.eql({ + type: 'object', + nullable: false, + properties: { + 'someInput': { + type: 'string', + nullable: false + }, + 'someBool': { + type: 'boolean', + nullable: false + } + }, + required: ['someInput'] + }); + }); + it('builds layered schema - partially filled out', () => { + const schema = Schema.array({ + items: Schema.object({ + properties: { + country: Schema.string({ + description: 'A country name' + }), + population: Schema.integer(), + coordinates: Schema.object({ + properties: { + latitude: Schema.number({ format: 'float' }), + longitude: Schema.number({ format: 'double' }) + } + }), + hemisphere: Schema.object({ + properties: { + latitudinal: Schema.enumString({ enum: ['N', 'S'] }), + longitudinal: Schema.enumString({ enum: ['E', 'W'] }) + } + }), + isCapital: Schema.boolean() + } + }) + }); + expect(schema.toJSON()).to.eql(layeredSchemaOutputPartial); + }); + it('builds layered schema - fully filled out', () => { + const schema = Schema.array({ + items: Schema.object({ + description: 'A country profile', + nullable: false, + properties: { + country: Schema.string({ + nullable: false, + description: 'Country name', + format: undefined + }), + population: Schema.integer({ + nullable: false, + description: 'Number of people in country', + format: 'int64' + }), + coordinates: Schema.object({ + nullable: false, + description: 'Latitude and longitude', + properties: { + latitude: Schema.number({ + nullable: false, + description: 'Latitude of capital', + format: 'float' + }), + longitude: Schema.number({ + nullable: false, + description: 'Longitude of capital', + format: 'double' + }) + } + }), + hemisphere: Schema.object({ + nullable: false, + description: 'Hemisphere(s) country is in', + properties: { + latitudinal: Schema.enumString({ enum: ['N', 'S'] }), + longitudinal: Schema.enumString({ enum: ['E', 'W'] }) + } + }), + isCapital: Schema.boolean({ + nullable: false, + description: "This doesn't make a lot of sense but it's a demo" + }), + elevation: Schema.integer({ + nullable: false, + description: 'Average elevation', + format: 'float' + }) + }, + optionalProperties: [] + }) + }); + + expect(schema.toJSON()).to.eql(layeredSchemaOutput); + }); + it('can override "nullable" and set optional properties', () => { + const schema = Schema.object({ + properties: { + country: Schema.string(), + elevation: Schema.number(), + population: Schema.integer({ nullable: true }) + }, + optionalProperties: ['elevation'] + }); + expect(schema.toJSON()).to.eql({ + 'type': 'object', + 'nullable': false, + 'properties': { + 'country': { + 'type': 'string', + 'nullable': false + }, + 'elevation': { + 'type': 'number', + 'nullable': false + }, + 'population': { + 'type': 'integer', + 'nullable': true + } + }, + 'required': ['country', 'population'] + }); + }); + it('throws if an optionalProperties item does not exist', () => { + const schema = Schema.object({ + properties: { + country: Schema.string(), + elevation: Schema.number(), + population: Schema.integer({ nullable: true }) + }, + optionalProperties: ['cat'] + }); + expect(() => schema.toJSON()).to.throw(VertexAIErrorCode.INVALID_SCHEMA); + }); +}); + +const layeredSchemaOutputPartial = { + 'type': 'array', + 'nullable': false, + 'items': { + 'type': 'object', + 'nullable': false, + 'properties': { + 'country': { + 'type': 'string', + 'description': 'A country name', + 'nullable': false + }, + 'population': { + 'type': 'integer', + 'nullable': false + }, + 'coordinates': { + 'type': 'object', + 'nullable': false, + 'properties': { + 'latitude': { + 'type': 'number', + 'format': 'float', + 'nullable': false + }, + 'longitude': { + 'type': 'number', + 'format': 'double', + 'nullable': false + } + }, + 'required': ['latitude', 'longitude'] + }, + 'hemisphere': { + 'type': 'object', + 'nullable': false, + 'properties': { + 'latitudinal': { + 'type': 'string', + 'nullable': false, + 'enum': ['N', 'S'] + }, + 'longitudinal': { + 'type': 'string', + 'nullable': false, + 'enum': ['E', 'W'] + } + }, + 'required': ['latitudinal', 'longitudinal'] + }, + 'isCapital': { + 'type': 'boolean', + 'nullable': false + } + }, + 'required': [ + 'country', + 'population', + 'coordinates', + 'hemisphere', + 'isCapital' + ] + } +}; + +const layeredSchemaOutput = { + 'type': 'array', + 'nullable': false, + 'items': { + 'type': 'object', + 'description': 'A country profile', + 'nullable': false, + 'required': [ + 'country', + 'population', + 'coordinates', + 'hemisphere', + 'isCapital', + 'elevation' + ], + 'properties': { + 'country': { + 'type': 'string', + 'description': 'Country name', + 'nullable': false + }, + 'population': { + 'type': 'integer', + 'format': 'int64', + 'description': 'Number of people in country', + 'nullable': false + }, + 'coordinates': { + 'type': 'object', + 'description': 'Latitude and longitude', + 'nullable': false, + 'required': ['latitude', 'longitude'], + 'properties': { + 'latitude': { + 'type': 'number', + 'format': 'float', + 'description': 'Latitude of capital', + 'nullable': false + }, + 'longitude': { + 'type': 'number', + 'format': 'double', + 'description': 'Longitude of capital', + 'nullable': false + } + } + }, + 'hemisphere': { + 'type': 'object', + 'description': 'Hemisphere(s) country is in', + 'nullable': false, + 'required': ['latitudinal', 'longitudinal'], + 'properties': { + 'latitudinal': { + 'type': 'string', + 'nullable': false, + 'enum': ['N', 'S'] + }, + 'longitudinal': { + 'type': 'string', + 'nullable': false, + 'enum': ['E', 'W'] + } + } + }, + 'isCapital': { + 'type': 'boolean', + 'description': "This doesn't make a lot of sense but it's a demo", + 'nullable': false + }, + 'elevation': { + 'type': 'integer', + 'format': 'float', + 'description': 'Average elevation', + 'nullable': false + } + } + } +}; diff --git a/packages/vertexai/src/requests/schema-builder.ts b/packages/vertexai/src/requests/schema-builder.ts new file mode 100644 index 00000000000..8a36aaa8997 --- /dev/null +++ b/packages/vertexai/src/requests/schema-builder.ts @@ -0,0 +1,292 @@ +/** + * @license + * Copyright 2024 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 { VertexAIError } from '../errors'; +import { VertexAIErrorCode } from '../types'; +import { + SchemaInterface, + SchemaType, + SchemaParams, + SchemaRequest, + ObjectSchemaInterface +} from '../types/schema'; + +/** + * Parent class encompassing all Schema types, with static methods that + * allow building specific Schema types. This class can be converted with + * `JSON.stringify()` into a JSON string accepted by Vertex AI REST endpoints. + * (This string conversion is automatically done when calling SDK methods.) + * @public + */ +export abstract class Schema implements SchemaInterface { + /** + * Optional. The type of the property. {@link + * SchemaType}. + */ + type: SchemaType; + /** Optional. The format of the property. + * Supported formats:
+ *
    + *
  • for NUMBER type: "float", "double"
  • + *
  • for INTEGER type: "int32", "int64"
  • + *
  • for STRING type: "email", "byte", etc
  • + *
+ */ + format?: string; + /** Optional. The description of the property. */ + description?: string; + /** Optional. Whether the property is nullable. Defaults to false. */ + nullable: boolean; + /** Optional. The example of the property. */ + example?: unknown; + /** + * Allows user to add other schema properties that have not yet + * been officially added to the SDK. + */ + [key: string]: unknown; + + constructor(schemaParams: SchemaInterface) { + // eslint-disable-next-line guard-for-in + for (const paramKey in schemaParams) { + this[paramKey] = schemaParams[paramKey]; + } + // Ensure these are explicitly set to avoid TS errors. + this.type = schemaParams.type; + this.nullable = schemaParams.hasOwnProperty('nullable') + ? !!schemaParams.nullable + : false; + } + + /** + * Defines how this Schema should be serialized as JSON. + * See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#tojson_behavior + * @internal + */ + toJSON(): SchemaRequest { + const obj: { type: SchemaType; [key: string]: unknown } = { + type: this.type + }; + for (const prop in this) { + if (this.hasOwnProperty(prop) && this[prop] !== undefined) { + if (prop !== 'required' || this.type === SchemaType.OBJECT) { + obj[prop] = this[prop]; + } + } + } + return obj as SchemaRequest; + } + + static array(arrayParams: SchemaParams & { items: Schema }): ArraySchema { + return new ArraySchema(arrayParams, arrayParams.items); + } + + static object( + objectParams: SchemaParams & { + properties: { + [k: string]: Schema; + }; + optionalProperties?: string[]; + } + ): ObjectSchema { + return new ObjectSchema( + objectParams, + objectParams.properties, + objectParams.optionalProperties + ); + } + + // eslint-disable-next-line id-blacklist + static string(stringParams?: SchemaParams): StringSchema { + return new StringSchema(stringParams); + } + + static enumString( + stringParams: SchemaParams & { enum: string[] } + ): StringSchema { + return new StringSchema(stringParams, stringParams.enum); + } + + static integer(integerParams?: SchemaParams): IntegerSchema { + return new IntegerSchema(integerParams); + } + + // eslint-disable-next-line id-blacklist + static number(numberParams?: SchemaParams): NumberSchema { + return new NumberSchema(numberParams); + } + + // eslint-disable-next-line id-blacklist + static boolean(booleanParams?: SchemaParams): BooleanSchema { + return new BooleanSchema(booleanParams); + } +} + +/** + * A type that includes all specific Schema types. + * @public + */ +export type TypedSchema = + | IntegerSchema + | NumberSchema + | StringSchema + | BooleanSchema + | ObjectSchema + | ArraySchema; + +/** + * Schema class for "integer" types. + * @public + */ +export class IntegerSchema extends Schema { + constructor(schemaParams?: SchemaParams) { + super({ + type: SchemaType.INTEGER, + ...schemaParams + }); + } +} + +/** + * Schema class for "number" types. + * @public + */ +export class NumberSchema extends Schema { + constructor(schemaParams?: SchemaParams) { + super({ + type: SchemaType.NUMBER, + ...schemaParams + }); + } +} + +/** + * Schema class for "boolean" types. + * @public + */ +export class BooleanSchema extends Schema { + constructor(schemaParams?: SchemaParams) { + super({ + type: SchemaType.BOOLEAN, + ...schemaParams + }); + } +} + +/** + * Schema class for "string" types. Can be used with or without + * enum values. + * @public + */ +export class StringSchema extends Schema { + enum?: string[]; + constructor(schemaParams?: SchemaParams, enumValues?: string[]) { + super({ + type: SchemaType.STRING, + ...schemaParams + }); + this.enum = enumValues; + } + + /** + * @internal + */ + toJSON(): SchemaRequest { + const obj = super.toJSON(); + if (this.enum) { + obj['enum'] = this.enum; + } + return obj as SchemaRequest; + } +} + +/** + * Schema class for "array" types. + * The `items` param should refer to the type of item that can be a member + * of the array. + * @public + */ +export class ArraySchema extends Schema { + constructor(schemaParams: SchemaParams, public items: TypedSchema) { + super({ + type: SchemaType.ARRAY, + ...schemaParams + }); + } + + /** + * @internal + */ + toJSON(): SchemaRequest { + const obj = super.toJSON(); + obj.items = this.items.toJSON(); + return obj; + } +} + +/** + * Schema class for "object" types. + * The `properties` param must be a map of Schema. + * @public + */ +export class ObjectSchema extends Schema { + constructor( + schemaParams: SchemaParams, + public properties: { + [k: string]: TypedSchema; + }, + public optionalProperties: string[] = [] + ) { + super({ + type: SchemaType.OBJECT, + ...schemaParams + }); + } + + /** + * @internal + */ + toJSON(): SchemaRequest { + const obj = super.toJSON(); + obj.properties = { ...this.properties }; + const required = []; + if (this.optionalProperties) { + for (const propertyKey of this.optionalProperties) { + if (!this.properties.hasOwnProperty(propertyKey)) { + throw new VertexAIError( + VertexAIErrorCode.INVALID_SCHEMA, + `Property "${propertyKey}" specified in "optionalProperties" does not exist.` + ); + } + } + } + for (const propertyKey in this.properties) { + if (this.properties.hasOwnProperty(propertyKey)) { + obj.properties[propertyKey] = this.properties[ + propertyKey + ].toJSON() as SchemaRequest; + if (!this.optionalProperties.includes(propertyKey)) { + required.push(propertyKey); + } + } + } + if (required.length > 0) { + obj.required = required; + } + delete (obj as ObjectSchemaInterface).optionalProperties; + return obj as SchemaRequest; + } +} diff --git a/packages/vertexai/src/types/enums.ts b/packages/vertexai/src/types/enums.ts index fd901241250..3e66bacc612 100644 --- a/packages/vertexai/src/types/enums.ts +++ b/packages/vertexai/src/types/enums.ts @@ -32,7 +32,6 @@ export const POSSIBLE_ROLES = ['user', 'model', 'function', 'system'] as const; * @public */ export enum HarmCategory { - HARM_CATEGORY_UNSPECIFIED = 'HARM_CATEGORY_UNSPECIFIED', HARM_CATEGORY_HATE_SPEECH = 'HARM_CATEGORY_HATE_SPEECH', HARM_CATEGORY_SEXUALLY_EXPLICIT = 'HARM_CATEGORY_SEXUALLY_EXPLICIT', HARM_CATEGORY_HARASSMENT = 'HARM_CATEGORY_HARASSMENT', @@ -44,8 +43,6 @@ export enum HarmCategory { * @public */ export enum HarmBlockThreshold { - // Threshold is unspecified. - HARM_BLOCK_THRESHOLD_UNSPECIFIED = 'HARM_BLOCK_THRESHOLD_UNSPECIFIED', // Content with NEGLIGIBLE will be allowed. BLOCK_LOW_AND_ABOVE = 'BLOCK_LOW_AND_ABOVE', // Content with NEGLIGIBLE and LOW will be allowed. @@ -60,8 +57,6 @@ export enum HarmBlockThreshold { * @public */ export enum HarmBlockMethod { - // The harm block method is unspecified. - HARM_BLOCK_METHOD_UNSPECIFIED = 'HARM_BLOCK_METHOD_UNSPECIFIED', // The harm block method uses both probability and severity scores. SEVERITY = 'SEVERITY', // The harm block method uses the probability score. @@ -73,8 +68,6 @@ export enum HarmBlockMethod { * @public */ export enum HarmProbability { - // Probability is unspecified. - HARM_PROBABILITY_UNSPECIFIED = 'HARM_PROBABILITY_UNSPECIFIED', // Content has a negligible chance of being unsafe. NEGLIGIBLE = 'NEGLIGIBLE', // Content has a low chance of being unsafe. @@ -90,8 +83,6 @@ export enum HarmProbability { * @public */ export enum HarmSeverity { - // Harm severity unspecified. - HARM_SEVERITY_UNSPECIFIED = 'HARM_SEVERITY_UNSPECIFIED', // Negligible level of harm severity. HARM_SEVERITY_NEGLIGIBLE = 'HARM_SEVERITY_NEGLIGIBLE', // Low level of harm severity. @@ -107,8 +98,6 @@ export enum HarmSeverity { * @public */ export enum BlockReason { - // A blocked reason was not specified. - BLOCKED_REASON_UNSPECIFIED = 'BLOCKED_REASON_UNSPECIFIED', // Content was blocked by safety settings. SAFETY = 'SAFETY', // Content was blocked, but the reason is uncategorized. @@ -120,8 +109,6 @@ export enum BlockReason { * @public */ export enum FinishReason { - // Default value. This value is unused. - FINISH_REASON_UNSPECIFIED = 'FINISH_REASON_UNSPECIFIED', // Natural stop point of the model or provided stop sequence. STOP = 'STOP', // The maximum number of tokens as specified in the request was reached. @@ -138,8 +125,6 @@ export enum FinishReason { * @public */ export enum FunctionCallingMode { - // Unspecified function calling mode. This value should not be used. - MODE_UNSPECIFIED = 'MODE_UNSPECIFIED', // Default model behavior, model decides to predict either a function call // or a natural language response. AUTO = 'AUTO', diff --git a/packages/vertexai/src/types/error.ts b/packages/vertexai/src/types/error.ts index 5ba594013c2..aaaf19f05b3 100644 --- a/packages/vertexai/src/types/error.ts +++ b/packages/vertexai/src/types/error.ts @@ -78,6 +78,12 @@ export const enum VertexAIErrorCode { /** An error associated with a Content object. */ INVALID_CONTENT = 'invalid-content', + /** An error due to the Firebase API not being enabled in the Console. */ + API_NOT_ENABLED = 'api-not-enabled', + + /** An error due to invalid Schema input. */ + INVALID_SCHEMA = 'invalid-schema', + /** An error occurred due to a missing Firebase API key. */ NO_API_KEY = 'no-api-key', diff --git a/packages/vertexai/src/types/index.ts b/packages/vertexai/src/types/index.ts index 45365c39037..85133aa07c5 100644 --- a/packages/vertexai/src/types/index.ts +++ b/packages/vertexai/src/types/index.ts @@ -20,3 +20,4 @@ export * from './enums'; export * from './requests'; export * from './responses'; export * from './error'; +export * from './schema'; diff --git a/packages/vertexai/src/types/requests.ts b/packages/vertexai/src/types/requests.ts index 1e976b386b6..c844ddfb878 100644 --- a/packages/vertexai/src/types/requests.ts +++ b/packages/vertexai/src/types/requests.ts @@ -15,6 +15,7 @@ * limitations under the License. */ +import { TypedSchema } from '../requests/schema-builder'; import { Content, Part } from './content'; import { FunctionCallingMode, @@ -22,6 +23,7 @@ import { HarmBlockThreshold, HarmCategory } from './enums'; +import { ObjectSchemaInterface, SchemaRequest } from './schema'; /** * Base parameters for a number of methods. @@ -78,14 +80,20 @@ export interface GenerationConfig { presencePenalty?: number; frequencyPenalty?: number; /** - * Output response mimetype of the generated candidate text. - * Supported mimetypes are `text/plain` (default, text output) and `application/json` + * Output response MIME type of the generated candidate text. + * Supported MIME types are `text/plain` (default, text output) and `application/json` * (JSON response in the candidates). - * The model needs to be prompted to output the appropriate response type, - * otherwise the behavior is undefined. - * This is a preview feature. */ responseMimeType?: string; + /** + * Output response schema of the generated candidate text. This + * value can be a class generated with a {@link Schema} static method + * like `Schema.string()` or `Schema.object()` or it can be a plain + * JS object matching the {@link SchemaRequest} interface. + *
Note: This only applies when the specified `responseMIMEType` supports a schema; currently + * this is limited to `application/json`. + */ + responseSchema?: TypedSchema | SchemaRequest; } /** @@ -113,7 +121,7 @@ export interface CountTokensRequest { */ export interface RequestOptions { /** - * Request timeout in milliseconds. + * Request timeout in milliseconds. Defaults to 180 seconds (180000ms). */ timeout?: number; /** @@ -145,16 +153,16 @@ export declare interface FunctionDeclaration { */ name: string; /** - * Optional. Description and purpose of the function. Model uses it to decide + * Description and purpose of the function. Model uses it to decide * how and whether to call the function. */ - description?: string; + description: string; /** * Optional. Describes the parameters to this function in JSON Schema Object * format. Reflects the Open API 3.03 Parameter Object. Parameter names are * case-sensitive. For a function with no parameters, this can be left unset. */ - parameters?: FunctionDeclarationSchema; + parameters?: ObjectSchemaInterface; } /** @@ -177,77 +185,12 @@ export declare interface FunctionDeclarationsTool { functionDeclarations?: FunctionDeclaration[]; } -/** - * Contains the list of OpenAPI data types - * as defined by https://swagger.io/docs/specification/data-models/data-types/ - * @public - */ -export enum FunctionDeclarationSchemaType { - /** String type. */ - STRING = 'STRING', - /** Number type. */ - NUMBER = 'NUMBER', - /** Integer type. */ - INTEGER = 'INTEGER', - /** Boolean type. */ - BOOLEAN = 'BOOLEAN', - /** Array type. */ - ARRAY = 'ARRAY', - /** Object type. */ - OBJECT = 'OBJECT' -} - -/** - * Schema for parameters passed to {@link FunctionDeclaration.parameters}. - * @public - */ -export interface FunctionDeclarationSchema { - /** The type of the parameter. */ - type: FunctionDeclarationSchemaType; - /** The format of the parameter. */ - properties: { [k: string]: FunctionDeclarationSchemaProperty }; - /** Optional. Description of the parameter. */ - description?: string; - /** Optional. Array of required parameters. */ - required?: string[]; -} - -/** - * Schema is used to define the format of input/output data. - * Represents a select subset of an OpenAPI 3.0 schema object. - * More fields may be added in the future as needed. - * @public - */ -export interface FunctionDeclarationSchemaProperty { - /** - * Optional. The type of the property. {@link - * FunctionDeclarationSchemaType}. - */ - type?: FunctionDeclarationSchemaType; - /** Optional. The format of the property. */ - format?: string; - /** Optional. The description of the property. */ - description?: string; - /** Optional. Whether the property is nullable. */ - nullable?: boolean; - /** Optional. The items of the property. {@link FunctionDeclarationSchema} */ - items?: FunctionDeclarationSchema; - /** Optional. The enum of the property. */ - enum?: string[]; - /** Optional. Map of {@link FunctionDeclarationSchema}. */ - properties?: { [k: string]: FunctionDeclarationSchema }; - /** Optional. Array of required property. */ - required?: string[]; - /** Optional. The example of the property. */ - example?: unknown; -} - /** * Tool config. This config is shared for all tools provided in the request. * @public */ export interface ToolConfig { - functionCallingConfig: FunctionCallingConfig; + functionCallingConfig?: FunctionCallingConfig; } /** diff --git a/packages/vertexai/src/types/responses.ts b/packages/vertexai/src/types/responses.ts index 0a4557fb055..026002a851d 100644 --- a/packages/vertexai/src/types/responses.ts +++ b/packages/vertexai/src/types/responses.ts @@ -91,7 +91,7 @@ export interface UsageMetadata { * @public */ export interface PromptFeedback { - blockReason: BlockReason; + blockReason?: BlockReason; safetyRatings: SafetyRating[]; blockReasonMessage?: string; } diff --git a/packages/vertexai/src/types/schema.ts b/packages/vertexai/src/types/schema.ts new file mode 100644 index 00000000000..7b8f34d89d6 --- /dev/null +++ b/packages/vertexai/src/types/schema.ts @@ -0,0 +1,104 @@ +/** + * @license + * Copyright 2024 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. + */ + +/** + * Contains the list of OpenAPI data types + * as defined by the + * {@link https://swagger.io/docs/specification/data-models/data-types/ | OpenAPI specification} + * @public + */ +export enum SchemaType { + /** String type. */ + STRING = 'string', + /** Number type. */ + NUMBER = 'number', + /** Integer type. */ + INTEGER = 'integer', + /** Boolean type. */ + BOOLEAN = 'boolean', + /** Array type. */ + ARRAY = 'array', + /** Object type. */ + OBJECT = 'object' +} + +/** + * Basic {@link Schema} properties shared across several Schema-related + * types. + * @public + */ +export interface SchemaShared { + /** Optional. The format of the property. */ + format?: string; + /** Optional. The description of the property. */ + description?: string; + /** Optional. The items of the property. */ + items?: T; + /** Optional. Map of Schemas. */ + properties?: { + [k: string]: T; + }; + /** Optional. The enum of the property. */ + enum?: string[]; + /** Optional. The example of the property. */ + example?: unknown; + /** Optional. Whether the property is nullable. */ + nullable?: boolean; + [key: string]: unknown; +} + +/** + * Params passed to {@link Schema} static methods to create specific + * {@link Schema} classes. + * @public + */ +export interface SchemaParams extends SchemaShared {} + +/** + * Final format for {@link Schema} params passed to backend requests. + * @public + */ +export interface SchemaRequest extends SchemaShared { + /** + * The type of the property. {@link + * SchemaType}. + */ + type: SchemaType; + /** Optional. Array of required property. */ + required?: string[]; +} + +/** + * Interface for {@link Schema} class. + * @public + */ +export interface SchemaInterface extends SchemaShared { + /** + * The type of the property. {@link + * SchemaType}. + */ + type: SchemaType; +} + +/** + * Interface for {@link ObjectSchema} class. + * @public + */ +export interface ObjectSchemaInterface extends SchemaInterface { + type: SchemaType.OBJECT; + optionalProperties?: string[]; +} diff --git a/packages/webchannel-wrapper/bloom-blob/package.json b/packages/webchannel-wrapper/bloom-blob/package.json index 956333e7cf2..21b0b0e4800 100644 --- a/packages/webchannel-wrapper/bloom-blob/package.json +++ b/packages/webchannel-wrapper/bloom-blob/package.json @@ -4,6 +4,5 @@ "main": "../dist/bloom-blob/bloom_blob_es2018.js", "browser": "../dist/bloom-blob/esm/bloom_blob_es2018.js", "module": "../dist/bloom-blob/esm/bloom_blob_es2018.js", - "esm5": "../dist/bloom-blob/bloom_blob_es5.js", "typings": "../dist/bloom-blob/bloom_blob_types.d.ts" } diff --git a/packages/webchannel-wrapper/package.json b/packages/webchannel-wrapper/package.json index ddc849bcce6..5e483417c95 100644 --- a/packages/webchannel-wrapper/package.json +++ b/packages/webchannel-wrapper/package.json @@ -8,13 +8,11 @@ "./webchannel-blob": { "types": "./dist/webchannel-blob/webchannel_blob_types.d.ts", "require": "./dist/webchannel-blob/webchannel_blob_es2018.js", - "esm5": "./dist/webchannel-blob/webchannel_blob_es5.js", "default": "./dist/webchannel-blob/esm/webchannel_blob_es2018.js" }, "./bloom-blob": { "types": "./dist/bloom-blob/bloom_blob_types.d.ts", "require": "./dist/bloom-blob/bloom_blob_es2018.js", - "esm5": "./dist/bloom-blob/bloom_blob_es5.js", "default": "./dist/bloom-blob/esm/bloom_blob_es2018.js" }, "./package.json": "./package.json" diff --git a/packages/webchannel-wrapper/rollup.config.js b/packages/webchannel-wrapper/rollup.config.js index 77c29ecb4ac..ae80c831396 100644 --- a/packages/webchannel-wrapper/rollup.config.js +++ b/packages/webchannel-wrapper/rollup.config.js @@ -25,7 +25,7 @@ import pkg from './package.json'; const closureBlobsDir = '../../node_modules/closure-net/firebase/'; -const es2017BuildPlugins = [ +const buildPlugins = [ copy({ targets: [ { @@ -57,7 +57,7 @@ const esm2017Builds = [ format: 'es', sourcemap: true }, - plugins: [...es2017BuildPlugins, emitModulePackageFile()] + plugins: [...buildPlugins, emitModulePackageFile()] }, { input: join(closureBlobsDir, 'bloom_blob_es2018.js'), @@ -66,7 +66,7 @@ const esm2017Builds = [ format: 'es', sourcemap: true }, - plugins: [...es2017BuildPlugins, emitModulePackageFile()] + plugins: [...buildPlugins, emitModulePackageFile()] } ]; diff --git a/packages/webchannel-wrapper/webchannel-blob/package.json b/packages/webchannel-wrapper/webchannel-blob/package.json index cb339b82557..312b9d9f2a2 100644 --- a/packages/webchannel-wrapper/webchannel-blob/package.json +++ b/packages/webchannel-wrapper/webchannel-blob/package.json @@ -4,6 +4,5 @@ "main": "../dist/webchannel-blob/webchannel_blob_es2018.js", "browser": "../dist/webchannel-blob/esm/webchannel_blob_es2018.js", "module": "../dist/webchannel-blob/esm/webchannel_blob_es2018.js", - "esm5": "../dist/webchannel-blob/webchannel_blob_es5.js", "typings": "../dist/webchannel-blob/webchannel_blob_types.d.ts" } diff --git a/repo-scripts/api-documenter/package.json b/repo-scripts/api-documenter/package.json index 1e6b1a9ac21..b824be66e65 100644 --- a/repo-scripts/api-documenter/package.json +++ b/repo-scripts/api-documenter/package.json @@ -34,5 +34,8 @@ "@types/js-yaml": "4.0.9", "@types/resolve": "1.20.6", "mocha-chai-jest-snapshot": "1.1.3" + }, + "engines": { + "node": ">=18.0.0" } } diff --git a/repo-scripts/changelog-generator/index.ts b/repo-scripts/changelog-generator/index.ts index 20f3de482f1..3570c8a96a5 100644 --- a/repo-scripts/changelog-generator/index.ts +++ b/repo-scripts/changelog-generator/index.ts @@ -17,7 +17,6 @@ import { ChangelogFunctions } from '@changesets/types'; import { getInfo } from '@changesets/get-github-info'; -import { fetch as undiciFetch, Response as undiciResponse } from 'undici'; const changelogFunctions: ChangelogFunctions = { getDependencyReleaseLine: async ( @@ -95,7 +94,7 @@ async function getFixedIssueLink( prNumber: number, repo: string ): Promise { - const response = await undiciFetch( + const response = await fetch( `https://api.github.com/repos/${repo}/pulls/${prNumber}`, { method: 'GET', @@ -105,7 +104,7 @@ async function getFixedIssueLink( } ).then(data => data.json()); - const body = (response as undiciResponse).body; + const body = (response as Response).body; if (!body) { return ''; } diff --git a/repo-scripts/changelog-generator/package.json b/repo-scripts/changelog-generator/package.json index f4afc131d1f..09313c27ed6 100644 --- a/repo-scripts/changelog-generator/package.json +++ b/repo-scripts/changelog-generator/package.json @@ -19,8 +19,7 @@ "dependencies": { "@changesets/types": "3.3.0", "@changesets/get-github-info": "0.5.2", - "@types/node": "20.8.10", - "undici": "6.19.7" + "@types/node": "20.8.10" }, "license": "Apache-2.0", "devDependencies": { @@ -39,5 +38,8 @@ ".ts" ], "reportDir": "./coverage/node" + }, + "engines": { + "node": ">=18.0.0" } } diff --git a/repo-scripts/changelog-generator/tsconfig.json b/repo-scripts/changelog-generator/tsconfig.json index 5c910fcca64..38bdb7035e4 100644 --- a/repo-scripts/changelog-generator/tsconfig.json +++ b/repo-scripts/changelog-generator/tsconfig.json @@ -9,6 +9,6 @@ "moduleResolution": "node", "esModuleInterop": true, "resolveJsonModule": true, - "target": "es5" + "target": "es2017" } } \ No newline at end of file diff --git a/repo-scripts/prune-dts/package.json b/repo-scripts/prune-dts/package.json index d8d4ab6391b..8b1128b29b0 100644 --- a/repo-scripts/prune-dts/package.json +++ b/repo-scripts/prune-dts/package.json @@ -3,7 +3,7 @@ "version": "0.1.0", "private": true, "engines": { - "node": "^8.13.0 || >=10.10.0" + "node": ">=18.0.0" }, "description": "A script to prune non-exported types from a d.ts.", "author": "Firebase (https://firebase.google.com/)", diff --git a/repo-scripts/size-analysis/package.json b/repo-scripts/size-analysis/package.json index 191901f5a6c..e0712390298 100644 --- a/repo-scripts/size-analysis/package.json +++ b/repo-scripts/size-analysis/package.json @@ -57,5 +57,8 @@ ".ts" ], "reportDir": "./coverage/node" + }, + "engines": { + "node": ">=18.0.0" } } diff --git a/repo-scripts/size-analysis/rollup.config.js b/repo-scripts/size-analysis/rollup.config.js index 505596e3d2e..2796accc3a9 100644 --- a/repo-scripts/size-analysis/rollup.config.js +++ b/repo-scripts/size-analysis/rollup.config.js @@ -42,7 +42,7 @@ export default [ tsconfigOverride: { compilerOptions: { target: 'es2017', - module: 'es2015' + module: 'es2017' } } }), @@ -67,7 +67,7 @@ export default [ tsconfigOverride: { compilerOptions: { target: 'es2017', - module: 'es2015' + module: 'es2017' } } }), diff --git a/scripts/ci-test/check-paths.ts b/scripts/ci-test/check-paths.ts index 236e63d310f..d3af878f286 100644 --- a/scripts/ci-test/check-paths.ts +++ b/scripts/ci-test/check-paths.ts @@ -31,7 +31,6 @@ const TOP_LEVEL_FIELDS = [ 'typings', 'react-native', 'cordova', - 'esm5', 'webworker', 'main-esm' ]; diff --git a/scripts/docgen/docgen.ts b/scripts/docgen/docgen.ts index 8e9dfa87cab..ab335256145 100644 --- a/scripts/docgen/docgen.ts +++ b/scripts/docgen/docgen.ts @@ -58,6 +58,9 @@ const PREFERRED_PARAMS = [ 'vertexAI' ]; +let authApiReportOriginal: string; +let authApiConfigOriginal: string; + yargs .command( '$0', @@ -93,9 +96,6 @@ yargs process.on('exit', cleanup); process.on('SIGINT', cleanup); -let authApiReportOriginal: string; -let authApiConfigOriginal: string; - function cleanup() { try { // Restore original auth api-extractor.json contents. @@ -189,8 +189,8 @@ async function generateDocs( 'utf8' ); const authApiConfigModified = authApiConfigOriginal.replace( - `"mainEntryPointFilePath": "/dist/esm5/index.d.ts"`, - `"mainEntryPointFilePath": "/dist/esm5/index.doc.d.ts"` + `"mainEntryPointFilePath": "/dist/esm2017/index.d.ts"`, + `"mainEntryPointFilePath": "/dist/esm2017/index.doc.d.ts"` ); try { diff --git a/scripts/emulator-testing/emulators/emulator.ts b/scripts/emulator-testing/emulators/emulator.ts index 1295d413e4b..ba69e049ad6 100644 --- a/scripts/emulator-testing/emulators/emulator.ts +++ b/scripts/emulator-testing/emulators/emulator.ts @@ -21,7 +21,6 @@ import { ChildProcess } from 'child_process'; import * as fs from 'fs'; import * as os from 'os'; import * as path from 'path'; -import fetch from 'node-fetch'; // @ts-ignore import * as tmp from 'tmp'; @@ -51,35 +50,60 @@ export abstract class Emulator { return new Promise((resolve, reject) => { tmp.dir((err: Error | null, dir: string) => { if (err) reject(err); - console.log(`Created temporary directory at [${dir}].`); const filepath: string = path.resolve(dir, this.binaryName); - const writeStream: fs.WriteStream = fs.createWriteStream(filepath); - + const writer = fs.createWriteStream(filepath); console.log(`Downloading emulator from [${this.binaryUrl}] ...`); - fetch(this.binaryUrl).then(resp => { - resp.body - .pipe(writeStream) - .on('finish', () => { - console.log(`Saved emulator binary file to [${filepath}].`); - // Change emulator binary file permission to 'rwxr-xr-x'. - // The execute permission is required for it to be able to start - // with 'java -jar'. - fs.chmod(filepath, 0o755, err => { - if (err) reject(err); - console.log( - `Changed emulator file permissions to 'rwxr-xr-x'.` - ); - this.binaryPath = filepath; - - if (this.copyToCache()) { - console.log(`Cached emulator at ${this.cacheBinaryPath}`); + // Map the DOM's fetch Reader to node's streaming file system + // operations. We will need to access class members `binaryPath` and `copyToCache` after the + // download completes. It's a compilation error to pass `this` into the named function + // `readChunk`, so the download operation is wrapped in a promise that we wait upon. + const downloadPromise = new Promise( + (downloadComplete, downloadFailed) => { + fetch(this.binaryUrl) + .then(resp => { + if (resp.status !== 200 || resp.body === null) { + console.log('Download of emulator failed: ', resp.statusText); + downloadFailed(); + } else { + const reader = resp.body.getReader(); + reader.read().then(function readChunk({ done, value }): any { + if (done) { + downloadComplete(); + } else { + writer.write(value); + return reader.read().then(readChunk); + } + }); } - resolve(); + }) + .catch(e => { + console.log(`Download of emulator failed: ${e}`); + downloadFailed(); }); - }) - .on('error', reject); - }); + } + ); + + downloadPromise.then( + () => { + console.log('Download complete'); + // Change emulator binary file permission to 'rwxr-xr-x'. + // The execute permission is required for it to be able to start + // with 'java -jar'. + fs.chmod(filepath, 0o755, err => { + if (err) reject(err); + console.log(`Changed emulator file permissions to 'rwxr-xr-x'.`); + this.binaryPath = filepath; + if (this.copyToCache()) { + console.log(`Cached emulator at ${this.cacheBinaryPath}`); + } + resolve(); + }); + }, + () => { + reject(); + } + ); }); }); } diff --git a/scripts/size_report/report_binary_size.ts b/scripts/size_report/report_binary_size.ts index 444e45dd978..da1ad166702 100644 --- a/scripts/size_report/report_binary_size.ts +++ b/scripts/size_report/report_binary_size.ts @@ -49,7 +49,6 @@ function generateReportForCDNScripts(): Report[] { const compatPkgJson = require(`${firebaseRoot}/compat/package.json`); const special_files = [ - 'firebase-performance-standalone-compat.es2017.js', 'firebase-performance-standalone-compat.js', 'firebase-compat.js' ]; @@ -118,11 +117,9 @@ async function collectBinarySize(pkg: string): Promise { 'main', 'module', 'browser', - 'esm5', 'react-native', 'cordova', - 'lite', - 'lite-esm5' + 'lite' ]; const json = require(pkg); for (const field of fields) { diff --git a/scripts/tsconfig.json b/scripts/tsconfig.json index 826691796fc..75f1741329a 100644 --- a/scripts/tsconfig.json +++ b/scripts/tsconfig.json @@ -8,7 +8,7 @@ "moduleResolution": "node", "esModuleInterop": true, "resolveJsonModule": true, - "target": "es5", + "target": "es2017", "typeRoots": [ "../node_modules/@types" ], diff --git a/yarn.lock b/yarn.lock index 477e784871e..f3fc015f9ec 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3480,14 +3480,6 @@ dependencies: "@types/node" "*" -"@types/node-fetch@2.6.4": - version "2.6.4" - resolved "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.4.tgz" - integrity sha512-1ZX9fcN4Rvkvgv4E6PAY5WXUFWFcRWxZa3EW83UjycOB9ljJCedb2CupIP4RZMEwF/M3eTcCihbBRgwtGbg5Rg== - dependencies: - "@types/node" "*" - form-data "^3.0.0" - "@types/node@*", "@types/node@>=10.0.0", "@types/node@^12.7.1": version "12.20.50" resolved "https://registry.npmjs.org/@types/node/-/node-12.20.50.tgz" @@ -8512,15 +8504,6 @@ form-data@^2.5.0: combined-stream "^1.0.6" mime-types "^2.1.12" -form-data@^3.0.0: - version "3.0.1" - resolved "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz" - integrity sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg== - dependencies: - asynckit "^0.4.0" - combined-stream "^1.0.8" - mime-types "^2.1.12" - form-data@^4.0.0: version "4.0.0" resolved "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz" @@ -12852,13 +12835,6 @@ node-emoji@^1.11.0: dependencies: lodash "^4.17.21" -node-fetch@2.6.7, node-fetch@^2.6.7: - version "2.6.7" - resolved "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz" - integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ== - dependencies: - whatwg-url "^5.0.0" - node-fetch@^2.5.0, node-fetch@^2.6.1: version "2.6.5" resolved "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.5.tgz" @@ -12866,6 +12842,13 @@ node-fetch@^2.5.0, node-fetch@^2.6.1: dependencies: whatwg-url "^5.0.0" +node-fetch@^2.6.7: + version "2.6.7" + resolved "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz" + integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ== + dependencies: + whatwg-url "^5.0.0" + node-forge@^0.10.0: version "0.10.0" resolved "https://registry.npmjs.org/node-forge/-/node-forge-0.10.0.tgz" @@ -17388,11 +17371,6 @@ undici-types@~5.26.4: resolved "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617" integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA== -undici@6.19.7: - version "6.19.7" - resolved "https://registry.npmjs.org/undici/-/undici-6.19.7.tgz#7d4cf26dc689838aa8b6753a3c5c4288fc1e0216" - integrity sha512-HR3W/bMGPSr90i8AAp2C4DM3wChFdJPLrWYpIS++LxS8K+W535qftjt+4MyjNYHeWabMj1nvtmLIi7l++iq91A== - unicode-canonical-property-names-ecmascript@^2.0.0: version "2.0.0" resolved "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-2.0.0.tgz"