ts-arc 1.0.1 → 1.0.3
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/bin.js +2 -19
- package/dist/loader.js +1 -50
- package/package.json +6 -6
package/dist/bin.js
CHANGED
|
@@ -1,20 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import * as url from "node:url";
|
|
5
|
-
const __filename = url.fileURLToPath(import.meta.url);
|
|
6
|
-
const __dirname = path.dirname(__filename);
|
|
7
|
-
const loaderPath = path.join(__dirname, "loader.js");
|
|
8
|
-
register(loaderPath, url.pathToFileURL(__dirname).href);
|
|
9
|
-
const script = process.argv[2];
|
|
10
|
-
if (!script) {
|
|
11
|
-
console.error("Usage: node bin.js <script.ts> [args...]");
|
|
12
|
-
process.exit(1);
|
|
13
|
-
}
|
|
14
|
-
const scriptPath = path.resolve(script);
|
|
15
|
-
const scriptUrl = url.pathToFileURL(scriptPath).href;
|
|
16
|
-
process.argv = [process.argv[0], script, ...process.argv.slice(3)];
|
|
17
|
-
import(scriptUrl).catch((err) => {
|
|
18
|
-
console.error(err);
|
|
19
|
-
process.exit(1);
|
|
20
|
-
});
|
|
2
|
+
import{register as b}from"node:module";import*as n from"node:path";import*as c from"node:url";import*as p from"node:fs";import{createRequire as j}from"node:module";const h=j(import.meta.url),C=c.fileURLToPath(import.meta.url),d=n.dirname(C),x=n.join(d,"loader.js");b(x,c.pathToFileURL(d).href);const l=process.argv[2];l||(console.error("Usage: node bin.js <script.ts> [args...]"),process.exit(1));const u=n.resolve(l),O=c.pathToFileURL(u).href;process.argv=[process.argv[0],l,...process.argv.slice(3)];function _(s){let t="",o=!1,e=0;for(;e<s.length;){const r=s[e];if(o){t+=r,r==='"'&&s[e-1]!=="\\"&&(o=!1),e++;continue}if(r==='"'){o=!0,t+=r,e++;continue}if(r==="/"&&s[e+1]==="/"){for(e+=2;e<s.length&&s[e]!==`
|
|
3
|
+
`;)e++;continue}if(r==="/"&&s[e+1]==="*"){for(e+=2;e<s.length&&!(s[e-1]==="*"&&s[e]==="/");)e++;e<s.length&&e++;continue}t+=r,e++}return t}function v(s){const t=p.readFileSync(s,"utf8"),o=_(t),e=JSON.parse(o);if(!e.extends)return e;const r=e.extends,U=n.dirname(s);let i;if(r.startsWith("./")||r.startsWith("../"))i=n.resolve(U,r),i.endsWith(".json")||(i+=".json");else try{i=h.resolve(r)}catch{i=h.resolve(r+"/tsconfig.json")}const g=v(i),m={...g,...e};return m.compilerOptions={...g.compilerOptions||{},...e.compilerOptions||{}},m}function P(s){let t=s;for(;t!==n.parse(t).root;){const o=n.join(t,"tsconfig.json");if(p.existsSync(o))return o;t=n.dirname(t)}return null}const a=P(n.dirname(u));let f={baseUrl:null,paths:{}};if(a){const t=v(a).compilerOptions||{},o=n.dirname(a),e=t.baseUrl;f.baseUrl=e?n.resolve(o,e):null,f.paths=t.paths||{}}global.__tsArcConfig=f,import(O).catch(s=>{console.error(s),process.exit(1)});
|
package/dist/loader.js
CHANGED
|
@@ -1,51 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import * as
|
|
3
|
-
import * as url from "url";
|
|
4
|
-
import { transformSync } from "esbuild";
|
|
5
|
-
async function resolve(specifier, context, nextResolve) {
|
|
6
|
-
try {
|
|
7
|
-
const resolved = await nextResolve(specifier, context);
|
|
8
|
-
return resolved;
|
|
9
|
-
} catch (error) {
|
|
10
|
-
if (error.code !== "ERR_MODULE_NOT_FOUND") {
|
|
11
|
-
throw error;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
try {
|
|
15
|
-
const resolved = await nextResolve(specifier + ".ts", context);
|
|
16
|
-
return { ...resolved, shortCircuit: true };
|
|
17
|
-
} catch (error) {
|
|
18
|
-
if (error.code !== "ERR_MODULE_NOT_FOUND") {
|
|
19
|
-
throw error;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
try {
|
|
23
|
-
const resolved = await nextResolve(specifier + "/index.ts", context);
|
|
24
|
-
return { ...resolved, shortCircuit: true };
|
|
25
|
-
} catch (error) {
|
|
26
|
-
throw error;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
async function load(urlStr, context, nextLoad) {
|
|
30
|
-
if (urlStr.endsWith(".ts")) {
|
|
31
|
-
const filePath = url.fileURLToPath(urlStr);
|
|
32
|
-
const rawSource = fs.readFileSync(filePath, "utf8");
|
|
33
|
-
const { code } = transformSync(rawSource, {
|
|
34
|
-
loader: "ts",
|
|
35
|
-
format: "esm",
|
|
36
|
-
target: `node${process.versions.node}`,
|
|
37
|
-
sourcemap: "inline",
|
|
38
|
-
sourcefile: filePath
|
|
39
|
-
});
|
|
40
|
-
return {
|
|
41
|
-
format: "module",
|
|
42
|
-
source: code,
|
|
43
|
-
shortCircuit: true
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
return nextLoad(urlStr, context);
|
|
47
|
-
}
|
|
48
|
-
export {
|
|
49
|
-
load,
|
|
50
|
-
resolve
|
|
51
|
-
};
|
|
2
|
+
import*as m from"fs";import*as l from"path";import*as f from"url";import{transformSync as g}from"esbuild";async function U(t,n,o){if(t.startsWith(".")||t.startsWith("/"))return o(t,n);const i=global.__tsArcConfig;if(i){const{baseUrl:r,paths:a}=i;for(const s of Object.keys(a)){let e=null;if(s.endsWith("/*")){const c=s.slice(0,-2);t.startsWith(c)&&(e=t.slice(c.length))}else t===s&&(e="");if(e!==null)for(const c of a[s]){const h=c.replace(/\*/g,e);if(r){const d=f.pathToFileURL(l.join(r,"dummy.ts")).href;try{return{...await o(`./${h}`,{parentURL:d}),shortCircuit:!0}}catch(u){if(u.code!=="ERR_MODULE_NOT_FOUND")throw u}}}}if(r){const s=f.pathToFileURL(l.join(r,"dummy.ts")).href;try{return{...await o(`./${t}`,{parentURL:s}),shortCircuit:!0}}catch(e){if(e.code!=="ERR_MODULE_NOT_FOUND")throw e}}}try{return await o(t,n)}catch(r){if(r.code!=="ERR_MODULE_NOT_FOUND")throw r}try{return{...await o(t+".ts",n),shortCircuit:!0}}catch(r){if(r.code!=="ERR_MODULE_NOT_FOUND")throw r}try{return{...await o(t+"/index.ts",n),shortCircuit:!0}}catch(r){throw r}}async function _(t,n,o){let i="ts";if(!t.endsWith(".ts"))if(t.endsWith(".tsx"))i="tsx";else return o(t,n);const r=f.fileURLToPath(t),a=m.readFileSync(r,"utf8"),{code:s}=g(a,{loader:i,format:"esm",target:`node${process.versions.node}`,sourcemap:"inline",sourcefile:r});return{format:"module",source:s,shortCircuit:!0}}export{_ as load,U as resolve};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-arc",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A simple typescript runtime.",
|
|
6
6
|
"main": "dist/bin.js",
|
|
@@ -8,18 +8,18 @@
|
|
|
8
8
|
"ts-arc": "./dist/bin.js"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
|
-
"build": "npx esbuild ./src/loader.ts ./src/bin.ts --outdir=./dist --platform=node --format=esm"
|
|
11
|
+
"build": "npx esbuild ./src/loader.ts ./src/bin.ts --outdir=./dist --platform=node --format=esm --minify=true"
|
|
12
12
|
},
|
|
13
13
|
"keywords": [],
|
|
14
14
|
"author": "",
|
|
15
15
|
"license": "ISC",
|
|
16
|
-
"devDependencies": {
|
|
17
|
-
"@types/node": "^24.9.1"
|
|
18
|
-
},
|
|
19
16
|
"dependencies": {
|
|
20
17
|
"esbuild": "^0.25.11"
|
|
21
18
|
},
|
|
22
19
|
"files": [
|
|
23
20
|
"dist"
|
|
24
|
-
]
|
|
21
|
+
],
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/node": "^24.9.1"
|
|
24
|
+
}
|
|
25
25
|
}
|