@atlaspack/utils 2.15.4-typescript-9a5730863.0 → 2.16.0

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