diff --git a/docs/05-plugin-development.md b/docs/05-plugin-development.md index 1b390d89bc7..fb14089cae4 100644 --- a/docs/05-plugin-development.md +++ b/docs/05-plugin-development.md @@ -365,11 +365,11 @@ Additionally, [`closeBundle`](guide/en/#closebundle) can be called as the very l #### `augmentChunkHash` -**Type:** `(chunkInfo: ChunkInfo) => string`
**Kind:** `sync, sequential`
**Previous Hook:** [`renderDynamicImport`](guide/en/#renderdynamicimport) for each dynamic import expression.
**Next Hook:** [`resolveFileUrl`](guide/en/#resolvefileurl) for each use of `import.meta.ROLLUP_FILE_URL_referenceId` and [`resolveImportMeta`](guide/en/#resolveimportmeta) for all other accesses to `import.meta`. +**Type:** `(chunkInfo: ChunkInfo) => string`
**Kind:** `sync, sequential`
**Previous Hook:** [`renderChunk`](guide/en/#renderchunk).
**Next Hook:** [`renderChunk`](guide/en/#renderchunk) if there are other chunks that still need to be processed, otherwise [`generateBundle`](guide/en/#generatebundle). -Can be used to augment the hash of individual chunks. Called for each Rollup output chunk. Returning a falsy value will not modify the hash. Truthy values will be passed to [`hash.update`](https://nodejs.org/dist/latest-v12.x/docs/api/crypto.html#crypto_hash_update_data_inputencoding). The `chunkInfo` is a reduced version of the one in [`generateBundle`](guide/en/#generatebundle) without properties that rely on file names. +Can be used to augment the hash of individual chunks. Called for each Rollup output chunk. Returning a falsy value will not modify the hash. Truthy values will be passed to [`hash.update`](https://nodejs.org/dist/latest-v12.x/docs/api/crypto.html#crypto_hash_update_data_inputencoding). The `chunkInfo` is a reduced version of the one in [`generateBundle`](guide/en/#generatebundle) without `code` and `map` and using placeholders for hashes in file names. -The following plugin will invalidate the hash of chunk `foo` with the timestamp of the last build: +The following plugin will invalidate the hash of chunk `foo` with the current timestamp: ```js function augmentWithDatePlugin() { @@ -386,7 +386,7 @@ function augmentWithDatePlugin() { #### `banner` -**Type:** `string | (() => string)`
**Kind:** `async, parallel`
**Previous Hook:** [`renderStart`](guide/en/#renderstart)
**Next Hook:** [`renderDynamicImport`](guide/en/#renderdynamicimport) for each dynamic import expression. +**Type:** `string | ((chunk: ChunkInfo) => string)`
**Kind:** `async, sequential`
**Previous Hook:** [`resolveFileUrl`](guide/en/#resolvefileurl) for each use of `import.meta.ROLLUP_FILE_URL_referenceId` and [`resolveImportMeta`](guide/en/#resolveimportmeta) for all other accesses to `import.meta` in the current chunk.
**Next Hook:** [`renderDynamicImport`](guide/en/#renderdynamicimport) for each dynamic import expression in the next chunk if there is another one, otherwise [`renderChunk`](guide/en/#renderchunk) for the first chunk. Cf. [`output.banner/output.footer`](guide/en/#outputbanneroutputfooter). @@ -400,13 +400,13 @@ If a plugin wants to retain resources across builds in watch mode, they can chec #### `footer` -**Type:** `string | (() => string)`
**Kind:** `async, parallel`
**Previous Hook:** [`renderStart`](guide/en/#renderstart)
**Next Hook:** [`renderDynamicImport`](guide/en/#renderdynamicimport) for each dynamic import expression. +**Type:** `string | ((chunk: ChunkInfo) => string)`
**Kind:** `async, sequential`
**Previous Hook:** [`resolveFileUrl`](guide/en/#resolvefileurl) for each use of `import.meta.ROLLUP_FILE_URL_referenceId` and [`resolveImportMeta`](guide/en/#resolveimportmeta) for all other accesses to `import.meta` in the current chunk.
**Next Hook:** [`renderDynamicImport`](guide/en/#renderdynamicimport) for each dynamic import expression in the next chunk if there is another one, otherwise [`renderChunk`](guide/en/#renderchunk) for the first chunk. Cf. [`output.banner/output.footer`](guide/en/#outputbanneroutputfooter). #### `generateBundle` -**Type:** `(options: OutputOptions, bundle: { [fileName: string]: AssetInfo | ChunkInfo }, isWrite: boolean) => void`
**Kind:** `async, sequential`
**Previous Hook:** [`renderChunk`](guide/en/#renderchunk) for each chunk.
**Next Hook:** [`writeBundle`](guide/en/#writebundle) if the output was generated via `bundle.write(...)`, otherwise this is the last hook of the output generation phase and may again be followed by [`outputOptions`](guide/en/#outputoptions) if another output is generated. +**Type:** `(options: OutputOptions, bundle: { [fileName: string]: AssetInfo | ChunkInfo }, isWrite: boolean) => void`
**Kind:** `async, sequential`
**Previous Hook:** [`augmentChunkHash`](guide/en/#augmentchunkhash).
**Next Hook:** [`writeBundle`](guide/en/#writebundle) if the output was generated via `bundle.write(...)`, otherwise this is the last hook of the output generation phase and may again be followed by [`outputOptions`](guide/en/#outputoptions) if another output is generated. Called at the end of `bundle.generate()` or immediately before the files are written in `bundle.write()`. To modify the files after they have been written, use the [`writeBundle`](guide/en/#writebundle) hook. `bundle` provides the full list of files being written or generated along with their details: @@ -440,6 +440,7 @@ type ChunkInfo = { code: string | null; }; }; + moduleIds: string[]; name: string; referencedFiles: string[]; type: 'chunk'; @@ -450,7 +451,7 @@ You can prevent files from being emitted by deleting them from the bundle object #### `intro` -**Type:** `string | (() => string)`
**Kind:** `async, parallel`
**Previous Hook:** [`renderStart`](guide/en/#renderstart)
**Next Hook:** [`renderDynamicImport`](guide/en/#renderdynamicimport) for each dynamic import expression. +**Type:** `string | ((chunk: ChunkInfo) => string)`
**Kind:** `async, sequential`
**Previous Hook:** [`resolveFileUrl`](guide/en/#resolvefileurl) for each use of `import.meta.ROLLUP_FILE_URL_referenceId` and [`resolveImportMeta`](guide/en/#resolveimportmeta) for all other accesses to `import.meta` in the current chunk.
**Next Hook:** [`renderDynamicImport`](guide/en/#renderdynamicimport) for each dynamic import expression in the next chunk if there is another one, otherwise [`renderChunk`](guide/en/#renderchunk) for the first chunk. Cf. [`output.intro/output.outro`](guide/en/#outputintrooutputoutro). @@ -462,19 +463,28 @@ Replaces or manipulates the output options object passed to `bundle.generate()` #### `outro` -**Type:** `string | (() => string)`
**Kind:** `async, parallel`
**Previous Hook:** [`renderStart`](guide/en/#renderstart)
**Next Hook:** [`renderDynamicImport`](guide/en/#renderdynamicimport) for each dynamic import expression. +**Type:** `string | ((chunk: ChunkInfo) => string)`
**Kind:** `async, sequential`
**Previous Hook:** [`resolveFileUrl`](guide/en/#resolvefileurl) for each use of `import.meta.ROLLUP_FILE_URL_referenceId` and [`resolveImportMeta`](guide/en/#resolveimportmeta) for all other accesses to `import.meta` in the current chunk.
**Next Hook:** [`renderDynamicImport`](guide/en/#renderdynamicimport) for each dynamic import expression in the next chunk if there is another one, otherwise [`renderChunk`](guide/en/#renderchunk) for the first chunk. Cf. [`output.intro/output.outro`](guide/en/#outputintrooutputoutro). #### `renderChunk` -**Type:** `(code: string, chunk: ChunkInfo, options: OutputOptions) => string | { code: string, map: SourceMap } | null`
**Kind:** `async, sequential`
**Previous Hook:** [`resolveFileUrl`](guide/en/#resolvefileurl) for each use of `import.meta.ROLLUP_FILE_URL_referenceId` and [`resolveImportMeta`](guide/en/#resolveimportmeta) for all other accesses to `import.meta`.
**Next Hook:** [`generateBundle`](guide/en/#generatebundle). +**Type:** `(code: string, chunk: ChunkInfo, options: OutputOptions, meta: { chunks: {[id: string]: ChunkInfo} }) => string | { code: string, map: SourceMap } | null`
**Kind:** `async, sequential`
**Previous Hook:** [`banner`](guide/en/#banner), [`footer`](guide/en/#footer), [`intro`](guide/en/#intro), [`outro`](guide/en/#outro) of the last chunk.
**Next Hook:** [`augmentChunkHash`](guide/en/#augmentchunkhash). -Can be used to transform individual chunks. Called for each Rollup output chunk file. Returning `null` will apply no transformations. +Can be used to transform individual chunks. Called for each Rollup output chunk file. Returning `null` will apply no transformations. If you change code in this hook and want to support source maps, you need to return a `map` describing your changes, see [the section on source code transformations](#source-code-transformations). + +`chunk` contains additional information about the chunk using the same `ChunkInfo` type as the [`generateBundle`](guide/en/#generatebundle) hook with the following differences: + +- `code` and `map` are not set. Instead, use the `code` parameter of this hook. +- all referenced chunk file names that would contain hashes will contain hash placeholders instead. This includes `fileName`, `imports`, `importedBindings`, `dynamicImports` and `implicitlyLoadedBefore`. When you use such a placeholder file name or part of it in the code returned from this hook, Rollup will replace the placeholder with the actual hash before `generateBundle`, making sure the hash reflects the actual content of the final generated chunk including all referenced file hashes. + +`chunk` is mutable and changes applied in this hook will propagate to other plugins and to the generated bundle. That means if you add or remove imports or exports in this hook, you should update `imports`, `importedBindings` and/or `exports`. + +`meta.chunks` contains information about all the chunks Rollup is generating and gives you access to their `ChunkInfo`, again using placeholders for hashes. That means you can explore the entire chunk graph in this hook. #### `renderDynamicImport` -**Type:** `({format: string, moduleId: string, targetModuleId: string | null, customResolution: string | null}) => {left: string, right: string} | null`
**Kind:** `sync, first`
**Previous Hook:** [`banner`](guide/en/#banner), [`footer`](guide/en/#footer), [`intro`](guide/en/#intro), [`outro`](guide/en/#outro).
**Next Hook:** [`augmentChunkHash`](guide/en/#augmentchunkhash) for each chunk that would contain a hash in the file name. +**Type:** `({format: string, moduleId: string, targetModuleId: string | null, customResolution: string | null}) => {left: string, right: string} | null`
**Kind:** `sync, first`
**Previous Hook:** [`renderStart`](guide/en/#renderstart) if this is the first chunk, otherwise [`banner`](guide/en/#banner), [`footer`](guide/en/#footer), [`intro`](guide/en/#intro), [`outro`](guide/en/#outro) of the previous chunk.
**Next Hook:** [`resolveFileUrl`](guide/en/#resolvefileurl) for each use of `import.meta.ROLLUP_FILE_URL_referenceId` and [`resolveImportMeta`](guide/en/#resolveimportmeta) for all other accesses to `import.meta` in the current chunk. This hook provides fine-grained control over how dynamic imports are rendered by providing replacements for the code to the left (`import(`) and right (`)`) of the argument of the import expression. Returning `null` defers to other hooks of this type and ultimately renders a format-specific default. @@ -534,27 +544,25 @@ Called when rollup encounters an error during `bundle.generate()` or `bundle.wri #### `renderStart` -**Type:** `(outputOptions: OutputOptions, inputOptions: InputOptions) => void`
**Kind:** `async, parallel`
**Previous Hook:** [`outputOptions`](guide/en/#outputoptions)
**Next Hook:** [`banner`](guide/en/#banner), [`footer`](guide/en/#footer), [`intro`](guide/en/#intro) and [`outro`](guide/en/#outro) run in parallel. +**Type:** `(outputOptions: OutputOptions, inputOptions: InputOptions) => void`
**Kind:** `async, parallel`
**Previous Hook:** [`outputOptions`](guide/en/#outputoptions)
**Next Hook:** [`renderDynamicImport`](guide/en/#renderdynamicimport) for each dynamic import expression in the first chunk. Called initially each time `bundle.generate()` or `bundle.write()` is called. To get notified when generation has completed, use the `generateBundle` and `renderError` hooks. This is the recommended hook to use when you need access to the output options passed to `bundle.generate()` or `bundle.write()` as it takes the transformations by all [`outputOptions`](guide/en/#outputoptions) hooks into account and also contains the right default values for unset options. It also receives the input options passed to `rollup.rollup()` so that plugins that can be used as output plugins, i.e. plugins that only use `generate` phase hooks, can get access to them. #### `resolveFileUrl` -**Type:** `({chunkId: string, fileName: string, format: string, moduleId: string, referenceId: string, relativePath: string}) => string | null`
**Kind:** `sync, first`
**Previous Hook:** [`augmentChunkHash`](guide/en/#augmentchunkhash) for each chunk that would contain a hash in the file name.
**Next Hook:** [`renderChunk`](guide/en/#renderchunk) for each chunk. +**Type:** `({chunkId: string, fileName: string, format: string, moduleId: string, referenceId: string, relativePath: string}) => string | null`
**Kind:** `sync, first`
**Previous Hook:** [`renderDynamicImport`](guide/en/#renderdynamicimport) for each dynamic import expression in the current chunk
**Next Hook:** [`banner`](guide/en/#banner), [`footer`](guide/en/#footer), [`intro`](guide/en/#intro), [`outro`](guide/en/#outro) in parallel for the current chunk. Allows to customize how Rollup resolves URLs of files that were emitted by plugins via `this.emitFile`. By default, Rollup will generate code for `import.meta.ROLLUP_FILE_URL_referenceId` 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: -- `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 `./`. +- `chunkId`: The id of the chunk this file is referenced from. If the chunk file name would contain a hash, this id will contain a placeholder instead. Rollup will replace this placeholder with the actual file name if it ends up in the generated code. +- `fileName`: The path and file name of the emitted file, relative to `output.dir` without a leading `./`. Again if this is a chunk that would have a hash in its name, it will contain a placeholder instead. - `format`: The rendered output format. - `moduleId`: The id of the original module this file is referenced from. Useful for conditionally resolving certain assets differently. - `referenceId`: The reference id of the file. - `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 `../`. -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 files relative to the current document: ```js @@ -570,7 +578,7 @@ function resolveToDocumentPlugin() { #### `resolveImportMeta` -**Type:** `(property: string | null, {chunkId: string, moduleId: string, format: string}) => string | null`
**Kind:** `sync, first`
**Previous Hook:** [`augmentChunkHash`](guide/en/#augmentchunkhash) for each chunk that would contain a hash in the file name.
**Next Hook:** [`renderChunk`](guide/en/#renderchunk) for each chunk. +**Type:** `(property: string | null, {chunkId: string, moduleId: string, format: string}) => string | null`
**Kind:** `sync, first`
**Previous Hook:** [`renderDynamicImport`](guide/en/#renderdynamicimport) for each dynamic import expression in the current chunk
**Next Hook:** [`banner`](guide/en/#banner), [`footer`](guide/en/#footer), [`intro`](guide/en/#intro), [`outro`](guide/en/#outro) in parallel for the current chunk. Allows to customize how Rollup handles `import.meta` and `import.meta.someProperty`, in particular `import.meta.url`. In ES modules, `import.meta` is an object and `import.meta.url` contains the URL of the current module, e.g. `http://server.net/bundle.js` for browsers or `file:///path/to/bundle.js` in Node. @@ -592,7 +600,7 @@ function importMetaUrlCurrentModulePlugin() { } ``` -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. +If the `chunkId` would contain a hash, it will contain a placeholder instead. If this placeholder ends up in the generated code, Rollup will replace it with the actual chunk hash. #### `writeBundle` @@ -643,7 +651,11 @@ In both cases, either a `name` or a `fileName` can be supplied. If a `fileName` You can reference the URL of an emitted file in any code returned by a [`load`](guide/en/#load) or [`transform`](guide/en/#transform) plugin hook via `import.meta.ROLLUP_FILE_URL_referenceId`. See [File URLs](guide/en/#file-urls) for more details and an example. -The generated code that replaces `import.meta.ROLLUP_FILE_URL_referenceId` can be customized via the [`resolveFileUrl`](guide/en/#resolvefileurl) plugin hook. You can also use [`this.getFileName(referenceId)`](guide/en/#thisgetfilename) to determine the file name as soon as it is available +The generated code that replaces `import.meta.ROLLUP_FILE_URL_referenceId` can be customized via the [`resolveFileUrl`](guide/en/#resolvefileurl) plugin hook. You can also use [`this.getFileName(referenceId)`](guide/en/#thisgetfilename) to determine the file name as soon as it is available. If the file name is not set explicitly, then + +- asset file names are available starting with the [`renderStart`](guide/en/#renderstart) hook. For assets that are emitted later, the file name will be available immediately after emitting the asset. +- chunk file names that do not contain a hash are available as soon as chunks are created after the `renderStart` hook. +- if a chunk file name would contain a hash, using `getFileName` in any hook before [`generateBundle`](guide/en/#generatebundle) will return a name containing a placeholder instead of the actual name. If you use this file name or parts of it in a chunk you transform in [`renderChunk`](guide/en/#renderchunk), Rollup will replace the placeholder with the actual hash before `generateBundle`, making sure the hash reflects the actual content of the final generated chunk including all referenced file hashes. If the `type` is _`chunk`_, then this emits a new chunk with the given module `id` as entry point. To resolve it, the `id` will be passed through build hooks just like regular entry points, starting with [`resolveId`](guide/en/#resolveid). If an `importer` is provided, this acts as the second parameter of `resolveId` and is important to properly resolve relative paths. If it is not provided, paths will be resolved relative to the current working directory. If a value for `preserveSignature` is provided, this will override [`preserveEntrySignatures`](guide/en/#preserveentrysignatures) for this particular chunk. @@ -1127,7 +1139,9 @@ function transformCodePlugin(options = {}) { #### Source Code Transformations -If a plugin transforms source code, it should generate a sourcemap automatically, unless there's a specific `sourceMap: false` option. Rollup only cares about the `mappings` property (everything else is handled automatically). If it doesn't make sense to generate a sourcemap, (e.g. [rollup-plugin-string](https://github.com/TrySound/rollup-plugin-string)), return an empty sourcemap: +If a plugin transforms source code, it should generate a sourcemap automatically, unless there's a specific `sourceMap: false` option. Rollup only cares about the `mappings` property (everything else is handled automatically). [magic-string](https://github.com/Rich-Harris/magic-string) provides a simple way to generate such a map for elementary transformations like adding or removing code snippets. + +If it doesn't make sense to generate a sourcemap, (e.g. [rollup-plugin-string](https://github.com/TrySound/rollup-plugin-string)), return an empty sourcemap: ```js return { diff --git a/docs/999-big-list-of-options.md b/docs/999-big-list-of-options.md index a022d0bd2c5..3e88edb7487 100755 --- a/docs/999-big-list-of-options.md +++ b/docs/999-big-list-of-options.md @@ -389,17 +389,24 @@ The pattern to use for naming custom emitted assets to include in the build outp - `[extname]`: The file extension of the asset including a leading dot, e.g. `.css`. - `[ext]`: The file extension without a leading dot, e.g. `css`. -- `[hash]`: A hash based on the name and content of the asset. +- `[hash]`: A hash based on the content of the asset. You can also set a specific hash length via e.g. `[hash:10]`. - `[name]`: The file name of the asset excluding any extension. Forward slashes `/` can be used to place files in sub-directories. When using a function, `assetInfo` is a reduced version of the one in [`generateBundle`](guide/en/#generatebundle) without the `fileName`. See also [`output.chunkFileNames`](guide/en/#outputchunkfilenames), [`output.entryFileNames`](guide/en/#outputentryfilenames). #### output.banner/output.footer -Type: `string | (() => string | Promise)`
CLI: `--banner`/`--footer ` +Type: `string | ((chunk: ChunkInfo) => string | Promise)`
CLI: `--banner`/`--footer ` A string to prepend/append to the bundle. You can also supply a function that returns a `Promise` that resolves to a `string` to generate it asynchronously (Note: `banner` and `footer` options will not break sourcemaps). +If you supply a function, `chunk` contains additional information about the chunk using the same `ChunkInfo` type as the [`generateBundle`](guide/en/#generatebundle) hook with the following differences: + +- `code` and `map` are not set as the chunk has not been rendered yet. +- all referenced chunk file names that would contain hashes will contain hash placeholders instead. This includes `fileName`, `imports`, `importedBindings`, `dynamicImports` and `implicitlyLoadedBefore`. When you use such a placeholder file name or part of it in the code returned from this option, Rollup will replace the placeholder with the actual hash before `generateBundle`, making sure the hash reflects the actual content of the final generated chunk including all referenced file hashes. + +`chunk` is mutable and changes applied in this hook will propagate to other plugins and to the generated bundle. That means if you add or remove imports or exports in this hook, you should update `imports`, `importedBindings` and/or `exports`. + ```js // rollup.config.js export default { @@ -421,10 +428,10 @@ Type: `string | ((chunkInfo: ChunkInfo) => string)`
CLI: `--chunkFileNames < The pattern to use for naming shared chunks created when code-splitting, or a function that is called per chunk to return such a pattern. Patterns support the following placeholders: - `[format]`: The rendering format defined in the output options, e.g. `es` or `cjs`. -- `[hash]`: A hash based on the content of the chunk and the content of all its dependencies. +- `[hash]`: A hash based only on the content of the final generated chunk, including transformations in [`renderChunk`](guide/en/#renderchunk) and any referenced file hashes. You can also set a specific hash length via e.g. `[hash:10]`. - `[name]`: The name of the chunk. This can be explicitly set via the [`output.manualChunks`](guide/en/#outputmanualchunks) option or when the chunk is created by a plugin via [`this.emitFile`](guide/en/#thisemitfile). Otherwise, it will be derived from the chunk contents. -Forward slashes `/` can be used to place files in sub-directories. When using a function, `chunkInfo` is a reduced version of the one in [`generateBundle`](guide/en/#generatebundle) without properties that depend on file names. See also [`output.assetFileNames`](guide/en/#outputassetfilenames), [`output.entryFileNames`](guide/en/#outputentryfilenames). +Forward slashes `/` can be used to place files in sub-directories. When using a function, `chunkInfo` is a reduced version of the one in [`generateBundle`](guide/en/#generatebundle) without properties that depend on file names and no information about the rendered modules as rendering only happens after file names have been generated. You can however access a list of included `moduleIds`. See also [`output.assetFileNames`](guide/en/#outputassetfilenames), [`output.entryFileNames`](guide/en/#outputentryfilenames). #### output.compact @@ -439,10 +446,10 @@ Type: `string | ((chunkInfo: ChunkInfo) => string)`
CLI: `--entryFileNames < The pattern to use for chunks created from entry points, or a function that is called per entry chunk to return such a pattern. Patterns support the following placeholders: - `[format]`: The rendering format defined in the output options, e.g. `es` or `cjs`. -- `[hash]`: A hash based on the content of the entry point and the content of all its dependencies. +- `[hash]`: A hash based only on the content of the final generated entry chunk, including transformations in [`renderChunk`](guide/en/#renderchunk) and any referenced file hashes. You can also set a specific hash length via e.g. `[hash:10]`. - `[name]`: The file name (without extension) of the entry point, unless the object form of input was used to define a different name. -Forward slashes `/` can be used to place files in sub-directories. When using a function, `chunkInfo` is a reduced version of the one in [`generateBundle`](guide/en/#generatebundle) without properties that depend on file names. See also [`output.assetFileNames`](guide/en/#outputassetfilenames), [`output.chunkFileNames`](guide/en/#outputchunkfilenames). +Forward slashes `/` can be used to place files in sub-directories. When using a function, `chunkInfo` is a reduced version of the one in [`generateBundle`](guide/en/#generatebundle) without properties that depend on file names and no information about the rendered modules as rendering only happens after file names have been generated. You can however access a list of included `moduleIds`. See also [`output.assetFileNames`](guide/en/#outputassetfilenames), [`output.chunkFileNames`](guide/en/#outputchunkfilenames). This pattern will also be used when setting the [`output.preserveModules`](guide/en/#outputpreservemodules) option. Here a different set of placeholders is available, though: @@ -809,7 +816,7 @@ There are some additional options that have an effect on the generated interop c #### output.intro/output.outro -Type: `string | (() => string | Promise)`
CLI: `--intro`/`--outro ` +Type: `string | ((chunk: ChunkInfo) => string | Promise)`
CLI: `--intro`/`--outro ` Similar to [`output.banner/output.footer`](guide/en/#outputbanneroutputfooter), except that the code goes _inside_ any format-specific wrapper. diff --git a/docs/build-hooks.mmd b/docs/build-hooks.mmd index f86760ed215..484a98c9187 100644 --- a/docs/build-hooks.mmd +++ b/docs/build-hooks.mmd @@ -1,4 +1,5 @@ flowchart TB + classDef default fill:transparent, color:#000; classDef hook-parallel fill:#ffb3b3,stroke:#000; classDef hook-sequential fill:#ffd2b3,stroke:#000; classDef hook-first fill:#fff2b3,stroke:#000; diff --git a/docs/output-generation-hooks.mmd b/docs/output-generation-hooks.mmd index 989ea902170..eccecdc9550 100644 --- a/docs/output-generation-hooks.mmd +++ b/docs/output-generation-hooks.mmd @@ -1,5 +1,5 @@ flowchart TB - classDef default fill:#fff; + classDef default fill:transparent, color:#000; classDef hook-parallel fill:#ffb3b3,stroke:#000; classDef hook-sequential fill:#ffd2b3,stroke:#000; classDef hook-first fill:#fff2b3,stroke:#000; @@ -9,25 +9,25 @@ flowchart TB augmentchunkhash("augmentChunkHash"):::hook-sequential-sync click augmentchunkhash "/guide/en/#augmentchunkhash" _parent - banner("banner"):::hook-parallel + banner("banner"):::hook-sequential click banner "/guide/en/#banner" _parent closebundle("closeBundle"):::hook-parallel click closebundle "/guide/en/#closebundle" _parent - footer("footer"):::hook-parallel + footer("footer"):::hook-sequential click footer "/guide/en/#footer" _parent generatebundle("generateBundle"):::hook-sequential click generatebundle "/guide/en/#generatebundle" _parent - intro("intro"):::hook-parallel + intro("intro"):::hook-sequential click intro "/guide/en/#intro" _parent outputoptions("outputOptions"):::hook-sequential-sync click outputoptions "/guide/en/#outputoptions" _parent - outro("outro"):::hook-parallel + outro("outro"):::hook-sequential click outro "/guide/en/#outro" _parent renderchunk("renderChunk"):::hook-sequential @@ -54,27 +54,47 @@ flowchart TB outputoptions --> renderstart - --> banner & footer & intro & outro - --> beforerenderdynamicimport(( )) - --> beforeaugmentchunkhash(( )) - --> |each chunk|augmentchunkhash - --> renderchunk - .-> generatebundle - --> writebundle - .-> closebundle + --> |each chunk|beforerenderdynamicimport - beforerenderdynamicimport - --> |"each import()"|renderdynamicimport - --> beforeaugmentchunkhash + afteraddons + --> |each chunk|renderchunk augmentchunkhash - --> |each import.meta.*|beforeimportmeta(( )) - --> |import.meta.url|resolvefileurl - .-> renderchunk + --> generatebundle + --> writebundle + .-> closebundle - beforeimportmeta - --> |other|resolveimportmeta - .-> renderchunk + subgraph generateChunks [" "] + direction TB + beforerenderdynamicimport(( )) + ---> beforeresolveimportmeta(( )) + ----> beforereaddons(( )) + --> banner & footer & intro & outro + --> afteraddons(( )) + .-> |next chunk|beforerenderdynamicimport + + beforerenderdynamicimport + --> |"each import()"|renderdynamicimport + --> beforerenderdynamicimport + + beforeresolveimportmeta + --> |each import.meta.*|beforeimportmeta(( )) + --> |import.meta.url|resolvefileurl + --> afterresolveimportmeta(( )) + + beforeimportmeta + --> |other|resolveimportmeta + --> afterresolveimportmeta + + afterresolveimportmeta + --> beforeresolveimportmeta + end + + renderchunk + --> augmentchunkhash + .-> |next chunk|renderchunk + + style generateChunks stroke-width:0px; rendererror .-> closebundle diff --git a/package-lock.json b/package-lock.json index 06f7bf2565c..0573072f21d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "rollup", - "version": "2.79.0", + "version": "3.0.0-0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "rollup", - "version": "2.77.0", + "version": "3.0.0-0", "license": "MIT", "bin": { "rollup": "dist/bin/rollup" diff --git a/package.json b/package.json index 52e7d62c369..9f3031888d6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rollup", - "version": "2.79.0", + "version": "3.0.0-0", "description": "Next-generation ES module bundler", "main": "dist/rollup.js", "module": "dist/es/rollup.js", diff --git a/src/Bundle.ts b/src/Bundle.ts index 99123386fcf..d7cc3822a86 100644 --- a/src/Bundle.ts +++ b/src/Bundle.ts @@ -1,5 +1,6 @@ import Chunk from './Chunk'; -import type ExternalModule from './ExternalModule'; +import ExternalChunk from './ExternalChunk'; +import ExternalModule from './ExternalModule'; import type Graph from './Graph'; import Module from './Module'; import type { @@ -8,12 +9,9 @@ import type { NormalizedOutputOptions, OutputBundle, OutputBundleWithPlaceholders, - OutputChunk, WarningHandler } from './rollup/types'; -import { FILE_PLACEHOLDER } from './utils/FileEmitter'; import type { PluginDriver } from './utils/PluginDriver'; -import { type Addons, createAddons } from './utils/addons'; import { getChunkAssignments } from './utils/chunkAssignment'; import commondir from './utils/commondir'; import { @@ -23,8 +21,10 @@ import { error } from './utils/error'; import { sortByExecutionOrder } from './utils/executionOrder'; -import { type GenerateCodeSnippets, getGenerateCodeSnippets } from './utils/generateCodeSnippets'; -import { basename, isAbsolute } from './utils/path'; +import { getGenerateCodeSnippets } from './utils/generateCodeSnippets'; +import { getHashPlaceholderGenerator, HashPlaceholderGenerator } from './utils/hashPlaceholders'; +import { isAbsolute } from './utils/path'; +import { renderChunks } from './utils/renderChunks'; import { timeEnd, timeStart } from './utils/timers'; export default class Bundle { @@ -42,28 +42,36 @@ export default class Bundle { async generate(isWrite: boolean): Promise { timeStart('GENERATE', 1); const outputBundle: OutputBundleWithPlaceholders = Object.create(null); - this.pluginDriver.setOutputBundle(outputBundle, this.outputOptions, this.facadeChunkByModule); + this.pluginDriver.setOutputBundle(outputBundle, this.outputOptions); + + // TODO Lukas rethink time measuring points try { await this.pluginDriver.hookParallel('renderStart', [this.outputOptions, this.inputOptions]); timeStart('generate chunks', 2); - const chunks = await this.generateChunks(); + const getHashPlaceholder = getHashPlaceholderGenerator(); + const chunks = await this.generateChunks(outputBundle, getHashPlaceholder); if (chunks.length > 1) { validateOptionsForMultiChunkOutput(this.outputOptions, this.inputOptions.onwarn); } - const inputBase = commondir(getAbsoluteEntryModulePaths(chunks)); + this.pluginDriver.setChunkInformation(this.facadeChunkByModule); + timeEnd('generate chunks', 2); - timeStart('render modules', 2); + timeStart('render chunks', 2); - // We need to create addons before prerender because at the moment, there - // can be no async code between prerender and render due to internal state - const addons = await createAddons(this.outputOptions, this.pluginDriver); - const snippets = getGenerateCodeSnippets(this.outputOptions); - this.prerenderChunks(chunks, inputBase, snippets); - timeEnd('render modules', 2); + for (const chunk of chunks) { + chunk.generateExports(); + } + await renderChunks( + chunks, + outputBundle, + this.pluginDriver, + this.outputOptions, + this.inputOptions.onwarn + ); - await this.addFinalizedChunksToBundle(chunks, inputBase, addons, outputBundle, snippets); + timeEnd('render chunks', 2); } catch (err: any) { await this.pluginDriver.hookParallel('renderError', [err]); throw err; @@ -79,28 +87,6 @@ export default class Bundle { return outputBundle as OutputBundle; } - private async addFinalizedChunksToBundle( - chunks: readonly Chunk[], - inputBase: string, - addons: Addons, - outputBundle: OutputBundleWithPlaceholders, - snippets: GenerateCodeSnippets - ): Promise { - this.assignChunkIds(chunks, inputBase, addons, outputBundle); - for (const chunk of chunks) { - outputBundle[chunk.id!] = chunk.getChunkInfoWithFileNames() as OutputChunk; - } - await Promise.all( - chunks.map(async chunk => { - const outputChunk = outputBundle[chunk.id!] as OutputChunk; - Object.assign( - outputChunk, - await chunk.render(this.outputOptions, addons, outputChunk, snippets) - ); - }) - ); - } - private async addManualChunks( manualChunks: Record ): Promise> { @@ -119,40 +105,6 @@ export default class Bundle { return manualChunkAliasByEntry; } - private assignChunkIds( - chunks: readonly Chunk[], - inputBase: string, - addons: Addons, - bundle: OutputBundleWithPlaceholders - ): void { - const entryChunks: Chunk[] = []; - const otherChunks: Chunk[] = []; - for (const chunk of chunks) { - (chunk.facadeModule && chunk.facadeModule.isUserDefinedEntryPoint - ? entryChunks - : otherChunks - ).push(chunk); - } - - // make sure entry chunk names take precedence with regard to deconflicting - const chunksForNaming = entryChunks.concat(otherChunks); - for (const chunk of chunksForNaming) { - if (this.outputOptions.file) { - chunk.id = basename(this.outputOptions.file); - } else if (this.outputOptions.preserveModules) { - chunk.id = chunk.generateIdPreserveModules( - inputBase, - this.outputOptions, - bundle, - this.unsetOptions - ); - } else { - chunk.id = chunk.generateId(addons, this.outputOptions, bundle, true); - } - bundle[chunk.id] = FILE_PLACEHOLDER; - } - } - private assignManualChunks(getManualChunk: GetManualChunk): Map { const manualChunkAliasesWithEntry: [alias: string, module: Module][] = []; const manualChunksApi = { @@ -193,21 +145,29 @@ export default class Bundle { this.pluginDriver.finaliseAssets(); } - private async generateChunks(): Promise { - const { manualChunks } = this.outputOptions; + private async generateChunks( + bundle: OutputBundleWithPlaceholders, + getHashPlaceholder: HashPlaceholderGenerator + ): Promise { + const { inlineDynamicImports, manualChunks, preserveModules } = this.outputOptions; const manualChunkAliasByEntry = typeof manualChunks === 'object' ? await this.addManualChunks(manualChunks) : this.assignManualChunks(manualChunks); + const snippets = getGenerateCodeSnippets(this.outputOptions); + const includedModules = getIncludedModules(this.graph.modulesById); + const inputBase = commondir(getAbsoluteEntryModulePaths(includedModules, preserveModules)); + const externalChunkByModule = getExternalChunkByModule( + this.graph.modulesById, + this.outputOptions, + inputBase + ); const chunks: Chunk[] = []; const chunkByModule = new Map(); - for (const { alias, modules } of this.outputOptions.inlineDynamicImports - ? [{ alias: null, modules: getIncludedModules(this.graph.modulesById) }] - : this.outputOptions.preserveModules - ? getIncludedModules(this.graph.modulesById).map(module => ({ - alias: null, - modules: [module] - })) + for (const { alias, modules } of inlineDynamicImports + ? [{ alias: null, modules: includedModules }] + : preserveModules + ? includedModules.map(module => ({ alias: null, modules: [module] })) : getChunkAssignments(this.graph.entryModules, manualChunkAliasByEntry)) { sortByExecutionOrder(modules); const chunk = new Chunk( @@ -218,14 +178,16 @@ export default class Bundle { this.pluginDriver, this.graph.modulesById, chunkByModule, + externalChunkByModule, this.facadeChunkByModule, this.includedNamespaces, - alias + alias, + getHashPlaceholder, + bundle, + inputBase, + snippets ); chunks.push(chunk); - for (const module of modules) { - chunkByModule.set(module, chunk); - } } for (const chunk of chunks) { chunk.link(); @@ -236,31 +198,6 @@ export default class Bundle { } return [...chunks, ...facades]; } - - private prerenderChunks( - chunks: readonly Chunk[], - inputBase: string, - snippets: GenerateCodeSnippets - ): void { - for (const chunk of chunks) { - chunk.generateExports(); - } - for (const chunk of chunks) { - chunk.preRender(this.outputOptions, inputBase, snippets); - } - } -} - -function getAbsoluteEntryModulePaths(chunks: readonly Chunk[]): string[] { - const absoluteEntryModulePaths: string[] = []; - for (const chunk of chunks) { - for (const entryModule of chunk.entryModules) { - if (isAbsolute(entryModule.id)) { - absoluteEntryModulePaths.push(entryModule.id); - } - } - } - return absoluteEntryModulePaths; } function validateOptionsForMultiChunkOutput( @@ -303,11 +240,43 @@ function validateOptionsForMultiChunkOutput( } function getIncludedModules(modulesById: ReadonlyMap): Module[] { - return [...modulesById.values()].filter( - (module): module is Module => + const includedModules: Module[] = []; + for (const module of modulesById.values()) { + if ( module instanceof Module && (module.isIncluded() || module.info.isEntry || module.includedDynamicImporters.length > 0) - ); + ) { + includedModules.push(module); + } + } + return includedModules; +} + +function getAbsoluteEntryModulePaths( + includedModules: Module[], + preserveModules: boolean +): string[] { + const absoluteEntryModulePaths: string[] = []; + for (const module of includedModules) { + if ((module.info.isEntry || preserveModules) && isAbsolute(module.id)) { + absoluteEntryModulePaths.push(module.id); + } + } + return absoluteEntryModulePaths; +} + +function getExternalChunkByModule( + modulesById: ReadonlyMap, + outputOptions: NormalizedOutputOptions, + inputBase: string +): Map { + const externalChunkByModule = new Map(); + for (const module of modulesById.values()) { + if (module instanceof ExternalModule) { + externalChunkByModule.set(module, new ExternalChunk(module, outputOptions, inputBase)); + } + } + return externalChunkByModule; } function addModuleToManualChunk( diff --git a/src/Chunk.ts b/src/Chunk.ts index bea8d36972c..a1efbcc26ac 100644 --- a/src/Chunk.ts +++ b/src/Chunk.ts @@ -1,9 +1,11 @@ import MagicString, { Bundle as MagicStringBundle, type SourceMap } from 'magic-string'; import { relative } from '../browser/path'; +import ExternalChunk from './ExternalChunk'; import ExternalModule from './ExternalModule'; import Module from './Module'; import ExportDefaultDeclaration from './ast/nodes/ExportDefaultDeclaration'; import FunctionDeclaration from './ast/nodes/FunctionDeclaration'; +import ImportExpression from './ast/nodes/ImportExpression'; import type ChildScope from './ast/scopes/ChildScope'; import ExportDefaultVariable from './ast/variables/ExportDefaultVariable'; import LocalVariable from './ast/variables/LocalVariable'; @@ -12,26 +14,24 @@ import SyntheticNamedExportVariable from './ast/variables/SyntheticNamedExportVa import type Variable from './ast/variables/Variable'; import finalisers from './finalisers/index'; import type { - DecodedSourceMapOrMissing, GetInterop, GlobalsOption, InternalModuleFormat, NormalizedInputOptions, NormalizedOutputOptions, + OutputBundleWithPlaceholders, + OutputChunk, PreRenderedChunk, RenderedChunk, RenderedModule, WarningHandler } from './rollup/types'; +import { FILE_PLACEHOLDER } from './utils/FileEmitter'; import type { PluginDriver } from './utils/PluginDriver'; -import type { Addons } from './utils/addons'; -import { collapseSourcemaps } from './utils/collapseSourcemaps'; -import { createHash } from './utils/crypto'; +import { createAddons } from './utils/addons'; import { deconflictChunk, type DependenciesToBeDeconflicted } from './utils/deconflictChunk'; import { errCyclicCrossChunkReexport, - errFailedValidation, - errInvalidOption, error, errUnexpectedNamedImport, errUnexpectedNamespaceReexport @@ -40,10 +40,10 @@ import { escapeId } from './utils/escapeId'; import { assignExportsToMangledNames, assignExportsToNames } from './utils/exportNames'; import type { GenerateCodeSnippets } from './utils/generateCodeSnippets'; import getExportMode from './utils/getExportMode'; -import { getId } from './utils/getId'; import getIndentString from './utils/getIndentString'; import { getOrCreate } from './utils/getOrCreate'; import { getStaticDependencies } from './utils/getStaticDependencies'; +import { HashPlaceholderGenerator, replacePlaceholders } from './utils/hashPlaceholders'; import { makeLegal } from './utils/identifierHelpers'; import { defaultInteropHelpersByInteropType, @@ -51,23 +51,47 @@ import { isDefaultAProperty, namespaceInteropHelpersByInteropType } from './utils/interopHelpers'; -import { dirname, extname, isAbsolute, normalize, resolve } from './utils/path'; +import { basename, dirname, extname, isAbsolute, normalize, resolve } from './utils/path'; import relativeId, { getAliasName, getImportPath } from './utils/relativeId'; -import renderChunk from './utils/renderChunk'; import type { RenderOptions } from './utils/renderHelpers'; import { makeUnique, renderNamePattern } from './utils/renderNamePattern'; import { timeEnd, timeStart } from './utils/timers'; import { MISSING_EXPORT_SHIM_VARIABLE } from './utils/variableNames'; export interface ModuleDeclarations { - dependencies: ModuleDeclarationDependency[]; + dependencies: ChunkDependency[]; exports: ChunkExports; } -export interface ModuleDeclarationDependency { +type PreliminaryFileName = PreliminaryFileNameWithPlaceholder | FixedPreliminaryFileName; + +export interface ChunkRenderResult { + chunk: Chunk; + magicString: MagicStringBundle; + preliminaryFileName: PreliminaryFileName; + usedModules: Module[]; +} + +interface PreliminaryFileNameWithPlaceholder { + fileName: string; + hashPlaceholder: string; +} + +interface FixedPreliminaryFileName { + fileName: string; + hashPlaceholder: null; +} + +export type ResolvedDynamicImport = ( + | { chunk: Chunk; externalChunk: null; facadeChunk: Chunk | undefined; resolution: Module } + | { chunk: null; externalChunk: ExternalChunk; facadeChunk: null; resolution: ExternalModule } + | { chunk: null; externalChunk: null; facadeChunk: null; resolution: string | null } +) & { node: ImportExpression }; + +export interface ChunkDependency { defaultVariableName: string | undefined; - globalName: string; - id: string; + globalName: string | false | undefined; + importPath: string; imports: ImportSpecifier[] | null; isChunk: boolean; name: string; @@ -76,8 +100,6 @@ export interface ModuleDeclarationDependency { reexports: ReexportSpecifier[] | null; } -export type ChunkDependencies = ModuleDeclarationDependency[]; - export type ChunkExports = { exported: string; expression: string | null; @@ -101,15 +123,17 @@ interface FacadeName { name?: string; } +type RenderedDependencies = Map; + const NON_ASSET_EXTENSIONS = ['.js', '.jsx', '.ts', '.tsx']; function getGlobalName( - module: ExternalModule, + chunk: ExternalChunk, globals: GlobalsOption, hasExports: boolean, warn: WarningHandler ): string | undefined { - const globalName = typeof globals === 'function' ? globals(module.id) : globals[module.id]; + const globalName = typeof globals === 'function' ? globals(chunk.id) : globals[chunk.id]; if (globalName) { return globalName; } @@ -117,28 +141,28 @@ function getGlobalName( if (hasExports) { warn({ code: 'MISSING_GLOBAL_NAME', - guess: module.variableName, - message: `No name was provided for external module '${module.id}' in output.globals – guessing '${module.variableName}'`, - source: module.id + guess: chunk.variableName, + message: `No name was provided for external module '${chunk.id}' in output.globals – guessing '${chunk.variableName}'`, + source: chunk.id }); - return module.variableName; + return chunk.variableName; } } export default class Chunk { + // placeholder declaration, only relevant for ExternalChunk + defaultVariableName?: undefined; readonly entryModules: Module[] = []; execIndex: number; exportMode: 'none' | 'named' | 'default' = 'named'; facadeModule: Module | null = null; id: string | null = null; namespaceVariableName = ''; - needsExportsShim = false; suggestedVariableName: string; variableName = ''; private readonly accessedGlobalsByScope = new Map>(); - private dependencies = new Set(); - private readonly dynamicDependencies = new Set(); + private dependencies = new Set(); private readonly dynamicEntryModules: Module[] = []; private dynamicName: string | null = null; private readonly exportNamesByVariable = new Map(); @@ -148,23 +172,21 @@ export default class Chunk { private implicitEntryModules: Module[] = []; private readonly implicitlyLoadedBefore = new Set(); private readonly imports = new Set(); + private includedDynamicImports: ResolvedDynamicImport[] | null = null; private readonly includedReexportsByModule = new Map(); - private indentString: string = undefined as never; - // This may only be updated in the constructor + // This may be updated in the constructor private readonly isEmpty: boolean = true; private name: string | null = null; - private renderedDependencies: Map | null = - null; - private renderedExports: ChunkExports | null = null; - private renderedHash: string | undefined = undefined; - private readonly renderedModuleSources = new Map(); + private needsExportsShim = false; + private preRenderedChunkInfo: PreRenderedChunk | null = null; + private preliminaryFileName: PreliminaryFileName | null = null; + private renderedChunkInfo: RenderedChunk | null = null; + private renderedDependencies: Map | null = null; private readonly renderedModules: { [moduleId: string]: RenderedModule; } = Object.create(null); - private renderedSource: MagicStringBundle | null = null; private sortedExportNames: string[] | null = null; private strictFacade = false; - private usedModules: Module[] = undefined as never; constructor( private readonly orderedModules: readonly Module[], @@ -173,15 +195,21 @@ export default class Chunk { private readonly unsetOptions: ReadonlySet, private readonly pluginDriver: PluginDriver, private readonly modulesById: ReadonlyMap, - private readonly chunkByModule: ReadonlyMap, + private readonly chunkByModule: Map, + private readonly externalChunkByModule: ReadonlyMap, private readonly facadeChunkByModule: Map, private readonly includedNamespaces: Set, - private readonly manualChunkAlias: string | null + private readonly manualChunkAlias: string | null, + private readonly getPlaceholder: HashPlaceholderGenerator, + private readonly bundle: OutputBundleWithPlaceholders, + private readonly inputBase: string, + private readonly snippets: GenerateCodeSnippets ) { this.execIndex = orderedModules.length > 0 ? orderedModules[0].execIndex : Infinity; const chunkModules = new Set(orderedModules); for (const module of orderedModules) { + chunkByModule.set(module, this); if (module.namespace.included) { includedNamespaces.add(module); } @@ -214,11 +242,16 @@ export default class Chunk { unsetOptions: ReadonlySet, pluginDriver: PluginDriver, modulesById: ReadonlyMap, - chunkByModule: ReadonlyMap, + chunkByModule: Map, + externalChunkByModule: ReadonlyMap, facadeChunkByModule: Map, includedNamespaces: Set, facadedModule: Module, - facadeName: FacadeName + facadeName: FacadeName, + getPlaceholder: HashPlaceholderGenerator, + bundle: OutputBundleWithPlaceholders, + inputBase: string, + snippets: GenerateCodeSnippets ): Chunk { const chunk = new Chunk( [], @@ -228,9 +261,14 @@ export default class Chunk { pluginDriver, modulesById, chunkByModule, + externalChunkByModule, facadeChunkByModule, includedNamespaces, - null + null, + getPlaceholder, + bundle, + inputBase, + snippets ); chunk.assignFacadeName(facadeName, facadedModule); if (!facadeChunkByModule.has(facadedModule)) { @@ -238,7 +276,9 @@ export default class Chunk { } for (const dependency of facadedModule.getDependenciesToBeIncluded()) { chunk.dependencies.add( - dependency instanceof Module ? chunkByModule.get(dependency)! : dependency + dependency instanceof Module + ? chunkByModule.get(dependency)! + : externalChunkByModule.get(dependency)! ); } if ( @@ -375,10 +415,15 @@ export default class Chunk { this.pluginDriver, this.modulesById, this.chunkByModule, + this.externalChunkByModule, this.facadeChunkByModule, this.includedNamespaces, module, - facadeName + facadeName, + this.getPlaceholder, + this.bundle, + this.inputBase, + this.snippets ) ); } @@ -407,112 +452,31 @@ export default class Chunk { return facades; } - generateId( - addons: Addons, - options: NormalizedOutputOptions, - existingNames: Record, - includeHash: boolean - ): string { - if (this.fileName !== null) { - return this.fileName; - } - const [pattern, patternName] = - this.facadeModule && this.facadeModule.isUserDefinedEntryPoint - ? [options.entryFileNames, 'output.entryFileNames'] - : [options.chunkFileNames, 'output.chunkFileNames']; - return makeUnique( - renderNamePattern( - typeof pattern === 'function' ? pattern(this.getChunkInfo()) : pattern, - patternName, - { - format: () => options.format, - hash: () => - includeHash - ? this.computeContentHashWithDependencies(addons, options, existingNames) - : '[hash]', - name: () => this.getChunkName() - } - ), - existingNames - ); - } - - generateIdPreserveModules( - preserveModulesRelativeDir: string, - options: NormalizedOutputOptions, - existingNames: Record, - unsetOptions: ReadonlySet - ): string { - const [{ id }] = this.orderedModules; - const sanitizedId = this.outputOptions.sanitizeFileName(id.split(QUERY_HASH_REGEX, 1)[0]); - let path: string; - - const patternOpt = unsetOptions.has('entryFileNames') - ? '[name][assetExtname].js' - : options.entryFileNames; - const pattern = typeof patternOpt === 'function' ? patternOpt(this.getChunkInfo()) : patternOpt; - - if (isAbsolute(sanitizedId)) { - const currentDir = dirname(sanitizedId); - const extension = extname(sanitizedId); - const fileName = renderNamePattern(pattern, 'output.entryFileNames', { - assetExtname: () => (NON_ASSET_EXTENSIONS.includes(extension) ? '' : extension), - ext: () => extension.substring(1), - extname: () => extension, - format: () => options.format as string, - name: () => this.getChunkName() - }); - const currentPath = `${currentDir}/${fileName}`; - const { preserveModulesRoot } = options; - if (preserveModulesRoot && resolve(currentPath).startsWith(preserveModulesRoot)) { - path = currentPath.slice(preserveModulesRoot.length).replace(/^[\\/]/, ''); - } else { - path = relative(preserveModulesRelativeDir, currentPath); - } - } else { - const extension = extname(sanitizedId); - const fileName = renderNamePattern(pattern, 'output.entryFileNames', { - assetExtname: () => (NON_ASSET_EXTENSIONS.includes(extension) ? '' : extension), - ext: () => extension.substring(1), - extname: () => extension, - format: () => options.format as string, - name: () => getAliasName(sanitizedId) - }); - path = `_virtual/${fileName}`; - } - return makeUnique(normalize(path), existingNames); - } - - getChunkInfo(): PreRenderedChunk { - const facadeModule = this.facadeModule; - const getChunkName = this.getChunkName.bind(this); + generateOutputChunk( + code: string, + map: SourceMap | null, + hashesByPlaceholder: Map + ): OutputChunk { + const renderedChunkInfo = this.getRenderedChunkInfo(); + const finalize = (code: string) => replacePlaceholders(code, hashesByPlaceholder); return { - exports: this.getExportNames(), - facadeModuleId: facadeModule && facadeModule.id, - isDynamicEntry: this.dynamicEntryModules.length > 0, - isEntry: facadeModule !== null && facadeModule.info.isEntry, - isImplicitEntry: this.implicitEntryModules.length > 0, - modules: this.renderedModules, - get name() { - return getChunkName(); - }, - type: 'chunk' + ...renderedChunkInfo, + code, + dynamicImports: renderedChunkInfo.dynamicImports.map(finalize), + fileName: finalize(renderedChunkInfo.fileName), + implicitlyLoadedBefore: renderedChunkInfo.implicitlyLoadedBefore.map(finalize), + importedBindings: Object.fromEntries( + Object.entries(renderedChunkInfo.importedBindings).map(([fileName, bindings]) => [ + finalize(fileName), + bindings + ]) + ), + imports: renderedChunkInfo.imports.map(finalize), + map, + referencedFiles: renderedChunkInfo.referencedFiles.map(finalize) }; } - getChunkInfoWithFileNames(): RenderedChunk { - return Object.assign(this.getChunkInfo(), { - code: undefined, - dynamicImports: Array.from(this.dynamicDependencies, getId), - fileName: this.id!, - implicitlyLoadedBefore: Array.from(this.implicitlyLoadedBefore, getId), - importedBindings: this.getImportedBindingsPerDependency(), - imports: Array.from(this.dependencies, getId), - map: undefined, - referencedFiles: this.getReferencedFiles() - }); - } - getChunkName(): string { return (this.name ??= this.outputOptions.sanitizeFileName(this.getFallbackChunkName())); } @@ -521,33 +485,78 @@ export default class Chunk { return (this.sortedExportNames ??= Array.from(this.exportsByName.keys()).sort()); } - getRenderedHash(): string { - if (this.renderedHash) return this.renderedHash; - const hash = createHash(); - const hashAugmentation = this.pluginDriver.hookReduceValueSync( - 'augmentChunkHash', - '', - [this.getChunkInfo()], - (augmentation, pluginHash) => { - if (pluginHash) { - augmentation += pluginHash; + getFileName(): string { + return this.preliminaryFileName?.fileName || this.getPreliminaryFileName().fileName; + } + + getImportPath(importer: string): string { + return escapeId( + getImportPath( + importer, + this.getFileName(), + this.outputOptions.format === 'amd' && !this.outputOptions.amd.forceJsExtensionForImports, + true + ) + ); + } + + getPreliminaryFileName(): PreliminaryFileName { + if (this.preliminaryFileName) { + return this.preliminaryFileName; + } + let fileName: string; + let hashPlaceholder: string | null = null; + const { chunkFileNames, entryFileNames, file, format, preserveModules } = this.outputOptions; + if (file) { + fileName = basename(file); + } else if (preserveModules) { + fileName = this.generateIdPreserveModules(); + } else if (this.fileName !== null) { + fileName = this.fileName; + } else { + const [pattern, patternName] = + this.facadeModule && this.facadeModule.isUserDefinedEntryPoint + ? [entryFileNames, 'output.entryFileNames'] + : [chunkFileNames, 'output.chunkFileNames']; + fileName = renderNamePattern( + typeof pattern === 'function' ? pattern(this.getPreRenderedChunkInfo()) : pattern, + patternName, + { + format: () => format, + hash: size => + hashPlaceholder || (hashPlaceholder = this.getPlaceholder(patternName, size)), + name: () => this.getChunkName() } - return augmentation; + ); + if (!hashPlaceholder) { + fileName = makeUnique(fileName, this.bundle); } - ); - hash.update(hashAugmentation); - hash.update(this.renderedSource!.toString()); - hash.update( - this.getExportNames() - .map(exportName => { - const variable = this.exportsByName.get(exportName)!; - return `${relativeId((variable.module as Module).id).replace(/\\/g, '/')}:${ - variable.name - }:${exportName}`; - }) - .join(',') - ); - return (this.renderedHash = hash.digest('hex')); + } + if (!hashPlaceholder) { + this.bundle[fileName] = FILE_PLACEHOLDER; + } + // Caching is essential to not conflict with the file name reservation above + return (this.preliminaryFileName = { fileName, hashPlaceholder }); + } + + public getRenderedChunkInfo(): RenderedChunk { + if (this.renderedChunkInfo) { + return this.renderedChunkInfo; + } + const resolveFileName = (dependency: Chunk | ExternalChunk): string => dependency.getFileName(); + return (this.renderedChunkInfo = { + ...this.getPreRenderedChunkInfo(), + dynamicImports: this.getDynamicDependencies().map(resolveFileName), + fileName: this.getFileName(), + implicitlyLoadedBefore: Array.from(this.implicitlyLoadedBefore, resolveFileName), + importedBindings: getImportedBindingsPerDependency( + this.getRenderedDependencies(), + resolveFileName + ), + imports: Array.from(this.dependencies, resolveFileName), + modules: this.renderedModules, + referencedFiles: this.getReferencedFiles() + }); } getVariableExportName(variable: Variable): string { @@ -558,281 +567,94 @@ export default class Chunk { } link(): void { - this.dependencies = getStaticDependencies(this, this.orderedModules, this.chunkByModule); + this.dependencies = getStaticDependencies( + this, + this.orderedModules, + this.chunkByModule, + this.externalChunkByModule + ); for (const module of this.orderedModules) { - this.addDependenciesToChunk(module.dynamicDependencies, this.dynamicDependencies); - this.addDependenciesToChunk(module.implicitlyLoadedBefore, this.implicitlyLoadedBefore); + this.addImplicitlyLoadedBeforeFromModule(module); this.setUpChunkImportsAndExportsForModule(module); } } - // prerender allows chunk hashes and names to be generated before finalizing - preRender( - options: NormalizedOutputOptions, - inputBase: string, - snippets: GenerateCodeSnippets - ): void { - const { _, getPropertyAccess, n } = snippets; - const magicString = new MagicStringBundle({ separator: `${n}${n}` }); - this.usedModules = []; - this.indentString = getIndentString(this.orderedModules, options); - - const renderOptions: RenderOptions = { - dynamicImportFunction: options.dynamicImportFunction, - exportNamesByVariable: this.exportNamesByVariable, - format: options.format, - freeze: options.freeze, - indent: this.indentString, - namespaceToStringTag: options.namespaceToStringTag, - outputPluginDriver: this.pluginDriver, + async render(): Promise { + const { + dependencies, + exportMode, + facadeModule, + inputOptions: { onwarn }, + outputOptions, + pluginDriver, snippets - }; + } = this; + const { format, hoistTransitiveImports, preserveModules } = outputOptions; - // for static and dynamic entry points, inline the execution list to avoid loading latency - if ( - options.hoistTransitiveImports && - !this.outputOptions.preserveModules && - this.facadeModule !== null - ) { - for (const dep of this.dependencies) { + // for static and dynamic entry points, add transitive dependencies to this + // chunk's dependencies to avoid loading latency + if (hoistTransitiveImports && !preserveModules && facadeModule !== null) { + for (const dep of dependencies) { if (dep instanceof Chunk) this.inlineChunkDependencies(dep); } } - this.prepareModulesForRendering(snippets); - this.setIdentifierRenderResolutions(options); - - let hoistedSource = ''; - const renderedModules = this.renderedModules; + const preliminaryFileName = this.getPreliminaryFileName(); + const { accessedGlobals, indent, magicString, renderedSource, usedModules, usesTopLevelAwait } = + this.renderModules(preliminaryFileName.fileName); - for (const module of this.orderedModules) { - let renderedLength = 0; - if (module.isIncluded() || this.includedNamespaces.has(module)) { - const source = module.render(renderOptions).trim(); - renderedLength = source.length(); - if (renderedLength) { - if (options.compact && source.lastLine().includes('//')) source.append('\n'); - this.renderedModuleSources.set(module, source); - magicString.addSource(source); - this.usedModules.push(module); - } - const namespace = module.namespace; - if (this.includedNamespaces.has(module) && !this.outputOptions.preserveModules) { - const rendered = namespace.renderBlock(renderOptions); - if (namespace.renderFirst()) hoistedSource += n + rendered; - else magicString.addSource(new MagicString(rendered)); - } - } - const { renderedExports, removedExports } = module.getRenderedExports(); - const { renderedModuleSources } = this; - renderedModules[module.id] = { - get code() { - return renderedModuleSources.get(module)?.toString() ?? null; - }, - originalLength: module.originalCode.length, - removedExports, - renderedExports, - renderedLength - }; - } - - if (hoistedSource) magicString.prepend(hoistedSource + n + n); - - if (this.needsExportsShim) { - magicString.prepend( - `${n}${snippets.cnst} ${MISSING_EXPORT_SHIM_VARIABLE}${_}=${_}void 0;${n}${n}` - ); - } - if (options.compact) { - this.renderedSource = magicString; - } else { - this.renderedSource = magicString.trim(); - } - - this.renderedHash = undefined; - - if (this.isEmpty && this.getExportNames().length === 0 && this.dependencies.size === 0) { - const chunkName = this.getChunkName(); - this.inputOptions.onwarn({ - chunkName, - code: 'EMPTY_BUNDLE', - message: `Generated an empty chunk: "${chunkName}"` - }); - } - - this.setExternalRenderPaths(options, inputBase); - - this.renderedDependencies = this.getChunkDependencyDeclarations(options, getPropertyAccess); - this.renderedExports = - this.exportMode === 'none' - ? [] - : this.getChunkExportDeclarations(options.format, getPropertyAccess); - } - - async render( - options: NormalizedOutputOptions, - addons: Addons, - outputChunk: RenderedChunk, - snippets: GenerateCodeSnippets - ): Promise<{ code: string; map: SourceMap }> { timeStart('render format', 2); - - const format = options.format; - const finalise = finalisers[format]; - if (options.dynamicImportFunction && format !== 'es') { - this.inputOptions.onwarn( - errInvalidOption( - 'output.dynamicImportFunction', - 'outputdynamicImportFunction', - 'this option is ignored for formats other than "es"' - ) - ); - } - - // populate ids in the rendered declarations only here - // as chunk ids known only after prerender - for (const dependency of this.dependencies) { - const renderedDependency = this.renderedDependencies!.get(dependency)!; - if (dependency instanceof ExternalModule) { - const originalId = dependency.renderPath; - renderedDependency.id = escapeId( - dependency.renormalizeRenderPath - ? getImportPath(this.id!, originalId, false, false) - : originalId - ); - } else { - renderedDependency.namedExportsMode = dependency.exportMode !== 'default'; - renderedDependency.id = escapeId(getImportPath(this.id!, dependency.id!, false, true)); - } - } - - this.finaliseDynamicImports(options, snippets); - this.finaliseImportMetas(format, snippets); - + const renderedDependencies = [...this.getRenderedDependencies().values()]; + const renderedExports = exportMode === 'none' ? [] : this.getChunkExportDeclarations(format); const hasExports = - this.renderedExports!.length !== 0 || - [...this.renderedDependencies!.values()].some( - dep => (dep.reexports && dep.reexports.length !== 0)! - ); - - let topLevelAwaitModule: string | null = null; - const accessedGlobals = new Set(); - for (const module of this.orderedModules) { - if (module.usesTopLevelAwait) { - topLevelAwaitModule = module.id; - } - const accessedGlobalVariables = this.accessedGlobalsByScope.get(module.scope); - if (accessedGlobalVariables) { - for (const name of accessedGlobalVariables) { - accessedGlobals.add(name); - } - } - } - - if (topLevelAwaitModule !== null && format !== 'es' && format !== 'system') { - return error({ - code: 'INVALID_TLA_FORMAT', - id: topLevelAwaitModule, - message: `Module format ${format} does not support top-level await. Use the "es" or "system" output formats rather.` - }); - } - - /* istanbul ignore next */ - if (!this.id) { - throw new Error('Internal Error: expecting chunk id'); - } + renderedExports.length !== 0 || + renderedDependencies.some(dep => (dep.reexports && dep.reexports.length !== 0)!); - const magicString = finalise( - this.renderedSource!, + // TODO Lukas Note: Mention in docs, that users/plugins are responsible to do their own caching + // TODO Lukas adapt plugin hook graphs and order in docs + const { intro, outro, banner, footer } = await createAddons( + outputOptions, + pluginDriver, + this.getRenderedChunkInfo() + ); + finalisers[format]( + renderedSource, { accessedGlobals, - dependencies: [...this.renderedDependencies!.values()], - exports: this.renderedExports!, + dependencies: renderedDependencies, + exports: renderedExports, hasExports, - id: this.id, - indent: this.indentString, - intro: addons.intro, - isEntryFacade: - this.outputOptions.preserveModules || - (this.facadeModule !== null && this.facadeModule.info.isEntry), - isModuleFacade: this.facadeModule !== null, - namedExportsMode: this.exportMode !== 'default', - outro: addons.outro, + id: preliminaryFileName.fileName, + indent, + intro, + isEntryFacade: preserveModules || (facadeModule !== null && facadeModule.info.isEntry), + isModuleFacade: facadeModule !== null, + namedExportsMode: exportMode !== 'default', + onwarn, + outro, snippets, - usesTopLevelAwait: topLevelAwaitModule !== null, - warn: this.inputOptions.onwarn + usesTopLevelAwait }, - options + outputOptions ); - if (addons.banner) magicString.prepend(addons.banner); - if (addons.footer) magicString.append(addons.footer); - const prevCode = magicString.toString(); - + if (banner) magicString.prepend(banner); + if (footer) magicString.append(footer); timeEnd('render format', 2); - let map: SourceMap = null as never; - const chunkSourcemapChain: DecodedSourceMapOrMissing[] = []; - - let code = await renderChunk({ - code: prevCode, - options, - outputPluginDriver: this.pluginDriver, - renderChunk: outputChunk, - sourcemapChain: chunkSourcemapChain - }); - if (options.sourcemap) { - timeStart('sourcemap', 2); - - let file: string; - if (options.file) file = resolve(options.sourcemapFile || options.file); - else if (options.dir) file = resolve(options.dir, this.id); - else file = resolve(this.id); - - const decodedMap = magicString.generateDecodedMap({}); - map = collapseSourcemaps( - file, - decodedMap, - this.usedModules, - chunkSourcemapChain, - options.sourcemapExcludeSources, - this.inputOptions.onwarn - ); - map.sources = map.sources - .map(sourcePath => { - const { sourcemapPathTransform } = options; - - if (sourcemapPathTransform) { - const newSourcePath = sourcemapPathTransform(sourcePath, `${file}.map`) as unknown; - - if (typeof newSourcePath !== 'string') { - error(errFailedValidation(`sourcemapPathTransform function must return a string.`)); - } - - return newSourcePath; - } - - return sourcePath; - }) - .map(normalize); - - timeEnd('sourcemap', 2); - } - if (!options.compact && code[code.length - 1] !== '\n') code += '\n'; - return { code, map }; + return { + chunk: this, + magicString, + preliminaryFileName, + usedModules + }; } - private addDependenciesToChunk( - moduleDependencies: ReadonlySet, - chunkDependencies: Set - ): void { - for (const module of moduleDependencies) { - if (module instanceof Module) { - const chunk = this.chunkByModule.get(module); - if (chunk && chunk !== this) { - chunkDependencies.add(chunk); - } - } else { - chunkDependencies.add(module); + private addImplicitlyLoadedBeforeFromModule(baseModule: Module): void { + const { implicitlyLoadedBefore } = this; + for (const module of baseModule.implicitlyLoadedBefore) { + const chunk = this.chunkByModule.get(module); + if (chunk && chunk !== this) { + implicitlyLoadedBefore.add(chunk); } } } @@ -882,30 +704,6 @@ export default class Chunk { } } - private computeContentHashWithDependencies( - addons: Addons, - options: NormalizedOutputOptions, - existingNames: Record - ): string { - const hash = createHash(); - hash.update([addons.intro, addons.outro, addons.banner, addons.footer].join(':')); - hash.update(options.format); - const dependenciesForHashing = new Set([this]); - for (const current of dependenciesForHashing) { - if (current instanceof ExternalModule) { - hash.update(`:${current.renderPath}`); - } else { - hash.update(current.getRenderedHash()); - hash.update(current.generateId(addons, options, existingNames, false)); - } - if (current instanceof ExternalModule) continue; - for (const dependency of [...current.dependencies, ...current.dynamicDependencies]) { - dependenciesForHashing.add(dependency); - } - } - return hash.digest('hex').substr(0, 8); - } - private ensureReexportsAreAvailableForModule(module: Module): void { const includedReexports: Variable[] = []; const map = module.getExportNamesByVariable(); @@ -934,49 +732,46 @@ export default class Chunk { } } - private finaliseDynamicImports( - options: NormalizedOutputOptions, - snippets: GenerateCodeSnippets - ): void { - const stripKnownJsExtensions = - options.format === 'amd' && !options.amd.forceJsExtensionForImports; - for (const [module, code] of this.renderedModuleSources) { - for (const { node, resolution } of module.dynamicImports) { - const chunk = this.chunkByModule.get(resolution as Module); - const facadeChunk = this.facadeChunkByModule.get(resolution as Module); - if (!resolution || !node.included || chunk === this) { - continue; - } - const renderedResolution = - resolution instanceof Module - ? `'${escapeId( - getImportPath(this.id!, (facadeChunk || chunk!).id!, stripKnownJsExtensions, true) - )}'` - : resolution instanceof ExternalModule - ? `'${escapeId( - resolution.renormalizeRenderPath - ? getImportPath(this.id!, resolution.renderPath, stripKnownJsExtensions, false) - : resolution.renderPath - )}'` - : resolution; - node.renderFinalResolution( - code, - renderedResolution, - resolution instanceof Module && - !facadeChunk?.strictFacade && - chunk!.exportNamesByVariable.get(resolution.namespace)![0], - snippets - ); - } - } - } + private generateIdPreserveModules(): string { + const [{ id }] = this.orderedModules; + const { entryFileNames, format, preserveModulesRoot, sanitizeFileName } = this.outputOptions; + const sanitizedId = sanitizeFileName(id.split(QUERY_HASH_REGEX, 1)[0]); + let path: string; - private finaliseImportMetas(format: InternalModuleFormat, snippets: GenerateCodeSnippets): void { - for (const [module, code] of this.renderedModuleSources) { - for (const importMeta of module.importMetas) { - importMeta.renderFinalMechanism(code, this.id!, format, snippets, this.pluginDriver); + const patternOpt = this.unsetOptions.has('entryFileNames') + ? '[name][assetExtname].js' + : entryFileNames; + const pattern = + typeof patternOpt === 'function' ? patternOpt(this.getPreRenderedChunkInfo()) : patternOpt; + + if (isAbsolute(sanitizedId)) { + const currentDir = dirname(sanitizedId); + const extension = extname(sanitizedId); + const fileName = renderNamePattern(pattern, 'output.entryFileNames', { + assetExtname: () => (NON_ASSET_EXTENSIONS.includes(extension) ? '' : extension), + ext: () => extension.substring(1), + extname: () => extension, + format: () => format as string, + name: () => this.getChunkName() + }); + const currentPath = `${currentDir}/${fileName}`; + if (preserveModulesRoot && resolve(currentPath).startsWith(preserveModulesRoot)) { + path = currentPath.slice(preserveModulesRoot.length).replace(/^[\\/]/, ''); + } else { + path = relative(this.inputBase, currentPath); } + } else { + const extension = extname(sanitizedId); + const fileName = renderNamePattern(pattern, 'output.entryFileNames', { + assetExtname: () => (NON_ASSET_EXTENSIONS.includes(extension) ? '' : extension), + ext: () => extension.substring(1), + extname: () => extension, + format: () => format as string, + name: () => getAliasName(sanitizedId) + }); + path = `_virtual/${fileName}`; } + return makeUnique(normalize(path), this.bundle); } private generateVariableName(): string { @@ -994,45 +789,7 @@ export default class Chunk { return 'chunk'; } - private getChunkDependencyDeclarations( - options: NormalizedOutputOptions, - getPropertyAccess: (name: string) => string - ): Map { - const importSpecifiers = this.getImportSpecifiers(getPropertyAccess); - const reexportSpecifiers = this.getReexportSpecifiers(); - const dependencyDeclaration = new Map(); - for (const dep of this.dependencies) { - const imports = importSpecifiers.get(dep) || null; - const reexports = reexportSpecifiers.get(dep) || null; - const namedExportsMode = dep instanceof ExternalModule || dep.exportMode !== 'default'; - - dependencyDeclaration.set(dep, { - defaultVariableName: (dep as ExternalModule).defaultVariableName, - globalName: (dep instanceof ExternalModule && - (options.format === 'umd' || options.format === 'iife') && - getGlobalName( - dep, - options.globals, - (imports || reexports) !== null, - this.inputOptions.onwarn - )) as string, - id: undefined as never, // chunk id updated on render - imports, - isChunk: dep instanceof Chunk, - name: dep.variableName, - namedExportsMode, - namespaceVariableName: (dep as ExternalModule).namespaceVariableName, - reexports - }); - } - - return dependencyDeclaration; - } - - private getChunkExportDeclarations( - format: InternalModuleFormat, - getPropertyAccess: (name: string) => string - ): ChunkExports { + private getChunkExportDeclarations(format: InternalModuleFormat): ChunkExports { const exports: ChunkExports = []; for (const exportName of this.getExportNames()) { if (exportName[0] === '*') continue; @@ -1044,7 +801,7 @@ export default class Chunk { } let expression = null; let hoisted = false; - let local = variable.getName(getPropertyAccess); + let local = variable.getName(this.snippets.getPropertyAccess); if (variable instanceof LocalVariable) { for (const declaration of variable.declarations) { if ( @@ -1078,22 +835,23 @@ export default class Chunk { addDependenciesWithoutBindings: boolean, interop: GetInterop ): DependenciesToBeDeconflicted { - const dependencies = new Set(); - const deconflictedDefault = new Set(); - const deconflictedNamespace = new Set(); + const dependencies = new Set(); + const deconflictedDefault = new Set(); + const deconflictedNamespace = new Set(); for (const variable of [...this.exportNamesByVariable.keys(), ...this.imports]) { if (addNonNamespacesAndInteropHelpers || variable.isNamespace) { const module = variable.module!; if (module instanceof ExternalModule) { - dependencies.add(module); + const chunk = this.externalChunkByModule.get(module)!; + dependencies.add(chunk); if (addNonNamespacesAndInteropHelpers) { if (variable.name === 'default') { if (defaultInteropHelpersByInteropType[String(interop(module.id))]) { - deconflictedDefault.add(module); + deconflictedDefault.add(chunk); } } else if (variable.name === '*') { if (namespaceInteropHelpersByInteropType[String(interop(module.id))]) { - deconflictedNamespace.add(module); + deconflictedNamespace.add(chunk); } } } @@ -1120,6 +878,22 @@ export default class Chunk { return { deconflictedDefault, deconflictedNamespace, dependencies }; } + private getDynamicDependencies(): (Chunk | ExternalChunk)[] { + return this.getIncludedDynamicImports() + .map( + resolvedDynamicImport => + resolvedDynamicImport.facadeChunk || + resolvedDynamicImport.chunk || + resolvedDynamicImport.externalChunk || + resolvedDynamicImport.resolution + ) + .filter( + (resolution): resolution is Chunk | ExternalChunk => + resolution !== this && + (resolution instanceof Chunk || resolution instanceof ExternalChunk) + ); + } + private getFallbackChunkName(): string { if (this.manualChunkAlias) { return this.manualChunkAlias; @@ -1133,17 +907,15 @@ export default class Chunk { return getAliasName(this.orderedModules[this.orderedModules.length - 1].id); } - private getImportSpecifiers( - getPropertyAccess: (name: string) => string - ): Map { + private getImportSpecifiers(): Map { const { interop } = this.outputOptions; - const importsByDependency = new Map(); + const importsByDependency = new Map(); for (const variable of this.imports) { const module = variable.module!; - let dependency: Chunk | ExternalModule; + let dependency: Chunk | ExternalChunk; let imported: string; if (module instanceof ExternalModule) { - dependency = module; + dependency = this.externalChunkByModule.get(module)!; imported = variable.name; if (imported !== 'default' && imported !== '*' && interop(module.id) === 'defaultOnly') { return error(errUnexpectedNamedImport(module.id, imported, false)); @@ -1154,36 +926,68 @@ export default class Chunk { } getOrCreate(importsByDependency, dependency, () => []).push({ imported, - local: variable.getName(getPropertyAccess) + local: variable.getName(this.snippets.getPropertyAccess) }); } return importsByDependency; } - private getImportedBindingsPerDependency(): { [imported: string]: string[] } { - const importSpecifiers: { [imported: string]: string[] } = {}; - for (const [dependency, declaration] of this.renderedDependencies!) { - const specifiers = new Set(); - if (declaration.imports) { - for (const { imported } of declaration.imports) { - specifiers.add(imported); - } - } - if (declaration.reexports) { - for (const { imported } of declaration.reexports) { - specifiers.add(imported); + private getIncludedDynamicImports(): ResolvedDynamicImport[] { + if (this.includedDynamicImports) { + return this.includedDynamicImports; + } + const includedDynamicImports: ResolvedDynamicImport[] = []; + for (const module of this.orderedModules) { + for (const { node, resolution } of module.dynamicImports) { + if (!node.included) { + continue; } + includedDynamicImports.push( + resolution instanceof Module + ? { + chunk: this.chunkByModule.get(resolution)!, + externalChunk: null, + facadeChunk: this.facadeChunkByModule.get(resolution), + node, + resolution + } + : resolution instanceof ExternalModule + ? { + chunk: null, + externalChunk: this.externalChunkByModule.get(resolution)!, + facadeChunk: null, + node, + resolution + } + : { chunk: null, externalChunk: null, facadeChunk: null, node, resolution } + ); } - importSpecifiers[dependency.id!] = [...specifiers]; } - return importSpecifiers; + return (this.includedDynamicImports = includedDynamicImports); } - private getReexportSpecifiers(): Map { + private getPreRenderedChunkInfo(): PreRenderedChunk { + if (this.preRenderedChunkInfo) { + return this.preRenderedChunkInfo; + } + const { facadeModule } = this; + return (this.preRenderedChunkInfo = { + exports: this.getExportNames(), + facadeModuleId: facadeModule && facadeModule.id, + isDynamicEntry: this.dynamicEntryModules.length > 0, + isEntry: !!facadeModule?.info.isEntry, + isImplicitEntry: this.implicitEntryModules.length > 0, + moduleIds: this.orderedModules.map(({ id }) => id), + name: this.getChunkName(), + type: 'chunk' + }); + } + + private getReexportSpecifiers(): Map { const { externalLiveBindings, interop } = this.outputOptions; - const reexportSpecifiers = new Map(); + const reexportSpecifiers = new Map(); for (let exportName of this.getExportNames()) { - let dependency: Chunk | ExternalModule; + let dependency: Chunk | ExternalChunk; let imported: string; let needsLiveBinding = false; if (exportName[0] === '*') { @@ -1192,7 +996,7 @@ export default class Chunk { this.inputOptions.onwarn(errUnexpectedNamespaceReexport(id)); } needsLiveBinding = externalLiveBindings; - dependency = this.modulesById.get(id) as ExternalModule; + dependency = this.externalChunkByModule.get(this.modulesById.get(id) as ExternalModule)!; imported = exportName = '*'; } else { const variable = this.exportsByName.get(exportName)!; @@ -1204,7 +1008,7 @@ export default class Chunk { imported = dependency.getVariableExportName(variable); needsLiveBinding = variable.isReassigned; } else { - dependency = module; + dependency = this.externalChunkByModule.get(module)!; imported = variable.name; if (imported !== 'default' && imported !== '*' && interop(module.id) === 'defaultOnly') { return error(errUnexpectedNamedImport(module.id, imported, true)); @@ -1224,16 +1028,54 @@ export default class Chunk { } private getReferencedFiles(): string[] { - const referencedFiles: string[] = []; + const referencedFiles = new Set(); for (const module of this.orderedModules) { for (const meta of module.importMetas) { const fileName = meta.getReferencedFileName(this.pluginDriver); if (fileName) { - referencedFiles.push(fileName); + referencedFiles.add(fileName); } } } - return referencedFiles; + return [...referencedFiles]; + } + + private getRenderedDependencies(): RenderedDependencies { + if (this.renderedDependencies) { + return this.renderedDependencies; + } + const importSpecifiers = this.getImportSpecifiers(); + const reexportSpecifiers = this.getReexportSpecifiers(); + const renderedDependencies = new Map(); + const fileName = this.getFileName(); + for (const dep of this.dependencies) { + const imports = importSpecifiers.get(dep) || null; + const reexports = reexportSpecifiers.get(dep) || null; + const namedExportsMode = dep instanceof ExternalChunk || dep.exportMode !== 'default'; + const importPath = dep.getImportPath(fileName); + + renderedDependencies.set(dep, { + defaultVariableName: dep.defaultVariableName, + globalName: + dep instanceof ExternalChunk && + (this.outputOptions.format === 'umd' || this.outputOptions.format === 'iife') && + getGlobalName( + dep, + this.outputOptions.globals, + (imports || reexports) !== null, + this.inputOptions.onwarn + ), + importPath, + imports, + isChunk: dep instanceof Chunk, + name: dep.variableName, + namedExportsMode, + namespaceVariableName: dep.namespaceVariableName, + reexports + }); + } + + return (this.renderedDependencies = renderedDependencies); } private inlineChunkDependencies(chunk: Chunk): void { @@ -1246,59 +1088,150 @@ export default class Chunk { } } - private prepareModulesForRendering(snippets: GenerateCodeSnippets): void { - const accessedGlobalsByScope = this.accessedGlobalsByScope; - for (const module of this.orderedModules) { - for (const { node, resolution } of module.dynamicImports) { - if (node.included) { - if (resolution instanceof Module) { - const chunk = this.chunkByModule.get(resolution); - if (chunk === this) { - node.setInternalResolution(resolution.namespace); - } else { - node.setExternalResolution( - this.facadeChunkByModule.get(resolution)?.exportMode || chunk!.exportMode, - resolution, - this.outputOptions, - snippets, - this.pluginDriver, - accessedGlobalsByScope - ); - } - } else { - node.setExternalResolution( - 'external', - resolution, - this.outputOptions, - snippets, - this.pluginDriver, - accessedGlobalsByScope - ); + // This method changes properties on the AST before rendering and must not be async + private renderModules(fileName: string) { + const { + dependencies, + exportNamesByVariable, + includedNamespaces, + inputOptions: { onwarn }, + isEmpty, + orderedModules, + outputOptions, + pluginDriver, + renderedModules, + snippets + } = this; + const { + compact, + dynamicImportFunction, + format, + freeze, + namespaceToStringTag, + preserveModules + } = outputOptions; + const { _, n } = snippets; + this.setDynamicImportResolutions(fileName); + this.setImportMetaResolutions(fileName); + this.setIdentifierRenderResolutions(); + + const magicString = new MagicStringBundle({ separator: `${n}${n}` }); + const indent = getIndentString(orderedModules, outputOptions); + const usedModules: Module[] = []; + let hoistedSource = ''; + const accessedGlobals = new Set(); + const renderedModuleSources = new Map(); + + const renderOptions: RenderOptions = { + dynamicImportFunction, + exportNamesByVariable, + format, + freeze, + indent, + namespaceToStringTag, + pluginDriver, + snippets + }; + + let usesTopLevelAwait = false; + for (const module of orderedModules) { + let renderedLength = 0; + let source: MagicString | undefined; + if (module.isIncluded() || includedNamespaces.has(module)) { + const rendered = module.render(renderOptions); + ({ source } = rendered); + usesTopLevelAwait ||= rendered.usesTopLevelAwait; + renderedLength = source.length(); + if (renderedLength) { + if (compact && source.lastLine().includes('//')) source.append('\n'); + renderedModuleSources.set(module, source); + magicString.addSource(source); + usedModules.push(module); + } + const namespace = module.namespace; + if (includedNamespaces.has(module) && !preserveModules) { + const rendered = namespace.renderBlock(renderOptions); + if (namespace.renderFirst()) hoistedSource += n + rendered; + else magicString.addSource(new MagicString(rendered)); + } + const accessedGlobalVariables = this.accessedGlobalsByScope.get(module.scope); + if (accessedGlobalVariables) { + for (const name of accessedGlobalVariables) { + accessedGlobals.add(name); } } } - for (const importMeta of module.importMetas) { - importMeta.addAccessedGlobals(this.outputOptions.format, accessedGlobalsByScope); - } - if (this.includedNamespaces.has(module) && !this.outputOptions.preserveModules) { - module.namespace.prepare(accessedGlobalsByScope); - } + const { renderedExports, removedExports } = module.getRenderedExports(); + renderedModules[module.id] = { + get code() { + return source?.toString() ?? null; + }, + originalLength: module.originalCode.length, + removedExports, + renderedExports, + renderedLength + }; + } + + if (hoistedSource) magicString.prepend(hoistedSource + n + n); + + if (this.needsExportsShim) { + magicString.prepend( + `${n}${snippets.cnst} ${MISSING_EXPORT_SHIM_VARIABLE}${_}=${_}void 0;${n}${n}` + ); + } + const renderedSource = compact ? magicString : magicString.trim(); + + if (isEmpty && this.getExportNames().length === 0 && dependencies.size === 0) { + const chunkName = this.getChunkName(); + onwarn({ + chunkName, + code: 'EMPTY_BUNDLE', + message: `Generated an empty chunk: "${chunkName}"` + }); } + return { accessedGlobals, indent, magicString, renderedSource, usedModules, usesTopLevelAwait }; } - private setExternalRenderPaths(options: NormalizedOutputOptions, inputBase: string): void { - for (const dependency of [...this.dependencies, ...this.dynamicDependencies]) { - if (dependency instanceof ExternalModule) { - dependency.setRenderPath(options, inputBase); + private setDynamicImportResolutions(fileName: string) { + const { accessedGlobalsByScope, outputOptions, pluginDriver, snippets } = this; + for (const resolvedDynamicImport of this.getIncludedDynamicImports()) { + if (resolvedDynamicImport.chunk) { + const { chunk, facadeChunk, node, resolution } = resolvedDynamicImport; + if (chunk === this) { + node.setInternalResolution(resolution.namespace); + } else { + node.setExternalResolution( + (facadeChunk || chunk).exportMode, + resolution, + outputOptions, + snippets, + pluginDriver, + accessedGlobalsByScope, + `'${(facadeChunk || chunk).getImportPath(fileName)}'`, + !facadeChunk?.strictFacade && chunk.exportNamesByVariable.get(resolution.namespace)![0] + ); + } + } else { + const { resolution } = resolvedDynamicImport; + resolvedDynamicImport.node.setExternalResolution( + 'external', + resolution, + outputOptions, + snippets, + pluginDriver, + accessedGlobalsByScope, + resolution instanceof ExternalModule + ? `'${this.externalChunkByModule.get(resolution)!.getImportPath(fileName)}'` + : resolution || '', + false + ); } } } - private setIdentifierRenderResolutions({ - format, - interop, - namespaceToStringTag - }: NormalizedOutputOptions) { + private setIdentifierRenderResolutions() { + const { format, interop, namespaceToStringTag } = this.outputOptions; const syntheticExports = new Set(); for (const exportName of this.getExportNames()) { const exportVariable = this.exportsByName.get(exportName)!; @@ -1358,6 +1291,7 @@ export default class Chunk { this.outputOptions.preserveModules, this.outputOptions.externalLiveBindings, this.chunkByModule, + this.externalChunkByModule, syntheticExports, this.exportNamesByVariable, this.accessedGlobalsByScope, @@ -1365,6 +1299,22 @@ export default class Chunk { ); } + private setImportMetaResolutions(fileName: string) { + const { + accessedGlobalsByScope, + includedNamespaces, + outputOptions: { format, preserveModules } + } = this; + for (const module of this.orderedModules) { + for (const importMeta of module.importMetas) { + importMeta.setResolution(format, accessedGlobalsByScope, fileName); + } + if (includedNamespaces.has(module) && !preserveModules) { + module.namespace.prepare(accessedGlobalsByScope); + } + } + } + private setUpChunkImportsAndExportsForModule(module: Module): void { const moduleImports = new Set(module.includedImports); // when we are not preserving modules, we need to make all namespace variables available for @@ -1425,4 +1375,28 @@ function getChunkNameFromModule(module: Module): string { ); } +function getImportedBindingsPerDependency( + renderedDependencies: RenderedDependencies, + resolveFileName: (dependency: Chunk | ExternalChunk) => string +): { + [imported: string]: string[]; +} { + const importedBindingsPerDependency: { [imported: string]: string[] } = {}; + for (const [dependency, declaration] of renderedDependencies) { + const specifiers = new Set(); + if (declaration.imports) { + for (const { imported } of declaration.imports) { + specifiers.add(imported); + } + } + if (declaration.reexports) { + for (const { imported } of declaration.reexports) { + specifiers.add(imported); + } + } + importedBindingsPerDependency[resolveFileName(dependency)] = [...specifiers]; + } + return importedBindingsPerDependency; +} + const QUERY_HASH_REGEX = /[?#]/; diff --git a/src/ExternalChunk.ts b/src/ExternalChunk.ts new file mode 100644 index 00000000000..2e76832b61e --- /dev/null +++ b/src/ExternalChunk.ts @@ -0,0 +1,44 @@ +import ExternalModule from './ExternalModule'; +import { NormalizedOutputOptions } from './rollup/types'; +import { escapeId } from './utils/escapeId'; +import { normalize, relative } from './utils/path'; +import { getImportPath } from './utils/relativeId'; + +export default class ExternalChunk { + defaultVariableName = ''; + id: string; + namespaceVariableName = ''; + suggestedVariableName: string; + variableName = ''; + + private fileName: string | null = null; + private renormalizeRenderPath: boolean; + + constructor( + module: ExternalModule, + private options: NormalizedOutputOptions, + private inputBase: string + ) { + this.id = module.id; + this.renormalizeRenderPath = module.renormalizeRenderPath; + this.suggestedVariableName = module.suggestedVariableName; + } + + getFileName(): string { + if (this.fileName) { + return this.fileName; + } + const { paths } = this.options; + return (this.fileName = + (typeof paths === 'function' ? paths(this.id) : paths[this.id]) || + (this.renormalizeRenderPath ? normalize(relative(this.inputBase, this.id)) : this.id)); + } + + getImportPath(importer: string): string { + return escapeId( + this.renormalizeRenderPath + ? getImportPath(importer, this.getFileName(), this.options.format === 'amd', false) + : this.getFileName() + ); + } +} diff --git a/src/ExternalModule.ts b/src/ExternalModule.ts index 8255da456af..d2157cbcde4 100644 --- a/src/ExternalModule.ts +++ b/src/ExternalModule.ts @@ -1,33 +1,24 @@ import ExternalVariable from './ast/variables/ExternalVariable'; -import type { - CustomPluginOptions, - ModuleInfo, - NormalizedInputOptions, - NormalizedOutputOptions -} from './rollup/types'; +import type { CustomPluginOptions, ModuleInfo, NormalizedInputOptions } from './rollup/types'; import { EMPTY_ARRAY } from './utils/blank'; import { warnDeprecation } from './utils/error'; import { makeLegal } from './utils/identifierHelpers'; -import { normalize, relative } from './utils/path'; import { printQuotedStringList } from './utils/printStringList'; import relativeId from './utils/relativeId'; export default class ExternalModule { - readonly declarations = new Map(); - defaultVariableName = ''; readonly dynamicImporters: string[] = []; execIndex = Infinity; readonly exportedVariables = new Map(); readonly importers: string[] = []; readonly info: ModuleInfo; - mostCommonSuggestion = 0; - readonly nameSuggestions = new Map(); - namespaceVariableName = ''; reexported = false; - renderPath: string = undefined as never; suggestedVariableName: string; used = false; - variableName = ''; + + private readonly declarations = new Map(); + private mostCommonSuggestion = 0; + private readonly nameSuggestions = new Map(); constructor( private readonly options: NormalizedInputOptions, @@ -87,16 +78,6 @@ export default class ExternalModule { return [externalVariable]; } - setRenderPath(options: NormalizedOutputOptions, inputBase: string): void { - this.renderPath = - typeof options.paths === 'function' ? options.paths(this.id) : options.paths[this.id]; - if (!this.renderPath) { - this.renderPath = this.renormalizeRenderPath - ? normalize(relative(inputBase, this.id)) - : this.id; - } - } - suggestName(name: string): void { const value = (this.nameSuggestions.get(name) ?? 0) + 1; this.nameSuggestions.set(name, value); diff --git a/src/Module.ts b/src/Module.ts index 5ca4f29dd66..1b7a851de76 100644 --- a/src/Module.ts +++ b/src/Module.ts @@ -51,6 +51,7 @@ import { augmentCodeLocation, errAmbiguousExternalNamespaces, errCircularReexport, + errInvalidFormatForTopLevelAwait, errMissingExport, errNamespaceConflict, error, @@ -222,7 +223,6 @@ export default class Module { declare sourcemapChain: DecodedSourceMapOrMissing[]; readonly sources = new Set(); declare transformFiles?: EmittedFile[]; - usesTopLevelAwait = false; private allExportNames: Set | null = null; private ast: Program | null = null; @@ -686,11 +686,15 @@ export default class Module { this.exportAllModules.push(...externalExportAllModules); } - render(options: RenderOptions): MagicString { - const magicString = this.magicString.clone(); - this.ast!.render(magicString, options); - this.usesTopLevelAwait = this.astContext.usesTopLevelAwait; - return magicString; + render(options: RenderOptions): { source: MagicString; usesTopLevelAwait: boolean } { + const source = this.magicString.clone(); + this.ast!.render(source, options); + source.trim(); + const { usesTopLevelAwait } = this.astContext; + if (usesTopLevelAwait && options.format !== 'es' && options.format !== 'system') { + return error(errInvalidFormatForTopLevelAwait(this.id, options.format)); + } + return { source, usesTopLevelAwait }; } setSource({ diff --git a/src/ast/nodes/ImportExpression.ts b/src/ast/nodes/ImportExpression.ts index 8f9121ea603..8d2e8574e84 100644 --- a/src/ast/nodes/ImportExpression.ts +++ b/src/ast/nodes/ImportExpression.ts @@ -26,7 +26,9 @@ export default class ImportExpression extends NodeBase { declare type: NodeType.tImportExpression; private mechanism: DynamicImportMechanism | null = null; + private namespaceExportName: string | false | undefined = undefined; private resolution: Module | ExternalModule | string | null = null; + private resolutionString: string | null = null; hasEffects(): boolean { return true; @@ -46,10 +48,10 @@ export default class ImportExpression extends NodeBase { } render(code: MagicString, options: RenderOptions): void { + const { + snippets: { getDirectReturnFunction, getPropertyAccess } + } = options; if (this.inlineNamespace) { - const { - snippets: { getDirectReturnFunction, getPropertyAccess } - } = options; const [left, right] = getDirectReturnFunction([], { functionReturn: true, lineBreakIndent: null, @@ -73,23 +75,18 @@ export default class ImportExpression extends NodeBase { ); code.overwrite(this.end - 1, this.end, this.mechanism.right, { contentOnly: true }); } - this.source.render(code, options); - } - - renderFinalResolution( - code: MagicString, - resolution: string, - namespaceExportName: string | false | undefined, - { getDirectReturnFunction }: GenerateCodeSnippets - ): void { - code.overwrite(this.source.start, this.source.end, resolution); - if (namespaceExportName) { - const [left, right] = getDirectReturnFunction(['n'], { - functionReturn: true, - lineBreakIndent: null, - name: null - }); - code.prependLeft(this.end, `.then(${left}n.${namespaceExportName}${right})`); + if (this.resolutionString) { + code.overwrite(this.source.start, this.source.end, this.resolutionString); + if (this.namespaceExportName) { + const [left, right] = getDirectReturnFunction(['n'], { + functionReturn: true, + lineBreakIndent: null, + name: null + }); + code.prependLeft(this.end, `.then(${left}n.${this.namespaceExportName}${right})`); + } + } else { + this.source.render(code, options); } } @@ -99,11 +96,15 @@ export default class ImportExpression extends NodeBase { options: NormalizedOutputOptions, snippets: GenerateCodeSnippets, pluginDriver: PluginDriver, - accessedGlobalsByScope: Map> + accessedGlobalsByScope: Map>, + resolutionString: string, + namespaceExportName: string | false | undefined ): void { const { format } = options; this.inlineNamespace = null; this.resolution = resolution; + this.resolutionString = resolutionString; + this.namespaceExportName = namespaceExportName; const accessedGlobals = [...(accessedImportGlobals[format] || [])]; let helper: string | null; ({ helper, mechanism: this.mechanism } = this.getDynamicImportMechanismAndHelper( diff --git a/src/ast/nodes/MetaProperty.ts b/src/ast/nodes/MetaProperty.ts index 807d8e6f194..6a09f3867d9 100644 --- a/src/ast/nodes/MetaProperty.ts +++ b/src/ast/nodes/MetaProperty.ts @@ -3,6 +3,7 @@ import type { InternalModuleFormat } from '../../rollup/types'; import type { PluginDriver } from '../../utils/PluginDriver'; import type { GenerateCodeSnippets } from '../../utils/generateCodeSnippets'; import { dirname, normalize, relative } from '../../utils/path'; +import { RenderOptions } from '../../utils/renderHelpers'; import { INTERACTION_ACCESSED, NodeInteraction } from '../NodeInteractions'; import type ChildScope from '../scopes/ChildScope'; import type { ObjectPath } from '../utils/PathTracker'; @@ -18,26 +19,13 @@ export default class MetaProperty extends NodeBase { declare property: Identifier; declare type: NodeType.tMetaProperty; - private declare metaProperty?: string | null; - - addAccessedGlobals( - format: InternalModuleFormat, - accessedGlobalsByScope: Map> - ): void { - const metaProperty = this.metaProperty; - const accessedGlobals = ( - metaProperty && metaProperty.startsWith(FILE_PREFIX) - ? accessedFileUrlGlobals - : accessedMetaUrlGlobals - )[format]; - if (accessedGlobals.length > 0) { - this.scope.addAccessedGlobals(accessedGlobals, accessedGlobalsByScope); - } - } + private metaProperty: string | null = null; + private preliminaryChunkId: string | null = null; + private referenceId: string | null = null; getReferencedFileName(outputPluginDriver: PluginDriver): string | null { - const metaProperty = this.metaProperty as string | null; - if (metaProperty && metaProperty.startsWith(FILE_PREFIX)) { + const { metaProperty } = this; + if (metaProperty?.startsWith(FILE_PREFIX)) { return outputPluginDriver.getFileName(metaProperty.substring(FILE_PREFIX.length)); } return null; @@ -57,31 +45,26 @@ export default class MetaProperty extends NodeBase { if (this.meta.name === 'import') { this.context.addImportMeta(this); const parent = this.parent; - this.metaProperty = + const metaProperty = (this.metaProperty = parent instanceof MemberExpression && typeof parent.propertyKey === 'string' ? parent.propertyKey - : null; + : null); + if (metaProperty?.startsWith(FILE_PREFIX)) { + this.referenceId = metaProperty.substring(FILE_PREFIX.length); + } } } } - renderFinalMechanism( - code: MagicString, - chunkId: string, - format: InternalModuleFormat, - snippets: GenerateCodeSnippets, - outputPluginDriver: PluginDriver - ): void { - const parent = this.parent; - const metaProperty = this.metaProperty as string | null; + render(code: MagicString, { format, pluginDriver, snippets }: RenderOptions): void { + const { metaProperty, parent, referenceId } = this; + const chunkId = this.preliminaryChunkId!; - if (metaProperty && metaProperty.startsWith(FILE_PREFIX)) { - let referenceId: string | null = null; - referenceId = metaProperty.substring(FILE_PREFIX.length); - const fileName = outputPluginDriver.getFileName(referenceId); + if (referenceId) { + const fileName = pluginDriver.getFileName(referenceId); const relativePath = normalize(relative(dirname(chunkId), fileName)); const replacement = - outputPluginDriver.hookFirstSync('resolveFileUrl', [ + pluginDriver.hookFirstSync('resolveFileUrl', [ { chunkId, fileName, @@ -102,7 +85,7 @@ export default class MetaProperty extends NodeBase { } const replacement = - outputPluginDriver.hookFirstSync('resolveImportMeta', [ + pluginDriver.hookFirstSync('resolveImportMeta', [ metaProperty, { chunkId, @@ -118,6 +101,20 @@ export default class MetaProperty extends NodeBase { } } } + + setResolution( + format: InternalModuleFormat, + accessedGlobalsByScope: Map>, + preliminaryChunkId: string + ): void { + this.preliminaryChunkId = preliminaryChunkId; + const accessedGlobals = ( + this.metaProperty?.startsWith(FILE_PREFIX) ? accessedFileUrlGlobals : accessedMetaUrlGlobals + )[format]; + if (accessedGlobals.length > 0) { + this.scope.addAccessedGlobals(accessedGlobals, accessedGlobalsByScope); + } + } } const accessedMetaUrlGlobals = { diff --git a/src/finalisers/amd.ts b/src/finalisers/amd.ts index 244c8d6f8a0..84360d431fe 100644 --- a/src/finalisers/amd.ts +++ b/src/finalisers/amd.ts @@ -1,4 +1,4 @@ -import type { Bundle, Bundle as MagicStringBundle } from 'magic-string'; +import type { Bundle as MagicStringBundle } from 'magic-string'; import type { NormalizedOutputOptions } from '../rollup/types'; import getCompleteAmdId from './shared/getCompleteAmdId'; import { getExportBlock, getNamespaceMarkers } from './shared/getExportBlock'; @@ -22,7 +22,7 @@ export default function amd( namedExportsMode, outro, snippets, - warn + onwarn }: FinaliserOptions, { amd, @@ -33,10 +33,10 @@ export default function amd( namespaceToStringTag, strict }: NormalizedOutputOptions -): Bundle { - warnOnBuiltins(warn, dependencies); +): void { + warnOnBuiltins(onwarn, dependencies); const deps = dependencies.map( - m => `'${updateExtensionForRelativeAmdId(m.id, amd.forceJsExtensionForImports)}'` + m => `'${updateExtensionForRelativeAmdId(m.importPath, amd.forceJsExtensionForImports)}'` ); const args = dependencies.map(m => m.name); const { n, getNonArrowFunctionIntro, _ } = snippets; @@ -93,18 +93,16 @@ export default function amd( if (namespaceMarkers) { namespaceMarkers = n + n + namespaceMarkers; } - magicString.append(`${exportBlock}${namespaceMarkers}${outro}`); - return ( - magicString - .indent(t) - // factory function should be wrapped by parentheses to avoid lazy parsing, - // cf. https://v8.dev/blog/preparser#pife - .prepend( - `${amd.define}(${params}(${getNonArrowFunctionIntro(args, { - isAsync: false, - name: null - })}{${useStrict}${n}${n}` - ) - .append(`${n}${n}}));`) - ); + magicString + .append(`${exportBlock}${namespaceMarkers}${outro}`) + .indent(t) + // factory function should be wrapped by parentheses to avoid lazy parsing, + // cf. https://v8.dev/blog/preparser#pife + .prepend( + `${amd.define}(${params}(${getNonArrowFunctionIntro(args, { + isAsync: false, + name: null + })}{${useStrict}${n}${n}` + ) + .append(`${n}${n}}));`); } diff --git a/src/finalisers/cjs.ts b/src/finalisers/cjs.ts index be0ed121db2..c7852b62634 100644 --- a/src/finalisers/cjs.ts +++ b/src/finalisers/cjs.ts @@ -1,5 +1,5 @@ -import type { Bundle, Bundle as MagicStringBundle } from 'magic-string'; -import type { ChunkDependencies } from '../Chunk'; +import type { Bundle as MagicStringBundle } from 'magic-string'; +import { ChunkDependency } from '../Chunk'; import type { NormalizedOutputOptions } from '../rollup/types'; import type { GenerateCodeSnippets } from '../utils/generateCodeSnippets'; import { getExportBlock, getNamespaceMarkers } from './shared/getExportBlock'; @@ -30,7 +30,7 @@ export default function cjs( namespaceToStringTag, strict }: NormalizedOutputOptions -): Bundle { +): void { const { _, n } = snippets; const useStrict = strict ? `'use strict';${n}${n}` : ''; @@ -68,27 +68,27 @@ export default function cjs( `module.exports${_}=${_}` ); - return magicString.append(`${exportBlock}${outro}`); + magicString.append(`${exportBlock}${outro}`); } function getImportBlock( - dependencies: ChunkDependencies, + dependencies: ChunkDependency[], { _, cnst, n }: GenerateCodeSnippets, compact: boolean ): string { let importBlock = ''; let definingVariable = false; - for (const { id, name, reexports, imports } of dependencies) { + for (const { importPath, name, reexports, imports } of dependencies) { if (!reexports && !imports) { if (importBlock) { importBlock += compact && !definingVariable ? ',' : `;${n}`; } definingVariable = false; - importBlock += `require('${id}')`; + importBlock += `require('${importPath}')`; } else { importBlock += compact && definingVariable ? ',' : `${importBlock ? `;${n}` : ''}${cnst} `; definingVariable = true; - importBlock += `${name}${_}=${_}require('${id}')`; + importBlock += `${name}${_}=${_}require('${importPath}')`; } } if (importBlock) { diff --git a/src/finalisers/es.ts b/src/finalisers/es.ts index 320109e13c2..668f2000322 100644 --- a/src/finalisers/es.ts +++ b/src/finalisers/es.ts @@ -1,5 +1,5 @@ -import type { Bundle, Bundle as MagicStringBundle } from 'magic-string'; -import type { ChunkDependencies, ChunkExports, ImportSpecifier, ReexportSpecifier } from '../Chunk'; +import type { Bundle as MagicStringBundle } from 'magic-string'; +import type { ChunkDependency, ChunkExports, ImportSpecifier, ReexportSpecifier } from '../Chunk'; import type { NormalizedOutputOptions } from '../rollup/types'; import type { GenerateCodeSnippets } from '../utils/generateCodeSnippets'; import { getHelpersBlock } from '../utils/interopHelpers'; @@ -9,7 +9,7 @@ export default function es( magicString: MagicStringBundle, { accessedGlobals, indent: t, intro, outro, dependencies, exports, snippets }: FinaliserOptions, { externalLiveBindings, freeze, namespaceToStringTag }: NormalizedOutputOptions -): Bundle { +): void { const { _, n } = snippets; const importBlock = getImportBlock(dependencies, _); @@ -29,14 +29,14 @@ export default function es( if (exportBlock.length) magicString.append(n + n + exportBlock.join(n).trim()); if (outro) magicString.append(outro); - return magicString.trim(); + magicString.trim(); } -function getImportBlock(dependencies: ChunkDependencies, _: string): string[] { +function getImportBlock(dependencies: ChunkDependency[], _: string): string[] { const importBlock: string[] = []; - for (const { id, reexports, imports, name } of dependencies) { + for (const { importPath, reexports, imports, name } of dependencies) { if (!reexports && !imports) { - importBlock.push(`import${_}'${id}';`); + importBlock.push(`import${_}'${importPath}';`); continue; } if (imports) { @@ -53,10 +53,10 @@ function getImportBlock(dependencies: ChunkDependencies, _: string): string[] { } } if (starImport) { - importBlock.push(`import${_}*${_}as ${starImport.local} from${_}'${id}';`); + importBlock.push(`import${_}*${_}as ${starImport.local} from${_}'${importPath}';`); } if (defaultImport && importedNames.length === 0) { - importBlock.push(`import ${defaultImport.local} from${_}'${id}';`); + importBlock.push(`import ${defaultImport.local} from${_}'${importPath}';`); } else if (importedNames.length > 0) { importBlock.push( `import ${defaultImport ? `${defaultImport.local},${_}` : ''}{${_}${importedNames @@ -67,7 +67,7 @@ function getImportBlock(dependencies: ChunkDependencies, _: string): string[] { return `${specifier.imported} as ${specifier.local}`; } }) - .join(`,${_}`)}${_}}${_}from${_}'${id}';` + .join(`,${_}`)}${_}}${_}from${_}'${importPath}';` ); } } @@ -85,14 +85,14 @@ function getImportBlock(dependencies: ChunkDependencies, _: string): string[] { } } if (starExport) { - importBlock.push(`export${_}*${_}from${_}'${id}';`); + importBlock.push(`export${_}*${_}from${_}'${importPath}';`); } if (namespaceReexports.length > 0) { if ( !imports || !imports.some(specifier => specifier.imported === '*' && specifier.local === name) ) { - importBlock.push(`import${_}*${_}as ${name} from${_}'${id}';`); + importBlock.push(`import${_}*${_}as ${name} from${_}'${importPath}';`); } for (const specifier of namespaceReexports) { importBlock.push( @@ -112,7 +112,7 @@ function getImportBlock(dependencies: ChunkDependencies, _: string): string[] { return `${specifier.imported} as ${specifier.reexported}`; } }) - .join(`,${_}`)}${_}}${_}from${_}'${id}';` + .join(`,${_}`)}${_}}${_}from${_}'${importPath}';` ); } } diff --git a/src/finalisers/iife.ts b/src/finalisers/iife.ts index eb34aa57c11..cd425f1268f 100644 --- a/src/finalisers/iife.ts +++ b/src/finalisers/iife.ts @@ -1,4 +1,4 @@ -import type { Bundle, Bundle as MagicStringBundle } from 'magic-string'; +import type { Bundle as MagicStringBundle } from 'magic-string'; import type { NormalizedOutputOptions } from '../rollup/types'; import { error } from '../utils/error'; import { isLegal } from '../utils/identifierHelpers'; @@ -22,7 +22,7 @@ export default function iife( namedExportsMode, outro, snippets, - warn + onwarn }: FinaliserOptions, { compact, @@ -36,7 +36,7 @@ export default function iife( namespaceToStringTag, strict }: NormalizedOutputOptions -): Bundle { +): void { const { _, getNonArrowFunctionIntro, getPropertyAccess, n } = snippets; const isNamespaced = name && name.includes('.'); const useVariableAssignment = !extend && !isNamespaced; @@ -48,14 +48,14 @@ export default function iife( }); } - warnOnBuiltins(warn, dependencies); + warnOnBuiltins(onwarn, dependencies); const external = trimEmptyImports(dependencies); const deps = external.map(dep => dep.globalName || 'null'); const args = external.map(m => m.name); if (hasExports && !name) { - warn({ + onwarn({ code: 'MISSING_NAME_OPTION_FOR_IIFE_EXPORT', message: `If you do not supply "output.name", you may not be able to access the exports of an IIFE bundle.` }); @@ -127,6 +127,9 @@ export default function iife( if (namespaceMarkers) { namespaceMarkers = n + n + namespaceMarkers; } - magicString.append(`${exportBlock}${namespaceMarkers}${outro}`); - return magicString.indent(t).prepend(wrapperIntro).append(wrapperOutro); + magicString + .append(`${exportBlock}${namespaceMarkers}${outro}`) + .indent(t) + .prepend(wrapperIntro) + .append(wrapperOutro); } diff --git a/src/finalisers/index.ts b/src/finalisers/index.ts index acbab8f085d..13a8aa1454e 100644 --- a/src/finalisers/index.ts +++ b/src/finalisers/index.ts @@ -1,5 +1,5 @@ import type { Bundle as MagicStringBundle } from 'magic-string'; -import type { ChunkDependencies, ChunkExports } from '../Chunk'; +import type { ChunkDependency, ChunkExports } from '../Chunk'; import type { NormalizedOutputOptions, RollupWarning } from '../rollup/types'; import type { GenerateCodeSnippets } from '../utils/generateCodeSnippets'; import amd from './amd'; @@ -11,7 +11,7 @@ import umd from './umd'; export interface FinaliserOptions { accessedGlobals: Set; - dependencies: ChunkDependencies; + dependencies: ChunkDependency[]; exports: ChunkExports; hasExports: boolean; id: string; @@ -23,14 +23,14 @@ export interface FinaliserOptions { outro: string; snippets: GenerateCodeSnippets; usesTopLevelAwait: boolean; - warn(warning: RollupWarning): void; + onwarn(warning: RollupWarning): void; } export type Finaliser = ( magicString: MagicStringBundle, finaliserOptions: FinaliserOptions, options: NormalizedOutputOptions -) => MagicStringBundle; +) => void; export default { amd, cjs, es, iife, system, umd } as { [format: string]: Finaliser; diff --git a/src/finalisers/shared/getExportBlock.ts b/src/finalisers/shared/getExportBlock.ts index 8664b178fe0..4d6fe42436d 100644 --- a/src/finalisers/shared/getExportBlock.ts +++ b/src/finalisers/shared/getExportBlock.ts @@ -1,4 +1,4 @@ -import type { ChunkDependencies, ChunkExports } from '../../Chunk'; +import type { ChunkDependency, ChunkExports } from '../../Chunk'; import type { GetInterop } from '../../rollup/types'; import type { GenerateCodeSnippets } from '../../utils/generateCodeSnippets'; import { @@ -10,7 +10,7 @@ import { export function getExportBlock( exports: ChunkExports, - dependencies: ChunkDependencies, + dependencies: ChunkDependency[], namedExportsMode: boolean, interop: GetInterop, snippets: GenerateCodeSnippets, @@ -33,7 +33,7 @@ export function getExportBlock( for (const { defaultVariableName, - id, + importPath, isChunk, name, namedExportsMode: depNamedExportsMode, @@ -51,7 +51,7 @@ export function getExportBlock( defaultVariableName!, namespaceVariableName!, interop, - id, + importPath, externalLiveBindings, getPropertyAccess ); @@ -117,7 +117,7 @@ export function getExportBlock( function getSingleDefaultExport( exports: ChunkExports, - dependencies: ChunkDependencies, + dependencies: ChunkDependency[], interop: GetInterop, externalLiveBindings: boolean, getPropertyAccess: (name: string) => string @@ -127,7 +127,7 @@ function getSingleDefaultExport( } else { for (const { defaultVariableName, - id, + importPath, isChunk, name, namedExportsMode: depNamedExportsMode, @@ -143,7 +143,7 @@ function getSingleDefaultExport( defaultVariableName!, namespaceVariableName!, interop, - id, + importPath, externalLiveBindings, getPropertyAccess ); diff --git a/src/finalisers/shared/getInteropBlock.ts b/src/finalisers/shared/getInteropBlock.ts index cbddb8d2aee..a305a7f4875 100644 --- a/src/finalisers/shared/getInteropBlock.ts +++ b/src/finalisers/shared/getInteropBlock.ts @@ -1,4 +1,4 @@ -import type { ModuleDeclarationDependency, ReexportSpecifier } from '../../Chunk'; +import type { ChunkDependency, ReexportSpecifier } from '../../Chunk'; import type { GetInterop } from '../../rollup/types'; import type { GenerateCodeSnippets } from '../../utils/generateCodeSnippets'; import { @@ -9,7 +9,7 @@ import { } from '../../utils/interopHelpers'; export default function getInteropBlock( - dependencies: readonly ModuleDeclarationDependency[], + dependencies: readonly ChunkDependency[], interop: GetInterop, externalLiveBindings: boolean, freeze: boolean, @@ -34,7 +34,7 @@ export default function getInteropBlock( for (const { defaultVariableName, imports, - id, + importPath, isChunk, name, namedExportsMode, @@ -58,7 +58,7 @@ export default function getInteropBlock( } } } else { - const moduleInterop = String(interop(id)); + const moduleInterop = String(interop(importPath)); let hasDefault = false; let hasNamespace = false; for (const { imported, reexported } of [ diff --git a/src/finalisers/shared/trimEmptyImports.ts b/src/finalisers/shared/trimEmptyImports.ts index 7c5051eac49..bf1c4701d61 100644 --- a/src/finalisers/shared/trimEmptyImports.ts +++ b/src/finalisers/shared/trimEmptyImports.ts @@ -1,8 +1,8 @@ -import type { ModuleDeclarationDependency } from '../../Chunk'; +import type { ChunkDependency } from '../../Chunk'; export default function trimEmptyImports( - dependencies: readonly ModuleDeclarationDependency[] -): ModuleDeclarationDependency[] { + dependencies: readonly ChunkDependency[] +): ChunkDependency[] { let i = dependencies.length; while (i--) { diff --git a/src/finalisers/shared/warnOnBuiltins.ts b/src/finalisers/shared/warnOnBuiltins.ts index 6457adf1127..dd8b0655bb0 100644 --- a/src/finalisers/shared/warnOnBuiltins.ts +++ b/src/finalisers/shared/warnOnBuiltins.ts @@ -1,4 +1,4 @@ -import type { ChunkDependencies } from '../../Chunk'; +import { ChunkDependency } from '../../Chunk'; import type { RollupWarning } from '../../rollup/types'; import { printQuotedStringList } from '../../utils/printStringList'; @@ -28,9 +28,11 @@ const builtins = { export default function warnOnBuiltins( warn: (warning: RollupWarning) => void, - dependencies: ChunkDependencies + dependencies: ChunkDependency[] ): void { - const externalBuiltins = dependencies.map(({ id }) => id).filter(id => id in builtins); + const externalBuiltins = dependencies + .map(({ importPath }) => importPath) + .filter(importPath => importPath in builtins); if (!externalBuiltins.length) return; diff --git a/src/finalisers/system.ts b/src/finalisers/system.ts index 703b825535c..24234a69c80 100644 --- a/src/finalisers/system.ts +++ b/src/finalisers/system.ts @@ -1,5 +1,5 @@ -import type { Bundle, Bundle as MagicStringBundle } from 'magic-string'; -import type { ChunkDependencies, ChunkExports, ModuleDeclarations } from '../Chunk'; +import type { Bundle as MagicStringBundle } from 'magic-string'; +import type { ChunkDependency, ChunkExports, ModuleDeclarations } from '../Chunk'; import type { NormalizedOutputOptions } from '../rollup/types'; import type { GenerateCodeSnippets } from '../utils/generateCodeSnippets'; import { getHelpersBlock } from '../utils/interopHelpers'; @@ -27,7 +27,7 @@ export default function system( strict, systemNullSetters }: NormalizedOutputOptions -): Bundle { +): void { const { _, getFunctionIntro, getNonArrowFunctionIntro, n, s } = snippets; const { importBindings, setters, starExcludes } = analyzeDependencies( dependencies, @@ -46,7 +46,7 @@ export default function system( // cf. https://v8.dev/blog/preparser#pife let wrapperStart = `System.register(${registeredName}[` + - dependencies.map(({ id }) => `'${id}'`).join(`,${_}`) + + dependencies.map(({ importPath }) => `'${importPath}'`).join(`,${_}`) + `],${_}(${getNonArrowFunctionIntro(wrapperParams, { isAsync: false, name: null })}{${n}${t}${ strict ? "'use strict';" : '' }` + @@ -75,29 +75,32 @@ export default function system( const wrapperEnd = `${t}${t}})${n}${t}}${s}${n}}));`; - magicString.prepend( - intro + - getHelpersBlock( - null, - accessedGlobals, - t, - snippets, - externalLiveBindings, - freeze, - namespaceToStringTag - ) + - getHoistedExportsBlock(exports, t, snippets) - ); - magicString.append( - `${outro}${n}${n}` + - getSyntheticExportsBlock(exports, t, snippets) + - getMissingExportsBlock(exports, t, snippets) - ); - return magicString.indent(`${t}${t}${t}`).append(wrapperEnd).prepend(wrapperStart); + magicString + .prepend( + intro + + getHelpersBlock( + null, + accessedGlobals, + t, + snippets, + externalLiveBindings, + freeze, + namespaceToStringTag + ) + + getHoistedExportsBlock(exports, t, snippets) + ) + .append( + `${outro}${n}${n}` + + getSyntheticExportsBlock(exports, t, snippets) + + getMissingExportsBlock(exports, t, snippets) + ) + .indent(`${t}${t}${t}`) + .append(wrapperEnd) + .prepend(wrapperStart); } function analyzeDependencies( - dependencies: ChunkDependencies, + dependencies: ChunkDependency[], exports: ChunkExports, t: string, { _, cnst, getObject, getPropertyAccess, n }: GenerateCodeSnippets diff --git a/src/finalisers/umd.ts b/src/finalisers/umd.ts index 30d08225fee..1be32dc5651 100644 --- a/src/finalisers/umd.ts +++ b/src/finalisers/umd.ts @@ -1,4 +1,4 @@ -import type { Bundle, Bundle as MagicStringBundle } from 'magic-string'; +import type { Bundle as MagicStringBundle } from 'magic-string'; import type { NormalizedOutputOptions } from '../rollup/types'; import { error } from '../utils/error'; import type { GenerateCodeSnippets } from '../utils/generateCodeSnippets'; @@ -12,7 +12,11 @@ import updateExtensionForRelativeAmdId from './shared/updateExtensionForRelative import warnOnBuiltins from './shared/warnOnBuiltins'; import type { FinaliserOptions } from './index'; -function globalProp(name: string, globalVar: string, getPropertyAccess: (name: string) => string) { +function globalProp( + name: string | false | undefined, + globalVar: string, + getPropertyAccess: (name: string) => string +) { if (!name) return 'null'; return `${globalVar}${keypath(name, getPropertyAccess)}`; } @@ -42,7 +46,7 @@ export default function umd( namedExportsMode, outro, snippets, - warn + onwarn }: FinaliserOptions, { amd, @@ -58,7 +62,7 @@ export default function umd( noConflict, strict }: NormalizedOutputOptions -): Bundle { +): void { const { _, cnst, getFunctionIntro, getNonArrowFunctionIntro, getPropertyAccess, n, s } = snippets; const factoryVar = compact ? 'f' : 'factory'; const globalVar = compact ? 'g' : 'global'; @@ -71,12 +75,12 @@ export default function umd( }); } - warnOnBuiltins(warn, dependencies); + warnOnBuiltins(onwarn, dependencies); const amdDeps = dependencies.map( - m => `'${updateExtensionForRelativeAmdId(m.id, amd.forceJsExtensionForImports)}'` + m => `'${updateExtensionForRelativeAmdId(m.importPath, amd.forceJsExtensionForImports)}'` ); - const cjsDeps = dependencies.map(m => `require('${m.id}')`); + const cjsDeps = dependencies.map(m => `require('${m.importPath}')`); const trimmedImports = trimEmptyImports(dependencies); const globalDeps = trimmedImports.map(module => @@ -210,6 +214,10 @@ export default function umd( if (namespaceMarkers) { namespaceMarkers = n + n + namespaceMarkers; } - magicString.append(`${exportBlock}${namespaceMarkers}${outro}`); - return magicString.trim().indent(t).append(wrapperOutro).prepend(wrapperIntro); + magicString + .append(`${exportBlock}${namespaceMarkers}${outro}`) + .trim() + .indent(t) + .append(wrapperOutro) + .prepend(wrapperIntro); } diff --git a/src/rollup/types.d.ts b/src/rollup/types.d.ts index c7f671bd767..2aa631d9c81 100644 --- a/src/rollup/types.d.ts +++ b/src/rollup/types.d.ts @@ -275,7 +275,8 @@ export type RenderChunkHook = ( this: PluginContext, code: string, chunk: RenderedChunk, - options: NormalizedOutputOptions + options: NormalizedOutputOptions, + meta: { chunks: Record } ) => { code: string; map?: SourceMapInput } | string | null | undefined; export type ResolveDynamicImportHook = ( @@ -302,7 +303,10 @@ export type ResolveFileUrlHook = ( } ) => string | null | void; -export type AddonHookFunction = (this: PluginContext) => string | Promise; +export type AddonHookFunction = ( + this: PluginContext, + chunk: RenderedChunk +) => string | Promise; export type AddonHook = string | AddonHookFunction; export type ChangeEvent = 'create' | 'update' | 'delete'; @@ -338,7 +342,7 @@ export interface OutputBundleWithPlaceholders { } export interface FunctionPluginHooks { - augmentChunkHash: (this: PluginContext, chunk: PreRenderedChunk) => string | void; + augmentChunkHash: (this: PluginContext, chunk: RenderedChunk) => string | void; buildEnd: (this: PluginContext, err?: Error) => void; buildStart: (this: PluginContext, options: NormalizedInputOptions) => void; closeBundle: (this: PluginContext) => void; @@ -474,11 +478,11 @@ export interface TreeshakingOptions preset?: TreeshakingPreset; } -interface GetManualChunkApi { +interface ManualChunkMeta { getModuleIds: () => IterableIterator; getModuleInfo: GetModuleInfo; } -export type GetManualChunk = (id: string, api: GetManualChunkApi) => string | null | void; +export type GetManualChunk = (id: string, meta: ManualChunkMeta) => string | null | void; export type ExternalOption = | (string | RegExp)[] @@ -612,10 +616,12 @@ export type NormalizedAmdOptions = ( forceJsExtensionForImports: boolean; }; +type AddonFunction = (chunk: RenderedChunk) => string | Promise; + export interface OutputOptions { amd?: AmdOptions; assetFileNames?: string | ((chunkInfo: PreRenderedAsset) => string); - banner?: string | (() => string | Promise); + banner?: string | AddonFunction; chunkFileNames?: string | ((chunkInfo: PreRenderedChunk) => string); compact?: boolean; // only required for bundle.write @@ -629,7 +635,7 @@ export interface OutputOptions { externalLiveBindings?: boolean; // only required for bundle.write file?: string; - footer?: string | (() => string | Promise); + footer?: string | AddonFunction; format?: ModuleFormat; freeze?: boolean; generatedCode?: GeneratedCodePreset | GeneratedCodeOptions; @@ -638,14 +644,14 @@ export interface OutputOptions { indent?: string | boolean; inlineDynamicImports?: boolean; interop?: InteropType | GetInterop; - intro?: string | (() => string | Promise); + intro?: string | AddonFunction; manualChunks?: ManualChunksOption; minifyInternalExports?: boolean; name?: string; /** @deprecated Use "generatedCode.symbols" instead. */ namespaceToStringTag?: boolean; noConflict?: boolean; - outro?: string | (() => string | Promise); + outro?: string | AddonFunction; paths?: OptionsPaths; plugins?: (OutputPlugin | null | false | undefined)[]; /** @deprecated Use "generatedCode.constBindings" instead. */ @@ -666,7 +672,7 @@ export interface OutputOptions { export interface NormalizedOutputOptions { amd: NormalizedAmdOptions; assetFileNames: string | ((chunkInfo: PreRenderedAsset) => string); - banner: () => string | Promise; + banner: AddonFunction; chunkFileNames: string | ((chunkInfo: PreRenderedChunk) => string); compact: boolean; dir: string | undefined; @@ -678,7 +684,7 @@ export interface NormalizedOutputOptions { extend: boolean; externalLiveBindings: boolean; file: string | undefined; - footer: () => string | Promise; + footer: AddonFunction; format: InternalModuleFormat; freeze: boolean; generatedCode: NormalizedGeneratedCodeOptions; @@ -687,14 +693,14 @@ export interface NormalizedOutputOptions { indent: true | string; inlineDynamicImports: boolean; interop: GetInterop; - intro: () => string | Promise; + intro: AddonFunction; manualChunks: ManualChunksOption; minifyInternalExports: boolean; name: string | undefined; /** @deprecated Use "generatedCode.symbols" instead. */ namespaceToStringTag: boolean; noConflict: boolean; - outro: () => string | Promise; + outro: AddonFunction; paths: OptionsPaths; plugins: OutputPlugin[]; /** @deprecated Use "generatedCode.constBindings" instead. */ @@ -746,15 +752,12 @@ export interface PreRenderedChunk { isDynamicEntry: boolean; isEntry: boolean; isImplicitEntry: boolean; - modules: { - [id: string]: RenderedModule; - }; + moduleIds: string[]; name: string; type: 'chunk'; } export interface RenderedChunk extends PreRenderedChunk { - code?: string; dynamicImports: string[]; fileName: string; implicitlyLoadedBefore: string[]; @@ -762,12 +765,15 @@ export interface RenderedChunk extends PreRenderedChunk { [imported: string]: string[]; }; imports: string[]; - map?: SourceMap; + modules: { + [id: string]: RenderedModule; + }; referencedFiles: string[]; } export interface OutputChunk extends RenderedChunk { code: string; + map: SourceMap | null; } export interface SerializablePluginCache { diff --git a/src/utils/FileEmitter.ts b/src/utils/FileEmitter.ts index 3c85715b3ac..14e803acd07 100644 --- a/src/utils/FileEmitter.ts +++ b/src/utils/FileEmitter.ts @@ -23,6 +23,7 @@ import { errNoAssetSourceSet, error } from './error'; +import { defaultHashSize } from './hashPlaceholders'; import { extname } from './path'; import { isPathFragment } from './relativeId'; import { makeUnique, renderNamePattern } from './renderNamePattern'; @@ -43,14 +44,11 @@ function generateAssetFileName( { ext: () => extname(emittedName).substring(1), extname: () => extname(emittedName), - hash() { - return createHash() - .update(emittedName) - .update(':') + hash: size => + createHash() .update(source) .digest('hex') - .substring(0, 8); - }, + .substring(0, size || defaultHashSize), name: () => emittedName.substring(0, emittedName.length - extname(emittedName).length) } ), @@ -143,9 +141,14 @@ function getChunkFileName( file: ConsumedChunk, facadeChunkByModule: ReadonlyMap | null ): string { - const fileName = file.fileName || (file.module && facadeChunkByModule?.get(file.module)?.id); - if (!fileName) return error(errChunkNotGeneratedForFileName(file.fileName || file.name)); - return fileName; + if (file.fileName) { + return file.fileName; + } + if (facadeChunkByModule) { + const chunk = facadeChunkByModule.get(file.module!)!; + return chunk.id || chunk.getFileName(); + } + return error(errChunkNotGeneratedForFileName(file.fileName || file.name)); } export class FileEmitter { @@ -164,13 +167,6 @@ export class FileEmitter { : new Map(); } - public assertAssetsFinalized = (): void => { - for (const [referenceId, emittedFile] of this.filesByReferenceId) { - if (emittedFile.type === 'asset' && typeof emittedFile.fileName !== 'string') - return error(errNoAssetSourceSet(emittedFile.name || referenceId)); - } - }; - public emitFile = (emittedFile: unknown): string => { if (!hasValidType(emittedFile)) { return error( @@ -196,6 +192,13 @@ export class FileEmitter { return this.emitAsset(emittedFile); }; + public finaliseAssets = (): void => { + for (const [referenceId, emittedFile] of this.filesByReferenceId) { + if (emittedFile.type === 'asset' && typeof emittedFile.fileName !== 'string') + return error(errNoAssetSourceSet(emittedFile.name || referenceId)); + } + }; + public getFileName = (fileReferenceId: string): string => { const emittedFile = this.filesByReferenceId.get(fileReferenceId); if (!emittedFile) return error(errFileReferenceIdNotFoundForFilename(fileReferenceId)); @@ -226,14 +229,16 @@ export class FileEmitter { } }; + public setChunkInformation = (facadeChunkByModule: ReadonlyMap): void => { + this.facadeChunkByModule = facadeChunkByModule; + }; + public setOutputBundle = ( outputBundle: OutputBundleWithPlaceholders, - outputOptions: NormalizedOutputOptions, - facadeChunkByModule: ReadonlyMap + outputOptions: NormalizedOutputOptions ): void => { this.outputOptions = outputOptions; this.bundle = outputBundle; - this.facadeChunkByModule = facadeChunkByModule; for (const emittedFile of this.filesByReferenceId.values()) { if (emittedFile.fileName) { reserveFileNameInBundle(emittedFile.fileName, this.bundle, this.options.onwarn); diff --git a/src/utils/PluginDriver.ts b/src/utils/PluginDriver.ts index e8918e46b02..0c697fd768c 100644 --- a/src/utils/PluginDriver.ts +++ b/src/utils/PluginDriver.ts @@ -68,10 +68,10 @@ export class PluginDriver { public readonly emitFile: EmitFile; public finaliseAssets: () => void; public getFileName: (fileReferenceId: string) => string; + public readonly setChunkInformation: (facadeChunkByModule: ReadonlyMap) => void; public readonly setOutputBundle: ( outputBundle: OutputBundleWithPlaceholders, - outputOptions: NormalizedOutputOptions, - facadeChunkByModule: ReadonlyMap + outputOptions: NormalizedOutputOptions ) => void; private readonly fileEmitter: FileEmitter; @@ -94,7 +94,8 @@ export class PluginDriver { ); this.emitFile = this.fileEmitter.emitFile.bind(this.fileEmitter); this.getFileName = this.fileEmitter.getFileName.bind(this.fileEmitter); - this.finaliseAssets = this.fileEmitter.assertAssetsFinalized.bind(this.fileEmitter); + this.finaliseAssets = this.fileEmitter.finaliseAssets.bind(this.fileEmitter); + this.setChunkInformation = this.fileEmitter.setChunkInformation.bind(this.fileEmitter); this.setOutputBundle = this.fileEmitter.setOutputBundle.bind(this.fileEmitter); this.plugins = userPlugins.concat(basePluginDriver ? basePluginDriver.plugins : []); const existingPluginNames = new Set(); diff --git a/src/utils/addons.ts b/src/utils/addons.ts index c9daeb4f12c..32e4ca9770b 100644 --- a/src/utils/addons.ts +++ b/src/utils/addons.ts @@ -1,6 +1,6 @@ -import type { NormalizedOutputOptions } from '../rollup/types'; +import type { NormalizedOutputOptions, RenderedChunk } from '../rollup/types'; import type { PluginDriver } from './PluginDriver'; -import { error } from './error'; +import { errAddonNotGenerated, error } from './error'; export interface Addons { banner: string; @@ -14,26 +14,23 @@ const concatDblSep = (out: string, next: string) => (next ? `${out}\n\n${next}` export async function createAddons( options: NormalizedOutputOptions, - outputPluginDriver: PluginDriver + outputPluginDriver: PluginDriver, + chunk: RenderedChunk ): Promise { try { let [banner, footer, intro, outro] = await Promise.all([ - outputPluginDriver.hookReduceValue('banner', options.banner(), [], concatSep), - outputPluginDriver.hookReduceValue('footer', options.footer(), [], concatSep), - outputPluginDriver.hookReduceValue('intro', options.intro(), [], concatDblSep), - outputPluginDriver.hookReduceValue('outro', options.outro(), [], concatDblSep) + outputPluginDriver.hookReduceValue('banner', options.banner(chunk), [chunk], concatSep), + outputPluginDriver.hookReduceValue('footer', options.footer(chunk), [chunk], concatSep), + outputPluginDriver.hookReduceValue('intro', options.intro(chunk), [chunk], concatDblSep), + outputPluginDriver.hookReduceValue('outro', options.outro(chunk), [chunk], concatDblSep) ]); if (intro) intro += '\n\n'; if (outro) outro = `\n\n${outro}`; - if (banner.length) banner += '\n'; - if (footer.length) footer = '\n' + footer; + if (banner) banner += '\n'; + if (footer) footer = '\n' + footer; return { banner, footer, intro, outro }; } catch (err: any) { - return error({ - code: 'ADDON_ERROR', - message: `Could not retrieve ${err.hook}. Check configuration of plugin ${err.plugin}. -\tError Message: ${err.message}` - }); + return error(errAddonNotGenerated(err.message, err.hook, err.plugin)); } } diff --git a/src/utils/deconflictChunk.ts b/src/utils/deconflictChunk.ts index e3bd7e91dbe..1ebcd189e3f 100644 --- a/src/utils/deconflictChunk.ts +++ b/src/utils/deconflictChunk.ts @@ -1,4 +1,5 @@ import type Chunk from '../Chunk'; +import ExternalChunk from '../ExternalChunk'; import ExternalModule from '../ExternalModule'; import type Module from '../Module'; import type ChildScope from '../ast/scopes/ChildScope'; @@ -15,9 +16,9 @@ import { import { getSafeName } from './safeName'; export interface DependenciesToBeDeconflicted { - deconflictedDefault: ReadonlySet; - deconflictedNamespace: ReadonlySet; - dependencies: ReadonlySet; + deconflictedDefault: ReadonlySet; + deconflictedNamespace: ReadonlySet; + dependencies: ReadonlySet; } const DECONFLICT_IMPORTED_VARIABLES_BY_FORMAT: { @@ -29,6 +30,7 @@ const DECONFLICT_IMPORTED_VARIABLES_BY_FORMAT: { preserveModules: boolean, externalLiveBindings: boolean, chunkByModule: ReadonlyMap, + externalChunkByModule: ReadonlyMap, syntheticExports: ReadonlySet ) => void; } = { @@ -50,6 +52,7 @@ export function deconflictChunk( preserveModules: boolean, externalLiveBindings: boolean, chunkByModule: ReadonlyMap, + externalChunkByModule: ReadonlyMap, syntheticExports: ReadonlySet, exportNamesByVariable: ReadonlyMap, accessedGlobalsByScope: ReadonlyMap>, @@ -73,6 +76,7 @@ export function deconflictChunk( preserveModules, externalLiveBindings, chunkByModule, + externalChunkByModule, syntheticExports ); @@ -89,11 +93,12 @@ function deconflictImportsEsmOrSystem( preserveModules: boolean, _externalLiveBindings: boolean, chunkByModule: ReadonlyMap, + externalChunkByModule: ReadonlyMap, syntheticExports: ReadonlySet ) { // This is needed for namespace reexports for (const dependency of dependenciesToBeDeconflicted.dependencies) { - if (preserveModules || dependency instanceof ExternalModule) { + if (preserveModules || dependency instanceof ExternalChunk) { dependency.variableName = getSafeName(dependency.suggestedVariableName, usedNames); } } @@ -103,7 +108,10 @@ function deconflictImportsEsmOrSystem( if (variable.isNamespace && (preserveModules || module instanceof ExternalModule)) { variable.setRenderNames( null, - (module instanceof ExternalModule ? module : chunkByModule.get(module)!).variableName + (module instanceof ExternalModule + ? externalChunkByModule.get(module)! + : chunkByModule.get(module)! + ).variableName ); } else if (module instanceof ExternalModule && name === 'default') { variable.setRenderNames( @@ -133,17 +141,15 @@ function deconflictImportsOther( interop: GetInterop, preserveModules: boolean, externalLiveBindings: boolean, - chunkByModule: ReadonlyMap + chunkByModule: ReadonlyMap, + externalChunkByModule: ReadonlyMap ): void { - for (const chunkOrExternalModule of dependencies) { - chunkOrExternalModule.variableName = getSafeName( - chunkOrExternalModule.suggestedVariableName, - usedNames - ); + for (const chunk of dependencies) { + chunk.variableName = getSafeName(chunk.suggestedVariableName, usedNames); } - for (const externalModuleOrChunk of deconflictedNamespace) { - externalModuleOrChunk.namespaceVariableName = getSafeName( - `${externalModuleOrChunk.suggestedVariableName}__namespace`, + for (const chunk of deconflictedNamespace) { + chunk.namespaceVariableName = getSafeName( + `${chunk.suggestedVariableName}__namespace`, usedNames ); } @@ -163,12 +169,13 @@ function deconflictImportsOther( for (const variable of imports) { const module = variable.module; if (module instanceof ExternalModule) { + const chunk = externalChunkByModule.get(module)!; const name = variable.name; if (name === 'default') { const moduleInterop = String(interop(module.id)); const variableName = defaultInteropHelpersByInteropType[moduleInterop] - ? module.defaultVariableName - : module.variableName; + ? chunk.defaultVariableName + : chunk.variableName; if (isDefaultAProperty(moduleInterop, externalLiveBindings)) { variable.setRenderNames(variableName, 'default'); } else { @@ -178,12 +185,12 @@ function deconflictImportsOther( variable.setRenderNames( null, namespaceInteropHelpersByInteropType[String(interop(module.id))] - ? module.namespaceVariableName - : module.variableName + ? chunk.namespaceVariableName + : chunk.variableName ); } else { // if the second parameter is `null`, it uses its "name" for the property name - variable.setRenderNames(module.variableName, null); + variable.setRenderNames(chunk.variableName, null); } } else { const chunk = chunkByModule.get(module!)!; diff --git a/src/utils/error.ts b/src/utils/error.ts index 44f1972700e..9fa88ce3fdf 100644 --- a/src/utils/error.ts +++ b/src/utils/error.ts @@ -1,6 +1,7 @@ import { locate } from 'locate-character'; import type Module from '../Module'; import type { + InternalModuleFormat, NormalizedInputOptions, RollupError, RollupLogProps, @@ -38,6 +39,7 @@ export function augmentCodeLocation( } export const enum Errors { + ADDON_ERROR = 'ADDON_ERROR', ALREADY_CLOSED = 'ALREADY_CLOSED', ASSET_NOT_FINALISED = 'ASSET_NOT_FINALISED', ASSET_NOT_FOUND = 'ASSET_NOT_FOUND', @@ -60,6 +62,7 @@ export const enum Errors { INVALID_OPTION = 'INVALID_OPTION', INVALID_PLUGIN_HOOK = 'INVALID_PLUGIN_HOOK', INVALID_ROLLUP_PHASE = 'INVALID_ROLLUP_PHASE', + INVALID_TLA_FORMAT = 'INVALID_TLA_FORMAT', MISSING_EXPORT = 'MISSING_EXPORT', MISSING_IMPLICIT_DEPENDANT = 'MISSING_IMPLICIT_DEPENDANT', MIXED_EXPORTS = 'MIXED_EXPORTS', @@ -75,10 +78,22 @@ export const enum Errors { VALIDATION_ERROR = 'VALIDATION_ERROR' } +export function errAddonNotGenerated( + message: string, + hook: string, + plugin: string +): RollupLogProps { + return { + code: Errors.ADDON_ERROR, + message: `Could not retrieve ${hook}. Check configuration of plugin ${plugin}. +\tError Message: ${message}` + }; +} + export function errAssetNotFinalisedForFileName(name: string): RollupLogProps { return { code: Errors.ASSET_NOT_FINALISED, - message: `Plugin error - Unable to get file name for asset "${name}". Ensure that the source is set and that generate is called first.` + message: `Plugin error - Unable to get file name for asset "${name}". Ensure that the source is set and that generate is called first. If you reference assets via import.meta.ROLLUP_FILE_URL_, you need to either have set their source after "renderStart" or need to provide an explicit "fileName" when emitting them.` }; } @@ -92,7 +107,7 @@ export function errCannotEmitFromOptionsHook(): RollupLogProps { export function errChunkNotGeneratedForFileName(name: string): RollupLogProps { return { code: Errors.CHUNK_NOT_GENERATED, - message: `Plugin error - Unable to get file name for chunk "${name}". Ensure that generate is called first.` + message: `Plugin error - Unable to get file name for emitted chunk "${name}". You can only get file names once chunks have been generated after the "renderStart" hook.` }; } @@ -287,6 +302,17 @@ export function errInvalidRollupPhaseForChunkEmission(): RollupLogProps { }; } +export function errInvalidFormatForTopLevelAwait( + id: string, + format: InternalModuleFormat +): RollupLogProps { + return { + code: Errors.INVALID_TLA_FORMAT, + id, + message: `Module format ${format} does not support top-level await. Use the "es" or "system" output formats rather.` + }; +} + export function errMissingExport( exportName: string, importingModule: string, diff --git a/src/utils/getStaticDependencies.ts b/src/utils/getStaticDependencies.ts index 41d4a72a26a..8363ed0cb02 100644 --- a/src/utils/getStaticDependencies.ts +++ b/src/utils/getStaticDependencies.ts @@ -1,23 +1,32 @@ import type Chunk from '../Chunk'; +import ExternalChunk from '../ExternalChunk'; import ExternalModule from '../ExternalModule'; import type Module from '../Module'; export function getStaticDependencies( chunk: Chunk, orderedModules: readonly Module[], - chunkByModule: ReadonlyMap -): Set { - const staticDependencyBlocks: (Chunk | ExternalModule)[][] = []; + chunkByModule: ReadonlyMap, + externalChunkByModule: ReadonlyMap +): Set { + const staticDependencyBlocks: (Chunk | ExternalChunk)[][] = []; const handledDependencies = new Set(); for (let modulePos = orderedModules.length - 1; modulePos >= 0; modulePos--) { const module = orderedModules[modulePos]; if (!handledDependencies.has(module)) { - const staticDependencies: (Chunk | ExternalModule)[] = []; - addStaticDependencies(module, staticDependencies, handledDependencies, chunk, chunkByModule); + const staticDependencies: (Chunk | ExternalChunk)[] = []; + addStaticDependencies( + module, + staticDependencies, + handledDependencies, + chunk, + chunkByModule, + externalChunkByModule + ); staticDependencyBlocks.unshift(staticDependencies); } } - const dependencies = new Set(); + const dependencies = new Set(); for (const block of staticDependencyBlocks) { for (const dependency of block) { dependencies.add(dependency); @@ -28,15 +37,16 @@ export function getStaticDependencies( function addStaticDependencies( module: Module, - staticDependencies: (Chunk | ExternalModule)[], + staticDependencies: (Chunk | ExternalChunk)[], handledModules: Set, chunk: Chunk, - chunkByModule: ReadonlyMap + chunkByModule: ReadonlyMap, + externalChunkByModule: ReadonlyMap ): void { const dependencies = module.getDependenciesToBeIncluded(); for (const dependency of dependencies) { if (dependency instanceof ExternalModule) { - staticDependencies.push(dependency); + staticDependencies.push(externalChunkByModule.get(dependency)!); continue; } const dependencyChunk = chunkByModule.get(dependency)!; @@ -46,7 +56,14 @@ function addStaticDependencies( } if (!handledModules.has(dependency)) { handledModules.add(dependency); - addStaticDependencies(dependency, staticDependencies, handledModules, chunk, chunkByModule); + addStaticDependencies( + dependency, + staticDependencies, + handledModules, + chunk, + chunkByModule, + externalChunkByModule + ); } } } diff --git a/src/utils/hashPlaceholders.ts b/src/utils/hashPlaceholders.ts new file mode 100644 index 00000000000..a83b4cdda42 --- /dev/null +++ b/src/utils/hashPlaceholders.ts @@ -0,0 +1,72 @@ +import { errFailedValidation, error } from './error'; + +// Four random characters from the private use area to minimize risk of conflicts +const hashPlaceholderLeft = '\uf7f9\ue4d3'; +const hashPlaceholderRight = '\ue3cc\uf1fe'; +const hashPlaceholderOverhead = hashPlaceholderLeft.length + hashPlaceholderRight.length; + +// This is the size of a sha256 +export const maxHashSize = 64; +export const defaultHashSize = 8; + +export type HashPlaceholderGenerator = (optionName: string, hashSize?: number) => string; + +export const getHashPlaceholderGenerator = (): HashPlaceholderGenerator => { + let nextIndex = 0; + return (optionName: string, hashSize: number = defaultHashSize) => { + if (hashSize > maxHashSize) { + return error( + errFailedValidation( + `Hashes cannot be longer than ${maxHashSize} characters, received ${hashSize}. Check the "${optionName}" option.` + ) + ); + } + const placeholder = `${hashPlaceholderLeft}${String(++nextIndex).padStart( + hashSize - hashPlaceholderOverhead, + '0' + )}${hashPlaceholderRight}`; + if (placeholder.length > hashSize) { + return error( + errFailedValidation( + `To generate hashes for this number of chunks (currently ${nextIndex}), you need a minimum hash size of ${placeholder.length}, received ${hashSize}. Check the "${optionName}" option.` + ) + ); + } + nextIndex++; + return placeholder; + }; +}; + +const REPLACER_REGEX = new RegExp( + `${hashPlaceholderLeft}\\d{1,${maxHashSize - hashPlaceholderOverhead}}${hashPlaceholderRight}`, + 'g' +); + +export const replacePlaceholders = ( + code: string, + hashesByPlaceholder: Map +): string => + code.replace(REPLACER_REGEX, placeholder => hashesByPlaceholder.get(placeholder) || placeholder); + +export const replaceSinglePlaceholder = ( + code: string, + placeholder: string, + value: string +): string => code.replace(REPLACER_REGEX, match => (match === placeholder ? value : match)); + +export const replacePlaceholdersWithDefaultAndGetContainedPlaceholders = ( + code: string, + placeholders: Set +): { containedPlaceholders: Set; transformedCode: string } => { + const containedPlaceholders = new Set(); + const transformedCode = code.replace(REPLACER_REGEX, placeholder => { + if (placeholders.has(placeholder)) { + containedPlaceholders.add(placeholder); + return `${hashPlaceholderLeft}${'0'.repeat( + placeholder.length - hashPlaceholderOverhead + )}${hashPlaceholderRight}`; + } + return placeholder; + }); + return { containedPlaceholders, transformedCode }; +}; diff --git a/src/utils/options/normalizeOutputOptions.ts b/src/utils/options/normalizeOutputOptions.ts index 3ccb72d8bce..46eeb93f288 100644 --- a/src/utils/options/normalizeOutputOptions.ts +++ b/src/utils/options/normalizeOutputOptions.ts @@ -42,7 +42,7 @@ export function normalizeOutputOptions( chunkFileNames: config.chunkFileNames ?? '[name]-[hash].js', compact, dir: getDir(config, file), - dynamicImportFunction: getDynamicImportFunction(config, inputOptions), + dynamicImportFunction: getDynamicImportFunction(config, inputOptions, format), entryFileNames: getEntryFileNames(config, unsetOptions), esModule: config.esModule ?? true, exports: getExports(config, unsetOptions), @@ -277,14 +277,15 @@ const getAmd = (config: OutputOptions): NormalizedOutputOptions['amd'] => { return normalized; }; -const getAddon = (config: OutputOptions, name: string): (() => string | Promise) => { - const configAddon = (config as GenericConfigObject)[name] as - | string - | (() => string | Promise); +const getAddon = ( + config: OutputOptions, + name: T +): NormalizedOutputOptions[T] => { + const configAddon = (config as GenericConfigObject)[name]; if (typeof configAddon === 'function') { - return configAddon; + return configAddon as NormalizedOutputOptions[T]; } - return () => configAddon || ''; + return () => (configAddon as string) || ''; }; const getDir = ( @@ -306,7 +307,8 @@ const getDir = ( const getDynamicImportFunction = ( config: OutputOptions, - inputOptions: NormalizedInputOptions + inputOptions: NormalizedInputOptions, + format: InternalModuleFormat ): NormalizedOutputOptions['dynamicImportFunction'] => { const configDynamicImportFunction = config.dynamicImportFunction; if (configDynamicImportFunction) { @@ -315,6 +317,15 @@ const getDynamicImportFunction = ( true, inputOptions ); + if (format !== 'es') { + inputOptions.onwarn( + errInvalidOption( + 'output.dynamicImportFunction', + 'outputdynamicImportFunction', + 'this option is ignored for formats other than "es"' + ) + ); + } } return configDynamicImportFunction; }; diff --git a/src/utils/renderChunk.ts b/src/utils/renderChunk.ts deleted file mode 100644 index 8b2467abd61..00000000000 --- a/src/utils/renderChunk.ts +++ /dev/null @@ -1,51 +0,0 @@ -import type { - DecodedSourceMapOrMissing, - NormalizedOutputOptions, - Plugin, - RenderedChunk, - SourceMapInput -} from '../rollup/types'; -import type { PluginDriver } from './PluginDriver'; -import { decodedSourcemap } from './decodedSourcemap'; - -export default function renderChunk({ - code, - options, - outputPluginDriver, - renderChunk, - sourcemapChain -}: { - code: string; - options: NormalizedOutputOptions; - outputPluginDriver: PluginDriver; - renderChunk: RenderedChunk; - sourcemapChain: DecodedSourceMapOrMissing[]; -}): Promise { - const renderChunkReducer = ( - code: string, - result: { code: string; map?: SourceMapInput } | string | null | undefined, - plugin: Plugin - ): string => { - if (result == null) return code; - - if (typeof result === 'string') - result = { - code: result, - map: undefined - }; - - // strict null check allows 'null' maps to not be pushed to the chain, while 'undefined' gets the missing map warning - if (result.map !== null) { - const map = decodedSourcemap(result.map); - sourcemapChain.push(map || { missing: true, plugin: plugin.name }); - } - - return result.code; - }; - - return outputPluginDriver.hookReduceArg0( - 'renderChunk', - [code, renderChunk, options], - renderChunkReducer - ); -} diff --git a/src/utils/renderChunks.ts b/src/utils/renderChunks.ts new file mode 100644 index 00000000000..3cf3e7ab6d9 --- /dev/null +++ b/src/utils/renderChunks.ts @@ -0,0 +1,297 @@ +import { Bundle as MagicStringBundle, SourceMap } from 'magic-string'; +import Chunk, { ChunkRenderResult } from '../Chunk'; +import Module from '../Module'; +import { + DecodedSourceMapOrMissing, + NormalizedOutputOptions, + OutputBundleWithPlaceholders, + RenderedChunk, + WarningHandler +} from '../rollup/types'; +import { FILE_PLACEHOLDER } from './FileEmitter'; +import { PluginDriver } from './PluginDriver'; +import { collapseSourcemaps } from './collapseSourcemaps'; +import { createHash } from './crypto'; +import { decodedSourcemap } from './decodedSourcemap'; +import { errFailedValidation, error } from './error'; +import { + replacePlaceholders, + replacePlaceholdersWithDefaultAndGetContainedPlaceholders, + replaceSinglePlaceholder +} from './hashPlaceholders'; +import { normalize, resolve } from './path'; +import { timeEnd, timeStart } from './timers'; + +interface HashResult { + containedPlaceholders: Set; + contentHash: string; +} + +interface RenderedChunkWithPlaceholders { + chunk: Chunk; + code: string; + fileName: string; + map: SourceMap | null; +} + +export async function renderChunks( + chunks: Chunk[], + outputBundle: OutputBundleWithPlaceholders, + pluginDriver: PluginDriver, + outputOptions: NormalizedOutputOptions, + onwarn: WarningHandler +) { + reserveEntryChunksInBundle(chunks); + const renderedChunks = await Promise.all(chunks.map(chunk => chunk.render())); + const chunkGraph = getChunkGraph(chunks); + const { + nonHashedChunksWithPlaceholders, + renderedChunksByPlaceholder, + hashDependenciesByPlaceholder + } = await transformChunksAndGenerateContentHashes( + renderedChunks, + chunkGraph, + outputOptions, + pluginDriver, + onwarn + ); + const hashesByPlaceholder = generateFinalHashes( + renderedChunksByPlaceholder, + hashDependenciesByPlaceholder, + outputBundle + ); + addChunksToBundle( + renderedChunksByPlaceholder, + hashesByPlaceholder, + outputBundle, + nonHashedChunksWithPlaceholders + ); +} + +function reserveEntryChunksInBundle(chunks: Chunk[]) { + for (const chunk of chunks) { + if (chunk.facadeModule && chunk.facadeModule.isUserDefinedEntryPoint) { + // reserves name in bundle as side effect if it does not contain a hash + chunk.getPreliminaryFileName(); + } + } +} + +function getChunkGraph(chunks: Chunk[]) { + return Object.fromEntries( + chunks.map(chunk => { + const renderedChunkInfo = chunk.getRenderedChunkInfo(); + return [renderedChunkInfo.fileName, renderedChunkInfo]; + }) + ); +} + +async function transformChunk( + magicString: MagicStringBundle, + fileName: string, + usedModules: Module[], + chunkGraph: Record, + options: NormalizedOutputOptions, + outputPluginDriver: PluginDriver, + onwarn: WarningHandler +) { + let map: SourceMap | null = null; + const sourcemapChain: DecodedSourceMapOrMissing[] = []; + let code = await outputPluginDriver.hookReduceArg0( + 'renderChunk', + [magicString.toString(), chunkGraph[fileName], options, { chunks: chunkGraph }], + (code, result, plugin) => { + if (result == null) return code; + + if (typeof result === 'string') + result = { + code: result, + map: undefined + }; + + // strict null check allows 'null' maps to not be pushed to the chain, while 'undefined' gets the missing map warning + if (result.map !== null) { + const map = decodedSourcemap(result.map); + sourcemapChain.push(map || { missing: true, plugin: plugin.name }); + } + + return result.code; + } + ); + const { compact, sourcemap, sourcemapPathTransform } = options; + if (!compact && code[code.length - 1] !== '\n') code += '\n'; + + if (sourcemap) { + timeStart('sourcemap', 2); + + let file: string; + if (options.file) file = resolve(options.sourcemapFile || options.file); + else if (options.dir) file = resolve(options.dir, fileName); + else file = resolve(fileName); + + const decodedMap = magicString.generateDecodedMap({}); + map = collapseSourcemaps( + file, + decodedMap, + usedModules, + sourcemapChain, + options.sourcemapExcludeSources, + onwarn + ); + map.sources = map.sources + .map(sourcePath => { + if (sourcemapPathTransform) { + const newSourcePath = sourcemapPathTransform(sourcePath, `${file}.map`) as unknown; + + if (typeof newSourcePath !== 'string') { + error(errFailedValidation(`sourcemapPathTransform function must return a string.`)); + } + + return newSourcePath; + } + + return sourcePath; + }) + .map(normalize); + + timeEnd('sourcemap', 2); + } + return { + code, + map + }; +} + +async function transformChunksAndGenerateContentHashes( + renderedChunks: ChunkRenderResult[], + chunkGraph: Record, + outputOptions: NormalizedOutputOptions, + pluginDriver: PluginDriver, + onwarn: WarningHandler +) { + const nonHashedChunksWithPlaceholders: RenderedChunkWithPlaceholders[] = []; + const renderedChunksByPlaceholder = new Map(); + const hashDependenciesByPlaceholder = new Map(); + const placeholders = new Set(); + for (const { + preliminaryFileName: { hashPlaceholder } + } of renderedChunks) { + if (hashPlaceholder) placeholders.add(hashPlaceholder); + } + await Promise.all( + renderedChunks.map( + async ({ + chunk, + preliminaryFileName: { fileName, hashPlaceholder }, + magicString, + usedModules + }) => { + const transformedChunk = { + chunk, + fileName, + ...(await transformChunk( + magicString, + fileName, + usedModules, + chunkGraph, + outputOptions, + pluginDriver, + onwarn + )) + }; + const { code } = transformedChunk; + if (hashPlaceholder) { + const hash = createHash(); + // To create a reproducible content-only hash, all placeholders are + // replaced with the same value before hashing + const { containedPlaceholders, transformedCode } = + replacePlaceholdersWithDefaultAndGetContainedPlaceholders(code, placeholders); + hash.update(transformedCode); + const hashAugmentation = pluginDriver.hookReduceValueSync( + 'augmentChunkHash', + '', + [chunk.getRenderedChunkInfo()], + (augmentation, pluginHash) => { + if (pluginHash) { + augmentation += pluginHash; + } + return augmentation; + } + ); + if (hashAugmentation) { + hash.update(hashAugmentation); + } + renderedChunksByPlaceholder.set(hashPlaceholder, transformedChunk); + hashDependenciesByPlaceholder.set(hashPlaceholder, { + containedPlaceholders, + contentHash: hash.digest('hex') + }); + } else { + nonHashedChunksWithPlaceholders.push(transformedChunk); + } + } + ) + ); + return { + hashDependenciesByPlaceholder, + nonHashedChunksWithPlaceholders, + renderedChunksByPlaceholder + }; +} + +function generateFinalHashes( + renderedChunksByPlaceholder: Map, + hashDependenciesByPlaceholder: Map, + outputBundle: OutputBundleWithPlaceholders +) { + const hashesByPlaceholder = new Map(); + for (const [placeholder, { fileName }] of renderedChunksByPlaceholder) { + let hash = createHash(); + const hashDependencyPlaceholders = new Set([placeholder]); + for (const dependencyPlaceholder of hashDependencyPlaceholders) { + const { containedPlaceholders, contentHash } = + hashDependenciesByPlaceholder.get(dependencyPlaceholder)!; + hash.update(contentHash); + for (const containedPlaceholder of containedPlaceholders) { + // When looping over a map, setting an entry only causes a new iteration if the key is new + hashDependencyPlaceholders.add(containedPlaceholder); + } + } + let finalFileName: string | undefined; + let finalHash: string | undefined; + do { + // In case of a hash collision, create a hash of the hash + if (finalHash) { + hash = createHash(); + hash.update(finalHash); + } + finalHash = hash.digest('hex').slice(0, placeholder.length); + finalFileName = replaceSinglePlaceholder(fileName, placeholder, finalHash); + } while (outputBundle[finalFileName]); + outputBundle[finalFileName] = FILE_PLACEHOLDER; + hashesByPlaceholder.set(placeholder, finalHash.slice(0, placeholder.length)); + } + return hashesByPlaceholder; +} + +function addChunksToBundle( + renderedChunksByPlaceholder: Map, + hashesByPlaceholder: Map, + outputBundle: OutputBundleWithPlaceholders, + nonHashedChunksWithPlaceholders: RenderedChunkWithPlaceholders[] +) { + for (const { chunk, code, fileName, map } of renderedChunksByPlaceholder.values()) { + const updatedCode = replacePlaceholders(code, hashesByPlaceholder); + const finalFileName = replacePlaceholders(fileName, hashesByPlaceholder); + if (map) { + map.file = replacePlaceholders(map.file, hashesByPlaceholder); + } + outputBundle[finalFileName] = chunk.generateOutputChunk(updatedCode, map, hashesByPlaceholder); + } + for (const { chunk, code, fileName, map } of nonHashedChunksWithPlaceholders) { + const updatedCode = hashesByPlaceholder.size + ? replacePlaceholders(code, hashesByPlaceholder) + : code; + outputBundle[fileName] = chunk.generateOutputChunk(updatedCode, map, hashesByPlaceholder); + } +} diff --git a/src/utils/renderHelpers.ts b/src/utils/renderHelpers.ts index fb328ceb582..4226572ff7d 100644 --- a/src/utils/renderHelpers.ts +++ b/src/utils/renderHelpers.ts @@ -13,7 +13,7 @@ export interface RenderOptions { freeze: boolean; indent: string; namespaceToStringTag: boolean; - outputPluginDriver: PluginDriver; + pluginDriver: PluginDriver; snippets: GenerateCodeSnippets; } diff --git a/src/utils/renderNamePattern.ts b/src/utils/renderNamePattern.ts index 28f96cdba4a..ef15b820133 100644 --- a/src/utils/renderNamePattern.ts +++ b/src/utils/renderNamePattern.ts @@ -5,7 +5,7 @@ import { isPathFragment } from './relativeId'; export function renderNamePattern( pattern: string, patternName: string, - replacements: { [name: string]: () => string } + replacements: { [name: string]: (size?: number) => string } ): string { if (isPathFragment(pattern)) return error( @@ -13,21 +13,26 @@ export function renderNamePattern( `Invalid pattern "${pattern}" for "${patternName}", patterns can be neither absolute nor relative paths. If you want your files to be stored in a subdirectory, write its name without a leading slash like this: subdirectory/pattern.` ) ); - return pattern.replace(/\[(\w+)\]/g, (_match, type) => { - if (!replacements.hasOwnProperty(type)) { - return error( - errFailedValidation(`"[${type}]" is not a valid placeholder in "${patternName}" pattern.`) - ); + return pattern.replace( + /\[(\w+)(:\d+)?]/g, + (_match, type: string, size: `:${string}` | undefined) => { + if (!replacements.hasOwnProperty(type) || (size && type !== 'hash')) { + return error( + errFailedValidation( + `"[${type}${size || ''}]" is not a valid placeholder in the "${patternName}" pattern.` + ) + ); + } + const replacement = replacements[type](size && parseInt(size.slice(1))); + if (isPathFragment(replacement)) + return error( + errFailedValidation( + `Invalid substitution "${replacement}" for placeholder "[${type}]" in "${patternName}" pattern, can be neither absolute nor relative path.` + ) + ); + return replacement; } - const replacement = replacements[type](); - if (isPathFragment(replacement)) - return error( - errFailedValidation( - `Invalid substitution "${replacement}" for placeholder "[${type}]" in "${patternName}" pattern, can be neither absolute nor relative path.` - ) - ); - return replacement; - }); + ); } export function makeUnique(name: string, existingNames: Record): string { diff --git a/test/browser/samples/supports-hashes/_expected/dep-cf8755fa.js b/test/browser/samples/supports-hashes/_expected/dep-bd733981.js similarity index 100% rename from test/browser/samples/supports-hashes/_expected/dep-cf8755fa.js rename to test/browser/samples/supports-hashes/_expected/dep-bd733981.js diff --git a/test/browser/samples/supports-hashes/_expected/main-53604712.js b/test/browser/samples/supports-hashes/_expected/main-53604712.js deleted file mode 100644 index 347f7a59847..00000000000 --- a/test/browser/samples/supports-hashes/_expected/main-53604712.js +++ /dev/null @@ -1,3 +0,0 @@ -import { foo } from './dep-cf8755fa.js'; - -console.log(foo); diff --git a/test/browser/samples/supports-hashes/_expected/main-e4b393dd.js b/test/browser/samples/supports-hashes/_expected/main-e4b393dd.js new file mode 100644 index 00000000000..697a036fc36 --- /dev/null +++ b/test/browser/samples/supports-hashes/_expected/main-e4b393dd.js @@ -0,0 +1,3 @@ +import { foo } from './dep-bd733981.js'; + +console.log(foo); diff --git a/test/chunking-form/samples/emit-file/asset-file-names/_expected/amd/txt/7468331f-test.txt b/test/chunking-form/samples/emit-file/asset-file-names/_expected/amd/txt/b94d27b9-test.txt similarity index 100% rename from test/chunking-form/samples/emit-file/asset-file-names/_expected/amd/txt/7468331f-test.txt rename to test/chunking-form/samples/emit-file/asset-file-names/_expected/amd/txt/b94d27b9-test.txt diff --git a/test/chunking-form/samples/emit-file/asset-file-names/_expected/cjs/txt/7468331f-test.txt b/test/chunking-form/samples/emit-file/asset-file-names/_expected/cjs/txt/b94d27b9-test.txt similarity index 100% rename from test/chunking-form/samples/emit-file/asset-file-names/_expected/cjs/txt/7468331f-test.txt rename to test/chunking-form/samples/emit-file/asset-file-names/_expected/cjs/txt/b94d27b9-test.txt diff --git a/test/chunking-form/samples/emit-file/asset-file-names/_expected/es/txt/7468331f-test.txt b/test/chunking-form/samples/emit-file/asset-file-names/_expected/es/txt/b94d27b9-test.txt similarity index 100% rename from test/chunking-form/samples/emit-file/asset-file-names/_expected/es/txt/7468331f-test.txt rename to test/chunking-form/samples/emit-file/asset-file-names/_expected/es/txt/b94d27b9-test.txt diff --git a/test/chunking-form/samples/emit-file/asset-file-names/_expected/system/txt/7468331f-test.txt b/test/chunking-form/samples/emit-file/asset-file-names/_expected/system/txt/b94d27b9-test.txt similarity index 100% rename from test/chunking-form/samples/emit-file/asset-file-names/_expected/system/txt/7468331f-test.txt rename to test/chunking-form/samples/emit-file/asset-file-names/_expected/system/txt/b94d27b9-test.txt diff --git a/test/chunking-form/samples/emit-file/deduplicate-assets/_expected/amd/assets/buffer-5a245d77.txt b/test/chunking-form/samples/emit-file/deduplicate-assets/_expected/amd/assets/buffer-d0ca8c2a.txt similarity index 100% rename from test/chunking-form/samples/emit-file/deduplicate-assets/_expected/amd/assets/buffer-5a245d77.txt rename to test/chunking-form/samples/emit-file/deduplicate-assets/_expected/amd/assets/buffer-d0ca8c2a.txt diff --git a/test/chunking-form/samples/emit-file/deduplicate-assets/_expected/amd/assets/string-be268e3d.txt b/test/chunking-form/samples/emit-file/deduplicate-assets/_expected/amd/assets/string-b94d27b9.txt similarity index 100% rename from test/chunking-form/samples/emit-file/deduplicate-assets/_expected/amd/assets/string-be268e3d.txt rename to test/chunking-form/samples/emit-file/deduplicate-assets/_expected/amd/assets/string-b94d27b9.txt diff --git a/test/chunking-form/samples/emit-file/deduplicate-assets/_expected/cjs/assets/buffer-5a245d77.txt b/test/chunking-form/samples/emit-file/deduplicate-assets/_expected/cjs/assets/buffer-d0ca8c2a.txt similarity index 100% rename from test/chunking-form/samples/emit-file/deduplicate-assets/_expected/cjs/assets/buffer-5a245d77.txt rename to test/chunking-form/samples/emit-file/deduplicate-assets/_expected/cjs/assets/buffer-d0ca8c2a.txt diff --git a/test/chunking-form/samples/emit-file/deduplicate-assets/_expected/cjs/assets/string-be268e3d.txt b/test/chunking-form/samples/emit-file/deduplicate-assets/_expected/cjs/assets/string-b94d27b9.txt similarity index 100% rename from test/chunking-form/samples/emit-file/deduplicate-assets/_expected/cjs/assets/string-be268e3d.txt rename to test/chunking-form/samples/emit-file/deduplicate-assets/_expected/cjs/assets/string-b94d27b9.txt diff --git a/test/chunking-form/samples/emit-file/deduplicate-assets/_expected/es/assets/buffer-5a245d77.txt b/test/chunking-form/samples/emit-file/deduplicate-assets/_expected/es/assets/buffer-d0ca8c2a.txt similarity index 100% rename from test/chunking-form/samples/emit-file/deduplicate-assets/_expected/es/assets/buffer-5a245d77.txt rename to test/chunking-form/samples/emit-file/deduplicate-assets/_expected/es/assets/buffer-d0ca8c2a.txt diff --git a/test/chunking-form/samples/emit-file/deduplicate-assets/_expected/es/assets/string-be268e3d.txt b/test/chunking-form/samples/emit-file/deduplicate-assets/_expected/es/assets/string-b94d27b9.txt similarity index 100% rename from test/chunking-form/samples/emit-file/deduplicate-assets/_expected/es/assets/string-be268e3d.txt rename to test/chunking-form/samples/emit-file/deduplicate-assets/_expected/es/assets/string-b94d27b9.txt diff --git a/test/chunking-form/samples/emit-file/deduplicate-assets/_expected/system/assets/buffer-5a245d77.txt b/test/chunking-form/samples/emit-file/deduplicate-assets/_expected/system/assets/buffer-d0ca8c2a.txt similarity index 100% rename from test/chunking-form/samples/emit-file/deduplicate-assets/_expected/system/assets/buffer-5a245d77.txt rename to test/chunking-form/samples/emit-file/deduplicate-assets/_expected/system/assets/buffer-d0ca8c2a.txt diff --git a/test/chunking-form/samples/emit-file/deduplicate-assets/_expected/system/assets/string-be268e3d.txt b/test/chunking-form/samples/emit-file/deduplicate-assets/_expected/system/assets/string-b94d27b9.txt similarity index 100% rename from test/chunking-form/samples/emit-file/deduplicate-assets/_expected/system/assets/string-be268e3d.txt rename to test/chunking-form/samples/emit-file/deduplicate-assets/_expected/system/assets/string-b94d27b9.txt diff --git a/test/chunking-form/samples/emit-file/emit-asset-without-name/_expected/amd/assets/asset-417c0188 b/test/chunking-form/samples/emit-file/emit-asset-without-name/_expected/amd/assets/asset-b94d27b9 similarity index 100% rename from test/chunking-form/samples/emit-file/emit-asset-without-name/_expected/amd/assets/asset-417c0188 rename to test/chunking-form/samples/emit-file/emit-asset-without-name/_expected/amd/assets/asset-b94d27b9 diff --git a/test/chunking-form/samples/emit-file/emit-asset-without-name/_expected/cjs/assets/asset-417c0188 b/test/chunking-form/samples/emit-file/emit-asset-without-name/_expected/cjs/assets/asset-b94d27b9 similarity index 100% rename from test/chunking-form/samples/emit-file/emit-asset-without-name/_expected/cjs/assets/asset-417c0188 rename to test/chunking-form/samples/emit-file/emit-asset-without-name/_expected/cjs/assets/asset-b94d27b9 diff --git a/test/chunking-form/samples/emit-file/emit-asset-without-name/_expected/es/assets/asset-417c0188 b/test/chunking-form/samples/emit-file/emit-asset-without-name/_expected/es/assets/asset-b94d27b9 similarity index 100% rename from test/chunking-form/samples/emit-file/emit-asset-without-name/_expected/es/assets/asset-417c0188 rename to test/chunking-form/samples/emit-file/emit-asset-without-name/_expected/es/assets/asset-b94d27b9 diff --git a/test/chunking-form/samples/emit-file/emit-asset-without-name/_expected/system/assets/asset-417c0188 b/test/chunking-form/samples/emit-file/emit-asset-without-name/_expected/system/assets/asset-b94d27b9 similarity index 100% rename from test/chunking-form/samples/emit-file/emit-asset-without-name/_expected/system/assets/asset-417c0188 rename to test/chunking-form/samples/emit-file/emit-asset-without-name/_expected/system/assets/asset-b94d27b9 diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/banner-2b65cc0c.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/banner-8c7ed2d9.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/banner-2b65cc0c.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/banner-8c7ed2d9.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/buildEnd-4678f17a.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/buildEnd-6e08d992.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/buildEnd-4678f17a.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/buildEnd-6e08d992.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/buildStart-5b740828.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/buildStart-db9421f6.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/buildStart-5b740828.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/buildStart-db9421f6.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/footer-e1d2fccb.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/footer-0301844c.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/footer-e1d2fccb.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/footer-0301844c.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/generateBundle-22413744.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/generateBundle-5b9a4e56.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/generateBundle-22413744.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/generateBundle-5b9a4e56.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/intro-520a8116.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/intro-c432b372.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/intro-520a8116.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/intro-c432b372.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/load-a4cc2865.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/load-0cf67fc7.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/load-a4cc2865.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/load-0cf67fc7.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/outro-21f77720.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/outro-1e5fe046.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/outro-21f77720.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/outro-1e5fe046.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/renderChunk-a91c7c32.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/renderChunk-aa9e49b7.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/renderChunk-a91c7c32.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/renderChunk-aa9e49b7.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/renderStart-66600c78.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/renderStart-981aa2ea.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/renderStart-66600c78.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/renderStart-981aa2ea.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/resolveId-6d8063a5.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/resolveId-dd9bb7f8.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/resolveId-6d8063a5.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/resolveId-dd9bb7f8.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/transform-d49df25a.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/transform-aa214ea3.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/transform-d49df25a.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/amd/assets/transform-aa214ea3.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/banner-2b65cc0c.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/banner-8c7ed2d9.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/banner-2b65cc0c.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/banner-8c7ed2d9.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/buildEnd-4678f17a.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/buildEnd-6e08d992.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/buildEnd-4678f17a.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/buildEnd-6e08d992.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/buildStart-5b740828.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/buildStart-db9421f6.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/buildStart-5b740828.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/buildStart-db9421f6.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/footer-e1d2fccb.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/footer-0301844c.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/footer-e1d2fccb.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/footer-0301844c.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/generateBundle-22413744.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/generateBundle-5b9a4e56.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/generateBundle-22413744.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/generateBundle-5b9a4e56.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/intro-520a8116.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/intro-c432b372.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/intro-520a8116.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/intro-c432b372.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/load-a4cc2865.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/load-0cf67fc7.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/load-a4cc2865.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/load-0cf67fc7.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/outro-21f77720.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/outro-1e5fe046.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/outro-21f77720.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/outro-1e5fe046.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/renderChunk-a91c7c32.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/renderChunk-aa9e49b7.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/renderChunk-a91c7c32.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/renderChunk-aa9e49b7.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/renderStart-66600c78.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/renderStart-981aa2ea.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/renderStart-66600c78.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/renderStart-981aa2ea.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/resolveId-6d8063a5.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/resolveId-dd9bb7f8.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/resolveId-6d8063a5.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/resolveId-dd9bb7f8.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/transform-d49df25a.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/transform-aa214ea3.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/transform-d49df25a.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/cjs/assets/transform-aa214ea3.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/banner-2b65cc0c.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/banner-8c7ed2d9.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/banner-2b65cc0c.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/banner-8c7ed2d9.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/buildEnd-4678f17a.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/buildEnd-6e08d992.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/buildEnd-4678f17a.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/buildEnd-6e08d992.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/buildStart-5b740828.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/buildStart-db9421f6.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/buildStart-5b740828.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/buildStart-db9421f6.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/footer-e1d2fccb.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/footer-0301844c.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/footer-e1d2fccb.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/footer-0301844c.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/generateBundle-22413744.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/generateBundle-5b9a4e56.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/generateBundle-22413744.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/generateBundle-5b9a4e56.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/intro-520a8116.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/intro-c432b372.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/intro-520a8116.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/intro-c432b372.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/load-a4cc2865.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/load-0cf67fc7.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/load-a4cc2865.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/load-0cf67fc7.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/outro-21f77720.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/outro-1e5fe046.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/outro-21f77720.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/outro-1e5fe046.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/renderChunk-a91c7c32.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/renderChunk-aa9e49b7.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/renderChunk-a91c7c32.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/renderChunk-aa9e49b7.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/renderStart-66600c78.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/renderStart-981aa2ea.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/renderStart-66600c78.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/renderStart-981aa2ea.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/resolveId-6d8063a5.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/resolveId-dd9bb7f8.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/resolveId-6d8063a5.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/resolveId-dd9bb7f8.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/transform-d49df25a.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/transform-aa214ea3.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/transform-d49df25a.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/es/assets/transform-aa214ea3.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/banner-2b65cc0c.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/banner-8c7ed2d9.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/banner-2b65cc0c.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/banner-8c7ed2d9.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/buildEnd-4678f17a.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/buildEnd-6e08d992.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/buildEnd-4678f17a.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/buildEnd-6e08d992.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/buildStart-5b740828.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/buildStart-db9421f6.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/buildStart-5b740828.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/buildStart-db9421f6.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/footer-e1d2fccb.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/footer-0301844c.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/footer-e1d2fccb.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/footer-0301844c.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/generateBundle-22413744.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/generateBundle-5b9a4e56.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/generateBundle-22413744.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/generateBundle-5b9a4e56.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/intro-520a8116.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/intro-c432b372.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/intro-520a8116.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/intro-c432b372.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/load-a4cc2865.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/load-0cf67fc7.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/load-a4cc2865.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/load-0cf67fc7.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/outro-21f77720.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/outro-1e5fe046.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/outro-21f77720.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/outro-1e5fe046.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/renderChunk-a91c7c32.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/renderChunk-aa9e49b7.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/renderChunk-a91c7c32.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/renderChunk-aa9e49b7.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/renderStart-66600c78.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/renderStart-981aa2ea.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/renderStart-66600c78.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/renderStart-981aa2ea.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/resolveId-6d8063a5.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/resolveId-dd9bb7f8.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/resolveId-6d8063a5.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/resolveId-dd9bb7f8.txt diff --git a/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/transform-d49df25a.txt b/test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/transform-aa214ea3.txt similarity index 100% rename from test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/transform-d49df25a.txt rename to test/chunking-form/samples/emit-file/emits-files-from-various-hooks/_expected/system/assets/transform-aa214ea3.txt diff --git a/test/chunking-form/samples/emit-file/filenames-function-patterns-preserve-modules/_config.js b/test/chunking-form/samples/emit-file/filenames-function-patterns-preserve-modules/_config.js index b4eb014757f..3e9eda6fc2e 100644 --- a/test/chunking-form/samples/emit-file/filenames-function-patterns-preserve-modules/_config.js +++ b/test/chunking-form/samples/emit-file/filenames-function-patterns-preserve-modules/_config.js @@ -18,26 +18,37 @@ module.exports = { output: { preserveModules: true, entryFileNames: fileInfo => { - const isMain = fileInfo.facadeModuleId === ID_MAIN; - - // This is checked separately as deepStrictEqual is having some issues - assert.deepStrictEqual(Object.keys(fileInfo.modules), [isMain ? ID_MAIN : ID_DEB]); - - delete fileInfo.modules; - assert.deepStrictEqual( - fileInfo, - { - exports: isMain ? [] : ['default'], - facadeModuleId: isMain ? ID_MAIN : ID_DEB, - isDynamicEntry: !isMain, - isEntry: isMain, - isImplicitEntry: false, - name: isMain ? 'main' : 'deb', - type: 'chunk' - }, - 'entry info' - ); - + if (fileInfo.facadeModuleId === ID_MAIN) { + assert.deepStrictEqual( + fileInfo, + { + exports: [], + facadeModuleId: ID_MAIN, + isDynamicEntry: false, + isEntry: true, + isImplicitEntry: false, + moduleIds: [ID_MAIN], + name: 'main', + type: 'chunk' + }, + 'entry info' + ); + } else { + assert.deepStrictEqual( + fileInfo, + { + exports: ['default'], + facadeModuleId: ID_DEB, + isDynamicEntry: true, + isEntry: false, + isImplicitEntry: false, + moduleIds: [ID_DEB], + name: 'deb', + type: 'chunk' + }, + 'entry info' + ); + } return `entry-[name]-[format].js`; } } diff --git a/test/chunking-form/samples/emit-file/filenames-function-patterns-preserve-modules/_expected/amd/assets/test-7468331f.txt b/test/chunking-form/samples/emit-file/filenames-function-patterns-preserve-modules/_expected/amd/assets/test-b94d27b9.txt similarity index 100% rename from test/chunking-form/samples/emit-file/filenames-function-patterns-preserve-modules/_expected/amd/assets/test-7468331f.txt rename to test/chunking-form/samples/emit-file/filenames-function-patterns-preserve-modules/_expected/amd/assets/test-b94d27b9.txt diff --git a/test/chunking-form/samples/emit-file/filenames-function-patterns-preserve-modules/_expected/cjs/assets/test-7468331f.txt b/test/chunking-form/samples/emit-file/filenames-function-patterns-preserve-modules/_expected/cjs/assets/test-b94d27b9.txt similarity index 100% rename from test/chunking-form/samples/emit-file/filenames-function-patterns-preserve-modules/_expected/cjs/assets/test-7468331f.txt rename to test/chunking-form/samples/emit-file/filenames-function-patterns-preserve-modules/_expected/cjs/assets/test-b94d27b9.txt diff --git a/test/chunking-form/samples/emit-file/filenames-function-patterns-preserve-modules/_expected/es/assets/test-7468331f.txt b/test/chunking-form/samples/emit-file/filenames-function-patterns-preserve-modules/_expected/es/assets/test-b94d27b9.txt similarity index 100% rename from test/chunking-form/samples/emit-file/filenames-function-patterns-preserve-modules/_expected/es/assets/test-7468331f.txt rename to test/chunking-form/samples/emit-file/filenames-function-patterns-preserve-modules/_expected/es/assets/test-b94d27b9.txt diff --git a/test/chunking-form/samples/emit-file/filenames-function-patterns-preserve-modules/_expected/system/assets/test-7468331f.txt b/test/chunking-form/samples/emit-file/filenames-function-patterns-preserve-modules/_expected/system/assets/test-b94d27b9.txt similarity index 100% rename from test/chunking-form/samples/emit-file/filenames-function-patterns-preserve-modules/_expected/system/assets/test-7468331f.txt rename to test/chunking-form/samples/emit-file/filenames-function-patterns-preserve-modules/_expected/system/assets/test-b94d27b9.txt diff --git a/test/chunking-form/samples/emit-file/filenames-function-patterns/_config.js b/test/chunking-form/samples/emit-file/filenames-function-patterns/_config.js index 5fed7481d5a..5f6bc8f24f8 100644 --- a/test/chunking-form/samples/emit-file/filenames-function-patterns/_config.js +++ b/test/chunking-form/samples/emit-file/filenames-function-patterns/_config.js @@ -16,9 +16,6 @@ module.exports = { }, output: { entryFileNames: fileInfo => { - // This is checked separately as deepStrictEqual is having some issues - assert.deepStrictEqual(Object.keys(fileInfo.modules), [ID_MAIN]); - delete fileInfo.modules; assert.deepStrictEqual( fileInfo, { @@ -28,6 +25,7 @@ module.exports = { isEntry: true, isImplicitEntry: false, name: 'main', + moduleIds: [ID_MAIN], type: 'chunk' }, 'entry info' @@ -47,9 +45,6 @@ module.exports = { return '[ext]/[hash]-[name][extname]'; }, chunkFileNames: fileInfo => { - // This is checked separately as deepStrictEqual is having some issues - assert.deepStrictEqual(Object.keys(fileInfo.modules), [ID_DEB]); - delete fileInfo.modules; assert.deepStrictEqual( fileInfo, { @@ -58,6 +53,7 @@ module.exports = { isDynamicEntry: true, isEntry: false, isImplicitEntry: false, + moduleIds: [ID_DEB], name: 'deb', type: 'chunk' }, diff --git a/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/amd/chunk-deb-c542d45b-amd.js b/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/amd/chunk-deb-faae56f2-amd.js similarity index 100% rename from test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/amd/chunk-deb-c542d45b-amd.js rename to test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/amd/chunk-deb-faae56f2-amd.js diff --git a/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/amd/entry-main-57ef342e-amd.js b/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/amd/entry-main-aaf15a0c-amd.js similarity index 72% rename from test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/amd/entry-main-57ef342e-amd.js rename to test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/amd/entry-main-aaf15a0c-amd.js index d0e99fe0907..1cbd0bc0e0c 100644 --- a/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/amd/entry-main-57ef342e-amd.js +++ b/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/amd/entry-main-aaf15a0c-amd.js @@ -1,6 +1,6 @@ define(['require'], (function (require) { 'use strict'; console.log('main'); - new Promise(function (resolve, reject) { require(['./chunk-deb-c542d45b-amd'], resolve, reject); }).then(console.log); + new Promise(function (resolve, reject) { require(['./chunk-deb-faae56f2-amd'], resolve, reject); }).then(console.log); })); diff --git a/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/amd/txt/7468331f-test.txt b/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/amd/txt/b94d27b9-test.txt similarity index 100% rename from test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/amd/txt/7468331f-test.txt rename to test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/amd/txt/b94d27b9-test.txt diff --git a/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/cjs/chunk-deb-19c947c3-cjs.js b/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/cjs/chunk-deb-2221fa83-cjs.js similarity index 100% rename from test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/cjs/chunk-deb-19c947c3-cjs.js rename to test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/cjs/chunk-deb-2221fa83-cjs.js diff --git a/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/cjs/entry-main-9f49db65-cjs.js b/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/cjs/entry-main-69b6552e-cjs.js similarity index 70% rename from test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/cjs/entry-main-9f49db65-cjs.js rename to test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/cjs/entry-main-69b6552e-cjs.js index 6363af0ae9e..82cd87dad4d 100644 --- a/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/cjs/entry-main-9f49db65-cjs.js +++ b/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/cjs/entry-main-69b6552e-cjs.js @@ -1,4 +1,4 @@ 'use strict'; console.log('main'); -Promise.resolve().then(function () { return require('./chunk-deb-19c947c3-cjs.js'); }).then(console.log); +Promise.resolve().then(function () { return require('./chunk-deb-2221fa83-cjs.js'); }).then(console.log); diff --git a/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/cjs/txt/7468331f-test.txt b/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/cjs/txt/b94d27b9-test.txt similarity index 100% rename from test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/cjs/txt/7468331f-test.txt rename to test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/cjs/txt/b94d27b9-test.txt diff --git a/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/es/chunk-deb-607fe03f-es.js b/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/es/chunk-deb-9f85baf7-es.js similarity index 100% rename from test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/es/chunk-deb-607fe03f-es.js rename to test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/es/chunk-deb-9f85baf7-es.js diff --git a/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/es/entry-main-137667a0-es.js b/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/es/entry-main-137667a0-es.js deleted file mode 100644 index 0896042fc2c..00000000000 --- a/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/es/entry-main-137667a0-es.js +++ /dev/null @@ -1,2 +0,0 @@ -console.log('main'); -import('./chunk-deb-607fe03f-es.js').then(console.log); diff --git a/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/es/entry-main-8d825d29-es.js b/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/es/entry-main-8d825d29-es.js new file mode 100644 index 00000000000..0e182cf5882 --- /dev/null +++ b/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/es/entry-main-8d825d29-es.js @@ -0,0 +1,2 @@ +console.log('main'); +import('./chunk-deb-9f85baf7-es.js').then(console.log); diff --git a/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/es/txt/7468331f-test.txt b/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/es/txt/b94d27b9-test.txt similarity index 100% rename from test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/es/txt/7468331f-test.txt rename to test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/es/txt/b94d27b9-test.txt diff --git a/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/system/chunk-deb-3a28869f-system.js b/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/system/chunk-deb-467d682b-system.js similarity index 100% rename from test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/system/chunk-deb-3a28869f-system.js rename to test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/system/chunk-deb-467d682b-system.js diff --git a/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/system/entry-main-e573b571-system.js b/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/system/entry-main-12044e01-system.js similarity index 69% rename from test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/system/entry-main-e573b571-system.js rename to test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/system/entry-main-12044e01-system.js index f2ecd449803..eadb26d8829 100644 --- a/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/system/entry-main-e573b571-system.js +++ b/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/system/entry-main-12044e01-system.js @@ -4,7 +4,7 @@ System.register([], (function (exports, module) { execute: (function () { console.log('main'); - module.import('./chunk-deb-3a28869f-system.js').then(console.log); + module.import('./chunk-deb-467d682b-system.js').then(console.log); }) }; diff --git a/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/system/txt/7468331f-test.txt b/test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/system/txt/b94d27b9-test.txt similarity index 100% rename from test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/system/txt/7468331f-test.txt rename to test/chunking-form/samples/emit-file/filenames-function-patterns/_expected/system/txt/b94d27b9-test.txt diff --git a/test/chunking-form/samples/emit-file/reference-files/_expected/amd/assets/logo1-a5ec488b.svg b/test/chunking-form/samples/emit-file/reference-files/_expected/amd/assets/logo1-60bc15c4.svg similarity index 100% rename from test/chunking-form/samples/emit-file/reference-files/_expected/amd/assets/logo1-a5ec488b.svg rename to test/chunking-form/samples/emit-file/reference-files/_expected/amd/assets/logo1-60bc15c4.svg diff --git a/test/chunking-form/samples/emit-file/reference-files/_expected/amd/assets/logo2-6d5979e4.svg b/test/chunking-form/samples/emit-file/reference-files/_expected/amd/assets/logo2-fdaa7478.svg similarity index 100% rename from test/chunking-form/samples/emit-file/reference-files/_expected/amd/assets/logo2-6d5979e4.svg rename to test/chunking-form/samples/emit-file/reference-files/_expected/amd/assets/logo2-fdaa7478.svg diff --git a/test/chunking-form/samples/emit-file/reference-files/_expected/amd/main.js b/test/chunking-form/samples/emit-file/reference-files/_expected/amd/main.js index 1dd5b4aaaa7..91b63f05a04 100644 --- a/test/chunking-form/samples/emit-file/reference-files/_expected/amd/main.js +++ b/test/chunking-form/samples/emit-file/reference-files/_expected/amd/main.js @@ -1,6 +1,6 @@ define(['require', 'exports'], (function (require, exports) { 'use strict'; - var logo = new URL(require.toUrl('./assets/logo1-a5ec488b.svg'), document.baseURI).href; + var logo = new URL(require.toUrl('./assets/logo1-60bc15c4.svg'), document.baseURI).href; function showImage(url) { console.log(url); diff --git a/test/chunking-form/samples/emit-file/reference-files/_expected/amd/nested/chunk.js b/test/chunking-form/samples/emit-file/reference-files/_expected/amd/nested/chunk.js index 6a888ad7ed2..dcde8981162 100644 --- a/test/chunking-form/samples/emit-file/reference-files/_expected/amd/nested/chunk.js +++ b/test/chunking-form/samples/emit-file/reference-files/_expected/amd/nested/chunk.js @@ -1,6 +1,6 @@ define(['require', '../main'], (function (require, main) { 'use strict'; - var logo = new URL(require.toUrl('../assets/logo2-6d5979e4.svg'), document.baseURI).href; + var logo = new URL(require.toUrl('../assets/logo2-fdaa7478.svg'), document.baseURI).href; main.showImage(logo); diff --git a/test/chunking-form/samples/emit-file/reference-files/_expected/cjs/assets/logo1-a5ec488b.svg b/test/chunking-form/samples/emit-file/reference-files/_expected/cjs/assets/logo1-60bc15c4.svg similarity index 100% rename from test/chunking-form/samples/emit-file/reference-files/_expected/cjs/assets/logo1-a5ec488b.svg rename to test/chunking-form/samples/emit-file/reference-files/_expected/cjs/assets/logo1-60bc15c4.svg diff --git a/test/chunking-form/samples/emit-file/reference-files/_expected/cjs/assets/logo2-6d5979e4.svg b/test/chunking-form/samples/emit-file/reference-files/_expected/cjs/assets/logo2-fdaa7478.svg similarity index 100% rename from test/chunking-form/samples/emit-file/reference-files/_expected/cjs/assets/logo2-6d5979e4.svg rename to test/chunking-form/samples/emit-file/reference-files/_expected/cjs/assets/logo2-fdaa7478.svg diff --git a/test/chunking-form/samples/emit-file/reference-files/_expected/cjs/main.js b/test/chunking-form/samples/emit-file/reference-files/_expected/cjs/main.js index 5c22a31491d..8b80ca97386 100644 --- a/test/chunking-form/samples/emit-file/reference-files/_expected/cjs/main.js +++ b/test/chunking-form/samples/emit-file/reference-files/_expected/cjs/main.js @@ -2,7 +2,7 @@ Object.defineProperty(exports, '__esModule', { value: true }); -var logo = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/logo1-a5ec488b.svg').href : new URL('assets/logo1-a5ec488b.svg', document.currentScript && document.currentScript.src || document.baseURI).href); +var logo = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/logo1-60bc15c4.svg').href : new URL('assets/logo1-60bc15c4.svg', document.currentScript && document.currentScript.src || document.baseURI).href); function showImage(url) { console.log(url); diff --git a/test/chunking-form/samples/emit-file/reference-files/_expected/cjs/nested/chunk.js b/test/chunking-form/samples/emit-file/reference-files/_expected/cjs/nested/chunk.js index 8d9f9558b6d..9b7c6f1cf8b 100644 --- a/test/chunking-form/samples/emit-file/reference-files/_expected/cjs/nested/chunk.js +++ b/test/chunking-form/samples/emit-file/reference-files/_expected/cjs/nested/chunk.js @@ -2,6 +2,6 @@ var main = require('../main.js'); -var logo = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/../assets/logo2-6d5979e4.svg').href : new URL('../assets/logo2-6d5979e4.svg', document.currentScript && document.currentScript.src || document.baseURI).href); +var logo = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/../assets/logo2-fdaa7478.svg').href : new URL('../assets/logo2-fdaa7478.svg', document.currentScript && document.currentScript.src || document.baseURI).href); main.showImage(logo); diff --git a/test/chunking-form/samples/emit-file/reference-files/_expected/es/assets/logo1-a5ec488b.svg b/test/chunking-form/samples/emit-file/reference-files/_expected/es/assets/logo1-60bc15c4.svg similarity index 100% rename from test/chunking-form/samples/emit-file/reference-files/_expected/es/assets/logo1-a5ec488b.svg rename to test/chunking-form/samples/emit-file/reference-files/_expected/es/assets/logo1-60bc15c4.svg diff --git a/test/chunking-form/samples/emit-file/reference-files/_expected/es/assets/logo2-6d5979e4.svg b/test/chunking-form/samples/emit-file/reference-files/_expected/es/assets/logo2-fdaa7478.svg similarity index 100% rename from test/chunking-form/samples/emit-file/reference-files/_expected/es/assets/logo2-6d5979e4.svg rename to test/chunking-form/samples/emit-file/reference-files/_expected/es/assets/logo2-fdaa7478.svg diff --git a/test/chunking-form/samples/emit-file/reference-files/_expected/es/main.js b/test/chunking-form/samples/emit-file/reference-files/_expected/es/main.js index 4d8fd5dd758..043250d9d13 100644 --- a/test/chunking-form/samples/emit-file/reference-files/_expected/es/main.js +++ b/test/chunking-form/samples/emit-file/reference-files/_expected/es/main.js @@ -1,4 +1,4 @@ -var logo = new URL('assets/logo1-a5ec488b.svg', import.meta.url).href; +var logo = new URL('assets/logo1-60bc15c4.svg', import.meta.url).href; function showImage(url) { console.log(url); diff --git a/test/chunking-form/samples/emit-file/reference-files/_expected/es/nested/chunk.js b/test/chunking-form/samples/emit-file/reference-files/_expected/es/nested/chunk.js index 4491f94fb7e..e8eb7621b9d 100644 --- a/test/chunking-form/samples/emit-file/reference-files/_expected/es/nested/chunk.js +++ b/test/chunking-form/samples/emit-file/reference-files/_expected/es/nested/chunk.js @@ -1,5 +1,5 @@ import { s as showImage } from '../main.js'; -var logo = new URL('../assets/logo2-6d5979e4.svg', import.meta.url).href; +var logo = new URL('../assets/logo2-fdaa7478.svg', import.meta.url).href; showImage(logo); diff --git a/test/chunking-form/samples/emit-file/reference-files/_expected/system/assets/logo1-a5ec488b.svg b/test/chunking-form/samples/emit-file/reference-files/_expected/system/assets/logo1-60bc15c4.svg similarity index 100% rename from test/chunking-form/samples/emit-file/reference-files/_expected/system/assets/logo1-a5ec488b.svg rename to test/chunking-form/samples/emit-file/reference-files/_expected/system/assets/logo1-60bc15c4.svg diff --git a/test/chunking-form/samples/emit-file/reference-files/_expected/system/assets/logo2-6d5979e4.svg b/test/chunking-form/samples/emit-file/reference-files/_expected/system/assets/logo2-fdaa7478.svg similarity index 100% rename from test/chunking-form/samples/emit-file/reference-files/_expected/system/assets/logo2-6d5979e4.svg rename to test/chunking-form/samples/emit-file/reference-files/_expected/system/assets/logo2-fdaa7478.svg diff --git a/test/chunking-form/samples/emit-file/reference-files/_expected/system/main.js b/test/chunking-form/samples/emit-file/reference-files/_expected/system/main.js index 01ef84effb6..aeaba1fc68d 100644 --- a/test/chunking-form/samples/emit-file/reference-files/_expected/system/main.js +++ b/test/chunking-form/samples/emit-file/reference-files/_expected/system/main.js @@ -5,7 +5,7 @@ System.register([], (function (exports, module) { exports('s', showImage); - var logo = new URL('assets/logo1-a5ec488b.svg', module.meta.url).href; + var logo = new URL('assets/logo1-60bc15c4.svg', module.meta.url).href; function showImage(url) { console.log(url); diff --git a/test/chunking-form/samples/emit-file/reference-files/_expected/system/nested/chunk.js b/test/chunking-form/samples/emit-file/reference-files/_expected/system/nested/chunk.js index f678780b7ba..3be6d43938d 100644 --- a/test/chunking-form/samples/emit-file/reference-files/_expected/system/nested/chunk.js +++ b/test/chunking-form/samples/emit-file/reference-files/_expected/system/nested/chunk.js @@ -7,7 +7,7 @@ System.register(['../main.js'], (function (exports, module) { }], execute: (function () { - var logo = new URL('../assets/logo2-6d5979e4.svg', module.meta.url).href; + var logo = new URL('../assets/logo2-fdaa7478.svg', module.meta.url).href; showImage(logo); diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_config.js b/test/chunking-form/samples/emit-file/set-asset-source/_config.js index c70db0ddc39..067a3de14bb 100644 --- a/test/chunking-form/samples/emit-file/set-asset-source/_config.js +++ b/test/chunking-form/samples/emit-file/set-asset-source/_config.js @@ -37,14 +37,12 @@ module.exports = { `export const renderStart = import.meta.ROLLUP_FILE_URL_${renderStart};\n` + `export const renderStartNamed = import.meta.ROLLUP_FILE_URL_${renderStartNamed};\n` + `export const renderStartNamedImmediately = '${this.getFileName(renderStartNamed)}';\n` + - `export const banner = import.meta.ROLLUP_FILE_URL_${banner};\n` + `export const bannerNamed = import.meta.ROLLUP_FILE_URL_${bannerNamed};\n` + - `export const footer = import.meta.ROLLUP_FILE_URL_${footer};\n` + `export const footerNamed = import.meta.ROLLUP_FILE_URL_${footerNamed};\n` + - `export const intro = import.meta.ROLLUP_FILE_URL_${intro};\n` + `export const introNamed = import.meta.ROLLUP_FILE_URL_${introNamed};\n` + - `export const outro = import.meta.ROLLUP_FILE_URL_${outro};\n` + - `export const outroNamed = import.meta.ROLLUP_FILE_URL_${outroNamed};\n` + `export const outroNamed = import.meta.ROLLUP_FILE_URL_${outroNamed};\n` + + `export const renderChunkNamed = import.meta.ROLLUP_FILE_URL_${renderChunkNamed};\n` + + `export const generateBundleNamed = import.meta.ROLLUP_FILE_URL_${generateBundleNamed};\n` ); }, renderStart() { diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/assets/banner-2b65cc0c.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/assets/banner-8c7ed2d9.txt similarity index 100% rename from test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/assets/banner-2b65cc0c.txt rename to test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/assets/banner-8c7ed2d9.txt diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/assets/footer-e1d2fccb.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/assets/footer-0301844c.txt similarity index 100% rename from test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/assets/footer-e1d2fccb.txt rename to test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/assets/footer-0301844c.txt diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/assets/generateBundle-6922b0a1.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/assets/generateBundle-6922b0a1.txt new file mode 100644 index 00000000000..b00dcf27801 --- /dev/null +++ b/test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/assets/generateBundle-6922b0a1.txt @@ -0,0 +1 @@ +generateBundle amd with assets/generateBundle-format-240389f4.txt \ No newline at end of file diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/assets/generateBundle-ea61028d.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/assets/generateBundle-ea61028d.txt deleted file mode 100644 index a11bda7ebad..00000000000 --- a/test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/assets/generateBundle-ea61028d.txt +++ /dev/null @@ -1 +0,0 @@ -generateBundle amd with assets/generateBundle-format-78d67aa8.txt \ No newline at end of file diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/assets/generateBundle-format-78d67aa8.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/assets/generateBundle-format-240389f4.txt similarity index 100% rename from test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/assets/generateBundle-format-78d67aa8.txt rename to test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/assets/generateBundle-format-240389f4.txt diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/assets/intro-520a8116.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/assets/intro-c432b372.txt similarity index 100% rename from test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/assets/intro-520a8116.txt rename to test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/assets/intro-c432b372.txt diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/assets/outro-21f77720.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/assets/outro-1e5fe046.txt similarity index 100% rename from test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/assets/outro-21f77720.txt rename to test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/assets/outro-1e5fe046.txt diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/assets/renderChunk-a91c7c32.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/assets/renderChunk-aa9e49b7.txt similarity index 100% rename from test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/assets/renderChunk-a91c7c32.txt rename to test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/assets/renderChunk-aa9e49b7.txt diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/assets/renderStart-66600c78.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/assets/renderStart-981aa2ea.txt similarity index 100% rename from test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/assets/renderStart-66600c78.txt rename to test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/assets/renderStart-981aa2ea.txt diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/generateBundle.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/generateBundle.txt index a11bda7ebad..b00dcf27801 100644 --- a/test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/generateBundle.txt +++ b/test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/generateBundle.txt @@ -1 +1 @@ -generateBundle amd with assets/generateBundle-format-78d67aa8.txt \ No newline at end of file +generateBundle amd with assets/generateBundle-format-240389f4.txt \ No newline at end of file diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/main.js b/test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/main.js index 7a630a87c8f..431afc714b9 100644 --- a/test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/main.js +++ b/test/chunking-form/samples/emit-file/set-asset-source/_expected/amd/main.js @@ -1,25 +1,21 @@ define(['require', 'exports'], (function (require, exports) { 'use strict'; - const renderStart = new URL(require.toUrl('./assets/renderStart-66600c78.txt'), document.baseURI).href; + const renderStart = new URL(require.toUrl('./assets/renderStart-981aa2ea.txt'), document.baseURI).href; const renderStartNamed = new URL(require.toUrl('./renderStart.txt'), document.baseURI).href; const renderStartNamedImmediately = 'renderStart.txt'; - const banner = new URL(require.toUrl('./assets/banner-2b65cc0c.txt'), document.baseURI).href; const bannerNamed = new URL(require.toUrl('./banner.txt'), document.baseURI).href; - const footer = new URL(require.toUrl('./assets/footer-e1d2fccb.txt'), document.baseURI).href; const footerNamed = new URL(require.toUrl('./footer.txt'), document.baseURI).href; - const intro = new URL(require.toUrl('./assets/intro-520a8116.txt'), document.baseURI).href; const introNamed = new URL(require.toUrl('./intro.txt'), document.baseURI).href; - const outro = new URL(require.toUrl('./assets/outro-21f77720.txt'), document.baseURI).href; const outroNamed = new URL(require.toUrl('./outro.txt'), document.baseURI).href; + const renderChunkNamed = new URL(require.toUrl('./renderChunk.txt'), document.baseURI).href; + const generateBundleNamed = new URL(require.toUrl('./generateBundle.txt'), document.baseURI).href; - exports.banner = banner; exports.bannerNamed = bannerNamed; - exports.footer = footer; exports.footerNamed = footerNamed; - exports.intro = intro; + exports.generateBundleNamed = generateBundleNamed; exports.introNamed = introNamed; - exports.outro = outro; exports.outroNamed = outroNamed; + exports.renderChunkNamed = renderChunkNamed; exports.renderStart = renderStart; exports.renderStartNamed = renderStartNamed; exports.renderStartNamedImmediately = renderStartNamedImmediately; diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/assets/banner-2b65cc0c.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/assets/banner-8c7ed2d9.txt similarity index 100% rename from test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/assets/banner-2b65cc0c.txt rename to test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/assets/banner-8c7ed2d9.txt diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/assets/footer-e1d2fccb.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/assets/footer-0301844c.txt similarity index 100% rename from test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/assets/footer-e1d2fccb.txt rename to test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/assets/footer-0301844c.txt diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/assets/generateBundle-7ba089df.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/assets/generateBundle-7ba089df.txt deleted file mode 100644 index 3f6be650ed5..00000000000 --- a/test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/assets/generateBundle-7ba089df.txt +++ /dev/null @@ -1 +0,0 @@ -generateBundle cjs with assets/generateBundle-format-ef46b0c8.txt \ No newline at end of file diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/assets/generateBundle-b1a5f14c.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/assets/generateBundle-b1a5f14c.txt new file mode 100644 index 00000000000..21e7f9971dd --- /dev/null +++ b/test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/assets/generateBundle-b1a5f14c.txt @@ -0,0 +1 @@ +generateBundle cjs with assets/generateBundle-format-4efb05bc.txt \ No newline at end of file diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/assets/generateBundle-format-ef46b0c8.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/assets/generateBundle-format-4efb05bc.txt similarity index 100% rename from test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/assets/generateBundle-format-ef46b0c8.txt rename to test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/assets/generateBundle-format-4efb05bc.txt diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/assets/intro-520a8116.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/assets/intro-c432b372.txt similarity index 100% rename from test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/assets/intro-520a8116.txt rename to test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/assets/intro-c432b372.txt diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/assets/outro-21f77720.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/assets/outro-1e5fe046.txt similarity index 100% rename from test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/assets/outro-21f77720.txt rename to test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/assets/outro-1e5fe046.txt diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/assets/renderChunk-a91c7c32.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/assets/renderChunk-aa9e49b7.txt similarity index 100% rename from test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/assets/renderChunk-a91c7c32.txt rename to test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/assets/renderChunk-aa9e49b7.txt diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/assets/renderStart-66600c78.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/assets/renderStart-981aa2ea.txt similarity index 100% rename from test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/assets/renderStart-66600c78.txt rename to test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/assets/renderStart-981aa2ea.txt diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/generateBundle.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/generateBundle.txt index 3f6be650ed5..21e7f9971dd 100644 --- a/test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/generateBundle.txt +++ b/test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/generateBundle.txt @@ -1 +1 @@ -generateBundle cjs with assets/generateBundle-format-ef46b0c8.txt \ No newline at end of file +generateBundle cjs with assets/generateBundle-format-4efb05bc.txt \ No newline at end of file diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/main.js b/test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/main.js index 51058623000..bd63ea33c1f 100644 --- a/test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/main.js +++ b/test/chunking-form/samples/emit-file/set-asset-source/_expected/cjs/main.js @@ -2,26 +2,22 @@ Object.defineProperty(exports, '__esModule', { value: true }); -const renderStart = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/renderStart-66600c78.txt').href : new URL('assets/renderStart-66600c78.txt', document.currentScript && document.currentScript.src || document.baseURI).href); +const renderStart = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/renderStart-981aa2ea.txt').href : new URL('assets/renderStart-981aa2ea.txt', document.currentScript && document.currentScript.src || document.baseURI).href); const renderStartNamed = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/renderStart.txt').href : new URL('renderStart.txt', document.currentScript && document.currentScript.src || document.baseURI).href); const renderStartNamedImmediately = 'renderStart.txt'; -const banner = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/banner-2b65cc0c.txt').href : new URL('assets/banner-2b65cc0c.txt', document.currentScript && document.currentScript.src || document.baseURI).href); const bannerNamed = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/banner.txt').href : new URL('banner.txt', document.currentScript && document.currentScript.src || document.baseURI).href); -const footer = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/footer-e1d2fccb.txt').href : new URL('assets/footer-e1d2fccb.txt', document.currentScript && document.currentScript.src || document.baseURI).href); const footerNamed = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/footer.txt').href : new URL('footer.txt', document.currentScript && document.currentScript.src || document.baseURI).href); -const intro = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/intro-520a8116.txt').href : new URL('assets/intro-520a8116.txt', document.currentScript && document.currentScript.src || document.baseURI).href); const introNamed = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/intro.txt').href : new URL('intro.txt', document.currentScript && document.currentScript.src || document.baseURI).href); -const outro = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/outro-21f77720.txt').href : new URL('assets/outro-21f77720.txt', document.currentScript && document.currentScript.src || document.baseURI).href); const outroNamed = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/outro.txt').href : new URL('outro.txt', document.currentScript && document.currentScript.src || document.baseURI).href); +const renderChunkNamed = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/renderChunk.txt').href : new URL('renderChunk.txt', document.currentScript && document.currentScript.src || document.baseURI).href); +const generateBundleNamed = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/generateBundle.txt').href : new URL('generateBundle.txt', document.currentScript && document.currentScript.src || document.baseURI).href); -exports.banner = banner; exports.bannerNamed = bannerNamed; -exports.footer = footer; exports.footerNamed = footerNamed; -exports.intro = intro; +exports.generateBundleNamed = generateBundleNamed; exports.introNamed = introNamed; -exports.outro = outro; exports.outroNamed = outroNamed; +exports.renderChunkNamed = renderChunkNamed; exports.renderStart = renderStart; exports.renderStartNamed = renderStartNamed; exports.renderStartNamedImmediately = renderStartNamedImmediately; diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/es/assets/banner-2b65cc0c.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/es/assets/banner-8c7ed2d9.txt similarity index 100% rename from test/chunking-form/samples/emit-file/set-asset-source/_expected/es/assets/banner-2b65cc0c.txt rename to test/chunking-form/samples/emit-file/set-asset-source/_expected/es/assets/banner-8c7ed2d9.txt diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/es/assets/footer-e1d2fccb.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/es/assets/footer-0301844c.txt similarity index 100% rename from test/chunking-form/samples/emit-file/set-asset-source/_expected/es/assets/footer-e1d2fccb.txt rename to test/chunking-form/samples/emit-file/set-asset-source/_expected/es/assets/footer-0301844c.txt diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/es/assets/generateBundle-668db42d.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/es/assets/generateBundle-668db42d.txt new file mode 100644 index 00000000000..253f7587c3a --- /dev/null +++ b/test/chunking-form/samples/emit-file/set-asset-source/_expected/es/assets/generateBundle-668db42d.txt @@ -0,0 +1 @@ +generateBundle es with assets/generateBundle-format-c0bc1e08.txt \ No newline at end of file diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/es/assets/generateBundle-7e84678a.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/es/assets/generateBundle-7e84678a.txt deleted file mode 100644 index 70119149dc7..00000000000 --- a/test/chunking-form/samples/emit-file/set-asset-source/_expected/es/assets/generateBundle-7e84678a.txt +++ /dev/null @@ -1 +0,0 @@ -generateBundle es with assets/generateBundle-format-8b573c58.txt \ No newline at end of file diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/es/assets/generateBundle-format-8b573c58.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/es/assets/generateBundle-format-c0bc1e08.txt similarity index 100% rename from test/chunking-form/samples/emit-file/set-asset-source/_expected/es/assets/generateBundle-format-8b573c58.txt rename to test/chunking-form/samples/emit-file/set-asset-source/_expected/es/assets/generateBundle-format-c0bc1e08.txt diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/es/assets/intro-520a8116.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/es/assets/intro-c432b372.txt similarity index 100% rename from test/chunking-form/samples/emit-file/set-asset-source/_expected/es/assets/intro-520a8116.txt rename to test/chunking-form/samples/emit-file/set-asset-source/_expected/es/assets/intro-c432b372.txt diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/es/assets/outro-21f77720.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/es/assets/outro-1e5fe046.txt similarity index 100% rename from test/chunking-form/samples/emit-file/set-asset-source/_expected/es/assets/outro-21f77720.txt rename to test/chunking-form/samples/emit-file/set-asset-source/_expected/es/assets/outro-1e5fe046.txt diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/es/assets/renderChunk-a91c7c32.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/es/assets/renderChunk-aa9e49b7.txt similarity index 100% rename from test/chunking-form/samples/emit-file/set-asset-source/_expected/es/assets/renderChunk-a91c7c32.txt rename to test/chunking-form/samples/emit-file/set-asset-source/_expected/es/assets/renderChunk-aa9e49b7.txt diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/es/assets/renderStart-66600c78.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/es/assets/renderStart-981aa2ea.txt similarity index 100% rename from test/chunking-form/samples/emit-file/set-asset-source/_expected/es/assets/renderStart-66600c78.txt rename to test/chunking-form/samples/emit-file/set-asset-source/_expected/es/assets/renderStart-981aa2ea.txt diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/es/generateBundle.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/es/generateBundle.txt index 70119149dc7..253f7587c3a 100644 --- a/test/chunking-form/samples/emit-file/set-asset-source/_expected/es/generateBundle.txt +++ b/test/chunking-form/samples/emit-file/set-asset-source/_expected/es/generateBundle.txt @@ -1 +1 @@ -generateBundle es with assets/generateBundle-format-8b573c58.txt \ No newline at end of file +generateBundle es with assets/generateBundle-format-c0bc1e08.txt \ No newline at end of file diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/es/main.js b/test/chunking-form/samples/emit-file/set-asset-source/_expected/es/main.js index 067f0c112fc..1e7d92b70a7 100644 --- a/test/chunking-form/samples/emit-file/set-asset-source/_expected/es/main.js +++ b/test/chunking-form/samples/emit-file/set-asset-source/_expected/es/main.js @@ -1,13 +1,11 @@ -const renderStart = new URL('assets/renderStart-66600c78.txt', import.meta.url).href; +const renderStart = new URL('assets/renderStart-981aa2ea.txt', import.meta.url).href; const renderStartNamed = new URL('renderStart.txt', import.meta.url).href; const renderStartNamedImmediately = 'renderStart.txt'; -const banner = new URL('assets/banner-2b65cc0c.txt', import.meta.url).href; const bannerNamed = new URL('banner.txt', import.meta.url).href; -const footer = new URL('assets/footer-e1d2fccb.txt', import.meta.url).href; const footerNamed = new URL('footer.txt', import.meta.url).href; -const intro = new URL('assets/intro-520a8116.txt', import.meta.url).href; const introNamed = new URL('intro.txt', import.meta.url).href; -const outro = new URL('assets/outro-21f77720.txt', import.meta.url).href; const outroNamed = new URL('outro.txt', import.meta.url).href; +const renderChunkNamed = new URL('renderChunk.txt', import.meta.url).href; +const generateBundleNamed = new URL('generateBundle.txt', import.meta.url).href; -export { banner, bannerNamed, footer, footerNamed, intro, introNamed, outro, outroNamed, renderStart, renderStartNamed, renderStartNamedImmediately }; +export { bannerNamed, footerNamed, generateBundleNamed, introNamed, outroNamed, renderChunkNamed, renderStart, renderStartNamed, renderStartNamedImmediately }; diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/system/assets/banner-2b65cc0c.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/system/assets/banner-8c7ed2d9.txt similarity index 100% rename from test/chunking-form/samples/emit-file/set-asset-source/_expected/system/assets/banner-2b65cc0c.txt rename to test/chunking-form/samples/emit-file/set-asset-source/_expected/system/assets/banner-8c7ed2d9.txt diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/system/assets/footer-e1d2fccb.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/system/assets/footer-0301844c.txt similarity index 100% rename from test/chunking-form/samples/emit-file/set-asset-source/_expected/system/assets/footer-e1d2fccb.txt rename to test/chunking-form/samples/emit-file/set-asset-source/_expected/system/assets/footer-0301844c.txt diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/system/assets/generateBundle-b0505b8f.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/system/assets/generateBundle-b0505b8f.txt new file mode 100644 index 00000000000..7b9889b5acb --- /dev/null +++ b/test/chunking-form/samples/emit-file/set-asset-source/_expected/system/assets/generateBundle-b0505b8f.txt @@ -0,0 +1 @@ +generateBundle system with assets/generateBundle-format-bbc5e661.txt \ No newline at end of file diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/system/assets/generateBundle-dd5a26a4.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/system/assets/generateBundle-dd5a26a4.txt deleted file mode 100644 index fdbb98a9d52..00000000000 --- a/test/chunking-form/samples/emit-file/set-asset-source/_expected/system/assets/generateBundle-dd5a26a4.txt +++ /dev/null @@ -1 +0,0 @@ -generateBundle system with assets/generateBundle-format-7df86840.txt \ No newline at end of file diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/system/assets/generateBundle-format-7df86840.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/system/assets/generateBundle-format-bbc5e661.txt similarity index 100% rename from test/chunking-form/samples/emit-file/set-asset-source/_expected/system/assets/generateBundle-format-7df86840.txt rename to test/chunking-form/samples/emit-file/set-asset-source/_expected/system/assets/generateBundle-format-bbc5e661.txt diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/system/assets/intro-520a8116.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/system/assets/intro-c432b372.txt similarity index 100% rename from test/chunking-form/samples/emit-file/set-asset-source/_expected/system/assets/intro-520a8116.txt rename to test/chunking-form/samples/emit-file/set-asset-source/_expected/system/assets/intro-c432b372.txt diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/system/assets/outro-21f77720.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/system/assets/outro-1e5fe046.txt similarity index 100% rename from test/chunking-form/samples/emit-file/set-asset-source/_expected/system/assets/outro-21f77720.txt rename to test/chunking-form/samples/emit-file/set-asset-source/_expected/system/assets/outro-1e5fe046.txt diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/system/assets/renderChunk-a91c7c32.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/system/assets/renderChunk-aa9e49b7.txt similarity index 100% rename from test/chunking-form/samples/emit-file/set-asset-source/_expected/system/assets/renderChunk-a91c7c32.txt rename to test/chunking-form/samples/emit-file/set-asset-source/_expected/system/assets/renderChunk-aa9e49b7.txt diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/system/assets/renderStart-66600c78.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/system/assets/renderStart-981aa2ea.txt similarity index 100% rename from test/chunking-form/samples/emit-file/set-asset-source/_expected/system/assets/renderStart-66600c78.txt rename to test/chunking-form/samples/emit-file/set-asset-source/_expected/system/assets/renderStart-981aa2ea.txt diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/system/generateBundle.txt b/test/chunking-form/samples/emit-file/set-asset-source/_expected/system/generateBundle.txt index fdbb98a9d52..7b9889b5acb 100644 --- a/test/chunking-form/samples/emit-file/set-asset-source/_expected/system/generateBundle.txt +++ b/test/chunking-form/samples/emit-file/set-asset-source/_expected/system/generateBundle.txt @@ -1 +1 @@ -generateBundle system with assets/generateBundle-format-7df86840.txt \ No newline at end of file +generateBundle system with assets/generateBundle-format-bbc5e661.txt \ No newline at end of file diff --git a/test/chunking-form/samples/emit-file/set-asset-source/_expected/system/main.js b/test/chunking-form/samples/emit-file/set-asset-source/_expected/system/main.js index ff13e5e65b1..ecff092f8e7 100644 --- a/test/chunking-form/samples/emit-file/set-asset-source/_expected/system/main.js +++ b/test/chunking-form/samples/emit-file/set-asset-source/_expected/system/main.js @@ -3,17 +3,15 @@ System.register([], (function (exports, module) { return { execute: (function () { - const renderStart = exports('renderStart', new URL('assets/renderStart-66600c78.txt', module.meta.url).href); + const renderStart = exports('renderStart', new URL('assets/renderStart-981aa2ea.txt', module.meta.url).href); const renderStartNamed = exports('renderStartNamed', new URL('renderStart.txt', module.meta.url).href); const renderStartNamedImmediately = exports('renderStartNamedImmediately', 'renderStart.txt'); - const banner = exports('banner', new URL('assets/banner-2b65cc0c.txt', module.meta.url).href); const bannerNamed = exports('bannerNamed', new URL('banner.txt', module.meta.url).href); - const footer = exports('footer', new URL('assets/footer-e1d2fccb.txt', module.meta.url).href); const footerNamed = exports('footerNamed', new URL('footer.txt', module.meta.url).href); - const intro = exports('intro', new URL('assets/intro-520a8116.txt', module.meta.url).href); const introNamed = exports('introNamed', new URL('intro.txt', module.meta.url).href); - const outro = exports('outro', new URL('assets/outro-21f77720.txt', module.meta.url).href); const outroNamed = exports('outroNamed', new URL('outro.txt', module.meta.url).href); + const renderChunkNamed = exports('renderChunkNamed', new URL('renderChunk.txt', module.meta.url).href); + const generateBundleNamed = exports('generateBundleNamed', new URL('generateBundle.txt', module.meta.url).href); }) }; diff --git a/test/chunking-form/samples/filenames-patterns/_expected/amd/chunk-main2-6a714ad3-amd.js b/test/chunking-form/samples/filenames-patterns/_expected/amd/chunk-main2-a7baadb6-amd.js similarity index 100% rename from test/chunking-form/samples/filenames-patterns/_expected/amd/chunk-main2-6a714ad3-amd.js rename to test/chunking-form/samples/filenames-patterns/_expected/amd/chunk-main2-a7baadb6-amd.js diff --git a/test/chunking-form/samples/filenames-patterns/_expected/amd/entry-main1-f47d0370-amd.js b/test/chunking-form/samples/filenames-patterns/_expected/amd/entry-main1-f47d0370-amd.js deleted file mode 100644 index 6614c42f978..00000000000 --- a/test/chunking-form/samples/filenames-patterns/_expected/amd/entry-main1-f47d0370-amd.js +++ /dev/null @@ -1,5 +0,0 @@ -define(['./chunk-main2-6a714ad3-amd'], (function (main2) { 'use strict'; - - main2.log(main2.dep); - -})); diff --git a/test/chunking-form/samples/filenames-patterns/_expected/amd/entry-main1-f9abc9cf-amd.js b/test/chunking-form/samples/filenames-patterns/_expected/amd/entry-main1-f9abc9cf-amd.js new file mode 100644 index 00000000000..f06358c3771 --- /dev/null +++ b/test/chunking-form/samples/filenames-patterns/_expected/amd/entry-main1-f9abc9cf-amd.js @@ -0,0 +1,5 @@ +define(['./chunk-main2-a7baadb6-amd'], (function (main2) { 'use strict'; + + main2.log(main2.dep); + +})); diff --git a/test/chunking-form/samples/filenames-patterns/_expected/amd/entry-main2-4db8cd0c-amd.js b/test/chunking-form/samples/filenames-patterns/_expected/amd/entry-main2-4db8cd0c-amd.js deleted file mode 100644 index 080df3846bc..00000000000 --- a/test/chunking-form/samples/filenames-patterns/_expected/amd/entry-main2-4db8cd0c-amd.js +++ /dev/null @@ -1,7 +0,0 @@ -define(['./chunk-main2-6a714ad3-amd'], (function (main2) { 'use strict'; - - - - return main2.log; - -})); diff --git a/test/chunking-form/samples/filenames-patterns/_expected/amd/entry-main2-85af4452-amd.js b/test/chunking-form/samples/filenames-patterns/_expected/amd/entry-main2-85af4452-amd.js new file mode 100644 index 00000000000..27e38c81871 --- /dev/null +++ b/test/chunking-form/samples/filenames-patterns/_expected/amd/entry-main2-85af4452-amd.js @@ -0,0 +1,7 @@ +define(['./chunk-main2-a7baadb6-amd'], (function (main2) { 'use strict'; + + + + return main2.log; + +})); diff --git a/test/chunking-form/samples/filenames-patterns/_expected/cjs/chunk-main2-397efa8f-cjs.js b/test/chunking-form/samples/filenames-patterns/_expected/cjs/chunk-main2-399c15fc-cjs.js similarity index 100% rename from test/chunking-form/samples/filenames-patterns/_expected/cjs/chunk-main2-397efa8f-cjs.js rename to test/chunking-form/samples/filenames-patterns/_expected/cjs/chunk-main2-399c15fc-cjs.js diff --git a/test/chunking-form/samples/filenames-patterns/_expected/cjs/entry-main1-5358eeba-cjs.js b/test/chunking-form/samples/filenames-patterns/_expected/cjs/entry-main1-5358eeba-cjs.js deleted file mode 100644 index 5528fde39bd..00000000000 --- a/test/chunking-form/samples/filenames-patterns/_expected/cjs/entry-main1-5358eeba-cjs.js +++ /dev/null @@ -1,5 +0,0 @@ -'use strict'; - -var main2 = require('./chunk-main2-397efa8f-cjs.js'); - -main2.log(main2.dep); diff --git a/test/chunking-form/samples/filenames-patterns/_expected/cjs/entry-main1-5f74b9d5-cjs.js b/test/chunking-form/samples/filenames-patterns/_expected/cjs/entry-main1-5f74b9d5-cjs.js new file mode 100644 index 00000000000..b3ace5cc380 --- /dev/null +++ b/test/chunking-form/samples/filenames-patterns/_expected/cjs/entry-main1-5f74b9d5-cjs.js @@ -0,0 +1,5 @@ +'use strict'; + +var main2 = require('./chunk-main2-399c15fc-cjs.js'); + +main2.log(main2.dep); diff --git a/test/chunking-form/samples/filenames-patterns/_expected/cjs/entry-main2-1558fcfd-cjs.js b/test/chunking-form/samples/filenames-patterns/_expected/cjs/entry-main2-1558fcfd-cjs.js new file mode 100644 index 00000000000..a2103eea76a --- /dev/null +++ b/test/chunking-form/samples/filenames-patterns/_expected/cjs/entry-main2-1558fcfd-cjs.js @@ -0,0 +1,7 @@ +'use strict'; + +var main2 = require('./chunk-main2-399c15fc-cjs.js'); + + + +module.exports = main2.log; diff --git a/test/chunking-form/samples/filenames-patterns/_expected/cjs/entry-main2-6a001c26-cjs.js b/test/chunking-form/samples/filenames-patterns/_expected/cjs/entry-main2-6a001c26-cjs.js deleted file mode 100644 index 3479ebb3f9c..00000000000 --- a/test/chunking-form/samples/filenames-patterns/_expected/cjs/entry-main2-6a001c26-cjs.js +++ /dev/null @@ -1,7 +0,0 @@ -'use strict'; - -var main2 = require('./chunk-main2-397efa8f-cjs.js'); - - - -module.exports = main2.log; diff --git a/test/chunking-form/samples/filenames-patterns/_expected/es/chunk-main2-bb2aced4-es.js b/test/chunking-form/samples/filenames-patterns/_expected/es/chunk-main2-c42fce1a-es.js similarity index 100% rename from test/chunking-form/samples/filenames-patterns/_expected/es/chunk-main2-bb2aced4-es.js rename to test/chunking-form/samples/filenames-patterns/_expected/es/chunk-main2-c42fce1a-es.js diff --git a/test/chunking-form/samples/filenames-patterns/_expected/es/entry-main1-0a8075b5-es.js b/test/chunking-form/samples/filenames-patterns/_expected/es/entry-main1-0a8075b5-es.js new file mode 100644 index 00000000000..43a51c0260d --- /dev/null +++ b/test/chunking-form/samples/filenames-patterns/_expected/es/entry-main1-0a8075b5-es.js @@ -0,0 +1,3 @@ +import { l as log, d as dep } from './chunk-main2-c42fce1a-es.js'; + +log(dep); diff --git a/test/chunking-form/samples/filenames-patterns/_expected/es/entry-main1-352fcfce-es.js b/test/chunking-form/samples/filenames-patterns/_expected/es/entry-main1-352fcfce-es.js deleted file mode 100644 index 989bb35ec89..00000000000 --- a/test/chunking-form/samples/filenames-patterns/_expected/es/entry-main1-352fcfce-es.js +++ /dev/null @@ -1,3 +0,0 @@ -import { l as log, d as dep } from './chunk-main2-bb2aced4-es.js'; - -log(dep); diff --git a/test/chunking-form/samples/filenames-patterns/_expected/es/entry-main2-8ebb5d84-es.js b/test/chunking-form/samples/filenames-patterns/_expected/es/entry-main2-8ebb5d84-es.js deleted file mode 100644 index eee53e0b1e0..00000000000 --- a/test/chunking-form/samples/filenames-patterns/_expected/es/entry-main2-8ebb5d84-es.js +++ /dev/null @@ -1 +0,0 @@ -export { l as default } from './chunk-main2-bb2aced4-es.js'; diff --git a/test/chunking-form/samples/filenames-patterns/_expected/es/entry-main2-fb2a74f2-es.js b/test/chunking-form/samples/filenames-patterns/_expected/es/entry-main2-fb2a74f2-es.js new file mode 100644 index 00000000000..ebb3c3e8959 --- /dev/null +++ b/test/chunking-form/samples/filenames-patterns/_expected/es/entry-main2-fb2a74f2-es.js @@ -0,0 +1 @@ +export { l as default } from './chunk-main2-c42fce1a-es.js'; diff --git a/test/chunking-form/samples/filenames-patterns/_expected/system/chunk-main2-97f5caac-system.js b/test/chunking-form/samples/filenames-patterns/_expected/system/chunk-main2-9cc03624-system.js similarity index 100% rename from test/chunking-form/samples/filenames-patterns/_expected/system/chunk-main2-97f5caac-system.js rename to test/chunking-form/samples/filenames-patterns/_expected/system/chunk-main2-9cc03624-system.js diff --git a/test/chunking-form/samples/filenames-patterns/_expected/system/entry-main1-e6585a3e-system.js b/test/chunking-form/samples/filenames-patterns/_expected/system/entry-main1-9f23e20b-system.js similarity index 73% rename from test/chunking-form/samples/filenames-patterns/_expected/system/entry-main1-e6585a3e-system.js rename to test/chunking-form/samples/filenames-patterns/_expected/system/entry-main1-9f23e20b-system.js index 62b088bf16f..bbe15d21f98 100644 --- a/test/chunking-form/samples/filenames-patterns/_expected/system/entry-main1-e6585a3e-system.js +++ b/test/chunking-form/samples/filenames-patterns/_expected/system/entry-main1-9f23e20b-system.js @@ -1,4 +1,4 @@ -System.register(['./chunk-main2-97f5caac-system.js'], (function () { +System.register(['./chunk-main2-9cc03624-system.js'], (function () { 'use strict'; var log, dep; return { diff --git a/test/chunking-form/samples/filenames-patterns/_expected/system/entry-main2-2e964c97-system.js b/test/chunking-form/samples/filenames-patterns/_expected/system/entry-main2-e9563da5-system.js similarity index 70% rename from test/chunking-form/samples/filenames-patterns/_expected/system/entry-main2-2e964c97-system.js rename to test/chunking-form/samples/filenames-patterns/_expected/system/entry-main2-e9563da5-system.js index 0f325c8f3d3..8b0dde3a35e 100644 --- a/test/chunking-form/samples/filenames-patterns/_expected/system/entry-main2-2e964c97-system.js +++ b/test/chunking-form/samples/filenames-patterns/_expected/system/entry-main2-e9563da5-system.js @@ -1,4 +1,4 @@ -System.register(['./chunk-main2-97f5caac-system.js'], (function (exports) { +System.register(['./chunk-main2-9cc03624-system.js'], (function (exports) { 'use strict'; return { setters: [function (module) { diff --git a/test/chunking-form/samples/hashing/deconflict-hashes/_config.js b/test/chunking-form/samples/hashing/deconflict-hashes/_config.js new file mode 100644 index 00000000000..f201f896d67 --- /dev/null +++ b/test/chunking-form/samples/hashing/deconflict-hashes/_config.js @@ -0,0 +1,7 @@ +module.exports = { + description: 'deduplicates hashes for identical files', + options: { + input: ['main1', 'main2'], + output: { entryFileNames: 'entry-[hash].js' } + } +}; diff --git a/test/chunking-form/samples/hashing/deconflict-hashes/_expected/amd/entry-7061c38c.js b/test/chunking-form/samples/hashing/deconflict-hashes/_expected/amd/entry-7061c38c.js new file mode 100644 index 00000000000..49540b44d78 --- /dev/null +++ b/test/chunking-form/samples/hashing/deconflict-hashes/_expected/amd/entry-7061c38c.js @@ -0,0 +1,5 @@ +define((function () { 'use strict'; + + console.log('main'); + +})); diff --git a/test/chunking-form/samples/hashing/deconflict-hashes/_expected/amd/entry-82a5a8a4.js b/test/chunking-form/samples/hashing/deconflict-hashes/_expected/amd/entry-82a5a8a4.js new file mode 100644 index 00000000000..49540b44d78 --- /dev/null +++ b/test/chunking-form/samples/hashing/deconflict-hashes/_expected/amd/entry-82a5a8a4.js @@ -0,0 +1,5 @@ +define((function () { 'use strict'; + + console.log('main'); + +})); diff --git a/test/chunking-form/samples/hashing/deconflict-hashes/_expected/cjs/entry-8011025d.js b/test/chunking-form/samples/hashing/deconflict-hashes/_expected/cjs/entry-8011025d.js new file mode 100644 index 00000000000..d0ed06d8c90 --- /dev/null +++ b/test/chunking-form/samples/hashing/deconflict-hashes/_expected/cjs/entry-8011025d.js @@ -0,0 +1,3 @@ +'use strict'; + +console.log('main'); diff --git a/test/chunking-form/samples/hashing/deconflict-hashes/_expected/cjs/entry-fc7b26ff.js b/test/chunking-form/samples/hashing/deconflict-hashes/_expected/cjs/entry-fc7b26ff.js new file mode 100644 index 00000000000..d0ed06d8c90 --- /dev/null +++ b/test/chunking-form/samples/hashing/deconflict-hashes/_expected/cjs/entry-fc7b26ff.js @@ -0,0 +1,3 @@ +'use strict'; + +console.log('main'); diff --git a/test/chunking-form/samples/hashing/deconflict-hashes/_expected/es/entry-2b8647b5.js b/test/chunking-form/samples/hashing/deconflict-hashes/_expected/es/entry-2b8647b5.js new file mode 100644 index 00000000000..c0b933d7b56 --- /dev/null +++ b/test/chunking-form/samples/hashing/deconflict-hashes/_expected/es/entry-2b8647b5.js @@ -0,0 +1 @@ +console.log('main'); diff --git a/test/chunking-form/samples/hashing/deconflict-hashes/_expected/es/entry-369b04c8.js b/test/chunking-form/samples/hashing/deconflict-hashes/_expected/es/entry-369b04c8.js new file mode 100644 index 00000000000..c0b933d7b56 --- /dev/null +++ b/test/chunking-form/samples/hashing/deconflict-hashes/_expected/es/entry-369b04c8.js @@ -0,0 +1 @@ +console.log('main'); diff --git a/test/chunking-form/samples/hashing/deconflict-hashes/_expected/system/entry-54240e14.js b/test/chunking-form/samples/hashing/deconflict-hashes/_expected/system/entry-54240e14.js new file mode 100644 index 00000000000..35e2693371a --- /dev/null +++ b/test/chunking-form/samples/hashing/deconflict-hashes/_expected/system/entry-54240e14.js @@ -0,0 +1,10 @@ +System.register([], (function () { + 'use strict'; + return { + execute: (function () { + + console.log('main'); + + }) + }; +})); diff --git a/test/chunking-form/samples/hashing/deconflict-hashes/_expected/system/entry-ed8fdbb3.js b/test/chunking-form/samples/hashing/deconflict-hashes/_expected/system/entry-ed8fdbb3.js new file mode 100644 index 00000000000..35e2693371a --- /dev/null +++ b/test/chunking-form/samples/hashing/deconflict-hashes/_expected/system/entry-ed8fdbb3.js @@ -0,0 +1,10 @@ +System.register([], (function () { + 'use strict'; + return { + execute: (function () { + + console.log('main'); + + }) + }; +})); diff --git a/test/chunking-form/samples/hashing/deconflict-hashes/main1.js b/test/chunking-form/samples/hashing/deconflict-hashes/main1.js new file mode 100644 index 00000000000..c0b933d7b56 --- /dev/null +++ b/test/chunking-form/samples/hashing/deconflict-hashes/main1.js @@ -0,0 +1 @@ +console.log('main'); diff --git a/test/chunking-form/samples/hashing/deconflict-hashes/main2.js b/test/chunking-form/samples/hashing/deconflict-hashes/main2.js new file mode 100644 index 00000000000..c0b933d7b56 --- /dev/null +++ b/test/chunking-form/samples/hashing/deconflict-hashes/main2.js @@ -0,0 +1 @@ +console.log('main'); diff --git a/test/chunking-form/samples/hashing/double-hash/_config.js b/test/chunking-form/samples/hashing/double-hash/_config.js new file mode 100644 index 00000000000..065a56632e9 --- /dev/null +++ b/test/chunking-form/samples/hashing/double-hash/_config.js @@ -0,0 +1,6 @@ +module.exports = { + description: 'supports double hashes in patterns', + options: { + output: { entryFileNames: '[hash]/entry-[hash].js' } + } +}; diff --git a/test/chunking-form/samples/hashing/double-hash/_expected/amd/7061c38c/entry-7061c38c.js b/test/chunking-form/samples/hashing/double-hash/_expected/amd/7061c38c/entry-7061c38c.js new file mode 100644 index 00000000000..49540b44d78 --- /dev/null +++ b/test/chunking-form/samples/hashing/double-hash/_expected/amd/7061c38c/entry-7061c38c.js @@ -0,0 +1,5 @@ +define((function () { 'use strict'; + + console.log('main'); + +})); diff --git a/test/chunking-form/samples/hashing/double-hash/_expected/cjs/8011025d/entry-8011025d.js b/test/chunking-form/samples/hashing/double-hash/_expected/cjs/8011025d/entry-8011025d.js new file mode 100644 index 00000000000..d0ed06d8c90 --- /dev/null +++ b/test/chunking-form/samples/hashing/double-hash/_expected/cjs/8011025d/entry-8011025d.js @@ -0,0 +1,3 @@ +'use strict'; + +console.log('main'); diff --git a/test/chunking-form/samples/hashing/double-hash/_expected/es/2b8647b5/entry-2b8647b5.js b/test/chunking-form/samples/hashing/double-hash/_expected/es/2b8647b5/entry-2b8647b5.js new file mode 100644 index 00000000000..c0b933d7b56 --- /dev/null +++ b/test/chunking-form/samples/hashing/double-hash/_expected/es/2b8647b5/entry-2b8647b5.js @@ -0,0 +1 @@ +console.log('main'); diff --git a/test/chunking-form/samples/hashing/double-hash/_expected/system/54240e14/entry-54240e14.js b/test/chunking-form/samples/hashing/double-hash/_expected/system/54240e14/entry-54240e14.js new file mode 100644 index 00000000000..35e2693371a --- /dev/null +++ b/test/chunking-form/samples/hashing/double-hash/_expected/system/54240e14/entry-54240e14.js @@ -0,0 +1,10 @@ +System.register([], (function () { + 'use strict'; + return { + execute: (function () { + + console.log('main'); + + }) + }; +})); diff --git a/test/chunking-form/samples/hashing/double-hash/main.js b/test/chunking-form/samples/hashing/double-hash/main.js new file mode 100644 index 00000000000..c0b933d7b56 --- /dev/null +++ b/test/chunking-form/samples/hashing/double-hash/main.js @@ -0,0 +1 @@ +console.log('main'); diff --git a/test/chunking-form/samples/hashing/hash-size/_config.js b/test/chunking-form/samples/hashing/hash-size/_config.js new file mode 100644 index 00000000000..fbbb3adc5bf --- /dev/null +++ b/test/chunking-form/samples/hashing/hash-size/_config.js @@ -0,0 +1,20 @@ +module.exports = { + description: 'allows configurable hash size', + options: { + input: ['main1.js', 'main2.js'], + plugins: [ + { + name: 'test', + buildStart() { + this.emitFile({ type: 'asset', name: 'test.txt', source: 'test' }); + } + } + ], + output: { + entryFileNames: ({ name }) => + name === 'main1' ? '[name]-[hash:6].js' : '[name]-[hash:10].js', + chunkFileNames: '[name]-[hash:14].js', + assetFileNames: '[name]-[hash:18][extname]' + } + } +}; diff --git a/test/chunking-form/samples/hashing/hash-size/_expected/amd/dep-5905830720d5f3.js b/test/chunking-form/samples/hashing/hash-size/_expected/amd/dep-5905830720d5f3.js new file mode 100644 index 00000000000..f94a3d9d9f9 --- /dev/null +++ b/test/chunking-form/samples/hashing/hash-size/_expected/amd/dep-5905830720d5f3.js @@ -0,0 +1,5 @@ +define((function () { 'use strict'; + + console.log('dep'); + +})); diff --git a/test/chunking-form/samples/hashing/hash-size/_expected/amd/main1-07dd83.js b/test/chunking-form/samples/hashing/hash-size/_expected/amd/main1-07dd83.js new file mode 100644 index 00000000000..3f3a686186f --- /dev/null +++ b/test/chunking-form/samples/hashing/hash-size/_expected/amd/main1-07dd83.js @@ -0,0 +1,5 @@ +define(['./dep-5905830720d5f3'], (function (dep) { 'use strict'; + + console.log('main1'); + +})); diff --git a/test/chunking-form/samples/hashing/hash-size/_expected/amd/main2-3eb7d864c1.js b/test/chunking-form/samples/hashing/hash-size/_expected/amd/main2-3eb7d864c1.js new file mode 100644 index 00000000000..e4c34f3a280 --- /dev/null +++ b/test/chunking-form/samples/hashing/hash-size/_expected/amd/main2-3eb7d864c1.js @@ -0,0 +1,5 @@ +define(['./dep-5905830720d5f3'], (function (dep) { 'use strict'; + + console.log('main2'); + +})); diff --git a/test/chunking-form/samples/hashing/hash-size/_expected/amd/test-9f86d081884c7d659a.txt b/test/chunking-form/samples/hashing/hash-size/_expected/amd/test-9f86d081884c7d659a.txt new file mode 100644 index 00000000000..30d74d25844 --- /dev/null +++ b/test/chunking-form/samples/hashing/hash-size/_expected/amd/test-9f86d081884c7d659a.txt @@ -0,0 +1 @@ +test \ No newline at end of file diff --git a/test/chunking-form/samples/hashing/hash-size/_expected/cjs/dep-0f12b4bf62a634.js b/test/chunking-form/samples/hashing/hash-size/_expected/cjs/dep-0f12b4bf62a634.js new file mode 100644 index 00000000000..f97cbb47032 --- /dev/null +++ b/test/chunking-form/samples/hashing/hash-size/_expected/cjs/dep-0f12b4bf62a634.js @@ -0,0 +1,3 @@ +'use strict'; + +console.log('dep'); diff --git a/test/chunking-form/samples/hashing/hash-size/_expected/cjs/main1-ebd270.js b/test/chunking-form/samples/hashing/hash-size/_expected/cjs/main1-ebd270.js new file mode 100644 index 00000000000..5b8fcb08ea5 --- /dev/null +++ b/test/chunking-form/samples/hashing/hash-size/_expected/cjs/main1-ebd270.js @@ -0,0 +1,5 @@ +'use strict'; + +require('./dep-0f12b4bf62a634.js'); + +console.log('main1'); diff --git a/test/chunking-form/samples/hashing/hash-size/_expected/cjs/main2-4c56283430.js b/test/chunking-form/samples/hashing/hash-size/_expected/cjs/main2-4c56283430.js new file mode 100644 index 00000000000..908db6fb440 --- /dev/null +++ b/test/chunking-form/samples/hashing/hash-size/_expected/cjs/main2-4c56283430.js @@ -0,0 +1,5 @@ +'use strict'; + +require('./dep-0f12b4bf62a634.js'); + +console.log('main2'); diff --git a/test/chunking-form/samples/hashing/hash-size/_expected/cjs/test-9f86d081884c7d659a.txt b/test/chunking-form/samples/hashing/hash-size/_expected/cjs/test-9f86d081884c7d659a.txt new file mode 100644 index 00000000000..30d74d25844 --- /dev/null +++ b/test/chunking-form/samples/hashing/hash-size/_expected/cjs/test-9f86d081884c7d659a.txt @@ -0,0 +1 @@ +test \ No newline at end of file diff --git a/test/chunking-form/samples/hashing/hash-size/_expected/es/dep-cd6f5744f7fc9c.js b/test/chunking-form/samples/hashing/hash-size/_expected/es/dep-cd6f5744f7fc9c.js new file mode 100644 index 00000000000..b74a9837c07 --- /dev/null +++ b/test/chunking-form/samples/hashing/hash-size/_expected/es/dep-cd6f5744f7fc9c.js @@ -0,0 +1 @@ +console.log('dep'); diff --git a/test/chunking-form/samples/hashing/hash-size/_expected/es/main1-126f2a.js b/test/chunking-form/samples/hashing/hash-size/_expected/es/main1-126f2a.js new file mode 100644 index 00000000000..1416a70c565 --- /dev/null +++ b/test/chunking-form/samples/hashing/hash-size/_expected/es/main1-126f2a.js @@ -0,0 +1,3 @@ +import './dep-cd6f5744f7fc9c.js'; + +console.log('main1'); diff --git a/test/chunking-form/samples/hashing/hash-size/_expected/es/main2-064a8187cc.js b/test/chunking-form/samples/hashing/hash-size/_expected/es/main2-064a8187cc.js new file mode 100644 index 00000000000..95158db6417 --- /dev/null +++ b/test/chunking-form/samples/hashing/hash-size/_expected/es/main2-064a8187cc.js @@ -0,0 +1,3 @@ +import './dep-cd6f5744f7fc9c.js'; + +console.log('main2'); diff --git a/test/chunking-form/samples/hashing/hash-size/_expected/es/test-9f86d081884c7d659a.txt b/test/chunking-form/samples/hashing/hash-size/_expected/es/test-9f86d081884c7d659a.txt new file mode 100644 index 00000000000..30d74d25844 --- /dev/null +++ b/test/chunking-form/samples/hashing/hash-size/_expected/es/test-9f86d081884c7d659a.txt @@ -0,0 +1 @@ +test \ No newline at end of file diff --git a/test/chunking-form/samples/hashing/hash-size/_expected/system/dep-626bb5df3105f7.js b/test/chunking-form/samples/hashing/hash-size/_expected/system/dep-626bb5df3105f7.js new file mode 100644 index 00000000000..963f20ddf9c --- /dev/null +++ b/test/chunking-form/samples/hashing/hash-size/_expected/system/dep-626bb5df3105f7.js @@ -0,0 +1,10 @@ +System.register([], (function () { + 'use strict'; + return { + execute: (function () { + + console.log('dep'); + + }) + }; +})); diff --git a/test/chunking-form/samples/hashing/hash-size/_expected/system/main1-415c92.js b/test/chunking-form/samples/hashing/hash-size/_expected/system/main1-415c92.js new file mode 100644 index 00000000000..3da42becfd9 --- /dev/null +++ b/test/chunking-form/samples/hashing/hash-size/_expected/system/main1-415c92.js @@ -0,0 +1,11 @@ +System.register(['./dep-626bb5df3105f7.js'], (function () { + 'use strict'; + return { + setters: [function () {}], + execute: (function () { + + console.log('main1'); + + }) + }; +})); diff --git a/test/chunking-form/samples/hashing/hash-size/_expected/system/main2-606a1eb4a0.js b/test/chunking-form/samples/hashing/hash-size/_expected/system/main2-606a1eb4a0.js new file mode 100644 index 00000000000..0f4168236e8 --- /dev/null +++ b/test/chunking-form/samples/hashing/hash-size/_expected/system/main2-606a1eb4a0.js @@ -0,0 +1,11 @@ +System.register(['./dep-626bb5df3105f7.js'], (function () { + 'use strict'; + return { + setters: [function () {}], + execute: (function () { + + console.log('main2'); + + }) + }; +})); diff --git a/test/chunking-form/samples/hashing/hash-size/_expected/system/test-9f86d081884c7d659a.txt b/test/chunking-form/samples/hashing/hash-size/_expected/system/test-9f86d081884c7d659a.txt new file mode 100644 index 00000000000..30d74d25844 --- /dev/null +++ b/test/chunking-form/samples/hashing/hash-size/_expected/system/test-9f86d081884c7d659a.txt @@ -0,0 +1 @@ +test \ No newline at end of file diff --git a/test/chunking-form/samples/hashing/hash-size/dep.js b/test/chunking-form/samples/hashing/hash-size/dep.js new file mode 100644 index 00000000000..b74a9837c07 --- /dev/null +++ b/test/chunking-form/samples/hashing/hash-size/dep.js @@ -0,0 +1 @@ +console.log('dep'); diff --git a/test/chunking-form/samples/hashing/hash-size/main1.js b/test/chunking-form/samples/hashing/hash-size/main1.js new file mode 100644 index 00000000000..a739b1e23d4 --- /dev/null +++ b/test/chunking-form/samples/hashing/hash-size/main1.js @@ -0,0 +1,3 @@ +import "./dep.js"; + +console.log('main1'); diff --git a/test/chunking-form/samples/hashing/hash-size/main2.js b/test/chunking-form/samples/hashing/hash-size/main2.js new file mode 100644 index 00000000000..03ed51465f8 --- /dev/null +++ b/test/chunking-form/samples/hashing/hash-size/main2.js @@ -0,0 +1,3 @@ +import "./dep.js"; + +console.log('main2'); diff --git a/test/chunking-form/samples/hashing/random-match/_config.js b/test/chunking-form/samples/hashing/random-match/_config.js new file mode 100644 index 00000000000..0d4d25ea5af --- /dev/null +++ b/test/chunking-form/samples/hashing/random-match/_config.js @@ -0,0 +1,8 @@ +module.exports = { + description: 'leaves random hash matches untransformed', + options: { + output: { + entryFileNames: 'entry-[hash]-\uf7f9\ue4d30001\ue3cc\uf1fe-\uf7f9\ue4d31234\ue3cc\uf1fe.js' + } + } +}; diff --git "a/test/chunking-form/samples/hashing/random-match/_expected/amd/entry-45acd559-45acd559-\357\237\271\356\223\2231234\356\217\214\357\207\276.js" "b/test/chunking-form/samples/hashing/random-match/_expected/amd/entry-45acd559-45acd559-\357\237\271\356\223\2231234\356\217\214\357\207\276.js" new file mode 100644 index 00000000000..02f8a5233cc --- /dev/null +++ "b/test/chunking-form/samples/hashing/random-match/_expected/amd/entry-45acd559-45acd559-\357\237\271\356\223\2231234\356\217\214\357\207\276.js" @@ -0,0 +1,6 @@ +define((function () { 'use strict'; + + console.log('replaced: 45acd559'); + console.log('not replaced: 1234'); + +})); diff --git "a/test/chunking-form/samples/hashing/random-match/_expected/cjs/entry-55c0e99e-55c0e99e-\357\237\271\356\223\2231234\356\217\214\357\207\276.js" "b/test/chunking-form/samples/hashing/random-match/_expected/cjs/entry-55c0e99e-55c0e99e-\357\237\271\356\223\2231234\356\217\214\357\207\276.js" new file mode 100644 index 00000000000..1a49ad3d57e --- /dev/null +++ "b/test/chunking-form/samples/hashing/random-match/_expected/cjs/entry-55c0e99e-55c0e99e-\357\237\271\356\223\2231234\356\217\214\357\207\276.js" @@ -0,0 +1,4 @@ +'use strict'; + +console.log('replaced: 55c0e99e'); +console.log('not replaced: 1234'); diff --git "a/test/chunking-form/samples/hashing/random-match/_expected/es/entry-866d3e85-866d3e85-\357\237\271\356\223\2231234\356\217\214\357\207\276.js" "b/test/chunking-form/samples/hashing/random-match/_expected/es/entry-866d3e85-866d3e85-\357\237\271\356\223\2231234\356\217\214\357\207\276.js" new file mode 100644 index 00000000000..ceee8366c1a --- /dev/null +++ "b/test/chunking-form/samples/hashing/random-match/_expected/es/entry-866d3e85-866d3e85-\357\237\271\356\223\2231234\356\217\214\357\207\276.js" @@ -0,0 +1,2 @@ +console.log('replaced: 866d3e85'); +console.log('not replaced: 1234'); diff --git "a/test/chunking-form/samples/hashing/random-match/_expected/system/entry-74248106-74248106-\357\237\271\356\223\2231234\356\217\214\357\207\276.js" "b/test/chunking-form/samples/hashing/random-match/_expected/system/entry-74248106-74248106-\357\237\271\356\223\2231234\356\217\214\357\207\276.js" new file mode 100644 index 00000000000..447bcd2b513 --- /dev/null +++ "b/test/chunking-form/samples/hashing/random-match/_expected/system/entry-74248106-74248106-\357\237\271\356\223\2231234\356\217\214\357\207\276.js" @@ -0,0 +1,11 @@ +System.register([], (function () { + 'use strict'; + return { + execute: (function () { + + console.log('replaced: 74248106'); + console.log('not replaced: 1234'); + + }) + }; +})); diff --git a/test/chunking-form/samples/hashing/random-match/main.js b/test/chunking-form/samples/hashing/random-match/main.js new file mode 100644 index 00000000000..f1cafc1f36a --- /dev/null +++ b/test/chunking-form/samples/hashing/random-match/main.js @@ -0,0 +1,2 @@ +console.log('replaced: 0001'); +console.log('not replaced: 1234'); diff --git a/test/chunking-form/samples/tree-shaken-dynamic-hash/_config.js b/test/chunking-form/samples/hashing/tree-shaken-dynamic-hash/_config.js similarity index 100% rename from test/chunking-form/samples/tree-shaken-dynamic-hash/_config.js rename to test/chunking-form/samples/hashing/tree-shaken-dynamic-hash/_config.js diff --git a/test/chunking-form/samples/tree-shaken-dynamic-hash/_expected/amd/16d985e6.js b/test/chunking-form/samples/hashing/tree-shaken-dynamic-hash/_expected/amd/09da348a.js similarity index 100% rename from test/chunking-form/samples/tree-shaken-dynamic-hash/_expected/amd/16d985e6.js rename to test/chunking-form/samples/hashing/tree-shaken-dynamic-hash/_expected/amd/09da348a.js diff --git a/test/chunking-form/samples/tree-shaken-dynamic-hash/_expected/cjs/05ff8838.js b/test/chunking-form/samples/hashing/tree-shaken-dynamic-hash/_expected/cjs/b99f90f4.js similarity index 100% rename from test/chunking-form/samples/tree-shaken-dynamic-hash/_expected/cjs/05ff8838.js rename to test/chunking-form/samples/hashing/tree-shaken-dynamic-hash/_expected/cjs/b99f90f4.js diff --git a/test/chunking-form/samples/tree-shaken-dynamic-hash/_expected/es/bed29d35.js b/test/chunking-form/samples/hashing/tree-shaken-dynamic-hash/_expected/es/55aeacf8.js similarity index 100% rename from test/chunking-form/samples/tree-shaken-dynamic-hash/_expected/es/bed29d35.js rename to test/chunking-form/samples/hashing/tree-shaken-dynamic-hash/_expected/es/55aeacf8.js diff --git a/test/chunking-form/samples/tree-shaken-dynamic-hash/_expected/system/0998116a.js b/test/chunking-form/samples/hashing/tree-shaken-dynamic-hash/_expected/system/e65da870.js similarity index 100% rename from test/chunking-form/samples/tree-shaken-dynamic-hash/_expected/system/0998116a.js rename to test/chunking-form/samples/hashing/tree-shaken-dynamic-hash/_expected/system/e65da870.js diff --git a/test/chunking-form/samples/tree-shaken-dynamic-hash/foo.js b/test/chunking-form/samples/hashing/tree-shaken-dynamic-hash/foo.js similarity index 100% rename from test/chunking-form/samples/tree-shaken-dynamic-hash/foo.js rename to test/chunking-form/samples/hashing/tree-shaken-dynamic-hash/foo.js diff --git a/test/chunking-form/samples/tree-shaken-dynamic-hash/main.js b/test/chunking-form/samples/hashing/tree-shaken-dynamic-hash/main.js similarity index 100% rename from test/chunking-form/samples/tree-shaken-dynamic-hash/main.js rename to test/chunking-form/samples/hashing/tree-shaken-dynamic-hash/main.js diff --git a/test/chunking-form/samples/manual-chunks-function/_config.js b/test/chunking-form/samples/manual-chunks-function/_config.js index 0407d6a0236..71f029fa64c 100644 --- a/test/chunking-form/samples/manual-chunks-function/_config.js +++ b/test/chunking-form/samples/manual-chunks-function/_config.js @@ -18,8 +18,8 @@ module.exports = { // between the manual chunks assert.deepStrictEqual(Object.keys(bundle), [ 'main-a.js', - 'generated-chunk-b.js', - 'generated-chunk-c.js' + 'generated-chunk-c.js', + 'generated-chunk-b.js' ]); } } diff --git a/test/chunking-form/samples/render-chunk-transform/_config.js b/test/chunking-form/samples/render-chunk-transform/_config.js new file mode 100644 index 00000000000..046f28ecd6e --- /dev/null +++ b/test/chunking-form/samples/render-chunk-transform/_config.js @@ -0,0 +1,77 @@ +const assert = require('assert'); +const path = require('path'); +const { replaceDirInStringifiedObject } = require('../../../utils'); + +module.exports = { + description: 'replaces hashes when mutating chunk info in renderChunk', + options: { + input: ['main1', 'main2'], + plugins: { + renderChunk(code, chunk, options, { chunks }) { + if (chunk.fileName.includes('main2')) { + const main1Chunk = Object.keys(chunks).find(fileName => fileName.includes('main1')); + chunk.imports.push(main1Chunk); + chunk.importedBindings[main1Chunk] = ['added']; + return `import { added } from ${JSON.stringify( + `./${main1Chunk}` + )};\nconsole.log(added);\n${code}`; + } + chunk.exports.push('added'); + return `${code}\nexport const added = 'added';`; + }, + generateBundle(options, bundle) { + const sanitizedBundle = JSON.parse( + replaceDirInStringifiedObject(bundle, __dirname).replace( + /(entry-\w+)-\w+\.js/g, + (match, name) => `${name}.js` + ) + ); + for (const fileName of Object.keys(sanitizedBundle)) { + delete sanitizedBundle[fileName].code; + delete sanitizedBundle[fileName].modules; + } + + assert.deepStrictEqual(sanitizedBundle, { + 'entry-main1.js': { + exports: ['added'], + facadeModuleId: '**/main1.js', + isDynamicEntry: false, + isEntry: true, + isImplicitEntry: false, + moduleIds: ['**/main1.js'], + name: 'main1', + type: 'chunk', + dynamicImports: [], + fileName: 'entry-main1.js', + implicitlyLoadedBefore: [], + importedBindings: {}, + imports: [], + referencedFiles: [], + map: null + }, + 'entry-main2.js': { + exports: [], + facadeModuleId: '**/main2.js', + isDynamicEntry: false, + isEntry: true, + isImplicitEntry: false, + moduleIds: ['**/main2.js'], + name: 'main2', + type: 'chunk', + dynamicImports: [], + fileName: 'entry-main2.js', + implicitlyLoadedBefore: [], + importedBindings: { 'entry-main1.js': ['added'] }, + imports: ['entry-main1.js'], + referencedFiles: [], + map: null + } + }); + } + }, + output: { + entryFileNames: 'entry-[name]-[hash].js', + chunkFileNames: 'chunk-[name]-[hash].js' + } + } +}; diff --git a/test/chunking-form/samples/render-chunk-transform/_expected/amd/entry-main1-31ed1903.js b/test/chunking-form/samples/render-chunk-transform/_expected/amd/entry-main1-31ed1903.js new file mode 100644 index 00000000000..baddcd1c81c --- /dev/null +++ b/test/chunking-form/samples/render-chunk-transform/_expected/amd/entry-main1-31ed1903.js @@ -0,0 +1,6 @@ +define((function () { 'use strict'; + + console.log('main1'); + +})); +export const added = 'added'; diff --git a/test/chunking-form/samples/render-chunk-transform/_expected/amd/entry-main2-16af9d90.js b/test/chunking-form/samples/render-chunk-transform/_expected/amd/entry-main2-16af9d90.js new file mode 100644 index 00000000000..a8a0784ce22 --- /dev/null +++ b/test/chunking-form/samples/render-chunk-transform/_expected/amd/entry-main2-16af9d90.js @@ -0,0 +1,7 @@ +import { added } from "./entry-main1-31ed1903.js"; +console.log(added); +define((function () { 'use strict'; + + console.log('main2'); + +})); diff --git a/test/chunking-form/samples/render-chunk-transform/_expected/cjs/entry-main1-c6673fa5.js b/test/chunking-form/samples/render-chunk-transform/_expected/cjs/entry-main1-c6673fa5.js new file mode 100644 index 00000000000..27e474e9ef1 --- /dev/null +++ b/test/chunking-form/samples/render-chunk-transform/_expected/cjs/entry-main1-c6673fa5.js @@ -0,0 +1,4 @@ +'use strict'; + +console.log('main1'); +export const added = 'added'; diff --git a/test/chunking-form/samples/render-chunk-transform/_expected/cjs/entry-main2-a19dc55f.js b/test/chunking-form/samples/render-chunk-transform/_expected/cjs/entry-main2-a19dc55f.js new file mode 100644 index 00000000000..af9ae0e960b --- /dev/null +++ b/test/chunking-form/samples/render-chunk-transform/_expected/cjs/entry-main2-a19dc55f.js @@ -0,0 +1,5 @@ +import { added } from "./entry-main1-c6673fa5.js"; +console.log(added); +'use strict'; + +console.log('main2'); diff --git a/test/chunking-form/samples/render-chunk-transform/_expected/es/entry-main1-56d7d368.js b/test/chunking-form/samples/render-chunk-transform/_expected/es/entry-main1-56d7d368.js new file mode 100644 index 00000000000..93378fe3d56 --- /dev/null +++ b/test/chunking-form/samples/render-chunk-transform/_expected/es/entry-main1-56d7d368.js @@ -0,0 +1,2 @@ +console.log('main1'); +export const added = 'added'; diff --git a/test/chunking-form/samples/render-chunk-transform/_expected/es/entry-main2-5a17c9e2.js b/test/chunking-form/samples/render-chunk-transform/_expected/es/entry-main2-5a17c9e2.js new file mode 100644 index 00000000000..183983b05c8 --- /dev/null +++ b/test/chunking-form/samples/render-chunk-transform/_expected/es/entry-main2-5a17c9e2.js @@ -0,0 +1,3 @@ +import { added } from "./entry-main1-56d7d368.js"; +console.log(added); +console.log('main2'); diff --git a/test/chunking-form/samples/render-chunk-transform/_expected/system/entry-main1-d7dc9358.js b/test/chunking-form/samples/render-chunk-transform/_expected/system/entry-main1-d7dc9358.js new file mode 100644 index 00000000000..a1b90cb4147 --- /dev/null +++ b/test/chunking-form/samples/render-chunk-transform/_expected/system/entry-main1-d7dc9358.js @@ -0,0 +1,11 @@ +System.register([], (function () { + 'use strict'; + return { + execute: (function () { + + console.log('main1'); + + }) + }; +})); +export const added = 'added'; diff --git a/test/chunking-form/samples/render-chunk-transform/_expected/system/entry-main2-d4227ff0.js b/test/chunking-form/samples/render-chunk-transform/_expected/system/entry-main2-d4227ff0.js new file mode 100644 index 00000000000..f97000e8248 --- /dev/null +++ b/test/chunking-form/samples/render-chunk-transform/_expected/system/entry-main2-d4227ff0.js @@ -0,0 +1,12 @@ +import { added } from "./entry-main1-d7dc9358.js"; +console.log(added); +System.register([], (function () { + 'use strict'; + return { + execute: (function () { + + console.log('main2'); + + }) + }; +})); diff --git a/test/chunking-form/samples/render-chunk-transform/main1.js b/test/chunking-form/samples/render-chunk-transform/main1.js new file mode 100644 index 00000000000..fda34828717 --- /dev/null +++ b/test/chunking-form/samples/render-chunk-transform/main1.js @@ -0,0 +1 @@ +console.log('main1'); diff --git a/test/chunking-form/samples/render-chunk-transform/main2.js b/test/chunking-form/samples/render-chunk-transform/main2.js new file mode 100644 index 00000000000..ac653633351 --- /dev/null +++ b/test/chunking-form/samples/render-chunk-transform/main2.js @@ -0,0 +1 @@ +console.log('main2'); diff --git a/test/chunking-form/samples/render-chunk/_config.js b/test/chunking-form/samples/render-chunk/_config.js index 6c925c5e62a..6ca7f743227 100644 --- a/test/chunking-form/samples/render-chunk/_config.js +++ b/test/chunking-form/samples/render-chunk/_config.js @@ -1,24 +1,33 @@ const assert = require('assert'); +const { replaceDirInStringifiedObject } = require('../../../utils'); module.exports = { - description: 'transforms chunks in the renderChunk hook', + description: + 'transforms chunks in the renderChunk hook, also transforming hashes added in the hook', options: { input: ['main1', 'main2'], plugins: { - renderChunk(code, chunk, options) { - assert.strictEqual(options.chunkFileNames, 'chunk-[name].js'); + transform(code) { + const referenceId = this.emitFile({ type: 'asset', name: 'test', source: 'test' }); + return `${code}\nconsole.log('referenced asset', import.meta.ROLLUP_FILE_URL_${referenceId});`; + }, + renderChunk(code, chunk, options, { chunks }) { + // Ensure the entries in "chunks" reference the actual chunk objects + assert.strictEqual(chunks[chunk.fileName], chunk); return ( code + - `\nconsole.log('fileName', '${chunk.fileName}');` + - `\nconsole.log('imports', '${chunk.imports.join(', ')}');` + - `\nconsole.log('isEntry', ${chunk.isEntry});` + - `\nconsole.log('name', '${chunk.name}');` + - `\nconsole.log('modules.length', ${Object.keys(chunk.modules).length});` + `\nconsole.log(${replaceDirInStringifiedObject(chunk, __dirname)});` + + `\nconsole.log('all chunks', ${JSON.stringify(Object.keys(chunks))})` + + `\nconsole.log('referenced asset in renderChunk', '${this.getFileName( + this.emitFile({ type: 'asset', name: 'test', source: 'test' }) + )}');` ); } }, output: { - chunkFileNames: 'chunk-[name].js' + entryFileNames: 'entry-[name]-[hash].js', + chunkFileNames: 'chunk-[name]-[hash].js', + assetFileNames: 'asset-[name]-[hash][extname]' } } }; diff --git a/test/chunking-form/samples/render-chunk/_expected/amd/asset-test-9f86d081 b/test/chunking-form/samples/render-chunk/_expected/amd/asset-test-9f86d081 new file mode 100644 index 00000000000..30d74d25844 --- /dev/null +++ b/test/chunking-form/samples/render-chunk/_expected/amd/asset-test-9f86d081 @@ -0,0 +1 @@ +test \ No newline at end of file diff --git a/test/chunking-form/samples/render-chunk/_expected/amd/chunk-dep2-5e5c0a2b.js b/test/chunking-form/samples/render-chunk/_expected/amd/chunk-dep2-5e5c0a2b.js new file mode 100644 index 00000000000..f97c4e7a250 --- /dev/null +++ b/test/chunking-form/samples/render-chunk/_expected/amd/chunk-dep2-5e5c0a2b.js @@ -0,0 +1,43 @@ +define(['require', 'exports'], (function (require, exports) { 'use strict'; + + var num = 2; + console.log('referenced asset', new URL(require.toUrl('./asset-test-9f86d081'), document.baseURI).href); + + exports.num = num; + +})); +console.log({ + "exports": [ + "num" + ], + "facadeModuleId": null, + "isDynamicEntry": false, + "isEntry": false, + "isImplicitEntry": false, + "moduleIds": [ + "**/dep2.js" + ], + "name": "dep2", + "type": "chunk", + "dynamicImports": [], + "fileName": "chunk-dep2-5e5c0a2b.js", + "implicitlyLoadedBefore": [], + "importedBindings": {}, + "imports": [], + "modules": { + "**/dep2.js": { + "code": "\tvar num = 2;\n\tconsole.log('referenced asset', new URL(require.toUrl('./asset-test-9f86d081'), document.baseURI).href);", + "originalLength": 19, + "removedExports": [], + "renderedExports": [ + "num" + ], + "renderedLength": 117 + } + }, + "referencedFiles": [ + "asset-test-9f86d081" + ] +}); +console.log('all chunks', ["entry-main1-92387c07.js","chunk-dep2-5e5c0a2b.js","entry-main2-8423cd41.js"]) +console.log('referenced asset in renderChunk', 'asset-test-9f86d081'); diff --git a/test/chunking-form/samples/render-chunk/_expected/amd/chunk-dep2.js b/test/chunking-form/samples/render-chunk/_expected/amd/chunk-dep2.js deleted file mode 100644 index 1a8ac477d2f..00000000000 --- a/test/chunking-form/samples/render-chunk/_expected/amd/chunk-dep2.js +++ /dev/null @@ -1,12 +0,0 @@ -define(['exports'], (function (exports) { 'use strict'; - - var num = 2; - - exports.num = num; - -})); -console.log('fileName', 'chunk-dep2.js'); -console.log('imports', ''); -console.log('isEntry', false); -console.log('name', 'dep2'); -console.log('modules.length', 1); diff --git a/test/chunking-form/samples/render-chunk/_expected/amd/entry-main1-92387c07.js b/test/chunking-form/samples/render-chunk/_expected/amd/entry-main1-92387c07.js new file mode 100644 index 00000000000..c6bd70f656b --- /dev/null +++ b/test/chunking-form/samples/render-chunk/_expected/amd/entry-main1-92387c07.js @@ -0,0 +1,56 @@ +define(['require', './chunk-dep2-5e5c0a2b'], (function (require, dep2) { 'use strict'; + + var num = 1; + console.log('referenced asset', new URL(require.toUrl('./asset-test-9f86d081'), document.baseURI).href); + + console.log(num + dep2.num); + console.log('referenced asset', new URL(require.toUrl('./asset-test-9f86d081'), document.baseURI).href); + +})); +console.log({ + "exports": [], + "facadeModuleId": "**/main1.js", + "isDynamicEntry": false, + "isEntry": true, + "isImplicitEntry": false, + "moduleIds": [ + "**/dep1.js", + "**/main1.js" + ], + "name": "main1", + "type": "chunk", + "dynamicImports": [], + "fileName": "entry-main1-92387c07.js", + "implicitlyLoadedBefore": [], + "importedBindings": { + "chunk-dep2-5e5c0a2b.js": [ + "num" + ] + }, + "imports": [ + "chunk-dep2-5e5c0a2b.js" + ], + "modules": { + "**/dep1.js": { + "code": "\tvar num = 1;\n\tconsole.log('referenced asset', new URL(require.toUrl('./asset-test-9f86d081'), document.baseURI).href);", + "originalLength": 19, + "removedExports": [], + "renderedExports": [ + "num" + ], + "renderedLength": 117 + }, + "**/main1.js": { + "code": "\tconsole.log(num + dep2.num);\n\tconsole.log('referenced asset', new URL(require.toUrl('./asset-test-9f86d081'), document.baseURI).href);", + "originalLength": 102, + "removedExports": [], + "renderedExports": [], + "renderedLength": 133 + } + }, + "referencedFiles": [ + "asset-test-9f86d081" + ] +}); +console.log('all chunks', ["entry-main1-92387c07.js","chunk-dep2-5e5c0a2b.js","entry-main2-8423cd41.js"]) +console.log('referenced asset in renderChunk', 'asset-test-9f86d081'); diff --git a/test/chunking-form/samples/render-chunk/_expected/amd/entry-main2-8423cd41.js b/test/chunking-form/samples/render-chunk/_expected/amd/entry-main2-8423cd41.js new file mode 100644 index 00000000000..578b4551443 --- /dev/null +++ b/test/chunking-form/samples/render-chunk/_expected/amd/entry-main2-8423cd41.js @@ -0,0 +1,56 @@ +define(['require', './chunk-dep2-5e5c0a2b'], (function (require, dep2) { 'use strict'; + + var num = 3; + console.log('referenced asset', new URL(require.toUrl('./asset-test-9f86d081'), document.baseURI).href); + + console.log(dep2.num + num); + console.log('referenced asset', new URL(require.toUrl('./asset-test-9f86d081'), document.baseURI).href); + +})); +console.log({ + "exports": [], + "facadeModuleId": "**/main2.js", + "isDynamicEntry": false, + "isEntry": true, + "isImplicitEntry": false, + "moduleIds": [ + "**/dep3.js", + "**/main2.js" + ], + "name": "main2", + "type": "chunk", + "dynamicImports": [], + "fileName": "entry-main2-8423cd41.js", + "implicitlyLoadedBefore": [], + "importedBindings": { + "chunk-dep2-5e5c0a2b.js": [ + "num" + ] + }, + "imports": [ + "chunk-dep2-5e5c0a2b.js" + ], + "modules": { + "**/dep3.js": { + "code": "\tvar num = 3;\n\tconsole.log('referenced asset', new URL(require.toUrl('./asset-test-9f86d081'), document.baseURI).href);", + "originalLength": 19, + "removedExports": [], + "renderedExports": [ + "num" + ], + "renderedLength": 117 + }, + "**/main2.js": { + "code": "\tconsole.log(dep2.num + num);\n\tconsole.log('referenced asset', new URL(require.toUrl('./asset-test-9f86d081'), document.baseURI).href);", + "originalLength": 102, + "removedExports": [], + "renderedExports": [], + "renderedLength": 133 + } + }, + "referencedFiles": [ + "asset-test-9f86d081" + ] +}); +console.log('all chunks', ["entry-main1-92387c07.js","chunk-dep2-5e5c0a2b.js","entry-main2-8423cd41.js"]) +console.log('referenced asset in renderChunk', 'asset-test-9f86d081'); diff --git a/test/chunking-form/samples/render-chunk/_expected/amd/main1.js b/test/chunking-form/samples/render-chunk/_expected/amd/main1.js deleted file mode 100644 index 2ab2b673698..00000000000 --- a/test/chunking-form/samples/render-chunk/_expected/amd/main1.js +++ /dev/null @@ -1,12 +0,0 @@ -define(['./chunk-dep2'], (function (dep2) { 'use strict'; - - var num = 1; - - console.log(num + dep2.num); - -})); -console.log('fileName', 'main1.js'); -console.log('imports', 'chunk-dep2.js'); -console.log('isEntry', true); -console.log('name', 'main1'); -console.log('modules.length', 2); diff --git a/test/chunking-form/samples/render-chunk/_expected/amd/main2.js b/test/chunking-form/samples/render-chunk/_expected/amd/main2.js deleted file mode 100644 index 540de8220c0..00000000000 --- a/test/chunking-form/samples/render-chunk/_expected/amd/main2.js +++ /dev/null @@ -1,12 +0,0 @@ -define(['./chunk-dep2'], (function (dep2) { 'use strict'; - - var num = 3; - - console.log(dep2.num + num); - -})); -console.log('fileName', 'main2.js'); -console.log('imports', 'chunk-dep2.js'); -console.log('isEntry', true); -console.log('name', 'main2'); -console.log('modules.length', 2); diff --git a/test/chunking-form/samples/render-chunk/_expected/cjs/asset-test-9f86d081 b/test/chunking-form/samples/render-chunk/_expected/cjs/asset-test-9f86d081 new file mode 100644 index 00000000000..30d74d25844 --- /dev/null +++ b/test/chunking-form/samples/render-chunk/_expected/cjs/asset-test-9f86d081 @@ -0,0 +1 @@ +test \ No newline at end of file diff --git a/test/chunking-form/samples/render-chunk/_expected/cjs/chunk-dep2-b09f6eac.js b/test/chunking-form/samples/render-chunk/_expected/cjs/chunk-dep2-b09f6eac.js new file mode 100644 index 00000000000..6b0cc7cac14 --- /dev/null +++ b/test/chunking-form/samples/render-chunk/_expected/cjs/chunk-dep2-b09f6eac.js @@ -0,0 +1,41 @@ +'use strict'; + +var num = 2; +console.log('referenced asset', (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/asset-test-9f86d081').href : new URL('asset-test-9f86d081', document.currentScript && document.currentScript.src || document.baseURI).href)); + +exports.num = num; +console.log({ + "exports": [ + "num" + ], + "facadeModuleId": null, + "isDynamicEntry": false, + "isEntry": false, + "isImplicitEntry": false, + "moduleIds": [ + "**/dep2.js" + ], + "name": "dep2", + "type": "chunk", + "dynamicImports": [], + "fileName": "chunk-dep2-b09f6eac.js", + "implicitlyLoadedBefore": [], + "importedBindings": {}, + "imports": [], + "modules": { + "**/dep2.js": { + "code": "var num = 2;\nconsole.log('referenced asset', (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/asset-test-9f86d081').href : new URL('asset-test-9f86d081', document.currentScript && document.currentScript.src || document.baseURI).href));", + "originalLength": 19, + "removedExports": [], + "renderedExports": [ + "num" + ], + "renderedLength": 275 + } + }, + "referencedFiles": [ + "asset-test-9f86d081" + ] +}); +console.log('all chunks', ["entry-main1-465ee0c3.js","chunk-dep2-b09f6eac.js","entry-main2-333fdc53.js"]) +console.log('referenced asset in renderChunk', 'asset-test-9f86d081'); diff --git a/test/chunking-form/samples/render-chunk/_expected/cjs/chunk-dep2.js b/test/chunking-form/samples/render-chunk/_expected/cjs/chunk-dep2.js deleted file mode 100644 index ad01f5c7b03..00000000000 --- a/test/chunking-form/samples/render-chunk/_expected/cjs/chunk-dep2.js +++ /dev/null @@ -1,10 +0,0 @@ -'use strict'; - -var num = 2; - -exports.num = num; -console.log('fileName', 'chunk-dep2.js'); -console.log('imports', ''); -console.log('isEntry', false); -console.log('name', 'dep2'); -console.log('modules.length', 1); diff --git a/test/chunking-form/samples/render-chunk/_expected/cjs/entry-main1-465ee0c3.js b/test/chunking-form/samples/render-chunk/_expected/cjs/entry-main1-465ee0c3.js new file mode 100644 index 00000000000..e6b7bdc31a7 --- /dev/null +++ b/test/chunking-form/samples/render-chunk/_expected/cjs/entry-main1-465ee0c3.js @@ -0,0 +1,56 @@ +'use strict'; + +var dep2 = require('./chunk-dep2-b09f6eac.js'); + +var num = 1; +console.log('referenced asset', (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/asset-test-9f86d081').href : new URL('asset-test-9f86d081', document.currentScript && document.currentScript.src || document.baseURI).href)); + +console.log(num + dep2.num); +console.log('referenced asset', (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/asset-test-9f86d081').href : new URL('asset-test-9f86d081', document.currentScript && document.currentScript.src || document.baseURI).href)); +console.log({ + "exports": [], + "facadeModuleId": "**/main1.js", + "isDynamicEntry": false, + "isEntry": true, + "isImplicitEntry": false, + "moduleIds": [ + "**/dep1.js", + "**/main1.js" + ], + "name": "main1", + "type": "chunk", + "dynamicImports": [], + "fileName": "entry-main1-465ee0c3.js", + "implicitlyLoadedBefore": [], + "importedBindings": { + "chunk-dep2-b09f6eac.js": [ + "num" + ] + }, + "imports": [ + "chunk-dep2-b09f6eac.js" + ], + "modules": { + "**/dep1.js": { + "code": "var num = 1;\nconsole.log('referenced asset', (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/asset-test-9f86d081').href : new URL('asset-test-9f86d081', document.currentScript && document.currentScript.src || document.baseURI).href));", + "originalLength": 19, + "removedExports": [], + "renderedExports": [ + "num" + ], + "renderedLength": 275 + }, + "**/main1.js": { + "code": "console.log(num + dep2.num);\nconsole.log('referenced asset', (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/asset-test-9f86d081').href : new URL('asset-test-9f86d081', document.currentScript && document.currentScript.src || document.baseURI).href));", + "originalLength": 102, + "removedExports": [], + "renderedExports": [], + "renderedLength": 291 + } + }, + "referencedFiles": [ + "asset-test-9f86d081" + ] +}); +console.log('all chunks', ["entry-main1-465ee0c3.js","chunk-dep2-b09f6eac.js","entry-main2-333fdc53.js"]) +console.log('referenced asset in renderChunk', 'asset-test-9f86d081'); diff --git a/test/chunking-form/samples/render-chunk/_expected/cjs/entry-main2-333fdc53.js b/test/chunking-form/samples/render-chunk/_expected/cjs/entry-main2-333fdc53.js new file mode 100644 index 00000000000..bc352138c16 --- /dev/null +++ b/test/chunking-form/samples/render-chunk/_expected/cjs/entry-main2-333fdc53.js @@ -0,0 +1,56 @@ +'use strict'; + +var dep2 = require('./chunk-dep2-b09f6eac.js'); + +var num = 3; +console.log('referenced asset', (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/asset-test-9f86d081').href : new URL('asset-test-9f86d081', document.currentScript && document.currentScript.src || document.baseURI).href)); + +console.log(dep2.num + num); +console.log('referenced asset', (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/asset-test-9f86d081').href : new URL('asset-test-9f86d081', document.currentScript && document.currentScript.src || document.baseURI).href)); +console.log({ + "exports": [], + "facadeModuleId": "**/main2.js", + "isDynamicEntry": false, + "isEntry": true, + "isImplicitEntry": false, + "moduleIds": [ + "**/dep3.js", + "**/main2.js" + ], + "name": "main2", + "type": "chunk", + "dynamicImports": [], + "fileName": "entry-main2-333fdc53.js", + "implicitlyLoadedBefore": [], + "importedBindings": { + "chunk-dep2-b09f6eac.js": [ + "num" + ] + }, + "imports": [ + "chunk-dep2-b09f6eac.js" + ], + "modules": { + "**/dep3.js": { + "code": "var num = 3;\nconsole.log('referenced asset', (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/asset-test-9f86d081').href : new URL('asset-test-9f86d081', document.currentScript && document.currentScript.src || document.baseURI).href));", + "originalLength": 19, + "removedExports": [], + "renderedExports": [ + "num" + ], + "renderedLength": 275 + }, + "**/main2.js": { + "code": "console.log(dep2.num + num);\nconsole.log('referenced asset', (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/asset-test-9f86d081').href : new URL('asset-test-9f86d081', document.currentScript && document.currentScript.src || document.baseURI).href));", + "originalLength": 102, + "removedExports": [], + "renderedExports": [], + "renderedLength": 291 + } + }, + "referencedFiles": [ + "asset-test-9f86d081" + ] +}); +console.log('all chunks', ["entry-main1-465ee0c3.js","chunk-dep2-b09f6eac.js","entry-main2-333fdc53.js"]) +console.log('referenced asset in renderChunk', 'asset-test-9f86d081'); diff --git a/test/chunking-form/samples/render-chunk/_expected/cjs/main1.js b/test/chunking-form/samples/render-chunk/_expected/cjs/main1.js deleted file mode 100644 index 86d308be0b0..00000000000 --- a/test/chunking-form/samples/render-chunk/_expected/cjs/main1.js +++ /dev/null @@ -1,12 +0,0 @@ -'use strict'; - -var dep2 = require('./chunk-dep2.js'); - -var num = 1; - -console.log(num + dep2.num); -console.log('fileName', 'main1.js'); -console.log('imports', 'chunk-dep2.js'); -console.log('isEntry', true); -console.log('name', 'main1'); -console.log('modules.length', 2); diff --git a/test/chunking-form/samples/render-chunk/_expected/cjs/main2.js b/test/chunking-form/samples/render-chunk/_expected/cjs/main2.js deleted file mode 100644 index f142d493e16..00000000000 --- a/test/chunking-form/samples/render-chunk/_expected/cjs/main2.js +++ /dev/null @@ -1,12 +0,0 @@ -'use strict'; - -var dep2 = require('./chunk-dep2.js'); - -var num = 3; - -console.log(dep2.num + num); -console.log('fileName', 'main2.js'); -console.log('imports', 'chunk-dep2.js'); -console.log('isEntry', true); -console.log('name', 'main2'); -console.log('modules.length', 2); diff --git a/test/chunking-form/samples/render-chunk/_expected/es/asset-test-9f86d081 b/test/chunking-form/samples/render-chunk/_expected/es/asset-test-9f86d081 new file mode 100644 index 00000000000..30d74d25844 --- /dev/null +++ b/test/chunking-form/samples/render-chunk/_expected/es/asset-test-9f86d081 @@ -0,0 +1 @@ +test \ No newline at end of file diff --git a/test/chunking-form/samples/render-chunk/_expected/es/chunk-dep2-124edba5.js b/test/chunking-form/samples/render-chunk/_expected/es/chunk-dep2-124edba5.js new file mode 100644 index 00000000000..fa3b4d492e1 --- /dev/null +++ b/test/chunking-form/samples/render-chunk/_expected/es/chunk-dep2-124edba5.js @@ -0,0 +1,39 @@ +var num = 2; +console.log('referenced asset', new URL('asset-test-9f86d081', import.meta.url).href); + +export { num as n }; +console.log({ + "exports": [ + "n" + ], + "facadeModuleId": null, + "isDynamicEntry": false, + "isEntry": false, + "isImplicitEntry": false, + "moduleIds": [ + "**/dep2.js" + ], + "name": "dep2", + "type": "chunk", + "dynamicImports": [], + "fileName": "chunk-dep2-124edba5.js", + "implicitlyLoadedBefore": [], + "importedBindings": {}, + "imports": [], + "modules": { + "**/dep2.js": { + "code": "var num = 2;\nconsole.log('referenced asset', new URL('asset-test-9f86d081', import.meta.url).href);", + "originalLength": 19, + "removedExports": [], + "renderedExports": [ + "num" + ], + "renderedLength": 99 + } + }, + "referencedFiles": [ + "asset-test-9f86d081" + ] +}); +console.log('all chunks', ["entry-main1-b12147aa.js","chunk-dep2-124edba5.js","entry-main2-09746024.js"]) +console.log('referenced asset in renderChunk', 'asset-test-9f86d081'); diff --git a/test/chunking-form/samples/render-chunk/_expected/es/chunk-dep2.js b/test/chunking-form/samples/render-chunk/_expected/es/chunk-dep2.js deleted file mode 100644 index 20ae277758e..00000000000 --- a/test/chunking-form/samples/render-chunk/_expected/es/chunk-dep2.js +++ /dev/null @@ -1,8 +0,0 @@ -var num = 2; - -export { num as n }; -console.log('fileName', 'chunk-dep2.js'); -console.log('imports', ''); -console.log('isEntry', false); -console.log('name', 'dep2'); -console.log('modules.length', 1); diff --git a/test/chunking-form/samples/render-chunk/_expected/es/entry-main1-b12147aa.js b/test/chunking-form/samples/render-chunk/_expected/es/entry-main1-b12147aa.js new file mode 100644 index 00000000000..7408471db99 --- /dev/null +++ b/test/chunking-form/samples/render-chunk/_expected/es/entry-main1-b12147aa.js @@ -0,0 +1,54 @@ +import { n as num$1 } from './chunk-dep2-124edba5.js'; + +var num = 1; +console.log('referenced asset', new URL('asset-test-9f86d081', import.meta.url).href); + +console.log(num + num$1); +console.log('referenced asset', new URL('asset-test-9f86d081', import.meta.url).href); +console.log({ + "exports": [], + "facadeModuleId": "**/main1.js", + "isDynamicEntry": false, + "isEntry": true, + "isImplicitEntry": false, + "moduleIds": [ + "**/dep1.js", + "**/main1.js" + ], + "name": "main1", + "type": "chunk", + "dynamicImports": [], + "fileName": "entry-main1-b12147aa.js", + "implicitlyLoadedBefore": [], + "importedBindings": { + "chunk-dep2-124edba5.js": [ + "n" + ] + }, + "imports": [ + "chunk-dep2-124edba5.js" + ], + "modules": { + "**/dep1.js": { + "code": "var num = 1;\nconsole.log('referenced asset', new URL('asset-test-9f86d081', import.meta.url).href);", + "originalLength": 19, + "removedExports": [], + "renderedExports": [ + "num" + ], + "renderedLength": 99 + }, + "**/main1.js": { + "code": "console.log(num + num$1);\nconsole.log('referenced asset', new URL('asset-test-9f86d081', import.meta.url).href);", + "originalLength": 102, + "removedExports": [], + "renderedExports": [], + "renderedLength": 112 + } + }, + "referencedFiles": [ + "asset-test-9f86d081" + ] +}); +console.log('all chunks', ["entry-main1-b12147aa.js","chunk-dep2-124edba5.js","entry-main2-09746024.js"]) +console.log('referenced asset in renderChunk', 'asset-test-9f86d081'); diff --git a/test/chunking-form/samples/render-chunk/_expected/es/entry-main2-09746024.js b/test/chunking-form/samples/render-chunk/_expected/es/entry-main2-09746024.js new file mode 100644 index 00000000000..4e3198988da --- /dev/null +++ b/test/chunking-form/samples/render-chunk/_expected/es/entry-main2-09746024.js @@ -0,0 +1,54 @@ +import { n as num$1 } from './chunk-dep2-124edba5.js'; + +var num = 3; +console.log('referenced asset', new URL('asset-test-9f86d081', import.meta.url).href); + +console.log(num$1 + num); +console.log('referenced asset', new URL('asset-test-9f86d081', import.meta.url).href); +console.log({ + "exports": [], + "facadeModuleId": "**/main2.js", + "isDynamicEntry": false, + "isEntry": true, + "isImplicitEntry": false, + "moduleIds": [ + "**/dep3.js", + "**/main2.js" + ], + "name": "main2", + "type": "chunk", + "dynamicImports": [], + "fileName": "entry-main2-09746024.js", + "implicitlyLoadedBefore": [], + "importedBindings": { + "chunk-dep2-124edba5.js": [ + "n" + ] + }, + "imports": [ + "chunk-dep2-124edba5.js" + ], + "modules": { + "**/dep3.js": { + "code": "var num = 3;\nconsole.log('referenced asset', new URL('asset-test-9f86d081', import.meta.url).href);", + "originalLength": 19, + "removedExports": [], + "renderedExports": [ + "num" + ], + "renderedLength": 99 + }, + "**/main2.js": { + "code": "console.log(num$1 + num);\nconsole.log('referenced asset', new URL('asset-test-9f86d081', import.meta.url).href);", + "originalLength": 102, + "removedExports": [], + "renderedExports": [], + "renderedLength": 112 + } + }, + "referencedFiles": [ + "asset-test-9f86d081" + ] +}); +console.log('all chunks', ["entry-main1-b12147aa.js","chunk-dep2-124edba5.js","entry-main2-09746024.js"]) +console.log('referenced asset in renderChunk', 'asset-test-9f86d081'); diff --git a/test/chunking-form/samples/render-chunk/_expected/es/main1.js b/test/chunking-form/samples/render-chunk/_expected/es/main1.js deleted file mode 100644 index c4b243a3998..00000000000 --- a/test/chunking-form/samples/render-chunk/_expected/es/main1.js +++ /dev/null @@ -1,10 +0,0 @@ -import { n as num$1 } from './chunk-dep2.js'; - -var num = 1; - -console.log(num + num$1); -console.log('fileName', 'main1.js'); -console.log('imports', 'chunk-dep2.js'); -console.log('isEntry', true); -console.log('name', 'main1'); -console.log('modules.length', 2); diff --git a/test/chunking-form/samples/render-chunk/_expected/es/main2.js b/test/chunking-form/samples/render-chunk/_expected/es/main2.js deleted file mode 100644 index 2666225853f..00000000000 --- a/test/chunking-form/samples/render-chunk/_expected/es/main2.js +++ /dev/null @@ -1,10 +0,0 @@ -import { n as num$1 } from './chunk-dep2.js'; - -var num = 3; - -console.log(num$1 + num); -console.log('fileName', 'main2.js'); -console.log('imports', 'chunk-dep2.js'); -console.log('isEntry', true); -console.log('name', 'main2'); -console.log('modules.length', 2); diff --git a/test/chunking-form/samples/render-chunk/_expected/system/asset-test-9f86d081 b/test/chunking-form/samples/render-chunk/_expected/system/asset-test-9f86d081 new file mode 100644 index 00000000000..30d74d25844 --- /dev/null +++ b/test/chunking-form/samples/render-chunk/_expected/system/asset-test-9f86d081 @@ -0,0 +1 @@ +test \ No newline at end of file diff --git a/test/chunking-form/samples/render-chunk/_expected/system/chunk-dep2-6579036d.js b/test/chunking-form/samples/render-chunk/_expected/system/chunk-dep2-6579036d.js new file mode 100644 index 00000000000..8c87c7a8501 --- /dev/null +++ b/test/chunking-form/samples/render-chunk/_expected/system/chunk-dep2-6579036d.js @@ -0,0 +1,46 @@ +System.register([], (function (exports, module) { + 'use strict'; + return { + execute: (function () { + + var num = exports('n', 2); + console.log('referenced asset', new URL('asset-test-9f86d081', module.meta.url).href); + + }) + }; +})); +console.log({ + "exports": [ + "n" + ], + "facadeModuleId": null, + "isDynamicEntry": false, + "isEntry": false, + "isImplicitEntry": false, + "moduleIds": [ + "**/dep2.js" + ], + "name": "dep2", + "type": "chunk", + "dynamicImports": [], + "fileName": "chunk-dep2-6579036d.js", + "implicitlyLoadedBefore": [], + "importedBindings": {}, + "imports": [], + "modules": { + "**/dep2.js": { + "code": "\t\t\tvar num = exports('n', 2);\n\t\t\tconsole.log('referenced asset', new URL('asset-test-9f86d081', module.meta.url).href);", + "originalLength": 19, + "removedExports": [], + "renderedExports": [ + "num" + ], + "renderedLength": 113 + } + }, + "referencedFiles": [ + "asset-test-9f86d081" + ] +}); +console.log('all chunks', ["entry-main1-331def45.js","chunk-dep2-6579036d.js","entry-main2-7bacea36.js"]) +console.log('referenced asset in renderChunk', 'asset-test-9f86d081'); diff --git a/test/chunking-form/samples/render-chunk/_expected/system/chunk-dep2.js b/test/chunking-form/samples/render-chunk/_expected/system/chunk-dep2.js deleted file mode 100644 index 63462658a6a..00000000000 --- a/test/chunking-form/samples/render-chunk/_expected/system/chunk-dep2.js +++ /dev/null @@ -1,15 +0,0 @@ -System.register([], (function (exports) { - 'use strict'; - return { - execute: (function () { - - var num = exports('n', 2); - - }) - }; -})); -console.log('fileName', 'chunk-dep2.js'); -console.log('imports', ''); -console.log('isEntry', false); -console.log('name', 'dep2'); -console.log('modules.length', 1); diff --git a/test/chunking-form/samples/render-chunk/_expected/system/entry-main1-331def45.js b/test/chunking-form/samples/render-chunk/_expected/system/entry-main1-331def45.js new file mode 100644 index 00000000000..ac113775c07 --- /dev/null +++ b/test/chunking-form/samples/render-chunk/_expected/system/entry-main1-331def45.js @@ -0,0 +1,65 @@ +System.register(['./chunk-dep2-6579036d.js'], (function (exports, module) { + 'use strict'; + var num$1; + return { + setters: [function (module) { + num$1 = module.n; + }], + execute: (function () { + + var num = 1; + console.log('referenced asset', new URL('asset-test-9f86d081', module.meta.url).href); + + console.log(num + num$1); + console.log('referenced asset', new URL('asset-test-9f86d081', module.meta.url).href); + + }) + }; +})); +console.log({ + "exports": [], + "facadeModuleId": "**/main1.js", + "isDynamicEntry": false, + "isEntry": true, + "isImplicitEntry": false, + "moduleIds": [ + "**/dep1.js", + "**/main1.js" + ], + "name": "main1", + "type": "chunk", + "dynamicImports": [], + "fileName": "entry-main1-331def45.js", + "implicitlyLoadedBefore": [], + "importedBindings": { + "chunk-dep2-6579036d.js": [ + "n" + ] + }, + "imports": [ + "chunk-dep2-6579036d.js" + ], + "modules": { + "**/dep1.js": { + "code": "\t\t\tvar num = 1;\n\t\t\tconsole.log('referenced asset', new URL('asset-test-9f86d081', module.meta.url).href);", + "originalLength": 19, + "removedExports": [], + "renderedExports": [ + "num" + ], + "renderedLength": 99 + }, + "**/main1.js": { + "code": "\t\t\tconsole.log(num + num$1);\n\t\t\tconsole.log('referenced asset', new URL('asset-test-9f86d081', module.meta.url).href);", + "originalLength": 102, + "removedExports": [], + "renderedExports": [], + "renderedLength": 112 + } + }, + "referencedFiles": [ + "asset-test-9f86d081" + ] +}); +console.log('all chunks', ["entry-main1-331def45.js","chunk-dep2-6579036d.js","entry-main2-7bacea36.js"]) +console.log('referenced asset in renderChunk', 'asset-test-9f86d081'); diff --git a/test/chunking-form/samples/render-chunk/_expected/system/entry-main2-7bacea36.js b/test/chunking-form/samples/render-chunk/_expected/system/entry-main2-7bacea36.js new file mode 100644 index 00000000000..9e0d0ca1dff --- /dev/null +++ b/test/chunking-form/samples/render-chunk/_expected/system/entry-main2-7bacea36.js @@ -0,0 +1,65 @@ +System.register(['./chunk-dep2-6579036d.js'], (function (exports, module) { + 'use strict'; + var num$1; + return { + setters: [function (module) { + num$1 = module.n; + }], + execute: (function () { + + var num = 3; + console.log('referenced asset', new URL('asset-test-9f86d081', module.meta.url).href); + + console.log(num$1 + num); + console.log('referenced asset', new URL('asset-test-9f86d081', module.meta.url).href); + + }) + }; +})); +console.log({ + "exports": [], + "facadeModuleId": "**/main2.js", + "isDynamicEntry": false, + "isEntry": true, + "isImplicitEntry": false, + "moduleIds": [ + "**/dep3.js", + "**/main2.js" + ], + "name": "main2", + "type": "chunk", + "dynamicImports": [], + "fileName": "entry-main2-7bacea36.js", + "implicitlyLoadedBefore": [], + "importedBindings": { + "chunk-dep2-6579036d.js": [ + "n" + ] + }, + "imports": [ + "chunk-dep2-6579036d.js" + ], + "modules": { + "**/dep3.js": { + "code": "\t\t\tvar num = 3;\n\t\t\tconsole.log('referenced asset', new URL('asset-test-9f86d081', module.meta.url).href);", + "originalLength": 19, + "removedExports": [], + "renderedExports": [ + "num" + ], + "renderedLength": 99 + }, + "**/main2.js": { + "code": "\t\t\tconsole.log(num$1 + num);\n\t\t\tconsole.log('referenced asset', new URL('asset-test-9f86d081', module.meta.url).href);", + "originalLength": 102, + "removedExports": [], + "renderedExports": [], + "renderedLength": 112 + } + }, + "referencedFiles": [ + "asset-test-9f86d081" + ] +}); +console.log('all chunks', ["entry-main1-331def45.js","chunk-dep2-6579036d.js","entry-main2-7bacea36.js"]) +console.log('referenced asset in renderChunk', 'asset-test-9f86d081'); diff --git a/test/chunking-form/samples/render-chunk/_expected/system/main1.js b/test/chunking-form/samples/render-chunk/_expected/system/main1.js deleted file mode 100644 index 41a4c734157..00000000000 --- a/test/chunking-form/samples/render-chunk/_expected/system/main1.js +++ /dev/null @@ -1,21 +0,0 @@ -System.register(['./chunk-dep2.js'], (function () { - 'use strict'; - var num$1; - return { - setters: [function (module) { - num$1 = module.n; - }], - execute: (function () { - - var num = 1; - - console.log(num + num$1); - - }) - }; -})); -console.log('fileName', 'main1.js'); -console.log('imports', 'chunk-dep2.js'); -console.log('isEntry', true); -console.log('name', 'main1'); -console.log('modules.length', 2); diff --git a/test/chunking-form/samples/render-chunk/_expected/system/main2.js b/test/chunking-form/samples/render-chunk/_expected/system/main2.js deleted file mode 100644 index 72988d3a16e..00000000000 --- a/test/chunking-form/samples/render-chunk/_expected/system/main2.js +++ /dev/null @@ -1,21 +0,0 @@ -System.register(['./chunk-dep2.js'], (function () { - 'use strict'; - var num$1; - return { - setters: [function (module) { - num$1 = module.n; - }], - execute: (function () { - - var num = 3; - - console.log(num$1 + num); - - }) - }; -})); -console.log('fileName', 'main2.js'); -console.log('imports', 'chunk-dep2.js'); -console.log('isEntry', true); -console.log('name', 'main2'); -console.log('modules.length', 2); diff --git a/test/chunking-form/samples/resolve-file-url/_expected/amd/assets/asset-resolved-8bd22e6e.txt b/test/chunking-form/samples/resolve-file-url/_expected/amd/assets/asset-resolved-9e0f7ca5.txt similarity index 100% rename from test/chunking-form/samples/resolve-file-url/_expected/amd/assets/asset-resolved-8bd22e6e.txt rename to test/chunking-form/samples/resolve-file-url/_expected/amd/assets/asset-resolved-9e0f7ca5.txt diff --git a/test/chunking-form/samples/resolve-file-url/_expected/amd/assets/asset-solved-28a7ac89.txt b/test/chunking-form/samples/resolve-file-url/_expected/amd/assets/asset-solved-230ecafd.txt similarity index 100% rename from test/chunking-form/samples/resolve-file-url/_expected/amd/assets/asset-solved-28a7ac89.txt rename to test/chunking-form/samples/resolve-file-url/_expected/amd/assets/asset-solved-230ecafd.txt diff --git a/test/chunking-form/samples/resolve-file-url/_expected/amd/assets/asset-unresolved-8dcd7fca.txt b/test/chunking-form/samples/resolve-file-url/_expected/amd/assets/asset-unresolved-f4c1e86c.txt similarity index 100% rename from test/chunking-form/samples/resolve-file-url/_expected/amd/assets/asset-unresolved-8dcd7fca.txt rename to test/chunking-form/samples/resolve-file-url/_expected/amd/assets/asset-unresolved-f4c1e86c.txt diff --git a/test/chunking-form/samples/resolve-file-url/_expected/amd/main.js b/test/chunking-form/samples/resolve-file-url/_expected/amd/main.js index cf5bdfec043..af4a4d20560 100644 --- a/test/chunking-form/samples/resolve-file-url/_expected/amd/main.js +++ b/test/chunking-form/samples/resolve-file-url/_expected/amd/main.js @@ -3,9 +3,9 @@ define(['require'], (function (require) { 'use strict'; const asset$1 = 'resolved'; const chunk$1 = 'resolved'; - const asset = new URL(require.toUrl('./assets/asset-unresolved-8dcd7fca.txt'), document.baseURI).href; - const chunk = new URL(require.toUrl('./nested/chunk.js'), document.baseURI).href; + const asset = new URL(require.toUrl('./assets/asset-unresolved-f4c1e86c.txt'), document.baseURI).href; + const chunk = new URL(require.toUrl('./nested/chunk2.js'), document.baseURI).href; - new Promise(function (resolve, reject) { require(['./nested/chunk2'], resolve, reject); }).then(result => console.log(result, chunk$1, chunk, asset$1, asset)); + new Promise(function (resolve, reject) { require(['./nested/chunk'], resolve, reject); }).then(result => console.log(result, chunk$1, chunk, asset$1, asset)); })); diff --git a/test/chunking-form/samples/resolve-file-url/_expected/amd/nested/chunk.js b/test/chunking-form/samples/resolve-file-url/_expected/amd/nested/chunk.js index f29221faf6c..c077f6b4e6b 100644 --- a/test/chunking-form/samples/resolve-file-url/_expected/amd/nested/chunk.js +++ b/test/chunking-form/samples/resolve-file-url/_expected/amd/nested/chunk.js @@ -1,5 +1,9 @@ -define((function () { 'use strict'; +define(['require', 'exports'], (function (require, exports) { 'use strict'; - console.log('chunk'); + const asset = 'chunkId=nested/chunk.js:moduleId=solved:fileName=assets/asset-solved-230ecafd.txt:format=amd:relativePath=../assets/asset-solved-230ecafd.txt:referenceId=6296c678'; + const chunk = 'chunkId=nested/chunk.js:moduleId=solved:fileName=nested/chunk2.js:format=amd:relativePath=chunk2.js:referenceId=f6c25ae7'; + + exports.asset = asset; + exports.chunk = chunk; })); diff --git a/test/chunking-form/samples/resolve-file-url/_expected/amd/nested/chunk2.js b/test/chunking-form/samples/resolve-file-url/_expected/amd/nested/chunk2.js index 44152bbff29..f29221faf6c 100644 --- a/test/chunking-form/samples/resolve-file-url/_expected/amd/nested/chunk2.js +++ b/test/chunking-form/samples/resolve-file-url/_expected/amd/nested/chunk2.js @@ -1,9 +1,5 @@ -define(['require', 'exports'], (function (require, exports) { 'use strict'; +define((function () { 'use strict'; - const asset = 'chunkId=nested/chunk2.js:moduleId=solved:fileName=assets/asset-solved-28a7ac89.txt:format=amd:relativePath=../assets/asset-solved-28a7ac89.txt:referenceId=6296c678'; - const chunk = 'chunkId=nested/chunk2.js:moduleId=solved:fileName=nested/chunk.js:format=amd:relativePath=chunk.js:referenceId=f6c25ae7'; - - exports.asset = asset; - exports.chunk = chunk; + console.log('chunk'); })); diff --git a/test/chunking-form/samples/resolve-file-url/_expected/cjs/assets/asset-resolved-8bd22e6e.txt b/test/chunking-form/samples/resolve-file-url/_expected/cjs/assets/asset-resolved-9e0f7ca5.txt similarity index 100% rename from test/chunking-form/samples/resolve-file-url/_expected/cjs/assets/asset-resolved-8bd22e6e.txt rename to test/chunking-form/samples/resolve-file-url/_expected/cjs/assets/asset-resolved-9e0f7ca5.txt diff --git a/test/chunking-form/samples/resolve-file-url/_expected/cjs/assets/asset-solved-28a7ac89.txt b/test/chunking-form/samples/resolve-file-url/_expected/cjs/assets/asset-solved-230ecafd.txt similarity index 100% rename from test/chunking-form/samples/resolve-file-url/_expected/cjs/assets/asset-solved-28a7ac89.txt rename to test/chunking-form/samples/resolve-file-url/_expected/cjs/assets/asset-solved-230ecafd.txt diff --git a/test/chunking-form/samples/resolve-file-url/_expected/cjs/assets/asset-unresolved-8dcd7fca.txt b/test/chunking-form/samples/resolve-file-url/_expected/cjs/assets/asset-unresolved-f4c1e86c.txt similarity index 100% rename from test/chunking-form/samples/resolve-file-url/_expected/cjs/assets/asset-unresolved-8dcd7fca.txt rename to test/chunking-form/samples/resolve-file-url/_expected/cjs/assets/asset-unresolved-f4c1e86c.txt diff --git a/test/chunking-form/samples/resolve-file-url/_expected/cjs/main.js b/test/chunking-form/samples/resolve-file-url/_expected/cjs/main.js index feea03def6e..24d8205dd21 100644 --- a/test/chunking-form/samples/resolve-file-url/_expected/cjs/main.js +++ b/test/chunking-form/samples/resolve-file-url/_expected/cjs/main.js @@ -3,7 +3,7 @@ const asset$1 = 'resolved'; const chunk$1 = 'resolved'; -const asset = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/asset-unresolved-8dcd7fca.txt').href : new URL('assets/asset-unresolved-8dcd7fca.txt', document.currentScript && document.currentScript.src || document.baseURI).href); -const chunk = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/nested/chunk.js').href : new URL('nested/chunk.js', document.currentScript && document.currentScript.src || document.baseURI).href); +const asset = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/asset-unresolved-f4c1e86c.txt').href : new URL('assets/asset-unresolved-f4c1e86c.txt', document.currentScript && document.currentScript.src || document.baseURI).href); +const chunk = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/nested/chunk2.js').href : new URL('nested/chunk2.js', document.currentScript && document.currentScript.src || document.baseURI).href); -Promise.resolve().then(function () { return require('./nested/chunk2.js'); }).then(result => console.log(result, chunk$1, chunk, asset$1, asset)); +Promise.resolve().then(function () { return require('./nested/chunk.js'); }).then(result => console.log(result, chunk$1, chunk, asset$1, asset)); diff --git a/test/chunking-form/samples/resolve-file-url/_expected/cjs/nested/chunk.js b/test/chunking-form/samples/resolve-file-url/_expected/cjs/nested/chunk.js index 9bd6f06e964..206e5c2c2a3 100644 --- a/test/chunking-form/samples/resolve-file-url/_expected/cjs/nested/chunk.js +++ b/test/chunking-form/samples/resolve-file-url/_expected/cjs/nested/chunk.js @@ -1,3 +1,7 @@ 'use strict'; -console.log('chunk'); +const asset = 'chunkId=nested/chunk.js:moduleId=solved:fileName=assets/asset-solved-230ecafd.txt:format=cjs:relativePath=../assets/asset-solved-230ecafd.txt:referenceId=6296c678'; +const chunk = 'chunkId=nested/chunk.js:moduleId=solved:fileName=nested/chunk2.js:format=cjs:relativePath=chunk2.js:referenceId=f6c25ae7'; + +exports.asset = asset; +exports.chunk = chunk; diff --git a/test/chunking-form/samples/resolve-file-url/_expected/cjs/nested/chunk2.js b/test/chunking-form/samples/resolve-file-url/_expected/cjs/nested/chunk2.js index 79b46e5bd8f..9bd6f06e964 100644 --- a/test/chunking-form/samples/resolve-file-url/_expected/cjs/nested/chunk2.js +++ b/test/chunking-form/samples/resolve-file-url/_expected/cjs/nested/chunk2.js @@ -1,7 +1,3 @@ 'use strict'; -const asset = 'chunkId=nested/chunk2.js:moduleId=solved:fileName=assets/asset-solved-28a7ac89.txt:format=cjs:relativePath=../assets/asset-solved-28a7ac89.txt:referenceId=6296c678'; -const chunk = 'chunkId=nested/chunk2.js:moduleId=solved:fileName=nested/chunk.js:format=cjs:relativePath=chunk.js:referenceId=f6c25ae7'; - -exports.asset = asset; -exports.chunk = chunk; +console.log('chunk'); diff --git a/test/chunking-form/samples/resolve-file-url/_expected/es/assets/asset-resolved-8bd22e6e.txt b/test/chunking-form/samples/resolve-file-url/_expected/es/assets/asset-resolved-9e0f7ca5.txt similarity index 100% rename from test/chunking-form/samples/resolve-file-url/_expected/es/assets/asset-resolved-8bd22e6e.txt rename to test/chunking-form/samples/resolve-file-url/_expected/es/assets/asset-resolved-9e0f7ca5.txt diff --git a/test/chunking-form/samples/resolve-file-url/_expected/es/assets/asset-solved-28a7ac89.txt b/test/chunking-form/samples/resolve-file-url/_expected/es/assets/asset-solved-230ecafd.txt similarity index 100% rename from test/chunking-form/samples/resolve-file-url/_expected/es/assets/asset-solved-28a7ac89.txt rename to test/chunking-form/samples/resolve-file-url/_expected/es/assets/asset-solved-230ecafd.txt diff --git a/test/chunking-form/samples/resolve-file-url/_expected/es/assets/asset-unresolved-8dcd7fca.txt b/test/chunking-form/samples/resolve-file-url/_expected/es/assets/asset-unresolved-f4c1e86c.txt similarity index 100% rename from test/chunking-form/samples/resolve-file-url/_expected/es/assets/asset-unresolved-8dcd7fca.txt rename to test/chunking-form/samples/resolve-file-url/_expected/es/assets/asset-unresolved-f4c1e86c.txt diff --git a/test/chunking-form/samples/resolve-file-url/_expected/es/main.js b/test/chunking-form/samples/resolve-file-url/_expected/es/main.js index 1f84c485bd4..787fa8158a2 100644 --- a/test/chunking-form/samples/resolve-file-url/_expected/es/main.js +++ b/test/chunking-form/samples/resolve-file-url/_expected/es/main.js @@ -1,7 +1,7 @@ const asset$1 = 'resolved'; const chunk$1 = 'resolved'; -const asset = new URL('assets/asset-unresolved-8dcd7fca.txt', import.meta.url).href; -const chunk = new URL('nested/chunk.js', import.meta.url).href; +const asset = new URL('assets/asset-unresolved-f4c1e86c.txt', import.meta.url).href; +const chunk = new URL('nested/chunk2.js', import.meta.url).href; -import('./nested/chunk2.js').then(result => console.log(result, chunk$1, chunk, asset$1, asset)); +import('./nested/chunk.js').then(result => console.log(result, chunk$1, chunk, asset$1, asset)); diff --git a/test/chunking-form/samples/resolve-file-url/_expected/es/nested/chunk.js b/test/chunking-form/samples/resolve-file-url/_expected/es/nested/chunk.js index 36b1d61dd25..a9081bb7a7a 100644 --- a/test/chunking-form/samples/resolve-file-url/_expected/es/nested/chunk.js +++ b/test/chunking-form/samples/resolve-file-url/_expected/es/nested/chunk.js @@ -1 +1,4 @@ -console.log('chunk'); +const asset = 'chunkId=nested/chunk.js:moduleId=solved:fileName=assets/asset-solved-230ecafd.txt:format=es:relativePath=../assets/asset-solved-230ecafd.txt:referenceId=6296c678'; +const chunk = 'chunkId=nested/chunk.js:moduleId=solved:fileName=nested/chunk2.js:format=es:relativePath=chunk2.js:referenceId=f6c25ae7'; + +export { asset, chunk }; diff --git a/test/chunking-form/samples/resolve-file-url/_expected/es/nested/chunk2.js b/test/chunking-form/samples/resolve-file-url/_expected/es/nested/chunk2.js index 295616b7273..36b1d61dd25 100644 --- a/test/chunking-form/samples/resolve-file-url/_expected/es/nested/chunk2.js +++ b/test/chunking-form/samples/resolve-file-url/_expected/es/nested/chunk2.js @@ -1,4 +1 @@ -const asset = 'chunkId=nested/chunk2.js:moduleId=solved:fileName=assets/asset-solved-28a7ac89.txt:format=es:relativePath=../assets/asset-solved-28a7ac89.txt:referenceId=6296c678'; -const chunk = 'chunkId=nested/chunk2.js:moduleId=solved:fileName=nested/chunk.js:format=es:relativePath=chunk.js:referenceId=f6c25ae7'; - -export { asset, chunk }; +console.log('chunk'); diff --git a/test/chunking-form/samples/resolve-file-url/_expected/system/assets/asset-resolved-8bd22e6e.txt b/test/chunking-form/samples/resolve-file-url/_expected/system/assets/asset-resolved-9e0f7ca5.txt similarity index 100% rename from test/chunking-form/samples/resolve-file-url/_expected/system/assets/asset-resolved-8bd22e6e.txt rename to test/chunking-form/samples/resolve-file-url/_expected/system/assets/asset-resolved-9e0f7ca5.txt diff --git a/test/chunking-form/samples/resolve-file-url/_expected/system/assets/asset-solved-28a7ac89.txt b/test/chunking-form/samples/resolve-file-url/_expected/system/assets/asset-solved-230ecafd.txt similarity index 100% rename from test/chunking-form/samples/resolve-file-url/_expected/system/assets/asset-solved-28a7ac89.txt rename to test/chunking-form/samples/resolve-file-url/_expected/system/assets/asset-solved-230ecafd.txt diff --git a/test/chunking-form/samples/resolve-file-url/_expected/system/assets/asset-unresolved-8dcd7fca.txt b/test/chunking-form/samples/resolve-file-url/_expected/system/assets/asset-unresolved-f4c1e86c.txt similarity index 100% rename from test/chunking-form/samples/resolve-file-url/_expected/system/assets/asset-unresolved-8dcd7fca.txt rename to test/chunking-form/samples/resolve-file-url/_expected/system/assets/asset-unresolved-f4c1e86c.txt diff --git a/test/chunking-form/samples/resolve-file-url/_expected/system/main.js b/test/chunking-form/samples/resolve-file-url/_expected/system/main.js index f837123459d..e8f41d38a17 100644 --- a/test/chunking-form/samples/resolve-file-url/_expected/system/main.js +++ b/test/chunking-form/samples/resolve-file-url/_expected/system/main.js @@ -6,10 +6,10 @@ System.register([], (function (exports, module) { const asset$1 = 'resolved'; const chunk$1 = 'resolved'; - const asset = new URL('assets/asset-unresolved-8dcd7fca.txt', module.meta.url).href; - const chunk = new URL('nested/chunk.js', module.meta.url).href; + const asset = new URL('assets/asset-unresolved-f4c1e86c.txt', module.meta.url).href; + const chunk = new URL('nested/chunk2.js', module.meta.url).href; - module.import('./nested/chunk2.js').then(result => console.log(result, chunk$1, chunk, asset$1, asset)); + module.import('./nested/chunk.js').then(result => console.log(result, chunk$1, chunk, asset$1, asset)); }) }; diff --git a/test/chunking-form/samples/resolve-file-url/_expected/system/nested/chunk.js b/test/chunking-form/samples/resolve-file-url/_expected/system/nested/chunk.js index 1443cae1e05..2565e1e8815 100644 --- a/test/chunking-form/samples/resolve-file-url/_expected/system/nested/chunk.js +++ b/test/chunking-form/samples/resolve-file-url/_expected/system/nested/chunk.js @@ -1,9 +1,10 @@ -System.register([], (function () { +System.register([], (function (exports, module) { 'use strict'; return { execute: (function () { - console.log('chunk'); + const asset = exports('asset', 'chunkId=nested/chunk.js:moduleId=solved:fileName=assets/asset-solved-230ecafd.txt:format=system:relativePath=../assets/asset-solved-230ecafd.txt:referenceId=6296c678'); + const chunk = exports('chunk', 'chunkId=nested/chunk.js:moduleId=solved:fileName=nested/chunk2.js:format=system:relativePath=chunk2.js:referenceId=f6c25ae7'); }) }; diff --git a/test/chunking-form/samples/resolve-file-url/_expected/system/nested/chunk2.js b/test/chunking-form/samples/resolve-file-url/_expected/system/nested/chunk2.js index b1818829873..1443cae1e05 100644 --- a/test/chunking-form/samples/resolve-file-url/_expected/system/nested/chunk2.js +++ b/test/chunking-form/samples/resolve-file-url/_expected/system/nested/chunk2.js @@ -1,10 +1,9 @@ -System.register([], (function (exports, module) { +System.register([], (function () { 'use strict'; return { execute: (function () { - const asset = exports('asset', 'chunkId=nested/chunk2.js:moduleId=solved:fileName=assets/asset-solved-28a7ac89.txt:format=system:relativePath=../assets/asset-solved-28a7ac89.txt:referenceId=6296c678'); - const chunk = exports('chunk', 'chunkId=nested/chunk2.js:moduleId=solved:fileName=nested/chunk.js:format=system:relativePath=chunk.js:referenceId=f6c25ae7'); + console.log('chunk'); }) }; diff --git a/test/cli/samples/code-splitting-named-default-inputs/_config.js b/test/cli/samples/code-splitting-named-default-inputs/_config.js index 28ac0795a3f..3c6ddea1237 100644 --- a/test/cli/samples/code-splitting-named-default-inputs/_config.js +++ b/test/cli/samples/code-splitting-named-default-inputs/_config.js @@ -8,13 +8,13 @@ module.exports = { assert.equal( code, '\n' + - `//→ entry1-b70571c1.js:\n` + + `//→ entry1-10873415.js:\n` + "console.log('main1');\n" + '\n' + - `//→ Entry 2-cc781491.js:\n` + + `//→ Entry 2-b2b9d0bf.js:\n` + "console.log('main2');\n" + '\n' + - `//→ main3-5e259623.js:\n` + + `//→ main3-064cd134.js:\n` + "console.log('main3');\n" ); } diff --git a/test/cli/samples/code-splitting-named-inputs/_config.js b/test/cli/samples/code-splitting-named-inputs/_config.js index 420bde6475a..8959d27273c 100644 --- a/test/cli/samples/code-splitting-named-inputs/_config.js +++ b/test/cli/samples/code-splitting-named-inputs/_config.js @@ -8,13 +8,13 @@ module.exports = { assert.equal( code, '\n' + - `//→ entry1-b70571c1.js:\n` + + `//→ entry1-10873415.js:\n` + "console.log('main1');\n" + '\n' + - `//→ Entry 2-cc781491.js:\n` + + `//→ Entry 2-b2b9d0bf.js:\n` + "console.log('main2');\n" + '\n' + - `//→ main3-5e259623.js:\n` + + `//→ main3-064cd134.js:\n` + "console.log('main3');\n" ); } diff --git a/test/cli/samples/stdout-code-splitting/_config.js b/test/cli/samples/stdout-code-splitting/_config.js index 20123fec988..b170cacb84f 100644 --- a/test/cli/samples/stdout-code-splitting/_config.js +++ b/test/cli/samples/stdout-code-splitting/_config.js @@ -20,7 +20,7 @@ module.exports = { `${COLOR}//→ main2.js:${STANDARD}\n` + "console.log('main2');\n" + '\n' + - `${COLOR}//→ assets/asset-74b448a5:${STANDARD}\n` + + `${COLOR}//→ assets/asset-185f8db3:${STANDARD}\n` + 'Hello' ); } diff --git a/test/file-hashes/samples/augment-chunk-hash/_config.js b/test/file-hashes/samples/augment-chunk-hash/_config.js index 06b9498eb86..b801e17ddd5 100644 --- a/test/file-hashes/samples/augment-chunk-hash/_config.js +++ b/test/file-hashes/samples/augment-chunk-hash/_config.js @@ -1,5 +1,6 @@ const augment1 = '/*foo*/'; const augment2 = '/*bar*/'; + module.exports = { description: 'augmentChunkHash updates hashes across all modules when returning something', options1: { diff --git a/test/file-hashes/samples/render-chunk-changes/_config.js b/test/file-hashes/samples/render-chunk-changes/_config.js new file mode 100644 index 00000000000..c4d17be937f --- /dev/null +++ b/test/file-hashes/samples/render-chunk-changes/_config.js @@ -0,0 +1,27 @@ +module.exports = { + description: 'reflects changes in renderChunk', + options1: { + input: 'main', + plugins: [ + { + renderChunk(code, chunk) { + if (chunk.name === 'main') { + return "console.log('first');" + code; + } + } + } + ] + }, + options2: { + input: 'main', + plugins: [ + { + renderChunk(code, chunk) { + if (chunk.name === 'main') { + return "console.log('second');" + code; + } + } + } + ] + } +}; diff --git a/test/file-hashes/samples/render-chunk-changes/main.js b/test/file-hashes/samples/render-chunk-changes/main.js new file mode 100644 index 00000000000..c0b933d7b56 --- /dev/null +++ b/test/file-hashes/samples/render-chunk-changes/main.js @@ -0,0 +1 @@ +console.log('main'); diff --git a/test/form/samples/addon-functions/_config.js b/test/form/samples/addon-functions/_config.js new file mode 100644 index 00000000000..97f80fdc2c8 --- /dev/null +++ b/test/form/samples/addon-functions/_config.js @@ -0,0 +1,96 @@ +const assert = require('assert'); +const { replaceDirInStringifiedObject } = require('../../../utils'); +const assertChunkData = chunk => + assert.strictEqual( + replaceDirInStringifiedObject({ ...chunk, fileName: undefined }, __dirname), + '{\n' + + ' "exports": [],\n' + + ' "facadeModuleId": "**/main.js",\n' + + ' "isDynamicEntry": false,\n' + + ' "isEntry": true,\n' + + ' "isImplicitEntry": false,\n' + + ' "moduleIds": [\n' + + ' "**/main.js"\n' + + ' ],\n' + + ' "name": "main",\n' + + ' "type": "chunk",\n' + + ' "dynamicImports": [],\n' + + ' "implicitlyLoadedBefore": [],\n' + + ' "importedBindings": {},\n' + + ' "imports": [],\n' + + ' "modules": {\n' + + ' "**/main.js": {\n' + + ' "code": "console.log(\'main\');",\n' + + ' "originalLength": 21,\n' + + ' "removedExports": [],\n' + + ' "renderedExports": [],\n' + + ' "renderedLength": 20\n' + + ' }\n' + + ' },\n' + + ' "referencedFiles": []\n' + + '}' + ); + +module.exports = { + description: 'provides module information when adding addons', + options: { + output: { + intro(chunk) { + assertChunkData(chunk); + return `/* intro-option ${chunk.fileName} */`; + }, + outro(chunk) { + assertChunkData(chunk); + return `/* outro-option ${chunk.fileName} */`; + }, + banner(chunk) { + assertChunkData(chunk); + return `/* banner-option ${chunk.fileName} */`; + }, + footer(chunk) { + assertChunkData(chunk); + return `/* footer-option ${chunk.fileName} */`; + } + }, + plugins: [ + { + name: 'first', + intro(chunk) { + assertChunkData(chunk); + return `/* intro-first ${chunk.fileName} */`; + }, + outro(chunk) { + assertChunkData(chunk); + return `/* outro-first ${chunk.fileName} */`; + }, + banner(chunk) { + assertChunkData(chunk); + return `/* banner-first ${chunk.fileName} */`; + }, + footer(chunk) { + assertChunkData(chunk); + return `/* footer-first ${chunk.fileName} */`; + } + }, + { + name: 'second', + intro(chunk) { + assertChunkData(chunk); + return `/* intro-second ${chunk.fileName} */`; + }, + outro(chunk) { + assertChunkData(chunk); + return `/* outro-second ${chunk.fileName} */`; + }, + banner(chunk) { + assertChunkData(chunk); + return `/* banner-second ${chunk.fileName} */`; + }, + footer(chunk) { + assertChunkData(chunk); + return `/* footer-second ${chunk.fileName} */`; + } + } + ] + } +}; diff --git a/test/form/samples/addon-functions/_expected/amd.js b/test/form/samples/addon-functions/_expected/amd.js new file mode 100644 index 00000000000..7de22f7a2f7 --- /dev/null +++ b/test/form/samples/addon-functions/_expected/amd.js @@ -0,0 +1,23 @@ +/* banner-option amd.js */ +/* banner-first amd.js */ +/* banner-second amd.js */ +define((function () { 'use strict'; + + /* intro-option amd.js */ + + /* intro-first amd.js */ + + /* intro-second amd.js */ + + console.log('main'); + + /* outro-option amd.js */ + + /* outro-first amd.js */ + + /* outro-second amd.js */ + +})); +/* footer-option amd.js */ +/* footer-first amd.js */ +/* footer-second amd.js */ diff --git a/test/form/samples/addon-functions/_expected/cjs.js b/test/form/samples/addon-functions/_expected/cjs.js new file mode 100644 index 00000000000..6d08b1eb5f6 --- /dev/null +++ b/test/form/samples/addon-functions/_expected/cjs.js @@ -0,0 +1,21 @@ +/* banner-option cjs.js */ +/* banner-first cjs.js */ +/* banner-second cjs.js */ +'use strict'; + +/* intro-option cjs.js */ + +/* intro-first cjs.js */ + +/* intro-second cjs.js */ + +console.log('main'); + +/* outro-option cjs.js */ + +/* outro-first cjs.js */ + +/* outro-second cjs.js */ +/* footer-option cjs.js */ +/* footer-first cjs.js */ +/* footer-second cjs.js */ diff --git a/test/form/samples/addon-functions/_expected/es.js b/test/form/samples/addon-functions/_expected/es.js new file mode 100644 index 00000000000..a8227dff141 --- /dev/null +++ b/test/form/samples/addon-functions/_expected/es.js @@ -0,0 +1,19 @@ +/* banner-option es.js */ +/* banner-first es.js */ +/* banner-second es.js */ +/* intro-option es.js */ + +/* intro-first es.js */ + +/* intro-second es.js */ + +console.log('main'); + +/* outro-option es.js */ + +/* outro-first es.js */ + +/* outro-second es.js */ +/* footer-option es.js */ +/* footer-first es.js */ +/* footer-second es.js */ diff --git a/test/form/samples/addon-functions/_expected/iife.js b/test/form/samples/addon-functions/_expected/iife.js new file mode 100644 index 00000000000..196271275c0 --- /dev/null +++ b/test/form/samples/addon-functions/_expected/iife.js @@ -0,0 +1,24 @@ +/* banner-option iife.js */ +/* banner-first iife.js */ +/* banner-second iife.js */ +(function () { + 'use strict'; + + /* intro-option iife.js */ + + /* intro-first iife.js */ + + /* intro-second iife.js */ + + console.log('main'); + + /* outro-option iife.js */ + + /* outro-first iife.js */ + + /* outro-second iife.js */ + +})(); +/* footer-option iife.js */ +/* footer-first iife.js */ +/* footer-second iife.js */ diff --git a/test/form/samples/addon-functions/_expected/system.js b/test/form/samples/addon-functions/_expected/system.js new file mode 100644 index 00000000000..60ec2175458 --- /dev/null +++ b/test/form/samples/addon-functions/_expected/system.js @@ -0,0 +1,28 @@ +/* banner-option system.js */ +/* banner-first system.js */ +/* banner-second system.js */ +System.register([], (function () { + 'use strict'; + return { + execute: (function () { + + /* intro-option system.js */ + + /* intro-first system.js */ + + /* intro-second system.js */ + + console.log('main'); + + /* outro-option system.js */ + + /* outro-first system.js */ + + /* outro-second system.js */ + + }) + }; +})); +/* footer-option system.js */ +/* footer-first system.js */ +/* footer-second system.js */ diff --git a/test/form/samples/addon-functions/_expected/umd.js b/test/form/samples/addon-functions/_expected/umd.js new file mode 100644 index 00000000000..9497d95f225 --- /dev/null +++ b/test/form/samples/addon-functions/_expected/umd.js @@ -0,0 +1,26 @@ +/* banner-option umd.js */ +/* banner-first umd.js */ +/* banner-second umd.js */ +(function (factory) { + typeof define === 'function' && define.amd ? define(factory) : + factory(); +})((function () { 'use strict'; + + /* intro-option umd.js */ + + /* intro-first umd.js */ + + /* intro-second umd.js */ + + console.log('main'); + + /* outro-option umd.js */ + + /* outro-first umd.js */ + + /* outro-second umd.js */ + +})); +/* footer-option umd.js */ +/* footer-first umd.js */ +/* footer-second umd.js */ diff --git a/test/form/samples/addon-functions/main.js b/test/form/samples/addon-functions/main.js new file mode 100644 index 00000000000..c0b933d7b56 --- /dev/null +++ b/test/form/samples/addon-functions/main.js @@ -0,0 +1 @@ +console.log('main'); diff --git a/test/form/samples/configure-file-url/_expected/amd.js b/test/form/samples/configure-file-url/_expected/amd.js index 2c00510ea0d..5b95fa904c2 100644 --- a/test/form/samples/configure-file-url/_expected/amd.js +++ b/test/form/samples/configure-file-url/_expected/amd.js @@ -1,10 +1,10 @@ define(['require'], (function (require) { 'use strict'; - var asset1 = 'chunkId=amd.js:moduleId=solved:fileName=assets/asset-solved-28a7ac89.txt:format=amd:relativePath=assets/asset-solved-28a7ac89.txt:referenceId=6296c678'; + var asset1 = 'chunkId=amd.js:moduleId=solved:fileName=assets/asset-solved-230ecafd.txt:format=amd:relativePath=assets/asset-solved-230ecafd.txt:referenceId=6296c678'; var asset2 = 'resolved'; - var asset3 = new URL(require.toUrl('./assets/asset-unresolved-8dcd7fca.txt'), document.baseURI).href; + var asset3 = new URL(require.toUrl('./assets/asset-unresolved-f4c1e86c.txt'), document.baseURI).href; console.log(asset1, asset2, asset3); diff --git a/test/form/samples/configure-file-url/_expected/assets/asset-resolved-8bd22e6e.txt b/test/form/samples/configure-file-url/_expected/assets/asset-resolved-9e0f7ca5.txt similarity index 100% rename from test/form/samples/configure-file-url/_expected/assets/asset-resolved-8bd22e6e.txt rename to test/form/samples/configure-file-url/_expected/assets/asset-resolved-9e0f7ca5.txt diff --git a/test/form/samples/configure-file-url/_expected/assets/asset-solved-28a7ac89.txt b/test/form/samples/configure-file-url/_expected/assets/asset-solved-230ecafd.txt similarity index 100% rename from test/form/samples/configure-file-url/_expected/assets/asset-solved-28a7ac89.txt rename to test/form/samples/configure-file-url/_expected/assets/asset-solved-230ecafd.txt diff --git a/test/form/samples/configure-file-url/_expected/assets/asset-unresolved-8dcd7fca.txt b/test/form/samples/configure-file-url/_expected/assets/asset-unresolved-f4c1e86c.txt similarity index 100% rename from test/form/samples/configure-file-url/_expected/assets/asset-unresolved-8dcd7fca.txt rename to test/form/samples/configure-file-url/_expected/assets/asset-unresolved-f4c1e86c.txt diff --git a/test/form/samples/configure-file-url/_expected/cjs.js b/test/form/samples/configure-file-url/_expected/cjs.js index 3f400f8f30d..28b247bc342 100644 --- a/test/form/samples/configure-file-url/_expected/cjs.js +++ b/test/form/samples/configure-file-url/_expected/cjs.js @@ -1,9 +1,9 @@ 'use strict'; -var asset1 = 'chunkId=cjs.js:moduleId=solved:fileName=assets/asset-solved-28a7ac89.txt:format=cjs:relativePath=assets/asset-solved-28a7ac89.txt:referenceId=6296c678'; +var asset1 = 'chunkId=cjs.js:moduleId=solved:fileName=assets/asset-solved-230ecafd.txt:format=cjs:relativePath=assets/asset-solved-230ecafd.txt:referenceId=6296c678'; var asset2 = 'resolved'; -var asset3 = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/asset-unresolved-8dcd7fca.txt').href : new URL('assets/asset-unresolved-8dcd7fca.txt', document.currentScript && document.currentScript.src || document.baseURI).href); +var asset3 = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/asset-unresolved-f4c1e86c.txt').href : new URL('assets/asset-unresolved-f4c1e86c.txt', document.currentScript && document.currentScript.src || document.baseURI).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 index 07d1b27b495..89945227ebc 100644 --- a/test/form/samples/configure-file-url/_expected/es.js +++ b/test/form/samples/configure-file-url/_expected/es.js @@ -1,7 +1,7 @@ -var asset1 = 'chunkId=es.js:moduleId=solved:fileName=assets/asset-solved-28a7ac89.txt:format=es:relativePath=assets/asset-solved-28a7ac89.txt:referenceId=6296c678'; +var asset1 = 'chunkId=es.js:moduleId=solved:fileName=assets/asset-solved-230ecafd.txt:format=es:relativePath=assets/asset-solved-230ecafd.txt:referenceId=6296c678'; var asset2 = 'resolved'; -var asset3 = new URL('assets/asset-unresolved-8dcd7fca.txt', import.meta.url).href; +var asset3 = new URL('assets/asset-unresolved-f4c1e86c.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 index a5870ddb682..66ea85781ef 100644 --- a/test/form/samples/configure-file-url/_expected/iife.js +++ b/test/form/samples/configure-file-url/_expected/iife.js @@ -1,11 +1,11 @@ (function () { 'use strict'; - var asset1 = 'chunkId=iife.js:moduleId=solved:fileName=assets/asset-solved-28a7ac89.txt:format=iife:relativePath=assets/asset-solved-28a7ac89.txt:referenceId=6296c678'; + var asset1 = 'chunkId=iife.js:moduleId=solved:fileName=assets/asset-solved-230ecafd.txt:format=iife:relativePath=assets/asset-solved-230ecafd.txt:referenceId=6296c678'; var asset2 = 'resolved'; - var asset3 = new URL('assets/asset-unresolved-8dcd7fca.txt', document.currentScript && document.currentScript.src || document.baseURI).href; + var asset3 = new URL('assets/asset-unresolved-f4c1e86c.txt', document.currentScript && document.currentScript.src || document.baseURI).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 index 6ed9c1c1323..83ada681a5b 100644 --- a/test/form/samples/configure-file-url/_expected/system.js +++ b/test/form/samples/configure-file-url/_expected/system.js @@ -3,11 +3,11 @@ System.register([], (function (exports, module) { return { execute: (function () { - var asset1 = 'chunkId=system.js:moduleId=solved:fileName=assets/asset-solved-28a7ac89.txt:format=system:relativePath=assets/asset-solved-28a7ac89.txt:referenceId=6296c678'; + var asset1 = 'chunkId=system.js:moduleId=solved:fileName=assets/asset-solved-230ecafd.txt:format=system:relativePath=assets/asset-solved-230ecafd.txt:referenceId=6296c678'; var asset2 = 'resolved'; - var asset3 = new URL('assets/asset-unresolved-8dcd7fca.txt', module.meta.url).href; + var asset3 = new URL('assets/asset-unresolved-f4c1e86c.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 index cc804e1ca7f..ac24d52850d 100644 --- a/test/form/samples/configure-file-url/_expected/umd.js +++ b/test/form/samples/configure-file-url/_expected/umd.js @@ -3,11 +3,11 @@ factory(); })((function () { 'use strict'; - var asset1 = 'chunkId=umd.js:moduleId=solved:fileName=assets/asset-solved-28a7ac89.txt:format=umd:relativePath=assets/asset-solved-28a7ac89.txt:referenceId=6296c678'; + var asset1 = 'chunkId=umd.js:moduleId=solved:fileName=assets/asset-solved-230ecafd.txt:format=umd:relativePath=assets/asset-solved-230ecafd.txt:referenceId=6296c678'; var asset2 = 'resolved'; - var asset3 = (typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/asset-unresolved-8dcd7fca.txt').href : new URL('assets/asset-unresolved-8dcd7fca.txt', typeof document === 'undefined' ? location.href : document.currentScript && document.currentScript.src || document.baseURI).href); + var asset3 = (typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/asset-unresolved-f4c1e86c.txt').href : new URL('assets/asset-unresolved-f4c1e86c.txt', typeof document === 'undefined' ? location.href : document.currentScript && document.currentScript.src || document.baseURI).href); console.log(asset1, asset2, asset3); diff --git a/test/form/samples/emit-asset-file/_config.js b/test/form/samples/emit-asset-file/_config.js index b4bbd8926d7..ea9534a9aef 100644 --- a/test/form/samples/emit-asset-file/_config.js +++ b/test/form/samples/emit-asset-file/_config.js @@ -23,9 +23,9 @@ module.exports = { generateBundle(options, outputBundle) { const keys = Object.keys(outputBundle); assert.strictEqual(keys.length, 2); - assert.strictEqual(keys[0], 'assets/logo-25585ac1.svg'); + assert.strictEqual(keys[0], 'assets/logo-a2a2cdc4.svg'); const asset = outputBundle[keys[0]]; - assert.strictEqual(asset.fileName, 'assets/logo-25585ac1.svg'); + assert.strictEqual(asset.fileName, 'assets/logo-a2a2cdc4.svg'); assert.strictEqual(asset.type, 'asset'); assert.ok( asset.source.equals(readFileSync(path.resolve(__dirname, 'logo.svg'))), diff --git a/test/form/samples/emit-asset-file/_expected/amd.js b/test/form/samples/emit-asset-file/_expected/amd.js index 0120fbb5f1c..ca2a1bdd557 100644 --- a/test/form/samples/emit-asset-file/_expected/amd.js +++ b/test/form/samples/emit-asset-file/_expected/amd.js @@ -1,6 +1,6 @@ define(['require'], (function (require) { 'use strict'; - var logo = new URL(require.toUrl('./assets/logo-25585ac1.svg'), document.baseURI).href; + var logo = new URL(require.toUrl('./assets/logo-a2a2cdc4.svg'), document.baseURI).href; function showImage(url) { console.log(url); diff --git a/test/form/samples/emit-asset-file/_expected/assets/logo-25585ac1.svg b/test/form/samples/emit-asset-file/_expected/assets/logo-a2a2cdc4.svg similarity index 100% rename from test/form/samples/emit-asset-file/_expected/assets/logo-25585ac1.svg rename to test/form/samples/emit-asset-file/_expected/assets/logo-a2a2cdc4.svg diff --git a/test/form/samples/emit-asset-file/_expected/cjs.js b/test/form/samples/emit-asset-file/_expected/cjs.js index f9a9dac3e1e..ae0b56a62c4 100644 --- a/test/form/samples/emit-asset-file/_expected/cjs.js +++ b/test/form/samples/emit-asset-file/_expected/cjs.js @@ -1,6 +1,6 @@ 'use strict'; -var logo = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/logo-25585ac1.svg').href : new URL('assets/logo-25585ac1.svg', document.currentScript && document.currentScript.src || document.baseURI).href); +var logo = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/logo-a2a2cdc4.svg').href : new URL('assets/logo-a2a2cdc4.svg', document.currentScript && document.currentScript.src || document.baseURI).href); function showImage(url) { console.log(url); diff --git a/test/form/samples/emit-asset-file/_expected/es.js b/test/form/samples/emit-asset-file/_expected/es.js index d100d42e367..c29240a6acf 100644 --- a/test/form/samples/emit-asset-file/_expected/es.js +++ b/test/form/samples/emit-asset-file/_expected/es.js @@ -1,4 +1,4 @@ -var logo = new URL('assets/logo-25585ac1.svg', import.meta.url).href; +var logo = new URL('assets/logo-a2a2cdc4.svg', import.meta.url).href; function showImage(url) { console.log(url); diff --git a/test/form/samples/emit-asset-file/_expected/iife.js b/test/form/samples/emit-asset-file/_expected/iife.js index 881dc9e042f..f28f46dbc3d 100644 --- a/test/form/samples/emit-asset-file/_expected/iife.js +++ b/test/form/samples/emit-asset-file/_expected/iife.js @@ -1,7 +1,7 @@ (function () { 'use strict'; - var logo = new URL('assets/logo-25585ac1.svg', document.currentScript && document.currentScript.src || document.baseURI).href; + var logo = new URL('assets/logo-a2a2cdc4.svg', document.currentScript && document.currentScript.src || document.baseURI).href; function showImage(url) { console.log(url); diff --git a/test/form/samples/emit-asset-file/_expected/system.js b/test/form/samples/emit-asset-file/_expected/system.js index cbef4b76bfd..d332088ba81 100644 --- a/test/form/samples/emit-asset-file/_expected/system.js +++ b/test/form/samples/emit-asset-file/_expected/system.js @@ -3,7 +3,7 @@ System.register([], (function (exports, module) { return { execute: (function () { - var logo = new URL('assets/logo-25585ac1.svg', module.meta.url).href; + var logo = new URL('assets/logo-a2a2cdc4.svg', module.meta.url).href; function showImage(url) { console.log(url); diff --git a/test/form/samples/emit-asset-file/_expected/umd.js b/test/form/samples/emit-asset-file/_expected/umd.js index b37ed465b1a..cd53dda9832 100644 --- a/test/form/samples/emit-asset-file/_expected/umd.js +++ b/test/form/samples/emit-asset-file/_expected/umd.js @@ -3,7 +3,7 @@ factory(); })((function () { 'use strict'; - var logo = (typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/logo-25585ac1.svg').href : new URL('assets/logo-25585ac1.svg', typeof document === 'undefined' ? location.href : document.currentScript && document.currentScript.src || document.baseURI).href); + var logo = (typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/logo-a2a2cdc4.svg').href : new URL('assets/logo-a2a2cdc4.svg', typeof document === 'undefined' ? location.href : document.currentScript && document.currentScript.src || document.baseURI).href); function showImage(url) { console.log(url); diff --git a/test/form/samples/emit-file-tree-shaken-access/_expected/assets/logo-25585ac1.svg b/test/form/samples/emit-file-tree-shaken-access/_expected/assets/logo-a2a2cdc4.svg similarity index 100% rename from test/form/samples/emit-file-tree-shaken-access/_expected/assets/logo-25585ac1.svg rename to test/form/samples/emit-file-tree-shaken-access/_expected/assets/logo-a2a2cdc4.svg diff --git a/test/form/samples/emit-uint8array-no-buffer/_expected/amd.js b/test/form/samples/emit-uint8array-no-buffer/_expected/amd.js index 95d0e337739..87efea4471d 100644 --- a/test/form/samples/emit-uint8array-no-buffer/_expected/amd.js +++ b/test/form/samples/emit-uint8array-no-buffer/_expected/amd.js @@ -1,14 +1,14 @@ define(['require'], (function (require) { 'use strict'; - var asset1a = new URL(require.toUrl('./assets/asset-dc5cb674'), document.baseURI).href; + var asset1a = new URL(require.toUrl('./assets/asset-8e3dd2ea'), document.baseURI).href; - var asset1b = new URL(require.toUrl('./assets/asset-dc5cb674'), document.baseURI).href; + var asset1b = new URL(require.toUrl('./assets/asset-8e3dd2ea'), document.baseURI).href; - var asset2a = new URL(require.toUrl('./assets/asset-52cbd095'), document.baseURI).href; + var asset2a = new URL(require.toUrl('./assets/asset-75590fc1'), document.baseURI).href; - var asset2b = new URL(require.toUrl('./assets/asset-52cbd095'), document.baseURI).href; + var asset2b = new URL(require.toUrl('./assets/asset-75590fc1'), document.baseURI).href; - var asset99a = new URL(require.toUrl('./assets/asset-c568a840'), document.baseURI).href; + var asset99a = new URL(require.toUrl('./assets/asset-60cc5dc9'), document.baseURI).href; console.log(asset1a, asset1b, asset2a, asset2b, asset99a); diff --git a/test/form/samples/emit-uint8array-no-buffer/_expected/assets/asset-c568a840 b/test/form/samples/emit-uint8array-no-buffer/_expected/assets/asset-60cc5dc9 similarity index 100% rename from test/form/samples/emit-uint8array-no-buffer/_expected/assets/asset-c568a840 rename to test/form/samples/emit-uint8array-no-buffer/_expected/assets/asset-60cc5dc9 diff --git a/test/form/samples/emit-uint8array-no-buffer/_expected/assets/asset-52cbd095 b/test/form/samples/emit-uint8array-no-buffer/_expected/assets/asset-75590fc1 similarity index 100% rename from test/form/samples/emit-uint8array-no-buffer/_expected/assets/asset-52cbd095 rename to test/form/samples/emit-uint8array-no-buffer/_expected/assets/asset-75590fc1 diff --git a/test/form/samples/emit-uint8array-no-buffer/_expected/assets/asset-dc5cb674 b/test/form/samples/emit-uint8array-no-buffer/_expected/assets/asset-8e3dd2ea similarity index 100% rename from test/form/samples/emit-uint8array-no-buffer/_expected/assets/asset-dc5cb674 rename to test/form/samples/emit-uint8array-no-buffer/_expected/assets/asset-8e3dd2ea diff --git a/test/form/samples/emit-uint8array-no-buffer/_expected/cjs.js b/test/form/samples/emit-uint8array-no-buffer/_expected/cjs.js index 52e66b16df3..083e9204889 100644 --- a/test/form/samples/emit-uint8array-no-buffer/_expected/cjs.js +++ b/test/form/samples/emit-uint8array-no-buffer/_expected/cjs.js @@ -1,13 +1,13 @@ 'use strict'; -var asset1a = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/asset-dc5cb674').href : new URL('assets/asset-dc5cb674', document.currentScript && document.currentScript.src || document.baseURI).href); +var asset1a = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/asset-8e3dd2ea').href : new URL('assets/asset-8e3dd2ea', document.currentScript && document.currentScript.src || document.baseURI).href); -var asset1b = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/asset-dc5cb674').href : new URL('assets/asset-dc5cb674', document.currentScript && document.currentScript.src || document.baseURI).href); +var asset1b = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/asset-8e3dd2ea').href : new URL('assets/asset-8e3dd2ea', document.currentScript && document.currentScript.src || document.baseURI).href); -var asset2a = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/asset-52cbd095').href : new URL('assets/asset-52cbd095', document.currentScript && document.currentScript.src || document.baseURI).href); +var asset2a = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/asset-75590fc1').href : new URL('assets/asset-75590fc1', document.currentScript && document.currentScript.src || document.baseURI).href); -var asset2b = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/asset-52cbd095').href : new URL('assets/asset-52cbd095', document.currentScript && document.currentScript.src || document.baseURI).href); +var asset2b = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/asset-75590fc1').href : new URL('assets/asset-75590fc1', document.currentScript && document.currentScript.src || document.baseURI).href); -var asset99a = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/asset-c568a840').href : new URL('assets/asset-c568a840', document.currentScript && document.currentScript.src || document.baseURI).href); +var asset99a = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/asset-60cc5dc9').href : new URL('assets/asset-60cc5dc9', document.currentScript && document.currentScript.src || document.baseURI).href); console.log(asset1a, asset1b, asset2a, asset2b, asset99a); diff --git a/test/form/samples/emit-uint8array-no-buffer/_expected/es.js b/test/form/samples/emit-uint8array-no-buffer/_expected/es.js index 8853325ff06..f61d2fab4e9 100644 --- a/test/form/samples/emit-uint8array-no-buffer/_expected/es.js +++ b/test/form/samples/emit-uint8array-no-buffer/_expected/es.js @@ -1,11 +1,11 @@ -var asset1a = new URL('assets/asset-dc5cb674', import.meta.url).href; +var asset1a = new URL('assets/asset-8e3dd2ea', import.meta.url).href; -var asset1b = new URL('assets/asset-dc5cb674', import.meta.url).href; +var asset1b = new URL('assets/asset-8e3dd2ea', import.meta.url).href; -var asset2a = new URL('assets/asset-52cbd095', import.meta.url).href; +var asset2a = new URL('assets/asset-75590fc1', import.meta.url).href; -var asset2b = new URL('assets/asset-52cbd095', import.meta.url).href; +var asset2b = new URL('assets/asset-75590fc1', import.meta.url).href; -var asset99a = new URL('assets/asset-c568a840', import.meta.url).href; +var asset99a = new URL('assets/asset-60cc5dc9', import.meta.url).href; console.log(asset1a, asset1b, asset2a, asset2b, asset99a); diff --git a/test/form/samples/emit-uint8array-no-buffer/_expected/iife.js b/test/form/samples/emit-uint8array-no-buffer/_expected/iife.js index cb0248b3e86..7735d95046d 100644 --- a/test/form/samples/emit-uint8array-no-buffer/_expected/iife.js +++ b/test/form/samples/emit-uint8array-no-buffer/_expected/iife.js @@ -1,15 +1,15 @@ (function () { 'use strict'; - var asset1a = new URL('assets/asset-dc5cb674', document.currentScript && document.currentScript.src || document.baseURI).href; + var asset1a = new URL('assets/asset-8e3dd2ea', document.currentScript && document.currentScript.src || document.baseURI).href; - var asset1b = new URL('assets/asset-dc5cb674', document.currentScript && document.currentScript.src || document.baseURI).href; + var asset1b = new URL('assets/asset-8e3dd2ea', document.currentScript && document.currentScript.src || document.baseURI).href; - var asset2a = new URL('assets/asset-52cbd095', document.currentScript && document.currentScript.src || document.baseURI).href; + var asset2a = new URL('assets/asset-75590fc1', document.currentScript && document.currentScript.src || document.baseURI).href; - var asset2b = new URL('assets/asset-52cbd095', document.currentScript && document.currentScript.src || document.baseURI).href; + var asset2b = new URL('assets/asset-75590fc1', document.currentScript && document.currentScript.src || document.baseURI).href; - var asset99a = new URL('assets/asset-c568a840', document.currentScript && document.currentScript.src || document.baseURI).href; + var asset99a = new URL('assets/asset-60cc5dc9', document.currentScript && document.currentScript.src || document.baseURI).href; console.log(asset1a, asset1b, asset2a, asset2b, asset99a); diff --git a/test/form/samples/emit-uint8array-no-buffer/_expected/system.js b/test/form/samples/emit-uint8array-no-buffer/_expected/system.js index 97d709cbe52..dc3b8c0c825 100644 --- a/test/form/samples/emit-uint8array-no-buffer/_expected/system.js +++ b/test/form/samples/emit-uint8array-no-buffer/_expected/system.js @@ -3,15 +3,15 @@ System.register([], (function (exports, module) { return { execute: (function () { - var asset1a = new URL('assets/asset-dc5cb674', module.meta.url).href; + var asset1a = new URL('assets/asset-8e3dd2ea', module.meta.url).href; - var asset1b = new URL('assets/asset-dc5cb674', module.meta.url).href; + var asset1b = new URL('assets/asset-8e3dd2ea', module.meta.url).href; - var asset2a = new URL('assets/asset-52cbd095', module.meta.url).href; + var asset2a = new URL('assets/asset-75590fc1', module.meta.url).href; - var asset2b = new URL('assets/asset-52cbd095', module.meta.url).href; + var asset2b = new URL('assets/asset-75590fc1', module.meta.url).href; - var asset99a = new URL('assets/asset-c568a840', module.meta.url).href; + var asset99a = new URL('assets/asset-60cc5dc9', module.meta.url).href; console.log(asset1a, asset1b, asset2a, asset2b, asset99a); diff --git a/test/form/samples/emit-uint8array-no-buffer/_expected/umd.js b/test/form/samples/emit-uint8array-no-buffer/_expected/umd.js index 459750c15a9..18c43ff8451 100644 --- a/test/form/samples/emit-uint8array-no-buffer/_expected/umd.js +++ b/test/form/samples/emit-uint8array-no-buffer/_expected/umd.js @@ -3,15 +3,15 @@ factory(); })((function () { 'use strict'; - var asset1a = (typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/asset-dc5cb674').href : new URL('assets/asset-dc5cb674', typeof document === 'undefined' ? location.href : document.currentScript && document.currentScript.src || document.baseURI).href); + var asset1a = (typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/asset-8e3dd2ea').href : new URL('assets/asset-8e3dd2ea', typeof document === 'undefined' ? location.href : document.currentScript && document.currentScript.src || document.baseURI).href); - var asset1b = (typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/asset-dc5cb674').href : new URL('assets/asset-dc5cb674', typeof document === 'undefined' ? location.href : document.currentScript && document.currentScript.src || document.baseURI).href); + var asset1b = (typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/asset-8e3dd2ea').href : new URL('assets/asset-8e3dd2ea', typeof document === 'undefined' ? location.href : document.currentScript && document.currentScript.src || document.baseURI).href); - var asset2a = (typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/asset-52cbd095').href : new URL('assets/asset-52cbd095', typeof document === 'undefined' ? location.href : document.currentScript && document.currentScript.src || document.baseURI).href); + var asset2a = (typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/asset-75590fc1').href : new URL('assets/asset-75590fc1', typeof document === 'undefined' ? location.href : document.currentScript && document.currentScript.src || document.baseURI).href); - var asset2b = (typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/asset-52cbd095').href : new URL('assets/asset-52cbd095', typeof document === 'undefined' ? location.href : document.currentScript && document.currentScript.src || document.baseURI).href); + var asset2b = (typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/asset-75590fc1').href : new URL('assets/asset-75590fc1', typeof document === 'undefined' ? location.href : document.currentScript && document.currentScript.src || document.baseURI).href); - var asset99a = (typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/asset-c568a840').href : new URL('assets/asset-c568a840', typeof document === 'undefined' ? location.href : document.currentScript && document.currentScript.src || document.baseURI).href); + var asset99a = (typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/assets/asset-60cc5dc9').href : new URL('assets/asset-60cc5dc9', typeof document === 'undefined' ? location.href : document.currentScript && document.currentScript.src || document.baseURI).href); console.log(asset1a, asset1b, asset2a, asset2b, asset99a); diff --git a/test/function/samples/emit-file/asset-source-missing3/_config.js b/test/function/samples/emit-file/asset-source-missing3/_config.js index 85e314793fe..202b2e01c59 100644 --- a/test/function/samples/emit-file/asset-source-missing3/_config.js +++ b/test/function/samples/emit-file/asset-source-missing3/_config.js @@ -13,7 +13,7 @@ module.exports = { code: 'PLUGIN_ERROR', hook: 'buildStart', message: - 'Plugin error - Unable to get file name for asset "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. If you reference assets via import.meta.ROLLUP_FILE_URL_, you need to either have set their source after "renderStart" or need to provide an explicit "fileName" when emitting them.', plugin: 'test-plugin', pluginCode: 'ASSET_NOT_FINALISED' } diff --git a/test/function/samples/emit-file/asset-source-missing4/_config.js b/test/function/samples/emit-file/asset-source-missing4/_config.js index a61bd81012d..2ff72ef342b 100644 --- a/test/function/samples/emit-file/asset-source-missing4/_config.js +++ b/test/function/samples/emit-file/asset-source-missing4/_config.js @@ -13,7 +13,7 @@ module.exports = { code: 'PLUGIN_ERROR', hook: 'buildStart', message: - 'Plugin error - Unable to get file name for asset "d59386e0". Ensure that the source is set and that generate is called first.', + 'Plugin error - Unable to get file name for asset "d59386e0". Ensure that the source is set and that generate is called first. If you reference assets via import.meta.ROLLUP_FILE_URL_, you need to either have set their source after "renderStart" or need to provide an explicit "fileName" when emitting them.', plugin: 'test-plugin', pluginCode: 'ASSET_NOT_FINALISED' } diff --git a/test/function/samples/emit-file/asset-source-missing5/_config.js b/test/function/samples/emit-file/asset-source-missing5/_config.js index 7ba7af1ee9a..54b254be27f 100644 --- a/test/function/samples/emit-file/asset-source-missing5/_config.js +++ b/test/function/samples/emit-file/asset-source-missing5/_config.js @@ -14,6 +14,6 @@ module.exports = { generateError: { code: 'ASSET_NOT_FINALISED', message: - 'Plugin error - Unable to get file name for asset "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. If you reference assets via import.meta.ROLLUP_FILE_URL_, you need to either have set their source after "renderStart" or need to provide an explicit "fileName" when emitting them.' } }; diff --git a/test/function/samples/emit-file/chunk-filename-not-available-buildEnd/_config.js b/test/function/samples/emit-file/chunk-filename-not-available-buildEnd/_config.js index 95688f451a8..dd470ea74cd 100644 --- a/test/function/samples/emit-file/chunk-filename-not-available-buildEnd/_config.js +++ b/test/function/samples/emit-file/chunk-filename-not-available-buildEnd/_config.js @@ -18,7 +18,7 @@ module.exports = { code: 'PLUGIN_ERROR', hook: 'buildEnd', message: - 'Plugin error - Unable to get file name for chunk "chunk.js". Ensure that generate is called first.', + 'Plugin error - Unable to get file name for emitted chunk "chunk.js". You can only get file names once chunks have been generated after the "renderStart" hook.', plugin: 'test-plugin', pluginCode: 'CHUNK_NOT_GENERATED' } diff --git a/test/function/samples/emit-file/chunk-filename-not-available-renderStart/_config.js b/test/function/samples/emit-file/chunk-filename-not-available-renderStart/_config.js index 8a35d9cfc2e..86e620e2fd5 100644 --- a/test/function/samples/emit-file/chunk-filename-not-available-renderStart/_config.js +++ b/test/function/samples/emit-file/chunk-filename-not-available-renderStart/_config.js @@ -18,7 +18,7 @@ module.exports = { code: 'PLUGIN_ERROR', hook: 'renderStart', message: - 'Plugin error - Unable to get file name for chunk "chunk.js". Ensure that generate is called first.', + 'Plugin error - Unable to get file name for emitted chunk "chunk.js". You can only get file names once chunks have been generated after the "renderStart" hook.', plugin: 'test-plugin', pluginCode: 'CHUNK_NOT_GENERATED' } diff --git a/test/function/samples/emit-file/chunk-filename-not-available/_config.js b/test/function/samples/emit-file/chunk-filename-not-available/_config.js index 2575784f8d7..b56bd15667c 100644 --- a/test/function/samples/emit-file/chunk-filename-not-available/_config.js +++ b/test/function/samples/emit-file/chunk-filename-not-available/_config.js @@ -14,7 +14,7 @@ module.exports = { code: 'PLUGIN_ERROR', hook: 'buildStart', message: - 'Plugin error - Unable to get file name for chunk "chunk.js". Ensure that generate is called first.', + 'Plugin error - Unable to get file name for emitted chunk "chunk.js". You can only get file names once chunks have been generated after the "renderStart" hook.', plugin: 'test-plugin', pluginCode: 'CHUNK_NOT_GENERATED' } diff --git a/test/function/samples/hashing/length-at-non-hash/_config.js b/test/function/samples/hashing/length-at-non-hash/_config.js new file mode 100644 index 00000000000..be57051eb69 --- /dev/null +++ b/test/function/samples/hashing/length-at-non-hash/_config.js @@ -0,0 +1,8 @@ +module.exports = { + description: 'throws when configuring a length for placeholder other than "hash"', + options: { output: { chunkFileNames: '[name:3].js' } }, + generateError: { + code: 'VALIDATION_ERROR', + message: '"[name:3]" is not a valid placeholder in the "output.chunkFileNames" pattern.' + } +}; diff --git a/test/function/samples/hashing/length-at-non-hash/foo.js b/test/function/samples/hashing/length-at-non-hash/foo.js new file mode 100644 index 00000000000..5f26d709a6b --- /dev/null +++ b/test/function/samples/hashing/length-at-non-hash/foo.js @@ -0,0 +1 @@ +throw new Error('should not be executed'); diff --git a/test/function/samples/hashing/length-at-non-hash/main.js b/test/function/samples/hashing/length-at-non-hash/main.js new file mode 100644 index 00000000000..bbe4a5cc219 --- /dev/null +++ b/test/function/samples/hashing/length-at-non-hash/main.js @@ -0,0 +1 @@ +import('./foo.js'); diff --git a/test/function/samples/hashing/maximum-hash-size/_config.js b/test/function/samples/hashing/maximum-hash-size/_config.js new file mode 100644 index 00000000000..4818302d041 --- /dev/null +++ b/test/function/samples/hashing/maximum-hash-size/_config.js @@ -0,0 +1,9 @@ +module.exports = { + description: 'throws when the maximum hash size is exceeded', + options: { output: { chunkFileNames: '[hash:65].js' } }, + generateError: { + code: 'VALIDATION_ERROR', + message: + 'Hashes cannot be longer than 64 characters, received 65. Check the "output.chunkFileNames" option.' + } +}; diff --git a/test/function/samples/hashing/maximum-hash-size/foo.js b/test/function/samples/hashing/maximum-hash-size/foo.js new file mode 100644 index 00000000000..5f26d709a6b --- /dev/null +++ b/test/function/samples/hashing/maximum-hash-size/foo.js @@ -0,0 +1 @@ +throw new Error('should not be executed'); diff --git a/test/function/samples/hashing/maximum-hash-size/main.js b/test/function/samples/hashing/maximum-hash-size/main.js new file mode 100644 index 00000000000..bbe4a5cc219 --- /dev/null +++ b/test/function/samples/hashing/maximum-hash-size/main.js @@ -0,0 +1 @@ +import('./foo.js'); diff --git a/test/function/samples/hashing/minimum-hash-size/_config.js b/test/function/samples/hashing/minimum-hash-size/_config.js new file mode 100644 index 00000000000..3058b420ce9 --- /dev/null +++ b/test/function/samples/hashing/minimum-hash-size/_config.js @@ -0,0 +1,9 @@ +module.exports = { + description: 'throws when the maximum hash size is exceeded', + options: { output: { chunkFileNames: '[hash:3].js' } }, + generateError: { + code: 'VALIDATION_ERROR', + message: + 'To generate hashes for this number of chunks (currently 1), you need a minimum hash size of 5, received 3. Check the "output.chunkFileNames" option.' + } +}; diff --git a/test/function/samples/hashing/minimum-hash-size/foo.js b/test/function/samples/hashing/minimum-hash-size/foo.js new file mode 100644 index 00000000000..5f26d709a6b --- /dev/null +++ b/test/function/samples/hashing/minimum-hash-size/foo.js @@ -0,0 +1 @@ +throw new Error('should not be executed'); diff --git a/test/function/samples/hashing/minimum-hash-size/main.js b/test/function/samples/hashing/minimum-hash-size/main.js new file mode 100644 index 00000000000..bbe4a5cc219 --- /dev/null +++ b/test/function/samples/hashing/minimum-hash-size/main.js @@ -0,0 +1 @@ +import('./foo.js'); diff --git a/test/function/samples/invalid-pattern-replacement/_config.js b/test/function/samples/invalid-pattern-replacement/_config.js index e02a3b56d35..09ec57507ca 100644 --- a/test/function/samples/invalid-pattern-replacement/_config.js +++ b/test/function/samples/invalid-pattern-replacement/_config.js @@ -5,6 +5,6 @@ module.exports = { }, generateError: { code: 'VALIDATION_ERROR', - message: '"[invalid]" is not a valid placeholder in "output.entryFileNames" pattern.' + message: '"[invalid]" is not a valid placeholder in the "output.entryFileNames" pattern.' } }; diff --git a/test/hooks/index.js b/test/hooks/index.js index a9018215bd9..498542a155f 100644 --- a/test/hooks/index.js +++ b/test/hooks/index.js @@ -168,9 +168,9 @@ describe('hooks', () => { .then(({ output }) => { assert.strictEqual( output[0].code, - `var input = new URL('chunk-928cb70b.js', import.meta.url).href;\n\nexport { input as default };\n` + `var input = new URL('chunk-f0e7d366.js', import.meta.url).href;\n\nexport { input as default };\n` ); - assert.strictEqual(output[1].fileName, 'chunk-928cb70b.js'); + assert.strictEqual(output[1].fileName, 'chunk-f0e7d366.js'); assert.strictEqual(output[1].code, `console.log('chunk');\n`); return rollup.rollup({ @@ -193,9 +193,9 @@ describe('hooks', () => { .then(({ output }) => { assert.strictEqual( output[0].code, - `var input = new URL('chunk-928cb70b.js', import.meta.url).href;\n\nexport { input as default };\n` + `var input = new URL('chunk-f0e7d366.js', import.meta.url).href;\n\nexport { input as default };\n` ); - assert.strictEqual(output[1].fileName, 'chunk-928cb70b.js'); + assert.strictEqual(output[1].fileName, 'chunk-f0e7d366.js'); assert.strictEqual(output[1].code, `console.log('chunk');\n`); return rollup.rollup({ @@ -215,9 +215,9 @@ describe('hooks', () => { .then(({ output }) => { assert.strictEqual( output[0].code, - `var input = new URL('chunk-928cb70b.js', import.meta.url).href;\n\nexport { input as default };\n` + `var input = new URL('chunk-f0e7d366.js', import.meta.url).href;\n\nexport { input as default };\n` ); - assert.strictEqual(output[1].fileName, 'chunk-928cb70b.js'); + assert.strictEqual(output[1].fileName, 'chunk-f0e7d366.js'); assert.strictEqual(output[1].code, `console.log('chunk');\n`); }); }); @@ -276,9 +276,9 @@ describe('hooks', () => { .then(({ output }) => { assert.strictEqual( output[0].code, - `var input = new URL('assets/test-0a676135.ext', import.meta.url).href;\n\nexport { input as default };\n` + `var input = new URL('assets/test-b94d27b9.ext', import.meta.url).href;\n\nexport { input as default };\n` ); - assert.strictEqual(output[1].fileName, 'assets/test-0a676135.ext'); + assert.strictEqual(output[1].fileName, 'assets/test-b94d27b9.ext'); assert.strictEqual(output[1].source, 'hello world'); return rollup.rollup({ @@ -301,9 +301,9 @@ describe('hooks', () => { .then(({ output }) => { assert.strictEqual( output[0].code, - `var input = new URL('assets/test-0a676135.ext', import.meta.url).href;\n\nexport { input as default };\n` + `var input = new URL('assets/test-b94d27b9.ext', import.meta.url).href;\n\nexport { input as default };\n` ); - assert.strictEqual(output[1].fileName, 'assets/test-0a676135.ext'); + assert.strictEqual(output[1].fileName, 'assets/test-b94d27b9.ext'); assert.strictEqual(output[1].source, 'hello world'); return rollup.rollup({ @@ -323,9 +323,9 @@ describe('hooks', () => { .then(({ output }) => { assert.strictEqual( output[0].code, - `var input = new URL('assets/test-0a676135.ext', import.meta.url).href;\n\nexport { input as default };\n` + `var input = new URL('assets/test-b94d27b9.ext', import.meta.url).href;\n\nexport { input as default };\n` ); - assert.strictEqual(output[1].fileName, 'assets/test-0a676135.ext'); + assert.strictEqual(output[1].fileName, 'assets/test-b94d27b9.ext'); assert.strictEqual(output[1].source, 'hello world'); }); }); @@ -371,10 +371,10 @@ describe('hooks', () => { assert.strictEqual( output[0].code, `console.log('imported');\n\n` + - `var input = new URL('assets/test-09aeb845.ext', import.meta.url).href;\n\n` + + `var input = new URL('assets/test-7d48a582.ext', import.meta.url).href;\n\n` + `export { input as default };\n` ); - assert.strictEqual(output[1].fileName, 'assets/test-09aeb845.ext'); + assert.strictEqual(output[1].fileName, 'assets/test-7d48a582.ext'); assert.strictEqual(output[1].source, 'first run'); return rollup.rollup({ @@ -404,10 +404,10 @@ describe('hooks', () => { assert.strictEqual( output[0].code, `console.log('imported');\n\n` + - `var input = new URL('assets/test-ce5fc71b.ext', import.meta.url).href;\n\n` + + `var input = new URL('assets/test-791d43e2.ext', import.meta.url).href;\n\n` + `export { input as default };\n` ); - assert.strictEqual(output[1].fileName, 'assets/test-ce5fc71b.ext'); + assert.strictEqual(output[1].fileName, 'assets/test-791d43e2.ext'); assert.strictEqual(output[1].source, 'second run'); }); }); @@ -442,11 +442,11 @@ describe('hooks', () => { .then(({ output }) => { assert.strictEqual( output[0].code, - `var input = new URL('assets/test-0a676135.ext', import.meta.url).href;\n\nexport { input as default };\n` + `var input = new URL('assets/test-b94d27b9.ext', import.meta.url).href;\n\nexport { input as default };\n` ); - assert.strictEqual(output[1].fileName, 'assets/test-0a676135.ext'); + assert.strictEqual(output[1].fileName, 'assets/test-b94d27b9.ext'); assert.strictEqual(output[1].source, 'hello world'); - assert.strictEqual(output[1].fileName, 'assets/test-0a676135.ext'); + assert.strictEqual(output[1].fileName, 'assets/test-b94d27b9.ext'); assert.strictEqual(output[1].source, 'hello world'); return rollup.rollup({ diff --git a/test/misc/bundle-information.js b/test/misc/bundle-information.js index 69c24e226ce..d003f5491ca 100644 --- a/test/misc/bundle-information.js +++ b/test/misc/bundle-information.js @@ -28,14 +28,14 @@ describe('The bundle object', () => { .then(({ output }) => { assert.deepEqual( output.map(chunk => chunk.fileName), - ['input1-ff0de9c1.js', 'input2-28dc81ee.js', 'generated-shared-c4fdd061.js'], + ['input1-7af41723.js', 'input2-95f92690.js', 'generated-shared-4eca6591.js'], 'fileName' ); assert.deepEqual( output.map(chunk => chunk.code), [ - `import { u as used, s as shared } from './generated-shared-c4fdd061.js';\n\nconsole.log("input1", used, shared);const out = true;\n\nexport { out };\n`, - `import './generated-shared-c4fdd061.js';\n\nconsole.log("input2");var input2 = 42;\n\nexport { input2 as default };\n`, + `import { u as used, s as shared } from './generated-shared-4eca6591.js';\n\nconsole.log("input1", used, shared);const out = true;\n\nexport { out };\n`, + `import './generated-shared-4eca6591.js';\n\nconsole.log("input2");var input2 = 42;\n\nexport { input2 as default };\n`, `console.log("shared");const used = "used"; var shared = "stuff";\n\nexport { shared as s, used as u };\n` ], 'code' @@ -62,14 +62,14 @@ describe('The bundle object', () => { ); assert.deepEqual( output.map(chunk => chunk.imports), - [['generated-shared-c4fdd061.js'], ['generated-shared-c4fdd061.js'], []], + [['generated-shared-4eca6591.js'], ['generated-shared-4eca6591.js'], []], 'imports' ); assert.deepEqual( output.map(chunk => chunk.importedBindings), [ - { 'generated-shared-c4fdd061.js': ['u', 's'] }, - { 'generated-shared-c4fdd061.js': [] }, + { 'generated-shared-4eca6591.js': ['u', 's'] }, + { 'generated-shared-4eca6591.js': [] }, {} ], 'importedBindings' @@ -483,8 +483,8 @@ describe('The bundle object', () => { [ '_virtual/input.js', '_virtual/dynamic1.js', - '_virtual/other.js', - '_virtual/dynamic2.js' + '_virtual/dynamic2.js', + '_virtual/other.js' ], 'fileName' ); @@ -500,14 +500,14 @@ describe('The bundle object', () => { console.log(other);Promise.all([import('./dynamic1.js'), import('./dynamic2.js')]).then(([{dynamic1}, {dynamic2}]) => console.log(dynamic1, dynamic2));\n`, 'const dynamic1 = "dynamic1";\n\nexport { dynamic1 };\n', - 'const other = "other";\n\nexport { other };\n', - 'const dynamic2 = "dynamic2";\n\nexport { dynamic2 };\n' + 'const dynamic2 = "dynamic2";\n\nexport { dynamic2 };\n', + 'const other = "other";\n\nexport { other };\n' ], 'code' ); assert.deepEqual( output.map(chunk => chunk.name), - ['input', 'dynamic1', 'other', 'dynamic2'], + ['input', 'dynamic1', 'dynamic2', 'other'], 'name' ); assert.deepEqual( @@ -522,7 +522,7 @@ console.log(other);Promise.all([import('./dynamic1.js'), import('./dynamic2.js') ); assert.deepEqual( output.map(chunk => chunk.exports), - [[], ['dynamic1'], ['other'], ['dynamic2']], + [[], ['dynamic1'], ['dynamic2'], ['other']], 'exports' ); assert.deepEqual( @@ -539,7 +539,7 @@ console.log(other);Promise.all([import('./dynamic1.js'), import('./dynamic2.js') originalLength: 169, removedExports: [], renderedExports: [], - renderedLength: 141 + renderedLength: 151 } }, { @@ -551,15 +551,6 @@ console.log(other);Promise.all([import('./dynamic1.js'), import('./dynamic2.js') renderedLength: 28 } }, - { - other: { - code: 'const other = "other";', - originalLength: 28, - removedExports: [], - renderedExports: ['other'], - renderedLength: 22 - } - }, { dynamic2: { code: 'const dynamic2 = "dynamic2";', @@ -568,18 +559,27 @@ console.log(other);Promise.all([import('./dynamic1.js'), import('./dynamic2.js') renderedExports: ['dynamic2'], renderedLength: 28 } + }, + { + other: { + code: 'const other = "other";', + originalLength: 28, + removedExports: [], + renderedExports: ['other'], + renderedLength: 22 + } } ], 'modules' ); assert.deepEqual( output.map(chunk => chunk.isDynamicEntry), - [false, true, false, true], + [false, true, true, false], 'isDynamicEntry' ); assert.deepEqual( output.map(chunk => chunk.facadeModuleId), - ['input', 'dynamic1', 'other', 'dynamic2'], + ['input', 'dynamic1', 'dynamic2', 'other'], 'facadeModuleId' ); }); diff --git a/test/misc/misc.js b/test/misc/misc.js index 6f2f27dae36..cf3210ec8c7 100644 --- a/test/misc/misc.js +++ b/test/misc/misc.js @@ -110,7 +110,7 @@ describe('misc', () => { assert.equal(warnings.length, 0); assert.deepEqual( output.map(({ fileName }) => fileName), - ['main1.js', 'main2.js', 'dep-f8bec8a7.js', 'dyndep-b0a9ee12.js'] + ['main1.js', 'main2.js', 'dep-00b63b6d.js', 'dyndep-d5d54b59.js'] ); }); }); diff --git a/test/sourcemaps/index.js b/test/sourcemaps/index.js index 2ef9aa5f35d..4fb704ae24e 100644 --- a/test/sourcemaps/index.js +++ b/test/sourcemaps/index.js @@ -50,8 +50,8 @@ async function generateAndTestBundle(bundle, outputOptions, config, format, warn } if (config.test) { const { - output: [{ code, map }] + output: [{ code, map, fileName }] } = await bundle.generate(outputOptions); - await config.test(code, map, { format }); + await config.test(code, map, { fileName, format }); } } diff --git a/test/sourcemaps/samples/sourcemap-file-hashed/_config.js b/test/sourcemaps/samples/sourcemap-file-hashed/_config.js new file mode 100644 index 00000000000..57ef3229bbb --- /dev/null +++ b/test/sourcemaps/samples/sourcemap-file-hashed/_config.js @@ -0,0 +1,15 @@ +const assert = require('assert'); + +module.exports = { + description: 'populates file property of sourcemap with final name when using hashes', + options: { + output: { + entryFileNames: '[hash].js', + file: null, + dir: '_actual' + } + }, + test: (code, map, { fileName }) => { + assert.strictEqual(map.file, fileName); + } +}; diff --git a/test/sourcemaps/samples/sourcemap-file-hashed/main.js b/test/sourcemaps/samples/sourcemap-file-hashed/main.js new file mode 100644 index 00000000000..5c72ff35124 --- /dev/null +++ b/test/sourcemaps/samples/sourcemap-file-hashed/main.js @@ -0,0 +1 @@ +console.log( 42 ); diff --git a/test/utils.js b/test/utils.js index 0ac77d546ed..13ea3014c99 100644 --- a/test/utils.js +++ b/test/utils.js @@ -272,7 +272,7 @@ exports.writeAndSync = function writeAndSync(filePath, contents) { // Sometimes, watchers on MacOS do not seem to fire. In those cases, it helps // to write the same content again. This function returns a callback to stop // further updates. -function writeAndRetry(filePath, contents) { +exports.writeAndRetry = function writeAndRetry(filePath, contents) { let retries = 0; let updateRetryTimeout; @@ -287,6 +287,14 @@ function writeAndRetry(filePath, contents) { writeFile(); return () => clearTimeout(updateRetryTimeout); -} +}; -exports.writeAndRetry = writeAndRetry; +exports.replaceDirInStringifiedObject = function replaceDirInStringifiedObject(object, replaced) { + return JSON.stringify(object, null, 2).replace( + new RegExp( + JSON.stringify(JSON.stringify(replaced).slice(1, -1)).slice(1, -1) + '[/\\\\]*', + 'g' + ), + '**/' + ); +};