@poppinss/ts-exec 1.1.4 → 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/README.md CHANGED
@@ -1,32 +1,49 @@
1
- # ts-exec
1
+ # @poppinss/ts-exec
2
+
3
+ TypeScript JIT compiler built for correctness and supports legacy/experimental decorators.
2
4
 
3
5
  <br />
4
6
 
5
7
  [![gh-workflow-image]][gh-workflow-url] [![npm-image]][npm-url] ![][typescript-image] [![license-image]][license-url]
6
8
 
7
- ## Introduction
9
+ > [!IMPORTANT]
10
+ > The `@poppinss/ts-exec` package requires `Node.js >= 24` and works with only ES modules.
11
+
12
+ ## Usage
13
+
14
+ Install the package from the npm packages registry.
15
+
16
+ ```sh
17
+ npm i -D @poppinss/ts-exec
18
+ ```
19
+
20
+ Once installed you can use it via the `--import` flag to execute the TypeScript source code.
21
+
22
+ ```sh
23
+ node --import=@poppinss/ts-exec some-script.ts
24
+ ```
8
25
 
9
- ## Official Documentation
26
+ ## Why another package?
10
27
 
11
28
  ## Contributing
12
29
 
13
- One of the primary goals of <org> is to have a vibrant community of users and contributors who believes in the principles of the framework.
30
+ One of the primary goals of Poppinss is to have a vibrant community of users and contributors who believes in the principles of the framework.
14
31
 
15
- We encourage you to read the [contribution guide](https://github.com/<org>/.github/blob/main/docs/CONTRIBUTING.md) before contributing to the framework.
32
+ We encourage you to read the [contribution guide](https://github.com/poppinss/.github/blob/main/docs/CONTRIBUTING.md) before contributing to the framework.
16
33
 
17
34
  ## Code of Conduct
18
35
 
19
- In order to ensure that the <org> community is welcoming to all, please review and abide by the [Code of Conduct](https://github.com/<org>/.github/blob/main/docs/CODE_OF_CONDUCT.md).
36
+ In order to ensure that the poppinss community is welcoming to all, please review and abide by the [Code of Conduct](https://github.com/poppinss/.github/blob/main/docs/CODE_OF_CONDUCT.md).
20
37
 
21
38
  ## License
22
39
 
23
40
  <pkg-name> is open-sourced software licensed under the [MIT license](LICENSE.md).
24
41
 
25
- [gh-workflow-image]: https://img.shields.io/github/actions/workflow/status/<org>/<repo>/checks.yml?style=for-the-badge
26
- [gh-workflow-url]: https://github.com/<org>/<repo>/actions/workflows/checks.yml 'Github action'
42
+ [gh-workflow-image]: https://img.shields.io/github/actions/workflow/status/poppinss/ts-exec/checks.yml?style=for-the-badge
43
+ [gh-workflow-url]: https://github.com/poppinss/ts-exec/actions/workflows/checks.yml 'Github action'
27
44
  [typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript
28
45
  [typescript-url]: "typescript"
29
- [npm-image]: https://img.shields.io/npm/v/<scope>/<repo>.svg?style=for-the-badge&logo=npm
30
- [npm-url]: https://npmjs.org/package/<scope>/<repo> 'npm'
31
- [license-image]: https://img.shields.io/npm/l/<scope>/<repo>?color=blueviolet&style=for-the-badge
46
+ [npm-image]: https://img.shields.io/npm/v/@poppinss/ts-exec.svg?style=for-the-badge&logo=npm
47
+ [npm-url]: https://npmjs.org/package/@poppinss/ts-exec 'npm'
48
+ [license-image]: https://img.shields.io/npm/l/@poppinss/ts-exec?color=blueviolet&style=for-the-badge
32
49
  [license-url]: LICENSE.md 'license'
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);
@@ -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?.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
- 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;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@poppinss/ts-exec",
3
- "description": "",
4
- "version": "1.1.4",
3
+ "description": "TypeScript JIT compiler built for correctness and supports legacy/experimental decorators",
4
+ "version": "1.2.0",
5
5
  "engines": {
6
6
  "node": ">=24.0.0"
7
7
  },
@@ -30,39 +30,38 @@
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-beta.6",
34
- "@adonisjs/prettier-config": "^1.4.0",
33
+ "@adonisjs/eslint-config": "^2.0.0",
34
+ "@adonisjs/prettier-config": "^1.4.4",
35
35
  "@adonisjs/tsconfig": "^1.4.0",
36
- "@japa/assert": "^4.0.0",
37
- "@japa/expect": "^3.0.2",
38
- "@japa/expect-type": "^2.0.2",
36
+ "@japa/assert": "^4.0.1",
37
+ "@japa/expect": "^3.0.4",
38
+ "@japa/expect-type": "^2.0.3",
39
39
  "@japa/file-system": "^2.3.2",
40
- "@japa/runner": "^3.1.4",
40
+ "@japa/runner": "^4.2.0",
41
41
  "@japa/snapshot": "^2.0.8",
42
- "@release-it/conventional-changelog": "^9.0.4",
42
+ "@release-it/conventional-changelog": "^10.0.1",
43
43
  "@types/node": "^22.10.2",
44
44
  "c8": "^10.1.3",
45
- "eslint": "^9.17.0",
45
+ "eslint": "^9.26.0",
46
46
  "ipaddr.js": "^2.2.0",
47
47
  "preact": "^10.26.6",
48
48
  "preact-render-to-string": "^6.5.13",
49
- "prettier": "^3.4.2",
50
- "release-it": "^17.11.0",
51
- "tsup": "^8.3.5",
52
- "typescript": "^5.7.2"
49
+ "prettier": "^3.5.3",
50
+ "release-it": "^19.0.2",
51
+ "tsup": "^8.4.0",
52
+ "typescript": "^5.8.3"
53
53
  },
54
54
  "dependencies": {
55
- "@swc/core": "^1.11.24",
56
- "get-tsconfig": "^4.10.0",
57
- "resolve-pkg-maps": "^1.0.0"
55
+ "@swc/core": "1.10.7",
56
+ "get-tsconfig": "^4.10.0"
58
57
  },
59
- "homepage": "https://github.com/thetutlage/ts-exec#readme",
58
+ "homepage": "https://github.com/poppinss/ts-exec#readme",
60
59
  "repository": {
61
60
  "type": "git",
62
- "url": "git+https://github.com/thetutlage/ts-exec.git"
61
+ "url": "git+https://github.com/poppinss/ts-exec.git"
63
62
  },
64
63
  "bugs": {
65
- "url": "https://github.com/thetutlage/ts-exec/issues"
64
+ "url": "https://github.com/poppinss/ts-exec/issues"
66
65
  },
67
66
  "keywords": [
68
67
  "typescript",
@@ -73,7 +72,8 @@
73
72
  "author": "Harminder Virk <virk@adonisjs.com>",
74
73
  "license": "MIT",
75
74
  "publishConfig": {
76
- "access": "public"
75
+ "access": "public",
76
+ "provenance": true
77
77
  },
78
78
  "tsup": {
79
79
  "entry": [
@@ -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>;