Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jul 1, 2022
1 parent 8b76631 commit 5cf0d58
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 114 deletions.
40 changes: 16 additions & 24 deletions docs/05-plugin-development.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/999-big-list-of-options.md
Expand Up @@ -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`.

Expand Down
62 changes: 41 additions & 21 deletions docs/output-generation-hooks.mmd
Expand Up @@ -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
Expand All @@ -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
14 changes: 0 additions & 14 deletions src/rollup/types.d.ts
Expand Up @@ -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: {
Expand Down Expand Up @@ -404,8 +393,6 @@ interface OutputPluginHooks {
outputOptions: NormalizedOutputOptions,
inputOptions: NormalizedInputOptions
) => Promise<void> | void;
/** @deprecated Use `resolveFileUrl` instead */
resolveAssetUrl: ResolveAssetUrlHook;
resolveFileUrl: ResolveFileUrlHook;
resolveImportMeta: ResolveImportMetaHook;
writeBundle: (
Expand Down Expand Up @@ -441,7 +428,6 @@ export type SyncPluginHooks = Exclude<keyof PluginHooks, AsyncPluginHooks>;
export type FirstPluginHooks =
| 'load'
| 'renderDynamicImport'
| 'resolveAssetUrl'
| 'resolveDynamicImport'
| 'resolveFileUrl'
| 'resolveId'
Expand Down
3 changes: 1 addition & 2 deletions src/utils/PluginDriver.ts
Expand Up @@ -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
Expand Down Expand Up @@ -94,7 +94,6 @@ export class PluginDriver {
pluginCache: Record<string, SerializablePluginCache> | undefined,
basePluginDriver?: PluginDriver
) {
warnDeprecatedHooks(userPlugins, options);
this.pluginCache = pluginCache;
this.fileEmitter = new FileEmitter(
graph,
Expand Down
28 changes: 2 additions & 26 deletions 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 ';
Expand All @@ -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
);
}
}
}
}
14 changes: 0 additions & 14 deletions test/function/samples/deprecations/resolveAssetUrl/_config.js

This file was deleted.

11 changes: 0 additions & 11 deletions test/function/samples/deprecations/resolveAssetUrl/main.js

This file was deleted.

0 comments on commit 5cf0d58

Please sign in to comment.