@tsmodule/tsmodule 30.0.7 → 31.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/dist/commands/build/index.js +7 -3
- package/dist/commands/create/lib/createTemplate.js +1 -1
- package/dist/commands/dev/index.js +2 -2
- package/dist/commands/execute/index.js +1 -1
- package/dist/commands/normalize/index.js +3 -3
- package/dist/constants.js +1 -1
- package/dist/index.js +4 -4
- package/dist/utils/cwd.js +1 -1
- package/dist/utils/require.js +1 -0
- package/package.json +23 -8
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import{dirname as
|
|
1
|
+
import{dirname as I,extname as z,isAbsolute as V,resolve as X,resolve as O}from"path";import{build as J,transform as H}from"esbuild";import{existsSync as M,mkdirSync as K,readFileSync as S,rmSync as A,writeFileSync as _}from"fs";import r from"chalk";import{env as L}from"process";import W from"fast-glob";import c from"ora";import{createDebugLogger as Q,log as m}from"create-debug-logger";import{createShell as Y}from"await-shell";import{getEmittedFile as j,getWorkingDirs as Z}from"../../utils/cwd.js";import{isJsOrTs as ee,isTs as k,isTsxOrJsx as x}from"../../utils/resolve.js";import{emitTsDeclarations as te}from"./lib/emitTsDeclarations.js";import{getPackageJsonFile as se}from"../../utils/pkgJson.js";import{normalizeImportSpecifiers as oe}from"../normalize/index.js";import{readStdin as ie}from"../../utils/stdin.js";const ne=`import React from "react";
|
|
2
2
|
import ReactDOM from "react-dom";
|
|
3
|
-
`,
|
|
4
|
-
|
|
3
|
+
`,v=t=>{const s=` ${t} `;m(r.bgBlue(r.bold(r.white(s))))},re=()=>{let t;if(M("dist/package.json")?t=JSON.parse(S("dist/package.json","utf-8")):t={},t?.module==="module")return!0;t.type="module",_("dist/package.json",JSON.stringify(t,null,2))},G=(t,s,g)=>{s=O(s);const i=j(s);return{stdin:{contents:t,sourcefile:s,resolveDir:I(s),loader:g},outdir:void 0,outfile:i}},U=async(t,s,g,i)=>{t=O(t),s=O(s);const l="npx tailwindcss",p=g?"":"-m",b="--postcss postcss.config.js",d=S(t,"utf-8"),u=i?d:`@import "@tsmodule/react";
|
|
4
|
+
|
|
5
|
+
${d}`,o=j(t);_(o,u);const y=[l,p,b,`-i ${o}`,"-o",s];await Y({log:!1,stdio:"ignore"}).run(y.join(" "))},le=`
|
|
6
|
+
await(async()=>{let{dirname:e}=await import("path"),{fileURLToPath:i}=await import("url");if(typeof globalThis.__filename>"u"&&(globalThis.__filename=i(import.meta.url)),typeof globalThis.__dirname>"u"&&(globalThis.__dirname=e(globalThis.__filename)),typeof globalThis.require>"u"){let{default:a}=await import("module");globalThis.require=a.createRequire(import.meta.url)}})();
|
|
7
|
+
`,ae=async({input:t="src/**/*",styles:s="src/components/index.css",target:g="esnext",dev:i=!1,bundle:l=!1,runtimeOnly:p=i,noWrite:b=!1,noStandardStyles:d=!1,stdin:f,stdinFile:u})=>{L.NODE_ENV=i?"development":"production";const o=Q(ae);i&&(p=!0);const{cwd:y,srcDir:C,outDir:h}=Z(),N=await se(),R=JSON.parse(N),P={treeShaking:l,target:g,minify:!i,jsx:"transform",jsxFactory:"React.createElement",format:"esm",charset:"utf8",logLevel:i?"warning":"error",define:{PACKAGE_JSON:N,"process.env.NODE_ENV":i?JSON.stringify("development"):JSON.stringify("production")}},B={...P,bundle:l,absWorkingDir:y,outbase:"src",outdir:"dist",assetNames:"[name].js",format:"esm",target:"esnext",platform:R?.platform??"node",write:!b,external:l?["esbuild"]:void 0,banner:l?{js:le}:void 0};let w="";if(f){o.log("Building file from stdin",{stdin:f,stdinFile:u,noWrite:b}),u||(m(r.red("ERROR: --stdin-file must be specified to emulate a file location when using stdin.")),process.exit(1)),typeof f=="string"&&f.length?w=f:w=await ie();const e={...P,sourcefile:u,loader:"tsx",banner:void 0,footer:void 0};if(b)return(await H(w,e)).code;{const n=G(w,u,"tsx");await J({...B,...n}),m(r.green("Successfully built stdin file to dist/.")),m(r.grey("Use --no-write to print to stdout instead."));return}}o.log("Building",{files:t,dev:i,runtimeOnly:p}),v(`${r.bold("TS Module")} [${L.NODE_ENV}]`);const a=W.sync(t,{cwd:y}).filter(e=>z(e)!==".d.ts").map(e=>O(e));if(V(t)){a.length||a.push(t);const e=t.replace(C,h).replace(k,".js").replace(x,".js");o.log("Cleaning emitted file:",{outfile:e}),A(e,{force:!0})}else o.log("Cleaning old output:",{outDir:h}),A(h,{force:!0,recursive:!0});console.log();const D=a.filter(e=>x.test(e));o.log("Compiling TSX files:",{tsxFiles:D});const q=D.filter(e=>!e.endsWith(".d.ts"));await Promise.all(q.map(async e=>{const n=S(e,"utf-8"),E=ne+n,T=G(E,e,"tsx");await J({...B,...T})})),c("Built TSX files.").succeed();const F=a.filter(e=>k.test(e)).filter(e=>!x.test(e));o.log("Compiling TS files:",{tsFiles:F}),await J({...B,entryPoints:F.filter(e=>!e.endsWith(".d.ts"))}),c("Built TS files.").succeed();const $=a.filter(e=>!ee.test(e));if(o.log("Copying non-JS/TS files.",{allFiles:a,nonJsTsFiles:$}),await Promise.all($.map(async e=>{const n=j(e);o.log("Copying non-source file:",{file:e,emittedFile:n}),K(I(n),{recursive:!0}),_(n,S(e),{encoding:"binary",flag:"w"})})),!process.env.NO_REWRITES){const e=t.replace(C,h).replace(/^(\.\/)?src\//,"dist/").replace(k,".js").replace(x,".js");o.log("Normalizing import specifiers in emitted JS.",{emittedJs:e}),await oe(e.endsWith(".js")?e:`${e}.js`),c("Normalized import specifiers.").succeed()}if(re()&&c('Forced "type": "module" in output.').succeed(),!p){if(M(X(s))){o.log("Building styles for production.");const{style:e="./dist/bundle.css"}=R;if(o.log("Building style bundle.",{bundleInput:s,bundleOutput:e,dev:i,noStandardStyles:d}),await U(s,e,i,d),l){o.log("Bundling all styles.");const n=W.sync("dist/**/*.css"),E=c("Bundled emitted styles.").start();await Promise.all(n.map(async T=>await U(T,T,i,d))),E.succeed()}c(`Bundled all styles to ${r.bold(e)}.`).succeed()}else m(r.grey("Bundle styles not found for this projected. Checked:"),{styles:s});v("Running post-build setup."),m(`Generating type declarations.
|
|
8
|
+
This might take a moment.`),te(a),c(`Generated delcarations for ${a.length} files.`).succeed(),m(r.green("Build complete."))}};export{v as bannerLog,ae as build};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{PACKAGE_ROOT as m}from"../../../constants.js";import{copy as s}from"fs-extra";import{resolve as t}from"path";const l=async(r,e)=>{const o=t(m,`./templates/${r}`),p=t(e);await s(o,p,{overwrite:!0,recursive:!0})};export{l as copyTemplate};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{existsSync as
|
|
1
|
+
import{existsSync as l,lstatSync as m}from"fs";import{relative as p,resolve as u}from"path";import{build as s}from"../build/index.js";import r from"chalk";import{createShell as f}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()))},O=async()=>{const t=process.cwd(),c=
|
|
3
|
+
`,r.blue(new Date().toLocaleString()))},O=async()=>{const t=process.cwd(),c=f();process.platform!=="win32"&&await c.run("clear"),o(),await s({dev:!0}),i("src/**/*"),v(u(t,"src"),{recursive:!0}).on("change",async(D,e)=>{if(!l(e)||m(e).isDirectory())return;o();const n=Date.now();await s({dev:!0,input:e});const a=Date.now()-n;w(r.blueBright(`Dev refresh finished in ${r.bold(`${a}ms`)}.`)).succeed(),i(p(t,e))})};export{O as dev};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{createShell as r}from"await-shell";import{pathToFileURL as s}from"url";import{resolve as t}from"path";import{PACKAGE_ROOT as n}from"../../constants.js";const p=async()=>{const o=t(n,"dist/loader/index.js"),e=["--no-warnings","--loader",s(o).href,...process.argv.slice(2)];await r().run(`node ${e.join(" ")}`)};export{p as execute};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{readFileSync as
|
|
2
|
-
\r;]*`,
|
|
3
|
-
]?$`,
|
|
1
|
+
import{existsSync as P,readFileSync as w,writeFileSync as $}from"fs";import{isAbsolute as I,resolve as S}from"path";import y from"fast-glob";import{pathToFileURL as h}from"url";import{createDebugLogger as R}from"create-debug-logger";import{getRewrittenSpecifiers as x}from"./lib/typescriptApi.js";const o=`[^
|
|
2
|
+
\r;]*`,F=`["']${o}['"][;
|
|
3
|
+
]?$`,T=`(import${o}(from)?)`,M=`(import|require)${o}\\(`,A=`(export${o}from)`,O=r=>{const e=r.replace(".","\\.").replace("/","\\/"),i=`${o}["']${e}["']${o}`;return new RegExp(`(${T}|${M}|${A})${i}`,"g")},d=(r,e,i)=>{const n=R(d);n.log("Rewriting import",{importStatement:r,specifierToReplace:e,specifierReplacement:i});const p=new RegExp(F),t=r.match(p);if(!t)throw n.log("No specifier match",{importStatement:r,specifierPattern:p}),new Error(`Could not identify specifier in import statement: ${r}`);const s=t[0],c=s.replace(e,i).trim();return r.replace(s,c)},U=async(r="dist/**/*.js")=>{const e=R(U),n=I(r)&&P(r)?[r]:y.sync(r);e.log("Normalizing import/require specifiers:",{files:r,filesToNormalize:n});for(const p of n){const t=S(p),s=h(t).href,c=x(t);if(!c)return null;e.log("TypeScript API yielded specifiers to rewrite:",{rewrites:c});let m=w(t,"utf8");e.group();for(const{specifierToReplace:l,specifierReplacement:f}of c){const E=O(l),a=m.match(E)??[];e.log("Replacing import statements.",{entryPointURL:s,specifierToReplace:l,specifierReplacement:f,importStatements:a});for(const g of a){e.group();const u=d(g,l,f);e.log("Performing specifier rewrite.",{entryPointURL:s,importStatement:g,rewrittenImportStatement:u}),m=m.replace(g,u),$(t,m),e.log("Wrote output file.",{resolvedEntryPoint:t}),e.groupEnd()}}e.groupEnd()}};export{O as generateImportPattern,U as normalizeImportSpecifiers,d as rewriteImportStatement};
|
package/dist/constants.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
import{dirname as e,resolve as t}from"path";import{fileURLToPath as o}from"url";const n={default:[],react:["@tsmodule/react","react","react-dom"]},a={default:["@types/node"],react:["next","@types/react","@types/react-dom","eslint","eslint-config-next","tailwindcss","autoprefixer","cssnano","postcss","postcss-import"]},p=t(e(o(import.meta.url)),"..");export{p as PACKAGE_ROOT,n as dependencies,a as devDependencies};
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var r="@tsmodule/tsmodule",s="node",a="module",d="
|
|
2
|
+
var r="@tsmodule/tsmodule",s="node",a="module",d="31.0.0",l="tsmodule/tsmodule",m="TypeScript Module loader and compiler",p="MIT",c="dist/types/index.d.ts",u={tsmodule:"dist/index.js"},f={".":"./dist/loader/index.js","./*":"./dist/*/index.js","./package.json":"./package.json"},b=["dist/","templates/"],g={node:">=14"},y={prebootload:"node bootstrap.js",bootload:"node --no-warnings --loader ./dist/loader/index.js src/index.ts build -r",prebuild:"yarn bootload && yarn link -f",build:"tsmodule build",dev:"tsmodule dev",pretest:"yarn build -b",test:"ava --no-worker-threads",retest:"SKIP_TEST_SETUP=1 yarn test",lint:"eslint --fix src",prepare:"yarn build -r",prepublishOnly:"yarn test",release:"release-it major -VV --ci"},h={"@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"},S={"@types/fs-extra":"^9.0.13","eslint-config-next":"^12.1.0","release-it":"^14.12.5"},v={git:{commitMessage:"chore: release v${version}",tagAnnotation:"v${version}"},github:{release:!0,releaseName:"v${version}"}},w={timeout:"10 minutes",files:["test/**/*.test.ts"],extensions:{ts:"module"},nodeArguments:["--no-warnings","--loader=@tsmodule/tsmodule"]},C=["esm","es module","ts module","bundle","loader","typescript","loader hook","require hook","experimental-loader"],R=[{name:"C. Lewis",email:"ctj.lewis@icloud.com",url:"https://ctjlewis.com"}],n={name:r,platform:s,type:a,version:d,repository:l,description:m,license:p,types:c,bin:u,exports:f,files:b,engines:g,scripts:y,dependencies:h,devDependencies:S,"release-it":v,ava:w,keywords:C,contributors:R};import t from"chalk";import{Command as x}from"commander";import{build as B}from"./commands/build/index.js";import{create as E}from"./commands/create/index.js";import{dev as T}from"./commands/dev/index.js";import{execute as A}from"./commands/execute/index.js";import{normalizeImportSpecifiers as j}from"./commands/normalize/index.js";const{version:k}=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
4
|
Run TS directly: ${t.bold("tsmodule src/index.ts")}
|
|
5
|
-
Use a command: ${t.bold("tsmodule build")}`)).version(String(
|
|
6
|
-
For programmatic use alongside { stdin: ... }.`,!1).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(
|
|
7
|
-
(default: dist/**/*.js)`).action(async({files:i})=>{await
|
|
5
|
+
Use a command: ${t.bold("tsmodule build")}`)).version(String(k)),o.command("dev").description("Build and watch for changes.").action(T),o.command("build").description("Builds TS files to output in dist/.").option("-i, --input <files>","Entrypoints to compile.","src/**/*").option("--styles <styles>","Specify stylesheet entrypoint.","src/components/index.css").option("-t, --target <target>","ECMAScript featureset to target.","esnext").option("-b, --bundle","Bundle dependencies into entrypoints.",!1).option("-d, --dev","Build development runtime.",!1).option("-r, --runtime-only","Do not emit type declarations, only build JS runtime.",!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: ... }.`,!1).option("--no-standard-styles","Do not add standard styles to bundled CSS.",!1).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(E),o.command("normalize [files]").description(`Rewrites import specifiers in files to ESM-compliant paths.
|
|
7
|
+
(default: dist/**/*.js)`).action(async({files:i})=>{await j(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(A),o.parse(process.argv);
|
package/dist/utils/cwd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{resolve as o}from"path";const i=()=>{const r=process.cwd(),s=o(r,"src"),t=o(r,"dist");return{cwd:r,srcDir:s,outDir:t}};export{i as getWorkingDirs};
|
|
1
|
+
import{isTs as c,isTsxOrJsx as e}from"./resolve.js";import{resolve as o}from"path";const i=()=>{const r=process.cwd(),s=o(r,"src"),t=o(r,"dist");return{cwd:r,srcDir:s,outDir:t}},D=r=>{r=o(r);const{srcDir:s,outDir:t}=i();return r.replace(s,t).replace(c,".js").replace(e,".js")};export{D as getEmittedFile,i as getWorkingDirs};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
await(async()=>{const{dirname:e}=await import("path"),{fileURLToPath:i}=await import("url");if(typeof globalThis.__filename>"u"&&(globalThis.__filename=i(import.meta.url)),typeof globalThis.__dirname>"u"&&(globalThis.__dirname=e(globalThis.__filename)),typeof globalThis.require>"u"){const{default:a}=await import("module");globalThis.require=a.createRequire(import.meta.url)}})();
|
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": "31.0.0",
|
|
6
6
|
"repository": "tsmodule/tsmodule",
|
|
7
7
|
"description": "TypeScript Module loader and compiler",
|
|
8
8
|
"license": "MIT",
|
|
@@ -23,17 +23,18 @@
|
|
|
23
23
|
"node": ">=14"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
|
-
"
|
|
26
|
+
"prebootload": "node bootstrap.js",
|
|
27
27
|
"bootload": "node --no-warnings --loader ./dist/loader/index.js src/index.ts build -r",
|
|
28
|
-
"prebuild": "yarn
|
|
28
|
+
"prebuild": "yarn bootload && yarn link -f",
|
|
29
29
|
"build": "tsmodule build",
|
|
30
30
|
"dev": "tsmodule dev",
|
|
31
|
+
"pretest": "yarn build -b",
|
|
32
|
+
"test": "ava --no-worker-threads",
|
|
33
|
+
"retest": "SKIP_TEST_SETUP=1 yarn test",
|
|
31
34
|
"lint": "eslint --fix src",
|
|
32
35
|
"prepare": "yarn build -r",
|
|
33
|
-
"prepublishOnly": "yarn
|
|
34
|
-
"
|
|
35
|
-
"test": "ava --no-worker-threads",
|
|
36
|
-
"retest": "SKIP_TEST_SETUP=1 yarn test"
|
|
36
|
+
"prepublishOnly": "yarn test",
|
|
37
|
+
"release": "release-it major -VV --ci"
|
|
37
38
|
},
|
|
38
39
|
"dependencies": {
|
|
39
40
|
"@types/glob": "^7.2.0",
|
|
@@ -57,7 +58,18 @@
|
|
|
57
58
|
},
|
|
58
59
|
"devDependencies": {
|
|
59
60
|
"@types/fs-extra": "^9.0.13",
|
|
60
|
-
"eslint-config-next": "^12.1.0"
|
|
61
|
+
"eslint-config-next": "^12.1.0",
|
|
62
|
+
"release-it": "^14.12.5"
|
|
63
|
+
},
|
|
64
|
+
"release-it": {
|
|
65
|
+
"git": {
|
|
66
|
+
"commitMessage": "chore: release v${version}",
|
|
67
|
+
"tagAnnotation": "v${version}"
|
|
68
|
+
},
|
|
69
|
+
"github": {
|
|
70
|
+
"release": true,
|
|
71
|
+
"releaseName": "v${version}"
|
|
72
|
+
}
|
|
61
73
|
},
|
|
62
74
|
"ava": {
|
|
63
75
|
"timeout": "10 minutes",
|
|
@@ -74,6 +86,9 @@
|
|
|
74
86
|
},
|
|
75
87
|
"keywords": [
|
|
76
88
|
"esm",
|
|
89
|
+
"es module",
|
|
90
|
+
"ts module",
|
|
91
|
+
"bundle",
|
|
77
92
|
"loader",
|
|
78
93
|
"typescript",
|
|
79
94
|
"loader hook",
|