@tsmodule/tsmodule 22.1.0 → 23.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,6 @@
1
- import{dirname as D,extname as O,isAbsolute as $,resolve as h,resolve as u}from"path";import{build as J}from"esbuild";import{existsSync as k,mkdirSync as W,readFileSync as T,rmSync as x,writeFileSync as P}from"fs";import a from"chalk";import{env as E}from"process";import v from"fast-glob";import m from"ora";import{createDebugLogger as G,log as f}from"create-debug-logger";import{getPackageJson as _,getPackageJsonFile as A}from"../../utils/pkgJson.js";import{isJsOrTs as I,isTs as d,isTsxOrJsx as p}from"../../utils/index.js";import{createShell as L}from"await-shell";import{emitTsDeclarations as M}from"./lib/emitTsDeclarations.js";import{normalizeImportSpecifiers as R}from"../normalize/index.js";const F=s=>{const r=` ${s} `;f(a.bgBlue(a.bold(a.white(r))))},z=()=>{let s;if(k("dist/package.json")?s=JSON.parse(T("dist/package.json","utf-8")):s={},s?.module==="module")return!0;s.type="module",P("dist/package.json",JSON.stringify(s,null,2))},V=async({files:s="src/**/*",styles:r="src/styles/components/index.css",dev:i=!1,runtimeOnly:y=!1})=>{E.NODE_ENV=i?"development":"production";const N=L(),t=G(V);t.log("Building",{files:s,dev:i,runtimeOnly:y}),F(`${a.bold("TS Module")} [${E.NODE_ENV}]`);const B=await A(),n=process.cwd(),S={absWorkingDir:n,outbase:"src",outdir:"dist",assetNames:"[name].js",logLevel:i?"warning":"error",charset:"utf8",format:"esm",target:"esnext",minify:!i,define:{PACKAGE_JSON:B}},g=u(n,"src"),l=u(n,"dist"),o=v.sync(s,{cwd:n}).filter(e=>O(e)!==".d.ts").map(e=>u(e));if($(s)){o.length||o.push(s);const e=s.replace(g,l).replace(d,".js").replace(p,".js");t.log("Cleaning emitted file:",{outfile:e}),x(e,{force:!0})}else t.log("Cleaning old output:",{outDir:l}),x(l,{force:!0,recursive:!0});console.log();const w=o.filter(e=>d.test(e)).filter(e=>!p.test(e));t.log("Compiling TS files:",{tsFiles:w}),await J({...S,entryPoints:w.filter(e=>!e.endsWith(".d.ts"))}),m("Built TS files.").succeed();const j=o.filter(e=>p.test(e));t.log("Compiling TSX files:",{tsxFiles:j}),await J({...S,entryPoints:j.filter(e=>!e.endsWith(".d.ts")),jsxFactory:"createElement",banner:{js:`import { createElement } from "react";
2
- `}}),m("Built TSX files.").succeed();const b=o.filter(e=>!I.test(e));if(t.log("Copying non-JS/TS files.",{allFiles:o,nonJsTsFiles:b}),await Promise.all(b.map(async e=>{const c=h(n,e).replace(g,l).replace(d,".js").replace(p,".js");t.log("Copying non-source file:",{file:e,outfile:c}),W(D(c),{recursive:!0}),P(c,T(e),{encoding:"binary",flag:"w"})})),!process.env.NO_REWRITES){const e=s.replace(g,l).replace(/^(\.\/)?src\//,"dist/").replace(d,".js").replace(p,".js");await R(e.endsWith(".js")?e:`${e}.js`),m("Normalized import specifiers.").succeed()}if(z()&&m('Forced "type": "module" in output.').succeed(),console.log(),!(i||y)){if(k(h(r))){t.log("Building styles for production.");const e=await _(),{style:c="./dist/styles.css"}=e,C=["npx tailwindcss",i?"":"-m","--postcss postcss.config.js",`-i ${r}`,"-o",c];await N.run(C.join(" "))}else t.log("Styles not found.",{styles:r});F("Running post-build setup."),f(`Generating type declarations.
3
- This might take a moment.`),M(o),m(`Generated delcarations for ${o.length} files.`).succeed(),f(a.green("Build complete."))}};export{F as bannerLog,V as build};
1
+ import{dirname as T,extname as W,isAbsolute as G,resolve as b,resolve as g}from"path";import{build as D}from"esbuild";import{existsSync as P,mkdirSync as M,readFileSync as u,rmSync as x,writeFileSync as N}from"fs";import m from"chalk";import{env as O}from"process";import _ from"fast-glob";import p from"ora";import{createDebugLogger as A,log as y}from"create-debug-logger";import{getPackageJson as B,getPackageJsonFile as I}from"../../utils/pkgJson.js";import{isJsOrTs as L,isTs as f,isTsxOrJsx as c}from"../../utils/index.js";import{createShell as z}from"await-shell";import{emitTsDeclarations as V}from"./lib/emitTsDeclarations.js";import{normalizeImportSpecifiers as X}from"../normalize/index.js";const C=s=>{const l=` ${s} `;y(m.bgBlue(m.bold(m.white(l))))},K=()=>{let s;if(P("dist/package.json")?s=JSON.parse(u("dist/package.json","utf-8")):s={},s?.module==="module")return!0;s.type="module",N("dist/package.json",JSON.stringify(s,null,2))},U=async({files:s="src/**/*",styles:l="src/styles/components/index.css",bundle:w=!1,dev:r=!1,runtimeOnly:S=!1})=>{O.NODE_ENV=r?"development":"production";const E=z(),t=A(U);t.log("Building",{files:s,dev:r,runtimeOnly:S}),C(`${m.bold("TS Module")} [${O.NODE_ENV}]`);const F=await I(),$=await B(),a=process.cwd(),h={absWorkingDir:a,bundle:w,treeShaking:w,outbase:"src",outdir:"dist",assetNames:"[name].js",logLevel:r?"warning":"error",charset:"utf8",format:"esm",target:"esnext",platform:$?.platform??"node",minify:!r,define:{PACKAGE_JSON:F}},d=g(a,"src"),n=g(a,"dist"),o=_.sync(s,{cwd:a}).filter(e=>W(e)!==".d.ts").map(e=>g(e));if(G(s)){o.length||o.push(s);const e=s.replace(d,n).replace(f,".js").replace(c,".js");t.log("Cleaning emitted file:",{outfile:e}),x(e,{force:!0})}else t.log("Cleaning old output:",{outDir:n}),x(n,{force:!0,recursive:!0});console.log();const j=o.filter(e=>f.test(e)).filter(e=>!c.test(e));t.log("Compiling TS files:",{tsFiles:j}),await D({...h,entryPoints:j.filter(e=>!e.endsWith(".d.ts"))}),p("Built TS files.").succeed();const k=o.filter(e=>c.test(e));t.log("Compiling TSX files:",{tsxFiles:k});const R=k.filter(e=>!e.endsWith(".d.ts"));await Promise.all(R.map(async e=>{const i=`
2
+ import React from "react";
3
+ import ReactDOM from "react-dom";
4
+ ${u(e,"utf-8")}
5
+ `;await D({...h,stdin:{contents:i,sourcefile:e,resolveDir:T(e),loader:"tsx"},outdir:void 0,outfile:e.replace(c,".js").replace(d,n),jsxFactory:"React.createElement"})})),p("Built TSX files.").succeed();const J=o.filter(e=>!L.test(e));if(t.log("Copying non-JS/TS files.",{allFiles:o,nonJsTsFiles:J}),await Promise.all(J.map(async e=>{const i=b(a,e).replace(d,n).replace(f,".js").replace(c,".js");t.log("Copying non-source file:",{file:e,outfile:i}),M(T(i),{recursive:!0}),N(i,u(e),{encoding:"binary",flag:"w"})})),!process.env.NO_REWRITES){const e=s.replace(d,n).replace(/^(\.\/)?src\//,"dist/").replace(f,".js").replace(c,".js");await X(e.endsWith(".js")?e:`${e}.js`),p("Normalized import specifiers.").succeed()}if(K()&&p('Forced "type": "module" in output.').succeed(),console.log(),!(r||S)){if(P(b(l))){t.log("Building styles for production.");const e=await B(),{style:i="./dist/styles.css"}=e,v=["npx tailwindcss",r?"":"-m","--postcss postcss.config.js",`-i ${l}`,"-o",i];await E.run(v.join(" "))}else t.log("Styles not found.",{styles:l});C("Running post-build setup."),y(`Generating type declarations.
6
+ This might take a moment.`),V(o),p(`Generated delcarations for ${o.length} files.`).succeed(),y(m.green("Build complete."))}};export{C as bannerLog,U as build};
@@ -1 +1 @@
1
- import a from"chalk";import{createShell as c}from"await-shell";import d from"ora";import{createTemplate as n}from"./lib/createTemplate.js";import{rewritePkgJson as l}from"./lib/rewritePkgJson.js";globalThis.SHELL_OPTIONS={stdio:["ignore","ignore","inherit"]};const w=async(e,{react:o=!1})=>{const t=c(),i=d(`Creating new module ${a.blueBright(e)}.`).start();await n("default",e),o&&await n("react",e),await l(e),i.succeed("Project created."),process.chdir(e);const r=[],s=["@tsmodule/tsmodule"];o&&(r.push("react","react-dom"),s.push("@types/react","@types/react-dom","next","eslint","eslint-config-next","tailwindcss","postcss","postcss-import","autoprefixer")),r.length&&await t.run(`yarn add ${r.join(" ")}`),s.length&&await t.run(`yarn add -D ${s.join(" ")}`),i.succeed("Dependencies installed."),await t.run("git init"),i.succeed("Git initialized.")};export{w as create};
1
+ import a from"chalk";import{createShell as c}from"await-shell";import d from"ora";import{createTemplate as n}from"./lib/createTemplate.js";import{rewritePkgJson as l}from"./lib/rewritePkgJson.js";globalThis.SHELL_OPTIONS={stdio:["ignore","ignore","inherit"]};const w=async(e,{react:o=!1})=>{const i=c(),s=d(`Creating new module ${a.blueBright(e)}.`).start();await n("default",e),o&&await n("react",e),await l(e),s.succeed("Project created."),process.chdir(e);const r=[],t=["@tsmodule/tsmodule"];o?(r.push("react","react-dom"),t.push("@types/react","@types/react-dom","next","eslint","eslint-config-next","tailwindcss","postcss","postcss-import","autoprefixer")):t.push("@types/node"),r.length&&await i.run(`yarn add ${r.join(" ")}`),t.length&&await i.run(`yarn add -D ${t.join(" ")}`),s.succeed("Dependencies installed."),await i.run("git init"),s.succeed("Git initialized.")};export{w as create};
@@ -1,3 +1,3 @@
1
- import{existsSync as a,lstatSync as m}from"fs";import{relative as p,resolve as f}from"path";import{build as s}from"../build/index.js";import r from"chalk";import{createShell as u}from"await-shell";import{log as d}from"create-debug-logger";import w from"ora";import v from"node-watch";const o=()=>{console.clear()},i=t=>{d(`
1
+ import{existsSync as a,lstatSync as m}from"fs";import{relative as p,resolve as f}from"path";import{build as s}from"../build/index.js";import r from"chalk";import{createShell as u}from"await-shell";import{log as d}from"create-debug-logger";import w from"ora";import v from"node-watch";const o=()=>{process.env.NODE_ENV!=="test"&&console.clear()},i=t=>{d(`
2
2
  `,r.gray(`Built ${r.bold(t)}.`),`
3
- `,r.blue(new Date().toLocaleString()))},O=async()=>{const t=process.cwd(),c=u();process.platform!=="win32"&&await c.run("clear"),o(),await s({dev:!0}),i("src/**/*"),v(f(t,"src"),{recursive:!0}).on("change",async(D,e)=>{if(!a(e)||m(e).isDirectory())return;o();const n=Date.now();await s({dev:!0,files:e});const l=Date.now()-n;w(r.blueBright(`Dev refresh finished in ${r.bold(`${l}ms`)}.`)).succeed(),i(p(t,e))})};export{O as dev};
3
+ `,r.blue(new Date().toLocaleString()))},O=async()=>{const t=process.cwd(),c=u();process.platform!=="win32"&&process.env.NODE_ENV!=="test"&&await c.run("clear"),o(),await s({dev:!0}),i("src/**/*"),v(f(t,"src"),{recursive:!0}).on("change",async(D,e)=>{if(!a(e)||m(e).isDirectory())return;o();const n=Date.now();await s({dev:!0,files:e});const l=Date.now()-n;w(r.blueBright(`Dev refresh finished in ${r.bold(`${l}ms`)}.`)).succeed(),i(p(t,e))})};export{O as dev};
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- var r="@tsmodule/tsmodule",s="module",m="22.1.0",d="tsmodule/tsmodule",l="TypeScript Module loader and compiler",a="MIT",c={tsmodule:"dist/index.js"},p={".":"./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"}],b=["dist/","templates/"],g={node:">=14"},h={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"},v={"@types/glob":"^7.2.0","@types/node":"^17.0.21","@typescript-eslint/eslint-plugin":"^5.13.0","@typescript-eslint/parser":"^5.13.0",ava:"^4.1.0","await-shell":"^31.0.0",chalk:"^5.0.0",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"},y=["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"]},w={"@types/fs-extra":"^9.0.13"},t={name:r,type:s,version:m,repository:d,description:l,license:a,bin:c,exports:p,types:u,contributors:f,files:b,engines:g,scripts:h,dependencies:v,keywords:y,ava:S,devDependencies:w};import o from"chalk";import{Command as T}from"commander";import{build as x}from"./commands/build/index.js";import{create as B}from"./commands/create/index.js";import{dev as C}from"./commands/dev/index.js";import{execute as R}from"./commands/execute/index.js";import{normalizeImportSpecifiers as j}from"./commands/normalize/index.js";const{version:A}=t,i=new T;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",m="23.0.3",l="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"},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:m,repository:l,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 x}from"./commands/build/index.js";import{create as C}from"./commands/create/index.js";import{dev as R}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.
3
3
 
4
4
  Run TS directly: ${o.bold("tsmodule src/index.ts")}
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("-d, --dev","Build development runtime").option("-r, --runtime-only","Do not emit type declarations, only build JS runtime").description("Builds TS files to output in dist/.").action(x),i.command("create <name>").option("--react","Create React component library with Next.js").description("Create a new project.").action(B),i.command("normalize [files]").description(`Rewrites import specifiers in files to ESM-compliant paths.
6
- (default: dist/**/*.js)`).action(async({files:n})=>{await j(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(R),i.parse(process.argv);
5
+ Use a command: ${o.bold("tsmodule build")}`)).version(String(E)),i.command("dev").description("Build and watch for changes.").action(R),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").option("-d, --dev","Build development runtime").option("-r, --runtime-only","Do not emit type declarations, only build JS runtime").description("Builds TS files to output in dist/.").action(x),i.command("create <name>").option("--react","Create React component library with Next.js").description("Create a new project.").action(C),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);
@@ -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/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:process.env.NODE_ENV==="development"?"debug":"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 +1 @@
1
- import{existsSync as i}from"fs";import{fileURLToPath as c}from"url";import{posix as x}from"path";import{sep as p}from"path";const O=!1,h=/\.[mc]?tsx?(?=\?|$)/,S=/\.([mc])?js$/,L=/\.([mc])?[tj]sx$/,M=/\.([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),T=s=>s.split(p).join(x.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,M as isJsOrTs,h as isTs,L as isTsxOrJsx,T as normalizeSpecifier};
1
+ import{existsSync as i}from"fs";import{fileURLToPath as c}from"url";import{posix as x}from"path";import{sep as p}from"path";const O=process.env.NODE_ENV==="development",h=/\.[mc]?tsx?(?=\?|$)/,S=/\.([mc])?js$/,L=/\.([mc])?[tj]sx$/,M=/\.([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),T=s=>s.split(p).join(x.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,M as isJsOrTs,h as isTs,L as isTsxOrJsx,T as normalizeSpecifier};
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@tsmodule/tsmodule",
3
+ "platform": "node",
3
4
  "type": "module",
4
- "version": "22.1.0",
5
+ "version": "23.0.3",
5
6
  "repository": "tsmodule/tsmodule",
6
7
  "description": "TypeScript Module loader and compiler",
7
8
  "license": "MIT",
@@ -43,11 +44,11 @@
43
44
  "dependencies": {
44
45
  "@types/glob": "^7.2.0",
45
46
  "@types/node": "^17.0.21",
46
- "@typescript-eslint/eslint-plugin": "^5.13.0",
47
- "@typescript-eslint/parser": "^5.13.0",
47
+ "@typescript-eslint/eslint-plugin": "^5.14.0",
48
+ "@typescript-eslint/parser": "^5.14.0",
48
49
  "ava": "^4.1.0",
49
50
  "await-shell": "^31.0.0",
50
- "chalk": "^5.0.0",
51
+ "chalk": "^5.0.1",
51
52
  "commander": "^9.0.0",
52
53
  "create-debug-logger": "^3.0.0",
53
54
  "esbuild": "^0.14.25",
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "name": "template",
3
+ "platform": "node",
3
4
  "type": "module",
4
5
  "version": "0.0.1",
5
6
  "license": "MIT",
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "name": "template",
3
+ "platform": "browser",
3
4
  "version": "0.0.1",
4
5
  "license": "MIT",
5
6
  "types": "dist/index.d.ts",