Skip to content

fix: use __glob_dynamic for dynamic import #4153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/bundler/bundler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2172,7 +2172,7 @@ func (s *scanner) generateResultForGlobResolve(
PrettyPath: result.prettyPath,
Index: sourceIndex,
}
ast := js_parser.GlobResolveAST(s.log, source, importRecords, &object, result.exportAlias)
ast := js_parser.GlobResolveAST(s.log, source, importRecords, &object, kind, result.exportAlias)

// Fill out "nil" for any additional imports (i.e. from the runtime)
for len(resolveResults) < len(ast.ImportRecords) {
Expand Down
22 changes: 11 additions & 11 deletions internal/bundler_tests/snapshots/snapshots_default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4587,7 +4587,7 @@ copy
import {
__commonJS,
__require
} from "./chunk-MQN2VSL5.js";
} from "./chunk-43MNX2CI.js";

// project/cjs.js
var require_cjs = __commonJS({
Expand Down Expand Up @@ -4618,23 +4618,23 @@ console.log(
e,
__require("extern-cjs"),
require_cjs(),
import("./dynamic-Q2DWDUFV.js")
import("./dynamic-CYIRSLLH.js")
);
var exported;
export {
exported
};

---------- /out/dynamic-Q2DWDUFV.js ----------
import "./chunk-MQN2VSL5.js";
---------- /out/dynamic-CYIRSLLH.js ----------
import "./chunk-43MNX2CI.js";

// project/dynamic.js
var dynamic_default = 5;
export {
dynamic_default as default
};

---------- /out/chunk-MQN2VSL5.js ----------
---------- /out/chunk-43MNX2CI.js ----------
export {
__require,
__commonJS
Expand Down Expand Up @@ -4791,7 +4791,7 @@ d {
"out/entry.js": {
"imports": [
{
"path": "out/chunk-MQN2VSL5.js",
"path": "out/chunk-43MNX2CI.js",
"kind": "import-statement"
},
{
Expand All @@ -4813,7 +4813,7 @@ d {
"external": true
},
{
"path": "out/dynamic-Q2DWDUFV.js",
"path": "out/dynamic-CYIRSLLH.js",
"kind": "dynamic-import"
}
],
Expand All @@ -4840,10 +4840,10 @@ d {
},
"bytes": 642
},
"out/dynamic-Q2DWDUFV.js": {
"out/dynamic-CYIRSLLH.js": {
"imports": [
{
"path": "out/chunk-MQN2VSL5.js",
"path": "out/chunk-43MNX2CI.js",
"kind": "import-statement"
}
],
Expand All @@ -4858,7 +4858,7 @@ d {
},
"bytes": 119
},
"out/chunk-MQN2VSL5.js": {
"out/chunk-43MNX2CI.js": {
"imports": [],
"exports": [
"__commonJS",
Expand Down Expand Up @@ -5830,7 +5830,7 @@ var init_ = __esm({
var globImport;
var init_2 = __esm({
'import("./**/*") in entry.js'() {
globImport = __glob({
globImport = __glob_dynamic({
"./entry.js": () => Promise.resolve().then(() => __toESM(require_entry()))
});
}
Expand Down
86 changes: 45 additions & 41 deletions internal/bundler_tests/snapshots/snapshots_glob.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var globRequire_src = __glob({
});

// import("./src/**/*") in entry.js
var globImport_src = __glob({
var globImport_src = __glob_dynamic({
"./src/a.js": () => Promise.resolve().then(() => __toESM(require_a())),
"./src/b.js": () => Promise.resolve().then(() => __toESM(require_b()))
});
Expand All @@ -59,13 +59,14 @@ TestGlobBasicSplitting
---------- /out/entry.js ----------
import {
require_a
} from "./chunk-KO426RN2.js";
} from "./chunk-PMWDUKWY.js";
import {
require_b
} from "./chunk-SGVK3D4Q.js";
} from "./chunk-IAHZMQWI.js";
import {
__glob
} from "./chunk-WCFE7E2E.js";
__glob,
__glob_dynamic
} from "./chunk-TCR27W4P.js";

// require("./src/**/*") in entry.js
var globRequire_src = __glob({
Expand All @@ -74,9 +75,9 @@ var globRequire_src = __glob({
});

// import("./src/**/*") in entry.js
var globImport_src = __glob({
"./src/a.js": () => import("./a-7QA47R6Z.js"),
"./src/b.js": () => import("./b-KY4MVCQS.js")
var globImport_src = __glob_dynamic({
"./src/a.js": () => import("./a-C7SOKCZS.js"),
"./src/b.js": () => import("./b-NPXBJ7DT.js")
});

// entry.js
Expand All @@ -92,17 +93,17 @@ console.log({
}
});

---------- /out/a-7QA47R6Z.js ----------
---------- /out/a-C7SOKCZS.js ----------
import {
require_a
} from "./chunk-KO426RN2.js";
import "./chunk-WCFE7E2E.js";
} from "./chunk-PMWDUKWY.js";
import "./chunk-TCR27W4P.js";
export default require_a();

---------- /out/chunk-KO426RN2.js ----------
---------- /out/chunk-PMWDUKWY.js ----------
import {
__commonJS
} from "./chunk-WCFE7E2E.js";
} from "./chunk-TCR27W4P.js";

// src/a.js
var require_a = __commonJS({
Expand All @@ -115,17 +116,17 @@ export {
require_a
};

---------- /out/b-KY4MVCQS.js ----------
---------- /out/b-NPXBJ7DT.js ----------
import {
require_b
} from "./chunk-SGVK3D4Q.js";
import "./chunk-WCFE7E2E.js";
} from "./chunk-IAHZMQWI.js";
import "./chunk-TCR27W4P.js";
export default require_b();

---------- /out/chunk-SGVK3D4Q.js ----------
---------- /out/chunk-IAHZMQWI.js ----------
import {
__commonJS
} from "./chunk-WCFE7E2E.js";
} from "./chunk-TCR27W4P.js";

// src/b.js
var require_b = __commonJS({
Expand All @@ -138,9 +139,10 @@ export {
require_b
};

---------- /out/chunk-WCFE7E2E.js ----------
---------- /out/chunk-TCR27W4P.js ----------
export {
__glob,
__glob_dynamic,
__commonJS
};

Expand All @@ -157,7 +159,7 @@ TestGlobNoMatches
var globRequire_src_json = __glob({});

// import("./src/**/*.json") in entry.js
var globImport_src_json = __glob({});
var globImport_src_json = __glob_dynamic({});

// entry.js
var ab = Math.random() < 0.5 ? "a.js" : "b.js";
Expand Down Expand Up @@ -196,7 +198,7 @@ var globRequire_src_file_js = __glob({
});

// import("./src/file-*.js") in entry.js
var globImport_src_file_js = __glob({
var globImport_src_file_js = __glob_dynamic({
"./src/file-a.js": () => Promise.resolve().then(() => __toESM(require_file_a())),
"./src/file-b.js": () => Promise.resolve().then(() => __toESM(require_file_b()))
});
Expand Down Expand Up @@ -254,7 +256,7 @@ var globRequire_src_js = __glob({
});

// import("./src/**/*.js") in entry.js
var globImport_src_js = __glob({
var globImport_src_js = __glob_dynamic({
"./src/file-a.js": () => Promise.resolve().then(() => __toESM(require_file_a())),
"./src/file-b.js": () => Promise.resolve().then(() => __toESM(require_file_b())),
"./src/nested/dir/file-a.js": () => Promise.resolve().then(() => __toESM(require_file_a2())),
Expand Down Expand Up @@ -298,7 +300,7 @@ var globRequire_src = __glob({
});

// import("./src/**/*") in entry.ts
var globImport_src = __glob({
var globImport_src = __glob_dynamic({
"./src/a.ts": () => Promise.resolve().then(() => __toESM(require_a())),
"./src/b.ts": () => Promise.resolve().then(() => __toESM(require_b()))
});
Expand All @@ -321,13 +323,14 @@ TestTSGlobBasicSplitting
---------- /out/entry.js ----------
import {
require_a
} from "./chunk-YMCIDKCT.js";
} from "./chunk-YNONNXHQ.js";
import {
require_b
} from "./chunk-2BST4PYI.js";
} from "./chunk-CLMFABLJ.js";
import {
__glob
} from "./chunk-WCFE7E2E.js";
__glob,
__glob_dynamic
} from "./chunk-TCR27W4P.js";

// require("./src/**/*") in entry.ts
var globRequire_src = __glob({
Expand All @@ -336,9 +339,9 @@ var globRequire_src = __glob({
});

// import("./src/**/*") in entry.ts
var globImport_src = __glob({
"./src/a.ts": () => import("./a-YXM4MR7E.js"),
"./src/b.ts": () => import("./b-IPMBSSGN.js")
var globImport_src = __glob_dynamic({
"./src/a.ts": () => import("./a-2HPWJ7PZ.js"),
"./src/b.ts": () => import("./b-RSUH7D2S.js")
});

// entry.ts
Expand All @@ -354,17 +357,17 @@ console.log({
}
});

---------- /out/a-YXM4MR7E.js ----------
---------- /out/a-2HPWJ7PZ.js ----------
import {
require_a
} from "./chunk-YMCIDKCT.js";
import "./chunk-WCFE7E2E.js";
} from "./chunk-YNONNXHQ.js";
import "./chunk-TCR27W4P.js";
export default require_a();

---------- /out/chunk-YMCIDKCT.js ----------
---------- /out/chunk-YNONNXHQ.js ----------
import {
__commonJS
} from "./chunk-WCFE7E2E.js";
} from "./chunk-TCR27W4P.js";

// src/a.ts
var require_a = __commonJS({
Expand All @@ -377,17 +380,17 @@ export {
require_a
};

---------- /out/b-IPMBSSGN.js ----------
---------- /out/b-RSUH7D2S.js ----------
import {
require_b
} from "./chunk-2BST4PYI.js";
import "./chunk-WCFE7E2E.js";
} from "./chunk-CLMFABLJ.js";
import "./chunk-TCR27W4P.js";
export default require_b();

---------- /out/chunk-2BST4PYI.js ----------
---------- /out/chunk-CLMFABLJ.js ----------
import {
__commonJS
} from "./chunk-WCFE7E2E.js";
} from "./chunk-TCR27W4P.js";

// src/b.ts
var require_b = __commonJS({
Expand All @@ -400,8 +403,9 @@ export {
require_b
};

---------- /out/chunk-WCFE7E2E.js ----------
---------- /out/chunk-TCR27W4P.js ----------
export {
__glob,
__glob_dynamic,
__commonJS
};
2 changes: 1 addition & 1 deletion internal/bundler_tests/snapshots/snapshots_loader.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ var init_foo = __esm({
});

// import("./foo*") in entry.js
var globImport_foo = __glob({
var globImport_foo = __glob_dynamic({
"./foo.js": () => Promise.resolve().then(() => (init_foo(), foo_exports))
});

Expand Down
Loading