@parcel/utils 2.1.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +35876 -411
- package/lib/index.js.map +1 -0
- package/package.json +28 -15
- package/src/config.js +2 -2
- package/src/glob.js +14 -3
- package/src/index.js +1 -1
- package/src/replaceBundleReferences.js +3 -1
- package/lib/DefaultMap.js +0 -56
- package/lib/Deferred.js +0 -34
- package/lib/PromiseQueue.js +0 -124
- package/lib/TapStream.js +0 -41
- package/lib/alternatives.js +0 -134
- package/lib/ansi-html.js +0 -24
- package/lib/blob.js +0 -49
- package/lib/bundle-url.js +0 -43
- package/lib/collection.js +0 -65
- package/lib/config.js +0 -198
- package/lib/countLines.js +0 -18
- package/lib/debounce.js +0 -20
- package/lib/dependency-location.js +0 -21
- package/lib/escape-html.js +0 -24
- package/lib/generateBuildMetrics.js +0 -148
- package/lib/generateCertificate.js +0 -149
- package/lib/getCertificate.js +0 -19
- package/lib/getExisting.js +0 -31
- package/lib/getRootDir.js +0 -66
- package/lib/glob.js +0 -110
- package/lib/hash.js +0 -44
- package/lib/http-server.js +0 -102
- package/lib/is-url.js +0 -27
- package/lib/isDirectoryInside.js +0 -24
- package/lib/objectHash.js +0 -34
- package/lib/openInBrowser.js +0 -94
- package/lib/parseCSSImport.js +0 -16
- package/lib/path.js +0 -49
- package/lib/prettifyTime.js +0 -10
- package/lib/prettyDiagnostic.js +0 -139
- package/lib/relativeBundlePath.js +0 -30
- package/lib/relativeUrl.js +0 -32
- package/lib/replaceBundleReferences.js +0 -207
- package/lib/schema.js +0 -391
- package/lib/shared-buffer.js +0 -31
- package/lib/sourcemap.js +0 -147
- package/lib/stream.js +0 -86
- package/lib/throttle.js +0 -16
- package/lib/urlJoin.js +0 -46
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcel/utils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Blazing fast, zero configuration web application bundler",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -19,37 +19,50 @@
|
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">= 12.0.0"
|
|
21
21
|
},
|
|
22
|
+
"targets": {
|
|
23
|
+
"main": {
|
|
24
|
+
"includeNodeModules": {
|
|
25
|
+
"@parcel/codeframe": false,
|
|
26
|
+
"@parcel/diagnostic": false,
|
|
27
|
+
"@parcel/hash": false,
|
|
28
|
+
"@parcel/logger": false,
|
|
29
|
+
"@parcel/markdown-ansi": false,
|
|
30
|
+
"@parcel/source-map": false,
|
|
31
|
+
"chalk": false
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
},
|
|
22
35
|
"dependencies": {
|
|
23
|
-
"@
|
|
24
|
-
"@parcel/
|
|
25
|
-
"@parcel/
|
|
26
|
-
"@parcel/
|
|
27
|
-
"@parcel/
|
|
28
|
-
"@parcel/markdown-ansi": "^2.1.0",
|
|
36
|
+
"@parcel/codeframe": "^2.3.0",
|
|
37
|
+
"@parcel/diagnostic": "^2.3.0",
|
|
38
|
+
"@parcel/hash": "^2.3.0",
|
|
39
|
+
"@parcel/logger": "^2.3.0",
|
|
40
|
+
"@parcel/markdown-ansi": "^2.3.0",
|
|
29
41
|
"@parcel/source-map": "^2.0.0",
|
|
42
|
+
"chalk": "^4.1.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@babel/plugin-transform-flow-strip-types": "^7.2.0",
|
|
46
|
+
"@iarna/toml": "^2.2.0",
|
|
30
47
|
"ansi-html-community": "0.0.8",
|
|
31
|
-
"chalk": "^4.1.0",
|
|
32
48
|
"clone": "^2.1.1",
|
|
33
49
|
"fast-glob": "3.1.1",
|
|
34
50
|
"fastest-levenshtein": "^1.0.8",
|
|
35
51
|
"is-glob": "^4.0.0",
|
|
36
52
|
"is-url": "^1.2.2",
|
|
37
|
-
"json5": "^
|
|
53
|
+
"json5": "^2.2.0",
|
|
38
54
|
"lru-cache": "^6.0.0",
|
|
39
55
|
"micromatch": "^4.0.4",
|
|
40
|
-
"node-forge": "^
|
|
56
|
+
"node-forge": "^1.2.1",
|
|
41
57
|
"nullthrows": "^1.1.1",
|
|
42
58
|
"open": "^7.0.3",
|
|
59
|
+
"random-int": "^1.0.0",
|
|
43
60
|
"terminal-link": "^2.1.1"
|
|
44
61
|
},
|
|
45
|
-
"devDependencies": {
|
|
46
|
-
"@babel/plugin-transform-flow-strip-types": "^7.2.0",
|
|
47
|
-
"random-int": "^1.0.0"
|
|
48
|
-
},
|
|
49
62
|
"browser": {
|
|
50
63
|
"./src/generateCertificate.js": false,
|
|
51
64
|
"./src/http-server.js": false,
|
|
52
65
|
"./src/openInBrowser.js": false
|
|
53
66
|
},
|
|
54
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "65ffb58e88024258c31e1f480241f293e29b25c5"
|
|
55
68
|
}
|
package/src/config.js
CHANGED
|
@@ -5,7 +5,7 @@ import type {FileSystem} from '@parcel/fs';
|
|
|
5
5
|
import ThrowableDiagnostic from '@parcel/diagnostic';
|
|
6
6
|
import path from 'path';
|
|
7
7
|
import clone from 'clone';
|
|
8
|
-
import
|
|
8
|
+
import json5 from 'json5';
|
|
9
9
|
import {parse as toml} from '@iarna/toml';
|
|
10
10
|
import LRU from 'lru-cache';
|
|
11
11
|
|
|
@@ -154,6 +154,6 @@ function getParser(extname) {
|
|
|
154
154
|
return toml;
|
|
155
155
|
case 'json':
|
|
156
156
|
default:
|
|
157
|
-
return json5;
|
|
157
|
+
return json5.parse;
|
|
158
158
|
}
|
|
159
159
|
}
|
package/src/glob.js
CHANGED
|
@@ -5,15 +5,26 @@ import type {FileSystem} from '@parcel/fs';
|
|
|
5
5
|
|
|
6
6
|
import _isGlob from 'is-glob';
|
|
7
7
|
import fastGlob, {type FastGlobOptions} from 'fast-glob';
|
|
8
|
-
import {isMatch} from 'micromatch';
|
|
8
|
+
import {isMatch, makeRe, type Options} from 'micromatch';
|
|
9
9
|
import {normalizeSeparators} from './path';
|
|
10
10
|
|
|
11
11
|
export function isGlob(p: FilePath): any {
|
|
12
12
|
return _isGlob(normalizeSeparators(p));
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export function isGlobMatch(
|
|
16
|
-
|
|
15
|
+
export function isGlobMatch(
|
|
16
|
+
filePath: FilePath,
|
|
17
|
+
glob: Glob | Array<Glob>,
|
|
18
|
+
opts?: Options,
|
|
19
|
+
): any {
|
|
20
|
+
glob = Array.isArray(glob)
|
|
21
|
+
? glob.map(normalizeSeparators)
|
|
22
|
+
: normalizeSeparators(glob);
|
|
23
|
+
return isMatch(filePath, glob, opts);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function globToRegex(glob: Glob, opts?: Options): RegExp {
|
|
27
|
+
return makeRe(glob, opts);
|
|
17
28
|
}
|
|
18
29
|
|
|
19
30
|
export function globSync(
|
package/src/index.js
CHANGED
|
@@ -41,7 +41,7 @@ export {
|
|
|
41
41
|
export {resolveConfig, resolveConfigSync, loadConfig} from './config';
|
|
42
42
|
export {DefaultMap, DefaultWeakMap} from './DefaultMap';
|
|
43
43
|
export {makeDeferredWithPromise} from './Deferred';
|
|
44
|
-
export {isGlob, isGlobMatch, globSync, glob} from './glob';
|
|
44
|
+
export {isGlob, isGlobMatch, globSync, glob, globToRegex} from './glob';
|
|
45
45
|
export {hashStream, hashObject, hashFile} from './hash';
|
|
46
46
|
export {SharedBuffer} from './shared-buffer';
|
|
47
47
|
export {fuzzySearch} from './schema';
|
|
@@ -139,8 +139,10 @@ export async function replaceInlineReferences({
|
|
|
139
139
|
|
|
140
140
|
let inlineType = nullthrows(entryBundle.getMainEntry()).meta.inlineType;
|
|
141
141
|
if (inlineType == null || inlineType === 'string') {
|
|
142
|
+
let placeholder = dependency.meta?.placeholder ?? dependency.id;
|
|
143
|
+
invariant(typeof placeholder === 'string');
|
|
142
144
|
replacements.set(
|
|
143
|
-
|
|
145
|
+
placeholder,
|
|
144
146
|
getInlineReplacement(dependency, inlineType, packagedContents),
|
|
145
147
|
);
|
|
146
148
|
}
|
package/lib/DefaultMap.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.DefaultWeakMap = exports.DefaultMap = void 0;
|
|
7
|
-
|
|
8
|
-
class DefaultMap extends Map {
|
|
9
|
-
constructor(getDefault, entries) {
|
|
10
|
-
super(entries);
|
|
11
|
-
this._getDefault = getDefault;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
get(key) {
|
|
15
|
-
let ret;
|
|
16
|
-
|
|
17
|
-
if (this.has(key)) {
|
|
18
|
-
ret = super.get(key);
|
|
19
|
-
} else {
|
|
20
|
-
ret = this._getDefault(key);
|
|
21
|
-
this.set(key, ret);
|
|
22
|
-
} // $FlowFixMe
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return ret;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
} // Duplicated from DefaultMap implementation for Flow
|
|
29
|
-
// Roughly mirrors https://github.com/facebook/flow/blob/2eb5a78d92c167117ba9caae070afd2b9f598599/lib/core.js#L617
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
exports.DefaultMap = DefaultMap;
|
|
33
|
-
|
|
34
|
-
class DefaultWeakMap extends WeakMap {
|
|
35
|
-
constructor(getDefault, entries) {
|
|
36
|
-
super(entries);
|
|
37
|
-
this._getDefault = getDefault;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
get(key) {
|
|
41
|
-
let ret;
|
|
42
|
-
|
|
43
|
-
if (this.has(key)) {
|
|
44
|
-
ret = super.get(key);
|
|
45
|
-
} else {
|
|
46
|
-
ret = this._getDefault(key);
|
|
47
|
-
this.set(key, ret);
|
|
48
|
-
} // $FlowFixMe
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return ret;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
exports.DefaultWeakMap = DefaultWeakMap;
|
package/lib/Deferred.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.makeDeferredWithPromise = makeDeferredWithPromise;
|
|
7
|
-
|
|
8
|
-
function _assert() {
|
|
9
|
-
const data = _interopRequireDefault(require("assert"));
|
|
10
|
-
|
|
11
|
-
_assert = function () {
|
|
12
|
-
return data;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
|
|
20
|
-
function makeDeferredWithPromise() {
|
|
21
|
-
let deferred;
|
|
22
|
-
let promise = new Promise((resolve, reject) => {
|
|
23
|
-
deferred = {
|
|
24
|
-
resolve,
|
|
25
|
-
reject
|
|
26
|
-
};
|
|
27
|
-
}); // Promise constructor callback executes synchronously, so this is defined
|
|
28
|
-
|
|
29
|
-
(0, _assert().default)(deferred != null);
|
|
30
|
-
return {
|
|
31
|
-
deferred,
|
|
32
|
-
promise
|
|
33
|
-
};
|
|
34
|
-
}
|
package/lib/PromiseQueue.js
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _Deferred = require("./Deferred");
|
|
9
|
-
|
|
10
|
-
class PromiseQueue {
|
|
11
|
-
_numRunning = 0;
|
|
12
|
-
_queue = [];
|
|
13
|
-
_runPromise = null;
|
|
14
|
-
_count = 0;
|
|
15
|
-
_results = [];
|
|
16
|
-
|
|
17
|
-
constructor(opts = {
|
|
18
|
-
maxConcurrent: Infinity
|
|
19
|
-
}) {
|
|
20
|
-
if (opts.maxConcurrent <= 0) {
|
|
21
|
-
throw new TypeError('maxConcurrent must be a positive, non-zero value');
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
this._maxConcurrent = opts.maxConcurrent;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
getNumWaiting() {
|
|
28
|
-
return this._queue.length;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
add(fn) {
|
|
32
|
-
return new Promise((resolve, reject) => {
|
|
33
|
-
let i = this._count++;
|
|
34
|
-
|
|
35
|
-
this._queue.push(() => fn().then(result => {
|
|
36
|
-
this._results[i] = result;
|
|
37
|
-
resolve(result);
|
|
38
|
-
}, err => {
|
|
39
|
-
reject(err);
|
|
40
|
-
throw err;
|
|
41
|
-
}));
|
|
42
|
-
|
|
43
|
-
if (this._numRunning > 0 && this._numRunning < this._maxConcurrent) {
|
|
44
|
-
this._next();
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
run() {
|
|
50
|
-
if (this._runPromise != null) {
|
|
51
|
-
return this._runPromise;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (this._queue.length === 0) {
|
|
55
|
-
return Promise.resolve([]);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
let {
|
|
59
|
-
deferred,
|
|
60
|
-
promise
|
|
61
|
-
} = (0, _Deferred.makeDeferredWithPromise)();
|
|
62
|
-
this._deferred = deferred;
|
|
63
|
-
this._runPromise = promise;
|
|
64
|
-
|
|
65
|
-
while (this._queue.length && this._numRunning < this._maxConcurrent) {
|
|
66
|
-
this._next();
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return promise;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async _next() {
|
|
73
|
-
let fn = this._queue.shift();
|
|
74
|
-
|
|
75
|
-
await this._runFn(fn);
|
|
76
|
-
|
|
77
|
-
if (this._queue.length) {
|
|
78
|
-
this._next();
|
|
79
|
-
} else if (this._numRunning === 0) {
|
|
80
|
-
this._done();
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
async _runFn(fn) {
|
|
85
|
-
this._numRunning++;
|
|
86
|
-
|
|
87
|
-
try {
|
|
88
|
-
await fn();
|
|
89
|
-
} catch (e) {
|
|
90
|
-
// Only store the first error that occurs.
|
|
91
|
-
// We don't reject immediately so that any other concurrent
|
|
92
|
-
// requests have time to complete.
|
|
93
|
-
if (this._error == null) {
|
|
94
|
-
this._error = e;
|
|
95
|
-
}
|
|
96
|
-
} finally {
|
|
97
|
-
this._numRunning--;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
_resetState() {
|
|
102
|
-
this._queue = [];
|
|
103
|
-
this._count = 0;
|
|
104
|
-
this._results = [];
|
|
105
|
-
this._runPromise = null;
|
|
106
|
-
this._numRunning = 0;
|
|
107
|
-
this._deferred = null;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
_done() {
|
|
111
|
-
if (this._deferred != null) {
|
|
112
|
-
if (this._error != null) {
|
|
113
|
-
this._deferred.reject(this._error);
|
|
114
|
-
} else {
|
|
115
|
-
this._deferred.resolve(this._results);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
this._resetState();
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
exports.default = PromiseQueue;
|
package/lib/TapStream.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
function _stream() {
|
|
9
|
-
const data = require("stream");
|
|
10
|
-
|
|
11
|
-
_stream = function () {
|
|
12
|
-
return data;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/*
|
|
19
|
-
* "Taps" into the contents of a flowing stream, yielding chunks to the passed
|
|
20
|
-
* callback. Continues to pass data chunks down the stream.
|
|
21
|
-
*/
|
|
22
|
-
class TapStream extends _stream().Transform {
|
|
23
|
-
constructor(tap, options) {
|
|
24
|
-
super({ ...options
|
|
25
|
-
});
|
|
26
|
-
this._tap = tap;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
_transform(chunk, encoding, callback) {
|
|
30
|
-
try {
|
|
31
|
-
this._tap(Buffer.from(chunk));
|
|
32
|
-
|
|
33
|
-
callback(null, chunk);
|
|
34
|
-
} catch (err) {
|
|
35
|
-
callback(err);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
exports.default = TapStream;
|
package/lib/alternatives.js
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.findAlternativeNodeModules = findAlternativeNodeModules;
|
|
7
|
-
exports.findAlternativeFiles = findAlternativeFiles;
|
|
8
|
-
|
|
9
|
-
function _path() {
|
|
10
|
-
const data = _interopRequireDefault(require("path"));
|
|
11
|
-
|
|
12
|
-
_path = function () {
|
|
13
|
-
return data;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
return data;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
var _schema = require("./schema");
|
|
20
|
-
|
|
21
|
-
var _path2 = require("./path");
|
|
22
|
-
|
|
23
|
-
var _config = require("./config");
|
|
24
|
-
|
|
25
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
26
|
-
|
|
27
|
-
async function findAlternativeNodeModules(fs, moduleName, dir) {
|
|
28
|
-
let potentialModules = [];
|
|
29
|
-
|
|
30
|
-
let root = _path().default.parse(dir).root;
|
|
31
|
-
|
|
32
|
-
let isOrganisationModule = moduleName.startsWith('@');
|
|
33
|
-
|
|
34
|
-
while (dir !== root) {
|
|
35
|
-
// Skip node_modules directories
|
|
36
|
-
if (_path().default.basename(dir) === 'node_modules') {
|
|
37
|
-
dir = _path().default.dirname(dir);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
try {
|
|
41
|
-
let modulesDir = _path().default.join(dir, 'node_modules');
|
|
42
|
-
|
|
43
|
-
let stats = await fs.stat(modulesDir);
|
|
44
|
-
|
|
45
|
-
if (stats.isDirectory()) {
|
|
46
|
-
let dirContent = (await fs.readdir(modulesDir)).sort(); // Filter out the modules that interest us
|
|
47
|
-
|
|
48
|
-
let modules = dirContent.filter(i => isOrganisationModule ? i.startsWith('@') : !i.startsWith('@')); // If it's an organisation module, loop through all the modules of that organisation
|
|
49
|
-
|
|
50
|
-
if (isOrganisationModule) {
|
|
51
|
-
await Promise.all(modules.map(async item => {
|
|
52
|
-
let orgDirPath = _path().default.join(modulesDir, item);
|
|
53
|
-
|
|
54
|
-
let orgDirContent = (await fs.readdir(orgDirPath)).sort(); // Add all org packages
|
|
55
|
-
|
|
56
|
-
potentialModules.push(...orgDirContent.map(i => `${item}/${i}`));
|
|
57
|
-
}));
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
} catch (err) {// ignore
|
|
61
|
-
} // Move up a directory
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
dir = _path().default.dirname(dir);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return (0, _schema.fuzzySearch)(potentialModules.sort(), moduleName).slice(0, 2);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
async function findAllFilesUp({
|
|
71
|
-
fs,
|
|
72
|
-
dir,
|
|
73
|
-
root,
|
|
74
|
-
basedir,
|
|
75
|
-
maxlength,
|
|
76
|
-
collected,
|
|
77
|
-
leadingDotSlash = true,
|
|
78
|
-
includeDirectories = true
|
|
79
|
-
}) {
|
|
80
|
-
let dirContent = (await fs.readdir(dir)).sort();
|
|
81
|
-
return Promise.all(dirContent.map(async item => {
|
|
82
|
-
let fullPath = _path().default.join(dir, item);
|
|
83
|
-
|
|
84
|
-
let relativeFilePath = (0, _path2.relativePath)(basedir, fullPath, leadingDotSlash);
|
|
85
|
-
|
|
86
|
-
if (relativeFilePath.length < maxlength) {
|
|
87
|
-
let stats = await fs.stat(fullPath);
|
|
88
|
-
let isDir = stats.isDirectory();
|
|
89
|
-
|
|
90
|
-
if (isDir && includeDirectories || stats.isFile()) {
|
|
91
|
-
collected.push(relativeFilePath);
|
|
92
|
-
} // If it's a directory, run over each item within said directory...
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (isDir) {
|
|
96
|
-
return findAllFilesUp({
|
|
97
|
-
fs,
|
|
98
|
-
dir: fullPath,
|
|
99
|
-
root,
|
|
100
|
-
basedir,
|
|
101
|
-
maxlength,
|
|
102
|
-
collected
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}));
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
async function findAlternativeFiles(fs, fileSpecifier, dir, projectRoot, leadingDotSlash = true, includeDirectories = true, includeExtension = false) {
|
|
110
|
-
let potentialFiles = []; // Find our root, we won't recommend files above the package root as that's bad practise
|
|
111
|
-
|
|
112
|
-
let pkg = await (0, _config.resolveConfig)(fs, _path().default.join(dir, 'index'), ['package.json'], projectRoot);
|
|
113
|
-
let pkgRoot = pkg ? _path().default.dirname(pkg) : projectRoot;
|
|
114
|
-
await findAllFilesUp({
|
|
115
|
-
fs,
|
|
116
|
-
dir: pkgRoot,
|
|
117
|
-
root: pkgRoot,
|
|
118
|
-
basedir: dir,
|
|
119
|
-
maxlength: fileSpecifier.length + 10,
|
|
120
|
-
collected: potentialFiles,
|
|
121
|
-
leadingDotSlash,
|
|
122
|
-
includeDirectories
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
if (_path().default.extname(fileSpecifier) === '' && !includeExtension) {
|
|
126
|
-
potentialFiles = potentialFiles.map(p => {
|
|
127
|
-
let ext = _path().default.extname(p);
|
|
128
|
-
|
|
129
|
-
return ext.length > 0 ? p.slice(0, -ext.length) : p;
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
return (0, _schema.fuzzySearch)(potentialFiles, fileSpecifier).slice(0, 2);
|
|
134
|
-
}
|
package/lib/ansi-html.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.ansiHtml = ansiHtml;
|
|
7
|
-
|
|
8
|
-
function _ansiHtmlCommunity() {
|
|
9
|
-
const data = _interopRequireDefault(require("ansi-html-community"));
|
|
10
|
-
|
|
11
|
-
_ansiHtmlCommunity = function () {
|
|
12
|
-
return data;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
var _escapeHtml = require("./escape-html");
|
|
19
|
-
|
|
20
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
-
|
|
22
|
-
function ansiHtml(ansi) {
|
|
23
|
-
return (0, _ansiHtmlCommunity().default)((0, _escapeHtml.escapeHTML)(ansi));
|
|
24
|
-
}
|
package/lib/blob.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.blobToBuffer = blobToBuffer;
|
|
7
|
-
exports.blobToString = blobToString;
|
|
8
|
-
|
|
9
|
-
function _buffer() {
|
|
10
|
-
const data = require("buffer");
|
|
11
|
-
|
|
12
|
-
_buffer = function () {
|
|
13
|
-
return data;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
return data;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
var _ = require("./");
|
|
20
|
-
|
|
21
|
-
function _stream() {
|
|
22
|
-
const data = require("stream");
|
|
23
|
-
|
|
24
|
-
_stream = function () {
|
|
25
|
-
return data;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
return data;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function blobToBuffer(blob) {
|
|
32
|
-
if (blob instanceof _stream().Readable) {
|
|
33
|
-
return (0, _.bufferStream)(blob);
|
|
34
|
-
} else if (blob instanceof _buffer().Buffer) {
|
|
35
|
-
return Promise.resolve(_buffer().Buffer.from(blob));
|
|
36
|
-
} else {
|
|
37
|
-
return Promise.resolve(_buffer().Buffer.from(blob, 'utf8'));
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
async function blobToString(blob) {
|
|
42
|
-
if (blob instanceof _stream().Readable) {
|
|
43
|
-
return (await (0, _.bufferStream)(blob)).toString();
|
|
44
|
-
} else if (blob instanceof _buffer().Buffer) {
|
|
45
|
-
return blob.toString();
|
|
46
|
-
} else {
|
|
47
|
-
return blob;
|
|
48
|
-
}
|
|
49
|
-
}
|
package/lib/bundle-url.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getBaseURL = getBaseURL;
|
|
7
|
-
exports.getBundleURL = void 0;
|
|
8
|
-
let bundleURL = null;
|
|
9
|
-
|
|
10
|
-
function getBundleURLCached() {
|
|
11
|
-
if (bundleURL == null) {
|
|
12
|
-
bundleURL = _getBundleURL();
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return bundleURL;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function _getBundleURL() {
|
|
19
|
-
// Attempt to find the URL of the current script and use that as the base URL
|
|
20
|
-
try {
|
|
21
|
-
throw new Error();
|
|
22
|
-
} catch (err) {
|
|
23
|
-
let stack = typeof err.stack === 'string' ? err.stack : '';
|
|
24
|
-
let matches = stack.match(/(https?|file|ftp):\/\/[^)\n]+/g);
|
|
25
|
-
|
|
26
|
-
if (matches) {
|
|
27
|
-
return getBaseURL(matches[0]);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return '/';
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function getBaseURL(url) {
|
|
35
|
-
if (url == null) {
|
|
36
|
-
return '/';
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return url.replace(/^((?:https?|file|ftp):\/\/.+)\/[^/]+$/, '$1') + '/';
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const getBundleURL = getBundleURLCached;
|
|
43
|
-
exports.getBundleURL = getBundleURL;
|