@modern-js/utils 2.4.0 → 2.5.0-alpha.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/FileSizeReporter.d.ts +5 -5
  3. package/dist/FileSizeReporter.js +143 -136
  4. package/dist/alias.d.ts +16 -14
  5. package/dist/alias.js +94 -54
  6. package/dist/analyzeProject.d.ts +1 -1
  7. package/dist/analyzeProject.js +58 -33
  8. package/dist/applyOptionsChain.d.ts +1 -1
  9. package/dist/applyOptionsChain.js +55 -27
  10. package/dist/chainId.d.ts +256 -184
  11. package/dist/chainId.js +132 -187
  12. package/dist/clearConsole.d.ts +1 -1
  13. package/dist/clearConsole.js +29 -7
  14. package/dist/commands.d.ts +1 -1
  15. package/dist/commands.js +33 -10
  16. package/dist/compatRequire.d.ts +3 -3
  17. package/dist/compatRequire.js +74 -38
  18. package/dist/compiled.d.ts +2 -1
  19. package/dist/compiled.js +137 -72
  20. package/dist/constants.d.ts +131 -105
  21. package/dist/constants.js +298 -277
  22. package/dist/debug.d.ts +1 -1
  23. package/dist/debug.js +28 -11
  24. package/dist/emptyDir.d.ts +1 -1
  25. package/dist/emptyDir.js +51 -9
  26. package/dist/ensureAbsolutePath.d.ts +1 -1
  27. package/dist/ensureAbsolutePath.js +33 -14
  28. package/dist/ensureArray.d.ts +1 -1
  29. package/dist/ensureArray.js +30 -8
  30. package/dist/findExists.d.ts +1 -1
  31. package/dist/findExists.js +37 -17
  32. package/dist/format.d.ts +3 -3
  33. package/dist/format.js +93 -81
  34. package/dist/generateMetaTags.d.ts +4 -4
  35. package/dist/generateMetaTags.js +56 -43
  36. package/dist/getBrowserslist.d.ts +1 -1
  37. package/dist/getBrowserslist.js +31 -7
  38. package/dist/getCoreJsVersion.d.ts +1 -1
  39. package/dist/getCoreJsVersion.js +39 -35
  40. package/dist/getEntryOptions.d.ts +1 -1
  41. package/dist/getEntryOptions.js +51 -24
  42. package/dist/getPackageManager.d.ts +1 -1
  43. package/dist/getPackageManager.js +75 -28
  44. package/dist/getPort.d.ts +7 -4
  45. package/dist/getPort.js +104 -58
  46. package/dist/getServerConfig.d.ts +1 -1
  47. package/dist/getServerConfig.js +61 -32
  48. package/dist/import.d.ts +2 -2
  49. package/dist/import.js +31 -8
  50. package/dist/index.d.ts +2 -0
  51. package/dist/index.js +61 -59
  52. package/dist/is/index.d.ts +12 -1
  53. package/dist/is/index.js +83 -82
  54. package/dist/is/node-env.d.ts +1 -1
  55. package/dist/is/node-env.js +39 -17
  56. package/dist/is/platform.d.ts +1 -1
  57. package/dist/is/platform.js +30 -10
  58. package/dist/is/type.d.ts +1 -1
  59. package/dist/is/type.js +48 -22
  60. package/dist/logger.d.ts +51 -51
  61. package/dist/logger.js +127 -95
  62. package/dist/monorepo.d.ts +3 -3
  63. package/dist/monorepo.js +117 -74
  64. package/dist/nestedRoutes.d.ts +9 -0
  65. package/dist/nestedRoutes.js +144 -0
  66. package/dist/nodeEnv.d.ts +1 -1
  67. package/dist/nodeEnv.js +72 -25
  68. package/dist/path.d.ts +3 -1
  69. package/dist/path.js +76 -59
  70. package/dist/pathSerializer.d.ts +7 -7
  71. package/dist/pathSerializer.js +65 -43
  72. package/dist/plugin.d.ts +1 -1
  73. package/dist/plugin.js +45 -26
  74. package/dist/prettyInstructions.d.ts +4 -4
  75. package/dist/prettyInstructions.js +107 -65
  76. package/dist/printBuildError.d.ts +1 -1
  77. package/dist/printBuildError.js +54 -40
  78. package/dist/react.d.ts +1 -1
  79. package/dist/react.js +57 -21
  80. package/dist/readTsConfig.d.ts +1 -1
  81. package/dist/readTsConfig.js +38 -12
  82. package/dist/remix-router.d.ts +1 -0
  83. package/dist/remix-router.js +17 -0
  84. package/dist/removeSlash.d.ts +1 -1
  85. package/dist/removeSlash.js +33 -9
  86. package/dist/routes.d.ts +1 -1
  87. package/dist/routes.js +49 -22
  88. package/dist/runtimeExports.d.ts +3 -3
  89. package/dist/runtimeExports.js +59 -39
  90. package/dist/serialize.d.ts +1 -0
  91. package/dist/serialize.js +36 -0
  92. package/dist/ssr.d.ts +2 -1
  93. package/dist/ssr.js +30 -7
  94. package/dist/storage.d.ts +3 -3
  95. package/dist/storage.js +65 -59
  96. package/dist/test-utils.d.ts +1 -1
  97. package/dist/test-utils.js +30 -24
  98. package/dist/tryResolve.d.ts +2 -1
  99. package/dist/tryResolve.js +45 -33
  100. package/dist/types.d.ts +1 -1
  101. package/dist/types.js +15 -2
  102. package/dist/version.d.ts +1 -1
  103. package/dist/version.js +83 -24
  104. package/dist/wait.d.ts +1 -1
  105. package/dist/wait.js +28 -6
  106. package/dist/watch.d.ts +5 -5
  107. package/dist/watch.js +82 -55
  108. package/package.json +31 -9
@@ -0,0 +1,144 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
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 __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
22
+ var __export = (target, all) => {
23
+ for (var name in all)
24
+ __defProp(target, name, { get: all[name], enumerable: true });
25
+ };
26
+ var __copyProps = (to, from, except, desc) => {
27
+ if (from && typeof from === "object" || typeof from === "function") {
28
+ for (let key of __getOwnPropNames(from))
29
+ if (!__hasOwnProp.call(to, key) && key !== except)
30
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
31
+ }
32
+ return to;
33
+ };
34
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
35
+ var nestedRoutes_exports = {};
36
+ __export(nestedRoutes_exports, {
37
+ renderNestedRoute: () => renderNestedRoute,
38
+ transformNestedRoutes: () => transformNestedRoutes
39
+ });
40
+ module.exports = __toCommonJS(nestedRoutes_exports);
41
+ var import_jsx_runtime = require("react/jsx-runtime");
42
+ var import_react = require("react");
43
+ var import_react_router_dom = require("react-router-dom");
44
+ const transformNestedRoutes = (routes) => {
45
+ const routeElements = [];
46
+ for (const route of routes) {
47
+ const routeElement = renderNestedRoute(route);
48
+ routeElements.push(routeElement);
49
+ }
50
+ return (0, import_react_router_dom.createRoutesFromElements)(routeElements);
51
+ };
52
+ const renderNestedRoute = (nestedRoute, options = {}) => {
53
+ const { children, index, id, component, isRoot } = nestedRoute;
54
+ const Component = component;
55
+ const { parent, DeferredDataComponent } = options;
56
+ const routeProps = {
57
+ caseSensitive: nestedRoute.caseSensitive,
58
+ path: nestedRoute.path,
59
+ id: nestedRoute.id,
60
+ loader: createLoader(nestedRoute),
61
+ action: nestedRoute.action,
62
+ hasErrorBoundary: nestedRoute.hasErrorBoundary,
63
+ shouldRevalidate: nestedRoute.shouldRevalidate,
64
+ handle: nestedRoute.handle,
65
+ index: nestedRoute.index,
66
+ element: nestedRoute.element,
67
+ errorElement: nestedRoute.errorElement
68
+ };
69
+ if (nestedRoute.error) {
70
+ const errorElement = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(nestedRoute.error, {});
71
+ routeProps.errorElement = errorElement;
72
+ }
73
+ let element;
74
+ if (Component) {
75
+ if (parent == null ? void 0 : parent.loading) {
76
+ const Loading = parent.loading;
77
+ if (isLoadableComponent(Component)) {
78
+ element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {
79
+ fallback: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Loading, {})
80
+ });
81
+ } else {
82
+ element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, {
83
+ fallback: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Loading, {}),
84
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {})
85
+ });
86
+ }
87
+ } else if (isLoadableComponent(Component)) {
88
+ element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {});
89
+ } else if (isRoot) {
90
+ element = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
91
+ children: [
92
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {}),
93
+ typeof document === "undefined" && DeferredDataComponent && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DeferredDataComponent, {})
94
+ ]
95
+ });
96
+ } else {
97
+ element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, {
98
+ fallback: null,
99
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {})
100
+ });
101
+ }
102
+ } else {
103
+ nestedRoute.loading = parent == null ? void 0 : parent.loading;
104
+ }
105
+ if (element) {
106
+ routeProps.element = element;
107
+ }
108
+ const childElements = children == null ? void 0 : children.map((childRoute) => {
109
+ return renderNestedRoute(childRoute, { parent: nestedRoute });
110
+ });
111
+ const routeElement = index ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.Route, __spreadProps(__spreadValues({}, routeProps), {
112
+ index: true
113
+ }), id) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.Route, __spreadProps(__spreadValues({}, routeProps), {
114
+ index: false,
115
+ children: childElements
116
+ }), id);
117
+ return routeElement;
118
+ };
119
+ function createLoader(route) {
120
+ const { loader } = route;
121
+ if (loader) {
122
+ return (args) => {
123
+ if (typeof route.lazyImport === "function") {
124
+ route.lazyImport();
125
+ }
126
+ return loader(args);
127
+ };
128
+ } else {
129
+ return () => {
130
+ if (typeof route.lazyImport === "function") {
131
+ route.lazyImport();
132
+ }
133
+ return null;
134
+ };
135
+ }
136
+ }
137
+ function isLoadableComponent(component) {
138
+ return component && component.displayName === "Loadable" && component.preload && typeof component.preload === "function";
139
+ }
140
+ // Annotate the CommonJS export names for ESM import in node:
141
+ 0 && (module.exports = {
142
+ renderNestedRoute,
143
+ transformNestedRoutes
144
+ });
package/dist/nodeEnv.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export declare function canUseNpm(): Promise<boolean>;
2
2
  export declare function canUseYarn(): Promise<boolean>;
3
- export declare function canUsePnpm(): Promise<boolean>;
3
+ export declare function canUsePnpm(): Promise<boolean>;
package/dist/nodeEnv.js CHANGED
@@ -1,34 +1,81 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.canUsePnpm = exports.canUseYarn = exports.canUseNpm = void 0;
4
- const compiled_1 = require("./compiled");
5
- async function canUseNpm() {
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* () {
6
48
  try {
7
- await (0, compiled_1.execa)('npm', ['--version'], { env: process.env });
8
- return true;
9
- }
10
- catch (e) {
11
- return false;
49
+ yield (0, import_compiled.execa)("npm", ["--version"], { env: process.env });
50
+ return true;
51
+ } catch (e) {
52
+ return false;
12
53
  }
54
+ });
13
55
  }
14
- exports.canUseNpm = canUseNpm;
15
- async function canUseYarn() {
56
+ function canUseYarn() {
57
+ return __async(this, null, function* () {
16
58
  try {
17
- await (0, compiled_1.execa)('yarn', ['--version'], { env: process.env });
18
- return true;
19
- }
20
- catch (e) {
21
- return false;
59
+ yield (0, import_compiled.execa)("yarn", ["--version"], { env: process.env });
60
+ return true;
61
+ } catch (e) {
62
+ return false;
22
63
  }
64
+ });
23
65
  }
24
- exports.canUseYarn = canUseYarn;
25
- async function canUsePnpm() {
66
+ function canUsePnpm() {
67
+ return __async(this, null, function* () {
26
68
  try {
27
- await (0, compiled_1.execa)('pnpm', ['--version'], { env: process.env });
28
- return true;
29
- }
30
- catch (e) {
31
- return false;
69
+ yield (0, import_compiled.execa)("pnpm", ["--version"], { env: process.env });
70
+ return true;
71
+ } catch (e) {
72
+ return false;
32
73
  }
74
+ });
33
75
  }
34
- exports.canUsePnpm = canUsePnpm;
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 CHANGED
@@ -8,9 +8,11 @@ export declare const getTemplatePath: (prefix?: string) => string;
8
8
  * Compile path string to RegExp.
9
9
  * @note Only support posix path.
10
10
  */
11
+
11
12
  export declare function compilePathMatcherRegExp(match: string | RegExp): RegExp;
12
13
  /** @internal @see {@link upwardPaths} */
14
+
13
15
  export declare const _joinPathParts: (_part: unknown, i: number, parts: _.List<string>) => string;
14
16
  export declare function upwardPaths(start: string): string[];
15
17
  export declare function getRealTemporaryDirectory(): string | null;
16
- export declare function splitPathString(str: string): string[];
18
+ export declare function splitPathString(str: string): string[];
package/dist/path.js CHANGED
@@ -1,71 +1,88 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __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 });
4
10
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.splitPathString = exports.getRealTemporaryDirectory = exports.upwardPaths = exports._joinPathParts = exports.compilePathMatcherRegExp = exports.getTemplatePath = exports.normalizeToPosixPath = exports.normalizeOutputPath = exports.isRelativePath = exports.isPathString = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- const os_1 = __importDefault(require("os"));
9
- const fs_1 = __importDefault(require("fs"));
10
- const compiled_1 = require("./compiled");
11
- const isPathString = (test) => path_1.default.posix.basename(test) !== test || path_1.default.win32.basename(test) !== test;
12
- exports.isPathString = isPathString;
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
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
23
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
+ var path_exports = {};
25
+ __export(path_exports, {
26
+ _joinPathParts: () => _joinPathParts,
27
+ compilePathMatcherRegExp: () => compilePathMatcherRegExp,
28
+ getRealTemporaryDirectory: () => getRealTemporaryDirectory,
29
+ getTemplatePath: () => getTemplatePath,
30
+ isPathString: () => isPathString,
31
+ isRelativePath: () => isRelativePath,
32
+ normalizeOutputPath: () => normalizeOutputPath,
33
+ normalizeToPosixPath: () => normalizeToPosixPath,
34
+ splitPathString: () => splitPathString,
35
+ upwardPaths: () => upwardPaths
36
+ });
37
+ module.exports = __toCommonJS(path_exports);
38
+ var import_path = __toESM(require("path"));
39
+ var import_os = __toESM(require("os"));
40
+ var import_fs = __toESM(require("fs"));
41
+ var import_compiled = require("./compiled");
42
+ const isPathString = (test) => import_path.default.posix.basename(test) !== test || import_path.default.win32.basename(test) !== test;
13
43
  const isRelativePath = (test) => /^\.\.?($|[\\/])/.test(test);
14
- exports.isRelativePath = isRelativePath;
15
- const normalizeOutputPath = (s) => s.replace(/\\/g, '\\\\');
16
- exports.normalizeOutputPath = normalizeOutputPath;
17
- const normalizeToPosixPath = (p) => compiled_1.upath
18
- .normalizeSafe(path_1.default.normalize(p || ''))
19
- .replace(/^([a-zA-Z]+):/, (_, m) => `/${m.toLowerCase()}`);
20
- exports.normalizeToPosixPath = normalizeToPosixPath;
44
+ const normalizeOutputPath = (s) => s.replace(/\\/g, "\\\\");
45
+ const normalizeToPosixPath = (p) => import_compiled.upath.normalizeSafe(import_path.default.normalize(p || "")).replace(/^([a-zA-Z]+):/, (_2, m) => `/${m.toLowerCase()}`);
21
46
  const getTemplatePath = (prefix) => {
22
- const tmpRoot = fs_1.default.realpathSync(os_1.default.tmpdir());
23
- const parts = [tmpRoot];
24
- prefix && parts.push(prefix);
25
- parts.push((0, compiled_1.nanoid)());
26
- return path_1.default.resolve(...parts);
47
+ const tmpRoot = import_fs.default.realpathSync(import_os.default.tmpdir());
48
+ const parts = [tmpRoot];
49
+ prefix && parts.push(prefix);
50
+ parts.push((0, import_compiled.nanoid)());
51
+ return import_path.default.resolve(...parts);
27
52
  };
28
- exports.getTemplatePath = getTemplatePath;
29
- /**
30
- * Compile path string to RegExp.
31
- * @note Only support posix path.
32
- */
33
53
  function compilePathMatcherRegExp(match) {
34
- if (typeof match !== 'string') {
35
- return match;
36
- }
37
- const escaped = compiled_1.lodash.escapeRegExp(match);
38
- return new RegExp(`(?<=\\W|^)${escaped}(?=\\W|$)`);
54
+ if (typeof match !== "string") {
55
+ return match;
56
+ }
57
+ const escaped = import_compiled.lodash.escapeRegExp(match);
58
+ return new RegExp(`(?<=\\W|^)${escaped}(?=\\W|$)`);
39
59
  }
40
- exports.compilePathMatcherRegExp = compilePathMatcherRegExp;
41
- /** @internal @see {@link upwardPaths} */
42
- const _joinPathParts = (_part, i, parts) => (0, compiled_1.lodash)(parts)
43
- .filter(part => !['/', '\\'].includes(part))
44
- .tap(parts => parts.unshift(''))
45
- .slice(0, i + 2)
46
- .join('/');
47
- exports._joinPathParts = _joinPathParts;
60
+ const _joinPathParts = (_part, i, parts) => (0, import_compiled.lodash)(parts).filter((part) => !["/", "\\"].includes(part)).tap((parts2) => parts2.unshift("")).slice(0, i + 2).join("/");
48
61
  function upwardPaths(start) {
49
- return (0, compiled_1.lodash)(start)
50
- .split(/[/\\]/)
51
- .filter(Boolean)
52
- .map(exports._joinPathParts)
53
- .reverse()
54
- .push('/')
55
- .value();
62
+ return (0, import_compiled.lodash)(start).split(/[/\\]/).filter(Boolean).map(_joinPathParts).reverse().push("/").value();
56
63
  }
57
- exports.upwardPaths = upwardPaths;
58
64
  function getRealTemporaryDirectory() {
59
- let ret = null;
60
- try {
61
- ret = os_1.default.tmpdir();
62
- ret = fs_1.default.realpathSync(ret);
63
- }
64
- catch { }
65
- return ret;
65
+ let ret = null;
66
+ try {
67
+ ret = import_os.default.tmpdir();
68
+ ret = import_fs.default.realpathSync(ret);
69
+ } catch (e) {
70
+ }
71
+ return ret;
66
72
  }
67
- exports.getRealTemporaryDirectory = getRealTemporaryDirectory;
68
73
  function splitPathString(str) {
69
- return str.split(/[\\/]/);
74
+ return str.split(/[\\/]/);
70
75
  }
71
- exports.splitPathString = splitPathString;
76
+ // Annotate the CommonJS export names for ESM import in node:
77
+ 0 && (module.exports = {
78
+ _joinPathParts,
79
+ compilePathMatcherRegExp,
80
+ getRealTemporaryDirectory,
81
+ getTemplatePath,
82
+ isPathString,
83
+ isRelativePath,
84
+ normalizeOutputPath,
85
+ normalizeToPosixPath,
86
+ splitPathString,
87
+ upwardPaths
88
+ });
@@ -1,16 +1,16 @@
1
1
  /** Different from */
2
- export type PathMatchExpression = string | RegExp;
2
+ export declare type PathMatchExpression = string | RegExp;
3
3
  export interface PathMatcher {
4
- match: PathMatchExpression;
5
- mark: string | ((substring: string, ...args: any[]) => string);
4
+ match: PathMatchExpression;
5
+ mark: string | ((substring: string, ...args: any[]) => string);
6
6
  }
7
7
  export declare const matchUpwardPathsAsUnknown: (p: string) => {
8
- match: string;
9
- mark: string;
8
+ match: string;
9
+ mark: string;
10
10
  }[];
11
11
  export interface ApplyPathMatcherOptions {
12
- minPartials?: number;
12
+ minPartials?: number;
13
13
  }
14
14
  export declare function applyPathMatcher(matcher: PathMatcher, str: string, options?: ApplyPathMatcherOptions): string;
15
15
  export declare function applyMatcherReplacement(matchers: PathMatcher[], str: string, options?: ApplyPathMatcherOptions): string;
16
- export declare const createDefaultPathMatchers: (root: string) => PathMatcher[];
16
+ export declare const createDefaultPathMatchers: (root: string) => PathMatcher[];
@@ -1,50 +1,72 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __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 });
4
10
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createDefaultPathMatchers = exports.applyMatcherReplacement = exports.applyPathMatcher = exports.matchUpwardPathsAsUnknown = void 0;
7
- const os_1 = __importDefault(require("os"));
8
- const lodash_1 = __importDefault(require("../compiled/lodash"));
9
- const path_1 = require("./path");
10
- const matchUpwardPathsAsUnknown = (p) => (0, lodash_1.default)((0, path_1.upwardPaths)((0, path_1.normalizeToPosixPath)(p)))
11
- .map(match => ({ match, mark: 'unknown' }))
12
- .slice(1, -1)
13
- .value();
14
- exports.matchUpwardPathsAsUnknown = matchUpwardPathsAsUnknown;
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
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
23
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
+ var pathSerializer_exports = {};
25
+ __export(pathSerializer_exports, {
26
+ applyMatcherReplacement: () => applyMatcherReplacement,
27
+ applyPathMatcher: () => applyPathMatcher,
28
+ createDefaultPathMatchers: () => createDefaultPathMatchers,
29
+ matchUpwardPathsAsUnknown: () => matchUpwardPathsAsUnknown
30
+ });
31
+ module.exports = __toCommonJS(pathSerializer_exports);
32
+ var import_os = __toESM(require("os"));
33
+ var import_lodash = __toESM(require("../compiled/lodash"));
34
+ var import_path = require("./path");
35
+ 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();
15
36
  function applyPathMatcher(matcher, str, options = {}) {
16
- const regex = (0, path_1.compilePathMatcherRegExp)(matcher.match);
17
- const replacer = (substring, ...args) => {
18
- if (options.minPartials &&
19
- (0, path_1.splitPathString)(substring).length < options.minPartials) {
20
- return substring;
21
- }
22
- const ret = typeof matcher.mark === 'string'
23
- ? matcher.mark
24
- : matcher.mark(substring, ...args);
25
- return `<${lodash_1.default.snakeCase(ret).toUpperCase()}>`;
26
- };
27
- return str.replace(regex, replacer);
37
+ const regex = (0, import_path.compilePathMatcherRegExp)(matcher.match);
38
+ const replacer = (substring, ...args) => {
39
+ if (options.minPartials && (0, import_path.splitPathString)(substring).length < options.minPartials) {
40
+ return substring;
41
+ }
42
+ const ret = typeof matcher.mark === "string" ? matcher.mark : matcher.mark(substring, ...args);
43
+ return `<${import_lodash.default.snakeCase(ret).toUpperCase()}>`;
44
+ };
45
+ return str.replace(regex, replacer);
28
46
  }
29
- exports.applyPathMatcher = applyPathMatcher;
30
47
  function applyMatcherReplacement(matchers, str, options = {}) {
31
- return matchers.reduce((ret, matcher) => {
32
- return applyPathMatcher(matcher, ret, options);
33
- }, str);
48
+ return matchers.reduce((ret, matcher) => {
49
+ return applyPathMatcher(matcher, ret, options);
50
+ }, str);
34
51
  }
35
- exports.applyMatcherReplacement = applyMatcherReplacement;
36
52
  const createDefaultPathMatchers = (root) => {
37
- const ret = [
38
- {
39
- match: /(?<=\/)(\.pnpm\/.+?\/node_modules)(?=\/)/,
40
- mark: 'pnpmInner',
41
- },
42
- ];
43
- const tmpdir = (0, path_1.getRealTemporaryDirectory)();
44
- tmpdir && ret.push({ match: tmpdir, mark: 'temp' });
45
- ret.push({ match: os_1.default.tmpdir(), mark: 'temp' });
46
- ret.push({ match: os_1.default.homedir(), mark: 'home' });
47
- ret.push(...(0, exports.matchUpwardPathsAsUnknown)(root));
48
- return ret;
53
+ const ret = [
54
+ {
55
+ match: new RegExp("(?<=\\/)(\\.pnpm\\/.+?\\/node_modules)(?=\\/)"),
56
+ mark: "pnpmInner"
57
+ }
58
+ ];
59
+ const tmpdir = (0, import_path.getRealTemporaryDirectory)();
60
+ tmpdir && ret.push({ match: tmpdir, mark: "temp" });
61
+ ret.push({ match: import_os.default.tmpdir(), mark: "temp" });
62
+ ret.push({ match: import_os.default.homedir(), mark: "home" });
63
+ ret.push(...matchUpwardPathsAsUnknown(root));
64
+ return ret;
49
65
  };
50
- exports.createDefaultPathMatchers = createDefaultPathMatchers;
66
+ // Annotate the CommonJS export names for ESM import in node:
67
+ 0 && (module.exports = {
68
+ applyMatcherReplacement,
69
+ applyPathMatcher,
70
+ createDefaultPathMatchers,
71
+ matchUpwardPathsAsUnknown
72
+ });
package/dist/plugin.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  import { InternalPlugins } from '@modern-js/types';
2
- export declare function getInternalPlugins(appDirectory: string, internalPlugins?: InternalPlugins): string[];
2
+ export declare function getInternalPlugins(appDirectory: string, internalPlugins?: InternalPlugins): string[];
package/dist/plugin.js CHANGED
@@ -1,27 +1,46 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getInternalPlugins = void 0;
4
- const constants_1 = require("./constants");
5
- const is_1 = require("./is");
6
- function getInternalPlugins(appDirectory, internalPlugins = constants_1.INTERNAL_CLI_PLUGINS) {
7
- return [
8
- ...Object.keys(internalPlugins)
9
- .filter(name => {
10
- const config = internalPlugins[name];
11
- if (typeof config !== 'string' && config.forced === true) {
12
- return true;
13
- }
14
- return (0, is_1.isDepExists)(appDirectory, name);
15
- })
16
- .map(name => {
17
- const config = internalPlugins[name];
18
- if (typeof config !== 'string') {
19
- return config.path;
20
- }
21
- else {
22
- return config;
23
- }
24
- }),
25
- ];
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
+ ];
26
42
  }
27
- exports.getInternalPlugins = getInternalPlugins;
43
+ // Annotate the CommonJS export names for ESM import in node:
44
+ 0 && (module.exports = {
45
+ getInternalPlugins
46
+ });