@atlaspack/utils 2.17.3-typescript-b27501580.0 → 2.17.3-typescript-5b4d3ad41.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 (87) hide show
  1. package/lib/DefaultMap.d.ts +13 -0
  2. package/lib/DefaultMap.js +42 -0
  3. package/lib/Deferred.d.ts +8 -0
  4. package/lib/Deferred.js +30 -0
  5. package/lib/PromiseQueue.d.ts +25 -0
  6. package/lib/PromiseQueue.js +112 -0
  7. package/lib/TapStream.d.ts +6 -0
  8. package/lib/TapStream.js +34 -0
  9. package/lib/alternatives.d.ts +3 -0
  10. package/lib/alternatives.js +116 -0
  11. package/lib/ansi-html.d.ts +1 -0
  12. package/lib/ansi-html.js +20 -0
  13. package/lib/blob.d.ts +4 -0
  14. package/lib/blob.js +40 -0
  15. package/lib/bundle-url.d.ts +4 -0
  16. package/lib/bundle-url.js +34 -0
  17. package/lib/collection.d.ts +33 -0
  18. package/lib/collection.js +111 -0
  19. package/lib/config.d.ts +17 -0
  20. package/lib/config.js +174 -0
  21. package/lib/countLines.d.ts +1 -0
  22. package/lib/countLines.js +15 -0
  23. package/lib/debounce.d.ts +1 -0
  24. package/lib/debounce.js +18 -0
  25. package/lib/debug-tools.d.ts +6 -0
  26. package/lib/debug-tools.js +37 -0
  27. package/lib/dependency-location.d.ts +14 -0
  28. package/lib/dependency-location.js +21 -0
  29. package/lib/escape-html.d.ts +1 -0
  30. package/lib/escape-html.js +22 -0
  31. package/lib/generateBuildMetrics.d.ts +18 -0
  32. package/lib/generateBuildMetrics.js +121 -0
  33. package/lib/generateCertificate.d.ts +5 -0
  34. package/lib/generateCertificate.js +129 -0
  35. package/lib/getCertificate.d.ts +6 -0
  36. package/lib/getCertificate.js +18 -0
  37. package/lib/getExisting.d.ts +8 -0
  38. package/lib/getExisting.js +25 -0
  39. package/lib/getModuleParts.d.ts +4 -0
  40. package/lib/getModuleParts.js +30 -0
  41. package/lib/getRootDir.d.ts +2 -0
  42. package/lib/getRootDir.js +52 -0
  43. package/lib/glob.d.ts +10 -0
  44. package/lib/glob.js +118 -0
  45. package/lib/hash.d.ts +7 -0
  46. package/lib/hash.js +50 -0
  47. package/lib/http-server.d.ts +19 -0
  48. package/lib/http-server.js +85 -0
  49. package/lib/index.d.ts +48 -0
  50. package/lib/index.js +665 -0
  51. package/lib/is-url.d.ts +1 -0
  52. package/lib/is-url.js +24 -0
  53. package/lib/isDirectoryInside.d.ts +2 -0
  54. package/lib/isDirectoryInside.js +18 -0
  55. package/lib/objectHash.d.ts +3 -0
  56. package/lib/objectHash.js +26 -0
  57. package/lib/openInBrowser.d.ts +1 -0
  58. package/lib/openInBrowser.js +74 -0
  59. package/lib/parseCSSImport.d.ts +1 -0
  60. package/lib/parseCSSImport.js +15 -0
  61. package/lib/path.d.ts +8 -0
  62. package/lib/path.js +39 -0
  63. package/lib/prettifyTime.d.ts +1 -0
  64. package/lib/prettifyTime.js +9 -0
  65. package/lib/prettyDiagnostic.d.ts +17 -0
  66. package/lib/prettyDiagnostic.js +134 -0
  67. package/lib/progress-message.d.ts +3 -0
  68. package/lib/progress-message.js +36 -0
  69. package/lib/relativeBundlePath.d.ts +4 -0
  70. package/lib/relativeBundlePath.js +22 -0
  71. package/lib/relativeUrl.d.ts +1 -0
  72. package/lib/relativeUrl.js +24 -0
  73. package/lib/replaceBundleReferences.d.ts +39 -0
  74. package/lib/replaceBundleReferences.js +199 -0
  75. package/lib/schema.d.ts +107 -0
  76. package/lib/schema.js +355 -0
  77. package/lib/shared-buffer.d.ts +2 -0
  78. package/lib/shared-buffer.js +31 -0
  79. package/lib/sourcemap.d.ts +16 -0
  80. package/lib/sourcemap.js +127 -0
  81. package/lib/stream.d.ts +8 -0
  82. package/lib/stream.js +76 -0
  83. package/lib/throttle.d.ts +1 -0
  84. package/lib/throttle.js +15 -0
  85. package/lib/urlJoin.d.ts +5 -0
  86. package/lib/urlJoin.js +35 -0
  87. package/package.json +9 -9
@@ -0,0 +1,13 @@
1
+ export declare class DefaultMap<K, V> extends Map<K, V> {
2
+ _getDefault: (arg1: K) => V;
3
+ constructor(getDefault: (arg1: K) => V, entries?: Iterable<[K, V]>);
4
+ get(key: K): V;
5
+ }
6
+ interface Key {
7
+ }
8
+ export declare class DefaultWeakMap<K extends Key, V> extends WeakMap<K, V> {
9
+ _getDefault: (arg1: K) => V;
10
+ constructor(getDefault: (arg1: K) => V, entries?: Iterable<[K, V]>);
11
+ get(key: K): V;
12
+ }
13
+ export {};
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.DefaultWeakMap = exports.DefaultMap = void 0;
7
+ class DefaultMap extends Map {
8
+ constructor(getDefault, entries) {
9
+ super(entries);
10
+ this._getDefault = getDefault;
11
+ }
12
+ get(key) {
13
+ let ret;
14
+ if (this.has(key)) {
15
+ ret = super.get(key);
16
+ } else {
17
+ ret = this._getDefault(key);
18
+ this.set(key, ret);
19
+ }
20
+ return ret;
21
+ }
22
+ }
23
+ exports.DefaultMap = DefaultMap;
24
+ // Duplicated from DefaultMap implementation for Flow
25
+ // Roughly mirrors https://github.com/facebook/flow/blob/2eb5a78d92c167117ba9caae070afd2b9f598599/lib/core.js#L617
26
+ class DefaultWeakMap extends WeakMap {
27
+ constructor(getDefault, entries) {
28
+ super(entries);
29
+ this._getDefault = getDefault;
30
+ }
31
+ get(key) {
32
+ let ret;
33
+ if (this.has(key)) {
34
+ ret = super.get(key);
35
+ } else {
36
+ ret = this._getDefault(key);
37
+ this.set(key, ret);
38
+ }
39
+ return ret;
40
+ }
41
+ }
42
+ exports.DefaultWeakMap = DefaultWeakMap;
@@ -0,0 +1,8 @@
1
+ export type Deferred<T> = {
2
+ resolve(arg1: T): void;
3
+ reject(arg1: unknown): void;
4
+ };
5
+ export declare function makeDeferredWithPromise<T>(): {
6
+ deferred: Deferred<T>;
7
+ promise: Promise<T>;
8
+ };
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.makeDeferredWithPromise = makeDeferredWithPromise;
7
+ function _assert() {
8
+ const data = _interopRequireDefault(require("assert"));
9
+ _assert = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+ function makeDeferredWithPromise() {
16
+ let deferred;
17
+ let promise = new Promise((resolve, reject) => {
18
+ deferred = {
19
+ resolve,
20
+ reject
21
+ };
22
+ });
23
+
24
+ // Promise constructor callback executes synchronously, so this is defined
25
+ (0, _assert().default)(deferred != null);
26
+ return {
27
+ deferred,
28
+ promise
29
+ };
30
+ }
@@ -0,0 +1,25 @@
1
+ import { type Deferred } from './Deferred';
2
+ type PromiseQueueOpts = {
3
+ maxConcurrent: number;
4
+ };
5
+ export default class PromiseQueue<T> {
6
+ _deferred: Deferred<Array<T>> | null | undefined;
7
+ _maxConcurrent: number;
8
+ _numRunning: number;
9
+ _queue: Array<() => Promise<void>>;
10
+ _runPromise: Promise<Array<T>> | null | undefined;
11
+ _error: unknown;
12
+ _count: number;
13
+ _results: Array<T>;
14
+ _addSubscriptions: Set<() => void>;
15
+ constructor(opts?: PromiseQueueOpts);
16
+ getNumWaiting(): number;
17
+ add(fn: () => Promise<T>): void;
18
+ subscribeToAdd(fn: () => void): () => void;
19
+ run(): Promise<Array<T>>;
20
+ _next(): Promise<void>;
21
+ _runFn(fn: () => unknown): Promise<void>;
22
+ _resetState(): void;
23
+ _done(): void;
24
+ }
25
+ export {};
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _Deferred = require("./Deferred");
8
+ class PromiseQueue {
9
+ _numRunning = 0;
10
+ _queue = [];
11
+ _runPromise = null;
12
+ _count = 0;
13
+ _results = [];
14
+ _addSubscriptions = new Set();
15
+ constructor(opts = {
16
+ maxConcurrent: Infinity
17
+ }) {
18
+ if (opts.maxConcurrent <= 0) {
19
+ throw new TypeError('maxConcurrent must be a positive, non-zero value');
20
+ }
21
+ this._maxConcurrent = opts.maxConcurrent;
22
+ }
23
+ getNumWaiting() {
24
+ return this._queue.length;
25
+ }
26
+ add(fn) {
27
+ new Promise((resolve, reject) => {
28
+ let i = this._count++;
29
+ let wrapped = () => fn().then(result => {
30
+ this._results[i] = result;
31
+ resolve(result);
32
+ }, err => {
33
+ reject(err);
34
+ throw err;
35
+ });
36
+ this._queue.push(wrapped);
37
+ for (const addFn of this._addSubscriptions) {
38
+ addFn();
39
+ }
40
+ if (this._numRunning > 0 && this._numRunning < this._maxConcurrent) {
41
+ this._next();
42
+ }
43
+ }).catch(() => {});
44
+ }
45
+ subscribeToAdd(fn) {
46
+ this._addSubscriptions.add(fn);
47
+ return () => {
48
+ this._addSubscriptions.delete(fn);
49
+ };
50
+ }
51
+ run() {
52
+ if (this._runPromise != null) {
53
+ return this._runPromise;
54
+ }
55
+ if (this._queue.length === 0) {
56
+ return Promise.resolve([]);
57
+ }
58
+ let {
59
+ deferred,
60
+ promise
61
+ } = (0, _Deferred.makeDeferredWithPromise)();
62
+ this._deferred = deferred;
63
+ this._runPromise = promise;
64
+ while (this._queue.length && this._numRunning < this._maxConcurrent) {
65
+ this._next();
66
+ }
67
+ return promise;
68
+ }
69
+ async _next() {
70
+ let fn = this._queue.shift();
71
+ await this._runFn(fn);
72
+ if (this._queue.length) {
73
+ this._next();
74
+ } else if (this._numRunning === 0) {
75
+ this._done();
76
+ }
77
+ }
78
+ async _runFn(fn) {
79
+ this._numRunning++;
80
+ try {
81
+ await fn();
82
+ } catch (e) {
83
+ // Only store the first error that occurs.
84
+ // We don't reject immediately so that any other concurrent
85
+ // requests have time to complete.
86
+ if (this._error == null) {
87
+ this._error = e;
88
+ }
89
+ } finally {
90
+ this._numRunning--;
91
+ }
92
+ }
93
+ _resetState() {
94
+ this._queue = [];
95
+ this._count = 0;
96
+ this._results = [];
97
+ this._runPromise = null;
98
+ this._numRunning = 0;
99
+ this._deferred = null;
100
+ }
101
+ _done() {
102
+ if (this._deferred != null) {
103
+ if (this._error != null) {
104
+ this._deferred.reject(this._error);
105
+ } else {
106
+ this._deferred.resolve(this._results);
107
+ }
108
+ }
109
+ this._resetState();
110
+ }
111
+ }
112
+ exports.default = PromiseQueue;
@@ -0,0 +1,6 @@
1
+ import { Transform } from 'stream';
2
+ export default class TapStream extends Transform {
3
+ _tap: (arg1: Buffer) => unknown;
4
+ constructor(tap: (arg1: Buffer) => unknown, options: unknown);
5
+ _transform(chunk: Buffer | string, encoding: string, callback: (err?: Error | null | undefined, chunk?: Buffer | string) => unknown): void;
6
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ function _stream() {
8
+ const data = require("stream");
9
+ _stream = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ /*
15
+ * "Taps" into the contents of a flowing stream, yielding chunks to the passed
16
+ * callback. Continues to pass data chunks down the stream.
17
+ */
18
+ class TapStream extends _stream().Transform {
19
+ constructor(tap, options) {
20
+ super({
21
+ ...options
22
+ });
23
+ this._tap = tap;
24
+ }
25
+ _transform(chunk, encoding, callback) {
26
+ try {
27
+ this._tap(Buffer.from(chunk));
28
+ callback(null, chunk);
29
+ } catch (err) {
30
+ callback(err);
31
+ }
32
+ }
33
+ }
34
+ exports.default = TapStream;
@@ -0,0 +1,3 @@
1
+ import type { FileSystem } from '@atlaspack/types';
2
+ export declare function findAlternativeNodeModules(fs: FileSystem, moduleName: string, dir: string): Promise<Array<string>>;
3
+ export declare function findAlternativeFiles(fs: FileSystem, fileSpecifier: string, dir: string, projectRoot: string, leadingDotSlash?: boolean, includeDirectories?: boolean, includeExtension?: boolean): Promise<Array<string>>;
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.findAlternativeFiles = findAlternativeFiles;
7
+ exports.findAlternativeNodeModules = findAlternativeNodeModules;
8
+ function _path() {
9
+ const data = _interopRequireDefault(require("path"));
10
+ _path = function () {
11
+ return data;
12
+ };
13
+ return data;
14
+ }
15
+ var _schema = require("./schema");
16
+ var _path2 = require("./path");
17
+ var _config = require("./config");
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+ async function findAlternativeNodeModules(fs, moduleName, dir) {
20
+ let potentialModules = [];
21
+ let root = _path().default.parse(dir).root;
22
+ let isOrganisationModule = moduleName.startsWith('@');
23
+ while (dir !== root) {
24
+ // Skip node_modules directories
25
+ if (_path().default.basename(dir) === 'node_modules') {
26
+ dir = _path().default.dirname(dir);
27
+ }
28
+ try {
29
+ let modulesDir = _path().default.join(dir, 'node_modules');
30
+ let stats = await fs.stat(modulesDir);
31
+ if (stats.isDirectory()) {
32
+ let dirContent = (await fs.readdir(modulesDir)).sort();
33
+
34
+ // Filter out the modules that interest us
35
+ let modules = dirContent.filter(i => isOrganisationModule ? i.startsWith('@') : !i.startsWith('@'));
36
+
37
+ // If it's an organisation module, loop through all the modules of that organisation
38
+ if (isOrganisationModule) {
39
+ await Promise.all(modules.map(async item => {
40
+ let orgDirPath = _path().default.join(modulesDir, item);
41
+ let orgDirContent = (await fs.readdir(orgDirPath)).sort();
42
+
43
+ // Add all org packages
44
+ potentialModules.push(...orgDirContent.map(i => `${item}/${i}`));
45
+ }));
46
+ } else {
47
+ potentialModules.push(...modules);
48
+ }
49
+ }
50
+ } catch (err) {
51
+ // ignore
52
+ }
53
+
54
+ // Move up a directory
55
+ dir = _path().default.dirname(dir);
56
+ }
57
+ return (0, _schema.fuzzySearch)(potentialModules.sort(), moduleName).slice(0, 2);
58
+ }
59
+ async function findAllFilesUp({
60
+ fs,
61
+ dir,
62
+ root,
63
+ basedir,
64
+ maxlength,
65
+ collected,
66
+ leadingDotSlash = true,
67
+ includeDirectories = true
68
+ }) {
69
+ let dirContent = (await fs.readdir(dir)).sort();
70
+ return Promise.all(dirContent.map(async item => {
71
+ let fullPath = _path().default.join(dir, item);
72
+ let relativeFilePath = (0, _path2.relativePath)(basedir, fullPath, leadingDotSlash);
73
+ if (relativeFilePath.length < maxlength) {
74
+ let stats = await fs.stat(fullPath);
75
+ let isDir = stats.isDirectory();
76
+ if (isDir && includeDirectories || stats.isFile()) {
77
+ collected.push(relativeFilePath);
78
+ }
79
+
80
+ // If it's a directory, run over each item within said directory...
81
+ if (isDir) {
82
+ return findAllFilesUp({
83
+ fs,
84
+ dir: fullPath,
85
+ root,
86
+ basedir,
87
+ maxlength,
88
+ collected
89
+ });
90
+ }
91
+ }
92
+ }));
93
+ }
94
+ async function findAlternativeFiles(fs, fileSpecifier, dir, projectRoot, leadingDotSlash = true, includeDirectories = true, includeExtension = false) {
95
+ let potentialFiles = [];
96
+ // Find our root, we won't recommend files above the package root as that's bad practise
97
+ let pkg = await (0, _config.resolveConfig)(fs, _path().default.join(dir, 'index'), ['package.json'], projectRoot);
98
+ let pkgRoot = pkg ? _path().default.dirname(pkg) : projectRoot;
99
+ await findAllFilesUp({
100
+ fs,
101
+ dir: pkgRoot,
102
+ root: pkgRoot,
103
+ basedir: dir,
104
+ maxlength: fileSpecifier.length + 10,
105
+ collected: potentialFiles,
106
+ leadingDotSlash,
107
+ includeDirectories
108
+ });
109
+ if (_path().default.extname(fileSpecifier) === '' && !includeExtension) {
110
+ potentialFiles = potentialFiles.map(p => {
111
+ let ext = _path().default.extname(p);
112
+ return ext.length > 0 ? p.slice(0, -ext.length) : p;
113
+ });
114
+ }
115
+ return (0, _schema.fuzzySearch)(potentialFiles.sort(), fileSpecifier).slice(0, 2);
116
+ }
@@ -0,0 +1 @@
1
+ export declare function ansiHtml(ansi: string): string;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ansiHtml = ansiHtml;
7
+ function _ansiHtmlCommunity() {
8
+ const data = _interopRequireDefault(require("ansi-html-community"));
9
+ _ansiHtmlCommunity = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ var _escapeHtml = require("./escape-html");
15
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
+ // @ts-expect-error ansi-html-community is not typed
17
+
18
+ function ansiHtml(ansi) {
19
+ return (0, _ansiHtmlCommunity().default)((0, _escapeHtml.escapeHTML)(ansi));
20
+ }
package/lib/blob.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import type { Blob } from '@atlaspack/types';
2
+ import { Buffer } from 'buffer';
3
+ export declare function blobToBuffer(blob: Blob): Promise<Buffer>;
4
+ export declare function blobToString(blob: Blob): Promise<string>;
package/lib/blob.js ADDED
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.blobToBuffer = blobToBuffer;
7
+ exports.blobToString = blobToString;
8
+ function _buffer() {
9
+ const data = require("buffer");
10
+ _buffer = function () {
11
+ return data;
12
+ };
13
+ return data;
14
+ }
15
+ var _ = require("./");
16
+ function _stream() {
17
+ const data = require("stream");
18
+ _stream = function () {
19
+ return data;
20
+ };
21
+ return data;
22
+ }
23
+ function blobToBuffer(blob) {
24
+ if (blob instanceof _stream().Readable) {
25
+ return (0, _.bufferStream)(blob);
26
+ } else if (blob instanceof _buffer().Buffer) {
27
+ return Promise.resolve(_buffer().Buffer.from(blob));
28
+ } else {
29
+ return Promise.resolve(_buffer().Buffer.from(blob, 'utf8'));
30
+ }
31
+ }
32
+ async function blobToString(blob) {
33
+ if (blob instanceof _stream().Readable) {
34
+ return (await (0, _.bufferStream)(blob)).toString();
35
+ } else if (blob instanceof _buffer().Buffer) {
36
+ return blob.toString();
37
+ } else {
38
+ return blob;
39
+ }
40
+ }
@@ -0,0 +1,4 @@
1
+ declare function getBundleURLCached(): string;
2
+ export declare function getBaseURL(url?: string | null): string;
3
+ export declare const getBundleURL: typeof getBundleURLCached;
4
+ export {};
@@ -0,0 +1,34 @@
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
+ function getBundleURLCached() {
10
+ if (bundleURL == null) {
11
+ bundleURL = _getBundleURL();
12
+ }
13
+ return bundleURL;
14
+ }
15
+ function _getBundleURL() {
16
+ // Attempt to find the URL of the current script and use that as the base URL
17
+ try {
18
+ throw new Error();
19
+ } catch (err) {
20
+ let stack = typeof err.stack === 'string' ? err.stack : '';
21
+ let matches = stack.match(/(https?|file|ftp):\/\/[^)\n]+/g);
22
+ if (matches) {
23
+ return getBaseURL(matches[0]);
24
+ }
25
+ }
26
+ return '/';
27
+ }
28
+ function getBaseURL(url) {
29
+ if (url == null) {
30
+ return '/';
31
+ }
32
+ return url.replace(/^((?:https?|file|ftp):\/\/.+)\/[^/]+$/, '$1') + '/';
33
+ }
34
+ const getBundleURL = exports.getBundleURL = getBundleURLCached;
@@ -0,0 +1,33 @@
1
+ export declare function unique<T>(array: Array<T>): Array<T>;
2
+ export declare function objectSortedEntries(obj: {
3
+ readonly [key: string]: unknown;
4
+ }): Array<[string, unknown]>;
5
+ export declare function objectSortedEntriesDeep(object: {
6
+ readonly [key: string]: unknown;
7
+ }): Array<[string, unknown]>;
8
+ /**
9
+ * Get the difference of A and B sets
10
+ *
11
+ * This is the set of elements which are in A but not in B
12
+ * For example, the difference of the sets {1,2,3} and {3,4} is {1,2}
13
+ *
14
+ * @param {*} a Set A
15
+ * @param {*} b Set B
16
+ * @returns A \ B
17
+ */
18
+ export declare function setDifference<T>(a: ReadonlySet<T>, b: ReadonlySet<T>): Set<T>;
19
+ /**
20
+ * Get the symmetric difference of A and B sets
21
+ *
22
+ * This is the set of elements which are in either of the sets, but not in their intersection.
23
+ * For example, the symmetric difference of the sets {1,2,3} and {3,4} is {1,2,4}
24
+ *
25
+ * @param {*} a Set A
26
+ * @param {*} b Set B
27
+ * @returns A Δ B
28
+ */
29
+ export declare function setSymmetricDifference<T>(a: ReadonlySet<T>, b: ReadonlySet<T>): Set<T>;
30
+ export declare function setIntersect<T>(a: Set<T>, b: ReadonlySet<T>): void;
31
+ export declare function setIntersectStatic<T>(a: Set<T>, b: Set<T>): Set<T>;
32
+ export declare function setUnion<T>(a: Iterable<T>, b: Iterable<T>): Set<T>;
33
+ export declare function setEqual<T>(a: ReadonlySet<T>, b: ReadonlySet<T>): boolean;
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.objectSortedEntries = objectSortedEntries;
7
+ exports.objectSortedEntriesDeep = objectSortedEntriesDeep;
8
+ exports.setDifference = setDifference;
9
+ exports.setEqual = setEqual;
10
+ exports.setIntersect = setIntersect;
11
+ exports.setIntersectStatic = setIntersectStatic;
12
+ exports.setSymmetricDifference = setSymmetricDifference;
13
+ exports.setUnion = setUnion;
14
+ exports.unique = unique;
15
+ function unique(array) {
16
+ return [...new Set(array)];
17
+ }
18
+ function objectSortedEntries(obj) {
19
+ return Object.entries(obj).sort(([keyA], [keyB]) => keyA.localeCompare(keyB));
20
+ }
21
+ function objectSortedEntriesDeep(object) {
22
+ let sortedEntries = objectSortedEntries(object);
23
+ for (let i = 0; i < sortedEntries.length; i++) {
24
+ sortedEntries[i][1] = sortEntry(sortedEntries[i][1]);
25
+ }
26
+ return sortedEntries;
27
+ }
28
+ function sortEntry(entry) {
29
+ if (Array.isArray(entry)) {
30
+ return entry.map(sortEntry);
31
+ }
32
+ if (typeof entry === 'object' && entry != null) {
33
+ return objectSortedEntriesDeep(entry);
34
+ }
35
+ return entry;
36
+ }
37
+
38
+ /**
39
+ * Get the difference of A and B sets
40
+ *
41
+ * This is the set of elements which are in A but not in B
42
+ * For example, the difference of the sets {1,2,3} and {3,4} is {1,2}
43
+ *
44
+ * @param {*} a Set A
45
+ * @param {*} b Set B
46
+ * @returns A \ B
47
+ */
48
+ function setDifference(a, b) {
49
+ let difference = new Set();
50
+ for (let e of a) {
51
+ if (!b.has(e)) {
52
+ difference.add(e);
53
+ }
54
+ }
55
+ return difference;
56
+ }
57
+
58
+ /**
59
+ * Get the symmetric difference of A and B sets
60
+ *
61
+ * This is the set of elements which are in either of the sets, but not in their intersection.
62
+ * For example, the symmetric difference of the sets {1,2,3} and {3,4} is {1,2,4}
63
+ *
64
+ * @param {*} a Set A
65
+ * @param {*} b Set B
66
+ * @returns A Δ B
67
+ */
68
+ function setSymmetricDifference(a, b) {
69
+ let difference = new Set();
70
+ for (let e of a) {
71
+ if (!b.has(e)) {
72
+ difference.add(e);
73
+ }
74
+ }
75
+ for (let d of b) {
76
+ if (!a.has(d)) {
77
+ difference.add(d);
78
+ }
79
+ }
80
+ return difference;
81
+ }
82
+ function setIntersect(a, b) {
83
+ for (let entry of a) {
84
+ if (!b.has(entry)) {
85
+ a.delete(entry);
86
+ }
87
+ }
88
+ }
89
+ function setIntersectStatic(a, b) {
90
+ let intersection = new Set();
91
+ for (let entry of a) {
92
+ if (b.has(entry)) {
93
+ intersection.add(entry);
94
+ }
95
+ }
96
+ return intersection;
97
+ }
98
+ function setUnion(a, b) {
99
+ return new Set([...a, ...b]);
100
+ }
101
+ function setEqual(a, b) {
102
+ if (a.size != b.size) {
103
+ return false;
104
+ }
105
+ for (let entry of a) {
106
+ if (!b.has(entry)) {
107
+ return false;
108
+ }
109
+ }
110
+ return true;
111
+ }
@@ -0,0 +1,17 @@
1
+ import type { ConfigResult, File, FilePath } from '@atlaspack/types';
2
+ import type { FileSystem } from '@atlaspack/fs';
3
+ export type ConfigOutput = {
4
+ config: ConfigResult;
5
+ files: Array<File>;
6
+ };
7
+ export type ConfigOptions = {
8
+ parse?: boolean;
9
+ parser?: (arg1: string) => any;
10
+ };
11
+ export declare function resolveConfig(fs: FileSystem, filepath: FilePath, filenames: Array<FilePath>, projectRoot: FilePath): Promise<FilePath | null | undefined>;
12
+ export declare function resolveConfigSync(fs: FileSystem, filepath: FilePath, filenames: Array<FilePath>, projectRoot: FilePath): FilePath | null | undefined;
13
+ export declare function loadConfig(fs: FileSystem, filepath: FilePath, filenames: Array<FilePath>, projectRoot: FilePath, opts?: ConfigOptions | null): Promise<ConfigOutput | null>;
14
+ export declare namespace loadConfig {
15
+ var clear: () => void;
16
+ }
17
+ export declare function readConfig(fs: FileSystem, configFile: FilePath, opts?: ConfigOptions | null): Promise<ConfigOutput | null>;