@atlaspack/utils 2.14.5-canary.34 → 2.14.5-canary.341
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/CHANGELOG.md +446 -0
- package/benchmark.js +23 -0
- package/dist/DefaultMap.js +41 -0
- package/dist/Deferred.js +16 -0
- package/dist/PromiseQueue.js +107 -0
- package/dist/TapStream.js +23 -0
- package/dist/alternatives.js +97 -0
- package/dist/ansi-html.js +12 -0
- package/dist/blob.js +29 -0
- package/dist/bundle-url.js +32 -0
- package/dist/collection.js +106 -0
- package/dist/config.js +138 -0
- package/dist/countLines.js +12 -0
- package/dist/debounce.js +15 -0
- package/dist/debug-tools.js +39 -0
- package/dist/dependency-location.js +22 -0
- package/dist/escape-html.js +19 -0
- package/dist/generateBuildMetrics.js +111 -0
- package/dist/generateCertificate.js +124 -0
- package/dist/getCertificate.js +13 -0
- package/dist/getExisting.js +20 -0
- package/dist/getModuleParts.js +27 -0
- package/dist/getRootDir.js +46 -0
- package/dist/getTimeId.js +13 -0
- package/dist/glob.js +129 -0
- package/dist/hash.js +45 -0
- package/dist/http-server.js +55 -0
- package/dist/index.js +148 -0
- package/dist/is-url.js +15 -0
- package/dist/isDirectoryInside.js +11 -0
- package/dist/objectHash.js +20 -0
- package/dist/openInBrowser.js +61 -0
- package/dist/parseCSSImport.js +14 -0
- package/dist/path.js +36 -0
- package/dist/prettifyTime.js +6 -0
- package/dist/prettyDiagnostic.js +104 -0
- package/dist/progress-message.js +31 -0
- package/dist/relativeBundlePath.js +13 -0
- package/dist/relativeUrl.js +11 -0
- package/dist/replaceBundleReferences.js +131 -0
- package/dist/schema.js +404 -0
- package/dist/shared-buffer.js +24 -0
- package/dist/sourcemap.js +121 -0
- package/dist/stream.js +69 -0
- package/dist/throttle.js +12 -0
- package/dist/urlJoin.js +22 -0
- package/lib/DefaultMap.js +42 -0
- package/lib/Deferred.js +30 -0
- package/lib/PromiseQueue.js +112 -0
- package/lib/TapStream.js +34 -0
- package/lib/alternatives.js +116 -0
- package/lib/ansi-html.js +20 -0
- package/lib/blob.js +40 -0
- package/lib/bundle-url.js +34 -0
- package/lib/collection.js +111 -0
- package/lib/config.js +174 -0
- package/lib/countLines.js +15 -0
- package/lib/debounce.js +18 -0
- package/lib/debug-tools.js +40 -0
- package/lib/dependency-location.js +21 -0
- package/lib/escape-html.js +22 -0
- package/lib/generateBuildMetrics.js +121 -0
- package/lib/generateCertificate.js +129 -0
- package/lib/getCertificate.js +18 -0
- package/lib/getExisting.js +25 -0
- package/lib/getModuleParts.js +30 -0
- package/lib/getRootDir.js +52 -0
- package/lib/getTimeId.js +10 -0
- package/lib/glob.js +110 -0
- package/lib/hash.js +50 -0
- package/lib/http-server.js +85 -0
- package/lib/index.js +643 -37310
- package/lib/is-url.js +24 -0
- package/lib/isDirectoryInside.js +18 -0
- package/lib/objectHash.js +26 -0
- package/lib/openInBrowser.js +74 -0
- package/lib/parseCSSImport.js +15 -0
- package/lib/path.js +39 -0
- package/lib/prettifyTime.js +9 -0
- package/lib/prettyDiagnostic.js +150 -0
- package/lib/progress-message.js +39 -0
- package/lib/relativeBundlePath.js +22 -0
- package/lib/relativeUrl.js +24 -0
- package/lib/replaceBundleReferences.js +182 -0
- package/lib/schema.js +353 -0
- package/lib/shared-buffer.js +31 -0
- package/lib/sourcemap.js +138 -0
- package/lib/stream.js +76 -0
- package/lib/throttle.js +15 -0
- package/lib/types/DefaultMap.d.ts +13 -0
- package/lib/types/Deferred.d.ts +8 -0
- package/lib/types/PromiseQueue.d.ts +25 -0
- package/lib/types/TapStream.d.ts +6 -0
- package/lib/types/alternatives.d.ts +3 -0
- package/lib/types/ansi-html.d.ts +1 -0
- package/lib/types/blob.d.ts +4 -0
- package/lib/types/bundle-url.d.ts +4 -0
- package/lib/types/collection.d.ts +33 -0
- package/lib/types/config.d.ts +17 -0
- package/lib/types/countLines.d.ts +1 -0
- package/lib/types/debounce.d.ts +1 -0
- package/lib/types/debug-tools.d.ts +8 -0
- package/lib/types/dependency-location.d.ts +14 -0
- package/lib/types/escape-html.d.ts +1 -0
- package/lib/types/generateBuildMetrics.d.ts +18 -0
- package/lib/types/generateCertificate.d.ts +5 -0
- package/lib/types/getCertificate.d.ts +5 -0
- package/lib/types/getExisting.d.ts +8 -0
- package/lib/types/getModuleParts.d.ts +4 -0
- package/lib/types/getRootDir.d.ts +2 -0
- package/lib/types/getTimeId.d.ts +1 -0
- package/lib/types/glob.d.ts +9 -0
- package/lib/types/hash.d.ts +7 -0
- package/lib/types/http-server.d.ts +19 -0
- package/lib/types/index.d.ts +49 -0
- package/lib/types/is-url.d.ts +1 -0
- package/lib/types/isDirectoryInside.d.ts +2 -0
- package/lib/types/objectHash.d.ts +3 -0
- package/lib/types/openInBrowser.d.ts +1 -0
- package/lib/types/parseCSSImport.d.ts +1 -0
- package/lib/types/path.d.ts +8 -0
- package/lib/types/prettifyTime.d.ts +1 -0
- package/lib/types/prettyDiagnostic.d.ts +17 -0
- package/lib/types/progress-message.d.ts +3 -0
- package/lib/types/relativeBundlePath.d.ts +4 -0
- package/lib/types/relativeUrl.d.ts +1 -0
- package/lib/types/replaceBundleReferences.d.ts +39 -0
- package/lib/types/schema.d.ts +107 -0
- package/lib/types/shared-buffer.d.ts +2 -0
- package/lib/types/sourcemap.d.ts +15 -0
- package/lib/types/stream.d.ts +8 -0
- package/lib/types/throttle.d.ts +1 -0
- package/lib/types/urlJoin.d.ts +5 -0
- package/lib/urlJoin.js +35 -0
- package/package.json +27 -18
- package/src/{DefaultMap.js → DefaultMap.ts} +8 -12
- package/src/Deferred.ts +26 -0
- package/src/{PromiseQueue.js → PromiseQueue.ts} +40 -35
- package/src/{TapStream.js → TapStream.ts} +8 -7
- package/src/{alternatives.js → alternatives.ts} +15 -16
- package/src/{ansi-html.js → ansi-html.ts} +1 -1
- package/src/{blob.js → blob.ts} +3 -5
- package/src/{bundle-url.js → bundle-url.ts} +3 -5
- package/src/{collection.js → collection.ts} +23 -20
- package/src/{config.js → config.ts} +20 -21
- package/src/{countLines.js → countLines.ts} +0 -2
- package/src/{debounce.js → debounce.ts} +3 -5
- package/src/debug-tools.ts +48 -0
- package/src/{dependency-location.js → dependency-location.ts} +15 -11
- package/src/{escape-html.js → escape-html.ts} +5 -3
- package/src/{generateBuildMetrics.js → generateBuildMetrics.ts} +19 -21
- package/src/{generateCertificate.js → generateCertificate.ts} +8 -6
- package/src/{getCertificate.js → getCertificate.ts} +6 -5
- package/src/{getExisting.js → getExisting.ts} +4 -3
- package/src/{getModuleParts.js → getModuleParts.ts} +3 -2
- package/src/{getRootDir.js → getRootDir.ts} +1 -3
- package/src/getTimeId.ts +12 -0
- package/src/{glob.js → glob.ts} +13 -14
- package/src/{hash.js → hash.ts} +23 -18
- package/src/{http-server.js → http-server.ts} +34 -40
- package/src/{index.js → index.ts} +14 -10
- package/src/{is-url.js → is-url.ts} +1 -2
- package/src/{isDirectoryInside.js → isDirectoryInside.ts} +1 -2
- package/src/{objectHash.js → objectHash.ts} +1 -4
- package/src/{openInBrowser.js → openInBrowser.ts} +2 -4
- package/src/{parseCSSImport.js → parseCSSImport.ts} +0 -2
- package/src/{path.js → path.ts} +2 -4
- package/src/{prettifyTime.js → prettifyTime.ts} +0 -2
- package/src/{prettyDiagnostic.js → prettyDiagnostic.ts} +34 -22
- package/src/progress-message.ts +43 -0
- package/src/{relativeBundlePath.js → relativeBundlePath.ts} +4 -4
- package/src/{relativeUrl.js → relativeUrl.ts} +0 -1
- package/src/{replaceBundleReferences.js → replaceBundleReferences.ts} +67 -51
- package/src/schema.ts +552 -0
- package/src/{shared-buffer.js → shared-buffer.ts} +5 -3
- package/src/{sourcemap.js → sourcemap.ts} +28 -10
- package/src/{stream.js → stream.ts} +30 -22
- package/src/throttle.ts +13 -0
- package/src/{urlJoin.js → urlJoin.ts} +1 -3
- package/test/{DefaultMap.test.js → DefaultMap.test.ts} +4 -6
- package/test/{PromiseQueue.test.js → PromiseQueue.test.ts} +5 -6
- package/test/{collection.test.js → collection.test.ts} +0 -2
- package/test/{config.test.js → config.test.ts} +0 -3
- package/test/{objectHash.test.js → objectHash.test.ts} +4 -5
- package/test/{prettifyTime.test.js → prettifyTime.test.ts} +0 -1
- package/test/{replaceBundleReferences.test.js → replaceBundleReferences.test.ts} +0 -32
- package/test/schema.test.ts +748 -0
- package/test/{sourcemap.test.js → sourcemap.test.ts} +0 -1
- package/test/{throttle.test.js → throttle.test.ts} +1 -3
- package/test/{urlJoin.test.js → urlJoin.test.ts} +0 -2
- package/tsconfig.json +36 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/lib/index.js.map +0 -1
- package/src/Deferred.js +0 -23
- package/src/progress-message.js +0 -22
- package/src/schema.js +0 -504
- package/src/throttle.js +0 -15
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = objectHash;
|
|
7
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
8
|
+
function objectHash(object) {
|
|
9
|
+
let hash = crypto_1.default.createHash('md5');
|
|
10
|
+
for (let key of Object.keys(object).sort()) {
|
|
11
|
+
let val = object[key];
|
|
12
|
+
if (typeof val === 'object' && val) {
|
|
13
|
+
hash.update(key + objectHash(val));
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
hash.update(key + val);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return hash.digest('hex');
|
|
20
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = openInBrowser;
|
|
7
|
+
const open_1 = __importDefault(require("open"));
|
|
8
|
+
const child_process_1 = require("child_process");
|
|
9
|
+
const logger_1 = __importDefault(require("@atlaspack/logger"));
|
|
10
|
+
// Chrome app name is platform dependent. we should not hard code it.
|
|
11
|
+
// https://github.com/react-native-community/cli/blob/e2be8a905285d9b37512fc78c9755b9635ecf805/packages/cli/src/commands/server/launchDebugger.ts#L28
|
|
12
|
+
function getChromeAppName() {
|
|
13
|
+
switch (process.platform) {
|
|
14
|
+
case 'darwin':
|
|
15
|
+
return 'google chrome';
|
|
16
|
+
case 'win32':
|
|
17
|
+
return 'chrome';
|
|
18
|
+
case 'linux':
|
|
19
|
+
if (commandExistsUnixSync('google-chrome')) {
|
|
20
|
+
return 'google-chrome';
|
|
21
|
+
}
|
|
22
|
+
if (commandExistsUnixSync('chromium-browser')) {
|
|
23
|
+
return 'chromium-browser';
|
|
24
|
+
}
|
|
25
|
+
return 'chromium';
|
|
26
|
+
default:
|
|
27
|
+
return 'google-chrome';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function commandExistsUnixSync(commandName) {
|
|
31
|
+
try {
|
|
32
|
+
const stdout = (0, child_process_1.execSync)(`command -v ${commandName} 2>/dev/null` +
|
|
33
|
+
` && { echo >&1 '${commandName} found'; exit 0; }`);
|
|
34
|
+
return !!stdout;
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function getAppName(appName) {
|
|
41
|
+
if (['google', 'chrome'].includes(appName)) {
|
|
42
|
+
return getChromeAppName();
|
|
43
|
+
}
|
|
44
|
+
else if (['brave', 'Brave'].includes(appName)) {
|
|
45
|
+
return 'Brave Browser';
|
|
46
|
+
}
|
|
47
|
+
else
|
|
48
|
+
return appName;
|
|
49
|
+
}
|
|
50
|
+
async function openInBrowser(url, browser) {
|
|
51
|
+
try {
|
|
52
|
+
const options = typeof browser === 'string' && browser.length > 0
|
|
53
|
+
? { app: [getAppName(browser)] }
|
|
54
|
+
: undefined;
|
|
55
|
+
await (0, open_1.default)(url, options);
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
logger_1.default.error(`Unexpected error while opening in browser: ${browser}`, '@atlaspack/utils');
|
|
59
|
+
logger_1.default.error(err, '@atlaspack/utils');
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = parseCSSImport;
|
|
4
|
+
function parseCSSImport(url) {
|
|
5
|
+
if (!/^(~|\.\/|\/)/.test(url)) {
|
|
6
|
+
return './' + url;
|
|
7
|
+
}
|
|
8
|
+
else if (!/^(~\/|\.\/|\/)/.test(url)) {
|
|
9
|
+
return url.substring(1);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
return url;
|
|
13
|
+
}
|
|
14
|
+
}
|
package/dist/path.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isAbsolute = isAbsolute;
|
|
7
|
+
exports.normalizeSeparators = normalizeSeparators;
|
|
8
|
+
exports.normalizePath = normalizePath;
|
|
9
|
+
exports.relativePath = relativePath;
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const ABSOLUTE_PATH_REGEX = /^([a-zA-Z]:){0,1}[\\/]+/;
|
|
12
|
+
const SEPARATOR_REGEX = /[\\]+/g;
|
|
13
|
+
function isAbsolute(filepath) {
|
|
14
|
+
return ABSOLUTE_PATH_REGEX.test(filepath);
|
|
15
|
+
}
|
|
16
|
+
function normalizeSeparators(filePath) {
|
|
17
|
+
return filePath.replace(SEPARATOR_REGEX, '/');
|
|
18
|
+
}
|
|
19
|
+
function normalizePath(filePath, leadingDotSlash = true) {
|
|
20
|
+
if (leadingDotSlash &&
|
|
21
|
+
(filePath[0] !== '.' ||
|
|
22
|
+
(filePath[1] !== '.' && filePath[1] !== '/' && filePath[1] !== '\\')) &&
|
|
23
|
+
!path_1.default.isAbsolute(filePath)) {
|
|
24
|
+
return normalizeSeparators('./' + filePath);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
return normalizeSeparators(filePath);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function relativePath(from, to, leadingDotSlash = true) {
|
|
31
|
+
// Fast path
|
|
32
|
+
if (to.startsWith(from + '/')) {
|
|
33
|
+
return (leadingDotSlash ? './' : '') + to.slice(from.length + 1);
|
|
34
|
+
}
|
|
35
|
+
return normalizePath(path_1.default.relative(from, to), leadingDotSlash);
|
|
36
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = prettyDiagnostic;
|
|
7
|
+
const codeframe_1 = __importDefault(require("@atlaspack/codeframe"));
|
|
8
|
+
const logger_1 = __importDefault(require("@atlaspack/logger"));
|
|
9
|
+
const markdown_ansi_1 = __importDefault(require("@atlaspack/markdown-ansi"));
|
|
10
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
11
|
+
const path_1 = __importDefault(require("path"));
|
|
12
|
+
const terminal_link_1 = __importDefault(require("terminal-link"));
|
|
13
|
+
/* eslint-disable import/no-extraneous-dependencies */
|
|
14
|
+
const snarkdown_1 = __importDefault(require("snarkdown"));
|
|
15
|
+
async function prettyDiagnostic(diagnostic, options, terminalWidth, format = 'ansi') {
|
|
16
|
+
let { origin, message, stack, codeFrames, hints, skipFormatting, documentationURL, } = diagnostic;
|
|
17
|
+
const md = format === 'ansi' ? markdown_ansi_1.default : snarkdown_1.default;
|
|
18
|
+
const terminalLink = format === 'ansi'
|
|
19
|
+
? terminal_link_1.default
|
|
20
|
+
: // eslint-disable-next-line no-unused-vars
|
|
21
|
+
(text, url, _) => `<a href="${url}">${text}</a>`;
|
|
22
|
+
const chalk = format === 'ansi'
|
|
23
|
+
? chalk_1.default
|
|
24
|
+
: {
|
|
25
|
+
gray: {
|
|
26
|
+
underline: (v) => `<span style="color: grey; text-decoration: underline;">${v}</span>`,
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
let result = {
|
|
30
|
+
message: md(`**${origin ?? 'unknown'}**: `) +
|
|
31
|
+
(skipFormatting ? message : md(message)),
|
|
32
|
+
stack: '',
|
|
33
|
+
codeframe: '',
|
|
34
|
+
frames: [],
|
|
35
|
+
hints: [],
|
|
36
|
+
documentation: '',
|
|
37
|
+
};
|
|
38
|
+
if (codeFrames != null) {
|
|
39
|
+
for (let codeFrame of codeFrames) {
|
|
40
|
+
let filePath = codeFrame.filePath;
|
|
41
|
+
if (filePath != null && options && !path_1.default.isAbsolute(filePath)) {
|
|
42
|
+
filePath = path_1.default.join(options.projectRoot, filePath);
|
|
43
|
+
}
|
|
44
|
+
let highlights = codeFrame.codeHighlights;
|
|
45
|
+
let code = codeFrame.code;
|
|
46
|
+
if (code == null && options && filePath != null) {
|
|
47
|
+
try {
|
|
48
|
+
code = await options.inputFS.readFile(filePath, 'utf8');
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
// In strange cases this can fail and hide the underlying error.
|
|
52
|
+
logger_1.default.warn({
|
|
53
|
+
origin: '@atlaspack/utils',
|
|
54
|
+
message: `Failed to read file for generating codeframe: "${filePath}"`,
|
|
55
|
+
skipFormatting: true,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
let formattedCodeFrame = '';
|
|
60
|
+
if (code != null) {
|
|
61
|
+
formattedCodeFrame = (0, codeframe_1.default)(code, highlights, {
|
|
62
|
+
useColor: true,
|
|
63
|
+
syntaxHighlighting: true,
|
|
64
|
+
language: codeFrame.language ||
|
|
65
|
+
(filePath != null ? path_1.default.extname(filePath).substr(1) : undefined),
|
|
66
|
+
terminalWidth,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
let location;
|
|
70
|
+
if (typeof filePath !== 'string') {
|
|
71
|
+
location = '';
|
|
72
|
+
}
|
|
73
|
+
else if (highlights.length === 0) {
|
|
74
|
+
location = filePath;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
location = `${filePath}:${highlights[0].start.line}:${highlights[0].start.column}`;
|
|
78
|
+
}
|
|
79
|
+
result.codeframe += location ? chalk.gray.underline(location) + '\n' : '';
|
|
80
|
+
result.codeframe += formattedCodeFrame;
|
|
81
|
+
if (codeFrame !== codeFrames[codeFrames.length - 1]) {
|
|
82
|
+
result.codeframe += '\n\n';
|
|
83
|
+
}
|
|
84
|
+
result.frames.push({
|
|
85
|
+
location,
|
|
86
|
+
code: formattedCodeFrame,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (stack != null) {
|
|
91
|
+
result.stack = stack;
|
|
92
|
+
}
|
|
93
|
+
if (Array.isArray(hints) && hints.length) {
|
|
94
|
+
result.hints = hints.map((h) => {
|
|
95
|
+
return md(h);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
if (documentationURL != null) {
|
|
99
|
+
result.documentation = terminalLink('Learn more', documentationURL, {
|
|
100
|
+
fallback: (text, url) => `${text}: ${url}`,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getProgressMessage = getProgressMessage;
|
|
7
|
+
exports.getPackageProgressMessage = getPackageProgressMessage;
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
function getProgressMessage(event) {
|
|
10
|
+
switch (event.phase) {
|
|
11
|
+
case 'transforming':
|
|
12
|
+
return `Building ${path_1.default.basename(event.filePath)}...`;
|
|
13
|
+
case 'bundling':
|
|
14
|
+
return 'Bundling...';
|
|
15
|
+
case 'packaging':
|
|
16
|
+
return `Packaging ${event.bundle.displayName}...`;
|
|
17
|
+
case 'optimizing':
|
|
18
|
+
return `Optimizing ${event.bundle.displayName}...`;
|
|
19
|
+
case 'packagingAndOptimizing': {
|
|
20
|
+
return getPackageProgressMessage(event.completeBundles, event.totalBundles);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
function getPackageProgressMessage(completeBundles, totalBundles) {
|
|
26
|
+
let percent = Math.floor((completeBundles / totalBundles) * 100);
|
|
27
|
+
let completeStr = completeBundles.toString();
|
|
28
|
+
let totalStr = totalBundles.toString();
|
|
29
|
+
let displayBundles = completeStr.padStart(totalStr.length, ' ');
|
|
30
|
+
return `Packaging bundles ${displayBundles}/${totalBundles} (${percent}%)`;
|
|
31
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.relativeBundlePath = relativeBundlePath;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const path_2 = require("./path");
|
|
9
|
+
function relativeBundlePath(from, to, opts = { leadingDotSlash: true }) {
|
|
10
|
+
let fromPath = path_1.default.join(from.target.distDir, from.name);
|
|
11
|
+
let toPath = path_1.default.join(to.target.distDir, to.name);
|
|
12
|
+
return (0, path_2.relativePath)(path_1.default.dirname(fromPath), toPath, opts.leadingDotSlash);
|
|
13
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = relativeUrl;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const url_1 = __importDefault(require("url"));
|
|
9
|
+
function relativeUrl(from, to) {
|
|
10
|
+
return url_1.default.format(url_1.default.parse(path_1.default.relative(from, to)));
|
|
11
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.replaceURLReferences = replaceURLReferences;
|
|
7
|
+
exports.replaceInlineReferences = replaceInlineReferences;
|
|
8
|
+
exports.getURLReplacement = getURLReplacement;
|
|
9
|
+
const rust_1 = require("@atlaspack/rust");
|
|
10
|
+
const stream_1 = require("stream");
|
|
11
|
+
const nullthrows_1 = __importDefault(require("nullthrows"));
|
|
12
|
+
const assert_1 = __importDefault(require("assert"));
|
|
13
|
+
const url_1 = __importDefault(require("url"));
|
|
14
|
+
const _1 = require("./");
|
|
15
|
+
/*
|
|
16
|
+
* Replaces references to dependency ids for URL dependencies with:
|
|
17
|
+
* - in the case of an unresolvable url dependency, the original specifier.
|
|
18
|
+
* These are external requests that Parcel did not bundle.
|
|
19
|
+
* - in the case of a reference to another bundle, the relative url to that
|
|
20
|
+
* bundle from the current bundle.
|
|
21
|
+
*/
|
|
22
|
+
function replaceURLReferences({ bundle, bundleGraph, contents, map, getReplacement = (s) => s, relative = true, }) {
|
|
23
|
+
let replacements = new Map();
|
|
24
|
+
let urlDependencies = [];
|
|
25
|
+
bundle.traverse((node) => {
|
|
26
|
+
if (node.type === 'dependency' && node.value.specifierType === 'url') {
|
|
27
|
+
urlDependencies.push(node.value);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
for (let dependency of urlDependencies) {
|
|
31
|
+
if (dependency.specifierType !== 'url') {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
let placeholder = dependency.meta?.placeholder ?? dependency.id;
|
|
35
|
+
(0, assert_1.default)(typeof placeholder === 'string');
|
|
36
|
+
let resolved = bundleGraph.getReferencedBundle(dependency, bundle);
|
|
37
|
+
if (resolved == null) {
|
|
38
|
+
replacements.set(placeholder, {
|
|
39
|
+
from: placeholder,
|
|
40
|
+
to: getReplacement(dependency.specifier),
|
|
41
|
+
});
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (resolved.bundleBehavior === 'inline' ||
|
|
45
|
+
resolved.bundleBehavior === 'inlineIsolated') {
|
|
46
|
+
// If a bundle is inline, it should be replaced with inline contents,
|
|
47
|
+
// not a URL.
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
replacements.set(placeholder, getURLReplacement({
|
|
51
|
+
dependency,
|
|
52
|
+
fromBundle: bundle,
|
|
53
|
+
toBundle: resolved,
|
|
54
|
+
relative,
|
|
55
|
+
getReplacement,
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
return performReplacement(replacements, contents, map);
|
|
59
|
+
}
|
|
60
|
+
/*
|
|
61
|
+
* Replaces references to dependency ids for inline bundles with the packaged
|
|
62
|
+
* contents of that bundle.
|
|
63
|
+
*/
|
|
64
|
+
async function replaceInlineReferences({ bundle, bundleGraph, contents, map, getInlineReplacement, getInlineBundleContents, }) {
|
|
65
|
+
let replacements = new Map();
|
|
66
|
+
let dependencies = [];
|
|
67
|
+
bundle.traverse((node) => {
|
|
68
|
+
if (node.type === 'dependency') {
|
|
69
|
+
dependencies.push(node.value);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
for (let dependency of dependencies) {
|
|
73
|
+
let entryBundle = bundleGraph.getReferencedBundle(dependency, bundle);
|
|
74
|
+
if (entryBundle?.bundleBehavior !== 'inline' &&
|
|
75
|
+
entryBundle?.bundleBehavior !== 'inlineIsolated') {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
let packagedBundle = await getInlineBundleContents(entryBundle, bundleGraph);
|
|
79
|
+
let packagedContents = (packagedBundle.contents instanceof stream_1.Readable
|
|
80
|
+
? await (0, _1.bufferStream)(packagedBundle.contents)
|
|
81
|
+
: packagedBundle.contents).toString();
|
|
82
|
+
let inlineType = (0, nullthrows_1.default)(entryBundle.getMainEntry()).meta.inlineType;
|
|
83
|
+
if (inlineType == null || inlineType === 'string') {
|
|
84
|
+
let placeholder = dependency.meta?.placeholder ?? dependency.id;
|
|
85
|
+
(0, assert_1.default)(typeof placeholder === 'string');
|
|
86
|
+
replacements.set(placeholder, getInlineReplacement(dependency, inlineType, packagedContents));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return performReplacement(replacements, contents, map);
|
|
90
|
+
}
|
|
91
|
+
function getURLReplacement({ dependency, fromBundle, toBundle, relative, getReplacement, }) {
|
|
92
|
+
let to;
|
|
93
|
+
let orig = url_1.default.parse(dependency.specifier);
|
|
94
|
+
if (relative) {
|
|
95
|
+
to = url_1.default.format({
|
|
96
|
+
pathname: (0, _1.relativeBundlePath)(fromBundle, toBundle, {
|
|
97
|
+
leadingDotSlash: false,
|
|
98
|
+
}),
|
|
99
|
+
hash: orig.hash,
|
|
100
|
+
});
|
|
101
|
+
// If the resulting path includes a colon character and doesn't start with a ./ or ../
|
|
102
|
+
// we need to add one so that the first part before the colon isn't parsed as a URL protocol.
|
|
103
|
+
if (to.includes(':') && !to.startsWith('./') && !to.startsWith('../')) {
|
|
104
|
+
to = './' + to;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
to = (0, _1.urlJoin)(toBundle.target.publicUrl, url_1.default.format({
|
|
109
|
+
pathname: (0, nullthrows_1.default)(toBundle.name),
|
|
110
|
+
hash: orig.hash,
|
|
111
|
+
}));
|
|
112
|
+
}
|
|
113
|
+
let placeholder = dependency.meta?.placeholder ?? dependency.id;
|
|
114
|
+
(0, assert_1.default)(typeof placeholder === 'string');
|
|
115
|
+
return {
|
|
116
|
+
from: placeholder,
|
|
117
|
+
to: getReplacement ? getReplacement(to) : to,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function performReplacement(replacements, contents, map) {
|
|
121
|
+
let finalContents = contents;
|
|
122
|
+
let replacementList = Array.from(replacements.values());
|
|
123
|
+
if (replacementList.length > 0) {
|
|
124
|
+
finalContents = (0, rust_1.performStringReplacements)(contents, replacementList);
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
contents: finalContents,
|
|
128
|
+
// TODO: Update sourcemap with adjusted contents
|
|
129
|
+
map,
|
|
130
|
+
};
|
|
131
|
+
}
|