jiek 1.0.8 → 1.0.10

Sign up to get free protection for your applications and to get access to all the features.
package/dist/cli.cjs CHANGED
@@ -141,7 +141,7 @@ async function getSelectedProjectsGraph() {
141
141
 
142
142
  var name = "jiek";
143
143
  var type = "module";
144
- var version = "1.0.7";
144
+ var version = "1.0.9";
145
145
  var description = "YiJie's personal kits.";
146
146
  var bin = {
147
147
  jiek: "bin/jiek.js",
package/dist/cli.d.cts CHANGED
@@ -46,6 +46,7 @@ interface TemplateOptions {
46
46
  dts: InputPluginOption;
47
47
  };
48
48
  }
49
+
49
50
  declare module 'jiek' {
50
51
  interface Config {
51
52
  build?: TemplateOptions & {
package/dist/cli.d.ts CHANGED
@@ -46,6 +46,7 @@ interface TemplateOptions {
46
46
  dts: InputPluginOption;
47
47
  };
48
48
  }
49
+
49
50
  declare module 'jiek' {
50
51
  interface Config {
51
52
  build?: TemplateOptions & {
package/dist/cli.js CHANGED
@@ -110,7 +110,7 @@ async function getSelectedProjectsGraph() {
110
110
 
111
111
  var name = "jiek";
112
112
  var type = "module";
113
- var version = "1.0.7";
113
+ var version = "1.0.9";
114
114
  var description = "YiJie's personal kits.";
115
115
  var bin = {
116
116
  jiek: "bin/jiek.js",
package/dist/cli.min.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var e=require("node:fs"),t=require("node:module"),n=require("node:path"),r=require("@pnpm/filter-workspace-packages"),o=require("commander"),a=require("js-yaml"),s=require("@jiek/utils/getWorkspaceDir"),i=require("cli-progress"),u=require("execa"),l=require("detect-indent"),p=require("inquirer"),c=require("jsonc-parser"),f=require("util"),d=require("path"),g=require("node:child_process"),h=require("@jiek/utils/bumper"),y=require("@jiek/pkger/entrypoints"),A="undefined"!=typeof document?document.currentScript:null;function R(e){return e&&e.__esModule?e:{default:e}}function m(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var E=R(e),_=R(n),b=R(l),S=R(p),C=R(f),v=R(d),$=m(g);let x,w;function H(){if(x)return x;const e=o.program.getOptionValue("root");return x=e?_.default.isAbsolute(e)?e:_.default.resolve(process.cwd(),e):void 0,x}let k=!1;function O(){if(w)return{wd:w,notWorkspace:k};const e=H();if(void 0!==e){const t=s.isWorkspaceDir(e,T);return k=!t,w=e,{wd:w,notWorkspace:k}}try{w=s.getWorkspaceDir(T)}catch(t){if(!("message"in t)||"workspace root not found"!==t.message)throw t;w=e,k=!0}return{wd:w,notWorkspace:k}}let T="";try{t.createRequire("undefined"==typeof document?require("url").pathToFileURL(__filename).href:A&&A.src||new URL("cli.min.cjs",document.baseURI).href).resolve("@pnpm/filter-workspace-packages"),T="pnpm"}catch{}async function L(){let e=o.program.getOptionValue("filter");const t=H(),{wd:n,notWorkspace:s}=O();if(!s&&"pnpm"===T){const o=_.default.resolve(n,"pnpm-workspace.yaml"),s=E.default.readFileSync(o,"utf-8"),i=a.load(s);if(t===n&&!e)throw new Error("root path is workspace root, please provide a filter");if(t!==n&&!e){if(!E.default.existsSync(_.default.resolve(t,"package.json")))throw new Error("root path is not workspace root, please provide a filter");const n=JSON.parse(E.default.readFileSync(_.default.resolve(t,"package.json"),"utf-8"));if(!n.name)throw new Error("root path is not workspace root, please provide a filter");e=n.name}const{selectedProjectsGraph:u}=await r.filterPackagesFromDir(n,[{filter:e??"",followProdDepsOnly:!0}],{prefix:t,workspaceDir:n,patterns:i.packages});return{wd:n,root:t,value:Object.entries(u).reduce(((e,[t,n])=>(e[t]=n.package.manifest,e)),{})}}return{wd:n,root:t,value:{[n]:JSON.parse(E.default.readFileSync(_.default.resolve(n,"package.json"),"utf-8"))}}}""!==T&&o.program.option("-f, --filter <filter>","filter packages");var N="1.0.7",I="YiJie's personal kits.";let M;function j(){M()}function P(){new Promise((e=>M=e))}o.program.version(N).description(I).option("--root <root>","root path").option("-c, --config-path <configPath>","config path");const B=t.createRequire("undefined"==typeof document?require("url").pathToFileURL(__filename).href:A&&A.src||new URL("cli.min.cjs",document.baseURI).href);function D(e){try{return B.resolve(e),!0}catch(e){return!1}}let U;const G=[process.env.JIEK_TS_REGISTER,"esbuild-register","@swc-node/register","ts-node/register"].filter(Boolean);for(const e of G)if(D(e)){U=e;break}let F="jiek.config";function K(e){const{wd:t}=O();let n=o.program.getOptionValue("configPath");if(n){if(!E.default.existsSync(n))throw new Error(`config file not found: ${n}`);_.default.isAbsolute(n)||(n=_.default.resolve(t,n))}else n=function(e,t){const n=!!U;function r(n){const r=[_.default.resolve(process.cwd(),`${F}.${n}`),_.default.resolve(process.cwd(),`.${F}.${n}`),_.default.resolve(e,`${F}.${n}`),_.default.resolve(e,`.${F}.${n}`)];t&&r.unshift(_.default.resolve(t,`${F}.${n}`),_.default.resolve(t,`.${F}.${n}`));for(const e of r)if(E.default.existsSync(e)&&E.default.lstatSync(e).isFile())return e}return F=r("js")??F,F=r("json")??F,F=r("yaml")??F,n&&(F=r("ts")??F),_.default.resolve(e,F)}(t,e);const r=_.default.extname(n);let s;switch(r){case".js":s=require(n);break;case".json":return require(n);case".yaml":return a.load(E.default.readFileSync(n,"utf-8"));case".ts":if(U){require(U),s=require(n);break}throw new Error("ts config file is not supported without ts register, please install esbuild-register or set JIEK_TS_REGISTER env for custom ts register");case".config":s={};break;default:throw new Error(`unsupported config file type: ${r}`)}if(!s)throw new Error("config file is empty");return s.default??s}const q=t.createRequire("undefined"==typeof document?require("url").pathToFileURL(__filename).href:A&&A.src||new URL("cli.min.cjs",document.baseURI).href);o.program.command("build").option("-s, --silent","Don't display logs.").option("-e, --entries <ENTRIES>","Specify the entries of the package.json's 'exports' field.(support glob)").option("-v, --verbose","Display debug logs.").action((async({silent:e,entries:t,verbose:n})=>{P();const{build:r}=K();e=e??r?.silent??!1;const{wd:o,value:a={}}=await L()??{};if(0===Object.keys(a).length)throw new Error("no package found");const s=_.default.resolve(o,"node_modules");E.default.existsSync(s)||E.default.mkdirSync(s);const l=(...e)=>_.default.resolve(s,".jiek",...e);E.default.existsSync(l())||E.default.mkdirSync(l());const p=q.resolve("rollup").replace(/dist\/rollup.js$/,"dist/bin/rollup"),c=new i.MultiBar({clearOnComplete:!1,hideCursor:!0,format:"- {bar} | {status} | {input} | {message}"},i.Presets.shades_classic);let f=0;await Promise.all(Object.entries(a).map((async([r,a])=>{const s=a.name?.replace(/^@/g,"").replace(/\//g,"+"),i=l(`${s??"anonymous-"+f++}.rollup.config.js`);E.default.writeFileSync(i,(e=>`\nmodule.exports = require('jiek/rollup').template(${JSON.stringify(e,null,2)})\n`.trimStart())(a));let d="";U&&(d=`node -r ${U} `);const g=`${d}${p} --silent -c ${i}`,h=u.execaCommand(g,{ipc:!0,cwd:r,env:{...process.env,JIEK_ROOT:o,JIEK_ENTRIES:t}}),y={};let A=10;h.on("message",(e=>{"debug"===e.type&&console.log(...Array.isArray(e.data)?e.data:[e.data])})),!e&&h.on("message",(e=>{if("init"===e.type){const{leafMap:t,targetsLength:n}=e.data,r=Array.from(t.entries()).flatMap((([e,t])=>t.map((([t,...n])=>({input:e,path:t,conditions:n})))));console.log(`Package '${a.name}' has ${n} targets to build`),r.forEach((({input:e})=>{A=Math.max(A,e.length)})),r.forEach((({input:e,path:t})=>{const n=`${e}:${t}`;y[n]||(y[n]=c.create(50,0,{input:e.padEnd(A),status:"waiting".padEnd(10)},{barsize:20,linewrap:!0}))}))}if("progress"===e.type){const{path:t,tags:n,input:r,event:o,message:a}=e.data,s=y[`${r}:${t}`];if(!s)return;s.update({start:0,resolve:20,end:50}[o??"start"]??0,{input:r.padEnd(A),status:o?.padEnd(10),message:`${n?.join(", ")}: ${a}`})}})),await new Promise(((e,t)=>{let r="";h.stderr?.on("data",(e=>{r+=e})),h.once("exit",(n=>0===n?e():t(new Error(`rollup build failed:\n${r}`)))),n&&h.stdout?.pipe(process.stdout)}))}))).finally((()=>{c.stop()})),j()}));var Q,W,X,Z,J,z,Y,V,ee,te,ne,re,oe,ae,se,ie,ue,le,pe,ce={};function fe(){return Q||(Q=1,(e=ce).isInteger=e=>"number"==typeof e?Number.isInteger(e):"string"==typeof e&&""!==e.trim()&&Number.isInteger(Number(e)),e.find=(e,t)=>e.nodes.find((e=>e.type===t)),e.exceedsLimit=(t,n,r=1,o)=>!1!==o&&!(!e.isInteger(t)||!e.isInteger(n))&&(Number(n)-Number(t))/Number(r)>=o,e.escapeNode=(e,t=0,n)=>{let r=e.nodes[t];r&&(n&&r.type===n||"open"===r.type||"close"===r.type)&&!0!==r.escaped&&(r.value="\\"+r.value,r.escaped=!0)},e.encloseBrace=e=>!("brace"!==e.type||e.commas>>0+e.ranges||(e.invalid=!0,0)),e.isInvalidBrace=e=>!("brace"!==e.type||!0!==e.invalid&&!e.dollar&&(e.commas>>0+e.ranges&&!0===e.open&&!0===e.close||(e.invalid=!0,0))),e.isOpenOrClose=e=>"open"===e.type||"close"===e.type||!0===e.open||!0===e.close,e.reduce=e=>e.reduce(((e,t)=>("text"===t.type&&e.push(t.value),"range"===t.type&&(t.type="text"),e)),[]),e.flatten=(...e)=>{const t=[],n=e=>{for(let r=0;r<e.length;r++){let o=e[r];Array.isArray(o)?n(o):void 0!==o&&t.push(o)}return t};return n(e),t}),ce;var e}function de(){if(X)return W;X=1;const e=fe();return W=(t,n={})=>{let r=(t,o={})=>{let a=n.escapeInvalid&&e.isInvalidBrace(o),s=!0===t.invalid&&!0===n.escapeInvalid,i="";if(t.value)return(a||s)&&e.isOpenOrClose(t)?"\\"+t.value:t.value;if(t.value)return t.value;if(t.nodes)for(let e of t.nodes)i+=r(e);return i};return r(t)}}
1
+ "use strict";var e=require("node:fs"),t=require("node:module"),n=require("node:path"),r=require("@pnpm/filter-workspace-packages"),o=require("commander"),a=require("js-yaml"),s=require("@jiek/utils/getWorkspaceDir"),i=require("cli-progress"),u=require("execa"),l=require("detect-indent"),p=require("inquirer"),c=require("jsonc-parser"),f=require("util"),d=require("path"),g=require("node:child_process"),h=require("@jiek/utils/bumper"),y=require("@jiek/pkger/entrypoints"),A="undefined"!=typeof document?document.currentScript:null;function R(e){return e&&e.__esModule?e:{default:e}}function m(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var E=R(e),_=R(n),b=R(l),S=R(p),C=R(f),v=R(d),$=m(g);let x,w;function H(){if(x)return x;const e=o.program.getOptionValue("root");return x=e?_.default.isAbsolute(e)?e:_.default.resolve(process.cwd(),e):void 0,x}let k=!1;function O(){if(w)return{wd:w,notWorkspace:k};const e=H();if(void 0!==e){const t=s.isWorkspaceDir(e,T);return k=!t,w=e,{wd:w,notWorkspace:k}}try{w=s.getWorkspaceDir(T)}catch(t){if(!("message"in t)||"workspace root not found"!==t.message)throw t;w=e,k=!0}return{wd:w,notWorkspace:k}}let T="";try{t.createRequire("undefined"==typeof document?require("url").pathToFileURL(__filename).href:A&&A.src||new URL("cli.min.cjs",document.baseURI).href).resolve("@pnpm/filter-workspace-packages"),T="pnpm"}catch{}async function L(){let e=o.program.getOptionValue("filter");const t=H(),{wd:n,notWorkspace:s}=O();if(!s&&"pnpm"===T){const o=_.default.resolve(n,"pnpm-workspace.yaml"),s=E.default.readFileSync(o,"utf-8"),i=a.load(s);if(t===n&&!e)throw new Error("root path is workspace root, please provide a filter");if(t!==n&&!e){if(!E.default.existsSync(_.default.resolve(t,"package.json")))throw new Error("root path is not workspace root, please provide a filter");const n=JSON.parse(E.default.readFileSync(_.default.resolve(t,"package.json"),"utf-8"));if(!n.name)throw new Error("root path is not workspace root, please provide a filter");e=n.name}const{selectedProjectsGraph:u}=await r.filterPackagesFromDir(n,[{filter:e??"",followProdDepsOnly:!0}],{prefix:t,workspaceDir:n,patterns:i.packages});return{wd:n,root:t,value:Object.entries(u).reduce(((e,[t,n])=>(e[t]=n.package.manifest,e)),{})}}return{wd:n,root:t,value:{[n]:JSON.parse(E.default.readFileSync(_.default.resolve(n,"package.json"),"utf-8"))}}}""!==T&&o.program.option("-f, --filter <filter>","filter packages");var N="1.0.9",I="YiJie's personal kits.";let M;function j(){M()}function P(){new Promise((e=>M=e))}o.program.version(N).description(I).option("--root <root>","root path").option("-c, --config-path <configPath>","config path");const B=t.createRequire("undefined"==typeof document?require("url").pathToFileURL(__filename).href:A&&A.src||new URL("cli.min.cjs",document.baseURI).href);function D(e){try{return B.resolve(e),!0}catch(e){return!1}}let U;const G=[process.env.JIEK_TS_REGISTER,"esbuild-register","@swc-node/register","ts-node/register"].filter(Boolean);for(const e of G)if(D(e)){U=e;break}let F="jiek.config";function K(e){const{wd:t}=O();let n=o.program.getOptionValue("configPath");if(n){if(!E.default.existsSync(n))throw new Error(`config file not found: ${n}`);_.default.isAbsolute(n)||(n=_.default.resolve(t,n))}else n=function(e,t){const n=!!U;function r(n){const r=[_.default.resolve(process.cwd(),`${F}.${n}`),_.default.resolve(process.cwd(),`.${F}.${n}`),_.default.resolve(e,`${F}.${n}`),_.default.resolve(e,`.${F}.${n}`)];t&&r.unshift(_.default.resolve(t,`${F}.${n}`),_.default.resolve(t,`.${F}.${n}`));for(const e of r)if(E.default.existsSync(e)&&E.default.lstatSync(e).isFile())return e}return F=r("js")??F,F=r("json")??F,F=r("yaml")??F,n&&(F=r("ts")??F),_.default.resolve(e,F)}(t,e);const r=_.default.extname(n);let s;switch(r){case".js":s=require(n);break;case".json":return require(n);case".yaml":return a.load(E.default.readFileSync(n,"utf-8"));case".ts":if(U){require(U),s=require(n);break}throw new Error("ts config file is not supported without ts register, please install esbuild-register or set JIEK_TS_REGISTER env for custom ts register");case".config":s={};break;default:throw new Error(`unsupported config file type: ${r}`)}if(!s)throw new Error("config file is empty");return s.default??s}const q=t.createRequire("undefined"==typeof document?require("url").pathToFileURL(__filename).href:A&&A.src||new URL("cli.min.cjs",document.baseURI).href);o.program.command("build").option("-s, --silent","Don't display logs.").option("-e, --entries <ENTRIES>","Specify the entries of the package.json's 'exports' field.(support glob)").option("-v, --verbose","Display debug logs.").action((async({silent:e,entries:t,verbose:n})=>{P();const{build:r}=K();e=e??r?.silent??!1;const{wd:o,value:a={}}=await L()??{};if(0===Object.keys(a).length)throw new Error("no package found");const s=_.default.resolve(o,"node_modules");E.default.existsSync(s)||E.default.mkdirSync(s);const l=(...e)=>_.default.resolve(s,".jiek",...e);E.default.existsSync(l())||E.default.mkdirSync(l());const p=q.resolve("rollup").replace(/dist\/rollup.js$/,"dist/bin/rollup"),c=new i.MultiBar({clearOnComplete:!1,hideCursor:!0,format:"- {bar} | {status} | {input} | {message}"},i.Presets.shades_classic);let f=0;await Promise.all(Object.entries(a).map((async([r,a])=>{const s=a.name?.replace(/^@/g,"").replace(/\//g,"+"),i=l(`${s??"anonymous-"+f++}.rollup.config.js`);E.default.writeFileSync(i,(e=>`\nmodule.exports = require('jiek/rollup').template(${JSON.stringify(e,null,2)})\n`.trimStart())(a));let d="";U&&(d=`node -r ${U} `);const g=`${d}${p} --silent -c ${i}`,h=u.execaCommand(g,{ipc:!0,cwd:r,env:{...process.env,JIEK_ROOT:o,JIEK_ENTRIES:t}}),y={};let A=10;h.on("message",(e=>{"debug"===e.type&&console.log(...Array.isArray(e.data)?e.data:[e.data])})),!e&&h.on("message",(e=>{if("init"===e.type){const{leafMap:t,targetsLength:n}=e.data,r=Array.from(t.entries()).flatMap((([e,t])=>t.map((([t,...n])=>({input:e,path:t,conditions:n})))));console.log(`Package '${a.name}' has ${n} targets to build`),r.forEach((({input:e})=>{A=Math.max(A,e.length)})),r.forEach((({input:e,path:t})=>{const n=`${e}:${t}`;y[n]||(y[n]=c.create(50,0,{input:e.padEnd(A),status:"waiting".padEnd(10)},{barsize:20,linewrap:!0}))}))}if("progress"===e.type){const{path:t,tags:n,input:r,event:o,message:a}=e.data,s=y[`${r}:${t}`];if(!s)return;s.update({start:0,resolve:20,end:50}[o??"start"]??0,{input:r.padEnd(A),status:o?.padEnd(10),message:`${n?.join(", ")}: ${a}`})}})),await new Promise(((e,t)=>{let r="";h.stderr?.on("data",(e=>{r+=e})),h.once("exit",(n=>0===n?e():t(new Error(`rollup build failed:\n${r}`)))),n&&h.stdout?.pipe(process.stdout)}))}))).finally((()=>{c.stop()})),j()}));var Q,W,X,Z,J,z,Y,V,ee,te,ne,re,oe,ae,se,ie,ue,le,pe,ce={};function fe(){return Q||(Q=1,(e=ce).isInteger=e=>"number"==typeof e?Number.isInteger(e):"string"==typeof e&&""!==e.trim()&&Number.isInteger(Number(e)),e.find=(e,t)=>e.nodes.find((e=>e.type===t)),e.exceedsLimit=(t,n,r=1,o)=>!1!==o&&!(!e.isInteger(t)||!e.isInteger(n))&&(Number(n)-Number(t))/Number(r)>=o,e.escapeNode=(e,t=0,n)=>{let r=e.nodes[t];r&&(n&&r.type===n||"open"===r.type||"close"===r.type)&&!0!==r.escaped&&(r.value="\\"+r.value,r.escaped=!0)},e.encloseBrace=e=>!("brace"!==e.type||e.commas>>0+e.ranges||(e.invalid=!0,0)),e.isInvalidBrace=e=>!("brace"!==e.type||!0!==e.invalid&&!e.dollar&&(e.commas>>0+e.ranges&&!0===e.open&&!0===e.close||(e.invalid=!0,0))),e.isOpenOrClose=e=>"open"===e.type||"close"===e.type||!0===e.open||!0===e.close,e.reduce=e=>e.reduce(((e,t)=>("text"===t.type&&e.push(t.value),"range"===t.type&&(t.type="text"),e)),[]),e.flatten=(...e)=>{const t=[],n=e=>{for(let r=0;r<e.length;r++){let o=e[r];Array.isArray(o)?n(o):void 0!==o&&t.push(o)}return t};return n(e),t}),ce;var e}function de(){if(X)return W;X=1;const e=fe();return W=(t,n={})=>{let r=(t,o={})=>{let a=n.escapeInvalid&&e.isInvalidBrace(o),s=!0===t.invalid&&!0===n.escapeInvalid,i="";if(t.value)return(a||s)&&e.isOpenOrClose(t)?"\\"+t.value:t.value;if(t.value)return t.value;if(t.nodes)for(let e of t.nodes)i+=r(e);return i};return r(t)}}
2
2
  /*!
3
3
  * is-number <https://github.com/jonschlinkert/is-number>
4
4
  *
package/dist/cli.min.js CHANGED
@@ -1,4 +1,4 @@
1
- import e from"node:fs";import{createRequire as t}from"node:module";import n,{resolve as r,relative as o}from"node:path";import{filterPackagesFromDir as s}from"@pnpm/filter-workspace-packages";import{program as a}from"commander";import{load as i}from"js-yaml";import{isWorkspaceDir as u,getWorkspaceDir as p}from"@jiek/utils/getWorkspaceDir";import{MultiBar as l,Presets as c}from"cli-progress";import{execaCommand as f}from"execa";import g from"detect-indent";import d from"inquirer";import{applyEdits as h,modify as A}from"jsonc-parser";import R from"util";import y from"path";import*as m from"node:child_process";import{bump as _}from"@jiek/utils/bumper";import{resolveEntrypoints as E,filterLeafs as b,DEFAULT_SKIP_VALUES as S,entrypoints2Exports as C}from"@jiek/pkger/entrypoints";let v,$;function x(){if(v)return v;const e=a.getOptionValue("root");return v=e?n.isAbsolute(e)?e:n.resolve(process.cwd(),e):void 0,v}let w=!1;function H(){if($)return{wd:$,notWorkspace:w};const e=x();if(void 0!==e){const t=u(e,k);return w=!t,$=e,{wd:$,notWorkspace:w}}try{$=p(k)}catch(t){if(!("message"in t)||"workspace root not found"!==t.message)throw t;$=e,w=!0}return{wd:$,notWorkspace:w}}let k="";try{t(import.meta.url).resolve("@pnpm/filter-workspace-packages"),k="pnpm"}catch{}async function O(){let t=a.getOptionValue("filter");const r=x(),{wd:o,notWorkspace:u}=H();if(!u&&"pnpm"===k){const a=n.resolve(o,"pnpm-workspace.yaml"),u=e.readFileSync(a,"utf-8"),p=i(u);if(r===o&&!t)throw new Error("root path is workspace root, please provide a filter");if(r!==o&&!t){if(!e.existsSync(n.resolve(r,"package.json")))throw new Error("root path is not workspace root, please provide a filter");const o=JSON.parse(e.readFileSync(n.resolve(r,"package.json"),"utf-8"));if(!o.name)throw new Error("root path is not workspace root, please provide a filter");t=o.name}const{selectedProjectsGraph:l}=await s(o,[{filter:t??"",followProdDepsOnly:!0}],{prefix:r,workspaceDir:o,patterns:p.packages});return{wd:o,root:r,value:Object.entries(l).reduce(((e,[t,n])=>(e[t]=n.package.manifest,e)),{})}}return{wd:o,root:r,value:{[o]:JSON.parse(e.readFileSync(n.resolve(o,"package.json"),"utf-8"))}}}""!==k&&a.option("-f, --filter <filter>","filter packages");var T="1.0.7",L="YiJie's personal kits.";let N;function I(){N()}function M(){new Promise((e=>N=e))}a.version(T).description(L).option("--root <root>","root path").option("-c, --config-path <configPath>","config path");const j=t(import.meta.url);function B(e){try{return j.resolve(e),!0}catch(e){return!1}}let P;const D=[process.env.JIEK_TS_REGISTER,"esbuild-register","@swc-node/register","ts-node/register"].filter(Boolean);for(const e of D)if(B(e)){P=e;break}let G="jiek.config";function K(t){const{wd:r}=H();let o=a.getOptionValue("configPath");if(o){if(!e.existsSync(o))throw new Error(`config file not found: ${o}`);n.isAbsolute(o)||(o=n.resolve(r,o))}else o=function(t,r){const o=!!P;function s(o){const s=[n.resolve(process.cwd(),`${G}.${o}`),n.resolve(process.cwd(),`.${G}.${o}`),n.resolve(t,`${G}.${o}`),n.resolve(t,`.${G}.${o}`)];r&&s.unshift(n.resolve(r,`${G}.${o}`),n.resolve(r,`.${G}.${o}`));for(const t of s)if(e.existsSync(t)&&e.lstatSync(t).isFile())return t}return G=s("js")??G,G=s("json")??G,G=s("yaml")??G,o&&(G=s("ts")??G),n.resolve(t,G)}(r,t);const s=n.extname(o);let u;switch(s){case".js":u=require(o);break;case".json":return require(o);case".yaml":return i(e.readFileSync(o,"utf-8"));case".ts":if(P){require(P),u=require(o);break}throw new Error("ts config file is not supported without ts register, please install esbuild-register or set JIEK_TS_REGISTER env for custom ts register");case".config":u={};break;default:throw new Error(`unsupported config file type: ${s}`)}if(!u)throw new Error("config file is empty");return u.default??u}const U=t(import.meta.url);a.command("build").option("-s, --silent","Don't display logs.").option("-e, --entries <ENTRIES>","Specify the entries of the package.json's 'exports' field.(support glob)").option("-v, --verbose","Display debug logs.").action((async({silent:t,entries:r,verbose:o})=>{M();const{build:s}=K();t=t??s?.silent??!1;const{wd:a,value:i={}}=await O()??{};if(0===Object.keys(i).length)throw new Error("no package found");const u=n.resolve(a,"node_modules");e.existsSync(u)||e.mkdirSync(u);const p=(...e)=>n.resolve(u,".jiek",...e);e.existsSync(p())||e.mkdirSync(p());const g=U.resolve("rollup").replace(/dist\/rollup.js$/,"dist/bin/rollup"),d=new l({clearOnComplete:!1,hideCursor:!0,format:"- {bar} | {status} | {input} | {message}"},c.shades_classic);let h=0;await Promise.all(Object.entries(i).map((async([n,s])=>{const i=s.name?.replace(/^@/g,"").replace(/\//g,"+"),u=p(`${i??"anonymous-"+h++}.rollup.config.js`);e.writeFileSync(u,(e=>`\nmodule.exports = require('jiek/rollup').template(${JSON.stringify(e,null,2)})\n`.trimStart())(s));let l="";P&&(l=`node -r ${P} `);const c=f(`${l}${g} --silent -c ${u}`,{ipc:!0,cwd:n,env:{...process.env,JIEK_ROOT:a,JIEK_ENTRIES:r}}),A={};let R=10;c.on("message",(e=>{"debug"===e.type&&console.log(...Array.isArray(e.data)?e.data:[e.data])})),!t&&c.on("message",(e=>{if("init"===e.type){const{leafMap:t,targetsLength:n}=e.data,r=Array.from(t.entries()).flatMap((([e,t])=>t.map((([t,...n])=>({input:e,path:t,conditions:n})))));console.log(`Package '${s.name}' has ${n} targets to build`),r.forEach((({input:e})=>{R=Math.max(R,e.length)})),r.forEach((({input:e,path:t})=>{const n=`${e}:${t}`;A[n]||(A[n]=d.create(50,0,{input:e.padEnd(R),status:"waiting".padEnd(10)},{barsize:20,linewrap:!0}))}))}if("progress"===e.type){const{path:t,tags:n,input:r,event:o,message:s}=e.data,a=A[`${r}:${t}`];if(!a)return;a.update({start:0,resolve:20,end:50}[o??"start"]??0,{input:r.padEnd(R),status:o?.padEnd(10),message:`${n?.join(", ")}: ${s}`})}})),await new Promise(((e,t)=>{let n="";c.stderr?.on("data",(e=>{n+=e})),c.once("exit",(r=>0===r?e():t(new Error(`rollup build failed:\n${n}`)))),o&&c.stdout?.pipe(process.stdout)}))}))).finally((()=>{d.stop()})),I()}));var F,Q,W,X,q,Z,J,Y,z,V,ee,te,ne,re,oe,se,ae,ie,ue,pe={};function le(){return F||(F=1,function(e){e.isInteger=e=>"number"==typeof e?Number.isInteger(e):"string"==typeof e&&""!==e.trim()&&Number.isInteger(Number(e)),e.find=(e,t)=>e.nodes.find((e=>e.type===t)),e.exceedsLimit=(t,n,r=1,o)=>!1!==o&&(!(!e.isInteger(t)||!e.isInteger(n))&&(Number(n)-Number(t))/Number(r)>=o),e.escapeNode=(e,t=0,n)=>{let r=e.nodes[t];r&&(n&&r.type===n||"open"===r.type||"close"===r.type)&&!0!==r.escaped&&(r.value="\\"+r.value,r.escaped=!0)},e.encloseBrace=e=>"brace"===e.type&&(!(e.commas>>0+e.ranges)&&(e.invalid=!0,!0)),e.isInvalidBrace=e=>"brace"===e.type&&(!(!0!==e.invalid&&!e.dollar)||(e.commas>>0+e.ranges?(!0!==e.open||!0!==e.close)&&(e.invalid=!0,!0):(e.invalid=!0,!0))),e.isOpenOrClose=e=>"open"===e.type||"close"===e.type||(!0===e.open||!0===e.close),e.reduce=e=>e.reduce(((e,t)=>("text"===t.type&&e.push(t.value),"range"===t.type&&(t.type="text"),e)),[]),e.flatten=(...e)=>{const t=[],n=e=>{for(let r=0;r<e.length;r++){let o=e[r];Array.isArray(o)?n(o):void 0!==o&&t.push(o)}return t};return n(e),t}}(pe)),pe}function ce(){if(W)return Q;W=1;const e=le();return Q=(t,n={})=>{let r=(t,o={})=>{let s=n.escapeInvalid&&e.isInvalidBrace(o),a=!0===t.invalid&&!0===n.escapeInvalid,i="";if(t.value)return(s||a)&&e.isOpenOrClose(t)?"\\"+t.value:t.value;if(t.value)return t.value;if(t.nodes)for(let e of t.nodes)i+=r(e);return i};return r(t)}}
1
+ import e from"node:fs";import{createRequire as t}from"node:module";import n,{resolve as r,relative as o}from"node:path";import{filterPackagesFromDir as s}from"@pnpm/filter-workspace-packages";import{program as a}from"commander";import{load as i}from"js-yaml";import{isWorkspaceDir as u,getWorkspaceDir as p}from"@jiek/utils/getWorkspaceDir";import{MultiBar as l,Presets as c}from"cli-progress";import{execaCommand as f}from"execa";import g from"detect-indent";import d from"inquirer";import{applyEdits as h,modify as A}from"jsonc-parser";import R from"util";import y from"path";import*as m from"node:child_process";import{bump as _}from"@jiek/utils/bumper";import{resolveEntrypoints as E,filterLeafs as b,DEFAULT_SKIP_VALUES as S,entrypoints2Exports as C}from"@jiek/pkger/entrypoints";let v,$;function x(){if(v)return v;const e=a.getOptionValue("root");return v=e?n.isAbsolute(e)?e:n.resolve(process.cwd(),e):void 0,v}let w=!1;function H(){if($)return{wd:$,notWorkspace:w};const e=x();if(void 0!==e){const t=u(e,k);return w=!t,$=e,{wd:$,notWorkspace:w}}try{$=p(k)}catch(t){if(!("message"in t)||"workspace root not found"!==t.message)throw t;$=e,w=!0}return{wd:$,notWorkspace:w}}let k="";try{t(import.meta.url).resolve("@pnpm/filter-workspace-packages"),k="pnpm"}catch{}async function O(){let t=a.getOptionValue("filter");const r=x(),{wd:o,notWorkspace:u}=H();if(!u&&"pnpm"===k){const a=n.resolve(o,"pnpm-workspace.yaml"),u=e.readFileSync(a,"utf-8"),p=i(u);if(r===o&&!t)throw new Error("root path is workspace root, please provide a filter");if(r!==o&&!t){if(!e.existsSync(n.resolve(r,"package.json")))throw new Error("root path is not workspace root, please provide a filter");const o=JSON.parse(e.readFileSync(n.resolve(r,"package.json"),"utf-8"));if(!o.name)throw new Error("root path is not workspace root, please provide a filter");t=o.name}const{selectedProjectsGraph:l}=await s(o,[{filter:t??"",followProdDepsOnly:!0}],{prefix:r,workspaceDir:o,patterns:p.packages});return{wd:o,root:r,value:Object.entries(l).reduce(((e,[t,n])=>(e[t]=n.package.manifest,e)),{})}}return{wd:o,root:r,value:{[o]:JSON.parse(e.readFileSync(n.resolve(o,"package.json"),"utf-8"))}}}""!==k&&a.option("-f, --filter <filter>","filter packages");var T="1.0.9",L="YiJie's personal kits.";let N;function I(){N()}function M(){new Promise((e=>N=e))}a.version(T).description(L).option("--root <root>","root path").option("-c, --config-path <configPath>","config path");const j=t(import.meta.url);function B(e){try{return j.resolve(e),!0}catch(e){return!1}}let P;const D=[process.env.JIEK_TS_REGISTER,"esbuild-register","@swc-node/register","ts-node/register"].filter(Boolean);for(const e of D)if(B(e)){P=e;break}let G="jiek.config";function K(t){const{wd:r}=H();let o=a.getOptionValue("configPath");if(o){if(!e.existsSync(o))throw new Error(`config file not found: ${o}`);n.isAbsolute(o)||(o=n.resolve(r,o))}else o=function(t,r){const o=!!P;function s(o){const s=[n.resolve(process.cwd(),`${G}.${o}`),n.resolve(process.cwd(),`.${G}.${o}`),n.resolve(t,`${G}.${o}`),n.resolve(t,`.${G}.${o}`)];r&&s.unshift(n.resolve(r,`${G}.${o}`),n.resolve(r,`.${G}.${o}`));for(const t of s)if(e.existsSync(t)&&e.lstatSync(t).isFile())return t}return G=s("js")??G,G=s("json")??G,G=s("yaml")??G,o&&(G=s("ts")??G),n.resolve(t,G)}(r,t);const s=n.extname(o);let u;switch(s){case".js":u=require(o);break;case".json":return require(o);case".yaml":return i(e.readFileSync(o,"utf-8"));case".ts":if(P){require(P),u=require(o);break}throw new Error("ts config file is not supported without ts register, please install esbuild-register or set JIEK_TS_REGISTER env for custom ts register");case".config":u={};break;default:throw new Error(`unsupported config file type: ${s}`)}if(!u)throw new Error("config file is empty");return u.default??u}const U=t(import.meta.url);a.command("build").option("-s, --silent","Don't display logs.").option("-e, --entries <ENTRIES>","Specify the entries of the package.json's 'exports' field.(support glob)").option("-v, --verbose","Display debug logs.").action((async({silent:t,entries:r,verbose:o})=>{M();const{build:s}=K();t=t??s?.silent??!1;const{wd:a,value:i={}}=await O()??{};if(0===Object.keys(i).length)throw new Error("no package found");const u=n.resolve(a,"node_modules");e.existsSync(u)||e.mkdirSync(u);const p=(...e)=>n.resolve(u,".jiek",...e);e.existsSync(p())||e.mkdirSync(p());const g=U.resolve("rollup").replace(/dist\/rollup.js$/,"dist/bin/rollup"),d=new l({clearOnComplete:!1,hideCursor:!0,format:"- {bar} | {status} | {input} | {message}"},c.shades_classic);let h=0;await Promise.all(Object.entries(i).map((async([n,s])=>{const i=s.name?.replace(/^@/g,"").replace(/\//g,"+"),u=p(`${i??"anonymous-"+h++}.rollup.config.js`);e.writeFileSync(u,(e=>`\nmodule.exports = require('jiek/rollup').template(${JSON.stringify(e,null,2)})\n`.trimStart())(s));let l="";P&&(l=`node -r ${P} `);const c=f(`${l}${g} --silent -c ${u}`,{ipc:!0,cwd:n,env:{...process.env,JIEK_ROOT:a,JIEK_ENTRIES:r}}),A={};let R=10;c.on("message",(e=>{"debug"===e.type&&console.log(...Array.isArray(e.data)?e.data:[e.data])})),!t&&c.on("message",(e=>{if("init"===e.type){const{leafMap:t,targetsLength:n}=e.data,r=Array.from(t.entries()).flatMap((([e,t])=>t.map((([t,...n])=>({input:e,path:t,conditions:n})))));console.log(`Package '${s.name}' has ${n} targets to build`),r.forEach((({input:e})=>{R=Math.max(R,e.length)})),r.forEach((({input:e,path:t})=>{const n=`${e}:${t}`;A[n]||(A[n]=d.create(50,0,{input:e.padEnd(R),status:"waiting".padEnd(10)},{barsize:20,linewrap:!0}))}))}if("progress"===e.type){const{path:t,tags:n,input:r,event:o,message:s}=e.data,a=A[`${r}:${t}`];if(!a)return;a.update({start:0,resolve:20,end:50}[o??"start"]??0,{input:r.padEnd(R),status:o?.padEnd(10),message:`${n?.join(", ")}: ${s}`})}})),await new Promise(((e,t)=>{let n="";c.stderr?.on("data",(e=>{n+=e})),c.once("exit",(r=>0===r?e():t(new Error(`rollup build failed:\n${n}`)))),o&&c.stdout?.pipe(process.stdout)}))}))).finally((()=>{d.stop()})),I()}));var F,Q,W,X,q,Z,J,Y,z,V,ee,te,ne,re,oe,se,ae,ie,ue,pe={};function le(){return F||(F=1,function(e){e.isInteger=e=>"number"==typeof e?Number.isInteger(e):"string"==typeof e&&""!==e.trim()&&Number.isInteger(Number(e)),e.find=(e,t)=>e.nodes.find((e=>e.type===t)),e.exceedsLimit=(t,n,r=1,o)=>!1!==o&&(!(!e.isInteger(t)||!e.isInteger(n))&&(Number(n)-Number(t))/Number(r)>=o),e.escapeNode=(e,t=0,n)=>{let r=e.nodes[t];r&&(n&&r.type===n||"open"===r.type||"close"===r.type)&&!0!==r.escaped&&(r.value="\\"+r.value,r.escaped=!0)},e.encloseBrace=e=>"brace"===e.type&&(!(e.commas>>0+e.ranges)&&(e.invalid=!0,!0)),e.isInvalidBrace=e=>"brace"===e.type&&(!(!0!==e.invalid&&!e.dollar)||(e.commas>>0+e.ranges?(!0!==e.open||!0!==e.close)&&(e.invalid=!0,!0):(e.invalid=!0,!0))),e.isOpenOrClose=e=>"open"===e.type||"close"===e.type||(!0===e.open||!0===e.close),e.reduce=e=>e.reduce(((e,t)=>("text"===t.type&&e.push(t.value),"range"===t.type&&(t.type="text"),e)),[]),e.flatten=(...e)=>{const t=[],n=e=>{for(let r=0;r<e.length;r++){let o=e[r];Array.isArray(o)?n(o):void 0!==o&&t.push(o)}return t};return n(e),t}}(pe)),pe}function ce(){if(W)return Q;W=1;const e=le();return Q=(t,n={})=>{let r=(t,o={})=>{let s=n.escapeInvalid&&e.isInvalidBrace(o),a=!0===t.invalid&&!0===n.escapeInvalid,i="";if(t.value)return(s||a)&&e.isOpenOrClose(t)?"\\"+t.value:t.value;if(t.value)return t.value;if(t.nodes)for(let e of t.nodes)i+=r(e);return i};return r(t)}}
2
2
  /*!
3
3
  * is-number <https://github.com/jonschlinkert/is-number>
4
4
  *
package/dist/index.d.cts CHANGED
@@ -1,3 +1,65 @@
1
+ import { InputPluginOption, OutputOptions } from 'rollup';
2
+
3
+ type Mapping2ROO<K extends keyof OutputOptions> = OutputOptions[K] | {
4
+ js?: OutputOptions[K];
5
+ dts?: OutputOptions[K];
6
+ };
7
+ interface ConfigGenerateContext {
8
+ path: string;
9
+ name: string;
10
+ input: string;
11
+ output: string;
12
+ external: (string | RegExp)[];
13
+ pkgIsModule: boolean;
14
+ conditionals: string[];
15
+ }
16
+ interface TemplateOptions {
17
+ /**
18
+ * When the user configures type: module, the generated output from entry points that don't
19
+ * have cts as a suffix will automatically include the CJS version.
20
+ * if it is not configured, and the generated output from entry points that do not have mts
21
+ * as a suffix will automatically include the ESM version.
22
+ *
23
+ * @default true
24
+ */
25
+ crossModuleConvertor?: boolean;
26
+ output?: {
27
+ /**
28
+ * @default true
29
+ *
30
+ * When minify is set to true, the output will with minified files.
31
+ * When minify is set to 'only-minify', the output will direct output minified files.
32
+ */
33
+ minify?: boolean | 'only-minify';
34
+ /**
35
+ * @default 'dist'
36
+ */
37
+ dir?: Mapping2ROO<'dir'>;
38
+ sourcemap?: Mapping2ROO<'sourcemap'>;
39
+ strict?: Mapping2ROO<'strict'>;
40
+ };
41
+ plugins?: InputPluginOption | ((type: 'js' | 'dts', context: ConfigGenerateContext) => InputPluginOption) | {
42
+ js: InputPluginOption;
43
+ dts?: InputPluginOption;
44
+ } | {
45
+ js?: InputPluginOption;
46
+ dts: InputPluginOption;
47
+ };
48
+ }
49
+
50
+ declare module 'jiek' {
51
+ interface Config {
52
+ build?: TemplateOptions & {
53
+ /**
54
+ * Whether to run in silent mode, only active when configured in the workspace root or cwd.
55
+ *
56
+ * @default false
57
+ */
58
+ silent?: boolean;
59
+ };
60
+ }
61
+ }
62
+
1
63
  declare module 'jiek' {
2
64
  type InitNamedFunction = (argument: string, paths: {
3
65
  full: string;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,65 @@
1
+ import { InputPluginOption, OutputOptions } from 'rollup';
2
+
3
+ type Mapping2ROO<K extends keyof OutputOptions> = OutputOptions[K] | {
4
+ js?: OutputOptions[K];
5
+ dts?: OutputOptions[K];
6
+ };
7
+ interface ConfigGenerateContext {
8
+ path: string;
9
+ name: string;
10
+ input: string;
11
+ output: string;
12
+ external: (string | RegExp)[];
13
+ pkgIsModule: boolean;
14
+ conditionals: string[];
15
+ }
16
+ interface TemplateOptions {
17
+ /**
18
+ * When the user configures type: module, the generated output from entry points that don't
19
+ * have cts as a suffix will automatically include the CJS version.
20
+ * if it is not configured, and the generated output from entry points that do not have mts
21
+ * as a suffix will automatically include the ESM version.
22
+ *
23
+ * @default true
24
+ */
25
+ crossModuleConvertor?: boolean;
26
+ output?: {
27
+ /**
28
+ * @default true
29
+ *
30
+ * When minify is set to true, the output will with minified files.
31
+ * When minify is set to 'only-minify', the output will direct output minified files.
32
+ */
33
+ minify?: boolean | 'only-minify';
34
+ /**
35
+ * @default 'dist'
36
+ */
37
+ dir?: Mapping2ROO<'dir'>;
38
+ sourcemap?: Mapping2ROO<'sourcemap'>;
39
+ strict?: Mapping2ROO<'strict'>;
40
+ };
41
+ plugins?: InputPluginOption | ((type: 'js' | 'dts', context: ConfigGenerateContext) => InputPluginOption) | {
42
+ js: InputPluginOption;
43
+ dts?: InputPluginOption;
44
+ } | {
45
+ js?: InputPluginOption;
46
+ dts: InputPluginOption;
47
+ };
48
+ }
49
+
50
+ declare module 'jiek' {
51
+ interface Config {
52
+ build?: TemplateOptions & {
53
+ /**
54
+ * Whether to run in silent mode, only active when configured in the workspace root or cwd.
55
+ *
56
+ * @default false
57
+ */
58
+ silent?: boolean;
59
+ };
60
+ }
61
+ }
62
+
1
63
  declare module 'jiek' {
2
64
  type InitNamedFunction = (argument: string, paths: {
3
65
  full: string;
@@ -33,6 +33,16 @@ var ts__default = /*#__PURE__*/_interopDefault(ts);
33
33
  var require$$0__default = /*#__PURE__*/_interopDefault(require$$0);
34
34
  var require$$0__default$1 = /*#__PURE__*/_interopDefault(require$$0$1);
35
35
 
36
+ const recusiveListFiles = (dir) => fs__default.default.readdirSync(dir).reduce((acc, file) => {
37
+ const filePath = path.resolve(dir, file);
38
+ if (fs__default.default.statSync(filePath).isDirectory()) {
39
+ if (filePath.endsWith("/node_modules"))
40
+ return acc;
41
+ return [...acc, ...recusiveListFiles(filePath)];
42
+ }
43
+ return [...acc, filePath];
44
+ }, []);
45
+
36
46
  var utils$1 = {};
37
47
 
38
48
  var hasRequiredUtils$1;
@@ -4216,7 +4226,7 @@ function getRoot() {
4216
4226
 
4217
4227
  let type = "";
4218
4228
  try {
4219
- const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
4229
+ const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('rollup/index.cjs', document.baseURI).href)));
4220
4230
  require$1.resolve("@pnpm/filter-workspace-packages");
4221
4231
  type = "pnpm";
4222
4232
  } catch {
@@ -4250,7 +4260,7 @@ function getWD() {
4250
4260
  return { wd, notWorkspace };
4251
4261
  }
4252
4262
 
4253
- const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
4263
+ const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('rollup/index.cjs', document.baseURI).href)));
4254
4264
  function packageIsExist(name) {
4255
4265
  try {
4256
4266
  require$1.resolve(name);
@@ -4511,7 +4521,9 @@ const withMinify = (output, minify = build?.output?.minify) => minify === false
4511
4521
  ...output,
4512
4522
  // TODO replace suffix when pubish to npm and the `build.output.minify` is 'only-minify'
4513
4523
  // TODO resolve dts output file name
4514
- file: output.file?.replace(/(\.[cm]?js)$/, ".min$1"),
4524
+ entryFileNames: (chunkInfo) => typeof output.entryFileNames === "function" ? output.entryFileNames(chunkInfo).replace(/(\.[cm]?js)$/, ".min$1") : (() => {
4525
+ throw new Error("entryFileNames must be a function");
4526
+ })(),
4515
4527
  plugins: [
4516
4528
  ...output.plugins ?? [],
4517
4529
  terser__default.default()
@@ -4520,6 +4532,9 @@ const withMinify = (output, minify = build?.output?.minify) => minify === false
4520
4532
  output,
4521
4533
  {
4522
4534
  ...output,
4535
+ entryFileNames: (chunkInfo) => typeof output.entryFileNames === "function" ? output.entryFileNames(chunkInfo).replace(/(\.[cm]?js)$/, ".min$1") : (() => {
4536
+ throw new Error("entryFileNames must be a function");
4537
+ })(),
4523
4538
  file: output.file?.replace(/(\.[cm]?js)$/, ".min$1"),
4524
4539
  plugins: [
4525
4540
  ...output.plugins ?? [],
@@ -4570,15 +4585,23 @@ const generateConfigs = (context, options = {}) => {
4570
4585
  };
4571
4586
  const outdir = options?.output?.dir;
4572
4587
  const { js: jsPlugins, dts: dtsPlugins } = resolveBuildPlugins(context, build.plugins);
4588
+ if (input.includes("**")) {
4589
+ throw new Error(
4590
+ 'input should not include "**", please read the [documentation](https://nodejs.org/api/packages.html#subpath-patterns).'
4591
+ );
4592
+ }
4593
+ const inputObj = !input.includes("*") ? input : recusiveListFiles(process.cwd()).filter((p) => /(?<!\.d)\.[cm]?tsx?$/.test(p));
4594
+ const globCommonDir = input.includes("*") ? input.split("*")[0] : "";
4573
4595
  return [
4574
4596
  {
4575
- input,
4597
+ input: inputObj,
4576
4598
  external,
4577
4599
  output: [
4578
4600
  ...withMinify({
4579
- file: output,
4601
+ dir: jsOutdir,
4580
4602
  name,
4581
4603
  interop: "auto",
4604
+ entryFileNames: (chunkInfo) => Array.isArray(inputObj) ? chunkInfo.facadeModuleId.replace(`${process.cwd()}/`, "./").replace(globCommonDir, "").replace(/(\.[cm]?)ts$/, "$1js") : output.replace(`${jsOutdir}/`, ""),
4582
4605
  sourcemap: typeof options?.output?.sourcemap === "object" ? options.output.sourcemap.js : options?.output?.sourcemap,
4583
4606
  format: isModule ? "esm" : isCommonJS ? "cjs" : isBrowser ? "umd" : pkgIsModule ? "esm" : "cjs",
4584
4607
  strict: typeof options?.output?.strict === "object" ? options.output.strict.js : options?.output?.strict
@@ -4608,13 +4631,13 @@ const generateConfigs = (context, options = {}) => {
4608
4631
  ]
4609
4632
  },
4610
4633
  {
4611
- input,
4634
+ input: inputObj,
4612
4635
  external,
4613
4636
  output: [
4614
4637
  {
4615
4638
  dir: path.resolve((typeof outdir === "object" ? outdir.dts : outdir) ?? "dist"),
4616
4639
  sourcemap: typeof options?.output?.sourcemap === "object" ? options.output.sourcemap.dts : options?.output?.sourcemap,
4617
- entryFileNames: () => output.replace(`${jsOutdir}/`, "").replace(/(\.[cm]?)js$/, ".d$1ts"),
4640
+ entryFileNames: (chunkInfo) => Array.isArray(inputObj) ? chunkInfo.facadeModuleId.replace(`${process.cwd()}/`, "./").replace(globCommonDir, "").replace(/(\.[cm]?)ts$/, ".d$1ts") : output.replace(`${jsOutdir}/`, "").replace(/(\.[cm]?)js$/, ".d$1ts"),
4618
4641
  strict: typeof options?.output?.strict === "object" ? options.output.strict.dts : options?.output?.strict
4619
4642
  }
4620
4643
  ],
@@ -1,63 +1,4 @@
1
- import { InputPluginOption, OutputOptions, RollupOptions } from 'rollup';
2
-
3
- type Mapping2ROO<K extends keyof OutputOptions> = OutputOptions[K] | {
4
- js?: OutputOptions[K];
5
- dts?: OutputOptions[K];
6
- };
7
- interface ConfigGenerateContext {
8
- path: string;
9
- name: string;
10
- input: string;
11
- output: string;
12
- external: (string | RegExp)[];
13
- pkgIsModule: boolean;
14
- conditionals: string[];
15
- }
16
- interface TemplateOptions {
17
- /**
18
- * When the user configures type: module, the generated output from entry points that don't
19
- * have cts as a suffix will automatically include the CJS version.
20
- * if it is not configured, and the generated output from entry points that do not have mts
21
- * as a suffix will automatically include the ESM version.
22
- *
23
- * @default true
24
- */
25
- crossModuleConvertor?: boolean;
26
- output?: {
27
- /**
28
- * @default true
29
- *
30
- * When minify is set to true, the output will with minified files.
31
- * When minify is set to 'only-minify', the output will direct output minified files.
32
- */
33
- minify?: boolean | 'only-minify';
34
- /**
35
- * @default 'dist'
36
- */
37
- dir?: Mapping2ROO<'dir'>;
38
- sourcemap?: Mapping2ROO<'sourcemap'>;
39
- strict?: Mapping2ROO<'strict'>;
40
- };
41
- plugins?: InputPluginOption | ((type: 'js' | 'dts', context: ConfigGenerateContext) => InputPluginOption) | {
42
- js: InputPluginOption;
43
- dts?: InputPluginOption;
44
- } | {
45
- js?: InputPluginOption;
46
- dts: InputPluginOption;
47
- };
48
- }
49
- declare module 'jiek' {
50
- interface Config {
51
- build?: TemplateOptions & {
52
- /**
53
- * Whether to run in silent mode, only active when configured in the workspace root or cwd.
54
- *
55
- * @default false
56
- */
57
- silent?: boolean;
58
- };
59
- }
60
- }
1
+ import { RollupOptions } from 'rollup';
61
2
 
62
3
  interface PackageJSON {
63
4
  name?: string;
@@ -1,63 +1,4 @@
1
- import { InputPluginOption, OutputOptions, RollupOptions } from 'rollup';
2
-
3
- type Mapping2ROO<K extends keyof OutputOptions> = OutputOptions[K] | {
4
- js?: OutputOptions[K];
5
- dts?: OutputOptions[K];
6
- };
7
- interface ConfigGenerateContext {
8
- path: string;
9
- name: string;
10
- input: string;
11
- output: string;
12
- external: (string | RegExp)[];
13
- pkgIsModule: boolean;
14
- conditionals: string[];
15
- }
16
- interface TemplateOptions {
17
- /**
18
- * When the user configures type: module, the generated output from entry points that don't
19
- * have cts as a suffix will automatically include the CJS version.
20
- * if it is not configured, and the generated output from entry points that do not have mts
21
- * as a suffix will automatically include the ESM version.
22
- *
23
- * @default true
24
- */
25
- crossModuleConvertor?: boolean;
26
- output?: {
27
- /**
28
- * @default true
29
- *
30
- * When minify is set to true, the output will with minified files.
31
- * When minify is set to 'only-minify', the output will direct output minified files.
32
- */
33
- minify?: boolean | 'only-minify';
34
- /**
35
- * @default 'dist'
36
- */
37
- dir?: Mapping2ROO<'dir'>;
38
- sourcemap?: Mapping2ROO<'sourcemap'>;
39
- strict?: Mapping2ROO<'strict'>;
40
- };
41
- plugins?: InputPluginOption | ((type: 'js' | 'dts', context: ConfigGenerateContext) => InputPluginOption) | {
42
- js: InputPluginOption;
43
- dts?: InputPluginOption;
44
- } | {
45
- js?: InputPluginOption;
46
- dts: InputPluginOption;
47
- };
48
- }
49
- declare module 'jiek' {
50
- interface Config {
51
- build?: TemplateOptions & {
52
- /**
53
- * Whether to run in silent mode, only active when configured in the workspace root or cwd.
54
- *
55
- * @default false
56
- */
57
- silent?: boolean;
58
- };
59
- }
60
- }
1
+ import { RollupOptions } from 'rollup';
61
2
 
62
3
  interface PackageJSON {
63
4
  name?: string;
@@ -18,6 +18,16 @@ import { createRequire } from 'node:module';
18
18
  import '@pnpm/filter-workspace-packages';
19
19
  import { parse } from 'jsonc-parser';
20
20
 
21
+ const recusiveListFiles = (dir) => fs.readdirSync(dir).reduce((acc, file) => {
22
+ const filePath = resolve(dir, file);
23
+ if (fs.statSync(filePath).isDirectory()) {
24
+ if (filePath.endsWith("/node_modules"))
25
+ return acc;
26
+ return [...acc, ...recusiveListFiles(filePath)];
27
+ }
28
+ return [...acc, filePath];
29
+ }, []);
30
+
21
31
  var utils$1 = {};
22
32
 
23
33
  var hasRequiredUtils$1;
@@ -4496,7 +4506,9 @@ const withMinify = (output, minify = build?.output?.minify) => minify === false
4496
4506
  ...output,
4497
4507
  // TODO replace suffix when pubish to npm and the `build.output.minify` is 'only-minify'
4498
4508
  // TODO resolve dts output file name
4499
- file: output.file?.replace(/(\.[cm]?js)$/, ".min$1"),
4509
+ entryFileNames: (chunkInfo) => typeof output.entryFileNames === "function" ? output.entryFileNames(chunkInfo).replace(/(\.[cm]?js)$/, ".min$1") : (() => {
4510
+ throw new Error("entryFileNames must be a function");
4511
+ })(),
4500
4512
  plugins: [
4501
4513
  ...output.plugins ?? [],
4502
4514
  terser()
@@ -4505,6 +4517,9 @@ const withMinify = (output, minify = build?.output?.minify) => minify === false
4505
4517
  output,
4506
4518
  {
4507
4519
  ...output,
4520
+ entryFileNames: (chunkInfo) => typeof output.entryFileNames === "function" ? output.entryFileNames(chunkInfo).replace(/(\.[cm]?js)$/, ".min$1") : (() => {
4521
+ throw new Error("entryFileNames must be a function");
4522
+ })(),
4508
4523
  file: output.file?.replace(/(\.[cm]?js)$/, ".min$1"),
4509
4524
  plugins: [
4510
4525
  ...output.plugins ?? [],
@@ -4555,15 +4570,23 @@ const generateConfigs = (context, options = {}) => {
4555
4570
  };
4556
4571
  const outdir = options?.output?.dir;
4557
4572
  const { js: jsPlugins, dts: dtsPlugins } = resolveBuildPlugins(context, build.plugins);
4573
+ if (input.includes("**")) {
4574
+ throw new Error(
4575
+ 'input should not include "**", please read the [documentation](https://nodejs.org/api/packages.html#subpath-patterns).'
4576
+ );
4577
+ }
4578
+ const inputObj = !input.includes("*") ? input : recusiveListFiles(process.cwd()).filter((p) => /(?<!\.d)\.[cm]?tsx?$/.test(p));
4579
+ const globCommonDir = input.includes("*") ? input.split("*")[0] : "";
4558
4580
  return [
4559
4581
  {
4560
- input,
4582
+ input: inputObj,
4561
4583
  external,
4562
4584
  output: [
4563
4585
  ...withMinify({
4564
- file: output,
4586
+ dir: jsOutdir,
4565
4587
  name,
4566
4588
  interop: "auto",
4589
+ entryFileNames: (chunkInfo) => Array.isArray(inputObj) ? chunkInfo.facadeModuleId.replace(`${process.cwd()}/`, "./").replace(globCommonDir, "").replace(/(\.[cm]?)ts$/, "$1js") : output.replace(`${jsOutdir}/`, ""),
4567
4590
  sourcemap: typeof options?.output?.sourcemap === "object" ? options.output.sourcemap.js : options?.output?.sourcemap,
4568
4591
  format: isModule ? "esm" : isCommonJS ? "cjs" : isBrowser ? "umd" : pkgIsModule ? "esm" : "cjs",
4569
4592
  strict: typeof options?.output?.strict === "object" ? options.output.strict.js : options?.output?.strict
@@ -4593,13 +4616,13 @@ const generateConfigs = (context, options = {}) => {
4593
4616
  ]
4594
4617
  },
4595
4618
  {
4596
- input,
4619
+ input: inputObj,
4597
4620
  external,
4598
4621
  output: [
4599
4622
  {
4600
4623
  dir: resolve((typeof outdir === "object" ? outdir.dts : outdir) ?? "dist"),
4601
4624
  sourcemap: typeof options?.output?.sourcemap === "object" ? options.output.sourcemap.dts : options?.output?.sourcemap,
4602
- entryFileNames: () => output.replace(`${jsOutdir}/`, "").replace(/(\.[cm]?)js$/, ".d$1ts"),
4625
+ entryFileNames: (chunkInfo) => Array.isArray(inputObj) ? chunkInfo.facadeModuleId.replace(`${process.cwd()}/`, "./").replace(globCommonDir, "").replace(/(\.[cm]?)ts$/, ".d$1ts") : output.replace(`${jsOutdir}/`, "").replace(/(\.[cm]?)js$/, ".d$1ts"),
4603
4626
  strict: typeof options?.output?.strict === "object" ? options.output.strict.dts : options?.output?.strict
4604
4627
  }
4605
4628
  ],