Skip to content

Commit

Permalink
fix(concatenate): ignored module should be treated as external (#1149)
Browse files Browse the repository at this point in the history
* fix: 🐛 use empty string for ignored module

* fix: 🐛 flag ignored module and it should be treat as external

* test: ✅ add ignored module in concatenation

* refactor: 🎨
  • Loading branch information
stormslowly authored May 11, 2024
1 parent c10d80b commit 4a0f2ad
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 6 deletions.
1 change: 1 addition & 0 deletions crates/mako/src/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ __mako_require__.loadScript('{}', (e) => e.type === 'load' ? resolve() : reject(
ModuleInfo {
file,
ast,
is_ignored: true,
..Default::default()
}
};
Expand Down
2 changes: 2 additions & 0 deletions crates/mako/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ pub struct ModuleInfo {
/// The top-level-await module must be an async module, in addition, for example, wasm is also an async module
/// The purpose of distinguishing top_level_await and is_async is to adapt to runtime_async
pub is_async: bool,
pub is_ignored: bool,
pub resolved_resource: Option<ResolverResource>,
/// The transformed source map chain of this module
pub source_map_chain: Vec<Vec<u8>>,
Expand All @@ -183,6 +184,7 @@ impl Default for ModuleInfo {
is_async: false,
resolved_resource: None,
source_map_chain: vec![],
is_ignored: false,
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,15 @@ pub fn optimize_module_graph(
can_be_inner = false;
}

let is_async = module_graph
module_graph
.get_module(module_id)
.and_then(|module| module.info.as_ref())
.map_or(false, |info| info.is_async);
if is_async {
can_be_inner = false;
can_be_root = false;
}
.inspect(|info| {
if info.is_async || info.is_ignored {
can_be_inner = false;
can_be_root = false;
}
});

if can_be_root {
root_candidates.push(module_id.clone());
Expand Down
12 changes: 12 additions & 0 deletions e2e/fixtures/mako.scope-hoisting.ignored-module/expect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const {
injectSimpleJest,
parseBuildResult,
moduleDefinitionOf,
} = require("../../../scripts/test-utils");
const { files } = parseBuildResult(__dirname);
injectSimpleJest();

// ignored module should not be concatenated, so keep the definition
expect(files["index.js"]).toContain(moduleDefinitionOf("node_modules/pkg/index.js"));

require("./dist/index.js");
9 changes: 9 additions & 0 deletions e2e/fixtures/mako.scope-hoisting.ignored-module/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {ans} from "./inner";
import ignoredDefault, {ignoredNamed} from "pkg"

it("should have the correct values", function() {
expect(ignoredDefault).toStrictEqual({});
expect(ignoredNamed).toBe(undefined);
expect(ans).toBe(42)
});

1 change: 1 addition & 0 deletions e2e/fixtures/mako.scope-hoisting.ignored-module/inner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const ans = 42
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"entry": {
"index": "./index.js"
},
"optimization": {
"skipModules": true,
"concatenateModules": true
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4a0f2ad

Please sign in to comment.