@modern-js/utils 3.1.2 → 3.1.4

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.
@@ -33,6 +33,9 @@ var __webpack_modules__ = {
33
33
  "./logger" (module) {
34
34
  module.exports = require("./logger.js");
35
35
  },
36
+ "./modulePath" (module) {
37
+ module.exports = require("./modulePath.js");
38
+ },
36
39
  "./monorepo" (module) {
37
40
  module.exports = require("./monorepo.js");
38
41
  },
@@ -191,6 +194,10 @@ var __webpack_exports__ = {};
191
194
  var __rspack_reexport = {};
192
195
  for(const __rspack_import_key in _route__rspack_import_20)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_route__rspack_import_20[__rspack_import_key];
193
196
  __webpack_require__.d(__webpack_exports__, __rspack_reexport);
197
+ var _modulePath__rspack_import_21 = __webpack_require__("./modulePath");
198
+ var __rspack_reexport = {};
199
+ for(const __rspack_import_key in _modulePath__rspack_import_21)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_modulePath__rspack_import_21[__rspack_import_key];
200
+ __webpack_require__.d(__webpack_exports__, __rspack_reexport);
194
201
  })();
195
202
  for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
196
203
  Object.defineProperty(exports, '__esModule', {
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = (module)=>{
5
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
+ __webpack_require__.d(getter, {
7
+ a: getter
8
+ });
9
+ return getter;
10
+ };
11
+ })();
12
+ (()=>{
13
+ __webpack_require__.d = (exports1, definition)=>{
14
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
+ enumerable: true,
16
+ get: definition[key]
17
+ });
18
+ };
19
+ })();
20
+ (()=>{
21
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
22
+ })();
23
+ (()=>{
24
+ __webpack_require__.r = (exports1)=>{
25
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
26
+ value: 'Module'
27
+ });
28
+ Object.defineProperty(exports1, '__esModule', {
29
+ value: true
30
+ });
31
+ };
32
+ })();
33
+ var __webpack_exports__ = {};
34
+ __webpack_require__.r(__webpack_exports__);
35
+ __webpack_require__.d(__webpack_exports__, {
36
+ SOURCE_EXTENSIONS: ()=>SOURCE_EXTENSIONS,
37
+ findMatchedSourcePath: ()=>findMatchedSourcePath,
38
+ findSourceEntry: ()=>findSourceEntry,
39
+ JS_LIKE_EXTENSION_RE: ()=>JS_LIKE_EXTENSION_RE
40
+ });
41
+ const external_node_fs_namespaceObject = require("node:fs");
42
+ var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
43
+ const external_node_path_namespaceObject = require("node:path");
44
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
45
+ const SOURCE_EXTENSIONS = [
46
+ '.ts',
47
+ '.js'
48
+ ];
49
+ const JS_LIKE_EXTENSION_RE = /\.(?:c|m)?js$/;
50
+ const isFile = (filepath)=>external_node_fs_default().existsSync(filepath) && external_node_fs_default().statSync(filepath).isFile();
51
+ const findSourceEntry = (resolvedPath)=>{
52
+ const ext = external_node_path_default().extname(resolvedPath);
53
+ if (ext) {
54
+ if (isFile(resolvedPath)) return resolvedPath;
55
+ if (JS_LIKE_EXTENSION_RE.test(resolvedPath)) {
56
+ const tsPath = `${resolvedPath.slice(0, -ext.length)}.ts`;
57
+ if (isFile(tsPath)) return tsPath;
58
+ }
59
+ return;
60
+ }
61
+ for (const candidateExt of SOURCE_EXTENSIONS){
62
+ const filePath = `${resolvedPath}${candidateExt}`;
63
+ if (isFile(filePath)) return filePath;
64
+ }
65
+ for (const candidateExt of SOURCE_EXTENSIONS){
66
+ const indexPath = external_node_path_default().join(resolvedPath, `index${candidateExt}`);
67
+ if (isFile(indexPath)) return indexPath;
68
+ }
69
+ };
70
+ const findMatchedSourcePath = (matchPath, specifier)=>{
71
+ let matchedPath = matchPath(specifier, void 0, void 0, SOURCE_EXTENSIONS);
72
+ if (!matchedPath && JS_LIKE_EXTENSION_RE.test(specifier)) matchedPath = matchPath(specifier.replace(JS_LIKE_EXTENSION_RE, ''), void 0, void 0, SOURCE_EXTENSIONS);
73
+ return matchedPath;
74
+ };
75
+ exports.JS_LIKE_EXTENSION_RE = __webpack_exports__.JS_LIKE_EXTENSION_RE;
76
+ exports.SOURCE_EXTENSIONS = __webpack_exports__.SOURCE_EXTENSIONS;
77
+ exports.findMatchedSourcePath = __webpack_exports__.findMatchedSourcePath;
78
+ exports.findSourceEntry = __webpack_exports__.findSourceEntry;
79
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
80
+ "JS_LIKE_EXTENSION_RE",
81
+ "SOURCE_EXTENSIONS",
82
+ "findMatchedSourcePath",
83
+ "findSourceEntry"
84
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
85
+ Object.defineProperty(exports, '__esModule', {
86
+ value: true
87
+ });
@@ -1026,7 +1026,7 @@
1026
1026
  if (Array.isArray(n)) return n;
1027
1027
  else if ("object" == typeof n) {
1028
1028
  if (!n.defaults) n.defaults = [];
1029
- return pickEnv(n, e, s);
1029
+ return pickEnv(n, e);
1030
1030
  }
1031
1031
  }
1032
1032
  throw new o("`" + s + "` config exports not an array of queries or an object of envs");
@@ -594,7 +594,7 @@
594
594
  const flat = (t)=>{
595
595
  for(let s = 0; s < t.length; s++){
596
596
  let r = t[s];
597
- Array.isArray(r) ? flat(r, e) : void 0 !== r && e.push(r);
597
+ Array.isArray(r) ? flat(r) : void 0 !== r && e.push(r);
598
598
  }
599
599
  return e;
600
600
  };
@@ -40,7 +40,7 @@
40
40
  const r = e.emit;
41
41
  e.emit = function(t, o) {
42
42
  if ("exit" === t) {
43
- const t = verifyENOENT(o, n, "spawn");
43
+ const t = verifyENOENT(o, n);
44
44
  if (t) return r.call(e, "error", t);
45
45
  }
46
46
  return r.apply(e, arguments);
@@ -1239,7 +1239,7 @@
1239
1239
  const flat = (t)=>{
1240
1240
  for(let r = 0; r < t.length; r++){
1241
1241
  let n = t[r];
1242
- Array.isArray(n) ? flat(n, e) : void 0 !== n && e.push(n);
1242
+ Array.isArray(n) ? flat(n) : void 0 !== n && e.push(n);
1243
1243
  }
1244
1244
  return e;
1245
1245
  };
@@ -317,7 +317,7 @@
317
317
  case R:
318
318
  return ">" + blockHeader(t, e.indent) + dropEndingNewline(indentString(foldString(t, l), o));
319
319
  case q:
320
- return '"' + escapeString(t, l) + '"';
320
+ return '"' + escapeString(t) + '"';
321
321
  default:
322
322
  throw new n("impossible error: invalid scalar style");
323
323
  }
@@ -816,7 +816,7 @@
816
816
  case false:
817
817
  return "false";
818
818
  }
819
- if ("string" == typeof e) return quoteString(e, false);
819
+ if ("string" == typeof e) return quoteString(e);
820
820
  if ("number" == typeof e) return String(e);
821
821
  if ("object" == typeof e) return Array.isArray(e) ? serializeArray(e) : serializeObject(e);
822
822
  }
@@ -903,10 +903,10 @@
903
903
  return A;
904
904
  }
905
905
  function serializeKey(u) {
906
- if (0 === u.length) return quoteString(u, true);
906
+ if (0 === u.length) return quoteString(u);
907
907
  const D = String.fromCodePoint(u.codePointAt(0));
908
- if (!r.isIdStartChar(D)) return quoteString(u, true);
909
- for(let e = D.length; e < u.length; e++)if (!r.isIdContinueChar(String.fromCodePoint(u.codePointAt(e)))) return quoteString(u, true);
908
+ if (!r.isIdStartChar(D)) return quoteString(u);
909
+ for(let e = D.length; e < u.length; e++)if (!r.isIdContinueChar(String.fromCodePoint(u.codePointAt(e)))) return quoteString(u);
910
910
  return u;
911
911
  }
912
912
  function serializeArray(u) {
@@ -355,7 +355,7 @@
355
355
  const r = s(210);
356
356
  const objectToString = (e, t, s, n)=>{
357
357
  if ("function" == typeof Buffer && Buffer.isBuffer(e)) return `Buffer.from(${s(e.toString("base64"))}, 'base64')`;
358
- if ("object" == typeof global && e === global) return globalToString(e, t, s, n);
358
+ if ("object" == typeof global && e === global) return globalToString(e, t, s);
359
359
  const i = o[Object.prototype.toString.call(e)];
360
360
  return i ? i(e, t, s, n) : void 0;
361
361
  };
@@ -19,3 +19,4 @@ export * from "./watch.mjs";
19
19
  export * from "./config.mjs";
20
20
  export * from "./version.mjs";
21
21
  export * from "./route.mjs";
22
+ export * from "./modulePath.mjs";
@@ -0,0 +1,33 @@
1
+ import node_fs from "node:fs";
2
+ import node_path from "node:path";
3
+ const SOURCE_EXTENSIONS = [
4
+ '.ts',
5
+ '.js'
6
+ ];
7
+ const JS_LIKE_EXTENSION_RE = /\.(?:c|m)?js$/;
8
+ const isFile = (filepath)=>node_fs.existsSync(filepath) && node_fs.statSync(filepath).isFile();
9
+ const findSourceEntry = (resolvedPath)=>{
10
+ const ext = node_path.extname(resolvedPath);
11
+ if (ext) {
12
+ if (isFile(resolvedPath)) return resolvedPath;
13
+ if (JS_LIKE_EXTENSION_RE.test(resolvedPath)) {
14
+ const tsPath = `${resolvedPath.slice(0, -ext.length)}.ts`;
15
+ if (isFile(tsPath)) return tsPath;
16
+ }
17
+ return;
18
+ }
19
+ for (const candidateExt of SOURCE_EXTENSIONS){
20
+ const filePath = `${resolvedPath}${candidateExt}`;
21
+ if (isFile(filePath)) return filePath;
22
+ }
23
+ for (const candidateExt of SOURCE_EXTENSIONS){
24
+ const indexPath = node_path.join(resolvedPath, `index${candidateExt}`);
25
+ if (isFile(indexPath)) return indexPath;
26
+ }
27
+ };
28
+ const findMatchedSourcePath = (matchPath, specifier)=>{
29
+ let matchedPath = matchPath(specifier, void 0, void 0, SOURCE_EXTENSIONS);
30
+ if (!matchedPath && JS_LIKE_EXTENSION_RE.test(specifier)) matchedPath = matchPath(specifier.replace(JS_LIKE_EXTENSION_RE, ''), void 0, void 0, SOURCE_EXTENSIONS);
31
+ return matchedPath;
32
+ };
33
+ export { JS_LIKE_EXTENSION_RE, SOURCE_EXTENSIONS, findMatchedSourcePath, findSourceEntry };
@@ -20,3 +20,4 @@ export * from "./watch.mjs";
20
20
  export * from "./config.mjs";
21
21
  export * from "./version.mjs";
22
22
  export * from "./route.mjs";
23
+ export * from "./modulePath.mjs";
@@ -0,0 +1,34 @@
1
+ import "node:module";
2
+ import node_fs from "node:fs";
3
+ import node_path from "node:path";
4
+ const SOURCE_EXTENSIONS = [
5
+ '.ts',
6
+ '.js'
7
+ ];
8
+ const JS_LIKE_EXTENSION_RE = /\.(?:c|m)?js$/;
9
+ const isFile = (filepath)=>node_fs.existsSync(filepath) && node_fs.statSync(filepath).isFile();
10
+ const findSourceEntry = (resolvedPath)=>{
11
+ const ext = node_path.extname(resolvedPath);
12
+ if (ext) {
13
+ if (isFile(resolvedPath)) return resolvedPath;
14
+ if (JS_LIKE_EXTENSION_RE.test(resolvedPath)) {
15
+ const tsPath = `${resolvedPath.slice(0, -ext.length)}.ts`;
16
+ if (isFile(tsPath)) return tsPath;
17
+ }
18
+ return;
19
+ }
20
+ for (const candidateExt of SOURCE_EXTENSIONS){
21
+ const filePath = `${resolvedPath}${candidateExt}`;
22
+ if (isFile(filePath)) return filePath;
23
+ }
24
+ for (const candidateExt of SOURCE_EXTENSIONS){
25
+ const indexPath = node_path.join(resolvedPath, `index${candidateExt}`);
26
+ if (isFile(indexPath)) return indexPath;
27
+ }
28
+ };
29
+ const findMatchedSourcePath = (matchPath, specifier)=>{
30
+ let matchedPath = matchPath(specifier, void 0, void 0, SOURCE_EXTENSIONS);
31
+ if (!matchedPath && JS_LIKE_EXTENSION_RE.test(specifier)) matchedPath = matchPath(specifier.replace(JS_LIKE_EXTENSION_RE, ''), void 0, void 0, SOURCE_EXTENSIONS);
32
+ return matchedPath;
33
+ };
34
+ export { JS_LIKE_EXTENSION_RE, SOURCE_EXTENSIONS, findMatchedSourcePath, findSourceEntry };
@@ -19,3 +19,4 @@ export * from './watch';
19
19
  export * from './config';
20
20
  export * from './version';
21
21
  export * from './route';
22
+ export * from './modulePath';
@@ -0,0 +1,5 @@
1
+ import type { MatchPath } from '../../compiled/tsconfig-paths';
2
+ export declare const SOURCE_EXTENSIONS: string[];
3
+ export declare const JS_LIKE_EXTENSION_RE: RegExp;
4
+ export declare const findSourceEntry: (resolvedPath: string) => string | undefined;
5
+ export declare const findMatchedSourcePath: (matchPath: MatchPath, specifier: string) => string | undefined;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "3.1.2",
18
+ "version": "3.1.4",
19
19
  "types": "./dist/types/index.d.ts",
20
20
  "main": "./dist/cjs/index.js",
21
21
  "module": "./dist/esm/index.mjs",
@@ -142,13 +142,13 @@
142
142
  "rslog": "^1.3.2"
143
143
  },
144
144
  "devDependencies": {
145
- "@rslib/core": "0.20.3",
145
+ "@rslib/core": "0.21.0",
146
146
  "@types/node": "^20",
147
- "happy-dom": "^20.8.4",
147
+ "happy-dom": "^20.8.9",
148
148
  "typescript": "^5",
149
149
  "@modern-js/rslib": "2.68.10",
150
- "@scripts/rstest-config": "2.66.0",
151
- "@modern-js/types": "3.1.2"
150
+ "@modern-js/types": "3.1.4",
151
+ "@scripts/rstest-config": "2.66.0"
152
152
  },
153
153
  "peerDependencies": {
154
154
  "react": "^19.2.4",