@atlaspack/utils 2.14.5-canary.138 → 2.14.5-canary.139
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/DefaultMap.d.ts +13 -0
- package/lib/DefaultMap.js +0 -4
- package/lib/Deferred.d.ts +8 -0
- package/lib/PromiseQueue.d.ts +25 -0
- package/lib/TapStream.d.ts +6 -0
- package/lib/alternatives.d.ts +3 -0
- package/lib/ansi-html.d.ts +1 -0
- package/lib/ansi-html.js +2 -0
- package/lib/blob.d.ts +4 -0
- package/lib/bundle-url.d.ts +4 -0
- package/lib/collection.d.ts +33 -0
- package/lib/config.d.ts +17 -0
- package/lib/config.js +3 -1
- package/lib/countLines.d.ts +1 -0
- package/lib/debounce.d.ts +1 -0
- package/lib/debug-tools.d.ts +6 -0
- package/lib/debug-tools.js +1 -0
- package/lib/dependency-location.d.ts +14 -0
- package/lib/escape-html.d.ts +1 -0
- package/lib/generateBuildMetrics.d.ts +18 -0
- package/lib/generateCertificate.d.ts +5 -0
- package/lib/getCertificate.d.ts +6 -0
- package/lib/getExisting.d.ts +8 -0
- package/lib/getModuleParts.d.ts +4 -0
- package/lib/getRootDir.d.ts +2 -0
- package/lib/glob.d.ts +10 -0
- package/lib/glob.js +12 -4
- package/lib/hash.d.ts +7 -0
- package/lib/http-server.d.ts +19 -0
- package/lib/index.d.ts +48 -0
- package/lib/index.js +164 -9
- package/lib/is-url.d.ts +1 -0
- package/lib/is-url.js +2 -0
- package/lib/isDirectoryInside.d.ts +2 -0
- package/lib/objectHash.d.ts +3 -0
- package/lib/objectHash.js +0 -1
- package/lib/openInBrowser.d.ts +1 -0
- package/lib/parseCSSImport.d.ts +1 -0
- package/lib/path.d.ts +8 -0
- package/lib/prettifyTime.d.ts +1 -0
- package/lib/prettyDiagnostic.d.ts +17 -0
- package/lib/prettyDiagnostic.js +3 -5
- package/lib/progress-message.d.ts +3 -0
- package/lib/relativeBundlePath.d.ts +4 -0
- package/lib/relativeUrl.d.ts +1 -0
- package/lib/replaceBundleReferences.d.ts +39 -0
- package/lib/schema.d.ts +107 -0
- package/lib/schema.js +38 -19
- package/lib/shared-buffer.d.ts +2 -0
- package/lib/shared-buffer.js +5 -1
- package/lib/sourcemap.d.ts +16 -0
- package/lib/stream.d.ts +8 -0
- package/lib/throttle.d.ts +1 -0
- package/lib/urlJoin.d.ts +5 -0
- package/lib/urlJoin.js +1 -1
- package/package.json +17 -11
- 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} +14 -15
- package/src/{ansi-html.js → ansi-html.ts} +1 -1
- package/src/{blob.js → blob.ts} +2 -4
- package/src/{bundle-url.js → bundle-url.ts} +3 -5
- package/src/{collection.js → collection.ts} +14 -21
- package/src/{config.js → config.ts} +18 -19
- package/src/{countLines.js → countLines.ts} +0 -2
- package/src/{debounce.js → debounce.ts} +3 -5
- package/src/{debug-tools.js → debug-tools.ts} +6 -8
- 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} +16 -18
- package/src/{generateCertificate.js → generateCertificate.ts} +7 -5
- package/src/{getCertificate.js → getCertificate.ts} +5 -3
- package/src/{getExisting.js → getExisting.ts} +4 -3
- package/src/{getModuleParts.js → getModuleParts.ts} +3 -2
- package/src/{getRootDir.js → getRootDir.ts} +0 -2
- package/src/{glob.js → glob.ts} +14 -10
- package/src/{hash.js → hash.ts} +22 -17
- package/src/{http-server.js → http-server.ts} +32 -38
- package/src/{index.js → index.ts} +7 -8
- package/src/{is-url.js → is-url.ts} +1 -2
- package/src/{isDirectoryInside.js → isDirectoryInside.ts} +0 -1
- 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} +1 -3
- package/src/{prettifyTime.js → prettifyTime.ts} +0 -2
- package/src/{prettyDiagnostic.js → prettyDiagnostic.ts} +22 -20
- package/src/{progress-message.js → progress-message.ts} +3 -2
- package/src/{relativeBundlePath.js → relativeBundlePath.ts} +3 -3
- package/src/{relativeUrl.js → relativeUrl.ts} +0 -1
- package/src/{replaceBundleReferences.js → replaceBundleReferences.ts} +54 -36
- package/src/{schema.js → schema.ts} +158 -141
- package/src/{shared-buffer.js → shared-buffer.ts} +5 -3
- package/src/{sourcemap.js → sourcemap.ts} +16 -6
- package/src/{stream.js → stream.ts} +29 -21
- 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/{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 +4 -0
- package/src/Deferred.js +0 -23
- package/src/throttle.js +0 -15
package/lib/is-url.js
CHANGED
package/lib/objectHash.js
CHANGED
|
@@ -12,7 +12,6 @@ function _crypto() {
|
|
|
12
12
|
return data;
|
|
13
13
|
}
|
|
14
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
// $FlowFixMe
|
|
16
15
|
function objectHash(object) {
|
|
17
16
|
let hash = _crypto().default.createHash('md5');
|
|
18
17
|
for (let key of Object.keys(object).sort()) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function openInBrowser(url: string, browser: string): Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function parseCSSImport(url: string): string;
|
package/lib/path.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { FilePath } from '@atlaspack/types';
|
|
2
|
+
export declare function isAbsolute(filepath: string): boolean;
|
|
3
|
+
export declare function normalizeSeparators(filePath: FilePath): FilePath;
|
|
4
|
+
export type PathOptions = {
|
|
5
|
+
noLeadingDotSlash?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare function normalizePath(filePath: FilePath, leadingDotSlash?: boolean): FilePath;
|
|
8
|
+
export declare function relativePath(from: string, to: string, leadingDotSlash?: boolean): FilePath;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function prettifyTime(timeInMs: number): string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Diagnostic } from '@atlaspack/diagnostic';
|
|
2
|
+
import type { PluginOptions } from '@atlaspack/types';
|
|
3
|
+
export type FormattedCodeFrame = {
|
|
4
|
+
location: string;
|
|
5
|
+
code: string;
|
|
6
|
+
};
|
|
7
|
+
export type AnsiDiagnosticResult = {
|
|
8
|
+
message: string;
|
|
9
|
+
stack: string;
|
|
10
|
+
/** A formatted string containing all code frames, including their file locations. */
|
|
11
|
+
codeframe: string;
|
|
12
|
+
/** A list of code frames with highlighted code and file locations separately. */
|
|
13
|
+
frames: Array<FormattedCodeFrame>;
|
|
14
|
+
hints: Array<string>;
|
|
15
|
+
documentation: string;
|
|
16
|
+
};
|
|
17
|
+
export default function prettyDiagnostic(diagnostic: Diagnostic, options?: PluginOptions, terminalWidth?: number, format?: 'ansi' | 'html'): Promise<AnsiDiagnosticResult>;
|
package/lib/prettyDiagnostic.js
CHANGED
|
@@ -47,10 +47,10 @@ function _snarkdown() {
|
|
|
47
47
|
return data;
|
|
48
48
|
}
|
|
49
49
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
50
|
-
// $FlowFixMe
|
|
51
50
|
/* eslint-disable import/no-extraneous-dependencies */
|
|
52
|
-
|
|
51
|
+
|
|
53
52
|
/* eslint-enable import/no-extraneous-dependencies */
|
|
53
|
+
|
|
54
54
|
async function prettyDiagnostic(diagnostic, options, terminalWidth, format = 'ansi') {
|
|
55
55
|
let {
|
|
56
56
|
origin,
|
|
@@ -94,9 +94,7 @@ async function prettyDiagnostic(diagnostic, options, terminalWidth, format = 'an
|
|
|
94
94
|
formattedCodeFrame = (0, _codeframe().default)(code, highlights, {
|
|
95
95
|
useColor: true,
|
|
96
96
|
syntaxHighlighting: true,
|
|
97
|
-
language:
|
|
98
|
-
// $FlowFixMe sketchy null checks do not matter here...
|
|
99
|
-
codeFrame.language || (filePath != null ? _path().default.extname(filePath).substr(1) : undefined),
|
|
97
|
+
language: codeFrame.language || (filePath != null ? _path().default.extname(filePath).substr(1) : undefined),
|
|
100
98
|
terminalWidth
|
|
101
99
|
});
|
|
102
100
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function relativeUrl(from: string, to: string): string;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type SourceMap from '@parcel/source-map';
|
|
2
|
+
import type { Async, Blob, Bundle, BundleGraph, Dependency, NamedBundle } from '@atlaspack/types';
|
|
3
|
+
export declare function replaceURLReferences({ bundle, bundleGraph, contents, map, getReplacement, relative, }: {
|
|
4
|
+
bundle: NamedBundle;
|
|
5
|
+
bundleGraph: BundleGraph<NamedBundle>;
|
|
6
|
+
contents: string;
|
|
7
|
+
relative?: boolean;
|
|
8
|
+
map?: SourceMap | null | undefined;
|
|
9
|
+
getReplacement?: (arg1: string) => string;
|
|
10
|
+
}): {
|
|
11
|
+
readonly contents: string;
|
|
12
|
+
readonly map: SourceMap | null | undefined;
|
|
13
|
+
};
|
|
14
|
+
export declare function replaceInlineReferences({ bundle, bundleGraph, contents, map, getInlineReplacement, getInlineBundleContents, }: {
|
|
15
|
+
bundle: Bundle;
|
|
16
|
+
bundleGraph: BundleGraph<NamedBundle>;
|
|
17
|
+
contents: string;
|
|
18
|
+
getInlineReplacement: (arg1: Dependency, arg2: 'string' | null | undefined, arg3: string) => {
|
|
19
|
+
from: string;
|
|
20
|
+
to: string;
|
|
21
|
+
};
|
|
22
|
+
getInlineBundleContents: (arg1: Bundle, arg2: BundleGraph<NamedBundle>) => Async<{
|
|
23
|
+
contents: Blob;
|
|
24
|
+
}>;
|
|
25
|
+
map?: SourceMap | null | undefined;
|
|
26
|
+
}): Promise<{
|
|
27
|
+
readonly contents: string;
|
|
28
|
+
readonly map: SourceMap | null | undefined;
|
|
29
|
+
}>;
|
|
30
|
+
export declare function getURLReplacement({ dependency, fromBundle, toBundle, relative, getReplacement, }: {
|
|
31
|
+
dependency: Dependency;
|
|
32
|
+
fromBundle: NamedBundle;
|
|
33
|
+
toBundle: NamedBundle;
|
|
34
|
+
relative: boolean;
|
|
35
|
+
getReplacement?: (arg1: string) => string;
|
|
36
|
+
}): {
|
|
37
|
+
from: string;
|
|
38
|
+
to: string;
|
|
39
|
+
};
|
package/lib/schema.d.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { Mapping } from '@mischnic/json-sourcemap';
|
|
2
|
+
export type SchemaEntity = SchemaObject | SchemaArray | SchemaBoolean | SchemaString | SchemaNumber | SchemaEnum | SchemaOneOf | SchemaAllOf | SchemaNot | SchemaAny;
|
|
3
|
+
export type SchemaArray = {
|
|
4
|
+
type: 'array';
|
|
5
|
+
items?: SchemaEntity;
|
|
6
|
+
__type?: string;
|
|
7
|
+
};
|
|
8
|
+
export type SchemaBoolean = {
|
|
9
|
+
type: 'boolean';
|
|
10
|
+
__type?: string;
|
|
11
|
+
};
|
|
12
|
+
export type SchemaOneOf = {
|
|
13
|
+
oneOf: Array<SchemaEntity>;
|
|
14
|
+
};
|
|
15
|
+
export type SchemaAllOf = {
|
|
16
|
+
allOf: Array<SchemaEntity>;
|
|
17
|
+
};
|
|
18
|
+
export type SchemaNot = {
|
|
19
|
+
not: SchemaEntity;
|
|
20
|
+
__message: string;
|
|
21
|
+
};
|
|
22
|
+
export type SchemaString = {
|
|
23
|
+
type: 'string';
|
|
24
|
+
enum?: Array<string>;
|
|
25
|
+
__validate?: (val: string) => string | null | undefined;
|
|
26
|
+
__type?: string;
|
|
27
|
+
};
|
|
28
|
+
export type SchemaNumber = {
|
|
29
|
+
type: 'number';
|
|
30
|
+
enum?: Array<number>;
|
|
31
|
+
__type?: string;
|
|
32
|
+
};
|
|
33
|
+
export type SchemaEnum = {
|
|
34
|
+
enum: Array<unknown>;
|
|
35
|
+
};
|
|
36
|
+
export type SchemaObject = {
|
|
37
|
+
type: 'object';
|
|
38
|
+
properties: {
|
|
39
|
+
[key: string]: SchemaEntity;
|
|
40
|
+
};
|
|
41
|
+
additionalProperties?: boolean | SchemaEntity;
|
|
42
|
+
required?: Array<string>;
|
|
43
|
+
__forbiddenProperties?: Array<string>;
|
|
44
|
+
__type?: string;
|
|
45
|
+
};
|
|
46
|
+
export type SchemaAny = Record<any, any>;
|
|
47
|
+
export type SchemaError = {
|
|
48
|
+
type: 'type';
|
|
49
|
+
expectedTypes: Array<string>;
|
|
50
|
+
dataType: 'key' | null | undefined | 'value';
|
|
51
|
+
dataPath: string;
|
|
52
|
+
ancestors: Array<SchemaEntity>;
|
|
53
|
+
prettyType?: string;
|
|
54
|
+
} | {
|
|
55
|
+
type: 'enum';
|
|
56
|
+
expectedValues: Array<unknown>;
|
|
57
|
+
dataType: 'key' | 'value';
|
|
58
|
+
actualValue: unknown;
|
|
59
|
+
dataPath: string;
|
|
60
|
+
ancestors: Array<SchemaEntity>;
|
|
61
|
+
prettyType?: string;
|
|
62
|
+
} | {
|
|
63
|
+
type: 'forbidden-prop';
|
|
64
|
+
prop: string;
|
|
65
|
+
expectedProps: Array<string>;
|
|
66
|
+
actualProps: Array<string>;
|
|
67
|
+
dataType: 'key';
|
|
68
|
+
dataPath: string;
|
|
69
|
+
ancestors: Array<SchemaEntity>;
|
|
70
|
+
prettyType?: string;
|
|
71
|
+
} | {
|
|
72
|
+
type: 'missing-prop';
|
|
73
|
+
prop: string;
|
|
74
|
+
expectedProps: Array<string>;
|
|
75
|
+
actualProps: Array<string>;
|
|
76
|
+
dataType: 'key' | 'value';
|
|
77
|
+
dataPath: string;
|
|
78
|
+
ancestors: Array<SchemaEntity>;
|
|
79
|
+
prettyType?: string;
|
|
80
|
+
} | {
|
|
81
|
+
type: 'other';
|
|
82
|
+
actualValue: unknown;
|
|
83
|
+
dataType: 'key' | null | undefined | 'value';
|
|
84
|
+
message?: string;
|
|
85
|
+
dataPath: string;
|
|
86
|
+
ancestors: Array<SchemaEntity>;
|
|
87
|
+
};
|
|
88
|
+
declare function validateSchema(schema: SchemaEntity, data: unknown): Array<SchemaError>;
|
|
89
|
+
declare namespace validateSchema {
|
|
90
|
+
var diagnostic: (schema: SchemaEntity, data: ({
|
|
91
|
+
source?: string | null | undefined;
|
|
92
|
+
data?: unknown;
|
|
93
|
+
} | {
|
|
94
|
+
source: string;
|
|
95
|
+
map: {
|
|
96
|
+
data: unknown;
|
|
97
|
+
pointers: {
|
|
98
|
+
[key: string]: Mapping;
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
}) & {
|
|
102
|
+
filePath?: string | null | undefined;
|
|
103
|
+
prependKey?: string | null | undefined;
|
|
104
|
+
}, origin: string, message: string) => undefined;
|
|
105
|
+
}
|
|
106
|
+
export default validateSchema;
|
|
107
|
+
export declare function fuzzySearch(expectedValues: Array<string>, actualValue: string): Array<string>;
|
package/lib/schema.js
CHANGED
|
@@ -30,7 +30,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
30
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
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
32
|
function validateSchema(schema, data) {
|
|
33
|
-
function walk(
|
|
33
|
+
function walk(
|
|
34
|
+
// @ts-expect-error TS7006
|
|
35
|
+
schemaAncestors, dataNode, dataPath) {
|
|
34
36
|
let [schemaNode] = schemaAncestors;
|
|
35
37
|
if (schemaNode.type) {
|
|
36
38
|
let type = Array.isArray(dataNode) ? 'array' : typeof dataNode;
|
|
@@ -49,10 +51,10 @@ function validateSchema(schema, data) {
|
|
|
49
51
|
{
|
|
50
52
|
if (schemaNode.items) {
|
|
51
53
|
let results = [];
|
|
52
|
-
//
|
|
54
|
+
// @ts-expect-error TS18046
|
|
53
55
|
for (let i = 0; i < dataNode.length; i++) {
|
|
54
56
|
let result = walk([schemaNode.items].concat(schemaAncestors),
|
|
55
|
-
//
|
|
57
|
+
// @ts-expect-error TS18046
|
|
56
58
|
dataNode[i], dataPath + '/' + i);
|
|
57
59
|
if (result) results.push(result);
|
|
58
60
|
}
|
|
@@ -62,7 +64,7 @@ function validateSchema(schema, data) {
|
|
|
62
64
|
}
|
|
63
65
|
case 'string':
|
|
64
66
|
{
|
|
65
|
-
//
|
|
67
|
+
// @ts-expect-error TS2322
|
|
66
68
|
let value = dataNode;
|
|
67
69
|
if (schemaNode.enum) {
|
|
68
70
|
if (!schemaNode.enum.includes(value)) {
|
|
@@ -92,7 +94,7 @@ function validateSchema(schema, data) {
|
|
|
92
94
|
}
|
|
93
95
|
case 'number':
|
|
94
96
|
{
|
|
95
|
-
//
|
|
97
|
+
// @ts-expect-error TS2322
|
|
96
98
|
let value = dataNode;
|
|
97
99
|
if (schemaNode.enum) {
|
|
98
100
|
if (!schemaNode.enum.includes(value)) {
|
|
@@ -113,10 +115,13 @@ function validateSchema(schema, data) {
|
|
|
113
115
|
let results = [];
|
|
114
116
|
let invalidProps;
|
|
115
117
|
if (schemaNode.__forbiddenProperties) {
|
|
116
|
-
//
|
|
118
|
+
// @ts-expect-error TS2769
|
|
117
119
|
let keys = Object.keys(dataNode);
|
|
120
|
+
// @ts-expect-error TS7006
|
|
118
121
|
invalidProps = schemaNode.__forbiddenProperties.filter(val => keys.includes(val));
|
|
119
|
-
results.push(...invalidProps.map(
|
|
122
|
+
results.push(...invalidProps.map(
|
|
123
|
+
// @ts-expect-error TS7006
|
|
124
|
+
k => ({
|
|
120
125
|
type: 'forbidden-prop',
|
|
121
126
|
dataPath: dataPath + '/' + (0, _diagnostic().encodeJSONKeyComponent)(k),
|
|
122
127
|
dataType: 'key',
|
|
@@ -127,10 +132,14 @@ function validateSchema(schema, data) {
|
|
|
127
132
|
})));
|
|
128
133
|
}
|
|
129
134
|
if (schemaNode.required) {
|
|
130
|
-
//
|
|
135
|
+
// @ts-expect-error TS2769
|
|
131
136
|
let keys = Object.keys(dataNode);
|
|
132
|
-
let missingKeys = schemaNode.required.filter(
|
|
133
|
-
|
|
137
|
+
let missingKeys = schemaNode.required.filter(
|
|
138
|
+
// @ts-expect-error TS7006
|
|
139
|
+
val => !keys.includes(val));
|
|
140
|
+
results.push(...missingKeys.map(
|
|
141
|
+
// @ts-expect-error TS7006
|
|
142
|
+
k => ({
|
|
134
143
|
type: 'missing-prop',
|
|
135
144
|
dataPath,
|
|
136
145
|
dataType: 'value',
|
|
@@ -144,14 +153,14 @@ function validateSchema(schema, data) {
|
|
|
144
153
|
let {
|
|
145
154
|
additionalProperties = true
|
|
146
155
|
} = schemaNode;
|
|
147
|
-
//
|
|
156
|
+
// @ts-expect-error TS2407
|
|
148
157
|
for (let k in dataNode) {
|
|
149
158
|
if (invalidProps && invalidProps.includes(k)) {
|
|
150
159
|
// Don't check type on forbidden props
|
|
151
160
|
continue;
|
|
152
161
|
} else if (k in schemaNode.properties) {
|
|
153
162
|
let result = walk([schemaNode.properties[k]].concat(schemaAncestors),
|
|
154
|
-
//
|
|
163
|
+
// @ts-expect-error TS18046
|
|
155
164
|
dataNode[k], dataPath + '/' + (0, _diagnostic().encodeJSONKeyComponent)(k));
|
|
156
165
|
if (result) results.push(result);
|
|
157
166
|
} else {
|
|
@@ -161,9 +170,9 @@ function validateSchema(schema, data) {
|
|
|
161
170
|
type: 'enum',
|
|
162
171
|
dataType: 'key',
|
|
163
172
|
dataPath: dataPath + '/' + (0, _diagnostic().encodeJSONKeyComponent)(k),
|
|
164
|
-
expectedValues: Object.keys(schemaNode.properties
|
|
165
|
-
//
|
|
166
|
-
p => !(p in dataNode)),
|
|
173
|
+
expectedValues: Object.keys(schemaNode.properties
|
|
174
|
+
// @ts-expect-error TS18046
|
|
175
|
+
).filter(p => !(p in dataNode)),
|
|
167
176
|
actualValue: k,
|
|
168
177
|
ancestors: schemaAncestors,
|
|
169
178
|
prettyType: schemaNode.__type
|
|
@@ -171,7 +180,7 @@ function validateSchema(schema, data) {
|
|
|
171
180
|
}
|
|
172
181
|
} else {
|
|
173
182
|
let result = walk([additionalProperties].concat(schemaAncestors),
|
|
174
|
-
//
|
|
183
|
+
// @ts-expect-error TS18046
|
|
175
184
|
dataNode[k], dataPath + '/' + (0, _diagnostic().encodeJSONKeyComponent)(k));
|
|
176
185
|
if (result) results.push(result);
|
|
177
186
|
}
|
|
@@ -213,6 +222,7 @@ function validateSchema(schema, data) {
|
|
|
213
222
|
}
|
|
214
223
|
} else if (schemaNode.not) {
|
|
215
224
|
let result = walk([schemaNode.not].concat(schemaAncestors), dataNode, dataPath);
|
|
225
|
+
// @ts-expect-error TS2339
|
|
216
226
|
if (!result || result.length == 0) {
|
|
217
227
|
return {
|
|
218
228
|
type: 'other',
|
|
@@ -234,16 +244,22 @@ var _default = exports.default = validateSchema;
|
|
|
234
244
|
function fuzzySearch(expectedValues, actualValue) {
|
|
235
245
|
let result = expectedValues.map(exp => [exp, levenshtein().distance(exp, actualValue)]).filter(
|
|
236
246
|
// Remove if more than half of the string would need to be changed
|
|
247
|
+
// @ts-expect-error TS2769
|
|
237
248
|
([, d]) => d * 2 < actualValue.length);
|
|
249
|
+
// @ts-expect-error TS2345
|
|
238
250
|
result.sort(([, a], [, b]) => a - b);
|
|
251
|
+
// @ts-expect-error TS2345
|
|
239
252
|
return result.map(([v]) => v);
|
|
240
253
|
}
|
|
241
254
|
validateSchema.diagnostic = function (schema, data, origin, message) {
|
|
242
255
|
if ('source' in data && 'data' in data && typeof data.source !== 'string' && !data) {
|
|
243
256
|
throw new Error('At least one of data.source and data.data must be defined!');
|
|
244
257
|
}
|
|
245
|
-
|
|
246
|
-
|
|
258
|
+
// @ts-expect-error TS2339
|
|
259
|
+
let object = data.map ?
|
|
260
|
+
// @ts-expect-error TS2339
|
|
261
|
+
data.map.data :
|
|
262
|
+
// @ts-expect-error TS2339
|
|
247
263
|
data.data ?? JSON.parse(data.source);
|
|
248
264
|
let errors = validateSchema(schema, object);
|
|
249
265
|
if (errors.length) {
|
|
@@ -303,11 +319,13 @@ validateSchema.diagnostic = function (schema, data, origin, message) {
|
|
|
303
319
|
};
|
|
304
320
|
});
|
|
305
321
|
let map, code;
|
|
322
|
+
// @ts-expect-error TS2339
|
|
306
323
|
if (data.map) {
|
|
324
|
+
// @ts-expect-error TS2339
|
|
307
325
|
map = data.map;
|
|
308
326
|
code = data.source;
|
|
309
327
|
} else {
|
|
310
|
-
//
|
|
328
|
+
// @ts-expect-error TS2339
|
|
311
329
|
map = data.source ?? JSON.stringify((0, _nullthrows().default)(data.data), 0, '\t');
|
|
312
330
|
code = map;
|
|
313
331
|
}
|
|
@@ -329,6 +347,7 @@ validateSchema.diagnostic = function (schema, data, origin, message) {
|
|
|
329
347
|
diagnostic: {
|
|
330
348
|
message: message,
|
|
331
349
|
origin,
|
|
350
|
+
// @ts-expect-error TS2322
|
|
332
351
|
codeFrames
|
|
333
352
|
}
|
|
334
353
|
});
|
package/lib/shared-buffer.js
CHANGED
|
@@ -4,9 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.SharedBuffer = void 0;
|
|
7
|
+
// flow-to-ts helpers
|
|
8
|
+
|
|
9
|
+
// /flow-to-ts helpers
|
|
10
|
+
|
|
7
11
|
let SharedBuffer = exports.SharedBuffer = void 0;
|
|
8
12
|
|
|
9
|
-
//
|
|
13
|
+
// @ts-expect-error process.browser is a browser-specific property
|
|
10
14
|
if (process.browser) {
|
|
11
15
|
exports.SharedBuffer = SharedBuffer = ArrayBuffer;
|
|
12
16
|
// Safari has removed the constructor
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { SourceLocation } from '@atlaspack/types';
|
|
2
|
+
import type { FileSystem } from '@atlaspack/fs';
|
|
3
|
+
import SourceMap from '@parcel/source-map';
|
|
4
|
+
export declare const SOURCEMAP_RE: RegExp;
|
|
5
|
+
export declare const SOURCEMAP_EXTENSIONS: Set<string>;
|
|
6
|
+
export declare function matchSourceMappingURL(contents: string): RegExpMatchArray | null;
|
|
7
|
+
export declare function loadSourceMapUrl(fs: FileSystem, filename: string, contents: string): Promise<{
|
|
8
|
+
filename: string;
|
|
9
|
+
map: any;
|
|
10
|
+
url: string;
|
|
11
|
+
} | null | undefined>;
|
|
12
|
+
export declare function loadSourceMap(filename: string, contents: string, options: {
|
|
13
|
+
fs: FileSystem;
|
|
14
|
+
projectRoot: string;
|
|
15
|
+
}): Promise<SourceMap | null | undefined>;
|
|
16
|
+
export declare function remapSourceLocation(loc: SourceLocation, originalMap: SourceMap): SourceLocation;
|
package/lib/stream.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Readable } from 'stream';
|
|
2
|
+
import type { Blob } from '@atlaspack/types';
|
|
3
|
+
export declare function measureStreamLength(stream: Readable): Promise<number>;
|
|
4
|
+
export declare function readableFromStringOrBuffer(str: string | Buffer): Readable;
|
|
5
|
+
export declare function bufferStream(stream: Readable): Promise<Buffer>;
|
|
6
|
+
export declare function blobToStream(blob: Blob): Readable;
|
|
7
|
+
export declare function streamFromPromise(promise: Promise<Blob>): Readable;
|
|
8
|
+
export declare function fallbackStream(stream: Readable, fallback: () => Readable): Readable;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function throttle<TArgs extends Array<unknown>>(fn: (...args: TArgs) => unknown, delay: number): (...args: TArgs) => void;
|
package/lib/urlJoin.d.ts
ADDED
package/lib/urlJoin.js
CHANGED
|
@@ -28,7 +28,7 @@ function urlJoin(publicURL, assetPath) {
|
|
|
28
28
|
// Leading / ensures that paths with colons are not parsed as a protocol.
|
|
29
29
|
let p = assetPath.startsWith('/') ? assetPath : '/' + assetPath;
|
|
30
30
|
const assetUrl = _url().default.parse(p);
|
|
31
|
-
url.pathname = _path().default.posix.join(url.pathname, assetUrl.pathname);
|
|
31
|
+
url.pathname = _path().default.posix.join(url.pathname ?? '', assetUrl.pathname ?? '');
|
|
32
32
|
url.search = assetUrl.search;
|
|
33
33
|
url.hash = assetUrl.hash;
|
|
34
34
|
return _url().default.format(url);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/utils",
|
|
3
|
-
"version": "2.14.5-canary.
|
|
3
|
+
"version": "2.14.5-canary.139+d2fd84977",
|
|
4
4
|
"description": "Blazing fast, zero configuration web application bundler",
|
|
5
5
|
"license": "(MIT OR Apache-2.0)",
|
|
6
6
|
"publishConfig": {
|
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "https://github.com/atlassian-labs/atlaspack.git"
|
|
12
12
|
},
|
|
13
|
-
"main": "lib/index.js",
|
|
14
|
-
"source": "src/index.
|
|
13
|
+
"main": "./lib/index.js",
|
|
14
|
+
"source": "./src/index.ts",
|
|
15
|
+
"types": "./lib/index.d.ts",
|
|
15
16
|
"engines": {
|
|
16
17
|
"node": ">= 16.0.0"
|
|
17
18
|
},
|
|
@@ -30,14 +31,16 @@
|
|
|
30
31
|
}
|
|
31
32
|
},
|
|
32
33
|
"dependencies": {
|
|
33
|
-
"@atlaspack/codeframe": "2.13.3-canary.
|
|
34
|
-
"@atlaspack/diagnostic": "2.14.1-canary.
|
|
35
|
-
"@atlaspack/feature-flags": "2.14.1-canary.
|
|
36
|
-
"@atlaspack/logger": "2.14.5-canary.
|
|
37
|
-
"@atlaspack/markdown-ansi": "2.14.1-canary.
|
|
38
|
-
"@atlaspack/rust": "3.2.1-canary.
|
|
34
|
+
"@atlaspack/codeframe": "2.13.3-canary.207+d2fd84977",
|
|
35
|
+
"@atlaspack/diagnostic": "2.14.1-canary.207+d2fd84977",
|
|
36
|
+
"@atlaspack/feature-flags": "2.14.1-canary.207+d2fd84977",
|
|
37
|
+
"@atlaspack/logger": "2.14.5-canary.139+d2fd84977",
|
|
38
|
+
"@atlaspack/markdown-ansi": "2.14.1-canary.207+d2fd84977",
|
|
39
|
+
"@atlaspack/rust": "3.2.1-canary.139+d2fd84977",
|
|
39
40
|
"@iarna/toml": "^2.2.0",
|
|
40
41
|
"@parcel/source-map": "^2.1.1",
|
|
42
|
+
"@types/micromatch": "^4.0.9",
|
|
43
|
+
"@types/node-forge": "^1.3.13",
|
|
41
44
|
"ansi-html-community": "0.0.8",
|
|
42
45
|
"chalk": "^4.1.0",
|
|
43
46
|
"clone": "^2.1.1",
|
|
@@ -67,5 +70,8 @@
|
|
|
67
70
|
"@atlaspack/markdown-ansi": false
|
|
68
71
|
},
|
|
69
72
|
"type": "commonjs",
|
|
70
|
-
"
|
|
71
|
-
|
|
73
|
+
"scripts": {
|
|
74
|
+
"check-ts": "tsc --emitDeclarationOnly --rootDir src"
|
|
75
|
+
},
|
|
76
|
+
"gitHead": "d2fd849770fe6305e9c694bd97b1bd905abd9d94"
|
|
77
|
+
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
|
-
|
|
3
1
|
export class DefaultMap<K, V> extends Map<K, V> {
|
|
4
|
-
_getDefault: (K) => V;
|
|
2
|
+
_getDefault: (arg1: K) => V;
|
|
5
3
|
|
|
6
|
-
constructor(getDefault: (K) => V, entries?: Iterable<[K, V]>) {
|
|
4
|
+
constructor(getDefault: (arg1: K) => V, entries?: Iterable<[K, V]>) {
|
|
7
5
|
super(entries);
|
|
8
6
|
this._getDefault = getDefault;
|
|
9
7
|
}
|
|
@@ -17,8 +15,7 @@ export class DefaultMap<K, V> extends Map<K, V> {
|
|
|
17
15
|
this.set(key, ret);
|
|
18
16
|
}
|
|
19
17
|
|
|
20
|
-
|
|
21
|
-
return ret;
|
|
18
|
+
return ret as V;
|
|
22
19
|
}
|
|
23
20
|
}
|
|
24
21
|
|
|
@@ -26,11 +23,11 @@ interface Key {}
|
|
|
26
23
|
|
|
27
24
|
// Duplicated from DefaultMap implementation for Flow
|
|
28
25
|
// Roughly mirrors https://github.com/facebook/flow/blob/2eb5a78d92c167117ba9caae070afd2b9f598599/lib/core.js#L617
|
|
29
|
-
export class DefaultWeakMap<K
|
|
30
|
-
_getDefault: (K) => V;
|
|
26
|
+
export class DefaultWeakMap<K extends Key, V> extends WeakMap<K, V> {
|
|
27
|
+
_getDefault: (arg1: K) => V;
|
|
31
28
|
|
|
32
|
-
constructor(getDefault: (K) => V, entries?: Iterable<[K, V]>) {
|
|
33
|
-
super(entries);
|
|
29
|
+
constructor(getDefault: (arg1: K) => V, entries?: Iterable<[K, V]>) {
|
|
30
|
+
super(entries as Iterable<readonly [K, V]>);
|
|
34
31
|
this._getDefault = getDefault;
|
|
35
32
|
}
|
|
36
33
|
|
|
@@ -43,7 +40,6 @@ export class DefaultWeakMap<K: Key, V> extends WeakMap<K, V> {
|
|
|
43
40
|
this.set(key, ret);
|
|
44
41
|
}
|
|
45
42
|
|
|
46
|
-
|
|
47
|
-
return ret;
|
|
43
|
+
return ret as V;
|
|
48
44
|
}
|
|
49
45
|
}
|
package/src/Deferred.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import invariant from 'assert';
|
|
2
|
+
|
|
3
|
+
export type Deferred<T> = {
|
|
4
|
+
resolve(arg1: T): void;
|
|
5
|
+
reject(arg1: unknown): void;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export function makeDeferredWithPromise<T>(): {
|
|
9
|
+
deferred: Deferred<T>;
|
|
10
|
+
promise: Promise<T>;
|
|
11
|
+
} {
|
|
12
|
+
let deferred: Deferred<T> | null | undefined;
|
|
13
|
+
let promise = new Promise<T>(
|
|
14
|
+
(
|
|
15
|
+
resolve: (result: Promise<T> | T) => void,
|
|
16
|
+
reject: (error?: any) => void,
|
|
17
|
+
) => {
|
|
18
|
+
deferred = {resolve, reject};
|
|
19
|
+
},
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
// Promise constructor callback executes synchronously, so this is defined
|
|
23
|
+
invariant(deferred != null);
|
|
24
|
+
|
|
25
|
+
return {deferred, promise};
|
|
26
|
+
}
|