Skip to content

Commit

Permalink
Provide resolvedSources instead of importedIds
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Feb 18, 2022
1 parent f67c404 commit ae21ad8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/Module.ts
Expand Up @@ -708,6 +708,7 @@ export default class Module {
transformFiles,
...moduleOptions
}: TransformModuleJSON & {
resolvedIds?: ResolvedIdMap;
transformFiles?: EmittedFile[] | undefined;
}): void {
this.info.code = code;
Expand Down Expand Up @@ -785,7 +786,6 @@ export default class Module {
code: this.info.code!,
customTransformCache: this.customTransformCache,
dependencies: Array.from(this.dependencies, getId),
dynamicDependencies: Array.from(this.dynamicDependencies, getId),
id: this.id,
meta: this.info.meta,
moduleSideEffects: this.info.moduleSideEffects,
Expand Down
3 changes: 1 addition & 2 deletions src/ModuleLoader.ts
Expand Up @@ -280,11 +280,10 @@ export class ModuleLoader {
{
ast: cachedModule.ast,
code: cachedModule.code,
dynamicallyImportedIds: cachedModule.dynamicDependencies,
id: cachedModule.id,
importedIds: cachedModule.dependencies,
meta: cachedModule.meta,
moduleSideEffects: cachedModule.moduleSideEffects,
resolvedSources: cachedModule.resolvedIds,
syntheticNamedExports: cachedModule.syntheticNamedExports
}
]))
Expand Down
6 changes: 2 additions & 4 deletions src/rollup/types.d.ts
Expand Up @@ -108,16 +108,15 @@ export interface TransformModuleJSON {
customTransformCache: boolean;
originalCode: string;
originalSourcemap: ExistingDecodedSourceMap | null;
resolvedIds?: ResolvedIdMap;
sourcemapChain: DecodedSourceMapOrMissing[];
transformDependencies: string[];
}

export interface ModuleJSON extends TransformModuleJSON, ModuleOptions {
ast: AcornNode;
dependencies: string[];
dynamicDependencies: string[];
id: string;
resolvedIds: ResolvedIdMap;
transformFiles: EmittedFile[] | undefined;
}

Expand Down Expand Up @@ -252,11 +251,10 @@ export type ShouldTransformCachedModuleHook = (
options: {
ast: AcornNode;
code: string;
dynamicallyImportedIds: string[];
id: string;
importedIds: string[];
meta: CustomPluginOptions;
moduleSideEffects: boolean | 'no-treeshake';
resolvedSources: ResolvedIdMap;
syntheticNamedExports: boolean | string;
}
) => Promise<boolean> | boolean;
Expand Down
34 changes: 20 additions & 14 deletions test/incremental/index.js
Expand Up @@ -346,14 +346,7 @@ describe('incremental', () => {
let shouldTransformCachedModuleCalls = 0;

const transformPlugin = {
async shouldTransformCachedModule({
ast,
id,
meta,
importedIds,
dynamicallyImportedIds,
...other
}) {
async shouldTransformCachedModule({ ast, id, meta, resolvedSources, ...other }) {
shouldTransformCachedModuleCalls++;
assert.strictEqual(ast.type, 'Program');
assert.deepStrictEqual(other, {
Expand All @@ -364,19 +357,32 @@ describe('incremental', () => {
switch (id) {
case 'foo':
assert.deepStrictEqual(meta, { transform: { calls: 1, id } });
assert.deepStrictEqual(importedIds, []);
assert.deepStrictEqual(dynamicallyImportedIds, []);
assert.deepStrictEqual(resolvedSources, { __proto__: null });
// we return promises to ensure they are awaited
return Promise.resolve(false);
case 'bar':
assert.deepStrictEqual(meta, { transform: { calls: 1, id } });
assert.deepStrictEqual(importedIds, []);
assert.deepStrictEqual(dynamicallyImportedIds, []);
assert.deepStrictEqual(resolvedSources, { __proto__: null });
return Promise.resolve(false);
case 'entry':
assert.deepStrictEqual(meta, { transform: { calls: 0, id } });
assert.deepStrictEqual(importedIds, ['foo']);
assert.deepStrictEqual(dynamicallyImportedIds, ['bar']);
assert.deepStrictEqual(resolvedSources, {
__proto__: null,
bar: {
external: false,
id: 'bar',
meta: {},
moduleSideEffects: true,
syntheticNamedExports: false
},
foo: {
external: false,
id: 'foo',
meta: {},
moduleSideEffects: true,
syntheticNamedExports: false
}
});
return Promise.resolve(true);
default:
throw new Error(`Unexpected id ${id}.`);
Expand Down

0 comments on commit ae21ad8

Please sign in to comment.