@modern-js/utils 1.3.7 → 1.5.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/.eslintrc.js +9 -0
- package/CHANGELOG.md +31 -0
- package/compiled/browserslist/index.d.ts +178 -0
- package/compiled/browserslist/index.js +1 -0
- package/compiled/browserslist/license +20 -0
- package/compiled/browserslist/package.json +1 -0
- package/compiled/chalk/index.d.ts +415 -0
- package/compiled/chalk/index.js +1 -0
- package/compiled/chalk/license +9 -0
- package/compiled/chalk/package.json +1 -0
- package/compiled/chokidar/anymatch/index.d.ts +19 -0
- package/compiled/chokidar/fsevents.node +0 -0
- package/compiled/chokidar/index.js +40 -0
- package/compiled/chokidar/license +21 -0
- package/compiled/chokidar/package.json +1 -0
- package/compiled/chokidar/types/index.d.ts +188 -0
- package/compiled/commander/index.js +1 -0
- package/compiled/commander/license +22 -0
- package/compiled/commander/package.json +1 -0
- package/compiled/commander/typings/index.d.ts +774 -0
- package/compiled/debug/index.d.ts +54 -0
- package/compiled/debug/index.js +1 -0
- package/compiled/debug/license +20 -0
- package/compiled/debug/ms/index.d.ts +25 -0
- package/compiled/debug/package.json +1 -0
- package/compiled/execa/index.d.ts +564 -0
- package/compiled/execa/index.js +1 -0
- package/compiled/execa/license +9 -0
- package/compiled/execa/package.json +1 -0
- package/compiled/filesize/filesize.d.ts +131 -0
- package/compiled/filesize/index.js +9 -0
- package/compiled/filesize/license +28 -0
- package/compiled/filesize/package.json +1 -0
- package/compiled/fs-extra/index.d.ts +563 -0
- package/compiled/fs-extra/index.js +1 -0
- package/compiled/fs-extra/license +15 -0
- package/compiled/fs-extra/package.json +1 -0
- package/compiled/glob/index.d.ts +91 -0
- package/compiled/glob/index.js +1 -0
- package/compiled/glob/license +21 -0
- package/compiled/glob/minimatch/index.d.ts +204 -0
- package/compiled/glob/package.json +1 -0
- package/compiled/gzip-size/index.d.ts +96 -0
- package/compiled/gzip-size/index.js +1 -0
- package/compiled/gzip-size/license +9 -0
- package/compiled/gzip-size/package.json +1 -0
- package/compiled/import-lazy/index.d.ts +26 -0
- package/compiled/import-lazy/index.js +1 -0
- package/compiled/import-lazy/license +9 -0
- package/compiled/import-lazy/package.json +1 -0
- package/compiled/js-yaml/index.d.ts +154 -0
- package/compiled/js-yaml/index.js +1 -0
- package/compiled/js-yaml/license +21 -0
- package/compiled/js-yaml/package.json +1 -0
- package/compiled/lodash/common/array.d.ts +2126 -0
- package/compiled/lodash/common/collection.d.ts +1930 -0
- package/compiled/lodash/common/common.d.ts +280 -0
- package/compiled/lodash/common/date.d.ts +23 -0
- package/compiled/lodash/common/function.d.ts +1446 -0
- package/compiled/lodash/common/lang.d.ts +1693 -0
- package/compiled/lodash/common/math.d.ts +405 -0
- package/compiled/lodash/common/number.d.ts +131 -0
- package/compiled/lodash/common/object.d.ts +2519 -0
- package/compiled/lodash/common/seq.d.ts +210 -0
- package/compiled/lodash/common/string.d.ts +788 -0
- package/compiled/lodash/common/util.d.ts +1220 -0
- package/compiled/lodash/index.d.ts +46 -0
- package/compiled/lodash/index.js +9 -0
- package/compiled/lodash/license +47 -0
- package/compiled/lodash/package.json +1 -0
- package/compiled/pkg-up/index.d.ts +48 -0
- package/compiled/pkg-up/index.js +1 -0
- package/compiled/pkg-up/license +9 -0
- package/compiled/pkg-up/package.json +1 -0
- package/compiled/recursive-readdir/index.d.ts +21 -0
- package/compiled/recursive-readdir/index.js +1 -0
- package/compiled/recursive-readdir/license +21 -0
- package/compiled/recursive-readdir/package.json +1 -0
- package/compiled/signale/index.d.ts +162 -0
- package/compiled/signale/index.js +1 -0
- package/compiled/signale/package.json +1 -0
- package/compiled/strip-ansi/index.d.ts +17 -0
- package/compiled/strip-ansi/index.js +1 -0
- package/compiled/strip-ansi/license +9 -0
- package/compiled/strip-ansi/package.json +1 -0
- package/compiled/upath/index.js +1 -0
- package/compiled/upath/license +22 -0
- package/compiled/upath/package.json +1 -0
- package/compiled/upath/upath.d.ts +241 -0
- package/dist/{types/FileSizeReporter.d.ts → FileSizeReporter.d.ts} +5 -5
- package/dist/FileSizeReporter.js +151 -0
- package/dist/{types/alias.d.ts → alias.d.ts} +12 -14
- package/dist/alias.js +62 -0
- package/dist/analyzeProject.d.ts +1 -0
- package/dist/analyzeProject.js +44 -0
- package/dist/applyOptionsChain.d.ts +6 -0
- package/dist/applyOptionsChain.js +30 -0
- package/dist/clearConsole.d.ts +1 -0
- package/dist/clearConsole.js +9 -0
- package/dist/{types/compatRequire.d.ts → compatRequire.d.ts} +1 -1
- package/dist/compatRequire.js +28 -0
- package/dist/compiled.d.ts +21 -0
- package/dist/compiled.js +33 -0
- package/dist/constants.d.ts +222 -0
- package/dist/constants.js +277 -0
- package/dist/{js/modern/debug.js → debug.d.ts} +1 -3
- package/dist/debug.js +11 -0
- package/dist/emptyDir.d.ts +1 -0
- package/dist/emptyDir.js +19 -0
- package/dist/{types/ensureAbsolutePath.d.ts → ensureAbsolutePath.d.ts} +1 -1
- package/dist/ensureAbsolutePath.js +15 -0
- package/dist/{types/findExists.d.ts → findExists.d.ts} +1 -1
- package/dist/findExists.js +21 -0
- package/dist/{types/format.d.ts → format.d.ts} +3 -3
- package/dist/format.js +113 -0
- package/dist/{types/generateMetaTags.d.ts → generateMetaTags.d.ts} +3 -3
- package/dist/generateMetaTags.js +48 -0
- package/dist/{types/getBrowserslist.d.ts → getBrowserslist.d.ts} +1 -1
- package/dist/getBrowserslist.js +7 -0
- package/dist/{types/getCacheIdentifier.d.ts → getCacheIdentifier.d.ts} +3 -3
- package/dist/getCacheIdentifier.js +24 -0
- package/dist/{types/getEntryOptions.d.ts → getEntryOptions.d.ts} +1 -1
- package/dist/getEntryOptions.js +26 -0
- package/dist/{types/getPackageManager.d.ts → getPackageManager.d.ts} +1 -1
- package/dist/getPackageManager.js +47 -0
- package/dist/{types/getPort.d.ts → getPort.d.ts} +1 -1
- package/dist/getPort.js +62 -0
- package/dist/getServerConfig.d.ts +1 -0
- package/dist/getServerConfig.js +39 -0
- package/dist/{types/import.d.ts → import.d.ts} +2 -2
- package/dist/import.js +10 -0
- package/dist/{types/index.d.ts → index.d.ts} +5 -4
- package/dist/index.js +46 -0
- package/dist/{types/is → is}/index.d.ts +1 -4
- package/dist/is/index.js +82 -0
- package/dist/{types/is → is}/node-env.d.ts +1 -1
- package/dist/is/node-env.js +12 -0
- package/dist/is/platform.d.ts +2 -0
- package/dist/is/platform.js +10 -0
- package/dist/{types/is → is}/type.d.ts +1 -1
- package/dist/is/type.js +38 -0
- package/dist/logger.d.ts +63 -0
- package/dist/logger.js +128 -0
- package/dist/{types/monorepo.d.ts → monorepo.d.ts} +3 -3
- package/dist/monorepo.js +80 -0
- package/dist/{types/nodeEnv.d.ts → nodeEnv.d.ts} +1 -1
- package/dist/nodeEnv.js +49 -0
- package/dist/{types/path.d.ts → path.d.ts} +1 -1
- package/dist/path.js +14 -0
- package/dist/{types/prettyInstructions.d.ts → prettyInstructions.d.ts} +2 -2
- package/dist/prettyInstructions.js +64 -0
- package/dist/{types/printBuildError.d.ts → printBuildError.d.ts} +1 -1
- package/dist/printBuildError.js +43 -0
- package/dist/{types/readTsConfig.d.ts → readTsConfig.d.ts} +1 -1
- package/dist/readTsConfig.js +19 -0
- package/dist/{types/removeSlash.d.ts → removeSlash.d.ts} +1 -1
- package/dist/removeSlash.js +9 -0
- package/dist/{types/runtimeExports.d.ts → runtimeExports.d.ts} +3 -3
- package/dist/runtimeExports.js +53 -0
- package/dist/ssrHelpers.d.ts +4 -0
- package/dist/ssrHelpers.js +7 -0
- package/dist/storage.d.ts +5 -0
- package/dist/storage.js +61 -0
- package/dist/{types/wait.d.ts → wait.d.ts} +1 -1
- package/dist/wait.js +7 -0
- package/dist/{types/watch.d.ts → watch.d.ts} +4 -4
- package/dist/watch.js +64 -0
- package/package.json +55 -37
- package/tsconfig.json +3 -5
- package/dist/js/modern/FileSizeReporter.js +0 -156
- package/dist/js/modern/alias.js +0 -74
- package/dist/js/modern/applyOptionsChain.js +0 -27
- package/dist/js/modern/chalk.js +0 -2
- package/dist/js/modern/clearConsole.js +0 -5
- package/dist/js/modern/compatRequire.js +0 -26
- package/dist/js/modern/constants.js +0 -333
- package/dist/js/modern/emptyDir.js +0 -6
- package/dist/js/modern/ensureAbsolutePath.js +0 -9
- package/dist/js/modern/findExists.js +0 -16
- package/dist/js/modern/format.js +0 -137
- package/dist/js/modern/generateMetaTags.js +0 -49
- package/dist/js/modern/getBrowserslist.js +0 -5
- package/dist/js/modern/getCacheIdentifier.js +0 -20
- package/dist/js/modern/getEntryOptions.js +0 -24
- package/dist/js/modern/getPackageManager.js +0 -37
- package/dist/js/modern/getPort.js +0 -52
- package/dist/js/modern/import.js +0 -11
- package/dist/js/modern/index.js +0 -34
- package/dist/js/modern/is/index.js +0 -77
- package/dist/js/modern/is/node-env.js +0 -5
- package/dist/js/modern/is/platform.js +0 -2
- package/dist/js/modern/is/type.js +0 -25
- package/dist/js/modern/logger.js +0 -152
- package/dist/js/modern/monorepo.js +0 -84
- package/dist/js/modern/nodeEnv.js +0 -31
- package/dist/js/modern/path.js +0 -5
- package/dist/js/modern/pkgUp.js +0 -2
- package/dist/js/modern/prettyInstructions.js +0 -79
- package/dist/js/modern/printBuildError.js +0 -40
- package/dist/js/modern/readTsConfig.js +0 -13
- package/dist/js/modern/removeSlash.js +0 -3
- package/dist/js/modern/runtimeExports.js +0 -52
- package/dist/js/modern/wait.js +0 -5
- package/dist/js/modern/watch.js +0 -43
- package/dist/js/node/FileSizeReporter.js +0 -175
- package/dist/js/node/alias.js +0 -97
- package/dist/js/node/applyOptionsChain.js +0 -37
- package/dist/js/node/chalk.js +0 -15
- package/dist/js/node/clearConsole.js +0 -14
- package/dist/js/node/compatRequire.js +0 -41
- package/dist/js/node/constants.js +0 -353
- package/dist/js/node/debug.js +0 -19
- package/dist/js/node/emptyDir.js +0 -18
- package/dist/js/node/ensureAbsolutePath.js +0 -20
- package/dist/js/node/findExists.js +0 -27
- package/dist/js/node/format.js +0 -141
- package/dist/js/node/generateMetaTags.js +0 -58
- package/dist/js/node/getBrowserslist.js +0 -17
- package/dist/js/node/getCacheIdentifier.js +0 -27
- package/dist/js/node/getEntryOptions.js +0 -35
- package/dist/js/node/getPackageManager.js +0 -51
- package/dist/js/node/getPort.js +0 -67
- package/dist/js/node/import.js +0 -19
- package/dist/js/node/index.js +0 -465
- package/dist/js/node/is/index.js +0 -150
- package/dist/js/node/is/node-env.js +0 -23
- package/dist/js/node/is/platform.js +0 -14
- package/dist/js/node/is/type.js +0 -46
- package/dist/js/node/logger.js +0 -162
- package/dist/js/node/monorepo.js +0 -118
- package/dist/js/node/nodeEnv.js +0 -45
- package/dist/js/node/path.js +0 -24
- package/dist/js/node/pkgUp.js +0 -15
- package/dist/js/node/prettyInstructions.js +0 -95
- package/dist/js/node/printBuildError.js +0 -52
- package/dist/js/node/readTsConfig.js +0 -28
- package/dist/js/node/removeSlash.js +0 -18
- package/dist/js/node/runtimeExports.js +0 -68
- package/dist/js/node/wait.js +0 -12
- package/dist/js/node/watch.js +0 -61
- package/dist/js/treeshaking/FileSizeReporter.js +0 -185
- package/dist/js/treeshaking/alias.js +0 -72
- package/dist/js/treeshaking/applyOptionsChain.js +0 -31
- package/dist/js/treeshaking/chalk.js +0 -2
- package/dist/js/treeshaking/clearConsole.js +0 -5
- package/dist/js/treeshaking/compatRequire.js +0 -29
- package/dist/js/treeshaking/constants.js +0 -333
- package/dist/js/treeshaking/debug.js +0 -10
- package/dist/js/treeshaking/emptyDir.js +0 -37
- package/dist/js/treeshaking/ensureAbsolutePath.js +0 -11
- package/dist/js/treeshaking/findExists.js +0 -33
- package/dist/js/treeshaking/format.js +0 -167
- package/dist/js/treeshaking/generateMetaTags.js +0 -55
- package/dist/js/treeshaking/getBrowserslist.js +0 -7
- package/dist/js/treeshaking/getCacheIdentifier.js +0 -35
- package/dist/js/treeshaking/getEntryOptions.js +0 -26
- package/dist/js/treeshaking/getPackageManager.js +0 -101
- package/dist/js/treeshaking/getPort.js +0 -103
- package/dist/js/treeshaking/import.js +0 -11
- package/dist/js/treeshaking/index.js +0 -34
- package/dist/js/treeshaking/is/index.js +0 -81
- package/dist/js/treeshaking/is/node-env.js +0 -13
- package/dist/js/treeshaking/is/platform.js +0 -6
- package/dist/js/treeshaking/is/type.js +0 -27
- package/dist/js/treeshaking/logger.js +0 -188
- package/dist/js/treeshaking/monorepo.js +0 -95
- package/dist/js/treeshaking/nodeEnv.js +0 -108
- package/dist/js/treeshaking/path.js +0 -11
- package/dist/js/treeshaking/pkgUp.js +0 -2
- package/dist/js/treeshaking/prettyInstructions.js +0 -100
- package/dist/js/treeshaking/printBuildError.js +0 -40
- package/dist/js/treeshaking/readTsConfig.js +0 -13
- package/dist/js/treeshaking/removeSlash.js +0 -9
- package/dist/js/treeshaking/runtimeExports.js +0 -61
- package/dist/js/treeshaking/wait.js +0 -8
- package/dist/js/treeshaking/watch.js +0 -112
- package/dist/types/applyOptionsChain.d.ts +0 -6
- package/dist/types/chalk.d.ts +0 -2
- package/dist/types/clearConsole.d.ts +0 -1
- package/dist/types/constants.d.ts +0 -219
- package/dist/types/debug.d.ts +0 -8
- package/dist/types/emptyDir.d.ts +0 -1
- package/dist/types/is/platform.d.ts +0 -2
- package/dist/types/logger.d.ts +0 -63
- package/dist/types/pkgUp.d.ts +0 -2
- package/tests/.eslintrc.js +0 -6
- package/tests/__snapshots__/prettyInstructions.test.ts.snap +0 -19
- package/tests/applyOptionsChain.test.ts +0 -100
- package/tests/compatRequire.test.ts +0 -32
- package/tests/debug.test.ts +0 -25
- package/tests/ensureAbsolutePath.test.ts +0 -16
- package/tests/findExists.test.ts +0 -22
- package/tests/fixtures/browserlist/develop/package.json +0 -11
- package/tests/fixtures/browserlist/dotfile/.browserslistrc +0 -3
- package/tests/fixtures/browserlist/pkg/package.json +0 -7
- package/tests/fixtures/compat-require/cjs.js +0 -1
- package/tests/fixtures/compat-require/empty.js +0 -1
- package/tests/fixtures/compat-require/esm.js +0 -5
- package/tests/fixtures/compat-require/foo.js +0 -3
- package/tests/fixtures/file-exists/a.ejs +0 -0
- package/tests/fixtures/file-exists/a.js/.gitkeep +0 -0
- package/tests/fixtures/file-exists/a.mjs +0 -0
- package/tests/fixtures/file-exists/a.ts +0 -0
- package/tests/format.test.ts +0 -60
- package/tests/generateMetaTags.test.ts +0 -19
- package/tests/getBrowserslist.test.ts +0 -32
- package/tests/getCacheIdentifier.test.ts +0 -37
- package/tests/getEntryOptions.test.ts +0 -53
- package/tests/index.test.ts +0 -18
- package/tests/is.test.ts +0 -27
- package/tests/isPlatform.test.ts +0 -19
- package/tests/isType.test.ts +0 -85
- package/tests/logger.test.ts +0 -53
- package/tests/prettyInstructions.test.ts +0 -139
- package/tests/removeSlash.test.ts +0 -19
- package/tests/tsconfig.json +0 -11
- package/tests/wait.ts +0 -38
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import net from 'net';
|
|
2
|
-
import { chalk } from "./chalk";
|
|
3
|
-
import { logger } from "./logger";
|
|
4
|
-
/**
|
|
5
|
-
* Get available free port.
|
|
6
|
-
* @param port - Current port want to use.
|
|
7
|
-
* @param tryLimits - Maximum number of retries.
|
|
8
|
-
* @returns Available port number.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/* eslint-disable no-param-reassign, @typescript-eslint/no-loop-func */
|
|
12
|
-
|
|
13
|
-
export const getPort = async (port, tryLimits = 20) => {
|
|
14
|
-
if (typeof port === 'string') {
|
|
15
|
-
port = parseInt(port, 10);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const original = port;
|
|
19
|
-
let found = false;
|
|
20
|
-
let attempts = 0;
|
|
21
|
-
|
|
22
|
-
while (!found && attempts <= tryLimits) {
|
|
23
|
-
try {
|
|
24
|
-
await new Promise((resolve, reject) => {
|
|
25
|
-
const server = net.createServer();
|
|
26
|
-
server.unref();
|
|
27
|
-
server.on('error', reject);
|
|
28
|
-
server.listen({
|
|
29
|
-
port,
|
|
30
|
-
host: '0.0.0.0'
|
|
31
|
-
}, () => {
|
|
32
|
-
found = true;
|
|
33
|
-
server.close(resolve);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
} catch (e) {
|
|
37
|
-
if (e.code !== 'EADDRINUSE') {
|
|
38
|
-
throw e;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
port++;
|
|
42
|
-
attempts++;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (port !== original) {
|
|
47
|
-
logger.info(chalk.red(`Something is already running on port ${original}. ${chalk.yellow(`Use port ${port} instead.`)}`));
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return port;
|
|
51
|
-
};
|
|
52
|
-
/* eslint-enable no-param-reassign, @typescript-eslint/no-loop-func */
|
package/dist/js/modern/import.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// cover: https://rushstack.io/pages/api/node-core-library.import.lazy/
|
|
2
|
-
const lazy = (moduleName, requireFn) => {
|
|
3
|
-
const importLazyLocal = require('import-lazy')(requireFn);
|
|
4
|
-
|
|
5
|
-
return importLazyLocal(moduleName);
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export { lazy as lazyImport };
|
|
9
|
-
export const Import = {
|
|
10
|
-
lazy
|
|
11
|
-
};
|
package/dist/js/modern/index.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import * as _fs from 'fs-extra';
|
|
2
|
-
export { _fs as fs };
|
|
3
|
-
export * from "./chalk";
|
|
4
|
-
export * from "./format";
|
|
5
|
-
export * from "./FileSizeReporter";
|
|
6
|
-
export * from "./printBuildError";
|
|
7
|
-
export * from "./debug";
|
|
8
|
-
export * from "./findExists";
|
|
9
|
-
export * from "./is";
|
|
10
|
-
export * from "./compatRequire";
|
|
11
|
-
export * from "./logger";
|
|
12
|
-
export * from "./constants";
|
|
13
|
-
export * from "./ensureAbsolutePath";
|
|
14
|
-
export * from "./getCacheIdentifier";
|
|
15
|
-
export * from "./clearConsole";
|
|
16
|
-
export * from "./pkgUp";
|
|
17
|
-
export * from "./applyOptionsChain";
|
|
18
|
-
export * from "./getBrowserslist";
|
|
19
|
-
export * from "./removeSlash";
|
|
20
|
-
export * from "./getEntryOptions";
|
|
21
|
-
export * from "./getPort";
|
|
22
|
-
export * from "./monorepo";
|
|
23
|
-
export * from "./getPackageManager";
|
|
24
|
-
export * from "./runtimeExports";
|
|
25
|
-
export * from "./readTsConfig";
|
|
26
|
-
export * from "./path";
|
|
27
|
-
export * from "./generateMetaTags";
|
|
28
|
-
export * from "./prettyInstructions";
|
|
29
|
-
export * from "./alias";
|
|
30
|
-
export * from "./import";
|
|
31
|
-
export * from "./watch";
|
|
32
|
-
export * from "./nodeEnv";
|
|
33
|
-
export * from "./wait";
|
|
34
|
-
export * from "./emptyDir";
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { isDev } from "./node-env";
|
|
4
|
-
/**
|
|
5
|
-
* Check if the package name is in dependencies or devDependencies.
|
|
6
|
-
*
|
|
7
|
-
* @param appDirectory - Project root directory.
|
|
8
|
-
* @param name - Package name.
|
|
9
|
-
* @returns True if the name is in dependencies or devDependencies, false otherwise.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
export const isDepExists = (appDirectory, name) => {
|
|
13
|
-
const json = require(path.resolve(appDirectory, './package.json'));
|
|
14
|
-
|
|
15
|
-
const {
|
|
16
|
-
dependencies = {},
|
|
17
|
-
devDependencies = {}
|
|
18
|
-
} = json;
|
|
19
|
-
return dependencies.hasOwnProperty(name) || devDependencies.hasOwnProperty(name);
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Is typescript project.
|
|
23
|
-
*
|
|
24
|
-
* @param root - App directory.
|
|
25
|
-
* @returns Whether to use typescript.
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
export const isTypescript = root => fs.existsSync(path.resolve(root, './tsconfig.json'));
|
|
29
|
-
/**
|
|
30
|
-
* Is Empty object
|
|
31
|
-
*
|
|
32
|
-
* @param o - Any object.
|
|
33
|
-
* @returns Whether it is empty object.
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
export const isEmpty = o => Object.entries(o).length === 0 && o.constructor === Object;
|
|
37
|
-
/**
|
|
38
|
-
* Is SSR project
|
|
39
|
-
*
|
|
40
|
-
* @param config - User config.
|
|
41
|
-
* @returns Whether to use server side render.
|
|
42
|
-
*/
|
|
43
|
-
|
|
44
|
-
export const isSSR = config => {
|
|
45
|
-
const {
|
|
46
|
-
server
|
|
47
|
-
} = config;
|
|
48
|
-
|
|
49
|
-
if (server !== null && server !== void 0 && server.ssr) {
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (server !== null && server !== void 0 && server.ssrByEntries && !isEmpty(server.ssrByEntries)) {
|
|
54
|
-
for (const name of Object.keys(server.ssrByEntries)) {
|
|
55
|
-
if (server.ssrByEntries[name]) {
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return false;
|
|
62
|
-
};
|
|
63
|
-
export const isUseSSRBundle = config => {
|
|
64
|
-
const {
|
|
65
|
-
output
|
|
66
|
-
} = config;
|
|
67
|
-
|
|
68
|
-
if (output !== null && output !== void 0 && output.ssg) {
|
|
69
|
-
return true;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return isSSR(config);
|
|
73
|
-
};
|
|
74
|
-
export const isFastRefresh = () => isDev() && process.env.FAST_REFRESH !== 'false';
|
|
75
|
-
export * from "./node-env";
|
|
76
|
-
export * from "./platform";
|
|
77
|
-
export * from "./type";
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export const isDev = () => process.env.NODE_ENV === 'development';
|
|
2
|
-
export const isProd = () => process.env.NODE_ENV === 'production';
|
|
3
|
-
export const isTest = () => process.env.NODE_ENV === 'test'; // Variable used for enabling profiling in Production.
|
|
4
|
-
|
|
5
|
-
export const isProdProfile = () => isProd() && process.argv.includes('--profile');
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export function isString(str) {
|
|
2
|
-
return typeof str === 'string';
|
|
3
|
-
}
|
|
4
|
-
export function isUndefined(obj) {
|
|
5
|
-
return typeof obj === 'undefined';
|
|
6
|
-
}
|
|
7
|
-
export function isArray(obj) {
|
|
8
|
-
return Array.isArray(obj);
|
|
9
|
-
} // eslint-disable-next-line @typescript-eslint/ban-types
|
|
10
|
-
|
|
11
|
-
export function isFunction(func) {
|
|
12
|
-
return typeof func === 'function';
|
|
13
|
-
}
|
|
14
|
-
export function isObject(obj) {
|
|
15
|
-
return obj !== null && typeof obj === 'object';
|
|
16
|
-
}
|
|
17
|
-
export function isPlainObject(obj) {
|
|
18
|
-
return isObject(obj) && Object.prototype.toString.call(obj) === '[object Object]';
|
|
19
|
-
}
|
|
20
|
-
export function isPromise(obj) {
|
|
21
|
-
return Boolean(obj) && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
|
|
22
|
-
}
|
|
23
|
-
export function isRegExp(obj) {
|
|
24
|
-
return Object.prototype.toString.call(obj) === '[object RegExp]';
|
|
25
|
-
}
|
package/dist/js/modern/logger.js
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
-
|
|
3
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
-
|
|
5
|
-
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; }
|
|
6
|
-
|
|
7
|
-
import chalk from 'chalk';
|
|
8
|
-
const {
|
|
9
|
-
grey,
|
|
10
|
-
underline
|
|
11
|
-
} = chalk;
|
|
12
|
-
const LOG_TYPES = {
|
|
13
|
-
error: {
|
|
14
|
-
color: 'red',
|
|
15
|
-
label: 'error',
|
|
16
|
-
level: 'error'
|
|
17
|
-
},
|
|
18
|
-
info: {
|
|
19
|
-
color: 'blue',
|
|
20
|
-
label: 'info',
|
|
21
|
-
level: 'info'
|
|
22
|
-
},
|
|
23
|
-
warn: {
|
|
24
|
-
color: 'yellow',
|
|
25
|
-
label: 'warning',
|
|
26
|
-
level: 'warn'
|
|
27
|
-
},
|
|
28
|
-
debug: {
|
|
29
|
-
color: 'red',
|
|
30
|
-
label: 'debug',
|
|
31
|
-
level: 'debug'
|
|
32
|
-
},
|
|
33
|
-
log: {
|
|
34
|
-
level: 'info'
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
const DEFAULT_CONFIG = {
|
|
38
|
-
displayLabel: true,
|
|
39
|
-
underlineLabel: true,
|
|
40
|
-
uppercaseLabel: false
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
class Logger {
|
|
44
|
-
constructor(options = {}) {
|
|
45
|
-
this.logCount = 200;
|
|
46
|
-
this.history = {};
|
|
47
|
-
this.config = void 0;
|
|
48
|
-
this.types = void 0;
|
|
49
|
-
this.longestLabel = void 0;
|
|
50
|
-
this.config = _objectSpread(_objectSpread({}, DEFAULT_CONFIG), options.config || {});
|
|
51
|
-
this.types = _objectSpread(_objectSpread({}, LOG_TYPES), options.types || {});
|
|
52
|
-
this.longestLabel = this.getLongestLabel();
|
|
53
|
-
Object.keys(this.types).forEach(type => {
|
|
54
|
-
this[type] = this._log.bind(this, type);
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
retainLog(type, message) {
|
|
59
|
-
if (!this.history[type]) {
|
|
60
|
-
this.history[type] = [];
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
this.history[type].push(message);
|
|
64
|
-
|
|
65
|
-
while (this.history[type].length > this.logCount) {
|
|
66
|
-
this.history[type].shift();
|
|
67
|
-
}
|
|
68
|
-
} // eslint-disable-next-line max-statements
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
_log(type, message) {
|
|
72
|
-
if (message === undefined) {
|
|
73
|
-
// eslint-disable-next-line no-console
|
|
74
|
-
console.log();
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
let label = '';
|
|
79
|
-
let text = '';
|
|
80
|
-
const logType = this.types[type];
|
|
81
|
-
|
|
82
|
-
if (this.config.displayLabel && logType.label) {
|
|
83
|
-
label = this.config.uppercaseLabel ? logType.label.toUpperCase() : logType.label;
|
|
84
|
-
|
|
85
|
-
if (this.config.underlineLabel) {
|
|
86
|
-
label = underline(label).padEnd(this.longestUnderlinedLabel.length + 1);
|
|
87
|
-
} else {
|
|
88
|
-
label = label.padEnd(this.longestLabel.length + 1);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
label = logType.color ? chalk[logType.color](label) : label;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (message instanceof Error) {
|
|
95
|
-
if (message.stack) {
|
|
96
|
-
const [name, ...rest] = message.stack.split('\n');
|
|
97
|
-
text = `${name}\n${grey(rest.join('\n'))}`;
|
|
98
|
-
} else {
|
|
99
|
-
text = message.message;
|
|
100
|
-
}
|
|
101
|
-
} else {
|
|
102
|
-
text = `${message}`;
|
|
103
|
-
} // only retain logs of warn/error level
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
if (logType.level === 'warn' || logType.level === 'error') {
|
|
107
|
-
// retain log text without label
|
|
108
|
-
this.retainLog(type, text);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const log = label.length > 0 ? `${label} ${text}` : text; // eslint-disable-next-line no-console
|
|
112
|
-
|
|
113
|
-
console.log(log);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
getLongestLabel() {
|
|
117
|
-
let longestLabel = '';
|
|
118
|
-
Object.keys(this.types).forEach(type => {
|
|
119
|
-
const {
|
|
120
|
-
label = ''
|
|
121
|
-
} = this.types[type];
|
|
122
|
-
|
|
123
|
-
if (label.length > longestLabel.length) {
|
|
124
|
-
longestLabel = label;
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
return longestLabel;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
get longestUnderlinedLabel() {
|
|
131
|
-
return underline(this.longestLabel);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
getRetainedLogs(type) {
|
|
135
|
-
return this.history[type] || [];
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
clearRetainedLogs(type) {
|
|
139
|
-
if (type) {
|
|
140
|
-
if (this.history[type]) {
|
|
141
|
-
this.history[type] = [];
|
|
142
|
-
}
|
|
143
|
-
} else {
|
|
144
|
-
this.history = {};
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const logger = new Logger();
|
|
151
|
-
logger.Logger = Logger;
|
|
152
|
-
export { logger };
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
-
|
|
3
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
-
|
|
5
|
-
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; }
|
|
6
|
-
|
|
7
|
-
import fs from 'fs';
|
|
8
|
-
import path from 'path';
|
|
9
|
-
import glob from 'glob';
|
|
10
|
-
import yaml from 'yaml';
|
|
11
|
-
const PACKAGE_MAX_DEPTH = 5;
|
|
12
|
-
const WOKRSPACES_FILES = {
|
|
13
|
-
YARN: 'package.json',
|
|
14
|
-
PNPM: 'pnpm-workspaces.yaml',
|
|
15
|
-
LERNA: 'lerna.json'
|
|
16
|
-
};
|
|
17
|
-
export const isLerna = root => fs.existsSync(path.join(root, WOKRSPACES_FILES.LERNA));
|
|
18
|
-
export const isYarnWorkspaces = root => {
|
|
19
|
-
var _json$workspaces;
|
|
20
|
-
|
|
21
|
-
const pkg = path.join(root, WOKRSPACES_FILES.YARN);
|
|
22
|
-
|
|
23
|
-
if (!fs.existsSync(pkg)) {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const json = JSON.parse(fs.readFileSync(pkg, 'utf8'));
|
|
28
|
-
return Boolean((_json$workspaces = json.workspaces) === null || _json$workspaces === void 0 ? void 0 : _json$workspaces.packages);
|
|
29
|
-
};
|
|
30
|
-
export const isPnpmWorkspaces = root => fs.existsSync(path.join(root, WOKRSPACES_FILES.PNPM));
|
|
31
|
-
export const isMonorepo = root => isLerna(root) || isYarnWorkspaces(root) || isPnpmWorkspaces(root);
|
|
32
|
-
export const isModernjsMonorepo = root => {
|
|
33
|
-
const json = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'));
|
|
34
|
-
|
|
35
|
-
const deps = _objectSpread(_objectSpread({}, json.dependencies || {}), json.devDependencies || {});
|
|
36
|
-
|
|
37
|
-
return Boolean(deps['@modern-js/monorepo-tools']);
|
|
38
|
-
};
|
|
39
|
-
export const findMonorepoRoot = (appDirectory, maxDepth = PACKAGE_MAX_DEPTH) => {
|
|
40
|
-
let inMonorepo = false;
|
|
41
|
-
|
|
42
|
-
for (let depth = 0; depth < maxDepth; depth++) {
|
|
43
|
-
if (isMonorepo(appDirectory)) {
|
|
44
|
-
inMonorepo = true;
|
|
45
|
-
break;
|
|
46
|
-
} // eslint-disable-next-line no-param-reassign
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
appDirectory = path.dirname(appDirectory);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return inMonorepo ? appDirectory : undefined;
|
|
53
|
-
};
|
|
54
|
-
export const getMonorepoPackages = root => {
|
|
55
|
-
let packages = [];
|
|
56
|
-
|
|
57
|
-
if (isYarnWorkspaces(root)) {
|
|
58
|
-
const json = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'));
|
|
59
|
-
({
|
|
60
|
-
packages
|
|
61
|
-
} = json.workspaces);
|
|
62
|
-
} else if (isLerna(root)) {
|
|
63
|
-
const json = JSON.parse(fs.readFileSync(path.resolve(root, 'lerna.json'), 'utf8'));
|
|
64
|
-
({
|
|
65
|
-
packages
|
|
66
|
-
} = json);
|
|
67
|
-
} else {
|
|
68
|
-
({
|
|
69
|
-
packages
|
|
70
|
-
} = yaml.parse(fs.readFileSync(path.join(root, WOKRSPACES_FILES.PNPM), 'utf8')));
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (packages) {
|
|
74
|
-
return packages.map(name => // The trailing / ensures only dirs are picked up
|
|
75
|
-
glob.sync(path.join(root, `${name}/`), {
|
|
76
|
-
ignore: ['**/node_modules/**']
|
|
77
|
-
})).flat().filter(filepath => fs.existsSync(path.resolve(filepath, 'package.json'))).map(filepath => ({
|
|
78
|
-
path: filepath,
|
|
79
|
-
name: JSON.parse(fs.readFileSync(path.resolve(filepath, 'package.json'), 'utf8')).name
|
|
80
|
-
}));
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return [];
|
|
84
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import execa from 'execa';
|
|
2
|
-
export async function canUseNpm() {
|
|
3
|
-
try {
|
|
4
|
-
await execa('npm', ['--version'], {
|
|
5
|
-
env: process.env
|
|
6
|
-
});
|
|
7
|
-
return true;
|
|
8
|
-
} catch (e) {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
export async function canUseYarn() {
|
|
13
|
-
try {
|
|
14
|
-
await execa('yarn', ['--version'], {
|
|
15
|
-
env: process.env
|
|
16
|
-
});
|
|
17
|
-
return true;
|
|
18
|
-
} catch (e) {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
export async function canUsePnpm() {
|
|
23
|
-
try {
|
|
24
|
-
await execa('pnpm', ['--version'], {
|
|
25
|
-
env: process.env
|
|
26
|
-
});
|
|
27
|
-
return true;
|
|
28
|
-
} catch (e) {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
}
|
package/dist/js/modern/path.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import upath from 'upath';
|
|
3
|
-
export const isRelativePath = test => /^\.\.?($|[\\/])/.test(test);
|
|
4
|
-
export const normalizeOutputPath = s => s.replace(/\\/g, '\\\\');
|
|
5
|
-
export const normalizeToPosixPath = p => upath.normalizeSafe(path.normalize(p));
|
package/dist/js/modern/pkgUp.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import os from 'os';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import { isDev } from "./is"; // TODO: type
|
|
4
|
-
|
|
5
|
-
// TODO: remove hard code 'main'
|
|
6
|
-
export const isSingleEntry = entrypoints => entrypoints.length === 1 && entrypoints[0].entryName === 'main';
|
|
7
|
-
|
|
8
|
-
const normalizeUrl = url => url.replace(/([^:]\/)\/+/g, '$1');
|
|
9
|
-
|
|
10
|
-
const getAddressUrls = (protocol = 'http', port) => {
|
|
11
|
-
const interfaces = os.networkInterfaces();
|
|
12
|
-
const ipv4Interfaces = [];
|
|
13
|
-
Object.keys(interfaces).forEach(key => {
|
|
14
|
-
interfaces[key].forEach(detail => {
|
|
15
|
-
if (detail.family === 'IPv4') {
|
|
16
|
-
ipv4Interfaces.push(detail);
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
return ipv4Interfaces.reduce((memo, detail) => {
|
|
21
|
-
let type = 'Network: ';
|
|
22
|
-
let url = `${protocol}://${detail.address}:${port}`;
|
|
23
|
-
|
|
24
|
-
if (detail.address.includes(`localhost`)) {
|
|
25
|
-
type = 'Local: ';
|
|
26
|
-
url = `${protocol}://localhost:${port}`;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
memo.push({
|
|
30
|
-
type,
|
|
31
|
-
url
|
|
32
|
-
});
|
|
33
|
-
return memo;
|
|
34
|
-
}, []);
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export const prettyInstructions = (appContext, config) => {
|
|
38
|
-
const {
|
|
39
|
-
entrypoints,
|
|
40
|
-
serverRoutes,
|
|
41
|
-
port,
|
|
42
|
-
existSrc,
|
|
43
|
-
checkedEntries
|
|
44
|
-
} = appContext;
|
|
45
|
-
const urls = getAddressUrls(config.dev.https && isDev() ? 'https' : 'http', port);
|
|
46
|
-
const routes = existSrc ? serverRoutes.filter(route => route.entryName) : serverRoutes;
|
|
47
|
-
let message = 'App running at:\n\n';
|
|
48
|
-
|
|
49
|
-
if (isSingleEntry(entrypoints) || !existSrc) {
|
|
50
|
-
message += urls.map(({
|
|
51
|
-
type,
|
|
52
|
-
url
|
|
53
|
-
}) => ` ${chalk.bold(`> ${type.padEnd(10)}`)}${chalk.cyanBright(normalizeUrl(`${url}/${routes[0].urlPath}`))}\n`).join('');
|
|
54
|
-
} else {
|
|
55
|
-
const maxNameLength = Math.max(...routes.map(r => r.entryName.length));
|
|
56
|
-
urls.forEach(({
|
|
57
|
-
type,
|
|
58
|
-
url
|
|
59
|
-
}) => {
|
|
60
|
-
message += ` ${chalk.bold(`> ${type}`)}\n`;
|
|
61
|
-
routes.forEach(({
|
|
62
|
-
entryName,
|
|
63
|
-
urlPath,
|
|
64
|
-
isSSR
|
|
65
|
-
}) => {
|
|
66
|
-
if (!checkedEntries.includes(entryName)) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
message += ` ${chalk.yellowBright(isSSR ? 'λ' : '○')} ${chalk.yellowBright(entryName.padEnd(maxNameLength + 8))}${chalk.cyanBright(normalizeUrl(`${url}/${urlPath}`))}\n`;
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
message += '\n';
|
|
74
|
-
message += chalk.cyanBright(' λ (Server) server-side renders at runtime\n');
|
|
75
|
-
message += chalk.cyanBright(' ○ (Static) client-side rendered as static HTML\n');
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return message;
|
|
79
|
-
};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/* eslint-disable eslint-comments/no-unlimited-disable */
|
|
2
|
-
|
|
3
|
-
/* eslint-disable */
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Copyright (c) 2015-present, Facebook, Inc.
|
|
7
|
-
*
|
|
8
|
-
* This source code is licensed under the MIT license found in the
|
|
9
|
-
* LICENSE file at
|
|
10
|
-
* https://github.com/facebook/create-react-app/blob/master/LICENSE
|
|
11
|
-
*/
|
|
12
|
-
// Modified by Chao Xu (xuchaobei)
|
|
13
|
-
import chalk from 'chalk';
|
|
14
|
-
import { logger } from "./logger";
|
|
15
|
-
export function printBuildError(err) {
|
|
16
|
-
const message = err != null && err.message;
|
|
17
|
-
const stack = err != null && err.stack; // Add more helpful message for Terser error
|
|
18
|
-
|
|
19
|
-
if (stack && typeof message === 'string' && message.indexOf('from Terser') !== -1) {
|
|
20
|
-
try {
|
|
21
|
-
const matched = /(.+)\[(.+):(.+),(.+)\]\[.+\]/.exec(stack);
|
|
22
|
-
|
|
23
|
-
if (!matched) {
|
|
24
|
-
throw new Error('Using errors for control flow is bad.');
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const problemPath = matched[2];
|
|
28
|
-
const line = matched[3];
|
|
29
|
-
const column = matched[4];
|
|
30
|
-
logger.error(`Failed to minify the code from this file: \n\n ${chalk.yellow(`\t${problemPath}:${line}${column !== '0' ? ':' + column : ''}`)}\n`);
|
|
31
|
-
} catch (ignored) {
|
|
32
|
-
logger.error(`Failed to minify the bundle. ${err}\n`);
|
|
33
|
-
}
|
|
34
|
-
} else {
|
|
35
|
-
logger.error((message || err) + '\n');
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
logger.log();
|
|
39
|
-
}
|
|
40
|
-
/* eslint-enable */
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
export const readTsConfig = root => {
|
|
3
|
-
// import typescript from 'typescript' cause eslint fromat error.
|
|
4
|
-
const typescript = require('typescript');
|
|
5
|
-
|
|
6
|
-
return typescript.readConfigFile(path.resolve(root, './tsconfig.json'), typescript.sys.readFile).config;
|
|
7
|
-
};
|
|
8
|
-
export const readTsConfigByFile = filename => {
|
|
9
|
-
// import typescript from 'typescript' cause eslint fromat error.
|
|
10
|
-
const typescript = require('typescript');
|
|
11
|
-
|
|
12
|
-
return typescript.readConfigFile(path.resolve(filename), typescript.sys.readFile).config;
|
|
13
|
-
};
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import fs from 'fs-extra';
|
|
3
|
-
import { normalizeOutputPath } from "./path";
|
|
4
|
-
|
|
5
|
-
const memo = fn => {
|
|
6
|
-
const cache = new Map();
|
|
7
|
-
return (...params) => {
|
|
8
|
-
const stringifiedParams = JSON.stringify(params);
|
|
9
|
-
const cachedResult = cache.get(stringifiedParams);
|
|
10
|
-
|
|
11
|
-
if (cachedResult) {
|
|
12
|
-
return cachedResult;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const res = fn(...params);
|
|
16
|
-
cache.set(stringifiedParams, res);
|
|
17
|
-
return res;
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export const createRuntimeExportsUtils = memo((pwd = '', namespace, ts = false) => {
|
|
22
|
-
const entryExportFile = path.join(pwd, `.runtime-exports/${namespace ? `${namespace}.js` : 'index.js'}`);
|
|
23
|
-
const entryExportTsFile = path.join(pwd, `.runtime-exports/${namespace ? `${namespace}.d.ts` : 'index.d.ts'}`); // const ensure = () => {
|
|
24
|
-
// if (!fs.existsSync(entryExportFile)) {
|
|
25
|
-
// fs.outputFileSync(entryExportFile, '');
|
|
26
|
-
// }
|
|
27
|
-
// fs.ensureFileSync(entryExportFile);
|
|
28
|
-
// };
|
|
29
|
-
|
|
30
|
-
const addExport = statement => {
|
|
31
|
-
// eslint-disable-next-line no-param-reassign
|
|
32
|
-
statement = normalizeOutputPath(statement);
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
fs.ensureFileSync(entryExportFile);
|
|
36
|
-
fs.ensureFileSync(entryExportTsFile);
|
|
37
|
-
|
|
38
|
-
if (!fs.readFileSync(entryExportFile, 'utf8').includes(statement)) {
|
|
39
|
-
fs.appendFileSync(entryExportFile, `${statement}\n`);
|
|
40
|
-
ts && fs.appendFileSync(entryExportTsFile, `${statement.replace('.js', '.d')}\n`);
|
|
41
|
-
}
|
|
42
|
-
} catch (_unused) {// FIXME:
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const getPath = () => entryExportFile;
|
|
47
|
-
|
|
48
|
-
return {
|
|
49
|
-
addExport,
|
|
50
|
-
getPath
|
|
51
|
-
};
|
|
52
|
-
});
|