@modern-js/utils 2.4.1-beta.0 → 2.5.0-alpha.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +7 -1
- package/dist/FileSizeReporter.d.ts +5 -5
- package/dist/FileSizeReporter.js +143 -136
- package/dist/alias.d.ts +16 -14
- package/dist/alias.js +94 -54
- package/dist/analyzeProject.d.ts +1 -1
- package/dist/analyzeProject.js +58 -33
- package/dist/applyOptionsChain.d.ts +1 -1
- package/dist/applyOptionsChain.js +55 -27
- package/dist/chainId.d.ts +256 -184
- package/dist/chainId.js +132 -187
- package/dist/clearConsole.d.ts +1 -1
- package/dist/clearConsole.js +29 -7
- package/dist/commands.d.ts +1 -1
- package/dist/commands.js +33 -10
- package/dist/compatRequire.d.ts +3 -3
- package/dist/compatRequire.js +74 -38
- package/dist/compiled.d.ts +2 -1
- package/dist/compiled.js +137 -72
- package/dist/constants.d.ts +127 -105
- package/dist/constants.js +298 -281
- package/dist/debug.d.ts +1 -1
- package/dist/debug.js +28 -11
- package/dist/emptyDir.d.ts +1 -1
- package/dist/emptyDir.js +51 -9
- package/dist/ensureAbsolutePath.d.ts +1 -1
- package/dist/ensureAbsolutePath.js +33 -14
- package/dist/ensureArray.d.ts +1 -1
- package/dist/ensureArray.js +30 -8
- package/dist/findExists.d.ts +1 -1
- package/dist/findExists.js +37 -17
- package/dist/format.d.ts +3 -3
- package/dist/format.js +93 -81
- package/dist/generateMetaTags.d.ts +4 -4
- package/dist/generateMetaTags.js +56 -43
- package/dist/getBrowserslist.d.ts +1 -1
- package/dist/getBrowserslist.js +31 -7
- package/dist/getCoreJsVersion.d.ts +1 -1
- package/dist/getCoreJsVersion.js +39 -35
- package/dist/getEntryOptions.d.ts +1 -1
- package/dist/getEntryOptions.js +51 -24
- package/dist/getPackageManager.d.ts +1 -1
- package/dist/getPackageManager.js +75 -28
- package/dist/getPort.d.ts +7 -4
- package/dist/getPort.js +104 -58
- package/dist/getServerConfig.d.ts +1 -1
- package/dist/getServerConfig.js +61 -32
- package/dist/import.d.ts +2 -2
- package/dist/import.js +31 -8
- package/dist/index.d.ts +2 -0
- package/dist/index.js +61 -59
- package/dist/is/index.d.ts +5 -1
- package/dist/is/index.js +81 -94
- package/dist/is/node-env.d.ts +1 -1
- package/dist/is/node-env.js +39 -17
- package/dist/is/platform.d.ts +1 -1
- package/dist/is/platform.js +30 -10
- package/dist/is/type.d.ts +1 -1
- package/dist/is/type.js +48 -22
- package/dist/logger.d.ts +51 -51
- package/dist/logger.js +127 -95
- package/dist/monorepo.d.ts +3 -3
- package/dist/monorepo.js +117 -74
- package/dist/nestedRoutes.d.ts +9 -0
- package/dist/nestedRoutes.js +144 -0
- package/dist/nodeEnv.d.ts +1 -1
- package/dist/nodeEnv.js +72 -25
- package/dist/path.d.ts +3 -1
- package/dist/path.js +76 -59
- package/dist/pathSerializer.d.ts +7 -7
- package/dist/pathSerializer.js +65 -43
- package/dist/plugin.d.ts +1 -1
- package/dist/plugin.js +45 -26
- package/dist/prettyInstructions.d.ts +4 -4
- package/dist/prettyInstructions.js +107 -65
- package/dist/printBuildError.d.ts +1 -1
- package/dist/printBuildError.js +54 -40
- package/dist/react.d.ts +1 -1
- package/dist/react.js +57 -21
- package/dist/readTsConfig.d.ts +1 -1
- package/dist/readTsConfig.js +38 -12
- package/dist/remix-router.d.ts +1 -0
- package/dist/remix-router.js +17 -0
- package/dist/removeSlash.d.ts +1 -1
- package/dist/removeSlash.js +33 -9
- package/dist/routes.d.ts +1 -1
- package/dist/routes.js +49 -22
- package/dist/runtimeExports.d.ts +3 -3
- package/dist/runtimeExports.js +59 -39
- package/dist/serialize.d.ts +1 -0
- package/dist/serialize.js +36 -0
- package/dist/ssr.d.ts +2 -1
- package/dist/ssr.js +30 -7
- package/dist/storage.d.ts +3 -3
- package/dist/storage.js +65 -59
- package/dist/test-utils.d.ts +1 -1
- package/dist/test-utils.js +30 -24
- package/dist/tryResolve.d.ts +2 -1
- package/dist/tryResolve.js +45 -33
- package/dist/types.d.ts +1 -1
- package/dist/types.js +15 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +83 -24
- package/dist/wait.d.ts +1 -1
- package/dist/wait.js +28 -6
- package/dist/watch.d.ts +5 -5
- package/dist/watch.js +82 -55
- package/package.json +31 -9
package/dist/logger.d.ts
CHANGED
@@ -1,65 +1,65 @@
|
|
1
1
|
import { Color } from '../compiled/chalk';
|
2
|
-
type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
3
|
-
type LogMsg = number | string | Error | null;
|
2
|
+
declare type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
3
|
+
declare type LogMsg = number | string | Error | null;
|
4
4
|
interface LoggerConfiguration {
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
color?: typeof Color;
|
6
|
+
label?: string;
|
7
|
+
level?: LogLevel;
|
8
8
|
}
|
9
9
|
interface InstanceConfiguration {
|
10
|
-
|
11
|
-
|
10
|
+
displayLabel?: boolean;
|
11
|
+
uppercaseLabel?: boolean;
|
12
12
|
}
|
13
13
|
interface ConstructorOptions {
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
config?: InstanceConfiguration;
|
15
|
+
level?: string;
|
16
|
+
types?: Record<string, LoggerConfiguration>;
|
17
17
|
}
|
18
|
-
type LoggerFunction = (message?: LogMsg, ...args: any[]) => void;
|
18
|
+
declare type LoggerFunction = (message?: LogMsg, ...args: any[]) => void;
|
19
19
|
declare const LOG_TYPES: {
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
20
|
+
error: {
|
21
|
+
color: string;
|
22
|
+
label: string;
|
23
|
+
level: string;
|
24
|
+
};
|
25
|
+
info: {
|
26
|
+
color: string;
|
27
|
+
label: string;
|
28
|
+
level: string;
|
29
|
+
};
|
30
|
+
success: {
|
31
|
+
color: string;
|
32
|
+
label: string;
|
33
|
+
level: string;
|
34
|
+
};
|
35
|
+
warn: {
|
36
|
+
color: string;
|
37
|
+
label: string;
|
38
|
+
level: string;
|
39
|
+
};
|
40
|
+
debug: {
|
41
|
+
color: string;
|
42
|
+
label: string;
|
43
|
+
level: string;
|
44
|
+
};
|
45
|
+
log: {
|
46
|
+
level: string;
|
47
|
+
};
|
48
48
|
};
|
49
|
+
|
49
50
|
declare class Logger {
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
51
|
+
private readonly level;
|
52
|
+
private readonly config;
|
53
|
+
private readonly types;
|
54
|
+
private readonly longestLabel;
|
55
|
+
[key: string]: any;
|
56
|
+
constructor(options?: ConstructorOptions);
|
57
|
+
private _log;
|
58
|
+
private getLongestLabel;
|
58
59
|
}
|
59
|
-
|
60
|
-
|
61
|
-
};
|
60
|
+
|
61
|
+
declare type LoggerInterface = { [key in keyof typeof LOG_TYPES]: LoggerFunction };
|
62
62
|
declare const logger: Logger & LoggerInterface;
|
63
63
|
export { Logger };
|
64
64
|
export { logger };
|
65
|
-
export type { LoggerInterface };
|
65
|
+
export type { LoggerInterface };
|
package/dist/logger.js
CHANGED
@@ -1,109 +1,141 @@
|
|
1
|
-
|
2
|
-
var
|
3
|
-
|
1
|
+
var __create = Object.create;
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
10
|
+
var __spreadValues = (a, b) => {
|
11
|
+
for (var prop in b || (b = {}))
|
12
|
+
if (__hasOwnProp.call(b, prop))
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
14
|
+
if (__getOwnPropSymbols)
|
15
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
16
|
+
if (__propIsEnum.call(b, prop))
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
18
|
+
}
|
19
|
+
return a;
|
20
|
+
};
|
21
|
+
var __export = (target, all) => {
|
22
|
+
for (var name in all)
|
23
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
4
24
|
};
|
5
|
-
|
6
|
-
|
7
|
-
|
25
|
+
var __copyProps = (to, from, except, desc) => {
|
26
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
27
|
+
for (let key of __getOwnPropNames(from))
|
28
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
29
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
30
|
+
}
|
31
|
+
return to;
|
32
|
+
};
|
33
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
34
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
35
|
+
mod
|
36
|
+
));
|
37
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
38
|
+
var logger_exports = {};
|
39
|
+
__export(logger_exports, {
|
40
|
+
Logger: () => Logger,
|
41
|
+
logger: () => logger
|
42
|
+
});
|
43
|
+
module.exports = __toCommonJS(logger_exports);
|
44
|
+
var import_chalk = __toESM(require("../compiled/chalk"));
|
8
45
|
const LOG_LEVEL = {
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
46
|
+
error: 0,
|
47
|
+
warn: 1,
|
48
|
+
info: 2,
|
49
|
+
debug: 3,
|
50
|
+
log: 4
|
14
51
|
};
|
15
52
|
const LOG_TYPES = {
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
53
|
+
error: {
|
54
|
+
color: "red",
|
55
|
+
label: "error",
|
56
|
+
level: "error"
|
57
|
+
},
|
58
|
+
info: {
|
59
|
+
color: "cyan",
|
60
|
+
label: "info",
|
61
|
+
level: "info"
|
62
|
+
},
|
63
|
+
success: {
|
64
|
+
color: "green",
|
65
|
+
label: "Success",
|
66
|
+
level: "info"
|
67
|
+
},
|
68
|
+
warn: {
|
69
|
+
color: "yellow",
|
70
|
+
label: "warn",
|
71
|
+
level: "warn"
|
72
|
+
},
|
73
|
+
debug: {
|
74
|
+
color: "red",
|
75
|
+
label: "debug",
|
76
|
+
level: "debug"
|
77
|
+
},
|
78
|
+
log: { level: "log" }
|
42
79
|
};
|
43
80
|
const DEFAULT_CONFIG = {
|
44
|
-
|
45
|
-
|
81
|
+
displayLabel: true,
|
82
|
+
uppercaseLabel: false
|
46
83
|
};
|
47
84
|
class Logger {
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
85
|
+
constructor(options = {}) {
|
86
|
+
this.level = options.level || LOG_TYPES.log.level;
|
87
|
+
this.config = __spreadValues(__spreadValues({}, DEFAULT_CONFIG), options.config || {});
|
88
|
+
this.types = __spreadValues(__spreadValues({}, LOG_TYPES), options.types || {});
|
89
|
+
this.longestLabel = this.getLongestLabel();
|
90
|
+
Object.keys(this.types).forEach((type) => {
|
91
|
+
this[type] = this._log.bind(this, type);
|
92
|
+
});
|
93
|
+
}
|
94
|
+
_log(type, message, ...args) {
|
95
|
+
if (message === void 0 || message === null) {
|
96
|
+
console.log();
|
97
|
+
return;
|
98
|
+
}
|
99
|
+
if (LOG_LEVEL[type] > LOG_LEVEL[this.level]) {
|
100
|
+
return;
|
59
101
|
}
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
return;
|
68
|
-
}
|
69
|
-
let label = '';
|
70
|
-
let text = '';
|
71
|
-
const logType = this.types[type];
|
72
|
-
if (this.config.displayLabel && logType.label) {
|
73
|
-
label = this.config.uppercaseLabel
|
74
|
-
? logType.label.toUpperCase()
|
75
|
-
: logType.label;
|
76
|
-
label = label.padEnd(this.longestLabel.length);
|
77
|
-
label = chalk_1.default.bold(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${chalk_1.default.grey(rest.join('\n'))}`;
|
83
|
-
}
|
84
|
-
else {
|
85
|
-
text = message.message;
|
86
|
-
}
|
87
|
-
}
|
88
|
-
else {
|
89
|
-
text = `${message}`;
|
90
|
-
}
|
91
|
-
const log = label.length > 0 ? `${label} ${text}` : text;
|
92
|
-
// eslint-disable-next-line no-console
|
93
|
-
console.log(log, ...args);
|
102
|
+
let label = "";
|
103
|
+
let text = "";
|
104
|
+
const logType = this.types[type];
|
105
|
+
if (this.config.displayLabel && logType.label) {
|
106
|
+
label = this.config.uppercaseLabel ? logType.label.toUpperCase() : logType.label;
|
107
|
+
label = label.padEnd(this.longestLabel.length);
|
108
|
+
label = import_chalk.default.bold(logType.color ? import_chalk.default[logType.color](label) : label);
|
94
109
|
}
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
110
|
+
if (message instanceof Error) {
|
111
|
+
if (message.stack) {
|
112
|
+
const [name, ...rest] = message.stack.split("\n");
|
113
|
+
text = `${name}
|
114
|
+
${import_chalk.default.grey(rest.join("\n"))}`;
|
115
|
+
} else {
|
116
|
+
text = message.message;
|
117
|
+
}
|
118
|
+
} else {
|
119
|
+
text = `${message}`;
|
104
120
|
}
|
121
|
+
const log = label.length > 0 ? `${label} ${text}` : text;
|
122
|
+
console.log(log, ...args);
|
123
|
+
}
|
124
|
+
getLongestLabel() {
|
125
|
+
let longestLabel = "";
|
126
|
+
Object.keys(this.types).forEach((type) => {
|
127
|
+
const { label = "" } = this.types[type];
|
128
|
+
if (label.length > longestLabel.length) {
|
129
|
+
longestLabel = label;
|
130
|
+
}
|
131
|
+
});
|
132
|
+
return longestLabel;
|
133
|
+
}
|
105
134
|
}
|
106
|
-
exports.Logger = Logger;
|
107
135
|
const logger = new Logger();
|
108
|
-
exports.logger = logger;
|
109
136
|
logger.Logger = Logger;
|
137
|
+
// Annotate the CommonJS export names for ESM import in node:
|
138
|
+
0 && (module.exports = {
|
139
|
+
Logger,
|
140
|
+
logger
|
141
|
+
});
|
package/dist/monorepo.d.ts
CHANGED
@@ -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
|
+
}[];
|
package/dist/monorepo.js
CHANGED
@@ -1,87 +1,130 @@
|
|
1
|
-
|
2
|
-
var
|
3
|
-
|
1
|
+
var __create = Object.create;
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
10
|
+
var __spreadValues = (a, b) => {
|
11
|
+
for (var prop in b || (b = {}))
|
12
|
+
if (__hasOwnProp.call(b, prop))
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
14
|
+
if (__getOwnPropSymbols)
|
15
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
16
|
+
if (__propIsEnum.call(b, prop))
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
18
|
+
}
|
19
|
+
return a;
|
20
|
+
};
|
21
|
+
var __export = (target, all) => {
|
22
|
+
for (var name in all)
|
23
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
24
|
+
};
|
25
|
+
var __copyProps = (to, from, except, desc) => {
|
26
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
27
|
+
for (let key of __getOwnPropNames(from))
|
28
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
29
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
30
|
+
}
|
31
|
+
return to;
|
4
32
|
};
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
33
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
34
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
35
|
+
mod
|
36
|
+
));
|
37
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
38
|
+
var monorepo_exports = {};
|
39
|
+
__export(monorepo_exports, {
|
40
|
+
findMonorepoRoot: () => findMonorepoRoot,
|
41
|
+
getMonorepoPackages: () => getMonorepoPackages,
|
42
|
+
isLerna: () => isLerna,
|
43
|
+
isModernjsMonorepo: () => isModernjsMonorepo,
|
44
|
+
isMonorepo: () => isMonorepo,
|
45
|
+
isPnpmWorkspaces: () => isPnpmWorkspaces,
|
46
|
+
isYarnWorkspaces: () => isYarnWorkspaces
|
47
|
+
});
|
48
|
+
module.exports = __toCommonJS(monorepo_exports);
|
49
|
+
var import_fs = __toESM(require("fs"));
|
50
|
+
var import_path = __toESM(require("path"));
|
51
|
+
var import_compiled = require("./compiled");
|
10
52
|
const PACKAGE_MAX_DEPTH = 5;
|
11
53
|
const WORKSPACE_FILES = {
|
12
|
-
|
13
|
-
|
14
|
-
|
54
|
+
YARN: "package.json",
|
55
|
+
PNPM: "pnpm-workspace.yaml",
|
56
|
+
LERNA: "lerna.json"
|
15
57
|
};
|
16
|
-
const isLerna = (root) =>
|
17
|
-
exports.isLerna = isLerna;
|
58
|
+
const isLerna = (root) => import_fs.default.existsSync(import_path.default.join(root, WORKSPACE_FILES.LERNA));
|
18
59
|
const isYarnWorkspaces = (root) => {
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
60
|
+
var _a;
|
61
|
+
const pkg = import_path.default.join(root, WORKSPACE_FILES.YARN);
|
62
|
+
if (!import_fs.default.existsSync(pkg)) {
|
63
|
+
return false;
|
64
|
+
}
|
65
|
+
const json = JSON.parse(import_fs.default.readFileSync(pkg, "utf8"));
|
66
|
+
return Boolean((_a = json.workspaces) == null ? void 0 : _a.packages);
|
26
67
|
};
|
27
|
-
|
28
|
-
const
|
29
|
-
exports.isPnpmWorkspaces = isPnpmWorkspaces;
|
30
|
-
const isMonorepo = (root) => (0, exports.isLerna)(root) || (0, exports.isYarnWorkspaces)(root) || (0, exports.isPnpmWorkspaces)(root);
|
31
|
-
exports.isMonorepo = isMonorepo;
|
68
|
+
const isPnpmWorkspaces = (root) => import_fs.default.existsSync(import_path.default.join(root, WORKSPACE_FILES.PNPM));
|
69
|
+
const isMonorepo = (root) => isLerna(root) || isYarnWorkspaces(root) || isPnpmWorkspaces(root);
|
32
70
|
const isModernjsMonorepo = (root) => {
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
...(json.devDependencies || {}),
|
41
|
-
};
|
42
|
-
return Boolean(deps['@modern-js/monorepo-tools']);
|
71
|
+
const pkgJsonPath = import_path.default.join(root, "package.json");
|
72
|
+
if (!import_fs.default.existsSync(pkgJsonPath)) {
|
73
|
+
return false;
|
74
|
+
}
|
75
|
+
const json = JSON.parse(import_fs.default.readFileSync(pkgJsonPath, "utf8"));
|
76
|
+
const deps = __spreadValues(__spreadValues({}, json.dependencies || {}), json.devDependencies || {});
|
77
|
+
return Boolean(deps["@modern-js/monorepo-tools"]);
|
43
78
|
};
|
44
|
-
exports.isModernjsMonorepo = isModernjsMonorepo;
|
45
79
|
const findMonorepoRoot = (appDirectory, maxDepth = PACKAGE_MAX_DEPTH) => {
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
}
|
52
|
-
// eslint-disable-next-line no-param-reassign
|
53
|
-
appDirectory = path_1.default.dirname(appDirectory);
|
80
|
+
let inMonorepo = false;
|
81
|
+
for (let depth = 0; depth < maxDepth; depth++) {
|
82
|
+
if (isMonorepo(appDirectory)) {
|
83
|
+
inMonorepo = true;
|
84
|
+
break;
|
54
85
|
}
|
55
|
-
|
86
|
+
appDirectory = import_path.default.dirname(appDirectory);
|
87
|
+
}
|
88
|
+
return inMonorepo ? appDirectory : void 0;
|
56
89
|
};
|
57
|
-
exports.findMonorepoRoot = findMonorepoRoot;
|
58
90
|
const getMonorepoPackages = (root) => {
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
91
|
+
let packages = [];
|
92
|
+
if (isYarnWorkspaces(root)) {
|
93
|
+
const json = JSON.parse(
|
94
|
+
import_fs.default.readFileSync(import_path.default.join(root, "package.json"), "utf8")
|
95
|
+
);
|
96
|
+
({ packages } = json.workspaces);
|
97
|
+
} else if (isLerna(root)) {
|
98
|
+
const json = JSON.parse(
|
99
|
+
import_fs.default.readFileSync(import_path.default.resolve(root, "lerna.json"), "utf8")
|
100
|
+
);
|
101
|
+
({ packages } = json);
|
102
|
+
} else {
|
103
|
+
({ packages } = import_compiled.yaml.load(
|
104
|
+
import_fs.default.readFileSync(import_path.default.join(root, WORKSPACE_FILES.PNPM), "utf8")
|
105
|
+
));
|
106
|
+
}
|
107
|
+
if (packages) {
|
108
|
+
return packages.map(
|
109
|
+
(name) => import_compiled.glob.sync(import_path.default.join(root, `${name}/`), {
|
110
|
+
ignore: ["**/node_modules/**"]
|
111
|
+
})
|
112
|
+
).reduce((acc, val) => acc.concat(val), []).filter((filepath) => import_fs.default.existsSync(import_path.default.resolve(filepath, "package.json"))).map((filepath) => ({
|
113
|
+
path: filepath,
|
114
|
+
name: JSON.parse(
|
115
|
+
import_fs.default.readFileSync(import_path.default.resolve(filepath, "package.json"), "utf8")
|
116
|
+
).name
|
117
|
+
}));
|
118
|
+
}
|
119
|
+
return [];
|
86
120
|
};
|
87
|
-
|
121
|
+
// Annotate the CommonJS export names for ESM import in node:
|
122
|
+
0 && (module.exports = {
|
123
|
+
findMonorepoRoot,
|
124
|
+
getMonorepoPackages,
|
125
|
+
isLerna,
|
126
|
+
isModernjsMonorepo,
|
127
|
+
isMonorepo,
|
128
|
+
isPnpmWorkspaces,
|
129
|
+
isYarnWorkspaces
|
130
|
+
});
|
@@ -0,0 +1,9 @@
|
|
1
|
+
/**
|
2
|
+
* runtime utils for nested routes generating
|
3
|
+
*/
|
4
|
+
import type { NestedRoute } from '@modern-js/types';
|
5
|
+
export declare const transformNestedRoutes: (routes: NestedRoute[]) => import("react-router-dom").RouteObject[];
|
6
|
+
export declare const renderNestedRoute: (nestedRoute: NestedRoute, options?: {
|
7
|
+
parent?: NestedRoute;
|
8
|
+
DeferredDataComponent?: () => JSX.Element;
|
9
|
+
}) => JSX.Element;
|