@tsmodule/tsmodule 10.2.1 → 10.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,3 +1,3 @@
1
- import{build as w}from"esbuild";import{existsSync as x,readFileSync as F,writeFileSync as O}from"fs";import{extname as B,isAbsolute as D,resolve as p}from"path";import c from"chalk";import{env as h}from"process";import j from"fs/promises";import J from"fast-glob";import s from"ora";import{createDebugLogger as P,log as u}from"create-debug-logger";import{isTs as d,isTsxOrJsx as m}from"../../utils/index.js";import{emitTsDeclarations as C}from"./lib/emitTsDeclarations.js";import{getPackageJsonFile as G}from"../../utils/pkgJson.js";import{normalizeImportSpecifiers as E}from"../normalize/index.js";const N=t=>{u(c.bgBlue(c.white(` ${t} `)))},W=async({files:t="src/**/*",dev:r=!1,fast:f=!1})=>{h.NODE_ENV=r?"development":"production";const o=P(W);o.log("Building",{files:t,dev:r,fast:f}),N(`${c.bold("TS Module")} [${h.NODE_ENV}]`);const T=await G(),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:T}},b=p(i,"src"),n=p(i,"dist");if(o.log("Cleaning old output:",{outDir:n}),r&&D(t)){const e=t.replace(b,n).replace(d,".js").replace(m,".js");await j.rm(e,{force:!0})}else await j.rm(n,{force:!0,recursive:!0});console.log();const l=J.sync(t,{cwd:i}).filter(e=>B(e)!==".d.ts").map(e=>p(e)),y=l.filter(e=>d.test(e)).filter(e=>!m.test(e));o.log("Compiling TS files:",{tsFiles:y}),await w({...g,entryPoints:y.filter(e=>!e.endsWith(".d.ts"))}),s("Built TS files.").succeed();const S=l.filter(e=>m.test(e));if(o.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
- `}}),s("Built TSX files.").succeed(),process.env.NO_REWRITES)return;const k=t.replace(b,n).replace(/^src\//,"dist/").replace(d,".js").replace(m,".js");if(t?await E(k):await E(),s("Normalized import specifiers.").succeed(),console.log(),r||f)return;N("Running post-build setup."),u(`Generating type declarations.
3
- This might take a moment.`),C(l),s(`Generated delcarations for ${l.length} files.`).succeed();let a;x("dist/package.json")?a=JSON.parse(F("dist/package.json","utf-8")):a={},a.type="module",O("dist/package.json",JSON.stringify(a,null,2)),s('Forced "type": "module" in output.').succeed(),u(c.green("Build complete."))};export{N as bannerLog,W as build};
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 s from"ora";import{createDebugLogger as J,log as u}from"create-debug-logger";import{isTs as d,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=>{u(c.bgBlue(c.white(` ${t} `)))},W=async({files:t="src/**/*",dev:r=!1,fast:f=!1})=>{h.NODE_ENV=r?"development":"production";const o=J(W);o.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(o.log("Cleaning old output:",{outDir:n}),r&&B(t)){const e=t.replace(b,n).replace(d,".js").replace(m,".js");await j.rm(e,{force:!0})}else 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=>d.test(e)).filter(e=>!m.test(e));o.log("Compiling TS files:",{tsFiles:y}),await w({...g,entryPoints:y.filter(e=>!e.endsWith(".d.ts"))}),s("Built TS files.").succeed();const S=l.filter(e=>m.test(e));if(o.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
+ `}}),s("Built TSX files.").succeed(),process.env.NO_REWRITES)return;const T=t.replace(b,n).replace(/^(\.\/)?src\//,"dist/").replace(d,".js").replace(m,".js");if(await G(T),s("Normalized import specifiers.").succeed(),console.log(),r||f)return;E("Running post-build setup."),u(`Generating type declarations.
3
+ This might take a moment.`),P(l),s(`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)),s('Forced "type": "module" in output.').succeed(),u(c.green("Build complete."))};export{E as bannerLog,W as build};
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
- var r="@tsmodule/tsmodule",a="module",m="10.2.1",d="tsmodule/tsmodule",s="TypeScript Module loader and compiler",l="MIT",p={tsmodule:"dist/index.js"},c={".":"./dist/loader/index.js","./*":"./dist/*/index.js","./package.json":"./package.json"},f="dist/types/index.d.ts",u=[{name:"C. Lewis",email:"ctj.lewis@icloud.com",url:"https://ctjlewis.com"}],v=["dist/","template/"],g={node:">=14"},b={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":"^6.0.3",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",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={files:["test/**/*.test.ts"],extensions:{ts:"module"},nodeArguments:["--no-warnings","--loader=@tsmodule/tsmodule"]},t={name:r,type:a,version:m,repository:d,description:s,license:l,bin:p,exports:c,types:f,contributors:u,files:v,engines:g,scripts:b,dependencies:h,keywords:S,ava:w};import i from"chalk";import{Command as B}from"commander";import{build as T}from"./commands/build/index.js";import{create as y}from"./commands/create/index.js";import{dev as A}from"./commands/dev/index.js";import{execute as C}from"./commands/execute/index.js";import{normalizeImportSpecifiers as E}from"./commands/normalize/index.js";const{version:j}=t,e=new B;e.name(i.bold(i.blueBright("tsmodule"))).description(i.blueBright("A tool for building TypeScript modules.")).version(String(j)),e.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(C),e.command("dev").description("Build and watch for changes.").action(A),e.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(T),e.command("create <name>").description("Create a new project.").action(y),e.command("normalize [files]").description(`Rewrites import specifiers in files to ESM-compliant paths.
2
+ var r="@tsmodule/tsmodule",a="module",m="10.3.0",d="tsmodule/tsmodule",s="TypeScript Module loader and compiler",l="MIT",p={tsmodule:"dist/index.js"},c={".":"./dist/loader/index.js","./*":"./dist/*/index.js","./package.json":"./package.json"},f="dist/types/index.d.ts",u=[{name:"C. Lewis",email:"ctj.lewis@icloud.com",url:"https://ctjlewis.com"}],v=["dist/","template/"],g={node:">=14"},b={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":"^7.4.0",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",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={name:r,type:a,version:m,repository:d,description:s,license:l,bin:p,exports:c,types:f,contributors:u,files:v,engines:g,scripts:b,dependencies:h,keywords:S,ava:w};import i from"chalk";import{Command as B}from"commander";import{build as T}from"./commands/build/index.js";import{create as y}from"./commands/create/index.js";import{dev as A}from"./commands/dev/index.js";import{execute as C}from"./commands/execute/index.js";import{normalizeImportSpecifiers as E}from"./commands/normalize/index.js";const{version:j}=t,e=new B;e.name(i.bold(i.blueBright("tsmodule"))).description(i.blueBright("A tool for building TypeScript modules.")).version(String(j)),e.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(C),e.command("dev").description("Build and watch for changes.").action(A),e.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(T),e.command("create <name>").description("Create a new project.").action(y),e.command("normalize [files]").description(`Rewrites import specifiers in files to ESM-compliant paths.
3
3
  (default: dist/**/*.js)`).action(async({files:n})=>{await E(n)}),e.parse(process.argv);
@@ -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";import{createDebugLogger as c}from"create-debug-logger";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};
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": "10.2.1",
4
+ "version": "10.3.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": "^6.0.3",
49
+ "await-shell": "^7.4.0",
50
50
  "chalk": "^5.0.0",
51
51
  "chokidar": "^3.5.3",
52
52
  "commander": "^8.3.0",
@@ -69,6 +69,7 @@
69
69
  "experimental-loader"
70
70
  ],
71
71
  "ava": {
72
+ "timeout": "10 minutes",
72
73
  "files": [
73
74
  "test/**/*.test.ts"
74
75
  ],
@@ -10,12 +10,12 @@ on:
10
10
 
11
11
  jobs:
12
12
  test:
13
- name: Node.js v${{ matrix.nodejs }} (${{ matrix.os }})
13
+ name: Node ${{ matrix.nodejs }} on ${{ matrix.os }}
14
14
  runs-on: ${{ matrix.os }}
15
- timeout-minutes: 5
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
@@ -18,6 +18,7 @@
18
18
  "lint": "eslint src --fix"
19
19
  },
20
20
  "ava": {
21
+ "timout": 240000,
21
22
  "files": [
22
23
  "test/**/*.test.ts"
23
24
  ],