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 +8 -0
- package/dist/bin.js +2 -2
- package/dist/loader.js +1 -1
- package/package.json +1 -1
package/README.md
ADDED
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),
|
|
3
|
-
`;)
|
|
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
|
|
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};
|