@modern-js/utils 1.3.6 → 1.3.8-canary.0
Sign up to get free protection for your applications and to get access to all the features.
- package/.eslintrc.js +9 -0
- package/CHANGELOG.md +6 -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/FileSizeReporter.d.ts +16 -0
- package/dist/FileSizeReporter.js +151 -0
- package/dist/alias.d.ts +21 -0
- package/dist/alias.js +62 -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/compatRequire.d.ts +8 -0
- 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/{js/modern/ensureAbsolutePath.js → ensureAbsolutePath.d.ts} +1 -3
- package/dist/ensureAbsolutePath.js +15 -0
- package/dist/findExists.d.ts +6 -0
- package/dist/findExists.js +21 -0
- package/dist/format.d.ts +16 -0
- package/dist/format.js +113 -0
- package/dist/generateMetaTags.d.ts +16 -0
- package/dist/generateMetaTags.js +48 -0
- package/dist/getBrowserslist.d.ts +2 -0
- package/dist/getBrowserslist.js +7 -0
- package/dist/getCacheIdentifier.d.ts +7 -0
- package/dist/getCacheIdentifier.js +24 -0
- package/dist/getEntryOptions.d.ts +1 -0
- package/dist/getEntryOptions.js +26 -0
- package/dist/getPackageManager.d.ts +1 -0
- package/dist/getPackageManager.js +47 -0
- package/dist/getPort.d.ts +7 -0
- package/dist/getPort.js +62 -0
- package/dist/getServerConfig.d.ts +1 -0
- package/dist/getServerConfig.js +39 -0
- package/dist/import.d.ts +5 -0
- package/dist/import.js +10 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +45 -0
- package/dist/is/index.d.ts +34 -0
- package/dist/is/index.js +82 -0
- package/dist/is/node-env.d.ts +4 -0
- 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/is/type.d.ts +8 -0
- package/dist/is/type.js +38 -0
- package/dist/js/modern/monorepo.js +4 -5
- package/dist/js/node/monorepo.js +5 -7
- package/dist/js/treeshaking/monorepo.js +7 -6
- package/dist/logger.d.ts +63 -0
- package/dist/logger.js +128 -0
- package/dist/monorepo.d.ts +11 -0
- package/dist/monorepo.js +80 -0
- package/dist/nodeEnv.d.ts +3 -0
- package/dist/nodeEnv.js +49 -0
- package/dist/path.d.ts +3 -0
- package/dist/path.js +14 -0
- package/dist/{types/pkgUp.d.ts → pkgUp.d.ts} +1 -1
- package/dist/pkgUp.js +8 -0
- package/dist/prettyInstructions.d.ts +6 -0
- package/dist/prettyInstructions.js +64 -0
- package/dist/printBuildError.d.ts +8 -0
- package/dist/printBuildError.js +43 -0
- package/dist/readTsConfig.d.ts +2 -0
- package/dist/readTsConfig.js +19 -0
- package/dist/removeSlash.d.ts +3 -0
- package/dist/removeSlash.js +9 -0
- package/dist/runtimeExports.d.ts +4 -0
- 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/FileSizeReporter.d.ts +5 -5
- package/dist/types/alias.d.ts +12 -14
- package/dist/types/applyOptionsChain.d.ts +5 -5
- package/dist/types/clearConsole.d.ts +1 -1
- package/dist/types/compatRequire.d.ts +1 -1
- package/dist/types/compiled.d.ts +17 -0
- package/dist/types/constants.d.ts +165 -162
- package/dist/types/debug.d.ts +1 -3
- package/dist/types/emptyDir.d.ts +1 -1
- package/dist/types/ensureAbsolutePath.d.ts +1 -1
- package/dist/types/findExists.d.ts +1 -1
- package/dist/types/format.d.ts +5 -5
- package/dist/types/generateMetaTags.d.ts +3 -3
- package/dist/types/getBrowserslist.d.ts +1 -1
- package/dist/types/getCacheIdentifier.d.ts +3 -3
- package/dist/types/getEntryOptions.d.ts +1 -1
- package/dist/types/getPackageManager.d.ts +1 -1
- package/dist/types/getPort.d.ts +1 -1
- package/dist/types/getServerConfig.d.ts +1 -0
- package/dist/types/import.d.ts +2 -2
- package/dist/types/index.d.ts +3 -4
- package/dist/types/is/index.d.ts +1 -4
- package/dist/types/is/node-env.d.ts +1 -1
- package/dist/types/is/platform.d.ts +1 -1
- package/dist/types/is/type.d.ts +1 -1
- package/dist/types/logger.d.ts +49 -49
- package/dist/types/monorepo.d.ts +3 -3
- package/dist/types/nodeEnv.d.ts +1 -1
- package/dist/types/path.d.ts +1 -1
- package/dist/types/prettyInstructions.d.ts +2 -2
- package/dist/types/printBuildError.d.ts +1 -1
- package/dist/types/readTsConfig.d.ts +1 -1
- package/dist/types/removeSlash.d.ts +1 -1
- package/dist/types/runtimeExports.d.ts +3 -3
- package/dist/types/wait.d.ts +1 -1
- package/dist/types/watch.d.ts +4 -4
- package/dist/wait.d.ts +2 -0
- package/dist/wait.js +7 -0
- package/dist/watch.d.ts +8 -0
- package/dist/watch.js +64 -0
- package/jest.config.js +0 -1
- package/package.json +57 -40
- package/tests/debug.test.ts +2 -2
- package/tests/is.test.ts +27 -0
- package/tests/isPlatform.test.ts +19 -0
- package/tests/prettyInstructions.test.ts +1 -1
- 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/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 -27
- package/dist/js/modern/logger.js +0 -152
- 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 -48
- package/dist/js/node/logger.js +0 -162
- 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 -29
- package/dist/js/treeshaking/logger.js +0 -188
- 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/chalk.d.ts +0 -2
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
|
-
});
|
package/dist/js/modern/wait.js
DELETED
package/dist/js/modern/watch.js
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
import * as path from 'path';
|
2
|
-
import { Import } from "./import";
|
3
|
-
const chokidar = Import.lazy('chokidar', require);
|
4
|
-
export const WatchChangeType = {
|
5
|
-
ADD: 'add',
|
6
|
-
UNLINK: 'unlink',
|
7
|
-
CHANGE: 'change'
|
8
|
-
};
|
9
|
-
export const watch = (watchDir, runTask, ignored = []) => {
|
10
|
-
let ready = false;
|
11
|
-
const watcher = chokidar.watch(watchDir, {
|
12
|
-
ignored
|
13
|
-
});
|
14
|
-
watcher.on('ready', () => ready = true);
|
15
|
-
watcher.on('change', async filePath => {
|
16
|
-
const changedFilePath = path.resolve(filePath);
|
17
|
-
await runTask({
|
18
|
-
changedFilePath,
|
19
|
-
changeType: WatchChangeType.CHANGE
|
20
|
-
});
|
21
|
-
});
|
22
|
-
watcher.on('add', async filePath => {
|
23
|
-
const changedFilePath = path.resolve(filePath);
|
24
|
-
|
25
|
-
if (ready) {
|
26
|
-
await runTask({
|
27
|
-
changedFilePath,
|
28
|
-
changeType: WatchChangeType.ADD
|
29
|
-
});
|
30
|
-
}
|
31
|
-
});
|
32
|
-
watcher.on('unlink', async filePath => {
|
33
|
-
const changedFilePath = path.resolve(filePath);
|
34
|
-
await runTask({
|
35
|
-
changedFilePath,
|
36
|
-
changeType: WatchChangeType.UNLINK
|
37
|
-
});
|
38
|
-
});
|
39
|
-
watcher.on('error', err => {
|
40
|
-
throw err;
|
41
|
-
});
|
42
|
-
return watcher;
|
43
|
-
};
|
@@ -1,175 +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
|
-
'use strict';
|
14
|
-
|
15
|
-
Object.defineProperty(exports, "__esModule", {
|
16
|
-
value: true
|
17
|
-
});
|
18
|
-
exports.measureFileSizesBeforeBuild = measureFileSizesBeforeBuild;
|
19
|
-
exports.printFileSizesAfterBuild = printFileSizesAfterBuild;
|
20
|
-
|
21
|
-
var _fs = _interopRequireDefault(require("fs"));
|
22
|
-
|
23
|
-
var _path = _interopRequireDefault(require("path"));
|
24
|
-
|
25
|
-
var _chalk = _interopRequireDefault(require("chalk"));
|
26
|
-
|
27
|
-
var _filesize = _interopRequireDefault(require("filesize"));
|
28
|
-
|
29
|
-
var _recursiveReaddir = _interopRequireDefault(require("recursive-readdir"));
|
30
|
-
|
31
|
-
var _stripAnsi = _interopRequireDefault(require("strip-ansi"));
|
32
|
-
|
33
|
-
var _gzipSize = _interopRequireDefault(require("gzip-size"));
|
34
|
-
|
35
|
-
var _logger = require("./logger");
|
36
|
-
|
37
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
38
|
-
|
39
|
-
function canReadAsset(asset) {
|
40
|
-
return /\.(js|css)$/.test(asset) && !/service-worker\.js/.test(asset) && !/precache-manifest\.[0-9a-f]+\.js/.test(asset);
|
41
|
-
} // Prints a detailed summary of build files.
|
42
|
-
|
43
|
-
|
44
|
-
function printFileSizesAfterBuild(webpackStats, previousSizeMap, buildFolder, maxBundleGzipSize, maxChunkGzipSize) {
|
45
|
-
var root = previousSizeMap.root;
|
46
|
-
var sizes = previousSizeMap.sizes;
|
47
|
-
var assets = (webpackStats.stats || [webpackStats]).map(stats => stats.toJson({
|
48
|
-
all: false,
|
49
|
-
assets: true
|
50
|
-
}).assets.filter(asset => canReadAsset(asset.name)).map(asset => {
|
51
|
-
var fileContents = _fs.default.readFileSync(_path.default.join(root, asset.name));
|
52
|
-
|
53
|
-
var size = fileContents.length;
|
54
|
-
|
55
|
-
var gzippedSize = _gzipSize.default.sync(fileContents);
|
56
|
-
|
57
|
-
var [previousSize, previousGzipSize] = sizes[removeFileNameHash(root, asset.name)] || [];
|
58
|
-
var sizeDifference = getDifferenceLabel(size, previousSize);
|
59
|
-
var gzipSizeDifference = getDifferenceLabel(gzippedSize, previousGzipSize);
|
60
|
-
return {
|
61
|
-
folder: _path.default.join(_path.default.basename(buildFolder), _path.default.dirname(asset.name)),
|
62
|
-
name: _path.default.basename(asset.name),
|
63
|
-
gzippedSize: gzippedSize,
|
64
|
-
sizeLabel: (0, _filesize.default)(size) + (sizeDifference ? ' (' + sizeDifference + ')' : ''),
|
65
|
-
gzipSizeLabel: (0, _filesize.default)(gzippedSize) + (gzipSizeDifference ? ' (' + gzipSizeDifference + ')' : '')
|
66
|
-
};
|
67
|
-
})).reduce((single, all) => all.concat(single), []);
|
68
|
-
assets.sort((a, b) => b.size - a.size);
|
69
|
-
var longestSizeLabelLength = Math.max.apply(null, assets.map(a => (0, _stripAnsi.default)(a.sizeLabel).length));
|
70
|
-
var longestFileNameLength = Math.max.apply(null, assets.map(a => (0, _stripAnsi.default)(a.folder + _path.default.sep + a.name).length));
|
71
|
-
printFileSizesHeader(longestFileNameLength, longestSizeLabelLength);
|
72
|
-
var suggestBundleSplitting = false;
|
73
|
-
assets.forEach(asset => {
|
74
|
-
var {
|
75
|
-
folder,
|
76
|
-
name,
|
77
|
-
sizeLabel,
|
78
|
-
gzipSizeLabel,
|
79
|
-
gzippedSize
|
80
|
-
} = asset;
|
81
|
-
var fileNameLength = (0, _stripAnsi.default)(folder + _path.default.sep + name).length;
|
82
|
-
var sizeLength = (0, _stripAnsi.default)(sizeLabel).length;
|
83
|
-
|
84
|
-
if (sizeLength < longestSizeLabelLength) {
|
85
|
-
var rightPadding = ' '.repeat(longestSizeLabelLength - sizeLength);
|
86
|
-
sizeLabel += rightPadding;
|
87
|
-
}
|
88
|
-
|
89
|
-
var fileNameLabel = _chalk.default.dim(asset.folder + _path.default.sep) + _chalk.default.cyan(asset.name);
|
90
|
-
|
91
|
-
if (fileNameLength < longestFileNameLength) {
|
92
|
-
var rightPadding = ' '.repeat(longestFileNameLength - fileNameLength);
|
93
|
-
fileNameLabel += rightPadding;
|
94
|
-
}
|
95
|
-
|
96
|
-
var isMainBundle = asset.name.indexOf('main.') === 0;
|
97
|
-
var maxRecommendedSize = isMainBundle ? maxBundleGzipSize : maxChunkGzipSize;
|
98
|
-
var isLarge = maxRecommendedSize && gzippedSize > maxRecommendedSize;
|
99
|
-
|
100
|
-
if (isLarge && _path.default.extname(asset.name) === '.js') {
|
101
|
-
suggestBundleSplitting = true;
|
102
|
-
}
|
103
|
-
|
104
|
-
_logger.logger.log(' ' + fileNameLabel + ' ' + sizeLabel + ' ' + (isLarge ? _chalk.default.yellow(gzipSizeLabel) : gzipSizeLabel));
|
105
|
-
});
|
106
|
-
|
107
|
-
if (suggestBundleSplitting) {
|
108
|
-
_logger.logger.log();
|
109
|
-
|
110
|
-
_logger.logger.warn('The bundle size is significantly larger than recommended.');
|
111
|
-
}
|
112
|
-
}
|
113
|
-
|
114
|
-
function printFileSizesHeader(longestFileNameLength, longestSizeLabelLength) {
|
115
|
-
const longestLengths = [longestFileNameLength, longestSizeLabelLength];
|
116
|
-
const headerRow = ['File', 'Size', 'Gzipped'].reduce((prev, cur, index) => {
|
117
|
-
const length = longestLengths[index];
|
118
|
-
let curLabel = cur;
|
119
|
-
|
120
|
-
if (length) {
|
121
|
-
curLabel = cur.length < length ? cur + ' '.repeat(length - cur.length) : cur;
|
122
|
-
}
|
123
|
-
|
124
|
-
return prev + curLabel + ' ';
|
125
|
-
}, ' ');
|
126
|
-
|
127
|
-
_logger.logger.log(_chalk.default.bold(_chalk.default.blue(headerRow)));
|
128
|
-
}
|
129
|
-
|
130
|
-
function removeFileNameHash(buildFolder, fileName) {
|
131
|
-
return fileName.replace(buildFolder, '').replace(/\\/g, '/').replace(/\/?(.*)(\.[0-9a-f]+)(\.chunk)?(\.js|\.css)/, (match, p1, p2, p3, p4) => p1 + p4);
|
132
|
-
} // Input: 1024, 2048
|
133
|
-
// Output: "(+1 KB)"
|
134
|
-
|
135
|
-
|
136
|
-
function getDifferenceLabel(currentSize, previousSize) {
|
137
|
-
var FIFTY_KILOBYTES = 1024 * 50;
|
138
|
-
var difference = currentSize - previousSize;
|
139
|
-
var fileSize = !Number.isNaN(difference) ? (0, _filesize.default)(difference) : 0;
|
140
|
-
|
141
|
-
if (difference >= FIFTY_KILOBYTES) {
|
142
|
-
return _chalk.default.red('+' + fileSize);
|
143
|
-
} else if (difference < FIFTY_KILOBYTES && difference > 0) {
|
144
|
-
return _chalk.default.yellow('+' + fileSize);
|
145
|
-
} else if (difference < 0) {
|
146
|
-
return _chalk.default.green(fileSize);
|
147
|
-
} else {
|
148
|
-
return '';
|
149
|
-
}
|
150
|
-
}
|
151
|
-
|
152
|
-
function measureFileSizesBeforeBuild(buildFolder) {
|
153
|
-
return new Promise(resolve => {
|
154
|
-
(0, _recursiveReaddir.default)(buildFolder, (err, fileNames) => {
|
155
|
-
var sizes;
|
156
|
-
|
157
|
-
if (!err && fileNames) {
|
158
|
-
sizes = fileNames.filter(canReadAsset).reduce((memo, fileName) => {
|
159
|
-
var contents = _fs.default.readFileSync(fileName);
|
160
|
-
|
161
|
-
var key = removeFileNameHash(buildFolder, fileName); // save both the original size and gzip size
|
162
|
-
|
163
|
-
memo[key] = [contents.length, _gzipSize.default.sync(contents)];
|
164
|
-
return memo;
|
165
|
-
}, {});
|
166
|
-
}
|
167
|
-
|
168
|
-
resolve({
|
169
|
-
root: buildFolder,
|
170
|
-
sizes: sizes || {}
|
171
|
-
});
|
172
|
-
});
|
173
|
-
});
|
174
|
-
}
|
175
|
-
/* eslint-enable */
|
package/dist/js/node/alias.js
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.validAlias = exports.getUserAlias = exports.getAlias = void 0;
|
7
|
-
|
8
|
-
var _fs = _interopRequireDefault(require("fs"));
|
9
|
-
|
10
|
-
var _path = _interopRequireDefault(require("path"));
|
11
|
-
|
12
|
-
var _chalk = _interopRequireDefault(require("chalk"));
|
13
|
-
|
14
|
-
var _readTsConfig = require("./readTsConfig");
|
15
|
-
|
16
|
-
var _applyOptionsChain = require("./applyOptionsChain");
|
17
|
-
|
18
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
19
|
-
|
20
|
-
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; }
|
21
|
-
|
22
|
-
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; }
|
23
|
-
|
24
|
-
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; }
|
25
|
-
|
26
|
-
const validAlias = (modernConfig, {
|
27
|
-
tsconfigPath
|
28
|
-
}) => {
|
29
|
-
const {
|
30
|
-
source: {
|
31
|
-
alias
|
32
|
-
}
|
33
|
-
} = modernConfig;
|
34
|
-
|
35
|
-
if (!alias) {
|
36
|
-
return null;
|
37
|
-
}
|
38
|
-
|
39
|
-
const isTsProject = _fs.default.existsSync(tsconfigPath);
|
40
|
-
|
41
|
-
if (!isTsProject) {
|
42
|
-
return null;
|
43
|
-
}
|
44
|
-
|
45
|
-
const userAlias = getUserAlias(alias);
|
46
|
-
|
47
|
-
if (Object.keys(userAlias).length > 0) {
|
48
|
-
return _chalk.default.red('Note: Please use `compilerOptions.paths` in "tsconfig.json" file replace `source.alias` config in "modern.config.js/ts" when project is typescript');
|
49
|
-
}
|
50
|
-
|
51
|
-
return null;
|
52
|
-
};
|
53
|
-
|
54
|
-
exports.validAlias = validAlias;
|
55
|
-
|
56
|
-
const getAlias = (aliasOption, option) => {
|
57
|
-
const isTsProject = _fs.default.existsSync(option.tsconfigPath);
|
58
|
-
|
59
|
-
let aliasConfig;
|
60
|
-
|
61
|
-
if (!isTsProject) {
|
62
|
-
aliasConfig = {
|
63
|
-
absoluteBaseUrl: option.appDirectory,
|
64
|
-
paths: (0, _applyOptionsChain.applyOptionsChain)({
|
65
|
-
'@': ['./src']
|
66
|
-
}, aliasOption),
|
67
|
-
isTsPath: false,
|
68
|
-
isTsProject
|
69
|
-
};
|
70
|
-
} else {
|
71
|
-
var _tsconfig$compilerOpt, _tsconfig$compilerOpt2;
|
72
|
-
|
73
|
-
const tsconfig = (0, _readTsConfig.readTsConfigByFile)(option.tsconfigPath);
|
74
|
-
const baseUrl = tsconfig === null || tsconfig === void 0 ? void 0 : (_tsconfig$compilerOpt = tsconfig.compilerOptions) === null || _tsconfig$compilerOpt === void 0 ? void 0 : _tsconfig$compilerOpt.baseUrl;
|
75
|
-
aliasConfig = {
|
76
|
-
absoluteBaseUrl: baseUrl ? _path.default.join(option.appDirectory, baseUrl) : option.appDirectory,
|
77
|
-
paths: _objectSpread(_objectSpread({}, aliasOption || {}), tsconfig === null || tsconfig === void 0 ? void 0 : (_tsconfig$compilerOpt2 = tsconfig.compilerOptions) === null || _tsconfig$compilerOpt2 === void 0 ? void 0 : _tsconfig$compilerOpt2.paths),
|
78
|
-
isTsPath: true,
|
79
|
-
isTsProject
|
80
|
-
};
|
81
|
-
}
|
82
|
-
|
83
|
-
return aliasConfig;
|
84
|
-
}; // filter invalid ts paths that are not array
|
85
|
-
|
86
|
-
|
87
|
-
exports.getAlias = getAlias;
|
88
|
-
|
89
|
-
const getUserAlias = (alias = {}) => Object.keys(alias).reduce((o, k) => {
|
90
|
-
if (Array.isArray(alias[k])) {
|
91
|
-
o[k] = alias[k];
|
92
|
-
}
|
93
|
-
|
94
|
-
return o;
|
95
|
-
}, {});
|
96
|
-
|
97
|
-
exports.getUserAlias = getUserAlias;
|
@@ -1,37 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.applyOptionsChain = void 0;
|
7
|
-
|
8
|
-
var _index = require("./index");
|
9
|
-
|
10
|
-
// eslint-disable-next-line import/no-useless-path-segments
|
11
|
-
const applyOptionsChain = (defaults, options, utils, mergeFn = Object.assign) => {
|
12
|
-
if (!options) {
|
13
|
-
return defaults;
|
14
|
-
}
|
15
|
-
|
16
|
-
if ((0, _index.isPlainObject)(options)) {
|
17
|
-
return mergeFn(defaults, options);
|
18
|
-
} else if ((0, _index.isFunction)(options)) {
|
19
|
-
const ret = options(defaults, utils);
|
20
|
-
|
21
|
-
if (ret) {
|
22
|
-
if (!(0, _index.isPlainObject)(ret)) {
|
23
|
-
_index.logger.warn(`${options.name}: Function should mutate the config and return nothing, Or return a cloned or merged version of config object.`);
|
24
|
-
}
|
25
|
-
|
26
|
-
return ret;
|
27
|
-
}
|
28
|
-
} else if (Array.isArray(options)) {
|
29
|
-
return options.reduce((memo, cur) => applyOptionsChain(memo, cur, utils, mergeFn), defaults);
|
30
|
-
} else {
|
31
|
-
throw new Error(`applyOptionsChain error:\ndefault options is: ${JSON.stringify(defaults)}`);
|
32
|
-
}
|
33
|
-
|
34
|
-
return defaults;
|
35
|
-
};
|
36
|
-
|
37
|
-
exports.applyOptionsChain = applyOptionsChain;
|
package/dist/js/node/chalk.js
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
Object.defineProperty(exports, "chalk", {
|
7
|
-
enumerable: true,
|
8
|
-
get: function () {
|
9
|
-
return _chalk.default;
|
10
|
-
}
|
11
|
-
});
|
12
|
-
|
13
|
-
var _chalk = _interopRequireDefault(require("chalk"));
|
14
|
-
|
15
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
@@ -1,14 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.clearConsole = void 0;
|
7
|
-
|
8
|
-
const clearConsole = () => {
|
9
|
-
if (process.stdout.isTTY && !process.env.DEBUG) {
|
10
|
-
process.stdout.write('\x1B[H\x1B[2J');
|
11
|
-
}
|
12
|
-
};
|
13
|
-
|
14
|
-
exports.clearConsole = clearConsole;
|
@@ -1,41 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.requireExistModule = exports.compatRequire = exports.cleanRequireCache = void 0;
|
7
|
-
|
8
|
-
var _findExists = require("./findExists");
|
9
|
-
|
10
|
-
/**
|
11
|
-
* Require function compatible with esm and cjs module.
|
12
|
-
* @param filePath - File to required.
|
13
|
-
* @returns module export object.
|
14
|
-
*/
|
15
|
-
const compatRequire = filePath => {
|
16
|
-
const mod = require(filePath);
|
17
|
-
|
18
|
-
return mod !== null && mod !== void 0 && mod.__esModule ? mod.default : mod;
|
19
|
-
};
|
20
|
-
|
21
|
-
exports.compatRequire = compatRequire;
|
22
|
-
|
23
|
-
const requireExistModule = (filename, extensions = ['.ts', '.js']) => {
|
24
|
-
const exist = (0, _findExists.findExists)(extensions.map(ext => `${filename}${ext}`));
|
25
|
-
|
26
|
-
if (!exist) {
|
27
|
-
return null;
|
28
|
-
}
|
29
|
-
|
30
|
-
return compatRequire(exist);
|
31
|
-
};
|
32
|
-
|
33
|
-
exports.requireExistModule = requireExistModule;
|
34
|
-
|
35
|
-
const cleanRequireCache = filelist => {
|
36
|
-
filelist.forEach(filepath => {
|
37
|
-
delete require.cache[filepath];
|
38
|
-
});
|
39
|
-
};
|
40
|
-
|
41
|
-
exports.cleanRequireCache = cleanRequireCache;
|