@tsmodule/tsmodule 27.0.3 → 28.3.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,4 +1,4 @@
|
|
|
1
|
-
import{dirname as
|
|
1
|
+
import{dirname as R,extname as K,isAbsolute as U,resolve as F,resolve as v}from"path";import{build as h,transform as q}from"esbuild";import{existsSync as _,mkdirSync as H,readFileSync as j,rmSync as $,writeFileSync as L}from"fs";import c from"chalk";import{env as M}from"process";import Q from"fast-glob";import m from"ora";import{createDebugLogger as Y,log as y}from"create-debug-logger";import{isJsOrTs as A,isTs as S,isTsxOrJsx as p}from"../../utils/resolve.js";import{createShell as Z}from"await-shell";import{emitTsDeclarations as ee}from"./lib/emitTsDeclarations.js";import{normalizeImportSpecifiers as te}from"../normalize/index.js";import{getPackageJsonFile as oe}from"../../utils/pkgJson.js";import{getWorkingDirs as G}from"../../utils/cwd.js";import{readStdin as se}from"../../utils/stdin.js";const ie=`import React from "react";
|
|
2
2
|
import ReactDOM from "react-dom";
|
|
3
|
-
`,
|
|
4
|
-
This might take a moment.`),
|
|
3
|
+
`,I=t=>{const o=` ${t} `;y(c.bgBlue(c.bold(c.white(o))))},ne=()=>{let t;if(_("dist/package.json")?t=JSON.parse(j("dist/package.json","utf-8")):t={},t?.module==="module")return!0;t.type="module",L("dist/package.json",JSON.stringify(t,null,2))},V=(t,o,f)=>{const{srcDir:i,outDir:O}=G();return o=v(o),{stdin:{contents:t,sourcefile:o,resolveDir:R(o),loader:f},outdir:void 0,outfile:o.replace(A,".js").replace(i,O)}},re=async({files:t="src/**/*",styles:o="src/styles/components/index.css",bundle:f=!1,dev:i=!1,target:O="esnext",runtimeOnly:w=!1,noWrite:d=!1,stdin:l="",stdinFile:u=""})=>{M.NODE_ENV=i?"development":"production";const s=Y(re),W=Z(),{cwd:b,srcDir:T,outDir:a}=G(),C=await oe(),J=JSON.parse(C),k={treeShaking:f,target:O,minify:!i,format:"esm",charset:"utf8",logLevel:i?"warning":"error",define:{PACKAGE_JSON:C,"process.env.NODE_ENV":i?JSON.stringify("development"):JSON.stringify("production")}},x={...k,bundle:f,absWorkingDir:b,outbase:"src",outdir:"dist",assetNames:"[name].js",format:"esm",target:"esnext",platform:J?.platform??"node",write:!d};let g="";if(l){s.log("Building file from stdin",{stdin:l,stdinFile:u,noWrite:d}),!d&&!u&&(y(c.red("ERROR: --stdin-file must be specified when using stdin in write mode.")),process.exit(1)),typeof l=="string"&&l.length?g=l:g=await se();const e={...k,sourcefile:u,loader:"tsx",banner:void 0,footer:void 0};if(d)return(await q(g,e)).code;{const n=V(g,u,"tsx");return await h({...x,...n})}}s.log("Building",{files:t,dev:i,runtimeOnly:w}),I(`${c.bold("TS Module")} [${M.NODE_ENV}]`);const r=Q.sync(t,{cwd:b}).filter(e=>K(e)!==".d.ts").map(e=>v(e));if(U(t)){r.length||r.push(t);const e=t.replace(T,a).replace(S,".js").replace(p,".js");s.log("Cleaning emitted file:",{outfile:e}),$(e,{force:!0})}else s.log("Cleaning old output:",{outDir:a}),$(a,{force:!0,recursive:!0});console.log();const D=r.filter(e=>S.test(e)).filter(e=>!p.test(e));s.log("Compiling TS files:",{tsFiles:D}),await h({...x,entryPoints:D.filter(e=>!e.endsWith(".d.ts"))}),m("Built TS files.").succeed();const N=r.filter(e=>p.test(e));s.log("Compiling TSX files:",{tsxFiles:N});const z=N.filter(e=>!e.endsWith(".d.ts"));await Promise.all(z.map(async e=>{const n=j(e,"utf-8"),B=ie+n,P=V(B,e,"tsx");await h({...x,...P,jsxFactory:"React.createElement"})})),m("Built TSX files.").succeed();const E=r.filter(e=>!A.test(e));if(s.log("Copying non-JS/TS files.",{allFiles:r,nonJsTsFiles:E}),await Promise.all(E.map(async e=>{const n=F(b,e).replace(T,a).replace(S,".js").replace(p,".js");s.log("Copying non-source file:",{file:e,outfile:n}),H(R(n),{recursive:!0}),L(n,j(e),{encoding:"binary",flag:"w"})})),!process.env.NO_REWRITES){const e=t.replace(T,a).replace(/^(\.\/)?src\//,"dist/").replace(S,".js").replace(p,".js");await te(e.endsWith(".js")?e:`${e}.js`),m("Normalized import specifiers.").succeed()}if(ne()&&m('Forced "type": "module" in output.').succeed(),console.log(),!(i||w)){if(_(F(o))){s.log("Building styles for production.");const{style:e="./dist/styles.css"}=J,X=["npx tailwindcss",i?"":"-m","--postcss postcss.config.js",`-i ${o}`,"-o",e];await W.run(X.join(" "))}else s.log("Styles not found.",{styles:o});I("Running post-build setup."),y(`Generating type declarations.
|
|
4
|
+
This might take a moment.`),ee(r),m(`Generated delcarations for ${r.length} files.`).succeed(),y(c.green("Build complete."))}};export{I as bannerLog,re as build};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import a from"chalk";import{createShell as c}from"await-shell";import d from"ora";import{
|
|
1
|
+
import a from"chalk";import{createShell as c}from"await-shell";import d from"ora";import{copyTemplate as n}from"./lib/createTemplate.js";import{rewritePkgJson as l}from"./lib/rewritePkgJson.js";globalThis.SHELL_OPTIONS={stdio:["ignore","ignore","inherit"]};const w=async(e,{react:o=!1})=>{const i=c(),s=d(`Creating new module ${a.blueBright(e)}.`).start();await n("default",e),o&&await n("react",e),await l(e),s.succeed("Project created."),process.chdir(e);const r=[],t=["@tsmodule/tsmodule"];o?(r.push("react","react-dom"),t.push("@types/react","@types/react-dom","next","eslint","eslint-config-next","tailwindcss","postcss","postcss-import","autoprefixer")):t.push("@types/node"),r.length&&await i.run(`yarn add ${r.join(" ")}`),t.length&&await i.run(`yarn add -D ${t.join(" ")}`),s.succeed("Dependencies installed."),await i.run("git init"),s.succeed("Git initialized.")};export{w as create};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{fileURLToPath as m,URL as p}from"url";import{copy as s}from"fs-extra";import{resolve as
|
|
1
|
+
import{fileURLToPath as m,URL as p}from"url";import{copy as s}from"fs-extra";import{resolve as c}from"path";const w=async(t,e)=>{const r=process.cwd(),o=new p(`../../../../templates/${t}`,import.meta.url);await s(m(o),c(r,e),{overwrite:!0,recursive:!0})};export{w as copyTemplate};
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var r="@tsmodule/tsmodule",s="node",
|
|
2
|
+
var r="@tsmodule/tsmodule",s="node",a="module",d="28.3.0",m="tsmodule/tsmodule",l="TypeScript Module loader and compiler",p="MIT",c={tsmodule:"dist/index.js"},u={".":"./dist/loader/index.js","./*":"./dist/*/index.js","./package.json":"./package.json"},f="dist/types/index.d.ts",g=[{name:"C. Lewis",email:"ctj.lewis@icloud.com",url:"https://ctjlewis.com"}],b=["dist/","templates/"],y={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",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":"^32.0.0",chalk:"^5.0.1",commander:"^9.0.0","create-debug-logger":"^3.0.0",esbuild:"^0.14.25",eslint:"^8.11.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"]},R={"@types/fs-extra":"^9.0.13"},n={name:r,platform:s,type:a,version:d,repository:m,description:l,license:p,bin:c,exports:u,types:f,contributors:g,files:b,engines:y,scripts:h,dependencies:v,keywords:w,ava:S,devDependencies:R};import t from"chalk";import{Command as x}from"commander";import{build as B}from"./commands/build/index.js";import{create as C}from"./commands/create/index.js";import{dev as E}from"./commands/dev/index.js";import{execute as T}from"./commands/execute/index.js";import{normalizeImportSpecifiers as A}from"./commands/normalize/index.js";const{version:j}=n,o=new x;o.name(t.white(t.bold("tsmodule"))).usage(t.white(t.bold("<file | command> [options]"))).description(t.blueBright(`A tool for building TypeScript modules.
|
|
3
3
|
|
|
4
|
-
Run TS directly: ${
|
|
5
|
-
Use a command: ${
|
|
6
|
-
|
|
4
|
+
Run TS directly: ${t.bold("tsmodule src/index.ts")}
|
|
5
|
+
Use a command: ${t.bold("tsmodule build")}`)).version(String(j)),o.command("dev").description("Build and watch for changes.").action(E),o.command("build").option("--files <files>","Entrypoints to compile.\r","src/**/*").option("--styles <styles>","Specify stylesheet entrypoint.\r","src/styles/components/index.css").option("-t, --target <target>","ECMAScript featureset to target.\r","esnext").option("-b, --bundle","Bundle dependencies into entrypoints.\r",!1).option("-d, --dev","Build development runtime.\r",!1).option("-r, --runtime-only","Do not emit type declarations, only build JS runtime.\r",!1).option("--stdin [source]","Read from a string or stdin.").option("--stdin-file [file]","File path to mock for stdin.").option("--no-write",`Return code from build() rather than write to disk.
|
|
6
|
+
For programmatic use alongside { stdin: ... }.`).description("Builds TS files to output in dist/.").action(async i=>{await B(i)}),o.command("create <name>").option("--react","Create React component library with Next.js").description("Create a new project.").action(C),o.command("normalize [files]").description(`Rewrites import specifiers in files to ESM-compliant paths.
|
|
7
|
+
(default: dist/**/*.js)`).action(async({files:i})=>{await A(i)}),o.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(T),o.parse(process.argv);
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@tsmodule/tsmodule",
|
|
3
3
|
"platform": "node",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "
|
|
5
|
+
"version": "28.3.0",
|
|
6
6
|
"repository": "tsmodule/tsmodule",
|
|
7
7
|
"description": "TypeScript Module loader and compiler",
|
|
8
8
|
"license": "MIT",
|
|
@@ -48,12 +48,12 @@
|
|
|
48
48
|
"@typescript-eslint/eslint-plugin": "^5.14.0",
|
|
49
49
|
"@typescript-eslint/parser": "^5.14.0",
|
|
50
50
|
"ava": "^4.1.0",
|
|
51
|
-
"await-shell": "^
|
|
51
|
+
"await-shell": "^32.0.0",
|
|
52
52
|
"chalk": "^5.0.1",
|
|
53
53
|
"commander": "^9.0.0",
|
|
54
54
|
"create-debug-logger": "^3.0.0",
|
|
55
55
|
"esbuild": "^0.14.25",
|
|
56
|
-
"eslint": "^8.
|
|
56
|
+
"eslint": "^8.11.0",
|
|
57
57
|
"fast-glob": "^3.2.10",
|
|
58
58
|
"fs-extra": "^10.0.1",
|
|
59
59
|
"glob": "^7.2.0",
|
|
@@ -1,5 +1,35 @@
|
|
|
1
|
-
|
|
1
|
+
# `tsmodule` library
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This is a [`tsmodule`](https://github.com/tsmodule/tsmodule) library. By
|
|
4
|
+
default, it is assumed to be a Node program, but this can be adjusted via the
|
|
5
|
+
`platform` field in package.json.
|
|
6
|
+
|
|
7
|
+
### Develop
|
|
8
|
+
|
|
9
|
+
Rebuild on changes with `tsmodule dev` or the `yarn dev` script:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
yarn dev
|
|
13
|
+
# calls `tsmodule dev`
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### Export and publish
|
|
17
|
+
|
|
18
|
+
To export your component library, use `tsmodule build` or the `yarn build`
|
|
19
|
+
script:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
4
22
|
yarn build
|
|
5
|
-
|
|
23
|
+
# calls `tsmodule build`
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
You can then publish to NPM:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
yarn publish
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
#### Importing from your library
|
|
33
|
+
|
|
34
|
+
All index exports, e.g. `src/example/index.tsx` will be available downstream
|
|
35
|
+
via `import ... from "my-library/example"`.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# `tsmodule` component library
|
|
2
|
+
|
|
3
|
+
This is a [`tsmodule`](https://github.com/tsmodule/tsmodule) component library
|
|
4
|
+
developed and previewed with Next.js.
|
|
5
|
+
|
|
6
|
+
### Develop
|
|
7
|
+
|
|
8
|
+
To start the Next server and develop your components, use `next dev` or the
|
|
9
|
+
`yarn dev` script:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
yarn dev
|
|
13
|
+
# calls `next dev`
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### Export and publish
|
|
17
|
+
|
|
18
|
+
To export your component library, use `tsmodule build` or the `yarn export`
|
|
19
|
+
script:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
yarn export
|
|
23
|
+
# calls `tsmodule build`
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
You can then publish to NPM:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
yarn publish
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
#### Importing from your component library
|
|
33
|
+
|
|
34
|
+
To reuse your components:
|
|
35
|
+
|
|
36
|
+
1. Import your component styles via `import "my-library/styles"`.
|
|
37
|
+
2. Import your component and render it via `import { MyComponent } from
|
|
38
|
+
"my-library/MyComponent`.
|
|
39
|
+
|
|
40
|
+
#### Footnotes
|
|
41
|
+
|
|
42
|
+
Styles are exported in `dist/`, and are also bundled to `dist/styles.css` from
|
|
43
|
+
the entrypoint given in the `style` package.json.
|
|
44
|
+
|
|
45
|
+
The default behavior is to export all component styles, i.e.
|
|
46
|
+
`src/styles/components/index.css ➞ dist/styles.css`. This can be overridden
|
|
47
|
+
with tsmodule's `--styles` flag, i.e. `tsmodule build --styles
|
|
48
|
+
src/styles/index.css` (which would include all styles in emitted bundle).
|