@modern-js/utils 1.3.7-alpha.prebundle.0 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/constants.d.ts +13 -0
  3. package/dist/constants.js +14 -1
  4. package/dist/getServerConfig.d.ts +1 -0
  5. package/dist/{src/watch.js → getServerConfig.js} +8 -34
  6. package/dist/index.d.ts +2 -0
  7. package/dist/index.js +2 -0
  8. package/dist/ssrHelpers.d.ts +4 -0
  9. package/dist/ssrHelpers.js +7 -0
  10. package/dist/storage.d.ts +5 -0
  11. package/dist/storage.js +61 -0
  12. package/package.json +2 -2
  13. package/dist/compiled/upath/index.d.ts +0 -225
  14. package/dist/compiled/upath/index.js +0 -1
  15. package/dist/pkgUp.d.ts +0 -2
  16. package/dist/pkgUp.js +0 -8
  17. package/dist/src/FileSizeReporter.d.ts +0 -16
  18. package/dist/src/FileSizeReporter.js +0 -152
  19. package/dist/src/alias.d.ts +0 -21
  20. package/dist/src/alias.js +0 -62
  21. package/dist/src/applyOptionsChain.d.ts +0 -6
  22. package/dist/src/applyOptionsChain.js +0 -30
  23. package/dist/src/clearConsole.d.ts +0 -1
  24. package/dist/src/clearConsole.js +0 -9
  25. package/dist/src/compatRequire.d.ts +0 -8
  26. package/dist/src/compatRequire.js +0 -28
  27. package/dist/src/compiled.d.ts +0 -7
  28. package/dist/src/compiled.js +0 -19
  29. package/dist/src/constants.d.ts +0 -209
  30. package/dist/src/constants.js +0 -264
  31. package/dist/src/debug.d.ts +0 -7
  32. package/dist/src/debug.js +0 -14
  33. package/dist/src/emptyDir.d.ts +0 -1
  34. package/dist/src/emptyDir.js +0 -22
  35. package/dist/src/ensureAbsolutePath.d.ts +0 -7
  36. package/dist/src/ensureAbsolutePath.js +0 -15
  37. package/dist/src/findExists.d.ts +0 -6
  38. package/dist/src/findExists.js +0 -21
  39. package/dist/src/format.d.ts +0 -16
  40. package/dist/src/format.js +0 -115
  41. package/dist/src/generateMetaTags.d.ts +0 -16
  42. package/dist/src/generateMetaTags.js +0 -48
  43. package/dist/src/getBrowserslist.d.ts +0 -2
  44. package/dist/src/getBrowserslist.js +0 -7
  45. package/dist/src/getCacheIdentifier.d.ts +0 -7
  46. package/dist/src/getCacheIdentifier.js +0 -24
  47. package/dist/src/getEntryOptions.d.ts +0 -1
  48. package/dist/src/getEntryOptions.js +0 -26
  49. package/dist/src/getPackageManager.d.ts +0 -1
  50. package/dist/src/getPackageManager.js +0 -47
  51. package/dist/src/getPort.d.ts +0 -7
  52. package/dist/src/getPort.js +0 -62
  53. package/dist/src/import.d.ts +0 -5
  54. package/dist/src/import.js +0 -10
  55. package/dist/src/index.d.ts +0 -32
  56. package/dist/src/index.js +0 -57
  57. package/dist/src/is/index.d.ts +0 -34
  58. package/dist/src/is/index.js +0 -82
  59. package/dist/src/is/node-env.d.ts +0 -4
  60. package/dist/src/is/node-env.js +0 -12
  61. package/dist/src/is/platform.d.ts +0 -2
  62. package/dist/src/is/platform.js +0 -10
  63. package/dist/src/is/type.d.ts +0 -8
  64. package/dist/src/is/type.js +0 -38
  65. package/dist/src/logger.d.ts +0 -63
  66. package/dist/src/logger.js +0 -129
  67. package/dist/src/monorepo.d.ts +0 -11
  68. package/dist/src/monorepo.js +0 -81
  69. package/dist/src/nodeEnv.d.ts +0 -3
  70. package/dist/src/nodeEnv.js +0 -52
  71. package/dist/src/path.d.ts +0 -3
  72. package/dist/src/path.js +0 -14
  73. package/dist/src/prettyInstructions.d.ts +0 -6
  74. package/dist/src/prettyInstructions.js +0 -64
  75. package/dist/src/printBuildError.d.ts +0 -8
  76. package/dist/src/printBuildError.js +0 -43
  77. package/dist/src/readTsConfig.d.ts +0 -2
  78. package/dist/src/readTsConfig.js +0 -19
  79. package/dist/src/removeSlash.d.ts +0 -3
  80. package/dist/src/removeSlash.js +0 -9
  81. package/dist/src/runtimeExports.d.ts +0 -4
  82. package/dist/src/runtimeExports.js +0 -53
  83. package/dist/src/wait.d.ts +0 -2
  84. package/dist/src/wait.js +0 -7
  85. package/dist/src/watch.d.ts +0 -8
package/dist/src/debug.js DELETED
@@ -1,14 +0,0 @@
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.createDebugger = void 0;
7
- const debug_1 = __importDefault(require("debug"));
8
- /**
9
- * Create debug function with unified namespace prefix.
10
- * @param scope - Custom module name of your debug function.
11
- * @returns Debug function which namespace start with modern-js:.
12
- */
13
- const createDebugger = (scope) => (0, debug_1.default)(`modern-js:${scope}`);
14
- exports.createDebugger = createDebugger;
@@ -1 +0,0 @@
1
- export declare const emptyDir: (dir: string) => Promise<void>;
@@ -1,22 +0,0 @@
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.emptyDir = void 0;
16
- const fs_extra_1 = __importDefault(require("fs-extra"));
17
- const emptyDir = (dir) => __awaiter(void 0, void 0, void 0, function* () {
18
- if (yield fs_extra_1.default.pathExists(dir)) {
19
- yield fs_extra_1.default.emptyDir(dir);
20
- }
21
- });
22
- exports.emptyDir = emptyDir;
@@ -1,7 +0,0 @@
1
- /**
2
- * ensure absolute file path.
3
- * @param base - Base path to resolve relative from.
4
- * @param filePath - Aboluste or relative file path.
5
- * @returns Resolved absolute file path.
6
- */
7
- export declare const ensureAbsolutePath: (base: string, filePath: string) => string;
@@ -1,15 +0,0 @@
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.ensureAbsolutePath = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- /**
9
- * ensure absolute file path.
10
- * @param base - Base path to resolve relative from.
11
- * @param filePath - Aboluste or relative file path.
12
- * @returns Resolved absolute file path.
13
- */
14
- const ensureAbsolutePath = (base, filePath) => path_1.default.isAbsolute(filePath) ? filePath : path_1.default.resolve(base, filePath);
15
- exports.ensureAbsolutePath = ensureAbsolutePath;
@@ -1,6 +0,0 @@
1
- /**
2
- * Find first already exists file.
3
- * @param files - Asbolute file paths with extension.
4
- * @returns The file path if exists, or false if no file exists.
5
- */
6
- export declare const findExists: (files: string[]) => string | false;
@@ -1,21 +0,0 @@
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.findExists = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- /**
9
- * Find first already exists file.
10
- * @param files - Asbolute file paths with extension.
11
- * @returns The file path if exists, or false if no file exists.
12
- */
13
- const findExists = (files) => {
14
- for (const file of files) {
15
- if (fs_1.default.existsSync(file) && fs_1.default.statSync(file).isFile()) {
16
- return file;
17
- }
18
- }
19
- return false;
20
- };
21
- exports.findExists = findExists;
@@ -1,16 +0,0 @@
1
- /**
2
- * Copyright (c) 2015-present, Facebook, Inc.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file at
6
- * https://github.com/facebook/create-react-app/blob/master/LICENSE
7
- */
8
- import { StatsCompilation } from 'webpack';
9
- import type { ProxyDetail, BffProxyOptions } from '@modern-js/types';
10
- declare function formatWebpackMessages(json: StatsCompilation): {
11
- errors: string[];
12
- warnings: string[];
13
- };
14
- export { formatWebpackMessages };
15
- declare function formatProxyOptions(proxyOptions: BffProxyOptions): ProxyDetail[];
16
- export { formatProxyOptions };
@@ -1,115 +0,0 @@
1
- "use strict";
2
- /* eslint-disable no-param-reassign */
3
- /* eslint-disable max-statements */
4
- /**
5
- * Copyright (c) 2015-present, Facebook, Inc.
6
- *
7
- * This source code is licensed under the MIT license found in the
8
- * LICENSE file at
9
- * https://github.com/facebook/create-react-app/blob/master/LICENSE
10
- */
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.formatProxyOptions = exports.formatWebpackMessages = void 0;
13
- const friendlySyntaxErrorLabel = 'Syntax error:';
14
- function isLikelyASyntaxError(message) {
15
- return message.includes(friendlySyntaxErrorLabel);
16
- }
17
- // Cleans up webpack error messages.
18
- function formatMessage(message) {
19
- var _a;
20
- let lines = [];
21
- // webpack 5 stats error object
22
- if (typeof message === 'object') {
23
- message = `${(message.moduleName && `${message.moduleName}\n`)}${message.details || message.stack || message.message}`;
24
- }
25
- lines = message.split('\n');
26
- // Strip webpack-added headers off errors/warnings
27
- // https://github.com/webpack/webpack/blob/master/lib/ModuleError.js
28
- lines = lines.filter(line => !/Module [A-z ]+\(from/.test(line));
29
- // Transform parsing error into syntax error
30
- lines = lines.map(line => {
31
- const parsingError = /Line (\d+):(?:(\d+):)?\s*Parsing error: (.+)$/.exec(line);
32
- if (!parsingError) {
33
- return line;
34
- }
35
- const [, errorLine, errorColumn, errorMessage] = parsingError;
36
- return `${friendlySyntaxErrorLabel} ${errorMessage} (${errorLine}:${errorColumn})`;
37
- });
38
- message = lines.join('\n');
39
- // Smoosh syntax errors (commonly found in CSS)
40
- message = message.replace(/SyntaxError\s+\((\d+):(\d+)\)\s*(.+?)\n/g, `${friendlySyntaxErrorLabel} $3 ($1:$2)\n`);
41
- lines = message.split('\n');
42
- // Remove leading newline
43
- if (lines.length > 2 && lines[1].trim() === '') {
44
- lines.splice(1, 1);
45
- }
46
- // Clean up file name
47
- lines[0] = lines[0].replace(/^(.*) \d+:\d+-\d+$/, '$1');
48
- // Cleans up verbose "module not found" messages for files and packages.
49
- if ((_a = lines[1]) === null || _a === void 0 ? void 0 : _a.startsWith('Module not found: ')) {
50
- lines = [
51
- lines[0],
52
- lines[1]
53
- .replace('Error: ', '')
54
- .replace('Module not found: Cannot find file:', 'Cannot find file:')
55
- .replace('[CaseSensitivePathsPlugin] ', '')
56
- .replace("Cannot resolve 'file' or 'directory' ", ''),
57
- ];
58
- }
59
- message = lines.join('\n');
60
- // Internal stacks are generally useless so we strip them... with the
61
- // exception of stacks containing `webpack:` because they're normally
62
- // from user code generated by webpack. For more information see
63
- // https://github.com/facebook/create-react-app/pull/1050
64
- message = message.replace(/^\s*at\s((?!webpack:).)*:\d+:\d+[\s)]*(\n|$)/gm, ''); // at ... ...:x:y
65
- message = message.replace(/^\s*at\s<anonymous>(\n|$)/gm, ''); // at <anonymous>
66
- lines = message.split('\n');
67
- // Remove duplicated newlines
68
- lines = lines.filter((line, index, arr) => index === 0 ||
69
- line.trim() !== '' ||
70
- line.trim() !== arr[index - 1].trim());
71
- // Reassemble the message
72
- message = lines.join('\n');
73
- return message.trim();
74
- }
75
- function formatWebpackMessages(json) {
76
- var _a, _b, _c;
77
- const formattedErrors = (_a = json.errors) === null || _a === void 0 ? void 0 : _a.map(formatMessage);
78
- const formattedWarnings = (_b = json.warnings) === null || _b === void 0 ? void 0 : _b.map(formatMessage);
79
- const result = {
80
- errors: formattedErrors || [],
81
- warnings: formattedWarnings || [],
82
- };
83
- if ((_c = result.errors) === null || _c === void 0 ? void 0 : _c.some(isLikelyASyntaxError)) {
84
- // If there are any syntax errors, show just them.
85
- result.errors = result.errors.filter(isLikelyASyntaxError);
86
- }
87
- // First error is usually it.
88
- if (result.errors.length > 1) {
89
- result.errors.length = 1;
90
- }
91
- return result;
92
- }
93
- exports.formatWebpackMessages = formatWebpackMessages;
94
- /* eslint-enable max-statements */
95
- /* eslint-enable no-param-reassign */
96
- function formatProxyOptions(proxyOptions) {
97
- const formatedProxy = [];
98
- if (!Array.isArray(proxyOptions)) {
99
- if ('target' in proxyOptions) {
100
- formatedProxy.push(proxyOptions);
101
- }
102
- else {
103
- Array.prototype.push.apply(formatedProxy, Object.keys(proxyOptions).reduce((total, source) => {
104
- const option = proxyOptions[source];
105
- total.push(Object.assign({ context: source, changeOrigin: true, logLevel: 'warn' }, (typeof option === 'string' ? { target: option } : option)));
106
- return total;
107
- }, []));
108
- }
109
- }
110
- else {
111
- formatedProxy.push(...proxyOptions);
112
- }
113
- return formatedProxy;
114
- }
115
- exports.formatProxyOptions = formatProxyOptions;
@@ -1,16 +0,0 @@
1
- /**
2
- * Copyright JS Foundation and other contributors.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file at
6
- * https://github.com/jantimon/html-webpack-plugin/blob/main/LICENSE
7
- *
8
- * Modified from https://github.com/jantimon/html-webpack-plugin/blob/2f5de7ab9e8bca60e9e200f2e4b4cfab90db28d4/index.js#L800
9
- */
10
- export declare type MetaAttributes = {
11
- [attributeName: string]: string | boolean;
12
- };
13
- export interface MetaOptions {
14
- [name: string]: string | false | MetaAttributes;
15
- }
16
- export declare const generateMetaTags: (metaOptions?: MetaOptions | undefined) => string;
@@ -1,48 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateMetaTags = void 0;
4
- const tagObjectToString = (tagDefinition) => {
5
- const attributes = Object.keys(tagDefinition.attributes || {})
6
- .filter(attributeName => tagDefinition.attributes[attributeName] !== false)
7
- .map(attributeName => {
8
- if (tagDefinition.attributes[attributeName] === true) {
9
- return attributeName;
10
- }
11
- return `${attributeName}="${tagDefinition.attributes[attributeName]}"`;
12
- });
13
- return `<${[tagDefinition.tagName].concat(attributes).join(' ')}>${tagDefinition.innerHTML || ''}${tagDefinition.voidTag ? '' : `</${tagDefinition.tagName}>`}`;
14
- };
15
- const generateMetaTags = (metaOptions) => {
16
- if (!metaOptions) {
17
- return '';
18
- }
19
- // Make tags self-closing in case of xhtml
20
- // Turn { "viewport" : "width=500, initial-scale=1" } into
21
- // [{ name:"viewport" content:"width=500, initial-scale=1" }]
22
- const metaTagAttributeObjects = Object.keys(metaOptions)
23
- .map(metaName => {
24
- const metaTagContent = metaOptions[metaName];
25
- return typeof metaTagContent === 'string'
26
- ? {
27
- name: metaName,
28
- content: metaTagContent,
29
- }
30
- : metaTagContent;
31
- })
32
- .filter(attribute => attribute !== false);
33
- // Turn [{ name:"viewport" content:"width=500, initial-scale=1" }] into
34
- // the html-webpack-plugin tag structure
35
- return metaTagAttributeObjects
36
- .map(metaTagAttributes => {
37
- if (metaTagAttributes === false) {
38
- throw new Error('Invalid meta tag');
39
- }
40
- return {
41
- tagName: 'meta',
42
- voidTag: true,
43
- attributes: metaTagAttributes,
44
- };
45
- })
46
- .reduce((memo, tagObject) => `${memo}\n${tagObjectToString(tagObject)}`, '');
47
- };
48
- exports.generateMetaTags = generateMetaTags;
@@ -1,2 +0,0 @@
1
- export declare const defaults: string[];
2
- export declare const getBrowserslist: (appDirectory: string) => string[];
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getBrowserslist = exports.defaults = void 0;
4
- const browserslist_1 = require("browserslist");
5
- exports.defaults = ['> 0.01%', 'not dead', 'not op_mini all'];
6
- const getBrowserslist = (appDirectory) => (0, browserslist_1.loadConfig)({ path: appDirectory }) || exports.defaults;
7
- exports.getBrowserslist = getBrowserslist;
@@ -1,7 +0,0 @@
1
- /**
2
- * Generate cache identifier from some packages and config files.
3
- */
4
- export declare function getCacheIdentifier(packages: {
5
- name: string;
6
- version: string;
7
- }[], _files?: string[]): string;
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCacheIdentifier = void 0;
4
- const is_1 = require("./is");
5
- /**
6
- * Generate cache identifier from some packages and config files.
7
- */
8
- function getCacheIdentifier(packages, _files) {
9
- /* eslint-disable no-nested-ternary */
10
- let cacheIdentifier = (0, is_1.isProd)()
11
- ? 'production'
12
- : (0, is_1.isDev)()
13
- ? 'development'
14
- : (0, is_1.isTest)()
15
- ? 'test'
16
- : '';
17
- /* eslint-enable no-nested-ternary */
18
- for (const { name, version } of packages) {
19
- cacheIdentifier += `:${name}@${version}`;
20
- }
21
- // TODO: config file hash
22
- return cacheIdentifier;
23
- }
24
- exports.getCacheIdentifier = getCacheIdentifier;
@@ -1 +0,0 @@
1
- export declare const getEntryOptions: <T>(name: string, baseOptions?: T | undefined, optionsByEntries?: Record<string, T> | undefined, packageName?: string | undefined) => T | undefined;
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getEntryOptions = void 0;
4
- const is_1 = require("./is");
5
- const constants_1 = require("./constants");
6
- const getEntryOptions = (name, baseOptions, optionsByEntries, packageName) => {
7
- if (optionsByEntries) {
8
- let optionsByEntry = getOptionsByEntryName(name, optionsByEntries);
9
- // compatible with main entry using packageName as the key
10
- if (optionsByEntry === undefined &&
11
- name === constants_1.MAIN_ENTRY_NAME &&
12
- packageName) {
13
- optionsByEntry = getOptionsByEntryName(packageName, optionsByEntries);
14
- }
15
- // eslint-disable-next-line no-nested-ternary
16
- return optionsByEntry !== undefined
17
- ? (0, is_1.isPlainObject)(optionsByEntry) && (0, is_1.isPlainObject)(baseOptions)
18
- ? Object.assign(Object.assign({}, baseOptions), optionsByEntry) : optionsByEntry
19
- : baseOptions;
20
- }
21
- else {
22
- return baseOptions;
23
- }
24
- };
25
- exports.getEntryOptions = getEntryOptions;
26
- const getOptionsByEntryName = (name, optionsByEntries) => optionsByEntries.hasOwnProperty(name) ? optionsByEntries[name] : undefined;
@@ -1 +0,0 @@
1
- export declare function getPackageManager(cwd?: string): Promise<"npm" | "yarn" | "pnpm">;
@@ -1,47 +0,0 @@
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 fs_extra_1 = __importDefault(require("fs-extra"));
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 (fs_extra_1.default.existsSync(path_1.default.resolve(appDirectory, 'pnpm-lock.yaml'))) {
28
- return 'pnpm';
29
- }
30
- if (fs_extra_1.default.existsSync(path_1.default.resolve(appDirectory, 'yarn.lock'))) {
31
- return 'yarn';
32
- }
33
- if (fs_extra_1.default.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;
@@ -1,7 +0,0 @@
1
- /**
2
- * Get available free port.
3
- * @param port - Current port want to use.
4
- * @param tryLimits - Maximum number of retries.
5
- * @returns Available port number.
6
- */
7
- export declare const getPort: (port: string | number, tryLimits?: number) => Promise<number>;
@@ -1,62 +0,0 @@
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 */
@@ -1,5 +0,0 @@
1
- declare const lazy: (moduleName: string, requireFn: (id: string) => unknown) => any;
2
- export { lazy as lazyImport };
3
- export declare const Import: {
4
- lazy: (moduleName: string, requireFn: (id: string) => unknown) => any;
5
- };
@@ -1,10 +0,0 @@
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,32 +0,0 @@
1
- export * as fs from 'fs-extra';
2
- export * from './compiled';
3
- export * from './format';
4
- export * from './FileSizeReporter';
5
- export * from './printBuildError';
6
- export * from './debug';
7
- export * from './findExists';
8
- export * from './is';
9
- export * from './compatRequire';
10
- export * from './logger';
11
- export * from './constants';
12
- export * from './ensureAbsolutePath';
13
- export * from './getCacheIdentifier';
14
- export * from './clearConsole';
15
- export * from './applyOptionsChain';
16
- export * from './getBrowserslist';
17
- export * from './removeSlash';
18
- export * from './getEntryOptions';
19
- export * from './getPort';
20
- export * from './monorepo';
21
- export * from './getPackageManager';
22
- export * from './runtimeExports';
23
- export * from './readTsConfig';
24
- export * from './path';
25
- export * from './generateMetaTags';
26
- export * from './prettyInstructions';
27
- export * from './alias';
28
- export * from './import';
29
- export * from './watch';
30
- export * from './nodeEnv';
31
- export * from './wait';
32
- export * from './emptyDir';
package/dist/src/index.js DELETED
@@ -1,57 +0,0 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
22
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
23
- };
24
- Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.fs = void 0;
26
- exports.fs = __importStar(require("fs-extra"));
27
- __exportStar(require("./compiled"), exports);
28
- __exportStar(require("./format"), exports);
29
- __exportStar(require("./FileSizeReporter"), exports);
30
- __exportStar(require("./printBuildError"), exports);
31
- __exportStar(require("./debug"), exports);
32
- __exportStar(require("./findExists"), exports);
33
- __exportStar(require("./is"), exports);
34
- __exportStar(require("./compatRequire"), exports);
35
- __exportStar(require("./logger"), exports);
36
- __exportStar(require("./constants"), exports);
37
- __exportStar(require("./ensureAbsolutePath"), exports);
38
- __exportStar(require("./getCacheIdentifier"), exports);
39
- __exportStar(require("./clearConsole"), exports);
40
- __exportStar(require("./applyOptionsChain"), exports);
41
- __exportStar(require("./getBrowserslist"), exports);
42
- __exportStar(require("./removeSlash"), exports);
43
- __exportStar(require("./getEntryOptions"), exports);
44
- __exportStar(require("./getPort"), exports);
45
- __exportStar(require("./monorepo"), exports);
46
- __exportStar(require("./getPackageManager"), exports);
47
- __exportStar(require("./runtimeExports"), exports);
48
- __exportStar(require("./readTsConfig"), exports);
49
- __exportStar(require("./path"), exports);
50
- __exportStar(require("./generateMetaTags"), exports);
51
- __exportStar(require("./prettyInstructions"), exports);
52
- __exportStar(require("./alias"), exports);
53
- __exportStar(require("./import"), exports);
54
- __exportStar(require("./watch"), exports);
55
- __exportStar(require("./nodeEnv"), exports);
56
- __exportStar(require("./wait"), exports);
57
- __exportStar(require("./emptyDir"), exports);
@@ -1,34 +0,0 @@
1
- /**
2
- * Check if the package name is in dependencies or devDependencies.
3
- *
4
- * @param appDirectory - Project root directory.
5
- * @param name - Package name.
6
- * @returns True if the name is in dependencies or devDependencies, false otherwise.
7
- */
8
- export declare const isDepExists: (appDirectory: string, name: string) => boolean;
9
- /**
10
- * Is typescript project.
11
- *
12
- * @param root - App directory.
13
- * @returns Whether to use typescript.
14
- */
15
- export declare const isTypescript: (root: string) => boolean;
16
- /**
17
- * Is Empty object
18
- *
19
- * @param o - Any object.
20
- * @returns Whether it is empty object.
21
- */
22
- export declare const isEmpty: (o: Record<string, unknown>) => boolean;
23
- /**
24
- * Is SSR project
25
- *
26
- * @param config - User config.
27
- * @returns Whether to use server side render.
28
- */
29
- export declare const isSSR: (config: any) => boolean;
30
- export declare const isUseSSRBundle: (config: any) => boolean;
31
- export declare const isFastRefresh: () => boolean;
32
- export * from './node-env';
33
- export * from './platform';
34
- export * from './type';