@parcel/utils 2.0.0-beta.3 → 2.0.0-dev.1510

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 (79) hide show
  1. package/lib/index.js +37516 -542
  2. package/lib/index.js.map +1 -0
  3. package/package.json +41 -18
  4. package/src/DefaultMap.js +1 -1
  5. package/src/PromiseQueue.js +13 -0
  6. package/src/alternatives.js +21 -6
  7. package/src/ansi-html.js +1 -1
  8. package/src/blob.js +1 -0
  9. package/src/collection.js +35 -3
  10. package/src/config.js +77 -22
  11. package/src/debounce.js +1 -1
  12. package/src/dependency-location.js +5 -5
  13. package/src/getExisting.js +1 -4
  14. package/src/getModuleParts.js +23 -0
  15. package/src/glob.js +26 -3
  16. package/src/hash.js +49 -0
  17. package/src/http-server.js +19 -7
  18. package/src/index.js +25 -10
  19. package/src/path.js +11 -1
  20. package/src/prettyDiagnostic.js +90 -40
  21. package/src/progress-message.js +22 -0
  22. package/src/replaceBundleReferences.js +49 -25
  23. package/src/schema.js +20 -19
  24. package/src/shared-buffer.js +23 -0
  25. package/src/sourcemap.js +13 -7
  26. package/src/urlJoin.js +3 -1
  27. package/test/DefaultMap.test.js +7 -4
  28. package/test/PromiseQueue.test.js +28 -0
  29. package/test/collection.test.js +13 -1
  30. package/test/config.test.js +98 -0
  31. package/test/input/config/.testrc +3 -0
  32. package/test/input/config/config.cjs +3 -0
  33. package/test/input/config/config.js +3 -0
  34. package/test/input/config/config.json +3 -0
  35. package/test/input/config/empty.json +0 -0
  36. package/test/input/config/empty.toml +0 -0
  37. package/test/replaceBundleReferences.test.js +88 -4
  38. package/test/throttle.test.js +1 -1
  39. package/test/urlJoin.test.js +11 -0
  40. package/lib/DefaultMap.js +0 -64
  41. package/lib/Deferred.js +0 -34
  42. package/lib/PromiseQueue.js +0 -144
  43. package/lib/TapStream.js +0 -46
  44. package/lib/alternatives.js +0 -151
  45. package/lib/ansi-html.js +0 -32
  46. package/lib/blob.js +0 -47
  47. package/lib/bundle-url.js +0 -43
  48. package/lib/collection.js +0 -51
  49. package/lib/config.js +0 -159
  50. package/lib/countLines.js +0 -18
  51. package/lib/debounce.js +0 -20
  52. package/lib/dependency-location.js +0 -21
  53. package/lib/escape-html.js +0 -24
  54. package/lib/generateBuildMetrics.js +0 -156
  55. package/lib/generateCertificate.js +0 -149
  56. package/lib/getCertificate.js +0 -19
  57. package/lib/getExisting.js +0 -31
  58. package/lib/getRootDir.js +0 -74
  59. package/lib/glob.js +0 -118
  60. package/lib/http-server.js +0 -110
  61. package/lib/is-url.js +0 -27
  62. package/lib/isDirectoryInside.js +0 -24
  63. package/lib/md5.js +0 -61
  64. package/lib/objectHash.js +0 -34
  65. package/lib/openInBrowser.js +0 -94
  66. package/lib/parseCSSImport.js +0 -16
  67. package/lib/path.js +0 -44
  68. package/lib/prettifyTime.js +0 -10
  69. package/lib/prettyDiagnostic.js +0 -119
  70. package/lib/relativeBundlePath.js +0 -38
  71. package/lib/relativeUrl.js +0 -32
  72. package/lib/replaceBundleReferences.js +0 -184
  73. package/lib/schema.js +0 -391
  74. package/lib/sourcemap.js +0 -155
  75. package/lib/stream.js +0 -86
  76. package/lib/throttle.js +0 -16
  77. package/lib/urlJoin.js +0 -43
  78. package/src/.babelrc +0 -3
  79. package/src/md5.js +0 -56
@@ -1,151 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.findAlternativeNodeModules = findAlternativeNodeModules;
7
- exports.findAlternativeFiles = findAlternativeFiles;
8
-
9
- function _path() {
10
- const data = _interopRequireDefault(require("path"));
11
-
12
- _path = function () {
13
- return data;
14
- };
15
-
16
- return data;
17
- }
18
-
19
- function _schema() {
20
- const data = require("./schema");
21
-
22
- _schema = function () {
23
- return data;
24
- };
25
-
26
- return data;
27
- }
28
-
29
- function _path2() {
30
- const data = require("./path");
31
-
32
- _path2 = function () {
33
- return data;
34
- };
35
-
36
- return data;
37
- }
38
-
39
- function _config() {
40
- const data = require("./config");
41
-
42
- _config = function () {
43
- return data;
44
- };
45
-
46
- return data;
47
- }
48
-
49
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
50
-
51
- async function findAlternativeNodeModules(fs, moduleName, dir) {
52
- let potentialModules = [];
53
-
54
- let root = _path().default.parse(dir).root;
55
-
56
- let isOrganisationModule = moduleName.startsWith('@');
57
-
58
- while (dir !== root) {
59
- // Skip node_modules directories
60
- if (_path().default.basename(dir) === 'node_modules') {
61
- dir = _path().default.dirname(dir);
62
- }
63
-
64
- try {
65
- let modulesDir = _path().default.join(dir, 'node_modules');
66
-
67
- let stats = await fs.stat(modulesDir);
68
-
69
- if (stats.isDirectory()) {
70
- let dirContent = (await fs.readdir(modulesDir)).sort(); // Filter out the modules that interest us
71
-
72
- let modules = dirContent.filter(i => isOrganisationModule ? i.startsWith('@') : !i.startsWith('@')); // If it's an organisation module, loop through all the modules of that organisation
73
-
74
- if (isOrganisationModule) {
75
- await Promise.all(modules.map(async item => {
76
- let orgDirPath = _path().default.join(modulesDir, item);
77
-
78
- let orgDirContent = (await fs.readdir(orgDirPath)).sort(); // Add all org packages
79
-
80
- potentialModules.push(...orgDirContent.map(i => `${item}/${i}`));
81
- }));
82
- }
83
- }
84
- } catch (err) {// ignore
85
- } // Move up a directory
86
-
87
-
88
- dir = _path().default.dirname(dir);
89
- }
90
-
91
- return (0, _schema().fuzzySearch)(potentialModules.sort(), moduleName).slice(0, 2);
92
- }
93
-
94
- async function findAllFilesUp({
95
- fs,
96
- dir,
97
- root,
98
- basedir,
99
- maxlength,
100
- collected
101
- }) {
102
- let dirContent = (await fs.readdir(dir)).sort();
103
- return Promise.all(dirContent.map(async item => {
104
- let fullPath = _path().default.join(dir, item);
105
-
106
- let relativeFilePath = (0, _path2().relativePath)(basedir, fullPath);
107
-
108
- if (relativeFilePath.length < maxlength) {
109
- let stats = await fs.stat(fullPath);
110
- let isDir = stats.isDirectory();
111
-
112
- if (isDir || stats.isFile()) {
113
- collected.push(relativeFilePath);
114
- } // If it's a directory, run over each item within said directory...
115
-
116
-
117
- if (isDir) {
118
- return findAllFilesUp({
119
- fs,
120
- dir: fullPath,
121
- root,
122
- basedir,
123
- maxlength,
124
- collected
125
- });
126
- }
127
- }
128
- }));
129
- }
130
-
131
- async function findAlternativeFiles(fs, fileSpecifier, dir, projectRoot) {
132
- let potentialFiles = []; // Find our root, we won't recommend files above the package root as that's bad practise
133
-
134
- let pkg = await (0, _config().resolveConfig)(fs, _path().default.join(dir, 'index'), ['package.json'], projectRoot);
135
-
136
- if (!pkg) {
137
- return potentialFiles;
138
- }
139
-
140
- let pkgRoot = _path().default.dirname(pkg);
141
-
142
- await findAllFilesUp({
143
- fs,
144
- dir: pkgRoot,
145
- root: pkgRoot,
146
- basedir: dir,
147
- maxlength: fileSpecifier.length + 10,
148
- collected: potentialFiles
149
- });
150
- return (0, _schema().fuzzySearch)(potentialFiles, fileSpecifier).slice(0, 2);
151
- }
package/lib/ansi-html.js DELETED
@@ -1,32 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.ansiHtml = ansiHtml;
7
-
8
- function _ansiHtml() {
9
- const data = _interopRequireDefault(require("ansi-html"));
10
-
11
- _ansiHtml = function () {
12
- return data;
13
- };
14
-
15
- return data;
16
- }
17
-
18
- function _escapeHtml() {
19
- const data = require("./escape-html");
20
-
21
- _escapeHtml = 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 ansiHtml(ansi) {
31
- return (0, _ansiHtml().default)((0, _escapeHtml().escapeHTML)(ansi));
32
- }
package/lib/blob.js DELETED
@@ -1,47 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.blobToBuffer = blobToBuffer;
7
- exports.blobToString = blobToString;
8
-
9
- function _() {
10
- const data = require("./");
11
-
12
- _ = function () {
13
- return data;
14
- };
15
-
16
- return data;
17
- }
18
-
19
- function _stream() {
20
- const data = require("stream");
21
-
22
- _stream = function () {
23
- return data;
24
- };
25
-
26
- return data;
27
- }
28
-
29
- function blobToBuffer(blob) {
30
- if (blob instanceof _stream().Readable) {
31
- return (0, _().bufferStream)(blob);
32
- } else if (blob instanceof Buffer) {
33
- return Promise.resolve(Buffer.from(blob));
34
- } else {
35
- return Promise.resolve(Buffer.from(blob, 'utf8'));
36
- }
37
- }
38
-
39
- async function blobToString(blob) {
40
- if (blob instanceof _stream().Readable) {
41
- return (await (0, _().bufferStream)(blob)).toString();
42
- } else if (blob instanceof Buffer) {
43
- return blob.toString();
44
- } else {
45
- return blob;
46
- }
47
- }
package/lib/bundle-url.js DELETED
@@ -1,43 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getBaseURL = getBaseURL;
7
- exports.getBundleURL = void 0;
8
- let bundleURL = null;
9
-
10
- function getBundleURLCached() {
11
- if (bundleURL == null) {
12
- bundleURL = _getBundleURL();
13
- }
14
-
15
- return bundleURL;
16
- }
17
-
18
- function _getBundleURL() {
19
- // Attempt to find the URL of the current script and use that as the base URL
20
- try {
21
- throw new Error();
22
- } catch (err) {
23
- let stack = typeof err.stack === 'string' ? err.stack : '';
24
- let matches = stack.match(/(https?|file|ftp):\/\/[^)\n]+/g);
25
-
26
- if (matches) {
27
- return getBaseURL(matches[0]);
28
- }
29
- }
30
-
31
- return '/';
32
- }
33
-
34
- function getBaseURL(url) {
35
- if (url == null) {
36
- return '/';
37
- }
38
-
39
- return url.replace(/^((?:https?|file|ftp):\/\/.+)\/[^/]+$/, '$1') + '/';
40
- }
41
-
42
- const getBundleURL = getBundleURLCached;
43
- exports.getBundleURL = getBundleURL;
package/lib/collection.js DELETED
@@ -1,51 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.unique = unique;
7
- exports.objectSortedEntries = objectSortedEntries;
8
- exports.objectSortedEntriesDeep = objectSortedEntriesDeep;
9
- exports.setDifference = setDifference;
10
-
11
- function unique(array) {
12
- return [...new Set(array)];
13
- }
14
-
15
- function objectSortedEntries(obj) {
16
- return Object.entries(obj).sort(([keyA], [keyB]) => keyA.localeCompare(keyB));
17
- }
18
-
19
- function objectSortedEntriesDeep(object) {
20
- let sortedEntries = objectSortedEntries(object);
21
-
22
- for (let i = 0; i < sortedEntries.length; i++) {
23
- sortedEntries[i][1] = sortEntry(sortedEntries[i][1]);
24
- }
25
-
26
- return sortedEntries;
27
- }
28
-
29
- function sortEntry(entry) {
30
- if (Array.isArray(entry)) {
31
- return entry.map(sortEntry);
32
- }
33
-
34
- if (typeof entry === 'object' && entry != null) {
35
- return objectSortedEntriesDeep(entry);
36
- }
37
-
38
- return entry;
39
- }
40
-
41
- function setDifference(a, b) {
42
- let difference = new Set();
43
-
44
- for (let e of a) {
45
- if (!b.has(e)) {
46
- difference.add(e);
47
- }
48
- }
49
-
50
- return difference;
51
- }
package/lib/config.js DELETED
@@ -1,159 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.resolveConfig = resolveConfig;
7
- exports.resolveConfigSync = resolveConfigSync;
8
- exports.loadConfig = loadConfig;
9
-
10
- function _path() {
11
- const data = _interopRequireDefault(require("path"));
12
-
13
- _path = function () {
14
- return data;
15
- };
16
-
17
- return data;
18
- }
19
-
20
- function _clone() {
21
- const data = _interopRequireDefault(require("clone"));
22
-
23
- _clone = function () {
24
- return data;
25
- };
26
-
27
- return data;
28
- }
29
-
30
- function _json() {
31
- const data = require("json5");
32
-
33
- _json = function () {
34
- return data;
35
- };
36
-
37
- return data;
38
- }
39
-
40
- function _toml() {
41
- const data = require("@iarna/toml");
42
-
43
- _toml = function () {
44
- return data;
45
- };
46
-
47
- return data;
48
- }
49
-
50
- function _lruCache() {
51
- const data = _interopRequireDefault(require("lru-cache"));
52
-
53
- _lruCache = function () {
54
- return data;
55
- };
56
-
57
- return data;
58
- }
59
-
60
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
61
-
62
- const configCache = new (_lruCache().default)({
63
- max: 500
64
- });
65
- const resolveCache = new Map();
66
-
67
- function resolveConfig(fs, filepath, filenames, projectRoot) {
68
- // Cache the result of resolving config for this directory.
69
- // This is automatically invalidated at the end of the current build.
70
- let key = _path().default.dirname(filepath) + filenames.join(',');
71
- let cached = resolveCache.get(key);
72
-
73
- if (cached !== undefined) {
74
- return Promise.resolve(cached);
75
- }
76
-
77
- let resolved = fs.findAncestorFile(filenames, _path().default.dirname(filepath), projectRoot);
78
- resolveCache.set(key, resolved);
79
- return Promise.resolve(resolved);
80
- }
81
-
82
- function resolveConfigSync(fs, filepath, filenames, projectRoot) {
83
- return fs.findAncestorFile(filenames, _path().default.dirname(filepath), projectRoot);
84
- }
85
-
86
- async function loadConfig(fs, filepath, filenames, projectRoot, opts) {
87
- var _opts$parse;
88
-
89
- let parse = (_opts$parse = opts === null || opts === void 0 ? void 0 : opts.parse) !== null && _opts$parse !== void 0 ? _opts$parse : true;
90
- let configFile = await resolveConfig(fs, filepath, filenames, projectRoot);
91
-
92
- if (configFile) {
93
- let cachedOutput = configCache.get(String(parse) + configFile);
94
-
95
- if (cachedOutput) {
96
- return cachedOutput;
97
- }
98
-
99
- try {
100
- let extname = _path().default.extname(configFile).slice(1);
101
-
102
- if (extname === 'js') {
103
- let output = {
104
- // $FlowFixMe
105
- config: (0, _clone().default)(require(configFile)),
106
- files: [{
107
- filePath: configFile
108
- }]
109
- };
110
- configCache.set(configFile, output);
111
- return output;
112
- }
113
-
114
- let configContent = await fs.readFile(configFile, 'utf8');
115
- if (!configContent) return null;
116
- let config;
117
-
118
- if (parse === false) {
119
- config = configContent;
120
- } else {
121
- let parse = getParser(extname);
122
- config = parse(configContent);
123
- }
124
-
125
- let output = {
126
- config,
127
- files: [{
128
- filePath: configFile
129
- }]
130
- };
131
- configCache.set(String(parse) + configFile, output);
132
- return output;
133
- } catch (err) {
134
- if (err.code === 'MODULE_NOT_FOUND' || err.code === 'ENOENT') {
135
- return null;
136
- }
137
-
138
- throw err;
139
- }
140
- }
141
-
142
- return null;
143
- }
144
-
145
- loadConfig.clear = () => {
146
- configCache.reset();
147
- resolveCache.clear();
148
- };
149
-
150
- function getParser(extname) {
151
- switch (extname) {
152
- case 'toml':
153
- return _toml().parse;
154
-
155
- case 'json':
156
- default:
157
- return _json().parse;
158
- }
159
- }
package/lib/countLines.js DELETED
@@ -1,18 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = countLines;
7
-
8
- function countLines(string, startIndex = 0) {
9
- let lines = 1;
10
-
11
- for (let i = startIndex; i < string.length; i++) {
12
- if (string.charAt(i) === '\n') {
13
- lines++;
14
- }
15
- }
16
-
17
- return lines;
18
- }
package/lib/debounce.js DELETED
@@ -1,20 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = debounce;
7
-
8
- function debounce(fn, delay) {
9
- let timeout;
10
- return function (...args) {
11
- if (timeout) {
12
- clearTimeout(timeout);
13
- }
14
-
15
- timeout = setTimeout(() => {
16
- timeout = null;
17
- fn(...args);
18
- }, delay);
19
- };
20
- }
@@ -1,21 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = createDependencyLocation;
7
-
8
- function createDependencyLocation(start, moduleSpecifier, lineOffset = 0, columnOffset = 0, // Imports are usually wrapped in quotes
9
- importWrapperLength = 2) {
10
- return {
11
- filePath: moduleSpecifier,
12
- start: {
13
- line: start.line + lineOffset,
14
- column: start.column + columnOffset
15
- },
16
- end: {
17
- line: start.line + lineOffset,
18
- column: start.column + moduleSpecifier.length - 1 + importWrapperLength + columnOffset
19
- }
20
- };
21
- }
@@ -1,24 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.escapeHTML = escapeHTML;
7
- // Based on _.escape https://github.com/lodash/lodash/blob/master/escape.js
8
- const reUnescapedHtml = /[&<>"']/g;
9
- const reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
10
- const htmlEscapes = {
11
- '&': '&amp;',
12
- '<': '&lt;',
13
- '>': '&gt;',
14
- '"': '&quot;',
15
- "'": '&#39;'
16
- };
17
-
18
- function escapeHTML(s) {
19
- if (reHasUnescapedHtml.test(s)) {
20
- return s.replace(reUnescapedHtml, c => htmlEscapes[c]);
21
- }
22
-
23
- return s;
24
- }