@parcel/utils 2.0.0-beta.2 → 2.0.0-nightly.1004
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/index.js +35741 -542
- package/lib/index.js.map +1 -0
- package/package.json +36 -16
- package/src/DefaultMap.js +1 -1
- package/src/alternatives.js +26 -7
- package/src/ansi-html.js +1 -1
- package/src/blob.js +1 -0
- package/src/collection.js +14 -2
- package/src/config.js +59 -9
- package/src/countLines.js +5 -2
- package/src/debounce.js +1 -1
- package/src/dependency-location.js +5 -5
- package/src/generateBuildMetrics.js +4 -4
- package/src/getExisting.js +1 -4
- package/src/glob.js +14 -3
- package/src/hash.js +34 -0
- package/src/index.js +10 -10
- package/src/path.js +11 -1
- package/src/prettyDiagnostic.js +40 -25
- package/src/relativeBundlePath.js +3 -5
- package/src/replaceBundleReferences.js +42 -24
- package/src/schema.js +22 -19
- package/src/shared-buffer.js +24 -0
- package/src/sourcemap.js +60 -5
- 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/replaceBundleReferences.test.js +96 -4
- package/test/sourcemap.test.js +3 -3
- package/test/throttle.test.js +1 -1
- package/test/urlJoin.test.js +11 -0
- package/lib/DefaultMap.js +0 -64
- package/lib/Deferred.js +0 -34
- package/lib/PromiseQueue.js +0 -144
- package/lib/TapStream.js +0 -46
- package/lib/alternatives.js +0 -151
- package/lib/ansi-html.js +0 -32
- package/lib/blob.js +0 -47
- package/lib/bundle-url.js +0 -43
- package/lib/collection.js +0 -51
- package/lib/config.js +0 -146
- package/lib/countLines.js +0 -18
- package/lib/debounce.js +0 -20
- package/lib/dependency-location.js +0 -21
- package/lib/escape-html.js +0 -24
- package/lib/generateBuildMetrics.js +0 -156
- package/lib/generateCertificate.js +0 -149
- package/lib/getCertificate.js +0 -19
- package/lib/getExisting.js +0 -31
- package/lib/getRootDir.js +0 -74
- package/lib/glob.js +0 -118
- package/lib/http-server.js +0 -110
- package/lib/is-url.js +0 -27
- package/lib/isDirectoryInside.js +0 -24
- package/lib/md5.js +0 -61
- package/lib/objectHash.js +0 -34
- package/lib/openInBrowser.js +0 -94
- package/lib/parseCSSImport.js +0 -16
- package/lib/path.js +0 -44
- package/lib/prettifyTime.js +0 -10
- package/lib/prettyDiagnostic.js +0 -115
- package/lib/relativeBundlePath.js +0 -34
- package/lib/relativeUrl.js +0 -32
- package/lib/replaceBundleReferences.js +0 -184
- package/lib/schema.js +0 -391
- package/lib/sourcemap.js +0 -94
- package/lib/stream.js +0 -86
- package/lib/throttle.js +0 -16
- package/lib/urlJoin.js +0 -43
- package/src/.babelrc +0 -3
- package/src/md5.js +0 -56
package/lib/blob.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.blobToBuffer = blobToBuffer;
|
|
7
|
-
exports.blobToString = blobToString;
|
|
8
|
-
|
|
9
|
-
function _() {
|
|
10
|
-
const data = require("./");
|
|
11
|
-
|
|
12
|
-
_ = function () {
|
|
13
|
-
return data;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
return data;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function _stream() {
|
|
20
|
-
const data = require("stream");
|
|
21
|
-
|
|
22
|
-
_stream = function () {
|
|
23
|
-
return data;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
return data;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function blobToBuffer(blob) {
|
|
30
|
-
if (blob instanceof _stream().Readable) {
|
|
31
|
-
return (0, _().bufferStream)(blob);
|
|
32
|
-
} else if (blob instanceof Buffer) {
|
|
33
|
-
return Promise.resolve(Buffer.from(blob));
|
|
34
|
-
} else {
|
|
35
|
-
return Promise.resolve(Buffer.from(blob, 'utf8'));
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async function blobToString(blob) {
|
|
40
|
-
if (blob instanceof _stream().Readable) {
|
|
41
|
-
return (await (0, _().bufferStream)(blob)).toString();
|
|
42
|
-
} else if (blob instanceof Buffer) {
|
|
43
|
-
return blob.toString();
|
|
44
|
-
} else {
|
|
45
|
-
return blob;
|
|
46
|
-
}
|
|
47
|
-
}
|
package/lib/bundle-url.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getBaseURL = getBaseURL;
|
|
7
|
-
exports.getBundleURL = void 0;
|
|
8
|
-
let bundleURL = null;
|
|
9
|
-
|
|
10
|
-
function getBundleURLCached() {
|
|
11
|
-
if (bundleURL == null) {
|
|
12
|
-
bundleURL = _getBundleURL();
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return bundleURL;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function _getBundleURL() {
|
|
19
|
-
// Attempt to find the URL of the current script and use that as the base URL
|
|
20
|
-
try {
|
|
21
|
-
throw new Error();
|
|
22
|
-
} catch (err) {
|
|
23
|
-
let stack = typeof err.stack === 'string' ? err.stack : '';
|
|
24
|
-
let matches = stack.match(/(https?|file|ftp):\/\/[^)\n]+/g);
|
|
25
|
-
|
|
26
|
-
if (matches) {
|
|
27
|
-
return getBaseURL(matches[0]);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return '/';
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function getBaseURL(url) {
|
|
35
|
-
if (url == null) {
|
|
36
|
-
return '/';
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return url.replace(/^((?:https?|file|ftp):\/\/.+)\/[^/]+$/, '$1') + '/';
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const getBundleURL = getBundleURLCached;
|
|
43
|
-
exports.getBundleURL = getBundleURL;
|
package/lib/collection.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.unique = unique;
|
|
7
|
-
exports.objectSortedEntries = objectSortedEntries;
|
|
8
|
-
exports.objectSortedEntriesDeep = objectSortedEntriesDeep;
|
|
9
|
-
exports.setDifference = setDifference;
|
|
10
|
-
|
|
11
|
-
function unique(array) {
|
|
12
|
-
return [...new Set(array)];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function objectSortedEntries(obj) {
|
|
16
|
-
return Object.entries(obj).sort(([keyA], [keyB]) => keyA.localeCompare(keyB));
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function objectSortedEntriesDeep(object) {
|
|
20
|
-
let sortedEntries = objectSortedEntries(object);
|
|
21
|
-
|
|
22
|
-
for (let i = 0; i < sortedEntries.length; i++) {
|
|
23
|
-
sortedEntries[i][1] = sortEntry(sortedEntries[i][1]);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return sortedEntries;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function sortEntry(entry) {
|
|
30
|
-
if (Array.isArray(entry)) {
|
|
31
|
-
return entry.map(sortEntry);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (typeof entry === 'object' && entry != null) {
|
|
35
|
-
return objectSortedEntriesDeep(entry);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return entry;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function setDifference(a, b) {
|
|
42
|
-
let difference = new Set();
|
|
43
|
-
|
|
44
|
-
for (let e of a) {
|
|
45
|
-
if (!b.has(e)) {
|
|
46
|
-
difference.add(e);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return difference;
|
|
51
|
-
}
|
package/lib/config.js
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.resolveConfig = resolveConfig;
|
|
7
|
-
exports.resolveConfigSync = resolveConfigSync;
|
|
8
|
-
exports.loadConfig = loadConfig;
|
|
9
|
-
|
|
10
|
-
function _path() {
|
|
11
|
-
const data = _interopRequireDefault(require("path"));
|
|
12
|
-
|
|
13
|
-
_path = function () {
|
|
14
|
-
return data;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
return data;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function _clone() {
|
|
21
|
-
const data = _interopRequireDefault(require("clone"));
|
|
22
|
-
|
|
23
|
-
_clone = function () {
|
|
24
|
-
return data;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
return data;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function _json() {
|
|
31
|
-
const data = require("json5");
|
|
32
|
-
|
|
33
|
-
_json = function () {
|
|
34
|
-
return data;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
return data;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function _toml() {
|
|
41
|
-
const data = require("@iarna/toml");
|
|
42
|
-
|
|
43
|
-
_toml = function () {
|
|
44
|
-
return data;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
return data;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function _lruCache() {
|
|
51
|
-
const data = _interopRequireDefault(require("lru-cache"));
|
|
52
|
-
|
|
53
|
-
_lruCache = function () {
|
|
54
|
-
return data;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
return data;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
61
|
-
|
|
62
|
-
const configCache = new (_lruCache().default)({
|
|
63
|
-
max: 500
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
function resolveConfig(fs, filepath, filenames) {
|
|
67
|
-
return Promise.resolve(fs.findAncestorFile(filenames, _path().default.dirname(filepath)));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function resolveConfigSync(fs, filepath, filenames) {
|
|
71
|
-
return fs.findAncestorFile(filenames, _path().default.dirname(filepath));
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
async function loadConfig(fs, filepath, filenames, opts) {
|
|
75
|
-
var _opts$parse;
|
|
76
|
-
|
|
77
|
-
let parse = (_opts$parse = opts === null || opts === void 0 ? void 0 : opts.parse) !== null && _opts$parse !== void 0 ? _opts$parse : true;
|
|
78
|
-
let configFile = await resolveConfig(fs, filepath, filenames);
|
|
79
|
-
|
|
80
|
-
if (configFile) {
|
|
81
|
-
let cachedOutput = configCache.get(String(parse) + configFile);
|
|
82
|
-
|
|
83
|
-
if (cachedOutput) {
|
|
84
|
-
return cachedOutput;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
try {
|
|
88
|
-
let extname = _path().default.extname(configFile).slice(1);
|
|
89
|
-
|
|
90
|
-
if (extname === 'js') {
|
|
91
|
-
let output = {
|
|
92
|
-
// $FlowFixMe
|
|
93
|
-
config: (0, _clone().default)(require(configFile)),
|
|
94
|
-
files: [{
|
|
95
|
-
filePath: configFile
|
|
96
|
-
}]
|
|
97
|
-
};
|
|
98
|
-
configCache.set(configFile, output);
|
|
99
|
-
return output;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
let configContent = await fs.readFile(configFile, 'utf8');
|
|
103
|
-
if (!configContent) return null;
|
|
104
|
-
let config;
|
|
105
|
-
|
|
106
|
-
if (parse === false) {
|
|
107
|
-
config = configContent;
|
|
108
|
-
} else {
|
|
109
|
-
let parse = getParser(extname);
|
|
110
|
-
config = parse(configContent);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
let output = {
|
|
114
|
-
config,
|
|
115
|
-
files: [{
|
|
116
|
-
filePath: configFile
|
|
117
|
-
}]
|
|
118
|
-
};
|
|
119
|
-
configCache.set(String(parse) + configFile, output);
|
|
120
|
-
return output;
|
|
121
|
-
} catch (err) {
|
|
122
|
-
if (err.code === 'MODULE_NOT_FOUND' || err.code === 'ENOENT') {
|
|
123
|
-
return null;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
throw err;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return null;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
loadConfig.clear = () => {
|
|
134
|
-
configCache.reset();
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
function getParser(extname) {
|
|
138
|
-
switch (extname) {
|
|
139
|
-
case 'toml':
|
|
140
|
-
return _toml().parse;
|
|
141
|
-
|
|
142
|
-
case 'json':
|
|
143
|
-
default:
|
|
144
|
-
return _json().parse;
|
|
145
|
-
}
|
|
146
|
-
}
|
package/lib/countLines.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = countLines;
|
|
7
|
-
|
|
8
|
-
function countLines(string) {
|
|
9
|
-
let lines = 1;
|
|
10
|
-
|
|
11
|
-
for (let i = 0; i < string.length; i++) {
|
|
12
|
-
if (string.charAt(i) === '\n') {
|
|
13
|
-
lines++;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return lines;
|
|
18
|
-
}
|
package/lib/debounce.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = debounce;
|
|
7
|
-
|
|
8
|
-
function debounce(fn, delay) {
|
|
9
|
-
let timeout;
|
|
10
|
-
return function (...args) {
|
|
11
|
-
if (timeout) {
|
|
12
|
-
clearTimeout(timeout);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
timeout = setTimeout(() => {
|
|
16
|
-
timeout = null;
|
|
17
|
-
fn(...args);
|
|
18
|
-
}, delay);
|
|
19
|
-
};
|
|
20
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = createDependencyLocation;
|
|
7
|
-
|
|
8
|
-
function createDependencyLocation(start, moduleSpecifier, lineOffset = 0, columnOffset = 0, // Imports are usually wrapped in quotes
|
|
9
|
-
importWrapperLength = 2) {
|
|
10
|
-
return {
|
|
11
|
-
filePath: moduleSpecifier,
|
|
12
|
-
start: {
|
|
13
|
-
line: start.line + lineOffset,
|
|
14
|
-
column: start.column + columnOffset
|
|
15
|
-
},
|
|
16
|
-
end: {
|
|
17
|
-
line: start.line + lineOffset,
|
|
18
|
-
column: start.column + moduleSpecifier.length - 1 + importWrapperLength + columnOffset
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
}
|
package/lib/escape-html.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
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
|
-
|
|
18
|
-
function escapeHTML(s) {
|
|
19
|
-
if (reHasUnescapedHtml.test(s)) {
|
|
20
|
-
return s.replace(reUnescapedHtml, c => htmlEscapes[c]);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return s;
|
|
24
|
-
}
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = generateBuildMetrics;
|
|
7
|
-
|
|
8
|
-
function _sourceMap() {
|
|
9
|
-
const data = _interopRequireDefault(require("@parcel/source-map"));
|
|
10
|
-
|
|
11
|
-
_sourceMap = function () {
|
|
12
|
-
return data;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function _nullthrows() {
|
|
19
|
-
const data = _interopRequireDefault(require("nullthrows"));
|
|
20
|
-
|
|
21
|
-
_nullthrows = function () {
|
|
22
|
-
return data;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
return data;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function _path() {
|
|
29
|
-
const data = _interopRequireDefault(require("path"));
|
|
30
|
-
|
|
31
|
-
_path = function () {
|
|
32
|
-
return data;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
return data;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function _() {
|
|
39
|
-
const data = require("./");
|
|
40
|
-
|
|
41
|
-
_ = function () {
|
|
42
|
-
return data;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
return data;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
49
|
-
|
|
50
|
-
async function getSourcemapSizes(filePath, fs, projectRoot) {
|
|
51
|
-
let bundleContents = await fs.readFile(filePath, 'utf-8');
|
|
52
|
-
let mapUrlData = await (0, _().loadSourceMapUrl)(fs, filePath, bundleContents);
|
|
53
|
-
|
|
54
|
-
if (!mapUrlData) {
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
let rawMap = mapUrlData.map;
|
|
59
|
-
let sourceMap = new (_sourceMap().default)(projectRoot);
|
|
60
|
-
sourceMap.addRawMappings(rawMap);
|
|
61
|
-
let parsedMapData = sourceMap.getMap();
|
|
62
|
-
|
|
63
|
-
if (parsedMapData.mappings.length > 2) {
|
|
64
|
-
let sources = parsedMapData.sources.map(s => _path().default.normalize(_path().default.join(projectRoot, s)));
|
|
65
|
-
let currLine = 1;
|
|
66
|
-
let currColumn = 0;
|
|
67
|
-
let currMappingIndex = 0;
|
|
68
|
-
let currMapping = parsedMapData.mappings[currMappingIndex];
|
|
69
|
-
let nextMapping = parsedMapData.mappings[currMappingIndex + 1];
|
|
70
|
-
let sourceSizes = new Array(sources.length).fill(0);
|
|
71
|
-
let unknownOrigin = 0;
|
|
72
|
-
|
|
73
|
-
for (let i = 0; i < bundleContents.length; i++) {
|
|
74
|
-
let character = bundleContents[i];
|
|
75
|
-
|
|
76
|
-
while (nextMapping && nextMapping.generated.line === currLine && nextMapping.generated.column <= currColumn) {
|
|
77
|
-
currMappingIndex++;
|
|
78
|
-
currMapping = parsedMapData.mappings[currMappingIndex];
|
|
79
|
-
nextMapping = parsedMapData.mappings[currMappingIndex + 1];
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
let currentSource = currMapping.source;
|
|
83
|
-
let charSize = Buffer.byteLength(character, 'utf8');
|
|
84
|
-
|
|
85
|
-
if (currentSource != null && currMapping.generated.line === currLine && currMapping.generated.column <= currColumn) {
|
|
86
|
-
sourceSizes[currentSource] += charSize;
|
|
87
|
-
} else {
|
|
88
|
-
unknownOrigin += charSize;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (character === '\n') {
|
|
92
|
-
currColumn = 0;
|
|
93
|
-
currLine++;
|
|
94
|
-
} else {
|
|
95
|
-
currColumn++;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
let sizeMap = new Map();
|
|
100
|
-
|
|
101
|
-
for (let i = 0; i < sourceSizes.length; i++) {
|
|
102
|
-
sizeMap.set(sources[i], sourceSizes[i]);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
sizeMap.set('', unknownOrigin);
|
|
106
|
-
return sizeMap;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
async function createBundleStats(bundle, fs, projectRoot) {
|
|
111
|
-
let filePath = bundle.filePath;
|
|
112
|
-
let sourcemapSizes = await getSourcemapSizes(filePath, fs, projectRoot);
|
|
113
|
-
let assets = new Map();
|
|
114
|
-
bundle.traverseAssets(asset => {
|
|
115
|
-
let filePath = _path().default.normalize(asset.filePath);
|
|
116
|
-
|
|
117
|
-
assets.set(filePath, {
|
|
118
|
-
filePath,
|
|
119
|
-
size: asset.stats.size,
|
|
120
|
-
originalSize: asset.stats.size,
|
|
121
|
-
time: asset.stats.time
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
let assetsReport = [];
|
|
125
|
-
|
|
126
|
-
if (sourcemapSizes && sourcemapSizes.size) {
|
|
127
|
-
assetsReport = Array.from(sourcemapSizes.keys()).map(filePath => {
|
|
128
|
-
let foundSize = sourcemapSizes.get(filePath) || 0;
|
|
129
|
-
let stats = assets.get(filePath) || {
|
|
130
|
-
filePath,
|
|
131
|
-
size: foundSize,
|
|
132
|
-
originalSize: foundSize,
|
|
133
|
-
time: 0
|
|
134
|
-
};
|
|
135
|
-
return { ...stats,
|
|
136
|
-
size: foundSize
|
|
137
|
-
};
|
|
138
|
-
});
|
|
139
|
-
} else {
|
|
140
|
-
assetsReport = Array.from(assets.values());
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return {
|
|
144
|
-
filePath: (0, _nullthrows().default)(bundle.filePath),
|
|
145
|
-
size: bundle.stats.size,
|
|
146
|
-
time: bundle.stats.time,
|
|
147
|
-
assets: assetsReport.sort((a, b) => b.size - a.size)
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
async function generateBuildMetrics(bundles, fs, projectRoot) {
|
|
152
|
-
bundles.sort((a, b) => b.stats.size - a.stats.size).filter(b => !!b.filePath);
|
|
153
|
-
return {
|
|
154
|
-
bundles: (await Promise.all(bundles.map(b => createBundleStats(b, fs, projectRoot)))).filter(e => !!e)
|
|
155
|
-
};
|
|
156
|
-
}
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = generateCertificate;
|
|
7
|
-
|
|
8
|
-
function _nodeForge() {
|
|
9
|
-
const data = _interopRequireDefault(require("node-forge"));
|
|
10
|
-
|
|
11
|
-
_nodeForge = function () {
|
|
12
|
-
return data;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function _path() {
|
|
19
|
-
const data = _interopRequireDefault(require("path"));
|
|
20
|
-
|
|
21
|
-
_path = 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
|
-
async function generateCertificate(fs, cacheDir, host) {
|
|
41
|
-
let certDirectory = cacheDir;
|
|
42
|
-
|
|
43
|
-
const privateKeyPath = _path().default.join(certDirectory, 'private.pem');
|
|
44
|
-
|
|
45
|
-
const certPath = _path().default.join(certDirectory, 'primary.crt');
|
|
46
|
-
|
|
47
|
-
const cachedKey = (await fs.exists(privateKeyPath)) && (await fs.readFile(privateKeyPath));
|
|
48
|
-
const cachedCert = (await fs.exists(certPath)) && (await fs.readFile(certPath));
|
|
49
|
-
|
|
50
|
-
if (cachedKey && cachedCert) {
|
|
51
|
-
return {
|
|
52
|
-
key: cachedKey,
|
|
53
|
-
cert: cachedCert
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
_logger().default.progress('Generating SSL Certificate...');
|
|
58
|
-
|
|
59
|
-
const pki = _nodeForge().default.pki;
|
|
60
|
-
|
|
61
|
-
const keys = pki.rsa.generateKeyPair(2048);
|
|
62
|
-
const cert = pki.createCertificate();
|
|
63
|
-
cert.publicKey = keys.publicKey;
|
|
64
|
-
cert.serialNumber = Date.now().toString();
|
|
65
|
-
cert.validity.notBefore = new Date();
|
|
66
|
-
cert.validity.notAfter = new Date();
|
|
67
|
-
cert.validity.notAfter.setFullYear(cert.validity.notBefore.getFullYear() + 1);
|
|
68
|
-
const attrs = [{
|
|
69
|
-
name: 'commonName',
|
|
70
|
-
value: 'parceljs.org'
|
|
71
|
-
}, {
|
|
72
|
-
name: 'countryName',
|
|
73
|
-
value: 'US'
|
|
74
|
-
}, {
|
|
75
|
-
shortName: 'ST',
|
|
76
|
-
value: 'Virginia'
|
|
77
|
-
}, {
|
|
78
|
-
name: 'localityName',
|
|
79
|
-
value: 'Blacksburg'
|
|
80
|
-
}, {
|
|
81
|
-
name: 'organizationName',
|
|
82
|
-
value: 'parcelBundler'
|
|
83
|
-
}, {
|
|
84
|
-
shortName: 'OU',
|
|
85
|
-
value: 'Test'
|
|
86
|
-
}];
|
|
87
|
-
let altNames = [{
|
|
88
|
-
type: 2,
|
|
89
|
-
// DNS
|
|
90
|
-
value: 'localhost'
|
|
91
|
-
}, {
|
|
92
|
-
type: 7,
|
|
93
|
-
// IP
|
|
94
|
-
ip: '127.0.0.1'
|
|
95
|
-
}];
|
|
96
|
-
|
|
97
|
-
if (host) {
|
|
98
|
-
altNames.push({
|
|
99
|
-
type: 2,
|
|
100
|
-
// DNS
|
|
101
|
-
value: host
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
cert.setSubject(attrs);
|
|
106
|
-
cert.setIssuer(attrs);
|
|
107
|
-
cert.setExtensions([{
|
|
108
|
-
name: 'basicConstraints',
|
|
109
|
-
cA: false
|
|
110
|
-
}, {
|
|
111
|
-
name: 'keyUsage',
|
|
112
|
-
keyCertSign: true,
|
|
113
|
-
digitalSignature: true,
|
|
114
|
-
nonRepudiation: true,
|
|
115
|
-
keyEncipherment: true,
|
|
116
|
-
dataEncipherment: true
|
|
117
|
-
}, {
|
|
118
|
-
name: 'extKeyUsage',
|
|
119
|
-
serverAuth: true,
|
|
120
|
-
clientAuth: true,
|
|
121
|
-
codeSigning: true,
|
|
122
|
-
emailProtection: true,
|
|
123
|
-
timeStamping: true
|
|
124
|
-
}, {
|
|
125
|
-
name: 'nsCertType',
|
|
126
|
-
client: true,
|
|
127
|
-
server: true,
|
|
128
|
-
email: true,
|
|
129
|
-
objsign: true,
|
|
130
|
-
sslCA: true,
|
|
131
|
-
emailCA: true,
|
|
132
|
-
objCA: true
|
|
133
|
-
}, {
|
|
134
|
-
name: 'subjectAltName',
|
|
135
|
-
altNames
|
|
136
|
-
}, {
|
|
137
|
-
name: 'subjectKeyIdentifier'
|
|
138
|
-
}]);
|
|
139
|
-
cert.sign(keys.privateKey, _nodeForge().default.md.sha256.create());
|
|
140
|
-
const privPem = pki.privateKeyToPem(keys.privateKey);
|
|
141
|
-
const certPem = pki.certificateToPem(cert);
|
|
142
|
-
await fs.mkdirp(certDirectory);
|
|
143
|
-
await fs.writeFile(privateKeyPath, privPem);
|
|
144
|
-
await fs.writeFile(certPath, certPem);
|
|
145
|
-
return {
|
|
146
|
-
key: privPem,
|
|
147
|
-
cert: certPem
|
|
148
|
-
};
|
|
149
|
-
}
|
package/lib/getCertificate.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = getCertificate;
|
|
7
|
-
|
|
8
|
-
async function getCertificate(fs, options) {
|
|
9
|
-
try {
|
|
10
|
-
let cert = await fs.readFile(options.cert);
|
|
11
|
-
let key = await fs.readFile(options.key);
|
|
12
|
-
return {
|
|
13
|
-
key,
|
|
14
|
-
cert
|
|
15
|
-
};
|
|
16
|
-
} catch (err) {
|
|
17
|
-
throw new Error('Certificate and/or key not found');
|
|
18
|
-
}
|
|
19
|
-
}
|