ts-swc-transform 2.8.1 → 2.8.2
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.
- package/dist/cjs/lib/resolveCJS.d.cts +17 -0
- package/dist/cjs/lib/resolveCJS.d.ts +17 -0
- package/dist/cjs/lib/resolveCJS.js +80 -0
- package/dist/cjs/lib/resolveCJS.js.map +1 -0
- package/dist/cjs/lib/resolveESM.d.cts +19 -0
- package/dist/cjs/lib/resolveESM.d.ts +19 -0
- package/dist/cjs/lib/resolveESM.js +180 -0
- package/dist/cjs/lib/resolveESM.js.map +1 -0
- package/dist/cjs/toPath.js +27 -22
- package/dist/cjs/toPath.js.map +1 -1
- package/dist/esm/lib/resolveCJS.d.ts +17 -0
- package/dist/esm/lib/resolveCJS.js +28 -0
- package/dist/esm/lib/resolveCJS.js.map +1 -0
- package/dist/esm/lib/resolveESM.d.ts +19 -0
- package/dist/esm/lib/resolveESM.js +163 -0
- package/dist/esm/lib/resolveESM.js.map +1 -0
- package/dist/esm/toPath.js +26 -21
- package/dist/esm/toPath.js.map +1 -1
- package/package.json +2 -1
- package/dist/cjs/lib/resolve-with-exports.d.cts +0 -16
- package/dist/cjs/lib/resolve-with-exports.d.ts +0 -16
- package/dist/cjs/lib/resolve-with-exports.js +0 -157
- package/dist/cjs/lib/resolve-with-exports.js.map +0 -1
- package/dist/esm/lib/resolve-with-exports.d.ts +0 -16
- package/dist/esm/lib/resolve-with-exports.js +0 -140
- package/dist/esm/lib/resolve-with-exports.js.map +0 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CJS resolver
|
|
3
|
+
*
|
|
4
|
+
* Uses the `resolve` npm package for CommonJS-style module resolution.
|
|
5
|
+
* Handles main field, index.js, etc.
|
|
6
|
+
*
|
|
7
|
+
* Note: CJS does not support subpath imports (#prefix) - those are ESM-only.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Resolve a CJS specifier to an absolute file path
|
|
11
|
+
*
|
|
12
|
+
* @param specifier - The require specifier (e.g., 'lodash', 'lodash/get')
|
|
13
|
+
* @param basedir - The directory to resolve from
|
|
14
|
+
* @returns The resolved absolute file path
|
|
15
|
+
* @throws Error if module cannot be found
|
|
16
|
+
*/
|
|
17
|
+
export default function resolveCJS(specifier: string, basedir: string): string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CJS resolver
|
|
3
|
+
*
|
|
4
|
+
* Uses the `resolve` npm package for CommonJS-style module resolution.
|
|
5
|
+
* Handles main field, index.js, etc.
|
|
6
|
+
*
|
|
7
|
+
* Note: CJS does not support subpath imports (#prefix) - those are ESM-only.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Resolve a CJS specifier to an absolute file path
|
|
11
|
+
*
|
|
12
|
+
* @param specifier - The require specifier (e.g., 'lodash', 'lodash/get')
|
|
13
|
+
* @param basedir - The directory to resolve from
|
|
14
|
+
* @returns The resolved absolute file path
|
|
15
|
+
* @throws Error if module cannot be found
|
|
16
|
+
*/
|
|
17
|
+
export default function resolveCJS(specifier: string, basedir: string): string;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CJS resolver
|
|
3
|
+
*
|
|
4
|
+
* Uses the `resolve` npm package for CommonJS-style module resolution.
|
|
5
|
+
* Handles main field, index.js, etc.
|
|
6
|
+
*
|
|
7
|
+
* Note: CJS does not support subpath imports (#prefix) - those are ESM-only.
|
|
8
|
+
*/ "use strict";
|
|
9
|
+
Object.defineProperty(exports, "__esModule", {
|
|
10
|
+
value: true
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, /**
|
|
13
|
+
* Resolve a CJS specifier to an absolute file path
|
|
14
|
+
*
|
|
15
|
+
* @param specifier - The require specifier (e.g., 'lodash', 'lodash/get')
|
|
16
|
+
* @param basedir - The directory to resolve from
|
|
17
|
+
* @returns The resolved absolute file path
|
|
18
|
+
* @throws Error if module cannot be found
|
|
19
|
+
*/ "default", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function() {
|
|
22
|
+
return resolveCJS;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
var _resolve = /*#__PURE__*/ _interop_require_wildcard(require("resolve"));
|
|
26
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
27
|
+
if (typeof WeakMap !== "function") return null;
|
|
28
|
+
var cacheBabelInterop = new WeakMap();
|
|
29
|
+
var cacheNodeInterop = new WeakMap();
|
|
30
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
31
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
32
|
+
})(nodeInterop);
|
|
33
|
+
}
|
|
34
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
35
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
36
|
+
return obj;
|
|
37
|
+
}
|
|
38
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
39
|
+
return {
|
|
40
|
+
default: obj
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
44
|
+
if (cache && cache.has(obj)) {
|
|
45
|
+
return cache.get(obj);
|
|
46
|
+
}
|
|
47
|
+
var newObj = {
|
|
48
|
+
__proto__: null
|
|
49
|
+
};
|
|
50
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
51
|
+
for(var key in obj){
|
|
52
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
53
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
54
|
+
if (desc && (desc.get || desc.set)) {
|
|
55
|
+
Object.defineProperty(newObj, key, desc);
|
|
56
|
+
} else {
|
|
57
|
+
newObj[key] = obj[key];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
newObj.default = obj;
|
|
62
|
+
if (cache) {
|
|
63
|
+
cache.set(obj, newObj);
|
|
64
|
+
}
|
|
65
|
+
return newObj;
|
|
66
|
+
}
|
|
67
|
+
var _resolve_default;
|
|
68
|
+
var resolveSync = ((_resolve_default = _resolve.default) !== null && _resolve_default !== void 0 ? _resolve_default : _resolve).sync;
|
|
69
|
+
function resolveCJS(specifier, basedir) {
|
|
70
|
+
return resolveSync(specifier, {
|
|
71
|
+
basedir: basedir,
|
|
72
|
+
extensions: [
|
|
73
|
+
'.js',
|
|
74
|
+
'.json',
|
|
75
|
+
'.node',
|
|
76
|
+
'.mjs'
|
|
77
|
+
]
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/* 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/resolveCJS.ts"],"sourcesContent":["/**\n * CJS resolver\n *\n * Uses the `resolve` npm package for CommonJS-style module resolution.\n * Handles main field, index.js, etc.\n *\n * Note: CJS does not support subpath imports (#prefix) - those are ESM-only.\n */\n\nimport * as resolve from 'resolve';\n\nconst resolveSync = (resolve.default ?? resolve).sync;\n\n/**\n * Resolve a CJS specifier to an absolute file path\n *\n * @param specifier - The require specifier (e.g., 'lodash', 'lodash/get')\n * @param basedir - The directory to resolve from\n * @returns The resolved absolute file path\n * @throws Error if module cannot be found\n */\nexport default function resolveCJS(specifier: string, basedir: string): string {\n return resolveSync(specifier, {\n basedir,\n extensions: ['.js', '.json', '.node', '.mjs'],\n });\n}\n"],"names":["resolveCJS","resolve","resolveSync","default","sync","specifier","basedir","extensions"],"mappings":"AAAA;;;;;;;CAOC;;;;+BAMD;;;;;;;CAOC,GACD;;;eAAwBA;;;+DAZC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAEJC;AAArB,IAAMC,cAAc,EAACD,mBAAAA,SAAQE,OAAO,cAAfF,8BAAAA,mBAAmBA,UAASG,IAAI;AAUtC,SAASJ,WAAWK,SAAiB,EAAEC,OAAe;IACnE,OAAOJ,YAAYG,WAAW;QAC5BC,SAAAA;QACAC,YAAY;YAAC;YAAO;YAAS;YAAS;SAAO;IAC/C;AACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified ESM resolver
|
|
3
|
+
*
|
|
4
|
+
* Handles both:
|
|
5
|
+
* - Package exports: import x from 'lodash' → uses exports field
|
|
6
|
+
* - Subpath imports: import x from '#internal' → uses imports field
|
|
7
|
+
*
|
|
8
|
+
* Uses resolve.exports.resolve() which automatically detects the specifier type.
|
|
9
|
+
* Only loaded on Node >= 12.2 where module.createRequire exists.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Resolve an ESM specifier to an absolute file path
|
|
13
|
+
*
|
|
14
|
+
* @param specifier - The import specifier (e.g., 'lodash', 'lodash/get', '#internal')
|
|
15
|
+
* @param parentPath - The file path of the importing module
|
|
16
|
+
* @param conditions - Export conditions (defaults to ['node', 'import'])
|
|
17
|
+
* @returns The resolved absolute file path, or null if not resolvable
|
|
18
|
+
*/
|
|
19
|
+
export default function resolveESM(specifier: string, parentPath: string, conditions?: string[]): string | null;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified ESM resolver
|
|
3
|
+
*
|
|
4
|
+
* Handles both:
|
|
5
|
+
* - Package exports: import x from 'lodash' → uses exports field
|
|
6
|
+
* - Subpath imports: import x from '#internal' → uses imports field
|
|
7
|
+
*
|
|
8
|
+
* Uses resolve.exports.resolve() which automatically detects the specifier type.
|
|
9
|
+
* Only loaded on Node >= 12.2 where module.createRequire exists.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Resolve an ESM specifier to an absolute file path
|
|
13
|
+
*
|
|
14
|
+
* @param specifier - The import specifier (e.g., 'lodash', 'lodash/get', '#internal')
|
|
15
|
+
* @param parentPath - The file path of the importing module
|
|
16
|
+
* @param conditions - Export conditions (defaults to ['node', 'import'])
|
|
17
|
+
* @returns The resolved absolute file path, or null if not resolvable
|
|
18
|
+
*/
|
|
19
|
+
export default function resolveESM(specifier: string, parentPath: string, conditions?: string[]): string | null;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified ESM resolver
|
|
3
|
+
*
|
|
4
|
+
* Handles both:
|
|
5
|
+
* - Package exports: import x from 'lodash' → uses exports field
|
|
6
|
+
* - Subpath imports: import x from '#internal' → uses imports field
|
|
7
|
+
*
|
|
8
|
+
* Uses resolve.exports.resolve() which automatically detects the specifier type.
|
|
9
|
+
* Only loaded on Node >= 12.2 where module.createRequire exists.
|
|
10
|
+
*/ "use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", {
|
|
12
|
+
value: true
|
|
13
|
+
});
|
|
14
|
+
Object.defineProperty(exports, /**
|
|
15
|
+
* Resolve an ESM specifier to an absolute file path
|
|
16
|
+
*
|
|
17
|
+
* @param specifier - The import specifier (e.g., 'lodash', 'lodash/get', '#internal')
|
|
18
|
+
* @param parentPath - The file path of the importing module
|
|
19
|
+
* @param conditions - Export conditions (defaults to ['node', 'import'])
|
|
20
|
+
* @returns The resolved absolute file path, or null if not resolvable
|
|
21
|
+
*/ "default", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function() {
|
|
24
|
+
return resolveESM;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
28
|
+
var _module = /*#__PURE__*/ _interop_require_default(require("module"));
|
|
29
|
+
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
30
|
+
function _interop_require_default(obj) {
|
|
31
|
+
return obj && obj.__esModule ? obj : {
|
|
32
|
+
default: obj
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
var _resolveExports = null;
|
|
36
|
+
function getResolveExports() {
|
|
37
|
+
if (_resolveExports === null) {
|
|
38
|
+
try {
|
|
39
|
+
var _require = typeof require === 'undefined' ? _module.default.createRequire(require("url").pathToFileURL(__filename).toString()) : require;
|
|
40
|
+
_resolveExports = _require('resolve.exports');
|
|
41
|
+
} catch (_) {
|
|
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 package.json in node_modules for external packages
|
|
65
|
+
*/ function findPackageInNodeModules(pkgName, basedir) {
|
|
66
|
+
var dir = basedir;
|
|
67
|
+
var root = _path.default.parse(dir).root;
|
|
68
|
+
while(dir !== root){
|
|
69
|
+
var pkgDir = _path.default.join(dir, 'node_modules', pkgName);
|
|
70
|
+
var pkgJsonPath = _path.default.join(pkgDir, 'package.json');
|
|
71
|
+
try {
|
|
72
|
+
if (_fs.default.existsSync(pkgJsonPath)) {
|
|
73
|
+
var content = _fs.default.readFileSync(pkgJsonPath, 'utf8');
|
|
74
|
+
return {
|
|
75
|
+
dir: pkgDir,
|
|
76
|
+
json: JSON.parse(content)
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
} catch (_) {
|
|
80
|
+
// Ignore filesystem errors
|
|
81
|
+
}
|
|
82
|
+
var parent = _path.default.dirname(dir);
|
|
83
|
+
if (parent === dir) break;
|
|
84
|
+
dir = parent;
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Find the containing package.json by walking up from a file path
|
|
90
|
+
* Used for # subpath imports which are scoped to the containing package
|
|
91
|
+
*/ function findContainingPackage(filePath) {
|
|
92
|
+
var dir = _path.default.dirname(filePath);
|
|
93
|
+
var root = _path.default.parse(dir).root;
|
|
94
|
+
while(dir !== root){
|
|
95
|
+
var pkgJsonPath = _path.default.join(dir, 'package.json');
|
|
96
|
+
try {
|
|
97
|
+
if (_fs.default.existsSync(pkgJsonPath)) {
|
|
98
|
+
var content = _fs.default.readFileSync(pkgJsonPath, 'utf8');
|
|
99
|
+
return {
|
|
100
|
+
dir: dir,
|
|
101
|
+
json: JSON.parse(content)
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
} catch (_) {
|
|
105
|
+
// Ignore filesystem errors
|
|
106
|
+
}
|
|
107
|
+
var parent = _path.default.dirname(dir);
|
|
108
|
+
if (parent === dir) break;
|
|
109
|
+
dir = parent;
|
|
110
|
+
}
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
function resolveESM(specifier, parentPath) {
|
|
114
|
+
var conditions = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : [
|
|
115
|
+
'node',
|
|
116
|
+
'import'
|
|
117
|
+
];
|
|
118
|
+
var resolveExportsMod = getResolveExports();
|
|
119
|
+
if (!resolveExportsMod) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
var resolveFn = resolveExportsMod.resolve, legacy = resolveExportsMod.legacy;
|
|
123
|
+
// Determine how to find the package.json based on specifier type
|
|
124
|
+
var pkg;
|
|
125
|
+
var subpath;
|
|
126
|
+
if (specifier.startsWith('#')) {
|
|
127
|
+
// Subpath import - find containing package
|
|
128
|
+
pkg = findContainingPackage(parentPath);
|
|
129
|
+
subpath = specifier; // resolve.exports expects the full #specifier
|
|
130
|
+
} else {
|
|
131
|
+
// External package - find in node_modules
|
|
132
|
+
var _parseSpecifier = parseSpecifier(specifier), pkgName = _parseSpecifier.pkgName, parsedSubpath = _parseSpecifier.subpath;
|
|
133
|
+
pkg = findPackageInNodeModules(pkgName, parentPath);
|
|
134
|
+
subpath = parsedSubpath;
|
|
135
|
+
}
|
|
136
|
+
if (!pkg) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
// Use resolve.exports.resolve() which handles both exports and imports
|
|
140
|
+
try {
|
|
141
|
+
var resolved = resolveFn(pkg.json, subpath, {
|
|
142
|
+
conditions: conditions
|
|
143
|
+
});
|
|
144
|
+
if (resolved === null || resolved === void 0 ? void 0 : resolved[0]) {
|
|
145
|
+
return _path.default.join(pkg.dir, resolved[0]);
|
|
146
|
+
}
|
|
147
|
+
} catch (_) {
|
|
148
|
+
// Resolution failed, try legacy
|
|
149
|
+
}
|
|
150
|
+
// Try legacy main/module fields for non-# imports
|
|
151
|
+
if (!specifier.startsWith('#')) {
|
|
152
|
+
try {
|
|
153
|
+
var legacyMain = legacy(pkg.json);
|
|
154
|
+
if (legacyMain) {
|
|
155
|
+
var mainPath;
|
|
156
|
+
if (typeof legacyMain === 'string') {
|
|
157
|
+
mainPath = legacyMain;
|
|
158
|
+
} else if (Array.isArray(legacyMain)) {
|
|
159
|
+
mainPath = legacyMain[0];
|
|
160
|
+
}
|
|
161
|
+
if (mainPath) {
|
|
162
|
+
return _path.default.join(pkg.dir, mainPath);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
} catch (_) {
|
|
166
|
+
// Legacy parsing failed
|
|
167
|
+
}
|
|
168
|
+
// Last resort: try index.js
|
|
169
|
+
var indexPath = _path.default.join(pkg.dir, 'index.js');
|
|
170
|
+
try {
|
|
171
|
+
if (_fs.default.existsSync(indexPath)) {
|
|
172
|
+
return indexPath;
|
|
173
|
+
}
|
|
174
|
+
} catch (_) {
|
|
175
|
+
// Ignore
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
/* 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/resolveESM.ts"],"sourcesContent":["/**\n * Unified ESM resolver\n *\n * Handles both:\n * - Package exports: import x from 'lodash' → uses exports field\n * - Subpath imports: import x from '#internal' → uses imports field\n *\n * Uses resolve.exports.resolve() which automatically detects the specifier type.\n * Only loaded on Node >= 12.2 where module.createRequire exists.\n */\n\nimport fs from 'fs';\nimport Module from 'module';\nimport path from 'path';\n\n// Lazy-load resolve.exports\ntype ResolveExportsModule = typeof import('resolve.exports');\nlet _resolveExports: ResolveExportsModule | null = null;\n\nfunction getResolveExports(): ResolveExportsModule | null {\n if (_resolveExports === null) {\n try {\n const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n _resolveExports = _require('resolve.exports') as ResolveExportsModule;\n } catch (_) {\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 package.json in node_modules for external packages\n */\nfunction findPackageInNodeModules(pkgName: string, basedir: string): { dir: string; json: Record<string, unknown> } | null {\n let dir = basedir;\n const root = path.parse(dir).root;\n\n while (dir !== root) {\n const pkgDir = path.join(dir, 'node_modules', pkgName);\n const pkgJsonPath = path.join(pkgDir, 'package.json');\n try {\n if (fs.existsSync(pkgJsonPath)) {\n const content = fs.readFileSync(pkgJsonPath, 'utf8');\n return { dir: pkgDir, json: JSON.parse(content) };\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 * Find the containing package.json by walking up from a file path\n * Used for # subpath imports which are scoped to the containing package\n */\nfunction findContainingPackage(filePath: string): { dir: string; json: Record<string, unknown> } | null {\n let dir = path.dirname(filePath);\n const root = path.parse(dir).root;\n\n while (dir !== root) {\n const pkgJsonPath = path.join(dir, 'package.json');\n try {\n if (fs.existsSync(pkgJsonPath)) {\n const content = fs.readFileSync(pkgJsonPath, 'utf8');\n return { dir, json: JSON.parse(content) };\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 * Resolve an ESM specifier to an absolute file path\n *\n * @param specifier - The import specifier (e.g., 'lodash', 'lodash/get', '#internal')\n * @param parentPath - The file path of the importing module\n * @param conditions - Export conditions (defaults to ['node', 'import'])\n * @returns The resolved absolute file path, or null if not resolvable\n */\nexport default function resolveESM(specifier: string, parentPath: string, conditions: string[] = ['node', 'import']): string | null {\n const resolveExportsMod = getResolveExports();\n if (!resolveExportsMod) {\n return null;\n }\n\n const { resolve: resolveFn, legacy } = resolveExportsMod;\n\n // Determine how to find the package.json based on specifier type\n let pkg: { dir: string; json: Record<string, unknown> } | null;\n let subpath: string;\n\n if (specifier.startsWith('#')) {\n // Subpath import - find containing package\n pkg = findContainingPackage(parentPath);\n subpath = specifier; // resolve.exports expects the full #specifier\n } else {\n // External package - find in node_modules\n const { pkgName, subpath: parsedSubpath } = parseSpecifier(specifier);\n pkg = findPackageInNodeModules(pkgName, parentPath);\n subpath = parsedSubpath;\n }\n\n if (!pkg) {\n return null;\n }\n\n // Use resolve.exports.resolve() which handles both exports and imports\n try {\n const resolved = resolveFn(pkg.json, subpath, { conditions });\n if (resolved?.[0]) {\n return path.join(pkg.dir, resolved[0]);\n }\n } catch (_) {\n // Resolution failed, try legacy\n }\n\n // Try legacy main/module fields for non-# imports\n if (!specifier.startsWith('#')) {\n try {\n const legacyMain = legacy(pkg.json);\n if (legacyMain) {\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 if (mainPath) {\n return path.join(pkg.dir, mainPath);\n }\n }\n } catch (_) {\n // Legacy parsing failed\n }\n\n // Last resort: try index.js\n const indexPath = path.join(pkg.dir, 'index.js');\n try {\n if (fs.existsSync(indexPath)) {\n return indexPath;\n }\n } catch (_) {\n // Ignore\n }\n }\n\n return null;\n}\n"],"names":["resolveESM","_resolveExports","getResolveExports","_require","require","Module","createRequire","_","parseSpecifier","specifier","parts","split","pkgName","slice","join","remainder","length","subpath","findPackageInNodeModules","basedir","dir","root","path","parse","pkgDir","pkgJsonPath","fs","existsSync","content","readFileSync","json","JSON","parent","dirname","findContainingPackage","filePath","parentPath","conditions","resolveExportsMod","resolve","resolveFn","legacy","pkg","startsWith","parsedSubpath","resolved","legacyMain","mainPath","Array","isArray","indexPath"],"mappings":"AAAA;;;;;;;;;CASC;;;;+BAyFD;;;;;;;CAOC,GACD;;;eAAwBA;;;yDA/FT;6DACI;2DACF;;;;;;AAIjB,IAAIC,kBAA+C;AAEnD,SAASC;IACP,IAAID,oBAAoB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EAAE;YACjB,OAAOvB,aAAI,CAACR,IAAI,CAAC4B,IAAItB,GAAG,EAAEyB,QAAQ,CAAC,EAAE;QACvC;IACF,EAAE,OAAOtC,GAAG;IACV,gCAAgC;IAClC;IAEA,kDAAkD;IAClD,IAAI,CAACE,UAAUkC,UAAU,CAAC,MAAM;QAC9B,IAAI;YACF,IAAMG,aAAaL,OAAOC,IAAIZ,IAAI;YAClC,IAAIgB,YAAY;gBACd,IAAIC;gBACJ,IAAI,OAAOD,eAAe,UAAU;oBAClCC,WAAWD;gBACb,OAAO,IAAIE,MAAMC,OAAO,CAACH,aAAa;oBACpCC,WAAWD,UAAU,CAAC,EAAE;gBAC1B;gBACA,IAAIC,UAAU;oBACZ,OAAOzB,aAAI,CAACR,IAAI,CAAC4B,IAAItB,GAAG,EAAE2B;gBAC5B;YACF;QACF,EAAE,OAAOxC,GAAG;QACV,wBAAwB;QAC1B;QAEA,4BAA4B;QAC5B,IAAM2C,YAAY5B,aAAI,CAACR,IAAI,CAAC4B,IAAItB,GAAG,EAAE;QACrC,IAAI;YACF,IAAIM,WAAE,CAACC,UAAU,CAACuB,YAAY;gBAC5B,OAAOA;YACT;QACF,EAAE,OAAO3C,GAAG;QACV,SAAS;QACX;IACF;IAEA,OAAO;AACT"}
|
package/dist/cjs/toPath.js
CHANGED
|
@@ -11,11 +11,11 @@ Object.defineProperty(exports, "default", {
|
|
|
11
11
|
var _isabsolute = /*#__PURE__*/ _interop_require_default(require("is-absolute"));
|
|
12
12
|
var _module = /*#__PURE__*/ _interop_require_default(require("module"));
|
|
13
13
|
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
14
|
-
var _resolve = /*#__PURE__*/ _interop_require_wildcard(require("resolve"));
|
|
15
14
|
var _url = /*#__PURE__*/ _interop_require_default(require("url"));
|
|
16
15
|
var _compatts = require("./compat.js");
|
|
17
16
|
var _constantsts = require("./constants.js");
|
|
18
|
-
var
|
|
17
|
+
var _resolveCJSts = /*#__PURE__*/ _interop_require_default(require("./lib/resolveCJS.js"));
|
|
18
|
+
var _resolveESMts = /*#__PURE__*/ _interop_require_default(require("./lib/resolveESM.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 : {
|
|
@@ -63,40 +63,45 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
63
63
|
}
|
|
64
64
|
return newObj;
|
|
65
65
|
}
|
|
66
|
-
var _resolve_default;
|
|
67
|
-
var resolveSync = ((_resolve_default = _resolve.default) !== null && _resolve_default !== void 0 ? _resolve_default : _resolve).sync;
|
|
68
66
|
var useCJS = !_module.default.createRequire;
|
|
69
67
|
var fileURLToPath = _url.default.fileURLToPath || _urlFileUrlts.fileURLToPath;
|
|
70
68
|
function getParentPath(context) {
|
|
71
69
|
if (context.parentPath) return _path.default.dirname(context.parentPath);
|
|
72
70
|
return context.parentURL ? _path.default.dirname(toPath(context.parentURL)) : process.cwd();
|
|
73
71
|
}
|
|
72
|
+
function getParentFilePath(context) {
|
|
73
|
+
if (context === null || context === void 0 ? void 0 : context.parentPath) return context.parentPath;
|
|
74
|
+
if (context === null || context === void 0 ? void 0 : context.parentURL) return fileURLToPath(context.parentURL);
|
|
75
|
+
return _path.default.join(process.cwd(), 'index.js');
|
|
76
|
+
}
|
|
74
77
|
function toPath(specifier, context) {
|
|
78
|
+
// Handle file:// URLs
|
|
75
79
|
if ((0, _compatts.stringStartsWith)(specifier, 'file:')) return fileURLToPath(specifier);
|
|
80
|
+
// Handle absolute paths
|
|
76
81
|
if ((0, _isabsolute.default)(specifier)) return specifier;
|
|
82
|
+
// Handle relative paths
|
|
77
83
|
if (specifier[0] === '.') {
|
|
78
84
|
var parentPath = context ? getParentPath(context) : process.cwd();
|
|
79
85
|
return _path.default.join(parentPath, specifier);
|
|
80
86
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
// Handle module specifiers (bare specifiers and # imports)
|
|
88
|
+
// moduleRegEx matches: bare specifiers like 'lodash', '@scope/pkg'
|
|
89
|
+
// specifier[0] === '#' matches: subpath imports like '#internal'
|
|
90
|
+
if (_constantsts.moduleRegEx.test(specifier) || specifier[0] === '#') {
|
|
91
|
+
var parentFilePath = getParentFilePath(context);
|
|
92
|
+
var parentDir = _path.default.dirname(parentFilePath);
|
|
93
|
+
if (useCJS) {
|
|
94
|
+
// CJS: use resolve package (does not support # imports)
|
|
95
|
+
if (specifier[0] === '#') {
|
|
96
|
+
throw new Error("Cannot find module '".concat(specifier, "' from '").concat(parentDir, "' (subpath imports not supported in CJS mode)"));
|
|
97
|
+
}
|
|
98
|
+
return (0, _resolveCJSts.default)(specifier, parentDir);
|
|
89
99
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
'.node',
|
|
96
|
-
'.mjs'
|
|
97
|
-
]
|
|
98
|
-
});
|
|
99
|
-
if (entryPath1) return entryPath1;
|
|
100
|
+
// ESM: use unified resolver that handles both exports and imports
|
|
101
|
+
var entryPath = (0, _resolveESMts.default)(specifier, parentFilePath);
|
|
102
|
+
if (entryPath) return entryPath;
|
|
103
|
+
// If ESM resolver failed, throw meaningful error
|
|
104
|
+
throw new Error("Cannot find module '".concat(specifier, "' from '").concat(parentDir, "'"));
|
|
100
105
|
}
|
|
101
106
|
return specifier;
|
|
102
107
|
}
|
package/dist/cjs/toPath.js.map
CHANGED
|
@@ -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
|
|
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 url from 'url';\n\nimport { stringStartsWith } from './compat.ts';\nimport { moduleRegEx } from './constants.ts';\nimport resolveCJS from './lib/resolveCJS.ts';\nimport resolveESM from './lib/resolveESM.ts';\nimport * as urlPolyfills from './lib/urlFileUrl.ts';\nimport type { Context } from './types.ts';\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\nfunction getParentFilePath(context?: Context): string {\n if (context?.parentPath) return context.parentPath;\n if (context?.parentURL) return fileURLToPath(context.parentURL);\n return path.join(process.cwd(), 'index.js');\n}\n\nexport default function toPath(specifier: string, context?: Context): string {\n // Handle file:// URLs\n if (stringStartsWith(specifier, 'file:')) return fileURLToPath(specifier);\n\n // Handle absolute paths\n if (isAbsolute(specifier)) return specifier;\n\n // Handle relative paths\n if (specifier[0] === '.') {\n const parentPath = context ? getParentPath(context) : process.cwd();\n return path.join(parentPath, specifier);\n }\n\n // Handle module specifiers (bare specifiers and # imports)\n // moduleRegEx matches: bare specifiers like 'lodash', '@scope/pkg'\n // specifier[0] === '#' matches: subpath imports like '#internal'\n if (moduleRegEx.test(specifier) || specifier[0] === '#') {\n const parentFilePath = getParentFilePath(context);\n const parentDir = path.dirname(parentFilePath);\n\n if (useCJS) {\n // CJS: use resolve package (does not support # imports)\n if (specifier[0] === '#') {\n throw new Error(`Cannot find module '${specifier}' from '${parentDir}' (subpath imports not supported in CJS mode)`);\n }\n return resolveCJS(specifier, parentDir);\n }\n // ESM: use unified resolver that handles both exports and imports\n const entryPath = resolveESM(specifier, parentFilePath);\n if (entryPath) return entryPath;\n\n // If ESM resolver failed, throw meaningful error\n throw new Error(`Cannot find module '${specifier}' from '${parentDir}'`);\n }\n\n return specifier;\n}\n"],"names":["toPath","useCJS","module","createRequire","fileURLToPath","url","urlPolyfills","getParentPath","context","parentPath","path","dirname","parentURL","process","cwd","getParentFilePath","join","specifier","stringStartsWith","isAbsolute","moduleRegEx","test","parentFilePath","parentDir","Error","resolveCJS","entryPath","resolveESM"],"mappings":";;;;+BA0BA;;;eAAwBA;;;iEA1BD;6DACJ;2DACF;0DACD;wBAEiB;2BACL;mEACL;mEACA;oEACO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAG9B,IAAMC,SAAS,CAACC,eAAM,CAACC,aAAa;AACpC,IAAMC,gBAAgBC,YAAG,CAACD,aAAa,IAAIE,cAAaF,aAAa;AAErE,SAASG,cAAcC,OAAgB;IACrC,IAAIA,QAAQC,UAAU,EAAE,OAAOC,aAAI,CAACC,OAAO,CAACH,QAAQC,UAAU;IAC9D,OAAOD,QAAQI,SAAS,GAAGF,aAAI,CAACC,OAAO,CAACX,OAAOQ,QAAQI,SAAS,KAAKC,QAAQC,GAAG;AAClF;AAEA,SAASC,kBAAkBP,OAAiB;IAC1C,IAAIA,oBAAAA,8BAAAA,QAASC,UAAU,EAAE,OAAOD,QAAQC,UAAU;IAClD,IAAID,oBAAAA,8BAAAA,QAASI,SAAS,EAAE,OAAOR,cAAcI,QAAQI,SAAS;IAC9D,OAAOF,aAAI,CAACM,IAAI,CAACH,QAAQC,GAAG,IAAI;AAClC;AAEe,SAASd,OAAOiB,SAAiB,EAAET,OAAiB;IACjE,sBAAsB;IACtB,IAAIU,IAAAA,0BAAgB,EAACD,WAAW,UAAU,OAAOb,cAAca;IAE/D,wBAAwB;IACxB,IAAIE,IAAAA,mBAAU,EAACF,YAAY,OAAOA;IAElC,wBAAwB;IACxB,IAAIA,SAAS,CAAC,EAAE,KAAK,KAAK;QACxB,IAAMR,aAAaD,UAAUD,cAAcC,WAAWK,QAAQC,GAAG;QACjE,OAAOJ,aAAI,CAACM,IAAI,CAACP,YAAYQ;IAC/B;IAEA,2DAA2D;IAC3D,mEAAmE;IACnE,iEAAiE;IACjE,IAAIG,wBAAW,CAACC,IAAI,CAACJ,cAAcA,SAAS,CAAC,EAAE,KAAK,KAAK;QACvD,IAAMK,iBAAiBP,kBAAkBP;QACzC,IAAMe,YAAYb,aAAI,CAACC,OAAO,CAACW;QAE/B,IAAIrB,QAAQ;YACV,wDAAwD;YACxD,IAAIgB,SAAS,CAAC,EAAE,KAAK,KAAK;gBACxB,MAAM,IAAIO,MAAM,AAAC,uBAA0CD,OAApBN,WAAU,YAAoB,OAAVM,WAAU;YACvE;YACA,OAAOE,IAAAA,qBAAU,EAACR,WAAWM;QAC/B;QACA,kEAAkE;QAClE,IAAMG,YAAYC,IAAAA,qBAAU,EAACV,WAAWK;QACxC,IAAII,WAAW,OAAOA;QAEtB,iDAAiD;QACjD,MAAM,IAAIF,MAAM,AAAC,uBAA0CD,OAApBN,WAAU,YAAoB,OAAVM,WAAU;IACvE;IAEA,OAAON;AACT"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CJS resolver
|
|
3
|
+
*
|
|
4
|
+
* Uses the `resolve` npm package for CommonJS-style module resolution.
|
|
5
|
+
* Handles main field, index.js, etc.
|
|
6
|
+
*
|
|
7
|
+
* Note: CJS does not support subpath imports (#prefix) - those are ESM-only.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Resolve a CJS specifier to an absolute file path
|
|
11
|
+
*
|
|
12
|
+
* @param specifier - The require specifier (e.g., 'lodash', 'lodash/get')
|
|
13
|
+
* @param basedir - The directory to resolve from
|
|
14
|
+
* @returns The resolved absolute file path
|
|
15
|
+
* @throws Error if module cannot be found
|
|
16
|
+
*/
|
|
17
|
+
export default function resolveCJS(specifier: string, basedir: string): string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CJS resolver
|
|
3
|
+
*
|
|
4
|
+
* Uses the `resolve` npm package for CommonJS-style module resolution.
|
|
5
|
+
* Handles main field, index.js, etc.
|
|
6
|
+
*
|
|
7
|
+
* Note: CJS does not support subpath imports (#prefix) - those are ESM-only.
|
|
8
|
+
*/ import * as resolve from 'resolve';
|
|
9
|
+
var _resolve_default;
|
|
10
|
+
const resolveSync = ((_resolve_default = resolve.default) !== null && _resolve_default !== void 0 ? _resolve_default : resolve).sync;
|
|
11
|
+
/**
|
|
12
|
+
* Resolve a CJS specifier to an absolute file path
|
|
13
|
+
*
|
|
14
|
+
* @param specifier - The require specifier (e.g., 'lodash', 'lodash/get')
|
|
15
|
+
* @param basedir - The directory to resolve from
|
|
16
|
+
* @returns The resolved absolute file path
|
|
17
|
+
* @throws Error if module cannot be found
|
|
18
|
+
*/ export default function resolveCJS(specifier, basedir) {
|
|
19
|
+
return resolveSync(specifier, {
|
|
20
|
+
basedir,
|
|
21
|
+
extensions: [
|
|
22
|
+
'.js',
|
|
23
|
+
'.json',
|
|
24
|
+
'.node',
|
|
25
|
+
'.mjs'
|
|
26
|
+
]
|
|
27
|
+
});
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/resolveCJS.ts"],"sourcesContent":["/**\n * CJS resolver\n *\n * Uses the `resolve` npm package for CommonJS-style module resolution.\n * Handles main field, index.js, etc.\n *\n * Note: CJS does not support subpath imports (#prefix) - those are ESM-only.\n */\n\nimport * as resolve from 'resolve';\n\nconst resolveSync = (resolve.default ?? resolve).sync;\n\n/**\n * Resolve a CJS specifier to an absolute file path\n *\n * @param specifier - The require specifier (e.g., 'lodash', 'lodash/get')\n * @param basedir - The directory to resolve from\n * @returns The resolved absolute file path\n * @throws Error if module cannot be found\n */\nexport default function resolveCJS(specifier: string, basedir: string): string {\n return resolveSync(specifier, {\n basedir,\n extensions: ['.js', '.json', '.node', '.mjs'],\n });\n}\n"],"names":["resolve","resolveSync","default","sync","resolveCJS","specifier","basedir","extensions"],"mappings":"AAAA;;;;;;;CAOC,GAED,YAAYA,aAAa,UAAU;IAEdA;AAArB,MAAMC,cAAc,EAACD,mBAAAA,QAAQE,OAAO,cAAfF,8BAAAA,mBAAmBA,SAASG,IAAI;AAErD;;;;;;;CAOC,GACD,eAAe,SAASC,WAAWC,SAAiB,EAAEC,OAAe;IACnE,OAAOL,YAAYI,WAAW;QAC5BC;QACAC,YAAY;YAAC;YAAO;YAAS;YAAS;SAAO;IAC/C;AACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified ESM resolver
|
|
3
|
+
*
|
|
4
|
+
* Handles both:
|
|
5
|
+
* - Package exports: import x from 'lodash' → uses exports field
|
|
6
|
+
* - Subpath imports: import x from '#internal' → uses imports field
|
|
7
|
+
*
|
|
8
|
+
* Uses resolve.exports.resolve() which automatically detects the specifier type.
|
|
9
|
+
* Only loaded on Node >= 12.2 where module.createRequire exists.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Resolve an ESM specifier to an absolute file path
|
|
13
|
+
*
|
|
14
|
+
* @param specifier - The import specifier (e.g., 'lodash', 'lodash/get', '#internal')
|
|
15
|
+
* @param parentPath - The file path of the importing module
|
|
16
|
+
* @param conditions - Export conditions (defaults to ['node', 'import'])
|
|
17
|
+
* @returns The resolved absolute file path, or null if not resolvable
|
|
18
|
+
*/
|
|
19
|
+
export default function resolveESM(specifier: string, parentPath: string, conditions?: string[]): string | null;
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified ESM resolver
|
|
3
|
+
*
|
|
4
|
+
* Handles both:
|
|
5
|
+
* - Package exports: import x from 'lodash' → uses exports field
|
|
6
|
+
* - Subpath imports: import x from '#internal' → uses imports field
|
|
7
|
+
*
|
|
8
|
+
* Uses resolve.exports.resolve() which automatically detects the specifier type.
|
|
9
|
+
* Only loaded on Node >= 12.2 where module.createRequire exists.
|
|
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
|
+
const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
|
|
18
|
+
_resolveExports = _require('resolve.exports');
|
|
19
|
+
} catch (_) {
|
|
20
|
+
_resolveExports = null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return _resolveExports;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Parse a specifier into package name and subpath
|
|
27
|
+
* "lodash" → { pkgName: "lodash", subpath: "." }
|
|
28
|
+
* "lodash/get" → { pkgName: "lodash", subpath: "./get" }
|
|
29
|
+
* "@scope/pkg" → { pkgName: "@scope/pkg", subpath: "." }
|
|
30
|
+
* "@scope/pkg/foo" → { pkgName: "@scope/pkg", subpath: "./foo" }
|
|
31
|
+
*/ function parseSpecifier(specifier) {
|
|
32
|
+
const parts = specifier.split('/');
|
|
33
|
+
const pkgName = specifier[0] === '@' ? parts.slice(0, 2).join('/') : parts[0];
|
|
34
|
+
const remainder = specifier.slice(pkgName.length);
|
|
35
|
+
const subpath = remainder ? `.${remainder}` : '.';
|
|
36
|
+
return {
|
|
37
|
+
pkgName,
|
|
38
|
+
subpath
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Find package.json in node_modules for external packages
|
|
43
|
+
*/ function findPackageInNodeModules(pkgName, basedir) {
|
|
44
|
+
let dir = basedir;
|
|
45
|
+
const root = path.parse(dir).root;
|
|
46
|
+
while(dir !== root){
|
|
47
|
+
const pkgDir = path.join(dir, 'node_modules', pkgName);
|
|
48
|
+
const pkgJsonPath = path.join(pkgDir, 'package.json');
|
|
49
|
+
try {
|
|
50
|
+
if (fs.existsSync(pkgJsonPath)) {
|
|
51
|
+
const content = fs.readFileSync(pkgJsonPath, 'utf8');
|
|
52
|
+
return {
|
|
53
|
+
dir: pkgDir,
|
|
54
|
+
json: JSON.parse(content)
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
} catch (_) {
|
|
58
|
+
// Ignore filesystem errors
|
|
59
|
+
}
|
|
60
|
+
const parent = path.dirname(dir);
|
|
61
|
+
if (parent === dir) break;
|
|
62
|
+
dir = parent;
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Find the containing package.json by walking up from a file path
|
|
68
|
+
* Used for # subpath imports which are scoped to the containing package
|
|
69
|
+
*/ function findContainingPackage(filePath) {
|
|
70
|
+
let dir = path.dirname(filePath);
|
|
71
|
+
const root = path.parse(dir).root;
|
|
72
|
+
while(dir !== root){
|
|
73
|
+
const pkgJsonPath = path.join(dir, 'package.json');
|
|
74
|
+
try {
|
|
75
|
+
if (fs.existsSync(pkgJsonPath)) {
|
|
76
|
+
const content = fs.readFileSync(pkgJsonPath, 'utf8');
|
|
77
|
+
return {
|
|
78
|
+
dir,
|
|
79
|
+
json: JSON.parse(content)
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
} catch (_) {
|
|
83
|
+
// Ignore filesystem errors
|
|
84
|
+
}
|
|
85
|
+
const parent = path.dirname(dir);
|
|
86
|
+
if (parent === dir) break;
|
|
87
|
+
dir = parent;
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Resolve an ESM specifier to an absolute file path
|
|
93
|
+
*
|
|
94
|
+
* @param specifier - The import specifier (e.g., 'lodash', 'lodash/get', '#internal')
|
|
95
|
+
* @param parentPath - The file path of the importing module
|
|
96
|
+
* @param conditions - Export conditions (defaults to ['node', 'import'])
|
|
97
|
+
* @returns The resolved absolute file path, or null if not resolvable
|
|
98
|
+
*/ export default function resolveESM(specifier, parentPath, conditions = [
|
|
99
|
+
'node',
|
|
100
|
+
'import'
|
|
101
|
+
]) {
|
|
102
|
+
const resolveExportsMod = getResolveExports();
|
|
103
|
+
if (!resolveExportsMod) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
const { resolve: resolveFn, legacy } = resolveExportsMod;
|
|
107
|
+
// Determine how to find the package.json based on specifier type
|
|
108
|
+
let pkg;
|
|
109
|
+
let subpath;
|
|
110
|
+
if (specifier.startsWith('#')) {
|
|
111
|
+
// Subpath import - find containing package
|
|
112
|
+
pkg = findContainingPackage(parentPath);
|
|
113
|
+
subpath = specifier; // resolve.exports expects the full #specifier
|
|
114
|
+
} else {
|
|
115
|
+
// External package - find in node_modules
|
|
116
|
+
const { pkgName, subpath: parsedSubpath } = parseSpecifier(specifier);
|
|
117
|
+
pkg = findPackageInNodeModules(pkgName, parentPath);
|
|
118
|
+
subpath = parsedSubpath;
|
|
119
|
+
}
|
|
120
|
+
if (!pkg) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
// Use resolve.exports.resolve() which handles both exports and imports
|
|
124
|
+
try {
|
|
125
|
+
const resolved = resolveFn(pkg.json, subpath, {
|
|
126
|
+
conditions
|
|
127
|
+
});
|
|
128
|
+
if (resolved === null || resolved === void 0 ? void 0 : resolved[0]) {
|
|
129
|
+
return path.join(pkg.dir, resolved[0]);
|
|
130
|
+
}
|
|
131
|
+
} catch (_) {
|
|
132
|
+
// Resolution failed, try legacy
|
|
133
|
+
}
|
|
134
|
+
// Try legacy main/module fields for non-# imports
|
|
135
|
+
if (!specifier.startsWith('#')) {
|
|
136
|
+
try {
|
|
137
|
+
const legacyMain = legacy(pkg.json);
|
|
138
|
+
if (legacyMain) {
|
|
139
|
+
let mainPath;
|
|
140
|
+
if (typeof legacyMain === 'string') {
|
|
141
|
+
mainPath = legacyMain;
|
|
142
|
+
} else if (Array.isArray(legacyMain)) {
|
|
143
|
+
mainPath = legacyMain[0];
|
|
144
|
+
}
|
|
145
|
+
if (mainPath) {
|
|
146
|
+
return path.join(pkg.dir, mainPath);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
} catch (_) {
|
|
150
|
+
// Legacy parsing failed
|
|
151
|
+
}
|
|
152
|
+
// Last resort: try index.js
|
|
153
|
+
const indexPath = path.join(pkg.dir, 'index.js');
|
|
154
|
+
try {
|
|
155
|
+
if (fs.existsSync(indexPath)) {
|
|
156
|
+
return indexPath;
|
|
157
|
+
}
|
|
158
|
+
} catch (_) {
|
|
159
|
+
// Ignore
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/resolveESM.ts"],"sourcesContent":["/**\n * Unified ESM resolver\n *\n * Handles both:\n * - Package exports: import x from 'lodash' → uses exports field\n * - Subpath imports: import x from '#internal' → uses imports field\n *\n * Uses resolve.exports.resolve() which automatically detects the specifier type.\n * Only loaded on Node >= 12.2 where module.createRequire exists.\n */\n\nimport fs from 'fs';\nimport Module from 'module';\nimport path from 'path';\n\n// Lazy-load resolve.exports\ntype ResolveExportsModule = typeof import('resolve.exports');\nlet _resolveExports: ResolveExportsModule | null = null;\n\nfunction getResolveExports(): ResolveExportsModule | null {\n if (_resolveExports === null) {\n try {\n const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n _resolveExports = _require('resolve.exports') as ResolveExportsModule;\n } catch (_) {\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 package.json in node_modules for external packages\n */\nfunction findPackageInNodeModules(pkgName: string, basedir: string): { dir: string; json: Record<string, unknown> } | null {\n let dir = basedir;\n const root = path.parse(dir).root;\n\n while (dir !== root) {\n const pkgDir = path.join(dir, 'node_modules', pkgName);\n const pkgJsonPath = path.join(pkgDir, 'package.json');\n try {\n if (fs.existsSync(pkgJsonPath)) {\n const content = fs.readFileSync(pkgJsonPath, 'utf8');\n return { dir: pkgDir, json: JSON.parse(content) };\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 * Find the containing package.json by walking up from a file path\n * Used for # subpath imports which are scoped to the containing package\n */\nfunction findContainingPackage(filePath: string): { dir: string; json: Record<string, unknown> } | null {\n let dir = path.dirname(filePath);\n const root = path.parse(dir).root;\n\n while (dir !== root) {\n const pkgJsonPath = path.join(dir, 'package.json');\n try {\n if (fs.existsSync(pkgJsonPath)) {\n const content = fs.readFileSync(pkgJsonPath, 'utf8');\n return { dir, json: JSON.parse(content) };\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 * Resolve an ESM specifier to an absolute file path\n *\n * @param specifier - The import specifier (e.g., 'lodash', 'lodash/get', '#internal')\n * @param parentPath - The file path of the importing module\n * @param conditions - Export conditions (defaults to ['node', 'import'])\n * @returns The resolved absolute file path, or null if not resolvable\n */\nexport default function resolveESM(specifier: string, parentPath: string, conditions: string[] = ['node', 'import']): string | null {\n const resolveExportsMod = getResolveExports();\n if (!resolveExportsMod) {\n return null;\n }\n\n const { resolve: resolveFn, legacy } = resolveExportsMod;\n\n // Determine how to find the package.json based on specifier type\n let pkg: { dir: string; json: Record<string, unknown> } | null;\n let subpath: string;\n\n if (specifier.startsWith('#')) {\n // Subpath import - find containing package\n pkg = findContainingPackage(parentPath);\n subpath = specifier; // resolve.exports expects the full #specifier\n } else {\n // External package - find in node_modules\n const { pkgName, subpath: parsedSubpath } = parseSpecifier(specifier);\n pkg = findPackageInNodeModules(pkgName, parentPath);\n subpath = parsedSubpath;\n }\n\n if (!pkg) {\n return null;\n }\n\n // Use resolve.exports.resolve() which handles both exports and imports\n try {\n const resolved = resolveFn(pkg.json, subpath, { conditions });\n if (resolved?.[0]) {\n return path.join(pkg.dir, resolved[0]);\n }\n } catch (_) {\n // Resolution failed, try legacy\n }\n\n // Try legacy main/module fields for non-# imports\n if (!specifier.startsWith('#')) {\n try {\n const legacyMain = legacy(pkg.json);\n if (legacyMain) {\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 if (mainPath) {\n return path.join(pkg.dir, mainPath);\n }\n }\n } catch (_) {\n // Legacy parsing failed\n }\n\n // Last resort: try index.js\n const indexPath = path.join(pkg.dir, 'index.js');\n try {\n if (fs.existsSync(indexPath)) {\n return indexPath;\n }\n } catch (_) {\n // Ignore\n }\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","findPackageInNodeModules","basedir","dir","root","parse","pkgDir","pkgJsonPath","existsSync","content","readFileSync","json","JSON","parent","dirname","findContainingPackage","filePath","resolveESM","parentPath","conditions","resolveExportsMod","resolve","resolveFn","legacy","pkg","startsWith","parsedSubpath","resolved","legacyMain","mainPath","Array","isArray","indexPath"],"mappings":"AAAA;;;;;;;;;CASC,GAED,OAAOA,QAAQ,KAAK;AACpB,OAAOC,YAAY,SAAS;AAC5B,OAAOC,UAAU,OAAO;AAIxB,IAAIC,kBAA+C;AAEnD,SAASC;IACP,IAAID,oBAAoB,MAAM;QAC5B,IAAI;YACF,MAAME,WAAW,OAAOC,YAAY,cAAcL,OAAOM,a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IAClC;IAEA,kDAAkD;IAClD,IAAI,CAACE,UAAUiC,UAAU,CAAC,MAAM;QAC9B,IAAI;YACF,MAAMG,aAAaL,OAAOC,IAAIb,IAAI;YAClC,IAAIiB,YAAY;gBACd,IAAIC;gBACJ,IAAI,OAAOD,eAAe,UAAU;oBAClCC,WAAWD;gBACb,OAAO,IAAIE,MAAMC,OAAO,CAACH,aAAa;oBACpCC,WAAWD,UAAU,CAAC,EAAE;gBAC1B;gBACA,IAAIC,UAAU;oBACZ,OAAO9C,KAAKc,IAAI,CAAC2B,IAAIrB,GAAG,EAAE0B;gBAC5B;YACF;QACF,EAAE,OAAOvC,GAAG;QACV,wBAAwB;QAC1B;QAEA,4BAA4B;QAC5B,MAAM0C,YAAYjD,KAAKc,IAAI,CAAC2B,IAAIrB,GAAG,EAAE;QACrC,IAAI;YACF,IAAItB,GAAG2B,UAAU,CAACwB,YAAY;gBAC5B,OAAOA;YACT;QACF,EAAE,OAAO1C,GAAG;QACV,SAAS;QACX;IACF;IAEA,OAAO;AACT"}
|
package/dist/esm/toPath.js
CHANGED
|
@@ -1,46 +1,51 @@
|
|
|
1
1
|
import isAbsolute from 'is-absolute';
|
|
2
2
|
import module from 'module';
|
|
3
3
|
import path from 'path';
|
|
4
|
-
import * as resolve from 'resolve';
|
|
5
4
|
import url from 'url';
|
|
6
5
|
import { stringStartsWith } from './compat.js';
|
|
7
6
|
import { moduleRegEx } from './constants.js';
|
|
8
|
-
import
|
|
7
|
+
import resolveCJS from './lib/resolveCJS.js';
|
|
8
|
+
import resolveESM from './lib/resolveESM.js';
|
|
9
9
|
import * as urlPolyfills from './lib/urlFileUrl.js';
|
|
10
|
-
var _resolve_default;
|
|
11
|
-
const resolveSync = ((_resolve_default = resolve.default) !== null && _resolve_default !== void 0 ? _resolve_default : resolve).sync;
|
|
12
10
|
const useCJS = !module.createRequire;
|
|
13
11
|
const fileURLToPath = url.fileURLToPath || urlPolyfills.fileURLToPath;
|
|
14
12
|
function getParentPath(context) {
|
|
15
13
|
if (context.parentPath) return path.dirname(context.parentPath);
|
|
16
14
|
return context.parentURL ? path.dirname(toPath(context.parentURL)) : process.cwd();
|
|
17
15
|
}
|
|
16
|
+
function getParentFilePath(context) {
|
|
17
|
+
if (context === null || context === void 0 ? void 0 : context.parentPath) return context.parentPath;
|
|
18
|
+
if (context === null || context === void 0 ? void 0 : context.parentURL) return fileURLToPath(context.parentURL);
|
|
19
|
+
return path.join(process.cwd(), 'index.js');
|
|
20
|
+
}
|
|
18
21
|
export default function toPath(specifier, context) {
|
|
22
|
+
// Handle file:// URLs
|
|
19
23
|
if (stringStartsWith(specifier, 'file:')) return fileURLToPath(specifier);
|
|
24
|
+
// Handle absolute paths
|
|
20
25
|
if (isAbsolute(specifier)) return specifier;
|
|
26
|
+
// Handle relative paths
|
|
21
27
|
if (specifier[0] === '.') {
|
|
22
28
|
const parentPath = context ? getParentPath(context) : process.cwd();
|
|
23
29
|
return path.join(parentPath, specifier);
|
|
24
30
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
// Handle module specifiers (bare specifiers and # imports)
|
|
32
|
+
// moduleRegEx matches: bare specifiers like 'lodash', '@scope/pkg'
|
|
33
|
+
// specifier[0] === '#' matches: subpath imports like '#internal'
|
|
34
|
+
if (moduleRegEx.test(specifier) || specifier[0] === '#') {
|
|
35
|
+
const parentFilePath = getParentFilePath(context);
|
|
36
|
+
const parentDir = path.dirname(parentFilePath);
|
|
37
|
+
if (useCJS) {
|
|
38
|
+
// CJS: use resolve package (does not support # imports)
|
|
39
|
+
if (specifier[0] === '#') {
|
|
40
|
+
throw new Error(`Cannot find module '${specifier}' from '${parentDir}' (subpath imports not supported in CJS mode)`);
|
|
41
|
+
}
|
|
42
|
+
return resolveCJS(specifier, parentDir);
|
|
33
43
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
extensions: [
|
|
37
|
-
'.js',
|
|
38
|
-
'.json',
|
|
39
|
-
'.node',
|
|
40
|
-
'.mjs'
|
|
41
|
-
]
|
|
42
|
-
});
|
|
44
|
+
// ESM: use unified resolver that handles both exports and imports
|
|
45
|
+
const entryPath = resolveESM(specifier, parentFilePath);
|
|
43
46
|
if (entryPath) return entryPath;
|
|
47
|
+
// If ESM resolver failed, throw meaningful error
|
|
48
|
+
throw new Error(`Cannot find module '${specifier}' from '${parentDir}'`);
|
|
44
49
|
}
|
|
45
50
|
return specifier;
|
|
46
51
|
}
|
package/dist/esm/toPath.js.map
CHANGED
|
@@ -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
|
|
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 url from 'url';\n\nimport { stringStartsWith } from './compat.ts';\nimport { moduleRegEx } from './constants.ts';\nimport resolveCJS from './lib/resolveCJS.ts';\nimport resolveESM from './lib/resolveESM.ts';\nimport * as urlPolyfills from './lib/urlFileUrl.ts';\nimport type { Context } from './types.ts';\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\nfunction getParentFilePath(context?: Context): string {\n if (context?.parentPath) return context.parentPath;\n if (context?.parentURL) return fileURLToPath(context.parentURL);\n return path.join(process.cwd(), 'index.js');\n}\n\nexport default function toPath(specifier: string, context?: Context): string {\n // Handle file:// URLs\n if (stringStartsWith(specifier, 'file:')) return fileURLToPath(specifier);\n\n // Handle absolute paths\n if (isAbsolute(specifier)) return specifier;\n\n // Handle relative paths\n if (specifier[0] === '.') {\n const parentPath = context ? getParentPath(context) : process.cwd();\n return path.join(parentPath, specifier);\n }\n\n // Handle module specifiers (bare specifiers and # imports)\n // moduleRegEx matches: bare specifiers like 'lodash', '@scope/pkg'\n // specifier[0] === '#' matches: subpath imports like '#internal'\n if (moduleRegEx.test(specifier) || specifier[0] === '#') {\n const parentFilePath = getParentFilePath(context);\n const parentDir = path.dirname(parentFilePath);\n\n if (useCJS) {\n // CJS: use resolve package (does not support # imports)\n if (specifier[0] === '#') {\n throw new Error(`Cannot find module '${specifier}' from '${parentDir}' (subpath imports not supported in CJS mode)`);\n }\n return resolveCJS(specifier, parentDir);\n }\n // ESM: use unified resolver that handles both exports and imports\n const entryPath = resolveESM(specifier, parentFilePath);\n if (entryPath) return entryPath;\n\n // If ESM resolver failed, throw meaningful error\n throw new Error(`Cannot find module '${specifier}' from '${parentDir}'`);\n }\n\n return specifier;\n}\n"],"names":["isAbsolute","module","path","url","stringStartsWith","moduleRegEx","resolveCJS","resolveESM","urlPolyfills","useCJS","createRequire","fileURLToPath","getParentPath","context","parentPath","dirname","parentURL","toPath","process","cwd","getParentFilePath","join","specifier","test","parentFilePath","parentDir","Error","entryPath"],"mappings":"AAAA,OAAOA,gBAAgB,cAAc;AACrC,OAAOC,YAAY,SAAS;AAC5B,OAAOC,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AAEtB,SAASC,gBAAgB,QAAQ,cAAc;AAC/C,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,OAAOC,gBAAgB,sBAAsB;AAC7C,OAAOC,gBAAgB,sBAAsB;AAC7C,YAAYC,kBAAkB,sBAAsB;AAGpD,MAAMC,SAAS,CAACR,OAAOS,aAAa;AACpC,MAAMC,gBAAgBR,IAAIQ,aAAa,IAAIH,aAAaG,aAAa;AAErE,SAASC,cAAcC,OAAgB;IACrC,IAAIA,QAAQC,UAAU,EAAE,OAAOZ,KAAKa,OAAO,CAACF,QAAQC,UAAU;IA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;IACzE;IAEA,OAAOH;AACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-swc-transform",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.2",
|
|
4
4
|
"description": "Typescript transformers for swc. Supports Node >= 0.8",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"matcher",
|
|
@@ -68,6 +68,7 @@
|
|
|
68
68
|
"cross-spawn-cb": "^2.0.0",
|
|
69
69
|
"fs-remove-compat": "^1.0.0",
|
|
70
70
|
"mock-exports-only-pkg": "file:test/data/mock-exports-only-pkg",
|
|
71
|
+
"mock-subpath-imports-pkg": "file:test/data/mock-subpath-imports-pkg",
|
|
71
72
|
"node-version-use": "*",
|
|
72
73
|
"pinkie-promise": "*",
|
|
73
74
|
"react": "^19.2.3",
|
|
@@ -1,16 +0,0 @@
|
|
|
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;
|
|
@@ -1,16 +0,0 @@
|
|
|
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;
|
|
@@ -1,157 +0,0 @@
|
|
|
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; }
|
|
@@ -1 +0,0 @@
|
|
|
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;QAC5B,IAAI;YACF,8DAA8D;YAC9D,IAAME,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;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,IAAMC,QAAQD,UAAUE,KAAK,CAAC;IAC9B,IAAMC,UAAUH,SAAS,CAAC,EAAE,KAAK,MAAMC,MAAMG,KAAK,CAAC,GAAG,GAAGC,IAAI,CAAC,OAAOJ,KAAK,CAAC,EAAE;IAC7E,IAAMK,YAAYN,UAAUI,KAAK,CAACD,QAAQI,MAAM;IAChD,IAAMC,UAAUF,YAAY,AAAC,IAAa,OAAVA,aAAc;IAC9C,OAAO;QAAEH,SAAAA;QAASK,SAAAA;IAAQ;AAC5B;AAEA;;CAEC,GACD,SAASC,gBAAgBN,OAAe,EAAEO,OAAe;IACvD,IAAIC,MAAMD;IACV,IAAME,OAAOC,aAAI,CAACC,KAAK,CAACH,KAAKC,IAAI;IAEjC,MAAOD,QAAQC,KAAM;QACnB,IAAMG,YAAYF,aAAI,CAACR,IAAI,CAACM,KAAK,gBAAgBR,SAAS;QAC1D,I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AI;QACF,IAAMmC,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,OAAOrB,aAAI,CAACR,IAAI,CAAC0B,QAAQG;YAC3B;QACF;IACF,EAAE,OAAOpC,GAAG;IACV,wBAAwB;IAC1B;IAEA,4BAA4B;IAC5B,IAAMuC,YAAYxB,aAAI,CAACR,IAAI,CAAC0B,QAAQ;IACpC,IAAI;QACF,IAAIf,WAAE,CAACC,UAAU,CAACoB,YAAY;YAC5B,OAAOA;QACT;IACF,EAAE,OAAOvC,GAAG;IACV,SAAS;IACX;IAEA,OAAO;AACT"}
|
|
@@ -1,16 +0,0 @@
|
|
|
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;
|
|
@@ -1,140 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
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,QAAQI,MAAM;IAChD,MAAMC,UAAUF,YAAY,CAAC,CAAC,EAAEA,WAAW,GAAG;IAC9C,OAAO;QAAEH;QAASK;IAAQ;AAC5B;AAEA;;CAEC,GACD,SAASC,gBAAgBN,OAAe,EAAEO,OAAe;IACvD,IAAIC,MAAMD;IACV,MAAME,OAAOrB,KAAKsB,KAAK,CAACF,KAAKC,IAAI;IAEjC,MAAOD,QAAQC,KAAM;QACnB,MAAME,YAAYvB,KAAKc,IAAI,CAACM,KAAK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