@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
|
2
|
-
\r;]*`,
|
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.
|
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.
|