From 1a42b199833e3b6cd82f0ba08c35a8d6e2b03b5a Mon Sep 17 00:00:00 2001 From: Blake Lovelace Date: Tue, 9 Aug 2022 22:43:42 +0800 Subject: [PATCH 01/10] Update functionality to maintain file output names when preserveModule = true BREAKING CHANGES: Changes the default behaviour to not alter filenames if preserveModules=true --- packages/multi-entry/src/index.js | 2 +- packages/multi-entry/test/test.js | 10 ++++++++++ packages/multi-entry/types/index.d.ts | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/multi-entry/src/index.js b/packages/multi-entry/src/index.js index ea01af793..161b1d2ca 100755 --- a/packages/multi-entry/src/index.js +++ b/packages/multi-entry/src/index.js @@ -53,7 +53,7 @@ export default function multiEntry(conf = {}) { outputOptions(options) { return { ...options, - entryFileNames: config.entryFileName + entryFileNames: (options.preserveModules && config.entryFileName === DEFAULT_OUTPUT) ? options.entryFileName : config.entryFileName }; }, diff --git a/packages/multi-entry/test/test.js b/packages/multi-entry/test/test.js index e23575ab1..73ea22b45 100755 --- a/packages/multi-entry/test/test.js +++ b/packages/multi-entry/test/test.js @@ -81,3 +81,13 @@ test('makes a bundle with entryFileName as the filename', async (t) => { const [result] = await getCode(bundle, { format: 'cjs' }, true); t.is(result.fileName, 'testing.js'); }); + +test('maintains filename when preserveModules = true', async (t) => { + const bundle = await rollup({ + input: 'test/fixtures/{0,1}.js', + plugins: [multiEntry()] + }); + const [result1, result2] = await getCode(bundle, { format: 'cjs', preserveModules: true }, true); + t.is(result1.fileName, '0.js'); + t.is(result2.fileName, '1.js'); +}); diff --git a/packages/multi-entry/types/index.d.ts b/packages/multi-entry/types/index.d.ts index 3331b2e87..5f461ade7 100644 --- a/packages/multi-entry/types/index.d.ts +++ b/packages/multi-entry/types/index.d.ts @@ -23,6 +23,7 @@ interface RollupMultiEntryOptions { /** * `entryFileName` changes the name of the generated entry file. * By default, it will override `outputOptions.entryFileNames` to be `'multi-entry.js'`. + * - If `output.preserveModules = true` ({@link https://rollupjs.org/guide/en/#outputpreservemodules}) the default is set to output.entryFileNames * @default 'multi-entry.js' */ entryFileName?: string; From ef657d399fb0d3fca717a2eefe291a2d2a8f6e0f Mon Sep 17 00:00:00 2001 From: Blake Lovelace Date: Wed, 10 Aug 2022 08:53:50 +0800 Subject: [PATCH 02/10] Fix docstring --- packages/multi-entry/types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/multi-entry/types/index.d.ts b/packages/multi-entry/types/index.d.ts index 5f461ade7..fafa31d15 100644 --- a/packages/multi-entry/types/index.d.ts +++ b/packages/multi-entry/types/index.d.ts @@ -23,7 +23,7 @@ interface RollupMultiEntryOptions { /** * `entryFileName` changes the name of the generated entry file. * By default, it will override `outputOptions.entryFileNames` to be `'multi-entry.js'`. - * - If `output.preserveModules = true` ({@link https://rollupjs.org/guide/en/#outputpreservemodules}) the default is set to output.entryFileNames + * - If `output.preserveModules = true` ({@link https://rollupjs.org/guide/en/#outputpreservemodules}) the default is set to output.entryFileName * @default 'multi-entry.js' */ entryFileName?: string; From efb2859d5cddc0130d0a69a1280d5d01c087d85a Mon Sep 17 00:00:00 2001 From: Blake Lovelace Date: Fri, 12 Aug 2022 20:52:59 +0800 Subject: [PATCH 03/10] Tests --- packages/multi-entry/src/index.js | 5 ++- packages/multi-entry/test/test.js | 59 +++++++++++++++++++++++++++++-- 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/packages/multi-entry/src/index.js b/packages/multi-entry/src/index.js index 161b1d2ca..fccb1333c 100755 --- a/packages/multi-entry/src/index.js +++ b/packages/multi-entry/src/index.js @@ -53,7 +53,10 @@ export default function multiEntry(conf = {}) { outputOptions(options) { return { ...options, - entryFileNames: (options.preserveModules && config.entryFileName === DEFAULT_OUTPUT) ? options.entryFileName : config.entryFileName + entryFileNames: + options.preserveModules && config.entryFileName === DEFAULT_OUTPUT + ? options.entryFileNames + : config.entryFileName }; }, diff --git a/packages/multi-entry/test/test.js b/packages/multi-entry/test/test.js index 73ea22b45..ab7286716 100755 --- a/packages/multi-entry/test/test.js +++ b/packages/multi-entry/test/test.js @@ -87,7 +87,60 @@ test('maintains filename when preserveModules = true', async (t) => { input: 'test/fixtures/{0,1}.js', plugins: [multiEntry()] }); - const [result1, result2] = await getCode(bundle, { format: 'cjs', preserveModules: true }, true); - t.is(result1.fileName, '0.js'); - t.is(result2.fileName, '1.js'); + const files = await getCode(bundle, { format: 'cjs', preserveModules: true }, true); + + const nonVirtualFiles = files + .filter(({ fileName }) => !fileName.startsWith('_virtual/')) + .sort((a, b) => a.fileName.localeCompare(b.fileName)); + + t.is(nonVirtualFiles.length, 2); + + t.is(nonVirtualFiles[0].fileName, '0.js'); + t.is(nonVirtualFiles[1].fileName, '1.js'); +}); + +test('makes a bundle with entryFileName as the filename when preserveModules = true and entryName is set', async (t) => { + const bundle = await rollup({ + input: 'test/fixtures/{0,1}.js', + plugins: [multiEntry({ entryFileName: 'testing.js' })], + output: { + preserveModules: true + } + }); + + const files = await getCode(bundle, { format: 'cjs', preserveModules: true }, true); + const nonVirtualFiles = files + .filter(({ fileName }) => !fileName.startsWith('_virtual/')) + .sort((a, b) => a.fileName.localeCompare(b.fileName)); + + t.is(nonVirtualFiles.length, 2); + + t.is(nonVirtualFiles[0].fileName, 'testing.js'); + t.is(nonVirtualFiles[1].fileName, 'testing2.js'); +}); + +test('makes a bundle with entryFileName as the output.entryFileName when preserveModules = true and entryName is not set', async (t) => { + const bundle = await rollup({ + input: 'test/fixtures/{0,1}.js', + plugins: [multiEntry()], + output: { + preserveModules: true, + entryFileNames: 'outputEntryFileName.js' + } + }); + + const files = await getCode( + bundle, + { format: 'cjs', preserveModules: true, entryFileNames: 'outputEntryFileName.js' }, + true + ); + + const nonVirtualFiles = files + .filter(({ fileName }) => !fileName.startsWith('_virtual/')) + .sort((a, b) => a.fileName.localeCompare(b.fileName)); + + t.is(nonVirtualFiles.length, 2); + + t.is(nonVirtualFiles[0].fileName, 'outputEntryFileName.js'); + t.is(nonVirtualFiles[1].fileName, 'outputEntryFileName2.js'); }); From e03e827908b0d886117f72646a2b509d19b7ba49 Mon Sep 17 00:00:00 2001 From: Blake Lovelace Date: Fri, 12 Aug 2022 20:54:44 +0800 Subject: [PATCH 04/10] Fix type doc --- packages/multi-entry/types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/multi-entry/types/index.d.ts b/packages/multi-entry/types/index.d.ts index fafa31d15..5f461ade7 100644 --- a/packages/multi-entry/types/index.d.ts +++ b/packages/multi-entry/types/index.d.ts @@ -23,7 +23,7 @@ interface RollupMultiEntryOptions { /** * `entryFileName` changes the name of the generated entry file. * By default, it will override `outputOptions.entryFileNames` to be `'multi-entry.js'`. - * - If `output.preserveModules = true` ({@link https://rollupjs.org/guide/en/#outputpreservemodules}) the default is set to output.entryFileName + * - If `output.preserveModules = true` ({@link https://rollupjs.org/guide/en/#outputpreservemodules}) the default is set to output.entryFileNames * @default 'multi-entry.js' */ entryFileName?: string; From 50c40845769550773485a7539eba5190e2738a38 Mon Sep 17 00:00:00 2001 From: Blake Lovelace Date: Wed, 14 Sep 2022 12:46:00 +0800 Subject: [PATCH 05/10] Swap to use preserveModules config option instead --- packages/multi-entry/src/index.js | 5 +--- packages/multi-entry/test/test.js | 39 +++++++-------------------- packages/multi-entry/types/index.d.ts | 9 +++++-- 3 files changed, 17 insertions(+), 36 deletions(-) diff --git a/packages/multi-entry/src/index.js b/packages/multi-entry/src/index.js index fccb1333c..dec066ac4 100755 --- a/packages/multi-entry/src/index.js +++ b/packages/multi-entry/src/index.js @@ -53,10 +53,7 @@ export default function multiEntry(conf = {}) { outputOptions(options) { return { ...options, - entryFileNames: - options.preserveModules && config.entryFileName === DEFAULT_OUTPUT - ? options.entryFileNames - : config.entryFileName + entryFileNames: config.preserveModules ? options.entryFileNames : config.entryFileName }; }, diff --git a/packages/multi-entry/test/test.js b/packages/multi-entry/test/test.js index ab7286716..c99588ee4 100755 --- a/packages/multi-entry/test/test.js +++ b/packages/multi-entry/test/test.js @@ -85,44 +85,25 @@ test('makes a bundle with entryFileName as the filename', async (t) => { test('maintains filename when preserveModules = true', async (t) => { const bundle = await rollup({ input: 'test/fixtures/{0,1}.js', - plugins: [multiEntry()] - }); - const files = await getCode(bundle, { format: 'cjs', preserveModules: true }, true); - - const nonVirtualFiles = files - .filter(({ fileName }) => !fileName.startsWith('_virtual/')) - .sort((a, b) => a.fileName.localeCompare(b.fileName)); - - t.is(nonVirtualFiles.length, 2); - - t.is(nonVirtualFiles[0].fileName, '0.js'); - t.is(nonVirtualFiles[1].fileName, '1.js'); -}); - -test('makes a bundle with entryFileName as the filename when preserveModules = true and entryName is set', async (t) => { - const bundle = await rollup({ - input: 'test/fixtures/{0,1}.js', - plugins: [multiEntry({ entryFileName: 'testing.js' })], + plugins: [multiEntry({ preserveModules: true, entryFileName: 'testing.js' })], output: { preserveModules: true } }); - const files = await getCode(bundle, { format: 'cjs', preserveModules: true }, true); - const nonVirtualFiles = files - .filter(({ fileName }) => !fileName.startsWith('_virtual/')) - .sort((a, b) => a.fileName.localeCompare(b.fileName)); + + const nonVirtualFiles = files.filter(({ fileName }) => !fileName.startsWith('_virtual/')); t.is(nonVirtualFiles.length, 2); - t.is(nonVirtualFiles[0].fileName, 'testing.js'); - t.is(nonVirtualFiles[1].fileName, 'testing2.js'); + t.truthy(nonVirtualFiles.find(({ fileName }) => fileName === '0.js')); + t.truthy(nonVirtualFiles.find(({ fileName }) => fileName === '1.js')); }); test('makes a bundle with entryFileName as the output.entryFileName when preserveModules = true and entryName is not set', async (t) => { const bundle = await rollup({ input: 'test/fixtures/{0,1}.js', - plugins: [multiEntry()], + plugins: [multiEntry({ preserveModules: true })], output: { preserveModules: true, entryFileNames: 'outputEntryFileName.js' @@ -135,12 +116,10 @@ test('makes a bundle with entryFileName as the output.entryFileName when preserv true ); - const nonVirtualFiles = files - .filter(({ fileName }) => !fileName.startsWith('_virtual/')) - .sort((a, b) => a.fileName.localeCompare(b.fileName)); + const nonVirtualFiles = files.filter(({ fileName }) => !fileName.startsWith('_virtual/')); t.is(nonVirtualFiles.length, 2); - t.is(nonVirtualFiles[0].fileName, 'outputEntryFileName.js'); - t.is(nonVirtualFiles[1].fileName, 'outputEntryFileName2.js'); + t.truthy(nonVirtualFiles.find(({ fileName }) => fileName === 'outputEntryFileName.js')); + t.truthy(nonVirtualFiles.find(({ fileName }) => fileName === 'outputEntryFileName2.js')); }); diff --git a/packages/multi-entry/types/index.d.ts b/packages/multi-entry/types/index.d.ts index 5f461ade7..901764b76 100644 --- a/packages/multi-entry/types/index.d.ts +++ b/packages/multi-entry/types/index.d.ts @@ -23,10 +23,15 @@ interface RollupMultiEntryOptions { /** * `entryFileName` changes the name of the generated entry file. * By default, it will override `outputOptions.entryFileNames` to be `'multi-entry.js'`. - * - If `output.preserveModules = true` ({@link https://rollupjs.org/guide/en/#outputpreservemodules}) the default is set to output.entryFileNames - * @default 'multi-entry.js' */ entryFileName?: string; + /** + * The preserveModules option is to be used in conjunction with output.preserveModules ({@link https://rollupjs.org/guide/en/#outputpreservemodules}). + * If `true`, overrides the entryFileName to be output.entryFileNames. + * If `false`, the plugin will respect the `entryFileName` option. + * @default false + */ + preserveModules?: boolean; } /** From f6dd4187d0b68d7b0bc075853e0e9fe7496a6c81 Mon Sep 17 00:00:00 2001 From: Blake Lovelace Date: Fri, 30 Sep 2022 08:43:24 +0800 Subject: [PATCH 06/10] Update readme and type docstrings --- packages/multi-entry/README.md | 7 +++++++ packages/multi-entry/types/index.d.ts | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/multi-entry/README.md b/packages/multi-entry/README.md index b5e74b5be..ccca365e5 100755 --- a/packages/multi-entry/README.md +++ b/packages/multi-entry/README.md @@ -80,6 +80,13 @@ Default: `'multi-entry.js'` `entryFileName` changes the name of the generated entry file. By default, it will override `outputOptions.entryFileNames` to be `'multi-entry.js'`. +### `preserveModules` + +Type: `Boolean`
+Default: `false` + +`preserveModules` is to be used in conjunction with [`output.preserveModules`](https://rollupjs.org/guide/en/#outputpreservemodules). If `true`, overrides the `entryFileName` option to be output.entryFileNames. If `false`, the plugin will respect the `entryFileName` option. + ## Supported Input Types This plugin extends Rollup's `input` option to support multiple new value types, in addition to a `String` specifying a path to a file. diff --git a/packages/multi-entry/types/index.d.ts b/packages/multi-entry/types/index.d.ts index 901764b76..7327aad86 100644 --- a/packages/multi-entry/types/index.d.ts +++ b/packages/multi-entry/types/index.d.ts @@ -27,7 +27,7 @@ interface RollupMultiEntryOptions { entryFileName?: string; /** * The preserveModules option is to be used in conjunction with output.preserveModules ({@link https://rollupjs.org/guide/en/#outputpreservemodules}). - * If `true`, overrides the entryFileName to be output.entryFileNames. + * If `true`, overrides the `entryFileName` option to be output.entryFileNames. * If `false`, the plugin will respect the `entryFileName` option. * @default false */ From 51518381484b98253ae150b75498275d5f641e1b Mon Sep 17 00:00:00 2001 From: Blake Lovelace Date: Sat, 15 Oct 2022 07:17:54 +0800 Subject: [PATCH 07/10] Fix tests --- packages/multi-entry/test/test.mjs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/packages/multi-entry/test/test.mjs b/packages/multi-entry/test/test.mjs index 67fbd6971..d9a689780 100755 --- a/packages/multi-entry/test/test.mjs +++ b/packages/multi-entry/test/test.mjs @@ -95,11 +95,9 @@ test('works as CJS plugin', async (t) => { test('maintains filename when preserveModules = true', async (t) => { const bundle = await rollup({ input: 'test/fixtures/{0,1}.js', - plugins: [multiEntry({ preserveModules: true, entryFileName: 'testing.js' })], - output: { - preserveModules: true - } + plugins: [multiEntry({ preserveModules: true, entryFileName: 'testing.js' })] }); + const files = await getCode(bundle, { format: 'cjs', preserveModules: true }, true); const nonVirtualFiles = files.filter(({ fileName }) => !fileName.startsWith('_virtual/')); @@ -113,16 +111,16 @@ test('maintains filename when preserveModules = true', async (t) => { test('makes a bundle with entryFileName as the output.entryFileName when preserveModules = true and entryName is not set', async (t) => { const bundle = await rollup({ input: 'test/fixtures/{0,1}.js', - plugins: [multiEntry({ preserveModules: true })], - output: { - preserveModules: true, - entryFileNames: 'outputEntryFileName.js' - } + plugins: [multiEntry({ preserveModules: true })] }); const files = await getCode( bundle, - { format: 'cjs', preserveModules: true, entryFileNames: 'outputEntryFileName.js' }, + { + format: 'cjs', + preserveModules: true, + entryFileNames: (c) => `${c.name}.js` + }, true ); @@ -130,6 +128,6 @@ test('makes a bundle with entryFileName as the output.entryFileName when preserv t.is(nonVirtualFiles.length, 2); - t.truthy(nonVirtualFiles.find(({ fileName }) => fileName === 'outputEntryFileName.js')); - t.truthy(nonVirtualFiles.find(({ fileName }) => fileName === 'outputEntryFileName2.js')); + t.truthy(nonVirtualFiles.find(({ fileName }) => fileName === '0.js')); + t.truthy(nonVirtualFiles.find(({ fileName }) => fileName === '1.js')); }); From 19b85a1e8b91507b4cce2687dcab9a17b21b9b2b Mon Sep 17 00:00:00 2001 From: Blake Lovelace Date: Sat, 15 Oct 2022 07:34:50 +0800 Subject: [PATCH 08/10] Revert odd changes in diff --- .../commonjs/src/resolve-require-sources.js | 109 +++++++++--------- packages/multi-entry/types/index.d.ts | 1 + packages/pluginutils/test/attachScopes.ts | 12 +- packages/replace/src/index.js | 3 +- packages/typescript/test/declarations.ts | 4 +- scripts/release.ts | 2 +- 6 files changed, 65 insertions(+), 66 deletions(-) diff --git a/packages/commonjs/src/resolve-require-sources.js b/packages/commonjs/src/resolve-require-sources.js index d392a0755..4efd6993d 100644 --- a/packages/commonjs/src/resolve-require-sources.js +++ b/packages/commonjs/src/resolve-require-sources.js @@ -140,7 +140,9 @@ export function getRequireResolver(extensions, detectCyclesAndConditional, curre if (isWrappedId(resolved.id, ES_IMPORT_SUFFIX)) { return ( (await getTypeForImportedModule( - (await this.load({ id: resolved.id })).meta.commonjs.resolved, + ( + await this.load({ id: resolved.id }) + ).meta.commonjs.resolved, this.load )) !== IS_WRAPPED_COMMONJS ); @@ -151,61 +153,56 @@ export function getRequireResolver(extensions, detectCyclesAndConditional, curre ).some((shouldTransform) => shouldTransform); }, /* eslint-disable no-param-reassign */ - resolveRequireSourcesAndUpdateMeta: (rollupContext) => async ( - parentId, - isParentCommonJS, - parentMeta, - sources - ) => { - parentMeta.initialCommonJSType = isParentCommonJS; - parentMeta.requires = []; - parentMeta.isRequiredCommonJS = Object.create(null); - setInitialParentType(parentId, isParentCommonJS); - const currentlyResolvingForParent = currentlyResolving.get(parentId) || new Set(); - currentlyResolving.set(parentId, currentlyResolvingForParent); - const requireTargets = await Promise.all( - sources.map(async ({ source, isConditional }) => { - // Never analyze or proxy internal modules - if (source.startsWith('\0')) { - return { id: source, allowProxy: false }; - } - currentlyResolvingForParent.add(source); - const resolved = - (await rollupContext.resolve(source, parentId, { - custom: { 'node-resolve': { isRequire: true } } - })) || resolveExtensions(source, parentId, extensions); - currentlyResolvingForParent.delete(source); - if (!resolved) { - return { id: wrapId(source, EXTERNAL_SUFFIX), allowProxy: false }; - } - const childId = resolved.id; - if (resolved.external) { - return { id: wrapId(childId, EXTERNAL_SUFFIX), allowProxy: false }; - } - parentMeta.requires.push({ resolved, isConditional }); - await analyzeRequiredModule(parentId, resolved, isConditional, rollupContext.load); - return { id: childId, allowProxy: true }; - }) - ); - parentMeta.isCommonJS = getTypeForFullyAnalyzedModule(parentId); - fullyAnalyzedModules[parentId] = true; - return requireTargets.map(({ id: dependencyId, allowProxy }, index) => { - // eslint-disable-next-line no-multi-assign - const isCommonJS = (parentMeta.isRequiredCommonJS[ - dependencyId - ] = getTypeForFullyAnalyzedModule(dependencyId)); - fullyAnalyzedModules[dependencyId] = true; - return { - source: sources[index].source, - id: allowProxy - ? isCommonJS === IS_WRAPPED_COMMONJS - ? wrapId(dependencyId, WRAPPED_SUFFIX) - : wrapId(dependencyId, PROXY_SUFFIX) - : dependencyId, - isCommonJS - }; - }); - }, + resolveRequireSourcesAndUpdateMeta: + (rollupContext) => async (parentId, isParentCommonJS, parentMeta, sources) => { + parentMeta.initialCommonJSType = isParentCommonJS; + parentMeta.requires = []; + parentMeta.isRequiredCommonJS = Object.create(null); + setInitialParentType(parentId, isParentCommonJS); + const currentlyResolvingForParent = currentlyResolving.get(parentId) || new Set(); + currentlyResolving.set(parentId, currentlyResolvingForParent); + const requireTargets = await Promise.all( + sources.map(async ({ source, isConditional }) => { + // Never analyze or proxy internal modules + if (source.startsWith('\0')) { + return { id: source, allowProxy: false }; + } + currentlyResolvingForParent.add(source); + const resolved = + (await rollupContext.resolve(source, parentId, { + custom: { 'node-resolve': { isRequire: true } } + })) || resolveExtensions(source, parentId, extensions); + currentlyResolvingForParent.delete(source); + if (!resolved) { + return { id: wrapId(source, EXTERNAL_SUFFIX), allowProxy: false }; + } + const childId = resolved.id; + if (resolved.external) { + return { id: wrapId(childId, EXTERNAL_SUFFIX), allowProxy: false }; + } + parentMeta.requires.push({ resolved, isConditional }); + await analyzeRequiredModule(parentId, resolved, isConditional, rollupContext.load); + return { id: childId, allowProxy: true }; + }) + ); + parentMeta.isCommonJS = getTypeForFullyAnalyzedModule(parentId); + fullyAnalyzedModules[parentId] = true; + return requireTargets.map(({ id: dependencyId, allowProxy }, index) => { + // eslint-disable-next-line no-multi-assign + const isCommonJS = (parentMeta.isRequiredCommonJS[dependencyId] = + getTypeForFullyAnalyzedModule(dependencyId)); + fullyAnalyzedModules[dependencyId] = true; + return { + source: sources[index].source, + id: allowProxy + ? isCommonJS === IS_WRAPPED_COMMONJS + ? wrapId(dependencyId, WRAPPED_SUFFIX) + : wrapId(dependencyId, PROXY_SUFFIX) + : dependencyId, + isCommonJS + }; + }); + }, isCurrentlyResolving(source, parentId) { const currentlyResolvingForParent = currentlyResolving.get(parentId); return currentlyResolvingForParent && currentlyResolvingForParent.has(source); diff --git a/packages/multi-entry/types/index.d.ts b/packages/multi-entry/types/index.d.ts index 7327aad86..0d6c085c3 100644 --- a/packages/multi-entry/types/index.d.ts +++ b/packages/multi-entry/types/index.d.ts @@ -23,6 +23,7 @@ interface RollupMultiEntryOptions { /** * `entryFileName` changes the name of the generated entry file. * By default, it will override `outputOptions.entryFileNames` to be `'multi-entry.js'`. + * @default 'multi-entry.js' */ entryFileName?: string; /** diff --git a/packages/pluginutils/test/attachScopes.ts b/packages/pluginutils/test/attachScopes.ts index 23d4214c5..eb4c6bdb1 100755 --- a/packages/pluginutils/test/attachScopes.ts +++ b/packages/pluginutils/test/attachScopes.ts @@ -74,7 +74,7 @@ test('supports catch without a parameter', (t) => { }); test('supports ForStatement', (t) => { - const ast = (parse( + const ast = parse( ` for (let a = 0; a < 10; a++) { console.log(a); @@ -82,7 +82,7 @@ test('supports ForStatement', (t) => { } `, { ecmaVersion: 2020, sourceType: 'module' } - ) as unknown) as estree.Program; + ) as unknown as estree.Program; const scope = attachScopes(ast, 'scope'); t.falsy(scope.contains('a')); @@ -99,7 +99,7 @@ test('supports ForStatement', (t) => { }); test('supports ForOfStatement', (t) => { - const ast = (parse( + const ast = parse( ` for (const a of [1, 2, 3]) { console.log(a); @@ -107,7 +107,7 @@ test('supports ForOfStatement', (t) => { } `, { ecmaVersion: 2020, sourceType: 'module' } - ) as unknown) as estree.Program; + ) as unknown as estree.Program; const scope = attachScopes(ast, 'scope'); t.falsy(scope.contains('a')); @@ -123,7 +123,7 @@ test('supports ForOfStatement', (t) => { }); test('supports ForInStatement', (t) => { - const ast = (parse( + const ast = parse( ` for (let a in [1, 2, 3]) { console.log(a); @@ -131,7 +131,7 @@ test('supports ForInStatement', (t) => { } `, { ecmaVersion: 2020, sourceType: 'module' } - ) as unknown) as estree.Program; + ) as unknown as estree.Program; const scope = attachScopes(ast, 'scope'); t.falsy(scope.contains('a')); diff --git a/packages/replace/src/index.js b/packages/replace/src/index.js index e65f30712..cd1ff5563 100755 --- a/packages/replace/src/index.js +++ b/packages/replace/src/index.js @@ -36,7 +36,8 @@ function mapToFunctions(object) { }, {}); } -const objKeyRegEx = /^([_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*)(\.([_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*))+$/; +const objKeyRegEx = + /^([_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*)(\.([_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*))+$/; function expandTypeofReplacements(replacements) { Object.keys(replacements).forEach((key) => { const objMatch = key.match(objKeyRegEx); diff --git a/packages/typescript/test/declarations.ts b/packages/typescript/test/declarations.ts index a8749b0f7..36ccdc85c 100644 --- a/packages/typescript/test/declarations.ts +++ b/packages/typescript/test/declarations.ts @@ -159,10 +159,10 @@ async function ensureOutDirWhenCreatingDeclarationFiles( ); t.true( - caughtError.message.includes( + caughtError!.message.includes( `'outDir' or 'declarationDir' must be specified to generate declaration files` ), - `Unexpected error message: ${caughtError.message}` + `Unexpected error message: ${caughtError!.message}` ); } diff --git a/scripts/release.ts b/scripts/release.ts index 9e6dec3a8..51384b760 100644 --- a/scripts/release.ts +++ b/scripts/release.ts @@ -83,7 +83,7 @@ const getCommits = async (shortName: string) => { if (!node.type) node.type = parser.sync(node.header?.replace(/\(.+\)!?:/, ':') || '').type; - ((node as unknown) as BreakingCommit).breaking = + (node as unknown as BreakingCommit).breaking = reBreaking.test(body) || /!:/.test(node.header as string); return node; From fe1f6b7d4113222d3bc0647978af73c62eba5627 Mon Sep 17 00:00:00 2001 From: Blake Lovelace Date: Sat, 15 Oct 2022 07:36:32 +0800 Subject: [PATCH 09/10] Improve test --- packages/multi-entry/test/test.mjs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/multi-entry/test/test.mjs b/packages/multi-entry/test/test.mjs index d9a689780..747422be7 100755 --- a/packages/multi-entry/test/test.mjs +++ b/packages/multi-entry/test/test.mjs @@ -119,7 +119,7 @@ test('makes a bundle with entryFileName as the output.entryFileName when preserv { format: 'cjs', preserveModules: true, - entryFileNames: (c) => `${c.name}.js` + entryFileNames: (c) => `entry-${c.name}.js` }, true ); @@ -128,6 +128,6 @@ test('makes a bundle with entryFileName as the output.entryFileName when preserv t.is(nonVirtualFiles.length, 2); - t.truthy(nonVirtualFiles.find(({ fileName }) => fileName === '0.js')); - t.truthy(nonVirtualFiles.find(({ fileName }) => fileName === '1.js')); + t.truthy(nonVirtualFiles.find(({ fileName }) => fileName === 'entry-0.js')); + t.truthy(nonVirtualFiles.find(({ fileName }) => fileName === 'entry-1.js')); }); From 073e1050b0854aa3b79127f9430c0f8f87e11908 Mon Sep 17 00:00:00 2001 From: Blake Lovelace Date: Sat, 15 Oct 2022 07:38:32 +0800 Subject: [PATCH 10/10] Fix tests --- packages/multi-entry/test/test.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/multi-entry/test/test.mjs b/packages/multi-entry/test/test.mjs index 747422be7..9addd6dad 100755 --- a/packages/multi-entry/test/test.mjs +++ b/packages/multi-entry/test/test.mjs @@ -100,7 +100,7 @@ test('maintains filename when preserveModules = true', async (t) => { const files = await getCode(bundle, { format: 'cjs', preserveModules: true }, true); - const nonVirtualFiles = files.filter(({ fileName }) => !fileName.startsWith('_virtual/')); + const nonVirtualFiles = files.filter(({ fileName }) => !fileName.includes('_virtual/')); t.is(nonVirtualFiles.length, 2); @@ -124,7 +124,7 @@ test('makes a bundle with entryFileName as the output.entryFileName when preserv true ); - const nonVirtualFiles = files.filter(({ fileName }) => !fileName.startsWith('_virtual/')); + const nonVirtualFiles = files.filter(({ fileName }) => !fileName.includes('_virtual/')); t.is(nonVirtualFiles.length, 2);