Skip to content

Commit

Permalink
Improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jun 21, 2020
1 parent a3b89e5 commit 7e82a1a
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 31 deletions.
21 changes: 9 additions & 12 deletions src/Chunk.ts
Expand Up @@ -895,8 +895,7 @@ export default class Chunk {
} else {
const variable = this.exportsByName![exportName];
if (variable instanceof SyntheticNamedExportVariable) continue;
const module = variable.module;
if (!module) continue;
const module = variable.module!;
if (module instanceof Module) {
exportChunk = this.chunkByModule.get(module)!;
if (exportChunk === this) continue;
Expand Down Expand Up @@ -1146,16 +1145,14 @@ export default class Chunk {
if (variable instanceof SyntheticNamedExportVariable) {
variable = variable.getBaseVariable();
}
if (variable.module) {
const chunk = this.chunkByModule.get(variable.module as Module);
if (chunk !== this) {
this.imports.add(variable);
if (
!(variable instanceof NamespaceVariable && this.outputOptions.preserveModules) &&
variable.module instanceof Module
) {
chunk!.exports.add(variable);
}
const chunk = this.chunkByModule.get(variable.module as Module);
if (chunk !== this) {
this.imports.add(variable);
if (
!(variable instanceof NamespaceVariable && this.outputOptions.preserveModules) &&
variable.module instanceof Module
) {
chunk!.exports.add(variable);
}
}
}
Expand Down
28 changes: 9 additions & 19 deletions src/utils/chunkAssignment.ts
Expand Up @@ -21,10 +21,7 @@ export function getChunkAssignments(
}

const assignedEntryPointsByModule: DependentModuleMap = new Map();
const { dependentEntryPointsByModule, dynamicEntryModules } = analyzeModuleGraph(
entryModules,
modulesInManualChunks
);
const { dependentEntryPointsByModule, dynamicEntryModules } = analyzeModuleGraph(entryModules);
const dynamicallyDependentEntryPointsByDynamicEntry: DependentModuleMap = getDynamicDependentEntryPoints(
dependentEntryPointsByModule,
dynamicEntryModules
Expand Down Expand Up @@ -59,16 +56,16 @@ export function getChunkAssignments(

function areEntryPointsContainedOrDynamicallyDependent(
entryPoints: Set<Module>,
superSet: Set<Module>
containedIn: Set<Module>
): boolean {
const entriesToCheck = new Set(entryPoints);
for (const entry of entriesToCheck) {
if (!superSet.has(entry)) {
if (!containedIn.has(entry)) {
if (staticEntries.has(entry)) return false;
const dynamicDependentEntryPoints = dynamicallyDependentEntryPointsByDynamicEntry.get(
const dynamicallyDependentEntryPoints = dynamicallyDependentEntryPointsByDynamicEntry.get(
entry
)!;
for (const dependentEntry of dynamicDependentEntryPoints) {
for (const dependentEntry of dynamicallyDependentEntryPoints) {
entriesToCheck.add(dependentEntry);
}
}
Expand Down Expand Up @@ -115,8 +112,7 @@ function addStaticDependenciesToManualChunk(
}

function analyzeModuleGraph(
entryModules: Module[],
modulesInManualChunks: Set<Module>
entryModules: Module[]
): {
dependentEntryPointsByModule: DependentModuleMap;
dynamicEntryModules: Set<Module>;
Expand All @@ -134,20 +130,14 @@ function analyzeModuleGraph(
}
}
for (const { resolution } of module.dynamicImports) {
if (
resolution instanceof Module &&
resolution.includedDynamicImporters.length > 0 &&
!modulesInManualChunks.has(resolution)
) {
if (resolution instanceof Module && resolution.includedDynamicImporters.length > 0) {
dynamicEntryModules.add(resolution);
entriesToHandle.add(resolution);
}
}
for (const dependency of module.implicitlyLoadedBefore) {
if (!modulesInManualChunks.has(dependency)) {
dynamicEntryModules.add(dependency);
entriesToHandle.add(dependency);
}
dynamicEntryModules.add(dependency);
entriesToHandle.add(dependency);
}
}
}
Expand Down
@@ -0,0 +1,25 @@
let chunkId;

module.exports = {
description: 'Throws when accessing the filename before it has been generated in buildEnd',
options: {
input: 'main.js',
plugins: {
name: 'test-plugin',
buildStart() {
chunkId = this.emitFile({ type: 'chunk', id: 'chunk.js' });
},
buildEnd() {
this.getFileName(chunkId);
}
}
},
error: {
code: 'PLUGIN_ERROR',
hook: 'buildEnd',
message:
'Plugin error - Unable to get file name for chunk "chunk.js". Ensure that generate is called first.',
plugin: 'test-plugin',
pluginCode: 'CHUNK_NOT_GENERATED'
}
};
@@ -0,0 +1 @@
console.log('chunk');
@@ -0,0 +1 @@
console.log('main');
@@ -0,0 +1,25 @@
let chunkId;

module.exports = {
description: 'Throws when accessing the filename before it has been generated in renderStart',
options: {
input: 'main.js',
plugins: {
name: 'test-plugin',
buildStart() {
chunkId = this.emitFile({ type: 'chunk', id: 'chunk.js' });
},
renderStart() {
this.getFileName(chunkId);
}
}
},
generateError: {
code: 'PLUGIN_ERROR',
hook: 'renderStart',
message:
'Plugin error - Unable to get file name for chunk "chunk.js". Ensure that generate is called first.',
plugin: 'test-plugin',
pluginCode: 'CHUNK_NOT_GENERATED'
}
};
@@ -0,0 +1 @@
console.log('chunk');
@@ -0,0 +1 @@
console.log('main');

0 comments on commit 7e82a1a

Please sign in to comment.