@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,35 +0,0 @@
|
|
|
1
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
2
|
-
|
|
3
|
-
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); }
|
|
4
|
-
|
|
5
|
-
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; }
|
|
6
|
-
|
|
7
|
-
import { isProd, isDev, isTest } from "./is";
|
|
8
|
-
/**
|
|
9
|
-
* Generate cache identifier from some packages and config files.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
export function getCacheIdentifier(packages, _files) {
|
|
13
|
-
/* eslint-disable no-nested-ternary */
|
|
14
|
-
var cacheIdentifier = isProd() ? 'production' : isDev() ? 'development' : isTest() ? 'test' : '';
|
|
15
|
-
/* eslint-enable no-nested-ternary */
|
|
16
|
-
|
|
17
|
-
var _iterator = _createForOfIteratorHelper(packages),
|
|
18
|
-
_step;
|
|
19
|
-
|
|
20
|
-
try {
|
|
21
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
22
|
-
var _step$value = _step.value,
|
|
23
|
-
name = _step$value.name,
|
|
24
|
-
version = _step$value.version;
|
|
25
|
-
cacheIdentifier += ":".concat(name, "@").concat(version);
|
|
26
|
-
} // TODO: config file hash
|
|
27
|
-
|
|
28
|
-
} catch (err) {
|
|
29
|
-
_iterator.e(err);
|
|
30
|
-
} finally {
|
|
31
|
-
_iterator.f();
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return cacheIdentifier;
|
|
35
|
-
}
|
|
@@ -1,26 +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 { isPlainObject } from "./is";
|
|
8
|
-
import { MAIN_ENTRY_NAME } from "./constants";
|
|
9
|
-
export var getEntryOptions = function getEntryOptions(name, baseOptions, optionsByEntries, packageName) {
|
|
10
|
-
if (optionsByEntries) {
|
|
11
|
-
var optionsByEntry = getOptionsByEntryName(name, optionsByEntries); // compatible with main entry using packageName as the key
|
|
12
|
-
|
|
13
|
-
if (optionsByEntry === undefined && name === MAIN_ENTRY_NAME && packageName) {
|
|
14
|
-
optionsByEntry = getOptionsByEntryName(packageName, optionsByEntries);
|
|
15
|
-
} // eslint-disable-next-line no-nested-ternary
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return optionsByEntry !== undefined ? isPlainObject(optionsByEntry) && isPlainObject(baseOptions) ? _objectSpread(_objectSpread({}, baseOptions), optionsByEntry) : optionsByEntry : baseOptions;
|
|
19
|
-
} else {
|
|
20
|
-
return baseOptions;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
var getOptionsByEntryName = function getOptionsByEntryName(name, optionsByEntries) {
|
|
25
|
-
return optionsByEntries.hasOwnProperty(name) ? optionsByEntries[name] : undefined;
|
|
26
|
-
};
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
2
|
-
|
|
3
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
4
|
-
|
|
5
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
6
|
-
|
|
7
|
-
import os from 'os';
|
|
8
|
-
import path from 'path';
|
|
9
|
-
import fs from 'fs-extra';
|
|
10
|
-
import { canUsePnpm, canUseYarn } from "./nodeEnv";
|
|
11
|
-
var MAX_TIMES = 5;
|
|
12
|
-
export function getPackageManager() {
|
|
13
|
-
return _getPackageManager.apply(this, arguments);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function _getPackageManager() {
|
|
17
|
-
_getPackageManager = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
18
|
-
var cwd,
|
|
19
|
-
appDirectory,
|
|
20
|
-
times,
|
|
21
|
-
_args = arguments;
|
|
22
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
23
|
-
while (1) {
|
|
24
|
-
switch (_context.prev = _context.next) {
|
|
25
|
-
case 0:
|
|
26
|
-
cwd = _args.length > 0 && _args[0] !== undefined ? _args[0] : process.cwd();
|
|
27
|
-
appDirectory = cwd;
|
|
28
|
-
times = 0;
|
|
29
|
-
|
|
30
|
-
case 3:
|
|
31
|
-
if (!(os.homedir() !== appDirectory && times < MAX_TIMES)) {
|
|
32
|
-
_context.next = 14;
|
|
33
|
-
break;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
times++;
|
|
37
|
-
|
|
38
|
-
if (!fs.existsSync(path.resolve(appDirectory, 'pnpm-lock.yaml'))) {
|
|
39
|
-
_context.next = 7;
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return _context.abrupt("return", 'pnpm');
|
|
44
|
-
|
|
45
|
-
case 7:
|
|
46
|
-
if (!fs.existsSync(path.resolve(appDirectory, 'yarn.lock'))) {
|
|
47
|
-
_context.next = 9;
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return _context.abrupt("return", 'yarn');
|
|
52
|
-
|
|
53
|
-
case 9:
|
|
54
|
-
if (!fs.existsSync(path.resolve(appDirectory, 'package-lock.json'))) {
|
|
55
|
-
_context.next = 11;
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return _context.abrupt("return", 'npm');
|
|
60
|
-
|
|
61
|
-
case 11:
|
|
62
|
-
appDirectory = path.join(appDirectory, '..');
|
|
63
|
-
_context.next = 3;
|
|
64
|
-
break;
|
|
65
|
-
|
|
66
|
-
case 14:
|
|
67
|
-
_context.next = 16;
|
|
68
|
-
return canUsePnpm();
|
|
69
|
-
|
|
70
|
-
case 16:
|
|
71
|
-
if (!_context.sent) {
|
|
72
|
-
_context.next = 18;
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return _context.abrupt("return", 'pnpm');
|
|
77
|
-
|
|
78
|
-
case 18:
|
|
79
|
-
_context.next = 20;
|
|
80
|
-
return canUseYarn();
|
|
81
|
-
|
|
82
|
-
case 20:
|
|
83
|
-
if (!_context.sent) {
|
|
84
|
-
_context.next = 22;
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return _context.abrupt("return", 'yarn');
|
|
89
|
-
|
|
90
|
-
case 22:
|
|
91
|
-
return _context.abrupt("return", 'npm');
|
|
92
|
-
|
|
93
|
-
case 23:
|
|
94
|
-
case "end":
|
|
95
|
-
return _context.stop();
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}, _callee);
|
|
99
|
-
}));
|
|
100
|
-
return _getPackageManager.apply(this, arguments);
|
|
101
|
-
}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
2
|
-
|
|
3
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
4
|
-
|
|
5
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
6
|
-
|
|
7
|
-
import net from 'net';
|
|
8
|
-
import { chalk } from "./chalk";
|
|
9
|
-
import { logger } from "./logger";
|
|
10
|
-
/**
|
|
11
|
-
* Get available free port.
|
|
12
|
-
* @param port - Current port want to use.
|
|
13
|
-
* @param tryLimits - Maximum number of retries.
|
|
14
|
-
* @returns Available port number.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/* eslint-disable no-param-reassign, @typescript-eslint/no-loop-func */
|
|
18
|
-
|
|
19
|
-
export var getPort = /*#__PURE__*/function () {
|
|
20
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(port) {
|
|
21
|
-
var tryLimits,
|
|
22
|
-
original,
|
|
23
|
-
found,
|
|
24
|
-
attempts,
|
|
25
|
-
_args = arguments;
|
|
26
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
27
|
-
while (1) {
|
|
28
|
-
switch (_context.prev = _context.next) {
|
|
29
|
-
case 0:
|
|
30
|
-
tryLimits = _args.length > 1 && _args[1] !== undefined ? _args[1] : 20;
|
|
31
|
-
|
|
32
|
-
if (typeof port === 'string') {
|
|
33
|
-
port = parseInt(port, 10);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
original = port;
|
|
37
|
-
found = false;
|
|
38
|
-
attempts = 0;
|
|
39
|
-
|
|
40
|
-
case 5:
|
|
41
|
-
if (!(!found && attempts <= tryLimits)) {
|
|
42
|
-
_context.next = 19;
|
|
43
|
-
break;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
_context.prev = 6;
|
|
47
|
-
_context.next = 9;
|
|
48
|
-
return new Promise(function (resolve, reject) {
|
|
49
|
-
var server = net.createServer();
|
|
50
|
-
server.unref();
|
|
51
|
-
server.on('error', reject);
|
|
52
|
-
server.listen({
|
|
53
|
-
port: port,
|
|
54
|
-
host: '0.0.0.0'
|
|
55
|
-
}, function () {
|
|
56
|
-
found = true;
|
|
57
|
-
server.close(resolve);
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
case 9:
|
|
62
|
-
_context.next = 17;
|
|
63
|
-
break;
|
|
64
|
-
|
|
65
|
-
case 11:
|
|
66
|
-
_context.prev = 11;
|
|
67
|
-
_context.t0 = _context["catch"](6);
|
|
68
|
-
|
|
69
|
-
if (!(_context.t0.code !== 'EADDRINUSE')) {
|
|
70
|
-
_context.next = 15;
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
throw _context.t0;
|
|
75
|
-
|
|
76
|
-
case 15:
|
|
77
|
-
port++;
|
|
78
|
-
attempts++;
|
|
79
|
-
|
|
80
|
-
case 17:
|
|
81
|
-
_context.next = 5;
|
|
82
|
-
break;
|
|
83
|
-
|
|
84
|
-
case 19:
|
|
85
|
-
if (port !== original) {
|
|
86
|
-
logger.info(chalk.red("Something is already running on port ".concat(original, ". ").concat(chalk.yellow("Use port ".concat(port, " instead.")))));
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return _context.abrupt("return", port);
|
|
90
|
-
|
|
91
|
-
case 21:
|
|
92
|
-
case "end":
|
|
93
|
-
return _context.stop();
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}, _callee, null, [[6, 11]]);
|
|
97
|
-
}));
|
|
98
|
-
|
|
99
|
-
return function getPort(_x) {
|
|
100
|
-
return _ref.apply(this, arguments);
|
|
101
|
-
};
|
|
102
|
-
}();
|
|
103
|
-
/* eslint-enable no-param-reassign, @typescript-eslint/no-loop-func */
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// cover: https://rushstack.io/pages/api/node-core-library.import.lazy/
|
|
2
|
-
var lazy = function lazy(moduleName, requireFn) {
|
|
3
|
-
var importLazyLocal = require('import-lazy')(requireFn);
|
|
4
|
-
|
|
5
|
-
return importLazyLocal(moduleName);
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export { lazy as lazyImport };
|
|
9
|
-
export var Import = {
|
|
10
|
-
lazy: lazy
|
|
11
|
-
};
|
|
@@ -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,81 +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 var isDepExists = function isDepExists(appDirectory, name) {
|
|
13
|
-
var json = require(path.resolve(appDirectory, './package.json'));
|
|
14
|
-
|
|
15
|
-
var _json$dependencies = json.dependencies,
|
|
16
|
-
dependencies = _json$dependencies === void 0 ? {} : _json$dependencies,
|
|
17
|
-
_json$devDependencies = json.devDependencies,
|
|
18
|
-
devDependencies = _json$devDependencies === void 0 ? {} : _json$devDependencies;
|
|
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 var isTypescript = function isTypescript(root) {
|
|
29
|
-
return fs.existsSync(path.resolve(root, './tsconfig.json'));
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* Is Empty object
|
|
33
|
-
*
|
|
34
|
-
* @param o - Any object.
|
|
35
|
-
* @returns Whether it is empty object.
|
|
36
|
-
*/
|
|
37
|
-
|
|
38
|
-
export var isEmpty = function isEmpty(o) {
|
|
39
|
-
return Object.entries(o).length === 0 && o.constructor === Object;
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* Is SSR project
|
|
43
|
-
*
|
|
44
|
-
* @param config - User config.
|
|
45
|
-
* @returns Whether to use server side render.
|
|
46
|
-
*/
|
|
47
|
-
|
|
48
|
-
export var isSSR = function isSSR(config) {
|
|
49
|
-
var server = config.server;
|
|
50
|
-
|
|
51
|
-
if (server !== null && server !== void 0 && server.ssr) {
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (server !== null && server !== void 0 && server.ssrByEntries && !isEmpty(server.ssrByEntries)) {
|
|
56
|
-
for (var _i = 0, _Object$keys = Object.keys(server.ssrByEntries); _i < _Object$keys.length; _i++) {
|
|
57
|
-
var name = _Object$keys[_i];
|
|
58
|
-
|
|
59
|
-
if (server.ssrByEntries[name]) {
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return false;
|
|
66
|
-
};
|
|
67
|
-
export var isUseSSRBundle = function isUseSSRBundle(config) {
|
|
68
|
-
var output = config.output;
|
|
69
|
-
|
|
70
|
-
if (output !== null && output !== void 0 && output.ssg) {
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return isSSR(config);
|
|
75
|
-
};
|
|
76
|
-
export var isFastRefresh = function isFastRefresh() {
|
|
77
|
-
return isDev() && process.env.FAST_REFRESH !== 'false';
|
|
78
|
-
};
|
|
79
|
-
export * from "./node-env";
|
|
80
|
-
export * from "./platform";
|
|
81
|
-
export * from "./type";
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export var isDev = function isDev() {
|
|
2
|
-
return process.env.NODE_ENV === 'development';
|
|
3
|
-
};
|
|
4
|
-
export var isProd = function isProd() {
|
|
5
|
-
return process.env.NODE_ENV === 'production';
|
|
6
|
-
};
|
|
7
|
-
export var isTest = function isTest() {
|
|
8
|
-
return process.env.NODE_ENV === 'test';
|
|
9
|
-
}; // Variable used for enabling profiling in Production.
|
|
10
|
-
|
|
11
|
-
export var isProdProfile = function isProdProfile() {
|
|
12
|
-
return isProd() && process.argv.includes('--profile');
|
|
13
|
-
};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export var isNodeJS = function isNodeJS() {
|
|
2
|
-
return typeof process !== 'undefined' && process.versions != null && process.versions.node != null && process.versions.electron == null;
|
|
3
|
-
};
|
|
4
|
-
export var isBrowser = function isBrowser() {
|
|
5
|
-
return typeof window !== 'undefined';
|
|
6
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
-
|
|
3
|
-
export function isString(str) {
|
|
4
|
-
return typeof str === 'string';
|
|
5
|
-
}
|
|
6
|
-
export function isUndefined(obj) {
|
|
7
|
-
return typeof obj === 'undefined';
|
|
8
|
-
}
|
|
9
|
-
export function isArray(obj) {
|
|
10
|
-
return Array.isArray(obj);
|
|
11
|
-
} // eslint-disable-next-line @typescript-eslint/ban-types
|
|
12
|
-
|
|
13
|
-
export function isFunction(func) {
|
|
14
|
-
return typeof func === 'function';
|
|
15
|
-
}
|
|
16
|
-
export function isObject(obj) {
|
|
17
|
-
return obj !== null && _typeof(obj) === 'object';
|
|
18
|
-
}
|
|
19
|
-
export function isPlainObject(obj) {
|
|
20
|
-
return isObject(obj) && Object.prototype.toString.call(obj) === '[object Object]';
|
|
21
|
-
}
|
|
22
|
-
export function isPromise(obj) {
|
|
23
|
-
return Boolean(obj) && (_typeof(obj) === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
|
|
24
|
-
}
|
|
25
|
-
export function isRegExp(obj) {
|
|
26
|
-
return Object.prototype.toString.call(obj) === '[object RegExp]';
|
|
27
|
-
}
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); }
|
|
2
|
-
|
|
3
|
-
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."); }
|
|
4
|
-
|
|
5
|
-
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); }
|
|
6
|
-
|
|
7
|
-
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; }
|
|
8
|
-
|
|
9
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
10
|
-
|
|
11
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
|
-
|
|
13
|
-
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; }
|
|
14
|
-
|
|
15
|
-
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; }
|
|
16
|
-
|
|
17
|
-
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; }
|
|
18
|
-
|
|
19
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
20
|
-
|
|
21
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
22
|
-
|
|
23
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
24
|
-
|
|
25
|
-
import chalk from 'chalk';
|
|
26
|
-
var grey = chalk.grey,
|
|
27
|
-
underline = chalk.underline;
|
|
28
|
-
var LOG_TYPES = {
|
|
29
|
-
error: {
|
|
30
|
-
color: 'red',
|
|
31
|
-
label: 'error',
|
|
32
|
-
level: 'error'
|
|
33
|
-
},
|
|
34
|
-
info: {
|
|
35
|
-
color: 'blue',
|
|
36
|
-
label: 'info',
|
|
37
|
-
level: 'info'
|
|
38
|
-
},
|
|
39
|
-
warn: {
|
|
40
|
-
color: 'yellow',
|
|
41
|
-
label: 'warning',
|
|
42
|
-
level: 'warn'
|
|
43
|
-
},
|
|
44
|
-
debug: {
|
|
45
|
-
color: 'red',
|
|
46
|
-
label: 'debug',
|
|
47
|
-
level: 'debug'
|
|
48
|
-
},
|
|
49
|
-
log: {
|
|
50
|
-
level: 'info'
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
var DEFAULT_CONFIG = {
|
|
54
|
-
displayLabel: true,
|
|
55
|
-
underlineLabel: true,
|
|
56
|
-
uppercaseLabel: false
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
var Logger = /*#__PURE__*/function () {
|
|
60
|
-
function Logger() {
|
|
61
|
-
var _this = this;
|
|
62
|
-
|
|
63
|
-
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
64
|
-
|
|
65
|
-
_classCallCheck(this, Logger);
|
|
66
|
-
|
|
67
|
-
this.logCount = 200;
|
|
68
|
-
this.history = {};
|
|
69
|
-
this.config = void 0;
|
|
70
|
-
this.types = void 0;
|
|
71
|
-
this.longestLabel = void 0;
|
|
72
|
-
this.config = _objectSpread(_objectSpread({}, DEFAULT_CONFIG), options.config || {});
|
|
73
|
-
this.types = _objectSpread(_objectSpread({}, LOG_TYPES), options.types || {});
|
|
74
|
-
this.longestLabel = this.getLongestLabel();
|
|
75
|
-
Object.keys(this.types).forEach(function (type) {
|
|
76
|
-
_this[type] = _this._log.bind(_this, type);
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
_createClass(Logger, [{
|
|
81
|
-
key: "retainLog",
|
|
82
|
-
value: function retainLog(type, message) {
|
|
83
|
-
if (!this.history[type]) {
|
|
84
|
-
this.history[type] = [];
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
this.history[type].push(message);
|
|
88
|
-
|
|
89
|
-
while (this.history[type].length > this.logCount) {
|
|
90
|
-
this.history[type].shift();
|
|
91
|
-
}
|
|
92
|
-
} // eslint-disable-next-line max-statements
|
|
93
|
-
|
|
94
|
-
}, {
|
|
95
|
-
key: "_log",
|
|
96
|
-
value: function _log(type, message) {
|
|
97
|
-
if (message === undefined) {
|
|
98
|
-
// eslint-disable-next-line no-console
|
|
99
|
-
console.log();
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
var label = '';
|
|
104
|
-
var text = '';
|
|
105
|
-
var logType = this.types[type];
|
|
106
|
-
|
|
107
|
-
if (this.config.displayLabel && logType.label) {
|
|
108
|
-
label = this.config.uppercaseLabel ? logType.label.toUpperCase() : logType.label;
|
|
109
|
-
|
|
110
|
-
if (this.config.underlineLabel) {
|
|
111
|
-
label = underline(label).padEnd(this.longestUnderlinedLabel.length + 1);
|
|
112
|
-
} else {
|
|
113
|
-
label = label.padEnd(this.longestLabel.length + 1);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
label = logType.color ? chalk[logType.color](label) : label;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (message instanceof Error) {
|
|
120
|
-
if (message.stack) {
|
|
121
|
-
var _message$stack$split = message.stack.split('\n'),
|
|
122
|
-
_message$stack$split2 = _toArray(_message$stack$split),
|
|
123
|
-
name = _message$stack$split2[0],
|
|
124
|
-
rest = _message$stack$split2.slice(1);
|
|
125
|
-
|
|
126
|
-
text = "".concat(name, "\n").concat(grey(rest.join('\n')));
|
|
127
|
-
} else {
|
|
128
|
-
text = message.message;
|
|
129
|
-
}
|
|
130
|
-
} else {
|
|
131
|
-
text = "".concat(message);
|
|
132
|
-
} // only retain logs of warn/error level
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (logType.level === 'warn' || logType.level === 'error') {
|
|
136
|
-
// retain log text without label
|
|
137
|
-
this.retainLog(type, text);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
var log = label.length > 0 ? "".concat(label, " ").concat(text) : text; // eslint-disable-next-line no-console
|
|
141
|
-
|
|
142
|
-
console.log(log);
|
|
143
|
-
}
|
|
144
|
-
}, {
|
|
145
|
-
key: "getLongestLabel",
|
|
146
|
-
value: function getLongestLabel() {
|
|
147
|
-
var _this2 = this;
|
|
148
|
-
|
|
149
|
-
var longestLabel = '';
|
|
150
|
-
Object.keys(this.types).forEach(function (type) {
|
|
151
|
-
var _this2$types$type$lab = _this2.types[type].label,
|
|
152
|
-
label = _this2$types$type$lab === void 0 ? '' : _this2$types$type$lab;
|
|
153
|
-
|
|
154
|
-
if (label.length > longestLabel.length) {
|
|
155
|
-
longestLabel = label;
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
return longestLabel;
|
|
159
|
-
}
|
|
160
|
-
}, {
|
|
161
|
-
key: "longestUnderlinedLabel",
|
|
162
|
-
get: function get() {
|
|
163
|
-
return underline(this.longestLabel);
|
|
164
|
-
}
|
|
165
|
-
}, {
|
|
166
|
-
key: "getRetainedLogs",
|
|
167
|
-
value: function getRetainedLogs(type) {
|
|
168
|
-
return this.history[type] || [];
|
|
169
|
-
}
|
|
170
|
-
}, {
|
|
171
|
-
key: "clearRetainedLogs",
|
|
172
|
-
value: function clearRetainedLogs(type) {
|
|
173
|
-
if (type) {
|
|
174
|
-
if (this.history[type]) {
|
|
175
|
-
this.history[type] = [];
|
|
176
|
-
}
|
|
177
|
-
} else {
|
|
178
|
-
this.history = {};
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}]);
|
|
182
|
-
|
|
183
|
-
return Logger;
|
|
184
|
-
}();
|
|
185
|
-
|
|
186
|
-
var logger = new Logger();
|
|
187
|
-
logger.Logger = Logger;
|
|
188
|
-
export { logger };
|