@tsmodule/tsmodule 41.5.0 → 41.6.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.
Files changed (2) hide show
  1. package/dist/bin.js +1 -1
  2. package/package.json +1 -1
package/dist/bin.js CHANGED
@@ -45,7 +45,7 @@ import ReactDOM from "react-dom";
45
45
  \rTried running: ${l}.
46
46
  \rError: ${c+f}`)},Cy=`
47
47
  if(typeof process<"u"){let{dirname:e}=await import("path"),{fileURLToPath:i}=await import("url");globalThis.__filename=i(import.meta.url),globalThis.__dirname=e(globalThis.__filename);let{default:a}=await import("module");globalThis.require=a.createRequire(import.meta.url)}
48
- `,Sr=async({input:t="src/**/*",styles:e="src/components/index.css",target:r="esnext",dev:i=!1,bundle:n=!1,standalone:s=!1,runtimeOnly:o=!1,jsOnly:a=!1,noWrite:l=!1,stdin:u=void 0,stdinFile:c=void 0}={})=>{kh.NODE_ENV=i?"development":"production";let f=fe(Sr);i&&(o=!0),s&&(n=!0);let{cwd:h,srcDir:y,outDir:A}=Jo(),_=await Wo(),v=JSON.parse(_),b={treeShaking:n,target:r,minify:!i,jsx:"transform",jsxFactory:"React.createElement",format:"esm",charset:"utf8",logLevel:i?"warning":"error",define:{"process.env.NODE_ENV":i?JSON.stringify("development"):JSON.stringify("production")}},D=["esbuild","*.png"],F=Wt(h,"tsconfig.export.json"),ie=wr(F),Q=[];s||Q.push(Oh);let M={...b,tsconfig:ie?F:void 0,bundle:n,absWorkingDir:h,outbase:"src",outdir:"dist",assetNames:"[name].js",format:"esm",target:"esnext",platform:v?.platform??"node",write:!l,external:n?D:void 0,banner:n?{js:Cy}:void 0,plugins:Q},I="";if(u){f.log("Building file from stdin",{stdin:u,stdinFile:c,noWrite:l}),c||(Ce(S.red("ERROR: --stdin-file must be specified to emulate a file location when using stdin.")),process.exit(1)),typeof u=="string"&&u.length?I=u:I=await ra();let B={...b,sourcefile:c,loader:"tsx",banner:void 0,footer:void 0};if(l)return(await _y(I,B)).code;{let p=Ph(I,c,"tsx");await Ge(async()=>await ia({...M,...p}),{start:"Building stdin to dist/.",success:"Built stdin to dist/.",error:"Error building stdin to dist/."}),Ce(S.grey("Use --no-write to print to stdout instead."));return}}f.log("Building",{files:t,dev:i,runtimeOnly:o}),Dh(`${S.bold("TS Module")} [${kh.NODE_ENV}]`);let x=na.default.sync(t,{cwd:h}).filter(B=>Ay(B)!==".d.ts").map(B=>Wt(B));if(gy(t)){x.length||x.push(t);let B=t.replace(y,A).replace(Gt,".js").replace(yt,".js");f.log("Cleaning emitted file:",{outfile:B}),await Th(B,{force:!0})}else f.log("Cleaning old output:",{outDir:A}),await Th(A,{force:!0,recursive:!0});let L=x.filter(B=>yt.test(B));f.log("Compiling TSX files:",{tsxJsxInput:L});let te=L.filter(B=>!B.endsWith(".d.ts"));await Ge(async()=>await Promise.all(te.map(async B=>{let p=await Fh(B,"utf-8"),d=Ey+p,se=Ph(d,B,"tsx");await ia({...M,...se})})),{start:"Compiling TSX files.",success:"Compiled TSX files.",error:"Failed to compile TSX files."});let m=x.filter(B=>Gt.test(B)).filter(B=>!yt.test(B));f.log("Compiling TS files:",{tsJsInput:m}),await Ge(async()=>await ia({...M,entryPoints:m.filter(B=>!B.endsWith(".d.ts"))}),{start:"Compiling TS/JS files.",success:"Compiled TS/JS files.",error:"Failed to compile TS/JS files."});let j=x.filter(B=>!wh.test(B));if(await Ge(async()=>{for(let B of j){let p=Yo(B);f.log("Copying non-source file:",{file:B,emittedFile:p}),await Nh(Mh(p),{recursive:!0}),await py(B,p,hy.COPYFILE_FICLONE)}},{start:"Copying non-source files to dist/.",success:"Copied non-source files to dist/.",error:"Failed to copy non-source files to dist/."}),!process.env.NO_REWRITES){let B=t.replace(y,A).replace(/^(\.\/)?src\//,"dist/").replace(Gt,".js").replace(yt,".js");f.log("Normalizing import specifiers in emitted JS.",{emittedJs:B}),await Ge(async()=>await Vt(B.endsWith(".js")?B:`${B}.js`),{start:"Normalizing import specifiers.",success:"Normalized import specifiers.",error:"Failed to normalize import specifiers."}),await Vt(B.endsWith(".js")?B:`${B}.js`)}if(await yy()&&Ue('Forced "type": "module" in output.').succeed(),!o){if(!a)if(wr(my(e))){f.log("Building styles for production.");let{style:B="./dist/bundle.css"}=v;if(f.log("Building style bundle.",{bundleInput:e,bundleOutput:B,dev:i}),await Ge(async()=>await Lh(e,B,i),{start:"Bundling styles with Tailwind.",success:"Bundled styles with Tailwind.",error:"Failed to bundle styles."}),n){f.log("Bundling all styles.");let p=na.default.sync("dist/**/*.css");await Ge(async()=>await Promise.all(p.map(async d=>await Lh(d,d,i))),{start:"Bundling emitted styles",success:`Bundled all styles to ${S.bold(B)}.`,error:"Failed to bundle styles."})}}else Ce(S.grey(`Bundle styles not found for this project.
48
+ `,Sr=async({input:t="src/**/*",styles:e="src/components/index.css",target:r="esnext",dev:i=!1,bundle:n=!1,standalone:s=!1,runtimeOnly:o=!1,jsOnly:a=!1,noWrite:l=!1,stdin:u=void 0,stdinFile:c=void 0}={})=>{kh.NODE_ENV=i?"development":"production";let f=fe(Sr);i&&(o=!0),s&&(n=!0);let{cwd:h,srcDir:y,outDir:A}=Jo(),_=await Wo(),v=JSON.parse(_),b={treeShaking:n,target:r,minify:!i,jsx:"transform",jsxFactory:"React.createElement",format:"esm",charset:"utf8",logLevel:i?"warning":"error",define:{"process.env.NODE_ENV":i?JSON.stringify("development"):JSON.stringify("production")}},D=["esbuild","*.png"],F=Wt(h,"tsconfig.export.json"),ie=wr(F),Q=[];s||Q.push(Oh);let M={...b,tsconfig:ie?F:void 0,bundle:n,absWorkingDir:h,outbase:"src",outdir:"dist",assetNames:"[name].js",format:"esm",target:"esnext",platform:v?.platform??"node",write:!l,external:n?D:void 0,banner:n?{js:Cy}:void 0,plugins:Q};f.log("Build options",M);let I="";if(u){f.log("Building file from stdin",{stdin:u,stdinFile:c,noWrite:l}),c||(Ce(S.red("ERROR: --stdin-file must be specified to emulate a file location when using stdin.")),process.exit(1)),typeof u=="string"&&u.length?I=u:I=await ra();let B={...b,sourcefile:c,loader:"tsx",banner:void 0,footer:void 0};if(l)return(await _y(I,B)).code;{let p=Ph(I,c,"tsx");await Ge(async()=>await ia({...M,...p}),{start:"Building stdin to dist/.",success:"Built stdin to dist/.",error:"Error building stdin to dist/."}),Ce(S.grey("Use --no-write to print to stdout instead."));return}}f.log("Building",{files:t,dev:i,runtimeOnly:o}),Dh(`${S.bold("TS Module")} [${kh.NODE_ENV}]`);let x=na.default.sync(t,{cwd:h}).filter(B=>Ay(B)!==".d.ts").map(B=>Wt(B));if(gy(t)){x.length||x.push(t);let B=t.replace(y,A).replace(Gt,".js").replace(yt,".js");f.log("Cleaning emitted file:",{outfile:B}),await Th(B,{force:!0})}else f.log("Cleaning old output:",{outDir:A}),await Th(A,{force:!0,recursive:!0});let L=x.filter(B=>yt.test(B));f.log("Compiling TSX files:",{tsxJsxInput:L});let te=L.filter(B=>!B.endsWith(".d.ts"));await Ge(async()=>await Promise.all(te.map(async B=>{let p=await Fh(B,"utf-8"),d=Ey+p,se=Ph(d,B,"tsx");await ia({...M,...se})})),{start:"Compiling TSX files.",success:"Compiled TSX files.",error:"Failed to compile TSX files."});let m=x.filter(B=>Gt.test(B)).filter(B=>!yt.test(B));f.log("Compiling TS files:",{tsJsInput:m}),await Ge(async()=>await ia({...M,entryPoints:m.filter(B=>!B.endsWith(".d.ts"))}),{start:"Compiling TS/JS files.",success:"Compiled TS/JS files.",error:"Failed to compile TS/JS files."});let j=x.filter(B=>!wh.test(B));if(await Ge(async()=>{for(let B of j){let p=Yo(B);f.log("Copying non-source file:",{file:B,emittedFile:p}),await Nh(Mh(p),{recursive:!0}),await py(B,p,hy.COPYFILE_FICLONE)}},{start:"Copying non-source files to dist/.",success:"Copied non-source files to dist/.",error:"Failed to copy non-source files to dist/."}),!process.env.NO_REWRITES){let B=t.replace(y,A).replace(/^(\.\/)?src\//,"dist/").replace(Gt,".js").replace(yt,".js");f.log("Normalizing import specifiers in emitted JS.",{emittedJs:B}),await Ge(async()=>await Vt(B.endsWith(".js")?B:`${B}.js`),{start:"Normalizing import specifiers.",success:"Normalized import specifiers.",error:"Failed to normalize import specifiers."}),await Vt(B.endsWith(".js")?B:`${B}.js`)}if(await yy()&&Ue('Forced "type": "module" in output.').succeed(),!o){if(!a)if(wr(my(e))){f.log("Building styles for production.");let{style:B="./dist/bundle.css"}=v;if(f.log("Building style bundle.",{bundleInput:e,bundleOutput:B,dev:i}),await Ge(async()=>await Lh(e,B,i),{start:"Bundling styles with Tailwind.",success:"Bundled styles with Tailwind.",error:"Failed to bundle styles."}),n){f.log("Bundling all styles.");let p=na.default.sync("dist/**/*.css");await Ge(async()=>await Promise.all(p.map(async d=>await Lh(d,d,i))),{start:"Bundling emitted styles",success:`Bundled all styles to ${S.bold(B)}.`,error:"Failed to bundle styles."})}}else Ce(S.grey(`Bundle styles not found for this project.
49
49
  \rChecked: `+S.bold(e)));Dh("Running post-build setup."),await Ge(async()=>await Vo(),{start:"Generating type declarations.",success:`Generated declarations for ${x.length} files.`,error:"Failed to generate type declarations."}),Ce(S.green("Build complete."))}},Hh=async(t,e)=>await Sr({input:t,...e});var Gh=Ie(gi(),1);import{copyFile as wy,mkdir as sa}from"fs/promises";import{dirname as Sy,resolve as Xt}from"path";var $h={"./package.json":"./package.json",".":"./dist/index.js","./*":"./dist/*/index.js"},jh={packageJson:{type:"module",platform:"node",engines:{node:">=14"},types:"dist/index.d.ts",files:["dist"],exports:$h,scripts:{dev:"tsmodule dev",build:"tsmodule build",test:"ava",pretest:"tsmodule build",prepublishOnly:"yarn test",lint:"eslint src --fix"}},files:[".github/**",".eslintrc",".gitignore","tsconfig.json","tsconfig.export.json","LICENSE","ava.config.mjs"],dependencies:[],devDependencies:["@types/node","@tsmodule/tsmodule","@typescript-eslint/eslint-plugin","@typescript-eslint/parser","ava","eslint","typescript"]},Ct={default:jh,react:{packageJson:{platform:"browser",style:"dist/bundle.css",exports:{...$h,"./*":"./dist/components/*/index.js","./styles":"./dist/bundle.css","./styles/*":"./dist/components/*/index.css"},scripts:{export:"tsmodule build",dev:"next dev",build:"next build",start:"next start",lint:"next lint --fix",pretest:"tsmodule build --runtime-only",test:"ava",prepublishOnly:"yarn export && yarn test"}},files:[".github/**",".gitignore","next-env.d.ts","next.config.js","postcss.config.js","tailwind.config.js"],dependencies:["react@^18.2.0","react-dom@^18.2.0"],devDependencies:[...jh.devDependencies,"@types/react@^18.0.23","@types/react-dom@^18.0.7","eslint-config-next","@tsmodule/react","next","tailwindcss","autoprefixer","cssnano","postcss","postcss-import"]}};import{dirname as by,resolve as Kh}from"path";import{fileURLToPath as vy}from"url";import{readFile as xy}from"fs/promises";var Br=Kh(by(vy(import.meta.url)),".."),Uh=async()=>{let t=await xy(Kh(Br,"package.json"),"utf-8");return JSON.parse(t)};var Jh=t=>Xt(Br,`./templates/${t}`),aa=async({template:t,targetDir:e=process.cwd()})=>{let r=Ae(),i=Jh(t),n=Xt(e);await sa(n,{recursive:!0}),await r.run({posix:`cp -rf ${i}/. ${n}`,win32:`xcopy /E /I /Q /Y ${i}\\ ${n}\\`})},oa=async({template:t,targetDir:e=process.cwd()})=>{let r=fe(oa);r.log("Copying template files",{template:t,targetDir:e});let i=Jh(t),n=Xt(e);await sa(n,{recursive:!0});let s=await(0,Gh.default)(Ct[t].files,{cwd:i,dot:!0});if(s.length)for(let o of s){let a=Xt(i,o),l=Xt(n,o);r.log({sourcePath:a,replacementPath:l}),await sa(Sy(l),{recursive:!0}),await wy(a,l)}},Qr=async({template:t,targetDir:e=process.cwd()})=>{let r=Xt(e),i=Ct[t].packageJson;return await Yi(r,i)},Vi=async({template:t,targetDir:e=process.cwd()})=>{let r=Ae({cwd:e}),i=[...Ct.default.dependencies],n=[...Ct.default.devDependencies];switch(t){case"react":i.push(...Ct.react.dependencies),n.push(...Ct.react.devDependencies);break}i.length&&await r.run(`yarn add ${i.join(" ")}`),n.length&&await r.run(`yarn add -D ${n.join(" ")}`)},Yh=async({template:t,targetDir:e=process.cwd()})=>{let r={template:"default",targetDir:e};if(await oa(r),await Qr(r),t!=="default"){let i={template:t,targetDir:e};await oa(i),await Qr(i)}await Vi({template:t,targetDir:e})};var Vh=async()=>{let t="default";(await Xo())?.dependencies?.react&&(t="react"),await Yh({template:t,targetDir:process.cwd()})};import{resolve as Wh}from"path";var Xh=async(t,{react:e=!1})=>{let r=Ue(`Creating new module ${S.blueBright(t)}.`).start(),i={template:"default",targetDir:t};if(await aa(i),await Qr(i),e){let s={template:"react",targetDir:t};await aa(s),await Qr(s)}await Yi(Wh(process.cwd(),t),{name:t}),r.succeed("Project created."),await Vi({template:"default",targetDir:t}),e&&await Vi({template:"react",targetDir:t}),r.succeed("Dependencies installed."),await Ae({cwd:Wh(t),stdio:["ignore","ignore","inherit"]}).run("git init"),r.succeed("Set up as Git repository.")};import{relative as Hy,resolve as jy}from"path";import{existsSync as $y}from"fs";import{lstat as Ky}from"fs/promises";var _p=Ie(Ap(),1);var gp=()=>{console.clear()},mp=t=>{Ce(`
50
50
  `,S.gray(`Built ${S.bold(t)}.`),`
51
51
  `,S.blue(new Date().toLocaleString()))},Ep=async()=>{let t=process.cwd(),e=Ae();process.platform!=="win32"&&await e.run("clear"),gp(),await Sr({dev:!0}),mp("src/**/*"),(0,_p.default)(jy(t,"src"),{recursive:!0}).on("change",async(r,i)=>{if(!$y(i)||(await Ky(i)).isDirectory())return;gp();let a=Date.now();try{await Sr({dev:!0,runtimeOnly:!0,input:i})}catch(u){Ce("ERROR:",u)}let l=Date.now()-a;Ue(S.blueBright(`Dev refresh finished in ${S.bold(`${l}ms`)}.`)).succeed(),mp(Hy(t,i))})};import{pathToFileURL as Uy}from"url";import{resolve as Gy}from"path";var yp=async()=>{let t=Gy(Br,"dist/loader/index.js"),e=["--no-warnings","--loader",Uy(t).href,...process.argv.slice(2)],r=Ae({stdio:"inherit"}),{code:i}=await r.run(`node ${e.join(" ")}`);process.exit(i??0)};var Jy=t=>{let e=t;return!(e.code===void 0||e.stdout==null||e.stderr==null)},bt=t=>async(...r)=>{try{return await t(...r)}catch(i){qh("Error"),Jy(i)?(i.stdout&&console.log(S.red(i.stdout)),i.stderr&&console.log(S.redBright(i.stderr))):console.log(S.redBright(JSON.stringify(i,null,2))),console.log()}};var{version:Yy}=await Uh(),nt=new Ua;nt.name(S.white(S.bold("tsmodule"))).usage(S.white(S.bold("<file | command> [options]"))).description(S.blueBright(`A tool for building TypeScript modules.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@tsmodule/tsmodule",
3
3
  "platform": "node",
4
4
  "type": "module",
5
- "version": "41.5.0",
5
+ "version": "41.6.0",
6
6
  "repository": "tsmodule/tsmodule",
7
7
  "description": "TypeScript Module loader and compiler",
8
8
  "license": "MIT",