Skip to content

Commit

Permalink
fix(node-resolve): forward meta-information from other plugins (#1062)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Dec 31, 2021
1 parent ffeec8f commit 23226cd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
15 changes: 9 additions & 6 deletions packages/node-resolve/src/index.js
Expand Up @@ -8,10 +8,10 @@ import isModule from 'is-module';
import { version } from '../package.json';

import { isDirCached, isFileCached, readCachedFile } from './cache';
import handleDeprecatedOptions from './deprecated-options';
import { fileExists, readFile, realpath } from './fs';
import resolveImportSpecifiers from './resolveImportSpecifiers';
import { getMainFields, getPackageName, normalizeInput } from './util';
import handleDeprecatedOptions from './deprecated-options';

const builtins = new Set(builtinList);
const ES6_BROWSER_EMPTY = '\0node-resolve:empty.js';
Expand Down Expand Up @@ -225,11 +225,10 @@ export function nodeResolve(opts = {}) {
}
return null;
}
const result = {
return {
id: `${location}${importSuffix}`,
moduleSideEffects: hasModuleSideEffects(location)
};
return result;
};

return {
Expand Down Expand Up @@ -271,9 +270,13 @@ export function nodeResolve(opts = {}) {
importer,
Object.assign({ skipSelf: true }, resolveOptions)
);
const isExternal = !!(resolvedResolved && resolvedResolved.external);
if (isExternal) {
return false;
if (resolvedResolved) {
// Handle plugins that manually make the result external
if (resolvedResolved.external) {
return false;
}
// Pass on meta information added by other plugins
return { ...resolved, meta: resolvedResolved.meta };
}
}
return resolved;
Expand Down
24 changes: 24 additions & 0 deletions packages/node-resolve/test/test.js
Expand Up @@ -525,3 +525,27 @@ test('passes on custom options', async (t) => {
['other.js', void 0, { custom: {}, isEntry: true }]
]);
});

test('passes on meta information from other plugins', async (t) => {
await rollup({
input: 'entry/other.js',
onwarn: failOnWarn(t),
plugins: [
nodeResolve(),
{
name: 'test-meta',
resolveId(importee) {
return {
id: resolve(importee),
meta: { test: { 'I am': 'here' } }
};
},

load(id) {
const info = this.getModuleInfo(id);
t.deepEqual(info.meta, { test: { 'I am': 'here' } });
}
}
]
});
});

0 comments on commit 23226cd

Please sign in to comment.