Skip to content

Commit 23226cd

Browse files
authored
fix(node-resolve): forward meta-information from other plugins (#1062)
1 parent ffeec8f commit 23226cd

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

packages/node-resolve/src/index.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import isModule from 'is-module';
88
import { version } from '../package.json';
99

1010
import { isDirCached, isFileCached, readCachedFile } from './cache';
11+
import handleDeprecatedOptions from './deprecated-options';
1112
import { fileExists, readFile, realpath } from './fs';
1213
import resolveImportSpecifiers from './resolveImportSpecifiers';
1314
import { getMainFields, getPackageName, normalizeInput } from './util';
14-
import handleDeprecatedOptions from './deprecated-options';
1515

1616
const builtins = new Set(builtinList);
1717
const ES6_BROWSER_EMPTY = '\0node-resolve:empty.js';
@@ -225,11 +225,10 @@ export function nodeResolve(opts = {}) {
225225
}
226226
return null;
227227
}
228-
const result = {
228+
return {
229229
id: `${location}${importSuffix}`,
230230
moduleSideEffects: hasModuleSideEffects(location)
231231
};
232-
return result;
233232
};
234233

235234
return {
@@ -271,9 +270,13 @@ export function nodeResolve(opts = {}) {
271270
importer,
272271
Object.assign({ skipSelf: true }, resolveOptions)
273272
);
274-
const isExternal = !!(resolvedResolved && resolvedResolved.external);
275-
if (isExternal) {
276-
return false;
273+
if (resolvedResolved) {
274+
// Handle plugins that manually make the result external
275+
if (resolvedResolved.external) {
276+
return false;
277+
}
278+
// Pass on meta information added by other plugins
279+
return { ...resolved, meta: resolvedResolved.meta };
277280
}
278281
}
279282
return resolved;

packages/node-resolve/test/test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,3 +525,27 @@ test('passes on custom options', async (t) => {
525525
['other.js', void 0, { custom: {}, isEntry: true }]
526526
]);
527527
});
528+
529+
test('passes on meta information from other plugins', async (t) => {
530+
await rollup({
531+
input: 'entry/other.js',
532+
onwarn: failOnWarn(t),
533+
plugins: [
534+
nodeResolve(),
535+
{
536+
name: 'test-meta',
537+
resolveId(importee) {
538+
return {
539+
id: resolve(importee),
540+
meta: { test: { 'I am': 'here' } }
541+
};
542+
},
543+
544+
load(id) {
545+
const info = this.getModuleInfo(id);
546+
t.deepEqual(info.meta, { test: { 'I am': 'here' } });
547+
}
548+
}
549+
]
550+
});
551+
});

0 commit comments

Comments
 (0)