ts-arc 1.1.1 → 1.1.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/README.md ADDED
@@ -0,0 +1,8 @@
1
+ # ts-arc
2
+ A simple & fast typescript runner.
3
+ ## Usage
4
+ `npx ts-arc [filename].ts`
5
+
6
+ ## Features
7
+ - Full TypeScript Support!
8
+ - CommonJS Interoperability.
package/dist/bin.js CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
- import{register as v}from"node:module";import*as o from"node:path";import*as l from"node:url";import*as p from"node:fs";import{createRequire as b}from"node:module";const h=b(import.meta.url),j=l.fileURLToPath(import.meta.url),x=o.dirname(j),C=o.join(x,"loader.js"),a=process.argv[2];a||(console.error("Usage: node bin.js <script.ts> [args...]"),process.exit(1));const d=o.resolve(a),O=l.pathToFileURL(d).href;process.argv=[process.argv[0],a,...process.argv.slice(3)];function D(s){let e="",n=!1,t=0;for(;t<s.length;){const r=s[t];if(n){e+=r,r==='"'&&s[t-1]!=="\\"&&(n=!1),t++;continue}if(r==='"'){n=!0,e+=r,t++;continue}if(r==="/"&&s[t+1]==="/"){for(t+=2;t<s.length&&s[t]!==`
3
- `;)t++;continue}if(r==="/"&&s[t+1]==="*"){for(t+=2;t<s.length&&!(s[t-1]==="*"&&s[t]==="/");)t++;t<s.length&&t++;continue}e+=r,t++}return e}function u(s){const e=p.readFileSync(s,"utf8"),n=D(e),t=JSON.parse(n);if(!t.extends)return t;const r=t.extends,U=o.dirname(s);let i;if(r.startsWith("./")||r.startsWith("../"))i=o.resolve(U,r),i.endsWith(".json")||(i+=".json");else try{i=h.resolve(r)}catch{i=h.resolve(r+"/tsconfig.json")}const g=u(i),m={...g,...t};return m.compilerOptions={...g.compilerOptions||{},...t.compilerOptions||{}},m}function P(s){let e=s;for(;e!==o.parse(e).root;){const n=o.join(e,"tsconfig.json");if(p.existsSync(n))return n;e=o.dirname(e)}return null}const f=P(o.dirname(d));let c={baseUrl:null,paths:{},tsconfigDir:null};if(f){const e=u(f).compilerOptions||{},n=o.dirname(f),t=e.baseUrl;c.baseUrl=t?o.resolve(n,t):null,c.paths=e.paths||{},c.tsconfigDir=n}const R=l.pathToFileURL(C).href;v(R,{data:c}),import(O).catch(s=>{console.error(s),process.exit(1)});
2
+ import{register as v}from"node:module";import*as o from"node:path";import*as l from"node:url";import*as p from"node:fs";import{createRequire as b}from"node:module";const h=b(import.meta.url),j=l.fileURLToPath(import.meta.url),C=o.dirname(j),x=o.join(C,"loader.js"),a=process.argv[2];a||(console.error("Usage: node bin.js <script.ts> [args...]"),process.exit(1));const d=o.resolve(a),R=l.pathToFileURL(d).href;process.argv=[process.argv[0],a,...process.argv.slice(3)];function O(e){let t="",n=!1,s=0;for(;s<e.length;){const r=e[s];if(n){t+=r,r==='"'&&e[s-1]!=="\\"&&(n=!1),s++;continue}if(r==='"'){n=!0,t+=r,s++;continue}if(r==="/"&&e[s+1]==="/"){for(s+=2;s<e.length&&e[s]!==`
3
+ `;)s++;continue}if(r==="/"&&e[s+1]==="*"){for(s+=2;s<e.length&&!(e[s-1]==="*"&&e[s]==="/");)s++;s<e.length&&s++;continue}t+=r,s++}return t}function u(e){const t=p.readFileSync(e,"utf8"),n=O(t),s=JSON.parse(n);if(!s.extends)return s;const r=s.extends,U=o.dirname(e);let i;if(r.startsWith("./")||r.startsWith("../"))i=o.resolve(U,r),i.endsWith(".json")||(i+=".json");else try{i=h.resolve(r)}catch{i=h.resolve(r+"/tsconfig.json")}const g=u(i),m={...g,...s};return m.compilerOptions={...g.compilerOptions||{},...s.compilerOptions||{}},m}function S(e){let t=e;for(;t!==o.parse(t).root;){const n=o.join(t,"tsconfig.json");if(p.existsSync(n))return n;t=o.dirname(t)}return null}const f=S(o.dirname(d));let c={baseUrl:null,paths:{},tsconfigDir:null};if(f){const t=u(f).compilerOptions||{},n=o.dirname(f),s=t.baseUrl;c.baseUrl=s?o.resolve(n,s):null,c.paths=t.paths||{},c.tsconfigDir=n}const D=l.pathToFileURL(x).href;v(D,{data:c}),console.log("TS-ARC: Registered tsconfig as:",c),import(R).catch(e=>{console.error(e),process.exit(1)});
package/dist/loader.js CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env node
2
- import*as O from"fs";import*as g from"path";import*as l from"url";import{transformSync as R}from"esbuild";let h;function w(t){h=t}async function y(t,s,e){if(!(t.startsWith(".")||t.startsWith("/"))&&h){const{baseUrl:r,paths:a,tsconfigDir:u}=h;for(const i of Object.keys(a)){let o=null;if(i.endsWith("/*")){const c=i.slice(0,-2);if(t.startsWith(c)){const n=t.slice(c.length);(n===""||n.startsWith("/"))&&(o=n,o.startsWith("/")&&(o=o.slice(1)))}}else t===i&&(o="");if(o!==null)for(const c of a[i]){const n=c.replace(/\*/g,o),m=r??u;if(m){const U=l.pathToFileURL(g.join(m,"dummy.ts")).href;try{return{...await y(`./${n}`,{parentURL:U},e),shortCircuit:!0}}catch(f){if(f.code!=="ERR_MODULE_NOT_FOUND")throw f}}}}if(r){const i=l.pathToFileURL(g.join(r,"dummy.ts")).href;try{return{...await y(`./${t}`,{parentURL:i},e),shortCircuit:!0}}catch(o){if(o.code!=="ERR_MODULE_NOT_FOUND")throw o}}}try{return{...await e(t,s),shortCircuit:!0}}catch(r){if(r.code!=="ERR_MODULE_NOT_FOUND")throw r}try{return{...await e(t+".ts",s),shortCircuit:!0}}catch(r){if(r.code!=="ERR_MODULE_NOT_FOUND")throw r}try{return{...await e(t+".tsx",s),shortCircuit:!0}}catch(r){if(r.code!=="ERR_MODULE_NOT_FOUND")throw r}try{return{...await e(t+"/index.ts",s),shortCircuit:!0}}catch(r){if(r.code!=="ERR_MODULE_NOT_FOUND")throw r}try{return{...await e(t+"/index.tsx",s),shortCircuit:!0}}catch(r){throw r}}async function p(t,s,e){if(!t.endsWith(".ts")&&!t.endsWith(".tsx"))return e(t,s);const d=t.endsWith(".tsx")?"tsx":"ts",r=l.fileURLToPath(t),a=O.readFileSync(r,"utf8"),{code:u}=R(a,{loader:d,format:"esm",target:`node${process.versions.node}`,sourcemap:"inline",sourcefile:r,banner:`
2
+ import*as O from"fs";import*as g from"path";import*as f from"url";import{transformSync as R}from"esbuild";let h;function w(t){console.log("TS-ARC: Loader got init context:",t),h=t}async function y(t,s,o){if(!(t.startsWith(".")||t.startsWith("/"))&&h){const{baseUrl:r,paths:a,tsconfigDir:u}=h;for(const i of Object.keys(a)){let e=null;if(i.endsWith("/*")){const c=i.slice(0,-2);if(t.startsWith(c)){let n=t.slice(c.length);e=n.startsWith("/")?n.slice(1):n}}else t===i&&(e="");if(e!==null)for(const c of a[i]){const n=c.replace(/\*/g,e),m=r??u;if(m){const U=f.pathToFileURL(g.join(m,"dummy.ts")).href;try{return{...await y(`./${n}`,{parentURL:U},o),shortCircuit:!0}}catch(l){if(l.code!=="ERR_MODULE_NOT_FOUND")throw l}}}}if(r){const i=f.pathToFileURL(g.join(r,"dummy.ts")).href;try{return{...await y(`./${t}`,{parentURL:i},o),shortCircuit:!0}}catch(e){if(e.code!=="ERR_MODULE_NOT_FOUND")throw e}}}try{return{...await o(t,s),shortCircuit:!0}}catch(r){if(r.code!=="ERR_MODULE_NOT_FOUND")throw r}try{return{...await o(t+".ts",s),shortCircuit:!0}}catch(r){if(r.code!=="ERR_MODULE_NOT_FOUND")throw r}try{return{...await o(t+".tsx",s),shortCircuit:!0}}catch(r){if(r.code!=="ERR_MODULE_NOT_FOUND")throw r}try{return{...await o(t+"/index.ts",s),shortCircuit:!0}}catch(r){if(r.code!=="ERR_MODULE_NOT_FOUND")throw r}try{return{...await o(t+"/index.tsx",s),shortCircuit:!0}}catch(r){throw r}}async function p(t,s,o){if(!t.endsWith(".ts")&&!t.endsWith(".tsx"))return o(t,s);const d=t.endsWith(".tsx")?"tsx":"ts",r=f.fileURLToPath(t),a=O.readFileSync(r,"utf8"),{code:u}=R(a,{loader:d,format:"esm",target:`node${process.versions.node}`,sourcemap:"inline",sourcefile:r,banner:`
3
3
  import { createRequire } from 'module';
4
4
  const require = createRequire(import.meta.url);`});return{format:"module",source:u,shortCircuit:!0}}export{w as initialize,p as load,y as resolve};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-arc",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "type": "module",
5
5
  "description": "A simple typescript runtime.",
6
6
  "main": "dist/bin.js",