Skip to content
Permalink
Browse files
Use browser relative path algorithm for chunks (#2902)
  • Loading branch information
lukastaegert committed Jun 6, 2019
1 parent b1df517 commit 7179390b7dd5ffc83ff4e729d3d6681d27bc553a
@@ -37,16 +37,17 @@ export function relative(from: string, to: string) {
const fromParts = from.split(/[/\\]/).filter(Boolean);
const toParts = to.split(/[/\\]/).filter(Boolean);

if (fromParts[0] === '.') fromParts.shift();
if (toParts[0] === '.') toParts.shift();

while (fromParts[0] && toParts[0] && fromParts[0] === toParts[0]) {
fromParts.shift();
toParts.shift();
}

while (toParts[0] === '.' || toParts[0] === '..') {
const toPart = toParts.shift();
if (toPart === '..') {
fromParts.pop();
}
while (toParts[0] === '..' && fromParts.length > 0) {
toParts.shift();
fromParts.pop();
}

while (fromParts.pop()) {
@@ -1,5 +1,6 @@
import sha256 from 'hash.js/lib/hash/sha/256';
import MagicString, { Bundle as MagicStringBundle, SourceMap } from 'magic-string';
import { relative } from '../browser/path';
import ExportDefaultDeclaration from './ast/nodes/ExportDefaultDeclaration';
import FunctionDeclaration from './ast/nodes/FunctionDeclaration';
import { UNDEFINED_EXPRESSION } from './ast/values';
@@ -28,7 +29,7 @@ import { error } from './utils/error';
import { sortByExecutionOrder } from './utils/executionOrder';
import getIndentString from './utils/getIndentString';
import { makeLegal } from './utils/identifierHelpers';
import { basename, dirname, isAbsolute, normalize, relative, resolve } from './utils/path';
import { basename, dirname, isAbsolute, normalize, resolve } from './utils/path';
import relativeId, { getAliasName } from './utils/relativeId';
import renderChunk from './utils/renderChunk';
import { RenderOptions } from './utils/renderHelpers';
@@ -51,6 +51,7 @@ runTestSuiteWithSamples('function', path.resolve(__dirname, 'samples'), (dir, co
path.basename(dir) + ': ' + config.description,
() => {
if (config.show) console.group(path.basename(dir));
if (config.before) config.before();

process.chdir(dir);
const warnings = [];
@@ -0,0 +1,23 @@
const assert = require('assert');
const cwd = process.cwd;

module.exports = {
description: 'correctly resolves relative external imports from outside directories',
options: {
external() {
return true;
}
},
before() {
process.cwd = () => '/';
},
context: {
require(id) {
return id;
}
},
exports(exports) {
process.cwd = cwd;
assert.strictEqual(exports.value, '../../../test.js');
}
};
@@ -0,0 +1 @@
export {default as value} from '../../../test.js';

0 comments on commit 7179390

Please sign in to comment.