Skip to content
Merged
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 packages/commonjs/src/resolve-require-sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export function getRequireResolver(extensions, detectCyclesAndConditional, curre
return (
(await getTypeForImportedModule(
(
await this.load({ id: resolved.id })
await this.load(resolved)
).meta.commonjs.resolved,
this.load
)) !== IS_WRAPPED_COMMONJS
Expand Down
42 changes: 42 additions & 0 deletions packages/commonjs/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,48 @@ test('handles external dependencies when using the cache', async (t) => {
t.is(await getCodeFromBundle(bundle), code);
});

test('Correctly processes meta data when using the cache but invalidating proxy modules', async (t) => {
const modules = {};
const resetModules = () => {
modules['main.js'] = "import first from 'first.js';export default first;";
modules['first.js'] = "import second from 'second.js';export default second;";
modules['second.js'] = 'module.exports = 42;';
};
const options = {
input: 'main.js',
external: ['external'],
plugins: [
{
name: 'test',
shouldTransformCachedModule({ id }) {
if (id.endsWith('?commonjs-es-import')) {
return true;
}
return null;
},
transform(code, id) {
if (id.endsWith('?commonjs-es-import')) {
return `${code}\n//${Date.now()}`;
}
return null;
}
},
commonjs(),
loader(modules)
],
onwarn
};

resetModules();
let bundle = await rollup(options);
t.is((await executeBundle(bundle, t)).exports, 42);

options.cache = bundle.cache;
modules['main.js'] = "import first from 'first.js';export default first + 1;";
bundle = await rollup(options);
t.is((await executeBundle(bundle, t)).exports, 43);
});

test('allows the config to be reused', async (t) => {
const config = {
preserveModules: true,
Expand Down
Loading