@parcel/utils 2.0.0-beta.1 → 2.0.0-nightly.1002
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +6 -6
- package/lib/index.js +35850 -337
- package/lib/index.js.map +1 -0
- package/package.json +42 -20
- package/src/DefaultMap.js +1 -1
- package/src/PromiseQueue.js +16 -12
- package/src/alternatives.js +143 -0
- package/src/ansi-html.js +2 -2
- package/src/blob.js +2 -1
- package/src/bundle-url.js +1 -1
- package/src/collection.js +14 -14
- package/src/config.js +93 -53
- package/src/countLines.js +5 -2
- package/src/debounce.js +1 -1
- package/src/dependency-location.js +11 -6
- package/src/generateBuildMetrics.js +5 -5
- package/src/generateCertificate.js +1 -1
- package/src/getCertificate.js +1 -1
- package/src/getExisting.js +1 -4
- package/src/getRootDir.js +1 -2
- package/src/glob.js +36 -5
- package/src/hash.js +34 -0
- package/src/http-server.js +4 -11
- package/src/index.js +47 -20
- package/src/is-url.js +1 -1
- package/src/isDirectoryInside.js +4 -1
- package/src/openInBrowser.js +3 -1
- package/src/path.js +17 -2
- package/src/prettyDiagnostic.js +39 -27
- package/src/relativeBundlePath.js +5 -7
- package/src/replaceBundleReferences.js +50 -34
- package/src/schema.js +96 -42
- package/src/shared-buffer.js +24 -0
- package/src/sourcemap.js +84 -10
- package/src/urlJoin.js +3 -1
- package/test/DefaultMap.test.js +7 -4
- package/test/config.test.js +50 -0
- package/test/input/config/config.json +3 -0
- package/test/input/config/empty.json +0 -0
- package/test/input/config/empty.toml +0 -0
- package/test/input/sourcemap/referenced-min.js +1 -1
- package/test/replaceBundleReferences.test.js +268 -0
- package/test/sourcemap.test.js +5 -9
- package/test/throttle.test.js +1 -2
- package/test/urlJoin.test.js +37 -0
- package/lib/DefaultMap.js +0 -64
- package/lib/Deferred.js +0 -26
- package/lib/PromiseQueue.js +0 -133
- package/lib/TapStream.js +0 -38
- package/lib/ansi-html.js +0 -16
- package/lib/blob.js +0 -31
- package/lib/bundle-url.js +0 -43
- package/lib/collection.js +0 -62
- package/lib/config.js +0 -109
- package/lib/countLines.js +0 -18
- package/lib/debounce.js +0 -20
- package/lib/dependency-location.js +0 -21
- package/lib/escape-html.js +0 -24
- package/lib/escape-markdown.js +0 -15
- package/lib/generateBuildMetrics.js +0 -124
- package/lib/generateCertificate.js +0 -124
- package/lib/getCertificate.js +0 -19
- package/lib/getExisting.js +0 -23
- package/lib/getRootDir.js +0 -55
- package/lib/glob.js +0 -69
- package/lib/http-server.js +0 -81
- package/lib/is-url.js +0 -17
- package/lib/isDirectoryInside.js +0 -16
- package/lib/md5.js +0 -40
- package/lib/objectHash.js +0 -26
- package/lib/openInBrowser.js +0 -70
- package/lib/parseCSSImport.js +0 -16
- package/lib/path.js +0 -30
- package/lib/prettifyTime.js +0 -10
- package/lib/prettyDiagnostic.js +0 -75
- package/lib/promisify.js +0 -13
- package/lib/relativeBundlePath.js +0 -18
- package/lib/relativeUrl.js +0 -16
- package/lib/replaceBundleReferences.js +0 -166
- package/lib/resolve.js +0 -108
- package/lib/schema.js +0 -321
- package/lib/serializeObject.js +0 -28
- package/lib/sourcemap.js +0 -58
- package/lib/stream.js +0 -78
- package/lib/throttle.js +0 -16
- package/lib/urlJoin.js +0 -27
- package/src/.babelrc +0 -3
- package/src/escape-markdown.js +0 -10
- package/src/md5.js +0 -49
- package/src/promisify.js +0 -13
- package/src/resolve.js +0 -216
- package/src/serializeObject.js +0 -22
- package/test/escapeMarkdown.test.js +0 -29
package/src/md5.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
|
-
|
|
3
|
-
import type {Readable} from 'stream';
|
|
4
|
-
import type {FileSystem} from '@parcel/fs';
|
|
5
|
-
|
|
6
|
-
import crypto from 'crypto';
|
|
7
|
-
import {objectSortedEntriesDeep} from './collection';
|
|
8
|
-
|
|
9
|
-
type StringHashEncoding = 'hex' | 'latin1' | 'binary' | 'base64';
|
|
10
|
-
|
|
11
|
-
export function md5FromString(
|
|
12
|
-
string: string | Buffer,
|
|
13
|
-
encoding: StringHashEncoding = 'hex',
|
|
14
|
-
): string {
|
|
15
|
-
return crypto
|
|
16
|
-
.createHash('md5')
|
|
17
|
-
.update(string)
|
|
18
|
-
.digest(encoding);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function md5FromReadableStream(stream: Readable): Promise<string> {
|
|
22
|
-
return new Promise((resolve, reject) => {
|
|
23
|
-
stream.on('error', err => {
|
|
24
|
-
reject(err);
|
|
25
|
-
});
|
|
26
|
-
stream
|
|
27
|
-
.pipe(crypto.createHash('md5').setEncoding('hex'))
|
|
28
|
-
.on('finish', function() {
|
|
29
|
-
resolve(this.read());
|
|
30
|
-
})
|
|
31
|
-
.on('error', err => {
|
|
32
|
-
reject(err);
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function md5FromObject(
|
|
38
|
-
obj: {+[string]: mixed, ...},
|
|
39
|
-
encoding: StringHashEncoding = 'hex',
|
|
40
|
-
): string {
|
|
41
|
-
return md5FromString(JSON.stringify(objectSortedEntriesDeep(obj)), encoding);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function md5FromFilePath(
|
|
45
|
-
fs: FileSystem,
|
|
46
|
-
filePath: string,
|
|
47
|
-
): Promise<string> {
|
|
48
|
-
return md5FromReadableStream(fs.createReadStream(filePath));
|
|
49
|
-
}
|
package/src/promisify.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
module.exports = function(fn) {
|
|
2
|
-
return function(...args) {
|
|
3
|
-
return new Promise(function(resolve, reject) {
|
|
4
|
-
fn(...args, function(err, ...res) {
|
|
5
|
-
if (err) return reject(err);
|
|
6
|
-
|
|
7
|
-
if (res.length === 1) return resolve(res[0]);
|
|
8
|
-
|
|
9
|
-
resolve(res);
|
|
10
|
-
});
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
};
|
package/src/resolve.js
DELETED
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
SemverRange,
|
|
5
|
-
PackageJSON,
|
|
6
|
-
FilePath,
|
|
7
|
-
ModuleSpecifier,
|
|
8
|
-
} from '@parcel/types';
|
|
9
|
-
import type {ResolveOptions} from 'resolve';
|
|
10
|
-
import type {FileSystem} from '@parcel/fs';
|
|
11
|
-
|
|
12
|
-
// $FlowFixMe TODO: Type promisify
|
|
13
|
-
import promisify from './promisify';
|
|
14
|
-
import _resolve from 'resolve';
|
|
15
|
-
import {resolveConfig, resolveConfigSync} from '../';
|
|
16
|
-
// $FlowFixMe this is untyped
|
|
17
|
-
import Module from 'module';
|
|
18
|
-
|
|
19
|
-
const resolveAsync = promisify(_resolve);
|
|
20
|
-
|
|
21
|
-
export type ResolveResult = {|
|
|
22
|
-
resolved: FilePath | ModuleSpecifier,
|
|
23
|
-
pkg?: ?PackageJSON,
|
|
24
|
-
|};
|
|
25
|
-
|
|
26
|
-
export async function resolve(
|
|
27
|
-
fs: FileSystem,
|
|
28
|
-
id: string,
|
|
29
|
-
opts: {|
|
|
30
|
-
range?: ?SemverRange,
|
|
31
|
-
...ResolveOptions,
|
|
32
|
-
basedir: string,
|
|
33
|
-
|},
|
|
34
|
-
): Promise<ResolveResult> {
|
|
35
|
-
if (process.env.PARCEL_BUILD_ENV !== 'production') {
|
|
36
|
-
// Yarn patches resolve automatically in a non-linked setup
|
|
37
|
-
let pnp;
|
|
38
|
-
if (
|
|
39
|
-
process.versions.pnp != null &&
|
|
40
|
-
(!id.includes('@parcel/') || id.startsWith('@parcel/watcher')) &&
|
|
41
|
-
(pnp = Module.findPnpApi(opts.basedir))
|
|
42
|
-
) {
|
|
43
|
-
try {
|
|
44
|
-
let res = pnp.resolveRequest(id, `${opts.basedir}/`, {
|
|
45
|
-
extensions: opts.extensions,
|
|
46
|
-
considerBuiltins: true,
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
if (!res) {
|
|
50
|
-
// builtin
|
|
51
|
-
return {resolved: id};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
let pkgFile = await resolveConfig(fs, res, ['package.json']);
|
|
55
|
-
let pkg = null;
|
|
56
|
-
if (pkgFile != null) {
|
|
57
|
-
pkg = JSON.parse(await fs.readFile(pkgFile, 'utf8'));
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (res) {
|
|
61
|
-
return {resolved: res, pkg};
|
|
62
|
-
}
|
|
63
|
-
} catch (e) {
|
|
64
|
-
if (e.code !== 'MODULE_NOT_FOUND') {
|
|
65
|
-
throw e;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// $FlowFixMe
|
|
71
|
-
opts.packageFilter = pkg => {
|
|
72
|
-
if (
|
|
73
|
-
typeof pkg.name === 'string' &&
|
|
74
|
-
pkg.name.startsWith('@parcel/') &&
|
|
75
|
-
pkg.name !== '@parcel/watcher'
|
|
76
|
-
) {
|
|
77
|
-
if (pkg.source) {
|
|
78
|
-
pkg.main = pkg.source;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return pkg;
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (id === 'pnpapi') {
|
|
86
|
-
// the resolve package doesn't recognize pnpapi as a builtin
|
|
87
|
-
return {resolved: 'pnpapi'};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
let res = await resolveAsync(id, {
|
|
91
|
-
...opts,
|
|
92
|
-
async readFile(filename, callback) {
|
|
93
|
-
try {
|
|
94
|
-
let res = await fs.readFile(filename);
|
|
95
|
-
callback(null, res);
|
|
96
|
-
} catch (err) {
|
|
97
|
-
callback(err);
|
|
98
|
-
}
|
|
99
|
-
},
|
|
100
|
-
async isFile(file, callback) {
|
|
101
|
-
try {
|
|
102
|
-
let stat = await fs.stat(file);
|
|
103
|
-
callback(null, stat.isFile());
|
|
104
|
-
} catch (err) {
|
|
105
|
-
callback(null, false);
|
|
106
|
-
}
|
|
107
|
-
},
|
|
108
|
-
async isDirectory(file, callback) {
|
|
109
|
-
try {
|
|
110
|
-
let stat = await fs.stat(file);
|
|
111
|
-
callback(null, stat.isDirectory());
|
|
112
|
-
} catch (err) {
|
|
113
|
-
callback(null, false);
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
if (typeof res === 'string') {
|
|
119
|
-
return {
|
|
120
|
-
resolved: res,
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return {
|
|
125
|
-
resolved: res[0],
|
|
126
|
-
pkg: res[1],
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export function resolveSync(
|
|
131
|
-
fs: FileSystem,
|
|
132
|
-
id: string,
|
|
133
|
-
opts: {|
|
|
134
|
-
...ResolveOptions,
|
|
135
|
-
basedir: string,
|
|
136
|
-
|},
|
|
137
|
-
): ResolveResult {
|
|
138
|
-
if (process.env.PARCEL_BUILD_ENV !== 'production') {
|
|
139
|
-
// Yarn patches resolve automatically in a non-linked setup
|
|
140
|
-
let pnp;
|
|
141
|
-
if (
|
|
142
|
-
process.versions.pnp != null &&
|
|
143
|
-
(!id.startsWith('@parcel') || id.startsWith('@parcel/watcher')) &&
|
|
144
|
-
(pnp = Module.findPnpApi(opts.basedir))
|
|
145
|
-
) {
|
|
146
|
-
try {
|
|
147
|
-
let res = pnp.resolveRequest(id, `${opts.basedir}/`, {
|
|
148
|
-
extensions: opts.extensions,
|
|
149
|
-
considerBuiltins: true,
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
if (!res) {
|
|
153
|
-
// builtin
|
|
154
|
-
return {resolved: id};
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
let pkgFile = resolveConfigSync(fs, res, ['package.json']);
|
|
158
|
-
let pkg = null;
|
|
159
|
-
if (pkgFile != null) {
|
|
160
|
-
pkg = JSON.parse(fs.readFileSync(pkgFile, 'utf8'));
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if (res) {
|
|
164
|
-
return {resolved: res, pkg};
|
|
165
|
-
}
|
|
166
|
-
} catch (e) {
|
|
167
|
-
if (e.code !== 'MODULE_NOT_FOUND') {
|
|
168
|
-
throw e;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// $FlowFixMe
|
|
174
|
-
opts.packageFilter = pkg => {
|
|
175
|
-
if (pkg.name.startsWith('@parcel/') && pkg.name !== '@parcel/watcher') {
|
|
176
|
-
if (pkg.source) {
|
|
177
|
-
pkg.main = pkg.source;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
return pkg;
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
if (id === 'pnpapi') {
|
|
185
|
-
// the resolve package doesn't recognize pnpapi as a builtin
|
|
186
|
-
return {resolved: 'pnpapi'};
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// $FlowFixMe
|
|
190
|
-
let res = _resolve.sync(id, {
|
|
191
|
-
...opts,
|
|
192
|
-
readFileSync: (...args) => {
|
|
193
|
-
return fs.readFileSync(...args);
|
|
194
|
-
},
|
|
195
|
-
isFile: file => {
|
|
196
|
-
try {
|
|
197
|
-
let stat = fs.statSync(file);
|
|
198
|
-
return stat.isFile();
|
|
199
|
-
} catch (err) {
|
|
200
|
-
return false;
|
|
201
|
-
}
|
|
202
|
-
},
|
|
203
|
-
isDirectory: file => {
|
|
204
|
-
try {
|
|
205
|
-
let stat = fs.statSync(file);
|
|
206
|
-
return stat.isDirectory();
|
|
207
|
-
} catch (err) {
|
|
208
|
-
return false;
|
|
209
|
-
}
|
|
210
|
-
},
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
return {
|
|
214
|
-
resolved: res,
|
|
215
|
-
};
|
|
216
|
-
}
|
package/src/serializeObject.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
|
-
import {minify} from 'terser';
|
|
4
|
-
import serialize from 'serialize-to-js';
|
|
5
|
-
|
|
6
|
-
export default function serializeObject(
|
|
7
|
-
obj: mixed,
|
|
8
|
-
shouldMinify: boolean = false,
|
|
9
|
-
) {
|
|
10
|
-
let code = `module.exports = ${serialize(obj)};`;
|
|
11
|
-
|
|
12
|
-
if (shouldMinify) {
|
|
13
|
-
let minified = minify(code);
|
|
14
|
-
if (minified.error) {
|
|
15
|
-
throw minified.error;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
code = minified.code;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return code;
|
|
22
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import assert from 'assert';
|
|
2
|
-
|
|
3
|
-
import {escapeMarkdown} from '../src/';
|
|
4
|
-
|
|
5
|
-
describe('escapeMarkdown', () => {
|
|
6
|
-
it('returns an escaped string 01', () => {
|
|
7
|
-
assert.equal('\\*test\\*', escapeMarkdown('*test*'));
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it('returns an escaped string 02', () => {
|
|
11
|
-
assert.equal('\\_test\\_', escapeMarkdown('_test_'));
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it('returns an escaped string 03', () => {
|
|
15
|
-
assert.equal('\\~test\\~', escapeMarkdown('~test~'));
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('returns an escaped string 04', () => {
|
|
19
|
-
assert.equal('\\*\\_\\~test\\~\\_\\*', escapeMarkdown('*_~test~_*'));
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('returns an escaped string with backslash 01', () => {
|
|
23
|
-
assert.equal('\\\\test\\\\', escapeMarkdown('\\test\\'));
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('returns an escaped string with backslash 02', () => {
|
|
27
|
-
assert.equal('\\\\\\*test\\*\\\\', escapeMarkdown('\\*test*\\'));
|
|
28
|
-
});
|
|
29
|
-
});
|