ts-arc 1.0.0 → 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 CHANGED
@@ -1,19 +1,3 @@
1
- import { register } from "node:module";
2
- import * as path from "node:path";
3
- import * as url from "node:url";
4
- const __filename = url.fileURLToPath(import.meta.url);
5
- const __dirname = path.dirname(__filename);
6
- const loaderPath = path.join(__dirname, "loader.js");
7
- register(loaderPath, url.pathToFileURL(__dirname).href);
8
- const script = process.argv[2];
9
- if (!script) {
10
- console.error("Usage: node bin.js <script.ts> [args...]");
11
- process.exit(1);
12
- }
13
- const scriptPath = path.resolve(script);
14
- const scriptUrl = url.pathToFileURL(scriptPath).href;
15
- process.argv = [process.argv[0], script, ...process.argv.slice(3)];
16
- import(scriptUrl).catch((err) => {
17
- console.error(err);
18
- process.exit(1);
19
- });
1
+ #!/usr/bin/env node
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,50 +1,2 @@
1
- import * as fs from "fs";
2
- import * as url from "url";
3
- import { transformSync } from "esbuild";
4
- async function resolve(specifier, context, nextResolve) {
5
- try {
6
- const resolved = await nextResolve(specifier, context);
7
- return resolved;
8
- } catch (error) {
9
- if (error.code !== "ERR_MODULE_NOT_FOUND") {
10
- throw error;
11
- }
12
- }
13
- try {
14
- const resolved = await nextResolve(specifier + ".ts", context);
15
- return { ...resolved, shortCircuit: true };
16
- } catch (error) {
17
- if (error.code !== "ERR_MODULE_NOT_FOUND") {
18
- throw error;
19
- }
20
- }
21
- try {
22
- const resolved = await nextResolve(specifier + "/index.ts", context);
23
- return { ...resolved, shortCircuit: true };
24
- } catch (error) {
25
- throw error;
26
- }
27
- }
28
- async function load(urlStr, context, nextLoad) {
29
- if (urlStr.endsWith(".ts")) {
30
- const filePath = url.fileURLToPath(urlStr);
31
- const rawSource = fs.readFileSync(filePath, "utf8");
32
- const { code } = transformSync(rawSource, {
33
- loader: "ts",
34
- format: "esm",
35
- target: `node${process.versions.node}`,
36
- sourcemap: "inline",
37
- sourcefile: filePath
38
- });
39
- return {
40
- format: "module",
41
- source: code,
42
- shortCircuit: true
43
- };
44
- }
45
- return nextLoad(urlStr, context);
46
- }
47
- export {
48
- load,
49
- resolve
50
- };
1
+ #!/usr/bin/env node
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.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
  }