@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.
- package/CHANGELOG.md +20 -0
- package/dist/constants.d.ts +13 -0
- package/dist/constants.js +14 -1
- package/dist/getServerConfig.d.ts +1 -0
- package/dist/{src/watch.js → getServerConfig.js} +8 -34
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -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/package.json +2 -2
- package/dist/compiled/upath/index.d.ts +0 -225
- package/dist/compiled/upath/index.js +0 -1
- package/dist/pkgUp.d.ts +0 -2
- package/dist/pkgUp.js +0 -8
- package/dist/src/FileSizeReporter.d.ts +0 -16
- package/dist/src/FileSizeReporter.js +0 -152
- package/dist/src/alias.d.ts +0 -21
- package/dist/src/alias.js +0 -62
- package/dist/src/applyOptionsChain.d.ts +0 -6
- package/dist/src/applyOptionsChain.js +0 -30
- package/dist/src/clearConsole.d.ts +0 -1
- package/dist/src/clearConsole.js +0 -9
- package/dist/src/compatRequire.d.ts +0 -8
- package/dist/src/compatRequire.js +0 -28
- package/dist/src/compiled.d.ts +0 -7
- package/dist/src/compiled.js +0 -19
- package/dist/src/constants.d.ts +0 -209
- package/dist/src/constants.js +0 -264
- package/dist/src/debug.d.ts +0 -7
- package/dist/src/debug.js +0 -14
- package/dist/src/emptyDir.d.ts +0 -1
- package/dist/src/emptyDir.js +0 -22
- package/dist/src/ensureAbsolutePath.d.ts +0 -7
- package/dist/src/ensureAbsolutePath.js +0 -15
- package/dist/src/findExists.d.ts +0 -6
- package/dist/src/findExists.js +0 -21
- package/dist/src/format.d.ts +0 -16
- package/dist/src/format.js +0 -115
- package/dist/src/generateMetaTags.d.ts +0 -16
- package/dist/src/generateMetaTags.js +0 -48
- package/dist/src/getBrowserslist.d.ts +0 -2
- package/dist/src/getBrowserslist.js +0 -7
- package/dist/src/getCacheIdentifier.d.ts +0 -7
- package/dist/src/getCacheIdentifier.js +0 -24
- package/dist/src/getEntryOptions.d.ts +0 -1
- package/dist/src/getEntryOptions.js +0 -26
- package/dist/src/getPackageManager.d.ts +0 -1
- package/dist/src/getPackageManager.js +0 -47
- package/dist/src/getPort.d.ts +0 -7
- package/dist/src/getPort.js +0 -62
- package/dist/src/import.d.ts +0 -5
- package/dist/src/import.js +0 -10
- package/dist/src/index.d.ts +0 -32
- package/dist/src/index.js +0 -57
- package/dist/src/is/index.d.ts +0 -34
- package/dist/src/is/index.js +0 -82
- package/dist/src/is/node-env.d.ts +0 -4
- package/dist/src/is/node-env.js +0 -12
- package/dist/src/is/platform.d.ts +0 -2
- package/dist/src/is/platform.js +0 -10
- package/dist/src/is/type.d.ts +0 -8
- package/dist/src/is/type.js +0 -38
- package/dist/src/logger.d.ts +0 -63
- package/dist/src/logger.js +0 -129
- package/dist/src/monorepo.d.ts +0 -11
- package/dist/src/monorepo.js +0 -81
- package/dist/src/nodeEnv.d.ts +0 -3
- package/dist/src/nodeEnv.js +0 -52
- package/dist/src/path.d.ts +0 -3
- package/dist/src/path.js +0 -14
- package/dist/src/prettyInstructions.d.ts +0 -6
- package/dist/src/prettyInstructions.js +0 -64
- package/dist/src/printBuildError.d.ts +0 -8
- package/dist/src/printBuildError.js +0 -43
- package/dist/src/readTsConfig.d.ts +0 -2
- package/dist/src/readTsConfig.js +0 -19
- package/dist/src/removeSlash.d.ts +0 -3
- package/dist/src/removeSlash.js +0 -9
- package/dist/src/runtimeExports.d.ts +0 -4
- package/dist/src/runtimeExports.js +0 -53
- package/dist/src/wait.d.ts +0 -2
- package/dist/src/wait.js +0 -7
- package/dist/src/watch.d.ts +0 -8
package/dist/src/is/index.js
DELETED
@@ -1,82 +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 __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);
|
package/dist/src/is/node-env.js
DELETED
@@ -1,12 +0,0 @@
|
|
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;
|
package/dist/src/is/platform.js
DELETED
@@ -1,10 +0,0 @@
|
|
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;
|
package/dist/src/is/type.d.ts
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
export declare function isString(str: any): str is string;
|
2
|
-
export declare function isUndefined(obj: any): obj is undefined;
|
3
|
-
export declare function isArray(obj: unknown): obj is any[];
|
4
|
-
export declare function isFunction(func: any): func is Function;
|
5
|
-
export declare function isObject(obj: unknown): obj is Record<string, any>;
|
6
|
-
export declare function isPlainObject(obj: unknown): obj is Record<string, any>;
|
7
|
-
export declare function isPromise(obj: any): obj is Promise<any>;
|
8
|
-
export declare function isRegExp(obj: any): obj is RegExp;
|
package/dist/src/is/type.js
DELETED
@@ -1,38 +0,0 @@
|
|
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/src/logger.d.ts
DELETED
@@ -1,63 +0,0 @@
|
|
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/src/logger.js
DELETED
@@ -1,129 +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.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
|
-
// eslint-disable-next-line max-statements
|
58
|
-
_log(type, message) {
|
59
|
-
if (message === undefined) {
|
60
|
-
// eslint-disable-next-line no-console
|
61
|
-
console.log();
|
62
|
-
return;
|
63
|
-
}
|
64
|
-
let label = '';
|
65
|
-
let text = '';
|
66
|
-
const logType = this.types[type];
|
67
|
-
if (this.config.displayLabel && logType.label) {
|
68
|
-
label = this.config.uppercaseLabel
|
69
|
-
? logType.label.toUpperCase()
|
70
|
-
: logType.label;
|
71
|
-
if (this.config.underlineLabel) {
|
72
|
-
label = underline(label).padEnd(this.longestUnderlinedLabel.length + 1);
|
73
|
-
}
|
74
|
-
else {
|
75
|
-
label = label.padEnd(this.longestLabel.length + 1);
|
76
|
-
}
|
77
|
-
label = logType.color ? chalk_1.default[logType.color](label) : label;
|
78
|
-
}
|
79
|
-
if (message instanceof Error) {
|
80
|
-
if (message.stack) {
|
81
|
-
const [name, ...rest] = message.stack.split('\n');
|
82
|
-
text = `${name}\n${grey(rest.join('\n'))}`;
|
83
|
-
}
|
84
|
-
else {
|
85
|
-
text = message.message;
|
86
|
-
}
|
87
|
-
}
|
88
|
-
else {
|
89
|
-
text = `${message}`;
|
90
|
-
}
|
91
|
-
// only retain logs of warn/error level
|
92
|
-
if (logType.level === 'warn' || logType.level === 'error') {
|
93
|
-
// retain log text without label
|
94
|
-
this.retainLog(type, text);
|
95
|
-
}
|
96
|
-
const log = label.length > 0 ? `${label} ${text}` : text;
|
97
|
-
// eslint-disable-next-line no-console
|
98
|
-
console.log(log);
|
99
|
-
}
|
100
|
-
getLongestLabel() {
|
101
|
-
let longestLabel = '';
|
102
|
-
Object.keys(this.types).forEach(type => {
|
103
|
-
const { label = '' } = this.types[type];
|
104
|
-
if (label.length > longestLabel.length) {
|
105
|
-
longestLabel = label;
|
106
|
-
}
|
107
|
-
});
|
108
|
-
return longestLabel;
|
109
|
-
}
|
110
|
-
get longestUnderlinedLabel() {
|
111
|
-
return underline(this.longestLabel);
|
112
|
-
}
|
113
|
-
getRetainedLogs(type) {
|
114
|
-
return this.history[type] || [];
|
115
|
-
}
|
116
|
-
clearRetainedLogs(type) {
|
117
|
-
if (type) {
|
118
|
-
if (this.history[type]) {
|
119
|
-
this.history[type] = [];
|
120
|
-
}
|
121
|
-
}
|
122
|
-
else {
|
123
|
-
this.history = {};
|
124
|
-
}
|
125
|
-
}
|
126
|
-
}
|
127
|
-
const logger = new Logger();
|
128
|
-
exports.logger = logger;
|
129
|
-
logger.Logger = Logger;
|
package/dist/src/monorepo.d.ts
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
import path from 'path';
|
2
|
-
export declare const isLerna: (root: string) => boolean;
|
3
|
-
export declare const isYarnWorkspaces: (root: string) => boolean;
|
4
|
-
export declare const isPnpmWorkspaces: (root: string) => boolean;
|
5
|
-
export declare const isMonorepo: (root: string) => boolean;
|
6
|
-
export declare const isModernjsMonorepo: (root: string) => boolean;
|
7
|
-
export declare const findMonorepoRoot: (appDirectory: string, maxDepth?: number) => string | undefined;
|
8
|
-
export declare const getMonorepoPackages: (root: string) => {
|
9
|
-
name: string;
|
10
|
-
path: string;
|
11
|
-
}[];
|
package/dist/src/monorepo.js
DELETED
@@ -1,81 +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.getMonorepoPackages = exports.findMonorepoRoot = exports.isModernjsMonorepo = exports.isMonorepo = exports.isPnpmWorkspaces = exports.isYarnWorkspaces = exports.isLerna = void 0;
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
8
|
-
const path_1 = __importDefault(require("path"));
|
9
|
-
const glob_1 = __importDefault(require("glob"));
|
10
|
-
const yaml_1 = __importDefault(require("yaml"));
|
11
|
-
const PACKAGE_MAX_DEPTH = 5;
|
12
|
-
const WOKRSPACES_FILES = {
|
13
|
-
YARN: 'package.json',
|
14
|
-
PNPM: 'pnpm-workspaces.yaml',
|
15
|
-
LERNA: 'lerna.json',
|
16
|
-
};
|
17
|
-
const isLerna = (root) => fs_1.default.existsSync(path_1.default.join(root, WOKRSPACES_FILES.LERNA));
|
18
|
-
exports.isLerna = isLerna;
|
19
|
-
const isYarnWorkspaces = (root) => {
|
20
|
-
var _a;
|
21
|
-
const pkg = path_1.default.join(root, WOKRSPACES_FILES.YARN);
|
22
|
-
if (!fs_1.default.existsSync(pkg)) {
|
23
|
-
return false;
|
24
|
-
}
|
25
|
-
const json = JSON.parse(fs_1.default.readFileSync(pkg, 'utf8'));
|
26
|
-
return Boolean((_a = json.workspaces) === null || _a === void 0 ? void 0 : _a.packages);
|
27
|
-
};
|
28
|
-
exports.isYarnWorkspaces = isYarnWorkspaces;
|
29
|
-
const isPnpmWorkspaces = (root) => fs_1.default.existsSync(path_1.default.join(root, WOKRSPACES_FILES.PNPM));
|
30
|
-
exports.isPnpmWorkspaces = isPnpmWorkspaces;
|
31
|
-
const isMonorepo = (root) => (0, exports.isLerna)(root) || (0, exports.isYarnWorkspaces)(root) || (0, exports.isPnpmWorkspaces)(root);
|
32
|
-
exports.isMonorepo = isMonorepo;
|
33
|
-
const isModernjsMonorepo = (root) => {
|
34
|
-
const json = JSON.parse(fs_1.default.readFileSync(path_1.default.join(root, 'package.json'), 'utf8'));
|
35
|
-
const deps = Object.assign(Object.assign({}, (json.dependencies || {})), (json.devDependencies || {}));
|
36
|
-
return Boolean(deps['@modern-js/monorepo-tools']);
|
37
|
-
};
|
38
|
-
exports.isModernjsMonorepo = isModernjsMonorepo;
|
39
|
-
const findMonorepoRoot = (appDirectory, maxDepth = PACKAGE_MAX_DEPTH) => {
|
40
|
-
let inMonorepo = false;
|
41
|
-
for (let depth = 0; depth < maxDepth; depth++) {
|
42
|
-
if ((0, exports.isMonorepo)(appDirectory)) {
|
43
|
-
inMonorepo = true;
|
44
|
-
break;
|
45
|
-
}
|
46
|
-
// eslint-disable-next-line no-param-reassign
|
47
|
-
appDirectory = path_1.default.dirname(appDirectory);
|
48
|
-
}
|
49
|
-
return inMonorepo ? appDirectory : undefined;
|
50
|
-
};
|
51
|
-
exports.findMonorepoRoot = findMonorepoRoot;
|
52
|
-
const getMonorepoPackages = (root) => {
|
53
|
-
let packages = [];
|
54
|
-
if ((0, exports.isYarnWorkspaces)(root)) {
|
55
|
-
const json = JSON.parse(fs_1.default.readFileSync(path_1.default.join(root, 'package.json'), 'utf8'));
|
56
|
-
({ packages } = json.workspaces);
|
57
|
-
}
|
58
|
-
else if ((0, exports.isLerna)(root)) {
|
59
|
-
const json = JSON.parse(fs_1.default.readFileSync(path_1.default.resolve(root, 'lerna.json'), 'utf8'));
|
60
|
-
({ packages } = json);
|
61
|
-
}
|
62
|
-
else {
|
63
|
-
({ packages } = yaml_1.default.parse(fs_1.default.readFileSync(path_1.default.join(root, WOKRSPACES_FILES.PNPM), 'utf8')));
|
64
|
-
}
|
65
|
-
if (packages) {
|
66
|
-
return packages
|
67
|
-
.map(name =>
|
68
|
-
// The trailing / ensures only dirs are picked up
|
69
|
-
glob_1.default.sync(path_1.default.join(root, `${name}/`), {
|
70
|
-
ignore: ['**/node_modules/**'],
|
71
|
-
}))
|
72
|
-
.reduce((acc, val) => acc.concat(val), [])
|
73
|
-
.filter(filepath => fs_1.default.existsSync(path_1.default.resolve(filepath, 'package.json')))
|
74
|
-
.map(filepath => ({
|
75
|
-
path: filepath,
|
76
|
-
name: JSON.parse(fs_1.default.readFileSync(path_1.default.resolve(filepath, 'package.json'), 'utf8')).name,
|
77
|
-
}));
|
78
|
-
}
|
79
|
-
return [];
|
80
|
-
};
|
81
|
-
exports.getMonorepoPackages = getMonorepoPackages;
|
package/dist/src/nodeEnv.d.ts
DELETED
package/dist/src/nodeEnv.js
DELETED
@@ -1,52 +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.canUsePnpm = exports.canUseYarn = exports.canUseNpm = void 0;
|
16
|
-
const execa_1 = __importDefault(require("execa"));
|
17
|
-
function canUseNpm() {
|
18
|
-
return __awaiter(this, void 0, void 0, function* () {
|
19
|
-
try {
|
20
|
-
yield (0, execa_1.default)('npm', ['--version'], { env: process.env });
|
21
|
-
return true;
|
22
|
-
}
|
23
|
-
catch (e) {
|
24
|
-
return false;
|
25
|
-
}
|
26
|
-
});
|
27
|
-
}
|
28
|
-
exports.canUseNpm = canUseNpm;
|
29
|
-
function canUseYarn() {
|
30
|
-
return __awaiter(this, void 0, void 0, function* () {
|
31
|
-
try {
|
32
|
-
yield (0, execa_1.default)('yarn', ['--version'], { env: process.env });
|
33
|
-
return true;
|
34
|
-
}
|
35
|
-
catch (e) {
|
36
|
-
return false;
|
37
|
-
}
|
38
|
-
});
|
39
|
-
}
|
40
|
-
exports.canUseYarn = canUseYarn;
|
41
|
-
function canUsePnpm() {
|
42
|
-
return __awaiter(this, void 0, void 0, function* () {
|
43
|
-
try {
|
44
|
-
yield (0, execa_1.default)('pnpm', ['--version'], { env: process.env });
|
45
|
-
return true;
|
46
|
-
}
|
47
|
-
catch (e) {
|
48
|
-
return false;
|
49
|
-
}
|
50
|
-
});
|
51
|
-
}
|
52
|
-
exports.canUsePnpm = canUsePnpm;
|
package/dist/src/path.d.ts
DELETED
package/dist/src/path.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.normalizeToPosixPath = exports.normalizeOutputPath = exports.isRelativePath = void 0;
|
7
|
-
const path_1 = __importDefault(require("path"));
|
8
|
-
const upath_1 = __importDefault(require("upath"));
|
9
|
-
const isRelativePath = (test) => /^\.\.?($|[\\/])/.test(test);
|
10
|
-
exports.isRelativePath = isRelativePath;
|
11
|
-
const normalizeOutputPath = (s) => s.replace(/\\/g, '\\\\');
|
12
|
-
exports.normalizeOutputPath = normalizeOutputPath;
|
13
|
-
const normalizeToPosixPath = (p) => upath_1.default.normalizeSafe(path_1.default.normalize(p));
|
14
|
-
exports.normalizeToPosixPath = normalizeToPosixPath;
|
@@ -1,64 +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.prettyInstructions = exports.isSingleEntry = void 0;
|
7
|
-
const os_1 = __importDefault(require("os"));
|
8
|
-
const compiled_1 = require("./compiled");
|
9
|
-
const is_1 = require("./is");
|
10
|
-
// TODO: remove hard code 'main'
|
11
|
-
const isSingleEntry = (entrypoints) => entrypoints.length === 1 && entrypoints[0].entryName === 'main';
|
12
|
-
exports.isSingleEntry = isSingleEntry;
|
13
|
-
const normalizeUrl = (url) => url.replace(/([^:]\/)\/+/g, '$1');
|
14
|
-
const getAddressUrls = (protocol = 'http', port) => {
|
15
|
-
const interfaces = os_1.default.networkInterfaces();
|
16
|
-
const ipv4Interfaces = [];
|
17
|
-
Object.keys(interfaces).forEach(key => {
|
18
|
-
interfaces[key].forEach(detail => {
|
19
|
-
if (detail.family === 'IPv4') {
|
20
|
-
ipv4Interfaces.push(detail);
|
21
|
-
}
|
22
|
-
});
|
23
|
-
});
|
24
|
-
return ipv4Interfaces.reduce((memo, detail) => {
|
25
|
-
let type = 'Network: ';
|
26
|
-
let url = `${protocol}://${detail.address}:${port}`;
|
27
|
-
if (detail.address.includes(`localhost`)) {
|
28
|
-
type = 'Local: ';
|
29
|
-
url = `${protocol}://localhost:${port}`;
|
30
|
-
}
|
31
|
-
memo.push({ type, url });
|
32
|
-
return memo;
|
33
|
-
}, []);
|
34
|
-
};
|
35
|
-
const prettyInstructions = (appContext, config) => {
|
36
|
-
const { entrypoints, serverRoutes, port, existSrc, checkedEntries } = appContext;
|
37
|
-
const urls = getAddressUrls(config.dev.https && (0, is_1.isDev)() ? 'https' : 'http', port);
|
38
|
-
const routes = existSrc
|
39
|
-
? serverRoutes.filter(route => route.entryName)
|
40
|
-
: serverRoutes;
|
41
|
-
let message = 'App running at:\n\n';
|
42
|
-
if ((0, exports.isSingleEntry)(entrypoints) || !existSrc) {
|
43
|
-
message += urls
|
44
|
-
.map(({ type, url }) => ` ${compiled_1.chalk.bold(`> ${type.padEnd(10)}`)}${compiled_1.chalk.cyanBright(normalizeUrl(`${url}/${routes[0].urlPath}`))}\n`)
|
45
|
-
.join('');
|
46
|
-
}
|
47
|
-
else {
|
48
|
-
const maxNameLength = Math.max(...routes.map(r => r.entryName.length));
|
49
|
-
urls.forEach(({ type, url }) => {
|
50
|
-
message += ` ${compiled_1.chalk.bold(`> ${type}`)}\n`;
|
51
|
-
routes.forEach(({ entryName, urlPath, isSSR }) => {
|
52
|
-
if (!checkedEntries.includes(entryName)) {
|
53
|
-
return;
|
54
|
-
}
|
55
|
-
message += ` ${compiled_1.chalk.yellowBright(isSSR ? 'λ' : '○')} ${compiled_1.chalk.yellowBright(entryName.padEnd(maxNameLength + 8))}${compiled_1.chalk.cyanBright(normalizeUrl(`${url}/${urlPath}`))}\n`;
|
56
|
-
});
|
57
|
-
});
|
58
|
-
message += '\n';
|
59
|
-
message += compiled_1.chalk.cyanBright(' λ (Server) server-side renders at runtime\n');
|
60
|
-
message += compiled_1.chalk.cyanBright(' ○ (Static) client-side rendered as static HTML\n');
|
61
|
-
}
|
62
|
-
return message;
|
63
|
-
};
|
64
|
-
exports.prettyInstructions = prettyInstructions;
|
@@ -1,8 +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
|
-
export declare function printBuildError(err: Error): void;
|
@@ -1,43 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
/* eslint-disable eslint-comments/no-unlimited-disable */
|
3
|
-
/* eslint-disable */
|
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.printBuildError = void 0;
|
13
|
-
// Modified by Chao Xu (xuchaobei)
|
14
|
-
const compiled_1 = require("./compiled");
|
15
|
-
const logger_1 = require("./logger");
|
16
|
-
function printBuildError(err) {
|
17
|
-
const message = err != null && err.message;
|
18
|
-
const stack = err != null && err.stack;
|
19
|
-
// Add more helpful message for Terser error
|
20
|
-
if (stack &&
|
21
|
-
typeof message === 'string' &&
|
22
|
-
message.indexOf('from Terser') !== -1) {
|
23
|
-
try {
|
24
|
-
const matched = /(.+)\[(.+):(.+),(.+)\]\[.+\]/.exec(stack);
|
25
|
-
if (!matched) {
|
26
|
-
throw new Error('Using errors for control flow is bad.');
|
27
|
-
}
|
28
|
-
const problemPath = matched[2];
|
29
|
-
const line = matched[3];
|
30
|
-
const column = matched[4];
|
31
|
-
logger_1.logger.error(`Failed to minify the code from this file: \n\n ${compiled_1.chalk.yellow(`\t${problemPath}:${line}${column !== '0' ? ':' + column : ''}`)}\n`);
|
32
|
-
}
|
33
|
-
catch (ignored) {
|
34
|
-
logger_1.logger.error(`Failed to minify the bundle. ${err}\n`);
|
35
|
-
}
|
36
|
-
}
|
37
|
-
else {
|
38
|
-
logger_1.logger.error((message || err) + '\n');
|
39
|
-
}
|
40
|
-
logger_1.logger.log();
|
41
|
-
}
|
42
|
-
exports.printBuildError = printBuildError;
|
43
|
-
/* eslint-enable */
|