@parcel/utils 2.0.0-rc.0 → 2.1.1

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.
@@ -74,7 +74,8 @@ async function findAllFilesUp({
74
74
  basedir,
75
75
  maxlength,
76
76
  collected,
77
- leadingDotSlash = true
77
+ leadingDotSlash = true,
78
+ includeDirectories = true
78
79
  }) {
79
80
  let dirContent = (await fs.readdir(dir)).sort();
80
81
  return Promise.all(dirContent.map(async item => {
@@ -86,7 +87,7 @@ async function findAllFilesUp({
86
87
  let stats = await fs.stat(fullPath);
87
88
  let isDir = stats.isDirectory();
88
89
 
89
- if (isDir || stats.isFile()) {
90
+ if (isDir && includeDirectories || stats.isFile()) {
90
91
  collected.push(relativeFilePath);
91
92
  } // If it's a directory, run over each item within said directory...
92
93
 
@@ -105,7 +106,7 @@ async function findAllFilesUp({
105
106
  }));
106
107
  }
107
108
 
108
- async function findAlternativeFiles(fs, fileSpecifier, dir, projectRoot, leadingDotSlash = true) {
109
+ async function findAlternativeFiles(fs, fileSpecifier, dir, projectRoot, leadingDotSlash = true, includeDirectories = true, includeExtension = false) {
109
110
  let potentialFiles = []; // Find our root, we won't recommend files above the package root as that's bad practise
110
111
 
111
112
  let pkg = await (0, _config.resolveConfig)(fs, _path().default.join(dir, 'index'), ['package.json'], projectRoot);
@@ -117,10 +118,11 @@ async function findAlternativeFiles(fs, fileSpecifier, dir, projectRoot, leading
117
118
  basedir: dir,
118
119
  maxlength: fileSpecifier.length + 10,
119
120
  collected: potentialFiles,
120
- leadingDotSlash
121
+ leadingDotSlash,
122
+ includeDirectories
121
123
  });
122
124
 
123
- if (_path().default.extname(fileSpecifier) === '') {
125
+ if (_path().default.extname(fileSpecifier) === '' && !includeExtension) {
124
126
  potentialFiles = potentialFiles.map(p => {
125
127
  let ext = _path().default.extname(p);
126
128
 
package/lib/ansi-html.js CHANGED
@@ -5,10 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.ansiHtml = ansiHtml;
7
7
 
8
- function _ansiHtml() {
9
- const data = _interopRequireDefault(require("ansi-html"));
8
+ function _ansiHtmlCommunity() {
9
+ const data = _interopRequireDefault(require("ansi-html-community"));
10
10
 
11
- _ansiHtml = function () {
11
+ _ansiHtmlCommunity = function () {
12
12
  return data;
13
13
  };
14
14
 
@@ -20,5 +20,5 @@ var _escapeHtml = require("./escape-html");
20
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
21
 
22
22
  function ansiHtml(ansi) {
23
- return (0, _ansiHtml().default)((0, _escapeHtml.escapeHTML)(ansi));
23
+ return (0, _ansiHtmlCommunity().default)((0, _escapeHtml.escapeHTML)(ansi));
24
24
  }
package/lib/blob.js CHANGED
@@ -6,6 +6,16 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.blobToBuffer = blobToBuffer;
7
7
  exports.blobToString = blobToString;
8
8
 
9
+ function _buffer() {
10
+ const data = require("buffer");
11
+
12
+ _buffer = function () {
13
+ return data;
14
+ };
15
+
16
+ return data;
17
+ }
18
+
9
19
  var _ = require("./");
10
20
 
11
21
  function _stream() {
@@ -21,17 +31,17 @@ function _stream() {
21
31
  function blobToBuffer(blob) {
22
32
  if (blob instanceof _stream().Readable) {
23
33
  return (0, _.bufferStream)(blob);
24
- } else if (blob instanceof Buffer) {
25
- return Promise.resolve(Buffer.from(blob));
34
+ } else if (blob instanceof _buffer().Buffer) {
35
+ return Promise.resolve(_buffer().Buffer.from(blob));
26
36
  } else {
27
- return Promise.resolve(Buffer.from(blob, 'utf8'));
37
+ return Promise.resolve(_buffer().Buffer.from(blob, 'utf8'));
28
38
  }
29
39
  }
30
40
 
31
41
  async function blobToString(blob) {
32
42
  if (blob instanceof _stream().Readable) {
33
43
  return (await (0, _.bufferStream)(blob)).toString();
34
- } else if (blob instanceof Buffer) {
44
+ } else if (blob instanceof _buffer().Buffer) {
35
45
  return blob.toString();
36
46
  } else {
37
47
  return blob;
package/lib/collection.js CHANGED
@@ -7,6 +7,8 @@ exports.unique = unique;
7
7
  exports.objectSortedEntries = objectSortedEntries;
8
8
  exports.objectSortedEntriesDeep = objectSortedEntriesDeep;
9
9
  exports.setDifference = setDifference;
10
+ exports.setIntersect = setIntersect;
11
+ exports.setUnion = setUnion;
10
12
 
11
13
  function unique(array) {
12
14
  return [...new Set(array)];
@@ -48,4 +50,16 @@ function setDifference(a, b) {
48
50
  }
49
51
 
50
52
  return difference;
53
+ }
54
+
55
+ function setIntersect(a, b) {
56
+ for (let entry of a) {
57
+ if (!b.has(entry)) {
58
+ a.delete(entry);
59
+ }
60
+ }
61
+ }
62
+
63
+ function setUnion(a, b) {
64
+ return new Set([...a, ...b]);
51
65
  }
package/lib/config.js CHANGED
@@ -7,6 +7,16 @@ exports.resolveConfig = resolveConfig;
7
7
  exports.resolveConfigSync = resolveConfigSync;
8
8
  exports.loadConfig = loadConfig;
9
9
 
10
+ function _diagnostic() {
11
+ const data = _interopRequireDefault(require("@parcel/diagnostic"));
12
+
13
+ _diagnostic = function () {
14
+ return data;
15
+ };
16
+
17
+ return data;
18
+ }
19
+
10
20
  function _path() {
11
21
  const data = _interopRequireDefault(require("path"));
12
22
 
@@ -112,7 +122,6 @@ async function loadConfig(fs, filepath, filenames, projectRoot, opts) {
112
122
  }
113
123
 
114
124
  let configContent = await fs.readFile(configFile, 'utf8');
115
- if (!configContent) return null;
116
125
  let config;
117
126
 
118
127
  if (parse === false) {
@@ -121,7 +130,35 @@ async function loadConfig(fs, filepath, filenames, projectRoot, opts) {
121
130
  var _opts$parser;
122
131
 
123
132
  let parse = (_opts$parser = opts === null || opts === void 0 ? void 0 : opts.parser) !== null && _opts$parser !== void 0 ? _opts$parser : getParser(extname);
124
- config = parse(configContent);
133
+
134
+ try {
135
+ config = parse(configContent);
136
+ } catch (e) {
137
+ if (extname !== '' && extname !== 'json') {
138
+ throw e;
139
+ }
140
+
141
+ let pos = {
142
+ line: e.lineNumber,
143
+ column: e.columnNumber
144
+ };
145
+ throw new (_diagnostic().default)({
146
+ diagnostic: {
147
+ message: `Failed to parse ${_path().default.basename(configFile)}`,
148
+ origin: '@parcel/utils',
149
+ codeFrames: [{
150
+ language: 'json5',
151
+ filePath: configFile,
152
+ code: configContent,
153
+ codeHighlights: [{
154
+ start: pos,
155
+ end: pos,
156
+ message: e.message
157
+ }]
158
+ }]
159
+ }
160
+ });
161
+ }
125
162
  }
126
163
 
127
164
  let output = {
package/lib/index.js CHANGED
@@ -171,6 +171,18 @@ Object.defineProperty(exports, "setDifference", {
171
171
  return _collection.setDifference;
172
172
  }
173
173
  });
174
+ Object.defineProperty(exports, "setIntersect", {
175
+ enumerable: true,
176
+ get: function () {
177
+ return _collection.setIntersect;
178
+ }
179
+ });
180
+ Object.defineProperty(exports, "setUnion", {
181
+ enumerable: true,
182
+ get: function () {
183
+ return _collection.setUnion;
184
+ }
185
+ });
174
186
  Object.defineProperty(exports, "resolveConfig", {
175
187
  enumerable: true,
176
188
  get: function () {
@@ -249,6 +261,12 @@ Object.defineProperty(exports, "hashFile", {
249
261
  return _hash.hashFile;
250
262
  }
251
263
  });
264
+ Object.defineProperty(exports, "SharedBuffer", {
265
+ enumerable: true,
266
+ get: function () {
267
+ return _sharedBuffer.SharedBuffer;
268
+ }
269
+ });
252
270
  Object.defineProperty(exports, "createHTTPServer", {
253
271
  enumerable: true,
254
272
  get: function () {
@@ -430,6 +448,8 @@ var _glob = require("./glob");
430
448
 
431
449
  var _hash = require("./hash");
432
450
 
451
+ var _sharedBuffer = require("./shared-buffer");
452
+
433
453
  var _httpServer = require("./http-server");
434
454
 
435
455
  var _path = require("./path");
@@ -55,8 +55,19 @@ function _nullthrows() {
55
55
  return data;
56
56
  }
57
57
 
58
+ function _terminalLink() {
59
+ const data = _interopRequireDefault(require("terminal-link"));
60
+
61
+ _terminalLink = function () {
62
+ return data;
63
+ };
64
+
65
+ return data;
66
+ }
67
+
58
68
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
59
69
 
70
+ // $FlowFixMe
60
71
  async function prettyDiagnostic(diagnostic, options, terminalWidth) {
61
72
  let {
62
73
  origin,
@@ -64,13 +75,15 @@ async function prettyDiagnostic(diagnostic, options, terminalWidth) {
64
75
  stack,
65
76
  codeFrames,
66
77
  hints,
67
- skipFormatting
78
+ skipFormatting,
79
+ documentationURL
68
80
  } = diagnostic;
69
81
  let result = {
70
82
  message: (0, _markdownAnsi().default)(`**${origin !== null && origin !== void 0 ? origin : 'unknown'}**: `) + (skipFormatting ? message : (0, _markdownAnsi().default)(message)),
71
83
  stack: '',
72
84
  codeframe: '',
73
- hints: []
85
+ hints: [],
86
+ documentation: ''
74
87
  };
75
88
 
76
89
  if (codeFrames != null) {
@@ -116,5 +129,11 @@ async function prettyDiagnostic(diagnostic, options, terminalWidth) {
116
129
  });
117
130
  }
118
131
 
132
+ if (documentationURL != null) {
133
+ result.documentation = (0, _terminalLink().default)('Learn more', documentationURL, {
134
+ fallback: (text, url) => `${text}: ${url}`
135
+ });
136
+ }
137
+
119
138
  return result;
120
139
  }
@@ -92,7 +92,7 @@ function replaceURLReferences({
92
92
  continue;
93
93
  }
94
94
 
95
- if (!resolved || resolved.bundleBehavior === 'inline') {
95
+ if (resolved.bundleBehavior === 'inline') {
96
96
  // If a bundle is inline, it should be replaced with inline contents,
97
97
  // not a URL.
98
98
  continue;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SharedBuffer = void 0;
7
+
8
+ /* global MessageChannel:readonly */
9
+ let SharedBuffer; // $FlowFixMe[prop-missing]
10
+
11
+ exports.SharedBuffer = SharedBuffer;
12
+
13
+ if (process.browser) {
14
+ exports.SharedBuffer = SharedBuffer = ArrayBuffer; // Safari has removed the constructor
15
+
16
+ if (typeof SharedArrayBuffer !== 'undefined') {
17
+ let channel = new MessageChannel();
18
+
19
+ try {
20
+ // Firefox might throw when sending the Buffer over a MessagePort
21
+ channel.port1.postMessage(new SharedArrayBuffer(0));
22
+ exports.SharedBuffer = SharedBuffer = SharedArrayBuffer;
23
+ } catch (_) {// NOOP
24
+ }
25
+
26
+ channel.port1.close();
27
+ channel.port2.close();
28
+ }
29
+ } else {
30
+ exports.SharedBuffer = SharedBuffer = SharedArrayBuffer;
31
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcel/utils",
3
- "version": "2.0.0-rc.0",
3
+ "version": "2.1.1",
4
4
  "description": "Blazing fast, zero configuration web application bundler",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -21,13 +21,13 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@iarna/toml": "^2.2.0",
24
- "@parcel/codeframe": "2.0.0-rc.0",
25
- "@parcel/diagnostic": "2.0.0-rc.0",
26
- "@parcel/hash": "2.0.0-rc.0",
27
- "@parcel/logger": "2.0.0-rc.0",
28
- "@parcel/markdown-ansi": "2.0.0-rc.0",
29
- "@parcel/source-map": "2.0.0-rc.6",
30
- "ansi-html": "^0.0.7",
24
+ "@parcel/codeframe": "^2.1.1",
25
+ "@parcel/diagnostic": "^2.1.1",
26
+ "@parcel/hash": "^2.1.1",
27
+ "@parcel/logger": "^2.1.1",
28
+ "@parcel/markdown-ansi": "^2.1.1",
29
+ "@parcel/source-map": "^2.0.0",
30
+ "ansi-html-community": "0.0.8",
31
31
  "chalk": "^4.1.0",
32
32
  "clone": "^2.1.1",
33
33
  "fast-glob": "3.1.1",
@@ -36,14 +36,20 @@
36
36
  "is-url": "^1.2.2",
37
37
  "json5": "^1.0.1",
38
38
  "lru-cache": "^6.0.0",
39
- "micromatch": "^3.0.4",
39
+ "micromatch": "^4.0.4",
40
40
  "node-forge": "^0.10.0",
41
41
  "nullthrows": "^1.1.1",
42
- "open": "^7.0.3"
42
+ "open": "^7.0.3",
43
+ "terminal-link": "^2.1.1"
43
44
  },
44
45
  "devDependencies": {
45
46
  "@babel/plugin-transform-flow-strip-types": "^7.2.0",
46
47
  "random-int": "^1.0.0"
47
48
  },
48
- "gitHead": "8fc248f1f8eeb4428f7abd768bd23111451b1903"
49
+ "browser": {
50
+ "./src/generateCertificate.js": false,
51
+ "./src/http-server.js": false,
52
+ "./src/openInBrowser.js": false
53
+ },
54
+ "gitHead": "f53ffe772a8259d94ca2937d02fde149454112f3"
49
55
  }
@@ -63,6 +63,7 @@ async function findAllFilesUp({
63
63
  maxlength,
64
64
  collected,
65
65
  leadingDotSlash = true,
66
+ includeDirectories = true,
66
67
  }: {|
67
68
  fs: FileSystem,
68
69
  dir: string,
@@ -71,6 +72,7 @@ async function findAllFilesUp({
71
72
  maxlength: number,
72
73
  collected: Array<string>,
73
74
  leadingDotSlash?: boolean,
75
+ includeDirectories?: boolean,
74
76
  |}): Promise<mixed> {
75
77
  let dirContent = (await fs.readdir(dir)).sort();
76
78
  return Promise.all(
@@ -80,7 +82,7 @@ async function findAllFilesUp({
80
82
  if (relativeFilePath.length < maxlength) {
81
83
  let stats = await fs.stat(fullPath);
82
84
  let isDir = stats.isDirectory();
83
- if (isDir || stats.isFile()) {
85
+ if ((isDir && includeDirectories) || stats.isFile()) {
84
86
  collected.push(relativeFilePath);
85
87
  }
86
88
 
@@ -106,6 +108,8 @@ export async function findAlternativeFiles(
106
108
  dir: string,
107
109
  projectRoot: string,
108
110
  leadingDotSlash?: boolean = true,
111
+ includeDirectories?: boolean = true,
112
+ includeExtension?: boolean = false,
109
113
  ): Promise<Array<string>> {
110
114
  let potentialFiles: Array<string> = [];
111
115
  // Find our root, we won't recommend files above the package root as that's bad practise
@@ -125,9 +129,10 @@ export async function findAlternativeFiles(
125
129
  maxlength: fileSpecifier.length + 10,
126
130
  collected: potentialFiles,
127
131
  leadingDotSlash,
132
+ includeDirectories,
128
133
  });
129
134
 
130
- if (path.extname(fileSpecifier) === '') {
135
+ if (path.extname(fileSpecifier) === '' && !includeExtension) {
131
136
  potentialFiles = potentialFiles.map(p => {
132
137
  let ext = path.extname(p);
133
138
  return ext.length > 0 ? p.slice(0, -ext.length) : p;
package/src/ansi-html.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // @flow strict-local
2
- import ansiHTML from 'ansi-html';
2
+ import ansiHTML from 'ansi-html-community';
3
3
  import {escapeHTML} from './escape-html';
4
4
 
5
5
  export function ansiHtml(ansi: string): string {
package/src/blob.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  import type {Blob} from '@parcel/types';
4
4
 
5
+ import {Buffer} from 'buffer';
5
6
  import {bufferStream} from './';
6
7
  import {Readable} from 'stream';
7
8
 
package/src/collection.js CHANGED
@@ -6,14 +6,14 @@ export function unique<T>(array: Array<T>): Array<T> {
6
6
 
7
7
  export function objectSortedEntries(obj: {
8
8
  +[string]: mixed,
9
- ...,
9
+ ...
10
10
  }): Array<[string, mixed]> {
11
11
  return Object.entries(obj).sort(([keyA], [keyB]) => keyA.localeCompare(keyB));
12
12
  }
13
13
 
14
14
  export function objectSortedEntriesDeep(object: {
15
15
  +[string]: mixed,
16
- ...,
16
+ ...
17
17
  }): Array<[string, mixed]> {
18
18
  let sortedEntries = objectSortedEntries(object);
19
19
  for (let i = 0; i < sortedEntries.length; i++) {
@@ -43,3 +43,15 @@ export function setDifference<T>(a: Set<T>, b: Set<T>): Set<T> {
43
43
  }
44
44
  return difference;
45
45
  }
46
+
47
+ export function setIntersect<T>(a: Set<T>, b: Set<T>): void {
48
+ for (let entry of a) {
49
+ if (!b.has(entry)) {
50
+ a.delete(entry);
51
+ }
52
+ }
53
+ }
54
+
55
+ export function setUnion<T>(a: Iterable<T>, b: Iterable<T>): Set<T> {
56
+ return new Set([...a, ...b]);
57
+ }
package/src/config.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  import type {ConfigResult, File, FilePath} from '@parcel/types';
4
4
  import type {FileSystem} from '@parcel/fs';
5
+ import ThrowableDiagnostic from '@parcel/diagnostic';
5
6
  import path from 'path';
6
7
  import clone from 'clone';
7
8
  import {parse as json5} from 'json5';
@@ -82,14 +83,45 @@ export async function loadConfig(
82
83
  }
83
84
 
84
85
  let configContent = await fs.readFile(configFile, 'utf8');
85
- if (!configContent) return null;
86
86
 
87
87
  let config;
88
88
  if (parse === false) {
89
89
  config = configContent;
90
90
  } else {
91
91
  let parse = opts?.parser ?? getParser(extname);
92
- config = parse(configContent);
92
+ try {
93
+ config = parse(configContent);
94
+ } catch (e) {
95
+ if (extname !== '' && extname !== 'json') {
96
+ throw e;
97
+ }
98
+
99
+ let pos = {
100
+ line: e.lineNumber,
101
+ column: e.columnNumber,
102
+ };
103
+
104
+ throw new ThrowableDiagnostic({
105
+ diagnostic: {
106
+ message: `Failed to parse ${path.basename(configFile)}`,
107
+ origin: '@parcel/utils',
108
+ codeFrames: [
109
+ {
110
+ language: 'json5',
111
+ filePath: configFile,
112
+ code: configContent,
113
+ codeHighlights: [
114
+ {
115
+ start: pos,
116
+ end: pos,
117
+ message: e.message,
118
+ },
119
+ ],
120
+ },
121
+ ],
122
+ },
123
+ });
124
+ }
93
125
  }
94
126
 
95
127
  let output = {
package/src/debounce.js CHANGED
@@ -6,7 +6,7 @@ export default function debounce<TArgs: Array<mixed>>(
6
6
  ): (...args: TArgs) => void {
7
7
  let timeout;
8
8
 
9
- return function(...args: TArgs) {
9
+ return function (...args: TArgs) {
10
10
  if (timeout) {
11
11
  clearTimeout(timeout);
12
12
  }
@@ -14,10 +14,7 @@ export default function getExisting(
14
14
  return {
15
15
  source,
16
16
  minified: fs.existsSync(minifiedPath)
17
- ? fs
18
- .readFileSync(minifiedPath, 'utf8')
19
- .trim()
20
- .replace(/;$/, '')
17
+ ? fs.readFileSync(minifiedPath, 'utf8').trim().replace(/;$/, '')
21
18
  : source,
22
19
  };
23
20
  }
package/src/hash.js CHANGED
@@ -16,7 +16,7 @@ export function hashStream(stream: Readable): Promise<string> {
16
16
  .on('data', chunk => {
17
17
  hash.writeBuffer(chunk);
18
18
  })
19
- .on('end', function() {
19
+ .on('end', function () {
20
20
  resolve(hash.finish());
21
21
  })
22
22
  .on('error', err => {
package/src/index.js CHANGED
@@ -35,12 +35,15 @@ export {
35
35
  objectSortedEntries,
36
36
  objectSortedEntriesDeep,
37
37
  setDifference,
38
+ setIntersect,
39
+ setUnion,
38
40
  } from './collection';
39
41
  export {resolveConfig, resolveConfigSync, loadConfig} from './config';
40
42
  export {DefaultMap, DefaultWeakMap} from './DefaultMap';
41
43
  export {makeDeferredWithPromise} from './Deferred';
42
44
  export {isGlob, isGlobMatch, globSync, glob} from './glob';
43
45
  export {hashStream, hashObject, hashFile} from './hash';
46
+ export {SharedBuffer} from './shared-buffer';
44
47
  export {fuzzySearch} from './schema';
45
48
  export {createHTTPServer} from './http-server';
46
49
  export {normalizePath, normalizeSeparators, relativePath} from './path';
@@ -7,12 +7,15 @@ import mdAnsi from '@parcel/markdown-ansi';
7
7
  import chalk from 'chalk';
8
8
  import path from 'path';
9
9
  import nullthrows from 'nullthrows';
10
+ // $FlowFixMe
11
+ import terminalLink from 'terminal-link';
10
12
 
11
13
  export type AnsiDiagnosticResult = {|
12
14
  message: string,
13
15
  stack: string,
14
16
  codeframe: string,
15
17
  hints: Array<string>,
18
+ documentation: string,
16
19
  |};
17
20
 
18
21
  export default async function prettyDiagnostic(
@@ -20,7 +23,15 @@ export default async function prettyDiagnostic(
20
23
  options?: PluginOptions,
21
24
  terminalWidth?: number,
22
25
  ): Promise<AnsiDiagnosticResult> {
23
- let {origin, message, stack, codeFrames, hints, skipFormatting} = diagnostic;
26
+ let {
27
+ origin,
28
+ message,
29
+ stack,
30
+ codeFrames,
31
+ hints,
32
+ skipFormatting,
33
+ documentationURL,
34
+ } = diagnostic;
24
35
 
25
36
  let result = {
26
37
  message:
@@ -29,6 +40,7 @@ export default async function prettyDiagnostic(
29
40
  stack: '',
30
41
  codeframe: '',
31
42
  hints: [],
43
+ documentation: '',
32
44
  };
33
45
 
34
46
  if (codeFrames != null) {
@@ -80,5 +92,11 @@ export default async function prettyDiagnostic(
80
92
  });
81
93
  }
82
94
 
95
+ if (documentationURL != null) {
96
+ result.documentation = terminalLink('Learn more', documentationURL, {
97
+ fallback: (text, url) => `${text}: ${url}`,
98
+ });
99
+ }
100
+
83
101
  return result;
84
102
  }
@@ -66,7 +66,7 @@ export function replaceURLReferences({
66
66
  continue;
67
67
  }
68
68
 
69
- if (!resolved || resolved.bundleBehavior === 'inline') {
69
+ if (resolved.bundleBehavior === 'inline') {
70
70
  // If a bundle is inline, it should be replaced with inline contents,
71
71
  // not a URL.
72
72
  continue;
@@ -131,9 +131,10 @@ export async function replaceInlineReferences({
131
131
  entryBundle,
132
132
  bundleGraph,
133
133
  );
134
- let packagedContents = (packagedBundle.contents instanceof Readable
135
- ? await bufferStream(packagedBundle.contents)
136
- : packagedBundle.contents
134
+ let packagedContents = (
135
+ packagedBundle.contents instanceof Readable
136
+ ? await bufferStream(packagedBundle.contents)
137
+ : packagedBundle.contents
137
138
  ).toString();
138
139
 
139
140
  let inlineType = nullthrows(entryBundle.getMainEntry()).meta.inlineType;
package/src/schema.js CHANGED
@@ -378,7 +378,7 @@ export function fuzzySearch(
378
378
  return result.map(([v]) => v);
379
379
  }
380
380
 
381
- validateSchema.diagnostic = function(
381
+ validateSchema.diagnostic = function (
382
382
  schema: SchemaEntity,
383
383
  data: {|
384
384
  ...
@@ -0,0 +1,24 @@
1
+ // @flow
2
+ /* global MessageChannel:readonly */
3
+
4
+ export let SharedBuffer: Class<ArrayBuffer> | Class<SharedArrayBuffer>;
5
+
6
+ // $FlowFixMe[prop-missing]
7
+ if (process.browser) {
8
+ SharedBuffer = ArrayBuffer;
9
+ // Safari has removed the constructor
10
+ if (typeof SharedArrayBuffer !== 'undefined') {
11
+ let channel = new MessageChannel();
12
+ try {
13
+ // Firefox might throw when sending the Buffer over a MessagePort
14
+ channel.port1.postMessage(new SharedArrayBuffer(0));
15
+ SharedBuffer = SharedArrayBuffer;
16
+ } catch (_) {
17
+ // NOOP
18
+ }
19
+ channel.port1.close();
20
+ channel.port2.close();
21
+ }
22
+ } else {
23
+ SharedBuffer = SharedArrayBuffer;
24
+ }
package/src/sourcemap.js CHANGED
@@ -5,7 +5,8 @@ import SourceMap from '@parcel/source-map';
5
5
  import path from 'path';
6
6
  import {normalizeSeparators, isAbsolute} from './path';
7
7
 
8
- export const SOURCEMAP_RE: RegExp = /(?:\/\*|\/\/)\s*[@#]\s*sourceMappingURL\s*=\s*([^\s*]+)(?:\s*\*\/)?\s*$/;
8
+ export const SOURCEMAP_RE: RegExp =
9
+ /(?:\/\*|\/\/)\s*[@#]\s*sourceMappingURL\s*=\s*([^\s*]+)(?:\s*\*\/)?\s*$/;
9
10
  const DATA_URL_RE = /^data:[^;]+(?:;charset=[^;]+)?;base64,(.*)/;
10
11
  export const SOURCEMAP_EXTENSIONS: Set<string> = new Set<string>([
11
12
  'css',
@@ -5,10 +5,13 @@ import {DefaultMap} from '../src/DefaultMap';
5
5
 
6
6
  describe('DefaultMap', () => {
7
7
  it('constructs with entries just like Map', () => {
8
- let map = new DefaultMap(k => k, [
9
- [1, 3],
10
- [2, 27],
11
- ]);
8
+ let map = new DefaultMap(
9
+ k => k,
10
+ [
11
+ [1, 3],
12
+ [2, 27],
13
+ ],
14
+ );
12
15
  assert.equal(map.get(1), 3);
13
16
  assert.deepEqual(Array.from(map.entries()), [
14
17
  [1, 3],
@@ -0,0 +1,50 @@
1
+ // @flow strict-local
2
+
3
+ import assert from 'assert';
4
+ import {loadConfig} from '../src/config';
5
+ import {inputFS as fs} from '@parcel/test-utils';
6
+ import path from 'path';
7
+
8
+ describe('loadConfig', () => {
9
+ it('load config with json', async () => {
10
+ assert.deepEqual(
11
+ (
12
+ await loadConfig(
13
+ fs,
14
+ path.join(__dirname, './input/config/config.json'),
15
+ ['config.json'],
16
+ path.join(__dirname, './input/config/'),
17
+ )
18
+ )?.config,
19
+ {
20
+ hoge: 'fuga',
21
+ },
22
+ );
23
+ });
24
+
25
+ it('should throw error with empty string json', async () => {
26
+ // $FlowFixMe[prop-missing]
27
+ await assert.rejects(async () => {
28
+ await loadConfig(
29
+ fs,
30
+ path.join(__dirname, './input/config/empty.json'),
31
+ ['empty.json'],
32
+ path.join(__dirname, './input/config/'),
33
+ );
34
+ });
35
+ });
36
+
37
+ it('should load with empty string config toml', async () => {
38
+ assert.deepEqual(
39
+ (
40
+ await loadConfig(
41
+ fs,
42
+ path.join(__dirname, './input/config/empty.toml'),
43
+ ['empty.toml'],
44
+ path.join(__dirname, './input/config/'),
45
+ )
46
+ )?.config,
47
+ {},
48
+ );
49
+ });
50
+ });
@@ -0,0 +1,3 @@
1
+ {
2
+ "hoge": "fuga"
3
+ }
File without changes
File without changes
@@ -34,7 +34,7 @@ describe('throttle', () => {
34
34
 
35
35
  it('preserves the `this` when throttled functions are invoked', () => {
36
36
  let result;
37
- let throttled = throttle(function() {
37
+ let throttled = throttle(function () {
38
38
  result = this.bar;
39
39
  }, 100);
40
40
 
package/src/.babelrc DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "presets": ["@parcel/babel-preset"]
3
- }