jiek 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cli.cjs +1 -1
- package/dist/cli.d.cts +17 -1
- package/dist/cli.d.ts +17 -1
- package/dist/cli.js +1 -1
- package/dist/cli.min.cjs +1 -1
- package/dist/cli.min.js +1 -1
- package/dist/rollup/index.cjs +115 -87
- package/dist/rollup/index.d.cts +17 -1
- package/dist/rollup/index.d.ts +17 -1
- package/dist/rollup/index.js +113 -85
- package/dist/rollup/index.min.cjs +3 -3
- package/dist/rollup/index.min.js +2 -2
- package/package.json +3 -3
- package/src/rollup/base.ts +22 -1
- package/src/rollup/index.ts +48 -110
- package/src/rollup/plugins/skip.ts +13 -15
- package/src/utils/ts.ts +94 -0
package/dist/cli.cjs
CHANGED
package/dist/cli.d.cts
CHANGED
@@ -1,9 +1,18 @@
|
|
1
|
-
import { OutputOptions } from 'rollup';
|
1
|
+
import { InputPluginOption, OutputOptions } from 'rollup';
|
2
2
|
|
3
3
|
type Mapping2ROO<K extends keyof OutputOptions> = OutputOptions[K] | {
|
4
4
|
js?: OutputOptions[K];
|
5
5
|
dts?: OutputOptions[K];
|
6
6
|
};
|
7
|
+
interface ConfigGenerateContext {
|
8
|
+
path: string;
|
9
|
+
name: string;
|
10
|
+
input: string;
|
11
|
+
output: string;
|
12
|
+
external: (string | RegExp)[];
|
13
|
+
pkgIsModule: boolean;
|
14
|
+
conditionals: string[];
|
15
|
+
}
|
7
16
|
interface TemplateOptions {
|
8
17
|
/**
|
9
18
|
* When the user configures type: module, the generated output from entry points that don't
|
@@ -29,6 +38,13 @@ interface TemplateOptions {
|
|
29
38
|
sourcemap?: Mapping2ROO<'sourcemap'>;
|
30
39
|
strict?: Mapping2ROO<'strict'>;
|
31
40
|
};
|
41
|
+
plugins?: InputPluginOption | ((type: 'js' | 'dts', context: ConfigGenerateContext) => InputPluginOption) | {
|
42
|
+
js: InputPluginOption;
|
43
|
+
dts?: InputPluginOption;
|
44
|
+
} | {
|
45
|
+
js?: InputPluginOption;
|
46
|
+
dts: InputPluginOption;
|
47
|
+
};
|
32
48
|
}
|
33
49
|
declare module 'jiek' {
|
34
50
|
interface Config {
|
package/dist/cli.d.ts
CHANGED
@@ -1,9 +1,18 @@
|
|
1
|
-
import { OutputOptions } from 'rollup';
|
1
|
+
import { InputPluginOption, OutputOptions } from 'rollup';
|
2
2
|
|
3
3
|
type Mapping2ROO<K extends keyof OutputOptions> = OutputOptions[K] | {
|
4
4
|
js?: OutputOptions[K];
|
5
5
|
dts?: OutputOptions[K];
|
6
6
|
};
|
7
|
+
interface ConfigGenerateContext {
|
8
|
+
path: string;
|
9
|
+
name: string;
|
10
|
+
input: string;
|
11
|
+
output: string;
|
12
|
+
external: (string | RegExp)[];
|
13
|
+
pkgIsModule: boolean;
|
14
|
+
conditionals: string[];
|
15
|
+
}
|
7
16
|
interface TemplateOptions {
|
8
17
|
/**
|
9
18
|
* When the user configures type: module, the generated output from entry points that don't
|
@@ -29,6 +38,13 @@ interface TemplateOptions {
|
|
29
38
|
sourcemap?: Mapping2ROO<'sourcemap'>;
|
30
39
|
strict?: Mapping2ROO<'strict'>;
|
31
40
|
};
|
41
|
+
plugins?: InputPluginOption | ((type: 'js' | 'dts', context: ConfigGenerateContext) => InputPluginOption) | {
|
42
|
+
js: InputPluginOption;
|
43
|
+
dts?: InputPluginOption;
|
44
|
+
} | {
|
45
|
+
js?: InputPluginOption;
|
46
|
+
dts: InputPluginOption;
|
47
|
+
};
|
32
48
|
}
|
33
49
|
declare module 'jiek' {
|
34
50
|
interface Config {
|
package/dist/cli.js
CHANGED
package/dist/cli.min.cjs
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
"use strict";var e=require("node:fs"),t=require("node:module"),n=require("node:path"),r=require("@pnpm/filter-workspace-packages"),o=require("commander"),a=require("js-yaml"),s=require("@jiek/utils/getWorkspaceDir"),i=require("cli-progress"),u=require("execa"),l=require("detect-indent"),p=require("inquirer"),c=require("jsonc-parser"),f=require("util"),d=require("path"),g=require("node:child_process"),h=require("@jiek/utils/bumper"),y=require("@jiek/pkger/entrypoints"),A="undefined"!=typeof document?document.currentScript:null;function R(e){return e&&e.__esModule?e:{default:e}}function m(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var E=R(e),_=R(n),b=R(l),S=R(p),C=R(f),v=R(d),$=m(g);let x,w;function H(){if(x)return x;const e=o.program.getOptionValue("root");return x=e?_.default.isAbsolute(e)?e:_.default.resolve(process.cwd(),e):void 0,x}let k=!1;function O(){if(w)return{wd:w,notWorkspace:k};const e=H();if(void 0!==e){const t=s.isWorkspaceDir(e,T);return k=!t,w=e,{wd:w,notWorkspace:k}}try{w=s.getWorkspaceDir(T)}catch(t){if(!("message"in t)||"workspace root not found"!==t.message)throw t;w=e,k=!0}return{wd:w,notWorkspace:k}}let T="";try{t.createRequire("undefined"==typeof document?require("url").pathToFileURL(__filename).href:A&&A.src||new URL("cli.min.cjs",document.baseURI).href).resolve("@pnpm/filter-workspace-packages"),T="pnpm"}catch{}async function L(){let e=o.program.getOptionValue("filter");const t=H(),{wd:n,notWorkspace:s}=O();if(!s&&"pnpm"===T){const o=_.default.resolve(n,"pnpm-workspace.yaml"),s=E.default.readFileSync(o,"utf-8"),i=a.load(s);if(t===n&&!e)throw new Error("root path is workspace root, please provide a filter");if(t!==n&&!e){if(!E.default.existsSync(_.default.resolve(t,"package.json")))throw new Error("root path is not workspace root, please provide a filter");const n=JSON.parse(E.default.readFileSync(_.default.resolve(t,"package.json"),"utf-8"));if(!n.name)throw new Error("root path is not workspace root, please provide a filter");e=n.name}const{selectedProjectsGraph:u}=await r.filterPackagesFromDir(n,[{filter:e??"",followProdDepsOnly:!0}],{prefix:t,workspaceDir:n,patterns:i.packages});return{wd:n,root:t,value:Object.entries(u).reduce(((e,[t,n])=>(e[t]=n.package.manifest,e)),{})}}return{wd:n,root:t,value:{[n]:JSON.parse(E.default.readFileSync(_.default.resolve(n,"package.json"),"utf-8"))}}}""!==T&&o.program.option("-f, --filter <filter>","filter packages");var N="1.0.
|
1
|
+
"use strict";var e=require("node:fs"),t=require("node:module"),n=require("node:path"),r=require("@pnpm/filter-workspace-packages"),o=require("commander"),a=require("js-yaml"),s=require("@jiek/utils/getWorkspaceDir"),i=require("cli-progress"),u=require("execa"),l=require("detect-indent"),p=require("inquirer"),c=require("jsonc-parser"),f=require("util"),d=require("path"),g=require("node:child_process"),h=require("@jiek/utils/bumper"),y=require("@jiek/pkger/entrypoints"),A="undefined"!=typeof document?document.currentScript:null;function R(e){return e&&e.__esModule?e:{default:e}}function m(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var E=R(e),_=R(n),b=R(l),S=R(p),C=R(f),v=R(d),$=m(g);let x,w;function H(){if(x)return x;const e=o.program.getOptionValue("root");return x=e?_.default.isAbsolute(e)?e:_.default.resolve(process.cwd(),e):void 0,x}let k=!1;function O(){if(w)return{wd:w,notWorkspace:k};const e=H();if(void 0!==e){const t=s.isWorkspaceDir(e,T);return k=!t,w=e,{wd:w,notWorkspace:k}}try{w=s.getWorkspaceDir(T)}catch(t){if(!("message"in t)||"workspace root not found"!==t.message)throw t;w=e,k=!0}return{wd:w,notWorkspace:k}}let T="";try{t.createRequire("undefined"==typeof document?require("url").pathToFileURL(__filename).href:A&&A.src||new URL("cli.min.cjs",document.baseURI).href).resolve("@pnpm/filter-workspace-packages"),T="pnpm"}catch{}async function L(){let e=o.program.getOptionValue("filter");const t=H(),{wd:n,notWorkspace:s}=O();if(!s&&"pnpm"===T){const o=_.default.resolve(n,"pnpm-workspace.yaml"),s=E.default.readFileSync(o,"utf-8"),i=a.load(s);if(t===n&&!e)throw new Error("root path is workspace root, please provide a filter");if(t!==n&&!e){if(!E.default.existsSync(_.default.resolve(t,"package.json")))throw new Error("root path is not workspace root, please provide a filter");const n=JSON.parse(E.default.readFileSync(_.default.resolve(t,"package.json"),"utf-8"));if(!n.name)throw new Error("root path is not workspace root, please provide a filter");e=n.name}const{selectedProjectsGraph:u}=await r.filterPackagesFromDir(n,[{filter:e??"",followProdDepsOnly:!0}],{prefix:t,workspaceDir:n,patterns:i.packages});return{wd:n,root:t,value:Object.entries(u).reduce(((e,[t,n])=>(e[t]=n.package.manifest,e)),{})}}return{wd:n,root:t,value:{[n]:JSON.parse(E.default.readFileSync(_.default.resolve(n,"package.json"),"utf-8"))}}}""!==T&&o.program.option("-f, --filter <filter>","filter packages");var N="1.0.3",I="YiJie's personal kits.";let M;function j(){M()}function P(){new Promise((e=>M=e))}o.program.version(N).description(I).option("--root <root>","root path").option("-c, --config-path <configPath>","config path");const B=t.createRequire("undefined"==typeof document?require("url").pathToFileURL(__filename).href:A&&A.src||new URL("cli.min.cjs",document.baseURI).href);function D(e){try{return B.resolve(e),!0}catch(e){return!1}}let U;const G=[process.env.JIEK_TS_REGISTER,"esbuild-register","@swc-node/register","ts-node/register"].filter(Boolean);for(const e of G)if(D(e)){U=e;break}let F="jiek.config";function K(e){const{wd:t}=O();let n=o.program.getOptionValue("configPath");if(n){if(!E.default.existsSync(n))throw new Error(`config file not found: ${n}`);_.default.isAbsolute(n)||(n=_.default.resolve(t,n))}else n=function(e,t){const n=!!U;function r(n){const r=[_.default.resolve(process.cwd(),`${F}.${n}`),_.default.resolve(process.cwd(),`.${F}.${n}`),_.default.resolve(e,`${F}.${n}`),_.default.resolve(e,`.${F}.${n}`)];t&&r.unshift(_.default.resolve(t,`${F}.${n}`),_.default.resolve(t,`.${F}.${n}`));for(const e of r)if(E.default.existsSync(e)&&E.default.lstatSync(e).isFile())return e}return F=r("js")??F,F=r("json")??F,F=r("yaml")??F,n&&(F=r("ts")??F),_.default.resolve(e,F)}(t,e);const r=_.default.extname(n);let s;switch(r){case".js":s=require(n);break;case".json":return require(n);case".yaml":return a.load(E.default.readFileSync(n,"utf-8"));case".ts":if(U){require(U),s=require(n);break}throw new Error("ts config file is not supported without ts register, please install esbuild-register or set JIEK_TS_REGISTER env for custom ts register");case".config":s={};break;default:throw new Error(`unsupported config file type: ${r}`)}if(!s)throw new Error("config file is empty");return s.default??s}const q=t.createRequire("undefined"==typeof document?require("url").pathToFileURL(__filename).href:A&&A.src||new URL("cli.min.cjs",document.baseURI).href);o.program.command("build").option("-s, --silent","Don't display logs.").option("-e, --entries <ENTRIES>","Specify the entries of the package.json's 'exports' field.(support glob)").action((async({silent:e,entries:t})=>{P();const{build:n}=K();e=e??n?.silent??!1;const{wd:r,value:o={}}=await L()??{};if(0===Object.keys(o).length)throw new Error("no package found");const a=_.default.resolve(r,"node_modules");E.default.existsSync(a)||E.default.mkdirSync(a);const s=(...e)=>_.default.resolve(a,".jiek",...e);E.default.existsSync(s())||E.default.mkdirSync(s());const l=q.resolve("rollup").replace(/dist\/rollup.js$/,"dist/bin/rollup"),p=new i.MultiBar({clearOnComplete:!1,hideCursor:!0,format:"- {bar} | {status} | {input} | {message}"},i.Presets.shades_classic);let c=0;await Promise.all(Object.entries(o).map((async([n,o])=>{const a=o.name?.replace(/^@/g,"").replace(/\//g,"+"),i=s(`${a??"anonymous-"+c++}.rollup.config.js`);E.default.writeFileSync(i,(e=>`\nmodule.exports = require('jiek/rollup').template(${JSON.stringify(e,null,2)})\n`.trimStart())(o));let f="";U&&(f=`node -r ${U} `);const d=`${f}${l} --silent -c ${i}`,g=u.execaCommand(d,{ipc:!0,cwd:n,env:{...process.env,JIEK_ROOT:r,JIEK_ENTRIES:t}}),h={};let y=10;g.on("message",(e=>{"debug"===e.type&&console.log(...Array.isArray(e.data)?e.data:[e.data])})),!e&&g.on("message",(e=>{if("init"===e.type){const{leafMap:t,targetsLength:n}=e.data,r=Array.from(t.entries()).flatMap((([e,t])=>t.map((([t,...n])=>({input:e,path:t,conditions:n})))));console.log(`Package '${o.name}' has ${n} targets to build`),r.forEach((({input:e})=>{y=Math.max(y,e.length)})),r.forEach((({input:e,path:t})=>{const n=`${e}:${t}`;h[n]||(h[n]=p.create(50,0,{input:e.padEnd(y),status:"waiting".padEnd(10)},{barsize:20,linewrap:!0}))}))}if("progress"===e.type){const{path:t,tags:n,input:r,event:o,message:a}=e.data,s=h[`${r}:${t}`];if(!s)return;s.update({start:0,resolve:20,end:50}[o??"start"]??0,{input:r.padEnd(y),status:o?.padEnd(10),message:`${n?.join(", ")}: ${a}`})}})),await new Promise(((e,t)=>{let n="";g.stderr?.on("data",(e=>{n+=e})),g.once("exit",(r=>0===r?e():t(new Error(`rollup build failed:\n${n}`))))}))}))).finally((()=>{p.stop()})),j()}));var Q,W,X,Z,J,z,Y,V,ee,te,ne,re,oe,ae,se,ie,ue,le,pe,ce={};function fe(){return Q||(Q=1,(e=ce).isInteger=e=>"number"==typeof e?Number.isInteger(e):"string"==typeof e&&""!==e.trim()&&Number.isInteger(Number(e)),e.find=(e,t)=>e.nodes.find((e=>e.type===t)),e.exceedsLimit=(t,n,r=1,o)=>!1!==o&&!(!e.isInteger(t)||!e.isInteger(n))&&(Number(n)-Number(t))/Number(r)>=o,e.escapeNode=(e,t=0,n)=>{let r=e.nodes[t];r&&(n&&r.type===n||"open"===r.type||"close"===r.type)&&!0!==r.escaped&&(r.value="\\"+r.value,r.escaped=!0)},e.encloseBrace=e=>!("brace"!==e.type||e.commas>>0+e.ranges||(e.invalid=!0,0)),e.isInvalidBrace=e=>!("brace"!==e.type||!0!==e.invalid&&!e.dollar&&(e.commas>>0+e.ranges&&!0===e.open&&!0===e.close||(e.invalid=!0,0))),e.isOpenOrClose=e=>"open"===e.type||"close"===e.type||!0===e.open||!0===e.close,e.reduce=e=>e.reduce(((e,t)=>("text"===t.type&&e.push(t.value),"range"===t.type&&(t.type="text"),e)),[]),e.flatten=(...e)=>{const t=[],n=e=>{for(let r=0;r<e.length;r++){let o=e[r];Array.isArray(o)?n(o):void 0!==o&&t.push(o)}return t};return n(e),t}),ce;var e}function de(){if(X)return W;X=1;const e=fe();return W=(t,n={})=>{let r=(t,o={})=>{let a=n.escapeInvalid&&e.isInvalidBrace(o),s=!0===t.invalid&&!0===n.escapeInvalid,i="";if(t.value)return(a||s)&&e.isOpenOrClose(t)?"\\"+t.value:t.value;if(t.value)return t.value;if(t.nodes)for(let e of t.nodes)i+=r(e);return i};return r(t)}}
|
2
2
|
/*!
|
3
3
|
* is-number <https://github.com/jonschlinkert/is-number>
|
4
4
|
*
|
package/dist/cli.min.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import e from"node:fs";import{createRequire as t}from"node:module";import n,{resolve as r,relative as o}from"node:path";import{filterPackagesFromDir as s}from"@pnpm/filter-workspace-packages";import{program as a}from"commander";import{load as i}from"js-yaml";import{isWorkspaceDir as u,getWorkspaceDir as p}from"@jiek/utils/getWorkspaceDir";import{MultiBar as l,Presets as c}from"cli-progress";import{execaCommand as f}from"execa";import g from"detect-indent";import d from"inquirer";import{applyEdits as h,modify as A}from"jsonc-parser";import R from"util";import y from"path";import*as m from"node:child_process";import{bump as _}from"@jiek/utils/bumper";import{resolveEntrypoints as E,filterLeafs as b,DEFAULT_SKIP_VALUES as S,entrypoints2Exports as C}from"@jiek/pkger/entrypoints";let v,$;function x(){if(v)return v;const e=a.getOptionValue("root");return v=e?n.isAbsolute(e)?e:n.resolve(process.cwd(),e):void 0,v}let w=!1;function H(){if($)return{wd:$,notWorkspace:w};const e=x();if(void 0!==e){const t=u(e,k);return w=!t,$=e,{wd:$,notWorkspace:w}}try{$=p(k)}catch(t){if(!("message"in t)||"workspace root not found"!==t.message)throw t;$=e,w=!0}return{wd:$,notWorkspace:w}}let k="";try{t(import.meta.url).resolve("@pnpm/filter-workspace-packages"),k="pnpm"}catch{}async function O(){let t=a.getOptionValue("filter");const r=x(),{wd:o,notWorkspace:u}=H();if(!u&&"pnpm"===k){const a=n.resolve(o,"pnpm-workspace.yaml"),u=e.readFileSync(a,"utf-8"),p=i(u);if(r===o&&!t)throw new Error("root path is workspace root, please provide a filter");if(r!==o&&!t){if(!e.existsSync(n.resolve(r,"package.json")))throw new Error("root path is not workspace root, please provide a filter");const o=JSON.parse(e.readFileSync(n.resolve(r,"package.json"),"utf-8"));if(!o.name)throw new Error("root path is not workspace root, please provide a filter");t=o.name}const{selectedProjectsGraph:l}=await s(o,[{filter:t??"",followProdDepsOnly:!0}],{prefix:r,workspaceDir:o,patterns:p.packages});return{wd:o,root:r,value:Object.entries(l).reduce(((e,[t,n])=>(e[t]=n.package.manifest,e)),{})}}return{wd:o,root:r,value:{[o]:JSON.parse(e.readFileSync(n.resolve(o,"package.json"),"utf-8"))}}}""!==k&&a.option("-f, --filter <filter>","filter packages");var T="1.0.
|
1
|
+
import e from"node:fs";import{createRequire as t}from"node:module";import n,{resolve as r,relative as o}from"node:path";import{filterPackagesFromDir as s}from"@pnpm/filter-workspace-packages";import{program as a}from"commander";import{load as i}from"js-yaml";import{isWorkspaceDir as u,getWorkspaceDir as p}from"@jiek/utils/getWorkspaceDir";import{MultiBar as l,Presets as c}from"cli-progress";import{execaCommand as f}from"execa";import g from"detect-indent";import d from"inquirer";import{applyEdits as h,modify as A}from"jsonc-parser";import R from"util";import y from"path";import*as m from"node:child_process";import{bump as _}from"@jiek/utils/bumper";import{resolveEntrypoints as E,filterLeafs as b,DEFAULT_SKIP_VALUES as S,entrypoints2Exports as C}from"@jiek/pkger/entrypoints";let v,$;function x(){if(v)return v;const e=a.getOptionValue("root");return v=e?n.isAbsolute(e)?e:n.resolve(process.cwd(),e):void 0,v}let w=!1;function H(){if($)return{wd:$,notWorkspace:w};const e=x();if(void 0!==e){const t=u(e,k);return w=!t,$=e,{wd:$,notWorkspace:w}}try{$=p(k)}catch(t){if(!("message"in t)||"workspace root not found"!==t.message)throw t;$=e,w=!0}return{wd:$,notWorkspace:w}}let k="";try{t(import.meta.url).resolve("@pnpm/filter-workspace-packages"),k="pnpm"}catch{}async function O(){let t=a.getOptionValue("filter");const r=x(),{wd:o,notWorkspace:u}=H();if(!u&&"pnpm"===k){const a=n.resolve(o,"pnpm-workspace.yaml"),u=e.readFileSync(a,"utf-8"),p=i(u);if(r===o&&!t)throw new Error("root path is workspace root, please provide a filter");if(r!==o&&!t){if(!e.existsSync(n.resolve(r,"package.json")))throw new Error("root path is not workspace root, please provide a filter");const o=JSON.parse(e.readFileSync(n.resolve(r,"package.json"),"utf-8"));if(!o.name)throw new Error("root path is not workspace root, please provide a filter");t=o.name}const{selectedProjectsGraph:l}=await s(o,[{filter:t??"",followProdDepsOnly:!0}],{prefix:r,workspaceDir:o,patterns:p.packages});return{wd:o,root:r,value:Object.entries(l).reduce(((e,[t,n])=>(e[t]=n.package.manifest,e)),{})}}return{wd:o,root:r,value:{[o]:JSON.parse(e.readFileSync(n.resolve(o,"package.json"),"utf-8"))}}}""!==k&&a.option("-f, --filter <filter>","filter packages");var T="1.0.3",L="YiJie's personal kits.";let N;function I(){N()}function M(){new Promise((e=>N=e))}a.version(T).description(L).option("--root <root>","root path").option("-c, --config-path <configPath>","config path");const j=t(import.meta.url);function B(e){try{return j.resolve(e),!0}catch(e){return!1}}let P;const G=[process.env.JIEK_TS_REGISTER,"esbuild-register","@swc-node/register","ts-node/register"].filter(Boolean);for(const e of G)if(B(e)){P=e;break}let D="jiek.config";function K(t){const{wd:r}=H();let o=a.getOptionValue("configPath");if(o){if(!e.existsSync(o))throw new Error(`config file not found: ${o}`);n.isAbsolute(o)||(o=n.resolve(r,o))}else o=function(t,r){const o=!!P;function s(o){const s=[n.resolve(process.cwd(),`${D}.${o}`),n.resolve(process.cwd(),`.${D}.${o}`),n.resolve(t,`${D}.${o}`),n.resolve(t,`.${D}.${o}`)];r&&s.unshift(n.resolve(r,`${D}.${o}`),n.resolve(r,`.${D}.${o}`));for(const t of s)if(e.existsSync(t)&&e.lstatSync(t).isFile())return t}return D=s("js")??D,D=s("json")??D,D=s("yaml")??D,o&&(D=s("ts")??D),n.resolve(t,D)}(r,t);const s=n.extname(o);let u;switch(s){case".js":u=require(o);break;case".json":return require(o);case".yaml":return i(e.readFileSync(o,"utf-8"));case".ts":if(P){require(P),u=require(o);break}throw new Error("ts config file is not supported without ts register, please install esbuild-register or set JIEK_TS_REGISTER env for custom ts register");case".config":u={};break;default:throw new Error(`unsupported config file type: ${s}`)}if(!u)throw new Error("config file is empty");return u.default??u}const U=t(import.meta.url);a.command("build").option("-s, --silent","Don't display logs.").option("-e, --entries <ENTRIES>","Specify the entries of the package.json's 'exports' field.(support glob)").action((async({silent:t,entries:r})=>{M();const{build:o}=K();t=t??o?.silent??!1;const{wd:s,value:a={}}=await O()??{};if(0===Object.keys(a).length)throw new Error("no package found");const i=n.resolve(s,"node_modules");e.existsSync(i)||e.mkdirSync(i);const u=(...e)=>n.resolve(i,".jiek",...e);e.existsSync(u())||e.mkdirSync(u());const p=U.resolve("rollup").replace(/dist\/rollup.js$/,"dist/bin/rollup"),g=new l({clearOnComplete:!1,hideCursor:!0,format:"- {bar} | {status} | {input} | {message}"},c.shades_classic);let d=0;await Promise.all(Object.entries(a).map((async([n,o])=>{const a=o.name?.replace(/^@/g,"").replace(/\//g,"+"),i=u(`${a??"anonymous-"+d++}.rollup.config.js`);e.writeFileSync(i,(e=>`\nmodule.exports = require('jiek/rollup').template(${JSON.stringify(e,null,2)})\n`.trimStart())(o));let l="";P&&(l=`node -r ${P} `);const c=f(`${l}${p} --silent -c ${i}`,{ipc:!0,cwd:n,env:{...process.env,JIEK_ROOT:s,JIEK_ENTRIES:r}}),h={};let A=10;c.on("message",(e=>{"debug"===e.type&&console.log(...Array.isArray(e.data)?e.data:[e.data])})),!t&&c.on("message",(e=>{if("init"===e.type){const{leafMap:t,targetsLength:n}=e.data,r=Array.from(t.entries()).flatMap((([e,t])=>t.map((([t,...n])=>({input:e,path:t,conditions:n})))));console.log(`Package '${o.name}' has ${n} targets to build`),r.forEach((({input:e})=>{A=Math.max(A,e.length)})),r.forEach((({input:e,path:t})=>{const n=`${e}:${t}`;h[n]||(h[n]=g.create(50,0,{input:e.padEnd(A),status:"waiting".padEnd(10)},{barsize:20,linewrap:!0}))}))}if("progress"===e.type){const{path:t,tags:n,input:r,event:o,message:s}=e.data,a=h[`${r}:${t}`];if(!a)return;a.update({start:0,resolve:20,end:50}[o??"start"]??0,{input:r.padEnd(A),status:o?.padEnd(10),message:`${n?.join(", ")}: ${s}`})}})),await new Promise(((e,t)=>{let n="";c.stderr?.on("data",(e=>{n+=e})),c.once("exit",(r=>0===r?e():t(new Error(`rollup build failed:\n${n}`))))}))}))).finally((()=>{g.stop()})),I()}));var F,Q,W,X,q,Z,J,Y,z,V,ee,te,ne,re,oe,se,ae,ie,ue,pe={};function le(){return F||(F=1,function(e){e.isInteger=e=>"number"==typeof e?Number.isInteger(e):"string"==typeof e&&""!==e.trim()&&Number.isInteger(Number(e)),e.find=(e,t)=>e.nodes.find((e=>e.type===t)),e.exceedsLimit=(t,n,r=1,o)=>!1!==o&&(!(!e.isInteger(t)||!e.isInteger(n))&&(Number(n)-Number(t))/Number(r)>=o),e.escapeNode=(e,t=0,n)=>{let r=e.nodes[t];r&&(n&&r.type===n||"open"===r.type||"close"===r.type)&&!0!==r.escaped&&(r.value="\\"+r.value,r.escaped=!0)},e.encloseBrace=e=>"brace"===e.type&&(!(e.commas>>0+e.ranges)&&(e.invalid=!0,!0)),e.isInvalidBrace=e=>"brace"===e.type&&(!(!0!==e.invalid&&!e.dollar)||(e.commas>>0+e.ranges?(!0!==e.open||!0!==e.close)&&(e.invalid=!0,!0):(e.invalid=!0,!0))),e.isOpenOrClose=e=>"open"===e.type||"close"===e.type||(!0===e.open||!0===e.close),e.reduce=e=>e.reduce(((e,t)=>("text"===t.type&&e.push(t.value),"range"===t.type&&(t.type="text"),e)),[]),e.flatten=(...e)=>{const t=[],n=e=>{for(let r=0;r<e.length;r++){let o=e[r];Array.isArray(o)?n(o):void 0!==o&&t.push(o)}return t};return n(e),t}}(pe)),pe}function ce(){if(W)return Q;W=1;const e=le();return Q=(t,n={})=>{let r=(t,o={})=>{let s=n.escapeInvalid&&e.isInvalidBrace(o),a=!0===t.invalid&&!0===n.escapeInvalid,i="";if(t.value)return(s||a)&&e.isOpenOrClose(t)?"\\"+t.value:t.value;if(t.value)return t.value;if(t.nodes)for(let e of t.nodes)i+=r(e);return i};return r(t)}}
|
2
2
|
/*!
|
3
3
|
* is-number <https://github.com/jonschlinkert/is-number>
|
4
4
|
*
|
package/dist/rollup/index.cjs
CHANGED
@@ -10,15 +10,15 @@ var json = require('@rollup/plugin-json');
|
|
10
10
|
var pluginNodeResolve = require('@rollup/plugin-node-resolve');
|
11
11
|
var terser = require('@rollup/plugin-terser');
|
12
12
|
var execa = require('execa');
|
13
|
-
var jsoncParser = require('jsonc-parser');
|
14
|
-
var require$$0 = require('util');
|
15
|
-
var require$$0$1 = require('path');
|
16
13
|
var esbuild = require('rollup-plugin-esbuild');
|
17
14
|
var ts = require('typescript');
|
15
|
+
var require$$0 = require('util');
|
16
|
+
var require$$0$1 = require('path');
|
18
17
|
var commander = require('commander');
|
19
18
|
var jsYaml = require('js-yaml');
|
20
19
|
var node_module = require('node:module');
|
21
20
|
require('@pnpm/filter-workspace-packages');
|
21
|
+
var jsoncParser = require('jsonc-parser');
|
22
22
|
|
23
23
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
24
24
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
@@ -28,10 +28,10 @@ var path__default = /*#__PURE__*/_interopDefault(path);
|
|
28
28
|
var commonjs__default = /*#__PURE__*/_interopDefault(commonjs);
|
29
29
|
var json__default = /*#__PURE__*/_interopDefault(json);
|
30
30
|
var terser__default = /*#__PURE__*/_interopDefault(terser);
|
31
|
-
var require$$0__default = /*#__PURE__*/_interopDefault(require$$0);
|
32
|
-
var require$$0__default$1 = /*#__PURE__*/_interopDefault(require$$0$1);
|
33
31
|
var esbuild__default = /*#__PURE__*/_interopDefault(esbuild);
|
34
32
|
var ts__default = /*#__PURE__*/_interopDefault(ts);
|
33
|
+
var require$$0__default = /*#__PURE__*/_interopDefault(require$$0);
|
34
|
+
var require$$0__default$1 = /*#__PURE__*/_interopDefault(require$$0$1);
|
35
35
|
|
36
36
|
var utils$1 = {};
|
37
37
|
|
@@ -4347,6 +4347,65 @@ function loadConfig(dir) {
|
|
4347
4347
|
return module.default ?? module;
|
4348
4348
|
}
|
4349
4349
|
|
4350
|
+
const getTSConfig = (p) => !fs__default.default.existsSync(p) || !fs__default.default.statSync(p).isFile() ? {} : jsoncParser.parse(fs__default.default.readFileSync(p, "utf-8"), [], { allowTrailingComma: true, allowEmptyContent: true });
|
4351
|
+
const getExtendTSConfig = (tsconfigPath) => {
|
4352
|
+
tsconfigPath = path.resolve(tsconfigPath);
|
4353
|
+
const tsconfigPathDirname = path.dirname(tsconfigPath);
|
4354
|
+
const { extends: exts, ...tsconfig } = getTSConfig(tsconfigPath);
|
4355
|
+
const resolvePaths = (paths) => paths?.map((p) => path.resolve(tsconfigPathDirname, p)) ?? [];
|
4356
|
+
const extendsPaths = resolvePaths(
|
4357
|
+
exts ? Array.isArray(exts) ? exts : [exts] : []
|
4358
|
+
);
|
4359
|
+
if (extendsPaths.length === 0)
|
4360
|
+
return tsconfig;
|
4361
|
+
return extendsPaths.map(getExtendTSConfig).concat(tsconfig).reduce((acc, { compilerOptions = {}, references: _, ...curr }) => ({
|
4362
|
+
...acc,
|
4363
|
+
...curr,
|
4364
|
+
compilerOptions: {
|
4365
|
+
...acc.compilerOptions,
|
4366
|
+
...compilerOptions
|
4367
|
+
}
|
4368
|
+
}), {});
|
4369
|
+
};
|
4370
|
+
const getCompilerOptionsByFilePath = (tsconfigPath, filePath) => {
|
4371
|
+
tsconfigPath = path.resolve(tsconfigPath);
|
4372
|
+
filePath = path.resolve(filePath);
|
4373
|
+
const tsconfigPathDirname = path.dirname(tsconfigPath);
|
4374
|
+
const tsconfig = getExtendTSConfig(tsconfigPath);
|
4375
|
+
const resolvePaths = (paths) => paths?.map((p) => path.resolve(tsconfigPathDirname, p)) ?? [];
|
4376
|
+
const [
|
4377
|
+
references,
|
4378
|
+
files,
|
4379
|
+
include,
|
4380
|
+
exclude
|
4381
|
+
] = [
|
4382
|
+
tsconfig.references?.map(({ path }) => path),
|
4383
|
+
tsconfig.files,
|
4384
|
+
tsconfig.include,
|
4385
|
+
tsconfig.exclude
|
4386
|
+
].map(resolvePaths);
|
4387
|
+
if (exclude.length > 0 && exclude.some((i) => micromatchExports.isMatch(filePath, i)))
|
4388
|
+
return;
|
4389
|
+
if (tsconfig.files?.length === 0 && tsconfig.include?.length === 0)
|
4390
|
+
return;
|
4391
|
+
let isInclude = false;
|
4392
|
+
isInclude || (isInclude = files.length > 0 && files.includes(filePath));
|
4393
|
+
isInclude || (isInclude = include.length > 0 && include.some((i) => micromatchExports.isMatch(filePath, i)));
|
4394
|
+
if (isInclude) {
|
4395
|
+
return tsconfig.compilerOptions ?? {};
|
4396
|
+
} else {
|
4397
|
+
if (tsconfig.files && tsconfig.files.length > 0 || tsconfig.include && tsconfig.include.length > 0)
|
4398
|
+
return;
|
4399
|
+
}
|
4400
|
+
references.reverse();
|
4401
|
+
for (const ref of references) {
|
4402
|
+
const compilerOptions = getCompilerOptionsByFilePath(ref, filePath);
|
4403
|
+
if (compilerOptions)
|
4404
|
+
return compilerOptions;
|
4405
|
+
}
|
4406
|
+
return tsconfig.compilerOptions;
|
4407
|
+
};
|
4408
|
+
|
4350
4409
|
var progress = (options = {}) => {
|
4351
4410
|
const { onEvent } = options;
|
4352
4411
|
return {
|
@@ -4368,19 +4427,17 @@ var progress = (options = {}) => {
|
|
4368
4427
|
};
|
4369
4428
|
};
|
4370
4429
|
|
4371
|
-
var skip = (options = {}) => {
|
4372
|
-
|
4373
|
-
|
4374
|
-
|
4375
|
-
|
4376
|
-
|
4377
|
-
|
4378
|
-
|
4379
|
-
return "";
|
4380
|
-
}
|
4430
|
+
var skip = (options = {}) => ({
|
4431
|
+
name: "skip",
|
4432
|
+
// skip the specified files by `options.patterns`
|
4433
|
+
load(id) {
|
4434
|
+
if (options.patterns?.some(
|
4435
|
+
(pattern) => typeof pattern === "string" ? id.includes(pattern) : pattern.test(id)
|
4436
|
+
)) {
|
4437
|
+
return "";
|
4381
4438
|
}
|
4382
|
-
}
|
4383
|
-
};
|
4439
|
+
}
|
4440
|
+
});
|
4384
4441
|
|
4385
4442
|
function externalResolver(jsonOrPath = process.cwd()) {
|
4386
4443
|
const pkg = typeof jsonOrPath === "string" ? fs__default.default.existsSync(`${jsonOrPath}/package.json`) ? JSON.parse(fs__default.default.readFileSync(`${jsonOrPath}/package.json`, "utf-8")) : {} : jsonOrPath;
|
@@ -4409,6 +4466,29 @@ const jsOutdir = `./${path.relative(
|
|
4409
4466
|
)
|
4410
4467
|
)}`;
|
4411
4468
|
const STYLE_REGEXP = /\.(css|s[ac]ss|less|styl)$/;
|
4469
|
+
const resolveBuildPlugins = (context, plugins) => {
|
4470
|
+
if (plugins === false || plugins === void 0 || plugins === null) {
|
4471
|
+
return { js: [], dts: [] };
|
4472
|
+
}
|
4473
|
+
let js = [];
|
4474
|
+
let dts2 = [];
|
4475
|
+
switch (typeof plugins) {
|
4476
|
+
case "function":
|
4477
|
+
js = plugins("js", context);
|
4478
|
+
dts2 = plugins("dts", context);
|
4479
|
+
break;
|
4480
|
+
case "object":
|
4481
|
+
if ("js" in plugins || "dts" in plugins) {
|
4482
|
+
js = plugins.js ?? [];
|
4483
|
+
dts2 = plugins.dts ?? [];
|
4484
|
+
} else {
|
4485
|
+
js = plugins;
|
4486
|
+
dts2 = plugins;
|
4487
|
+
}
|
4488
|
+
break;
|
4489
|
+
}
|
4490
|
+
return { js, dts: dts2 };
|
4491
|
+
};
|
4412
4492
|
const resolveWorkspacePath = (p) => path.resolve(WORKSPACE_ROOT, p);
|
4413
4493
|
const pascalCase = (str) => str.replace(/[@|/-](\w)/g, (_, $1) => $1.toUpperCase()).replace(/(?:^|-)(\w)/g, (_, $1) => $1.toUpperCase());
|
4414
4494
|
const reveal = (obj, keys) => keys.reduce((acc, key) => {
|
@@ -4438,73 +4518,16 @@ const withMinify = (output, minify = build?.output?.minify) => minify === false
|
|
4438
4518
|
]
|
4439
4519
|
}
|
4440
4520
|
];
|
4441
|
-
const
|
4442
|
-
const
|
4443
|
-
|
4444
|
-
|
4445
|
-
|
4446
|
-
|
4447
|
-
|
4448
|
-
|
4449
|
-
|
4450
|
-
|
4451
|
-
return tsconfig;
|
4452
|
-
return extendsPaths.map(getExtendTSConfig).concat(tsconfig).reduce((acc, { compilerOptions = {}, references: _, ...curr }) => ({
|
4453
|
-
...acc,
|
4454
|
-
...curr,
|
4455
|
-
compilerOptions: {
|
4456
|
-
...acc.compilerOptions,
|
4457
|
-
...compilerOptions
|
4458
|
-
}
|
4459
|
-
}), {});
|
4460
|
-
};
|
4461
|
-
const getCompilerOptionsByFilePath = (tsconfigPath, filePath) => {
|
4462
|
-
tsconfigPath = path.resolve(tsconfigPath);
|
4463
|
-
filePath = path.resolve(filePath);
|
4464
|
-
const tsconfigPathDirname = path.dirname(tsconfigPath);
|
4465
|
-
const tsconfig = getExtendTSConfig(tsconfigPath);
|
4466
|
-
const resolvePaths = (paths) => paths?.map((p) => path.resolve(tsconfigPathDirname, p)) ?? [];
|
4467
|
-
const [
|
4468
|
-
references,
|
4469
|
-
files,
|
4470
|
-
include,
|
4471
|
-
exclude
|
4472
|
-
] = [
|
4473
|
-
tsconfig.references?.map(({ path }) => path),
|
4474
|
-
tsconfig.files,
|
4475
|
-
tsconfig.include,
|
4476
|
-
tsconfig.exclude
|
4477
|
-
].map(resolvePaths);
|
4478
|
-
if (exclude.length > 0 && exclude.some((i) => micromatchExports.isMatch(filePath, i)))
|
4479
|
-
return;
|
4480
|
-
if (tsconfig.files?.length === 0 && tsconfig.include?.length === 0)
|
4481
|
-
return;
|
4482
|
-
let isInclude = false;
|
4483
|
-
isInclude || (isInclude = files.length > 0 && files.includes(filePath));
|
4484
|
-
isInclude || (isInclude = include.length > 0 && include.some((i) => micromatchExports.isMatch(filePath, i)));
|
4485
|
-
if (isInclude) {
|
4486
|
-
return tsconfig.compilerOptions ?? {};
|
4487
|
-
} else {
|
4488
|
-
if (tsconfig.files && tsconfig.files.length > 0 || tsconfig.include && tsconfig.include.length > 0)
|
4489
|
-
return;
|
4490
|
-
}
|
4491
|
-
references.reverse();
|
4492
|
-
for (const ref of references) {
|
4493
|
-
const compilerOptions = getCompilerOptionsByFilePath(ref, filePath);
|
4494
|
-
if (compilerOptions)
|
4495
|
-
return compilerOptions;
|
4496
|
-
}
|
4497
|
-
return tsconfig.compilerOptions;
|
4498
|
-
};
|
4499
|
-
const generateConfigs = ({
|
4500
|
-
path: path$1,
|
4501
|
-
name,
|
4502
|
-
input,
|
4503
|
-
output,
|
4504
|
-
external,
|
4505
|
-
pkgIsModule,
|
4506
|
-
conditionals
|
4507
|
-
}, options = {}) => {
|
4521
|
+
const generateConfigs = (context, options = {}) => {
|
4522
|
+
const {
|
4523
|
+
path: path$1,
|
4524
|
+
name,
|
4525
|
+
input,
|
4526
|
+
output,
|
4527
|
+
external,
|
4528
|
+
pkgIsModule,
|
4529
|
+
conditionals
|
4530
|
+
} = context;
|
4508
4531
|
const isModule = conditionals.includes("import");
|
4509
4532
|
const isCommonJS = conditionals.includes("require");
|
4510
4533
|
const isBrowser = conditionals.includes("browser");
|
@@ -4536,6 +4559,7 @@ const generateConfigs = ({
|
|
4536
4559
|
data: { name, path: path$1, exportConditions, input }
|
4537
4560
|
};
|
4538
4561
|
const outdir = options?.output?.dir;
|
4562
|
+
const { js: jsPlugins, dts: dtsPlugins } = resolveBuildPlugins(context, build.plugins);
|
4539
4563
|
return [
|
4540
4564
|
{
|
4541
4565
|
input,
|
@@ -4558,7 +4582,9 @@ const generateConfigs = ({
|
|
4558
4582
|
minimize: true
|
4559
4583
|
})
|
4560
4584
|
).catch(() => void 0),
|
4561
|
-
esbuild__default.default(
|
4585
|
+
esbuild__default.default({
|
4586
|
+
tsconfig: dtsTSConfigPath
|
4587
|
+
}),
|
4562
4588
|
commonjs__default.default(),
|
4563
4589
|
progress({
|
4564
4590
|
onEvent: (event, message) => execa.sendMessage(
|
@@ -4567,7 +4593,8 @@ const generateConfigs = ({
|
|
4567
4593
|
data: { ...throughEventProps.data, event, message, tags: ["js"] }
|
4568
4594
|
}
|
4569
4595
|
)
|
4570
|
-
})
|
4596
|
+
}),
|
4597
|
+
jsPlugins
|
4571
4598
|
]
|
4572
4599
|
},
|
4573
4600
|
{
|
@@ -4595,7 +4622,8 @@ const generateConfigs = ({
|
|
4595
4622
|
data: { ...throughEventProps.data, event, message, tags: ["dts"] }
|
4596
4623
|
}
|
4597
4624
|
)
|
4598
|
-
})
|
4625
|
+
}),
|
4626
|
+
dtsPlugins
|
4599
4627
|
]
|
4600
4628
|
}
|
4601
4629
|
];
|
package/dist/rollup/index.d.cts
CHANGED
@@ -1,9 +1,18 @@
|
|
1
|
-
import { OutputOptions, RollupOptions } from 'rollup';
|
1
|
+
import { InputPluginOption, OutputOptions, RollupOptions } from 'rollup';
|
2
2
|
|
3
3
|
type Mapping2ROO<K extends keyof OutputOptions> = OutputOptions[K] | {
|
4
4
|
js?: OutputOptions[K];
|
5
5
|
dts?: OutputOptions[K];
|
6
6
|
};
|
7
|
+
interface ConfigGenerateContext {
|
8
|
+
path: string;
|
9
|
+
name: string;
|
10
|
+
input: string;
|
11
|
+
output: string;
|
12
|
+
external: (string | RegExp)[];
|
13
|
+
pkgIsModule: boolean;
|
14
|
+
conditionals: string[];
|
15
|
+
}
|
7
16
|
interface TemplateOptions {
|
8
17
|
/**
|
9
18
|
* When the user configures type: module, the generated output from entry points that don't
|
@@ -29,6 +38,13 @@ interface TemplateOptions {
|
|
29
38
|
sourcemap?: Mapping2ROO<'sourcemap'>;
|
30
39
|
strict?: Mapping2ROO<'strict'>;
|
31
40
|
};
|
41
|
+
plugins?: InputPluginOption | ((type: 'js' | 'dts', context: ConfigGenerateContext) => InputPluginOption) | {
|
42
|
+
js: InputPluginOption;
|
43
|
+
dts?: InputPluginOption;
|
44
|
+
} | {
|
45
|
+
js?: InputPluginOption;
|
46
|
+
dts: InputPluginOption;
|
47
|
+
};
|
32
48
|
}
|
33
49
|
declare module 'jiek' {
|
34
50
|
interface Config {
|
package/dist/rollup/index.d.ts
CHANGED
@@ -1,9 +1,18 @@
|
|
1
|
-
import { OutputOptions, RollupOptions } from 'rollup';
|
1
|
+
import { InputPluginOption, OutputOptions, RollupOptions } from 'rollup';
|
2
2
|
|
3
3
|
type Mapping2ROO<K extends keyof OutputOptions> = OutputOptions[K] | {
|
4
4
|
js?: OutputOptions[K];
|
5
5
|
dts?: OutputOptions[K];
|
6
6
|
};
|
7
|
+
interface ConfigGenerateContext {
|
8
|
+
path: string;
|
9
|
+
name: string;
|
10
|
+
input: string;
|
11
|
+
output: string;
|
12
|
+
external: (string | RegExp)[];
|
13
|
+
pkgIsModule: boolean;
|
14
|
+
conditionals: string[];
|
15
|
+
}
|
7
16
|
interface TemplateOptions {
|
8
17
|
/**
|
9
18
|
* When the user configures type: module, the generated output from entry points that don't
|
@@ -29,6 +38,13 @@ interface TemplateOptions {
|
|
29
38
|
sourcemap?: Mapping2ROO<'sourcemap'>;
|
30
39
|
strict?: Mapping2ROO<'strict'>;
|
31
40
|
};
|
41
|
+
plugins?: InputPluginOption | ((type: 'js' | 'dts', context: ConfigGenerateContext) => InputPluginOption) | {
|
42
|
+
js: InputPluginOption;
|
43
|
+
dts?: InputPluginOption;
|
44
|
+
} | {
|
45
|
+
js?: InputPluginOption;
|
46
|
+
dts: InputPluginOption;
|
47
|
+
};
|
32
48
|
}
|
33
49
|
declare module 'jiek' {
|
34
50
|
interface Config {
|