jiek 0.2.9 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. package/dist/cli.cjs +1 -1
  2. package/dist/cli.cjs.map +1 -1
  3. package/dist/cli.esm.js +1 -2
  4. package/dist/cli.esm.js.map +1 -1
  5. package/dist/cli.esm.min.js +1 -1
  6. package/dist/cli.esm.min.js.map +1 -1
  7. package/dist/commands/base.esm.js +5 -0
  8. package/dist/commands/base.esm.js.map +1 -0
  9. package/dist/commands/base.esm.min.js +2 -0
  10. package/dist/commands/base.esm.min.js.map +1 -0
  11. package/dist/commands/build.esm.js +2 -2
  12. package/dist/commands/build.esm.js.map +1 -1
  13. package/dist/commands/build.esm.min.js +1 -1
  14. package/dist/commands/build.esm.min.js.map +1 -1
  15. package/dist/merge-package-json.esm.js +9 -2
  16. package/dist/merge-package-json.esm.js.map +1 -1
  17. package/dist/merge-package-json.esm.min.js +1 -1
  18. package/dist/merge-package-json.esm.min.js.map +1 -1
  19. package/dist/rollup/utils/commonOptions.esm.js +0 -1
  20. package/dist/rollup/utils/commonOptions.esm.js.map +1 -1
  21. package/dist/rollup/utils/commonOptions.esm.min.js +1 -1
  22. package/dist/rollup/utils/commonOptions.esm.min.js.map +1 -1
  23. package/dist/rollup.cjs +1 -1
  24. package/dist/rollup.cjs.map +1 -1
  25. package/dist/rollup.esm.js +145 -9
  26. package/dist/rollup.esm.js.map +1 -1
  27. package/dist/rollup.esm.min.js +1 -1
  28. package/dist/rollup.esm.min.js.map +1 -1
  29. package/dist/utils/getRoot.esm.js +1 -1
  30. package/dist/utils/getRoot.esm.js.map +1 -1
  31. package/dist/utils/getRoot.esm.min.js +1 -1
  32. package/dist/utils/getRoot.esm.min.js.map +1 -1
  33. package/dist/utils/getWD.esm.js +8 -2
  34. package/dist/utils/getWD.esm.js.map +1 -1
  35. package/dist/utils/getWD.esm.min.js +1 -1
  36. package/dist/utils/getWD.esm.min.js.map +1 -1
  37. package/package.json +6 -7
package/dist/cli.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("node:fs"),t=require("node:path"),r=require("@pnpm/filter-workspace-packages"),n=require("commander"),o=require("js-yaml"),a=require("@jiek/utils/getWorkspaceDir"),i=require("node:child_process"),s=require("@jiek/pkger"),l=require("detect-indent"),c=require("inquirer"),p=require("jsonc-parser"),u=require("micromatch"),f=require("@jiek/utils/bumper");function d(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(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var g=d(e),y=d(t),w=m(i),k=d(l),h=d(c);let b,j;function v(){if(b)return b;const e=n.program.getOptionValue("root");return b=e?y.default.isAbsolute(e)?e:y.default.resolve(process.cwd(),e):process.cwd(),b}let S=!1;function $(){if(j)return{wd:j,notWorkspace:S};const e=v();try{j=a.getWorkspaceDir(e,q)}catch(t){if(!("message"in t)||"workspace root not found"!==t.message)throw t;j=e,S=!0}return{wd:j,notWorkspace:S}}let E,O,q="";try{require.resolve("@pnpm/filter-workspace-packages"),q="pnpm"}catch{}async function x(){let e=n.program.getOptionValue("filter");const t=v(),{wd:a,notWorkspace:i}=$();if(!i&&"pnpm"===q){const n=y.default.resolve(a,"pnpm-workspace.yaml"),i=g.default.readFileSync(n,"utf-8"),s=o.load(i);if(t===a&&!e)throw new Error("root path is workspace root, please provide a filter");if(t!==a&&!e){if(!g.default.existsSync(y.default.resolve(t,"package.json")))throw new Error("root path is not workspace root, please provide a filter");const r=JSON.parse(g.default.readFileSync(y.default.resolve(t,"package.json"),"utf-8"));if(!r.name)throw new Error("root path is not workspace root, please provide a filter");e=r.name}const{selectedProjectsGraph:l}=await r.filterPackagesFromDir(a,[{filter:e??"",followProdDepsOnly:!0}],{prefix:t,workspaceDir:a,patterns:s.packages});return{wd:a,root:t,value:Object.entries(l).reduce(((e,[t,r])=>(e[t]=r.package.manifest,e)),{})}}return{wd:a,root:t,value:{[a]:JSON.parse(g.default.readFileSync(y.default.resolve(a,"package.json"),"utf-8"))}}}function F(){E()}function _(){new Promise((e=>E=e))}function A(e,t){const{jiek:{cwd:r,...n}={}}=e;let{exports:o}=e,a=!1;"string"==typeof o&&(a=!0,o={".":o}),void 0===o&&(o={".":"./src/index.ts"}),"object"==typeof o&&(a=!!(Array.isArray(o)&&o.length>0)||!!o["."]);const i=Array.isArray(o)?o:Object.entries(o).reduce(((e,[t,r])=>{if("string"==typeof r)return"."===t?[r,...e]:e.concat(r);if(Array.isArray(r))return e.concat(r);throw new TypeError(`Unexpected value type for key "${t}" in exports, expected string, got ${typeof r}`)}),[]);if(0===i.length)throw new Error("No inputs found");const l=i.map((e=>y.default.isAbsolute(e)?e:y.default.resolve(t,e)));let c=y.default.dirname(l[0]);l.length>1&&(c=function(e,t=process.cwd()){const r=e.map((e=>y.default.isAbsolute(e)?e:y.default.resolve(t,e))),[n=""]=r,o=n.split("/");let a="";for(let e=0;e<o.length;e++){const t=o[e];if(!r.every((e=>e.startsWith(a+t))))break;a+=t+"/"}return a}(l,t));const p=l.map((e=>y.default.relative(c,e)));return{...e,...s.pkger({cwd:t,noIndex:!a,source:y.default.relative(t,c),inputs:p,...n})}}function J(e){try{return require.resolve(e),!0}catch(e){return!1}}""!==q&&n.program.option("-f, --filter <filter>","filter packages");const N=[process.env.JIEK_TS_REGISTER,"esbuild-register","@swc-node/register","ts-node/register"].filter(Boolean);for(const e of N)if(J(e)){O=e;break}const P=e=>`\nconst pkg = ${JSON.stringify(e,null,2)}\nconst { jiek = {} } = pkg\nconst templateArg = jiek.templateArgFilePath\n ? require.resolve(jiek.templateArgFilePath)\n : {\n styled: jiek.styled\n }\nmodule.exports = require('jiek/rollup').template(templateArg, pkg)\n`.trimStart();n.program.command("build").action((async()=>{_();const{wd:e,value:t={}}=await x()??{};if(0===Object.keys(t).length)throw new Error("no package found");const r=(...t)=>y.default.resolve(e,"node_modules/.jiek",...t);g.default.existsSync(r())||g.default.mkdirSync(r());const n=require.resolve("rollup").replace(/dist\/rollup.js$/,"dist/bin/rollup");let o=0;for(const[e,a]of Object.entries(t)){const t=A(a,e),i=a.name?.replace(/^@/g,"").replace(/\//g,"+"),s=r(`${i??"anonymous-"+o++}.rollup.config.js`);g.default.writeFileSync(s,P(t));let l="";O&&(l=`node -r ${O} `),w.execSync(`${l}${n} -c ${s}`,{cwd:e,stdio:"inherit"})}F()}));let D="jiek.config";function M(){const{wd:e,notWorkspace:t}=$();if(t)throw new Error("not in workspace");let r=n.program.getOptionValue("configPath");if(r){if(!g.default.existsSync(r))throw new Error(`config file not found: ${r}`);y.default.isAbsolute(r)||(r=y.default.resolve(e,r))}else r=function(e){const t=!!O;function r(t){const r=[y.default.resolve(e,`${D}.${t}`),y.default.resolve(e,`.${D}.${t}`)];for(const e of r)if(g.default.existsSync(e)&&g.default.lstatSync(e).isFile())return e}return D=r("js")??D,D=r("json")??D,D=r("yaml")??D,t&&(D=r("ts")??D),y.default.resolve(e,D)}(e);const a=y.default.extname(r);let i;switch(a){case".js":i=require(r);break;case".json":return require(r);case".yaml":return o.load(g.default.readFileSync(r,"utf-8"));case".ts":if(O){require(O),i=require(r);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":i={};break;default:throw new Error(`unsupported config file type: ${a}`)}if(!i)throw new Error("config file is empty");return i.default??i}const W='{\n "name": "",\n "version": "0.0.1",\n "description": "",\n "license": "",\n "author": "",\n "files": ["dist"],\n "exports": {\n ".": "./src/index.ts"\n },\n "scripts": {\n },\n "homepage": "",\n "repository": "",\n "bugs": ""\n}'.trimStart(),I="# $name\n\n## Installation\n\n```bash\nnpm install $name\n# or\npnpm install $name\n# or\nyarn add $name\n```\n\n## Usage\n\n\n## License\n\n$license\n".trimStart();const R=new Map;function T(e,t){if(R.has(e))return R.get(e)[t];const r=y.default.resolve(e,"package.json"),n=JSON.parse(g.default.readFileSync(r,"utf-8"));return R.set(e,n),n[t]}n.program.command("init [name]").option("-t, --template <template>","the package.json template file path or file content").action((async()=>{const[,e]=n.program.args,t=process.cwd(),{init:r={}}=M()??{},{wd:o}=$(),a=y.default.basename(o),{named:i,template:s,bug:l={},readme:c=I,readmeTemplate:f}=r,d={template:"bug_report.yml",labels:["bug"],...l};let m=c;if(f){const e=y.default.resolve(o,f);m=g.default.readFileSync(e,"utf-8")}const w=function(e,t){let r=t??W,n=!1;try{t&&JSON.parse(t)}catch(e){n=!0}if(n){const n=y.default.resolve(e,t);r=g.default.readFileSync(n,"utf-8")}return r}(o,s),{indent:b=" "}=k.default(w),j={tabSize:b.length,insertSpaces:!0},v=["license","author"];let S=w;for(const e of v)S=p.applyEdits(S,p.modify(S,[e],T(o,e),{formattingOptions:j}));let[E,O]=await async function(e,t,{wd:r,cwd:n,workspaceName:o}){const a=n.replace(`${r}/`,"");let i=y.default.basename(n);if("function"==typeof e)return e(t,{full:r,relative:n});let s,l,c=!1;if("object"==typeof e)if(n===r){const{rule:t}=await h.default.prompt({type:"list",name:"rule",message:"choose a rule",default:"default",choices:["default"].concat(Object.keys(e))});"default"!==t&&(s=t,l=e[t])}else for(const[t,r]of Object.entries(e)){if(u.isMatch(a,t)){s=t,l=r;break}if(u.isMatch(`${a}/jiek_ignore_dont_use_same_file_name`,t)){c=!0,s=t,l=r;break}}if(l||(s="packages/*",l=`@${o}/$basename`),!l)throw new Error("no matched rule");if(!t&&c&&(i=await h.default.prompt({type:"input",name:"name",message:`the matched rule is \`${String(l)}\`, please input the basename\n`}).then((({name:e})=>e))),"function"==typeof l)return l(t,{full:r,relative:n,basename:i});if("string"==typeof l){const e=t??i;return[l.replace(/\$basename/g,e),s?.replace(/\/\*$/g,`/${e}`)]}throw new Error("no matched rule")}(i,e,{wd:o,cwd:t,workspaceName:a});if(!O){const{dir:t}=await h.default.prompt({type:"input",name:"dir",message:"package directory",default:e});O=t}if(!E){const{name:t}=await h.default.prompt({type:"input",name:"name",message:"package name",default:e});E=t}S=p.applyEdits(S,p.modify(S,["name"],E,{formattingOptions:j}));let q=T(o,"repository");"string"==typeof q&&(q={type:"git",url:q,directory:O}),S=p.applyEdits(S,p.modify(S,["repository"],q,{formattingOptions:j}));const x=`${q?.url}/blob/master/${O}/README.md`;S=p.applyEdits(S,p.modify(S,["homepage"],x,{formattingOptions:j}));let F=d.labels;"function"==typeof F&&(F=F({name:E,dir:O})),F.push(`scope:${E}`);const _=`${q?.url}/issues/new?template=${d.template}&labels=${F.join(",")}`;function A(e){if(!O)throw new Error("pkgDir is not defined");return y.default.resolve(O,e)}S=p.applyEdits(S,p.modify(S,["bugs"],_,{formattingOptions:j})),g.default.existsSync(O)||g.default.mkdirSync(O);const J=A("package.json");if(g.default.existsSync(J))throw new Error("package.json already exists");g.default.writeFileSync(J,S),console.log(S,"written to",J);const N=T(o,"license"),P=A("README.md");"function"==typeof m&&(m=m({dir:O,packageJson:JSON.parse(S)}));const D=m.replace(/\$name/g,E).replace(/\$license/g,N);g.default.writeFileSync(P,D)})),n.program.command("publish").aliases(["pub","p"]).option("-b, --bumper <bumper>","bump version","patch").option("-p, --preview","preview publish").action((async({preview:e,bumper:t,...r})=>{_();const{value:n={}}=await x()??{},o=Object.entries(n);if(0===o.length)throw new Error("no packages selected");const a=o.map((([e,t])=>[e,A(t,e)])),i=Object.entries(r).reduce(((e,[t,r])=>(r&&e.push(`--${t}`,r),e)),[]);for(const[r,n]of a){const o=g.default.readFileSync(y.default.join(r,"package.json"),"utf-8"),a=JSON.parse(o)??"0.0.0",s=f.bump(a.version,t),{indent:l=" "}=k.default(o),c={tabSize:l.length,insertSpaces:!0};let u=o;u=p.applyEdits(u,p.modify(u,["version"],s,{formattingOptions:c}));for(const[e,t]of Object.entries(n))JSON.stringify(t)!==JSON.stringify(a[e])&&(u=p.applyEdits(u,p.modify(u,["publishConfig",e],t,{formattingOptions:c})));try{if(g.default.renameSync(y.default.join(r,"package.json"),y.default.join(r,"package.json.bak")),g.default.writeFileSync(y.default.join(r,"package.json"),u),console.log(u),e){console.warn("preview mode");continue}w.execSync(["pnpm","publish","--access","public","--no-git-checks",...i].join(" "),{cwd:r,stdio:"inherit"});const t=p.applyEdits(o,p.modify(o,["version"],s,{}));g.default.writeFileSync(y.default.join(r,"package.json.bak"),t)}finally{g.default.unlinkSync(y.default.join(r,"package.json")),g.default.renameSync(y.default.join(r,"package.json.bak"),y.default.join(r,"package.json"))}}F()}));const z=require("../package.json");n.program.version(z.version).description(z.description).option("--root <root>","root path").option("-c, --config-path <configPath>","config path"),n.program.parse(process.argv);
1
+ "use strict";var e=require("node:fs"),t=require("node:path"),r=require("@pnpm/filter-workspace-packages"),n=require("commander"),o=require("js-yaml"),a=require("@jiek/utils/getWorkspaceDir"),i=require("node:child_process"),s=require("@jiek/pkger"),l=require("detect-indent"),c=require("inquirer"),p=require("jsonc-parser"),u=require("micromatch"),f=require("@jiek/utils/bumper");function d(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(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var g=d(e),y=d(t),w=m(i),k=d(l),h=d(c);let b,j;function v(){if(b)return b;const e=n.program.getOptionValue("root");return b=e?y.default.isAbsolute(e)?e:y.default.resolve(process.cwd(),e):void 0,b}let S=!1;function $(){if(j)return{wd:j,notWorkspace:S};const e=v();if(void 0!==e){const t=a.isWorkspaceDir(e,E);return S=!t,j=e,{wd:j,notWorkspace:S}}try{j=a.getWorkspaceDir(E)}catch(t){if(!("message"in t)||"workspace root not found"!==t.message)throw t;j=e,S=!0}return{wd:j,notWorkspace:S}}let E="";try{require.resolve("@pnpm/filter-workspace-packages"),E="pnpm"}catch{}async function O(){let e=n.program.getOptionValue("filter");const t=v(),{wd:a,notWorkspace:i}=$();if(!i&&"pnpm"===E){const n=y.default.resolve(a,"pnpm-workspace.yaml"),i=g.default.readFileSync(n,"utf-8"),s=o.load(i);if(t===a&&!e)throw new Error("root path is workspace root, please provide a filter");if(t!==a&&!e){if(!g.default.existsSync(y.default.resolve(t,"package.json")))throw new Error("root path is not workspace root, please provide a filter");const r=JSON.parse(g.default.readFileSync(y.default.resolve(t,"package.json"),"utf-8"));if(!r.name)throw new Error("root path is not workspace root, please provide a filter");e=r.name}const{selectedProjectsGraph:l}=await r.filterPackagesFromDir(a,[{filter:e??"",followProdDepsOnly:!0}],{prefix:t,workspaceDir:a,patterns:s.packages});return{wd:a,root:t,value:Object.entries(l).reduce(((e,[t,r])=>(e[t]=r.package.manifest,e)),{})}}return{wd:a,root:t,value:{[a]:JSON.parse(g.default.readFileSync(y.default.resolve(a,"package.json"),"utf-8"))}}}""!==E&&n.program.option("-f, --filter <filter>","filter packages");const q=require("../../package.json");let x,F;function _(){x()}function A(){new Promise((e=>x=e))}function D(e,t,r={}){const{excludeDistInExports:n=!1}=r,{jiek:{cwd:o,...a}={}}=e,{outdir:i="dist"}=a;let{exports:l}=e,c=!1;"string"==typeof l&&(c=!0,l={".":l}),void 0===l&&(l={".":"./src/index.ts"}),"object"==typeof l&&(c=!!(Array.isArray(l)&&l.length>0)||!!l["."]);let p=Array.isArray(l)?l:Object.entries(l).reduce(((e,[t,r])=>{if("string"==typeof r)return"."===t?[r,...e]:e.concat(r);if(Array.isArray(r))return e.concat(r);throw new TypeError(`Unexpected value type for key "${t}" in exports, expected string, got ${typeof r}`)}),[]);if(n&&(p=p.filter((e=>!e.startsWith(`./${i}`)&&!e.startsWith(i)))),0===p.length)throw new Error("No inputs found");const u=p.map((e=>y.default.isAbsolute(e)?e:y.default.resolve(t,e)));let f=y.default.dirname(u[0]);u.length>1&&(f=function(e,t=process.cwd()){const r=e.map((e=>y.default.isAbsolute(e)?e:y.default.resolve(t,e))),[n=""]=r,o=n.split("/");let a="";for(let e=0;e<o.length;e++){const t=o[e];if(!r.every((e=>e.startsWith(a+t))))break;a+=t+"/"}return a}(u,t));const d=u.map((e=>y.default.relative(f,e)));return{...e,...s.pkger({cwd:t,noIndex:!c,source:y.default.relative(t,f),inputs:d,...a})}}function J(e){try{return require.resolve(e),!0}catch(e){return!1}}n.program.version(q.version).description(q.description).option("--root <root>","root path").option("-c, --config-path <configPath>","config path");const N=[process.env.JIEK_TS_REGISTER,"esbuild-register","@swc-node/register","ts-node/register"].filter(Boolean);for(const e of N)if(J(e)){F=e;break}const W=e=>`\nconst pkg = ${JSON.stringify(e,null,2)}\nconst { jiek = {} } = pkg\nconst templateArg = jiek.templateArgFilePath\n ? require.resolve(jiek.templateArgFilePath)\n : {\n styled: jiek.styled\n }\nmodule.exports = require('jiek/rollup').template(templateArg, pkg)\n`.trimStart();n.program.command("build").action((async()=>{A();const{wd:e,value:t={}}=await O()??{};if(0===Object.keys(t).length)throw new Error("no package found");const r=(...t)=>y.default.resolve(e,"node_modules/.jiek",...t);g.default.existsSync(r())||g.default.mkdirSync(r());const n=require.resolve("rollup").replace(/dist\/rollup.js$/,"dist/bin/rollup");let o=0;for(const[e,a]of Object.entries(t)){const t=D(a,e,{excludeDistInExports:!0}),i=a.name?.replace(/^@/g,"").replace(/\//g,"+"),s=r(`${i??"anonymous-"+o++}.rollup.config.js`);g.default.writeFileSync(s,W(t));let l="";F&&(l=`node -r ${F} `),w.execSync(`${l}${n} --silent -c ${s}`,{cwd:e,stdio:"inherit"})}_()}));let P="jiek.config";function I(){const{wd:e,notWorkspace:t}=$();if(t)throw new Error("not in workspace");let r=n.program.getOptionValue("configPath");if(r){if(!g.default.existsSync(r))throw new Error(`config file not found: ${r}`);y.default.isAbsolute(r)||(r=y.default.resolve(e,r))}else r=function(e){const t=!!F;function r(t){const r=[y.default.resolve(e,`${P}.${t}`),y.default.resolve(e,`.${P}.${t}`)];for(const e of r)if(g.default.existsSync(e)&&g.default.lstatSync(e).isFile())return e}return P=r("js")??P,P=r("json")??P,P=r("yaml")??P,t&&(P=r("ts")??P),y.default.resolve(e,P)}(e);const a=y.default.extname(r);let i;switch(a){case".js":i=require(r);break;case".json":return require(r);case".yaml":return o.load(g.default.readFileSync(r,"utf-8"));case".ts":if(F){require(F),i=require(r);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":i={};break;default:throw new Error(`unsupported config file type: ${a}`)}if(!i)throw new Error("config file is empty");return i.default??i}const M='{\n "name": "",\n "version": "0.0.1",\n "description": "",\n "license": "",\n "author": "",\n "files": ["dist"],\n "exports": {\n ".": "./src/index.ts"\n },\n "scripts": {\n },\n "homepage": "",\n "repository": "",\n "bugs": ""\n}'.trimStart(),R="# $name\n\n## Installation\n\n```bash\nnpm install $name\n# or\npnpm install $name\n# or\nyarn add $name\n```\n\n## Usage\n\n\n## License\n\n$license\n".trimStart();const T=new Map;function z(e,t){if(T.has(e))return T.get(e)[t];const r=y.default.resolve(e,"package.json"),n=JSON.parse(g.default.readFileSync(r,"utf-8"));return T.set(e,n),n[t]}n.program.command("init [name]").option("-t, --template <template>","the package.json template file path or file content").action((async()=>{const[,e]=n.program.args,t=process.cwd(),{init:r={}}=I()??{},{wd:o}=$(),a=y.default.basename(o),{named:i,template:s,bug:l={},readme:c=R,readmeTemplate:f}=r,d={template:"bug_report.yml",labels:["bug"],...l};let m=c;if(f){const e=y.default.resolve(o,f);m=g.default.readFileSync(e,"utf-8")}const w=function(e,t){let r=t??M,n=!1;try{t&&JSON.parse(t)}catch(e){n=!0}if(n){const n=y.default.resolve(e,t);r=g.default.readFileSync(n,"utf-8")}return r}(o,s),{indent:b=" "}=k.default(w),j={tabSize:b.length,insertSpaces:!0},v=["license","author"];let S=w;for(const e of v)S=p.applyEdits(S,p.modify(S,[e],z(o,e),{formattingOptions:j}));let[E,O]=await async function(e,t,{wd:r,cwd:n,workspaceName:o}){const a=n.replace(`${r}/`,"");let i=y.default.basename(n);if("function"==typeof e)return e(t,{full:r,relative:n});let s,l,c=!1;if("object"==typeof e)if(n===r){const{rule:t}=await h.default.prompt({type:"list",name:"rule",message:"choose a rule",default:"default",choices:["default"].concat(Object.keys(e))});"default"!==t&&(s=t,l=e[t])}else for(const[t,r]of Object.entries(e)){if(u.isMatch(a,t)){s=t,l=r;break}if(u.isMatch(`${a}/jiek_ignore_dont_use_same_file_name`,t)){c=!0,s=t,l=r;break}}if(l||(s="packages/*",l=`@${o}/$basename`),!l)throw new Error("no matched rule");if(!t&&c&&(i=await h.default.prompt({type:"input",name:"name",message:`the matched rule is \`${String(l)}\`, please input the basename\n`}).then((({name:e})=>e))),"function"==typeof l)return l(t,{full:r,relative:n,basename:i});if("string"==typeof l){const e=t??i;return[l.replace(/\$basename/g,e),s?.replace(/\/\*$/g,`/${e}`)]}throw new Error("no matched rule")}(i,e,{wd:o,cwd:t,workspaceName:a});if(!O){const{dir:t}=await h.default.prompt({type:"input",name:"dir",message:"package directory",default:e});O=t}if(!E){const{name:t}=await h.default.prompt({type:"input",name:"name",message:"package name",default:e});E=t}S=p.applyEdits(S,p.modify(S,["name"],E,{formattingOptions:j}));let q=z(o,"repository");"string"==typeof q&&(q={type:"git",url:q,directory:O}),S=p.applyEdits(S,p.modify(S,["repository"],q,{formattingOptions:j}));const x=`${q?.url}/blob/master/${O}/README.md`;S=p.applyEdits(S,p.modify(S,["homepage"],x,{formattingOptions:j}));let F=d.labels;"function"==typeof F&&(F=F({name:E,dir:O})),F.push(`scope:${E}`);const _=`${q?.url}/issues/new?template=${d.template}&labels=${F.join(",")}`;function A(e){if(!O)throw new Error("pkgDir is not defined");return y.default.resolve(O,e)}S=p.applyEdits(S,p.modify(S,["bugs"],_,{formattingOptions:j})),g.default.existsSync(O)||g.default.mkdirSync(O);const D=A("package.json");if(g.default.existsSync(D))throw new Error("package.json already exists");g.default.writeFileSync(D,S),console.log(S,"written to",D);const J=z(o,"license"),N=A("README.md");"function"==typeof m&&(m=m({dir:O,packageJson:JSON.parse(S)}));const W=m.replace(/\$name/g,E).replace(/\$license/g,J);g.default.writeFileSync(N,W)})),n.program.command("publish").aliases(["pub","p"]).option("-b, --bumper <bumper>","bump version","patch").option("-p, --preview","preview publish").action((async({preview:e,bumper:t,...r})=>{A();const{value:n={}}=await O()??{},o=Object.entries(n);if(0===o.length)throw new Error("no packages selected");const a=o.map((([e,t])=>[e,D(t,e)])),i=Object.entries(r).reduce(((e,[t,r])=>(r&&e.push(`--${t}`,r),e)),[]);for(const[r,n]of a){const o=g.default.readFileSync(y.default.join(r,"package.json"),"utf-8"),a=JSON.parse(o)??"0.0.0",s=f.bump(a.version,t),{indent:l=" "}=k.default(o),c={tabSize:l.length,insertSpaces:!0};let u=o;u=p.applyEdits(u,p.modify(u,["version"],s,{formattingOptions:c}));for(const[e,t]of Object.entries(n))JSON.stringify(t)!==JSON.stringify(a[e])&&(u=p.applyEdits(u,p.modify(u,["publishConfig",e],t,{formattingOptions:c})));try{if(g.default.renameSync(y.default.join(r,"package.json"),y.default.join(r,"package.json.bak")),g.default.writeFileSync(y.default.join(r,"package.json"),u),console.log(u),e){console.warn("preview mode");continue}w.execSync(["pnpm","publish","--access","public","--no-git-checks",...i].join(" "),{cwd:r,stdio:"inherit"});const t=p.applyEdits(o,p.modify(o,["version"],s,{}));g.default.writeFileSync(y.default.join(r,"package.json.bak"),t)}finally{g.default.unlinkSync(y.default.join(r,"package.json")),g.default.renameSync(y.default.join(r,"package.json.bak"),y.default.join(r,"package.json"))}}_()})),n.program.parse(process.argv);
2
2
  //# sourceMappingURL=cli.cjs.map
package/dist/cli.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.cjs","sources":["../src/utils/getRoot.ts","../src/utils/getWD.ts","../src/utils/filterSupport.ts","../src/inner.ts","../src/utils/tsRegister.ts","../src/merge-package-json.ts","../src/utils/commondir.ts","../src/commands/build.ts","../src/utils/loadConfig.ts","../src/commands/init.ts","../src/commands/publish.ts","../src/cli.ts"],"sourcesContent":["import path from 'node:path'\n\nimport { program } from 'commander'\n\nlet root: string\nexport function getRoot() {\n if (root) return root\n\n const rootOption = program.getOptionValue('root')\n root = rootOption\n ? path.isAbsolute(rootOption)\n ? rootOption\n : path.resolve(process.cwd(), rootOption)\n : process.cwd()\n return root\n}\n","import { getWorkspaceDir } from '@jiek/utils/getWorkspaceDir'\n\nimport { type } from './filterSupport'\nimport { getRoot } from './getRoot'\n\nlet wd: string\nlet notWorkspace = false\n\nexport function getWD() {\n if (wd) return { wd, notWorkspace }\n\n const root = getRoot()\n try {\n wd = getWorkspaceDir(root, type)\n } catch (e) {\n // @ts-ignore\n if ('message' in e && e.message === 'workspace root not found') {\n wd = root\n notWorkspace = true\n } else {\n throw e\n }\n }\n return { wd, notWorkspace }\n}\n","import fs from 'node:fs'\nimport path from 'node:path'\n\nimport { getWorkspaceDir } from '@jiek/utils/getWorkspaceDir'\nimport { filterPackagesFromDir } from '@pnpm/filter-workspace-packages'\nimport { program } from 'commander'\nimport { load } from 'js-yaml'\n\nimport { getRoot } from './getRoot'\nimport { getWD } from './getWD'\n\nexport let type = ''\n\ntry {\n require.resolve('@pnpm/filter-workspace-packages')\n type = 'pnpm'\n} catch { /* empty */ }\nif (type !== '') {\n program\n .option('-f, --filter <filter>', 'filter packages')\n}\n\ninterface ProjectsGraph {\n wd: string\n root: string\n value?: Record<string, {\n name?: string\n }>\n}\n\nexport async function getSelectedProjectsGraph(): Promise<ProjectsGraph> {\n let filter = program.getOptionValue('filter')\n const root = getRoot()\n const { wd, notWorkspace } = getWD()\n if (!notWorkspace && type === 'pnpm') {\n const pnpmWorkspaceFilePath = path.resolve(wd, 'pnpm-workspace.yaml')\n const pnpmWorkspaceFileContent = fs.readFileSync(pnpmWorkspaceFilePath, 'utf-8')\n const pnpmWorkspace = load(pnpmWorkspaceFileContent) as {\n packages: string[]\n }\n if (root === wd && !filter) {\n throw new Error('root path is workspace root, please provide a filter')\n // TODO inquirer prompt support user select packages\n }\n if (root !== wd && !filter) {\n const packageJSONIsExist = fs.existsSync(path.resolve(root, 'package.json'))\n if (!packageJSONIsExist) {\n throw new Error('root path is not workspace root, please provide a filter')\n }\n const packageJSON = JSON.parse(fs.readFileSync(path.resolve(root, 'package.json'), 'utf-8'))\n if (!packageJSON.name) {\n throw new Error('root path is not workspace root, please provide a filter')\n }\n filter = packageJSON.name\n }\n const { selectedProjectsGraph } = await filterPackagesFromDir(wd, [{\n filter: filter ?? '',\n followProdDepsOnly: true\n }], {\n prefix: root,\n workspaceDir: wd,\n patterns: pnpmWorkspace.packages\n })\n return {\n wd, root,\n value: Object.entries(selectedProjectsGraph)\n .reduce((acc, [key, value]) => {\n acc[key] = value.package.manifest\n return acc\n }, {} as NonNullable<ProjectsGraph['value']>)\n }\n }\n return {\n wd, root,\n value: {\n [wd]: JSON.parse(fs.readFileSync(path.resolve(wd, 'package.json'), 'utf-8'))\n }\n }\n}\n","let resolve: () => void\n\nexport let actionFuture: Promise<void>\n\nexport function actionDone() {\n resolve()\n}\n\nexport function actionRestore() {\n actionFuture = new Promise<void>(r => resolve = r)\n}\n","function packageIsExist(name: string) {\n try {\n require.resolve(name)\n return true\n } catch (e) {\n return false\n }\n}\n\nexport let tsRegisterName: string | undefined\nconst registers = [\n process.env.JIEK_TS_REGISTER,\n 'esbuild-register',\n '@swc-node/register',\n 'ts-node/register'\n].filter(Boolean) as string[]\nfor (const register of registers) {\n if (packageIsExist(register)) {\n tsRegisterName = register\n break\n }\n}\n","import path from 'node:path'\n\nimport { type Options, pkger } from '@jiek/pkger'\nimport type { Manifest } from '@pnpm/workspace.pkgs-graph'\n\nimport { commondir } from './utils/commondir'\n\nexport function mergePackageJson(manifest: Manifest & {\n jiek?: Options\n exports?: unknown | unknown[]\n}, cwd: string) {\n const {\n jiek: { cwd: _, ...jiek } = {}\n } = manifest\n let { exports } = manifest\n let includeIndex = false\n if (typeof exports === 'string') {\n includeIndex = true\n exports = { '.': exports }\n }\n if (exports === undefined) {\n exports = { '.': './src/index.ts' }\n }\n if (typeof exports === 'object') {\n if (Array.isArray(exports) && exports.length > 0) {\n includeIndex = true\n } else {\n includeIndex = !!(<Record<string, unknown>>exports)['.']\n }\n }\n const inputs = Array.isArray(exports)\n ? exports as string[]\n : Object\n .entries(<Record<string, unknown>>exports)\n .reduce((acc, [key, value]) => {\n if (typeof value === 'string') return key === '.'\n ? [value, ...acc]\n : acc.concat(value)\n if (Array.isArray(value)) return acc.concat(value)\n\n throw new TypeError(`Unexpected value type for key \"${key}\" in exports, expected string, got ${typeof value}`)\n }, [] as string[])\n if (inputs.length === 0)\n throw new Error('No inputs found')\n\n const absoluteInputs = inputs.map(input => path.isAbsolute(input)\n ? input\n : path.resolve(cwd, input)\n )\n let cDir = path.dirname(absoluteInputs[0])\n if (absoluteInputs.length > 1) {\n cDir = commondir(absoluteInputs, cwd)\n }\n const resolvedInputs = absoluteInputs.map(input => {\n return path.relative(cDir, input)\n })\n return {\n ...manifest,\n ...pkger({\n cwd,\n noIndex: !includeIndex,\n source: path.relative(cwd, cDir),\n inputs: resolvedInputs,\n ...jiek\n })\n }\n}\n","import path from 'node:path'\n\nexport function commondir(files: string[], cwd = process.cwd()): string {\n const resolvedFiles = files.map(file => {\n if (path.isAbsolute(file)) return file\n return path.resolve(cwd, file)\n })\n const sep = '/'\n const [first = ''] = resolvedFiles\n const parts = first.split(sep)\n let common = ''\n for (let i = 0; i < parts.length; i++) {\n const segment = parts[i]\n if (resolvedFiles.every(file => file.startsWith(common + segment))) {\n common += segment + sep\n } else {\n break\n }\n }\n return common\n}\n","import * as childProcess from 'node:child_process'\nimport fs from 'node:fs'\nimport path from 'node:path'\n\nimport { program } from 'commander'\n\nimport { actionDone, actionRestore } from '../inner'\nimport { mergePackageJson } from '../merge-package-json'\nimport { getSelectedProjectsGraph } from '../utils/filterSupport'\nimport { tsRegisterName } from '../utils/tsRegister'\n\nconst FILE_TEMPLATE = (manifest: unknown) => `\nconst pkg = ${JSON.stringify(manifest, null, 2)}\nconst { jiek = {} } = pkg\nconst templateArg = jiek.templateArgFilePath\n ? require.resolve(jiek.templateArgFilePath)\n : {\n styled: jiek.styled\n }\nmodule.exports = require('jiek/rollup').template(templateArg, pkg)\n`.trimStart()\n\nprogram\n .command('build')\n .action(async () => {\n actionRestore()\n const {\n wd, value = {}\n } = await getSelectedProjectsGraph() ?? {}\n\n if (Object.keys(value).length === 0) {\n throw new Error('no package found')\n }\n const jiekTempDir = (...paths: string[]) => path.resolve(wd, 'node_modules/.jiek', ...paths)\n if (!fs.existsSync(jiekTempDir())) fs.mkdirSync(jiekTempDir())\n\n const rollupBinaryPath = require.resolve('rollup')\n .replace(/dist\\/rollup.js$/, 'dist/bin/rollup')\n let i = 0\n for (const [dir, manifest] of Object.entries(value)) {\n const newManifest = mergePackageJson(manifest, dir)\n // TODO support auto build child packages in workspaces\n const escapeManifestName = manifest.name?.replace(/^@/g, '').replace(/\\//g, '+')\n const configFile = jiekTempDir(\n `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`\n )\n fs.writeFileSync(configFile, FILE_TEMPLATE(newManifest))\n let prefix = ''\n if (tsRegisterName) {\n prefix = `node -r ${tsRegisterName} `\n }\n // TODO replace with `spawn` to support watch mode\n childProcess.execSync(`${prefix}${rollupBinaryPath} -c ${configFile}`, {\n cwd: dir, stdio: 'inherit'\n })\n }\n\n actionDone()\n })\n","import fs from 'node:fs'\nimport path from 'node:path'\n\nimport { program } from 'commander'\nimport { load } from 'js-yaml'\n\nimport { getWD } from './getWD'\nimport { tsRegisterName } from './tsRegister'\n\nlet configName = 'jiek.config'\n\nfunction getConfigPath(root: string) {\n const isSupportTsLoader = !!tsRegisterName\n function configWithExtIsExist(ext: string) {\n const filenames = [\n path.resolve(root, `${configName}.${ext}`),\n path.resolve(root, `.${configName}.${ext}`)\n ]\n for (const filename of filenames) {\n if (\n fs.existsSync(filename) &&\n fs.lstatSync(filename)\n .isFile()\n ) {\n return filename\n }\n }\n return\n }\n configName = configWithExtIsExist('js') ?? configName\n configName = configWithExtIsExist('json') ?? configName\n configName = configWithExtIsExist('yaml') ?? configName\n if (isSupportTsLoader) {\n configName = configWithExtIsExist('ts') ?? configName\n }\n return path.resolve(root, configName)\n}\n\nexport function loadConfig() {\n const { wd: root, notWorkspace } = getWD()\n if (notWorkspace)\n throw new Error('not in workspace')\n\n let configPath = program.getOptionValue('configPath')\n\n if (!configPath) {\n configPath = getConfigPath(root)\n } else {\n if (!fs.existsSync(configPath))\n throw new Error(`config file not found: ${configPath}`)\n if (!path.isAbsolute(configPath))\n configPath = path.resolve(root, configPath)\n }\n const ext = path.extname(configPath)\n\n let module: any\n switch (ext) {\n case '.js':\n module = require(configPath)\n break\n case '.json':\n return require(configPath)\n case '.yaml':\n return load(fs.readFileSync(configPath, 'utf-8'))\n case '.ts':\n if (tsRegisterName) {\n require(tsRegisterName)\n module = require(configPath)\n break\n }\n throw new Error(\n 'ts config file is not supported without ts register, ' +\n 'please install esbuild-register or set JIEK_TS_REGISTER env for custom ts register'\n )\n case '.config':\n module = {}\n break\n default:\n throw new Error(`unsupported config file type: ${ext}`)\n }\n if (!module) throw new Error('config file is empty')\n\n return module.default ?? module\n}\n","import fs from 'node:fs'\nimport path from 'node:path'\n\nimport { program } from 'commander'\nimport detectIndent from 'detect-indent'\nimport inquirer from 'inquirer'\nimport { applyEdits, modify } from 'jsonc-parser'\nimport { isMatch } from 'micromatch'\n\nimport type { Config, InitNamed } from '../base'\nimport { getWD } from '../utils/getWD'\nimport { loadConfig } from '../utils/loadConfig'\n\nconst PACKAGE_JSON_TEMPLATE = `{\n \"name\": \"\",\n \"version\": \"0.0.1\",\n \"description\": \"\",\n \"license\": \"\",\n \"author\": \"\",\n \"files\": [\"dist\"],\n \"exports\": {\n \".\": \"./src/index.ts\"\n },\n \"scripts\": {\n },\n \"homepage\": \"\",\n \"repository\": \"\",\n \"bugs\": \"\"\n}`.trimStart()\nconst README_TEMPLATE = `# $name\n\n## Installation\n\n\\`\\`\\`bash\nnpm install $name\n# or\npnpm install $name\n# or\nyarn add $name\n\\`\\`\\`\n\n## Usage\n\n\n## License\n\n$license\n`.trimStart()\n\nfunction getTemplateStr(wd: string, template: string | undefined) {\n let templateString = template ?? PACKAGE_JSON_TEMPLATE\n let isTemplateFile = false\n try {\n if (template) JSON.parse(template)\n } catch (e) {\n isTemplateFile = true\n }\n if (isTemplateFile) {\n const templatePath = path.resolve(wd, template!)\n templateString = fs.readFileSync(templatePath, 'utf-8')\n }\n return templateString\n}\nconst wdCache = new Map<string, Record<string, any>>()\nfunction getWDPackageJSONFiled(wd: string, field: string) {\n if (wdCache.has(wd)) {\n return wdCache.get(wd)![field]\n }\n const packageJSONPath = path.resolve(wd, 'package.json')\n const packageJSON = JSON.parse(fs.readFileSync(packageJSONPath, 'utf-8'))\n wdCache.set(wd, packageJSON)\n return packageJSON[field]\n}\nasync function getName(\n named: InitNamed | undefined,\n name: string,\n {\n wd, cwd,\n workspaceName\n }: {\n wd: string\n cwd: string\n workspaceName: string\n }\n): Promise<[name?: string, path?: string]> {\n const relativePath = cwd.replace(`${wd}/`, '')\n let basename = path.basename(cwd)\n\n if (typeof named === 'function') {\n return named(name, {\n full: wd,\n relative: cwd\n })\n }\n\n let isParentMatched = false\n let matchedKey: string | undefined\n let matchedRule: NonNullable<typeof named>[string] | undefined\n if (typeof named === 'object') {\n const isWD = cwd === wd\n if (isWD) {\n const { rule } = await inquirer.prompt<{ rule: string }>({\n type: 'list',\n name: 'rule',\n message: 'choose a rule',\n default: 'default',\n choices: ['default'].concat(Object.keys(named))\n })\n if (rule !== 'default') {\n matchedKey = rule\n matchedRule = named[rule]\n }\n } else for (const [key, value] of Object.entries(named)) {\n if (isMatch(relativePath, key)) {\n matchedKey = key\n matchedRule = value\n break\n }\n if (isMatch(`${relativePath}/jiek_ignore_dont_use_same_file_name`, key)) {\n isParentMatched = true\n matchedKey = key\n matchedRule = value\n break\n }\n }\n }\n if (!matchedRule) {\n matchedKey = 'packages/*'\n matchedRule = `@${workspaceName}/$basename`\n }\n if (!matchedRule)\n throw new Error('no matched rule')\n if (!name && isParentMatched) {\n basename = await inquirer.prompt<{ name: string }>({\n type: 'input',\n name: 'name',\n message: `the matched rule is \\`${String(matchedRule)}\\`, please input the basename\\n`\n }).then(({ name }) => name)\n }\n\n if (typeof matchedRule === 'function') {\n return matchedRule(name, {\n full: wd,\n relative: cwd,\n basename: basename\n })\n }\n if (typeof matchedRule === 'string') {\n const dirName = name ?? basename\n return [\n matchedRule.replace(/\\$basename/g, dirName),\n matchedKey?.replace(/\\/\\*$/g, `/${dirName}`)\n ]\n }\n throw new Error('no matched rule')\n}\n\nprogram\n .command('init [name]')\n .option('-t, --template <template>', 'the package.json template file path or file content')\n .action(async () => {\n const [, name] = program.args\n const cwd = process.cwd()\n const { init = {} }: Config = loadConfig() ?? {}\n const { wd } = getWD()\n const workspaceName = path.basename(wd)\n\n const {\n named,\n template,\n bug = {},\n readme: _readme = README_TEMPLATE,\n readmeTemplate\n } = init\n const resolvedBug = {\n template: 'bug_report.yml',\n labels: ['bug'],\n ...bug\n }\n let readme = _readme\n if (readmeTemplate) {\n const readmeTemplatePath = path.resolve(wd, readmeTemplate)\n readme = fs.readFileSync(readmeTemplatePath, 'utf-8')\n }\n\n const templateString = getTemplateStr(wd, template)\n // TODO detectIndent by editorconfig\n const { indent = ' ' } = detectIndent(templateString)\n const formattingOptions = {\n tabSize: indent.length,\n insertSpaces: true\n }\n const passFields = [\n 'license', 'author'\n ]\n let newJSONString = templateString\n for (const field of passFields) {\n newJSONString = applyEdits(newJSONString, modify(\n newJSONString, [field], getWDPackageJSONFiled(wd, field), { formattingOptions }\n ))\n }\n let [pkgName, pkgDir] = await getName(named, name, {\n wd, cwd,\n workspaceName\n })\n if (!pkgDir) {\n const { dir } = await inquirer.prompt<{ dir: string }>({\n type: 'input',\n name: 'dir',\n message: 'package directory',\n default: name\n })\n pkgDir = dir\n }\n if (!pkgName) {\n const { name: inputName } = await inquirer.prompt<{\n name: string\n }>({\n type: 'input',\n name: 'name',\n message: 'package name',\n default: name\n })\n pkgName = inputName\n }\n newJSONString = applyEdits(newJSONString, modify(newJSONString, ['name'], pkgName, { formattingOptions }))\n\n let pkgRepo = getWDPackageJSONFiled(wd, 'repository')\n if (typeof pkgRepo === 'string') {\n pkgRepo = {\n type: 'git',\n url: pkgRepo,\n directory: pkgDir\n }\n }\n newJSONString = applyEdits(newJSONString, modify(\n newJSONString, ['repository'], pkgRepo, { formattingOptions }\n ))\n const homepage = `${pkgRepo?.url}/blob/master/${pkgDir}/README.md`\n newJSONString = applyEdits(newJSONString, modify(\n newJSONString, ['homepage'], homepage, { formattingOptions }\n ))\n let labels = resolvedBug.labels\n if (typeof labels === 'function') labels = labels({\n name: pkgName, dir: pkgDir\n })\n labels.push(`scope:${pkgName}`)\n const bugs = `${pkgRepo?.url}/issues/new?template=${\n resolvedBug.template\n }&labels=${\n labels.join(',')\n }`\n newJSONString = applyEdits(newJSONString, modify(\n newJSONString, ['bugs'], bugs, { formattingOptions }\n ))\n\n function pkgDirTo(to: string) {\n if (!pkgDir) throw new Error('pkgDir is not defined')\n\n return path.resolve(pkgDir, to)\n }\n if (!fs.existsSync(pkgDir)) fs.mkdirSync(pkgDir)\n const pkgJSONFilePath = pkgDirTo('package.json')\n if (fs.existsSync(pkgJSONFilePath)) {\n throw new Error('package.json already exists')\n }\n fs.writeFileSync(pkgJSONFilePath, newJSONString)\n console.log(newJSONString, 'written to', pkgJSONFilePath)\n\n const license = getWDPackageJSONFiled(wd, 'license')\n const readmeFilePath = pkgDirTo('README.md')\n if (typeof readme === 'function') {\n readme = readme({\n dir: pkgDir,\n packageJson: JSON.parse(newJSONString)\n })\n }\n const readmeContent = readme\n .replace(/\\$name/g, pkgName)\n .replace(/\\$license/g, license)\n fs.writeFileSync(readmeFilePath, readmeContent)\n })\n","import * as childProcess from 'node:child_process'\nimport fs from 'node:fs'\nimport path from 'node:path'\n\nimport { bump, type BumperType } from '@jiek/utils/bumper'\nimport { program } from 'commander'\nimport detectIndent from 'detect-indent'\nimport { applyEdits, modify } from 'jsonc-parser'\n\nimport { actionDone, actionRestore } from '../inner'\nimport { mergePackageJson } from '../merge-package-json'\nimport { getSelectedProjectsGraph } from '../utils/filterSupport'\n\nprogram\n .command('publish')\n .aliases(['pub', 'p'])\n .option('-b, --bumper <bumper>', 'bump version', 'patch')\n .option('-p, --preview', 'preview publish')\n .action(async ({ preview, bumper, ...options }: {\n preview?: boolean\n bumper: BumperType\n }) => {\n actionRestore()\n\n const { value = {} } = await getSelectedProjectsGraph() ?? {}\n const selectedProjectsGraphEntries = Object.entries(value)\n if (selectedProjectsGraphEntries.length === 0) {\n throw new Error('no packages selected')\n }\n const mainfests = selectedProjectsGraphEntries\n .map(([dir, manifest]) => [\n dir, mergePackageJson(manifest, dir)\n ] as const)\n const passArgs = Object\n .entries(options)\n .reduce((acc, [key, value]) => {\n if (value) {\n acc.push(`--${key}`, value as string)\n }\n return acc\n }, [] as string[])\n for (const [dir, manifest] of mainfests) {\n const oldJSONString = fs.readFileSync(path.join(dir, 'package.json'), 'utf-8')\n const oldJSON = JSON.parse(oldJSONString) ?? '0.0.0'\n const newVersion = bump(oldJSON.version, bumper)\n // TODO detectIndent by editorconfig\n const { indent = ' ' } = detectIndent(oldJSONString)\n const formattingOptions = {\n tabSize: indent.length,\n insertSpaces: true\n }\n let newJSONString = oldJSONString\n newJSONString = applyEdits(newJSONString, modify(\n newJSONString, ['version'], newVersion, { formattingOptions }\n ))\n for (const [key, value] of Object.entries(manifest)) {\n if (JSON.stringify(value) === JSON.stringify(oldJSON[key])) continue\n\n newJSONString = applyEdits(newJSONString, modify(\n newJSONString, ['publishConfig', key], value, { formattingOptions }\n ))\n }\n try {\n fs.renameSync(path.join(dir, 'package.json'), path.join(dir, 'package.json.bak'))\n fs.writeFileSync(path.join(dir, 'package.json'), newJSONString)\n console.log(newJSONString)\n if (preview) {\n console.warn('preview mode')\n continue\n }\n childProcess.execSync(['pnpm', 'publish', '--access', 'public', '--no-git-checks', ...passArgs].join(' '), {\n cwd: dir,\n stdio: 'inherit'\n })\n const modifyVersionPackageJSON = applyEdits(oldJSONString, modify(oldJSONString, ['version'], newVersion, {}))\n fs.writeFileSync(path.join(dir, 'package.json.bak'), modifyVersionPackageJSON)\n } finally {\n fs.unlinkSync(path.join(dir, 'package.json'))\n fs.renameSync(path.join(dir, 'package.json.bak'), path.join(dir, 'package.json'))\n }\n }\n actionDone()\n })\n","import './utils/filterSupport'\nimport './commands/build'\nimport './commands/init'\nimport './commands/publish'\n\nimport { program } from 'commander'\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst pkg = require('../package.json')\n\nprogram\n .version(pkg.version)\n .description(pkg.description)\n .option('--root <root>', 'root path')\n .option('-c, --config-path <configPath>', 'config path')\n\nprogram.parse(process.argv)\n"],"names":["root","wd","getRoot","rootOption","program","getOptionValue","path","default","isAbsolute","resolve","process","cwd","notWorkspace","getWD","getWorkspaceDir","type","e","message","tsRegisterName","require","async","getSelectedProjectsGraph","filter","pnpmWorkspaceFilePath","pnpmWorkspaceFileContent","fs","readFileSync","pnpmWorkspace","load","Error","existsSync","packageJSON","JSON","parse","name","selectedProjectsGraph","filterPackagesFromDir","followProdDepsOnly","prefix","workspaceDir","patterns","packages","value","Object","entries","reduce","acc","key","package","manifest","actionDone","actionRestore","Promise","r","mergePackageJson","jiek","_","exports","includeIndex","Array","isArray","length","inputs","concat","TypeError","absoluteInputs","map","input","cDir","dirname","files","resolvedFiles","file","first","parts","split","common","i","segment","every","startsWith","commondir","resolvedInputs","relative","pkger","noIndex","source","packageIsExist","option","registers","env","JIEK_TS_REGISTER","Boolean","register","FILE_TEMPLATE","stringify","trimStart","command","action","keys","jiekTempDir","paths","mkdirSync","rollupBinaryPath","replace","dir","newManifest","escapeManifestName","configFile","writeFileSync","childProcess","execSync","stdio","configName","loadConfig","configPath","isSupportTsLoader","configWithExtIsExist","ext","filenames","filename","lstatSync","isFile","getConfigPath","extname","module","PACKAGE_JSON_TEMPLATE","README_TEMPLATE","wdCache","Map","getWDPackageJSONFiled","field","has","get","packageJSONPath","set","args","init","workspaceName","basename","named","template","bug","readme","_readme","readmeTemplate","resolvedBug","labels","readmeTemplatePath","templateString","isTemplateFile","templatePath","getTemplateStr","indent","detectIndent","formattingOptions","tabSize","insertSpaces","passFields","newJSONString","applyEdits","modify","pkgName","pkgDir","relativePath","full","matchedKey","matchedRule","isParentMatched","rule","inquirer","prompt","choices","isMatch","String","then","dirName","getName","inputName","pkgRepo","url","directory","homepage","push","bugs","join","pkgDirTo","to","pkgJSONFilePath","console","log","license","readmeFilePath","packageJson","readmeContent","aliases","preview","bumper","options","selectedProjectsGraphEntries","mainfests","passArgs","oldJSONString","oldJSON","newVersion","bump","version","renameSync","warn","modifyVersionPackageJSON","unlinkSync","pkg","description","argv"],"mappings":"ovBAIA,IAAIA,ECCAC,EDAG,SAASC,IACV,GAAAF,EAAa,OAAAA,EAEX,MAAAG,EAAaC,EAAAA,QAAQC,eAAe,QAMnC,OALPL,EAAOG,EACHG,EAAAC,QAAKC,WAAWL,GACdA,EACAG,EAAAA,QAAKG,QAAQC,QAAQC,MAAOR,GAC9BO,QAAQC,MACLX,CACT,CCTA,IAAIY,GAAe,EAEZ,SAASC,IACV,GAAAZ,EAAW,MAAA,CAAEA,KAAIW,gBAErB,MAAMZ,EAAOE,IACT,IACGD,EAAAa,EAAAA,gBAAgBd,EAAMe,SACpBC,GAEP,KAAI,YAAaA,IAAmB,6BAAdA,EAAEC,QAIhB,MAAAD,EAHDf,EAAAD,EACUY,GAAA,CAInB,CACO,MAAA,CAAEX,KAAIW,eACf,CCbO,ICXHH,ECSOS,EFEAH,EAAO,GAElB,IACEI,QAAQV,QAAQ,mCACTM,EAAA,MACT,CAAQ,MAAc,CActBK,eAAsBC,IAChB,IAAAC,EAASlB,EAAAA,QAAQC,eAAe,UACpC,MAAML,EAAOE,KACPD,GAAEA,EAAAW,aAAIA,GAAiBC,IACzB,IAACD,GAAyB,SAATG,EAAiB,CACpC,MAAMQ,EAAwBjB,EAAAC,QAAKE,QAAQR,EAAI,uBACzCuB,EAA2BC,EAAAlB,QAAG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F,EAAK,oBAAqBnG,EAAAA,QAAKmL,KAAKhF,EAAK,gBACnE,CACF,CACWvD,GAAA,ICzEf,MAAMiK,EAAMhM,QAAQ,mBAEpBf,EAAAA,QACG0M,QAAQK,EAAIL,SACZM,YAAYD,EAAIC,aAChB5H,OAAO,gBAAiB,aACxBA,OAAO,iCAAkC,eAE5CpF,EAAAA,QAAQ6B,MAAMvB,QAAQ2M"}
1
+ {"version":3,"file":"cli.cjs","sources":["../src/utils/getRoot.ts","../src/utils/getWD.ts","../src/utils/filterSupport.ts","../src/commands/base.ts","../src/inner.ts","../src/utils/tsRegister.ts","../src/merge-package-json.ts","../src/utils/commondir.ts","../src/commands/build.ts","../src/utils/loadConfig.ts","../src/commands/init.ts","../src/commands/publish.ts","../src/cli.ts"],"sourcesContent":["import path from 'node:path'\n\nimport { program } from 'commander'\n\nlet root: string\nexport function getRoot() {\n if (root) return root\n\n const rootOption = program.getOptionValue('root')\n root = rootOption\n ? path.isAbsolute(rootOption)\n ? rootOption\n : path.resolve(process.cwd(), rootOption)\n : undefined\n return root\n}\n","import { getWorkspaceDir, isWorkspaceDir } from '@jiek/utils/getWorkspaceDir'\n\nimport { type } from './filterSupport'\nimport { getRoot } from './getRoot'\n\nlet wd: string\nlet notWorkspace = false\n\nexport function getWD() {\n if (wd) return { wd, notWorkspace }\n\n const root = getRoot()\n if (root !== undefined) {\n const isWorkspace = isWorkspaceDir(root, type)\n notWorkspace = !isWorkspace\n wd = root\n return { wd, notWorkspace }\n }\n try {\n wd = getWorkspaceDir(type)\n } catch (e) {\n // @ts-ignore\n if ('message' in e && e.message === 'workspace root not found') {\n wd = root\n notWorkspace = true\n } else {\n throw e\n }\n }\n return { wd, notWorkspace }\n}\n","import fs from 'node:fs'\nimport path from 'node:path'\n\nimport { getWorkspaceDir } from '@jiek/utils/getWorkspaceDir'\nimport { filterPackagesFromDir } from '@pnpm/filter-workspace-packages'\nimport { program } from 'commander'\nimport { load } from 'js-yaml'\n\nimport { getRoot } from './getRoot'\nimport { getWD } from './getWD'\n\nexport let type = ''\n\ntry {\n require.resolve('@pnpm/filter-workspace-packages')\n type = 'pnpm'\n} catch { /* empty */ }\nif (type !== '') {\n program\n .option('-f, --filter <filter>', 'filter packages')\n}\n\ninterface ProjectsGraph {\n wd: string\n root: string\n value?: Record<string, {\n name?: string\n }>\n}\n\nexport async function getSelectedProjectsGraph(): Promise<ProjectsGraph> {\n let filter = program.getOptionValue('filter')\n const root = getRoot()\n const { wd, notWorkspace } = getWD()\n if (!notWorkspace && type === 'pnpm') {\n const pnpmWorkspaceFilePath = path.resolve(wd, 'pnpm-workspace.yaml')\n const pnpmWorkspaceFileContent = fs.readFileSync(pnpmWorkspaceFilePath, 'utf-8')\n const pnpmWorkspace = load(pnpmWorkspaceFileContent) as {\n packages: string[]\n }\n if (root === wd && !filter) {\n throw new Error('root path is workspace root, please provide a filter')\n // TODO inquirer prompt support user select packages\n }\n if (root !== wd && !filter) {\n const packageJSONIsExist = fs.existsSync(path.resolve(root, 'package.json'))\n if (!packageJSONIsExist) {\n throw new Error('root path is not workspace root, please provide a filter')\n }\n const packageJSON = JSON.parse(fs.readFileSync(path.resolve(root, 'package.json'), 'utf-8'))\n if (!packageJSON.name) {\n throw new Error('root path is not workspace root, please provide a filter')\n }\n filter = packageJSON.name\n }\n const { selectedProjectsGraph } = await filterPackagesFromDir(wd, [{\n filter: filter ?? '',\n followProdDepsOnly: true\n }], {\n prefix: root,\n workspaceDir: wd,\n patterns: pnpmWorkspace.packages\n })\n return {\n wd, root,\n value: Object.entries(selectedProjectsGraph)\n .reduce((acc, [key, value]) => {\n acc[key] = value.package.manifest\n return acc\n }, {} as NonNullable<ProjectsGraph['value']>)\n }\n }\n return {\n wd, root,\n value: {\n [wd]: JSON.parse(fs.readFileSync(path.resolve(wd, 'package.json'), 'utf-8'))\n }\n }\n}\n","import { program } from 'commander'\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst pkg = require('../../package.json')\n\nprogram\n .version(pkg.version)\n .description(pkg.description)\n .option('--root <root>', 'root path')\n .option('-c, --config-path <configPath>', 'config path')\n","let resolve: () => void\n\nexport let actionFuture: Promise<void>\n\nexport function actionDone() {\n resolve()\n}\n\nexport function actionRestore() {\n actionFuture = new Promise<void>(r => resolve = r)\n}\n","function packageIsExist(name: string) {\n try {\n require.resolve(name)\n return true\n } catch (e) {\n return false\n }\n}\n\nexport let tsRegisterName: string | undefined\nconst registers = [\n process.env.JIEK_TS_REGISTER,\n 'esbuild-register',\n '@swc-node/register',\n 'ts-node/register'\n].filter(Boolean) as string[]\nfor (const register of registers) {\n if (packageIsExist(register)) {\n tsRegisterName = register\n break\n }\n}\n","import path from 'node:path'\n\nimport { type Options, pkger } from '@jiek/pkger'\nimport type { Manifest } from '@pnpm/workspace.pkgs-graph'\n\nimport { commondir } from './utils/commondir'\n\nexport function mergePackageJson(manifest: Manifest & {\n jiek?: Options\n exports?: unknown | unknown[]\n}, cwd: string, options: {\n excludeDistInExports?: boolean\n} = {}) {\n const {\n excludeDistInExports = false\n } = options\n const {\n jiek: { cwd: _, ...jiek } = {}\n } = manifest\n const { outdir = 'dist' } = jiek\n let { exports } = manifest\n let includeIndex = false\n if (typeof exports === 'string') {\n includeIndex = true\n exports = { '.': exports }\n }\n if (exports === undefined) {\n exports = { '.': './src/index.ts' }\n }\n if (typeof exports === 'object') {\n if (Array.isArray(exports) && exports.length > 0) {\n includeIndex = true\n } else {\n includeIndex = !!(<Record<string, unknown>>exports)['.']\n }\n }\n let inputs = Array.isArray(exports)\n ? exports as string[]\n : Object\n .entries(<Record<string, unknown>>exports)\n .reduce((acc, [key, value]) => {\n if (typeof value === 'string') return key === '.'\n ? [value, ...acc]\n : acc.concat(value)\n if (Array.isArray(value)) return acc.concat(value)\n\n throw new TypeError(`Unexpected value type for key \"${key}\" in exports, expected string, got ${typeof value}`)\n }, [] as string[])\n if (excludeDistInExports) {\n inputs = inputs.filter(input => !input.startsWith(`./${outdir}`) && !input.startsWith(outdir))\n }\n if (inputs.length === 0)\n throw new Error('No inputs found')\n\n const absoluteInputs = inputs.map(input => path.isAbsolute(input)\n ? input\n : path.resolve(cwd, input)\n )\n let cDir = path.dirname(absoluteInputs[0])\n if (absoluteInputs.length > 1) {\n cDir = commondir(absoluteInputs, cwd)\n }\n const resolvedInputs = absoluteInputs.map(input => {\n return path.relative(cDir, input)\n })\n return {\n ...manifest,\n ...pkger({\n cwd,\n noIndex: !includeIndex,\n source: path.relative(cwd, cDir),\n inputs: resolvedInputs,\n ...jiek\n })\n }\n}\n","import path from 'node:path'\n\nexport function commondir(files: string[], cwd = process.cwd()): string {\n const resolvedFiles = files.map(file => {\n if (path.isAbsolute(file)) return file\n return path.resolve(cwd, file)\n })\n const sep = '/'\n const [first = ''] = resolvedFiles\n const parts = first.split(sep)\n let common = ''\n for (let i = 0; i < parts.length; i++) {\n const segment = parts[i]\n if (resolvedFiles.every(file => file.startsWith(common + segment))) {\n common += segment + sep\n } else {\n break\n }\n }\n return common\n}\n","import * as childProcess from 'node:child_process'\nimport fs from 'node:fs'\nimport path from 'node:path'\n\nimport { program } from 'commander'\n\nimport { actionDone, actionRestore } from '../inner'\nimport { mergePackageJson } from '../merge-package-json'\nimport { getSelectedProjectsGraph } from '../utils/filterSupport'\nimport { tsRegisterName } from '../utils/tsRegister'\n\nconst FILE_TEMPLATE = (manifest: unknown) => `\nconst pkg = ${JSON.stringify(manifest, null, 2)}\nconst { jiek = {} } = pkg\nconst templateArg = jiek.templateArgFilePath\n ? require.resolve(jiek.templateArgFilePath)\n : {\n styled: jiek.styled\n }\nmodule.exports = require('jiek/rollup').template(templateArg, pkg)\n`.trimStart()\n\nprogram\n .command('build')\n .action(async () => {\n actionRestore()\n const {\n wd, value = {}\n } = await getSelectedProjectsGraph() ?? {}\n\n if (Object.keys(value).length === 0) {\n throw new Error('no package found')\n }\n const jiekTempDir = (...paths: string[]) => path.resolve(wd, 'node_modules/.jiek', ...paths)\n if (!fs.existsSync(jiekTempDir())) fs.mkdirSync(jiekTempDir())\n\n const rollupBinaryPath = require.resolve('rollup')\n .replace(/dist\\/rollup.js$/, 'dist/bin/rollup')\n let i = 0\n for (const [dir, manifest] of Object.entries(value)) {\n const newManifest = mergePackageJson(manifest, dir, { excludeDistInExports: true })\n // TODO support auto build child packages in workspaces\n const escapeManifestName = manifest.name?.replace(/^@/g, '').replace(/\\//g, '+')\n const configFile = jiekTempDir(\n `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`\n )\n fs.writeFileSync(configFile, FILE_TEMPLATE(newManifest))\n let prefix = ''\n if (tsRegisterName) {\n prefix = `node -r ${tsRegisterName} `\n }\n // TODO replace with `spawn` to support watch mode\n childProcess.execSync(`${prefix}${rollupBinaryPath} --silent -c ${configFile}`, {\n cwd: dir, stdio: 'inherit'\n })\n }\n\n actionDone()\n })\n","import fs from 'node:fs'\nimport path from 'node:path'\n\nimport { program } from 'commander'\nimport { load } from 'js-yaml'\n\nimport { getWD } from './getWD'\nimport { tsRegisterName } from './tsRegister'\n\nlet configName = 'jiek.config'\n\nfunction getConfigPath(root: string) {\n const isSupportTsLoader = !!tsRegisterName\n function configWithExtIsExist(ext: string) {\n const filenames = [\n path.resolve(root, `${configName}.${ext}`),\n path.resolve(root, `.${configName}.${ext}`)\n ]\n for (const filename of filenames) {\n if (\n fs.existsSync(filename) &&\n fs.lstatSync(filename)\n .isFile()\n ) {\n return filename\n }\n }\n return\n }\n configName = configWithExtIsExist('js') ?? configName\n configName = configWithExtIsExist('json') ?? configName\n configName = configWithExtIsExist('yaml') ?? configName\n if (isSupportTsLoader) {\n configName = configWithExtIsExist('ts') ?? configName\n }\n return path.resolve(root, configName)\n}\n\nexport function loadConfig() {\n const { wd: root, notWorkspace } = getWD()\n if (notWorkspace)\n throw new Error('not in workspace')\n\n let configPath = program.getOptionValue('configPath')\n\n if (!configPath) {\n configPath = getConfigPath(root)\n } else {\n if (!fs.existsSync(configPath))\n throw new Error(`config file not found: ${configPath}`)\n if (!path.isAbsolute(configPath))\n configPath = path.resolve(root, configPath)\n }\n const ext = path.extname(configPath)\n\n let module: any\n switch (ext) {\n case '.js':\n module = require(configPath)\n break\n case '.json':\n return require(configPath)\n case '.yaml':\n return load(fs.readFileSync(configPath, 'utf-8'))\n case '.ts':\n if (tsRegisterName) {\n require(tsRegisterName)\n module = require(configPath)\n break\n }\n throw new Error(\n 'ts config file is not supported without ts register, ' +\n 'please install esbuild-register or set JIEK_TS_REGISTER env for custom ts register'\n )\n case '.config':\n module = {}\n break\n default:\n throw new Error(`unsupported config file type: ${ext}`)\n }\n if (!module) throw new Error('config file is empty')\n\n return module.default ?? module\n}\n","import fs from 'node:fs'\nimport path from 'node:path'\n\nimport { program } from 'commander'\nimport detectIndent from 'detect-indent'\nimport inquirer from 'inquirer'\nimport { applyEdits, modify } from 'jsonc-parser'\nimport { isMatch } from 'micromatch'\n\nimport type { Config, InitNamed } from '../base'\nimport { getWD } from '../utils/getWD'\nimport { loadConfig } from '../utils/loadConfig'\n\nconst PACKAGE_JSON_TEMPLATE = `{\n \"name\": \"\",\n \"version\": \"0.0.1\",\n \"description\": \"\",\n \"license\": \"\",\n \"author\": \"\",\n \"files\": [\"dist\"],\n \"exports\": {\n \".\": \"./src/index.ts\"\n },\n \"scripts\": {\n },\n \"homepage\": \"\",\n \"repository\": \"\",\n \"bugs\": \"\"\n}`.trimStart()\nconst README_TEMPLATE = `# $name\n\n## Installation\n\n\\`\\`\\`bash\nnpm install $name\n# or\npnpm install $name\n# or\nyarn add $name\n\\`\\`\\`\n\n## Usage\n\n\n## License\n\n$license\n`.trimStart()\n\nfunction getTemplateStr(wd: string, template: string | undefined) {\n let templateString = template ?? PACKAGE_JSON_TEMPLATE\n let isTemplateFile = false\n try {\n if (template) JSON.parse(template)\n } catch (e) {\n isTemplateFile = true\n }\n if (isTemplateFile) {\n const templatePath = path.resolve(wd, template!)\n templateString = fs.readFileSync(templatePath, 'utf-8')\n }\n return templateString\n}\nconst wdCache = new Map<string, Record<string, any>>()\nfunction getWDPackageJSONFiled(wd: string, field: string) {\n if (wdCache.has(wd)) {\n return wdCache.get(wd)![field]\n }\n const packageJSONPath = path.resolve(wd, 'package.json')\n const packageJSON = JSON.parse(fs.readFileSync(packageJSONPath, 'utf-8'))\n wdCache.set(wd, packageJSON)\n return packageJSON[field]\n}\nasync function getName(\n named: InitNamed | undefined,\n name: string,\n {\n wd, cwd,\n workspaceName\n }: {\n wd: string\n cwd: string\n workspaceName: string\n }\n): Promise<[name?: string, path?: string]> {\n const relativePath = cwd.replace(`${wd}/`, '')\n let basename = path.basename(cwd)\n\n if (typeof named === 'function') {\n return named(name, {\n full: wd,\n relative: cwd\n })\n }\n\n let isParentMatched = false\n let matchedKey: string | undefined\n let matchedRule: NonNullable<typeof named>[string] | undefined\n if (typeof named === 'object') {\n const isWD = cwd === wd\n if (isWD) {\n const { rule } = await inquirer.prompt<{ rule: string }>({\n type: 'list',\n name: 'rule',\n message: 'choose a rule',\n default: 'default',\n choices: ['default'].concat(Object.keys(named))\n })\n if (rule !== 'default') {\n matchedKey = rule\n matchedRule = named[rule]\n }\n } else for (const [key, value] of Object.entries(named)) {\n if (isMatch(relativePath, key)) {\n matchedKey = key\n matchedRule = value\n break\n }\n if (isMatch(`${relativePath}/jiek_ignore_dont_use_same_file_name`, key)) {\n isParentMatched = true\n matchedKey = key\n matchedRule = value\n break\n }\n }\n }\n if (!matchedRule) {\n matchedKey = 'packages/*'\n matchedRule = `@${workspaceName}/$basename`\n }\n if (!matchedRule)\n throw new Error('no matched rule')\n if (!name && isParentMatched) {\n basename = await inquirer.prompt<{ name: string }>({\n type: 'input',\n name: 'name',\n message: `the matched rule is \\`${String(matchedRule)}\\`, please input the basename\\n`\n }).then(({ name }) => name)\n }\n\n if (typeof matchedRule === 'function') {\n return matchedRule(name, {\n full: wd,\n relative: cwd,\n basename: basename\n })\n }\n if (typeof matchedRule === 'string') {\n const dirName = name ?? basename\n return [\n matchedRule.replace(/\\$basename/g, dirName),\n matchedKey?.replace(/\\/\\*$/g, `/${dirName}`)\n ]\n }\n throw new Error('no matched rule')\n}\n\nprogram\n .command('init [name]')\n .option('-t, --template <template>', 'the package.json template file path or file content')\n .action(async () => {\n const [, name] = program.args\n const cwd = process.cwd()\n const { init = {} }: Config = loadConfig() ?? {}\n const { wd } = getWD()\n const workspaceName = path.basename(wd)\n\n const {\n named,\n template,\n bug = {},\n readme: _readme = README_TEMPLATE,\n readmeTemplate\n } = init\n const resolvedBug = {\n template: 'bug_report.yml',\n labels: ['bug'],\n ...bug\n }\n let readme = _readme\n if (readmeTemplate) {\n const readmeTemplatePath = path.resolve(wd, readmeTemplate)\n readme = fs.readFileSync(readmeTemplatePath, 'utf-8')\n }\n\n const templateString = getTemplateStr(wd, template)\n // TODO detectIndent by editorconfig\n const { indent = ' ' } = detectIndent(templateString)\n const formattingOptions = {\n tabSize: indent.length,\n insertSpaces: true\n }\n const passFields = [\n 'license', 'author'\n ]\n let newJSONString = templateString\n for (const field of passFields) {\n newJSONString = applyEdits(newJSONString, modify(\n newJSONString, [field], getWDPackageJSONFiled(wd, field), { formattingOptions }\n ))\n }\n let [pkgName, pkgDir] = await getName(named, name, {\n wd, cwd,\n workspaceName\n })\n if (!pkgDir) {\n const { dir } = await inquirer.prompt<{ dir: string }>({\n type: 'input',\n name: 'dir',\n message: 'package directory',\n default: name\n })\n pkgDir = dir\n }\n if (!pkgName) {\n const { name: inputName } = await inquirer.prompt<{\n name: string\n }>({\n type: 'input',\n name: 'name',\n message: 'package name',\n default: name\n })\n pkgName = inputName\n }\n newJSONString = applyEdits(newJSONString, modify(newJSONString, ['name'], pkgName, { formattingOptions }))\n\n let pkgRepo = getWDPackageJSONFiled(wd, 'repository')\n if (typeof pkgRepo === 'string') {\n pkgRepo = {\n type: 'git',\n url: pkgRepo,\n directory: pkgDir\n }\n }\n newJSONString = applyEdits(newJSONString, modify(\n newJSONString, ['repository'], pkgRepo, { formattingOptions }\n ))\n const homepage = `${pkgRepo?.url}/blob/master/${pkgDir}/README.md`\n newJSONString = applyEdits(newJSONString, modify(\n newJSONString, ['homepage'], homepage, { formattingOptions }\n ))\n let labels = resolvedBug.labels\n if (typeof labels === 'function') labels = labels({\n name: pkgName, dir: pkgDir\n })\n labels.push(`scope:${pkgName}`)\n const bugs = `${pkgRepo?.url}/issues/new?template=${\n resolvedBug.template\n }&labels=${\n labels.join(',')\n }`\n newJSONString = applyEdits(newJSONString, modify(\n newJSONString, ['bugs'], bugs, { formattingOptions }\n ))\n\n function pkgDirTo(to: string) {\n if (!pkgDir) throw new Error('pkgDir is not defined')\n\n return path.resolve(pkgDir, to)\n }\n if (!fs.existsSync(pkgDir)) fs.mkdirSync(pkgDir)\n const pkgJSONFilePath = pkgDirTo('package.json')\n if (fs.existsSync(pkgJSONFilePath)) {\n throw new Error('package.json already exists')\n }\n fs.writeFileSync(pkgJSONFilePath, newJSONString)\n console.log(newJSONString, 'written to', pkgJSONFilePath)\n\n const license = getWDPackageJSONFiled(wd, 'license')\n const readmeFilePath = pkgDirTo('README.md')\n if (typeof readme === 'function') {\n readme = readme({\n dir: pkgDir,\n packageJson: JSON.parse(newJSONString)\n })\n }\n const readmeContent = readme\n .replace(/\\$name/g, pkgName)\n .replace(/\\$license/g, license)\n fs.writeFileSync(readmeFilePath, readmeContent)\n })\n","import * as childProcess from 'node:child_process'\nimport fs from 'node:fs'\nimport path from 'node:path'\n\nimport { bump, type BumperType } from '@jiek/utils/bumper'\nimport { program } from 'commander'\nimport detectIndent from 'detect-indent'\nimport { applyEdits, modify } from 'jsonc-parser'\n\nimport { actionDone, actionRestore } from '../inner'\nimport { mergePackageJson } from '../merge-package-json'\nimport { getSelectedProjectsGraph } from '../utils/filterSupport'\n\nprogram\n .command('publish')\n .aliases(['pub', 'p'])\n .option('-b, --bumper <bumper>', 'bump version', 'patch')\n .option('-p, --preview', 'preview publish')\n .action(async ({ preview, bumper, ...options }: {\n preview?: boolean\n bumper: BumperType\n }) => {\n actionRestore()\n\n const { value = {} } = await getSelectedProjectsGraph() ?? {}\n const selectedProjectsGraphEntries = Object.entries(value)\n if (selectedProjectsGraphEntries.length === 0) {\n throw new Error('no packages selected')\n }\n const mainfests = selectedProjectsGraphEntries\n .map(([dir, manifest]) => [\n dir, mergePackageJson(manifest, dir)\n ] as const)\n const passArgs = Object\n .entries(options)\n .reduce((acc, [key, value]) => {\n if (value) {\n acc.push(`--${key}`, value as string)\n }\n return acc\n }, [] as string[])\n for (const [dir, manifest] of mainfests) {\n const oldJSONString = fs.readFileSync(path.join(dir, 'package.json'), 'utf-8')\n const oldJSON = JSON.parse(oldJSONString) ?? '0.0.0'\n const newVersion = bump(oldJSON.version, bumper)\n // TODO detectIndent by editorconfig\n const { indent = ' ' } = detectIndent(oldJSONString)\n const formattingOptions = {\n tabSize: indent.length,\n insertSpaces: true\n }\n let newJSONString = oldJSONString\n newJSONString = applyEdits(newJSONString, modify(\n newJSONString, ['version'], newVersion, { formattingOptions }\n ))\n for (const [key, value] of Object.entries(manifest)) {\n if (JSON.stringify(value) === JSON.stringify(oldJSON[key])) continue\n\n newJSONString = applyEdits(newJSONString, modify(\n newJSONString, ['publishConfig', key], value, { formattingOptions }\n ))\n }\n try {\n fs.renameSync(path.join(dir, 'package.json'), path.join(dir, 'package.json.bak'))\n fs.writeFileSync(path.join(dir, 'package.json'), newJSONString)\n console.log(newJSONString)\n if (preview) {\n console.warn('preview mode')\n continue\n }\n childProcess.execSync(['pnpm', 'publish', '--access', 'public', '--no-git-checks', ...passArgs].join(' '), {\n cwd: dir,\n stdio: 'inherit'\n })\n const modifyVersionPackageJSON = applyEdits(oldJSONString, modify(oldJSONString, ['version'], newVersion, {}))\n fs.writeFileSync(path.join(dir, 'package.json.bak'), modifyVersionPackageJSON)\n } finally {\n fs.unlinkSync(path.join(dir, 'package.json'))\n fs.renameSync(path.join(dir, 'package.json.bak'), path.join(dir, 'package.json'))\n }\n }\n actionDone()\n })\n","import './utils/filterSupport'\nimport './commands/base'\nimport './commands/build'\nimport './commands/init'\nimport './commands/publish'\n\nimport { program } from 'commander'\n\nprogram.parse(process.argv)\n"],"names":["root","wd","getRoot","rootOption","program","getOptionValue","path","isAbsolute","default","resolve","process","cwd","notWorkspace","getWD","isWorkspace","isWorkspaceDir","type","getWorkspaceDir","e","message","require","async","getSelectedProjectsGraph","filter","pnpmWorkspaceFilePath","pnpmWorkspaceFileContent","fs","readFileSync","pnpmWorkspace","load","Error","existsSync","packageJSON","JSON","parse","name","selectedProjectsGraph","filterPackagesFromDir","followProdDepsOnly","prefix","workspaceDir","patterns","packages","value","Object","entries","reduce","acc","key","package","manifest","option","pkg","tsRegisterName","actionDone","actionRestore","Promise","r","mergePackageJson","options","excludeDistInExports","jiek","_","outdir","exports","includeIndex","Array","isArray","length","inputs","concat","TypeError","input","startsWith","absoluteInputs","map","cDir","dirname","files","resolvedFiles","file","first","parts","split","common","i","segment","every","commondir","resolvedInputs","relative","pkger","noIndex","source","packageIsExist","version","description","registers","env","JIEK_TS_REGISTER","Boolean","register","FILE_TEMPLATE","stringify","trimStart","command","action","keys","jiekTempDir","paths","mkdirSync","rollupBinaryPath","replace","dir","newManifest","escapeManifestName","configFile","writeFileSync","childProcess","execSync","stdio","configName","loadConfig","configPath","isSupportTsLoader","configWithExtIsExist","ext","filenames","filename","lstatSync","isFile","getConfigPath","extname","module","PACKAGE_JSON_TEMPLATE","README_TEMPLATE","wdCache","Map","getWDPackageJSONFiled","field","has","get","packageJSONPath","set","args","init","workspaceName","basename","named","template","bug","readme","_readme","readmeTemplate","resolvedBug","labels","readmeTemplatePath","templateString","isTemplateFile","templatePath","getTemplateStr","indent","detectIndent","formattingOptions","tabSize","insertSpaces","passFields","newJSONString","applyEdits","modify","pkgName","pkgDir","relativePath","full","matchedKey","matchedRule","isParentMatched","rule","inquirer","prompt","choices","isMatch","String","then","dirName","getName","inputName","pkgRepo","url","directory","homepage","push","bugs","join","pkgDirTo","to","pkgJSONFilePath","console","log","license","readmeFilePath","packageJson","readmeContent","aliases","preview","bumper","selectedProjectsGraphEntries","mainfests","passArg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GgN,WAAWlN,EAAAE,QAAKyL,KAAKhF,EAAK,iBAC1BvF,EAAAA,QAAA2L,WAAW/M,UAAK2L,KAAKhF,EAAK,oBAAqB3G,EAAAA,QAAK2L,KAAKhF,EAAK,gBACnE,CACF,CACW3D,GAAA,ICzEflD,EAAAA,QAAQ8B,MAAMxB,QAAQ+M"}
package/dist/cli.esm.js CHANGED
@@ -1,10 +1,9 @@
1
1
  import './utils/filterSupport.esm.js';
2
+ import './commands/base.esm.js';
2
3
  import './commands/build.esm.js';
3
4
  import './commands/init.esm.js';
4
5
  import './commands/publish.esm.js';
5
6
  import { program } from 'commander';
6
7
 
7
- const pkg = require("../package.json");
8
- program.version(pkg.version).description(pkg.description).option("--root <root>", "root path").option("-c, --config-path <configPath>", "config path");
9
8
  program.parse(process.argv);
10
9
  //# sourceMappingURL=cli.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cli.esm.js","sources":["../src/cli.ts"],"sourcesContent":["import './utils/filterSupport'\nimport './commands/build'\nimport './commands/init'\nimport './commands/publish'\n\nimport { program } from 'commander'\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst pkg = require('../package.json')\n\nprogram\n .version(pkg.version)\n .description(pkg.description)\n .option('--root <root>', 'root path')\n .option('-c, --config-path <configPath>', 'config path')\n\nprogram.parse(process.argv)\n"],"names":[],"mappings":";;;;;;AAQA,MAAM,GAAA,GAAM,QAAQ,iBAAiB,CAAA,CAAA;AAErC,OAAA,CACG,OAAQ,CAAA,GAAA,CAAI,OAAO,CAAA,CACnB,YAAY,GAAI,CAAA,WAAW,CAC3B,CAAA,MAAA,CAAO,eAAiB,EAAA,WAAW,CACnC,CAAA,MAAA,CAAO,kCAAkC,aAAa,CAAA,CAAA;AAEzD,OAAQ,CAAA,KAAA,CAAM,QAAQ,IAAI,CAAA"}
1
+ {"version":3,"file":"cli.esm.js","sources":["../src/cli.ts"],"sourcesContent":["import './utils/filterSupport'\nimport './commands/base'\nimport './commands/build'\nimport './commands/init'\nimport './commands/publish'\n\nimport { program } from 'commander'\n\nprogram.parse(process.argv)\n"],"names":[],"mappings":";;;;;;;AAQA,OAAQ,CAAA,KAAA,CAAM,QAAQ,IAAI,CAAA"}
@@ -1,2 +1,2 @@
1
- import"./utils/filterSupport.esm.min.js";import"./commands/build.esm.min.js";import"./commands/init.esm.min.js";import"./commands/publish.esm.min.js";import{program as o}from"commander";const i=require("../package.json");o.version(i.version).description(i.description).option("--root <root>","root path").option("-c, --config-path <configPath>","config path"),o.parse(process.argv);
1
+ import"./utils/filterSupport.esm.min.js";import"./commands/base.esm.min.js";import"./commands/build.esm.min.js";import"./commands/init.esm.min.js";import"./commands/publish.esm.min.js";import{program as m}from"commander";m.parse(process.argv);
2
2
  //# sourceMappingURL=cli.esm.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cli.esm.min.js","sources":["../src/cli.ts"],"sourcesContent":["import './utils/filterSupport'\nimport './commands/build'\nimport './commands/init'\nimport './commands/publish'\n\nimport { program } from 'commander'\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst pkg = require('../package.json')\n\nprogram\n .version(pkg.version)\n .description(pkg.description)\n .option('--root <root>', 'root path')\n .option('-c, --config-path <configPath>', 'config path')\n\nprogram.parse(process.argv)\n"],"names":["pkg","require","program","version","description","option","parse","process","argv"],"mappings":"0LAQA,MAAMA,EAAMC,QAAQ,mBAEpBC,EACGC,QAAQH,EAAIG,SACZC,YAAYJ,EAAII,aAChBC,OAAO,gBAAiB,aACxBA,OAAO,iCAAkC,eAE5CH,EAAQI,MAAMC,QAAQC"}
1
+ {"version":3,"file":"cli.esm.min.js","sources":["../src/cli.ts"],"sourcesContent":["import './utils/filterSupport'\nimport './commands/base'\nimport './commands/build'\nimport './commands/init'\nimport './commands/publish'\n\nimport { program } from 'commander'\n\nprogram.parse(process.argv)\n"],"names":["program","parse","process","argv"],"mappings":"6NAQAA,EAAQC,MAAMC,QAAQC"}
@@ -0,0 +1,5 @@
1
+ import { program } from 'commander';
2
+
3
+ const pkg = require("../../package.json");
4
+ program.version(pkg.version).description(pkg.description).option("--root <root>", "root path").option("-c, --config-path <configPath>", "config path");
5
+ //# sourceMappingURL=base.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.esm.js","sources":["../../src/commands/base.ts"],"sourcesContent":["import { program } from 'commander'\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst pkg = require('../../package.json')\n\nprogram\n .version(pkg.version)\n .description(pkg.description)\n .option('--root <root>', 'root path')\n .option('-c, --config-path <configPath>', 'config path')\n"],"names":[],"mappings":";;AAGA,MAAM,GAAA,GAAM,QAAQ,oBAAoB,CAAA,CAAA;AAExC,OAAA,CACG,OAAQ,CAAA,GAAA,CAAI,OAAO,CAAA,CACnB,YAAY,GAAI,CAAA,WAAW,CAC3B,CAAA,MAAA,CAAO,eAAiB,EAAA,WAAW,CACnC,CAAA,MAAA,CAAO,kCAAkC,aAAa,CAAA"}
@@ -0,0 +1,2 @@
1
+ import{program as o}from"commander";const i=require("../../package.json");o.version(i.version).description(i.description).option("--root <root>","root path").option("-c, --config-path <configPath>","config path");
2
+ //# sourceMappingURL=base.esm.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.esm.min.js","sources":["../../src/commands/base.ts"],"sourcesContent":["import { program } from 'commander'\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst pkg = require('../../package.json')\n\nprogram\n .version(pkg.version)\n .description(pkg.description)\n .option('--root <root>', 'root path')\n .option('-c, --config-path <configPath>', 'config path')\n"],"names":["pkg","require","program","version","description","option"],"mappings":"oCAGA,MAAMA,EAAMC,QAAQ,sBAEpBC,EACGC,QAAQH,EAAIG,SACZC,YAAYJ,EAAII,aAChBC,OAAO,gBAAiB,aACxBA,OAAO,iCAAkC"}
@@ -32,7 +32,7 @@ program.command("build").action(async () => {
32
32
  const rollupBinaryPath = require.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
33
33
  let i = 0;
34
34
  for (const [dir, manifest] of Object.entries(value)) {
35
- const newManifest = mergePackageJson(manifest, dir);
35
+ const newManifest = mergePackageJson(manifest, dir, { excludeDistInExports: true });
36
36
  const escapeManifestName = manifest.name?.replace(/^@/g, "").replace(/\//g, "+");
37
37
  const configFile = jiekTempDir(
38
38
  `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
@@ -42,7 +42,7 @@ program.command("build").action(async () => {
42
42
  if (tsRegisterName) {
43
43
  prefix = `node -r ${tsRegisterName} `;
44
44
  }
45
- childProcess.execSync(`${prefix}${rollupBinaryPath} -c ${configFile}`, {
45
+ childProcess.execSync(`${prefix}${rollupBinaryPath} --silent -c ${configFile}`, {
46
46
  cwd: dir,
47
47
  stdio: "inherit"
48
48
  });
@@ -1 +1 @@
1
- {"version":3,"file":"build.esm.js","sources":["../../src/commands/build.ts"],"sourcesContent":["import * as childProcess from 'node:child_process'\nimport fs from 'node:fs'\nimport path from 'node:path'\n\nimport { program } from 'commander'\n\nimport { actionDone, actionRestore } from '../inner'\nimport { mergePackageJson } from '../merge-package-json'\nimport { getSelectedProjectsGraph } from '../utils/filterSupport'\nimport { tsRegisterName } from '../utils/tsRegister'\n\nconst FILE_TEMPLATE = (manifest: unknown) => `\nconst pkg = ${JSON.stringify(manifest, null, 2)}\nconst { jiek = {} } = pkg\nconst templateArg = jiek.templateArgFilePath\n ? require.resolve(jiek.templateArgFilePath)\n : {\n styled: jiek.styled\n }\nmodule.exports = require('jiek/rollup').template(templateArg, pkg)\n`.trimStart()\n\nprogram\n .command('build')\n .action(async () => {\n actionRestore()\n const {\n wd, value = {}\n } = await getSelectedProjectsGraph() ?? {}\n\n if (Object.keys(value).length === 0) {\n throw new Error('no package found')\n }\n const jiekTempDir = (...paths: string[]) => path.resolve(wd, 'node_modules/.jiek', ...paths)\n if (!fs.existsSync(jiekTempDir())) fs.mkdirSync(jiekTempDir())\n\n const rollupBinaryPath = require.resolve('rollup')\n .replace(/dist\\/rollup.js$/, 'dist/bin/rollup')\n let i = 0\n for (const [dir, manifest] of Object.entries(value)) {\n const newManifest = mergePackageJson(manifest, dir)\n // TODO support auto build child packages in workspaces\n const escapeManifestName = manifest.name?.replace(/^@/g, '').replace(/\\//g, '+')\n const configFile = jiekTempDir(\n `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`\n )\n fs.writeFileSync(configFile, FILE_TEMPLATE(newManifest))\n let prefix = ''\n if (tsRegisterName) {\n prefix = `node -r ${tsRegisterName} `\n }\n // TODO replace with `spawn` to support watch mode\n childProcess.execSync(`${prefix}${rollupBinaryPath} -c ${configFile}`, {\n cwd: dir, stdio: 'inherit'\n })\n }\n\n actionDone()\n })\n"],"names":[],"mappings":";;;;;;;;;AAWA,MAAM,aAAA,GAAgB,CAAC,QAAsB,KAAA,CAAA;AAAA,YAAA,EAC/B,IAAK,CAAA,SAAA,CAAU,QAAU,EAAA,IAAA,EAAM,CAAC,CAAC,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAAA,CAQ7C,SAAU,EAAA,CAAA;AAEZ,OAAA,CACG,OAAQ,CAAA,OAAO,CACf,CAAA,MAAA,CAAO,YAAY;AAClB,EAAc,aAAA,EAAA,CAAA;AACd,EAAM,MAAA;AAAA,IACJ,EAAA;AAAA,IAAI,QAAQ,EAAC;AAAA,GACX,GAAA,MAAM,wBAAyB,EAAA,IAAK,EAAC,CAAA;AAEzC,EAAA,IAAI,MAAO,CAAA,IAAA,CAAK,KAAK,CAAA,CAAE,WAAW,CAAG,EAAA;AACnC,IAAM,MAAA,IAAI,MAAM,kBAAkB,CAAA,CAAA;AAAA,GACpC;AACA,EAAM,MAAA,WAAA,GAAc,IAAI,KAAoB,KAAA,IAAA,CAAK,QAAQ,EAAI,EAAA,oBAAA,EAAsB,GAAG,KAAK,CAAA,CAAA;AAC3F,EAAA,IAAI,CAAC,EAAA,CAAG,UAAW,CAAA,WAAA,EAAa,CAAA;AAAG,IAAG,EAAA,CAAA,SAAA,CAAU,aAAa,CAAA,CAAA;AAE7D,EAAA,MAAM,mBAAmB,OAAQ,CAAA,OAAA,CAAQ,QAAQ,CAC9C,CAAA,OAAA,CAAQ,oBAAoB,iBAAiB,CAAA,CAAA;AAChD,EAAA,IAAI,CAAI,GAAA,CAAA,CAAA;AACR,EAAA,KAAA,MAAW,CAAC,GAAK,EAAA,QAAQ,KAAK,MAAO,CAAA,OAAA,CAAQ,KAAK,CAAG,EAAA;AACnD,IAAM,MAAA,WAAA,GAAc,gBAAiB,CAAA,QAAA,EAAU,GAAG,CAAA,CAAA;AAElD,IAAM,MAAA,kBAAA,GAAqB,SAAS,IAAM,EAAA,OAAA,CAAQ,OAAO,EAAE,CAAA,CAAE,OAAQ,CAAA,KAAA,EAAO,GAAG,CAAA,CAAA;AAC/E,IAAA,MAAM,UAAa,GAAA,WAAA;AAAA,MACjB,CAAG,EAAA,kBAAA,IAAsB,CAAa,UAAA,EAAA,CAAA,EAAG,CAAE,CAAA,CAAA,iBAAA,CAAA;AAAA,KAC7C,CAAA;AACA,IAAA,EAAA,CAAG,aAAc,CAAA,UAAA,EAAY,aAAc,CAAA,WAAW,CAAC,CAAA,CAAA;AACvD,IAAA,IAAI,MAAS,GAAA,EAAA,CAAA;AACb,IAAA,IAAI,cAAgB,EAAA;AAClB,MAAA,MAAA,GAAS,WAAW,cAAc,CAAA,CAAA,CAAA,CAAA;AAAA,KACpC;AAEA,IAAA,YAAA,CAAa,SAAS,CAAG,EAAA,MAAM,GAAG,gBAAgB,CAAA,IAAA,EAAO,UAAU,CAAI,CAAA,EAAA;AAAA,MACrE,GAAK,EAAA,GAAA;AAAA,MAAK,KAAO,EAAA,SAAA;AAAA,KAClB,CAAA,CAAA;AAAA,GACH;AAEA,EAAW,UAAA,EAAA,CAAA;AACb,CAAC,CAAA"}
1
+ {"version":3,"file":"build.esm.js","sources":["../../src/commands/build.ts"],"sourcesContent":["import * as childProcess from 'node:child_process'\nimport fs from 'node:fs'\nimport path from 'node:path'\n\nimport { program } from 'commander'\n\nimport { actionDone, actionRestore } from '../inner'\nimport { mergePackageJson } from '../merge-package-json'\nimport { getSelectedProjectsGraph } from '../utils/filterSupport'\nimport { tsRegisterName } from '../utils/tsRegister'\n\nconst FILE_TEMPLATE = (manifest: unknown) => `\nconst pkg = ${JSON.stringify(manifest, null, 2)}\nconst { jiek = {} } = pkg\nconst templateArg = jiek.templateArgFilePath\n ? require.resolve(jiek.templateArgFilePath)\n : {\n styled: jiek.styled\n }\nmodule.exports = require('jiek/rollup').template(templateArg, pkg)\n`.trimStart()\n\nprogram\n .command('build')\n .action(async () => {\n actionRestore()\n const {\n wd, value = {}\n } = await getSelectedProjectsGraph() ?? {}\n\n if (Object.keys(value).length === 0) {\n throw new Error('no package found')\n }\n const jiekTempDir = (...paths: string[]) => path.resolve(wd, 'node_modules/.jiek', ...paths)\n if (!fs.existsSync(jiekTempDir())) fs.mkdirSync(jiekTempDir())\n\n const rollupBinaryPath = require.resolve('rollup')\n .replace(/dist\\/rollup.js$/, 'dist/bin/rollup')\n let i = 0\n for (const [dir, manifest] of Object.entries(value)) {\n const newManifest = mergePackageJson(manifest, dir, { excludeDistInExports: true })\n // TODO support auto build child packages in workspaces\n const escapeManifestName = manifest.name?.replace(/^@/g, '').replace(/\\//g, '+')\n const configFile = jiekTempDir(\n `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`\n )\n fs.writeFileSync(configFile, FILE_TEMPLATE(newManifest))\n let prefix = ''\n if (tsRegisterName) {\n prefix = `node -r ${tsRegisterName} `\n }\n // TODO replace with `spawn` to support watch mode\n childProcess.execSync(`${prefix}${rollupBinaryPath} --silent -c ${configFile}`, {\n cwd: dir, stdio: 'inherit'\n })\n }\n\n actionDone()\n })\n"],"names":[],"mappings":";;;;;;;;;AAWA,MAAM,aAAA,GAAgB,CAAC,QAAsB,KAAA,CAAA;AAAA,YAAA,EAC/B,IAAK,CAAA,SAAA,CAAU,QAAU,EAAA,IAAA,EAAM,CAAC,CAAC,CAAA;AAAA;AAAA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,EAAA,CAAA,EAAG,CAAE,CAAA,CAAA,iBAAA,CAAA;AAAA,KAC7C,CAAA;AACA,IAAA,EAAA,CAAG,aAAc,CAAA,UAAA,EAAY,aAAc,CAAA,WAAW,CAAC,CAAA,CAAA;AACvD,IAAA,IAAI,MAAS,GAAA,EAAA,CAAA;AACb,IAAA,IAAI,cAAgB,EAAA;AAClB,MAAA,MAAA,GAAS,WAAW,cAAc,CAAA,CAAA,CAAA,CAAA;AAAA,KACpC;AAEA,IAAA,YAAA,CAAa,SAAS,CAAG,EAAA,MAAM,GAAG,gBAAgB,CAAA,aAAA,EAAgB,UAAU,CAAI,CAAA,EAAA;AAAA,MAC9E,GAAK,EAAA,GAAA;AAAA,MAAK,KAAO,EAAA,SAAA;AAAA,KAClB,CAAA,CAAA;AAAA,GACH;AAEA,EAAW,UAAA,EAAA,CAAA;AACb,CAAC,CAAA"}
@@ -1,2 +1,2 @@
1
- import*as e from"node:child_process";import r from"node:fs";import t from"node:path";import{program as o}from"commander";import{actionRestore as n,actionDone as i}from"../inner.esm.min.js";import{mergePackageJson as s}from"../merge-package-json.esm.min.js";import{getSelectedProjectsGraph as m}from"../utils/filterSupport.esm.min.js";import{tsRegisterName as l}from"../utils/tsRegister.esm.min.js";const p=e=>`\nconst pkg = ${JSON.stringify(e,null,2)}\nconst { jiek = {} } = pkg\nconst templateArg = jiek.templateArgFilePath\n ? require.resolve(jiek.templateArgFilePath)\n : {\n styled: jiek.styled\n }\nmodule.exports = require('jiek/rollup').template(templateArg, pkg)\n`.trimStart();o.command("build").action((async()=>{n();const{wd:o,value:c={}}=await m()??{};if(0===Object.keys(c).length)throw new Error("no package found");const a=(...e)=>t.resolve(o,"node_modules/.jiek",...e);r.existsSync(a())||r.mkdirSync(a());const d=require.resolve("rollup").replace(/dist\/rollup.js$/,"dist/bin/rollup");let u=0;for(const[t,o]of Object.entries(c)){const n=s(o,t),i=o.name?.replace(/^@/g,"").replace(/\//g,"+"),m=a(`${i??"anonymous-"+u++}.rollup.config.js`);r.writeFileSync(m,p(n));let c="";l&&(c=`node -r ${l} `),e.execSync(`${c}${d} -c ${m}`,{cwd:t,stdio:"inherit"})}i()}));
1
+ import*as e from"node:child_process";import t from"node:fs";import r from"node:path";import{program as o}from"commander";import{actionRestore as n,actionDone as i}from"../inner.esm.min.js";import{mergePackageJson as s}from"../merge-package-json.esm.min.js";import{getSelectedProjectsGraph as l}from"../utils/filterSupport.esm.min.js";import{tsRegisterName as m}from"../utils/tsRegister.esm.min.js";const p=e=>`\nconst pkg = ${JSON.stringify(e,null,2)}\nconst { jiek = {} } = pkg\nconst templateArg = jiek.templateArgFilePath\n ? require.resolve(jiek.templateArgFilePath)\n : {\n styled: jiek.styled\n }\nmodule.exports = require('jiek/rollup').template(templateArg, pkg)\n`.trimStart();o.command("build").action((async()=>{n();const{wd:o,value:c={}}=await l()??{};if(0===Object.keys(c).length)throw new Error("no package found");const a=(...e)=>r.resolve(o,"node_modules/.jiek",...e);t.existsSync(a())||t.mkdirSync(a());const d=require.resolve("rollup").replace(/dist\/rollup.js$/,"dist/bin/rollup");let u=0;for(const[r,o]of Object.entries(c)){const n=s(o,r,{excludeDistInExports:!0}),i=o.name?.replace(/^@/g,"").replace(/\//g,"+"),l=a(`${i??"anonymous-"+u++}.rollup.config.js`);t.writeFileSync(l,p(n));let c="";m&&(c=`node -r ${m} `),e.execSync(`${c}${d} --silent -c ${l}`,{cwd:r,stdio:"inherit"})}i()}));
2
2
  //# sourceMappingURL=build.esm.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"build.esm.min.js","sources":["../../src/commands/build.ts"],"sourcesContent":["import * as childProcess from 'node:child_process'\nimport fs from 'node:fs'\nimport path from 'node:path'\n\nimport { program } from 'commander'\n\nimport { actionDone, actionRestore } from '../inner'\nimport { mergePackageJson } from '../merge-package-json'\nimport { getSelectedProjectsGraph } from '../utils/filterSupport'\nimport { tsRegisterName } from '../utils/tsRegister'\n\nconst FILE_TEMPLATE = (manifest: unknown) => `\nconst pkg = ${JSON.stringify(manifest, null, 2)}\nconst { jiek = {} } = pkg\nconst templateArg = jiek.templateArgFilePath\n ? require.resolve(jiek.templateArgFilePath)\n : {\n styled: jiek.styled\n }\nmodule.exports = require('jiek/rollup').template(templateArg, pkg)\n`.trimStart()\n\nprogram\n .command('build')\n .action(async () => {\n actionRestore()\n const {\n wd, value = {}\n } = await getSelectedProjectsGraph() ?? {}\n\n if (Object.keys(value).length === 0) {\n throw new Error('no package found')\n }\n const jiekTempDir = (...paths: string[]) => path.resolve(wd, 'node_modules/.jiek', ...paths)\n if (!fs.existsSync(jiekTempDir())) fs.mkdirSync(jiekTempDir())\n\n const rollupBinaryPath = require.resolve('rollup')\n .replace(/dist\\/rollup.js$/, 'dist/bin/rollup')\n let i = 0\n for (const [dir, manifest] of Object.entries(value)) {\n const newManifest = mergePackageJson(manifest, dir)\n // TODO support auto build child packages in workspaces\n const escapeManifestName = manifest.name?.replace(/^@/g, '').replace(/\\//g, '+')\n const configFile = jiekTempDir(\n `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`\n )\n fs.writeFileSync(configFile, FILE_TEMPLATE(newManifest))\n let prefix = ''\n if (tsRegisterName) {\n prefix = `node -r ${tsRegisterName} `\n }\n // TODO replace with `spawn` to support watch mode\n childProcess.execSync(`${prefix}${rollupBinaryPath} -c ${configFile}`, {\n cwd: dir, stdio: 'inherit'\n })\n }\n\n actionDone()\n })\n"],"names":["FILE_TEMPLATE","manifest","JSON","stringify","trimStart","program","command","action","async","actionRestore","wd","value","getSelectedProjectsGraph","Object","keys","length","Error","jiekTempDir","paths","path","resolve","fs","existsSync","mkdirSync","rollupBinaryPath","require","replace","i","dir","entries","newManifest","mergePackageJson","escapeManifestName","name","configFile","writeFileSync","prefix","tsRegisterName","childProcess","execSync","cwd","stdio","actionDone"],"mappings":"8YAWA,MAAMA,EAAiBC,GAAsB,iBAC/BC,KAAKC,UAAUF,EAAU,KAAM,wOAQ3CG,YAEFC,EACGC,QAAQ,SACRC,QAAOC,UACQC,IACR,MAAAC,GACJA,EAAAC,MAAIA,EAAQ,CAAC,SACLC,KAA8B,GAExC,GAAkC,IAA9BC,OAAOC,KAAKH,GAAOI,OACf,MAAA,IAAIC,MAAM,oBAEZ,MAAAC,EAAc,IAAIC,IAAoBC,EAAKC,QAAQV,EAAI,wBAAyBQ,GACjFG,EAAGC,WAAWL,MAAmBI,EAAAE,UAAUN,KAEhD,MAAMO,EAAmBC,QAAQL,QAAQ,UACtCM,QAAQ,mBAAoB,mBAC/B,IAAIC,EAAI,EACR,IAAA,MAAYC,EAAK3B,KAAaY,OAAOgB,QAAQlB,GAAQ,CAC7C,MAAAmB,EAAcC,EAAiB9B,EAAU2B,GAEzCI,EAAqB/B,EAASgC,MAAMP,QAAQ,MAAO,IAAIA,QAAQ,MAAO,KACtEQ,EAAajB,EACjB,GAAGe,GAAsB,aAAaL,wBAExCN,EAAGc,cAAcD,EAAYlC,EAAc8B,IAC3C,IAAIM,EAAS,GACTC,IACFD,EAAS,WAAWC,MAGtBC,EAAaC,SAAS,GAAGH,IAASZ,QAAuBU,IAAc,CACrEM,IAAKZ,EAAKa,MAAO,WAErB,CAEWC,GAAA"}
1
+ {"version":3,"file":"build.esm.min.js","sources":["../../src/commands/build.ts"],"sourcesContent":["import * as childProcess from 'node:child_process'\nimport fs from 'node:fs'\nimport path from 'node:path'\n\nimport { program } from 'commander'\n\nimport { actionDone, actionRestore } from '../inner'\nimport { mergePackageJson } from '../merge-package-json'\nimport { getSelectedProjectsGraph } from '../utils/filterSupport'\nimport { tsRegisterName } from '../utils/tsRegister'\n\nconst FILE_TEMPLATE = (manifest: unknown) => `\nconst pkg = ${JSON.stringify(manifest, null, 2)}\nconst { jiek = {} } = pkg\nconst templateArg = jiek.templateArgFilePath\n ? require.resolve(jiek.templateArgFilePath)\n : {\n styled: jiek.styled\n }\nmodule.exports = require('jiek/rollup').template(templateArg, pkg)\n`.trimStart()\n\nprogram\n .command('build')\n .action(async () => {\n actionRestore()\n const {\n wd, value = {}\n } = await getSelectedProjectsGraph() ?? {}\n\n if (Object.keys(value).length === 0) {\n throw new Error('no package found')\n }\n const jiekTempDir = (...paths: string[]) => path.resolve(wd, 'node_modules/.jiek', ...paths)\n if (!fs.existsSync(jiekTempDir())) fs.mkdirSync(jiekTempDir())\n\n const rollupBinaryPath = require.resolve('rollup')\n .replace(/dist\\/rollup.js$/, 'dist/bin/rollup')\n let i = 0\n for (const [dir, manifest] of Object.entries(value)) {\n const newManifest = mergePackageJson(manifest, dir, { excludeDistInExports: true })\n // TODO support auto build child packages in workspaces\n const escapeManifestName = manifest.name?.replace(/^@/g, '').replace(/\\//g, '+')\n const configFile = jiekTempDir(\n `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`\n )\n fs.writeFileSync(configFile, FILE_TEMPLATE(newManifest))\n let prefix = ''\n if (tsRegisterName) {\n prefix = `node -r ${tsRegisterName} `\n }\n // TODO replace with `spawn` to support watch mode\n childProcess.execSync(`${prefix}${rollupBinaryPath} --silent -c ${configFile}`, {\n cwd: dir, stdio: 'inherit'\n })\n }\n\n actionDone()\n })\n"],"names":["FILE_TEMPLATE","manifest","JSON","stringify","trimStart","program","command","action","async","actionRestore","wd","value","getSelectedProjectsGraph","Object","keys","length","Error","jiekTempDir","paths","path","resolve","fs","existsSync","mkdirSync","rollupBinaryPath","require","replace","i","dir","entries","newManifest","mergePackageJson","excludeDistInExports","escapeManifestName","name","configFile","writeFileSync","prefix","tsRegisterName","childProcess","execSync","cwd","stdio","actionDone"],"mappings":"8YAWA,MAAMA,EAAiBC,GAAsB,iBAC/BC,KAAKC,UAAUF,EAAU,KAAM,wOAQ3CG,YAEFC,EACGC,QAAQ,SACRC,QAAOC,UACQC,IACR,MAAAC,GACJA,EAAAC,MAAIA,EAAQ,CAAC,SACLC,KAA8B,GAExC,GAAkC,IAA9BC,OAAOC,KAAKH,GAAOI,OACf,MAAA,IAAIC,MAAM,oBAEZ,MAAAC,EAAc,IAAIC,IAAoBC,EAAKC,QAAQV,EAAI,wBAAyBQ,GACjFG,EAAGC,WAAWL,MAAmBI,EAAAE,UAAUN,KAEhD,MAAMO,EAAmBC,QAAQL,QAAQ,UACtCM,QAAQ,mBAAoB,mBAC/B,IAAIC,EAAI,EACR,IAAA,MAAYC,EAAK3B,KAAaY,OAAOgB,QAAQlB,GAAQ,CACnD,MAAMmB,EAAcC,EAAiB9B,EAAU2B,EAAK,CAAEI,sBAAsB,IAEtEC,EAAqBhC,EAASiC,MAAMR,QAAQ,MAAO,IAAIA,QAAQ,MAAO,KACtES,EAAalB,EACjB,GAAGgB,GAAsB,aAAaN,wBAExCN,EAAGe,cAAcD,EAAYnC,EAAc8B,IAC3C,IAAIO,EAAS,GACTC,IACFD,EAAS,WAAWC,MAGtBC,EAAaC,SAAS,GAAGH,IAASb,iBAAgCW,IAAc,CAC9EM,IAAKb,EAAKc,MAAO,WAErB,CAEWC,GAAA"}
@@ -2,10 +2,14 @@ import path from 'node:path';
2
2
  import { pkger } from '@jiek/pkger';
3
3
  import { commondir } from './utils/commondir.esm.js';
4
4
 
5
- function mergePackageJson(manifest, cwd) {
5
+ function mergePackageJson(manifest, cwd, options = {}) {
6
+ const {
7
+ excludeDistInExports = false
8
+ } = options;
6
9
  const {
7
10
  jiek: { cwd: _, ...jiek } = {}
8
11
  } = manifest;
12
+ const { outdir = "dist" } = jiek;
9
13
  let { exports } = manifest;
10
14
  let includeIndex = false;
11
15
  if (typeof exports === "string") {
@@ -22,13 +26,16 @@ function mergePackageJson(manifest, cwd) {
22
26
  includeIndex = !!exports["."];
23
27
  }
24
28
  }
25
- const inputs = Array.isArray(exports) ? exports : Object.entries(exports).reduce((acc, [key, value]) => {
29
+ let inputs = Array.isArray(exports) ? exports : Object.entries(exports).reduce((acc, [key, value]) => {
26
30
  if (typeof value === "string")
27
31
  return key === "." ? [value, ...acc] : acc.concat(value);
28
32
  if (Array.isArray(value))
29
33
  return acc.concat(value);
30
34
  throw new TypeError(`Unexpected value type for key "${key}" in exports, expected string, got ${typeof value}`);
31
35
  }, []);
36
+ if (excludeDistInExports) {
37
+ inputs = inputs.filter((input) => !input.startsWith(`./${outdir}`) && !input.startsWith(outdir));
38
+ }
32
39
  if (inputs.length === 0)
33
40
  throw new Error("No inputs found");
34
41
  const absoluteInputs = inputs.map(
@@ -1 +1 @@
1
- {"version":3,"file":"merge-package-json.esm.js","sources":["../src/merge-package-json.ts"],"sourcesContent":["import path from 'node:path'\n\nimport { type Options, pkger } from '@jiek/pkger'\nimport type { Manifest } from '@pnpm/workspace.pkgs-graph'\n\nimport { commondir } from './utils/commondir'\n\nexport function mergePackageJson(manifest: Manifest & {\n jiek?: Options\n exports?: unknown | unknown[]\n}, cwd: string) {\n const {\n jiek: { cwd: _, ...jiek } = {}\n } = manifest\n let { exports } = manifest\n let includeIndex = false\n if (typeof exports === 'string') {\n includeIndex = true\n exports = { '.': exports }\n }\n if (exports === undefined) {\n exports = { '.': './src/index.ts' }\n }\n if (typeof exports === 'object') {\n if (Array.isArray(exports) && exports.length > 0) {\n includeIndex = true\n } else {\n includeIndex = !!(<Record<string, unknown>>exports)['.']\n }\n }\n const inputs = Array.isArray(exports)\n ? exports as string[]\n : Object\n .entries(<Record<string, unknown>>exports)\n .reduce((acc, [key, value]) => {\n if (typeof value === 'string') return key === '.'\n ? [value, ...acc]\n : acc.concat(value)\n if (Array.isArray(value)) return acc.concat(value)\n\n throw new TypeError(`Unexpected value type for key \"${key}\" in exports, expected string, got ${typeof value}`)\n }, [] as string[])\n if (inputs.length === 0)\n throw new Error('No inputs found')\n\n const absoluteInputs = inputs.map(input => path.isAbsolute(input)\n ? input\n : path.resolve(cwd, input)\n )\n let cDir = path.dirname(absoluteInputs[0])\n if (absoluteInputs.length > 1) {\n cDir = commondir(absoluteInputs, cwd)\n }\n const resolvedInputs = absoluteInputs.map(input => {\n return path.relative(cDir, input)\n })\n return {\n ...manifest,\n ...pkger({\n cwd,\n noIndex: !includeIndex,\n source: path.relative(cwd, cDir),\n inputs: resolvedInputs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CAAI,OAAO,KAAK,CAAA,CAAA;AAEjD,IAAA,MAAM,IAAI,SAAU,CAAA,CAAA,+BAAA,EAAkC,GAAG,CAAsC,mCAAA,EAAA,OAAO,KAAK,CAAE,CAAA,CAAA,CAAA;AAAA,GAC/G,EAAG,EAAc,CAAA,CAAA;AACrB,EAAA,IAAI,OAAO,MAAW,KAAA,CAAA;AACpB,IAAM,MAAA,IAAI,MAAM,iBAAiB,CAAA,CAAA;AAEnC,EAAA,MAAM,iBAAiB,MAAO,CAAA,GAAA;AAAA,IAAI,CAAA,KAAA,KAAS,KAAK,UAAW,CAAA,KAAK,IAC5D,KACA,GAAA,IAAA,CAAK,OAAQ,CAAA,GAAA,EAAK,KAAK,CAAA;AAAA,GAC3B,CAAA;AACA,EAAA,IAAI,IAAO,GAAA,IAAA,CAAK,OAAQ,CAAA,cAAA,CAAe,CAAC,CAAC,CAAA,CAAA;AACzC,EAAI,IAAA,cAAA,CAAe,SAAS,CAAG,EAAA;AAC7B,IAAO,IAAA,GAAA,SAAA,CAAU,gBAAgB,GAAG,CAAA,CAAA;AAAA,GACtC;AACA,EAAM,MAAA,cAAA,GAAiB,cAAe,CAAA,GAAA,CAAI,CAAS,KAAA,KAAA;AACjD,IAAO,OAAA,IAAA,CAAK,QAAS,CAAA,IAAA,EAAM,KAAK,CAAA,CAAA;AAAA,GACjC,CAAA,CAAA;AACD,EAAO,OAAA;AAAA,IACL,GAAG,QAAA;AAAA,IACH,GAAG,KAAM,CAAA;AAAA,MACP,GAAA;AAAA,MACA,SAAS,CAAC,YAAA;AAAA,MACV,MAAQ,EAAA,IAAA,CAAK,QAAS,CAAA,GAAA,EAAK,IAAI,CAAA;AAAA,MAC/B,MAAQ,EAAA,cAAA;AAAA,MACR,GAAG,IAAA;AAAA,KACJ,CAAA;AAAA,GACH,CAAA;AACF;;;;"}
1
+ {"version":3,"file":"merge-package-json.esm.js","sources":["../src/merge-package-json.ts"],"sourcesContent":["import path from 'node:path'\n\nimport { type Options, pkger } from '@jiek/pkger'\nimport type { Manifest } from '@pnpm/workspace.pkgs-graph'\n\nimport { commondir } from './utils/commondir'\n\nexport function mergePackageJson(manifest: Manifest & {\n jiek?: Options\n exports?: unknown | unknown[]\n}, cwd: string, options: {\n excludeDistInExports?: boolean\n} = {}) {\n const {\n excludeDistInExports = false\n } = options\n const {\n jiek: { cwd: _, ...jiek } = {}\n } = manifest\n const { outdir = 'dist' } = jiek\n let { exports } = manifest\n let includeIndex = false\n if (typeof exports === 'string') {\n includeIndex = true\n exports = { '.': exports }\n }\n if (exports === undefined) {\n exports = { '.': './src/index.ts' }\n }\n if (typeof exports === 'object') {\n if (Array.isArray(exports) && exports.length > 0) {\n includeIndex = true\n } else {\n includeIndex = !!(<Record<string, unknown>>exports)['.']\n }\n }\n let inputs = Array.isArray(exports)\n ? exports as string[]\n : Object\n .entries(<Record<string, unknown>>exports)\n .reduce((acc, [key, value]) => {\n if (typeof value === 'string') return key === '.'\n ? [value, ...acc]\n : acc.concat(value)\n if (Array.isArray(value)) return acc.concat(value)\n\n throw new TypeError(`Unexpected value type for key \"${key}\" in exports, expected string, got ${typeof value}`)\n }, [] as string[])\n if (excludeDistInExports) {\n inputs = inputs.filter(input => !input.startsWith(`./${outdir}`) && !input.startsWith(outdir))\n }\n if (inputs.length === 0)\n throw new Error('No inputs found')\n\n const absoluteInputs = inputs.map(input => path.isAbsolute(input)\n ? input\n : path.resolve(cwd, input)\n )\n let cDir = path.dirname(absoluteInputs[0])\n if (absoluteInputs.length > 1) {\n cDir = commondir(absoluteInputs, cwd)\n }\n const resolvedInputs = absoluteInputs.map(input => {\n return path.relative(cDir, input)\n })\n return {\n ...manifest,\n ...pkger({\n cwd,\n noIndex: !includeIndex,\n source: path.relative(cwd, cDir),\n inputs: resolvedInputs,\n ...jiek\n })\n }\n}\n"],"names":[],"mappings":";;;;AAOO,SAAS,gBAAiB,CAAA,QAAA,EAG9B,GAAa,EAAA,OAAA,GAEZ,EAAI,EAAA;AACN,EAAM,MAAA;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CAAC,YAAA;AAAA,MACV,MAAQ,EAAA,IAAA,CAAK,QAAS,CAAA,GAAA,EAAK,IAAI,CAAA;AAAA,MAC/B,MAAQ,EAAA,cAAA;AAAA,MACR,GAAG,IAAA;AAAA,KACJ,CAAA;AAAA,GACH,CAAA;AACF;;;;"}
@@ -1,2 +1,2 @@
1
- import e from"node:path";import{pkger as r}from"@jiek/pkger";import{commondir as t}from"./utils/commondir.esm.min.js";function o(o,n){const{jiek:{cwd:i,...s}={}}=o;let{exports:p}=o,c=!1;"string"==typeof p&&(c=!0,p={".":p}),void 0===p&&(p={".":"./src/index.ts"}),"object"==typeof p&&(c=!!(Array.isArray(p)&&p.length>0)||!!p["."]);const a=Array.isArray(p)?p:Object.entries(p).reduce(((e,[r,t])=>{if("string"==typeof t)return"."===r?[t,...e]:e.concat(t);if(Array.isArray(t))return e.concat(t);throw new TypeError(`Unexpected value type for key "${r}" in exports, expected string, got ${typeof t}`)}),[]);if(0===a.length)throw new Error("No inputs found");const f=a.map((r=>e.isAbsolute(r)?r:e.resolve(n,r)));let m=e.dirname(f[0]);f.length>1&&(m=t(f,n));const y=f.map((r=>e.relative(m,r)));return{...o,...r({cwd:n,noIndex:!c,source:e.relative(n,m),inputs:y,...s})}}export{o as mergePackageJson};
1
+ import t from"node:path";import{pkger as r}from"@jiek/pkger";import{commondir as e}from"./utils/commondir.esm.min.js";function o(o,i,n={}){const{excludeDistInExports:s=!1}=n,{jiek:{cwd:p,...c}={}}=o,{outdir:a="dist"}=c;let{exports:d}=o,f=!1;"string"==typeof d&&(f=!0,d={".":d}),void 0===d&&(d={".":"./src/index.ts"}),"object"==typeof d&&(f=!!(Array.isArray(d)&&d.length>0)||!!d["."]);let l=Array.isArray(d)?d:Object.entries(d).reduce(((t,[r,e])=>{if("string"==typeof e)return"."===r?[e,...t]:t.concat(e);if(Array.isArray(e))return t.concat(e);throw new TypeError(`Unexpected value type for key "${r}" in exports, expected string, got ${typeof e}`)}),[]);if(s&&(l=l.filter((t=>!t.startsWith(`./${a}`)&&!t.startsWith(a)))),0===l.length)throw new Error("No inputs found");const u=l.map((r=>t.isAbsolute(r)?r:t.resolve(i,r)));let m=t.dirname(u[0]);u.length>1&&(m=e(u,i));const y=u.map((r=>t.relative(m,r)));return{...o,...r({cwd:i,noIndex:!f,source:t.relative(i,m),inputs:y,...c})}}export{o as mergePackageJson};
2
2
  //# sourceMappingURL=merge-package-json.esm.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"merge-package-json.esm.min.js","sources":["../src/merge-package-json.ts"],"sourcesContent":["import path from 'node:path'\n\nimport { type Options, pkger } from '@jiek/pkger'\nimport type { Manifest } from '@pnpm/workspace.pkgs-graph'\n\nimport { commondir } from './utils/commondir'\n\nexport function mergePackageJson(manifest: Manifest & {\n jiek?: Options\n exports?: unknown | unknown[]\n}, cwd: string) {\n const {\n jiek: { cwd: _, ...jiek } = {}\n } = manifest\n let { exports } = manifest\n let includeIndex = false\n if (typeof exports === 'string') {\n includeIndex = true\n exports = { '.': exports }\n }\n if (exports === undefined) {\n exports = { '.': './src/index.ts' }\n }\n if (typeof exports === 'object') {\n if (Array.isArray(exports) && exports.length > 0) {\n includeIndex = true\n } else {\n includeIndex = !!(<Record<string, unknown>>exports)['.']\n }\n }\n const inputs = Array.isArray(exports)\n ? exports as string[]\n : Object\n .entries(<Record<string, unknown>>exports)\n .reduce((acc, [key, value]) => {\n if (typeof value === 'string') return key === '.'\n ? [value, ...acc]\n : acc.concat(value)\n if (Array.isArray(value)) return acc.concat(value)\n\n throw new TypeError(`Unexpected value type for key \"${key}\" in exports, expected string, got ${typeof value}`)\n }, [] as string[])\n if (inputs.length === 0)\n throw new Error('No inputs found')\n\n const absoluteInputs = inputs.map(input => path.isAbsolute(input)\n ? input\n : path.resolve(cwd, input)\n )\n let cDir = path.dirname(absoluteInputs[0])\n if (absoluteInputs.length > 1) {\n cDir = commondir(absoluteInputs, cwd)\n }\n const resolvedInputs = absoluteInputs.map(input => {\n return path.relative(cDir, input)\n })\n return {\n ...manifest,\n ...pkger({\n cwd,\n noIndex: !includeIndex,\n source: path.relative(cwd, cDir),\n inputs: resolvedInputs,\n ...jiek\n })\n }\n}\n"],"names":["mergePackageJson","manifest","cwd","jiek","_","exports","includeIndex","Array","isArray","length","inputs","Object","entries","reduce","acc","key","value","concat","TypeError","Error","absoluteInputs","map","input","path","isAbsolute","resolve","cDir","dirname","commondir","resolvedInputs","relative","pkger","noIndex","source"],"mappings":"sHAOgB,SAAAA,EAAiBC,EAG9BC,GACK,MACJC,MAAQD,IAAKE,KAAMD,GAAS,CAAC,GAC3BF,EACA,IAAAI,QAAEA,GAAYJ,EACdK,GAAe,EACI,iBAAZD,IACMC,GAAA,EACLD,EAAA,CAAE,IAAKA,SAEH,IAAZA,IACQA,EAAA,CAAE,IAAK,mBAEI,iBAAZA,IAEQC,KADbC,MAAMC,QAAQH,IAAYA,EAAQI,OAAS,MAGFJ,EAAS,MAGxD,MAAMK,EAASH,MAAMC,QAAQH,GACzBA,EACAM,OACCC,QAAiCP,GACjCQ,QAAO,CAACC,GAAMC,EAAKC,MAClB,GAAqB,iBAAVA,EAA2B,MAAQ,MAARD,EAClC,CAACC,KAAUF,GACXA,EAAIG,OAAOD,GACX,GAAAT,MAAMC,QAAQQ,GAAe,OAAAF,EAAIG,OAAOD,GAE5C,MAAM,IAAIE,UAAU,kCAAkCH,8CAAgDC,IAAO,GAC5G,IACP,GAAsB,IAAlBN,EAAOD,OACH,MAAA,IAAIU,MAAM,mBAElB,MAAMC,EAAiBV,EAAOW,KAAIC,GAASC,EAAKC,WAAWF,GACvDA,EACAC,EAAKE,QAAQvB,EAAKoB,KAEtB,IAAII,EAAOH,EAAKI,QAAQP,EAAe,IACnCA,EAAeX,OAAS,IACnBiB,EAAAE,EAAUR,EAAgBlB,IAE7B,MAAA2B,EAAiBT,EAAeC,KAAaC,GAC1CC,EAAKO,SAASJ,EAAMJ,KAEtB,MAAA,IACFrB,KACA8B,EAAM,CACP7B,MACA8B,SAAU1B,EACV2B,OAAQV,EAAKO,SAAS5B,EAAKwB,GAC3BhB,OAAQmB,KACL1B,IAGT"}
1
+ {"version":3,"file":"merge-package-json.esm.min.js","sources":["../src/merge-package-json.ts"],"sourcesContent":["import path from 'node:path'\n\nimport { type Options, pkger } from '@jiek/pkger'\nimport type { Manifest } from '@pnpm/workspace.pkgs-graph'\n\nimport { commondir } from './utils/commondir'\n\nexport function mergePackageJson(manifest: Manifest & {\n jiek?: Options\n exports?: unknown | unknown[]\n}, cwd: string, options: {\n excludeDistInExports?: boolean\n} = {}) {\n const {\n excludeDistInExports = false\n } = options\n const {\n jiek: { cwd: _, ...jiek } = {}\n } = manifest\n const { outdir = 'dist' } = jiek\n let { exports } = manifest\n let includeIndex = false\n if (typeof exports === 'string') {\n includeIndex = true\n exports = { '.': exports }\n }\n if (exports === undefined) {\n exports = { '.': './src/index.ts' }\n }\n if (typeof exports === 'object') {\n if (Array.isArray(exports) && exports.length > 0) {\n includeIndex = true\n } else {\n includeIndex = !!(<Record<string, unknown>>exports)['.']\n }\n }\n let inputs = Array.isArray(exports)\n ? exports as string[]\n : Object\n .entries(<Record<string, unknown>>exports)\n .reduce((acc, [key, value]) => {\n if (typeof value === 'string') return key === '.'\n ? [value, ...acc]\n : acc.concat(value)\n if (Array.isArray(value)) return acc.concat(value)\n\n throw new TypeError(`Unexpected value type for key \"${key}\" in exports, expected string, got ${typeof value}`)\n }, [] as string[])\n if (excludeDistInExports) {\n inputs = inputs.filter(input => !input.startsWith(`./${outdir}`) && !input.startsWith(outdir))\n }\n if (inputs.length === 0)\n throw new Error('No inputs found')\n\n const absoluteInputs = inputs.map(input => path.isAbsolute(input)\n ? input\n : path.resolve(cwd, input)\n )\n let cDir = path.dirname(absoluteInputs[0])\n if (absoluteInputs.length > 1) {\n cDir = commondir(absoluteInputs, cwd)\n }\n const resolvedInputs = absoluteInputs.map(input => {\n return path.relative(cDir, input)\n })\n return {\n ...manifest,\n ...pkger({\n cwd,\n noIndex: !includeIndex,\n source: path.relative(cwd, cDir),\n inputs: resolvedInputs,\n ...jiek\n })\n }\n}\n"],"names":["mergePackageJson","manifest","cwd","options","excludeDistInExports","jiek","_","outdir","exports","includeIndex","Array","isArray","length","inputs","Object","entries","reduce","acc","key","value","concat","TypeError","filter","input","startsWith","Error","absoluteInputs","map","path","isAbsolute","resolve","cDir","dirname","commondir","resolvedInputs","relative","pkger","noIndex","source"],"mappings":"sHAOO,SAASA,EAAiBC,EAG9BC,EAAaC,EAEZ,CAAA,GACI,MAAAC,qBACJA,GAAuB,GACrBD,GAEFE,MAAQH,IAAKI,KAAMD,GAAS,CAAC,GAC3BJ,GACEM,OAAEA,EAAS,QAAWF,EACxB,IAAAG,QAAEA,GAAYP,EACdQ,GAAe,EACI,iBAAZD,IACMC,GAAA,EACLD,EAAA,CAAE,IAAKA,SAEH,IAAZA,IACQA,EAAA,CAAE,IAAK,mBAEI,iBAAZA,IAEQC,KADbC,MAAMC,QAAQH,IAAYA,EAAQI,OAAS,MAGFJ,EAAS,MAGxD,IAAIK,EAASH,MAAMC,QAAQH,GACvBA,EACAM,OACCC,QAAiCP,GACjCQ,QAAO,CAACC,GAAMC,EAAKC,MAClB,GAAqB,iBAAVA,EAA2B,MAAQ,MAARD,EAClC,CAACC,KAAUF,GACXA,EAAIG,OAAOD,GACX,GAAAT,MAAMC,QAAQQ,GAAe,OAAAF,EAAIG,OAAOD,GAE5C,MAAM,IAAIE,UAAU,kCAAkCH,8CAAgDC,IAAO,GAC5G,IAIP,GAHIf,IACFS,EAASA,EAAOS,QAAgBC,IAACA,EAAMC,WAAW,KAAKjB,OAAcgB,EAAMC,WAAWjB,MAElE,IAAlBM,EAAOD,OACH,MAAA,IAAIa,MAAM,mBAElB,MAAMC,EAAiBb,EAAOc,KAAIJ,GAASK,EAAKC,WAAWN,GACvDA,EACAK,EAAKE,QAAQ5B,EAAKqB,KAEtB,IAAIQ,EAAOH,EAAKI,QAAQN,EAAe,IACnCA,EAAed,OAAS,IACnBmB,EAAAE,EAAUP,EAAgBxB,IAE7B,MAAAgC,EAAiBR,EAAeC,KAAaJ,GAC1CK,EAAKO,SAASJ,EAAMR,KAEtB,MAAA,IACFtB,KACAmC,EAAM,CACPlC,MACAmC,SAAU5B,EACV6B,OAAQV,EAAKO,SAASjC,EAAK6B,GAC3BlB,OAAQqB,KACL7B,IAGT"}
@@ -1,6 +1,5 @@
1
1
  const defineOutput = (output) => output;
2
2
  const commonOutputOptions = defineOutput({
3
- dir: "dist",
4
3
  exports: "named",
5
4
  interop: "auto",
6
5
  sourcemap: true
@@ -1 +1 @@
1
- {"version":3,"file":"commonOptions.esm.js","sources":["../../../src/rollup/utils/commonOptions.ts"],"sourcesContent":["import type { OutputOptions } from 'rollup'\n\nconst defineOutput = <O extends OutputOptions>(output: O) => output\n\nexport const commonOutputOptions = defineOutput({\n dir: 'dist',\n exports: 'named',\n interop: 'auto',\n sourcemap: true\n})\n"],"names":[],"mappings":"AAEA,MAAM,YAAA,GAAe,CAA0B,MAAc,KAAA,MAAA,CAAA;AAEtD,MAAM,sBAAsB,YAAa,CAAA;AAAA,EAC9C,GAAK,EAAA,MAAA;AAAA,EACL,OAAS,EAAA,OAAA;AAAA,EACT,OAAS,EAAA,MAAA;AAAA,EACT,SAAW,EAAA,IAAA;AACb,CAAC;;;;"}
1
+ {"version":3,"file":"commonOptions.esm.js","sources":["../../../src/rollup/utils/commonOptions.ts"],"sourcesContent":["import type { OutputOptions } from 'rollup'\n\nconst defineOutput = <O extends OutputOptions>(output: O) => output\n\nexport const commonOutputOptions = defineOutput({\n exports: 'named',\n interop: 'auto',\n sourcemap: true\n})\n"],"names":[],"mappings":"AAEA,MAAM,YAAA,GAAe,CAA0B,MAAc,KAAA,MAAA,CAAA;AAEtD,MAAM,sBAAsB,YAAa,CAAA;AAAA,EAC9C,OAAS,EAAA,OAAA;AAAA,EACT,OAAS,EAAA,MAAA;AAAA,EACT,SAAW,EAAA,IAAA;AACb,CAAC;;;;"}
@@ -1,2 +1,2 @@
1
- const o={dir:"dist",exports:"named",interop:"auto",sourcemap:!0};export{o as commonOutputOptions};
1
+ const o={exports:"named",interop:"auto",sourcemap:!0};export{o as commonOutputOptions};
2
2
  //# sourceMappingURL=commonOptions.esm.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"commonOptions.esm.min.js","sources":["../../../src/rollup/utils/commonOptions.ts"],"sourcesContent":["import type { OutputOptions } from 'rollup'\n\nconst defineOutput = <O extends OutputOptions>(output: O) => output\n\nexport const commonOutputOptions = defineOutput({\n dir: 'dist',\n exports: 'named',\n interop: 'auto',\n sourcemap: true\n})\n"],"names":["commonOutputOptions","dir","exports","interop","sourcemap"],"mappings":"AAEA,MAEaA,EAAmC,CAC9CC,IAAK,OACLC,QAAS,QACTC,QAAS,OACTC,WAAW"}
1
+ {"version":3,"file":"commonOptions.esm.min.js","sources":["../../../src/rollup/utils/commonOptions.ts"],"sourcesContent":["import type { OutputOptions } from 'rollup'\n\nconst defineOutput = <O extends OutputOptions>(output: O) => output\n\nexport const commonOutputOptions = defineOutput({\n exports: 'named',\n interop: 'auto',\n sourcemap: true\n})\n"],"names":["commonOutputOptions","exports","interop","sourcemap"],"mappings":"AAEA,MAEaA,EAAmC,CAC9CC,QAAS,QACTC,QAAS,OACTC,WAAW"}
package/dist/rollup.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("node:path"),t=require("@jiek/utils/getWorkspaceDir"),r=require("@rollup/plugin-json"),s=require("autoprefixer"),n=require("rollup-plugin-dts"),i=require("rollup-plugin-esbuild"),o=require("rollup-plugin-postcss"),a=require("@rollup/plugin-terser");function l(e){return e&&e.__esModule?e:{default:e}}var u=l(r),p=l(s),c=l(i),d=l(o),m=l(a);function f(e){return e.startsWith("node:")?e.slice(5):e.replace(/[@|/-](\w)/g,((e,t)=>t.toUpperCase()))}var g=(e={})=>({name:"skip",load(t){if(e.patterns?.some((e=>"string"==typeof e?t.includes(e):e.test(t))))return""}});const j={dir:"dist",exports:"named",interop:"auto",sourcemap:!0};function x(e){return[e,{...e,entryFileNames:e.entryFileNames?.replace(/(\.js)$/,".min$1"),plugins:[...e.plugins??[],m.default()]}]}const y=t.getWorkspaceDir();exports.template=({styled:t=!1,plugins:{index:r=[],entry:s=[],dts:i=[]}={}}={},o)=>{const{jiek:{noBrowser:a=!1}={}}=o;if(!o.name)throw new Error("pkg.name is required");const l=o.name.replace(/[@|/-](\w)/g,((e,t)=>t.toUpperCase())),m=Object.fromEntries(Object.entries(o.exports??{}).filter((([e])=>!/\.(json|css|scss)$/.test(e))).filter((([,e])=>"object"==typeof e&&e["inner-src"]&&e.import)).map((([e,t])=>[e.replace(/^\.$/,"index").replace(/^\.\//,""),"string"==typeof t?t:t["inner-src"]]))),[$,b]=function(){let e={};const t=new Set([]);return[({external:r}={})=>({name:"globals",resolveId:e=>r?.some((t=>t instanceof RegExp?t.test(e):t===e))?(t.add(e),{id:e,external:!0}):null,outputOptions:r=>(e=[...t].reduce(((e,t)=>({...e,[t]:f(t)})),{}),{...r,globals:e})}),{outputOptions:t=>({...t,globals:e})}]}(),k=function(){const e=process.cwd(),t=require(`${e}/package.json`),{dependencies:r={},peerDependencies:s={},optionalDependencies:n={}}=t;return Object.keys(r).concat(Object.keys(s)).concat(Object.keys(n)).map((e=>new RegExp(`^${e}(/.*)?$`))).concat([/^node:/])}(),q=[u.default()];return[{input:m,output:[...x({...j,format:"esm",entryFileNames:"[name].esm.js",preserveModules:!0})],plugins:[q,$({external:k}),t&&g({patterns:[/\.s?css$/]}),c.default(),r]},...Object.entries(m).map((([e,r])=>{const n=l+("index"===e?"":e.replace(/[@|/-](\w)/g,((e,t)=>t.toUpperCase())));return{input:r,output:a?[...x({...j,name:n,format:"cjs",entryFileNames:`${e}.cjs`})]:[...x({...j,name:n,format:"iife",entryFileNames:`${e}.iife.js`}),...x({...j,name:n,format:"umd",entryFileNames:`${e}.umd.js`})],plugins:[q,b,t&&d.default({plugins:[p.default],minimize:!0,sourceMap:!0,extract:`${e}.css`}),c.default(),s],external:k}})),{input:m,output:[{dir:"dist",entryFileNames:({name:e})=>`${e.replace(/^src\//,"")}.esm.d.ts`,preserveModules:!0},{dir:"dist"}],plugins:[q,t&&g({patterns:[/\.s?css$/]}),n.dts({tsconfig:(v="tsconfig.dts.json",e.resolve(y,v))}),{name:"rollup-plugin-declare-module-replacer",generateBundle(e,t){for(const e of Object.values(t))"code"in e&&(e.code=e.code.replace(/declare module ['|"]\..*['|"]/g,`declare module '${o.name}'`))}},i],external:k}];var v};
1
+ "use strict";var e=require("node:path"),t=require("@jiek/utils/getWorkspaceDir"),s=require("@rollup/plugin-json"),r=require("autoprefixer"),n=require("rollup-plugin-dts"),a=require("rollup-plugin-esbuild"),i=require("rollup-plugin-postcss"),u=require("cli-progress"),o=require("@rollup/plugin-terser");function p(e){return e&&e.__esModule?e:{default:e}}var d=p(s),c=p(r),l=p(a),m=p(i),g=p(o);function y(e){return e.startsWith("node:")?e.slice(5):e.replace(/[@|/-](\w)/g,((e,t)=>t.toUpperCase()))}var f=(e={})=>({name:"skip",load(t){if(e.patterns?.some((e=>"string"==typeof e?t.includes(e):e.test(t))))return""}});const j={exports:"named",interop:"auto",sourcemap:!0};function $(e){return[e,{...e,entryFileNames:e.entryFileNames?.replace(/(\.js)$/,".min$1"),plugins:[...e.plugins??[],g.default()]}]}const b=t.getWorkspaceDir();function v(e,t,s,r){return{name:"progress",resolveId(s,r){(e.includes(s)||void 0===r)&&t(s)},transform(e,t){s(t)},writeBundle(e,t){Object.entries(t).forEach((([e,t])=>{void 0!==t.name&&"isEntry"in t&&r(t.name,t.fileName)}))}}}exports.template=({styled:t=!1,plugins:{index:s=[],entry:r=[],dts:a=[]}={}}={},i)=>{const{jiek:{noBrowser:o=!1,outdir:p="dist"}={}}=i,g={...j,dir:p};if(!i.name)throw new Error("pkg.name is required");const x=i.name.replace(/[@|/-](\w)/g,((e,t)=>t.toUpperCase())),O=Object.fromEntries(Object.entries(i.exports??{}).filter((([e])=>!e.startsWith(`./${p}`)&&!e.startsWith(p))).filter((([e])=>!/\.(json|css|scss)$/.test(e))).filter((([,e])=>"object"==typeof e&&e["inner-src"]&&e.import)).map((([e,t])=>[e.replace(/^\.$/,"index").replace(/^\.\//,""),"string"==typeof t?t:t["inner-src"]]))),[h,w]=function(){let e={};const t=new Set([]);return[({external:s}={})=>({name:"globals",resolveId:e=>s?.some((t=>t instanceof RegExp?t.test(e):t===e))?(t.add(e),{id:e,external:!0}):null,outputOptions:s=>(e=[...t].reduce(((e,t)=>({...e,[t]:y(t)})),{}),{...s,globals:e})}),{outputOptions:t=>({...t,globals:e})}]}(),q=function(){const e=process.cwd(),t=require(`${e}/package.json`),{dependencies:s={},peerDependencies:r={},optionalDependencies:n={}}=t;return Object.keys(s).concat(Object.keys(r)).concat(Object.keys(n)).map((e=>new RegExp(`^${e}(/.*)?$`))).concat([/^node:/])}(),k={},N=[d.default()],W=new u.MultiBar({clearOnComplete:!1,hideCursor:!0,format:"- {bar} | {type} | {entry} | {message}"},u.Presets.shades_classic),F=Object.values(O),E={esm:F.reduce(((e,t)=>{const s=W.create(100,0);return s.update(0,{type:"esm",entry:t,message:"waiting"}),{...e,[t]:s}}),{}),umd:F.reduce(((e,t)=>{const s=W.create(100,0);return s.update(0,{type:"umd",entry:t,message:"waiting"}),{...e,[t]:s}}),{}),dts:F.reduce(((e,t)=>{const s=W.create(100,0);return s.update(0,{type:"dts",entry:t,message:"waiting"}),{...e,[t]:s}}),{})},B=F.reduce(((e,t)=>({...e,[t]:!1})),{});return[{...k,input:O,output:[...$({...g,format:"esm",entryFileNames:"[name].esm.js",preserveModules:!0})],plugins:[v(Object.values(O),(e=>{const t=E.esm[e];t&&t.update(0,{type:"esm",entry:e,message:"processing"})}),(e=>{const t=E.esm[e];t&&t.update(50,{type:"esm",entry:e,message:`transforming ${e}`})}),((e,t)=>{const s=O[e],r=E.esm[s];r&&(t.endsWith(".min.js")?r.update(100,{type:"esm",entry:s,message:"finished"}):r.update(95,{type:"esm",entry:s,message:"processed"}))})),N,h({external:q}),t&&f({patterns:[/\.s?css$/]}),l.default(),s]},...Object.entries(O).map((([e,s])=>{const n=x+("index"===e?"":e.replace(/[@|/-](\w)/g,((e,t)=>t.toUpperCase())));return{...k,input:s,output:o?[...$({...g,name:n,format:"cjs",entryFileNames:`${e}.cjs`})]:[...$({...g,name:n,format:"iife",entryFileNames:`${e}.iife.js`}),...$({...g,name:n,format:"umd",entryFileNames:`${e}.umd.js`})],plugins:[v([s],(e=>{const t=E.umd[e];t&&t.update(0,{type:"umd",entry:e,message:"processing"})}),(e=>{const t=E.umd[s];t&&t.update(50,{type:"umd",input:s,message:`transforming ${e}`})}),((e,t)=>{const r=E.umd[s];r&&(t.endsWith(".min.js")?r.update(100,{type:"umd",input:s,message:"finished"}):r.update(95,{type:"umd",input:s,message:"processed"}))})),N,w,t&&m.default({plugins:[c.default],minimize:!0,sourceMap:!0,extract:`${e}.css`}),l.default(),r],external:q}})),{...k,input:O,output:[{dir:"dist"},{dir:"dist",entryFileNames:({name:e})=>`${e.replace(/^src\//,"")}.esm.d.ts`,preserveModules:!0}],plugins:[v(Object.values(O),(e=>{const t=E.dts[e];t&&t.update(0,{type:"dts",entry:e,message:"processing"})}),(e=>{const t=E.dts[e];t&&t.update(50,{type:"dts",entry:e,message:`transforming ${e}`})}),((e,t)=>{const s=O[e],r=E.dts[s];r&&(t.endsWith(".esm.d.ts")?(r.update(100,{type:"dts",entry:s,message:"finished"}),B[s]=!0):r.update(95,{type:"dts",entry:s,message:"processed"}),Object.values(B).every(Boolean)&&setTimeout((()=>{W.stop()}),100))})),N,t&&f({patterns:[/\.s?css$/]}),n.dts({tsconfig:(C="tsconfig.dts.json",e.resolve(b,C))}),{name:"rollup-plugin-declare-module-replacer",generateBundle(e,t){for(const e of Object.values(t))"code"in e&&(e.code=e.code.replace(/declare module ['|"]\..*['|"]/g,`declare module '${i.name}'`))}},a],external:q}];var C};
2
2
  //# sourceMappingURL=rollup.cjs.map