8000 fix(Quantum): Prevent Quantum from creating empty chunks · fuse-box/fuse-box@24f5915 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
8000
This repository was archived by the owner on Jun 20, 2023. It is now read-only.

Commit 24f5915

Browse files
committed
fix(Quantum): Prevent Quantum from creating empty chunks
fixes #1297 #1184
1 parent 9cea9e5 commit 24f59
8000
15

File tree

3 files changed

+43
-8
lines changed

3 files changed

+43
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,5 @@
123123
"test": "node test.js"
124124
},
125125
"typings": "index.d.ts",
126-
"version": "3.5.0-next.8"
126+
"version": "3.5.0-next.9"
127127
}

src/quantum/plugin/QuantumBit.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,14 @@ export class QuantumBit {
162162
});
163163
if (dynamicStatementUsed && regularStatementUsed) {
164164
moduleCandidate.quantumBitBanned = true;
165+
if (this.entry === file) {
166+
// if QuantumBit entry matches the file in a package
167+
// e.g import('foobar') whereas foobar and its files (with the entry) are listed
168+
// in moduleCandidates (which contains only one package
169+
// in this case) the whole QuantumBit should be banned. Otherwise it will result
170+
// in creating empty files
171+
this.banned = true;
172+
}
165173
}
166174
});
167175
if (moduleCandidate.quantumBitBanned) {

src/tests/dynamic_imports_test/CodeSplittingFileIntegrity.test.ts

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,6 @@ export class CodeSplittingFileIntegrityTest {
666666
window.$fsx.r(0);
667667

668668
env.scriptShouldExist(HOME_COMPONENT_SCRIPT);
669-
env.scriptShouldExist(LIB_A_SCRIPT);
670669

671670
const appScript = env.getScript("app.js");
672671
appScript.shouldNotFindString("// default/components/HomeComponent.js");
@@ -678,12 +677,6 @@ export class CodeSplittingFileIntegrityTest {
678677

679678
const homeScript = env.getScript(HOME_COMPONENT_SCRIPT);
680679
homeScript.shouldFindString("// default/components/HomeComponent.js");
681-
682-
const libAScript = env.getScript(LIB_A_SCRIPT);
683-
libAScript.shouldNotFindString("// lib_a/index.js");
684-
libAScript.shouldNotFindString("// lib_a/a_mod.js");
685-
libAScript.shouldNotFindString("// lib_b/index.js");
686-
libAScript.shouldNotFindString("// lib_b/b_mod.js");
687680
}),
688681
);
689682
}
@@ -872,4 +865,38 @@ export class CodeSplittingFileIntegrityTest {
872865
}),
873866
);
874867
}
868+
869+
"Should avoid creating empty split bundle files"() {
870+
return FuseTestEnv.create({
871+
testFolder: "_current_test",
872+
project: {
873+
files: {
874+
"index.ts": `
875+
export async function test() {
876+
await import("lib_a")
877+
await import("./a")
878+
}
879+
`,
880+
"a.ts": `
881+
import * as lib_a from "lib_a"
882+
module.exports = lib_a;
883+
`,
884+
},
885+
plugins: [
886+
QuantumPlugin({
887+
target: "browser",
888+
}),
889+
],
890+
},
891+
})
892+
.simple()
893+
.then(test =>
894+
test.browser((window, env) => {
895+
window.$fsx.r(0);
896+
const files = [];
897+
env.scripts.forEach((item, key) => files.push(key));
898+
should(files).deepEqual(["api.js", "app.js", "19879a97.js"]);
899+
}),
900+
);
901+
}
875902
}

0 commit comments

Comments
 (0)
0