Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ describe('wrapModule()', () => {
raw(
wrapModule(myModule, {
createModuleId: createModuleIdFactory(),
dev: false,
dev: true,
includeAsyncPaths: true,
projectRoot: '/root',
serverRoot: '/root',
sourceUrl: 'http://localhost/Main.bundle?param1=true&param2=1234',
}),
),
).toMatchInlineSnapshot(
`__d(function() { console.log("foo") },0,{"0":1,"1":2,"paths":{"1":"/../bar.bundle?param1=true&param2=1234&modulesOnly=true&runModule=false"}});`,
`__d(function() { console.log("foo") },0,{"0":1,"1":2,"paths":{"1":"/../bar.bundle?param1=true&param2=1234&modulesOnly=true&runModule=false"}},"foo.js");`,
);
});

Expand All @@ -164,15 +164,15 @@ describe('wrapModule()', () => {
raw(
wrapModule(myModule, {
createModuleId: createModuleIdFactory(),
dev: false,
dev: true,
includeAsyncPaths: true,
projectRoot: '/root',
serverRoot: '/',
sourceUrl: 'http://localhost/Main.bundle?param1=true&param2=1234',
}),
),
).toMatchInlineSnapshot(
`__d(function() { console.log("foo") },0,{"0":1,"1":2,"paths":{"1":"/bar.bundle?param1=true&param2=1234&modulesOnly=true&runModule=false"}});`,
`__d(function() { console.log("foo") },0,{"0":1,"1":2,"paths":{"1":"/bar.bundle?param1=true&param2=1234&modulesOnly=true&runModule=false"}},"foo.js");`,
);
});

Expand All @@ -186,7 +186,7 @@ describe('wrapModule()', () => {
raw(
wrapModule(myModule, {
createModuleId: createModuleIdFactory(),
dev: false,
dev: true,
includeAsyncPaths: true,
projectRoot: '/root',
serverRoot: '/root',
Expand All @@ -195,7 +195,29 @@ describe('wrapModule()', () => {
}),
),
).toMatchInlineSnapshot(
`__d(function() { console.log("foo") },0,{"0":1,"1":2,"paths":{"1":"/../bar.bundle?modulesOnly=true&runModule=false"}});`,
`__d(function() { console.log("foo") },0,{"0":1,"1":2,"paths":{"1":"/../bar.bundle?modulesOnly=true&runModule=false"}},"foo.js");`,
);
});

test('async dependency paths do not add query params when dev is false', () => {
const dep = nullthrows(myModule.dependencies.get('bar'));
myModule.dependencies.set('bar', {
...dep,
data: {...dep.data, data: {...dep.data.data, asyncType: 'async'}},
});
expect(
raw(
wrapModule(myModule, {
createModuleId: createModuleIdFactory(),
dev: false,
includeAsyncPaths: true,
projectRoot: '/root',
serverRoot: '/root',
sourceUrl: 'http://localhost/Main.bundle?param1=true&param2=1234',
}),
),
).toMatchInlineSnapshot(
`__d(function() { console.log("foo") },0,{"0":1,"1":2,"paths":{"1":"/../bar.bundle"}});`,
);
});
});
18 changes: 11 additions & 7 deletions packages/metro/src/DeltaBundler/Serializers/helpers/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,15 @@ function getModuleParams(module: Module<>, options: Options): Array<mixed> {
// Construct a server-relative URL for the split bundle, propagating
// most parameters from the main bundle's URL.

const {searchParams} = new URL(
jscSafeUrl.toNormalUrl(options.sourceUrl),
);
searchParams.set('modulesOnly', 'true');
searchParams.set('runModule', 'false');
let searchParamsString = '';
if (options.dev) {
const {searchParams} = new URL(
jscSafeUrl.toNormalUrl(options.sourceUrl),
);
searchParams.set('modulesOnly', 'true');
searchParams.set('runModule', 'false');
searchParamsString = '?' + searchParams.toString();
}

const bundlePath = path.relative(
options.serverRoot,
Expand All @@ -77,8 +81,8 @@ function getModuleParams(module: Module<>, options: Options): Array<mixed> {
// Strip the file extension
path.basename(bundlePath, path.extname(bundlePath)),
) +
'.bundle?' +
searchParams.toString();
'.bundle' +
searchParamsString;
}
return id;
},
Expand Down
Loading