@tsmodule/tsmodule 23.0.3 → 23.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/commands/build/index.js +4 -4
- package/dist/index.js +1 -1
- package/package.json +1 -1
@@ -1,6 +1,6 @@
|
|
1
|
-
import{dirname as
|
1
|
+
import{dirname as D,extname as v,isAbsolute as W,resolve as N,resolve as u}from"path";import{build as O}from"esbuild";import{existsSync as x,mkdirSync as G,readFileSync as g,rmSync as B,writeFileSync as C}from"fs";import m from"chalk";import{env as E}from"process";import M from"fast-glob";import p from"ora";import{createDebugLogger as _,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 z}from"../../utils/pkgJson.js";import{normalizeImportSpecifiers as V}from"../normalize/index.js";const P=s=>{const c=` ${s} `;y(m.bgBlue(m.bold(m.white(c))))},X=()=>{let s;if(x("dist/package.json")?s=JSON.parse(g("dist/package.json","utf-8")):s={},s?.module==="module")return!0;s.type="module",C("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})=>{E.NODE_ENV=i?"development":"production";const F=I(),t=_(K);t.log("Building",{files:s,dev:i,runtimeOnly:w}),P(`${m.bold("TS Module")} [${E.NODE_ENV}]`);const h=await z(),j=JSON.parse(h),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:j?.platform??"node",minify:!i,define:{PACKAGE_JSON:h}},d=u(a,"src"),r=u(a,"dist"),o=M.sync(s,{cwd:a}).filter(e=>v(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}),B(e,{force:!0})}else t.log("Cleaning old output:",{outDir:r}),B(r,{force:!0,recursive:!0});console.log();const T=o.filter(e=>f.test(e)).filter(e=>!l.test(e));t.log("Compiling TS files:",{tsFiles:T}),await O({...J,entryPoints:T.filter(e=>!e.endsWith(".d.ts"))}),p("Built TS files.").succeed();const b=o.filter(e=>l.test(e));t.log("Compiling TSX files:",{tsxFiles:b});const $=b.filter(e=>!e.endsWith(".d.ts"));await Promise.all($.map(async e=>{const n=`
|
2
2
|
import React from "react";
|
3
3
|
import ReactDOM from "react-dom";
|
4
|
-
${
|
5
|
-
`;await
|
6
|
-
This might take a moment.`),
|
4
|
+
${g(e,"utf-8")}
|
5
|
+
`;await O({...J,stdin:{contents:n,sourcefile:e,resolveDir:D(e),loader:"tsx"},outdir:void 0,outfile:e.replace(l,".js").replace(d,r),jsxFactory:"React.createElement"})})),p("Built TSX files.").succeed();const k=o.filter(e=>!A.test(e));if(t.log("Copying non-JS/TS files.",{allFiles:o,nonJsTsFiles:k}),await Promise.all(k.map(async e=>{const n=N(a,e).replace(d,r).replace(f,".js").replace(l,".js");t.log("Copying non-source file:",{file:e,outfile:n}),G(D(n),{recursive:!0}),C(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 V(e.endsWith(".js")?e:`${e}.js`),p("Normalized import specifiers.").succeed()}if(X()&&p('Forced "type": "module" in output.').succeed(),console.log(),!(i||w)){if(x(N(c))){t.log("Building styles for production.");const{style:e="./dist/styles.css"}=j,R=["npx tailwindcss",i?"":"-m","--postcss postcss.config.js",`-i ${c}`,"-o",e];await F.run(R.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),p(`Generated delcarations for ${o.length} files.`).succeed(),y(m.green("Build complete."))}};export{P as bannerLog,K as build};
|
package/dist/index.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
|
-
var r="@tsmodule/tsmodule",s="node",d="module",m="23.0
|
2
|
+
var r="@tsmodule/tsmodule",s="node",d="module",m="23.1.0",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
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.
|