From 83a392490f73c072ac9ab6ae7469fc38ae7f1a49 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Thu, 20 Feb 2020 21:14:00 -0800 Subject: [PATCH] De-mangle Node and CJS build --- packages/firestore/rollup.config.js | 56 ++++++++++++++++++----------- packages/firestore/src/util/api.ts | 2 +- 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/packages/firestore/rollup.config.js b/packages/firestore/rollup.config.js index a8da318d07a..5ed8d8ef7fb 100644 --- a/packages/firestore/rollup.config.js +++ b/packages/firestore/rollup.config.js @@ -51,7 +51,8 @@ const transformers = [ const terserOptions = { output: { - comments: false + comments: "all", + beautify: true }, mangle: { properties: { @@ -60,19 +61,6 @@ const terserOptions = { } }; -/** - * ES5 Builds - */ -const es5BuildPlugins = [ - typescriptPlugin({ - typescript, - transformers, - cacheRoot: './.cache/es5.min/' - }), - json(), - terser(terserOptions) -]; - const es5Builds = [ /** * Node.js Build @@ -81,7 +69,11 @@ const es5Builds = [ input: 'index.node.ts', output: [{ file: pkg.main, format: 'cjs', sourcemap: true }], plugins: [ - ...es5BuildPlugins, + typescriptPlugin({ + typescript, + cacheRoot: './.cache/node.cjs/' + }), + json(), // Needed as we also use the *.proto files copy({ assets: ['./src/protos'] @@ -96,15 +88,37 @@ const es5Builds = [ ) }, /** - * Browser Builds + * Browser CJS Build + * + * The Browser CJS build is not mangled as Terser's property name mangling + * does not work well with CommonJS-style files. */ { input: 'index.ts', - output: [ - { file: pkg.browser, format: 'cjs', sourcemap: true }, - { file: pkg.module, format: 'es', sourcemap: true } + output:{ file: pkg.browser, format: 'cjs', sourcemap: true }, + plugins: [ + typescriptPlugin({ + typescript, + cacheRoot: './.cache/cjs/' + }), + json() + ], + }, + /** + * Browser ESM Build + */ + { + input: 'index.ts', + output: { file: pkg.module, format: 'es', sourcemap: true }, + plugins: [ + typescriptPlugin({ + typescript, + transformers, + cacheRoot: './.cache/esm/' + }), + json(), + terser(terserOptions) ], - plugins: es5BuildPlugins, external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) } ]; @@ -120,7 +134,7 @@ const es2017BuildPlugins = [ target: 'es2017' } }, - cacheRoot: './.cache/es2017.min/', + cacheRoot: './.cache/esm2017/', transformers }), json({ preferConst: true }), diff --git a/packages/firestore/src/util/api.ts b/packages/firestore/src/util/api.ts index 32e89e2e4d1..bc180f6d943 100644 --- a/packages/firestore/src/util/api.ts +++ b/packages/firestore/src/util/api.ts @@ -47,7 +47,7 @@ export function makeConstructorPrivate( // Copy any static methods/members Object.assign(PublicConstructor, cls); - + // eslint-disable-next-line @typescript-eslint/no-explicit-any return PublicConstructor as any; }