@poppinss/ts-exec 1.1.5 → 1.2.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/build/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // index.ts
2
- import { register } from "node:module";
2
+ import { register } from "module";
3
3
  register("./src/loader.js", import.meta.url);
@@ -5,7 +5,11 @@ import { type TsConfigJsonResolved } from 'get-tsconfig';
5
5
  * file in the provided search path
6
6
  */
7
7
  export declare function getConfig(searchPath: string | URL): {
8
- tsConfig: TsConfigJsonResolved | null;
8
+ tsConfig: (TsConfigJsonResolved & {
9
+ compilerOptions?: {
10
+ rewriteRelativeImportExtensions?: boolean;
11
+ };
12
+ }) | null;
9
13
  tsConfigPath: string | null;
10
14
  swcConfig: SWCConfig;
11
15
  };
@@ -1,14 +1,13 @@
1
1
  // src/loader.ts
2
- import { extname } from "node:path";
3
- import { fileURLToPath as fileURLToPath3 } from "node:url";
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 "node:util";
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 "node:url";
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(specifier)) {
181
- const fileExtension = extname(specifier);
149
+ if (!tsConfig?.compilerOptions?.rewriteRelativeImportExtensions && 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
- specifier = specifier.replace(".js", ".ts");
153
+ url = url.replace(".js", ".ts");
184
154
  } else if (fileExtension === ".mjs") {
185
- specifier = specifier.replace(".mjs", ".mts");
155
+ url = url.replace(".mjs", ".mts");
186
156
  } else if (fileExtension === ".cjs") {
187
- specifier = specifier.replace(".cjs", ".cts");
157
+ url = url.replace(".cjs", ".cts");
188
158
  } else if (fileExtension === ".jsx") {
189
- specifier = specifier.replace(".jsx", ".tsx");
159
+ url = url.replace(".jsx", ".tsx");
190
160
  }
191
- debug_default("retrying to resolve file with specifier %s", specifier);
192
- return nextResolve(specifier, context);
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: fileURLToPath3(url),
178
+ filename: fileURLToPath2(url),
209
179
  ...swcConfig
210
180
  });
211
181
  let output = code;
@@ -1,4 +1,4 @@
1
- import { Config as SwcConfig } from '@swc/core';
1
+ import { type Config as SwcConfig } from '@swc/core';
2
2
  /**
3
3
  * Transforms source code using SWC
4
4
  */
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.1.5",
4
+ "version": "1.2.1",
5
5
  "engines": {
6
6
  "node": ">=24.0.0"
7
7
  },
@@ -30,9 +30,9 @@
30
30
  "quick:test": "node --experimental-transform-types --enable-source-maps bin/test.ts"
31
31
  },
32
32
  "devDependencies": {
33
- "@adonisjs/eslint-config": "^2.0.0",
34
- "@adonisjs/prettier-config": "^1.4.4",
35
- "@adonisjs/tsconfig": "^1.4.0",
33
+ "@adonisjs/eslint-config": "^3.0.0-next.0",
34
+ "@adonisjs/prettier-config": "^1.4.5",
35
+ "@adonisjs/tsconfig": "^2.0.0-next.0",
36
36
  "@japa/assert": "^4.0.1",
37
37
  "@japa/expect": "^3.0.4",
38
38
  "@japa/expect-type": "^2.0.3",
@@ -40,21 +40,20 @@
40
40
  "@japa/runner": "^4.2.0",
41
41
  "@japa/snapshot": "^2.0.8",
42
42
  "@release-it/conventional-changelog": "^10.0.1",
43
- "@types/node": "^22.10.2",
43
+ "@types/node": "^22.15.23",
44
44
  "c8": "^10.1.3",
45
- "eslint": "^9.26.0",
45
+ "eslint": "^9.27.0",
46
46
  "ipaddr.js": "^2.2.0",
47
- "preact": "^10.26.6",
47
+ "preact": "^10.26.7",
48
48
  "preact-render-to-string": "^6.5.13",
49
49
  "prettier": "^3.5.3",
50
50
  "release-it": "^19.0.2",
51
- "tsup": "^8.4.0",
51
+ "tsup": "^8.5.0",
52
52
  "typescript": "^5.8.3"
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.1"
58
57
  },
59
58
  "homepage": "https://github.com/poppinss/ts-exec#readme",
60
59
  "repository": {
@@ -1,4 +0,0 @@
1
- /**
2
- * Returns the contents of the package.json file
3
- */
4
- export declare function getPackageJson(searchPath: string | URL): Promise<any>;