@modern-js/utils 2.22.0 → 2.22.1-alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. package/dist/FileSizeReporter.d.ts +16 -0
  2. package/dist/FileSizeReporter.js +162 -0
  3. package/dist/alias.d.ts +25 -0
  4. package/dist/alias.js +108 -0
  5. package/dist/analyzeProject.d.ts +2 -0
  6. package/dist/analyzeProject.js +71 -0
  7. package/dist/applyOptionsChain.d.ts +3 -0
  8. package/dist/applyOptionsChain.js +58 -0
  9. package/dist/babel.d.ts +3 -0
  10. package/dist/babel.js +136 -0
  11. package/dist/chainId.d.ts +244 -0
  12. package/dist/chainId.js +196 -0
  13. package/dist/cjs/cli/constants/index.js +4 -0
  14. package/dist/cjs/runtime-node/walk.js +1 -0
  15. package/dist/cjs/universal/constants.js +4 -0
  16. package/dist/clearConsole.d.ts +1 -0
  17. package/dist/clearConsole.js +31 -0
  18. package/dist/commands.d.ts +4 -0
  19. package/dist/commands.js +48 -0
  20. package/dist/compatRequire.d.ts +13 -0
  21. package/dist/compatRequire.js +82 -0
  22. package/dist/compiled.d.ts +43 -0
  23. package/dist/compiled.js +142 -0
  24. package/dist/constants.d.ts +244 -0
  25. package/dist/constants.js +320 -0
  26. package/dist/debug.d.ts +6 -0
  27. package/dist/debug.js +28 -0
  28. package/dist/emptyDir.d.ts +1 -0
  29. package/dist/emptyDir.js +52 -0
  30. package/dist/ensureAbsolutePath.d.ts +7 -0
  31. package/dist/ensureAbsolutePath.js +38 -0
  32. package/dist/ensureArray.d.ts +1 -0
  33. package/dist/ensureArray.js +32 -0
  34. package/dist/esm/cli/constants/index.js +1 -0
  35. package/dist/esm/runtime-node/walk.js +0 -0
  36. package/dist/esm/universal/constants.js +1 -0
  37. package/dist/findExists.d.ts +6 -0
  38. package/dist/findExists.js +45 -0
  39. package/dist/generateMetaTags.d.ts +16 -0
  40. package/dist/generateMetaTags.js +61 -0
  41. package/dist/getBrowserslist.d.ts +2 -0
  42. package/dist/getBrowserslist.js +31 -0
  43. package/dist/getCoreJsVersion.d.ts +1 -0
  44. package/dist/getCoreJsVersion.js +46 -0
  45. package/dist/getEntryOptions.d.ts +1 -0
  46. package/dist/getEntryOptions.js +54 -0
  47. package/dist/getPackageManager.d.ts +1 -0
  48. package/dist/getPackageManager.js +87 -0
  49. package/dist/getPort.d.ts +14 -0
  50. package/dist/getPort.js +112 -0
  51. package/dist/getServerConfig.d.ts +1 -0
  52. package/dist/getServerConfig.js +67 -0
  53. package/dist/getTargetDir.d.ts +1 -0
  54. package/dist/getTargetDir.js +41 -0
  55. package/dist/import.d.ts +5 -0
  56. package/dist/import.js +33 -0
  57. package/dist/index.d.ts +44 -0
  58. package/dist/index.js +60 -0
  59. package/dist/is/index.d.ts +58 -0
  60. package/dist/is/index.js +114 -0
  61. package/dist/is/nodeEnv.d.ts +8 -0
  62. package/dist/is/nodeEnv.js +39 -0
  63. package/dist/is/platform.d.ts +2 -0
  64. package/dist/is/platform.js +30 -0
  65. package/dist/is/type.d.ts +8 -0
  66. package/dist/is/type.js +64 -0
  67. package/dist/logger.d.ts +65 -0
  68. package/dist/logger.js +145 -0
  69. package/dist/monorepo.d.ts +11 -0
  70. package/dist/monorepo.js +137 -0
  71. package/dist/nodeEnv.d.ts +3 -0
  72. package/dist/nodeEnv.js +81 -0
  73. package/dist/path.d.ts +18 -0
  74. package/dist/path.js +92 -0
  75. package/dist/pathSerializer.d.ts +16 -0
  76. package/dist/pathSerializer.js +76 -0
  77. package/dist/plugin.d.ts +2 -0
  78. package/dist/plugin.js +46 -0
  79. package/dist/prettyInstructions.d.ts +9 -0
  80. package/dist/prettyInstructions.js +112 -0
  81. package/dist/printBuildError.d.ts +8 -0
  82. package/dist/printBuildError.js +57 -0
  83. package/dist/react.d.ts +1 -0
  84. package/dist/react.js +64 -0
  85. package/dist/readTsConfig.d.ts +2 -0
  86. package/dist/readTsConfig.js +47 -0
  87. package/dist/removeSlash.d.ts +3 -0
  88. package/dist/removeSlash.js +33 -0
  89. package/dist/resolve.d.ts +13 -0
  90. package/dist/resolve.js +63 -0
  91. package/dist/routes.d.ts +2 -0
  92. package/dist/routes.js +58 -0
  93. package/dist/runtimeExports.d.ts +4 -0
  94. package/dist/runtimeExports.js +73 -0
  95. package/dist/ssr.d.ts +8 -0
  96. package/dist/ssr.js +30 -0
  97. package/dist/storage.d.ts +5 -0
  98. package/dist/storage.js +75 -0
  99. package/dist/testUtils.d.ts +5 -0
  100. package/dist/testUtils.js +38 -0
  101. package/dist/types/cli/constants/index.d.ts +4 -0
  102. package/dist/types/runtime-node/walk.d.ts +0 -0
  103. package/dist/types/universal/constants.d.ts +5 -1
  104. package/dist/types.d.ts +1 -0
  105. package/dist/types.js +15 -0
  106. package/dist/universal/constants.d.ts +9 -0
  107. package/dist/universal/constants.js +30 -0
  108. package/dist/universal/formatWebpack.d.ts +13 -0
  109. package/dist/universal/formatWebpack.js +100 -0
  110. package/dist/universal/nestedRoutes.d.ts +8 -0
  111. package/dist/universal/nestedRoutes.js +131 -0
  112. package/dist/universal/remixRouter.d.ts +1 -0
  113. package/dist/universal/remixRouter.js +17 -0
  114. package/dist/universal/serialize.d.ts +1 -0
  115. package/dist/universal/serialize.js +40 -0
  116. package/dist/version.d.ts +2 -0
  117. package/dist/version.js +92 -0
  118. package/dist/wait.d.ts +2 -0
  119. package/dist/wait.js +29 -0
  120. package/dist/watch.d.ts +8 -0
  121. package/dist/watch.js +90 -0
  122. package/package.json +12 -3
@@ -0,0 +1,58 @@
1
+ interface EntryPoint {
2
+ entryName: string;
3
+ }
4
+ /**
5
+ * Check if the package name is in dependencies or devDependencies.
6
+ *
7
+ * @param appDirectory - Project root directory.
8
+ * @param name - Package name.
9
+ * @returns True if the name is in dependencies or devDependencies, false otherwise.
10
+ */
11
+
12
+ export declare const isDepExists: (appDirectory: string, name: string) => boolean;
13
+ /**
14
+ * Is typescript project.
15
+ *
16
+ * @param root - App directory.
17
+ * @returns Whether to use typescript.
18
+ */
19
+
20
+ export declare const isTypescript: (root: string) => boolean;
21
+ /**
22
+ * Is Empty object
23
+ *
24
+ * @param o - Any object.
25
+ * @returns Whether it is empty object.
26
+ */
27
+
28
+ export declare const isEmpty: (o: Record<string, unknown>) => boolean;
29
+ /**
30
+ * Is SSR project
31
+ *
32
+ * @param config - User config.
33
+ * @returns Whether to use server side render.
34
+ */
35
+
36
+ export declare const isSSR: (config: any) => boolean;
37
+ export declare const isUseSSRBundle: (config: any) => boolean;
38
+ /**
39
+ * Is Worker project
40
+ *
41
+ * @param config - User config.
42
+ * @returns Whether to use worker deploy.
43
+ */
44
+
45
+ export declare const isServiceWorker: (config: any) => boolean;
46
+ export declare const isFastRefresh: () => boolean;
47
+ export declare const isRouterV5: (config: {
48
+ runtime?: {
49
+ router?: {
50
+ mode?: string;
51
+ } | boolean;
52
+ };
53
+ }) => boolean;
54
+ export declare const isSSGEntry: (config: any, entryName: string, entrypoints: EntryPoint[]) => boolean;
55
+ export declare const isSingleEntry: (entrypoints: EntryPoint[]) => boolean;
56
+ export * from './nodeEnv';
57
+ export * from './platform';
58
+ export * from './type';
@@ -0,0 +1,114 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var is_exports = {};
30
+ __export(is_exports, {
31
+ isDepExists: () => isDepExists,
32
+ isEmpty: () => isEmpty,
33
+ isFastRefresh: () => isFastRefresh,
34
+ isRouterV5: () => isRouterV5,
35
+ isSSGEntry: () => isSSGEntry,
36
+ isSSR: () => isSSR,
37
+ isServiceWorker: () => isServiceWorker,
38
+ isSingleEntry: () => isSingleEntry,
39
+ isTypescript: () => isTypescript,
40
+ isUseSSRBundle: () => isUseSSRBundle
41
+ });
42
+ module.exports = __toCommonJS(is_exports);
43
+ var import_fs = __toESM(require("fs"));
44
+ var import_path = __toESM(require("path"));
45
+ var import_debug = require("../debug");
46
+ var import_nodeEnv = require("./nodeEnv");
47
+ __reExport(is_exports, require("./nodeEnv"), module.exports);
48
+ __reExport(is_exports, require("./platform"), module.exports);
49
+ __reExport(is_exports, require("./type"), module.exports);
50
+ const debug = (0, import_debug.createDebugger)("judge-depExists");
51
+ const isDepExists = (appDirectory, name) => {
52
+ const pkgPath = import_path.default.resolve(appDirectory, "./package.json");
53
+ if (!import_fs.default.existsSync(pkgPath)) {
54
+ debug(`can't find package.json under: %s`, appDirectory);
55
+ return false;
56
+ }
57
+ const json = require(pkgPath);
58
+ const { dependencies = {}, devDependencies = {} } = json;
59
+ return dependencies.hasOwnProperty(name) || devDependencies.hasOwnProperty(name);
60
+ };
61
+ const isTypescript = (root) => import_fs.default.existsSync(import_path.default.resolve(root, "./tsconfig.json"));
62
+ const isEmpty = (o) => Object.entries(o).length === 0 && o.constructor === Object;
63
+ const isSSR = (config) => {
64
+ const { server } = config;
65
+ if (server == null ? void 0 : server.ssr) {
66
+ return true;
67
+ }
68
+ if ((server == null ? void 0 : server.ssrByEntries) && !isEmpty(server.ssrByEntries)) {
69
+ for (const name of Object.keys(server.ssrByEntries)) {
70
+ if (server.ssrByEntries[name]) {
71
+ return true;
72
+ }
73
+ }
74
+ }
75
+ return false;
76
+ };
77
+ const isUseSSRBundle = (config) => {
78
+ const { output } = config;
79
+ if (output == null ? void 0 : output.ssg) {
80
+ return true;
81
+ }
82
+ return isSSR(config);
83
+ };
84
+ const isServiceWorker = (config) => {
85
+ const { output, server } = config;
86
+ if ((server == null ? void 0 : server.worker) && ((output == null ? void 0 : output.ssg) || isSSR(config))) {
87
+ return true;
88
+ }
89
+ return false;
90
+ };
91
+ const isFastRefresh = () => (0, import_nodeEnv.isDev)() && process.env.FAST_REFRESH !== "false";
92
+ const isRouterV5 = (config) => {
93
+ var _a, _b, _c;
94
+ return typeof ((_a = config.runtime) == null ? void 0 : _a.router) !== "boolean" && ((_c = (_b = config == null ? void 0 : config.runtime) == null ? void 0 : _b.router) == null ? void 0 : _c.mode) === "react-router-5";
95
+ };
96
+ const isSSGEntry = (config, entryName, entrypoints) => {
97
+ const ssgConfig = config.output.ssg;
98
+ const useSSG = isSingleEntry(entrypoints) ? Boolean(ssgConfig) : ssgConfig === true || typeof (ssgConfig == null ? void 0 : ssgConfig[0]) === "function" || Boolean(ssgConfig == null ? void 0 : ssgConfig[entryName]);
99
+ return useSSG;
100
+ };
101
+ const isSingleEntry = (entrypoints) => entrypoints.length === 1 && entrypoints[0].entryName === "main";
102
+ // Annotate the CommonJS export names for ESM import in node:
103
+ 0 && (module.exports = {
104
+ isDepExists,
105
+ isEmpty,
106
+ isFastRefresh,
107
+ isRouterV5,
108
+ isSSGEntry,
109
+ isSSR,
110
+ isServiceWorker,
111
+ isSingleEntry,
112
+ isTypescript,
113
+ isUseSSRBundle
114
+ });
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Get the current NODE_ENV, or default to 'development' if not set.
3
+ */
4
+ export declare const getNodeEnv: () => string;
5
+ export declare const isDev: () => boolean;
6
+ export declare const isProd: () => boolean;
7
+ export declare const isTest: () => boolean;
8
+ export declare const isProdProfile: () => boolean;
@@ -0,0 +1,39 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var nodeEnv_exports = {};
19
+ __export(nodeEnv_exports, {
20
+ getNodeEnv: () => getNodeEnv,
21
+ isDev: () => isDev,
22
+ isProd: () => isProd,
23
+ isProdProfile: () => isProdProfile,
24
+ isTest: () => isTest
25
+ });
26
+ module.exports = __toCommonJS(nodeEnv_exports);
27
+ const getNodeEnv = () => process.env.NODE_ENV || "development";
28
+ const isDev = () => getNodeEnv() === "development";
29
+ const isProd = () => getNodeEnv() === "production";
30
+ const isTest = () => getNodeEnv() === "test";
31
+ const isProdProfile = () => isProd() && process.argv.includes("--profile");
32
+ // Annotate the CommonJS export names for ESM import in node:
33
+ 0 && (module.exports = {
34
+ getNodeEnv,
35
+ isDev,
36
+ isProd,
37
+ isProdProfile,
38
+ isTest
39
+ });
@@ -0,0 +1,2 @@
1
+ export declare const isNodeJS: () => boolean;
2
+ export declare const isBrowser: () => boolean;
@@ -0,0 +1,30 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var platform_exports = {};
19
+ __export(platform_exports, {
20
+ isBrowser: () => isBrowser,
21
+ isNodeJS: () => isNodeJS
22
+ });
23
+ module.exports = __toCommonJS(platform_exports);
24
+ const isNodeJS = () => typeof process !== "undefined" && process.versions != null && process.versions.node != null && process.versions.electron == null;
25
+ const isBrowser = () => typeof window !== "undefined";
26
+ // Annotate the CommonJS export names for ESM import in node:
27
+ 0 && (module.exports = {
28
+ isBrowser,
29
+ isNodeJS
30
+ });
@@ -0,0 +1,8 @@
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;
@@ -0,0 +1,64 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var type_exports = {};
19
+ __export(type_exports, {
20
+ isArray: () => isArray,
21
+ isFunction: () => isFunction,
22
+ isObject: () => isObject,
23
+ isPlainObject: () => isPlainObject,
24
+ isPromise: () => isPromise,
25
+ isRegExp: () => isRegExp,
26
+ isString: () => isString,
27
+ isUndefined: () => isUndefined
28
+ });
29
+ module.exports = __toCommonJS(type_exports);
30
+ function isString(str) {
31
+ return typeof str === "string";
32
+ }
33
+ function isUndefined(obj) {
34
+ return typeof obj === "undefined";
35
+ }
36
+ function isArray(obj) {
37
+ return Array.isArray(obj);
38
+ }
39
+ function isFunction(func) {
40
+ return typeof func === "function";
41
+ }
42
+ function isObject(obj) {
43
+ return obj !== null && typeof obj === "object";
44
+ }
45
+ function isPlainObject(obj) {
46
+ return isObject(obj) && Object.prototype.toString.call(obj) === "[object Object]";
47
+ }
48
+ function isPromise(obj) {
49
+ return Boolean(obj) && (typeof obj === "object" || typeof obj === "function") && typeof obj.then === "function";
50
+ }
51
+ function isRegExp(obj) {
52
+ return Object.prototype.toString.call(obj) === "[object RegExp]";
53
+ }
54
+ // Annotate the CommonJS export names for ESM import in node:
55
+ 0 && (module.exports = {
56
+ isArray,
57
+ isFunction,
58
+ isObject,
59
+ isPlainObject,
60
+ isPromise,
61
+ isRegExp,
62
+ isString,
63
+ isUndefined
64
+ });
@@ -0,0 +1,65 @@
1
+ import { Color } from '../compiled/chalk';
2
+ type LogLevel = 'debug' | 'info' | 'warn' | 'error';
3
+ type LogMsg = number | string | Error | null;
4
+ interface LoggerConfiguration {
5
+ color?: typeof Color;
6
+ label?: string;
7
+ level?: LogLevel;
8
+ }
9
+ interface InstanceConfiguration {
10
+ displayLabel?: boolean;
11
+ uppercaseLabel?: boolean;
12
+ }
13
+ interface ConstructorOptions {
14
+ config?: InstanceConfiguration;
15
+ level?: string;
16
+ types?: Record<string, LoggerConfiguration>;
17
+ }
18
+ type LoggerFunction = (message?: LogMsg, ...args: any[]) => void;
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
+ };
48
+ };
49
+
50
+ declare class Logger {
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;
59
+ }
60
+
61
+ type LoggerInterface = { [key in keyof typeof LOG_TYPES]: LoggerFunction };
62
+ declare const logger: Logger & LoggerInterface;
63
+ export { Logger };
64
+ export { logger };
65
+ export type { LoggerInterface };
package/dist/logger.js ADDED
@@ -0,0 +1,145 @@
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;
32
+ };
33
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
34
+ // If the importer is in node compatibility mode or this is not an ESM
35
+ // file that has been converted to a CommonJS file using a Babel-
36
+ // compatible transform (i.e. "__esModule" has not been set), then set
37
+ // "default" to the CommonJS "module.exports" for node compatibility.
38
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
39
+ mod
40
+ ));
41
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
42
+ var logger_exports = {};
43
+ __export(logger_exports, {
44
+ Logger: () => Logger,
45
+ logger: () => logger
46
+ });
47
+ module.exports = __toCommonJS(logger_exports);
48
+ var import_chalk = __toESM(require("../compiled/chalk"));
49
+ const LOG_LEVEL = {
50
+ error: 0,
51
+ warn: 1,
52
+ info: 2,
53
+ debug: 3,
54
+ log: 4
55
+ };
56
+ const LOG_TYPES = {
57
+ error: {
58
+ color: "red",
59
+ label: "error",
60
+ level: "error"
61
+ },
62
+ info: {
63
+ color: "cyan",
64
+ label: "info",
65
+ level: "info"
66
+ },
67
+ success: {
68
+ color: "green",
69
+ label: "Success",
70
+ level: "info"
71
+ },
72
+ warn: {
73
+ color: "yellow",
74
+ label: "warn",
75
+ level: "warn"
76
+ },
77
+ debug: {
78
+ color: "red",
79
+ label: "debug",
80
+ level: "debug"
81
+ },
82
+ log: { level: "log" }
83
+ };
84
+ const DEFAULT_CONFIG = {
85
+ displayLabel: true,
86
+ uppercaseLabel: false
87
+ };
88
+ class Logger {
89
+ constructor(options = {}) {
90
+ this.level = options.level || LOG_TYPES.log.level;
91
+ this.config = __spreadValues(__spreadValues({}, DEFAULT_CONFIG), options.config || {});
92
+ this.types = __spreadValues(__spreadValues({}, LOG_TYPES), options.types || {});
93
+ this.longestLabel = this.getLongestLabel();
94
+ Object.keys(this.types).forEach((type) => {
95
+ this[type] = this._log.bind(this, type);
96
+ });
97
+ }
98
+ _log(type, message, ...args) {
99
+ if (message === void 0 || message === null) {
100
+ console.log();
101
+ return;
102
+ }
103
+ if (LOG_LEVEL[type] > LOG_LEVEL[this.level]) {
104
+ return;
105
+ }
106
+ let label = "";
107
+ let text = "";
108
+ const logType = this.types[type];
109
+ if (this.config.displayLabel && logType.label) {
110
+ label = this.config.uppercaseLabel ? logType.label.toUpperCase() : logType.label;
111
+ label = label.padEnd(this.longestLabel.length);
112
+ label = import_chalk.default.bold(logType.color ? import_chalk.default[logType.color](label) : label);
113
+ }
114
+ if (message instanceof Error) {
115
+ if (message.stack) {
116
+ const [name, ...rest] = message.stack.split("\n");
117
+ text = `${name}
118
+ ${import_chalk.default.grey(rest.join("\n"))}`;
119
+ } else {
120
+ text = message.message;
121
+ }
122
+ } else {
123
+ text = `${message}`;
124
+ }
125
+ const log = label.length > 0 ? `${label} ${text}` : text;
126
+ console.log(log, ...args);
127
+ }
128
+ getLongestLabel() {
129
+ let longestLabel = "";
130
+ Object.keys(this.types).forEach((type) => {
131
+ const { label = "" } = this.types[type];
132
+ if (label.length > longestLabel.length) {
133
+ longestLabel = label;
134
+ }
135
+ });
136
+ return longestLabel;
137
+ }
138
+ }
139
+ const logger = new Logger();
140
+ logger.Logger = Logger;
141
+ // Annotate the CommonJS export names for ESM import in node:
142
+ 0 && (module.exports = {
143
+ Logger,
144
+ logger
145
+ });
@@ -0,0 +1,11 @@
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
+ }[];
@@ -0,0 +1,137 @@
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;
32
+ };
33
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
34
+ // If the importer is in node compatibility mode or this is not an ESM
35
+ // file that has been converted to a CommonJS file using a Babel-
36
+ // compatible transform (i.e. "__esModule" has not been set), then set
37
+ // "default" to the CommonJS "module.exports" for node compatibility.
38
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
39
+ mod
40
+ ));
41
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
42
+ var monorepo_exports = {};
43
+ __export(monorepo_exports, {
44
+ findMonorepoRoot: () => findMonorepoRoot,
45
+ getMonorepoPackages: () => getMonorepoPackages,
46
+ isLerna: () => isLerna,
47
+ isModernjsMonorepo: () => isModernjsMonorepo,
48
+ isMonorepo: () => isMonorepo,
49
+ isPnpmWorkspaces: () => isPnpmWorkspaces,
50
+ isYarnWorkspaces: () => isYarnWorkspaces
51
+ });
52
+ module.exports = __toCommonJS(monorepo_exports);
53
+ var import_fs = __toESM(require("fs"));
54
+ var import_path = __toESM(require("path"));
55
+ var import_compiled = require("./compiled");
56
+ const PACKAGE_MAX_DEPTH = 5;
57
+ const WORKSPACE_FILES = {
58
+ YARN: "package.json",
59
+ PNPM: "pnpm-workspace.yaml",
60
+ LERNA: "lerna.json"
61
+ };
62
+ const isLerna = (root) => import_fs.default.existsSync(import_path.default.join(root, WORKSPACE_FILES.LERNA));
63
+ const isYarnWorkspaces = (root) => {
64
+ var _a;
65
+ const pkg = import_path.default.join(root, WORKSPACE_FILES.YARN);
66
+ if (!import_fs.default.existsSync(pkg)) {
67
+ return false;
68
+ }
69
+ const json = JSON.parse(import_fs.default.readFileSync(pkg, "utf8"));
70
+ return Boolean((_a = json.workspaces) == null ? void 0 : _a.packages);
71
+ };
72
+ const isPnpmWorkspaces = (root) => import_fs.default.existsSync(import_path.default.join(root, WORKSPACE_FILES.PNPM));
73
+ const isMonorepo = (root) => isLerna(root) || isYarnWorkspaces(root) || isPnpmWorkspaces(root);
74
+ const isModernjsMonorepo = (root) => {
75
+ const pkgJsonPath = import_path.default.join(root, "package.json");
76
+ if (!import_fs.default.existsSync(pkgJsonPath)) {
77
+ return false;
78
+ }
79
+ const json = JSON.parse(import_fs.default.readFileSync(pkgJsonPath, "utf8"));
80
+ const deps = __spreadValues(__spreadValues({}, json.dependencies || {}), json.devDependencies || {});
81
+ return Boolean(deps["@modern-js/monorepo-tools"]);
82
+ };
83
+ const findMonorepoRoot = (appDirectory, maxDepth = PACKAGE_MAX_DEPTH) => {
84
+ let inMonorepo = false;
85
+ for (let depth = 0; depth < maxDepth; depth++) {
86
+ if (isMonorepo(appDirectory)) {
87
+ inMonorepo = true;
88
+ break;
89
+ }
90
+ appDirectory = import_path.default.dirname(appDirectory);
91
+ }
92
+ return inMonorepo ? appDirectory : void 0;
93
+ };
94
+ const getMonorepoPackages = (root) => {
95
+ let packages = [];
96
+ if (isYarnWorkspaces(root)) {
97
+ const json = JSON.parse(
98
+ import_fs.default.readFileSync(import_path.default.join(root, "package.json"), "utf8")
99
+ );
100
+ ({ packages } = json.workspaces);
101
+ } else if (isLerna(root)) {
102
+ const json = JSON.parse(
103
+ import_fs.default.readFileSync(import_path.default.resolve(root, "lerna.json"), "utf8")
104
+ );
105
+ ({ packages } = json);
106
+ } else {
107
+ ({ packages } = import_compiled.yaml.load(
108
+ import_fs.default.readFileSync(import_path.default.join(root, WORKSPACE_FILES.PNPM), "utf8")
109
+ ));
110
+ }
111
+ if (packages) {
112
+ return packages.map(
113
+ (name) => (
114
+ // The trailing / ensures only dirs are picked up
115
+ import_compiled.glob.sync(import_path.default.join(root, `${name}/`), {
116
+ ignore: ["**/node_modules/**"]
117
+ })
118
+ )
119
+ ).reduce((acc, val) => acc.concat(val), []).filter((filepath) => import_fs.default.existsSync(import_path.default.resolve(filepath, "package.json"))).map((filepath) => ({
120
+ path: filepath,
121
+ name: JSON.parse(
122
+ import_fs.default.readFileSync(import_path.default.resolve(filepath, "package.json"), "utf8")
123
+ ).name
124
+ }));
125
+ }
126
+ return [];
127
+ };
128
+ // Annotate the CommonJS export names for ESM import in node:
129
+ 0 && (module.exports = {
130
+ findMonorepoRoot,
131
+ getMonorepoPackages,
132
+ isLerna,
133
+ isModernjsMonorepo,
134
+ isMonorepo,
135
+ isPnpmWorkspaces,
136
+ isYarnWorkspaces
137
+ });