@tsmodule/tsmodule 23.1.0 → 23.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,2 +1,3 @@
1
- import{readFileSync as w,writeFileSync as $}from"fs";import y from"fast-glob";import{pathToFileURL as S}from"url";import{resolve as x}from"path";import{createDebugLogger as g}from"create-debug-logger";import{getRewrittenSpecifiers as E}from"./lib/typescriptApi.js";const I=t=>{const r=`[^
2
- \r;]*`,o=t.replace(".","\\.").replace("/","\\/"),s=`${r}["']${o}["']${r}`,e=`(import${r}from)`,i=`(import|require)${r}\\(`,n=`(export${r}from)`;return new RegExp(`(${e}|${i}|${n})${s}`,"g")},d=(t,r,o)=>{g(d).log("Rewriting import",{importStatement:t,specifierToReplace:r,specifierReplacement:o});const[,e]=t.split(/from|\(/),i=e.replace(r,o).trim();return t.replace(e,i)},P=async(t="dist/**/*.js")=>{const r=g(P),o=await y(t,{cwd:process.cwd()});r.log("Normalizing import/require specifiers:",{filesToNormalize:o});for(const s of o){const e=x(s),i=S(e).href,n=E(e);if(!n)return null;r.log("TypeScript API yielded specifiers to rewrite:",{rewrites:n});let c=w(e,"utf8");r.group();for(const{specifierToReplace:p,specifierReplacement:l}of n){const u=I(p),a=c.match(u)??[];r.log("Replacing import statements.",{entryPointURL:i,specifierToReplace:p,specifierReplacement:l,importStatements:a});for(const m of a){r.group();const f=d(m,p,l);r.log("Performing specifier rewrite.",{entryPointURL:i,importStatement:m,rewrittenImportStatement:f}),c=c.replace(m,f),$(e,c),r.log("Wrote output file.",{resolvedEntryPoint:e}),r.groupEnd()}}r.groupEnd()}};export{I as generateImportPattern,P as normalizeImportSpecifiers,d as rewriteImportStatement};
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/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- var r="@tsmodule/tsmodule",s="node",d="module",m="23.1.0",l="tsmodule/tsmodule",a="TypeScript Module loader and compiler",c="MIT",p={tsmodule:"dist/index.js"},u={".":"./dist/loader/index.js","./*":"./dist/*/index.js","./package.json":"./package.json"},f="dist/types/index.d.ts",b=[{name:"C. Lewis",email:"ctj.lewis@icloud.com",url:"https://ctjlewis.com"}],g=["dist/","templates/"],h={node:">=14"},v={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"},y={"@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":"^31.0.0",chalk:"^5.0.1",commander:"^9.0.0","create-debug-logger":"^3.0.0",esbuild:"^0.14.25",eslint:"^8.10.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=["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,platform:s,type:d,version:m,repository:l,description:a,license:c,bin:p,exports:u,types:f,contributors:b,files:g,engines:h,scripts:v,dependencies:y,keywords:S,ava:w,devDependencies:T};import o from"chalk";import{Command as B}from"commander";import{build as x}from"./commands/build/index.js";import{create as C}from"./commands/create/index.js";import{dev as R}from"./commands/dev/index.js";import{execute as j}from"./commands/execute/index.js";import{normalizeImportSpecifiers as A}from"./commands/normalize/index.js";const{version:E}=t,i=new B;i.name(o.white(o.bold("tsmodule"))).usage(o.white(o.bold("<file | command> [options]"))).description(o.blueBright(`A tool for building TypeScript modules.
2
+ var r="@tsmodule/tsmodule",s="node",d="module",m="23.2.0",l="tsmodule/tsmodule",a="TypeScript Module loader and compiler",c="MIT",p={tsmodule:"dist/index.js"},u={".":"./dist/loader/index.js","./*":"./dist/*/index.js","./package.json":"./package.json"},f="dist/types/index.d.ts",b=[{name:"C. Lewis",email:"ctj.lewis@icloud.com",url:"https://ctjlewis.com"}],g=["dist/","templates/"],h={node:">=14"},v={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"},y={"@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":"^31.0.0",chalk:"^5.0.1",commander:"^9.0.0","create-debug-logger":"^3.0.0",esbuild:"^0.14.25",eslint:"^8.10.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=["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,platform:s,type:d,version:m,repository:l,description:a,license:c,bin:p,exports:u,types:f,contributors:b,files:g,engines:h,scripts:v,dependencies:y,keywords:S,ava:w,devDependencies:T};import o from"chalk";import{Command as B}from"commander";import{build as x}from"./commands/build/index.js";import{create as C}from"./commands/create/index.js";import{dev as R}from"./commands/dev/index.js";import{execute as j}from"./commands/execute/index.js";import{normalizeImportSpecifiers as A}from"./commands/normalize/index.js";const{version:E}=t,i=new B;i.name(o.white(o.bold("tsmodule"))).usage(o.white(o.bold("<file | command> [options]"))).description(o.blueBright(`A tool for building TypeScript modules.
3
3
 
4
4
  Run TS directly: ${o.bold("tsmodule src/index.ts")}
5
5
  Use a command: ${o.bold("tsmodule build")}`)).version(String(E)),i.command("dev").description("Build and watch for changes.").action(R),i.command("build").option("--files <files>","Files to build","src/**/*").option("--styles <styles>","The styles to build","src/styles/components/index.css").option("-b, --bundle","Bundle dependencies").option("-d, --dev","Build development runtime").option("-r, --runtime-only","Do not emit type declarations, only build JS runtime").description("Builds TS files to output in dist/.").action(x),i.command("create <name>").option("--react","Create React component library with Next.js").description("Create a new project.").action(C),i.command("normalize [files]").description(`Rewrites import specifiers in files to ESM-compliant paths.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@tsmodule/tsmodule",
3
3
  "platform": "node",
4
4
  "type": "module",
5
- "version": "23.1.0",
5
+ "version": "23.2.0",
6
6
  "repository": "tsmodule/tsmodule",
7
7
  "description": "TypeScript Module loader and compiler",
8
8
  "license": "MIT",