@parcel/utils 2.0.0-nightly.143 → 2.0.0-nightly.1431

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.
Files changed (105) hide show
  1. package/.eslintrc.js +6 -6
  2. package/lib/index.js +37531 -318
  3. package/lib/index.js.map +1 -0
  4. package/package.json +47 -20
  5. package/src/DefaultMap.js +1 -1
  6. package/src/PromiseQueue.js +16 -12
  7. package/src/alternatives.js +145 -0
  8. package/src/ansi-html.js +2 -2
  9. package/src/blob.js +2 -1
  10. package/src/bundle-url.js +1 -1
  11. package/src/collection.js +35 -15
  12. package/src/config.js +132 -45
  13. package/src/countLines.js +5 -2
  14. package/src/debounce.js +1 -1
  15. package/src/dependency-location.js +11 -6
  16. package/src/generateBuildMetrics.js +158 -0
  17. package/src/generateCertificate.js +1 -1
  18. package/src/getCertificate.js +1 -1
  19. package/src/getExisting.js +1 -4
  20. package/src/getModuleParts.js +23 -0
  21. package/src/getRootDir.js +1 -2
  22. package/src/glob.js +51 -10
  23. package/src/hash.js +49 -0
  24. package/src/http-server.js +29 -19
  25. package/src/index.js +68 -22
  26. package/src/is-url.js +1 -1
  27. package/src/isDirectoryInside.js +11 -0
  28. package/src/openInBrowser.js +64 -0
  29. package/src/path.js +38 -6
  30. package/src/prettyDiagnostic.js +102 -30
  31. package/src/progress-message.js +22 -0
  32. package/src/relativeBundlePath.js +8 -13
  33. package/src/replaceBundleReferences.js +85 -41
  34. package/src/schema.js +100 -44
  35. package/src/shared-buffer.js +23 -0
  36. package/src/sourcemap.js +138 -0
  37. package/src/stream.js +31 -1
  38. package/src/urlJoin.js +3 -1
  39. package/test/DefaultMap.test.js +7 -4
  40. package/test/collection.test.js +13 -1
  41. package/test/config.test.js +98 -0
  42. package/test/input/config/.testrc +3 -0
  43. package/test/input/config/config.cjs +3 -0
  44. package/test/input/config/config.js +3 -0
  45. package/test/input/config/config.json +3 -0
  46. package/test/input/config/empty.json +0 -0
  47. package/test/input/config/empty.toml +0 -0
  48. package/test/input/sourcemap/referenced-min.js +2 -0
  49. package/test/input/sourcemap/referenced-min.js.map +6 -0
  50. package/test/input/sourcemap/source-root.js +2 -0
  51. package/test/input/sourcemap/source-root.js.map +7 -0
  52. package/test/replaceBundleReferences.test.js +268 -0
  53. package/test/sourcemap.test.js +207 -0
  54. package/test/throttle.test.js +1 -2
  55. package/test/urlJoin.test.js +37 -0
  56. package/lib/DefaultMap.js +0 -64
  57. package/lib/Deferred.js +0 -26
  58. package/lib/PromiseQueue.js +0 -133
  59. package/lib/TapStream.js +0 -41
  60. package/lib/ansi-html.js +0 -16
  61. package/lib/blob.js +0 -31
  62. package/lib/bundle-url.js +0 -43
  63. package/lib/collection.js +0 -62
  64. package/lib/config.js +0 -88
  65. package/lib/countLines.js +0 -18
  66. package/lib/debounce.js +0 -20
  67. package/lib/dependency-location.js +0 -21
  68. package/lib/escape-html.js +0 -24
  69. package/lib/escape-markdown.js +0 -15
  70. package/lib/generateBundleReport.js +0 -38
  71. package/lib/generateCertificate.js +0 -124
  72. package/lib/getCertificate.js +0 -19
  73. package/lib/getExisting.js +0 -23
  74. package/lib/getRootDir.js +0 -55
  75. package/lib/glob.js +0 -76
  76. package/lib/http-server.js +0 -64
  77. package/lib/is-url.js +0 -17
  78. package/lib/loadSourceMapUrl.js +0 -33
  79. package/lib/md5.js +0 -35
  80. package/lib/objectHash.js +0 -26
  81. package/lib/parseCSSImport.js +0 -16
  82. package/lib/path.js +0 -22
  83. package/lib/prettifyTime.js +0 -10
  84. package/lib/prettyDiagnostic.js +0 -57
  85. package/lib/promisify.js +0 -13
  86. package/lib/relativeBundlePath.js +0 -24
  87. package/lib/relativeUrl.js +0 -16
  88. package/lib/replaceBundleReferences.js +0 -151
  89. package/lib/resolve.js +0 -93
  90. package/lib/schema.js +0 -320
  91. package/lib/serializeObject.js +0 -28
  92. package/lib/stream.js +0 -51
  93. package/lib/throttle.js +0 -16
  94. package/lib/urlJoin.js +0 -27
  95. package/src/.babelrc +0 -3
  96. package/src/escape-markdown.js +0 -10
  97. package/src/generateBundleReport.js +0 -51
  98. package/src/loadSourceMapUrl.js +0 -33
  99. package/src/md5.js +0 -44
  100. package/src/promisify.js +0 -13
  101. package/src/resolve.js +0 -135
  102. package/src/serializeObject.js +0 -22
  103. package/test/escapeMarkdown.test.js +0 -29
  104. package/test/input/sourcemap/referenced.js +0 -7
  105. package/test/loadSourceMapUrl.test.js +0 -37
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
- }
@@ -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
- });
@@ -1,7 +0,0 @@
1
- function hello() {
2
- var l = 'Hello',
3
- o = 'world';
4
- console.log(l + ' ' + o + '!');
5
- }
6
- hello();
7
- //# sourceMappingURL=main.min.js.map
@@ -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
- });