@parcel/utils 2.0.0-nightly.150 → 2.0.0-nightly.1501
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/.eslintrc.js +6 -6
- package/lib/index.js +37626 -318
- package/lib/index.js.map +1 -0
- package/package.json +47 -20
- package/src/DefaultMap.js +1 -1
- package/src/PromiseQueue.js +16 -12
- package/src/alternatives.js +145 -0
- package/src/ansi-html.js +2 -2
- package/src/blob.js +2 -1
- package/src/bundle-url.js +1 -1
- package/src/collection.js +35 -15
- package/src/config.js +132 -45
- package/src/countLines.js +5 -2
- package/src/debounce.js +1 -1
- package/src/dependency-location.js +11 -6
- package/src/generateBuildMetrics.js +158 -0
- package/src/generateCertificate.js +1 -1
- package/src/getCertificate.js +1 -1
- package/src/getExisting.js +1 -4
- package/src/getModuleParts.js +23 -0
- package/src/getRootDir.js +1 -2
- package/src/glob.js +51 -10
- package/src/hash.js +49 -0
- package/src/http-server.js +29 -19
- package/src/index.js +68 -22
- package/src/is-url.js +1 -1
- package/src/isDirectoryInside.js +11 -0
- package/src/openInBrowser.js +64 -0
- package/src/path.js +38 -6
- package/src/prettyDiagnostic.js +102 -30
- package/src/progress-message.js +22 -0
- package/src/relativeBundlePath.js +8 -13
- package/src/replaceBundleReferences.js +85 -41
- package/src/schema.js +100 -44
- package/src/shared-buffer.js +23 -0
- package/src/sourcemap.js +138 -0
- package/src/stream.js +31 -1
- package/src/urlJoin.js +3 -1
- package/test/DefaultMap.test.js +7 -4
- package/test/collection.test.js +13 -1
- package/test/config.test.js +98 -0
- package/test/input/config/.testrc +3 -0
- package/test/input/config/config.cjs +3 -0
- package/test/input/config/config.js +3 -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/input/sourcemap/referenced-min.js +2 -0
- package/test/input/sourcemap/referenced-min.js.map +6 -0
- package/test/input/sourcemap/source-root.js +2 -0
- package/test/input/sourcemap/source-root.js.map +7 -0
- package/test/replaceBundleReferences.test.js +268 -0
- package/test/sourcemap.test.js +207 -0
- package/test/throttle.test.js +1 -2
- package/test/urlJoin.test.js +37 -0
- package/lib/DefaultMap.js +0 -64
- package/lib/Deferred.js +0 -26
- package/lib/PromiseQueue.js +0 -133
- package/lib/TapStream.js +0 -41
- package/lib/ansi-html.js +0 -16
- package/lib/blob.js +0 -31
- package/lib/bundle-url.js +0 -43
- package/lib/collection.js +0 -62
- package/lib/config.js +0 -88
- 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/escape-markdown.js +0 -15
- package/lib/generateBundleReport.js +0 -38
- package/lib/generateCertificate.js +0 -124
- package/lib/getCertificate.js +0 -19
- package/lib/getExisting.js +0 -23
- package/lib/getRootDir.js +0 -55
- package/lib/glob.js +0 -76
- package/lib/http-server.js +0 -64
- package/lib/is-url.js +0 -17
- package/lib/loadSourceMapUrl.js +0 -33
- package/lib/md5.js +0 -35
- package/lib/objectHash.js +0 -26
- package/lib/parseCSSImport.js +0 -16
- package/lib/path.js +0 -22
- package/lib/prettifyTime.js +0 -10
- package/lib/prettyDiagnostic.js +0 -57
- package/lib/promisify.js +0 -13
- package/lib/relativeBundlePath.js +0 -24
- package/lib/relativeUrl.js +0 -16
- package/lib/replaceBundleReferences.js +0 -151
- package/lib/resolve.js +0 -93
- package/lib/schema.js +0 -320
- package/lib/serializeObject.js +0 -28
- package/lib/stream.js +0 -51
- package/lib/throttle.js +0 -16
- package/lib/urlJoin.js +0 -27
- package/src/.babelrc +0 -3
- package/src/escape-markdown.js +0 -10
- package/src/generateBundleReport.js +0 -51
- package/src/loadSourceMapUrl.js +0 -33
- package/src/md5.js +0 -44
- package/src/promisify.js +0 -13
- package/src/resolve.js +0 -135
- package/src/serializeObject.js +0 -22
- package/test/escapeMarkdown.test.js +0 -29
- package/test/input/sourcemap/referenced.js +0 -7
- package/test/loadSourceMapUrl.test.js +0 -37
package/lib/resolve.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.resolve = resolve;
|
|
7
|
-
exports.resolveSync = resolveSync;
|
|
8
|
-
|
|
9
|
-
var _promisify = _interopRequireDefault(require("./promisify"));
|
|
10
|
-
|
|
11
|
-
var _resolve2 = _interopRequireDefault(require("resolve"));
|
|
12
|
-
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
|
|
15
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
16
|
-
|
|
17
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
18
|
-
|
|
19
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
20
|
-
|
|
21
|
-
const resolveAsync = (0, _promisify.default)(_resolve2.default);
|
|
22
|
-
|
|
23
|
-
async function resolve(fs, id, opts) {
|
|
24
|
-
let res = await resolveAsync(id, _objectSpread({}, opts, {
|
|
25
|
-
async readFile(filename, callback) {
|
|
26
|
-
try {
|
|
27
|
-
let res = await fs.readFile(filename);
|
|
28
|
-
callback(null, res);
|
|
29
|
-
} catch (err) {
|
|
30
|
-
callback(err);
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
async isFile(file, callback) {
|
|
35
|
-
try {
|
|
36
|
-
let stat = await fs.stat(file);
|
|
37
|
-
callback(null, stat.isFile());
|
|
38
|
-
} catch (err) {
|
|
39
|
-
callback(null, false);
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
|
|
43
|
-
async isDirectory(file, callback) {
|
|
44
|
-
try {
|
|
45
|
-
let stat = await fs.stat(file);
|
|
46
|
-
callback(null, stat.isDirectory());
|
|
47
|
-
} catch (err) {
|
|
48
|
-
callback(null, false);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
}));
|
|
53
|
-
|
|
54
|
-
if (typeof res === 'string') {
|
|
55
|
-
return {
|
|
56
|
-
resolved: res
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return {
|
|
61
|
-
resolved: res[0],
|
|
62
|
-
pkg: res[1]
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function resolveSync(fs, id, opts) {
|
|
67
|
-
// $FlowFixMe
|
|
68
|
-
let res = _resolve2.default.sync(id, _objectSpread({}, opts, {
|
|
69
|
-
readFileSync: (...args) => {
|
|
70
|
-
return fs.readFileSync(...args);
|
|
71
|
-
},
|
|
72
|
-
isFile: file => {
|
|
73
|
-
try {
|
|
74
|
-
let stat = fs.statSync(file);
|
|
75
|
-
return stat.isFile();
|
|
76
|
-
} catch (err) {
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
isDirectory: file => {
|
|
81
|
-
try {
|
|
82
|
-
let stat = fs.statSync(file);
|
|
83
|
-
return stat.isDirectory();
|
|
84
|
-
} catch (err) {
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}));
|
|
89
|
-
|
|
90
|
-
return {
|
|
91
|
-
resolved: res
|
|
92
|
-
};
|
|
93
|
-
}
|
package/lib/schema.js
DELETED
|
@@ -1,320 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _diagnostic = _interopRequireWildcard(require("@parcel/diagnostic"));
|
|
9
|
-
|
|
10
|
-
var _jsLevenshtein = _interopRequireDefault(require("js-levenshtein"));
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
15
|
-
|
|
16
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
17
|
-
|
|
18
|
-
// $FlowFixMe untyped
|
|
19
|
-
function validateSchema(schema, data) {
|
|
20
|
-
function walk(schemaAncestors, dataNode, dataPath) {
|
|
21
|
-
let [schemaNode] = schemaAncestors;
|
|
22
|
-
|
|
23
|
-
if (schemaNode.type) {
|
|
24
|
-
let type = Array.isArray(dataNode) ? 'array' : typeof dataNode;
|
|
25
|
-
|
|
26
|
-
if (schemaNode.type !== type) {
|
|
27
|
-
return {
|
|
28
|
-
type: 'type',
|
|
29
|
-
dataType: 'value',
|
|
30
|
-
dataPath,
|
|
31
|
-
expectedTypes: [schemaNode.type],
|
|
32
|
-
ancestors: schemaAncestors,
|
|
33
|
-
prettyType: schemaNode.__type
|
|
34
|
-
};
|
|
35
|
-
} else {
|
|
36
|
-
switch (schemaNode.type) {
|
|
37
|
-
case 'array':
|
|
38
|
-
{
|
|
39
|
-
if (schemaNode.items) {
|
|
40
|
-
let results = []; // $FlowFixMe type was already checked
|
|
41
|
-
|
|
42
|
-
for (let i = 0; i < dataNode.length; i++) {
|
|
43
|
-
let result = walk([schemaNode.items].concat(schemaAncestors), // $FlowFixMe type was already checked
|
|
44
|
-
dataNode[i], dataPath + '/' + i);
|
|
45
|
-
if (result) results.push(result);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (results.length) return results.reduce((acc, v) => acc.concat(v), []);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
case 'string':
|
|
55
|
-
{
|
|
56
|
-
// $FlowFixMe type was already checked
|
|
57
|
-
let value = dataNode;
|
|
58
|
-
|
|
59
|
-
if (schemaNode.enum) {
|
|
60
|
-
if (!schemaNode.enum.includes(value)) {
|
|
61
|
-
return {
|
|
62
|
-
type: 'enum',
|
|
63
|
-
dataType: 'value',
|
|
64
|
-
dataPath,
|
|
65
|
-
expectedValues: schemaNode.enum,
|
|
66
|
-
actualValue: value,
|
|
67
|
-
ancestors: schemaAncestors
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
} else if (schemaNode.__validate) {
|
|
71
|
-
let validationError = schemaNode.__validate(value); // $FlowFixMe
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if (validationError) {
|
|
75
|
-
return {
|
|
76
|
-
type: 'other',
|
|
77
|
-
dataType: 'value',
|
|
78
|
-
dataPath,
|
|
79
|
-
message: validationError,
|
|
80
|
-
actualValue: value,
|
|
81
|
-
ancestors: schemaAncestors
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
case 'object':
|
|
90
|
-
{
|
|
91
|
-
let results = [];
|
|
92
|
-
let invalidProps;
|
|
93
|
-
|
|
94
|
-
if (schemaNode.__forbiddenProperties) {
|
|
95
|
-
// $FlowFixMe type was already checked
|
|
96
|
-
let keys = Object.keys(dataNode);
|
|
97
|
-
invalidProps = schemaNode.__forbiddenProperties.filter(val => keys.includes(val));
|
|
98
|
-
results.push(...invalidProps.map(k => ({
|
|
99
|
-
type: 'forbidden-prop',
|
|
100
|
-
dataPath: dataPath + '/' + k,
|
|
101
|
-
dataType: 'key',
|
|
102
|
-
prop: k,
|
|
103
|
-
expectedProps: Object.keys(schemaNode.properties),
|
|
104
|
-
actualProps: keys,
|
|
105
|
-
ancestors: schemaAncestors
|
|
106
|
-
})));
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (schemaNode.required) {
|
|
110
|
-
// $FlowFixMe type was already checked
|
|
111
|
-
let keys = Object.keys(dataNode);
|
|
112
|
-
let missingKeys = schemaNode.required.filter(val => !keys.includes(val));
|
|
113
|
-
results.push(...missingKeys.map(k => ({
|
|
114
|
-
type: 'missing-prop',
|
|
115
|
-
dataPath,
|
|
116
|
-
dataType: null,
|
|
117
|
-
prop: k,
|
|
118
|
-
expectedProps: schemaNode.required,
|
|
119
|
-
actualProps: keys,
|
|
120
|
-
ancestors: schemaAncestors
|
|
121
|
-
})));
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (schemaNode.properties) {
|
|
125
|
-
let {
|
|
126
|
-
additionalProperties = true
|
|
127
|
-
} = schemaNode; // $FlowFixMe type was already checked
|
|
128
|
-
|
|
129
|
-
for (let k in dataNode) {
|
|
130
|
-
if (invalidProps && invalidProps.includes(k)) {
|
|
131
|
-
// Don't check type on forbidden props
|
|
132
|
-
continue;
|
|
133
|
-
} else if (k in schemaNode.properties) {
|
|
134
|
-
let result = walk([schemaNode.properties[k]].concat(schemaAncestors), // $FlowFixMe type was already checked
|
|
135
|
-
dataNode[k], dataPath + '/' + k);
|
|
136
|
-
if (result) results.push(result);
|
|
137
|
-
} else {
|
|
138
|
-
if (typeof additionalProperties === 'boolean') {
|
|
139
|
-
if (!additionalProperties) {
|
|
140
|
-
results.push({
|
|
141
|
-
type: 'enum',
|
|
142
|
-
dataType: 'key',
|
|
143
|
-
dataPath: dataPath + '/' + k,
|
|
144
|
-
expectedValues: Object.keys(schemaNode.properties).filter( // $FlowFixMe type was already checked
|
|
145
|
-
p => !(p in dataNode)),
|
|
146
|
-
actualValue: k,
|
|
147
|
-
ancestors: schemaAncestors,
|
|
148
|
-
prettyType: schemaNode.__type
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
} else {
|
|
152
|
-
let result = walk([additionalProperties].concat(schemaAncestors), // $FlowFixMe type was already checked
|
|
153
|
-
dataNode[k], dataPath + '/' + k);
|
|
154
|
-
if (result) results.push(result);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
if (results.length) return results.reduce((acc, v) => acc.concat(v), []);
|
|
161
|
-
break;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
case 'boolean':
|
|
165
|
-
// NOOP, type was checked already
|
|
166
|
-
break;
|
|
167
|
-
|
|
168
|
-
default:
|
|
169
|
-
throw new Error(`Unimplemented schema type ${type}?`);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
} else {
|
|
173
|
-
if (schemaNode.enum && !schemaNode.enum.includes(dataNode)) {
|
|
174
|
-
return {
|
|
175
|
-
type: 'enum',
|
|
176
|
-
dataType: 'value',
|
|
177
|
-
dataPath: dataPath,
|
|
178
|
-
expectedValues: schemaNode.enum,
|
|
179
|
-
actualValue: schemaNode,
|
|
180
|
-
ancestors: schemaAncestors
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
if (schemaNode.oneOf || schemaNode.allOf) {
|
|
185
|
-
let list = schemaNode.oneOf || schemaNode.allOf;
|
|
186
|
-
let results = [];
|
|
187
|
-
|
|
188
|
-
for (let f of list) {
|
|
189
|
-
let result = walk([f].concat(schemaAncestors), dataNode, dataPath);
|
|
190
|
-
if (result) results.push(result);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if (schemaNode.oneOf ? results.length == schemaNode.oneOf.length : results.length > 0) {
|
|
194
|
-
// return the result with more values / longer key
|
|
195
|
-
results.sort((a, b) => Array.isArray(a) || Array.isArray(b) ? Array.isArray(a) && !Array.isArray(b) ? -1 : !Array.isArray(a) && Array.isArray(b) ? 1 : Array.isArray(a) && Array.isArray(b) ? b.length - a.length : 0 : b.dataPath.length - a.dataPath.length);
|
|
196
|
-
return results[0];
|
|
197
|
-
}
|
|
198
|
-
} else if (schemaNode.not) {
|
|
199
|
-
let result = walk([schemaNode.not].concat(schemaAncestors), dataNode, dataPath);
|
|
200
|
-
|
|
201
|
-
if (!result || result.length == 0) {
|
|
202
|
-
return {
|
|
203
|
-
type: 'other',
|
|
204
|
-
dataPath,
|
|
205
|
-
dataType: null,
|
|
206
|
-
message: schemaNode.__message,
|
|
207
|
-
actualValue: dataNode,
|
|
208
|
-
ancestors: schemaAncestors
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
return undefined;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
let result = walk([schema], data, '');
|
|
218
|
-
return Array.isArray(result) ? result : result ? [result] : [];
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
var _default = validateSchema;
|
|
222
|
-
exports.default = _default;
|
|
223
|
-
|
|
224
|
-
function fuzzySearch(expectedValues, actualValue) {
|
|
225
|
-
let result = expectedValues.map(exp => [exp, (0, _jsLevenshtein.default)(exp, actualValue)]).filter( // Remove if more than half of the string would need to be changed
|
|
226
|
-
([, d]) => d * 2 < actualValue.length);
|
|
227
|
-
result.sort(([, a], [, b]) => a - b);
|
|
228
|
-
return result.map(([v]) => v);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
validateSchema.diagnostic = function (schema, data, dataContentsPath, dataContents, origin, prependKey, message) {
|
|
232
|
-
let errors = validateSchema(schema, data);
|
|
233
|
-
|
|
234
|
-
if (errors.length) {
|
|
235
|
-
let dataContentsString = typeof dataContents === 'string' ? dataContents : // $FlowFixMe
|
|
236
|
-
JSON.stringify(dataContents, null, '\t');
|
|
237
|
-
let keys = errors.map(e => {
|
|
238
|
-
let message;
|
|
239
|
-
|
|
240
|
-
if (e.type === 'enum') {
|
|
241
|
-
let {
|
|
242
|
-
actualValue
|
|
243
|
-
} = e;
|
|
244
|
-
let expectedValues = e.expectedValues.map(String);
|
|
245
|
-
let likely = actualValue != null ? fuzzySearch(expectedValues, String(actualValue)) : [];
|
|
246
|
-
|
|
247
|
-
if (likely.length > 0) {
|
|
248
|
-
message = `Did you mean ${likely.map(v => JSON.stringify(v)).join(', ')}?`;
|
|
249
|
-
} else if (expectedValues.length > 0) {
|
|
250
|
-
message = `Possible values: ${expectedValues.map(v => JSON.stringify(v)).join(', ')}`;
|
|
251
|
-
} else {
|
|
252
|
-
message = 'Unexpected value';
|
|
253
|
-
}
|
|
254
|
-
} else if (e.type === 'forbidden-prop') {
|
|
255
|
-
let {
|
|
256
|
-
prop,
|
|
257
|
-
expectedProps,
|
|
258
|
-
actualProps
|
|
259
|
-
} = e;
|
|
260
|
-
let likely = fuzzySearch(expectedProps, prop).filter(v => !actualProps.includes(v));
|
|
261
|
-
|
|
262
|
-
if (likely.length > 0) {
|
|
263
|
-
message = `Did you mean ${likely.map(v => JSON.stringify(v)).join(', ')}?`;
|
|
264
|
-
} else {
|
|
265
|
-
message = 'Unexpected property';
|
|
266
|
-
}
|
|
267
|
-
} else if (e.type === 'missing-prop') {
|
|
268
|
-
let {
|
|
269
|
-
prop,
|
|
270
|
-
actualProps
|
|
271
|
-
} = e;
|
|
272
|
-
let likely = fuzzySearch(actualProps, prop);
|
|
273
|
-
|
|
274
|
-
if (likely.length > 0) {
|
|
275
|
-
message = `Did you mean ${likely.map(v => JSON.stringify(v)).join(', ')}?`;
|
|
276
|
-
e.dataPath += '/' + prop;
|
|
277
|
-
e.dataType = 'key';
|
|
278
|
-
} else {
|
|
279
|
-
message = `Missing property ${prop}`;
|
|
280
|
-
}
|
|
281
|
-
} else if (e.type === 'type') {
|
|
282
|
-
if (e.prettyType != null) {
|
|
283
|
-
message = `Expected ${e.prettyType}`;
|
|
284
|
-
} else {
|
|
285
|
-
message = `Expected type ${e.expectedTypes.join(', ')}`;
|
|
286
|
-
}
|
|
287
|
-
} else {
|
|
288
|
-
message = e.message;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
return {
|
|
292
|
-
key: e.dataPath,
|
|
293
|
-
type: e.dataType,
|
|
294
|
-
message
|
|
295
|
-
};
|
|
296
|
-
});
|
|
297
|
-
let codeFrame = {
|
|
298
|
-
code: dataContentsString,
|
|
299
|
-
codeHighlights: (0, _diagnostic.generateJSONCodeHighlights)(dataContentsString, keys.map(({
|
|
300
|
-
key,
|
|
301
|
-
type,
|
|
302
|
-
message
|
|
303
|
-
}) => ({
|
|
304
|
-
key: prependKey + key,
|
|
305
|
-
type: type,
|
|
306
|
-
message
|
|
307
|
-
})))
|
|
308
|
-
};
|
|
309
|
-
throw new _diagnostic.default({
|
|
310
|
-
diagnostic: {
|
|
311
|
-
message,
|
|
312
|
-
origin,
|
|
313
|
-
// $FlowFixMe should be a sketchy string check
|
|
314
|
-
filePath: dataContentsPath || undefined,
|
|
315
|
-
language: 'json',
|
|
316
|
-
codeFrame
|
|
317
|
-
}
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
};
|
package/lib/serializeObject.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = serializeObject;
|
|
7
|
-
|
|
8
|
-
var _terser = require("terser");
|
|
9
|
-
|
|
10
|
-
var _serializeToJs = _interopRequireDefault(require("serialize-to-js"));
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
function serializeObject(obj, shouldMinify = false) {
|
|
15
|
-
let code = `module.exports = ${(0, _serializeToJs.default)(obj)};`;
|
|
16
|
-
|
|
17
|
-
if (shouldMinify) {
|
|
18
|
-
let minified = (0, _terser.minify)(code);
|
|
19
|
-
|
|
20
|
-
if (minified.error) {
|
|
21
|
-
throw minified.error;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
code = minified.code;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return code;
|
|
28
|
-
}
|
package/lib/stream.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.measureStreamLength = measureStreamLength;
|
|
7
|
-
exports.readableFromStringOrBuffer = readableFromStringOrBuffer;
|
|
8
|
-
exports.bufferStream = bufferStream;
|
|
9
|
-
exports.blobToStream = blobToStream;
|
|
10
|
-
|
|
11
|
-
var _stream = require("stream");
|
|
12
|
-
|
|
13
|
-
function measureStreamLength(stream) {
|
|
14
|
-
return new Promise((resolve, reject) => {
|
|
15
|
-
let length = 0;
|
|
16
|
-
stream.on('data', chunk => {
|
|
17
|
-
length += chunk;
|
|
18
|
-
});
|
|
19
|
-
stream.on('end', () => resolve(length));
|
|
20
|
-
stream.on('error', reject);
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function readableFromStringOrBuffer(str) {
|
|
25
|
-
// https://stackoverflow.com/questions/12755997/how-to-create-streams-from-string-in-node-js
|
|
26
|
-
const stream = new _stream.Readable();
|
|
27
|
-
stream.push(str);
|
|
28
|
-
stream.push(null);
|
|
29
|
-
return stream;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function bufferStream(stream) {
|
|
33
|
-
return new Promise((resolve, reject) => {
|
|
34
|
-
let buf = Buffer.from([]);
|
|
35
|
-
stream.on('data', data => {
|
|
36
|
-
buf = Buffer.concat([buf, data]);
|
|
37
|
-
});
|
|
38
|
-
stream.on('end', () => {
|
|
39
|
-
resolve(buf);
|
|
40
|
-
});
|
|
41
|
-
stream.on('error', reject);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function blobToStream(blob) {
|
|
46
|
-
if (blob instanceof _stream.Readable) {
|
|
47
|
-
return blob;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return readableFromStringOrBuffer(blob);
|
|
51
|
-
}
|
package/lib/throttle.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = throttle;
|
|
7
|
-
|
|
8
|
-
function throttle(fn, delay) {
|
|
9
|
-
let lastCalled;
|
|
10
|
-
return function (...args) {
|
|
11
|
-
if (lastCalled == null || lastCalled + delay <= Date.now()) {
|
|
12
|
-
fn.call(this, ...args);
|
|
13
|
-
lastCalled = Date.now();
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
}
|
package/lib/urlJoin.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = urlJoin;
|
|
7
|
-
|
|
8
|
-
var _url = _interopRequireDefault(require("url"));
|
|
9
|
-
|
|
10
|
-
var _path = _interopRequireDefault(require("path"));
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Joins a path onto a URL, and normalizes Windows paths
|
|
16
|
-
* e.g. from \path\to\res.js to /path/to/res.js.
|
|
17
|
-
*/
|
|
18
|
-
function urlJoin(publicURL, assetPath) {
|
|
19
|
-
const url = _url.default.parse(publicURL, false, true);
|
|
20
|
-
|
|
21
|
-
const assetUrl = _url.default.parse(assetPath);
|
|
22
|
-
|
|
23
|
-
url.pathname = _path.default.posix.join(url.pathname, assetUrl.pathname);
|
|
24
|
-
url.search = assetUrl.search;
|
|
25
|
-
url.hash = assetUrl.hash;
|
|
26
|
-
return _url.default.format(url);
|
|
27
|
-
}
|
package/src/.babelrc
DELETED
package/src/escape-markdown.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
|
-
|
|
3
|
-
import type {Asset, BundleGraph} from '@parcel/types';
|
|
4
|
-
import nullthrows from 'nullthrows';
|
|
5
|
-
|
|
6
|
-
export type BundleReport = {|
|
|
7
|
-
bundles: Array<{|
|
|
8
|
-
filePath: string,
|
|
9
|
-
size: number,
|
|
10
|
-
time: number,
|
|
11
|
-
largestAssets: Array<{|
|
|
12
|
-
filePath: string,
|
|
13
|
-
size: number,
|
|
14
|
-
time: number,
|
|
15
|
-
|}>,
|
|
16
|
-
totalAssets: number,
|
|
17
|
-
|}>,
|
|
18
|
-
|};
|
|
19
|
-
|
|
20
|
-
export default function generateBundleReport(
|
|
21
|
-
bundleGraph: BundleGraph,
|
|
22
|
-
largestAssetCount: number = 10,
|
|
23
|
-
): BundleReport {
|
|
24
|
-
let bundles = [];
|
|
25
|
-
bundleGraph.traverseBundles(bundle => {
|
|
26
|
-
bundles.push(bundle);
|
|
27
|
-
});
|
|
28
|
-
bundles.sort((a, b) => b.stats.size - a.stats.size);
|
|
29
|
-
|
|
30
|
-
return {
|
|
31
|
-
bundles: bundles.map(bundle => {
|
|
32
|
-
let assets: Array<Asset> = [];
|
|
33
|
-
bundle.traverseAssets(asset => {
|
|
34
|
-
assets.push(asset);
|
|
35
|
-
});
|
|
36
|
-
assets.sort((a, b) => b.stats.size - a.stats.size);
|
|
37
|
-
|
|
38
|
-
return {
|
|
39
|
-
filePath: nullthrows(bundle.filePath),
|
|
40
|
-
size: bundle.stats.size,
|
|
41
|
-
time: bundle.stats.time,
|
|
42
|
-
largestAssets: assets.slice(0, largestAssetCount).map(asset => ({
|
|
43
|
-
filePath: asset.filePath,
|
|
44
|
-
size: asset.stats.size,
|
|
45
|
-
time: asset.stats.time,
|
|
46
|
-
})),
|
|
47
|
-
totalAssets: assets.length,
|
|
48
|
-
};
|
|
49
|
-
}),
|
|
50
|
-
};
|
|
51
|
-
}
|
package/src/loadSourceMapUrl.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import type {FileSystem} from '@parcel/fs';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
|
|
5
|
-
const SOURCEMAP_RE = /(?:\/\*|\/\/)\s*[@#]\s*sourceMappingURL\s*=\s*([^\s*]+)(?:\s*\*\/)?\s*$/;
|
|
6
|
-
const DATA_URL_RE = /^data:[^;]+(?:;charset=[^;]+)?;base64,(.*)/;
|
|
7
|
-
|
|
8
|
-
export function matchSourceMappingURL(contents: string) {
|
|
9
|
-
return contents.match(SOURCEMAP_RE);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export default async function loadSourceMapUrl(
|
|
13
|
-
fs: FileSystem,
|
|
14
|
-
filename: string,
|
|
15
|
-
contents: string,
|
|
16
|
-
) {
|
|
17
|
-
let match = matchSourceMappingURL(contents);
|
|
18
|
-
if (match) {
|
|
19
|
-
let url = match[1].trim();
|
|
20
|
-
let dataURLMatch = url.match(DATA_URL_RE);
|
|
21
|
-
filename = dataURLMatch ? filename : path.join(path.dirname(filename), url);
|
|
22
|
-
|
|
23
|
-
return {
|
|
24
|
-
url,
|
|
25
|
-
filename,
|
|
26
|
-
map: JSON.parse(
|
|
27
|
-
dataURLMatch
|
|
28
|
-
? Buffer.from(dataURLMatch[1], 'base64').toString()
|
|
29
|
-
: await fs.readFile(filename, 'utf8'),
|
|
30
|
-
),
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
}
|
package/src/md5.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
|
-
|
|
3
|
-
import type {Readable} from 'stream';
|
|
4
|
-
import type {FileSystem} from '@parcel/fs';
|
|
5
|
-
|
|
6
|
-
import crypto from 'crypto';
|
|
7
|
-
import {objectSortedEntriesDeep} from './collection';
|
|
8
|
-
|
|
9
|
-
type StringHashEncoding = 'hex' | 'latin1' | 'binary' | 'base64';
|
|
10
|
-
|
|
11
|
-
export function md5FromString(
|
|
12
|
-
string: string | Buffer,
|
|
13
|
-
encoding: StringHashEncoding = 'hex',
|
|
14
|
-
): string {
|
|
15
|
-
return crypto
|
|
16
|
-
.createHash('md5')
|
|
17
|
-
.update(string)
|
|
18
|
-
.digest(encoding);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function md5FromReadableStream(stream: Readable): Promise<string> {
|
|
22
|
-
return new Promise((resolve, reject) => {
|
|
23
|
-
stream
|
|
24
|
-
.pipe(crypto.createHash('md5').setEncoding('hex'))
|
|
25
|
-
.on('finish', function() {
|
|
26
|
-
resolve(this.read());
|
|
27
|
-
})
|
|
28
|
-
.on('error', reject);
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function md5FromObject(
|
|
33
|
-
obj: {+[string]: mixed, ...},
|
|
34
|
-
encoding: StringHashEncoding = 'hex',
|
|
35
|
-
): string {
|
|
36
|
-
return md5FromString(JSON.stringify(objectSortedEntriesDeep(obj)), encoding);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function md5FromFilePath(
|
|
40
|
-
fs: FileSystem,
|
|
41
|
-
filePath: string,
|
|
42
|
-
): Promise<string> {
|
|
43
|
-
return md5FromReadableStream(fs.createReadStream(filePath));
|
|
44
|
-
}
|
package/src/promisify.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
module.exports = function(fn) {
|
|
2
|
-
return function(...args) {
|
|
3
|
-
return new Promise(function(resolve, reject) {
|
|
4
|
-
fn(...args, function(err, ...res) {
|
|
5
|
-
if (err) return reject(err);
|
|
6
|
-
|
|
7
|
-
if (res.length === 1) return resolve(res[0]);
|
|
8
|
-
|
|
9
|
-
resolve(res);
|
|
10
|
-
});
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
};
|