@atlaspack/utils 2.14.5-canary.35 → 2.14.5-canary.351
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +446 -0
- package/benchmark.js +23 -0
- package/dist/DefaultMap.js +41 -0
- package/dist/Deferred.js +16 -0
- package/dist/PromiseQueue.js +107 -0
- package/dist/TapStream.js +23 -0
- package/dist/alternatives.js +97 -0
- package/dist/ansi-html.js +12 -0
- package/dist/blob.js +29 -0
- package/dist/bundle-url.js +32 -0
- package/dist/collection.js +106 -0
- package/dist/config.js +138 -0
- package/dist/countLines.js +12 -0
- package/dist/debounce.js +15 -0
- package/dist/debug-tools.js +39 -0
- package/dist/dependency-location.js +22 -0
- package/dist/escape-html.js +19 -0
- package/dist/generateBuildMetrics.js +111 -0
- package/dist/generateCertificate.js +124 -0
- package/dist/getCertificate.js +13 -0
- package/dist/getExisting.js +20 -0
- package/dist/getModuleParts.js +27 -0
- package/dist/getRootDir.js +46 -0
- package/dist/getTimeId.js +13 -0
- package/dist/glob.js +129 -0
- package/dist/hash.js +45 -0
- package/dist/http-server.js +55 -0
- package/dist/index.js +148 -0
- package/dist/is-url.js +15 -0
- package/dist/isDirectoryInside.js +11 -0
- package/dist/objectHash.js +20 -0
- package/dist/openInBrowser.js +61 -0
- package/dist/parseCSSImport.js +14 -0
- package/dist/path.js +36 -0
- package/dist/prettifyTime.js +6 -0
- package/dist/prettyDiagnostic.js +108 -0
- package/dist/progress-message.js +31 -0
- package/dist/relativeBundlePath.js +13 -0
- package/dist/relativeUrl.js +11 -0
- package/dist/replaceBundleReferences.js +131 -0
- package/dist/schema.js +404 -0
- package/dist/shared-buffer.js +24 -0
- package/dist/sourcemap.js +121 -0
- package/dist/stream.js +69 -0
- package/dist/throttle.js +12 -0
- package/dist/urlJoin.js +22 -0
- package/lib/DefaultMap.js +42 -0
- package/lib/Deferred.js +30 -0
- package/lib/PromiseQueue.js +112 -0
- package/lib/TapStream.js +34 -0
- package/lib/alternatives.js +116 -0
- package/lib/ansi-html.js +20 -0
- package/lib/blob.js +40 -0
- package/lib/bundle-url.js +34 -0
- package/lib/collection.js +111 -0
- package/lib/config.js +174 -0
- package/lib/countLines.js +15 -0
- package/lib/debounce.js +18 -0
- package/lib/debug-tools.js +40 -0
- package/lib/dependency-location.js +21 -0
- package/lib/escape-html.js +22 -0
- package/lib/generateBuildMetrics.js +121 -0
- package/lib/generateCertificate.js +129 -0
- package/lib/getCertificate.js +18 -0
- package/lib/getExisting.js +25 -0
- package/lib/getModuleParts.js +30 -0
- package/lib/getRootDir.js +52 -0
- package/lib/getTimeId.js +10 -0
- package/lib/glob.js +110 -0
- package/lib/hash.js +50 -0
- package/lib/http-server.js +85 -0
- package/lib/index.js +643 -37310
- package/lib/is-url.js +24 -0
- package/lib/isDirectoryInside.js +18 -0
- package/lib/objectHash.js +26 -0
- package/lib/openInBrowser.js +74 -0
- package/lib/parseCSSImport.js +15 -0
- package/lib/path.js +39 -0
- package/lib/prettifyTime.js +9 -0
- package/lib/prettyDiagnostic.js +154 -0
- package/lib/progress-message.js +39 -0
- package/lib/relativeBundlePath.js +22 -0
- package/lib/relativeUrl.js +24 -0
- package/lib/replaceBundleReferences.js +182 -0
- package/lib/schema.js +353 -0
- package/lib/shared-buffer.js +31 -0
- package/lib/sourcemap.js +138 -0
- package/lib/stream.js +76 -0
- package/lib/throttle.js +15 -0
- package/lib/types/DefaultMap.d.ts +13 -0
- package/lib/types/Deferred.d.ts +8 -0
- package/lib/types/PromiseQueue.d.ts +25 -0
- package/lib/types/TapStream.d.ts +6 -0
- package/lib/types/alternatives.d.ts +3 -0
- package/lib/types/ansi-html.d.ts +1 -0
- package/lib/types/blob.d.ts +4 -0
- package/lib/types/bundle-url.d.ts +4 -0
- package/lib/types/collection.d.ts +33 -0
- package/lib/types/config.d.ts +17 -0
- package/lib/types/countLines.d.ts +1 -0
- package/lib/types/debounce.d.ts +1 -0
- package/lib/types/debug-tools.d.ts +8 -0
- package/lib/types/dependency-location.d.ts +14 -0
- package/lib/types/escape-html.d.ts +1 -0
- package/lib/types/generateBuildMetrics.d.ts +18 -0
- package/lib/types/generateCertificate.d.ts +5 -0
- package/lib/types/getCertificate.d.ts +5 -0
- package/lib/types/getExisting.d.ts +8 -0
- package/lib/types/getModuleParts.d.ts +4 -0
- package/lib/types/getRootDir.d.ts +2 -0
- package/lib/types/getTimeId.d.ts +1 -0
- package/lib/types/glob.d.ts +9 -0
- package/lib/types/hash.d.ts +7 -0
- package/lib/types/http-server.d.ts +19 -0
- package/lib/types/index.d.ts +49 -0
- package/lib/types/is-url.d.ts +1 -0
- package/lib/types/isDirectoryInside.d.ts +2 -0
- package/lib/types/objectHash.d.ts +3 -0
- package/lib/types/openInBrowser.d.ts +1 -0
- package/lib/types/parseCSSImport.d.ts +1 -0
- package/lib/types/path.d.ts +8 -0
- package/lib/types/prettifyTime.d.ts +1 -0
- package/lib/types/prettyDiagnostic.d.ts +18 -0
- package/lib/types/progress-message.d.ts +3 -0
- package/lib/types/relativeBundlePath.d.ts +4 -0
- package/lib/types/relativeUrl.d.ts +1 -0
- package/lib/types/replaceBundleReferences.d.ts +39 -0
- package/lib/types/schema.d.ts +107 -0
- package/lib/types/shared-buffer.d.ts +2 -0
- package/lib/types/sourcemap.d.ts +15 -0
- package/lib/types/stream.d.ts +8 -0
- package/lib/types/throttle.d.ts +1 -0
- package/lib/types/urlJoin.d.ts +5 -0
- package/lib/urlJoin.js +35 -0
- package/package.json +27 -18
- package/src/{DefaultMap.js → DefaultMap.ts} +8 -12
- package/src/Deferred.ts +26 -0
- package/src/{PromiseQueue.js → PromiseQueue.ts} +40 -35
- package/src/{TapStream.js → TapStream.ts} +8 -7
- package/src/{alternatives.js → alternatives.ts} +15 -16
- package/src/{ansi-html.js → ansi-html.ts} +1 -1
- package/src/{blob.js → blob.ts} +3 -5
- package/src/{bundle-url.js → bundle-url.ts} +3 -5
- package/src/{collection.js → collection.ts} +23 -20
- package/src/{config.js → config.ts} +20 -21
- package/src/{countLines.js → countLines.ts} +0 -2
- package/src/{debounce.js → debounce.ts} +3 -5
- package/src/debug-tools.ts +48 -0
- package/src/{dependency-location.js → dependency-location.ts} +15 -11
- package/src/{escape-html.js → escape-html.ts} +5 -3
- package/src/{generateBuildMetrics.js → generateBuildMetrics.ts} +19 -21
- package/src/{generateCertificate.js → generateCertificate.ts} +8 -6
- package/src/{getCertificate.js → getCertificate.ts} +6 -5
- package/src/{getExisting.js → getExisting.ts} +4 -3
- package/src/{getModuleParts.js → getModuleParts.ts} +3 -2
- package/src/{getRootDir.js → getRootDir.ts} +1 -3
- package/src/getTimeId.ts +12 -0
- package/src/{glob.js → glob.ts} +13 -14
- package/src/{hash.js → hash.ts} +23 -18
- package/src/{http-server.js → http-server.ts} +34 -40
- package/src/{index.js → index.ts} +14 -10
- package/src/{is-url.js → is-url.ts} +1 -2
- package/src/{isDirectoryInside.js → isDirectoryInside.ts} +1 -2
- package/src/{objectHash.js → objectHash.ts} +1 -4
- package/src/{openInBrowser.js → openInBrowser.ts} +2 -4
- package/src/{parseCSSImport.js → parseCSSImport.ts} +0 -2
- package/src/{path.js → path.ts} +2 -4
- package/src/{prettifyTime.js → prettifyTime.ts} +0 -2
- package/src/{prettyDiagnostic.js → prettyDiagnostic.ts} +47 -24
- package/src/progress-message.ts +43 -0
- package/src/{relativeBundlePath.js → relativeBundlePath.ts} +4 -4
- package/src/{relativeUrl.js → relativeUrl.ts} +0 -1
- package/src/{replaceBundleReferences.js → replaceBundleReferences.ts} +67 -51
- package/src/schema.ts +552 -0
- package/src/{shared-buffer.js → shared-buffer.ts} +5 -3
- package/src/{sourcemap.js → sourcemap.ts} +28 -10
- package/src/{stream.js → stream.ts} +30 -22
- package/src/throttle.ts +13 -0
- package/src/{urlJoin.js → urlJoin.ts} +1 -3
- package/test/{DefaultMap.test.js → DefaultMap.test.ts} +4 -6
- package/test/{PromiseQueue.test.js → PromiseQueue.test.ts} +5 -6
- package/test/{collection.test.js → collection.test.ts} +0 -2
- package/test/{config.test.js → config.test.ts} +0 -3
- package/test/{objectHash.test.js → objectHash.test.ts} +4 -5
- package/test/{prettifyTime.test.js → prettifyTime.test.ts} +0 -1
- package/test/{replaceBundleReferences.test.js → replaceBundleReferences.test.ts} +0 -32
- package/test/schema.test.ts +748 -0
- package/test/{sourcemap.test.js → sourcemap.test.ts} +0 -1
- package/test/{throttle.test.js → throttle.test.ts} +1 -3
- package/test/{urlJoin.test.js → urlJoin.test.ts} +0 -2
- package/tsconfig.json +36 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/lib/index.js.map +0 -1
- package/src/Deferred.js +0 -23
- package/src/progress-message.js +0 -22
- package/src/schema.js +0 -504
- package/src/throttle.js +0 -15
package/lib/schema.js
ADDED
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
exports.fuzzySearch = fuzzySearch;
|
|
8
|
+
function _diagnostic() {
|
|
9
|
+
const data = _interopRequireWildcard(require("@atlaspack/diagnostic"));
|
|
10
|
+
_diagnostic = function () {
|
|
11
|
+
return data;
|
|
12
|
+
};
|
|
13
|
+
return data;
|
|
14
|
+
}
|
|
15
|
+
function _nullthrows() {
|
|
16
|
+
const data = _interopRequireDefault(require("nullthrows"));
|
|
17
|
+
_nullthrows = function () {
|
|
18
|
+
return data;
|
|
19
|
+
};
|
|
20
|
+
return data;
|
|
21
|
+
}
|
|
22
|
+
function levenshtein() {
|
|
23
|
+
const data = _interopRequireWildcard(require("fastest-levenshtein"));
|
|
24
|
+
levenshtein = function () {
|
|
25
|
+
return data;
|
|
26
|
+
};
|
|
27
|
+
return data;
|
|
28
|
+
}
|
|
29
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
30
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
31
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
32
|
+
function validateSchema(schema, data) {
|
|
33
|
+
function walk(schemaAncestors, dataNode, dataPath) {
|
|
34
|
+
let [schemaNode] = schemaAncestors;
|
|
35
|
+
if ('type' in schemaNode && schemaNode.type) {
|
|
36
|
+
let type = Array.isArray(dataNode) ? 'array' : typeof dataNode;
|
|
37
|
+
if (schemaNode.type !== type) {
|
|
38
|
+
return {
|
|
39
|
+
type: 'type',
|
|
40
|
+
dataType: 'value',
|
|
41
|
+
dataPath,
|
|
42
|
+
expectedTypes: [schemaNode.type],
|
|
43
|
+
ancestors: schemaAncestors,
|
|
44
|
+
prettyType: '__type' in schemaNode ? schemaNode.__type : undefined
|
|
45
|
+
};
|
|
46
|
+
} else {
|
|
47
|
+
switch (schemaNode.type) {
|
|
48
|
+
case 'array':
|
|
49
|
+
{
|
|
50
|
+
if ('items' in schemaNode && schemaNode.items && Array.isArray(dataNode)) {
|
|
51
|
+
let results = [];
|
|
52
|
+
for (let i = 0; i < dataNode.length; i++) {
|
|
53
|
+
let result = walk([schemaNode.items].concat(schemaAncestors), dataNode[i], dataPath + '/' + i);
|
|
54
|
+
if (result) results.push(result);
|
|
55
|
+
}
|
|
56
|
+
if (results.length) return results.reduce((acc, v) => acc.concat(v), []);
|
|
57
|
+
}
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
case 'string':
|
|
61
|
+
{
|
|
62
|
+
if (typeof dataNode === 'string') {
|
|
63
|
+
let value = dataNode;
|
|
64
|
+
if ('enum' in schemaNode && schemaNode.enum) {
|
|
65
|
+
if (!schemaNode.enum.includes(value)) {
|
|
66
|
+
return {
|
|
67
|
+
type: 'enum',
|
|
68
|
+
dataType: 'value',
|
|
69
|
+
dataPath,
|
|
70
|
+
expectedValues: schemaNode.enum,
|
|
71
|
+
actualValue: value,
|
|
72
|
+
ancestors: schemaAncestors
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
} else if ('__validate' in schemaNode && schemaNode.__validate) {
|
|
76
|
+
let validationError = schemaNode.__validate(value);
|
|
77
|
+
if (typeof validationError == 'string') {
|
|
78
|
+
return {
|
|
79
|
+
type: 'other',
|
|
80
|
+
dataType: 'value',
|
|
81
|
+
dataPath,
|
|
82
|
+
message: validationError,
|
|
83
|
+
actualValue: value,
|
|
84
|
+
ancestors: schemaAncestors
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
case 'number':
|
|
92
|
+
{
|
|
93
|
+
if (typeof dataNode === 'number') {
|
|
94
|
+
let value = dataNode;
|
|
95
|
+
if ('enum' in schemaNode && schemaNode.enum) {
|
|
96
|
+
if (!schemaNode.enum.includes(value)) {
|
|
97
|
+
return {
|
|
98
|
+
type: 'enum',
|
|
99
|
+
dataType: 'value',
|
|
100
|
+
dataPath,
|
|
101
|
+
expectedValues: schemaNode.enum,
|
|
102
|
+
actualValue: value,
|
|
103
|
+
ancestors: schemaAncestors
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
case 'object':
|
|
111
|
+
{
|
|
112
|
+
if (typeof dataNode === 'object' && dataNode !== null && !Array.isArray(dataNode)) {
|
|
113
|
+
let results = [];
|
|
114
|
+
let invalidProps;
|
|
115
|
+
if ('__forbiddenProperties' in schemaNode && schemaNode.__forbiddenProperties) {
|
|
116
|
+
let keys = Object.keys(dataNode);
|
|
117
|
+
invalidProps = schemaNode.__forbiddenProperties.filter(val => keys.includes(val));
|
|
118
|
+
results.push(...invalidProps.map(k => ({
|
|
119
|
+
type: 'forbidden-prop',
|
|
120
|
+
dataPath: dataPath + '/' + (0, _diagnostic().encodeJSONKeyComponent)(k),
|
|
121
|
+
dataType: 'key',
|
|
122
|
+
prop: k,
|
|
123
|
+
expectedProps: Object.keys(schemaNode.properties),
|
|
124
|
+
actualProps: keys,
|
|
125
|
+
ancestors: schemaAncestors
|
|
126
|
+
})));
|
|
127
|
+
}
|
|
128
|
+
if ('required' in schemaNode && schemaNode.required) {
|
|
129
|
+
let keys = Object.keys(dataNode);
|
|
130
|
+
let missingKeys = schemaNode.required.filter(val => !keys.includes(val));
|
|
131
|
+
results.push(...missingKeys.map(k => ({
|
|
132
|
+
type: 'missing-prop',
|
|
133
|
+
dataPath,
|
|
134
|
+
dataType: 'value',
|
|
135
|
+
prop: k,
|
|
136
|
+
expectedProps: schemaNode.required,
|
|
137
|
+
actualProps: keys,
|
|
138
|
+
ancestors: schemaAncestors
|
|
139
|
+
})));
|
|
140
|
+
}
|
|
141
|
+
if ('properties' in schemaNode && schemaNode.properties) {
|
|
142
|
+
let {
|
|
143
|
+
additionalProperties = true
|
|
144
|
+
} = schemaNode;
|
|
145
|
+
for (let k in dataNode) {
|
|
146
|
+
if (invalidProps && invalidProps.includes(k)) {
|
|
147
|
+
// Don't check type on forbidden props
|
|
148
|
+
continue;
|
|
149
|
+
} else if (k in schemaNode.properties) {
|
|
150
|
+
let result = walk([schemaNode.properties[k]].concat(schemaAncestors), dataNode[k], dataPath + '/' + (0, _diagnostic().encodeJSONKeyComponent)(k));
|
|
151
|
+
if (result) results.push(result);
|
|
152
|
+
} else {
|
|
153
|
+
if (typeof additionalProperties === 'boolean') {
|
|
154
|
+
if (!additionalProperties) {
|
|
155
|
+
results.push({
|
|
156
|
+
type: 'enum',
|
|
157
|
+
dataType: 'key',
|
|
158
|
+
dataPath: dataPath + '/' + (0, _diagnostic().encodeJSONKeyComponent)(k),
|
|
159
|
+
expectedValues: Object.keys(schemaNode.properties).filter(p => !(p in dataNode)),
|
|
160
|
+
actualValue: k,
|
|
161
|
+
ancestors: schemaAncestors,
|
|
162
|
+
prettyType: schemaNode.__type
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
} else {
|
|
166
|
+
let result = walk([additionalProperties].concat(schemaAncestors), dataNode[k], dataPath + '/' + (0, _diagnostic().encodeJSONKeyComponent)(k));
|
|
167
|
+
if (result) results.push(result);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (results.length) return results.reduce((acc, v) => acc.concat(v), []);
|
|
173
|
+
}
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
case 'boolean':
|
|
177
|
+
// NOOP, type was checked already
|
|
178
|
+
break;
|
|
179
|
+
default:
|
|
180
|
+
throw new Error(`Unimplemented schema type ${type}?`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
} else {
|
|
184
|
+
if ('enum' in schemaNode && schemaNode.enum && !schemaNode.enum.includes(dataNode)) {
|
|
185
|
+
return {
|
|
186
|
+
type: 'enum',
|
|
187
|
+
dataType: 'value',
|
|
188
|
+
dataPath: dataPath,
|
|
189
|
+
expectedValues: schemaNode.enum,
|
|
190
|
+
actualValue: schemaNode,
|
|
191
|
+
ancestors: schemaAncestors
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
if ('oneOf' in schemaNode || 'allOf' in schemaNode) {
|
|
195
|
+
let list = 'oneOf' in schemaNode ? schemaNode.oneOf : 'allOf' in schemaNode ? schemaNode.allOf : [];
|
|
196
|
+
let results = [];
|
|
197
|
+
for (let f of list) {
|
|
198
|
+
let result = walk([f].concat(schemaAncestors), dataNode, dataPath);
|
|
199
|
+
if (result) results.push(result);
|
|
200
|
+
}
|
|
201
|
+
if ('oneOf' in schemaNode ? results.length == schemaNode.oneOf.length : results.length > 0) {
|
|
202
|
+
// return the result with more values / longer key
|
|
203
|
+
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);
|
|
204
|
+
return results[0];
|
|
205
|
+
}
|
|
206
|
+
} else if ('not' in schemaNode && schemaNode.not) {
|
|
207
|
+
let result = walk([schemaNode.not].concat(schemaAncestors), dataNode, dataPath);
|
|
208
|
+
if (!result || Array.isArray(result) && result.length == 0) {
|
|
209
|
+
return {
|
|
210
|
+
type: 'other',
|
|
211
|
+
dataPath,
|
|
212
|
+
dataType: null,
|
|
213
|
+
message: schemaNode.__message,
|
|
214
|
+
actualValue: dataNode,
|
|
215
|
+
ancestors: schemaAncestors
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return undefined;
|
|
221
|
+
}
|
|
222
|
+
let result = walk([schema], data, '');
|
|
223
|
+
return Array.isArray(result) ? result : result ? [result] : [];
|
|
224
|
+
}
|
|
225
|
+
var _default = exports.default = validateSchema;
|
|
226
|
+
function fuzzySearch(expectedValues, actualValue) {
|
|
227
|
+
let result = expectedValues.map(exp => [exp, levenshtein().distance(exp, actualValue)]).filter(
|
|
228
|
+
// Remove if more than half of the string would need to be changed
|
|
229
|
+
([, d]) => d * 2 < actualValue.length);
|
|
230
|
+
result.sort(([, a], [, b]) => a - b);
|
|
231
|
+
return result.map(([v]) => v);
|
|
232
|
+
}
|
|
233
|
+
validateSchema.diagnostic = function (schema, data, origin, message) {
|
|
234
|
+
if (!('map' in data) && !('source' in data || 'data' in data)) {
|
|
235
|
+
throw new Error('At least one of data.source, data.data, or data.map must be defined!');
|
|
236
|
+
}
|
|
237
|
+
let loadedSource;
|
|
238
|
+
function loadSource(loader) {
|
|
239
|
+
if (loadedSource !== undefined) {
|
|
240
|
+
return loadedSource;
|
|
241
|
+
} else if (typeof loader === 'function') {
|
|
242
|
+
loadedSource = loader();
|
|
243
|
+
return loadedSource;
|
|
244
|
+
} else if (typeof loader === 'string') {
|
|
245
|
+
loadedSource = loader;
|
|
246
|
+
return loadedSource;
|
|
247
|
+
}
|
|
248
|
+
return loadedSource;
|
|
249
|
+
}
|
|
250
|
+
let object;
|
|
251
|
+
if ('map' in data && data.map) {
|
|
252
|
+
object = data.map.data;
|
|
253
|
+
} else if ('data' in data && data.data !== undefined) {
|
|
254
|
+
object = data.data;
|
|
255
|
+
} else if ('source' in data && data.source) {
|
|
256
|
+
object = JSON.parse(loadSource(data.source) || '');
|
|
257
|
+
} else {
|
|
258
|
+
throw new Error('Unable to get object from data');
|
|
259
|
+
}
|
|
260
|
+
let errors = validateSchema(schema, object);
|
|
261
|
+
if (errors.length) {
|
|
262
|
+
let keys = errors.map(e => {
|
|
263
|
+
let message;
|
|
264
|
+
if (e.type === 'enum') {
|
|
265
|
+
let {
|
|
266
|
+
actualValue
|
|
267
|
+
} = e;
|
|
268
|
+
let expectedValues = e.expectedValues.map(String);
|
|
269
|
+
let likely = actualValue != null ? fuzzySearch(expectedValues, String(actualValue)) : [];
|
|
270
|
+
if (likely.length > 0) {
|
|
271
|
+
message = `Did you mean ${likely.map(v => JSON.stringify(v)).join(', ')}?`;
|
|
272
|
+
} else if (expectedValues.length > 0) {
|
|
273
|
+
message = `Possible values: ${expectedValues.map(v => JSON.stringify(v)).join(', ')}`;
|
|
274
|
+
} else {
|
|
275
|
+
message = 'Unexpected value';
|
|
276
|
+
}
|
|
277
|
+
} else if (e.type === 'forbidden-prop') {
|
|
278
|
+
let {
|
|
279
|
+
prop,
|
|
280
|
+
expectedProps,
|
|
281
|
+
actualProps
|
|
282
|
+
} = e;
|
|
283
|
+
let likely = fuzzySearch(expectedProps, prop).filter(v => !actualProps.includes(v));
|
|
284
|
+
if (likely.length > 0) {
|
|
285
|
+
message = `Did you mean ${likely.map(v => JSON.stringify(v)).join(', ')}?`;
|
|
286
|
+
} else {
|
|
287
|
+
message = 'Unexpected property';
|
|
288
|
+
}
|
|
289
|
+
} else if (e.type === 'missing-prop') {
|
|
290
|
+
let {
|
|
291
|
+
prop,
|
|
292
|
+
actualProps
|
|
293
|
+
} = e;
|
|
294
|
+
let likely = fuzzySearch(actualProps, prop);
|
|
295
|
+
if (likely.length > 0) {
|
|
296
|
+
message = `Did you mean ${JSON.stringify(prop)}?`;
|
|
297
|
+
e.dataPath += '/' + likely[0];
|
|
298
|
+
e.dataType = 'key';
|
|
299
|
+
} else {
|
|
300
|
+
message = `Missing property ${prop}`;
|
|
301
|
+
}
|
|
302
|
+
} else if (e.type === 'type') {
|
|
303
|
+
if (e.prettyType != null) {
|
|
304
|
+
message = `Expected ${e.prettyType}`;
|
|
305
|
+
} else {
|
|
306
|
+
message = `Expected type ${e.expectedTypes.join(', ')}`;
|
|
307
|
+
}
|
|
308
|
+
} else {
|
|
309
|
+
message = e.message;
|
|
310
|
+
}
|
|
311
|
+
return {
|
|
312
|
+
key: e.dataPath,
|
|
313
|
+
type: e.dataType,
|
|
314
|
+
message
|
|
315
|
+
};
|
|
316
|
+
});
|
|
317
|
+
let map, code;
|
|
318
|
+
if ('map' in data && data.map) {
|
|
319
|
+
map = data.map;
|
|
320
|
+
code = loadSource(data.source) ?? '';
|
|
321
|
+
} else {
|
|
322
|
+
if ('source' in data && data.source) {
|
|
323
|
+
map = loadSource(data.source) ?? '';
|
|
324
|
+
} else if ('data' in data && data.data !== undefined) {
|
|
325
|
+
map = JSON.stringify((0, _nullthrows().default)(data.data), null, '\t');
|
|
326
|
+
} else {
|
|
327
|
+
map = '';
|
|
328
|
+
}
|
|
329
|
+
code = map;
|
|
330
|
+
}
|
|
331
|
+
let codeFrames = [{
|
|
332
|
+
filePath: data.filePath ?? undefined,
|
|
333
|
+
language: 'json',
|
|
334
|
+
code: code ?? '',
|
|
335
|
+
codeHighlights: (0, _diagnostic().generateJSONCodeHighlights)(map, keys.map(({
|
|
336
|
+
key,
|
|
337
|
+
type,
|
|
338
|
+
message
|
|
339
|
+
}) => ({
|
|
340
|
+
key: (data.prependKey ?? '') + key,
|
|
341
|
+
type: type,
|
|
342
|
+
message: message != null ? (0, _diagnostic().escapeMarkdown)(message) : message
|
|
343
|
+
})))
|
|
344
|
+
}];
|
|
345
|
+
throw new (_diagnostic().default)({
|
|
346
|
+
diagnostic: {
|
|
347
|
+
message: message,
|
|
348
|
+
origin,
|
|
349
|
+
codeFrames
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.SharedBuffer = void 0;
|
|
7
|
+
// flow-to-ts helpers
|
|
8
|
+
|
|
9
|
+
// /flow-to-ts helpers
|
|
10
|
+
|
|
11
|
+
let SharedBuffer = exports.SharedBuffer = void 0;
|
|
12
|
+
|
|
13
|
+
// @ts-expect-error process.browser is a browser-specific property
|
|
14
|
+
if (process.browser) {
|
|
15
|
+
exports.SharedBuffer = SharedBuffer = ArrayBuffer;
|
|
16
|
+
// Safari has removed the constructor
|
|
17
|
+
if (typeof SharedArrayBuffer !== 'undefined') {
|
|
18
|
+
let channel = new MessageChannel();
|
|
19
|
+
try {
|
|
20
|
+
// Firefox might throw when sending the Buffer over a MessagePort
|
|
21
|
+
channel.port1.postMessage(new SharedArrayBuffer(0));
|
|
22
|
+
exports.SharedBuffer = SharedBuffer = SharedArrayBuffer;
|
|
23
|
+
} catch (_) {
|
|
24
|
+
// NOOP
|
|
25
|
+
}
|
|
26
|
+
channel.port1.close();
|
|
27
|
+
channel.port2.close();
|
|
28
|
+
}
|
|
29
|
+
} else {
|
|
30
|
+
exports.SharedBuffer = SharedBuffer = SharedArrayBuffer;
|
|
31
|
+
}
|
package/lib/sourcemap.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.SOURCEMAP_RE = exports.SOURCEMAP_EXTENSIONS = void 0;
|
|
7
|
+
exports.loadSourceMap = loadSourceMap;
|
|
8
|
+
exports.loadSourceMapUrl = loadSourceMapUrl;
|
|
9
|
+
exports.matchSourceMappingURL = matchSourceMappingURL;
|
|
10
|
+
exports.remapSourceLocation = remapSourceLocation;
|
|
11
|
+
function _featureFlags() {
|
|
12
|
+
const data = require("@atlaspack/feature-flags");
|
|
13
|
+
_featureFlags = function () {
|
|
14
|
+
return data;
|
|
15
|
+
};
|
|
16
|
+
return data;
|
|
17
|
+
}
|
|
18
|
+
function _sourceMap() {
|
|
19
|
+
const data = _interopRequireDefault(require("@atlaspack/source-map"));
|
|
20
|
+
_sourceMap = function () {
|
|
21
|
+
return data;
|
|
22
|
+
};
|
|
23
|
+
return data;
|
|
24
|
+
}
|
|
25
|
+
function _path() {
|
|
26
|
+
const data = _interopRequireDefault(require("path"));
|
|
27
|
+
_path = function () {
|
|
28
|
+
return data;
|
|
29
|
+
};
|
|
30
|
+
return data;
|
|
31
|
+
}
|
|
32
|
+
var _path2 = require("./path");
|
|
33
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
34
|
+
const SOURCEMAP_RE = exports.SOURCEMAP_RE = /(?:\/\*|\/\/)\s*[@#]\s*sourceMappingURL\s*=\s*([^\s*]+)(?:\s*\*\/)?\s*$/;
|
|
35
|
+
const DATA_URL_RE = /^data:[^;]+(?:;charset=[^;]+)?;base64,(.*)/;
|
|
36
|
+
const SOURCEMAP_EXTENSIONS = exports.SOURCEMAP_EXTENSIONS = new Set(['css', 'es', 'es6', 'js', 'jsx', 'mjs', 'ts', 'tsx']);
|
|
37
|
+
function matchSourceMappingURL(contents) {
|
|
38
|
+
return contents.match(SOURCEMAP_RE);
|
|
39
|
+
}
|
|
40
|
+
async function loadSourceMapUrl(fs, filename, contents) {
|
|
41
|
+
let match = matchSourceMappingURL(contents);
|
|
42
|
+
if (match) {
|
|
43
|
+
let url = match[1].trim();
|
|
44
|
+
let dataURLMatch = url.match(DATA_URL_RE);
|
|
45
|
+
let mapFilePath;
|
|
46
|
+
if (dataURLMatch) {
|
|
47
|
+
mapFilePath = filename;
|
|
48
|
+
} else {
|
|
49
|
+
mapFilePath = url.replace(/^file:\/\//, '');
|
|
50
|
+
mapFilePath = (0, _path2.isAbsolute)(mapFilePath) ? mapFilePath : _path().default.join(_path().default.dirname(filename), mapFilePath);
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
url,
|
|
54
|
+
filename: mapFilePath,
|
|
55
|
+
map: JSON.parse(dataURLMatch ? Buffer.from(dataURLMatch[1], 'base64').toString() : await fs.readFile(mapFilePath, 'utf8'))
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async function loadSourceMap(filename, contents, options) {
|
|
60
|
+
let foundMap = await loadSourceMapUrl(options.fs, filename, contents);
|
|
61
|
+
if (foundMap) {
|
|
62
|
+
let mapSourceRoot = _path().default.dirname(filename);
|
|
63
|
+
if (foundMap.map.sourceRoot && !(0, _path2.normalizeSeparators)(foundMap.map.sourceRoot).startsWith('/')) {
|
|
64
|
+
mapSourceRoot = _path().default.join(mapSourceRoot, foundMap.map.sourceRoot);
|
|
65
|
+
}
|
|
66
|
+
let sourcemapInstance = new (_sourceMap().default)(options.projectRoot);
|
|
67
|
+
sourcemapInstance.addVLQMap({
|
|
68
|
+
...foundMap.map,
|
|
69
|
+
sources: foundMap.map.sources.map(s => {
|
|
70
|
+
return _path().default.join(mapSourceRoot, s);
|
|
71
|
+
})
|
|
72
|
+
});
|
|
73
|
+
return sourcemapInstance;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function remapSourceLocation(loc, originalMap, projectRoot) {
|
|
77
|
+
let {
|
|
78
|
+
filePath,
|
|
79
|
+
start: {
|
|
80
|
+
line: startLine,
|
|
81
|
+
column: startCol
|
|
82
|
+
},
|
|
83
|
+
end: {
|
|
84
|
+
line: endLine,
|
|
85
|
+
column: endCol
|
|
86
|
+
}
|
|
87
|
+
} = loc;
|
|
88
|
+
let lineDiff = endLine - startLine;
|
|
89
|
+
let colDiff = endCol - startCol;
|
|
90
|
+
let start = originalMap.findClosestMapping(startLine, startCol - 1);
|
|
91
|
+
let end = originalMap.findClosestMapping(endLine, endCol - 1);
|
|
92
|
+
if (start !== null && start !== void 0 && start.original) {
|
|
93
|
+
if (start.source) {
|
|
94
|
+
if ((0, _featureFlags().getFeatureFlag)('symbolLocationFix') && !_path().default.isAbsolute(start.source)) {
|
|
95
|
+
filePath = _path().default.join(projectRoot, start.source);
|
|
96
|
+
} else {
|
|
97
|
+
filePath = start.source;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
({
|
|
101
|
+
line: startLine,
|
|
102
|
+
column: startCol
|
|
103
|
+
} = start.original);
|
|
104
|
+
startCol++; // source map columns are 0-based
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (end !== null && end !== void 0 && end.original) {
|
|
108
|
+
({
|
|
109
|
+
line: endLine,
|
|
110
|
+
column: endCol
|
|
111
|
+
} = end.original);
|
|
112
|
+
endCol++; // source map columns are 0-based
|
|
113
|
+
|
|
114
|
+
if (endLine < startLine) {
|
|
115
|
+
endLine = startLine;
|
|
116
|
+
endCol = startCol;
|
|
117
|
+
} else if (endLine === startLine && endCol < startCol && lineDiff === 0) {
|
|
118
|
+
endCol = startCol + colDiff;
|
|
119
|
+
} else if (endLine === startLine && startCol === endCol && lineDiff === 0) {
|
|
120
|
+
// Prevent 0-length ranges
|
|
121
|
+
endCol = startCol + 1;
|
|
122
|
+
}
|
|
123
|
+
} else {
|
|
124
|
+
endLine = startLine;
|
|
125
|
+
endCol = startCol;
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
filePath,
|
|
129
|
+
start: {
|
|
130
|
+
line: startLine,
|
|
131
|
+
column: startCol
|
|
132
|
+
},
|
|
133
|
+
end: {
|
|
134
|
+
line: endLine,
|
|
135
|
+
column: endCol
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
}
|
package/lib/stream.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.blobToStream = blobToStream;
|
|
7
|
+
exports.bufferStream = bufferStream;
|
|
8
|
+
exports.fallbackStream = fallbackStream;
|
|
9
|
+
exports.measureStreamLength = measureStreamLength;
|
|
10
|
+
exports.readableFromStringOrBuffer = readableFromStringOrBuffer;
|
|
11
|
+
exports.streamFromPromise = streamFromPromise;
|
|
12
|
+
function _stream() {
|
|
13
|
+
const data = require("stream");
|
|
14
|
+
_stream = function () {
|
|
15
|
+
return data;
|
|
16
|
+
};
|
|
17
|
+
return data;
|
|
18
|
+
}
|
|
19
|
+
function measureStreamLength(stream) {
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
let length = 0;
|
|
22
|
+
stream.on('data', chunk => {
|
|
23
|
+
length += chunk;
|
|
24
|
+
});
|
|
25
|
+
stream.on('end', () => resolve(length));
|
|
26
|
+
stream.on('error', reject);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function readableFromStringOrBuffer(str) {
|
|
30
|
+
// https://stackoverflow.com/questions/12755997/how-to-create-streams-from-string-in-node-js
|
|
31
|
+
const stream = new (_stream().Readable)();
|
|
32
|
+
stream.push(str);
|
|
33
|
+
stream.push(null);
|
|
34
|
+
return stream;
|
|
35
|
+
}
|
|
36
|
+
function bufferStream(stream) {
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
let buf = Buffer.from([]);
|
|
39
|
+
stream.on('data', data => {
|
|
40
|
+
buf = Buffer.concat([buf, data]);
|
|
41
|
+
});
|
|
42
|
+
stream.on('end', () => {
|
|
43
|
+
resolve(buf);
|
|
44
|
+
});
|
|
45
|
+
stream.on('error', reject);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function blobToStream(blob) {
|
|
49
|
+
if (blob instanceof _stream().Readable) {
|
|
50
|
+
return blob;
|
|
51
|
+
}
|
|
52
|
+
return readableFromStringOrBuffer(blob);
|
|
53
|
+
}
|
|
54
|
+
function streamFromPromise(promise) {
|
|
55
|
+
const stream = new (_stream().PassThrough)();
|
|
56
|
+
promise.then(blob => {
|
|
57
|
+
if (blob instanceof _stream().Readable) {
|
|
58
|
+
blob.pipe(stream);
|
|
59
|
+
} else {
|
|
60
|
+
stream.end(blob);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
return stream;
|
|
64
|
+
}
|
|
65
|
+
function fallbackStream(stream, fallback) {
|
|
66
|
+
const res = new (_stream().PassThrough)();
|
|
67
|
+
stream.on('error', err => {
|
|
68
|
+
if (err.code === 'ENOENT') {
|
|
69
|
+
fallback().pipe(res);
|
|
70
|
+
} else {
|
|
71
|
+
res.emit('error', err);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
stream.pipe(res);
|
|
75
|
+
return res;
|
|
76
|
+
}
|
package/lib/throttle.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = throttle;
|
|
7
|
+
function throttle(fn, delay) {
|
|
8
|
+
let lastCalled;
|
|
9
|
+
return function throttled(...args) {
|
|
10
|
+
if (lastCalled == null || lastCalled + delay <= Date.now()) {
|
|
11
|
+
fn.call(this, ...args);
|
|
12
|
+
lastCalled = Date.now();
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare class DefaultMap<K, V> extends Map<K, V> {
|
|
2
|
+
_getDefault: (arg1: K) => V;
|
|
3
|
+
constructor(getDefault: (arg1: K) => V, entries?: Iterable<[K, V]>);
|
|
4
|
+
get(key: K): V;
|
|
5
|
+
}
|
|
6
|
+
interface Key {
|
|
7
|
+
}
|
|
8
|
+
export declare class DefaultWeakMap<K extends Key, V> extends WeakMap<K, V> {
|
|
9
|
+
_getDefault: (arg1: K) => V;
|
|
10
|
+
constructor(getDefault: (arg1: K) => V, entries?: Iterable<[K, V]>);
|
|
11
|
+
get(key: K): V;
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type Deferred } from './Deferred';
|
|
2
|
+
type PromiseQueueOpts = {
|
|
3
|
+
maxConcurrent: number;
|
|
4
|
+
};
|
|
5
|
+
export default class PromiseQueue<T> {
|
|
6
|
+
_deferred: Deferred<Array<T>> | null | undefined;
|
|
7
|
+
_maxConcurrent: number;
|
|
8
|
+
_numRunning: number;
|
|
9
|
+
_queue: Array<() => Promise<void>>;
|
|
10
|
+
_runPromise: Promise<Array<T>> | null | undefined;
|
|
11
|
+
_error: unknown;
|
|
12
|
+
_count: number;
|
|
13
|
+
_results: Array<T>;
|
|
14
|
+
_addSubscriptions: Set<() => void>;
|
|
15
|
+
constructor(opts?: PromiseQueueOpts);
|
|
16
|
+
getNumWaiting(): number;
|
|
17
|
+
add(fn: () => Promise<T>): void;
|
|
18
|
+
subscribeToAdd(fn: () => void): () => void;
|
|
19
|
+
run(): Promise<Array<T>>;
|
|
20
|
+
_next(): Promise<void>;
|
|
21
|
+
_runFn(fn: () => unknown): Promise<void>;
|
|
22
|
+
_resetState(): void;
|
|
23
|
+
_done(): void;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Transform } from 'stream';
|
|
2
|
+
export default class TapStream extends Transform {
|
|
3
|
+
_tap: (arg1: Buffer) => unknown;
|
|
4
|
+
constructor(tap: (arg1: Buffer) => unknown, options: unknown);
|
|
5
|
+
_transform(chunk: Buffer | string, encoding: string, callback: (err?: Error | null | undefined, chunk?: Buffer | string) => unknown): void;
|
|
6
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { FileSystem } from '@atlaspack/types-internal';
|
|
2
|
+
export declare function findAlternativeNodeModules(fs: FileSystem, moduleName: string, dir: string): Promise<Array<string>>;
|
|
3
|
+
export declare function findAlternativeFiles(fs: FileSystem, fileSpecifier: string, dir: string, projectRoot: string, leadingDotSlash?: boolean, includeDirectories?: boolean, includeExtension?: boolean): Promise<Array<string>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function ansiHtml(ansi: string): string;
|