Skip to content

Commit d88e6ff

Browse files
committed
Fix this.load meta override
1 parent 0d3814a commit d88e6ff

File tree

5 files changed

+34
-7
lines changed

5 files changed

+34
-7
lines changed

examples/example-react-refresh/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
"@babel/core": "^7.13.14",
1313
"@babel/preset-react": "^7.13.13",
1414
"@rollup/plugin-babel": "^5.3.0",
15-
"@rollup/plugin-node-resolve": "^11.2.1",
15+
"@rollup/plugin-node-resolve": "^13.3.0",
1616
"cross-env": "^7.0.3",
1717
"react-refresh": "^0.9.0",
18-
"rollup": "^1.28.0",
18+
"rollup": "^2.77.0",
1919
"rollup-plugin-commonjs-alternate": "^0.8.0",
2020
"rollup-plugin-hot-css": "^0.4.0",
2121
"rollup-plugin-react-refresh": "0.0.3",

lib/impl/ConfigLoader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ module.exports = class ConfigLoader {
3838
// so mark it as external so the require call persists.
3939
external: id => (id[0] !== '.' && !path.isAbsolute(id)) || id.slice(-5, id.length) === '.json',
4040
// Support --configPlugin flag to transform this config file before loading
41-
plugins: getPlugins(configPlugins)
41+
plugins: getPlugins(configPlugins || [])
4242
});
4343

4444
let isESM = filepath.endsWith('.mjs');

lib/impl/NollupContext.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,9 @@ class NollupContext {
201201
});
202202

203203
this.plugins.onLoad(async ({ id, syntheticNamedExports, resolveDependencies, meta}) => {
204-
this.plugins.__meta[id] = meta;
204+
if (meta) {
205+
this.plugins.__meta[id] = meta;
206+
}
205207
await this.load(id, null, false, syntheticNamedExports, resolveDependencies);
206208
});
207209

@@ -222,6 +224,7 @@ class NollupContext {
222224

223225
return this.resolvedInputs;
224226
}
227+
225228
}
226229

227230
/**

lib/impl/PluginLifecycle.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ function handleMetaProperty (container, filePath, meta) {
153153
container.__meta[filePath] = fileMeta;
154154
}
155155

156-
157156
for (let prop in meta) {
158157
fileMeta[prop] = meta[prop];
159158
}
@@ -371,7 +370,7 @@ const PluginLifecycle = {
371370
container.__currentMapChain = null;
372371
container.__currentOriginalCode = null;
373372
container.__currentModuleId = null;
374-
373+
375374
return {
376375
code: hr.code,
377376
map: await combineSourceMapChainFast(mapChain, originalCode, id),

test/cases/api/context.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2764,6 +2764,31 @@ describe ('API: Plugin Context', () => {
27642764
expect(result).to.deep.equal({ hello: true });
27652765
});
27662766

2767+
it ('should not override meta if not is provided', async () => {
2768+
fs.stub('./src/subdep.js', () => `export default 789`);
2769+
fs.stub('./src/dep.js', () => `import './subdep'; export default 456`);
2770+
fs.stub('./src/main.js', () => `import './dep'; export default 123`);
2771+
2772+
let result;
2773+
let bundle = await nollup({
2774+
input: './src/main.js',
2775+
plugins: [{
2776+
async resolveId (id, parent) {
2777+
if (id.indexOf('main') > - 1) {
2778+
let target = await this.resolve('./dep.js', path.resolve(process.cwd(), './src/main.js'));
2779+
(await this.load({ ...target, meta: { hello: true } }));
2780+
let modInfo = (await this.load({ ...target, meta: undefined }));
2781+
result = modInfo.meta;
2782+
2783+
}
2784+
}
2785+
}]
2786+
});
2787+
2788+
await bundle.generate({ format: 'esm' });
2789+
expect(result).to.deep.equal({ hello: true });
2790+
});
2791+
27672792
it ('should support meta via importedIdResolutions', async () => {
27682793
fs.stub('./src/subdep.js', () => `export default 789`);
27692794
fs.stub('./src/dep.js', () => `import './subdep'; export default 456`);
@@ -2928,7 +2953,7 @@ describe ('API: Plugin Context', () => {
29282953

29292954
const DYNAMIC_IMPORT_PROXY_PREFIX = '\0dynamic-import:';
29302955

2931-
let bundle = await rollup({
2956+
let bundle = await nollup({
29322957
input: './src/main.js',
29332958
plugins: [{
29342959
async resolveDynamicImport(specifier, importer) {

0 commit comments

Comments
 (0)