From 5cf0d58f3df9ffe55f9b67244496373e1f3baf52 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Fri, 1 Jul 2022 11:44:14 +0200 Subject: [PATCH] Update documentation --- docs/05-plugin-development.md | 40 +++++------- docs/999-big-list-of-options.md | 4 +- docs/output-generation-hooks.mmd | 62 ++++++++++++------- src/rollup/types.d.ts | 14 ----- src/utils/PluginDriver.ts | 3 +- src/utils/pluginUtils.ts | 28 +-------- .../deprecations/resolveAssetUrl/_config.js | 14 ----- .../deprecations/resolveAssetUrl/main.js | 11 ---- 8 files changed, 62 insertions(+), 114 deletions(-) delete mode 100644 test/function/samples/deprecations/resolveAssetUrl/_config.js delete mode 100644 test/function/samples/deprecations/resolveAssetUrl/main.js diff --git a/docs/05-plugin-development.md b/docs/05-plugin-development.md index 2c7d863a2c4..515c3693f0a 100644 --- a/docs/05-plugin-development.md +++ b/docs/05-plugin-development.md @@ -319,7 +319,7 @@ 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 `code` and `map` and using placeholders for hashes in file names. @@ -340,7 +340,7 @@ function augmentWithDatePlugin() { #### `banner` -**Type:** `string | ((chunk: ChunkInfo) => 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). @@ -354,13 +354,13 @@ If a plugin wants to retain resources across builds in watch mode, they can chec #### `footer` -**Type:** `string | ((chunk: ChunkInfo) => 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: @@ -405,7 +405,7 @@ You can prevent files from being emitted by deleting them from the bundle object #### `intro` -**Type:** `string | ((chunk: ChunkInfo) => 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). @@ -417,20 +417,20 @@ Replaces or manipulates the output options object passed to `bundle.generate()` #### `outro` -**Type:** `string | ((chunk: ChunkInfo) => 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, meta: { chunks: {[id: string]: ChunkInfo} }) => 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. 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. +- `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`. @@ -438,7 +438,7 @@ Can be used to transform individual chunks. Called for each Rollup output chunk #### `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. @@ -498,13 +498,13 @@ 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. @@ -532,7 +532,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. @@ -562,14 +562,6 @@ If the `chunkId` would contain a hash, it will contain a placeholder instead. If Called only at the end of `bundle.write()` once all files have been written. Similar to the [`generateBundle`](guide/en/#generatebundle) hook, `bundle` provides the full list of files being written along with their details. -### Deprecated Hooks - -☢️ These hooks have been deprecated and may be removed in a future Rollup version. - -- `resolveAssetUrl` - _**Use [`resolveFileUrl`](guide/en/#resolvefileurl)**_ - Function hook that allows to customize the generated code for asset URLs. - -More properties may be supported in the future, as and when they prove necessary. - ### Plugin Context A number of utility functions and informational bits can be accessed from within most [hooks](guide/en/#build-hooks) via `this`: @@ -615,9 +607,9 @@ You can reference the URL of an emitted file in any code returned by a [`load`]( 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. +- 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. diff --git a/docs/999-big-list-of-options.md b/docs/999-big-list-of-options.md index f17df800a5f..ef23b032f22 100755 --- a/docs/999-big-list-of-options.md +++ b/docs/999-big-list-of-options.md @@ -402,8 +402,8 @@ A string to prepend/append to the bundle. You can also supply a function that re 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. +- `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`. diff --git a/docs/output-generation-hooks.mmd b/docs/output-generation-hooks.mmd index 989ea902170..e356412cbc1 100644 --- a/docs/output-generation-hooks.mmd +++ b/docs/output-generation-hooks.mmd @@ -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/src/rollup/types.d.ts b/src/rollup/types.d.ts index 42b4ecc7411..d0d818d15b9 100644 --- a/src/rollup/types.d.ts +++ b/src/rollup/types.d.ts @@ -300,17 +300,6 @@ export type ResolveImportMetaHook = ( options: { chunkId: string; format: InternalModuleFormat; moduleId: string } ) => string | null | void; -export type ResolveAssetUrlHook = ( - this: PluginContext, - options: { - assetFileName: string; - chunkId: string; - format: InternalModuleFormat; - moduleId: string; - relativeAssetPath: string; - } -) => string | null | void; - export type ResolveFileUrlHook = ( this: PluginContext, options: { @@ -404,8 +393,6 @@ interface OutputPluginHooks { outputOptions: NormalizedOutputOptions, inputOptions: NormalizedInputOptions ) => Promise | void; - /** @deprecated Use `resolveFileUrl` instead */ - resolveAssetUrl: ResolveAssetUrlHook; resolveFileUrl: ResolveFileUrlHook; resolveImportMeta: ResolveImportMetaHook; writeBundle: ( @@ -441,7 +428,6 @@ export type SyncPluginHooks = Exclude; export type FirstPluginHooks = | 'load' | 'renderDynamicImport' - | 'resolveAssetUrl' | 'resolveDynamicImport' | 'resolveFileUrl' | 'resolveId' diff --git a/src/utils/PluginDriver.ts b/src/utils/PluginDriver.ts index 7b7e1105a3a..1f795f22642 100644 --- a/src/utils/PluginDriver.ts +++ b/src/utils/PluginDriver.ts @@ -22,7 +22,7 @@ import type { import { FileEmitter } from './FileEmitter'; import { getPluginContext } from './PluginContext'; import { errInputHookInOutputPlugin, error } from './error'; -import { throwPluginError, warnDeprecatedHooks } from './pluginUtils'; +import { throwPluginError } from './pluginUtils'; /** * Get the inner type from a promise @@ -94,7 +94,6 @@ export class PluginDriver { pluginCache: Record | undefined, basePluginDriver?: PluginDriver ) { - warnDeprecatedHooks(userPlugins, options); this.pluginCache = pluginCache; this.fileEmitter = new FileEmitter( graph, diff --git a/src/utils/pluginUtils.ts b/src/utils/pluginUtils.ts index 05cc8ba25b3..ab55417731c 100644 --- a/src/utils/pluginUtils.ts +++ b/src/utils/pluginUtils.ts @@ -1,5 +1,5 @@ -import type { NormalizedInputOptions, Plugin, RollupError } from '../rollup/types'; -import { error, Errors, warnDeprecation } from './error'; +import type { RollupError } from '../rollup/types'; +import { error, Errors } from './error'; export const ANONYMOUS_PLUGIN_PREFIX = 'at position '; export const ANONYMOUS_OUTPUT_PLUGIN_PREFIX = 'at output position '; @@ -23,27 +23,3 @@ export function throwPluginError( } return error(err); } - -const deprecatedHooks = [ - { active: true, deprecated: 'resolveAssetUrl', replacement: 'resolveFileUrl' } -] as const; - -export function warnDeprecatedHooks( - plugins: readonly Plugin[], - options: NormalizedInputOptions -): void { - for (const { active, deprecated, replacement } of deprecatedHooks) { - for (const plugin of plugins) { - if (deprecated in plugin) { - warnDeprecation( - { - message: `The "${deprecated}" hook used by plugin ${plugin.name} is deprecated. The "${replacement}" hook should be used instead.`, - plugin: plugin.name - }, - active, - options - ); - } - } - } -} diff --git a/test/function/samples/deprecations/resolveAssetUrl/_config.js b/test/function/samples/deprecations/resolveAssetUrl/_config.js deleted file mode 100644 index 25e521c58c9..00000000000 --- a/test/function/samples/deprecations/resolveAssetUrl/_config.js +++ /dev/null @@ -1,14 +0,0 @@ -module.exports = { - description: 'marks the resolveAssetUrl hook as deprecated', - options: { - plugins: { - resolveAssetUrl() {} - } - }, - error: { - code: 'DEPRECATED_FEATURE', - message: - 'The "resolveAssetUrl" hook used by plugin at position 1 is deprecated. The "resolveFileUrl" hook should be used instead.', - plugin: 'at position 1' - } -}; diff --git a/test/function/samples/deprecations/resolveAssetUrl/main.js b/test/function/samples/deprecations/resolveAssetUrl/main.js deleted file mode 100644 index f8a2d88d245..00000000000 --- a/test/function/samples/deprecations/resolveAssetUrl/main.js +++ /dev/null @@ -1,11 +0,0 @@ -const foo = {}; - -function doIt(x) { - if (foo[x]) { - return true; - } - foo[x] = true; -} - -doIt('x'); -assert.ok(doIt('x'), 'foo was not reassigned');