ts-swc-transform 2.7.10 → 2.8.1

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.
@@ -5,3 +5,4 @@
5
5
  export declare function stringStartsWith(str: string, search: string, position?: number): boolean;
6
6
  export declare function stringEndsWith(str: string, search: string, position?: number): boolean;
7
7
  export declare function stringReplaceAll(str: string, search: string, replace: string): string;
8
+ export declare function arrayFind<T>(arr: T[], predicate: (item: T, index: number, arr: T[]) => boolean): T | undefined;
@@ -5,3 +5,4 @@
5
5
  export declare function stringStartsWith(str: string, search: string, position?: number): boolean;
6
6
  export declare function stringEndsWith(str: string, search: string, position?: number): boolean;
7
7
  export declare function stringReplaceAll(str: string, search: string, replace: string): string;
8
+ export declare function arrayFind<T>(arr: T[], predicate: (item: T, index: number, arr: T[]) => boolean): T | undefined;
@@ -9,6 +9,9 @@ function _export(target, all) {
9
9
  });
10
10
  }
11
11
  _export(exports, {
12
+ get arrayFind () {
13
+ return arrayFind;
14
+ },
12
15
  get stringEndsWith () {
13
16
  return stringEndsWith;
14
17
  },
@@ -61,4 +64,18 @@ function stringReplaceAll(str, search, replace) {
61
64
  var escaped = search.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
62
65
  return str.replace(new RegExp(escaped, 'g'), replace);
63
66
  }
67
+ /**
68
+ * Array.prototype.find wrapper for Node.js 0.8+
69
+ * - Uses native find on Node 4.0+ / ES2015+
70
+ * - Falls back to loop on Node 0.8-3.x
71
+ */ var hasArrayFind = typeof Array.prototype.find === 'function';
72
+ function arrayFind(arr, predicate) {
73
+ if (hasArrayFind) {
74
+ return arr.find(predicate);
75
+ }
76
+ for(var i = 0; i < arr.length; i++){
77
+ if (predicate(arr[i], i, arr)) return arr[i];
78
+ }
79
+ return undefined;
80
+ }
64
81
  /* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/compat.ts"],"sourcesContent":["/**\n * Compatibility Layer for Node.js 0.8+\n * Local to this package - contains only needed functions.\n */\n\n/**\n * String.prototype.startsWith wrapper for Node.js 0.8+\n * - Uses native startsWith on Node 4.0+ / ES2015+\n * - Falls back to indexOf on Node 0.8-3.x\n */\nconst hasStartsWith = typeof String.prototype.startsWith === 'function';\n\nexport function stringStartsWith(str: string, search: string, position?: number): boolean {\n if (hasStartsWith) {\n return str.startsWith(search, position);\n }\n position = position || 0;\n return str.indexOf(search, position) === position;\n}\n\n/**\n * String.prototype.endsWith wrapper for Node.js 0.8+\n * - Uses native endsWith on Node 4.0+ / ES2015+\n * - Falls back to lastIndexOf on Node 0.8-3.x\n */\nconst hasEndsWith = typeof String.prototype.endsWith === 'function';\n\nexport function stringEndsWith(str: string, search: string, position?: number): boolean {\n if (hasEndsWith) {\n return str.endsWith(search, position);\n }\n const len = position === undefined ? str.length : position;\n return str.lastIndexOf(search) === len - search.length;\n}\n\n/**\n * String.prototype.replaceAll wrapper for Node.js 0.8+\n * - Uses native replaceAll on Node 15.0+ / ES2021+\n * - Falls back to regex replace on older versions\n */\n// biome-ignore lint/suspicious/noExplicitAny: Feature detection for ES2021 replaceAll\nconst hasReplaceAll = typeof (String.prototype as any).replaceAll === 'function';\n\nexport function stringReplaceAll(str: string, search: string, replace: string): string {\n if (hasReplaceAll) {\n // biome-ignore lint/suspicious/noExplicitAny: Using native replaceAll when available\n return (str as any).replaceAll(search, replace);\n }\n // Escape special regex characters\n const escaped = search.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n return str.replace(new RegExp(escaped, 'g'), replace);\n}\n"],"names":["stringEndsWith","stringReplaceAll","stringStartsWith","hasStartsWith","String","prototype","startsWith","str","search","position","indexOf","hasEndsWith","endsWith","len","undefined","length","lastIndexOf","hasReplaceAll","replaceAll","replace","escaped","RegExp"],"mappings":";;;;;;;;;;;QA2BgBA;eAAAA;;QAgBAC;eAAAA;;QA/BAC;eAAAA;;;AAZhB;;;CAGC,GAED;;;;CAIC,GACD,IAAMC,gBAAgB,OAAOC,OAAOC,SAAS,CAACC,UAAU,KAAK;AAEtD,SAASJ,iBAAiBK,GAAW,EAAEC,MAAc,EAAEC,QAAiB;IAC7E,IAAIN,eAAe;QACjB,OAAOI,IAAID,UAAU,CAACE,QAAQC;IAChC;IACAA,WAAWA,YAAY;IACvB,OAAOF,IAAIG,OAAO,CAACF,QAAQC,cAAcA;AAC3C;AAEA;;;;CAIC,GACD,IAAME,cAAc,OAAOP,OAAOC,SAAS,CAACO,QAAQ,KAAK;AAElD,SAASZ,eAAeO,GAAW,EAAEC,MAAc,EAAEC,QAAiB;IAC3E,IAAIE,aAAa;QACf,OAAOJ,IAAIK,QAAQ,CAACJ,QAAQC;IAC9B;IACA,IAAMI,MAAMJ,aAAaK,YAAYP,IAAIQ,MAAM,GAAGN;IAClD,OAAOF,IAAIS,WAAW,CAACR,YAAYK,MAAML,OAAOO,MAAM;AACxD;AAEA;;;;CAIC,GACD,sFAAsF;AACtF,IAAME,gBAAgB,OAAO,AAACb,OAAOC,SAAS,CAASa,UAAU,KAAK;AAE/D,SAASjB,iBAAiBM,GAAW,EAAEC,MAAc,EAAEW,OAAe;IAC3E,IAAIF,eAAe;QACjB,qFAAqF;QACrF,OAAO,AAACV,IAAYW,UAAU,CAACV,QAAQW;IACzC;IACA,kCAAkC;IAClC,IAAMC,UAAUZ,OAAOW,OAAO,CAAC,uBAAuB;IACtD,OAAOZ,IAAIY,OAAO,CAAC,IAAIE,OAAOD,SAAS,MAAMD;AAC/C"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/compat.ts"],"sourcesContent":["/**\n * Compatibility Layer for Node.js 0.8+\n * Local to this package - contains only needed functions.\n */\n\n/**\n * String.prototype.startsWith wrapper for Node.js 0.8+\n * - Uses native startsWith on Node 4.0+ / ES2015+\n * - Falls back to indexOf on Node 0.8-3.x\n */\nconst hasStartsWith = typeof String.prototype.startsWith === 'function';\n\nexport function stringStartsWith(str: string, search: string, position?: number): boolean {\n if (hasStartsWith) {\n return str.startsWith(search, position);\n }\n position = position || 0;\n return str.indexOf(search, position) === position;\n}\n\n/**\n * String.prototype.endsWith wrapper for Node.js 0.8+\n * - Uses native endsWith on Node 4.0+ / ES2015+\n * - Falls back to lastIndexOf on Node 0.8-3.x\n */\nconst hasEndsWith = typeof String.prototype.endsWith === 'function';\n\nexport function stringEndsWith(str: string, search: string, position?: number): boolean {\n if (hasEndsWith) {\n return str.endsWith(search, position);\n }\n const len = position === undefined ? str.length : position;\n return str.lastIndexOf(search) === len - search.length;\n}\n\n/**\n * String.prototype.replaceAll wrapper for Node.js 0.8+\n * - Uses native replaceAll on Node 15.0+ / ES2021+\n * - Falls back to regex replace on older versions\n */\n// biome-ignore lint/suspicious/noExplicitAny: Feature detection for ES2021 replaceAll\nconst hasReplaceAll = typeof (String.prototype as any).replaceAll === 'function';\n\nexport function stringReplaceAll(str: string, search: string, replace: string): string {\n if (hasReplaceAll) {\n // biome-ignore lint/suspicious/noExplicitAny: Using native replaceAll when available\n return (str as any).replaceAll(search, replace);\n }\n // Escape special regex characters\n const escaped = search.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n return str.replace(new RegExp(escaped, 'g'), replace);\n}\n\n/**\n * Array.prototype.find wrapper for Node.js 0.8+\n * - Uses native find on Node 4.0+ / ES2015+\n * - Falls back to loop on Node 0.8-3.x\n */\nconst hasArrayFind = typeof Array.prototype.find === 'function';\n\nexport function arrayFind<T>(arr: T[], predicate: (item: T, index: number, arr: T[]) => boolean): T | undefined {\n if (hasArrayFind) {\n return arr.find(predicate);\n }\n for (let i = 0; i < arr.length; i++) {\n if (predicate(arr[i], i, arr)) return arr[i];\n }\n return undefined;\n}\n"],"names":["arrayFind","stringEndsWith","stringReplaceAll","stringStartsWith","hasStartsWith","String","prototype","startsWith","str","search","position","indexOf","hasEndsWith","endsWith","len","undefined","length","lastIndexOf","hasReplaceAll","replaceAll","replace","escaped","RegExp","hasArrayFind","Array","find","arr","predicate","i"],"mappings":";;;;;;;;;;;QA4DgBA;eAAAA;;QAjCAC;eAAAA;;QAgBAC;eAAAA;;QA/BAC;eAAAA;;;AAZhB;;;CAGC,GAED;;;;CAIC,GACD,IAAMC,gBAAgB,OAAOC,OAAOC,SAAS,CAACC,UAAU,KAAK;AAEtD,SAASJ,iBAAiBK,GAAW,EAAEC,MAAc,EAAEC,QAAiB;IAC7E,IAAIN,eAAe;QACjB,OAAOI,IAAID,UAAU,CAACE,QAAQC;IAChC;IACAA,WAAWA,YAAY;IACvB,OAAOF,IAAIG,OAAO,CAACF,QAAQC,cAAcA;AAC3C;AAEA;;;;CAIC,GACD,IAAME,cAAc,OAAOP,OAAOC,SAAS,CAACO,QAAQ,KAAK;AAElD,SAASZ,eAAeO,GAAW,EAAEC,MAAc,EAAEC,QAAiB;IAC3E,IAAIE,aAAa;QACf,OAAOJ,IAAIK,QAAQ,CAACJ,QAAQC;IAC9B;IACA,IAAMI,MAAMJ,aAAaK,YAAYP,IAAIQ,MAAM,GAAGN;IAClD,OAAOF,IAAIS,WAAW,CAACR,YAAYK,MAAML,OAAOO,MAAM;AACxD;AAEA;;;;CAIC,GACD,sFAAsF;AACtF,IAAME,gBAAgB,OAAO,AAACb,OAAOC,SAAS,CAASa,UAAU,KAAK;AAE/D,SAASjB,iBAAiBM,GAAW,EAAEC,MAAc,EAAEW,OAAe;IAC3E,IAAIF,eAAe;QACjB,qFAAqF;QACrF,OAAO,AAACV,IAAYW,UAAU,CAACV,QAAQW;IACzC;IACA,kCAAkC;IAClC,IAAMC,UAAUZ,OAAOW,OAAO,CAAC,uBAAuB;IACtD,OAAOZ,IAAIY,OAAO,CAAC,IAAIE,OAAOD,SAAS,MAAMD;AAC/C;AAEA;;;;CAIC,GACD,IAAMG,eAAe,OAAOC,MAAMlB,SAAS,CAACmB,IAAI,KAAK;AAE9C,SAASzB,UAAa0B,GAAQ,EAAEC,SAAwD;IAC7F,IAAIJ,cAAc;QAChB,OAAOG,IAAID,IAAI,CAACE;IAClB;IACA,IAAK,IAAIC,IAAI,GAAGA,IAAIF,IAAIV,MAAM,EAAEY,IAAK;QACnC,IAAID,UAAUD,GAAG,CAACE,EAAE,EAAEA,GAAGF,MAAM,OAAOA,GAAG,CAACE,EAAE;IAC9C;IACA,OAAOb;AACT"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Lightweight ESM exports field resolver
3
+ * Uses resolve.exports (952 bytes) instead of import-meta-resolve (64KB)
4
+ *
5
+ * Only loaded on Node >= 12.2 where module.createRequire exists.
6
+ * On older Node, toPath.ts skips this and falls back to resolve.sync().
7
+ *
8
+ * This implementation handles packages with ONLY an exports field (no main),
9
+ * which the resolve package cannot handle on its own.
10
+ */
11
+ /**
12
+ * Resolve a module specifier using the exports field in package.json
13
+ * This implementation directly finds the package and reads its exports,
14
+ * bypassing the resolve package which can't handle exports-only packages.
15
+ */
16
+ export default function resolveWithExports(specifier: string, basedir: string, conditions?: string[]): string | null;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Lightweight ESM exports field resolver
3
+ * Uses resolve.exports (952 bytes) instead of import-meta-resolve (64KB)
4
+ *
5
+ * Only loaded on Node >= 12.2 where module.createRequire exists.
6
+ * On older Node, toPath.ts skips this and falls back to resolve.sync().
7
+ *
8
+ * This implementation handles packages with ONLY an exports field (no main),
9
+ * which the resolve package cannot handle on its own.
10
+ */
11
+ /**
12
+ * Resolve a module specifier using the exports field in package.json
13
+ * This implementation directly finds the package and reads its exports,
14
+ * bypassing the resolve package which can't handle exports-only packages.
15
+ */
16
+ export default function resolveWithExports(specifier: string, basedir: string, conditions?: string[]): string | null;
@@ -0,0 +1,157 @@
1
+ /**
2
+ * Lightweight ESM exports field resolver
3
+ * Uses resolve.exports (952 bytes) instead of import-meta-resolve (64KB)
4
+ *
5
+ * Only loaded on Node >= 12.2 where module.createRequire exists.
6
+ * On older Node, toPath.ts skips this and falls back to resolve.sync().
7
+ *
8
+ * This implementation handles packages with ONLY an exports field (no main),
9
+ * which the resolve package cannot handle on its own.
10
+ */ "use strict";
11
+ Object.defineProperty(exports, "__esModule", {
12
+ value: true
13
+ });
14
+ Object.defineProperty(exports, /**
15
+ * Resolve a module specifier using the exports field in package.json
16
+ * This implementation directly finds the package and reads its exports,
17
+ * bypassing the resolve package which can't handle exports-only packages.
18
+ */ "default", {
19
+ enumerable: true,
20
+ get: function() {
21
+ return resolveWithExports;
22
+ }
23
+ });
24
+ var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
25
+ var _module = /*#__PURE__*/ _interop_require_default(require("module"));
26
+ var _path = /*#__PURE__*/ _interop_require_default(require("path"));
27
+ function _interop_require_default(obj) {
28
+ return obj && obj.__esModule ? obj : {
29
+ default: obj
30
+ };
31
+ }
32
+ var _resolveExports = null;
33
+ function getResolveExports() {
34
+ if (_resolveExports === null) {
35
+ try {
36
+ // Use dynamic require to avoid loading on older Node versions
37
+ var _require = typeof require === 'undefined' ? _module.default.createRequire(require("url").pathToFileURL(__filename).toString()) : require;
38
+ _resolveExports = _require('resolve.exports');
39
+ } catch (_) {
40
+ // If resolve.exports fails to load, return null
41
+ // This shouldn't happen on Node >= 12.2, but handle gracefully
42
+ _resolveExports = null;
43
+ }
44
+ }
45
+ return _resolveExports;
46
+ }
47
+ /**
48
+ * Parse a specifier into package name and subpath
49
+ * "lodash" → { pkgName: "lodash", subpath: "." }
50
+ * "lodash/get" → { pkgName: "lodash", subpath: "./get" }
51
+ * "@scope/pkg" → { pkgName: "@scope/pkg", subpath: "." }
52
+ * "@scope/pkg/foo" → { pkgName: "@scope/pkg", subpath: "./foo" }
53
+ */ function parseSpecifier(specifier) {
54
+ var parts = specifier.split('/');
55
+ var pkgName = specifier[0] === '@' ? parts.slice(0, 2).join('/') : parts[0];
56
+ var remainder = specifier.slice(pkgName.length);
57
+ var subpath = remainder ? ".".concat(remainder) : '.';
58
+ return {
59
+ pkgName: pkgName,
60
+ subpath: subpath
61
+ };
62
+ }
63
+ /**
64
+ * Find the package.json for a package by walking up node_modules
65
+ */ function findPackageJson(pkgName, basedir) {
66
+ var dir = basedir;
67
+ var root = _path.default.parse(dir).root;
68
+ while(dir !== root){
69
+ var candidate = _path.default.join(dir, 'node_modules', pkgName, 'package.json');
70
+ try {
71
+ if (_fs.default.existsSync(candidate)) {
72
+ return candidate;
73
+ }
74
+ } catch (_) {
75
+ // Ignore filesystem errors
76
+ }
77
+ var parent = _path.default.dirname(dir);
78
+ if (parent === dir) break;
79
+ dir = parent;
80
+ }
81
+ return null;
82
+ }
83
+ /**
84
+ * Read and parse a package.json file
85
+ */ function readPackageJson(pkgJsonPath) {
86
+ try {
87
+ var content = _fs.default.readFileSync(pkgJsonPath, 'utf8');
88
+ return JSON.parse(content);
89
+ } catch (_) {
90
+ return null;
91
+ }
92
+ }
93
+ function resolveWithExports(specifier, basedir) {
94
+ var conditions = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : [
95
+ 'node',
96
+ 'import'
97
+ ];
98
+ var resolveExportsMod = getResolveExports();
99
+ if (!resolveExportsMod) {
100
+ // resolve.exports not available, return null to trigger fallback
101
+ return null;
102
+ }
103
+ var resolveExportsFn = resolveExportsMod.exports, legacy = resolveExportsMod.legacy;
104
+ var _parseSpecifier = parseSpecifier(specifier), pkgName = _parseSpecifier.pkgName, subpath = _parseSpecifier.subpath;
105
+ // Find the package.json
106
+ var pkgJsonPath = findPackageJson(pkgName, basedir);
107
+ if (!pkgJsonPath) {
108
+ return null;
109
+ }
110
+ // Read package.json
111
+ var pkg = readPackageJson(pkgJsonPath);
112
+ if (!pkg) {
113
+ return null;
114
+ }
115
+ var pkgDir = _path.default.dirname(pkgJsonPath);
116
+ // Try exports field first
117
+ try {
118
+ var resolved = resolveExportsFn(pkg, subpath, {
119
+ conditions: conditions
120
+ });
121
+ if (resolved === null || resolved === void 0 ? void 0 : resolved[0]) {
122
+ return _path.default.join(pkgDir, resolved[0]);
123
+ }
124
+ } catch (_) {
125
+ // exports field parsing failed, try legacy
126
+ }
127
+ // Try legacy main/module fields
128
+ try {
129
+ var legacyMain = legacy(pkg);
130
+ if (legacyMain) {
131
+ // legacy() can return string, string[], or browser field object
132
+ var mainPath;
133
+ if (typeof legacyMain === 'string') {
134
+ mainPath = legacyMain;
135
+ } else if (Array.isArray(legacyMain)) {
136
+ mainPath = legacyMain[0];
137
+ }
138
+ // Ignore browser field objects (they map file paths, not entry points)
139
+ if (mainPath) {
140
+ return _path.default.join(pkgDir, mainPath);
141
+ }
142
+ }
143
+ } catch (_) {
144
+ // legacy parsing failed
145
+ }
146
+ // Last resort: try index.js
147
+ var indexPath = _path.default.join(pkgDir, 'index.js');
148
+ try {
149
+ if (_fs.default.existsSync(indexPath)) {
150
+ return indexPath;
151
+ }
152
+ } catch (_) {
153
+ // Ignore
154
+ }
155
+ return null;
156
+ }
157
+ /* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/resolve-with-exports.ts"],"sourcesContent":["/**\n * Lightweight ESM exports field resolver\n * Uses resolve.exports (952 bytes) instead of import-meta-resolve (64KB)\n *\n * Only loaded on Node >= 12.2 where module.createRequire exists.\n * On older Node, toPath.ts skips this and falls back to resolve.sync().\n *\n * This implementation handles packages with ONLY an exports field (no main),\n * which the resolve package cannot handle on its own.\n */\n\nimport fs from 'fs';\nimport Module from 'module';\nimport path from 'path';\n\n// Lazy-load resolve.exports to avoid requiring it on older Node versions\n// resolve.exports requires Node >= 10, but this code only runs on Node >= 12.2\ntype ResolveExportsModule = typeof import('resolve.exports');\nlet _resolveExports: ResolveExportsModule | null = null;\n\nfunction getResolveExports(): ResolveExportsModule | null {\n if (_resolveExports === null) {\n try {\n // Use dynamic require to avoid loading on older Node versions\n const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n _resolveExports = _require('resolve.exports') as ResolveExportsModule;\n } catch (_) {\n // If resolve.exports fails to load, return null\n // This shouldn't happen on Node >= 12.2, but handle gracefully\n _resolveExports = null;\n }\n }\n return _resolveExports;\n}\n\n/**\n * Parse a specifier into package name and subpath\n * \"lodash\" → { pkgName: \"lodash\", subpath: \".\" }\n * \"lodash/get\" → { pkgName: \"lodash\", subpath: \"./get\" }\n * \"@scope/pkg\" → { pkgName: \"@scope/pkg\", subpath: \".\" }\n * \"@scope/pkg/foo\" → { pkgName: \"@scope/pkg\", subpath: \"./foo\" }\n */\nfunction parseSpecifier(specifier: string): { pkgName: string; subpath: string } {\n const parts = specifier.split('/');\n const pkgName = specifier[0] === '@' ? parts.slice(0, 2).join('/') : parts[0];\n const remainder = specifier.slice(pkgName.length);\n const subpath = remainder ? `.${remainder}` : '.';\n return { pkgName, subpath };\n}\n\n/**\n * Find the package.json for a package by walking up node_modules\n */\nfunction findPackageJson(pkgName: string, basedir: string): string | null {\n let dir = basedir;\n const root = path.parse(dir).root;\n\n while (dir !== root) {\n const candidate = path.join(dir, 'node_modules', pkgName, 'package.json');\n try {\n if (fs.existsSync(candidate)) {\n return candidate;\n }\n } catch (_) {\n // Ignore filesystem errors\n }\n const parent = path.dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n\n return null;\n}\n\n/**\n * Read and parse a package.json file\n */\nfunction readPackageJson(pkgJsonPath: string): Record<string, unknown> | null {\n try {\n const content = fs.readFileSync(pkgJsonPath, 'utf8');\n return JSON.parse(content);\n } catch (_) {\n return null;\n }\n}\n\n/**\n * Resolve a module specifier using the exports field in package.json\n * This implementation directly finds the package and reads its exports,\n * bypassing the resolve package which can't handle exports-only packages.\n */\nexport default function resolveWithExports(specifier: string, basedir: string, conditions: string[] = ['node', 'import']): string | null {\n const resolveExportsMod = getResolveExports();\n if (!resolveExportsMod) {\n // resolve.exports not available, return null to trigger fallback\n return null;\n }\n\n const { exports: resolveExportsFn, legacy } = resolveExportsMod;\n const { pkgName, subpath } = parseSpecifier(specifier);\n\n // Find the package.json\n const pkgJsonPath = findPackageJson(pkgName, basedir);\n if (!pkgJsonPath) {\n return null;\n }\n\n // Read package.json\n const pkg = readPackageJson(pkgJsonPath);\n if (!pkg) {\n return null;\n }\n\n const pkgDir = path.dirname(pkgJsonPath);\n\n // Try exports field first\n try {\n const resolved = resolveExportsFn(pkg, subpath, { conditions });\n if (resolved?.[0]) {\n return path.join(pkgDir, resolved[0]);\n }\n } catch (_) {\n // exports field parsing failed, try legacy\n }\n\n // Try legacy main/module fields\n try {\n const legacyMain = legacy(pkg);\n if (legacyMain) {\n // legacy() can return string, string[], or browser field object\n let mainPath: string | undefined;\n if (typeof legacyMain === 'string') {\n mainPath = legacyMain;\n } else if (Array.isArray(legacyMain)) {\n mainPath = legacyMain[0];\n }\n // Ignore browser field objects (they map file paths, not entry points)\n if (mainPath) {\n return path.join(pkgDir, mainPath);\n }\n }\n } catch (_) {\n // legacy parsing failed\n }\n\n // Last resort: try index.js\n const indexPath = path.join(pkgDir, 'index.js');\n try {\n if (fs.existsSync(indexPath)) {\n return indexPath;\n }\n } catch (_) {\n // Ignore\n }\n\n return null;\n}\n"],"names":["resolveWithExports","_resolveExports","getResolveExports","_require","require","Module","createRequire","_","parseSpecifier","specifier","parts","split","pkgName","slice","join","remainder","length","subpath","findPackageJson","basedir","dir","root","path","parse","candidate","fs","existsSync","parent","dirname","readPackageJson","pkgJsonPath","content","readFileSync","JSON","conditions","resolveExportsMod","exports","resolveExportsFn","legacy","pkg","pkgDir","resolved","legacyMain","mainPath","Array","isArray","indexPath"],"mappings":"AAAA;;;;;;;;;CASC;;;;+BA6ED;;;;CAIC,GACD;;;eAAwBA;;;yDAhFT;6DACI;2DACF;;;;;;AAKjB,IAAIC,kBAA+C;AAEnD,SAASC;IACP,IAAID,oBAAoB,MAAM;Q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0B,QAAQ;IACpC,IAAI;QACF,IAAIf,WAAE,CAACC,UAAU,CAACoB,YAAY;YAC5B,OAAOA;QACT;IACF,EAAE,OAAOvC,GAAG;IACV,SAAS;IACX;IAEA,OAAO;AACT"}
@@ -9,8 +9,8 @@ Object.defineProperty(exports, "default", {
9
9
  }
10
10
  });
11
11
  var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
12
- var _lodashfind = /*#__PURE__*/ _interop_require_default(require("lodash.find"));
13
12
  var _path = /*#__PURE__*/ _interop_require_default(require("path"));
13
+ var _compatts = require("./compat.js");
14
14
  var _constantsts = require("./constants.js");
15
15
  var _toPathts = /*#__PURE__*/ _interop_require_default(require("./toPath.js"));
16
16
  function _interop_require_default(obj) {
@@ -30,7 +30,7 @@ function resolveFileSync(specifier, context) {
30
30
  try {
31
31
  if (stat && stat.isDirectory() || specifier[specifier.length - 1] === '/') {
32
32
  var items = _fs.default.readdirSync(filePath);
33
- var item = (0, _lodashfind.default)(indexExtensions, function(x) {
33
+ var item = (0, _compatts.arrayFind)(indexExtensions, function(x) {
34
34
  return items.indexOf(x) !== -1;
35
35
  });
36
36
  if (item) return _path.default.join(filePath, item);
@@ -38,7 +38,7 @@ function resolveFileSync(specifier, context) {
38
38
  var ext = _path.default.extname(filePath);
39
39
  var basename = ext ? _path.default.basename(filePath).slice(0, -ext.length) : _path.default.basename(filePath);
40
40
  var items1 = _fs.default.readdirSync(_path.default.dirname(filePath));
41
- var item1 = (0, _lodashfind.default)(items1, function(x) {
41
+ var item1 = (0, _compatts.arrayFind)(items1, function(x) {
42
42
  if (_constantsts.typeFileRegEx.test(x)) return false;
43
43
  var extTest = _path.default.extname(x);
44
44
  var basenameTest = extTest ? _path.default.basename(x).slice(0, -extTest.length) : _path.default.basename(x);
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/resolveFileSync.ts"],"sourcesContent":["import fs from 'fs';\nimport find from 'lodash.find';\nimport path from 'path';\nimport { extensions, moduleRegEx, typeFileRegEx } from './constants.ts';\nimport toPath from './toPath.ts';\nimport type { Context } from './types.ts';\n\nconst indexExtensions = extensions.map((x) => `index${x}`);\n\nexport default function resolveFileSync(specifier: string, context?: Context): string {\n const filePath = toPath(specifier, context);\n let stat: fs.Stats;\n try {\n stat = fs.statSync(filePath);\n } catch (_err) {}\n try {\n if ((stat && stat.isDirectory()) || specifier[specifier.length - 1] === '/') {\n const items = fs.readdirSync(filePath);\n const item = find(indexExtensions, (x) => items.indexOf(x) !== -1);\n if (item) return path.join(filePath, item);\n } else if (!stat && !moduleRegEx.test(specifier)) {\n const ext = path.extname(filePath);\n const basename = ext ? path.basename(filePath).slice(0, -ext.length) : path.basename(filePath);\n const items = fs.readdirSync(path.dirname(filePath));\n const item = find(items, (x) => {\n if (typeFileRegEx.test(x)) return false;\n const extTest = path.extname(x);\n const basenameTest = extTest ? path.basename(x).slice(0, -extTest.length) : path.basename(x);\n return basename === basenameTest;\n });\n if (item) return path.join(path.dirname(filePath), item);\n }\n // return what was found\n return stat ? filePath : null;\n } catch (_err) {\n return null;\n }\n}\n"],"names":["resolveFileSync","indexExtensions","extensions","map","x","specifier","context","filePath","toPath","stat","fs","statSync","_err","isDirectory","length","items","readdirSync","item","find","indexOf","path","join","moduleRegEx","test","ext","extname","basename","slice","dirname","typeFileRegEx","extTest","basenameTest"],"mappings":";;;;+BASA;;;eAAwBA;;;yDATT;iEACE;2DACA;2BACsC;+DACpC;;;;;;AAGnB,IAAMC,kBAAkBC,uBAAU,CAACC,GAAG,CAAC,SAACC;WAAM,AAAC,QAAS,OAAFA;;AAEvC,SAASJ,gBAAgBK,SAAiB,EAAEC,OAAiB;IAC1E,IAAMC,WAAWC,IAAAA,iBAAM,EAACH,WAAWC;IACnC,IAAIG;IACJ,IAAI;QACFA,OAAOC,WAAE,CAACC,QAAQ,CAACJ;IACrB,EAAE,OAAOK,MAAM,CAAC;IAChB,IAAI;QACF,IAAI,AAACH,QAAQA,KAAKI,WAAW,MAAOR,SAAS,CAACA,UAAUS,MAAM,GAAG,EAAE,KAAK,KAAK;YAC3E,IAAMC,QAAQL,WAAE,CAACM,WAAW,CAACT;YAC7B,IAAMU,OAAOC,IAAAA,mBAAI,EAACjB,iBAAiB,SAACG;uBAAMW,MAAMI,OAAO,CAACf,OAAO,CAAC;;YAChE,IAAIa,MAAM,OAAOG,aAAI,CAACC,IAAI,CAACd,UAAUU;QACvC,OAAO,IAAI,CAACR,QAAQ,CAACa,wBAAW,CAACC,IAAI,CAAClB,YAAY;YAChD,IAAMmB,MAAMJ,aAAI,CAACK,OAAO,CAAClB;YACzB,IAAMmB,WAAWF,MAAMJ,aAAI,CAACM,QAAQ,CAACnB,UAAUoB,KAAK,CAAC,GAAG,CAACH,IAAIV,MAAM,IAAIM,aAAI,CAACM,QAAQ,CAACnB;YACrF,IAAMQ,SAAQL,WAAE,CAACM,WAAW,CAACI,aAAI,CAACQ,OAAO,CAACrB;YAC1C,IAAMU,QAAOC,IAAAA,mBAAI,EAACH,QAAO,SAACX;gBACxB,IAAIyB,0BAAa,CAACN,IAAI,CAACnB,IAAI,OAAO;gBAClC,IAAM0B,UAAUV,aAAI,CAACK,OAAO,CAACrB;gBAC7B,IAAM2B,eAAeD,UAAUV,aAAI,CAACM,QAAQ,CAACtB,GAAGuB,KAAK,CAAC,GAAG,CAACG,QAAQhB,MAAM,IAAIM,aAAI,CAACM,QAAQ,CAACtB;gBAC1F,OAAOsB,aAAaK;YACtB;YACA,IAAId,OAAM,OAAOG,aAAI,CAACC,IAAI,CAACD,aAAI,CAACQ,OAAO,CAACrB,WAAWU;QACrD;QACA,wBAAwB;QACxB,OAAOR,OAAOF,WAAW;IAC3B,EAAE,OAAOK,MAAM;QACb,OAAO;IACT;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/resolveFileSync.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport { arrayFind } from './compat.ts';\nimport { extensions, moduleRegEx, typeFileRegEx } from './constants.ts';\nimport toPath from './toPath.ts';\nimport type { Context } from './types.ts';\n\nconst indexExtensions = extensions.map((x) => `index${x}`);\n\nexport default function resolveFileSync(specifier: string, context?: Context): string {\n const filePath = toPath(specifier, context);\n let stat: fs.Stats;\n try {\n stat = fs.statSync(filePath);\n } catch (_err) {}\n try {\n if ((stat && stat.isDirectory()) || specifier[specifier.length - 1] === '/') {\n const items = fs.readdirSync(filePath);\n const item = arrayFind(indexExtensions, (x) => items.indexOf(x) !== -1);\n if (item) return path.join(filePath, item);\n } else if (!stat && !moduleRegEx.test(specifier)) {\n const ext = path.extname(filePath);\n const basename = ext ? path.basename(filePath).slice(0, -ext.length) : path.basename(filePath);\n const items = fs.readdirSync(path.dirname(filePath));\n const item = arrayFind(items, (x) => {\n if (typeFileRegEx.test(x)) return false;\n const extTest = path.extname(x);\n const basenameTest = extTest ? path.basename(x).slice(0, -extTest.length) : path.basename(x);\n return basename === basenameTest;\n });\n if (item) return path.join(path.dirname(filePath), item);\n }\n // return what was found\n return stat ? filePath : null;\n } catch (_err) {\n return null;\n }\n}\n"],"names":["resolveFileSync","indexExtensions","extensions","map","x","specifier","context","filePath","toPath","stat","fs","statSync","_err","isDirectory","length","items","readdirSync","item","arrayFind","indexOf","path","join","moduleRegEx","test","ext","extname","basename","slice","dirname","typeFileRegEx","extTest","basenameTest"],"mappings":";;;;+BASA;;;eAAwBA;;;yDATT;2DACE;wBACS;2BAC6B;+DACpC;;;;;;AAGnB,IAAMC,kBAAkBC,uBAAU,CAACC,GAAG,CAAC,SAACC;WAAM,AAAC,QAAS,OAAFA;;AAEvC,SAASJ,gBAAgBK,SAAiB,EAAEC,OAAiB;IAC1E,IAAMC,WAAWC,IAAAA,iBAAM,EAACH,WAAWC;IACnC,IAAIG;IACJ,IAAI;QACFA,OAAOC,WAAE,CAACC,QAAQ,CAACJ;IACrB,EAAE,OAAOK,MAAM,CAAC;IAChB,IAAI;QACF,IAAI,AAACH,QAAQA,KAAKI,WAAW,MAAOR,SAAS,CAACA,UAAUS,MAAM,GAAG,EAAE,KAAK,KAAK;YAC3E,IAAMC,QAAQL,WAAE,CAACM,WAAW,CAACT;YAC7B,IAAMU,OAAOC,IAAAA,mBAAS,EAACjB,iBAAiB,SAACG;uBAAMW,MAAMI,OAAO,CAACf,OAAO,CAAC;;YACrE,IAAIa,MAAM,OAAOG,aAAI,CAACC,IAAI,CAACd,UAAUU;QACvC,OAAO,IAAI,CAACR,QAAQ,CAACa,wBAAW,CAACC,IAAI,CAAClB,YAAY;YAChD,IAAMmB,MAAMJ,aAAI,CAACK,OAAO,CAAClB;YACzB,IAAMmB,WAAWF,MAAMJ,aAAI,CAACM,QAAQ,CAACnB,UAAUoB,KAAK,CAAC,GAAG,CAACH,IAAIV,MAAM,IAAIM,aAAI,CAACM,QAAQ,CAACnB;YACrF,IAAMQ,SAAQL,WAAE,CAACM,WAAW,CAACI,aAAI,CAACQ,OAAO,CAACrB;YAC1C,IAAMU,QAAOC,IAAAA,mBAAS,EAACH,QAAO,SAACX;gBAC7B,IAAIyB,0BAAa,CAACN,IAAI,CAACnB,IAAI,OAAO;gBAClC,IAAM0B,UAAUV,aAAI,CAACK,OAAO,CAACrB;gBAC7B,IAAM2B,eAAeD,UAAUV,aAAI,CAACM,QAAQ,CAACtB,GAAGuB,KAAK,CAAC,GAAG,CAACG,QAAQhB,MAAM,IAAIM,aAAI,CAACM,QAAQ,CAACtB;gBAC1F,OAAOsB,aAAaK;YACtB;YACA,IAAId,OAAM,OAAOG,aAAI,CAACC,IAAI,CAACD,aAAI,CAACQ,OAAO,CAACrB,WAAWU;QACrD;QACA,wBAAwB;QACxB,OAAOR,OAAOF,WAAW;IAC3B,EAAE,OAAOK,MAAM;QACb,OAAO;IACT;AACF"}
@@ -15,7 +15,7 @@ var _resolve = /*#__PURE__*/ _interop_require_wildcard(require("resolve"));
15
15
  var _url = /*#__PURE__*/ _interop_require_default(require("url"));
16
16
  var _compatts = require("./compat.js");
17
17
  var _constantsts = require("./constants.js");
18
- var _importmetaresolvets = /*#__PURE__*/ _interop_require_default(require("./lib/import-meta-resolve.js"));
18
+ var _resolvewithexportsts = /*#__PURE__*/ _interop_require_default(require("./lib/resolve-with-exports.js"));
19
19
  var _urlFileUrlts = /*#__PURE__*/ _interop_require_wildcard(require("./lib/urlFileUrl.js"));
20
20
  function _interop_require_default(obj) {
21
21
  return obj && obj.__esModule ? obj : {
@@ -67,7 +67,6 @@ var _resolve_default;
67
67
  var resolveSync = ((_resolve_default = _resolve.default) !== null && _resolve_default !== void 0 ? _resolve_default : _resolve).sync;
68
68
  var useCJS = !_module.default.createRequire;
69
69
  var fileURLToPath = _url.default.fileURLToPath || _urlFileUrlts.fileURLToPath;
70
- var pathToFileURL = _url.default.pathToFileURL || _urlFileUrlts.pathToFileURL;
71
70
  function getParentPath(context) {
72
71
  if (context.parentPath) return _path.default.dirname(context.parentPath);
73
72
  return context.parentURL ? _path.default.dirname(toPath(context.parentURL)) : process.cwd();
@@ -83,12 +82,12 @@ function toPath(specifier, context) {
83
82
  var parentPath1 = context ? getParentPath(context) : process.cwd();
84
83
  if (!useCJS) {
85
84
  try {
86
- var entryURL = (0, _importmetaresolvets.default)(specifier, pathToFileURL(parentPath1));
87
- if (entryURL) return fileURLToPath(entryURL);
85
+ var entryPath = (0, _resolvewithexportsts.default)(specifier, parentPath1);
86
+ if (entryPath) return entryPath;
88
87
  } catch (_) {
89
88
  /* it may fail due to commonjs edge cases */ }
90
89
  }
91
- var entryPath = resolveSync(specifier, {
90
+ var entryPath1 = resolveSync(specifier, {
92
91
  basedir: parentPath1,
93
92
  extensions: [
94
93
  '.js',
@@ -97,7 +96,7 @@ function toPath(specifier, context) {
97
96
  '.mjs'
98
97
  ]
99
98
  });
100
- if (entryPath) return entryPath;
99
+ if (entryPath1) return entryPath1;
101
100
  }
102
101
  return specifier;
103
102
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/toPath.ts"],"sourcesContent":["import isAbsolute from 'is-absolute';\nimport module from 'module';\nimport path from 'path';\nimport * as resolve from 'resolve';\nimport url from 'url';\n\nimport { stringStartsWith } from './compat.ts';\nimport { moduleRegEx } from './constants.ts';\nimport importMetaResolve from './lib/import-meta-resolve.ts';\nimport * as urlPolyfills from './lib/urlFileUrl.ts';\nimport type { Context } from './types.ts';\n\nconst resolveSync = (resolve.default ?? resolve).sync;\n\nconst useCJS = !module.createRequire;\nconst fileURLToPath = url.fileURLToPath || urlPolyfills.fileURLToPath;\nconst pathToFileURL = url.pathToFileURL || urlPolyfills.pathToFileURL;\n\nfunction getParentPath(context: Context): string {\n if (context.parentPath) return path.dirname(context.parentPath);\n return context.parentURL ? path.dirname(toPath(context.parentURL)) : process.cwd();\n}\n\nexport default function toPath(specifier: string, context?: Context): string {\n if (stringStartsWith(specifier, 'file:')) return fileURLToPath(specifier);\n if (isAbsolute(specifier)) return specifier;\n if (specifier[0] === '.') {\n const parentPath = context ? getParentPath(context) : process.cwd();\n return path.join(parentPath, specifier);\n }\n if (moduleRegEx.test(specifier)) {\n const parentPath = context ? getParentPath(context) : process.cwd();\n if (!useCJS) {\n try {\n const entryURL = importMetaResolve(specifier, pathToFileURL(parentPath));\n if (entryURL) return fileURLToPath(entryURL);\n } catch (_) {\n /* it may fail due to commonjs edge cases */\n }\n }\n const entryPath = resolveSync(specifier, {\n basedir: parentPath,\n extensions: ['.js', '.json', '.node', '.mjs'],\n });\n if (entryPath) return entryPath;\n }\n\n return specifier;\n}\n"],"names":["toPath","resolve","resolveSync","default","sync","useCJS","module","createRequire","fileURLToPath","url","urlPolyfills","pathToFileURL","getParentPath","context","parentPath","path","dirname","parentURL","process","cwd","specifier","stringStartsWith","isAbsolute","join","moduleRegEx","test","entryURL","importMetaResolve","_","entryPath","basedir","extensions"],"mappings":";;;;+BAuBA;;;eAAwBA;;;iEAvBD;6DACJ;2DACF;+DACQ;0DACT;wBAEiB;2BACL;0EACE;oEACA;;;;;;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ACA,IAAIF,WAAW,OAAOA;IACxB;IAEA,OAAOT;AACT"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/toPath.ts"],"sourcesContent":["import isAbsolute from 'is-absolute';\nimport module from 'module';\nimport path from 'path';\nimport * as resolve from 'resolve';\nimport url from 'url';\n\nimport { stringStartsWith } from './compat.ts';\nimport { moduleRegEx } from './constants.ts';\nimport resolveWithExports from './lib/resolve-with-exports.ts';\nimport * as urlPolyfills from './lib/urlFileUrl.ts';\nimport type { Context } from './types.ts';\n\nconst resolveSync = (resolve.default ?? resolve).sync;\n\nconst useCJS = !module.createRequire;\nconst fileURLToPath = url.fileURLToPath || urlPolyfills.fileURLToPath;\n\nfunction getParentPath(context: Context): string {\n if (context.parentPath) return path.dirname(context.parentPath);\n return context.parentURL ? path.dirname(toPath(context.parentURL)) : process.cwd();\n}\n\nexport default function toPath(specifier: string, context?: Context): string {\n if (stringStartsWith(specifier, 'file:')) return fileURLToPath(specifier);\n if (isAbsolute(specifier)) return specifier;\n if (specifier[0] === '.') {\n const parentPath = context ? getParentPath(context) : process.cwd();\n return path.join(parentPath, specifier);\n }\n if (moduleRegEx.test(specifier)) {\n const parentPath = context ? getParentPath(context) : process.cwd();\n if (!useCJS) {\n try {\n const entryPath = resolveWithExports(specifier, parentPath);\n if (entryPath) return entryPath;\n } catch (_) {\n /* it may fail due to commonjs edge cases */\n }\n }\n const entryPath = resolveSync(specifier, {\n basedir: parentPath,\n extensions: ['.js', '.json', '.node', '.mjs'],\n });\n if (entryPath) return entryPath;\n }\n\n return specifier;\n}\n"],"names":["toPath","resolve","resolveSync","default","sync","useCJS","module","createRequire","fileURLToPath","url","urlPolyfills","getParentPath","context","parentPath","path","dirname","parentURL","process","cwd","specifier","stringStartsWith","isAbsolute","join","moduleRegEx","test","entryPath","resolveWithExports","_","basedir","extensions"],"mappings":";;;;+BAsBA;;;eAAwBA;;;iEAtBD;6DACJ;2DACF;+DACQ;0DACT;wBAEi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export declare function stringStartsWith(str: string, search: string, position?: number): boolean;
6
6
  export declare function stringEndsWith(str: string, search: string, position?: number): boolean;
7
7
  export declare function stringReplaceAll(str: string, search: string, replace: string): string;
8
+ export declare function arrayFind<T>(arr: T[], predicate: (item: T, index: number, arr: T[]) => boolean): T | undefined;
@@ -40,3 +40,17 @@ export function stringReplaceAll(str, search, replace) {
40
40
  const escaped = search.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
41
41
  return str.replace(new RegExp(escaped, 'g'), replace);
42
42
  }
43
+ /**
44
+ * Array.prototype.find wrapper for Node.js 0.8+
45
+ * - Uses native find on Node 4.0+ / ES2015+
46
+ * - Falls back to loop on Node 0.8-3.x
47
+ */ const hasArrayFind = typeof Array.prototype.find === 'function';
48
+ export function arrayFind(arr, predicate) {
49
+ if (hasArrayFind) {
50
+ return arr.find(predicate);
51
+ }
52
+ for(let i = 0; i < arr.length; i++){
53
+ if (predicate(arr[i], i, arr)) return arr[i];
54
+ }
55
+ return undefined;
56
+ }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/compat.ts"],"sourcesContent":["/**\n * Compatibility Layer for Node.js 0.8+\n * Local to this package - contains only needed functions.\n */\n\n/**\n * String.prototype.startsWith wrapper for Node.js 0.8+\n * - Uses native startsWith on Node 4.0+ / ES2015+\n * - Falls back to indexOf on Node 0.8-3.x\n */\nconst hasStartsWith = typeof String.prototype.startsWith === 'function';\n\nexport function stringStartsWith(str: string, search: string, position?: number): boolean {\n if (hasStartsWith) {\n return str.startsWith(search, position);\n }\n position = position || 0;\n return str.indexOf(search, position) === position;\n}\n\n/**\n * String.prototype.endsWith wrapper for Node.js 0.8+\n * - Uses native endsWith on Node 4.0+ / ES2015+\n * - Falls back to lastIndexOf on Node 0.8-3.x\n */\nconst hasEndsWith = typeof String.prototype.endsWith === 'function';\n\nexport function stringEndsWith(str: string, search: string, position?: number): boolean {\n if (hasEndsWith) {\n return str.endsWith(search, position);\n }\n const len = position === undefined ? str.length : position;\n return str.lastIndexOf(search) === len - search.length;\n}\n\n/**\n * String.prototype.replaceAll wrapper for Node.js 0.8+\n * - Uses native replaceAll on Node 15.0+ / ES2021+\n * - Falls back to regex replace on older versions\n */\n// biome-ignore lint/suspicious/noExplicitAny: Feature detection for ES2021 replaceAll\nconst hasReplaceAll = typeof (String.prototype as any).replaceAll === 'function';\n\nexport function stringReplaceAll(str: string, search: string, replace: string): string {\n if (hasReplaceAll) {\n // biome-ignore lint/suspicious/noExplicitAny: Using native replaceAll when available\n return (str as any).replaceAll(search, replace);\n }\n // Escape special regex characters\n const escaped = search.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n return str.replace(new RegExp(escaped, 'g'), replace);\n}\n"],"names":["hasStartsWith","String","prototype","startsWith","stringStartsWith","str","search","position","indexOf","hasEndsWith","endsWith","stringEndsWith","len","undefined","length","lastIndexOf","hasReplaceAll","replaceAll","stringReplaceAll","replace","escaped","RegExp"],"mappings":"AAAA;;;CAGC,GAED;;;;CAIC,GACD,MAAMA,gBAAgB,OAAOC,OAAOC,SAAS,CAACC,UAAU,KAAK;AAE7D,OAAO,SAASC,iBAAiBC,GAAW,EAAEC,MAAc,EAAEC,QAAiB;IAC7E,IAAIP,eAAe;QACjB,OAAOK,IAAIF,UAAU,CAACG,QAAQC;IAChC;IACAA,WAAWA,YAAY;IACvB,OAAOF,IAAIG,OAAO,CAACF,QAAQC,cAAcA;AAC3C;AAEA;;;;CAIC,GACD,MAAME,cAAc,OAAOR,OAAOC,SAAS,CAACQ,QAAQ,KAAK;AAEzD,OAAO,SAASC,eAAeN,GAAW,EAAEC,MAAc,EAAEC,QAAiB;IAC3E,IAAIE,aAAa;QACf,OAAOJ,IAAIK,QAAQ,CAACJ,QAAQC;IAC9B;IACA,MAAMK,MAAML,aAAaM,YAAYR,IAAIS,MAAM,GAAGP;IAClD,OAAOF,IAAIU,WAAW,CAACT,YAAYM,MAAMN,OAAOQ,MAAM;AACxD;AAEA;;;;CAIC,GACD,sFAAsF;AACtF,MAAME,gBAAgB,OAAO,AAACf,OAAOC,SAAS,CAASe,UAAU,KAAK;AAEtE,OAAO,SAASC,iBAAiBb,GAAW,EAAEC,MAAc,EAAEa,OAAe;IAC3E,IAAIH,eAAe;QACjB,qFAAqF;QACrF,OAAO,AAACX,IAAYY,UAAU,CAACX,QAAQa;IACzC;IACA,kCAAkC;IAClC,MAAMC,UAAUd,OAAOa,OAAO,CAAC,uBAAuB;IACtD,OAAOd,IAAIc,OAAO,CAAC,IAAIE,OAAOD,SAAS,MAAMD;AAC/C"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/compat.ts"],"sourcesContent":["/**\n * Compatibility Layer for Node.js 0.8+\n * Local to this package - contains only needed functions.\n */\n\n/**\n * String.prototype.startsWith wrapper for Node.js 0.8+\n * - Uses native startsWith on Node 4.0+ / ES2015+\n * - Falls back to indexOf on Node 0.8-3.x\n */\nconst hasStartsWith = typeof String.prototype.startsWith === 'function';\n\nexport function stringStartsWith(str: string, search: string, position?: number): boolean {\n if (hasStartsWith) {\n return str.startsWith(search, position);\n }\n position = position || 0;\n return str.indexOf(search, position) === position;\n}\n\n/**\n * String.prototype.endsWith wrapper for Node.js 0.8+\n * - Uses native endsWith on Node 4.0+ / ES2015+\n * - Falls back to lastIndexOf on Node 0.8-3.x\n */\nconst hasEndsWith = typeof String.prototype.endsWith === 'function';\n\nexport function stringEndsWith(str: string, search: string, position?: number): boolean {\n if (hasEndsWith) {\n return str.endsWith(search, position);\n }\n const len = position === undefined ? str.length : position;\n return str.lastIndexOf(search) === len - search.length;\n}\n\n/**\n * String.prototype.replaceAll wrapper for Node.js 0.8+\n * - Uses native replaceAll on Node 15.0+ / ES2021+\n * - Falls back to regex replace on older versions\n */\n// biome-ignore lint/suspicious/noExplicitAny: Feature detection for ES2021 replaceAll\nconst hasReplaceAll = typeof (String.prototype as any).replaceAll === 'function';\n\nexport function stringReplaceAll(str: string, search: string, replace: string): string {\n if (hasReplaceAll) {\n // biome-ignore lint/suspicious/noExplicitAny: Using native replaceAll when available\n return (str as any).replaceAll(search, replace);\n }\n // Escape special regex characters\n const escaped = search.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n return str.replace(new RegExp(escaped, 'g'), replace);\n}\n\n/**\n * Array.prototype.find wrapper for Node.js 0.8+\n * - Uses native find on Node 4.0+ / ES2015+\n * - Falls back to loop on Node 0.8-3.x\n */\nconst hasArrayFind = typeof Array.prototype.find === 'function';\n\nexport function arrayFind<T>(arr: T[], predicate: (item: T, index: number, arr: T[]) => boolean): T | undefined {\n if (hasArrayFind) {\n return arr.find(predicate);\n }\n for (let i = 0; i < arr.length; i++) {\n if (predicate(arr[i], i, arr)) return arr[i];\n }\n return undefined;\n}\n"],"names":["hasStartsWith","String","prototype","startsWith","stringStartsWith","str","search","position","indexOf","hasEndsWith","endsWith","stringEndsWith","len","undefined","length","lastIndexOf","hasReplaceAll","replaceAll","stringReplaceAll","replace","escaped","RegExp","hasArrayFind","Array","find","arrayFind","arr","predicate","i"],"mappings":"AAAA;;;CAGC,GAED;;;;CAIC,GACD,MAAMA,gBAAgB,OAAOC,OAAOC,SAAS,CAACC,UAAU,KAAK;AAE7D,OAAO,SAASC,iBAAiBC,GAAW,EAAEC,MAAc,EAAEC,QAAiB;IAC7E,IAAIP,eAAe;QACjB,OAAOK,IAAIF,UAAU,CAACG,QAAQC;IAChC;IACAA,WAAWA,YAAY;IACvB,OAAOF,IAAIG,OAAO,CAACF,QAAQC,cAAcA;AAC3C;AAEA;;;;CAIC,GACD,MAAME,cAAc,OAAOR,OAAOC,SAAS,CAACQ,QAAQ,KAAK;AAEzD,OAAO,SAASC,eAAeN,GAAW,EAAEC,MAAc,EAAEC,QAAiB;IAC3E,IAAIE,aAAa;QACf,OAAOJ,IAAIK,QAAQ,CAACJ,QAAQC;IAC9B;IACA,MAAMK,MAAML,aAAaM,YAAYR,IAAIS,MAAM,GAAGP;IAClD,OAAOF,IAAIU,WAAW,CAACT,YAAYM,MAAMN,OAAOQ,MAAM;AACxD;AAEA;;;;CAIC,GACD,sFAAsF;AACtF,MAAME,gBAAgB,OAAO,AAACf,OAAOC,SAAS,CAASe,UAAU,KAAK;AAEtE,OAAO,SAASC,iBAAiBb,GAAW,EAAEC,MAAc,EAAEa,OAAe;IAC3E,IAAIH,eAAe;QACjB,qFAAqF;QACrF,OAAO,AAACX,IAAYY,UAAU,CAACX,QAAQa;IACzC;IACA,kCAAkC;IAClC,MAAMC,UAAUd,OAAOa,OAAO,CAAC,uBAAuB;IACtD,OAAOd,IAAIc,OAAO,CAAC,IAAIE,OAAOD,SAAS,MAAMD;AAC/C;AAEA;;;;CAIC,GACD,MAAMG,eAAe,OAAOC,MAAMrB,SAAS,CAACsB,IAAI,KAAK;AAErD,OAAO,SAASC,UAAaC,GAAQ,EAAEC,SAAwD;IAC7F,IAAIL,cAAc;QAChB,OAAOI,IAAIF,IAAI,CAACG;IAClB;IACA,IAAK,IAAIC,IAAI,GAAGA,IAAIF,IAAIZ,MAAM,EAAEc,IAAK;QACnC,IAAID,UAAUD,GAAG,CAACE,EAAE,EAAEA,GAAGF,MAAM,OAAOA,GAAG,CAACE,EAAE;IAC9C;IACA,OAAOf;AACT"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Lightweight ESM exports field resolver
3
+ * Uses resolve.exports (952 bytes) instead of import-meta-resolve (64KB)
4
+ *
5
+ * Only loaded on Node >= 12.2 where module.createRequire exists.
6
+ * On older Node, toPath.ts skips this and falls back to resolve.sync().
7
+ *
8
+ * This implementation handles packages with ONLY an exports field (no main),
9
+ * which the resolve package cannot handle on its own.
10
+ */
11
+ /**
12
+ * Resolve a module specifier using the exports field in package.json
13
+ * This implementation directly finds the package and reads its exports,
14
+ * bypassing the resolve package which can't handle exports-only packages.
15
+ */
16
+ export default function resolveWithExports(specifier: string, basedir: string, conditions?: string[]): string | null;
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Lightweight ESM exports field resolver
3
+ * Uses resolve.exports (952 bytes) instead of import-meta-resolve (64KB)
4
+ *
5
+ * Only loaded on Node >= 12.2 where module.createRequire exists.
6
+ * On older Node, toPath.ts skips this and falls back to resolve.sync().
7
+ *
8
+ * This implementation handles packages with ONLY an exports field (no main),
9
+ * which the resolve package cannot handle on its own.
10
+ */ import fs from 'fs';
11
+ import Module from 'module';
12
+ import path from 'path';
13
+ let _resolveExports = null;
14
+ function getResolveExports() {
15
+ if (_resolveExports === null) {
16
+ try {
17
+ // Use dynamic require to avoid loading on older Node versions
18
+ const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
19
+ _resolveExports = _require('resolve.exports');
20
+ } catch (_) {
21
+ // If resolve.exports fails to load, return null
22
+ // This shouldn't happen on Node >= 12.2, but handle gracefully
23
+ _resolveExports = null;
24
+ }
25
+ }
26
+ return _resolveExports;
27
+ }
28
+ /**
29
+ * Parse a specifier into package name and subpath
30
+ * "lodash" → { pkgName: "lodash", subpath: "." }
31
+ * "lodash/get" → { pkgName: "lodash", subpath: "./get" }
32
+ * "@scope/pkg" → { pkgName: "@scope/pkg", subpath: "." }
33
+ * "@scope/pkg/foo" → { pkgName: "@scope/pkg", subpath: "./foo" }
34
+ */ function parseSpecifier(specifier) {
35
+ const parts = specifier.split('/');
36
+ const pkgName = specifier[0] === '@' ? parts.slice(0, 2).join('/') : parts[0];
37
+ const remainder = specifier.slice(pkgName.length);
38
+ const subpath = remainder ? `.${remainder}` : '.';
39
+ return {
40
+ pkgName,
41
+ subpath
42
+ };
43
+ }
44
+ /**
45
+ * Find the package.json for a package by walking up node_modules
46
+ */ function findPackageJson(pkgName, basedir) {
47
+ let dir = basedir;
48
+ const root = path.parse(dir).root;
49
+ while(dir !== root){
50
+ const candidate = path.join(dir, 'node_modules', pkgName, 'package.json');
51
+ try {
52
+ if (fs.existsSync(candidate)) {
53
+ return candidate;
54
+ }
55
+ } catch (_) {
56
+ // Ignore filesystem errors
57
+ }
58
+ const parent = path.dirname(dir);
59
+ if (parent === dir) break;
60
+ dir = parent;
61
+ }
62
+ return null;
63
+ }
64
+ /**
65
+ * Read and parse a package.json file
66
+ */ function readPackageJson(pkgJsonPath) {
67
+ try {
68
+ const content = fs.readFileSync(pkgJsonPath, 'utf8');
69
+ return JSON.parse(content);
70
+ } catch (_) {
71
+ return null;
72
+ }
73
+ }
74
+ /**
75
+ * Resolve a module specifier using the exports field in package.json
76
+ * This implementation directly finds the package and reads its exports,
77
+ * bypassing the resolve package which can't handle exports-only packages.
78
+ */ export default function resolveWithExports(specifier, basedir, conditions = [
79
+ 'node',
80
+ 'import'
81
+ ]) {
82
+ const resolveExportsMod = getResolveExports();
83
+ if (!resolveExportsMod) {
84
+ // resolve.exports not available, return null to trigger fallback
85
+ return null;
86
+ }
87
+ const { exports: resolveExportsFn, legacy } = resolveExportsMod;
88
+ const { pkgName, subpath } = parseSpecifier(specifier);
89
+ // Find the package.json
90
+ const pkgJsonPath = findPackageJson(pkgName, basedir);
91
+ if (!pkgJsonPath) {
92
+ return null;
93
+ }
94
+ // Read package.json
95
+ const pkg = readPackageJson(pkgJsonPath);
96
+ if (!pkg) {
97
+ return null;
98
+ }
99
+ const pkgDir = path.dirname(pkgJsonPath);
100
+ // Try exports field first
101
+ try {
102
+ const resolved = resolveExportsFn(pkg, subpath, {
103
+ conditions
104
+ });
105
+ if (resolved === null || resolved === void 0 ? void 0 : resolved[0]) {
106
+ return path.join(pkgDir, resolved[0]);
107
+ }
108
+ } catch (_) {
109
+ // exports field parsing failed, try legacy
110
+ }
111
+ // Try legacy main/module fields
112
+ try {
113
+ const legacyMain = legacy(pkg);
114
+ if (legacyMain) {
115
+ // legacy() can return string, string[], or browser field object
116
+ let mainPath;
117
+ if (typeof legacyMain === 'string') {
118
+ mainPath = legacyMain;
119
+ } else if (Array.isArray(legacyMain)) {
120
+ mainPath = legacyMain[0];
121
+ }
122
+ // Ignore browser field objects (they map file paths, not entry points)
123
+ if (mainPath) {
124
+ return path.join(pkgDir, mainPath);
125
+ }
126
+ }
127
+ } catch (_) {
128
+ // legacy parsing failed
129
+ }
130
+ // Last resort: try index.js
131
+ const indexPath = path.join(pkgDir, 'index.js');
132
+ try {
133
+ if (fs.existsSync(indexPath)) {
134
+ return indexPath;
135
+ }
136
+ } catch (_) {
137
+ // Ignore
138
+ }
139
+ return null;
140
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/resolve-with-exports.ts"],"sourcesContent":["/**\n * Lightweight ESM exports field resolver\n * Uses resolve.exports (952 bytes) instead of import-meta-resolve (64KB)\n *\n * Only loaded on Node >= 12.2 where module.createRequire exists.\n * On older Node, toPath.ts skips this and falls back to resolve.sync().\n *\n * This implementation handles packages with ONLY an exports field (no main),\n * which the resolve package cannot handle on its own.\n */\n\nimport fs from 'fs';\nimport Module from 'module';\nimport path from 'path';\n\n// Lazy-load resolve.exports to avoid requiring it on older Node versions\n// resolve.exports requires Node >= 10, but this code only runs on Node >= 12.2\ntype ResolveExportsModule = typeof import('resolve.exports');\nlet _resolveExports: ResolveExportsModule | null = null;\n\nfunction getResolveExports(): ResolveExportsModule | null {\n if (_resolveExports === null) {\n try {\n // Use dynamic require to avoid loading on older Node versions\n const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n _resolveExports = _require('resolve.exports') as ResolveExportsModule;\n } catch (_) {\n // If resolve.exports fails to load, return null\n // This shouldn't happen on Node >= 12.2, but handle gracefully\n _resolveExports = null;\n }\n }\n return _resolveExports;\n}\n\n/**\n * Parse a specifier into package name and subpath\n * \"lodash\" → { pkgName: \"lodash\", subpath: \".\" }\n * \"lodash/get\" → { pkgName: \"lodash\", subpath: \"./get\" }\n * \"@scope/pkg\" → { pkgName: \"@scope/pkg\", subpath: \".\" }\n * \"@scope/pkg/foo\" → { pkgName: \"@scope/pkg\", subpath: \"./foo\" }\n */\nfunction parseSpecifier(specifier: string): { pkgName: string; subpath: string } {\n const parts = specifier.split('/');\n const pkgName = specifier[0] === '@' ? parts.slice(0, 2).join('/') : parts[0];\n const remainder = specifier.slice(pkgName.length);\n const subpath = remainder ? `.${remainder}` : '.';\n return { pkgName, subpath };\n}\n\n/**\n * Find the package.json for a package by walking up node_modules\n */\nfunction findPackageJson(pkgName: string, basedir: string): string | null {\n let dir = basedir;\n const root = path.parse(dir).root;\n\n while (dir !== root) {\n const candidate = path.join(dir, 'node_modules', pkgName, 'package.json');\n try {\n if (fs.existsSync(candidate)) {\n return candidate;\n }\n } catch (_) {\n // Ignore filesystem errors\n }\n const parent = path.dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n\n return null;\n}\n\n/**\n * Read and parse a package.json file\n */\nfunction readPackageJson(pkgJsonPath: string): Record<string, unknown> | null {\n try {\n const content = fs.readFileSync(pkgJsonPath, 'utf8');\n return JSON.parse(content);\n } catch (_) {\n return null;\n }\n}\n\n/**\n * Resolve a module specifier using the exports field in package.json\n * This implementation directly finds the package and reads its exports,\n * bypassing the resolve package which can't handle exports-only packages.\n */\nexport default function resolveWithExports(specifier: string, basedir: string, conditions: string[] = ['node', 'import']): string | null {\n const resolveExportsMod = getResolveExports();\n if (!resolveExportsMod) {\n // resolve.exports not available, return null to trigger fallback\n return null;\n }\n\n const { exports: resolveExportsFn, legacy } = resolveExportsMod;\n const { pkgName, subpath } = parseSpecifier(specifier);\n\n // Find the package.json\n const pkgJsonPath = findPackageJson(pkgName, basedir);\n if (!pkgJsonPath) {\n return null;\n }\n\n // Read package.json\n const pkg = readPackageJson(pkgJsonPath);\n if (!pkg) {\n return null;\n }\n\n const pkgDir = path.dirname(pkgJsonPath);\n\n // Try exports field first\n try {\n const resolved = resolveExportsFn(pkg, subpath, { conditions });\n if (resolved?.[0]) {\n return path.join(pkgDir, resolved[0]);\n }\n } catch (_) {\n // exports field parsing failed, try legacy\n }\n\n // Try legacy main/module fields\n try {\n const legacyMain = legacy(pkg);\n if (legacyMain) {\n // legacy() can return string, string[], or browser field object\n let mainPath: string | undefined;\n if (typeof legacyMain === 'string') {\n mainPath = legacyMain;\n } else if (Array.isArray(legacyMain)) {\n mainPath = legacyMain[0];\n }\n // Ignore browser field objects (they map file paths, not entry points)\n if (mainPath) {\n return path.join(pkgDir, mainPath);\n }\n }\n } catch (_) {\n // legacy parsing failed\n }\n\n // Last resort: try index.js\n const indexPath = path.join(pkgDir, 'index.js');\n try {\n if (fs.existsSync(indexPath)) {\n return indexPath;\n }\n } catch (_) {\n // Ignore\n }\n\n return null;\n}\n"],"names":["fs","Module","path","_resolveExports","getResolveExports","_require","require","createRequire","url","_","parseSpecifier","specifier","parts","split","pkgName","slice","join","remainder","length","subpath","findPackageJson","basedir","dir","root","parse","candidate","existsSync","parent","dirname","readPackageJson","pkgJsonPath","content","readFileSync","JSON","resolveWithExports","conditions","resolveExportsMod","exports","resolveExportsFn","legacy","pkg","pkgDir","resolved","legacyMain","mainPath","Array","isArray","indexPath"],"mappings":"AAAA;;;;;;;;;CASC,GAED,OAAOA,QAAQ,KAAK;AACpB,OAAOC,YAAY,SAAS;AAC5B,OAAOC,UAAU,OAAO;AAKxB,IAAIC,kBAA+C;AAEnD,SAASC;IACP,IAAID,oBAAoB,MAAM;QAC5B,IAAI;YACF,8DAA8D;YAC9D,MAAME,WAAW,OAAOC,YAAY,cAAcL,OAAOM,aAAa,CAAC,YAAYC,GAAG,IAAIF;YAC1FH,kBAAkBE,SAAS;QAC7B,EAAE,OAAOI,GAAG;YACV,gDAAgD;YAChD,+DAA+D;YAC/DN,kBAAkB;QACpB;IACF;IACA,OAAOA;AACT;AAEA;;;;;;CAMC,GACD,SAASO,eAAeC,SAAiB;IACvC,MAAMC,QAAQD,UAAUE,KAAK,CAAC;IAC9B,MAAMC,UAAUH,SAAS,CAAC,EAAE,KAAK,MAAMC,MAAMG,KAAK,CAAC,GAAG,GAAGC,IAAI,CAAC,OAAOJ,KAAK,CAAC,EAAE;IAC7E,MAAMK,YAAYN,UAAUI,KAAK,CAACD,QAA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KAAK0B,OAAO,CAACE;IAE5B,0BAA0B;IAC1B,IAAI;QACF,MAAMY,WAAWJ,iBAAiBE,KAAKrB,SAAS;YAAEgB;QAAW;QAC7D,IAAIO,qBAAAA,+BAAAA,QAAU,CAAC,EAAE,EAAE;YACjB,OAAOxC,KAAKc,IAAI,CAACyB,QAAQC,QAAQ,CAAC,EAAE;QACtC;IACF,EAAE,OAAOjC,GAAG;IACV,2CAA2C;IAC7C;IAEA,gCAAgC;IAChC,IAAI;QACF,MAAMkC,aAAaJ,OAAOC;QAC1B,IAAIG,YAAY;YACd,gEAAgE;YAChE,IAAIC;YACJ,IAAI,OAAOD,eAAe,UAAU;gBAClCC,WAAWD;YACb,OAAO,IAAIE,MAAMC,OAAO,CAACH,aAAa;gBACpCC,WAAWD,UAAU,CAAC,EAAE;YAC1B;YACA,uEAAuE;YACvE,IAAIC,UAAU;gBACZ,OAAO1C,KAAKc,IAAI,CAACyB,QAAQG;YAC3B;QACF;IACF,EAAE,OAAOnC,GAAG;IACV,wBAAwB;IAC1B;IAEA,4BAA4B;IAC5B,MAAMsC,YAAY7C,KAAKc,IAAI,CAACyB,QAAQ;IACpC,IAAI;QACF,IAAIzC,GAAG0B,UAAU,CAACqB,YAAY;YAC5B,OAAOA;QACT;IACF,EAAE,OAAOtC,GAAG;IACV,SAAS;IACX;IAEA,OAAO;AACT"}
@@ -1,6 +1,6 @@
1
1
  import fs from 'fs';
2
- import find from 'lodash.find';
3
2
  import path from 'path';
3
+ import { arrayFind } from './compat.js';
4
4
  import { extensions, moduleRegEx, typeFileRegEx } from './constants.js';
5
5
  import toPath from './toPath.js';
6
6
  const indexExtensions = extensions.map((x)=>`index${x}`);
@@ -13,13 +13,13 @@ export default function resolveFileSync(specifier, context) {
13
13
  try {
14
14
  if (stat && stat.isDirectory() || specifier[specifier.length - 1] === '/') {
15
15
  const items = fs.readdirSync(filePath);
16
- const item = find(indexExtensions, (x)=>items.indexOf(x) !== -1);
16
+ const item = arrayFind(indexExtensions, (x)=>items.indexOf(x) !== -1);
17
17
  if (item) return path.join(filePath, item);
18
18
  } else if (!stat && !moduleRegEx.test(specifier)) {
19
19
  const ext = path.extname(filePath);
20
20
  const basename = ext ? path.basename(filePath).slice(0, -ext.length) : path.basename(filePath);
21
21
  const items = fs.readdirSync(path.dirname(filePath));
22
- const item = find(items, (x)=>{
22
+ const item = arrayFind(items, (x)=>{
23
23
  if (typeFileRegEx.test(x)) return false;
24
24
  const extTest = path.extname(x);
25
25
  const basenameTest = extTest ? path.basename(x).slice(0, -extTest.length) : path.basename(x);