@parcel/utils 2.0.0-nightly.978 → 2.0.0-nightly.992
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 +35876 -411
- package/lib/index.js.map +1 -0
- package/package.json +28 -15
- package/src/config.js +2 -2
- package/src/glob.js +14 -3
- package/src/index.js +1 -1
- package/lib/DefaultMap.js +0 -56
- package/lib/Deferred.js +0 -34
- package/lib/PromiseQueue.js +0 -124
- package/lib/TapStream.js +0 -41
- package/lib/alternatives.js +0 -134
- package/lib/ansi-html.js +0 -24
- package/lib/blob.js +0 -49
- package/lib/bundle-url.js +0 -43
- package/lib/collection.js +0 -65
- package/lib/config.js +0 -198
- 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 -148
- package/lib/generateCertificate.js +0 -149
- package/lib/getCertificate.js +0 -19
- package/lib/getExisting.js +0 -31
- package/lib/getRootDir.js +0 -66
- package/lib/glob.js +0 -110
- package/lib/hash.js +0 -44
- package/lib/http-server.js +0 -102
- package/lib/is-url.js +0 -27
- package/lib/isDirectoryInside.js +0 -24
- package/lib/objectHash.js +0 -34
- package/lib/openInBrowser.js +0 -94
- package/lib/parseCSSImport.js +0 -16
- package/lib/path.js +0 -49
- package/lib/prettifyTime.js +0 -10
- package/lib/prettyDiagnostic.js +0 -139
- package/lib/relativeBundlePath.js +0 -30
- package/lib/relativeUrl.js +0 -32
- package/lib/replaceBundleReferences.js +0 -211
- package/lib/schema.js +0 -391
- package/lib/shared-buffer.js +0 -31
- package/lib/sourcemap.js +0 -147
- package/lib/stream.js +0 -86
- package/lib/throttle.js +0 -16
- package/lib/urlJoin.js +0 -46
package/lib/collection.js
DELETED
|
@@ -1,65 +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
|
-
exports.setIntersect = setIntersect;
|
|
11
|
-
exports.setUnion = setUnion;
|
|
12
|
-
|
|
13
|
-
function unique(array) {
|
|
14
|
-
return [...new Set(array)];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function objectSortedEntries(obj) {
|
|
18
|
-
return Object.entries(obj).sort(([keyA], [keyB]) => keyA.localeCompare(keyB));
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function objectSortedEntriesDeep(object) {
|
|
22
|
-
let sortedEntries = objectSortedEntries(object);
|
|
23
|
-
|
|
24
|
-
for (let i = 0; i < sortedEntries.length; i++) {
|
|
25
|
-
sortedEntries[i][1] = sortEntry(sortedEntries[i][1]);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return sortedEntries;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function sortEntry(entry) {
|
|
32
|
-
if (Array.isArray(entry)) {
|
|
33
|
-
return entry.map(sortEntry);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (typeof entry === 'object' && entry != null) {
|
|
37
|
-
return objectSortedEntriesDeep(entry);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return entry;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function setDifference(a, b) {
|
|
44
|
-
let difference = new Set();
|
|
45
|
-
|
|
46
|
-
for (let e of a) {
|
|
47
|
-
if (!b.has(e)) {
|
|
48
|
-
difference.add(e);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return difference;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function setIntersect(a, b) {
|
|
56
|
-
for (let entry of a) {
|
|
57
|
-
if (!b.has(entry)) {
|
|
58
|
-
a.delete(entry);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function setUnion(a, b) {
|
|
64
|
-
return new Set([...a, ...b]);
|
|
65
|
-
}
|
package/lib/config.js
DELETED
|
@@ -1,198 +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 _diagnostic() {
|
|
11
|
-
const data = _interopRequireDefault(require("@parcel/diagnostic"));
|
|
12
|
-
|
|
13
|
-
_diagnostic = function () {
|
|
14
|
-
return data;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
return data;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function _path() {
|
|
21
|
-
const data = _interopRequireDefault(require("path"));
|
|
22
|
-
|
|
23
|
-
_path = function () {
|
|
24
|
-
return data;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
return data;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function _clone() {
|
|
31
|
-
const data = _interopRequireDefault(require("clone"));
|
|
32
|
-
|
|
33
|
-
_clone = function () {
|
|
34
|
-
return data;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
return data;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function _json() {
|
|
41
|
-
const data = require("json5");
|
|
42
|
-
|
|
43
|
-
_json = function () {
|
|
44
|
-
return data;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
return data;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function _toml() {
|
|
51
|
-
const data = require("@iarna/toml");
|
|
52
|
-
|
|
53
|
-
_toml = function () {
|
|
54
|
-
return data;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
return data;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function _lruCache() {
|
|
61
|
-
const data = _interopRequireDefault(require("lru-cache"));
|
|
62
|
-
|
|
63
|
-
_lruCache = function () {
|
|
64
|
-
return data;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
return data;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
71
|
-
|
|
72
|
-
const configCache = new (_lruCache().default)({
|
|
73
|
-
max: 500
|
|
74
|
-
});
|
|
75
|
-
const resolveCache = new Map();
|
|
76
|
-
|
|
77
|
-
function resolveConfig(fs, filepath, filenames, projectRoot) {
|
|
78
|
-
// Cache the result of resolving config for this directory.
|
|
79
|
-
// This is automatically invalidated at the end of the current build.
|
|
80
|
-
let key = _path().default.dirname(filepath) + filenames.join(',');
|
|
81
|
-
let cached = resolveCache.get(key);
|
|
82
|
-
|
|
83
|
-
if (cached !== undefined) {
|
|
84
|
-
return Promise.resolve(cached);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
let resolved = fs.findAncestorFile(filenames, _path().default.dirname(filepath), projectRoot);
|
|
88
|
-
resolveCache.set(key, resolved);
|
|
89
|
-
return Promise.resolve(resolved);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function resolveConfigSync(fs, filepath, filenames, projectRoot) {
|
|
93
|
-
return fs.findAncestorFile(filenames, _path().default.dirname(filepath), projectRoot);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
async function loadConfig(fs, filepath, filenames, projectRoot, opts) {
|
|
97
|
-
var _opts$parse;
|
|
98
|
-
|
|
99
|
-
let parse = (_opts$parse = opts === null || opts === void 0 ? void 0 : opts.parse) !== null && _opts$parse !== void 0 ? _opts$parse : true;
|
|
100
|
-
let configFile = await resolveConfig(fs, filepath, filenames, projectRoot);
|
|
101
|
-
|
|
102
|
-
if (configFile) {
|
|
103
|
-
let cachedOutput = configCache.get(String(parse) + configFile);
|
|
104
|
-
|
|
105
|
-
if (cachedOutput) {
|
|
106
|
-
return cachedOutput;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
try {
|
|
110
|
-
let extname = _path().default.extname(configFile).slice(1);
|
|
111
|
-
|
|
112
|
-
if (extname === 'js') {
|
|
113
|
-
let output = {
|
|
114
|
-
// $FlowFixMe
|
|
115
|
-
config: (0, _clone().default)(require(configFile)),
|
|
116
|
-
files: [{
|
|
117
|
-
filePath: configFile
|
|
118
|
-
}]
|
|
119
|
-
};
|
|
120
|
-
configCache.set(configFile, output);
|
|
121
|
-
return output;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
let configContent = await fs.readFile(configFile, 'utf8');
|
|
125
|
-
let config;
|
|
126
|
-
|
|
127
|
-
if (parse === false) {
|
|
128
|
-
config = configContent;
|
|
129
|
-
} else {
|
|
130
|
-
var _opts$parser;
|
|
131
|
-
|
|
132
|
-
let parse = (_opts$parser = opts === null || opts === void 0 ? void 0 : opts.parser) !== null && _opts$parser !== void 0 ? _opts$parser : getParser(extname);
|
|
133
|
-
|
|
134
|
-
try {
|
|
135
|
-
config = parse(configContent);
|
|
136
|
-
} catch (e) {
|
|
137
|
-
if (extname !== '' && extname !== 'json') {
|
|
138
|
-
throw e;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
let pos = {
|
|
142
|
-
line: e.lineNumber,
|
|
143
|
-
column: e.columnNumber
|
|
144
|
-
};
|
|
145
|
-
throw new (_diagnostic().default)({
|
|
146
|
-
diagnostic: {
|
|
147
|
-
message: `Failed to parse ${_path().default.basename(configFile)}`,
|
|
148
|
-
origin: '@parcel/utils',
|
|
149
|
-
codeFrames: [{
|
|
150
|
-
language: 'json5',
|
|
151
|
-
filePath: configFile,
|
|
152
|
-
code: configContent,
|
|
153
|
-
codeHighlights: [{
|
|
154
|
-
start: pos,
|
|
155
|
-
end: pos,
|
|
156
|
-
message: e.message
|
|
157
|
-
}]
|
|
158
|
-
}]
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
let output = {
|
|
165
|
-
config,
|
|
166
|
-
files: [{
|
|
167
|
-
filePath: configFile
|
|
168
|
-
}]
|
|
169
|
-
};
|
|
170
|
-
configCache.set(String(parse) + configFile, output);
|
|
171
|
-
return output;
|
|
172
|
-
} catch (err) {
|
|
173
|
-
if (err.code === 'MODULE_NOT_FOUND' || err.code === 'ENOENT') {
|
|
174
|
-
return null;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
throw err;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
return null;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
loadConfig.clear = () => {
|
|
185
|
-
configCache.reset();
|
|
186
|
-
resolveCache.clear();
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
function getParser(extname) {
|
|
190
|
-
switch (extname) {
|
|
191
|
-
case 'toml':
|
|
192
|
-
return _toml().parse;
|
|
193
|
-
|
|
194
|
-
case 'json':
|
|
195
|
-
default:
|
|
196
|
-
return _json().parse;
|
|
197
|
-
}
|
|
198
|
-
}
|
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, startIndex = 0) {
|
|
9
|
-
let lines = 1;
|
|
10
|
-
|
|
11
|
-
for (let i = startIndex; 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, specifier, lineOffset = 0, columnOffset = 0, // 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
|
-
}
|
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,148 +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
|
-
var _ = require("./");
|
|
39
|
-
|
|
40
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
41
|
-
|
|
42
|
-
async function getSourcemapSizes(filePath, fs, projectRoot) {
|
|
43
|
-
let bundleContents = await fs.readFile(filePath, 'utf-8');
|
|
44
|
-
let mapUrlData = await (0, _.loadSourceMapUrl)(fs, filePath, bundleContents);
|
|
45
|
-
|
|
46
|
-
if (!mapUrlData) {
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
let rawMap = mapUrlData.map;
|
|
51
|
-
let sourceMap = new (_sourceMap().default)(projectRoot);
|
|
52
|
-
sourceMap.addVLQMap(rawMap);
|
|
53
|
-
let parsedMapData = sourceMap.getMap();
|
|
54
|
-
|
|
55
|
-
if (parsedMapData.mappings.length > 2) {
|
|
56
|
-
let sources = parsedMapData.sources.map(s => _path().default.normalize(_path().default.join(projectRoot, s)));
|
|
57
|
-
let currLine = 1;
|
|
58
|
-
let currColumn = 0;
|
|
59
|
-
let currMappingIndex = 0;
|
|
60
|
-
let currMapping = parsedMapData.mappings[currMappingIndex];
|
|
61
|
-
let nextMapping = parsedMapData.mappings[currMappingIndex + 1];
|
|
62
|
-
let sourceSizes = new Array(sources.length).fill(0);
|
|
63
|
-
let unknownOrigin = 0;
|
|
64
|
-
|
|
65
|
-
for (let i = 0; i < bundleContents.length; i++) {
|
|
66
|
-
let character = bundleContents[i];
|
|
67
|
-
|
|
68
|
-
while (nextMapping && nextMapping.generated.line === currLine && nextMapping.generated.column <= currColumn) {
|
|
69
|
-
currMappingIndex++;
|
|
70
|
-
currMapping = parsedMapData.mappings[currMappingIndex];
|
|
71
|
-
nextMapping = parsedMapData.mappings[currMappingIndex + 1];
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
let currentSource = currMapping.source;
|
|
75
|
-
let charSize = Buffer.byteLength(character, 'utf8');
|
|
76
|
-
|
|
77
|
-
if (currentSource != null && currMapping.generated.line === currLine && currMapping.generated.column <= currColumn) {
|
|
78
|
-
sourceSizes[currentSource] += charSize;
|
|
79
|
-
} else {
|
|
80
|
-
unknownOrigin += charSize;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (character === '\n') {
|
|
84
|
-
currColumn = 0;
|
|
85
|
-
currLine++;
|
|
86
|
-
} else {
|
|
87
|
-
currColumn++;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
let sizeMap = new Map();
|
|
92
|
-
|
|
93
|
-
for (let i = 0; i < sourceSizes.length; i++) {
|
|
94
|
-
sizeMap.set(sources[i], sourceSizes[i]);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
sizeMap.set('', unknownOrigin);
|
|
98
|
-
return sizeMap;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
async function createBundleStats(bundle, fs, projectRoot) {
|
|
103
|
-
let filePath = bundle.filePath;
|
|
104
|
-
let sourcemapSizes = await getSourcemapSizes(filePath, fs, projectRoot);
|
|
105
|
-
let assets = new Map();
|
|
106
|
-
bundle.traverseAssets(asset => {
|
|
107
|
-
let filePath = _path().default.normalize(asset.filePath);
|
|
108
|
-
|
|
109
|
-
assets.set(filePath, {
|
|
110
|
-
filePath,
|
|
111
|
-
size: asset.stats.size,
|
|
112
|
-
originalSize: asset.stats.size,
|
|
113
|
-
time: asset.stats.time
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
let assetsReport = [];
|
|
117
|
-
|
|
118
|
-
if (sourcemapSizes && sourcemapSizes.size) {
|
|
119
|
-
assetsReport = Array.from(sourcemapSizes.keys()).map(filePath => {
|
|
120
|
-
let foundSize = sourcemapSizes.get(filePath) || 0;
|
|
121
|
-
let stats = assets.get(filePath) || {
|
|
122
|
-
filePath,
|
|
123
|
-
size: foundSize,
|
|
124
|
-
originalSize: foundSize,
|
|
125
|
-
time: 0
|
|
126
|
-
};
|
|
127
|
-
return { ...stats,
|
|
128
|
-
size: foundSize
|
|
129
|
-
};
|
|
130
|
-
});
|
|
131
|
-
} else {
|
|
132
|
-
assetsReport = Array.from(assets.values());
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return {
|
|
136
|
-
filePath: (0, _nullthrows().default)(bundle.filePath),
|
|
137
|
-
size: bundle.stats.size,
|
|
138
|
-
time: bundle.stats.time,
|
|
139
|
-
assets: assetsReport.sort((a, b) => b.size - a.size)
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
async function generateBuildMetrics(bundles, fs, projectRoot) {
|
|
144
|
-
bundles.sort((a, b) => b.stats.size - a.stats.size).filter(b => !!b.filePath);
|
|
145
|
-
return {
|
|
146
|
-
bundles: (await Promise.all(bundles.map(b => createBundleStats(b, fs, projectRoot)))).filter(e => !!e)
|
|
147
|
-
};
|
|
148
|
-
}
|
|
@@ -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
|
-
}
|
package/lib/getExisting.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = getExisting;
|
|
7
|
-
|
|
8
|
-
function _fs() {
|
|
9
|
-
const data = _interopRequireDefault(require("fs"));
|
|
10
|
-
|
|
11
|
-
_fs = function () {
|
|
12
|
-
return data;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Creates an object that contains both source and minified (using the source as a fallback).
|
|
22
|
-
* e.g. builtins.min.js and builtins.js.
|
|
23
|
-
*/
|
|
24
|
-
function getExisting(minifiedPath, sourcePath) {
|
|
25
|
-
let source = _fs().default.readFileSync(sourcePath, 'utf8').trim();
|
|
26
|
-
|
|
27
|
-
return {
|
|
28
|
-
source,
|
|
29
|
-
minified: _fs().default.existsSync(minifiedPath) ? _fs().default.readFileSync(minifiedPath, 'utf8').trim().replace(/;$/, '') : source
|
|
30
|
-
};
|
|
31
|
-
}
|