Skip to content

Commit 366380e

Browse files
authored
fix(node-resolve)!: resolve hash in path (#588)
* fix(node-resolve): resolve hash in path * refact(node-resolve)!: remove special handling for hashes See #588 (comment)
1 parent ec70687 commit 366380e

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

packages/node-resolve/src/index.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
const builtins = new Set(builtinList);
1919
const ES6_BROWSER_EMPTY = '\0node-resolve:empty.js';
2020
const nullFn = () => null;
21-
const deepFreeze = object => {
21+
const deepFreeze = (object) => {
2222
Object.freeze(object);
2323

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

103-
// strip hash and query params from import
104-
const [withoutHash, hash] = importee.split('#');
105-
const [importPath, params] = withoutHash.split('?');
106-
const importSuffix = `${params ? `?${params}` : ''}${hash ? `#${hash}` : ''}`;
103+
// strip query params from import
104+
const [importPath, params] = importee.split('?');
105+
const importSuffix = `${params ? `?${params}` : ''}`;
107106
importee = importPath;
108107

109108
const basedir = !importer || dedupe(importee) ? rootDir : dirname(importer);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import test from 'test/#/foo';
2+
3+
export default test;

packages/node-resolve/test/fixtures/hash.js

-3
This file was deleted.

packages/node-resolve/test/fixtures/node_modules/test/#/foo.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/node-resolve/test/test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,15 @@ test('handles package side-effects', async (t) => {
240240
delete global.sideEffects;
241241
});
242242

243-
test('can resolve imports with hashes', async (t) => {
243+
test('can resolve imports with hash in path', async (t) => {
244244
const bundle = await rollup({
245-
input: 'hash.js',
245+
input: 'hash-in-path.js',
246246
onwarn: () => t.fail('No warnings were expected'),
247247
plugins: [
248248
nodeResolve(),
249249
{
250250
load(id) {
251-
if (id === resolve(__dirname, 'fixtures', 'node_modules', 'test', 'index.js#foo')) {
251+
if (id === resolve(__dirname, 'fixtures', 'node_modules', 'test', '#', 'foo.js')) {
252252
return 'export default "resolved with hash"';
253253
}
254254
return null;

0 commit comments

Comments
 (0)