@atlaspack/utils 2.14.5-canary.14 → 2.14.5-canary.140
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 +146 -0
- package/benchmark.js +23 -0
- package/lib/DefaultMap.d.ts +13 -0
- package/lib/DefaultMap.js +42 -0
- package/lib/Deferred.d.ts +8 -0
- package/lib/Deferred.js +30 -0
- package/lib/PromiseQueue.d.ts +25 -0
- package/lib/PromiseQueue.js +112 -0
- package/lib/TapStream.d.ts +6 -0
- package/lib/TapStream.js +34 -0
- package/lib/alternatives.d.ts +3 -0
- package/lib/alternatives.js +116 -0
- package/lib/ansi-html.d.ts +1 -0
- package/lib/ansi-html.js +20 -0
- package/lib/blob.d.ts +4 -0
- package/lib/blob.js +40 -0
- package/lib/bundle-url.d.ts +4 -0
- package/lib/bundle-url.js +34 -0
- package/lib/collection.d.ts +33 -0
- package/lib/collection.js +111 -0
- package/lib/config.d.ts +17 -0
- package/lib/config.js +174 -0
- package/lib/countLines.d.ts +1 -0
- package/lib/countLines.js +15 -0
- package/lib/debounce.d.ts +1 -0
- package/lib/debounce.js +18 -0
- package/lib/debug-tools.d.ts +6 -0
- package/lib/debug-tools.js +37 -0
- package/lib/dependency-location.d.ts +14 -0
- package/lib/dependency-location.js +21 -0
- package/lib/escape-html.d.ts +1 -0
- package/lib/escape-html.js +22 -0
- package/lib/generateBuildMetrics.d.ts +18 -0
- package/lib/generateBuildMetrics.js +121 -0
- package/lib/generateCertificate.d.ts +5 -0
- package/lib/generateCertificate.js +129 -0
- package/lib/getCertificate.d.ts +6 -0
- package/lib/getCertificate.js +18 -0
- package/lib/getExisting.d.ts +8 -0
- package/lib/getExisting.js +25 -0
- package/lib/getModuleParts.d.ts +4 -0
- package/lib/getModuleParts.js +30 -0
- package/lib/getRootDir.d.ts +2 -0
- package/lib/getRootDir.js +52 -0
- package/lib/glob.d.ts +10 -0
- package/lib/glob.js +118 -0
- package/lib/hash.d.ts +7 -0
- package/lib/hash.js +50 -0
- package/lib/http-server.d.ts +19 -0
- package/lib/http-server.js +85 -0
- package/lib/index.d.ts +48 -0
- package/lib/index.js +635 -37310
- package/lib/is-url.d.ts +1 -0
- package/lib/is-url.js +24 -0
- package/lib/isDirectoryInside.d.ts +2 -0
- package/lib/isDirectoryInside.js +18 -0
- package/lib/objectHash.d.ts +3 -0
- package/lib/objectHash.js +26 -0
- package/lib/openInBrowser.d.ts +1 -0
- package/lib/openInBrowser.js +74 -0
- package/lib/parseCSSImport.d.ts +1 -0
- package/lib/parseCSSImport.js +15 -0
- package/lib/path.d.ts +8 -0
- package/lib/path.js +39 -0
- package/lib/prettifyTime.d.ts +1 -0
- package/lib/prettifyTime.js +9 -0
- package/lib/prettyDiagnostic.d.ts +17 -0
- package/lib/prettyDiagnostic.js +134 -0
- package/lib/progress-message.d.ts +3 -0
- package/lib/progress-message.js +36 -0
- package/lib/relativeBundlePath.d.ts +4 -0
- package/lib/relativeBundlePath.js +22 -0
- package/lib/relativeUrl.d.ts +1 -0
- package/lib/relativeUrl.js +24 -0
- package/lib/replaceBundleReferences.d.ts +39 -0
- package/lib/replaceBundleReferences.js +199 -0
- package/lib/schema.d.ts +107 -0
- package/lib/schema.js +355 -0
- package/lib/shared-buffer.d.ts +2 -0
- package/lib/shared-buffer.js +31 -0
- package/lib/sourcemap.d.ts +16 -0
- package/lib/sourcemap.js +127 -0
- package/lib/stream.d.ts +8 -0
- package/lib/stream.js +76 -0
- package/lib/throttle.d.ts +1 -0
- package/lib/throttle.js +15 -0
- package/lib/urlJoin.d.ts +5 -0
- package/lib/urlJoin.js +35 -0
- package/package.json +24 -17
- 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} +23 -20
- 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.ts +43 -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} +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} +13 -9
- 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.ts +38 -0
- 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/lib/index.js.map +0 -1
- package/src/Deferred.js +0 -23
- package/src/progress-message.js +0 -22
- package/src/throttle.js +0 -15
|
@@ -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/sourcemap.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
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 _sourceMap() {
|
|
12
|
+
const data = _interopRequireDefault(require("@parcel/source-map"));
|
|
13
|
+
_sourceMap = function () {
|
|
14
|
+
return data;
|
|
15
|
+
};
|
|
16
|
+
return data;
|
|
17
|
+
}
|
|
18
|
+
function _path() {
|
|
19
|
+
const data = _interopRequireDefault(require("path"));
|
|
20
|
+
_path = function () {
|
|
21
|
+
return data;
|
|
22
|
+
};
|
|
23
|
+
return data;
|
|
24
|
+
}
|
|
25
|
+
var _path2 = require("./path");
|
|
26
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
|
+
const SOURCEMAP_RE = exports.SOURCEMAP_RE = /(?:\/\*|\/\/)\s*[@#]\s*sourceMappingURL\s*=\s*([^\s*]+)(?:\s*\*\/)?\s*$/;
|
|
28
|
+
const DATA_URL_RE = /^data:[^;]+(?:;charset=[^;]+)?;base64,(.*)/;
|
|
29
|
+
const SOURCEMAP_EXTENSIONS = exports.SOURCEMAP_EXTENSIONS = new Set(['css', 'es', 'es6', 'js', 'jsx', 'mjs', 'ts', 'tsx']);
|
|
30
|
+
function matchSourceMappingURL(contents) {
|
|
31
|
+
return contents.match(SOURCEMAP_RE);
|
|
32
|
+
}
|
|
33
|
+
async function loadSourceMapUrl(fs, filename, contents) {
|
|
34
|
+
let match = matchSourceMappingURL(contents);
|
|
35
|
+
if (match) {
|
|
36
|
+
let url = match[1].trim();
|
|
37
|
+
let dataURLMatch = url.match(DATA_URL_RE);
|
|
38
|
+
let mapFilePath;
|
|
39
|
+
if (dataURLMatch) {
|
|
40
|
+
mapFilePath = filename;
|
|
41
|
+
} else {
|
|
42
|
+
mapFilePath = url.replace(/^file:\/\//, '');
|
|
43
|
+
mapFilePath = (0, _path2.isAbsolute)(mapFilePath) ? mapFilePath : _path().default.join(_path().default.dirname(filename), mapFilePath);
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
url,
|
|
47
|
+
filename: mapFilePath,
|
|
48
|
+
map: JSON.parse(dataURLMatch ? Buffer.from(dataURLMatch[1], 'base64').toString() : await fs.readFile(mapFilePath, 'utf8'))
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async function loadSourceMap(filename, contents, options) {
|
|
53
|
+
let foundMap = await loadSourceMapUrl(options.fs, filename, contents);
|
|
54
|
+
if (foundMap) {
|
|
55
|
+
let mapSourceRoot = _path().default.dirname(filename);
|
|
56
|
+
if (foundMap.map.sourceRoot && !(0, _path2.normalizeSeparators)(foundMap.map.sourceRoot).startsWith('/')) {
|
|
57
|
+
mapSourceRoot = _path().default.join(mapSourceRoot, foundMap.map.sourceRoot);
|
|
58
|
+
}
|
|
59
|
+
let sourcemapInstance = new (_sourceMap().default)(options.projectRoot);
|
|
60
|
+
sourcemapInstance.addVLQMap({
|
|
61
|
+
...foundMap.map,
|
|
62
|
+
sources: foundMap.map.sources.map(s => {
|
|
63
|
+
return _path().default.join(mapSourceRoot, s);
|
|
64
|
+
})
|
|
65
|
+
});
|
|
66
|
+
return sourcemapInstance;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function remapSourceLocation(loc, originalMap) {
|
|
70
|
+
let {
|
|
71
|
+
filePath,
|
|
72
|
+
start: {
|
|
73
|
+
line: startLine,
|
|
74
|
+
column: startCol
|
|
75
|
+
},
|
|
76
|
+
end: {
|
|
77
|
+
line: endLine,
|
|
78
|
+
column: endCol
|
|
79
|
+
}
|
|
80
|
+
} = loc;
|
|
81
|
+
let lineDiff = endLine - startLine;
|
|
82
|
+
let colDiff = endCol - startCol;
|
|
83
|
+
let start = originalMap.findClosestMapping(startLine, startCol - 1);
|
|
84
|
+
let end = originalMap.findClosestMapping(endLine, endCol - 1);
|
|
85
|
+
if (start !== null && start !== void 0 && start.original) {
|
|
86
|
+
if (start.source) {
|
|
87
|
+
filePath = start.source;
|
|
88
|
+
}
|
|
89
|
+
({
|
|
90
|
+
line: startLine,
|
|
91
|
+
column: startCol
|
|
92
|
+
} = start.original);
|
|
93
|
+
startCol++; // source map columns are 0-based
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (end !== null && end !== void 0 && end.original) {
|
|
97
|
+
({
|
|
98
|
+
line: endLine,
|
|
99
|
+
column: endCol
|
|
100
|
+
} = end.original);
|
|
101
|
+
endCol++; // source map columns are 0-based
|
|
102
|
+
|
|
103
|
+
if (endLine < startLine) {
|
|
104
|
+
endLine = startLine;
|
|
105
|
+
endCol = startCol;
|
|
106
|
+
} else if (endLine === startLine && endCol < startCol && lineDiff === 0) {
|
|
107
|
+
endCol = startCol + colDiff;
|
|
108
|
+
} else if (endLine === startLine && startCol === endCol && lineDiff === 0) {
|
|
109
|
+
// Prevent 0-length ranges
|
|
110
|
+
endCol = startCol + 1;
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
endLine = startLine;
|
|
114
|
+
endCol = startCol;
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
filePath,
|
|
118
|
+
start: {
|
|
119
|
+
line: startLine,
|
|
120
|
+
column: startCol
|
|
121
|
+
},
|
|
122
|
+
end: {
|
|
123
|
+
line: endLine,
|
|
124
|
+
column: endCol
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
}
|
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;
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function throttle<TArgs extends Array<unknown>>(fn: (...args: TArgs) => unknown, delay: number): (...args: TArgs) => void;
|
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
|
+
}
|
package/lib/urlJoin.d.ts
ADDED
package/lib/urlJoin.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = urlJoin;
|
|
7
|
+
function _url() {
|
|
8
|
+
const data = _interopRequireDefault(require("url"));
|
|
9
|
+
_url = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
function _path() {
|
|
15
|
+
const data = _interopRequireDefault(require("path"));
|
|
16
|
+
_path = function () {
|
|
17
|
+
return data;
|
|
18
|
+
};
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
|
+
/**
|
|
23
|
+
* Joins a path onto a URL, and normalizes Windows paths
|
|
24
|
+
* e.g. from \path\to\res.js to /path/to/res.js.
|
|
25
|
+
*/
|
|
26
|
+
function urlJoin(publicURL, assetPath) {
|
|
27
|
+
const url = _url().default.parse(publicURL, false, true);
|
|
28
|
+
// Leading / ensures that paths with colons are not parsed as a protocol.
|
|
29
|
+
let p = assetPath.startsWith('/') ? assetPath : '/' + assetPath;
|
|
30
|
+
const assetUrl = _url().default.parse(p);
|
|
31
|
+
url.pathname = _path().default.posix.join(url.pathname ?? '', assetUrl.pathname ?? '');
|
|
32
|
+
url.search = assetUrl.search;
|
|
33
|
+
url.hash = assetUrl.hash;
|
|
34
|
+
return _url().default.format(url);
|
|
35
|
+
}
|
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.140+43fdd2238",
|
|
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,19 +31,18 @@
|
|
|
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.
|
|
39
|
-
"@parcel/source-map": "^2.1.1",
|
|
40
|
-
"chalk": "^4.1.0",
|
|
41
|
-
"nullthrows": "^1.1.1"
|
|
42
|
-
},
|
|
43
|
-
"devDependencies": {
|
|
34
|
+
"@atlaspack/codeframe": "2.13.3-canary.208+43fdd2238",
|
|
35
|
+
"@atlaspack/diagnostic": "2.14.1-canary.208+43fdd2238",
|
|
36
|
+
"@atlaspack/feature-flags": "2.14.1-canary.208+43fdd2238",
|
|
37
|
+
"@atlaspack/logger": "2.14.5-canary.140+43fdd2238",
|
|
38
|
+
"@atlaspack/markdown-ansi": "2.14.1-canary.208+43fdd2238",
|
|
39
|
+
"@atlaspack/rust": "3.2.1-canary.140+43fdd2238",
|
|
44
40
|
"@iarna/toml": "^2.2.0",
|
|
41
|
+
"@parcel/source-map": "^2.1.1",
|
|
42
|
+
"@types/micromatch": "^4.0.9",
|
|
43
|
+
"@types/node-forge": "^1.3.13",
|
|
45
44
|
"ansi-html-community": "0.0.8",
|
|
45
|
+
"chalk": "^4.1.0",
|
|
46
46
|
"clone": "^2.1.1",
|
|
47
47
|
"fast-glob": "^3.2.12",
|
|
48
48
|
"fastest-levenshtein": "^1.0.16",
|
|
@@ -54,11 +54,15 @@
|
|
|
54
54
|
"node-forge": "^1.2.1",
|
|
55
55
|
"nullthrows": "^1.1.1",
|
|
56
56
|
"open": "^7.0.3",
|
|
57
|
-
"random-int": "^1.0.0",
|
|
58
57
|
"snarkdown": "^2.0.0",
|
|
59
58
|
"strip-ansi": "^6.0.0",
|
|
60
59
|
"terminal-link": "^2.1.1"
|
|
61
60
|
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@atlaspack/babel-register": "2.14.1",
|
|
63
|
+
"benny": "^3.7.1",
|
|
64
|
+
"random-int": "^1.0.0"
|
|
65
|
+
},
|
|
62
66
|
"browser": {
|
|
63
67
|
"./src/generateCertificate.js": false,
|
|
64
68
|
"./src/http-server.js": false,
|
|
@@ -66,5 +70,8 @@
|
|
|
66
70
|
"@atlaspack/markdown-ansi": false
|
|
67
71
|
},
|
|
68
72
|
"type": "commonjs",
|
|
69
|
-
"
|
|
70
|
-
|
|
73
|
+
"scripts": {
|
|
74
|
+
"check-ts": "tsc --emitDeclarationOnly --rootDir src"
|
|
75
|
+
},
|
|
76
|
+
"gitHead": "43fdd223860fbc97af17d68c65419b97412cb888"
|
|
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
|
+
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
|
-
|
|
3
1
|
import {makeDeferredWithPromise, type Deferred} from './Deferred';
|
|
4
2
|
|
|
5
|
-
type PromiseQueueOpts = {
|
|
3
|
+
type PromiseQueueOpts = {
|
|
4
|
+
maxConcurrent: number;
|
|
5
|
+
};
|
|
6
6
|
|
|
7
7
|
export default class PromiseQueue<T> {
|
|
8
|
-
_deferred:
|
|
8
|
+
_deferred: Deferred<Array<T>> | null | undefined;
|
|
9
9
|
_maxConcurrent: number;
|
|
10
10
|
_numRunning: number = 0;
|
|
11
11
|
_queue: Array<() => Promise<void>> = [];
|
|
12
|
-
_runPromise:
|
|
13
|
-
_error:
|
|
12
|
+
_runPromise: Promise<Array<T>> | null | undefined = null;
|
|
13
|
+
_error: unknown;
|
|
14
14
|
_count: number = 0;
|
|
15
15
|
_results: Array<T> = [];
|
|
16
16
|
_addSubscriptions: Set<() => void> = new Set();
|
|
@@ -28,30 +28,35 @@ export default class PromiseQueue<T> {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
add(fn: () => Promise<T>): void {
|
|
31
|
-
new Promise(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
31
|
+
new Promise(
|
|
32
|
+
(
|
|
33
|
+
resolve: (result: Promise<T> | T) => void,
|
|
34
|
+
reject: (error?: any) => void,
|
|
35
|
+
) => {
|
|
36
|
+
let i = this._count++;
|
|
37
|
+
let wrapped = () =>
|
|
38
|
+
fn().then(
|
|
39
|
+
(result) => {
|
|
40
|
+
this._results[i] = result;
|
|
41
|
+
resolve(result);
|
|
42
|
+
},
|
|
43
|
+
(err) => {
|
|
44
|
+
reject(err);
|
|
45
|
+
throw err;
|
|
46
|
+
},
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
this._queue.push(wrapped);
|
|
50
|
+
|
|
51
|
+
for (const addFn of this._addSubscriptions) {
|
|
52
|
+
addFn();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (this._numRunning > 0 && this._numRunning < this._maxConcurrent) {
|
|
56
|
+
this._next();
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
).catch(() => {});
|
|
55
60
|
}
|
|
56
61
|
|
|
57
62
|
subscribeToAdd(fn: () => void): () => void {
|
|
@@ -71,9 +76,9 @@ export default class PromiseQueue<T> {
|
|
|
71
76
|
return Promise.resolve([]);
|
|
72
77
|
}
|
|
73
78
|
|
|
74
|
-
let {deferred, promise} = makeDeferredWithPromise();
|
|
79
|
+
let {deferred, promise} = makeDeferredWithPromise<Array<T>>();
|
|
75
80
|
this._deferred = deferred;
|
|
76
|
-
this._runPromise = promise
|
|
81
|
+
this._runPromise = promise as Promise<Array<T>>;
|
|
77
82
|
|
|
78
83
|
while (this._queue.length && this._numRunning < this._maxConcurrent) {
|
|
79
84
|
this._next();
|
|
@@ -84,7 +89,7 @@ export default class PromiseQueue<T> {
|
|
|
84
89
|
|
|
85
90
|
async _next(): Promise<void> {
|
|
86
91
|
let fn = this._queue.shift();
|
|
87
|
-
await this._runFn(fn);
|
|
92
|
+
await this._runFn(fn as () => unknown);
|
|
88
93
|
if (this._queue.length) {
|
|
89
94
|
this._next();
|
|
90
95
|
} else if (this._numRunning === 0) {
|
|
@@ -92,11 +97,11 @@ export default class PromiseQueue<T> {
|
|
|
92
97
|
}
|
|
93
98
|
}
|
|
94
99
|
|
|
95
|
-
async _runFn(fn: () =>
|
|
100
|
+
async _runFn(fn: () => unknown): Promise<void> {
|
|
96
101
|
this._numRunning++;
|
|
97
102
|
try {
|
|
98
103
|
await fn();
|
|
99
|
-
} catch (e) {
|
|
104
|
+
} catch (e: any) {
|
|
100
105
|
// Only store the first error that occurs.
|
|
101
106
|
// We don't reject immediately so that any other concurrent
|
|
102
107
|
// requests have time to complete.
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
|
-
|
|
3
1
|
import {Transform} from 'stream';
|
|
4
2
|
|
|
5
3
|
/*
|
|
@@ -7,21 +5,24 @@ import {Transform} from 'stream';
|
|
|
7
5
|
* callback. Continues to pass data chunks down the stream.
|
|
8
6
|
*/
|
|
9
7
|
export default class TapStream extends Transform {
|
|
10
|
-
_tap: (Buffer) =>
|
|
11
|
-
constructor(tap: (Buffer) =>
|
|
12
|
-
super({...options});
|
|
8
|
+
_tap: (arg1: Buffer) => unknown;
|
|
9
|
+
constructor(tap: (arg1: Buffer) => unknown, options: unknown) {
|
|
10
|
+
super({...(options as any)});
|
|
13
11
|
this._tap = tap;
|
|
14
12
|
}
|
|
15
13
|
|
|
16
14
|
_transform(
|
|
17
15
|
chunk: Buffer | string,
|
|
18
16
|
encoding: string,
|
|
19
|
-
callback: (
|
|
17
|
+
callback: (
|
|
18
|
+
err?: Error | null | undefined,
|
|
19
|
+
chunk?: Buffer | string,
|
|
20
|
+
) => unknown,
|
|
20
21
|
) {
|
|
21
22
|
try {
|
|
22
23
|
this._tap(Buffer.from(chunk));
|
|
23
24
|
callback(null, chunk);
|
|
24
|
-
} catch (err) {
|
|
25
|
+
} catch (err: any) {
|
|
25
26
|
callback(err);
|
|
26
27
|
}
|
|
27
28
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import path from 'path';
|
|
3
2
|
import type {FileSystem} from '@atlaspack/types';
|
|
4
3
|
import {fuzzySearch} from './schema';
|
|
@@ -48,7 +47,7 @@ export async function findAlternativeNodeModules(
|
|
|
48
47
|
potentialModules.push(...modules);
|
|
49
48
|
}
|
|
50
49
|
}
|
|
51
|
-
} catch (err) {
|
|
50
|
+
} catch (err: any) {
|
|
52
51
|
// ignore
|
|
53
52
|
}
|
|
54
53
|
|
|
@@ -68,16 +67,16 @@ async function findAllFilesUp({
|
|
|
68
67
|
collected,
|
|
69
68
|
leadingDotSlash = true,
|
|
70
69
|
includeDirectories = true,
|
|
71
|
-
}: {
|
|
72
|
-
fs: FileSystem
|
|
73
|
-
dir: string
|
|
74
|
-
root: string
|
|
75
|
-
basedir: string
|
|
76
|
-
maxlength: number
|
|
77
|
-
collected: Array<string
|
|
78
|
-
leadingDotSlash?: boolean
|
|
79
|
-
includeDirectories?: boolean
|
|
80
|
-
|
|
70
|
+
}: {
|
|
71
|
+
fs: FileSystem;
|
|
72
|
+
dir: string;
|
|
73
|
+
root: string;
|
|
74
|
+
basedir: string;
|
|
75
|
+
maxlength: number;
|
|
76
|
+
collected: Array<string>;
|
|
77
|
+
leadingDotSlash?: boolean;
|
|
78
|
+
includeDirectories?: boolean;
|
|
79
|
+
}): Promise<unknown> {
|
|
81
80
|
let dirContent = (await fs.readdir(dir)).sort();
|
|
82
81
|
return Promise.all(
|
|
83
82
|
dirContent.map(async (item) => {
|
|
@@ -111,9 +110,9 @@ export async function findAlternativeFiles(
|
|
|
111
110
|
fileSpecifier: string,
|
|
112
111
|
dir: string,
|
|
113
112
|
projectRoot: string,
|
|
114
|
-
leadingDotSlash
|
|
115
|
-
includeDirectories
|
|
116
|
-
includeExtension
|
|
113
|
+
leadingDotSlash: boolean = true,
|
|
114
|
+
includeDirectories: boolean = true,
|
|
115
|
+
includeExtension: boolean = false,
|
|
117
116
|
): Promise<Array<string>> {
|
|
118
117
|
let potentialFiles: Array<string> = [];
|
|
119
118
|
// Find our root, we won't recommend files above the package root as that's bad practise
|
package/src/{blob.js → blob.ts}
RENAMED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
|
-
|
|
3
1
|
import type {Blob} from '@atlaspack/types';
|
|
4
2
|
|
|
5
3
|
import {Buffer} from 'buffer';
|
|
@@ -12,7 +10,7 @@ export function blobToBuffer(blob: Blob): Promise<Buffer> {
|
|
|
12
10
|
} else if (blob instanceof Buffer) {
|
|
13
11
|
return Promise.resolve(Buffer.from(blob));
|
|
14
12
|
} else {
|
|
15
|
-
return Promise.resolve(Buffer.from(blob, 'utf8'));
|
|
13
|
+
return Promise.resolve(Buffer.from(blob as string, 'utf8'));
|
|
16
14
|
}
|
|
17
15
|
}
|
|
18
16
|
|
|
@@ -22,6 +20,6 @@ export async function blobToString(blob: Blob): Promise<string> {
|
|
|
22
20
|
} else if (blob instanceof Buffer) {
|
|
23
21
|
return blob.toString();
|
|
24
22
|
} else {
|
|
25
|
-
return blob;
|
|
23
|
+
return blob as string;
|
|
26
24
|
}
|
|
27
25
|
}
|