From cf4693845d710dfe9d86b8a3374a95376f1d2265 Mon Sep 17 00:00:00 2001 From: Brian Terlson Date: Thu, 20 Jun 2019 18:10:19 -0700 Subject: [PATCH] WIP fix path fragment inputs --- src/index.js | 9 ++++++++- test/package.json | 15 +++++++++++++++ test/samples/browser-local/delme.js | 3 +++ test/samples/browser-local/main.js | 4 ++++ test/test.js | 14 ++++++++++++++ 5 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 test/package.json create mode 100644 test/samples/browser-local/delme.js create mode 100644 test/samples/browser-local/main.js diff --git a/src/index.js b/src/index.js index d2f75b5..f7d6cf5 100644 --- a/src/index.js +++ b/src/index.js @@ -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 diff --git a/test/package.json b/test/package.json new file mode 100644 index 0000000..5d2dbc8 --- /dev/null +++ b/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" + } +} diff --git a/test/samples/browser-local/delme.js b/test/samples/browser-local/delme.js new file mode 100644 index 0000000..9ef1725 --- /dev/null +++ b/test/samples/browser-local/delme.js @@ -0,0 +1,3 @@ +import s from 'dummy-module'; + +export default x = 1; \ No newline at end of file diff --git a/test/samples/browser-local/main.js b/test/samples/browser-local/main.js new file mode 100644 index 0000000..0560c2d --- /dev/null +++ b/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; \ No newline at end of file diff --git a/test/test.js b/test/test.js index d0b52f6..95d612b 100644 --- a/test/test.js +++ b/test/test.js @@ -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',