@parcel/utils 2.0.0-nightly.92 → 2.0.0-nightly.934

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/.eslintrc.js +6 -6
  2. package/lib/DefaultMap.js +26 -5
  3. package/lib/Deferred.js +10 -2
  4. package/lib/PromiseQueue.js +21 -30
  5. package/lib/TapStream.js +10 -10
  6. package/lib/alternatives.js +134 -0
  7. package/lib/ansi-html.js +10 -2
  8. package/lib/blob.js +14 -6
  9. package/lib/collection.js +0 -11
  10. package/lib/config.js +107 -34
  11. package/lib/countLines.js +2 -2
  12. package/lib/dependency-location.js +3 -3
  13. package/lib/generateBuildMetrics.js +148 -0
  14. package/lib/generateCertificate.js +33 -8
  15. package/lib/getExisting.js +11 -3
  16. package/lib/getRootDir.js +18 -7
  17. package/lib/glob.js +53 -19
  18. package/lib/hash.js +44 -0
  19. package/lib/http-server.js +48 -10
  20. package/lib/index.js +280 -222
  21. package/lib/is-url.js +12 -2
  22. package/lib/isDirectoryInside.js +24 -0
  23. package/lib/objectHash.js +10 -2
  24. package/lib/openInBrowser.js +94 -0
  25. package/lib/path.js +33 -6
  26. package/lib/prettyDiagnostic.js +107 -25
  27. package/lib/relativeBundlePath.js +13 -7
  28. package/lib/relativeUrl.js +19 -3
  29. package/lib/replaceBundleReferences.js +91 -35
  30. package/lib/schema.js +104 -33
  31. package/lib/sourcemap.js +147 -0
  32. package/lib/stream.js +38 -3
  33. package/lib/urlJoin.js +25 -6
  34. package/package.json +22 -16
  35. package/src/DefaultMap.js +25 -1
  36. package/src/PromiseQueue.js +16 -12
  37. package/src/alternatives.js +143 -0
  38. package/src/ansi-html.js +2 -2
  39. package/src/blob.js +3 -3
  40. package/src/bundle-url.js +1 -1
  41. package/src/collection.js +2 -14
  42. package/src/config.js +67 -34
  43. package/src/countLines.js +5 -2
  44. package/src/debounce.js +1 -1
  45. package/src/dependency-location.js +11 -6
  46. package/src/generateBuildMetrics.js +158 -0
  47. package/src/generateCertificate.js +1 -1
  48. package/src/getCertificate.js +1 -1
  49. package/src/getExisting.js +1 -4
  50. package/src/getRootDir.js +1 -2
  51. package/src/glob.js +29 -11
  52. package/src/hash.js +34 -0
  53. package/src/http-server.js +10 -12
  54. package/src/index.js +49 -23
  55. package/src/is-url.js +1 -1
  56. package/src/isDirectoryInside.js +11 -0
  57. package/src/openInBrowser.js +64 -0
  58. package/src/path.js +38 -6
  59. package/src/prettyDiagnostic.js +59 -28
  60. package/src/relativeBundlePath.js +8 -13
  61. package/src/replaceBundleReferences.js +75 -39
  62. package/src/schema.js +101 -44
  63. package/src/sourcemap.js +135 -0
  64. package/src/stream.js +31 -1
  65. package/src/urlJoin.js +3 -1
  66. package/test/DefaultMap.test.js +8 -5
  67. package/test/input/sourcemap/referenced-min.js +2 -0
  68. package/test/input/sourcemap/referenced-min.js.map +6 -0
  69. package/test/input/sourcemap/source-root.js +2 -0
  70. package/test/input/sourcemap/source-root.js.map +7 -0
  71. package/test/objectHash.test.js +33 -0
  72. package/test/prettifyTime.test.js +17 -0
  73. package/test/replaceBundleReferences.test.js +268 -0
  74. package/test/sourcemap.test.js +207 -0
  75. package/test/throttle.test.js +1 -2
  76. package/test/urlJoin.test.js +37 -0
  77. package/lib/generateBundleReport.js +0 -38
  78. package/lib/loadSourceMapUrl.js +0 -33
  79. package/lib/md5.js +0 -35
  80. package/lib/prettyError.js +0 -43
  81. package/lib/promisify.js +0 -13
  82. package/lib/resolve.js +0 -93
  83. package/lib/serializeObject.js +0 -28
  84. package/src/generateBundleReport.js +0 -51
  85. package/src/loadSourceMapUrl.js +0 -33
  86. package/src/md5.js +0 -44
  87. package/src/prettyError.js +0 -54
  88. package/src/promisify.js +0 -13
  89. package/src/resolve.js +0 -123
  90. package/src/serializeObject.js +0 -22
  91. package/test/input/sourcemap/referenced.js +0 -7
  92. package/test/loadSourceMapUrl.test.js +0 -37
  93. package/test/prettyError.test.js +0 -104
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = openInBrowser;
7
+
8
+ function _open() {
9
+ const data = _interopRequireDefault(require("open"));
10
+
11
+ _open = function () {
12
+ return data;
13
+ };
14
+
15
+ return data;
16
+ }
17
+
18
+ function _child_process() {
19
+ const data = require("child_process");
20
+
21
+ _child_process = function () {
22
+ return data;
23
+ };
24
+
25
+ return data;
26
+ }
27
+
28
+ function _logger() {
29
+ const data = _interopRequireDefault(require("@parcel/logger"));
30
+
31
+ _logger = function () {
32
+ return data;
33
+ };
34
+
35
+ return data;
36
+ }
37
+
38
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
39
+
40
+ // Chrome app name is platform dependent. we should not hard code it.
41
+ // https://github.com/react-native-community/cli/blob/e2be8a905285d9b37512fc78c9755b9635ecf805/packages/cli/src/commands/server/launchDebugger.ts#L28
42
+ function getChromeAppName() {
43
+ switch (process.platform) {
44
+ case 'darwin':
45
+ return 'google chrome';
46
+
47
+ case 'win32':
48
+ return 'chrome';
49
+
50
+ case 'linux':
51
+ if (commandExistsUnixSync('google-chrome')) {
52
+ return 'google-chrome';
53
+ }
54
+
55
+ if (commandExistsUnixSync('chromium-browser')) {
56
+ return 'chromium-browser';
57
+ }
58
+
59
+ return 'chromium';
60
+
61
+ default:
62
+ return 'google-chrome';
63
+ }
64
+ }
65
+
66
+ function commandExistsUnixSync(commandName) {
67
+ try {
68
+ const stdout = (0, _child_process().execSync)(`command -v ${commandName} 2>/dev/null` + ` && { echo >&1 '${commandName} found'; exit 0; }`);
69
+ return !!stdout;
70
+ } catch (error) {
71
+ return false;
72
+ }
73
+ }
74
+
75
+ function getAppName(appName) {
76
+ if (['google', 'chrome'].includes(appName)) {
77
+ return getChromeAppName();
78
+ } else if (['brave', 'Brave'].includes(appName)) {
79
+ return 'Brave Browser';
80
+ } else return appName;
81
+ }
82
+
83
+ async function openInBrowser(url, browser) {
84
+ try {
85
+ const options = typeof browser === 'string' && browser.length > 0 ? {
86
+ app: [getAppName(browser)]
87
+ } : undefined;
88
+ await (0, _open().default)(url, options);
89
+ } catch (err) {
90
+ _logger().default.error(`Unexpected error while opening in browser: ${browser}`, '@parcel/utils');
91
+
92
+ _logger().default.error(err, '@parcel/utils');
93
+ }
94
+ }
package/lib/path.js CHANGED
@@ -3,20 +3,47 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.isAbsolute = isAbsolute;
6
7
  exports.normalizeSeparators = normalizeSeparators;
8
+ exports.normalizePath = normalizePath;
9
+ exports.relativePath = relativePath;
7
10
 
8
- var _path = _interopRequireDefault(require("path"));
11
+ function _path() {
12
+ const data = _interopRequireDefault(require("path"));
13
+
14
+ _path = function () {
15
+ return data;
16
+ };
17
+
18
+ return data;
19
+ }
9
20
 
10
21
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
22
 
12
- const COMMON_SEPARATORS = ['/', '\\'];
23
+ const ABSOLUTE_PATH_REGEX = /^([a-zA-Z]:){0,1}[\\/]+/;
24
+ const SEPARATOR_REGEX = /[\\]+/g;
25
+
26
+ function isAbsolute(filepath) {
27
+ return ABSOLUTE_PATH_REGEX.test(filepath);
28
+ }
13
29
 
14
30
  function normalizeSeparators(filePath) {
15
- let ret = filePath;
31
+ return filePath.replace(SEPARATOR_REGEX, '/');
32
+ }
33
+
34
+ function normalizePath(filePath, leadingDotSlash = true) {
35
+ if (leadingDotSlash && (filePath[0] !== '.' || filePath[1] !== '.' && filePath[1] !== '/' && filePath[1] !== '\\') && !_path().default.isAbsolute(filePath)) {
36
+ return normalizeSeparators('./' + filePath);
37
+ } else {
38
+ return normalizeSeparators(filePath);
39
+ }
40
+ }
16
41
 
17
- for (let separator of COMMON_SEPARATORS) {
18
- ret = ret.split(separator).join(_path.default.sep);
42
+ function relativePath(from, to, leadingDotSlash = true) {
43
+ // Fast path
44
+ if (to.startsWith(from + '/')) {
45
+ return (leadingDotSlash ? './' : '') + to.slice(from.length + 1);
19
46
  }
20
47
 
21
- return ret;
48
+ return normalizePath(_path().default.relative(from, to), leadingDotSlash);
22
49
  }
@@ -5,51 +5,133 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = prettyDiagnostic;
7
7
 
8
- var _codeframe = _interopRequireDefault(require("@parcel/codeframe"));
8
+ function _codeframe() {
9
+ const data = _interopRequireDefault(require("@parcel/codeframe"));
9
10
 
10
- var _markdownAnsi = _interopRequireDefault(require("@parcel/markdown-ansi"));
11
+ _codeframe = function () {
12
+ return data;
13
+ };
14
+
15
+ return data;
16
+ }
17
+
18
+ function _markdownAnsi() {
19
+ const data = _interopRequireDefault(require("@parcel/markdown-ansi"));
20
+
21
+ _markdownAnsi = function () {
22
+ return data;
23
+ };
24
+
25
+ return data;
26
+ }
27
+
28
+ function _chalk() {
29
+ const data = _interopRequireDefault(require("chalk"));
30
+
31
+ _chalk = function () {
32
+ return data;
33
+ };
34
+
35
+ return data;
36
+ }
37
+
38
+ function _path() {
39
+ const data = _interopRequireDefault(require("path"));
40
+
41
+ _path = function () {
42
+ return data;
43
+ };
44
+
45
+ return data;
46
+ }
47
+
48
+ function _nullthrows() {
49
+ const data = _interopRequireDefault(require("nullthrows"));
50
+
51
+ _nullthrows = function () {
52
+ return data;
53
+ };
11
54
 
12
- var _chalk = _interopRequireDefault(require("chalk"));
55
+ return data;
56
+ }
13
57
 
14
- var _path = _interopRequireDefault(require("path"));
58
+ function _terminalLink() {
59
+ const data = _interopRequireDefault(require("terminal-link"));
60
+
61
+ _terminalLink = function () {
62
+ return data;
63
+ };
64
+
65
+ return data;
66
+ }
15
67
 
16
68
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
69
 
18
- function prettyDiagnostic(diagnostic) {
70
+ // $FlowFixMe
71
+ async function prettyDiagnostic(diagnostic, options, terminalWidth) {
19
72
  let {
20
73
  origin,
21
74
  message,
22
75
  stack,
23
- codeFrame,
76
+ codeFrames,
24
77
  hints,
25
- filePath,
26
- language,
27
- skipFormatting
78
+ skipFormatting,
79
+ documentationURL
28
80
  } = diagnostic;
29
81
  let result = {
30
- message: '',
82
+ message: (0, _markdownAnsi().default)(`**${origin !== null && origin !== void 0 ? origin : 'unknown'}**: `) + (skipFormatting ? message : (0, _markdownAnsi().default)(message)),
31
83
  stack: '',
32
84
  codeframe: '',
33
- hints: []
85
+ hints: [],
86
+ documentation: ''
34
87
  };
35
- result.message = (0, _markdownAnsi.default)(`**${origin !== null && origin !== void 0 ? origin : 'unknown'}**: `) + (skipFormatting ? message : (0, _markdownAnsi.default)(message));
36
- result.stack = stack || '';
37
-
38
- if (codeFrame !== undefined) {
39
- let highlights = Array.isArray(codeFrame.codeHighlights) ? codeFrame.codeHighlights : [codeFrame.codeHighlights];
40
- let formattedCodeFrame = (0, _codeframe.default)(codeFrame.code, highlights, {
41
- useColor: true,
42
- syntaxHighlighting: true,
43
- language: // $FlowFixMe sketchy null checks do not matter here...
44
- language || (filePath ? _path.default.extname(filePath).substr(1) : undefined)
45
- });
46
- result.codeframe += typeof filePath !== 'string' ? '' : _chalk.default.underline(`${filePath}:${highlights[0].start.line}:${highlights[0].start.column}\n`);
47
- result.codeframe += formattedCodeFrame;
88
+
89
+ if (codeFrames != null) {
90
+ for (let codeFrame of codeFrames) {
91
+ var _codeFrame$code;
92
+
93
+ let filePath = codeFrame.filePath;
94
+
95
+ if (filePath != null && options && !_path().default.isAbsolute(filePath)) {
96
+ filePath = _path().default.join(options.projectRoot, filePath);
97
+ }
98
+
99
+ let highlights = codeFrame.codeHighlights;
100
+ let code = (_codeFrame$code = codeFrame.code) !== null && _codeFrame$code !== void 0 ? _codeFrame$code : options && (await options.inputFS.readFile((0, _nullthrows().default)(filePath), 'utf8'));
101
+ let formattedCodeFrame = '';
102
+
103
+ if (code != null) {
104
+ formattedCodeFrame = (0, _codeframe().default)(code, highlights, {
105
+ useColor: true,
106
+ syntaxHighlighting: true,
107
+ language: // $FlowFixMe sketchy null checks do not matter here...
108
+ codeFrame.language || (filePath != null ? _path().default.extname(filePath).substr(1) : undefined),
109
+ terminalWidth
110
+ });
111
+ }
112
+
113
+ result.codeframe += typeof filePath !== 'string' ? '' : _chalk().default.gray.underline(`${filePath}:${highlights[0].start.line}:${highlights[0].start.column}\n`);
114
+ result.codeframe += formattedCodeFrame;
115
+
116
+ if (codeFrame !== codeFrames[codeFrames.length - 1]) {
117
+ result.codeframe += '\n\n';
118
+ }
119
+ }
120
+ }
121
+
122
+ if (stack != null) {
123
+ result.stack = stack;
48
124
  }
49
125
 
50
126
  if (Array.isArray(hints) && hints.length) {
51
127
  result.hints = hints.map(h => {
52
- return (0, _markdownAnsi.default)(h);
128
+ return (0, _markdownAnsi().default)(h);
129
+ });
130
+ }
131
+
132
+ if (documentationURL != null) {
133
+ result.documentation = (0, _terminalLink().default)('Learn more', documentationURL, {
134
+ fallback: (text, url) => `${text}: ${url}`
53
135
  });
54
136
  }
55
137
 
@@ -5,20 +5,26 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.relativeBundlePath = relativeBundlePath;
7
7
 
8
- var _path = _interopRequireDefault(require("path"));
8
+ function _path() {
9
+ const data = _interopRequireDefault(require("path"));
9
10
 
10
- var _nullthrows = _interopRequireDefault(require("nullthrows"));
11
+ _path = function () {
12
+ return data;
13
+ };
14
+
15
+ return data;
16
+ }
17
+
18
+ var _path2 = require("./path");
11
19
 
12
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
21
 
14
22
  function relativeBundlePath(from, to, opts = {
15
23
  leadingDotSlash: true
16
24
  }) {
17
- let p = _path.default.relative(_path.default.dirname((0, _nullthrows.default)(from.filePath)), (0, _nullthrows.default)(to.filePath)).replace(/\\/g, '/');
25
+ let fromPath = _path().default.join(from.target.distDir, from.name);
18
26
 
19
- if (opts.leadingDotSlash && p[0] !== '.') {
20
- p = './' + p;
21
- }
27
+ let toPath = _path().default.join(to.target.distDir, to.name);
22
28
 
23
- return p;
29
+ return (0, _path2.relativePath)(_path().default.dirname(fromPath), toPath, opts.leadingDotSlash);
24
30
  }
@@ -5,12 +5,28 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = relativeUrl;
7
7
 
8
- var _path = _interopRequireDefault(require("path"));
8
+ function _path() {
9
+ const data = _interopRequireDefault(require("path"));
9
10
 
10
- var _url = _interopRequireDefault(require("url"));
11
+ _path = function () {
12
+ return data;
13
+ };
14
+
15
+ return data;
16
+ }
17
+
18
+ function _url() {
19
+ const data = _interopRequireDefault(require("url"));
20
+
21
+ _url = function () {
22
+ return data;
23
+ };
24
+
25
+ return data;
26
+ }
11
27
 
12
28
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
29
 
14
30
  function relativeUrl(from, to) {
15
- return _url.default.format(_url.default.parse(_path.default.relative(from, to)));
31
+ return _url().default.format(_url().default.parse(_path().default.relative(from, to)));
16
32
  }
@@ -5,20 +5,55 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.replaceURLReferences = replaceURLReferences;
7
7
  exports.replaceInlineReferences = replaceInlineReferences;
8
+ exports.getURLReplacement = getURLReplacement;
8
9
 
9
- var _stream = require("stream");
10
+ function _stream() {
11
+ const data = require("stream");
10
12
 
11
- var _nullthrows = _interopRequireDefault(require("nullthrows"));
13
+ _stream = function () {
14
+ return data;
15
+ };
16
+
17
+ return data;
18
+ }
19
+
20
+ function _nullthrows() {
21
+ const data = _interopRequireDefault(require("nullthrows"));
22
+
23
+ _nullthrows = function () {
24
+ return data;
25
+ };
26
+
27
+ return data;
28
+ }
29
+
30
+ function _assert() {
31
+ const data = _interopRequireDefault(require("assert"));
32
+
33
+ _assert = function () {
34
+ return data;
35
+ };
36
+
37
+ return data;
38
+ }
12
39
 
13
- var _url = _interopRequireDefault(require("url"));
40
+ function _url() {
41
+ const data = _interopRequireDefault(require("url"));
14
42
 
15
- var _ = require("../");
43
+ _url = function () {
44
+ return data;
45
+ };
46
+
47
+ return data;
48
+ }
49
+
50
+ var _ = require("./");
16
51
 
17
52
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
53
 
19
54
  /*
20
55
  * Replaces references to dependency ids for URL dependencies with:
21
- * - in the case of an unresolvable url dependency, the original moduleSpecifier.
56
+ * - in the case of an unresolvable url dependency, the original specifier.
22
57
  * These are external requests that Parcel did not bundle.
23
58
  * - in the case of a reference to another bundle, the relative url to that
24
59
  * bundle from the current bundle.
@@ -31,34 +66,42 @@ function replaceURLReferences({
31
66
  relative = true
32
67
  }) {
33
68
  let replacements = new Map();
69
+ let urlDependencies = [];
70
+ bundle.traverse(node => {
71
+ if (node.type === 'dependency' && node.value.specifierType === 'url') {
72
+ urlDependencies.push(node.value);
73
+ }
74
+ });
75
+
76
+ for (let dependency of urlDependencies) {
77
+ var _dependency$meta$plac, _dependency$meta;
34
78
 
35
- for (let dependency of bundleGraph.getExternalDependencies(bundle)) {
36
- if (!dependency.isURL) {
79
+ if (dependency.specifierType !== 'url') {
37
80
  continue;
38
81
  }
39
82
 
40
- let bundleGroup = bundleGraph.resolveExternalDependency(dependency);
83
+ let placeholder = (_dependency$meta$plac = (_dependency$meta = dependency.meta) === null || _dependency$meta === void 0 ? void 0 : _dependency$meta.placeholder) !== null && _dependency$meta$plac !== void 0 ? _dependency$meta$plac : dependency.id;
84
+ (0, _assert().default)(typeof placeholder === 'string');
85
+ let resolved = bundleGraph.getReferencedBundle(dependency, bundle);
41
86
 
42
- if (bundleGroup == null) {
43
- replacements.set(dependency.id, {
44
- from: dependency.id,
45
- to: dependency.moduleSpecifier
87
+ if (resolved == null) {
88
+ replacements.set(placeholder, {
89
+ from: placeholder,
90
+ to: dependency.specifier
46
91
  });
47
92
  continue;
48
93
  }
49
94
 
50
- let [entryBundle] = bundleGraph.getBundlesInBundleGroup(bundleGroup);
51
-
52
- if (entryBundle.isInline) {
95
+ if (!resolved || resolved.bundleBehavior === 'inline') {
53
96
  // If a bundle is inline, it should be replaced with inline contents,
54
97
  // not a URL.
55
98
  continue;
56
99
  }
57
100
 
58
- replacements.set(dependency.id, getURLReplacement({
101
+ replacements.set(placeholder, getURLReplacement({
59
102
  dependency,
60
103
  fromBundle: bundle,
61
- toBundle: entryBundle,
104
+ toBundle: resolved,
62
105
  relative
63
106
  }));
64
107
  }
@@ -80,23 +123,23 @@ async function replaceInlineReferences({
80
123
  getInlineBundleContents
81
124
  }) {
82
125
  let replacements = new Map();
83
-
84
- for (let dependency of bundleGraph.getExternalDependencies(bundle)) {
85
- let bundleGroup = bundleGraph.resolveExternalDependency(dependency);
86
-
87
- if (bundleGroup == null) {
88
- continue;
126
+ let dependencies = [];
127
+ bundle.traverse(node => {
128
+ if (node.type === 'dependency') {
129
+ dependencies.push(node.value);
89
130
  }
131
+ });
90
132
 
91
- let [entryBundle] = bundleGraph.getBundlesInBundleGroup(bundleGroup);
133
+ for (let dependency of dependencies) {
134
+ let entryBundle = bundleGraph.getReferencedBundle(dependency, bundle);
92
135
 
93
- if (!entryBundle.isInline) {
136
+ if ((entryBundle === null || entryBundle === void 0 ? void 0 : entryBundle.bundleBehavior) !== 'inline') {
94
137
  continue;
95
138
  }
96
139
 
97
140
  let packagedBundle = await getInlineBundleContents(entryBundle, bundleGraph);
98
- let packagedContents = (packagedBundle.contents instanceof _stream.Readable ? await (0, _.bufferStream)(packagedBundle.contents) : packagedBundle.contents).toString();
99
- let inlineType = (0, _nullthrows.default)(entryBundle.getMainEntry()).meta.inlineType;
141
+ let packagedContents = (packagedBundle.contents instanceof _stream().Readable ? await (0, _.bufferStream)(packagedBundle.contents) : packagedBundle.contents).toString();
142
+ let inlineType = (0, _nullthrows().default)(entryBundle.getMainEntry()).meta.inlineType;
100
143
 
101
144
  if (inlineType == null || inlineType === 'string') {
102
145
  replacements.set(dependency.id, getInlineReplacement(dependency, inlineType, packagedContents));
@@ -112,22 +155,35 @@ function getURLReplacement({
112
155
  toBundle,
113
156
  relative
114
157
  }) {
115
- let url = _url.default.parse(dependency.moduleSpecifier);
158
+ var _dependency$meta$plac2, _dependency$meta2;
116
159
 
117
160
  let to;
118
161
 
162
+ let orig = _url().default.parse(dependency.specifier);
163
+
119
164
  if (relative) {
120
- url.pathname = (0, _.relativeBundlePath)(fromBundle, toBundle, {
121
- leadingDotSlash: false
122
- });
123
- to = _url.default.format(url);
165
+ to = _url().default.format({
166
+ pathname: (0, _.relativeBundlePath)(fromBundle, toBundle, {
167
+ leadingDotSlash: false
168
+ }),
169
+ hash: orig.hash
170
+ }); // If the resulting path includes a colon character and doesn't start with a ./ or ../
171
+ // we need to add one so that the first part before the colon isn't parsed as a URL protocol.
172
+
173
+ if (to.includes(':') && !to.startsWith('./') && !to.startsWith('../')) {
174
+ to = './' + to;
175
+ }
124
176
  } else {
125
- url.pathname = (0, _nullthrows.default)(toBundle.name);
126
- to = (0, _.urlJoin)((0, _nullthrows.default)(toBundle.target.publicUrl), _url.default.format(url));
177
+ to = (0, _.urlJoin)(toBundle.target.publicUrl, _url().default.format({
178
+ pathname: (0, _nullthrows().default)(toBundle.name),
179
+ hash: orig.hash
180
+ }));
127
181
  }
128
182
 
183
+ let placeholder = (_dependency$meta$plac2 = (_dependency$meta2 = dependency.meta) === null || _dependency$meta2 === void 0 ? void 0 : _dependency$meta2.placeholder) !== null && _dependency$meta$plac2 !== void 0 ? _dependency$meta$plac2 : dependency.id;
184
+ (0, _assert().default)(typeof placeholder === 'string');
129
185
  return {
130
- from: dependency.id,
186
+ from: placeholder,
131
187
  to
132
188
  };
133
189
  }