Skip to content

Commit

Permalink
Create a shallow copy when returning meta from resolveId (#4347)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jan 14, 2022
1 parent 1d2ea22 commit 9e947fc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Module.ts
Expand Up @@ -293,7 +293,7 @@ export default class Module {
}
return module.isIncluded();
},
meta,
meta: { ...meta },
syntheticNamedExports
};
}
Expand Down
29 changes: 29 additions & 0 deletions test/function/samples/reuse-resolve-meta/_config.js
@@ -0,0 +1,29 @@
const assert = require('assert');
const path = require('path');
const meta = { plugin: { initial: true } };

const ID_MAIN = path.join(__dirname, 'main.js');

module.exports = {
description: 'does not modify meta objects passed in resolveId',
options: {
plugins: [
{
async resolveId(source, importer) {
const { id } = await this.resolve(source, importer, { skipSelf: true });
return { id, meta };
},
transform(code) {
return { code, meta: { otherPlugin: { ignored: true }, plugin: { replaced: true } } };
},
buildEnd() {
assert.deepStrictEqual(meta, { plugin: { initial: true } });
assert.deepStrictEqual(this.getModuleInfo(ID_MAIN).meta, {
otherPlugin: { ignored: true },
plugin: { replaced: true }
});
}
}
]
}
};
1 change: 1 addition & 0 deletions test/function/samples/reuse-resolve-meta/main.js
@@ -0,0 +1 @@
assert.ok(true);

0 comments on commit 9e947fc

Please sign in to comment.