@modern-js/utils 2.22.0 → 2.22.1-alpha.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 (113) 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/clearConsole.d.ts +1 -0
  14. package/dist/clearConsole.js +31 -0
  15. package/dist/commands.d.ts +4 -0
  16. package/dist/commands.js +48 -0
  17. package/dist/compatRequire.d.ts +13 -0
  18. package/dist/compatRequire.js +82 -0
  19. package/dist/compiled.d.ts +43 -0
  20. package/dist/compiled.js +142 -0
  21. package/dist/constants.d.ts +244 -0
  22. package/dist/constants.js +320 -0
  23. package/dist/debug.d.ts +6 -0
  24. package/dist/debug.js +28 -0
  25. package/dist/emptyDir.d.ts +1 -0
  26. package/dist/emptyDir.js +52 -0
  27. package/dist/ensureAbsolutePath.d.ts +7 -0
  28. package/dist/ensureAbsolutePath.js +38 -0
  29. package/dist/ensureArray.d.ts +1 -0
  30. package/dist/ensureArray.js +32 -0
  31. package/dist/findExists.d.ts +6 -0
  32. package/dist/findExists.js +45 -0
  33. package/dist/generateMetaTags.d.ts +16 -0
  34. package/dist/generateMetaTags.js +61 -0
  35. package/dist/getBrowserslist.d.ts +2 -0
  36. package/dist/getBrowserslist.js +31 -0
  37. package/dist/getCoreJsVersion.d.ts +1 -0
  38. package/dist/getCoreJsVersion.js +46 -0
  39. package/dist/getEntryOptions.d.ts +1 -0
  40. package/dist/getEntryOptions.js +54 -0
  41. package/dist/getPackageManager.d.ts +1 -0
  42. package/dist/getPackageManager.js +87 -0
  43. package/dist/getPort.d.ts +14 -0
  44. package/dist/getPort.js +112 -0
  45. package/dist/getServerConfig.d.ts +1 -0
  46. package/dist/getServerConfig.js +67 -0
  47. package/dist/getTargetDir.d.ts +1 -0
  48. package/dist/getTargetDir.js +41 -0
  49. package/dist/import.d.ts +5 -0
  50. package/dist/import.js +33 -0
  51. package/dist/index.d.ts +44 -0
  52. package/dist/index.js +60 -0
  53. package/dist/is/index.d.ts +58 -0
  54. package/dist/is/index.js +114 -0
  55. package/dist/is/nodeEnv.d.ts +8 -0
  56. package/dist/is/nodeEnv.js +39 -0
  57. package/dist/is/platform.d.ts +2 -0
  58. package/dist/is/platform.js +30 -0
  59. package/dist/is/type.d.ts +8 -0
  60. package/dist/is/type.js +64 -0
  61. package/dist/logger.d.ts +65 -0
  62. package/dist/logger.js +145 -0
  63. package/dist/monorepo.d.ts +11 -0
  64. package/dist/monorepo.js +137 -0
  65. package/dist/nodeEnv.d.ts +3 -0
  66. package/dist/nodeEnv.js +81 -0
  67. package/dist/path.d.ts +18 -0
  68. package/dist/path.js +92 -0
  69. package/dist/pathSerializer.d.ts +16 -0
  70. package/dist/pathSerializer.js +76 -0
  71. package/dist/plugin.d.ts +2 -0
  72. package/dist/plugin.js +46 -0
  73. package/dist/prettyInstructions.d.ts +9 -0
  74. package/dist/prettyInstructions.js +112 -0
  75. package/dist/printBuildError.d.ts +8 -0
  76. package/dist/printBuildError.js +57 -0
  77. package/dist/react.d.ts +1 -0
  78. package/dist/react.js +64 -0
  79. package/dist/readTsConfig.d.ts +2 -0
  80. package/dist/readTsConfig.js +47 -0
  81. package/dist/removeSlash.d.ts +3 -0
  82. package/dist/removeSlash.js +33 -0
  83. package/dist/resolve.d.ts +13 -0
  84. package/dist/resolve.js +63 -0
  85. package/dist/routes.d.ts +2 -0
  86. package/dist/routes.js +58 -0
  87. package/dist/runtimeExports.d.ts +4 -0
  88. package/dist/runtimeExports.js +73 -0
  89. package/dist/ssr.d.ts +8 -0
  90. package/dist/ssr.js +30 -0
  91. package/dist/storage.d.ts +5 -0
  92. package/dist/storage.js +75 -0
  93. package/dist/testUtils.d.ts +5 -0
  94. package/dist/testUtils.js +38 -0
  95. package/dist/types.d.ts +1 -0
  96. package/dist/types.js +15 -0
  97. package/dist/universal/constants.d.ts +9 -0
  98. package/dist/universal/constants.js +30 -0
  99. package/dist/universal/formatWebpack.d.ts +13 -0
  100. package/dist/universal/formatWebpack.js +100 -0
  101. package/dist/universal/nestedRoutes.d.ts +8 -0
  102. package/dist/universal/nestedRoutes.js +131 -0
  103. package/dist/universal/remixRouter.d.ts +1 -0
  104. package/dist/universal/remixRouter.js +17 -0
  105. package/dist/universal/serialize.d.ts +1 -0
  106. package/dist/universal/serialize.js +40 -0
  107. package/dist/version.d.ts +2 -0
  108. package/dist/version.js +92 -0
  109. package/dist/wait.d.ts +2 -0
  110. package/dist/wait.js +29 -0
  111. package/dist/watch.d.ts +8 -0
  112. package/dist/watch.js +90 -0
  113. package/package.json +3 -3
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
+ });
@@ -0,0 +1,3 @@
1
+ export declare function canUseNpm(): Promise<boolean>;
2
+ export declare function canUseYarn(): Promise<boolean>;
3
+ export declare function canUsePnpm(): Promise<boolean>;
@@ -0,0 +1,81 @@
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 __async = (__this, __arguments, generator) => {
19
+ return new Promise((resolve, reject) => {
20
+ var fulfilled = (value) => {
21
+ try {
22
+ step(generator.next(value));
23
+ } catch (e) {
24
+ reject(e);
25
+ }
26
+ };
27
+ var rejected = (value) => {
28
+ try {
29
+ step(generator.throw(value));
30
+ } catch (e) {
31
+ reject(e);
32
+ }
33
+ };
34
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
35
+ step((generator = generator.apply(__this, __arguments)).next());
36
+ });
37
+ };
38
+ var nodeEnv_exports = {};
39
+ __export(nodeEnv_exports, {
40
+ canUseNpm: () => canUseNpm,
41
+ canUsePnpm: () => canUsePnpm,
42
+ canUseYarn: () => canUseYarn
43
+ });
44
+ module.exports = __toCommonJS(nodeEnv_exports);
45
+ var import_compiled = require("./compiled");
46
+ function canUseNpm() {
47
+ return __async(this, null, function* () {
48
+ try {
49
+ yield (0, import_compiled.execa)("npm", ["--version"], { env: process.env });
50
+ return true;
51
+ } catch (e) {
52
+ return false;
53
+ }
54
+ });
55
+ }
56
+ function canUseYarn() {
57
+ return __async(this, null, function* () {
58
+ try {
59
+ yield (0, import_compiled.execa)("yarn", ["--version"], { env: process.env });
60
+ return true;
61
+ } catch (e) {
62
+ return false;
63
+ }
64
+ });
65
+ }
66
+ function canUsePnpm() {
67
+ return __async(this, null, function* () {
68
+ try {
69
+ yield (0, import_compiled.execa)("pnpm", ["--version"], { env: process.env });
70
+ return true;
71
+ } catch (e) {
72
+ return false;
73
+ }
74
+ });
75
+ }
76
+ // Annotate the CommonJS export names for ESM import in node:
77
+ 0 && (module.exports = {
78
+ canUseNpm,
79
+ canUsePnpm,
80
+ canUseYarn
81
+ });
package/dist/path.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ import { lodash as _ } from './compiled';
2
+ export declare const isPathString: (test: string) => boolean;
3
+ export declare const isRelativePath: (test: string) => boolean;
4
+ export declare const normalizeOutputPath: (s: string) => string;
5
+ export declare const normalizeToPosixPath: (p: string | undefined) => string;
6
+ export declare const getTemplatePath: (prefix?: string) => string;
7
+ /**
8
+ * Compile path string to RegExp.
9
+ * @note Only support posix path.
10
+ */
11
+
12
+ export declare function compilePathMatcherRegExp(match: string | RegExp): RegExp;
13
+ /** @internal @see {@link upwardPaths} */
14
+
15
+ export declare const _joinPathParts: (_part: unknown, i: number, parts: _.List<string>) => string;
16
+ export declare function upwardPaths(start: string): string[];
17
+ export declare function getRealTemporaryDirectory(): string | null;
18
+ export declare function splitPathString(str: string): string[];
package/dist/path.js ADDED
@@ -0,0 +1,92 @@
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var path_exports = {};
29
+ __export(path_exports, {
30
+ _joinPathParts: () => _joinPathParts,
31
+ compilePathMatcherRegExp: () => compilePathMatcherRegExp,
32
+ getRealTemporaryDirectory: () => getRealTemporaryDirectory,
33
+ getTemplatePath: () => getTemplatePath,
34
+ isPathString: () => isPathString,
35
+ isRelativePath: () => isRelativePath,
36
+ normalizeOutputPath: () => normalizeOutputPath,
37
+ normalizeToPosixPath: () => normalizeToPosixPath,
38
+ splitPathString: () => splitPathString,
39
+ upwardPaths: () => upwardPaths
40
+ });
41
+ module.exports = __toCommonJS(path_exports);
42
+ var import_path = __toESM(require("path"));
43
+ var import_os = __toESM(require("os"));
44
+ var import_fs = __toESM(require("fs"));
45
+ var import_compiled = require("./compiled");
46
+ const isPathString = (test) => import_path.default.posix.basename(test) !== test || import_path.default.win32.basename(test) !== test;
47
+ const isRelativePath = (test) => /^\.\.?($|[\\/])/.test(test);
48
+ const normalizeOutputPath = (s) => s.replace(/\\/g, "\\\\");
49
+ const normalizeToPosixPath = (p) => import_compiled.upath.normalizeSafe(import_path.default.normalize(p || "")).replace(/^([a-zA-Z]+):/, (_2, m) => `/${m.toLowerCase()}`);
50
+ const getTemplatePath = (prefix) => {
51
+ const tmpRoot = import_fs.default.realpathSync(import_os.default.tmpdir());
52
+ const parts = [tmpRoot];
53
+ prefix && parts.push(prefix);
54
+ parts.push((0, import_compiled.nanoid)());
55
+ return import_path.default.resolve(...parts);
56
+ };
57
+ function compilePathMatcherRegExp(match) {
58
+ if (typeof match !== "string") {
59
+ return match;
60
+ }
61
+ const escaped = import_compiled.lodash.escapeRegExp(match);
62
+ return new RegExp(`(?<=\\W|^)${escaped}(?=\\W|$)`);
63
+ }
64
+ const _joinPathParts = (_part, i, parts) => (0, import_compiled.lodash)(parts).filter((part) => !["/", "\\"].includes(part)).tap((parts2) => parts2.unshift("")).slice(0, i + 2).join("/");
65
+ function upwardPaths(start) {
66
+ return (0, import_compiled.lodash)(start).split(/[/\\]/).filter(Boolean).map(_joinPathParts).reverse().push("/").value();
67
+ }
68
+ function getRealTemporaryDirectory() {
69
+ let ret = null;
70
+ try {
71
+ ret = import_os.default.tmpdir();
72
+ ret = import_fs.default.realpathSync(ret);
73
+ } catch (e) {
74
+ }
75
+ return ret;
76
+ }
77
+ function splitPathString(str) {
78
+ return str.split(/[\\/]/);
79
+ }
80
+ // Annotate the CommonJS export names for ESM import in node:
81
+ 0 && (module.exports = {
82
+ _joinPathParts,
83
+ compilePathMatcherRegExp,
84
+ getRealTemporaryDirectory,
85
+ getTemplatePath,
86
+ isPathString,
87
+ isRelativePath,
88
+ normalizeOutputPath,
89
+ normalizeToPosixPath,
90
+ splitPathString,
91
+ upwardPaths
92
+ });
@@ -0,0 +1,16 @@
1
+ /** Different from */
2
+ export type PathMatchExpression = string | RegExp;
3
+ export interface PathMatcher {
4
+ match: PathMatchExpression;
5
+ mark: string | ((substring: string, ...args: any[]) => string);
6
+ }
7
+ export declare const matchUpwardPathsAsUnknown: (p: string) => {
8
+ match: string;
9
+ mark: string;
10
+ }[];
11
+ export interface ApplyPathMatcherOptions {
12
+ minPartials?: number;
13
+ }
14
+ export declare function applyPathMatcher(matcher: PathMatcher, str: string, options?: ApplyPathMatcherOptions): string;
15
+ export declare function applyMatcherReplacement(matchers: PathMatcher[], str: string, options?: ApplyPathMatcherOptions): string;
16
+ export declare const createDefaultPathMatchers: (root: string) => PathMatcher[];
@@ -0,0 +1,76 @@
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var pathSerializer_exports = {};
29
+ __export(pathSerializer_exports, {
30
+ applyMatcherReplacement: () => applyMatcherReplacement,
31
+ applyPathMatcher: () => applyPathMatcher,
32
+ createDefaultPathMatchers: () => createDefaultPathMatchers,
33
+ matchUpwardPathsAsUnknown: () => matchUpwardPathsAsUnknown
34
+ });
35
+ module.exports = __toCommonJS(pathSerializer_exports);
36
+ var import_os = __toESM(require("os"));
37
+ var import_lodash = __toESM(require("../compiled/lodash"));
38
+ var import_path = require("./path");
39
+ const matchUpwardPathsAsUnknown = (p) => (0, import_lodash.default)((0, import_path.upwardPaths)((0, import_path.normalizeToPosixPath)(p))).map((match) => ({ match, mark: "unknown" })).slice(1, -1).value();
40
+ function applyPathMatcher(matcher, str, options = {}) {
41
+ const regex = (0, import_path.compilePathMatcherRegExp)(matcher.match);
42
+ const replacer = (substring, ...args) => {
43
+ if (options.minPartials && (0, import_path.splitPathString)(substring).length < options.minPartials) {
44
+ return substring;
45
+ }
46
+ const ret = typeof matcher.mark === "string" ? matcher.mark : matcher.mark(substring, ...args);
47
+ return `<${import_lodash.default.snakeCase(ret).toUpperCase()}>`;
48
+ };
49
+ return str.replace(regex, replacer);
50
+ }
51
+ function applyMatcherReplacement(matchers, str, options = {}) {
52
+ return matchers.reduce((ret, matcher) => {
53
+ return applyPathMatcher(matcher, ret, options);
54
+ }, str);
55
+ }
56
+ const createDefaultPathMatchers = (root) => {
57
+ const ret = [
58
+ {
59
+ match: new RegExp("(?<=\\/)(\\.pnpm\\/.+?\\/node_modules)(?=\\/)"),
60
+ mark: "pnpmInner"
61
+ }
62
+ ];
63
+ const tmpdir = (0, import_path.getRealTemporaryDirectory)();
64
+ tmpdir && ret.push({ match: tmpdir, mark: "temp" });
65
+ ret.push({ match: import_os.default.tmpdir(), mark: "temp" });
66
+ ret.push({ match: import_os.default.homedir(), mark: "home" });
67
+ ret.push(...matchUpwardPathsAsUnknown(root));
68
+ return ret;
69
+ };
70
+ // Annotate the CommonJS export names for ESM import in node:
71
+ 0 && (module.exports = {
72
+ applyMatcherReplacement,
73
+ applyPathMatcher,
74
+ createDefaultPathMatchers,
75
+ matchUpwardPathsAsUnknown
76
+ });
@@ -0,0 +1,2 @@
1
+ import { InternalPlugins } from '@modern-js/types';
2
+ export declare function getInternalPlugins(appDirectory: string, internalPlugins?: InternalPlugins): string[];
package/dist/plugin.js ADDED
@@ -0,0 +1,46 @@
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 plugin_exports = {};
19
+ __export(plugin_exports, {
20
+ getInternalPlugins: () => getInternalPlugins
21
+ });
22
+ module.exports = __toCommonJS(plugin_exports);
23
+ var import_constants = require("./constants");
24
+ var import_is = require("./is");
25
+ function getInternalPlugins(appDirectory, internalPlugins = import_constants.INTERNAL_CLI_PLUGINS) {
26
+ return [
27
+ ...Object.keys(internalPlugins).filter((name) => {
28
+ const config = internalPlugins[name];
29
+ if (typeof config !== "string" && config.forced === true) {
30
+ return true;
31
+ }
32
+ return (0, import_is.isDepExists)(appDirectory, name);
33
+ }).map((name) => {
34
+ const config = internalPlugins[name];
35
+ if (typeof config !== "string") {
36
+ return config.path;
37
+ } else {
38
+ return config;
39
+ }
40
+ })
41
+ ];
42
+ }
43
+ // Annotate the CommonJS export names for ESM import in node:
44
+ 0 && (module.exports = {
45
+ getInternalPlugins
46
+ });
@@ -0,0 +1,9 @@
1
+ /// <reference types="node" />
2
+ import os from 'os';
3
+ export declare const getIpv4Interfaces: () => os.NetworkInterfaceInfo[];
4
+ export type AddressUrl = {
5
+ label: string;
6
+ url: string;
7
+ };
8
+ export declare const getAddressUrls: (protocol: string | undefined, port: number) => AddressUrl[];
9
+ export declare const prettyInstructions: (appContext: any, config: any) => string;