@parcel/utils 2.0.0-nightly.97 → 2.0.0-nightly.982
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.
- package/.eslintrc.js +6 -6
- package/lib/DefaultMap.js +0 -8
- package/lib/Deferred.js +10 -2
- package/lib/PromiseQueue.js +21 -30
- package/lib/TapStream.js +10 -10
- package/lib/alternatives.js +134 -0
- package/lib/ansi-html.js +10 -2
- package/lib/blob.js +26 -8
- package/lib/collection.js +14 -11
- package/lib/config.js +145 -35
- package/lib/countLines.js +2 -2
- package/lib/dependency-location.js +3 -3
- package/lib/generateBuildMetrics.js +148 -0
- package/lib/generateCertificate.js +33 -8
- package/lib/getExisting.js +11 -3
- package/lib/getRootDir.js +18 -7
- package/lib/glob.js +53 -19
- package/lib/hash.js +44 -0
- package/lib/http-server.js +48 -10
- package/lib/index.js +298 -224
- package/lib/is-url.js +12 -2
- package/lib/isDirectoryInside.js +24 -0
- package/lib/objectHash.js +10 -2
- package/lib/openInBrowser.js +94 -0
- package/lib/path.js +33 -6
- package/lib/prettyDiagnostic.js +107 -25
- package/lib/relativeBundlePath.js +13 -7
- package/lib/relativeUrl.js +19 -3
- package/lib/replaceBundleReferences.js +96 -36
- package/lib/schema.js +104 -33
- package/lib/shared-buffer.js +31 -0
- package/lib/sourcemap.js +147 -0
- package/lib/stream.js +38 -3
- package/lib/urlJoin.js +25 -6
- package/package.json +27 -16
- package/src/DefaultMap.js +1 -1
- package/src/PromiseQueue.js +16 -12
- package/src/alternatives.js +143 -0
- package/src/ansi-html.js +2 -2
- package/src/blob.js +4 -3
- package/src/bundle-url.js +1 -1
- package/src/collection.js +14 -14
- package/src/config.js +100 -35
- package/src/countLines.js +5 -2
- package/src/debounce.js +1 -1
- package/src/dependency-location.js +11 -6
- package/src/generateBuildMetrics.js +158 -0
- package/src/generateCertificate.js +1 -1
- package/src/getCertificate.js +1 -1
- package/src/getExisting.js +1 -4
- package/src/getRootDir.js +1 -2
- package/src/glob.js +29 -11
- package/src/hash.js +34 -0
- package/src/http-server.js +10 -12
- package/src/index.js +52 -23
- package/src/is-url.js +1 -1
- package/src/isDirectoryInside.js +11 -0
- package/src/openInBrowser.js +64 -0
- package/src/path.js +38 -6
- package/src/prettyDiagnostic.js +58 -24
- package/src/relativeBundlePath.js +8 -13
- package/src/replaceBundleReferences.js +78 -40
- package/src/schema.js +101 -44
- package/src/shared-buffer.js +24 -0
- package/src/sourcemap.js +135 -0
- package/src/stream.js +31 -1
- package/src/urlJoin.js +3 -1
- package/test/DefaultMap.test.js +7 -4
- package/test/config.test.js +50 -0
- package/test/input/config/config.json +3 -0
- package/test/input/config/empty.json +0 -0
- package/test/input/config/empty.toml +0 -0
- package/test/input/sourcemap/referenced-min.js +2 -0
- package/test/input/sourcemap/referenced-min.js.map +6 -0
- package/test/input/sourcemap/source-root.js +2 -0
- package/test/input/sourcemap/source-root.js.map +7 -0
- package/test/objectHash.test.js +33 -0
- package/test/prettifyTime.test.js +17 -0
- package/test/replaceBundleReferences.test.js +268 -0
- package/test/sourcemap.test.js +207 -0
- package/test/throttle.test.js +1 -2
- package/test/urlJoin.test.js +37 -0
- package/lib/generateBundleReport.js +0 -38
- package/lib/loadSourceMapUrl.js +0 -33
- package/lib/md5.js +0 -35
- package/lib/prettyError.js +0 -43
- package/lib/promisify.js +0 -13
- package/lib/resolve.js +0 -93
- package/lib/serializeObject.js +0 -28
- package/src/.babelrc +0 -3
- package/src/generateBundleReport.js +0 -51
- package/src/loadSourceMapUrl.js +0 -33
- package/src/md5.js +0 -44
- package/src/prettyError.js +0 -54
- package/src/promisify.js +0 -13
- package/src/resolve.js +0 -123
- package/src/serializeObject.js +0 -22
- package/test/input/sourcemap/referenced.js +0 -7
- package/test/loadSourceMapUrl.test.js +0 -37
- 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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
18
|
-
|
|
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
|
|
48
|
+
return normalizePath(_path().default.relative(from, to), leadingDotSlash);
|
|
22
49
|
}
|
package/lib/prettyDiagnostic.js
CHANGED
|
@@ -5,51 +5,133 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = prettyDiagnostic;
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
function _codeframe() {
|
|
9
|
+
const data = _interopRequireDefault(require("@parcel/codeframe"));
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
_codeframe = function () {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
11
14
|
|
|
12
|
-
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
13
17
|
|
|
14
|
-
|
|
18
|
+
function _markdownAnsi() {
|
|
19
|
+
const data = _interopRequireDefault(require("@parcel/markdown-ansi"));
|
|
15
20
|
|
|
16
|
-
function
|
|
21
|
+
_markdownAnsi = function () {
|
|
22
|
+
return data;
|
|
23
|
+
};
|
|
17
24
|
|
|
18
|
-
|
|
19
|
-
|
|
25
|
+
return data;
|
|
26
|
+
}
|
|
20
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
|
+
};
|
|
54
|
+
|
|
55
|
+
return data;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function _terminalLink() {
|
|
59
|
+
const data = _interopRequireDefault(require("terminal-link"));
|
|
60
|
+
|
|
61
|
+
_terminalLink = function () {
|
|
62
|
+
return data;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
return data;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
69
|
+
|
|
70
|
+
// $FlowFixMe
|
|
71
|
+
async function prettyDiagnostic(diagnostic, options, terminalWidth) {
|
|
21
72
|
let {
|
|
22
73
|
origin,
|
|
23
74
|
message,
|
|
24
75
|
stack,
|
|
25
|
-
|
|
76
|
+
codeFrames,
|
|
26
77
|
hints,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
skipFormatting
|
|
78
|
+
skipFormatting,
|
|
79
|
+
documentationURL
|
|
30
80
|
} = diagnostic;
|
|
31
81
|
let result = {
|
|
32
|
-
message: (0, _markdownAnsi.default)(`**${origin !== null && origin !== void 0 ? origin : 'unknown'}**: `) + (skipFormatting ? message : (0, _markdownAnsi.default)(message)),
|
|
33
|
-
stack:
|
|
82
|
+
message: (0, _markdownAnsi().default)(`**${origin !== null && origin !== void 0 ? origin : 'unknown'}**: `) + (skipFormatting ? message : (0, _markdownAnsi().default)(message)),
|
|
83
|
+
stack: '',
|
|
34
84
|
codeframe: '',
|
|
35
|
-
hints: []
|
|
85
|
+
hints: [],
|
|
86
|
+
documentation: ''
|
|
36
87
|
};
|
|
37
88
|
|
|
38
|
-
if (
|
|
39
|
-
let
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
8
|
+
function _path() {
|
|
9
|
+
const data = _interopRequireDefault(require("path"));
|
|
9
10
|
|
|
10
|
-
|
|
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
|
|
25
|
+
let fromPath = _path().default.join(from.target.distDir, from.name);
|
|
18
26
|
|
|
19
|
-
|
|
20
|
-
p = './' + p;
|
|
21
|
-
}
|
|
27
|
+
let toPath = _path().default.join(to.target.distDir, to.name);
|
|
22
28
|
|
|
23
|
-
return
|
|
29
|
+
return (0, _path2.relativePath)(_path().default.dirname(fromPath), toPath, opts.leadingDotSlash);
|
|
24
30
|
}
|
package/lib/relativeUrl.js
CHANGED
|
@@ -5,12 +5,28 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = relativeUrl;
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
function _path() {
|
|
9
|
+
const data = _interopRequireDefault(require("path"));
|
|
9
10
|
|
|
10
|
-
|
|
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
|
-
|
|
10
|
+
function _stream() {
|
|
11
|
+
const data = require("stream");
|
|
10
12
|
|
|
11
|
-
|
|
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"));
|
|
12
32
|
|
|
13
|
-
|
|
33
|
+
_assert = function () {
|
|
34
|
+
return data;
|
|
35
|
+
};
|
|
14
36
|
|
|
15
|
-
|
|
37
|
+
return data;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function _url() {
|
|
41
|
+
const data = _interopRequireDefault(require("url"));
|
|
42
|
+
|
|
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
|
|
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
|
+
});
|
|
34
75
|
|
|
35
|
-
for (let dependency of
|
|
36
|
-
|
|
76
|
+
for (let dependency of urlDependencies) {
|
|
77
|
+
var _dependency$meta$plac, _dependency$meta;
|
|
78
|
+
|
|
79
|
+
if (dependency.specifierType !== 'url') {
|
|
37
80
|
continue;
|
|
38
81
|
}
|
|
39
82
|
|
|
40
|
-
let
|
|
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 (
|
|
43
|
-
replacements.set(
|
|
44
|
-
from:
|
|
45
|
-
to: dependency.
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
if (entryBundle.isInline) {
|
|
95
|
+
if (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(
|
|
101
|
+
replacements.set(placeholder, getURLReplacement({
|
|
59
102
|
dependency,
|
|
60
103
|
fromBundle: bundle,
|
|
61
|
-
toBundle:
|
|
104
|
+
toBundle: resolved,
|
|
62
105
|
relative
|
|
63
106
|
}));
|
|
64
107
|
}
|
|
@@ -80,26 +123,30 @@ async function replaceInlineReferences({
|
|
|
80
123
|
getInlineBundleContents
|
|
81
124
|
}) {
|
|
82
125
|
let replacements = new Map();
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
133
|
+
for (let dependency of dependencies) {
|
|
134
|
+
let entryBundle = bundleGraph.getReferencedBundle(dependency, bundle);
|
|
92
135
|
|
|
93
|
-
if (
|
|
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
|
+
var _dependency$meta$plac2, _dependency$meta2;
|
|
146
|
+
|
|
147
|
+
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;
|
|
148
|
+
(0, _assert().default)(typeof placeholder === 'string');
|
|
149
|
+
replacements.set(placeholder, getInlineReplacement(dependency, inlineType, packagedContents));
|
|
103
150
|
}
|
|
104
151
|
}
|
|
105
152
|
|
|
@@ -112,22 +159,35 @@ function getURLReplacement({
|
|
|
112
159
|
toBundle,
|
|
113
160
|
relative
|
|
114
161
|
}) {
|
|
115
|
-
|
|
162
|
+
var _dependency$meta$plac3, _dependency$meta3;
|
|
116
163
|
|
|
117
164
|
let to;
|
|
118
165
|
|
|
166
|
+
let orig = _url().default.parse(dependency.specifier);
|
|
167
|
+
|
|
119
168
|
if (relative) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
169
|
+
to = _url().default.format({
|
|
170
|
+
pathname: (0, _.relativeBundlePath)(fromBundle, toBundle, {
|
|
171
|
+
leadingDotSlash: false
|
|
172
|
+
}),
|
|
173
|
+
hash: orig.hash
|
|
174
|
+
}); // If the resulting path includes a colon character and doesn't start with a ./ or ../
|
|
175
|
+
// we need to add one so that the first part before the colon isn't parsed as a URL protocol.
|
|
176
|
+
|
|
177
|
+
if (to.includes(':') && !to.startsWith('./') && !to.startsWith('../')) {
|
|
178
|
+
to = './' + to;
|
|
179
|
+
}
|
|
124
180
|
} else {
|
|
125
|
-
|
|
126
|
-
|
|
181
|
+
to = (0, _.urlJoin)(toBundle.target.publicUrl, _url().default.format({
|
|
182
|
+
pathname: (0, _nullthrows().default)(toBundle.name),
|
|
183
|
+
hash: orig.hash
|
|
184
|
+
}));
|
|
127
185
|
}
|
|
128
186
|
|
|
187
|
+
let placeholder = (_dependency$meta$plac3 = (_dependency$meta3 = dependency.meta) === null || _dependency$meta3 === void 0 ? void 0 : _dependency$meta3.placeholder) !== null && _dependency$meta$plac3 !== void 0 ? _dependency$meta$plac3 : dependency.id;
|
|
188
|
+
(0, _assert().default)(typeof placeholder === 'string');
|
|
129
189
|
return {
|
|
130
|
-
from:
|
|
190
|
+
from: placeholder,
|
|
131
191
|
to
|
|
132
192
|
};
|
|
133
193
|
}
|