From 70a2b81ec8f4c3de108598c08e89e69e3cb4b896 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Sun, 20 Feb 2022 07:47:18 +0100 Subject: [PATCH] Add documentation --- docs/05-plugin-development.md | 2 +- test/incremental/index.js | 28 +++++++++++++++------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/docs/05-plugin-development.md b/docs/05-plugin-development.md index 4b73a042072..c96f746ae6a 100644 --- a/docs/05-plugin-development.md +++ b/docs/05-plugin-development.md @@ -266,7 +266,7 @@ In watch mode or when using the cache explicitly, the resolved imports of a cach #### `shouldTransformCachedModule` -**Type:** `({id: string, code: string, ast: ESTree.Program, meta: {[plugin: string]: any}, moduleSideEffects: boolean | "no-treeshake", syntheticNamedExports: string | boolean}) => boolean`
**Kind:** `async, first`
**Previous Hook:** [`load`](guide/en/#load) where the cached file was loaded to compare its code with the cached version.
**Next Hook:** [`moduleParsed`](guide/en/#moduleparsed) if no plugin returns `true`, otherwise [`transform`](guide/en/#transform). +**Type:** `({id: string, code: string, ast: ESTree.Program, resoledSources: {[source: string]: ResolvedId}, meta: {[plugin: string]: any}, moduleSideEffects: boolean | "no-treeshake", syntheticNamedExports: string | boolean}) => boolean`
**Kind:** `async, first`
**Previous Hook:** [`load`](guide/en/#load) where the cached file was loaded to compare its code with the cached version.
**Next Hook:** [`moduleParsed`](guide/en/#moduleparsed) if no plugin returns `true`, otherwise [`transform`](guide/en/#transform). If the Rollup cache is used (e.g. in watch mode or explicitly via the JavaScript API), Rollup will skip the [`transform`](guide/en/#transform) hook of a module if after the [`load`](guide/en/#transform) hook, the loaded `code` is identical to the code of the cached copy. To prevent this, discard the cached copy and instead transform a module, plugins can implement this hook and return `true`. diff --git a/test/incremental/index.js b/test/incremental/index.js index 3d5b6bf01b9..542785ce873 100644 --- a/test/incremental/index.js +++ b/test/incremental/index.js @@ -339,9 +339,9 @@ describe('incremental', () => { it('runs shouldTransformCachedModule when using a cached module', async () => { modules = { - entry: `import foo from 'foo'; export default foo; import('bar').then(console.log);`, - foo: `export default 42`, - bar: `export default 21` + entry: `import foo from 'foo'; export default foo;`, + foo: `export default import('bar')`, + bar: `export default 42` }; let shouldTransformCachedModuleCalls = 0; @@ -357,24 +357,26 @@ describe('incremental', () => { switch (id) { case 'foo': assert.deepStrictEqual(meta, { transform: { calls: 1, id } }); - assert.deepStrictEqual(resolvedSources, { __proto__: null }); + assert.deepStrictEqual(resolvedSources, { + __proto__: null, + bar: { + external: false, + id: 'bar', + meta: {}, + moduleSideEffects: true, + syntheticNamedExports: false + } + }); // we return promises to ensure they are awaited return Promise.resolve(false); case 'bar': - assert.deepStrictEqual(meta, { transform: { calls: 1, id } }); + assert.deepStrictEqual(meta, { transform: { calls: 2, id } }); assert.deepStrictEqual(resolvedSources, { __proto__: null }); return Promise.resolve(false); case 'entry': assert.deepStrictEqual(meta, { transform: { calls: 0, id } }); assert.deepStrictEqual(resolvedSources, { __proto__: null, - bar: { - external: false, - id: 'bar', - meta: {}, - moduleSideEffects: true, - syntheticNamedExports: false - }, foo: { external: false, id: 'foo', @@ -421,6 +423,6 @@ describe('incremental', () => { assert.strictEqual(cachedModules[1].id, 'entry'); assert.deepStrictEqual(cachedModules[1].meta, { transform: { calls: 3, id: 'entry' } }); assert.strictEqual(cachedModules[2].id, 'bar'); - assert.deepStrictEqual(cachedModules[2].meta, { transform: { calls: 1, id: 'bar' } }); + assert.deepStrictEqual(cachedModules[2].meta, { transform: { calls: 2, id: 'bar' } }); }); });