From fde0f206e1a954f2473ecdadde1d831285f9c50f Mon Sep 17 00:00:00 2001 From: Antignote Date: Tue, 23 Nov 2021 23:29:16 +0100 Subject: [PATCH 1/2] fix issue where the global RTK object got overwritten in the UMD files fix #1761 --- packages/toolkit/scripts/build.ts | 10 +++++----- packages/toolkit/scripts/types.ts | 2 ++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/toolkit/scripts/build.ts b/packages/toolkit/scripts/build.ts index d7960a1f99..8173df28f4 100644 --- a/packages/toolkit/scripts/build.ts +++ b/packages/toolkit/scripts/build.ts @@ -97,18 +97,21 @@ const entryPoints: EntryPointOptions[] = [ folder: '', entryPoint: 'src/index.ts', extractionConfig: 'api-extractor.json', + globalName: 'RTK', }, { prefix: 'rtk-query', folder: 'query', entryPoint: 'src/query/index.ts', extractionConfig: 'api-extractor.query.json', + globalName: 'RTK.QUERY', }, { prefix: 'rtk-query-react', folder: 'query/react', entryPoint: 'src/query/react/index.ts', extractionConfig: 'api-extractor.query-react.json', + globalName: 'RTK.QUERY.REACT', }, ] @@ -250,10 +253,7 @@ async function bundle(options: BuildOptions & EntryPointOptions) { /** * since esbuild doesn't support umd, we use rollup to convert esm to umd */ -async function buildUMD(outputPath: string, prefix: string) { - // All RTK UMD files share the same global variable name, regardless - const globalName = 'RTK' - +async function buildUMD(outputPath: string, prefix: string, globalName: string) { for (let umdExtension of ['umd', 'umd.min']) { const input = path.join(outputPath, `${prefix}.${umdExtension}.js`) const instance = await rollup.rollup({ @@ -319,7 +319,7 @@ async function main({ skipExtraction = false, local = false }: BuildArgs) { for (let entryPoint of entryPoints) { const { folder } = entryPoint const outputPath = path.join('dist', folder) - await buildUMD(outputPath, entryPoint.prefix) + await buildUMD(outputPath, entryPoint.prefix, entryPoint.globalName) } // We need one additional package.json file in dist to support diff --git a/packages/toolkit/scripts/types.ts b/packages/toolkit/scripts/types.ts index 4d365ec3e6..562b28ab51 100644 --- a/packages/toolkit/scripts/types.ts +++ b/packages/toolkit/scripts/types.ts @@ -19,4 +19,6 @@ export interface EntryPointOptions { folder: string entryPoint: string extractionConfig: string + // globalName is used in the conversion to umd files to separate rtk from rtk-query on a global name space + globalName: string } From 2bdcd5227007e7db3af753a361d9617c574536a0 Mon Sep 17 00:00:00 2001 From: Antignote Date: Wed, 24 Nov 2021 20:17:19 +0100 Subject: [PATCH 2/2] change the global namespace of rtk-query use the same namespace for both rtk-query and rtk-query-react since users should only be loading one or the other fix #1761 --- packages/toolkit/scripts/build.ts | 4 ++-- packages/toolkit/scripts/types.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/toolkit/scripts/build.ts b/packages/toolkit/scripts/build.ts index 8173df28f4..2f4927b592 100644 --- a/packages/toolkit/scripts/build.ts +++ b/packages/toolkit/scripts/build.ts @@ -104,14 +104,14 @@ const entryPoints: EntryPointOptions[] = [ folder: 'query', entryPoint: 'src/query/index.ts', extractionConfig: 'api-extractor.query.json', - globalName: 'RTK.QUERY', + globalName: 'RTKQ', }, { prefix: 'rtk-query-react', folder: 'query/react', entryPoint: 'src/query/react/index.ts', extractionConfig: 'api-extractor.query-react.json', - globalName: 'RTK.QUERY.REACT', + globalName: 'RTKQ', }, ] diff --git a/packages/toolkit/scripts/types.ts b/packages/toolkit/scripts/types.ts index 562b28ab51..31f2fbe9b9 100644 --- a/packages/toolkit/scripts/types.ts +++ b/packages/toolkit/scripts/types.ts @@ -19,6 +19,6 @@ export interface EntryPointOptions { folder: string entryPoint: string extractionConfig: string - // globalName is used in the conversion to umd files to separate rtk from rtk-query on a global name space + // globalName is used in the conversion to umd files to separate rtk from rtk-query on a global namespace globalName: string }