@tsmodule/tsmodule 30.0.4 → 30.0.7
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 +3 -7
- 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 +3 -3
- package/dist/utils/cwd.js +1 -1
- package/package.json +8 -13
- package/dist/utils/require.js +0 -1
|
@@ -1,8 +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 j,transform as q}from"esbuild";import{existsSync as A,mkdirSync as H,readFileSync as h,rmSync as _,writeFileSync as $}from"fs";import l from"chalk";import{env as L}from"process";import Q from"fast-glob";import m from"ora";import{createDebugLogger as Y,log as g}from"create-debug-logger";import{isJsOrTs as M,isTs as y,isTsxOrJsx as f}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 W}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
|
-
|
|
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};
|
|
3
|
+
`,G=t=>{const o=` ${t} `;g(l.bgBlue(l.bold(l.white(o))))},ne=()=>{let t;if(A("dist/package.json")?t=JSON.parse(h("dist/package.json","utf-8")):t={},t?.module==="module")return!0;t.type="module",$("dist/package.json",JSON.stringify(t,null,2))},I=(t,o,p)=>{const{srcDir:i,outDir:S}=W();return o=v(o),{stdin:{contents:t,sourcefile:o,resolveDir:R(o),loader:p},outdir:void 0,outfile:o.replace(M,".js").replace(i,S)}},re=async({files:t="src/**/*",styles:o="src/components/index.css",bundle:p=!1,dev:i=!1,target:S="esnext",runtimeOnly:b=!1,noWrite:O=!1,stdin:c,stdinFile:d})=>{L.NODE_ENV=i?"development":"production";const s=Y(re),V=Z(),{cwd:w,srcDir:x,outDir:a}=W(),C=await oe(),J=JSON.parse(C),k={treeShaking:p,target:S,minify:!i,jsx:"transform",jsxFactory:"React.createElement",format:"esm",charset:"utf8",logLevel:i?"warning":"error",define:{PACKAGE_JSON:C,"process.env.NODE_ENV":i?JSON.stringify("development"):JSON.stringify("production")}},T={...k,bundle:p,absWorkingDir:w,outbase:"src",outdir:"dist",assetNames:"[name].js",format:"esm",target:"esnext",platform:J?.platform??"node",write:!O};let u="";if(c){s.log("Building file from stdin",{stdin:c,stdinFile:d,noWrite:O}),d||(g(l.red("ERROR: --stdin-file must be specified to emulate a file location when using stdin.")),process.exit(1)),typeof c=="string"&&c.length?u=c:u=await se();const e={...k,sourcefile:d,loader:"tsx",banner:void 0,footer:void 0};if(O)return(await q(u,e)).code;{const n=I(u,d,"tsx");return await j({...T,...n})}}s.log("Building",{files:t,dev:i,runtimeOnly:b}),G(`${l.bold("TS Module")} [${L.NODE_ENV}]`);const r=Q.sync(t,{cwd:w}).filter(e=>K(e)!==".d.ts").map(e=>v(e));if(U(t)){r.length||r.push(t);const e=t.replace(x,a).replace(y,".js").replace(f,".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=>f.test(e));s.log("Compiling TSX files:",{tsxFiles:D});const z=D.filter(e=>!e.endsWith(".d.ts"));await Promise.all(z.map(async e=>{const n=h(e,"utf-8"),E=ie+n,P=I(E,e,"tsx");await j({...T,...P})})),m("Built TSX files.").succeed();const N=r.filter(e=>y.test(e)).filter(e=>!f.test(e));s.log("Compiling TS files:",{tsFiles:N}),await j({...T,entryPoints:N.filter(e=>!e.endsWith(".d.ts"))}),m("Built TS files.").succeed();const B=r.filter(e=>!M.test(e));if(s.log("Copying non-JS/TS files.",{allFiles:r,nonJsTsFiles:B}),await Promise.all(B.map(async e=>{const n=F(w,e).replace(x,a).replace(y,".js").replace(f,".js");s.log("Copying non-source file:",{file:e,outfile:n}),H(R(n),{recursive:!0}),$(n,h(e),{encoding:"binary",flag:"w"})})),!process.env.NO_REWRITES){const e=t.replace(x,a).replace(/^(\.\/)?src\//,"dist/").replace(y,".js").replace(f,".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||b)){if(A(F(o))){s.log("Building styles for production.");const{style:e="./dist/bundle.css"}=J,X=["npx tailwindcss",i?"":"-m","--postcss postcss.config.js",`-i ${o}`,"-o",e];await V.run(X.join(" "))}else s.log("Styles not found.",{styles:o});G("Running post-build setup."),g(`Generating type declarations.
|
|
4
|
+
This might take a moment.`),ee(r),m(`Generated delcarations for ${r.length} files.`).succeed(),g(l.green("Build complete."))}};export{G as bannerLog,re as build};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
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};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{existsSync as
|
|
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()))},O=async()=>{const t=process.cwd(),c=
|
|
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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{URL as n}from"url";import{createShell as s}from"await-shell";const i=async()=>{const e=import.meta.url,o=new n("../../../dist/loader/index.js",e),r=["--no-warnings","--loader",o.href,...process.argv.slice(2)];await s().run(`node ${r.join(" ")}`)};export{i as execute};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{
|
|
2
|
-
\r;]*`,
|
|
3
|
-
]?$`,
|
|
1
|
+
import{readFileSync as R,writeFileSync as E}from"fs";import P from"fast-glob";import{pathToFileURL as $}from"url";import{resolve as I}from"path";import{createDebugLogger as d}from"create-debug-logger";import{getRewrittenSpecifiers as h}from"./lib/typescriptApi.js";const s=`[^
|
|
2
|
+
\r;]*`,y=`["']${s}['"][;
|
|
3
|
+
]?$`,S=`(import${s}(from)?)`,T=`(import|require)${s}\\(`,x=`(export${s}from)`,M=r=>{const e=r.replace(".","\\.").replace("/","\\/"),o=`${s}["']${e}["']${s}`;return new RegExp(`(${S}|${T}|${x})${o}`,"g")},u=(r,e,o)=>{const p=d(u);p.log("Rewriting import",{importStatement:r,specifierToReplace:e,specifierReplacement:o});const t=new RegExp(y),c=r.match(t);if(!c)throw p.log("No specifier match",{importStatement:r,specifierPattern:t}),new Error(`Could not identify specifier in import statement: ${r}`);const i=c[0],n=i.replace(e,o).trim();return r.replace(i,n)},F=async(r="dist/**/*.js")=>{const e=d(F),o=await P(r,{cwd:process.cwd()});e.log("Normalizing import/require specifiers:",{filesToNormalize:o});for(const p of o){const t=I(p),c=$(t).href,i=h(t);if(!i)return null;e.log("TypeScript API yielded specifiers to rewrite:",{rewrites:i});let n=R(t,"utf8");e.group();for(const{specifierToReplace:f,specifierReplacement:l}of i){const w=M(f),a=n.match(w)??[];e.log("Replacing import statements.",{entryPointURL:c,specifierToReplace:f,specifierReplacement:l,importStatements:a});for(const m of a){e.group();const g=u(m,f,l);e.log("Performing specifier rewrite.",{entryPointURL:c,importStatement:m,rewrittenImportStatement:g}),n=n.replace(m,g),E(t,n),e.log("Wrote output file.",{resolvedEntryPoint:t}),e.groupEnd()}}e.groupEnd()}};export{M as generateImportPattern,F as normalizeImportSpecifiers,u as rewriteImportStatement};
|
package/dist/constants.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
const t={default:[],react:["@tsmodule/react","react","react-dom"]},s={default:["@types/node"],react:["next","@types/react","@types/react-dom","eslint","eslint-config-next","tailwindcss","autoprefixer","cssnano","postcss","postcss-import"]};export{t as dependencies,s 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="30.0.
|
|
2
|
+
var r="@tsmodule/tsmodule",s="node",a="module",d="30.0.7",m="tsmodule/tsmodule",l="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"},g=["dist/","templates/"],b={node:">=14"},y={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"},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"},v={"@types/fs-extra":"^9.0.13","eslint-config-next":"^12.1.0"},w={timeout:"10 minutes",files:["test/**/*.test.ts"],extensions:{ts:"module"},nodeArguments:["--no-warnings","--loader=@tsmodule/tsmodule"]},S=["esm","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:m,description:l,license:p,types:c,bin:u,exports:f,files:g,engines:b,scripts:y,dependencies:h,devDependencies:v,ava:w,keywords:S,contributors: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
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").description("Builds TS files to output in dist/.").option("
|
|
6
|
-
For programmatic use alongside { stdin: ... }.`,!1).
|
|
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").description("Builds TS files to output in dist/.").option("--files <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).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
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/dist/utils/cwd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
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};
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@tsmodule/tsmodule",
|
|
3
3
|
"platform": "node",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "30.0.
|
|
5
|
+
"version": "30.0.7",
|
|
6
6
|
"repository": "tsmodule/tsmodule",
|
|
7
7
|
"description": "TypeScript Module loader and compiler",
|
|
8
8
|
"license": "MIT",
|
|
@@ -23,18 +23,17 @@
|
|
|
23
23
|
"node": ">=14"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
|
-
"
|
|
26
|
+
"bootstrap": "node bootstrap.js",
|
|
27
27
|
"bootload": "node --no-warnings --loader ./dist/loader/index.js src/index.ts build -r",
|
|
28
|
-
"prebuild": "yarn bootload && yarn link -f",
|
|
28
|
+
"prebuild": "yarn bootstrap && 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",
|
|
34
31
|
"lint": "eslint --fix src",
|
|
35
32
|
"prepare": "yarn build -r",
|
|
36
|
-
"prepublishOnly": "yarn test",
|
|
37
|
-
"
|
|
33
|
+
"prepublishOnly": "yarn build && yarn test",
|
|
34
|
+
"pretest": "yarn build -r",
|
|
35
|
+
"test": "ava --no-worker-threads",
|
|
36
|
+
"retest": "SKIP_TEST_SETUP=1 yarn test"
|
|
38
37
|
},
|
|
39
38
|
"dependencies": {
|
|
40
39
|
"@types/glob": "^7.2.0",
|
|
@@ -58,8 +57,7 @@
|
|
|
58
57
|
},
|
|
59
58
|
"devDependencies": {
|
|
60
59
|
"@types/fs-extra": "^9.0.13",
|
|
61
|
-
"eslint-config-next": "^12.1.0"
|
|
62
|
-
"release-it": "^14.12.5"
|
|
60
|
+
"eslint-config-next": "^12.1.0"
|
|
63
61
|
},
|
|
64
62
|
"ava": {
|
|
65
63
|
"timeout": "10 minutes",
|
|
@@ -76,9 +74,6 @@
|
|
|
76
74
|
},
|
|
77
75
|
"keywords": [
|
|
78
76
|
"esm",
|
|
79
|
-
"es module",
|
|
80
|
-
"ts module",
|
|
81
|
-
"bundle",
|
|
82
77
|
"loader",
|
|
83
78
|
"typescript",
|
|
84
79
|
"loader hook",
|
package/dist/utils/require.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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)}})();
|