@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
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.getPackageManager = void 0;
|
|
16
|
+
const os_1 = __importDefault(require("os"));
|
|
17
|
+
const path_1 = __importDefault(require("path"));
|
|
18
|
+
const compiled_1 = require("./compiled");
|
|
19
|
+
const nodeEnv_1 = require("./nodeEnv");
|
|
20
|
+
const MAX_TIMES = 5;
|
|
21
|
+
function getPackageManager(cwd = process.cwd()) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
let appDirectory = cwd;
|
|
24
|
+
let times = 0;
|
|
25
|
+
while (os_1.default.homedir() !== appDirectory && times < MAX_TIMES) {
|
|
26
|
+
times++;
|
|
27
|
+
if (compiled_1.fs.existsSync(path_1.default.resolve(appDirectory, 'pnpm-lock.yaml'))) {
|
|
28
|
+
return 'pnpm';
|
|
29
|
+
}
|
|
30
|
+
if (compiled_1.fs.existsSync(path_1.default.resolve(appDirectory, 'yarn.lock'))) {
|
|
31
|
+
return 'yarn';
|
|
32
|
+
}
|
|
33
|
+
if (compiled_1.fs.existsSync(path_1.default.resolve(appDirectory, 'package-lock.json'))) {
|
|
34
|
+
return 'npm';
|
|
35
|
+
}
|
|
36
|
+
appDirectory = path_1.default.join(appDirectory, '..');
|
|
37
|
+
}
|
|
38
|
+
if (yield (0, nodeEnv_1.canUsePnpm)()) {
|
|
39
|
+
return 'pnpm';
|
|
40
|
+
}
|
|
41
|
+
if (yield (0, nodeEnv_1.canUseYarn)()) {
|
|
42
|
+
return 'yarn';
|
|
43
|
+
}
|
|
44
|
+
return 'npm';
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
exports.getPackageManager = getPackageManager;
|
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
* @param tryLimits - Maximum number of retries.
|
|
5
5
|
* @returns Available port number.
|
|
6
6
|
*/
|
|
7
|
-
export declare const getPort: (port: string | number, tryLimits?: number) => Promise<number>;
|
|
7
|
+
export declare const getPort: (port: string | number, tryLimits?: number) => Promise<number>;
|
package/dist/getPort.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.getPort = void 0;
|
|
16
|
+
const net_1 = __importDefault(require("net"));
|
|
17
|
+
const compiled_1 = require("./compiled");
|
|
18
|
+
const logger_1 = require("./logger");
|
|
19
|
+
/**
|
|
20
|
+
* Get available free port.
|
|
21
|
+
* @param port - Current port want to use.
|
|
22
|
+
* @param tryLimits - Maximum number of retries.
|
|
23
|
+
* @returns Available port number.
|
|
24
|
+
*/
|
|
25
|
+
/* eslint-disable no-param-reassign, @typescript-eslint/no-loop-func */
|
|
26
|
+
const getPort = (port, tryLimits = 20) => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
+
if (typeof port === 'string') {
|
|
28
|
+
port = parseInt(port, 10);
|
|
29
|
+
}
|
|
30
|
+
const original = port;
|
|
31
|
+
let found = false;
|
|
32
|
+
let attempts = 0;
|
|
33
|
+
while (!found && attempts <= tryLimits) {
|
|
34
|
+
try {
|
|
35
|
+
yield new Promise((resolve, reject) => {
|
|
36
|
+
const server = net_1.default.createServer();
|
|
37
|
+
server.unref();
|
|
38
|
+
server.on('error', reject);
|
|
39
|
+
server.listen({
|
|
40
|
+
port,
|
|
41
|
+
host: '0.0.0.0',
|
|
42
|
+
}, () => {
|
|
43
|
+
found = true;
|
|
44
|
+
server.close(resolve);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
catch (e) {
|
|
49
|
+
if (e.code !== 'EADDRINUSE') {
|
|
50
|
+
throw e;
|
|
51
|
+
}
|
|
52
|
+
port++;
|
|
53
|
+
attempts++;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (port !== original) {
|
|
57
|
+
logger_1.logger.info(compiled_1.chalk.red(`Something is already running on port ${original}. ${compiled_1.chalk.yellow(`Use port ${port} instead.`)}`));
|
|
58
|
+
}
|
|
59
|
+
return port;
|
|
60
|
+
});
|
|
61
|
+
exports.getPort = getPort;
|
|
62
|
+
/* eslint-enable no-param-reassign, @typescript-eslint/no-loop-func */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getServerConfig: (appDirectory: string, configFile: string) => Promise<string | false>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
exports.getServerConfig = void 0;
|
|
32
|
+
const path = __importStar(require("path"));
|
|
33
|
+
const constants_1 = require("./constants");
|
|
34
|
+
const findExists_1 = require("./findExists");
|
|
35
|
+
const getServerConfig = (appDirectory, configFile) => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
+
const configFilePath = (0, findExists_1.findExists)(constants_1.CONFIG_FILE_EXTENSIONS.map(extension => path.resolve(appDirectory, `${configFile}${extension}`)));
|
|
37
|
+
return configFilePath;
|
|
38
|
+
});
|
|
39
|
+
exports.getServerConfig = getServerConfig;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare const lazy: (moduleName: string, requireFn: (id: string) => unknown) => any;
|
|
2
2
|
export { lazy as lazyImport };
|
|
3
3
|
export declare const Import: {
|
|
4
|
-
|
|
5
|
-
};
|
|
4
|
+
lazy: (moduleName: string, requireFn: (id: string) => unknown) => any;
|
|
5
|
+
};
|
package/dist/import.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Import = exports.lazyImport = void 0;
|
|
4
|
+
// cover: https://rushstack.io/pages/api/node-core-library.import.lazy/
|
|
5
|
+
const lazy = (moduleName, requireFn) => {
|
|
6
|
+
const importLazyLocal = require('../compiled/import-lazy')(requireFn);
|
|
7
|
+
return importLazyLocal(moduleName);
|
|
8
|
+
};
|
|
9
|
+
exports.lazyImport = lazy;
|
|
10
|
+
exports.Import = { lazy };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export *
|
|
2
|
-
export * from './chalk';
|
|
1
|
+
export * from './compiled';
|
|
3
2
|
export * from './format';
|
|
4
3
|
export * from './FileSizeReporter';
|
|
5
4
|
export * from './printBuildError';
|
|
@@ -12,7 +11,6 @@ export * from './constants';
|
|
|
12
11
|
export * from './ensureAbsolutePath';
|
|
13
12
|
export * from './getCacheIdentifier';
|
|
14
13
|
export * from './clearConsole';
|
|
15
|
-
export * from './pkgUp';
|
|
16
14
|
export * from './applyOptionsChain';
|
|
17
15
|
export * from './getBrowserslist';
|
|
18
16
|
export * from './removeSlash';
|
|
@@ -30,4 +28,7 @@ export * from './import';
|
|
|
30
28
|
export * from './watch';
|
|
31
29
|
export * from './nodeEnv';
|
|
32
30
|
export * from './wait';
|
|
33
|
-
export * from './emptyDir';
|
|
31
|
+
export * from './emptyDir';
|
|
32
|
+
export * from './getServerConfig';
|
|
33
|
+
export * from './ssrHelpers';
|
|
34
|
+
export * from './analyzeProject';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./compiled"), exports);
|
|
14
|
+
__exportStar(require("./format"), exports);
|
|
15
|
+
__exportStar(require("./FileSizeReporter"), exports);
|
|
16
|
+
__exportStar(require("./printBuildError"), exports);
|
|
17
|
+
__exportStar(require("./debug"), exports);
|
|
18
|
+
__exportStar(require("./findExists"), exports);
|
|
19
|
+
__exportStar(require("./is"), exports);
|
|
20
|
+
__exportStar(require("./compatRequire"), exports);
|
|
21
|
+
__exportStar(require("./logger"), exports);
|
|
22
|
+
__exportStar(require("./constants"), exports);
|
|
23
|
+
__exportStar(require("./ensureAbsolutePath"), exports);
|
|
24
|
+
__exportStar(require("./getCacheIdentifier"), exports);
|
|
25
|
+
__exportStar(require("./clearConsole"), exports);
|
|
26
|
+
__exportStar(require("./applyOptionsChain"), exports);
|
|
27
|
+
__exportStar(require("./getBrowserslist"), exports);
|
|
28
|
+
__exportStar(require("./removeSlash"), exports);
|
|
29
|
+
__exportStar(require("./getEntryOptions"), exports);
|
|
30
|
+
__exportStar(require("./getPort"), exports);
|
|
31
|
+
__exportStar(require("./monorepo"), exports);
|
|
32
|
+
__exportStar(require("./getPackageManager"), exports);
|
|
33
|
+
__exportStar(require("./runtimeExports"), exports);
|
|
34
|
+
__exportStar(require("./readTsConfig"), exports);
|
|
35
|
+
__exportStar(require("./path"), exports);
|
|
36
|
+
__exportStar(require("./generateMetaTags"), exports);
|
|
37
|
+
__exportStar(require("./prettyInstructions"), exports);
|
|
38
|
+
__exportStar(require("./alias"), exports);
|
|
39
|
+
__exportStar(require("./import"), exports);
|
|
40
|
+
__exportStar(require("./watch"), exports);
|
|
41
|
+
__exportStar(require("./nodeEnv"), exports);
|
|
42
|
+
__exportStar(require("./wait"), exports);
|
|
43
|
+
__exportStar(require("./emptyDir"), exports);
|
|
44
|
+
__exportStar(require("./getServerConfig"), exports);
|
|
45
|
+
__exportStar(require("./ssrHelpers"), exports);
|
|
46
|
+
__exportStar(require("./analyzeProject"), exports);
|
|
@@ -12,7 +12,6 @@ export declare const isDepExists: (appDirectory: string, name: string) => boolea
|
|
|
12
12
|
* @param root - App directory.
|
|
13
13
|
* @returns Whether to use typescript.
|
|
14
14
|
*/
|
|
15
|
-
|
|
16
15
|
export declare const isTypescript: (root: string) => boolean;
|
|
17
16
|
/**
|
|
18
17
|
* Is Empty object
|
|
@@ -20,7 +19,6 @@ export declare const isTypescript: (root: string) => boolean;
|
|
|
20
19
|
* @param o - Any object.
|
|
21
20
|
* @returns Whether it is empty object.
|
|
22
21
|
*/
|
|
23
|
-
|
|
24
22
|
export declare const isEmpty: (o: Record<string, unknown>) => boolean;
|
|
25
23
|
/**
|
|
26
24
|
* Is SSR project
|
|
@@ -28,10 +26,9 @@ export declare const isEmpty: (o: Record<string, unknown>) => boolean;
|
|
|
28
26
|
* @param config - User config.
|
|
29
27
|
* @returns Whether to use server side render.
|
|
30
28
|
*/
|
|
31
|
-
|
|
32
29
|
export declare const isSSR: (config: any) => boolean;
|
|
33
30
|
export declare const isUseSSRBundle: (config: any) => boolean;
|
|
34
31
|
export declare const isFastRefresh: () => boolean;
|
|
35
32
|
export * from './node-env';
|
|
36
33
|
export * from './platform';
|
|
37
|
-
export * from './type';
|
|
34
|
+
export * from './type';
|
package/dist/is/index.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.isFastRefresh = exports.isUseSSRBundle = exports.isSSR = exports.isEmpty = exports.isTypescript = exports.isDepExists = void 0;
|
|
17
|
+
const fs_1 = __importDefault(require("fs"));
|
|
18
|
+
const path_1 = __importDefault(require("path"));
|
|
19
|
+
const node_env_1 = require("./node-env");
|
|
20
|
+
/**
|
|
21
|
+
* Check if the package name is in dependencies or devDependencies.
|
|
22
|
+
*
|
|
23
|
+
* @param appDirectory - Project root directory.
|
|
24
|
+
* @param name - Package name.
|
|
25
|
+
* @returns True if the name is in dependencies or devDependencies, false otherwise.
|
|
26
|
+
*/
|
|
27
|
+
const isDepExists = (appDirectory, name) => {
|
|
28
|
+
const json = require(path_1.default.resolve(appDirectory, './package.json'));
|
|
29
|
+
const { dependencies = {}, devDependencies = {} } = json;
|
|
30
|
+
return (dependencies.hasOwnProperty(name) || devDependencies.hasOwnProperty(name));
|
|
31
|
+
};
|
|
32
|
+
exports.isDepExists = isDepExists;
|
|
33
|
+
/**
|
|
34
|
+
* Is typescript project.
|
|
35
|
+
*
|
|
36
|
+
* @param root - App directory.
|
|
37
|
+
* @returns Whether to use typescript.
|
|
38
|
+
*/
|
|
39
|
+
const isTypescript = (root) => fs_1.default.existsSync(path_1.default.resolve(root, './tsconfig.json'));
|
|
40
|
+
exports.isTypescript = isTypescript;
|
|
41
|
+
/**
|
|
42
|
+
* Is Empty object
|
|
43
|
+
*
|
|
44
|
+
* @param o - Any object.
|
|
45
|
+
* @returns Whether it is empty object.
|
|
46
|
+
*/
|
|
47
|
+
const isEmpty = (o) => Object.entries(o).length === 0 && o.constructor === Object;
|
|
48
|
+
exports.isEmpty = isEmpty;
|
|
49
|
+
/**
|
|
50
|
+
* Is SSR project
|
|
51
|
+
*
|
|
52
|
+
* @param config - User config.
|
|
53
|
+
* @returns Whether to use server side render.
|
|
54
|
+
*/
|
|
55
|
+
const isSSR = (config) => {
|
|
56
|
+
const { server } = config;
|
|
57
|
+
if (server === null || server === void 0 ? void 0 : server.ssr) {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
if ((server === null || server === void 0 ? void 0 : server.ssrByEntries) && !(0, exports.isEmpty)(server.ssrByEntries)) {
|
|
61
|
+
for (const name of Object.keys(server.ssrByEntries)) {
|
|
62
|
+
if (server.ssrByEntries[name]) {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return false;
|
|
68
|
+
};
|
|
69
|
+
exports.isSSR = isSSR;
|
|
70
|
+
const isUseSSRBundle = (config) => {
|
|
71
|
+
const { output } = config;
|
|
72
|
+
if (output === null || output === void 0 ? void 0 : output.ssg) {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
return (0, exports.isSSR)(config);
|
|
76
|
+
};
|
|
77
|
+
exports.isUseSSRBundle = isUseSSRBundle;
|
|
78
|
+
const isFastRefresh = () => (0, node_env_1.isDev)() && process.env.FAST_REFRESH !== 'false';
|
|
79
|
+
exports.isFastRefresh = isFastRefresh;
|
|
80
|
+
__exportStar(require("./node-env"), exports);
|
|
81
|
+
__exportStar(require("./platform"), exports);
|
|
82
|
+
__exportStar(require("./type"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isProdProfile = exports.isTest = exports.isProd = exports.isDev = void 0;
|
|
4
|
+
const isDev = () => process.env.NODE_ENV === 'development';
|
|
5
|
+
exports.isDev = isDev;
|
|
6
|
+
const isProd = () => process.env.NODE_ENV === 'production';
|
|
7
|
+
exports.isProd = isProd;
|
|
8
|
+
const isTest = () => process.env.NODE_ENV === 'test';
|
|
9
|
+
exports.isTest = isTest;
|
|
10
|
+
// Variable used for enabling profiling in Production.
|
|
11
|
+
const isProdProfile = () => (0, exports.isProd)() && process.argv.includes('--profile');
|
|
12
|
+
exports.isProdProfile = isProdProfile;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isBrowser = exports.isNodeJS = void 0;
|
|
4
|
+
const isNodeJS = () => typeof process !== 'undefined' &&
|
|
5
|
+
process.versions != null &&
|
|
6
|
+
process.versions.node != null &&
|
|
7
|
+
process.versions.electron == null;
|
|
8
|
+
exports.isNodeJS = isNodeJS;
|
|
9
|
+
const isBrowser = () => typeof window !== 'undefined';
|
|
10
|
+
exports.isBrowser = isBrowser;
|
|
@@ -5,4 +5,4 @@ export declare function isFunction(func: any): func is Function;
|
|
|
5
5
|
export declare function isObject(obj: unknown): obj is Record<string, any>;
|
|
6
6
|
export declare function isPlainObject(obj: unknown): obj is Record<string, any>;
|
|
7
7
|
export declare function isPromise(obj: any): obj is Promise<any>;
|
|
8
|
-
export declare function isRegExp(obj: any): obj is RegExp;
|
|
8
|
+
export declare function isRegExp(obj: any): obj is RegExp;
|
package/dist/is/type.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isRegExp = exports.isPromise = exports.isPlainObject = exports.isObject = exports.isFunction = exports.isArray = exports.isUndefined = exports.isString = void 0;
|
|
4
|
+
function isString(str) {
|
|
5
|
+
return typeof str === 'string';
|
|
6
|
+
}
|
|
7
|
+
exports.isString = isString;
|
|
8
|
+
function isUndefined(obj) {
|
|
9
|
+
return typeof obj === 'undefined';
|
|
10
|
+
}
|
|
11
|
+
exports.isUndefined = isUndefined;
|
|
12
|
+
function isArray(obj) {
|
|
13
|
+
return Array.isArray(obj);
|
|
14
|
+
}
|
|
15
|
+
exports.isArray = isArray;
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
17
|
+
function isFunction(func) {
|
|
18
|
+
return typeof func === 'function';
|
|
19
|
+
}
|
|
20
|
+
exports.isFunction = isFunction;
|
|
21
|
+
function isObject(obj) {
|
|
22
|
+
return obj !== null && typeof obj === 'object';
|
|
23
|
+
}
|
|
24
|
+
exports.isObject = isObject;
|
|
25
|
+
function isPlainObject(obj) {
|
|
26
|
+
return (isObject(obj) && Object.prototype.toString.call(obj) === '[object Object]');
|
|
27
|
+
}
|
|
28
|
+
exports.isPlainObject = isPlainObject;
|
|
29
|
+
function isPromise(obj) {
|
|
30
|
+
return (Boolean(obj) &&
|
|
31
|
+
(typeof obj === 'object' || typeof obj === 'function') &&
|
|
32
|
+
typeof obj.then === 'function');
|
|
33
|
+
}
|
|
34
|
+
exports.isPromise = isPromise;
|
|
35
|
+
function isRegExp(obj) {
|
|
36
|
+
return Object.prototype.toString.call(obj) === '[object RegExp]';
|
|
37
|
+
}
|
|
38
|
+
exports.isRegExp = isRegExp;
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Color } from '../compiled/chalk';
|
|
2
|
+
declare type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
3
|
+
interface LoggerConfiguration {
|
|
4
|
+
color?: typeof Color;
|
|
5
|
+
label?: string;
|
|
6
|
+
level?: LogLevel;
|
|
7
|
+
}
|
|
8
|
+
interface InstanceConfiguration {
|
|
9
|
+
displayLabel?: boolean;
|
|
10
|
+
underlineLabel?: boolean;
|
|
11
|
+
uppercaseLabel?: boolean;
|
|
12
|
+
}
|
|
13
|
+
interface ConstructorOptions {
|
|
14
|
+
config?: InstanceConfiguration;
|
|
15
|
+
types?: Record<string, LoggerConfiguration>;
|
|
16
|
+
}
|
|
17
|
+
declare type LoggerFunction = (message?: number | string | Error, ...args: any[]) => void;
|
|
18
|
+
declare const LOG_TYPES: {
|
|
19
|
+
error: {
|
|
20
|
+
color: string;
|
|
21
|
+
label: string;
|
|
22
|
+
level: string;
|
|
23
|
+
};
|
|
24
|
+
info: {
|
|
25
|
+
color: string;
|
|
26
|
+
label: string;
|
|
27
|
+
level: string;
|
|
28
|
+
};
|
|
29
|
+
warn: {
|
|
30
|
+
color: string;
|
|
31
|
+
label: string;
|
|
32
|
+
level: string;
|
|
33
|
+
};
|
|
34
|
+
debug: {
|
|
35
|
+
color: string;
|
|
36
|
+
label: string;
|
|
37
|
+
level: string;
|
|
38
|
+
};
|
|
39
|
+
log: {
|
|
40
|
+
level: string;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
declare class Logger {
|
|
44
|
+
private readonly logCount;
|
|
45
|
+
private history;
|
|
46
|
+
private readonly config;
|
|
47
|
+
private readonly types;
|
|
48
|
+
private readonly longestLabel;
|
|
49
|
+
[key: string]: any;
|
|
50
|
+
constructor(options?: ConstructorOptions);
|
|
51
|
+
private retainLog;
|
|
52
|
+
private _log;
|
|
53
|
+
private getLongestLabel;
|
|
54
|
+
private get longestUnderlinedLabel();
|
|
55
|
+
getRetainedLogs(type: string): string[];
|
|
56
|
+
clearRetainedLogs(type: string): void;
|
|
57
|
+
}
|
|
58
|
+
declare type LoggerInterface = {
|
|
59
|
+
[key in keyof typeof LOG_TYPES]: LoggerFunction;
|
|
60
|
+
};
|
|
61
|
+
declare const logger: Logger & LoggerInterface;
|
|
62
|
+
export { logger };
|
|
63
|
+
export type { LoggerInterface };
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.logger = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("../compiled/chalk"));
|
|
8
|
+
const { grey, underline } = chalk_1.default;
|
|
9
|
+
const LOG_TYPES = {
|
|
10
|
+
error: {
|
|
11
|
+
color: 'red',
|
|
12
|
+
label: 'error',
|
|
13
|
+
level: 'error',
|
|
14
|
+
},
|
|
15
|
+
info: {
|
|
16
|
+
color: 'blue',
|
|
17
|
+
label: 'info',
|
|
18
|
+
level: 'info',
|
|
19
|
+
},
|
|
20
|
+
warn: {
|
|
21
|
+
color: 'yellow',
|
|
22
|
+
label: 'warning',
|
|
23
|
+
level: 'warn',
|
|
24
|
+
},
|
|
25
|
+
debug: {
|
|
26
|
+
color: 'red',
|
|
27
|
+
label: 'debug',
|
|
28
|
+
level: 'debug',
|
|
29
|
+
},
|
|
30
|
+
log: { level: 'info' },
|
|
31
|
+
};
|
|
32
|
+
const DEFAULT_CONFIG = {
|
|
33
|
+
displayLabel: true,
|
|
34
|
+
underlineLabel: true,
|
|
35
|
+
uppercaseLabel: false,
|
|
36
|
+
};
|
|
37
|
+
class Logger {
|
|
38
|
+
constructor(options = {}) {
|
|
39
|
+
this.logCount = 200;
|
|
40
|
+
this.history = {};
|
|
41
|
+
this.config = Object.assign(Object.assign({}, DEFAULT_CONFIG), (options.config || {}));
|
|
42
|
+
this.types = Object.assign(Object.assign({}, LOG_TYPES), (options.types || {}));
|
|
43
|
+
this.longestLabel = this.getLongestLabel();
|
|
44
|
+
Object.keys(this.types).forEach(type => {
|
|
45
|
+
this[type] = this._log.bind(this, type);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
retainLog(type, message) {
|
|
49
|
+
if (!this.history[type]) {
|
|
50
|
+
this.history[type] = [];
|
|
51
|
+
}
|
|
52
|
+
this.history[type].push(message);
|
|
53
|
+
while (this.history[type].length > this.logCount) {
|
|
54
|
+
this.history[type].shift();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
_log(type, message) {
|
|
58
|
+
if (message === undefined) {
|
|
59
|
+
// eslint-disable-next-line no-console
|
|
60
|
+
console.log();
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
let label = '';
|
|
64
|
+
let text = '';
|
|
65
|
+
const logType = this.types[type];
|
|
66
|
+
if (this.config.displayLabel && logType.label) {
|
|
67
|
+
label = this.config.uppercaseLabel
|
|
68
|
+
? logType.label.toUpperCase()
|
|
69
|
+
: logType.label;
|
|
70
|
+
if (this.config.underlineLabel) {
|
|
71
|
+
label = underline(label).padEnd(this.longestUnderlinedLabel.length + 1);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
label = label.padEnd(this.longestLabel.length + 1);
|
|
75
|
+
}
|
|
76
|
+
label = logType.color ? chalk_1.default[logType.color](label) : label;
|
|
77
|
+
}
|
|
78
|
+
if (message instanceof Error) {
|
|
79
|
+
if (message.stack) {
|
|
80
|
+
const [name, ...rest] = message.stack.split('\n');
|
|
81
|
+
text = `${name}\n${grey(rest.join('\n'))}`;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
text = message.message;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
text = `${message}`;
|
|
89
|
+
}
|
|
90
|
+
// only retain logs of warn/error level
|
|
91
|
+
if (logType.level === 'warn' || logType.level === 'error') {
|
|
92
|
+
// retain log text without label
|
|
93
|
+
this.retainLog(type, text);
|
|
94
|
+
}
|
|
95
|
+
const log = label.length > 0 ? `${label} ${text}` : text;
|
|
96
|
+
// eslint-disable-next-line no-console
|
|
97
|
+
console.log(log);
|
|
98
|
+
}
|
|
99
|
+
getLongestLabel() {
|
|
100
|
+
let longestLabel = '';
|
|
101
|
+
Object.keys(this.types).forEach(type => {
|
|
102
|
+
const { label = '' } = this.types[type];
|
|
103
|
+
if (label.length > longestLabel.length) {
|
|
104
|
+
longestLabel = label;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
return longestLabel;
|
|
108
|
+
}
|
|
109
|
+
get longestUnderlinedLabel() {
|
|
110
|
+
return underline(this.longestLabel);
|
|
111
|
+
}
|
|
112
|
+
getRetainedLogs(type) {
|
|
113
|
+
return this.history[type] || [];
|
|
114
|
+
}
|
|
115
|
+
clearRetainedLogs(type) {
|
|
116
|
+
if (type) {
|
|
117
|
+
if (this.history[type]) {
|
|
118
|
+
this.history[type] = [];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
this.history = {};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const logger = new Logger();
|
|
127
|
+
exports.logger = logger;
|
|
128
|
+
logger.Logger = Logger;
|
|
@@ -6,6 +6,6 @@ export declare const isMonorepo: (root: string) => boolean;
|
|
|
6
6
|
export declare const isModernjsMonorepo: (root: string) => boolean;
|
|
7
7
|
export declare const findMonorepoRoot: (appDirectory: string, maxDepth?: number) => string | undefined;
|
|
8
8
|
export declare const getMonorepoPackages: (root: string) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}[];
|
|
9
|
+
name: string;
|
|
10
|
+
path: string;
|
|
11
|
+
}[];
|