tsnite 0.0.17 → 0.0.19
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 +17 -0
- package/dist/cli.js +13 -0
- package/dist/loader.js +33 -21
- package/package.json +16 -10
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
|
|
3
|
+
import { readFile } from 'node:fs/promises';
|
|
4
4
|
import json5 from 'json5';
|
|
5
5
|
import path from 'node:path';
|
|
6
|
-
|
|
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
|
|
9
|
-
|
|
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 = path.join(process.cwd(), baseUrl) || process.cwd();
|
|
17
|
+
return tsconfigCache;
|
|
10
18
|
}
|
|
11
19
|
catch {
|
|
12
|
-
|
|
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
|
|
53
|
+
if (await existsWithCache(file)) {
|
|
54
|
+
const url = pathToFileURL(file).href;
|
|
55
|
+
resolveCache.set(cacheKey, url);
|
|
35
56
|
return {
|
|
36
|
-
url
|
|
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
|
|
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:
|
|
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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsnite",
|
|
3
3
|
"description": "TypeScript at full throttle—fast, safe, unstoppable. 🚀",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.19",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
7
7
|
"esm",
|
|
@@ -9,15 +9,21 @@
|
|
|
9
9
|
"nodejs",
|
|
10
10
|
"typescript"
|
|
11
11
|
],
|
|
12
|
-
"
|
|
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 . --
|
|
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,31 @@
|
|
|
26
32
|
"prepare": "husky"
|
|
27
33
|
},
|
|
28
34
|
"dependencies": {
|
|
29
|
-
"@swc/core": "^1.15.
|
|
35
|
+
"@swc/core": "^1.15.18",
|
|
30
36
|
"chokidar": "^5.0.0",
|
|
31
37
|
"commander": "^14.0.3",
|
|
32
38
|
"json5": "^2.2.3"
|
|
33
39
|
},
|
|
34
40
|
"devDependencies": {
|
|
35
|
-
"@commitlint/cli": "^20.4.
|
|
36
|
-
"@commitlint/config-conventional": "^20.4.
|
|
41
|
+
"@commitlint/cli": "^20.4.2",
|
|
42
|
+
"@commitlint/config-conventional": "^20.4.2",
|
|
37
43
|
"@eslint/js": "^10.0.1",
|
|
38
44
|
"@jest/globals": "^30.2.0",
|
|
39
45
|
"@swc/jest": "^0.2.39",
|
|
40
|
-
"eslint": "^10.0.
|
|
46
|
+
"eslint": "^10.0.2",
|
|
41
47
|
"eslint-plugin-jest": "^29.15.0",
|
|
42
48
|
"eslint-plugin-prettier": "^5.5.5",
|
|
43
|
-
"globals": "^17.
|
|
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.
|
|
54
|
+
"lint-staged": "^16.3.1",
|
|
49
55
|
"prettier": "^3.8.1",
|
|
50
56
|
"rimraf": "^6.1.3",
|
|
51
57
|
"tsc-alias": "^1.8.16",
|
|
52
58
|
"typescript": "^5.9.3",
|
|
53
|
-
"typescript-eslint": "^8.56.
|
|
59
|
+
"typescript-eslint": "^8.56.1"
|
|
54
60
|
},
|
|
55
61
|
"engines": {
|
|
56
62
|
"node": "^20.9.0 || ^22.11.0 || ^24.11.0"
|