Skip to content

Commit

Permalink
Fix repeated re-emission of files emitted from a transform hook (#2936)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jun 13, 2019
1 parent c3247e6 commit 9d19a18
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 149 deletions.
17 changes: 14 additions & 3 deletions src/Module.ts
Expand Up @@ -217,7 +217,7 @@ export default class Module {
private graph: Graph;
private magicString!: MagicString;
private namespaceVariable: NamespaceVariable = undefined as any;
private transformDependencies!: string[];
private transformDependencies: string[] | null = null;
private transitiveReexports?: string[];

constructor(graph: Graph, id: string, moduleSideEffects: boolean, isEntry: boolean) {
Expand Down Expand Up @@ -526,13 +526,24 @@ export default class Module {
originalSourcemap,
resolvedIds,
sourcemapChain,
transformAssets,
transformChunks,
transformDependencies
}: TransformModuleJSON) {
}: TransformModuleJSON & {
transformAssets?: Asset[] | undefined;
transformChunks?: EmittedChunk[] | undefined;
}) {
this.code = code;
this.originalCode = originalCode;
this.originalSourcemap = originalSourcemap;
this.sourcemapChain = sourcemapChain as RawSourceMap[];
this.transformDependencies = transformDependencies as string[];
if (transformAssets) {
this.transformAssets = transformAssets;
}
if (transformChunks) {
this.transformChunks = transformChunks;
}
this.transformDependencies = transformDependencies;
this.customTransformCache = customTransformCache;
if (typeof moduleSideEffects === 'boolean') {
this.moduleSideEffects = moduleSideEffects;
Expand Down
3 changes: 2 additions & 1 deletion src/ModuleLoader.ts
Expand Up @@ -7,6 +7,7 @@ import {
ExternalOption,
GetManualChunk,
IsExternal,
ModuleJSON,
ModuleSideEffectsOption,
PureModulesOption,
ResolvedId,
Expand Down Expand Up @@ -348,7 +349,7 @@ export class ModuleLoader {
}
return transform(this.graph, sourceDescription, module);
})
.then((source: TransformModuleJSON) => {
.then((source: TransformModuleJSON | ModuleJSON) => {
module.setSource(source);
this.modulesById.set(id, module);

Expand Down
4 changes: 2 additions & 2 deletions src/rollup/types.d.ts
Expand Up @@ -88,8 +88,8 @@ export interface TransformModuleJSON {
export interface ModuleJSON extends TransformModuleJSON {
dependencies: string[];
id: string;
transformAssets: Asset[] | void;
transformChunks: EmittedChunk[] | void;
transformAssets: Asset[] | undefined;
transformChunks: EmittedChunk[] | undefined;
}

export interface EmittedChunk {
Expand Down

0 comments on commit 9d19a18

Please sign in to comment.