@poppinss/ts-exec 1.1.5 → 1.2.0
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/build/index.js +1 -1
- package/build/src/loader.js +14 -44
- package/package.json +2 -3
- package/build/src/get_package_json.d.ts +0 -4
package/build/index.js
CHANGED
package/build/src/loader.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
// src/loader.ts
|
|
2
|
-
import { extname } from "
|
|
3
|
-
import { fileURLToPath as
|
|
4
|
-
import { resolveImports } from "resolve-pkg-maps";
|
|
2
|
+
import { extname } from "path";
|
|
3
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
5
4
|
|
|
6
5
|
// src/debug.ts
|
|
7
|
-
import { debuglog } from "
|
|
6
|
+
import { debuglog } from "util";
|
|
8
7
|
var debug_default = debuglog("ts-exec");
|
|
9
8
|
|
|
10
9
|
// src/get_config.ts
|
|
11
|
-
import { fileURLToPath } from "
|
|
10
|
+
import { fileURLToPath } from "url";
|
|
12
11
|
import { getTsconfig } from "get-tsconfig";
|
|
13
12
|
var DEFAULT_CONFIG = {
|
|
14
13
|
sourceMaps: true,
|
|
@@ -110,29 +109,9 @@ function transformSync(source, options) {
|
|
|
110
109
|
return swcTransform(input, rest);
|
|
111
110
|
}
|
|
112
111
|
|
|
113
|
-
// src/get_package_json.ts
|
|
114
|
-
import { join } from "node:path";
|
|
115
|
-
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
116
|
-
import { readFile } from "node:fs/promises";
|
|
117
|
-
async function getPackageJson(searchPath) {
|
|
118
|
-
try {
|
|
119
|
-
const pkgFile = await readFile(
|
|
120
|
-
join(typeof searchPath === "string" ? searchPath : fileURLToPath2(searchPath), "package.json"),
|
|
121
|
-
"utf-8"
|
|
122
|
-
);
|
|
123
|
-
return JSON.parse(pkgFile);
|
|
124
|
-
} catch (error) {
|
|
125
|
-
if (error.code === "ENOENT") {
|
|
126
|
-
return null;
|
|
127
|
-
}
|
|
128
|
-
throw error;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
112
|
// src/loader.ts
|
|
133
113
|
var swcConfig;
|
|
134
114
|
var tsConfig;
|
|
135
|
-
var subPathImports;
|
|
136
115
|
function isLocalPath(specifier) {
|
|
137
116
|
return specifier.startsWith("./") || specifier.startsWith("../") || specifier.startsWith("/") || specifier.startsWith("file:");
|
|
138
117
|
}
|
|
@@ -159,37 +138,28 @@ ${error.snippet}
|
|
|
159
138
|
async function initialize() {
|
|
160
139
|
const searchPath = process.env.TS_EXEC_PWD ?? process.cwd();
|
|
161
140
|
const config = getConfig(searchPath);
|
|
162
|
-
const pkgJSON = await getPackageJson(searchPath);
|
|
163
141
|
swcConfig = config.swcConfig;
|
|
164
142
|
tsConfig = config.tsConfig;
|
|
165
|
-
subPathImports = pkgJSON ? pkgJSON.imports : null;
|
|
166
143
|
}
|
|
167
144
|
var resolve = async (specifier, context, nextResolve) => {
|
|
168
145
|
debug_default("resolving specifier %s", specifier);
|
|
169
|
-
if (specifier.startsWith("#") && subPathImports) {
|
|
170
|
-
debug_default("resolving subpath import %s %O", specifier, subPathImports);
|
|
171
|
-
const resolvedPaths = resolveImports(subPathImports, specifier, context.conditions);
|
|
172
|
-
if (resolvedPaths.length) {
|
|
173
|
-
specifier = resolvedPaths[0];
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
debug_default("resolving file with specifier %s", specifier);
|
|
177
146
|
try {
|
|
178
147
|
return await nextResolve(specifier, context);
|
|
179
148
|
} catch (error) {
|
|
180
|
-
if (!tsConfig?.compilerOptions?.allowArbitraryExtensions && error.code === "ERR_MODULE_NOT_FOUND" && isLocalPath(
|
|
181
|
-
|
|
149
|
+
if (!tsConfig?.compilerOptions?.allowArbitraryExtensions && error.code === "ERR_MODULE_NOT_FOUND" && error.url && isLocalPath(error.url)) {
|
|
150
|
+
let url = error.url;
|
|
151
|
+
const fileExtension = extname(url);
|
|
182
152
|
if (fileExtension === ".js") {
|
|
183
|
-
|
|
153
|
+
url = url.replace(".js", ".ts");
|
|
184
154
|
} else if (fileExtension === ".mjs") {
|
|
185
|
-
|
|
155
|
+
url = url.replace(".mjs", ".mts");
|
|
186
156
|
} else if (fileExtension === ".cjs") {
|
|
187
|
-
|
|
157
|
+
url = url.replace(".cjs", ".cts");
|
|
188
158
|
} else if (fileExtension === ".jsx") {
|
|
189
|
-
|
|
159
|
+
url = url.replace(".jsx", ".tsx");
|
|
190
160
|
}
|
|
191
|
-
debug_default("retrying to resolve file with specifier %s",
|
|
192
|
-
return nextResolve(
|
|
161
|
+
debug_default("retrying to resolve file with specifier %s", url);
|
|
162
|
+
return nextResolve(url, context);
|
|
193
163
|
}
|
|
194
164
|
throw error;
|
|
195
165
|
}
|
|
@@ -205,7 +175,7 @@ var load = async function load2(url, context, nextLoad) {
|
|
|
205
175
|
});
|
|
206
176
|
const { code, map } = await transformSync(source.toString(), {
|
|
207
177
|
format: format ?? "module-tsx",
|
|
208
|
-
filename:
|
|
178
|
+
filename: fileURLToPath2(url),
|
|
209
179
|
...swcConfig
|
|
210
180
|
});
|
|
211
181
|
let output = code;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@poppinss/ts-exec",
|
|
3
3
|
"description": "TypeScript JIT compiler built for correctness and supports legacy/experimental decorators",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.2.0",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=24.0.0"
|
|
7
7
|
},
|
|
@@ -53,8 +53,7 @@
|
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@swc/core": "1.10.7",
|
|
56
|
-
"get-tsconfig": "^4.10.0"
|
|
57
|
-
"resolve-pkg-maps": "^1.0.0"
|
|
56
|
+
"get-tsconfig": "^4.10.0"
|
|
58
57
|
},
|
|
59
58
|
"homepage": "https://github.com/poppinss/ts-exec#readme",
|
|
60
59
|
"repository": {
|