@atlaspack/utils 2.17.3-typescript-b27501580.0 → 2.17.3-typescript-5b4d3ad41.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/lib/DefaultMap.d.ts +13 -0
- package/lib/DefaultMap.js +42 -0
- package/lib/Deferred.d.ts +8 -0
- package/lib/Deferred.js +30 -0
- package/lib/PromiseQueue.d.ts +25 -0
- package/lib/PromiseQueue.js +112 -0
- package/lib/TapStream.d.ts +6 -0
- package/lib/TapStream.js +34 -0
- package/lib/alternatives.d.ts +3 -0
- package/lib/alternatives.js +116 -0
- package/lib/ansi-html.d.ts +1 -0
- package/lib/ansi-html.js +20 -0
- package/lib/blob.d.ts +4 -0
- package/lib/blob.js +40 -0
- package/lib/bundle-url.d.ts +4 -0
- package/lib/bundle-url.js +34 -0
- package/lib/collection.d.ts +33 -0
- package/lib/collection.js +111 -0
- package/lib/config.d.ts +17 -0
- package/lib/config.js +174 -0
- package/lib/countLines.d.ts +1 -0
- package/lib/countLines.js +15 -0
- package/lib/debounce.d.ts +1 -0
- package/lib/debounce.js +18 -0
- package/lib/debug-tools.d.ts +6 -0
- package/lib/debug-tools.js +37 -0
- package/lib/dependency-location.d.ts +14 -0
- package/lib/dependency-location.js +21 -0
- package/lib/escape-html.d.ts +1 -0
- package/lib/escape-html.js +22 -0
- package/lib/generateBuildMetrics.d.ts +18 -0
- package/lib/generateBuildMetrics.js +121 -0
- package/lib/generateCertificate.d.ts +5 -0
- package/lib/generateCertificate.js +129 -0
- package/lib/getCertificate.d.ts +6 -0
- package/lib/getCertificate.js +18 -0
- package/lib/getExisting.d.ts +8 -0
- package/lib/getExisting.js +25 -0
- package/lib/getModuleParts.d.ts +4 -0
- package/lib/getModuleParts.js +30 -0
- package/lib/getRootDir.d.ts +2 -0
- package/lib/getRootDir.js +52 -0
- package/lib/glob.d.ts +10 -0
- package/lib/glob.js +118 -0
- package/lib/hash.d.ts +7 -0
- package/lib/hash.js +50 -0
- package/lib/http-server.d.ts +19 -0
- package/lib/http-server.js +85 -0
- package/lib/index.d.ts +48 -0
- package/lib/index.js +665 -0
- package/lib/is-url.d.ts +1 -0
- package/lib/is-url.js +24 -0
- package/lib/isDirectoryInside.d.ts +2 -0
- package/lib/isDirectoryInside.js +18 -0
- package/lib/objectHash.d.ts +3 -0
- package/lib/objectHash.js +26 -0
- package/lib/openInBrowser.d.ts +1 -0
- package/lib/openInBrowser.js +74 -0
- package/lib/parseCSSImport.d.ts +1 -0
- package/lib/parseCSSImport.js +15 -0
- package/lib/path.d.ts +8 -0
- package/lib/path.js +39 -0
- package/lib/prettifyTime.d.ts +1 -0
- package/lib/prettifyTime.js +9 -0
- package/lib/prettyDiagnostic.d.ts +17 -0
- package/lib/prettyDiagnostic.js +134 -0
- package/lib/progress-message.d.ts +3 -0
- package/lib/progress-message.js +36 -0
- package/lib/relativeBundlePath.d.ts +4 -0
- package/lib/relativeBundlePath.js +22 -0
- package/lib/relativeUrl.d.ts +1 -0
- package/lib/relativeUrl.js +24 -0
- package/lib/replaceBundleReferences.d.ts +39 -0
- package/lib/replaceBundleReferences.js +199 -0
- package/lib/schema.d.ts +107 -0
- package/lib/schema.js +355 -0
- package/lib/shared-buffer.d.ts +2 -0
- package/lib/shared-buffer.js +31 -0
- package/lib/sourcemap.d.ts +16 -0
- package/lib/sourcemap.js +127 -0
- package/lib/stream.d.ts +8 -0
- package/lib/stream.js +76 -0
- package/lib/throttle.d.ts +1 -0
- package/lib/throttle.js +15 -0
- package/lib/urlJoin.d.ts +5 -0
- package/lib/urlJoin.js +35 -0
- package/package.json +9 -9
package/lib/config.js
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.loadConfig = loadConfig;
|
|
7
|
+
exports.readConfig = readConfig;
|
|
8
|
+
exports.resolveConfig = resolveConfig;
|
|
9
|
+
exports.resolveConfigSync = resolveConfigSync;
|
|
10
|
+
function _diagnostic() {
|
|
11
|
+
const data = _interopRequireDefault(require("@atlaspack/diagnostic"));
|
|
12
|
+
_diagnostic = function () {
|
|
13
|
+
return data;
|
|
14
|
+
};
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
function _path() {
|
|
18
|
+
const data = _interopRequireDefault(require("path"));
|
|
19
|
+
_path = function () {
|
|
20
|
+
return data;
|
|
21
|
+
};
|
|
22
|
+
return data;
|
|
23
|
+
}
|
|
24
|
+
function _clone() {
|
|
25
|
+
const data = _interopRequireDefault(require("clone"));
|
|
26
|
+
_clone = function () {
|
|
27
|
+
return data;
|
|
28
|
+
};
|
|
29
|
+
return data;
|
|
30
|
+
}
|
|
31
|
+
function _json() {
|
|
32
|
+
const data = _interopRequireDefault(require("json5"));
|
|
33
|
+
_json = function () {
|
|
34
|
+
return data;
|
|
35
|
+
};
|
|
36
|
+
return data;
|
|
37
|
+
}
|
|
38
|
+
function _toml() {
|
|
39
|
+
const data = require("@iarna/toml");
|
|
40
|
+
_toml = function () {
|
|
41
|
+
return data;
|
|
42
|
+
};
|
|
43
|
+
return data;
|
|
44
|
+
}
|
|
45
|
+
function _lruCache() {
|
|
46
|
+
const data = _interopRequireDefault(require("lru-cache"));
|
|
47
|
+
_lruCache = function () {
|
|
48
|
+
return data;
|
|
49
|
+
};
|
|
50
|
+
return data;
|
|
51
|
+
}
|
|
52
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
53
|
+
// @ts-expect-error TS7016
|
|
54
|
+
|
|
55
|
+
// @ts-expect-error TS2351
|
|
56
|
+
const configCache = new (_lruCache().default)({
|
|
57
|
+
max: 500
|
|
58
|
+
});
|
|
59
|
+
const resolveCache = new Map();
|
|
60
|
+
function resolveConfig(fs, filepath, filenames, projectRoot) {
|
|
61
|
+
// Cache the result of resolving config for this directory.
|
|
62
|
+
// This is automatically invalidated at the end of the current build.
|
|
63
|
+
let key = _path().default.dirname(filepath) + filenames.join(',');
|
|
64
|
+
let cached = resolveCache.get(key);
|
|
65
|
+
if (cached !== undefined) {
|
|
66
|
+
return Promise.resolve(cached);
|
|
67
|
+
}
|
|
68
|
+
let resolved = fs.findAncestorFile(filenames, _path().default.dirname(filepath), projectRoot);
|
|
69
|
+
resolveCache.set(key, resolved);
|
|
70
|
+
return Promise.resolve(resolved);
|
|
71
|
+
}
|
|
72
|
+
function resolveConfigSync(fs, filepath, filenames, projectRoot) {
|
|
73
|
+
return fs.findAncestorFile(filenames, _path().default.dirname(filepath), projectRoot);
|
|
74
|
+
}
|
|
75
|
+
async function loadConfig(fs, filepath, filenames, projectRoot, opts) {
|
|
76
|
+
let parse = (opts === null || opts === void 0 ? void 0 : opts.parse) ?? true;
|
|
77
|
+
let configFile = await resolveConfig(fs, filepath, filenames, projectRoot);
|
|
78
|
+
if (configFile) {
|
|
79
|
+
let cachedOutput = configCache.get(String(parse) + configFile);
|
|
80
|
+
if (cachedOutput) {
|
|
81
|
+
return cachedOutput;
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
let extname = _path().default.extname(configFile).slice(1);
|
|
85
|
+
if (extname === 'js' || extname === 'cjs') {
|
|
86
|
+
let output = {
|
|
87
|
+
config: (0, _clone().default)(module.require(configFile)),
|
|
88
|
+
files: [{
|
|
89
|
+
filePath: configFile
|
|
90
|
+
}]
|
|
91
|
+
};
|
|
92
|
+
configCache.set(configFile, output);
|
|
93
|
+
return output;
|
|
94
|
+
}
|
|
95
|
+
return readConfig(fs, configFile, opts);
|
|
96
|
+
} catch (err) {
|
|
97
|
+
if (err.code === 'MODULE_NOT_FOUND' || err.code === 'ENOENT') {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
throw err;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
loadConfig.clear = () => {
|
|
106
|
+
configCache.reset();
|
|
107
|
+
resolveCache.clear();
|
|
108
|
+
};
|
|
109
|
+
async function readConfig(fs, configFile, opts) {
|
|
110
|
+
let parse = (opts === null || opts === void 0 ? void 0 : opts.parse) ?? true;
|
|
111
|
+
let cachedOutput = configCache.get(String(parse) + configFile);
|
|
112
|
+
if (cachedOutput) {
|
|
113
|
+
return cachedOutput;
|
|
114
|
+
}
|
|
115
|
+
try {
|
|
116
|
+
let configContent = await fs.readFile(configFile, 'utf8');
|
|
117
|
+
let config;
|
|
118
|
+
if (parse === false) {
|
|
119
|
+
config = configContent;
|
|
120
|
+
} else {
|
|
121
|
+
let extname = _path().default.extname(configFile).slice(1);
|
|
122
|
+
let parse = (opts === null || opts === void 0 ? void 0 : opts.parser) ?? getParser(extname);
|
|
123
|
+
try {
|
|
124
|
+
config = parse(configContent);
|
|
125
|
+
} catch (e) {
|
|
126
|
+
if (extname !== '' && extname !== 'json') {
|
|
127
|
+
throw e;
|
|
128
|
+
}
|
|
129
|
+
let pos = {
|
|
130
|
+
line: e.lineNumber,
|
|
131
|
+
column: e.columnNumber
|
|
132
|
+
};
|
|
133
|
+
throw new (_diagnostic().default)({
|
|
134
|
+
diagnostic: {
|
|
135
|
+
message: `Failed to parse ${_path().default.basename(configFile)}`,
|
|
136
|
+
origin: '@atlaspack/utils',
|
|
137
|
+
codeFrames: [{
|
|
138
|
+
language: 'json5',
|
|
139
|
+
filePath: configFile,
|
|
140
|
+
code: configContent,
|
|
141
|
+
codeHighlights: [{
|
|
142
|
+
start: pos,
|
|
143
|
+
end: pos,
|
|
144
|
+
message: e.message
|
|
145
|
+
}]
|
|
146
|
+
}]
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
let output = {
|
|
152
|
+
config,
|
|
153
|
+
files: [{
|
|
154
|
+
filePath: configFile
|
|
155
|
+
}]
|
|
156
|
+
};
|
|
157
|
+
configCache.set(String(parse) + configFile, output);
|
|
158
|
+
return output;
|
|
159
|
+
} catch (err) {
|
|
160
|
+
if (err.code === 'MODULE_NOT_FOUND' || err.code === 'ENOENT') {
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
throw err;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function getParser(extname) {
|
|
167
|
+
switch (extname) {
|
|
168
|
+
case 'toml':
|
|
169
|
+
return _toml().parse;
|
|
170
|
+
case 'json':
|
|
171
|
+
default:
|
|
172
|
+
return _json().default.parse;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function countLines(string: string, startIndex?: number): number;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = countLines;
|
|
7
|
+
function countLines(string, startIndex = 0) {
|
|
8
|
+
let lines = 1;
|
|
9
|
+
for (let i = startIndex; i < string.length; i++) {
|
|
10
|
+
if (string.charAt(i) === '\n') {
|
|
11
|
+
lines++;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return lines;
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function debounce<TArgs extends Array<unknown>>(fn: (...args: TArgs) => unknown, delay: number): (...args: TArgs) => void;
|
package/lib/debounce.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = debounce;
|
|
7
|
+
function debounce(fn, delay) {
|
|
8
|
+
let timeout;
|
|
9
|
+
return function (...args) {
|
|
10
|
+
if (timeout) {
|
|
11
|
+
clearTimeout(timeout);
|
|
12
|
+
}
|
|
13
|
+
timeout = setTimeout(() => {
|
|
14
|
+
timeout = null;
|
|
15
|
+
fn(...args);
|
|
16
|
+
}, delay);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.debugTools = void 0;
|
|
7
|
+
/*
|
|
8
|
+
* These tools are intended for Atlaspack developers, to provide extra utilities
|
|
9
|
+
* to make debugging Atlaspack issues more straightforward.
|
|
10
|
+
*
|
|
11
|
+
* To enable a tool, set the `ATLASPACK_DEBUG_TOOLS` environment variable to a
|
|
12
|
+
* comma-separated list of tool names. For example:
|
|
13
|
+
* `ATLASPACK_DEBUG_TOOLS="asset-file-names-in-output,simple-cli-reporter"`
|
|
14
|
+
*
|
|
15
|
+
* You can enable all tools by setting `ATLASPACK_DEBUG_TOOLS=all`.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
let debugTools = exports.debugTools = {
|
|
19
|
+
'asset-file-names-in-output': false,
|
|
20
|
+
'simple-cli-reporter': false
|
|
21
|
+
};
|
|
22
|
+
const envVarValue = process.env.ATLASPACK_DEBUG_TOOLS ?? '';
|
|
23
|
+
for (let tool of envVarValue.split(',')) {
|
|
24
|
+
tool = tool.trim();
|
|
25
|
+
if (tool === 'all') {
|
|
26
|
+
for (let key in debugTools) {
|
|
27
|
+
debugTools[key] = true;
|
|
28
|
+
}
|
|
29
|
+
break;
|
|
30
|
+
} else if (debugTools.hasOwnProperty(tool)) {
|
|
31
|
+
debugTools[tool] = true;
|
|
32
|
+
} else if (tool === '') {
|
|
33
|
+
continue;
|
|
34
|
+
} else {
|
|
35
|
+
throw new Error(`Invalid debug tool option: ${tool}. Valid options are: ${Object.keys(debugTools).join(', ')}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export default function createDependencyLocation(start: {
|
|
2
|
+
line: number;
|
|
3
|
+
column: number;
|
|
4
|
+
}, specifier: string, lineOffset?: number, columnOffset?: number, importWrapperLength?: number): {
|
|
5
|
+
end: {
|
|
6
|
+
column: number;
|
|
7
|
+
line: number;
|
|
8
|
+
};
|
|
9
|
+
filePath: string;
|
|
10
|
+
start: {
|
|
11
|
+
column: number;
|
|
12
|
+
line: number;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = createDependencyLocation;
|
|
7
|
+
function createDependencyLocation(start, specifier, lineOffset = 0, columnOffset = 0,
|
|
8
|
+
// Imports are usually wrapped in quotes
|
|
9
|
+
importWrapperLength = 2) {
|
|
10
|
+
return {
|
|
11
|
+
filePath: specifier,
|
|
12
|
+
start: {
|
|
13
|
+
line: start.line + lineOffset,
|
|
14
|
+
column: start.column + columnOffset
|
|
15
|
+
},
|
|
16
|
+
end: {
|
|
17
|
+
line: start.line + lineOffset,
|
|
18
|
+
column: start.column + specifier.length - 1 + importWrapperLength + columnOffset
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function escapeHTML(s: string): string;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.escapeHTML = escapeHTML;
|
|
7
|
+
// Based on _.escape https://github.com/lodash/lodash/blob/master/escape.js
|
|
8
|
+
const reUnescapedHtml = /[&<>"']/g;
|
|
9
|
+
const reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
|
|
10
|
+
const htmlEscapes = {
|
|
11
|
+
'&': '&',
|
|
12
|
+
'<': '<',
|
|
13
|
+
'>': '>',
|
|
14
|
+
'"': '"',
|
|
15
|
+
"'": '''
|
|
16
|
+
};
|
|
17
|
+
function escapeHTML(s) {
|
|
18
|
+
if (reHasUnescapedHtml.test(s)) {
|
|
19
|
+
return s.replace(reUnescapedHtml, c => htmlEscapes[c]);
|
|
20
|
+
}
|
|
21
|
+
return s;
|
|
22
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { FilePath, PackagedBundle } from '@atlaspack/types';
|
|
2
|
+
import type { FileSystem } from '@atlaspack/fs';
|
|
3
|
+
export type AssetStats = {
|
|
4
|
+
filePath: string;
|
|
5
|
+
size: number;
|
|
6
|
+
originalSize: number;
|
|
7
|
+
time: number;
|
|
8
|
+
};
|
|
9
|
+
export type BundleStats = {
|
|
10
|
+
filePath: string;
|
|
11
|
+
size: number;
|
|
12
|
+
time: number;
|
|
13
|
+
assets: Array<AssetStats>;
|
|
14
|
+
};
|
|
15
|
+
export type BuildMetrics = {
|
|
16
|
+
bundles: Array<BundleStats>;
|
|
17
|
+
};
|
|
18
|
+
export default function generateBuildMetrics(bundles: Array<PackagedBundle>, fs: FileSystem, projectRoot: FilePath): Promise<BuildMetrics>;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = generateBuildMetrics;
|
|
7
|
+
function _sourceMap() {
|
|
8
|
+
const data = _interopRequireDefault(require("@parcel/source-map"));
|
|
9
|
+
_sourceMap = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
function _nullthrows() {
|
|
15
|
+
const data = _interopRequireDefault(require("nullthrows"));
|
|
16
|
+
_nullthrows = function () {
|
|
17
|
+
return data;
|
|
18
|
+
};
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
function _path() {
|
|
22
|
+
const data = _interopRequireDefault(require("path"));
|
|
23
|
+
_path = function () {
|
|
24
|
+
return data;
|
|
25
|
+
};
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
var _ = require("./");
|
|
29
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
30
|
+
async function getSourcemapSizes(filePath, fs, projectRoot) {
|
|
31
|
+
let bundleContents = await fs.readFile(filePath, 'utf-8');
|
|
32
|
+
let mapUrlData = await (0, _.loadSourceMapUrl)(fs, filePath, bundleContents);
|
|
33
|
+
if (!mapUrlData) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
let rawMap = mapUrlData.map;
|
|
37
|
+
let sourceMap = new (_sourceMap().default)(projectRoot);
|
|
38
|
+
sourceMap.addVLQMap(rawMap);
|
|
39
|
+
let parsedMapData = sourceMap.getMap();
|
|
40
|
+
if (parsedMapData.mappings.length > 2) {
|
|
41
|
+
let sources = parsedMapData.sources.map(s => _path().default.normalize(_path().default.join(projectRoot, s)));
|
|
42
|
+
let currLine = 1;
|
|
43
|
+
let currColumn = 0;
|
|
44
|
+
let currMappingIndex = 0;
|
|
45
|
+
let currMapping = parsedMapData.mappings[currMappingIndex];
|
|
46
|
+
let nextMapping = parsedMapData.mappings[currMappingIndex + 1];
|
|
47
|
+
let sourceSizes = new Array(sources.length).fill(0);
|
|
48
|
+
let unknownOrigin = 0;
|
|
49
|
+
for (let i = 0; i < bundleContents.length; i++) {
|
|
50
|
+
let character = bundleContents[i];
|
|
51
|
+
while (nextMapping && nextMapping.generated.line === currLine && nextMapping.generated.column <= currColumn) {
|
|
52
|
+
currMappingIndex++;
|
|
53
|
+
currMapping = parsedMapData.mappings[currMappingIndex];
|
|
54
|
+
nextMapping = parsedMapData.mappings[currMappingIndex + 1];
|
|
55
|
+
}
|
|
56
|
+
let currentSource = currMapping.source;
|
|
57
|
+
let charSize = Buffer.byteLength(character, 'utf8');
|
|
58
|
+
if (currentSource != null && currMapping.generated.line === currLine && currMapping.generated.column <= currColumn) {
|
|
59
|
+
sourceSizes[currentSource] += charSize;
|
|
60
|
+
} else {
|
|
61
|
+
unknownOrigin += charSize;
|
|
62
|
+
}
|
|
63
|
+
if (character === '\n') {
|
|
64
|
+
currColumn = 0;
|
|
65
|
+
currLine++;
|
|
66
|
+
} else {
|
|
67
|
+
currColumn++;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
let sizeMap = new Map();
|
|
71
|
+
for (let i = 0; i < sourceSizes.length; i++) {
|
|
72
|
+
sizeMap.set(sources[i], sourceSizes[i]);
|
|
73
|
+
}
|
|
74
|
+
sizeMap.set('', unknownOrigin);
|
|
75
|
+
return sizeMap;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
async function createBundleStats(bundle, fs, projectRoot) {
|
|
79
|
+
let filePath = bundle.filePath;
|
|
80
|
+
let sourcemapSizes = await getSourcemapSizes(filePath, fs, projectRoot);
|
|
81
|
+
let assets = new Map();
|
|
82
|
+
bundle.traverseAssets(asset => {
|
|
83
|
+
let filePath = _path().default.normalize(asset.filePath);
|
|
84
|
+
assets.set(filePath, {
|
|
85
|
+
filePath,
|
|
86
|
+
size: asset.stats.size,
|
|
87
|
+
originalSize: asset.stats.size,
|
|
88
|
+
time: asset.stats.time
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
let assetsReport = [];
|
|
92
|
+
if (sourcemapSizes && sourcemapSizes.size) {
|
|
93
|
+
assetsReport = Array.from(sourcemapSizes.keys()).map(filePath => {
|
|
94
|
+
let foundSize = sourcemapSizes.get(filePath) || 0;
|
|
95
|
+
let stats = assets.get(filePath) || {
|
|
96
|
+
filePath,
|
|
97
|
+
size: foundSize,
|
|
98
|
+
originalSize: foundSize,
|
|
99
|
+
time: 0
|
|
100
|
+
};
|
|
101
|
+
return {
|
|
102
|
+
...stats,
|
|
103
|
+
size: foundSize
|
|
104
|
+
};
|
|
105
|
+
});
|
|
106
|
+
} else {
|
|
107
|
+
assetsReport = Array.from(assets.values());
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
filePath: (0, _nullthrows().default)(bundle.filePath),
|
|
111
|
+
size: bundle.stats.size,
|
|
112
|
+
time: bundle.stats.time,
|
|
113
|
+
assets: assetsReport.sort((a, b) => b.size - a.size)
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
async function generateBuildMetrics(bundles, fs, projectRoot) {
|
|
117
|
+
bundles.sort((a, b) => b.stats.size - a.stats.size).filter(b => !!b.filePath);
|
|
118
|
+
return {
|
|
119
|
+
bundles: (await Promise.all(bundles.map(b => createBundleStats(b, fs, projectRoot)))).filter(e => !!e)
|
|
120
|
+
};
|
|
121
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = generateCertificate;
|
|
7
|
+
function _nodeForge() {
|
|
8
|
+
const data = _interopRequireDefault(require("node-forge"));
|
|
9
|
+
_nodeForge = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
function _path() {
|
|
15
|
+
const data = _interopRequireDefault(require("path"));
|
|
16
|
+
_path = function () {
|
|
17
|
+
return data;
|
|
18
|
+
};
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
function _logger() {
|
|
22
|
+
const data = _interopRequireDefault(require("@atlaspack/logger"));
|
|
23
|
+
_logger = function () {
|
|
24
|
+
return data;
|
|
25
|
+
};
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
|
+
async function generateCertificate(fs, cacheDir, host) {
|
|
30
|
+
let certDirectory = cacheDir;
|
|
31
|
+
const privateKeyPath = _path().default.join(certDirectory, 'private.pem');
|
|
32
|
+
const certPath = _path().default.join(certDirectory, 'primary.crt');
|
|
33
|
+
const cachedKey = (await fs.exists(privateKeyPath)) && (await fs.readFile(privateKeyPath));
|
|
34
|
+
const cachedCert = (await fs.exists(certPath)) && (await fs.readFile(certPath));
|
|
35
|
+
if (cachedKey && cachedCert) {
|
|
36
|
+
return {
|
|
37
|
+
key: cachedKey,
|
|
38
|
+
cert: cachedCert
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
_logger().default.progress('Generating SSL Certificate...');
|
|
42
|
+
const pki = _nodeForge().default.pki;
|
|
43
|
+
const keys = pki.rsa.generateKeyPair(2048);
|
|
44
|
+
const cert = pki.createCertificate();
|
|
45
|
+
cert.publicKey = keys.publicKey;
|
|
46
|
+
cert.serialNumber = Date.now().toString();
|
|
47
|
+
cert.validity.notBefore = new Date();
|
|
48
|
+
cert.validity.notAfter = new Date();
|
|
49
|
+
cert.validity.notAfter.setFullYear(cert.validity.notBefore.getFullYear() + 1);
|
|
50
|
+
const attrs = [{
|
|
51
|
+
name: 'commonName',
|
|
52
|
+
value: 'parceljs.org'
|
|
53
|
+
}, {
|
|
54
|
+
name: 'countryName',
|
|
55
|
+
value: 'US'
|
|
56
|
+
}, {
|
|
57
|
+
shortName: 'ST',
|
|
58
|
+
value: 'Virginia'
|
|
59
|
+
}, {
|
|
60
|
+
name: 'localityName',
|
|
61
|
+
value: 'Blacksburg'
|
|
62
|
+
}, {
|
|
63
|
+
name: 'organizationName',
|
|
64
|
+
value: 'parcelBundler'
|
|
65
|
+
}, {
|
|
66
|
+
shortName: 'OU',
|
|
67
|
+
value: 'Test'
|
|
68
|
+
}];
|
|
69
|
+
let altNames = [{
|
|
70
|
+
type: 2,
|
|
71
|
+
// DNS
|
|
72
|
+
value: 'localhost'
|
|
73
|
+
}, {
|
|
74
|
+
type: 7,
|
|
75
|
+
// IP
|
|
76
|
+
ip: '127.0.0.1'
|
|
77
|
+
}];
|
|
78
|
+
if (host) {
|
|
79
|
+
altNames.push({
|
|
80
|
+
type: 2,
|
|
81
|
+
// DNS
|
|
82
|
+
value: host
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
cert.setSubject(attrs);
|
|
86
|
+
cert.setIssuer(attrs);
|
|
87
|
+
cert.setExtensions([{
|
|
88
|
+
name: 'basicConstraints',
|
|
89
|
+
cA: false
|
|
90
|
+
}, {
|
|
91
|
+
name: 'keyUsage',
|
|
92
|
+
keyCertSign: true,
|
|
93
|
+
digitalSignature: true,
|
|
94
|
+
nonRepudiation: true,
|
|
95
|
+
keyEncipherment: true,
|
|
96
|
+
dataEncipherment: true
|
|
97
|
+
}, {
|
|
98
|
+
name: 'extKeyUsage',
|
|
99
|
+
serverAuth: true,
|
|
100
|
+
clientAuth: true,
|
|
101
|
+
codeSigning: true,
|
|
102
|
+
emailProtection: true,
|
|
103
|
+
timeStamping: true
|
|
104
|
+
}, {
|
|
105
|
+
name: 'nsCertType',
|
|
106
|
+
client: true,
|
|
107
|
+
server: true,
|
|
108
|
+
email: true,
|
|
109
|
+
objsign: true,
|
|
110
|
+
sslCA: true,
|
|
111
|
+
emailCA: true,
|
|
112
|
+
objCA: true
|
|
113
|
+
}, {
|
|
114
|
+
name: 'subjectAltName',
|
|
115
|
+
altNames
|
|
116
|
+
}, {
|
|
117
|
+
name: 'subjectKeyIdentifier'
|
|
118
|
+
}]);
|
|
119
|
+
cert.sign(keys.privateKey, _nodeForge().default.md.sha256.create());
|
|
120
|
+
const privPem = pki.privateKeyToPem(keys.privateKey);
|
|
121
|
+
const certPem = pki.certificateToPem(cert);
|
|
122
|
+
await fs.mkdirp(certDirectory);
|
|
123
|
+
await fs.writeFile(privateKeyPath, privPem);
|
|
124
|
+
await fs.writeFile(certPath, certPem);
|
|
125
|
+
return {
|
|
126
|
+
key: privPem,
|
|
127
|
+
cert: certPem
|
|
128
|
+
};
|
|
129
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = getCertificate;
|
|
7
|
+
async function getCertificate(fs, options) {
|
|
8
|
+
try {
|
|
9
|
+
let cert = await fs.readFile(options.cert);
|
|
10
|
+
let key = await fs.readFile(options.key);
|
|
11
|
+
return {
|
|
12
|
+
key,
|
|
13
|
+
cert
|
|
14
|
+
};
|
|
15
|
+
} catch (err) {
|
|
16
|
+
throw new Error('Certificate and/or key not found');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates an object that contains both source and minified (using the source as a fallback).
|
|
3
|
+
* e.g. builtins.min.js and builtins.js.
|
|
4
|
+
*/
|
|
5
|
+
export default function getExisting(minifiedPath: string, sourcePath: string): {
|
|
6
|
+
minified: string;
|
|
7
|
+
source: string;
|
|
8
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = getExisting;
|
|
7
|
+
function _fs() {
|
|
8
|
+
const data = _interopRequireDefault(require("fs"));
|
|
9
|
+
_fs = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
/**
|
|
16
|
+
* Creates an object that contains both source and minified (using the source as a fallback).
|
|
17
|
+
* e.g. builtins.min.js and builtins.js.
|
|
18
|
+
*/
|
|
19
|
+
function getExisting(minifiedPath, sourcePath) {
|
|
20
|
+
let source = _fs().default.readFileSync(sourcePath, 'utf8').trim();
|
|
21
|
+
return {
|
|
22
|
+
source,
|
|
23
|
+
minified: _fs().default.existsSync(minifiedPath) ? _fs().default.readFileSync(minifiedPath, 'utf8').trim().replace(/;$/, '') : source
|
|
24
|
+
};
|
|
25
|
+
}
|