@parcel/utils 2.0.0-nightly.97 → 2.1.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 (100) hide show
  1. package/.eslintrc.js +6 -6
  2. package/lib/DefaultMap.js +0 -8
  3. package/lib/Deferred.js +10 -2
  4. package/lib/PromiseQueue.js +21 -30
  5. package/lib/TapStream.js +10 -10
  6. package/lib/alternatives.js +134 -0
  7. package/lib/ansi-html.js +10 -2
  8. package/lib/blob.js +26 -8
  9. package/lib/collection.js +14 -11
  10. package/lib/config.js +145 -35
  11. package/lib/countLines.js +2 -2
  12. package/lib/dependency-location.js +3 -3
  13. package/lib/generateBuildMetrics.js +148 -0
  14. package/lib/generateCertificate.js +33 -8
  15. package/lib/getExisting.js +11 -3
  16. package/lib/getRootDir.js +18 -7
  17. package/lib/glob.js +53 -19
  18. package/lib/hash.js +44 -0
  19. package/lib/http-server.js +48 -10
  20. package/lib/index.js +298 -224
  21. package/lib/is-url.js +12 -2
  22. package/lib/isDirectoryInside.js +24 -0
  23. package/lib/objectHash.js +10 -2
  24. package/lib/openInBrowser.js +94 -0
  25. package/lib/path.js +33 -6
  26. package/lib/prettyDiagnostic.js +107 -25
  27. package/lib/relativeBundlePath.js +13 -7
  28. package/lib/relativeUrl.js +19 -3
  29. package/lib/replaceBundleReferences.js +91 -35
  30. package/lib/schema.js +104 -33
  31. package/lib/shared-buffer.js +31 -0
  32. package/lib/sourcemap.js +147 -0
  33. package/lib/stream.js +38 -3
  34. package/lib/urlJoin.js +25 -6
  35. package/package.json +27 -16
  36. package/src/DefaultMap.js +1 -1
  37. package/src/PromiseQueue.js +16 -12
  38. package/src/alternatives.js +143 -0
  39. package/src/ansi-html.js +2 -2
  40. package/src/blob.js +4 -3
  41. package/src/bundle-url.js +1 -1
  42. package/src/collection.js +14 -14
  43. package/src/config.js +100 -35
  44. package/src/countLines.js +5 -2
  45. package/src/debounce.js +1 -1
  46. package/src/dependency-location.js +11 -6
  47. package/src/generateBuildMetrics.js +158 -0
  48. package/src/generateCertificate.js +1 -1
  49. package/src/getCertificate.js +1 -1
  50. package/src/getExisting.js +1 -4
  51. package/src/getRootDir.js +1 -2
  52. package/src/glob.js +29 -11
  53. package/src/hash.js +34 -0
  54. package/src/http-server.js +10 -12
  55. package/src/index.js +52 -23
  56. package/src/is-url.js +1 -1
  57. package/src/isDirectoryInside.js +11 -0
  58. package/src/openInBrowser.js +64 -0
  59. package/src/path.js +38 -6
  60. package/src/prettyDiagnostic.js +58 -24
  61. package/src/relativeBundlePath.js +8 -13
  62. package/src/replaceBundleReferences.js +75 -39
  63. package/src/schema.js +101 -44
  64. package/src/shared-buffer.js +24 -0
  65. package/src/sourcemap.js +135 -0
  66. package/src/stream.js +31 -1
  67. package/src/urlJoin.js +3 -1
  68. package/test/DefaultMap.test.js +7 -4
  69. package/test/config.test.js +50 -0
  70. package/test/input/config/config.json +3 -0
  71. package/test/input/config/empty.json +0 -0
  72. package/test/input/config/empty.toml +0 -0
  73. package/test/input/sourcemap/referenced-min.js +2 -0
  74. package/test/input/sourcemap/referenced-min.js.map +6 -0
  75. package/test/input/sourcemap/source-root.js +2 -0
  76. package/test/input/sourcemap/source-root.js.map +7 -0
  77. package/test/objectHash.test.js +33 -0
  78. package/test/prettifyTime.test.js +17 -0
  79. package/test/replaceBundleReferences.test.js +268 -0
  80. package/test/sourcemap.test.js +207 -0
  81. package/test/throttle.test.js +1 -2
  82. package/test/urlJoin.test.js +37 -0
  83. package/lib/generateBundleReport.js +0 -38
  84. package/lib/loadSourceMapUrl.js +0 -33
  85. package/lib/md5.js +0 -35
  86. package/lib/prettyError.js +0 -43
  87. package/lib/promisify.js +0 -13
  88. package/lib/resolve.js +0 -93
  89. package/lib/serializeObject.js +0 -28
  90. package/src/.babelrc +0 -3
  91. package/src/generateBundleReport.js +0 -51
  92. package/src/loadSourceMapUrl.js +0 -33
  93. package/src/md5.js +0 -44
  94. package/src/prettyError.js +0 -54
  95. package/src/promisify.js +0 -13
  96. package/src/resolve.js +0 -123
  97. package/src/serializeObject.js +0 -22
  98. package/test/input/sourcemap/referenced.js +0 -7
  99. package/test/loadSourceMapUrl.test.js +0 -37
  100. package/test/prettyError.test.js +0 -104
@@ -1,38 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = generateBundleReport;
7
-
8
- var _nullthrows = _interopRequireDefault(require("nullthrows"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
- function generateBundleReport(bundleGraph, largestAssetCount = 10) {
13
- let bundles = [];
14
- bundleGraph.traverseBundles(bundle => {
15
- bundles.push(bundle);
16
- });
17
- bundles.sort((a, b) => b.stats.size - a.stats.size);
18
- return {
19
- bundles: bundles.map(bundle => {
20
- let assets = [];
21
- bundle.traverseAssets(asset => {
22
- assets.push(asset);
23
- });
24
- assets.sort((a, b) => b.stats.size - a.stats.size);
25
- return {
26
- filePath: (0, _nullthrows.default)(bundle.filePath),
27
- size: bundle.stats.size,
28
- time: bundle.stats.time,
29
- largestAssets: assets.slice(0, largestAssetCount).map(asset => ({
30
- filePath: asset.filePath,
31
- size: asset.stats.size,
32
- time: asset.stats.time
33
- })),
34
- totalAssets: assets.length
35
- };
36
- })
37
- };
38
- }
@@ -1,33 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.matchSourceMappingURL = matchSourceMappingURL;
7
- exports.default = loadSourceMapUrl;
8
-
9
- var _path = _interopRequireDefault(require("path"));
10
-
11
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
-
13
- const SOURCEMAP_RE = /(?:\/\*|\/\/)\s*[@#]\s*sourceMappingURL\s*=\s*([^\s*]+)(?:\s*\*\/)?\s*$/;
14
- const DATA_URL_RE = /^data:[^;]+(?:;charset=[^;]+)?;base64,(.*)/;
15
-
16
- function matchSourceMappingURL(contents) {
17
- return contents.match(SOURCEMAP_RE);
18
- }
19
-
20
- async function loadSourceMapUrl(fs, filename, contents) {
21
- let match = matchSourceMappingURL(contents);
22
-
23
- if (match) {
24
- let url = match[1].trim();
25
- let dataURLMatch = url.match(DATA_URL_RE);
26
- filename = dataURLMatch ? filename : _path.default.join(_path.default.dirname(filename), url);
27
- return {
28
- url,
29
- filename,
30
- map: JSON.parse(dataURLMatch ? Buffer.from(dataURLMatch[1], 'base64').toString() : await fs.readFile(filename, 'utf8'))
31
- };
32
- }
33
- }
package/lib/md5.js DELETED
@@ -1,35 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.md5FromString = md5FromString;
7
- exports.md5FromReadableStream = md5FromReadableStream;
8
- exports.md5FromObject = md5FromObject;
9
- exports.md5FromFilePath = md5FromFilePath;
10
-
11
- var _crypto = _interopRequireDefault(require("crypto"));
12
-
13
- var _collection = require("./collection");
14
-
15
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
-
17
- function md5FromString(string, encoding = 'hex') {
18
- return _crypto.default.createHash('md5').update(string).digest(encoding);
19
- }
20
-
21
- function md5FromReadableStream(stream) {
22
- return new Promise((resolve, reject) => {
23
- stream.pipe(_crypto.default.createHash('md5').setEncoding('hex')).on('finish', function () {
24
- resolve(this.read());
25
- }).on('error', reject);
26
- });
27
- }
28
-
29
- function md5FromObject(obj, encoding = 'hex') {
30
- return md5FromString(JSON.stringify((0, _collection.objectSortedEntriesDeep)(obj)), encoding);
31
- }
32
-
33
- function md5FromFilePath(fs, filePath) {
34
- return md5FromReadableStream(fs.createReadStream(filePath));
35
- }
@@ -1,43 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = prettyError;
7
-
8
- function prettyError(err, opts = {}) {
9
- if (typeof err === 'string') {
10
- return {
11
- message: err
12
- };
13
- }
14
-
15
- let message = err.message;
16
-
17
- if (!message) {
18
- message = 'Unknown error';
19
- }
20
-
21
- if (err.fileName != null) {
22
- let fileName = err.fileName;
23
-
24
- if (err.loc) {
25
- fileName += `:${err.loc.line}:${err.loc.column}`;
26
- }
27
-
28
- message = `${fileName}: ${message}`;
29
- }
30
-
31
- let stack;
32
-
33
- if (err.codeFrame != null && err.codeFrame !== '') {
34
- stack = opts.color === true && err.highlightedCodeFrame || err.codeFrame;
35
- } else if (err.stack) {
36
- stack = err.stack.slice(err.stack.indexOf('\n') + 1);
37
- }
38
-
39
- return {
40
- message,
41
- stack
42
- };
43
- }
package/lib/promisify.js DELETED
@@ -1,13 +0,0 @@
1
- "use strict";
2
-
3
- module.exports = function (fn) {
4
- return function (...args) {
5
- return new Promise(function (resolve, reject) {
6
- fn(...args, function (err, ...res) {
7
- if (err) return reject(err);
8
- if (res.length === 1) return resolve(res[0]);
9
- resolve(res);
10
- });
11
- });
12
- };
13
- };
package/lib/resolve.js DELETED
@@ -1,93 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.resolve = resolve;
7
- exports.resolveSync = resolveSync;
8
-
9
- var _promisify = _interopRequireDefault(require("./promisify"));
10
-
11
- var _resolve2 = _interopRequireDefault(require("resolve"));
12
-
13
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
-
15
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
16
-
17
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
18
-
19
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
20
-
21
- const resolveAsync = (0, _promisify.default)(_resolve2.default);
22
-
23
- async function resolve(fs, id, opts) {
24
- let res = await resolveAsync(id, _objectSpread({}, opts, {
25
- async readFile(filename, callback) {
26
- try {
27
- let res = await fs.readFile(filename);
28
- callback(null, res);
29
- } catch (err) {
30
- callback(err);
31
- }
32
- },
33
-
34
- async isFile(file, callback) {
35
- try {
36
- let stat = await fs.stat(file);
37
- callback(null, stat.isFile());
38
- } catch (err) {
39
- callback(null, false);
40
- }
41
- },
42
-
43
- async isDirectory(file, callback) {
44
- try {
45
- let stat = await fs.stat(file);
46
- callback(null, stat.isDirectory());
47
- } catch (err) {
48
- callback(null, false);
49
- }
50
- }
51
-
52
- }));
53
-
54
- if (typeof res === 'string') {
55
- return {
56
- resolved: res
57
- };
58
- }
59
-
60
- return {
61
- resolved: res[0],
62
- pkg: res[1]
63
- };
64
- }
65
-
66
- function resolveSync(fs, id, opts) {
67
- // $FlowFixMe
68
- let res = _resolve2.default.sync(id, _objectSpread({}, opts, {
69
- readFileSync: (...args) => {
70
- return fs.readFileSync(...args);
71
- },
72
- isFile: file => {
73
- try {
74
- let stat = fs.statSync(file);
75
- return stat.isFile();
76
- } catch (err) {
77
- return false;
78
- }
79
- },
80
- isDirectory: file => {
81
- try {
82
- let stat = fs.statSync(file);
83
- return stat.isDirectory();
84
- } catch (err) {
85
- return false;
86
- }
87
- }
88
- }));
89
-
90
- return {
91
- resolved: res
92
- };
93
- }
@@ -1,28 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = serializeObject;
7
-
8
- var _terser = require("terser");
9
-
10
- var _serializeToJs = _interopRequireDefault(require("serialize-to-js"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- function serializeObject(obj, shouldMinify = false) {
15
- let code = `module.exports = ${(0, _serializeToJs.default)(obj)};`;
16
-
17
- if (shouldMinify) {
18
- let minified = (0, _terser.minify)(code);
19
-
20
- if (minified.error) {
21
- throw minified.error;
22
- }
23
-
24
- code = minified.code;
25
- }
26
-
27
- return code;
28
- }
package/src/.babelrc DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "presets": ["@parcel/babel-preset"]
3
- }
@@ -1,51 +0,0 @@
1
- // @flow strict-local
2
-
3
- import type {Asset, BundleGraph} from '@parcel/types';
4
- import nullthrows from 'nullthrows';
5
-
6
- export type BundleReport = {|
7
- bundles: Array<{|
8
- filePath: string,
9
- size: number,
10
- time: number,
11
- largestAssets: Array<{|
12
- filePath: string,
13
- size: number,
14
- time: number,
15
- |}>,
16
- totalAssets: number,
17
- |}>,
18
- |};
19
-
20
- export default function generateBundleReport(
21
- bundleGraph: BundleGraph,
22
- largestAssetCount: number = 10,
23
- ): BundleReport {
24
- let bundles = [];
25
- bundleGraph.traverseBundles(bundle => {
26
- bundles.push(bundle);
27
- });
28
- bundles.sort((a, b) => b.stats.size - a.stats.size);
29
-
30
- return {
31
- bundles: bundles.map(bundle => {
32
- let assets: Array<Asset> = [];
33
- bundle.traverseAssets(asset => {
34
- assets.push(asset);
35
- });
36
- assets.sort((a, b) => b.stats.size - a.stats.size);
37
-
38
- return {
39
- filePath: nullthrows(bundle.filePath),
40
- size: bundle.stats.size,
41
- time: bundle.stats.time,
42
- largestAssets: assets.slice(0, largestAssetCount).map(asset => ({
43
- filePath: asset.filePath,
44
- size: asset.stats.size,
45
- time: asset.stats.time,
46
- })),
47
- totalAssets: assets.length,
48
- };
49
- }),
50
- };
51
- }
@@ -1,33 +0,0 @@
1
- // @flow
2
- import type {FileSystem} from '@parcel/fs';
3
- import path from 'path';
4
-
5
- const SOURCEMAP_RE = /(?:\/\*|\/\/)\s*[@#]\s*sourceMappingURL\s*=\s*([^\s*]+)(?:\s*\*\/)?\s*$/;
6
- const DATA_URL_RE = /^data:[^;]+(?:;charset=[^;]+)?;base64,(.*)/;
7
-
8
- export function matchSourceMappingURL(contents: string) {
9
- return contents.match(SOURCEMAP_RE);
10
- }
11
-
12
- export default async function loadSourceMapUrl(
13
- fs: FileSystem,
14
- filename: string,
15
- contents: string,
16
- ) {
17
- let match = matchSourceMappingURL(contents);
18
- if (match) {
19
- let url = match[1].trim();
20
- let dataURLMatch = url.match(DATA_URL_RE);
21
- filename = dataURLMatch ? filename : path.join(path.dirname(filename), url);
22
-
23
- return {
24
- url,
25
- filename,
26
- map: JSON.parse(
27
- dataURLMatch
28
- ? Buffer.from(dataURLMatch[1], 'base64').toString()
29
- : await fs.readFile(filename, 'utf8'),
30
- ),
31
- };
32
- }
33
- }
package/src/md5.js DELETED
@@ -1,44 +0,0 @@
1
- // @flow strict-local
2
-
3
- import type {Readable} from 'stream';
4
- import type {FileSystem} from '@parcel/fs';
5
-
6
- import crypto from 'crypto';
7
- import {objectSortedEntriesDeep} from './collection';
8
-
9
- type StringHashEncoding = 'hex' | 'latin1' | 'binary' | 'base64';
10
-
11
- export function md5FromString(
12
- string: string | Buffer,
13
- encoding: StringHashEncoding = 'hex',
14
- ): string {
15
- return crypto
16
- .createHash('md5')
17
- .update(string)
18
- .digest(encoding);
19
- }
20
-
21
- export function md5FromReadableStream(stream: Readable): Promise<string> {
22
- return new Promise((resolve, reject) => {
23
- stream
24
- .pipe(crypto.createHash('md5').setEncoding('hex'))
25
- .on('finish', function() {
26
- resolve(this.read());
27
- })
28
- .on('error', reject);
29
- });
30
- }
31
-
32
- export function md5FromObject(
33
- obj: {+[string]: mixed, ...},
34
- encoding: StringHashEncoding = 'hex',
35
- ): string {
36
- return md5FromString(JSON.stringify(objectSortedEntriesDeep(obj)), encoding);
37
- }
38
-
39
- export function md5FromFilePath(
40
- fs: FileSystem,
41
- filePath: string,
42
- ): Promise<string> {
43
- return md5FromReadableStream(fs.createReadStream(filePath));
44
- }
@@ -1,54 +0,0 @@
1
- // @flow strict-local
2
-
3
- export type PrintableError =
4
- | string
5
- | (Error & {
6
- codeFrame?: string,
7
- highlightedCodeFrame?: string,
8
- loc?: {|
9
- column: number,
10
- line: number,
11
- |},
12
- ...
13
- });
14
-
15
- export type PrettyErrorOpts = {color?: boolean, ...};
16
-
17
- export type PrettyError = {|
18
- message: string,
19
- stack?: string,
20
- |};
21
-
22
- export default function prettyError(
23
- err: PrintableError,
24
- opts: PrettyErrorOpts = {},
25
- ): PrettyError {
26
- if (typeof err === 'string') {
27
- return {
28
- message: err,
29
- };
30
- }
31
-
32
- let message = err.message;
33
- if (!message) {
34
- message = 'Unknown error';
35
- }
36
-
37
- if (err.fileName != null) {
38
- let fileName = err.fileName;
39
- if (err.loc) {
40
- fileName += `:${err.loc.line}:${err.loc.column}`;
41
- }
42
-
43
- message = `${fileName}: ${message}`;
44
- }
45
-
46
- let stack;
47
- if (err.codeFrame != null && err.codeFrame !== '') {
48
- stack = (opts.color === true && err.highlightedCodeFrame) || err.codeFrame;
49
- } else if (err.stack) {
50
- stack = err.stack.slice(err.stack.indexOf('\n') + 1);
51
- }
52
-
53
- return {message, stack};
54
- }
package/src/promisify.js DELETED
@@ -1,13 +0,0 @@
1
- module.exports = function(fn) {
2
- return function(...args) {
3
- return new Promise(function(resolve, reject) {
4
- fn(...args, function(err, ...res) {
5
- if (err) return reject(err);
6
-
7
- if (res.length === 1) return resolve(res[0]);
8
-
9
- resolve(res);
10
- });
11
- });
12
- };
13
- };
package/src/resolve.js DELETED
@@ -1,123 +0,0 @@
1
- // @flow strict-local
2
-
3
- import type {PackageJSON, FilePath, ModuleSpecifier} from '@parcel/types';
4
- import type {ResolveOptions} from 'resolve';
5
- import type {FileSystem} from '@parcel/fs';
6
-
7
- // $FlowFixMe TODO: Type promisify
8
- import promisify from './promisify';
9
- import _resolve from 'resolve';
10
-
11
- const resolveAsync = promisify(_resolve);
12
-
13
- export type ResolveResult = {|
14
- resolved: FilePath | ModuleSpecifier,
15
- pkg?: ?PackageJSON,
16
- |};
17
-
18
- export async function resolve(
19
- fs: FileSystem,
20
- id: string,
21
- opts?: ResolveOptions,
22
- ): Promise<ResolveResult> {
23
- if (process.env.PARCEL_BUILD_ENV !== 'production') {
24
- // $FlowFixMe
25
- opts = opts || {};
26
- // $FlowFixMe
27
- opts.packageFilter = pkg => {
28
- if (pkg.name.startsWith('@parcel/') && pkg.name !== '@parcel/watcher') {
29
- if (pkg.source) {
30
- pkg.main = pkg.source;
31
- }
32
- }
33
- return pkg;
34
- };
35
- }
36
-
37
- let res = await resolveAsync(id, {
38
- ...opts,
39
- async readFile(filename, callback) {
40
- try {
41
- let res = await fs.readFile(filename);
42
- callback(null, res);
43
- } catch (err) {
44
- callback(err);
45
- }
46
- },
47
- async isFile(file, callback) {
48
- try {
49
- let stat = await fs.stat(file);
50
- callback(null, stat.isFile());
51
- } catch (err) {
52
- callback(null, false);
53
- }
54
- },
55
- async isDirectory(file, callback) {
56
- try {
57
- let stat = await fs.stat(file);
58
- callback(null, stat.isDirectory());
59
- } catch (err) {
60
- callback(null, false);
61
- }
62
- },
63
- });
64
-
65
- if (typeof res === 'string') {
66
- return {
67
- resolved: res,
68
- };
69
- }
70
-
71
- return {
72
- resolved: res[0],
73
- pkg: res[1],
74
- };
75
- }
76
-
77
- export function resolveSync(
78
- fs: FileSystem,
79
- id: string,
80
- opts?: ResolveOptions,
81
- ): ResolveResult {
82
- if (process.env.PARCEL_BUILD_ENV !== 'production') {
83
- // $FlowFixMe
84
- opts = opts || {};
85
- // $FlowFixMe
86
- opts.packageFilter = pkg => {
87
- if (pkg.name.startsWith('@parcel/') && pkg.name !== '@parcel/watcher') {
88
- if (pkg.source) {
89
- pkg.main = pkg.source;
90
- }
91
- }
92
- return pkg;
93
- };
94
- }
95
-
96
- // $FlowFixMe
97
- let res = _resolve.sync(id, {
98
- ...opts,
99
- readFileSync: (...args) => {
100
- return fs.readFileSync(...args);
101
- },
102
- isFile: file => {
103
- try {
104
- let stat = fs.statSync(file);
105
- return stat.isFile();
106
- } catch (err) {
107
- return false;
108
- }
109
- },
110
- isDirectory: file => {
111
- try {
112
- let stat = fs.statSync(file);
113
- return stat.isDirectory();
114
- } catch (err) {
115
- return false;
116
- }
117
- },
118
- });
119
-
120
- return {
121
- resolved: res,
122
- };
123
- }
@@ -1,22 +0,0 @@
1
- // @flow
2
-
3
- import {minify} from 'terser';
4
- import serialize from 'serialize-to-js';
5
-
6
- export default function serializeObject(
7
- obj: mixed,
8
- shouldMinify: boolean = false,
9
- ) {
10
- let code = `module.exports = ${serialize(obj)};`;
11
-
12
- if (shouldMinify) {
13
- let minified = minify(code);
14
- if (minified.error) {
15
- throw minified.error;
16
- }
17
-
18
- code = minified.code;
19
- }
20
-
21
- return code;
22
- }
@@ -1,7 +0,0 @@
1
- function hello() {
2
- var l = 'Hello',
3
- o = 'world';
4
- console.log(l + ' ' + o + '!');
5
- }
6
- hello();
7
- //# sourceMappingURL=main.min.js.map
@@ -1,37 +0,0 @@
1
- import assert from 'assert';
2
- import {matchSourceMappingURL} from '../src/loadSourceMapUrl';
3
- import fs from 'fs';
4
- import path from 'path';
5
-
6
- describe('loadSourceMap', () => {
7
- it('should not match sourceMappingURL when not at the end of the bundle', () => {
8
- // Code example taken from livescript.js (issue #2408 in parcel-bundler)
9
- // This snippet lead to JSAsset.js being mislead and incorrectly trying to
10
- // load (due to false-positive match) sourcemap before fix was introduced
11
- let code = fs.readFileSync(
12
- path.join(__dirname, './input/sourcemap/no-sourcemap.js'),
13
- 'utf-8',
14
- );
15
-
16
- assert(!matchSourceMappingURL(code));
17
- });
18
-
19
- it('should match referenced sourceMappingURL when correctly inserted at end of the bundle', () => {
20
- let code = fs.readFileSync(
21
- path.join(__dirname, './input/sourcemap/referenced.js'),
22
- 'utf-8',
23
- );
24
-
25
- assert(!!matchSourceMappingURL(code));
26
- });
27
-
28
- it('should match inline sourceMappingURL when correctly inserted at end of the bundle', () => {
29
- // inline source map taken from https://github.com/thlorenz/inline-source-map
30
- let code = fs.readFileSync(
31
- path.join(__dirname, './input/sourcemap/inline.js'),
32
- 'utf-8',
33
- );
34
-
35
- assert(!!matchSourceMappingURL(code));
36
- });
37
- });