@modern-js/utils 2.22.1-alpha.2 → 2.22.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/cjs/cli/constants/index.js +0 -4
  3. package/dist/cjs/cli/prettyInstructions.js +3 -2
  4. package/dist/cjs/runtime/nestedRoutes.js +3 -1
  5. package/dist/cjs/runtime-node/index.js +0 -2
  6. package/dist/cjs/universal/constants.js +0 -4
  7. package/dist/esm/cli/constants/index.js +0 -1
  8. package/dist/esm/cli/prettyInstructions.js +3 -2
  9. package/dist/esm/runtime/nestedRoutes.js +3 -1
  10. package/dist/esm/runtime-node/index.js +0 -1
  11. package/dist/esm/universal/constants.js +0 -1
  12. package/dist/types/cli/constants/index.d.ts +0 -4
  13. package/dist/types/runtime/nestedRoutes.d.ts +6 -2
  14. package/dist/types/runtime-node/index.d.ts +1 -2
  15. package/dist/types/universal/constants.d.ts +1 -5
  16. package/package.json +4 -13
  17. package/dist/FileSizeReporter.d.ts +0 -16
  18. package/dist/FileSizeReporter.js +0 -162
  19. package/dist/alias.d.ts +0 -25
  20. package/dist/alias.js +0 -108
  21. package/dist/analyzeProject.d.ts +0 -2
  22. package/dist/analyzeProject.js +0 -71
  23. package/dist/applyOptionsChain.d.ts +0 -3
  24. package/dist/applyOptionsChain.js +0 -58
  25. package/dist/babel.d.ts +0 -3
  26. package/dist/babel.js +0 -136
  27. package/dist/chainId.d.ts +0 -244
  28. package/dist/chainId.js +0 -196
  29. package/dist/cjs/runtime-node/nestedRoutes.js +0 -28
  30. package/dist/clearConsole.d.ts +0 -1
  31. package/dist/clearConsole.js +0 -31
  32. package/dist/commands.d.ts +0 -4
  33. package/dist/commands.js +0 -48
  34. package/dist/compatRequire.d.ts +0 -13
  35. package/dist/compatRequire.js +0 -82
  36. package/dist/compiled.d.ts +0 -43
  37. package/dist/compiled.js +0 -142
  38. package/dist/constants.d.ts +0 -244
  39. package/dist/constants.js +0 -320
  40. package/dist/debug.d.ts +0 -6
  41. package/dist/debug.js +0 -28
  42. package/dist/emptyDir.d.ts +0 -1
  43. package/dist/emptyDir.js +0 -52
  44. package/dist/ensureAbsolutePath.d.ts +0 -7
  45. package/dist/ensureAbsolutePath.js +0 -38
  46. package/dist/ensureArray.d.ts +0 -1
  47. package/dist/ensureArray.js +0 -32
  48. package/dist/esm/runtime-node/nestedRoutes.js +0 -18
  49. package/dist/findExists.d.ts +0 -6
  50. package/dist/findExists.js +0 -45
  51. package/dist/generateMetaTags.d.ts +0 -16
  52. package/dist/generateMetaTags.js +0 -61
  53. package/dist/getBrowserslist.d.ts +0 -2
  54. package/dist/getBrowserslist.js +0 -31
  55. package/dist/getCoreJsVersion.d.ts +0 -1
  56. package/dist/getCoreJsVersion.js +0 -46
  57. package/dist/getEntryOptions.d.ts +0 -1
  58. package/dist/getEntryOptions.js +0 -54
  59. package/dist/getPackageManager.d.ts +0 -1
  60. package/dist/getPackageManager.js +0 -87
  61. package/dist/getPort.d.ts +0 -14
  62. package/dist/getPort.js +0 -112
  63. package/dist/getServerConfig.d.ts +0 -1
  64. package/dist/getServerConfig.js +0 -67
  65. package/dist/getTargetDir.d.ts +0 -1
  66. package/dist/getTargetDir.js +0 -41
  67. package/dist/import.d.ts +0 -5
  68. package/dist/import.js +0 -33
  69. package/dist/index.d.ts +0 -44
  70. package/dist/index.js +0 -60
  71. package/dist/is/index.d.ts +0 -58
  72. package/dist/is/index.js +0 -114
  73. package/dist/is/nodeEnv.d.ts +0 -8
  74. package/dist/is/nodeEnv.js +0 -39
  75. package/dist/is/platform.d.ts +0 -2
  76. package/dist/is/platform.js +0 -30
  77. package/dist/is/type.d.ts +0 -8
  78. package/dist/is/type.js +0 -64
  79. package/dist/logger.d.ts +0 -65
  80. package/dist/logger.js +0 -145
  81. package/dist/monorepo.d.ts +0 -11
  82. package/dist/monorepo.js +0 -137
  83. package/dist/nodeEnv.d.ts +0 -3
  84. package/dist/nodeEnv.js +0 -81
  85. package/dist/path.d.ts +0 -18
  86. package/dist/path.js +0 -92
  87. package/dist/pathSerializer.d.ts +0 -16
  88. package/dist/pathSerializer.js +0 -76
  89. package/dist/plugin.d.ts +0 -2
  90. package/dist/plugin.js +0 -46
  91. package/dist/prettyInstructions.d.ts +0 -9
  92. package/dist/prettyInstructions.js +0 -112
  93. package/dist/printBuildError.d.ts +0 -8
  94. package/dist/printBuildError.js +0 -57
  95. package/dist/react.d.ts +0 -1
  96. package/dist/react.js +0 -64
  97. package/dist/readTsConfig.d.ts +0 -2
  98. package/dist/readTsConfig.js +0 -47
  99. package/dist/removeSlash.d.ts +0 -3
  100. package/dist/removeSlash.js +0 -33
  101. package/dist/resolve.d.ts +0 -13
  102. package/dist/resolve.js +0 -63
  103. package/dist/routes.d.ts +0 -2
  104. package/dist/routes.js +0 -58
  105. package/dist/runtimeExports.d.ts +0 -4
  106. package/dist/runtimeExports.js +0 -73
  107. package/dist/ssr.d.ts +0 -8
  108. package/dist/ssr.js +0 -30
  109. package/dist/storage.d.ts +0 -5
  110. package/dist/storage.js +0 -75
  111. package/dist/testUtils.d.ts +0 -5
  112. package/dist/testUtils.js +0 -38
  113. package/dist/types/runtime-node/nestedRoutes.d.ts +0 -3
  114. package/dist/types.d.ts +0 -1
  115. package/dist/types.js +0 -15
  116. package/dist/universal/constants.d.ts +0 -9
  117. package/dist/universal/constants.js +0 -30
  118. package/dist/universal/formatWebpack.d.ts +0 -13
  119. package/dist/universal/formatWebpack.js +0 -100
  120. package/dist/universal/nestedRoutes.d.ts +0 -8
  121. package/dist/universal/nestedRoutes.js +0 -131
  122. package/dist/universal/remixRouter.d.ts +0 -1
  123. package/dist/universal/remixRouter.js +0 -17
  124. package/dist/universal/serialize.d.ts +0 -1
  125. package/dist/universal/serialize.js +0 -40
  126. package/dist/version.d.ts +0 -2
  127. package/dist/version.js +0 -92
  128. package/dist/wait.d.ts +0 -2
  129. package/dist/wait.js +0 -29
  130. package/dist/watch.d.ts +0 -8
  131. package/dist/watch.js +0 -90
@@ -1,58 +0,0 @@
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';
package/dist/is/index.js DELETED
@@ -1,114 +0,0 @@
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
- });
@@ -1,8 +0,0 @@
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;
@@ -1,39 +0,0 @@
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
- });
@@ -1,2 +0,0 @@
1
- export declare const isNodeJS: () => boolean;
2
- export declare const isBrowser: () => boolean;
@@ -1,30 +0,0 @@
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
- });
package/dist/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/is/type.js DELETED
@@ -1,64 +0,0 @@
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
- });
package/dist/logger.d.ts DELETED
@@ -1,65 +0,0 @@
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 DELETED
@@ -1,145 +0,0 @@
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
- });
@@ -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/monorepo.js DELETED
@@ -1,137 +0,0 @@
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
- });