ts-arc 1.1.2 → 1.1.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 +2 -2
- package/dist/loader.js +2 -2
- package/package.json +1 -1
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
|
|
2
|
+
import*as O from"fs";import*as y from"path";import*as f from"url";import{transformSync as w}from"esbuild";let h;function v(t){h=t}async function U(t,s,o){if(!(t.startsWith(".")||t.startsWith("/"))&&h){const{baseUrl:r,paths:c,tsconfigDir:l}=h;for(const n of Object.keys(c)){let i=null;if(n.endsWith("/*")){const e=n.slice(0,-2);if(t.startsWith(e)){let a=t.slice(e.length);i=a.startsWith("/")?a.slice(1):a}}else t===n&&(i="");if(i!==null)for(const e of c[n]){const a=e.replace(/\*/g,i),m=r??l,g=`./${a}`;if(m){const R=f.pathToFileURL(y.join(m,"dummy.ts")).href;try{return{...await U(g,{parentURL:R},o),shortCircuit:!0}}catch(u){if(console.error("TS-ARC: Could not find a module with a resolved filePath of:",g),u.code!=="ERR_MODULE_NOT_FOUND")throw u}}}}if(r){const n=f.pathToFileURL(y.join(r,"dummy.ts")).href,i=`./${t}`;try{return{...await U(i,{parentURL:n},o),shortCircuit:!0}}catch(e){if(e.code!=="ERR_MODULE_NOT_FOUND")throw console.error("TS-ARC: Could not find a module with a resolved filePath of:",i),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 C(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),c=O.readFileSync(r,"utf8"),{code:l}=w(c,{loader:d,format:"esm",target:`node${process.versions.node}`,sourcemap:"inline",sourcefile:r,banner:`
|
|
3
3
|
import { createRequire } from 'module';
|
|
4
|
-
const require = createRequire(import.meta.url);`});return{format:"module",source:
|
|
4
|
+
const require = createRequire(import.meta.url);`});return{format:"module",source:l,shortCircuit:!0}}export{v as initialize,C as load,U as resolve};
|