Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

Commit

Permalink
WIP fix path fragment inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
bterlson committed Jun 21, 2019
1 parent cdb7448 commit cf46938
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/index.js
Expand Up @@ -239,9 +239,16 @@ export default function nodeResolve ( options = {} ) {
resolveOptions.preserveSymlinks = preserveSymlinks;
}

let importSpecifier = importee;

if (importer === undefined && !importee[0].match(/^\.?\.?\//)) {
// convert implicit relative path for `inputs`
// to an equivalent explicit relative path
importSpecifier = './' + importee;
}

const importeeIsBuiltin = builtins.has(importee);
const forceLocalLookup = importeeIsBuiltin && (!preferBuiltins || !isPreferBuiltinsSet);
let importSpecifier = importee;

if (forceLocalLookup) {
// need to attempt to look up a local module
Expand Down
15 changes: 15 additions & 0 deletions test/package.json
@@ -0,0 +1,15 @@
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "test.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"browser": {
"dummy-module": "component-type"
}
}
3 changes: 3 additions & 0 deletions test/samples/browser-local/delme.js
@@ -0,0 +1,3 @@
import s from 'dummy-module';

export default x = 1;
4 changes: 4 additions & 0 deletions test/samples/browser-local/main.js
@@ -0,0 +1,4 @@
// test browser mapped imports from the main entrypoint
import s from 'dummy-module';

export default s;
14 changes: 14 additions & 0 deletions test/test.js
Expand Up @@ -337,6 +337,20 @@ describe( 'rollup-plugin-node-resolve', function () {
});
});

it('respects local browser field', function () {
return rollup.rollup({
input: 'samples/browser-local/main.js',
onwarn: expectNoWarnings,
plugins: [
nodeResolve({
mainFields: ['browser', 'main']
})
]
}).then(executeBundle).then(module => {
assert.equal(module.exports, 'component-type');
});
});

it( 'warns when importing builtins', function () {
return rollup.rollup({
input: 'samples/builtins/main.js',
Expand Down

0 comments on commit cf46938

Please sign in to comment.