Skip to content

Commit

Permalink
add the __glob runtime helper method
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Aug 8, 2023
1 parent c067c5e commit 8e14e25
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 25 deletions.
20 changes: 10 additions & 10 deletions internal/bundler_tests/snapshots/snapshots_default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3953,7 +3953,7 @@ copy
import {
__commonJS,
__require
} from "./chunk-O3JHV3KG.js";
} from "./chunk-WXLYCZIT.js";

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

---------- /out/dynamic-3QRP4J6Z.js ----------
import "./chunk-O3JHV3KG.js";
---------- /out/dynamic-TGITTCVZ.js ----------
import "./chunk-WXLYCZIT.js";

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

---------- /out/chunk-O3JHV3KG.js ----------
---------- /out/chunk-WXLYCZIT.js ----------
export {
__require,
__commonJS
Expand Down Expand Up @@ -4157,7 +4157,7 @@ d {
"out/entry.js": {
"imports": [
{
"path": "out/chunk-O3JHV3KG.js",
"path": "out/chunk-WXLYCZIT.js",
"kind": "import-statement"
},
{
Expand All @@ -4179,7 +4179,7 @@ d {
"external": true
},
{
"path": "out/dynamic-3QRP4J6Z.js",
"path": "out/dynamic-TGITTCVZ.js",
"kind": "dynamic-import"
}
],
Expand All @@ -4206,10 +4206,10 @@ d {
},
"bytes": 642
},
"out/dynamic-3QRP4J6Z.js": {
"out/dynamic-TGITTCVZ.js": {
"imports": [
{
"path": "out/chunk-O3JHV3KG.js",
"path": "out/chunk-WXLYCZIT.js",
"kind": "import-statement"
}
],
Expand All @@ -4224,7 +4224,7 @@ d {
},
"bytes": 119
},
"out/chunk-O3JHV3KG.js": {
"out/chunk-WXLYCZIT.js": {
"imports": [],
"exports": [
"__commonJS",
Expand Down
26 changes: 13 additions & 13 deletions internal/bundler_tests/snapshots/snapshots_splitting.txt
Original file line number Diff line number Diff line change
Expand Up @@ -259,19 +259,19 @@ TestSplittingDynamicAndNotDynamicCommonJSIntoES6
import {
__toESM,
require_foo
} from "./chunk-H2HESYLH.js";
} from "./chunk-P5A5627R.js";

// entry.js
var import_foo = __toESM(require_foo());
import("./foo-OK6Y35CI.js").then(({ default: { bar: b } }) => console.log(import_foo.bar, b));
import("./foo-N2LAC7TT.js").then(({ default: { bar: b } }) => console.log(import_foo.bar, b));

---------- /out/foo-OK6Y35CI.js ----------
---------- /out/foo-N2LAC7TT.js ----------
import {
require_foo
} from "./chunk-H2HESYLH.js";
} from "./chunk-P5A5627R.js";
export default require_foo();

---------- /out/chunk-H2HESYLH.js ----------
---------- /out/chunk-P5A5627R.js ----------
// foo.js
var require_foo = __commonJS({
"foo.js"(exports) {
Expand Down Expand Up @@ -314,9 +314,9 @@ export {
TestSplittingDynamicCommonJSIntoES6
---------- /out/entry.js ----------
// entry.js
import("./foo-PPQD77K4.js").then(({ default: { bar } }) => console.log(bar));
import("./foo-LH6ELO2A.js").then(({ default: { bar } }) => console.log(bar));

---------- /out/foo-PPQD77K4.js ----------
---------- /out/foo-LH6ELO2A.js ----------
// foo.js
var require_foo = __commonJS({
"foo.js"(exports) {
Expand Down Expand Up @@ -371,7 +371,7 @@ TestSplittingHybridESMAndCJSIssue617
import {
foo,
init_a
} from "./chunk-NE324UYZ.js";
} from "./chunk-P3Z6IJKQ.js";
init_a();
export {
foo
Expand All @@ -382,15 +382,15 @@ import {
__toCommonJS,
a_exports,
init_a
} from "./chunk-NE324UYZ.js";
} from "./chunk-P3Z6IJKQ.js";

// b.js
var bar = (init_a(), __toCommonJS(a_exports));
export {
bar
};

---------- /out/chunk-NE324UYZ.js ----------
---------- /out/chunk-P3Z6IJKQ.js ----------
// a.js
var a_exports = {};
__export(a_exports, {
Expand Down Expand Up @@ -541,7 +541,7 @@ TestSplittingSharedCommonJSIntoES6
---------- /out/a.js ----------
import {
require_shared
} from "./chunk-KTJ3L72M.js";
} from "./chunk-EJ4GJF3D.js";

// a.js
var { foo } = require_shared();
Expand All @@ -550,13 +550,13 @@ console.log(foo);
---------- /out/b.js ----------
import {
require_shared
} from "./chunk-KTJ3L72M.js";
} from "./chunk-EJ4GJF3D.js";

// b.js
var { foo } = require_shared();
console.log(foo);

---------- /out/chunk-KTJ3L72M.js ----------
---------- /out/chunk-EJ4GJF3D.js ----------
// shared.js
var require_shared = __commonJS({
"shared.js"(exports) {
Expand Down
7 changes: 7 additions & 0 deletions internal/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ func Source(unsupportedJSFeatures compat.JSFeature) logger.Source {
throw Error('Dynamic require of "' + x + '" is not supported')
})
// This is used for glob imports
export var __glob = map => path => {
var fn = map[path]
if (fn) return fn()
throw new Error('Module not found in bundle: ' + path)
}
// For object rest patterns
export var __restKey = key => typeof key === 'symbol' ? key : key + ''
export var __objRest = (source, exclude) => {
Expand Down
4 changes: 2 additions & 2 deletions scripts/js-api-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -923,8 +923,8 @@ export {
const names2 = result2.outputFiles.map(x => path.basename(x.path)).sort()

// Check that the public path is included in chunk hashes but not asset hashes
assert.deepStrictEqual(names1, ['data-BYATPJRB.bin', 'in-IN5VRZMW.js'])
assert.deepStrictEqual(names2, ['data-BYATPJRB.bin', 'in-7HV645WS.js'])
assert.deepStrictEqual(names1, ['data-BYATPJRB.bin', 'in-7SVE3DTC.js'])
assert.deepStrictEqual(names2, ['data-BYATPJRB.bin', 'in-E6EBO534.js'])
},

async fileLoaderPublicPath({ esbuild, testDir }) {
Expand Down

0 comments on commit 8e14e25

Please sign in to comment.