Skip to content

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Feb 20, 2022
1 parent ae21ad8 commit 70a2b81
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion docs/05-plugin-development.md
Expand Up @@ -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`<br> **Kind:** `async, first`<br> **Previous Hook:** [`load`](guide/en/#load) where the cached file was loaded to compare its code with the cached version.<br> **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`<br> **Kind:** `async, first`<br> **Previous Hook:** [`load`](guide/en/#load) where the cached file was loaded to compare its code with the cached version.<br> **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`.

Expand Down
28 changes: 15 additions & 13 deletions test/incremental/index.js
Expand Up @@ -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;

Expand All @@ -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',
Expand Down Expand Up @@ -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' } });
});
});

0 comments on commit 70a2b81

Please sign in to comment.