ts-arc 1.0.3 → 1.0.4

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 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)});
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)});
package/dist/loader.js CHANGED
@@ -1,2 +1,2 @@
1
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};
2
+ import*as U from"fs";import*as d from"path";import*as l from"url";import{transformSync as _}from"esbuild";async function w(t,s,o){if(!(t.startsWith(".")||t.startsWith("/"))){const r=global.__tsArcConfig;if(r){const{baseUrl:n,paths:a,tsconfigDir:m}=r;for(const i of Object.keys(a)){let e=null;if(i.endsWith("/*")){const c=i.slice(0,-2);t.startsWith(c)&&(e=t.slice(c.length))}else t===i&&(e="");if(e!==null)for(const c of a[i]){const g=c.replace(/\*/g,e),h=n??m;if(h){const y=l.pathToFileURL(d.join(h,"dummy.ts")).href;try{return{...await o(`./${g}`,{parentURL:y}),shortCircuit:!0}}catch(f){if(f.code!=="ERR_MODULE_NOT_FOUND")throw f}}}}if(n){const i=l.pathToFileURL(d.join(n,"dummy.ts")).href;try{return{...await o(`./${t}`,{parentURL:i}),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 R(t,s,o){let u="ts";if(t.endsWith(".tsx"))u="tsx";else return o(t,s);const r=l.fileURLToPath(t),n=U.readFileSync(r,"utf8"),{code:a}=_(n,{loader:u,format:"esm",target:`node${process.versions.node}`,sourcemap:"inline",sourcefile:r});return{format:"module",source:a,shortCircuit:!0}}export{R as load,w as resolve};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-arc",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "type": "module",
5
5
  "description": "A simple typescript runtime.",
6
6
  "main": "dist/bin.js",