@parcel/utils 2.2.0 → 2.3.2

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 +27 -14
  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
package/lib/sourcemap.js DELETED
@@ -1,147 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.matchSourceMappingURL = matchSourceMappingURL;
7
- exports.loadSourceMapUrl = loadSourceMapUrl;
8
- exports.loadSourceMap = loadSourceMap;
9
- exports.remapSourceLocation = remapSourceLocation;
10
- exports.SOURCEMAP_EXTENSIONS = exports.SOURCEMAP_RE = void 0;
11
-
12
- function _sourceMap() {
13
- const data = _interopRequireDefault(require("@parcel/source-map"));
14
-
15
- _sourceMap = function () {
16
- return data;
17
- };
18
-
19
- return data;
20
- }
21
-
22
- function _path() {
23
- const data = _interopRequireDefault(require("path"));
24
-
25
- _path = function () {
26
- return data;
27
- };
28
-
29
- return data;
30
- }
31
-
32
- var _path2 = require("./path");
33
-
34
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
35
-
36
- const SOURCEMAP_RE = /(?:\/\*|\/\/)\s*[@#]\s*sourceMappingURL\s*=\s*([^\s*]+)(?:\s*\*\/)?\s*$/;
37
- exports.SOURCEMAP_RE = SOURCEMAP_RE;
38
- const DATA_URL_RE = /^data:[^;]+(?:;charset=[^;]+)?;base64,(.*)/;
39
- const SOURCEMAP_EXTENSIONS = new Set(['css', 'es', 'es6', 'js', 'jsx', 'mjs', 'ts', 'tsx']);
40
- exports.SOURCEMAP_EXTENSIONS = SOURCEMAP_EXTENSIONS;
41
-
42
- function matchSourceMappingURL(contents) {
43
- return contents.match(SOURCEMAP_RE);
44
- }
45
-
46
- async function loadSourceMapUrl(fs, filename, contents) {
47
- let match = matchSourceMappingURL(contents);
48
-
49
- if (match) {
50
- let url = match[1].trim();
51
- let dataURLMatch = url.match(DATA_URL_RE);
52
- let mapFilePath;
53
-
54
- if (dataURLMatch) {
55
- mapFilePath = filename;
56
- } else {
57
- mapFilePath = url.replace(/^file:\/\//, '');
58
- mapFilePath = (0, _path2.isAbsolute)(mapFilePath) ? mapFilePath : _path().default.join(_path().default.dirname(filename), mapFilePath);
59
- }
60
-
61
- return {
62
- url,
63
- filename: mapFilePath,
64
- map: JSON.parse(dataURLMatch ? Buffer.from(dataURLMatch[1], 'base64').toString() : await fs.readFile(mapFilePath, 'utf8'))
65
- };
66
- }
67
- }
68
-
69
- async function loadSourceMap(filename, contents, options) {
70
- let foundMap = await loadSourceMapUrl(options.fs, filename, contents);
71
-
72
- if (foundMap) {
73
- let mapSourceRoot = _path().default.dirname(filename);
74
-
75
- if (foundMap.map.sourceRoot && !(0, _path2.normalizeSeparators)(foundMap.map.sourceRoot).startsWith('/')) {
76
- mapSourceRoot = _path().default.join(mapSourceRoot, foundMap.map.sourceRoot);
77
- }
78
-
79
- let sourcemapInstance = new (_sourceMap().default)(options.projectRoot);
80
- sourcemapInstance.addVLQMap({ ...foundMap.map,
81
- sources: foundMap.map.sources.map(s => {
82
- return _path().default.join(mapSourceRoot, s);
83
- })
84
- });
85
- return sourcemapInstance;
86
- }
87
- }
88
-
89
- function remapSourceLocation(loc, originalMap) {
90
- let {
91
- filePath,
92
- start: {
93
- line: startLine,
94
- column: startCol
95
- },
96
- end: {
97
- line: endLine,
98
- column: endCol
99
- }
100
- } = loc;
101
- let lineDiff = endLine - startLine;
102
- let colDiff = endCol - startCol;
103
- let start = originalMap.findClosestMapping(startLine, startCol);
104
- let end = originalMap.findClosestMapping(endLine, endCol);
105
-
106
- if (start !== null && start !== void 0 && start.original) {
107
- if (start.source) {
108
- filePath = start.source;
109
- }
110
-
111
- ({
112
- line: startLine,
113
- column: startCol
114
- } = start.original);
115
- startCol++; // source map columns are 0-based
116
- }
117
-
118
- if (end !== null && end !== void 0 && end.original) {
119
- ({
120
- line: endLine,
121
- column: endCol
122
- } = end.original);
123
- endCol++;
124
-
125
- if (endLine < startLine) {
126
- endLine = startLine;
127
- endCol = startCol;
128
- } else if (endLine === startLine && endCol < startCol && lineDiff === 0) {
129
- endCol = startCol + colDiff;
130
- }
131
- } else {
132
- endLine = startLine;
133
- endCol = startCol;
134
- }
135
-
136
- return {
137
- filePath,
138
- start: {
139
- line: startLine,
140
- column: startCol
141
- },
142
- end: {
143
- line: endLine,
144
- column: endCol
145
- }
146
- };
147
- }
package/lib/stream.js DELETED
@@ -1,86 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.measureStreamLength = measureStreamLength;
7
- exports.readableFromStringOrBuffer = readableFromStringOrBuffer;
8
- exports.bufferStream = bufferStream;
9
- exports.blobToStream = blobToStream;
10
- exports.streamFromPromise = streamFromPromise;
11
- exports.fallbackStream = fallbackStream;
12
-
13
- function _stream() {
14
- const data = require("stream");
15
-
16
- _stream = function () {
17
- return data;
18
- };
19
-
20
- return data;
21
- }
22
-
23
- function measureStreamLength(stream) {
24
- return new Promise((resolve, reject) => {
25
- let length = 0;
26
- stream.on('data', chunk => {
27
- length += chunk;
28
- });
29
- stream.on('end', () => resolve(length));
30
- stream.on('error', reject);
31
- });
32
- }
33
-
34
- function readableFromStringOrBuffer(str) {
35
- // https://stackoverflow.com/questions/12755997/how-to-create-streams-from-string-in-node-js
36
- const stream = new (_stream().Readable)();
37
- stream.push(str);
38
- stream.push(null);
39
- return stream;
40
- }
41
-
42
- function bufferStream(stream) {
43
- return new Promise((resolve, reject) => {
44
- let buf = Buffer.from([]);
45
- stream.on('data', data => {
46
- buf = Buffer.concat([buf, data]);
47
- });
48
- stream.on('end', () => {
49
- resolve(buf);
50
- });
51
- stream.on('error', reject);
52
- });
53
- }
54
-
55
- function blobToStream(blob) {
56
- if (blob instanceof _stream().Readable) {
57
- return blob;
58
- }
59
-
60
- return readableFromStringOrBuffer(blob);
61
- }
62
-
63
- function streamFromPromise(promise) {
64
- const stream = new (_stream().PassThrough)();
65
- promise.then(blob => {
66
- if (blob instanceof _stream().Readable) {
67
- blob.pipe(stream);
68
- } else {
69
- stream.end(blob);
70
- }
71
- });
72
- return stream;
73
- }
74
-
75
- function fallbackStream(stream, fallback) {
76
- const res = new (_stream().PassThrough)();
77
- stream.on('error', err => {
78
- if (err.code === 'ENOENT') {
79
- fallback().pipe(res);
80
- } else {
81
- res.emit('error', err);
82
- }
83
- });
84
- stream.pipe(res);
85
- return res;
86
- }
package/lib/throttle.js DELETED
@@ -1,16 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = throttle;
7
-
8
- function throttle(fn, delay) {
9
- let lastCalled;
10
- return function (...args) {
11
- if (lastCalled == null || lastCalled + delay <= Date.now()) {
12
- fn.call(this, ...args);
13
- lastCalled = Date.now();
14
- }
15
- };
16
- }
package/lib/urlJoin.js DELETED
@@ -1,46 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = urlJoin;
7
-
8
- function _url() {
9
- const data = _interopRequireDefault(require("url"));
10
-
11
- _url = function () {
12
- return data;
13
- };
14
-
15
- return data;
16
- }
17
-
18
- function _path() {
19
- const data = _interopRequireDefault(require("path"));
20
-
21
- _path = function () {
22
- return data;
23
- };
24
-
25
- return data;
26
- }
27
-
28
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
-
30
- /**
31
- * Joins a path onto a URL, and normalizes Windows paths
32
- * e.g. from \path\to\res.js to /path/to/res.js.
33
- */
34
- function urlJoin(publicURL, assetPath) {
35
- const url = _url().default.parse(publicURL, false, true); // Leading / ensures that paths with colons are not parsed as a protocol.
36
-
37
-
38
- let p = assetPath.startsWith('/') ? assetPath : '/' + assetPath;
39
-
40
- const assetUrl = _url().default.parse(p);
41
-
42
- url.pathname = _path().default.posix.join(url.pathname, assetUrl.pathname);
43
- url.search = assetUrl.search;
44
- url.hash = assetUrl.hash;
45
- return _url().default.format(url);
46
- }