@modern-js/utils 2.4.0 → 2.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.
Files changed (102) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/FileSizeReporter.d.ts +5 -5
  3. package/dist/FileSizeReporter.js +143 -136
  4. package/dist/alias.d.ts +14 -12
  5. package/dist/alias.js +94 -54
  6. package/dist/analyzeProject.d.ts +1 -1
  7. package/dist/analyzeProject.js +58 -33
  8. package/dist/applyOptionsChain.d.ts +1 -1
  9. package/dist/applyOptionsChain.js +55 -27
  10. package/dist/chainId.d.ts +256 -184
  11. package/dist/chainId.js +132 -187
  12. package/dist/clearConsole.d.ts +1 -1
  13. package/dist/clearConsole.js +29 -7
  14. package/dist/commands.d.ts +1 -1
  15. package/dist/commands.js +33 -10
  16. package/dist/compatRequire.d.ts +3 -3
  17. package/dist/compatRequire.js +74 -38
  18. package/dist/compiled.d.ts +2 -1
  19. package/dist/compiled.js +137 -72
  20. package/dist/constants.d.ts +131 -105
  21. package/dist/constants.js +298 -277
  22. package/dist/debug.d.ts +1 -1
  23. package/dist/debug.js +28 -11
  24. package/dist/emptyDir.d.ts +1 -1
  25. package/dist/emptyDir.js +51 -9
  26. package/dist/ensureAbsolutePath.d.ts +1 -1
  27. package/dist/ensureAbsolutePath.js +33 -14
  28. package/dist/ensureArray.d.ts +1 -1
  29. package/dist/ensureArray.js +30 -8
  30. package/dist/findExists.d.ts +1 -1
  31. package/dist/findExists.js +37 -17
  32. package/dist/format.d.ts +3 -3
  33. package/dist/format.js +93 -81
  34. package/dist/generateMetaTags.d.ts +3 -3
  35. package/dist/generateMetaTags.js +56 -43
  36. package/dist/getBrowserslist.d.ts +1 -1
  37. package/dist/getBrowserslist.js +31 -7
  38. package/dist/getCoreJsVersion.d.ts +1 -1
  39. package/dist/getCoreJsVersion.js +39 -35
  40. package/dist/getEntryOptions.d.ts +1 -1
  41. package/dist/getEntryOptions.js +51 -24
  42. package/dist/getPackageManager.d.ts +1 -1
  43. package/dist/getPackageManager.js +75 -28
  44. package/dist/getPort.d.ts +7 -4
  45. package/dist/getPort.js +104 -58
  46. package/dist/getServerConfig.d.ts +1 -1
  47. package/dist/getServerConfig.js +61 -32
  48. package/dist/import.d.ts +2 -2
  49. package/dist/import.js +31 -8
  50. package/dist/index.d.ts +1 -1
  51. package/dist/index.js +59 -59
  52. package/dist/is/index.d.ts +12 -1
  53. package/dist/is/index.js +83 -82
  54. package/dist/is/node-env.d.ts +1 -1
  55. package/dist/is/node-env.js +39 -17
  56. package/dist/is/platform.d.ts +1 -1
  57. package/dist/is/platform.js +30 -10
  58. package/dist/is/type.d.ts +1 -1
  59. package/dist/is/type.js +48 -22
  60. package/dist/logger.d.ts +48 -48
  61. package/dist/logger.js +127 -95
  62. package/dist/monorepo.d.ts +3 -3
  63. package/dist/monorepo.js +117 -74
  64. package/dist/nodeEnv.d.ts +1 -1
  65. package/dist/nodeEnv.js +72 -25
  66. package/dist/path.d.ts +3 -1
  67. package/dist/path.js +76 -59
  68. package/dist/pathSerializer.d.ts +6 -6
  69. package/dist/pathSerializer.js +65 -43
  70. package/dist/plugin.d.ts +1 -1
  71. package/dist/plugin.js +45 -26
  72. package/dist/prettyInstructions.d.ts +4 -4
  73. package/dist/prettyInstructions.js +107 -65
  74. package/dist/printBuildError.d.ts +1 -1
  75. package/dist/printBuildError.js +54 -40
  76. package/dist/react.d.ts +1 -1
  77. package/dist/react.js +57 -21
  78. package/dist/readTsConfig.d.ts +1 -1
  79. package/dist/readTsConfig.js +38 -12
  80. package/dist/removeSlash.d.ts +1 -1
  81. package/dist/removeSlash.js +33 -9
  82. package/dist/routes.d.ts +1 -1
  83. package/dist/routes.js +49 -22
  84. package/dist/runtimeExports.d.ts +3 -3
  85. package/dist/runtimeExports.js +59 -39
  86. package/dist/ssr.d.ts +2 -1
  87. package/dist/ssr.js +30 -7
  88. package/dist/storage.d.ts +3 -3
  89. package/dist/storage.js +65 -59
  90. package/dist/test-utils.d.ts +1 -1
  91. package/dist/test-utils.js +30 -24
  92. package/dist/tryResolve.d.ts +2 -1
  93. package/dist/tryResolve.js +45 -33
  94. package/dist/types.d.ts +1 -1
  95. package/dist/types.js +15 -2
  96. package/dist/version.d.ts +1 -1
  97. package/dist/version.js +83 -24
  98. package/dist/wait.d.ts +1 -1
  99. package/dist/wait.js +28 -6
  100. package/dist/watch.d.ts +3 -3
  101. package/dist/watch.js +82 -55
  102. package/package.json +7 -8
package/dist/logger.d.ts CHANGED
@@ -2,64 +2,64 @@ import { Color } from '../compiled/chalk';
2
2
  type LogLevel = 'debug' | 'info' | 'warn' | 'error';
3
3
  type LogMsg = number | string | Error | null;
4
4
  interface LoggerConfiguration {
5
- color?: typeof Color;
6
- label?: string;
7
- level?: LogLevel;
5
+ color?: typeof Color;
6
+ label?: string;
7
+ level?: LogLevel;
8
8
  }
9
9
  interface InstanceConfiguration {
10
- displayLabel?: boolean;
11
- uppercaseLabel?: boolean;
10
+ displayLabel?: boolean;
11
+ uppercaseLabel?: boolean;
12
12
  }
13
13
  interface ConstructorOptions {
14
- config?: InstanceConfiguration;
15
- level?: string;
16
- types?: Record<string, LoggerConfiguration>;
14
+ config?: InstanceConfiguration;
15
+ level?: string;
16
+ types?: Record<string, LoggerConfiguration>;
17
17
  }
18
18
  type LoggerFunction = (message?: LogMsg, ...args: any[]) => void;
19
19
  declare const LOG_TYPES: {
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
- };
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
- private readonly level;
51
- private readonly config;
52
- private readonly types;
53
- private readonly longestLabel;
54
- [key: string]: any;
55
- constructor(options?: ConstructorOptions);
56
- private _log;
57
- private getLongestLabel;
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
- type LoggerInterface = {
60
- [key in keyof typeof LOG_TYPES]: LoggerFunction;
61
- };
60
+
61
+ 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
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.logger = exports.Logger = void 0;
7
- const chalk_1 = __importDefault(require("../compiled/chalk"));
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
- error: 0,
10
- warn: 1,
11
- info: 2,
12
- debug: 3,
13
- log: 4,
46
+ error: 0,
47
+ warn: 1,
48
+ info: 2,
49
+ debug: 3,
50
+ log: 4
14
51
  };
15
52
  const LOG_TYPES = {
16
- error: {
17
- color: 'red',
18
- label: 'error',
19
- level: 'error',
20
- },
21
- info: {
22
- color: 'cyan',
23
- label: 'info',
24
- level: 'info',
25
- },
26
- success: {
27
- color: 'green',
28
- label: 'Success',
29
- level: 'info',
30
- },
31
- warn: {
32
- color: 'yellow',
33
- label: 'warn',
34
- level: 'warn',
35
- },
36
- debug: {
37
- color: 'red',
38
- label: 'debug',
39
- level: 'debug',
40
- },
41
- log: { level: 'log' },
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
- displayLabel: true,
45
- uppercaseLabel: false,
81
+ displayLabel: true,
82
+ uppercaseLabel: false
46
83
  };
47
84
  class Logger {
48
- constructor(options = {}) {
49
- this.level = options.level || LOG_TYPES.log.level;
50
- this.config = { ...DEFAULT_CONFIG, ...(options.config || {}) };
51
- this.types = {
52
- ...LOG_TYPES,
53
- ...(options.types || {}),
54
- };
55
- this.longestLabel = this.getLongestLabel();
56
- Object.keys(this.types).forEach(type => {
57
- this[type] = this._log.bind(this, type);
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
- _log(type, message, ...args) {
61
- if (message === undefined || message === null) {
62
- // eslint-disable-next-line no-console
63
- console.log();
64
- return;
65
- }
66
- if (LOG_LEVEL[type] > LOG_LEVEL[this.level]) {
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
- getLongestLabel() {
96
- let longestLabel = '';
97
- Object.keys(this.types).forEach(type => {
98
- const { label = '' } = this.types[type];
99
- if (label.length > longestLabel.length) {
100
- longestLabel = label;
101
- }
102
- });
103
- return longestLabel;
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
+ });
@@ -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
- name: string;
10
- path: string;
11
- }[];
9
+ name: string;
10
+ path: string;
11
+ }[];
package/dist/monorepo.js CHANGED
@@ -1,87 +1,130 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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
- 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 compiled_1 = require("./compiled");
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
- YARN: 'package.json',
13
- PNPM: 'pnpm-workspace.yaml',
14
- LERNA: 'lerna.json',
54
+ YARN: "package.json",
55
+ PNPM: "pnpm-workspace.yaml",
56
+ LERNA: "lerna.json"
15
57
  };
16
- const isLerna = (root) => fs_1.default.existsSync(path_1.default.join(root, WORKSPACE_FILES.LERNA));
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
- var _a;
20
- const pkg = path_1.default.join(root, WORKSPACE_FILES.YARN);
21
- if (!fs_1.default.existsSync(pkg)) {
22
- return false;
23
- }
24
- const json = JSON.parse(fs_1.default.readFileSync(pkg, 'utf8'));
25
- return Boolean((_a = json.workspaces) === null || _a === void 0 ? void 0 : _a.packages);
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
- exports.isYarnWorkspaces = isYarnWorkspaces;
28
- const isPnpmWorkspaces = (root) => fs_1.default.existsSync(path_1.default.join(root, WORKSPACE_FILES.PNPM));
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
- const pkgJsonPath = path_1.default.join(root, 'package.json');
34
- if (!fs_1.default.existsSync(pkgJsonPath)) {
35
- return false;
36
- }
37
- const json = JSON.parse(fs_1.default.readFileSync(pkgJsonPath, 'utf8'));
38
- const deps = {
39
- ...(json.dependencies || {}),
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
- let inMonorepo = false;
47
- for (let depth = 0; depth < maxDepth; depth++) {
48
- if ((0, exports.isMonorepo)(appDirectory)) {
49
- inMonorepo = true;
50
- break;
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
- return inMonorepo ? appDirectory : undefined;
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
- let packages = [];
60
- if ((0, exports.isYarnWorkspaces)(root)) {
61
- const json = JSON.parse(fs_1.default.readFileSync(path_1.default.join(root, 'package.json'), 'utf8'));
62
- ({ packages } = json.workspaces);
63
- }
64
- else if ((0, exports.isLerna)(root)) {
65
- const json = JSON.parse(fs_1.default.readFileSync(path_1.default.resolve(root, 'lerna.json'), 'utf8'));
66
- ({ packages } = json);
67
- }
68
- else {
69
- ({ packages } = compiled_1.yaml.load(fs_1.default.readFileSync(path_1.default.join(root, WORKSPACE_FILES.PNPM), 'utf8')));
70
- }
71
- if (packages) {
72
- return packages
73
- .map(name =>
74
- // The trailing / ensures only dirs are picked up
75
- compiled_1.glob.sync(path_1.default.join(root, `${name}/`), {
76
- ignore: ['**/node_modules/**'],
77
- }))
78
- .reduce((acc, val) => acc.concat(val), [])
79
- .filter(filepath => fs_1.default.existsSync(path_1.default.resolve(filepath, 'package.json')))
80
- .map(filepath => ({
81
- path: filepath,
82
- name: JSON.parse(fs_1.default.readFileSync(path_1.default.resolve(filepath, 'package.json'), 'utf8')).name,
83
- }));
84
- }
85
- return [];
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
- exports.getMonorepoPackages = getMonorepoPackages;
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
+ });
package/dist/nodeEnv.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export declare function canUseNpm(): Promise<boolean>;
2
2
  export declare function canUseYarn(): Promise<boolean>;
3
- export declare function canUsePnpm(): Promise<boolean>;
3
+ export declare function canUsePnpm(): Promise<boolean>;