@parcel/utils 2.0.0-nightly.978 → 2.0.0-nightly.992

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 (45) hide show
  1. package/lib/index.js +35876 -411
  2. package/lib/index.js.map +1 -0
  3. package/package.json +28 -15
  4. package/src/config.js +2 -2
  5. package/src/glob.js +14 -3
  6. package/src/index.js +1 -1
  7. package/lib/DefaultMap.js +0 -56
  8. package/lib/Deferred.js +0 -34
  9. package/lib/PromiseQueue.js +0 -124
  10. package/lib/TapStream.js +0 -41
  11. package/lib/alternatives.js +0 -134
  12. package/lib/ansi-html.js +0 -24
  13. package/lib/blob.js +0 -49
  14. package/lib/bundle-url.js +0 -43
  15. package/lib/collection.js +0 -65
  16. package/lib/config.js +0 -198
  17. package/lib/countLines.js +0 -18
  18. package/lib/debounce.js +0 -20
  19. package/lib/dependency-location.js +0 -21
  20. package/lib/escape-html.js +0 -24
  21. package/lib/generateBuildMetrics.js +0 -148
  22. package/lib/generateCertificate.js +0 -149
  23. package/lib/getCertificate.js +0 -19
  24. package/lib/getExisting.js +0 -31
  25. package/lib/getRootDir.js +0 -66
  26. package/lib/glob.js +0 -110
  27. package/lib/hash.js +0 -44
  28. package/lib/http-server.js +0 -102
  29. package/lib/is-url.js +0 -27
  30. package/lib/isDirectoryInside.js +0 -24
  31. package/lib/objectHash.js +0 -34
  32. package/lib/openInBrowser.js +0 -94
  33. package/lib/parseCSSImport.js +0 -16
  34. package/lib/path.js +0 -49
  35. package/lib/prettifyTime.js +0 -10
  36. package/lib/prettyDiagnostic.js +0 -139
  37. package/lib/relativeBundlePath.js +0 -30
  38. package/lib/relativeUrl.js +0 -32
  39. package/lib/replaceBundleReferences.js +0 -211
  40. package/lib/schema.js +0 -391
  41. package/lib/shared-buffer.js +0 -31
  42. package/lib/sourcemap.js +0 -147
  43. package/lib/stream.js +0 -86
  44. package/lib/throttle.js +0 -16
  45. package/lib/urlJoin.js +0 -46
@@ -1,139 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = prettyDiagnostic;
7
-
8
- function _codeframe() {
9
- const data = _interopRequireDefault(require("@parcel/codeframe"));
10
-
11
- _codeframe = function () {
12
- return data;
13
- };
14
-
15
- return data;
16
- }
17
-
18
- function _markdownAnsi() {
19
- const data = _interopRequireDefault(require("@parcel/markdown-ansi"));
20
-
21
- _markdownAnsi = function () {
22
- return data;
23
- };
24
-
25
- return data;
26
- }
27
-
28
- function _chalk() {
29
- const data = _interopRequireDefault(require("chalk"));
30
-
31
- _chalk = function () {
32
- return data;
33
- };
34
-
35
- return data;
36
- }
37
-
38
- function _path() {
39
- const data = _interopRequireDefault(require("path"));
40
-
41
- _path = function () {
42
- return data;
43
- };
44
-
45
- return data;
46
- }
47
-
48
- function _nullthrows() {
49
- const data = _interopRequireDefault(require("nullthrows"));
50
-
51
- _nullthrows = function () {
52
- return data;
53
- };
54
-
55
- return data;
56
- }
57
-
58
- function _terminalLink() {
59
- const data = _interopRequireDefault(require("terminal-link"));
60
-
61
- _terminalLink = function () {
62
- return data;
63
- };
64
-
65
- return data;
66
- }
67
-
68
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
69
-
70
- // $FlowFixMe
71
- async function prettyDiagnostic(diagnostic, options, terminalWidth) {
72
- let {
73
- origin,
74
- message,
75
- stack,
76
- codeFrames,
77
- hints,
78
- skipFormatting,
79
- documentationURL
80
- } = diagnostic;
81
- let result = {
82
- message: (0, _markdownAnsi().default)(`**${origin !== null && origin !== void 0 ? origin : 'unknown'}**: `) + (skipFormatting ? message : (0, _markdownAnsi().default)(message)),
83
- stack: '',
84
- codeframe: '',
85
- hints: [],
86
- documentation: ''
87
- };
88
-
89
- if (codeFrames != null) {
90
- for (let codeFrame of codeFrames) {
91
- var _codeFrame$code;
92
-
93
- let filePath = codeFrame.filePath;
94
-
95
- if (filePath != null && options && !_path().default.isAbsolute(filePath)) {
96
- filePath = _path().default.join(options.projectRoot, filePath);
97
- }
98
-
99
- let highlights = codeFrame.codeHighlights;
100
- let code = (_codeFrame$code = codeFrame.code) !== null && _codeFrame$code !== void 0 ? _codeFrame$code : options && (await options.inputFS.readFile((0, _nullthrows().default)(filePath), 'utf8'));
101
- let formattedCodeFrame = '';
102
-
103
- if (code != null) {
104
- formattedCodeFrame = (0, _codeframe().default)(code, highlights, {
105
- useColor: true,
106
- syntaxHighlighting: true,
107
- language: // $FlowFixMe sketchy null checks do not matter here...
108
- codeFrame.language || (filePath != null ? _path().default.extname(filePath).substr(1) : undefined),
109
- terminalWidth
110
- });
111
- }
112
-
113
- result.codeframe += typeof filePath !== 'string' ? '' : _chalk().default.gray.underline(`${filePath}:${highlights[0].start.line}:${highlights[0].start.column}\n`);
114
- result.codeframe += formattedCodeFrame;
115
-
116
- if (codeFrame !== codeFrames[codeFrames.length - 1]) {
117
- result.codeframe += '\n\n';
118
- }
119
- }
120
- }
121
-
122
- if (stack != null) {
123
- result.stack = stack;
124
- }
125
-
126
- if (Array.isArray(hints) && hints.length) {
127
- result.hints = hints.map(h => {
128
- return (0, _markdownAnsi().default)(h);
129
- });
130
- }
131
-
132
- if (documentationURL != null) {
133
- result.documentation = (0, _terminalLink().default)('Learn more', documentationURL, {
134
- fallback: (text, url) => `${text}: ${url}`
135
- });
136
- }
137
-
138
- return result;
139
- }
@@ -1,30 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.relativeBundlePath = relativeBundlePath;
7
-
8
- function _path() {
9
- const data = _interopRequireDefault(require("path"));
10
-
11
- _path = function () {
12
- return data;
13
- };
14
-
15
- return data;
16
- }
17
-
18
- var _path2 = require("./path");
19
-
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
-
22
- function relativeBundlePath(from, to, opts = {
23
- leadingDotSlash: true
24
- }) {
25
- let fromPath = _path().default.join(from.target.distDir, from.name);
26
-
27
- let toPath = _path().default.join(to.target.distDir, to.name);
28
-
29
- return (0, _path2.relativePath)(_path().default.dirname(fromPath), toPath, opts.leadingDotSlash);
30
- }
@@ -1,32 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = relativeUrl;
7
-
8
- function _path() {
9
- const data = _interopRequireDefault(require("path"));
10
-
11
- _path = function () {
12
- return data;
13
- };
14
-
15
- return data;
16
- }
17
-
18
- function _url() {
19
- const data = _interopRequireDefault(require("url"));
20
-
21
- _url = function () {
22
- return data;
23
- };
24
-
25
- return data;
26
- }
27
-
28
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
-
30
- function relativeUrl(from, to) {
31
- return _url().default.format(_url().default.parse(_path().default.relative(from, to)));
32
- }
@@ -1,211 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.replaceURLReferences = replaceURLReferences;
7
- exports.replaceInlineReferences = replaceInlineReferences;
8
- exports.getURLReplacement = getURLReplacement;
9
-
10
- function _stream() {
11
- const data = require("stream");
12
-
13
- _stream = function () {
14
- return data;
15
- };
16
-
17
- return data;
18
- }
19
-
20
- function _nullthrows() {
21
- const data = _interopRequireDefault(require("nullthrows"));
22
-
23
- _nullthrows = function () {
24
- return data;
25
- };
26
-
27
- return data;
28
- }
29
-
30
- function _assert() {
31
- const data = _interopRequireDefault(require("assert"));
32
-
33
- _assert = function () {
34
- return data;
35
- };
36
-
37
- return data;
38
- }
39
-
40
- function _url() {
41
- const data = _interopRequireDefault(require("url"));
42
-
43
- _url = function () {
44
- return data;
45
- };
46
-
47
- return data;
48
- }
49
-
50
- var _ = require("./");
51
-
52
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
53
-
54
- /*
55
- * Replaces references to dependency ids for URL dependencies with:
56
- * - in the case of an unresolvable url dependency, the original specifier.
57
- * These are external requests that Parcel did not bundle.
58
- * - in the case of a reference to another bundle, the relative url to that
59
- * bundle from the current bundle.
60
- */
61
- function replaceURLReferences({
62
- bundle,
63
- bundleGraph,
64
- contents,
65
- map,
66
- relative = true
67
- }) {
68
- let replacements = new Map();
69
- let urlDependencies = [];
70
- bundle.traverse(node => {
71
- if (node.type === 'dependency' && node.value.specifierType === 'url') {
72
- urlDependencies.push(node.value);
73
- }
74
- });
75
-
76
- for (let dependency of urlDependencies) {
77
- var _dependency$meta$plac, _dependency$meta;
78
-
79
- if (dependency.specifierType !== 'url') {
80
- continue;
81
- }
82
-
83
- let placeholder = (_dependency$meta$plac = (_dependency$meta = dependency.meta) === null || _dependency$meta === void 0 ? void 0 : _dependency$meta.placeholder) !== null && _dependency$meta$plac !== void 0 ? _dependency$meta$plac : dependency.id;
84
- (0, _assert().default)(typeof placeholder === 'string');
85
- let resolved = bundleGraph.getReferencedBundle(dependency, bundle);
86
-
87
- if (resolved == null) {
88
- replacements.set(placeholder, {
89
- from: placeholder,
90
- to: dependency.specifier
91
- });
92
- continue;
93
- }
94
-
95
- if (resolved.bundleBehavior === 'inline') {
96
- // If a bundle is inline, it should be replaced with inline contents,
97
- // not a URL.
98
- continue;
99
- }
100
-
101
- replacements.set(placeholder, getURLReplacement({
102
- dependency,
103
- fromBundle: bundle,
104
- toBundle: resolved,
105
- relative
106
- }));
107
- }
108
-
109
- return performReplacement(replacements, contents, map);
110
- }
111
- /*
112
- * Replaces references to dependency ids for inline bundles with the packaged
113
- * contents of that bundle.
114
- */
115
-
116
-
117
- async function replaceInlineReferences({
118
- bundle,
119
- bundleGraph,
120
- contents,
121
- map,
122
- getInlineReplacement,
123
- getInlineBundleContents
124
- }) {
125
- let replacements = new Map();
126
- let dependencies = [];
127
- bundle.traverse(node => {
128
- if (node.type === 'dependency') {
129
- dependencies.push(node.value);
130
- }
131
- });
132
-
133
- for (let dependency of dependencies) {
134
- let entryBundle = bundleGraph.getReferencedBundle(dependency, bundle);
135
-
136
- if ((entryBundle === null || entryBundle === void 0 ? void 0 : entryBundle.bundleBehavior) !== 'inline') {
137
- continue;
138
- }
139
-
140
- let packagedBundle = await getInlineBundleContents(entryBundle, bundleGraph);
141
- let packagedContents = (packagedBundle.contents instanceof _stream().Readable ? await (0, _.bufferStream)(packagedBundle.contents) : packagedBundle.contents).toString();
142
- let inlineType = (0, _nullthrows().default)(entryBundle.getMainEntry()).meta.inlineType;
143
-
144
- if (inlineType == null || inlineType === 'string') {
145
- var _dependency$meta$plac2, _dependency$meta2;
146
-
147
- let placeholder = (_dependency$meta$plac2 = (_dependency$meta2 = dependency.meta) === null || _dependency$meta2 === void 0 ? void 0 : _dependency$meta2.placeholder) !== null && _dependency$meta$plac2 !== void 0 ? _dependency$meta$plac2 : dependency.id;
148
- (0, _assert().default)(typeof placeholder === 'string');
149
- replacements.set(placeholder, getInlineReplacement(dependency, inlineType, packagedContents));
150
- }
151
- }
152
-
153
- return performReplacement(replacements, contents, map);
154
- }
155
-
156
- function getURLReplacement({
157
- dependency,
158
- fromBundle,
159
- toBundle,
160
- relative
161
- }) {
162
- var _dependency$meta$plac3, _dependency$meta3;
163
-
164
- let to;
165
-
166
- let orig = _url().default.parse(dependency.specifier);
167
-
168
- if (relative) {
169
- to = _url().default.format({
170
- pathname: (0, _.relativeBundlePath)(fromBundle, toBundle, {
171
- leadingDotSlash: false
172
- }),
173
- hash: orig.hash
174
- }); // If the resulting path includes a colon character and doesn't start with a ./ or ../
175
- // we need to add one so that the first part before the colon isn't parsed as a URL protocol.
176
-
177
- if (to.includes(':') && !to.startsWith('./') && !to.startsWith('../')) {
178
- to = './' + to;
179
- }
180
- } else {
181
- to = (0, _.urlJoin)(toBundle.target.publicUrl, _url().default.format({
182
- pathname: (0, _nullthrows().default)(toBundle.name),
183
- hash: orig.hash
184
- }));
185
- }
186
-
187
- let placeholder = (_dependency$meta$plac3 = (_dependency$meta3 = dependency.meta) === null || _dependency$meta3 === void 0 ? void 0 : _dependency$meta3.placeholder) !== null && _dependency$meta$plac3 !== void 0 ? _dependency$meta$plac3 : dependency.id;
188
- (0, _assert().default)(typeof placeholder === 'string');
189
- return {
190
- from: placeholder,
191
- to
192
- };
193
- }
194
-
195
- function performReplacement(replacements, contents, map) {
196
- let finalContents = contents;
197
-
198
- for (let {
199
- from,
200
- to
201
- } of replacements.values()) {
202
- // Perform replacement
203
- finalContents = finalContents.split(from).join(to);
204
- }
205
-
206
- return {
207
- contents: finalContents,
208
- // TODO: Update sourcemap with adjusted contents
209
- map
210
- };
211
- }