@tsmodule/tsmodule 23.2.1 → 27.0.1

Sign up to get free protection for your applications and to get access to all the features.
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,12 +13,12 @@ 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
 
@@ -1,6 +1,4 @@
1
- import{dirname as k,extname as R,isAbsolute as W,resolve as O,resolve as u}from"path";import{build as D}from"esbuild";import{existsSync as E,mkdirSync as _,readFileSync as g,rmSync as x,writeFileSync as B}from"fs";import p from"chalk";import{env as C}from"process";import G from"fast-glob";import m from"ora";import{createDebugLogger as M,log as y}from"create-debug-logger";import{isJsOrTs as A,isTs as f,isTsxOrJsx as l}from"../../utils/index.js";import{createShell as I}from"await-shell";import{emitTsDeclarations as L}from"./lib/emitTsDeclarations.js";import{getPackageJsonFile as V}from"../../utils/pkgJson.js";import{normalizeImportSpecifiers as z}from"../normalize/index.js";const P=s=>{const c=` ${s} `;y(p.bgBlue(p.bold(p.white(c))))},X=()=>{let s;if(E("dist/package.json")?s=JSON.parse(g("dist/package.json","utf-8")):s={},s?.module==="module")return!0;s.type="module",B("dist/package.json",JSON.stringify(s,null,2))},K=async({files:s="src/**/*",styles:c="src/styles/components/index.css",bundle:S=!1,dev:i=!1,runtimeOnly:w=!1})=>{C.NODE_ENV=i?"development":"production";const F=I(),t=M(K);t.log("Building",{files:s,dev:i,runtimeOnly:w}),P(`${p.bold("TS Module")} [${C.NODE_ENV}]`);const J=await V(),h=JSON.parse(J),a=process.cwd(),j={absWorkingDir:a,bundle:S,treeShaking:S,outbase:"src",outdir:"dist",assetNames:"[name].js",logLevel:i?"warning":"error",charset:"utf8",format:"esm",target:"esnext",platform:h?.platform??"node",minify:!i,define:{PACKAGE_JSON:J,"process.env.NODE_ENV":i?JSON.stringify("development"):JSON.stringify("production")}},d=u(a,"src"),r=u(a,"dist"),o=G.sync(s,{cwd:a}).filter(e=>R(e)!==".d.ts").map(e=>u(e));if(W(s)){o.length||o.push(s);const e=s.replace(d,r).replace(f,".js").replace(l,".js");t.log("Cleaning emitted file:",{outfile:e}),x(e,{force:!0})}else t.log("Cleaning old output:",{outDir:r}),x(r,{force:!0,recursive:!0});console.log();const N=o.filter(e=>f.test(e)).filter(e=>!l.test(e));t.log("Compiling TS files:",{tsFiles:N}),await D({...j,entryPoints:N.filter(e=>!e.endsWith(".d.ts"))}),m("Built TS files.").succeed();const T=o.filter(e=>l.test(e));t.log("Compiling TSX files:",{tsxFiles:T});const $=T.filter(e=>!e.endsWith(".d.ts"));await Promise.all($.map(async e=>{const n=`
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
- ${g(e,"utf-8")}
5
- `;await D({...j,stdin:{contents:n,sourcefile:e,resolveDir:k(e),loader:"tsx"},outdir:void 0,outfile:e.replace(l,".js").replace(d,r),jsxFactory:"React.createElement"})})),m("Built TSX files.").succeed();const b=o.filter(e=>!A.test(e));if(t.log("Copying non-JS/TS files.",{allFiles:o,nonJsTsFiles:b}),await Promise.all(b.map(async e=>{const n=O(a,e).replace(d,r).replace(f,".js").replace(l,".js");t.log("Copying non-source file:",{file:e,outfile:n}),_(k(n),{recursive:!0}),B(n,g(e),{encoding:"binary",flag:"w"})})),!process.env.NO_REWRITES){const e=s.replace(d,r).replace(/^(\.\/)?src\//,"dist/").replace(f,".js").replace(l,".js");await z(e.endsWith(".js")?e:`${e}.js`),m("Normalized import specifiers.").succeed()}if(X()&&m('Forced "type": "module" in output.').succeed(),console.log(),!(i||w)){if(E(O(c))){t.log("Building styles for production.");const{style:e="./dist/styles.css"}=h,v=["npx tailwindcss",i?"":"-m","--postcss postcss.config.js",`-i ${c}`,"-o",e];await F.run(v.join(" "))}else t.log("Styles not found.",{styles:c});P("Running post-build setup."),y(`Generating type declarations.
6
- This might take a moment.`),L(o),m(`Generated delcarations for ${o.length} files.`).succeed(),y(p.green("Build complete."))}};export{P as bannerLog,K 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",m="23.2.1",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.
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(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);
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};
@@ -0,0 +1 @@
1
+ import{resolve as o}from"path";const i=()=>{const r=process.cwd(),s=o(r,"src"),t=o(r,"dist");return{cwd:r,srcDir:s,outDir:t}};export{i as getWorkingDirs};
File without changes
@@ -0,0 +1 @@
1
+ import{createDebugLogger as c,log as d}from"create-debug-logger";import a from"chalk";import{readFileSync as m}from"fs";function g(n){return new Promise((e,r)=>{const t=[];function i(o){t.push(o)}function s(){u(),e(Buffer.concat(t))}function f(o){u(),r(o)}function u(){n.removeListener("data",i),n.removeListener("end",s),n.removeListener("error",f)}n.on("data",i),n.on("end",s),n.on("error",f)})}const p=async()=>{const n=c(p);n.log("Reading stdin");try{const r=m(0).toString();if(r)return n.log("Found stdin",{stdin:r}),r}catch(r){n.log("Could not read stdin",{e:r})}return d(a.gray("Type your source code. Press Ctrl+D to finish.")),(await g(process.stdin)).toString()};export{p as readStdin};
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@tsmodule/tsmodule",
3
3
  "platform": "node",
4
4
  "type": "module",
5
- "version": "23.2.1",
5
+ "version": "27.0.1",
6
6
  "repository": "tsmodule/tsmodule",
7
7
  "description": "TypeScript Module loader and compiler",
8
8
  "license": "MIT",
@@ -39,7 +39,8 @@
39
39
  "prepare": "yarn build -r",
40
40
  "prepublishOnly": "yarn build && yarn test",
41
41
  "pretest": "yarn build -r",
42
- "test": "ava --no-worker-threads"
42
+ "test": "ava --no-worker-threads",
43
+ "retest": "SKIP_TEST_SETUP=1 yarn test"
43
44
  },
44
45
  "dependencies": {
45
46
  "@types/glob": "^7.2.0",