@poppinss/ts-exec 1.1.0 → 1.1.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.
@@ -1,6 +1,7 @@
1
1
  // src/loader.ts
2
2
  import { extname } from "node:path";
3
3
  import { fileURLToPath as fileURLToPath3 } from "node:url";
4
+ import { createError } from "@poppinss/exception";
4
5
  import { resolveImports } from "resolve-pkg-maps";
5
6
 
6
7
  // src/debug.ts
@@ -123,6 +124,10 @@ async function getPackageJson(searchPath) {
123
124
  var swcConfig;
124
125
  var tsConfig;
125
126
  var subPathImports;
127
+ var ERR_UNKNOWN_FILE_EXTENSION = createError(
128
+ 'Unknown file extension "%s"',
129
+ "ERR_UNKNOWN_FILE_EXTENSION"
130
+ );
126
131
  var UNALLOWED_FILE_EXTENSIONS = [".tsx", ".ts", ".mts", ".cts"];
127
132
  function isLocalPath(specifier) {
128
133
  return specifier.startsWith("./") || specifier.startsWith("../") || specifier.startsWith("/") || specifier.startsWith("file:");
@@ -169,8 +174,16 @@ var resolve = async (specifier, context, nextResolve) => {
169
174
  if (isLocalPath(specifier)) {
170
175
  const fileExtension = extname(specifier);
171
176
  if (UNALLOWED_FILE_EXTENSIONS.includes(fileExtension) && context.parentURL) {
172
- throw new Error(`Unknown file extension "${fileExtension}"`);
177
+ throw new ERR_UNKNOWN_FILE_EXTENSION([fileExtension]);
173
178
  }
179
+ }
180
+ }
181
+ debug_default("resolving file with specifier %s", specifier);
182
+ try {
183
+ return await nextResolve(specifier, context);
184
+ } catch (error) {
185
+ if (!allowArbitraryExtensions && error.code === "ERR_MODULE_NOT_FOUND" && isLocalPath(specifier)) {
186
+ const fileExtension = extname(specifier);
174
187
  if (fileExtension === ".js") {
175
188
  specifier = specifier.replace(".js", ".ts");
176
189
  } else if (fileExtension === ".mjs") {
@@ -180,10 +193,11 @@ var resolve = async (specifier, context, nextResolve) => {
180
193
  } else if (fileExtension === ".jsx") {
181
194
  specifier = specifier.replace(".jsx", ".tsx");
182
195
  }
196
+ debug_default("retrying to resolve file with specifier %s", specifier);
197
+ return nextResolve(specifier, context);
183
198
  }
199
+ throw error;
184
200
  }
185
- debug_default("resolving file with specifier %s", specifier);
186
- return nextResolve(specifier, context);
187
201
  };
188
202
  var load = async function load2(url, context, nextLoad) {
189
203
  const { format } = context;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@poppinss/ts-exec",
3
3
  "description": "",
4
- "version": "1.1.0",
4
+ "version": "1.1.1",
5
5
  "engines": {
6
6
  "node": ">=20.6.0"
7
7
  },
@@ -52,6 +52,7 @@
52
52
  "typescript": "^5.7.2"
53
53
  },
54
54
  "dependencies": {
55
+ "@poppinss/exception": "^1.2.1",
55
56
  "@swc/core": "^1.11.24",
56
57
  "get-tsconfig": "^4.10.0",
57
58
  "resolve-pkg-maps": "^1.0.0"