Skip to content

Commit

Permalink
refact(node-resolve): remove special handling for hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
chengcyber committed Oct 9, 2020
1 parent 6f35821 commit 362a0c7
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 34 deletions.
14 changes: 4 additions & 10 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,15 +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
let [withoutHash, hash] = importee.split('#');
// handle hash in path test/#/foo
if (hash && hash[0] === '/') {
withoutHash = `${withoutHash}#${hash}`;
hash = '';
}
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: 0 additions & 3 deletions packages/node-resolve/test/fixtures/hash.js

This file was deleted.

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

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

t.is(module.exports, 'resolved with hash');
});

test('can resolve imports with hash in path', async (t) => {
const bundle = await rollup({
input: 'hash-in-path.js',
Expand Down

0 comments on commit 362a0c7

Please sign in to comment.