@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
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.printBuildError = printBuildError;
|
|
7
|
-
|
|
8
|
-
var _chalk = _interopRequireDefault(require("chalk"));
|
|
9
|
-
|
|
10
|
-
var _logger = require("./logger");
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
/* eslint-disable eslint-comments/no-unlimited-disable */
|
|
15
|
-
|
|
16
|
-
/* eslint-disable */
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Copyright (c) 2015-present, Facebook, Inc.
|
|
20
|
-
*
|
|
21
|
-
* This source code is licensed under the MIT license found in the
|
|
22
|
-
* LICENSE file at
|
|
23
|
-
* https://github.com/facebook/create-react-app/blob/master/LICENSE
|
|
24
|
-
*/
|
|
25
|
-
// Modified by Chao Xu (xuchaobei)
|
|
26
|
-
function printBuildError(err) {
|
|
27
|
-
const message = err != null && err.message;
|
|
28
|
-
const stack = err != null && err.stack; // Add more helpful message for Terser error
|
|
29
|
-
|
|
30
|
-
if (stack && typeof message === 'string' && message.indexOf('from Terser') !== -1) {
|
|
31
|
-
try {
|
|
32
|
-
const matched = /(.+)\[(.+):(.+),(.+)\]\[.+\]/.exec(stack);
|
|
33
|
-
|
|
34
|
-
if (!matched) {
|
|
35
|
-
throw new Error('Using errors for control flow is bad.');
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const problemPath = matched[2];
|
|
39
|
-
const line = matched[3];
|
|
40
|
-
const column = matched[4];
|
|
41
|
-
|
|
42
|
-
_logger.logger.error(`Failed to minify the code from this file: \n\n ${_chalk.default.yellow(`\t${problemPath}:${line}${column !== '0' ? ':' + column : ''}`)}\n`);
|
|
43
|
-
} catch (ignored) {
|
|
44
|
-
_logger.logger.error(`Failed to minify the bundle. ${err}\n`);
|
|
45
|
-
}
|
|
46
|
-
} else {
|
|
47
|
-
_logger.logger.error((message || err) + '\n');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
_logger.logger.log();
|
|
51
|
-
}
|
|
52
|
-
/* eslint-enable */
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.readTsConfigByFile = exports.readTsConfig = void 0;
|
|
7
|
-
|
|
8
|
-
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
const readTsConfig = root => {
|
|
13
|
-
// import typescript from 'typescript' cause eslint fromat error.
|
|
14
|
-
const typescript = require('typescript');
|
|
15
|
-
|
|
16
|
-
return typescript.readConfigFile(_path.default.resolve(root, './tsconfig.json'), typescript.sys.readFile).config;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
exports.readTsConfig = readTsConfig;
|
|
20
|
-
|
|
21
|
-
const readTsConfigByFile = filename => {
|
|
22
|
-
// import typescript from 'typescript' cause eslint fromat error.
|
|
23
|
-
const typescript = require('typescript');
|
|
24
|
-
|
|
25
|
-
return typescript.readConfigFile(_path.default.resolve(filename), typescript.sys.readFile).config;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
exports.readTsConfigByFile = readTsConfigByFile;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.removeTailSlash = exports.removeSlash = exports.removeLeadingSlash = void 0;
|
|
7
|
-
|
|
8
|
-
const removeLeadingSlash = s => s.replace(/^\/+/, '');
|
|
9
|
-
|
|
10
|
-
exports.removeLeadingSlash = removeLeadingSlash;
|
|
11
|
-
|
|
12
|
-
const removeTailSlash = s => s.replace(/\/+$/, '');
|
|
13
|
-
|
|
14
|
-
exports.removeTailSlash = removeTailSlash;
|
|
15
|
-
|
|
16
|
-
const removeSlash = s => removeLeadingSlash(removeTailSlash(s));
|
|
17
|
-
|
|
18
|
-
exports.removeSlash = removeSlash;
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createRuntimeExportsUtils = void 0;
|
|
7
|
-
|
|
8
|
-
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
|
|
10
|
-
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
11
|
-
|
|
12
|
-
var _path2 = require("./path");
|
|
13
|
-
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
|
-
const memo = fn => {
|
|
17
|
-
const cache = new Map();
|
|
18
|
-
return (...params) => {
|
|
19
|
-
const stringifiedParams = JSON.stringify(params);
|
|
20
|
-
const cachedResult = cache.get(stringifiedParams);
|
|
21
|
-
|
|
22
|
-
if (cachedResult) {
|
|
23
|
-
return cachedResult;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const res = fn(...params);
|
|
27
|
-
cache.set(stringifiedParams, res);
|
|
28
|
-
return res;
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const createRuntimeExportsUtils = memo((pwd = '', namespace, ts = false) => {
|
|
33
|
-
const entryExportFile = _path.default.join(pwd, `.runtime-exports/${namespace ? `${namespace}.js` : 'index.js'}`);
|
|
34
|
-
|
|
35
|
-
const entryExportTsFile = _path.default.join(pwd, `.runtime-exports/${namespace ? `${namespace}.d.ts` : 'index.d.ts'}`); // const ensure = () => {
|
|
36
|
-
// if (!fs.existsSync(entryExportFile)) {
|
|
37
|
-
// fs.outputFileSync(entryExportFile, '');
|
|
38
|
-
// }
|
|
39
|
-
// fs.ensureFileSync(entryExportFile);
|
|
40
|
-
// };
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const addExport = statement => {
|
|
44
|
-
// eslint-disable-next-line no-param-reassign
|
|
45
|
-
statement = (0, _path2.normalizeOutputPath)(statement);
|
|
46
|
-
|
|
47
|
-
try {
|
|
48
|
-
_fsExtra.default.ensureFileSync(entryExportFile);
|
|
49
|
-
|
|
50
|
-
_fsExtra.default.ensureFileSync(entryExportTsFile);
|
|
51
|
-
|
|
52
|
-
if (!_fsExtra.default.readFileSync(entryExportFile, 'utf8').includes(statement)) {
|
|
53
|
-
_fsExtra.default.appendFileSync(entryExportFile, `${statement}\n`);
|
|
54
|
-
|
|
55
|
-
ts && _fsExtra.default.appendFileSync(entryExportTsFile, `${statement.replace('.js', '.d')}\n`);
|
|
56
|
-
}
|
|
57
|
-
} catch (_unused) {// FIXME:
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const getPath = () => entryExportFile;
|
|
62
|
-
|
|
63
|
-
return {
|
|
64
|
-
addExport,
|
|
65
|
-
getPath
|
|
66
|
-
};
|
|
67
|
-
});
|
|
68
|
-
exports.createRuntimeExportsUtils = createRuntimeExportsUtils;
|
package/dist/js/node/wait.js
DELETED
package/dist/js/node/watch.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.watch = exports.WatchChangeType = void 0;
|
|
7
|
-
|
|
8
|
-
var path = _interopRequireWildcard(require("path"));
|
|
9
|
-
|
|
10
|
-
var _import = require("./import");
|
|
11
|
-
|
|
12
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
13
|
-
|
|
14
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
15
|
-
|
|
16
|
-
const chokidar = _import.Import.lazy('chokidar', require);
|
|
17
|
-
|
|
18
|
-
const WatchChangeType = {
|
|
19
|
-
ADD: 'add',
|
|
20
|
-
UNLINK: 'unlink',
|
|
21
|
-
CHANGE: 'change'
|
|
22
|
-
};
|
|
23
|
-
exports.WatchChangeType = WatchChangeType;
|
|
24
|
-
|
|
25
|
-
const watch = (watchDir, runTask, ignored = []) => {
|
|
26
|
-
let ready = false;
|
|
27
|
-
const watcher = chokidar.watch(watchDir, {
|
|
28
|
-
ignored
|
|
29
|
-
});
|
|
30
|
-
watcher.on('ready', () => ready = true);
|
|
31
|
-
watcher.on('change', async filePath => {
|
|
32
|
-
const changedFilePath = path.resolve(filePath);
|
|
33
|
-
await runTask({
|
|
34
|
-
changedFilePath,
|
|
35
|
-
changeType: WatchChangeType.CHANGE
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
watcher.on('add', async filePath => {
|
|
39
|
-
const changedFilePath = path.resolve(filePath);
|
|
40
|
-
|
|
41
|
-
if (ready) {
|
|
42
|
-
await runTask({
|
|
43
|
-
changedFilePath,
|
|
44
|
-
changeType: WatchChangeType.ADD
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
watcher.on('unlink', async filePath => {
|
|
49
|
-
const changedFilePath = path.resolve(filePath);
|
|
50
|
-
await runTask({
|
|
51
|
-
changedFilePath,
|
|
52
|
-
changeType: WatchChangeType.UNLINK
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
watcher.on('error', err => {
|
|
56
|
-
throw err;
|
|
57
|
-
});
|
|
58
|
-
return watcher;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
exports.watch = watch;
|
|
@@ -1,185 +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
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
16
|
-
|
|
17
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
18
|
-
|
|
19
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
20
|
-
|
|
21
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
22
|
-
|
|
23
|
-
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
24
|
-
|
|
25
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
26
|
-
|
|
27
|
-
import fs from 'fs';
|
|
28
|
-
import path from 'path';
|
|
29
|
-
import chalk from 'chalk';
|
|
30
|
-
import filesize from 'filesize';
|
|
31
|
-
import recursive from 'recursive-readdir';
|
|
32
|
-
import stripAnsi from 'strip-ansi';
|
|
33
|
-
import gzipSize from 'gzip-size';
|
|
34
|
-
import { logger } from "./logger";
|
|
35
|
-
|
|
36
|
-
function canReadAsset(asset) {
|
|
37
|
-
return /\.(js|css)$/.test(asset) && !/service-worker\.js/.test(asset) && !/precache-manifest\.[0-9a-f]+\.js/.test(asset);
|
|
38
|
-
} // Prints a detailed summary of build files.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
function printFileSizesAfterBuild(webpackStats, previousSizeMap, buildFolder, maxBundleGzipSize, maxChunkGzipSize) {
|
|
42
|
-
var root = previousSizeMap.root;
|
|
43
|
-
var sizes = previousSizeMap.sizes;
|
|
44
|
-
var assets = (webpackStats.stats || [webpackStats]).map(function (stats) {
|
|
45
|
-
return stats.toJson({
|
|
46
|
-
all: false,
|
|
47
|
-
assets: true
|
|
48
|
-
}).assets.filter(function (asset) {
|
|
49
|
-
return canReadAsset(asset.name);
|
|
50
|
-
}).map(function (asset) {
|
|
51
|
-
var fileContents = fs.readFileSync(path.join(root, asset.name));
|
|
52
|
-
var size = fileContents.length;
|
|
53
|
-
var gzippedSize = gzipSize.sync(fileContents);
|
|
54
|
-
|
|
55
|
-
var _ref = sizes[removeFileNameHash(root, asset.name)] || [],
|
|
56
|
-
_ref2 = _slicedToArray(_ref, 2),
|
|
57
|
-
previousSize = _ref2[0],
|
|
58
|
-
previousGzipSize = _ref2[1];
|
|
59
|
-
|
|
60
|
-
var sizeDifference = getDifferenceLabel(size, previousSize);
|
|
61
|
-
var gzipSizeDifference = getDifferenceLabel(gzippedSize, previousGzipSize);
|
|
62
|
-
return {
|
|
63
|
-
folder: path.join(path.basename(buildFolder), path.dirname(asset.name)),
|
|
64
|
-
name: path.basename(asset.name),
|
|
65
|
-
gzippedSize: gzippedSize,
|
|
66
|
-
sizeLabel: filesize(size) + (sizeDifference ? ' (' + sizeDifference + ')' : ''),
|
|
67
|
-
gzipSizeLabel: filesize(gzippedSize) + (gzipSizeDifference ? ' (' + gzipSizeDifference + ')' : '')
|
|
68
|
-
};
|
|
69
|
-
});
|
|
70
|
-
}).reduce(function (single, all) {
|
|
71
|
-
return all.concat(single);
|
|
72
|
-
}, []);
|
|
73
|
-
assets.sort(function (a, b) {
|
|
74
|
-
return b.size - a.size;
|
|
75
|
-
});
|
|
76
|
-
var longestSizeLabelLength = Math.max.apply(null, assets.map(function (a) {
|
|
77
|
-
return stripAnsi(a.sizeLabel).length;
|
|
78
|
-
}));
|
|
79
|
-
var longestFileNameLength = Math.max.apply(null, assets.map(function (a) {
|
|
80
|
-
return stripAnsi(a.folder + path.sep + a.name).length;
|
|
81
|
-
}));
|
|
82
|
-
printFileSizesHeader(longestFileNameLength, longestSizeLabelLength);
|
|
83
|
-
var suggestBundleSplitting = false;
|
|
84
|
-
assets.forEach(function (asset) {
|
|
85
|
-
var folder = asset.folder,
|
|
86
|
-
name = asset.name,
|
|
87
|
-
sizeLabel = asset.sizeLabel,
|
|
88
|
-
gzipSizeLabel = asset.gzipSizeLabel,
|
|
89
|
-
gzippedSize = asset.gzippedSize;
|
|
90
|
-
var fileNameLength = stripAnsi(folder + path.sep + name).length;
|
|
91
|
-
var sizeLength = stripAnsi(sizeLabel).length;
|
|
92
|
-
|
|
93
|
-
if (sizeLength < longestSizeLabelLength) {
|
|
94
|
-
var rightPadding = ' '.repeat(longestSizeLabelLength - sizeLength);
|
|
95
|
-
sizeLabel += rightPadding;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
var fileNameLabel = chalk.dim(asset.folder + path.sep) + chalk.cyan(asset.name);
|
|
99
|
-
|
|
100
|
-
if (fileNameLength < longestFileNameLength) {
|
|
101
|
-
var rightPadding = ' '.repeat(longestFileNameLength - fileNameLength);
|
|
102
|
-
fileNameLabel += rightPadding;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
var isMainBundle = asset.name.indexOf('main.') === 0;
|
|
106
|
-
var maxRecommendedSize = isMainBundle ? maxBundleGzipSize : maxChunkGzipSize;
|
|
107
|
-
var isLarge = maxRecommendedSize && gzippedSize > maxRecommendedSize;
|
|
108
|
-
|
|
109
|
-
if (isLarge && path.extname(asset.name) === '.js') {
|
|
110
|
-
suggestBundleSplitting = true;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
logger.log(' ' + fileNameLabel + ' ' + sizeLabel + ' ' + (isLarge ? chalk.yellow(gzipSizeLabel) : gzipSizeLabel));
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
if (suggestBundleSplitting) {
|
|
117
|
-
logger.log();
|
|
118
|
-
logger.warn('The bundle size is significantly larger than recommended.');
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function printFileSizesHeader(longestFileNameLength, longestSizeLabelLength) {
|
|
123
|
-
var longestLengths = [longestFileNameLength, longestSizeLabelLength];
|
|
124
|
-
var headerRow = ['File', 'Size', 'Gzipped'].reduce(function (prev, cur, index) {
|
|
125
|
-
var length = longestLengths[index];
|
|
126
|
-
var curLabel = cur;
|
|
127
|
-
|
|
128
|
-
if (length) {
|
|
129
|
-
curLabel = cur.length < length ? cur + ' '.repeat(length - cur.length) : cur;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return prev + curLabel + ' ';
|
|
133
|
-
}, ' ');
|
|
134
|
-
logger.log(chalk.bold(chalk.blue(headerRow)));
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function removeFileNameHash(buildFolder, fileName) {
|
|
138
|
-
return fileName.replace(buildFolder, '').replace(/\\/g, '/').replace(/\/?(.*)(\.[0-9a-f]+)(\.chunk)?(\.js|\.css)/, function (match, p1, p2, p3, p4) {
|
|
139
|
-
return p1 + p4;
|
|
140
|
-
});
|
|
141
|
-
} // Input: 1024, 2048
|
|
142
|
-
// Output: "(+1 KB)"
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
function getDifferenceLabel(currentSize, previousSize) {
|
|
146
|
-
var FIFTY_KILOBYTES = 1024 * 50;
|
|
147
|
-
var difference = currentSize - previousSize;
|
|
148
|
-
var fileSize = !Number.isNaN(difference) ? filesize(difference) : 0;
|
|
149
|
-
|
|
150
|
-
if (difference >= FIFTY_KILOBYTES) {
|
|
151
|
-
return chalk.red('+' + fileSize);
|
|
152
|
-
} else if (difference < FIFTY_KILOBYTES && difference > 0) {
|
|
153
|
-
return chalk.yellow('+' + fileSize);
|
|
154
|
-
} else if (difference < 0) {
|
|
155
|
-
return chalk.green(fileSize);
|
|
156
|
-
} else {
|
|
157
|
-
return '';
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
function measureFileSizesBeforeBuild(buildFolder) {
|
|
162
|
-
return new Promise(function (resolve) {
|
|
163
|
-
recursive(buildFolder, function (err, fileNames) {
|
|
164
|
-
var sizes;
|
|
165
|
-
|
|
166
|
-
if (!err && fileNames) {
|
|
167
|
-
sizes = fileNames.filter(canReadAsset).reduce(function (memo, fileName) {
|
|
168
|
-
var contents = fs.readFileSync(fileName);
|
|
169
|
-
var key = removeFileNameHash(buildFolder, fileName); // save both the original size and gzip size
|
|
170
|
-
|
|
171
|
-
memo[key] = [contents.length, gzipSize.sync(contents)];
|
|
172
|
-
return memo;
|
|
173
|
-
}, {});
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
resolve({
|
|
177
|
-
root: buildFolder,
|
|
178
|
-
sizes: sizes || {}
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
export { measureFileSizesBeforeBuild, printFileSizesAfterBuild };
|
|
185
|
-
/* eslint-enable */
|
|
@@ -1,72 +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 chalk from 'chalk';
|
|
10
|
-
import { readTsConfigByFile } from "./readTsConfig";
|
|
11
|
-
import { applyOptionsChain } from "./applyOptionsChain";
|
|
12
|
-
export var validAlias = function validAlias(modernConfig, _ref) {
|
|
13
|
-
var tsconfigPath = _ref.tsconfigPath;
|
|
14
|
-
var alias = modernConfig.source.alias;
|
|
15
|
-
|
|
16
|
-
if (!alias) {
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
var isTsProject = fs.existsSync(tsconfigPath);
|
|
21
|
-
|
|
22
|
-
if (!isTsProject) {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
var userAlias = getUserAlias(alias);
|
|
27
|
-
|
|
28
|
-
if (Object.keys(userAlias).length > 0) {
|
|
29
|
-
return chalk.red('Note: Please use `compilerOptions.paths` in "tsconfig.json" file replace `source.alias` config in "modern.config.js/ts" when project is typescript');
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return null;
|
|
33
|
-
};
|
|
34
|
-
export var getAlias = function getAlias(aliasOption, option) {
|
|
35
|
-
var isTsProject = fs.existsSync(option.tsconfigPath);
|
|
36
|
-
var aliasConfig;
|
|
37
|
-
|
|
38
|
-
if (!isTsProject) {
|
|
39
|
-
aliasConfig = {
|
|
40
|
-
absoluteBaseUrl: option.appDirectory,
|
|
41
|
-
paths: applyOptionsChain({
|
|
42
|
-
'@': ['./src']
|
|
43
|
-
}, aliasOption),
|
|
44
|
-
isTsPath: false,
|
|
45
|
-
isTsProject: isTsProject
|
|
46
|
-
};
|
|
47
|
-
} else {
|
|
48
|
-
var _tsconfig$compilerOpt, _tsconfig$compilerOpt2;
|
|
49
|
-
|
|
50
|
-
var tsconfig = readTsConfigByFile(option.tsconfigPath);
|
|
51
|
-
var baseUrl = tsconfig === null || tsconfig === void 0 ? void 0 : (_tsconfig$compilerOpt = tsconfig.compilerOptions) === null || _tsconfig$compilerOpt === void 0 ? void 0 : _tsconfig$compilerOpt.baseUrl;
|
|
52
|
-
aliasConfig = {
|
|
53
|
-
absoluteBaseUrl: baseUrl ? path.join(option.appDirectory, baseUrl) : option.appDirectory,
|
|
54
|
-
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),
|
|
55
|
-
isTsPath: true,
|
|
56
|
-
isTsProject: isTsProject
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return aliasConfig;
|
|
61
|
-
}; // filter invalid ts paths that are not array
|
|
62
|
-
|
|
63
|
-
export var getUserAlias = function getUserAlias() {
|
|
64
|
-
var alias = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
65
|
-
return Object.keys(alias).reduce(function (o, k) {
|
|
66
|
-
if (Array.isArray(alias[k])) {
|
|
67
|
-
o[k] = alias[k];
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return o;
|
|
71
|
-
}, {});
|
|
72
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line import/no-useless-path-segments
|
|
2
|
-
import { isFunction, logger, isPlainObject } from "./index";
|
|
3
|
-
export var applyOptionsChain = function applyOptionsChain(defaults, options, utils) {
|
|
4
|
-
var mergeFn = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : Object.assign;
|
|
5
|
-
|
|
6
|
-
if (!options) {
|
|
7
|
-
return defaults;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
if (isPlainObject(options)) {
|
|
11
|
-
return mergeFn(defaults, options);
|
|
12
|
-
} else if (isFunction(options)) {
|
|
13
|
-
var ret = options(defaults, utils);
|
|
14
|
-
|
|
15
|
-
if (ret) {
|
|
16
|
-
if (!isPlainObject(ret)) {
|
|
17
|
-
logger.warn("".concat(options.name, ": Function should mutate the config and return nothing, Or return a cloned or merged version of config object."));
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return ret;
|
|
21
|
-
}
|
|
22
|
-
} else if (Array.isArray(options)) {
|
|
23
|
-
return options.reduce(function (memo, cur) {
|
|
24
|
-
return applyOptionsChain(memo, cur, utils, mergeFn);
|
|
25
|
-
}, defaults);
|
|
26
|
-
} else {
|
|
27
|
-
throw new Error("applyOptionsChain error:\ndefault options is: ".concat(JSON.stringify(defaults)));
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return defaults;
|
|
31
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { findExists } from "./findExists";
|
|
2
|
-
/**
|
|
3
|
-
* Require function compatible with esm and cjs module.
|
|
4
|
-
* @param filePath - File to required.
|
|
5
|
-
* @returns module export object.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export var compatRequire = function compatRequire(filePath) {
|
|
9
|
-
var mod = require(filePath);
|
|
10
|
-
|
|
11
|
-
return mod !== null && mod !== void 0 && mod.__esModule ? mod["default"] : mod;
|
|
12
|
-
};
|
|
13
|
-
export var requireExistModule = function requireExistModule(filename) {
|
|
14
|
-
var extensions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ['.ts', '.js'];
|
|
15
|
-
var exist = findExists(extensions.map(function (ext) {
|
|
16
|
-
return "".concat(filename).concat(ext);
|
|
17
|
-
}));
|
|
18
|
-
|
|
19
|
-
if (!exist) {
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return compatRequire(exist);
|
|
24
|
-
};
|
|
25
|
-
export var cleanRequireCache = function cleanRequireCache(filelist) {
|
|
26
|
-
filelist.forEach(function (filepath) {
|
|
27
|
-
delete require.cache[filepath];
|
|
28
|
-
});
|
|
29
|
-
};
|