@tsmodule/tsmodule 8.2.0 → 9.0.3
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/README.md +2 -2
- package/dist/commands/build/index.d.ts +4 -1
- package/dist/commands/build/index.js +3 -3
- package/dist/index.js +2 -2
- package/dist/loader/index.js +1 -1
- package/dist/utils/pkgJson.d.ts +1 -0
- package/dist/utils/pkgJson.js +1 -0
- package/package.json +3 -2
package/README.md
CHANGED
@@ -4,4 +4,7 @@ export declare const bannerLog: (msg: string) => void;
|
|
4
4
|
* could mean many things, all of which is handled by the loader which will
|
5
5
|
* resolve them for us.
|
6
6
|
*/
|
7
|
-
export declare const build: (dev
|
7
|
+
export declare const build: ({ dev, fast }: {
|
8
|
+
dev?: boolean;
|
9
|
+
fast?: boolean;
|
10
|
+
}) => Promise<void>;
|
@@ -1,3 +1,3 @@
|
|
1
|
-
import{build as d}from"esbuild";import{existsSync as h,readFileSync as k,writeFileSync as
|
2
|
-
`}}),i("Built TSX files.").succeed(),process.env.NO_REWRITES||(await
|
3
|
-
This might take a moment.`),
|
1
|
+
import{build as d}from"esbuild";import{existsSync as h,readFileSync as k,writeFileSync as w}from"fs";import{extname as x,resolve as u}from"path";import l from"chalk";import{env as F}from"process";import T from"fast-glob";import i from"ora";import{rm as B}from"fs/promises";import{createDebugLogger as E,log as a}from"create-debug-logger";import{isTs as N,isTsxOrJsx as g}from"../../utils/index.js";import{emitTsDeclarations as O}from"./lib/emitTsDeclarations.js";import{getPackageJsonFile as J}from"../../utils/pkgJson.js";import{normalizeImportSpecifiers as j}from"../normalize/index.js";const y=t=>{a(l.bgBlue(l.white(` ${t} `)))},D=async({dev:t=!1,fast:b=!1})=>{t&&(F.NODE_ENV="development");const r=E(D);t||y("Building for production.");const n=process.cwd(),S=await J(),c={absWorkingDir:n,outbase:"src",outdir:"dist",assetNames:"[name].js",logLevel:t?"debug":"error",charset:"utf8",format:"esm",target:"esnext",minify:!t,define:{PACKAGE_JSON:S}},m=u(n,"dist");r.log("Cleaning old output:",{distDir:m}),await B(m,{force:!0,recursive:!0}),console.log();const s=T.sync("src/**/*",{cwd:n}).filter(e=>x(e)!==".d.ts").map(e=>u(e)),f=s.filter(e=>N.test(e)).filter(e=>!g.test(e));r.log("Compiling TS files:",{tsFiles:f}),await d({...c,entryPoints:f.filter(e=>!e.endsWith(".d.ts"))}),i("Built TS files.").succeed();const p=s.filter(e=>g.test(e));if(r.log("Compiling TSX files:",{tsxFiles:p}),await d({...c,entryPoints:p.filter(e=>!e.endsWith(".d.ts")),jsxFactory:"createElement",banner:{js:`import { createElement } from "react";
|
2
|
+
`}}),i("Built TSX files.").succeed(),process.env.NO_REWRITES||(await j(),i("Normalized import specifiers.").succeed(),console.log(),t||b))return;y("Running post-build setup."),a(`Generating type declarations.
|
3
|
+
This might take a moment.`),O(s),i(`Generated delcarations for ${s.length} files.`).succeed();let o;h("dist/package.json")?o=JSON.parse(k("dist/package.json","utf-8")):o={},o.type="module",w("dist/package.json",JSON.stringify(o,null,2)),i('Forced "type": "module" in output.').succeed(),a(l.green("Build complete."))};export{y as bannerLog,D as build};
|
package/dist/index.js
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
|
-
var
|
3
|
-
(default: dist/**/*.js)`).action(async({files:
|
2
|
+
var r="@tsmodule/tsmodule",m="module",a="9.0.3",s="tsmodule/tsmodule",d="TypeScript Module loader and compiler",p="MIT",l={tsmodule:"dist/index.js"},c={".":"./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"}],g=["dist/","template/"],v={node:">=14"},b={bootstrap:"node bootstrap.js",prebuild:"yarn bootstrap",build:"node --no-warnings --loader ./dist/loader/index.js src/index.ts build",lint:"eslint --fix src",install:"yarn build -f",prepublishOnly:"yarn build && yarn test",test:"ava --no-worker-threads"},S={"await-shell":"^2.7.0",chalk:"^5.0.0",commander:"^8.3.0","create-debug-logger":"^1.10.1",esbuild:"^0.14.0","fast-glob":"^3.2.10",ora:"^6.0.1",path:"^0.12.7",react:"^17.0.2",rollup:"^2.63.0","rollup-plugin-preserve-shebang":"^1.0.1",typescript:"^4.5.5"},h={"@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",eslint:"^8.6.0"},w=["esm","loader","typescript","loader hook","require hook","experimental-loader"],y={files:["test/**/*.test.ts"],extensions:{ts:"module"},nodeArguments:["--no-warnings","--loader=@tsmodule/tsmodule"]},t={name:r,type:m,version:a,repository:s,description:d,license:p,bin:l,exports:c,types:u,contributors:f,files:g,engines:v,scripts:b,dependencies:S,devDependencies:h,keywords:w,ava:y};import i from"chalk";import{Command as B}from"commander";import{build as T}from"./commands/build/index.js";import{create as A}from"./commands/create/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("build").option("-d, --dev","Build development version (default: production)").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(A),e.command("normalize [files]").description(`Rewrites import specifiers in files to ESM-compliant paths.
|
3
|
+
(default: dist/**/*.js)`).action(async({files:n})=>{await E(n)}),e.parse(process.argv);
|
package/dist/loader/index.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
import{extname as m,isAbsolute as U,join as
|
1
|
+
import{extname as m,isAbsolute as U,join as h,normalize as x,resolve as w}from"path";import{fileURLToPath as H,pathToFileURL as v,URL as L}from"url";import{promises as G}from"fs";import{transform as k}from"esbuild";import{sep as M}from"path/posix";import{sep as T}from"path/win32";import{checkExtensions as F,checkTsExtensions as D,fileExists as b,isJs as N,isTs as y,MODULE_LOADERS as R}from"../utils/index.js";import{getPackageJsonFile as A}from"../utils/pkgJson.js";import{createDebugLogger as c}from"create-debug-logger";const E=await A(),J=async(o,r,t)=>{const{parentURL:s}=r,e=c(J);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(w(x(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)&&y.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=F(n);if(g)return e.log("Resolved import URL to file:",{resolvedFile:g}),{url:g};const S=new L(h(n,"index")).href,u=F(S);return u?(e.log("Resolved import URL to index file:",{resolvedIndexFile:u}),{url:u}):t(o,r,t)},O=async(o,r,t)=>{const s=c(O);if(s.log("Loading source file:",{url:o}),!o.includes(T)&&!o.includes(M))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 k(n.toString(),{...l,sourcefile:i,format:"esm",define:{PACKAGE_JSON:E}});return{format:"module",source:f.code}},P=async(o,r,t)=>{const s=c(P);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 k(o.toString(),{...i,logLevel:"info",charset:"utf8",target:"esnext",sourcefile:r.url,format:r.format==="module"?"esm":"cjs",define:{PACKAGE_JSON:E}})).code}:(s.log("No loader found, using default transformer:",{url:e}),t(o,r,t))};export{P as getFormat,O as load,J as resolve,B as transformSource};
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const getPackageJsonFile: () => Promise<string>;
|
@@ -0,0 +1 @@
|
|
1
|
+
import{readFile as r}from"fs/promises";import{resolve as s}from"path";const n=async()=>{const o=process.cwd(),e=s(o,"package.json");return await r(e,"utf-8")};export{n as getPackageJsonFile};
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@tsmodule/tsmodule",
|
3
3
|
"type": "module",
|
4
|
-
"version": "
|
4
|
+
"version": "9.0.3",
|
5
5
|
"repository": "tsmodule/tsmodule",
|
6
6
|
"description": "TypeScript Module loader and compiler",
|
7
7
|
"license": "MIT",
|
@@ -33,7 +33,8 @@
|
|
33
33
|
"prebuild": "yarn bootstrap",
|
34
34
|
"build": "node --no-warnings --loader ./dist/loader/index.js src/index.ts build",
|
35
35
|
"lint": "eslint --fix src",
|
36
|
-
"
|
36
|
+
"install": "yarn build -f",
|
37
|
+
"prepublishOnly": "yarn build && yarn test",
|
37
38
|
"test": "ava --no-worker-threads"
|
38
39
|
},
|
39
40
|
"dependencies": {
|