@tsmodule/tsmodule 9.4.2 → 9.5.0

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
@@ -74,7 +74,7 @@ in `src/pages`:
74
74
 
75
75
  ## Requirements
76
76
 
77
- Because TS modules are pure ESM environments, **Node 16+** is required.
77
+ Because TS modules are pure ESM environments, **Node 14+** is required.
78
78
 
79
79
  ## Installation
80
80
 
@@ -1,3 +1,3 @@
1
- import{build as d}from"esbuild";import{existsSync as h,readFileSync as k,writeFileSync as w}from"fs";import{extname as x,resolve as u}from"path";import l from"chalk";import{env as F}from"process";import T from"fast-glob";import i from"ora";import{rm as B}from"fs/promises";import{createDebugLogger as E,log as a}from"create-debug-logger";import{isTs as N,isTsxOrJsx as g}from"../../utils/index.js";import{emitTsDeclarations as O}from"./lib/emitTsDeclarations.js";import{getPackageJsonFile as J}from"../../utils/pkgJson.js";import{normalizeImportSpecifiers as j}from"../normalize/index.js";const y=t=>{a(l.bgBlue(l.white(` ${t} `)))},D=async({dev:t=!1,fast:b=!1})=>{t&&(F.NODE_ENV="development");const r=E(D);t||y("Building for production.");const n=process.cwd(),S=await J(),c={absWorkingDir:n,outbase:"src",outdir:"dist",assetNames:"[name].js",logLevel:t?"debug":"error",charset:"utf8",format:"esm",target:"esnext",minify:!t,define:{PACKAGE_JSON:S}},m=u(n,"dist");r.log("Cleaning old output:",{distDir:m}),await B(m,{force:!0,recursive:!0}),console.log();const s=T.sync("src/**/*",{cwd:n}).filter(e=>x(e)!==".d.ts").map(e=>u(e)),f=s.filter(e=>N.test(e)).filter(e=>!g.test(e));r.log("Compiling TS files:",{tsFiles:f}),await d({...c,entryPoints:f.filter(e=>!e.endsWith(".d.ts"))}),i("Built TS files.").succeed();const p=s.filter(e=>g.test(e));if(r.log("Compiling TSX files:",{tsxFiles:p}),await d({...c,entryPoints:p.filter(e=>!e.endsWith(".d.ts")),jsxFactory:"createElement",banner:{js:`import { createElement } from "react";
1
+ import{build as d}from"esbuild";import{existsSync as h,readFileSync as k,writeFileSync as w}from"fs";import{extname as x,resolve as u}from"path";import l from"chalk";import{env as F}from"process";import T from"fs/promises";import B from"fast-glob";import i from"ora";import{createDebugLogger as E,log as a}from"create-debug-logger";import{isTs as N,isTsxOrJsx as g}from"../../utils/index.js";import{emitTsDeclarations as O}from"./lib/emitTsDeclarations.js";import{getPackageJsonFile as J}from"../../utils/pkgJson.js";import{normalizeImportSpecifiers as j}from"../normalize/index.js";const y=t=>{a(l.bgBlue(l.white(` ${t} `)))},D=async({dev:t=!1,fast:b=!1})=>{t&&(F.NODE_ENV="development");const r=E(D);t||y("Building for production.");const n=process.cwd(),S=await J(),c={absWorkingDir:n,outbase:"src",outdir:"dist",assetNames:"[name].js",logLevel:t?"debug":"error",charset:"utf8",format:"esm",target:"esnext",minify:!t,define:{PACKAGE_JSON:S}},m=u(n,"dist");r.log("Cleaning old output:",{distDir:m}),await T.rm(m,{force:!0,recursive:!0}),console.log();const s=B.sync("src/**/*",{cwd:n}).filter(e=>x(e)!==".d.ts").map(e=>u(e)),f=s.filter(e=>N.test(e)).filter(e=>!g.test(e));r.log("Compiling TS files:",{tsFiles:f}),await d({...c,entryPoints:f.filter(e=>!e.endsWith(".d.ts"))}),i("Built TS files.").succeed();const p=s.filter(e=>g.test(e));if(r.log("Compiling TSX files:",{tsxFiles:p}),await d({...c,entryPoints:p.filter(e=>!e.endsWith(".d.ts")),jsxFactory:"createElement",banner:{js:`import { createElement } from "react";
2
2
  `}}),i("Built TSX files.").succeed(),process.env.NO_REWRITES||(await j(),i("Normalized import specifiers.").succeed(),console.log(),t||b))return;y("Running post-build setup."),a(`Generating type declarations.
3
3
  This might take a moment.`),O(s),i(`Generated delcarations for ${s.length} files.`).succeed();let o;h("dist/package.json")?o=JSON.parse(k("dist/package.json","utf-8")):o={},o.type="module",w("dist/package.json",JSON.stringify(o,null,2)),i('Forced "type": "module" in output.').succeed(),a(l.green("Build complete."))};export{y as bannerLog,D as build};
@@ -1 +1 @@
1
- import{cp as p,readFile as d,writeFile as m}from"fs/promises";import{fileURLToPath as g,URL as u}from"url";import w from"chalk";import f from"ora";import{resolve as s}from"path";import{shell as a}from"await-shell";const j=async e=>{const i=process.cwd(),t=f(`Creating new module ${w.blueBright(e)}.`).start(),n=new u("../../../template",import.meta.url);await p(g(n),s(i,e),{recursive:!0});const r=s(i,e,"package.json"),c=await d(r,"utf-8"),o=JSON.parse(c);o.name=e,await m(r,JSON.stringify(o,null,2)),t.succeed("Project created."),t.start("Installing dependencies."),process.chdir(e);const l=["@tsmodule/tsmodule"];globalThis.SHELL_OPTIONS={stdio:["ignore","ignore","inherit"]},await a(`yarn add -D ${l.join(" ")}`),t.succeed("Dependencies installed."),t.start("Initializing git."),await a("git init"),t.succeed("Git initialized.")};export{j as create};
1
+ import{fileURLToPath as d,URL as m}from"url";import g from"chalk";import r from"fs/promises";import f from"ora";import{resolve as n}from"path";import{shell as i}from"await-shell";const P=async e=>{const o=process.cwd(),t=f(`Creating new module ${g.blueBright(e)}.`).start(),c=new m("../../../template",import.meta.url);await i(`cp -R ${d(c)} ${n(o,e)}`);const s=n(o,e,"package.json"),l=await r.readFile(s,"utf-8"),a=JSON.parse(l);a.name=e,await r.writeFile(s,JSON.stringify(a,null,2)),t.succeed("Project created."),t.start("Installing dependencies."),process.chdir(e);const p=["@tsmodule/tsmodule"];globalThis.SHELL_OPTIONS={stdio:["ignore","ignore","inherit"]},await i(`yarn add -D ${p.join(" ")}`),t.succeed("Dependencies installed."),t.start("Initializing git."),await i("git init"),t.succeed("Git initialized.")};export{P as create};
@@ -1,2 +1,2 @@
1
- import{readFile as w,writeFile as $}from"fs/promises";import x from"fast-glob";import{pathToFileURL as E}from"url";import{resolve as y}from"path";import{createDebugLogger as g}from"create-debug-logger";import{getRewrittenSpecifiers as I}from"./lib/typescriptApi.js";const P=e=>{const r=`[^
2
- \r;]*`,o=e.replace(".","\\.").replace("/","\\/"),s=`${r}["']${o}["']${r}`,t=`(import${r}from)`,i=`(import|require)${r}\\(`,n=`(export${r}from)`;return new RegExp(`(${t}|${i}|${n})${s}`,"g")},d=(e,r,o)=>{g(d).log("Rewriting import",{importStatement:e,specifierToReplace:r,specifierReplacement:o});const[,t]=e.split(/from|\(/),i=t.replace(r,o).trim();return e.replace(t,i)},R=async(e="dist/**/*.js")=>{const r=g(R),o=await x(e,{cwd:process.cwd()});r.log("Normalizing import/require specifiers:",{filesToNormalize:o});for(const s of o){const t=y(s),i=E(t).href,n=I(t);if(!n)return null;r.log("TypeScript API yielded specifiers to rewrite:",{rewrites:n});let p=await w(t,"utf8");r.group();for(const{specifierToReplace:c,specifierReplacement:a}of n){const u=P(c),l=p.match(u)??[];r.log("Replacing import statements.",{entryPointURL:i,specifierToReplace:c,specifierReplacement:a,importStatements:l});for(const m of l){r.group();const f=d(m,c,a);r.log("Performing specifier rewrite.",{entryPointURL:i,importStatement:m,rewrittenImportStatement:f}),p=p.replace(m,f),await $(t,p),r.log("Wrote output file.",{resolvedEntryPoint:t}),r.groupEnd()}}r.groupEnd()}};export{P as generateImportPattern,R as normalizeImportSpecifiers,d as rewriteImportStatement};
1
+ import{promises as g}from"fs";import $ from"fast-glob";import{pathToFileURL as x}from"url";import{resolve as E}from"path";import{createDebugLogger as d}from"create-debug-logger";import{getRewrittenSpecifiers as y}from"./lib/typescriptApi.js";const I=t=>{const r=`[^
2
+ \r;]*`,o=t.replace(".","\\.").replace("/","\\/"),n=`${r}["']${o}["']${r}`,e=`(import${r}from)`,i=`(import|require)${r}\\(`,s=`(export${r}from)`;return new RegExp(`(${e}|${i}|${s})${n}`,"g")},u=(t,r,o)=>{d(u).log("Rewriting import",{importStatement:t,specifierToReplace:r,specifierReplacement:o});const[,e]=t.split(/from|\(/),i=e.replace(r,o).trim();return t.replace(e,i)},P=async(t="dist/**/*.js")=>{const r=d(P),o=await $(t,{cwd:process.cwd()});r.log("Normalizing import/require specifiers:",{filesToNormalize:o});for(const n of o){const e=E(n),i=x(e).href,s=y(e);if(!s)return null;r.log("TypeScript API yielded specifiers to rewrite:",{rewrites:s});let p=await g.readFile(e,"utf8");r.group();for(const{specifierToReplace:c,specifierReplacement:a}of s){const w=I(c),l=p.match(w)??[];r.log("Replacing import statements.",{entryPointURL:i,specifierToReplace:c,specifierReplacement:a,importStatements:l});for(const m of l){r.group();const f=u(m,c,a);r.log("Performing specifier rewrite.",{entryPointURL:i,importStatement:m,rewrittenImportStatement:f}),p=p.replace(m,f),await g.writeFile(e,p),r.log("Wrote output file.",{resolvedEntryPoint:e}),r.groupEnd()}}r.groupEnd()}};export{I as generateImportPattern,P as normalizeImportSpecifiers,u as rewriteImportStatement};
@@ -1 +1 @@
1
- import{dirname as E,extname as v,relative as w}from"path/posix";import{createDebugLogger as N}from"create-debug-logger";import e from"typescript";const l={moduleResolution:e.ModuleResolutionKind.NodeJs,module:e.ModuleKind.ESNext,target:e.ScriptTarget.ESNext,esModuleInterop:!0,incremental:!1,noEmit:!0,rootDir:"src",outDir:"dist"},p=e.createCompilerHost(l),R=(t,o=process.cwd())=>{const{resolvedModule:r}=e.resolveModuleName(t,o,l,p);if(!r){const s=JSON.stringify({specifier:t,entryPoint:o},null,2);throw new Error(`Could not resolve module: ${s}`)}return r},x=(t,o)=>{const r=w(E(t),o);return r.startsWith(".")?r:`./${r}`},h=t=>{const o=N(h);o.log("Getting rewritten specifiers:",{modulePath:t});const{resolvedFileName:r}=R(t),s=p.getSourceFile(r,e.ScriptTarget.ESNext);if(!s)throw new Error(`Could not read source file: ${r}`);const{statements:d,fileName:u}=s,a=[];return d.forEach(n=>{const f=e.isExportDeclaration(n);if(!(e.isImportDeclaration(n)&&!n?.importClause?.isTypeOnly)&&!f)return;const{moduleSpecifier:c}=n;if(!c){if(f)return;throw new Error(`Could not find module specifier in: ${JSON.stringify(n)}`)}if(e.isStringLiteral(c)){const{text:i}=c;if(!i.startsWith(".")||v(i))return;o.log("Using TypeScript API to resolve specifier",{specifier:i});const{resolvedModule:m}=e.resolveModuleName(i,u,{...l,allowJs:!0,checkJs:!0},p);if(!m)throw new Error(`Could not resolve module: ${i}`);const{resolvedFileName:g}=m,S=x(u,g);a.push({specifierToReplace:i,specifierReplacement:S})}}),a};export{l as TS_CONFIG,p as compilerHost,h as getRewrittenSpecifiers};
1
+ import{createDebugLogger as v}from"create-debug-logger";import{posix as l}from"path";import e from"typescript";const p={moduleResolution:e.ModuleResolutionKind.NodeJs,module:e.ModuleKind.ESNext,target:e.ScriptTarget.ESNext,esModuleInterop:!0,incremental:!1,noEmit:!0,rootDir:"src",outDir:"dist"},a=e.createCompilerHost(p),w=(t,o=process.cwd())=>{const{resolvedModule:r}=e.resolveModuleName(t,o,p,a);if(!r){const s=JSON.stringify({specifier:t,entryPoint:o},null,2);throw new Error(`Could not resolve module: ${s}`)}return r},N=(t,o)=>{const r=l.relative(l.dirname(t),o);return r.startsWith(".")?r:`./${r}`},x=t=>{const o=v(x);o.log("Getting rewritten specifiers:",{modulePath:t});const{resolvedFileName:r}=w(t),s=a.getSourceFile(r,e.ScriptTarget.ESNext);if(!s)throw new Error(`Could not read source file: ${r}`);const{statements:g,fileName:u}=s,f=[];return g.forEach(n=>{const m=e.isExportDeclaration(n);if(!(e.isImportDeclaration(n)&&!n?.importClause?.isTypeOnly)&&!m)return;const{moduleSpecifier:c}=n;if(!c){if(m)return;throw new Error(`Could not find module specifier in: ${JSON.stringify(n)}`)}if(e.isStringLiteral(c)){const{text:i}=c;if(!i.startsWith(".")||l.extname(i))return;o.log("Using TypeScript API to resolve specifier",{specifier:i});const{resolvedModule:d}=e.resolveModuleName(i,u,{...p,allowJs:!0,checkJs:!0},a);if(!d)throw new Error(`Could not resolve module: ${i}`);const{resolvedFileName:S}=d,E=N(u,S);f.push({specifierToReplace:i,specifierReplacement:E})}}),f};export{p as TS_CONFIG,a as compilerHost,x as getRewrittenSpecifiers};
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
- var r="@tsmodule/tsmodule",m="module",a="9.4.2",s="tsmodule/tsmodule",d="TypeScript Module loader and compiler",p="MIT",l={tsmodule:"dist/index.js"},c={".":"./dist/loader/index.js","./*":"./dist/*/index.js","./package.json":"./package.json"},u="dist/types/index.d.ts",f=[{name:"C. Lewis",email:"ctj.lewis@icloud.com",url:"https://ctjlewis.com"}],g=["dist/","template/"],v={node:">=14"},b={bootstrap:"node bootstrap.js",prebuild:"yarn bootstrap",build:"node --no-warnings --loader ./dist/loader/index.js src/index.ts build",lint:"eslint --fix src",prepare:"yarn build -f",prepublishOnly:"yarn build && yarn test",test:"ava --no-worker-threads"},S={"@types/cross-spawn":"^6.0.2","@types/node":"17.0.8","@types/react":"17.0.38","@typescript-eslint/eslint-plugin":"^5.9.1","@typescript-eslint/parser":"^5.9.1",ava:"^4.0.1","await-shell":"^4.1.0",chalk:"^5.0.0",commander:"^8.3.0","create-debug-logger":"^1.10.1","cross-spawn":"^7.0.3",esbuild:"^0.14.0",eslint:"^8.6.0","fast-glob":"^3.2.10",ora:"^6.0.1",path:"^0.12.7",react:"^17.0.2",typescript:"^4.5.5"},h=["esm","loader","typescript","loader hook","require hook","experimental-loader"],w={files:["test/**/*.test.ts"],extensions:{ts:"module"},nodeArguments:["--no-warnings","--loader=@tsmodule/tsmodule"]},t={name:r,type:m,version:a,repository:s,description:d,license:p,bin:l,exports:c,types:u,contributors:f,files:g,engines:v,scripts:b,dependencies:S,keywords:h,ava:w};import i from"chalk";import{Command as y}from"commander";import{build as B}from"./commands/build/index.js";import{create as T}from"./commands/create/index.js";import{execute as A}from"./commands/execute/index.js";import{normalizeImportSpecifiers as C}from"./commands/normalize/index.js";const{version:E}=t,e=new y;e.name(i.bold(i.blueBright("tsmodule"))).description(i.blueBright("A tool for building TypeScript modules.")).version(String(E)),e.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(A),e.command("build").option("-d, --dev","Build development version (default: production)").option("-f, --fast","Do not emit type declarations, only transform to JS.").description("Builds TS files to output in dist/.").action(B),e.command("create <name>").description("Create a new project.").action(T),e.command("normalize [files]").description(`Rewrites import specifiers in files to ESM-compliant paths.
2
+ var r="@tsmodule/tsmodule",m="module",a="9.5.0",s="tsmodule/tsmodule",d="TypeScript Module loader and compiler",p="MIT",l={tsmodule:"dist/index.js"},c={".":"./dist/loader/index.js","./*":"./dist/*/index.js","./package.json":"./package.json"},u="dist/types/index.d.ts",f=[{name:"C. Lewis",email:"ctj.lewis@icloud.com",url:"https://ctjlewis.com"}],g=["dist/","template/"],v={node:">=14"},b={bootstrap:"node bootstrap.js",prebuild:"yarn bootstrap",build:"node --no-warnings --loader ./dist/loader/index.js src/index.ts build",lint:"eslint --fix src",prepare:"yarn build -f",prepublishOnly:"yarn build && yarn test",test:"ava --no-worker-threads"},S={"@types/cross-spawn":"^6.0.2","@types/node":"17.0.8","@types/react":"17.0.38","@typescript-eslint/eslint-plugin":"^5.9.1","@typescript-eslint/parser":"^5.9.1",ava:"^4.0.1","await-shell":"^4.1.0",chalk:"^5.0.0",commander:"^8.3.0","create-debug-logger":"^1.10.1","cross-spawn":"^7.0.3",esbuild:"^0.14.0",eslint:"^8.6.0","fast-glob":"^3.2.10",ora:"^6.0.1",path:"^0.12.7",react:"^17.0.2",typescript:"^4.5.5"},h=["esm","loader","typescript","loader hook","require hook","experimental-loader"],w={files:["test/**/*.test.ts"],extensions:{ts:"module"},nodeArguments:["--no-warnings","--loader=@tsmodule/tsmodule"]},t={name:r,type:m,version:a,repository:s,description:d,license:p,bin:l,exports:c,types:u,contributors:f,files:g,engines:v,scripts:b,dependencies:S,keywords:h,ava:w};import i from"chalk";import{Command as y}from"commander";import{build as B}from"./commands/build/index.js";import{create as T}from"./commands/create/index.js";import{execute as A}from"./commands/execute/index.js";import{normalizeImportSpecifiers as C}from"./commands/normalize/index.js";const{version:E}=t,e=new y;e.name(i.bold(i.blueBright("tsmodule"))).description(i.blueBright("A tool for building TypeScript modules.")).version(String(E)),e.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(A),e.command("build").option("-d, --dev","Build development version (default: production)").option("-f, --fast","Do not emit type declarations, only transform to JS.").description("Builds TS files to output in dist/.").action(B),e.command("create <name>").description("Create a new project.").action(T),e.command("normalize [files]").description(`Rewrites import specifiers in files to ESM-compliant paths.
3
3
  (default: dist/**/*.js)`).action(async({files:n})=>{await C(n)}),e.parse(process.argv);
@@ -1 +1 @@
1
- import{extname as m,isAbsolute as U,join as h,normalize as x,resolve as w}from"path";import{fileURLToPath as H,pathToFileURL as v,URL as L}from"url";import{promises as G}from"fs";import{transform as k}from"esbuild";import{sep as M}from"path/posix";import{sep as T}from"path/win32";import{checkExtensions as F,checkTsExtensions as D,fileExists as b,isJs as N,isTs as y,MODULE_LOADERS as R}from"../utils/index.js";import{getPackageJsonFile as A}from"../utils/pkgJson.js";import{createDebugLogger as c}from"create-debug-logger";const E=await A(),J=async(o,r,t)=>{const{parentURL:s}=r,e=c(J);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(x(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(),d=m(n).toLowerCase();if(e.log("Rewriting file extension:",{parentExtension:f,specifierExtension:d}),d){const a=n.substring(0,n.lastIndexOf(d));if(e.log("Re-resolving specifier:",{unresolvedSpecifier:a}),N.test(d)&&y.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 g=F(n);if(g)return e.log("Resolved import URL to file:",{resolvedFile:g}),{url:g};const S=new L(h(n,"index")).href,u=F(S);return u?(e.log("Resolved import URL to index file:",{resolvedIndexFile:u}),{url:u}):t(o,r,t)},O=async(o,r,t)=>{const s=c(O);if(s.log("Loading source file:",{url:o}),!o.includes(T)&&!o.includes(M))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=await G.readFile(i),f=await k(n.toString(),{...l,sourcefile:i,format:"esm",define:{PACKAGE_JSON:E}});return{format:"module",source:f.code}},P=async(o,r,t)=>{const s=c(P);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=c(B);s.log("Transforming source from context:",{context:r});const{url:e}=r,l=m(e),i=R[l];return i?{source:(await k(o.toString(),{...i,logLevel:"info",charset:"utf8",target:"esnext",sourcefile:r.url,format:r.format==="module"?"esm":"cjs",define:{PACKAGE_JSON:E}})).code}:(s.log("No loader found, using default transformer:",{url:e}),t(o,r,t))};export{P as getFormat,O as load,J as resolve,B as transformSource};
1
+ import{extname as m,isAbsolute as U,join as E,normalize as w,resolve as S}from"path";import{fileURLToPath as H,pathToFileURL as v,URL as L}from"url";import{promises 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 N,isTs as P,MODULE_LOADERS as R}from"../utils/index.js";import{getPackageJsonFile as y}from"../utils/pkgJson.js";import{createDebugLogger as c}from"create-debug-logger";const F=await y(),A=async(o,r,t)=>{const{parentURL:s}=r,e=c(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(S(w(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(),d=m(n).toLowerCase();if(e.log("Rewriting file extension:",{parentExtension:f,specifierExtension:d}),d){const a=n.substring(0,n.lastIndexOf(d));if(e.log("Re-resolving specifier:",{unresolvedSpecifier:a}),N.test(d)&&P.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 g=k(n);if(g)return e.log("Resolved import URL to file:",{resolvedFile:g}),{url:g};const x=new L(E(n,"index")).href,u=k(x);return u?(e.log("Resolved import URL to index file:",{resolvedIndexFile:u}),{url:u}):t(o,r,t)},J=async(o,r,t)=>{const s=c(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=await G.readFile(i),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=c(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=c(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};
@@ -19,7 +19,7 @@ export declare const POSSIBLE_EXTENSIONS: string[];
19
19
  /**
20
20
  * Force a Unix-like path.
21
21
  */
22
- export declare const normalizeSpecifier: (path: string) => string;
22
+ export declare const normalizeSpecifier: (specifier: string) => string;
23
23
  export declare const fileExists: (fileUrl: string) => string | void;
24
24
  export declare const fileExistsAny: (fileUrls: string[]) => string | void;
25
25
  export declare const checkTsExtensions: (specifier: string) => string | void;
@@ -1 +1 @@
1
- import{existsSync as i}from"fs";import{fileURLToPath as c}from"url";import{sep as p}from"path/posix";import{sep as x}from"path";const O=!1,S=/\.[mc]?tsx?(?=\?|$)/,h=/\.([mc])?js$/,L=/\.([mc])?[tj]sx$/,e={format:"esm",charset:"utf8",sourcemap:"inline",target:"node16",minify:!1},a={".mts":{...e,loader:"ts"},".jsx":{...e,loader:"jsx"},".tsx":{...e,loader:"tsx"},".cts":{...e,loader:"ts"},".ts":{...e,loader:"ts"},".json":{...e,loader:"json"}},n=Object.keys(a),M=s=>s.split(x).join(p),l=s=>{const t=c(s);if(i(t))return s},r=s=>{for(const t of s)if(l(t))return t},m=s=>{const t=n.filter(o=>o.includes("ts")).concat([".js"]);return r(t.map(o=>s+o))},f=s=>{const t=n.filter(o=>o.includes("js")).concat([".js"]);return r(t.map(o=>s+o))},y=s=>{const t=f(s);if(t)return t;const o=m(s);if(o)return o};export{e as BASE_CONFIG,O as DEVELOPMENT_MODE,a as MODULE_LOADERS,n as POSSIBLE_EXTENSIONS,y as checkExtensions,f as checkJsExtension,m as checkTsExtensions,l as fileExists,r as fileExistsAny,h as isJs,S as isTs,L as isTsxOrJsx,M as normalizeSpecifier};
1
+ import{existsSync as i}from"fs";import{fileURLToPath as c}from"url";import{posix as p}from"path";import{sep as x}from"path";const O=!1,h=/\.[mc]?tsx?(?=\?|$)/,S=/\.([mc])?js$/,L=/\.([mc])?[tj]sx$/,e={format:"esm",charset:"utf8",sourcemap:"inline",target:"node16",minify:!1},a={".mts":{...e,loader:"ts"},".jsx":{...e,loader:"jsx"},".tsx":{...e,loader:"tsx"},".cts":{...e,loader:"ts"},".ts":{...e,loader:"ts"},".json":{...e,loader:"json"}},n=Object.keys(a),M=s=>s.split(x).join(p.sep),l=s=>{const t=c(s);if(i(t))return s},r=s=>{for(const t of s)if(l(t))return t},m=s=>{const t=n.filter(o=>o.includes("ts")).concat([".js"]);return r(t.map(o=>s+o))},f=s=>{const t=n.filter(o=>o.includes("js")).concat([".js"]);return r(t.map(o=>s+o))},y=s=>{const t=f(s);if(t)return t;const o=m(s);if(o)return o};export{e as BASE_CONFIG,O as DEVELOPMENT_MODE,a as MODULE_LOADERS,n as POSSIBLE_EXTENSIONS,y as checkExtensions,f as checkJsExtension,m as checkTsExtensions,l as fileExists,r as fileExistsAny,S as isJs,h as isTs,L as isTsxOrJsx,M as normalizeSpecifier};
@@ -1 +1 @@
1
- import{readFile as r}from"fs/promises";import{resolve as s}from"path";const n=async()=>{const o=process.cwd(),e=s(o,"package.json");return await r(e,"utf-8")};export{n as getPackageJsonFile};
1
+ import{promises as e}from"fs";import{resolve as r}from"path";const n=async()=>{const o=process.cwd(),s=r(o,"package.json");return await e.readFile(s,"utf-8")};export{n as getPackageJsonFile};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tsmodule/tsmodule",
3
3
  "type": "module",
4
- "version": "9.4.2",
4
+ "version": "9.5.0",
5
5
  "repository": "tsmodule/tsmodule",
6
6
  "description": "TypeScript Module loader and compiler",
7
7
  "license": "MIT",