@atlaspack/utils 2.12.1-dev.3443 → 2.12.1-dev.3478

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/utils",
3
- "version": "2.12.1-dev.3443+d1170cfc7",
3
+ "version": "2.12.1-dev.3478+5fd2da535",
4
4
  "description": "Blazing fast, zero configuration web application bundler",
5
5
  "license": "(MIT OR Apache-2.0)",
6
6
  "publishConfig": {
@@ -29,11 +29,11 @@
29
29
  }
30
30
  },
31
31
  "dependencies": {
32
- "@atlaspack/codeframe": "2.12.1-dev.3443+d1170cfc7",
33
- "@atlaspack/diagnostic": "2.12.1-dev.3443+d1170cfc7",
34
- "@atlaspack/logger": "2.12.1-dev.3443+d1170cfc7",
35
- "@atlaspack/markdown-ansi": "2.12.1-dev.3443+d1170cfc7",
36
- "@atlaspack/rust": "2.12.1-dev.3443+d1170cfc7",
32
+ "@atlaspack/codeframe": "2.12.1-dev.3478+5fd2da535",
33
+ "@atlaspack/diagnostic": "2.12.1-dev.3478+5fd2da535",
34
+ "@atlaspack/logger": "2.12.1-dev.3478+5fd2da535",
35
+ "@atlaspack/markdown-ansi": "2.12.1-dev.3478+5fd2da535",
36
+ "@atlaspack/rust": "2.12.1-dev.3478+5fd2da535",
37
37
  "@parcel/source-map": "^2.1.1",
38
38
  "chalk": "^4.1.0",
39
39
  "nullthrows": "^1.1.1"
@@ -63,5 +63,5 @@
63
63
  "./src/openInBrowser.js": false,
64
64
  "@atlaspack/markdown-ansi": false
65
65
  },
66
- "gitHead": "d1170cfc79beb290b2a066f472f68f71f7d7cb23"
66
+ "gitHead": "5fd2da535ecbe096d57e03aec15e80bb1d7601f7"
67
67
  }
package/src/DefaultMap.js CHANGED
@@ -1,9 +1,9 @@
1
1
  // @flow strict-local
2
2
 
3
3
  export class DefaultMap<K, V> extends Map<K, V> {
4
- _getDefault: K => V;
4
+ _getDefault: (K) => V;
5
5
 
6
- constructor(getDefault: K => V, entries?: Iterable<[K, V]>) {
6
+ constructor(getDefault: (K) => V, entries?: Iterable<[K, V]>) {
7
7
  super(entries);
8
8
  this._getDefault = getDefault;
9
9
  }
@@ -25,9 +25,9 @@ export class DefaultMap<K, V> extends Map<K, V> {
25
25
  // Duplicated from DefaultMap implementation for Flow
26
26
  // Roughly mirrors https://github.com/facebook/flow/blob/2eb5a78d92c167117ba9caae070afd2b9f598599/lib/core.js#L617
27
27
  export class DefaultWeakMap<K: interface {}, V> extends WeakMap<K, V> {
28
- _getDefault: K => V;
28
+ _getDefault: (K) => V;
29
29
 
30
- constructor(getDefault: K => V, entries?: Iterable<[K, V]>) {
30
+ constructor(getDefault: (K) => V, entries?: Iterable<[K, V]>) {
31
31
  super(entries);
32
32
  this._getDefault = getDefault;
33
33
  }
@@ -32,11 +32,11 @@ export default class PromiseQueue<T> {
32
32
  let i = this._count++;
33
33
  let wrapped = () =>
34
34
  fn().then(
35
- result => {
35
+ (result) => {
36
36
  this._results[i] = result;
37
37
  resolve(result);
38
38
  },
39
- err => {
39
+ (err) => {
40
40
  reject(err);
41
41
  throw err;
42
42
  },
package/src/TapStream.js CHANGED
@@ -7,8 +7,8 @@ import {Transform} from 'stream';
7
7
  * callback. Continues to pass data chunks down the stream.
8
8
  */
9
9
  export default class TapStream extends Transform {
10
- _tap: Buffer => mixed;
11
- constructor(tap: Buffer => mixed, options: mixed) {
10
+ _tap: (Buffer) => mixed;
11
+ constructor(tap: (Buffer) => mixed, options: mixed) {
12
12
  super({...options});
13
13
  this._tap = tap;
14
14
  }
@@ -27,19 +27,21 @@ export async function findAlternativeNodeModules(
27
27
  let dirContent = (await fs.readdir(modulesDir)).sort();
28
28
 
29
29
  // Filter out the modules that interest us
30
- let modules = dirContent.filter(i =>
30
+ let modules = dirContent.filter((i) =>
31
31
  isOrganisationModule ? i.startsWith('@') : !i.startsWith('@'),
32
32
  );
33
33
 
34
34
  // If it's an organisation module, loop through all the modules of that organisation
35
35
  if (isOrganisationModule) {
36
36
  await Promise.all(
37
- modules.map(async item => {
37
+ modules.map(async (item) => {
38
38
  let orgDirPath = path.join(modulesDir, item);
39
39
  let orgDirContent = (await fs.readdir(orgDirPath)).sort();
40
40
 
41
41
  // Add all org packages
42
- potentialModules.push(...orgDirContent.map(i => `${item}/${i}`));
42
+ potentialModules.push(
43
+ ...orgDirContent.map((i) => `${item}/${i}`),
44
+ );
43
45
  }),
44
46
  );
45
47
  } else {
@@ -78,7 +80,7 @@ async function findAllFilesUp({
78
80
  |}): Promise<mixed> {
79
81
  let dirContent = (await fs.readdir(dir)).sort();
80
82
  return Promise.all(
81
- dirContent.map(async item => {
83
+ dirContent.map(async (item) => {
82
84
  let fullPath = path.join(dir, item);
83
85
  let relativeFilePath = relativePath(basedir, fullPath, leadingDotSlash);
84
86
  if (relativeFilePath.length < maxlength) {
@@ -135,7 +137,7 @@ export async function findAlternativeFiles(
135
137
  });
136
138
 
137
139
  if (path.extname(fileSpecifier) === '' && !includeExtension) {
138
- potentialFiles = potentialFiles.map(p => {
140
+ potentialFiles = potentialFiles.map((p) => {
139
141
  let ext = path.extname(p);
140
142
  return ext.length > 0 ? p.slice(0, -ext.length) : p;
141
143
  });
package/src/config.js CHANGED
@@ -16,7 +16,7 @@ export type ConfigOutput = {|
16
16
 
17
17
  export type ConfigOptions = {|
18
18
  parse?: boolean,
19
- parser?: string => any,
19
+ parser?: (string) => any,
20
20
  |};
21
21
 
22
22
  const configCache = new LRU<FilePath, ConfigOutput>({max: 500});
@@ -13,7 +13,7 @@ const htmlEscapes = {
13
13
 
14
14
  export function escapeHTML(s: string): string {
15
15
  if (reHasUnescapedHtml.test(s)) {
16
- return s.replace(reUnescapedHtml, c => htmlEscapes[c]);
16
+ return s.replace(reUnescapedHtml, (c) => htmlEscapes[c]);
17
17
  }
18
18
 
19
19
  return s;
@@ -42,7 +42,7 @@ async function getSourcemapSizes(
42
42
  let parsedMapData = sourceMap.getMap();
43
43
 
44
44
  if (parsedMapData.mappings.length > 2) {
45
- let sources = parsedMapData.sources.map(s =>
45
+ let sources = parsedMapData.sources.map((s) =>
46
46
  path.normalize(path.join(projectRoot, s)),
47
47
  );
48
48
  let currLine = 1;
@@ -105,7 +105,7 @@ async function createBundleStats(
105
105
  let sourcemapSizes = await getSourcemapSizes(filePath, fs, projectRoot);
106
106
 
107
107
  let assets: Map<string, AssetStats> = new Map();
108
- bundle.traverseAssets(asset => {
108
+ bundle.traverseAssets((asset) => {
109
109
  let filePath = path.normalize(asset.filePath);
110
110
  assets.set(filePath, {
111
111
  filePath,
@@ -148,11 +148,15 @@ export default async function generateBuildMetrics(
148
148
  fs: FileSystem,
149
149
  projectRoot: FilePath,
150
150
  ): Promise<BuildMetrics> {
151
- bundles.sort((a, b) => b.stats.size - a.stats.size).filter(b => !!b.filePath);
151
+ bundles
152
+ .sort((a, b) => b.stats.size - a.stats.size)
153
+ .filter((b) => !!b.filePath);
152
154
 
153
155
  return {
154
156
  bundles: (
155
- await Promise.all(bundles.map(b => createBundleStats(b, fs, projectRoot)))
156
- ).filter(e => !!e),
157
+ await Promise.all(
158
+ bundles.map((b) => createBundleStats(b, fs, projectRoot)),
159
+ )
160
+ ).filter((e) => !!e),
157
161
  };
158
162
  }
package/src/glob.js CHANGED
@@ -48,10 +48,10 @@ export function globSync(
48
48
  options = {
49
49
  ...options,
50
50
  fs: {
51
- statSync: p => {
51
+ statSync: (p) => {
52
52
  return fs.statSync(p);
53
53
  },
54
- lstatSync: p => {
54
+ lstatSync: (p) => {
55
55
  // Our FileSystem interface doesn't have lstat support at the moment,
56
56
  // but this is fine for our purposes since we follow symlinks by default.
57
57
  return fs.statSync(p);
package/src/hash.js CHANGED
@@ -9,17 +9,17 @@ import {hashString, Hash} from '@atlaspack/rust';
9
9
  export function hashStream(stream: Readable): Promise<string> {
10
10
  let hash = new Hash();
11
11
  return new Promise((resolve, reject) => {
12
- stream.on('error', err => {
12
+ stream.on('error', (err) => {
13
13
  reject(err);
14
14
  });
15
15
  stream
16
- .on('data', chunk => {
16
+ .on('data', (chunk) => {
17
17
  hash.writeBuffer(chunk);
18
18
  })
19
19
  .on('end', function () {
20
20
  resolve(hash.finish());
21
21
  })
22
- .on('error', err => {
22
+ .on('error', (err) => {
23
23
  reject(err);
24
24
  });
25
25
  });
@@ -79,7 +79,7 @@ export async function createHTTPServer(
79
79
  }
80
80
  sockets = new Set();
81
81
 
82
- server.close(err => {
82
+ server.close((err) => {
83
83
  if (err != null) {
84
84
  reject(err);
85
85
  return;
package/src/index.js CHANGED
@@ -48,7 +48,7 @@ export {
48
48
  } from './config';
49
49
  export {DefaultMap, DefaultWeakMap} from './DefaultMap';
50
50
  export {makeDeferredWithPromise} from './Deferred';
51
- export {getProgressMessage} from './progress-message.js';
51
+ export {getProgressMessage} from './progress-message';
52
52
  export {
53
53
  isGlob,
54
54
  isGlobMatch,
@@ -57,7 +57,7 @@ export default async function prettyDiagnostic(
57
57
  ? _chalk
58
58
  : {
59
59
  gray: {
60
- underline: v =>
60
+ underline: (v) =>
61
61
  `<span style="color: grey; text-decoration: underline;">${v}</span>`,
62
62
  },
63
63
  };
@@ -125,7 +125,7 @@ export default async function prettyDiagnostic(
125
125
  }
126
126
 
127
127
  if (Array.isArray(hints) && hints.length) {
128
- result.hints = hints.map(h => {
128
+ result.hints = hints.map((h) => {
129
129
  return md(h);
130
130
  });
131
131
  }
@@ -33,7 +33,7 @@ export function replaceURLReferences({
33
33
  bundleGraph,
34
34
  contents,
35
35
  map,
36
- getReplacement = s => s,
36
+ getReplacement = (s) => s,
37
37
  relative = true,
38
38
  }: {|
39
39
  bundle: NamedBundle,
@@ -41,11 +41,11 @@ export function replaceURLReferences({
41
41
  contents: string,
42
42
  relative?: boolean,
43
43
  map?: ?SourceMap,
44
- getReplacement?: string => string,
44
+ getReplacement?: (string) => string,
45
45
  |}): {|+contents: string, +map: ?SourceMap|} {
46
46
  let replacements = new Map();
47
47
  let urlDependencies = [];
48
- bundle.traverse(node => {
48
+ bundle.traverse((node) => {
49
49
  if (node.type === 'dependency' && node.value.specifierType === 'url') {
50
50
  urlDependencies.push(node.value);
51
51
  }
@@ -118,7 +118,7 @@ export async function replaceInlineReferences({
118
118
  let replacements = new Map();
119
119
 
120
120
  let dependencies = [];
121
- bundle.traverse(node => {
121
+ bundle.traverse((node) => {
122
122
  if (node.type === 'dependency') {
123
123
  dependencies.push(node.value);
124
124
  }
@@ -165,7 +165,7 @@ export function getURLReplacement({
165
165
  fromBundle: NamedBundle,
166
166
  toBundle: NamedBundle,
167
167
  relative: boolean,
168
- getReplacement?: string => string,
168
+ getReplacement?: (string) => string,
169
169
  |}): {|from: string, to: string|} {
170
170
  let to;
171
171
 
package/src/schema.js CHANGED
@@ -203,12 +203,12 @@ function validateSchema(schema: SchemaEntity, data: mixed): Array<SchemaError> {
203
203
  if (schemaNode.__forbiddenProperties) {
204
204
  // $FlowFixMe type was already checked
205
205
  let keys = Object.keys(dataNode);
206
- invalidProps = schemaNode.__forbiddenProperties.filter(val =>
206
+ invalidProps = schemaNode.__forbiddenProperties.filter((val) =>
207
207
  keys.includes(val),
208
208
  );
209
209
  results.push(
210
210
  ...invalidProps.map(
211
- k =>
211
+ (k) =>
212
212
  ({
213
213
  type: 'forbidden-prop',
214
214
  dataPath: dataPath + '/' + encodeJSONKeyComponent(k),
@@ -225,11 +225,11 @@ function validateSchema(schema: SchemaEntity, data: mixed): Array<SchemaError> {
225
225
  // $FlowFixMe type was already checked
226
226
  let keys = Object.keys(dataNode);
227
227
  let missingKeys = schemaNode.required.filter(
228
- val => !keys.includes(val),
228
+ (val) => !keys.includes(val),
229
229
  );
230
230
  results.push(
231
231
  ...missingKeys.map(
232
- k =>
232
+ (k) =>
233
233
  ({
234
234
  type: 'missing-prop',
235
235
  dataPath,
@@ -268,7 +268,7 @@ function validateSchema(schema: SchemaEntity, data: mixed): Array<SchemaError> {
268
268
  schemaNode.properties,
269
269
  ).filter(
270
270
  // $FlowFixMe type was already checked
271
- p => !(p in dataNode),
271
+ (p) => !(p in dataNode),
272
272
  ),
273
273
  actualValue: k,
274
274
  ancestors: schemaAncestors,
@@ -368,7 +368,7 @@ export function fuzzySearch(
368
368
  actualValue: string,
369
369
  ): Array<string> {
370
370
  let result = expectedValues
371
- .map(exp => [exp, levenshtein.distance(exp, actualValue)])
371
+ .map((exp) => [exp, levenshtein.distance(exp, actualValue)])
372
372
  .filter(
373
373
  // Remove if more than half of the string would need to be changed
374
374
  ([, d]) => d * 2 < actualValue.length,
@@ -414,7 +414,7 @@ validateSchema.diagnostic = function (
414
414
  data.data ?? JSON.parse(data.source);
415
415
  let errors = validateSchema(schema, object);
416
416
  if (errors.length) {
417
- let keys = errors.map(e => {
417
+ let keys = errors.map((e) => {
418
418
  let message;
419
419
  if (e.type === 'enum') {
420
420
  let {actualValue} = e;
@@ -426,11 +426,11 @@ validateSchema.diagnostic = function (
426
426
 
427
427
  if (likely.length > 0) {
428
428
  message = `Did you mean ${likely
429
- .map(v => JSON.stringify(v))
429
+ .map((v) => JSON.stringify(v))
430
430
  .join(', ')}?`;
431
431
  } else if (expectedValues.length > 0) {
432
432
  message = `Possible values: ${expectedValues
433
- .map(v => JSON.stringify(v))
433
+ .map((v) => JSON.stringify(v))
434
434
  .join(', ')}`;
435
435
  } else {
436
436
  message = 'Unexpected value';
@@ -438,11 +438,11 @@ validateSchema.diagnostic = function (
438
438
  } else if (e.type === 'forbidden-prop') {
439
439
  let {prop, expectedProps, actualProps} = e;
440
440
  let likely = fuzzySearch(expectedProps, prop).filter(
441
- v => !actualProps.includes(v),
441
+ (v) => !actualProps.includes(v),
442
442
  );
443
443
  if (likely.length > 0) {
444
444
  message = `Did you mean ${likely
445
- .map(v => JSON.stringify(v))
445
+ .map((v) => JSON.stringify(v))
446
446
  .join(', ')}?`;
447
447
  } else {
448
448
  message = 'Unexpected property';
package/src/sourcemap.js CHANGED
@@ -75,7 +75,7 @@ export async function loadSourceMap(
75
75
  let sourcemapInstance = new SourceMap(options.projectRoot);
76
76
  sourcemapInstance.addVLQMap({
77
77
  ...foundMap.map,
78
- sources: foundMap.map.sources.map(s => {
78
+ sources: foundMap.map.sources.map((s) => {
79
79
  return path.join(mapSourceRoot, s);
80
80
  }),
81
81
  });
package/src/stream.js CHANGED
@@ -6,7 +6,7 @@ import type {Blob} from '@atlaspack/types';
6
6
  export function measureStreamLength(stream: Readable): Promise<number> {
7
7
  return new Promise((resolve, reject) => {
8
8
  let length = 0;
9
- stream.on('data', chunk => {
9
+ stream.on('data', (chunk) => {
10
10
  length += chunk;
11
11
  });
12
12
  stream.on('end', () => resolve(length));
@@ -25,7 +25,7 @@ export function readableFromStringOrBuffer(str: string | Buffer): Readable {
25
25
  export function bufferStream(stream: Readable): Promise<Buffer> {
26
26
  return new Promise((resolve, reject) => {
27
27
  let buf = Buffer.from([]);
28
- stream.on('data', data => {
28
+ stream.on('data', (data) => {
29
29
  buf = Buffer.concat([buf, data]);
30
30
  });
31
31
  stream.on('end', () => {
@@ -45,7 +45,7 @@ export function blobToStream(blob: Blob): Readable {
45
45
 
46
46
  export function streamFromPromise(promise: Promise<Blob>): Readable {
47
47
  const stream = new PassThrough();
48
- promise.then(blob => {
48
+ promise.then((blob) => {
49
49
  if (blob instanceof Readable) {
50
50
  blob.pipe(stream);
51
51
  } else {
@@ -61,7 +61,7 @@ export function fallbackStream(
61
61
  fallback: () => Readable,
62
62
  ): Readable {
63
63
  const res = new PassThrough();
64
- stream.on('error', err => {
64
+ stream.on('error', (err) => {
65
65
  if (err.code === 'ENOENT') {
66
66
  fallback().pipe(res);
67
67
  } else {
@@ -6,7 +6,7 @@ import {DefaultMap} from '../src/DefaultMap';
6
6
  describe('DefaultMap', () => {
7
7
  it('constructs with entries just like Map', () => {
8
8
  let map = new DefaultMap(
9
- k => k,
9
+ (k) => k,
10
10
  [
11
11
  [1, 3],
12
12
  [2, 27],
@@ -20,18 +20,18 @@ describe('DefaultMap', () => {
20
20
  });
21
21
 
22
22
  it("returns a default value based on a key if it doesn't exist", () => {
23
- let map = new DefaultMap(k => k);
23
+ let map = new DefaultMap((k) => k);
24
24
  assert.equal(map.get(3), 3);
25
25
  });
26
26
 
27
27
  it("sets a default value based on a key if it doesn't exist", () => {
28
- let map = new DefaultMap(k => k);
28
+ let map = new DefaultMap((k) => k);
29
29
  map.get(3);
30
30
  assert.deepEqual(Array.from(map.entries()), [[3, 3]]);
31
31
  });
32
32
 
33
33
  it('respects undefined/null if it already existed in the map', () => {
34
- let map = new DefaultMap<number, number | void | null>(k => k);
34
+ let map = new DefaultMap<number, number | void | null>((k) => k);
35
35
  map.set(3, undefined);
36
36
  assert.equal(map.get(3), undefined);
37
37
 
@@ -53,7 +53,7 @@ describe('PromiseQueue', () => {
53
53
  let error = new Error('Oh no!');
54
54
  let promise = queue.add(() => Promise.reject(error));
55
55
  await queue.run().catch(() => null);
56
- await promise.then(null, e => assert.equal(e, error));
56
+ await promise.then(null, (e) => assert.equal(e, error));
57
57
  });
58
58
 
59
59
  it('constructor() should allow for configuration of max concurrent running functions', async () => {