@parcel/utils 2.0.0-nightly.112 → 2.0.0-nightly.1127
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 +35509 -315
- package/lib/index.js.map +1 -0
- package/package.json +43 -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 +4 -3
- package/src/bundle-url.js +1 -1
- package/src/collection.js +14 -14
- package/src/config.js +100 -35
- package/src/countLines.js +5 -2
- package/src/debounce.js +1 -1
- package/src/dependency-location.js +11 -6
- package/src/generateBuildMetrics.js +158 -0
- 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 +39 -10
- package/src/hash.js +34 -0
- package/src/http-server.js +29 -19
- package/src/index.js +52 -23
- package/src/is-url.js +1 -1
- package/src/isDirectoryInside.js +11 -0
- package/src/openInBrowser.js +64 -0
- package/src/path.js +38 -6
- package/src/prettyDiagnostic.js +71 -24
- package/src/relativeBundlePath.js +8 -13
- package/src/replaceBundleReferences.js +85 -41
- package/src/schema.js +101 -44
- package/src/shared-buffer.js +24 -0
- package/src/sourcemap.js +135 -0
- package/src/stream.js +31 -1
- 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 +2 -0
- package/test/input/sourcemap/referenced-min.js.map +6 -0
- package/test/input/sourcemap/source-root.js +2 -0
- package/test/input/sourcemap/source-root.js.map +7 -0
- package/test/replaceBundleReferences.test.js +268 -0
- package/test/sourcemap.test.js +207 -0
- 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 -41
- 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 -88
- 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/generateBundleReport.js +0 -38
- 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 -76
- package/lib/http-server.js +0 -64
- package/lib/is-url.js +0 -17
- package/lib/loadSourceMapUrl.js +0 -33
- package/lib/md5.js +0 -35
- package/lib/objectHash.js +0 -26
- package/lib/parseCSSImport.js +0 -16
- package/lib/path.js +0 -22
- package/lib/prettifyTime.js +0 -10
- package/lib/prettyDiagnostic.js +0 -57
- package/lib/prettyError.js +0 -43
- package/lib/promisify.js +0 -13
- package/lib/relativeBundlePath.js +0 -24
- package/lib/relativeUrl.js +0 -16
- package/lib/replaceBundleReferences.js +0 -151
- package/lib/resolve.js +0 -93
- package/lib/schema.js +0 -320
- package/lib/serializeObject.js +0 -28
- package/lib/stream.js +0 -51
- package/lib/throttle.js +0 -16
- package/lib/urlJoin.js +0 -27
- package/src/.babelrc +0 -3
- package/src/generateBundleReport.js +0 -51
- package/src/loadSourceMapUrl.js +0 -33
- package/src/md5.js +0 -44
- package/src/prettyError.js +0 -54
- package/src/promisify.js +0 -13
- package/src/resolve.js +0 -135
- package/src/serializeObject.js +0 -22
- package/test/input/sourcemap/referenced.js +0 -7
- package/test/loadSourceMapUrl.test.js +0 -37
- package/test/prettyError.test.js +0 -104
package/src/resolve.js
DELETED
|
@@ -1,135 +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
|
-
|
|
16
|
-
const resolveAsync = promisify(_resolve);
|
|
17
|
-
|
|
18
|
-
export type ResolveResult = {|
|
|
19
|
-
resolved: FilePath | ModuleSpecifier,
|
|
20
|
-
pkg?: ?PackageJSON,
|
|
21
|
-
|};
|
|
22
|
-
|
|
23
|
-
export async function resolve(
|
|
24
|
-
fs: FileSystem,
|
|
25
|
-
id: string,
|
|
26
|
-
opts?: {|
|
|
27
|
-
range?: ?SemverRange,
|
|
28
|
-
...ResolveOptions,
|
|
29
|
-
|},
|
|
30
|
-
): Promise<ResolveResult> {
|
|
31
|
-
if (process.env.PARCEL_BUILD_ENV !== 'production') {
|
|
32
|
-
// $FlowFixMe
|
|
33
|
-
opts = opts || {};
|
|
34
|
-
// $FlowFixMe
|
|
35
|
-
opts.packageFilter = pkg => {
|
|
36
|
-
if (
|
|
37
|
-
typeof pkg.name === 'string' &&
|
|
38
|
-
pkg.name.startsWith('@parcel/') &&
|
|
39
|
-
pkg.name !== '@parcel/watcher'
|
|
40
|
-
) {
|
|
41
|
-
if (pkg.source) {
|
|
42
|
-
pkg.main = pkg.source;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return pkg;
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
let res = await resolveAsync(id, {
|
|
50
|
-
...opts,
|
|
51
|
-
async readFile(filename, callback) {
|
|
52
|
-
try {
|
|
53
|
-
let res = await fs.readFile(filename);
|
|
54
|
-
callback(null, res);
|
|
55
|
-
} catch (err) {
|
|
56
|
-
callback(err);
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
async isFile(file, callback) {
|
|
60
|
-
try {
|
|
61
|
-
let stat = await fs.stat(file);
|
|
62
|
-
callback(null, stat.isFile());
|
|
63
|
-
} catch (err) {
|
|
64
|
-
callback(null, false);
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
async isDirectory(file, callback) {
|
|
68
|
-
try {
|
|
69
|
-
let stat = await fs.stat(file);
|
|
70
|
-
callback(null, stat.isDirectory());
|
|
71
|
-
} catch (err) {
|
|
72
|
-
callback(null, false);
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
if (typeof res === 'string') {
|
|
78
|
-
return {
|
|
79
|
-
resolved: res,
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return {
|
|
84
|
-
resolved: res[0],
|
|
85
|
-
pkg: res[1],
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export function resolveSync(
|
|
90
|
-
fs: FileSystem,
|
|
91
|
-
id: string,
|
|
92
|
-
opts?: ResolveOptions,
|
|
93
|
-
): ResolveResult {
|
|
94
|
-
if (process.env.PARCEL_BUILD_ENV !== 'production') {
|
|
95
|
-
// $FlowFixMe
|
|
96
|
-
opts = opts || {};
|
|
97
|
-
// $FlowFixMe
|
|
98
|
-
opts.packageFilter = pkg => {
|
|
99
|
-
if (pkg.name.startsWith('@parcel/') && pkg.name !== '@parcel/watcher') {
|
|
100
|
-
if (pkg.source) {
|
|
101
|
-
pkg.main = pkg.source;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return pkg;
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// $FlowFixMe
|
|
109
|
-
let res = _resolve.sync(id, {
|
|
110
|
-
...opts,
|
|
111
|
-
readFileSync: (...args) => {
|
|
112
|
-
return fs.readFileSync(...args);
|
|
113
|
-
},
|
|
114
|
-
isFile: file => {
|
|
115
|
-
try {
|
|
116
|
-
let stat = fs.statSync(file);
|
|
117
|
-
return stat.isFile();
|
|
118
|
-
} catch (err) {
|
|
119
|
-
return false;
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
isDirectory: file => {
|
|
123
|
-
try {
|
|
124
|
-
let stat = fs.statSync(file);
|
|
125
|
-
return stat.isDirectory();
|
|
126
|
-
} catch (err) {
|
|
127
|
-
return false;
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
return {
|
|
133
|
-
resolved: res,
|
|
134
|
-
};
|
|
135
|
-
}
|
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,37 +0,0 @@
|
|
|
1
|
-
import assert from 'assert';
|
|
2
|
-
import {matchSourceMappingURL} from '../src/loadSourceMapUrl';
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
|
|
6
|
-
describe('loadSourceMap', () => {
|
|
7
|
-
it('should not match sourceMappingURL when not at the end of the bundle', () => {
|
|
8
|
-
// Code example taken from livescript.js (issue #2408 in parcel-bundler)
|
|
9
|
-
// This snippet lead to JSAsset.js being mislead and incorrectly trying to
|
|
10
|
-
// load (due to false-positive match) sourcemap before fix was introduced
|
|
11
|
-
let code = fs.readFileSync(
|
|
12
|
-
path.join(__dirname, './input/sourcemap/no-sourcemap.js'),
|
|
13
|
-
'utf-8',
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
assert(!matchSourceMappingURL(code));
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('should match referenced sourceMappingURL when correctly inserted at end of the bundle', () => {
|
|
20
|
-
let code = fs.readFileSync(
|
|
21
|
-
path.join(__dirname, './input/sourcemap/referenced.js'),
|
|
22
|
-
'utf-8',
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
assert(!!matchSourceMappingURL(code));
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('should match inline sourceMappingURL when correctly inserted at end of the bundle', () => {
|
|
29
|
-
// inline source map taken from https://github.com/thlorenz/inline-source-map
|
|
30
|
-
let code = fs.readFileSync(
|
|
31
|
-
path.join(__dirname, './input/sourcemap/inline.js'),
|
|
32
|
-
'utf-8',
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
assert(!!matchSourceMappingURL(code));
|
|
36
|
-
});
|
|
37
|
-
});
|
package/test/prettyError.test.js
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import assert from 'assert';
|
|
2
|
-
import prettyError from '../src/prettyError';
|
|
3
|
-
|
|
4
|
-
const message = 'Error Message!';
|
|
5
|
-
const fileName = 'Test.js';
|
|
6
|
-
const codeFrame = '<code>frame</code>';
|
|
7
|
-
const stack =
|
|
8
|
-
'Error: Uh-oh. Something went wrong. Line 88. \n Oh no. Something else went wrong. Line 77 \n';
|
|
9
|
-
|
|
10
|
-
describe('prettyError', () => {
|
|
11
|
-
it('should handle passing error as string', () => {
|
|
12
|
-
const err = prettyError(message);
|
|
13
|
-
|
|
14
|
-
assert.equal(err.message, message);
|
|
15
|
-
assert.equal(err.stack, undefined);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('should handle passing error as object', () => {
|
|
19
|
-
const err = prettyError({message});
|
|
20
|
-
|
|
21
|
-
assert.equal(err.message, message);
|
|
22
|
-
assert.equal(err.stack, undefined);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('should handle unknown input', () => {
|
|
26
|
-
const err = prettyError(Number.NaN);
|
|
27
|
-
|
|
28
|
-
assert(err.message.length); // non-empty error message
|
|
29
|
-
assert.equal(err.stack, undefined);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('should prepend fileName', () => {
|
|
33
|
-
const err = prettyError({
|
|
34
|
-
message,
|
|
35
|
-
fileName,
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
assert(err.message.startsWith(fileName));
|
|
39
|
-
assert.equal(err.stack, undefined);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('should prepend line and column location', () => {
|
|
43
|
-
const err = prettyError({
|
|
44
|
-
message,
|
|
45
|
-
fileName,
|
|
46
|
-
loc: {
|
|
47
|
-
line: 1,
|
|
48
|
-
column: 10,
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
assert(err.message.startsWith(`${fileName}:1:10`));
|
|
53
|
-
assert.equal(err.stack, undefined);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('should support providing a codeFrame as stack', () => {
|
|
57
|
-
const err = prettyError({
|
|
58
|
-
message,
|
|
59
|
-
stack,
|
|
60
|
-
codeFrame: codeFrame,
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
assert.equal(err.message, message);
|
|
64
|
-
assert.equal(err.stack, codeFrame);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('should support highlightedCodeFrame when opts.color is true', () => {
|
|
68
|
-
let err = prettyError(
|
|
69
|
-
{
|
|
70
|
-
message,
|
|
71
|
-
stack,
|
|
72
|
-
codeFrame: '<not>a code frame</not>',
|
|
73
|
-
highlightedCodeFrame: codeFrame,
|
|
74
|
-
},
|
|
75
|
-
{color: true},
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
assert.equal(err.message, message);
|
|
79
|
-
assert.equal(err.stack, codeFrame);
|
|
80
|
-
|
|
81
|
-
err = prettyError(
|
|
82
|
-
{
|
|
83
|
-
message,
|
|
84
|
-
stack,
|
|
85
|
-
codeFrame: codeFrame,
|
|
86
|
-
highlightedCodeFrame: '<not>a code frame</not>',
|
|
87
|
-
},
|
|
88
|
-
{color: false},
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
assert.equal(err.message, message);
|
|
92
|
-
assert.equal(err.stack, codeFrame);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('should support stack', () => {
|
|
96
|
-
const err = prettyError({
|
|
97
|
-
message,
|
|
98
|
-
stack,
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
assert.equal(err.message, message);
|
|
102
|
-
assert(err.stack.includes('Line'));
|
|
103
|
-
});
|
|
104
|
-
});
|