@atlaspack/utils 2.19.2 → 2.19.4-dev-ts-project-refs-d30e9754f.0
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 +15 -0
- package/LICENSE +201 -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 +37 -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/glob.js +133 -0
- package/dist/hash.js +45 -0
- package/dist/http-server.js +55 -0
- package/dist/index.js +146 -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 +93 -0
- package/dist/progress-message.js +31 -0
- package/dist/relativeBundlePath.js +13 -0
- package/dist/relativeUrl.js +11 -0
- package/dist/replaceBundleReferences.js +140 -0
- package/dist/schema.js +389 -0
- package/dist/shared-buffer.js +24 -0
- package/dist/sourcemap.js +114 -0
- package/dist/stream.js +69 -0
- package/dist/throttle.js +12 -0
- package/dist/urlJoin.js +22 -0
- package/package.json +15 -15
- package/tsconfig.json +31 -2
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unique = unique;
|
|
4
|
+
exports.objectSortedEntries = objectSortedEntries;
|
|
5
|
+
exports.objectSortedEntriesDeep = objectSortedEntriesDeep;
|
|
6
|
+
exports.setDifference = setDifference;
|
|
7
|
+
exports.setSymmetricDifference = setSymmetricDifference;
|
|
8
|
+
exports.setIntersect = setIntersect;
|
|
9
|
+
exports.setIntersectStatic = setIntersectStatic;
|
|
10
|
+
exports.setUnion = setUnion;
|
|
11
|
+
exports.setEqual = setEqual;
|
|
12
|
+
function unique(array) {
|
|
13
|
+
return [...new Set(array)];
|
|
14
|
+
}
|
|
15
|
+
function objectSortedEntries(obj) {
|
|
16
|
+
return Object.entries(obj).sort(([keyA], [keyB]) => keyA.localeCompare(keyB));
|
|
17
|
+
}
|
|
18
|
+
function objectSortedEntriesDeep(object) {
|
|
19
|
+
let sortedEntries = objectSortedEntries(object);
|
|
20
|
+
for (let i = 0; i < sortedEntries.length; i++) {
|
|
21
|
+
sortedEntries[i][1] = sortEntry(sortedEntries[i][1]);
|
|
22
|
+
}
|
|
23
|
+
return sortedEntries;
|
|
24
|
+
}
|
|
25
|
+
function sortEntry(entry) {
|
|
26
|
+
if (Array.isArray(entry)) {
|
|
27
|
+
return entry.map(sortEntry);
|
|
28
|
+
}
|
|
29
|
+
if (typeof entry === 'object' && entry != null) {
|
|
30
|
+
return objectSortedEntriesDeep(entry);
|
|
31
|
+
}
|
|
32
|
+
return entry;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Get the difference of A and B sets
|
|
36
|
+
*
|
|
37
|
+
* This is the set of elements which are in A but not in B
|
|
38
|
+
* For example, the difference of the sets {1,2,3} and {3,4} is {1,2}
|
|
39
|
+
*
|
|
40
|
+
* @param {*} a Set A
|
|
41
|
+
* @param {*} b Set B
|
|
42
|
+
* @returns A \ B
|
|
43
|
+
*/
|
|
44
|
+
function setDifference(a, b) {
|
|
45
|
+
let difference = new Set();
|
|
46
|
+
for (let e of a) {
|
|
47
|
+
if (!b.has(e)) {
|
|
48
|
+
difference.add(e);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return difference;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Get the symmetric difference of A and B sets
|
|
55
|
+
*
|
|
56
|
+
* This is the set of elements which are in either of the sets, but not in their intersection.
|
|
57
|
+
* For example, the symmetric difference of the sets {1,2,3} and {3,4} is {1,2,4}
|
|
58
|
+
*
|
|
59
|
+
* @param {*} a Set A
|
|
60
|
+
* @param {*} b Set B
|
|
61
|
+
* @returns A Δ B
|
|
62
|
+
*/
|
|
63
|
+
function setSymmetricDifference(a, b) {
|
|
64
|
+
let difference = new Set();
|
|
65
|
+
for (let e of a) {
|
|
66
|
+
if (!b.has(e)) {
|
|
67
|
+
difference.add(e);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
for (let d of b) {
|
|
71
|
+
if (!a.has(d)) {
|
|
72
|
+
difference.add(d);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return difference;
|
|
76
|
+
}
|
|
77
|
+
function setIntersect(a, b) {
|
|
78
|
+
for (let entry of a) {
|
|
79
|
+
if (!b.has(entry)) {
|
|
80
|
+
a.delete(entry);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function setIntersectStatic(a, b) {
|
|
85
|
+
let intersection = new Set();
|
|
86
|
+
for (let entry of a) {
|
|
87
|
+
if (b.has(entry)) {
|
|
88
|
+
intersection.add(entry);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return intersection;
|
|
92
|
+
}
|
|
93
|
+
function setUnion(a, b) {
|
|
94
|
+
return new Set([...a, ...b]);
|
|
95
|
+
}
|
|
96
|
+
function setEqual(a, b) {
|
|
97
|
+
if (a.size != b.size) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
for (let entry of a) {
|
|
101
|
+
if (!b.has(entry)) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return true;
|
|
106
|
+
}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
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.resolveConfig = resolveConfig;
|
|
7
|
+
exports.resolveConfigSync = resolveConfigSync;
|
|
8
|
+
exports.loadConfig = loadConfig;
|
|
9
|
+
exports.readConfig = readConfig;
|
|
10
|
+
const diagnostic_1 = __importDefault(require("@atlaspack/diagnostic"));
|
|
11
|
+
const path_1 = __importDefault(require("path"));
|
|
12
|
+
// @ts-expect-error TS7016
|
|
13
|
+
const clone_1 = __importDefault(require("clone"));
|
|
14
|
+
const json5_1 = __importDefault(require("json5"));
|
|
15
|
+
const toml_1 = require("@iarna/toml");
|
|
16
|
+
const lru_cache_1 = __importDefault(require("lru-cache"));
|
|
17
|
+
// @ts-expect-error TS2351
|
|
18
|
+
const configCache = new lru_cache_1.default({ max: 500 });
|
|
19
|
+
const resolveCache = new Map();
|
|
20
|
+
function resolveConfig(fs, filepath, filenames, projectRoot) {
|
|
21
|
+
// Cache the result of resolving config for this directory.
|
|
22
|
+
// This is automatically invalidated at the end of the current build.
|
|
23
|
+
let key = path_1.default.dirname(filepath) + filenames.join(',');
|
|
24
|
+
let cached = resolveCache.get(key);
|
|
25
|
+
if (cached !== undefined) {
|
|
26
|
+
return Promise.resolve(cached);
|
|
27
|
+
}
|
|
28
|
+
let resolved = fs.findAncestorFile(filenames, path_1.default.dirname(filepath), projectRoot);
|
|
29
|
+
resolveCache.set(key, resolved);
|
|
30
|
+
return Promise.resolve(resolved);
|
|
31
|
+
}
|
|
32
|
+
function resolveConfigSync(fs, filepath, filenames, projectRoot) {
|
|
33
|
+
return fs.findAncestorFile(filenames, path_1.default.dirname(filepath), projectRoot);
|
|
34
|
+
}
|
|
35
|
+
async function loadConfig(fs, filepath, filenames, projectRoot, opts) {
|
|
36
|
+
let parse = opts?.parse ?? true;
|
|
37
|
+
let configFile = await resolveConfig(fs, filepath, filenames, projectRoot);
|
|
38
|
+
if (configFile) {
|
|
39
|
+
let cachedOutput = configCache.get(String(parse) + configFile);
|
|
40
|
+
if (cachedOutput) {
|
|
41
|
+
return cachedOutput;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
let extname = path_1.default.extname(configFile).slice(1);
|
|
45
|
+
if (extname === 'js' || extname === 'cjs') {
|
|
46
|
+
let output = {
|
|
47
|
+
config: (0, clone_1.default)(module.require(configFile)),
|
|
48
|
+
files: [{ filePath: configFile }],
|
|
49
|
+
};
|
|
50
|
+
configCache.set(configFile, output);
|
|
51
|
+
return output;
|
|
52
|
+
}
|
|
53
|
+
return readConfig(fs, configFile, opts);
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
if (err.code === 'MODULE_NOT_FOUND' || err.code === 'ENOENT') {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
throw err;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
loadConfig.clear = () => {
|
|
65
|
+
configCache.reset();
|
|
66
|
+
resolveCache.clear();
|
|
67
|
+
};
|
|
68
|
+
async function readConfig(fs, configFile, opts) {
|
|
69
|
+
let parse = opts?.parse ?? true;
|
|
70
|
+
let cachedOutput = configCache.get(String(parse) + configFile);
|
|
71
|
+
if (cachedOutput) {
|
|
72
|
+
return cachedOutput;
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
let configContent = await fs.readFile(configFile, 'utf8');
|
|
76
|
+
let config;
|
|
77
|
+
if (parse === false) {
|
|
78
|
+
config = configContent;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
let extname = path_1.default.extname(configFile).slice(1);
|
|
82
|
+
let parse = opts?.parser ?? getParser(extname);
|
|
83
|
+
try {
|
|
84
|
+
config = parse(configContent);
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
if (extname !== '' && extname !== 'json') {
|
|
88
|
+
throw e;
|
|
89
|
+
}
|
|
90
|
+
let pos = {
|
|
91
|
+
line: e.lineNumber,
|
|
92
|
+
column: e.columnNumber,
|
|
93
|
+
};
|
|
94
|
+
throw new diagnostic_1.default({
|
|
95
|
+
diagnostic: {
|
|
96
|
+
message: `Failed to parse ${path_1.default.basename(configFile)}`,
|
|
97
|
+
origin: '@atlaspack/utils',
|
|
98
|
+
codeFrames: [
|
|
99
|
+
{
|
|
100
|
+
language: 'json5',
|
|
101
|
+
filePath: configFile,
|
|
102
|
+
code: configContent,
|
|
103
|
+
codeHighlights: [
|
|
104
|
+
{
|
|
105
|
+
start: pos,
|
|
106
|
+
end: pos,
|
|
107
|
+
message: e.message,
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
let output = {
|
|
117
|
+
config,
|
|
118
|
+
files: [{ filePath: configFile }],
|
|
119
|
+
};
|
|
120
|
+
configCache.set(String(parse) + configFile, output);
|
|
121
|
+
return output;
|
|
122
|
+
}
|
|
123
|
+
catch (err) {
|
|
124
|
+
if (err.code === 'MODULE_NOT_FOUND' || err.code === 'ENOENT') {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
throw err;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function getParser(extname) {
|
|
131
|
+
switch (extname) {
|
|
132
|
+
case 'toml':
|
|
133
|
+
return toml_1.parse;
|
|
134
|
+
case 'json':
|
|
135
|
+
default:
|
|
136
|
+
return json5_1.default.parse;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = countLines;
|
|
4
|
+
function countLines(string, startIndex = 0) {
|
|
5
|
+
let lines = 1;
|
|
6
|
+
for (let i = startIndex; i < string.length; i++) {
|
|
7
|
+
if (string.charAt(i) === '\n') {
|
|
8
|
+
lines++;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return lines;
|
|
12
|
+
}
|
package/dist/debounce.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = debounce;
|
|
4
|
+
function debounce(fn, delay) {
|
|
5
|
+
let timeout;
|
|
6
|
+
return function (...args) {
|
|
7
|
+
if (timeout) {
|
|
8
|
+
clearTimeout(timeout);
|
|
9
|
+
}
|
|
10
|
+
timeout = setTimeout(() => {
|
|
11
|
+
timeout = null;
|
|
12
|
+
fn(...args);
|
|
13
|
+
}, delay);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* These tools are intended for Atlaspack developers, to provide extra utilities
|
|
4
|
+
* to make debugging Atlaspack issues more straightforward.
|
|
5
|
+
*
|
|
6
|
+
* To enable a tool, set the `ATLASPACK_DEBUG_TOOLS` environment variable to a
|
|
7
|
+
* comma-separated list of tool names. For example:
|
|
8
|
+
* `ATLASPACK_DEBUG_TOOLS="asset-file-names-in-output,simple-cli-reporter"`
|
|
9
|
+
*
|
|
10
|
+
* You can enable all tools by setting `ATLASPACK_DEBUG_TOOLS=all`.
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.debugTools = void 0;
|
|
14
|
+
exports.debugTools = {
|
|
15
|
+
'asset-file-names-in-output': false,
|
|
16
|
+
'simple-cli-reporter': false,
|
|
17
|
+
'bundle-stats': false,
|
|
18
|
+
};
|
|
19
|
+
const envVarValue = process.env.ATLASPACK_DEBUG_TOOLS ?? '';
|
|
20
|
+
for (let tool of envVarValue.split(',')) {
|
|
21
|
+
tool = tool.trim();
|
|
22
|
+
if (tool === 'all') {
|
|
23
|
+
for (let key in exports.debugTools) {
|
|
24
|
+
exports.debugTools[key] = true;
|
|
25
|
+
}
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
else if (exports.debugTools.hasOwnProperty(tool)) {
|
|
29
|
+
exports.debugTools[tool] = true;
|
|
30
|
+
}
|
|
31
|
+
else if (tool === '') {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
throw new Error(`Invalid debug tool option: ${tool}. Valid options are: ${Object.keys(exports.debugTools).join(', ')}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = createDependencyLocation;
|
|
4
|
+
function createDependencyLocation(start, specifier, lineOffset = 0, columnOffset = 0,
|
|
5
|
+
// Imports are usually wrapped in quotes
|
|
6
|
+
importWrapperLength = 2) {
|
|
7
|
+
return {
|
|
8
|
+
filePath: specifier,
|
|
9
|
+
start: {
|
|
10
|
+
line: start.line + lineOffset,
|
|
11
|
+
column: start.column + columnOffset,
|
|
12
|
+
},
|
|
13
|
+
end: {
|
|
14
|
+
line: start.line + lineOffset,
|
|
15
|
+
column: start.column +
|
|
16
|
+
specifier.length -
|
|
17
|
+
1 +
|
|
18
|
+
importWrapperLength +
|
|
19
|
+
columnOffset,
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.escapeHTML = escapeHTML;
|
|
4
|
+
// Based on _.escape https://github.com/lodash/lodash/blob/master/escape.js
|
|
5
|
+
const reUnescapedHtml = /[&<>"']/g;
|
|
6
|
+
const reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
|
|
7
|
+
const htmlEscapes = {
|
|
8
|
+
'&': '&',
|
|
9
|
+
'<': '<',
|
|
10
|
+
'>': '>',
|
|
11
|
+
'"': '"',
|
|
12
|
+
"'": ''',
|
|
13
|
+
};
|
|
14
|
+
function escapeHTML(s) {
|
|
15
|
+
if (reHasUnescapedHtml.test(s)) {
|
|
16
|
+
return s.replace(reUnescapedHtml, (c) => htmlEscapes[c]);
|
|
17
|
+
}
|
|
18
|
+
return s;
|
|
19
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
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 = generateBuildMetrics;
|
|
7
|
+
const source_map_1 = __importDefault(require("@parcel/source-map"));
|
|
8
|
+
const nullthrows_1 = __importDefault(require("nullthrows"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const _1 = require("./");
|
|
11
|
+
async function getSourcemapSizes(filePath, fs, projectRoot) {
|
|
12
|
+
let bundleContents = await fs.readFile(filePath, 'utf-8');
|
|
13
|
+
let mapUrlData = await (0, _1.loadSourceMapUrl)(fs, filePath, bundleContents);
|
|
14
|
+
if (!mapUrlData) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
let rawMap = mapUrlData.map;
|
|
18
|
+
let sourceMap = new source_map_1.default(projectRoot);
|
|
19
|
+
sourceMap.addVLQMap(rawMap);
|
|
20
|
+
let parsedMapData = sourceMap.getMap();
|
|
21
|
+
if (parsedMapData.mappings.length > 2) {
|
|
22
|
+
let sources = parsedMapData.sources.map((s) => path_1.default.normalize(path_1.default.join(projectRoot, s)));
|
|
23
|
+
let currLine = 1;
|
|
24
|
+
let currColumn = 0;
|
|
25
|
+
let currMappingIndex = 0;
|
|
26
|
+
let currMapping = parsedMapData.mappings[currMappingIndex];
|
|
27
|
+
let nextMapping = parsedMapData.mappings[currMappingIndex + 1];
|
|
28
|
+
let sourceSizes = new Array(sources.length).fill(0);
|
|
29
|
+
let unknownOrigin = 0;
|
|
30
|
+
for (let i = 0; i < bundleContents.length; i++) {
|
|
31
|
+
let character = bundleContents[i];
|
|
32
|
+
while (nextMapping &&
|
|
33
|
+
nextMapping.generated.line === currLine &&
|
|
34
|
+
nextMapping.generated.column <= currColumn) {
|
|
35
|
+
currMappingIndex++;
|
|
36
|
+
currMapping = parsedMapData.mappings[currMappingIndex];
|
|
37
|
+
nextMapping = parsedMapData.mappings[currMappingIndex + 1];
|
|
38
|
+
}
|
|
39
|
+
let currentSource = currMapping.source;
|
|
40
|
+
let charSize = Buffer.byteLength(character, 'utf8');
|
|
41
|
+
if (currentSource != null &&
|
|
42
|
+
currMapping.generated.line === currLine &&
|
|
43
|
+
currMapping.generated.column <= currColumn) {
|
|
44
|
+
sourceSizes[currentSource] += charSize;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
unknownOrigin += charSize;
|
|
48
|
+
}
|
|
49
|
+
if (character === '\n') {
|
|
50
|
+
currColumn = 0;
|
|
51
|
+
currLine++;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
currColumn++;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
let sizeMap = new Map();
|
|
58
|
+
for (let i = 0; i < sourceSizes.length; i++) {
|
|
59
|
+
sizeMap.set(sources[i], sourceSizes[i]);
|
|
60
|
+
}
|
|
61
|
+
sizeMap.set('', unknownOrigin);
|
|
62
|
+
return sizeMap;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async function createBundleStats(bundle, fs, projectRoot) {
|
|
66
|
+
let filePath = bundle.filePath;
|
|
67
|
+
let sourcemapSizes = await getSourcemapSizes(filePath, fs, projectRoot);
|
|
68
|
+
let assets = new Map();
|
|
69
|
+
bundle.traverseAssets((asset) => {
|
|
70
|
+
let filePath = path_1.default.normalize(asset.filePath);
|
|
71
|
+
assets.set(filePath, {
|
|
72
|
+
filePath,
|
|
73
|
+
size: asset.stats.size,
|
|
74
|
+
originalSize: asset.stats.size,
|
|
75
|
+
time: asset.stats.time,
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
let assetsReport = [];
|
|
79
|
+
if (sourcemapSizes && sourcemapSizes.size) {
|
|
80
|
+
assetsReport = Array.from(sourcemapSizes.keys()).map((filePath) => {
|
|
81
|
+
let foundSize = sourcemapSizes.get(filePath) || 0;
|
|
82
|
+
let stats = assets.get(filePath) || {
|
|
83
|
+
filePath,
|
|
84
|
+
size: foundSize,
|
|
85
|
+
originalSize: foundSize,
|
|
86
|
+
time: 0,
|
|
87
|
+
};
|
|
88
|
+
return {
|
|
89
|
+
...stats,
|
|
90
|
+
size: foundSize,
|
|
91
|
+
};
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
assetsReport = Array.from(assets.values());
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
filePath: (0, nullthrows_1.default)(bundle.filePath),
|
|
99
|
+
size: bundle.stats.size,
|
|
100
|
+
time: bundle.stats.time,
|
|
101
|
+
assets: assetsReport.sort((a, b) => b.size - a.size),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
async function generateBuildMetrics(bundles, fs, projectRoot) {
|
|
105
|
+
bundles
|
|
106
|
+
.sort((a, b) => b.stats.size - a.stats.size)
|
|
107
|
+
.filter((b) => !!b.filePath);
|
|
108
|
+
return {
|
|
109
|
+
bundles: (await Promise.all(bundles.map((b) => createBundleStats(b, fs, projectRoot)))).filter((e) => !!e),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
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 = generateCertificate;
|
|
7
|
+
const node_forge_1 = __importDefault(require("node-forge"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const logger_1 = __importDefault(require("@atlaspack/logger"));
|
|
10
|
+
async function generateCertificate(fs, cacheDir, host) {
|
|
11
|
+
let certDirectory = cacheDir;
|
|
12
|
+
const privateKeyPath = path_1.default.join(certDirectory, 'private.pem');
|
|
13
|
+
const certPath = path_1.default.join(certDirectory, 'primary.crt');
|
|
14
|
+
const cachedKey = (await fs.exists(privateKeyPath)) && (await fs.readFile(privateKeyPath));
|
|
15
|
+
const cachedCert = (await fs.exists(certPath)) && (await fs.readFile(certPath));
|
|
16
|
+
if (cachedKey && cachedCert) {
|
|
17
|
+
return {
|
|
18
|
+
key: cachedKey,
|
|
19
|
+
cert: cachedCert,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
logger_1.default.progress('Generating SSL Certificate...');
|
|
23
|
+
const pki = node_forge_1.default.pki;
|
|
24
|
+
const keys = pki.rsa.generateKeyPair(2048);
|
|
25
|
+
const cert = pki.createCertificate();
|
|
26
|
+
cert.publicKey = keys.publicKey;
|
|
27
|
+
cert.serialNumber = Date.now().toString();
|
|
28
|
+
cert.validity.notBefore = new Date();
|
|
29
|
+
cert.validity.notAfter = new Date();
|
|
30
|
+
cert.validity.notAfter.setFullYear(cert.validity.notBefore.getFullYear() + 1);
|
|
31
|
+
const attrs = [
|
|
32
|
+
{
|
|
33
|
+
name: 'commonName',
|
|
34
|
+
value: 'parceljs.org',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: 'countryName',
|
|
38
|
+
value: 'US',
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
shortName: 'ST',
|
|
42
|
+
value: 'Virginia',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: 'localityName',
|
|
46
|
+
value: 'Blacksburg',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: 'organizationName',
|
|
50
|
+
value: 'parcelBundler',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
shortName: 'OU',
|
|
54
|
+
value: 'Test',
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
let altNames = [
|
|
58
|
+
{
|
|
59
|
+
type: 2, // DNS
|
|
60
|
+
value: 'localhost',
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
type: 7, // IP
|
|
64
|
+
ip: '127.0.0.1',
|
|
65
|
+
},
|
|
66
|
+
];
|
|
67
|
+
if (host) {
|
|
68
|
+
altNames.push({
|
|
69
|
+
type: 2, // DNS
|
|
70
|
+
value: host,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
cert.setSubject(attrs);
|
|
74
|
+
cert.setIssuer(attrs);
|
|
75
|
+
cert.setExtensions([
|
|
76
|
+
{
|
|
77
|
+
name: 'basicConstraints',
|
|
78
|
+
cA: false,
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
name: 'keyUsage',
|
|
82
|
+
keyCertSign: true,
|
|
83
|
+
digitalSignature: true,
|
|
84
|
+
nonRepudiation: true,
|
|
85
|
+
keyEncipherment: true,
|
|
86
|
+
dataEncipherment: true,
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
name: 'extKeyUsage',
|
|
90
|
+
serverAuth: true,
|
|
91
|
+
clientAuth: true,
|
|
92
|
+
codeSigning: true,
|
|
93
|
+
emailProtection: true,
|
|
94
|
+
timeStamping: true,
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: 'nsCertType',
|
|
98
|
+
client: true,
|
|
99
|
+
server: true,
|
|
100
|
+
email: true,
|
|
101
|
+
objsign: true,
|
|
102
|
+
sslCA: true,
|
|
103
|
+
emailCA: true,
|
|
104
|
+
objCA: true,
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
name: 'subjectAltName',
|
|
108
|
+
altNames,
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
name: 'subjectKeyIdentifier',
|
|
112
|
+
},
|
|
113
|
+
]);
|
|
114
|
+
cert.sign(keys.privateKey, node_forge_1.default.md.sha256.create());
|
|
115
|
+
const privPem = pki.privateKeyToPem(keys.privateKey);
|
|
116
|
+
const certPem = pki.certificateToPem(cert);
|
|
117
|
+
await fs.mkdirp(certDirectory);
|
|
118
|
+
await fs.writeFile(privateKeyPath, privPem);
|
|
119
|
+
await fs.writeFile(certPath, certPem);
|
|
120
|
+
return {
|
|
121
|
+
key: privPem,
|
|
122
|
+
cert: certPem,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = getCertificate;
|
|
4
|
+
async function getCertificate(fs, options) {
|
|
5
|
+
try {
|
|
6
|
+
let cert = await fs.readFile(options.cert);
|
|
7
|
+
let key = await fs.readFile(options.key);
|
|
8
|
+
return { key, cert };
|
|
9
|
+
}
|
|
10
|
+
catch (err) {
|
|
11
|
+
throw new Error('Certificate and/or key not found');
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -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 = getExisting;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
/**
|
|
9
|
+
* Creates an object that contains both source and minified (using the source as a fallback).
|
|
10
|
+
* e.g. builtins.min.js and builtins.js.
|
|
11
|
+
*/
|
|
12
|
+
function getExisting(minifiedPath, sourcePath) {
|
|
13
|
+
let source = fs_1.default.readFileSync(sourcePath, 'utf8').trim();
|
|
14
|
+
return {
|
|
15
|
+
source,
|
|
16
|
+
minified: fs_1.default.existsSync(minifiedPath)
|
|
17
|
+
? fs_1.default.readFileSync(minifiedPath, 'utf8').trim().replace(/;$/, '')
|
|
18
|
+
: source,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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 = getModuleParts;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const path_2 = require("./path");
|
|
9
|
+
/**
|
|
10
|
+
* Returns the package name and the optional subpath
|
|
11
|
+
*/
|
|
12
|
+
function getModuleParts(_name) {
|
|
13
|
+
let name = path_1.default.normalize(_name);
|
|
14
|
+
let splitOn = name.indexOf(path_1.default.sep);
|
|
15
|
+
if (name.charAt(0) === '@') {
|
|
16
|
+
splitOn = name.indexOf(path_1.default.sep, splitOn + 1);
|
|
17
|
+
}
|
|
18
|
+
if (splitOn < 0) {
|
|
19
|
+
return [(0, path_2.normalizeSeparators)(name), undefined];
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
return [
|
|
23
|
+
(0, path_2.normalizeSeparators)(name.substring(0, splitOn)),
|
|
24
|
+
name.substring(splitOn + 1) || undefined,
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
}
|