Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use strict types with PluginDriver #3426

Merged
merged 3 commits into from Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ast/nodes/MetaProperty.ts
Expand Up @@ -106,7 +106,7 @@ export default class MetaProperty extends NodeBase {
]);
}
if (!replacement) {
replacement = outputPluginDriver.hookFirstSync<'resolveFileUrl', string>('resolveFileUrl', [
replacement = outputPluginDriver.hookFirstSync<'resolveFileUrl'>('resolveFileUrl', [
{
assetReferenceId,
chunkId,
Expand All @@ -117,7 +117,7 @@ export default class MetaProperty extends NodeBase {
referenceId: referenceId || assetReferenceId || chunkReferenceId!,
relativePath
}
]);
]) as string;
}

code.overwrite(
Expand Down
4 changes: 2 additions & 2 deletions src/rollup/rollup.ts
Expand Up @@ -362,8 +362,8 @@ function normalizeOutputOptions(
const outputOptions = parseOutputOptions(
outputPluginDriver.hookReduceArg0Sync(
'outputOptions',
[rawOutputOptions.output || inputOptions.output || rawOutputOptions],
(outputOptions: OutputOptions, result: OutputOptions) => result || outputOptions,
[rawOutputOptions.output || inputOptions.output || rawOutputOptions] as [OutputOptions],
(outputOptions, result) => result || outputOptions,
pluginContext => {
const emitError = () => pluginContext.error(errCannotEmitFromOptionsHook());
return {
Expand Down
48 changes: 47 additions & 1 deletion src/rollup/types.d.ts
Expand Up @@ -288,7 +288,8 @@ export type ResolveFileUrlHook = (
}
) => string | null | undefined;

export type AddonHook = string | ((this: PluginContext) => string | Promise<string>);
export type AddonHookFunction = (this: PluginContext) => string | Promise<string>;
export type AddonHook = string | AddonHookFunction;

/**
* use this type for plugin annotation
Expand Down Expand Up @@ -352,6 +353,51 @@ export interface PluginHooks extends OutputPluginHooks {
watchChange: (id: string) => void;
}

export type AsyncPluginHooks =
| 'buildEnd'
| 'buildStart'
| 'generateBundle'
| 'load'
| 'renderChunk'
| 'renderError'
| 'renderStart'
| 'resolveDynamicImport'
| 'resolveId'
| 'transform'
| 'writeBundle';

export type PluginValueHooks = 'banner' | 'footer' | 'intro' | 'outro';

export type SyncPluginHooks = Exclude<keyof PluginHooks, AsyncPluginHooks>;

export type FirstPluginHooks =
| 'load'
| 'resolveAssetUrl'
| 'resolveDynamicImport'
| 'resolveFileUrl'
| 'resolveId'
| 'resolveImportMeta';

export type SequentialPluginHooks =
| 'augmentChunkHash'
| 'generateBundle'
| 'options'
| 'outputOptions'
| 'renderChunk'
| 'transform'
| 'watchChange';

export type ParallelPluginHooks =
| 'banner'
| 'buildEnd'
| 'buildStart'
| 'footer'
| 'intro'
| 'outro'
| 'renderError'
| 'renderStart'
| 'writeBundle';

interface OutputPluginValueHooks {
banner: AddonHook;
cacheKey: string;
Expand Down