@tsmodule/tsmodule 25.0.0 → 27.0.2

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 CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  ---
7
7
 
8
- ### Quickly create TypeScript projects with **`tsmodule create`**
8
+ #### Quickly create TypeScript projects with **`tsmodule create`**
9
9
 
10
10
  Supports React via TSX/JSX. Ready with zero config:
11
11
 
@@ -13,16 +13,16 @@ Supports React via TSX/JSX. Ready with zero config:
13
13
  - ESLint + TypeScript configs
14
14
  - CI/CD with GitHub Actions
15
15
 
16
- ### Build TypeScript to pure ESM with **`tsmodule build`**
16
+ #### Build TypeScript to pure ESM with **`tsmodule build`**
17
17
 
18
18
  - No more polyfilling to CJS or older featuresets
19
19
  - Use latest syntax in source, leave backporting to downstream consumers
20
20
 
21
- ### Dev mode with **`tsmodule dev`**
21
+ #### Dev mode with **`tsmodule dev`**
22
22
 
23
23
  - Build and watch for changes
24
24
 
25
- ### Run TypeScript directly with **`tsmodule <file>`**
25
+ #### Run TypeScript directly with **`tsmodule <file>`**
26
26
 
27
27
  - Uses Node module loader to resolve TS at runtime
28
28
  - Executable TypeScript files with `#!/usr/bin/env tsmodule`
@@ -1,6 +1,4 @@
1
- import{dirname as E,extname as I,isAbsolute as V,resolve as C,resolve as B}from"path";import{build as J}from"esbuild";import{existsSync as P,mkdirSync as z,readFileSync as O,rmSync as R,writeFileSync as F}from"fs";import l from"chalk";import{env as $}from"process";import X from"fast-glob";import p from"ora";import{createDebugLogger as K,log as d}from"create-debug-logger";import{isJsOrTs as v,isTs as u,isTsxOrJsx as m}from"../../utils/index.js";import{createShell as U}from"await-shell";import{emitTsDeclarations as q}from"./lib/emitTsDeclarations.js";import{normalizeImportSpecifiers as H}from"../normalize/index.js";import{getPackageJsonFile as Q}from"../../utils/pkgJson.js";import{getWorkingDirs as W}from"../../utils/cwd.js";import{readStdin as Y}from"../../utils/stdin.js";const L=t=>{const s=` ${t} `;d(l.bgBlue(l.bold(l.white(s))))},Z=()=>{let t;if(P("dist/package.json")?t=JSON.parse(O("dist/package.json","utf-8")):t={},t?.module==="module")return!0;t.type="module",F("dist/package.json",JSON.stringify(t,null,2))},_=(t,s,f)=>{const{srcDir:i,outDir:g}=W();return s=B(s),{stdin:{contents:t,sourcefile:s,resolveDir:E(s),loader:f},outdir:void 0,outfile:s.replace(v,".js").replace(i,g)}},ee=async({files:t="src/**/*",styles:s="src/styles/components/index.css",bundle:f=!1,dev:i=!1,runtimeOnly:g=!1,stdin:n="",stdinFile:y=""})=>{$.NODE_ENV=i?"development":"production";const o=K(ee),G=U(),{cwd:S,srcDir:w,outDir:a}=W(),b=await Q(),k=JSON.parse(b),h={absWorkingDir:S,bundle:f,treeShaking:f,outbase:"src",outdir:"dist",assetNames:"[name].js",logLevel:i?"warning":"error",charset:"utf8",format:"esm",target:"esnext",platform:k?.platform??"node",minify:!i,define:{PACKAGE_JSON:b,"process.env.NODE_ENV":i?JSON.stringify("development"):JSON.stringify("production")}};let j="";if(n){o.log("Building file from stdin",{stdin:n,stdinFile:y}),y||(d(l.red("ERROR: --stdin-file must be specified when using stdin.")),process.exit(1)),typeof n=="string"&&n.length?j=n:j=await Y();const e=_(j,y,"tsx");await J({...h,...e});return}o.log("Building",{files:t,dev:i,runtimeOnly:g}),L(`${l.bold("TS Module")} [${$.NODE_ENV}]`);const r=X.sync(t,{cwd:S}).filter(e=>I(e)!==".d.ts").map(e=>B(e));if(V(t)){r.length||r.push(t);const e=t.replace(w,a).replace(u,".js").replace(m,".js");o.log("Cleaning emitted file:",{outfile:e}),R(e,{force:!0})}else o.log("Cleaning old output:",{outDir:a}),R(a,{force:!0,recursive:!0});console.log();const x=r.filter(e=>u.test(e)).filter(e=>!m.test(e));o.log("Compiling TS files:",{tsFiles:x}),await J({...h,entryPoints:x.filter(e=>!e.endsWith(".d.ts"))}),p("Built TS files.").succeed();const D=r.filter(e=>m.test(e));o.log("Compiling TSX files:",{tsxFiles:D});const M=D.filter(e=>!e.endsWith(".d.ts"));await Promise.all(M.map(async e=>{const c=`
2
- import React from "react";
1
+ import{dirname as P,extname as X,isAbsolute as K,resolve as R,resolve as F}from"path";import{build as x,transform as U}from"esbuild";import{existsSync as v,mkdirSync as q,readFileSync as h,rmSync as _,writeFileSync as $}from"fs";import c from"chalk";import{env as L}from"process";import H from"fast-glob";import p from"ora";import{createDebugLogger as Q,log as S}from"create-debug-logger";import{isJsOrTs as M,isTs as O,isTsxOrJsx as f}from"../../utils/resolve.js";import{createShell as Y}from"await-shell";import{emitTsDeclarations as Z}from"./lib/emitTsDeclarations.js";import{normalizeImportSpecifiers as ee}from"../normalize/index.js";import{getPackageJsonFile as te}from"../../utils/pkgJson.js";import{getWorkingDirs as A}from"../../utils/cwd.js";import{readStdin as oe}from"../../utils/stdin.js";const se=`import React from "react";
3
2
  import ReactDOM from "react-dom";
4
- ${O(e,"utf-8")}
5
- `,T=_(c,e,"tsx");await J({...h,...T,jsxFactory:"React.createElement"})})),p("Built TSX files.").succeed();const N=r.filter(e=>!v.test(e));if(o.log("Copying non-JS/TS files.",{allFiles:r,nonJsTsFiles:N}),await Promise.all(N.map(async e=>{const c=C(S,e).replace(w,a).replace(u,".js").replace(m,".js");o.log("Copying non-source file:",{file:e,outfile:c}),z(E(c),{recursive:!0}),F(c,O(e),{encoding:"binary",flag:"w"})})),!process.env.NO_REWRITES){const e=t.replace(w,a).replace(/^(\.\/)?src\//,"dist/").replace(u,".js").replace(m,".js");await H(e.endsWith(".js")?e:`${e}.js`),p("Normalized import specifiers.").succeed()}if(Z()&&p('Forced "type": "module" in output.').succeed(),console.log(),!(i||g)){if(P(C(s))){o.log("Building styles for production.");const{style:e="./dist/styles.css"}=k,A=["npx tailwindcss",i?"":"-m","--postcss postcss.config.js",`-i ${s}`,"-o",e];await G.run(A.join(" "))}else o.log("Styles not found.",{styles:s});L("Running post-build setup."),d(`Generating type declarations.
6
- This might take a moment.`),q(r),p(`Generated delcarations for ${r.length} files.`).succeed(),d(l.green("Build complete."))}};export{L as bannerLog,ee as build};
3
+ `,G=t=>{const o=` ${t} `;S(c.bgBlue(c.bold(c.white(o))))},ie=()=>{let t;if(v("dist/package.json")?t=JSON.parse(h("dist/package.json","utf-8")):t={},t?.module==="module")return!0;t.type="module",$("dist/package.json",JSON.stringify(t,null,2))},I=(t,o,d)=>{const{srcDir:i,outDir:u}=A();return o=F(o),{stdin:{contents:t,sourcefile:o,resolveDir:P(o),loader:d},outdir:void 0,outfile:o.replace(M,".js").replace(i,u)}},re=async({files:t="src/**/*",styles:o="src/styles/components/index.css",bundle:d=!1,dev:i=!1,runtimeOnly:u=!1,noWrite:l=!1,stdin:a="",stdinFile:g=""})=>{L.NODE_ENV=i?"development":"production";const s=Q(re),V=Y(),{cwd:w,srcDir:b,outDir:m}=A(),j=await te(),C=JSON.parse(j),J={treeShaking:d,logLevel:i?"warning":"error",charset:"utf8",format:"esm",target:"esnext",minify:!i,define:{PACKAGE_JSON:j,"process.env.NODE_ENV":i?JSON.stringify("development"):JSON.stringify("production")}},T={...J,bundle:d,absWorkingDir:w,outbase:"src",outdir:"dist",assetNames:"[name].js",format:"esm",target:"esnext",platform:C?.platform??"node",write:!l};let y="";if(a){s.log("Building file from stdin",{stdin:a,stdinFile:g,noWrite:l}),!l&&!g&&(S(c.red("ERROR: --stdin-file must be specified when using stdin in write mode.")),process.exit(1)),typeof a=="string"&&a.length?y=a:y=await oe();const e={...J,sourcefile:g,loader:"tsx",banner:void 0,footer:void 0};if(l)return(await U(y,e)).code;{const r=I(y,g,"tsx");return await x({...T,...r})}}s.log("Building",{files:t,dev:i,runtimeOnly:u}),G(`${c.bold("TS Module")} [${L.NODE_ENV}]`);const n=H.sync(t,{cwd:w}).filter(e=>X(e)!==".d.ts").map(e=>F(e));if(K(t)){n.length||n.push(t);const e=t.replace(b,m).replace(O,".js").replace(f,".js");s.log("Cleaning emitted file:",{outfile:e}),_(e,{force:!0})}else s.log("Cleaning old output:",{outDir:m}),_(m,{force:!0,recursive:!0});console.log();const k=n.filter(e=>O.test(e)).filter(e=>!f.test(e));s.log("Compiling TS files:",{tsFiles:k}),await x({...T,entryPoints:k.filter(e=>!e.endsWith(".d.ts"))}),p("Built TS files.").succeed();const D=n.filter(e=>f.test(e));s.log("Compiling TSX files:",{tsxFiles:D});const W=D.filter(e=>!e.endsWith(".d.ts"));await Promise.all(W.map(async e=>{const r=h(e,"utf-8"),E=se+r,B=I(E,e,"tsx");await x({...T,...B,jsxFactory:"React.createElement"})})),p("Built TSX files.").succeed();const N=n.filter(e=>!M.test(e));if(s.log("Copying non-JS/TS files.",{allFiles:n,nonJsTsFiles:N}),await Promise.all(N.map(async e=>{const r=R(w,e).replace(b,m).replace(O,".js").replace(f,".js");s.log("Copying non-source file:",{file:e,outfile:r}),q(P(r),{recursive:!0}),$(r,h(e),{encoding:"binary",flag:"w"})})),!process.env.NO_REWRITES){const e=t.replace(b,m).replace(/^(\.\/)?src\//,"dist/").replace(O,".js").replace(f,".js");await ee(e.endsWith(".js")?e:`${e}.js`),p("Normalized import specifiers.").succeed()}if(ie()&&p('Forced "type": "module" in output.').succeed(),console.log(),!(i||u)){if(v(R(o))){s.log("Building styles for production.");const{style:e="./dist/styles.css"}=C,z=["npx tailwindcss",i?"":"-m","--postcss postcss.config.js",`-i ${o}`,"-o",e];await V.run(z.join(" "))}else s.log("Styles not found.",{styles:o});G("Running post-build setup."),S(`Generating type declarations.
4
+ This might take a moment.`),Z(n),p(`Generated delcarations for ${n.length} files.`).succeed(),S(c.green("Build complete."))}};export{G as bannerLog,re as build};
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- var r="@tsmodule/tsmodule",s="node",d="module",l="25.0.0",m="tsmodule/tsmodule",a="TypeScript Module loader and compiler",c="MIT",p={tsmodule:"dist/index.js"},u={".":"./dist/loader/index.js","./*":"./dist/*/index.js","./package.json":"./package.json"},f="dist/types/index.d.ts",b=[{name:"C. Lewis",email:"ctj.lewis@icloud.com",url:"https://ctjlewis.com"}],g=["dist/","templates/"],h={node:">=14"},v={bootstrap:"node bootstrap.js",bootload:"node --no-warnings --loader ./dist/loader/index.js src/index.ts build -r",prebuild:"yarn bootstrap && yarn bootload && yarn link -f",build:"tsmodule build",dev:"tsmodule dev",lint:"eslint --fix src",prepare:"yarn build -r",prepublishOnly:"yarn build && yarn test",pretest:"yarn build -r",test:"ava --no-worker-threads",retest:"SKIP_TEST_SETUP=1 yarn test"},y={"@types/glob":"^7.2.0","@types/node":"^17.0.21","@typescript-eslint/eslint-plugin":"^5.14.0","@typescript-eslint/parser":"^5.14.0",ava:"^4.1.0","await-shell":"^31.0.0",chalk:"^5.0.1",commander:"^9.0.0","create-debug-logger":"^3.0.0",esbuild:"^0.14.25",eslint:"^8.10.0","fast-glob":"^3.2.10","fs-extra":"^10.0.1",glob:"^7.2.0","node-watch":"^0.7.3",ora:"^6.1.0",path:"^0.12.7",typescript:"^4.6.2"},S=["esm","loader","typescript","loader hook","require hook","experimental-loader"],w={timeout:"10 minutes",files:["test/**/*.test.ts"],extensions:{ts:"module"},nodeArguments:["--no-warnings","--loader=@tsmodule/tsmodule"]},T={"@types/fs-extra":"^9.0.13"},t={name:r,platform:s,type:d,version:l,repository:m,description:a,license:c,bin:p,exports:u,types:f,contributors:b,files:g,engines:h,scripts:v,dependencies:y,keywords:S,ava:w,devDependencies:T};import o from"chalk";import{Command as B}from"commander";import{build as R}from"./commands/build/index.js";import{create as x}from"./commands/create/index.js";import{dev as C}from"./commands/dev/index.js";import{execute as j}from"./commands/execute/index.js";import{normalizeImportSpecifiers as A}from"./commands/normalize/index.js";const{version:E}=t,i=new B;i.name(o.white(o.bold("tsmodule"))).usage(o.white(o.bold("<file | command> [options]"))).description(o.blueBright(`A tool for building TypeScript modules.
2
+ var r="@tsmodule/tsmodule",s="node",d="module",a="27.0.0",l="tsmodule/tsmodule",m="TypeScript Module loader and compiler",c="MIT",p={tsmodule:"dist/index.js"},u={".":"./dist/loader/index.js","./*":"./dist/*/index.js","./package.json":"./package.json"},f="dist/types/index.d.ts",b=[{name:"C. Lewis",email:"ctj.lewis@icloud.com",url:"https://ctjlewis.com"}],g=["dist/","templates/"],h={node:">=14"},y={bootstrap:"node bootstrap.js",bootload:"node --no-warnings --loader ./dist/loader/index.js src/index.ts build -r",prebuild:"yarn bootstrap && yarn bootload && yarn link -f",build:"tsmodule build",dev:"tsmodule dev",lint:"eslint --fix src",prepare:"yarn build -r",prepublishOnly:"yarn build && yarn test",pretest:"yarn build -r",test:"ava --no-worker-threads",retest:"SKIP_TEST_SETUP=1 yarn test"},v={"@types/glob":"^7.2.0","@types/node":"^17.0.21","@typescript-eslint/eslint-plugin":"^5.14.0","@typescript-eslint/parser":"^5.14.0",ava:"^4.1.0","await-shell":"^31.0.0",chalk:"^5.0.1",commander:"^9.0.0","create-debug-logger":"^3.0.0",esbuild:"^0.14.25",eslint:"^8.10.0","fast-glob":"^3.2.10","fs-extra":"^10.0.1",glob:"^7.2.0","node-watch":"^0.7.3",ora:"^6.1.0",path:"^0.12.7",typescript:"^4.6.2"},w=["esm","loader","typescript","loader hook","require hook","experimental-loader"],S={timeout:"10 minutes",files:["test/**/*.test.ts"],extensions:{ts:"module"},nodeArguments:["--no-warnings","--loader=@tsmodule/tsmodule"]},T={"@types/fs-extra":"^9.0.13"},n={name:r,platform:s,type:d,version:a,repository:l,description:m,license:c,bin:p,exports:u,types:f,contributors:b,files:g,engines:h,scripts:y,dependencies:v,keywords:w,ava:S,devDependencies:T};import o from"chalk";import{Command as B}from"commander";import{build as R}from"./commands/build/index.js";import{create as x}from"./commands/create/index.js";import{dev as C}from"./commands/dev/index.js";import{execute as j}from"./commands/execute/index.js";import{normalizeImportSpecifiers as k}from"./commands/normalize/index.js";const{version:A}=n,i=new B;i.name(o.white(o.bold("tsmodule"))).usage(o.white(o.bold("<file | command> [options]"))).description(o.blueBright(`A tool for building TypeScript modules.
3
3
 
4
4
  Run TS directly: ${o.bold("tsmodule src/index.ts")}
5
- Use a command: ${o.bold("tsmodule build")}`)).version(String(E)),i.command("dev").description("Build and watch for changes.").action(C),i.command("build").option("--files <files>","Files to build","src/**/*").option("--styles <styles>","The styles to build","src/styles/components/index.css").option("-b, --bundle","Bundle dependencies",!1).option("-d, --dev","Build development runtime",!1).option("-r, --runtime-only","Do not emit type declarations, only build JS runtime",!1).option("--stdin [source]","Read from a string or stdin.","").option("--stdin-file [file]","File path to mock for stdin.","").description("Builds TS files to output in dist/.").action(R),i.command("create <name>").option("--react","Create React component library with Next.js").description("Create a new project.").action(x),i.command("normalize [files]").description(`Rewrites import specifiers in files to ESM-compliant paths.
6
- (default: dist/**/*.js)`).action(async({files:n})=>{await A(n)}),i.command("run",{isDefault:!0}).argument("<file>","The file to run.").option("--d, --dev","Enable development mode").description("Run the given TS program, analogous to `node <file>`.").action(j),i.parse(process.argv);
5
+ Use a command: ${o.bold("tsmodule build")}`)).version(String(A)),i.command("dev").description("Build and watch for changes.").action(C),i.command("build").option("--files <files>","Files to build","src/**/*").option("--styles <styles>","The styles to build","src/styles/components/index.css").option("-b, --bundle","Bundle dependencies",!1).option("-d, --dev","Build development runtime",!1).option("-r, --runtime-only","Do not emit type declarations, only build JS runtime",!1).option("--stdin [source]","Read from a string or stdin.","").option("--stdin-file [file]","File path to mock for stdin.","").option("--no-write","Do not write to disk",!1).description("Builds TS files to output in dist/.").action(async t=>{await R(t)}),i.command("create <name>").option("--react","Create React component library with Next.js").description("Create a new project.").action(x),i.command("normalize [files]").description(`Rewrites import specifiers in files to ESM-compliant paths.
6
+ (default: dist/**/*.js)`).action(async({files:t})=>{await k(t)}),i.command("run",{isDefault:!0}).argument("<file>","The file to run.").option("--d, --dev","Enable development mode").description("Run the given TS program, analogous to `node <file>`.").action(j),i.parse(process.argv);
@@ -1 +1 @@
1
- import{extname as m,isAbsolute as U,join as E,normalize as S,resolve as w}from"path";import{fileURLToPath as H,pathToFileURL as v,URL as L}from"url";import{createDebugLogger as d}from"create-debug-logger";import{readFileSync as G}from"fs";import{transform as h}from"esbuild";import{posix as M}from"path";import{win32 as T}from"path";import{checkExtensions as k,checkTsExtensions as D,fileExists as b,isJs as y,isTs as N,MODULE_LOADERS as R}from"../utils/index.js";import{getPackageJsonFile as P}from"../utils/pkgJson.js";const F=await P(),A=async(o,r,t)=>{const{parentURL:s}=r,e=d(A);if(e.log("Resolving specifier:",{importedFromURL:s,specifier:o}),!o.startsWith(".")&&!U(o))return e.log("Using defaultResolve for named module:",{specifier:o}),t(o,r,t);const{href:l}=v(process.cwd()),{href:i}=new L(s||l);e.log("Finding import URL for",{specifier:o,baseURL:i});let n=o;o.startsWith("file://")||(U(o)?(e.log("Setting import URL to absolute specifier."),n=v(w(S(o))).href):(e.log("Setting import URL relative to baseURL."),n=new L(o,i).href),e.log("Resolved import URL:",{importedFileURL:n,importedFromURL:s}));const f=m(s??"").toLowerCase(),c=m(n).toLowerCase();if(e.log("Rewriting file extension:",{parentExtension:f,specifierExtension:c}),c){const a=n.substring(0,n.lastIndexOf(c));if(e.log("Re-resolving specifier:",{unresolvedSpecifier:a}),y.test(c)&&N.test(f)){const p=D(a);if(p)return e.log("Found JS import in TS:",{unresolvedSpecifier:a,resolvedTsSourceFile:p}),{url:p}}return b(a)?(e.log("Found file at unresolved specifier:",{unresolvedSpecifier:a}),{url:a}):t(o,r,t)}e.log("Resolving incomplete URL import to file:",{specifier:o});const u=k(n);if(u)return e.log("Resolved import URL to file:",{resolvedFile:u}),{url:u};const x=new L(E(n,"index")).href,g=k(x);return g?(e.log("Resolved import URL to index file:",{resolvedIndexFile:g}),{url:g}):t(o,r,t)},J=async(o,r,t)=>{const s=d(J);if(s.log("Loading source file:",{url:o}),!o.includes(T.sep)&&!o.includes(M.sep))return s.log("Using defaultLoad for named module:",{url:o}),t(o,r,t);const e=m(o),l=R[e];if(!l)return s.log("No loader found, using defaultLoad:",{url:o}),t(o,r,t);const i=H(o),n=G(i,"utf8"),f=await h(n.toString(),{...l,sourcefile:i,format:"esm",define:{PACKAGE_JSON:F}});return{format:"module",source:f.code}},O=async(o,r,t)=>{const s=d(O);s.log("Getting format for source file:",{url:o});const e=m(o);return R[e]?{format:"module"}:(s.log("No loader found, using default format:",{url:o}),t(o,r,t))},B=async(o,r,t)=>{const s=d(B);s.log("Transforming source from context:",{context:r});const{url:e}=r,l=m(e),i=R[l];return i?{source:(await h(o.toString(),{...i,logLevel:"info",charset:"utf8",target:"esnext",sourcefile:r.url,format:r.format==="module"?"esm":"cjs",define:{PACKAGE_JSON:F}})).code}:(s.log("No loader found, using default transformer:",{url:e}),t(o,r,t))};export{O as getFormat,J as load,A as resolve,B as transformSource};
1
+ import{extname as m,isAbsolute as U,join as E,normalize as S,resolve as w}from"path";import{fileURLToPath as H,pathToFileURL as v,URL as L}from"url";import{createDebugLogger as d}from"create-debug-logger";import{readFileSync as G}from"fs";import{transform as h}from"esbuild";import{posix as M}from"path";import{win32 as T}from"path";import{checkExtensions as k,checkTsExtensions as D,fileExists as b,isJs as y,isTs as N,MODULE_LOADERS as R}from"../utils/resolve.js";import{getPackageJsonFile as P}from"../utils/pkgJson.js";const F=await P(),A=async(o,r,t)=>{const{parentURL:s}=r,e=d(A);if(e.log("Resolving specifier:",{importedFromURL:s,specifier:o}),!o.startsWith(".")&&!U(o))return e.log("Using defaultResolve for named module:",{specifier:o}),t(o,r,t);const{href:l}=v(process.cwd()),{href:i}=new L(s||l);e.log("Finding import URL for",{specifier:o,baseURL:i});let n=o;o.startsWith("file://")||(U(o)?(e.log("Setting import URL to absolute specifier."),n=v(w(S(o))).href):(e.log("Setting import URL relative to baseURL."),n=new L(o,i).href),e.log("Resolved import URL:",{importedFileURL:n,importedFromURL:s}));const f=m(s??"").toLowerCase(),c=m(n).toLowerCase();if(e.log("Rewriting file extension:",{parentExtension:f,specifierExtension:c}),c){const a=n.substring(0,n.lastIndexOf(c));if(e.log("Re-resolving specifier:",{unresolvedSpecifier:a}),y.test(c)&&N.test(f)){const p=D(a);if(p)return e.log("Found JS import in TS:",{unresolvedSpecifier:a,resolvedTsSourceFile:p}),{url:p}}return b(a)?(e.log("Found file at unresolved specifier:",{unresolvedSpecifier:a}),{url:a}):t(o,r,t)}e.log("Resolving incomplete URL import to file:",{specifier:o});const u=k(n);if(u)return e.log("Resolved import URL to file:",{resolvedFile:u}),{url:u};const x=new L(E(n,"index")).href,g=k(x);return g?(e.log("Resolved import URL to index file:",{resolvedIndexFile:g}),{url:g}):t(o,r,t)},J=async(o,r,t)=>{const s=d(J);if(s.log("Loading source file:",{url:o}),!o.includes(T.sep)&&!o.includes(M.sep))return s.log("Using defaultLoad for named module:",{url:o}),t(o,r,t);const e=m(o),l=R[e];if(!l)return s.log("No loader found, using defaultLoad:",{url:o}),t(o,r,t);const i=H(o),n=G(i,"utf8"),f=await h(n.toString(),{...l,sourcefile:i,format:"esm",define:{PACKAGE_JSON:F}});return{format:"module",source:f.code}},O=async(o,r,t)=>{const s=d(O);s.log("Getting format for source file:",{url:o});const e=m(o);return R[e]?{format:"module"}:(s.log("No loader found, using default format:",{url:o}),t(o,r,t))},B=async(o,r,t)=>{const s=d(B);s.log("Transforming source from context:",{context:r});const{url:e}=r,l=m(e),i=R[l];return i?{source:(await h(o.toString(),{...i,logLevel:"info",charset:"utf8",target:"esnext",sourcefile:r.url,format:r.format==="module"?"esm":"cjs",define:{PACKAGE_JSON:F}})).code}:(s.log("No loader found, using default transformer:",{url:e}),t(o,r,t))};export{O as getFormat,J as load,A as resolve,B as transformSource};
File without changes
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@tsmodule/tsmodule",
3
3
  "platform": "node",
4
4
  "type": "module",
5
- "version": "25.0.0",
5
+ "version": "27.0.2",
6
6
  "repository": "tsmodule/tsmodule",
7
7
  "description": "TypeScript Module loader and compiler",
8
8
  "license": "MIT",