@tsmodule/tsmodule 17.1.0 → 18.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.
package/README.md
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
import{
|
2
|
-
`}}),c("Built TSX files.").succeed();const
|
3
|
-
This might take a moment.`),$(
|
1
|
+
import{dirname as N,extname as O,isAbsolute as x,resolve as D,resolve as d}from"path";import{build as T}from"esbuild";import{existsSync as P,mkdirSync as B,readFileSync as h,rmSync as w,writeFileSync as J}from"fs";import l from"chalk";import{env as k}from"process";import C from"fast-glob";import c from"ora";import{createDebugLogger as v,log as g}from"create-debug-logger";import{isJsOrTs as W,isTs as m,isTsxOrJsx as a}from"../../utils/index.js";import{emitTsDeclarations as $}from"./lib/emitTsDeclarations.js";import{getPackageJsonFile as G}from"../../utils/pkgJson.js";import{normalizeImportSpecifiers as _}from"../normalize/index.js";const E=t=>{const o=` ${t} `;g(l.bgBlue(l.bold(l.white(o))))},A=()=>{let t;if(P("dist/package.json")?t=JSON.parse(h("dist/package.json","utf-8")):t={},t?.module==="module")return!0;t.type="module",J("dist/package.json",JSON.stringify(t,null,2))},I=async({files:t="src/**/*",dev:o=!1,fast:f=!1})=>{k.NODE_ENV=o?"development":"production";const r=v(I);r.log("Building",{files:t,dev:o,fast:f}),E(`${l.bold("TS Module")} [${k.NODE_ENV}]`);const F=await G(),i=process.cwd(),y={absWorkingDir:i,outbase:"src",outdir:"dist",assetNames:"[name].js",logLevel:o?"warning":"error",charset:"utf8",format:"esm",target:"esnext",minify:!o,define:{PACKAGE_JSON:F}},p=d(i,"src"),n=d(i,"dist"),s=C.sync(t,{cwd:i}).filter(e=>O(e)!==".d.ts").map(e=>d(e));if(x(t)){s.length||s.push(t);const e=t.replace(p,n).replace(m,".js").replace(a,".js");r.log("Cleaning emitted file:",{outfile:e}),w(e,{force:!0})}else r.log("Cleaning old output:",{outDir:n}),w(n,{force:!0,recursive:!0});console.log();const S=s.filter(e=>m.test(e)).filter(e=>!a.test(e));r.log("Compiling TS files:",{tsFiles:S}),await T({...y,entryPoints:S.filter(e=>!e.endsWith(".d.ts"))}),c("Built TS files.").succeed();const b=s.filter(e=>a.test(e));r.log("Compiling TSX files:",{tsxFiles:b}),await T({...y,entryPoints:b.filter(e=>!e.endsWith(".d.ts")),jsxFactory:"createElement",banner:{js:`import { createElement } from "react";
|
2
|
+
`}}),c("Built TSX files.").succeed();const j=s.filter(e=>!W.test(e));if(r.log("Copying non-JS/TS files.",{allFiles:s,nonJsTsFiles:j}),await Promise.all(j.map(async e=>{const u=D(i,e).replace(p,n).replace(m,".js").replace(a,".js");r.log("Copying non-source file:",{file:e,outfile:u}),B(N(u),{recursive:!0}),J(u,h(e),{encoding:"binary",flag:"w"})})),!process.env.NO_REWRITES){const e=t.replace(p,n).replace(/^(\.\/)?src\//,"dist/").replace(m,".js").replace(a,".js");await _(e.endsWith(".js")?e:`${e}.js`),c("Normalized import specifiers.").succeed()}A()&&c('Forced "type": "module" in output.').succeed(),console.log(),!(o||f)&&(E("Running post-build setup."),g(`Generating type declarations.
|
3
|
+
This might take a moment.`),$(s),c(`Generated delcarations for ${s.length} files.`).succeed(),g(l.green("Build complete.")))};export{E as bannerLog,I as build};
|
@@ -1 +1 @@
|
|
1
|
-
import
|
1
|
+
import a from"chalk";import{createShell as c}from"await-shell";import d from"ora";import{createTemplate as o}from"./lib/createTemplate.js";import{rewritePkgJson as l}from"./lib/rewritePkgJson.js";globalThis.SHELL_OPTIONS={stdio:["ignore","ignore","inherit"]};const w=async(e,{react:n=!1})=>{const t=c(),i=d(`Creating new module ${a.blueBright(e)}.`).start();await o("default",e),n&&await o("react",e),await l(e),i.succeed("Project created."),process.chdir(e);const r=[],s=["@tsmodule/tsmodule"];n&&(r.push("react","react-dom"),s.push("@types/react","@types/react-dom","next","eslint-config-next","tailwindcss","postcss","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,3 +1,3 @@
|
|
1
|
-
import{
|
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(`
|
2
2
|
`,r.gray(`Built ${r.bold(t)}.`),`
|
3
|
-
`,r.blue(new Date().toLocaleString()))},
|
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};
|
package/dist/index.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
|
-
var r="@tsmodule/tsmodule",a="module",m="
|
2
|
+
var r="@tsmodule/tsmodule",a="module",m="18.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.
|
3
3
|
|
4
4
|
Run TS directly: ${e.bold("tsmodule src/index.ts")}
|
5
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.
|