From dd1d6a91b2770cc2574a2303c0be24565a6383d9 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Thu, 28 Mar 2019 13:23:11 +0100 Subject: [PATCH 01/60] Merge compact and non-compact import.meta.url mechanisms --- test/form/samples/import-meta-url-compact/_config.js | 8 ++++++++ .../form/samples/import-meta-url-compact/_expected/amd.js | 1 + .../form/samples/import-meta-url-compact/_expected/cjs.js | 1 + test/form/samples/import-meta-url-compact/_expected/es.js | 1 + .../samples/import-meta-url-compact/_expected/iife.js | 1 + .../samples/import-meta-url-compact/_expected/system.js | 1 + .../form/samples/import-meta-url-compact/_expected/umd.js | 1 + test/form/samples/import-meta-url-compact/main.js | 1 + 8 files changed, 15 insertions(+) create mode 100644 test/form/samples/import-meta-url-compact/_config.js create mode 100644 test/form/samples/import-meta-url-compact/_expected/amd.js create mode 100644 test/form/samples/import-meta-url-compact/_expected/cjs.js create mode 100644 test/form/samples/import-meta-url-compact/_expected/es.js create mode 100644 test/form/samples/import-meta-url-compact/_expected/iife.js create mode 100644 test/form/samples/import-meta-url-compact/_expected/system.js create mode 100644 test/form/samples/import-meta-url-compact/_expected/umd.js create mode 100644 test/form/samples/import-meta-url-compact/main.js diff --git a/test/form/samples/import-meta-url-compact/_config.js b/test/form/samples/import-meta-url-compact/_config.js new file mode 100644 index 00000000000..5c250b32a03 --- /dev/null +++ b/test/form/samples/import-meta-url-compact/_config.js @@ -0,0 +1,8 @@ +module.exports = { + description: 'import.meta.url support in compact mode', + options: { + output: { + compact: true + } + } +}; diff --git a/test/form/samples/import-meta-url-compact/_expected/amd.js b/test/form/samples/import-meta-url-compact/_expected/amd.js new file mode 100644 index 00000000000..9049a3c865d --- /dev/null +++ b/test/form/samples/import-meta-url-compact/_expected/amd.js @@ -0,0 +1 @@ +define(['module'],function(module){'use strict';console.log(new URL((typeof process!=='undefined'&&process.versions&&process.versions.node?'file:':'')+module.uri).href);}); \ No newline at end of file diff --git a/test/form/samples/import-meta-url-compact/_expected/cjs.js b/test/form/samples/import-meta-url-compact/_expected/cjs.js new file mode 100644 index 00000000000..a2dc745981b --- /dev/null +++ b/test/form/samples/import-meta-url-compact/_expected/cjs.js @@ -0,0 +1 @@ +'use strict';console.log(new(typeof URL!=='undefined'?URL:require('ur'+'l').URL)((process.browser?'':'file:')+__filename,process.browser&&document.baseURI).href); \ No newline at end of file diff --git a/test/form/samples/import-meta-url-compact/_expected/es.js b/test/form/samples/import-meta-url-compact/_expected/es.js new file mode 100644 index 00000000000..0c4061a00d3 --- /dev/null +++ b/test/form/samples/import-meta-url-compact/_expected/es.js @@ -0,0 +1 @@ +console.log(import.meta.url); \ No newline at end of file diff --git a/test/form/samples/import-meta-url-compact/_expected/iife.js b/test/form/samples/import-meta-url-compact/_expected/iife.js new file mode 100644 index 00000000000..578ef472f7c --- /dev/null +++ b/test/form/samples/import-meta-url-compact/_expected/iife.js @@ -0,0 +1 @@ +(function(){'use strict';console.log((typeof document!=='undefined'?document.currentScript&&document.currentScript.src||document.baseURI:new(typeof URL!=='undefined'?URL:require('ur'+'l').URL)('file:'+__filename).href));}()); \ No newline at end of file diff --git a/test/form/samples/import-meta-url-compact/_expected/system.js b/test/form/samples/import-meta-url-compact/_expected/system.js new file mode 100644 index 00000000000..d423f33fb4b --- /dev/null +++ b/test/form/samples/import-meta-url-compact/_expected/system.js @@ -0,0 +1 @@ +System.register([],function(exports,module){'use strict';return{execute:function(){console.log(module.meta.url);}}}); \ No newline at end of file diff --git a/test/form/samples/import-meta-url-compact/_expected/umd.js b/test/form/samples/import-meta-url-compact/_expected/umd.js new file mode 100644 index 00000000000..ff15e5ae749 --- /dev/null +++ b/test/form/samples/import-meta-url-compact/_expected/umd.js @@ -0,0 +1 @@ +(function(f){typeof define==='function'&&define.amd?define(f):f();}(function(){'use strict';console.log((typeof document!=='undefined'?document.currentScript&&document.currentScript.src||document.baseURI:new(typeof URL!=='undefined'?URL:require('ur'+'l').URL)('file:'+__filename).href));})); \ No newline at end of file diff --git a/test/form/samples/import-meta-url-compact/main.js b/test/form/samples/import-meta-url-compact/main.js new file mode 100644 index 00000000000..0c4061a00d3 --- /dev/null +++ b/test/form/samples/import-meta-url-compact/main.js @@ -0,0 +1 @@ +console.log(import.meta.url); \ No newline at end of file From 9c53d2402dccc25ef60c1d07bfa4a8e9fc2d51d1 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Fri, 29 Mar 2019 08:51:15 +0100 Subject: [PATCH 02/60] Extract more common code --- test/form/samples/import-meta-url-compact/_config.js | 8 -------- .../form/samples/import-meta-url-compact/_expected/amd.js | 1 - .../form/samples/import-meta-url-compact/_expected/cjs.js | 1 - test/form/samples/import-meta-url-compact/_expected/es.js | 1 - .../samples/import-meta-url-compact/_expected/iife.js | 1 - .../samples/import-meta-url-compact/_expected/system.js | 1 - .../form/samples/import-meta-url-compact/_expected/umd.js | 1 - test/form/samples/import-meta-url-compact/main.js | 1 - 8 files changed, 15 deletions(-) delete mode 100644 test/form/samples/import-meta-url-compact/_config.js delete mode 100644 test/form/samples/import-meta-url-compact/_expected/amd.js delete mode 100644 test/form/samples/import-meta-url-compact/_expected/cjs.js delete mode 100644 test/form/samples/import-meta-url-compact/_expected/es.js delete mode 100644 test/form/samples/import-meta-url-compact/_expected/iife.js delete mode 100644 test/form/samples/import-meta-url-compact/_expected/system.js delete mode 100644 test/form/samples/import-meta-url-compact/_expected/umd.js delete mode 100644 test/form/samples/import-meta-url-compact/main.js diff --git a/test/form/samples/import-meta-url-compact/_config.js b/test/form/samples/import-meta-url-compact/_config.js deleted file mode 100644 index 5c250b32a03..00000000000 --- a/test/form/samples/import-meta-url-compact/_config.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = { - description: 'import.meta.url support in compact mode', - options: { - output: { - compact: true - } - } -}; diff --git a/test/form/samples/import-meta-url-compact/_expected/amd.js b/test/form/samples/import-meta-url-compact/_expected/amd.js deleted file mode 100644 index 9049a3c865d..00000000000 --- a/test/form/samples/import-meta-url-compact/_expected/amd.js +++ /dev/null @@ -1 +0,0 @@ -define(['module'],function(module){'use strict';console.log(new URL((typeof process!=='undefined'&&process.versions&&process.versions.node?'file:':'')+module.uri).href);}); \ No newline at end of file diff --git a/test/form/samples/import-meta-url-compact/_expected/cjs.js b/test/form/samples/import-meta-url-compact/_expected/cjs.js deleted file mode 100644 index a2dc745981b..00000000000 --- a/test/form/samples/import-meta-url-compact/_expected/cjs.js +++ /dev/null @@ -1 +0,0 @@ -'use strict';console.log(new(typeof URL!=='undefined'?URL:require('ur'+'l').URL)((process.browser?'':'file:')+__filename,process.browser&&document.baseURI).href); \ No newline at end of file diff --git a/test/form/samples/import-meta-url-compact/_expected/es.js b/test/form/samples/import-meta-url-compact/_expected/es.js deleted file mode 100644 index 0c4061a00d3..00000000000 --- a/test/form/samples/import-meta-url-compact/_expected/es.js +++ /dev/null @@ -1 +0,0 @@ -console.log(import.meta.url); \ No newline at end of file diff --git a/test/form/samples/import-meta-url-compact/_expected/iife.js b/test/form/samples/import-meta-url-compact/_expected/iife.js deleted file mode 100644 index 578ef472f7c..00000000000 --- a/test/form/samples/import-meta-url-compact/_expected/iife.js +++ /dev/null @@ -1 +0,0 @@ -(function(){'use strict';console.log((typeof document!=='undefined'?document.currentScript&&document.currentScript.src||document.baseURI:new(typeof URL!=='undefined'?URL:require('ur'+'l').URL)('file:'+__filename).href));}()); \ No newline at end of file diff --git a/test/form/samples/import-meta-url-compact/_expected/system.js b/test/form/samples/import-meta-url-compact/_expected/system.js deleted file mode 100644 index d423f33fb4b..00000000000 --- a/test/form/samples/import-meta-url-compact/_expected/system.js +++ /dev/null @@ -1 +0,0 @@ -System.register([],function(exports,module){'use strict';return{execute:function(){console.log(module.meta.url);}}}); \ No newline at end of file diff --git a/test/form/samples/import-meta-url-compact/_expected/umd.js b/test/form/samples/import-meta-url-compact/_expected/umd.js deleted file mode 100644 index ff15e5ae749..00000000000 --- a/test/form/samples/import-meta-url-compact/_expected/umd.js +++ /dev/null @@ -1 +0,0 @@ -(function(f){typeof define==='function'&&define.amd?define(f):f();}(function(){'use strict';console.log((typeof document!=='undefined'?document.currentScript&&document.currentScript.src||document.baseURI:new(typeof URL!=='undefined'?URL:require('ur'+'l').URL)('file:'+__filename).href));})); \ No newline at end of file diff --git a/test/form/samples/import-meta-url-compact/main.js b/test/form/samples/import-meta-url-compact/main.js deleted file mode 100644 index 0c4061a00d3..00000000000 --- a/test/form/samples/import-meta-url-compact/main.js +++ /dev/null @@ -1 +0,0 @@ -console.log(import.meta.url); \ No newline at end of file From 98d5188a514f677356447adf84ac4689601e9f13 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Mon, 1 Apr 2019 07:07:38 +0200 Subject: [PATCH 03/60] Add option to configure import.meta.url resolution --- docs/999-big-list-of-options.md | 27 ++++++++++++++++++++++++++- src/utils/mergeOptions.ts | 1 + test/misc/optionList.js | 4 ++-- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/docs/999-big-list-of-options.md b/docs/999-big-list-of-options.md index ffc103d6839..8219a017ebe 100755 --- a/docs/999-big-list-of-options.md +++ b/docs/999-big-list-of-options.md @@ -614,6 +614,31 @@ Default: `true` Whether to `Object.freeze()` namespace import objects (i.e. `import * as namespaceImportObject from...`) that are accessed dynamically. +#### output.importMetaUrl +Type: `((chunkId: string, moduleId: string) => string)`
+ +This allows the user to configure how Rollup handles `import.meta.url`. In ES modules, `import.meta.url` returns the URL of the current module, e.g. `http://server.net/bundle.js` for browsers or `file:///path/to/bundle.js` in Node. + +By default for formats other than ES modules, Rollup replaces `import.meta.url` with code that attempts to match this behaviour by returning the dynamic URL of the current chunk. Note that all formats except CommonJS and UMD assume that they run in a browser environment where `URL` and `document` are available. + + This behaviour can be customized by supplying a function, which will replace `import.meta.url` for all formats: + +```javascript +// rollup.config.js +export default { + ..., + output: { + ..., + + // this will use the original module id when resolving import.meta.url + importMetaUrl(chunkId, moduleId) { + return `"${moduleId}"`; + } + } +}; + +``` + #### output.indent Type: `boolean | string`
CLI: `--indent`/`--no-indent`
@@ -621,7 +646,7 @@ Default: `true` The indent string to use, for formats that require code to be indented (`amd`, `iife`, `umd`, `system`). Can also be `false` (no indent), or `true` (the default – auto-indent) -```js +```javascript // rollup.config.js export default { ..., diff --git a/src/utils/mergeOptions.ts b/src/utils/mergeOptions.ts index a91739eb166..b87c1199fac 100644 --- a/src/utils/mergeOptions.ts +++ b/src/utils/mergeOptions.ts @@ -258,6 +258,7 @@ function getOutputOptions( format: format === 'esm' ? 'es' : format, freeze: getOption('freeze', true), globals: getOption('globals'), + importMetaUrl: getOption('importMetaUrl'), indent: getOption('indent', true), interop: getOption('interop', true), intro: getOption('intro'), diff --git a/test/misc/optionList.js b/test/misc/optionList.js index ab34fa25c8c..57b7a6cb097 100644 --- a/test/misc/optionList.js +++ b/test/misc/optionList.js @@ -1,3 +1,3 @@ exports.input = 'acorn, acornInjectPlugins, cache, chunkGroupingSize, context, experimentalCacheExpiry, experimentalOptimizeChunks, experimentalTopLevelAwait, external, inlineDynamicImports, input, manualChunks, moduleContext, onwarn, perf, plugins, preserveModules, preserveSymlinks, shimMissingExports, treeshake, watch'; -exports.flags = 'acorn, acornInjectPlugins, amd, assetFileNames, banner, c, cache, chunkFileNames, chunkGroupingSize, compact, config, context, d, dir, dynamicImportFunction, e, entryFileNames, environment, esModule, experimentalCacheExpiry, experimentalOptimizeChunks, experimentalTopLevelAwait, exports, extend, external, f, file, footer, format, freeze, g, globals, h, i, indent, inlineDynamicImports, input, interop, intro, m, manualChunks, moduleContext, n, name, namespaceToStringTag, noConflict, o, onwarn, outro, paths, perf, plugins, preferConst, preserveModules, preserveSymlinks, shimMissingExports, silent, sourcemap, sourcemapExcludeSources, sourcemapFile, strict, treeshake, v, w, watch'; -exports.output = 'amd, assetFileNames, banner, chunkFileNames, compact, dir, dynamicImportFunction, entryFileNames, esModule, exports, extend, file, footer, format, freeze, globals, indent, interop, intro, name, namespaceToStringTag, noConflict, outro, paths, preferConst, sourcemap, sourcemapExcludeSources, sourcemapFile, sourcemapPathTransform, strict'; +exports.flags = 'acorn, acornInjectPlugins, amd, assetFileNames, banner, c, cache, chunkFileNames, chunkGroupingSize, compact, config, context, d, dir, dynamicImportFunction, e, entryFileNames, environment, esModule, experimentalCacheExpiry, experimentalOptimizeChunks, experimentalTopLevelAwait, exports, extend, external, f, file, footer, format, freeze, g, globals, h, i, importMetaUrl, indent, inlineDynamicImports, input, interop, intro, m, manualChunks, moduleContext, n, name, namespaceToStringTag, noConflict, o, onwarn, outro, paths, perf, plugins, preferConst, preserveModules, preserveSymlinks, shimMissingExports, silent, sourcemap, sourcemapExcludeSources, sourcemapFile, strict, treeshake, v, w, watch'; +exports.output = 'amd, assetFileNames, banner, chunkFileNames, compact, dir, dynamicImportFunction, entryFileNames, esModule, exports, extend, file, footer, format, freeze, globals, importMetaUrl, indent, interop, intro, name, namespaceToStringTag, noConflict, outro, paths, preferConst, sourcemap, sourcemapExcludeSources, sourcemapFile, sourcemapPathTransform, strict'; From df1c6420adcea810588d31c822ff24676174d4aa Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Fri, 5 Apr 2019 11:49:59 +0200 Subject: [PATCH 04/60] Switch to using a plugin hook --- docs/999-big-list-of-options.md | 27 +-------------------------- src/utils/mergeOptions.ts | 1 - test/misc/optionList.js | 4 ++-- 3 files changed, 3 insertions(+), 29 deletions(-) diff --git a/docs/999-big-list-of-options.md b/docs/999-big-list-of-options.md index 8219a017ebe..ffc103d6839 100755 --- a/docs/999-big-list-of-options.md +++ b/docs/999-big-list-of-options.md @@ -614,31 +614,6 @@ Default: `true` Whether to `Object.freeze()` namespace import objects (i.e. `import * as namespaceImportObject from...`) that are accessed dynamically. -#### output.importMetaUrl -Type: `((chunkId: string, moduleId: string) => string)`
- -This allows the user to configure how Rollup handles `import.meta.url`. In ES modules, `import.meta.url` returns the URL of the current module, e.g. `http://server.net/bundle.js` for browsers or `file:///path/to/bundle.js` in Node. - -By default for formats other than ES modules, Rollup replaces `import.meta.url` with code that attempts to match this behaviour by returning the dynamic URL of the current chunk. Note that all formats except CommonJS and UMD assume that they run in a browser environment where `URL` and `document` are available. - - This behaviour can be customized by supplying a function, which will replace `import.meta.url` for all formats: - -```javascript -// rollup.config.js -export default { - ..., - output: { - ..., - - // this will use the original module id when resolving import.meta.url - importMetaUrl(chunkId, moduleId) { - return `"${moduleId}"`; - } - } -}; - -``` - #### output.indent Type: `boolean | string`
CLI: `--indent`/`--no-indent`
@@ -646,7 +621,7 @@ Default: `true` The indent string to use, for formats that require code to be indented (`amd`, `iife`, `umd`, `system`). Can also be `false` (no indent), or `true` (the default – auto-indent) -```javascript +```js // rollup.config.js export default { ..., diff --git a/src/utils/mergeOptions.ts b/src/utils/mergeOptions.ts index b87c1199fac..a91739eb166 100644 --- a/src/utils/mergeOptions.ts +++ b/src/utils/mergeOptions.ts @@ -258,7 +258,6 @@ function getOutputOptions( format: format === 'esm' ? 'es' : format, freeze: getOption('freeze', true), globals: getOption('globals'), - importMetaUrl: getOption('importMetaUrl'), indent: getOption('indent', true), interop: getOption('interop', true), intro: getOption('intro'), diff --git a/test/misc/optionList.js b/test/misc/optionList.js index 57b7a6cb097..ab34fa25c8c 100644 --- a/test/misc/optionList.js +++ b/test/misc/optionList.js @@ -1,3 +1,3 @@ exports.input = 'acorn, acornInjectPlugins, cache, chunkGroupingSize, context, experimentalCacheExpiry, experimentalOptimizeChunks, experimentalTopLevelAwait, external, inlineDynamicImports, input, manualChunks, moduleContext, onwarn, perf, plugins, preserveModules, preserveSymlinks, shimMissingExports, treeshake, watch'; -exports.flags = 'acorn, acornInjectPlugins, amd, assetFileNames, banner, c, cache, chunkFileNames, chunkGroupingSize, compact, config, context, d, dir, dynamicImportFunction, e, entryFileNames, environment, esModule, experimentalCacheExpiry, experimentalOptimizeChunks, experimentalTopLevelAwait, exports, extend, external, f, file, footer, format, freeze, g, globals, h, i, importMetaUrl, indent, inlineDynamicImports, input, interop, intro, m, manualChunks, moduleContext, n, name, namespaceToStringTag, noConflict, o, onwarn, outro, paths, perf, plugins, preferConst, preserveModules, preserveSymlinks, shimMissingExports, silent, sourcemap, sourcemapExcludeSources, sourcemapFile, strict, treeshake, v, w, watch'; -exports.output = 'amd, assetFileNames, banner, chunkFileNames, compact, dir, dynamicImportFunction, entryFileNames, esModule, exports, extend, file, footer, format, freeze, globals, importMetaUrl, indent, interop, intro, name, namespaceToStringTag, noConflict, outro, paths, preferConst, sourcemap, sourcemapExcludeSources, sourcemapFile, sourcemapPathTransform, strict'; +exports.flags = 'acorn, acornInjectPlugins, amd, assetFileNames, banner, c, cache, chunkFileNames, chunkGroupingSize, compact, config, context, d, dir, dynamicImportFunction, e, entryFileNames, environment, esModule, experimentalCacheExpiry, experimentalOptimizeChunks, experimentalTopLevelAwait, exports, extend, external, f, file, footer, format, freeze, g, globals, h, i, indent, inlineDynamicImports, input, interop, intro, m, manualChunks, moduleContext, n, name, namespaceToStringTag, noConflict, o, onwarn, outro, paths, perf, plugins, preferConst, preserveModules, preserveSymlinks, shimMissingExports, silent, sourcemap, sourcemapExcludeSources, sourcemapFile, strict, treeshake, v, w, watch'; +exports.output = 'amd, assetFileNames, banner, chunkFileNames, compact, dir, dynamicImportFunction, entryFileNames, esModule, exports, extend, file, footer, format, freeze, globals, indent, interop, intro, name, namespaceToStringTag, noConflict, outro, paths, preferConst, sourcemap, sourcemapExcludeSources, sourcemapFile, sourcemapPathTransform, strict'; From 7276c9b108ef4f01627cd27527da960f9aebe604 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Fri, 29 Mar 2019 08:51:15 +0100 Subject: [PATCH 05/60] Extract more common code --- package-lock.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/package-lock.json b/package-lock.json index 612602a4855..b4f42718fd5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4180,6 +4180,12 @@ "integrity": "sha512-ipEzlWQe6RK3jkzikgCupiTbTvm4S0/CAU5GlgptkN5SO6F3u0UD0K18wy6ErDqiCyP4J4YYe1HuAShvsxePLg==", "dev": true }, + "requirejs": { + "version": "2.3.6", + "resolved": "https://registry.npmjs.org/requirejs/-/requirejs-2.3.6.tgz", + "integrity": "sha512-ipEzlWQe6RK3jkzikgCupiTbTvm4S0/CAU5GlgptkN5SO6F3u0UD0K18wy6ErDqiCyP4J4YYe1HuAShvsxePLg==", + "dev": true + }, "requires-port": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz", From 6127570a516deb8a7ad252bc5b9a68d489573eeb Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Mon, 8 Apr 2019 08:01:17 +0200 Subject: [PATCH 06/60] Move functionality into default plugin --- src/utils/defaultPlugin.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/utils/defaultPlugin.ts b/src/utils/defaultPlugin.ts index b8e4d8e84ba..39887a0ac93 100644 --- a/src/utils/defaultPlugin.ts +++ b/src/utils/defaultPlugin.ts @@ -131,3 +131,25 @@ const relativeUrlMechanisms: Record string> = `(require('u' + 'rl').URL)` )} : ${getRelativeUrlFromDocument(relativePath)})` }; + +const getRelativeUrlFromDocument = (relativePath: string) => + getResolveUrl( + `(document.currentScript && document.currentScript.src || document.baseURI) + '/../${relativePath}'` + ); + +const relativeUrlMechanisms: Record string> = { + amd: relativePath => getResolveUrl(`module.uri + '/../${relativePath}', document.baseURI`), + cjs: relativePath => + `(typeof document === 'undefined' ? ${getResolveUrl( + `'file:' + __dirname + '/${relativePath}'`, + `(require('u' + 'rl').URL)` + )} : ${getRelativeUrlFromDocument(relativePath)})`, + es: relativePath => getResolveUrl(`'${relativePath}', import.meta.url`), + iife: relativePath => getRelativeUrlFromDocument(relativePath), + system: relativePath => getResolveUrl(`'${relativePath}', module.meta.url`), + umd: relativePath => + `(typeof document === 'undefined' ? ${getResolveUrl( + `'file:' + __dirname + '/${relativePath}'`, + `(require('u' + 'rl').URL)` + )} : ${getRelativeUrlFromDocument(relativePath)})` +}; From a3c40fd18870dc5aea75dc09b350dd4d4ddda930 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Tue, 9 Apr 2019 13:03:17 +0200 Subject: [PATCH 07/60] Improve SystemJS handling --- package-lock.json | 6 ------ 1 file changed, 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index b4f42718fd5..612602a4855 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4180,12 +4180,6 @@ "integrity": "sha512-ipEzlWQe6RK3jkzikgCupiTbTvm4S0/CAU5GlgptkN5SO6F3u0UD0K18wy6ErDqiCyP4J4YYe1HuAShvsxePLg==", "dev": true }, - "requirejs": { - "version": "2.3.6", - "resolved": "https://registry.npmjs.org/requirejs/-/requirejs-2.3.6.tgz", - "integrity": "sha512-ipEzlWQe6RK3jkzikgCupiTbTvm4S0/CAU5GlgptkN5SO6F3u0UD0K18wy6ErDqiCyP4J4YYe1HuAShvsxePLg==", - "dev": true - }, "requires-port": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz", From 660e880296e4be5f963070965b8d95b643acbbb8 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Sun, 31 Mar 2019 18:51:21 +0200 Subject: [PATCH 08/60] Refactor import.meta.url handling --- test/chunking-form/samples/asset-emission/index.html | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 test/chunking-form/samples/asset-emission/index.html diff --git a/test/chunking-form/samples/asset-emission/index.html b/test/chunking-form/samples/asset-emission/index.html new file mode 100644 index 00000000000..58ae4a61527 --- /dev/null +++ b/test/chunking-form/samples/asset-emission/index.html @@ -0,0 +1,10 @@ + + + + + Title + + + + + From e053537991d1d7bbca20b63c2294a40ac86d5d03 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Sun, 7 Apr 2019 17:03:33 +0200 Subject: [PATCH 09/60] Fix, refactor and test asset emission --- test/chunking-form/samples/asset-emission/index.html | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 test/chunking-form/samples/asset-emission/index.html diff --git a/test/chunking-form/samples/asset-emission/index.html b/test/chunking-form/samples/asset-emission/index.html deleted file mode 100644 index 58ae4a61527..00000000000 --- a/test/chunking-form/samples/asset-emission/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - Title - - - - - From eadfdce992b9092d695e8412c8c837d42257fb22 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Sun, 10 Mar 2019 09:04:17 +0100 Subject: [PATCH 10/60] Extract ModuleLoader --- bin/src/run/loadConfigFile.ts | 5 +- src/Graph.ts | 337 ++----------------- src/ModuleLoader.ts | 329 ++++++++++++++++++ src/finalisers/system.ts | 5 +- src/rollup/index.ts | 11 +- src/utils/collapseSourcemaps.ts | 6 +- src/utils/pluginDriver.ts | 10 +- src/watch/index.ts | 6 +- test/function/samples/module-tree/_config.js | 10 +- test/misc/write-bundle.js | 16 +- 10 files changed, 373 insertions(+), 362 deletions(-) create mode 100644 src/ModuleLoader.ts diff --git a/bin/src/run/loadConfigFile.ts b/bin/src/run/loadConfigFile.ts index 03c02d28565..3fbba121fe6 100644 --- a/bin/src/run/loadConfigFile.ts +++ b/bin/src/run/loadConfigFile.ts @@ -19,9 +19,8 @@ export default function loadConfigFile( return rollup .rollup({ - external: (id: string) => { - return (id[0] !== '.' && !path.isAbsolute(id)) || id.slice(-5, id.length) === '.json'; - }, + external: (id: string) => + (id[0] !== '.' && !path.isAbsolute(id)) || id.slice(-5, id.length) === '.json', input: configFile, onwarn: warnings.add, treeshake: false diff --git a/src/Graph.ts b/src/Graph.ts index 2657d6ef9ff..5d9c8dbf3f2 100644 --- a/src/Graph.ts +++ b/src/Graph.ts @@ -8,19 +8,17 @@ import { EntityPathTracker } from './ast/utils/EntityPathTracker'; import Chunk from './Chunk'; import ExternalModule from './ExternalModule'; import Module, { defaultAcornOptions } from './Module'; +import { ModuleLoader } from './ModuleLoader'; import { Asset, InputOptions, IsExternal, ModuleJSON, OutputBundle, - ResolvedId, - ResolveIdResult, RollupCache, RollupWarning, RollupWatcher, SerializablePluginCache, - SourceDescription, TreeshakingOptions, WarningHandler } from './rollup/types'; @@ -29,11 +27,10 @@ import { assignChunkColouringHashes } from './utils/chunkColouring'; import { Uint8ArrayToHexString } from './utils/entryHashing'; import { error } from './utils/error'; import { analyseModuleExecution, sortByExecutionOrder } from './utils/executionOrder'; -import { isRelative, resolve } from './utils/path'; +import { resolve } from './utils/path'; import { createPluginDriver, PluginDriver } from './utils/pluginDriver'; -import relativeId, { getAliasName } from './utils/relativeId'; +import relativeId from './utils/relativeId'; import { timeEnd, timeStart } from './utils/timers'; -import transform from './utils/transform'; function makeOnwarn() { const warned = Object.create(null); @@ -46,10 +43,6 @@ function makeOnwarn() { }; } -function normalizeRelativeExternalId(importee: string, source: string) { - return isRelative(source) ? resolve(importee, '..', source) : source; -} - export default class Graph { acornOptions: acorn.Options; acornParser: typeof acorn.Parser; @@ -130,13 +123,12 @@ export default class Graph { this.isPureExternalModule = () => false; } - this.contextParse = (code: string, options: acorn.Options = {}) => { - return this.acornParser.parse(code, { + this.contextParse = (code: string, options: acorn.Options = {}) => + this.acornParser.parse(code, { ...defaultAcornOptions, ...options, ...this.acornOptions }) as any; - }; this.pluginDriver = createPluginDriver(this, options, this.pluginCache, watcher); @@ -148,6 +140,7 @@ export default class Graph { }); } + // TODO Lukas move this to the module loader if (typeof options.external === 'function') { const external = options.external; this.isExternal = (id, parentId, isResolved) => @@ -208,9 +201,19 @@ export default class Graph { // of the entry module's dependencies timeStart('parse modules', 2); - - return this.loadEntryModules(entryModules, manualChunks).then( - ({ entryModules, entryModuleAliases, manualChunkModules }) => { + const moduleLoader = new ModuleLoader(this, this.moduleById); + + return moduleLoader + .loadEntryModules(entryModules, manualChunks) + .then(({ entryModules, entryModuleAliases, manualChunkModules }) => { + for (const module of Array.from(this.moduleById.values())) { + if (module instanceof Module) { + this.modules.push(module); + this.watchFiles[module.id] = true; + } else { + this.externalModules.push(module); + } + } timeEnd('parse modules', 2); // Phase 2 - linking. We populate the module dependency links and @@ -336,8 +339,7 @@ export default class Graph { this.finished = true; return chunks.concat(facades); - } - ); + }); } finaliseAssets(assetFileNames: string) { @@ -398,151 +400,6 @@ export default class Graph { this.onwarn(warning); } - private fetchAllDependencies(module: Module) { - const fetchDynamicImportsPromise = Promise.all( - module.getDynamicImportExpressions().map((dynamicImportExpression, index) => - this.pluginDriver - .hookFirst('resolveDynamicImport', [dynamicImportExpression, module.id]) - .then(replacement => { - if (!replacement) return; - const dynamicImport = module.dynamicImports[index]; - dynamicImport.alias = getAliasName( - replacement, - typeof dynamicImportExpression === 'string' ? dynamicImportExpression : undefined - ); - if (typeof dynamicImportExpression !== 'string') { - dynamicImport.resolution = replacement; - } else if (this.isExternal(replacement, module.id, true)) { - let externalModule; - if (!this.moduleById.has(replacement)) { - externalModule = new ExternalModule({ - graph: this, - id: replacement - }); - this.externalModules.push(externalModule); - this.moduleById.set(replacement, module); - } else { - externalModule = this.moduleById.get(replacement); - } - dynamicImport.resolution = externalModule; - externalModule.exportsNamespace = true; - } else { - return this.fetchModule(replacement, module.id).then(depModule => { - dynamicImport.resolution = depModule; - }); - } - }) - ) - ); - fetchDynamicImportsPromise.catch(() => {}); - - return Promise.all( - module.sources.map(source => this.resolveAndFetchDependency(module, source)) - ).then(() => fetchDynamicImportsPromise); - } - - private fetchModule(id: string, importer: string): Promise { - // short-circuit cycles - const existingModule = this.moduleById.get(id); - if (existingModule) { - if (existingModule.isExternal) throw new Error(`Cannot fetch external module ${id}`); - return Promise.resolve(existingModule); - } - - const module: Module = new Module(this, id); - this.moduleById.set(id, module); - this.watchFiles[id] = true; - - timeStart('load modules', 3); - return Promise.resolve(this.pluginDriver.hookFirst('load', [id])) - .catch((err: Error) => { - timeEnd('load modules', 3); - let msg = `Could not load ${id}`; - if (importer) msg += ` (imported by ${importer})`; - - msg += `: ${err.message}`; - throw new Error(msg); - }) - .then(source => { - timeEnd('load modules', 3); - if (typeof source === 'string') return source; - if (source && typeof source === 'object' && typeof source.code === 'string') return source; - - // TODO report which plugin failed - error({ - code: 'BAD_LOADER', - message: `Error loading ${relativeId( - id - )}: plugin load hook should return a string, a { code, map } object, or nothing/null` - }); - }) - .then(source => { - const sourceDescription: SourceDescription = - typeof source === 'string' - ? { - ast: null, - code: source - } - : source; - - const cachedModule = this.cachedModules.get(id); - if ( - cachedModule && - !cachedModule.customTransformCache && - cachedModule.originalCode === sourceDescription.code - ) { - // re-emit transform assets - if (cachedModule.transformAssets) { - for (const asset of cachedModule.transformAssets) - this.pluginDriver.emitAsset(asset.name, asset.source); - } - return cachedModule; - } - - return transform(this, sourceDescription, module); - }) - .then((source: ModuleJSON) => { - module.setSource(source); - - this.modules.push(module); - this.moduleById.set(id, module); - - return this.fetchAllDependencies(module).then(() => { - for (const name in module.exports) { - if (name !== 'default') { - module.exportsAll[name] = module.id; - } - } - module.exportAllSources.forEach(source => { - const id = module.resolvedIds[source].id; - const exportAllModule = this.moduleById.get(id); - if (exportAllModule.isExternal) return; - - for (const name in (exportAllModule).exportsAll) { - if (name in module.exportsAll) { - this.warn({ - code: 'NAMESPACE_CONFLICT', - message: `Conflicting namespaces: ${relativeId( - module.id - )} re-exports '${name}' from both ${relativeId( - module.exportsAll[name] - )} and ${relativeId( - (exportAllModule).exportsAll[name] - )} (will be ignored)`, - name, - reexporter: module.id, - sources: [module.exportsAll[name], (exportAllModule).exportsAll[name]] - }); - } else { - module.exportsAll[name] = (exportAllModule).exportsAll[name]; - } - } - }); - return module; - }); - }); - } - private link(entryModules: Module[]) { for (const module of this.modules) { module.linkDependencies(); @@ -562,160 +419,6 @@ export default class Graph { this.warnForMissingExports(); } - private loadEntryModules( - entryModules: string | string[] | Record, - manualChunks: Record | void - ) { - let removeAliasExtensions = false; - let entryModuleIds: string[]; - let entryModuleAliases: string[]; - if (typeof entryModules === 'string') entryModules = [entryModules]; - - if (Array.isArray(entryModules)) { - removeAliasExtensions = true; - entryModuleAliases = entryModules.concat([]); - entryModuleIds = entryModules; - } else { - entryModuleAliases = Object.keys(entryModules); - entryModuleIds = entryModuleAliases.map(name => (>entryModules)[name]); - } - - const entryAndManualChunkIds = entryModuleIds.concat([]); - if (manualChunks) { - Object.keys(manualChunks).forEach(name => { - const manualChunkIds = manualChunks[name]; - manualChunkIds.forEach(id => { - if (entryAndManualChunkIds.indexOf(id) === -1) entryAndManualChunkIds.push(id); - }); - }); - } - - return Promise.all(entryAndManualChunkIds.map(id => this.loadModule(id))).then( - entryAndChunkModules => { - if (removeAliasExtensions) { - for (let i = 0; i < entryModuleAliases.length; i++) - entryModuleAliases[i] = getAliasName(entryAndChunkModules[i].id, entryModuleAliases[i]); - } - - const entryModules = entryAndChunkModules.slice(0, entryModuleIds.length); - - let manualChunkModules: { [chunkName: string]: Module[] }; - if (manualChunks) { - manualChunkModules = {}; - for (const chunkName of Object.keys(manualChunks)) { - const chunk = manualChunks[chunkName]; - manualChunkModules[chunkName] = chunk.map(entryId => { - const entryIndex = entryAndManualChunkIds.indexOf(entryId); - return entryAndChunkModules[entryIndex]; - }); - } - } - - return { entryModules, entryModuleAliases, manualChunkModules }; - } - ); - } - - private loadModule(entryName: string) { - return this.pluginDriver - .hookFirst('resolveId', [entryName, undefined]) - .then(id => { - if (id === false) { - error({ - code: 'UNRESOLVED_ENTRY', - message: `Entry module cannot be external` - }); - } - - if (id == null) { - error({ - code: 'UNRESOLVED_ENTRY', - message: `Could not resolve entry (${entryName})` - }); - } - - return this.fetchModule(id, undefined); - }); - } - - private normalizeResolveIdResult( - resolveIdResult: ResolveIdResult, - module: Module, - source: string - ): ResolvedId { - let id = ''; - let external = false; - if (resolveIdResult) { - if (typeof resolveIdResult === 'object') { - id = resolveIdResult.id; - if (resolveIdResult.external) { - external = true; - } - } else { - id = resolveIdResult; - if (this.isExternal(id, module.id, true)) { - external = true; - } - } - if (external) { - id = normalizeRelativeExternalId(module.id, id); - } - } else { - id = normalizeRelativeExternalId(module.id, source); - external = true; - if (resolveIdResult !== false && !this.isExternal(id, module.id, true)) { - if (isRelative(source)) { - error({ - code: 'UNRESOLVED_IMPORT', - message: `Could not resolve '${source}' from ${relativeId(module.id)}` - }); - } - this.warn({ - code: 'UNRESOLVED_IMPORT', - importer: relativeId(module.id), - message: `'${source}' is imported by ${relativeId( - module.id - )}, but could not be resolved – treating it as an external dependency`, - source, - url: 'https://rollupjs.org/guide/en#warning-treating-module-as-external-dependency' - }); - } - } - return { id, external }; - } - - private resolveAndFetchDependency(module: Module, source: string): Promise { - return Promise.resolve( - module.resolvedIds[source] || - Promise.resolve( - this.isExternal(source, module.id, false) - ? { id: source, external: true } - : this.pluginDriver.hookFirst('resolveId', [source, module.id]) - ).then(result => this.normalizeResolveIdResult(result, module, source)) - ).then(resolvedId => { - module.resolvedIds[source] = resolvedId; - if (resolvedId.external) { - if (!this.moduleById.has(resolvedId.id)) { - const module = new ExternalModule({ graph: this, id: resolvedId.id }); - this.externalModules.push(module); - this.moduleById.set(resolvedId.id, module); - } - - const externalModule = this.moduleById.get(resolvedId.id); - if (externalModule instanceof ExternalModule === false) { - error({ - code: 'INVALID_EXTERNAL_ID', - message: `'${source}' is imported as an external by ${relativeId( - module.id - )}, but is already an existing non-external module id.` - }); - } - } else { - return this.fetchModule(resolvedId.id, module.id); - } - }); - } - private warnForMissingExports() { for (const module of this.modules) { for (const importName of Object.keys(module.importDescriptions)) { diff --git a/src/ModuleLoader.ts b/src/ModuleLoader.ts new file mode 100644 index 00000000000..a702fc24ddb --- /dev/null +++ b/src/ModuleLoader.ts @@ -0,0 +1,329 @@ +import ExternalModule from './ExternalModule'; +import Graph from './Graph'; +import Module from './Module'; +import { ModuleJSON, ResolvedId, ResolveIdResult, SourceDescription } from './rollup/types'; +import { error } from './utils/error'; +import { isRelative, resolve } from './utils/path'; +import relativeId, { getAliasName } from './utils/relativeId'; +import { timeEnd, timeStart } from './utils/timers'; +import transform from './utils/transform'; + +function normalizeRelativeExternalId(importee: string, source: string) { + return isRelative(source) ? resolve(importee, '..', source) : source; +} + +export class ModuleLoader { + private readonly graph: Graph; + private readonly modulesById: Map; + + // TODO Lukas get rid of graph dependence + constructor(graph: Graph, modulesById: Map) { + this.graph = graph; + this.modulesById = modulesById; + } + + loadEntryModules( + entryModules: string | string[] | Record, + manualChunks: Record | void + ) { + // TODO Lukas the parsing of entry modules could happen outside + let removeAliasExtensions = false; + let entryModuleIds: string[]; + let entryModuleAliases: string[]; + if (typeof entryModules === 'string') entryModules = [entryModules]; + + if (Array.isArray(entryModules)) { + removeAliasExtensions = true; + entryModuleAliases = entryModules.concat([]); + entryModuleIds = entryModules; + } else { + entryModuleAliases = Object.keys(entryModules); + entryModuleIds = entryModuleAliases.map(name => (>entryModules)[name]); + } + + const entryAndManualChunkIds = entryModuleIds.concat([]); + if (manualChunks) { + Object.keys(manualChunks).forEach(name => { + const manualChunkIds = manualChunks[name]; + manualChunkIds.forEach(id => { + if (entryAndManualChunkIds.indexOf(id) === -1) entryAndManualChunkIds.push(id); + }); + }); + } + + // TODO Lukas We want to return a Promise which we do not know completely yet + // - We create a manual Promise + // - The resolved Promise.all checks if new entries are added. If not, it resolves, otherwise it does another Promise.all + // - First collect all entries + return Promise.all(entryAndManualChunkIds.map(id => this.loadEntryModule(id))).then( + entryAndChunkModules => { + if (removeAliasExtensions) { + for (let i = 0; i < entryModuleAliases.length; i++) + entryModuleAliases[i] = getAliasName(entryAndChunkModules[i].id, entryModuleAliases[i]); + } + + const entryModules = entryAndChunkModules.slice(0, entryModuleIds.length); + + let manualChunkModules: { [chunkName: string]: Module[] }; + if (manualChunks) { + manualChunkModules = {}; + for (const chunkName of Object.keys(manualChunks)) { + const chunk = manualChunks[chunkName]; + console.log(entryAndChunkModules); + manualChunkModules[chunkName] = chunk.map( + entryId => entryAndChunkModules[entryAndManualChunkIds.indexOf(entryId)] + ); + } + } + + // TODO Lukas at this point, the entry modules need to contain all entry points + return { entryModules, entryModuleAliases, manualChunkModules }; + } + ); + } + + // // TODO Lukas in an ideal world, all entries pass through here + // public addEntries() { + // } + // + // public addManualChunks() { + // } + + private fetchAllDependencies(module: Module) { + const fetchDynamicImportsPromise = Promise.all( + module.getDynamicImportExpressions().map((dynamicImportExpression, index) => + this.graph.pluginDriver + .hookFirst('resolveDynamicImport', [dynamicImportExpression, module.id]) + .then(replacement => { + if (!replacement) return; + const dynamicImport = module.dynamicImports[index]; + dynamicImport.alias = getAliasName( + replacement, + typeof dynamicImportExpression === 'string' ? dynamicImportExpression : undefined + ); + if (typeof dynamicImportExpression !== 'string') { + dynamicImport.resolution = replacement; + } else if (this.graph.isExternal(replacement, module.id, true)) { + let externalModule; + if (!this.modulesById.has(replacement)) { + externalModule = new ExternalModule({ + graph: this.graph, + id: replacement + }); + this.modulesById.set(replacement, module); + } else { + externalModule = this.modulesById.get(replacement); + } + dynamicImport.resolution = externalModule; + externalModule.exportsNamespace = true; + } else { + return this.fetchModule(replacement, module.id).then(depModule => { + dynamicImport.resolution = depModule; + }); + } + }) + ) + ); + fetchDynamicImportsPromise.catch(() => {}); + + return Promise.all( + module.sources.map(source => this.resolveAndFetchDependency(module, source)) + ).then(() => fetchDynamicImportsPromise); + } + + private fetchModule(id: string, importer: string): Promise { + const existingModule = this.modulesById.get(id); + if (existingModule) { + if (existingModule.isExternal) throw new Error(`Cannot fetch external module ${id}`); + return Promise.resolve(existingModule); + } + + const module: Module = new Module(this.graph, id); + this.modulesById.set(id, module); + + timeStart('load modules', 3); + return Promise.resolve(this.graph.pluginDriver.hookFirst('load', [id])) + .catch((err: Error) => { + timeEnd('load modules', 3); + let msg = `Could not load ${id}`; + if (importer) msg += ` (imported by ${importer})`; + + msg += `: ${err.message}`; + throw new Error(msg); + }) + .then(source => { + timeEnd('load modules', 3); + if (typeof source === 'string') return source; + if (source && typeof source === 'object' && typeof source.code === 'string') return source; + + error({ + code: 'BAD_LOADER', + message: `Error loading ${relativeId( + id + )}: plugin load hook should return a string, a { code, map } object, or nothing/null` + }); + }) + .then(source => { + const sourceDescription: SourceDescription = + typeof source === 'string' + ? { + ast: null, + code: source + } + : source; + + const cachedModule = this.graph.cachedModules.get(id); + if ( + cachedModule && + !cachedModule.customTransformCache && + cachedModule.originalCode === sourceDescription.code + ) { + // re-emit transform assets + if (cachedModule.transformAssets) { + for (const asset of cachedModule.transformAssets) + this.graph.pluginDriver.emitAsset(asset.name, asset.source); + } + return cachedModule; + } + + return transform(this.graph, sourceDescription, module); + }) + .then((source: ModuleJSON) => { + module.setSource(source); + + this.modulesById.set(id, module); + + return this.fetchAllDependencies(module).then(() => { + for (const name in module.exports) { + if (name !== 'default') { + module.exportsAll[name] = module.id; + } + } + module.exportAllSources.forEach(source => { + const id = module.resolvedIds[source].id; + const exportAllModule = this.modulesById.get(id); + if (exportAllModule.isExternal) return; + + for (const name in (exportAllModule).exportsAll) { + if (name in module.exportsAll) { + this.graph.warn({ + code: 'NAMESPACE_CONFLICT', + message: `Conflicting namespaces: ${relativeId( + module.id + )} re-exports '${name}' from both ${relativeId( + module.exportsAll[name] + )} and ${relativeId( + (exportAllModule).exportsAll[name] + )} (will be ignored)`, + name, + reexporter: module.id, + sources: [module.exportsAll[name], (exportAllModule).exportsAll[name]] + }); + } else { + module.exportsAll[name] = (exportAllModule).exportsAll[name]; + } + } + }); + return module; + }); + }); + } + + private loadEntryModule(entryName: string) { + return this.graph.pluginDriver + .hookFirst('resolveId', [entryName, undefined]) + .then(id => { + if (id === false) { + error({ + code: 'UNRESOLVED_ENTRY', + message: `Entry module cannot be external` + }); + } + + if (id == null) { + error({ + code: 'UNRESOLVED_ENTRY', + message: `Could not resolve entry (${entryName})` + }); + } + + return this.fetchModule(id, undefined); + }); + } + + private normalizeResolveIdResult( + resolveIdResult: ResolveIdResult, + module: Module, + source: string + ): ResolvedId { + let id = ''; + let external = false; + if (resolveIdResult) { + if (typeof resolveIdResult === 'object') { + id = resolveIdResult.id; + if (resolveIdResult.external) { + external = true; + } + } else { + id = resolveIdResult; + if (this.graph.isExternal(id, module.id, true)) { + external = true; + } + } + if (external) { + id = normalizeRelativeExternalId(module.id, id); + } + }else { + id = normalizeRelativeExternalId(module.id, source); + external = true; + if (resolveIdResult !== false && !this.graph.isExternal(id, module.id, true)) { + if (isRelative(source)) { + error({ + code: 'UNRESOLVED_IMPORT', + message: `Could not resolve '${source}' from ${relativeId(module.id)}` + }); + } + this.graph.warn({ + code: 'UNRESOLVED_IMPORT', + importer: relativeId(module.id), + message: `'${source}' is imported by ${relativeId( + module.id + )}, but could not be resolved – treating it as an external dependency`, + source, + url: 'https://rollupjs.org/guide/en#warning-treating-module-as-external-dependency' + }); + } + } + return { id, external }; + } + + private resolveAndFetchDependency(module: Module, source: string): Promise { + return Promise.resolve( + module.resolvedIds[source] || + Promise.resolve( + this.graph.isExternal(source, module.id, false) + ? { id: source, external: true } + : this.graph.pluginDriver.hookFirst('resolveId', [source, module.id]) + ).then(result => this.normalizeResolveIdResult(result, module, source)) + ).then(resolvedId => { + module.resolvedIds[source] = resolvedId; + if (resolvedId.external) { + if (!this.modulesById.has(resolvedId.id)) { + this.modulesById.set(resolvedId.id, new ExternalModule({ graph: this.graph, id: resolvedId.id })); + } + + const externalModule = this.modulesById.get(resolvedId.id); + if (externalModule instanceof ExternalModule === false) { + error({ + code: 'INVALID_EXTERNAL_ID', + message: `'${source}' is imported as an external by ${relativeId( + module.id + )}, but is already an existing non-external module id.` + }); + } + } else { + return this.fetchModule(resolvedId.id, module.id); + } + }); + } +} diff --git a/src/finalisers/system.ts b/src/finalisers/system.ts index 5502862cfc2..88294083e4a 100644 --- a/src/finalisers/system.ts +++ b/src/finalisers/system.ts @@ -57,8 +57,8 @@ function getExportsBlock( ); } -const getHoistedExportsBlock = (exports: ChunkExports, _: string, t: string, n: string): string => { - return getExportsBlock( +const getHoistedExportsBlock = (exports: ChunkExports, _: string, t: string, n: string): string => + getExportsBlock( exports .filter(expt => expt.hoisted || expt.uninitialized) .map(expt => ({ name: expt.exported, value: expt.uninitialized ? 'void 0' : expt.local })), @@ -66,7 +66,6 @@ const getHoistedExportsBlock = (exports: ChunkExports, _: string, t: string, n: t, n ); -}; const getMissingExportsBlock = (exports: ChunkExports, _: string, t: string, n: string): string => getExportsBlock( diff --git a/src/rollup/index.ts b/src/rollup/index.ts index c1faac31ca2..705369eee6a 100644 --- a/src/rollup/index.ts +++ b/src/rollup/index.ts @@ -156,10 +156,7 @@ export default function rollup(rawInputOptions: GenericConfigObject): Promise - graph.pluginDriver.hookParallel('buildEnd').then(() => { - return chunks; - }), + chunks => graph.pluginDriver.hookParallel('buildEnd').then(() => chunks), err => graph.pluginDriver.hookParallel('buildEnd', [err]).then(() => { throw err; @@ -326,9 +323,9 @@ export default function rollup(rawInputOptions: GenericConfigObject): Promise { - return writeOutputFile(graph, result, bundle[chunkId], outputOptions); - }) + Object.keys(bundle).map(chunkId => + writeOutputFile(graph, result, bundle[chunkId], outputOptions) + ) ) .then(() => graph.pluginDriver.hookParallel('writeBundle', [bundle])) .then(() => createOutput(bundle)); diff --git a/src/utils/collapseSourcemaps.ts b/src/utils/collapseSourcemaps.ts index 1a2c07bdf5a..ee7a3310ebe 100644 --- a/src/utils/collapseSourcemaps.ts +++ b/src/utils/collapseSourcemaps.ts @@ -184,9 +184,9 @@ export default function collapseSourcemaps( const directory = dirname(module.id) || '.'; const sourceRoot = originalSourcemap.sourceRoot || '.'; - const baseSources = sources.map((source, i) => { - return new Source(resolve(directory, sourceRoot, source), sourcesContent[i]); - }); + const baseSources = sources.map( + (source, i) => new Source(resolve(directory, sourceRoot, source), sourcesContent[i]) + ); source = new Link(originalSourcemap, baseSources); } diff --git a/src/utils/pluginDriver.ts b/src/utils/pluginDriver.ts index 2c32d9403d5..cb4671f9f13 100644 --- a/src/utils/pluginDriver.ts +++ b/src/utils/pluginDriver.ts @@ -268,9 +268,7 @@ export function createPluginDriver( hookSeq(name, args, hookContext) { let promise: Promise = Promise.resolve(); for (let i = 0; i < plugins.length; i++) - promise = promise.then(() => { - return runHook(name, args, i, false, hookContext); - }); + promise = promise.then(() => runHook(name, args, i, false, hookContext)); return promise; }, @@ -342,9 +340,9 @@ export function createPluginDriver( promise = promise.then(value => { const hookPromise = runHook(name, args, i, true, hookContext); if (!hookPromise) return value; - return hookPromise.then((result: any) => { - return reduce.call(pluginContexts[i], value, result, plugins[i]); - }); + return hookPromise.then((result: any) => + reduce.call(pluginContexts[i], value, result, plugins[i]) + ); }); } return promise; diff --git a/src/watch/index.ts b/src/watch/index.ts index 8798b026603..efae4a7053e 100644 --- a/src/watch/index.ts +++ b/src/watch/index.ts @@ -229,11 +229,7 @@ export class Task { if (!watched.has(id)) deleteTask(id, this, this.chokidarOptionsHash); }); - return Promise.all( - this.outputs.map(output => { - return result.write(output); - }) - ).then(() => result); + return Promise.all(this.outputs.map(output => result.write(output))).then(() => result); }) .then((result: RollupBuild) => { this.watcher.emit('event', { diff --git a/test/function/samples/module-tree/_config.js b/test/function/samples/module-tree/_config.js index d55fe7bd2b8..add3840062e 100644 --- a/test/function/samples/module-tree/_config.js +++ b/test/function/samples/module-tree/_config.js @@ -4,12 +4,10 @@ const assert = require('assert'); module.exports = { description: 'bundle.modules includes dependencies (#903)', bundle(bundle) { - const modules = bundle.cache.modules.map(module => { - return { - id: path.relative(__dirname, module.id), - dependencies: module.dependencies.map(id => path.relative(__dirname, id)) - }; - }); + const modules = bundle.cache.modules.map(module => ({ + id: path.relative(__dirname, module.id), + dependencies: module.dependencies.map(id => path.relative(__dirname, id)) + })); assert.deepEqual(modules, [ { diff --git a/test/misc/write-bundle.js b/test/misc/write-bundle.js index 1ef523fe9cc..decb030012e 100644 --- a/test/misc/write-bundle.js +++ b/test/misc/write-bundle.js @@ -9,12 +9,8 @@ describe('bundle.write()', () => { input: 'x', plugins: [ { - resolveId: () => { - return 'test'; - }, - load: () => { - return '// empty'; - } + resolveId: () => 'test', + load: () => '// empty' } ] }) @@ -37,12 +33,8 @@ describe('bundle.write()', () => { input: 'x', plugins: [ { - resolveId: () => { - return 'test'; - }, - load: () => { - return 'export var foo = 42;'; - } + resolveId: () => 'test', + load: () => 'export var foo = 42;' } ] }) From 6e46702817f25ab95efd162128c42794302a1e35 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Sun, 10 Mar 2019 11:36:48 +0100 Subject: [PATCH 11/60] Use sets for colouring hashes --- src/Graph.ts | 6 ++---- src/utils/chunkColouring.ts | 25 ++++++++++++++----------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/Graph.ts b/src/Graph.ts index 5d9c8dbf3f2..bf58c77052e 100644 --- a/src/Graph.ts +++ b/src/Graph.ts @@ -264,10 +264,8 @@ export default class Graph { assignChunkColouringHashes(entryModules, manualChunkModules); } - if (entryModuleAliases) { - for (let i = entryModules.length - 1; i >= 0; i--) { - entryModules[i].chunkAlias = entryModuleAliases[i]; - } + for (let i = entryModules.length - 1; i >= 0; i--) { + entryModules[i].chunkAlias = entryModuleAliases[i]; } // TODO: there is one special edge case unhandled here and that is that any module diff --git a/src/utils/chunkColouring.ts b/src/utils/chunkColouring.ts index 577c7da97da..73c07bd0e38 100644 --- a/src/utils/chunkColouring.ts +++ b/src/utils/chunkColouring.ts @@ -9,8 +9,8 @@ export function assignChunkColouringHashes( manualChunkModules: Record ) { let currentEntry: Module, currentEntryHash: Uint8Array; - let modulesVisitedForCurrentEntry: { [id: string]: boolean }; - const handledEntryPoints: { [id: string]: boolean } = {}; + let modulesVisitedForCurrentEntry: Set; + const handledEntryPoints: Set = new Set(); const dynamicImports: Module[] = []; const addCurrentEntryColourToModule = (module: Module) => { @@ -22,11 +22,14 @@ export function assignChunkColouringHashes( } for (const dependency of module.dependencies) { - if (dependency instanceof ExternalModule || dependency.id in modulesVisitedForCurrentEntry) { + if ( + dependency instanceof ExternalModule || + modulesVisitedForCurrentEntry.has(dependency.id) + ) { continue; } - modulesVisitedForCurrentEntry[dependency.id] = true; - if (!handledEntryPoints[dependency.id] && !dependency.chunkAlias) + modulesVisitedForCurrentEntry.add(dependency.id); + if (!handledEntryPoints.has(dependency.id) && !dependency.chunkAlias) addCurrentEntryColourToModule(dependency); } @@ -59,26 +62,26 @@ Try defining "${chunkName}" first in the manualChunks definitions of the Rollup }); } currentEntry.chunkAlias = chunkName; - modulesVisitedForCurrentEntry = { [currentEntry.id]: true }; + modulesVisitedForCurrentEntry = new Set(currentEntry.id); addCurrentEntryColourToModule(currentEntry); } } } for (currentEntry of entryModules) { - handledEntryPoints[currentEntry.id] = true; + handledEntryPoints.add(currentEntry.id); currentEntryHash = randomUint8Array(10); - modulesVisitedForCurrentEntry = { [currentEntry.id]: null }; + modulesVisitedForCurrentEntry = new Set(currentEntry.id); addCurrentEntryColourToModule(currentEntry); } for (currentEntry of dynamicImports) { - if (handledEntryPoints[currentEntry.id]) { + if (handledEntryPoints.has(currentEntry.id)) { continue; } - handledEntryPoints[currentEntry.id] = true; + handledEntryPoints.add(currentEntry.id); currentEntryHash = randomUint8Array(10); - modulesVisitedForCurrentEntry = { [currentEntry.id]: null }; + modulesVisitedForCurrentEntry = new Set(currentEntry.id); addCurrentEntryColourToModule(currentEntry); } } From 6f3f13923683ca6bf97d3e785a64a95ecd5ea640 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Sun, 10 Mar 2019 18:06:18 +0100 Subject: [PATCH 12/60] Simplify alias generation --- src/ModuleLoader.ts | 15 ++++++--------- src/utils/relativeId.ts | 14 +++++--------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/src/ModuleLoader.ts b/src/ModuleLoader.ts index a702fc24ddb..2a7b02857b0 100644 --- a/src/ModuleLoader.ts +++ b/src/ModuleLoader.ts @@ -26,14 +26,14 @@ export class ModuleLoader { entryModules: string | string[] | Record, manualChunks: Record | void ) { - // TODO Lukas the parsing of entry modules could happen outside - let removeAliasExtensions = false; + // TODO Lukas the aliasing of entry modules could happen outside + let deriveAliasFromId = false; let entryModuleIds: string[]; let entryModuleAliases: string[]; if (typeof entryModules === 'string') entryModules = [entryModules]; if (Array.isArray(entryModules)) { - removeAliasExtensions = true; + deriveAliasFromId = true; entryModuleAliases = entryModules.concat([]); entryModuleIds = entryModules; } else { @@ -57,9 +57,9 @@ export class ModuleLoader { // - First collect all entries return Promise.all(entryAndManualChunkIds.map(id => this.loadEntryModule(id))).then( entryAndChunkModules => { - if (removeAliasExtensions) { + if (deriveAliasFromId) { for (let i = 0; i < entryModuleAliases.length; i++) - entryModuleAliases[i] = getAliasName(entryAndChunkModules[i].id, entryModuleAliases[i]); + entryModuleAliases[i] = getAliasName(entryAndChunkModules[i].id); } const entryModules = entryAndChunkModules.slice(0, entryModuleIds.length); @@ -97,10 +97,7 @@ export class ModuleLoader { .then(replacement => { if (!replacement) return; const dynamicImport = module.dynamicImports[index]; - dynamicImport.alias = getAliasName( - replacement, - typeof dynamicImportExpression === 'string' ? dynamicImportExpression : undefined - ); + dynamicImport.alias = getAliasName(replacement); if (typeof dynamicImportExpression !== 'string') { dynamicImport.resolution = replacement; } else if (this.graph.isExternal(replacement, module.id, true)) { diff --git a/src/utils/relativeId.ts b/src/utils/relativeId.ts index 59012a1e206..56c0160d860 100644 --- a/src/utils/relativeId.ts +++ b/src/utils/relativeId.ts @@ -1,10 +1,8 @@ import { basename, extname, isAbsolute, relative } from './path'; -export function getAliasName(resolved: string, unresolved?: string) { - let alias = basename(unresolved || resolved); - const ext = extname(resolved); - if (alias.endsWith(ext)) alias = alias.substr(0, alias.length - ext.length); - return alias; +export function getAliasName(id: string) { + const base = basename(id); + return base.substr(0, base.length - extname(id).length); } export default function relativeId(id: string) { @@ -14,10 +12,8 @@ export default function relativeId(id: string) { export function isPlainName(name: string) { // not starting with "./", "/". "../" - if ( + return !( name[0] === '/' || (name[1] === '.' && (name[2] === '/' || (name[2] === '.' && name[3] === '/'))) - ) - return false; - return true; + ); } From fb789a6c07d708dbc9d626162ea93cf0e768578b Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Mon, 11 Mar 2019 07:51:41 +0100 Subject: [PATCH 13/60] Attach aliases to modules --- src/Graph.ts | 71 +++++++++++++++++++++++++++------------ src/ModuleLoader.ts | 81 +++++++++++++++++++-------------------------- 2 files changed, 83 insertions(+), 69 deletions(-) diff --git a/src/Graph.ts b/src/Graph.ts index bf58c77052e..21b5de8ce8e 100644 --- a/src/Graph.ts +++ b/src/Graph.ts @@ -43,6 +43,39 @@ function makeOnwarn() { }; } +// TODO Lukas extract type for entry module +function normalizeEntryModules( + entryModules: string | string[] | Record +): { alias: string | null; unresolvedId: string }[] { + if (typeof entryModules === 'string') { + return [{ alias: null, unresolvedId: entryModules }]; + } + if (Array.isArray(entryModules)) { + return entryModules.map(unresolvedId => ({ alias: null, unresolvedId })); + } + return Object.keys(entryModules).map(alias => ({ alias, unresolvedId: entryModules[alias] })); +} + +function detectDuplicateEntryPoints( + entryModulesWithAliases: { alias: string | null; module: Module }[] +) { + const foundEntryModules = new Set(); + for (let i = 0; i < entryModulesWithAliases.length; i++) { + const entryModule = entryModulesWithAliases[i].module; + if (foundEntryModules.has(entryModule)) { + error({ + code: 'DUPLICATE_ENTRY_POINTS', + message: `Duplicate entry points detected. The input entries ${ + entryModulesWithAliases[i].alias + } and ${ + entryModulesWithAliases.find(({ module }) => module === entryModule).alias + } both point to the same module, ${entryModule.id}` + }); + } + foundEntryModules.add(entryModule); + } +} + export default class Graph { acornOptions: acorn.Options; acornParser: typeof acorn.Parser; @@ -204,8 +237,8 @@ export default class Graph { const moduleLoader = new ModuleLoader(this, this.moduleById); return moduleLoader - .loadEntryModules(entryModules, manualChunks) - .then(({ entryModules, entryModuleAliases, manualChunkModules }) => { + .loadEntryModules(normalizeEntryModules(entryModules), manualChunks) + .then(({ entryModulesWithAliases, manualChunkModulesByAlias }) => { for (const module of Array.from(this.moduleById.values())) { if (module instanceof Module) { this.modules.push(module); @@ -220,22 +253,9 @@ export default class Graph { // determine the topological execution order for the bundle timeStart('analyse dependency graph', 2); - for (let i = 0; i < entryModules.length; i++) { - const entryModule = entryModules[i]; - const duplicateIndex = entryModules.indexOf(entryModule, i + 1); - if (duplicateIndex !== -1) { - error({ - code: 'DUPLICATE_ENTRY_POINTS', - message: `Duplicate entry points detected. The input entries ${ - entryModuleAliases[i] - } and ${entryModuleAliases[duplicateIndex]} both point to the same module, ${ - entryModule.id - }` - }); - } - } + detectDuplicateEntryPoints(entryModulesWithAliases); - this.link(entryModules); + this.link(entryModulesWithAliases.map(({ module }) => module)); timeEnd('analyse dependency graph', 2); @@ -243,12 +263,15 @@ export default class Graph { timeStart('mark included statements', 2); if (inlineDynamicImports) { - if (entryModules.length > 1) + if (entryModulesWithAliases.length > 1) { throw new Error( 'Internal Error: can only inline dynamic imports for single-file builds.' ); + } + } + for (const { module } of entryModulesWithAliases) { + module.includeAllExports(); } - for (const entryModule of entryModules) entryModule.includeAllExports(); this.includeMarked(this.modules); // check for unused external imports @@ -260,12 +283,16 @@ export default class Graph { // entry point graph colouring, before generating the import and export facades timeStart('generate chunks', 2); + // TODO Lukas can we move the alias assigment into the colouring? if (!this.preserveModules && !inlineDynamicImports) { - assignChunkColouringHashes(entryModules, manualChunkModules); + assignChunkColouringHashes( + entryModulesWithAliases.map(({ module }) => module), + manualChunkModulesByAlias + ); } - for (let i = entryModules.length - 1; i >= 0; i--) { - entryModules[i].chunkAlias = entryModuleAliases[i]; + for (let i = entryModulesWithAliases.length - 1; i >= 0; i--) { + entryModulesWithAliases[i].module.chunkAlias = entryModulesWithAliases[i].alias; } // TODO: there is one special edge case unhandled here and that is that any module diff --git a/src/ModuleLoader.ts b/src/ModuleLoader.ts index 2a7b02857b0..cd4267ce465 100644 --- a/src/ModuleLoader.ts +++ b/src/ModuleLoader.ts @@ -16,70 +16,57 @@ export class ModuleLoader { private readonly graph: Graph; private readonly modulesById: Map; - // TODO Lukas get rid of graph dependence + // TODO Lukas get rid of graph dependency constructor(graph: Graph, modulesById: Map) { this.graph = graph; this.modulesById = modulesById; } loadEntryModules( - entryModules: string | string[] | Record, + unresolvedEntryModules: { alias: string | null; unresolvedId: string }[], manualChunks: Record | void - ) { - // TODO Lukas the aliasing of entry modules could happen outside - let deriveAliasFromId = false; - let entryModuleIds: string[]; - let entryModuleAliases: string[]; - if (typeof entryModules === 'string') entryModules = [entryModules]; - - if (Array.isArray(entryModules)) { - deriveAliasFromId = true; - entryModuleAliases = entryModules.concat([]); - entryModuleIds = entryModules; - } else { - entryModuleAliases = Object.keys(entryModules); - entryModuleIds = entryModuleAliases.map(name => (>entryModules)[name]); - } - - const entryAndManualChunkIds = entryModuleIds.concat([]); + ): Promise<{ + entryModulesWithAliases: { alias: string; module: Module }[]; + manualChunkModulesByAlias: Record; + }> { + const unresolvedManualChunks: { alias: string; unresolvedId: string }[] = []; if (manualChunks) { - Object.keys(manualChunks).forEach(name => { - const manualChunkIds = manualChunks[name]; - manualChunkIds.forEach(id => { - if (entryAndManualChunkIds.indexOf(id) === -1) entryAndManualChunkIds.push(id); - }); - }); + for (const alias of Object.keys(manualChunks)) { + const manualChunkIds = manualChunks[alias]; + for (const unresolvedId of manualChunkIds) { + unresolvedManualChunks.push({ unresolvedId, alias }); + } + } } // TODO Lukas We want to return a Promise which we do not know completely yet // - We create a manual Promise // - The resolved Promise.all checks if new entries are added. If not, it resolves, otherwise it does another Promise.all // - First collect all entries - return Promise.all(entryAndManualChunkIds.map(id => this.loadEntryModule(id))).then( - entryAndChunkModules => { - if (deriveAliasFromId) { - for (let i = 0; i < entryModuleAliases.length; i++) - entryModuleAliases[i] = getAliasName(entryAndChunkModules[i].id); - } - - const entryModules = entryAndChunkModules.slice(0, entryModuleIds.length); + return Promise.all([ + Promise.all( + unresolvedEntryModules.map(({ unresolvedId }) => this.loadEntryModule(unresolvedId)) + ), + Promise.all( + unresolvedManualChunks.map(({ unresolvedId }) => this.loadEntryModule(unresolvedId)) + ) + ]).then(([entryModules, manualChunkModules]) => { + const entryModulesWithAliases = entryModules.map((module, entryIndex) => ({ + alias: unresolvedEntryModules[entryIndex].alias || getAliasName(module.id), + module + })); + const manualChunkModulesByAlias: Record = {}; - let manualChunkModules: { [chunkName: string]: Module[] }; - if (manualChunks) { - manualChunkModules = {}; - for (const chunkName of Object.keys(manualChunks)) { - const chunk = manualChunks[chunkName]; - console.log(entryAndChunkModules); - manualChunkModules[chunkName] = chunk.map( - entryId => entryAndChunkModules[entryAndManualChunkIds.indexOf(entryId)] - ); - } + for (let i = 0; i < manualChunkModules.length; i++) { + const { alias } = unresolvedManualChunks[i]; + if (!manualChunkModulesByAlias[alias]) { + manualChunkModulesByAlias[alias] = []; } - - // TODO Lukas at this point, the entry modules need to contain all entry points - return { entryModules, entryModuleAliases, manualChunkModules }; + manualChunkModulesByAlias[alias].push(manualChunkModules[i]); } - ); + + return { entryModulesWithAliases, manualChunkModulesByAlias }; + }); } // // TODO Lukas in an ideal world, all entries pass through here From 9d54f71a6ea3307d69cbd3090855910b0206600a Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Mon, 11 Mar 2019 08:18:39 +0100 Subject: [PATCH 14/60] Transform loading into a process that dynamically accepts new entry points and manual chunks --- src/Graph.ts | 5 ++- src/ModuleLoader.ts | 77 +++++++++++++++++++++++++-------------------- 2 files changed, 47 insertions(+), 35 deletions(-) diff --git a/src/Graph.ts b/src/Graph.ts index 21b5de8ce8e..bf5b5f87bb7 100644 --- a/src/Graph.ts +++ b/src/Graph.ts @@ -236,8 +236,11 @@ export default class Graph { timeStart('parse modules', 2); const moduleLoader = new ModuleLoader(this, this.moduleById); + if (manualChunks) { + moduleLoader.addManualChunks(manualChunks); + } return moduleLoader - .loadEntryModules(normalizeEntryModules(entryModules), manualChunks) + .addEntryModules(normalizeEntryModules(entryModules)) .then(({ entryModulesWithAliases, manualChunkModulesByAlias }) => { for (const module of Array.from(this.moduleById.values())) { if (module instanceof Module) { diff --git a/src/ModuleLoader.ts b/src/ModuleLoader.ts index cd4267ce465..0cfe13aae0c 100644 --- a/src/ModuleLoader.ts +++ b/src/ModuleLoader.ts @@ -8,12 +8,20 @@ import relativeId, { getAliasName } from './utils/relativeId'; import { timeEnd, timeStart } from './utils/timers'; import transform from './utils/transform'; +interface ModuleWithAlias { + alias: string; + module: Module; +} + function normalizeRelativeExternalId(importee: string, source: string) { return isRelative(source) ? resolve(importee, '..', source) : source; } export class ModuleLoader { + private currentLoadModulesPromise: Promise = Promise.resolve(); + private readonly entryModules: ModuleWithAlias[] = []; private readonly graph: Graph; + private readonly manualChunkModules: Record = {}; private readonly modulesById: Map; // TODO Lukas get rid of graph dependency @@ -22,13 +30,34 @@ export class ModuleLoader { this.modulesById = modulesById; } - loadEntryModules( - unresolvedEntryModules: { alias: string | null; unresolvedId: string }[], - manualChunks: Record | void + addEntryModules( + unresolvedEntryModules: { alias: string | null; unresolvedId: string }[] ): Promise<{ entryModulesWithAliases: { alias: string; module: Module }[]; manualChunkModulesByAlias: Record; }> { + const loadNewEntryModulesPromise = Promise.all( + unresolvedEntryModules.map(({ unresolvedId }) => this.loadEntryModule(unresolvedId)) + ).then(entryModules => + this.entryModules.push( + ...entryModules.map((module, entryIndex) => ({ + alias: unresolvedEntryModules[entryIndex].alias || getAliasName(module.id), + module + })) + ) + ); + + this.currentLoadModulesPromise = Promise.all([ + this.currentLoadModulesPromise, + loadNewEntryModulesPromise + ]); + return this.currentLoadModulesPromise.then(() => ({ + entryModulesWithAliases: this.entryModules, + manualChunkModulesByAlias: this.manualChunkModules + })); + } + + addManualChunks(manualChunks: Record | void): void { const unresolvedManualChunks: { alias: string; unresolvedId: string }[] = []; if (manualChunks) { for (const alias of Object.keys(manualChunks)) { @@ -38,43 +67,23 @@ export class ModuleLoader { } } } - - // TODO Lukas We want to return a Promise which we do not know completely yet - // - We create a manual Promise - // - The resolved Promise.all checks if new entries are added. If not, it resolves, otherwise it does another Promise.all - // - First collect all entries - return Promise.all([ - Promise.all( - unresolvedEntryModules.map(({ unresolvedId }) => this.loadEntryModule(unresolvedId)) - ), - Promise.all( - unresolvedManualChunks.map(({ unresolvedId }) => this.loadEntryModule(unresolvedId)) - ) - ]).then(([entryModules, manualChunkModules]) => { - const entryModulesWithAliases = entryModules.map((module, entryIndex) => ({ - alias: unresolvedEntryModules[entryIndex].alias || getAliasName(module.id), - module - })); - const manualChunkModulesByAlias: Record = {}; - + const loadNewManualChunkModulesModulesPromise = Promise.all( + unresolvedManualChunks.map(({ unresolvedId }) => this.loadEntryModule(unresolvedId)) + ).then(manualChunkModules => { for (let i = 0; i < manualChunkModules.length; i++) { const { alias } = unresolvedManualChunks[i]; - if (!manualChunkModulesByAlias[alias]) { - manualChunkModulesByAlias[alias] = []; + if (!this.manualChunkModules[alias]) { + this.manualChunkModules[alias] = []; } - manualChunkModulesByAlias[alias].push(manualChunkModules[i]); + this.manualChunkModules[alias].push(manualChunkModules[i]); } - - return { entryModulesWithAliases, manualChunkModulesByAlias }; }); - } - // // TODO Lukas in an ideal world, all entries pass through here - // public addEntries() { - // } - // - // public addManualChunks() { - // } + this.currentLoadModulesPromise = Promise.all([ + this.currentLoadModulesPromise, + loadNewManualChunkModulesModulesPromise + ]); + } private fetchAllDependencies(module: Module) { const fetchDynamicImportsPromise = Promise.all( From 4c0c660d1142fc2a762b03a404f35335bb53a3cf Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Thu, 14 Mar 2019 11:03:16 +0100 Subject: [PATCH 15/60] Pass alias objects through the module loader --- src/Graph.ts | 9 +++--- src/ModuleLoader.ts | 76 +++++++++++++++++++++++++-------------------- 2 files changed, 47 insertions(+), 38 deletions(-) diff --git a/src/Graph.ts b/src/Graph.ts index bf5b5f87bb7..906de1578fc 100644 --- a/src/Graph.ts +++ b/src/Graph.ts @@ -80,6 +80,7 @@ export default class Graph { acornOptions: acorn.Options; acornParser: typeof acorn.Parser; assetsById = new Map(); + cachedModules: Map; contextParse: (code: string, acornOptions?: acorn.Options) => ESTree.Program; curChunkIndex = 0; deoptimizationTracker: EntityPathTracker; @@ -99,10 +100,10 @@ export default class Graph { treeshakingOptions: TreeshakingOptions; watchFiles: Record = Object.create(null); - private cachedModules: Map; private cacheExpiry: number; private context: string; private externalModules: ExternalModule[] = []; + private moduleLoader: ModuleLoader; private modules: Module[] = []; private onwarn: WarningHandler; private pluginCache: Record; @@ -222,6 +223,7 @@ export default class Graph { : []) ); this.acornParser = acorn.Parser.extend(...acornPluginsToInject); + this.moduleLoader = new ModuleLoader(this, this.moduleById, this.pluginDriver); } build( @@ -234,12 +236,11 @@ export default class Graph { // of the entry module's dependencies timeStart('parse modules', 2); - const moduleLoader = new ModuleLoader(this, this.moduleById); if (manualChunks) { - moduleLoader.addManualChunks(manualChunks); + this.moduleLoader.addManualChunks(manualChunks); } - return moduleLoader + return this.moduleLoader .addEntryModules(normalizeEntryModules(entryModules)) .then(({ entryModulesWithAliases, manualChunkModulesByAlias }) => { for (const module of Array.from(this.moduleById.values())) { diff --git a/src/ModuleLoader.ts b/src/ModuleLoader.ts index 0cfe13aae0c..4c4cfb126f4 100644 --- a/src/ModuleLoader.ts +++ b/src/ModuleLoader.ts @@ -4,6 +4,7 @@ import Module from './Module'; import { ModuleJSON, ResolvedId, ResolveIdResult, SourceDescription } from './rollup/types'; import { error } from './utils/error'; import { isRelative, resolve } from './utils/path'; +import { PluginDriver } from './utils/pluginDriver'; import relativeId, { getAliasName } from './utils/relativeId'; import { timeEnd, timeStart } from './utils/timers'; import transform from './utils/transform'; @@ -13,6 +14,11 @@ interface ModuleWithAlias { module: Module; } +interface UnresolvedModuleWithAlias { + alias: string | null; + unresolvedId: string; +} + function normalizeRelativeExternalId(importee: string, source: string) { return isRelative(source) ? resolve(importee, '..', source) : source; } @@ -23,29 +29,28 @@ export class ModuleLoader { private readonly graph: Graph; private readonly manualChunkModules: Record = {}; private readonly modulesById: Map; + private readonly pluginDriver: PluginDriver; // TODO Lukas get rid of graph dependency - constructor(graph: Graph, modulesById: Map) { + constructor( + graph: Graph, + modulesById: Map, + pluginDriver: PluginDriver + ) { this.graph = graph; this.modulesById = modulesById; + this.pluginDriver = pluginDriver; } addEntryModules( - unresolvedEntryModules: { alias: string | null; unresolvedId: string }[] + unresolvedEntryModules: UnresolvedModuleWithAlias[] ): Promise<{ - entryModulesWithAliases: { alias: string; module: Module }[]; + entryModulesWithAliases: ModuleWithAlias[]; manualChunkModulesByAlias: Record; }> { const loadNewEntryModulesPromise = Promise.all( - unresolvedEntryModules.map(({ unresolvedId }) => this.loadEntryModule(unresolvedId)) - ).then(entryModules => - this.entryModules.push( - ...entryModules.map((module, entryIndex) => ({ - alias: unresolvedEntryModules[entryIndex].alias || getAliasName(module.id), - module - })) - ) - ); + unresolvedEntryModules.map(this.loadEntryModule) + ).then(entryModules => this.entryModules.push(...entryModules)); this.currentLoadModulesPromise = Promise.all([ this.currentLoadModulesPromise, @@ -57,25 +62,22 @@ export class ModuleLoader { })); } - addManualChunks(manualChunks: Record | void): void { - const unresolvedManualChunks: { alias: string; unresolvedId: string }[] = []; - if (manualChunks) { - for (const alias of Object.keys(manualChunks)) { - const manualChunkIds = manualChunks[alias]; - for (const unresolvedId of manualChunkIds) { - unresolvedManualChunks.push({ unresolvedId, alias }); - } + addManualChunks(manualChunks: Record): void { + const unresolvedManualChunks: UnresolvedModuleWithAlias[] = []; + for (const alias of Object.keys(manualChunks)) { + const manualChunkIds = manualChunks[alias]; + for (const unresolvedId of manualChunkIds) { + unresolvedManualChunks.push({ unresolvedId, alias }); } } const loadNewManualChunkModulesModulesPromise = Promise.all( - unresolvedManualChunks.map(({ unresolvedId }) => this.loadEntryModule(unresolvedId)) + unresolvedManualChunks.map(this.loadEntryModule) ).then(manualChunkModules => { - for (let i = 0; i < manualChunkModules.length; i++) { - const { alias } = unresolvedManualChunks[i]; + for (const { alias, module } of manualChunkModules) { if (!this.manualChunkModules[alias]) { this.manualChunkModules[alias] = []; } - this.manualChunkModules[alias].push(manualChunkModules[i]); + this.manualChunkModules[alias].push(module); } }); @@ -88,7 +90,7 @@ export class ModuleLoader { private fetchAllDependencies(module: Module) { const fetchDynamicImportsPromise = Promise.all( module.getDynamicImportExpressions().map((dynamicImportExpression, index) => - this.graph.pluginDriver + this.pluginDriver .hookFirst('resolveDynamicImport', [dynamicImportExpression, module.id]) .then(replacement => { if (!replacement) return; @@ -135,7 +137,7 @@ export class ModuleLoader { this.modulesById.set(id, module); timeStart('load modules', 3); - return Promise.resolve(this.graph.pluginDriver.hookFirst('load', [id])) + return Promise.resolve(this.pluginDriver.hookFirst('load', [id])) .catch((err: Error) => { timeEnd('load modules', 3); let msg = `Could not load ${id}`; @@ -174,7 +176,7 @@ export class ModuleLoader { // re-emit transform assets if (cachedModule.transformAssets) { for (const asset of cachedModule.transformAssets) - this.graph.pluginDriver.emitAsset(asset.name, asset.source); + this.pluginDriver.emitAsset(asset.name, asset.source); } return cachedModule; } @@ -222,9 +224,12 @@ export class ModuleLoader { }); } - private loadEntryModule(entryName: string) { - return this.graph.pluginDriver - .hookFirst('resolveId', [entryName, undefined]) + private loadEntryModule = ({ + alias, + unresolvedId + }: UnresolvedModuleWithAlias): Promise => { + return this.pluginDriver + .hookFirst('resolveId', [unresolvedId, undefined]) .then(id => { if (id === false) { error({ @@ -236,13 +241,16 @@ export class ModuleLoader { if (id == null) { error({ code: 'UNRESOLVED_ENTRY', - message: `Could not resolve entry (${entryName})` + message: `Could not resolve entry (${unresolvedId})` }); } - return this.fetchModule(id, undefined); + return this.fetchModule(id, undefined).then(module => ({ + alias: alias || getAliasName(module.id), + module + })); }); - } + }; private normalizeResolveIdResult( resolveIdResult: ResolveIdResult, @@ -296,7 +304,7 @@ export class ModuleLoader { Promise.resolve( this.graph.isExternal(source, module.id, false) ? { id: source, external: true } - : this.graph.pluginDriver.hookFirst('resolveId', [source, module.id]) + : this.pluginDriver.hookFirst('resolveId', [source, module.id]) ).then(result => this.normalizeResolveIdResult(result, module, source)) ).then(resolvedId => { module.resolvedIds[source] = resolvedId; From 34a2f43e729c6df5d022e115733e593a15c89caa Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Fri, 12 Apr 2019 08:29:01 +0200 Subject: [PATCH 16/60] Implement basic chunk emission --- src/Graph.ts | 13 ++- src/Module.ts | 5 +- src/ModuleLoader.ts | 98 ++++++++++++++----- src/ast/nodes/MetaProperty.ts | 34 ++++++- src/rollup/types.d.ts | 27 ++++- src/utils/assetHooks.ts | 44 +++------ src/utils/defaultPlugin.ts | 25 +---- src/utils/metaIds.ts | 16 +++ src/utils/pluginDriver.ts | 14 ++- src/utils/transform.ts | 7 +- .../samples/add-entry-worker/_config.js | 32 ++++++ .../_expected/amd/chunks/chunk.js | 10 ++ .../add-entry-worker/_expected/amd/main.js | 14 +++ .../add-entry-worker/_expected/amd/worker.js | 5 + .../_expected/cjs/chunks/chunk.js | 8 ++ .../add-entry-worker/_expected/cjs/main.js | 12 +++ .../add-entry-worker/_expected/cjs/worker.js | 3 + .../_expected/es/chunks/chunk.js | 6 ++ .../add-entry-worker/_expected/es/main.js | 10 ++ .../add-entry-worker/_expected/es/worker.js | 1 + .../_expected/system/chunks/chunk.js | 13 +++ .../add-entry-worker/_expected/system/main.js | 19 ++++ .../_expected/system/worker.js | 10 ++ .../samples/add-entry-worker/index-amd.html | 10 ++ .../samples/add-entry-worker/index-es.html | 10 ++ .../add-entry-worker/index-system.html | 11 +++ .../samples/add-entry-worker/main.js | 7 ++ .../samples/add-entry-worker/worker.js | 1 + .../samples/add-entry/_config.js | 36 +++++++ .../add-entry/_expected/amd/buildStart.js | 5 + .../_expected/amd/generated-chunk.js | 7 ++ .../samples/add-entry/_expected/amd/load.js | 5 + .../samples/add-entry/_expected/amd/main.js | 8 ++ .../add-entry/_expected/cjs/buildStart.js | 5 + .../_expected/cjs/generated-chunk.js | 5 + .../samples/add-entry/_expected/cjs/load.js | 5 + .../samples/add-entry/_expected/cjs/main.js | 8 ++ .../add-entry/_expected/es/buildStart.js | 3 + .../add-entry/_expected/es/generated-chunk.js | 3 + .../samples/add-entry/_expected/es/load.js | 3 + .../samples/add-entry/_expected/es/main.js | 6 ++ .../add-entry/_expected/system/buildStart.js | 14 +++ .../_expected/system/generated-chunk.js | 10 ++ .../add-entry/_expected/system/load.js | 14 +++ .../add-entry/_expected/system/main.js | 17 ++++ .../samples/add-entry/buildStart.js | 3 + test/chunking-form/samples/add-entry/dep.js | 1 + test/chunking-form/samples/add-entry/main.js | 4 + 48 files changed, 533 insertions(+), 94 deletions(-) create mode 100644 src/utils/metaIds.ts create mode 100644 test/chunking-form/samples/add-entry-worker/_config.js create mode 100644 test/chunking-form/samples/add-entry-worker/_expected/amd/chunks/chunk.js create mode 100644 test/chunking-form/samples/add-entry-worker/_expected/amd/main.js create mode 100644 test/chunking-form/samples/add-entry-worker/_expected/amd/worker.js create mode 100644 test/chunking-form/samples/add-entry-worker/_expected/cjs/chunks/chunk.js create mode 100644 test/chunking-form/samples/add-entry-worker/_expected/cjs/main.js create mode 100644 test/chunking-form/samples/add-entry-worker/_expected/cjs/worker.js create mode 100644 test/chunking-form/samples/add-entry-worker/_expected/es/chunks/chunk.js create mode 100644 test/chunking-form/samples/add-entry-worker/_expected/es/main.js create mode 100644 test/chunking-form/samples/add-entry-worker/_expected/es/worker.js create mode 100644 test/chunking-form/samples/add-entry-worker/_expected/system/chunks/chunk.js create mode 100644 test/chunking-form/samples/add-entry-worker/_expected/system/main.js create mode 100644 test/chunking-form/samples/add-entry-worker/_expected/system/worker.js create mode 100644 test/chunking-form/samples/add-entry-worker/index-amd.html create mode 100644 test/chunking-form/samples/add-entry-worker/index-es.html create mode 100644 test/chunking-form/samples/add-entry-worker/index-system.html create mode 100644 test/chunking-form/samples/add-entry-worker/main.js create mode 100644 test/chunking-form/samples/add-entry-worker/worker.js create mode 100644 test/chunking-form/samples/add-entry/_config.js create mode 100644 test/chunking-form/samples/add-entry/_expected/amd/buildStart.js create mode 100644 test/chunking-form/samples/add-entry/_expected/amd/generated-chunk.js create mode 100644 test/chunking-form/samples/add-entry/_expected/amd/load.js create mode 100644 test/chunking-form/samples/add-entry/_expected/amd/main.js create mode 100644 test/chunking-form/samples/add-entry/_expected/cjs/buildStart.js create mode 100644 test/chunking-form/samples/add-entry/_expected/cjs/generated-chunk.js create mode 100644 test/chunking-form/samples/add-entry/_expected/cjs/load.js create mode 100644 test/chunking-form/samples/add-entry/_expected/cjs/main.js create mode 100644 test/chunking-form/samples/add-entry/_expected/es/buildStart.js create mode 100644 test/chunking-form/samples/add-entry/_expected/es/generated-chunk.js create mode 100644 test/chunking-form/samples/add-entry/_expected/es/load.js create mode 100644 test/chunking-form/samples/add-entry/_expected/es/main.js create mode 100644 test/chunking-form/samples/add-entry/_expected/system/buildStart.js create mode 100644 test/chunking-form/samples/add-entry/_expected/system/generated-chunk.js create mode 100644 test/chunking-form/samples/add-entry/_expected/system/load.js create mode 100644 test/chunking-form/samples/add-entry/_expected/system/main.js create mode 100644 test/chunking-form/samples/add-entry/buildStart.js create mode 100644 test/chunking-form/samples/add-entry/dep.js create mode 100644 test/chunking-form/samples/add-entry/main.js diff --git a/src/Graph.ts b/src/Graph.ts index 906de1578fc..4bce746eef9 100644 --- a/src/Graph.ts +++ b/src/Graph.ts @@ -8,7 +8,7 @@ import { EntityPathTracker } from './ast/utils/EntityPathTracker'; import Chunk from './Chunk'; import ExternalModule from './ExternalModule'; import Module, { defaultAcornOptions } from './Module'; -import { ModuleLoader } from './ModuleLoader'; +import { ModuleLoader, UnresolvedModuleWithAlias } from './ModuleLoader'; import { Asset, InputOptions, @@ -43,17 +43,20 @@ function makeOnwarn() { }; } -// TODO Lukas extract type for entry module function normalizeEntryModules( entryModules: string | string[] | Record -): { alias: string | null; unresolvedId: string }[] { +): UnresolvedModuleWithAlias[] { if (typeof entryModules === 'string') { return [{ alias: null, unresolvedId: entryModules }]; } if (Array.isArray(entryModules)) { return entryModules.map(unresolvedId => ({ alias: null, unresolvedId })); } - return Object.keys(entryModules).map(alias => ({ alias, unresolvedId: entryModules[alias] })); + return Object.keys(entryModules).map(alias => ({ + alias, + metaId: null, + unresolvedId: entryModules[alias] + })); } function detectDuplicateEntryPoints( @@ -90,6 +93,7 @@ export default class Graph { isExternal: IsExternal; isPureExternalModule: (id: string) => boolean; moduleById = new Map(); + moduleLoader: ModuleLoader; needsTreeshakingPass: boolean = false; pluginDriver: PluginDriver; preserveModules: boolean; @@ -103,7 +107,6 @@ export default class Graph { private cacheExpiry: number; private context: string; private externalModules: ExternalModule[] = []; - private moduleLoader: ModuleLoader; private modules: Module[] = []; private onwarn: WarningHandler; private pluginCache: Record; diff --git a/src/Module.ts b/src/Module.ts index a122ad6b877..aad8299adcf 100644 --- a/src/Module.ts +++ b/src/Module.ts @@ -88,7 +88,8 @@ export interface AstContext { deoptimizationTracker: EntityPathTracker; error: (props: RollupError, pos: number) => void; fileName: string; - getAssetFileName: (assetId: string) => string; + getAssetFileName: (assetMetaId: string) => string; + getChunkFileName: (metaId: string) => string; getExports: () => string[]; getModuleExecIndex: () => number; getModuleName: () => string; @@ -521,7 +522,9 @@ export default class Module { deoptimizationTracker: this.graph.deoptimizationTracker, error: this.error.bind(this), fileName, // Needed for warnings + // TODO Lukas move asset handling to graph? getAssetFileName: this.graph.pluginDriver.getAssetFileName, + getChunkFileName: this.graph.moduleLoader.getChunkFileName.bind(this.graph.moduleLoader), getExports: this.getExports.bind(this), getModuleExecIndex: () => this.execIndex, getModuleName: this.basename.bind(this), diff --git a/src/ModuleLoader.ts b/src/ModuleLoader.ts index 4c4cfb126f4..83fbf158483 100644 --- a/src/ModuleLoader.ts +++ b/src/ModuleLoader.ts @@ -3,6 +3,7 @@ import Graph from './Graph'; import Module from './Module'; import { ModuleJSON, ResolvedId, ResolveIdResult, SourceDescription } from './rollup/types'; import { error } from './utils/error'; +import { addWithNewMetaId } from './utils/metaIds'; import { isRelative, resolve } from './utils/path'; import { PluginDriver } from './utils/pluginDriver'; import relativeId, { getAliasName } from './utils/relativeId'; @@ -14,7 +15,7 @@ interface ModuleWithAlias { module: Module; } -interface UnresolvedModuleWithAlias { +export interface UnresolvedModuleWithAlias { alias: string | null; unresolvedId: string; } @@ -23,10 +24,12 @@ function normalizeRelativeExternalId(importee: string, source: string) { return isRelative(source) ? resolve(importee, '..', source) : source; } +// TODO Lukas this.addEntry -> addEntryChunk export class ModuleLoader { - private currentLoadModulesPromise: Promise = Promise.resolve(); + private readonly entriesByMetaId = new Map(); private readonly entryModules: ModuleWithAlias[] = []; private readonly graph: Graph; + private latestLoadModulesPromise: Promise = Promise.resolve(); private readonly manualChunkModules: Record = {}; private readonly modulesById: Map; private readonly pluginDriver: PluginDriver; @@ -42,35 +45,49 @@ export class ModuleLoader { this.pluginDriver = pluginDriver; } + addEntryModuleAndGetMetaId(unresolvedEntryModule: UnresolvedModuleWithAlias): string { + const entryRecord: { module: Module | null } = { module: null }; + const metaId = addWithNewMetaId( + entryRecord, + this.entriesByMetaId, + unresolvedEntryModule.unresolvedId + ); + this.addEntryModules([unresolvedEntryModule]).then(({ newEntryModules: [{ module }] }) => { + entryRecord.module = module; + }); + return metaId; + } + + // TODO Lukas fail if finished addEntryModules( unresolvedEntryModules: UnresolvedModuleWithAlias[] ): Promise<{ entryModulesWithAliases: ModuleWithAlias[]; manualChunkModulesByAlias: Record; + newEntryModules: ModuleWithAlias[]; }> { const loadNewEntryModulesPromise = Promise.all( unresolvedEntryModules.map(this.loadEntryModule) - ).then(entryModules => this.entryModules.push(...entryModules)); - - this.currentLoadModulesPromise = Promise.all([ - this.currentLoadModulesPromise, - loadNewEntryModulesPromise - ]); - return this.currentLoadModulesPromise.then(() => ({ + ).then(entryModules => { + this.entryModules.push(...entryModules); + return entryModules; + }); + return this.awaitLoadModulesPromise(loadNewEntryModulesPromise).then(newEntryModules => ({ entryModulesWithAliases: this.entryModules, - manualChunkModulesByAlias: this.manualChunkModules + manualChunkModulesByAlias: this.manualChunkModules, + newEntryModules })); } - addManualChunks(manualChunks: Record): void { + addManualChunks(manualChunks: Record): Promise { const unresolvedManualChunks: UnresolvedModuleWithAlias[] = []; for (const alias of Object.keys(manualChunks)) { const manualChunkIds = manualChunks[alias]; for (const unresolvedId of manualChunkIds) { - unresolvedManualChunks.push({ unresolvedId, alias }); + unresolvedManualChunks.push({ alias, unresolvedId }); } } - const loadNewManualChunkModulesModulesPromise = Promise.all( + const loadNewManualChunkModulesPromise = Promise.all( unresolvedManualChunks.map(this.loadEntryModule) ).then(manualChunkModules => { for (const { alias, module } of manualChunkModules) { @@ -81,10 +98,42 @@ export class ModuleLoader { } }); - this.currentLoadModulesPromise = Promise.all([ - this.currentLoadModulesPromise, - loadNewManualChunkModulesModulesPromise + return this.awaitLoadModulesPromise(loadNewManualChunkModulesPromise); + } + + getChunkFileName(metaId: string): string { + const entryRecord = this.entriesByMetaId.get(metaId); + if (!entryRecord) + error({ + code: 'CHUNK_NOT_FOUND', + message: `Plugin error - Unable to get chunk filename for unknown chunk ${metaId}.` + }); + // TODO Lukas check correct file name + if (entryRecord.module === null) + error({ + code: 'XXX', + message: `Plugin error - Unable to get chunk file name for chunk ${metaId}. Ensure that generate is called first.` + }); + // TODO Lukas facadeChunk? + return entryRecord.module.chunk.id; + } + + private awaitLoadModulesPromise(loadNewModulesPromise: Promise): Promise { + this.latestLoadModulesPromise = Promise.all([ + loadNewModulesPromise, + this.latestLoadModulesPromise ]); + + const getCombinedPromise = (): Promise => { + const startingPromise = this.latestLoadModulesPromise; + return startingPromise.then(() => { + if (this.latestLoadModulesPromise !== startingPromise) { + return getCombinedPromise(); + } + }); + }; + + return getCombinedPromise().then(() => loadNewModulesPromise); } private fetchAllDependencies(module: Module) { @@ -274,7 +323,7 @@ export class ModuleLoader { if (external) { id = normalizeRelativeExternalId(module.id, id); } - }else { + } else { id = normalizeRelativeExternalId(module.id, source); external = true; if (resolveIdResult !== false && !this.graph.isExternal(id, module.id, true)) { @@ -301,16 +350,19 @@ export class ModuleLoader { private resolveAndFetchDependency(module: Module, source: string): Promise { return Promise.resolve( module.resolvedIds[source] || - Promise.resolve( - this.graph.isExternal(source, module.id, false) - ? { id: source, external: true } - : this.pluginDriver.hookFirst('resolveId', [source, module.id]) - ).then(result => this.normalizeResolveIdResult(result, module, source)) + Promise.resolve( + this.graph.isExternal(source, module.id, false) + ? { id: source, external: true } + : this.pluginDriver.hookFirst('resolveId', [source, module.id]) + ).then(result => this.normalizeResolveIdResult(result, module, source)) ).then(resolvedId => { module.resolvedIds[source] = resolvedId; if (resolvedId.external) { if (!this.modulesById.has(resolvedId.id)) { - this.modulesById.set(resolvedId.id, new ExternalModule({ graph: this.graph, id: resolvedId.id })); + this.modulesById.set( + resolvedId.id, + new ExternalModule({ graph: this.graph, id: resolvedId.id }) + ); } const externalModule = this.modulesById.get(resolvedId.id); diff --git a/src/ast/nodes/MetaProperty.ts b/src/ast/nodes/MetaProperty.ts index 4bbbc30eace..0f804009056 100644 --- a/src/ast/nodes/MetaProperty.ts +++ b/src/ast/nodes/MetaProperty.ts @@ -6,6 +6,9 @@ import MemberExpression from './MemberExpression'; import * as NodeType from './NodeType'; import { NodeBase } from './shared/Node'; +const ASSET_PREFIX = 'ROLLUP_ASSET_URL_'; +const CHUNK_PREFIX = 'ROLLUP_CHUNK_URL_'; + export default class MetaProperty extends NodeBase { meta: Identifier; property: Identifier; @@ -31,9 +34,11 @@ export default class MetaProperty extends NodeBase { ? parent.propertyKey : null; - // support import.meta.ROLLUP_ASSET_URL_[ID] - if (importMetaProperty && importMetaProperty.startsWith('ROLLUP_ASSET_URL_')) { - const assetFileName = this.context.getAssetFileName(importMetaProperty.substr(17)); + // TODO Lukas extract, use same hook + if (importMetaProperty && importMetaProperty.startsWith(ASSET_PREFIX)) { + const assetFileName = this.context.getAssetFileName( + importMetaProperty.substr(ASSET_PREFIX.length) + ); const relativeAssetPath = normalize(relative(dirname(chunkId), assetFileName)); const replacement = pluginDriver.hookFirstSync('resolveAssetUrl', [ { @@ -53,6 +58,29 @@ export default class MetaProperty extends NodeBase { return true; } + if (importMetaProperty && importMetaProperty.startsWith(CHUNK_PREFIX)) { + const chunkFileName = this.context.getChunkFileName( + importMetaProperty.substr(CHUNK_PREFIX.length) + ); + const relativeChunkPath = normalize(relative(dirname(chunkId), chunkFileName)); + const replacement = pluginDriver.hookFirstSync('resolveChunkUrl', [ + { + chunkFileName, + chunkId, + format, + moduleId: this.context.module.id, + relativeChunkPath + } + ]); + + code.overwrite( + (parent as MemberExpression).start, + (parent as MemberExpression).end, + replacement + ); + return true; + } + const replacement = pluginDriver.hookFirstSync('resolveImportMeta', [ importMetaProperty, { diff --git a/src/rollup/types.d.ts b/src/rollup/types.d.ts index 86b5fffe558..fce539a6153 100644 --- a/src/rollup/types.d.ts +++ b/src/rollup/types.d.ts @@ -103,10 +103,17 @@ export interface MinimalPluginContext { meta: PluginContextMeta; } +export type EmitAsset = (name: string, source?: string | Buffer) => string; +export type AddEntry = (name: string) => string; + export interface PluginContext extends MinimalPluginContext { + addEntry: AddEntry; addWatchFile: (id: string) => void; cache: PluginCache; - getAssetFileName: (assetId: string) => string; + emitAsset: EmitAsset; + error: (err: RollupError | string, pos?: { column: number; line: number }) => void; + getAssetFileName: (assetMetaId: string) => string; + getChunkFileName: (chunkMetaId: string) => string; getModuleInfo: ( moduleId: string ) => { @@ -118,12 +125,10 @@ export interface PluginContext extends MinimalPluginContext { moduleIds: IterableIterator; parse: (input: string, options: any) => ESTree.Program; resolveId: ResolveIdHook; - setAssetSource: (assetId: string, source: string | Buffer) => void; + setAssetSource: (assetMetaId: string, source: string | Buffer) => void; + warn: (warning: RollupWarning | string, pos?: { column: number; line: number }) => void; /** @deprecated */ watcher: EventEmitter; - emitAsset(name: string, source?: string | Buffer): string; - error(err: RollupError | string, pos?: { column: number; line: number }): void; - warn(warning: RollupWarning | string, pos?: { column: number; line: number }): void; } export interface PluginContextMeta { @@ -208,6 +213,17 @@ export type ResolveAssetUrlHook = ( } ) => string | void; +export type ResolveChunkUrlHook = ( + this: PluginContext, + options: { + chunkFileName: string; + chunkId: string; + format: string; + moduleId: string; + relativeChunkPath: string; + } +) => string | void; + export type AddonHook = string | ((this: PluginContext) => string | Promise); /** @@ -260,6 +276,7 @@ export interface Plugin { renderError?: (this: PluginContext, err?: Error) => Promise | void; renderStart?: (this: PluginContext) => Promise | void; resolveAssetUrl?: ResolveAssetUrlHook; + resolveChunkUrl?: ResolveChunkUrlHook; resolveDynamicImport?: ResolveDynamicImportHook; resolveId?: ResolveIdHook; resolveImportMeta?: ResolveImportMetaHook; diff --git a/src/utils/assetHooks.ts b/src/utils/assetHooks.ts index 619757f426a..89cc912c8d6 100644 --- a/src/utils/assetHooks.ts +++ b/src/utils/assetHooks.ts @@ -1,12 +1,11 @@ import sha256 from 'hash.js/lib/hash/sha/256'; -import { Asset, OutputBundle } from '../rollup/types'; +import { Asset, EmitAsset, OutputBundle } from '../rollup/types'; import { error } from './error'; +import { addWithNewMetaId } from './metaIds'; import { extname } from './path'; import { isPlainName } from './relativeId'; import { makeUnique, renderNamePattern } from './renderNamePattern'; -export type EmitAsset = (name: string, source?: string | Buffer) => string; - export function getAssetFileName( asset: Asset, existingNames: Record, @@ -42,7 +41,7 @@ export function getAssetFileName( } export function createAssetPluginHooks( - assetsById: Map, + assetsByMetaId: Map, outputBundle?: OutputBundle, assetFileNames?: string ) { @@ -53,30 +52,16 @@ export function createAssetPluginHooks( code: 'INVALID_ASSET_NAME', message: `Plugin error creating asset, name is not a plain (non relative or absolute URL) string name.` }); - - let assetId: string; - do { - const assetHash = sha256(); - if (assetId) { - // if there is a collision, chain until there isn't - assetHash.update(assetId); - } else { - assetHash.update(name); - } - assetId = assetHash.digest('hex').substr(0, 8); - } while (assetsById.has(assetId)); - const asset: Asset = { name, source, fileName: undefined }; if (outputBundle && source !== undefined) finaliseAsset(asset, outputBundle, assetFileNames); - assetsById.set(assetId, asset); - return assetId; + return addWithNewMetaId(asset, assetsByMetaId, name); }, - setAssetSource(assetId: string, source?: string | Buffer) { - const asset = assetsById.get(assetId); + setAssetSource(assetMetaId: string, source?: string | Buffer) { + const asset = assetsByMetaId.get(assetMetaId); if (!asset) error({ code: 'ASSET_NOT_FOUND', - message: `Plugin error - Unable to set asset source for unknown asset ${assetId}.` + message: `Plugin error - Unable to set asset source for unknown asset ${assetMetaId}.` }); if (asset.source !== undefined) error({ @@ -93,17 +78,18 @@ export function createAssetPluginHooks( asset.source = source; if (outputBundle) finaliseAsset(asset, outputBundle, assetFileNames); }, - getAssetFileName(assetId: string) { - const asset = assetsById.get(assetId); + // TODO Lukas we also need this for chunks. Can this be shared? + getAssetFileName(assetMetaId: string) { + const asset = assetsByMetaId.get(assetMetaId); if (!asset) error({ code: 'ASSET_NOT_FOUND', - message: `Plugin error - Unable to get asset filename for unknown asset ${assetId}.` + message: `Plugin error - Unable to get asset filename for unknown asset ${assetMetaId}.` }); if (asset.fileName === undefined) error({ code: 'ASSET_NOT_FINALISED', - message: `Plugin error - Unable to get asset file name for asset ${assetId}. Ensure that the source is set and that generate is called first.` + message: `Plugin error - Unable to get asset file name for asset ${assetMetaId}. Ensure that the source is set and that generate is called first.` }); return asset.fileName; } @@ -125,15 +111,15 @@ export function createTransformEmitAsset(assetsById: Map, emitAss return { assets, emitAsset: (name: string, source?: string | Buffer) => { - const assetId = emitAsset(name, source); - const asset = assetsById.get(assetId); + const assetMetaId = emitAsset(name, source); + const asset = assetsById.get(assetMetaId); // distinguish transform assets assets.push({ fileName: undefined, name: asset.name, source: asset.source }); - return assetId; + return assetMetaId; } }; } diff --git a/src/utils/defaultPlugin.ts b/src/utils/defaultPlugin.ts index 39887a0ac93..2b86d05c3cb 100644 --- a/src/utils/defaultPlugin.ts +++ b/src/utils/defaultPlugin.ts @@ -17,6 +17,9 @@ export function getRollupDefaultPlugin(options: InputOptions): Plugin { resolveAssetUrl({ relativeAssetPath, format }) { return relativeUrlMechanisms[format](relativeAssetPath); }, + resolveChunkUrl({ relativeChunkPath, format }) { + return relativeUrlMechanisms[format](relativeChunkPath); + }, resolveImportMeta(prop, { chunkId, format }) { const mechanism = importMetaMechanisms[format] && importMetaMechanisms[format](prop, chunkId); if (mechanism) { @@ -131,25 +134,3 @@ const relativeUrlMechanisms: Record string> = `(require('u' + 'rl').URL)` )} : ${getRelativeUrlFromDocument(relativePath)})` }; - -const getRelativeUrlFromDocument = (relativePath: string) => - getResolveUrl( - `(document.currentScript && document.currentScript.src || document.baseURI) + '/../${relativePath}'` - ); - -const relativeUrlMechanisms: Record string> = { - amd: relativePath => getResolveUrl(`module.uri + '/../${relativePath}', document.baseURI`), - cjs: relativePath => - `(typeof document === 'undefined' ? ${getResolveUrl( - `'file:' + __dirname + '/${relativePath}'`, - `(require('u' + 'rl').URL)` - )} : ${getRelativeUrlFromDocument(relativePath)})`, - es: relativePath => getResolveUrl(`'${relativePath}', import.meta.url`), - iife: relativePath => getRelativeUrlFromDocument(relativePath), - system: relativePath => getResolveUrl(`'${relativePath}', module.meta.url`), - umd: relativePath => - `(typeof document === 'undefined' ? ${getResolveUrl( - `'file:' + __dirname + '/${relativePath}'`, - `(require('u' + 'rl').URL)` - )} : ${getRelativeUrlFromDocument(relativePath)})` -}; diff --git a/src/utils/metaIds.ts b/src/utils/metaIds.ts new file mode 100644 index 00000000000..ff6e0164f9a --- /dev/null +++ b/src/utils/metaIds.ts @@ -0,0 +1,16 @@ +import sha256 from 'hash.js/lib/hash/sha/256'; + +export function addWithNewMetaId(item: T, idMap: Map, hashBase: string): string { + let metaId: string; + do { + const hash = sha256(); + if (metaId) { + hash.update(metaId); + } else { + hash.update(hashBase); + } + metaId = hash.digest('hex').substr(0, 8); + } while (idMap.has(metaId)); + idMap.set(metaId, item); + return metaId; +} diff --git a/src/utils/pluginDriver.ts b/src/utils/pluginDriver.ts index cb4671f9f13..57ade528131 100644 --- a/src/utils/pluginDriver.ts +++ b/src/utils/pluginDriver.ts @@ -3,6 +3,7 @@ import { version as rollupVersion } from 'package.json'; import Graph from '../Graph'; import Module from '../Module'; import { + EmitAsset, InputOptions, Plugin, PluginCache, @@ -12,7 +13,7 @@ import { RollupWatcher, SerializablePluginCache } from '../rollup/types'; -import { createAssetPluginHooks, EmitAsset } from './assetHooks'; +import { createAssetPluginHooks } from './assetHooks'; import { getRollupDefaultPlugin } from './defaultPlugin'; import { error } from './error'; import { NameCollection } from './reservedNames'; @@ -20,7 +21,7 @@ import { NameCollection } from './reservedNames'; export interface PluginDriver { emitAsset: EmitAsset; hasLoadersOrTransforms: boolean; - getAssetFileName(assetId: string): string; + getAssetFileName(assetMetaId: string): string; hookFirst(hook: string, args?: any[], hookContext?: HookContext): Promise; hookFirstSync(hook: string, args?: any[], hookContext?: HookContext): T; hookParallel(hook: string, args?: any[], hookContext?: HookContext): Promise; @@ -111,7 +112,11 @@ export function createPluginDriver( } const context: PluginContext = { + addEntry(id: string) { + return graph.moduleLoader.addEntryModuleAndGetMetaId({ alias: null, unresolvedId: id }); + }, addWatchFile(id: string) { + // TODO Lukas is this tested? if (graph.finished) this.error('addWatchFile can only be called during the build.'); graph.watchFiles[id] = true; }, @@ -128,7 +133,10 @@ export function createPluginDriver( return graph.isExternal(id, parentId, isResolved); }, getAssetFileName, - getModuleInfo: (moduleId: string) => { + getChunkFileName(chunkMetaId: string): string { + return graph.moduleLoader.getChunkFileName(chunkMetaId); + }, + getModuleInfo(moduleId: string) { const foundModule = graph.moduleById.get(moduleId); if (foundModule == null) { throw new Error(`Unable to find module ${moduleId}`); diff --git a/src/utils/transform.ts b/src/utils/transform.ts index b388d3e5f4b..782b622b657 100644 --- a/src/utils/transform.ts +++ b/src/utils/transform.ts @@ -5,6 +5,7 @@ import Graph from '../Graph'; import Module from '../Module'; import { Asset, + EmitAsset, Plugin, PluginCache, PluginContext, @@ -13,7 +14,7 @@ import { RollupWarning, TransformSourceDescription } from '../rollup/types'; -import { createTransformEmitAsset, EmitAsset } from './assetHooks'; +import { createTransformEmitAsset } from './assetHooks'; import { augmentCodeLocation, error } from './error'; import { dirname, resolve } from './path'; import { trackPluginCache } from './pluginDriver'; @@ -132,8 +133,8 @@ export default function transform( transformDependencies.push(id); pluginContext.addWatchFile(id); }, - setAssetSource(assetId, source) { - pluginContext.setAssetSource(assetId, source); + setAssetSource(assetMetaId, source) { + pluginContext.setAssetSource(assetMetaId, source); if (!customTransformCache && !setAssetSourceErr) { try { this.error({ diff --git a/test/chunking-form/samples/add-entry-worker/_config.js b/test/chunking-form/samples/add-entry-worker/_config.js new file mode 100644 index 00000000000..346acf4cbdf --- /dev/null +++ b/test/chunking-form/samples/add-entry-worker/_config.js @@ -0,0 +1,32 @@ +let metaId; + +module.exports = { + description: 'allows adding additional entry points', + options: { + input: 'main', + output: { + chunkFileNames: 'chunks/[name].js' + }, + plugins: { + load(id) { + if (id === 'merged' || id === 'nested') { + if (!metaId) { + // TODO Lukas is there a way to prevent reemitting the same entry point? What about already existing ones? + metaId = this.addEntry('worker'); + } + return ` +export const getWorkerMessage = () => new Promise(resolve => { + const worker = new Worker(import.meta.ROLLUP_CHUNK_URL_${metaId}); + worker.onmessage = resolve; +});`; + } + }, + resolveId(id) { + if (id === 'merged' || id === 'nested') { + return id; + } + return null; + } + } + } +}; diff --git a/test/chunking-form/samples/add-entry-worker/_expected/amd/chunks/chunk.js b/test/chunking-form/samples/add-entry-worker/_expected/amd/chunks/chunk.js new file mode 100644 index 00000000000..e372a64fc7f --- /dev/null +++ b/test/chunking-form/samples/add-entry-worker/_expected/amd/chunks/chunk.js @@ -0,0 +1,10 @@ +define(['module', 'exports'], function (module, exports) { 'use strict'; + + const getWorkerMessage = () => new Promise(resolve => { + const worker = new Worker(new URL(module.uri + '/../../worker.js', document.baseURI).href); + worker.onmessage = resolve; + }); + + exports.getWorkerMessage = getWorkerMessage; + +}); diff --git a/test/chunking-form/samples/add-entry-worker/_expected/amd/main.js b/test/chunking-form/samples/add-entry-worker/_expected/amd/main.js new file mode 100644 index 00000000000..8b65a262c12 --- /dev/null +++ b/test/chunking-form/samples/add-entry-worker/_expected/amd/main.js @@ -0,0 +1,14 @@ +define(['module', 'require'], function (module, require) { 'use strict'; + + const getWorkerMessage = () => new Promise(resolve => { + const worker = new Worker(new URL(module.uri + '/../worker.js', document.baseURI).href); + worker.onmessage = resolve; + }); + + getWorkerMessage().then(message => document.write(`

1: ${message.data}

`)); + + new Promise(function (resolve, reject) { require(['./chunks/chunk.js'], resolve, reject) }) + .then(result => result.getWorkerMessage()) + .then(message => document.write(`

2: ${message.data}

`)); + +}); diff --git a/test/chunking-form/samples/add-entry-worker/_expected/amd/worker.js b/test/chunking-form/samples/add-entry-worker/_expected/amd/worker.js new file mode 100644 index 00000000000..77279bd859f --- /dev/null +++ b/test/chunking-form/samples/add-entry-worker/_expected/amd/worker.js @@ -0,0 +1,5 @@ +define(function () { 'use strict'; + + postMessage('from worker'); + +}); diff --git a/test/chunking-form/samples/add-entry-worker/_expected/cjs/chunks/chunk.js b/test/chunking-form/samples/add-entry-worker/_expected/cjs/chunks/chunk.js new file mode 100644 index 00000000000..261509b57c7 --- /dev/null +++ b/test/chunking-form/samples/add-entry-worker/_expected/cjs/chunks/chunk.js @@ -0,0 +1,8 @@ +'use strict'; + +const getWorkerMessage = () => new Promise(resolve => { + const worker = new Worker((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/../worker.js').href : new URL((document.currentScript && document.currentScript.src || document.baseURI) + '/../../worker.js').href)); + worker.onmessage = resolve; +}); + +exports.getWorkerMessage = getWorkerMessage; diff --git a/test/chunking-form/samples/add-entry-worker/_expected/cjs/main.js b/test/chunking-form/samples/add-entry-worker/_expected/cjs/main.js new file mode 100644 index 00000000000..6c6dcd1dadd --- /dev/null +++ b/test/chunking-form/samples/add-entry-worker/_expected/cjs/main.js @@ -0,0 +1,12 @@ +'use strict'; + +const getWorkerMessage = () => new Promise(resolve => { + const worker = new Worker((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/worker.js').href : new URL((document.currentScript && document.currentScript.src || document.baseURI) + '/../worker.js').href)); + worker.onmessage = resolve; +}); + +getWorkerMessage().then(message => document.write(`

1: ${message.data}

`)); + +Promise.resolve(require('./chunks/chunk.js')) + .then(result => result.getWorkerMessage()) + .then(message => document.write(`

2: ${message.data}

`)); diff --git a/test/chunking-form/samples/add-entry-worker/_expected/cjs/worker.js b/test/chunking-form/samples/add-entry-worker/_expected/cjs/worker.js new file mode 100644 index 00000000000..2154e7b7a97 --- /dev/null +++ b/test/chunking-form/samples/add-entry-worker/_expected/cjs/worker.js @@ -0,0 +1,3 @@ +'use strict'; + +postMessage('from worker'); diff --git a/test/chunking-form/samples/add-entry-worker/_expected/es/chunks/chunk.js b/test/chunking-form/samples/add-entry-worker/_expected/es/chunks/chunk.js new file mode 100644 index 00000000000..66b32e656c4 --- /dev/null +++ b/test/chunking-form/samples/add-entry-worker/_expected/es/chunks/chunk.js @@ -0,0 +1,6 @@ +const getWorkerMessage = () => new Promise(resolve => { + const worker = new Worker(new URL('../worker.js', import.meta.url).href); + worker.onmessage = resolve; +}); + +export { getWorkerMessage }; diff --git a/test/chunking-form/samples/add-entry-worker/_expected/es/main.js b/test/chunking-form/samples/add-entry-worker/_expected/es/main.js new file mode 100644 index 00000000000..2e201e79a32 --- /dev/null +++ b/test/chunking-form/samples/add-entry-worker/_expected/es/main.js @@ -0,0 +1,10 @@ +const getWorkerMessage = () => new Promise(resolve => { + const worker = new Worker(new URL('worker.js', import.meta.url).href); + worker.onmessage = resolve; +}); + +getWorkerMessage().then(message => document.write(`

1: ${message.data}

`)); + +import('./chunks/chunk.js') + .then(result => result.getWorkerMessage()) + .then(message => document.write(`

2: ${message.data}

`)); diff --git a/test/chunking-form/samples/add-entry-worker/_expected/es/worker.js b/test/chunking-form/samples/add-entry-worker/_expected/es/worker.js new file mode 100644 index 00000000000..89a9039df0d --- /dev/null +++ b/test/chunking-form/samples/add-entry-worker/_expected/es/worker.js @@ -0,0 +1 @@ +postMessage('from worker'); diff --git a/test/chunking-form/samples/add-entry-worker/_expected/system/chunks/chunk.js b/test/chunking-form/samples/add-entry-worker/_expected/system/chunks/chunk.js new file mode 100644 index 00000000000..d638eb2b7e1 --- /dev/null +++ b/test/chunking-form/samples/add-entry-worker/_expected/system/chunks/chunk.js @@ -0,0 +1,13 @@ +System.register([], function (exports, module) { + 'use strict'; + return { + execute: function () { + + const getWorkerMessage = exports('getWorkerMessage', () => new Promise(resolve => { + const worker = new Worker(new URL('../worker.js', module.meta.url).href); + worker.onmessage = resolve; + })); + + } + }; +}); diff --git a/test/chunking-form/samples/add-entry-worker/_expected/system/main.js b/test/chunking-form/samples/add-entry-worker/_expected/system/main.js new file mode 100644 index 00000000000..0f2664053e8 --- /dev/null +++ b/test/chunking-form/samples/add-entry-worker/_expected/system/main.js @@ -0,0 +1,19 @@ +System.register([], function (exports, module) { + 'use strict'; + return { + execute: function () { + + const getWorkerMessage = () => new Promise(resolve => { + const worker = new Worker(new URL('worker.js', module.meta.url).href); + worker.onmessage = resolve; + }); + + getWorkerMessage().then(message => document.write(`

1: ${message.data}

`)); + + module.import('./chunks/chunk.js') + .then(result => result.getWorkerMessage()) + .then(message => document.write(`

2: ${message.data}

`)); + + } + }; +}); diff --git a/test/chunking-form/samples/add-entry-worker/_expected/system/worker.js b/test/chunking-form/samples/add-entry-worker/_expected/system/worker.js new file mode 100644 index 00000000000..6523f179726 --- /dev/null +++ b/test/chunking-form/samples/add-entry-worker/_expected/system/worker.js @@ -0,0 +1,10 @@ +System.register([], function (exports, module) { + 'use strict'; + return { + execute: function () { + + postMessage('from worker'); + + } + }; +}); diff --git a/test/chunking-form/samples/add-entry-worker/index-amd.html b/test/chunking-form/samples/add-entry-worker/index-amd.html new file mode 100644 index 00000000000..476b9ce3df1 --- /dev/null +++ b/test/chunking-form/samples/add-entry-worker/index-amd.html @@ -0,0 +1,10 @@ + + + + + AMD + + + + + diff --git a/test/chunking-form/samples/add-entry-worker/index-es.html b/test/chunking-form/samples/add-entry-worker/index-es.html new file mode 100644 index 00000000000..58ae4a61527 --- /dev/null +++ b/test/chunking-form/samples/add-entry-worker/index-es.html @@ -0,0 +1,10 @@ + + + + + Title + + + + + diff --git a/test/chunking-form/samples/add-entry-worker/index-system.html b/test/chunking-form/samples/add-entry-worker/index-system.html new file mode 100644 index 00000000000..96c687c1eb7 --- /dev/null +++ b/test/chunking-form/samples/add-entry-worker/index-system.html @@ -0,0 +1,11 @@ + + + + + SystemJS + + + + + + diff --git a/test/chunking-form/samples/add-entry-worker/main.js b/test/chunking-form/samples/add-entry-worker/main.js new file mode 100644 index 00000000000..2d30d9148c0 --- /dev/null +++ b/test/chunking-form/samples/add-entry-worker/main.js @@ -0,0 +1,7 @@ +import { getWorkerMessage } from 'merged'; + +getWorkerMessage().then(message => document.write(`

1: ${message.data}

`)); + +import('nested') + .then(result => result.getWorkerMessage()) + .then(message => document.write(`

2: ${message.data}

`)); diff --git a/test/chunking-form/samples/add-entry-worker/worker.js b/test/chunking-form/samples/add-entry-worker/worker.js new file mode 100644 index 00000000000..89a9039df0d --- /dev/null +++ b/test/chunking-form/samples/add-entry-worker/worker.js @@ -0,0 +1 @@ +postMessage('from worker'); diff --git a/test/chunking-form/samples/add-entry/_config.js b/test/chunking-form/samples/add-entry/_config.js new file mode 100644 index 00000000000..8d95e5a3d5f --- /dev/null +++ b/test/chunking-form/samples/add-entry/_config.js @@ -0,0 +1,36 @@ +const assert = require('assert'); +let metaId; + +module.exports = { + description: 'allows adding additional entry points', + options: { + input: 'main', + plugins: { + buildStart() { + metaId = this.addEntry('buildStart'); + }, + load(id) { + switch (id) { + case 'virtual': { + return `import value from './dep.js'; +console.log('virtual', value); +new Worker(import.meta.ROLLUP_CHUNK_URL_${this.addEntry('load')});`; + } + case 'load': + return `import value from './dep.js';console.log('load', value);`; + default: + return null; + } + }, + renderChunk() { + assert.strictEqual(this.getChunkFileName(metaId), 'buildStart.js'); + }, + resolveId(id) { + if (['virtual', 'load'].indexOf(id) >= 0) { + return id; + } + return null; + } + } + } +}; diff --git a/test/chunking-form/samples/add-entry/_expected/amd/buildStart.js b/test/chunking-form/samples/add-entry/_expected/amd/buildStart.js new file mode 100644 index 00000000000..946e98c742b --- /dev/null +++ b/test/chunking-form/samples/add-entry/_expected/amd/buildStart.js @@ -0,0 +1,5 @@ +define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; + + console.log('startBuild', __chunk_1.value); + +}); diff --git a/test/chunking-form/samples/add-entry/_expected/amd/generated-chunk.js b/test/chunking-form/samples/add-entry/_expected/amd/generated-chunk.js new file mode 100644 index 00000000000..5e2f9f02968 --- /dev/null +++ b/test/chunking-form/samples/add-entry/_expected/amd/generated-chunk.js @@ -0,0 +1,7 @@ +define(['exports'], function (exports) { 'use strict'; + + var value = 42; + + exports.value = value; + +}); diff --git a/test/chunking-form/samples/add-entry/_expected/amd/load.js b/test/chunking-form/samples/add-entry/_expected/amd/load.js new file mode 100644 index 00000000000..1e2456738ff --- /dev/null +++ b/test/chunking-form/samples/add-entry/_expected/amd/load.js @@ -0,0 +1,5 @@ +define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; + + console.log('load', __chunk_1.value); + +}); diff --git a/test/chunking-form/samples/add-entry/_expected/amd/main.js b/test/chunking-form/samples/add-entry/_expected/amd/main.js new file mode 100644 index 00000000000..0ce5315d3bb --- /dev/null +++ b/test/chunking-form/samples/add-entry/_expected/amd/main.js @@ -0,0 +1,8 @@ +define(['module', './generated-chunk.js'], function (module, __chunk_1) { 'use strict'; + + console.log('virtual', __chunk_1.value); + new Worker(new URL(module.uri + '/../load.js', document.baseURI).href); + + console.log('main', __chunk_1.value); + +}); diff --git a/test/chunking-form/samples/add-entry/_expected/cjs/buildStart.js b/test/chunking-form/samples/add-entry/_expected/cjs/buildStart.js new file mode 100644 index 00000000000..806bebd797b --- /dev/null +++ b/test/chunking-form/samples/add-entry/_expected/cjs/buildStart.js @@ -0,0 +1,5 @@ +'use strict'; + +var __chunk_1 = require('./generated-chunk.js'); + +console.log('startBuild', __chunk_1.value); diff --git a/test/chunking-form/samples/add-entry/_expected/cjs/generated-chunk.js b/test/chunking-form/samples/add-entry/_expected/cjs/generated-chunk.js new file mode 100644 index 00000000000..6cec42c9a07 --- /dev/null +++ b/test/chunking-form/samples/add-entry/_expected/cjs/generated-chunk.js @@ -0,0 +1,5 @@ +'use strict'; + +var value = 42; + +exports.value = value; diff --git a/test/chunking-form/samples/add-entry/_expected/cjs/load.js b/test/chunking-form/samples/add-entry/_expected/cjs/load.js new file mode 100644 index 00000000000..b80f005b64a --- /dev/null +++ b/test/chunking-form/samples/add-entry/_expected/cjs/load.js @@ -0,0 +1,5 @@ +'use strict'; + +var __chunk_1 = require('./generated-chunk.js'); + +console.log('load', __chunk_1.value); diff --git a/test/chunking-form/samples/add-entry/_expected/cjs/main.js b/test/chunking-form/samples/add-entry/_expected/cjs/main.js new file mode 100644 index 00000000000..ab396b9c448 --- /dev/null +++ b/test/chunking-form/samples/add-entry/_expected/cjs/main.js @@ -0,0 +1,8 @@ +'use strict'; + +var __chunk_1 = require('./generated-chunk.js'); + +console.log('virtual', __chunk_1.value); +new Worker((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/load.js').href : new URL((document.currentScript && document.currentScript.src || document.baseURI) + '/../load.js').href)); + +console.log('main', __chunk_1.value); diff --git a/test/chunking-form/samples/add-entry/_expected/es/buildStart.js b/test/chunking-form/samples/add-entry/_expected/es/buildStart.js new file mode 100644 index 00000000000..0aa63110db2 --- /dev/null +++ b/test/chunking-form/samples/add-entry/_expected/es/buildStart.js @@ -0,0 +1,3 @@ +import { a as value } from './generated-chunk.js'; + +console.log('startBuild', value); diff --git a/test/chunking-form/samples/add-entry/_expected/es/generated-chunk.js b/test/chunking-form/samples/add-entry/_expected/es/generated-chunk.js new file mode 100644 index 00000000000..637e70967d1 --- /dev/null +++ b/test/chunking-form/samples/add-entry/_expected/es/generated-chunk.js @@ -0,0 +1,3 @@ +var value = 42; + +export { value as a }; diff --git a/test/chunking-form/samples/add-entry/_expected/es/load.js b/test/chunking-form/samples/add-entry/_expected/es/load.js new file mode 100644 index 00000000000..b827d722353 --- /dev/null +++ b/test/chunking-form/samples/add-entry/_expected/es/load.js @@ -0,0 +1,3 @@ +import { a as value } from './generated-chunk.js'; + +console.log('load', value); diff --git a/test/chunking-form/samples/add-entry/_expected/es/main.js b/test/chunking-form/samples/add-entry/_expected/es/main.js new file mode 100644 index 00000000000..d2d4ce4cb84 --- /dev/null +++ b/test/chunking-form/samples/add-entry/_expected/es/main.js @@ -0,0 +1,6 @@ +import { a as value } from './generated-chunk.js'; + +console.log('virtual', value); +new Worker(new URL('load.js', import.meta.url).href); + +console.log('main', value); diff --git a/test/chunking-form/samples/add-entry/_expected/system/buildStart.js b/test/chunking-form/samples/add-entry/_expected/system/buildStart.js new file mode 100644 index 00000000000..77070033222 --- /dev/null +++ b/test/chunking-form/samples/add-entry/_expected/system/buildStart.js @@ -0,0 +1,14 @@ +System.register(['./generated-chunk.js'], function (exports, module) { + 'use strict'; + var value; + return { + setters: [function (module) { + value = module.a; + }], + execute: function () { + + console.log('startBuild', value); + + } + }; +}); diff --git a/test/chunking-form/samples/add-entry/_expected/system/generated-chunk.js b/test/chunking-form/samples/add-entry/_expected/system/generated-chunk.js new file mode 100644 index 00000000000..28865ae6188 --- /dev/null +++ b/test/chunking-form/samples/add-entry/_expected/system/generated-chunk.js @@ -0,0 +1,10 @@ +System.register([], function (exports, module) { + 'use strict'; + return { + execute: function () { + + var value = exports('a', 42); + + } + }; +}); diff --git a/test/chunking-form/samples/add-entry/_expected/system/load.js b/test/chunking-form/samples/add-entry/_expected/system/load.js new file mode 100644 index 00000000000..585b23e0646 --- /dev/null +++ b/test/chunking-form/samples/add-entry/_expected/system/load.js @@ -0,0 +1,14 @@ +System.register(['./generated-chunk.js'], function (exports, module) { + 'use strict'; + var value; + return { + setters: [function (module) { + value = module.a; + }], + execute: function () { + + console.log('load', value); + + } + }; +}); diff --git a/test/chunking-form/samples/add-entry/_expected/system/main.js b/test/chunking-form/samples/add-entry/_expected/system/main.js new file mode 100644 index 00000000000..88a42130f83 --- /dev/null +++ b/test/chunking-form/samples/add-entry/_expected/system/main.js @@ -0,0 +1,17 @@ +System.register(['./generated-chunk.js'], function (exports, module) { + 'use strict'; + var value; + return { + setters: [function (module) { + value = module.a; + }], + execute: function () { + + console.log('virtual', value); + new Worker(new URL('load.js', module.meta.url).href); + + console.log('main', value); + + } + }; +}); diff --git a/test/chunking-form/samples/add-entry/buildStart.js b/test/chunking-form/samples/add-entry/buildStart.js new file mode 100644 index 00000000000..f9b1b414da5 --- /dev/null +++ b/test/chunking-form/samples/add-entry/buildStart.js @@ -0,0 +1,3 @@ +import value from './dep.js'; + +console.log('startBuild', value); diff --git a/test/chunking-form/samples/add-entry/dep.js b/test/chunking-form/samples/add-entry/dep.js new file mode 100644 index 00000000000..7a4e8a723a4 --- /dev/null +++ b/test/chunking-form/samples/add-entry/dep.js @@ -0,0 +1 @@ +export default 42; diff --git a/test/chunking-form/samples/add-entry/main.js b/test/chunking-form/samples/add-entry/main.js new file mode 100644 index 00000000000..f5fe2279dd5 --- /dev/null +++ b/test/chunking-form/samples/add-entry/main.js @@ -0,0 +1,4 @@ +import 'virtual'; +import value from './dep.js'; + +console.log('main', value); From e24df1fc3a835111057e3c576750505c26f80b90 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Sun, 14 Apr 2019 08:07:45 +0200 Subject: [PATCH 17/60] Allow duplicate entry points again --- src/Graph.ts | 31 +++----------- src/ModuleLoader.ts | 40 +++++++++++++++---- .../samples/add-entry-existing/_config.js | 20 ++++++++++ .../add-entry-existing/_expected/amd/dep.js | 7 ++++ .../_expected/amd/first-main.js | 5 +++ .../_expected/amd/second-main.js | 5 +++ .../add-entry-existing/_expected/cjs/dep.js | 5 +++ .../_expected/cjs/first-main.js | 5 +++ .../_expected/cjs/second-main.js | 5 +++ .../add-entry-existing/_expected/es/dep.js | 3 ++ .../_expected/es/first-main.js | 3 ++ .../_expected/es/second-main.js | 3 ++ .../_expected/system/dep.js | 10 +++++ .../_expected/system/first-main.js | 14 +++++++ .../_expected/system/second-main.js | 14 +++++++ .../samples/add-entry-existing/dep.js | 1 + .../samples/add-entry-existing/main1.js | 3 ++ .../samples/add-entry-existing/main2.js | 3 ++ .../samples/add-entry-worker/_config.js | 7 +++- .../_expected/amd/chunks/chunk.js | 2 +- .../add-entry-worker/_expected/amd/main.js | 2 +- .../_expected/cjs/chunks/chunk.js | 2 +- .../add-entry-worker/_expected/cjs/main.js | 2 +- .../_expected/es/chunks/chunk.js | 2 +- .../add-entry-worker/_expected/es/main.js | 2 +- .../_expected/system/chunks/chunk.js | 2 +- .../add-entry-worker/_expected/system/main.js | 2 +- .../samples/add-entry/_config.js | 21 +--------- .../samples/add-entry/_expected/amd/load.js | 5 --- .../samples/add-entry/_expected/amd/main.js | 5 +-- .../samples/add-entry/_expected/cjs/load.js | 5 --- .../samples/add-entry/_expected/cjs/main.js | 3 -- .../samples/add-entry/_expected/es/load.js | 3 -- .../samples/add-entry/_expected/es/main.js | 3 -- .../add-entry/_expected/system/load.js | 14 ------- .../add-entry/_expected/system/main.js | 3 -- test/chunking-form/samples/add-entry/main.js | 1 - .../duplicate-input-entry-fails/_config.js | 15 ------- .../duplicate-input-entry-fails/main.js | 1 - .../samples/duplicate-input-entry/_config.js | 11 +++++ .../samples/duplicate-input-entry/entry.js | 1 + 41 files changed, 172 insertions(+), 119 deletions(-) create mode 100644 test/chunking-form/samples/add-entry-existing/_config.js create mode 100644 test/chunking-form/samples/add-entry-existing/_expected/amd/dep.js create mode 100644 test/chunking-form/samples/add-entry-existing/_expected/amd/first-main.js create mode 100644 test/chunking-form/samples/add-entry-existing/_expected/amd/second-main.js create mode 100644 test/chunking-form/samples/add-entry-existing/_expected/cjs/dep.js create mode 100644 test/chunking-form/samples/add-entry-existing/_expected/cjs/first-main.js create mode 100644 test/chunking-form/samples/add-entry-existing/_expected/cjs/second-main.js create mode 100644 test/chunking-form/samples/add-entry-existing/_expected/es/dep.js create mode 100644 test/chunking-form/samples/add-entry-existing/_expected/es/first-main.js create mode 100644 test/chunking-form/samples/add-entry-existing/_expected/es/second-main.js create mode 100644 test/chunking-form/samples/add-entry-existing/_expected/system/dep.js create mode 100644 test/chunking-form/samples/add-entry-existing/_expected/system/first-main.js create mode 100644 test/chunking-form/samples/add-entry-existing/_expected/system/second-main.js create mode 100644 test/chunking-form/samples/add-entry-existing/dep.js create mode 100644 test/chunking-form/samples/add-entry-existing/main1.js create mode 100644 test/chunking-form/samples/add-entry-existing/main2.js delete mode 100644 test/chunking-form/samples/add-entry/_expected/amd/load.js delete mode 100644 test/chunking-form/samples/add-entry/_expected/cjs/load.js delete mode 100644 test/chunking-form/samples/add-entry/_expected/es/load.js delete mode 100644 test/chunking-form/samples/add-entry/_expected/system/load.js delete mode 100644 test/function/samples/duplicate-input-entry-fails/_config.js delete mode 100644 test/function/samples/duplicate-input-entry-fails/main.js create mode 100644 test/function/samples/duplicate-input-entry/_config.js create mode 100644 test/function/samples/duplicate-input-entry/entry.js diff --git a/src/Graph.ts b/src/Graph.ts index 4bce746eef9..ef9613419b8 100644 --- a/src/Graph.ts +++ b/src/Graph.ts @@ -25,11 +25,10 @@ import { import { finaliseAsset } from './utils/assetHooks'; import { assignChunkColouringHashes } from './utils/chunkColouring'; import { Uint8ArrayToHexString } from './utils/entryHashing'; -import { error } from './utils/error'; import { analyseModuleExecution, sortByExecutionOrder } from './utils/executionOrder'; import { resolve } from './utils/path'; import { createPluginDriver, PluginDriver } from './utils/pluginDriver'; -import relativeId from './utils/relativeId'; +import relativeId, { getAliasName } from './utils/relativeId'; import { timeEnd, timeStart } from './utils/timers'; function makeOnwarn() { @@ -59,26 +58,6 @@ function normalizeEntryModules( })); } -function detectDuplicateEntryPoints( - entryModulesWithAliases: { alias: string | null; module: Module }[] -) { - const foundEntryModules = new Set(); - for (let i = 0; i < entryModulesWithAliases.length; i++) { - const entryModule = entryModulesWithAliases[i].module; - if (foundEntryModules.has(entryModule)) { - error({ - code: 'DUPLICATE_ENTRY_POINTS', - message: `Duplicate entry points detected. The input entries ${ - entryModulesWithAliases[i].alias - } and ${ - entryModulesWithAliases.find(({ module }) => module === entryModule).alias - } both point to the same module, ${entryModule.id}` - }); - } - foundEntryModules.add(entryModule); - } -} - export default class Graph { acornOptions: acorn.Options; acornParser: typeof acorn.Parser; @@ -246,6 +225,11 @@ export default class Graph { return this.moduleLoader .addEntryModules(normalizeEntryModules(entryModules)) .then(({ entryModulesWithAliases, manualChunkModulesByAlias }) => { + for (const entryModuleWithAlias of entryModulesWithAliases) { + if (entryModuleWithAlias.alias === null) { + entryModuleWithAlias.alias = getAliasName(entryModuleWithAlias.module.id); + } + } for (const module of Array.from(this.moduleById.values())) { if (module instanceof Module) { this.modules.push(module); @@ -260,8 +244,6 @@ export default class Graph { // determine the topological execution order for the bundle timeStart('analyse dependency graph', 2); - detectDuplicateEntryPoints(entryModulesWithAliases); - this.link(entryModulesWithAliases.map(({ module }) => module)); timeEnd('analyse dependency graph', 2); @@ -290,7 +272,6 @@ export default class Graph { // entry point graph colouring, before generating the import and export facades timeStart('generate chunks', 2); - // TODO Lukas can we move the alias assigment into the colouring? if (!this.preserveModules && !inlineDynamicImports) { assignChunkColouringHashes( entryModulesWithAliases.map(({ module }) => module), diff --git a/src/ModuleLoader.ts b/src/ModuleLoader.ts index 83fbf158483..6d40af8ebd8 100644 --- a/src/ModuleLoader.ts +++ b/src/ModuleLoader.ts @@ -11,7 +11,7 @@ import { timeEnd, timeStart } from './utils/timers'; import transform from './utils/transform'; interface ModuleWithAlias { - alias: string; + alias: string | null; module: Module; } @@ -27,7 +27,7 @@ function normalizeRelativeExternalId(importee: string, source: string) { // TODO Lukas this.addEntry -> addEntryChunk export class ModuleLoader { private readonly entriesByMetaId = new Map(); - private readonly entryModules: ModuleWithAlias[] = []; + private readonly entryModulesWithAliases: ModuleWithAlias[] = []; private readonly graph: Graph; private latestLoadModulesPromise: Promise = Promise.resolve(); private readonly manualChunkModules: Record = {}; @@ -68,12 +68,37 @@ export class ModuleLoader { }> { const loadNewEntryModulesPromise = Promise.all( unresolvedEntryModules.map(this.loadEntryModule) - ).then(entryModules => { - this.entryModules.push(...entryModules); - return entryModules; + ).then(entryModulesWithAliases => { + for (const entryModuleWithAlias of entryModulesWithAliases) { + const existingEntryModuleWithAlias = this.entryModulesWithAliases.find( + ({ module: { id } }) => id === entryModuleWithAlias.module.id + ); + if (existingEntryModuleWithAlias) { + // TODO Lukas: Do not assign aliases here + // TODO Lukas: Introduce separate manual chunk alias variable + if (entryModuleWithAlias.alias) { + if (!existingEntryModuleWithAlias.alias) { + existingEntryModuleWithAlias.alias = entryModuleWithAlias.alias; + } else if (existingEntryModuleWithAlias.alias !== entryModuleWithAlias.alias) { + // TODO Lukas can this even happen? + error({ + code: 'DUPLICATE_ENTRY_POINTS', + message: `Duplicate entry points with different aliases detected. The input entries ${ + existingEntryModuleWithAlias.alias + } and ${entryModuleWithAlias.alias} both point to the same module, ${ + entryModuleWithAlias.module.id + }` + }); + } + } + } else { + this.entryModulesWithAliases.push(entryModuleWithAlias); + } + } + return entryModulesWithAliases; }); return this.awaitLoadModulesPromise(loadNewEntryModulesPromise).then(newEntryModules => ({ - entryModulesWithAliases: this.entryModules, + entryModulesWithAliases: this.entryModulesWithAliases, manualChunkModulesByAlias: this.manualChunkModules, newEntryModules })); @@ -144,6 +169,7 @@ export class ModuleLoader { .then(replacement => { if (!replacement) return; const dynamicImport = module.dynamicImports[index]; + // TODO Lukas why can we assign to the module here? dynamicImport.alias = getAliasName(replacement); if (typeof dynamicImportExpression !== 'string') { dynamicImport.resolution = replacement; @@ -295,7 +321,7 @@ export class ModuleLoader { } return this.fetchModule(id, undefined).then(module => ({ - alias: alias || getAliasName(module.id), + alias, module })); }); diff --git a/test/chunking-form/samples/add-entry-existing/_config.js b/test/chunking-form/samples/add-entry-existing/_config.js new file mode 100644 index 00000000000..48f5e289b95 --- /dev/null +++ b/test/chunking-form/samples/add-entry-existing/_config.js @@ -0,0 +1,20 @@ +// TODO Lukas entry not found -> unhandled Promise rejection? +module.exports = { + description: 'allows adding modules already in the graph as entry points', + options: { + input: { + 'first-main': 'main1', + 'second-main': 'main2' + }, + plugins: { + buildStart() { + // it should be possible to add existing entry points while not overriding their alias + this.addEntry('main1'); + + // if an existing dependency is added, all references should use the new name + this.addEntry('dep.js'); + this.addEntry('dep'); + } + } + } +}; diff --git a/test/chunking-form/samples/add-entry-existing/_expected/amd/dep.js b/test/chunking-form/samples/add-entry-existing/_expected/amd/dep.js new file mode 100644 index 00000000000..e14fcf80133 --- /dev/null +++ b/test/chunking-form/samples/add-entry-existing/_expected/amd/dep.js @@ -0,0 +1,7 @@ +define(function () { 'use strict'; + + var value = 42; + + return value; + +}); diff --git a/test/chunking-form/samples/add-entry-existing/_expected/amd/first-main.js b/test/chunking-form/samples/add-entry-existing/_expected/amd/first-main.js new file mode 100644 index 00000000000..e92c9063515 --- /dev/null +++ b/test/chunking-form/samples/add-entry-existing/_expected/amd/first-main.js @@ -0,0 +1,5 @@ +define(['./dep.js'], function (dep) { 'use strict'; + + console.log('main1', dep); + +}); diff --git a/test/chunking-form/samples/add-entry-existing/_expected/amd/second-main.js b/test/chunking-form/samples/add-entry-existing/_expected/amd/second-main.js new file mode 100644 index 00000000000..e92c9063515 --- /dev/null +++ b/test/chunking-form/samples/add-entry-existing/_expected/amd/second-main.js @@ -0,0 +1,5 @@ +define(['./dep.js'], function (dep) { 'use strict'; + + console.log('main1', dep); + +}); diff --git a/test/chunking-form/samples/add-entry-existing/_expected/cjs/dep.js b/test/chunking-form/samples/add-entry-existing/_expected/cjs/dep.js new file mode 100644 index 00000000000..07d7bfe2962 --- /dev/null +++ b/test/chunking-form/samples/add-entry-existing/_expected/cjs/dep.js @@ -0,0 +1,5 @@ +'use strict'; + +var value = 42; + +module.exports = value; diff --git a/test/chunking-form/samples/add-entry-existing/_expected/cjs/first-main.js b/test/chunking-form/samples/add-entry-existing/_expected/cjs/first-main.js new file mode 100644 index 00000000000..cb8b24decc7 --- /dev/null +++ b/test/chunking-form/samples/add-entry-existing/_expected/cjs/first-main.js @@ -0,0 +1,5 @@ +'use strict'; + +var dep = require('./dep.js'); + +console.log('main1', dep); diff --git a/test/chunking-form/samples/add-entry-existing/_expected/cjs/second-main.js b/test/chunking-form/samples/add-entry-existing/_expected/cjs/second-main.js new file mode 100644 index 00000000000..cb8b24decc7 --- /dev/null +++ b/test/chunking-form/samples/add-entry-existing/_expected/cjs/second-main.js @@ -0,0 +1,5 @@ +'use strict'; + +var dep = require('./dep.js'); + +console.log('main1', dep); diff --git a/test/chunking-form/samples/add-entry-existing/_expected/es/dep.js b/test/chunking-form/samples/add-entry-existing/_expected/es/dep.js new file mode 100644 index 00000000000..630536069ae --- /dev/null +++ b/test/chunking-form/samples/add-entry-existing/_expected/es/dep.js @@ -0,0 +1,3 @@ +var value = 42; + +export default value; diff --git a/test/chunking-form/samples/add-entry-existing/_expected/es/first-main.js b/test/chunking-form/samples/add-entry-existing/_expected/es/first-main.js new file mode 100644 index 00000000000..e384824c6f2 --- /dev/null +++ b/test/chunking-form/samples/add-entry-existing/_expected/es/first-main.js @@ -0,0 +1,3 @@ +import value from './dep.js'; + +console.log('main1', value); diff --git a/test/chunking-form/samples/add-entry-existing/_expected/es/second-main.js b/test/chunking-form/samples/add-entry-existing/_expected/es/second-main.js new file mode 100644 index 00000000000..e384824c6f2 --- /dev/null +++ b/test/chunking-form/samples/add-entry-existing/_expected/es/second-main.js @@ -0,0 +1,3 @@ +import value from './dep.js'; + +console.log('main1', value); diff --git a/test/chunking-form/samples/add-entry-existing/_expected/system/dep.js b/test/chunking-form/samples/add-entry-existing/_expected/system/dep.js new file mode 100644 index 00000000000..a90fc7ba918 --- /dev/null +++ b/test/chunking-form/samples/add-entry-existing/_expected/system/dep.js @@ -0,0 +1,10 @@ +System.register([], function (exports, module) { + 'use strict'; + return { + execute: function () { + + var value = exports('default', 42); + + } + }; +}); diff --git a/test/chunking-form/samples/add-entry-existing/_expected/system/first-main.js b/test/chunking-form/samples/add-entry-existing/_expected/system/first-main.js new file mode 100644 index 00000000000..1441e3fac98 --- /dev/null +++ b/test/chunking-form/samples/add-entry-existing/_expected/system/first-main.js @@ -0,0 +1,14 @@ +System.register(['./dep.js'], function (exports, module) { + 'use strict'; + var value; + return { + setters: [function (module) { + value = module.default; + }], + execute: function () { + + console.log('main1', value); + + } + }; +}); diff --git a/test/chunking-form/samples/add-entry-existing/_expected/system/second-main.js b/test/chunking-form/samples/add-entry-existing/_expected/system/second-main.js new file mode 100644 index 00000000000..1441e3fac98 --- /dev/null +++ b/test/chunking-form/samples/add-entry-existing/_expected/system/second-main.js @@ -0,0 +1,14 @@ +System.register(['./dep.js'], function (exports, module) { + 'use strict'; + var value; + return { + setters: [function (module) { + value = module.default; + }], + execute: function () { + + console.log('main1', value); + + } + }; +}); diff --git a/test/chunking-form/samples/add-entry-existing/dep.js b/test/chunking-form/samples/add-entry-existing/dep.js new file mode 100644 index 00000000000..7a4e8a723a4 --- /dev/null +++ b/test/chunking-form/samples/add-entry-existing/dep.js @@ -0,0 +1 @@ +export default 42; diff --git a/test/chunking-form/samples/add-entry-existing/main1.js b/test/chunking-form/samples/add-entry-existing/main1.js new file mode 100644 index 00000000000..e384824c6f2 --- /dev/null +++ b/test/chunking-form/samples/add-entry-existing/main1.js @@ -0,0 +1,3 @@ +import value from './dep.js'; + +console.log('main1', value); diff --git a/test/chunking-form/samples/add-entry-existing/main2.js b/test/chunking-form/samples/add-entry-existing/main2.js new file mode 100644 index 00000000000..e384824c6f2 --- /dev/null +++ b/test/chunking-form/samples/add-entry-existing/main2.js @@ -0,0 +1,3 @@ +import value from './dep.js'; + +console.log('main1', value); diff --git a/test/chunking-form/samples/add-entry-worker/_config.js b/test/chunking-form/samples/add-entry-worker/_config.js index 346acf4cbdf..9392d29f984 100644 --- a/test/chunking-form/samples/add-entry-worker/_config.js +++ b/test/chunking-form/samples/add-entry-worker/_config.js @@ -1,5 +1,9 @@ let metaId; +// TODO Lukas can we load requirejs via renderChunk? +// importScripts('../../../../../../node_modules/requirejs/require.js'); +// requirejs([], function () { ... +// also test shared modules module.exports = { description: 'allows adding additional entry points', options: { @@ -11,12 +15,11 @@ module.exports = { load(id) { if (id === 'merged' || id === 'nested') { if (!metaId) { - // TODO Lukas is there a way to prevent reemitting the same entry point? What about already existing ones? metaId = this.addEntry('worker'); } return ` export const getWorkerMessage = () => new Promise(resolve => { - const worker = new Worker(import.meta.ROLLUP_CHUNK_URL_${metaId}); + const worker = new Worker(import.meta.ROLLUP_CHUNK_URL_${metaId}, {type: 'module'}); worker.onmessage = resolve; });`; } diff --git a/test/chunking-form/samples/add-entry-worker/_expected/amd/chunks/chunk.js b/test/chunking-form/samples/add-entry-worker/_expected/amd/chunks/chunk.js index e372a64fc7f..ad6d56cfa97 100644 --- a/test/chunking-form/samples/add-entry-worker/_expected/amd/chunks/chunk.js +++ b/test/chunking-form/samples/add-entry-worker/_expected/amd/chunks/chunk.js @@ -1,7 +1,7 @@ define(['module', 'exports'], function (module, exports) { 'use strict'; const getWorkerMessage = () => new Promise(resolve => { - const worker = new Worker(new URL(module.uri + '/../../worker.js', document.baseURI).href); + const worker = new Worker(new URL(module.uri + '/../../worker.js', document.baseURI).href, {type: 'module'}); worker.onmessage = resolve; }); diff --git a/test/chunking-form/samples/add-entry-worker/_expected/amd/main.js b/test/chunking-form/samples/add-entry-worker/_expected/amd/main.js index 8b65a262c12..c7eaf3a6dac 100644 --- a/test/chunking-form/samples/add-entry-worker/_expected/amd/main.js +++ b/test/chunking-form/samples/add-entry-worker/_expected/amd/main.js @@ -1,7 +1,7 @@ define(['module', 'require'], function (module, require) { 'use strict'; const getWorkerMessage = () => new Promise(resolve => { - const worker = new Worker(new URL(module.uri + '/../worker.js', document.baseURI).href); + const worker = new Worker(new URL(module.uri + '/../worker.js', document.baseURI).href, {type: 'module'}); worker.onmessage = resolve; }); diff --git a/test/chunking-form/samples/add-entry-worker/_expected/cjs/chunks/chunk.js b/test/chunking-form/samples/add-entry-worker/_expected/cjs/chunks/chunk.js index 261509b57c7..61dd338f47c 100644 --- a/test/chunking-form/samples/add-entry-worker/_expected/cjs/chunks/chunk.js +++ b/test/chunking-form/samples/add-entry-worker/_expected/cjs/chunks/chunk.js @@ -1,7 +1,7 @@ 'use strict'; const getWorkerMessage = () => new Promise(resolve => { - const worker = new Worker((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/../worker.js').href : new URL((document.currentScript && document.currentScript.src || document.baseURI) + '/../../worker.js').href)); + const worker = new Worker((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/../worker.js').href : new URL((document.currentScript && document.currentScript.src || document.baseURI) + '/../../worker.js').href), {type: 'module'}); worker.onmessage = resolve; }); diff --git a/test/chunking-form/samples/add-entry-worker/_expected/cjs/main.js b/test/chunking-form/samples/add-entry-worker/_expected/cjs/main.js index 6c6dcd1dadd..20755ed466d 100644 --- a/test/chunking-form/samples/add-entry-worker/_expected/cjs/main.js +++ b/test/chunking-form/samples/add-entry-worker/_expected/cjs/main.js @@ -1,7 +1,7 @@ 'use strict'; const getWorkerMessage = () => new Promise(resolve => { - const worker = new Worker((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/worker.js').href : new URL((document.currentScript && document.currentScript.src || document.baseURI) + '/../worker.js').href)); + const worker = new Worker((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/worker.js').href : new URL((document.currentScript && document.currentScript.src || document.baseURI) + '/../worker.js').href), {type: 'module'}); worker.onmessage = resolve; }); diff --git a/test/chunking-form/samples/add-entry-worker/_expected/es/chunks/chunk.js b/test/chunking-form/samples/add-entry-worker/_expected/es/chunks/chunk.js index 66b32e656c4..ce751792d9f 100644 --- a/test/chunking-form/samples/add-entry-worker/_expected/es/chunks/chunk.js +++ b/test/chunking-form/samples/add-entry-worker/_expected/es/chunks/chunk.js @@ -1,5 +1,5 @@ const getWorkerMessage = () => new Promise(resolve => { - const worker = new Worker(new URL('../worker.js', import.meta.url).href); + const worker = new Worker(new URL('../worker.js', import.meta.url).href, {type: 'module'}); worker.onmessage = resolve; }); diff --git a/test/chunking-form/samples/add-entry-worker/_expected/es/main.js b/test/chunking-form/samples/add-entry-worker/_expected/es/main.js index 2e201e79a32..70ea4e8f767 100644 --- a/test/chunking-form/samples/add-entry-worker/_expected/es/main.js +++ b/test/chunking-form/samples/add-entry-worker/_expected/es/main.js @@ -1,5 +1,5 @@ const getWorkerMessage = () => new Promise(resolve => { - const worker = new Worker(new URL('worker.js', import.meta.url).href); + const worker = new Worker(new URL('worker.js', import.meta.url).href, {type: 'module'}); worker.onmessage = resolve; }); diff --git a/test/chunking-form/samples/add-entry-worker/_expected/system/chunks/chunk.js b/test/chunking-form/samples/add-entry-worker/_expected/system/chunks/chunk.js index d638eb2b7e1..1eafc4034cf 100644 --- a/test/chunking-form/samples/add-entry-worker/_expected/system/chunks/chunk.js +++ b/test/chunking-form/samples/add-entry-worker/_expected/system/chunks/chunk.js @@ -4,7 +4,7 @@ System.register([], function (exports, module) { execute: function () { const getWorkerMessage = exports('getWorkerMessage', () => new Promise(resolve => { - const worker = new Worker(new URL('../worker.js', module.meta.url).href); + const worker = new Worker(new URL('../worker.js', module.meta.url).href, {type: 'module'}); worker.onmessage = resolve; })); diff --git a/test/chunking-form/samples/add-entry-worker/_expected/system/main.js b/test/chunking-form/samples/add-entry-worker/_expected/system/main.js index 0f2664053e8..1b1a3b48846 100644 --- a/test/chunking-form/samples/add-entry-worker/_expected/system/main.js +++ b/test/chunking-form/samples/add-entry-worker/_expected/system/main.js @@ -4,7 +4,7 @@ System.register([], function (exports, module) { execute: function () { const getWorkerMessage = () => new Promise(resolve => { - const worker = new Worker(new URL('worker.js', module.meta.url).href); + const worker = new Worker(new URL('worker.js', module.meta.url).href, {type: 'module'}); worker.onmessage = resolve; }); diff --git a/test/chunking-form/samples/add-entry/_config.js b/test/chunking-form/samples/add-entry/_config.js index 8d95e5a3d5f..07c2684e237 100644 --- a/test/chunking-form/samples/add-entry/_config.js +++ b/test/chunking-form/samples/add-entry/_config.js @@ -2,34 +2,15 @@ const assert = require('assert'); let metaId; module.exports = { - description: 'allows adding additional entry points', + description: 'allows adding additional entry points and retrieving their name', options: { input: 'main', plugins: { buildStart() { metaId = this.addEntry('buildStart'); }, - load(id) { - switch (id) { - case 'virtual': { - return `import value from './dep.js'; -console.log('virtual', value); -new Worker(import.meta.ROLLUP_CHUNK_URL_${this.addEntry('load')});`; - } - case 'load': - return `import value from './dep.js';console.log('load', value);`; - default: - return null; - } - }, renderChunk() { assert.strictEqual(this.getChunkFileName(metaId), 'buildStart.js'); - }, - resolveId(id) { - if (['virtual', 'load'].indexOf(id) >= 0) { - return id; - } - return null; } } } diff --git a/test/chunking-form/samples/add-entry/_expected/amd/load.js b/test/chunking-form/samples/add-entry/_expected/amd/load.js deleted file mode 100644 index 1e2456738ff..00000000000 --- a/test/chunking-form/samples/add-entry/_expected/amd/load.js +++ /dev/null @@ -1,5 +0,0 @@ -define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; - - console.log('load', __chunk_1.value); - -}); diff --git a/test/chunking-form/samples/add-entry/_expected/amd/main.js b/test/chunking-form/samples/add-entry/_expected/amd/main.js index 0ce5315d3bb..486030eb3c3 100644 --- a/test/chunking-form/samples/add-entry/_expected/amd/main.js +++ b/test/chunking-form/samples/add-entry/_expected/amd/main.js @@ -1,7 +1,4 @@ -define(['module', './generated-chunk.js'], function (module, __chunk_1) { 'use strict'; - - console.log('virtual', __chunk_1.value); - new Worker(new URL(module.uri + '/../load.js', document.baseURI).href); +define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; console.log('main', __chunk_1.value); diff --git a/test/chunking-form/samples/add-entry/_expected/cjs/load.js b/test/chunking-form/samples/add-entry/_expected/cjs/load.js deleted file mode 100644 index b80f005b64a..00000000000 --- a/test/chunking-form/samples/add-entry/_expected/cjs/load.js +++ /dev/null @@ -1,5 +0,0 @@ -'use strict'; - -var __chunk_1 = require('./generated-chunk.js'); - -console.log('load', __chunk_1.value); diff --git a/test/chunking-form/samples/add-entry/_expected/cjs/main.js b/test/chunking-form/samples/add-entry/_expected/cjs/main.js index ab396b9c448..04040e8d4f8 100644 --- a/test/chunking-form/samples/add-entry/_expected/cjs/main.js +++ b/test/chunking-form/samples/add-entry/_expected/cjs/main.js @@ -2,7 +2,4 @@ var __chunk_1 = require('./generated-chunk.js'); -console.log('virtual', __chunk_1.value); -new Worker((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/load.js').href : new URL((document.currentScript && document.currentScript.src || document.baseURI) + '/../load.js').href)); - console.log('main', __chunk_1.value); diff --git a/test/chunking-form/samples/add-entry/_expected/es/load.js b/test/chunking-form/samples/add-entry/_expected/es/load.js deleted file mode 100644 index b827d722353..00000000000 --- a/test/chunking-form/samples/add-entry/_expected/es/load.js +++ /dev/null @@ -1,3 +0,0 @@ -import { a as value } from './generated-chunk.js'; - -console.log('load', value); diff --git a/test/chunking-form/samples/add-entry/_expected/es/main.js b/test/chunking-form/samples/add-entry/_expected/es/main.js index d2d4ce4cb84..6647a955386 100644 --- a/test/chunking-form/samples/add-entry/_expected/es/main.js +++ b/test/chunking-form/samples/add-entry/_expected/es/main.js @@ -1,6 +1,3 @@ import { a as value } from './generated-chunk.js'; -console.log('virtual', value); -new Worker(new URL('load.js', import.meta.url).href); - console.log('main', value); diff --git a/test/chunking-form/samples/add-entry/_expected/system/load.js b/test/chunking-form/samples/add-entry/_expected/system/load.js deleted file mode 100644 index 585b23e0646..00000000000 --- a/test/chunking-form/samples/add-entry/_expected/system/load.js +++ /dev/null @@ -1,14 +0,0 @@ -System.register(['./generated-chunk.js'], function (exports, module) { - 'use strict'; - var value; - return { - setters: [function (module) { - value = module.a; - }], - execute: function () { - - console.log('load', value); - - } - }; -}); diff --git a/test/chunking-form/samples/add-entry/_expected/system/main.js b/test/chunking-form/samples/add-entry/_expected/system/main.js index 88a42130f83..9db3c59931a 100644 --- a/test/chunking-form/samples/add-entry/_expected/system/main.js +++ b/test/chunking-form/samples/add-entry/_expected/system/main.js @@ -7,9 +7,6 @@ System.register(['./generated-chunk.js'], function (exports, module) { }], execute: function () { - console.log('virtual', value); - new Worker(new URL('load.js', module.meta.url).href); - console.log('main', value); } diff --git a/test/chunking-form/samples/add-entry/main.js b/test/chunking-form/samples/add-entry/main.js index f5fe2279dd5..4a9b3a3f405 100644 --- a/test/chunking-form/samples/add-entry/main.js +++ b/test/chunking-form/samples/add-entry/main.js @@ -1,4 +1,3 @@ -import 'virtual'; import value from './dep.js'; console.log('main', value); diff --git a/test/function/samples/duplicate-input-entry-fails/_config.js b/test/function/samples/duplicate-input-entry-fails/_config.js deleted file mode 100644 index aa1b1b2e67f..00000000000 --- a/test/function/samples/duplicate-input-entry-fails/_config.js +++ /dev/null @@ -1,15 +0,0 @@ -const path = require('path'); - -module.exports = { - description: 'duplicate entry modules', - options: { - input: ['main.js', 'main.js'] - }, - error: { - code: 'DUPLICATE_ENTRY_POINTS', - message: `Duplicate entry points detected. The input entries main and main both point to the same module, ${path.resolve( - __dirname, - 'main.js' - )}` - } -}; diff --git a/test/function/samples/duplicate-input-entry-fails/main.js b/test/function/samples/duplicate-input-entry-fails/main.js deleted file mode 100644 index 20e41f60071..00000000000 --- a/test/function/samples/duplicate-input-entry-fails/main.js +++ /dev/null @@ -1 +0,0 @@ -export var main = 'main'; \ No newline at end of file diff --git a/test/function/samples/duplicate-input-entry/_config.js b/test/function/samples/duplicate-input-entry/_config.js new file mode 100644 index 00000000000..cecb19f2eeb --- /dev/null +++ b/test/function/samples/duplicate-input-entry/_config.js @@ -0,0 +1,11 @@ +const assert = require('assert'); + +module.exports = { + description: 'handles duplicate entry modules when using the object form', + options: { + input: ['entry', 'entry.js'] + }, + exports(exports) { + assert.deepStrictEqual(exports, { entry: 'main' }); + } +}; diff --git a/test/function/samples/duplicate-input-entry/entry.js b/test/function/samples/duplicate-input-entry/entry.js new file mode 100644 index 00000000000..735812c9c09 --- /dev/null +++ b/test/function/samples/duplicate-input-entry/entry.js @@ -0,0 +1 @@ +export var entry = 'main'; From 148661caacc35446234e52fdfcffc2ea2255bcf2 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Sun, 14 Apr 2019 08:14:08 +0200 Subject: [PATCH 18/60] Rename addEntry -> emitEntryChunk --- src/ModuleLoader.ts | 1 - src/rollup/types.d.ts | 4 ++-- src/utils/pluginDriver.ts | 2 +- test/chunking-form/samples/add-entry-existing/_config.js | 6 +++--- test/chunking-form/samples/add-entry-worker/_config.js | 2 +- test/chunking-form/samples/add-entry/_config.js | 2 +- 6 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/ModuleLoader.ts b/src/ModuleLoader.ts index 6d40af8ebd8..7def2ff0918 100644 --- a/src/ModuleLoader.ts +++ b/src/ModuleLoader.ts @@ -24,7 +24,6 @@ function normalizeRelativeExternalId(importee: string, source: string) { return isRelative(source) ? resolve(importee, '..', source) : source; } -// TODO Lukas this.addEntry -> addEntryChunk export class ModuleLoader { private readonly entriesByMetaId = new Map(); private readonly entryModulesWithAliases: ModuleWithAlias[] = []; diff --git a/src/rollup/types.d.ts b/src/rollup/types.d.ts index fce539a6153..5c2f40e3c6f 100644 --- a/src/rollup/types.d.ts +++ b/src/rollup/types.d.ts @@ -104,13 +104,13 @@ export interface MinimalPluginContext { } export type EmitAsset = (name: string, source?: string | Buffer) => string; -export type AddEntry = (name: string) => string; +export type EmitEntryChunk = (name: string) => string; export interface PluginContext extends MinimalPluginContext { - addEntry: AddEntry; addWatchFile: (id: string) => void; cache: PluginCache; emitAsset: EmitAsset; + emitEntryChunk: EmitEntryChunk; error: (err: RollupError | string, pos?: { column: number; line: number }) => void; getAssetFileName: (assetMetaId: string) => string; getChunkFileName: (chunkMetaId: string) => string; diff --git a/src/utils/pluginDriver.ts b/src/utils/pluginDriver.ts index 57ade528131..b1cff8b17a6 100644 --- a/src/utils/pluginDriver.ts +++ b/src/utils/pluginDriver.ts @@ -112,7 +112,7 @@ export function createPluginDriver( } const context: PluginContext = { - addEntry(id: string) { + emitEntryChunk(id: string) { return graph.moduleLoader.addEntryModuleAndGetMetaId({ alias: null, unresolvedId: id }); }, addWatchFile(id: string) { diff --git a/test/chunking-form/samples/add-entry-existing/_config.js b/test/chunking-form/samples/add-entry-existing/_config.js index 48f5e289b95..d9a3b8d229c 100644 --- a/test/chunking-form/samples/add-entry-existing/_config.js +++ b/test/chunking-form/samples/add-entry-existing/_config.js @@ -9,11 +9,11 @@ module.exports = { plugins: { buildStart() { // it should be possible to add existing entry points while not overriding their alias - this.addEntry('main1'); + this.emitEntryChunk('main1'); // if an existing dependency is added, all references should use the new name - this.addEntry('dep.js'); - this.addEntry('dep'); + this.emitEntryChunk('dep.js'); + this.emitEntryChunk('dep'); } } } diff --git a/test/chunking-form/samples/add-entry-worker/_config.js b/test/chunking-form/samples/add-entry-worker/_config.js index 9392d29f984..51a39261230 100644 --- a/test/chunking-form/samples/add-entry-worker/_config.js +++ b/test/chunking-form/samples/add-entry-worker/_config.js @@ -15,7 +15,7 @@ module.exports = { load(id) { if (id === 'merged' || id === 'nested') { if (!metaId) { - metaId = this.addEntry('worker'); + metaId = this.emitEntryChunk('worker'); } return ` export const getWorkerMessage = () => new Promise(resolve => { diff --git a/test/chunking-form/samples/add-entry/_config.js b/test/chunking-form/samples/add-entry/_config.js index 07c2684e237..9e314116c05 100644 --- a/test/chunking-form/samples/add-entry/_config.js +++ b/test/chunking-form/samples/add-entry/_config.js @@ -7,7 +7,7 @@ module.exports = { input: 'main', plugins: { buildStart() { - metaId = this.addEntry('buildStart'); + metaId = this.emitEntryChunk('buildStart'); }, renderChunk() { assert.strictEqual(this.getChunkFileName(metaId), 'buildStart.js'); From 9a5a98cc88728406c42967a171d60174e4232b12 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Sun, 14 Apr 2019 09:58:53 +0200 Subject: [PATCH 19/60] Simplify alias handling by immediately assigning a chunkAlias to entry points and introducing a manualChunkAlias for colouring to resolve this confusing double use of chunkAlias --- src/Chunk.ts | 2 + src/Graph.ts | 23 ++---- src/Module.ts | 3 +- src/ModuleLoader.ts | 76 ++++++++----------- src/utils/chunkColouring.ts | 14 ++-- ...nerated-dynamic2.js => generated-chunk.js} | 0 ...erated-dynamic3.js => generated-chunk2.js} | 0 .../_expected/amd/main.js | 2 +- ...nerated-dynamic2.js => generated-chunk.js} | 0 ...erated-dynamic3.js => generated-chunk2.js} | 0 .../_expected/cjs/main.js | 2 +- ...nerated-dynamic2.js => generated-chunk.js} | 0 ...erated-dynamic3.js => generated-chunk2.js} | 0 .../_expected/es/main.js | 2 +- ...nerated-dynamic2.js => generated-chunk.js} | 0 ...erated-dynamic3.js => generated-chunk2.js} | 0 .../_expected/system/main.js | 2 +- 17 files changed, 54 insertions(+), 72 deletions(-) rename test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/{generated-dynamic2.js => generated-chunk.js} (100%) rename test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/{generated-dynamic3.js => generated-chunk2.js} (100%) rename test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/cjs/{generated-dynamic2.js => generated-chunk.js} (100%) rename test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/cjs/{generated-dynamic3.js => generated-chunk2.js} (100%) rename test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/es/{generated-dynamic2.js => generated-chunk.js} (100%) rename test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/es/{generated-dynamic3.js => generated-chunk2.js} (100%) rename test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/system/{generated-dynamic2.js => generated-chunk.js} (100%) rename test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/system/{generated-dynamic3.js => generated-chunk2.js} (100%) diff --git a/src/Chunk.ts b/src/Chunk.ts index 2e2fb2da111..562be4c2154 100644 --- a/src/Chunk.ts +++ b/src/Chunk.ts @@ -152,6 +152,7 @@ export default class Chunk { if (this.isEmpty && module.isIncluded()) { this.isEmpty = false; } + // TODO Lukas can this be done via manualChunkAlias? if (module.chunkAlias) { this.isManualChunk = true; } @@ -167,6 +168,7 @@ export default class Chunk { if (this.entryModules.length > 0) { this.variableName = makeLegal( basename( + // TODO Lukas is searching necessary as all entryModules should have a chunkAlias by now? this.entryModules.map(module => module.chunkAlias).find(Boolean) || this.entryModules[0].id ) diff --git a/src/Graph.ts b/src/Graph.ts index ef9613419b8..08b797baa8a 100644 --- a/src/Graph.ts +++ b/src/Graph.ts @@ -224,10 +224,10 @@ export default class Graph { } return this.moduleLoader .addEntryModules(normalizeEntryModules(entryModules)) - .then(({ entryModulesWithAliases, manualChunkModulesByAlias }) => { - for (const entryModuleWithAlias of entryModulesWithAliases) { - if (entryModuleWithAlias.alias === null) { - entryModuleWithAlias.alias = getAliasName(entryModuleWithAlias.module.id); + .then(({ entryModules, manualChunkModulesByAlias }) => { + for (const entryModule of entryModules) { + if (entryModule.chunkAlias === null) { + entryModule.chunkAlias = getAliasName(entryModule.id); } } for (const module of Array.from(this.moduleById.values())) { @@ -244,7 +244,7 @@ export default class Graph { // determine the topological execution order for the bundle timeStart('analyse dependency graph', 2); - this.link(entryModulesWithAliases.map(({ module }) => module)); + this.link(entryModules); timeEnd('analyse dependency graph', 2); @@ -252,13 +252,13 @@ export default class Graph { timeStart('mark included statements', 2); if (inlineDynamicImports) { - if (entryModulesWithAliases.length > 1) { + if (entryModules.length > 1) { throw new Error( 'Internal Error: can only inline dynamic imports for single-file builds.' ); } } - for (const { module } of entryModulesWithAliases) { + for (const module of entryModules) { module.includeAllExports(); } this.includeMarked(this.modules); @@ -273,14 +273,7 @@ export default class Graph { timeStart('generate chunks', 2); if (!this.preserveModules && !inlineDynamicImports) { - assignChunkColouringHashes( - entryModulesWithAliases.map(({ module }) => module), - manualChunkModulesByAlias - ); - } - - for (let i = entryModulesWithAliases.length - 1; i >= 0; i--) { - entryModulesWithAliases[i].module.chunkAlias = entryModulesWithAliases[i].alias; + assignChunkColouringHashes(entryModules, manualChunkModulesByAlias); } // TODO: there is one special edge case unhandled here and that is that any module diff --git a/src/Module.ts b/src/Module.ts index aad8299adcf..97f009cbd36 100644 --- a/src/Module.ts +++ b/src/Module.ts @@ -164,7 +164,7 @@ const MISSING_EXPORT_SHIM_DESCRIPTION: ExportDescription = { export default class Module { chunk: Chunk; - chunkAlias: string = undefined; + chunkAlias: string = null; code: string; comments: CommentDescription[] = []; customTransformCache: boolean; @@ -192,6 +192,7 @@ export default class Module { isEntryPoint: boolean = false; isExecuted: boolean = false; isExternal: false; + manualChunkAlias: string = null; originalCode: string; originalSourcemap: RawSourceMap | void; reexports: { [name: string]: ReexportDescription } = Object.create(null); diff --git a/src/ModuleLoader.ts b/src/ModuleLoader.ts index 7def2ff0918..4afeaee948b 100644 --- a/src/ModuleLoader.ts +++ b/src/ModuleLoader.ts @@ -10,11 +10,6 @@ import relativeId, { getAliasName } from './utils/relativeId'; import { timeEnd, timeStart } from './utils/timers'; import transform from './utils/transform'; -interface ModuleWithAlias { - alias: string | null; - module: Module; -} - export interface UnresolvedModuleWithAlias { alias: string | null; unresolvedId: string; @@ -26,7 +21,7 @@ function normalizeRelativeExternalId(importee: string, source: string) { export class ModuleLoader { private readonly entriesByMetaId = new Map(); - private readonly entryModulesWithAliases: ModuleWithAlias[] = []; + private readonly entryModules: Module[] = []; private readonly graph: Graph; private latestLoadModulesPromise: Promise = Promise.resolve(); private readonly manualChunkModules: Record = {}; @@ -51,7 +46,7 @@ export class ModuleLoader { this.entriesByMetaId, unresolvedEntryModule.unresolvedId ); - this.addEntryModules([unresolvedEntryModule]).then(({ newEntryModules: [{ module }] }) => { + this.addEntryModules([unresolvedEntryModule]).then(({ newEntryModules: [module] }) => { entryRecord.module = module; }); return metaId; @@ -61,43 +56,23 @@ export class ModuleLoader { addEntryModules( unresolvedEntryModules: UnresolvedModuleWithAlias[] ): Promise<{ - entryModulesWithAliases: ModuleWithAlias[]; + entryModules: Module[]; manualChunkModulesByAlias: Record; - newEntryModules: ModuleWithAlias[]; + newEntryModules: Module[]; }> { const loadNewEntryModulesPromise = Promise.all( unresolvedEntryModules.map(this.loadEntryModule) - ).then(entryModulesWithAliases => { - for (const entryModuleWithAlias of entryModulesWithAliases) { - const existingEntryModuleWithAlias = this.entryModulesWithAliases.find( - ({ module: { id } }) => id === entryModuleWithAlias.module.id - ); - if (existingEntryModuleWithAlias) { - // TODO Lukas: Do not assign aliases here - // TODO Lukas: Introduce separate manual chunk alias variable - if (entryModuleWithAlias.alias) { - if (!existingEntryModuleWithAlias.alias) { - existingEntryModuleWithAlias.alias = entryModuleWithAlias.alias; - } else if (existingEntryModuleWithAlias.alias !== entryModuleWithAlias.alias) { - // TODO Lukas can this even happen? - error({ - code: 'DUPLICATE_ENTRY_POINTS', - message: `Duplicate entry points with different aliases detected. The input entries ${ - existingEntryModuleWithAlias.alias - } and ${entryModuleWithAlias.alias} both point to the same module, ${ - entryModuleWithAlias.module.id - }` - }); - } - } - } else { - this.entryModulesWithAliases.push(entryModuleWithAlias); + ).then(entryModules => { + for (const entryModule of entryModules) { + const existingEntryModule = this.entryModules.find(module => module.id === entryModule.id); + if (!existingEntryModule) { + this.entryModules.push(entryModule); } } - return entryModulesWithAliases; + return entryModules; }); return this.awaitLoadModulesPromise(loadNewEntryModulesPromise).then(newEntryModules => ({ - entryModulesWithAliases: this.entryModulesWithAliases, + entryModules: this.entryModules, manualChunkModulesByAlias: this.manualChunkModules, newEntryModules })); @@ -114,11 +89,11 @@ export class ModuleLoader { const loadNewManualChunkModulesPromise = Promise.all( unresolvedManualChunks.map(this.loadEntryModule) ).then(manualChunkModules => { - for (const { alias, module } of manualChunkModules) { - if (!this.manualChunkModules[alias]) { - this.manualChunkModules[alias] = []; + for (const module of manualChunkModules) { + if (!this.manualChunkModules[module.chunkAlias]) { + this.manualChunkModules[module.chunkAlias] = []; } - this.manualChunkModules[alias].push(module); + this.manualChunkModules[module.chunkAlias].push(module); } }); @@ -301,7 +276,7 @@ export class ModuleLoader { private loadEntryModule = ({ alias, unresolvedId - }: UnresolvedModuleWithAlias): Promise => { + }: UnresolvedModuleWithAlias): Promise => { return this.pluginDriver .hookFirst('resolveId', [unresolvedId, undefined]) .then(id => { @@ -319,10 +294,21 @@ export class ModuleLoader { }); } - return this.fetchModule(id, undefined).then(module => ({ - alias, - module - })); + // TODO Handle entry points as manual chunks? + return this.fetchModule(id, undefined).then(module => { + if (alias !== null) { + if (module.chunkAlias !== null) { + error({ + code: 'DUPLICATE_ENTRY_POINTS', + message: `Duplicate entry points with different aliases detected. The entries ${ + module.chunkAlias + } and ${alias} both point to the same module, ${module.id}` + }); + } + module.chunkAlias = alias; + } + return module; + }); }); }; diff --git a/src/utils/chunkColouring.ts b/src/utils/chunkColouring.ts index 73c07bd0e38..59c5a7d743c 100644 --- a/src/utils/chunkColouring.ts +++ b/src/utils/chunkColouring.ts @@ -14,8 +14,8 @@ export function assignChunkColouringHashes( const dynamicImports: Module[] = []; const addCurrentEntryColourToModule = (module: Module) => { - if (currentEntry.chunkAlias) { - module.chunkAlias = currentEntry.chunkAlias; + if (currentEntry.manualChunkAlias) { + module.manualChunkAlias = currentEntry.manualChunkAlias; module.entryPointsHash = currentEntryHash; } else { Uint8ArrayXor(module.entryPointsHash, currentEntryHash); @@ -29,7 +29,7 @@ export function assignChunkColouringHashes( continue; } modulesVisitedForCurrentEntry.add(dependency.id); - if (!handledEntryPoints.has(dependency.id) && !dependency.chunkAlias) + if (!handledEntryPoints.has(dependency.id) && !dependency.manualChunkAlias) addCurrentEntryColourToModule(dependency); } @@ -37,7 +37,7 @@ export function assignChunkColouringHashes( if ( resolution instanceof Module && resolution.dynamicallyImportedBy.length > 0 && - !resolution.chunkAlias + !resolution.manualChunkAlias ) { dynamicImports.push(resolution); } @@ -49,19 +49,19 @@ export function assignChunkColouringHashes( currentEntryHash = randomUint8Array(10); for (currentEntry of manualChunkModules[chunkName]) { - if (currentEntry.chunkAlias) { + if (currentEntry.manualChunkAlias) { error({ code: 'INVALID_CHUNK', message: `Cannot assign ${relative( process.cwd(), currentEntry.id )} to the "${chunkName}" chunk as it is already in the "${ - currentEntry.chunkAlias + currentEntry.manualChunkAlias }" chunk. Try defining "${chunkName}" first in the manualChunks definitions of the Rollup configuration.` }); } - currentEntry.chunkAlias = chunkName; + currentEntry.manualChunkAlias = chunkName; modulesVisitedForCurrentEntry = new Set(currentEntry.id); addCurrentEntryColourToModule(currentEntry); } diff --git a/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/generated-dynamic2.js b/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/generated-chunk.js similarity index 100% rename from test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/generated-dynamic2.js rename to test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/generated-chunk.js diff --git a/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/generated-dynamic3.js b/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/generated-chunk2.js similarity index 100% rename from test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/generated-dynamic3.js rename to test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/generated-chunk2.js diff --git a/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/main.js b/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/main.js index 3c9d3dbf487..3239719cf2e 100644 --- a/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/main.js +++ b/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/main.js @@ -1,6 +1,6 @@ define(['require', './generated-dynamic.js'], function (require, dynamic) { 'use strict'; - Promise.all([new Promise(function (resolve, reject) { require(['./generated-dynamic.js'], resolve, reject) }), new Promise(function (resolve, reject) { require(['./generated-dynamic2.js'], resolve, reject) }), new Promise(function (resolve, reject) { require(['./generated-dynamic3.js'], resolve, reject) })]).then( + Promise.all([new Promise(function (resolve, reject) { require(['./generated-dynamic.js'], resolve, reject) }), new Promise(function (resolve, reject) { require(['./generated-chunk.js'], resolve, reject) }), new Promise(function (resolve, reject) { require(['./generated-chunk2.js'], resolve, reject) })]).then( results => console.log(results, dynamic.DEP) ); diff --git a/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/cjs/generated-dynamic2.js b/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/cjs/generated-chunk.js similarity index 100% rename from test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/cjs/generated-dynamic2.js rename to test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/cjs/generated-chunk.js diff --git a/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/cjs/generated-dynamic3.js b/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/cjs/generated-chunk2.js similarity index 100% rename from test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/cjs/generated-dynamic3.js rename to test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/cjs/generated-chunk2.js diff --git a/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/cjs/main.js b/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/cjs/main.js index 529ca20e209..88d78ae23ed 100644 --- a/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/cjs/main.js +++ b/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/cjs/main.js @@ -2,6 +2,6 @@ var dynamic = require('./generated-dynamic.js'); -Promise.all([Promise.resolve(require('./generated-dynamic.js')), Promise.resolve(require('./generated-dynamic2.js')), Promise.resolve(require('./generated-dynamic3.js'))]).then( +Promise.all([Promise.resolve(require('./generated-dynamic.js')), Promise.resolve(require('./generated-chunk.js')), Promise.resolve(require('./generated-chunk2.js'))]).then( results => console.log(results, dynamic.DEP) ); diff --git a/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/es/generated-dynamic2.js b/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/es/generated-chunk.js similarity index 100% rename from test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/es/generated-dynamic2.js rename to test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/es/generated-chunk.js diff --git a/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/es/generated-dynamic3.js b/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/es/generated-chunk2.js similarity index 100% rename from test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/es/generated-dynamic3.js rename to test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/es/generated-chunk2.js diff --git a/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/es/main.js b/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/es/main.js index 4ed1bade3c1..f73645a1c0c 100644 --- a/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/es/main.js +++ b/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/es/main.js @@ -1,5 +1,5 @@ import { DEP } from './generated-dynamic.js'; -Promise.all([import('./generated-dynamic.js'), import('./generated-dynamic2.js'), import('./generated-dynamic3.js')]).then( +Promise.all([import('./generated-dynamic.js'), import('./generated-chunk.js'), import('./generated-chunk2.js')]).then( results => console.log(results, DEP) ); diff --git a/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/system/generated-dynamic2.js b/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/system/generated-chunk.js similarity index 100% rename from test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/system/generated-dynamic2.js rename to test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/system/generated-chunk.js diff --git a/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/system/generated-dynamic3.js b/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/system/generated-chunk2.js similarity index 100% rename from test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/system/generated-dynamic3.js rename to test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/system/generated-chunk2.js diff --git a/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/system/main.js b/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/system/main.js index 3b527719e90..38a54ddc18f 100644 --- a/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/system/main.js +++ b/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/system/main.js @@ -7,7 +7,7 @@ System.register(['./generated-dynamic.js'], function (exports, module) { }], execute: function () { - Promise.all([module.import('./generated-dynamic.js'), module.import('./generated-dynamic2.js'), module.import('./generated-dynamic3.js')]).then( + Promise.all([module.import('./generated-dynamic.js'), module.import('./generated-chunk.js'), module.import('./generated-chunk2.js')]).then( results => console.log(results, DEP) ); From 98296c3e3797d5c565f01b5ac9e18f0befea8b3e Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Mon, 15 Apr 2019 06:43:40 +0200 Subject: [PATCH 20/60] * Allow manual chunks to contain nested entry points * Allow manual chunks to contain entry points without name or with the same name * Throw if an emitted chunk is not found * Throw if there is a conflict between manual chunk entries * Allow nesting of manual chunks without requiring a specific order --- src/Graph.ts | 198 +++++++++--------- src/ModuleLoader.ts | 23 +- src/utils/chunkColouring.ts | 22 +- src/utils/errors.ts | 19 ++ .../_config.js | 0 .../_expected/amd/buildStart.js | 0 .../_expected/amd/generated-chunk.js | 0 .../_expected/amd/main.js | 0 .../_expected/cjs/buildStart.js | 0 .../_expected/cjs/generated-chunk.js | 0 .../_expected/cjs/main.js | 0 .../_expected/es/buildStart.js | 0 .../_expected/es/generated-chunk.js | 0 .../_expected/es/main.js | 0 .../_expected/system/buildStart.js | 0 .../_expected/system/generated-chunk.js | 0 .../_expected/system/main.js | 0 .../buildStart.js | 0 .../dep.js | 0 .../{add-entry => emit-entry-chunk}/main.js | 0 .../_config.js | 1 - .../_expected/amd/dep.js | 0 .../_expected/amd/first-main.js | 0 .../_expected/amd/second-main.js | 0 .../_expected/cjs/dep.js | 0 .../_expected/cjs/first-main.js | 0 .../_expected/cjs/second-main.js | 0 .../_expected/es/dep.js | 0 .../_expected/es/first-main.js | 0 .../_expected/es/second-main.js | 0 .../_expected/system/dep.js | 0 .../_expected/system/first-main.js | 0 .../_expected/system/second-main.js | 0 .../{add-entry => emit-entry-existing}/dep.js | 0 .../main1.js | 0 .../main2.js | 0 .../_config.js | 0 .../_expected/amd/chunks/chunk.js | 0 .../_expected/amd/main.js | 0 .../_expected/amd/worker.js | 0 .../_expected/cjs/chunks/chunk.js | 0 .../_expected/cjs/main.js | 0 .../_expected/cjs/worker.js | 0 .../_expected/es/chunks/chunk.js | 0 .../_expected/es/main.js | 0 .../_expected/es/worker.js | 0 .../_expected/system/chunks/chunk.js | 0 .../_expected/system/main.js | 0 .../_expected/system/worker.js | 0 .../index-amd.html | 0 .../index-es.html | 0 .../index-system.html | 0 .../main.js | 0 .../worker.js | 0 .../samples/manual-chunk-input/_config.js | 12 ++ .../manual-chunk-input/_expected/amd/main.js | 7 + .../manual-chunk-input/_expected/amd/other.js | 5 + .../manual-chunk-input/_expected/cjs/main.js | 5 + .../manual-chunk-input/_expected/cjs/other.js | 5 + .../manual-chunk-input/_expected/es/main.js | 3 + .../manual-chunk-input/_expected/es/other.js | 3 + .../_expected/system/main.js | 12 ++ .../_expected/system/other.js | 11 + .../samples/manual-chunk-input/dep.js | 1 + .../samples/manual-chunk-input/main1.js | 3 + .../samples/manual-chunk-input/main2.js | 3 + .../samples/manual-chunks-nested/_config.js | 9 + .../_expected/amd/generated-manual.js | 9 + .../_expected/amd/main.js | 5 + .../_expected/cjs/generated-manual.js | 7 + .../_expected/cjs/main.js | 5 + .../_expected/es/generated-manual.js | 5 + .../manual-chunks-nested/_expected/es/main.js | 3 + .../_expected/system/generated-manual.js | 14 ++ .../_expected/system/main.js | 11 + .../samples/manual-chunks-nested/inner.js | 1 + .../samples/manual-chunks-nested/main.js | 3 + .../samples/manual-chunks-nested/middle.js | 3 + .../samples/manual-chunks-nested/outer.js | 3 + .../emit-entry-chunk-not-found/_config.js | 15 ++ .../emit-entry-chunk-not-found/main.js | 1 + .../manual-chunk-input-conflict/_config.js | 17 ++ .../manual-chunk-input-conflict/dep.js | 1 + .../manual-chunk-input-conflict/main.js | 1 + .../samples/manual-chunks-conflict/_config.js | 14 ++ .../samples/manual-chunks-conflict/dep.js | 1 + .../samples/manual-chunks-conflict/main.js | 1 + .../samples/manual-chunks-invalid/_config.js | 14 -- .../samples/manual-chunks-invalid/dep1.js | 1 - .../samples/manual-chunks-invalid/dep2.js | 1 - .../samples/manual-chunks-invalid/main.js | 1 - 91 files changed, 333 insertions(+), 146 deletions(-) create mode 100644 src/utils/errors.ts rename test/chunking-form/samples/{add-entry => emit-entry-chunk}/_config.js (100%) rename test/chunking-form/samples/{add-entry => emit-entry-chunk}/_expected/amd/buildStart.js (100%) rename test/chunking-form/samples/{add-entry => emit-entry-chunk}/_expected/amd/generated-chunk.js (100%) rename test/chunking-form/samples/{add-entry => emit-entry-chunk}/_expected/amd/main.js (100%) rename test/chunking-form/samples/{add-entry => emit-entry-chunk}/_expected/cjs/buildStart.js (100%) rename test/chunking-form/samples/{add-entry => emit-entry-chunk}/_expected/cjs/generated-chunk.js (100%) rename test/chunking-form/samples/{add-entry => emit-entry-chunk}/_expected/cjs/main.js (100%) rename test/chunking-form/samples/{add-entry => emit-entry-chunk}/_expected/es/buildStart.js (100%) rename test/chunking-form/samples/{add-entry => emit-entry-chunk}/_expected/es/generated-chunk.js (100%) rename test/chunking-form/samples/{add-entry => emit-entry-chunk}/_expected/es/main.js (100%) rename test/chunking-form/samples/{add-entry => emit-entry-chunk}/_expected/system/buildStart.js (100%) rename test/chunking-form/samples/{add-entry => emit-entry-chunk}/_expected/system/generated-chunk.js (100%) rename test/chunking-form/samples/{add-entry => emit-entry-chunk}/_expected/system/main.js (100%) rename test/chunking-form/samples/{add-entry => emit-entry-chunk}/buildStart.js (100%) rename test/chunking-form/samples/{add-entry-existing => emit-entry-chunk}/dep.js (100%) rename test/chunking-form/samples/{add-entry => emit-entry-chunk}/main.js (100%) rename test/chunking-form/samples/{add-entry-existing => emit-entry-existing}/_config.js (88%) rename test/chunking-form/samples/{add-entry-existing => emit-entry-existing}/_expected/amd/dep.js (100%) rename test/chunking-form/samples/{add-entry-existing => emit-entry-existing}/_expected/amd/first-main.js (100%) rename test/chunking-form/samples/{add-entry-existing => emit-entry-existing}/_expected/amd/second-main.js (100%) rename test/chunking-form/samples/{add-entry-existing => emit-entry-existing}/_expected/cjs/dep.js (100%) rename test/chunking-form/samples/{add-entry-existing => emit-entry-existing}/_expected/cjs/first-main.js (100%) rename test/chunking-form/samples/{add-entry-existing => emit-entry-existing}/_expected/cjs/second-main.js (100%) rename test/chunking-form/samples/{add-entry-existing => emit-entry-existing}/_expected/es/dep.js (100%) rename test/chunking-form/samples/{add-entry-existing => emit-entry-existing}/_expected/es/first-main.js (100%) rename test/chunking-form/samples/{add-entry-existing => emit-entry-existing}/_expected/es/second-main.js (100%) rename test/chunking-form/samples/{add-entry-existing => emit-entry-existing}/_expected/system/dep.js (100%) rename test/chunking-form/samples/{add-entry-existing => emit-entry-existing}/_expected/system/first-main.js (100%) rename test/chunking-form/samples/{add-entry-existing => emit-entry-existing}/_expected/system/second-main.js (100%) rename test/chunking-form/samples/{add-entry => emit-entry-existing}/dep.js (100%) rename test/chunking-form/samples/{add-entry-existing => emit-entry-existing}/main1.js (100%) rename test/chunking-form/samples/{add-entry-existing => emit-entry-existing}/main2.js (100%) rename test/chunking-form/samples/{add-entry-worker => emit-entry-worker}/_config.js (100%) rename test/chunking-form/samples/{add-entry-worker => emit-entry-worker}/_expected/amd/chunks/chunk.js (100%) rename test/chunking-form/samples/{add-entry-worker => emit-entry-worker}/_expected/amd/main.js (100%) rename test/chunking-form/samples/{add-entry-worker => emit-entry-worker}/_expected/amd/worker.js (100%) rename test/chunking-form/samples/{add-entry-worker => emit-entry-worker}/_expected/cjs/chunks/chunk.js (100%) rename test/chunking-form/samples/{add-entry-worker => emit-entry-worker}/_expected/cjs/main.js (100%) rename test/chunking-form/samples/{add-entry-worker => emit-entry-worker}/_expected/cjs/worker.js (100%) rename test/chunking-form/samples/{add-entry-worker => emit-entry-worker}/_expected/es/chunks/chunk.js (100%) rename test/chunking-form/samples/{add-entry-worker => emit-entry-worker}/_expected/es/main.js (100%) rename test/chunking-form/samples/{add-entry-worker => emit-entry-worker}/_expected/es/worker.js (100%) rename test/chunking-form/samples/{add-entry-worker => emit-entry-worker}/_expected/system/chunks/chunk.js (100%) rename test/chunking-form/samples/{add-entry-worker => emit-entry-worker}/_expected/system/main.js (100%) rename test/chunking-form/samples/{add-entry-worker => emit-entry-worker}/_expected/system/worker.js (100%) rename test/chunking-form/samples/{add-entry-worker => emit-entry-worker}/index-amd.html (100%) rename test/chunking-form/samples/{add-entry-worker => emit-entry-worker}/index-es.html (100%) rename test/chunking-form/samples/{add-entry-worker => emit-entry-worker}/index-system.html (100%) rename test/chunking-form/samples/{add-entry-worker => emit-entry-worker}/main.js (100%) rename test/chunking-form/samples/{add-entry-worker => emit-entry-worker}/worker.js (100%) create mode 100644 test/chunking-form/samples/manual-chunk-input/_config.js create mode 100644 test/chunking-form/samples/manual-chunk-input/_expected/amd/main.js create mode 100644 test/chunking-form/samples/manual-chunk-input/_expected/amd/other.js create mode 100644 test/chunking-form/samples/manual-chunk-input/_expected/cjs/main.js create mode 100644 test/chunking-form/samples/manual-chunk-input/_expected/cjs/other.js create mode 100644 test/chunking-form/samples/manual-chunk-input/_expected/es/main.js create mode 100644 test/chunking-form/samples/manual-chunk-input/_expected/es/other.js create mode 100644 test/chunking-form/samples/manual-chunk-input/_expected/system/main.js create mode 100644 test/chunking-form/samples/manual-chunk-input/_expected/system/other.js create mode 100644 test/chunking-form/samples/manual-chunk-input/dep.js create mode 100644 test/chunking-form/samples/manual-chunk-input/main1.js create mode 100644 test/chunking-form/samples/manual-chunk-input/main2.js create mode 100644 test/chunking-form/samples/manual-chunks-nested/_config.js create mode 100644 test/chunking-form/samples/manual-chunks-nested/_expected/amd/generated-manual.js create mode 100644 test/chunking-form/samples/manual-chunks-nested/_expected/amd/main.js create mode 100644 test/chunking-form/samples/manual-chunks-nested/_expected/cjs/generated-manual.js create mode 100644 test/chunking-form/samples/manual-chunks-nested/_expected/cjs/main.js create mode 100644 test/chunking-form/samples/manual-chunks-nested/_expected/es/generated-manual.js create mode 100644 test/chunking-form/samples/manual-chunks-nested/_expected/es/main.js create mode 100644 test/chunking-form/samples/manual-chunks-nested/_expected/system/generated-manual.js create mode 100644 test/chunking-form/samples/manual-chunks-nested/_expected/system/main.js create mode 100644 test/chunking-form/samples/manual-chunks-nested/inner.js create mode 100644 test/chunking-form/samples/manual-chunks-nested/main.js create mode 100644 test/chunking-form/samples/manual-chunks-nested/middle.js create mode 100644 test/chunking-form/samples/manual-chunks-nested/outer.js create mode 100644 test/function/samples/emit-entry-chunk-not-found/_config.js create mode 100644 test/function/samples/emit-entry-chunk-not-found/main.js create mode 100644 test/function/samples/manual-chunk-input-conflict/_config.js create mode 100644 test/function/samples/manual-chunk-input-conflict/dep.js create mode 100644 test/function/samples/manual-chunk-input-conflict/main.js create mode 100644 test/function/samples/manual-chunks-conflict/_config.js create mode 100644 test/function/samples/manual-chunks-conflict/dep.js create mode 100644 test/function/samples/manual-chunks-conflict/main.js delete mode 100644 test/function/samples/manual-chunks-invalid/_config.js delete mode 100644 test/function/samples/manual-chunks-invalid/dep1.js delete mode 100644 test/function/samples/manual-chunks-invalid/dep2.js delete mode 100644 test/function/samples/manual-chunks-invalid/main.js diff --git a/src/Graph.ts b/src/Graph.ts index 08b797baa8a..df88b1fa440 100644 --- a/src/Graph.ts +++ b/src/Graph.ts @@ -219,133 +219,131 @@ export default class Graph { timeStart('parse modules', 2); - if (manualChunks) { - this.moduleLoader.addManualChunks(manualChunks); - } - return this.moduleLoader - .addEntryModules(normalizeEntryModules(entryModules)) - .then(({ entryModules, manualChunkModulesByAlias }) => { - for (const entryModule of entryModules) { - if (entryModule.chunkAlias === null) { - entryModule.chunkAlias = getAliasName(entryModule.id); - } + return Promise.all([ + this.moduleLoader.addEntryModules(normalizeEntryModules(entryModules)), + manualChunks && this.moduleLoader.addManualChunks(manualChunks) + ]).then(([{ entryModules, manualChunkModulesByAlias }]) => { + for (const entryModule of entryModules) { + if (entryModule.chunkAlias === null) { + entryModule.chunkAlias = getAliasName(entryModule.id); } - for (const module of Array.from(this.moduleById.values())) { - if (module instanceof Module) { - this.modules.push(module); - this.watchFiles[module.id] = true; - } else { - this.externalModules.push(module); - } + } + for (const module of Array.from(this.moduleById.values())) { + if (module instanceof Module) { + this.modules.push(module); + this.watchFiles[module.id] = true; + } else { + this.externalModules.push(module); } - timeEnd('parse modules', 2); + } + timeEnd('parse modules', 2); - // Phase 2 - linking. We populate the module dependency links and - // determine the topological execution order for the bundle - timeStart('analyse dependency graph', 2); + // Phase 2 - linking. We populate the module dependency links and + // determine the topological execution order for the bundle + timeStart('analyse dependency graph', 2); - this.link(entryModules); + this.link(entryModules); - timeEnd('analyse dependency graph', 2); + timeEnd('analyse dependency graph', 2); - // Phase 3 – marking. We include all statements that should be included - timeStart('mark included statements', 2); + // Phase 3 – marking. We include all statements that should be included + timeStart('mark included statements', 2); - if (inlineDynamicImports) { - if (entryModules.length > 1) { - throw new Error( - 'Internal Error: can only inline dynamic imports for single-file builds.' - ); - } - } - for (const module of entryModules) { - module.includeAllExports(); + if (inlineDynamicImports) { + if (entryModules.length > 1) { + throw new Error( + 'Internal Error: can only inline dynamic imports for single-file builds.' + ); } - this.includeMarked(this.modules); + } + for (const module of entryModules) { + module.includeAllExports(); + } + this.includeMarked(this.modules); - // check for unused external imports - for (const externalModule of this.externalModules) externalModule.warnUnusedImports(); + // check for unused external imports + for (const externalModule of this.externalModules) externalModule.warnUnusedImports(); - timeEnd('mark included statements', 2); + timeEnd('mark included statements', 2); - // Phase 4 – we construct the chunks, working out the optimal chunking using - // entry point graph colouring, before generating the import and export facades - timeStart('generate chunks', 2); + // Phase 4 – we construct the chunks, working out the optimal chunking using + // entry point graph colouring, before generating the import and export facades + timeStart('generate chunks', 2); - if (!this.preserveModules && !inlineDynamicImports) { - assignChunkColouringHashes(entryModules, manualChunkModulesByAlias); - } + if (!this.preserveModules && !inlineDynamicImports) { + assignChunkColouringHashes(entryModules, manualChunkModulesByAlias); + } - // TODO: there is one special edge case unhandled here and that is that any module - // exposed as an unresolvable export * (to a graph external export *, - // either as a namespace import reexported or top-level export *) - // should be made to be its own entry point module before chunking - let chunks: Chunk[] = []; - if (this.preserveModules) { - for (const module of this.modules) { - const chunk = new Chunk(this, [module]); - if (module.isEntryPoint || !chunk.isEmpty) { - chunk.entryModules = [module]; - } - chunks.push(chunk); + // TODO: there is one special edge case unhandled here and that is that any module + // exposed as an unresolvable export * (to a graph external export *, + // either as a namespace import reexported or top-level export *) + // should be made to be its own entry point module before chunking + let chunks: Chunk[] = []; + if (this.preserveModules) { + for (const module of this.modules) { + const chunk = new Chunk(this, [module]); + if (module.isEntryPoint || !chunk.isEmpty) { + chunk.entryModules = [module]; } - } else { - const chunkModules: { [entryHashSum: string]: Module[] } = {}; - for (const module of this.modules) { - const entryPointsHashStr = Uint8ArrayToHexString(module.entryPointsHash); - const curChunk = chunkModules[entryPointsHashStr]; - if (curChunk) { - curChunk.push(module); - } else { - chunkModules[entryPointsHashStr] = [module]; - } - } - - for (const entryHashSum in chunkModules) { - const chunkModulesOrdered = chunkModules[entryHashSum]; - sortByExecutionOrder(chunkModulesOrdered); - const chunk = new Chunk(this, chunkModulesOrdered); - chunks.push(chunk); + chunks.push(chunk); + } + } else { + const chunkModules: { [entryHashSum: string]: Module[] } = {}; + for (const module of this.modules) { + const entryPointsHashStr = Uint8ArrayToHexString(module.entryPointsHash); + const curChunk = chunkModules[entryPointsHashStr]; + if (curChunk) { + curChunk.push(module); + } else { + chunkModules[entryPointsHashStr] = [module]; } } - // for each chunk module, set up its imports to other - // chunks, if those variables are included after treeshaking - for (const chunk of chunks) { - chunk.link(); + for (const entryHashSum in chunkModules) { + const chunkModulesOrdered = chunkModules[entryHashSum]; + sortByExecutionOrder(chunkModulesOrdered); + const chunk = new Chunk(this, chunkModulesOrdered); + chunks.push(chunk); } + } + + // for each chunk module, set up its imports to other + // chunks, if those variables are included after treeshaking + for (const chunk of chunks) { + chunk.link(); + } - // filter out empty dependencies - chunks = chunks.filter( - chunk => !chunk.isEmpty || chunk.entryModules.length > 0 || chunk.isManualChunk - ); + // filter out empty dependencies + chunks = chunks.filter( + chunk => !chunk.isEmpty || chunk.entryModules.length > 0 || chunk.isManualChunk + ); - // then go over and ensure all entry chunks export their variables - for (const chunk of chunks) { - if (this.preserveModules || chunk.entryModules.length > 0) { - chunk.generateEntryExportsOrMarkAsTainted(); - } + // then go over and ensure all entry chunks export their variables + for (const chunk of chunks) { + if (this.preserveModules || chunk.entryModules.length > 0) { + chunk.generateEntryExportsOrMarkAsTainted(); } + } - // create entry point facades for entry module chunks that have tainted exports - const facades = []; - if (!this.preserveModules) { - for (const chunk of chunks) { - for (const entryModule of chunk.entryModules) { - if (chunk.facadeModule !== entryModule) { - const entryPointFacade = new Chunk(this, []); - entryPointFacade.turnIntoFacade(entryModule); - facades.push(entryPointFacade); - } + // create entry point facades for entry module chunks that have tainted exports + const facades = []; + if (!this.preserveModules) { + for (const chunk of chunks) { + for (const entryModule of chunk.entryModules) { + if (chunk.facadeModule !== entryModule) { + const entryPointFacade = new Chunk(this, []); + entryPointFacade.turnIntoFacade(entryModule); + facades.push(entryPointFacade); } } } + } - timeEnd('generate chunks', 2); + timeEnd('generate chunks', 2); - this.finished = true; - return chunks.concat(facades); - }); + this.finished = true; + return chunks.concat(facades); + }); } finaliseAssets(assetFileNames: string) { diff --git a/src/ModuleLoader.ts b/src/ModuleLoader.ts index 4afeaee948b..b0c1cb366ef 100644 --- a/src/ModuleLoader.ts +++ b/src/ModuleLoader.ts @@ -3,6 +3,7 @@ import Graph from './Graph'; import Module from './Module'; import { ModuleJSON, ResolvedId, ResolveIdResult, SourceDescription } from './rollup/types'; import { error } from './utils/error'; +import { errorCannotAssignModuleToChunk } from './utils/errors'; import { addWithNewMetaId } from './utils/metaIds'; import { isRelative, resolve } from './utils/path'; import { PluginDriver } from './utils/pluginDriver'; @@ -46,9 +47,14 @@ export class ModuleLoader { this.entriesByMetaId, unresolvedEntryModule.unresolvedId ); - this.addEntryModules([unresolvedEntryModule]).then(({ newEntryModules: [module] }) => { - entryRecord.module = module; - }); + this.addEntryModules([unresolvedEntryModule]) + .then(({ newEntryModules: [module] }) => { + entryRecord.module = module; + }) + .catch(() => { + // Avoid unhandled Promise rejection as the error will be thrown later + // once module loading has finished + }); return metaId; } @@ -94,6 +100,7 @@ export class ModuleLoader { this.manualChunkModules[module.chunkAlias] = []; } this.manualChunkModules[module.chunkAlias].push(module); + module.manualChunkAlias = module.chunkAlias; } }); @@ -294,16 +301,10 @@ export class ModuleLoader { }); } - // TODO Handle entry points as manual chunks? return this.fetchModule(id, undefined).then(module => { if (alias !== null) { - if (module.chunkAlias !== null) { - error({ - code: 'DUPLICATE_ENTRY_POINTS', - message: `Duplicate entry points with different aliases detected. The entries ${ - module.chunkAlias - } and ${alias} both point to the same module, ${module.id}` - }); + if (module.chunkAlias !== null && module.chunkAlias !== alias) { + errorCannotAssignModuleToChunk(module.id, alias, module.chunkAlias); } module.chunkAlias = alias; } diff --git a/src/utils/chunkColouring.ts b/src/utils/chunkColouring.ts index 59c5a7d743c..3c8efadefb0 100644 --- a/src/utils/chunkColouring.ts +++ b/src/utils/chunkColouring.ts @@ -1,8 +1,6 @@ import ExternalModule from '../ExternalModule'; import Module from '../Module'; import { randomUint8Array, Uint8ArrayXor } from './entryHashing'; -import { error } from './error'; -import { relative } from './path'; export function assignChunkColouringHashes( entryModules: Module[], @@ -29,8 +27,9 @@ export function assignChunkColouringHashes( continue; } modulesVisitedForCurrentEntry.add(dependency.id); - if (!handledEntryPoints.has(dependency.id) && !dependency.manualChunkAlias) + if (!handledEntryPoints.has(dependency.id) && !dependency.manualChunkAlias) { addCurrentEntryColourToModule(dependency); + } } for (const { resolution } of module.dynamicImports) { @@ -49,19 +48,6 @@ export function assignChunkColouringHashes( currentEntryHash = randomUint8Array(10); for (currentEntry of manualChunkModules[chunkName]) { - if (currentEntry.manualChunkAlias) { - error({ - code: 'INVALID_CHUNK', - message: `Cannot assign ${relative( - process.cwd(), - currentEntry.id - )} to the "${chunkName}" chunk as it is already in the "${ - currentEntry.manualChunkAlias - }" chunk. -Try defining "${chunkName}" first in the manualChunks definitions of the Rollup configuration.` - }); - } - currentEntry.manualChunkAlias = chunkName; modulesVisitedForCurrentEntry = new Set(currentEntry.id); addCurrentEntryColourToModule(currentEntry); } @@ -72,7 +58,9 @@ Try defining "${chunkName}" first in the manualChunks definitions of the Rollup handledEntryPoints.add(currentEntry.id); currentEntryHash = randomUint8Array(10); modulesVisitedForCurrentEntry = new Set(currentEntry.id); - addCurrentEntryColourToModule(currentEntry); + if (!currentEntry.manualChunkAlias) { + addCurrentEntryColourToModule(currentEntry); + } } for (currentEntry of dynamicImports) { diff --git a/src/utils/errors.ts b/src/utils/errors.ts new file mode 100644 index 00000000000..95e003999a8 --- /dev/null +++ b/src/utils/errors.ts @@ -0,0 +1,19 @@ +import { error } from './error'; +import { relative } from './path'; + +// TODO Lukas polyfill process.cwd() +// TODO Lukas error constant enum +// TODO Lukas other errors +export function errorCannotAssignModuleToChunk( + moduleId: string, + assignToAlias: string, + currentAlias: string +) { + error({ + code: 'INVALID_CHUNK', + message: `Cannot assign ${relative( + process.cwd(), + moduleId + )} to the "${assignToAlias}" chunk as it is already in the "${currentAlias}" chunk.` + }); +} diff --git a/test/chunking-form/samples/add-entry/_config.js b/test/chunking-form/samples/emit-entry-chunk/_config.js similarity index 100% rename from test/chunking-form/samples/add-entry/_config.js rename to test/chunking-form/samples/emit-entry-chunk/_config.js diff --git a/test/chunking-form/samples/add-entry/_expected/amd/buildStart.js b/test/chunking-form/samples/emit-entry-chunk/_expected/amd/buildStart.js similarity index 100% rename from test/chunking-form/samples/add-entry/_expected/amd/buildStart.js rename to test/chunking-form/samples/emit-entry-chunk/_expected/amd/buildStart.js diff --git a/test/chunking-form/samples/add-entry/_expected/amd/generated-chunk.js b/test/chunking-form/samples/emit-entry-chunk/_expected/amd/generated-chunk.js similarity index 100% rename from test/chunking-form/samples/add-entry/_expected/amd/generated-chunk.js rename to test/chunking-form/samples/emit-entry-chunk/_expected/amd/generated-chunk.js diff --git a/test/chunking-form/samples/add-entry/_expected/amd/main.js b/test/chunking-form/samples/emit-entry-chunk/_expected/amd/main.js similarity index 100% rename from test/chunking-form/samples/add-entry/_expected/amd/main.js rename to test/chunking-form/samples/emit-entry-chunk/_expected/amd/main.js diff --git a/test/chunking-form/samples/add-entry/_expected/cjs/buildStart.js b/test/chunking-form/samples/emit-entry-chunk/_expected/cjs/buildStart.js similarity index 100% rename from test/chunking-form/samples/add-entry/_expected/cjs/buildStart.js rename to test/chunking-form/samples/emit-entry-chunk/_expected/cjs/buildStart.js diff --git a/test/chunking-form/samples/add-entry/_expected/cjs/generated-chunk.js b/test/chunking-form/samples/emit-entry-chunk/_expected/cjs/generated-chunk.js similarity index 100% rename from test/chunking-form/samples/add-entry/_expected/cjs/generated-chunk.js rename to test/chunking-form/samples/emit-entry-chunk/_expected/cjs/generated-chunk.js diff --git a/test/chunking-form/samples/add-entry/_expected/cjs/main.js b/test/chunking-form/samples/emit-entry-chunk/_expected/cjs/main.js similarity index 100% rename from test/chunking-form/samples/add-entry/_expected/cjs/main.js rename to test/chunking-form/samples/emit-entry-chunk/_expected/cjs/main.js diff --git a/test/chunking-form/samples/add-entry/_expected/es/buildStart.js b/test/chunking-form/samples/emit-entry-chunk/_expected/es/buildStart.js similarity index 100% rename from test/chunking-form/samples/add-entry/_expected/es/buildStart.js rename to test/chunking-form/samples/emit-entry-chunk/_expected/es/buildStart.js diff --git a/test/chunking-form/samples/add-entry/_expected/es/generated-chunk.js b/test/chunking-form/samples/emit-entry-chunk/_expected/es/generated-chunk.js similarity index 100% rename from test/chunking-form/samples/add-entry/_expected/es/generated-chunk.js rename to test/chunking-form/samples/emit-entry-chunk/_expected/es/generated-chunk.js diff --git a/test/chunking-form/samples/add-entry/_expected/es/main.js b/test/chunking-form/samples/emit-entry-chunk/_expected/es/main.js similarity index 100% rename from test/chunking-form/samples/add-entry/_expected/es/main.js rename to test/chunking-form/samples/emit-entry-chunk/_expected/es/main.js diff --git a/test/chunking-form/samples/add-entry/_expected/system/buildStart.js b/test/chunking-form/samples/emit-entry-chunk/_expected/system/buildStart.js similarity index 100% rename from test/chunking-form/samples/add-entry/_expected/system/buildStart.js rename to test/chunking-form/samples/emit-entry-chunk/_expected/system/buildStart.js diff --git a/test/chunking-form/samples/add-entry/_expected/system/generated-chunk.js b/test/chunking-form/samples/emit-entry-chunk/_expected/system/generated-chunk.js similarity index 100% rename from test/chunking-form/samples/add-entry/_expected/system/generated-chunk.js rename to test/chunking-form/samples/emit-entry-chunk/_expected/system/generated-chunk.js diff --git a/test/chunking-form/samples/add-entry/_expected/system/main.js b/test/chunking-form/samples/emit-entry-chunk/_expected/system/main.js similarity index 100% rename from test/chunking-form/samples/add-entry/_expected/system/main.js rename to test/chunking-form/samples/emit-entry-chunk/_expected/system/main.js diff --git a/test/chunking-form/samples/add-entry/buildStart.js b/test/chunking-form/samples/emit-entry-chunk/buildStart.js similarity index 100% rename from test/chunking-form/samples/add-entry/buildStart.js rename to test/chunking-form/samples/emit-entry-chunk/buildStart.js diff --git a/test/chunking-form/samples/add-entry-existing/dep.js b/test/chunking-form/samples/emit-entry-chunk/dep.js similarity index 100% rename from test/chunking-form/samples/add-entry-existing/dep.js rename to test/chunking-form/samples/emit-entry-chunk/dep.js diff --git a/test/chunking-form/samples/add-entry/main.js b/test/chunking-form/samples/emit-entry-chunk/main.js similarity index 100% rename from test/chunking-form/samples/add-entry/main.js rename to test/chunking-form/samples/emit-entry-chunk/main.js diff --git a/test/chunking-form/samples/add-entry-existing/_config.js b/test/chunking-form/samples/emit-entry-existing/_config.js similarity index 88% rename from test/chunking-form/samples/add-entry-existing/_config.js rename to test/chunking-form/samples/emit-entry-existing/_config.js index d9a3b8d229c..b1bdaa36ef9 100644 --- a/test/chunking-form/samples/add-entry-existing/_config.js +++ b/test/chunking-form/samples/emit-entry-existing/_config.js @@ -1,4 +1,3 @@ -// TODO Lukas entry not found -> unhandled Promise rejection? module.exports = { description: 'allows adding modules already in the graph as entry points', options: { diff --git a/test/chunking-form/samples/add-entry-existing/_expected/amd/dep.js b/test/chunking-form/samples/emit-entry-existing/_expected/amd/dep.js similarity index 100% rename from test/chunking-form/samples/add-entry-existing/_expected/amd/dep.js rename to test/chunking-form/samples/emit-entry-existing/_expected/amd/dep.js diff --git a/test/chunking-form/samples/add-entry-existing/_expected/amd/first-main.js b/test/chunking-form/samples/emit-entry-existing/_expected/amd/first-main.js similarity index 100% rename from test/chunking-form/samples/add-entry-existing/_expected/amd/first-main.js rename to test/chunking-form/samples/emit-entry-existing/_expected/amd/first-main.js diff --git a/test/chunking-form/samples/add-entry-existing/_expected/amd/second-main.js b/test/chunking-form/samples/emit-entry-existing/_expected/amd/second-main.js similarity index 100% rename from test/chunking-form/samples/add-entry-existing/_expected/amd/second-main.js rename to test/chunking-form/samples/emit-entry-existing/_expected/amd/second-main.js diff --git a/test/chunking-form/samples/add-entry-existing/_expected/cjs/dep.js b/test/chunking-form/samples/emit-entry-existing/_expected/cjs/dep.js similarity index 100% rename from test/chunking-form/samples/add-entry-existing/_expected/cjs/dep.js rename to test/chunking-form/samples/emit-entry-existing/_expected/cjs/dep.js diff --git a/test/chunking-form/samples/add-entry-existing/_expected/cjs/first-main.js b/test/chunking-form/samples/emit-entry-existing/_expected/cjs/first-main.js similarity index 100% rename from test/chunking-form/samples/add-entry-existing/_expected/cjs/first-main.js rename to test/chunking-form/samples/emit-entry-existing/_expected/cjs/first-main.js diff --git a/test/chunking-form/samples/add-entry-existing/_expected/cjs/second-main.js b/test/chunking-form/samples/emit-entry-existing/_expected/cjs/second-main.js similarity index 100% rename from test/chunking-form/samples/add-entry-existing/_expected/cjs/second-main.js rename to test/chunking-form/samples/emit-entry-existing/_expected/cjs/second-main.js diff --git a/test/chunking-form/samples/add-entry-existing/_expected/es/dep.js b/test/chunking-form/samples/emit-entry-existing/_expected/es/dep.js similarity index 100% rename from test/chunking-form/samples/add-entry-existing/_expected/es/dep.js rename to test/chunking-form/samples/emit-entry-existing/_expected/es/dep.js diff --git a/test/chunking-form/samples/add-entry-existing/_expected/es/first-main.js b/test/chunking-form/samples/emit-entry-existing/_expected/es/first-main.js similarity index 100% rename from test/chunking-form/samples/add-entry-existing/_expected/es/first-main.js rename to test/chunking-form/samples/emit-entry-existing/_expected/es/first-main.js diff --git a/test/chunking-form/samples/add-entry-existing/_expected/es/second-main.js b/test/chunking-form/samples/emit-entry-existing/_expected/es/second-main.js similarity index 100% rename from test/chunking-form/samples/add-entry-existing/_expected/es/second-main.js rename to test/chunking-form/samples/emit-entry-existing/_expected/es/second-main.js diff --git a/test/chunking-form/samples/add-entry-existing/_expected/system/dep.js b/test/chunking-form/samples/emit-entry-existing/_expected/system/dep.js similarity index 100% rename from test/chunking-form/samples/add-entry-existing/_expected/system/dep.js rename to test/chunking-form/samples/emit-entry-existing/_expected/system/dep.js diff --git a/test/chunking-form/samples/add-entry-existing/_expected/system/first-main.js b/test/chunking-form/samples/emit-entry-existing/_expected/system/first-main.js similarity index 100% rename from test/chunking-form/samples/add-entry-existing/_expected/system/first-main.js rename to test/chunking-form/samples/emit-entry-existing/_expected/system/first-main.js diff --git a/test/chunking-form/samples/add-entry-existing/_expected/system/second-main.js b/test/chunking-form/samples/emit-entry-existing/_expected/system/second-main.js similarity index 100% rename from test/chunking-form/samples/add-entry-existing/_expected/system/second-main.js rename to test/chunking-form/samples/emit-entry-existing/_expected/system/second-main.js diff --git a/test/chunking-form/samples/add-entry/dep.js b/test/chunking-form/samples/emit-entry-existing/dep.js similarity index 100% rename from test/chunking-form/samples/add-entry/dep.js rename to test/chunking-form/samples/emit-entry-existing/dep.js diff --git a/test/chunking-form/samples/add-entry-existing/main1.js b/test/chunking-form/samples/emit-entry-existing/main1.js similarity index 100% rename from test/chunking-form/samples/add-entry-existing/main1.js rename to test/chunking-form/samples/emit-entry-existing/main1.js diff --git a/test/chunking-form/samples/add-entry-existing/main2.js b/test/chunking-form/samples/emit-entry-existing/main2.js similarity index 100% rename from test/chunking-form/samples/add-entry-existing/main2.js rename to test/chunking-form/samples/emit-entry-existing/main2.js diff --git a/test/chunking-form/samples/add-entry-worker/_config.js b/test/chunking-form/samples/emit-entry-worker/_config.js similarity index 100% rename from test/chunking-form/samples/add-entry-worker/_config.js rename to test/chunking-form/samples/emit-entry-worker/_config.js diff --git a/test/chunking-form/samples/add-entry-worker/_expected/amd/chunks/chunk.js b/test/chunking-form/samples/emit-entry-worker/_expected/amd/chunks/chunk.js similarity index 100% rename from test/chunking-form/samples/add-entry-worker/_expected/amd/chunks/chunk.js rename to test/chunking-form/samples/emit-entry-worker/_expected/amd/chunks/chunk.js diff --git a/test/chunking-form/samples/add-entry-worker/_expected/amd/main.js b/test/chunking-form/samples/emit-entry-worker/_expected/amd/main.js similarity index 100% rename from test/chunking-form/samples/add-entry-worker/_expected/amd/main.js rename to test/chunking-form/samples/emit-entry-worker/_expected/amd/main.js diff --git a/test/chunking-form/samples/add-entry-worker/_expected/amd/worker.js b/test/chunking-form/samples/emit-entry-worker/_expected/amd/worker.js similarity index 100% rename from test/chunking-form/samples/add-entry-worker/_expected/amd/worker.js rename to test/chunking-form/samples/emit-entry-worker/_expected/amd/worker.js diff --git a/test/chunking-form/samples/add-entry-worker/_expected/cjs/chunks/chunk.js b/test/chunking-form/samples/emit-entry-worker/_expected/cjs/chunks/chunk.js similarity index 100% rename from test/chunking-form/samples/add-entry-worker/_expected/cjs/chunks/chunk.js rename to test/chunking-form/samples/emit-entry-worker/_expected/cjs/chunks/chunk.js diff --git a/test/chunking-form/samples/add-entry-worker/_expected/cjs/main.js b/test/chunking-form/samples/emit-entry-worker/_expected/cjs/main.js similarity index 100% rename from test/chunking-form/samples/add-entry-worker/_expected/cjs/main.js rename to test/chunking-form/samples/emit-entry-worker/_expected/cjs/main.js diff --git a/test/chunking-form/samples/add-entry-worker/_expected/cjs/worker.js b/test/chunking-form/samples/emit-entry-worker/_expected/cjs/worker.js similarity index 100% rename from test/chunking-form/samples/add-entry-worker/_expected/cjs/worker.js rename to test/chunking-form/samples/emit-entry-worker/_expected/cjs/worker.js diff --git a/test/chunking-form/samples/add-entry-worker/_expected/es/chunks/chunk.js b/test/chunking-form/samples/emit-entry-worker/_expected/es/chunks/chunk.js similarity index 100% rename from test/chunking-form/samples/add-entry-worker/_expected/es/chunks/chunk.js rename to test/chunking-form/samples/emit-entry-worker/_expected/es/chunks/chunk.js diff --git a/test/chunking-form/samples/add-entry-worker/_expected/es/main.js b/test/chunking-form/samples/emit-entry-worker/_expected/es/main.js similarity index 100% rename from test/chunking-form/samples/add-entry-worker/_expected/es/main.js rename to test/chunking-form/samples/emit-entry-worker/_expected/es/main.js diff --git a/test/chunking-form/samples/add-entry-worker/_expected/es/worker.js b/test/chunking-form/samples/emit-entry-worker/_expected/es/worker.js similarity index 100% rename from test/chunking-form/samples/add-entry-worker/_expected/es/worker.js rename to test/chunking-form/samples/emit-entry-worker/_expected/es/worker.js diff --git a/test/chunking-form/samples/add-entry-worker/_expected/system/chunks/chunk.js b/test/chunking-form/samples/emit-entry-worker/_expected/system/chunks/chunk.js similarity index 100% rename from test/chunking-form/samples/add-entry-worker/_expected/system/chunks/chunk.js rename to test/chunking-form/samples/emit-entry-worker/_expected/system/chunks/chunk.js diff --git a/test/chunking-form/samples/add-entry-worker/_expected/system/main.js b/test/chunking-form/samples/emit-entry-worker/_expected/system/main.js similarity index 100% rename from test/chunking-form/samples/add-entry-worker/_expected/system/main.js rename to test/chunking-form/samples/emit-entry-worker/_expected/system/main.js diff --git a/test/chunking-form/samples/add-entry-worker/_expected/system/worker.js b/test/chunking-form/samples/emit-entry-worker/_expected/system/worker.js similarity index 100% rename from test/chunking-form/samples/add-entry-worker/_expected/system/worker.js rename to test/chunking-form/samples/emit-entry-worker/_expected/system/worker.js diff --git a/test/chunking-form/samples/add-entry-worker/index-amd.html b/test/chunking-form/samples/emit-entry-worker/index-amd.html similarity index 100% rename from test/chunking-form/samples/add-entry-worker/index-amd.html rename to test/chunking-form/samples/emit-entry-worker/index-amd.html diff --git a/test/chunking-form/samples/add-entry-worker/index-es.html b/test/chunking-form/samples/emit-entry-worker/index-es.html similarity index 100% rename from test/chunking-form/samples/add-entry-worker/index-es.html rename to test/chunking-form/samples/emit-entry-worker/index-es.html diff --git a/test/chunking-form/samples/add-entry-worker/index-system.html b/test/chunking-form/samples/emit-entry-worker/index-system.html similarity index 100% rename from test/chunking-form/samples/add-entry-worker/index-system.html rename to test/chunking-form/samples/emit-entry-worker/index-system.html diff --git a/test/chunking-form/samples/add-entry-worker/main.js b/test/chunking-form/samples/emit-entry-worker/main.js similarity index 100% rename from test/chunking-form/samples/add-entry-worker/main.js rename to test/chunking-form/samples/emit-entry-worker/main.js diff --git a/test/chunking-form/samples/add-entry-worker/worker.js b/test/chunking-form/samples/emit-entry-worker/worker.js similarity index 100% rename from test/chunking-form/samples/add-entry-worker/worker.js rename to test/chunking-form/samples/emit-entry-worker/worker.js diff --git a/test/chunking-form/samples/manual-chunk-input/_config.js b/test/chunking-form/samples/manual-chunk-input/_config.js new file mode 100644 index 00000000000..1481c073dbe --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-input/_config.js @@ -0,0 +1,12 @@ +module.exports = { + description: 'Allows entry chunks with names to be manual chunks if the name matches', + options: { + input: { + main: 'main1.js', + other: 'main2.js' + }, + manualChunks: { + main: ['main1.js'] + } + } +}; diff --git a/test/chunking-form/samples/manual-chunk-input/_expected/amd/main.js b/test/chunking-form/samples/manual-chunk-input/_expected/amd/main.js new file mode 100644 index 00000000000..fb57f4cb253 --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-input/_expected/amd/main.js @@ -0,0 +1,7 @@ +define(function () { 'use strict'; + + console.log('dep'); + + console.log('main'); + +}); diff --git a/test/chunking-form/samples/manual-chunk-input/_expected/amd/other.js b/test/chunking-form/samples/manual-chunk-input/_expected/amd/other.js new file mode 100644 index 00000000000..999b4c9c6b7 --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-input/_expected/amd/other.js @@ -0,0 +1,5 @@ +define(['./main.js'], function (main) { 'use strict'; + + console.log('main2'); + +}); diff --git a/test/chunking-form/samples/manual-chunk-input/_expected/cjs/main.js b/test/chunking-form/samples/manual-chunk-input/_expected/cjs/main.js new file mode 100644 index 00000000000..bbbb389f949 --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-input/_expected/cjs/main.js @@ -0,0 +1,5 @@ +'use strict'; + +console.log('dep'); + +console.log('main'); diff --git a/test/chunking-form/samples/manual-chunk-input/_expected/cjs/other.js b/test/chunking-form/samples/manual-chunk-input/_expected/cjs/other.js new file mode 100644 index 00000000000..1c892685576 --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-input/_expected/cjs/other.js @@ -0,0 +1,5 @@ +'use strict'; + +require('./main.js'); + +console.log('main2'); diff --git a/test/chunking-form/samples/manual-chunk-input/_expected/es/main.js b/test/chunking-form/samples/manual-chunk-input/_expected/es/main.js new file mode 100644 index 00000000000..6cb3740018f --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-input/_expected/es/main.js @@ -0,0 +1,3 @@ +console.log('dep'); + +console.log('main'); diff --git a/test/chunking-form/samples/manual-chunk-input/_expected/es/other.js b/test/chunking-form/samples/manual-chunk-input/_expected/es/other.js new file mode 100644 index 00000000000..16c5af242ae --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-input/_expected/es/other.js @@ -0,0 +1,3 @@ +import './main.js'; + +console.log('main2'); diff --git a/test/chunking-form/samples/manual-chunk-input/_expected/system/main.js b/test/chunking-form/samples/manual-chunk-input/_expected/system/main.js new file mode 100644 index 00000000000..8ef5ee4bdfd --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-input/_expected/system/main.js @@ -0,0 +1,12 @@ +System.register([], function (exports, module) { + 'use strict'; + return { + execute: function () { + + console.log('dep'); + + console.log('main'); + + } + }; +}); diff --git a/test/chunking-form/samples/manual-chunk-input/_expected/system/other.js b/test/chunking-form/samples/manual-chunk-input/_expected/system/other.js new file mode 100644 index 00000000000..45ffbad3456 --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-input/_expected/system/other.js @@ -0,0 +1,11 @@ +System.register(['./main.js'], function (exports, module) { + 'use strict'; + return { + setters: [function () {}], + execute: function () { + + console.log('main2'); + + } + }; +}); diff --git a/test/chunking-form/samples/manual-chunk-input/dep.js b/test/chunking-form/samples/manual-chunk-input/dep.js new file mode 100644 index 00000000000..b74a9837c07 --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-input/dep.js @@ -0,0 +1 @@ +console.log('dep'); diff --git a/test/chunking-form/samples/manual-chunk-input/main1.js b/test/chunking-form/samples/manual-chunk-input/main1.js new file mode 100644 index 00000000000..3539759cb0e --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-input/main1.js @@ -0,0 +1,3 @@ +import './dep.js'; + +console.log('main'); diff --git a/test/chunking-form/samples/manual-chunk-input/main2.js b/test/chunking-form/samples/manual-chunk-input/main2.js new file mode 100644 index 00000000000..52f43b1ab29 --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-input/main2.js @@ -0,0 +1,3 @@ +import './dep.js'; + +console.log('main2'); diff --git a/test/chunking-form/samples/manual-chunks-nested/_config.js b/test/chunking-form/samples/manual-chunks-nested/_config.js new file mode 100644 index 00000000000..a617f04b21f --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-nested/_config.js @@ -0,0 +1,9 @@ +module.exports = { + description: 'manual chunks can contain nested modules', + options: { + input: ['main.js'], + manualChunks: { + manual: ['middle.js', 'inner.js', 'outer.js'] + } + } +}; diff --git a/test/chunking-form/samples/manual-chunks-nested/_expected/amd/generated-manual.js b/test/chunking-form/samples/manual-chunks-nested/_expected/amd/generated-manual.js new file mode 100644 index 00000000000..e81d58f94e9 --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-nested/_expected/amd/generated-manual.js @@ -0,0 +1,9 @@ +define(function () { 'use strict'; + + console.log('inner'); + + console.log('middle'); + + console.log('outer'); + +}); diff --git a/test/chunking-form/samples/manual-chunks-nested/_expected/amd/main.js b/test/chunking-form/samples/manual-chunks-nested/_expected/amd/main.js new file mode 100644 index 00000000000..a2db4c96a66 --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-nested/_expected/amd/main.js @@ -0,0 +1,5 @@ +define(['./generated-manual.js'], function (__chunk_1) { 'use strict'; + + console.log('main'); + +}); diff --git a/test/chunking-form/samples/manual-chunks-nested/_expected/cjs/generated-manual.js b/test/chunking-form/samples/manual-chunks-nested/_expected/cjs/generated-manual.js new file mode 100644 index 00000000000..3ce3b1a69a1 --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-nested/_expected/cjs/generated-manual.js @@ -0,0 +1,7 @@ +'use strict'; + +console.log('inner'); + +console.log('middle'); + +console.log('outer'); diff --git a/test/chunking-form/samples/manual-chunks-nested/_expected/cjs/main.js b/test/chunking-form/samples/manual-chunks-nested/_expected/cjs/main.js new file mode 100644 index 00000000000..f679e51bff2 --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-nested/_expected/cjs/main.js @@ -0,0 +1,5 @@ +'use strict'; + +require('./generated-manual.js'); + +console.log('main'); diff --git a/test/chunking-form/samples/manual-chunks-nested/_expected/es/generated-manual.js b/test/chunking-form/samples/manual-chunks-nested/_expected/es/generated-manual.js new file mode 100644 index 00000000000..7abdcd7f151 --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-nested/_expected/es/generated-manual.js @@ -0,0 +1,5 @@ +console.log('inner'); + +console.log('middle'); + +console.log('outer'); diff --git a/test/chunking-form/samples/manual-chunks-nested/_expected/es/main.js b/test/chunking-form/samples/manual-chunks-nested/_expected/es/main.js new file mode 100644 index 00000000000..ddeb648f149 --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-nested/_expected/es/main.js @@ -0,0 +1,3 @@ +import './generated-manual.js'; + +console.log('main'); diff --git a/test/chunking-form/samples/manual-chunks-nested/_expected/system/generated-manual.js b/test/chunking-form/samples/manual-chunks-nested/_expected/system/generated-manual.js new file mode 100644 index 00000000000..6b13800502d --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-nested/_expected/system/generated-manual.js @@ -0,0 +1,14 @@ +System.register([], function (exports, module) { + 'use strict'; + return { + execute: function () { + + console.log('inner'); + + console.log('middle'); + + console.log('outer'); + + } + }; +}); diff --git a/test/chunking-form/samples/manual-chunks-nested/_expected/system/main.js b/test/chunking-form/samples/manual-chunks-nested/_expected/system/main.js new file mode 100644 index 00000000000..34f054c95fd --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-nested/_expected/system/main.js @@ -0,0 +1,11 @@ +System.register(['./generated-manual.js'], function (exports, module) { + 'use strict'; + return { + setters: [function () {}], + execute: function () { + + console.log('main'); + + } + }; +}); diff --git a/test/chunking-form/samples/manual-chunks-nested/inner.js b/test/chunking-form/samples/manual-chunks-nested/inner.js new file mode 100644 index 00000000000..8e1a29ca97f --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-nested/inner.js @@ -0,0 +1 @@ +console.log('inner'); diff --git a/test/chunking-form/samples/manual-chunks-nested/main.js b/test/chunking-form/samples/manual-chunks-nested/main.js new file mode 100644 index 00000000000..b46ebb222d8 --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-nested/main.js @@ -0,0 +1,3 @@ +import './outer.js'; + +console.log('main'); diff --git a/test/chunking-form/samples/manual-chunks-nested/middle.js b/test/chunking-form/samples/manual-chunks-nested/middle.js new file mode 100644 index 00000000000..0073259087e --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-nested/middle.js @@ -0,0 +1,3 @@ +import './inner.js'; + +console.log('middle'); diff --git a/test/chunking-form/samples/manual-chunks-nested/outer.js b/test/chunking-form/samples/manual-chunks-nested/outer.js new file mode 100644 index 00000000000..c77196cec49 --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-nested/outer.js @@ -0,0 +1,3 @@ +import './middle.js'; + +console.log('outer'); diff --git a/test/function/samples/emit-entry-chunk-not-found/_config.js b/test/function/samples/emit-entry-chunk-not-found/_config.js new file mode 100644 index 00000000000..8114505869b --- /dev/null +++ b/test/function/samples/emit-entry-chunk-not-found/_config.js @@ -0,0 +1,15 @@ +module.exports = { + description: 'Throws if an emitted entry chunk cannot be resolved', + options: { + input: 'main.js', + plugins: { + buildStart() { + this.emitEntryChunk('not-found.js'); + } + } + }, + error: { + code: 'UNRESOLVED_ENTRY', + message: 'Could not resolve entry (not-found.js)' + } +}; diff --git a/test/function/samples/emit-entry-chunk-not-found/main.js b/test/function/samples/emit-entry-chunk-not-found/main.js new file mode 100644 index 00000000000..c0b933d7b56 --- /dev/null +++ b/test/function/samples/emit-entry-chunk-not-found/main.js @@ -0,0 +1 @@ +console.log('main'); diff --git a/test/function/samples/manual-chunk-input-conflict/_config.js b/test/function/samples/manual-chunk-input-conflict/_config.js new file mode 100644 index 00000000000..79a21e961ad --- /dev/null +++ b/test/function/samples/manual-chunk-input-conflict/_config.js @@ -0,0 +1,17 @@ +// TODO Lukas test that we can have different manual chunks nested in each other +// TODO Lukas test that we create facades if a manual chunk contains an entry point with a different alias +module.exports = { + description: 'Throws for conflicts between manual chunks and inputs if the alias does not match', + options: { + input: { + main: 'main.js' + }, + manualChunks: { + other: ['main.js'] + } + }, + error: { + code: 'INVALID_CHUNK', + message: `Cannot assign main.js to the "main" chunk as it is already in the "other" chunk.` + } +}; diff --git a/test/function/samples/manual-chunk-input-conflict/dep.js b/test/function/samples/manual-chunk-input-conflict/dep.js new file mode 100644 index 00000000000..b74a9837c07 --- /dev/null +++ b/test/function/samples/manual-chunk-input-conflict/dep.js @@ -0,0 +1 @@ +console.log('dep'); diff --git a/test/function/samples/manual-chunk-input-conflict/main.js b/test/function/samples/manual-chunk-input-conflict/main.js new file mode 100644 index 00000000000..d6cf3b02443 --- /dev/null +++ b/test/function/samples/manual-chunk-input-conflict/main.js @@ -0,0 +1 @@ +import './dep.js'; diff --git a/test/function/samples/manual-chunks-conflict/_config.js b/test/function/samples/manual-chunks-conflict/_config.js new file mode 100644 index 00000000000..e07a6cf5cbd --- /dev/null +++ b/test/function/samples/manual-chunks-conflict/_config.js @@ -0,0 +1,14 @@ +module.exports = { + description: 'Throws for conflicts between manual chunks', + options: { + input: ['main.js'], + manualChunks: { + dep1: ['dep.js'], + dep2: ['dep.js'] + } + }, + error: { + code: 'INVALID_CHUNK', + message: `Cannot assign dep.js to the "dep1" chunk as it is already in the "dep2" chunk.` + } +}; diff --git a/test/function/samples/manual-chunks-conflict/dep.js b/test/function/samples/manual-chunks-conflict/dep.js new file mode 100644 index 00000000000..b74a9837c07 --- /dev/null +++ b/test/function/samples/manual-chunks-conflict/dep.js @@ -0,0 +1 @@ +console.log('dep'); diff --git a/test/function/samples/manual-chunks-conflict/main.js b/test/function/samples/manual-chunks-conflict/main.js new file mode 100644 index 00000000000..d6cf3b02443 --- /dev/null +++ b/test/function/samples/manual-chunks-conflict/main.js @@ -0,0 +1 @@ +import './dep.js'; diff --git a/test/function/samples/manual-chunks-invalid/_config.js b/test/function/samples/manual-chunks-invalid/_config.js deleted file mode 100644 index bcab89c422f..00000000000 --- a/test/function/samples/manual-chunks-invalid/_config.js +++ /dev/null @@ -1,14 +0,0 @@ -module.exports = { - description: 'manual chunks support', - options: { - input: ['main.js'], - manualChunks: { - dep1: ['dep1.js'], - dep2: ['dep2.js'] - } - }, - error: { - code: 'INVALID_CHUNK', - message: `Cannot assign dep2.js to the "dep2" chunk as it is already in the "dep1" chunk.\nTry defining "dep2" first in the manualChunks definitions of the Rollup configuration.` - } -}; diff --git a/test/function/samples/manual-chunks-invalid/dep1.js b/test/function/samples/manual-chunks-invalid/dep1.js deleted file mode 100644 index f752f4ebdc9..00000000000 --- a/test/function/samples/manual-chunks-invalid/dep1.js +++ /dev/null @@ -1 +0,0 @@ -import './dep2.js'; \ No newline at end of file diff --git a/test/function/samples/manual-chunks-invalid/dep2.js b/test/function/samples/manual-chunks-invalid/dep2.js deleted file mode 100644 index 55c9255134f..00000000000 --- a/test/function/samples/manual-chunks-invalid/dep2.js +++ /dev/null @@ -1 +0,0 @@ -export var p = 5; \ No newline at end of file diff --git a/test/function/samples/manual-chunks-invalid/main.js b/test/function/samples/manual-chunks-invalid/main.js deleted file mode 100644 index ec8ef6016c0..00000000000 --- a/test/function/samples/manual-chunks-invalid/main.js +++ /dev/null @@ -1 +0,0 @@ -import './dep1.js'; \ No newline at end of file From 70ef241ad2b5ce4da38094852c9c800af6988055 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Mon, 15 Apr 2019 08:15:41 +0200 Subject: [PATCH 21/60] Manual chunks never conflict with entry points: - if the alias matches, the manual chunk becomes the entry chunk - otherwise a facade is created --- src/Chunk.ts | 30 ++++++++++++------- src/Graph.ts | 2 +- src/ModuleLoader.ts | 30 ++++++++++++------- src/chunk-optimization.ts | 2 +- .../_config.js | 11 +++++++ .../_expected/amd/generated-outer.js | 11 +++++++ .../_expected/amd/main.js | 9 ++++++ .../_expected/cjs/generated-outer.js} | 4 +++ .../_expected/cjs/main.js | 9 ++++++ .../_expected/es/generated-outer.js | 7 +++++ .../_expected/es/main.js | 1 + .../_expected/system/generated-outer.js} | 2 ++ .../_expected/system/main.js | 13 ++++++++ .../dep.js | 0 .../main.js} | 2 ++ .../outer.js | 3 ++ .../_config.js | 12 ++++++++ .../_expected/amd/main.js | 13 ++++++++ .../_expected/cjs/main.js | 11 +++++++ .../_expected/es/main.js | 4 +++ .../_expected/system/main.js | 14 +++++++++ .../manual-chunk-contains-entry-match}/dep.js | 0 .../manual-chunk-contains-entry-match/main.js | 5 ++++ .../outer.js | 3 ++ .../samples/manual-chunk-input/_config.js | 12 -------- .../manual-chunk-input/_expected/amd/main.js | 7 ----- .../manual-chunk-input/_expected/amd/other.js | 5 ---- .../manual-chunk-input/_expected/cjs/other.js | 5 ---- .../manual-chunk-input/_expected/es/other.js | 3 -- .../_expected/system/other.js | 11 ------- .../samples/manual-chunk-input/main2.js | 3 -- .../manual-chunk-is-entry-conflict/_config.js | 11 +++++++ .../_expected/amd/generated-other.js | 11 +++++++ .../_expected/amd/main.js | 9 ++++++ .../_expected/cjs/generated-other.js | 9 ++++++ .../_expected/cjs/main.js | 9 ++++++ .../_expected/es/generated-other.js | 7 +++++ .../_expected/es/main.js | 1 + .../_expected/system/generated-other.js | 14 +++++++++ .../_expected/system/main.js | 13 ++++++++ .../manual-chunk-is-entry-conflict/dep.js | 1 + .../manual-chunk-is-entry-conflict/main.js | 5 ++++ .../manual-chunk-is-entry-match/_config.js | 12 ++++++++ .../_expected/amd/main.js | 13 ++++++++ .../_expected/cjs/main.js | 11 +++++++ .../_expected/es/main.js | 7 +++++ .../_expected/system/main.js | 14 +++++++++ .../manual-chunk-is-entry-match/dep.js | 1 + .../manual-chunk-is-entry-match/main.js | 5 ++++ .../manual-chunks-different-nested/_config.js | 11 +++++++ .../_expected/amd/generated-manual-inner.js | 5 ++++ .../_expected/amd/generated-manual-middle.js | 5 ++++ .../_expected/amd/generated-manual-outer.js | 5 ++++ .../_expected/amd/main.js | 5 ++++ .../_expected/cjs/generated-manual-inner.js | 3 ++ .../_expected/cjs/generated-manual-middle.js | 5 ++++ .../_expected/cjs/generated-manual-outer.js | 5 ++++ .../_expected/cjs/main.js | 7 +++++ .../_expected/es/generated-manual-inner.js | 1 + .../_expected/es/generated-manual-middle.js | 3 ++ .../_expected/es/generated-manual-outer.js | 3 ++ .../_expected/es/main.js | 5 ++++ .../system/generated-manual-inner.js | 10 +++++++ .../system/generated-manual-middle.js | 11 +++++++ .../system/generated-manual-outer.js | 11 +++++++ .../_expected/system/main.js | 11 +++++++ .../manual-chunks-different-nested/inner.js | 1 + .../manual-chunks-different-nested/main.js | 3 ++ .../manual-chunks-different-nested/middle.js | 3 ++ .../manual-chunks-different-nested/outer.js | 3 ++ ...nerated-dynamic2.js => generated-chunk.js} | 0 .../_expected/amd/main.js | 2 +- ...nerated-dynamic2.js => generated-chunk.js} | 0 .../_expected/cjs/main.js | 2 +- ...nerated-dynamic2.js => generated-chunk.js} | 0 .../_expected/es/main.js | 2 +- ...nerated-dynamic2.js => generated-chunk.js} | 0 .../_expected/system/main.js | 2 +- .../manual-chunk-input-conflict/_config.js | 17 ----------- .../manual-chunk-input-conflict/main.js | 1 - 80 files changed, 448 insertions(+), 91 deletions(-) create mode 100644 test/chunking-form/samples/manual-chunk-contains-entry-conflict/_config.js create mode 100644 test/chunking-form/samples/manual-chunk-contains-entry-conflict/_expected/amd/generated-outer.js create mode 100644 test/chunking-form/samples/manual-chunk-contains-entry-conflict/_expected/amd/main.js rename test/chunking-form/samples/{manual-chunk-input/_expected/cjs/main.js => manual-chunk-contains-entry-conflict/_expected/cjs/generated-outer.js} (57%) create mode 100644 test/chunking-form/samples/manual-chunk-contains-entry-conflict/_expected/cjs/main.js create mode 100644 test/chunking-form/samples/manual-chunk-contains-entry-conflict/_expected/es/generated-outer.js create mode 100644 test/chunking-form/samples/manual-chunk-contains-entry-conflict/_expected/es/main.js rename test/chunking-form/samples/{manual-chunk-input/_expected/system/main.js => manual-chunk-contains-entry-conflict/_expected/system/generated-outer.js} (81%) create mode 100644 test/chunking-form/samples/manual-chunk-contains-entry-conflict/_expected/system/main.js rename test/chunking-form/samples/{manual-chunk-input => manual-chunk-contains-entry-conflict}/dep.js (100%) rename test/chunking-form/samples/{manual-chunk-input/main1.js => manual-chunk-contains-entry-conflict/main.js} (61%) create mode 100644 test/chunking-form/samples/manual-chunk-contains-entry-conflict/outer.js create mode 100644 test/chunking-form/samples/manual-chunk-contains-entry-match/_config.js create mode 100644 test/chunking-form/samples/manual-chunk-contains-entry-match/_expected/amd/main.js create mode 100644 test/chunking-form/samples/manual-chunk-contains-entry-match/_expected/cjs/main.js rename test/chunking-form/samples/{manual-chunk-input => manual-chunk-contains-entry-match}/_expected/es/main.js (52%) create mode 100644 test/chunking-form/samples/manual-chunk-contains-entry-match/_expected/system/main.js rename test/{function/samples/manual-chunk-input-conflict => chunking-form/samples/manual-chunk-contains-entry-match}/dep.js (100%) create mode 100644 test/chunking-form/samples/manual-chunk-contains-entry-match/main.js create mode 100644 test/chunking-form/samples/manual-chunk-contains-entry-match/outer.js delete mode 100644 test/chunking-form/samples/manual-chunk-input/_config.js delete mode 100644 test/chunking-form/samples/manual-chunk-input/_expected/amd/main.js delete mode 100644 test/chunking-form/samples/manual-chunk-input/_expected/amd/other.js delete mode 100644 test/chunking-form/samples/manual-chunk-input/_expected/cjs/other.js delete mode 100644 test/chunking-form/samples/manual-chunk-input/_expected/es/other.js delete mode 100644 test/chunking-form/samples/manual-chunk-input/_expected/system/other.js delete mode 100644 test/chunking-form/samples/manual-chunk-input/main2.js create mode 100644 test/chunking-form/samples/manual-chunk-is-entry-conflict/_config.js create mode 100644 test/chunking-form/samples/manual-chunk-is-entry-conflict/_expected/amd/generated-other.js create mode 100644 test/chunking-form/samples/manual-chunk-is-entry-conflict/_expected/amd/main.js create mode 100644 test/chunking-form/samples/manual-chunk-is-entry-conflict/_expected/cjs/generated-other.js create mode 100644 test/chunking-form/samples/manual-chunk-is-entry-conflict/_expected/cjs/main.js create mode 100644 test/chunking-form/samples/manual-chunk-is-entry-conflict/_expected/es/generated-other.js create mode 100644 test/chunking-form/samples/manual-chunk-is-entry-conflict/_expected/es/main.js create mode 100644 test/chunking-form/samples/manual-chunk-is-entry-conflict/_expected/system/generated-other.js create mode 100644 test/chunking-form/samples/manual-chunk-is-entry-conflict/_expected/system/main.js create mode 100644 test/chunking-form/samples/manual-chunk-is-entry-conflict/dep.js create mode 100644 test/chunking-form/samples/manual-chunk-is-entry-conflict/main.js create mode 100644 test/chunking-form/samples/manual-chunk-is-entry-match/_config.js create mode 100644 test/chunking-form/samples/manual-chunk-is-entry-match/_expected/amd/main.js create mode 100644 test/chunking-form/samples/manual-chunk-is-entry-match/_expected/cjs/main.js create mode 100644 test/chunking-form/samples/manual-chunk-is-entry-match/_expected/es/main.js create mode 100644 test/chunking-form/samples/manual-chunk-is-entry-match/_expected/system/main.js create mode 100644 test/chunking-form/samples/manual-chunk-is-entry-match/dep.js create mode 100644 test/chunking-form/samples/manual-chunk-is-entry-match/main.js create mode 100644 test/chunking-form/samples/manual-chunks-different-nested/_config.js create mode 100644 test/chunking-form/samples/manual-chunks-different-nested/_expected/amd/generated-manual-inner.js create mode 100644 test/chunking-form/samples/manual-chunks-different-nested/_expected/amd/generated-manual-middle.js create mode 100644 test/chunking-form/samples/manual-chunks-different-nested/_expected/amd/generated-manual-outer.js create mode 100644 test/chunking-form/samples/manual-chunks-different-nested/_expected/amd/main.js create mode 100644 test/chunking-form/samples/manual-chunks-different-nested/_expected/cjs/generated-manual-inner.js create mode 100644 test/chunking-form/samples/manual-chunks-different-nested/_expected/cjs/generated-manual-middle.js create mode 100644 test/chunking-form/samples/manual-chunks-different-nested/_expected/cjs/generated-manual-outer.js create mode 100644 test/chunking-form/samples/manual-chunks-different-nested/_expected/cjs/main.js create mode 100644 test/chunking-form/samples/manual-chunks-different-nested/_expected/es/generated-manual-inner.js create mode 100644 test/chunking-form/samples/manual-chunks-different-nested/_expected/es/generated-manual-middle.js create mode 100644 test/chunking-form/samples/manual-chunks-different-nested/_expected/es/generated-manual-outer.js create mode 100644 test/chunking-form/samples/manual-chunks-different-nested/_expected/es/main.js create mode 100644 test/chunking-form/samples/manual-chunks-different-nested/_expected/system/generated-manual-inner.js create mode 100644 test/chunking-form/samples/manual-chunks-different-nested/_expected/system/generated-manual-middle.js create mode 100644 test/chunking-form/samples/manual-chunks-different-nested/_expected/system/generated-manual-outer.js create mode 100644 test/chunking-form/samples/manual-chunks-different-nested/_expected/system/main.js create mode 100644 test/chunking-form/samples/manual-chunks-different-nested/inner.js create mode 100644 test/chunking-form/samples/manual-chunks-different-nested/main.js create mode 100644 test/chunking-form/samples/manual-chunks-different-nested/middle.js create mode 100644 test/chunking-form/samples/manual-chunks-different-nested/outer.js rename test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/amd/{generated-dynamic2.js => generated-chunk.js} (100%) rename test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/cjs/{generated-dynamic2.js => generated-chunk.js} (100%) rename test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/es/{generated-dynamic2.js => generated-chunk.js} (100%) rename test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/system/{generated-dynamic2.js => generated-chunk.js} (100%) delete mode 100644 test/function/samples/manual-chunk-input-conflict/_config.js delete mode 100644 test/function/samples/manual-chunk-input-conflict/main.js diff --git a/src/Chunk.ts b/src/Chunk.ts index 562be4c2154..a930d424014 100644 --- a/src/Chunk.ts +++ b/src/Chunk.ts @@ -117,7 +117,7 @@ export default class Chunk { id: string = undefined; indentString: string = undefined; isEmpty: boolean; - isManualChunk: boolean = false; + manualChunkAlias: string | null = null; orderedModules: Module[]; renderedModules: { [moduleId: string]: RenderedModule; @@ -152,9 +152,8 @@ export default class Chunk { if (this.isEmpty && module.isIncluded()) { this.isEmpty = false; } - // TODO Lukas can this be done via manualChunkAlias? - if (module.chunkAlias) { - this.isManualChunk = true; + if (module.manualChunkAlias) { + this.manualChunkAlias = module.manualChunkAlias; } module.chunk = this; if ( @@ -165,15 +164,14 @@ export default class Chunk { } } - if (this.entryModules.length > 0) { + const entryModule = this.entryModules[0]; + if (entryModule) { this.variableName = makeLegal( - basename( - // TODO Lukas is searching necessary as all entryModules should have a chunkAlias by now? - this.entryModules.map(module => module.chunkAlias).find(Boolean) || - this.entryModules[0].id - ) + basename(entryModule.chunkAlias || entryModule.manualChunkAlias || entryModule.id) ); - } else this.variableName = '__chunk_' + ++graph.curChunkIndex; + } else { + this.variableName = '__chunk_' + ++graph.curChunkIndex; + } } generateEntryExportsOrMarkAsTainted() { @@ -189,6 +187,13 @@ export default class Chunk { const exposedVariables = Array.from(this.exports); checkNextEntryModule: for (const { map, module } of exportVariableMaps) { if (!this.graph.preserveModules) { + if ( + this.manualChunkAlias && + module.chunkAlias && + this.manualChunkAlias !== module.chunkAlias + ) { + continue checkNextEntryModule; + } for (const exposedVariable of exposedVariables) { if (!map.has(exposedVariable)) { continue checkNextEntryModule; @@ -750,6 +755,9 @@ export default class Chunk { } private computeChunkName(): string { + if (this.manualChunkAlias) { + return sanitizeFileName(this.manualChunkAlias); + } if (this.facadeModule !== null && this.facadeModule.chunkAlias) { return sanitizeFileName(this.facadeModule.chunkAlias); } diff --git a/src/Graph.ts b/src/Graph.ts index df88b1fa440..f9c27dcfdea 100644 --- a/src/Graph.ts +++ b/src/Graph.ts @@ -315,7 +315,7 @@ export default class Graph { // filter out empty dependencies chunks = chunks.filter( - chunk => !chunk.isEmpty || chunk.entryModules.length > 0 || chunk.isManualChunk + chunk => !chunk.isEmpty || chunk.entryModules.length > 0 || chunk.manualChunkAlias !== null ); // then go over and ensure all entry chunks export their variables diff --git a/src/ModuleLoader.ts b/src/ModuleLoader.ts index b0c1cb366ef..5a51dab72f5 100644 --- a/src/ModuleLoader.ts +++ b/src/ModuleLoader.ts @@ -16,6 +16,10 @@ export interface UnresolvedModuleWithAlias { unresolvedId: string; } +interface UnresolvedEntryModuleWithAlias extends UnresolvedModuleWithAlias { + isManualChunkEntry?: boolean; +} + function normalizeRelativeExternalId(importee: string, source: string) { return isRelative(source) ? resolve(importee, '..', source) : source; } @@ -85,22 +89,21 @@ export class ModuleLoader { } addManualChunks(manualChunks: Record): Promise { - const unresolvedManualChunks: UnresolvedModuleWithAlias[] = []; + const unresolvedManualChunks: UnresolvedEntryModuleWithAlias[] = []; for (const alias of Object.keys(manualChunks)) { const manualChunkIds = manualChunks[alias]; for (const unresolvedId of manualChunkIds) { - unresolvedManualChunks.push({ alias, unresolvedId }); + unresolvedManualChunks.push({ alias, unresolvedId, isManualChunkEntry: true }); } } const loadNewManualChunkModulesPromise = Promise.all( unresolvedManualChunks.map(this.loadEntryModule) ).then(manualChunkModules => { for (const module of manualChunkModules) { - if (!this.manualChunkModules[module.chunkAlias]) { - this.manualChunkModules[module.chunkAlias] = []; + if (!this.manualChunkModules[module.manualChunkAlias]) { + this.manualChunkModules[module.manualChunkAlias] = []; } - this.manualChunkModules[module.chunkAlias].push(module); - module.manualChunkAlias = module.chunkAlias; + this.manualChunkModules[module.manualChunkAlias].push(module); } }); @@ -120,7 +123,7 @@ export class ModuleLoader { code: 'XXX', message: `Plugin error - Unable to get chunk file name for chunk ${metaId}. Ensure that generate is called first.` }); - // TODO Lukas facadeChunk? + // TODO Lukas what if this is a facadeChunk? return entryRecord.module.chunk.id; } @@ -150,7 +153,6 @@ export class ModuleLoader { .then(replacement => { if (!replacement) return; const dynamicImport = module.dynamicImports[index]; - // TODO Lukas why can we assign to the module here? dynamicImport.alias = getAliasName(replacement); if (typeof dynamicImportExpression !== 'string') { dynamicImport.resolution = replacement; @@ -282,8 +284,9 @@ export class ModuleLoader { private loadEntryModule = ({ alias, - unresolvedId - }: UnresolvedModuleWithAlias): Promise => { + unresolvedId, + isManualChunkEntry + }: UnresolvedEntryModuleWithAlias): Promise => { return this.pluginDriver .hookFirst('resolveId', [unresolvedId, undefined]) .then(id => { @@ -303,6 +306,13 @@ export class ModuleLoader { return this.fetchModule(id, undefined).then(module => { if (alias !== null) { + if (isManualChunkEntry) { + if (module.manualChunkAlias !== null && module.manualChunkAlias !== alias) { + errorCannotAssignModuleToChunk(module.id, alias, module.manualChunkAlias); + } + module.manualChunkAlias = alias; + return module; + } if (module.chunkAlias !== null && module.chunkAlias !== alias) { errorCannotAssignModuleToChunk(module.id, alias, module.chunkAlias); } diff --git a/src/chunk-optimization.ts b/src/chunk-optimization.ts index 757df08d1fe..46c29749874 100644 --- a/src/chunk-optimization.ts +++ b/src/chunk-optimization.ts @@ -36,7 +36,7 @@ export function optimizeChunks( nextChunk = execGroup[1]; const isMergeCandidate = (chunk: Chunk) => { - if (chunk.facadeModule !== null || chunk.isManualChunk) { + if (chunk.facadeModule !== null || chunk.manualChunkAlias !== null) { return false; } if (!nextChunk || nextChunk.facadeModule !== null) { diff --git a/test/chunking-form/samples/manual-chunk-contains-entry-conflict/_config.js b/test/chunking-form/samples/manual-chunk-contains-entry-conflict/_config.js new file mode 100644 index 00000000000..e77c4240f0f --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-contains-entry-conflict/_config.js @@ -0,0 +1,11 @@ +module.exports = { + description: 'Creates proper facades if manual chunks contain entry chunks with different alias', + options: { + input: { + main: 'main.js' + }, + manualChunks: { + outer: ['outer'] + } + } +}; diff --git a/test/chunking-form/samples/manual-chunk-contains-entry-conflict/_expected/amd/generated-outer.js b/test/chunking-form/samples/manual-chunk-contains-entry-conflict/_expected/amd/generated-outer.js new file mode 100644 index 00000000000..659be70e586 --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-contains-entry-conflict/_expected/amd/generated-outer.js @@ -0,0 +1,11 @@ +define(['exports'], function (exports) { 'use strict'; + + console.log('dep'); + + console.log('main'); + + const value = 42; + + exports.value = value; + +}); diff --git a/test/chunking-form/samples/manual-chunk-contains-entry-conflict/_expected/amd/main.js b/test/chunking-form/samples/manual-chunk-contains-entry-conflict/_expected/amd/main.js new file mode 100644 index 00000000000..905ce3018ca --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-contains-entry-conflict/_expected/amd/main.js @@ -0,0 +1,9 @@ +define(['exports', './generated-outer.js'], function (exports, main) { 'use strict'; + + + + exports.value = main.value; + + Object.defineProperty(exports, '__esModule', { value: true }); + +}); diff --git a/test/chunking-form/samples/manual-chunk-input/_expected/cjs/main.js b/test/chunking-form/samples/manual-chunk-contains-entry-conflict/_expected/cjs/generated-outer.js similarity index 57% rename from test/chunking-form/samples/manual-chunk-input/_expected/cjs/main.js rename to test/chunking-form/samples/manual-chunk-contains-entry-conflict/_expected/cjs/generated-outer.js index bbbb389f949..fe59aaab6b9 100644 --- a/test/chunking-form/samples/manual-chunk-input/_expected/cjs/main.js +++ b/test/chunking-form/samples/manual-chunk-contains-entry-conflict/_expected/cjs/generated-outer.js @@ -3,3 +3,7 @@ console.log('dep'); console.log('main'); + +const value = 42; + +exports.value = value; diff --git a/test/chunking-form/samples/manual-chunk-contains-entry-conflict/_expected/cjs/main.js b/test/chunking-form/samples/manual-chunk-contains-entry-conflict/_expected/cjs/main.js new file mode 100644 index 00000000000..d4b7fbb7259 --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-contains-entry-conflict/_expected/cjs/main.js @@ -0,0 +1,9 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +var main = require('./generated-outer.js'); + + + +exports.value = main.value; diff --git a/test/chunking-form/samples/manual-chunk-contains-entry-conflict/_expected/es/generated-outer.js b/test/chunking-form/samples/manual-chunk-contains-entry-conflict/_expected/es/generated-outer.js new file mode 100644 index 00000000000..799f32a0d48 --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-contains-entry-conflict/_expected/es/generated-outer.js @@ -0,0 +1,7 @@ +console.log('dep'); + +console.log('main'); + +const value = 42; + +export { value as a }; diff --git a/test/chunking-form/samples/manual-chunk-contains-entry-conflict/_expected/es/main.js b/test/chunking-form/samples/manual-chunk-contains-entry-conflict/_expected/es/main.js new file mode 100644 index 00000000000..5eb7786ffac --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-contains-entry-conflict/_expected/es/main.js @@ -0,0 +1 @@ +export { a as value } from './generated-outer.js'; diff --git a/test/chunking-form/samples/manual-chunk-input/_expected/system/main.js b/test/chunking-form/samples/manual-chunk-contains-entry-conflict/_expected/system/generated-outer.js similarity index 81% rename from test/chunking-form/samples/manual-chunk-input/_expected/system/main.js rename to test/chunking-form/samples/manual-chunk-contains-entry-conflict/_expected/system/generated-outer.js index 8ef5ee4bdfd..7addc0e2fc9 100644 --- a/test/chunking-form/samples/manual-chunk-input/_expected/system/main.js +++ b/test/chunking-form/samples/manual-chunk-contains-entry-conflict/_expected/system/generated-outer.js @@ -7,6 +7,8 @@ System.register([], function (exports, module) { console.log('main'); + const value = exports('a', 42); + } }; }); diff --git a/test/chunking-form/samples/manual-chunk-contains-entry-conflict/_expected/system/main.js b/test/chunking-form/samples/manual-chunk-contains-entry-conflict/_expected/system/main.js new file mode 100644 index 00000000000..263739c45e1 --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-contains-entry-conflict/_expected/system/main.js @@ -0,0 +1,13 @@ +System.register(['./generated-outer.js'], function (exports, module) { + 'use strict'; + return { + setters: [function (module) { + exports('value', module.a); + }], + execute: function () { + + + + } + }; +}); diff --git a/test/chunking-form/samples/manual-chunk-input/dep.js b/test/chunking-form/samples/manual-chunk-contains-entry-conflict/dep.js similarity index 100% rename from test/chunking-form/samples/manual-chunk-input/dep.js rename to test/chunking-form/samples/manual-chunk-contains-entry-conflict/dep.js diff --git a/test/chunking-form/samples/manual-chunk-input/main1.js b/test/chunking-form/samples/manual-chunk-contains-entry-conflict/main.js similarity index 61% rename from test/chunking-form/samples/manual-chunk-input/main1.js rename to test/chunking-form/samples/manual-chunk-contains-entry-conflict/main.js index 3539759cb0e..983ead17e5a 100644 --- a/test/chunking-form/samples/manual-chunk-input/main1.js +++ b/test/chunking-form/samples/manual-chunk-contains-entry-conflict/main.js @@ -1,3 +1,5 @@ import './dep.js'; console.log('main'); + +export const value = 42; diff --git a/test/chunking-form/samples/manual-chunk-contains-entry-conflict/outer.js b/test/chunking-form/samples/manual-chunk-contains-entry-conflict/outer.js new file mode 100644 index 00000000000..26385b8a3c3 --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-contains-entry-conflict/outer.js @@ -0,0 +1,3 @@ +import './main'; + +console.log('outer'); diff --git a/test/chunking-form/samples/manual-chunk-contains-entry-match/_config.js b/test/chunking-form/samples/manual-chunk-contains-entry-match/_config.js new file mode 100644 index 00000000000..a08d4f85d17 --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-contains-entry-match/_config.js @@ -0,0 +1,12 @@ +module.exports = { + description: + 'Identifies the entry chunk with the manual chunk that contains it if the aliases match', + options: { + input: { + main: 'main.js' + }, + manualChunks: { + main: ['outer'] + } + } +}; diff --git a/test/chunking-form/samples/manual-chunk-contains-entry-match/_expected/amd/main.js b/test/chunking-form/samples/manual-chunk-contains-entry-match/_expected/amd/main.js new file mode 100644 index 00000000000..fc91f027a0e --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-contains-entry-match/_expected/amd/main.js @@ -0,0 +1,13 @@ +define(['exports'], function (exports) { 'use strict'; + + console.log('dep'); + + console.log('main'); + + const value = 42; + + exports.value = value; + + Object.defineProperty(exports, '__esModule', { value: true }); + +}); diff --git a/test/chunking-form/samples/manual-chunk-contains-entry-match/_expected/cjs/main.js b/test/chunking-form/samples/manual-chunk-contains-entry-match/_expected/cjs/main.js new file mode 100644 index 00000000000..5da9ebd5132 --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-contains-entry-match/_expected/cjs/main.js @@ -0,0 +1,11 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +console.log('dep'); + +console.log('main'); + +const value = 42; + +exports.value = value; diff --git a/test/chunking-form/samples/manual-chunk-input/_expected/es/main.js b/test/chunking-form/samples/manual-chunk-contains-entry-match/_expected/es/main.js similarity index 52% rename from test/chunking-form/samples/manual-chunk-input/_expected/es/main.js rename to test/chunking-form/samples/manual-chunk-contains-entry-match/_expected/es/main.js index 6cb3740018f..132b27a8d7c 100644 --- a/test/chunking-form/samples/manual-chunk-input/_expected/es/main.js +++ b/test/chunking-form/samples/manual-chunk-contains-entry-match/_expected/es/main.js @@ -1,3 +1,7 @@ console.log('dep'); console.log('main'); + +const value = 42; + +export { value }; diff --git a/test/chunking-form/samples/manual-chunk-contains-entry-match/_expected/system/main.js b/test/chunking-form/samples/manual-chunk-contains-entry-match/_expected/system/main.js new file mode 100644 index 00000000000..6c03a5d5fb7 --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-contains-entry-match/_expected/system/main.js @@ -0,0 +1,14 @@ +System.register([], function (exports, module) { + 'use strict'; + return { + execute: function () { + + console.log('dep'); + + console.log('main'); + + const value = exports('value', 42); + + } + }; +}); diff --git a/test/function/samples/manual-chunk-input-conflict/dep.js b/test/chunking-form/samples/manual-chunk-contains-entry-match/dep.js similarity index 100% rename from test/function/samples/manual-chunk-input-conflict/dep.js rename to test/chunking-form/samples/manual-chunk-contains-entry-match/dep.js diff --git a/test/chunking-form/samples/manual-chunk-contains-entry-match/main.js b/test/chunking-form/samples/manual-chunk-contains-entry-match/main.js new file mode 100644 index 00000000000..983ead17e5a --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-contains-entry-match/main.js @@ -0,0 +1,5 @@ +import './dep.js'; + +console.log('main'); + +export const value = 42; diff --git a/test/chunking-form/samples/manual-chunk-contains-entry-match/outer.js b/test/chunking-form/samples/manual-chunk-contains-entry-match/outer.js new file mode 100644 index 00000000000..26385b8a3c3 --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-contains-entry-match/outer.js @@ -0,0 +1,3 @@ +import './main'; + +console.log('outer'); diff --git a/test/chunking-form/samples/manual-chunk-input/_config.js b/test/chunking-form/samples/manual-chunk-input/_config.js deleted file mode 100644 index 1481c073dbe..00000000000 --- a/test/chunking-form/samples/manual-chunk-input/_config.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - description: 'Allows entry chunks with names to be manual chunks if the name matches', - options: { - input: { - main: 'main1.js', - other: 'main2.js' - }, - manualChunks: { - main: ['main1.js'] - } - } -}; diff --git a/test/chunking-form/samples/manual-chunk-input/_expected/amd/main.js b/test/chunking-form/samples/manual-chunk-input/_expected/amd/main.js deleted file mode 100644 index fb57f4cb253..00000000000 --- a/test/chunking-form/samples/manual-chunk-input/_expected/amd/main.js +++ /dev/null @@ -1,7 +0,0 @@ -define(function () { 'use strict'; - - console.log('dep'); - - console.log('main'); - -}); diff --git a/test/chunking-form/samples/manual-chunk-input/_expected/amd/other.js b/test/chunking-form/samples/manual-chunk-input/_expected/amd/other.js deleted file mode 100644 index 999b4c9c6b7..00000000000 --- a/test/chunking-form/samples/manual-chunk-input/_expected/amd/other.js +++ /dev/null @@ -1,5 +0,0 @@ -define(['./main.js'], function (main) { 'use strict'; - - console.log('main2'); - -}); diff --git a/test/chunking-form/samples/manual-chunk-input/_expected/cjs/other.js b/test/chunking-form/samples/manual-chunk-input/_expected/cjs/other.js deleted file mode 100644 index 1c892685576..00000000000 --- a/test/chunking-form/samples/manual-chunk-input/_expected/cjs/other.js +++ /dev/null @@ -1,5 +0,0 @@ -'use strict'; - -require('./main.js'); - -console.log('main2'); diff --git a/test/chunking-form/samples/manual-chunk-input/_expected/es/other.js b/test/chunking-form/samples/manual-chunk-input/_expected/es/other.js deleted file mode 100644 index 16c5af242ae..00000000000 --- a/test/chunking-form/samples/manual-chunk-input/_expected/es/other.js +++ /dev/null @@ -1,3 +0,0 @@ -import './main.js'; - -console.log('main2'); diff --git a/test/chunking-form/samples/manual-chunk-input/_expected/system/other.js b/test/chunking-form/samples/manual-chunk-input/_expected/system/other.js deleted file mode 100644 index 45ffbad3456..00000000000 --- a/test/chunking-form/samples/manual-chunk-input/_expected/system/other.js +++ /dev/null @@ -1,11 +0,0 @@ -System.register(['./main.js'], function (exports, module) { - 'use strict'; - return { - setters: [function () {}], - execute: function () { - - console.log('main2'); - - } - }; -}); diff --git a/test/chunking-form/samples/manual-chunk-input/main2.js b/test/chunking-form/samples/manual-chunk-input/main2.js deleted file mode 100644 index 52f43b1ab29..00000000000 --- a/test/chunking-form/samples/manual-chunk-input/main2.js +++ /dev/null @@ -1,3 +0,0 @@ -import './dep.js'; - -console.log('main2'); diff --git a/test/chunking-form/samples/manual-chunk-is-entry-conflict/_config.js b/test/chunking-form/samples/manual-chunk-is-entry-conflict/_config.js new file mode 100644 index 00000000000..d7c6eea6eba --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-is-entry-conflict/_config.js @@ -0,0 +1,11 @@ +module.exports = { + description: 'Creates proper facades if manual chunks are entry chunks with different alias', + options: { + input: { + main: 'main.js' + }, + manualChunks: { + other: ['main'] + } + } +}; diff --git a/test/chunking-form/samples/manual-chunk-is-entry-conflict/_expected/amd/generated-other.js b/test/chunking-form/samples/manual-chunk-is-entry-conflict/_expected/amd/generated-other.js new file mode 100644 index 00000000000..659be70e586 --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-is-entry-conflict/_expected/amd/generated-other.js @@ -0,0 +1,11 @@ +define(['exports'], function (exports) { 'use strict'; + + console.log('dep'); + + console.log('main'); + + const value = 42; + + exports.value = value; + +}); diff --git a/test/chunking-form/samples/manual-chunk-is-entry-conflict/_expected/amd/main.js b/test/chunking-form/samples/manual-chunk-is-entry-conflict/_expected/amd/main.js new file mode 100644 index 00000000000..57007ba3c57 --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-is-entry-conflict/_expected/amd/main.js @@ -0,0 +1,9 @@ +define(['exports', './generated-other.js'], function (exports, main) { 'use strict'; + + + + exports.value = main.value; + + Object.defineProperty(exports, '__esModule', { value: true }); + +}); diff --git a/test/chunking-form/samples/manual-chunk-is-entry-conflict/_expected/cjs/generated-other.js b/test/chunking-form/samples/manual-chunk-is-entry-conflict/_expected/cjs/generated-other.js new file mode 100644 index 00000000000..fe59aaab6b9 --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-is-entry-conflict/_expected/cjs/generated-other.js @@ -0,0 +1,9 @@ +'use strict'; + +console.log('dep'); + +console.log('main'); + +const value = 42; + +exports.value = value; diff --git a/test/chunking-form/samples/manual-chunk-is-entry-conflict/_expected/cjs/main.js b/test/chunking-form/samples/manual-chunk-is-entry-conflict/_expected/cjs/main.js new file mode 100644 index 00000000000..830a223da0b --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-is-entry-conflict/_expected/cjs/main.js @@ -0,0 +1,9 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +var main = require('./generated-other.js'); + + + +exports.value = main.value; diff --git a/test/chunking-form/samples/manual-chunk-is-entry-conflict/_expected/es/generated-other.js b/test/chunking-form/samples/manual-chunk-is-entry-conflict/_expected/es/generated-other.js new file mode 100644 index 00000000000..799f32a0d48 --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-is-entry-conflict/_expected/es/generated-other.js @@ -0,0 +1,7 @@ +console.log('dep'); + +console.log('main'); + +const value = 42; + +export { value as a }; diff --git a/test/chunking-form/samples/manual-chunk-is-entry-conflict/_expected/es/main.js b/test/chunking-form/samples/manual-chunk-is-entry-conflict/_expected/es/main.js new file mode 100644 index 00000000000..604a3884871 --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-is-entry-conflict/_expected/es/main.js @@ -0,0 +1 @@ +export { a as value } from './generated-other.js'; diff --git a/test/chunking-form/samples/manual-chunk-is-entry-conflict/_expected/system/generated-other.js b/test/chunking-form/samples/manual-chunk-is-entry-conflict/_expected/system/generated-other.js new file mode 100644 index 00000000000..7addc0e2fc9 --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-is-entry-conflict/_expected/system/generated-other.js @@ -0,0 +1,14 @@ +System.register([], function (exports, module) { + 'use strict'; + return { + execute: function () { + + console.log('dep'); + + console.log('main'); + + const value = exports('a', 42); + + } + }; +}); diff --git a/test/chunking-form/samples/manual-chunk-is-entry-conflict/_expected/system/main.js b/test/chunking-form/samples/manual-chunk-is-entry-conflict/_expected/system/main.js new file mode 100644 index 00000000000..335cd2bb0ab --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-is-entry-conflict/_expected/system/main.js @@ -0,0 +1,13 @@ +System.register(['./generated-other.js'], function (exports, module) { + 'use strict'; + return { + setters: [function (module) { + exports('value', module.a); + }], + execute: function () { + + + + } + }; +}); diff --git a/test/chunking-form/samples/manual-chunk-is-entry-conflict/dep.js b/test/chunking-form/samples/manual-chunk-is-entry-conflict/dep.js new file mode 100644 index 00000000000..b74a9837c07 --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-is-entry-conflict/dep.js @@ -0,0 +1 @@ +console.log('dep'); diff --git a/test/chunking-form/samples/manual-chunk-is-entry-conflict/main.js b/test/chunking-form/samples/manual-chunk-is-entry-conflict/main.js new file mode 100644 index 00000000000..983ead17e5a --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-is-entry-conflict/main.js @@ -0,0 +1,5 @@ +import './dep.js'; + +console.log('main'); + +export const value = 42; diff --git a/test/chunking-form/samples/manual-chunk-is-entry-match/_config.js b/test/chunking-form/samples/manual-chunk-is-entry-match/_config.js new file mode 100644 index 00000000000..f86733b33a7 --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-is-entry-match/_config.js @@ -0,0 +1,12 @@ +module.exports = { + description: + 'Identifies the entry chunk with the manual chunk that has the same entry if the aliases match', + options: { + input: { + main: 'main.js' + }, + manualChunks: { + main: ['main'] + } + } +}; diff --git a/test/chunking-form/samples/manual-chunk-is-entry-match/_expected/amd/main.js b/test/chunking-form/samples/manual-chunk-is-entry-match/_expected/amd/main.js new file mode 100644 index 00000000000..fc91f027a0e --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-is-entry-match/_expected/amd/main.js @@ -0,0 +1,13 @@ +define(['exports'], function (exports) { 'use strict'; + + console.log('dep'); + + console.log('main'); + + const value = 42; + + exports.value = value; + + Object.defineProperty(exports, '__esModule', { value: true }); + +}); diff --git a/test/chunking-form/samples/manual-chunk-is-entry-match/_expected/cjs/main.js b/test/chunking-form/samples/manual-chunk-is-entry-match/_expected/cjs/main.js new file mode 100644 index 00000000000..5da9ebd5132 --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-is-entry-match/_expected/cjs/main.js @@ -0,0 +1,11 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +console.log('dep'); + +console.log('main'); + +const value = 42; + +exports.value = value; diff --git a/test/chunking-form/samples/manual-chunk-is-entry-match/_expected/es/main.js b/test/chunking-form/samples/manual-chunk-is-entry-match/_expected/es/main.js new file mode 100644 index 00000000000..132b27a8d7c --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-is-entry-match/_expected/es/main.js @@ -0,0 +1,7 @@ +console.log('dep'); + +console.log('main'); + +const value = 42; + +export { value }; diff --git a/test/chunking-form/samples/manual-chunk-is-entry-match/_expected/system/main.js b/test/chunking-form/samples/manual-chunk-is-entry-match/_expected/system/main.js new file mode 100644 index 00000000000..6c03a5d5fb7 --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-is-entry-match/_expected/system/main.js @@ -0,0 +1,14 @@ +System.register([], function (exports, module) { + 'use strict'; + return { + execute: function () { + + console.log('dep'); + + console.log('main'); + + const value = exports('value', 42); + + } + }; +}); diff --git a/test/chunking-form/samples/manual-chunk-is-entry-match/dep.js b/test/chunking-form/samples/manual-chunk-is-entry-match/dep.js new file mode 100644 index 00000000000..b74a9837c07 --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-is-entry-match/dep.js @@ -0,0 +1 @@ +console.log('dep'); diff --git a/test/chunking-form/samples/manual-chunk-is-entry-match/main.js b/test/chunking-form/samples/manual-chunk-is-entry-match/main.js new file mode 100644 index 00000000000..983ead17e5a --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-is-entry-match/main.js @@ -0,0 +1,5 @@ +import './dep.js'; + +console.log('main'); + +export const value = 42; diff --git a/test/chunking-form/samples/manual-chunks-different-nested/_config.js b/test/chunking-form/samples/manual-chunks-different-nested/_config.js new file mode 100644 index 00000000000..ef32850d199 --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-different-nested/_config.js @@ -0,0 +1,11 @@ +module.exports = { + description: 'manual chunks can have other manual chunks as dependencies', + options: { + input: ['main.js'], + manualChunks: { + 'manual-outer': ['outer.js'], + 'manual-inner': ['inner.js'], + 'manual-middle': ['middle.js'] + } + } +}; diff --git a/test/chunking-form/samples/manual-chunks-different-nested/_expected/amd/generated-manual-inner.js b/test/chunking-form/samples/manual-chunks-different-nested/_expected/amd/generated-manual-inner.js new file mode 100644 index 00000000000..5068b5fd910 --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-different-nested/_expected/amd/generated-manual-inner.js @@ -0,0 +1,5 @@ +define(function () { 'use strict'; + + console.log('inner'); + +}); diff --git a/test/chunking-form/samples/manual-chunks-different-nested/_expected/amd/generated-manual-middle.js b/test/chunking-form/samples/manual-chunks-different-nested/_expected/amd/generated-manual-middle.js new file mode 100644 index 00000000000..378a00d6f24 --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-different-nested/_expected/amd/generated-manual-middle.js @@ -0,0 +1,5 @@ +define(['./generated-manual-inner.js'], function (__chunk_1) { 'use strict'; + + console.log('middle'); + +}); diff --git a/test/chunking-form/samples/manual-chunks-different-nested/_expected/amd/generated-manual-outer.js b/test/chunking-form/samples/manual-chunks-different-nested/_expected/amd/generated-manual-outer.js new file mode 100644 index 00000000000..9a3151549dd --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-different-nested/_expected/amd/generated-manual-outer.js @@ -0,0 +1,5 @@ +define(['./generated-manual-middle.js'], function (__chunk_2) { 'use strict'; + + console.log('outer'); + +}); diff --git a/test/chunking-form/samples/manual-chunks-different-nested/_expected/amd/main.js b/test/chunking-form/samples/manual-chunks-different-nested/_expected/amd/main.js new file mode 100644 index 00000000000..3f877adee34 --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-different-nested/_expected/amd/main.js @@ -0,0 +1,5 @@ +define(['./generated-manual-inner.js', './generated-manual-middle.js', './generated-manual-outer.js'], function (__chunk_1, __chunk_2, __chunk_3) { 'use strict'; + + console.log('main'); + +}); diff --git a/test/chunking-form/samples/manual-chunks-different-nested/_expected/cjs/generated-manual-inner.js b/test/chunking-form/samples/manual-chunks-different-nested/_expected/cjs/generated-manual-inner.js new file mode 100644 index 00000000000..02ef883da4e --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-different-nested/_expected/cjs/generated-manual-inner.js @@ -0,0 +1,3 @@ +'use strict'; + +console.log('inner'); diff --git a/test/chunking-form/samples/manual-chunks-different-nested/_expected/cjs/generated-manual-middle.js b/test/chunking-form/samples/manual-chunks-different-nested/_expected/cjs/generated-manual-middle.js new file mode 100644 index 00000000000..77da3dd71c1 --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-different-nested/_expected/cjs/generated-manual-middle.js @@ -0,0 +1,5 @@ +'use strict'; + +require('./generated-manual-inner.js'); + +console.log('middle'); diff --git a/test/chunking-form/samples/manual-chunks-different-nested/_expected/cjs/generated-manual-outer.js b/test/chunking-form/samples/manual-chunks-different-nested/_expected/cjs/generated-manual-outer.js new file mode 100644 index 00000000000..8a4efba721e --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-different-nested/_expected/cjs/generated-manual-outer.js @@ -0,0 +1,5 @@ +'use strict'; + +require('./generated-manual-middle.js'); + +console.log('outer'); diff --git a/test/chunking-form/samples/manual-chunks-different-nested/_expected/cjs/main.js b/test/chunking-form/samples/manual-chunks-different-nested/_expected/cjs/main.js new file mode 100644 index 00000000000..7b5cf110cf4 --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-different-nested/_expected/cjs/main.js @@ -0,0 +1,7 @@ +'use strict'; + +require('./generated-manual-inner.js'); +require('./generated-manual-middle.js'); +require('./generated-manual-outer.js'); + +console.log('main'); diff --git a/test/chunking-form/samples/manual-chunks-different-nested/_expected/es/generated-manual-inner.js b/test/chunking-form/samples/manual-chunks-different-nested/_expected/es/generated-manual-inner.js new file mode 100644 index 00000000000..8e1a29ca97f --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-different-nested/_expected/es/generated-manual-inner.js @@ -0,0 +1 @@ +console.log('inner'); diff --git a/test/chunking-form/samples/manual-chunks-different-nested/_expected/es/generated-manual-middle.js b/test/chunking-form/samples/manual-chunks-different-nested/_expected/es/generated-manual-middle.js new file mode 100644 index 00000000000..247a57bae80 --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-different-nested/_expected/es/generated-manual-middle.js @@ -0,0 +1,3 @@ +import './generated-manual-inner.js'; + +console.log('middle'); diff --git a/test/chunking-form/samples/manual-chunks-different-nested/_expected/es/generated-manual-outer.js b/test/chunking-form/samples/manual-chunks-different-nested/_expected/es/generated-manual-outer.js new file mode 100644 index 00000000000..f348b38752c --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-different-nested/_expected/es/generated-manual-outer.js @@ -0,0 +1,3 @@ +import './generated-manual-middle.js'; + +console.log('outer'); diff --git a/test/chunking-form/samples/manual-chunks-different-nested/_expected/es/main.js b/test/chunking-form/samples/manual-chunks-different-nested/_expected/es/main.js new file mode 100644 index 00000000000..de3b67e6685 --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-different-nested/_expected/es/main.js @@ -0,0 +1,5 @@ +import './generated-manual-inner.js'; +import './generated-manual-middle.js'; +import './generated-manual-outer.js'; + +console.log('main'); diff --git a/test/chunking-form/samples/manual-chunks-different-nested/_expected/system/generated-manual-inner.js b/test/chunking-form/samples/manual-chunks-different-nested/_expected/system/generated-manual-inner.js new file mode 100644 index 00000000000..bd48d6dccbe --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-different-nested/_expected/system/generated-manual-inner.js @@ -0,0 +1,10 @@ +System.register([], function (exports, module) { + 'use strict'; + return { + execute: function () { + + console.log('inner'); + + } + }; +}); diff --git a/test/chunking-form/samples/manual-chunks-different-nested/_expected/system/generated-manual-middle.js b/test/chunking-form/samples/manual-chunks-different-nested/_expected/system/generated-manual-middle.js new file mode 100644 index 00000000000..b08dca795bb --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-different-nested/_expected/system/generated-manual-middle.js @@ -0,0 +1,11 @@ +System.register(['./generated-manual-inner.js'], function (exports, module) { + 'use strict'; + return { + setters: [function () {}], + execute: function () { + + console.log('middle'); + + } + }; +}); diff --git a/test/chunking-form/samples/manual-chunks-different-nested/_expected/system/generated-manual-outer.js b/test/chunking-form/samples/manual-chunks-different-nested/_expected/system/generated-manual-outer.js new file mode 100644 index 00000000000..1bb210ffd84 --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-different-nested/_expected/system/generated-manual-outer.js @@ -0,0 +1,11 @@ +System.register(['./generated-manual-middle.js'], function (exports, module) { + 'use strict'; + return { + setters: [function () {}], + execute: function () { + + console.log('outer'); + + } + }; +}); diff --git a/test/chunking-form/samples/manual-chunks-different-nested/_expected/system/main.js b/test/chunking-form/samples/manual-chunks-different-nested/_expected/system/main.js new file mode 100644 index 00000000000..806c05886bf --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-different-nested/_expected/system/main.js @@ -0,0 +1,11 @@ +System.register(['./generated-manual-inner.js', './generated-manual-middle.js', './generated-manual-outer.js'], function (exports, module) { + 'use strict'; + return { + setters: [function () {}, function () {}, function () {}], + execute: function () { + + console.log('main'); + + } + }; +}); diff --git a/test/chunking-form/samples/manual-chunks-different-nested/inner.js b/test/chunking-form/samples/manual-chunks-different-nested/inner.js new file mode 100644 index 00000000000..8e1a29ca97f --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-different-nested/inner.js @@ -0,0 +1 @@ +console.log('inner'); diff --git a/test/chunking-form/samples/manual-chunks-different-nested/main.js b/test/chunking-form/samples/manual-chunks-different-nested/main.js new file mode 100644 index 00000000000..b46ebb222d8 --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-different-nested/main.js @@ -0,0 +1,3 @@ +import './outer.js'; + +console.log('main'); diff --git a/test/chunking-form/samples/manual-chunks-different-nested/middle.js b/test/chunking-form/samples/manual-chunks-different-nested/middle.js new file mode 100644 index 00000000000..0073259087e --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-different-nested/middle.js @@ -0,0 +1,3 @@ +import './inner.js'; + +console.log('middle'); diff --git a/test/chunking-form/samples/manual-chunks-different-nested/outer.js b/test/chunking-form/samples/manual-chunks-different-nested/outer.js new file mode 100644 index 00000000000..c77196cec49 --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-different-nested/outer.js @@ -0,0 +1,3 @@ +import './middle.js'; + +console.log('outer'); diff --git a/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/amd/generated-dynamic2.js b/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/amd/generated-chunk.js similarity index 100% rename from test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/amd/generated-dynamic2.js rename to test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/amd/generated-chunk.js diff --git a/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/amd/main.js b/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/amd/main.js index 0e20039a5ed..fc473ab782b 100644 --- a/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/amd/main.js +++ b/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/amd/main.js @@ -1,6 +1,6 @@ define(['require'], function (require) { 'use strict'; - new Promise(function (resolve, reject) { require(['./generated-dynamic2.js'], resolve, reject) }).then(result => console.log(result)); + new Promise(function (resolve, reject) { require(['./generated-chunk.js'], resolve, reject) }).then(result => console.log(result)); new Promise(function (resolve, reject) { require(['./generated-dynamic.js'], resolve, reject) }).then(result => console.log(result)); }); diff --git a/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/cjs/generated-dynamic2.js b/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/cjs/generated-chunk.js similarity index 100% rename from test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/cjs/generated-dynamic2.js rename to test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/cjs/generated-chunk.js diff --git a/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/cjs/main.js b/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/cjs/main.js index 0a28239769b..2cf5a2e9b8d 100644 --- a/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/cjs/main.js +++ b/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/cjs/main.js @@ -1,4 +1,4 @@ 'use strict'; -Promise.resolve(require('./generated-dynamic2.js')).then(result => console.log(result)); +Promise.resolve(require('./generated-chunk.js')).then(result => console.log(result)); Promise.resolve(require('./generated-dynamic.js')).then(result => console.log(result)); diff --git a/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/es/generated-dynamic2.js b/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/es/generated-chunk.js similarity index 100% rename from test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/es/generated-dynamic2.js rename to test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/es/generated-chunk.js diff --git a/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/es/main.js b/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/es/main.js index d191126a7d3..c11f64d0ba9 100644 --- a/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/es/main.js +++ b/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/es/main.js @@ -1,2 +1,2 @@ -import('./generated-dynamic2.js').then(result => console.log(result)); +import('./generated-chunk.js').then(result => console.log(result)); import('./generated-dynamic.js').then(result => console.log(result)); diff --git a/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/system/generated-dynamic2.js b/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/system/generated-chunk.js similarity index 100% rename from test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/system/generated-dynamic2.js rename to test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/system/generated-chunk.js diff --git a/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/system/main.js b/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/system/main.js index fa189fe4b60..139d8a26580 100644 --- a/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/system/main.js +++ b/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/system/main.js @@ -3,7 +3,7 @@ System.register([], function (exports, module) { return { execute: function () { - module.import('./generated-dynamic2.js').then(result => console.log(result)); + module.import('./generated-chunk.js').then(result => console.log(result)); module.import('./generated-dynamic.js').then(result => console.log(result)); } diff --git a/test/function/samples/manual-chunk-input-conflict/_config.js b/test/function/samples/manual-chunk-input-conflict/_config.js deleted file mode 100644 index 79a21e961ad..00000000000 --- a/test/function/samples/manual-chunk-input-conflict/_config.js +++ /dev/null @@ -1,17 +0,0 @@ -// TODO Lukas test that we can have different manual chunks nested in each other -// TODO Lukas test that we create facades if a manual chunk contains an entry point with a different alias -module.exports = { - description: 'Throws for conflicts between manual chunks and inputs if the alias does not match', - options: { - input: { - main: 'main.js' - }, - manualChunks: { - other: ['main.js'] - } - }, - error: { - code: 'INVALID_CHUNK', - message: `Cannot assign main.js to the "main" chunk as it is already in the "other" chunk.` - } -}; diff --git a/test/function/samples/manual-chunk-input-conflict/main.js b/test/function/samples/manual-chunk-input-conflict/main.js deleted file mode 100644 index d6cf3b02443..00000000000 --- a/test/function/samples/manual-chunk-input-conflict/main.js +++ /dev/null @@ -1 +0,0 @@ -import './dep.js'; From a306a92d90e648c8d9474cae5367c1c3ae5fb017 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Mon, 15 Apr 2019 08:28:46 +0200 Subject: [PATCH 22/60] Return correct file name if a facade is created for an emitted chunk --- src/ModuleLoader.ts | 5 +++-- .../emit-entry-chunk-facade/_config.js | 20 +++++++++++++++++++ .../_expected/amd/buildStart.js | 9 +++++++++ .../_expected/amd/generated-build-starter.js | 9 +++++++++ .../_expected/amd/main.js | 5 +++++ .../_expected/cjs/buildStart.js | 9 +++++++++ .../_expected/cjs/generated-build-starter.js | 7 +++++++ .../_expected/cjs/main.js | 5 +++++ .../_expected/es/buildStart.js | 1 + .../_expected/es/generated-build-starter.js | 5 +++++ .../_expected/es/main.js | 3 +++ .../_expected/system/buildStart.js | 13 ++++++++++++ .../system/generated-build-starter.js | 12 +++++++++++ .../_expected/system/main.js | 14 +++++++++++++ .../emit-entry-chunk-facade/buildStart.js | 5 +++++ .../samples/emit-entry-chunk-facade/dep.js | 1 + .../samples/emit-entry-chunk-facade/main.js | 3 +++ 17 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 test/chunking-form/samples/emit-entry-chunk-facade/_config.js create mode 100644 test/chunking-form/samples/emit-entry-chunk-facade/_expected/amd/buildStart.js create mode 100644 test/chunking-form/samples/emit-entry-chunk-facade/_expected/amd/generated-build-starter.js create mode 100644 test/chunking-form/samples/emit-entry-chunk-facade/_expected/amd/main.js create mode 100644 test/chunking-form/samples/emit-entry-chunk-facade/_expected/cjs/buildStart.js create mode 100644 test/chunking-form/samples/emit-entry-chunk-facade/_expected/cjs/generated-build-starter.js create mode 100644 test/chunking-form/samples/emit-entry-chunk-facade/_expected/cjs/main.js create mode 100644 test/chunking-form/samples/emit-entry-chunk-facade/_expected/es/buildStart.js create mode 100644 test/chunking-form/samples/emit-entry-chunk-facade/_expected/es/generated-build-starter.js create mode 100644 test/chunking-form/samples/emit-entry-chunk-facade/_expected/es/main.js create mode 100644 test/chunking-form/samples/emit-entry-chunk-facade/_expected/system/buildStart.js create mode 100644 test/chunking-form/samples/emit-entry-chunk-facade/_expected/system/generated-build-starter.js create mode 100644 test/chunking-form/samples/emit-entry-chunk-facade/_expected/system/main.js create mode 100644 test/chunking-form/samples/emit-entry-chunk-facade/buildStart.js create mode 100644 test/chunking-form/samples/emit-entry-chunk-facade/dep.js create mode 100644 test/chunking-form/samples/emit-entry-chunk-facade/main.js diff --git a/src/ModuleLoader.ts b/src/ModuleLoader.ts index 5a51dab72f5..be538c7e0a0 100644 --- a/src/ModuleLoader.ts +++ b/src/ModuleLoader.ts @@ -123,8 +123,9 @@ export class ModuleLoader { code: 'XXX', message: `Plugin error - Unable to get chunk file name for chunk ${metaId}. Ensure that generate is called first.` }); - // TODO Lukas what if this is a facadeChunk? - return entryRecord.module.chunk.id; + return entryRecord.module.facadeChunk + ? entryRecord.module.facadeChunk.id + : entryRecord.module.chunk.id; } private awaitLoadModulesPromise(loadNewModulesPromise: Promise): Promise { diff --git a/test/chunking-form/samples/emit-entry-chunk-facade/_config.js b/test/chunking-form/samples/emit-entry-chunk-facade/_config.js new file mode 100644 index 00000000000..7d4b14b8e1f --- /dev/null +++ b/test/chunking-form/samples/emit-entry-chunk-facade/_config.js @@ -0,0 +1,20 @@ +const assert = require('assert'); +let metaId; + +module.exports = { + description: 'retrieves the correct name of emitted entry chunk in case a facade is created', + options: { + input: 'main', + manualChunks: { + 'build-starter': ['buildStart'] + }, + plugins: { + buildStart() { + metaId = this.emitEntryChunk('buildStart'); + }, + renderChunk() { + assert.strictEqual(this.getChunkFileName(metaId), 'buildStart.js'); + } + } + } +}; diff --git a/test/chunking-form/samples/emit-entry-chunk-facade/_expected/amd/buildStart.js b/test/chunking-form/samples/emit-entry-chunk-facade/_expected/amd/buildStart.js new file mode 100644 index 00000000000..b72b98f383a --- /dev/null +++ b/test/chunking-form/samples/emit-entry-chunk-facade/_expected/amd/buildStart.js @@ -0,0 +1,9 @@ +define(['exports', './generated-build-starter.js'], function (exports, buildStart) { 'use strict'; + + + + exports.buildStartValue = buildStart.value; + + Object.defineProperty(exports, '__esModule', { value: true }); + +}); diff --git a/test/chunking-form/samples/emit-entry-chunk-facade/_expected/amd/generated-build-starter.js b/test/chunking-form/samples/emit-entry-chunk-facade/_expected/amd/generated-build-starter.js new file mode 100644 index 00000000000..432f32da2c3 --- /dev/null +++ b/test/chunking-form/samples/emit-entry-chunk-facade/_expected/amd/generated-build-starter.js @@ -0,0 +1,9 @@ +define(['exports'], function (exports) { 'use strict'; + + var value = 42; + + console.log('startBuild', value); + + exports.value = value; + +}); diff --git a/test/chunking-form/samples/emit-entry-chunk-facade/_expected/amd/main.js b/test/chunking-form/samples/emit-entry-chunk-facade/_expected/amd/main.js new file mode 100644 index 00000000000..e5dd2756bd9 --- /dev/null +++ b/test/chunking-form/samples/emit-entry-chunk-facade/_expected/amd/main.js @@ -0,0 +1,5 @@ +define(['./generated-build-starter.js'], function (buildStart) { 'use strict'; + + console.log('main', buildStart.value); + +}); diff --git a/test/chunking-form/samples/emit-entry-chunk-facade/_expected/cjs/buildStart.js b/test/chunking-form/samples/emit-entry-chunk-facade/_expected/cjs/buildStart.js new file mode 100644 index 00000000000..835455878ac --- /dev/null +++ b/test/chunking-form/samples/emit-entry-chunk-facade/_expected/cjs/buildStart.js @@ -0,0 +1,9 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +var buildStart = require('./generated-build-starter.js'); + + + +exports.buildStartValue = buildStart.value; diff --git a/test/chunking-form/samples/emit-entry-chunk-facade/_expected/cjs/generated-build-starter.js b/test/chunking-form/samples/emit-entry-chunk-facade/_expected/cjs/generated-build-starter.js new file mode 100644 index 00000000000..edbeacb8d71 --- /dev/null +++ b/test/chunking-form/samples/emit-entry-chunk-facade/_expected/cjs/generated-build-starter.js @@ -0,0 +1,7 @@ +'use strict'; + +var value = 42; + +console.log('startBuild', value); + +exports.value = value; diff --git a/test/chunking-form/samples/emit-entry-chunk-facade/_expected/cjs/main.js b/test/chunking-form/samples/emit-entry-chunk-facade/_expected/cjs/main.js new file mode 100644 index 00000000000..828c65c903c --- /dev/null +++ b/test/chunking-form/samples/emit-entry-chunk-facade/_expected/cjs/main.js @@ -0,0 +1,5 @@ +'use strict'; + +var buildStart = require('./generated-build-starter.js'); + +console.log('main', buildStart.value); diff --git a/test/chunking-form/samples/emit-entry-chunk-facade/_expected/es/buildStart.js b/test/chunking-form/samples/emit-entry-chunk-facade/_expected/es/buildStart.js new file mode 100644 index 00000000000..56b50340df5 --- /dev/null +++ b/test/chunking-form/samples/emit-entry-chunk-facade/_expected/es/buildStart.js @@ -0,0 +1 @@ +export { a as buildStartValue } from './generated-build-starter.js'; diff --git a/test/chunking-form/samples/emit-entry-chunk-facade/_expected/es/generated-build-starter.js b/test/chunking-form/samples/emit-entry-chunk-facade/_expected/es/generated-build-starter.js new file mode 100644 index 00000000000..f81734586e0 --- /dev/null +++ b/test/chunking-form/samples/emit-entry-chunk-facade/_expected/es/generated-build-starter.js @@ -0,0 +1,5 @@ +var value = 42; + +console.log('startBuild', value); + +export { value as a }; diff --git a/test/chunking-form/samples/emit-entry-chunk-facade/_expected/es/main.js b/test/chunking-form/samples/emit-entry-chunk-facade/_expected/es/main.js new file mode 100644 index 00000000000..2282b46084d --- /dev/null +++ b/test/chunking-form/samples/emit-entry-chunk-facade/_expected/es/main.js @@ -0,0 +1,3 @@ +import { a as value } from './generated-build-starter.js'; + +console.log('main', value); diff --git a/test/chunking-form/samples/emit-entry-chunk-facade/_expected/system/buildStart.js b/test/chunking-form/samples/emit-entry-chunk-facade/_expected/system/buildStart.js new file mode 100644 index 00000000000..205a5d5e0f8 --- /dev/null +++ b/test/chunking-form/samples/emit-entry-chunk-facade/_expected/system/buildStart.js @@ -0,0 +1,13 @@ +System.register(['./generated-build-starter.js'], function (exports, module) { + 'use strict'; + return { + setters: [function (module) { + exports('buildStartValue', module.a); + }], + execute: function () { + + + + } + }; +}); diff --git a/test/chunking-form/samples/emit-entry-chunk-facade/_expected/system/generated-build-starter.js b/test/chunking-form/samples/emit-entry-chunk-facade/_expected/system/generated-build-starter.js new file mode 100644 index 00000000000..347c480523e --- /dev/null +++ b/test/chunking-form/samples/emit-entry-chunk-facade/_expected/system/generated-build-starter.js @@ -0,0 +1,12 @@ +System.register([], function (exports, module) { + 'use strict'; + return { + execute: function () { + + var value = exports('a', 42); + + console.log('startBuild', value); + + } + }; +}); diff --git a/test/chunking-form/samples/emit-entry-chunk-facade/_expected/system/main.js b/test/chunking-form/samples/emit-entry-chunk-facade/_expected/system/main.js new file mode 100644 index 00000000000..899bb08fbe8 --- /dev/null +++ b/test/chunking-form/samples/emit-entry-chunk-facade/_expected/system/main.js @@ -0,0 +1,14 @@ +System.register(['./generated-build-starter.js'], function (exports, module) { + 'use strict'; + var value; + return { + setters: [function (module) { + value = module.a; + }], + execute: function () { + + console.log('main', value); + + } + }; +}); diff --git a/test/chunking-form/samples/emit-entry-chunk-facade/buildStart.js b/test/chunking-form/samples/emit-entry-chunk-facade/buildStart.js new file mode 100644 index 00000000000..41707ae1ea3 --- /dev/null +++ b/test/chunking-form/samples/emit-entry-chunk-facade/buildStart.js @@ -0,0 +1,5 @@ +import value from './dep.js'; + +console.log('startBuild', value); + +export { value as buildStartValue }; diff --git a/test/chunking-form/samples/emit-entry-chunk-facade/dep.js b/test/chunking-form/samples/emit-entry-chunk-facade/dep.js new file mode 100644 index 00000000000..7a4e8a723a4 --- /dev/null +++ b/test/chunking-form/samples/emit-entry-chunk-facade/dep.js @@ -0,0 +1 @@ +export default 42; diff --git a/test/chunking-form/samples/emit-entry-chunk-facade/main.js b/test/chunking-form/samples/emit-entry-chunk-facade/main.js new file mode 100644 index 00000000000..4a9b3a3f405 --- /dev/null +++ b/test/chunking-form/samples/emit-entry-chunk-facade/main.js @@ -0,0 +1,3 @@ +import value from './dep.js'; + +console.log('main', value); From c90f7d7c8cea40920f244f0c8cbb5b5853c4ba6b Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Mon, 15 Apr 2019 18:57:09 +0200 Subject: [PATCH 23/60] Start using central error handlers --- src/ModuleLoader.ts | 3 +-- src/utils/error.ts | 21 +++++++++++++++++++++ src/utils/errors.ts | 19 ------------------- 3 files changed, 22 insertions(+), 21 deletions(-) delete mode 100644 src/utils/errors.ts diff --git a/src/ModuleLoader.ts b/src/ModuleLoader.ts index be538c7e0a0..68b17cf64b2 100644 --- a/src/ModuleLoader.ts +++ b/src/ModuleLoader.ts @@ -2,8 +2,7 @@ import ExternalModule from './ExternalModule'; import Graph from './Graph'; import Module from './Module'; import { ModuleJSON, ResolvedId, ResolveIdResult, SourceDescription } from './rollup/types'; -import { error } from './utils/error'; -import { errorCannotAssignModuleToChunk } from './utils/errors'; +import { error, errorCannotAssignModuleToChunk } from './utils/error'; import { addWithNewMetaId } from './utils/metaIds'; import { isRelative, resolve } from './utils/path'; import { PluginDriver } from './utils/pluginDriver'; diff --git a/src/utils/error.ts b/src/utils/error.ts index d32b3d56ee8..bf787954c6e 100644 --- a/src/utils/error.ts +++ b/src/utils/error.ts @@ -1,6 +1,7 @@ import { locate } from 'locate-character'; import { RollupError, RollupWarning } from '../rollup/types'; import getCodeFrame from './getCodeFrame'; +import { relative } from './path'; export function error(base: Error | RollupError, props?: RollupError) { if (base instanceof Error === false) base = Object.assign(new Error(base.message), base); @@ -28,3 +29,23 @@ export function augmentCodeLocation( object.frame = getCodeFrame(source, line, column); } } + +enum Errors { + INVALID_CHUNK = 'INVALID_CHUNK' +} + +// TODO Lukas polyfill process.cwd() +// TODO Lukas other errors +export function errorCannotAssignModuleToChunk( + moduleId: string, + assignToAlias: string, + currentAlias: string +) { + error({ + code: Errors.INVALID_CHUNK, + message: `Cannot assign ${relative( + process.cwd(), + moduleId + )} to the "${assignToAlias}" chunk as it is already in the "${currentAlias}" chunk.` + }); +} diff --git a/src/utils/errors.ts b/src/utils/errors.ts deleted file mode 100644 index 95e003999a8..00000000000 --- a/src/utils/errors.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { error } from './error'; -import { relative } from './path'; - -// TODO Lukas polyfill process.cwd() -// TODO Lukas error constant enum -// TODO Lukas other errors -export function errorCannotAssignModuleToChunk( - moduleId: string, - assignToAlias: string, - currentAlias: string -) { - error({ - code: 'INVALID_CHUNK', - message: `Cannot assign ${relative( - process.cwd(), - moduleId - )} to the "${assignToAlias}" chunk as it is already in the "${currentAlias}" chunk.` - }); -} From 27cdcdadfbcf4c645826489acdbfab38329505cf Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Tue, 16 Apr 2019 09:51:18 +0200 Subject: [PATCH 24/60] Improve plugin driver type, add generic resolveFileUrl hook --- src/ModuleLoader.ts | 71 +++++++++++++++++--------------- src/ast/nodes/MetaProperty.ts | 76 +++++++++++++++++------------------ src/rollup/index.ts | 4 +- src/rollup/types.d.ts | 44 +++++++++++++------- src/utils/assetHooks.ts | 8 ++-- src/utils/defaultPlugin.ts | 7 +--- src/utils/pluginDriver.ts | 50 +++++++++++++++++------ 7 files changed, 151 insertions(+), 109 deletions(-) diff --git a/src/ModuleLoader.ts b/src/ModuleLoader.ts index 68b17cf64b2..5da5d97f582 100644 --- a/src/ModuleLoader.ts +++ b/src/ModuleLoader.ts @@ -1,3 +1,4 @@ +import * as ESTree from 'estree'; import ExternalModule from './ExternalModule'; import Graph from './Graph'; import Module from './Module'; @@ -148,8 +149,12 @@ export class ModuleLoader { private fetchAllDependencies(module: Module) { const fetchDynamicImportsPromise = Promise.all( module.getDynamicImportExpressions().map((dynamicImportExpression, index) => + // TODO we only should expose the acorn AST here this.pluginDriver - .hookFirst('resolveDynamicImport', [dynamicImportExpression, module.id]) + .hookFirst<'resolveDynamicImport', string>('resolveDynamicImport', [ + dynamicImportExpression as string | ESTree.Node, + module.id + ]) .then(replacement => { if (!replacement) return; const dynamicImport = module.dynamicImports[index]; @@ -195,7 +200,9 @@ export class ModuleLoader { this.modulesById.set(id, module); timeStart('load modules', 3); - return Promise.resolve(this.pluginDriver.hookFirst('load', [id])) + return Promise.resolve( + this.pluginDriver.hookFirst<'load', string | SourceDescription>('load', [id]) + ) .catch((err: Error) => { timeEnd('load modules', 3); let msg = `Could not load ${id}`; @@ -287,40 +294,38 @@ export class ModuleLoader { unresolvedId, isManualChunkEntry }: UnresolvedEntryModuleWithAlias): Promise => { - return this.pluginDriver - .hookFirst('resolveId', [unresolvedId, undefined]) - .then(id => { - if (id === false) { - error({ - code: 'UNRESOLVED_ENTRY', - message: `Entry module cannot be external` - }); - } + return this.pluginDriver.hookFirst('resolveId', [unresolvedId, undefined]).then(id => { + if (id === false) { + error({ + code: 'UNRESOLVED_ENTRY', + message: `Entry module cannot be external` + }); + } - if (id == null) { - error({ - code: 'UNRESOLVED_ENTRY', - message: `Could not resolve entry (${unresolvedId})` - }); - } + if (id == null) { + error({ + code: 'UNRESOLVED_ENTRY', + message: `Could not resolve entry (${unresolvedId})` + }); + } - return this.fetchModule(id, undefined).then(module => { - if (alias !== null) { - if (isManualChunkEntry) { - if (module.manualChunkAlias !== null && module.manualChunkAlias !== alias) { - errorCannotAssignModuleToChunk(module.id, alias, module.manualChunkAlias); - } - module.manualChunkAlias = alias; - return module; - } - if (module.chunkAlias !== null && module.chunkAlias !== alias) { - errorCannotAssignModuleToChunk(module.id, alias, module.chunkAlias); + return this.fetchModule(id, undefined).then(module => { + if (alias !== null) { + if (isManualChunkEntry) { + if (module.manualChunkAlias !== null && module.manualChunkAlias !== alias) { + errorCannotAssignModuleToChunk(module.id, alias, module.manualChunkAlias); } - module.chunkAlias = alias; + module.manualChunkAlias = alias; + return module; } - return module; - }); + if (module.chunkAlias !== null && module.chunkAlias !== alias) { + errorCannotAssignModuleToChunk(module.id, alias, module.chunkAlias); + } + module.chunkAlias = alias; + } + return module; }); + }); }; private normalizeResolveIdResult( @@ -375,8 +380,8 @@ export class ModuleLoader { Promise.resolve( this.graph.isExternal(source, module.id, false) ? { id: source, external: true } - : this.pluginDriver.hookFirst('resolveId', [source, module.id]) - ).then(result => this.normalizeResolveIdResult(result, module, source)) + : this.pluginDriver.hookFirst('resolveId', [source, module.id]) + ).then((result: ResolveIdResult) => this.normalizeResolveIdResult(result, module, source)) ).then(resolvedId => { module.resolvedIds[source] = resolvedId; if (resolvedId.external) { diff --git a/src/ast/nodes/MetaProperty.ts b/src/ast/nodes/MetaProperty.ts index 0f804009056..12df25f58a9 100644 --- a/src/ast/nodes/MetaProperty.ts +++ b/src/ast/nodes/MetaProperty.ts @@ -1,4 +1,5 @@ import MagicString from 'magic-string'; +import { EmittedFileType } from '../../rollup/types'; import { dirname, normalize, relative } from '../../utils/path'; import { PluginDriver } from '../../utils/pluginDriver'; import Identifier from './Identifier'; @@ -34,44 +35,43 @@ export default class MetaProperty extends NodeBase { ? parent.propertyKey : null; - // TODO Lukas extract, use same hook - if (importMetaProperty && importMetaProperty.startsWith(ASSET_PREFIX)) { - const assetFileName = this.context.getAssetFileName( - importMetaProperty.substr(ASSET_PREFIX.length) - ); - const relativeAssetPath = normalize(relative(dirname(chunkId), assetFileName)); - const replacement = pluginDriver.hookFirstSync('resolveAssetUrl', [ - { - assetFileName, - chunkId, - format, - moduleId: this.context.module.id, - relativeAssetPath - } - ]); - - code.overwrite( - (parent as MemberExpression).start, - (parent as MemberExpression).end, - replacement - ); - return true; - } + // TODO Lukas duplicate asset tests with new hook + if ( + importMetaProperty && + (importMetaProperty.startsWith(ASSET_PREFIX) || importMetaProperty.startsWith(CHUNK_PREFIX)) + ) { + const [type, fileName]: [EmittedFileType, string] = importMetaProperty.startsWith( + ASSET_PREFIX + ) + ? ['ASSET', this.context.getAssetFileName(importMetaProperty.substr(ASSET_PREFIX.length))] + : ['CHUNK', this.context.getChunkFileName(importMetaProperty.substr(CHUNK_PREFIX.length))]; - if (importMetaProperty && importMetaProperty.startsWith(CHUNK_PREFIX)) { - const chunkFileName = this.context.getChunkFileName( - importMetaProperty.substr(CHUNK_PREFIX.length) - ); - const relativeChunkPath = normalize(relative(dirname(chunkId), chunkFileName)); - const replacement = pluginDriver.hookFirstSync('resolveChunkUrl', [ - { - chunkFileName, - chunkId, - format, - moduleId: this.context.module.id, - relativeChunkPath - } - ]); + const relativePath = normalize(relative(dirname(chunkId), fileName)); + let replacement; + if (type === 'ASSET') { + // deprecated hook for assets + replacement = pluginDriver.hookFirstSync('resolveAssetUrl', [ + { + assetFileName: fileName, + chunkId, + format, + moduleId: this.context.module.id, + relativeAssetPath: relativePath + } + ]); + } + if (!replacement) { + replacement = pluginDriver.hookFirstSync<'resolveFileUrl', string>('resolveFileUrl', [ + { + chunkId, + fileName, + format, + moduleId: this.context.module.id, + relativePath, + type + } + ]); + } code.overwrite( (parent as MemberExpression).start, @@ -81,7 +81,7 @@ export default class MetaProperty extends NodeBase { return true; } - const replacement = pluginDriver.hookFirstSync('resolveImportMeta', [ + const replacement = pluginDriver.hookFirstSync('resolveImportMeta', [ importMetaProperty, { chunkId, diff --git a/src/rollup/index.ts b/src/rollup/index.ts index 705369eee6a..a98543e6a05 100644 --- a/src/rollup/index.ts +++ b/src/rollup/index.ts @@ -156,7 +156,7 @@ export default function rollup(rawInputOptions: GenericConfigObject): Promise graph.pluginDriver.hookParallel('buildEnd').then(() => chunks), + chunks => graph.pluginDriver.hookParallel('buildEnd', []).then(() => chunks), err => graph.pluginDriver.hookParallel('buildEnd', [err]).then(() => { throw err; @@ -185,7 +185,7 @@ export default function rollup(rawInputOptions: GenericConfigObject): Promise createAddons(graph, outputOptions)) .then(addons => { // pre-render all chunks diff --git a/src/rollup/types.d.ts b/src/rollup/types.d.ts index 5c2f40e3c6f..b29c202c699 100644 --- a/src/rollup/types.d.ts +++ b/src/rollup/types.d.ts @@ -62,12 +62,12 @@ export interface SourceMap { } export interface SourceDescription { + ast?: ESTree.Program; code: string; map?: string | RawSourceMap; } export interface TransformSourceDescription extends SourceDescription { - ast?: ESTree.Program; dependencies?: string[]; } @@ -213,14 +213,18 @@ export type ResolveAssetUrlHook = ( } ) => string | void; -export type ResolveChunkUrlHook = ( +type EmittedFileType = 'ASSET' | 'CHUNK'; + +// TODO Lukas are all properties tested? +export type ResolveFileUrlHook = ( this: PluginContext, options: { - chunkFileName: string; chunkId: string; + fileName: string; format: string; moduleId: string; - relativeChunkPath: string; + relativePath: string; + type: EmittedFileType; } ) => string | void; @@ -242,42 +246,45 @@ export interface OutputBundle { [fileName: string]: OutputAsset | OutputChunk; } -export interface Plugin { - banner?: AddonHook; +interface OnGenerateOptions extends OutputOptions { + bundle: OutputChunk; +} + +interface OnWriteOptions extends OutputOptions { + bundle: RollupBuild; +} + +export interface PluginHooks { buildEnd?: (this: PluginContext, err?: Error) => Promise | void; buildStart?: (this: PluginContext, options: InputOptions) => Promise | void; - cacheKey?: string; - footer?: AddonHook; generateBundle?: ( this: PluginContext, options: OutputOptions, bundle: OutputBundle, isWrite: boolean ) => void | Promise; - intro?: AddonHook; load?: LoadHook; - name: string; /** @deprecated */ ongenerate?: ( this: PluginContext, - options: OutputOptions, + options: OnGenerateOptions, chunk: OutputChunk ) => void | Promise; /** @deprecated */ onwrite?: ( this: PluginContext, - options: OutputOptions, + options: OnWriteOptions, chunk: OutputChunk ) => void | Promise; options?: (this: MinimalPluginContext, options: InputOptions) => InputOptions | void | null; outputOptions?: (this: PluginContext, options: OutputOptions) => OutputOptions | void | null; - outro?: AddonHook; renderChunk?: RenderChunkHook; renderError?: (this: PluginContext, err?: Error) => Promise | void; renderStart?: (this: PluginContext) => Promise | void; + /** @deprecated */ resolveAssetUrl?: ResolveAssetUrlHook; - resolveChunkUrl?: ResolveChunkUrlHook; resolveDynamicImport?: ResolveDynamicImportHook; + resolveFileUrl?: ResolveFileUrlHook; resolveId?: ResolveIdHook; resolveImportMeta?: ResolveImportMetaHook; transform?: TransformHook; @@ -289,6 +296,15 @@ export interface Plugin { writeBundle?: (this: PluginContext, bundle: OutputBundle) => void | Promise; } +export interface Plugin extends PluginHooks { + banner?: AddonHook; + cacheKey?: string; + footer?: AddonHook; + intro?: AddonHook; + name: string; + outro?: AddonHook; +} + export interface TreeshakingOptions { annotations?: boolean; propertyReadSideEffects?: boolean; diff --git a/src/utils/assetHooks.ts b/src/utils/assetHooks.ts index 89cc912c8d6..55951b3985c 100644 --- a/src/utils/assetHooks.ts +++ b/src/utils/assetHooks.ts @@ -56,6 +56,7 @@ export function createAssetPluginHooks( if (outputBundle && source !== undefined) finaliseAsset(asset, outputBundle, assetFileNames); return addWithNewMetaId(asset, assetsByMetaId, name); }, + setAssetSource(assetMetaId: string, source?: string | Buffer) { const asset = assetsByMetaId.get(assetMetaId); if (!asset) @@ -78,7 +79,7 @@ export function createAssetPluginHooks( asset.source = source; if (outputBundle) finaliseAsset(asset, outputBundle, assetFileNames); }, - // TODO Lukas we also need this for chunks. Can this be shared? + getAssetFileName(assetMetaId: string) { const asset = assetsByMetaId.get(assetMetaId); if (!asset) @@ -106,14 +107,13 @@ export function finaliseAsset(asset: Asset, outputBundle: OutputBundle, assetFil }; } -export function createTransformEmitAsset(assetsById: Map, emitAsset: EmitAsset) { +export function createTransformEmitAsset(assetsByMetaId: Map, emitAsset: EmitAsset) { const assets: Asset[] = []; return { assets, emitAsset: (name: string, source?: string | Buffer) => { const assetMetaId = emitAsset(name, source); - const asset = assetsById.get(assetMetaId); - // distinguish transform assets + const asset = assetsByMetaId.get(assetMetaId); assets.push({ fileName: undefined, name: asset.name, diff --git a/src/utils/defaultPlugin.ts b/src/utils/defaultPlugin.ts index 2b86d05c3cb..9d938cb350c 100644 --- a/src/utils/defaultPlugin.ts +++ b/src/utils/defaultPlugin.ts @@ -14,11 +14,8 @@ export function getRollupDefaultPlugin(options: InputOptions): Plugin { if (typeof specifier === 'string' && !this.isExternal(specifier, parentId, false)) return >this.resolveId(specifier, parentId); }, - resolveAssetUrl({ relativeAssetPath, format }) { - return relativeUrlMechanisms[format](relativeAssetPath); - }, - resolveChunkUrl({ relativeChunkPath, format }) { - return relativeUrlMechanisms[format](relativeChunkPath); + resolveFileUrl({ relativePath, format }) { + return relativeUrlMechanisms[format](relativePath); }, resolveImportMeta(prop, { chunkId, format }) { const mechanism = importMetaMechanisms[format] && importMetaMechanisms[format](prop, chunkId); diff --git a/src/utils/pluginDriver.ts b/src/utils/pluginDriver.ts index b1cff8b17a6..eb2602bd4af 100644 --- a/src/utils/pluginDriver.ts +++ b/src/utils/pluginDriver.ts @@ -8,6 +8,7 @@ import { Plugin, PluginCache, PluginContext, + PluginHooks, RollupError, RollupWarning, RollupWatcher, @@ -18,25 +19,40 @@ import { getRollupDefaultPlugin } from './defaultPlugin'; import { error } from './error'; import { NameCollection } from './reservedNames'; +type Args = T extends (...args: infer K) => any ? K : never; + +// TODO Lukas include defaultPlugin type export interface PluginDriver { emitAsset: EmitAsset; hasLoadersOrTransforms: boolean; getAssetFileName(assetMetaId: string): string; - hookFirst(hook: string, args?: any[], hookContext?: HookContext): Promise; - hookFirstSync(hook: string, args?: any[], hookContext?: HookContext): T; - hookParallel(hook: string, args?: any[], hookContext?: HookContext): Promise; - hookReduceArg0( - hook: string, + hookFirst>( + hook: H, + args: Args, + hookContext?: HookContext + ): Promise; + hookFirstSync>( + hook: H, + args: Args, + hookContext?: HookContext + ): R; + hookParallel( + hook: H, + args: Args, + hookContext?: HookContext + ): Promise; + hookReduceArg0>( + hook: H, args: any[], - reduce: Reduce, + reduce: Reduce, hookContext?: HookContext - ): Promise; - hookReduceArg0Sync( - hook: string, + ): Promise; + hookReduceArg0Sync>( + hook: H, args: any[], - reduce: Reduce, + reduce: Reduce, hookContext?: HookContext - ): T; + ): R; hookReduceValue( hook: string, value: T | Promise, @@ -44,8 +60,16 @@ export interface PluginDriver { reduce: Reduce, hookContext?: HookContext ): Promise; - hookSeq(hook: string, args?: any[], context?: HookContext): Promise; - hookSeqSync(hook: string, args?: any[], context?: HookContext): void; + hookSeq( + hook: H, + args: Args, + context?: HookContext + ): Promise; + hookSeqSync( + hook: H, + args: Args, + context?: HookContext + ): void; } export type Reduce = (reduction: T, result: R, plugin: Plugin) => T; From 32d3e53605178d4ddc5fe3cf53458465f9c2240f Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Wed, 17 Apr 2019 06:48:39 +0200 Subject: [PATCH 25/60] Test new resolveFileUrl hook, make meta properties tree-shakeable --- src/ast/nodes/MetaProperty.ts | 6 ++- .../samples/configure-file-url/_config.js | 47 +++++++++++++++++++ .../amd/assets/asset-resolved-dfc93baf.txt | 1 + .../amd/assets/asset-solved-9b321da2.txt | 1 + .../amd/assets/asset-unresolved-9548436d.txt | 1 + .../configure-file-url/_expected/amd/chunk.js | 5 ++ .../configure-file-url/_expected/amd/main.js | 11 +++++ .../_expected/amd/nested/chunk.js | 9 ++++ .../cjs/assets/asset-resolved-dfc93baf.txt | 1 + .../cjs/assets/asset-solved-9b321da2.txt | 1 + .../cjs/assets/asset-unresolved-9548436d.txt | 1 + .../configure-file-url/_expected/cjs/chunk.js | 3 ++ .../configure-file-url/_expected/cjs/main.js | 9 ++++ .../_expected/cjs/nested/chunk.js | 7 +++ .../es/assets/asset-resolved-dfc93baf.txt | 1 + .../es/assets/asset-solved-9b321da2.txt | 1 + .../es/assets/asset-unresolved-9548436d.txt | 1 + .../configure-file-url/_expected/es/chunk.js | 1 + .../configure-file-url/_expected/es/main.js | 7 +++ .../_expected/es/nested/chunk.js | 4 ++ .../system/assets/asset-resolved-dfc93baf.txt | 1 + .../system/assets/asset-solved-9b321da2.txt | 1 + .../assets/asset-unresolved-9548436d.txt | 1 + .../_expected/system/chunk.js | 10 ++++ .../_expected/system/main.js | 16 +++++++ .../_expected/system/nested/chunk.js | 11 +++++ .../samples/configure-file-url/chunk.js | 1 + .../samples/configure-file-url/main.js | 5 ++ .../samples/configure-file-url/_config.js | 40 ++++++++++++++++ .../configure-file-url/_expected/amd.js | 11 +++++ .../assets/asset-resolved-dfc93baf.txt | 1 + .../assets/asset-solved-9b321da2.txt | 1 + .../assets/asset-unresolved-9548436d.txt | 1 + .../configure-file-url/_expected/cjs.js | 9 ++++ .../configure-file-url/_expected/es.js | 7 +++ .../configure-file-url/_expected/iife.js | 12 +++++ .../configure-file-url/_expected/system.js | 16 +++++++ .../configure-file-url/_expected/umd.js | 14 ++++++ test/form/samples/configure-file-url/main.js | 5 ++ .../samples/treeshake-import-meta/_config.js | 3 ++ .../treeshake-import-meta/_expected.js | 1 + .../samples/treeshake-import-meta/main.js | 4 ++ 42 files changed, 288 insertions(+), 1 deletion(-) create mode 100644 test/chunking-form/samples/configure-file-url/_config.js create mode 100644 test/chunking-form/samples/configure-file-url/_expected/amd/assets/asset-resolved-dfc93baf.txt create mode 100644 test/chunking-form/samples/configure-file-url/_expected/amd/assets/asset-solved-9b321da2.txt create mode 100644 test/chunking-form/samples/configure-file-url/_expected/amd/assets/asset-unresolved-9548436d.txt create mode 100644 test/chunking-form/samples/configure-file-url/_expected/amd/chunk.js create mode 100644 test/chunking-form/samples/configure-file-url/_expected/amd/main.js create mode 100644 test/chunking-form/samples/configure-file-url/_expected/amd/nested/chunk.js create mode 100644 test/chunking-form/samples/configure-file-url/_expected/cjs/assets/asset-resolved-dfc93baf.txt create mode 100644 test/chunking-form/samples/configure-file-url/_expected/cjs/assets/asset-solved-9b321da2.txt create mode 100644 test/chunking-form/samples/configure-file-url/_expected/cjs/assets/asset-unresolved-9548436d.txt create mode 100644 test/chunking-form/samples/configure-file-url/_expected/cjs/chunk.js create mode 100644 test/chunking-form/samples/configure-file-url/_expected/cjs/main.js create mode 100644 test/chunking-form/samples/configure-file-url/_expected/cjs/nested/chunk.js create mode 100644 test/chunking-form/samples/configure-file-url/_expected/es/assets/asset-resolved-dfc93baf.txt create mode 100644 test/chunking-form/samples/configure-file-url/_expected/es/assets/asset-solved-9b321da2.txt create mode 100644 test/chunking-form/samples/configure-file-url/_expected/es/assets/asset-unresolved-9548436d.txt create mode 100644 test/chunking-form/samples/configure-file-url/_expected/es/chunk.js create mode 100644 test/chunking-form/samples/configure-file-url/_expected/es/main.js create mode 100644 test/chunking-form/samples/configure-file-url/_expected/es/nested/chunk.js create mode 100644 test/chunking-form/samples/configure-file-url/_expected/system/assets/asset-resolved-dfc93baf.txt create mode 100644 test/chunking-form/samples/configure-file-url/_expected/system/assets/asset-solved-9b321da2.txt create mode 100644 test/chunking-form/samples/configure-file-url/_expected/system/assets/asset-unresolved-9548436d.txt create mode 100644 test/chunking-form/samples/configure-file-url/_expected/system/chunk.js create mode 100644 test/chunking-form/samples/configure-file-url/_expected/system/main.js create mode 100644 test/chunking-form/samples/configure-file-url/_expected/system/nested/chunk.js create mode 100644 test/chunking-form/samples/configure-file-url/chunk.js create mode 100644 test/chunking-form/samples/configure-file-url/main.js create mode 100644 test/form/samples/configure-file-url/_config.js create mode 100644 test/form/samples/configure-file-url/_expected/amd.js create mode 100644 test/form/samples/configure-file-url/_expected/assets/asset-resolved-dfc93baf.txt create mode 100644 test/form/samples/configure-file-url/_expected/assets/asset-solved-9b321da2.txt create mode 100644 test/form/samples/configure-file-url/_expected/assets/asset-unresolved-9548436d.txt create mode 100644 test/form/samples/configure-file-url/_expected/cjs.js create mode 100644 test/form/samples/configure-file-url/_expected/es.js create mode 100644 test/form/samples/configure-file-url/_expected/iife.js create mode 100644 test/form/samples/configure-file-url/_expected/system.js create mode 100644 test/form/samples/configure-file-url/_expected/umd.js create mode 100644 test/form/samples/configure-file-url/main.js create mode 100644 test/form/samples/treeshake-import-meta/_config.js create mode 100644 test/form/samples/treeshake-import-meta/_expected.js create mode 100644 test/form/samples/treeshake-import-meta/main.js diff --git a/src/ast/nodes/MetaProperty.ts b/src/ast/nodes/MetaProperty.ts index 12df25f58a9..5f1a45a072c 100644 --- a/src/ast/nodes/MetaProperty.ts +++ b/src/ast/nodes/MetaProperty.ts @@ -2,6 +2,7 @@ import MagicString from 'magic-string'; import { EmittedFileType } from '../../rollup/types'; import { dirname, normalize, relative } from '../../utils/path'; import { PluginDriver } from '../../utils/pluginDriver'; +import { ObjectPathKey } from '../values'; import Identifier from './Identifier'; import MemberExpression from './MemberExpression'; import * as NodeType from './NodeType'; @@ -15,6 +16,10 @@ export default class MetaProperty extends NodeBase { property: Identifier; type: NodeType.tMetaProperty; + hasEffectsWhenAccessedAtPath(path: ObjectPathKey[]): boolean { + return path.length > 1; + } + initialise() { if (this.meta.name === 'import') { this.context.addImportMeta(this); @@ -35,7 +40,6 @@ export default class MetaProperty extends NodeBase { ? parent.propertyKey : null; - // TODO Lukas duplicate asset tests with new hook if ( importMetaProperty && (importMetaProperty.startsWith(ASSET_PREFIX) || importMetaProperty.startsWith(CHUNK_PREFIX)) diff --git a/test/chunking-form/samples/configure-file-url/_config.js b/test/chunking-form/samples/configure-file-url/_config.js new file mode 100644 index 00000000000..4cb2654b529 --- /dev/null +++ b/test/chunking-form/samples/configure-file-url/_config.js @@ -0,0 +1,47 @@ +module.exports = { + description: 'allows to configure file urls', + options: { + output: { + chunkFileNames: 'nested/chunk.js' + }, + plugins: [ + { + resolveId(id) { + if (id.endsWith('solved')) { + return id; + } + }, + load(id) { + if (id.endsWith('solved')) { + const assetId = this.emitAsset(`asset-${id}.txt`, `Asset for: ${id}`); + const chunkId = this.emitEntryChunk('chunk.js'); + return ( + `export const asset = import.meta.ROLLUP_ASSET_URL_${assetId};\n` + + `export const chunk = import.meta.ROLLUP_CHUNK_URL_${chunkId};` + ); + } + }, + resolveFileUrl({ chunkId, fileName, format, moduleId, relativePath, type }) { + if (!moduleId.endsWith('resolved')) { + return `'chunkId=${chunkId}:moduleId=${moduleId + .replace(/\\/g, '/') + .split('/') + .slice(-2) + .join( + '/' + )}:fileName=${fileName}:format=${format}:relativePath=${relativePath}:type=${type}'`; + } + return null; + } + }, + { + resolveFileUrl({ moduleId }) { + if (moduleId === 'resolved') { + return `'resolved'`; + } + return null; + } + } + ] + } +}; diff --git a/test/chunking-form/samples/configure-file-url/_expected/amd/assets/asset-resolved-dfc93baf.txt b/test/chunking-form/samples/configure-file-url/_expected/amd/assets/asset-resolved-dfc93baf.txt new file mode 100644 index 00000000000..31fb300f988 --- /dev/null +++ b/test/chunking-form/samples/configure-file-url/_expected/amd/assets/asset-resolved-dfc93baf.txt @@ -0,0 +1 @@ +Asset for: resolved \ No newline at end of file diff --git a/test/chunking-form/samples/configure-file-url/_expected/amd/assets/asset-solved-9b321da2.txt b/test/chunking-form/samples/configure-file-url/_expected/amd/assets/asset-solved-9b321da2.txt new file mode 100644 index 00000000000..07c7a096c7e --- /dev/null +++ b/test/chunking-form/samples/configure-file-url/_expected/amd/assets/asset-solved-9b321da2.txt @@ -0,0 +1 @@ +Asset for: solved \ No newline at end of file diff --git a/test/chunking-form/samples/configure-file-url/_expected/amd/assets/asset-unresolved-9548436d.txt b/test/chunking-form/samples/configure-file-url/_expected/amd/assets/asset-unresolved-9548436d.txt new file mode 100644 index 00000000000..fd3ad6261cc --- /dev/null +++ b/test/chunking-form/samples/configure-file-url/_expected/amd/assets/asset-unresolved-9548436d.txt @@ -0,0 +1 @@ +Asset for: unresolved \ No newline at end of file diff --git a/test/chunking-form/samples/configure-file-url/_expected/amd/chunk.js b/test/chunking-form/samples/configure-file-url/_expected/amd/chunk.js new file mode 100644 index 00000000000..32f0814a584 --- /dev/null +++ b/test/chunking-form/samples/configure-file-url/_expected/amd/chunk.js @@ -0,0 +1,5 @@ +define(function () { 'use strict'; + + console.log('chunk'); + +}); diff --git a/test/chunking-form/samples/configure-file-url/_expected/amd/main.js b/test/chunking-form/samples/configure-file-url/_expected/amd/main.js new file mode 100644 index 00000000000..7fd64cc10db --- /dev/null +++ b/test/chunking-form/samples/configure-file-url/_expected/amd/main.js @@ -0,0 +1,11 @@ +define(['module', 'require'], function (module, require) { 'use strict'; + + const asset = 'resolved'; + const chunk = 'resolved'; + + const asset$1 = new URL(module.uri + '/../assets/asset-unresolved-9548436d.txt', document.baseURI).href; + const chunk$1 = new URL(module.uri + '/../chunk.js', document.baseURI).href; + + new Promise(function (resolve, reject) { require(['./nested/chunk.js'], resolve, reject) }).then(result => console.log(result, chunk, chunk$1, asset, asset$1)); + +}); diff --git a/test/chunking-form/samples/configure-file-url/_expected/amd/nested/chunk.js b/test/chunking-form/samples/configure-file-url/_expected/amd/nested/chunk.js new file mode 100644 index 00000000000..0125d6ff8cd --- /dev/null +++ b/test/chunking-form/samples/configure-file-url/_expected/amd/nested/chunk.js @@ -0,0 +1,9 @@ +define(['module', 'exports'], function (module, exports) { 'use strict'; + + const asset = 'chunkId=nested/chunk.js:moduleId=solved:fileName=assets/asset-solved-9b321da2.txt:format=amd:relativePath=../assets/asset-solved-9b321da2.txt:type=ASSET' + const chunk = 'chunkId=nested/chunk.js:moduleId=solved:fileName=chunk.js:format=amd:relativePath=../chunk.js:type=CHUNK' + + exports.asset = asset; + exports.chunk = chunk; + +}); diff --git a/test/chunking-form/samples/configure-file-url/_expected/cjs/assets/asset-resolved-dfc93baf.txt b/test/chunking-form/samples/configure-file-url/_expected/cjs/assets/asset-resolved-dfc93baf.txt new file mode 100644 index 00000000000..31fb300f988 --- /dev/null +++ b/test/chunking-form/samples/configure-file-url/_expected/cjs/assets/asset-resolved-dfc93baf.txt @@ -0,0 +1 @@ +Asset for: resolved \ No newline at end of file diff --git a/test/chunking-form/samples/configure-file-url/_expected/cjs/assets/asset-solved-9b321da2.txt b/test/chunking-form/samples/configure-file-url/_expected/cjs/assets/asset-solved-9b321da2.txt new file mode 100644 index 00000000000..07c7a096c7e --- /dev/null +++ b/test/chunking-form/samples/configure-file-url/_expected/cjs/assets/asset-solved-9b321da2.txt @@ -0,0 +1 @@ +Asset for: solved \ No newline at end of file diff --git a/test/chunking-form/samples/configure-file-url/_expected/cjs/assets/asset-unresolved-9548436d.txt b/test/chunking-form/samples/configure-file-url/_expected/cjs/assets/asset-unresolved-9548436d.txt new file mode 100644 index 00000000000..fd3ad6261cc --- /dev/null +++ b/test/chunking-form/samples/configure-file-url/_expected/cjs/assets/asset-unresolved-9548436d.txt @@ -0,0 +1 @@ +Asset for: unresolved \ No newline at end of file diff --git a/test/chunking-form/samples/configure-file-url/_expected/cjs/chunk.js b/test/chunking-form/samples/configure-file-url/_expected/cjs/chunk.js new file mode 100644 index 00000000000..9bd6f06e964 --- /dev/null +++ b/test/chunking-form/samples/configure-file-url/_expected/cjs/chunk.js @@ -0,0 +1,3 @@ +'use strict'; + +console.log('chunk'); diff --git a/test/chunking-form/samples/configure-file-url/_expected/cjs/main.js b/test/chunking-form/samples/configure-file-url/_expected/cjs/main.js new file mode 100644 index 00000000000..3575b0dd1f1 --- /dev/null +++ b/test/chunking-form/samples/configure-file-url/_expected/cjs/main.js @@ -0,0 +1,9 @@ +'use strict'; + +const asset = 'resolved'; +const chunk = 'resolved'; + +const asset$1 = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/asset-unresolved-9548436d.txt').href : new URL((document.currentScript && document.currentScript.src || document.baseURI) + '/../assets/asset-unresolved-9548436d.txt').href); +const chunk$1 = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/chunk.js').href : new URL((document.currentScript && document.currentScript.src || document.baseURI) + '/../chunk.js').href); + +Promise.resolve(require('./nested/chunk.js')).then(result => console.log(result, chunk, chunk$1, asset, asset$1)); diff --git a/test/chunking-form/samples/configure-file-url/_expected/cjs/nested/chunk.js b/test/chunking-form/samples/configure-file-url/_expected/cjs/nested/chunk.js new file mode 100644 index 00000000000..019ff7dcfd0 --- /dev/null +++ b/test/chunking-form/samples/configure-file-url/_expected/cjs/nested/chunk.js @@ -0,0 +1,7 @@ +'use strict'; + +const asset = 'chunkId=nested/chunk.js:moduleId=solved:fileName=assets/asset-solved-9b321da2.txt:format=cjs:relativePath=../assets/asset-solved-9b321da2.txt:type=ASSET' +const chunk = 'chunkId=nested/chunk.js:moduleId=solved:fileName=chunk.js:format=cjs:relativePath=../chunk.js:type=CHUNK' + +exports.asset = asset; +exports.chunk = chunk; diff --git a/test/chunking-form/samples/configure-file-url/_expected/es/assets/asset-resolved-dfc93baf.txt b/test/chunking-form/samples/configure-file-url/_expected/es/assets/asset-resolved-dfc93baf.txt new file mode 100644 index 00000000000..31fb300f988 --- /dev/null +++ b/test/chunking-form/samples/configure-file-url/_expected/es/assets/asset-resolved-dfc93baf.txt @@ -0,0 +1 @@ +Asset for: resolved \ No newline at end of file diff --git a/test/chunking-form/samples/configure-file-url/_expected/es/assets/asset-solved-9b321da2.txt b/test/chunking-form/samples/configure-file-url/_expected/es/assets/asset-solved-9b321da2.txt new file mode 100644 index 00000000000..07c7a096c7e --- /dev/null +++ b/test/chunking-form/samples/configure-file-url/_expected/es/assets/asset-solved-9b321da2.txt @@ -0,0 +1 @@ +Asset for: solved \ No newline at end of file diff --git a/test/chunking-form/samples/configure-file-url/_expected/es/assets/asset-unresolved-9548436d.txt b/test/chunking-form/samples/configure-file-url/_expected/es/assets/asset-unresolved-9548436d.txt new file mode 100644 index 00000000000..fd3ad6261cc --- /dev/null +++ b/test/chunking-form/samples/configure-file-url/_expected/es/assets/asset-unresolved-9548436d.txt @@ -0,0 +1 @@ +Asset for: unresolved \ No newline at end of file diff --git a/test/chunking-form/samples/configure-file-url/_expected/es/chunk.js b/test/chunking-form/samples/configure-file-url/_expected/es/chunk.js new file mode 100644 index 00000000000..36b1d61dd25 --- /dev/null +++ b/test/chunking-form/samples/configure-file-url/_expected/es/chunk.js @@ -0,0 +1 @@ +console.log('chunk'); diff --git a/test/chunking-form/samples/configure-file-url/_expected/es/main.js b/test/chunking-form/samples/configure-file-url/_expected/es/main.js new file mode 100644 index 00000000000..7f9578e00cc --- /dev/null +++ b/test/chunking-form/samples/configure-file-url/_expected/es/main.js @@ -0,0 +1,7 @@ +const asset = 'resolved'; +const chunk = 'resolved'; + +const asset$1 = new URL('assets/asset-unresolved-9548436d.txt', import.meta.url).href; +const chunk$1 = new URL('chunk.js', import.meta.url).href; + +import('./nested/chunk.js').then(result => console.log(result, chunk, chunk$1, asset, asset$1)); diff --git a/test/chunking-form/samples/configure-file-url/_expected/es/nested/chunk.js b/test/chunking-form/samples/configure-file-url/_expected/es/nested/chunk.js new file mode 100644 index 00000000000..a3a938282a6 --- /dev/null +++ b/test/chunking-form/samples/configure-file-url/_expected/es/nested/chunk.js @@ -0,0 +1,4 @@ +const asset = 'chunkId=nested/chunk.js:moduleId=solved:fileName=assets/asset-solved-9b321da2.txt:format=es:relativePath=../assets/asset-solved-9b321da2.txt:type=ASSET' +const chunk = 'chunkId=nested/chunk.js:moduleId=solved:fileName=chunk.js:format=es:relativePath=../chunk.js:type=CHUNK' + +export { asset, chunk }; diff --git a/test/chunking-form/samples/configure-file-url/_expected/system/assets/asset-resolved-dfc93baf.txt b/test/chunking-form/samples/configure-file-url/_expected/system/assets/asset-resolved-dfc93baf.txt new file mode 100644 index 00000000000..31fb300f988 --- /dev/null +++ b/test/chunking-form/samples/configure-file-url/_expected/system/assets/asset-resolved-dfc93baf.txt @@ -0,0 +1 @@ +Asset for: resolved \ No newline at end of file diff --git a/test/chunking-form/samples/configure-file-url/_expected/system/assets/asset-solved-9b321da2.txt b/test/chunking-form/samples/configure-file-url/_expected/system/assets/asset-solved-9b321da2.txt new file mode 100644 index 00000000000..07c7a096c7e --- /dev/null +++ b/test/chunking-form/samples/configure-file-url/_expected/system/assets/asset-solved-9b321da2.txt @@ -0,0 +1 @@ +Asset for: solved \ No newline at end of file diff --git a/test/chunking-form/samples/configure-file-url/_expected/system/assets/asset-unresolved-9548436d.txt b/test/chunking-form/samples/configure-file-url/_expected/system/assets/asset-unresolved-9548436d.txt new file mode 100644 index 00000000000..fd3ad6261cc --- /dev/null +++ b/test/chunking-form/samples/configure-file-url/_expected/system/assets/asset-unresolved-9548436d.txt @@ -0,0 +1 @@ +Asset for: unresolved \ No newline at end of file diff --git a/test/chunking-form/samples/configure-file-url/_expected/system/chunk.js b/test/chunking-form/samples/configure-file-url/_expected/system/chunk.js new file mode 100644 index 00000000000..8f0f1907cfd --- /dev/null +++ b/test/chunking-form/samples/configure-file-url/_expected/system/chunk.js @@ -0,0 +1,10 @@ +System.register([], function (exports, module) { + 'use strict'; + return { + execute: function () { + + console.log('chunk'); + + } + }; +}); diff --git a/test/chunking-form/samples/configure-file-url/_expected/system/main.js b/test/chunking-form/samples/configure-file-url/_expected/system/main.js new file mode 100644 index 00000000000..19dad1f0c15 --- /dev/null +++ b/test/chunking-form/samples/configure-file-url/_expected/system/main.js @@ -0,0 +1,16 @@ +System.register([], function (exports, module) { + 'use strict'; + return { + execute: function () { + + const asset = 'resolved'; + const chunk = 'resolved'; + + const asset$1 = new URL('assets/asset-unresolved-9548436d.txt', module.meta.url).href; + const chunk$1 = new URL('chunk.js', module.meta.url).href; + + module.import('./nested/chunk.js').then(result => console.log(result, chunk, chunk$1, asset, asset$1)); + + } + }; +}); diff --git a/test/chunking-form/samples/configure-file-url/_expected/system/nested/chunk.js b/test/chunking-form/samples/configure-file-url/_expected/system/nested/chunk.js new file mode 100644 index 00000000000..74abe05b6e3 --- /dev/null +++ b/test/chunking-form/samples/configure-file-url/_expected/system/nested/chunk.js @@ -0,0 +1,11 @@ +System.register([], function (exports, module) { + 'use strict'; + return { + execute: function () { + + const asset = exports('asset', 'chunkId=nested/chunk.js:moduleId=solved:fileName=assets/asset-solved-9b321da2.txt:format=system:relativePath=../assets/asset-solved-9b321da2.txt:type=ASSET' + const chunk = exports('chunk', 'chunkId=nested/chunk.js:moduleId=solved:fileName=chunk.js:format=system:relativePath=../chunk.js:type=CHUNK' + + } + }; +}); diff --git a/test/chunking-form/samples/configure-file-url/chunk.js b/test/chunking-form/samples/configure-file-url/chunk.js new file mode 100644 index 00000000000..36b1d61dd25 --- /dev/null +++ b/test/chunking-form/samples/configure-file-url/chunk.js @@ -0,0 +1 @@ +console.log('chunk'); diff --git a/test/chunking-form/samples/configure-file-url/main.js b/test/chunking-form/samples/configure-file-url/main.js new file mode 100644 index 00000000000..c7b101dfc5b --- /dev/null +++ b/test/chunking-form/samples/configure-file-url/main.js @@ -0,0 +1,5 @@ +import { asset as asset1, chunk as chunk1 } from 'resolved'; +import { asset as asset2, chunk as chunk2 } from 'unresolved'; + +import('solved').then(result => console.log(result, chunk1, chunk2, asset1, asset2)); + diff --git a/test/form/samples/configure-file-url/_config.js b/test/form/samples/configure-file-url/_config.js new file mode 100644 index 00000000000..5fb186f12db --- /dev/null +++ b/test/form/samples/configure-file-url/_config.js @@ -0,0 +1,40 @@ +module.exports = { + description: 'allows to configure file urls', + options: { + plugins: [ + { + resolveId(id) { + if (id.endsWith('solved')) { + return id; + } + }, + load(id) { + if (id.endsWith('solved')) { + const assetId = this.emitAsset(`asset-${id}.txt`, `Asset for: ${id}`); + return `export default import.meta.ROLLUP_ASSET_URL_${assetId};`; + } + }, + resolveFileUrl({ chunkId, fileName, format, moduleId, relativePath, type }) { + if (!moduleId.endsWith('resolved')) { + return `'chunkId=${chunkId}:moduleId=${moduleId + .replace(/\\/g, '/') + .split('/') + .slice(-2) + .join( + '/' + )}:fileName=${fileName}:format=${format}:relativePath=${relativePath}:type=${type}'`; + } + return null; + } + }, + { + resolveFileUrl({ moduleId }) { + if (moduleId === 'resolved') { + return `'resolved'`; + } + return null; + } + } + ] + } +}; diff --git a/test/form/samples/configure-file-url/_expected/amd.js b/test/form/samples/configure-file-url/_expected/amd.js new file mode 100644 index 00000000000..19b03cfac12 --- /dev/null +++ b/test/form/samples/configure-file-url/_expected/amd.js @@ -0,0 +1,11 @@ +define(['module'], function (module) { 'use strict'; + + var asset1 = 'chunkId=amd.js:moduleId=solved:fileName=assets/asset-solved-9b321da2.txt:format=amd:relativePath=assets/asset-solved-9b321da2.txt:type=ASSET'; + + var asset2 = 'resolved'; + + var asset3 = new URL(module.uri + '/../assets/asset-unresolved-9548436d.txt', document.baseURI).href; + + console.log(asset1, asset2, asset3); + +}); diff --git a/test/form/samples/configure-file-url/_expected/assets/asset-resolved-dfc93baf.txt b/test/form/samples/configure-file-url/_expected/assets/asset-resolved-dfc93baf.txt new file mode 100644 index 00000000000..31fb300f988 --- /dev/null +++ b/test/form/samples/configure-file-url/_expected/assets/asset-resolved-dfc93baf.txt @@ -0,0 +1 @@ +Asset for: resolved \ No newline at end of file diff --git a/test/form/samples/configure-file-url/_expected/assets/asset-solved-9b321da2.txt b/test/form/samples/configure-file-url/_expected/assets/asset-solved-9b321da2.txt new file mode 100644 index 00000000000..07c7a096c7e --- /dev/null +++ b/test/form/samples/configure-file-url/_expected/assets/asset-solved-9b321da2.txt @@ -0,0 +1 @@ +Asset for: solved \ No newline at end of file diff --git a/test/form/samples/configure-file-url/_expected/assets/asset-unresolved-9548436d.txt b/test/form/samples/configure-file-url/_expected/assets/asset-unresolved-9548436d.txt new file mode 100644 index 00000000000..fd3ad6261cc --- /dev/null +++ b/test/form/samples/configure-file-url/_expected/assets/asset-unresolved-9548436d.txt @@ -0,0 +1 @@ +Asset for: unresolved \ No newline at end of file diff --git a/test/form/samples/configure-file-url/_expected/cjs.js b/test/form/samples/configure-file-url/_expected/cjs.js new file mode 100644 index 00000000000..5ecf4d8ddeb --- /dev/null +++ b/test/form/samples/configure-file-url/_expected/cjs.js @@ -0,0 +1,9 @@ +'use strict'; + +var asset1 = 'chunkId=cjs.js:moduleId=solved:fileName=assets/asset-solved-9b321da2.txt:format=cjs:relativePath=assets/asset-solved-9b321da2.txt:type=ASSET'; + +var asset2 = 'resolved'; + +var asset3 = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/asset-unresolved-9548436d.txt').href : new URL((document.currentScript && document.currentScript.src || document.baseURI) + '/../assets/asset-unresolved-9548436d.txt').href); + +console.log(asset1, asset2, asset3); diff --git a/test/form/samples/configure-file-url/_expected/es.js b/test/form/samples/configure-file-url/_expected/es.js new file mode 100644 index 00000000000..32e91325fed --- /dev/null +++ b/test/form/samples/configure-file-url/_expected/es.js @@ -0,0 +1,7 @@ +var asset1 = 'chunkId=es.js:moduleId=solved:fileName=assets/asset-solved-9b321da2.txt:format=es:relativePath=assets/asset-solved-9b321da2.txt:type=ASSET'; + +var asset2 = 'resolved'; + +var asset3 = new URL('assets/asset-unresolved-9548436d.txt', import.meta.url).href; + +console.log(asset1, asset2, asset3); diff --git a/test/form/samples/configure-file-url/_expected/iife.js b/test/form/samples/configure-file-url/_expected/iife.js new file mode 100644 index 00000000000..fc1bd600210 --- /dev/null +++ b/test/form/samples/configure-file-url/_expected/iife.js @@ -0,0 +1,12 @@ +(function () { + 'use strict'; + + var asset1 = 'chunkId=iife.js:moduleId=solved:fileName=assets/asset-solved-9b321da2.txt:format=iife:relativePath=assets/asset-solved-9b321da2.txt:type=ASSET'; + + var asset2 = 'resolved'; + + var asset3 = new URL((document.currentScript && document.currentScript.src || document.baseURI) + '/../assets/asset-unresolved-9548436d.txt').href; + + console.log(asset1, asset2, asset3); + +}()); diff --git a/test/form/samples/configure-file-url/_expected/system.js b/test/form/samples/configure-file-url/_expected/system.js new file mode 100644 index 00000000000..054f8a7dda6 --- /dev/null +++ b/test/form/samples/configure-file-url/_expected/system.js @@ -0,0 +1,16 @@ +System.register([], function (exports, module) { + 'use strict'; + return { + execute: function () { + + var asset1 = 'chunkId=system.js:moduleId=solved:fileName=assets/asset-solved-9b321da2.txt:format=system:relativePath=assets/asset-solved-9b321da2.txt:type=ASSET'; + + var asset2 = 'resolved'; + + var asset3 = new URL('assets/asset-unresolved-9548436d.txt', module.meta.url).href; + + console.log(asset1, asset2, asset3); + + } + }; +}); diff --git a/test/form/samples/configure-file-url/_expected/umd.js b/test/form/samples/configure-file-url/_expected/umd.js new file mode 100644 index 00000000000..c46f7a66d1a --- /dev/null +++ b/test/form/samples/configure-file-url/_expected/umd.js @@ -0,0 +1,14 @@ +(function (factory) { + typeof define === 'function' && define.amd ? define(factory) : + factory(); +}(function () { 'use strict'; + + var asset1 = 'chunkId=umd.js:moduleId=solved:fileName=assets/asset-solved-9b321da2.txt:format=umd:relativePath=assets/asset-solved-9b321da2.txt:type=ASSET'; + + var asset2 = 'resolved'; + + var asset3 = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/asset-unresolved-9548436d.txt').href : new URL((document.currentScript && document.currentScript.src || document.baseURI) + '/../assets/asset-unresolved-9548436d.txt').href); + + console.log(asset1, asset2, asset3); + +})); diff --git a/test/form/samples/configure-file-url/main.js b/test/form/samples/configure-file-url/main.js new file mode 100644 index 00000000000..47414d65a9f --- /dev/null +++ b/test/form/samples/configure-file-url/main.js @@ -0,0 +1,5 @@ +import asset2 from 'resolved'; +import asset1 from 'solved'; +import asset3 from 'unresolved'; + +console.log(asset1, asset2, asset3); diff --git a/test/form/samples/treeshake-import-meta/_config.js b/test/form/samples/treeshake-import-meta/_config.js new file mode 100644 index 00000000000..64d9f998bc0 --- /dev/null +++ b/test/form/samples/treeshake-import-meta/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'supports tree-shaking for meta properties' +}; diff --git a/test/form/samples/treeshake-import-meta/_expected.js b/test/form/samples/treeshake-import-meta/_expected.js new file mode 100644 index 00000000000..fbce83c5c52 --- /dev/null +++ b/test/form/samples/treeshake-import-meta/_expected.js @@ -0,0 +1 @@ +const retained = import.meta.a.b; diff --git a/test/form/samples/treeshake-import-meta/main.js b/test/form/samples/treeshake-import-meta/main.js new file mode 100644 index 00000000000..4a41ad2333a --- /dev/null +++ b/test/form/samples/treeshake-import-meta/main.js @@ -0,0 +1,4 @@ +const removed1 = import.meta; +const removed2 = import.meta.url; +const removed3 = import.meta.unknown; +const retained = import.meta.a.b; From b7f229f988a8985c1aff497c56a2f1656b8d5e0e Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Wed, 17 Apr 2019 07:26:42 +0200 Subject: [PATCH 26/60] Move setAssetSource failure tests to function --- src/rollup/types.d.ts | 1 - test/form/samples/configure-file-url/main.js | 2 +- .../_config.js | 2 +- .../set-asset-source-transform/_config.js | 24 ++++++++ .../set-asset-source-transform/main.js | 1 + .../samples/set-asset-source-twice/_config.js | 20 +++++++ .../samples/set-asset-source-twice/main.js | 1 + test/hooks/index.js | 56 ------------------- 8 files changed, 48 insertions(+), 59 deletions(-) create mode 100644 test/function/samples/set-asset-source-transform/_config.js create mode 100644 test/function/samples/set-asset-source-transform/main.js create mode 100644 test/function/samples/set-asset-source-twice/_config.js create mode 100644 test/function/samples/set-asset-source-twice/main.js diff --git a/src/rollup/types.d.ts b/src/rollup/types.d.ts index b29c202c699..751512d2104 100644 --- a/src/rollup/types.d.ts +++ b/src/rollup/types.d.ts @@ -215,7 +215,6 @@ export type ResolveAssetUrlHook = ( type EmittedFileType = 'ASSET' | 'CHUNK'; -// TODO Lukas are all properties tested? export type ResolveFileUrlHook = ( this: PluginContext, options: { diff --git a/test/form/samples/configure-file-url/main.js b/test/form/samples/configure-file-url/main.js index 47414d65a9f..74a56461e3a 100644 --- a/test/form/samples/configure-file-url/main.js +++ b/test/form/samples/configure-file-url/main.js @@ -1,5 +1,5 @@ -import asset2 from 'resolved'; import asset1 from 'solved'; +import asset2 from 'resolved'; import asset3 from 'unresolved'; console.log(asset1, asset2, asset3); diff --git a/test/function/samples/internal-reexports-from-external/_config.js b/test/function/samples/internal-reexports-from-external/_config.js index 79d4f56d24d..4b56fa1782d 100644 --- a/test/function/samples/internal-reexports-from-external/_config.js +++ b/test/function/samples/internal-reexports-from-external/_config.js @@ -10,6 +10,6 @@ module.exports = { code: 'NAMESPACE_CANNOT_CONTAIN_EXTERNAL', message: 'Cannot create an explicit namespace object for module "reexport" because it contains a reexported external namespace', - id: path.join(__dirname, '/reexport.js') + id: path.join(__dirname, 'reexport.js') } }; diff --git a/test/function/samples/set-asset-source-transform/_config.js b/test/function/samples/set-asset-source-transform/_config.js new file mode 100644 index 00000000000..bb506dfd995 --- /dev/null +++ b/test/function/samples/set-asset-source-transform/_config.js @@ -0,0 +1,24 @@ +const path = require('path'); + +module.exports = { + description: 'throws when setting the asset source in the transform hook', + options: { + plugins: { + name: 'test-plugin', + transform(code) { + const assetId = this.emitAsset('test.ext'); + this.setAssetSource(assetId, 'asdf'); + return code; + } + } + }, + error: { + code: 'PLUGIN_ERROR', + hook: 'transform', + id: path.join(__dirname, 'main.js'), + message: + 'setAssetSource cannot be called in transform for caching reasons. Use emitAsset with a source, or call setAssetSource in another hook.', + plugin: 'test-plugin', + pluginCode: 'INVALID_SETASSETSOURCE' + } +}; diff --git a/test/function/samples/set-asset-source-transform/main.js b/test/function/samples/set-asset-source-transform/main.js new file mode 100644 index 00000000000..c4b940fc952 --- /dev/null +++ b/test/function/samples/set-asset-source-transform/main.js @@ -0,0 +1 @@ +throw new Error('should not build'); diff --git a/test/function/samples/set-asset-source-twice/_config.js b/test/function/samples/set-asset-source-twice/_config.js new file mode 100644 index 00000000000..7fea77b58f1 --- /dev/null +++ b/test/function/samples/set-asset-source-twice/_config.js @@ -0,0 +1,20 @@ +module.exports = { + description: 'throws when setting the asset source twice', + options: { + plugins: { + name: 'test-plugin', + buildEnd() { + const assetId = this.emitAsset('test.ext'); + this.setAssetSource(assetId, 'hello world'); + this.setAssetSource(assetId, 'another'); + } + } + }, + error: { + code: 'PLUGIN_ERROR', + hook: 'buildEnd', + message: 'Plugin error - Unable to set asset source for test.ext, source already set.', + plugin: 'test-plugin', + pluginCode: 'ASSET_SOURCE_ALREADY_SET' + } +}; diff --git a/test/function/samples/set-asset-source-twice/main.js b/test/function/samples/set-asset-source-twice/main.js new file mode 100644 index 00000000000..c4b940fc952 --- /dev/null +++ b/test/function/samples/set-asset-source-twice/main.js @@ -0,0 +1 @@ +throw new Error('should not build'); diff --git a/test/hooks/index.js b/test/hooks/index.js index 6568c68e24c..207c86e60b9 100644 --- a/test/hooks/index.js +++ b/test/hooks/index.js @@ -588,62 +588,6 @@ module.exports = input; }); }); - it('throws when calling setAssetSource in transform', () => { - return rollup - .rollup({ - input: 'input', - plugins: [ - loader({ input: `alert('hello')` }), - { - transform() { - const assetId = this.emitAsset('test.ext'); - this.setAssetSource(assetId, 'asdf'); - return ''; - } - } - ] - }) - .then(({ output }) => { - throw new Error('should fail'); - }) - .catch(err => { - assert.equal(err.code, 'PLUGIN_ERROR'); - assert.equal(err.pluginCode, 'INVALID_SETASSETSOURCE'); - }); - }); - - it('throws when setting asset source twice', () => { - let thrown = false; - return rollup - .rollup({ - input: 'input', - plugins: [ - loader({ input: `alert('hello')` }), - { - buildEnd() { - const assetId = this.emitAsset('test.ext'); - this.setAssetSource(assetId, 'hello world'); - try { - this.setAssetSource(assetId, 'another'); - } catch (e) { - assert.equal(e.code, 'ASSET_SOURCE_ALREADY_SET'); - thrown = true; - return ''; - } - assert.fail(); - } - } - ] - }) - .then(bundle => { - return bundle.generate({ format: 'es' }); - }) - .then(({ output: [, output] }) => { - assert.equal(output.source, 'hello world'); - assert.equal(thrown, true); - }); - }); - it('allows setting asset source at generateBundle', () => { let assetId; return rollup From b5819c8320d3427c58e35593d65e7afdb75827fe Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Wed, 17 Apr 2019 08:46:39 +0200 Subject: [PATCH 27/60] Test and extract all errors thrown when emitting assets --- src/utils/assetHooks.ts | 55 +++++------------ src/utils/error.ts | 59 ++++++++++++++++++- .../asset-source-missing-2/_config.js | 16 +++++ .../asset-source-missing-2}/main.js | 0 .../asset-source-missing-3/_config.js | 19 ++++++ .../asset-source-missing-3}/main.js | 0 .../asset-source-missing/_config.js | 15 +++++ .../emit-asset/asset-source-missing/main.js | 1 + .../emit-asset/invalid-asset-id/_config.js | 15 +++++ .../emit-asset/invalid-asset-id/main.js | 1 + .../emit-asset/invalid-asset-name/_config.js | 19 ++++++ .../emit-asset/invalid-asset-name/main.js | 1 + .../invalid-set-asset-source-id/_config.js | 18 ++++++ .../invalid-set-asset-source-id/main.js | 1 + .../set-asset-source-transform/_config.js | 0 .../set-asset-source-transform/main.js | 1 + .../set-asset-source-twice/_config.js | 2 +- .../emit-asset/set-asset-source-twice/main.js | 1 + 18 files changed, 183 insertions(+), 41 deletions(-) create mode 100644 test/function/samples/emit-asset/asset-source-missing-2/_config.js rename test/function/samples/{set-asset-source-transform => emit-asset/asset-source-missing-2}/main.js (100%) create mode 100644 test/function/samples/emit-asset/asset-source-missing-3/_config.js rename test/function/samples/{set-asset-source-twice => emit-asset/asset-source-missing-3}/main.js (100%) create mode 100644 test/function/samples/emit-asset/asset-source-missing/_config.js create mode 100644 test/function/samples/emit-asset/asset-source-missing/main.js create mode 100644 test/function/samples/emit-asset/invalid-asset-id/_config.js create mode 100644 test/function/samples/emit-asset/invalid-asset-id/main.js create mode 100644 test/function/samples/emit-asset/invalid-asset-name/_config.js create mode 100644 test/function/samples/emit-asset/invalid-asset-name/main.js create mode 100644 test/function/samples/emit-asset/invalid-set-asset-source-id/_config.js create mode 100644 test/function/samples/emit-asset/invalid-set-asset-source-id/main.js rename test/function/samples/{ => emit-asset}/set-asset-source-transform/_config.js (100%) create mode 100644 test/function/samples/emit-asset/set-asset-source-transform/main.js rename test/function/samples/{ => emit-asset}/set-asset-source-twice/_config.js (82%) create mode 100644 test/function/samples/emit-asset/set-asset-source-twice/main.js diff --git a/src/utils/assetHooks.ts b/src/utils/assetHooks.ts index 55951b3985c..6eedc42b45c 100644 --- a/src/utils/assetHooks.ts +++ b/src/utils/assetHooks.ts @@ -1,6 +1,14 @@ import sha256 from 'hash.js/lib/hash/sha/256'; import { Asset, EmitAsset, OutputBundle } from '../rollup/types'; -import { error } from './error'; +import { + errorAssetMetaIdNotFoundForFilename, + errorAssetMetaIdNotFoundForSetSource, + errorAssetNotFinalisedForFileName, + errorAssetSourceAlreadySet, + errorAssetSourceMissingForSetSource, + errorInvalidAssetName, + errorNoAssetSourceSet +} from './error'; import { addWithNewMetaId } from './metaIds'; import { extname } from './path'; import { isPlainName } from './relativeId'; @@ -11,12 +19,7 @@ export function getAssetFileName( existingNames: Record, assetFileNames: string ) { - if (asset.source === undefined) - error({ - code: 'ASSET_SOURCE_NOT_FOUND', - message: `Plugin error creating asset ${asset.name} - no asset source set.` - }); - + if (asset.source === undefined) errorNoAssetSourceSet(asset); if (asset.fileName) return asset.fileName; return makeUnique( @@ -47,11 +50,7 @@ export function createAssetPluginHooks( ) { return { emitAsset(name: string, source?: string | Buffer) { - if (typeof name !== 'string' || !isPlainName(name)) - error({ - code: 'INVALID_ASSET_NAME', - message: `Plugin error creating asset, name is not a plain (non relative or absolute URL) string name.` - }); + if (typeof name !== 'string' || !isPlainName(name)) errorInvalidAssetName(name); const asset: Asset = { name, source, fileName: undefined }; if (outputBundle && source !== undefined) finaliseAsset(asset, outputBundle, assetFileNames); return addWithNewMetaId(asset, assetsByMetaId, name); @@ -59,39 +58,17 @@ export function createAssetPluginHooks( setAssetSource(assetMetaId: string, source?: string | Buffer) { const asset = assetsByMetaId.get(assetMetaId); - if (!asset) - error({ - code: 'ASSET_NOT_FOUND', - message: `Plugin error - Unable to set asset source for unknown asset ${assetMetaId}.` - }); - if (asset.source !== undefined) - error({ - code: 'ASSET_SOURCE_ALREADY_SET', - message: `Plugin error - Unable to set asset source for ${ - asset.name - }, source already set.` - }); - if (typeof source !== 'string' && !source) - error({ - code: 'ASSET_SOURCE_MISSING', - message: `Plugin error creating asset ${name}, setAssetSource call without a source.` - }); + if (!asset) errorAssetMetaIdNotFoundForSetSource(assetMetaId); + if (asset.source !== undefined) errorAssetSourceAlreadySet(asset); + if (typeof source !== 'string' && !source) errorAssetSourceMissingForSetSource(asset); asset.source = source; if (outputBundle) finaliseAsset(asset, outputBundle, assetFileNames); }, getAssetFileName(assetMetaId: string) { const asset = assetsByMetaId.get(assetMetaId); - if (!asset) - error({ - code: 'ASSET_NOT_FOUND', - message: `Plugin error - Unable to get asset filename for unknown asset ${assetMetaId}.` - }); - if (asset.fileName === undefined) - error({ - code: 'ASSET_NOT_FINALISED', - message: `Plugin error - Unable to get asset file name for asset ${assetMetaId}. Ensure that the source is set and that generate is called first.` - }); + if (!asset) errorAssetMetaIdNotFoundForFilename(assetMetaId); + if (asset.fileName === undefined) errorAssetNotFinalisedForFileName(asset); return asset.fileName; } }; diff --git a/src/utils/error.ts b/src/utils/error.ts index bf787954c6e..2ce241b34cc 100644 --- a/src/utils/error.ts +++ b/src/utils/error.ts @@ -1,5 +1,5 @@ import { locate } from 'locate-character'; -import { RollupError, RollupWarning } from '../rollup/types'; +import { Asset, RollupError, RollupWarning } from '../rollup/types'; import getCodeFrame from './getCodeFrame'; import { relative } from './path'; @@ -31,9 +31,66 @@ export function augmentCodeLocation( } enum Errors { + ASSET_NOT_FINALISED = 'ASSET_NOT_FINALISED', + ASSET_NOT_FOUND = 'ASSET_NOT_FOUND', + ASSET_SOURCE_ALREADY_SET = 'ASSET_SOURCE_ALREADY_SET', + ASSET_SOURCE_MISSING = 'ASSET_SOURCE_MISSING', + ASSET_SOURCE_NOT_FOUND = 'ASSET_SOURCE_NOT_FOUND', + INVALID_ASSET_NAME = 'INVALID_ASSET_NAME', INVALID_CHUNK = 'INVALID_CHUNK' } +export function errorAssetNotFinalisedForFileName(asset: Asset) { + error({ + code: Errors.ASSET_NOT_FINALISED, + message: `Plugin error - Unable to get asset file name for "${ + asset.name + }". Ensure that the source is set and that generate is called first.` + }); +} + +export function errorAssetMetaIdNotFoundForFilename(assetMetaId: string) { + error({ + code: Errors.ASSET_NOT_FOUND, + message: `Plugin error - Unable to get asset filename for unknown asset "${assetMetaId}".` + }); +} + +export function errorAssetMetaIdNotFoundForSetSource(assetMetaId: string) { + error({ + code: Errors.ASSET_NOT_FOUND, + message: `Plugin error - Unable to set asset source for unknown asset "${assetMetaId}".` + }); +} + +export function errorAssetSourceAlreadySet(asset: Asset) { + error({ + code: Errors.ASSET_SOURCE_ALREADY_SET, + message: `Plugin error - Unable to set asset source for "${asset.name}", source already set.` + }); +} + +export function errorAssetSourceMissingForSetSource(asset: Asset) { + error({ + code: Errors.ASSET_SOURCE_MISSING, + message: `Plugin error creating asset "${asset.name}", setAssetSource call without a source.` + }); +} + +export function errorNoAssetSourceSet(asset: Asset) { + error({ + code: Errors.ASSET_SOURCE_NOT_FOUND, + message: `Plugin error creating asset "${asset.name}" - no asset source set.` + }); +} + +export function errorInvalidAssetName(name: string) { + error({ + code: Errors.INVALID_ASSET_NAME, + message: `Plugin error creating asset, name "${name}" is not a plain (non relative or absolute URL) string name.` + }); +} + // TODO Lukas polyfill process.cwd() // TODO Lukas other errors export function errorCannotAssignModuleToChunk( diff --git a/test/function/samples/emit-asset/asset-source-missing-2/_config.js b/test/function/samples/emit-asset/asset-source-missing-2/_config.js new file mode 100644 index 00000000000..6527dcf0aa3 --- /dev/null +++ b/test/function/samples/emit-asset/asset-source-missing-2/_config.js @@ -0,0 +1,16 @@ +module.exports = { + description: 'throws when not setting the asset source and accessing the asset URL', + options: { + plugins: { + name: 'test-plugin', + load() { + return `export default import.meta.ROLLUP_ASSET_URL_${this.emitAsset('test.ext')};`; + } + } + }, + generateError: { + code: 'ASSET_NOT_FINALISED', + message: + 'Plugin error - Unable to get asset file name for "test.ext". Ensure that the source is set and that generate is called first.' + } +}; diff --git a/test/function/samples/set-asset-source-transform/main.js b/test/function/samples/emit-asset/asset-source-missing-2/main.js similarity index 100% rename from test/function/samples/set-asset-source-transform/main.js rename to test/function/samples/emit-asset/asset-source-missing-2/main.js diff --git a/test/function/samples/emit-asset/asset-source-missing-3/_config.js b/test/function/samples/emit-asset/asset-source-missing-3/_config.js new file mode 100644 index 00000000000..8929ab542fb --- /dev/null +++ b/test/function/samples/emit-asset/asset-source-missing-3/_config.js @@ -0,0 +1,19 @@ +module.exports = { + description: 'throws when setting an empty asset source', + options: { + plugins: { + name: 'test-plugin', + buildStart() { + const assetId = this.emitAsset('test.ext'); + this.setAssetSource(assetId, null); + } + } + }, + error: { + code: 'PLUGIN_ERROR', + hook: 'buildStart', + message: 'Plugin error creating asset "test.ext", setAssetSource call without a source.', + plugin: 'test-plugin', + pluginCode: 'ASSET_SOURCE_MISSING' + } +}; diff --git a/test/function/samples/set-asset-source-twice/main.js b/test/function/samples/emit-asset/asset-source-missing-3/main.js similarity index 100% rename from test/function/samples/set-asset-source-twice/main.js rename to test/function/samples/emit-asset/asset-source-missing-3/main.js diff --git a/test/function/samples/emit-asset/asset-source-missing/_config.js b/test/function/samples/emit-asset/asset-source-missing/_config.js new file mode 100644 index 00000000000..ccc218c8ca5 --- /dev/null +++ b/test/function/samples/emit-asset/asset-source-missing/_config.js @@ -0,0 +1,15 @@ +module.exports = { + description: 'throws when not setting the asset source', + options: { + plugins: { + name: 'test-plugin', + load() { + this.emitAsset('test.ext'); + } + } + }, + generateError: { + code: 'ASSET_SOURCE_NOT_FOUND', + message: 'Plugin error creating asset "test.ext" - no asset source set.' + } +}; diff --git a/test/function/samples/emit-asset/asset-source-missing/main.js b/test/function/samples/emit-asset/asset-source-missing/main.js new file mode 100644 index 00000000000..c4b940fc952 --- /dev/null +++ b/test/function/samples/emit-asset/asset-source-missing/main.js @@ -0,0 +1 @@ +throw new Error('should not build'); diff --git a/test/function/samples/emit-asset/invalid-asset-id/_config.js b/test/function/samples/emit-asset/invalid-asset-id/_config.js new file mode 100644 index 00000000000..adb4ffe0bc1 --- /dev/null +++ b/test/function/samples/emit-asset/invalid-asset-id/_config.js @@ -0,0 +1,15 @@ +module.exports = { + description: 'throws for invalid asset ids', + options: { + plugins: { + name: 'test-plugin', + load() { + return `export default import.meta.ROLLUP_ASSET_URL_invalid;`; + } + } + }, + generateError: { + code: 'ASSET_NOT_FOUND', + message: 'Plugin error - Unable to get asset filename for unknown asset "invalid".' + } +}; diff --git a/test/function/samples/emit-asset/invalid-asset-id/main.js b/test/function/samples/emit-asset/invalid-asset-id/main.js new file mode 100644 index 00000000000..c4b940fc952 --- /dev/null +++ b/test/function/samples/emit-asset/invalid-asset-id/main.js @@ -0,0 +1 @@ +throw new Error('should not build'); diff --git a/test/function/samples/emit-asset/invalid-asset-name/_config.js b/test/function/samples/emit-asset/invalid-asset-name/_config.js new file mode 100644 index 00000000000..ffbe4fa4a9b --- /dev/null +++ b/test/function/samples/emit-asset/invalid-asset-name/_config.js @@ -0,0 +1,19 @@ +module.exports = { + description: 'throws for invalid asset names', + options: { + plugins: { + name: 'test-plugin', + buildStart() { + this.emitAsset('/test.ext', 'content'); + } + } + }, + error: { + code: 'PLUGIN_ERROR', + hook: 'buildStart', + message: + 'Plugin error creating asset, name "/test.ext" is not a plain (non relative or absolute URL) string name.', + plugin: 'test-plugin', + pluginCode: 'INVALID_ASSET_NAME' + } +}; diff --git a/test/function/samples/emit-asset/invalid-asset-name/main.js b/test/function/samples/emit-asset/invalid-asset-name/main.js new file mode 100644 index 00000000000..c4b940fc952 --- /dev/null +++ b/test/function/samples/emit-asset/invalid-asset-name/main.js @@ -0,0 +1 @@ +throw new Error('should not build'); diff --git a/test/function/samples/emit-asset/invalid-set-asset-source-id/_config.js b/test/function/samples/emit-asset/invalid-set-asset-source-id/_config.js new file mode 100644 index 00000000000..2a2f2849773 --- /dev/null +++ b/test/function/samples/emit-asset/invalid-set-asset-source-id/_config.js @@ -0,0 +1,18 @@ +module.exports = { + description: 'throws for invalid asset ids', + options: { + plugins: { + name: 'test-plugin', + buildStart() { + this.setAssetSource('invalid', 'content'); + } + } + }, + error: { + code: 'PLUGIN_ERROR', + hook: 'buildStart', + message: 'Plugin error - Unable to set asset source for unknown asset "invalid".', + plugin: 'test-plugin', + pluginCode: 'ASSET_NOT_FOUND' + } +}; diff --git a/test/function/samples/emit-asset/invalid-set-asset-source-id/main.js b/test/function/samples/emit-asset/invalid-set-asset-source-id/main.js new file mode 100644 index 00000000000..c4b940fc952 --- /dev/null +++ b/test/function/samples/emit-asset/invalid-set-asset-source-id/main.js @@ -0,0 +1 @@ +throw new Error('should not build'); diff --git a/test/function/samples/set-asset-source-transform/_config.js b/test/function/samples/emit-asset/set-asset-source-transform/_config.js similarity index 100% rename from test/function/samples/set-asset-source-transform/_config.js rename to test/function/samples/emit-asset/set-asset-source-transform/_config.js diff --git a/test/function/samples/emit-asset/set-asset-source-transform/main.js b/test/function/samples/emit-asset/set-asset-source-transform/main.js new file mode 100644 index 00000000000..c4b940fc952 --- /dev/null +++ b/test/function/samples/emit-asset/set-asset-source-transform/main.js @@ -0,0 +1 @@ +throw new Error('should not build'); diff --git a/test/function/samples/set-asset-source-twice/_config.js b/test/function/samples/emit-asset/set-asset-source-twice/_config.js similarity index 82% rename from test/function/samples/set-asset-source-twice/_config.js rename to test/function/samples/emit-asset/set-asset-source-twice/_config.js index 7fea77b58f1..695a4693dda 100644 --- a/test/function/samples/set-asset-source-twice/_config.js +++ b/test/function/samples/emit-asset/set-asset-source-twice/_config.js @@ -13,7 +13,7 @@ module.exports = { error: { code: 'PLUGIN_ERROR', hook: 'buildEnd', - message: 'Plugin error - Unable to set asset source for test.ext, source already set.', + message: 'Plugin error - Unable to set asset source for "test.ext", source already set.', plugin: 'test-plugin', pluginCode: 'ASSET_SOURCE_ALREADY_SET' } diff --git a/test/function/samples/emit-asset/set-asset-source-twice/main.js b/test/function/samples/emit-asset/set-asset-source-twice/main.js new file mode 100644 index 00000000000..c4b940fc952 --- /dev/null +++ b/test/function/samples/emit-asset/set-asset-source-twice/main.js @@ -0,0 +1 @@ +throw new Error('should not build'); From 69fb78908469c59c7bbcbd84300c036cb0ba14c3 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Wed, 17 Apr 2019 08:58:28 +0200 Subject: [PATCH 28/60] Extract and refine error when chunk id cannot be found --- src/ModuleLoader.ts | 12 ++++++------ src/utils/error.ts | 18 ++++++++++++++---- .../asset-source-missing-2/_config.js | 2 +- .../emit-asset/invalid-asset-id/_config.js | 2 +- .../invalid-set-asset-source-id/_config.js | 2 +- .../set-asset-source-twice/_config.js | 2 +- .../invalid-chunk-id/_config.js | 15 +++++++++++++++ .../emit-entry-chunk/invalid-chunk-id/main.js | 1 + 8 files changed, 40 insertions(+), 14 deletions(-) create mode 100644 test/function/samples/emit-entry-chunk/invalid-chunk-id/_config.js create mode 100644 test/function/samples/emit-entry-chunk/invalid-chunk-id/main.js diff --git a/src/ModuleLoader.ts b/src/ModuleLoader.ts index 5da5d97f582..6bc9bee8c1e 100644 --- a/src/ModuleLoader.ts +++ b/src/ModuleLoader.ts @@ -3,7 +3,11 @@ import ExternalModule from './ExternalModule'; import Graph from './Graph'; import Module from './Module'; import { ModuleJSON, ResolvedId, ResolveIdResult, SourceDescription } from './rollup/types'; -import { error, errorCannotAssignModuleToChunk } from './utils/error'; +import { + error, + errorCannotAssignModuleToChunk, + errorChunkMetaIdNotFoundForFilename +} from './utils/error'; import { addWithNewMetaId } from './utils/metaIds'; import { isRelative, resolve } from './utils/path'; import { PluginDriver } from './utils/pluginDriver'; @@ -112,11 +116,7 @@ export class ModuleLoader { getChunkFileName(metaId: string): string { const entryRecord = this.entriesByMetaId.get(metaId); - if (!entryRecord) - error({ - code: 'CHUNK_NOT_FOUND', - message: `Plugin error - Unable to get chunk filename for unknown chunk ${metaId}.` - }); + if (!entryRecord) errorChunkMetaIdNotFoundForFilename(metaId); // TODO Lukas check correct file name if (entryRecord.module === null) error({ diff --git a/src/utils/error.ts b/src/utils/error.ts index 2ce241b34cc..0dfa0e3765c 100644 --- a/src/utils/error.ts +++ b/src/utils/error.ts @@ -36,6 +36,7 @@ enum Errors { ASSET_SOURCE_ALREADY_SET = 'ASSET_SOURCE_ALREADY_SET', ASSET_SOURCE_MISSING = 'ASSET_SOURCE_MISSING', ASSET_SOURCE_NOT_FOUND = 'ASSET_SOURCE_NOT_FOUND', + CHUNK_NOT_FOUND = 'CHUNK_NOT_FOUND', INVALID_ASSET_NAME = 'INVALID_ASSET_NAME', INVALID_CHUNK = 'INVALID_CHUNK' } @@ -43,7 +44,7 @@ enum Errors { export function errorAssetNotFinalisedForFileName(asset: Asset) { error({ code: Errors.ASSET_NOT_FINALISED, - message: `Plugin error - Unable to get asset file name for "${ + message: `Plugin error - Unable to get file name for asset "${ asset.name }". Ensure that the source is set and that generate is called first.` }); @@ -52,21 +53,23 @@ export function errorAssetNotFinalisedForFileName(asset: Asset) { export function errorAssetMetaIdNotFoundForFilename(assetMetaId: string) { error({ code: Errors.ASSET_NOT_FOUND, - message: `Plugin error - Unable to get asset filename for unknown asset "${assetMetaId}".` + message: `Plugin error - Unable to get file name for unknown asset "${assetMetaId}".` }); } export function errorAssetMetaIdNotFoundForSetSource(assetMetaId: string) { error({ code: Errors.ASSET_NOT_FOUND, - message: `Plugin error - Unable to set asset source for unknown asset "${assetMetaId}".` + message: `Plugin error - Unable to set the source for unknown asset "${assetMetaId}".` }); } export function errorAssetSourceAlreadySet(asset: Asset) { error({ code: Errors.ASSET_SOURCE_ALREADY_SET, - message: `Plugin error - Unable to set asset source for "${asset.name}", source already set.` + message: `Plugin error - Unable to set the source for asset "${ + asset.name + }", source already set.` }); } @@ -84,6 +87,13 @@ export function errorNoAssetSourceSet(asset: Asset) { }); } +export function errorChunkMetaIdNotFoundForFilename(chunkMetaId: string) { + error({ + code: Errors.CHUNK_NOT_FOUND, + message: `Plugin error - Unable to get file name for unknown chunk "${chunkMetaId}".` + }); +} + export function errorInvalidAssetName(name: string) { error({ code: Errors.INVALID_ASSET_NAME, diff --git a/test/function/samples/emit-asset/asset-source-missing-2/_config.js b/test/function/samples/emit-asset/asset-source-missing-2/_config.js index 6527dcf0aa3..722c1b9c225 100644 --- a/test/function/samples/emit-asset/asset-source-missing-2/_config.js +++ b/test/function/samples/emit-asset/asset-source-missing-2/_config.js @@ -11,6 +11,6 @@ module.exports = { generateError: { code: 'ASSET_NOT_FINALISED', message: - 'Plugin error - Unable to get asset file name for "test.ext". Ensure that the source is set and that generate is called first.' + 'Plugin error - Unable to get file name for asset "test.ext". Ensure that the source is set and that generate is called first.' } }; diff --git a/test/function/samples/emit-asset/invalid-asset-id/_config.js b/test/function/samples/emit-asset/invalid-asset-id/_config.js index adb4ffe0bc1..9e7898f97b8 100644 --- a/test/function/samples/emit-asset/invalid-asset-id/_config.js +++ b/test/function/samples/emit-asset/invalid-asset-id/_config.js @@ -10,6 +10,6 @@ module.exports = { }, generateError: { code: 'ASSET_NOT_FOUND', - message: 'Plugin error - Unable to get asset filename for unknown asset "invalid".' + message: 'Plugin error - Unable to get file name for unknown asset "invalid".' } }; diff --git a/test/function/samples/emit-asset/invalid-set-asset-source-id/_config.js b/test/function/samples/emit-asset/invalid-set-asset-source-id/_config.js index 2a2f2849773..67ed85414a5 100644 --- a/test/function/samples/emit-asset/invalid-set-asset-source-id/_config.js +++ b/test/function/samples/emit-asset/invalid-set-asset-source-id/_config.js @@ -11,7 +11,7 @@ module.exports = { error: { code: 'PLUGIN_ERROR', hook: 'buildStart', - message: 'Plugin error - Unable to set asset source for unknown asset "invalid".', + message: 'Plugin error - Unable to set the source for unknown asset "invalid".', plugin: 'test-plugin', pluginCode: 'ASSET_NOT_FOUND' } diff --git a/test/function/samples/emit-asset/set-asset-source-twice/_config.js b/test/function/samples/emit-asset/set-asset-source-twice/_config.js index 695a4693dda..d009be672f8 100644 --- a/test/function/samples/emit-asset/set-asset-source-twice/_config.js +++ b/test/function/samples/emit-asset/set-asset-source-twice/_config.js @@ -13,7 +13,7 @@ module.exports = { error: { code: 'PLUGIN_ERROR', hook: 'buildEnd', - message: 'Plugin error - Unable to set asset source for "test.ext", source already set.', + message: 'Plugin error - Unable to set the source for asset "test.ext", source already set.', plugin: 'test-plugin', pluginCode: 'ASSET_SOURCE_ALREADY_SET' } diff --git a/test/function/samples/emit-entry-chunk/invalid-chunk-id/_config.js b/test/function/samples/emit-entry-chunk/invalid-chunk-id/_config.js new file mode 100644 index 00000000000..878e67a24ff --- /dev/null +++ b/test/function/samples/emit-entry-chunk/invalid-chunk-id/_config.js @@ -0,0 +1,15 @@ +module.exports = { + description: 'throws for invalid chunk ids', + options: { + plugins: { + name: 'test-plugin', + load() { + return `export default import.meta.ROLLUP_CHUNK_URL_invalid;`; + } + } + }, + generateError: { + code: 'CHUNK_NOT_FOUND', + message: 'Plugin error - Unable to get file name for unknown chunk "invalid".' + } +}; diff --git a/test/function/samples/emit-entry-chunk/invalid-chunk-id/main.js b/test/function/samples/emit-entry-chunk/invalid-chunk-id/main.js new file mode 100644 index 00000000000..c4b940fc952 --- /dev/null +++ b/test/function/samples/emit-entry-chunk/invalid-chunk-id/main.js @@ -0,0 +1 @@ +throw new Error('should not build'); From 994a89dee005b678bcdabcfe50dc5114d00744dd Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Wed, 17 Apr 2019 17:49:14 +0200 Subject: [PATCH 29/60] Fail if filename is not yet available --- src/Module.ts | 1 - src/ModuleLoader.ts | 27 ++++++++++--------- src/utils/buildPhase.ts | 4 +++ src/utils/error.ts | 10 +++++++ .../chunk-filename-not-available/_config.js | 21 +++++++++++++++ .../chunk-filename-not-available/chunk.js | 1 + .../chunk-filename-not-available}/main.js | 0 .../chunk-not-found}/_config.js | 0 .../emit-entry-chunk/chunk-not-found/main.js | 1 + 9 files changed, 52 insertions(+), 13 deletions(-) create mode 100644 src/utils/buildPhase.ts create mode 100644 test/function/samples/emit-entry-chunk/chunk-filename-not-available/_config.js create mode 100644 test/function/samples/emit-entry-chunk/chunk-filename-not-available/chunk.js rename test/function/samples/{emit-entry-chunk-not-found => emit-entry-chunk/chunk-filename-not-available}/main.js (100%) rename test/function/samples/{emit-entry-chunk-not-found => emit-entry-chunk/chunk-not-found}/_config.js (100%) create mode 100644 test/function/samples/emit-entry-chunk/chunk-not-found/main.js diff --git a/src/Module.ts b/src/Module.ts index 97f009cbd36..e58224f02fe 100644 --- a/src/Module.ts +++ b/src/Module.ts @@ -523,7 +523,6 @@ export default class Module { deoptimizationTracker: this.graph.deoptimizationTracker, error: this.error.bind(this), fileName, // Needed for warnings - // TODO Lukas move asset handling to graph? getAssetFileName: this.graph.pluginDriver.getAssetFileName, getChunkFileName: this.graph.moduleLoader.getChunkFileName.bind(this.graph.moduleLoader), getExports: this.getExports.bind(this), diff --git a/src/ModuleLoader.ts b/src/ModuleLoader.ts index 6bc9bee8c1e..ce94b5c2b74 100644 --- a/src/ModuleLoader.ts +++ b/src/ModuleLoader.ts @@ -6,7 +6,8 @@ import { ModuleJSON, ResolvedId, ResolveIdResult, SourceDescription } from './ro import { error, errorCannotAssignModuleToChunk, - errorChunkMetaIdNotFoundForFilename + errorChunkMetaIdNotFoundForFilename, + errorChunkNotGeneratedForFileName } from './utils/error'; import { addWithNewMetaId } from './utils/metaIds'; import { isRelative, resolve } from './utils/path'; @@ -29,7 +30,7 @@ function normalizeRelativeExternalId(importee: string, source: string) { } export class ModuleLoader { - private readonly entriesByMetaId = new Map(); + private readonly entriesByMetaId = new Map(); private readonly entryModules: Module[] = []; private readonly graph: Graph; private latestLoadModulesPromise: Promise = Promise.resolve(); @@ -49,7 +50,10 @@ export class ModuleLoader { } addEntryModuleAndGetMetaId(unresolvedEntryModule: UnresolvedModuleWithAlias): string { - const entryRecord: { module: Module | null } = { module: null }; + const entryRecord: { module: Module | null; name: string } = { + module: null, + name: unresolvedEntryModule.unresolvedId + }; const metaId = addWithNewMetaId( entryRecord, this.entriesByMetaId, @@ -114,18 +118,17 @@ export class ModuleLoader { return this.awaitLoadModulesPromise(loadNewManualChunkModulesPromise); } + // TODO Lukas use graph phases getChunkFileName(metaId: string): string { const entryRecord = this.entriesByMetaId.get(metaId); if (!entryRecord) errorChunkMetaIdNotFoundForFilename(metaId); - // TODO Lukas check correct file name - if (entryRecord.module === null) - error({ - code: 'XXX', - message: `Plugin error - Unable to get chunk file name for chunk ${metaId}. Ensure that generate is called first.` - }); - return entryRecord.module.facadeChunk - ? entryRecord.module.facadeChunk.id - : entryRecord.module.chunk.id; + const fileName = + entryRecord.module && + (entryRecord.module.facadeChunk + ? entryRecord.module.facadeChunk.id + : entryRecord.module.chunk.id); + if (!fileName) errorChunkNotGeneratedForFileName(entryRecord); + return fileName; } private awaitLoadModulesPromise(loadNewModulesPromise: Promise): Promise { diff --git a/src/utils/buildPhase.ts b/src/utils/buildPhase.ts new file mode 100644 index 00000000000..80d62a9ff81 --- /dev/null +++ b/src/utils/buildPhase.ts @@ -0,0 +1,4 @@ +export enum BuildPhase { + INIT = 1, + LOAD +} diff --git a/src/utils/error.ts b/src/utils/error.ts index 0dfa0e3765c..f4e4e0422d4 100644 --- a/src/utils/error.ts +++ b/src/utils/error.ts @@ -37,6 +37,7 @@ enum Errors { ASSET_SOURCE_MISSING = 'ASSET_SOURCE_MISSING', ASSET_SOURCE_NOT_FOUND = 'ASSET_SOURCE_NOT_FOUND', CHUNK_NOT_FOUND = 'CHUNK_NOT_FOUND', + CHUNK_NOT_GENERATED = 'CHUNK_NOT_GENERATED', INVALID_ASSET_NAME = 'INVALID_ASSET_NAME', INVALID_CHUNK = 'INVALID_CHUNK' } @@ -50,6 +51,15 @@ export function errorAssetNotFinalisedForFileName(asset: Asset) { }); } +export function errorChunkNotGeneratedForFileName(entry: { name: string }) { + error({ + code: Errors.CHUNK_NOT_GENERATED, + message: `Plugin error - Unable to get file name for chunk "${ + entry.name + }". Ensure that generate is called first.` + }); +} + export function errorAssetMetaIdNotFoundForFilename(assetMetaId: string) { error({ code: Errors.ASSET_NOT_FOUND, diff --git a/test/function/samples/emit-entry-chunk/chunk-filename-not-available/_config.js b/test/function/samples/emit-entry-chunk/chunk-filename-not-available/_config.js new file mode 100644 index 00000000000..40ecb0adba8 --- /dev/null +++ b/test/function/samples/emit-entry-chunk/chunk-filename-not-available/_config.js @@ -0,0 +1,21 @@ +module.exports = { + description: 'Throws when accessing the filename before it has been generated', + options: { + input: 'main.js', + plugins: { + name: 'test-plugin', + buildStart() { + const chunkId = this.emitEntryChunk('chunk.js'); + this.getChunkFileName(chunkId); + } + } + }, + error: { + code: 'PLUGIN_ERROR', + hook: 'buildStart', + message: + 'Plugin error - Unable to get file name for chunk "chunk.js". Ensure that generate is called first.', + plugin: 'test-plugin', + pluginCode: 'CHUNK_NOT_GENERATED' + } +}; diff --git a/test/function/samples/emit-entry-chunk/chunk-filename-not-available/chunk.js b/test/function/samples/emit-entry-chunk/chunk-filename-not-available/chunk.js new file mode 100644 index 00000000000..36b1d61dd25 --- /dev/null +++ b/test/function/samples/emit-entry-chunk/chunk-filename-not-available/chunk.js @@ -0,0 +1 @@ +console.log('chunk'); diff --git a/test/function/samples/emit-entry-chunk-not-found/main.js b/test/function/samples/emit-entry-chunk/chunk-filename-not-available/main.js similarity index 100% rename from test/function/samples/emit-entry-chunk-not-found/main.js rename to test/function/samples/emit-entry-chunk/chunk-filename-not-available/main.js diff --git a/test/function/samples/emit-entry-chunk-not-found/_config.js b/test/function/samples/emit-entry-chunk/chunk-not-found/_config.js similarity index 100% rename from test/function/samples/emit-entry-chunk-not-found/_config.js rename to test/function/samples/emit-entry-chunk/chunk-not-found/_config.js diff --git a/test/function/samples/emit-entry-chunk/chunk-not-found/main.js b/test/function/samples/emit-entry-chunk/chunk-not-found/main.js new file mode 100644 index 00000000000..c0b933d7b56 --- /dev/null +++ b/test/function/samples/emit-entry-chunk/chunk-not-found/main.js @@ -0,0 +1 @@ +console.log('main'); From 5853e05a88d6868f7537af568836ba14b9db7286 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Thu, 18 Apr 2019 07:29:43 +0200 Subject: [PATCH 30/60] Fail when adding a chunk after loading has finished --- src/Graph.ts | 8 +++++--- src/ModuleLoader.ts | 2 -- src/utils/buildPhase.ts | 5 +++-- src/utils/error.ts | 8 ++++---- src/utils/pluginDriver.ts | 15 +++++++++++--- .../add-watch-file-generate/_config.js | 20 +++++++++++++++++++ .../samples/add-watch-file-generate/main.js | 1 + .../add-watch-file-generate/watched.js | 0 .../asset-source-missing/_config.js | 2 +- .../modules-loaded/_config.js | 19 ++++++++++++++++++ .../emit-entry-chunk/modules-loaded/chunk.js | 1 + .../emit-entry-chunk/modules-loaded/main.js | 1 + 12 files changed, 67 insertions(+), 15 deletions(-) create mode 100644 test/function/samples/add-watch-file-generate/_config.js create mode 100644 test/function/samples/add-watch-file-generate/main.js create mode 100644 test/function/samples/add-watch-file-generate/watched.js create mode 100644 test/function/samples/emit-entry-chunk/modules-loaded/_config.js create mode 100644 test/function/samples/emit-entry-chunk/modules-loaded/chunk.js create mode 100644 test/function/samples/emit-entry-chunk/modules-loaded/main.js diff --git a/src/Graph.ts b/src/Graph.ts index f9c27dcfdea..fe1676bad88 100644 --- a/src/Graph.ts +++ b/src/Graph.ts @@ -23,6 +23,7 @@ import { WarningHandler } from './rollup/types'; import { finaliseAsset } from './utils/assetHooks'; +import { BuildPhase } from './utils/buildPhase'; import { assignChunkColouringHashes } from './utils/chunkColouring'; import { Uint8ArrayToHexString } from './utils/entryHashing'; import { analyseModuleExecution, sortByExecutionOrder } from './utils/executionOrder'; @@ -66,14 +67,13 @@ export default class Graph { contextParse: (code: string, acornOptions?: acorn.Options) => ESTree.Program; curChunkIndex = 0; deoptimizationTracker: EntityPathTracker; - // track graph build status as each graph instance is used only once - finished = false; getModuleContext: (id: string) => string; isExternal: IsExternal; isPureExternalModule: (id: string) => boolean; moduleById = new Map(); moduleLoader: ModuleLoader; needsTreeshakingPass: boolean = false; + phase: BuildPhase = BuildPhase.LOAD_AND_PARSE; pluginDriver: PluginDriver; preserveModules: boolean; scope: GlobalScope; @@ -238,6 +238,8 @@ export default class Graph { } timeEnd('parse modules', 2); + this.phase = BuildPhase.ANALYSE; + // Phase 2 - linking. We populate the module dependency links and // determine the topological execution order for the bundle timeStart('analyse dependency graph', 2); @@ -341,7 +343,7 @@ export default class Graph { timeEnd('generate chunks', 2); - this.finished = true; + this.phase = BuildPhase.GENERATE; return chunks.concat(facades); }); } diff --git a/src/ModuleLoader.ts b/src/ModuleLoader.ts index ce94b5c2b74..9b1a803d53f 100644 --- a/src/ModuleLoader.ts +++ b/src/ModuleLoader.ts @@ -70,7 +70,6 @@ export class ModuleLoader { return metaId; } - // TODO Lukas fail if finished addEntryModules( unresolvedEntryModules: UnresolvedModuleWithAlias[] ): Promise<{ @@ -118,7 +117,6 @@ export class ModuleLoader { return this.awaitLoadModulesPromise(loadNewManualChunkModulesPromise); } - // TODO Lukas use graph phases getChunkFileName(metaId: string): string { const entryRecord = this.entriesByMetaId.get(metaId); if (!entryRecord) errorChunkMetaIdNotFoundForFilename(metaId); diff --git a/src/utils/buildPhase.ts b/src/utils/buildPhase.ts index 80d62a9ff81..f5b530b034b 100644 --- a/src/utils/buildPhase.ts +++ b/src/utils/buildPhase.ts @@ -1,4 +1,5 @@ export enum BuildPhase { - INIT = 1, - LOAD + LOAD_AND_PARSE = 0, + ANALYSE, + GENERATE } diff --git a/src/utils/error.ts b/src/utils/error.ts index f4e4e0422d4..eda92329446 100644 --- a/src/utils/error.ts +++ b/src/utils/error.ts @@ -30,16 +30,16 @@ export function augmentCodeLocation( } } -enum Errors { +export enum Errors { ASSET_NOT_FINALISED = 'ASSET_NOT_FINALISED', ASSET_NOT_FOUND = 'ASSET_NOT_FOUND', ASSET_SOURCE_ALREADY_SET = 'ASSET_SOURCE_ALREADY_SET', ASSET_SOURCE_MISSING = 'ASSET_SOURCE_MISSING', - ASSET_SOURCE_NOT_FOUND = 'ASSET_SOURCE_NOT_FOUND', CHUNK_NOT_FOUND = 'CHUNK_NOT_FOUND', CHUNK_NOT_GENERATED = 'CHUNK_NOT_GENERATED', INVALID_ASSET_NAME = 'INVALID_ASSET_NAME', - INVALID_CHUNK = 'INVALID_CHUNK' + INVALID_CHUNK = 'INVALID_CHUNK', + INVALID_ROLLUP_PHASE = 'INVALID_ROLLUP_PHASE' } export function errorAssetNotFinalisedForFileName(asset: Asset) { @@ -92,7 +92,7 @@ export function errorAssetSourceMissingForSetSource(asset: Asset) { export function errorNoAssetSourceSet(asset: Asset) { error({ - code: Errors.ASSET_SOURCE_NOT_FOUND, + code: Errors.ASSET_SOURCE_MISSING, message: `Plugin error creating asset "${asset.name}" - no asset source set.` }); } diff --git a/src/utils/pluginDriver.ts b/src/utils/pluginDriver.ts index eb2602bd4af..8a9c1138129 100644 --- a/src/utils/pluginDriver.ts +++ b/src/utils/pluginDriver.ts @@ -15,8 +15,9 @@ import { SerializablePluginCache } from '../rollup/types'; import { createAssetPluginHooks } from './assetHooks'; +import { BuildPhase } from './buildPhase'; import { getRollupDefaultPlugin } from './defaultPlugin'; -import { error } from './error'; +import { error, Errors } from './error'; import { NameCollection } from './reservedNames'; type Args = T extends (...args: infer K) => any ? K : never; @@ -137,11 +138,19 @@ export function createPluginDriver( const context: PluginContext = { emitEntryChunk(id: string) { + if (graph.phase > BuildPhase.LOAD_AND_PARSE) + this.error({ + code: Errors.INVALID_ROLLUP_PHASE, + message: `Cannot call emitEntryChunk after module loading has finished.` + }); return graph.moduleLoader.addEntryModuleAndGetMetaId({ alias: null, unresolvedId: id }); }, addWatchFile(id: string) { - // TODO Lukas is this tested? - if (graph.finished) this.error('addWatchFile can only be called during the build.'); + if (graph.phase >= BuildPhase.GENERATE) + this.error({ + code: Errors.INVALID_ROLLUP_PHASE, + message: `Cannot call addWatchFile after the build has finished.` + }); graph.watchFiles[id] = true; }, cache: cacheInstance, diff --git a/test/function/samples/add-watch-file-generate/_config.js b/test/function/samples/add-watch-file-generate/_config.js new file mode 100644 index 00000000000..38c4562c7eb --- /dev/null +++ b/test/function/samples/add-watch-file-generate/_config.js @@ -0,0 +1,20 @@ +const path = require('path'); + +module.exports = { + description: 'throws when adding watch files during generate', + options: { + plugins: { + name: 'test-plugin', + renderStart() { + this.addWatchFile(path.resolve(__dirname, 'watched.js')); + } + } + }, + generateError: { + code: 'PLUGIN_ERROR', + hook: 'renderStart', + message: 'Cannot call addWatchFile after the build has finished.', + plugin: 'test-plugin', + pluginCode: 'INVALID_ROLLUP_PHASE' + } +}; diff --git a/test/function/samples/add-watch-file-generate/main.js b/test/function/samples/add-watch-file-generate/main.js new file mode 100644 index 00000000000..a9244a453fb --- /dev/null +++ b/test/function/samples/add-watch-file-generate/main.js @@ -0,0 +1 @@ +throw new Error('Not executed'); diff --git a/test/function/samples/add-watch-file-generate/watched.js b/test/function/samples/add-watch-file-generate/watched.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/function/samples/emit-asset/asset-source-missing/_config.js b/test/function/samples/emit-asset/asset-source-missing/_config.js index ccc218c8ca5..e29179abf9e 100644 --- a/test/function/samples/emit-asset/asset-source-missing/_config.js +++ b/test/function/samples/emit-asset/asset-source-missing/_config.js @@ -9,7 +9,7 @@ module.exports = { } }, generateError: { - code: 'ASSET_SOURCE_NOT_FOUND', + code: 'ASSET_SOURCE_MISSING', message: 'Plugin error creating asset "test.ext" - no asset source set.' } }; diff --git a/test/function/samples/emit-entry-chunk/modules-loaded/_config.js b/test/function/samples/emit-entry-chunk/modules-loaded/_config.js new file mode 100644 index 00000000000..27540891884 --- /dev/null +++ b/test/function/samples/emit-entry-chunk/modules-loaded/_config.js @@ -0,0 +1,19 @@ +module.exports = { + description: 'Throws when adding a chunk after the modules have finished loading', + options: { + input: 'main.js', + plugins: { + name: 'test-plugin', + buildEnd() { + this.emitEntryChunk('chunk.js'); + } + } + }, + error: { + code: 'PLUGIN_ERROR', + hook: 'buildEnd', + message: 'Cannot call emitEntryChunk after module loading has finished.', + plugin: 'test-plugin', + pluginCode: 'INVALID_ROLLUP_PHASE' + } +}; diff --git a/test/function/samples/emit-entry-chunk/modules-loaded/chunk.js b/test/function/samples/emit-entry-chunk/modules-loaded/chunk.js new file mode 100644 index 00000000000..a9244a453fb --- /dev/null +++ b/test/function/samples/emit-entry-chunk/modules-loaded/chunk.js @@ -0,0 +1 @@ +throw new Error('Not executed'); diff --git a/test/function/samples/emit-entry-chunk/modules-loaded/main.js b/test/function/samples/emit-entry-chunk/modules-loaded/main.js new file mode 100644 index 00000000000..c0b933d7b56 --- /dev/null +++ b/test/function/samples/emit-entry-chunk/modules-loaded/main.js @@ -0,0 +1 @@ +console.log('main'); From 85375536090601e854193e179d25daac82acebf7 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Thu, 18 Apr 2019 07:33:09 +0200 Subject: [PATCH 31/60] Do not access process.cwd() unchecked --- src/utils/error.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/utils/error.ts b/src/utils/error.ts index eda92329446..dc505b6d059 100644 --- a/src/utils/error.ts +++ b/src/utils/error.ts @@ -1,7 +1,7 @@ import { locate } from 'locate-character'; import { Asset, RollupError, RollupWarning } from '../rollup/types'; import getCodeFrame from './getCodeFrame'; -import { relative } from './path'; +import relativeId from './relativeId'; export function error(base: Error | RollupError, props?: RollupError) { if (base instanceof Error === false) base = Object.assign(new Error(base.message), base); @@ -111,7 +111,6 @@ export function errorInvalidAssetName(name: string) { }); } -// TODO Lukas polyfill process.cwd() // TODO Lukas other errors export function errorCannotAssignModuleToChunk( moduleId: string, @@ -120,8 +119,7 @@ export function errorCannotAssignModuleToChunk( ) { error({ code: Errors.INVALID_CHUNK, - message: `Cannot assign ${relative( - process.cwd(), + message: `Cannot assign ${relativeId( moduleId )} to the "${assignToAlias}" chunk as it is already in the "${currentAlias}" chunk.` }); From b445491f4dc984a08eb4c17d64a42754cadc6ae5 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Thu, 18 Apr 2019 07:46:49 +0200 Subject: [PATCH 32/60] Move isExternal to module loader --- src/Graph.ts | 20 ++++++-------------- src/ModuleLoader.ts | 29 ++++++++++++++++++++++------- src/utils/error.ts | 1 - src/utils/pluginDriver.ts | 2 +- 4 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/Graph.ts b/src/Graph.ts index fe1676bad88..e1b3f516f9e 100644 --- a/src/Graph.ts +++ b/src/Graph.ts @@ -12,7 +12,6 @@ import { ModuleLoader, UnresolvedModuleWithAlias } from './ModuleLoader'; import { Asset, InputOptions, - IsExternal, ModuleJSON, OutputBundle, RollupCache, @@ -68,7 +67,6 @@ export default class Graph { curChunkIndex = 0; deoptimizationTracker: EntityPathTracker; getModuleContext: (id: string) => string; - isExternal: IsExternal; isPureExternalModule: (id: string) => boolean; moduleById = new Map(); moduleLoader: ModuleLoader; @@ -156,17 +154,6 @@ export default class Graph { }); } - // TODO Lukas move this to the module loader - if (typeof options.external === 'function') { - const external = options.external; - this.isExternal = (id, parentId, isResolved) => - !id.startsWith('\0') && external(id, parentId, isResolved); - } else { - const external = options.external; - const ids = new Set(Array.isArray(external) ? external : external ? [external] : []); - this.isExternal = id => ids.has(id); - } - this.shimMissingExports = options.shimMissingExports; this.scope = new GlobalScope(); this.context = String(options.context); @@ -205,7 +192,12 @@ export default class Graph { : []) ); this.acornParser = acorn.Parser.extend(...acornPluginsToInject); - this.moduleLoader = new ModuleLoader(this, this.moduleById, this.pluginDriver); + this.moduleLoader = new ModuleLoader( + this, + this.moduleById, + this.pluginDriver, + options.external + ); } build( diff --git a/src/ModuleLoader.ts b/src/ModuleLoader.ts index 9b1a803d53f..264eec0d220 100644 --- a/src/ModuleLoader.ts +++ b/src/ModuleLoader.ts @@ -2,7 +2,14 @@ import * as ESTree from 'estree'; import ExternalModule from './ExternalModule'; import Graph from './Graph'; import Module from './Module'; -import { ModuleJSON, ResolvedId, ResolveIdResult, SourceDescription } from './rollup/types'; +import { + ExternalOption, + IsExternal, + ModuleJSON, + ResolvedId, + ResolveIdResult, + SourceDescription +} from './rollup/types'; import { error, errorCannotAssignModuleToChunk, @@ -30,6 +37,7 @@ function normalizeRelativeExternalId(importee: string, source: string) { } export class ModuleLoader { + readonly isExternal: IsExternal; private readonly entriesByMetaId = new Map(); private readonly entryModules: Module[] = []; private readonly graph: Graph; @@ -38,15 +46,22 @@ export class ModuleLoader { private readonly modulesById: Map; private readonly pluginDriver: PluginDriver; - // TODO Lukas get rid of graph dependency constructor( graph: Graph, modulesById: Map, - pluginDriver: PluginDriver + pluginDriver: PluginDriver, + external: ExternalOption ) { this.graph = graph; this.modulesById = modulesById; this.pluginDriver = pluginDriver; + if (typeof external === 'function') { + this.isExternal = (id, parentId, isResolved) => + !id.startsWith('\0') && external(id, parentId, isResolved); + } else { + const ids = new Set(Array.isArray(external) ? external : external ? [external] : []); + this.isExternal = id => ids.has(id); + } } addEntryModuleAndGetMetaId(unresolvedEntryModule: UnresolvedModuleWithAlias): string { @@ -162,7 +177,7 @@ export class ModuleLoader { dynamicImport.alias = getAliasName(replacement); if (typeof dynamicImportExpression !== 'string') { dynamicImport.resolution = replacement; - } else if (this.graph.isExternal(replacement, module.id, true)) { + } else if (this.isExternal(replacement, module.id, true)) { let externalModule; if (!this.modulesById.has(replacement)) { externalModule = new ExternalModule({ @@ -344,7 +359,7 @@ export class ModuleLoader { } } else { id = resolveIdResult; - if (this.graph.isExternal(id, module.id, true)) { + if (this.isExternal(id, module.id, true)) { external = true; } } @@ -354,7 +369,7 @@ export class ModuleLoader { } else { id = normalizeRelativeExternalId(module.id, source); external = true; - if (resolveIdResult !== false && !this.graph.isExternal(id, module.id, true)) { + if (resolveIdResult !== false && !this.isExternal(id, module.id, true)) { if (isRelative(source)) { error({ code: 'UNRESOLVED_IMPORT', @@ -379,7 +394,7 @@ export class ModuleLoader { return Promise.resolve( module.resolvedIds[source] || Promise.resolve( - this.graph.isExternal(source, module.id, false) + this.isExternal(source, module.id, false) ? { id: source, external: true } : this.pluginDriver.hookFirst('resolveId', [source, module.id]) ).then((result: ResolveIdResult) => this.normalizeResolveIdResult(result, module, source)) diff --git a/src/utils/error.ts b/src/utils/error.ts index dc505b6d059..4fbddb8de27 100644 --- a/src/utils/error.ts +++ b/src/utils/error.ts @@ -111,7 +111,6 @@ export function errorInvalidAssetName(name: string) { }); } -// TODO Lukas other errors export function errorCannotAssignModuleToChunk( moduleId: string, assignToAlias: string, diff --git a/src/utils/pluginDriver.ts b/src/utils/pluginDriver.ts index 8a9c1138129..dfc1dc2b5f9 100644 --- a/src/utils/pluginDriver.ts +++ b/src/utils/pluginDriver.ts @@ -163,7 +163,7 @@ export function createPluginDriver( error(err); }, isExternal(id: string, parentId: string, isResolved = false) { - return graph.isExternal(id, parentId, isResolved); + return graph.moduleLoader.isExternal(id, parentId, isResolved); }, getAssetFileName, getChunkFileName(chunkMetaId: string): string { From 746c2b9cc035b9448166f72fef9c05138b6a78f8 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Thu, 18 Apr 2019 08:27:23 +0200 Subject: [PATCH 33/60] Fix typing of resolveId context hook --- docs/05-plugins.md | 2 +- src/ModuleLoader.ts | 4 ++-- src/rollup/types.d.ts | 3 ++- src/utils/defaultPlugin.ts | 1 + 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/05-plugins.md b/docs/05-plugins.md index 9fbf1f28b17..acc95351ea2 100644 --- a/docs/05-plugins.md +++ b/docs/05-plugins.md @@ -347,7 +347,7 @@ or converted into an Array via `Array.from(this.moduleIds)`. Use Rollup's internal acorn instance to parse code to an AST. -#### `this.resolveId(importee: string, importer: string) => string` +#### `this.resolveId(importee: string, importer: string) => Promise` Resolve imports to module ids (i.e. file names). Uses the same hooks as Rollup itself. diff --git a/src/ModuleLoader.ts b/src/ModuleLoader.ts index 264eec0d220..e17fd561d35 100644 --- a/src/ModuleLoader.ts +++ b/src/ModuleLoader.ts @@ -167,11 +167,11 @@ export class ModuleLoader { module.getDynamicImportExpressions().map((dynamicImportExpression, index) => // TODO we only should expose the acorn AST here this.pluginDriver - .hookFirst<'resolveDynamicImport', string>('resolveDynamicImport', [ + .hookFirst('resolveDynamicImport', [ dynamicImportExpression as string | ESTree.Node, module.id ]) - .then(replacement => { + .then((replacement: string | void) => { if (!replacement) return; const dynamicImport = module.dynamicImports[index]; dynamicImport.alias = getAliasName(replacement); diff --git a/src/rollup/types.d.ts b/src/rollup/types.d.ts index 751512d2104..002c8bc50c3 100644 --- a/src/rollup/types.d.ts +++ b/src/rollup/types.d.ts @@ -124,7 +124,7 @@ export interface PluginContext extends MinimalPluginContext { isExternal: IsExternal; moduleIds: IterableIterator; parse: (input: string, options: any) => ESTree.Program; - resolveId: ResolveIdHook; + resolveId: (id: string, parent: string) => Promise; setAssetSource: (assetMetaId: string, source: string | Buffer) => void; warn: (warning: RollupWarning | string, pos?: { column: number; line: number }) => void; /** @deprecated */ @@ -190,6 +190,7 @@ export type RenderChunkHook = ( | string | null; +// TODO this should probably return ResolveIdResult export type ResolveDynamicImportHook = ( this: PluginContext, specifier: string | ESTree.Node, diff --git a/src/utils/defaultPlugin.ts b/src/utils/defaultPlugin.ts index 9d938cb350c..c5b6f390cf8 100644 --- a/src/utils/defaultPlugin.ts +++ b/src/utils/defaultPlugin.ts @@ -12,6 +12,7 @@ export function getRollupDefaultPlugin(options: InputOptions): Plugin { }, resolveDynamicImport(specifier, parentId) { if (typeof specifier === 'string' && !this.isExternal(specifier, parentId, false)) + // TODO this typecast will cause problems if resolveId returns false or an object return >this.resolveId(specifier, parentId); }, resolveFileUrl({ relativePath, format }) { From 2fd3e6d71a79967ea07a1003bf76c37b81144329 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Fri, 19 Apr 2019 07:50:44 +0200 Subject: [PATCH 34/60] Refine worker test --- src/utils/pluginDriver.ts | 1 - .../samples/emit-entry-worker/_config.js | 31 +++++++++++++------ .../_expected/amd/chunks/chunk.js | 9 ++---- .../_expected/amd/chunks/chunk2.js | 10 ++++++ .../emit-entry-worker/_expected/amd/main.js | 11 ++++--- .../_expected/amd/worker-proxy.js | 2 ++ .../emit-entry-worker/_expected/amd/worker.js | 4 +-- .../_expected/cjs/chunks/chunk.js | 7 ++--- .../_expected/cjs/chunks/chunk2.js | 8 +++++ .../emit-entry-worker/_expected/cjs/main.js | 11 ++++--- .../_expected/cjs/worker-proxy.js | 3 ++ .../emit-entry-worker/_expected/cjs/worker.js | 4 ++- .../_expected/es/chunks/chunk.js | 7 ++--- .../_expected/es/chunks/chunk2.js | 6 ++++ .../emit-entry-worker/_expected/es/main.js | 11 ++++--- .../_expected/es/worker-proxy.js | 1 + .../emit-entry-worker/_expected/es/worker.js | 4 ++- .../_expected/system/chunks/chunk.js | 15 ++++----- .../_expected/system/chunks/chunk2.js | 13 ++++++++ .../_expected/system/main.js | 15 ++++++--- .../_expected/system/worker-proxy.js | 2 ++ .../_expected/system/worker.js | 8 +++-- .../samples/emit-entry-worker/main.js | 6 ++-- .../samples/emit-entry-worker/shared.js | 1 + .../samples/emit-entry-worker/worker.js | 4 ++- 25 files changed, 132 insertions(+), 62 deletions(-) create mode 100644 test/chunking-form/samples/emit-entry-worker/_expected/amd/chunks/chunk2.js create mode 100644 test/chunking-form/samples/emit-entry-worker/_expected/amd/worker-proxy.js create mode 100644 test/chunking-form/samples/emit-entry-worker/_expected/cjs/chunks/chunk2.js create mode 100644 test/chunking-form/samples/emit-entry-worker/_expected/cjs/worker-proxy.js create mode 100644 test/chunking-form/samples/emit-entry-worker/_expected/es/chunks/chunk2.js create mode 100644 test/chunking-form/samples/emit-entry-worker/_expected/es/worker-proxy.js create mode 100644 test/chunking-form/samples/emit-entry-worker/_expected/system/chunks/chunk2.js create mode 100644 test/chunking-form/samples/emit-entry-worker/_expected/system/worker-proxy.js create mode 100644 test/chunking-form/samples/emit-entry-worker/shared.js diff --git a/src/utils/pluginDriver.ts b/src/utils/pluginDriver.ts index dfc1dc2b5f9..f4a4ff5ebcb 100644 --- a/src/utils/pluginDriver.ts +++ b/src/utils/pluginDriver.ts @@ -22,7 +22,6 @@ import { NameCollection } from './reservedNames'; type Args = T extends (...args: infer K) => any ? K : never; -// TODO Lukas include defaultPlugin type export interface PluginDriver { emitAsset: EmitAsset; hasLoadersOrTransforms: boolean; diff --git a/test/chunking-form/samples/emit-entry-worker/_config.js b/test/chunking-form/samples/emit-entry-worker/_config.js index 51a39261230..5f2f23f67ce 100644 --- a/test/chunking-form/samples/emit-entry-worker/_config.js +++ b/test/chunking-form/samples/emit-entry-worker/_config.js @@ -1,9 +1,6 @@ -let metaId; +let workerId; +let proxyId; -// TODO Lukas can we load requirejs via renderChunk? -// importScripts('../../../../../../node_modules/requirejs/require.js'); -// requirejs([], function () { ... -// also test shared modules module.exports = { description: 'allows adding additional entry points', options: { @@ -14,18 +11,34 @@ module.exports = { plugins: { load(id) { if (id === 'merged' || id === 'nested') { - if (!metaId) { - metaId = this.emitEntryChunk('worker'); + if (!workerId) { + workerId = this.emitEntryChunk('worker'); + proxyId = this.emitEntryChunk('worker-proxy'); } return ` export const getWorkerMessage = () => new Promise(resolve => { - const worker = new Worker(import.meta.ROLLUP_CHUNK_URL_${metaId}, {type: 'module'}); + const worker = new Worker(import.meta.ROLLUP_CHUNK_URL_${proxyId}); worker.onmessage = resolve; });`; } + if (id === 'worker-proxy') { + return `PLACEHOLDER(import.meta.ROLLUP_CHUNK_URL_${workerId})`; + } + }, + renderChunk(code, chunk, options) { + if (chunk.facadeModuleId === 'worker-proxy') { + if (options.format === 'system') { + return `importScripts('../../../../../../node_modules/systemjs/dist/system.js'); +System.import('./${this.getChunkFileName(workerId)}');`; + } + if (options.format === 'amd') { + return `importScripts('../../../../../../node_modules/requirejs/require.js'); +requirejs(['./${this.getChunkFileName(workerId)}']);`; + } + } }, resolveId(id) { - if (id === 'merged' || id === 'nested') { + if (id === 'merged' || id === 'nested' || id === 'worker-proxy') { return id; } return null; diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/amd/chunks/chunk.js b/test/chunking-form/samples/emit-entry-worker/_expected/amd/chunks/chunk.js index ad6d56cfa97..b188047d8e0 100644 --- a/test/chunking-form/samples/emit-entry-worker/_expected/amd/chunks/chunk.js +++ b/test/chunking-form/samples/emit-entry-worker/_expected/amd/chunks/chunk.js @@ -1,10 +1,7 @@ -define(['module', 'exports'], function (module, exports) { 'use strict'; +define(['exports'], function (exports) { 'use strict'; - const getWorkerMessage = () => new Promise(resolve => { - const worker = new Worker(new URL(module.uri + '/../../worker.js', document.baseURI).href, {type: 'module'}); - worker.onmessage = resolve; - }); + const shared = 'shared'; - exports.getWorkerMessage = getWorkerMessage; + exports.shared = shared; }); diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/amd/chunks/chunk2.js b/test/chunking-form/samples/emit-entry-worker/_expected/amd/chunks/chunk2.js new file mode 100644 index 00000000000..a445b0e9849 --- /dev/null +++ b/test/chunking-form/samples/emit-entry-worker/_expected/amd/chunks/chunk2.js @@ -0,0 +1,10 @@ +define(['module', 'exports'], function (module, exports) { 'use strict'; + + const getWorkerMessage = () => new Promise(resolve => { + const worker = new Worker(new URL(module.uri + '/../../worker-proxy.js', document.baseURI).href); + worker.onmessage = resolve; + }); + + exports.getWorkerMessage = getWorkerMessage; + +}); diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/amd/main.js b/test/chunking-form/samples/emit-entry-worker/_expected/amd/main.js index c7eaf3a6dac..47fa1c45ce5 100644 --- a/test/chunking-form/samples/emit-entry-worker/_expected/amd/main.js +++ b/test/chunking-form/samples/emit-entry-worker/_expected/amd/main.js @@ -1,14 +1,15 @@ -define(['module', 'require'], function (module, require) { 'use strict'; +define(['module', 'require', './chunks/chunk.js'], function (module, require, __chunk_1) { 'use strict'; const getWorkerMessage = () => new Promise(resolve => { - const worker = new Worker(new URL(module.uri + '/../worker.js', document.baseURI).href, {type: 'module'}); + const worker = new Worker(new URL(module.uri + '/../worker-proxy.js', document.baseURI).href); worker.onmessage = resolve; }); - getWorkerMessage().then(message => document.write(`

1: ${message.data}

`)); + document.body.innerHTML += `

main: ${__chunk_1.shared}

`; + getWorkerMessage().then(message => (document.body.innerHTML += `

1: ${message.data}

`)); - new Promise(function (resolve, reject) { require(['./chunks/chunk.js'], resolve, reject) }) + new Promise(function (resolve, reject) { require(['./chunks/chunk2.js'], resolve, reject) }) .then(result => result.getWorkerMessage()) - .then(message => document.write(`

2: ${message.data}

`)); + .then(message => (document.body.innerHTML += `

2: ${message.data}

`)); }); diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/amd/worker-proxy.js b/test/chunking-form/samples/emit-entry-worker/_expected/amd/worker-proxy.js new file mode 100644 index 00000000000..35fe9ceb868 --- /dev/null +++ b/test/chunking-form/samples/emit-entry-worker/_expected/amd/worker-proxy.js @@ -0,0 +1,2 @@ +importScripts('../../../../../../node_modules/requirejs/require.js'); +requirejs(['./worker.js']); diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/amd/worker.js b/test/chunking-form/samples/emit-entry-worker/_expected/amd/worker.js index 77279bd859f..4516491b07b 100644 --- a/test/chunking-form/samples/emit-entry-worker/_expected/amd/worker.js +++ b/test/chunking-form/samples/emit-entry-worker/_expected/amd/worker.js @@ -1,5 +1,5 @@ -define(function () { 'use strict'; +define(['./chunks/chunk.js'], function (__chunk_1) { 'use strict'; - postMessage('from worker'); + postMessage(`from worker: ${__chunk_1.shared}`); }); diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/cjs/chunks/chunk.js b/test/chunking-form/samples/emit-entry-worker/_expected/cjs/chunks/chunk.js index 61dd338f47c..e2dc6ecb8ef 100644 --- a/test/chunking-form/samples/emit-entry-worker/_expected/cjs/chunks/chunk.js +++ b/test/chunking-form/samples/emit-entry-worker/_expected/cjs/chunks/chunk.js @@ -1,8 +1,5 @@ 'use strict'; -const getWorkerMessage = () => new Promise(resolve => { - const worker = new Worker((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/../worker.js').href : new URL((document.currentScript && document.currentScript.src || document.baseURI) + '/../../worker.js').href), {type: 'module'}); - worker.onmessage = resolve; -}); +const shared = 'shared'; -exports.getWorkerMessage = getWorkerMessage; +exports.shared = shared; diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/cjs/chunks/chunk2.js b/test/chunking-form/samples/emit-entry-worker/_expected/cjs/chunks/chunk2.js new file mode 100644 index 00000000000..b04d405dc7a --- /dev/null +++ b/test/chunking-form/samples/emit-entry-worker/_expected/cjs/chunks/chunk2.js @@ -0,0 +1,8 @@ +'use strict'; + +const getWorkerMessage = () => new Promise(resolve => { + const worker = new Worker((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/../worker-proxy.js').href : new URL((document.currentScript && document.currentScript.src || document.baseURI) + '/../../worker-proxy.js').href)); + worker.onmessage = resolve; +}); + +exports.getWorkerMessage = getWorkerMessage; diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/cjs/main.js b/test/chunking-form/samples/emit-entry-worker/_expected/cjs/main.js index 20755ed466d..de2e30e9a42 100644 --- a/test/chunking-form/samples/emit-entry-worker/_expected/cjs/main.js +++ b/test/chunking-form/samples/emit-entry-worker/_expected/cjs/main.js @@ -1,12 +1,15 @@ 'use strict'; +var __chunk_1 = require('./chunks/chunk.js'); + const getWorkerMessage = () => new Promise(resolve => { - const worker = new Worker((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/worker.js').href : new URL((document.currentScript && document.currentScript.src || document.baseURI) + '/../worker.js').href), {type: 'module'}); + const worker = new Worker((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/worker-proxy.js').href : new URL((document.currentScript && document.currentScript.src || document.baseURI) + '/../worker-proxy.js').href)); worker.onmessage = resolve; }); -getWorkerMessage().then(message => document.write(`

1: ${message.data}

`)); +document.body.innerHTML += `

main: ${__chunk_1.shared}

`; +getWorkerMessage().then(message => (document.body.innerHTML += `

1: ${message.data}

`)); -Promise.resolve(require('./chunks/chunk.js')) +Promise.resolve(require('./chunks/chunk2.js')) .then(result => result.getWorkerMessage()) - .then(message => document.write(`

2: ${message.data}

`)); + .then(message => (document.body.innerHTML += `

2: ${message.data}

`)); diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/cjs/worker-proxy.js b/test/chunking-form/samples/emit-entry-worker/_expected/cjs/worker-proxy.js new file mode 100644 index 00000000000..cc45d6af87d --- /dev/null +++ b/test/chunking-form/samples/emit-entry-worker/_expected/cjs/worker-proxy.js @@ -0,0 +1,3 @@ +'use strict'; + +PLACEHOLDER((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/worker.js').href : new URL((document.currentScript && document.currentScript.src || document.baseURI) + '/../worker.js').href)); diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/cjs/worker.js b/test/chunking-form/samples/emit-entry-worker/_expected/cjs/worker.js index 2154e7b7a97..c9c2775eacc 100644 --- a/test/chunking-form/samples/emit-entry-worker/_expected/cjs/worker.js +++ b/test/chunking-form/samples/emit-entry-worker/_expected/cjs/worker.js @@ -1,3 +1,5 @@ 'use strict'; -postMessage('from worker'); +var __chunk_1 = require('./chunks/chunk.js'); + +postMessage(`from worker: ${__chunk_1.shared}`); diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/es/chunks/chunk.js b/test/chunking-form/samples/emit-entry-worker/_expected/es/chunks/chunk.js index ce751792d9f..7e7f4f90302 100644 --- a/test/chunking-form/samples/emit-entry-worker/_expected/es/chunks/chunk.js +++ b/test/chunking-form/samples/emit-entry-worker/_expected/es/chunks/chunk.js @@ -1,6 +1,3 @@ -const getWorkerMessage = () => new Promise(resolve => { - const worker = new Worker(new URL('../worker.js', import.meta.url).href, {type: 'module'}); - worker.onmessage = resolve; -}); +const shared = 'shared'; -export { getWorkerMessage }; +export { shared as a }; diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/es/chunks/chunk2.js b/test/chunking-form/samples/emit-entry-worker/_expected/es/chunks/chunk2.js new file mode 100644 index 00000000000..afbe3130f8a --- /dev/null +++ b/test/chunking-form/samples/emit-entry-worker/_expected/es/chunks/chunk2.js @@ -0,0 +1,6 @@ +const getWorkerMessage = () => new Promise(resolve => { + const worker = new Worker(new URL('../worker-proxy.js', import.meta.url).href); + worker.onmessage = resolve; +}); + +export { getWorkerMessage }; diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/es/main.js b/test/chunking-form/samples/emit-entry-worker/_expected/es/main.js index 70ea4e8f767..f2a6d0756d6 100644 --- a/test/chunking-form/samples/emit-entry-worker/_expected/es/main.js +++ b/test/chunking-form/samples/emit-entry-worker/_expected/es/main.js @@ -1,10 +1,13 @@ +import { a as shared } from './chunks/chunk.js'; + const getWorkerMessage = () => new Promise(resolve => { - const worker = new Worker(new URL('worker.js', import.meta.url).href, {type: 'module'}); + const worker = new Worker(new URL('worker-proxy.js', import.meta.url).href); worker.onmessage = resolve; }); -getWorkerMessage().then(message => document.write(`

1: ${message.data}

`)); +document.body.innerHTML += `

main: ${shared}

`; +getWorkerMessage().then(message => (document.body.innerHTML += `

1: ${message.data}

`)); -import('./chunks/chunk.js') +import('./chunks/chunk2.js') .then(result => result.getWorkerMessage()) - .then(message => document.write(`

2: ${message.data}

`)); + .then(message => (document.body.innerHTML += `

2: ${message.data}

`)); diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/es/worker-proxy.js b/test/chunking-form/samples/emit-entry-worker/_expected/es/worker-proxy.js new file mode 100644 index 00000000000..88e9531a22e --- /dev/null +++ b/test/chunking-form/samples/emit-entry-worker/_expected/es/worker-proxy.js @@ -0,0 +1 @@ +PLACEHOLDER(new URL('worker.js', import.meta.url).href); diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/es/worker.js b/test/chunking-form/samples/emit-entry-worker/_expected/es/worker.js index 89a9039df0d..b788aa660f4 100644 --- a/test/chunking-form/samples/emit-entry-worker/_expected/es/worker.js +++ b/test/chunking-form/samples/emit-entry-worker/_expected/es/worker.js @@ -1 +1,3 @@ -postMessage('from worker'); +import { a as shared } from './chunks/chunk.js'; + +postMessage(`from worker: ${shared}`); diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/system/chunks/chunk.js b/test/chunking-form/samples/emit-entry-worker/_expected/system/chunks/chunk.js index 1eafc4034cf..69b5ccbdda5 100644 --- a/test/chunking-form/samples/emit-entry-worker/_expected/system/chunks/chunk.js +++ b/test/chunking-form/samples/emit-entry-worker/_expected/system/chunks/chunk.js @@ -1,13 +1,10 @@ System.register([], function (exports, module) { - 'use strict'; - return { - execute: function () { + 'use strict'; + return { + execute: function () { - const getWorkerMessage = exports('getWorkerMessage', () => new Promise(resolve => { - const worker = new Worker(new URL('../worker.js', module.meta.url).href, {type: 'module'}); - worker.onmessage = resolve; - })); + const shared = exports('a', 'shared'); - } - }; + } + }; }); diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/system/chunks/chunk2.js b/test/chunking-form/samples/emit-entry-worker/_expected/system/chunks/chunk2.js new file mode 100644 index 00000000000..81655e5003f --- /dev/null +++ b/test/chunking-form/samples/emit-entry-worker/_expected/system/chunks/chunk2.js @@ -0,0 +1,13 @@ +System.register([], function (exports, module) { + 'use strict'; + return { + execute: function () { + + const getWorkerMessage = exports('getWorkerMessage', () => new Promise(resolve => { + const worker = new Worker(new URL('../worker-proxy.js', module.meta.url).href); + worker.onmessage = resolve; + })); + + } + }; +}); diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/system/main.js b/test/chunking-form/samples/emit-entry-worker/_expected/system/main.js index 1b1a3b48846..f679ae2b1a2 100644 --- a/test/chunking-form/samples/emit-entry-worker/_expected/system/main.js +++ b/test/chunking-form/samples/emit-entry-worker/_expected/system/main.js @@ -1,18 +1,23 @@ -System.register([], function (exports, module) { +System.register(['./chunks/chunk.js'], function (exports, module) { 'use strict'; + var shared; return { + setters: [function (module) { + shared = module.a; + }], execute: function () { const getWorkerMessage = () => new Promise(resolve => { - const worker = new Worker(new URL('worker.js', module.meta.url).href, {type: 'module'}); + const worker = new Worker(new URL('worker-proxy.js', module.meta.url).href); worker.onmessage = resolve; }); - getWorkerMessage().then(message => document.write(`

1: ${message.data}

`)); + document.body.innerHTML += `

main: ${shared}

`; + getWorkerMessage().then(message => (document.body.innerHTML += `

1: ${message.data}

`)); - module.import('./chunks/chunk.js') + module.import('./chunks/chunk2.js') .then(result => result.getWorkerMessage()) - .then(message => document.write(`

2: ${message.data}

`)); + .then(message => (document.body.innerHTML += `

2: ${message.data}

`)); } }; diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/system/worker-proxy.js b/test/chunking-form/samples/emit-entry-worker/_expected/system/worker-proxy.js new file mode 100644 index 00000000000..dfb005926dd --- /dev/null +++ b/test/chunking-form/samples/emit-entry-worker/_expected/system/worker-proxy.js @@ -0,0 +1,2 @@ +importScripts('../../../../../../node_modules/systemjs/dist/system.js'); +System.import('./worker.js'); diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/system/worker.js b/test/chunking-form/samples/emit-entry-worker/_expected/system/worker.js index 6523f179726..f2964dcc68f 100644 --- a/test/chunking-form/samples/emit-entry-worker/_expected/system/worker.js +++ b/test/chunking-form/samples/emit-entry-worker/_expected/system/worker.js @@ -1,9 +1,13 @@ -System.register([], function (exports, module) { +System.register(['./chunks/chunk.js'], function (exports, module) { 'use strict'; + var shared; return { + setters: [function (module) { + shared = module.a; + }], execute: function () { - postMessage('from worker'); + postMessage(`from worker: ${shared}`); } }; diff --git a/test/chunking-form/samples/emit-entry-worker/main.js b/test/chunking-form/samples/emit-entry-worker/main.js index 2d30d9148c0..4c03186f74e 100644 --- a/test/chunking-form/samples/emit-entry-worker/main.js +++ b/test/chunking-form/samples/emit-entry-worker/main.js @@ -1,7 +1,9 @@ import { getWorkerMessage } from 'merged'; +import { shared } from './shared'; -getWorkerMessage().then(message => document.write(`

1: ${message.data}

`)); +document.body.innerHTML += `

main: ${shared}

`; +getWorkerMessage().then(message => (document.body.innerHTML += `

1: ${message.data}

`)); import('nested') .then(result => result.getWorkerMessage()) - .then(message => document.write(`

2: ${message.data}

`)); + .then(message => (document.body.innerHTML += `

2: ${message.data}

`)); diff --git a/test/chunking-form/samples/emit-entry-worker/shared.js b/test/chunking-form/samples/emit-entry-worker/shared.js new file mode 100644 index 00000000000..cd35843de7a --- /dev/null +++ b/test/chunking-form/samples/emit-entry-worker/shared.js @@ -0,0 +1 @@ +export const shared = 'shared'; diff --git a/test/chunking-form/samples/emit-entry-worker/worker.js b/test/chunking-form/samples/emit-entry-worker/worker.js index 89a9039df0d..824aa26d2e0 100644 --- a/test/chunking-form/samples/emit-entry-worker/worker.js +++ b/test/chunking-form/samples/emit-entry-worker/worker.js @@ -1 +1,3 @@ -postMessage('from worker'); +import {shared} from './shared'; + +postMessage(`from worker: ${shared}`); From 1b810a3185841c2eec809cf7a5035ffc382c5d81 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Fri, 19 Apr 2019 08:40:25 +0200 Subject: [PATCH 35/60] Revert to "wrong" resolveId type as this will probably be fixed in a separate PR --- docs/05-plugins.md | 2 +- src/rollup/types.d.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/05-plugins.md b/docs/05-plugins.md index acc95351ea2..0c966498a48 100644 --- a/docs/05-plugins.md +++ b/docs/05-plugins.md @@ -347,7 +347,7 @@ or converted into an Array via `Array.from(this.moduleIds)`. Use Rollup's internal acorn instance to parse code to an AST. -#### `this.resolveId(importee: string, importer: string) => Promise` +#### `this.resolveId(importee: string, importer: string) => Promise` Resolve imports to module ids (i.e. file names). Uses the same hooks as Rollup itself. diff --git a/src/rollup/types.d.ts b/src/rollup/types.d.ts index 002c8bc50c3..2e3156befc1 100644 --- a/src/rollup/types.d.ts +++ b/src/rollup/types.d.ts @@ -124,7 +124,7 @@ export interface PluginContext extends MinimalPluginContext { isExternal: IsExternal; moduleIds: IterableIterator; parse: (input: string, options: any) => ESTree.Program; - resolveId: (id: string, parent: string) => Promise; + resolveId: (id: string, parent: string) => Promise; setAssetSource: (assetMetaId: string, source: string | Buffer) => void; warn: (warning: RollupWarning | string, pos?: { column: number; line: number }) => void; /** @deprecated */ From 70197b48e6ff73b8eff36451e94dd58da65db3c3 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Sat, 20 Apr 2019 08:27:24 +0200 Subject: [PATCH 36/60] Suppress .js extensions for AMD, fix issue with empty dynamically imported chunks --- src/Chunk.ts | 16 ++++++++++------ src/Graph.ts | 6 ++---- src/ast/nodes/Import.ts | 5 ++++- src/finalisers/amd.ts | 15 ++++++++++++++- test/chunking-form/index.js | 14 +++++++++++++- .../aliasing-extensions/_expected/amd/main1.js | 4 ++-- .../asset-emission/_expected/amd/main.js | 4 ++-- .../_expected/amd/nested/chunk2.js | 2 +- .../basic-chunking/_expected/amd/main1.js | 2 +- .../basic-chunking/_expected/amd/main2.js | 2 +- .../_expected/amd/generated-chunk2.js | 2 +- .../_expected/amd/main1.js | 2 +- .../_expected/amd/main2.js | 2 +- .../_expected/amd/main3.js | 2 +- .../_expected/amd/main4.js | 2 +- .../_expected/amd/generated-chunk3.js | 2 +- .../_expected/amd/main1.js | 2 +- .../_expected/amd/main2.js | 2 +- .../_expected/amd/main3.js | 2 +- .../_expected/amd/main4.js | 2 +- .../_expected/amd/main1.js | 2 +- .../_expected/amd/main2.js | 2 +- .../_expected/amd/main1.js | 2 +- .../_expected/amd/main2.js | 2 +- .../_expected/amd/main1.js | 2 +- .../_expected/amd/main2.js | 2 +- .../chunk-live-bindings/_expected/amd/main1.js | 2 +- .../chunk-live-bindings/_expected/amd/main2.js | 2 +- .../_expected/amd/main1.js | 2 +- .../_expected/amd/main2.js | 2 +- .../_expected/amd/custom/entryC.js | 2 +- .../chunk-naming/_expected/amd/entryA.js | 2 +- .../chunk-naming/_expected/amd/entryB.js | 2 +- .../chunking-compact/_expected/amd/main1.js | 2 +- .../chunking-compact/_expected/amd/main2.js | 2 +- .../chunking-externals/_expected/amd/main1.js | 2 +- .../chunking-externals/_expected/amd/main2.js | 2 +- .../chunking-reexport/_expected/amd/main1.js | 2 +- .../chunking-reexport/_expected/amd/main2.js | 2 +- .../_expected/amd/main1.js | 2 +- .../_expected/amd/main2.js | 2 +- .../_expected/amd/main1.js | 2 +- .../_expected/amd/main2.js | 2 +- .../_expected/amd/main1.js | 2 +- .../_expected/amd/main2.js | 2 +- .../configure-asset-url/_expected/amd/main.js | 2 +- .../configure-file-url/_expected/amd/main.js | 2 +- .../deconflict-globals/_expected/amd/main1.js | 2 +- .../deconflict-globals/_expected/amd/main2.js | 2 +- .../_expected/amd/main1.js | 2 +- .../_expected/amd/main2.js | 2 +- .../_expected/amd/main1.js | 2 +- .../_expected/amd/main2.js | 2 +- .../_expected/amd/main1.js | 2 +- .../_expected/amd/main2.js | 2 +- .../_expected/amd/generated-chunk2.js | 2 +- .../_expected/amd/main.js | 2 +- .../_expected/amd/generated-chunk2.js | 2 +- .../_expected/amd/main.js | 4 ++-- .../_expected/amd/generated-chunk2.js | 2 +- .../_expected/amd/main1.js | 2 +- .../_expected/amd/main2.js | 2 +- .../_expected/amd/main1.js | 6 +++--- .../_expected/amd/main2.js | 2 +- .../_expected/amd/main.js | 2 +- .../_expected/amd/generated-chunk2.js | 2 +- .../_expected/amd/main.js | 2 +- .../_expected/amd/main2.js | 2 +- .../_expected/amd/main.js | 2 +- .../samples/dynamic-import/_config.js | 14 ++++++++++++++ .../_expected/amd/chunks/chunk.js | 7 +++++++ .../_expected/amd/chunks/chunk2.js | 7 +++++++ .../dynamic-import/_expected/amd/main.js | 13 +++++++++++++ .../_expected/cjs/chunks/chunk.js | 5 +++++ .../_expected/cjs/chunks/chunk2.js | 7 +++++++ .../dynamic-import/_expected/cjs/main.js | 13 +++++++++++++ .../_expected/es/chunks/chunk.js | 3 +++ .../_expected/es/chunks/chunk2.js | 1 + .../dynamic-import/_expected/es/main.js | 9 +++++++++ .../_expected/system/chunks/chunk.js | 10 ++++++++++ .../_expected/system/chunks/chunk2.js | 13 +++++++++++++ .../dynamic-import/_expected/system/main.js | 18 ++++++++++++++++++ .../samples/dynamic-import/main.js | 6 ++++++ .../samples/dynamic-import/other.js | 1 + .../samples/dynamic-import/shared.js | 1 + .../_expected/amd/buildStart.js | 2 +- .../_expected/amd/main.js | 2 +- .../_expected/amd/buildStart.js | 2 +- .../emit-entry-chunk/_expected/amd/main.js | 2 +- .../_expected/amd/first-main.js | 2 +- .../_expected/amd/second-main.js | 2 +- .../emit-entry-worker/_expected/amd/main.js | 4 ++-- .../emit-entry-worker/_expected/amd/worker.js | 2 +- .../_expected/amd/main1.js | 2 +- .../_expected/amd/generated-m1.js | 2 +- .../_expected/amd/m1.js | 2 +- .../_expected/amd/main.js | 2 +- .../_expected/amd/main1alias.js | 2 +- .../_expected/amd/main2alias.js | 2 +- .../entrypoint-facade/_expected/amd/main1.js | 2 +- .../entrypoint-facade/_expected/amd/main2.js | 2 +- .../_expected/amd/main.js | 2 +- .../_expected/amd/entry-main1-e7c7d1b5-amd.js | 2 +- .../_expected/amd/entry-main2-f9a2200a-amd.js | 2 +- .../grouping-multiple/_expected/amd/main1.js | 2 +- .../grouping-multiple/_expected/amd/main2.js | 2 +- .../grouping-multiple/_expected/amd/main3.js | 2 +- .../grouping-size/_expected/amd/main1.js | 2 +- .../grouping-size/_expected/amd/main2.js | 2 +- .../grouping-size/_expected/amd/main3.js | 2 +- .../import-meta-url/_expected/amd/main.js | 4 ++-- .../_expected/amd/nested/chunk2.js | 2 +- .../_expected/amd/head.js | 2 +- .../_expected/amd/main1.js | 2 +- .../_expected/amd/main2.js | 2 +- .../_expected/amd/main.js | 2 +- .../_expected/amd/main.js | 2 +- .../_expected/amd/generated-manual-middle.js | 2 +- .../_expected/amd/generated-manual-outer.js | 2 +- .../_expected/amd/main.js | 2 +- .../_expected/amd/generated-chunk.js | 2 +- .../_expected/amd/generated-chunk2.js | 2 +- .../_expected/amd/main.js | 4 ++-- .../_expected/amd/generated-chunk.js | 2 +- .../_expected/amd/main.js | 4 ++-- .../_expected/amd/main.js | 2 +- .../manual-chunks-nested/_expected/amd/main.js | 2 +- .../_expected/amd/generated-deps2and3.js | 2 +- .../manual-chunks/_expected/amd/main.js | 2 +- .../_expected/amd/main.js | 2 +- .../_expected/amd/main.js | 2 +- .../missing-export/_expected/amd/main.js | 2 +- .../multi-chunking/_expected/amd/main1.js | 2 +- .../multi-chunking/_expected/amd/main2.js | 2 +- .../multi-chunking/_expected/amd/main3.js | 2 +- .../samples/multiple-entry-points/_config.js | 10 ++++++++++ .../_expected/amd/chunks/chunk.js | 7 +++++++ .../_expected/amd/main.js | 5 +++++ .../_expected/amd/other.js | 9 +++++++++ .../_expected/cjs/chunks/chunk.js | 5 +++++ .../_expected/cjs/main.js | 5 +++++ .../_expected/cjs/other.js | 9 +++++++++ .../_expected/es/chunks/chunk.js | 3 +++ .../multiple-entry-points/_expected/es/main.js | 3 +++ .../_expected/es/other.js | 1 + .../_expected/system/chunks/chunk.js | 10 ++++++++++ .../_expected/system/main.js | 14 ++++++++++++++ .../_expected/system/other.js | 13 +++++++++++++ .../samples/multiple-entry-points/main.js | 3 +++ .../samples/multiple-entry-points/other.js | 1 + .../samples/multiple-entry-points/shared.js | 1 + .../_expected/amd/main2.js | 2 +- .../_expected/amd/main1.js | 2 +- .../_expected/amd/main2.js | 2 +- .../_expected/amd/generated-chunk2.js | 2 +- .../_expected/amd/main1.js | 2 +- .../_expected/amd/main2.js | 2 +- .../_expected/amd/main3.js | 2 +- .../_expected/amd/generated-index.js | 2 +- .../namespace-reexports/_expected/amd/index.js | 2 +- .../namespace-reexports/_expected/amd/main.js | 2 +- .../_expected/amd/main-a.js | 2 +- .../_expected/amd/main-b.js | 2 +- .../_expected/amd/generated-chunk2.js | 2 +- .../_expected/amd/generated-chunk3.js | 2 +- .../namespace-tracing/_expected/amd/main-a.js | 2 +- .../namespace-tracing/_expected/amd/main-b.js | 2 +- .../namespace-tracing/_expected/amd/main-c.js | 2 +- .../_expected/amd/generated-chunk.js | 2 +- .../_expected/amd/generated-chunk2.js | 2 +- .../_expected/amd/generated-chunk3.js | 2 +- .../_expected/amd/generated-chunk4.js | 2 +- .../_expected/amd/main.js | 2 +- .../_expected/amd/_virtual/other.js | 2 +- .../_expected/amd/commonjs.js | 2 +- .../_expected/amd/main.js | 2 +- .../_expected/amd/main.js | 2 +- .../_expected/amd/m1.js | 2 +- .../_expected/amd/main.js | 2 +- .../_expected/amd/main.js | 2 +- .../_expected/amd/main1.js | 2 +- .../_expected/amd/main2.js | 2 +- .../_expected/amd/main.js | 2 +- .../_expected/amd/lib/main.js | 2 +- .../_expected/amd/deps/dep2.js | 2 +- .../_expected/amd/deps/dep3.js | 2 +- .../preserve-modules/_expected/amd/main1.js | 2 +- .../preserve-modules/_expected/amd/main2.js | 2 +- .../reexport-shortpaths/_expected/amd/main1.js | 2 +- .../reexport-shortpaths/_expected/amd/main2.js | 2 +- .../reexport-shortpaths/_expected/amd/main3.js | 2 +- .../_expected/amd/generated-chunk2.js | 2 +- .../_expected/amd/main.js | 4 ++-- .../_expected/amd/main1.js | 2 +- .../_expected/amd/main2.js | 2 +- .../_expected/amd.js | 4 ++-- .../_expected/cjs.js | 2 +- .../_expected/es.js | 2 +- 198 files changed, 442 insertions(+), 185 deletions(-) create mode 100644 test/chunking-form/samples/dynamic-import/_config.js create mode 100644 test/chunking-form/samples/dynamic-import/_expected/amd/chunks/chunk.js create mode 100644 test/chunking-form/samples/dynamic-import/_expected/amd/chunks/chunk2.js create mode 100644 test/chunking-form/samples/dynamic-import/_expected/amd/main.js create mode 100644 test/chunking-form/samples/dynamic-import/_expected/cjs/chunks/chunk.js create mode 100644 test/chunking-form/samples/dynamic-import/_expected/cjs/chunks/chunk2.js create mode 100644 test/chunking-form/samples/dynamic-import/_expected/cjs/main.js create mode 100644 test/chunking-form/samples/dynamic-import/_expected/es/chunks/chunk.js create mode 100644 test/chunking-form/samples/dynamic-import/_expected/es/chunks/chunk2.js create mode 100644 test/chunking-form/samples/dynamic-import/_expected/es/main.js create mode 100644 test/chunking-form/samples/dynamic-import/_expected/system/chunks/chunk.js create mode 100644 test/chunking-form/samples/dynamic-import/_expected/system/chunks/chunk2.js create mode 100644 test/chunking-form/samples/dynamic-import/_expected/system/main.js create mode 100644 test/chunking-form/samples/dynamic-import/main.js create mode 100644 test/chunking-form/samples/dynamic-import/other.js create mode 100644 test/chunking-form/samples/dynamic-import/shared.js create mode 100644 test/chunking-form/samples/multiple-entry-points/_config.js create mode 100644 test/chunking-form/samples/multiple-entry-points/_expected/amd/chunks/chunk.js create mode 100644 test/chunking-form/samples/multiple-entry-points/_expected/amd/main.js create mode 100644 test/chunking-form/samples/multiple-entry-points/_expected/amd/other.js create mode 100644 test/chunking-form/samples/multiple-entry-points/_expected/cjs/chunks/chunk.js create mode 100644 test/chunking-form/samples/multiple-entry-points/_expected/cjs/main.js create mode 100644 test/chunking-form/samples/multiple-entry-points/_expected/cjs/other.js create mode 100644 test/chunking-form/samples/multiple-entry-points/_expected/es/chunks/chunk.js create mode 100644 test/chunking-form/samples/multiple-entry-points/_expected/es/main.js create mode 100644 test/chunking-form/samples/multiple-entry-points/_expected/es/other.js create mode 100644 test/chunking-form/samples/multiple-entry-points/_expected/system/chunks/chunk.js create mode 100644 test/chunking-form/samples/multiple-entry-points/_expected/system/main.js create mode 100644 test/chunking-form/samples/multiple-entry-points/_expected/system/other.js create mode 100644 test/chunking-form/samples/multiple-entry-points/main.js create mode 100644 test/chunking-form/samples/multiple-entry-points/other.js create mode 100644 test/chunking-form/samples/multiple-entry-points/shared.js diff --git a/src/Chunk.ts b/src/Chunk.ts index a930d424014..1104388307c 100644 --- a/src/Chunk.ts +++ b/src/Chunk.ts @@ -107,6 +107,10 @@ function getGlobalName( } } +export function isChunkRendered(chunk: Chunk): boolean { + return !chunk.isEmpty || chunk.entryModules.length > 0 || chunk.manualChunkAlias !== null; +} + export default class Chunk { entryModules: Module[] = []; execIndex: number; @@ -597,7 +601,7 @@ export default class Chunk { renderedDependency.id = relPath; } - this.finaliseDynamicImports(); + this.finaliseDynamicImports(options.format); const needsAmdModule = this.finaliseImportMetas(options); const hasExports = @@ -782,23 +786,23 @@ export default class Chunk { return hash.digest('hex').substr(0, 8); } - private finaliseDynamicImports() { + private finaliseDynamicImports(format: string) { for (let i = 0; i < this.orderedModules.length; i++) { const module = this.orderedModules[i]; const code = this.renderedModuleSources[i]; for (const { node, resolution } of module.dynamicImports) { if (!resolution) continue; if (resolution instanceof Module) { - if (!resolution.chunk.isEmpty && resolution.chunk !== this) { + if (resolution.chunk !== this && isChunkRendered(resolution.chunk)) { const resolutionChunk = resolution.facadeChunk || resolution.chunk; let relPath = normalize(relative(dirname(this.id), resolutionChunk.id)); if (!relPath.startsWith('../')) relPath = './' + relPath; - node.renderFinalResolution(code, `'${relPath}'`); + node.renderFinalResolution(code, `'${relPath}'`, format); } } else if (resolution instanceof ExternalModule) { - node.renderFinalResolution(code, `'${resolution.id}'`); + node.renderFinalResolution(code, `'${resolution.id}'`, format); } else { - node.renderFinalResolution(code, resolution); + node.renderFinalResolution(code, resolution, format); } } } diff --git a/src/Graph.ts b/src/Graph.ts index e1b3f516f9e..054f00e1b6a 100644 --- a/src/Graph.ts +++ b/src/Graph.ts @@ -5,7 +5,7 @@ import injectImportMeta from 'acorn-import-meta'; import * as ESTree from 'estree'; import GlobalScope from './ast/scopes/GlobalScope'; import { EntityPathTracker } from './ast/utils/EntityPathTracker'; -import Chunk from './Chunk'; +import Chunk, { isChunkRendered } from './Chunk'; import ExternalModule from './ExternalModule'; import Module, { defaultAcornOptions } from './Module'; import { ModuleLoader, UnresolvedModuleWithAlias } from './ModuleLoader'; @@ -308,9 +308,7 @@ export default class Graph { } // filter out empty dependencies - chunks = chunks.filter( - chunk => !chunk.isEmpty || chunk.entryModules.length > 0 || chunk.manualChunkAlias !== null - ); + chunks = chunks.filter(isChunkRendered); // then go over and ensure all entry chunks export their variables for (const chunk of chunks) { diff --git a/src/ast/nodes/Import.ts b/src/ast/nodes/Import.ts index cc562b7ea6f..501010507d7 100644 --- a/src/ast/nodes/Import.ts +++ b/src/ast/nodes/Import.ts @@ -91,8 +91,11 @@ export default class Import extends NodeBase { } } - renderFinalResolution(code: MagicString, resolution: string) { + renderFinalResolution(code: MagicString, resolution: string, format: string) { if (this.included) { + if (format === 'amd' && resolution.startsWith("'.") && resolution.endsWith(".js'")) { + resolution = resolution.slice(0, -4) + "'"; + } code.overwrite(this.parent.arguments[0].start, this.parent.arguments[0].end, resolution); } } diff --git a/src/finalisers/amd.ts b/src/finalisers/amd.ts index 963bc462b59..fb51b193ec9 100644 --- a/src/finalisers/amd.ts +++ b/src/finalisers/amd.ts @@ -6,6 +6,19 @@ import getExportBlock from './shared/getExportBlock'; import getInteropBlock from './shared/getInteropBlock'; import warnOnBuiltins from './shared/warnOnBuiltins'; +// TODO Lukas consider improved AMD relative imports: +// https://requirejs.org/docs/api.html#modulenotes-urls + +// AMD resolution will only respect the AMD baseUrl if the .js extension is omitted. +// The assumption is that this makes sense for all relative ids: +// https://requirejs.org/docs/api.html#jsfiles +function removeExtensionFromRelativeAmdId(id: string) { + if (id[0] === '.' && id.endsWith('.js')) { + return id.slice(0, -3); + } + return id; +} + export default function amd( magicString: MagicStringBundle, { @@ -26,7 +39,7 @@ export default function amd( ) { warnOnBuiltins(warn, dependencies); - const deps = dependencies.map(m => `'${m.id}'`); + const deps = dependencies.map(m => `'${removeExtensionFromRelativeAmdId(m.id)}'`); const args = dependencies.map(m => m.name); const n = options.compact ? '' : '\n'; const _ = options.compact ? '' : ' '; diff --git a/test/chunking-form/index.js b/test/chunking-form/index.js index 25bf35f3608..3858d7e26e3 100644 --- a/test/chunking-form/index.js +++ b/test/chunking-form/index.js @@ -49,8 +49,20 @@ runTestSuiteWithSamples('chunking form', path.resolve(__dirname, 'samples'), (di ); }); -function generateAndTestBundle(bundle, outputOptions, expectedDir) { +function generateAndTestBundle(bundle, outputOptions, expectedDir, config) { return bundle .write(outputOptions) + .then(() => { + if (outputOptions.format === 'amd' && config.runAmd) { + return new Promise(resolve => { + global.assert = require('assert'); + const requirejs = require('requirejs'); + requirejs.config({ baseUrl: outputOptions.dir }); + requirejs(['main'], main => { + Promise.resolve(config.runAmd.exports && config.runAmd.exports(main)).then(resolve); + }); + }); + } + }) .then(() => assertDirectoriesAreEqual(outputOptions.dir, expectedDir)); } diff --git a/test/chunking-form/samples/aliasing-extensions/_expected/amd/main1.js b/test/chunking-form/samples/aliasing-extensions/_expected/amd/main1.js index 97a0f22a858..6330bb0df77 100644 --- a/test/chunking-form/samples/aliasing-extensions/_expected/amd/main1.js +++ b/test/chunking-form/samples/aliasing-extensions/_expected/amd/main1.js @@ -1,7 +1,7 @@ define(['require'], function (require) { 'use strict'; console.log('main1'); - new Promise(function (resolve, reject) { require(['./generated-chunk.js'], resolve, reject) }); - new Promise(function (resolve, reject) { require(['./generated-chunk2.js'], resolve, reject) }); + new Promise(function (resolve, reject) { require(['./generated-chunk'], resolve, reject) }); + new Promise(function (resolve, reject) { require(['./generated-chunk2'], resolve, reject) }); }); diff --git a/test/chunking-form/samples/asset-emission/_expected/amd/main.js b/test/chunking-form/samples/asset-emission/_expected/amd/main.js index 88a74ef7790..ecd1444b38d 100644 --- a/test/chunking-form/samples/asset-emission/_expected/amd/main.js +++ b/test/chunking-form/samples/asset-emission/_expected/amd/main.js @@ -1,8 +1,8 @@ -define(['module', 'require', './nested/chunk.js'], function (module, require, __chunk_1) { 'use strict'; +define(['module', 'require', './nested/chunk'], function (module, require, __chunk_1) { 'use strict'; var logo = new URL(module.uri + '/../assets/logo1-25253976.svg', document.baseURI).href; __chunk_1.showImage(logo); - new Promise(function (resolve, reject) { require(['./nested/chunk2.js'], resolve, reject) }); + new Promise(function (resolve, reject) { require(['./nested/chunk2'], resolve, reject) }); }); diff --git a/test/chunking-form/samples/asset-emission/_expected/amd/nested/chunk2.js b/test/chunking-form/samples/asset-emission/_expected/amd/nested/chunk2.js index f4f035d353e..c3c0a8c5af7 100644 --- a/test/chunking-form/samples/asset-emission/_expected/amd/nested/chunk2.js +++ b/test/chunking-form/samples/asset-emission/_expected/amd/nested/chunk2.js @@ -1,4 +1,4 @@ -define(['module', './chunk.js'], function (module, __chunk_1) { 'use strict'; +define(['module', './chunk'], function (module, __chunk_1) { 'use strict'; var logo = new URL(module.uri + '/../../assets/logo2-25253976.svg', document.baseURI).href; diff --git a/test/chunking-form/samples/basic-chunking/_expected/amd/main1.js b/test/chunking-form/samples/basic-chunking/_expected/amd/main1.js index c28862eef55..ac14c9b6c66 100644 --- a/test/chunking-form/samples/basic-chunking/_expected/amd/main1.js +++ b/test/chunking-form/samples/basic-chunking/_expected/amd/main1.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; +define(['./generated-chunk'], function (__chunk_1) { 'use strict'; function fn () { console.log('dep1 fn'); diff --git a/test/chunking-form/samples/basic-chunking/_expected/amd/main2.js b/test/chunking-form/samples/basic-chunking/_expected/amd/main2.js index efd7525d8f1..111b5a4ace0 100644 --- a/test/chunking-form/samples/basic-chunking/_expected/amd/main2.js +++ b/test/chunking-form/samples/basic-chunking/_expected/amd/main2.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; +define(['./generated-chunk'], function (__chunk_1) { 'use strict'; function fn () { console.log('lib1 fn'); diff --git a/test/chunking-form/samples/chunk-deshadowing-reassignment/_expected/amd/generated-chunk2.js b/test/chunking-form/samples/chunk-deshadowing-reassignment/_expected/amd/generated-chunk2.js index 26b4d40d458..81990cfcc0b 100644 --- a/test/chunking-form/samples/chunk-deshadowing-reassignment/_expected/amd/generated-chunk2.js +++ b/test/chunking-form/samples/chunk-deshadowing-reassignment/_expected/amd/generated-chunk2.js @@ -1,4 +1,4 @@ -define(['exports', './generated-chunk.js', './generated-chunk3.js'], function (exports, __chunk_1, __chunk_3) { 'use strict'; +define(['exports', './generated-chunk', './generated-chunk3'], function (exports, __chunk_1, __chunk_3) { 'use strict'; var x = __chunk_1.x + 1; diff --git a/test/chunking-form/samples/chunk-deshadowing-reassignment/_expected/amd/main1.js b/test/chunking-form/samples/chunk-deshadowing-reassignment/_expected/amd/main1.js index 433f5b9e4c5..ebe790c766a 100644 --- a/test/chunking-form/samples/chunk-deshadowing-reassignment/_expected/amd/main1.js +++ b/test/chunking-form/samples/chunk-deshadowing-reassignment/_expected/amd/main1.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js', './generated-chunk2.js', './generated-chunk3.js'], function (__chunk_1, __chunk_2, __chunk_3) { 'use strict'; +define(['./generated-chunk', './generated-chunk2', './generated-chunk3'], function (__chunk_1, __chunk_2, __chunk_3) { 'use strict'; console.log(__chunk_2.x + __chunk_2.y); diff --git a/test/chunking-form/samples/chunk-deshadowing-reassignment/_expected/amd/main2.js b/test/chunking-form/samples/chunk-deshadowing-reassignment/_expected/amd/main2.js index e672a31543d..6924458be25 100644 --- a/test/chunking-form/samples/chunk-deshadowing-reassignment/_expected/amd/main2.js +++ b/test/chunking-form/samples/chunk-deshadowing-reassignment/_expected/amd/main2.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js', './generated-chunk2.js', './generated-chunk3.js'], function (__chunk_1, __chunk_2, __chunk_3) { 'use strict'; +define(['./generated-chunk', './generated-chunk2', './generated-chunk3'], function (__chunk_1, __chunk_2, __chunk_3) { 'use strict'; diff --git a/test/chunking-form/samples/chunk-deshadowing-reassignment/_expected/amd/main3.js b/test/chunking-form/samples/chunk-deshadowing-reassignment/_expected/amd/main3.js index 7829aea9079..80869868e48 100644 --- a/test/chunking-form/samples/chunk-deshadowing-reassignment/_expected/amd/main3.js +++ b/test/chunking-form/samples/chunk-deshadowing-reassignment/_expected/amd/main3.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; +define(['./generated-chunk'], function (__chunk_1) { 'use strict'; diff --git a/test/chunking-form/samples/chunk-deshadowing-reassignment/_expected/amd/main4.js b/test/chunking-form/samples/chunk-deshadowing-reassignment/_expected/amd/main4.js index 8cfcfb33c4a..57661f926d5 100644 --- a/test/chunking-form/samples/chunk-deshadowing-reassignment/_expected/amd/main4.js +++ b/test/chunking-form/samples/chunk-deshadowing-reassignment/_expected/amd/main4.js @@ -1,4 +1,4 @@ -define(['./generated-chunk3.js'], function (__chunk_3) { 'use strict'; +define(['./generated-chunk3'], function (__chunk_3) { 'use strict'; diff --git a/test/chunking-form/samples/chunk-execution-order/_expected/amd/generated-chunk3.js b/test/chunking-form/samples/chunk-execution-order/_expected/amd/generated-chunk3.js index 1cb52024d4c..63b1b2fef74 100644 --- a/test/chunking-form/samples/chunk-execution-order/_expected/amd/generated-chunk3.js +++ b/test/chunking-form/samples/chunk-execution-order/_expected/amd/generated-chunk3.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js', './generated-chunk2.js'], function (__chunk_1, __chunk_2) { 'use strict'; +define(['./generated-chunk', './generated-chunk2'], function (__chunk_1, __chunk_2) { 'use strict'; console.log('11'); diff --git a/test/chunking-form/samples/chunk-execution-order/_expected/amd/main1.js b/test/chunking-form/samples/chunk-execution-order/_expected/amd/main1.js index ccdadcbc5a0..84e0fbc0088 100644 --- a/test/chunking-form/samples/chunk-execution-order/_expected/amd/main1.js +++ b/test/chunking-form/samples/chunk-execution-order/_expected/amd/main1.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js', './generated-chunk2.js', './generated-chunk3.js'], function (__chunk_1, __chunk_2, __chunk_3) { 'use strict'; +define(['./generated-chunk', './generated-chunk2', './generated-chunk3'], function (__chunk_1, __chunk_2, __chunk_3) { 'use strict'; console.log('1'); diff --git a/test/chunking-form/samples/chunk-execution-order/_expected/amd/main2.js b/test/chunking-form/samples/chunk-execution-order/_expected/amd/main2.js index e672a31543d..6924458be25 100644 --- a/test/chunking-form/samples/chunk-execution-order/_expected/amd/main2.js +++ b/test/chunking-form/samples/chunk-execution-order/_expected/amd/main2.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js', './generated-chunk2.js', './generated-chunk3.js'], function (__chunk_1, __chunk_2, __chunk_3) { 'use strict'; +define(['./generated-chunk', './generated-chunk2', './generated-chunk3'], function (__chunk_1, __chunk_2, __chunk_3) { 'use strict'; diff --git a/test/chunking-form/samples/chunk-execution-order/_expected/amd/main3.js b/test/chunking-form/samples/chunk-execution-order/_expected/amd/main3.js index 7829aea9079..80869868e48 100644 --- a/test/chunking-form/samples/chunk-execution-order/_expected/amd/main3.js +++ b/test/chunking-form/samples/chunk-execution-order/_expected/amd/main3.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; +define(['./generated-chunk'], function (__chunk_1) { 'use strict'; diff --git a/test/chunking-form/samples/chunk-execution-order/_expected/amd/main4.js b/test/chunking-form/samples/chunk-execution-order/_expected/amd/main4.js index c2fd988e2c2..01a1c62db72 100644 --- a/test/chunking-form/samples/chunk-execution-order/_expected/amd/main4.js +++ b/test/chunking-form/samples/chunk-execution-order/_expected/amd/main4.js @@ -1,4 +1,4 @@ -define(['./generated-chunk2.js'], function (__chunk_2) { 'use strict'; +define(['./generated-chunk2'], function (__chunk_2) { 'use strict'; diff --git a/test/chunking-form/samples/chunk-export-deshadowing/_expected/amd/main1.js b/test/chunking-form/samples/chunk-export-deshadowing/_expected/amd/main1.js index 1030e98d0cc..166cf5b87f0 100644 --- a/test/chunking-form/samples/chunk-export-deshadowing/_expected/amd/main1.js +++ b/test/chunking-form/samples/chunk-export-deshadowing/_expected/amd/main1.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; +define(['./generated-chunk'], function (__chunk_1) { 'use strict'; class Main1 { constructor () { diff --git a/test/chunking-form/samples/chunk-export-deshadowing/_expected/amd/main2.js b/test/chunking-form/samples/chunk-export-deshadowing/_expected/amd/main2.js index 879ad390277..2755a1f1093 100644 --- a/test/chunking-form/samples/chunk-export-deshadowing/_expected/amd/main2.js +++ b/test/chunking-form/samples/chunk-export-deshadowing/_expected/amd/main2.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; +define(['./generated-chunk'], function (__chunk_1) { 'use strict'; class Main2 { constructor () { diff --git a/test/chunking-form/samples/chunk-export-renaming/_expected/amd/main1.js b/test/chunking-form/samples/chunk-export-renaming/_expected/amd/main1.js index 042aa5e2ef2..b2e05fcc77c 100644 --- a/test/chunking-form/samples/chunk-export-renaming/_expected/amd/main1.js +++ b/test/chunking-form/samples/chunk-export-renaming/_expected/amd/main1.js @@ -1,4 +1,4 @@ -define(['exports', './generated-chunk.js'], function (exports, __chunk_1) { 'use strict'; +define(['exports', './generated-chunk'], function (exports, __chunk_1) { 'use strict'; diff --git a/test/chunking-form/samples/chunk-export-renaming/_expected/amd/main2.js b/test/chunking-form/samples/chunk-export-renaming/_expected/amd/main2.js index 296df6af6d0..5817de20203 100644 --- a/test/chunking-form/samples/chunk-export-renaming/_expected/amd/main2.js +++ b/test/chunking-form/samples/chunk-export-renaming/_expected/amd/main2.js @@ -1,4 +1,4 @@ -define(['exports', './generated-chunk.js'], function (exports, __chunk_1) { 'use strict'; +define(['exports', './generated-chunk'], function (exports, __chunk_1) { 'use strict'; class Two { test() { diff --git a/test/chunking-form/samples/chunk-import-deshadowing/_expected/amd/main1.js b/test/chunking-form/samples/chunk-import-deshadowing/_expected/amd/main1.js index 77482994344..aa788e1c4dc 100644 --- a/test/chunking-form/samples/chunk-import-deshadowing/_expected/amd/main1.js +++ b/test/chunking-form/samples/chunk-import-deshadowing/_expected/amd/main1.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; +define(['./generated-chunk'], function (__chunk_1) { 'use strict'; function fn () { var emptyFunction = __chunk_1.emptyFunction; diff --git a/test/chunking-form/samples/chunk-import-deshadowing/_expected/amd/main2.js b/test/chunking-form/samples/chunk-import-deshadowing/_expected/amd/main2.js index 7829aea9079..80869868e48 100644 --- a/test/chunking-form/samples/chunk-import-deshadowing/_expected/amd/main2.js +++ b/test/chunking-form/samples/chunk-import-deshadowing/_expected/amd/main2.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; +define(['./generated-chunk'], function (__chunk_1) { 'use strict'; diff --git a/test/chunking-form/samples/chunk-live-bindings/_expected/amd/main1.js b/test/chunking-form/samples/chunk-live-bindings/_expected/amd/main1.js index 0918612bfae..d618cb1c2d6 100644 --- a/test/chunking-form/samples/chunk-live-bindings/_expected/amd/main1.js +++ b/test/chunking-form/samples/chunk-live-bindings/_expected/amd/main1.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; +define(['./generated-chunk'], function (__chunk_1) { 'use strict'; class Main1 { constructor () { diff --git a/test/chunking-form/samples/chunk-live-bindings/_expected/amd/main2.js b/test/chunking-form/samples/chunk-live-bindings/_expected/amd/main2.js index 93a48a8dd14..c49699c2b2c 100644 --- a/test/chunking-form/samples/chunk-live-bindings/_expected/amd/main2.js +++ b/test/chunking-form/samples/chunk-live-bindings/_expected/amd/main2.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; +define(['./generated-chunk'], function (__chunk_1) { 'use strict'; class Main2 { constructor () { diff --git a/test/chunking-form/samples/chunk-namespace-boundary/_expected/amd/main1.js b/test/chunking-form/samples/chunk-namespace-boundary/_expected/amd/main1.js index 685de59a288..2167f01dcf8 100644 --- a/test/chunking-form/samples/chunk-namespace-boundary/_expected/amd/main1.js +++ b/test/chunking-form/samples/chunk-namespace-boundary/_expected/amd/main1.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; +define(['./generated-chunk'], function (__chunk_1) { 'use strict'; __chunk_1.commonjsGlobal.fn = d => d + 1; var cjs = __chunk_1.commonjsGlobal.fn; diff --git a/test/chunking-form/samples/chunk-namespace-boundary/_expected/amd/main2.js b/test/chunking-form/samples/chunk-namespace-boundary/_expected/amd/main2.js index bc56788609f..aaabc773106 100644 --- a/test/chunking-form/samples/chunk-namespace-boundary/_expected/amd/main2.js +++ b/test/chunking-form/samples/chunk-namespace-boundary/_expected/amd/main2.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; +define(['./generated-chunk'], function (__chunk_1) { 'use strict'; var main2 = __chunk_1.d.map(d => d + 2); diff --git a/test/chunking-form/samples/chunk-naming/_expected/amd/custom/entryC.js b/test/chunking-form/samples/chunk-naming/_expected/amd/custom/entryC.js index 820d0876029..0996f9cb03b 100644 --- a/test/chunking-form/samples/chunk-naming/_expected/amd/custom/entryC.js +++ b/test/chunking-form/samples/chunk-naming/_expected/amd/custom/entryC.js @@ -1,4 +1,4 @@ -define(['../chunks/chunk.js', '../chunks/chunk3.js'], function (__chunk_1, __chunk_3) { 'use strict'; +define(['../chunks/chunk', '../chunks/chunk3'], function (__chunk_1, __chunk_3) { 'use strict'; console.log(__chunk_1.num + __chunk_3.num); diff --git a/test/chunking-form/samples/chunk-naming/_expected/amd/entryA.js b/test/chunking-form/samples/chunk-naming/_expected/amd/entryA.js index 320b1c5e8ed..587db5114ca 100644 --- a/test/chunking-form/samples/chunk-naming/_expected/amd/entryA.js +++ b/test/chunking-form/samples/chunk-naming/_expected/amd/entryA.js @@ -1,4 +1,4 @@ -define(['./chunks/chunk.js', './chunks/chunk2.js'], function (__chunk_1, __chunk_2) { 'use strict'; +define(['./chunks/chunk', './chunks/chunk2'], function (__chunk_1, __chunk_2) { 'use strict'; console.log(__chunk_1.num + __chunk_2.num); diff --git a/test/chunking-form/samples/chunk-naming/_expected/amd/entryB.js b/test/chunking-form/samples/chunk-naming/_expected/amd/entryB.js index 8a4dcc5a765..66a2dc57923 100644 --- a/test/chunking-form/samples/chunk-naming/_expected/amd/entryB.js +++ b/test/chunking-form/samples/chunk-naming/_expected/amd/entryB.js @@ -1,4 +1,4 @@ -define(['./chunks/chunk2.js', './chunks/chunk3.js'], function (__chunk_2, __chunk_3) { 'use strict'; +define(['./chunks/chunk2', './chunks/chunk3'], function (__chunk_2, __chunk_3) { 'use strict'; console.log(__chunk_2.num + __chunk_3.num); diff --git a/test/chunking-form/samples/chunking-compact/_expected/amd/main1.js b/test/chunking-form/samples/chunking-compact/_expected/amd/main1.js index 56c322f18fb..c4aa8295a3d 100644 --- a/test/chunking-form/samples/chunking-compact/_expected/amd/main1.js +++ b/test/chunking-form/samples/chunking-compact/_expected/amd/main1.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'],function(__chunk_1){'use strict';function fn () { +define(['./generated-chunk'],function(__chunk_1){'use strict';function fn () { console.log('dep1 fn'); }class Main1 { constructor () { diff --git a/test/chunking-form/samples/chunking-compact/_expected/amd/main2.js b/test/chunking-form/samples/chunking-compact/_expected/amd/main2.js index 79d0d2e16b7..7ff5ce00cee 100644 --- a/test/chunking-form/samples/chunking-compact/_expected/amd/main2.js +++ b/test/chunking-form/samples/chunking-compact/_expected/amd/main2.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js','external'],function(__chunk_1,external){'use strict';function fn () { +define(['./generated-chunk','external'],function(__chunk_1,external){'use strict';function fn () { console.log('lib1 fn'); external.fn(); }function fn$1 () { diff --git a/test/chunking-form/samples/chunking-externals/_expected/amd/main1.js b/test/chunking-form/samples/chunking-externals/_expected/amd/main1.js index c28862eef55..ac14c9b6c66 100644 --- a/test/chunking-form/samples/chunking-externals/_expected/amd/main1.js +++ b/test/chunking-form/samples/chunking-externals/_expected/amd/main1.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; +define(['./generated-chunk'], function (__chunk_1) { 'use strict'; function fn () { console.log('dep1 fn'); diff --git a/test/chunking-form/samples/chunking-externals/_expected/amd/main2.js b/test/chunking-form/samples/chunking-externals/_expected/amd/main2.js index 3691e83b8f2..c6f58144aa8 100644 --- a/test/chunking-form/samples/chunking-externals/_expected/amd/main2.js +++ b/test/chunking-form/samples/chunking-externals/_expected/amd/main2.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js', 'external'], function (__chunk_1, external) { 'use strict'; +define(['./generated-chunk', 'external'], function (__chunk_1, external) { 'use strict'; function fn () { console.log('lib1 fn'); diff --git a/test/chunking-form/samples/chunking-reexport/_expected/amd/main1.js b/test/chunking-form/samples/chunking-reexport/_expected/amd/main1.js index 2aaaa7c33cb..46adba2f54f 100644 --- a/test/chunking-form/samples/chunking-reexport/_expected/amd/main1.js +++ b/test/chunking-form/samples/chunking-reexport/_expected/amd/main1.js @@ -1,4 +1,4 @@ -define(['exports', 'external', './generated-chunk.js'], function (exports, external, __chunk_1) { 'use strict'; +define(['exports', 'external', './generated-chunk'], function (exports, external, __chunk_1) { 'use strict'; diff --git a/test/chunking-form/samples/chunking-reexport/_expected/amd/main2.js b/test/chunking-form/samples/chunking-reexport/_expected/amd/main2.js index 2aaaa7c33cb..46adba2f54f 100644 --- a/test/chunking-form/samples/chunking-reexport/_expected/amd/main2.js +++ b/test/chunking-form/samples/chunking-reexport/_expected/amd/main2.js @@ -1,4 +1,4 @@ -define(['exports', 'external', './generated-chunk.js'], function (exports, external, __chunk_1) { 'use strict'; +define(['exports', 'external', './generated-chunk'], function (exports, external, __chunk_1) { 'use strict'; diff --git a/test/chunking-form/samples/chunking-source-maps/_expected/amd/main1.js b/test/chunking-form/samples/chunking-source-maps/_expected/amd/main1.js index 8628ce47de6..e69175e6288 100644 --- a/test/chunking-form/samples/chunking-source-maps/_expected/amd/main1.js +++ b/test/chunking-form/samples/chunking-source-maps/_expected/amd/main1.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; +define(['./generated-chunk'], function (__chunk_1) { 'use strict'; function fn () { console.log('dep1 fn'); diff --git a/test/chunking-form/samples/chunking-source-maps/_expected/amd/main2.js b/test/chunking-form/samples/chunking-source-maps/_expected/amd/main2.js index 8d5ee940efa..2a762c5f878 100644 --- a/test/chunking-form/samples/chunking-source-maps/_expected/amd/main2.js +++ b/test/chunking-form/samples/chunking-source-maps/_expected/amd/main2.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; +define(['./generated-chunk'], function (__chunk_1) { 'use strict'; function fn () { console.log('lib1 fn'); diff --git a/test/chunking-form/samples/chunking-star-external/_expected/amd/main1.js b/test/chunking-form/samples/chunking-star-external/_expected/amd/main1.js index 274e709b0fb..e695a654e92 100644 --- a/test/chunking-form/samples/chunking-star-external/_expected/amd/main1.js +++ b/test/chunking-form/samples/chunking-star-external/_expected/amd/main1.js @@ -1,4 +1,4 @@ -define(['exports', 'starexternal1', 'external1', 'starexternal2', 'external2', './generated-chunk.js'], function (exports, starexternal1, external1, starexternal2, external2, __chunk_1) { 'use strict'; +define(['exports', 'starexternal1', 'external1', 'starexternal2', 'external2', './generated-chunk'], function (exports, starexternal1, external1, starexternal2, external2, __chunk_1) { 'use strict'; var main = '1'; diff --git a/test/chunking-form/samples/chunking-star-external/_expected/amd/main2.js b/test/chunking-form/samples/chunking-star-external/_expected/amd/main2.js index 43b41d0322b..43214ab663d 100644 --- a/test/chunking-form/samples/chunking-star-external/_expected/amd/main2.js +++ b/test/chunking-form/samples/chunking-star-external/_expected/amd/main2.js @@ -1,4 +1,4 @@ -define(['exports', 'starexternal2', 'external2', './generated-chunk.js'], function (exports, starexternal2, external2, __chunk_1) { 'use strict'; +define(['exports', 'starexternal2', 'external2', './generated-chunk'], function (exports, starexternal2, external2, __chunk_1) { 'use strict'; var main = '2'; diff --git a/test/chunking-form/samples/circular-entry-points/_expected/amd/main1.js b/test/chunking-form/samples/circular-entry-points/_expected/amd/main1.js index 4ca2e731aca..85ab96efabc 100644 --- a/test/chunking-form/samples/circular-entry-points/_expected/amd/main1.js +++ b/test/chunking-form/samples/circular-entry-points/_expected/amd/main1.js @@ -1,4 +1,4 @@ -define(['exports', './main2.js'], function (exports, main2) { 'use strict'; +define(['exports', './main2'], function (exports, main2) { 'use strict'; class C { fn (num) { diff --git a/test/chunking-form/samples/circular-entry-points/_expected/amd/main2.js b/test/chunking-form/samples/circular-entry-points/_expected/amd/main2.js index 251e0f1f4f2..3eb8db12220 100644 --- a/test/chunking-form/samples/circular-entry-points/_expected/amd/main2.js +++ b/test/chunking-form/samples/circular-entry-points/_expected/amd/main2.js @@ -1,4 +1,4 @@ -define(['exports', './main1.js'], function (exports, main1) { 'use strict'; +define(['exports', './main1'], function (exports, main1) { 'use strict'; class C { fn (num) { diff --git a/test/chunking-form/samples/configure-asset-url/_expected/amd/main.js b/test/chunking-form/samples/configure-asset-url/_expected/amd/main.js index 3d245c68235..47bef05d750 100644 --- a/test/chunking-form/samples/configure-asset-url/_expected/amd/main.js +++ b/test/chunking-form/samples/configure-asset-url/_expected/amd/main.js @@ -4,6 +4,6 @@ define(['module', 'require'], function (module, require) { 'use strict'; var asset3 = new URL(module.uri + '/../assets/asset-unresolved-9548436d.txt', document.baseURI).href; - new Promise(function (resolve, reject) { require(['./nested/chunk.js'], resolve, reject) }).then(result => console.log(result, asset2, asset3)); + new Promise(function (resolve, reject) { require(['./nested/chunk'], resolve, reject) }).then(result => console.log(result, asset2, asset3)); }); diff --git a/test/chunking-form/samples/configure-file-url/_expected/amd/main.js b/test/chunking-form/samples/configure-file-url/_expected/amd/main.js index 7fd64cc10db..8d8463928ba 100644 --- a/test/chunking-form/samples/configure-file-url/_expected/amd/main.js +++ b/test/chunking-form/samples/configure-file-url/_expected/amd/main.js @@ -6,6 +6,6 @@ define(['module', 'require'], function (module, require) { 'use strict'; const asset$1 = new URL(module.uri + '/../assets/asset-unresolved-9548436d.txt', document.baseURI).href; const chunk$1 = new URL(module.uri + '/../chunk.js', document.baseURI).href; - new Promise(function (resolve, reject) { require(['./nested/chunk.js'], resolve, reject) }).then(result => console.log(result, chunk, chunk$1, asset, asset$1)); + new Promise(function (resolve, reject) { require(['./nested/chunk'], resolve, reject) }).then(result => console.log(result, chunk, chunk$1, asset, asset$1)); }); diff --git a/test/chunking-form/samples/deconflict-globals/_expected/amd/main1.js b/test/chunking-form/samples/deconflict-globals/_expected/amd/main1.js index ecf5ce1bd53..875ce56c7de 100644 --- a/test/chunking-form/samples/deconflict-globals/_expected/amd/main1.js +++ b/test/chunking-form/samples/deconflict-globals/_expected/amd/main1.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; +define(['./generated-chunk'], function (__chunk_1) { 'use strict'; console.log(__chunk_1.x); diff --git a/test/chunking-form/samples/deconflict-globals/_expected/amd/main2.js b/test/chunking-form/samples/deconflict-globals/_expected/amd/main2.js index 178cb27ad02..5d18b330e59 100644 --- a/test/chunking-form/samples/deconflict-globals/_expected/amd/main2.js +++ b/test/chunking-form/samples/deconflict-globals/_expected/amd/main2.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; +define(['./generated-chunk'], function (__chunk_1) { 'use strict'; console.log(x, __chunk_1.x); diff --git a/test/chunking-form/samples/deduplicate-imports-referencing-originals-2/_expected/amd/main1.js b/test/chunking-form/samples/deduplicate-imports-referencing-originals-2/_expected/amd/main1.js index 302e4c4da46..4116f89dc57 100644 --- a/test/chunking-form/samples/deduplicate-imports-referencing-originals-2/_expected/amd/main1.js +++ b/test/chunking-form/samples/deduplicate-imports-referencing-originals-2/_expected/amd/main1.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; +define(['./generated-chunk'], function (__chunk_1) { 'use strict'; console.log(__chunk_1.bar, __chunk_1.bar); diff --git a/test/chunking-form/samples/deduplicate-imports-referencing-originals-2/_expected/amd/main2.js b/test/chunking-form/samples/deduplicate-imports-referencing-originals-2/_expected/amd/main2.js index 302e4c4da46..4116f89dc57 100644 --- a/test/chunking-form/samples/deduplicate-imports-referencing-originals-2/_expected/amd/main2.js +++ b/test/chunking-form/samples/deduplicate-imports-referencing-originals-2/_expected/amd/main2.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; +define(['./generated-chunk'], function (__chunk_1) { 'use strict'; console.log(__chunk_1.bar, __chunk_1.bar); diff --git a/test/chunking-form/samples/deduplicate-imports-referencing-originals/_expected/amd/main1.js b/test/chunking-form/samples/deduplicate-imports-referencing-originals/_expected/amd/main1.js index 302e4c4da46..4116f89dc57 100644 --- a/test/chunking-form/samples/deduplicate-imports-referencing-originals/_expected/amd/main1.js +++ b/test/chunking-form/samples/deduplicate-imports-referencing-originals/_expected/amd/main1.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; +define(['./generated-chunk'], function (__chunk_1) { 'use strict'; console.log(__chunk_1.bar, __chunk_1.bar); diff --git a/test/chunking-form/samples/deduplicate-imports-referencing-originals/_expected/amd/main2.js b/test/chunking-form/samples/deduplicate-imports-referencing-originals/_expected/amd/main2.js index 302e4c4da46..4116f89dc57 100644 --- a/test/chunking-form/samples/deduplicate-imports-referencing-originals/_expected/amd/main2.js +++ b/test/chunking-form/samples/deduplicate-imports-referencing-originals/_expected/amd/main2.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; +define(['./generated-chunk'], function (__chunk_1) { 'use strict'; console.log(__chunk_1.bar, __chunk_1.bar); diff --git a/test/chunking-form/samples/default-identifier-renaming/_expected/amd/main1.js b/test/chunking-form/samples/default-identifier-renaming/_expected/amd/main1.js index c9e4318d314..d67cb599463 100644 --- a/test/chunking-form/samples/default-identifier-renaming/_expected/amd/main1.js +++ b/test/chunking-form/samples/default-identifier-renaming/_expected/amd/main1.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; +define(['./generated-chunk'], function (__chunk_1) { 'use strict'; var main1 = __chunk_1.d.map(d => d + 1); diff --git a/test/chunking-form/samples/default-identifier-renaming/_expected/amd/main2.js b/test/chunking-form/samples/default-identifier-renaming/_expected/amd/main2.js index bc56788609f..aaabc773106 100644 --- a/test/chunking-form/samples/default-identifier-renaming/_expected/amd/main2.js +++ b/test/chunking-form/samples/default-identifier-renaming/_expected/amd/main2.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; +define(['./generated-chunk'], function (__chunk_1) { 'use strict'; var main2 = __chunk_1.d.map(d => d + 2); diff --git a/test/chunking-form/samples/dynamic-import-chained/_expected/amd/generated-chunk2.js b/test/chunking-form/samples/dynamic-import-chained/_expected/amd/generated-chunk2.js index dd1c3279a6c..a3a007a9219 100644 --- a/test/chunking-form/samples/dynamic-import-chained/_expected/amd/generated-chunk2.js +++ b/test/chunking-form/samples/dynamic-import-chained/_expected/amd/generated-chunk2.js @@ -1,6 +1,6 @@ define(['require'], function (require) { 'use strict'; console.log('dep1'); - new Promise(function (resolve, reject) { require(['./generated-chunk.js'], resolve, reject) }); + new Promise(function (resolve, reject) { require(['./generated-chunk'], resolve, reject) }); }); diff --git a/test/chunking-form/samples/dynamic-import-chained/_expected/amd/main.js b/test/chunking-form/samples/dynamic-import-chained/_expected/amd/main.js index 5ccfb90eecb..4c78beff51c 100644 --- a/test/chunking-form/samples/dynamic-import-chained/_expected/amd/main.js +++ b/test/chunking-form/samples/dynamic-import-chained/_expected/amd/main.js @@ -1,6 +1,6 @@ define(['require'], function (require) { 'use strict'; console.log('main'); - new Promise(function (resolve, reject) { require(['./generated-chunk2.js'], resolve, reject) }); + new Promise(function (resolve, reject) { require(['./generated-chunk2'], resolve, reject) }); }); diff --git a/test/chunking-form/samples/dynamic-import-chunking/_expected/amd/generated-chunk2.js b/test/chunking-form/samples/dynamic-import-chunking/_expected/amd/generated-chunk2.js index e7a09c0f4e9..d6192e01c21 100644 --- a/test/chunking-form/samples/dynamic-import-chunking/_expected/amd/generated-chunk2.js +++ b/test/chunking-form/samples/dynamic-import-chunking/_expected/amd/generated-chunk2.js @@ -1,4 +1,4 @@ -define(['exports', './generated-chunk.js'], function (exports, __chunk_1) { 'use strict'; +define(['exports', './generated-chunk'], function (exports, __chunk_1) { 'use strict'; function mult (num) { return num + __chunk_1.multiplier; diff --git a/test/chunking-form/samples/dynamic-import-chunking/_expected/amd/main.js b/test/chunking-form/samples/dynamic-import-chunking/_expected/amd/main.js index 67da9d2aa86..9a5bfc4f5fe 100644 --- a/test/chunking-form/samples/dynamic-import-chunking/_expected/amd/main.js +++ b/test/chunking-form/samples/dynamic-import-chunking/_expected/amd/main.js @@ -1,4 +1,4 @@ -define(['require', './generated-chunk.js'], function (require, __chunk_1) { 'use strict'; +define(['require', './generated-chunk'], function (require, __chunk_1) { 'use strict'; function calc (num) { return num * __chunk_1.multiplier; @@ -9,7 +9,7 @@ define(['require', './generated-chunk.js'], function (require, __chunk_1) { 'use } function dynamic (num) { - return new Promise(function (resolve, reject) { require(['./generated-chunk2.js'], resolve, reject) }) + return new Promise(function (resolve, reject) { require(['./generated-chunk2'], resolve, reject) }) .then(dep2 => { return dep2.mult(num); }); diff --git a/test/chunking-form/samples/dynamic-import-facade/_expected/amd/generated-chunk2.js b/test/chunking-form/samples/dynamic-import-facade/_expected/amd/generated-chunk2.js index 872563addeb..4fb60e87db8 100644 --- a/test/chunking-form/samples/dynamic-import-facade/_expected/amd/generated-chunk2.js +++ b/test/chunking-form/samples/dynamic-import-facade/_expected/amd/generated-chunk2.js @@ -1,4 +1,4 @@ -define(['exports', './generated-chunk.js'], function (exports, dynamic_js) { 'use strict'; +define(['exports', './generated-chunk'], function (exports, dynamic_js) { 'use strict'; diff --git a/test/chunking-form/samples/dynamic-import-facade/_expected/amd/main1.js b/test/chunking-form/samples/dynamic-import-facade/_expected/amd/main1.js index 570ef4f354d..3efdb461ba4 100644 --- a/test/chunking-form/samples/dynamic-import-facade/_expected/amd/main1.js +++ b/test/chunking-form/samples/dynamic-import-facade/_expected/amd/main1.js @@ -1,5 +1,5 @@ define(['require'], function (require) { 'use strict'; - new Promise(function (resolve, reject) { require(['./generated-chunk2.js'], resolve, reject) }).then(({dynamic}) => console.log('main1', dynamic)); + new Promise(function (resolve, reject) { require(['./generated-chunk2'], resolve, reject) }).then(({dynamic}) => console.log('main1', dynamic)); }); diff --git a/test/chunking-form/samples/dynamic-import-facade/_expected/amd/main2.js b/test/chunking-form/samples/dynamic-import-facade/_expected/amd/main2.js index 050d46670e8..fdc6e221a48 100644 --- a/test/chunking-form/samples/dynamic-import-facade/_expected/amd/main2.js +++ b/test/chunking-form/samples/dynamic-import-facade/_expected/amd/main2.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (dynamic_js) { 'use strict'; +define(['./generated-chunk'], function (dynamic_js) { 'use strict'; console.log('main2', dynamic_js.dynamic, dynamic_js.dep); diff --git a/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/amd/main1.js b/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/amd/main1.js index 5f4d1a82f33..9c51a929f27 100644 --- a/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/amd/main1.js +++ b/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/amd/main1.js @@ -1,7 +1,7 @@ -define(['require', 'exports', './generated-chunk.js', './generated-chunk2.js'], function (require, exports, inlined_js, separate_js) { 'use strict'; +define(['require', 'exports', './generated-chunk', './generated-chunk2'], function (require, exports, inlined_js, separate_js) { 'use strict'; - const inlined = new Promise(function (resolve, reject) { require(['./generated-chunk.js'], resolve, reject) }); - const separate = new Promise(function (resolve, reject) { require(['./generated-chunk2.js'], resolve, reject) }); + const inlined = new Promise(function (resolve, reject) { require(['./generated-chunk'], resolve, reject) }); + const separate = new Promise(function (resolve, reject) { require(['./generated-chunk2'], resolve, reject) }); exports.inlined = inlined; exports.separate = separate; diff --git a/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/amd/main2.js b/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/amd/main2.js index daa2ff23c23..7ce766added 100644 --- a/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/amd/main2.js +++ b/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/amd/main2.js @@ -1,6 +1,6 @@ define(['require', 'exports'], function (require, exports) { 'use strict'; - const separate = new Promise(function (resolve, reject) { require(['./generated-chunk2.js'], resolve, reject) }); + const separate = new Promise(function (resolve, reject) { require(['./generated-chunk2'], resolve, reject) }); exports.separate = separate; diff --git a/test/chunking-form/samples/dynamic-import-only-reexports/_expected/amd/main.js b/test/chunking-form/samples/dynamic-import-only-reexports/_expected/amd/main.js index fdc21863cbe..7d42d18212d 100644 --- a/test/chunking-form/samples/dynamic-import-only-reexports/_expected/amd/main.js +++ b/test/chunking-form/samples/dynamic-import-only-reexports/_expected/amd/main.js @@ -1,5 +1,5 @@ define(['require'], function (require) { 'use strict'; - new Promise(function (resolve, reject) { require(['./generated-chunk.js'], resolve, reject) }).then(({ value }) => console.log(value)); + new Promise(function (resolve, reject) { require(['./generated-chunk'], resolve, reject) }).then(({ value }) => console.log(value)); }); diff --git a/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/amd/generated-chunk2.js b/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/amd/generated-chunk2.js index add64858457..2e890387bbe 100644 --- a/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/amd/generated-chunk2.js +++ b/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/amd/generated-chunk2.js @@ -1,4 +1,4 @@ -define(['exports', './generated-chunk.js'], function (exports, dep1_js) { 'use strict'; +define(['exports', './generated-chunk'], function (exports, dep1_js) { 'use strict'; diff --git a/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/amd/main.js b/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/amd/main.js index 3644b7ffb2f..2b7ac5e4e0d 100644 --- a/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/amd/main.js +++ b/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/amd/main.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (dep1_js) { 'use strict'; +define(['./generated-chunk'], function (dep1_js) { 'use strict'; console.log(dep1_js.foo(), dep1_js.bar()); diff --git a/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/amd/main2.js b/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/amd/main2.js index f9a67e79b6a..794f49aeca2 100644 --- a/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/amd/main2.js +++ b/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/amd/main2.js @@ -1,5 +1,5 @@ define(['require'], function (require) { 'use strict'; - new Promise(function (resolve, reject) { require(['./generated-chunk2.js'], resolve, reject) }).then(({ bar }) => console.log(bar())); + new Promise(function (resolve, reject) { require(['./generated-chunk2'], resolve, reject) }).then(({ bar }) => console.log(bar())); }); diff --git a/test/chunking-form/samples/dynamic-import-statically-imported/_expected/amd/main.js b/test/chunking-form/samples/dynamic-import-statically-imported/_expected/amd/main.js index d90b886ebac..b9e9c31e762 100644 --- a/test/chunking-form/samples/dynamic-import-statically-imported/_expected/amd/main.js +++ b/test/chunking-form/samples/dynamic-import-statically-imported/_expected/amd/main.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; +define(['./generated-chunk'], function (__chunk_1) { 'use strict'; console.log(__chunk_1.foo(), __chunk_1.bar()); diff --git a/test/chunking-form/samples/dynamic-import/_config.js b/test/chunking-form/samples/dynamic-import/_config.js new file mode 100644 index 00000000000..c62aae20125 --- /dev/null +++ b/test/chunking-form/samples/dynamic-import/_config.js @@ -0,0 +1,14 @@ +module.exports = { + description: 'handles dynamic imports with a shared dependency', + options: { + input: ['main'], + output: { + chunkFileNames: 'chunks/[name].js' + } + }, + runAmd: { + exports(exports) { + return exports.promise; + } + } +}; diff --git a/test/chunking-form/samples/dynamic-import/_expected/amd/chunks/chunk.js b/test/chunking-form/samples/dynamic-import/_expected/amd/chunks/chunk.js new file mode 100644 index 00000000000..65e59158953 --- /dev/null +++ b/test/chunking-form/samples/dynamic-import/_expected/amd/chunks/chunk.js @@ -0,0 +1,7 @@ +define(['exports'], function (exports) { 'use strict'; + + const sharedValue = 'shared'; + + exports.sharedValue = sharedValue; + +}); diff --git a/test/chunking-form/samples/dynamic-import/_expected/amd/chunks/chunk2.js b/test/chunking-form/samples/dynamic-import/_expected/amd/chunks/chunk2.js new file mode 100644 index 00000000000..3aab0b0cf74 --- /dev/null +++ b/test/chunking-form/samples/dynamic-import/_expected/amd/chunks/chunk2.js @@ -0,0 +1,7 @@ +define(['exports', './chunk'], function (exports, __chunk_1) { 'use strict'; + + + + exports.value = __chunk_1.sharedValue; + +}); diff --git a/test/chunking-form/samples/dynamic-import/_expected/amd/main.js b/test/chunking-form/samples/dynamic-import/_expected/amd/main.js new file mode 100644 index 00000000000..3c301a7e490 --- /dev/null +++ b/test/chunking-form/samples/dynamic-import/_expected/amd/main.js @@ -0,0 +1,13 @@ +define(['require', 'exports', './chunks/chunk'], function (require, exports, __chunk_1) { 'use strict'; + + assert.equal(__chunk_1.sharedValue, 'shared'); + + const promise = new Promise(function (resolve, reject) { require(['./chunks/chunk2'], resolve, reject) }).then(result => + assert.deepEqual(result, { value: 'shared' }) + ); + + exports.promise = promise; + + Object.defineProperty(exports, '__esModule', { value: true }); + +}); diff --git a/test/chunking-form/samples/dynamic-import/_expected/cjs/chunks/chunk.js b/test/chunking-form/samples/dynamic-import/_expected/cjs/chunks/chunk.js new file mode 100644 index 00000000000..5a6d40af489 --- /dev/null +++ b/test/chunking-form/samples/dynamic-import/_expected/cjs/chunks/chunk.js @@ -0,0 +1,5 @@ +'use strict'; + +const sharedValue = 'shared'; + +exports.sharedValue = sharedValue; diff --git a/test/chunking-form/samples/dynamic-import/_expected/cjs/chunks/chunk2.js b/test/chunking-form/samples/dynamic-import/_expected/cjs/chunks/chunk2.js new file mode 100644 index 00000000000..04b27928561 --- /dev/null +++ b/test/chunking-form/samples/dynamic-import/_expected/cjs/chunks/chunk2.js @@ -0,0 +1,7 @@ +'use strict'; + +var __chunk_1 = require('./chunk.js'); + + + +exports.value = __chunk_1.sharedValue; diff --git a/test/chunking-form/samples/dynamic-import/_expected/cjs/main.js b/test/chunking-form/samples/dynamic-import/_expected/cjs/main.js new file mode 100644 index 00000000000..c5526455ed2 --- /dev/null +++ b/test/chunking-form/samples/dynamic-import/_expected/cjs/main.js @@ -0,0 +1,13 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +var __chunk_1 = require('./chunks/chunk.js'); + +assert.equal(__chunk_1.sharedValue, 'shared'); + +const promise = Promise.resolve(require('./chunks/chunk2.js')).then(result => + assert.deepEqual(result, { value: 'shared' }) +); + +exports.promise = promise; diff --git a/test/chunking-form/samples/dynamic-import/_expected/es/chunks/chunk.js b/test/chunking-form/samples/dynamic-import/_expected/es/chunks/chunk.js new file mode 100644 index 00000000000..94dca2d35b3 --- /dev/null +++ b/test/chunking-form/samples/dynamic-import/_expected/es/chunks/chunk.js @@ -0,0 +1,3 @@ +const sharedValue = 'shared'; + +export { sharedValue as a }; diff --git a/test/chunking-form/samples/dynamic-import/_expected/es/chunks/chunk2.js b/test/chunking-form/samples/dynamic-import/_expected/es/chunks/chunk2.js new file mode 100644 index 00000000000..614213eb1d2 --- /dev/null +++ b/test/chunking-form/samples/dynamic-import/_expected/es/chunks/chunk2.js @@ -0,0 +1 @@ +export { a as value } from './chunk.js'; diff --git a/test/chunking-form/samples/dynamic-import/_expected/es/main.js b/test/chunking-form/samples/dynamic-import/_expected/es/main.js new file mode 100644 index 00000000000..457f2aba301 --- /dev/null +++ b/test/chunking-form/samples/dynamic-import/_expected/es/main.js @@ -0,0 +1,9 @@ +import { a as sharedValue } from './chunks/chunk.js'; + +assert.equal(sharedValue, 'shared'); + +const promise = import('./chunks/chunk2.js').then(result => + assert.deepEqual(result, { value: 'shared' }) +); + +export { promise }; diff --git a/test/chunking-form/samples/dynamic-import/_expected/system/chunks/chunk.js b/test/chunking-form/samples/dynamic-import/_expected/system/chunks/chunk.js new file mode 100644 index 00000000000..f4a5045db1a --- /dev/null +++ b/test/chunking-form/samples/dynamic-import/_expected/system/chunks/chunk.js @@ -0,0 +1,10 @@ +System.register([], function (exports, module) { + 'use strict'; + return { + execute: function () { + + const sharedValue = exports('a', 'shared'); + + } + }; +}); diff --git a/test/chunking-form/samples/dynamic-import/_expected/system/chunks/chunk2.js b/test/chunking-form/samples/dynamic-import/_expected/system/chunks/chunk2.js new file mode 100644 index 00000000000..91d13a25f79 --- /dev/null +++ b/test/chunking-form/samples/dynamic-import/_expected/system/chunks/chunk2.js @@ -0,0 +1,13 @@ +System.register(['./chunk.js'], function (exports, module) { + 'use strict'; + return { + setters: [function (module) { + exports('value', module.a); + }], + execute: function () { + + + + } + }; +}); diff --git a/test/chunking-form/samples/dynamic-import/_expected/system/main.js b/test/chunking-form/samples/dynamic-import/_expected/system/main.js new file mode 100644 index 00000000000..ace4b6cf31c --- /dev/null +++ b/test/chunking-form/samples/dynamic-import/_expected/system/main.js @@ -0,0 +1,18 @@ +System.register(['./chunks/chunk.js'], function (exports, module) { + 'use strict'; + var sharedValue; + return { + setters: [function (module) { + sharedValue = module.a; + }], + execute: function () { + + assert.equal(sharedValue, 'shared'); + + const promise = exports('promise', module.import('./chunks/chunk2.js').then(result => + assert.deepEqual(result, { value: 'shared' }) + )); + + } + }; +}); diff --git a/test/chunking-form/samples/dynamic-import/main.js b/test/chunking-form/samples/dynamic-import/main.js new file mode 100644 index 00000000000..cf97619c11b --- /dev/null +++ b/test/chunking-form/samples/dynamic-import/main.js @@ -0,0 +1,6 @@ +import { sharedValue } from './shared'; +assert.equal(sharedValue, 'shared'); + +export const promise = import('./other').then(result => + assert.deepEqual(result, { value: 'shared' }) +); diff --git a/test/chunking-form/samples/dynamic-import/other.js b/test/chunking-form/samples/dynamic-import/other.js new file mode 100644 index 00000000000..e662538f8b4 --- /dev/null +++ b/test/chunking-form/samples/dynamic-import/other.js @@ -0,0 +1 @@ +export { sharedValue as value } from './shared'; diff --git a/test/chunking-form/samples/dynamic-import/shared.js b/test/chunking-form/samples/dynamic-import/shared.js new file mode 100644 index 00000000000..7a5200e8ec7 --- /dev/null +++ b/test/chunking-form/samples/dynamic-import/shared.js @@ -0,0 +1 @@ +export const sharedValue = 'shared'; diff --git a/test/chunking-form/samples/emit-entry-chunk-facade/_expected/amd/buildStart.js b/test/chunking-form/samples/emit-entry-chunk-facade/_expected/amd/buildStart.js index b72b98f383a..90fb5bc3e0a 100644 --- a/test/chunking-form/samples/emit-entry-chunk-facade/_expected/amd/buildStart.js +++ b/test/chunking-form/samples/emit-entry-chunk-facade/_expected/amd/buildStart.js @@ -1,4 +1,4 @@ -define(['exports', './generated-build-starter.js'], function (exports, buildStart) { 'use strict'; +define(['exports', './generated-build-starter'], function (exports, buildStart) { 'use strict'; diff --git a/test/chunking-form/samples/emit-entry-chunk-facade/_expected/amd/main.js b/test/chunking-form/samples/emit-entry-chunk-facade/_expected/amd/main.js index e5dd2756bd9..328cf40fd71 100644 --- a/test/chunking-form/samples/emit-entry-chunk-facade/_expected/amd/main.js +++ b/test/chunking-form/samples/emit-entry-chunk-facade/_expected/amd/main.js @@ -1,4 +1,4 @@ -define(['./generated-build-starter.js'], function (buildStart) { 'use strict'; +define(['./generated-build-starter'], function (buildStart) { 'use strict'; console.log('main', buildStart.value); diff --git a/test/chunking-form/samples/emit-entry-chunk/_expected/amd/buildStart.js b/test/chunking-form/samples/emit-entry-chunk/_expected/amd/buildStart.js index 946e98c742b..e313dd4eb35 100644 --- a/test/chunking-form/samples/emit-entry-chunk/_expected/amd/buildStart.js +++ b/test/chunking-form/samples/emit-entry-chunk/_expected/amd/buildStart.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; +define(['./generated-chunk'], function (__chunk_1) { 'use strict'; console.log('startBuild', __chunk_1.value); diff --git a/test/chunking-form/samples/emit-entry-chunk/_expected/amd/main.js b/test/chunking-form/samples/emit-entry-chunk/_expected/amd/main.js index 486030eb3c3..56bd65658a2 100644 --- a/test/chunking-form/samples/emit-entry-chunk/_expected/amd/main.js +++ b/test/chunking-form/samples/emit-entry-chunk/_expected/amd/main.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; +define(['./generated-chunk'], function (__chunk_1) { 'use strict'; console.log('main', __chunk_1.value); diff --git a/test/chunking-form/samples/emit-entry-existing/_expected/amd/first-main.js b/test/chunking-form/samples/emit-entry-existing/_expected/amd/first-main.js index e92c9063515..eb85a7017b0 100644 --- a/test/chunking-form/samples/emit-entry-existing/_expected/amd/first-main.js +++ b/test/chunking-form/samples/emit-entry-existing/_expected/amd/first-main.js @@ -1,4 +1,4 @@ -define(['./dep.js'], function (dep) { 'use strict'; +define(['./dep'], function (dep) { 'use strict'; console.log('main1', dep); diff --git a/test/chunking-form/samples/emit-entry-existing/_expected/amd/second-main.js b/test/chunking-form/samples/emit-entry-existing/_expected/amd/second-main.js index e92c9063515..eb85a7017b0 100644 --- a/test/chunking-form/samples/emit-entry-existing/_expected/amd/second-main.js +++ b/test/chunking-form/samples/emit-entry-existing/_expected/amd/second-main.js @@ -1,4 +1,4 @@ -define(['./dep.js'], function (dep) { 'use strict'; +define(['./dep'], function (dep) { 'use strict'; console.log('main1', dep); diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/amd/main.js b/test/chunking-form/samples/emit-entry-worker/_expected/amd/main.js index 47fa1c45ce5..9facbe919ee 100644 --- a/test/chunking-form/samples/emit-entry-worker/_expected/amd/main.js +++ b/test/chunking-form/samples/emit-entry-worker/_expected/amd/main.js @@ -1,4 +1,4 @@ -define(['module', 'require', './chunks/chunk.js'], function (module, require, __chunk_1) { 'use strict'; +define(['module', 'require', './chunks/chunk'], function (module, require, __chunk_1) { 'use strict'; const getWorkerMessage = () => new Promise(resolve => { const worker = new Worker(new URL(module.uri + '/../worker-proxy.js', document.baseURI).href); @@ -8,7 +8,7 @@ define(['module', 'require', './chunks/chunk.js'], function (module, require, __ document.body.innerHTML += `

main: ${__chunk_1.shared}

`; getWorkerMessage().then(message => (document.body.innerHTML += `

1: ${message.data}

`)); - new Promise(function (resolve, reject) { require(['./chunks/chunk2.js'], resolve, reject) }) + new Promise(function (resolve, reject) { require(['./chunks/chunk2'], resolve, reject) }) .then(result => result.getWorkerMessage()) .then(message => (document.body.innerHTML += `

2: ${message.data}

`)); diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/amd/worker.js b/test/chunking-form/samples/emit-entry-worker/_expected/amd/worker.js index 4516491b07b..6684145758a 100644 --- a/test/chunking-form/samples/emit-entry-worker/_expected/amd/worker.js +++ b/test/chunking-form/samples/emit-entry-worker/_expected/amd/worker.js @@ -1,4 +1,4 @@ -define(['./chunks/chunk.js'], function (__chunk_1) { 'use strict'; +define(['./chunks/chunk'], function (__chunk_1) { 'use strict'; postMessage(`from worker: ${__chunk_1.shared}`); diff --git a/test/chunking-form/samples/entry-chunk-export-mode/_expected/amd/main1.js b/test/chunking-form/samples/entry-chunk-export-mode/_expected/amd/main1.js index cb06afa3a2b..0d61613c51f 100644 --- a/test/chunking-form/samples/entry-chunk-export-mode/_expected/amd/main1.js +++ b/test/chunking-form/samples/entry-chunk-export-mode/_expected/amd/main1.js @@ -1,4 +1,4 @@ -define(['./main2.js'], function (main2) { 'use strict'; +define(['./main2'], function (main2) { 'use strict'; main2(); diff --git a/test/chunking-form/samples/entry-point-without-own-code/_expected/amd/generated-m1.js b/test/chunking-form/samples/entry-point-without-own-code/_expected/amd/generated-m1.js index 77ebf9c9248..d23351b5be1 100644 --- a/test/chunking-form/samples/entry-point-without-own-code/_expected/amd/generated-m1.js +++ b/test/chunking-form/samples/entry-point-without-own-code/_expected/amd/generated-m1.js @@ -1,4 +1,4 @@ -define(['exports', './m2.js'], function (exports, m2) { 'use strict'; +define(['exports', './m2'], function (exports, m2) { 'use strict'; diff --git a/test/chunking-form/samples/entry-point-without-own-code/_expected/amd/m1.js b/test/chunking-form/samples/entry-point-without-own-code/_expected/amd/m1.js index 0103e34d77d..b95c6ca797c 100644 --- a/test/chunking-form/samples/entry-point-without-own-code/_expected/amd/m1.js +++ b/test/chunking-form/samples/entry-point-without-own-code/_expected/amd/m1.js @@ -1,4 +1,4 @@ -define(['exports', './m2.js', './generated-m1.js'], function (exports, m2, m1) { 'use strict'; +define(['exports', './m2', './generated-m1'], function (exports, m2, m1) { 'use strict'; diff --git a/test/chunking-form/samples/entry-point-without-own-code/_expected/amd/main.js b/test/chunking-form/samples/entry-point-without-own-code/_expected/amd/main.js index e57685b8d41..fd4897a745b 100644 --- a/test/chunking-form/samples/entry-point-without-own-code/_expected/amd/main.js +++ b/test/chunking-form/samples/entry-point-without-own-code/_expected/amd/main.js @@ -1,4 +1,4 @@ -define(['./m2.js', './generated-m1.js'], function (m2, m1) { 'use strict'; +define(['./m2', './generated-m1'], function (m2, m1) { 'use strict'; console.log(m1.ms); diff --git a/test/chunking-form/samples/entrypoint-aliasing/_expected/amd/main1alias.js b/test/chunking-form/samples/entrypoint-aliasing/_expected/amd/main1alias.js index 24677c96bb0..bac6f259fff 100644 --- a/test/chunking-form/samples/entrypoint-aliasing/_expected/amd/main1alias.js +++ b/test/chunking-form/samples/entrypoint-aliasing/_expected/amd/main1alias.js @@ -1,4 +1,4 @@ -define(['./generated-main2alias.js'], function (main2alias) { 'use strict'; +define(['./generated-main2alias'], function (main2alias) { 'use strict'; main2alias.log(main2alias.dep); diff --git a/test/chunking-form/samples/entrypoint-aliasing/_expected/amd/main2alias.js b/test/chunking-form/samples/entrypoint-aliasing/_expected/amd/main2alias.js index 1fdf53588c5..2747e887cd9 100644 --- a/test/chunking-form/samples/entrypoint-aliasing/_expected/amd/main2alias.js +++ b/test/chunking-form/samples/entrypoint-aliasing/_expected/amd/main2alias.js @@ -1,4 +1,4 @@ -define(['./generated-main2alias.js'], function (main2alias) { 'use strict'; +define(['./generated-main2alias'], function (main2alias) { 'use strict'; diff --git a/test/chunking-form/samples/entrypoint-facade/_expected/amd/main1.js b/test/chunking-form/samples/entrypoint-facade/_expected/amd/main1.js index 800083d483f..b319e7ebff9 100644 --- a/test/chunking-form/samples/entrypoint-facade/_expected/amd/main1.js +++ b/test/chunking-form/samples/entrypoint-facade/_expected/amd/main1.js @@ -1,4 +1,4 @@ -define(['./generated-main2.js'], function (main2) { 'use strict'; +define(['./generated-main2'], function (main2) { 'use strict'; main2.log(main2.dep); diff --git a/test/chunking-form/samples/entrypoint-facade/_expected/amd/main2.js b/test/chunking-form/samples/entrypoint-facade/_expected/amd/main2.js index 9d820bbf99a..e4a115ee883 100644 --- a/test/chunking-form/samples/entrypoint-facade/_expected/amd/main2.js +++ b/test/chunking-form/samples/entrypoint-facade/_expected/amd/main2.js @@ -1,4 +1,4 @@ -define(['./generated-main2.js'], function (main2) { 'use strict'; +define(['./generated-main2'], function (main2) { 'use strict'; diff --git a/test/chunking-form/samples/export-default-from-entry/_expected/amd/main.js b/test/chunking-form/samples/export-default-from-entry/_expected/amd/main.js index f34747d3cdb..515a0bbe1cf 100644 --- a/test/chunking-form/samples/export-default-from-entry/_expected/amd/main.js +++ b/test/chunking-form/samples/export-default-from-entry/_expected/amd/main.js @@ -1,4 +1,4 @@ -define(['exports', './dep.js'], function (exports, dep) { 'use strict'; +define(['exports', './dep'], function (exports, dep) { 'use strict'; diff --git a/test/chunking-form/samples/filenames-patterns/_expected/amd/entry-main1-e7c7d1b5-amd.js b/test/chunking-form/samples/filenames-patterns/_expected/amd/entry-main1-e7c7d1b5-amd.js index 5cf1f787f69..791e2547a0f 100644 --- a/test/chunking-form/samples/filenames-patterns/_expected/amd/entry-main1-e7c7d1b5-amd.js +++ b/test/chunking-form/samples/filenames-patterns/_expected/amd/entry-main1-e7c7d1b5-amd.js @@ -1,4 +1,4 @@ -define(['./chunk-main2-6bb39c19-amd.js'], function (main2) { 'use strict'; +define(['./chunk-main2-6bb39c19-amd'], function (main2) { 'use strict'; main2.log(main2.dep); diff --git a/test/chunking-form/samples/filenames-patterns/_expected/amd/entry-main2-f9a2200a-amd.js b/test/chunking-form/samples/filenames-patterns/_expected/amd/entry-main2-f9a2200a-amd.js index 8bfb309da5e..0e357dbc084 100644 --- a/test/chunking-form/samples/filenames-patterns/_expected/amd/entry-main2-f9a2200a-amd.js +++ b/test/chunking-form/samples/filenames-patterns/_expected/amd/entry-main2-f9a2200a-amd.js @@ -1,4 +1,4 @@ -define(['./chunk-main2-6bb39c19-amd.js'], function (main2) { 'use strict'; +define(['./chunk-main2-6bb39c19-amd'], function (main2) { 'use strict'; diff --git a/test/chunking-form/samples/grouping-multiple/_expected/amd/main1.js b/test/chunking-form/samples/grouping-multiple/_expected/amd/main1.js index 03b232e9f26..70d5738bbcb 100644 --- a/test/chunking-form/samples/grouping-multiple/_expected/amd/main1.js +++ b/test/chunking-form/samples/grouping-multiple/_expected/amd/main1.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; +define(['./generated-chunk'], function (__chunk_1) { 'use strict'; var main1 = __chunk_1.x + __chunk_1.y; diff --git a/test/chunking-form/samples/grouping-multiple/_expected/amd/main2.js b/test/chunking-form/samples/grouping-multiple/_expected/amd/main2.js index 0a3dfa0871e..4aef9d410a7 100644 --- a/test/chunking-form/samples/grouping-multiple/_expected/amd/main2.js +++ b/test/chunking-form/samples/grouping-multiple/_expected/amd/main2.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; +define(['./generated-chunk'], function (__chunk_1) { 'use strict'; var main2 = __chunk_1.x + __chunk_1.z; diff --git a/test/chunking-form/samples/grouping-multiple/_expected/amd/main3.js b/test/chunking-form/samples/grouping-multiple/_expected/amd/main3.js index bd9fa6422ac..b42651359db 100644 --- a/test/chunking-form/samples/grouping-multiple/_expected/amd/main3.js +++ b/test/chunking-form/samples/grouping-multiple/_expected/amd/main3.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; +define(['./generated-chunk'], function (__chunk_1) { 'use strict'; var main3 = __chunk_1.y + __chunk_1.z; diff --git a/test/chunking-form/samples/grouping-size/_expected/amd/main1.js b/test/chunking-form/samples/grouping-size/_expected/amd/main1.js index f18ba752f42..c21d934d51e 100644 --- a/test/chunking-form/samples/grouping-size/_expected/amd/main1.js +++ b/test/chunking-form/samples/grouping-size/_expected/amd/main1.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js', './generated-chunk2.js'], function (__chunk_1, __chunk_2) { 'use strict'; +define(['./generated-chunk', './generated-chunk2'], function (__chunk_1, __chunk_2) { 'use strict'; var main1 = __chunk_1.x + __chunk_2.y; diff --git a/test/chunking-form/samples/grouping-size/_expected/amd/main2.js b/test/chunking-form/samples/grouping-size/_expected/amd/main2.js index df2bfa670de..0eb3cf0c0aa 100644 --- a/test/chunking-form/samples/grouping-size/_expected/amd/main2.js +++ b/test/chunking-form/samples/grouping-size/_expected/amd/main2.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js', './generated-chunk2.js'], function (__chunk_1, __chunk_2) { 'use strict'; +define(['./generated-chunk', './generated-chunk2'], function (__chunk_1, __chunk_2) { 'use strict'; var main2 = __chunk_1.x + __chunk_2.z; diff --git a/test/chunking-form/samples/grouping-size/_expected/amd/main3.js b/test/chunking-form/samples/grouping-size/_expected/amd/main3.js index 1f8ae40d5d3..7d4ddbd4550 100644 --- a/test/chunking-form/samples/grouping-size/_expected/amd/main3.js +++ b/test/chunking-form/samples/grouping-size/_expected/amd/main3.js @@ -1,4 +1,4 @@ -define(['./generated-chunk2.js'], function (__chunk_2) { 'use strict'; +define(['./generated-chunk2'], function (__chunk_2) { 'use strict'; var main3 = __chunk_2.y + __chunk_2.z; diff --git a/test/chunking-form/samples/import-meta-url/_expected/amd/main.js b/test/chunking-form/samples/import-meta-url/_expected/amd/main.js index d95c0efb5a9..97f96ccbbaf 100644 --- a/test/chunking-form/samples/import-meta-url/_expected/amd/main.js +++ b/test/chunking-form/samples/import-meta-url/_expected/amd/main.js @@ -1,6 +1,6 @@ -define(['module', 'require', './nested/chunk.js'], function (module, require, __chunk_1) { 'use strict'; +define(['module', 'require', './nested/chunk'], function (module, require, __chunk_1) { 'use strict'; __chunk_1.log('main: ' + new URL(module.uri, document.baseURI).href); - new Promise(function (resolve, reject) { require(['./nested/chunk2.js'], resolve, reject) }); + new Promise(function (resolve, reject) { require(['./nested/chunk2'], resolve, reject) }); }); diff --git a/test/chunking-form/samples/import-meta-url/_expected/amd/nested/chunk2.js b/test/chunking-form/samples/import-meta-url/_expected/amd/nested/chunk2.js index 0c78bb0ac8b..e63722d0646 100644 --- a/test/chunking-form/samples/import-meta-url/_expected/amd/nested/chunk2.js +++ b/test/chunking-form/samples/import-meta-url/_expected/amd/nested/chunk2.js @@ -1,4 +1,4 @@ -define(['module', './chunk.js'], function (module, __chunk_1) { 'use strict'; +define(['module', './chunk'], function (module, __chunk_1) { 'use strict'; __chunk_1.log('nested: ' + new URL(module.uri, document.baseURI).href); diff --git a/test/chunking-form/samples/import-variable-duplicates/_expected/amd/head.js b/test/chunking-form/samples/import-variable-duplicates/_expected/amd/head.js index 17ef0fc0c25..4fee7a37979 100644 --- a/test/chunking-form/samples/import-variable-duplicates/_expected/amd/head.js +++ b/test/chunking-form/samples/import-variable-duplicates/_expected/amd/head.js @@ -1,4 +1,4 @@ -define(['./first.js'], function (first) { 'use strict'; +define(['./first'], function (first) { 'use strict'; diff --git a/test/chunking-form/samples/import-variable-duplicates/_expected/amd/main1.js b/test/chunking-form/samples/import-variable-duplicates/_expected/amd/main1.js index ffbe8de995b..c1fbad76dd0 100644 --- a/test/chunking-form/samples/import-variable-duplicates/_expected/amd/main1.js +++ b/test/chunking-form/samples/import-variable-duplicates/_expected/amd/main1.js @@ -1,4 +1,4 @@ -define(['./first.js'], function (first) { 'use strict'; +define(['./first'], function (first) { 'use strict'; console.log(first); console.log(first); diff --git a/test/chunking-form/samples/import-variable-duplicates/_expected/amd/main2.js b/test/chunking-form/samples/import-variable-duplicates/_expected/amd/main2.js index 7ad9926838b..638c64b4bd7 100644 --- a/test/chunking-form/samples/import-variable-duplicates/_expected/amd/main2.js +++ b/test/chunking-form/samples/import-variable-duplicates/_expected/amd/main2.js @@ -1,4 +1,4 @@ -define(['./first.js'], function (first) { 'use strict'; +define(['./first'], function (first) { 'use strict'; diff --git a/test/chunking-form/samples/manual-chunk-contains-entry-conflict/_expected/amd/main.js b/test/chunking-form/samples/manual-chunk-contains-entry-conflict/_expected/amd/main.js index 905ce3018ca..bf9d53b546e 100644 --- a/test/chunking-form/samples/manual-chunk-contains-entry-conflict/_expected/amd/main.js +++ b/test/chunking-form/samples/manual-chunk-contains-entry-conflict/_expected/amd/main.js @@ -1,4 +1,4 @@ -define(['exports', './generated-outer.js'], function (exports, main) { 'use strict'; +define(['exports', './generated-outer'], function (exports, main) { 'use strict'; diff --git a/test/chunking-form/samples/manual-chunk-is-entry-conflict/_expected/amd/main.js b/test/chunking-form/samples/manual-chunk-is-entry-conflict/_expected/amd/main.js index 57007ba3c57..c5a19397b7d 100644 --- a/test/chunking-form/samples/manual-chunk-is-entry-conflict/_expected/amd/main.js +++ b/test/chunking-form/samples/manual-chunk-is-entry-conflict/_expected/amd/main.js @@ -1,4 +1,4 @@ -define(['exports', './generated-other.js'], function (exports, main) { 'use strict'; +define(['exports', './generated-other'], function (exports, main) { 'use strict'; diff --git a/test/chunking-form/samples/manual-chunks-different-nested/_expected/amd/generated-manual-middle.js b/test/chunking-form/samples/manual-chunks-different-nested/_expected/amd/generated-manual-middle.js index 378a00d6f24..d685b7251a8 100644 --- a/test/chunking-form/samples/manual-chunks-different-nested/_expected/amd/generated-manual-middle.js +++ b/test/chunking-form/samples/manual-chunks-different-nested/_expected/amd/generated-manual-middle.js @@ -1,4 +1,4 @@ -define(['./generated-manual-inner.js'], function (__chunk_1) { 'use strict'; +define(['./generated-manual-inner'], function (__chunk_1) { 'use strict'; console.log('middle'); diff --git a/test/chunking-form/samples/manual-chunks-different-nested/_expected/amd/generated-manual-outer.js b/test/chunking-form/samples/manual-chunks-different-nested/_expected/amd/generated-manual-outer.js index 9a3151549dd..13ebf2a438d 100644 --- a/test/chunking-form/samples/manual-chunks-different-nested/_expected/amd/generated-manual-outer.js +++ b/test/chunking-form/samples/manual-chunks-different-nested/_expected/amd/generated-manual-outer.js @@ -1,4 +1,4 @@ -define(['./generated-manual-middle.js'], function (__chunk_2) { 'use strict'; +define(['./generated-manual-middle'], function (__chunk_2) { 'use strict'; console.log('outer'); diff --git a/test/chunking-form/samples/manual-chunks-different-nested/_expected/amd/main.js b/test/chunking-form/samples/manual-chunks-different-nested/_expected/amd/main.js index 3f877adee34..6bc9ac6c053 100644 --- a/test/chunking-form/samples/manual-chunks-different-nested/_expected/amd/main.js +++ b/test/chunking-form/samples/manual-chunks-different-nested/_expected/amd/main.js @@ -1,4 +1,4 @@ -define(['./generated-manual-inner.js', './generated-manual-middle.js', './generated-manual-outer.js'], function (__chunk_1, __chunk_2, __chunk_3) { 'use strict'; +define(['./generated-manual-inner', './generated-manual-middle', './generated-manual-outer'], function (__chunk_1, __chunk_2, __chunk_3) { 'use strict'; console.log('main'); diff --git a/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/generated-chunk.js b/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/generated-chunk.js index d61d9fe71fc..89b1bf75c5c 100644 --- a/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/generated-chunk.js +++ b/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/generated-chunk.js @@ -1,4 +1,4 @@ -define(['exports', './generated-dynamic.js'], function (exports, dynamic) { 'use strict'; +define(['exports', './generated-dynamic'], function (exports, dynamic) { 'use strict'; diff --git a/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/generated-chunk2.js b/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/generated-chunk2.js index d8b85da29fc..384c6292ada 100644 --- a/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/generated-chunk2.js +++ b/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/generated-chunk2.js @@ -1,4 +1,4 @@ -define(['exports', './generated-dynamic.js'], function (exports, dynamic) { 'use strict'; +define(['exports', './generated-dynamic'], function (exports, dynamic) { 'use strict'; diff --git a/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/main.js b/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/main.js index 3239719cf2e..fae2c778a45 100644 --- a/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/main.js +++ b/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/main.js @@ -1,6 +1,6 @@ -define(['require', './generated-dynamic.js'], function (require, dynamic) { 'use strict'; +define(['require', './generated-dynamic'], function (require, dynamic) { 'use strict'; - Promise.all([new Promise(function (resolve, reject) { require(['./generated-dynamic.js'], resolve, reject) }), new Promise(function (resolve, reject) { require(['./generated-chunk.js'], resolve, reject) }), new Promise(function (resolve, reject) { require(['./generated-chunk2.js'], resolve, reject) })]).then( + Promise.all([new Promise(function (resolve, reject) { require(['./generated-dynamic'], resolve, reject) }), new Promise(function (resolve, reject) { require(['./generated-chunk'], resolve, reject) }), new Promise(function (resolve, reject) { require(['./generated-chunk2'], resolve, reject) })]).then( results => console.log(results, dynamic.DEP) ); diff --git a/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/amd/generated-chunk.js b/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/amd/generated-chunk.js index 4d555970c86..b0ba64ff7d0 100644 --- a/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/amd/generated-chunk.js +++ b/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/amd/generated-chunk.js @@ -1,4 +1,4 @@ -define(['exports', './generated-dynamic.js'], function (exports, dynamic) { 'use strict'; +define(['exports', './generated-dynamic'], function (exports, dynamic) { 'use strict'; diff --git a/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/amd/main.js b/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/amd/main.js index fc473ab782b..6113e054cf8 100644 --- a/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/amd/main.js +++ b/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/amd/main.js @@ -1,6 +1,6 @@ define(['require'], function (require) { 'use strict'; - new Promise(function (resolve, reject) { require(['./generated-chunk.js'], resolve, reject) }).then(result => console.log(result)); - new Promise(function (resolve, reject) { require(['./generated-dynamic.js'], resolve, reject) }).then(result => console.log(result)); + new Promise(function (resolve, reject) { require(['./generated-chunk'], resolve, reject) }).then(result => console.log(result)); + new Promise(function (resolve, reject) { require(['./generated-dynamic'], resolve, reject) }).then(result => console.log(result)); }); diff --git a/test/chunking-form/samples/manual-chunks-dynamic/_expected/amd/main.js b/test/chunking-form/samples/manual-chunks-dynamic/_expected/amd/main.js index bf87287061c..7ade37c39c9 100644 --- a/test/chunking-form/samples/manual-chunks-dynamic/_expected/amd/main.js +++ b/test/chunking-form/samples/manual-chunks-dynamic/_expected/amd/main.js @@ -1,5 +1,5 @@ define(['require'], function (require) { 'use strict'; - new Promise(function (resolve, reject) { require(['./generated-dynamic.js'], resolve, reject) }).then(({DYNAMIC_USED_BY_A}) => console.log(DYNAMIC_USED_BY_A)); + new Promise(function (resolve, reject) { require(['./generated-dynamic'], resolve, reject) }).then(({DYNAMIC_USED_BY_A}) => console.log(DYNAMIC_USED_BY_A)); }); diff --git a/test/chunking-form/samples/manual-chunks-nested/_expected/amd/main.js b/test/chunking-form/samples/manual-chunks-nested/_expected/amd/main.js index a2db4c96a66..4cfe600e533 100644 --- a/test/chunking-form/samples/manual-chunks-nested/_expected/amd/main.js +++ b/test/chunking-form/samples/manual-chunks-nested/_expected/amd/main.js @@ -1,4 +1,4 @@ -define(['./generated-manual.js'], function (__chunk_1) { 'use strict'; +define(['./generated-manual'], function (__chunk_1) { 'use strict'; console.log('main'); diff --git a/test/chunking-form/samples/manual-chunks/_expected/amd/generated-deps2and3.js b/test/chunking-form/samples/manual-chunks/_expected/amd/generated-deps2and3.js index db8359837ef..165b82f137a 100644 --- a/test/chunking-form/samples/manual-chunks/_expected/amd/generated-deps2and3.js +++ b/test/chunking-form/samples/manual-chunks/_expected/amd/generated-deps2and3.js @@ -1,4 +1,4 @@ -define(['exports', './generated-lib1.js'], function (exports, __chunk_2) { 'use strict'; +define(['exports', './generated-lib1'], function (exports, __chunk_2) { 'use strict'; function fn () { console.log('lib2 fn'); diff --git a/test/chunking-form/samples/manual-chunks/_expected/amd/main.js b/test/chunking-form/samples/manual-chunks/_expected/amd/main.js index 9b6de0df0dd..beeca173eae 100644 --- a/test/chunking-form/samples/manual-chunks/_expected/amd/main.js +++ b/test/chunking-form/samples/manual-chunks/_expected/amd/main.js @@ -1,4 +1,4 @@ -define(['./generated-deps2and3.js', './generated-lib1.js'], function (__chunk_1, __chunk_2) { 'use strict'; +define(['./generated-deps2and3', './generated-lib1'], function (__chunk_1, __chunk_2) { 'use strict'; function fn () { console.log('dep1 fn'); diff --git a/test/chunking-form/samples/missing-export-compact/_expected/amd/main.js b/test/chunking-form/samples/missing-export-compact/_expected/amd/main.js index 6b26a92f175..99e530fa9c8 100644 --- a/test/chunking-form/samples/missing-export-compact/_expected/amd/main.js +++ b/test/chunking-form/samples/missing-export-compact/_expected/amd/main.js @@ -1,2 +1,2 @@ -define(['./dep.js'],function(dep){'use strict';dep.missingFn(); +define(['./dep'],function(dep){'use strict';dep.missingFn(); dep.x(dep.missingFn);}); \ No newline at end of file diff --git a/test/chunking-form/samples/missing-export-reused-deconflicting/_expected/amd/main.js b/test/chunking-form/samples/missing-export-reused-deconflicting/_expected/amd/main.js index 771a3512c76..8fd12daee88 100644 --- a/test/chunking-form/samples/missing-export-reused-deconflicting/_expected/amd/main.js +++ b/test/chunking-form/samples/missing-export-reused-deconflicting/_expected/amd/main.js @@ -1,4 +1,4 @@ -define(['./dep1.js', './dep2.js'], function (__chunk_1, __chunk_2) { 'use strict'; +define(['./dep1', './dep2'], function (__chunk_1, __chunk_2) { 'use strict'; console.log(__chunk_1.missing1, __chunk_2.missing2, __chunk_2.previousShimmedExport); diff --git a/test/chunking-form/samples/missing-export/_expected/amd/main.js b/test/chunking-form/samples/missing-export/_expected/amd/main.js index bbdd8227b07..45cf3ece8f6 100644 --- a/test/chunking-form/samples/missing-export/_expected/amd/main.js +++ b/test/chunking-form/samples/missing-export/_expected/amd/main.js @@ -1,4 +1,4 @@ -define(['./dep.js'], function (dep) { 'use strict'; +define(['./dep'], function (dep) { 'use strict'; dep.missingFn(); dep.x(dep.missingFn, dep.missingFn); diff --git a/test/chunking-form/samples/multi-chunking/_expected/amd/main1.js b/test/chunking-form/samples/multi-chunking/_expected/amd/main1.js index 38b0814fc10..41ad8f756f1 100644 --- a/test/chunking-form/samples/multi-chunking/_expected/amd/main1.js +++ b/test/chunking-form/samples/multi-chunking/_expected/amd/main1.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js', './generated-chunk2.js'], function (__chunk_1, __chunk_2) { 'use strict'; +define(['./generated-chunk', './generated-chunk2'], function (__chunk_1, __chunk_2) { 'use strict'; console.log(__chunk_1.num + __chunk_2.num); diff --git a/test/chunking-form/samples/multi-chunking/_expected/amd/main2.js b/test/chunking-form/samples/multi-chunking/_expected/amd/main2.js index 0907bafb19c..fb0872ff799 100644 --- a/test/chunking-form/samples/multi-chunking/_expected/amd/main2.js +++ b/test/chunking-form/samples/multi-chunking/_expected/amd/main2.js @@ -1,4 +1,4 @@ -define(['./generated-chunk2.js', './generated-chunk3.js'], function (__chunk_2, __chunk_3) { 'use strict'; +define(['./generated-chunk2', './generated-chunk3'], function (__chunk_2, __chunk_3) { 'use strict'; console.log(__chunk_2.num + __chunk_3.num); diff --git a/test/chunking-form/samples/multi-chunking/_expected/amd/main3.js b/test/chunking-form/samples/multi-chunking/_expected/amd/main3.js index 28d1860b9a0..3317ef0bd37 100644 --- a/test/chunking-form/samples/multi-chunking/_expected/amd/main3.js +++ b/test/chunking-form/samples/multi-chunking/_expected/amd/main3.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js', './generated-chunk3.js'], function (__chunk_1, __chunk_3) { 'use strict'; +define(['./generated-chunk', './generated-chunk3'], function (__chunk_1, __chunk_3) { 'use strict'; console.log(__chunk_1.num + __chunk_3.num); diff --git a/test/chunking-form/samples/multiple-entry-points/_config.js b/test/chunking-form/samples/multiple-entry-points/_config.js new file mode 100644 index 00000000000..e8f588be523 --- /dev/null +++ b/test/chunking-form/samples/multiple-entry-points/_config.js @@ -0,0 +1,10 @@ +module.exports = { + description: 'handles multiple entry points with a shared dependency', + options: { + input: ['main', 'other'], + output: { + chunkFileNames: 'chunks/[name].js' + } + }, + runAmd: true +}; diff --git a/test/chunking-form/samples/multiple-entry-points/_expected/amd/chunks/chunk.js b/test/chunking-form/samples/multiple-entry-points/_expected/amd/chunks/chunk.js new file mode 100644 index 00000000000..65e59158953 --- /dev/null +++ b/test/chunking-form/samples/multiple-entry-points/_expected/amd/chunks/chunk.js @@ -0,0 +1,7 @@ +define(['exports'], function (exports) { 'use strict'; + + const sharedValue = 'shared'; + + exports.sharedValue = sharedValue; + +}); diff --git a/test/chunking-form/samples/multiple-entry-points/_expected/amd/main.js b/test/chunking-form/samples/multiple-entry-points/_expected/amd/main.js new file mode 100644 index 00000000000..e8d75a79e14 --- /dev/null +++ b/test/chunking-form/samples/multiple-entry-points/_expected/amd/main.js @@ -0,0 +1,5 @@ +define(['./chunks/chunk'], function (__chunk_1) { 'use strict'; + + assert.equal(__chunk_1.sharedValue, 'shared'); + +}); diff --git a/test/chunking-form/samples/multiple-entry-points/_expected/amd/other.js b/test/chunking-form/samples/multiple-entry-points/_expected/amd/other.js new file mode 100644 index 00000000000..1c4346af7f8 --- /dev/null +++ b/test/chunking-form/samples/multiple-entry-points/_expected/amd/other.js @@ -0,0 +1,9 @@ +define(['exports', './chunks/chunk'], function (exports, __chunk_1) { 'use strict'; + + + + exports.sharedValue = __chunk_1.sharedValue; + + Object.defineProperty(exports, '__esModule', { value: true }); + +}); diff --git a/test/chunking-form/samples/multiple-entry-points/_expected/cjs/chunks/chunk.js b/test/chunking-form/samples/multiple-entry-points/_expected/cjs/chunks/chunk.js new file mode 100644 index 00000000000..5a6d40af489 --- /dev/null +++ b/test/chunking-form/samples/multiple-entry-points/_expected/cjs/chunks/chunk.js @@ -0,0 +1,5 @@ +'use strict'; + +const sharedValue = 'shared'; + +exports.sharedValue = sharedValue; diff --git a/test/chunking-form/samples/multiple-entry-points/_expected/cjs/main.js b/test/chunking-form/samples/multiple-entry-points/_expected/cjs/main.js new file mode 100644 index 00000000000..276798be0e4 --- /dev/null +++ b/test/chunking-form/samples/multiple-entry-points/_expected/cjs/main.js @@ -0,0 +1,5 @@ +'use strict'; + +var __chunk_1 = require('./chunks/chunk.js'); + +assert.equal(__chunk_1.sharedValue, 'shared'); diff --git a/test/chunking-form/samples/multiple-entry-points/_expected/cjs/other.js b/test/chunking-form/samples/multiple-entry-points/_expected/cjs/other.js new file mode 100644 index 00000000000..bdb6a8f4c55 --- /dev/null +++ b/test/chunking-form/samples/multiple-entry-points/_expected/cjs/other.js @@ -0,0 +1,9 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +var __chunk_1 = require('./chunks/chunk.js'); + + + +exports.sharedValue = __chunk_1.sharedValue; diff --git a/test/chunking-form/samples/multiple-entry-points/_expected/es/chunks/chunk.js b/test/chunking-form/samples/multiple-entry-points/_expected/es/chunks/chunk.js new file mode 100644 index 00000000000..94dca2d35b3 --- /dev/null +++ b/test/chunking-form/samples/multiple-entry-points/_expected/es/chunks/chunk.js @@ -0,0 +1,3 @@ +const sharedValue = 'shared'; + +export { sharedValue as a }; diff --git a/test/chunking-form/samples/multiple-entry-points/_expected/es/main.js b/test/chunking-form/samples/multiple-entry-points/_expected/es/main.js new file mode 100644 index 00000000000..793646ecb4c --- /dev/null +++ b/test/chunking-form/samples/multiple-entry-points/_expected/es/main.js @@ -0,0 +1,3 @@ +import { a as sharedValue } from './chunks/chunk.js'; + +assert.equal(sharedValue, 'shared'); diff --git a/test/chunking-form/samples/multiple-entry-points/_expected/es/other.js b/test/chunking-form/samples/multiple-entry-points/_expected/es/other.js new file mode 100644 index 00000000000..8e3d65b216d --- /dev/null +++ b/test/chunking-form/samples/multiple-entry-points/_expected/es/other.js @@ -0,0 +1 @@ +export { a as sharedValue } from './chunks/chunk.js'; diff --git a/test/chunking-form/samples/multiple-entry-points/_expected/system/chunks/chunk.js b/test/chunking-form/samples/multiple-entry-points/_expected/system/chunks/chunk.js new file mode 100644 index 00000000000..f4a5045db1a --- /dev/null +++ b/test/chunking-form/samples/multiple-entry-points/_expected/system/chunks/chunk.js @@ -0,0 +1,10 @@ +System.register([], function (exports, module) { + 'use strict'; + return { + execute: function () { + + const sharedValue = exports('a', 'shared'); + + } + }; +}); diff --git a/test/chunking-form/samples/multiple-entry-points/_expected/system/main.js b/test/chunking-form/samples/multiple-entry-points/_expected/system/main.js new file mode 100644 index 00000000000..11b81781952 --- /dev/null +++ b/test/chunking-form/samples/multiple-entry-points/_expected/system/main.js @@ -0,0 +1,14 @@ +System.register(['./chunks/chunk.js'], function (exports, module) { + 'use strict'; + var sharedValue; + return { + setters: [function (module) { + sharedValue = module.a; + }], + execute: function () { + + assert.equal(sharedValue, 'shared'); + + } + }; +}); diff --git a/test/chunking-form/samples/multiple-entry-points/_expected/system/other.js b/test/chunking-form/samples/multiple-entry-points/_expected/system/other.js new file mode 100644 index 00000000000..81bcc1cf806 --- /dev/null +++ b/test/chunking-form/samples/multiple-entry-points/_expected/system/other.js @@ -0,0 +1,13 @@ +System.register(['./chunks/chunk.js'], function (exports, module) { + 'use strict'; + return { + setters: [function (module) { + exports('sharedValue', module.a); + }], + execute: function () { + + + + } + }; +}); diff --git a/test/chunking-form/samples/multiple-entry-points/main.js b/test/chunking-form/samples/multiple-entry-points/main.js new file mode 100644 index 00000000000..39653f0b622 --- /dev/null +++ b/test/chunking-form/samples/multiple-entry-points/main.js @@ -0,0 +1,3 @@ +import { sharedValue } from './shared'; + +assert.equal(sharedValue, 'shared'); diff --git a/test/chunking-form/samples/multiple-entry-points/other.js b/test/chunking-form/samples/multiple-entry-points/other.js new file mode 100644 index 00000000000..39347a6c304 --- /dev/null +++ b/test/chunking-form/samples/multiple-entry-points/other.js @@ -0,0 +1 @@ +export { sharedValue } from './shared'; diff --git a/test/chunking-form/samples/multiple-entry-points/shared.js b/test/chunking-form/samples/multiple-entry-points/shared.js new file mode 100644 index 00000000000..7a5200e8ec7 --- /dev/null +++ b/test/chunking-form/samples/multiple-entry-points/shared.js @@ -0,0 +1 @@ +export const sharedValue = 'shared'; diff --git a/test/chunking-form/samples/namespace-imports-from-chunks/_expected/amd/main2.js b/test/chunking-form/samples/namespace-imports-from-chunks/_expected/amd/main2.js index 5dcc1bb7e82..40c8ca3127f 100644 --- a/test/chunking-form/samples/namespace-imports-from-chunks/_expected/amd/main2.js +++ b/test/chunking-form/samples/namespace-imports-from-chunks/_expected/amd/main2.js @@ -1,4 +1,4 @@ -define(['./main1.js'], function (main1) { 'use strict'; +define(['./main1'], function (main1) { 'use strict'; console.log( main1.p ); diff --git a/test/chunking-form/samples/namespace-object-import/_expected/amd/main1.js b/test/chunking-form/samples/namespace-object-import/_expected/amd/main1.js index 2fef00ce740..78484e848f0 100644 --- a/test/chunking-form/samples/namespace-object-import/_expected/amd/main1.js +++ b/test/chunking-form/samples/namespace-object-import/_expected/amd/main1.js @@ -1,4 +1,4 @@ -define(['./generated-main2.js'], function (main2) { 'use strict'; +define(['./generated-main2'], function (main2) { 'use strict'; console.log(main2.a); diff --git a/test/chunking-form/samples/namespace-object-import/_expected/amd/main2.js b/test/chunking-form/samples/namespace-object-import/_expected/amd/main2.js index 9558090c768..58cbd115137 100644 --- a/test/chunking-form/samples/namespace-object-import/_expected/amd/main2.js +++ b/test/chunking-form/samples/namespace-object-import/_expected/amd/main2.js @@ -1,4 +1,4 @@ -define(['exports', './generated-main2.js'], function (exports, main2) { 'use strict'; +define(['exports', './generated-main2'], function (exports, main2) { 'use strict'; diff --git a/test/chunking-form/samples/namespace-reexport-name-conflict/_expected/amd/generated-chunk2.js b/test/chunking-form/samples/namespace-reexport-name-conflict/_expected/amd/generated-chunk2.js index 72fef366cb5..2d9441cbf54 100644 --- a/test/chunking-form/samples/namespace-reexport-name-conflict/_expected/amd/generated-chunk2.js +++ b/test/chunking-form/samples/namespace-reexport-name-conflict/_expected/amd/generated-chunk2.js @@ -1,4 +1,4 @@ -define(['exports', './generated-chunk.js', 'external'], function (exports, __chunk_1, external) { 'use strict'; +define(['exports', './generated-chunk', 'external'], function (exports, __chunk_1, external) { 'use strict'; console.log(external.reexported); diff --git a/test/chunking-form/samples/namespace-reexport-name-conflict/_expected/amd/main1.js b/test/chunking-form/samples/namespace-reexport-name-conflict/_expected/amd/main1.js index 3d3a5144d0b..51772b15d56 100644 --- a/test/chunking-form/samples/namespace-reexport-name-conflict/_expected/amd/main1.js +++ b/test/chunking-form/samples/namespace-reexport-name-conflict/_expected/amd/main1.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js', 'external', './generated-chunk2.js'], function (__chunk_1, external, __chunk_2) { 'use strict'; +define(['./generated-chunk', 'external', './generated-chunk2'], function (__chunk_1, external, __chunk_2) { 'use strict'; console.log(__chunk_2.lib); diff --git a/test/chunking-form/samples/namespace-reexport-name-conflict/_expected/amd/main2.js b/test/chunking-form/samples/namespace-reexport-name-conflict/_expected/amd/main2.js index 3ed815db8ae..cf6f7207880 100644 --- a/test/chunking-form/samples/namespace-reexport-name-conflict/_expected/amd/main2.js +++ b/test/chunking-form/samples/namespace-reexport-name-conflict/_expected/amd/main2.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js', 'external', './generated-chunk2.js'], function (__chunk_1, external, __chunk_2) { 'use strict'; +define(['./generated-chunk', 'external', './generated-chunk2'], function (__chunk_1, external, __chunk_2) { 'use strict'; console.log(__chunk_1.reexported); diff --git a/test/chunking-form/samples/namespace-reexport-name-conflict/_expected/amd/main3.js b/test/chunking-form/samples/namespace-reexport-name-conflict/_expected/amd/main3.js index 7829aea9079..80869868e48 100644 --- a/test/chunking-form/samples/namespace-reexport-name-conflict/_expected/amd/main3.js +++ b/test/chunking-form/samples/namespace-reexport-name-conflict/_expected/amd/main3.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; +define(['./generated-chunk'], function (__chunk_1) { 'use strict'; diff --git a/test/chunking-form/samples/namespace-reexports/_expected/amd/generated-index.js b/test/chunking-form/samples/namespace-reexports/_expected/amd/generated-index.js index cbc8db134cb..1337d2c2adb 100644 --- a/test/chunking-form/samples/namespace-reexports/_expected/amd/generated-index.js +++ b/test/chunking-form/samples/namespace-reexports/_expected/amd/generated-index.js @@ -1,4 +1,4 @@ -define(['exports', './hsl2hsv.js'], function (exports, hsl2hsv$1) { 'use strict'; +define(['exports', './hsl2hsv'], function (exports, hsl2hsv$1) { 'use strict'; var hsl2hsv = 'asdf'; diff --git a/test/chunking-form/samples/namespace-reexports/_expected/amd/index.js b/test/chunking-form/samples/namespace-reexports/_expected/amd/index.js index c51c47b4df8..1c0eff2a0ca 100644 --- a/test/chunking-form/samples/namespace-reexports/_expected/amd/index.js +++ b/test/chunking-form/samples/namespace-reexports/_expected/amd/index.js @@ -1,4 +1,4 @@ -define(['exports', './hsl2hsv.js', './generated-index.js'], function (exports, hsl2hsv$1, index) { 'use strict'; +define(['exports', './hsl2hsv', './generated-index'], function (exports, hsl2hsv$1, index) { 'use strict'; diff --git a/test/chunking-form/samples/namespace-reexports/_expected/amd/main.js b/test/chunking-form/samples/namespace-reexports/_expected/amd/main.js index 71dd02c2f28..ab833f3837e 100644 --- a/test/chunking-form/samples/namespace-reexports/_expected/amd/main.js +++ b/test/chunking-form/samples/namespace-reexports/_expected/amd/main.js @@ -1,4 +1,4 @@ -define(['exports', './hsl2hsv.js', './generated-index.js'], function (exports, hsl2hsv$1, index) { 'use strict'; +define(['exports', './hsl2hsv', './generated-index'], function (exports, hsl2hsv$1, index) { 'use strict'; console.log(hsl2hsv$1.p); var main = new Map(Object.entries(index.lib)); diff --git a/test/chunking-form/samples/namespace-retracing/_expected/amd/main-a.js b/test/chunking-form/samples/namespace-retracing/_expected/amd/main-a.js index 281c65d538f..b5a0e083248 100644 --- a/test/chunking-form/samples/namespace-retracing/_expected/amd/main-a.js +++ b/test/chunking-form/samples/namespace-retracing/_expected/amd/main-a.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; +define(['./generated-chunk'], function (__chunk_1) { 'use strict'; __chunk_1.Other.doSomething(); __chunk_1.Broken.doSomething(); diff --git a/test/chunking-form/samples/namespace-retracing/_expected/amd/main-b.js b/test/chunking-form/samples/namespace-retracing/_expected/amd/main-b.js index 9d265d80d18..e2d4985dc13 100644 --- a/test/chunking-form/samples/namespace-retracing/_expected/amd/main-b.js +++ b/test/chunking-form/samples/namespace-retracing/_expected/amd/main-b.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; +define(['./generated-chunk'], function (__chunk_1) { 'use strict'; __chunk_1.Other.doSomething(); diff --git a/test/chunking-form/samples/namespace-tracing/_expected/amd/generated-chunk2.js b/test/chunking-form/samples/namespace-tracing/_expected/amd/generated-chunk2.js index c31c4ebb3c6..0a3e8b14711 100644 --- a/test/chunking-form/samples/namespace-tracing/_expected/amd/generated-chunk2.js +++ b/test/chunking-form/samples/namespace-tracing/_expected/amd/generated-chunk2.js @@ -1,4 +1,4 @@ -define(['exports', './generated-chunk.js'], function (exports, __chunk_1) { 'use strict'; +define(['exports', './generated-chunk'], function (exports, __chunk_1) { 'use strict'; function foo() { console.log('foo'); diff --git a/test/chunking-form/samples/namespace-tracing/_expected/amd/generated-chunk3.js b/test/chunking-form/samples/namespace-tracing/_expected/amd/generated-chunk3.js index 78fb02a11f2..6d8f8bf796c 100644 --- a/test/chunking-form/samples/namespace-tracing/_expected/amd/generated-chunk3.js +++ b/test/chunking-form/samples/namespace-tracing/_expected/amd/generated-chunk3.js @@ -1,4 +1,4 @@ -define(['exports', './generated-chunk.js'], function (exports, __chunk_1) { 'use strict'; +define(['exports', './generated-chunk'], function (exports, __chunk_1) { 'use strict'; function bar() { console.log('bar'); diff --git a/test/chunking-form/samples/namespace-tracing/_expected/amd/main-a.js b/test/chunking-form/samples/namespace-tracing/_expected/amd/main-a.js index 906d540ccd9..116300fc7e0 100644 --- a/test/chunking-form/samples/namespace-tracing/_expected/amd/main-a.js +++ b/test/chunking-form/samples/namespace-tracing/_expected/amd/main-a.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js', './generated-chunk2.js'], function (__chunk_1, __chunk_2) { 'use strict'; +define(['./generated-chunk', './generated-chunk2'], function (__chunk_1, __chunk_2) { 'use strict'; __chunk_2.foo(); __chunk_1.broken(); diff --git a/test/chunking-form/samples/namespace-tracing/_expected/amd/main-b.js b/test/chunking-form/samples/namespace-tracing/_expected/amd/main-b.js index 35f5d479917..0f2eec7ca6d 100644 --- a/test/chunking-form/samples/namespace-tracing/_expected/amd/main-b.js +++ b/test/chunking-form/samples/namespace-tracing/_expected/amd/main-b.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js', './generated-chunk2.js', './generated-chunk3.js'], function (__chunk_1, __chunk_2, __chunk_3) { 'use strict'; +define(['./generated-chunk', './generated-chunk2', './generated-chunk3'], function (__chunk_1, __chunk_2, __chunk_3) { 'use strict'; __chunk_2.foo(); __chunk_1.broken(); diff --git a/test/chunking-form/samples/namespace-tracing/_expected/amd/main-c.js b/test/chunking-form/samples/namespace-tracing/_expected/amd/main-c.js index a9bad503da0..28477f9fa63 100644 --- a/test/chunking-form/samples/namespace-tracing/_expected/amd/main-c.js +++ b/test/chunking-form/samples/namespace-tracing/_expected/amd/main-c.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js', './generated-chunk3.js'], function (__chunk_1, __chunk_3) { 'use strict'; +define(['./generated-chunk', './generated-chunk3'], function (__chunk_1, __chunk_3) { 'use strict'; __chunk_3.bar(); __chunk_1.broken(); diff --git a/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-chunk.js b/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-chunk.js index 986051119fc..1bfe4471eb9 100644 --- a/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-chunk.js +++ b/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-chunk.js @@ -1,6 +1,6 @@ define(['require'], function (require) { 'use strict'; - new Promise(function (resolve, reject) { require(['./generated-chunk2.js'], resolve, reject) }); + new Promise(function (resolve, reject) { require(['./generated-chunk2'], resolve, reject) }); console.log('dynamic1'); }); diff --git a/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-chunk2.js b/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-chunk2.js index 1b30cdd57b8..df13602628f 100644 --- a/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-chunk2.js +++ b/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-chunk2.js @@ -1,6 +1,6 @@ define(['require'], function (require) { 'use strict'; - new Promise(function (resolve, reject) { require(['./generated-chunk3.js'], resolve, reject) }); + new Promise(function (resolve, reject) { require(['./generated-chunk3'], resolve, reject) }); console.log('dynamic2'); }); diff --git a/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-chunk3.js b/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-chunk3.js index 429e468a258..b949b96f311 100644 --- a/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-chunk3.js +++ b/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-chunk3.js @@ -1,6 +1,6 @@ define(['require'], function (require) { 'use strict'; - new Promise(function (resolve, reject) { require(['./generated-chunk4.js'], resolve, reject) }); + new Promise(function (resolve, reject) { require(['./generated-chunk4'], resolve, reject) }); console.log('dynamic3'); }); diff --git a/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-chunk4.js b/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-chunk4.js index fd70ed340c9..d054038fdc6 100644 --- a/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-chunk4.js +++ b/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-chunk4.js @@ -1,6 +1,6 @@ define(['require'], function (require) { 'use strict'; - new Promise(function (resolve, reject) { require(['./generated-chunk5.js'], resolve, reject) }); + new Promise(function (resolve, reject) { require(['./generated-chunk5'], resolve, reject) }); console.log('dynamic4'); }); diff --git a/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/main.js b/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/main.js index c8a31868ae7..01d6eb9470d 100644 --- a/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/main.js +++ b/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/main.js @@ -1,6 +1,6 @@ define(['require'], function (require) { 'use strict'; - new Promise(function (resolve, reject) { require(['./generated-chunk.js'], resolve, reject) }); + new Promise(function (resolve, reject) { require(['./generated-chunk'], resolve, reject) }); console.log('main'); }); diff --git a/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/_virtual/other.js b/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/_virtual/other.js index 2f18de25c3c..598a5312942 100644 --- a/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/_virtual/other.js +++ b/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/_virtual/other.js @@ -1,4 +1,4 @@ -define(['exports', '../other.js'], function (exports, __chunk_1) { 'use strict'; +define(['exports', '../other'], function (exports, __chunk_1) { 'use strict'; diff --git a/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/commonjs.js b/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/commonjs.js index 84e944e5ced..005be973ac7 100644 --- a/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/commonjs.js +++ b/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/commonjs.js @@ -1,4 +1,4 @@ -define(['exports', 'external', './other.js', './_virtual/_commonjs-external-external', './_virtual/other.js'], function (exports, external, __chunk_1, __chunk_2, __chunk_3) { 'use strict'; +define(['exports', 'external', './other', './_virtual/_commonjs-external-external', './_virtual/other'], function (exports, external, __chunk_1, __chunk_2, __chunk_3) { 'use strict'; external = external && external.hasOwnProperty('default') ? external['default'] : external; diff --git a/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/main.js b/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/main.js index a8edbd239a5..d266f1602d4 100644 --- a/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/main.js +++ b/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/main.js @@ -1,4 +1,4 @@ -define(['external', './commonjs.js'], function (external, __chunk_4) { 'use strict'; +define(['external', './commonjs'], function (external, __chunk_4) { 'use strict'; external = external && external.hasOwnProperty('default') ? external['default'] : external; diff --git a/test/chunking-form/samples/preserve-modules-dynamic-imports/_expected/amd/main.js b/test/chunking-form/samples/preserve-modules-dynamic-imports/_expected/amd/main.js index 83b30a7c2ee..2ec310c64aa 100644 --- a/test/chunking-form/samples/preserve-modules-dynamic-imports/_expected/amd/main.js +++ b/test/chunking-form/samples/preserve-modules-dynamic-imports/_expected/amd/main.js @@ -1,5 +1,5 @@ define(['require'], function (require) { 'use strict'; - new Promise(function (resolve, reject) { require(['./dynamic-included.js'], resolve, reject) }).then(result => console.log(result)); + new Promise(function (resolve, reject) { require(['./dynamic-included'], resolve, reject) }).then(result => console.log(result)); }); diff --git a/test/chunking-form/samples/preserve-modules-dynamic-namespace/_expected/amd/m1.js b/test/chunking-form/samples/preserve-modules-dynamic-namespace/_expected/amd/m1.js index 0788bf47212..c298602724e 100644 --- a/test/chunking-form/samples/preserve-modules-dynamic-namespace/_expected/amd/m1.js +++ b/test/chunking-form/samples/preserve-modules-dynamic-namespace/_expected/amd/m1.js @@ -1,4 +1,4 @@ -define(['exports', './m2.js', './m3.js'], function (exports, __chunk_1, __chunk_2) { 'use strict'; +define(['exports', './m2', './m3'], function (exports, __chunk_1, __chunk_2) { 'use strict'; diff --git a/test/chunking-form/samples/preserve-modules-dynamic-namespace/_expected/amd/main.js b/test/chunking-form/samples/preserve-modules-dynamic-namespace/_expected/amd/main.js index d2ddab26e51..72e7481571d 100644 --- a/test/chunking-form/samples/preserve-modules-dynamic-namespace/_expected/amd/main.js +++ b/test/chunking-form/samples/preserve-modules-dynamic-namespace/_expected/amd/main.js @@ -1,4 +1,4 @@ -define(['./m1.js'], function (__chunk_3) { 'use strict'; +define(['./m1'], function (__chunk_3) { 'use strict'; console.log(__chunk_3); diff --git a/test/chunking-form/samples/preserve-modules-empty/_expected/amd/main.js b/test/chunking-form/samples/preserve-modules-empty/_expected/amd/main.js index ec2c914ddc2..1ed84f69b0f 100644 --- a/test/chunking-form/samples/preserve-modules-empty/_expected/amd/main.js +++ b/test/chunking-form/samples/preserve-modules-empty/_expected/amd/main.js @@ -1,4 +1,4 @@ -define(['./two.js'], function (__chunk_1) { 'use strict'; +define(['./two'], function (__chunk_1) { 'use strict'; window.APP = { a: __chunk_1.default }; diff --git a/test/chunking-form/samples/preserve-modules-export-alias/_expected/amd/main1.js b/test/chunking-form/samples/preserve-modules-export-alias/_expected/amd/main1.js index 8007ede60f3..eca24c0e300 100644 --- a/test/chunking-form/samples/preserve-modules-export-alias/_expected/amd/main1.js +++ b/test/chunking-form/samples/preserve-modules-export-alias/_expected/amd/main1.js @@ -1,4 +1,4 @@ -define(['exports', './dep.js'], function (exports, __chunk_1) { 'use strict'; +define(['exports', './dep'], function (exports, __chunk_1) { 'use strict'; diff --git a/test/chunking-form/samples/preserve-modules-export-alias/_expected/amd/main2.js b/test/chunking-form/samples/preserve-modules-export-alias/_expected/amd/main2.js index d02f9269af5..ce0c6142f0d 100644 --- a/test/chunking-form/samples/preserve-modules-export-alias/_expected/amd/main2.js +++ b/test/chunking-form/samples/preserve-modules-export-alias/_expected/amd/main2.js @@ -1,4 +1,4 @@ -define(['exports', './dep.js'], function (exports, __chunk_1) { 'use strict'; +define(['exports', './dep'], function (exports, __chunk_1) { 'use strict'; diff --git a/test/chunking-form/samples/preserve-modules-non-entry-imports/_expected/amd/main.js b/test/chunking-form/samples/preserve-modules-non-entry-imports/_expected/amd/main.js index a80d55726c2..35ea0e4c3f7 100644 --- a/test/chunking-form/samples/preserve-modules-non-entry-imports/_expected/amd/main.js +++ b/test/chunking-form/samples/preserve-modules-non-entry-imports/_expected/amd/main.js @@ -1,4 +1,4 @@ -define(['./dep2.js'], function (__chunk_1) { 'use strict'; +define(['./dep2'], function (__chunk_1) { 'use strict'; diff --git a/test/chunking-form/samples/preserve-modules-reaching-outside/_expected/amd/lib/main.js b/test/chunking-form/samples/preserve-modules-reaching-outside/_expected/amd/lib/main.js index cca8c1fcfa9..0562844ec4c 100644 --- a/test/chunking-form/samples/preserve-modules-reaching-outside/_expected/amd/lib/main.js +++ b/test/chunking-form/samples/preserve-modules-reaching-outside/_expected/amd/lib/main.js @@ -1,4 +1,4 @@ -define(['../dep.js'], function (__chunk_1) { 'use strict'; +define(['../dep'], function (__chunk_1) { 'use strict'; class Main { constructor () { diff --git a/test/chunking-form/samples/preserve-modules/_expected/amd/deps/dep2.js b/test/chunking-form/samples/preserve-modules/_expected/amd/deps/dep2.js index 5d99aeae9fe..babc3674287 100644 --- a/test/chunking-form/samples/preserve-modules/_expected/amd/deps/dep2.js +++ b/test/chunking-form/samples/preserve-modules/_expected/amd/deps/dep2.js @@ -1,4 +1,4 @@ -define(['exports', '../lib/lib2.js'], function (exports, __chunk_2) { 'use strict'; +define(['exports', '../lib/lib2'], function (exports, __chunk_2) { 'use strict'; function fn () { __chunk_2.fn(); diff --git a/test/chunking-form/samples/preserve-modules/_expected/amd/deps/dep3.js b/test/chunking-form/samples/preserve-modules/_expected/amd/deps/dep3.js index 4b2f9d41fe8..b3a7e253194 100644 --- a/test/chunking-form/samples/preserve-modules/_expected/amd/deps/dep3.js +++ b/test/chunking-form/samples/preserve-modules/_expected/amd/deps/dep3.js @@ -1,4 +1,4 @@ -define(['exports', '../lib/lib1.js'], function (exports, __chunk_4) { 'use strict'; +define(['exports', '../lib/lib1'], function (exports, __chunk_4) { 'use strict'; function fn () { __chunk_4.fn(); diff --git a/test/chunking-form/samples/preserve-modules/_expected/amd/main1.js b/test/chunking-form/samples/preserve-modules/_expected/amd/main1.js index 260cfa9dfef..59c09092c0b 100644 --- a/test/chunking-form/samples/preserve-modules/_expected/amd/main1.js +++ b/test/chunking-form/samples/preserve-modules/_expected/amd/main1.js @@ -1,4 +1,4 @@ -define(['./deps/dep1.js', './deps/dep2.js'], function (__chunk_1, __chunk_3) { 'use strict'; +define(['./deps/dep1', './deps/dep2'], function (__chunk_1, __chunk_3) { 'use strict'; class Main1 { constructor () { diff --git a/test/chunking-form/samples/preserve-modules/_expected/amd/main2.js b/test/chunking-form/samples/preserve-modules/_expected/amd/main2.js index 6e00984a2d4..4c0aa3659bf 100644 --- a/test/chunking-form/samples/preserve-modules/_expected/amd/main2.js +++ b/test/chunking-form/samples/preserve-modules/_expected/amd/main2.js @@ -1,4 +1,4 @@ -define(['./deps/dep2.js', './deps/dep3.js'], function (__chunk_3, __chunk_5) { 'use strict'; +define(['./deps/dep2', './deps/dep3'], function (__chunk_3, __chunk_5) { 'use strict'; class Main2 { constructor () { diff --git a/test/chunking-form/samples/reexport-shortpaths/_expected/amd/main1.js b/test/chunking-form/samples/reexport-shortpaths/_expected/amd/main1.js index e80b94da055..f1a34bad61f 100644 --- a/test/chunking-form/samples/reexport-shortpaths/_expected/amd/main1.js +++ b/test/chunking-form/samples/reexport-shortpaths/_expected/amd/main1.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; +define(['./generated-chunk'], function (__chunk_1) { 'use strict'; diff --git a/test/chunking-form/samples/reexport-shortpaths/_expected/amd/main2.js b/test/chunking-form/samples/reexport-shortpaths/_expected/amd/main2.js index 7829aea9079..80869868e48 100644 --- a/test/chunking-form/samples/reexport-shortpaths/_expected/amd/main2.js +++ b/test/chunking-form/samples/reexport-shortpaths/_expected/amd/main2.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; +define(['./generated-chunk'], function (__chunk_1) { 'use strict'; diff --git a/test/chunking-form/samples/reexport-shortpaths/_expected/amd/main3.js b/test/chunking-form/samples/reexport-shortpaths/_expected/amd/main3.js index 7829aea9079..80869868e48 100644 --- a/test/chunking-form/samples/reexport-shortpaths/_expected/amd/main3.js +++ b/test/chunking-form/samples/reexport-shortpaths/_expected/amd/main3.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; +define(['./generated-chunk'], function (__chunk_1) { 'use strict'; diff --git a/test/chunking-form/samples/sanitize-internal-exports/_expected/amd/generated-chunk2.js b/test/chunking-form/samples/sanitize-internal-exports/_expected/amd/generated-chunk2.js index 11ea24da7fa..e42b35f00ff 100644 --- a/test/chunking-form/samples/sanitize-internal-exports/_expected/amd/generated-chunk2.js +++ b/test/chunking-form/samples/sanitize-internal-exports/_expected/amd/generated-chunk2.js @@ -1,4 +1,4 @@ -define(['exports', './generated-chunk.js'], function (exports, __chunk_1) { 'use strict'; +define(['exports', './generated-chunk'], function (exports, __chunk_1) { 'use strict'; var lazy = () => __chunk_1.v1; diff --git a/test/chunking-form/samples/sanitize-internal-exports/_expected/amd/main.js b/test/chunking-form/samples/sanitize-internal-exports/_expected/amd/main.js index f0e05ca8570..664244c36b1 100644 --- a/test/chunking-form/samples/sanitize-internal-exports/_expected/amd/main.js +++ b/test/chunking-form/samples/sanitize-internal-exports/_expected/amd/main.js @@ -1,6 +1,6 @@ -define(['require', 'exports', './generated-chunk.js'], function (require, exports, __chunk_1) { 'use strict'; +define(['require', 'exports', './generated-chunk'], function (require, exports, __chunk_1) { 'use strict'; - const lazy = new Promise(function (resolve, reject) { require(['./generated-chunk2.js'], resolve, reject) }); + const lazy = new Promise(function (resolve, reject) { require(['./generated-chunk2'], resolve, reject) }); exports.v1 = __chunk_1.v1; exports.v10 = __chunk_1.v10; diff --git a/test/chunking-form/samples/system-exports-wrap-pure-annotation/_expected/amd/main1.js b/test/chunking-form/samples/system-exports-wrap-pure-annotation/_expected/amd/main1.js index 47e0f71b87d..4d9e69640e1 100644 --- a/test/chunking-form/samples/system-exports-wrap-pure-annotation/_expected/amd/main1.js +++ b/test/chunking-form/samples/system-exports-wrap-pure-annotation/_expected/amd/main1.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; +define(['./generated-chunk'], function (__chunk_1) { 'use strict'; console.log('1', __chunk_1.dep); diff --git a/test/chunking-form/samples/system-exports-wrap-pure-annotation/_expected/amd/main2.js b/test/chunking-form/samples/system-exports-wrap-pure-annotation/_expected/amd/main2.js index d4fbe558080..b493172d6f7 100644 --- a/test/chunking-form/samples/system-exports-wrap-pure-annotation/_expected/amd/main2.js +++ b/test/chunking-form/samples/system-exports-wrap-pure-annotation/_expected/amd/main2.js @@ -1,4 +1,4 @@ -define(['./generated-chunk.js'], function (__chunk_1) { 'use strict'; +define(['./generated-chunk'], function (__chunk_1) { 'use strict'; console.log('2', __chunk_1.dep); diff --git a/test/form/samples/relative-external-with-global/_expected/amd.js b/test/form/samples/relative-external-with-global/_expected/amd.js index 0520af02768..084748c64a2 100644 --- a/test/form/samples/relative-external-with-global/_expected/amd.js +++ b/test/form/samples/relative-external-with-global/_expected/amd.js @@ -1,4 +1,4 @@ -define(['./lib/throttle.js'], function (throttle) { 'use strict'; +define(['./lib/throttle'], function (throttle) { 'use strict'; throttle = throttle && throttle.hasOwnProperty('default') ? throttle['default'] : throttle; @@ -8,4 +8,4 @@ define(['./lib/throttle.js'], function (throttle) { 'use strict'; window.addEventListener( 'mousemove', throttle ); -}); \ No newline at end of file +}); diff --git a/test/form/samples/relative-external-with-global/_expected/cjs.js b/test/form/samples/relative-external-with-global/_expected/cjs.js index 1b74d5687f4..7ae442850ea 100644 --- a/test/form/samples/relative-external-with-global/_expected/cjs.js +++ b/test/form/samples/relative-external-with-global/_expected/cjs.js @@ -8,4 +8,4 @@ const fn = throttle( () => { console.log( '.' ); }, 500 ); -window.addEventListener( 'mousemove', throttle ); \ No newline at end of file +window.addEventListener( 'mousemove', throttle ); diff --git a/test/form/samples/relative-external-with-global/_expected/es.js b/test/form/samples/relative-external-with-global/_expected/es.js index fe8f7cf3d40..750ac953c06 100644 --- a/test/form/samples/relative-external-with-global/_expected/es.js +++ b/test/form/samples/relative-external-with-global/_expected/es.js @@ -4,4 +4,4 @@ const fn = throttle( () => { console.log( '.' ); }, 500 ); -window.addEventListener( 'mousemove', throttle ); \ No newline at end of file +window.addEventListener( 'mousemove', throttle ); From 95438f80e45c6654ec3c7bebd163f908b9df5b97 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Sun, 21 Apr 2019 11:09:13 +0200 Subject: [PATCH 37/60] Use generated chunk naming scheme for emitted chunks and rename context function to `emitChunk` --- src/Graph.ts | 2 +- src/Module.ts | 2 +- src/ModuleLoader.ts | 6 ++++-- src/rollup/types.d.ts | 4 ++-- src/utils/assignChunkIds.ts | 9 +++++---- src/utils/pluginDriver.ts | 4 ++-- .../samples/configure-file-url/_config.js | 2 +- .../configure-file-url/_expected/amd/chunk.js | 5 ----- .../configure-file-url/_expected/amd/main.js | 4 ++-- .../_expected/amd/nested/chunk.js | 8 ++------ .../_expected/amd/nested/chunk2.js | 9 +++++++++ .../configure-file-url/_expected/cjs/chunk.js | 3 --- .../configure-file-url/_expected/cjs/main.js | 4 ++-- .../_expected/cjs/nested/chunk.js | 6 +----- .../_expected/cjs/nested/chunk2.js | 7 +++++++ .../configure-file-url/_expected/es/chunk.js | 1 - .../configure-file-url/_expected/es/main.js | 4 ++-- .../_expected/es/nested/chunk.js | 5 +---- .../_expected/es/nested/chunk2.js | 4 ++++ .../_expected/system/chunk.js | 10 ---------- .../_expected/system/main.js | 4 ++-- .../_expected/system/nested/chunk.js | 3 +-- .../_expected/system/nested/chunk2.js | 11 ++++++++++ .../_config.js | 6 +++--- .../_expected/amd/first-main.js | 5 +++++ .../_expected/amd/generated-dep.js} | 0 .../_expected/amd/second-main.js | 5 +++++ .../_expected/cjs/first-main.js | 2 +- .../_expected/cjs/generated-dep.js} | 0 .../_expected/cjs/second-main.js | 2 +- .../_expected/es/first-main.js | 3 +++ .../_expected/es/generated-dep.js} | 0 .../_expected/es/second-main.js | 3 +++ .../_expected/system/first-main.js | 2 +- .../_expected/system/generated-dep.js} | 0 .../_expected/system/second-main.js | 2 +- .../dep.js | 0 .../main1.js | 0 .../main2.js | 0 .../_config.js | 6 +++--- .../_expected/amd/generated-build-starter.js | 0 .../_expected/amd/generated-buildStart.js} | 0 .../_expected/amd/main.js | 0 .../_expected/cjs/generated-build-starter.js | 0 .../_expected/cjs/generated-buildStart.js} | 0 .../_expected/cjs/main.js | 0 .../_expected/es/generated-build-starter.js | 0 .../_expected/es/generated-buildStart.js} | 0 .../_expected/es/main.js | 0 .../system/generated-build-starter.js | 0 .../_expected/system/generated-buildStart.js} | 0 .../_expected/system/main.js | 0 .../buildStart.js | 0 .../dep.js | 0 .../main.js | 0 .../_config.js | 20 ++++++++++++------- .../_expected/amd/chunks/chunk.js | 0 .../_expected/amd/chunks/chunk2.js | 2 +- .../_expected/amd/chunks/worker-proxy.js | 2 ++ .../_expected/amd/chunks/worker.js | 5 +++++ .../_expected/amd/main.js | 2 +- .../_expected/cjs/chunks/chunk.js | 0 .../_expected/cjs/chunks/chunk2.js | 2 +- .../_expected/cjs/chunks}/worker-proxy.js | 0 .../_expected/cjs/chunks}/worker.js | 2 +- .../_expected/cjs/main.js | 2 +- .../_expected/es/chunks/chunk.js | 0 .../_expected/es/chunks/chunk2.js | 2 +- .../_expected/es/chunks}/worker-proxy.js | 0 .../_expected/es/chunks/worker.js | 3 +++ .../_expected/es/main.js | 2 +- .../_expected/system/chunks/chunk.js | 0 .../_expected/system/chunks/chunk2.js | 2 +- .../_expected/system/chunks/worker-proxy.js | 2 ++ .../_expected/system/chunks}/worker.js | 2 +- .../_expected/system/main.js | 2 +- .../index-amd.html | 0 .../index-system.html | 0 .../main.js | 0 .../shared.js | 0 .../worker.js | 0 .../samples/emit-chunk/_config.js | 17 ++++++++++++++++ .../_expected/amd/generated-buildStart.js} | 0 .../_expected/amd/generated-chunk.js | 0 .../_expected/amd/main.js | 0 .../_expected/cjs/generated-buildStart.js} | 0 .../_expected/cjs/generated-chunk.js | 0 .../_expected/cjs/main.js | 0 .../_expected/es/generated-buildStart.js} | 0 .../_expected/es/generated-chunk.js | 0 .../_expected/es/main.js | 0 .../_expected/system/generated-buildStart.js} | 0 .../_expected/system/generated-chunk.js | 0 .../_expected/system/main.js | 0 .../buildStart.js | 0 .../dep.js | 0 .../{emit-entry-chunk => emit-chunk}/main.js | 0 .../samples/emit-entry-chunk/_config.js | 17 ---------------- .../_expected/amd/first-main.js | 5 ----- .../_expected/amd/second-main.js | 5 ----- .../_expected/es/first-main.js | 3 --- .../_expected/es/second-main.js | 3 --- .../_expected/amd/worker-proxy.js | 2 -- .../emit-entry-worker/_expected/amd/worker.js | 5 ----- .../emit-entry-worker/_expected/es/worker.js | 3 --- .../_expected/system/worker-proxy.js | 2 -- .../samples/emit-entry-worker/index-es.html | 10 ---------- .../chunk-filename-not-available/_config.js | 2 +- .../chunk-not-found/_config.js | 2 +- .../modules-loaded/_config.js | 4 ++-- 110 files changed, 142 insertions(+), 143 deletions(-) delete mode 100644 test/chunking-form/samples/configure-file-url/_expected/amd/chunk.js create mode 100644 test/chunking-form/samples/configure-file-url/_expected/amd/nested/chunk2.js delete mode 100644 test/chunking-form/samples/configure-file-url/_expected/cjs/chunk.js create mode 100644 test/chunking-form/samples/configure-file-url/_expected/cjs/nested/chunk2.js delete mode 100644 test/chunking-form/samples/configure-file-url/_expected/es/chunk.js create mode 100644 test/chunking-form/samples/configure-file-url/_expected/es/nested/chunk2.js delete mode 100644 test/chunking-form/samples/configure-file-url/_expected/system/chunk.js create mode 100644 test/chunking-form/samples/configure-file-url/_expected/system/nested/chunk2.js rename test/chunking-form/samples/{emit-entry-existing => emit-chunk-existing}/_config.js (79%) create mode 100644 test/chunking-form/samples/emit-chunk-existing/_expected/amd/first-main.js rename test/chunking-form/samples/{emit-entry-existing/_expected/amd/dep.js => emit-chunk-existing/_expected/amd/generated-dep.js} (100%) create mode 100644 test/chunking-form/samples/emit-chunk-existing/_expected/amd/second-main.js rename test/chunking-form/samples/{emit-entry-existing => emit-chunk-existing}/_expected/cjs/first-main.js (51%) rename test/chunking-form/samples/{emit-entry-existing/_expected/cjs/dep.js => emit-chunk-existing/_expected/cjs/generated-dep.js} (100%) rename test/chunking-form/samples/{emit-entry-existing => emit-chunk-existing}/_expected/cjs/second-main.js (51%) create mode 100644 test/chunking-form/samples/emit-chunk-existing/_expected/es/first-main.js rename test/chunking-form/samples/{emit-entry-existing/_expected/es/dep.js => emit-chunk-existing/_expected/es/generated-dep.js} (100%) create mode 100644 test/chunking-form/samples/emit-chunk-existing/_expected/es/second-main.js rename test/chunking-form/samples/{emit-entry-existing => emit-chunk-existing}/_expected/system/first-main.js (71%) rename test/chunking-form/samples/{emit-entry-existing/_expected/system/dep.js => emit-chunk-existing/_expected/system/generated-dep.js} (100%) rename test/chunking-form/samples/{emit-entry-existing => emit-chunk-existing}/_expected/system/second-main.js (71%) rename test/chunking-form/samples/{emit-entry-chunk-facade => emit-chunk-existing}/dep.js (100%) rename test/chunking-form/samples/{emit-entry-existing => emit-chunk-existing}/main1.js (100%) rename test/chunking-form/samples/{emit-entry-existing => emit-chunk-existing}/main2.js (100%) rename test/chunking-form/samples/{emit-entry-chunk-facade => emit-chunk-facade}/_config.js (50%) rename test/chunking-form/samples/{emit-entry-chunk-facade => emit-chunk-facade}/_expected/amd/generated-build-starter.js (100%) rename test/chunking-form/samples/{emit-entry-chunk-facade/_expected/amd/buildStart.js => emit-chunk-facade/_expected/amd/generated-buildStart.js} (100%) rename test/chunking-form/samples/{emit-entry-chunk-facade => emit-chunk-facade}/_expected/amd/main.js (100%) rename test/chunking-form/samples/{emit-entry-chunk-facade => emit-chunk-facade}/_expected/cjs/generated-build-starter.js (100%) rename test/chunking-form/samples/{emit-entry-chunk-facade/_expected/cjs/buildStart.js => emit-chunk-facade/_expected/cjs/generated-buildStart.js} (100%) rename test/chunking-form/samples/{emit-entry-chunk-facade => emit-chunk-facade}/_expected/cjs/main.js (100%) rename test/chunking-form/samples/{emit-entry-chunk-facade => emit-chunk-facade}/_expected/es/generated-build-starter.js (100%) rename test/chunking-form/samples/{emit-entry-chunk-facade/_expected/es/buildStart.js => emit-chunk-facade/_expected/es/generated-buildStart.js} (100%) rename test/chunking-form/samples/{emit-entry-chunk-facade => emit-chunk-facade}/_expected/es/main.js (100%) rename test/chunking-form/samples/{emit-entry-chunk-facade => emit-chunk-facade}/_expected/system/generated-build-starter.js (100%) rename test/chunking-form/samples/{emit-entry-chunk-facade/_expected/system/buildStart.js => emit-chunk-facade/_expected/system/generated-buildStart.js} (100%) rename test/chunking-form/samples/{emit-entry-chunk-facade => emit-chunk-facade}/_expected/system/main.js (100%) rename test/chunking-form/samples/{emit-entry-chunk-facade => emit-chunk-facade}/buildStart.js (100%) rename test/chunking-form/samples/{emit-entry-chunk => emit-chunk-facade}/dep.js (100%) rename test/chunking-form/samples/{emit-entry-chunk-facade => emit-chunk-facade}/main.js (100%) rename test/chunking-form/samples/{emit-entry-worker => emit-chunk-worker}/_config.js (60%) rename test/chunking-form/samples/{emit-entry-worker => emit-chunk-worker}/_expected/amd/chunks/chunk.js (100%) rename test/chunking-form/samples/{emit-entry-worker => emit-chunk-worker}/_expected/amd/chunks/chunk2.js (68%) create mode 100644 test/chunking-form/samples/emit-chunk-worker/_expected/amd/chunks/worker-proxy.js create mode 100644 test/chunking-form/samples/emit-chunk-worker/_expected/amd/chunks/worker.js rename test/chunking-form/samples/{emit-entry-worker => emit-chunk-worker}/_expected/amd/main.js (84%) rename test/chunking-form/samples/{emit-entry-worker => emit-chunk-worker}/_expected/cjs/chunks/chunk.js (100%) rename test/chunking-form/samples/{emit-entry-worker => emit-chunk-worker}/_expected/cjs/chunks/chunk2.js (51%) rename test/chunking-form/samples/{emit-entry-worker/_expected/cjs => emit-chunk-worker/_expected/cjs/chunks}/worker-proxy.js (100%) rename test/chunking-form/samples/{emit-entry-worker/_expected/cjs => emit-chunk-worker/_expected/cjs/chunks}/worker.js (58%) rename test/chunking-form/samples/{emit-entry-worker => emit-chunk-worker}/_expected/cjs/main.js (72%) rename test/chunking-form/samples/{emit-entry-worker => emit-chunk-worker}/_expected/es/chunks/chunk.js (100%) rename test/chunking-form/samples/{emit-entry-worker => emit-chunk-worker}/_expected/es/chunks/chunk2.js (59%) rename test/chunking-form/samples/{emit-entry-worker/_expected/es => emit-chunk-worker/_expected/es/chunks}/worker-proxy.js (100%) create mode 100644 test/chunking-form/samples/emit-chunk-worker/_expected/es/chunks/worker.js rename test/chunking-form/samples/{emit-entry-worker => emit-chunk-worker}/_expected/es/main.js (83%) rename test/chunking-form/samples/{emit-entry-worker => emit-chunk-worker}/_expected/system/chunks/chunk.js (100%) rename test/chunking-form/samples/{emit-entry-worker => emit-chunk-worker}/_expected/system/chunks/chunk2.js (74%) create mode 100644 test/chunking-form/samples/emit-chunk-worker/_expected/system/chunks/worker-proxy.js rename test/chunking-form/samples/{emit-entry-worker/_expected/system => emit-chunk-worker/_expected/system/chunks}/worker.js (72%) rename test/chunking-form/samples/{emit-entry-worker => emit-chunk-worker}/_expected/system/main.js (87%) rename test/chunking-form/samples/{emit-entry-worker => emit-chunk-worker}/index-amd.html (100%) rename test/chunking-form/samples/{emit-entry-worker => emit-chunk-worker}/index-system.html (100%) rename test/chunking-form/samples/{emit-entry-worker => emit-chunk-worker}/main.js (100%) rename test/chunking-form/samples/{emit-entry-worker => emit-chunk-worker}/shared.js (100%) rename test/chunking-form/samples/{emit-entry-worker => emit-chunk-worker}/worker.js (100%) create mode 100644 test/chunking-form/samples/emit-chunk/_config.js rename test/chunking-form/samples/{emit-entry-chunk/_expected/amd/buildStart.js => emit-chunk/_expected/amd/generated-buildStart.js} (100%) rename test/chunking-form/samples/{emit-entry-chunk => emit-chunk}/_expected/amd/generated-chunk.js (100%) rename test/chunking-form/samples/{emit-entry-chunk => emit-chunk}/_expected/amd/main.js (100%) rename test/chunking-form/samples/{emit-entry-chunk/_expected/cjs/buildStart.js => emit-chunk/_expected/cjs/generated-buildStart.js} (100%) rename test/chunking-form/samples/{emit-entry-chunk => emit-chunk}/_expected/cjs/generated-chunk.js (100%) rename test/chunking-form/samples/{emit-entry-chunk => emit-chunk}/_expected/cjs/main.js (100%) rename test/chunking-form/samples/{emit-entry-chunk/_expected/es/buildStart.js => emit-chunk/_expected/es/generated-buildStart.js} (100%) rename test/chunking-form/samples/{emit-entry-chunk => emit-chunk}/_expected/es/generated-chunk.js (100%) rename test/chunking-form/samples/{emit-entry-chunk => emit-chunk}/_expected/es/main.js (100%) rename test/chunking-form/samples/{emit-entry-chunk/_expected/system/buildStart.js => emit-chunk/_expected/system/generated-buildStart.js} (100%) rename test/chunking-form/samples/{emit-entry-chunk => emit-chunk}/_expected/system/generated-chunk.js (100%) rename test/chunking-form/samples/{emit-entry-chunk => emit-chunk}/_expected/system/main.js (100%) rename test/chunking-form/samples/{emit-entry-chunk => emit-chunk}/buildStart.js (100%) rename test/chunking-form/samples/{emit-entry-existing => emit-chunk}/dep.js (100%) rename test/chunking-form/samples/{emit-entry-chunk => emit-chunk}/main.js (100%) delete mode 100644 test/chunking-form/samples/emit-entry-chunk/_config.js delete mode 100644 test/chunking-form/samples/emit-entry-existing/_expected/amd/first-main.js delete mode 100644 test/chunking-form/samples/emit-entry-existing/_expected/amd/second-main.js delete mode 100644 test/chunking-form/samples/emit-entry-existing/_expected/es/first-main.js delete mode 100644 test/chunking-form/samples/emit-entry-existing/_expected/es/second-main.js delete mode 100644 test/chunking-form/samples/emit-entry-worker/_expected/amd/worker-proxy.js delete mode 100644 test/chunking-form/samples/emit-entry-worker/_expected/amd/worker.js delete mode 100644 test/chunking-form/samples/emit-entry-worker/_expected/es/worker.js delete mode 100644 test/chunking-form/samples/emit-entry-worker/_expected/system/worker-proxy.js delete mode 100644 test/chunking-form/samples/emit-entry-worker/index-es.html diff --git a/src/Graph.ts b/src/Graph.ts index 054f00e1b6a..19b0a19ba77 100644 --- a/src/Graph.ts +++ b/src/Graph.ts @@ -212,7 +212,7 @@ export default class Graph { timeStart('parse modules', 2); return Promise.all([ - this.moduleLoader.addEntryModules(normalizeEntryModules(entryModules)), + this.moduleLoader.addEntryModules(normalizeEntryModules(entryModules), true), manualChunks && this.moduleLoader.addManualChunks(manualChunks) ]).then(([{ entryModules, manualChunkModulesByAlias }]) => { for (const entryModule of entryModules) { diff --git a/src/Module.ts b/src/Module.ts index e58224f02fe..060d1922f78 100644 --- a/src/Module.ts +++ b/src/Module.ts @@ -192,6 +192,7 @@ export default class Module { isEntryPoint: boolean = false; isExecuted: boolean = false; isExternal: false; + isUserDefinedEntryPoint: boolean = false; manualChunkAlias: string = null; originalCode: string; originalSourcemap: RawSourceMap | void; @@ -201,7 +202,6 @@ export default class Module { sourcemapChain: RawSourceMap[]; sources: string[] = []; transformAssets: Asset[]; - type: 'Module'; usesTopLevelAwait: boolean = false; private ast: Program; diff --git a/src/ModuleLoader.ts b/src/ModuleLoader.ts index e17fd561d35..eb6e1f74c0d 100644 --- a/src/ModuleLoader.ts +++ b/src/ModuleLoader.ts @@ -74,7 +74,7 @@ export class ModuleLoader { this.entriesByMetaId, unresolvedEntryModule.unresolvedId ); - this.addEntryModules([unresolvedEntryModule]) + this.addEntryModules([unresolvedEntryModule], false) .then(({ newEntryModules: [module] }) => { entryRecord.module = module; }) @@ -86,7 +86,8 @@ export class ModuleLoader { } addEntryModules( - unresolvedEntryModules: UnresolvedModuleWithAlias[] + unresolvedEntryModules: UnresolvedModuleWithAlias[], + isUserDefined: boolean ): Promise<{ entryModules: Module[]; manualChunkModulesByAlias: Record; @@ -96,6 +97,7 @@ export class ModuleLoader { unresolvedEntryModules.map(this.loadEntryModule) ).then(entryModules => { for (const entryModule of entryModules) { + entryModule.isUserDefinedEntryPoint = entryModule.isUserDefinedEntryPoint || isUserDefined; const existingEntryModule = this.entryModules.find(module => module.id === entryModule.id); if (!existingEntryModule) { this.entryModules.push(entryModule); diff --git a/src/rollup/types.d.ts b/src/rollup/types.d.ts index 2e3156befc1..cb290696e2d 100644 --- a/src/rollup/types.d.ts +++ b/src/rollup/types.d.ts @@ -104,13 +104,13 @@ export interface MinimalPluginContext { } export type EmitAsset = (name: string, source?: string | Buffer) => string; -export type EmitEntryChunk = (name: string) => string; +export type EmitChunk = (name: string) => string; export interface PluginContext extends MinimalPluginContext { addWatchFile: (id: string) => void; cache: PluginCache; emitAsset: EmitAsset; - emitEntryChunk: EmitEntryChunk; + emitChunk: EmitChunk; error: (err: RollupError | string, pos?: { column: number; line: number }) => void; getAssetFileName: (assetMetaId: string) => string; getChunkFileName: (chunkMetaId: string) => string; diff --git a/src/utils/assignChunkIds.ts b/src/utils/assignChunkIds.ts index 4386eb01e50..a538f027926 100644 --- a/src/utils/assignChunkIds.ts +++ b/src/utils/assignChunkIds.ts @@ -13,9 +13,10 @@ export function assignChunkIds( const usedIds: Record = {}; const [entryChunks, otherChunks] = chunks.reduce( ([entryChunks, otherChunks], chunk) => { - (chunk.facadeModule && chunk.facadeModule.isEntryPoint ? entryChunks : otherChunks).push( - chunk - ); + (chunk.facadeModule && chunk.facadeModule.isUserDefinedEntryPoint + ? entryChunks + : otherChunks + ).push(chunk); return [entryChunks, otherChunks]; }, [[], []] @@ -32,7 +33,7 @@ export function assignChunkIds( chunk.generateIdPreserveModules(inputBase, usedIds); } else { let pattern, patternName; - if (chunk.facadeModule && chunk.facadeModule.isEntryPoint) { + if (chunk.facadeModule && chunk.facadeModule.isUserDefinedEntryPoint) { pattern = outputOptions.entryFileNames || '[name].js'; patternName = 'output.entryFileNames'; } else { diff --git a/src/utils/pluginDriver.ts b/src/utils/pluginDriver.ts index f4a4ff5ebcb..0ea00aa2d24 100644 --- a/src/utils/pluginDriver.ts +++ b/src/utils/pluginDriver.ts @@ -136,11 +136,11 @@ export function createPluginDriver( } const context: PluginContext = { - emitEntryChunk(id: string) { + emitChunk(id: string) { if (graph.phase > BuildPhase.LOAD_AND_PARSE) this.error({ code: Errors.INVALID_ROLLUP_PHASE, - message: `Cannot call emitEntryChunk after module loading has finished.` + message: `Cannot call emitChunk after module loading has finished.` }); return graph.moduleLoader.addEntryModuleAndGetMetaId({ alias: null, unresolvedId: id }); }, diff --git a/test/chunking-form/samples/configure-file-url/_config.js b/test/chunking-form/samples/configure-file-url/_config.js index 4cb2654b529..947874f3214 100644 --- a/test/chunking-form/samples/configure-file-url/_config.js +++ b/test/chunking-form/samples/configure-file-url/_config.js @@ -14,7 +14,7 @@ module.exports = { load(id) { if (id.endsWith('solved')) { const assetId = this.emitAsset(`asset-${id}.txt`, `Asset for: ${id}`); - const chunkId = this.emitEntryChunk('chunk.js'); + const chunkId = this.emitChunk('chunk.js'); return ( `export const asset = import.meta.ROLLUP_ASSET_URL_${assetId};\n` + `export const chunk = import.meta.ROLLUP_CHUNK_URL_${chunkId};` diff --git a/test/chunking-form/samples/configure-file-url/_expected/amd/chunk.js b/test/chunking-form/samples/configure-file-url/_expected/amd/chunk.js deleted file mode 100644 index 32f0814a584..00000000000 --- a/test/chunking-form/samples/configure-file-url/_expected/amd/chunk.js +++ /dev/null @@ -1,5 +0,0 @@ -define(function () { 'use strict'; - - console.log('chunk'); - -}); diff --git a/test/chunking-form/samples/configure-file-url/_expected/amd/main.js b/test/chunking-form/samples/configure-file-url/_expected/amd/main.js index 8d8463928ba..3877c193000 100644 --- a/test/chunking-form/samples/configure-file-url/_expected/amd/main.js +++ b/test/chunking-form/samples/configure-file-url/_expected/amd/main.js @@ -4,8 +4,8 @@ define(['module', 'require'], function (module, require) { 'use strict'; const chunk = 'resolved'; const asset$1 = new URL(module.uri + '/../assets/asset-unresolved-9548436d.txt', document.baseURI).href; - const chunk$1 = new URL(module.uri + '/../chunk.js', document.baseURI).href; + const chunk$1 = new URL(module.uri + '/../nested/chunk.js', document.baseURI).href; - new Promise(function (resolve, reject) { require(['./nested/chunk'], resolve, reject) }).then(result => console.log(result, chunk, chunk$1, asset, asset$1)); + new Promise(function (resolve, reject) { require(['./nested/chunk2'], resolve, reject) }).then(result => console.log(result, chunk, chunk$1, asset, asset$1)); }); diff --git a/test/chunking-form/samples/configure-file-url/_expected/amd/nested/chunk.js b/test/chunking-form/samples/configure-file-url/_expected/amd/nested/chunk.js index 0125d6ff8cd..32f0814a584 100644 --- a/test/chunking-form/samples/configure-file-url/_expected/amd/nested/chunk.js +++ b/test/chunking-form/samples/configure-file-url/_expected/amd/nested/chunk.js @@ -1,9 +1,5 @@ -define(['module', 'exports'], function (module, exports) { 'use strict'; +define(function () { 'use strict'; - const asset = 'chunkId=nested/chunk.js:moduleId=solved:fileName=assets/asset-solved-9b321da2.txt:format=amd:relativePath=../assets/asset-solved-9b321da2.txt:type=ASSET' - const chunk = 'chunkId=nested/chunk.js:moduleId=solved:fileName=chunk.js:format=amd:relativePath=../chunk.js:type=CHUNK' - - exports.asset = asset; - exports.chunk = chunk; + console.log('chunk'); }); diff --git a/test/chunking-form/samples/configure-file-url/_expected/amd/nested/chunk2.js b/test/chunking-form/samples/configure-file-url/_expected/amd/nested/chunk2.js new file mode 100644 index 00000000000..10eb3a989a2 --- /dev/null +++ b/test/chunking-form/samples/configure-file-url/_expected/amd/nested/chunk2.js @@ -0,0 +1,9 @@ +define(['module', 'exports'], function (module, exports) { 'use strict'; + + const asset = 'chunkId=nested/chunk2.js:moduleId=solved:fileName=assets/asset-solved-9b321da2.txt:format=amd:relativePath=../assets/asset-solved-9b321da2.txt:type=ASSET' + const chunk = 'chunkId=nested/chunk2.js:moduleId=solved:fileName=nested/chunk.js:format=amd:relativePath=chunk.js:type=CHUNK' + + exports.asset = asset; + exports.chunk = chunk; + +}); diff --git a/test/chunking-form/samples/configure-file-url/_expected/cjs/chunk.js b/test/chunking-form/samples/configure-file-url/_expected/cjs/chunk.js deleted file mode 100644 index 9bd6f06e964..00000000000 --- a/test/chunking-form/samples/configure-file-url/_expected/cjs/chunk.js +++ /dev/null @@ -1,3 +0,0 @@ -'use strict'; - -console.log('chunk'); diff --git a/test/chunking-form/samples/configure-file-url/_expected/cjs/main.js b/test/chunking-form/samples/configure-file-url/_expected/cjs/main.js index 3575b0dd1f1..53e5508203c 100644 --- a/test/chunking-form/samples/configure-file-url/_expected/cjs/main.js +++ b/test/chunking-form/samples/configure-file-url/_expected/cjs/main.js @@ -4,6 +4,6 @@ const asset = 'resolved'; const chunk = 'resolved'; const asset$1 = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/asset-unresolved-9548436d.txt').href : new URL((document.currentScript && document.currentScript.src || document.baseURI) + '/../assets/asset-unresolved-9548436d.txt').href); -const chunk$1 = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/chunk.js').href : new URL((document.currentScript && document.currentScript.src || document.baseURI) + '/../chunk.js').href); +const chunk$1 = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/nested/chunk.js').href : new URL((document.currentScript && document.currentScript.src || document.baseURI) + '/../nested/chunk.js').href); -Promise.resolve(require('./nested/chunk.js')).then(result => console.log(result, chunk, chunk$1, asset, asset$1)); +Promise.resolve(require('./nested/chunk2.js')).then(result => console.log(result, chunk, chunk$1, asset, asset$1)); diff --git a/test/chunking-form/samples/configure-file-url/_expected/cjs/nested/chunk.js b/test/chunking-form/samples/configure-file-url/_expected/cjs/nested/chunk.js index 019ff7dcfd0..9bd6f06e964 100644 --- a/test/chunking-form/samples/configure-file-url/_expected/cjs/nested/chunk.js +++ b/test/chunking-form/samples/configure-file-url/_expected/cjs/nested/chunk.js @@ -1,7 +1,3 @@ 'use strict'; -const asset = 'chunkId=nested/chunk.js:moduleId=solved:fileName=assets/asset-solved-9b321da2.txt:format=cjs:relativePath=../assets/asset-solved-9b321da2.txt:type=ASSET' -const chunk = 'chunkId=nested/chunk.js:moduleId=solved:fileName=chunk.js:format=cjs:relativePath=../chunk.js:type=CHUNK' - -exports.asset = asset; -exports.chunk = chunk; +console.log('chunk'); diff --git a/test/chunking-form/samples/configure-file-url/_expected/cjs/nested/chunk2.js b/test/chunking-form/samples/configure-file-url/_expected/cjs/nested/chunk2.js new file mode 100644 index 00000000000..c01786fabc8 --- /dev/null +++ b/test/chunking-form/samples/configure-file-url/_expected/cjs/nested/chunk2.js @@ -0,0 +1,7 @@ +'use strict'; + +const asset = 'chunkId=nested/chunk2.js:moduleId=solved:fileName=assets/asset-solved-9b321da2.txt:format=cjs:relativePath=../assets/asset-solved-9b321da2.txt:type=ASSET' +const chunk = 'chunkId=nested/chunk2.js:moduleId=solved:fileName=nested/chunk.js:format=cjs:relativePath=chunk.js:type=CHUNK' + +exports.asset = asset; +exports.chunk = chunk; diff --git a/test/chunking-form/samples/configure-file-url/_expected/es/chunk.js b/test/chunking-form/samples/configure-file-url/_expected/es/chunk.js deleted file mode 100644 index 36b1d61dd25..00000000000 --- a/test/chunking-form/samples/configure-file-url/_expected/es/chunk.js +++ /dev/null @@ -1 +0,0 @@ -console.log('chunk'); diff --git a/test/chunking-form/samples/configure-file-url/_expected/es/main.js b/test/chunking-form/samples/configure-file-url/_expected/es/main.js index 7f9578e00cc..3234da07909 100644 --- a/test/chunking-form/samples/configure-file-url/_expected/es/main.js +++ b/test/chunking-form/samples/configure-file-url/_expected/es/main.js @@ -2,6 +2,6 @@ const asset = 'resolved'; const chunk = 'resolved'; const asset$1 = new URL('assets/asset-unresolved-9548436d.txt', import.meta.url).href; -const chunk$1 = new URL('chunk.js', import.meta.url).href; +const chunk$1 = new URL('nested/chunk.js', import.meta.url).href; -import('./nested/chunk.js').then(result => console.log(result, chunk, chunk$1, asset, asset$1)); +import('./nested/chunk2.js').then(result => console.log(result, chunk, chunk$1, asset, asset$1)); diff --git a/test/chunking-form/samples/configure-file-url/_expected/es/nested/chunk.js b/test/chunking-form/samples/configure-file-url/_expected/es/nested/chunk.js index a3a938282a6..36b1d61dd25 100644 --- a/test/chunking-form/samples/configure-file-url/_expected/es/nested/chunk.js +++ b/test/chunking-form/samples/configure-file-url/_expected/es/nested/chunk.js @@ -1,4 +1 @@ -const asset = 'chunkId=nested/chunk.js:moduleId=solved:fileName=assets/asset-solved-9b321da2.txt:format=es:relativePath=../assets/asset-solved-9b321da2.txt:type=ASSET' -const chunk = 'chunkId=nested/chunk.js:moduleId=solved:fileName=chunk.js:format=es:relativePath=../chunk.js:type=CHUNK' - -export { asset, chunk }; +console.log('chunk'); diff --git a/test/chunking-form/samples/configure-file-url/_expected/es/nested/chunk2.js b/test/chunking-form/samples/configure-file-url/_expected/es/nested/chunk2.js new file mode 100644 index 00000000000..7269cd9eb94 --- /dev/null +++ b/test/chunking-form/samples/configure-file-url/_expected/es/nested/chunk2.js @@ -0,0 +1,4 @@ +const asset = 'chunkId=nested/chunk2.js:moduleId=solved:fileName=assets/asset-solved-9b321da2.txt:format=es:relativePath=../assets/asset-solved-9b321da2.txt:type=ASSET' +const chunk = 'chunkId=nested/chunk2.js:moduleId=solved:fileName=nested/chunk.js:format=es:relativePath=chunk.js:type=CHUNK' + +export { asset, chunk }; diff --git a/test/chunking-form/samples/configure-file-url/_expected/system/chunk.js b/test/chunking-form/samples/configure-file-url/_expected/system/chunk.js deleted file mode 100644 index 8f0f1907cfd..00000000000 --- a/test/chunking-form/samples/configure-file-url/_expected/system/chunk.js +++ /dev/null @@ -1,10 +0,0 @@ -System.register([], function (exports, module) { - 'use strict'; - return { - execute: function () { - - console.log('chunk'); - - } - }; -}); diff --git a/test/chunking-form/samples/configure-file-url/_expected/system/main.js b/test/chunking-form/samples/configure-file-url/_expected/system/main.js index 19dad1f0c15..f45bae342b0 100644 --- a/test/chunking-form/samples/configure-file-url/_expected/system/main.js +++ b/test/chunking-form/samples/configure-file-url/_expected/system/main.js @@ -7,9 +7,9 @@ System.register([], function (exports, module) { const chunk = 'resolved'; const asset$1 = new URL('assets/asset-unresolved-9548436d.txt', module.meta.url).href; - const chunk$1 = new URL('chunk.js', module.meta.url).href; + const chunk$1 = new URL('nested/chunk.js', module.meta.url).href; - module.import('./nested/chunk.js').then(result => console.log(result, chunk, chunk$1, asset, asset$1)); + module.import('./nested/chunk2.js').then(result => console.log(result, chunk, chunk$1, asset, asset$1)); } }; diff --git a/test/chunking-form/samples/configure-file-url/_expected/system/nested/chunk.js b/test/chunking-form/samples/configure-file-url/_expected/system/nested/chunk.js index 74abe05b6e3..8f0f1907cfd 100644 --- a/test/chunking-form/samples/configure-file-url/_expected/system/nested/chunk.js +++ b/test/chunking-form/samples/configure-file-url/_expected/system/nested/chunk.js @@ -3,8 +3,7 @@ System.register([], function (exports, module) { return { execute: function () { - const asset = exports('asset', 'chunkId=nested/chunk.js:moduleId=solved:fileName=assets/asset-solved-9b321da2.txt:format=system:relativePath=../assets/asset-solved-9b321da2.txt:type=ASSET' - const chunk = exports('chunk', 'chunkId=nested/chunk.js:moduleId=solved:fileName=chunk.js:format=system:relativePath=../chunk.js:type=CHUNK' + console.log('chunk'); } }; diff --git a/test/chunking-form/samples/configure-file-url/_expected/system/nested/chunk2.js b/test/chunking-form/samples/configure-file-url/_expected/system/nested/chunk2.js new file mode 100644 index 00000000000..ace995589af --- /dev/null +++ b/test/chunking-form/samples/configure-file-url/_expected/system/nested/chunk2.js @@ -0,0 +1,11 @@ +System.register([], function (exports, module) { + 'use strict'; + return { + execute: function () { + + const asset = exports('asset', 'chunkId=nested/chunk2.js:moduleId=solved:fileName=assets/asset-solved-9b321da2.txt:format=system:relativePath=../assets/asset-solved-9b321da2.txt:type=ASSET' + const chunk = exports('chunk', 'chunkId=nested/chunk2.js:moduleId=solved:fileName=nested/chunk.js:format=system:relativePath=chunk.js:type=CHUNK' + + } + }; +}); diff --git a/test/chunking-form/samples/emit-entry-existing/_config.js b/test/chunking-form/samples/emit-chunk-existing/_config.js similarity index 79% rename from test/chunking-form/samples/emit-entry-existing/_config.js rename to test/chunking-form/samples/emit-chunk-existing/_config.js index b1bdaa36ef9..3f626f6076e 100644 --- a/test/chunking-form/samples/emit-entry-existing/_config.js +++ b/test/chunking-form/samples/emit-chunk-existing/_config.js @@ -8,11 +8,11 @@ module.exports = { plugins: { buildStart() { // it should be possible to add existing entry points while not overriding their alias - this.emitEntryChunk('main1'); + this.emitChunk('main1'); // if an existing dependency is added, all references should use the new name - this.emitEntryChunk('dep.js'); - this.emitEntryChunk('dep'); + this.emitChunk('dep.js'); + this.emitChunk('dep'); } } } diff --git a/test/chunking-form/samples/emit-chunk-existing/_expected/amd/first-main.js b/test/chunking-form/samples/emit-chunk-existing/_expected/amd/first-main.js new file mode 100644 index 00000000000..fd823ca54c7 --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-existing/_expected/amd/first-main.js @@ -0,0 +1,5 @@ +define(['./generated-dep'], function (dep) { 'use strict'; + + console.log('main1', dep); + +}); diff --git a/test/chunking-form/samples/emit-entry-existing/_expected/amd/dep.js b/test/chunking-form/samples/emit-chunk-existing/_expected/amd/generated-dep.js similarity index 100% rename from test/chunking-form/samples/emit-entry-existing/_expected/amd/dep.js rename to test/chunking-form/samples/emit-chunk-existing/_expected/amd/generated-dep.js diff --git a/test/chunking-form/samples/emit-chunk-existing/_expected/amd/second-main.js b/test/chunking-form/samples/emit-chunk-existing/_expected/amd/second-main.js new file mode 100644 index 00000000000..fd823ca54c7 --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-existing/_expected/amd/second-main.js @@ -0,0 +1,5 @@ +define(['./generated-dep'], function (dep) { 'use strict'; + + console.log('main1', dep); + +}); diff --git a/test/chunking-form/samples/emit-entry-existing/_expected/cjs/first-main.js b/test/chunking-form/samples/emit-chunk-existing/_expected/cjs/first-main.js similarity index 51% rename from test/chunking-form/samples/emit-entry-existing/_expected/cjs/first-main.js rename to test/chunking-form/samples/emit-chunk-existing/_expected/cjs/first-main.js index cb8b24decc7..54bee5af979 100644 --- a/test/chunking-form/samples/emit-entry-existing/_expected/cjs/first-main.js +++ b/test/chunking-form/samples/emit-chunk-existing/_expected/cjs/first-main.js @@ -1,5 +1,5 @@ 'use strict'; -var dep = require('./dep.js'); +var dep = require('./generated-dep.js'); console.log('main1', dep); diff --git a/test/chunking-form/samples/emit-entry-existing/_expected/cjs/dep.js b/test/chunking-form/samples/emit-chunk-existing/_expected/cjs/generated-dep.js similarity index 100% rename from test/chunking-form/samples/emit-entry-existing/_expected/cjs/dep.js rename to test/chunking-form/samples/emit-chunk-existing/_expected/cjs/generated-dep.js diff --git a/test/chunking-form/samples/emit-entry-existing/_expected/cjs/second-main.js b/test/chunking-form/samples/emit-chunk-existing/_expected/cjs/second-main.js similarity index 51% rename from test/chunking-form/samples/emit-entry-existing/_expected/cjs/second-main.js rename to test/chunking-form/samples/emit-chunk-existing/_expected/cjs/second-main.js index cb8b24decc7..54bee5af979 100644 --- a/test/chunking-form/samples/emit-entry-existing/_expected/cjs/second-main.js +++ b/test/chunking-form/samples/emit-chunk-existing/_expected/cjs/second-main.js @@ -1,5 +1,5 @@ 'use strict'; -var dep = require('./dep.js'); +var dep = require('./generated-dep.js'); console.log('main1', dep); diff --git a/test/chunking-form/samples/emit-chunk-existing/_expected/es/first-main.js b/test/chunking-form/samples/emit-chunk-existing/_expected/es/first-main.js new file mode 100644 index 00000000000..d77500b5810 --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-existing/_expected/es/first-main.js @@ -0,0 +1,3 @@ +import value from './generated-dep.js'; + +console.log('main1', value); diff --git a/test/chunking-form/samples/emit-entry-existing/_expected/es/dep.js b/test/chunking-form/samples/emit-chunk-existing/_expected/es/generated-dep.js similarity index 100% rename from test/chunking-form/samples/emit-entry-existing/_expected/es/dep.js rename to test/chunking-form/samples/emit-chunk-existing/_expected/es/generated-dep.js diff --git a/test/chunking-form/samples/emit-chunk-existing/_expected/es/second-main.js b/test/chunking-form/samples/emit-chunk-existing/_expected/es/second-main.js new file mode 100644 index 00000000000..d77500b5810 --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-existing/_expected/es/second-main.js @@ -0,0 +1,3 @@ +import value from './generated-dep.js'; + +console.log('main1', value); diff --git a/test/chunking-form/samples/emit-entry-existing/_expected/system/first-main.js b/test/chunking-form/samples/emit-chunk-existing/_expected/system/first-main.js similarity index 71% rename from test/chunking-form/samples/emit-entry-existing/_expected/system/first-main.js rename to test/chunking-form/samples/emit-chunk-existing/_expected/system/first-main.js index 1441e3fac98..d3cb55d1a7c 100644 --- a/test/chunking-form/samples/emit-entry-existing/_expected/system/first-main.js +++ b/test/chunking-form/samples/emit-chunk-existing/_expected/system/first-main.js @@ -1,4 +1,4 @@ -System.register(['./dep.js'], function (exports, module) { +System.register(['./generated-dep.js'], function (exports, module) { 'use strict'; var value; return { diff --git a/test/chunking-form/samples/emit-entry-existing/_expected/system/dep.js b/test/chunking-form/samples/emit-chunk-existing/_expected/system/generated-dep.js similarity index 100% rename from test/chunking-form/samples/emit-entry-existing/_expected/system/dep.js rename to test/chunking-form/samples/emit-chunk-existing/_expected/system/generated-dep.js diff --git a/test/chunking-form/samples/emit-entry-existing/_expected/system/second-main.js b/test/chunking-form/samples/emit-chunk-existing/_expected/system/second-main.js similarity index 71% rename from test/chunking-form/samples/emit-entry-existing/_expected/system/second-main.js rename to test/chunking-form/samples/emit-chunk-existing/_expected/system/second-main.js index 1441e3fac98..d3cb55d1a7c 100644 --- a/test/chunking-form/samples/emit-entry-existing/_expected/system/second-main.js +++ b/test/chunking-form/samples/emit-chunk-existing/_expected/system/second-main.js @@ -1,4 +1,4 @@ -System.register(['./dep.js'], function (exports, module) { +System.register(['./generated-dep.js'], function (exports, module) { 'use strict'; var value; return { diff --git a/test/chunking-form/samples/emit-entry-chunk-facade/dep.js b/test/chunking-form/samples/emit-chunk-existing/dep.js similarity index 100% rename from test/chunking-form/samples/emit-entry-chunk-facade/dep.js rename to test/chunking-form/samples/emit-chunk-existing/dep.js diff --git a/test/chunking-form/samples/emit-entry-existing/main1.js b/test/chunking-form/samples/emit-chunk-existing/main1.js similarity index 100% rename from test/chunking-form/samples/emit-entry-existing/main1.js rename to test/chunking-form/samples/emit-chunk-existing/main1.js diff --git a/test/chunking-form/samples/emit-entry-existing/main2.js b/test/chunking-form/samples/emit-chunk-existing/main2.js similarity index 100% rename from test/chunking-form/samples/emit-entry-existing/main2.js rename to test/chunking-form/samples/emit-chunk-existing/main2.js diff --git a/test/chunking-form/samples/emit-entry-chunk-facade/_config.js b/test/chunking-form/samples/emit-chunk-facade/_config.js similarity index 50% rename from test/chunking-form/samples/emit-entry-chunk-facade/_config.js rename to test/chunking-form/samples/emit-chunk-facade/_config.js index 7d4b14b8e1f..298c350d86c 100644 --- a/test/chunking-form/samples/emit-entry-chunk-facade/_config.js +++ b/test/chunking-form/samples/emit-chunk-facade/_config.js @@ -2,7 +2,7 @@ const assert = require('assert'); let metaId; module.exports = { - description: 'retrieves the correct name of emitted entry chunk in case a facade is created', + description: 'retrieves the correct name of an emitted chunk in case a facade is created', options: { input: 'main', manualChunks: { @@ -10,10 +10,10 @@ module.exports = { }, plugins: { buildStart() { - metaId = this.emitEntryChunk('buildStart'); + metaId = this.emitChunk('buildStart'); }, renderChunk() { - assert.strictEqual(this.getChunkFileName(metaId), 'buildStart.js'); + assert.strictEqual(this.getChunkFileName(metaId), 'generated-buildStart.js'); } } } diff --git a/test/chunking-form/samples/emit-entry-chunk-facade/_expected/amd/generated-build-starter.js b/test/chunking-form/samples/emit-chunk-facade/_expected/amd/generated-build-starter.js similarity index 100% rename from test/chunking-form/samples/emit-entry-chunk-facade/_expected/amd/generated-build-starter.js rename to test/chunking-form/samples/emit-chunk-facade/_expected/amd/generated-build-starter.js diff --git a/test/chunking-form/samples/emit-entry-chunk-facade/_expected/amd/buildStart.js b/test/chunking-form/samples/emit-chunk-facade/_expected/amd/generated-buildStart.js similarity index 100% rename from test/chunking-form/samples/emit-entry-chunk-facade/_expected/amd/buildStart.js rename to test/chunking-form/samples/emit-chunk-facade/_expected/amd/generated-buildStart.js diff --git a/test/chunking-form/samples/emit-entry-chunk-facade/_expected/amd/main.js b/test/chunking-form/samples/emit-chunk-facade/_expected/amd/main.js similarity index 100% rename from test/chunking-form/samples/emit-entry-chunk-facade/_expected/amd/main.js rename to test/chunking-form/samples/emit-chunk-facade/_expected/amd/main.js diff --git a/test/chunking-form/samples/emit-entry-chunk-facade/_expected/cjs/generated-build-starter.js b/test/chunking-form/samples/emit-chunk-facade/_expected/cjs/generated-build-starter.js similarity index 100% rename from test/chunking-form/samples/emit-entry-chunk-facade/_expected/cjs/generated-build-starter.js rename to test/chunking-form/samples/emit-chunk-facade/_expected/cjs/generated-build-starter.js diff --git a/test/chunking-form/samples/emit-entry-chunk-facade/_expected/cjs/buildStart.js b/test/chunking-form/samples/emit-chunk-facade/_expected/cjs/generated-buildStart.js similarity index 100% rename from test/chunking-form/samples/emit-entry-chunk-facade/_expected/cjs/buildStart.js rename to test/chunking-form/samples/emit-chunk-facade/_expected/cjs/generated-buildStart.js diff --git a/test/chunking-form/samples/emit-entry-chunk-facade/_expected/cjs/main.js b/test/chunking-form/samples/emit-chunk-facade/_expected/cjs/main.js similarity index 100% rename from test/chunking-form/samples/emit-entry-chunk-facade/_expected/cjs/main.js rename to test/chunking-form/samples/emit-chunk-facade/_expected/cjs/main.js diff --git a/test/chunking-form/samples/emit-entry-chunk-facade/_expected/es/generated-build-starter.js b/test/chunking-form/samples/emit-chunk-facade/_expected/es/generated-build-starter.js similarity index 100% rename from test/chunking-form/samples/emit-entry-chunk-facade/_expected/es/generated-build-starter.js rename to test/chunking-form/samples/emit-chunk-facade/_expected/es/generated-build-starter.js diff --git a/test/chunking-form/samples/emit-entry-chunk-facade/_expected/es/buildStart.js b/test/chunking-form/samples/emit-chunk-facade/_expected/es/generated-buildStart.js similarity index 100% rename from test/chunking-form/samples/emit-entry-chunk-facade/_expected/es/buildStart.js rename to test/chunking-form/samples/emit-chunk-facade/_expected/es/generated-buildStart.js diff --git a/test/chunking-form/samples/emit-entry-chunk-facade/_expected/es/main.js b/test/chunking-form/samples/emit-chunk-facade/_expected/es/main.js similarity index 100% rename from test/chunking-form/samples/emit-entry-chunk-facade/_expected/es/main.js rename to test/chunking-form/samples/emit-chunk-facade/_expected/es/main.js diff --git a/test/chunking-form/samples/emit-entry-chunk-facade/_expected/system/generated-build-starter.js b/test/chunking-form/samples/emit-chunk-facade/_expected/system/generated-build-starter.js similarity index 100% rename from test/chunking-form/samples/emit-entry-chunk-facade/_expected/system/generated-build-starter.js rename to test/chunking-form/samples/emit-chunk-facade/_expected/system/generated-build-starter.js diff --git a/test/chunking-form/samples/emit-entry-chunk-facade/_expected/system/buildStart.js b/test/chunking-form/samples/emit-chunk-facade/_expected/system/generated-buildStart.js similarity index 100% rename from test/chunking-form/samples/emit-entry-chunk-facade/_expected/system/buildStart.js rename to test/chunking-form/samples/emit-chunk-facade/_expected/system/generated-buildStart.js diff --git a/test/chunking-form/samples/emit-entry-chunk-facade/_expected/system/main.js b/test/chunking-form/samples/emit-chunk-facade/_expected/system/main.js similarity index 100% rename from test/chunking-form/samples/emit-entry-chunk-facade/_expected/system/main.js rename to test/chunking-form/samples/emit-chunk-facade/_expected/system/main.js diff --git a/test/chunking-form/samples/emit-entry-chunk-facade/buildStart.js b/test/chunking-form/samples/emit-chunk-facade/buildStart.js similarity index 100% rename from test/chunking-form/samples/emit-entry-chunk-facade/buildStart.js rename to test/chunking-form/samples/emit-chunk-facade/buildStart.js diff --git a/test/chunking-form/samples/emit-entry-chunk/dep.js b/test/chunking-form/samples/emit-chunk-facade/dep.js similarity index 100% rename from test/chunking-form/samples/emit-entry-chunk/dep.js rename to test/chunking-form/samples/emit-chunk-facade/dep.js diff --git a/test/chunking-form/samples/emit-entry-chunk-facade/main.js b/test/chunking-form/samples/emit-chunk-facade/main.js similarity index 100% rename from test/chunking-form/samples/emit-entry-chunk-facade/main.js rename to test/chunking-form/samples/emit-chunk-facade/main.js diff --git a/test/chunking-form/samples/emit-entry-worker/_config.js b/test/chunking-form/samples/emit-chunk-worker/_config.js similarity index 60% rename from test/chunking-form/samples/emit-entry-worker/_config.js rename to test/chunking-form/samples/emit-chunk-worker/_config.js index 5f2f23f67ce..168b5d3bb62 100644 --- a/test/chunking-form/samples/emit-entry-worker/_config.js +++ b/test/chunking-form/samples/emit-chunk-worker/_config.js @@ -1,8 +1,10 @@ +const path = require('path'); + let workerId; let proxyId; module.exports = { - description: 'allows adding additional entry points', + description: 'allows adding additional chunks to be used in workers', options: { input: 'main', output: { @@ -12,8 +14,8 @@ module.exports = { load(id) { if (id === 'merged' || id === 'nested') { if (!workerId) { - workerId = this.emitEntryChunk('worker'); - proxyId = this.emitEntryChunk('worker-proxy'); + workerId = this.emitChunk('worker'); + proxyId = this.emitChunk('worker-proxy'); } return ` export const getWorkerMessage = () => new Promise(resolve => { @@ -27,13 +29,17 @@ export const getWorkerMessage = () => new Promise(resolve => { }, renderChunk(code, chunk, options) { if (chunk.facadeModuleId === 'worker-proxy') { + const chunkFileName = `./${path.relative( + path.dirname(chunk.fileName), + this.getChunkFileName(workerId) + )}`; if (options.format === 'system') { - return `importScripts('../../../../../../node_modules/systemjs/dist/system.js'); -System.import('./${this.getChunkFileName(workerId)}');`; + return `importScripts('../../../../../../../node_modules/systemjs/dist/system.js'); +System.import('${chunkFileName}');`; } if (options.format === 'amd') { - return `importScripts('../../../../../../node_modules/requirejs/require.js'); -requirejs(['./${this.getChunkFileName(workerId)}']);`; + return `importScripts('../../../../../../../node_modules/requirejs/require.js'); +requirejs(['${chunkFileName}']);`; } } }, diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/amd/chunks/chunk.js b/test/chunking-form/samples/emit-chunk-worker/_expected/amd/chunks/chunk.js similarity index 100% rename from test/chunking-form/samples/emit-entry-worker/_expected/amd/chunks/chunk.js rename to test/chunking-form/samples/emit-chunk-worker/_expected/amd/chunks/chunk.js diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/amd/chunks/chunk2.js b/test/chunking-form/samples/emit-chunk-worker/_expected/amd/chunks/chunk2.js similarity index 68% rename from test/chunking-form/samples/emit-entry-worker/_expected/amd/chunks/chunk2.js rename to test/chunking-form/samples/emit-chunk-worker/_expected/amd/chunks/chunk2.js index a445b0e9849..9ea6f6a2f08 100644 --- a/test/chunking-form/samples/emit-entry-worker/_expected/amd/chunks/chunk2.js +++ b/test/chunking-form/samples/emit-chunk-worker/_expected/amd/chunks/chunk2.js @@ -1,7 +1,7 @@ define(['module', 'exports'], function (module, exports) { 'use strict'; const getWorkerMessage = () => new Promise(resolve => { - const worker = new Worker(new URL(module.uri + '/../../worker-proxy.js', document.baseURI).href); + const worker = new Worker(new URL(module.uri + '/../worker-proxy.js', document.baseURI).href); worker.onmessage = resolve; }); diff --git a/test/chunking-form/samples/emit-chunk-worker/_expected/amd/chunks/worker-proxy.js b/test/chunking-form/samples/emit-chunk-worker/_expected/amd/chunks/worker-proxy.js new file mode 100644 index 00000000000..4f2962c005b --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-worker/_expected/amd/chunks/worker-proxy.js @@ -0,0 +1,2 @@ +importScripts('../../../../../../../node_modules/requirejs/require.js'); +requirejs(['./worker.js']); diff --git a/test/chunking-form/samples/emit-chunk-worker/_expected/amd/chunks/worker.js b/test/chunking-form/samples/emit-chunk-worker/_expected/amd/chunks/worker.js new file mode 100644 index 00000000000..4cfe5e26c29 --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-worker/_expected/amd/chunks/worker.js @@ -0,0 +1,5 @@ +define(['./chunk'], function (__chunk_1) { 'use strict'; + + postMessage(`from worker: ${__chunk_1.shared}`); + +}); diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/amd/main.js b/test/chunking-form/samples/emit-chunk-worker/_expected/amd/main.js similarity index 84% rename from test/chunking-form/samples/emit-entry-worker/_expected/amd/main.js rename to test/chunking-form/samples/emit-chunk-worker/_expected/amd/main.js index 9facbe919ee..7c337df5ec4 100644 --- a/test/chunking-form/samples/emit-entry-worker/_expected/amd/main.js +++ b/test/chunking-form/samples/emit-chunk-worker/_expected/amd/main.js @@ -1,7 +1,7 @@ define(['module', 'require', './chunks/chunk'], function (module, require, __chunk_1) { 'use strict'; const getWorkerMessage = () => new Promise(resolve => { - const worker = new Worker(new URL(module.uri + '/../worker-proxy.js', document.baseURI).href); + const worker = new Worker(new URL(module.uri + '/../chunks/worker-proxy.js', document.baseURI).href); worker.onmessage = resolve; }); diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/cjs/chunks/chunk.js b/test/chunking-form/samples/emit-chunk-worker/_expected/cjs/chunks/chunk.js similarity index 100% rename from test/chunking-form/samples/emit-entry-worker/_expected/cjs/chunks/chunk.js rename to test/chunking-form/samples/emit-chunk-worker/_expected/cjs/chunks/chunk.js diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/cjs/chunks/chunk2.js b/test/chunking-form/samples/emit-chunk-worker/_expected/cjs/chunks/chunk2.js similarity index 51% rename from test/chunking-form/samples/emit-entry-worker/_expected/cjs/chunks/chunk2.js rename to test/chunking-form/samples/emit-chunk-worker/_expected/cjs/chunks/chunk2.js index b04d405dc7a..e7ed919b078 100644 --- a/test/chunking-form/samples/emit-entry-worker/_expected/cjs/chunks/chunk2.js +++ b/test/chunking-form/samples/emit-chunk-worker/_expected/cjs/chunks/chunk2.js @@ -1,7 +1,7 @@ 'use strict'; const getWorkerMessage = () => new Promise(resolve => { - const worker = new Worker((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/../worker-proxy.js').href : new URL((document.currentScript && document.currentScript.src || document.baseURI) + '/../../worker-proxy.js').href)); + const worker = new Worker((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/worker-proxy.js').href : new URL((document.currentScript && document.currentScript.src || document.baseURI) + '/../worker-proxy.js').href)); worker.onmessage = resolve; }); diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/cjs/worker-proxy.js b/test/chunking-form/samples/emit-chunk-worker/_expected/cjs/chunks/worker-proxy.js similarity index 100% rename from test/chunking-form/samples/emit-entry-worker/_expected/cjs/worker-proxy.js rename to test/chunking-form/samples/emit-chunk-worker/_expected/cjs/chunks/worker-proxy.js diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/cjs/worker.js b/test/chunking-form/samples/emit-chunk-worker/_expected/cjs/chunks/worker.js similarity index 58% rename from test/chunking-form/samples/emit-entry-worker/_expected/cjs/worker.js rename to test/chunking-form/samples/emit-chunk-worker/_expected/cjs/chunks/worker.js index c9c2775eacc..3e14edd224a 100644 --- a/test/chunking-form/samples/emit-entry-worker/_expected/cjs/worker.js +++ b/test/chunking-form/samples/emit-chunk-worker/_expected/cjs/chunks/worker.js @@ -1,5 +1,5 @@ 'use strict'; -var __chunk_1 = require('./chunks/chunk.js'); +var __chunk_1 = require('./chunk.js'); postMessage(`from worker: ${__chunk_1.shared}`); diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/cjs/main.js b/test/chunking-form/samples/emit-chunk-worker/_expected/cjs/main.js similarity index 72% rename from test/chunking-form/samples/emit-entry-worker/_expected/cjs/main.js rename to test/chunking-form/samples/emit-chunk-worker/_expected/cjs/main.js index de2e30e9a42..929cf5ec04a 100644 --- a/test/chunking-form/samples/emit-entry-worker/_expected/cjs/main.js +++ b/test/chunking-form/samples/emit-chunk-worker/_expected/cjs/main.js @@ -3,7 +3,7 @@ var __chunk_1 = require('./chunks/chunk.js'); const getWorkerMessage = () => new Promise(resolve => { - const worker = new Worker((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/worker-proxy.js').href : new URL((document.currentScript && document.currentScript.src || document.baseURI) + '/../worker-proxy.js').href)); + const worker = new Worker((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/chunks/worker-proxy.js').href : new URL((document.currentScript && document.currentScript.src || document.baseURI) + '/../chunks/worker-proxy.js').href)); worker.onmessage = resolve; }); diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/es/chunks/chunk.js b/test/chunking-form/samples/emit-chunk-worker/_expected/es/chunks/chunk.js similarity index 100% rename from test/chunking-form/samples/emit-entry-worker/_expected/es/chunks/chunk.js rename to test/chunking-form/samples/emit-chunk-worker/_expected/es/chunks/chunk.js diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/es/chunks/chunk2.js b/test/chunking-form/samples/emit-chunk-worker/_expected/es/chunks/chunk2.js similarity index 59% rename from test/chunking-form/samples/emit-entry-worker/_expected/es/chunks/chunk2.js rename to test/chunking-form/samples/emit-chunk-worker/_expected/es/chunks/chunk2.js index afbe3130f8a..13c379e9742 100644 --- a/test/chunking-form/samples/emit-entry-worker/_expected/es/chunks/chunk2.js +++ b/test/chunking-form/samples/emit-chunk-worker/_expected/es/chunks/chunk2.js @@ -1,5 +1,5 @@ const getWorkerMessage = () => new Promise(resolve => { - const worker = new Worker(new URL('../worker-proxy.js', import.meta.url).href); + const worker = new Worker(new URL('worker-proxy.js', import.meta.url).href); worker.onmessage = resolve; }); diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/es/worker-proxy.js b/test/chunking-form/samples/emit-chunk-worker/_expected/es/chunks/worker-proxy.js similarity index 100% rename from test/chunking-form/samples/emit-entry-worker/_expected/es/worker-proxy.js rename to test/chunking-form/samples/emit-chunk-worker/_expected/es/chunks/worker-proxy.js diff --git a/test/chunking-form/samples/emit-chunk-worker/_expected/es/chunks/worker.js b/test/chunking-form/samples/emit-chunk-worker/_expected/es/chunks/worker.js new file mode 100644 index 00000000000..c3bd7baebed --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-worker/_expected/es/chunks/worker.js @@ -0,0 +1,3 @@ +import { a as shared } from './chunk.js'; + +postMessage(`from worker: ${shared}`); diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/es/main.js b/test/chunking-form/samples/emit-chunk-worker/_expected/es/main.js similarity index 83% rename from test/chunking-form/samples/emit-entry-worker/_expected/es/main.js rename to test/chunking-form/samples/emit-chunk-worker/_expected/es/main.js index f2a6d0756d6..77ab1097b33 100644 --- a/test/chunking-form/samples/emit-entry-worker/_expected/es/main.js +++ b/test/chunking-form/samples/emit-chunk-worker/_expected/es/main.js @@ -1,7 +1,7 @@ import { a as shared } from './chunks/chunk.js'; const getWorkerMessage = () => new Promise(resolve => { - const worker = new Worker(new URL('worker-proxy.js', import.meta.url).href); + const worker = new Worker(new URL('chunks/worker-proxy.js', import.meta.url).href); worker.onmessage = resolve; }); diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/system/chunks/chunk.js b/test/chunking-form/samples/emit-chunk-worker/_expected/system/chunks/chunk.js similarity index 100% rename from test/chunking-form/samples/emit-entry-worker/_expected/system/chunks/chunk.js rename to test/chunking-form/samples/emit-chunk-worker/_expected/system/chunks/chunk.js diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/system/chunks/chunk2.js b/test/chunking-form/samples/emit-chunk-worker/_expected/system/chunks/chunk2.js similarity index 74% rename from test/chunking-form/samples/emit-entry-worker/_expected/system/chunks/chunk2.js rename to test/chunking-form/samples/emit-chunk-worker/_expected/system/chunks/chunk2.js index 81655e5003f..1c41e726447 100644 --- a/test/chunking-form/samples/emit-entry-worker/_expected/system/chunks/chunk2.js +++ b/test/chunking-form/samples/emit-chunk-worker/_expected/system/chunks/chunk2.js @@ -4,7 +4,7 @@ System.register([], function (exports, module) { execute: function () { const getWorkerMessage = exports('getWorkerMessage', () => new Promise(resolve => { - const worker = new Worker(new URL('../worker-proxy.js', module.meta.url).href); + const worker = new Worker(new URL('worker-proxy.js', module.meta.url).href); worker.onmessage = resolve; })); diff --git a/test/chunking-form/samples/emit-chunk-worker/_expected/system/chunks/worker-proxy.js b/test/chunking-form/samples/emit-chunk-worker/_expected/system/chunks/worker-proxy.js new file mode 100644 index 00000000000..44eb3bb9210 --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-worker/_expected/system/chunks/worker-proxy.js @@ -0,0 +1,2 @@ +importScripts('../../../../../../../node_modules/systemjs/dist/system.js'); +System.import('./worker.js'); diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/system/worker.js b/test/chunking-form/samples/emit-chunk-worker/_expected/system/chunks/worker.js similarity index 72% rename from test/chunking-form/samples/emit-entry-worker/_expected/system/worker.js rename to test/chunking-form/samples/emit-chunk-worker/_expected/system/chunks/worker.js index f2964dcc68f..0436f8885e4 100644 --- a/test/chunking-form/samples/emit-entry-worker/_expected/system/worker.js +++ b/test/chunking-form/samples/emit-chunk-worker/_expected/system/chunks/worker.js @@ -1,4 +1,4 @@ -System.register(['./chunks/chunk.js'], function (exports, module) { +System.register(['./chunk.js'], function (exports, module) { 'use strict'; var shared; return { diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/system/main.js b/test/chunking-form/samples/emit-chunk-worker/_expected/system/main.js similarity index 87% rename from test/chunking-form/samples/emit-entry-worker/_expected/system/main.js rename to test/chunking-form/samples/emit-chunk-worker/_expected/system/main.js index f679ae2b1a2..07d1929dae4 100644 --- a/test/chunking-form/samples/emit-entry-worker/_expected/system/main.js +++ b/test/chunking-form/samples/emit-chunk-worker/_expected/system/main.js @@ -8,7 +8,7 @@ System.register(['./chunks/chunk.js'], function (exports, module) { execute: function () { const getWorkerMessage = () => new Promise(resolve => { - const worker = new Worker(new URL('worker-proxy.js', module.meta.url).href); + const worker = new Worker(new URL('chunks/worker-proxy.js', module.meta.url).href); worker.onmessage = resolve; }); diff --git a/test/chunking-form/samples/emit-entry-worker/index-amd.html b/test/chunking-form/samples/emit-chunk-worker/index-amd.html similarity index 100% rename from test/chunking-form/samples/emit-entry-worker/index-amd.html rename to test/chunking-form/samples/emit-chunk-worker/index-amd.html diff --git a/test/chunking-form/samples/emit-entry-worker/index-system.html b/test/chunking-form/samples/emit-chunk-worker/index-system.html similarity index 100% rename from test/chunking-form/samples/emit-entry-worker/index-system.html rename to test/chunking-form/samples/emit-chunk-worker/index-system.html diff --git a/test/chunking-form/samples/emit-entry-worker/main.js b/test/chunking-form/samples/emit-chunk-worker/main.js similarity index 100% rename from test/chunking-form/samples/emit-entry-worker/main.js rename to test/chunking-form/samples/emit-chunk-worker/main.js diff --git a/test/chunking-form/samples/emit-entry-worker/shared.js b/test/chunking-form/samples/emit-chunk-worker/shared.js similarity index 100% rename from test/chunking-form/samples/emit-entry-worker/shared.js rename to test/chunking-form/samples/emit-chunk-worker/shared.js diff --git a/test/chunking-form/samples/emit-entry-worker/worker.js b/test/chunking-form/samples/emit-chunk-worker/worker.js similarity index 100% rename from test/chunking-form/samples/emit-entry-worker/worker.js rename to test/chunking-form/samples/emit-chunk-worker/worker.js diff --git a/test/chunking-form/samples/emit-chunk/_config.js b/test/chunking-form/samples/emit-chunk/_config.js new file mode 100644 index 00000000000..17d8295012b --- /dev/null +++ b/test/chunking-form/samples/emit-chunk/_config.js @@ -0,0 +1,17 @@ +const assert = require('assert'); +let metaId; + +module.exports = { + description: 'allows adding additional chunks and retrieving their file name', + options: { + input: 'main', + plugins: { + buildStart() { + metaId = this.emitChunk('buildStart'); + }, + renderChunk() { + assert.strictEqual(this.getChunkFileName(metaId), 'generated-buildStart.js'); + } + } + } +}; diff --git a/test/chunking-form/samples/emit-entry-chunk/_expected/amd/buildStart.js b/test/chunking-form/samples/emit-chunk/_expected/amd/generated-buildStart.js similarity index 100% rename from test/chunking-form/samples/emit-entry-chunk/_expected/amd/buildStart.js rename to test/chunking-form/samples/emit-chunk/_expected/amd/generated-buildStart.js diff --git a/test/chunking-form/samples/emit-entry-chunk/_expected/amd/generated-chunk.js b/test/chunking-form/samples/emit-chunk/_expected/amd/generated-chunk.js similarity index 100% rename from test/chunking-form/samples/emit-entry-chunk/_expected/amd/generated-chunk.js rename to test/chunking-form/samples/emit-chunk/_expected/amd/generated-chunk.js diff --git a/test/chunking-form/samples/emit-entry-chunk/_expected/amd/main.js b/test/chunking-form/samples/emit-chunk/_expected/amd/main.js similarity index 100% rename from test/chunking-form/samples/emit-entry-chunk/_expected/amd/main.js rename to test/chunking-form/samples/emit-chunk/_expected/amd/main.js diff --git a/test/chunking-form/samples/emit-entry-chunk/_expected/cjs/buildStart.js b/test/chunking-form/samples/emit-chunk/_expected/cjs/generated-buildStart.js similarity index 100% rename from test/chunking-form/samples/emit-entry-chunk/_expected/cjs/buildStart.js rename to test/chunking-form/samples/emit-chunk/_expected/cjs/generated-buildStart.js diff --git a/test/chunking-form/samples/emit-entry-chunk/_expected/cjs/generated-chunk.js b/test/chunking-form/samples/emit-chunk/_expected/cjs/generated-chunk.js similarity index 100% rename from test/chunking-form/samples/emit-entry-chunk/_expected/cjs/generated-chunk.js rename to test/chunking-form/samples/emit-chunk/_expected/cjs/generated-chunk.js diff --git a/test/chunking-form/samples/emit-entry-chunk/_expected/cjs/main.js b/test/chunking-form/samples/emit-chunk/_expected/cjs/main.js similarity index 100% rename from test/chunking-form/samples/emit-entry-chunk/_expected/cjs/main.js rename to test/chunking-form/samples/emit-chunk/_expected/cjs/main.js diff --git a/test/chunking-form/samples/emit-entry-chunk/_expected/es/buildStart.js b/test/chunking-form/samples/emit-chunk/_expected/es/generated-buildStart.js similarity index 100% rename from test/chunking-form/samples/emit-entry-chunk/_expected/es/buildStart.js rename to test/chunking-form/samples/emit-chunk/_expected/es/generated-buildStart.js diff --git a/test/chunking-form/samples/emit-entry-chunk/_expected/es/generated-chunk.js b/test/chunking-form/samples/emit-chunk/_expected/es/generated-chunk.js similarity index 100% rename from test/chunking-form/samples/emit-entry-chunk/_expected/es/generated-chunk.js rename to test/chunking-form/samples/emit-chunk/_expected/es/generated-chunk.js diff --git a/test/chunking-form/samples/emit-entry-chunk/_expected/es/main.js b/test/chunking-form/samples/emit-chunk/_expected/es/main.js similarity index 100% rename from test/chunking-form/samples/emit-entry-chunk/_expected/es/main.js rename to test/chunking-form/samples/emit-chunk/_expected/es/main.js diff --git a/test/chunking-form/samples/emit-entry-chunk/_expected/system/buildStart.js b/test/chunking-form/samples/emit-chunk/_expected/system/generated-buildStart.js similarity index 100% rename from test/chunking-form/samples/emit-entry-chunk/_expected/system/buildStart.js rename to test/chunking-form/samples/emit-chunk/_expected/system/generated-buildStart.js diff --git a/test/chunking-form/samples/emit-entry-chunk/_expected/system/generated-chunk.js b/test/chunking-form/samples/emit-chunk/_expected/system/generated-chunk.js similarity index 100% rename from test/chunking-form/samples/emit-entry-chunk/_expected/system/generated-chunk.js rename to test/chunking-form/samples/emit-chunk/_expected/system/generated-chunk.js diff --git a/test/chunking-form/samples/emit-entry-chunk/_expected/system/main.js b/test/chunking-form/samples/emit-chunk/_expected/system/main.js similarity index 100% rename from test/chunking-form/samples/emit-entry-chunk/_expected/system/main.js rename to test/chunking-form/samples/emit-chunk/_expected/system/main.js diff --git a/test/chunking-form/samples/emit-entry-chunk/buildStart.js b/test/chunking-form/samples/emit-chunk/buildStart.js similarity index 100% rename from test/chunking-form/samples/emit-entry-chunk/buildStart.js rename to test/chunking-form/samples/emit-chunk/buildStart.js diff --git a/test/chunking-form/samples/emit-entry-existing/dep.js b/test/chunking-form/samples/emit-chunk/dep.js similarity index 100% rename from test/chunking-form/samples/emit-entry-existing/dep.js rename to test/chunking-form/samples/emit-chunk/dep.js diff --git a/test/chunking-form/samples/emit-entry-chunk/main.js b/test/chunking-form/samples/emit-chunk/main.js similarity index 100% rename from test/chunking-form/samples/emit-entry-chunk/main.js rename to test/chunking-form/samples/emit-chunk/main.js diff --git a/test/chunking-form/samples/emit-entry-chunk/_config.js b/test/chunking-form/samples/emit-entry-chunk/_config.js deleted file mode 100644 index 9e314116c05..00000000000 --- a/test/chunking-form/samples/emit-entry-chunk/_config.js +++ /dev/null @@ -1,17 +0,0 @@ -const assert = require('assert'); -let metaId; - -module.exports = { - description: 'allows adding additional entry points and retrieving their name', - options: { - input: 'main', - plugins: { - buildStart() { - metaId = this.emitEntryChunk('buildStart'); - }, - renderChunk() { - assert.strictEqual(this.getChunkFileName(metaId), 'buildStart.js'); - } - } - } -}; diff --git a/test/chunking-form/samples/emit-entry-existing/_expected/amd/first-main.js b/test/chunking-form/samples/emit-entry-existing/_expected/amd/first-main.js deleted file mode 100644 index eb85a7017b0..00000000000 --- a/test/chunking-form/samples/emit-entry-existing/_expected/amd/first-main.js +++ /dev/null @@ -1,5 +0,0 @@ -define(['./dep'], function (dep) { 'use strict'; - - console.log('main1', dep); - -}); diff --git a/test/chunking-form/samples/emit-entry-existing/_expected/amd/second-main.js b/test/chunking-form/samples/emit-entry-existing/_expected/amd/second-main.js deleted file mode 100644 index eb85a7017b0..00000000000 --- a/test/chunking-form/samples/emit-entry-existing/_expected/amd/second-main.js +++ /dev/null @@ -1,5 +0,0 @@ -define(['./dep'], function (dep) { 'use strict'; - - console.log('main1', dep); - -}); diff --git a/test/chunking-form/samples/emit-entry-existing/_expected/es/first-main.js b/test/chunking-form/samples/emit-entry-existing/_expected/es/first-main.js deleted file mode 100644 index e384824c6f2..00000000000 --- a/test/chunking-form/samples/emit-entry-existing/_expected/es/first-main.js +++ /dev/null @@ -1,3 +0,0 @@ -import value from './dep.js'; - -console.log('main1', value); diff --git a/test/chunking-form/samples/emit-entry-existing/_expected/es/second-main.js b/test/chunking-form/samples/emit-entry-existing/_expected/es/second-main.js deleted file mode 100644 index e384824c6f2..00000000000 --- a/test/chunking-form/samples/emit-entry-existing/_expected/es/second-main.js +++ /dev/null @@ -1,3 +0,0 @@ -import value from './dep.js'; - -console.log('main1', value); diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/amd/worker-proxy.js b/test/chunking-form/samples/emit-entry-worker/_expected/amd/worker-proxy.js deleted file mode 100644 index 35fe9ceb868..00000000000 --- a/test/chunking-form/samples/emit-entry-worker/_expected/amd/worker-proxy.js +++ /dev/null @@ -1,2 +0,0 @@ -importScripts('../../../../../../node_modules/requirejs/require.js'); -requirejs(['./worker.js']); diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/amd/worker.js b/test/chunking-form/samples/emit-entry-worker/_expected/amd/worker.js deleted file mode 100644 index 6684145758a..00000000000 --- a/test/chunking-form/samples/emit-entry-worker/_expected/amd/worker.js +++ /dev/null @@ -1,5 +0,0 @@ -define(['./chunks/chunk'], function (__chunk_1) { 'use strict'; - - postMessage(`from worker: ${__chunk_1.shared}`); - -}); diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/es/worker.js b/test/chunking-form/samples/emit-entry-worker/_expected/es/worker.js deleted file mode 100644 index b788aa660f4..00000000000 --- a/test/chunking-form/samples/emit-entry-worker/_expected/es/worker.js +++ /dev/null @@ -1,3 +0,0 @@ -import { a as shared } from './chunks/chunk.js'; - -postMessage(`from worker: ${shared}`); diff --git a/test/chunking-form/samples/emit-entry-worker/_expected/system/worker-proxy.js b/test/chunking-form/samples/emit-entry-worker/_expected/system/worker-proxy.js deleted file mode 100644 index dfb005926dd..00000000000 --- a/test/chunking-form/samples/emit-entry-worker/_expected/system/worker-proxy.js +++ /dev/null @@ -1,2 +0,0 @@ -importScripts('../../../../../../node_modules/systemjs/dist/system.js'); -System.import('./worker.js'); diff --git a/test/chunking-form/samples/emit-entry-worker/index-es.html b/test/chunking-form/samples/emit-entry-worker/index-es.html deleted file mode 100644 index 58ae4a61527..00000000000 --- a/test/chunking-form/samples/emit-entry-worker/index-es.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - Title - - - - - diff --git a/test/function/samples/emit-entry-chunk/chunk-filename-not-available/_config.js b/test/function/samples/emit-entry-chunk/chunk-filename-not-available/_config.js index 40ecb0adba8..eda4e487c82 100644 --- a/test/function/samples/emit-entry-chunk/chunk-filename-not-available/_config.js +++ b/test/function/samples/emit-entry-chunk/chunk-filename-not-available/_config.js @@ -5,7 +5,7 @@ module.exports = { plugins: { name: 'test-plugin', buildStart() { - const chunkId = this.emitEntryChunk('chunk.js'); + const chunkId = this.emitChunk('chunk.js'); this.getChunkFileName(chunkId); } } diff --git a/test/function/samples/emit-entry-chunk/chunk-not-found/_config.js b/test/function/samples/emit-entry-chunk/chunk-not-found/_config.js index 8114505869b..46e17ecb5ee 100644 --- a/test/function/samples/emit-entry-chunk/chunk-not-found/_config.js +++ b/test/function/samples/emit-entry-chunk/chunk-not-found/_config.js @@ -4,7 +4,7 @@ module.exports = { input: 'main.js', plugins: { buildStart() { - this.emitEntryChunk('not-found.js'); + this.emitChunk('not-found.js'); } } }, diff --git a/test/function/samples/emit-entry-chunk/modules-loaded/_config.js b/test/function/samples/emit-entry-chunk/modules-loaded/_config.js index 27540891884..1baeb21d1d2 100644 --- a/test/function/samples/emit-entry-chunk/modules-loaded/_config.js +++ b/test/function/samples/emit-entry-chunk/modules-loaded/_config.js @@ -5,14 +5,14 @@ module.exports = { plugins: { name: 'test-plugin', buildEnd() { - this.emitEntryChunk('chunk.js'); + this.emitChunk('chunk.js'); } } }, error: { code: 'PLUGIN_ERROR', hook: 'buildEnd', - message: 'Cannot call emitEntryChunk after module loading has finished.', + message: 'Cannot call emitChunk after module loading has finished.', plugin: 'test-plugin', pluginCode: 'INVALID_ROLLUP_PHASE' } From 12e75896bfad51e274b586ebaadcb0f1bf54925c Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Sun, 21 Apr 2019 11:50:02 +0200 Subject: [PATCH 38/60] Allow emitted chunks to be named --- src/rollup/types.d.ts | 2 +- src/utils/pluginDriver.ts | 34 ++++++++++--------- .../samples/emit-chunk-named/_config.js | 17 ++++++++++ .../_expected/amd/generated-chunk.js | 7 ++++ .../amd/generated-nested/my-chunk.js | 5 +++ .../emit-chunk-named/_expected/amd/main.js | 5 +++ .../_expected/cjs/generated-chunk.js | 5 +++ .../cjs/generated-nested/my-chunk.js | 5 +++ .../emit-chunk-named/_expected/cjs/main.js | 5 +++ .../_expected/es/generated-chunk.js | 3 ++ .../_expected/es/generated-nested/my-chunk.js | 3 ++ .../emit-chunk-named/_expected/es/main.js | 3 ++ .../_expected/system/generated-chunk.js | 10 ++++++ .../system/generated-nested/my-chunk.js | 14 ++++++++ .../emit-chunk-named/_expected/system/main.js | 14 ++++++++ .../samples/emit-chunk-named/buildStart.js | 3 ++ .../samples/emit-chunk-named/dep.js | 1 + .../samples/emit-chunk-named/main.js | 3 ++ 18 files changed, 122 insertions(+), 17 deletions(-) create mode 100644 test/chunking-form/samples/emit-chunk-named/_config.js create mode 100644 test/chunking-form/samples/emit-chunk-named/_expected/amd/generated-chunk.js create mode 100644 test/chunking-form/samples/emit-chunk-named/_expected/amd/generated-nested/my-chunk.js create mode 100644 test/chunking-form/samples/emit-chunk-named/_expected/amd/main.js create mode 100644 test/chunking-form/samples/emit-chunk-named/_expected/cjs/generated-chunk.js create mode 100644 test/chunking-form/samples/emit-chunk-named/_expected/cjs/generated-nested/my-chunk.js create mode 100644 test/chunking-form/samples/emit-chunk-named/_expected/cjs/main.js create mode 100644 test/chunking-form/samples/emit-chunk-named/_expected/es/generated-chunk.js create mode 100644 test/chunking-form/samples/emit-chunk-named/_expected/es/generated-nested/my-chunk.js create mode 100644 test/chunking-form/samples/emit-chunk-named/_expected/es/main.js create mode 100644 test/chunking-form/samples/emit-chunk-named/_expected/system/generated-chunk.js create mode 100644 test/chunking-form/samples/emit-chunk-named/_expected/system/generated-nested/my-chunk.js create mode 100644 test/chunking-form/samples/emit-chunk-named/_expected/system/main.js create mode 100644 test/chunking-form/samples/emit-chunk-named/buildStart.js create mode 100644 test/chunking-form/samples/emit-chunk-named/dep.js create mode 100644 test/chunking-form/samples/emit-chunk-named/main.js diff --git a/src/rollup/types.d.ts b/src/rollup/types.d.ts index cb290696e2d..ecffb3eec3c 100644 --- a/src/rollup/types.d.ts +++ b/src/rollup/types.d.ts @@ -104,7 +104,7 @@ export interface MinimalPluginContext { } export type EmitAsset = (name: string, source?: string | Buffer) => string; -export type EmitChunk = (name: string) => string; +export type EmitChunk = (name: string, options?: { name?: string }) => string; export interface PluginContext extends MinimalPluginContext { addWatchFile: (id: string) => void; diff --git a/src/utils/pluginDriver.ts b/src/utils/pluginDriver.ts index 0ea00aa2d24..0a6484fedef 100644 --- a/src/utils/pluginDriver.ts +++ b/src/utils/pluginDriver.ts @@ -9,7 +9,6 @@ import { PluginCache, PluginContext, PluginHooks, - RollupError, RollupWarning, RollupWatcher, SerializablePluginCache @@ -136,15 +135,7 @@ export function createPluginDriver( } const context: PluginContext = { - emitChunk(id: string) { - if (graph.phase > BuildPhase.LOAD_AND_PARSE) - this.error({ - code: Errors.INVALID_ROLLUP_PHASE, - message: `Cannot call emitChunk after module loading has finished.` - }); - return graph.moduleLoader.addEntryModuleAndGetMetaId({ alias: null, unresolvedId: id }); - }, - addWatchFile(id: string) { + addWatchFile(id) { if (graph.phase >= BuildPhase.GENERATE) this.error({ code: Errors.INVALID_ROLLUP_PHASE, @@ -154,21 +145,32 @@ export function createPluginDriver( }, cache: cacheInstance, emitAsset, - error: (err: RollupError | string) => { + emitChunk(id, options) { + if (graph.phase > BuildPhase.LOAD_AND_PARSE) + this.error({ + code: Errors.INVALID_ROLLUP_PHASE, + message: `Cannot call emitChunk after module loading has finished.` + }); + return graph.moduleLoader.addEntryModuleAndGetMetaId({ + alias: (options && options.name) || null, + unresolvedId: id + }); + }, + error(err) { if (typeof err === 'string') err = { message: err }; if (err.code) err.pluginCode = err.code; err.code = 'PLUGIN_ERROR'; err.plugin = plugin.name || `Plugin at position ${pidx + 1}`; error(err); }, - isExternal(id: string, parentId: string, isResolved = false) { + isExternal(id, parentId, isResolved = false) { return graph.moduleLoader.isExternal(id, parentId, isResolved); }, getAssetFileName, - getChunkFileName(chunkMetaId: string): string { + getChunkFileName(chunkMetaId) { return graph.moduleLoader.getChunkFileName(chunkMetaId); }, - getModuleInfo(moduleId: string) { + getModuleInfo(moduleId) { const foundModule = graph.moduleById.get(moduleId); if (foundModule == null) { throw new Error(`Unable to find module ${moduleId}`); @@ -187,11 +189,11 @@ export function createPluginDriver( }, moduleIds: graph.moduleById.keys(), parse: graph.contextParse, - resolveId(id: string, parent: string) { + resolveId(id, parent) { return pluginDriver.hookFirst('resolveId', [id, parent]); }, setAssetSource, - warn: (warning: RollupWarning | string) => { + warn(warning) { if (typeof warning === 'string') warning = { message: warning } as RollupWarning; if (warning.code) warning.pluginCode = warning.code; warning.code = 'PLUGIN_WARNING'; diff --git a/test/chunking-form/samples/emit-chunk-named/_config.js b/test/chunking-form/samples/emit-chunk-named/_config.js new file mode 100644 index 00000000000..f7c8d65460f --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-named/_config.js @@ -0,0 +1,17 @@ +const assert = require('assert'); +let metaId; + +module.exports = { + description: 'allows naming emitted chunks', + options: { + input: 'main', + plugins: { + buildStart() { + metaId = this.emitChunk('buildStart', { name: 'nested/my-chunk' }); + }, + renderChunk() { + assert.strictEqual(this.getChunkFileName(metaId), 'generated-nested/my-chunk.js'); + } + } + } +}; diff --git a/test/chunking-form/samples/emit-chunk-named/_expected/amd/generated-chunk.js b/test/chunking-form/samples/emit-chunk-named/_expected/amd/generated-chunk.js new file mode 100644 index 00000000000..5e2f9f02968 --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-named/_expected/amd/generated-chunk.js @@ -0,0 +1,7 @@ +define(['exports'], function (exports) { 'use strict'; + + var value = 42; + + exports.value = value; + +}); diff --git a/test/chunking-form/samples/emit-chunk-named/_expected/amd/generated-nested/my-chunk.js b/test/chunking-form/samples/emit-chunk-named/_expected/amd/generated-nested/my-chunk.js new file mode 100644 index 00000000000..9b82e0fcc17 --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-named/_expected/amd/generated-nested/my-chunk.js @@ -0,0 +1,5 @@ +define(['../generated-chunk'], function (__chunk_1) { 'use strict'; + + console.log('startBuild', __chunk_1.value); + +}); diff --git a/test/chunking-form/samples/emit-chunk-named/_expected/amd/main.js b/test/chunking-form/samples/emit-chunk-named/_expected/amd/main.js new file mode 100644 index 00000000000..56bd65658a2 --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-named/_expected/amd/main.js @@ -0,0 +1,5 @@ +define(['./generated-chunk'], function (__chunk_1) { 'use strict'; + + console.log('main', __chunk_1.value); + +}); diff --git a/test/chunking-form/samples/emit-chunk-named/_expected/cjs/generated-chunk.js b/test/chunking-form/samples/emit-chunk-named/_expected/cjs/generated-chunk.js new file mode 100644 index 00000000000..6cec42c9a07 --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-named/_expected/cjs/generated-chunk.js @@ -0,0 +1,5 @@ +'use strict'; + +var value = 42; + +exports.value = value; diff --git a/test/chunking-form/samples/emit-chunk-named/_expected/cjs/generated-nested/my-chunk.js b/test/chunking-form/samples/emit-chunk-named/_expected/cjs/generated-nested/my-chunk.js new file mode 100644 index 00000000000..c193d450be5 --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-named/_expected/cjs/generated-nested/my-chunk.js @@ -0,0 +1,5 @@ +'use strict'; + +var __chunk_1 = require('../generated-chunk.js'); + +console.log('startBuild', __chunk_1.value); diff --git a/test/chunking-form/samples/emit-chunk-named/_expected/cjs/main.js b/test/chunking-form/samples/emit-chunk-named/_expected/cjs/main.js new file mode 100644 index 00000000000..04040e8d4f8 --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-named/_expected/cjs/main.js @@ -0,0 +1,5 @@ +'use strict'; + +var __chunk_1 = require('./generated-chunk.js'); + +console.log('main', __chunk_1.value); diff --git a/test/chunking-form/samples/emit-chunk-named/_expected/es/generated-chunk.js b/test/chunking-form/samples/emit-chunk-named/_expected/es/generated-chunk.js new file mode 100644 index 00000000000..637e70967d1 --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-named/_expected/es/generated-chunk.js @@ -0,0 +1,3 @@ +var value = 42; + +export { value as a }; diff --git a/test/chunking-form/samples/emit-chunk-named/_expected/es/generated-nested/my-chunk.js b/test/chunking-form/samples/emit-chunk-named/_expected/es/generated-nested/my-chunk.js new file mode 100644 index 00000000000..27feabf6e10 --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-named/_expected/es/generated-nested/my-chunk.js @@ -0,0 +1,3 @@ +import { a as value } from '../generated-chunk.js'; + +console.log('startBuild', value); diff --git a/test/chunking-form/samples/emit-chunk-named/_expected/es/main.js b/test/chunking-form/samples/emit-chunk-named/_expected/es/main.js new file mode 100644 index 00000000000..6647a955386 --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-named/_expected/es/main.js @@ -0,0 +1,3 @@ +import { a as value } from './generated-chunk.js'; + +console.log('main', value); diff --git a/test/chunking-form/samples/emit-chunk-named/_expected/system/generated-chunk.js b/test/chunking-form/samples/emit-chunk-named/_expected/system/generated-chunk.js new file mode 100644 index 00000000000..28865ae6188 --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-named/_expected/system/generated-chunk.js @@ -0,0 +1,10 @@ +System.register([], function (exports, module) { + 'use strict'; + return { + execute: function () { + + var value = exports('a', 42); + + } + }; +}); diff --git a/test/chunking-form/samples/emit-chunk-named/_expected/system/generated-nested/my-chunk.js b/test/chunking-form/samples/emit-chunk-named/_expected/system/generated-nested/my-chunk.js new file mode 100644 index 00000000000..2fb89fd0319 --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-named/_expected/system/generated-nested/my-chunk.js @@ -0,0 +1,14 @@ +System.register(['../generated-chunk.js'], function (exports, module) { + 'use strict'; + var value; + return { + setters: [function (module) { + value = module.a; + }], + execute: function () { + + console.log('startBuild', value); + + } + }; +}); diff --git a/test/chunking-form/samples/emit-chunk-named/_expected/system/main.js b/test/chunking-form/samples/emit-chunk-named/_expected/system/main.js new file mode 100644 index 00000000000..9db3c59931a --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-named/_expected/system/main.js @@ -0,0 +1,14 @@ +System.register(['./generated-chunk.js'], function (exports, module) { + 'use strict'; + var value; + return { + setters: [function (module) { + value = module.a; + }], + execute: function () { + + console.log('main', value); + + } + }; +}); diff --git a/test/chunking-form/samples/emit-chunk-named/buildStart.js b/test/chunking-form/samples/emit-chunk-named/buildStart.js new file mode 100644 index 00000000000..f9b1b414da5 --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-named/buildStart.js @@ -0,0 +1,3 @@ +import value from './dep.js'; + +console.log('startBuild', value); diff --git a/test/chunking-form/samples/emit-chunk-named/dep.js b/test/chunking-form/samples/emit-chunk-named/dep.js new file mode 100644 index 00000000000..7a4e8a723a4 --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-named/dep.js @@ -0,0 +1 @@ +export default 42; diff --git a/test/chunking-form/samples/emit-chunk-named/main.js b/test/chunking-form/samples/emit-chunk-named/main.js new file mode 100644 index 00000000000..4a9b3a3f405 --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-named/main.js @@ -0,0 +1,3 @@ +import value from './dep.js'; + +console.log('main', value); From ccceb932841bf498647c3c7b0da0e2d1c5ccbee7 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Mon, 22 Apr 2019 17:49:30 +0200 Subject: [PATCH 39/60] Add paint worklet example --- .../samples/emit-chunk-worklet/_config.js | 28 +++++++++++++++++++ .../_expected/amd/chunks/chunk.js | 9 ++++++ .../_expected/amd/chunks/worklet.js | 17 +++++++++++ .../emit-chunk-worklet/_expected/amd/main.js | 7 +++++ .../_expected/cjs/chunks/chunk.js | 7 +++++ .../_expected/cjs/chunks/worklet.js | 17 +++++++++++ .../emit-chunk-worklet/_expected/cjs/main.js | 7 +++++ .../_expected/es/chunks/chunk.js | 4 +++ .../_expected/es/chunks/worklet.js | 15 ++++++++++ .../emit-chunk-worklet/_expected/es/main.js | 5 ++++ .../_expected/system/chunks/chunk.js | 11 ++++++++ .../_expected/system/chunks/worklet.js | 27 ++++++++++++++++++ .../_expected/system/main.js | 17 +++++++++++ .../samples/emit-chunk-worklet/index-es.html | 10 +++++++ .../samples/emit-chunk-worklet/main.js | 4 +++ .../samples/emit-chunk-worklet/shared.js | 2 ++ .../samples/emit-chunk-worklet/worklet.js | 15 ++++++++++ 17 files changed, 202 insertions(+) create mode 100644 test/chunking-form/samples/emit-chunk-worklet/_config.js create mode 100644 test/chunking-form/samples/emit-chunk-worklet/_expected/amd/chunks/chunk.js create mode 100644 test/chunking-form/samples/emit-chunk-worklet/_expected/amd/chunks/worklet.js create mode 100644 test/chunking-form/samples/emit-chunk-worklet/_expected/amd/main.js create mode 100644 test/chunking-form/samples/emit-chunk-worklet/_expected/cjs/chunks/chunk.js create mode 100644 test/chunking-form/samples/emit-chunk-worklet/_expected/cjs/chunks/worklet.js create mode 100644 test/chunking-form/samples/emit-chunk-worklet/_expected/cjs/main.js create mode 100644 test/chunking-form/samples/emit-chunk-worklet/_expected/es/chunks/chunk.js create mode 100644 test/chunking-form/samples/emit-chunk-worklet/_expected/es/chunks/worklet.js create mode 100644 test/chunking-form/samples/emit-chunk-worklet/_expected/es/main.js create mode 100644 test/chunking-form/samples/emit-chunk-worklet/_expected/system/chunks/chunk.js create mode 100644 test/chunking-form/samples/emit-chunk-worklet/_expected/system/chunks/worklet.js create mode 100644 test/chunking-form/samples/emit-chunk-worklet/_expected/system/main.js create mode 100644 test/chunking-form/samples/emit-chunk-worklet/index-es.html create mode 100644 test/chunking-form/samples/emit-chunk-worklet/main.js create mode 100644 test/chunking-form/samples/emit-chunk-worklet/shared.js create mode 100644 test/chunking-form/samples/emit-chunk-worklet/worklet.js diff --git a/test/chunking-form/samples/emit-chunk-worklet/_config.js b/test/chunking-form/samples/emit-chunk-worklet/_config.js new file mode 100644 index 00000000000..a9579f1f9d8 --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-worklet/_config.js @@ -0,0 +1,28 @@ +const REGISTER_WORKLET = 'register-paint-worklet:'; + +module.exports = { + description: 'allows adding additional chunks to be used in worklets', + options: { + input: 'main', + output: { + chunkFileNames: 'chunks/[name].js' + }, + plugins: { + load(id) { + if (id.startsWith(REGISTER_WORKLET)) { + return `CSS.paintWorklet.addModule(import.meta.ROLLUP_CHUNK_URL_${this.emitChunk( + id.slice(REGISTER_WORKLET.length) + )});`; + } + }, + resolveId(id, importee) { + if (id.startsWith(REGISTER_WORKLET)) { + return this.resolveId(id.slice(REGISTER_WORKLET.length), importee).then( + id => REGISTER_WORKLET + id + ); + } + return null; + } + } + } +}; diff --git a/test/chunking-form/samples/emit-chunk-worklet/_expected/amd/chunks/chunk.js b/test/chunking-form/samples/emit-chunk-worklet/_expected/amd/chunks/chunk.js new file mode 100644 index 00000000000..931cd5869bc --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-worklet/_expected/amd/chunks/chunk.js @@ -0,0 +1,9 @@ +define(['exports'], function (exports) { 'use strict'; + + const color = 'greenyellow'; + const size = 6; + + exports.color = color; + exports.size = size; + +}); diff --git a/test/chunking-form/samples/emit-chunk-worklet/_expected/amd/chunks/worklet.js b/test/chunking-form/samples/emit-chunk-worklet/_expected/amd/chunks/worklet.js new file mode 100644 index 00000000000..6b97d5f9e07 --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-worklet/_expected/amd/chunks/worklet.js @@ -0,0 +1,17 @@ +define(['./chunk'], function (__chunk_1) { 'use strict'; + + registerPaint( + 'vertical-lines', + class { + paint(ctx, geom) { + for (let x = 0; x < geom.width / __chunk_1.size; x++) { + ctx.beginPath(); + ctx.fillStyle = __chunk_1.color; + ctx.rect(x * __chunk_1.size, 0, 2, geom.height); + ctx.fill(); + } + } + } + ); + +}); diff --git a/test/chunking-form/samples/emit-chunk-worklet/_expected/amd/main.js b/test/chunking-form/samples/emit-chunk-worklet/_expected/amd/main.js new file mode 100644 index 00000000000..7cdcf91f2ac --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-worklet/_expected/amd/main.js @@ -0,0 +1,7 @@ +define(['module', './chunks/chunk'], function (module, __chunk_1) { 'use strict'; + + CSS.paintWorklet.addModule(new URL(module.uri + '/../chunks/worklet.js', document.baseURI).href); + + document.body.innerHTML += `

color: ${__chunk_1.color}, size: ${__chunk_1.size}

`; + +}); diff --git a/test/chunking-form/samples/emit-chunk-worklet/_expected/cjs/chunks/chunk.js b/test/chunking-form/samples/emit-chunk-worklet/_expected/cjs/chunks/chunk.js new file mode 100644 index 00000000000..baee02947f7 --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-worklet/_expected/cjs/chunks/chunk.js @@ -0,0 +1,7 @@ +'use strict'; + +const color = 'greenyellow'; +const size = 6; + +exports.color = color; +exports.size = size; diff --git a/test/chunking-form/samples/emit-chunk-worklet/_expected/cjs/chunks/worklet.js b/test/chunking-form/samples/emit-chunk-worklet/_expected/cjs/chunks/worklet.js new file mode 100644 index 00000000000..b3eec36c862 --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-worklet/_expected/cjs/chunks/worklet.js @@ -0,0 +1,17 @@ +'use strict'; + +var __chunk_1 = require('./chunk.js'); + +registerPaint( + 'vertical-lines', + class { + paint(ctx, geom) { + for (let x = 0; x < geom.width / __chunk_1.size; x++) { + ctx.beginPath(); + ctx.fillStyle = __chunk_1.color; + ctx.rect(x * __chunk_1.size, 0, 2, geom.height); + ctx.fill(); + } + } + } +); diff --git a/test/chunking-form/samples/emit-chunk-worklet/_expected/cjs/main.js b/test/chunking-form/samples/emit-chunk-worklet/_expected/cjs/main.js new file mode 100644 index 00000000000..ca4d7d2e014 --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-worklet/_expected/cjs/main.js @@ -0,0 +1,7 @@ +'use strict'; + +var __chunk_1 = require('./chunks/chunk.js'); + +CSS.paintWorklet.addModule((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/chunks/worklet.js').href : new URL((document.currentScript && document.currentScript.src || document.baseURI) + '/../chunks/worklet.js').href)); + +document.body.innerHTML += `

color: ${__chunk_1.color}, size: ${__chunk_1.size}

`; diff --git a/test/chunking-form/samples/emit-chunk-worklet/_expected/es/chunks/chunk.js b/test/chunking-form/samples/emit-chunk-worklet/_expected/es/chunks/chunk.js new file mode 100644 index 00000000000..766aa80086a --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-worklet/_expected/es/chunks/chunk.js @@ -0,0 +1,4 @@ +const color = 'greenyellow'; +const size = 6; + +export { color as a, size as b }; diff --git a/test/chunking-form/samples/emit-chunk-worklet/_expected/es/chunks/worklet.js b/test/chunking-form/samples/emit-chunk-worklet/_expected/es/chunks/worklet.js new file mode 100644 index 00000000000..7e6de10220d --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-worklet/_expected/es/chunks/worklet.js @@ -0,0 +1,15 @@ +import { b as size, a as color } from './chunk.js'; + +registerPaint( + 'vertical-lines', + class { + paint(ctx, geom) { + for (let x = 0; x < geom.width / size; x++) { + ctx.beginPath(); + ctx.fillStyle = color; + ctx.rect(x * size, 0, 2, geom.height); + ctx.fill(); + } + } + } +); diff --git a/test/chunking-form/samples/emit-chunk-worklet/_expected/es/main.js b/test/chunking-form/samples/emit-chunk-worklet/_expected/es/main.js new file mode 100644 index 00000000000..a2e8f846702 --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-worklet/_expected/es/main.js @@ -0,0 +1,5 @@ +import { a as color, b as size } from './chunks/chunk.js'; + +CSS.paintWorklet.addModule(new URL('chunks/worklet.js', import.meta.url).href); + +document.body.innerHTML += `

color: ${color}, size: ${size}

`; diff --git a/test/chunking-form/samples/emit-chunk-worklet/_expected/system/chunks/chunk.js b/test/chunking-form/samples/emit-chunk-worklet/_expected/system/chunks/chunk.js new file mode 100644 index 00000000000..d41169b77d4 --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-worklet/_expected/system/chunks/chunk.js @@ -0,0 +1,11 @@ +System.register([], function (exports, module) { + 'use strict'; + return { + execute: function () { + + const color = exports('a', 'greenyellow'); + const size = exports('b', 6); + + } + }; +}); diff --git a/test/chunking-form/samples/emit-chunk-worklet/_expected/system/chunks/worklet.js b/test/chunking-form/samples/emit-chunk-worklet/_expected/system/chunks/worklet.js new file mode 100644 index 00000000000..0b48cd0f63e --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-worklet/_expected/system/chunks/worklet.js @@ -0,0 +1,27 @@ +System.register(['./chunk.js'], function (exports, module) { + 'use strict'; + var size, color; + return { + setters: [function (module) { + size = module.b; + color = module.a; + }], + execute: function () { + + registerPaint( + 'vertical-lines', + class { + paint(ctx, geom) { + for (let x = 0; x < geom.width / size; x++) { + ctx.beginPath(); + ctx.fillStyle = color; + ctx.rect(x * size, 0, 2, geom.height); + ctx.fill(); + } + } + } + ); + + } + }; +}); diff --git a/test/chunking-form/samples/emit-chunk-worklet/_expected/system/main.js b/test/chunking-form/samples/emit-chunk-worklet/_expected/system/main.js new file mode 100644 index 00000000000..7cf17827eee --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-worklet/_expected/system/main.js @@ -0,0 +1,17 @@ +System.register(['./chunks/chunk.js'], function (exports, module) { + 'use strict'; + var color, size; + return { + setters: [function (module) { + color = module.a; + size = module.b; + }], + execute: function () { + + CSS.paintWorklet.addModule(new URL('chunks/worklet.js', module.meta.url).href); + + document.body.innerHTML += `

color: ${color}, size: ${size}

`; + + } + }; +}); diff --git a/test/chunking-form/samples/emit-chunk-worklet/index-es.html b/test/chunking-form/samples/emit-chunk-worklet/index-es.html new file mode 100644 index 00000000000..af223f6c5c1 --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-worklet/index-es.html @@ -0,0 +1,10 @@ + + + + + ESM + + + + + diff --git a/test/chunking-form/samples/emit-chunk-worklet/main.js b/test/chunking-form/samples/emit-chunk-worklet/main.js new file mode 100644 index 00000000000..60bad6751e8 --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-worklet/main.js @@ -0,0 +1,4 @@ +import 'register-paint-worklet:./worklet.js'; +import { color, size } from './shared'; + +document.body.innerHTML += `

color: ${color}, size: ${size}

`; diff --git a/test/chunking-form/samples/emit-chunk-worklet/shared.js b/test/chunking-form/samples/emit-chunk-worklet/shared.js new file mode 100644 index 00000000000..5a94b80cdd8 --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-worklet/shared.js @@ -0,0 +1,2 @@ +export const color = 'greenyellow'; +export const size = 6; diff --git a/test/chunking-form/samples/emit-chunk-worklet/worklet.js b/test/chunking-form/samples/emit-chunk-worklet/worklet.js new file mode 100644 index 00000000000..2274b010e02 --- /dev/null +++ b/test/chunking-form/samples/emit-chunk-worklet/worklet.js @@ -0,0 +1,15 @@ +import { color, size } from './shared'; + +registerPaint( + 'vertical-lines', + class { + paint(ctx, geom) { + for (let x = 0; x < geom.width / size; x++) { + ctx.beginPath(); + ctx.fillStyle = color; + ctx.rect(x * size, 0, 2, geom.height); + ctx.fill(); + } + } + } +); From 48bc0c16cd47f6d1e4e3cad4f16fdf3b375d4824 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Mon, 22 Apr 2019 18:52:00 +0200 Subject: [PATCH 40/60] Update documentation --- docs/05-plugins.md | 128 ++++++++++++++++++++++++++------ docs/999-big-list-of-options.md | 2 +- 2 files changed, 106 insertions(+), 24 deletions(-) diff --git a/docs/05-plugins.md b/docs/05-plugins.md index 0c966498a48..76897abecc1 100644 --- a/docs/05-plugins.md +++ b/docs/05-plugins.md @@ -179,37 +179,38 @@ Kind: `async, parallel` Called initially each time `bundle.generate()` or `bundle.write()` is called. To get notified when generation has completed, use the `generateBundle` and `renderError` hooks. -#### `resolveAssetUrl` -Type: `({assetFileName: string, relativeAssetPath: string, chunkId: string, moduleId: string, format: string}) => string | null`
+#### `resolveDynamicImport` +Type: `(specifier: string | ESTree.Node, importer: string) => string | false | null`
+Kind: `async, first` + +Defines a custom resolver for dynamic imports. In case a dynamic import is not passed a string as argument, this hook gets access to the raw AST nodes to analyze. Returning `null` will defer to other resolvers and eventually to `resolveId` if this is possible; returning `false` signals that the import should be kept as it is and not be passed to other resolvers thus making it external. Note that the return value of this hook will not be passed to `resolveId` afterwards; if you need access to the static resolution algorithm, you can use `this.resolveId(importee, importer)` on the plugin context. + +#### `resolveFileUrl` +Type: `({chunkId: string, fileName: string, format: string, moduleId: string, relativePath: string, type: 'ASSET' | 'CHUNK}) => string | null`
Kind: `sync, first` -Allows to customize how Rollup resolves URLs of assets emitted via `this.emitAsset` by plugins. By default, Rollup will generate code for `import.meta.ROLLUP_ASSET_URL_[assetId]` that should correctly generate absolute URLs of emitted assets independent of the output format and the host system where the code is deployed. +Allows to customize how Rollup resolves URLs of files that were emitted by plugins via `this.emitAsset` or `this.emitChunk`. By default, Rollup will generate code for `import.meta.ROLLUP_ASSET_URL_assetReferenceId` and `import.meta.ROLLUP_CHUNK_URL_chunkReferenceId` that should correctly generate absolute URLs of emitted files independent of the output format and the host system where the code is deployed. For that, all formats except CommonJS and UMD assume that they run in a browser environment where `URL` and `document` are available. In case that fails or to generate more optimized code, this hook can be used to customize this behaviour. To do that, the following information is available: -- `assetFileName`: The path and file name of the emitted asset, relative to `output.dir` without a leading `./`. -- `relativeAssetPath`: The path and file name of the emitted asset, relative to the chunk from which the asset is referenced via `import.meta.ROLLUP_ASSET_URL_[assetId]`. This will also contain no leading `./` but may contain a leading `../`. -- `moduleId`: The id of the original module this asset is referenced from. Useful for conditionally resolving certain assets differently. -- `chunkId`: The id of the chunk this asset is referenced from. +- `chunkId`: The id of the chunk this file is referenced from. +- `fileName`: The path and file name of the emitted asset, relative to `output.dir` without a leading `./`. - `format`: The rendered output format. +- `moduleId`: The id of the original module this file is referenced from. Useful for conditionally resolving certain assets differently. +- `relativePath`: The path and file name of the emitted file, relative to the chunk the file is referenced from. This will path will contain no leading `./` but may contain a leading `../`. +- `type`: Either `CHUNK` for `import.meta.ROLLUP_CHUNK_URL_chunkReferenceId` or `ASSET` for `import.meta.ROLLUP_ASSET_URL_assetReferenceId`. Note that since this hook has access to the filename of the current chunk, its return value will not be considered when generating the hash of this chunk. -The following plugin will always resolve all assets relative to the current document: +The following plugin will always resolve all files relative to the current document: ```javascript // rollup.config.js -resolveAssetUrl({assetFileName}) { - return `new URL('${assetFileName}', document.baseURI).href`; +resolveFileUrl({fileName}) { + return `new URL('${fileName}', document.baseURI).href`; } ``` -#### `resolveDynamicImport` -Type: `(specifier: string | ESTree.Node, importer: string) => string | false | null`
-Kind: `async, first` - -Defines a custom resolver for dynamic imports. In case a dynamic import is not passed a string as argument, this hook gets access to the raw AST nodes to analyze. Returning `null` will defer to other resolvers and eventually to `resolveId` if this is possible; returning `false` signals that the import should be kept as it is and not be passed to other resolvers thus making it external. Note that the return value of this hook will not be passed to `resolveId` afterwards; if you need access to the static resolution algorithm, you can use `this.resolveId(importee, importer)` on the plugin context. - #### `resolveId` Type: `(importee: string, importer: string) => string | false | null | {id: string, external?: boolean}`
Kind: `async, first` @@ -279,6 +280,8 @@ called when `bundle.generate()` is being executed. called when `bundle.write()` is being executed, after the file has been written to disk. +- `resolveAssetUrl` - _**Use [`resolveFileUrl`](guide/en#resolvefileurl)**_ - Function hook that allows to customize the generated code for asset URLs. + - `transformBundle` – _**Use [`renderChunk`](guide/en#renderchunk)**_ - A `( source, { format } ) => code` or `( source, { format } ) => { code, map }` bundle transformer function. @@ -301,15 +304,31 @@ In general, it is recommended to use `this.addWatchfile` from within the hook th #### `this.emitAsset(assetName: string, source: string) => string` -Emits a custom file to include in the build output, returning its `assetId`. You can defer setting the source if you provide it later via `this.setAssetSource(assetId, source)`. A string or Buffer source must be set for each asset through either method or an error will be thrown on generate completion. +Emits a custom file that is included in the build output, returning an `assetReferenceId` that can be used to reference the emitted file. You can defer setting the source if you provide it later via [`this.setAssetSource(assetReferenceId, source)`](guide/en#this-setassetsource-assetreferenceid-string-source-string-buffer-void). A string or Buffer source must be set for each asset through either method or an error will be thrown on generate completion. + +Emitted assets will follow the [`output.assetFileNames`](guide/en#output-assetfilenames) naming scheme. You can reference the URL of the file in any code returned by a [`load`](guide/en#load) or [`transform`](guide/en#transform) plugin hook via `import.meta.ROLLUP_ASSET_URL_assetReferenceId`. See [Asset URLs](guide/en#asset-urls) for more details and an example. + +The generated code that replaces `import.meta.ROLLUP_ASSET_URL_assetReferenceId` can be customized via the [`resolveFileUrl`](guide/en#resolvefileurl) plugin hook. Once the asset has been finalized during `generate`, you can also use [`this.getAssetFileName(assetReferenceId)`](guide/en#this-getassetfilename-assetreferenceid-string-string) to determine the file name. + +#### `this.emitChunk(moduleId: string, options?: {name?: string}) => string` + +Emits a new chunk with the given module as entry point. This will not result in duplicate modules in the graph, instead if necessary, existing chunks will be split. It returns a `chunkReferenceId` that can be used to later access the generated file name of the chunk. + +Emitted chunks will follow the [`output.chunkFileNames`](guide/en#output-chunkfilenames), [`output.entryFileNames`](guide/en#output-entryfilenames) naming scheme. If a `name` is provided, this will be used for the `[name]` file name placeholder, otherwise the name will be derived from the file name. If a `name` is provided, this name must not conflict with any other entry point names unless the entry points reference the same entry module. You can reference the URL of the emitted chunk in any code returned by a [`load`](guide/en#load) or [`transform`](guide/en#transform) plugin hook via `import.meta.ROLLUP_CHUNK_URL_chunkReferenceId`. + +The generated code that replaces `import.meta.ROLLUP_CHUNK_URL_chunkReferenceId` can be customized via the [`resolveFileUrl`](guide/en#resolvefileurl) plugin hook. Once the chunk has been rendered during `generate`, you can also use [`this.getChunkFileName(chunkReferenceId)`](guide/en#this-getchunkfilename-chunkreferenceid-string-string) to determine the file name. #### `this.error(error: string | Error, position?: number) => void` Structurally equivalent to `this.warn`, except that it will also abort the bundling process. -#### `this.getAssetFileName(assetId: string) => string` +#### `this.getAssetFileName(assetReferenceId: string) => string` + +Get the file name of an asset, according to the `assetFileNames` output option pattern. The file name will be relative to `outputOptions.dir`. -Get the file name of an asset, according to the `assetFileNames` output option pattern. +#### `this.getChunkFileName(chunkReferenceId: string) => string` + +Get the file name of an emitted chunk. The file name will be relative to `outputOptions.dir`. #### `this.getModuleInfo(moduleId: string) => ModuleInfo` @@ -351,7 +370,7 @@ Use Rollup's internal acorn instance to parse code to an AST. Resolve imports to module ids (i.e. file names). Uses the same hooks as Rollup itself. -#### `this.setAssetSource(assetId: string, source: string | Buffer) => void` +#### `this.setAssetSource(assetReferenceId: string, source: string | Buffer) => void` Set the deferred source of an asset. @@ -373,7 +392,7 @@ The `position` argument is a character index where the warning was raised. If pr ### Asset URLs -To reference an asset URL reference from within JS code, use the `import.meta.ROLLUP_ASSET_URL_[assetId]` replacement. This will generate code that depends on the output format and generates a URL that points to the emitted file in the target environment. Note that all formats except CommonJS and UMD assume that they run in a browser environment where `URL` and `document` are available. +To reference an asset URL reference from within JS code, use the `import.meta.ROLLUP_ASSET_URL_assetReferenceId` replacement. This will generate code that depends on the output format and generates a URL that points to the emitted file in the target environment. Note that all formats except CommonJS and UMD assume that they run in a browser environment where `URL` and `document` are available. The following example will detect imports of `.svg` files, emit the imported files as assets, and return their URLs to be used e.g. as the `src` attribute of an `img` tag: @@ -388,11 +407,11 @@ export default function svgResolverPlugin () { }, load(id) { if (id.endsWith('.svg')) { - const assetId = this.emitAsset( + const assetReferenceId = this.emitAsset( path.basename(id), fs.readFileSync(id) ); - return `export default import.meta.ROLLUP_ASSET_URL_${assetId};`; + return `export default import.meta.ROLLUP_ASSET_URL_${assetReferenceId};`; } } }); @@ -405,6 +424,69 @@ image.src = logo; document.body.appendChild(image); ``` +### Chunk URLs + +Similar to assets, emitted chunks can be referenced from within JS code via the `import.meta.ROLLUP_CHUNK_URL_chunkReferenceId` replacement. + +The following example will detect imports prefixed with `register-paint-worklet:` and generate the necessary code and separate chunk to generate a CSS paint worklet. Note that this will only work in modern browsers and will only work if the output format is set to `esm`. + +```js +// plugin +const REGISTER_WORKLET = 'register-paint-worklet:'; +export default function paintWorkletPlugin () { + return ({ + load(id) { + if (id.startsWith(REGISTER_WORKLET)) { + return `CSS.paintWorklet.addModule(import.meta.ROLLUP_CHUNK_URL_${this.emitChunk( + id.slice(REGISTER_WORKLET.length) + )});`; + } + }, + resolveId(id, importee) { + // We remove the prefix, resolve everything to absolute ids and add the prefix again + // This makes sure that you can use relative imports to define worklets + if (id.startsWith(REGISTER_WORKLET)) { + return this.resolveId(id.slice(REGISTER_WORKLET.length), importee).then( + id => REGISTER_WORKLET + id + ); + } + return null; + } + }); +} +``` + +Usage: + +```js +// main.js +import 'register-paint-worklet:./worklet.js'; +import { color, size } from './config.js'; +document.body.innerHTML += `

color: ${color}, size: ${size}

`; + +// worklet.js +import { color, size } from './config.js'; +registerPaint( + 'vertical-lines', + class { + paint(ctx, geom) { + for (let x = 0; x < geom.width / size; x++) { + ctx.beginPath(); + ctx.fillStyle = color; + ctx.rect(x * size, 0, 2, geom.height); + ctx.fill(); + } + } + } +); + +// config.js +export const color = 'greenyellow'; +export const size = 6; +``` + +If you build this code, both the main chunk and the worklet will share the code from `config.js` via a shared chunk. This enables us to make use of the browser cache to reduce transmitted data and speed up loading the worklet. + ### Advanced Loaders The `load` hook can optionally return a `{ code, ast }` object. The `ast` must be a standard ESTree AST with `start` and `end` properties for each node. diff --git a/docs/999-big-list-of-options.md b/docs/999-big-list-of-options.md index ffc103d6839..acd4735a55b 100755 --- a/docs/999-big-list-of-options.md +++ b/docs/999-big-list-of-options.md @@ -322,7 +322,7 @@ The pattern to use for naming custom emitted assets to include in the build outp * `[hash]`: A hash based on the name and content of the asset. * `[name]`: The file name of the asset excluding any extension. -Forward slashes `/` can be used to place files in sub-directories. See also [`output.chunkFileNames`](guide/en#output-chunkfilenames), [`output.entryFileNames`](guide/en#output-entryfilenames). +Forward slashes `/` can be used to place files in sub-directories. See also `[`output.chunkFileNames`](guide/en#output-chunkfilenames)`, [`output.entryFileNames`](guide/en#output-entryfilenames). #### output.banner/output.footer Type: `string | (() => string | Promise)`
From 2b8570dc5bea812266ea7b9c3b2c98f942b52a97 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Tue, 23 Apr 2019 07:13:07 +0200 Subject: [PATCH 41/60] Add reference ids to resolveFileUrl and replace type --- docs/05-plugins.md | 5 +-- src/Graph.ts | 1 - src/Module.ts | 4 +-- src/ModuleLoader.ts | 25 +++++++------- src/ast/nodes/MetaProperty.ts | 24 ++++++++------ src/rollup/types.d.ts | 12 +++---- src/utils/assetHooks.ts | 33 ++++++++++--------- src/utils/error.ts | 12 +++---- src/utils/metaIds.ts | 16 --------- src/utils/pluginDriver.ts | 8 ++--- src/utils/referenceIds.ts | 16 +++++++++ src/utils/transform.ts | 4 +-- .../samples/configure-file-url/_config.js | 12 +++++-- .../_expected/amd/nested/chunk2.js | 4 +-- .../_expected/cjs/nested/chunk2.js | 4 +-- .../_expected/es/nested/chunk2.js | 4 +-- .../_expected/system/nested/chunk2.js | 4 +-- .../samples/emit-chunk-facade/_config.js | 6 ++-- .../samples/emit-chunk-named/_config.js | 6 ++-- .../samples/emit-chunk/_config.js | 6 ++-- .../samples/configure-file-url/_config.js | 12 +++++-- .../configure-file-url/_expected/amd.js | 2 +- .../configure-file-url/_expected/cjs.js | 2 +- .../configure-file-url/_expected/es.js | 2 +- .../configure-file-url/_expected/iife.js | 2 +- .../configure-file-url/_expected/system.js | 2 +- .../configure-file-url/_expected/umd.js | 2 +- 27 files changed, 128 insertions(+), 102 deletions(-) delete mode 100644 src/utils/metaIds.ts create mode 100644 src/utils/referenceIds.ts diff --git a/docs/05-plugins.md b/docs/05-plugins.md index 76897abecc1..0a32d9ba878 100644 --- a/docs/05-plugins.md +++ b/docs/05-plugins.md @@ -186,19 +186,20 @@ Kind: `async, first` Defines a custom resolver for dynamic imports. In case a dynamic import is not passed a string as argument, this hook gets access to the raw AST nodes to analyze. Returning `null` will defer to other resolvers and eventually to `resolveId` if this is possible; returning `false` signals that the import should be kept as it is and not be passed to other resolvers thus making it external. Note that the return value of this hook will not be passed to `resolveId` afterwards; if you need access to the static resolution algorithm, you can use `this.resolveId(importee, importer)` on the plugin context. #### `resolveFileUrl` -Type: `({chunkId: string, fileName: string, format: string, moduleId: string, relativePath: string, type: 'ASSET' | 'CHUNK}) => string | null`
+Type: `({assetReferenceId: string | null, chunkId: string, chunkReferenceId: string | null, fileName: string, format: string, moduleId: string, relativePath: string}) => string | null`
Kind: `sync, first` Allows to customize how Rollup resolves URLs of files that were emitted by plugins via `this.emitAsset` or `this.emitChunk`. By default, Rollup will generate code for `import.meta.ROLLUP_ASSET_URL_assetReferenceId` and `import.meta.ROLLUP_CHUNK_URL_chunkReferenceId` that should correctly generate absolute URLs of emitted files independent of the output format and the host system where the code is deployed. For that, all formats except CommonJS and UMD assume that they run in a browser environment where `URL` and `document` are available. In case that fails or to generate more optimized code, this hook can be used to customize this behaviour. To do that, the following information is available: +- `assetReferenceId`: The asset reference id if we are resolving `import.meta.ROLLUP_ASSET_URL_assetReferenceId`, otherwise `null`. - `chunkId`: The id of the chunk this file is referenced from. +- `chunkReferenceId`: The chunk reference id if we are resolving `import.meta.ROLLUP_CHUNK_URL_chunkReferenceId`, otherwise `null`. - `fileName`: The path and file name of the emitted asset, relative to `output.dir` without a leading `./`. - `format`: The rendered output format. - `moduleId`: The id of the original module this file is referenced from. Useful for conditionally resolving certain assets differently. - `relativePath`: The path and file name of the emitted file, relative to the chunk the file is referenced from. This will path will contain no leading `./` but may contain a leading `../`. -- `type`: Either `CHUNK` for `import.meta.ROLLUP_CHUNK_URL_chunkReferenceId` or `ASSET` for `import.meta.ROLLUP_ASSET_URL_assetReferenceId`. Note that since this hook has access to the filename of the current chunk, its return value will not be considered when generating the hash of this chunk. diff --git a/src/Graph.ts b/src/Graph.ts index 19b0a19ba77..415eee6ee19 100644 --- a/src/Graph.ts +++ b/src/Graph.ts @@ -53,7 +53,6 @@ function normalizeEntryModules( } return Object.keys(entryModules).map(alias => ({ alias, - metaId: null, unresolvedId: entryModules[alias] })); } diff --git a/src/Module.ts b/src/Module.ts index 060d1922f78..b0c82fcb352 100644 --- a/src/Module.ts +++ b/src/Module.ts @@ -88,8 +88,8 @@ export interface AstContext { deoptimizationTracker: EntityPathTracker; error: (props: RollupError, pos: number) => void; fileName: string; - getAssetFileName: (assetMetaId: string) => string; - getChunkFileName: (metaId: string) => string; + getAssetFileName: (assetReferenceId: string) => string; + getChunkFileName: (chunkReferenceId: string) => string; getExports: () => string[]; getModuleExecIndex: () => number; getModuleName: () => string; diff --git a/src/ModuleLoader.ts b/src/ModuleLoader.ts index eb6e1f74c0d..524722ec41d 100644 --- a/src/ModuleLoader.ts +++ b/src/ModuleLoader.ts @@ -13,12 +13,12 @@ import { import { error, errorCannotAssignModuleToChunk, - errorChunkMetaIdNotFoundForFilename, - errorChunkNotGeneratedForFileName + errorChunkNotGeneratedForFileName, + errorChunkReferenceIdNotFoundForFilename } from './utils/error'; -import { addWithNewMetaId } from './utils/metaIds'; import { isRelative, resolve } from './utils/path'; import { PluginDriver } from './utils/pluginDriver'; +import { addWithNewReferenceId } from './utils/referenceIds'; import relativeId, { getAliasName } from './utils/relativeId'; import { timeEnd, timeStart } from './utils/timers'; import transform from './utils/transform'; @@ -38,7 +38,10 @@ function normalizeRelativeExternalId(importee: string, source: string) { export class ModuleLoader { readonly isExternal: IsExternal; - private readonly entriesByMetaId = new Map(); + private readonly entriesByReferenceId = new Map< + string, + { module: Module | null; name: string } + >(); private readonly entryModules: Module[] = []; private readonly graph: Graph; private latestLoadModulesPromise: Promise = Promise.resolve(); @@ -64,14 +67,14 @@ export class ModuleLoader { } } - addEntryModuleAndGetMetaId(unresolvedEntryModule: UnresolvedModuleWithAlias): string { + addEntryModuleAndGetReferenceId(unresolvedEntryModule: UnresolvedModuleWithAlias): string { const entryRecord: { module: Module | null; name: string } = { module: null, name: unresolvedEntryModule.unresolvedId }; - const metaId = addWithNewMetaId( + const referenceId = addWithNewReferenceId( entryRecord, - this.entriesByMetaId, + this.entriesByReferenceId, unresolvedEntryModule.unresolvedId ); this.addEntryModules([unresolvedEntryModule], false) @@ -82,7 +85,7 @@ export class ModuleLoader { // Avoid unhandled Promise rejection as the error will be thrown later // once module loading has finished }); - return metaId; + return referenceId; } addEntryModules( @@ -134,9 +137,9 @@ export class ModuleLoader { return this.awaitLoadModulesPromise(loadNewManualChunkModulesPromise); } - getChunkFileName(metaId: string): string { - const entryRecord = this.entriesByMetaId.get(metaId); - if (!entryRecord) errorChunkMetaIdNotFoundForFilename(metaId); + getChunkFileName(referenceId: string): string { + const entryRecord = this.entriesByReferenceId.get(referenceId); + if (!entryRecord) errorChunkReferenceIdNotFoundForFilename(referenceId); const fileName = entryRecord.module && (entryRecord.module.facadeChunk diff --git a/src/ast/nodes/MetaProperty.ts b/src/ast/nodes/MetaProperty.ts index 5f1a45a072c..08e6dc0047c 100644 --- a/src/ast/nodes/MetaProperty.ts +++ b/src/ast/nodes/MetaProperty.ts @@ -1,5 +1,4 @@ import MagicString from 'magic-string'; -import { EmittedFileType } from '../../rollup/types'; import { dirname, normalize, relative } from '../../utils/path'; import { PluginDriver } from '../../utils/pluginDriver'; import { ObjectPathKey } from '../values'; @@ -44,15 +43,19 @@ export default class MetaProperty extends NodeBase { importMetaProperty && (importMetaProperty.startsWith(ASSET_PREFIX) || importMetaProperty.startsWith(CHUNK_PREFIX)) ) { - const [type, fileName]: [EmittedFileType, string] = importMetaProperty.startsWith( - ASSET_PREFIX - ) - ? ['ASSET', this.context.getAssetFileName(importMetaProperty.substr(ASSET_PREFIX.length))] - : ['CHUNK', this.context.getChunkFileName(importMetaProperty.substr(CHUNK_PREFIX.length))]; - + let assetReferenceId: string | null = null; + let chunkReferenceId: string | null = null; + let fileName: string; + if (importMetaProperty.startsWith(ASSET_PREFIX)) { + assetReferenceId = importMetaProperty.substr(ASSET_PREFIX.length); + fileName = this.context.getAssetFileName(assetReferenceId); + } else { + chunkReferenceId = importMetaProperty.substr(CHUNK_PREFIX.length); + fileName = this.context.getChunkFileName(chunkReferenceId); + } const relativePath = normalize(relative(dirname(chunkId), fileName)); let replacement; - if (type === 'ASSET') { + if (assetReferenceId !== null) { // deprecated hook for assets replacement = pluginDriver.hookFirstSync('resolveAssetUrl', [ { @@ -67,12 +70,13 @@ export default class MetaProperty extends NodeBase { if (!replacement) { replacement = pluginDriver.hookFirstSync<'resolveFileUrl', string>('resolveFileUrl', [ { + assetReferenceId, chunkId, + chunkReferenceId, fileName, format, moduleId: this.context.module.id, - relativePath, - type + relativePath } ]); } diff --git a/src/rollup/types.d.ts b/src/rollup/types.d.ts index ecffb3eec3c..e9f7f70f7d6 100644 --- a/src/rollup/types.d.ts +++ b/src/rollup/types.d.ts @@ -112,8 +112,8 @@ export interface PluginContext extends MinimalPluginContext { emitAsset: EmitAsset; emitChunk: EmitChunk; error: (err: RollupError | string, pos?: { column: number; line: number }) => void; - getAssetFileName: (assetMetaId: string) => string; - getChunkFileName: (chunkMetaId: string) => string; + getAssetFileName: (assetReferenceId: string) => string; + getChunkFileName: (chunkReferenceId: string) => string; getModuleInfo: ( moduleId: string ) => { @@ -125,7 +125,7 @@ export interface PluginContext extends MinimalPluginContext { moduleIds: IterableIterator; parse: (input: string, options: any) => ESTree.Program; resolveId: (id: string, parent: string) => Promise; - setAssetSource: (assetMetaId: string, source: string | Buffer) => void; + setAssetSource: (assetReferenceId: string, source: string | Buffer) => void; warn: (warning: RollupWarning | string, pos?: { column: number; line: number }) => void; /** @deprecated */ watcher: EventEmitter; @@ -214,17 +214,17 @@ export type ResolveAssetUrlHook = ( } ) => string | void; -type EmittedFileType = 'ASSET' | 'CHUNK'; - +// TODO Lukas do not require an input to be present if entries are created dynamically export type ResolveFileUrlHook = ( this: PluginContext, options: { + assetReferenceId: string | null; chunkId: string; + chunkReferenceId: string | null; fileName: string; format: string; moduleId: string; relativePath: string; - type: EmittedFileType; } ) => string | void; diff --git a/src/utils/assetHooks.ts b/src/utils/assetHooks.ts index 6eedc42b45c..3d3b66a0be4 100644 --- a/src/utils/assetHooks.ts +++ b/src/utils/assetHooks.ts @@ -1,16 +1,16 @@ import sha256 from 'hash.js/lib/hash/sha/256'; import { Asset, EmitAsset, OutputBundle } from '../rollup/types'; import { - errorAssetMetaIdNotFoundForFilename, - errorAssetMetaIdNotFoundForSetSource, errorAssetNotFinalisedForFileName, + errorAssetReferenceIdNotFoundForFilename, + errorAssetReferenceIdNotFoundForSetSource, errorAssetSourceAlreadySet, errorAssetSourceMissingForSetSource, errorInvalidAssetName, errorNoAssetSourceSet } from './error'; -import { addWithNewMetaId } from './metaIds'; import { extname } from './path'; +import { addWithNewReferenceId } from './referenceIds'; import { isPlainName } from './relativeId'; import { makeUnique, renderNamePattern } from './renderNamePattern'; @@ -44,7 +44,7 @@ export function getAssetFileName( } export function createAssetPluginHooks( - assetsByMetaId: Map, + assetsByReferenceId: Map, outputBundle?: OutputBundle, assetFileNames?: string ) { @@ -53,21 +53,21 @@ export function createAssetPluginHooks( if (typeof name !== 'string' || !isPlainName(name)) errorInvalidAssetName(name); const asset: Asset = { name, source, fileName: undefined }; if (outputBundle && source !== undefined) finaliseAsset(asset, outputBundle, assetFileNames); - return addWithNewMetaId(asset, assetsByMetaId, name); + return addWithNewReferenceId(asset, assetsByReferenceId, name); }, - setAssetSource(assetMetaId: string, source?: string | Buffer) { - const asset = assetsByMetaId.get(assetMetaId); - if (!asset) errorAssetMetaIdNotFoundForSetSource(assetMetaId); + setAssetSource(assetReferenceId: string, source?: string | Buffer) { + const asset = assetsByReferenceId.get(assetReferenceId); + if (!asset) errorAssetReferenceIdNotFoundForSetSource(assetReferenceId); if (asset.source !== undefined) errorAssetSourceAlreadySet(asset); if (typeof source !== 'string' && !source) errorAssetSourceMissingForSetSource(asset); asset.source = source; if (outputBundle) finaliseAsset(asset, outputBundle, assetFileNames); }, - getAssetFileName(assetMetaId: string) { - const asset = assetsByMetaId.get(assetMetaId); - if (!asset) errorAssetMetaIdNotFoundForFilename(assetMetaId); + getAssetFileName(assetReferenceId: string) { + const asset = assetsByReferenceId.get(assetReferenceId); + if (!asset) errorAssetReferenceIdNotFoundForFilename(assetReferenceId); if (asset.fileName === undefined) errorAssetNotFinalisedForFileName(asset); return asset.fileName; } @@ -84,19 +84,22 @@ export function finaliseAsset(asset: Asset, outputBundle: OutputBundle, assetFil }; } -export function createTransformEmitAsset(assetsByMetaId: Map, emitAsset: EmitAsset) { +export function createTransformEmitAsset( + assetsByReferenceId: Map, + emitAsset: EmitAsset +) { const assets: Asset[] = []; return { assets, emitAsset: (name: string, source?: string | Buffer) => { - const assetMetaId = emitAsset(name, source); - const asset = assetsByMetaId.get(assetMetaId); + const assetReferenceId = emitAsset(name, source); + const asset = assetsByReferenceId.get(assetReferenceId); assets.push({ fileName: undefined, name: asset.name, source: asset.source }); - return assetMetaId; + return assetReferenceId; } }; } diff --git a/src/utils/error.ts b/src/utils/error.ts index 4fbddb8de27..dd2fe14e979 100644 --- a/src/utils/error.ts +++ b/src/utils/error.ts @@ -60,17 +60,17 @@ export function errorChunkNotGeneratedForFileName(entry: { name: string }) { }); } -export function errorAssetMetaIdNotFoundForFilename(assetMetaId: string) { +export function errorAssetReferenceIdNotFoundForFilename(assetReferenceId: string) { error({ code: Errors.ASSET_NOT_FOUND, - message: `Plugin error - Unable to get file name for unknown asset "${assetMetaId}".` + message: `Plugin error - Unable to get file name for unknown asset "${assetReferenceId}".` }); } -export function errorAssetMetaIdNotFoundForSetSource(assetMetaId: string) { +export function errorAssetReferenceIdNotFoundForSetSource(assetReferenceId: string) { error({ code: Errors.ASSET_NOT_FOUND, - message: `Plugin error - Unable to set the source for unknown asset "${assetMetaId}".` + message: `Plugin error - Unable to set the source for unknown asset "${assetReferenceId}".` }); } @@ -97,10 +97,10 @@ export function errorNoAssetSourceSet(asset: Asset) { }); } -export function errorChunkMetaIdNotFoundForFilename(chunkMetaId: string) { +export function errorChunkReferenceIdNotFoundForFilename(chunkReferenceId: string) { error({ code: Errors.CHUNK_NOT_FOUND, - message: `Plugin error - Unable to get file name for unknown chunk "${chunkMetaId}".` + message: `Plugin error - Unable to get file name for unknown chunk "${chunkReferenceId}".` }); } diff --git a/src/utils/metaIds.ts b/src/utils/metaIds.ts deleted file mode 100644 index ff6e0164f9a..00000000000 --- a/src/utils/metaIds.ts +++ /dev/null @@ -1,16 +0,0 @@ -import sha256 from 'hash.js/lib/hash/sha/256'; - -export function addWithNewMetaId(item: T, idMap: Map, hashBase: string): string { - let metaId: string; - do { - const hash = sha256(); - if (metaId) { - hash.update(metaId); - } else { - hash.update(hashBase); - } - metaId = hash.digest('hex').substr(0, 8); - } while (idMap.has(metaId)); - idMap.set(metaId, item); - return metaId; -} diff --git a/src/utils/pluginDriver.ts b/src/utils/pluginDriver.ts index 0a6484fedef..f1464e0171b 100644 --- a/src/utils/pluginDriver.ts +++ b/src/utils/pluginDriver.ts @@ -24,7 +24,7 @@ type Args = T extends (...args: infer K) => any ? K : never; export interface PluginDriver { emitAsset: EmitAsset; hasLoadersOrTransforms: boolean; - getAssetFileName(assetMetaId: string): string; + getAssetFileName(assetReferenceId: string): string; hookFirst>( hook: H, args: Args, @@ -151,7 +151,7 @@ export function createPluginDriver( code: Errors.INVALID_ROLLUP_PHASE, message: `Cannot call emitChunk after module loading has finished.` }); - return graph.moduleLoader.addEntryModuleAndGetMetaId({ + return graph.moduleLoader.addEntryModuleAndGetReferenceId({ alias: (options && options.name) || null, unresolvedId: id }); @@ -167,8 +167,8 @@ export function createPluginDriver( return graph.moduleLoader.isExternal(id, parentId, isResolved); }, getAssetFileName, - getChunkFileName(chunkMetaId) { - return graph.moduleLoader.getChunkFileName(chunkMetaId); + getChunkFileName(chunkReferenceId) { + return graph.moduleLoader.getChunkFileName(chunkReferenceId); }, getModuleInfo(moduleId) { const foundModule = graph.moduleById.get(moduleId); diff --git a/src/utils/referenceIds.ts b/src/utils/referenceIds.ts new file mode 100644 index 00000000000..a7daf938468 --- /dev/null +++ b/src/utils/referenceIds.ts @@ -0,0 +1,16 @@ +import sha256 from 'hash.js/lib/hash/sha/256'; + +export function addWithNewReferenceId(item: T, idMap: Map, hashBase: string): string { + let referenceId: string; + do { + const hash = sha256(); + if (referenceId) { + hash.update(referenceId); + } else { + hash.update(hashBase); + } + referenceId = hash.digest('hex').substr(0, 8); + } while (idMap.has(referenceId)); + idMap.set(referenceId, item); + return referenceId; +} diff --git a/src/utils/transform.ts b/src/utils/transform.ts index 782b622b657..21b32dda282 100644 --- a/src/utils/transform.ts +++ b/src/utils/transform.ts @@ -133,8 +133,8 @@ export default function transform( transformDependencies.push(id); pluginContext.addWatchFile(id); }, - setAssetSource(assetMetaId, source) { - pluginContext.setAssetSource(assetMetaId, source); + setAssetSource(assetReferenceId, source) { + pluginContext.setAssetSource(assetReferenceId, source); if (!customTransformCache && !setAssetSourceErr) { try { this.error({ diff --git a/test/chunking-form/samples/configure-file-url/_config.js b/test/chunking-form/samples/configure-file-url/_config.js index 947874f3214..9ee4fa22535 100644 --- a/test/chunking-form/samples/configure-file-url/_config.js +++ b/test/chunking-form/samples/configure-file-url/_config.js @@ -21,7 +21,15 @@ module.exports = { ); } }, - resolveFileUrl({ chunkId, fileName, format, moduleId, relativePath, type }) { + resolveFileUrl({ + assetReferenceId, + chunkId, + chunkReferenceId, + fileName, + format, + moduleId, + relativePath + }) { if (!moduleId.endsWith('resolved')) { return `'chunkId=${chunkId}:moduleId=${moduleId .replace(/\\/g, '/') @@ -29,7 +37,7 @@ module.exports = { .slice(-2) .join( '/' - )}:fileName=${fileName}:format=${format}:relativePath=${relativePath}:type=${type}'`; + )}:fileName=${fileName}:format=${format}:relativePath=${relativePath}:assetReferenceId=${assetReferenceId}:chunkReferenceId=${chunkReferenceId}'`; } return null; } diff --git a/test/chunking-form/samples/configure-file-url/_expected/amd/nested/chunk2.js b/test/chunking-form/samples/configure-file-url/_expected/amd/nested/chunk2.js index 10eb3a989a2..6adfcf6b0fe 100644 --- a/test/chunking-form/samples/configure-file-url/_expected/amd/nested/chunk2.js +++ b/test/chunking-form/samples/configure-file-url/_expected/amd/nested/chunk2.js @@ -1,7 +1,7 @@ define(['module', 'exports'], function (module, exports) { 'use strict'; - const asset = 'chunkId=nested/chunk2.js:moduleId=solved:fileName=assets/asset-solved-9b321da2.txt:format=amd:relativePath=../assets/asset-solved-9b321da2.txt:type=ASSET' - const chunk = 'chunkId=nested/chunk2.js:moduleId=solved:fileName=nested/chunk.js:format=amd:relativePath=chunk.js:type=CHUNK' + const asset = 'chunkId=nested/chunk2.js:moduleId=solved:fileName=assets/asset-solved-9b321da2.txt:format=amd:relativePath=../assets/asset-solved-9b321da2.txt:assetReferenceId=6296c678:chunkReferenceId=null' + const chunk = 'chunkId=nested/chunk2.js:moduleId=solved:fileName=nested/chunk.js:format=amd:relativePath=chunk.js:assetReferenceId=null:chunkReferenceId=f6c25ae7' exports.asset = asset; exports.chunk = chunk; diff --git a/test/chunking-form/samples/configure-file-url/_expected/cjs/nested/chunk2.js b/test/chunking-form/samples/configure-file-url/_expected/cjs/nested/chunk2.js index c01786fabc8..9c12e75444e 100644 --- a/test/chunking-form/samples/configure-file-url/_expected/cjs/nested/chunk2.js +++ b/test/chunking-form/samples/configure-file-url/_expected/cjs/nested/chunk2.js @@ -1,7 +1,7 @@ 'use strict'; -const asset = 'chunkId=nested/chunk2.js:moduleId=solved:fileName=assets/asset-solved-9b321da2.txt:format=cjs:relativePath=../assets/asset-solved-9b321da2.txt:type=ASSET' -const chunk = 'chunkId=nested/chunk2.js:moduleId=solved:fileName=nested/chunk.js:format=cjs:relativePath=chunk.js:type=CHUNK' +const asset = 'chunkId=nested/chunk2.js:moduleId=solved:fileName=assets/asset-solved-9b321da2.txt:format=cjs:relativePath=../assets/asset-solved-9b321da2.txt:assetReferenceId=6296c678:chunkReferenceId=null' +const chunk = 'chunkId=nested/chunk2.js:moduleId=solved:fileName=nested/chunk.js:format=cjs:relativePath=chunk.js:assetReferenceId=null:chunkReferenceId=f6c25ae7' exports.asset = asset; exports.chunk = chunk; diff --git a/test/chunking-form/samples/configure-file-url/_expected/es/nested/chunk2.js b/test/chunking-form/samples/configure-file-url/_expected/es/nested/chunk2.js index 7269cd9eb94..11a45614417 100644 --- a/test/chunking-form/samples/configure-file-url/_expected/es/nested/chunk2.js +++ b/test/chunking-form/samples/configure-file-url/_expected/es/nested/chunk2.js @@ -1,4 +1,4 @@ -const asset = 'chunkId=nested/chunk2.js:moduleId=solved:fileName=assets/asset-solved-9b321da2.txt:format=es:relativePath=../assets/asset-solved-9b321da2.txt:type=ASSET' -const chunk = 'chunkId=nested/chunk2.js:moduleId=solved:fileName=nested/chunk.js:format=es:relativePath=chunk.js:type=CHUNK' +const asset = 'chunkId=nested/chunk2.js:moduleId=solved:fileName=assets/asset-solved-9b321da2.txt:format=es:relativePath=../assets/asset-solved-9b321da2.txt:assetReferenceId=6296c678:chunkReferenceId=null' +const chunk = 'chunkId=nested/chunk2.js:moduleId=solved:fileName=nested/chunk.js:format=es:relativePath=chunk.js:assetReferenceId=null:chunkReferenceId=f6c25ae7' export { asset, chunk }; diff --git a/test/chunking-form/samples/configure-file-url/_expected/system/nested/chunk2.js b/test/chunking-form/samples/configure-file-url/_expected/system/nested/chunk2.js index ace995589af..c0df71d70a9 100644 --- a/test/chunking-form/samples/configure-file-url/_expected/system/nested/chunk2.js +++ b/test/chunking-form/samples/configure-file-url/_expected/system/nested/chunk2.js @@ -3,8 +3,8 @@ System.register([], function (exports, module) { return { execute: function () { - const asset = exports('asset', 'chunkId=nested/chunk2.js:moduleId=solved:fileName=assets/asset-solved-9b321da2.txt:format=system:relativePath=../assets/asset-solved-9b321da2.txt:type=ASSET' - const chunk = exports('chunk', 'chunkId=nested/chunk2.js:moduleId=solved:fileName=nested/chunk.js:format=system:relativePath=chunk.js:type=CHUNK' + const asset = exports('asset', 'chunkId=nested/chunk2.js:moduleId=solved:fileName=assets/asset-solved-9b321da2.txt:format=system:relativePath=../assets/asset-solved-9b321da2.txt:assetReferenceId=6296c678:chunkReferenceId=null' + const chunk = exports('chunk', 'chunkId=nested/chunk2.js:moduleId=solved:fileName=nested/chunk.js:format=system:relativePath=chunk.js:assetReferenceId=null:chunkReferenceId=f6c25ae7' } }; diff --git a/test/chunking-form/samples/emit-chunk-facade/_config.js b/test/chunking-form/samples/emit-chunk-facade/_config.js index 298c350d86c..4f15ed7ab82 100644 --- a/test/chunking-form/samples/emit-chunk-facade/_config.js +++ b/test/chunking-form/samples/emit-chunk-facade/_config.js @@ -1,5 +1,5 @@ const assert = require('assert'); -let metaId; +let referenceId; module.exports = { description: 'retrieves the correct name of an emitted chunk in case a facade is created', @@ -10,10 +10,10 @@ module.exports = { }, plugins: { buildStart() { - metaId = this.emitChunk('buildStart'); + referenceId = this.emitChunk('buildStart'); }, renderChunk() { - assert.strictEqual(this.getChunkFileName(metaId), 'generated-buildStart.js'); + assert.strictEqual(this.getChunkFileName(referenceId), 'generated-buildStart.js'); } } } diff --git a/test/chunking-form/samples/emit-chunk-named/_config.js b/test/chunking-form/samples/emit-chunk-named/_config.js index f7c8d65460f..8b171c6146e 100644 --- a/test/chunking-form/samples/emit-chunk-named/_config.js +++ b/test/chunking-form/samples/emit-chunk-named/_config.js @@ -1,5 +1,5 @@ const assert = require('assert'); -let metaId; +let referenceId; module.exports = { description: 'allows naming emitted chunks', @@ -7,10 +7,10 @@ module.exports = { input: 'main', plugins: { buildStart() { - metaId = this.emitChunk('buildStart', { name: 'nested/my-chunk' }); + referenceId = this.emitChunk('buildStart', { name: 'nested/my-chunk' }); }, renderChunk() { - assert.strictEqual(this.getChunkFileName(metaId), 'generated-nested/my-chunk.js'); + assert.strictEqual(this.getChunkFileName(referenceId), 'generated-nested/my-chunk.js'); } } } diff --git a/test/chunking-form/samples/emit-chunk/_config.js b/test/chunking-form/samples/emit-chunk/_config.js index 17d8295012b..225c6722e8e 100644 --- a/test/chunking-form/samples/emit-chunk/_config.js +++ b/test/chunking-form/samples/emit-chunk/_config.js @@ -1,5 +1,5 @@ const assert = require('assert'); -let metaId; +let referenceId; module.exports = { description: 'allows adding additional chunks and retrieving their file name', @@ -7,10 +7,10 @@ module.exports = { input: 'main', plugins: { buildStart() { - metaId = this.emitChunk('buildStart'); + referenceId = this.emitChunk('buildStart'); }, renderChunk() { - assert.strictEqual(this.getChunkFileName(metaId), 'generated-buildStart.js'); + assert.strictEqual(this.getChunkFileName(referenceId), 'generated-buildStart.js'); } } } diff --git a/test/form/samples/configure-file-url/_config.js b/test/form/samples/configure-file-url/_config.js index 5fb186f12db..51f63117e90 100644 --- a/test/form/samples/configure-file-url/_config.js +++ b/test/form/samples/configure-file-url/_config.js @@ -14,7 +14,15 @@ module.exports = { return `export default import.meta.ROLLUP_ASSET_URL_${assetId};`; } }, - resolveFileUrl({ chunkId, fileName, format, moduleId, relativePath, type }) { + resolveFileUrl({ + assetReferenceId, + chunkId, + chunkReferenceId, + fileName, + format, + moduleId, + relativePath + }) { if (!moduleId.endsWith('resolved')) { return `'chunkId=${chunkId}:moduleId=${moduleId .replace(/\\/g, '/') @@ -22,7 +30,7 @@ module.exports = { .slice(-2) .join( '/' - )}:fileName=${fileName}:format=${format}:relativePath=${relativePath}:type=${type}'`; + )}:fileName=${fileName}:format=${format}:relativePath=${relativePath}:assetReferenceId=${assetReferenceId}:chunkReferenceId=${chunkReferenceId}'`; } return null; } diff --git a/test/form/samples/configure-file-url/_expected/amd.js b/test/form/samples/configure-file-url/_expected/amd.js index 19b03cfac12..4f17cacf559 100644 --- a/test/form/samples/configure-file-url/_expected/amd.js +++ b/test/form/samples/configure-file-url/_expected/amd.js @@ -1,6 +1,6 @@ define(['module'], function (module) { 'use strict'; - var asset1 = 'chunkId=amd.js:moduleId=solved:fileName=assets/asset-solved-9b321da2.txt:format=amd:relativePath=assets/asset-solved-9b321da2.txt:type=ASSET'; + var asset1 = 'chunkId=amd.js:moduleId=solved:fileName=assets/asset-solved-9b321da2.txt:format=amd:relativePath=assets/asset-solved-9b321da2.txt:assetReferenceId=6296c678:chunkReferenceId=null'; var asset2 = 'resolved'; diff --git a/test/form/samples/configure-file-url/_expected/cjs.js b/test/form/samples/configure-file-url/_expected/cjs.js index 5ecf4d8ddeb..0cd0cf76d41 100644 --- a/test/form/samples/configure-file-url/_expected/cjs.js +++ b/test/form/samples/configure-file-url/_expected/cjs.js @@ -1,6 +1,6 @@ 'use strict'; -var asset1 = 'chunkId=cjs.js:moduleId=solved:fileName=assets/asset-solved-9b321da2.txt:format=cjs:relativePath=assets/asset-solved-9b321da2.txt:type=ASSET'; +var asset1 = 'chunkId=cjs.js:moduleId=solved:fileName=assets/asset-solved-9b321da2.txt:format=cjs:relativePath=assets/asset-solved-9b321da2.txt:assetReferenceId=6296c678:chunkReferenceId=null'; var asset2 = 'resolved'; diff --git a/test/form/samples/configure-file-url/_expected/es.js b/test/form/samples/configure-file-url/_expected/es.js index 32e91325fed..df7dcc61d02 100644 --- a/test/form/samples/configure-file-url/_expected/es.js +++ b/test/form/samples/configure-file-url/_expected/es.js @@ -1,4 +1,4 @@ -var asset1 = 'chunkId=es.js:moduleId=solved:fileName=assets/asset-solved-9b321da2.txt:format=es:relativePath=assets/asset-solved-9b321da2.txt:type=ASSET'; +var asset1 = 'chunkId=es.js:moduleId=solved:fileName=assets/asset-solved-9b321da2.txt:format=es:relativePath=assets/asset-solved-9b321da2.txt:assetReferenceId=6296c678:chunkReferenceId=null'; var asset2 = 'resolved'; diff --git a/test/form/samples/configure-file-url/_expected/iife.js b/test/form/samples/configure-file-url/_expected/iife.js index fc1bd600210..08bb0ddca71 100644 --- a/test/form/samples/configure-file-url/_expected/iife.js +++ b/test/form/samples/configure-file-url/_expected/iife.js @@ -1,7 +1,7 @@ (function () { 'use strict'; - var asset1 = 'chunkId=iife.js:moduleId=solved:fileName=assets/asset-solved-9b321da2.txt:format=iife:relativePath=assets/asset-solved-9b321da2.txt:type=ASSET'; + var asset1 = 'chunkId=iife.js:moduleId=solved:fileName=assets/asset-solved-9b321da2.txt:format=iife:relativePath=assets/asset-solved-9b321da2.txt:assetReferenceId=6296c678:chunkReferenceId=null'; var asset2 = 'resolved'; diff --git a/test/form/samples/configure-file-url/_expected/system.js b/test/form/samples/configure-file-url/_expected/system.js index 054f8a7dda6..b819b26364a 100644 --- a/test/form/samples/configure-file-url/_expected/system.js +++ b/test/form/samples/configure-file-url/_expected/system.js @@ -3,7 +3,7 @@ System.register([], function (exports, module) { return { execute: function () { - var asset1 = 'chunkId=system.js:moduleId=solved:fileName=assets/asset-solved-9b321da2.txt:format=system:relativePath=assets/asset-solved-9b321da2.txt:type=ASSET'; + var asset1 = 'chunkId=system.js:moduleId=solved:fileName=assets/asset-solved-9b321da2.txt:format=system:relativePath=assets/asset-solved-9b321da2.txt:assetReferenceId=6296c678:chunkReferenceId=null'; var asset2 = 'resolved'; diff --git a/test/form/samples/configure-file-url/_expected/umd.js b/test/form/samples/configure-file-url/_expected/umd.js index c46f7a66d1a..ce104bada6e 100644 --- a/test/form/samples/configure-file-url/_expected/umd.js +++ b/test/form/samples/configure-file-url/_expected/umd.js @@ -3,7 +3,7 @@ factory(); }(function () { 'use strict'; - var asset1 = 'chunkId=umd.js:moduleId=solved:fileName=assets/asset-solved-9b321da2.txt:format=umd:relativePath=assets/asset-solved-9b321da2.txt:type=ASSET'; + var asset1 = 'chunkId=umd.js:moduleId=solved:fileName=assets/asset-solved-9b321da2.txt:format=umd:relativePath=assets/asset-solved-9b321da2.txt:assetReferenceId=6296c678:chunkReferenceId=null'; var asset2 = 'resolved'; From 738d6caa3f561c3eb45e09197f12c51c02555385 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Tue, 23 Apr 2019 07:42:38 +0200 Subject: [PATCH 42/60] Do not require `input` to be set if a dynamic entry is emitted --- src/Graph.ts | 7 +++---- src/finalisers/amd.ts | 2 +- src/rollup/index.ts | 2 +- src/rollup/types.d.ts | 3 +-- src/utils/mergeOptions.ts | 4 ++-- src/watch/index.ts | 14 ++++++++------ .../chunk-filename-not-available/_config.js | 0 .../chunk-filename-not-available/chunk.js | 0 .../chunk-filename-not-available/main.js | 0 .../chunk-not-found/_config.js | 0 .../chunk-not-found/main.js | 0 .../invalid-chunk-id/_config.js | 0 .../invalid-chunk-id/main.js | 0 .../modules-loaded/_config.js | 0 .../modules-loaded/chunk.js | 0 .../modules-loaded/main.js | 0 .../samples/emit-chunk/no-input/_config.js | 12 ++++++++++++ test/function/samples/emit-chunk/no-input/chunk.js | 1 + 18 files changed, 29 insertions(+), 16 deletions(-) rename test/function/samples/{emit-entry-chunk => emit-chunk}/chunk-filename-not-available/_config.js (100%) rename test/function/samples/{emit-entry-chunk => emit-chunk}/chunk-filename-not-available/chunk.js (100%) rename test/function/samples/{emit-entry-chunk => emit-chunk}/chunk-filename-not-available/main.js (100%) rename test/function/samples/{emit-entry-chunk => emit-chunk}/chunk-not-found/_config.js (100%) rename test/function/samples/{emit-entry-chunk => emit-chunk}/chunk-not-found/main.js (100%) rename test/function/samples/{emit-entry-chunk => emit-chunk}/invalid-chunk-id/_config.js (100%) rename test/function/samples/{emit-entry-chunk => emit-chunk}/invalid-chunk-id/main.js (100%) rename test/function/samples/{emit-entry-chunk => emit-chunk}/modules-loaded/_config.js (100%) rename test/function/samples/{emit-entry-chunk => emit-chunk}/modules-loaded/chunk.js (100%) rename test/function/samples/{emit-entry-chunk => emit-chunk}/modules-loaded/main.js (100%) create mode 100644 test/function/samples/emit-chunk/no-input/_config.js create mode 100644 test/function/samples/emit-chunk/no-input/chunk.js diff --git a/src/Graph.ts b/src/Graph.ts index 415eee6ee19..714cb49241c 100644 --- a/src/Graph.ts +++ b/src/Graph.ts @@ -108,10 +108,6 @@ export default class Graph { this.cacheExpiry = options.experimentalCacheExpiry; - if (!options.input) { - throw new Error('You must supply options.input to rollup'); - } - this.treeshake = options.treeshake !== false; if (this.treeshake) { this.treeshakingOptions = options.treeshake @@ -214,6 +210,9 @@ export default class Graph { this.moduleLoader.addEntryModules(normalizeEntryModules(entryModules), true), manualChunks && this.moduleLoader.addManualChunks(manualChunks) ]).then(([{ entryModules, manualChunkModulesByAlias }]) => { + if (entryModules.length === 0) { + throw new Error('You must supply options.input to rollup'); + } for (const entryModule of entryModules) { if (entryModule.chunkAlias === null) { entryModule.chunkAlias = getAliasName(entryModule.id); diff --git a/src/finalisers/amd.ts b/src/finalisers/amd.ts index fb51b193ec9..534c41fb778 100644 --- a/src/finalisers/amd.ts +++ b/src/finalisers/amd.ts @@ -6,7 +6,7 @@ import getExportBlock from './shared/getExportBlock'; import getInteropBlock from './shared/getInteropBlock'; import warnOnBuiltins from './shared/warnOnBuiltins'; -// TODO Lukas consider improved AMD relative imports: +// TODO consider using improved AMD relative imports: // https://requirejs.org/docs/api.html#modulenotes-urls // AMD resolution will only respect the AMD baseUrl if the .js extension is omitted. diff --git a/src/rollup/index.ts b/src/rollup/index.ts index a98543e6a05..f35cf6aca88 100644 --- a/src/rollup/index.ts +++ b/src/rollup/index.ts @@ -67,7 +67,7 @@ function applyOptionHook(inputOptions: InputOptions, plugin: Plugin) { return inputOptions; } -function getInputOptions(rawInputOptions: GenericConfigObject): any { +function getInputOptions(rawInputOptions: GenericConfigObject): InputOptions { if (!rawInputOptions) { throw new Error('You must supply an options object to rollup'); } diff --git a/src/rollup/types.d.ts b/src/rollup/types.d.ts index e9f7f70f7d6..19f07e2fe99 100644 --- a/src/rollup/types.d.ts +++ b/src/rollup/types.d.ts @@ -214,7 +214,6 @@ export type ResolveAssetUrlHook = ( } ) => string | void; -// TODO Lukas do not require an input to be present if entries are created dynamically export type ResolveFileUrlHook = ( this: PluginContext, options: { @@ -326,7 +325,7 @@ export interface InputOptions { experimentalTopLevelAwait?: boolean; external?: ExternalOption; inlineDynamicImports?: boolean; - input: InputOption; + input?: InputOption; manualChunks?: { [chunkAlias: string]: string[] }; moduleContext?: ((id: string) => string) | { [id: string]: string }; onwarn?: WarningHandler; diff --git a/src/utils/mergeOptions.ts b/src/utils/mergeOptions.ts index a91739eb166..37016d94b5f 100644 --- a/src/utils/mergeOptions.ts +++ b/src/utils/mergeOptions.ts @@ -88,7 +88,7 @@ export default function mergeOptions({ config: GenericConfigObject; defaultOnWarnHandler?: WarningHandler; }): { - inputOptions: any; + inputOptions: InputOptions; optionError: string | null; outputOptions: any; } { @@ -204,7 +204,7 @@ function getInputOptions( experimentalTopLevelAwait: getOption('experimentalTopLevelAwait'), external: getExternal(config, command), inlineDynamicImports: getOption('inlineDynamicImports', false), - input: getOption('input'), + input: getOption('input', []), manualChunks: getOption('manualChunks'), moduleContext: config.moduleContext, onwarn: getOnWarn(config, command, defaultOnWarnHandler), diff --git a/src/watch/index.ts b/src/watch/index.ts index efae4a7053e..519ad166a2e 100644 --- a/src/watch/index.ts +++ b/src/watch/index.ts @@ -9,7 +9,8 @@ import { RollupBuild, RollupCache, RollupWatcher, - RollupWatchOptions + RollupWatchOptions, + WatcherOptions } from '../rollup/types'; import mergeOptions from '../utils/mergeOptions'; import chokidar from './chokidar'; @@ -28,7 +29,7 @@ export class Watcher { private tasks: Task[]; constructor(configs: RollupWatchOptions[]) { - this.emitter = new class extends EventEmitter implements RollupWatcher { + this.emitter = new (class extends EventEmitter implements RollupWatcher { close: () => void; constructor(close: () => void) { super(); @@ -37,7 +38,7 @@ export class Watcher { // showing the `MaxListenersExceededWarning` to the user. this.setMaxListeners(Infinity); } - }(this.close.bind(this)); + })(this.close.bind(this)); this.tasks = (Array.isArray(configs) ? configs : configs ? [configs] : []).map( config => new Task(this, config) ); @@ -144,8 +145,9 @@ export class Task { if (output.file || output.dir) return path.resolve(output.file || output.dir); }); - const watchOptions = inputOptions.watch || {}; - if ('useChokidar' in watchOptions) watchOptions.chokidar = watchOptions.useChokidar; + const watchOptions: WatcherOptions = inputOptions.watch || {}; + if ('useChokidar' in watchOptions) + (watchOptions as any).chokidar = (watchOptions as any).useChokidar; let chokidarOptions = 'chokidar' in watchOptions ? watchOptions.chokidar : !!chokidar; if (chokidarOptions) { chokidarOptions = { @@ -161,7 +163,7 @@ export class Task { ); } - this.chokidarOptions = chokidarOptions; + this.chokidarOptions = chokidarOptions as WatchOptions; this.chokidarOptionsHash = JSON.stringify(chokidarOptions); this.filter = createFilter(watchOptions.include, watchOptions.exclude); diff --git a/test/function/samples/emit-entry-chunk/chunk-filename-not-available/_config.js b/test/function/samples/emit-chunk/chunk-filename-not-available/_config.js similarity index 100% rename from test/function/samples/emit-entry-chunk/chunk-filename-not-available/_config.js rename to test/function/samples/emit-chunk/chunk-filename-not-available/_config.js diff --git a/test/function/samples/emit-entry-chunk/chunk-filename-not-available/chunk.js b/test/function/samples/emit-chunk/chunk-filename-not-available/chunk.js similarity index 100% rename from test/function/samples/emit-entry-chunk/chunk-filename-not-available/chunk.js rename to test/function/samples/emit-chunk/chunk-filename-not-available/chunk.js diff --git a/test/function/samples/emit-entry-chunk/chunk-filename-not-available/main.js b/test/function/samples/emit-chunk/chunk-filename-not-available/main.js similarity index 100% rename from test/function/samples/emit-entry-chunk/chunk-filename-not-available/main.js rename to test/function/samples/emit-chunk/chunk-filename-not-available/main.js diff --git a/test/function/samples/emit-entry-chunk/chunk-not-found/_config.js b/test/function/samples/emit-chunk/chunk-not-found/_config.js similarity index 100% rename from test/function/samples/emit-entry-chunk/chunk-not-found/_config.js rename to test/function/samples/emit-chunk/chunk-not-found/_config.js diff --git a/test/function/samples/emit-entry-chunk/chunk-not-found/main.js b/test/function/samples/emit-chunk/chunk-not-found/main.js similarity index 100% rename from test/function/samples/emit-entry-chunk/chunk-not-found/main.js rename to test/function/samples/emit-chunk/chunk-not-found/main.js diff --git a/test/function/samples/emit-entry-chunk/invalid-chunk-id/_config.js b/test/function/samples/emit-chunk/invalid-chunk-id/_config.js similarity index 100% rename from test/function/samples/emit-entry-chunk/invalid-chunk-id/_config.js rename to test/function/samples/emit-chunk/invalid-chunk-id/_config.js diff --git a/test/function/samples/emit-entry-chunk/invalid-chunk-id/main.js b/test/function/samples/emit-chunk/invalid-chunk-id/main.js similarity index 100% rename from test/function/samples/emit-entry-chunk/invalid-chunk-id/main.js rename to test/function/samples/emit-chunk/invalid-chunk-id/main.js diff --git a/test/function/samples/emit-entry-chunk/modules-loaded/_config.js b/test/function/samples/emit-chunk/modules-loaded/_config.js similarity index 100% rename from test/function/samples/emit-entry-chunk/modules-loaded/_config.js rename to test/function/samples/emit-chunk/modules-loaded/_config.js diff --git a/test/function/samples/emit-entry-chunk/modules-loaded/chunk.js b/test/function/samples/emit-chunk/modules-loaded/chunk.js similarity index 100% rename from test/function/samples/emit-entry-chunk/modules-loaded/chunk.js rename to test/function/samples/emit-chunk/modules-loaded/chunk.js diff --git a/test/function/samples/emit-entry-chunk/modules-loaded/main.js b/test/function/samples/emit-chunk/modules-loaded/main.js similarity index 100% rename from test/function/samples/emit-entry-chunk/modules-loaded/main.js rename to test/function/samples/emit-chunk/modules-loaded/main.js diff --git a/test/function/samples/emit-chunk/no-input/_config.js b/test/function/samples/emit-chunk/no-input/_config.js new file mode 100644 index 00000000000..ec7d2de6ece --- /dev/null +++ b/test/function/samples/emit-chunk/no-input/_config.js @@ -0,0 +1,12 @@ +module.exports = { + description: 'It is not necessary to provide an input if a dynamic entry is emitted', + options: { + input: undefined, + plugins: { + name: 'test-plugin', + buildStart() { + this.emitChunk('chunk.js'); + } + } + } +}; diff --git a/test/function/samples/emit-chunk/no-input/chunk.js b/test/function/samples/emit-chunk/no-input/chunk.js new file mode 100644 index 00000000000..c40c320ba58 --- /dev/null +++ b/test/function/samples/emit-chunk/no-input/chunk.js @@ -0,0 +1 @@ +assert.equal(42, 42); From 08b69d206f1ea53952d095ce15ffe5847592a8b1 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Wed, 24 Apr 2019 08:11:48 +0200 Subject: [PATCH 43/60] Use facade module id as [name] for dynamic imports --- src/Chunk.ts | 10 ++++++---- src/Graph.ts | 7 +------ ...nerated-chunk.js => generated-main4.dynamic.js} | 0 .../{generated-chunk2.js => generated-main5.js} | 0 .../aliasing-extensions/_expected/amd/main1.js | 4 ++-- ...nerated-chunk.js => generated-main4.dynamic.js} | 0 .../{generated-chunk2.js => generated-main5.js} | 0 .../aliasing-extensions/_expected/cjs/main1.js | 4 ++-- ...nerated-chunk.js => generated-main4.dynamic.js} | 0 .../es/{generated-chunk2.js => generated-main5.js} | 0 .../aliasing-extensions/_expected/es/main1.js | 4 ++-- ...nerated-chunk.js => generated-main4.dynamic.js} | 0 .../{generated-chunk2.js => generated-main5.js} | 0 .../aliasing-extensions/_expected/system/main1.js | 4 ++-- .../amd/{generated-chunk2.js => generated-dep1.js} | 2 +- .../amd/{generated-chunk.js => generated-dep2.js} | 0 .../dynamic-import-chained/_expected/amd/main.js | 2 +- .../_expected/cjs/generated-chunk2.js | 4 ---- .../_expected/cjs/generated-dep1.js | 4 ++++ .../cjs/{generated-chunk.js => generated-dep2.js} | 0 .../dynamic-import-chained/_expected/cjs/main.js | 2 +- .../_expected/es/generated-chunk2.js | 2 -- .../_expected/es/generated-dep1.js | 2 ++ .../es/{generated-chunk.js => generated-dep2.js} | 0 .../dynamic-import-chained/_expected/es/main.js | 2 +- .../{generated-chunk2.js => generated-dep1.js} | 2 +- .../{generated-chunk.js => generated-dep2.js} | 0 .../_expected/system/main.js | 2 +- .../amd/{generated-chunk2.js => generated-dep2.js} | 0 .../dynamic-import-chunking/_expected/amd/main.js | 2 +- .../cjs/{generated-chunk2.js => generated-dep2.js} | 0 .../dynamic-import-chunking/_expected/cjs/main.js | 2 +- .../es/{generated-chunk2.js => generated-dep2.js} | 0 .../dynamic-import-chunking/_expected/es/main.js | 2 +- .../{generated-chunk2.js => generated-dep2.js} | 0 .../_expected/system/main.js | 2 +- .../{generated-chunk2.js => generated-dynamic.js} | 4 ++-- .../dynamic-import-facade/_expected/amd/main1.js | 2 +- .../dynamic-import-facade/_expected/amd/main2.js | 4 ++-- .../_expected/cjs/generated-chunk2.js | 7 ------- .../_expected/cjs/generated-dynamic.js | 7 +++++++ .../dynamic-import-facade/_expected/cjs/main1.js | 2 +- .../dynamic-import-facade/_expected/cjs/main2.js | 4 ++-- .../{generated-chunk2.js => generated-dynamic.js} | 0 .../dynamic-import-facade/_expected/es/main1.js | 2 +- .../{generated-chunk2.js => generated-dynamic.js} | 0 .../_expected/system/main1.js | 2 +- .../{generated-chunk.js => generated-inlined.js} | 0 .../{generated-chunk2.js => generated-separate.js} | 0 .../_expected/amd/main1.js | 6 +++--- .../_expected/amd/main2.js | 2 +- .../{generated-chunk.js => generated-inlined.js} | 0 .../{generated-chunk2.js => generated-separate.js} | 0 .../_expected/cjs/main1.js | 8 ++++---- .../_expected/cjs/main2.js | 2 +- .../{generated-chunk.js => generated-inlined.js} | 0 .../{generated-chunk2.js => generated-separate.js} | 0 .../_expected/es/main1.js | 8 ++++---- .../_expected/es/main2.js | 2 +- .../{generated-chunk.js => generated-inlined.js} | 0 .../{generated-chunk2.js => generated-separate.js} | 0 .../_expected/system/main1.js | 6 +++--- .../_expected/system/main2.js | 2 +- .../{generated-chunk.js => generated-dynamic.js} | 0 .../_expected/amd/main.js | 2 +- .../{generated-chunk.js => generated-dynamic.js} | 0 .../_expected/cjs/main.js | 2 +- .../{generated-chunk.js => generated-dynamic.js} | 0 .../_expected/es/main.js | 2 +- .../{generated-chunk.js => generated-dynamic.js} | 0 .../_expected/system/main.js | 2 +- .../amd/{generated-chunk2.js => generated-dep1.js} | 4 ++-- .../_expected/amd/main.js | 4 ++-- .../_expected/amd/main2.js | 2 +- .../_expected/cjs/generated-chunk2.js | 7 ------- .../_expected/cjs/generated-dep1.js | 7 +++++++ .../_expected/cjs/main.js | 4 ++-- .../_expected/cjs/main2.js | 2 +- .../es/{generated-chunk2.js => generated-dep1.js} | 0 .../_expected/es/main2.js | 2 +- .../{generated-chunk2.js => generated-dep1.js} | 0 .../_expected/system/main2.js | 2 +- .../_expected/amd/chunks/{chunk2.js => other.js} | 0 .../samples/dynamic-import/_expected/amd/main.js | 2 +- .../_expected/cjs/chunks/{chunk2.js => other.js} | 0 .../samples/dynamic-import/_expected/cjs/main.js | 2 +- .../_expected/es/chunks/{chunk2.js => other.js} | 0 .../samples/dynamic-import/_expected/es/main.js | 2 +- .../system/chunks/{chunk2.js => other.js} | 0 .../dynamic-import/_expected/system/main.js | 2 +- .../_expected/amd/generated-build-starter.js | 4 +++- .../_expected/amd/generated-buildStart.js | 4 ++-- .../emit-chunk-facade/_expected/amd/main.js | 4 ++-- .../_expected/cjs/generated-build-starter.js | 4 +++- .../_expected/cjs/generated-buildStart.js | 4 ++-- .../emit-chunk-facade/_expected/cjs/main.js | 4 ++-- .../_expected/es/generated-build-starter.js | 5 +++-- .../samples/emit-chunk-facade/_expected/es/main.js | 4 ++-- .../_expected/system/generated-build-starter.js | 3 ++- .../emit-chunk-facade/_expected/system/main.js | 5 +++-- .../samples/emit-chunk-facade/buildStart.js | 2 +- .../chunking-form/samples/emit-chunk-facade/dep.js | 3 ++- .../samples/emit-chunk-facade/main.js | 4 ++-- .../_expected/amd/chunks/{chunk2.js => nested.js} | 0 .../emit-chunk-worker/_expected/amd/main.js | 2 +- .../_expected/cjs/chunks/{chunk2.js => nested.js} | 0 .../emit-chunk-worker/_expected/cjs/main.js | 2 +- .../_expected/es/chunks/{chunk2.js => nested.js} | 0 .../samples/emit-chunk-worker/_expected/es/main.js | 2 +- .../system/chunks/{chunk2.js => nested.js} | 0 .../emit-chunk-worker/_expected/system/main.js | 2 +- .../amd/{generated-m1.js => generated-chunk.js} | 0 .../_expected/amd/m1.js | 2 +- .../_expected/amd/main.js | 2 +- .../cjs/{generated-m1.js => generated-chunk.js} | 0 .../_expected/cjs/m1.js | 2 +- .../_expected/cjs/main.js | 2 +- .../es/{generated-m1.js => generated-chunk.js} | 0 .../_expected/es/m1.js | 2 +- .../_expected/es/main.js | 2 +- .../system/{generated-m1.js => generated-chunk.js} | 0 .../_expected/system/m1.js | 2 +- .../_expected/system/main.js | 2 +- .../amd/{generated-main2.js => generated-chunk.js} | 0 .../entrypoint-facade/_expected/amd/main1.js | 2 +- .../entrypoint-facade/_expected/amd/main2.js | 2 +- .../cjs/{generated-main2.js => generated-chunk.js} | 0 .../entrypoint-facade/_expected/cjs/main1.js | 2 +- .../entrypoint-facade/_expected/cjs/main2.js | 2 +- .../es/{generated-main2.js => generated-chunk.js} | 0 .../entrypoint-facade/_expected/es/main1.js | 2 +- .../entrypoint-facade/_expected/es/main2.js | 2 +- .../{generated-main2.js => generated-chunk.js} | 0 .../entrypoint-facade/_expected/system/main1.js | 2 +- .../entrypoint-facade/_expected/system/main2.js | 2 +- ...6bb39c19-amd.js => chunk-chunk-6bb39c19-amd.js} | 0 .../_expected/amd/entry-main1-e7c7d1b5-amd.js | 2 +- .../_expected/amd/entry-main2-f9a2200a-amd.js | 2 +- ...33c8b40d-cjs.js => chunk-chunk-33c8b40d-cjs.js} | 0 .../_expected/cjs/entry-main1-639831da-cjs.js | 2 +- .../_expected/cjs/entry-main2-4508233a-cjs.js | 2 +- ...88db1d1d-esm.js => chunk-chunk-88db1d1d-esm.js} | 0 .../_expected/es/entry-main1-0152a638-esm.js | 2 +- .../_expected/es/entry-main2-5a78ab60-esm.js | 2 +- ...1e-system.js => chunk-chunk-26e1391e-system.js} | 0 .../system/entry-main1-2c874064-system.js | 2 +- .../system/entry-main2-dd802b9d-system.js | 2 +- .../samples/manual-chunk-avoid-facade/_config.js | 9 +++++++++ .../_expected/amd/main1.js | 5 +++++ .../_expected/amd/manual.js | 11 +++++++++++ .../_expected/cjs/main1.js | 5 +++++ .../_expected/cjs/manual.js | 9 +++++++++ .../_expected/es/main1.js | 3 +++ .../_expected/es/manual.js | 5 +++++ .../_expected/system/main1.js | 14 ++++++++++++++ .../_expected/system/manual.js | 12 ++++++++++++ .../samples/manual-chunk-avoid-facade/dep.js | 1 + .../samples/manual-chunk-avoid-facade/main1.js | 3 +++ .../samples/manual-chunk-avoid-facade/main2.js | 5 +++++ .../{generated-chunk.js => generated-dynamic2.js} | 0 .../{generated-chunk2.js => generated-dynamic3.js} | 0 .../_expected/amd/main.js | 2 +- .../{generated-chunk.js => generated-dynamic2.js} | 0 .../{generated-chunk2.js => generated-dynamic3.js} | 0 .../_expected/cjs/main.js | 2 +- .../{generated-chunk.js => generated-dynamic2.js} | 0 .../{generated-chunk2.js => generated-dynamic3.js} | 0 .../_expected/es/main.js | 2 +- .../{generated-chunk.js => generated-dynamic2.js} | 0 .../{generated-chunk2.js => generated-dynamic3.js} | 0 .../_expected/system/main.js | 2 +- .../{generated-chunk.js => generated-dynamic1.js} | 0 .../_expected/amd/main.js | 2 +- .../{generated-chunk.js => generated-dynamic1.js} | 0 .../_expected/cjs/main.js | 2 +- .../{generated-chunk.js => generated-dynamic1.js} | 0 .../_expected/es/main.js | 2 +- .../{generated-chunk.js => generated-dynamic1.js} | 0 .../_expected/system/main.js | 2 +- .../amd/{generated-main2.js => generated-chunk.js} | 0 .../namespace-object-import/_expected/amd/main1.js | 2 +- .../namespace-object-import/_expected/amd/main2.js | 2 +- .../cjs/{generated-main2.js => generated-chunk.js} | 0 .../namespace-object-import/_expected/cjs/main1.js | 2 +- .../namespace-object-import/_expected/cjs/main2.js | 2 +- .../es/{generated-main2.js => generated-chunk.js} | 0 .../namespace-object-import/_expected/es/main1.js | 2 +- .../namespace-object-import/_expected/es/main2.js | 2 +- .../{generated-main2.js => generated-chunk.js} | 0 .../_expected/system/main1.js | 2 +- .../_expected/system/main2.js | 2 +- .../amd/{generated-index.js => generated-chunk.js} | 0 .../namespace-reexports/_expected/amd/index.js | 2 +- .../namespace-reexports/_expected/amd/main.js | 2 +- .../cjs/{generated-index.js => generated-chunk.js} | 0 .../namespace-reexports/_expected/cjs/index.js | 2 +- .../namespace-reexports/_expected/cjs/main.js | 2 +- .../es/{generated-index.js => generated-chunk.js} | 0 .../namespace-reexports/_expected/es/index.js | 2 +- .../namespace-reexports/_expected/es/main.js | 2 +- .../{generated-index.js => generated-chunk.js} | 0 .../namespace-reexports/_expected/system/index.js | 2 +- .../namespace-reexports/_expected/system/main.js | 2 +- .../{generated-chunk.js => generated-dynamic1.js} | 2 +- .../{generated-chunk2.js => generated-dynamic2.js} | 2 +- .../{generated-chunk3.js => generated-dynamic3.js} | 2 +- .../{generated-chunk4.js => generated-dynamic4.js} | 2 +- .../{generated-chunk5.js => generated-dynamic5.js} | 0 .../nested-dynamic-imports/_expected/amd/main.js | 2 +- .../_expected/cjs/generated-chunk.js | 4 ---- .../_expected/cjs/generated-chunk2.js | 4 ---- .../_expected/cjs/generated-chunk3.js | 4 ---- .../_expected/cjs/generated-chunk4.js | 4 ---- .../_expected/cjs/generated-dynamic1.js | 4 ++++ .../_expected/cjs/generated-dynamic2.js | 4 ++++ .../_expected/cjs/generated-dynamic3.js | 4 ++++ .../_expected/cjs/generated-dynamic4.js | 4 ++++ .../{generated-chunk5.js => generated-dynamic5.js} | 0 .../nested-dynamic-imports/_expected/cjs/main.js | 2 +- .../_expected/es/generated-chunk.js | 2 -- .../_expected/es/generated-chunk2.js | 2 -- .../_expected/es/generated-chunk3.js | 2 -- .../_expected/es/generated-chunk4.js | 2 -- .../_expected/es/generated-dynamic1.js | 2 ++ .../_expected/es/generated-dynamic2.js | 2 ++ .../_expected/es/generated-dynamic3.js | 2 ++ .../_expected/es/generated-dynamic4.js | 2 ++ .../{generated-chunk5.js => generated-dynamic5.js} | 0 .../nested-dynamic-imports/_expected/es/main.js | 2 +- .../{generated-chunk.js => generated-dynamic1.js} | 2 +- .../{generated-chunk2.js => generated-dynamic2.js} | 2 +- .../{generated-chunk3.js => generated-dynamic3.js} | 2 +- .../{generated-chunk4.js => generated-dynamic4.js} | 2 +- .../{generated-chunk5.js => generated-dynamic5.js} | 0 .../_expected/system/main.js | 2 +- .../amd/{generated-chunk2.js => generated-lazy.js} | 0 .../_expected/amd/main.js | 2 +- .../cjs/{generated-chunk2.js => generated-lazy.js} | 0 .../_expected/cjs/main.js | 2 +- .../es/{generated-chunk2.js => generated-lazy.js} | 0 .../sanitize-internal-exports/_expected/es/main.js | 2 +- .../{generated-chunk2.js => generated-lazy.js} | 0 .../_expected/system/main.js | 2 +- test/hooks/index.js | 10 +++++----- test/misc/bundle-information.js | 14 +++++++------- test/misc/misc.js | 2 +- test/watch/index.js | 8 ++++---- 247 files changed, 311 insertions(+), 224 deletions(-) rename test/chunking-form/samples/aliasing-extensions/_expected/amd/{generated-chunk.js => generated-main4.dynamic.js} (100%) rename test/chunking-form/samples/aliasing-extensions/_expected/amd/{generated-chunk2.js => generated-main5.js} (100%) rename test/chunking-form/samples/aliasing-extensions/_expected/cjs/{generated-chunk.js => generated-main4.dynamic.js} (100%) rename test/chunking-form/samples/aliasing-extensions/_expected/cjs/{generated-chunk2.js => generated-main5.js} (100%) rename test/chunking-form/samples/aliasing-extensions/_expected/es/{generated-chunk.js => generated-main4.dynamic.js} (100%) rename test/chunking-form/samples/aliasing-extensions/_expected/es/{generated-chunk2.js => generated-main5.js} (100%) rename test/chunking-form/samples/aliasing-extensions/_expected/system/{generated-chunk.js => generated-main4.dynamic.js} (100%) rename test/chunking-form/samples/aliasing-extensions/_expected/system/{generated-chunk2.js => generated-main5.js} (100%) rename test/chunking-form/samples/dynamic-import-chained/_expected/amd/{generated-chunk2.js => generated-dep1.js} (83%) rename test/chunking-form/samples/dynamic-import-chained/_expected/amd/{generated-chunk.js => generated-dep2.js} (100%) delete mode 100644 test/chunking-form/samples/dynamic-import-chained/_expected/cjs/generated-chunk2.js create mode 100644 test/chunking-form/samples/dynamic-import-chained/_expected/cjs/generated-dep1.js rename test/chunking-form/samples/dynamic-import-chained/_expected/cjs/{generated-chunk.js => generated-dep2.js} (100%) delete mode 100644 test/chunking-form/samples/dynamic-import-chained/_expected/es/generated-chunk2.js create mode 100644 test/chunking-form/samples/dynamic-import-chained/_expected/es/generated-dep1.js rename test/chunking-form/samples/dynamic-import-chained/_expected/es/{generated-chunk.js => generated-dep2.js} (100%) rename test/chunking-form/samples/dynamic-import-chained/_expected/system/{generated-chunk2.js => generated-dep1.js} (76%) rename test/chunking-form/samples/dynamic-import-chained/_expected/system/{generated-chunk.js => generated-dep2.js} (100%) rename test/chunking-form/samples/dynamic-import-chunking/_expected/amd/{generated-chunk2.js => generated-dep2.js} (100%) rename test/chunking-form/samples/dynamic-import-chunking/_expected/cjs/{generated-chunk2.js => generated-dep2.js} (100%) rename test/chunking-form/samples/dynamic-import-chunking/_expected/es/{generated-chunk2.js => generated-dep2.js} (100%) rename test/chunking-form/samples/dynamic-import-chunking/_expected/system/{generated-chunk2.js => generated-dep2.js} (100%) rename test/chunking-form/samples/dynamic-import-facade/_expected/amd/{generated-chunk2.js => generated-dynamic.js} (53%) delete mode 100644 test/chunking-form/samples/dynamic-import-facade/_expected/cjs/generated-chunk2.js create mode 100644 test/chunking-form/samples/dynamic-import-facade/_expected/cjs/generated-dynamic.js rename test/chunking-form/samples/dynamic-import-facade/_expected/es/{generated-chunk2.js => generated-dynamic.js} (100%) rename test/chunking-form/samples/dynamic-import-facade/_expected/system/{generated-chunk2.js => generated-dynamic.js} (100%) rename test/chunking-form/samples/dynamic-import-inline-colouring/_expected/amd/{generated-chunk.js => generated-inlined.js} (100%) rename test/chunking-form/samples/dynamic-import-inline-colouring/_expected/amd/{generated-chunk2.js => generated-separate.js} (100%) rename test/chunking-form/samples/dynamic-import-inline-colouring/_expected/cjs/{generated-chunk.js => generated-inlined.js} (100%) rename test/chunking-form/samples/dynamic-import-inline-colouring/_expected/cjs/{generated-chunk2.js => generated-separate.js} (100%) rename test/chunking-form/samples/dynamic-import-inline-colouring/_expected/es/{generated-chunk.js => generated-inlined.js} (100%) rename test/chunking-form/samples/dynamic-import-inline-colouring/_expected/es/{generated-chunk2.js => generated-separate.js} (100%) rename test/chunking-form/samples/dynamic-import-inline-colouring/_expected/system/{generated-chunk.js => generated-inlined.js} (100%) rename test/chunking-form/samples/dynamic-import-inline-colouring/_expected/system/{generated-chunk2.js => generated-separate.js} (100%) rename test/chunking-form/samples/dynamic-import-only-reexports/_expected/amd/{generated-chunk.js => generated-dynamic.js} (100%) rename test/chunking-form/samples/dynamic-import-only-reexports/_expected/cjs/{generated-chunk.js => generated-dynamic.js} (100%) rename test/chunking-form/samples/dynamic-import-only-reexports/_expected/es/{generated-chunk.js => generated-dynamic.js} (100%) rename test/chunking-form/samples/dynamic-import-only-reexports/_expected/system/{generated-chunk.js => generated-dynamic.js} (100%) rename test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/amd/{generated-chunk2.js => generated-dep1.js} (59%) delete mode 100644 test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/cjs/generated-chunk2.js create mode 100644 test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/cjs/generated-dep1.js rename test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/es/{generated-chunk2.js => generated-dep1.js} (100%) rename test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/system/{generated-chunk2.js => generated-dep1.js} (100%) rename test/chunking-form/samples/dynamic-import/_expected/amd/chunks/{chunk2.js => other.js} (100%) rename test/chunking-form/samples/dynamic-import/_expected/cjs/chunks/{chunk2.js => other.js} (100%) rename test/chunking-form/samples/dynamic-import/_expected/es/chunks/{chunk2.js => other.js} (100%) rename test/chunking-form/samples/dynamic-import/_expected/system/chunks/{chunk2.js => other.js} (100%) rename test/chunking-form/samples/emit-chunk-worker/_expected/amd/chunks/{chunk2.js => nested.js} (100%) rename test/chunking-form/samples/emit-chunk-worker/_expected/cjs/chunks/{chunk2.js => nested.js} (100%) rename test/chunking-form/samples/emit-chunk-worker/_expected/es/chunks/{chunk2.js => nested.js} (100%) rename test/chunking-form/samples/emit-chunk-worker/_expected/system/chunks/{chunk2.js => nested.js} (100%) rename test/chunking-form/samples/entry-point-without-own-code/_expected/amd/{generated-m1.js => generated-chunk.js} (100%) rename test/chunking-form/samples/entry-point-without-own-code/_expected/cjs/{generated-m1.js => generated-chunk.js} (100%) rename test/chunking-form/samples/entry-point-without-own-code/_expected/es/{generated-m1.js => generated-chunk.js} (100%) rename test/chunking-form/samples/entry-point-without-own-code/_expected/system/{generated-m1.js => generated-chunk.js} (100%) rename test/chunking-form/samples/entrypoint-facade/_expected/amd/{generated-main2.js => generated-chunk.js} (100%) rename test/chunking-form/samples/entrypoint-facade/_expected/cjs/{generated-main2.js => generated-chunk.js} (100%) rename test/chunking-form/samples/entrypoint-facade/_expected/es/{generated-main2.js => generated-chunk.js} (100%) rename test/chunking-form/samples/entrypoint-facade/_expected/system/{generated-main2.js => generated-chunk.js} (100%) rename test/chunking-form/samples/filenames-patterns/_expected/amd/{chunk-main2-6bb39c19-amd.js => chunk-chunk-6bb39c19-amd.js} (100%) rename test/chunking-form/samples/filenames-patterns/_expected/cjs/{chunk-main2-33c8b40d-cjs.js => chunk-chunk-33c8b40d-cjs.js} (100%) rename test/chunking-form/samples/filenames-patterns/_expected/es/{chunk-main2-88db1d1d-esm.js => chunk-chunk-88db1d1d-esm.js} (100%) rename test/chunking-form/samples/filenames-patterns/_expected/system/{chunk-main2-26e1391e-system.js => chunk-chunk-26e1391e-system.js} (100%) create mode 100644 test/chunking-form/samples/manual-chunk-avoid-facade/_config.js create mode 100644 test/chunking-form/samples/manual-chunk-avoid-facade/_expected/amd/main1.js create mode 100644 test/chunking-form/samples/manual-chunk-avoid-facade/_expected/amd/manual.js create mode 100644 test/chunking-form/samples/manual-chunk-avoid-facade/_expected/cjs/main1.js create mode 100644 test/chunking-form/samples/manual-chunk-avoid-facade/_expected/cjs/manual.js create mode 100644 test/chunking-form/samples/manual-chunk-avoid-facade/_expected/es/main1.js create mode 100644 test/chunking-form/samples/manual-chunk-avoid-facade/_expected/es/manual.js create mode 100644 test/chunking-form/samples/manual-chunk-avoid-facade/_expected/system/main1.js create mode 100644 test/chunking-form/samples/manual-chunk-avoid-facade/_expected/system/manual.js create mode 100644 test/chunking-form/samples/manual-chunk-avoid-facade/dep.js create mode 100644 test/chunking-form/samples/manual-chunk-avoid-facade/main1.js create mode 100644 test/chunking-form/samples/manual-chunk-avoid-facade/main2.js rename test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/{generated-chunk.js => generated-dynamic2.js} (100%) rename test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/{generated-chunk2.js => generated-dynamic3.js} (100%) rename test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/cjs/{generated-chunk.js => generated-dynamic2.js} (100%) rename test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/cjs/{generated-chunk2.js => generated-dynamic3.js} (100%) rename test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/es/{generated-chunk.js => generated-dynamic2.js} (100%) rename test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/es/{generated-chunk2.js => generated-dynamic3.js} (100%) rename test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/system/{generated-chunk.js => generated-dynamic2.js} (100%) rename test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/system/{generated-chunk2.js => generated-dynamic3.js} (100%) rename test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/amd/{generated-chunk.js => generated-dynamic1.js} (100%) rename test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/cjs/{generated-chunk.js => generated-dynamic1.js} (100%) rename test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/es/{generated-chunk.js => generated-dynamic1.js} (100%) rename test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/system/{generated-chunk.js => generated-dynamic1.js} (100%) rename test/chunking-form/samples/namespace-object-import/_expected/amd/{generated-main2.js => generated-chunk.js} (100%) rename test/chunking-form/samples/namespace-object-import/_expected/cjs/{generated-main2.js => generated-chunk.js} (100%) rename test/chunking-form/samples/namespace-object-import/_expected/es/{generated-main2.js => generated-chunk.js} (100%) rename test/chunking-form/samples/namespace-object-import/_expected/system/{generated-main2.js => generated-chunk.js} (100%) rename test/chunking-form/samples/namespace-reexports/_expected/amd/{generated-index.js => generated-chunk.js} (100%) rename test/chunking-form/samples/namespace-reexports/_expected/cjs/{generated-index.js => generated-chunk.js} (100%) rename test/chunking-form/samples/namespace-reexports/_expected/es/{generated-index.js => generated-chunk.js} (100%) rename test/chunking-form/samples/namespace-reexports/_expected/system/{generated-index.js => generated-chunk.js} (100%) rename test/chunking-form/samples/nested-dynamic-imports/_expected/amd/{generated-chunk.js => generated-dynamic1.js} (82%) rename test/chunking-form/samples/nested-dynamic-imports/_expected/amd/{generated-chunk2.js => generated-dynamic2.js} (82%) rename test/chunking-form/samples/nested-dynamic-imports/_expected/amd/{generated-chunk3.js => generated-dynamic3.js} (82%) rename test/chunking-form/samples/nested-dynamic-imports/_expected/amd/{generated-chunk4.js => generated-dynamic4.js} (82%) rename test/chunking-form/samples/nested-dynamic-imports/_expected/amd/{generated-chunk5.js => generated-dynamic5.js} (100%) delete mode 100644 test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/generated-chunk.js delete mode 100644 test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/generated-chunk2.js delete mode 100644 test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/generated-chunk3.js delete mode 100644 test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/generated-chunk4.js create mode 100644 test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/generated-dynamic1.js create mode 100644 test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/generated-dynamic2.js create mode 100644 test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/generated-dynamic3.js create mode 100644 test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/generated-dynamic4.js rename test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/{generated-chunk5.js => generated-dynamic5.js} (100%) delete mode 100644 test/chunking-form/samples/nested-dynamic-imports/_expected/es/generated-chunk.js delete mode 100644 test/chunking-form/samples/nested-dynamic-imports/_expected/es/generated-chunk2.js delete mode 100644 test/chunking-form/samples/nested-dynamic-imports/_expected/es/generated-chunk3.js delete mode 100644 test/chunking-form/samples/nested-dynamic-imports/_expected/es/generated-chunk4.js create mode 100644 test/chunking-form/samples/nested-dynamic-imports/_expected/es/generated-dynamic1.js create mode 100644 test/chunking-form/samples/nested-dynamic-imports/_expected/es/generated-dynamic2.js create mode 100644 test/chunking-form/samples/nested-dynamic-imports/_expected/es/generated-dynamic3.js create mode 100644 test/chunking-form/samples/nested-dynamic-imports/_expected/es/generated-dynamic4.js rename test/chunking-form/samples/nested-dynamic-imports/_expected/es/{generated-chunk5.js => generated-dynamic5.js} (100%) rename test/chunking-form/samples/nested-dynamic-imports/_expected/system/{generated-chunk.js => generated-dynamic1.js} (75%) rename test/chunking-form/samples/nested-dynamic-imports/_expected/system/{generated-chunk2.js => generated-dynamic2.js} (75%) rename test/chunking-form/samples/nested-dynamic-imports/_expected/system/{generated-chunk3.js => generated-dynamic3.js} (75%) rename test/chunking-form/samples/nested-dynamic-imports/_expected/system/{generated-chunk4.js => generated-dynamic4.js} (75%) rename test/chunking-form/samples/nested-dynamic-imports/_expected/system/{generated-chunk5.js => generated-dynamic5.js} (100%) rename test/chunking-form/samples/sanitize-internal-exports/_expected/amd/{generated-chunk2.js => generated-lazy.js} (100%) rename test/chunking-form/samples/sanitize-internal-exports/_expected/cjs/{generated-chunk2.js => generated-lazy.js} (100%) rename test/chunking-form/samples/sanitize-internal-exports/_expected/es/{generated-chunk2.js => generated-lazy.js} (100%) rename test/chunking-form/samples/sanitize-internal-exports/_expected/system/{generated-chunk2.js => generated-lazy.js} (100%) diff --git a/src/Chunk.ts b/src/Chunk.ts index 1104388307c..5eeff82240f 100644 --- a/src/Chunk.ts +++ b/src/Chunk.ts @@ -30,7 +30,7 @@ import { sortByExecutionOrder } from './utils/executionOrder'; import getIndentString from './utils/getIndentString'; import { makeLegal } from './utils/identifierHelpers'; import { basename, dirname, isAbsolute, normalize, relative, resolve } from './utils/path'; -import relativeId from './utils/relativeId'; +import relativeId, { getAliasName } from './utils/relativeId'; import renderChunk from './utils/renderChunk'; import { RenderOptions } from './utils/renderHelpers'; import { makeUnique, renderNamePattern } from './utils/renderNamePattern'; @@ -171,7 +171,9 @@ export default class Chunk { const entryModule = this.entryModules[0]; if (entryModule) { this.variableName = makeLegal( - basename(entryModule.chunkAlias || entryModule.manualChunkAlias || entryModule.id) + basename( + entryModule.chunkAlias || entryModule.manualChunkAlias || getAliasName(entryModule.id) + ) ); } else { this.variableName = '__chunk_' + ++graph.curChunkIndex; @@ -762,8 +764,8 @@ export default class Chunk { if (this.manualChunkAlias) { return sanitizeFileName(this.manualChunkAlias); } - if (this.facadeModule !== null && this.facadeModule.chunkAlias) { - return sanitizeFileName(this.facadeModule.chunkAlias); + if (this.facadeModule !== null) { + return sanitizeFileName(this.facadeModule.chunkAlias || getAliasName(this.facadeModule.id)); } for (const module of this.orderedModules) { if (module.chunkAlias) return sanitizeFileName(module.chunkAlias); diff --git a/src/Graph.ts b/src/Graph.ts index 714cb49241c..5a20e022243 100644 --- a/src/Graph.ts +++ b/src/Graph.ts @@ -28,7 +28,7 @@ import { Uint8ArrayToHexString } from './utils/entryHashing'; import { analyseModuleExecution, sortByExecutionOrder } from './utils/executionOrder'; import { resolve } from './utils/path'; import { createPluginDriver, PluginDriver } from './utils/pluginDriver'; -import relativeId, { getAliasName } from './utils/relativeId'; +import relativeId from './utils/relativeId'; import { timeEnd, timeStart } from './utils/timers'; function makeOnwarn() { @@ -213,11 +213,6 @@ export default class Graph { if (entryModules.length === 0) { throw new Error('You must supply options.input to rollup'); } - for (const entryModule of entryModules) { - if (entryModule.chunkAlias === null) { - entryModule.chunkAlias = getAliasName(entryModule.id); - } - } for (const module of Array.from(this.moduleById.values())) { if (module instanceof Module) { this.modules.push(module); diff --git a/test/chunking-form/samples/aliasing-extensions/_expected/amd/generated-chunk.js b/test/chunking-form/samples/aliasing-extensions/_expected/amd/generated-main4.dynamic.js similarity index 100% rename from test/chunking-form/samples/aliasing-extensions/_expected/amd/generated-chunk.js rename to test/chunking-form/samples/aliasing-extensions/_expected/amd/generated-main4.dynamic.js diff --git a/test/chunking-form/samples/aliasing-extensions/_expected/amd/generated-chunk2.js b/test/chunking-form/samples/aliasing-extensions/_expected/amd/generated-main5.js similarity index 100% rename from test/chunking-form/samples/aliasing-extensions/_expected/amd/generated-chunk2.js rename to test/chunking-form/samples/aliasing-extensions/_expected/amd/generated-main5.js diff --git a/test/chunking-form/samples/aliasing-extensions/_expected/amd/main1.js b/test/chunking-form/samples/aliasing-extensions/_expected/amd/main1.js index 6330bb0df77..faa948b5725 100644 --- a/test/chunking-form/samples/aliasing-extensions/_expected/amd/main1.js +++ b/test/chunking-form/samples/aliasing-extensions/_expected/amd/main1.js @@ -1,7 +1,7 @@ define(['require'], function (require) { 'use strict'; console.log('main1'); - new Promise(function (resolve, reject) { require(['./generated-chunk'], resolve, reject) }); - new Promise(function (resolve, reject) { require(['./generated-chunk2'], resolve, reject) }); + new Promise(function (resolve, reject) { require(['./generated-main4.dynamic'], resolve, reject) }); + new Promise(function (resolve, reject) { require(['./generated-main5'], resolve, reject) }); }); diff --git a/test/chunking-form/samples/aliasing-extensions/_expected/cjs/generated-chunk.js b/test/chunking-form/samples/aliasing-extensions/_expected/cjs/generated-main4.dynamic.js similarity index 100% rename from test/chunking-form/samples/aliasing-extensions/_expected/cjs/generated-chunk.js rename to test/chunking-form/samples/aliasing-extensions/_expected/cjs/generated-main4.dynamic.js diff --git a/test/chunking-form/samples/aliasing-extensions/_expected/cjs/generated-chunk2.js b/test/chunking-form/samples/aliasing-extensions/_expected/cjs/generated-main5.js similarity index 100% rename from test/chunking-form/samples/aliasing-extensions/_expected/cjs/generated-chunk2.js rename to test/chunking-form/samples/aliasing-extensions/_expected/cjs/generated-main5.js diff --git a/test/chunking-form/samples/aliasing-extensions/_expected/cjs/main1.js b/test/chunking-form/samples/aliasing-extensions/_expected/cjs/main1.js index ffb10b14b6d..4e8cf4fb59f 100644 --- a/test/chunking-form/samples/aliasing-extensions/_expected/cjs/main1.js +++ b/test/chunking-form/samples/aliasing-extensions/_expected/cjs/main1.js @@ -1,5 +1,5 @@ 'use strict'; console.log('main1'); -Promise.resolve(require('./generated-chunk.js')); -Promise.resolve(require('./generated-chunk2.js')); +Promise.resolve(require('./generated-main4.dynamic.js')); +Promise.resolve(require('./generated-main5.js')); diff --git a/test/chunking-form/samples/aliasing-extensions/_expected/es/generated-chunk.js b/test/chunking-form/samples/aliasing-extensions/_expected/es/generated-main4.dynamic.js similarity index 100% rename from test/chunking-form/samples/aliasing-extensions/_expected/es/generated-chunk.js rename to test/chunking-form/samples/aliasing-extensions/_expected/es/generated-main4.dynamic.js diff --git a/test/chunking-form/samples/aliasing-extensions/_expected/es/generated-chunk2.js b/test/chunking-form/samples/aliasing-extensions/_expected/es/generated-main5.js similarity index 100% rename from test/chunking-form/samples/aliasing-extensions/_expected/es/generated-chunk2.js rename to test/chunking-form/samples/aliasing-extensions/_expected/es/generated-main5.js diff --git a/test/chunking-form/samples/aliasing-extensions/_expected/es/main1.js b/test/chunking-form/samples/aliasing-extensions/_expected/es/main1.js index de1c78214cd..17a9dcfce67 100644 --- a/test/chunking-form/samples/aliasing-extensions/_expected/es/main1.js +++ b/test/chunking-form/samples/aliasing-extensions/_expected/es/main1.js @@ -1,3 +1,3 @@ console.log('main1'); -import('./generated-chunk.js'); -import('./generated-chunk2.js'); +import('./generated-main4.dynamic.js'); +import('./generated-main5.js'); diff --git a/test/chunking-form/samples/aliasing-extensions/_expected/system/generated-chunk.js b/test/chunking-form/samples/aliasing-extensions/_expected/system/generated-main4.dynamic.js similarity index 100% rename from test/chunking-form/samples/aliasing-extensions/_expected/system/generated-chunk.js rename to test/chunking-form/samples/aliasing-extensions/_expected/system/generated-main4.dynamic.js diff --git a/test/chunking-form/samples/aliasing-extensions/_expected/system/generated-chunk2.js b/test/chunking-form/samples/aliasing-extensions/_expected/system/generated-main5.js similarity index 100% rename from test/chunking-form/samples/aliasing-extensions/_expected/system/generated-chunk2.js rename to test/chunking-form/samples/aliasing-extensions/_expected/system/generated-main5.js diff --git a/test/chunking-form/samples/aliasing-extensions/_expected/system/main1.js b/test/chunking-form/samples/aliasing-extensions/_expected/system/main1.js index fe72dd01fb6..7ca66f3c42e 100644 --- a/test/chunking-form/samples/aliasing-extensions/_expected/system/main1.js +++ b/test/chunking-form/samples/aliasing-extensions/_expected/system/main1.js @@ -4,8 +4,8 @@ System.register([], function (exports, module) { execute: function () { console.log('main1'); - module.import('./generated-chunk.js'); - module.import('./generated-chunk2.js'); + module.import('./generated-main4.dynamic.js'); + module.import('./generated-main5.js'); } }; diff --git a/test/chunking-form/samples/dynamic-import-chained/_expected/amd/generated-chunk2.js b/test/chunking-form/samples/dynamic-import-chained/_expected/amd/generated-dep1.js similarity index 83% rename from test/chunking-form/samples/dynamic-import-chained/_expected/amd/generated-chunk2.js rename to test/chunking-form/samples/dynamic-import-chained/_expected/amd/generated-dep1.js index a3a007a9219..83e82a16985 100644 --- a/test/chunking-form/samples/dynamic-import-chained/_expected/amd/generated-chunk2.js +++ b/test/chunking-form/samples/dynamic-import-chained/_expected/amd/generated-dep1.js @@ -1,6 +1,6 @@ define(['require'], function (require) { 'use strict'; console.log('dep1'); - new Promise(function (resolve, reject) { require(['./generated-chunk'], resolve, reject) }); + new Promise(function (resolve, reject) { require(['./generated-dep2'], resolve, reject) }); }); diff --git a/test/chunking-form/samples/dynamic-import-chained/_expected/amd/generated-chunk.js b/test/chunking-form/samples/dynamic-import-chained/_expected/amd/generated-dep2.js similarity index 100% rename from test/chunking-form/samples/dynamic-import-chained/_expected/amd/generated-chunk.js rename to test/chunking-form/samples/dynamic-import-chained/_expected/amd/generated-dep2.js diff --git a/test/chunking-form/samples/dynamic-import-chained/_expected/amd/main.js b/test/chunking-form/samples/dynamic-import-chained/_expected/amd/main.js index 4c78beff51c..a337561f677 100644 --- a/test/chunking-form/samples/dynamic-import-chained/_expected/amd/main.js +++ b/test/chunking-form/samples/dynamic-import-chained/_expected/amd/main.js @@ -1,6 +1,6 @@ define(['require'], function (require) { 'use strict'; console.log('main'); - new Promise(function (resolve, reject) { require(['./generated-chunk2'], resolve, reject) }); + new Promise(function (resolve, reject) { require(['./generated-dep1'], resolve, reject) }); }); diff --git a/test/chunking-form/samples/dynamic-import-chained/_expected/cjs/generated-chunk2.js b/test/chunking-form/samples/dynamic-import-chained/_expected/cjs/generated-chunk2.js deleted file mode 100644 index 264ed3db946..00000000000 --- a/test/chunking-form/samples/dynamic-import-chained/_expected/cjs/generated-chunk2.js +++ /dev/null @@ -1,4 +0,0 @@ -'use strict'; - -console.log('dep1'); -Promise.resolve(require('./generated-chunk.js')); diff --git a/test/chunking-form/samples/dynamic-import-chained/_expected/cjs/generated-dep1.js b/test/chunking-form/samples/dynamic-import-chained/_expected/cjs/generated-dep1.js new file mode 100644 index 00000000000..8f77bed67fc --- /dev/null +++ b/test/chunking-form/samples/dynamic-import-chained/_expected/cjs/generated-dep1.js @@ -0,0 +1,4 @@ +'use strict'; + +console.log('dep1'); +Promise.resolve(require('./generated-dep2.js')); diff --git a/test/chunking-form/samples/dynamic-import-chained/_expected/cjs/generated-chunk.js b/test/chunking-form/samples/dynamic-import-chained/_expected/cjs/generated-dep2.js similarity index 100% rename from test/chunking-form/samples/dynamic-import-chained/_expected/cjs/generated-chunk.js rename to test/chunking-form/samples/dynamic-import-chained/_expected/cjs/generated-dep2.js diff --git a/test/chunking-form/samples/dynamic-import-chained/_expected/cjs/main.js b/test/chunking-form/samples/dynamic-import-chained/_expected/cjs/main.js index f94f250a8bb..aeff3cd02fb 100644 --- a/test/chunking-form/samples/dynamic-import-chained/_expected/cjs/main.js +++ b/test/chunking-form/samples/dynamic-import-chained/_expected/cjs/main.js @@ -1,4 +1,4 @@ 'use strict'; console.log('main'); -Promise.resolve(require('./generated-chunk2.js')); +Promise.resolve(require('./generated-dep1.js')); diff --git a/test/chunking-form/samples/dynamic-import-chained/_expected/es/generated-chunk2.js b/test/chunking-form/samples/dynamic-import-chained/_expected/es/generated-chunk2.js deleted file mode 100644 index 829d0490ba6..00000000000 --- a/test/chunking-form/samples/dynamic-import-chained/_expected/es/generated-chunk2.js +++ /dev/null @@ -1,2 +0,0 @@ -console.log('dep1'); -import('./generated-chunk.js'); diff --git a/test/chunking-form/samples/dynamic-import-chained/_expected/es/generated-dep1.js b/test/chunking-form/samples/dynamic-import-chained/_expected/es/generated-dep1.js new file mode 100644 index 00000000000..a644729548a --- /dev/null +++ b/test/chunking-form/samples/dynamic-import-chained/_expected/es/generated-dep1.js @@ -0,0 +1,2 @@ +console.log('dep1'); +import('./generated-dep2.js'); diff --git a/test/chunking-form/samples/dynamic-import-chained/_expected/es/generated-chunk.js b/test/chunking-form/samples/dynamic-import-chained/_expected/es/generated-dep2.js similarity index 100% rename from test/chunking-form/samples/dynamic-import-chained/_expected/es/generated-chunk.js rename to test/chunking-form/samples/dynamic-import-chained/_expected/es/generated-dep2.js diff --git a/test/chunking-form/samples/dynamic-import-chained/_expected/es/main.js b/test/chunking-form/samples/dynamic-import-chained/_expected/es/main.js index 8e124b5d186..0844106d368 100644 --- a/test/chunking-form/samples/dynamic-import-chained/_expected/es/main.js +++ b/test/chunking-form/samples/dynamic-import-chained/_expected/es/main.js @@ -1,2 +1,2 @@ console.log('main'); -import('./generated-chunk2.js'); +import('./generated-dep1.js'); diff --git a/test/chunking-form/samples/dynamic-import-chained/_expected/system/generated-chunk2.js b/test/chunking-form/samples/dynamic-import-chained/_expected/system/generated-dep1.js similarity index 76% rename from test/chunking-form/samples/dynamic-import-chained/_expected/system/generated-chunk2.js rename to test/chunking-form/samples/dynamic-import-chained/_expected/system/generated-dep1.js index 83e8602aefd..40c0c5a289e 100644 --- a/test/chunking-form/samples/dynamic-import-chained/_expected/system/generated-chunk2.js +++ b/test/chunking-form/samples/dynamic-import-chained/_expected/system/generated-dep1.js @@ -4,7 +4,7 @@ System.register([], function (exports, module) { execute: function () { console.log('dep1'); - module.import('./generated-chunk.js'); + module.import('./generated-dep2.js'); } }; diff --git a/test/chunking-form/samples/dynamic-import-chained/_expected/system/generated-chunk.js b/test/chunking-form/samples/dynamic-import-chained/_expected/system/generated-dep2.js similarity index 100% rename from test/chunking-form/samples/dynamic-import-chained/_expected/system/generated-chunk.js rename to test/chunking-form/samples/dynamic-import-chained/_expected/system/generated-dep2.js diff --git a/test/chunking-form/samples/dynamic-import-chained/_expected/system/main.js b/test/chunking-form/samples/dynamic-import-chained/_expected/system/main.js index 7dfd4a28cae..818a9966643 100644 --- a/test/chunking-form/samples/dynamic-import-chained/_expected/system/main.js +++ b/test/chunking-form/samples/dynamic-import-chained/_expected/system/main.js @@ -4,7 +4,7 @@ System.register([], function (exports, module) { execute: function () { console.log('main'); - module.import('./generated-chunk2.js'); + module.import('./generated-dep1.js'); } }; diff --git a/test/chunking-form/samples/dynamic-import-chunking/_expected/amd/generated-chunk2.js b/test/chunking-form/samples/dynamic-import-chunking/_expected/amd/generated-dep2.js similarity index 100% rename from test/chunking-form/samples/dynamic-import-chunking/_expected/amd/generated-chunk2.js rename to test/chunking-form/samples/dynamic-import-chunking/_expected/amd/generated-dep2.js diff --git a/test/chunking-form/samples/dynamic-import-chunking/_expected/amd/main.js b/test/chunking-form/samples/dynamic-import-chunking/_expected/amd/main.js index 9a5bfc4f5fe..ef675ab6761 100644 --- a/test/chunking-form/samples/dynamic-import-chunking/_expected/amd/main.js +++ b/test/chunking-form/samples/dynamic-import-chunking/_expected/amd/main.js @@ -9,7 +9,7 @@ define(['require', './generated-chunk'], function (require, __chunk_1) { 'use st } function dynamic (num) { - return new Promise(function (resolve, reject) { require(['./generated-chunk2'], resolve, reject) }) + return new Promise(function (resolve, reject) { require(['./generated-dep2'], resolve, reject) }) .then(dep2 => { return dep2.mult(num); }); diff --git a/test/chunking-form/samples/dynamic-import-chunking/_expected/cjs/generated-chunk2.js b/test/chunking-form/samples/dynamic-import-chunking/_expected/cjs/generated-dep2.js similarity index 100% rename from test/chunking-form/samples/dynamic-import-chunking/_expected/cjs/generated-chunk2.js rename to test/chunking-form/samples/dynamic-import-chunking/_expected/cjs/generated-dep2.js diff --git a/test/chunking-form/samples/dynamic-import-chunking/_expected/cjs/main.js b/test/chunking-form/samples/dynamic-import-chunking/_expected/cjs/main.js index 5f57de05b13..cb2d4803bf4 100644 --- a/test/chunking-form/samples/dynamic-import-chunking/_expected/cjs/main.js +++ b/test/chunking-form/samples/dynamic-import-chunking/_expected/cjs/main.js @@ -11,7 +11,7 @@ function fn (num) { } function dynamic (num) { - return Promise.resolve(require('./generated-chunk2.js')) + return Promise.resolve(require('./generated-dep2.js')) .then(dep2 => { return dep2.mult(num); }); diff --git a/test/chunking-form/samples/dynamic-import-chunking/_expected/es/generated-chunk2.js b/test/chunking-form/samples/dynamic-import-chunking/_expected/es/generated-dep2.js similarity index 100% rename from test/chunking-form/samples/dynamic-import-chunking/_expected/es/generated-chunk2.js rename to test/chunking-form/samples/dynamic-import-chunking/_expected/es/generated-dep2.js diff --git a/test/chunking-form/samples/dynamic-import-chunking/_expected/es/main.js b/test/chunking-form/samples/dynamic-import-chunking/_expected/es/main.js index cae50cac305..d1c97541a75 100644 --- a/test/chunking-form/samples/dynamic-import-chunking/_expected/es/main.js +++ b/test/chunking-form/samples/dynamic-import-chunking/_expected/es/main.js @@ -9,7 +9,7 @@ function fn (num) { } function dynamic (num) { - return import('./generated-chunk2.js') + return import('./generated-dep2.js') .then(dep2 => { return dep2.mult(num); }); diff --git a/test/chunking-form/samples/dynamic-import-chunking/_expected/system/generated-chunk2.js b/test/chunking-form/samples/dynamic-import-chunking/_expected/system/generated-dep2.js similarity index 100% rename from test/chunking-form/samples/dynamic-import-chunking/_expected/system/generated-chunk2.js rename to test/chunking-form/samples/dynamic-import-chunking/_expected/system/generated-dep2.js diff --git a/test/chunking-form/samples/dynamic-import-chunking/_expected/system/main.js b/test/chunking-form/samples/dynamic-import-chunking/_expected/system/main.js index 02815d8471c..361619daf83 100644 --- a/test/chunking-form/samples/dynamic-import-chunking/_expected/system/main.js +++ b/test/chunking-form/samples/dynamic-import-chunking/_expected/system/main.js @@ -16,7 +16,7 @@ System.register(['./generated-chunk.js'], function (exports, module) { } function dynamic (num) { - return module.import('./generated-chunk2.js') + return module.import('./generated-dep2.js') .then(dep2 => { return dep2.mult(num); }); diff --git a/test/chunking-form/samples/dynamic-import-facade/_expected/amd/generated-chunk2.js b/test/chunking-form/samples/dynamic-import-facade/_expected/amd/generated-dynamic.js similarity index 53% rename from test/chunking-form/samples/dynamic-import-facade/_expected/amd/generated-chunk2.js rename to test/chunking-form/samples/dynamic-import-facade/_expected/amd/generated-dynamic.js index 4fb60e87db8..f5831da416e 100644 --- a/test/chunking-form/samples/dynamic-import-facade/_expected/amd/generated-chunk2.js +++ b/test/chunking-form/samples/dynamic-import-facade/_expected/amd/generated-dynamic.js @@ -1,7 +1,7 @@ -define(['exports', './generated-chunk'], function (exports, dynamic_js) { 'use strict'; +define(['exports', './generated-chunk'], function (exports, dynamic) { 'use strict'; - exports.dynamic = dynamic_js.dynamic; + exports.dynamic = dynamic.dynamic; }); diff --git a/test/chunking-form/samples/dynamic-import-facade/_expected/amd/main1.js b/test/chunking-form/samples/dynamic-import-facade/_expected/amd/main1.js index 3efdb461ba4..4dc4a80e97f 100644 --- a/test/chunking-form/samples/dynamic-import-facade/_expected/amd/main1.js +++ b/test/chunking-form/samples/dynamic-import-facade/_expected/amd/main1.js @@ -1,5 +1,5 @@ define(['require'], function (require) { 'use strict'; - new Promise(function (resolve, reject) { require(['./generated-chunk2'], resolve, reject) }).then(({dynamic}) => console.log('main1', dynamic)); + new Promise(function (resolve, reject) { require(['./generated-dynamic'], resolve, reject) }).then(({dynamic}) => console.log('main1', dynamic)); }); diff --git a/test/chunking-form/samples/dynamic-import-facade/_expected/amd/main2.js b/test/chunking-form/samples/dynamic-import-facade/_expected/amd/main2.js index fdc6e221a48..0efdba2aa84 100644 --- a/test/chunking-form/samples/dynamic-import-facade/_expected/amd/main2.js +++ b/test/chunking-form/samples/dynamic-import-facade/_expected/amd/main2.js @@ -1,5 +1,5 @@ -define(['./generated-chunk'], function (dynamic_js) { 'use strict'; +define(['./generated-chunk'], function (dynamic) { 'use strict'; - console.log('main2', dynamic_js.dynamic, dynamic_js.dep); + console.log('main2', dynamic.dynamic, dynamic.dep); }); diff --git a/test/chunking-form/samples/dynamic-import-facade/_expected/cjs/generated-chunk2.js b/test/chunking-form/samples/dynamic-import-facade/_expected/cjs/generated-chunk2.js deleted file mode 100644 index 760a1b8ffb8..00000000000 --- a/test/chunking-form/samples/dynamic-import-facade/_expected/cjs/generated-chunk2.js +++ /dev/null @@ -1,7 +0,0 @@ -'use strict'; - -var dynamic_js = require('./generated-chunk.js'); - - - -exports.dynamic = dynamic_js.dynamic; diff --git a/test/chunking-form/samples/dynamic-import-facade/_expected/cjs/generated-dynamic.js b/test/chunking-form/samples/dynamic-import-facade/_expected/cjs/generated-dynamic.js new file mode 100644 index 00000000000..9ce0252a483 --- /dev/null +++ b/test/chunking-form/samples/dynamic-import-facade/_expected/cjs/generated-dynamic.js @@ -0,0 +1,7 @@ +'use strict'; + +var dynamic = require('./generated-chunk.js'); + + + +exports.dynamic = dynamic.dynamic; diff --git a/test/chunking-form/samples/dynamic-import-facade/_expected/cjs/main1.js b/test/chunking-form/samples/dynamic-import-facade/_expected/cjs/main1.js index 3c929ea0738..374a10ce818 100644 --- a/test/chunking-form/samples/dynamic-import-facade/_expected/cjs/main1.js +++ b/test/chunking-form/samples/dynamic-import-facade/_expected/cjs/main1.js @@ -1,3 +1,3 @@ 'use strict'; -Promise.resolve(require('./generated-chunk2.js')).then(({dynamic}) => console.log('main1', dynamic)); +Promise.resolve(require('./generated-dynamic.js')).then(({dynamic}) => console.log('main1', dynamic)); diff --git a/test/chunking-form/samples/dynamic-import-facade/_expected/cjs/main2.js b/test/chunking-form/samples/dynamic-import-facade/_expected/cjs/main2.js index e9c43ce79ee..924410b061d 100644 --- a/test/chunking-form/samples/dynamic-import-facade/_expected/cjs/main2.js +++ b/test/chunking-form/samples/dynamic-import-facade/_expected/cjs/main2.js @@ -1,5 +1,5 @@ 'use strict'; -var dynamic_js = require('./generated-chunk.js'); +var dynamic = require('./generated-chunk.js'); -console.log('main2', dynamic_js.dynamic, dynamic_js.dep); +console.log('main2', dynamic.dynamic, dynamic.dep); diff --git a/test/chunking-form/samples/dynamic-import-facade/_expected/es/generated-chunk2.js b/test/chunking-form/samples/dynamic-import-facade/_expected/es/generated-dynamic.js similarity index 100% rename from test/chunking-form/samples/dynamic-import-facade/_expected/es/generated-chunk2.js rename to test/chunking-form/samples/dynamic-import-facade/_expected/es/generated-dynamic.js diff --git a/test/chunking-form/samples/dynamic-import-facade/_expected/es/main1.js b/test/chunking-form/samples/dynamic-import-facade/_expected/es/main1.js index e895a10f9a4..2fbb59a4af9 100644 --- a/test/chunking-form/samples/dynamic-import-facade/_expected/es/main1.js +++ b/test/chunking-form/samples/dynamic-import-facade/_expected/es/main1.js @@ -1 +1 @@ -import('./generated-chunk2.js').then(({dynamic}) => console.log('main1', dynamic)); +import('./generated-dynamic.js').then(({dynamic}) => console.log('main1', dynamic)); diff --git a/test/chunking-form/samples/dynamic-import-facade/_expected/system/generated-chunk2.js b/test/chunking-form/samples/dynamic-import-facade/_expected/system/generated-dynamic.js similarity index 100% rename from test/chunking-form/samples/dynamic-import-facade/_expected/system/generated-chunk2.js rename to test/chunking-form/samples/dynamic-import-facade/_expected/system/generated-dynamic.js diff --git a/test/chunking-form/samples/dynamic-import-facade/_expected/system/main1.js b/test/chunking-form/samples/dynamic-import-facade/_expected/system/main1.js index c4de0a21d81..c49f55149f2 100644 --- a/test/chunking-form/samples/dynamic-import-facade/_expected/system/main1.js +++ b/test/chunking-form/samples/dynamic-import-facade/_expected/system/main1.js @@ -3,7 +3,7 @@ System.register([], function (exports, module) { return { execute: function () { - module.import('./generated-chunk2.js').then(({dynamic}) => console.log('main1', dynamic)); + module.import('./generated-dynamic.js').then(({dynamic}) => console.log('main1', dynamic)); } }; diff --git a/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/amd/generated-chunk.js b/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/amd/generated-inlined.js similarity index 100% rename from test/chunking-form/samples/dynamic-import-inline-colouring/_expected/amd/generated-chunk.js rename to test/chunking-form/samples/dynamic-import-inline-colouring/_expected/amd/generated-inlined.js diff --git a/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/amd/generated-chunk2.js b/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/amd/generated-separate.js similarity index 100% rename from test/chunking-form/samples/dynamic-import-inline-colouring/_expected/amd/generated-chunk2.js rename to test/chunking-form/samples/dynamic-import-inline-colouring/_expected/amd/generated-separate.js diff --git a/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/amd/main1.js b/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/amd/main1.js index 9c51a929f27..ab477ff73b1 100644 --- a/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/amd/main1.js +++ b/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/amd/main1.js @@ -1,7 +1,7 @@ -define(['require', 'exports', './generated-chunk', './generated-chunk2'], function (require, exports, inlined_js, separate_js) { 'use strict'; +define(['require', 'exports', './generated-inlined', './generated-separate'], function (require, exports, inlined$1, separate$1) { 'use strict'; - const inlined = new Promise(function (resolve, reject) { require(['./generated-chunk'], resolve, reject) }); - const separate = new Promise(function (resolve, reject) { require(['./generated-chunk2'], resolve, reject) }); + const inlined = new Promise(function (resolve, reject) { require(['./generated-inlined'], resolve, reject) }); + const separate = new Promise(function (resolve, reject) { require(['./generated-separate'], resolve, reject) }); exports.inlined = inlined; exports.separate = separate; diff --git a/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/amd/main2.js b/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/amd/main2.js index 7ce766added..0be3fee1ac0 100644 --- a/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/amd/main2.js +++ b/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/amd/main2.js @@ -1,6 +1,6 @@ define(['require', 'exports'], function (require, exports) { 'use strict'; - const separate = new Promise(function (resolve, reject) { require(['./generated-chunk2'], resolve, reject) }); + const separate = new Promise(function (resolve, reject) { require(['./generated-separate'], resolve, reject) }); exports.separate = separate; diff --git a/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/cjs/generated-chunk.js b/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/cjs/generated-inlined.js similarity index 100% rename from test/chunking-form/samples/dynamic-import-inline-colouring/_expected/cjs/generated-chunk.js rename to test/chunking-form/samples/dynamic-import-inline-colouring/_expected/cjs/generated-inlined.js diff --git a/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/cjs/generated-chunk2.js b/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/cjs/generated-separate.js similarity index 100% rename from test/chunking-form/samples/dynamic-import-inline-colouring/_expected/cjs/generated-chunk2.js rename to test/chunking-form/samples/dynamic-import-inline-colouring/_expected/cjs/generated-separate.js diff --git a/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/cjs/main1.js b/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/cjs/main1.js index a0422c52ed6..7154e55ccc7 100644 --- a/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/cjs/main1.js +++ b/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/cjs/main1.js @@ -2,11 +2,11 @@ Object.defineProperty(exports, '__esModule', { value: true }); -require('./generated-chunk.js'); -require('./generated-chunk2.js'); +require('./generated-inlined.js'); +require('./generated-separate.js'); -const inlined = Promise.resolve(require('./generated-chunk.js')); -const separate = Promise.resolve(require('./generated-chunk2.js')); +const inlined = Promise.resolve(require('./generated-inlined.js')); +const separate = Promise.resolve(require('./generated-separate.js')); exports.inlined = inlined; exports.separate = separate; diff --git a/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/cjs/main2.js b/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/cjs/main2.js index bdaaa5d1ad3..62e8058aba0 100644 --- a/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/cjs/main2.js +++ b/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/cjs/main2.js @@ -2,6 +2,6 @@ Object.defineProperty(exports, '__esModule', { value: true }); -const separate = Promise.resolve(require('./generated-chunk2.js')); +const separate = Promise.resolve(require('./generated-separate.js')); exports.separate = separate; diff --git a/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/es/generated-chunk.js b/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/es/generated-inlined.js similarity index 100% rename from test/chunking-form/samples/dynamic-import-inline-colouring/_expected/es/generated-chunk.js rename to test/chunking-form/samples/dynamic-import-inline-colouring/_expected/es/generated-inlined.js diff --git a/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/es/generated-chunk2.js b/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/es/generated-separate.js similarity index 100% rename from test/chunking-form/samples/dynamic-import-inline-colouring/_expected/es/generated-chunk2.js rename to test/chunking-form/samples/dynamic-import-inline-colouring/_expected/es/generated-separate.js diff --git a/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/es/main1.js b/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/es/main1.js index 8f43588ea64..4a8004df29f 100644 --- a/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/es/main1.js +++ b/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/es/main1.js @@ -1,7 +1,7 @@ -import './generated-chunk.js'; -import './generated-chunk2.js'; +import './generated-inlined.js'; +import './generated-separate.js'; -const inlined = import('./generated-chunk.js'); -const separate = import('./generated-chunk2.js'); +const inlined = import('./generated-inlined.js'); +const separate = import('./generated-separate.js'); export { inlined, separate }; diff --git a/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/es/main2.js b/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/es/main2.js index 0175fd44065..1ede98ed451 100644 --- a/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/es/main2.js +++ b/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/es/main2.js @@ -1,3 +1,3 @@ -const separate = import('./generated-chunk2.js'); +const separate = import('./generated-separate.js'); export { separate }; diff --git a/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/system/generated-chunk.js b/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/system/generated-inlined.js similarity index 100% rename from test/chunking-form/samples/dynamic-import-inline-colouring/_expected/system/generated-chunk.js rename to test/chunking-form/samples/dynamic-import-inline-colouring/_expected/system/generated-inlined.js diff --git a/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/system/generated-chunk2.js b/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/system/generated-separate.js similarity index 100% rename from test/chunking-form/samples/dynamic-import-inline-colouring/_expected/system/generated-chunk2.js rename to test/chunking-form/samples/dynamic-import-inline-colouring/_expected/system/generated-separate.js diff --git a/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/system/main1.js b/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/system/main1.js index 25ed60fd12a..9523ff96e05 100644 --- a/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/system/main1.js +++ b/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/system/main1.js @@ -1,11 +1,11 @@ -System.register(['./generated-chunk.js', './generated-chunk2.js'], function (exports, module) { +System.register(['./generated-inlined.js', './generated-separate.js'], function (exports, module) { 'use strict'; return { setters: [function () {}, function () {}], execute: function () { - const inlined = exports('inlined', module.import('./generated-chunk.js')); - const separate = exports('separate', module.import('./generated-chunk2.js')); + const inlined = exports('inlined', module.import('./generated-inlined.js')); + const separate = exports('separate', module.import('./generated-separate.js')); } }; diff --git a/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/system/main2.js b/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/system/main2.js index 4e5e7630150..f54417af5a0 100644 --- a/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/system/main2.js +++ b/test/chunking-form/samples/dynamic-import-inline-colouring/_expected/system/main2.js @@ -3,7 +3,7 @@ System.register([], function (exports, module) { return { execute: function () { - const separate = exports('separate', module.import('./generated-chunk2.js')); + const separate = exports('separate', module.import('./generated-separate.js')); } }; diff --git a/test/chunking-form/samples/dynamic-import-only-reexports/_expected/amd/generated-chunk.js b/test/chunking-form/samples/dynamic-import-only-reexports/_expected/amd/generated-dynamic.js similarity index 100% rename from test/chunking-form/samples/dynamic-import-only-reexports/_expected/amd/generated-chunk.js rename to test/chunking-form/samples/dynamic-import-only-reexports/_expected/amd/generated-dynamic.js diff --git a/test/chunking-form/samples/dynamic-import-only-reexports/_expected/amd/main.js b/test/chunking-form/samples/dynamic-import-only-reexports/_expected/amd/main.js index 7d42d18212d..86ed8240329 100644 --- a/test/chunking-form/samples/dynamic-import-only-reexports/_expected/amd/main.js +++ b/test/chunking-form/samples/dynamic-import-only-reexports/_expected/amd/main.js @@ -1,5 +1,5 @@ define(['require'], function (require) { 'use strict'; - new Promise(function (resolve, reject) { require(['./generated-chunk'], resolve, reject) }).then(({ value }) => console.log(value)); + new Promise(function (resolve, reject) { require(['./generated-dynamic'], resolve, reject) }).then(({ value }) => console.log(value)); }); diff --git a/test/chunking-form/samples/dynamic-import-only-reexports/_expected/cjs/generated-chunk.js b/test/chunking-form/samples/dynamic-import-only-reexports/_expected/cjs/generated-dynamic.js similarity index 100% rename from test/chunking-form/samples/dynamic-import-only-reexports/_expected/cjs/generated-chunk.js rename to test/chunking-form/samples/dynamic-import-only-reexports/_expected/cjs/generated-dynamic.js diff --git a/test/chunking-form/samples/dynamic-import-only-reexports/_expected/cjs/main.js b/test/chunking-form/samples/dynamic-import-only-reexports/_expected/cjs/main.js index 53775291ad7..8da97186d0e 100644 --- a/test/chunking-form/samples/dynamic-import-only-reexports/_expected/cjs/main.js +++ b/test/chunking-form/samples/dynamic-import-only-reexports/_expected/cjs/main.js @@ -1,3 +1,3 @@ 'use strict'; -Promise.resolve(require('./generated-chunk.js')).then(({ value }) => console.log(value)); +Promise.resolve(require('./generated-dynamic.js')).then(({ value }) => console.log(value)); diff --git a/test/chunking-form/samples/dynamic-import-only-reexports/_expected/es/generated-chunk.js b/test/chunking-form/samples/dynamic-import-only-reexports/_expected/es/generated-dynamic.js similarity index 100% rename from test/chunking-form/samples/dynamic-import-only-reexports/_expected/es/generated-chunk.js rename to test/chunking-form/samples/dynamic-import-only-reexports/_expected/es/generated-dynamic.js diff --git a/test/chunking-form/samples/dynamic-import-only-reexports/_expected/es/main.js b/test/chunking-form/samples/dynamic-import-only-reexports/_expected/es/main.js index 97a57b60b65..4b8de10a9a7 100644 --- a/test/chunking-form/samples/dynamic-import-only-reexports/_expected/es/main.js +++ b/test/chunking-form/samples/dynamic-import-only-reexports/_expected/es/main.js @@ -1 +1 @@ -import('./generated-chunk.js').then(({ value }) => console.log(value)); +import('./generated-dynamic.js').then(({ value }) => console.log(value)); diff --git a/test/chunking-form/samples/dynamic-import-only-reexports/_expected/system/generated-chunk.js b/test/chunking-form/samples/dynamic-import-only-reexports/_expected/system/generated-dynamic.js similarity index 100% rename from test/chunking-form/samples/dynamic-import-only-reexports/_expected/system/generated-chunk.js rename to test/chunking-form/samples/dynamic-import-only-reexports/_expected/system/generated-dynamic.js diff --git a/test/chunking-form/samples/dynamic-import-only-reexports/_expected/system/main.js b/test/chunking-form/samples/dynamic-import-only-reexports/_expected/system/main.js index 67f17ffe8c5..c9a3d7a8e03 100644 --- a/test/chunking-form/samples/dynamic-import-only-reexports/_expected/system/main.js +++ b/test/chunking-form/samples/dynamic-import-only-reexports/_expected/system/main.js @@ -3,7 +3,7 @@ System.register([], function (exports, module) { return { execute: function () { - module.import('./generated-chunk.js').then(({ value }) => console.log(value)); + module.import('./generated-dynamic.js').then(({ value }) => console.log(value)); } }; diff --git a/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/amd/generated-chunk2.js b/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/amd/generated-dep1.js similarity index 59% rename from test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/amd/generated-chunk2.js rename to test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/amd/generated-dep1.js index 2e890387bbe..4c6c80f1699 100644 --- a/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/amd/generated-chunk2.js +++ b/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/amd/generated-dep1.js @@ -1,7 +1,7 @@ -define(['exports', './generated-chunk'], function (exports, dep1_js) { 'use strict'; +define(['exports', './generated-chunk'], function (exports, dep1) { 'use strict'; - exports.bar = dep1_js.bar; + exports.bar = dep1.bar; }); diff --git a/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/amd/main.js b/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/amd/main.js index 2b7ac5e4e0d..5f16b4ed626 100644 --- a/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/amd/main.js +++ b/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/amd/main.js @@ -1,5 +1,5 @@ -define(['./generated-chunk'], function (dep1_js) { 'use strict'; +define(['./generated-chunk'], function (dep1) { 'use strict'; - console.log(dep1_js.foo(), dep1_js.bar()); + console.log(dep1.foo(), dep1.bar()); }); diff --git a/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/amd/main2.js b/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/amd/main2.js index 794f49aeca2..86ec013aaab 100644 --- a/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/amd/main2.js +++ b/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/amd/main2.js @@ -1,5 +1,5 @@ define(['require'], function (require) { 'use strict'; - new Promise(function (resolve, reject) { require(['./generated-chunk2'], resolve, reject) }).then(({ bar }) => console.log(bar())); + new Promise(function (resolve, reject) { require(['./generated-dep1'], resolve, reject) }).then(({ bar }) => console.log(bar())); }); diff --git a/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/cjs/generated-chunk2.js b/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/cjs/generated-chunk2.js deleted file mode 100644 index ea4786b677e..00000000000 --- a/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/cjs/generated-chunk2.js +++ /dev/null @@ -1,7 +0,0 @@ -'use strict'; - -var dep1_js = require('./generated-chunk.js'); - - - -exports.bar = dep1_js.bar; diff --git a/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/cjs/generated-dep1.js b/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/cjs/generated-dep1.js new file mode 100644 index 00000000000..cf4187f08c2 --- /dev/null +++ b/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/cjs/generated-dep1.js @@ -0,0 +1,7 @@ +'use strict'; + +var dep1 = require('./generated-chunk.js'); + + + +exports.bar = dep1.bar; diff --git a/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/cjs/main.js b/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/cjs/main.js index e2eac98455c..12c7a0a7c3b 100644 --- a/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/cjs/main.js +++ b/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/cjs/main.js @@ -1,5 +1,5 @@ 'use strict'; -var dep1_js = require('./generated-chunk.js'); +var dep1 = require('./generated-chunk.js'); -console.log(dep1_js.foo(), dep1_js.bar()); +console.log(dep1.foo(), dep1.bar()); diff --git a/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/cjs/main2.js b/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/cjs/main2.js index 04aab10a99b..41b25026533 100644 --- a/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/cjs/main2.js +++ b/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/cjs/main2.js @@ -1,3 +1,3 @@ 'use strict'; -Promise.resolve(require('./generated-chunk2.js')).then(({ bar }) => console.log(bar())); +Promise.resolve(require('./generated-dep1.js')).then(({ bar }) => console.log(bar())); diff --git a/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/es/generated-chunk2.js b/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/es/generated-dep1.js similarity index 100% rename from test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/es/generated-chunk2.js rename to test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/es/generated-dep1.js diff --git a/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/es/main2.js b/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/es/main2.js index c93316e9992..00aba354edb 100644 --- a/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/es/main2.js +++ b/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/es/main2.js @@ -1 +1 @@ -import('./generated-chunk2.js').then(({ bar }) => console.log(bar())); +import('./generated-dep1.js').then(({ bar }) => console.log(bar())); diff --git a/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/system/generated-chunk2.js b/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/system/generated-dep1.js similarity index 100% rename from test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/system/generated-chunk2.js rename to test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/system/generated-dep1.js diff --git a/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/system/main2.js b/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/system/main2.js index 24b8ca32f1c..2f2c41db6e5 100644 --- a/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/system/main2.js +++ b/test/chunking-form/samples/dynamic-import-statically-imported-2/_expected/system/main2.js @@ -3,7 +3,7 @@ System.register([], function (exports, module) { return { execute: function () { - module.import('./generated-chunk2.js').then(({ bar }) => console.log(bar())); + module.import('./generated-dep1.js').then(({ bar }) => console.log(bar())); } }; diff --git a/test/chunking-form/samples/dynamic-import/_expected/amd/chunks/chunk2.js b/test/chunking-form/samples/dynamic-import/_expected/amd/chunks/other.js similarity index 100% rename from test/chunking-form/samples/dynamic-import/_expected/amd/chunks/chunk2.js rename to test/chunking-form/samples/dynamic-import/_expected/amd/chunks/other.js diff --git a/test/chunking-form/samples/dynamic-import/_expected/amd/main.js b/test/chunking-form/samples/dynamic-import/_expected/amd/main.js index 3c301a7e490..205e4fcd0fc 100644 --- a/test/chunking-form/samples/dynamic-import/_expected/amd/main.js +++ b/test/chunking-form/samples/dynamic-import/_expected/amd/main.js @@ -2,7 +2,7 @@ define(['require', 'exports', './chunks/chunk'], function (require, exports, __c assert.equal(__chunk_1.sharedValue, 'shared'); - const promise = new Promise(function (resolve, reject) { require(['./chunks/chunk2'], resolve, reject) }).then(result => + const promise = new Promise(function (resolve, reject) { require(['./chunks/other'], resolve, reject) }).then(result => assert.deepEqual(result, { value: 'shared' }) ); diff --git a/test/chunking-form/samples/dynamic-import/_expected/cjs/chunks/chunk2.js b/test/chunking-form/samples/dynamic-import/_expected/cjs/chunks/other.js similarity index 100% rename from test/chunking-form/samples/dynamic-import/_expected/cjs/chunks/chunk2.js rename to test/chunking-form/samples/dynamic-import/_expected/cjs/chunks/other.js diff --git a/test/chunking-form/samples/dynamic-import/_expected/cjs/main.js b/test/chunking-form/samples/dynamic-import/_expected/cjs/main.js index c5526455ed2..e4241fd2cf8 100644 --- a/test/chunking-form/samples/dynamic-import/_expected/cjs/main.js +++ b/test/chunking-form/samples/dynamic-import/_expected/cjs/main.js @@ -6,7 +6,7 @@ var __chunk_1 = require('./chunks/chunk.js'); assert.equal(__chunk_1.sharedValue, 'shared'); -const promise = Promise.resolve(require('./chunks/chunk2.js')).then(result => +const promise = Promise.resolve(require('./chunks/other.js')).then(result => assert.deepEqual(result, { value: 'shared' }) ); diff --git a/test/chunking-form/samples/dynamic-import/_expected/es/chunks/chunk2.js b/test/chunking-form/samples/dynamic-import/_expected/es/chunks/other.js similarity index 100% rename from test/chunking-form/samples/dynamic-import/_expected/es/chunks/chunk2.js rename to test/chunking-form/samples/dynamic-import/_expected/es/chunks/other.js diff --git a/test/chunking-form/samples/dynamic-import/_expected/es/main.js b/test/chunking-form/samples/dynamic-import/_expected/es/main.js index 457f2aba301..0bc9c02af44 100644 --- a/test/chunking-form/samples/dynamic-import/_expected/es/main.js +++ b/test/chunking-form/samples/dynamic-import/_expected/es/main.js @@ -2,7 +2,7 @@ import { a as sharedValue } from './chunks/chunk.js'; assert.equal(sharedValue, 'shared'); -const promise = import('./chunks/chunk2.js').then(result => +const promise = import('./chunks/other.js').then(result => assert.deepEqual(result, { value: 'shared' }) ); diff --git a/test/chunking-form/samples/dynamic-import/_expected/system/chunks/chunk2.js b/test/chunking-form/samples/dynamic-import/_expected/system/chunks/other.js similarity index 100% rename from test/chunking-form/samples/dynamic-import/_expected/system/chunks/chunk2.js rename to test/chunking-form/samples/dynamic-import/_expected/system/chunks/other.js diff --git a/test/chunking-form/samples/dynamic-import/_expected/system/main.js b/test/chunking-form/samples/dynamic-import/_expected/system/main.js index ace4b6cf31c..cd01a25c888 100644 --- a/test/chunking-form/samples/dynamic-import/_expected/system/main.js +++ b/test/chunking-form/samples/dynamic-import/_expected/system/main.js @@ -9,7 +9,7 @@ System.register(['./chunks/chunk.js'], function (exports, module) { assert.equal(sharedValue, 'shared'); - const promise = exports('promise', module.import('./chunks/chunk2.js').then(result => + const promise = exports('promise', module.import('./chunks/other.js').then(result => assert.deepEqual(result, { value: 'shared' }) )); diff --git a/test/chunking-form/samples/emit-chunk-facade/_expected/amd/generated-build-starter.js b/test/chunking-form/samples/emit-chunk-facade/_expected/amd/generated-build-starter.js index 432f32da2c3..4974a348248 100644 --- a/test/chunking-form/samples/emit-chunk-facade/_expected/amd/generated-build-starter.js +++ b/test/chunking-form/samples/emit-chunk-facade/_expected/amd/generated-build-starter.js @@ -1,9 +1,11 @@ define(['exports'], function (exports) { 'use strict'; - var value = 42; + const value = 42; + const otherValue = 43; console.log('startBuild', value); + exports.otherValue = otherValue; exports.value = value; }); diff --git a/test/chunking-form/samples/emit-chunk-facade/_expected/amd/generated-buildStart.js b/test/chunking-form/samples/emit-chunk-facade/_expected/amd/generated-buildStart.js index 90fb5bc3e0a..06143748495 100644 --- a/test/chunking-form/samples/emit-chunk-facade/_expected/amd/generated-buildStart.js +++ b/test/chunking-form/samples/emit-chunk-facade/_expected/amd/generated-buildStart.js @@ -1,8 +1,8 @@ -define(['exports', './generated-build-starter'], function (exports, buildStart) { 'use strict'; +define(['exports', './generated-build-starter'], function (exports, buildStarter) { 'use strict'; - exports.buildStartValue = buildStart.value; + exports.buildStartValue = buildStarter.value; Object.defineProperty(exports, '__esModule', { value: true }); diff --git a/test/chunking-form/samples/emit-chunk-facade/_expected/amd/main.js b/test/chunking-form/samples/emit-chunk-facade/_expected/amd/main.js index 328cf40fd71..f9191ee8ad4 100644 --- a/test/chunking-form/samples/emit-chunk-facade/_expected/amd/main.js +++ b/test/chunking-form/samples/emit-chunk-facade/_expected/amd/main.js @@ -1,5 +1,5 @@ -define(['./generated-build-starter'], function (buildStart) { 'use strict'; +define(['./generated-build-starter'], function (buildStarter) { 'use strict'; - console.log('main', buildStart.value); + console.log('main', buildStarter.value, buildStarter.otherValue); }); diff --git a/test/chunking-form/samples/emit-chunk-facade/_expected/cjs/generated-build-starter.js b/test/chunking-form/samples/emit-chunk-facade/_expected/cjs/generated-build-starter.js index edbeacb8d71..fecf7a3cd4c 100644 --- a/test/chunking-form/samples/emit-chunk-facade/_expected/cjs/generated-build-starter.js +++ b/test/chunking-form/samples/emit-chunk-facade/_expected/cjs/generated-build-starter.js @@ -1,7 +1,9 @@ 'use strict'; -var value = 42; +const value = 42; +const otherValue = 43; console.log('startBuild', value); +exports.otherValue = otherValue; exports.value = value; diff --git a/test/chunking-form/samples/emit-chunk-facade/_expected/cjs/generated-buildStart.js b/test/chunking-form/samples/emit-chunk-facade/_expected/cjs/generated-buildStart.js index 835455878ac..66c05cca4ba 100644 --- a/test/chunking-form/samples/emit-chunk-facade/_expected/cjs/generated-buildStart.js +++ b/test/chunking-form/samples/emit-chunk-facade/_expected/cjs/generated-buildStart.js @@ -2,8 +2,8 @@ Object.defineProperty(exports, '__esModule', { value: true }); -var buildStart = require('./generated-build-starter.js'); +var buildStarter = require('./generated-build-starter.js'); -exports.buildStartValue = buildStart.value; +exports.buildStartValue = buildStarter.value; diff --git a/test/chunking-form/samples/emit-chunk-facade/_expected/cjs/main.js b/test/chunking-form/samples/emit-chunk-facade/_expected/cjs/main.js index 828c65c903c..666c396846a 100644 --- a/test/chunking-form/samples/emit-chunk-facade/_expected/cjs/main.js +++ b/test/chunking-form/samples/emit-chunk-facade/_expected/cjs/main.js @@ -1,5 +1,5 @@ 'use strict'; -var buildStart = require('./generated-build-starter.js'); +var buildStarter = require('./generated-build-starter.js'); -console.log('main', buildStart.value); +console.log('main', buildStarter.value, buildStarter.otherValue); diff --git a/test/chunking-form/samples/emit-chunk-facade/_expected/es/generated-build-starter.js b/test/chunking-form/samples/emit-chunk-facade/_expected/es/generated-build-starter.js index f81734586e0..99728ea9c48 100644 --- a/test/chunking-form/samples/emit-chunk-facade/_expected/es/generated-build-starter.js +++ b/test/chunking-form/samples/emit-chunk-facade/_expected/es/generated-build-starter.js @@ -1,5 +1,6 @@ -var value = 42; +const value = 42; +const otherValue = 43; console.log('startBuild', value); -export { value as a }; +export { value as a, otherValue as b }; diff --git a/test/chunking-form/samples/emit-chunk-facade/_expected/es/main.js b/test/chunking-form/samples/emit-chunk-facade/_expected/es/main.js index 2282b46084d..eeb48762412 100644 --- a/test/chunking-form/samples/emit-chunk-facade/_expected/es/main.js +++ b/test/chunking-form/samples/emit-chunk-facade/_expected/es/main.js @@ -1,3 +1,3 @@ -import { a as value } from './generated-build-starter.js'; +import { a as value, b as otherValue } from './generated-build-starter.js'; -console.log('main', value); +console.log('main', value, otherValue); diff --git a/test/chunking-form/samples/emit-chunk-facade/_expected/system/generated-build-starter.js b/test/chunking-form/samples/emit-chunk-facade/_expected/system/generated-build-starter.js index 347c480523e..e3d0622be44 100644 --- a/test/chunking-form/samples/emit-chunk-facade/_expected/system/generated-build-starter.js +++ b/test/chunking-form/samples/emit-chunk-facade/_expected/system/generated-build-starter.js @@ -3,7 +3,8 @@ System.register([], function (exports, module) { return { execute: function () { - var value = exports('a', 42); + const value = exports('a', 42); + const otherValue = exports('b', 43); console.log('startBuild', value); diff --git a/test/chunking-form/samples/emit-chunk-facade/_expected/system/main.js b/test/chunking-form/samples/emit-chunk-facade/_expected/system/main.js index 899bb08fbe8..bdb5d51f748 100644 --- a/test/chunking-form/samples/emit-chunk-facade/_expected/system/main.js +++ b/test/chunking-form/samples/emit-chunk-facade/_expected/system/main.js @@ -1,13 +1,14 @@ System.register(['./generated-build-starter.js'], function (exports, module) { 'use strict'; - var value; + var value, otherValue; return { setters: [function (module) { value = module.a; + otherValue = module.b; }], execute: function () { - console.log('main', value); + console.log('main', value, otherValue); } }; diff --git a/test/chunking-form/samples/emit-chunk-facade/buildStart.js b/test/chunking-form/samples/emit-chunk-facade/buildStart.js index 41707ae1ea3..49baee4964e 100644 --- a/test/chunking-form/samples/emit-chunk-facade/buildStart.js +++ b/test/chunking-form/samples/emit-chunk-facade/buildStart.js @@ -1,4 +1,4 @@ -import value from './dep.js'; +import {value} from './dep.js'; console.log('startBuild', value); diff --git a/test/chunking-form/samples/emit-chunk-facade/dep.js b/test/chunking-form/samples/emit-chunk-facade/dep.js index 7a4e8a723a4..a2db6341120 100644 --- a/test/chunking-form/samples/emit-chunk-facade/dep.js +++ b/test/chunking-form/samples/emit-chunk-facade/dep.js @@ -1 +1,2 @@ -export default 42; +export const value = 42; +export const otherValue = 43; diff --git a/test/chunking-form/samples/emit-chunk-facade/main.js b/test/chunking-form/samples/emit-chunk-facade/main.js index 4a9b3a3f405..df41d56376c 100644 --- a/test/chunking-form/samples/emit-chunk-facade/main.js +++ b/test/chunking-form/samples/emit-chunk-facade/main.js @@ -1,3 +1,3 @@ -import value from './dep.js'; +import { value, otherValue } from './dep'; -console.log('main', value); +console.log('main', value, otherValue); diff --git a/test/chunking-form/samples/emit-chunk-worker/_expected/amd/chunks/chunk2.js b/test/chunking-form/samples/emit-chunk-worker/_expected/amd/chunks/nested.js similarity index 100% rename from test/chunking-form/samples/emit-chunk-worker/_expected/amd/chunks/chunk2.js rename to test/chunking-form/samples/emit-chunk-worker/_expected/amd/chunks/nested.js diff --git a/test/chunking-form/samples/emit-chunk-worker/_expected/amd/main.js b/test/chunking-form/samples/emit-chunk-worker/_expected/amd/main.js index 7c337df5ec4..287f2f571b1 100644 --- a/test/chunking-form/samples/emit-chunk-worker/_expected/amd/main.js +++ b/test/chunking-form/samples/emit-chunk-worker/_expected/amd/main.js @@ -8,7 +8,7 @@ define(['module', 'require', './chunks/chunk'], function (module, require, __chu document.body.innerHTML += `

main: ${__chunk_1.shared}

`; getWorkerMessage().then(message => (document.body.innerHTML += `

1: ${message.data}

`)); - new Promise(function (resolve, reject) { require(['./chunks/chunk2'], resolve, reject) }) + new Promise(function (resolve, reject) { require(['./chunks/nested'], resolve, reject) }) .then(result => result.getWorkerMessage()) .then(message => (document.body.innerHTML += `

2: ${message.data}

`)); diff --git a/test/chunking-form/samples/emit-chunk-worker/_expected/cjs/chunks/chunk2.js b/test/chunking-form/samples/emit-chunk-worker/_expected/cjs/chunks/nested.js similarity index 100% rename from test/chunking-form/samples/emit-chunk-worker/_expected/cjs/chunks/chunk2.js rename to test/chunking-form/samples/emit-chunk-worker/_expected/cjs/chunks/nested.js diff --git a/test/chunking-form/samples/emit-chunk-worker/_expected/cjs/main.js b/test/chunking-form/samples/emit-chunk-worker/_expected/cjs/main.js index 929cf5ec04a..2fb3a0fd077 100644 --- a/test/chunking-form/samples/emit-chunk-worker/_expected/cjs/main.js +++ b/test/chunking-form/samples/emit-chunk-worker/_expected/cjs/main.js @@ -10,6 +10,6 @@ const getWorkerMessage = () => new Promise(resolve => { document.body.innerHTML += `

main: ${__chunk_1.shared}

`; getWorkerMessage().then(message => (document.body.innerHTML += `

1: ${message.data}

`)); -Promise.resolve(require('./chunks/chunk2.js')) +Promise.resolve(require('./chunks/nested.js')) .then(result => result.getWorkerMessage()) .then(message => (document.body.innerHTML += `

2: ${message.data}

`)); diff --git a/test/chunking-form/samples/emit-chunk-worker/_expected/es/chunks/chunk2.js b/test/chunking-form/samples/emit-chunk-worker/_expected/es/chunks/nested.js similarity index 100% rename from test/chunking-form/samples/emit-chunk-worker/_expected/es/chunks/chunk2.js rename to test/chunking-form/samples/emit-chunk-worker/_expected/es/chunks/nested.js diff --git a/test/chunking-form/samples/emit-chunk-worker/_expected/es/main.js b/test/chunking-form/samples/emit-chunk-worker/_expected/es/main.js index 77ab1097b33..69ed05a894e 100644 --- a/test/chunking-form/samples/emit-chunk-worker/_expected/es/main.js +++ b/test/chunking-form/samples/emit-chunk-worker/_expected/es/main.js @@ -8,6 +8,6 @@ const getWorkerMessage = () => new Promise(resolve => { document.body.innerHTML += `

main: ${shared}

`; getWorkerMessage().then(message => (document.body.innerHTML += `

1: ${message.data}

`)); -import('./chunks/chunk2.js') +import('./chunks/nested.js') .then(result => result.getWorkerMessage()) .then(message => (document.body.innerHTML += `

2: ${message.data}

`)); diff --git a/test/chunking-form/samples/emit-chunk-worker/_expected/system/chunks/chunk2.js b/test/chunking-form/samples/emit-chunk-worker/_expected/system/chunks/nested.js similarity index 100% rename from test/chunking-form/samples/emit-chunk-worker/_expected/system/chunks/chunk2.js rename to test/chunking-form/samples/emit-chunk-worker/_expected/system/chunks/nested.js diff --git a/test/chunking-form/samples/emit-chunk-worker/_expected/system/main.js b/test/chunking-form/samples/emit-chunk-worker/_expected/system/main.js index 07d1929dae4..1d7867c7769 100644 --- a/test/chunking-form/samples/emit-chunk-worker/_expected/system/main.js +++ b/test/chunking-form/samples/emit-chunk-worker/_expected/system/main.js @@ -15,7 +15,7 @@ System.register(['./chunks/chunk.js'], function (exports, module) { document.body.innerHTML += `

main: ${shared}

`; getWorkerMessage().then(message => (document.body.innerHTML += `

1: ${message.data}

`)); - module.import('./chunks/chunk2.js') + module.import('./chunks/nested.js') .then(result => result.getWorkerMessage()) .then(message => (document.body.innerHTML += `

2: ${message.data}

`)); diff --git a/test/chunking-form/samples/entry-point-without-own-code/_expected/amd/generated-m1.js b/test/chunking-form/samples/entry-point-without-own-code/_expected/amd/generated-chunk.js similarity index 100% rename from test/chunking-form/samples/entry-point-without-own-code/_expected/amd/generated-m1.js rename to test/chunking-form/samples/entry-point-without-own-code/_expected/amd/generated-chunk.js diff --git a/test/chunking-form/samples/entry-point-without-own-code/_expected/amd/m1.js b/test/chunking-form/samples/entry-point-without-own-code/_expected/amd/m1.js index b95c6ca797c..2e73f2c4072 100644 --- a/test/chunking-form/samples/entry-point-without-own-code/_expected/amd/m1.js +++ b/test/chunking-form/samples/entry-point-without-own-code/_expected/amd/m1.js @@ -1,4 +1,4 @@ -define(['exports', './m2', './generated-m1'], function (exports, m2, m1) { 'use strict'; +define(['exports', './m2', './generated-chunk'], function (exports, m2, m1) { 'use strict'; diff --git a/test/chunking-form/samples/entry-point-without-own-code/_expected/amd/main.js b/test/chunking-form/samples/entry-point-without-own-code/_expected/amd/main.js index fd4897a745b..c56ed5a438c 100644 --- a/test/chunking-form/samples/entry-point-without-own-code/_expected/amd/main.js +++ b/test/chunking-form/samples/entry-point-without-own-code/_expected/amd/main.js @@ -1,4 +1,4 @@ -define(['./m2', './generated-m1'], function (m2, m1) { 'use strict'; +define(['./m2', './generated-chunk'], function (m2, m1) { 'use strict'; console.log(m1.ms); diff --git a/test/chunking-form/samples/entry-point-without-own-code/_expected/cjs/generated-m1.js b/test/chunking-form/samples/entry-point-without-own-code/_expected/cjs/generated-chunk.js similarity index 100% rename from test/chunking-form/samples/entry-point-without-own-code/_expected/cjs/generated-m1.js rename to test/chunking-form/samples/entry-point-without-own-code/_expected/cjs/generated-chunk.js diff --git a/test/chunking-form/samples/entry-point-without-own-code/_expected/cjs/m1.js b/test/chunking-form/samples/entry-point-without-own-code/_expected/cjs/m1.js index 9b97781f444..69e845c1c87 100644 --- a/test/chunking-form/samples/entry-point-without-own-code/_expected/cjs/m1.js +++ b/test/chunking-form/samples/entry-point-without-own-code/_expected/cjs/m1.js @@ -3,7 +3,7 @@ Object.defineProperty(exports, '__esModule', { value: true }); var m2 = require('./m2.js'); -require('./generated-m1.js'); +require('./generated-chunk.js'); diff --git a/test/chunking-form/samples/entry-point-without-own-code/_expected/cjs/main.js b/test/chunking-form/samples/entry-point-without-own-code/_expected/cjs/main.js index a7ba4a72c65..cab9d88907e 100644 --- a/test/chunking-form/samples/entry-point-without-own-code/_expected/cjs/main.js +++ b/test/chunking-form/samples/entry-point-without-own-code/_expected/cjs/main.js @@ -1,6 +1,6 @@ 'use strict'; require('./m2.js'); -var m1 = require('./generated-m1.js'); +var m1 = require('./generated-chunk.js'); console.log(m1.ms); diff --git a/test/chunking-form/samples/entry-point-without-own-code/_expected/es/generated-m1.js b/test/chunking-form/samples/entry-point-without-own-code/_expected/es/generated-chunk.js similarity index 100% rename from test/chunking-form/samples/entry-point-without-own-code/_expected/es/generated-m1.js rename to test/chunking-form/samples/entry-point-without-own-code/_expected/es/generated-chunk.js diff --git a/test/chunking-form/samples/entry-point-without-own-code/_expected/es/m1.js b/test/chunking-form/samples/entry-point-without-own-code/_expected/es/m1.js index a0461824120..60888641454 100644 --- a/test/chunking-form/samples/entry-point-without-own-code/_expected/es/m1.js +++ b/test/chunking-form/samples/entry-point-without-own-code/_expected/es/m1.js @@ -1,2 +1,2 @@ export { default as m2 } from './m2.js'; -import './generated-m1.js'; +import './generated-chunk.js'; diff --git a/test/chunking-form/samples/entry-point-without-own-code/_expected/es/main.js b/test/chunking-form/samples/entry-point-without-own-code/_expected/es/main.js index 107671de693..b68936e6d94 100644 --- a/test/chunking-form/samples/entry-point-without-own-code/_expected/es/main.js +++ b/test/chunking-form/samples/entry-point-without-own-code/_expected/es/main.js @@ -1,4 +1,4 @@ import './m2.js'; -import { a as ms } from './generated-m1.js'; +import { a as ms } from './generated-chunk.js'; console.log(ms); diff --git a/test/chunking-form/samples/entry-point-without-own-code/_expected/system/generated-m1.js b/test/chunking-form/samples/entry-point-without-own-code/_expected/system/generated-chunk.js similarity index 100% rename from test/chunking-form/samples/entry-point-without-own-code/_expected/system/generated-m1.js rename to test/chunking-form/samples/entry-point-without-own-code/_expected/system/generated-chunk.js diff --git a/test/chunking-form/samples/entry-point-without-own-code/_expected/system/m1.js b/test/chunking-form/samples/entry-point-without-own-code/_expected/system/m1.js index 936faa85f6b..f2f6739d8c4 100644 --- a/test/chunking-form/samples/entry-point-without-own-code/_expected/system/m1.js +++ b/test/chunking-form/samples/entry-point-without-own-code/_expected/system/m1.js @@ -1,4 +1,4 @@ -System.register(['./m2.js', './generated-m1.js'], function (exports, module) { +System.register(['./m2.js', './generated-chunk.js'], function (exports, module) { 'use strict'; return { setters: [function (module) { diff --git a/test/chunking-form/samples/entry-point-without-own-code/_expected/system/main.js b/test/chunking-form/samples/entry-point-without-own-code/_expected/system/main.js index d3e75023a03..ea34b06467b 100644 --- a/test/chunking-form/samples/entry-point-without-own-code/_expected/system/main.js +++ b/test/chunking-form/samples/entry-point-without-own-code/_expected/system/main.js @@ -1,4 +1,4 @@ -System.register(['./m2.js', './generated-m1.js'], function (exports, module) { +System.register(['./m2.js', './generated-chunk.js'], function (exports, module) { 'use strict'; var ms; return { diff --git a/test/chunking-form/samples/entrypoint-facade/_expected/amd/generated-main2.js b/test/chunking-form/samples/entrypoint-facade/_expected/amd/generated-chunk.js similarity index 100% rename from test/chunking-form/samples/entrypoint-facade/_expected/amd/generated-main2.js rename to test/chunking-form/samples/entrypoint-facade/_expected/amd/generated-chunk.js diff --git a/test/chunking-form/samples/entrypoint-facade/_expected/amd/main1.js b/test/chunking-form/samples/entrypoint-facade/_expected/amd/main1.js index b319e7ebff9..4b813479b19 100644 --- a/test/chunking-form/samples/entrypoint-facade/_expected/amd/main1.js +++ b/test/chunking-form/samples/entrypoint-facade/_expected/amd/main1.js @@ -1,4 +1,4 @@ -define(['./generated-main2'], function (main2) { 'use strict'; +define(['./generated-chunk'], function (main2) { 'use strict'; main2.log(main2.dep); diff --git a/test/chunking-form/samples/entrypoint-facade/_expected/amd/main2.js b/test/chunking-form/samples/entrypoint-facade/_expected/amd/main2.js index e4a115ee883..dca57e6bdbb 100644 --- a/test/chunking-form/samples/entrypoint-facade/_expected/amd/main2.js +++ b/test/chunking-form/samples/entrypoint-facade/_expected/amd/main2.js @@ -1,4 +1,4 @@ -define(['./generated-main2'], function (main2) { 'use strict'; +define(['./generated-chunk'], function (main2) { 'use strict'; diff --git a/test/chunking-form/samples/entrypoint-facade/_expected/cjs/generated-main2.js b/test/chunking-form/samples/entrypoint-facade/_expected/cjs/generated-chunk.js similarity index 100% rename from test/chunking-form/samples/entrypoint-facade/_expected/cjs/generated-main2.js rename to test/chunking-form/samples/entrypoint-facade/_expected/cjs/generated-chunk.js diff --git a/test/chunking-form/samples/entrypoint-facade/_expected/cjs/main1.js b/test/chunking-form/samples/entrypoint-facade/_expected/cjs/main1.js index 6c0864d0770..0f9129ef76b 100644 --- a/test/chunking-form/samples/entrypoint-facade/_expected/cjs/main1.js +++ b/test/chunking-form/samples/entrypoint-facade/_expected/cjs/main1.js @@ -1,5 +1,5 @@ 'use strict'; -var main2 = require('./generated-main2.js'); +var main2 = require('./generated-chunk.js'); main2.log(main2.dep); diff --git a/test/chunking-form/samples/entrypoint-facade/_expected/cjs/main2.js b/test/chunking-form/samples/entrypoint-facade/_expected/cjs/main2.js index 1cca608acf8..30320fc1844 100644 --- a/test/chunking-form/samples/entrypoint-facade/_expected/cjs/main2.js +++ b/test/chunking-form/samples/entrypoint-facade/_expected/cjs/main2.js @@ -1,6 +1,6 @@ 'use strict'; -var main2 = require('./generated-main2.js'); +var main2 = require('./generated-chunk.js'); diff --git a/test/chunking-form/samples/entrypoint-facade/_expected/es/generated-main2.js b/test/chunking-form/samples/entrypoint-facade/_expected/es/generated-chunk.js similarity index 100% rename from test/chunking-form/samples/entrypoint-facade/_expected/es/generated-main2.js rename to test/chunking-form/samples/entrypoint-facade/_expected/es/generated-chunk.js diff --git a/test/chunking-form/samples/entrypoint-facade/_expected/es/main1.js b/test/chunking-form/samples/entrypoint-facade/_expected/es/main1.js index 3eed7498c84..c647800f0c5 100644 --- a/test/chunking-form/samples/entrypoint-facade/_expected/es/main1.js +++ b/test/chunking-form/samples/entrypoint-facade/_expected/es/main1.js @@ -1,3 +1,3 @@ -import { a as log, b as dep } from './generated-main2.js'; +import { a as log, b as dep } from './generated-chunk.js'; log(dep); diff --git a/test/chunking-form/samples/entrypoint-facade/_expected/es/main2.js b/test/chunking-form/samples/entrypoint-facade/_expected/es/main2.js index 11f1b8ce08c..a16a620d03f 100644 --- a/test/chunking-form/samples/entrypoint-facade/_expected/es/main2.js +++ b/test/chunking-form/samples/entrypoint-facade/_expected/es/main2.js @@ -1 +1 @@ -export { a as default } from './generated-main2.js'; +export { a as default } from './generated-chunk.js'; diff --git a/test/chunking-form/samples/entrypoint-facade/_expected/system/generated-main2.js b/test/chunking-form/samples/entrypoint-facade/_expected/system/generated-chunk.js similarity index 100% rename from test/chunking-form/samples/entrypoint-facade/_expected/system/generated-main2.js rename to test/chunking-form/samples/entrypoint-facade/_expected/system/generated-chunk.js diff --git a/test/chunking-form/samples/entrypoint-facade/_expected/system/main1.js b/test/chunking-form/samples/entrypoint-facade/_expected/system/main1.js index ad2a738b972..ab11cc92c57 100644 --- a/test/chunking-form/samples/entrypoint-facade/_expected/system/main1.js +++ b/test/chunking-form/samples/entrypoint-facade/_expected/system/main1.js @@ -1,4 +1,4 @@ -System.register(['./generated-main2.js'], function (exports, module) { +System.register(['./generated-chunk.js'], function (exports, module) { 'use strict'; var log, dep; return { diff --git a/test/chunking-form/samples/entrypoint-facade/_expected/system/main2.js b/test/chunking-form/samples/entrypoint-facade/_expected/system/main2.js index 99ccd7b3796..2ec2077c897 100644 --- a/test/chunking-form/samples/entrypoint-facade/_expected/system/main2.js +++ b/test/chunking-form/samples/entrypoint-facade/_expected/system/main2.js @@ -1,4 +1,4 @@ -System.register(['./generated-main2.js'], function (exports, module) { +System.register(['./generated-chunk.js'], function (exports, module) { 'use strict'; return { setters: [function (module) { diff --git a/test/chunking-form/samples/filenames-patterns/_expected/amd/chunk-main2-6bb39c19-amd.js b/test/chunking-form/samples/filenames-patterns/_expected/amd/chunk-chunk-6bb39c19-amd.js similarity index 100% rename from test/chunking-form/samples/filenames-patterns/_expected/amd/chunk-main2-6bb39c19-amd.js rename to test/chunking-form/samples/filenames-patterns/_expected/amd/chunk-chunk-6bb39c19-amd.js diff --git a/test/chunking-form/samples/filenames-patterns/_expected/amd/entry-main1-e7c7d1b5-amd.js b/test/chunking-form/samples/filenames-patterns/_expected/amd/entry-main1-e7c7d1b5-amd.js index 791e2547a0f..16b886110fd 100644 --- a/test/chunking-form/samples/filenames-patterns/_expected/amd/entry-main1-e7c7d1b5-amd.js +++ b/test/chunking-form/samples/filenames-patterns/_expected/amd/entry-main1-e7c7d1b5-amd.js @@ -1,4 +1,4 @@ -define(['./chunk-main2-6bb39c19-amd'], function (main2) { 'use strict'; +define(['./chunk-chunk-6bb39c19-amd'], function (main2) { 'use strict'; main2.log(main2.dep); diff --git a/test/chunking-form/samples/filenames-patterns/_expected/amd/entry-main2-f9a2200a-amd.js b/test/chunking-form/samples/filenames-patterns/_expected/amd/entry-main2-f9a2200a-amd.js index 0e357dbc084..eb0faba5282 100644 --- a/test/chunking-form/samples/filenames-patterns/_expected/amd/entry-main2-f9a2200a-amd.js +++ b/test/chunking-form/samples/filenames-patterns/_expected/amd/entry-main2-f9a2200a-amd.js @@ -1,4 +1,4 @@ -define(['./chunk-main2-6bb39c19-amd'], function (main2) { 'use strict'; +define(['./chunk-chunk-6bb39c19-amd'], function (main2) { 'use strict'; diff --git a/test/chunking-form/samples/filenames-patterns/_expected/cjs/chunk-main2-33c8b40d-cjs.js b/test/chunking-form/samples/filenames-patterns/_expected/cjs/chunk-chunk-33c8b40d-cjs.js similarity index 100% rename from test/chunking-form/samples/filenames-patterns/_expected/cjs/chunk-main2-33c8b40d-cjs.js rename to test/chunking-form/samples/filenames-patterns/_expected/cjs/chunk-chunk-33c8b40d-cjs.js diff --git a/test/chunking-form/samples/filenames-patterns/_expected/cjs/entry-main1-639831da-cjs.js b/test/chunking-form/samples/filenames-patterns/_expected/cjs/entry-main1-639831da-cjs.js index df68f3f3591..c6c3e337b7a 100644 --- a/test/chunking-form/samples/filenames-patterns/_expected/cjs/entry-main1-639831da-cjs.js +++ b/test/chunking-form/samples/filenames-patterns/_expected/cjs/entry-main1-639831da-cjs.js @@ -1,5 +1,5 @@ 'use strict'; -var main2 = require('./chunk-main2-33c8b40d-cjs.js'); +var main2 = require('./chunk-chunk-33c8b40d-cjs.js'); main2.log(main2.dep); diff --git a/test/chunking-form/samples/filenames-patterns/_expected/cjs/entry-main2-4508233a-cjs.js b/test/chunking-form/samples/filenames-patterns/_expected/cjs/entry-main2-4508233a-cjs.js index 60dc76f979f..b4586862b9a 100644 --- a/test/chunking-form/samples/filenames-patterns/_expected/cjs/entry-main2-4508233a-cjs.js +++ b/test/chunking-form/samples/filenames-patterns/_expected/cjs/entry-main2-4508233a-cjs.js @@ -1,6 +1,6 @@ 'use strict'; -var main2 = require('./chunk-main2-33c8b40d-cjs.js'); +var main2 = require('./chunk-chunk-33c8b40d-cjs.js'); diff --git a/test/chunking-form/samples/filenames-patterns/_expected/es/chunk-main2-88db1d1d-esm.js b/test/chunking-form/samples/filenames-patterns/_expected/es/chunk-chunk-88db1d1d-esm.js similarity index 100% rename from test/chunking-form/samples/filenames-patterns/_expected/es/chunk-main2-88db1d1d-esm.js rename to test/chunking-form/samples/filenames-patterns/_expected/es/chunk-chunk-88db1d1d-esm.js diff --git a/test/chunking-form/samples/filenames-patterns/_expected/es/entry-main1-0152a638-esm.js b/test/chunking-form/samples/filenames-patterns/_expected/es/entry-main1-0152a638-esm.js index 9acd03d4111..e8e34075cbd 100644 --- a/test/chunking-form/samples/filenames-patterns/_expected/es/entry-main1-0152a638-esm.js +++ b/test/chunking-form/samples/filenames-patterns/_expected/es/entry-main1-0152a638-esm.js @@ -1,3 +1,3 @@ -import { a as log, b as dep } from './chunk-main2-88db1d1d-esm.js'; +import { a as log, b as dep } from './chunk-chunk-88db1d1d-esm.js'; log(dep); diff --git a/test/chunking-form/samples/filenames-patterns/_expected/es/entry-main2-5a78ab60-esm.js b/test/chunking-form/samples/filenames-patterns/_expected/es/entry-main2-5a78ab60-esm.js index 9796d7f6e44..a3bc712a1a2 100644 --- a/test/chunking-form/samples/filenames-patterns/_expected/es/entry-main2-5a78ab60-esm.js +++ b/test/chunking-form/samples/filenames-patterns/_expected/es/entry-main2-5a78ab60-esm.js @@ -1 +1 @@ -export { a as default } from './chunk-main2-88db1d1d-esm.js'; +export { a as default } from './chunk-chunk-88db1d1d-esm.js'; diff --git a/test/chunking-form/samples/filenames-patterns/_expected/system/chunk-main2-26e1391e-system.js b/test/chunking-form/samples/filenames-patterns/_expected/system/chunk-chunk-26e1391e-system.js similarity index 100% rename from test/chunking-form/samples/filenames-patterns/_expected/system/chunk-main2-26e1391e-system.js rename to test/chunking-form/samples/filenames-patterns/_expected/system/chunk-chunk-26e1391e-system.js diff --git a/test/chunking-form/samples/filenames-patterns/_expected/system/entry-main1-2c874064-system.js b/test/chunking-form/samples/filenames-patterns/_expected/system/entry-main1-2c874064-system.js index 69a08d534b2..a1f541a5733 100644 --- a/test/chunking-form/samples/filenames-patterns/_expected/system/entry-main1-2c874064-system.js +++ b/test/chunking-form/samples/filenames-patterns/_expected/system/entry-main1-2c874064-system.js @@ -1,4 +1,4 @@ -System.register(['./chunk-main2-26e1391e-system.js'], function (exports, module) { +System.register(['./chunk-chunk-26e1391e-system.js'], function (exports, module) { 'use strict'; var log, dep; return { diff --git a/test/chunking-form/samples/filenames-patterns/_expected/system/entry-main2-dd802b9d-system.js b/test/chunking-form/samples/filenames-patterns/_expected/system/entry-main2-dd802b9d-system.js index c805a82f422..29c79bc8437 100644 --- a/test/chunking-form/samples/filenames-patterns/_expected/system/entry-main2-dd802b9d-system.js +++ b/test/chunking-form/samples/filenames-patterns/_expected/system/entry-main2-dd802b9d-system.js @@ -1,4 +1,4 @@ -System.register(['./chunk-main2-26e1391e-system.js'], function (exports, module) { +System.register(['./chunk-chunk-26e1391e-system.js'], function (exports, module) { 'use strict'; return { setters: [function (module) { diff --git a/test/chunking-form/samples/manual-chunk-avoid-facade/_config.js b/test/chunking-form/samples/manual-chunk-avoid-facade/_config.js new file mode 100644 index 00000000000..3872987a3f1 --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-avoid-facade/_config.js @@ -0,0 +1,9 @@ +module.exports = { + description: 'avoid facades if possible when using manual chunks', + options: { + input: ['main1', 'main2'], + manualChunks: { + manual: ['main2'] + } + } +}; diff --git a/test/chunking-form/samples/manual-chunk-avoid-facade/_expected/amd/main1.js b/test/chunking-form/samples/manual-chunk-avoid-facade/_expected/amd/main1.js new file mode 100644 index 00000000000..6b16473382c --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-avoid-facade/_expected/amd/main1.js @@ -0,0 +1,5 @@ +define(['./manual'], function (manual) { 'use strict'; + + console.log('main', manual.reexported); + +}); diff --git a/test/chunking-form/samples/manual-chunk-avoid-facade/_expected/amd/manual.js b/test/chunking-form/samples/manual-chunk-avoid-facade/_expected/amd/manual.js new file mode 100644 index 00000000000..674f42a401c --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-avoid-facade/_expected/amd/manual.js @@ -0,0 +1,11 @@ +define(['exports'], function (exports) { 'use strict'; + + const value = 42; + + console.log('main2', value); + + exports.reexported = value; + + Object.defineProperty(exports, '__esModule', { value: true }); + +}); diff --git a/test/chunking-form/samples/manual-chunk-avoid-facade/_expected/cjs/main1.js b/test/chunking-form/samples/manual-chunk-avoid-facade/_expected/cjs/main1.js new file mode 100644 index 00000000000..05d27bd0aac --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-avoid-facade/_expected/cjs/main1.js @@ -0,0 +1,5 @@ +'use strict'; + +var manual = require('./manual.js'); + +console.log('main', manual.reexported); diff --git a/test/chunking-form/samples/manual-chunk-avoid-facade/_expected/cjs/manual.js b/test/chunking-form/samples/manual-chunk-avoid-facade/_expected/cjs/manual.js new file mode 100644 index 00000000000..f7d33362bcc --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-avoid-facade/_expected/cjs/manual.js @@ -0,0 +1,9 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +const value = 42; + +console.log('main2', value); + +exports.reexported = value; diff --git a/test/chunking-form/samples/manual-chunk-avoid-facade/_expected/es/main1.js b/test/chunking-form/samples/manual-chunk-avoid-facade/_expected/es/main1.js new file mode 100644 index 00000000000..4023c0017b1 --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-avoid-facade/_expected/es/main1.js @@ -0,0 +1,3 @@ +import { reexported as value } from './manual.js'; + +console.log('main', value); diff --git a/test/chunking-form/samples/manual-chunk-avoid-facade/_expected/es/manual.js b/test/chunking-form/samples/manual-chunk-avoid-facade/_expected/es/manual.js new file mode 100644 index 00000000000..897452bd66e --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-avoid-facade/_expected/es/manual.js @@ -0,0 +1,5 @@ +const value = 42; + +console.log('main2', value); + +export { value as reexported }; diff --git a/test/chunking-form/samples/manual-chunk-avoid-facade/_expected/system/main1.js b/test/chunking-form/samples/manual-chunk-avoid-facade/_expected/system/main1.js new file mode 100644 index 00000000000..64e1dc330b9 --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-avoid-facade/_expected/system/main1.js @@ -0,0 +1,14 @@ +System.register(['./manual.js'], function (exports, module) { + 'use strict'; + var value; + return { + setters: [function (module) { + value = module.reexported; + }], + execute: function () { + + console.log('main', value); + + } + }; +}); diff --git a/test/chunking-form/samples/manual-chunk-avoid-facade/_expected/system/manual.js b/test/chunking-form/samples/manual-chunk-avoid-facade/_expected/system/manual.js new file mode 100644 index 00000000000..80b775efdee --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-avoid-facade/_expected/system/manual.js @@ -0,0 +1,12 @@ +System.register([], function (exports, module) { + 'use strict'; + return { + execute: function () { + + const value = exports('reexported', 42); + + console.log('main2', value); + + } + }; +}); diff --git a/test/chunking-form/samples/manual-chunk-avoid-facade/dep.js b/test/chunking-form/samples/manual-chunk-avoid-facade/dep.js new file mode 100644 index 00000000000..46d3ca8c61f --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-avoid-facade/dep.js @@ -0,0 +1 @@ +export const value = 42; diff --git a/test/chunking-form/samples/manual-chunk-avoid-facade/main1.js b/test/chunking-form/samples/manual-chunk-avoid-facade/main1.js new file mode 100644 index 00000000000..5da97663c3a --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-avoid-facade/main1.js @@ -0,0 +1,3 @@ +import { value } from './dep'; + +console.log('main', value); diff --git a/test/chunking-form/samples/manual-chunk-avoid-facade/main2.js b/test/chunking-form/samples/manual-chunk-avoid-facade/main2.js new file mode 100644 index 00000000000..868d23fd0a7 --- /dev/null +++ b/test/chunking-form/samples/manual-chunk-avoid-facade/main2.js @@ -0,0 +1,5 @@ +import {value} from './dep.js'; + +console.log('main2', value); + +export { value as reexported }; diff --git a/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/generated-chunk.js b/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/generated-dynamic2.js similarity index 100% rename from test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/generated-chunk.js rename to test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/generated-dynamic2.js diff --git a/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/generated-chunk2.js b/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/generated-dynamic3.js similarity index 100% rename from test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/generated-chunk2.js rename to test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/generated-dynamic3.js diff --git a/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/main.js b/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/main.js index fae2c778a45..9558e0b7837 100644 --- a/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/main.js +++ b/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/amd/main.js @@ -1,6 +1,6 @@ define(['require', './generated-dynamic'], function (require, dynamic) { 'use strict'; - Promise.all([new Promise(function (resolve, reject) { require(['./generated-dynamic'], resolve, reject) }), new Promise(function (resolve, reject) { require(['./generated-chunk'], resolve, reject) }), new Promise(function (resolve, reject) { require(['./generated-chunk2'], resolve, reject) })]).then( + Promise.all([new Promise(function (resolve, reject) { require(['./generated-dynamic'], resolve, reject) }), new Promise(function (resolve, reject) { require(['./generated-dynamic2'], resolve, reject) }), new Promise(function (resolve, reject) { require(['./generated-dynamic3'], resolve, reject) })]).then( results => console.log(results, dynamic.DEP) ); diff --git a/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/cjs/generated-chunk.js b/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/cjs/generated-dynamic2.js similarity index 100% rename from test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/cjs/generated-chunk.js rename to test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/cjs/generated-dynamic2.js diff --git a/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/cjs/generated-chunk2.js b/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/cjs/generated-dynamic3.js similarity index 100% rename from test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/cjs/generated-chunk2.js rename to test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/cjs/generated-dynamic3.js diff --git a/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/cjs/main.js b/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/cjs/main.js index 88d78ae23ed..529ca20e209 100644 --- a/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/cjs/main.js +++ b/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/cjs/main.js @@ -2,6 +2,6 @@ var dynamic = require('./generated-dynamic.js'); -Promise.all([Promise.resolve(require('./generated-dynamic.js')), Promise.resolve(require('./generated-chunk.js')), Promise.resolve(require('./generated-chunk2.js'))]).then( +Promise.all([Promise.resolve(require('./generated-dynamic.js')), Promise.resolve(require('./generated-dynamic2.js')), Promise.resolve(require('./generated-dynamic3.js'))]).then( results => console.log(results, dynamic.DEP) ); diff --git a/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/es/generated-chunk.js b/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/es/generated-dynamic2.js similarity index 100% rename from test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/es/generated-chunk.js rename to test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/es/generated-dynamic2.js diff --git a/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/es/generated-chunk2.js b/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/es/generated-dynamic3.js similarity index 100% rename from test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/es/generated-chunk2.js rename to test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/es/generated-dynamic3.js diff --git a/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/es/main.js b/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/es/main.js index f73645a1c0c..4ed1bade3c1 100644 --- a/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/es/main.js +++ b/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/es/main.js @@ -1,5 +1,5 @@ import { DEP } from './generated-dynamic.js'; -Promise.all([import('./generated-dynamic.js'), import('./generated-chunk.js'), import('./generated-chunk2.js')]).then( +Promise.all([import('./generated-dynamic.js'), import('./generated-dynamic2.js'), import('./generated-dynamic3.js')]).then( results => console.log(results, DEP) ); diff --git a/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/system/generated-chunk.js b/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/system/generated-dynamic2.js similarity index 100% rename from test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/system/generated-chunk.js rename to test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/system/generated-dynamic2.js diff --git a/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/system/generated-chunk2.js b/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/system/generated-dynamic3.js similarity index 100% rename from test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/system/generated-chunk2.js rename to test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/system/generated-dynamic3.js diff --git a/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/system/main.js b/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/system/main.js index 38a54ddc18f..3b527719e90 100644 --- a/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/system/main.js +++ b/test/chunking-form/samples/manual-chunks-dynamic-facades/_expected/system/main.js @@ -7,7 +7,7 @@ System.register(['./generated-dynamic.js'], function (exports, module) { }], execute: function () { - Promise.all([module.import('./generated-dynamic.js'), module.import('./generated-chunk.js'), module.import('./generated-chunk2.js')]).then( + Promise.all([module.import('./generated-dynamic.js'), module.import('./generated-dynamic2.js'), module.import('./generated-dynamic3.js')]).then( results => console.log(results, DEP) ); diff --git a/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/amd/generated-chunk.js b/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/amd/generated-dynamic1.js similarity index 100% rename from test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/amd/generated-chunk.js rename to test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/amd/generated-dynamic1.js diff --git a/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/amd/main.js b/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/amd/main.js index 6113e054cf8..ca2fb108442 100644 --- a/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/amd/main.js +++ b/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/amd/main.js @@ -1,6 +1,6 @@ define(['require'], function (require) { 'use strict'; - new Promise(function (resolve, reject) { require(['./generated-chunk'], resolve, reject) }).then(result => console.log(result)); + new Promise(function (resolve, reject) { require(['./generated-dynamic1'], resolve, reject) }).then(result => console.log(result)); new Promise(function (resolve, reject) { require(['./generated-dynamic'], resolve, reject) }).then(result => console.log(result)); }); diff --git a/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/cjs/generated-chunk.js b/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/cjs/generated-dynamic1.js similarity index 100% rename from test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/cjs/generated-chunk.js rename to test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/cjs/generated-dynamic1.js diff --git a/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/cjs/main.js b/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/cjs/main.js index 2cf5a2e9b8d..ad1107c73a0 100644 --- a/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/cjs/main.js +++ b/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/cjs/main.js @@ -1,4 +1,4 @@ 'use strict'; -Promise.resolve(require('./generated-chunk.js')).then(result => console.log(result)); +Promise.resolve(require('./generated-dynamic1.js')).then(result => console.log(result)); Promise.resolve(require('./generated-dynamic.js')).then(result => console.log(result)); diff --git a/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/es/generated-chunk.js b/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/es/generated-dynamic1.js similarity index 100% rename from test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/es/generated-chunk.js rename to test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/es/generated-dynamic1.js diff --git a/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/es/main.js b/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/es/main.js index c11f64d0ba9..56b8f8a4d28 100644 --- a/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/es/main.js +++ b/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/es/main.js @@ -1,2 +1,2 @@ -import('./generated-chunk.js').then(result => console.log(result)); +import('./generated-dynamic1.js').then(result => console.log(result)); import('./generated-dynamic.js').then(result => console.log(result)); diff --git a/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/system/generated-chunk.js b/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/system/generated-dynamic1.js similarity index 100% rename from test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/system/generated-chunk.js rename to test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/system/generated-dynamic1.js diff --git a/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/system/main.js b/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/system/main.js index 139d8a26580..f2c39c717c5 100644 --- a/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/system/main.js +++ b/test/chunking-form/samples/manual-chunks-dynamic-name-conflict/_expected/system/main.js @@ -3,7 +3,7 @@ System.register([], function (exports, module) { return { execute: function () { - module.import('./generated-chunk.js').then(result => console.log(result)); + module.import('./generated-dynamic1.js').then(result => console.log(result)); module.import('./generated-dynamic.js').then(result => console.log(result)); } diff --git a/test/chunking-form/samples/namespace-object-import/_expected/amd/generated-main2.js b/test/chunking-form/samples/namespace-object-import/_expected/amd/generated-chunk.js similarity index 100% rename from test/chunking-form/samples/namespace-object-import/_expected/amd/generated-main2.js rename to test/chunking-form/samples/namespace-object-import/_expected/amd/generated-chunk.js diff --git a/test/chunking-form/samples/namespace-object-import/_expected/amd/main1.js b/test/chunking-form/samples/namespace-object-import/_expected/amd/main1.js index 78484e848f0..585aa959563 100644 --- a/test/chunking-form/samples/namespace-object-import/_expected/amd/main1.js +++ b/test/chunking-form/samples/namespace-object-import/_expected/amd/main1.js @@ -1,4 +1,4 @@ -define(['./generated-main2'], function (main2) { 'use strict'; +define(['./generated-chunk'], function (main2) { 'use strict'; console.log(main2.a); diff --git a/test/chunking-form/samples/namespace-object-import/_expected/amd/main2.js b/test/chunking-form/samples/namespace-object-import/_expected/amd/main2.js index 58cbd115137..ab807b27492 100644 --- a/test/chunking-form/samples/namespace-object-import/_expected/amd/main2.js +++ b/test/chunking-form/samples/namespace-object-import/_expected/amd/main2.js @@ -1,4 +1,4 @@ -define(['exports', './generated-main2'], function (exports, main2) { 'use strict'; +define(['exports', './generated-chunk'], function (exports, main2) { 'use strict'; diff --git a/test/chunking-form/samples/namespace-object-import/_expected/cjs/generated-main2.js b/test/chunking-form/samples/namespace-object-import/_expected/cjs/generated-chunk.js similarity index 100% rename from test/chunking-form/samples/namespace-object-import/_expected/cjs/generated-main2.js rename to test/chunking-form/samples/namespace-object-import/_expected/cjs/generated-chunk.js diff --git a/test/chunking-form/samples/namespace-object-import/_expected/cjs/main1.js b/test/chunking-form/samples/namespace-object-import/_expected/cjs/main1.js index 76c02e55904..09ee475014d 100644 --- a/test/chunking-form/samples/namespace-object-import/_expected/cjs/main1.js +++ b/test/chunking-form/samples/namespace-object-import/_expected/cjs/main1.js @@ -1,6 +1,6 @@ 'use strict'; -var main2 = require('./generated-main2.js'); +var main2 = require('./generated-chunk.js'); console.log(main2.a); diff --git a/test/chunking-form/samples/namespace-object-import/_expected/cjs/main2.js b/test/chunking-form/samples/namespace-object-import/_expected/cjs/main2.js index 688bfd2c811..ad7ea0780cc 100644 --- a/test/chunking-form/samples/namespace-object-import/_expected/cjs/main2.js +++ b/test/chunking-form/samples/namespace-object-import/_expected/cjs/main2.js @@ -2,7 +2,7 @@ Object.defineProperty(exports, '__esModule', { value: true }); -var main2 = require('./generated-main2.js'); +var main2 = require('./generated-chunk.js'); diff --git a/test/chunking-form/samples/namespace-object-import/_expected/es/generated-main2.js b/test/chunking-form/samples/namespace-object-import/_expected/es/generated-chunk.js similarity index 100% rename from test/chunking-form/samples/namespace-object-import/_expected/es/generated-main2.js rename to test/chunking-form/samples/namespace-object-import/_expected/es/generated-chunk.js diff --git a/test/chunking-form/samples/namespace-object-import/_expected/es/main1.js b/test/chunking-form/samples/namespace-object-import/_expected/es/main1.js index 2fc8d5876d7..50d073052f2 100644 --- a/test/chunking-form/samples/namespace-object-import/_expected/es/main1.js +++ b/test/chunking-form/samples/namespace-object-import/_expected/es/main1.js @@ -1,4 +1,4 @@ -import { a, b as main2 } from './generated-main2.js'; +import { a, b as main2 } from './generated-chunk.js'; console.log(a); diff --git a/test/chunking-form/samples/namespace-object-import/_expected/es/main2.js b/test/chunking-form/samples/namespace-object-import/_expected/es/main2.js index 8c213203342..086197544e8 100644 --- a/test/chunking-form/samples/namespace-object-import/_expected/es/main2.js +++ b/test/chunking-form/samples/namespace-object-import/_expected/es/main2.js @@ -1 +1 @@ -export { a, c as b } from './generated-main2.js'; +export { a, c as b } from './generated-chunk.js'; diff --git a/test/chunking-form/samples/namespace-object-import/_expected/system/generated-main2.js b/test/chunking-form/samples/namespace-object-import/_expected/system/generated-chunk.js similarity index 100% rename from test/chunking-form/samples/namespace-object-import/_expected/system/generated-main2.js rename to test/chunking-form/samples/namespace-object-import/_expected/system/generated-chunk.js diff --git a/test/chunking-form/samples/namespace-object-import/_expected/system/main1.js b/test/chunking-form/samples/namespace-object-import/_expected/system/main1.js index d39745288cb..f067ddbe178 100644 --- a/test/chunking-form/samples/namespace-object-import/_expected/system/main1.js +++ b/test/chunking-form/samples/namespace-object-import/_expected/system/main1.js @@ -1,4 +1,4 @@ -System.register(['./generated-main2.js'], function (exports, module) { +System.register(['./generated-chunk.js'], function (exports, module) { 'use strict'; var a, main2; return { diff --git a/test/chunking-form/samples/namespace-object-import/_expected/system/main2.js b/test/chunking-form/samples/namespace-object-import/_expected/system/main2.js index f4265e986bc..fb13e62e855 100644 --- a/test/chunking-form/samples/namespace-object-import/_expected/system/main2.js +++ b/test/chunking-form/samples/namespace-object-import/_expected/system/main2.js @@ -1,4 +1,4 @@ -System.register(['./generated-main2.js'], function (exports, module) { +System.register(['./generated-chunk.js'], function (exports, module) { 'use strict'; return { setters: [function (module) { diff --git a/test/chunking-form/samples/namespace-reexports/_expected/amd/generated-index.js b/test/chunking-form/samples/namespace-reexports/_expected/amd/generated-chunk.js similarity index 100% rename from test/chunking-form/samples/namespace-reexports/_expected/amd/generated-index.js rename to test/chunking-form/samples/namespace-reexports/_expected/amd/generated-chunk.js diff --git a/test/chunking-form/samples/namespace-reexports/_expected/amd/index.js b/test/chunking-form/samples/namespace-reexports/_expected/amd/index.js index 1c0eff2a0ca..403b5f70f60 100644 --- a/test/chunking-form/samples/namespace-reexports/_expected/amd/index.js +++ b/test/chunking-form/samples/namespace-reexports/_expected/amd/index.js @@ -1,4 +1,4 @@ -define(['exports', './hsl2hsv', './generated-index'], function (exports, hsl2hsv$1, index) { 'use strict'; +define(['exports', './hsl2hsv', './generated-chunk'], function (exports, hsl2hsv$1, index) { 'use strict'; diff --git a/test/chunking-form/samples/namespace-reexports/_expected/amd/main.js b/test/chunking-form/samples/namespace-reexports/_expected/amd/main.js index ab833f3837e..95dbd44f35d 100644 --- a/test/chunking-form/samples/namespace-reexports/_expected/amd/main.js +++ b/test/chunking-form/samples/namespace-reexports/_expected/amd/main.js @@ -1,4 +1,4 @@ -define(['exports', './hsl2hsv', './generated-index'], function (exports, hsl2hsv$1, index) { 'use strict'; +define(['exports', './hsl2hsv', './generated-chunk'], function (exports, hsl2hsv$1, index) { 'use strict'; console.log(hsl2hsv$1.p); var main = new Map(Object.entries(index.lib)); diff --git a/test/chunking-form/samples/namespace-reexports/_expected/cjs/generated-index.js b/test/chunking-form/samples/namespace-reexports/_expected/cjs/generated-chunk.js similarity index 100% rename from test/chunking-form/samples/namespace-reexports/_expected/cjs/generated-index.js rename to test/chunking-form/samples/namespace-reexports/_expected/cjs/generated-chunk.js diff --git a/test/chunking-form/samples/namespace-reexports/_expected/cjs/index.js b/test/chunking-form/samples/namespace-reexports/_expected/cjs/index.js index cd95edf7d26..dc695449285 100644 --- a/test/chunking-form/samples/namespace-reexports/_expected/cjs/index.js +++ b/test/chunking-form/samples/namespace-reexports/_expected/cjs/index.js @@ -3,7 +3,7 @@ Object.defineProperty(exports, '__esModule', { value: true }); var hsl2hsv$1 = require('./hsl2hsv.js'); -require('./generated-index.js'); +require('./generated-chunk.js'); diff --git a/test/chunking-form/samples/namespace-reexports/_expected/cjs/main.js b/test/chunking-form/samples/namespace-reexports/_expected/cjs/main.js index f56ee42c2ad..19c3b6a8ff6 100644 --- a/test/chunking-form/samples/namespace-reexports/_expected/cjs/main.js +++ b/test/chunking-form/samples/namespace-reexports/_expected/cjs/main.js @@ -3,7 +3,7 @@ Object.defineProperty(exports, '__esModule', { value: true }); var hsl2hsv$1 = require('./hsl2hsv.js'); -var index = require('./generated-index.js'); +var index = require('./generated-chunk.js'); console.log(hsl2hsv$1.p); var main = new Map(Object.entries(index.lib)); diff --git a/test/chunking-form/samples/namespace-reexports/_expected/es/generated-index.js b/test/chunking-form/samples/namespace-reexports/_expected/es/generated-chunk.js similarity index 100% rename from test/chunking-form/samples/namespace-reexports/_expected/es/generated-index.js rename to test/chunking-form/samples/namespace-reexports/_expected/es/generated-chunk.js diff --git a/test/chunking-form/samples/namespace-reexports/_expected/es/index.js b/test/chunking-form/samples/namespace-reexports/_expected/es/index.js index 18fe44189f4..bd43de91785 100644 --- a/test/chunking-form/samples/namespace-reexports/_expected/es/index.js +++ b/test/chunking-form/samples/namespace-reexports/_expected/es/index.js @@ -1,2 +1,2 @@ export { default as hsl2hsv } from './hsl2hsv.js'; -import './generated-index.js'; +import './generated-chunk.js'; diff --git a/test/chunking-form/samples/namespace-reexports/_expected/es/main.js b/test/chunking-form/samples/namespace-reexports/_expected/es/main.js index a41e4fe2ee9..d1c06ab9b87 100644 --- a/test/chunking-form/samples/namespace-reexports/_expected/es/main.js +++ b/test/chunking-form/samples/namespace-reexports/_expected/es/main.js @@ -1,5 +1,5 @@ import { p } from './hsl2hsv.js'; -import { a as lib } from './generated-index.js'; +import { a as lib } from './generated-chunk.js'; console.log(p); var main = new Map(Object.entries(lib)); diff --git a/test/chunking-form/samples/namespace-reexports/_expected/system/generated-index.js b/test/chunking-form/samples/namespace-reexports/_expected/system/generated-chunk.js similarity index 100% rename from test/chunking-form/samples/namespace-reexports/_expected/system/generated-index.js rename to test/chunking-form/samples/namespace-reexports/_expected/system/generated-chunk.js diff --git a/test/chunking-form/samples/namespace-reexports/_expected/system/index.js b/test/chunking-form/samples/namespace-reexports/_expected/system/index.js index 6fcfedd47f1..f3063b0b8f0 100644 --- a/test/chunking-form/samples/namespace-reexports/_expected/system/index.js +++ b/test/chunking-form/samples/namespace-reexports/_expected/system/index.js @@ -1,4 +1,4 @@ -System.register(['./hsl2hsv.js', './generated-index.js'], function (exports, module) { +System.register(['./hsl2hsv.js', './generated-chunk.js'], function (exports, module) { 'use strict'; return { setters: [function (module) { diff --git a/test/chunking-form/samples/namespace-reexports/_expected/system/main.js b/test/chunking-form/samples/namespace-reexports/_expected/system/main.js index f76be46c34c..30e0cc95052 100644 --- a/test/chunking-form/samples/namespace-reexports/_expected/system/main.js +++ b/test/chunking-form/samples/namespace-reexports/_expected/system/main.js @@ -1,4 +1,4 @@ -System.register(['./hsl2hsv.js', './generated-index.js'], function (exports, module) { +System.register(['./hsl2hsv.js', './generated-chunk.js'], function (exports, module) { 'use strict'; var p, lib; return { diff --git a/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-chunk.js b/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-dynamic1.js similarity index 82% rename from test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-chunk.js rename to test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-dynamic1.js index 1bfe4471eb9..be41dd73ba2 100644 --- a/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-chunk.js +++ b/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-dynamic1.js @@ -1,6 +1,6 @@ define(['require'], function (require) { 'use strict'; - new Promise(function (resolve, reject) { require(['./generated-chunk2'], resolve, reject) }); + new Promise(function (resolve, reject) { require(['./generated-dynamic2'], resolve, reject) }); console.log('dynamic1'); }); diff --git a/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-chunk2.js b/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-dynamic2.js similarity index 82% rename from test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-chunk2.js rename to test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-dynamic2.js index df13602628f..109eafa86de 100644 --- a/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-chunk2.js +++ b/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-dynamic2.js @@ -1,6 +1,6 @@ define(['require'], function (require) { 'use strict'; - new Promise(function (resolve, reject) { require(['./generated-chunk3'], resolve, reject) }); + new Promise(function (resolve, reject) { require(['./generated-dynamic3'], resolve, reject) }); console.log('dynamic2'); }); diff --git a/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-chunk3.js b/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-dynamic3.js similarity index 82% rename from test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-chunk3.js rename to test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-dynamic3.js index b949b96f311..87c99b617b8 100644 --- a/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-chunk3.js +++ b/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-dynamic3.js @@ -1,6 +1,6 @@ define(['require'], function (require) { 'use strict'; - new Promise(function (resolve, reject) { require(['./generated-chunk4'], resolve, reject) }); + new Promise(function (resolve, reject) { require(['./generated-dynamic4'], resolve, reject) }); console.log('dynamic3'); }); diff --git a/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-chunk4.js b/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-dynamic4.js similarity index 82% rename from test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-chunk4.js rename to test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-dynamic4.js index d054038fdc6..eed6272d3aa 100644 --- a/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-chunk4.js +++ b/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-dynamic4.js @@ -1,6 +1,6 @@ define(['require'], function (require) { 'use strict'; - new Promise(function (resolve, reject) { require(['./generated-chunk5'], resolve, reject) }); + new Promise(function (resolve, reject) { require(['./generated-dynamic5'], resolve, reject) }); console.log('dynamic4'); }); diff --git a/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-chunk5.js b/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-dynamic5.js similarity index 100% rename from test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-chunk5.js rename to test/chunking-form/samples/nested-dynamic-imports/_expected/amd/generated-dynamic5.js diff --git a/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/main.js b/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/main.js index 01d6eb9470d..317bb5f6206 100644 --- a/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/main.js +++ b/test/chunking-form/samples/nested-dynamic-imports/_expected/amd/main.js @@ -1,6 +1,6 @@ define(['require'], function (require) { 'use strict'; - new Promise(function (resolve, reject) { require(['./generated-chunk'], resolve, reject) }); + new Promise(function (resolve, reject) { require(['./generated-dynamic1'], resolve, reject) }); console.log('main'); }); diff --git a/test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/generated-chunk.js b/test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/generated-chunk.js deleted file mode 100644 index b09e30b302a..00000000000 --- a/test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/generated-chunk.js +++ /dev/null @@ -1,4 +0,0 @@ -'use strict'; - -Promise.resolve(require('./generated-chunk2.js')); -console.log('dynamic1'); diff --git a/test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/generated-chunk2.js b/test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/generated-chunk2.js deleted file mode 100644 index 7d9a89fbaf2..00000000000 --- a/test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/generated-chunk2.js +++ /dev/null @@ -1,4 +0,0 @@ -'use strict'; - -Promise.resolve(require('./generated-chunk3.js')); -console.log('dynamic2'); diff --git a/test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/generated-chunk3.js b/test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/generated-chunk3.js deleted file mode 100644 index 88071473204..00000000000 --- a/test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/generated-chunk3.js +++ /dev/null @@ -1,4 +0,0 @@ -'use strict'; - -Promise.resolve(require('./generated-chunk4.js')); -console.log('dynamic3'); diff --git a/test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/generated-chunk4.js b/test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/generated-chunk4.js deleted file mode 100644 index 214f7ec28ca..00000000000 --- a/test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/generated-chunk4.js +++ /dev/null @@ -1,4 +0,0 @@ -'use strict'; - -Promise.resolve(require('./generated-chunk5.js')); -console.log('dynamic4'); diff --git a/test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/generated-dynamic1.js b/test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/generated-dynamic1.js new file mode 100644 index 00000000000..2e429ed58c4 --- /dev/null +++ b/test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/generated-dynamic1.js @@ -0,0 +1,4 @@ +'use strict'; + +Promise.resolve(require('./generated-dynamic2.js')); +console.log('dynamic1'); diff --git a/test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/generated-dynamic2.js b/test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/generated-dynamic2.js new file mode 100644 index 00000000000..a9896858b47 --- /dev/null +++ b/test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/generated-dynamic2.js @@ -0,0 +1,4 @@ +'use strict'; + +Promise.resolve(require('./generated-dynamic3.js')); +console.log('dynamic2'); diff --git a/test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/generated-dynamic3.js b/test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/generated-dynamic3.js new file mode 100644 index 00000000000..1e884c8b3db --- /dev/null +++ b/test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/generated-dynamic3.js @@ -0,0 +1,4 @@ +'use strict'; + +Promise.resolve(require('./generated-dynamic4.js')); +console.log('dynamic3'); diff --git a/test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/generated-dynamic4.js b/test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/generated-dynamic4.js new file mode 100644 index 00000000000..aaafd7e6277 --- /dev/null +++ b/test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/generated-dynamic4.js @@ -0,0 +1,4 @@ +'use strict'; + +Promise.resolve(require('./generated-dynamic5.js')); +console.log('dynamic4'); diff --git a/test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/generated-chunk5.js b/test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/generated-dynamic5.js similarity index 100% rename from test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/generated-chunk5.js rename to test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/generated-dynamic5.js diff --git a/test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/main.js b/test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/main.js index 5b3ffb7c6e4..dcea8717078 100644 --- a/test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/main.js +++ b/test/chunking-form/samples/nested-dynamic-imports/_expected/cjs/main.js @@ -1,4 +1,4 @@ 'use strict'; -Promise.resolve(require('./generated-chunk.js')); +Promise.resolve(require('./generated-dynamic1.js')); console.log('main'); diff --git a/test/chunking-form/samples/nested-dynamic-imports/_expected/es/generated-chunk.js b/test/chunking-form/samples/nested-dynamic-imports/_expected/es/generated-chunk.js deleted file mode 100644 index 04888332178..00000000000 --- a/test/chunking-form/samples/nested-dynamic-imports/_expected/es/generated-chunk.js +++ /dev/null @@ -1,2 +0,0 @@ -import('./generated-chunk2.js'); -console.log('dynamic1'); diff --git a/test/chunking-form/samples/nested-dynamic-imports/_expected/es/generated-chunk2.js b/test/chunking-form/samples/nested-dynamic-imports/_expected/es/generated-chunk2.js deleted file mode 100644 index f43111637d5..00000000000 --- a/test/chunking-form/samples/nested-dynamic-imports/_expected/es/generated-chunk2.js +++ /dev/null @@ -1,2 +0,0 @@ -import('./generated-chunk3.js'); -console.log('dynamic2'); diff --git a/test/chunking-form/samples/nested-dynamic-imports/_expected/es/generated-chunk3.js b/test/chunking-form/samples/nested-dynamic-imports/_expected/es/generated-chunk3.js deleted file mode 100644 index b830dba19da..00000000000 --- a/test/chunking-form/samples/nested-dynamic-imports/_expected/es/generated-chunk3.js +++ /dev/null @@ -1,2 +0,0 @@ -import('./generated-chunk4.js'); -console.log('dynamic3'); diff --git a/test/chunking-form/samples/nested-dynamic-imports/_expected/es/generated-chunk4.js b/test/chunking-form/samples/nested-dynamic-imports/_expected/es/generated-chunk4.js deleted file mode 100644 index 0ea2bc62e07..00000000000 --- a/test/chunking-form/samples/nested-dynamic-imports/_expected/es/generated-chunk4.js +++ /dev/null @@ -1,2 +0,0 @@ -import('./generated-chunk5.js'); -console.log('dynamic4'); diff --git a/test/chunking-form/samples/nested-dynamic-imports/_expected/es/generated-dynamic1.js b/test/chunking-form/samples/nested-dynamic-imports/_expected/es/generated-dynamic1.js new file mode 100644 index 00000000000..2db19197d94 --- /dev/null +++ b/test/chunking-form/samples/nested-dynamic-imports/_expected/es/generated-dynamic1.js @@ -0,0 +1,2 @@ +import('./generated-dynamic2.js'); +console.log('dynamic1'); diff --git a/test/chunking-form/samples/nested-dynamic-imports/_expected/es/generated-dynamic2.js b/test/chunking-form/samples/nested-dynamic-imports/_expected/es/generated-dynamic2.js new file mode 100644 index 00000000000..544cfec1ef5 --- /dev/null +++ b/test/chunking-form/samples/nested-dynamic-imports/_expected/es/generated-dynamic2.js @@ -0,0 +1,2 @@ +import('./generated-dynamic3.js'); +console.log('dynamic2'); diff --git a/test/chunking-form/samples/nested-dynamic-imports/_expected/es/generated-dynamic3.js b/test/chunking-form/samples/nested-dynamic-imports/_expected/es/generated-dynamic3.js new file mode 100644 index 00000000000..53e4eba921e --- /dev/null +++ b/test/chunking-form/samples/nested-dynamic-imports/_expected/es/generated-dynamic3.js @@ -0,0 +1,2 @@ +import('./generated-dynamic4.js'); +console.log('dynamic3'); diff --git a/test/chunking-form/samples/nested-dynamic-imports/_expected/es/generated-dynamic4.js b/test/chunking-form/samples/nested-dynamic-imports/_expected/es/generated-dynamic4.js new file mode 100644 index 00000000000..db04880a96f --- /dev/null +++ b/test/chunking-form/samples/nested-dynamic-imports/_expected/es/generated-dynamic4.js @@ -0,0 +1,2 @@ +import('./generated-dynamic5.js'); +console.log('dynamic4'); diff --git a/test/chunking-form/samples/nested-dynamic-imports/_expected/es/generated-chunk5.js b/test/chunking-form/samples/nested-dynamic-imports/_expected/es/generated-dynamic5.js similarity index 100% rename from test/chunking-form/samples/nested-dynamic-imports/_expected/es/generated-chunk5.js rename to test/chunking-form/samples/nested-dynamic-imports/_expected/es/generated-dynamic5.js diff --git a/test/chunking-form/samples/nested-dynamic-imports/_expected/es/main.js b/test/chunking-form/samples/nested-dynamic-imports/_expected/es/main.js index 0d08731bb46..eb9bbf2acfb 100644 --- a/test/chunking-form/samples/nested-dynamic-imports/_expected/es/main.js +++ b/test/chunking-form/samples/nested-dynamic-imports/_expected/es/main.js @@ -1,2 +1,2 @@ -import('./generated-chunk.js'); +import('./generated-dynamic1.js'); console.log('main'); diff --git a/test/chunking-form/samples/nested-dynamic-imports/_expected/system/generated-chunk.js b/test/chunking-form/samples/nested-dynamic-imports/_expected/system/generated-dynamic1.js similarity index 75% rename from test/chunking-form/samples/nested-dynamic-imports/_expected/system/generated-chunk.js rename to test/chunking-form/samples/nested-dynamic-imports/_expected/system/generated-dynamic1.js index 10450928e02..4885888ccf8 100644 --- a/test/chunking-form/samples/nested-dynamic-imports/_expected/system/generated-chunk.js +++ b/test/chunking-form/samples/nested-dynamic-imports/_expected/system/generated-dynamic1.js @@ -3,7 +3,7 @@ System.register([], function (exports, module) { return { execute: function () { - module.import('./generated-chunk2.js'); + module.import('./generated-dynamic2.js'); console.log('dynamic1'); } diff --git a/test/chunking-form/samples/nested-dynamic-imports/_expected/system/generated-chunk2.js b/test/chunking-form/samples/nested-dynamic-imports/_expected/system/generated-dynamic2.js similarity index 75% rename from test/chunking-form/samples/nested-dynamic-imports/_expected/system/generated-chunk2.js rename to test/chunking-form/samples/nested-dynamic-imports/_expected/system/generated-dynamic2.js index 8a981954622..186a6116c10 100644 --- a/test/chunking-form/samples/nested-dynamic-imports/_expected/system/generated-chunk2.js +++ b/test/chunking-form/samples/nested-dynamic-imports/_expected/system/generated-dynamic2.js @@ -3,7 +3,7 @@ System.register([], function (exports, module) { return { execute: function () { - module.import('./generated-chunk3.js'); + module.import('./generated-dynamic3.js'); console.log('dynamic2'); } diff --git a/test/chunking-form/samples/nested-dynamic-imports/_expected/system/generated-chunk3.js b/test/chunking-form/samples/nested-dynamic-imports/_expected/system/generated-dynamic3.js similarity index 75% rename from test/chunking-form/samples/nested-dynamic-imports/_expected/system/generated-chunk3.js rename to test/chunking-form/samples/nested-dynamic-imports/_expected/system/generated-dynamic3.js index 913ec0b469d..96e85221924 100644 --- a/test/chunking-form/samples/nested-dynamic-imports/_expected/system/generated-chunk3.js +++ b/test/chunking-form/samples/nested-dynamic-imports/_expected/system/generated-dynamic3.js @@ -3,7 +3,7 @@ System.register([], function (exports, module) { return { execute: function () { - module.import('./generated-chunk4.js'); + module.import('./generated-dynamic4.js'); console.log('dynamic3'); } diff --git a/test/chunking-form/samples/nested-dynamic-imports/_expected/system/generated-chunk4.js b/test/chunking-form/samples/nested-dynamic-imports/_expected/system/generated-dynamic4.js similarity index 75% rename from test/chunking-form/samples/nested-dynamic-imports/_expected/system/generated-chunk4.js rename to test/chunking-form/samples/nested-dynamic-imports/_expected/system/generated-dynamic4.js index 928a453dd1c..d2859ce1ff5 100644 --- a/test/chunking-form/samples/nested-dynamic-imports/_expected/system/generated-chunk4.js +++ b/test/chunking-form/samples/nested-dynamic-imports/_expected/system/generated-dynamic4.js @@ -3,7 +3,7 @@ System.register([], function (exports, module) { return { execute: function () { - module.import('./generated-chunk5.js'); + module.import('./generated-dynamic5.js'); console.log('dynamic4'); } diff --git a/test/chunking-form/samples/nested-dynamic-imports/_expected/system/generated-chunk5.js b/test/chunking-form/samples/nested-dynamic-imports/_expected/system/generated-dynamic5.js similarity index 100% rename from test/chunking-form/samples/nested-dynamic-imports/_expected/system/generated-chunk5.js rename to test/chunking-form/samples/nested-dynamic-imports/_expected/system/generated-dynamic5.js diff --git a/test/chunking-form/samples/nested-dynamic-imports/_expected/system/main.js b/test/chunking-form/samples/nested-dynamic-imports/_expected/system/main.js index 61f5627b5c3..356dfbd0378 100644 --- a/test/chunking-form/samples/nested-dynamic-imports/_expected/system/main.js +++ b/test/chunking-form/samples/nested-dynamic-imports/_expected/system/main.js @@ -3,7 +3,7 @@ System.register([], function (exports, module) { return { execute: function () { - module.import('./generated-chunk.js'); + module.import('./generated-dynamic1.js'); console.log('main'); } diff --git a/test/chunking-form/samples/sanitize-internal-exports/_expected/amd/generated-chunk2.js b/test/chunking-form/samples/sanitize-internal-exports/_expected/amd/generated-lazy.js similarity index 100% rename from test/chunking-form/samples/sanitize-internal-exports/_expected/amd/generated-chunk2.js rename to test/chunking-form/samples/sanitize-internal-exports/_expected/amd/generated-lazy.js diff --git a/test/chunking-form/samples/sanitize-internal-exports/_expected/amd/main.js b/test/chunking-form/samples/sanitize-internal-exports/_expected/amd/main.js index 664244c36b1..a5b743a2ca4 100644 --- a/test/chunking-form/samples/sanitize-internal-exports/_expected/amd/main.js +++ b/test/chunking-form/samples/sanitize-internal-exports/_expected/amd/main.js @@ -1,6 +1,6 @@ define(['require', 'exports', './generated-chunk'], function (require, exports, __chunk_1) { 'use strict'; - const lazy = new Promise(function (resolve, reject) { require(['./generated-chunk2'], resolve, reject) }); + const lazy = new Promise(function (resolve, reject) { require(['./generated-lazy'], resolve, reject) }); exports.v1 = __chunk_1.v1; exports.v10 = __chunk_1.v10; diff --git a/test/chunking-form/samples/sanitize-internal-exports/_expected/cjs/generated-chunk2.js b/test/chunking-form/samples/sanitize-internal-exports/_expected/cjs/generated-lazy.js similarity index 100% rename from test/chunking-form/samples/sanitize-internal-exports/_expected/cjs/generated-chunk2.js rename to test/chunking-form/samples/sanitize-internal-exports/_expected/cjs/generated-lazy.js diff --git a/test/chunking-form/samples/sanitize-internal-exports/_expected/cjs/main.js b/test/chunking-form/samples/sanitize-internal-exports/_expected/cjs/main.js index 4687a5bb309..202e70c12c0 100644 --- a/test/chunking-form/samples/sanitize-internal-exports/_expected/cjs/main.js +++ b/test/chunking-form/samples/sanitize-internal-exports/_expected/cjs/main.js @@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true }); var __chunk_1 = require('./generated-chunk.js'); -const lazy = Promise.resolve(require('./generated-chunk2.js')); +const lazy = Promise.resolve(require('./generated-lazy.js')); exports.v1 = __chunk_1.v1; exports.v10 = __chunk_1.v10; diff --git a/test/chunking-form/samples/sanitize-internal-exports/_expected/es/generated-chunk2.js b/test/chunking-form/samples/sanitize-internal-exports/_expected/es/generated-lazy.js similarity index 100% rename from test/chunking-form/samples/sanitize-internal-exports/_expected/es/generated-chunk2.js rename to test/chunking-form/samples/sanitize-internal-exports/_expected/es/generated-lazy.js diff --git a/test/chunking-form/samples/sanitize-internal-exports/_expected/es/main.js b/test/chunking-form/samples/sanitize-internal-exports/_expected/es/main.js index 9820c00783c..8ce7e5984df 100644 --- a/test/chunking-form/samples/sanitize-internal-exports/_expected/es/main.js +++ b/test/chunking-form/samples/sanitize-internal-exports/_expected/es/main.js @@ -1,5 +1,5 @@ export { a as v1, j as v10, aJ as v100, aK as v101, aL as v102, aM as v103, aN as v104, aO as v105, aP as v106, aQ as v107, aR as v108, aS as v109, k as v11, aT as v110, aU as v111, aV as v112, aW as v113, aX as v114, aY as v115, aZ as v116, a_ as v117, a$ as v118, b0 as v119, l as v12, b1 as v120, b2 as v121, b3 as v122, b4 as v123, b5 as v124, b6 as v125, b7 as v126, b8 as v127, b9 as v128, ba as v129, m as v13, bb as v130, bc as v131, bd as v132, be as v133, bf as v134, bg as v135, bh as v136, bi as v137, bj as v138, bk as v139, n as v14, bl as v140, bm as v141, bn as v142, bo as v143, bp as v144, bq as v145, br as v146, bs as v147, bt as v148, bu as v149, o as v15, bv as v150, bw as v151, bx as v152, by as v153, bz as v154, bA as v155, bB as v156, bC as v157, bD as v158, bE as v159, p as v16, bF as v160, bG as v161, bH as v162, bI as v163, bJ as v164, bK as v165, bL as v166, bM as v167, bN as v168, bO as v169, q as v17, bP as v170, bQ as v171, bR as v172, bS as v173, bT as v174, bU as v175, bV as v176, bW as v177, bX as v178, bY as v179, r as v18, bZ as v180, b_ as v181, b$ as v182, c0 as v183, c1 as v184, c2 as v185, c3 as v186, c4 as v187, c5 as v188, c6 as v189, s as v19, c7 as v190, c8 as v191, c9 as v192, ca as v193, cb as v194, cc as v195, cd as v196, ce as v197, cf as v198, cg as v199, b as v2, t as v20, ch as v200, ci as v201, cj as v202, ck as v203, cl as v204, cm as v205, cn as v206, co as v207, cp as v208, cq as v209, u as v21, cr as v210, cs as v211, ct as v212, cu as v213, cv as v214, cw as v215, cx as v216, cy as v217, cz as v218, cA as v219, v as v22, cB as v220, cC as v221, cD as v222, cE as v223, cF as v224, cG as v225, cH as v226, cI as v227, cJ as v228, cK as v229, w as v23, cL as v230, cM as v231, cN as v232, cO as v233, cP as v234, cQ as v235, cR as v236, cS as v237, cT as v238, cU as v239, x as v24, cV as v240, cW as v241, cX as v242, cY as v243, cZ as v244, c_ as v245, c$ as v246, d0 as v247, d1 as v248, d2 as v249, y as v25, d3 as v250, d4 as v251, d5 as v252, d6 as v253, d7 as v254, d8 as v255, d9 as v256, da as v257, db as v258, dc as v259, z as v26, dd as v260, de as v261, df as v262, dg as v263, dh as v264, di as v265, dj as v266, dk as v267, dl as v268, dm as v269, A as v27, dn as v270, dp as v271, dq as v272, B as v28, C as v29, c as v3, D as v30, E as v31, F as v32, G as v33, H as v34, I as v35, J as v36, K as v37, L as v38, M as v39, d as v4, N as v40, O as v41, P as v42, Q as v43, R as v44, S as v45, T as v46, U as v47, V as v48, W as v49, e as v5, X as v50, Y as v51, Z as v52, _ as v53, $ as v54, a0 as v55, a1 as v56, a2 as v57, a3 as v58, a4 as v59, f as v6, a5 as v60, a6 as v61, a7 as v62, a8 as v63, a9 as v64, aa as v65, ab as v66, ac as v67, ad as v68, ae as v69, g as v7, af as v70, ag as v71, ah as v72, ai as v73, aj as v74, ak as v75, al as v76, am as v77, an as v78, ao as v79, h as v8, ap as v80, aq as v81, ar as v82, as as v83, at as v84, au as v85, av as v86, aw as v87, ax as v88, ay as v89, i as v9, az as v90, aA as v91, aB as v92, aC as v93, aD as v94, aE as v95, aF as v96, aG as v97, aH as v98, aI as v99 } from './generated-chunk.js'; -const lazy = import('./generated-chunk2.js'); +const lazy = import('./generated-lazy.js'); export { lazy }; diff --git a/test/chunking-form/samples/sanitize-internal-exports/_expected/system/generated-chunk2.js b/test/chunking-form/samples/sanitize-internal-exports/_expected/system/generated-lazy.js similarity index 100% rename from test/chunking-form/samples/sanitize-internal-exports/_expected/system/generated-chunk2.js rename to test/chunking-form/samples/sanitize-internal-exports/_expected/system/generated-lazy.js diff --git a/test/chunking-form/samples/sanitize-internal-exports/_expected/system/main.js b/test/chunking-form/samples/sanitize-internal-exports/_expected/system/main.js index ffe78d9f1af..5ce83aac926 100644 --- a/test/chunking-form/samples/sanitize-internal-exports/_expected/system/main.js +++ b/test/chunking-form/samples/sanitize-internal-exports/_expected/system/main.js @@ -279,7 +279,7 @@ System.register(['./generated-chunk.js'], function (exports, module) { }], execute: function () { - const lazy = exports('lazy', module.import('./generated-chunk2.js')); + const lazy = exports('lazy', module.import('./generated-lazy.js')); } }; diff --git a/test/hooks/index.js b/test/hooks/index.js index 207c86e60b9..292c75bf6b8 100644 --- a/test/hooks/index.js +++ b/test/hooks/index.js @@ -1311,18 +1311,18 @@ module.exports = input; modules: ['input'] }, { - fileName: 'generated-chunk.js', - imports: ['generated-chunk2.js'], + fileName: 'generated-a.js', + imports: ['generated-chunk.js'], modules: ['d', 'a'] }, { - fileName: 'generated-chunk2.js', + fileName: 'generated-chunk.js', imports: [], modules: ['c'] }, { - fileName: 'generated-chunk3.js', - imports: ['generated-chunk2.js'], + fileName: 'generated-b.js', + imports: ['generated-chunk.js'], modules: ['b'] } ]); diff --git a/test/misc/bundle-information.js b/test/misc/bundle-information.js index 106417b9709..0ca67ba968d 100644 --- a/test/misc/bundle-information.js +++ b/test/misc/bundle-information.js @@ -109,7 +109,7 @@ describe('The bundle object', () => { .then(({ output }) => { assert.deepEqual( output.map(chunk => chunk.fileName), - ['input1.js', 'input2.js', 'generated-input2.js'], + ['input1.js', 'input2.js', 'generated-chunk.js'], 'fileName' ); assert.deepEqual( @@ -150,7 +150,7 @@ describe('The bundle object', () => { .then(({ output }) => { assert.deepEqual( output.map(chunk => chunk.fileName), - ['input1.js', 'input2.js', 'input22.js'], + ['input1.js', 'input2.js', 'chunk.js'], 'fileName' ); assert.deepEqual( @@ -184,14 +184,14 @@ describe('The bundle object', () => { .then(({ output }) => { assert.deepEqual( output.map(chunk => chunk.fileName), - ['input.js', 'dynamic1.js', 'generated-chunk.js'], + ['input.js', 'dynamic1.js', 'generated-dynamic2.js'], 'fileName' ); assert.deepEqual(output.map(chunk => chunk.isEntry), [true, true, false], 'isEntry'); assert.deepEqual( output.map(chunk => chunk.code), [ - `Promise.all([import('./dynamic1.js'), import('./generated-chunk.js')]).then(([{dynamic1}, {dynamic2}]) => console.log(dynamic1, dynamic2));\n`, + `Promise.all([import('./dynamic1.js'), import('./generated-dynamic2.js')]).then(([{dynamic1}, {dynamic2}]) => console.log(dynamic1, dynamic2));\n`, 'const dynamic1 = "dynamic1";\n\nexport { dynamic1 };\n', 'const dynamic2 = "dynamic2";\n\nexport { dynamic2 };\n' ], @@ -209,7 +209,7 @@ describe('The bundle object', () => { ); assert.deepEqual( output.map(chunk => chunk.dynamicImports), - [['dynamic1.js', 'generated-chunk.js'], [], []], + [['dynamic1.js', 'generated-dynamic2.js'], [], []], 'dynamicImports' ); }); @@ -239,7 +239,7 @@ describe('The bundle object', () => { .then(({ output }) => { assert.deepEqual( output.map(chunk => chunk.fileName), - ['input1.js', 'input2.js', 'generated-chunk.js', 'generated-chunk2.js'], + ['input1.js', 'input2.js', 'generated-chunk.js', 'generated-dynamic.js'], 'fileName' ); assert.deepEqual( @@ -348,7 +348,7 @@ console.log(other);Promise.all([import('./dynamic1'), import('./dynamic2')]).the ); assert.deepEqual( output.map(chunk => chunk.name), - ['input', 'dynamic1', 'chunk', 'chunk'], + ['input', 'dynamic1', 'other', 'dynamic2'], 'name' ); assert.deepEqual( diff --git a/test/misc/misc.js b/test/misc/misc.js index 9336ab25605..1a59e2a0fd5 100644 --- a/test/misc/misc.js +++ b/test/misc/misc.js @@ -92,7 +92,7 @@ describe('misc', () => { 'main1.js', 'main2.js', 'chunk-9d1272f4.js', - 'chunk-80285050.js' + 'dyndep-80285050.js' ]); }); }); diff --git a/test/watch/index.js b/test/watch/index.js index 6f65562713e..1af42233e9e 100644 --- a/test/watch/index.js +++ b/test/watch/index.js @@ -605,13 +605,13 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - [chunkName, dynamicName, staticName] = sander.readdirSync('test/_tmp/output').sort(); + [dynamicName, staticName, chunkName] = sander.readdirSync('test/_tmp/output').sort(); sander.rimrafSync('test/_tmp/output'); // this should only update the hash of that particular entry point sander.writeFileSync( 'test/_tmp/input/main-static.js', - "import {value} from './shared';export default 2*value;" + "import {value} from './shared';\nexport default 2 * value;" ); }, 'START', @@ -619,7 +619,7 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - const [newChunkName, newDynamicName, newStaticName] = sander + const [newDynamicName, newStaticName, newChunkName] = sander .readdirSync('test/_tmp/output') .sort(); sander.rimrafSync('test/_tmp/output'); @@ -636,7 +636,7 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - const [newChunkName, newDynamicName, newStaticName] = sander + const [newDynamicName, newStaticName, newChunkName] = sander .readdirSync('test/_tmp/output') .sort(); assert.notEqual(newStaticName, staticName); From 6675abb09fc0256a26009c85938d1b7b11bed7e2 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Wed, 24 Apr 2019 09:01:45 +0200 Subject: [PATCH 44/60] Update documentation --- docs/05-plugins.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/docs/05-plugins.md b/docs/05-plugins.md index 9fbf1f28b17..98f3b4ae664 100644 --- a/docs/05-plugins.md +++ b/docs/05-plugins.md @@ -205,10 +205,12 @@ resolveAssetUrl({assetFileName}) { ``` #### `resolveDynamicImport` -Type: `(specifier: string | ESTree.Node, importer: string) => string | false | null`
+Type: `(specifier: string | ESTree.Node, importer: string) => string | false | null | {id: string, external?: boolean}`
Kind: `async, first` -Defines a custom resolver for dynamic imports. In case a dynamic import is not passed a string as argument, this hook gets access to the raw AST nodes to analyze. Returning `null` will defer to other resolvers and eventually to `resolveId` if this is possible; returning `false` signals that the import should be kept as it is and not be passed to other resolvers thus making it external. Note that the return value of this hook will not be passed to `resolveId` afterwards; if you need access to the static resolution algorithm, you can use `this.resolveId(importee, importer)` on the plugin context. +Defines a custom resolver for dynamic imports. In case a dynamic import is not passed a string as argument, this hook gets access to the raw AST nodes to analyze. Returning `null` will defer to other resolvers and eventually to `resolveId` if this is possible; returning `false` signals that the import should be kept as it is and not be passed to other resolvers thus making it external. Similar to the [`resolveId`](guide/en#resolveid) hook, you can also return an object to resolve the import to a different id while marking it as external at the same time. + +Note that the return value of this hook will not be passed to `resolveId` afterwards; if you need access to the static resolution algorithm, you can use [`this.resolveId(importee, importer)`](guide/en#this-resolveid-importee-string-importer-string-string-null) on the plugin context. #### `resolveId` Type: `(importee: string, importer: string) => string | false | null | {id: string, external?: boolean}`
@@ -325,9 +327,9 @@ Returns additional information about the module in question in the form If the module id cannot be found, an error is thrown. -#### `this.isExternal(id: string, parentId: string, isResolved: boolean): boolean` +#### `this.isExternal(id: string, importer: string, isResolved: boolean): boolean` -Determine if a given module ID is external. +Determine if a given module ID is external when imported by `importer`. When `isResolved` is false, Rollup will try to resolve the id before testing if it is external. #### `this.meta: {rollupVersion: string}` @@ -347,9 +349,9 @@ or converted into an Array via `Array.from(this.moduleIds)`. Use Rollup's internal acorn instance to parse code to an AST. -#### `this.resolveId(importee: string, importer: string) => string` +#### `this.resolveId(importee: string, importer: string) => string | null` -Resolve imports to module ids (i.e. file names). Uses the same hooks as Rollup itself. +Resolve imports to module ids (i.e. file names) using the same plugins that Rollup uses. Returns `null` if an id cannot be resolved. Use [`this.isExternal(importee, importer, true)`](guide/en#this-isexternal-id-string-importer-string-isresolved-boolean-boolean) to determine if a resolved id is external. #### `this.setAssetSource(assetId: string, source: string | Buffer) => void` From 35b76f32f93ec8e7c90b9dfeaf4c1c6d6b2a0ec0 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Thu, 25 Apr 2019 17:15:17 +0200 Subject: [PATCH 45/60] Refine pluginDriver types (ported from add-entry branch) --- src/Graph.ts | 47 ++++++++++++++++-------------- src/ast/nodes/MetaProperty.ts | 4 +-- src/rollup/index.ts | 15 ++++------ src/rollup/types.d.ts | 34 +++++++++++++++------- src/utils/pluginDriver.ts | 55 ++++++++++++++++++++++++----------- 5 files changed, 94 insertions(+), 61 deletions(-) diff --git a/src/Graph.ts b/src/Graph.ts index 2657d6ef9ff..ea789caa959 100644 --- a/src/Graph.ts +++ b/src/Graph.ts @@ -402,8 +402,11 @@ export default class Graph { const fetchDynamicImportsPromise = Promise.all( module.getDynamicImportExpressions().map((dynamicImportExpression, index) => this.pluginDriver - .hookFirst('resolveDynamicImport', [dynamicImportExpression, module.id]) - .then(replacement => { + .hookFirst('resolveDynamicImport', [ + dynamicImportExpression as string | ESTree.Node, + module.id + ]) + .then((replacement: string | void) => { if (!replacement) return; const dynamicImport = module.dynamicImports[index]; dynamicImport.alias = getAliasName( @@ -454,7 +457,9 @@ export default class Graph { this.watchFiles[id] = true; timeStart('load modules', 3); - return Promise.resolve(this.pluginDriver.hookFirst('load', [id])) + return Promise.resolve( + this.pluginDriver.hookFirst<'load', string | SourceDescription>('load', [id]) + ) .catch((err: Error) => { timeEnd('load modules', 3); let msg = `Could not load ${id}`; @@ -617,25 +622,23 @@ export default class Graph { } private loadModule(entryName: string) { - return this.pluginDriver - .hookFirst('resolveId', [entryName, undefined]) - .then(id => { - if (id === false) { - error({ - code: 'UNRESOLVED_ENTRY', - message: `Entry module cannot be external` - }); - } + return this.pluginDriver.hookFirst('resolveId', [entryName, undefined]).then(id => { + if (id === false) { + error({ + code: 'UNRESOLVED_ENTRY', + message: `Entry module cannot be external` + }); + } - if (id == null) { - error({ - code: 'UNRESOLVED_ENTRY', - message: `Could not resolve entry (${entryName})` - }); - } + if (id == null) { + error({ + code: 'UNRESOLVED_ENTRY', + message: `Could not resolve entry (${entryName})` + }); + } - return this.fetchModule(id, undefined); - }); + return this.fetchModule(id, undefined); + }); } private normalizeResolveIdResult( @@ -690,8 +693,8 @@ export default class Graph { Promise.resolve( this.isExternal(source, module.id, false) ? { id: source, external: true } - : this.pluginDriver.hookFirst('resolveId', [source, module.id]) - ).then(result => this.normalizeResolveIdResult(result, module, source)) + : this.pluginDriver.hookFirst('resolveId', [source, module.id]) + ).then((result: ResolveIdResult) => this.normalizeResolveIdResult(result, module, source)) ).then(resolvedId => { module.resolvedIds[source] = resolvedId; if (resolvedId.external) { diff --git a/src/ast/nodes/MetaProperty.ts b/src/ast/nodes/MetaProperty.ts index 4bbbc30eace..0f545483d2a 100644 --- a/src/ast/nodes/MetaProperty.ts +++ b/src/ast/nodes/MetaProperty.ts @@ -35,7 +35,7 @@ export default class MetaProperty extends NodeBase { if (importMetaProperty && importMetaProperty.startsWith('ROLLUP_ASSET_URL_')) { const assetFileName = this.context.getAssetFileName(importMetaProperty.substr(17)); const relativeAssetPath = normalize(relative(dirname(chunkId), assetFileName)); - const replacement = pluginDriver.hookFirstSync('resolveAssetUrl', [ + const replacement = pluginDriver.hookFirstSync<'resolveAssetUrl', string>('resolveAssetUrl', [ { assetFileName, chunkId, @@ -53,7 +53,7 @@ export default class MetaProperty extends NodeBase { return true; } - const replacement = pluginDriver.hookFirstSync('resolveImportMeta', [ + const replacement = pluginDriver.hookFirstSync('resolveImportMeta', [ importMetaProperty, { chunkId, diff --git a/src/rollup/index.ts b/src/rollup/index.ts index c1faac31ca2..f35cf6aca88 100644 --- a/src/rollup/index.ts +++ b/src/rollup/index.ts @@ -67,7 +67,7 @@ function applyOptionHook(inputOptions: InputOptions, plugin: Plugin) { return inputOptions; } -function getInputOptions(rawInputOptions: GenericConfigObject): any { +function getInputOptions(rawInputOptions: GenericConfigObject): InputOptions { if (!rawInputOptions) { throw new Error('You must supply an options object to rollup'); } @@ -156,10 +156,7 @@ export default function rollup(rawInputOptions: GenericConfigObject): Promise - graph.pluginDriver.hookParallel('buildEnd').then(() => { - return chunks; - }), + chunks => graph.pluginDriver.hookParallel('buildEnd', []).then(() => chunks), err => graph.pluginDriver.hookParallel('buildEnd', [err]).then(() => { throw err; @@ -188,7 +185,7 @@ export default function rollup(rawInputOptions: GenericConfigObject): Promise createAddons(graph, outputOptions)) .then(addons => { // pre-render all chunks @@ -326,9 +323,9 @@ export default function rollup(rawInputOptions: GenericConfigObject): Promise { - return writeOutputFile(graph, result, bundle[chunkId], outputOptions); - }) + Object.keys(bundle).map(chunkId => + writeOutputFile(graph, result, bundle[chunkId], outputOptions) + ) ) .then(() => graph.pluginDriver.hookParallel('writeBundle', [bundle])) .then(() => createOutput(bundle)); diff --git a/src/rollup/types.d.ts b/src/rollup/types.d.ts index 86b5fffe558..34ea3915cc5 100644 --- a/src/rollup/types.d.ts +++ b/src/rollup/types.d.ts @@ -62,12 +62,12 @@ export interface SourceMap { } export interface SourceDescription { + ast?: ESTree.Program; code: string; map?: string | RawSourceMap; } export interface TransformSourceDescription extends SourceDescription { - ast?: ESTree.Program; dependencies?: string[]; } @@ -117,7 +117,7 @@ export interface PluginContext extends MinimalPluginContext { isExternal: IsExternal; moduleIds: IterableIterator; parse: (input: string, options: any) => ESTree.Program; - resolveId: ResolveIdHook; + resolveId: (id: string, parent: string) => Promise; setAssetSource: (assetId: string, source: string | Buffer) => void; /** @deprecated */ watcher: EventEmitter; @@ -185,6 +185,7 @@ export type RenderChunkHook = ( | string | null; +// TODO this should probably return ResolveIdResult export type ResolveDynamicImportHook = ( this: PluginContext, specifier: string | ESTree.Node, @@ -226,36 +227,38 @@ export interface OutputBundle { [fileName: string]: OutputAsset | OutputChunk; } -export interface Plugin { - banner?: AddonHook; +interface OnGenerateOptions extends OutputOptions { + bundle: OutputChunk; +} + +interface OnWriteOptions extends OutputOptions { + bundle: RollupBuild; +} + +export interface PluginHooks { buildEnd?: (this: PluginContext, err?: Error) => Promise | void; buildStart?: (this: PluginContext, options: InputOptions) => Promise | void; - cacheKey?: string; - footer?: AddonHook; generateBundle?: ( this: PluginContext, options: OutputOptions, bundle: OutputBundle, isWrite: boolean ) => void | Promise; - intro?: AddonHook; load?: LoadHook; - name: string; /** @deprecated */ ongenerate?: ( this: PluginContext, - options: OutputOptions, + options: OnGenerateOptions, chunk: OutputChunk ) => void | Promise; /** @deprecated */ onwrite?: ( this: PluginContext, - options: OutputOptions, + options: OnWriteOptions, chunk: OutputChunk ) => void | Promise; options?: (this: MinimalPluginContext, options: InputOptions) => InputOptions | void | null; outputOptions?: (this: PluginContext, options: OutputOptions) => OutputOptions | void | null; - outro?: AddonHook; renderChunk?: RenderChunkHook; renderError?: (this: PluginContext, err?: Error) => Promise | void; renderStart?: (this: PluginContext) => Promise | void; @@ -272,6 +275,15 @@ export interface Plugin { writeBundle?: (this: PluginContext, bundle: OutputBundle) => void | Promise; } +export interface Plugin extends PluginHooks { + banner?: AddonHook; + cacheKey?: string; + footer?: AddonHook; + intro?: AddonHook; + name: string; + outro?: AddonHook; +} + export interface TreeshakingOptions { annotations?: boolean; propertyReadSideEffects?: boolean; diff --git a/src/utils/pluginDriver.ts b/src/utils/pluginDriver.ts index 2c32d9403d5..a04ee981bdd 100644 --- a/src/utils/pluginDriver.ts +++ b/src/utils/pluginDriver.ts @@ -7,6 +7,7 @@ import { Plugin, PluginCache, PluginContext, + PluginHooks, RollupError, RollupWarning, RollupWatcher, @@ -17,25 +18,39 @@ import { getRollupDefaultPlugin } from './defaultPlugin'; import { error } from './error'; import { NameCollection } from './reservedNames'; +type Args = T extends (...args: infer K) => any ? K : never; + export interface PluginDriver { emitAsset: EmitAsset; hasLoadersOrTransforms: boolean; - getAssetFileName(assetId: string): string; - hookFirst(hook: string, args?: any[], hookContext?: HookContext): Promise; - hookFirstSync(hook: string, args?: any[], hookContext?: HookContext): T; - hookParallel(hook: string, args?: any[], hookContext?: HookContext): Promise; - hookReduceArg0( - hook: string, + getAssetFileName(assetReferenceId: string): string; + hookFirst>( + hook: H, + args: Args, + hookContext?: HookContext + ): Promise; + hookFirstSync>( + hook: H, + args: Args, + hookContext?: HookContext + ): R; + hookParallel( + hook: H, + args: Args, + hookContext?: HookContext + ): Promise; + hookReduceArg0>( + hook: H, args: any[], - reduce: Reduce, + reduce: Reduce, hookContext?: HookContext - ): Promise; - hookReduceArg0Sync( - hook: string, + ): Promise; + hookReduceArg0Sync>( + hook: H, args: any[], - reduce: Reduce, + reduce: Reduce, hookContext?: HookContext - ): T; + ): R; hookReduceValue( hook: string, value: T | Promise, @@ -43,8 +58,16 @@ export interface PluginDriver { reduce: Reduce, hookContext?: HookContext ): Promise; - hookSeq(hook: string, args?: any[], context?: HookContext): Promise; - hookSeqSync(hook: string, args?: any[], context?: HookContext): void; + hookSeq( + hook: H, + args: Args, + context?: HookContext + ): Promise; + hookSeqSync( + hook: H, + args: Args, + context?: HookContext + ): void; } export type Reduce = (reduction: T, result: R, plugin: Plugin) => T; @@ -268,9 +291,7 @@ export function createPluginDriver( hookSeq(name, args, hookContext) { let promise: Promise = Promise.resolve(); for (let i = 0; i < plugins.length; i++) - promise = promise.then(() => { - return runHook(name, args, i, false, hookContext); - }); + promise = promise.then(() => runHook(name, args, i, false, hookContext)); return promise; }, From e7f79dc90ff2fe335b2d5b7d7004f6dfd8f639ce Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Fri, 26 Apr 2019 07:52:20 +0200 Subject: [PATCH 46/60] Make sure resolveId is always passed either string or null --- src/Graph.ts | 122 +++++++++++------- src/rollup/types.d.ts | 2 +- src/utils/defaultPlugin.ts | 18 +-- src/utils/pluginDriver.ts | 17 ++- .../samples/context-resolve-id/_config.js | 82 ++++++++++++ .../context-resolve-id/existing-name.js | 1 + .../context-resolve-id/existing-object.js | 1 + .../samples/context-resolve-id/main.js | 5 + .../external-entry-point-object/_config.js | 14 ++ .../external-entry-point-object/foo.js | 3 + .../external-entry-point-object/main.js | 7 + .../samples/external-entry-point/_config.js | 14 ++ .../samples/external-entry-point/foo.js | 3 + .../samples/external-entry-point/main.js | 7 + 14 files changed, 226 insertions(+), 70 deletions(-) create mode 100644 test/function/samples/context-resolve-id/_config.js create mode 100644 test/function/samples/context-resolve-id/existing-name.js create mode 100644 test/function/samples/context-resolve-id/existing-object.js create mode 100644 test/function/samples/context-resolve-id/main.js create mode 100644 test/function/samples/external-entry-point-object/_config.js create mode 100644 test/function/samples/external-entry-point-object/foo.js create mode 100644 test/function/samples/external-entry-point-object/main.js create mode 100644 test/function/samples/external-entry-point/_config.js create mode 100644 test/function/samples/external-entry-point/foo.js create mode 100644 test/function/samples/external-entry-point/main.js diff --git a/src/Graph.ts b/src/Graph.ts index ea789caa959..8b8276a9a41 100644 --- a/src/Graph.ts +++ b/src/Graph.ts @@ -383,6 +383,42 @@ export default class Graph { } } + resolveId(importee: string, importer: string, resolveImport: true): Promise; + resolveId(importee: string, importer: string, resolveImport: false): Promise; + resolveId( + importee: string, + importer: string, + resolveImport: boolean + ): Promise { + return Promise.resolve( + this.isExternal(importee, importer, false) + ? { id: importee, external: true } + : this.pluginDriver.hookFirst('resolveId', [importee, importer]) + ) + .then((result: ResolveIdResult) => this.normalizeResolveIdResult(result, importer, importee)) + .then(resolvedId => { + if (resolveImport && resolvedId === null) { + if (isRelative(importee)) { + error({ + code: 'UNRESOLVED_IMPORT', + message: `Could not resolve '${importee}' from ${relativeId(importer)}` + }); + } + this.warn({ + code: 'UNRESOLVED_IMPORT', + importer: relativeId(importer), + message: `'${importee}' is imported by ${relativeId( + importer + )}, but could not be resolved – treating it as an external dependency`, + source: importee, + url: 'https://rollupjs.org/guide/en#warning-treating-module-as-external-dependency' + }); + return { id: normalizeRelativeExternalId(importer, importee), external: true }; + } + return resolvedId; + }); + } + warn(warning: RollupWarning) { warning.toString = () => { let str = ''; @@ -567,6 +603,33 @@ export default class Graph { this.warnForMissingExports(); } + private loadEntryModule(entryName: string) { + return this.pluginDriver + .hookFirst('resolveId', [entryName, undefined]) + .then((resolveIdResult: ResolveIdResult) => { + if ( + resolveIdResult === false || + (resolveIdResult && typeof resolveIdResult === 'object' && resolveIdResult.external) + ) { + error({ + code: 'UNRESOLVED_ENTRY', + message: `Entry module cannot be external` + }); + } + const id = + resolveIdResult && typeof resolveIdResult === 'object' + ? resolveIdResult.id + : resolveIdResult; + if (typeof id === 'string') { + return this.fetchModule(id, undefined); + } + error({ + code: 'UNRESOLVED_ENTRY', + message: `Could not resolve entry (${entryName})` + }); + }); + } + private loadEntryModules( entryModules: string | string[] | Record, manualChunks: Record | void @@ -595,7 +658,7 @@ export default class Graph { }); } - return Promise.all(entryAndManualChunkIds.map(id => this.loadModule(id))).then( + return Promise.all(entryAndManualChunkIds.map(id => this.loadEntryModule(id))).then( entryAndChunkModules => { if (removeAliasExtensions) { for (let i = 0; i < entryModuleAliases.length; i++) @@ -621,31 +684,11 @@ export default class Graph { ); } - private loadModule(entryName: string) { - return this.pluginDriver.hookFirst('resolveId', [entryName, undefined]).then(id => { - if (id === false) { - error({ - code: 'UNRESOLVED_ENTRY', - message: `Entry module cannot be external` - }); - } - - if (id == null) { - error({ - code: 'UNRESOLVED_ENTRY', - message: `Could not resolve entry (${entryName})` - }); - } - - return this.fetchModule(id, undefined); - }); - } - private normalizeResolveIdResult( resolveIdResult: ResolveIdResult, - module: Module, + importer: string, source: string - ): ResolvedId { + ): ResolvedId | null { let id = ''; let external = false; if (resolveIdResult) { @@ -656,45 +699,26 @@ export default class Graph { } } else { id = resolveIdResult; - if (this.isExternal(id, module.id, true)) { + if (this.isExternal(id, importer, true)) { external = true; } } if (external) { - id = normalizeRelativeExternalId(module.id, id); + id = normalizeRelativeExternalId(importer, id); } } else { - id = normalizeRelativeExternalId(module.id, source); - external = true; - if (resolveIdResult !== false && !this.isExternal(id, module.id, true)) { - if (isRelative(source)) { - error({ - code: 'UNRESOLVED_IMPORT', - message: `Could not resolve '${source}' from ${relativeId(module.id)}` - }); - } - this.warn({ - code: 'UNRESOLVED_IMPORT', - importer: relativeId(module.id), - message: `'${source}' is imported by ${relativeId( - module.id - )}, but could not be resolved – treating it as an external dependency`, - source, - url: 'https://rollupjs.org/guide/en#warning-treating-module-as-external-dependency' - }); + id = normalizeRelativeExternalId(importer, source); + if (resolveIdResult !== false && !this.isExternal(id, importer, true)) { + return null; } + external = true; } return { id, external }; } private resolveAndFetchDependency(module: Module, source: string): Promise { return Promise.resolve( - module.resolvedIds[source] || - Promise.resolve( - this.isExternal(source, module.id, false) - ? { id: source, external: true } - : this.pluginDriver.hookFirst('resolveId', [source, module.id]) - ).then((result: ResolveIdResult) => this.normalizeResolveIdResult(result, module, source)) + module.resolvedIds[source] || this.resolveId(source, module.id, true) ).then(resolvedId => { module.resolvedIds[source] = resolvedId; if (resolvedId.external) { diff --git a/src/rollup/types.d.ts b/src/rollup/types.d.ts index 34ea3915cc5..d03df336abf 100644 --- a/src/rollup/types.d.ts +++ b/src/rollup/types.d.ts @@ -117,7 +117,7 @@ export interface PluginContext extends MinimalPluginContext { isExternal: IsExternal; moduleIds: IterableIterator; parse: (input: string, options: any) => ESTree.Program; - resolveId: (id: string, parent: string) => Promise; + resolveId: (id: string, parent: string) => Promise; setAssetSource: (assetId: string, source: string | Buffer) => void; /** @deprecated */ watcher: EventEmitter; diff --git a/src/utils/defaultPlugin.ts b/src/utils/defaultPlugin.ts index b8e4d8e84ba..9e0c9c5ae01 100644 --- a/src/utils/defaultPlugin.ts +++ b/src/utils/defaultPlugin.ts @@ -1,18 +1,18 @@ -import { InputOptions, Plugin } from '../rollup/types'; +import { Plugin } from '../rollup/types'; import { error } from './error'; import { lstatSync, readdirSync, readFileSync, realpathSync } from './fs'; -import { basename, dirname, isAbsolute, resolve } from './path'; +import { basename, dirname, resolve } from './path'; -export function getRollupDefaultPlugin(options: InputOptions): Plugin { +export function getRollupDefaultPlugin(preserveSymlinks: boolean): Plugin { return { name: 'Rollup Core', - resolveId: createResolveId(options), + resolveId: createResolveId(preserveSymlinks), load(id) { return readFileSync(id, 'utf-8'); }, resolveDynamicImport(specifier, parentId) { if (typeof specifier === 'string' && !this.isExternal(specifier, parentId, false)) - return >this.resolveId(specifier, parentId); + return this.resolveId(specifier, parentId); }, resolveAssetUrl({ relativeAssetPath, format }) { return relativeUrlMechanisms[format](relativeAssetPath); @@ -52,7 +52,7 @@ function addJsExtensionIfNecessary(file: string, preserveSymlinks: boolean) { return found; } -function createResolveId(options: InputOptions) { +function createResolveId(preserveSymlinks: boolean) { return function(importee: string, importer: string) { if (typeof process === 'undefined') { error({ @@ -62,17 +62,13 @@ function createResolveId(options: InputOptions) { }); } - // external modules (non-entry modules that start with neither '.' or '/') - // are skipped at this stage. - if (importer !== undefined && !isAbsolute(importee) && importee[0] !== '.') return null; - // `resolve` processes paths from right to left, prepending them until an // absolute path is created. Absolute importees therefore shortcircuit the // resolve call and require no special handing on our part. // See https://nodejs.org/api/path.html#path_path_resolve_paths return addJsExtensionIfNecessary( resolve(importer ? dirname(importer) : resolve(), importee), - options.preserveSymlinks + preserveSymlinks ); }; } diff --git a/src/utils/pluginDriver.ts b/src/utils/pluginDriver.ts index a04ee981bdd..7413bf47fbc 100644 --- a/src/utils/pluginDriver.ts +++ b/src/utils/pluginDriver.ts @@ -8,7 +8,6 @@ import { PluginCache, PluginContext, PluginHooks, - RollupError, RollupWarning, RollupWatcher, SerializablePluginCache @@ -86,7 +85,7 @@ export function createPluginDriver( pluginCache: Record, watcher?: RollupWatcher ): PluginDriver { - const plugins = [...(options.plugins || []), getRollupDefaultPlugin(options)]; + const plugins = [...(options.plugins || []), getRollupDefaultPlugin(options.preserveSymlinks)]; const { emitAsset, getAssetFileName, setAssetSource } = createAssetPluginHooks(graph.assetsById); const existingPluginKeys: NameCollection = {}; @@ -134,24 +133,24 @@ export function createPluginDriver( } const context: PluginContext = { - addWatchFile(id: string) { + addWatchFile(id) { if (graph.finished) this.error('addWatchFile can only be called during the build.'); graph.watchFiles[id] = true; }, cache: cacheInstance, emitAsset, - error: (err: RollupError | string) => { + error: err => { if (typeof err === 'string') err = { message: err }; if (err.code) err.pluginCode = err.code; err.code = 'PLUGIN_ERROR'; err.plugin = plugin.name || `Plugin at position ${pidx + 1}`; error(err); }, - isExternal(id: string, parentId: string, isResolved = false) { + isExternal(id, parentId, isResolved = false) { return graph.isExternal(id, parentId, isResolved); }, getAssetFileName, - getModuleInfo: (moduleId: string) => { + getModuleInfo: moduleId => { const foundModule = graph.moduleById.get(moduleId); if (foundModule == null) { throw new Error(`Unable to find module ${moduleId}`); @@ -170,11 +169,11 @@ export function createPluginDriver( }, moduleIds: graph.moduleById.keys(), parse: graph.contextParse, - resolveId(id: string, parent: string) { - return pluginDriver.hookFirst('resolveId', [id, parent]); + resolveId(id, parent) { + return graph.resolveId(id, parent, false).then(resolveId => resolveId && resolveId.id); }, setAssetSource, - warn: (warning: RollupWarning | string) => { + warn: warning => { if (typeof warning === 'string') warning = { message: warning } as RollupWarning; if (warning.code) warning.pluginCode = warning.code; warning.code = 'PLUGIN_WARNING'; diff --git a/test/function/samples/context-resolve-id/_config.js b/test/function/samples/context-resolve-id/_config.js new file mode 100644 index 00000000000..7cbb4a0bd33 --- /dev/null +++ b/test/function/samples/context-resolve-id/_config.js @@ -0,0 +1,82 @@ +const path = require('path'); +const assert = require('assert'); + +module.exports = { + description: 'correctly returns string or null for the context resolveId helper', + exports(exports) { + assert.deepStrictEqual(exports, { + externalName: 'external name', + externalObject: 'external object', + name: 'existing name', + object: 'existing object', + unresolved: 'unresolved' + }); + }, + context: { + require(id) { + switch (id) { + case 'external-name': + return { value: 'external name' }; + case 'external-object': + return { value: 'external object' }; + case 'resolveto-unresolved': + return { value: 'unresolved' }; + default: + throw new Error(`Unexpected import ${id}`); + } + } + }, + warnings(warnings) { + assert.strictEqual(warnings.length, 1); + assert.strictEqual(warnings[0].code, 'UNRESOLVED_IMPORT'); + }, + options: { + plugins: [ + { + resolveId(id, importer) { + if (id.startsWith('resolveto-')) { + const resolutionId = id.slice('resolveto-'.length); + return this.resolveId(resolutionId, importer).then(resolvedId => { + if (!resolvedId) { + assert.strictEqual(resolutionId, 'unresolved'); + assert.strictEqual(resolvedId, null); + } else { + if (typeof resolvedId !== 'string') { + throw new Error( + `Only valid resolveId return types are string and null, found ${typeof resolvedId} ${JSON.stringify( + resolvedId + )}` + ); + } + return { + id: resolvedId, + external: resolvedId.startsWith('external') + }; + } + }); + } + } + }, + { + resolveId(id) { + switch (id) { + case 'object': + return { + id: path.resolve(__dirname, 'existing-object.js'), + external: false + }; + case 'external-object': + return { + id: 'external-object', + external: true + }; + case 'name': + return path.resolve(__dirname, 'existing-name.js'); + case 'external-name': + return false; + } + } + } + ] + } +}; diff --git a/test/function/samples/context-resolve-id/existing-name.js b/test/function/samples/context-resolve-id/existing-name.js new file mode 100644 index 00000000000..d7aebd0e184 --- /dev/null +++ b/test/function/samples/context-resolve-id/existing-name.js @@ -0,0 +1 @@ +export const value = 'existing name'; diff --git a/test/function/samples/context-resolve-id/existing-object.js b/test/function/samples/context-resolve-id/existing-object.js new file mode 100644 index 00000000000..fb5c62510d0 --- /dev/null +++ b/test/function/samples/context-resolve-id/existing-object.js @@ -0,0 +1 @@ +export const value = 'existing object'; diff --git a/test/function/samples/context-resolve-id/main.js b/test/function/samples/context-resolve-id/main.js new file mode 100644 index 00000000000..2088cffef30 --- /dev/null +++ b/test/function/samples/context-resolve-id/main.js @@ -0,0 +1,5 @@ +export {value as name} from 'resolveto-name'; +export {value as externalName} from 'resolveto-external-name'; +export {value as object} from 'resolveto-object'; +export {value as externalObject} from 'resolveto-external-object'; +export {value as unresolved} from 'resolveto-unresolved'; diff --git a/test/function/samples/external-entry-point-object/_config.js b/test/function/samples/external-entry-point-object/_config.js new file mode 100644 index 00000000000..72bc5d8844a --- /dev/null +++ b/test/function/samples/external-entry-point-object/_config.js @@ -0,0 +1,14 @@ +module.exports = { + description: 'throws for entry points that are resolved as an external object by plugins', + options: { + plugins: { + resolveId(id) { + return { id, external: true }; + } + } + }, + error: { + code: 'UNRESOLVED_ENTRY', + message: 'Entry module cannot be external' + } +}; diff --git a/test/function/samples/external-entry-point-object/foo.js b/test/function/samples/external-entry-point-object/foo.js new file mode 100644 index 00000000000..14d0105c721 --- /dev/null +++ b/test/function/samples/external-entry-point-object/foo.js @@ -0,0 +1,3 @@ +export var foo = function () { + return 42; +} diff --git a/test/function/samples/external-entry-point-object/main.js b/test/function/samples/external-entry-point-object/main.js new file mode 100644 index 00000000000..2a031e5db48 --- /dev/null +++ b/test/function/samples/external-entry-point-object/main.js @@ -0,0 +1,7 @@ +import { foo } from './foo.js'; + +(function bar() { + assert.ok( true ); +})(); + +assert.equal( foo(), 42 ); diff --git a/test/function/samples/external-entry-point/_config.js b/test/function/samples/external-entry-point/_config.js new file mode 100644 index 00000000000..87194245ee0 --- /dev/null +++ b/test/function/samples/external-entry-point/_config.js @@ -0,0 +1,14 @@ +module.exports = { + description: 'throws for entry points that are resolved as false by plugins', + options: { + plugins: { + resolveId() { + return false; + } + } + }, + error: { + code: 'UNRESOLVED_ENTRY', + message: 'Entry module cannot be external' + } +}; diff --git a/test/function/samples/external-entry-point/foo.js b/test/function/samples/external-entry-point/foo.js new file mode 100644 index 00000000000..14d0105c721 --- /dev/null +++ b/test/function/samples/external-entry-point/foo.js @@ -0,0 +1,3 @@ +export var foo = function () { + return 42; +} diff --git a/test/function/samples/external-entry-point/main.js b/test/function/samples/external-entry-point/main.js new file mode 100644 index 00000000000..2a031e5db48 --- /dev/null +++ b/test/function/samples/external-entry-point/main.js @@ -0,0 +1,7 @@ +import { foo } from './foo.js'; + +(function bar() { + assert.ok( true ); +})(); + +assert.equal( foo(), 42 ); From e4157ab003bf3e39fa423941389672a609e0a3c9 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Sat, 27 Apr 2019 18:15:41 +0200 Subject: [PATCH 47/60] Unify parameter names --- src/ModuleLoader.ts | 32 ++++++++++++++++---------------- src/rollup/types.d.ts | 10 +++++----- src/utils/defaultPlugin.ts | 6 +++--- src/utils/pluginDriver.ts | 4 ++-- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/ModuleLoader.ts b/src/ModuleLoader.ts index d8574472f07..ed76e21e98c 100644 --- a/src/ModuleLoader.ts +++ b/src/ModuleLoader.ts @@ -32,8 +32,8 @@ interface UnresolvedEntryModuleWithAlias extends UnresolvedModuleWithAlias { isManualChunkEntry?: boolean; } -function normalizeRelativeExternalId(importee: string, source: string) { - return isRelative(source) ? resolve(importee, '..', source) : source; +function normalizeRelativeExternalId(importer: string, source: string) { + return isRelative(source) ? resolve(importer, '..', source) : source; } export class ModuleLoader { @@ -149,37 +149,37 @@ export class ModuleLoader { return fileName; } - resolveId(importee: string, importer: string, resolveImport: true): Promise; - resolveId(importee: string, importer: string, resolveImport: false): Promise; + resolveId(source: string, importer: string, resolveImport: true): Promise; + resolveId(source: string, importer: string, resolveImport: false): Promise; resolveId( - importee: string, + source: string, importer: string, - resolveImport: boolean + forceResolveImport: boolean ): Promise { return Promise.resolve( - this.isExternal(importee, importer, false) - ? { id: importee, external: true } - : this.pluginDriver.hookFirst('resolveId', [importee, importer]) + this.isExternal(source, importer, false) + ? { id: source, external: true } + : this.pluginDriver.hookFirst('resolveId', [source, importer]) ) - .then((result: ResolveIdResult) => this.normalizeResolveIdResult(result, importer, importee)) + .then((result: ResolveIdResult) => this.normalizeResolveIdResult(result, importer, source)) .then(resolvedId => { - if (resolveImport && resolvedId === null) { - if (isRelative(importee)) { + if (forceResolveImport && resolvedId === null) { + if (isRelative(source)) { error({ code: 'UNRESOLVED_IMPORT', - message: `Could not resolve '${importee}' from ${relativeId(importer)}` + message: `Could not resolve '${source}' from ${relativeId(importer)}` }); } this.graph.warn({ code: 'UNRESOLVED_IMPORT', importer: relativeId(importer), - message: `'${importee}' is imported by ${relativeId( + message: `'${source}' is imported by ${relativeId( importer )}, but could not be resolved – treating it as an external dependency`, - source: importee, + source, url: 'https://rollupjs.org/guide/en#warning-treating-module-as-external-dependency' }); - return { id: normalizeRelativeExternalId(importer, importee), external: true }; + return { id: source, external: true }; } return resolvedId; }); diff --git a/src/rollup/types.d.ts b/src/rollup/types.d.ts index 72680fab586..2f0197570e3 100644 --- a/src/rollup/types.d.ts +++ b/src/rollup/types.d.ts @@ -124,7 +124,7 @@ export interface PluginContext extends MinimalPluginContext { isExternal: IsExternal; moduleIds: IterableIterator; parse: (input: string, options: any) => ESTree.Program; - resolveId: (id: string, parent: string) => Promise; + resolveId: (source: string, importer: string) => Promise; setAssetSource: (assetReferenceId: string, source: string | Buffer) => void; warn: (warning: RollupWarning | string, pos?: { column: number; line: number }) => void; /** @deprecated */ @@ -148,11 +148,11 @@ export interface ResolvedIdMap { export type ResolveIdHook = ( this: PluginContext, - id: string, - parent: string + source: string, + importer: string ) => Promise | ResolveIdResult; -export type IsExternal = (id: string, parentId: string, isResolved: boolean) => boolean | void; +export type IsExternal = (source: string, importer: string, isResolved: boolean) => boolean | void; export type LoadHook = ( this: PluginContext, @@ -194,7 +194,7 @@ export type RenderChunkHook = ( export type ResolveDynamicImportHook = ( this: PluginContext, specifier: string | ESTree.Node, - parentId: string + importer: string ) => Promise | string | void; export type ResolveImportMetaHook = ( diff --git a/src/utils/defaultPlugin.ts b/src/utils/defaultPlugin.ts index d79f513cf0f..df97f9b41bd 100644 --- a/src/utils/defaultPlugin.ts +++ b/src/utils/defaultPlugin.ts @@ -54,7 +54,7 @@ function addJsExtensionIfNecessary(file: string, preserveSymlinks: boolean) { } function createResolveId(preserveSymlinks: boolean) { - return function(importee: string, importer: string) { + return function(source: string, importer: string) { if (typeof process === 'undefined') { error({ code: 'MISSING_PROCESS', @@ -65,14 +65,14 @@ function createResolveId(preserveSymlinks: boolean) { // external modules (non-entry modules that start with neither '.' or '/') // are skipped at this stage. - if (importer !== undefined && !isAbsolute(importee) && importee[0] !== '.') return null; + if (importer !== undefined && !isAbsolute(source) && source[0] !== '.') return null; // `resolve` processes paths from right to left, prepending them until an // absolute path is created. Absolute importees therefore shortcircuit the // resolve call and require no special handing on our part. // See https://nodejs.org/api/path.html#path_path_resolve_paths return addJsExtensionIfNecessary( - resolve(importer ? dirname(importer) : resolve(), importee), + resolve(importer ? dirname(importer) : resolve(), source), preserveSymlinks ); }; diff --git a/src/utils/pluginDriver.ts b/src/utils/pluginDriver.ts index e165599edf3..38df25bad6c 100644 --- a/src/utils/pluginDriver.ts +++ b/src/utils/pluginDriver.ts @@ -189,9 +189,9 @@ export function createPluginDriver( }, moduleIds: graph.moduleById.keys(), parse: graph.contextParse, - resolveId(id, parent) { + resolveId(source, importer) { return graph.moduleLoader - .resolveId(id, parent, false) + .resolveId(source, importer, false) .then(resolveId => resolveId && resolveId.id); }, setAssetSource, From ab0f13f6c89e2ebd251eb8fb417a7ac899df8242 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Sun, 28 Apr 2019 11:55:09 +0200 Subject: [PATCH 48/60] Add new this.resolve context function --- docs/05-plugins.md | 3 + src/rollup/types.d.ts | 9 +- src/utils/pluginDriver.ts | 3 + .../samples/context-resolve-id/_config.js | 9 -- .../samples/context-resolve-id/main.js | 16 +++- .../samples/context-resolve/_config.js | 96 +++++++++++++++++++ .../samples/context-resolve/existing.js | 1 + test/function/samples/context-resolve/main.js | 3 + 8 files changed, 123 insertions(+), 17 deletions(-) create mode 100644 test/function/samples/context-resolve/_config.js create mode 100644 test/function/samples/context-resolve/existing.js create mode 100644 test/function/samples/context-resolve/main.js diff --git a/docs/05-plugins.md b/docs/05-plugins.md index 02fd63874e0..71107986412 100644 --- a/docs/05-plugins.md +++ b/docs/05-plugins.md @@ -394,6 +394,9 @@ or converted into an Array via `Array.from(this.moduleIds)`. Use Rollup's internal acorn instance to parse code to an AST. +#### `this.resolve(importee: string, importer: string) => Promise<{id: string, external: boolean} | null>` +Resolve imports to module ids (i.e. file names) using the same plugins that Rollup uses, and determine if an import should be external. If `null` is returned, the import could not be resolved by Rollup or any plugin but was not explicitly marked as external by the user. + #### `this.resolveId(importee: string, importer: string) => Promise` Resolve imports to module ids (i.e. file names) using the same plugins that Rollup uses. Returns `null` if an id cannot be resolved. diff --git a/src/rollup/types.d.ts b/src/rollup/types.d.ts index 2f0197570e3..1ac38c59676 100644 --- a/src/rollup/types.d.ts +++ b/src/rollup/types.d.ts @@ -124,6 +124,7 @@ export interface PluginContext extends MinimalPluginContext { isExternal: IsExternal; moduleIds: IterableIterator; parse: (input: string, options: any) => ESTree.Program; + resolve: (source: string, importer: string) => Promise; resolveId: (source: string, importer: string) => Promise; setAssetSource: (assetReferenceId: string, source: string | Buffer) => void; warn: (warning: RollupWarning | string, pos?: { column: number; line: number }) => void; @@ -136,16 +137,18 @@ export interface PluginContextMeta { } export interface ResolvedId { - external?: boolean | void; + external: boolean; id: string; } -export type ResolveIdResult = string | false | void | ResolvedId; - export interface ResolvedIdMap { [key: string]: ResolvedId; } +type PartialResolvedId = Partial & { id: string }; + +export type ResolveIdResult = string | false | void | PartialResolvedId; + export type ResolveIdHook = ( this: PluginContext, source: string, diff --git a/src/utils/pluginDriver.ts b/src/utils/pluginDriver.ts index 38df25bad6c..0258a27e7b5 100644 --- a/src/utils/pluginDriver.ts +++ b/src/utils/pluginDriver.ts @@ -194,6 +194,9 @@ export function createPluginDriver( .resolveId(source, importer, false) .then(resolveId => resolveId && resolveId.id); }, + resolve(source, importer) { + return graph.moduleLoader.resolveId(source, importer, false); + }, setAssetSource, warn(warning) { if (typeof warning === 'string') warning = { message: warning } as RollupWarning; diff --git a/test/function/samples/context-resolve-id/_config.js b/test/function/samples/context-resolve-id/_config.js index 7cbb4a0bd33..cef41520d15 100644 --- a/test/function/samples/context-resolve-id/_config.js +++ b/test/function/samples/context-resolve-id/_config.js @@ -3,15 +3,6 @@ const assert = require('assert'); module.exports = { description: 'correctly returns string or null for the context resolveId helper', - exports(exports) { - assert.deepStrictEqual(exports, { - externalName: 'external name', - externalObject: 'external object', - name: 'existing name', - object: 'existing object', - unresolved: 'unresolved' - }); - }, context: { require(id) { switch (id) { diff --git a/test/function/samples/context-resolve-id/main.js b/test/function/samples/context-resolve-id/main.js index 2088cffef30..188a3921e2e 100644 --- a/test/function/samples/context-resolve-id/main.js +++ b/test/function/samples/context-resolve-id/main.js @@ -1,5 +1,11 @@ -export {value as name} from 'resolveto-name'; -export {value as externalName} from 'resolveto-external-name'; -export {value as object} from 'resolveto-object'; -export {value as externalObject} from 'resolveto-external-object'; -export {value as unresolved} from 'resolveto-unresolved'; +import { value as name } from 'resolveto-name'; +import { value as externalName } from 'resolveto-external-name'; +import { value as object } from 'resolveto-object'; +import { value as externalObject } from 'resolveto-external-object'; +import { value as unresolved } from 'resolveto-unresolved'; + +assert.strictEqual(externalName, 'external name'); +assert.strictEqual(externalObject, 'external object'); +assert.strictEqual(name, 'existing name'); +assert.strictEqual(object, 'existing object'); +assert.strictEqual(unresolved, 'unresolved'); diff --git a/test/function/samples/context-resolve/_config.js b/test/function/samples/context-resolve/_config.js new file mode 100644 index 00000000000..8a6d1eff991 --- /dev/null +++ b/test/function/samples/context-resolve/_config.js @@ -0,0 +1,96 @@ +const path = require('path'); +const assert = require('assert'); + +const tests = [ + { + source: './existing', + expected: { id: path.resolve(__dirname, 'existing.js'), external: false } + }, + { + source: './missing-relative', + expected: null + }, + { + source: 'missing-absolute', + expected: null + }, + { + source: './marked-directly-external-relative', + expected: { id: path.resolve(__dirname, 'marked-directly-external-relative'), external: true } + }, + { + source: './marked-external-relative', + expected: { id: path.resolve(__dirname, 'marked-external-relative'), external: true } + }, + { + source: 'marked-external-absolute', + expected: { id: 'marked-external-absolute', external: true } + }, + { + source: 'resolved-name', + expected: { id: 'resolved:resolved-name', external: false } + }, + { + source: 'resolved-false', + expected: { id: 'resolved-false', external: true } + }, + { + source: 'resolved-object', + expected: { id: 'resolved:resolved-object', external: false } + }, + { + source: 'resolved-object-non-external', + expected: { id: 'resolved:resolved-object-non-external', external: false } + }, + { + source: 'resolved-object-external', + expected: { id: 'resolved:resolved-object-external', external: true } + } +]; + +module.exports = { + description: 'returns the correct results for the context resolve helper', + options: { + external: [ + 'marked-external-absolute', + './marked-directly-external-relative', + path.resolve(__dirname, 'marked-external-relative') + ], + plugins: [ + { + resolveId(id) { + if (id === 'resolutions') { + return id; + } + }, + load(id) { + if (id === 'resolutions') { + return Promise.all( + tests.map(({ source, expected }) => + this.resolve(source, path.resolve(__dirname, 'main.js')).then(resolution => + assert.deepStrictEqual(resolution, expected) + ) + ) + ).then(result => `export default ${result.length}`); + } + } + }, + { + resolveId(id) { + switch (id) { + case 'resolved-name': + return 'resolved:resolved-name'; + case 'resolved-false': + return false; + case 'resolved-object': + return { id: 'resolved:resolved-object' }; + case 'resolved-object-non-external': + return { id: 'resolved:resolved-object-non-external', external: false }; + case 'resolved-object-external': + return { id: 'resolved:resolved-object-external', external: true }; + } + } + } + ] + } +}; diff --git a/test/function/samples/context-resolve/existing.js b/test/function/samples/context-resolve/existing.js new file mode 100644 index 00000000000..9486260537f --- /dev/null +++ b/test/function/samples/context-resolve/existing.js @@ -0,0 +1 @@ +console.log('existing'); diff --git a/test/function/samples/context-resolve/main.js b/test/function/samples/context-resolve/main.js new file mode 100644 index 00000000000..b97e429539e --- /dev/null +++ b/test/function/samples/context-resolve/main.js @@ -0,0 +1,3 @@ +import resolutions from 'resolutions'; + +assert.strictEqual(resolutions,11); From 35944c0b2e8b159f0200ded88f48ca8d868ebb7f Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Mon, 29 Apr 2019 07:13:35 +0200 Subject: [PATCH 49/60] Get rid of dynamic import alias --- src/Module.ts | 3 +-- src/ModuleLoader.ts | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Module.ts b/src/Module.ts index b0c82fcb352..f96737ce7cc 100644 --- a/src/Module.ts +++ b/src/Module.ts @@ -172,7 +172,6 @@ export default class Module { dynamicallyImportedBy: Module[] = []; dynamicDependencies: (Module | ExternalModule)[] = []; dynamicImports: { - alias: string | null; node: Import; resolution: Module | ExternalModule | string | void; }[] = []; @@ -613,7 +612,7 @@ export default class Module { } private addDynamicImport(node: Import) { - this.dynamicImports.push({ node, alias: undefined, resolution: undefined }); + this.dynamicImports.push({ node, resolution: undefined }); } private addExport( diff --git a/src/ModuleLoader.ts b/src/ModuleLoader.ts index ed76e21e98c..60bca0a766f 100644 --- a/src/ModuleLoader.ts +++ b/src/ModuleLoader.ts @@ -19,7 +19,7 @@ import { import { isRelative, resolve } from './utils/path'; import { PluginDriver } from './utils/pluginDriver'; import { addWithNewReferenceId } from './utils/referenceIds'; -import relativeId, { getAliasName } from './utils/relativeId'; +import relativeId from './utils/relativeId'; import { timeEnd, timeStart } from './utils/timers'; import transform from './utils/transform'; @@ -215,7 +215,6 @@ export class ModuleLoader { .then((replacement: string | void) => { if (!replacement) return; const dynamicImport = module.dynamicImports[index]; - dynamicImport.alias = getAliasName(replacement); if (typeof dynamicImportExpression !== 'string') { dynamicImport.resolution = replacement; } else if (this.isExternal(replacement, module.id, true)) { From 125547e4256922cdcd0fee3041f2b2b5a73f8744 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Wed, 1 May 2019 09:31:12 +0200 Subject: [PATCH 50/60] Make sure resolveDynamicImport behaves the same as resolveId if an object is returned --- docs/05-plugins.md | 43 ++-- src/Chunk.ts | 28 ++- src/ModuleLoader.ts | 200 ++++++++++-------- src/rollup/index.ts | 5 +- src/rollup/types.d.ts | 3 +- src/utils/defaultPlugin.ts | 5 - src/utils/pluginDriver.ts | 10 +- .../_expected/amd/main.js | 2 +- .../_expected/amd/main.js | 2 +- .../dynamic-import-name/_expected/amd/main.js | 2 +- .../samples/resolve-dynamic-import/_config.js | 76 +++++++ .../_expected/amd/generated-existing.js | 7 + .../_expected/amd/main.js | 22 ++ .../_expected/cjs/generated-existing.js | 5 + .../_expected/cjs/main.js | 26 +++ .../_expected/es/generated-existing.js | 3 + .../_expected/es/main.js | 24 +++ .../_expected/system/generated-existing.js | 10 + .../_expected/system/main.js | 28 +++ .../resolve-dynamic-import/existing.js | 1 + .../samples/resolve-dynamic-import/main.js | 19 ++ .../resolve-dynamic-import/nested/nested.js | 6 + .../_config.js | 2 +- 23 files changed, 399 insertions(+), 130 deletions(-) create mode 100644 test/chunking-form/samples/resolve-dynamic-import/_config.js create mode 100644 test/chunking-form/samples/resolve-dynamic-import/_expected/amd/generated-existing.js create mode 100644 test/chunking-form/samples/resolve-dynamic-import/_expected/amd/main.js create mode 100644 test/chunking-form/samples/resolve-dynamic-import/_expected/cjs/generated-existing.js create mode 100644 test/chunking-form/samples/resolve-dynamic-import/_expected/cjs/main.js create mode 100644 test/chunking-form/samples/resolve-dynamic-import/_expected/es/generated-existing.js create mode 100644 test/chunking-form/samples/resolve-dynamic-import/_expected/es/main.js create mode 100644 test/chunking-form/samples/resolve-dynamic-import/_expected/system/generated-existing.js create mode 100644 test/chunking-form/samples/resolve-dynamic-import/_expected/system/main.js create mode 100644 test/chunking-form/samples/resolve-dynamic-import/existing.js create mode 100644 test/chunking-form/samples/resolve-dynamic-import/main.js create mode 100644 test/chunking-form/samples/resolve-dynamic-import/nested/nested.js diff --git a/docs/05-plugins.md b/docs/05-plugins.md index 71107986412..57a887f2d8f 100644 --- a/docs/05-plugins.md +++ b/docs/05-plugins.md @@ -19,9 +19,9 @@ The following plugin will intercept any imports of `virtual-module` without acce export default function myExample () { return { name: 'my-example', // this name will show up in warnings and errors - resolveId ( importee ) { - if (importee === 'virtual-module') { - return importee; // this signals that rollup should not ask other plugins or check the file system to find this id + resolveId ( source ) { + if (source === 'virtual-module') { + return source; // this signals that rollup should not ask other plugins or check the file system to find this id } return null; // other ids should be handled as usually }, @@ -208,22 +208,29 @@ resolveAssetUrl({assetFileName}) { Type: `(specifier: string | ESTree.Node, importer: string) => string | false | null | {id: string, external?: boolean}`
Kind: `async, first` -Defines a custom resolver for dynamic imports. In case a dynamic import is not passed a string as argument, this hook gets access to the raw AST nodes to analyze. Returning `null` will defer to other resolvers and eventually to `resolveId` if this is possible; returning `false` signals that the import should be kept as it is and not be passed to other resolvers thus making it external. Similar to the [`resolveId`](guide/en#resolveid) hook, you can also return an object to resolve the import to a different id while marking it as external at the same time. +Defines a custom resolver for dynamic imports. Returning `false` signals that the import should be kept as it is and not be passed to other resolvers thus making it external. Similar to the [`resolveId`](guide/en#resolveid) hook, you can also return an object to resolve the import to a different id while marking it as external at the same time. -Note that the return value of this hook will not be passed to `resolveId` afterwards; if you need access to the static resolution algorithm, you can use [`this.resolveId(importee, importer)`](guide/en#this-resolveid-importee-string-importer-string-string-null) on the plugin context. +In case a dynamic import is passed a string as argument, a string returned from this hook will be interpreted as an existing module id while returning `null` will defer to other resolvers and eventually to `resolveId` . + +In case a dynamic import is not passed a string as argument, this hook gets access to the raw AST nodes to analyze and behaves slightly different in the following ways: +- If all plugins return `null`, the import is treated as `external` without a warning. +- If a string is returned, this string is *not* interpreted as a module id but is instead used as a replacement for the import argument. It is the responsibility of the plugin to make sure the generated code is valid. +- To resolve such an import to an existing module, you can still return an object `{id, external}`. + +Note that the return value of this hook will not be passed to `resolveId` afterwards; if you need access to the static resolution algorithm, you can use [`this.resolve(source, importer)`](guide/en#this-resolve-source-string-importer-string-promise-id-string-external-boolean-null) on the plugin context. #### `resolveId` -Type: `(importee: string, importer: string) => string | false | null | {id: string, external?: boolean}`
+Type: `(source: string, importer: string) => string | false | null | {id: string, external?: boolean}`
Kind: `async, first` -Defines a custom resolver. A resolver can be useful for e.g. locating third-party dependencies. Returning `null` defers to other `resolveId` functions (and eventually the default resolution behavior); returning `false` signals that `importee` should be treated as an external module and not included in the bundle. +Defines a custom resolver. A resolver can be useful for e.g. locating third-party dependencies. Returning `null` defers to other `resolveId` functions (and eventually the default resolution behavior); returning `false` signals that `source` should be treated as an external module and not included in the bundle. If you return an object, then it is possible to resolve an import to a different id while excluding it from the bundle at the same time. This allows you to replace dependencies with external dependencies without the need for the user to mark them as "external" manually via the `external` option: ```js -resolveId(id) { - if (id === 'my-dependency') { - return {id: 'my-dependency-develop', external: true}; +resolveId(source) { + if (source === 'my-dependency') { + return {source: 'my-dependency-develop', external: true}; } return null; } @@ -394,10 +401,10 @@ or converted into an Array via `Array.from(this.moduleIds)`. Use Rollup's internal acorn instance to parse code to an AST. -#### `this.resolve(importee: string, importer: string) => Promise<{id: string, external: boolean} | null>` +#### `this.resolve(source: string, importer: string) => Promise<{id: string, external: boolean} | null>` Resolve imports to module ids (i.e. file names) using the same plugins that Rollup uses, and determine if an import should be external. If `null` is returned, the import could not be resolved by Rollup or any plugin but was not explicitly marked as external by the user. -#### `this.resolveId(importee: string, importer: string) => Promise` +#### `this.resolveId(source: string, importer: string) => Promise` Resolve imports to module ids (i.e. file names) using the same plugins that Rollup uses. Returns `null` if an id cannot be resolved. @@ -431,9 +438,9 @@ The following example will detect imports of `.svg` files, emit the imported fil // plugin export default function svgResolverPlugin () { return ({ - resolveId(id, importee) { - if (id.endsWith('.svg')) { - return path.resolve(path.dirname(importee), id); + resolveId(source, importer) { + if (source.endsWith('.svg')) { + return path.resolve(path.dirname(importer), source); } }, load(id) { @@ -473,11 +480,11 @@ export default function paintWorkletPlugin () { )});`; } }, - resolveId(id, importee) { + resolveId(source, importer) { // We remove the prefix, resolve everything to absolute ids and add the prefix again // This makes sure that you can use relative imports to define worklets - if (id.startsWith(REGISTER_WORKLET)) { - return this.resolveId(id.slice(REGISTER_WORKLET.length), importee).then( + if (source.startsWith(REGISTER_WORKLET)) { + return this.resolveId(source.slice(REGISTER_WORKLET.length), importer).then( id => REGISTER_WORKLET + id ); } diff --git a/src/Chunk.ts b/src/Chunk.ts index 5eeff82240f..f6df6ad2ba6 100644 --- a/src/Chunk.ts +++ b/src/Chunk.ts @@ -557,8 +557,10 @@ export default class Chunk { }); } + this.setExternalRenderPaths(options, inputBase); + this.renderedDeclarations = { - dependencies: this.getChunkDependencyDeclarations(options, inputBase), + dependencies: this.getChunkDependencyDeclarations(options), exports: this.exportMode === 'none' ? [] : this.getChunkExportDeclarations() }; @@ -802,7 +804,12 @@ export default class Chunk { node.renderFinalResolution(code, `'${relPath}'`, format); } } else if (resolution instanceof ExternalModule) { - node.renderFinalResolution(code, `'${resolution.id}'`, format); + let resolutionId = resolution.id; + if (resolution.renormalizeRenderPath) { + resolutionId = normalize(relative(dirname(this.id), resolution.renderPath)); + if (!resolutionId.startsWith('../')) resolutionId = './' + resolutionId; + } + node.renderFinalResolution(code, `'${resolutionId}'`, format); } else { node.renderFinalResolution(code, resolution, format); } @@ -826,10 +833,7 @@ export default class Chunk { return needsAmdModule; } - private getChunkDependencyDeclarations( - options: OutputOptions, - inputBase: string - ): ChunkDependencies { + private getChunkDependencyDeclarations(options: OutputOptions): ChunkDependencies { const reexportDeclarations = new Map(); for (let exportName of this.getExportNames()) { @@ -902,7 +906,7 @@ export default class Chunk { let id: string; let globalName: string; if (dep instanceof ExternalModule) { - id = dep.setRenderPath(options, inputBase); + id = dep.renderPath; if (options.format === 'umd' || options.format === 'iife') { globalName = getGlobalName( dep, @@ -1012,7 +1016,7 @@ export default class Chunk { node.setResolution(false); } } else if (resolution instanceof ExternalModule) { - node.setResolution(true); + node.setResolution(false); } else { node.setResolution(false); } @@ -1020,6 +1024,14 @@ export default class Chunk { } } + private setExternalRenderPaths(options: OutputOptions, inputBase: string) { + for (const dependency of this.dependencies.concat(this.dynamicDependencies)) { + if (dependency instanceof ExternalModule) { + dependency.setRenderPath(options, inputBase); + } + } + } + private setIdentifierRenderResolutions(options: OutputOptions) { for (const exportName of this.getExportNames()) { const exportVariable = this.exportNames[exportName]; diff --git a/src/ModuleLoader.ts b/src/ModuleLoader.ts index 60bca0a766f..9e1c1d9edc1 100644 --- a/src/ModuleLoader.ts +++ b/src/ModuleLoader.ts @@ -149,40 +149,12 @@ export class ModuleLoader { return fileName; } - resolveId(source: string, importer: string, resolveImport: true): Promise; - resolveId(source: string, importer: string, resolveImport: false): Promise; - resolveId( - source: string, - importer: string, - forceResolveImport: boolean - ): Promise { + resolveId(source: string, importer: string): Promise { return Promise.resolve( this.isExternal(source, importer, false) ? { id: source, external: true } : this.pluginDriver.hookFirst('resolveId', [source, importer]) - ) - .then((result: ResolveIdResult) => this.normalizeResolveIdResult(result, importer, source)) - .then(resolvedId => { - if (forceResolveImport && resolvedId === null) { - if (isRelative(source)) { - error({ - code: 'UNRESOLVED_IMPORT', - message: `Could not resolve '${source}' from ${relativeId(importer)}` - }); - } - this.graph.warn({ - code: 'UNRESOLVED_IMPORT', - importer: relativeId(importer), - message: `'${source}' is imported by ${relativeId( - importer - )}, but could not be resolved – treating it as an external dependency`, - source, - url: 'https://rollupjs.org/guide/en#warning-treating-module-as-external-dependency' - }); - return { id: source, external: true }; - } - return resolvedId; - }); + ).then((result: ResolveIdResult) => this.normalizeResolveIdResult(result, importer, source)); } private awaitLoadModulesPromise(loadNewModulesPromise: Promise): Promise { @@ -205,37 +177,22 @@ export class ModuleLoader { private fetchAllDependencies(module: Module) { const fetchDynamicImportsPromise = Promise.all( - module.getDynamicImportExpressions().map((dynamicImportExpression, index) => - // TODO we only should expose the acorn AST here - this.pluginDriver - .hookFirst('resolveDynamicImport', [ - dynamicImportExpression as string | ESTree.Node, - module.id - ]) - .then((replacement: string | void) => { - if (!replacement) return; - const dynamicImport = module.dynamicImports[index]; - if (typeof dynamicImportExpression !== 'string') { - dynamicImport.resolution = replacement; - } else if (this.isExternal(replacement, module.id, true)) { - let externalModule; - if (!this.modulesById.has(replacement)) { - externalModule = new ExternalModule({ - graph: this.graph, - id: replacement - }); - this.modulesById.set(replacement, module); - } else { - externalModule = this.modulesById.get(replacement); - } - dynamicImport.resolution = externalModule; - externalModule.exportsNamespace = true; - } else { - return this.fetchModule(replacement, module.id).then(depModule => { - dynamicImport.resolution = depModule; - }); - } - }) + module.getDynamicImportExpressions().map((specifier, index) => + this.resolveDynamicImport(specifier as string | ESTree.Node, module.id).then(resolvedId => { + if (resolvedId === null) return; + const dynamicImport = module.dynamicImports[index]; + if (typeof resolvedId === 'string') { + dynamicImport.resolution = resolvedId; + return; + } + return this.fetchResolvedDependency( + relativeId(resolvedId.id), + module.id, + resolvedId + ).then(module => { + dynamicImport.resolution = module; + }); + }) ) ); fetchDynamicImportsPromise.catch(() => {}); @@ -345,12 +302,66 @@ export class ModuleLoader { }); } + private fetchResolvedDependency( + source: string, + importer: string, + resolvedId: ResolvedId + ): Promise { + if (resolvedId.external) { + if (!this.modulesById.has(resolvedId.id)) { + this.modulesById.set( + resolvedId.id, + new ExternalModule({ graph: this.graph, id: resolvedId.id }) + ); + } + + const externalModule = this.modulesById.get(resolvedId.id); + if (externalModule instanceof ExternalModule === false) { + error({ + code: 'INVALID_EXTERNAL_ID', + message: `'${source}' is imported as an external by ${relativeId( + importer + )}, but is already an existing non-external module id.` + }); + } + return Promise.resolve(externalModule); + } else { + return this.fetchModule(resolvedId.id, importer); + } + } + + private handleMissingImports( + resolvedId: ResolvedId | null, + source: string, + importer: string + ): ResolvedId { + if (resolvedId === null) { + if (isRelative(source)) { + error({ + code: 'UNRESOLVED_IMPORT', + message: `Could not resolve '${source}' from ${relativeId(importer)}` + }); + } + this.graph.warn({ + code: 'UNRESOLVED_IMPORT', + importer: relativeId(importer), + message: `'${source}' is imported by ${relativeId( + importer + )}, but could not be resolved – treating it as an external dependency`, + source, + url: 'https://rollupjs.org/guide/en#warning-treating-module-as-external-dependency' + }); + return { id: source, external: true }; + } + return resolvedId; + } + private loadEntryModule = ({ alias, unresolvedId, isManualChunkEntry - }: UnresolvedEntryModuleWithAlias): Promise => { - return this.pluginDriver + }: UnresolvedEntryModuleWithAlias): Promise => + this.pluginDriver .hookFirst('resolveId', [unresolvedId, undefined]) .then((resolveIdResult: ResolveIdResult) => { if ( @@ -390,7 +401,6 @@ export class ModuleLoader { message: `Could not resolve entry (${unresolvedId})` }); }); - }; private normalizeResolveIdResult( resolveIdResult: ResolveIdResult, @@ -424,31 +434,51 @@ export class ModuleLoader { return { id, external }; } - private resolveAndFetchDependency(module: Module, source: string): Promise { + private resolveAndFetchDependency( + module: Module, + source: string + ): Promise { return Promise.resolve( - module.resolvedIds[source] || this.resolveId(source, module.id, true) + module.resolvedIds[source] || + this.resolveId(source, module.id).then(resolvedId => + this.handleMissingImports(resolvedId, source, module.id) + ) ).then(resolvedId => { module.resolvedIds[source] = resolvedId; - if (resolvedId.external) { - if (!this.modulesById.has(resolvedId.id)) { - this.modulesById.set( - resolvedId.id, - new ExternalModule({ graph: this.graph, id: resolvedId.id }) - ); - } + return this.fetchResolvedDependency(source, module.id, resolvedId); + }); + } - const externalModule = this.modulesById.get(resolvedId.id); - if (externalModule instanceof ExternalModule === false) { - error({ - code: 'INVALID_EXTERNAL_ID', - message: `'${source}' is imported as an external by ${relativeId( - module.id - )}, but is already an existing non-external module id.` - }); + private resolveDynamicImport( + specifier: string | ESTree.Node, + importer: string + ): Promise { + // TODO we only should expose the acorn AST here + return this.pluginDriver + .hookFirst('resolveDynamicImport', [specifier, importer]) + .then((resolution: ResolveIdResult) => { + if (typeof specifier !== 'string') { + if (typeof resolution === 'string') { + return resolution; + } + if (!resolution) { + return null; + } + return { + external: false, + ...resolution + }; } - } else { - return this.fetchModule(resolvedId.id, module.id); - } - }); + if (resolution == null) { + return this.resolveId(specifier, importer).then(resolvedId => + this.handleMissingImports(resolvedId, specifier, importer) + ); + } + return this.handleMissingImports( + this.normalizeResolveIdResult(resolution, importer, specifier), + specifier, + importer + ); + }); } } diff --git a/src/rollup/index.ts b/src/rollup/index.ts index f35cf6aca88..4a40443f850 100644 --- a/src/rollup/index.ts +++ b/src/rollup/index.ts @@ -433,9 +433,8 @@ function normalizeOutputOptions( // now outputOptions is an array, but rollup.rollup API doesn't support arrays const mergedOutputOptions = mergedOptions.outputOptions[0]; - const outputOptionsReducer = (outputOptions: OutputOptions, result: OutputOptions) => { - return result || outputOptions; - }; + const outputOptionsReducer = (outputOptions: OutputOptions, result: OutputOptions) => + result || outputOptions; const outputOptions = pluginDriver.hookReduceArg0Sync( 'outputOptions', [mergedOutputOptions], diff --git a/src/rollup/types.d.ts b/src/rollup/types.d.ts index 1ac38c59676..f1c60625d92 100644 --- a/src/rollup/types.d.ts +++ b/src/rollup/types.d.ts @@ -193,12 +193,11 @@ export type RenderChunkHook = ( | string | null; -// TODO this should probably return ResolveIdResult export type ResolveDynamicImportHook = ( this: PluginContext, specifier: string | ESTree.Node, importer: string -) => Promise | string | void; +) => Promise | ResolveIdResult; export type ResolveImportMetaHook = ( this: PluginContext, diff --git a/src/utils/defaultPlugin.ts b/src/utils/defaultPlugin.ts index df97f9b41bd..f447699ff2e 100644 --- a/src/utils/defaultPlugin.ts +++ b/src/utils/defaultPlugin.ts @@ -10,11 +10,6 @@ export function getRollupDefaultPlugin(preserveSymlinks: boolean): Plugin { load(id) { return readFileSync(id, 'utf-8'); }, - resolveDynamicImport(specifier, parentId) { - if (typeof specifier === 'string' && !this.isExternal(specifier, parentId, false)) - // TODO this typecast will cause problems if resolveId returns false or an object - return this.resolveId(specifier, parentId); - }, resolveFileUrl({ relativePath, format }) { return relativeUrlMechanisms[format](relativePath); }, diff --git a/src/utils/pluginDriver.ts b/src/utils/pluginDriver.ts index 0258a27e7b5..02a7b328efb 100644 --- a/src/utils/pluginDriver.ts +++ b/src/utils/pluginDriver.ts @@ -191,11 +191,11 @@ export function createPluginDriver( parse: graph.contextParse, resolveId(source, importer) { return graph.moduleLoader - .resolveId(source, importer, false) + .resolveId(source, importer) .then(resolveId => resolveId && resolveId.id); }, resolve(source, importer) { - return graph.moduleLoader.resolveId(source, importer, false); + return graph.moduleLoader.resolveId(source, importer); }, setAssetSource, warn(warning) { @@ -363,9 +363,9 @@ export function createPluginDriver( promise = promise.then(arg0 => { const hookPromise = runHook(name, [arg0, ...args], i, false, hookContext); if (!hookPromise) return arg0; - return hookPromise.then((result: any) => { - return reduce.call(pluginContexts[i], arg0, result, plugins[i]); - }); + return hookPromise.then((result: any) => + reduce.call(pluginContexts[i], arg0, result, plugins[i]) + ); }); } return promise; diff --git a/test/chunking-form/samples/dynamic-import-comments/_expected/amd/main.js b/test/chunking-form/samples/dynamic-import-comments/_expected/amd/main.js index 6e19fb3714f..5d7a227c6c1 100644 --- a/test/chunking-form/samples/dynamic-import-comments/_expected/amd/main.js +++ b/test/chunking-form/samples/dynamic-import-comments/_expected/amd/main.js @@ -2,6 +2,6 @@ define(['require'], function (require) { 'use strict'; new Promise(function (resolve, reject) { require([ /* webpackChunkName: "chunk-name" */ - './foo.js'/*suffix*/], resolve, reject) }); + './foo'/*suffix*/], resolve, reject) }); }); diff --git a/test/chunking-form/samples/dynamic-import-external/_expected/amd/main.js b/test/chunking-form/samples/dynamic-import-external/_expected/amd/main.js index b81e4d74b05..571a87ecba4 100644 --- a/test/chunking-form/samples/dynamic-import-external/_expected/amd/main.js +++ b/test/chunking-form/samples/dynamic-import-external/_expected/amd/main.js @@ -1,5 +1,5 @@ define(['require'], function (require) { 'use strict'; - new Promise(function (resolve, reject) { require(['./foo.js'], resolve, reject) }); + new Promise(function (resolve, reject) { require(['./foo'], resolve, reject) }); }); diff --git a/test/chunking-form/samples/dynamic-import-name/_expected/amd/main.js b/test/chunking-form/samples/dynamic-import-name/_expected/amd/main.js index a17abe669db..ed174177324 100644 --- a/test/chunking-form/samples/dynamic-import-name/_expected/amd/main.js +++ b/test/chunking-form/samples/dynamic-import-name/_expected/amd/main.js @@ -1,5 +1,5 @@ define(['require'], function (require) { 'use strict'; - new Promise(function (resolve, reject) { require(['./foo.js'], resolve, reject) }).then(result => console.log(result)); + new Promise(function (resolve, reject) { require(['./foo'], resolve, reject) }).then(result => console.log(result)); }); diff --git a/test/chunking-form/samples/resolve-dynamic-import/_config.js b/test/chunking-form/samples/resolve-dynamic-import/_config.js new file mode 100644 index 00000000000..b01f3e5ea8c --- /dev/null +++ b/test/chunking-form/samples/resolve-dynamic-import/_config.js @@ -0,0 +1,76 @@ +const path = require('path'); +const EXISTING = path.resolve(__dirname, 'existing.js'); + +module.exports = { + description: 'Supports all resolution formats for dynamic imports', + options: { + plugins: { + resolveId(source) { + switch (source) { + case 'existing-name': + return EXISTING; + case './direct-relative-external': + return false; + case './indirect-relative-external': + return { + id: 'to-indirect-relative-external', + external: true + }; + case 'direct-absolute-external': + return false; + case 'indirect-absolute-external': + return { + id: 'to-indirect-absolute-external', + external: true + }; + } + }, + + // TODO Lukas test new warnings + resolveDynamicImport(specifier) { + if (typeof specifier === 'string') { + switch (specifier) { + case 'existing-name': + return EXISTING; + case './direct-relative-external': + case '../direct-relative-external': + return false; + case './indirect-relative-external': + case '../indirect-relative-external': + return { + id: 'to-indirect-relative-external', + external: true + }; + case 'direct-absolute-external': + return false; + case 'indirect-absolute-external': + return { + id: 'to-indirect-absolute-external', + external: true + }; + default: + throw new Error(`Unexpected import ${specifier}`); + } + } + switch (specifier.left.value) { + case 'dynamic-direct-external': + return false; + case 'dynamic-indirect-external': + return { + id: 'to-dynamic-indirect-external', + external: true + }; + case 'dynamic-indirect-existing': + return { + id: EXISTING, + external: false + }; + case 'dynamic-replaced': + return `'my' + 'replacement'`; + default: + throw new Error(`Unexpected import ${specifier.left.value}`); + } + } + } + } +}; diff --git a/test/chunking-form/samples/resolve-dynamic-import/_expected/amd/generated-existing.js b/test/chunking-form/samples/resolve-dynamic-import/_expected/amd/generated-existing.js new file mode 100644 index 00000000000..e4849575ab9 --- /dev/null +++ b/test/chunking-form/samples/resolve-dynamic-import/_expected/amd/generated-existing.js @@ -0,0 +1,7 @@ +define(['exports'], function (exports) { 'use strict'; + + const value = 'existing'; + + exports.value = value; + +}); diff --git a/test/chunking-form/samples/resolve-dynamic-import/_expected/amd/main.js b/test/chunking-form/samples/resolve-dynamic-import/_expected/amd/main.js new file mode 100644 index 00000000000..ab43e42d41c --- /dev/null +++ b/test/chunking-form/samples/resolve-dynamic-import/_expected/amd/main.js @@ -0,0 +1,22 @@ +define(['require', './generated-existing', './direct-relative-external', 'to-indirect-relative-external', 'direct-absolute-external', 'to-indirect-absolute-external'], function (require, existing, directRelativeExternal, toIndirectRelativeExternal, directAbsoluteExternal, toIndirectAbsoluteExternal) { 'use strict'; + + // nested + new Promise(function (resolve, reject) { require(['./generated-existing'], resolve, reject) }); + new Promise(function (resolve, reject) { require(['./direct-relative-external'], resolve, reject) }); + new Promise(function (resolve, reject) { require(['to-indirect-relative-external'], resolve, reject) }); + new Promise(function (resolve, reject) { require(['direct-absolute-external'], resolve, reject) }); + new Promise(function (resolve, reject) { require(['to-indirect-absolute-external'], resolve, reject) }); + + //main + new Promise(function (resolve, reject) { require(['./generated-existing'], resolve, reject) }); + new Promise(function (resolve, reject) { require(['./direct-relative-external'], resolve, reject) }); + new Promise(function (resolve, reject) { require(['to-indirect-relative-external'], resolve, reject) }); + new Promise(function (resolve, reject) { require(['direct-absolute-external'], resolve, reject) }); + new Promise(function (resolve, reject) { require(['to-indirect-absolute-external'], resolve, reject) }); + + new Promise(function (resolve, reject) { require(['dynamic-direct-external' + unknown], resolve, reject) }); + new Promise(function (resolve, reject) { require(['to-dynamic-indirect-external'], resolve, reject) }); + new Promise(function (resolve, reject) { require(['./generated-existing'], resolve, reject) }); + new Promise(function (resolve, reject) { require(['my' + 'replacement'], resolve, reject) }); + +}); diff --git a/test/chunking-form/samples/resolve-dynamic-import/_expected/cjs/generated-existing.js b/test/chunking-form/samples/resolve-dynamic-import/_expected/cjs/generated-existing.js new file mode 100644 index 00000000000..561531ebe17 --- /dev/null +++ b/test/chunking-form/samples/resolve-dynamic-import/_expected/cjs/generated-existing.js @@ -0,0 +1,5 @@ +'use strict'; + +const value = 'existing'; + +exports.value = value; diff --git a/test/chunking-form/samples/resolve-dynamic-import/_expected/cjs/main.js b/test/chunking-form/samples/resolve-dynamic-import/_expected/cjs/main.js new file mode 100644 index 00000000000..613f8edbf07 --- /dev/null +++ b/test/chunking-form/samples/resolve-dynamic-import/_expected/cjs/main.js @@ -0,0 +1,26 @@ +'use strict'; + +require('./generated-existing.js'); +require('./direct-relative-external'); +require('to-indirect-relative-external'); +require('direct-absolute-external'); +require('to-indirect-absolute-external'); + +// nested +Promise.resolve(require('./generated-existing.js')); +Promise.resolve(require('./direct-relative-external')); +Promise.resolve(require('to-indirect-relative-external')); +Promise.resolve(require('direct-absolute-external')); +Promise.resolve(require('to-indirect-absolute-external')); + +//main +Promise.resolve(require('./generated-existing.js')); +Promise.resolve(require('./direct-relative-external')); +Promise.resolve(require('to-indirect-relative-external')); +Promise.resolve(require('direct-absolute-external')); +Promise.resolve(require('to-indirect-absolute-external')); + +Promise.resolve(require('dynamic-direct-external' + unknown)); +Promise.resolve(require('to-dynamic-indirect-external')); +Promise.resolve(require('./generated-existing.js')); +Promise.resolve(require('my' + 'replacement')); diff --git a/test/chunking-form/samples/resolve-dynamic-import/_expected/es/generated-existing.js b/test/chunking-form/samples/resolve-dynamic-import/_expected/es/generated-existing.js new file mode 100644 index 00000000000..4eca34c7282 --- /dev/null +++ b/test/chunking-form/samples/resolve-dynamic-import/_expected/es/generated-existing.js @@ -0,0 +1,3 @@ +const value = 'existing'; + +export { value }; diff --git a/test/chunking-form/samples/resolve-dynamic-import/_expected/es/main.js b/test/chunking-form/samples/resolve-dynamic-import/_expected/es/main.js new file mode 100644 index 00000000000..7dacf7a3eee --- /dev/null +++ b/test/chunking-form/samples/resolve-dynamic-import/_expected/es/main.js @@ -0,0 +1,24 @@ +import './generated-existing.js'; +import './direct-relative-external'; +import 'to-indirect-relative-external'; +import 'direct-absolute-external'; +import 'to-indirect-absolute-external'; + +// nested +import('./generated-existing.js'); +import('./direct-relative-external'); +import('to-indirect-relative-external'); +import('direct-absolute-external'); +import('to-indirect-absolute-external'); + +//main +import('./generated-existing.js'); +import('./direct-relative-external'); +import('to-indirect-relative-external'); +import('direct-absolute-external'); +import('to-indirect-absolute-external'); + +import('dynamic-direct-external' + unknown); +import('to-dynamic-indirect-external'); +import('./generated-existing.js'); +import('my' + 'replacement'); diff --git a/test/chunking-form/samples/resolve-dynamic-import/_expected/system/generated-existing.js b/test/chunking-form/samples/resolve-dynamic-import/_expected/system/generated-existing.js new file mode 100644 index 00000000000..d7b47fdc482 --- /dev/null +++ b/test/chunking-form/samples/resolve-dynamic-import/_expected/system/generated-existing.js @@ -0,0 +1,10 @@ +System.register([], function (exports, module) { + 'use strict'; + return { + execute: function () { + + const value = exports('value', 'existing'); + + } + }; +}); diff --git a/test/chunking-form/samples/resolve-dynamic-import/_expected/system/main.js b/test/chunking-form/samples/resolve-dynamic-import/_expected/system/main.js new file mode 100644 index 00000000000..ea036d03331 --- /dev/null +++ b/test/chunking-form/samples/resolve-dynamic-import/_expected/system/main.js @@ -0,0 +1,28 @@ +System.register(['./generated-existing.js', './direct-relative-external', 'to-indirect-relative-external', 'direct-absolute-external', 'to-indirect-absolute-external'], function (exports, module) { + 'use strict'; + return { + setters: [function () {}, function () {}, function () {}, function () {}, function () {}], + execute: function () { + + // nested + module.import('./generated-existing.js'); + module.import('./direct-relative-external'); + module.import('to-indirect-relative-external'); + module.import('direct-absolute-external'); + module.import('to-indirect-absolute-external'); + + //main + module.import('./generated-existing.js'); + module.import('./direct-relative-external'); + module.import('to-indirect-relative-external'); + module.import('direct-absolute-external'); + module.import('to-indirect-absolute-external'); + + module.import('dynamic-direct-external' + unknown); + module.import('to-dynamic-indirect-external'); + module.import('./generated-existing.js'); + module.import('my' + 'replacement'); + + } + }; +}); diff --git a/test/chunking-form/samples/resolve-dynamic-import/existing.js b/test/chunking-form/samples/resolve-dynamic-import/existing.js new file mode 100644 index 00000000000..29aa16bd444 --- /dev/null +++ b/test/chunking-form/samples/resolve-dynamic-import/existing.js @@ -0,0 +1 @@ +export const value = 'existing'; diff --git a/test/chunking-form/samples/resolve-dynamic-import/main.js b/test/chunking-form/samples/resolve-dynamic-import/main.js new file mode 100644 index 00000000000..dd732190f3f --- /dev/null +++ b/test/chunking-form/samples/resolve-dynamic-import/main.js @@ -0,0 +1,19 @@ +import './nested/nested.js'; + +import 'existing-name'; +import './direct-relative-external'; +import './indirect-relative-external'; +import 'direct-absolute-external'; +import 'indirect-absolute-external'; + +//main +import(`existing-name`); +import('./direct-relative-external'); +import('./indirect-relative-external'); +import('direct-absolute-external'); +import('indirect-absolute-external'); + +import('dynamic-direct-external' + unknown); +import('dynamic-indirect-external' + unknown); +import('dynamic-indirect-existing' + unknown); +import('dynamic-replaced' + unknown); diff --git a/test/chunking-form/samples/resolve-dynamic-import/nested/nested.js b/test/chunking-form/samples/resolve-dynamic-import/nested/nested.js new file mode 100644 index 00000000000..57cf6733ae8 --- /dev/null +++ b/test/chunking-form/samples/resolve-dynamic-import/nested/nested.js @@ -0,0 +1,6 @@ +// nested +import('existing-name'); +import('../direct-relative-external'); +import('../indirect-relative-external'); +import('direct-absolute-external'); +import('indirect-absolute-external'); diff --git a/test/form/samples/resolve-external-dynamic-imports/_config.js b/test/form/samples/resolve-external-dynamic-imports/_config.js index f8f2eb0bd1c..3349408669e 100644 --- a/test/form/samples/resolve-external-dynamic-imports/_config.js +++ b/test/form/samples/resolve-external-dynamic-imports/_config.js @@ -1,5 +1,5 @@ module.exports = { - description: 'correctly resolves ids of external dynamic imports (#2481)', + description: 'does not resolve external dynamic imports via plugins (#2481)', options: { output: { name: 'bundle' }, external(id) { From 996d7ede7524f4fbf14fa4302ed0c7b5619e614e Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Wed, 1 May 2019 09:44:11 +0200 Subject: [PATCH 51/60] Test new warnings and errors --- .../samples/resolve-dynamic-import/_config.js | 3 ++- .../dynamic-import-not-found/_config.js | 20 +++++++++++++++++++ .../samples/dynamic-import-not-found/main.js | 1 + .../_config.js | 7 +++++++ .../dynamic-import-relative-not-found/main.js | 1 + 5 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 test/function/samples/dynamic-import-not-found/_config.js create mode 100644 test/function/samples/dynamic-import-not-found/main.js create mode 100644 test/function/samples/dynamic-import-relative-not-found/_config.js create mode 100644 test/function/samples/dynamic-import-relative-not-found/main.js diff --git a/test/chunking-form/samples/resolve-dynamic-import/_config.js b/test/chunking-form/samples/resolve-dynamic-import/_config.js index b01f3e5ea8c..468e8ac7d7e 100644 --- a/test/chunking-form/samples/resolve-dynamic-import/_config.js +++ b/test/chunking-form/samples/resolve-dynamic-import/_config.js @@ -26,7 +26,8 @@ module.exports = { } }, - // TODO Lukas test new warnings + // TODO Lukas soft-deprecate resolveId context function + // TODO Lukas extract errors resolveDynamicImport(specifier) { if (typeof specifier === 'string') { switch (specifier) { diff --git a/test/function/samples/dynamic-import-not-found/_config.js b/test/function/samples/dynamic-import-not-found/_config.js new file mode 100644 index 00000000000..2f00552892b --- /dev/null +++ b/test/function/samples/dynamic-import-not-found/_config.js @@ -0,0 +1,20 @@ +module.exports = { + description: 'warns if a dynamic import is not found', + context: { + require(id) { + if (id === 'mod') { + return {}; + } + } + }, + warnings: [ + { + code: 'UNRESOLVED_IMPORT', + importer: 'main.js', + message: + "'mod' is imported by main.js, but could not be resolved – treating it as an external dependency", + source: 'mod', + url: 'https://rollupjs.org/guide/en#warning-treating-module-as-external-dependency' + } + ] +}; diff --git a/test/function/samples/dynamic-import-not-found/main.js b/test/function/samples/dynamic-import-not-found/main.js new file mode 100644 index 00000000000..9a1c5d2d166 --- /dev/null +++ b/test/function/samples/dynamic-import-not-found/main.js @@ -0,0 +1 @@ +import('mod'); diff --git a/test/function/samples/dynamic-import-relative-not-found/_config.js b/test/function/samples/dynamic-import-relative-not-found/_config.js new file mode 100644 index 00000000000..fa9cf8e9d04 --- /dev/null +++ b/test/function/samples/dynamic-import-relative-not-found/_config.js @@ -0,0 +1,7 @@ +module.exports = { + description: 'throws if a dynamic relative import is not found', + error: { + code: 'UNRESOLVED_IMPORT', + message: `Could not resolve './mod' from main.js` + } +}; diff --git a/test/function/samples/dynamic-import-relative-not-found/main.js b/test/function/samples/dynamic-import-relative-not-found/main.js new file mode 100644 index 00000000000..f9be6719428 --- /dev/null +++ b/test/function/samples/dynamic-import-relative-not-found/main.js @@ -0,0 +1 @@ +import('./mod'); From 18d5d382e53162d9de72283a42da0e893a292ac7 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Wed, 1 May 2019 10:45:02 +0200 Subject: [PATCH 52/60] Mark this.resolveId and this.isExternal as deprecated --- docs/05-plugins.md | 18 +++++++++--------- .../samples/resolve-dynamic-import/_config.js | 1 - 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/docs/05-plugins.md b/docs/05-plugins.md index 57a887f2d8f..9a0de3babd3 100644 --- a/docs/05-plugins.md +++ b/docs/05-plugins.md @@ -304,7 +304,7 @@ Kind: `async, parallel` Called only at the end of `bundle.write()` once all files have been written. Similar to the [`generateBundle`](guide/en#generatebundle) hook, `bundle` provides the full list of files being written along with their details. -### Deprecated +### Deprecated Hooks ☢️ These hooks have been deprecated and may be removed in a future Rollup version. @@ -379,10 +379,6 @@ Returns additional information about the module in question in the form If the module id cannot be found, an error is thrown. -#### `this.isExternal(id: string, importer: string, isResolved: boolean): boolean` - -Determine if a given module ID is external when imported by `importer`. When `isResolved` is false, Rollup will try to resolve the id before testing if it is external. - #### `this.meta: {rollupVersion: string}` An `Object` containing potentially useful Rollup metadata. `meta` is the only context property accessible from the [`options`](guide/en#options) hook. @@ -404,10 +400,6 @@ Use Rollup's internal acorn instance to parse code to an AST. #### `this.resolve(source: string, importer: string) => Promise<{id: string, external: boolean} | null>` Resolve imports to module ids (i.e. file names) using the same plugins that Rollup uses, and determine if an import should be external. If `null` is returned, the import could not be resolved by Rollup or any plugin but was not explicitly marked as external by the user. -#### `this.resolveId(source: string, importer: string) => Promise` - -Resolve imports to module ids (i.e. file names) using the same plugins that Rollup uses. Returns `null` if an id cannot be resolved. - #### `this.setAssetSource(assetReferenceId: string, source: string | Buffer) => void` Set the deferred source of an asset. @@ -428,6 +420,14 @@ Use the second form if you need to add additional properties to your warning obj The `position` argument is a character index where the warning was raised. If present, Rollup will augment the warning object with `pos`, `loc` (a standard `{ file, line, column }` object) and `frame` (a snippet of code showing the error). +### Deprecated Context Functions + +☢️ These context utility functions have been deprecated and may be removed in a future Rollup version. + +- `this.isExternal(id: string, importer: string, isResolved: boolean): boolean` - _**Use [`this.resolve`](guide/en#this-resolve-source-string-importer-string-promise-id-string-external-boolean-null)**_ - Determine if a given module ID is external when imported by `importer`. When `isResolved` is false, Rollup will try to resolve the id before testing if it is external. + +- `this.resolveId(source: string, importer: string) => Promise` - _**Use [`this.resolve`](guide/en#this-resolve-source-string-importer-string-promise-id-string-external-boolean-null)**_ - Resolve imports to module ids (i.e. file names) using the same plugins that Rollup uses. Returns `null` if an id cannot be resolved. + ### Asset URLs To reference an asset URL reference from within JS code, use the `import.meta.ROLLUP_ASSET_URL_assetReferenceId` replacement. This will generate code that depends on the output format and generates a URL that points to the emitted file in the target environment. Note that all formats except CommonJS and UMD assume that they run in a browser environment where `URL` and `document` are available. diff --git a/test/chunking-form/samples/resolve-dynamic-import/_config.js b/test/chunking-form/samples/resolve-dynamic-import/_config.js index 468e8ac7d7e..5c578f15b44 100644 --- a/test/chunking-form/samples/resolve-dynamic-import/_config.js +++ b/test/chunking-form/samples/resolve-dynamic-import/_config.js @@ -26,7 +26,6 @@ module.exports = { } }, - // TODO Lukas soft-deprecate resolveId context function // TODO Lukas extract errors resolveDynamicImport(specifier) { if (typeof specifier === 'string') { From 293cada029070bf7d9d4f7245cab2a425905ad7e Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Wed, 1 May 2019 11:11:57 +0200 Subject: [PATCH 53/60] Extract more errors --- src/ModuleLoader.ts | 41 ++++++----------- src/utils/error.ts | 46 ++++++++++++++++++- .../samples/resolve-dynamic-import/_config.js | 1 - .../check-resolve-for-entry/_config.js | 2 +- .../emit-chunk/chunk-not-found/_config.js | 2 +- .../external-entry-point-object/_config.js | 4 +- .../samples/external-entry-point/_config.js | 4 +- 7 files changed, 66 insertions(+), 34 deletions(-) diff --git a/src/ModuleLoader.ts b/src/ModuleLoader.ts index 9e1c1d9edc1..8754c31d16c 100644 --- a/src/ModuleLoader.ts +++ b/src/ModuleLoader.ts @@ -11,10 +11,15 @@ import { SourceDescription } from './rollup/types'; import { - error, + errorBadLoader, errorCannotAssignModuleToChunk, errorChunkNotGeneratedForFileName, - errorChunkReferenceIdNotFoundForFilename + errorChunkReferenceIdNotFoundForFilename, + errorEntryCannotBeExternal, + errorInternalIdCannotBeExternal, + Errors, + errorUnresolvedEntry, + errorUnresolvedImport } from './utils/error'; import { isRelative, resolve } from './utils/path'; import { PluginDriver } from './utils/pluginDriver'; @@ -228,13 +233,7 @@ export class ModuleLoader { timeEnd('load modules', 3); if (typeof source === 'string') return source; if (source && typeof source === 'object' && typeof source.code === 'string') return source; - - error({ - code: 'BAD_LOADER', - message: `Error loading ${relativeId( - id - )}: plugin load hook should return a string, a { code, map } object, or nothing/null` - }); + errorBadLoader(id); }) .then(source => { const sourceDescription: SourceDescription = @@ -317,12 +316,7 @@ export class ModuleLoader { const externalModule = this.modulesById.get(resolvedId.id); if (externalModule instanceof ExternalModule === false) { - error({ - code: 'INVALID_EXTERNAL_ID', - message: `'${source}' is imported as an external by ${relativeId( - importer - )}, but is already an existing non-external module id.` - }); + errorInternalIdCannotBeExternal(source, importer); } return Promise.resolve(externalModule); } else { @@ -337,13 +331,10 @@ export class ModuleLoader { ): ResolvedId { if (resolvedId === null) { if (isRelative(source)) { - error({ - code: 'UNRESOLVED_IMPORT', - message: `Could not resolve '${source}' from ${relativeId(importer)}` - }); + errorUnresolvedImport(source, importer); } this.graph.warn({ - code: 'UNRESOLVED_IMPORT', + code: Errors.UNRESOLVED_IMPORT, importer: relativeId(importer), message: `'${source}' is imported by ${relativeId( importer @@ -368,10 +359,7 @@ export class ModuleLoader { resolveIdResult === false || (resolveIdResult && typeof resolveIdResult === 'object' && resolveIdResult.external) ) { - error({ - code: 'UNRESOLVED_ENTRY', - message: `Entry module cannot be external` - }); + errorEntryCannotBeExternal(unresolvedId); } const id = resolveIdResult && typeof resolveIdResult === 'object' @@ -396,10 +384,7 @@ export class ModuleLoader { return module; }); } - error({ - code: 'UNRESOLVED_ENTRY', - message: `Could not resolve entry (${unresolvedId})` - }); + errorUnresolvedEntry(unresolvedId); }); private normalizeResolveIdResult( diff --git a/src/utils/error.ts b/src/utils/error.ts index dd2fe14e979..6d86da8b4ee 100644 --- a/src/utils/error.ts +++ b/src/utils/error.ts @@ -35,13 +35,18 @@ export enum Errors { ASSET_NOT_FOUND = 'ASSET_NOT_FOUND', ASSET_SOURCE_ALREADY_SET = 'ASSET_SOURCE_ALREADY_SET', ASSET_SOURCE_MISSING = 'ASSET_SOURCE_MISSING', + BAD_LOADER = 'BAD_LOADER', CHUNK_NOT_FOUND = 'CHUNK_NOT_FOUND', CHUNK_NOT_GENERATED = 'CHUNK_NOT_GENERATED', INVALID_ASSET_NAME = 'INVALID_ASSET_NAME', INVALID_CHUNK = 'INVALID_CHUNK', - INVALID_ROLLUP_PHASE = 'INVALID_ROLLUP_PHASE' + INVALID_EXTERNAL_ID = 'INVALID_EXTERNAL_ID', + INVALID_ROLLUP_PHASE = 'INVALID_ROLLUP_PHASE', + UNRESOLVED_ENTRY = 'UNRESOLVED_ENTRY', + UNRESOLVED_IMPORT = 'UNRESOLVED_IMPORT' } +// TODO Lukas only export objects export function errorAssetNotFinalisedForFileName(asset: Asset) { error({ code: Errors.ASSET_NOT_FINALISED, @@ -97,6 +102,15 @@ export function errorNoAssetSourceSet(asset: Asset) { }); } +export function errorBadLoader(id: string) { + error({ + code: Errors.BAD_LOADER, + message: `Error loading ${relativeId( + id + )}: plugin load hook should return a string, a { code, map } object, or nothing/null` + }); +} + export function errorChunkReferenceIdNotFoundForFilename(chunkReferenceId: string) { error({ code: Errors.CHUNK_NOT_FOUND, @@ -123,3 +137,33 @@ export function errorCannotAssignModuleToChunk( )} to the "${assignToAlias}" chunk as it is already in the "${currentAlias}" chunk.` }); } + +export function errorInternalIdCannotBeExternal(source: string, importer: string) { + error({ + code: Errors.INVALID_EXTERNAL_ID, + message: `'${source}' is imported as an external by ${relativeId( + importer + )}, but is already an existing non-external module id.` + }); +} + +export function errorEntryCannotBeExternal(unresolvedId: string) { + error({ + code: Errors.UNRESOLVED_ENTRY, + message: `Entry module cannot be external (${unresolvedId}).` + }); +} + +export function errorUnresolvedEntry(unresolvedId: string) { + error({ + code: Errors.UNRESOLVED_ENTRY, + message: `Could not resolve entry module (${unresolvedId}).` + }); +} + +export function errorUnresolvedImport(source: string, importer: string) { + error({ + code: Errors.UNRESOLVED_IMPORT, + message: `Could not resolve '${source}' from ${relativeId(importer)}` + }); +} diff --git a/test/chunking-form/samples/resolve-dynamic-import/_config.js b/test/chunking-form/samples/resolve-dynamic-import/_config.js index 5c578f15b44..fc84d61a62e 100644 --- a/test/chunking-form/samples/resolve-dynamic-import/_config.js +++ b/test/chunking-form/samples/resolve-dynamic-import/_config.js @@ -26,7 +26,6 @@ module.exports = { } }, - // TODO Lukas extract errors resolveDynamicImport(specifier) { if (typeof specifier === 'string') { switch (specifier) { diff --git a/test/function/samples/check-resolve-for-entry/_config.js b/test/function/samples/check-resolve-for-entry/_config.js index 492041a77f1..6e2ab9abea4 100644 --- a/test/function/samples/check-resolve-for-entry/_config.js +++ b/test/function/samples/check-resolve-for-entry/_config.js @@ -5,6 +5,6 @@ module.exports = { }, error: { code: 'UNRESOLVED_ENTRY', - message: 'Could not resolve entry (/not/a/path/that/actually/really/exists)' + message: 'Could not resolve entry module (/not/a/path/that/actually/really/exists).' } }; diff --git a/test/function/samples/emit-chunk/chunk-not-found/_config.js b/test/function/samples/emit-chunk/chunk-not-found/_config.js index 46e17ecb5ee..0d85644457d 100644 --- a/test/function/samples/emit-chunk/chunk-not-found/_config.js +++ b/test/function/samples/emit-chunk/chunk-not-found/_config.js @@ -10,6 +10,6 @@ module.exports = { }, error: { code: 'UNRESOLVED_ENTRY', - message: 'Could not resolve entry (not-found.js)' + message: 'Could not resolve entry module (not-found.js).' } }; diff --git a/test/function/samples/external-entry-point-object/_config.js b/test/function/samples/external-entry-point-object/_config.js index 72bc5d8844a..066a4932142 100644 --- a/test/function/samples/external-entry-point-object/_config.js +++ b/test/function/samples/external-entry-point-object/_config.js @@ -1,3 +1,5 @@ +const path = require('path'); + module.exports = { description: 'throws for entry points that are resolved as an external object by plugins', options: { @@ -9,6 +11,6 @@ module.exports = { }, error: { code: 'UNRESOLVED_ENTRY', - message: 'Entry module cannot be external' + message: `Entry module cannot be external (${path.resolve(__dirname, 'main.js')}).` } }; diff --git a/test/function/samples/external-entry-point/_config.js b/test/function/samples/external-entry-point/_config.js index 87194245ee0..421a4d48fcb 100644 --- a/test/function/samples/external-entry-point/_config.js +++ b/test/function/samples/external-entry-point/_config.js @@ -1,3 +1,5 @@ +const path = require('path'); + module.exports = { description: 'throws for entry points that are resolved as false by plugins', options: { @@ -9,6 +11,6 @@ module.exports = { }, error: { code: 'UNRESOLVED_ENTRY', - message: 'Entry module cannot be external' + message: `Entry module cannot be external (${path.resolve(__dirname, 'main.js')}).` } }; From f5c27bd92e92b3b1548852f38fa8df5b79c00ae5 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Wed, 1 May 2019 11:37:01 +0200 Subject: [PATCH 54/60] Use error message generators instead of error generators --- src/ModuleLoader.ts | 68 +++++++------------ src/utils/assetHooks.ts | 29 ++++---- src/utils/error.ts | 138 +++++++++++++++++++++++++------------- src/utils/pluginDriver.ts | 17 ++--- 4 files changed, 139 insertions(+), 113 deletions(-) diff --git a/src/ModuleLoader.ts b/src/ModuleLoader.ts index 8754c31d16c..419b33ec6e2 100644 --- a/src/ModuleLoader.ts +++ b/src/ModuleLoader.ts @@ -11,15 +11,17 @@ import { SourceDescription } from './rollup/types'; import { - errorBadLoader, - errorCannotAssignModuleToChunk, - errorChunkNotGeneratedForFileName, - errorChunkReferenceIdNotFoundForFilename, - errorEntryCannotBeExternal, - errorInternalIdCannotBeExternal, - Errors, - errorUnresolvedEntry, - errorUnresolvedImport + errBadLoader, + errCannotAssignModuleToChunk, + errChunkNotGeneratedForFileName, + errChunkReferenceIdNotFoundForFilename, + errEntryCannotBeExternal, + errInternalIdCannotBeExternal, + errNamespaceConflict, + error, + errUnresolvedEntry, + errUnresolvedImport, + errUnresolvedImportTreatedAsExternal } from './utils/error'; import { isRelative, resolve } from './utils/path'; import { PluginDriver } from './utils/pluginDriver'; @@ -144,13 +146,13 @@ export class ModuleLoader { getChunkFileName(referenceId: string): string { const entryRecord = this.entriesByReferenceId.get(referenceId); - if (!entryRecord) errorChunkReferenceIdNotFoundForFilename(referenceId); + if (!entryRecord) error(errChunkReferenceIdNotFoundForFilename(referenceId)); const fileName = entryRecord.module && (entryRecord.module.facadeChunk ? entryRecord.module.facadeChunk.id : entryRecord.module.chunk.id); - if (!fileName) errorChunkNotGeneratedForFileName(entryRecord); + if (!fileName) error(errChunkNotGeneratedForFileName(entryRecord)); return fileName; } @@ -233,7 +235,7 @@ export class ModuleLoader { timeEnd('load modules', 3); if (typeof source === 'string') return source; if (source && typeof source === 'object' && typeof source.code === 'string') return source; - errorBadLoader(id); + error(errBadLoader(id)); }) .then(source => { const sourceDescription: SourceDescription = @@ -274,25 +276,13 @@ export class ModuleLoader { module.exportAllSources.forEach(source => { const id = module.resolvedIds[source].id; const exportAllModule = this.modulesById.get(id); - if (exportAllModule.isExternal) return; + if (exportAllModule instanceof ExternalModule) return; - for (const name in (exportAllModule).exportsAll) { + for (const name in exportAllModule.exportsAll) { if (name in module.exportsAll) { - this.graph.warn({ - code: 'NAMESPACE_CONFLICT', - message: `Conflicting namespaces: ${relativeId( - module.id - )} re-exports '${name}' from both ${relativeId( - module.exportsAll[name] - )} and ${relativeId( - (exportAllModule).exportsAll[name] - )} (will be ignored)`, - name, - reexporter: module.id, - sources: [module.exportsAll[name], (exportAllModule).exportsAll[name]] - }); + this.graph.warn(errNamespaceConflict(name, module, exportAllModule)); } else { - module.exportsAll[name] = (exportAllModule).exportsAll[name]; + module.exportsAll[name] = exportAllModule.exportsAll[name]; } } }); @@ -316,7 +306,7 @@ export class ModuleLoader { const externalModule = this.modulesById.get(resolvedId.id); if (externalModule instanceof ExternalModule === false) { - errorInternalIdCannotBeExternal(source, importer); + error(errInternalIdCannotBeExternal(source, importer)); } return Promise.resolve(externalModule); } else { @@ -331,17 +321,9 @@ export class ModuleLoader { ): ResolvedId { if (resolvedId === null) { if (isRelative(source)) { - errorUnresolvedImport(source, importer); + error(errUnresolvedImport(source, importer)); } - this.graph.warn({ - code: Errors.UNRESOLVED_IMPORT, - importer: relativeId(importer), - message: `'${source}' is imported by ${relativeId( - importer - )}, but could not be resolved – treating it as an external dependency`, - source, - url: 'https://rollupjs.org/guide/en#warning-treating-module-as-external-dependency' - }); + this.graph.warn(errUnresolvedImportTreatedAsExternal(source, importer)); return { id: source, external: true }; } return resolvedId; @@ -359,7 +341,7 @@ export class ModuleLoader { resolveIdResult === false || (resolveIdResult && typeof resolveIdResult === 'object' && resolveIdResult.external) ) { - errorEntryCannotBeExternal(unresolvedId); + error(errEntryCannotBeExternal(unresolvedId)); } const id = resolveIdResult && typeof resolveIdResult === 'object' @@ -371,20 +353,20 @@ export class ModuleLoader { if (alias !== null) { if (isManualChunkEntry) { if (module.manualChunkAlias !== null && module.manualChunkAlias !== alias) { - errorCannotAssignModuleToChunk(module.id, alias, module.manualChunkAlias); + error(errCannotAssignModuleToChunk(module.id, alias, module.manualChunkAlias)); } module.manualChunkAlias = alias; return module; } if (module.chunkAlias !== null && module.chunkAlias !== alias) { - errorCannotAssignModuleToChunk(module.id, alias, module.chunkAlias); + error(errCannotAssignModuleToChunk(module.id, alias, module.chunkAlias)); } module.chunkAlias = alias; } return module; }); } - errorUnresolvedEntry(unresolvedId); + error(errUnresolvedEntry(unresolvedId)); }); private normalizeResolveIdResult( diff --git a/src/utils/assetHooks.ts b/src/utils/assetHooks.ts index 3d3b66a0be4..a2b24e4d20c 100644 --- a/src/utils/assetHooks.ts +++ b/src/utils/assetHooks.ts @@ -1,13 +1,14 @@ import sha256 from 'hash.js/lib/hash/sha/256'; import { Asset, EmitAsset, OutputBundle } from '../rollup/types'; import { - errorAssetNotFinalisedForFileName, - errorAssetReferenceIdNotFoundForFilename, - errorAssetReferenceIdNotFoundForSetSource, - errorAssetSourceAlreadySet, - errorAssetSourceMissingForSetSource, - errorInvalidAssetName, - errorNoAssetSourceSet + errAssetNotFinalisedForFileName, + errAssetReferenceIdNotFoundForFilename, + errAssetReferenceIdNotFoundForSetSource, + errAssetSourceAlreadySet, + errAssetSourceMissingForSetSource, + errInvalidAssetName, + errNoAssetSourceSet, + error } from './error'; import { extname } from './path'; import { addWithNewReferenceId } from './referenceIds'; @@ -19,7 +20,7 @@ export function getAssetFileName( existingNames: Record, assetFileNames: string ) { - if (asset.source === undefined) errorNoAssetSourceSet(asset); + if (asset.source === undefined) error(errNoAssetSourceSet(asset)); if (asset.fileName) return asset.fileName; return makeUnique( @@ -50,7 +51,7 @@ export function createAssetPluginHooks( ) { return { emitAsset(name: string, source?: string | Buffer) { - if (typeof name !== 'string' || !isPlainName(name)) errorInvalidAssetName(name); + if (typeof name !== 'string' || !isPlainName(name)) error(errInvalidAssetName(name)); const asset: Asset = { name, source, fileName: undefined }; if (outputBundle && source !== undefined) finaliseAsset(asset, outputBundle, assetFileNames); return addWithNewReferenceId(asset, assetsByReferenceId, name); @@ -58,17 +59,17 @@ export function createAssetPluginHooks( setAssetSource(assetReferenceId: string, source?: string | Buffer) { const asset = assetsByReferenceId.get(assetReferenceId); - if (!asset) errorAssetReferenceIdNotFoundForSetSource(assetReferenceId); - if (asset.source !== undefined) errorAssetSourceAlreadySet(asset); - if (typeof source !== 'string' && !source) errorAssetSourceMissingForSetSource(asset); + if (!asset) error(errAssetReferenceIdNotFoundForSetSource(assetReferenceId)); + if (asset.source !== undefined) error(errAssetSourceAlreadySet(asset)); + if (typeof source !== 'string' && !source) error(errAssetSourceMissingForSetSource(asset)); asset.source = source; if (outputBundle) finaliseAsset(asset, outputBundle, assetFileNames); }, getAssetFileName(assetReferenceId: string) { const asset = assetsByReferenceId.get(assetReferenceId); - if (!asset) errorAssetReferenceIdNotFoundForFilename(assetReferenceId); - if (asset.fileName === undefined) errorAssetNotFinalisedForFileName(asset); + if (!asset) error(errAssetReferenceIdNotFoundForFilename(assetReferenceId)); + if (asset.fileName === undefined) error(errAssetNotFinalisedForFileName(asset)); return asset.fileName; } }; diff --git a/src/utils/error.ts b/src/utils/error.ts index 6d86da8b4ee..7f735a1e2de 100644 --- a/src/utils/error.ts +++ b/src/utils/error.ts @@ -1,4 +1,5 @@ import { locate } from 'locate-character'; +import Module from '../Module'; import { Asset, RollupError, RollupWarning } from '../rollup/types'; import getCodeFrame from './getCodeFrame'; import relativeId from './relativeId'; @@ -41,129 +42,174 @@ export enum Errors { INVALID_ASSET_NAME = 'INVALID_ASSET_NAME', INVALID_CHUNK = 'INVALID_CHUNK', INVALID_EXTERNAL_ID = 'INVALID_EXTERNAL_ID', + INVALID_PLUGIN_HOOK = 'INVALID_PLUGIN_HOOK', INVALID_ROLLUP_PHASE = 'INVALID_ROLLUP_PHASE', + NAMESPACE_CONFLICT = 'NAMESPACE_CONFLICT', UNRESOLVED_ENTRY = 'UNRESOLVED_ENTRY', UNRESOLVED_IMPORT = 'UNRESOLVED_IMPORT' } -// TODO Lukas only export objects -export function errorAssetNotFinalisedForFileName(asset: Asset) { - error({ +export function errAssetNotFinalisedForFileName(asset: Asset) { + return { code: Errors.ASSET_NOT_FINALISED, message: `Plugin error - Unable to get file name for asset "${ asset.name }". Ensure that the source is set and that generate is called first.` - }); + }; } -export function errorChunkNotGeneratedForFileName(entry: { name: string }) { - error({ +export function errChunkNotGeneratedForFileName(entry: { name: string }) { + return { code: Errors.CHUNK_NOT_GENERATED, message: `Plugin error - Unable to get file name for chunk "${ entry.name }". Ensure that generate is called first.` - }); + }; } -export function errorAssetReferenceIdNotFoundForFilename(assetReferenceId: string) { - error({ +export function errAssetReferenceIdNotFoundForFilename(assetReferenceId: string) { + return { code: Errors.ASSET_NOT_FOUND, message: `Plugin error - Unable to get file name for unknown asset "${assetReferenceId}".` - }); + }; } -export function errorAssetReferenceIdNotFoundForSetSource(assetReferenceId: string) { - error({ +export function errAssetReferenceIdNotFoundForSetSource(assetReferenceId: string) { + return { code: Errors.ASSET_NOT_FOUND, message: `Plugin error - Unable to set the source for unknown asset "${assetReferenceId}".` - }); + }; } -export function errorAssetSourceAlreadySet(asset: Asset) { - error({ +export function errAssetSourceAlreadySet(asset: Asset) { + return { code: Errors.ASSET_SOURCE_ALREADY_SET, message: `Plugin error - Unable to set the source for asset "${ asset.name }", source already set.` - }); + }; } -export function errorAssetSourceMissingForSetSource(asset: Asset) { - error({ +export function errAssetSourceMissingForSetSource(asset: Asset) { + return { code: Errors.ASSET_SOURCE_MISSING, message: `Plugin error creating asset "${asset.name}", setAssetSource call without a source.` - }); + }; } -export function errorNoAssetSourceSet(asset: Asset) { - error({ +export function errNoAssetSourceSet(asset: Asset) { + return { code: Errors.ASSET_SOURCE_MISSING, message: `Plugin error creating asset "${asset.name}" - no asset source set.` - }); + }; } -export function errorBadLoader(id: string) { - error({ +export function errBadLoader(id: string) { + return { code: Errors.BAD_LOADER, message: `Error loading ${relativeId( id )}: plugin load hook should return a string, a { code, map } object, or nothing/null` - }); + }; } -export function errorChunkReferenceIdNotFoundForFilename(chunkReferenceId: string) { - error({ +export function errChunkReferenceIdNotFoundForFilename(chunkReferenceId: string) { + return { code: Errors.CHUNK_NOT_FOUND, message: `Plugin error - Unable to get file name for unknown chunk "${chunkReferenceId}".` - }); + }; } -export function errorInvalidAssetName(name: string) { - error({ +export function errInvalidAssetName(name: string) { + return { code: Errors.INVALID_ASSET_NAME, message: `Plugin error creating asset, name "${name}" is not a plain (non relative or absolute URL) string name.` - }); + }; } -export function errorCannotAssignModuleToChunk( +export function errCannotAssignModuleToChunk( moduleId: string, assignToAlias: string, currentAlias: string ) { - error({ + return { code: Errors.INVALID_CHUNK, message: `Cannot assign ${relativeId( moduleId )} to the "${assignToAlias}" chunk as it is already in the "${currentAlias}" chunk.` - }); + }; } -export function errorInternalIdCannotBeExternal(source: string, importer: string) { - error({ +export function errInternalIdCannotBeExternal(source: string, importer: string) { + return { code: Errors.INVALID_EXTERNAL_ID, message: `'${source}' is imported as an external by ${relativeId( importer )}, but is already an existing non-external module id.` - }); + }; } -export function errorEntryCannotBeExternal(unresolvedId: string) { - error({ +export function errInvalidRollupPhaseForAddWatchFile() { + return { + code: Errors.INVALID_ROLLUP_PHASE, + message: `Cannot call addWatchFile after the build has finished.` + }; +} + +export function errInvalidRollupPhaseForEmitChunk() { + return { + code: Errors.INVALID_ROLLUP_PHASE, + message: `Cannot call emitChunk after module loading has finished.` + }; +} + +export function errNamespaceConflict( + name: string, + reexportingModule: Module, + additionalExportAllModule: Module +) { + return { + code: Errors.NAMESPACE_CONFLICT, + message: `Conflicting namespaces: ${relativeId( + reexportingModule.id + )} re-exports '${name}' from both ${relativeId( + reexportingModule.exportsAll[name] + )} and ${relativeId(additionalExportAllModule.exportsAll[name])} (will be ignored)`, + name, + reexporter: reexportingModule.id, + sources: [reexportingModule.exportsAll[name], additionalExportAllModule.exportsAll[name]] + }; +} + +export function errEntryCannotBeExternal(unresolvedId: string) { + return { code: Errors.UNRESOLVED_ENTRY, message: `Entry module cannot be external (${unresolvedId}).` - }); + }; } -export function errorUnresolvedEntry(unresolvedId: string) { - error({ +export function errUnresolvedEntry(unresolvedId: string) { + return { code: Errors.UNRESOLVED_ENTRY, message: `Could not resolve entry module (${unresolvedId}).` - }); + }; } -export function errorUnresolvedImport(source: string, importer: string) { - error({ +export function errUnresolvedImport(source: string, importer: string) { + return { code: Errors.UNRESOLVED_IMPORT, message: `Could not resolve '${source}' from ${relativeId(importer)}` - }); + }; +} + +export function errUnresolvedImportTreatedAsExternal(source: string, importer: string) { + return { + code: Errors.UNRESOLVED_IMPORT, + importer: relativeId(importer), + message: `'${source}' is imported by ${relativeId( + importer + )}, but could not be resolved – treating it as an external dependency`, + source, + url: 'https://rollupjs.org/guide/en#warning-treating-module-as-external-dependency' + }; } diff --git a/src/utils/pluginDriver.ts b/src/utils/pluginDriver.ts index 02a7b328efb..cea0d193bbe 100644 --- a/src/utils/pluginDriver.ts +++ b/src/utils/pluginDriver.ts @@ -16,7 +16,11 @@ import { import { createAssetPluginHooks } from './assetHooks'; import { BuildPhase } from './buildPhase'; import { getRollupDefaultPlugin } from './defaultPlugin'; -import { error, Errors } from './error'; +import { + errInvalidRollupPhaseForAddWatchFile, + errInvalidRollupPhaseForEmitChunk, + error +} from './error'; import { NameCollection } from './reservedNames'; type Args = T extends (...args: infer K) => any ? K : never; @@ -136,21 +140,14 @@ export function createPluginDriver( const context: PluginContext = { addWatchFile(id) { - if (graph.phase >= BuildPhase.GENERATE) - this.error({ - code: Errors.INVALID_ROLLUP_PHASE, - message: `Cannot call addWatchFile after the build has finished.` - }); + if (graph.phase >= BuildPhase.GENERATE) this.error(errInvalidRollupPhaseForAddWatchFile()); graph.watchFiles[id] = true; }, cache: cacheInstance, emitAsset, emitChunk(id, options) { if (graph.phase > BuildPhase.LOAD_AND_PARSE) - this.error({ - code: Errors.INVALID_ROLLUP_PHASE, - message: `Cannot call emitChunk after module loading has finished.` - }); + this.error(errInvalidRollupPhaseForEmitChunk()); return graph.moduleLoader.addEntryModuleAndGetReferenceId({ alias: (options && options.name) || null, unresolvedId: id From 3552fdc0df54e9b95bf10c73647b35b6d1a76b6c Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Wed, 1 May 2019 12:15:59 +0200 Subject: [PATCH 55/60] Fix documentation ordering --- docs/05-plugins.md | 59 +++++++++++++--------------------------------- 1 file changed, 17 insertions(+), 42 deletions(-) diff --git a/docs/05-plugins.md b/docs/05-plugins.md index 9a0de3babd3..4051f60aaf7 100644 --- a/docs/05-plugins.md +++ b/docs/05-plugins.md @@ -179,31 +179,6 @@ Kind: `async, parallel` Called initially each time `bundle.generate()` or `bundle.write()` is called. To get notified when generation has completed, use the `generateBundle` and `renderError` hooks. -#### `resolveAssetUrl` -Type: `({assetFileName: string, relativeAssetPath: string, chunkId: string, moduleId: string, format: string}) => string | null`
-Kind: `sync, first` - -Allows to customize how Rollup resolves URLs of assets emitted via `this.emitAsset` by plugins. By default, Rollup will generate code for `import.meta.ROLLUP_ASSET_URL_[assetId]` that should correctly generate absolute URLs of emitted assets independent of the output format and the host system where the code is deployed. - -For that, all formats except CommonJS and UMD assume that they run in a browser environment where `URL` and `document` are available. In case that fails or to generate more optimized code, this hook can be used to customize this behaviour. To do that, the following information is available: - -- `assetFileName`: The path and file name of the emitted asset, relative to `output.dir` without a leading `./`. -- `relativeAssetPath`: The path and file name of the emitted asset, relative to the chunk from which the asset is referenced via `import.meta.ROLLUP_ASSET_URL_[assetId]`. This will also contain no leading `./` but may contain a leading `../`. -- `moduleId`: The id of the original module this asset is referenced from. Useful for conditionally resolving certain assets differently. -- `chunkId`: The id of the chunk this asset is referenced from. -- `format`: The rendered output format. - -Note that since this hook has access to the filename of the current chunk, its return value will not be considered when generating the hash of this chunk. - -The following plugin will always resolve all assets relative to the current document: - -```javascript -// rollup.config.js -resolveAssetUrl({assetFileName}) { - return `new URL('${assetFileName}', document.baseURI).href`; -} -``` - #### `resolveDynamicImport` Type: `(specifier: string | ESTree.Node, importer: string) => string | false | null | {id: string, external?: boolean}`
Kind: `async, first` @@ -219,23 +194,6 @@ In case a dynamic import is not passed a string as argument, this hook gets acce Note that the return value of this hook will not be passed to `resolveId` afterwards; if you need access to the static resolution algorithm, you can use [`this.resolve(source, importer)`](guide/en#this-resolve-source-string-importer-string-promise-id-string-external-boolean-null) on the plugin context. -#### `resolveId` -Type: `(source: string, importer: string) => string | false | null | {id: string, external?: boolean}`
-Kind: `async, first` - -Defines a custom resolver. A resolver can be useful for e.g. locating third-party dependencies. Returning `null` defers to other `resolveId` functions (and eventually the default resolution behavior); returning `false` signals that `source` should be treated as an external module and not included in the bundle. - -If you return an object, then it is possible to resolve an import to a different id while excluding it from the bundle at the same time. This allows you to replace dependencies with external dependencies without the need for the user to mark them as "external" manually via the `external` option: - -```js -resolveId(source) { - if (source === 'my-dependency') { - return {source: 'my-dependency-develop', external: true}; - } - return null; -} -``` - #### `resolveFileUrl` Type: `({assetReferenceId: string | null, chunkId: string, chunkReferenceId: string | null, fileName: string, format: string, moduleId: string, relativePath: string}) => string | null`
Kind: `sync, first` @@ -263,6 +221,23 @@ resolveFileUrl({fileName}) { } ``` +#### `resolveId` +Type: `(source: string, importer: string) => string | false | null | {id: string, external?: boolean}`
+Kind: `async, first` + +Defines a custom resolver. A resolver can be useful for e.g. locating third-party dependencies. Returning `null` defers to other `resolveId` functions (and eventually the default resolution behavior); returning `false` signals that `source` should be treated as an external module and not included in the bundle. + +If you return an object, then it is possible to resolve an import to a different id while excluding it from the bundle at the same time. This allows you to replace dependencies with external dependencies without the need for the user to mark them as "external" manually via the `external` option: + +```js +resolveId(source) { + if (source === 'my-dependency') { + return {source: 'my-dependency-develop', external: true}; + } + return null; +} +``` + #### `resolveImportMeta` Type: `(property: string | null, {chunkId: string, moduleId: string, format: string}) => string | null`
Kind: `sync, first` From 76f65edf7be24275663a6110e10bd315da741d74 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Wed, 1 May 2019 12:17:40 +0200 Subject: [PATCH 56/60] Mark utility functions deprecated in types --- src/rollup/types.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rollup/types.d.ts b/src/rollup/types.d.ts index f1c60625d92..f894cac08ba 100644 --- a/src/rollup/types.d.ts +++ b/src/rollup/types.d.ts @@ -121,10 +121,12 @@ export interface PluginContext extends MinimalPluginContext { importedIds: string[]; isExternal: boolean; }; + /** @deprecated */ isExternal: IsExternal; moduleIds: IterableIterator; parse: (input: string, options: any) => ESTree.Program; resolve: (source: string, importer: string) => Promise; + /** @deprecated */ resolveId: (source: string, importer: string) => Promise; setAssetSource: (assetReferenceId: string, source: string | Buffer) => void; warn: (warning: RollupWarning | string, pos?: { column: number; line: number }) => void; From 4ea16206cbc924001a429c9ee4f0c0367aa5889d Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Thu, 2 May 2019 08:27:04 +0200 Subject: [PATCH 57/60] Use relative ids in error messages --- src/utils/error.ts | 4 ++-- test/function/samples/check-resolve-for-entry/_config.js | 4 ++-- test/function/samples/external-entry-point-object/_config.js | 4 +--- test/function/samples/external-entry-point/_config.js | 4 +--- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/utils/error.ts b/src/utils/error.ts index 7f735a1e2de..95e1f460805 100644 --- a/src/utils/error.ts +++ b/src/utils/error.ts @@ -184,14 +184,14 @@ export function errNamespaceConflict( export function errEntryCannotBeExternal(unresolvedId: string) { return { code: Errors.UNRESOLVED_ENTRY, - message: `Entry module cannot be external (${unresolvedId}).` + message: `Entry module cannot be external (${relativeId(unresolvedId)}).` }; } export function errUnresolvedEntry(unresolvedId: string) { return { code: Errors.UNRESOLVED_ENTRY, - message: `Could not resolve entry module (${unresolvedId}).` + message: `Could not resolve entry module (${relativeId(unresolvedId)}).` }; } diff --git a/test/function/samples/check-resolve-for-entry/_config.js b/test/function/samples/check-resolve-for-entry/_config.js index 6e2ab9abea4..88ef2dd83be 100644 --- a/test/function/samples/check-resolve-for-entry/_config.js +++ b/test/function/samples/check-resolve-for-entry/_config.js @@ -1,10 +1,10 @@ module.exports = { description: 'checks that entry is resolved', options: { - input: '/not/a/path/that/actually/really/exists' + input: 'not/a/path/that/actually/really/exists' }, error: { code: 'UNRESOLVED_ENTRY', - message: 'Could not resolve entry module (/not/a/path/that/actually/really/exists).' + message: 'Could not resolve entry module (not/a/path/that/actually/really/exists).' } }; diff --git a/test/function/samples/external-entry-point-object/_config.js b/test/function/samples/external-entry-point-object/_config.js index 066a4932142..5f27f7b99ac 100644 --- a/test/function/samples/external-entry-point-object/_config.js +++ b/test/function/samples/external-entry-point-object/_config.js @@ -1,5 +1,3 @@ -const path = require('path'); - module.exports = { description: 'throws for entry points that are resolved as an external object by plugins', options: { @@ -11,6 +9,6 @@ module.exports = { }, error: { code: 'UNRESOLVED_ENTRY', - message: `Entry module cannot be external (${path.resolve(__dirname, 'main.js')}).` + message: `Entry module cannot be external (main.js).` } }; diff --git a/test/function/samples/external-entry-point/_config.js b/test/function/samples/external-entry-point/_config.js index 421a4d48fcb..ce44d387343 100644 --- a/test/function/samples/external-entry-point/_config.js +++ b/test/function/samples/external-entry-point/_config.js @@ -1,5 +1,3 @@ -const path = require('path'); - module.exports = { description: 'throws for entry points that are resolved as false by plugins', options: { @@ -11,6 +9,6 @@ module.exports = { }, error: { code: 'UNRESOLVED_ENTRY', - message: `Entry module cannot be external (${path.resolve(__dirname, 'main.js')}).` + message: `Entry module cannot be external (main.js).` } }; From efe30cc926ecb8b5d7622b686182eab7b561c36e Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Thu, 2 May 2019 07:32:30 +0200 Subject: [PATCH 58/60] Allow manualChunks to be a function --- docs/999-big-list-of-options.md | 20 ++++++++-- src/Graph.ts | 10 +++-- src/ModuleLoader.ts | 38 +++++++++++++------ src/rollup/types.d.ts | 5 ++- src/utils/mergeOptions.ts | 1 + .../samples/manual-chunks-function/_config.js | 12 ++++++ .../_expected/amd/chunk-a.js | 9 +++++ .../_expected/amd/generated-chunk-b.js | 7 ++++ .../_expected/amd/generated-chunk-c.js | 5 +++ .../_expected/cjs/chunk-a.js | 10 +++++ .../_expected/cjs/generated-chunk-b.js | 5 +++ .../_expected/cjs/generated-chunk-c.js | 5 +++ .../_expected/es/chunk-a.js | 8 ++++ .../_expected/es/generated-chunk-b.js | 3 ++ .../_expected/es/generated-chunk-c.js | 3 ++ .../_expected/system/chunk-a.js | 15 ++++++++ .../_expected/system/generated-chunk-b.js | 12 ++++++ .../_expected/system/generated-chunk-c.js | 11 ++++++ .../samples/manual-chunks-function/dep-a.js | 4 ++ .../samples/manual-chunks-function/dep-b.js | 3 ++ .../samples/manual-chunks-function/dep-c.js | 3 ++ .../samples/manual-chunks-function/dep1.js | 1 + .../samples/manual-chunks-function/dep2.js | 1 + .../samples/manual-chunks-function/main-a.js | 4 ++ 24 files changed, 175 insertions(+), 20 deletions(-) create mode 100644 test/chunking-form/samples/manual-chunks-function/_config.js create mode 100644 test/chunking-form/samples/manual-chunks-function/_expected/amd/chunk-a.js create mode 100644 test/chunking-form/samples/manual-chunks-function/_expected/amd/generated-chunk-b.js create mode 100644 test/chunking-form/samples/manual-chunks-function/_expected/amd/generated-chunk-c.js create mode 100644 test/chunking-form/samples/manual-chunks-function/_expected/cjs/chunk-a.js create mode 100644 test/chunking-form/samples/manual-chunks-function/_expected/cjs/generated-chunk-b.js create mode 100644 test/chunking-form/samples/manual-chunks-function/_expected/cjs/generated-chunk-c.js create mode 100644 test/chunking-form/samples/manual-chunks-function/_expected/es/chunk-a.js create mode 100644 test/chunking-form/samples/manual-chunks-function/_expected/es/generated-chunk-b.js create mode 100644 test/chunking-form/samples/manual-chunks-function/_expected/es/generated-chunk-c.js create mode 100644 test/chunking-form/samples/manual-chunks-function/_expected/system/chunk-a.js create mode 100644 test/chunking-form/samples/manual-chunks-function/_expected/system/generated-chunk-b.js create mode 100644 test/chunking-form/samples/manual-chunks-function/_expected/system/generated-chunk-c.js create mode 100644 test/chunking-form/samples/manual-chunks-function/dep-a.js create mode 100644 test/chunking-form/samples/manual-chunks-function/dep-b.js create mode 100644 test/chunking-form/samples/manual-chunks-function/dep-c.js create mode 100644 test/chunking-form/samples/manual-chunks-function/dep1.js create mode 100644 test/chunking-form/samples/manual-chunks-function/dep2.js create mode 100644 test/chunking-form/samples/manual-chunks-function/main-a.js diff --git a/docs/999-big-list-of-options.md b/docs/999-big-list-of-options.md index acd4735a55b..5eddb1cb0b3 100755 --- a/docs/999-big-list-of-options.md +++ b/docs/999-big-list-of-options.md @@ -145,7 +145,7 @@ Alternatively, supply a function that will turn an external module ID into a glo When given as a command line argument, it should be a comma-separated list of `id:variableName` pairs: -```bash +``` rollup -i src/main.js ... -g jquery:$,underscore:_ ``` @@ -263,11 +263,23 @@ Default: `false` This will inline dynamic imports instead of creating new chunks to create a single bundle. Only possible if a single input is provided. #### manualChunks -Type: `{ [chunkAlias: string]: string[] }` +Type: `{ [chunkAlias: string]: string[] } | ((id: string) => string | null)` + +Allows the creation of custom shared common chunks. When using the object form, each property represents a chunk that contains the listed modules and all their dependencies if they are part of the module graph unless they are already in another manual chunk. The name of the chunk will be determined by the property key. + +Note that it is not necessary for the listed modules themselves to be be part of the module graph, which is useful if you are working with `rollup-plugin-node-resolve` and use deep imports from packages. For instance + +``` +manualChunks: { + lodash: ['lodash'] +} +``` + +will put all lodash modules into a manual chunk even if you are only using imports of the form `import get from 'lodash/get'`. -Allows the creation of custom shared common chunks. Provides an alias for the chunk and the list of modules to include in that chunk. Modules are bundled into the chunk along with their dependencies. If a module is already in a previous chunk, then the chunk will reference it there. Modules defined into chunks this way are considered to be entry points that can execute independently to any parent importers. +When using the function form, each resolved module id will be passed to the function. If a string is returned, the module and all its dependency will be added to the manual chunk with the given name. -Note that manual chunks can change the behaviour of the application if side-effects are triggered before the corresponding modules are actually used. +Be aware that manual chunks can change the behaviour of the application if side-effects are triggered before the corresponding modules are actually used. #### onwarn Type: `(warning: RollupWarning, defaultHandler: (warning: string | RollupWarning) => void) => void;` diff --git a/src/Graph.ts b/src/Graph.ts index 5a20e022243..dd40cb55caa 100644 --- a/src/Graph.ts +++ b/src/Graph.ts @@ -12,6 +12,7 @@ import { ModuleLoader, UnresolvedModuleWithAlias } from './ModuleLoader'; import { Asset, InputOptions, + ManualChunksOption, ModuleJSON, OutputBundle, RollupCache, @@ -191,13 +192,14 @@ export default class Graph { this, this.moduleById, this.pluginDriver, - options.external + options.external, + typeof options.manualChunks === 'function' && options.manualChunks ); } build( entryModules: string | string[] | Record, - manualChunks: Record | void, + manualChunks: ManualChunksOption | void, inlineDynamicImports: boolean ): Promise { // Phase 1 – discovery. We load the entry module and find which @@ -208,7 +210,9 @@ export default class Graph { return Promise.all([ this.moduleLoader.addEntryModules(normalizeEntryModules(entryModules), true), - manualChunks && this.moduleLoader.addManualChunks(manualChunks) + manualChunks && + typeof manualChunks === 'object' && + this.moduleLoader.addManualChunks(manualChunks) ]).then(([{ entryModules, manualChunkModulesByAlias }]) => { if (entryModules.length === 0) { throw new Error('You must supply options.input to rollup'); diff --git a/src/ModuleLoader.ts b/src/ModuleLoader.ts index 419b33ec6e2..99dd617718b 100644 --- a/src/ModuleLoader.ts +++ b/src/ModuleLoader.ts @@ -4,6 +4,7 @@ import Graph from './Graph'; import Module from './Module'; import { ExternalOption, + GetManualChunk, IsExternal, ModuleJSON, ResolvedId, @@ -50,6 +51,7 @@ export class ModuleLoader { { module: Module | null; name: string } >(); private readonly entryModules: Module[] = []; + private readonly getManualChunk: GetManualChunk; private readonly graph: Graph; private latestLoadModulesPromise: Promise = Promise.resolve(); private readonly manualChunkModules: Record = {}; @@ -60,7 +62,8 @@ export class ModuleLoader { graph: Graph, modulesById: Map, pluginDriver: PluginDriver, - external: ExternalOption + external: ExternalOption, + getManualChunk: GetManualChunk | null ) { this.graph = graph; this.modulesById = modulesById; @@ -72,6 +75,7 @@ export class ModuleLoader { const ids = new Set(Array.isArray(external) ? external : external ? [external] : []); this.isExternal = id => ids.has(id); } + this.getManualChunk = typeof getManualChunk === 'function' ? getManualChunk : () => null; } addEntryModuleAndGetReferenceId(unresolvedEntryModule: UnresolvedModuleWithAlias): string { @@ -134,10 +138,8 @@ export class ModuleLoader { unresolvedManualChunks.map(this.loadEntryModule) ).then(manualChunkModules => { for (const module of manualChunkModules) { - if (!this.manualChunkModules[module.manualChunkAlias]) { - this.manualChunkModules[module.manualChunkAlias] = []; - } - this.manualChunkModules[module.manualChunkAlias].push(module); + // TODO Lukas can we do the assigment and error handling here? + this.addToManualChunk(module.manualChunkAlias, module); } }); @@ -164,6 +166,13 @@ export class ModuleLoader { ).then((result: ResolveIdResult) => this.normalizeResolveIdResult(result, importer, source)); } + private addToManualChunk(alias: string, module: Module) { + if (!this.manualChunkModules[alias]) { + this.manualChunkModules[alias] = []; + } + this.manualChunkModules[alias].push(module); + } + private awaitLoadModulesPromise(loadNewModulesPromise: Promise): Promise { this.latestLoadModulesPromise = Promise.all([ loadNewModulesPromise, @@ -218,6 +227,11 @@ export class ModuleLoader { const module: Module = new Module(this.graph, id); this.modulesById.set(id, module); + const manualChunkAlias = this.getManualChunk(id); + if (typeof manualChunkAlias === 'string') { + module.manualChunkAlias = manualChunkAlias; + this.addToManualChunk(manualChunkAlias, module); + } timeStart('load modules', 3); return Promise.resolve( @@ -350,14 +364,14 @@ export class ModuleLoader { if (typeof id === 'string') { return this.fetchModule(id, undefined).then(module => { - if (alias !== null) { - if (isManualChunkEntry) { - if (module.manualChunkAlias !== null && module.manualChunkAlias !== alias) { - error(errCannotAssignModuleToChunk(module.id, alias, module.manualChunkAlias)); - } - module.manualChunkAlias = alias; - return module; + if (isManualChunkEntry) { + if (module.manualChunkAlias !== null && module.manualChunkAlias !== alias) { + error(errCannotAssignModuleToChunk(module.id, alias, module.manualChunkAlias)); } + module.manualChunkAlias = alias; + return module; + } + if (alias !== null) { if (module.chunkAlias !== null && module.chunkAlias !== alias) { error(errCannotAssignModuleToChunk(module.id, alias, module.chunkAlias)); } diff --git a/src/rollup/types.d.ts b/src/rollup/types.d.ts index f894cac08ba..d2a83d7bff2 100644 --- a/src/rollup/types.d.ts +++ b/src/rollup/types.d.ts @@ -314,9 +314,12 @@ export interface TreeshakingOptions { pureExternalModules?: boolean; } +export type GetManualChunk = (id: string) => string | void; + export type ExternalOption = string[] | IsExternal; export type GlobalsOption = { [name: string]: string } | ((name: string) => string); export type InputOption = string | string[] | { [entryAlias: string]: string }; +export type ManualChunksOption = { [chunkAlias: string]: string[] } | GetManualChunk; export interface InputOptions { acorn?: any; @@ -330,7 +333,7 @@ export interface InputOptions { external?: ExternalOption; inlineDynamicImports?: boolean; input?: InputOption; - manualChunks?: { [chunkAlias: string]: string[] }; + manualChunks?: ManualChunksOption; moduleContext?: ((id: string) => string) | { [id: string]: string }; onwarn?: WarningHandler; perf?: boolean; diff --git a/src/utils/mergeOptions.ts b/src/utils/mergeOptions.ts index 37016d94b5f..63d2a2fcb14 100644 --- a/src/utils/mergeOptions.ts +++ b/src/utils/mergeOptions.ts @@ -56,6 +56,7 @@ const getOnWarn = ( ? warning => config.onwarn(warning, defaultOnWarnHandler) : defaultOnWarnHandler; +// TODO Lukas manual chunks should receive the same treatment const getExternal = (config: GenericConfigObject, command: GenericConfigObject) => { const configExternal = config.external; return typeof configExternal === 'function' diff --git a/test/chunking-form/samples/manual-chunks-function/_config.js b/test/chunking-form/samples/manual-chunks-function/_config.js new file mode 100644 index 00000000000..0ea976037f8 --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-function/_config.js @@ -0,0 +1,12 @@ +module.exports = { + description: 'allows to define manual chunks via a function', + options: { + input: ['main-a'], + manualChunks(id) { + if (id[id.length - 5] === '-') { + console.log(id, id[id.length - 4]); + return `chunk-${id[id.length - 4]}`; + } + } + } +}; diff --git a/test/chunking-form/samples/manual-chunks-function/_expected/amd/chunk-a.js b/test/chunking-form/samples/manual-chunks-function/_expected/amd/chunk-a.js new file mode 100644 index 00000000000..6f202bfb172 --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-function/_expected/amd/chunk-a.js @@ -0,0 +1,9 @@ +define(['./generated-chunk-b', './generated-chunk-c'], function (__chunk_1, __chunk_2) { 'use strict'; + + console.log('dep1'); + + console.log('dep-a'); + + console.log('main-a'); + +}); diff --git a/test/chunking-form/samples/manual-chunks-function/_expected/amd/generated-chunk-b.js b/test/chunking-form/samples/manual-chunks-function/_expected/amd/generated-chunk-b.js new file mode 100644 index 00000000000..234e6a42b0c --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-function/_expected/amd/generated-chunk-b.js @@ -0,0 +1,7 @@ +define(function () { 'use strict'; + + console.log('dep2'); + + console.log('dep-b'); + +}); diff --git a/test/chunking-form/samples/manual-chunks-function/_expected/amd/generated-chunk-c.js b/test/chunking-form/samples/manual-chunks-function/_expected/amd/generated-chunk-c.js new file mode 100644 index 00000000000..ac30fde69d7 --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-function/_expected/amd/generated-chunk-c.js @@ -0,0 +1,5 @@ +define(['./generated-chunk-b'], function (__chunk_1) { 'use strict'; + + console.log('dep-c'); + +}); diff --git a/test/chunking-form/samples/manual-chunks-function/_expected/cjs/chunk-a.js b/test/chunking-form/samples/manual-chunks-function/_expected/cjs/chunk-a.js new file mode 100644 index 00000000000..d65da8d78b5 --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-function/_expected/cjs/chunk-a.js @@ -0,0 +1,10 @@ +'use strict'; + +require('./generated-chunk-b.js'); +require('./generated-chunk-c.js'); + +console.log('dep1'); + +console.log('dep-a'); + +console.log('main-a'); diff --git a/test/chunking-form/samples/manual-chunks-function/_expected/cjs/generated-chunk-b.js b/test/chunking-form/samples/manual-chunks-function/_expected/cjs/generated-chunk-b.js new file mode 100644 index 00000000000..51b3d3e3d98 --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-function/_expected/cjs/generated-chunk-b.js @@ -0,0 +1,5 @@ +'use strict'; + +console.log('dep2'); + +console.log('dep-b'); diff --git a/test/chunking-form/samples/manual-chunks-function/_expected/cjs/generated-chunk-c.js b/test/chunking-form/samples/manual-chunks-function/_expected/cjs/generated-chunk-c.js new file mode 100644 index 00000000000..d8349602bd6 --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-function/_expected/cjs/generated-chunk-c.js @@ -0,0 +1,5 @@ +'use strict'; + +require('./generated-chunk-b.js'); + +console.log('dep-c'); diff --git a/test/chunking-form/samples/manual-chunks-function/_expected/es/chunk-a.js b/test/chunking-form/samples/manual-chunks-function/_expected/es/chunk-a.js new file mode 100644 index 00000000000..ae2fdbf85e5 --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-function/_expected/es/chunk-a.js @@ -0,0 +1,8 @@ +import './generated-chunk-b.js'; +import './generated-chunk-c.js'; + +console.log('dep1'); + +console.log('dep-a'); + +console.log('main-a'); diff --git a/test/chunking-form/samples/manual-chunks-function/_expected/es/generated-chunk-b.js b/test/chunking-form/samples/manual-chunks-function/_expected/es/generated-chunk-b.js new file mode 100644 index 00000000000..16fb2a90267 --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-function/_expected/es/generated-chunk-b.js @@ -0,0 +1,3 @@ +console.log('dep2'); + +console.log('dep-b'); diff --git a/test/chunking-form/samples/manual-chunks-function/_expected/es/generated-chunk-c.js b/test/chunking-form/samples/manual-chunks-function/_expected/es/generated-chunk-c.js new file mode 100644 index 00000000000..78ee7d95de5 --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-function/_expected/es/generated-chunk-c.js @@ -0,0 +1,3 @@ +import './generated-chunk-b.js'; + +console.log('dep-c'); diff --git a/test/chunking-form/samples/manual-chunks-function/_expected/system/chunk-a.js b/test/chunking-form/samples/manual-chunks-function/_expected/system/chunk-a.js new file mode 100644 index 00000000000..791b503f984 --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-function/_expected/system/chunk-a.js @@ -0,0 +1,15 @@ +System.register(['./generated-chunk-b.js', './generated-chunk-c.js'], function (exports, module) { + 'use strict'; + return { + setters: [function () {}, function () {}], + execute: function () { + + console.log('dep1'); + + console.log('dep-a'); + + console.log('main-a'); + + } + }; +}); diff --git a/test/chunking-form/samples/manual-chunks-function/_expected/system/generated-chunk-b.js b/test/chunking-form/samples/manual-chunks-function/_expected/system/generated-chunk-b.js new file mode 100644 index 00000000000..5fe714bfe08 --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-function/_expected/system/generated-chunk-b.js @@ -0,0 +1,12 @@ +System.register([], function (exports, module) { + 'use strict'; + return { + execute: function () { + + console.log('dep2'); + + console.log('dep-b'); + + } + }; +}); diff --git a/test/chunking-form/samples/manual-chunks-function/_expected/system/generated-chunk-c.js b/test/chunking-form/samples/manual-chunks-function/_expected/system/generated-chunk-c.js new file mode 100644 index 00000000000..6486e19b0b8 --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-function/_expected/system/generated-chunk-c.js @@ -0,0 +1,11 @@ +System.register(['./generated-chunk-b.js'], function (exports, module) { + 'use strict'; + return { + setters: [function () {}], + execute: function () { + + console.log('dep-c'); + + } + }; +}); diff --git a/test/chunking-form/samples/manual-chunks-function/dep-a.js b/test/chunking-form/samples/manual-chunks-function/dep-a.js new file mode 100644 index 00000000000..5cf180c1404 --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-function/dep-a.js @@ -0,0 +1,4 @@ +import './dep-c'; +import './dep1'; + +console.log('dep-a'); diff --git a/test/chunking-form/samples/manual-chunks-function/dep-b.js b/test/chunking-form/samples/manual-chunks-function/dep-b.js new file mode 100644 index 00000000000..67c590f583e --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-function/dep-b.js @@ -0,0 +1,3 @@ +import './dep2'; + +console.log('dep-b'); diff --git a/test/chunking-form/samples/manual-chunks-function/dep-c.js b/test/chunking-form/samples/manual-chunks-function/dep-c.js new file mode 100644 index 00000000000..3934b0ad90e --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-function/dep-c.js @@ -0,0 +1,3 @@ +import './dep2'; + +console.log('dep-c'); diff --git a/test/chunking-form/samples/manual-chunks-function/dep1.js b/test/chunking-form/samples/manual-chunks-function/dep1.js new file mode 100644 index 00000000000..6aa6066cec9 --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-function/dep1.js @@ -0,0 +1 @@ +console.log('dep1'); diff --git a/test/chunking-form/samples/manual-chunks-function/dep2.js b/test/chunking-form/samples/manual-chunks-function/dep2.js new file mode 100644 index 00000000000..f5325d80e8a --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-function/dep2.js @@ -0,0 +1 @@ +console.log('dep2'); diff --git a/test/chunking-form/samples/manual-chunks-function/main-a.js b/test/chunking-form/samples/manual-chunks-function/main-a.js new file mode 100644 index 00000000000..cf97f330a79 --- /dev/null +++ b/test/chunking-form/samples/manual-chunks-function/main-a.js @@ -0,0 +1,4 @@ +import './dep-a'; +import './dep-b'; + +console.log('main-a'); From 3201c392af6a395a1890e5c61286bfb00d11c59a Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Thu, 2 May 2019 07:42:36 +0200 Subject: [PATCH 59/60] Only add manual chunks in a single location --- src/ModuleLoader.ts | 30 ++++++++----------- .../samples/manual-chunks-conflict/_config.js | 2 +- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/ModuleLoader.ts b/src/ModuleLoader.ts index 99dd617718b..140d83c0049 100644 --- a/src/ModuleLoader.ts +++ b/src/ModuleLoader.ts @@ -37,7 +37,7 @@ export interface UnresolvedModuleWithAlias { } interface UnresolvedEntryModuleWithAlias extends UnresolvedModuleWithAlias { - isManualChunkEntry?: boolean; + manualChunkAlias?: string; } function normalizeRelativeExternalId(importer: string, source: string) { @@ -131,15 +131,17 @@ export class ModuleLoader { for (const alias of Object.keys(manualChunks)) { const manualChunkIds = manualChunks[alias]; for (const unresolvedId of manualChunkIds) { - unresolvedManualChunks.push({ alias, unresolvedId, isManualChunkEntry: true }); + unresolvedManualChunks.push({ alias: null, unresolvedId, manualChunkAlias: alias }); } } const loadNewManualChunkModulesPromise = Promise.all( unresolvedManualChunks.map(this.loadEntryModule) ).then(manualChunkModules => { - for (const module of manualChunkModules) { - // TODO Lukas can we do the assigment and error handling here? - this.addToManualChunk(module.manualChunkAlias, module); + for (let index = 0; index < manualChunkModules.length; index++) { + this.addToManualChunk( + unresolvedManualChunks[index].manualChunkAlias, + manualChunkModules[index] + ); } }); @@ -167,6 +169,10 @@ export class ModuleLoader { } private addToManualChunk(alias: string, module: Module) { + if (module.manualChunkAlias !== null && module.manualChunkAlias !== alias) { + error(errCannotAssignModuleToChunk(module.id, alias, module.manualChunkAlias)); + } + module.manualChunkAlias = alias; if (!this.manualChunkModules[alias]) { this.manualChunkModules[alias] = []; } @@ -229,7 +235,6 @@ export class ModuleLoader { this.modulesById.set(id, module); const manualChunkAlias = this.getManualChunk(id); if (typeof manualChunkAlias === 'string') { - module.manualChunkAlias = manualChunkAlias; this.addToManualChunk(manualChunkAlias, module); } @@ -343,11 +348,7 @@ export class ModuleLoader { return resolvedId; } - private loadEntryModule = ({ - alias, - unresolvedId, - isManualChunkEntry - }: UnresolvedEntryModuleWithAlias): Promise => + private loadEntryModule = ({ alias, unresolvedId }: UnresolvedModuleWithAlias): Promise => this.pluginDriver .hookFirst('resolveId', [unresolvedId, undefined]) .then((resolveIdResult: ResolveIdResult) => { @@ -364,13 +365,6 @@ export class ModuleLoader { if (typeof id === 'string') { return this.fetchModule(id, undefined).then(module => { - if (isManualChunkEntry) { - if (module.manualChunkAlias !== null && module.manualChunkAlias !== alias) { - error(errCannotAssignModuleToChunk(module.id, alias, module.manualChunkAlias)); - } - module.manualChunkAlias = alias; - return module; - } if (alias !== null) { if (module.chunkAlias !== null && module.chunkAlias !== alias) { error(errCannotAssignModuleToChunk(module.id, alias, module.chunkAlias)); diff --git a/test/function/samples/manual-chunks-conflict/_config.js b/test/function/samples/manual-chunks-conflict/_config.js index e07a6cf5cbd..75d353007fd 100644 --- a/test/function/samples/manual-chunks-conflict/_config.js +++ b/test/function/samples/manual-chunks-conflict/_config.js @@ -9,6 +9,6 @@ module.exports = { }, error: { code: 'INVALID_CHUNK', - message: `Cannot assign dep.js to the "dep1" chunk as it is already in the "dep2" chunk.` + message: `Cannot assign dep.js to the "dep2" chunk as it is already in the "dep1" chunk.` } }; From 261d6cad1e35e1940d5ff60b4858a36a15c5c605 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Thu, 2 May 2019 08:16:53 +0200 Subject: [PATCH 60/60] Add vendor chunk example --- docs/999-big-list-of-options.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/999-big-list-of-options.md b/docs/999-big-list-of-options.md index 5eddb1cb0b3..ca20a3acff9 100755 --- a/docs/999-big-list-of-options.md +++ b/docs/999-big-list-of-options.md @@ -263,7 +263,7 @@ Default: `false` This will inline dynamic imports instead of creating new chunks to create a single bundle. Only possible if a single input is provided. #### manualChunks -Type: `{ [chunkAlias: string]: string[] } | ((id: string) => string | null)` +Type: `{ [chunkAlias: string]: string[] } | ((id: string) => string | void)` Allows the creation of custom shared common chunks. When using the object form, each property represents a chunk that contains the listed modules and all their dependencies if they are part of the module graph unless they are already in another manual chunk. The name of the chunk will be determined by the property key. @@ -277,7 +277,15 @@ manualChunks: { will put all lodash modules into a manual chunk even if you are only using imports of the form `import get from 'lodash/get'`. -When using the function form, each resolved module id will be passed to the function. If a string is returned, the module and all its dependency will be added to the manual chunk with the given name. +When using the function form, each resolved module id will be passed to the function. If a string is returned, the module and all its dependency will be added to the manual chunk with the given name. For instance this will create a `vendor` chunk containing all dependencies inside `node_modules`: + +```javascript +manualChunks(id) { + if (id.includes('node_modules')) { + return 'vendor'; + } +} +``` Be aware that manual chunks can change the behaviour of the application if side-effects are triggered before the corresponding modules are actually used.