ts-arc 1.1.8 → 1.1.9

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.
Files changed (2) hide show
  1. package/dist/loader.js +3 -2
  2. package/package.json +1 -1
package/dist/loader.js CHANGED
@@ -1,3 +1,4 @@
1
- import*as _ from"fs";import*as l from"path";import*as h from"url";import{transformSync as D}from"esbuild";let m;function b(r){m=r}async function y(r,i,e){if(!(r.startsWith(".")||r.startsWith("/"))){if(m){const{baseUrl:t,paths:o,tsconfigDir:d}=m,O=t?l.resolve(d??"",t):d;for(const s of Object.keys(o)){let a=null,c=s.endsWith("/*");const n=c?s.slice(0,-2):s;if(c?r.startsWith(n+"/")&&(a=r.slice(n.length+1)):r===s&&(a=""),a!==null)for(const p of o[s]){const U=`./${c?p.replace(/\*/g,a):p}`,R=O??process.cwd(),w=h.pathToFileURL(l.join(R,"dummy.ts")).href;try{return{...await y(U,{parentURL:w},e),shortCircuit:!0}}catch(u){if(console.error(`TS-ARC: Failed to resolve mapped specifier "${U}" from base "${R}":`,u.message),u.code!=="ERR_MODULE_NOT_FOUND")throw u}}}if(t){const s=l.resolve(d??"",t),a=`./${r}`,c=h.pathToFileURL(l.join(s,"dummy.ts")).href;try{return{...await y(a,{parentURL:c},e),shortCircuit:!0}}catch(n){if(console.error(`TS-ARC: Failed to resolve specifier "${r}" from baseUrl "${s}":`,n.message),n.code!=="ERR_MODULE_NOT_FOUND")throw n}}}try{return{...await e(r,i),shortCircuit:!0}}catch(t){throw t.code==="ERR_MODULE_NOT_FOUND",t}}try{return{...await e(r,i),shortCircuit:!0}}catch(t){if(t.code!=="ERR_MODULE_NOT_FOUND")throw t}if(l.extname(r)!=="")throw new Error(`Module not found: ${r}`);for(const t of[".ts",".tsx"])try{return{...await e(r+t,i),shortCircuit:!0}}catch(o){if(o.code!=="ERR_MODULE_NOT_FOUND")throw o}for(const t of["/index.ts","/index.tsx"])try{return{...await e(r+t,i),shortCircuit:!0}}catch(o){if(o.code!=="ERR_MODULE_NOT_FOUND")throw o}throw new Error(`Module not found: ${r}`)}async function E(r,i,e){if(!r.endsWith(".ts")&&!r.endsWith(".tsx"))return e(r,i);const g=r.endsWith(".tsx")?"tsx":"ts",f=h.fileURLToPath(r),t=_.readFileSync(f,"utf8"),{code:o}=D(t,{loader:g,format:"esm",target:`node${process.versions.node}`,sourcemap:"inline",sourcefile:f,banner:`
1
+ #!/usr/bin/env node
2
+ import*as g from"fs";import*as i from"path";import*as d from"url";import{transformSync as y}from"esbuild";let p={baseUrl:null,paths:{},tsconfigDir:null};function x(t){p=t}function L(){const{baseUrl:t,tsconfigDir:e}=p;return t?i.resolve(e??process.cwd(),t):null}async function h(t,e){const s=i.resolve(t,e),c=[s,s+".ts",s+".tsx",i.join(s,"index.ts"),i.join(s,"index.tsx")];for(const a of c)try{if(g.existsSync(a)&&g.statSync(a).isFile())return{url:d.pathToFileURL(a).href}}catch{}throw Object.assign(new Error(`Cannot find module '${e}'`),{code:"ERR_MODULE_NOT_FOUND"})}async function P(t,e,s){let c=process.cwd();if(e.parentURL&&(c=i.dirname(d.fileURLToPath(e.parentURL))),t.startsWith("file://")){const o=d.fileURLToPath(t),n=i.dirname(o),u=i.basename(o),r=(i.extname(u),u);return{...await h(n,r),shortCircuit:!0}}if(t.startsWith(".")||t.startsWith("/"))return{...await h(c,t),shortCircuit:!0};{const{paths:o}=p,n=L();for(const r of Object.keys(o)){let l=null;const f=r.endsWith("/*"),v=f?r.slice(0,-2):r;if(f&&t.startsWith(v+"/")?l=t.slice(v.length+1):!f&&t===r&&(l=""),l!==null)for(const R of o[r]){const U=f?R.replace(/\*/g,l):R;if(n)try{return{...await h(n,U),shortCircuit:!0}}catch(m){if(m.code!=="ERR_MODULE_NOT_FOUND")throw m}}}if(n)try{return{...await h(n,t),shortCircuit:!0}}catch(r){if(r.code!=="ERR_MODULE_NOT_FOUND")throw r}return{...await s(t,e),shortCircuit:!0}}}async function w(t,e,s){if(!t.endsWith(".ts")&&!t.endsWith(".tsx"))return s(t,e);const c=t.endsWith(".tsx")?"tsx":"ts",a=d.fileURLToPath(t),o=g.readFileSync(a,"utf8"),{code:n}=y(o,{loader:c,format:"esm",target:`node${process.versions.node}`,sourcemap:"inline",sourcefile:a,banner:`
2
3
  import { createRequire } from 'module';
3
- const require = createRequire(import.meta.url);`});return{format:"module",source:o,shortCircuit:!0}}export{b as initialize,E as load,y as resolve};
4
+ const require = createRequire(import.meta.url);`});return{format:"module",source:n,shortCircuit:!0}}export{x as initialize,w as load,P as resolve};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-arc",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
4
4
  "type": "module",
5
5
  "description": "A simple typescript runtime.",
6
6
  "main": "dist/bin.js",