Skip to content

Commit

Permalink
fix(node-resolve)!: resolve hash in path (#588)
Browse files Browse the repository at this point in the history
* fix(node-resolve): resolve hash in path

* refact(node-resolve)!: remove special handling for hashes

See #588 (comment)
  • Loading branch information
chengcyber authored Oct 11, 2020
1 parent ec70687 commit 366380e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
9 changes: 4 additions & 5 deletions packages/node-resolve/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
const builtins = new Set(builtinList);
const ES6_BROWSER_EMPTY = '\0node-resolve:empty.js';
const nullFn = () => null;
const deepFreeze = object => {
const deepFreeze = (object) => {
Object.freeze(object);

for (const value of Object.values(object)) {
Expand Down Expand Up @@ -100,10 +100,9 @@ export function nodeResolve(opts = {}) {
// ignore IDs with null character, these belong to other plugins
if (/\0/.test(importee)) return null;

// strip hash and query params from import
const [withoutHash, hash] = importee.split('#');
const [importPath, params] = withoutHash.split('?');
const importSuffix = `${params ? `?${params}` : ''}${hash ? `#${hash}` : ''}`;
// strip query params from import
const [importPath, params] = importee.split('?');
const importSuffix = `${params ? `?${params}` : ''}`;
importee = importPath;

const basedir = !importer || dedupe(importee) ? rootDir : dirname(importer);
Expand Down
3 changes: 3 additions & 0 deletions packages/node-resolve/test/fixtures/hash-in-path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import test from 'test/#/foo';

export default test;
3 changes: 0 additions & 3 deletions packages/node-resolve/test/fixtures/hash.js

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/node-resolve/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,15 @@ test('handles package side-effects', async (t) => {
delete global.sideEffects;
});

test('can resolve imports with hashes', async (t) => {
test('can resolve imports with hash in path', async (t) => {
const bundle = await rollup({
input: 'hash.js',
input: 'hash-in-path.js',
onwarn: () => t.fail('No warnings were expected'),
plugins: [
nodeResolve(),
{
load(id) {
if (id === resolve(__dirname, 'fixtures', 'node_modules', 'test', 'index.js#foo')) {
if (id === resolve(__dirname, 'fixtures', 'node_modules', 'test', '#', 'foo.js')) {
return 'export default "resolved with hash"';
}
return null;
Expand Down

0 comments on commit 366380e

Please sign in to comment.