ts-swc-transform 2.8.0 → 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.
- package/dist/cjs/lib/resolve-with-exports.d.cts +5 -1
- package/dist/cjs/lib/resolve-with-exports.d.ts +5 -1
- package/dist/cjs/lib/resolve-with-exports.js +96 -85
- package/dist/cjs/lib/resolve-with-exports.js.map +1 -1
- package/dist/cjs/toPath.js.map +1 -1
- package/dist/esm/lib/resolve-with-exports.d.ts +5 -1
- package/dist/esm/lib/resolve-with-exports.js +97 -45
- package/dist/esm/lib/resolve-with-exports.js.map +1 -1
- package/dist/esm/toPath.js.map +1 -1
- package/package.json +2 -1
- package/assets/import-meta-resolve.cjs +0 -1481
|
@@ -4,9 +4,13 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Only loaded on Node >= 12.2 where module.createRequire exists.
|
|
6
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.
|
|
7
10
|
*/
|
|
8
11
|
/**
|
|
9
12
|
* Resolve a module specifier using the exports field in package.json
|
|
10
|
-
*
|
|
13
|
+
* This implementation directly finds the package and reads its exports,
|
|
14
|
+
* bypassing the resolve package which can't handle exports-only packages.
|
|
11
15
|
*/
|
|
12
16
|
export default function resolveWithExports(specifier: string, basedir: string, conditions?: string[]): string | null;
|
|
@@ -4,9 +4,13 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Only loaded on Node >= 12.2 where module.createRequire exists.
|
|
6
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.
|
|
7
10
|
*/
|
|
8
11
|
/**
|
|
9
12
|
* Resolve a module specifier using the exports field in package.json
|
|
10
|
-
*
|
|
13
|
+
* This implementation directly finds the package and reads its exports,
|
|
14
|
+
* bypassing the resolve package which can't handle exports-only packages.
|
|
11
15
|
*/
|
|
12
16
|
export default function resolveWithExports(specifier: string, basedir: string, conditions?: string[]): string | null;
|
|
@@ -4,69 +4,31 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Only loaded on Node >= 12.2 where module.createRequire exists.
|
|
6
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.
|
|
7
10
|
*/ "use strict";
|
|
8
11
|
Object.defineProperty(exports, "__esModule", {
|
|
9
12
|
value: true
|
|
10
13
|
});
|
|
11
14
|
Object.defineProperty(exports, /**
|
|
12
15
|
* Resolve a module specifier using the exports field in package.json
|
|
13
|
-
*
|
|
16
|
+
* This implementation directly finds the package and reads its exports,
|
|
17
|
+
* bypassing the resolve package which can't handle exports-only packages.
|
|
14
18
|
*/ "default", {
|
|
15
19
|
enumerable: true,
|
|
16
20
|
get: function() {
|
|
17
21
|
return resolveWithExports;
|
|
18
22
|
}
|
|
19
23
|
});
|
|
24
|
+
var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
20
25
|
var _module = /*#__PURE__*/ _interop_require_default(require("module"));
|
|
21
|
-
var
|
|
26
|
+
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
22
27
|
function _interop_require_default(obj) {
|
|
23
28
|
return obj && obj.__esModule ? obj : {
|
|
24
29
|
default: obj
|
|
25
30
|
};
|
|
26
31
|
}
|
|
27
|
-
function _getRequireWildcardCache(nodeInterop) {
|
|
28
|
-
if (typeof WeakMap !== "function") return null;
|
|
29
|
-
var cacheBabelInterop = new WeakMap();
|
|
30
|
-
var cacheNodeInterop = new WeakMap();
|
|
31
|
-
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
32
|
-
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
33
|
-
})(nodeInterop);
|
|
34
|
-
}
|
|
35
|
-
function _interop_require_wildcard(obj, nodeInterop) {
|
|
36
|
-
if (!nodeInterop && obj && obj.__esModule) {
|
|
37
|
-
return obj;
|
|
38
|
-
}
|
|
39
|
-
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
40
|
-
return {
|
|
41
|
-
default: obj
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
var cache = _getRequireWildcardCache(nodeInterop);
|
|
45
|
-
if (cache && cache.has(obj)) {
|
|
46
|
-
return cache.get(obj);
|
|
47
|
-
}
|
|
48
|
-
var newObj = {
|
|
49
|
-
__proto__: null
|
|
50
|
-
};
|
|
51
|
-
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
52
|
-
for(var key in obj){
|
|
53
|
-
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
54
|
-
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
55
|
-
if (desc && (desc.get || desc.set)) {
|
|
56
|
-
Object.defineProperty(newObj, key, desc);
|
|
57
|
-
} else {
|
|
58
|
-
newObj[key] = obj[key];
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
newObj.default = obj;
|
|
63
|
-
if (cache) {
|
|
64
|
-
cache.set(obj, newObj);
|
|
65
|
-
}
|
|
66
|
-
return newObj;
|
|
67
|
-
}
|
|
68
|
-
var _resolve_default;
|
|
69
|
-
var resolveSync = ((_resolve_default = _resolve.default) !== null && _resolve_default !== void 0 ? _resolve_default : _resolve).sync;
|
|
70
32
|
var _resolveExports = null;
|
|
71
33
|
function getResolveExports() {
|
|
72
34
|
if (_resolveExports === null) {
|
|
@@ -83,15 +45,50 @@ function getResolveExports() {
|
|
|
83
45
|
return _resolveExports;
|
|
84
46
|
}
|
|
85
47
|
/**
|
|
86
|
-
*
|
|
87
|
-
* "lodash
|
|
88
|
-
* "
|
|
89
|
-
* "@scope/pkg
|
|
90
|
-
|
|
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) {
|
|
91
54
|
var parts = specifier.split('/');
|
|
92
55
|
var pkgName = specifier[0] === '@' ? parts.slice(0, 2).join('/') : parts[0];
|
|
93
56
|
var remainder = specifier.slice(pkgName.length);
|
|
94
|
-
|
|
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
|
+
}
|
|
95
92
|
}
|
|
96
93
|
function resolveWithExports(specifier, basedir) {
|
|
97
94
|
var conditions = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : [
|
|
@@ -104,43 +101,57 @@ function resolveWithExports(specifier, basedir) {
|
|
|
104
101
|
return null;
|
|
105
102
|
}
|
|
106
103
|
var resolveExportsFn = resolveExportsMod.exports, legacy = resolveExportsMod.legacy;
|
|
107
|
-
var
|
|
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
|
|
108
117
|
try {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
extensions: [
|
|
112
|
-
'.js',
|
|
113
|
-
'.json',
|
|
114
|
-
'.node',
|
|
115
|
-
'.mjs'
|
|
116
|
-
],
|
|
117
|
-
packageFilter: function(pkg) {
|
|
118
|
-
// Try exports field first
|
|
119
|
-
try {
|
|
120
|
-
var resolved = resolveExportsFn(pkg, subpath, {
|
|
121
|
-
conditions: conditions
|
|
122
|
-
});
|
|
123
|
-
if (resolved === null || resolved === void 0 ? void 0 : resolved[0]) {
|
|
124
|
-
pkg.main = resolved[0];
|
|
125
|
-
return pkg;
|
|
126
|
-
}
|
|
127
|
-
} catch (_) {
|
|
128
|
-
// exports field parsing failed, try legacy
|
|
129
|
-
}
|
|
130
|
-
// Try legacy main/module fields
|
|
131
|
-
try {
|
|
132
|
-
var legacyMain = legacy(pkg);
|
|
133
|
-
if (legacyMain) {
|
|
134
|
-
pkg.main = legacyMain;
|
|
135
|
-
}
|
|
136
|
-
} catch (_) {
|
|
137
|
-
// legacy parsing failed, use original pkg
|
|
138
|
-
}
|
|
139
|
-
return pkg;
|
|
140
|
-
}
|
|
118
|
+
var resolved = resolveExportsFn(pkg, subpath, {
|
|
119
|
+
conditions: conditions
|
|
141
120
|
});
|
|
121
|
+
if (resolved === null || resolved === void 0 ? void 0 : resolved[0]) {
|
|
122
|
+
return _path.default.join(pkgDir, resolved[0]);
|
|
123
|
+
}
|
|
142
124
|
} catch (_) {
|
|
143
|
-
|
|
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
|
|
144
154
|
}
|
|
155
|
+
return null;
|
|
145
156
|
}
|
|
146
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 +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\nimport
|
|
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":"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"}
|
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 * 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;wBAEiB;2BACL;2EACG;oEACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAGTC;AAArB,IAAMC,cAAc,
|
|
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;wBAEiB;2BACL;2EACG;oEACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAGTC;AAArB,IAAMC,cAAc,EAACD,mBAAAA,SAAQE,OAAO,cAAfF,8BAAAA,mBAAmBA,UAASG,IAAI;AAErD,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,CAACf,OAAOY,QAAQI,SAAS,KAAKC,QAAQC,GAAG;AAClF;AAEe,SAASlB,OAAOmB,SAAiB,EAAEP,OAAiB;IACjE,IAAIQ,IAAAA,0BAAgB,EAACD,WAAW,UAAU,OAAOX,cAAcW;IAC/D,IAAIE,IAAAA,mBAAU,EAACF,YAAY,OAAOA;IAClC,IAAIA,SAAS,CAAC,EAAE,KAAK,KAAK;QACxB,IAAMN,aAAaD,UAAUD,cAAcC,WAAWK,QAAQC,GAAG;QACjE,OAAOJ,aAAI,CAACQ,IAAI,CAACT,YAAYM;IAC/B;IACA,IAAII,wBAAW,CAACC,IAAI,CAACL,YAAY;QAC/B,IAAMN,cAAaD,UAAUD,cAAcC,WAAWK,QAAQC,GAAG;QACjE,IAAI,CAACb,QAAQ;YACX,IAAI;gBACF,IAAMoB,YAAYC,IAAAA,6BAAkB,EAACP,WAAWN;gBAChD,IAAIY,WAAW,OAAOA;YACxB,EAAE,OAAOE,GAAG;YACV,0CAA0C,GAC5C;QACF;QACA,IAAMF,aAAYvB,YAAYiB,WAAW;YACvCS,SAASf;YACTgB,YAAY;gBAAC;gBAAO;gBAAS;gBAAS;aAAO;QAC/C;QACA,IAAIJ,YAAW,OAAOA;IACxB;IAEA,OAAON;AACT"}
|
|
@@ -4,9 +4,13 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Only loaded on Node >= 12.2 where module.createRequire exists.
|
|
6
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.
|
|
7
10
|
*/
|
|
8
11
|
/**
|
|
9
12
|
* Resolve a module specifier using the exports field in package.json
|
|
10
|
-
*
|
|
13
|
+
* This implementation directly finds the package and reads its exports,
|
|
14
|
+
* bypassing the resolve package which can't handle exports-only packages.
|
|
11
15
|
*/
|
|
12
16
|
export default function resolveWithExports(specifier: string, basedir: string, conditions?: string[]): string | null;
|
|
@@ -4,10 +4,12 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Only loaded on Node >= 12.2 where module.createRequire exists.
|
|
6
6
|
* On older Node, toPath.ts skips this and falls back to resolve.sync().
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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';
|
|
11
13
|
let _resolveExports = null;
|
|
12
14
|
function getResolveExports() {
|
|
13
15
|
if (_resolveExports === null) {
|
|
@@ -24,19 +26,55 @@ function getResolveExports() {
|
|
|
24
26
|
return _resolveExports;
|
|
25
27
|
}
|
|
26
28
|
/**
|
|
27
|
-
*
|
|
28
|
-
* "lodash
|
|
29
|
-
* "
|
|
30
|
-
* "@scope/pkg
|
|
31
|
-
|
|
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) {
|
|
32
35
|
const parts = specifier.split('/');
|
|
33
36
|
const pkgName = specifier[0] === '@' ? parts.slice(0, 2).join('/') : parts[0];
|
|
34
37
|
const remainder = specifier.slice(pkgName.length);
|
|
35
|
-
|
|
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
|
+
}
|
|
36
73
|
}
|
|
37
74
|
/**
|
|
38
75
|
* Resolve a module specifier using the exports field in package.json
|
|
39
|
-
*
|
|
76
|
+
* This implementation directly finds the package and reads its exports,
|
|
77
|
+
* bypassing the resolve package which can't handle exports-only packages.
|
|
40
78
|
*/ export default function resolveWithExports(specifier, basedir, conditions = [
|
|
41
79
|
'node',
|
|
42
80
|
'import'
|
|
@@ -47,42 +85,56 @@ function getResolveExports() {
|
|
|
47
85
|
return null;
|
|
48
86
|
}
|
|
49
87
|
const { exports: resolveExportsFn, legacy } = resolveExportsMod;
|
|
50
|
-
const subpath =
|
|
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
|
|
51
101
|
try {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
extensions: [
|
|
55
|
-
'.js',
|
|
56
|
-
'.json',
|
|
57
|
-
'.node',
|
|
58
|
-
'.mjs'
|
|
59
|
-
],
|
|
60
|
-
packageFilter: (pkg)=>{
|
|
61
|
-
// Try exports field first
|
|
62
|
-
try {
|
|
63
|
-
const resolved = resolveExportsFn(pkg, subpath, {
|
|
64
|
-
conditions
|
|
65
|
-
});
|
|
66
|
-
if (resolved === null || resolved === void 0 ? void 0 : resolved[0]) {
|
|
67
|
-
pkg.main = resolved[0];
|
|
68
|
-
return pkg;
|
|
69
|
-
}
|
|
70
|
-
} catch (_) {
|
|
71
|
-
// exports field parsing failed, try legacy
|
|
72
|
-
}
|
|
73
|
-
// Try legacy main/module fields
|
|
74
|
-
try {
|
|
75
|
-
const legacyMain = legacy(pkg);
|
|
76
|
-
if (legacyMain) {
|
|
77
|
-
pkg.main = legacyMain;
|
|
78
|
-
}
|
|
79
|
-
} catch (_) {
|
|
80
|
-
// legacy parsing failed, use original pkg
|
|
81
|
-
}
|
|
82
|
-
return pkg;
|
|
83
|
-
}
|
|
102
|
+
const resolved = resolveExportsFn(pkg, subpath, {
|
|
103
|
+
conditions
|
|
84
104
|
});
|
|
105
|
+
if (resolved === null || resolved === void 0 ? void 0 : resolved[0]) {
|
|
106
|
+
return path.join(pkgDir, resolved[0]);
|
|
107
|
+
}
|
|
85
108
|
} catch (_) {
|
|
86
|
-
|
|
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
|
|
87
138
|
}
|
|
139
|
+
return null;
|
|
88
140
|
}
|
|
@@ -1 +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\nimport
|
|
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":"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"}
|
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 * 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":["isAbsolute","module","path","resolve","url","stringStartsWith","moduleRegEx","resolveWithExports","urlPolyfills","resolveSync","default","sync","useCJS","createRequire","fileURLToPath","getParentPath","context","parentPath","dirname","parentURL","toPath","process","cwd","specifier","join","test","entryPath","_","basedir","extensions"],"mappings":"AAAA,OAAOA,gBAAgB,cAAc;AACrC,OAAOC,YAAY,SAAS;AAC5B,OAAOC,UAAU,OAAO;AACxB,YAAYC,aAAa,UAAU;AACnC,OAAOC,SAAS,MAAM;AAEtB,SAASC,gBAAgB,QAAQ,cAAc;AAC/C,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,OAAOC,wBAAwB,gCAAgC;AAC/D,YAAYC,kBAAkB,sBAAsB;IAG/BL;AAArB,MAAMM,cAAc,
|
|
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":["isAbsolute","module","path","resolve","url","stringStartsWith","moduleRegEx","resolveWithExports","urlPolyfills","resolveSync","default","sync","useCJS","createRequire","fileURLToPath","getParentPath","context","parentPath","dirname","parentURL","toPath","process","cwd","specifier","join","test","entryPath","_","basedir","extensions"],"mappings":"AAAA,OAAOA,gBAAgB,cAAc;AACrC,OAAOC,YAAY,SAAS;AAC5B,OAAOC,UAAU,OAAO;AACxB,YAAYC,aAAa,UAAU;AACnC,OAAOC,SAAS,MAAM;AAEtB,SAASC,gBAAgB,QAAQ,cAAc;AAC/C,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,OAAOC,wBAAwB,gCAAgC;AAC/D,YAAYC,kBAAkB,sBAAsB;IAG/BL;AAArB,MAAMM,cAAc,EAACN,mBAAAA,QAAQO,OAAO,cAAfP,8BAAAA,mBAAmBA,SAASQ,IAAI;AAErD,MAAMC,SAAS,CAACX,OAAOY,aAAa;AACpC,MAAMC,gBAAgBV,IAAIU,aAAa,IAAIN,aAAaM,aAAa;AAErE,SAASC,cAAcC,OAAgB;IACrC,IAAIA,QAAQC,UAAU,EAAE,OAAOf,KAAKgB,OAAO,CAACF,QAAQC,UAAU;IAC9D,OAAOD,QAAQG,SAAS,GAAGjB,KAAKgB,OAAO,CAACE,OAAOJ,QAAQG,SAAS,KAAKE,QAAQC,GAAG;AAClF;AAEA,eAAe,SAASF,OAAOG,SAAiB,EAAEP,OAAiB;IACjE,IAAIX,iBAAiBkB,WAAW,UAAU,OAAOT,cAAcS;IAC/D,IAAIvB,WAAWuB,YAAY,OAAOA;IAClC,IAAIA,SAAS,CAAC,EAAE,KAAK,KAAK;QACxB,MAAMN,aAAaD,UAAUD,cAAcC,WAAWK,QAAQC,GAAG;QACjE,OAAOpB,KAAKsB,IAAI,CAACP,YAAYM;IAC/B;IACA,IAAIjB,YAAYmB,IAAI,CAACF,YAAY;QAC/B,MAAMN,aAAaD,UAAUD,cAAcC,WAAWK,QAAQC,GAAG;QACjE,IAAI,CAACV,QAAQ;YACX,IAAI;gBACF,MAAMc,YAAYnB,mBAAmBgB,WAAWN;gBAChD,IAAIS,WAAW,OAAOA;YACxB,EAAE,OAAOC,GAAG;YACV,0CAA0C,GAC5C;QACF;QACA,MAAMD,YAAYjB,YAAYc,WAAW;YACvCK,SAASX;YACTY,YAAY;gBAAC;gBAAO;gBAAS;gBAAS;aAAO;QAC/C;QACA,IAAIH,WAAW,OAAOA;IACxB;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.1",
|
|
4
4
|
"description": "Typescript transformers for swc. Supports Node >= 0.8",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"matcher",
|
|
@@ -67,6 +67,7 @@
|
|
|
67
67
|
"cr": "^0.1.0",
|
|
68
68
|
"cross-spawn-cb": "^2.0.0",
|
|
69
69
|
"fs-remove-compat": "^1.0.0",
|
|
70
|
+
"mock-exports-only-pkg": "file:test/data/mock-exports-only-pkg",
|
|
70
71
|
"node-version-use": "*",
|
|
71
72
|
"pinkie-promise": "*",
|
|
72
73
|
"react": "^19.2.3",
|