ts-arc 1.0.6 → 1.1.1

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,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
- import{register as b}from"node:module";import*as o from"node:path";import*as l from"node:url";import*as p from"node:fs";import{createRequire as j}from"node:module";const h=j(import.meta.url),C=l.fileURLToPath(import.meta.url),d=o.dirname(C),x=o.join(d,"loader.js");b(x,l.pathToFileURL(d).href);const a=process.argv[2];a||(console.error("Usage: node bin.js <script.ts> [args...]"),process.exit(1));const u=o.resolve(a),O=l.pathToFileURL(u).href;process.argv=[process.argv[0],a,...process.argv.slice(3)];function _(t){let e="",n=!1,s=0;for(;s<t.length;){const r=t[s];if(n){e+=r,r==='"'&&t[s-1]!=="\\"&&(n=!1),s++;continue}if(r==='"'){n=!0,e+=r,s++;continue}if(r==="/"&&t[s+1]==="/"){for(s+=2;s<t.length&&t[s]!==`
3
- `;)s++;continue}if(r==="/"&&t[s+1]==="*"){for(s+=2;s<t.length&&!(t[s-1]==="*"&&t[s]==="/");)s++;s<t.length&&s++;continue}e+=r,s++}return e}function v(t){const e=p.readFileSync(t,"utf8"),n=_(e),s=JSON.parse(n);if(!s.extends)return s;const r=s.extends,U=o.dirname(t);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=v(i),m={...g,...s};return m.compilerOptions={...g.compilerOptions||{},...s.compilerOptions||{}},m}function D(t){let e=t;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=D(o.dirname(u));let c={baseUrl:null,paths:{},tsconfigDir:null};if(f){const e=v(f).compilerOptions||{},n=o.dirname(f),s=e.baseUrl;c.baseUrl=s?o.resolve(n,s):null,c.paths=e.paths||{},c.tsconfigDir=n}global.__tsArcConfig=c,import(O).catch(t=>{console.error(t),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),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)});
package/dist/loader.js CHANGED
@@ -1,2 +1,4 @@
1
1
  #!/usr/bin/env node
2
- import*as _ from"fs";import*as d from"path";import*as f from"url";import{transformSync as O}from"esbuild";async function m(t,e,o){if(!(t.startsWith(".")||t.startsWith("/"))){const r=global.__tsArcConfig;if(r){const{baseUrl:n,paths:a,tsconfigDir:g}=r;for(const i of Object.keys(a)){let s=null;if(i.endsWith("/*")){const c=i.slice(0,-2);t.startsWith(c)&&(s=t.slice(c.length))}else t===i&&(s="");if(s!==null)for(const c of a[i]){const y=c.replace(/\*/g,s),l=n??g;if(l){const U=f.pathToFileURL(d.join(l,"dummy.ts")).href;try{return{...await m(`./${y}`,{parentURL:U},o),shortCircuit:!0}}catch(u){if(u.code!=="ERR_MODULE_NOT_FOUND")throw u}}}}if(n){const i=f.pathToFileURL(d.join(n,"dummy.ts")).href;try{return{...await m(`./${t}`,{parentURL:i},o),shortCircuit:!0}}catch(s){if(s.code!=="ERR_MODULE_NOT_FOUND")throw s}}}}try{return{...await o(t,e),shortCircuit:!0}}catch(r){if(r.code!=="ERR_MODULE_NOT_FOUND")throw r}try{return{...await o(t+".ts",e),shortCircuit:!0}}catch(r){if(r.code!=="ERR_MODULE_NOT_FOUND")throw r}try{return{...await o(t+".tsx",e),shortCircuit:!0}}catch(r){if(r.code!=="ERR_MODULE_NOT_FOUND")throw r}try{return{...await o(t+"/index.ts",e),shortCircuit:!0}}catch(r){if(r.code!=="ERR_MODULE_NOT_FOUND")throw r}try{return{...await o(t+"/index.tsx",e),shortCircuit:!0}}catch(r){throw r}}async function R(t,e,o){if(!t.endsWith(".ts")&&!t.endsWith(".tsx"))return o(t,e);const h=t.endsWith(".tsx")?"tsx":"ts",r=f.fileURLToPath(t),n=_.readFileSync(r,"utf8"),{code:a}=O(n,{loader:h,format:"esm",target:`node${process.versions.node}`,sourcemap:"inline",sourcefile:r});return{format:"module",source:a,shortCircuit:!0}}export{R as load,m as resolve};
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:`
3
+ import { createRequire } from 'module';
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.0.6",
3
+ "version": "1.1.1",
4
4
  "type": "module",
5
5
  "description": "A simple typescript runtime.",
6
6
  "main": "dist/bin.js",