@parcel/utils 2.6.2 → 2.8.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcel/utils",
3
- "version": "2.6.2",
3
+ "version": "2.8.0",
4
4
  "description": "Blazing fast, zero configuration web application bundler",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -33,12 +33,12 @@
33
33
  }
34
34
  },
35
35
  "dependencies": {
36
- "@parcel/codeframe": "2.6.2",
37
- "@parcel/diagnostic": "2.6.2",
38
- "@parcel/hash": "2.6.2",
39
- "@parcel/logger": "2.6.2",
40
- "@parcel/markdown-ansi": "2.6.2",
41
- "@parcel/source-map": "^2.0.0",
36
+ "@parcel/codeframe": "2.8.0",
37
+ "@parcel/diagnostic": "2.8.0",
38
+ "@parcel/hash": "2.8.0",
39
+ "@parcel/logger": "2.8.0",
40
+ "@parcel/markdown-ansi": "2.8.0",
41
+ "@parcel/source-map": "^2.1.1",
42
42
  "chalk": "^4.1.0"
43
43
  },
44
44
  "devDependencies": {
@@ -63,5 +63,5 @@
63
63
  "./src/http-server.js": false,
64
64
  "./src/openInBrowser.js": false
65
65
  },
66
- "gitHead": "e10fcfc1e8b71222da90978fb87f1b68e207473e"
66
+ "gitHead": "c3bbe0a6160186f496ca2f9e9bead9376c0522f1"
67
67
  }
package/src/collection.js CHANGED
@@ -55,3 +55,15 @@ export function setIntersect<T>(a: Set<T>, b: Set<T>): void {
55
55
  export function setUnion<T>(a: Iterable<T>, b: Iterable<T>): Set<T> {
56
56
  return new Set([...a, ...b]);
57
57
  }
58
+
59
+ export function setEqual<T>(a: Set<T>, b: Set<T>): boolean {
60
+ if (a.size != b.size) {
61
+ return false;
62
+ }
63
+ for (let entry of a) {
64
+ if (!b.has(entry)) {
65
+ return false;
66
+ }
67
+ }
68
+ return true;
69
+ }
package/src/config.js CHANGED
@@ -71,7 +71,7 @@ export async function loadConfig(
71
71
 
72
72
  try {
73
73
  let extname = path.extname(configFile).slice(1);
74
- if (extname === 'js') {
74
+ if (extname === 'js' || extname === 'cjs') {
75
75
  let output = {
76
76
  // $FlowFixMe
77
77
  config: clone(require(configFile)),
@@ -0,0 +1,23 @@
1
+ // @flow strict-local
2
+ import path from 'path';
3
+
4
+ import {normalizeSeparators} from './path';
5
+
6
+ /**
7
+ * Returns the package name and the optional subpath
8
+ */
9
+ export default function getModuleParts(_name: string): [string, ?string] {
10
+ let name = path.normalize(_name);
11
+ let splitOn = name.indexOf(path.sep);
12
+ if (name.charAt(0) === '@') {
13
+ splitOn = name.indexOf(path.sep, splitOn + 1);
14
+ }
15
+ if (splitOn < 0) {
16
+ return [normalizeSeparators(name), undefined];
17
+ } else {
18
+ return [
19
+ normalizeSeparators(name.substring(0, splitOn)),
20
+ name.substring(splitOn + 1) || undefined,
21
+ ];
22
+ }
23
+ }
package/src/index.js CHANGED
@@ -11,6 +11,7 @@ export {default as countLines} from './countLines';
11
11
  export {default as generateBuildMetrics} from './generateBuildMetrics';
12
12
  export {default as generateCertificate} from './generateCertificate';
13
13
  export {default as getCertificate} from './getCertificate';
14
+ export {default as getModuleParts} from './getModuleParts';
14
15
  export {default as getRootDir} from './getRootDir';
15
16
  export {default as isDirectoryInside} from './isDirectoryInside';
16
17
  export {default as isURL} from './is-url';
@@ -35,12 +36,14 @@ export {
35
36
  objectSortedEntries,
36
37
  objectSortedEntriesDeep,
37
38
  setDifference,
39
+ setEqual,
38
40
  setIntersect,
39
41
  setUnion,
40
42
  } from './collection';
41
43
  export {resolveConfig, resolveConfigSync, loadConfig} from './config';
42
44
  export {DefaultMap, DefaultWeakMap} from './DefaultMap';
43
45
  export {makeDeferredWithPromise} from './Deferred';
46
+ export {getProgressMessage} from './progress-message.js';
44
47
  export {isGlob, isGlobMatch, globSync, glob, globToRegex} from './glob';
45
48
  export {hashStream, hashObject, hashFile} from './hash';
46
49
  export {SharedBuffer} from './shared-buffer';
@@ -6,7 +6,6 @@ import formatCodeFrame from '@parcel/codeframe';
6
6
  import mdAnsi from '@parcel/markdown-ansi';
7
7
  import chalk from 'chalk';
8
8
  import path from 'path';
9
- import nullthrows from 'nullthrows';
10
9
  // $FlowFixMe
11
10
  import terminalLink from 'terminal-link';
12
11
 
@@ -60,10 +59,10 @@ export default async function prettyDiagnostic(
60
59
  }
61
60
 
62
61
  let highlights = codeFrame.codeHighlights;
63
- let code =
64
- codeFrame.code ??
65
- (options &&
66
- (await options.inputFS.readFile(nullthrows(filePath), 'utf8')));
62
+ let code = codeFrame.code;
63
+ if (code == null && options && filePath != null) {
64
+ code = await options.inputFS.readFile(filePath, 'utf8');
65
+ }
67
66
 
68
67
  let formattedCodeFrame = '';
69
68
  if (code != null) {
@@ -0,0 +1,22 @@
1
+ // @flow strict-local
2
+ import type {BuildProgressEvent} from '@parcel/types';
3
+
4
+ import path from 'path';
5
+
6
+ export function getProgressMessage(event: BuildProgressEvent): ?string {
7
+ switch (event.phase) {
8
+ case 'transforming':
9
+ return `Building ${path.basename(event.filePath)}...`;
10
+
11
+ case 'bundling':
12
+ return 'Bundling...';
13
+
14
+ case 'packaging':
15
+ return `Packaging ${event.bundle.displayName}...`;
16
+
17
+ case 'optimizing':
18
+ return `Optimizing ${event.bundle.displayName}...`;
19
+ }
20
+
21
+ return null;
22
+ }
@@ -47,4 +47,52 @@ describe('loadConfig', () => {
47
47
  {},
48
48
  );
49
49
  });
50
+
51
+ it('should load with js', async () => {
52
+ assert.deepEqual(
53
+ (
54
+ await loadConfig(
55
+ fs,
56
+ path.join(__dirname, './input/config/config.js'),
57
+ ['config.js'],
58
+ path.join(__dirname, './input/config/'),
59
+ )
60
+ )?.config,
61
+ {
62
+ hoge: 'fuga',
63
+ },
64
+ );
65
+ });
66
+
67
+ it('should load with cjs', async () => {
68
+ assert.deepEqual(
69
+ (
70
+ await loadConfig(
71
+ fs,
72
+ path.join(__dirname, './input/config/config.cjs'),
73
+ ['config.cjs'],
74
+ path.join(__dirname, './input/config/'),
75
+ )
76
+ )?.config,
77
+ {
78
+ hoge: 'fuga',
79
+ },
80
+ );
81
+ });
82
+
83
+ it('should load without an extension as json', async () => {
84
+ assert.deepEqual(
85
+ (
86
+ await loadConfig(
87
+ fs,
88
+ path.join(__dirname, './input/config/.testrc'),
89
+ ['.testrc'],
90
+ path.join(__dirname, './input/config/'),
91
+ )
92
+ )?.config,
93
+ {
94
+ hoge: 'fuga',
95
+ },
96
+ );
97
+ });
50
98
  });
@@ -0,0 +1,3 @@
1
+ {
2
+ "hoge": "fuga"
3
+ }
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ hoge: 'fuga',
3
+ };
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ hoge: 'fuga',
3
+ };