tsnite 0.0.16 → 0.0.18

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/cache.js ADDED
@@ -0,0 +1,17 @@
1
+ import { stat } from 'node:fs/promises';
2
+ export const resolveCache = new Map();
3
+ const statCache = new Map();
4
+ export async function existsWithCache(filePath) {
5
+ const cached = statCache.get(filePath);
6
+ if (cached)
7
+ return cached.exists;
8
+ try {
9
+ const stats = await stat(filePath);
10
+ statCache.set(filePath, { exists: true, mtime: stats.mtimeMs });
11
+ return true;
12
+ }
13
+ catch {
14
+ statCache.set(filePath, { exists: false });
15
+ return false;
16
+ }
17
+ }
package/dist/cli.js CHANGED
@@ -18,6 +18,19 @@ program
18
18
  .argument('<string>', 'Entrypoint file')
19
19
  .argument('[args...]', 'Specify the Node.js command and any additional arguments')
20
20
  .showSuggestionAfterError();
21
+ function cleanup() {
22
+ for (const pid of pids.values()) {
23
+ try {
24
+ process.kill(pid, 'SIGTERM');
25
+ }
26
+ catch {
27
+ // processo já morreu
28
+ }
29
+ }
30
+ process.exit(0);
31
+ }
32
+ process.on('SIGINT', cleanup);
33
+ process.on('SIGTERM', cleanup);
21
34
  async function handler() {
22
35
  const options = program.opts();
23
36
  const [entry, nodeArgs] = program.processedArgs;
package/dist/loader.js CHANGED
@@ -1,21 +1,40 @@
1
1
  import { transformFile } from '@swc/core';
2
2
  import { fileURLToPath, pathToFileURL } from 'node:url';
3
- import { readFile, access, constants } from 'node:fs/promises';
3
+ import { readFile } from 'node:fs/promises';
4
4
  import json5 from 'json5';
5
5
  import path from 'node:path';
6
- async function exists(path) {
6
+ import { resolveCache, existsWithCache } from './cache.js';
7
+ const tsconfigCache = { paths: null, baseUrl: null };
8
+ async function loadTSConfig() {
9
+ if (tsconfigCache.paths !== null && tsconfigCache.baseUrl !== null) {
10
+ return tsconfigCache;
11
+ }
7
12
  try {
8
- await access(path, constants.F_OK);
9
- return true;
13
+ const data = await readFile(path.join(process.cwd(), 'tsconfig.json'), 'utf-8');
14
+ const { compilerOptions: { paths, baseUrl } } = json5.parse(data);
15
+ tsconfigCache.paths = paths || null;
16
+ tsconfigCache.baseUrl = baseUrl || process.cwd();
17
+ return tsconfigCache;
10
18
  }
11
19
  catch {
12
- return false;
20
+ tsconfigCache.paths = null;
21
+ tsconfigCache.baseUrl = process.cwd();
22
+ return tsconfigCache;
13
23
  }
14
24
  }
15
25
  export async function resolve(specifier, ctx, next) {
16
26
  if (!specifier.startsWith('.') && !specifier.startsWith('/')) {
17
27
  return next(specifier, ctx);
18
28
  }
29
+ const cacheKey = `${ctx.parentURL}::${specifier}`;
30
+ const cached = resolveCache.get(cacheKey);
31
+ if (cached) {
32
+ return {
33
+ url: cached,
34
+ format: 'module',
35
+ shortCircuit: true
36
+ };
37
+ }
19
38
  const parentPath = fileURLToPath(ctx.parentURL);
20
39
  const parentDir = path.dirname(parentPath);
21
40
  const basePath = path.resolve(parentDir, specifier);
@@ -31,38 +50,31 @@ export async function resolve(specifier, ctx, next) {
31
50
  path.join(basePath, 'index.mjs')
32
51
  ];
33
52
  for (const file of tryFiles) {
34
- if (await exists(file)) {
53
+ if (await existsWithCache(file)) {
54
+ const url = pathToFileURL(file).href;
55
+ resolveCache.set(cacheKey, url);
35
56
  return {
36
- url: pathToFileURL(file).href,
57
+ url,
37
58
  format: 'module',
38
59
  shortCircuit: true
39
60
  };
40
61
  }
41
62
  }
42
- }
43
- async function loadTsconfigPaths() {
44
- try {
45
- const data = await readFile(path.join(process.cwd(), 'tsconfig.json'), 'utf-8');
46
- const { compilerOptions: { paths } } = json5.parse(data);
47
- return paths;
48
- }
49
- catch {
50
- return {};
51
- }
63
+ return next(specifier, ctx);
52
64
  }
53
65
  export async function load(url, ctx, next) {
54
66
  if (!url.startsWith('file://') || !url.endsWith('.ts')) {
55
67
  return next(url, ctx);
56
68
  }
57
- const paths = await loadTsconfigPaths();
69
+ const { paths, baseUrl } = await loadTSConfig();
58
70
  const filename = fileURLToPath(url);
59
71
  const { code } = await transformFile(filename, {
60
72
  filename,
61
73
  jsc: {
62
- baseUrl: process.cwd(),
74
+ baseUrl: baseUrl || process.cwd(),
63
75
  parser: {
64
76
  syntax: 'typescript',
65
- tsx: false,
77
+ tsx: url.endsWith('.tsx'),
66
78
  decorators: true
67
79
  },
68
80
  target: 'es2022',
@@ -78,7 +90,7 @@ export async function load(url, ctx, next) {
78
90
  development: true
79
91
  }
80
92
  },
81
- paths
93
+ paths: paths ?? {}
82
94
  },
83
95
  module: {
84
96
  type: 'es6',
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "tsnite",
3
3
  "description": "TypeScript at full throttle—fast, safe, unstoppable. 🚀",
4
+ "version": "0.0.18",
4
5
  "keywords": [
5
6
  "cli",
6
7
  "esm",
@@ -8,16 +9,21 @@
8
9
  "nodejs",
9
10
  "typescript"
10
11
  ],
11
- "version": "0.0.16",
12
- "type": "module",
12
+ "files": [
13
+ "dist",
14
+ "README.md",
15
+ "LICENSE",
16
+ "package.json"
17
+ ],
13
18
  "bin": {
14
19
  "tsnite": "dist/cli.js"
15
20
  },
21
+ "type": "module",
16
22
  "scripts": {
17
23
  "prebuild": "rimraf dist",
18
24
  "build": "tsc -p tsconfig.build.json",
19
25
  "postbuild": "tsc-alias -f -p tsconfig.build.json",
20
- "lint": "eslint . --config eslint.config.js",
26
+ "lint": "eslint . --cache",
21
27
  "test": "jest --passWithNoTests --verbose",
22
28
  "test:ci": "jest --passWithNoTests --ci",
23
29
  "test:watch": "jest --passWithNoTests --watch",
@@ -26,31 +32,34 @@
26
32
  "prepare": "husky"
27
33
  },
28
34
  "dependencies": {
29
- "@swc/core": "^1.15.11",
35
+ "@swc/core": "^1.15.18",
30
36
  "chokidar": "^5.0.0",
31
- "commander": "^14.0.2",
37
+ "commander": "^14.0.3",
32
38
  "json5": "^2.2.3"
33
39
  },
34
40
  "devDependencies": {
35
- "@commitlint/cli": "^20.3.1",
36
- "@commitlint/config-conventional": "^20.3.1",
37
- "@eslint/js": "^9.39.2",
41
+ "@commitlint/cli": "^20.4.2",
42
+ "@commitlint/config-conventional": "^20.4.2",
43
+ "@eslint/js": "^10.0.1",
38
44
  "@jest/globals": "^30.2.0",
39
45
  "@swc/jest": "^0.2.39",
40
- "eslint": "^9.39.2",
41
- "eslint-plugin-jest": "^29.12.1",
46
+ "eslint": "^10.0.2",
47
+ "eslint-plugin-jest": "^29.15.0",
42
48
  "eslint-plugin-prettier": "^5.5.5",
43
- "globals": "^17.2.0",
49
+ "globals": "^17.4.0",
44
50
  "husky": "^9.1.7",
45
51
  "jest": "^30.2.0",
46
52
  "jest-environment-node": "^30.2.0",
47
53
  "jest-mock-extended": "^4.0.0",
48
- "lint-staged": "^16.2.7",
54
+ "lint-staged": "^16.3.1",
49
55
  "prettier": "^3.8.1",
50
- "rimraf": "^6.1.2",
56
+ "rimraf": "^6.1.3",
51
57
  "tsc-alias": "^1.8.16",
52
58
  "typescript": "^5.9.3",
53
- "typescript-eslint": "^8.54.0"
59
+ "typescript-eslint": "^8.56.1"
60
+ },
61
+ "engines": {
62
+ "node": "^20.9.0 || ^22.11.0 || ^24.11.0"
54
63
  },
55
64
  "author": {
56
65
  "name": "Luciano Alves",