@tsmodule/tsmodule 19.0.0 → 21.0.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.
@@ -1,3 +1,3 @@
1
- import{dirname as B,extname as C,isAbsolute as D,resolve as b,resolve as g}from"path";import{build as h}from"esbuild";import{existsSync as J,mkdirSync as W,readFileSync as k,rmSync as T,writeFileSync as x}from"fs";import c from"chalk";import{env as P}from"process";import $ from"fast-glob";import a from"ora";import{createDebugLogger as v,log as u}from"create-debug-logger";import{getPackageJson as G,getPackageJsonFile as _}from"../../utils/pkgJson.js";import{isJsOrTs as A,isTs as p,isTsxOrJsx as m}from"../../utils/index.js";import{createShell as I}from"await-shell";import{emitTsDeclarations as L}from"./lib/emitTsDeclarations.js";import{normalizeImportSpecifiers as M}from"../normalize/index.js";const E=s=>{const t=` ${s} `;u(c.bgBlue(c.bold(c.white(t))))},R=()=>{let s;if(J("dist/package.json")?s=JSON.parse(k("dist/package.json","utf-8")):s={},s?.module==="module")return!0;s.type="module",x("dist/package.json",JSON.stringify(s,null,2))},z=async({files:s="src/**/*",dev:t=!1,fast:f=!1})=>{P.NODE_ENV=t?"development":"production";const F=I(),o=v(z);o.log("Building",{files:s,dev:t,fast:f}),E(`${c.bold("TS Module")} [${P.NODE_ENV}]`);const N=await _(),r=process.cwd(),y={absWorkingDir:r,outbase:"src",outdir:"dist",assetNames:"[name].js",logLevel:t?"warning":"error",charset:"utf8",format:"esm",target:"esnext",minify:!t,define:{PACKAGE_JSON:N}},d=g(r,"src"),n=g(r,"dist"),i=$.sync(s,{cwd:r}).filter(e=>C(e)!==".d.ts").map(e=>g(e));if(D(s)){i.length||i.push(s);const e=s.replace(d,n).replace(p,".js").replace(m,".js");o.log("Cleaning emitted file:",{outfile:e}),T(e,{force:!0})}else o.log("Cleaning old output:",{outDir:n}),T(n,{force:!0,recursive:!0});console.log();const w=i.filter(e=>p.test(e)).filter(e=>!m.test(e));o.log("Compiling TS files:",{tsFiles:w}),await h({...y,entryPoints:w.filter(e=>!e.endsWith(".d.ts"))}),a("Built TS files.").succeed();const S=i.filter(e=>m.test(e));o.log("Compiling TSX files:",{tsxFiles:S}),await h({...y,entryPoints:S.filter(e=>!e.endsWith(".d.ts")),jsxFactory:"createElement",banner:{js:`import { createElement } from "react";
2
- `}}),a("Built TSX files.").succeed();const j=i.filter(e=>!A.test(e));if(o.log("Copying non-JS/TS files.",{allFiles:i,nonJsTsFiles:j}),await Promise.all(j.map(async e=>{const l=b(r,e).replace(d,n).replace(p,".js").replace(m,".js");o.log("Copying non-source file:",{file:e,outfile:l}),W(B(l),{recursive:!0}),x(l,k(e),{encoding:"binary",flag:"w"})})),!process.env.NO_REWRITES){const e=s.replace(d,n).replace(/^(\.\/)?src\//,"dist/").replace(p,".js").replace(m,".js");await M(e.endsWith(".js")?e:`${e}.js`),a("Normalized import specifiers.").succeed()}if(R()&&a('Forced "type": "module" in output.').succeed(),console.log(),!(t||f)){if(J(b("src","styles","components","index.css"))){o.log("Build minified component styles from styles/components.");const e=await G(),{style:l="./dist/styles.css"}=e,O=["npx tailwindcss",t?"":"-m","--postcss postcss.config.js","-i src/styles/components/index.css","-o",l];await F.run(O.join(" "))}E("Running post-build setup."),u(`Generating type declarations.
3
- This might take a moment.`),L(i),a(`Generated delcarations for ${i.length} files.`).succeed(),u(c.green("Build complete."))}};export{E as bannerLog,z as build};
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};
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- var r="@tsmodule/tsmodule",a="module",m="19.0.0",d="tsmodule/tsmodule",s="TypeScript Module loader and compiler",l="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/"],v={node:">=14"},g={bootstrap:"node bootstrap.js",bootload:"node --no-warnings --loader ./dist/loader/index.js src/index.ts build -f",prebuild:"yarn bootstrap && yarn bootload && yarn link -f",build:"tsmodule build",dev:"tsmodule dev",lint:"eslint --fix src",prepare:"yarn build -f",prepublishOnly:"yarn build && yarn test",pretest:"yarn build -f",test:"ava --no-worker-threads"},h={"@types/glob":"^7.2.0","@types/node":"^17.0.15","@typescript-eslint/eslint-plugin":"^5.9.1","@typescript-eslint/parser":"^5.9.1",ava:"^4.0.1","await-shell":"^29.0.1-0",chalk:"^5.0.0",commander:"^8.3.0","create-debug-logger":"^1.10.1",esbuild:"^0.14.0",eslint:"^8.8.0","fast-glob":"^3.2.10","fs-extra":"^10.0.0",glob:"^7.2.0","node-watch":"^0.7.3",ora:"^6.0.1",path:"^0.12.7",typescript:"^4.5.5"},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"]},y={"@types/fs-extra":"^9.0.13"},t={name:r,type:a,version:m,repository:d,description:s,license:l,bin:c,exports:p,types:u,contributors:f,files:b,engines:v,scripts:g,dependencies:h,keywords:S,ava:w,devDependencies:y};import e from"chalk";import{Command as T}from"commander";import{build as B}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 x}from"./commands/normalize/index.js";const{version:A}=t,i=new T;i.name(e.white(e.bold("tsmodule"))).usage(e.white(e.bold("<file | command> [options]"))).description(e.blueBright(`A tool for building TypeScript modules.
2
+ var r="@tsmodule/tsmodule",s="module",m="21.0.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.15","@typescript-eslint/eslint-plugin":"^5.9.1","@typescript-eslint/parser":"^5.9.1",ava:"^4.0.1","await-shell":"^30.0.0",chalk:"^5.0.0",commander:"^8.3.0","create-debug-logger":"^1.10.1",esbuild:"^0.14.0",eslint:"^8.8.0","fast-glob":"^3.2.10","fs-extra":"^10.0.0",glob:"^7.2.0","node-watch":"^0.7.3",ora:"^6.0.1",path:"^0.12.7",typescript:"^4.5.5"},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.
3
3
 
4
- Run TS directly: ${e.bold("tsmodule src/index.ts")}
5
- Use a command: ${e.bold("tsmodule build")}`)).version(String(A)),i.command("dev").description("Build and watch for changes.").action(R),i.command("build").option("--files <files>","The files to build (default: all)").option("-d, --dev","Build development version").option("-f, --fast","Do not emit type declarations, only transform to JS").description("Builds TS files to output in dist/.").action(B),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 x(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);
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);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tsmodule/tsmodule",
3
3
  "type": "module",
4
- "version": "19.0.0",
4
+ "version": "21.0.0",
5
5
  "repository": "tsmodule/tsmodule",
6
6
  "description": "TypeScript Module loader and compiler",
7
7
  "license": "MIT",
@@ -30,14 +30,14 @@
30
30
  },
31
31
  "scripts": {
32
32
  "bootstrap": "node bootstrap.js",
33
- "bootload": "node --no-warnings --loader ./dist/loader/index.js src/index.ts build -f",
33
+ "bootload": "node --no-warnings --loader ./dist/loader/index.js src/index.ts build -r",
34
34
  "prebuild": "yarn bootstrap && yarn bootload && yarn link -f",
35
35
  "build": "tsmodule build",
36
36
  "dev": "tsmodule dev",
37
37
  "lint": "eslint --fix src",
38
- "prepare": "yarn build -f",
38
+ "prepare": "yarn build -r",
39
39
  "prepublishOnly": "yarn build && yarn test",
40
- "pretest": "yarn build -f",
40
+ "pretest": "yarn build -r",
41
41
  "test": "ava --no-worker-threads"
42
42
  },
43
43
  "dependencies": {
@@ -46,7 +46,7 @@
46
46
  "@typescript-eslint/eslint-plugin": "^5.9.1",
47
47
  "@typescript-eslint/parser": "^5.9.1",
48
48
  "ava": "^4.0.1",
49
- "await-shell": "^29.0.1-0",
49
+ "await-shell": "^30.0.0",
50
50
  "chalk": "^5.0.0",
51
51
  "commander": "^8.3.0",
52
52
  "create-debug-logger": "^1.10.1",
@@ -17,7 +17,7 @@
17
17
  "build": "tsmodule build",
18
18
  "test": "ava",
19
19
  "lint": "eslint src --fix",
20
- "pretest": "tsmodule build -f",
20
+ "pretest": "tsmodule build -r",
21
21
  "prepublishOnly": "yarn build && yarn test"
22
22
  },
23
23
  "ava": {