@tsmodule/tsmodule 10.1.0 → 12.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 +3 -3
- package/dist/commands/create/index.js +1 -1
- package/dist/commands/dev/index.js +2 -2
- package/dist/index.js +5 -2
- package/dist/loader/index.js +1 -1
- package/package.json +8 -2
- package/template/.github/workflows/ci.yml +3 -3
- package/template/package.json +1 -0
@@ -1,3 +1,3 @@
|
|
1
|
-
import{build as w}from"esbuild";import{existsSync as
|
2
|
-
`}}),
|
3
|
-
This might take a moment.`),
|
1
|
+
import{build as w}from"esbuild";import{existsSync as k,readFileSync as x,writeFileSync as F}from"fs";import{extname as O,isAbsolute as B,resolve as p}from"path";import c from"chalk";import{env as h}from"process";import j from"fs/promises";import D from"fast-glob";import o from"ora";import{createDebugLogger as J,log as d}from"create-debug-logger";import{isTs as u,isTsxOrJsx as m}from"../../utils/index.js";import{emitTsDeclarations as P}from"./lib/emitTsDeclarations.js";import{getPackageJsonFile as C}from"../../utils/pkgJson.js";import{normalizeImportSpecifiers as G}from"../normalize/index.js";const E=t=>{d(c.bgBlue(c.white(` ${t} `)))},W=async({files:t="src/**/*",dev:r=!1,fast:f=!1})=>{h.NODE_ENV=r?"development":"production";const s=J(W);s.log("Building",{files:t,dev:r,fast:f}),E(`${c.bold("TS Module")} [${h.NODE_ENV}]`);const N=await C(),i=process.cwd(),g={absWorkingDir:i,outbase:"src",outdir:"dist",assetNames:"[name].js",logLevel:r?"warning":"error",charset:"utf8",format:"esm",target:"esnext",minify:!r,define:{PACKAGE_JSON:N}},b=p(i,"src"),n=p(i,"dist");if(B(t)){const e=t.replace(b,n).replace(u,".js").replace(m,".js");s.log("Cleaning emitted file:",{outfile:e}),await j.rm(e,{force:!0})}else s.log("Cleaning old output:",{outDir:n}),await j.rm(n,{force:!0,recursive:!0});console.log();const l=D.sync(t,{cwd:i}).filter(e=>O(e)!==".d.ts").map(e=>p(e)),y=l.filter(e=>u.test(e)).filter(e=>!m.test(e));s.log("Compiling TS files:",{tsFiles:y}),await w({...g,entryPoints:y.filter(e=>!e.endsWith(".d.ts"))}),o("Built TS files.").succeed();const S=l.filter(e=>m.test(e));if(s.log("Compiling TSX files:",{tsxFiles:S}),await w({...g,entryPoints:S.filter(e=>!e.endsWith(".d.ts")),jsxFactory:"createElement",banner:{js:`import { createElement } from "react";
|
2
|
+
`}}),o("Built TSX files.").succeed(),process.env.NO_REWRITES)return;const T=t.replace(b,n).replace(/^(\.\/)?src\//,"dist/").replace(u,".js").replace(m,".js");if(await G(T),o("Normalized import specifiers.").succeed(),console.log(),r||f)return;E("Running post-build setup."),d(`Generating type declarations.
|
3
|
+
This might take a moment.`),P(l),o(`Generated delcarations for ${l.length} files.`).succeed();let a;k("dist/package.json")?a=JSON.parse(x("dist/package.json","utf-8")):a={},a.type="module",F("dist/package.json",JSON.stringify(a,null,2)),o('Forced "type": "module" in output.').succeed(),d(c.green("Build complete."))};export{E as bannerLog,W as build};
|
@@ -1 +1 @@
|
|
1
|
-
import{fileURLToPath as d,URL as m}from"url";import g from"chalk";import
|
1
|
+
import{fileURLToPath as d,URL as m}from"url";import g from"chalk";import s from"fs/promises";import f from"ora";import{resolve as a}from"path";import{shell as n}from"await-shell";import{copy as u}from"fs-extra";const S=async t=>{const i=process.cwd(),e=f(`Creating new module ${g.blueBright(t)}.`).start(),c=new m("../../../template",import.meta.url);await u(d(c),a(i,t));const o=a(i,t,"package.json"),l=await s.readFile(o,"utf-8"),r=JSON.parse(l);r.name=t,await s.writeFile(o,JSON.stringify(r,null,2)),e.succeed("Project created."),process.chdir(t);const p=["@tsmodule/tsmodule"];globalThis.SHELL_OPTIONS={stdio:["ignore","ignore","inherit"]},e.start("Installing dependencies."),await n(`yarn add -D ${p.join(" ")}`),e.succeed("Dependencies installed."),e.start("Initializing git."),await n("git init"),e.succeed("Git initialized.")};export{S as create};
|
@@ -1,3 +1,3 @@
|
|
1
|
-
import{relative as a,resolve as m}from"path";import{build as o}from"../build/index.js";import e from"chalk";import{log as l}from"create-debug-logger";import p from"ora";import{
|
1
|
+
import{relative as a,resolve as m}from"path";import{build as o}from"../build/index.js";import e from"chalk";import{log as l}from"create-debug-logger";import p from"ora";import d from"node-watch";import{shell as u}from"await-shell";const s=()=>{console.clear()},i=r=>{l(`
|
2
2
|
`,e.gray(`Built ${e.bold(r)}.`),`
|
3
|
-
`,e.blue(new Date().toLocaleString()))},
|
3
|
+
`,e.blue(new Date().toLocaleString()))},B=async()=>{const r=process.cwd();await u("clear"),s(),await o({dev:!0}),i("src/**/*"),d(m(r,"src"),{recursive:!0,persistent:!0}).on("change",async(f,t)=>{s();const c=Date.now();await o({dev:!0,files:t});const n=Date.now()-c;p(e.blueBright(`Dev refresh finished in ${e.bold(`${n}ms`)}.`)).succeed(),i(a(r,t))})};export{B as dev};
|
package/dist/index.js
CHANGED
@@ -1,3 +1,6 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
|
-
var r="@tsmodule/tsmodule",
|
3
|
-
|
2
|
+
var r="@tsmodule/tsmodule",d="module",m="12.0.0",a="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/","template/"],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",test:"ava --no-worker-threads"},h={"@types/cross-spawn":"^6.0.2","@types/node":"17.0.8","@types/react":"17.0.38","@typescript-eslint/eslint-plugin":"^5.9.1","@typescript-eslint/parser":"^5.9.1",ava:"^4.0.1","await-shell":"^14.0.1",chalk:"^5.0.0",chokidar:"^3.5.3",commander:"^8.3.0","create-debug-logger":"^1.10.1","cross-spawn":"^7.0.3",esbuild:"^0.14.0",eslint:"^8.6.0","fast-glob":"^3.2.10","fs-extra":"^10.0.0","node-watch":"^0.7.3",ora:"^6.0.1",path:"^0.12.7",react:"^17.0.2",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"]},T={"@types/fs-extra":"^9.0.13"},t={name:r,type:d,version:m,repository:a,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:T};import e from"chalk";import{Command as y}from"commander";import{build as B}from"./commands/build/index.js";import{create as A}from"./commands/create/index.js";import{dev as C}from"./commands/dev/index.js";import{execute as E}from"./commands/execute/index.js";import{normalizeImportSpecifiers as R}from"./commands/normalize/index.js";const{version:j}=t,i=new y;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
|
+
|
4
|
+
Run TS directly: ${e.bold("tsmodule src/index.ts")}
|
5
|
+
Use a command: ${e.bold("tsmodule build")}`)).version(String(j)),i.command("dev").description("Build and watch for changes.").action(C),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>").description("Create a new project.").action(A),i.command("normalize [files]").description(`Rewrites import specifiers in files to ESM-compliant paths.
|
6
|
+
(default: dist/**/*.js)`).action(async({files:n})=>{await R(n)}),i.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(E),i.parse(process.argv);
|
package/dist/loader/index.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
import{extname as m,isAbsolute as U,join as E,normalize as w,resolve as S}from"path";import{fileURLToPath as H,pathToFileURL as v,URL as L}from"url";import{promises as G}from"fs";import{transform as h}from"esbuild";import{posix as M}from"path";import{win32 as T}from"path";import{checkExtensions as k,checkTsExtensions as D,fileExists as b,isJs as N,isTs as P,MODULE_LOADERS as R}from"../utils/index.js";import{getPackageJsonFile as y}from"../utils/pkgJson.js";
|
1
|
+
import{extname as m,isAbsolute as U,join as E,normalize as w,resolve as S}from"path";import{fileURLToPath as H,pathToFileURL as v,URL as L}from"url";import{createDebugLogger as c}from"create-debug-logger";import{promises as G}from"fs";import{transform as h}from"esbuild";import{posix as M}from"path";import{win32 as T}from"path";import{checkExtensions as k,checkTsExtensions as D,fileExists as b,isJs as N,isTs as P,MODULE_LOADERS as R}from"../utils/index.js";import{getPackageJsonFile as y}from"../utils/pkgJson.js";const F=await y(),A=async(o,r,t)=>{const{parentURL:s}=r,e=c(A);if(e.log("Resolving specifier:",{importedFromURL:s,specifier:o}),!o.startsWith(".")&&!U(o))return e.log("Using defaultResolve for named module:",{specifier:o}),t(o,r,t);const{href:l}=v(process.cwd()),{href:i}=new L(s||l);e.log("Finding import URL for",{specifier:o,baseURL:i});let n=o;o.startsWith("file://")||(U(o)?(e.log("Setting import URL to absolute specifier."),n=v(S(w(o))).href):(e.log("Setting import URL relative to baseURL."),n=new L(o,i).href),e.log("Resolved import URL:",{importedFileURL:n,importedFromURL:s}));const f=m(s??"").toLowerCase(),d=m(n).toLowerCase();if(e.log("Rewriting file extension:",{parentExtension:f,specifierExtension:d}),d){const a=n.substring(0,n.lastIndexOf(d));if(e.log("Re-resolving specifier:",{unresolvedSpecifier:a}),N.test(d)&&P.test(f)){const p=D(a);if(p)return e.log("Found JS import in TS:",{unresolvedSpecifier:a,resolvedTsSourceFile:p}),{url:p}}return b(a)?(e.log("Found file at unresolved specifier:",{unresolvedSpecifier:a}),{url:a}):t(o,r,t)}e.log("Resolving incomplete URL import to file:",{specifier:o});const g=k(n);if(g)return e.log("Resolved import URL to file:",{resolvedFile:g}),{url:g};const x=new L(E(n,"index")).href,u=k(x);return u?(e.log("Resolved import URL to index file:",{resolvedIndexFile:u}),{url:u}):t(o,r,t)},J=async(o,r,t)=>{const s=c(J);if(s.log("Loading source file:",{url:o}),!o.includes(T.sep)&&!o.includes(M.sep))return s.log("Using defaultLoad for named module:",{url:o}),t(o,r,t);const e=m(o),l=R[e];if(!l)return s.log("No loader found, using defaultLoad:",{url:o}),t(o,r,t);const i=H(o),n=await G.readFile(i),f=await h(n.toString(),{...l,sourcefile:i,format:"esm",define:{PACKAGE_JSON:F}});return{format:"module",source:f.code}},O=async(o,r,t)=>{const s=c(O);s.log("Getting format for source file:",{url:o});const e=m(o);return R[e]?{format:"module"}:(s.log("No loader found, using default format:",{url:o}),t(o,r,t))},B=async(o,r,t)=>{const s=c(B);s.log("Transforming source from context:",{context:r});const{url:e}=r,l=m(e),i=R[l];return i?{source:(await h(o.toString(),{...i,logLevel:"info",charset:"utf8",target:"esnext",sourcefile:r.url,format:r.format==="module"?"esm":"cjs",define:{PACKAGE_JSON:F}})).code}:(s.log("No loader found, using default transformer:",{url:e}),t(o,r,t))};export{O as getFormat,J as load,A as resolve,B as transformSource};
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@tsmodule/tsmodule",
|
3
3
|
"type": "module",
|
4
|
-
"version": "
|
4
|
+
"version": "12.0.0",
|
5
5
|
"repository": "tsmodule/tsmodule",
|
6
6
|
"description": "TypeScript Module loader and compiler",
|
7
7
|
"license": "MIT",
|
@@ -46,7 +46,7 @@
|
|
46
46
|
"@typescript-eslint/eslint-plugin": "^5.9.1",
|
47
47
|
"@typescript-eslint/parser": "^5.9.1",
|
48
48
|
"ava": "^4.0.1",
|
49
|
-
"await-shell": "^
|
49
|
+
"await-shell": "^14.0.1",
|
50
50
|
"chalk": "^5.0.0",
|
51
51
|
"chokidar": "^3.5.3",
|
52
52
|
"commander": "^8.3.0",
|
@@ -55,6 +55,8 @@
|
|
55
55
|
"esbuild": "^0.14.0",
|
56
56
|
"eslint": "^8.6.0",
|
57
57
|
"fast-glob": "^3.2.10",
|
58
|
+
"fs-extra": "^10.0.0",
|
59
|
+
"node-watch": "^0.7.3",
|
58
60
|
"ora": "^6.0.1",
|
59
61
|
"path": "^0.12.7",
|
60
62
|
"react": "^17.0.2",
|
@@ -69,6 +71,7 @@
|
|
69
71
|
"experimental-loader"
|
70
72
|
],
|
71
73
|
"ava": {
|
74
|
+
"timeout": "10 minutes",
|
72
75
|
"files": [
|
73
76
|
"test/**/*.test.ts"
|
74
77
|
],
|
@@ -79,5 +82,8 @@
|
|
79
82
|
"--no-warnings",
|
80
83
|
"--loader=@tsmodule/tsmodule"
|
81
84
|
]
|
85
|
+
},
|
86
|
+
"devDependencies": {
|
87
|
+
"@types/fs-extra": "^9.0.13"
|
82
88
|
}
|
83
89
|
}
|
@@ -10,12 +10,12 @@ on:
|
|
10
10
|
|
11
11
|
jobs:
|
12
12
|
test:
|
13
|
-
name: Node
|
13
|
+
name: Node ${{ matrix.nodejs }} on ${{ matrix.os }}
|
14
14
|
runs-on: ${{ matrix.os }}
|
15
|
-
timeout-minutes:
|
15
|
+
timeout-minutes: 10
|
16
16
|
strategy:
|
17
17
|
matrix:
|
18
|
-
nodejs: [16]
|
18
|
+
nodejs: [14, 16, "lts/*"]
|
19
19
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
20
20
|
steps:
|
21
21
|
- uses: actions/checkout@v2
|