pkgroll 1.1.3 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -150,8 +150,8 @@ The target specifies the environments the output should support. Depending on ho
150
150
 
151
151
  By default, the target is set to the version of Node.js used. It can be overwritten with the `--target` flag:
152
152
 
153
- ```
154
- pkgroll --target es2020 --target node14.18.0
153
+ ```sh
154
+ pkgroll --target=es2020 --target=node14.18.0
155
155
  ```
156
156
 
157
157
  It will also automatically detect and include the `target` specified in `tsconfig.json#compilerOptions`.
@@ -160,18 +160,28 @@ It will also automatically detect and include the `target` specified in `tsconfi
160
160
  #### Strip `node:` protocol
161
161
  Node.js builtin modules can be prefixed with the [`node:` protocol](https://nodejs.org/api/esm.html#node-imports) for explicitness:
162
162
 
163
- ```
164
- import fs from 'node:fs/promises';
163
+ ```js
164
+ import fs from 'node:fs/promises'
165
165
  ```
166
166
 
167
167
  This is a new feature and may not work in older versions of Node.js. While you can opt out of using it, your dependencies may still be using it (example package using `node:`: [path-exists](https://github.com/sindresorhus/path-exists/blob/7c95f5c1f5f811c7f4dac78ab5b9e258491f03af/index.js#L1)).
168
168
 
169
169
  Pass in a Node.js target that that doesn't support it to strip the `node:` protocol from imports:
170
170
 
171
+ ```sh
172
+ pkgroll --target=node12.19
171
173
  ```
172
- pkgroll --target node12.19
174
+
175
+ ### Export condition
176
+
177
+ Similarly to the target, the export condition specifies which fields to read from when evaluating [export](https://nodejs.org/api/packages.html#exports) and [import](https://nodejs.org/api/packages.html#imports) maps.
178
+
179
+ For example, to simulate import resolutions in Node.js, pass in `node` as the export condition:
180
+ ```sh
181
+ pkgroll --export-condition=node
173
182
  ```
174
183
 
184
+
175
185
  ### ESM ⇄ CJS interoperability
176
186
 
177
187
  Node.js ESM offers [interoperability with CommonJS](https://nodejs.org/api/esm.html#interoperability-with-commonjs) via [static analysis](https://github.com/nodejs/cjs-module-lexer). However, not all bundlers compile ESM to CJS syntax in a way that is statically analyzable.
package/dist/cli.js CHANGED
@@ -24,10 +24,10 @@
24
24
 
25
25
  export default (
26
26
  ${Xu}
27
- ? createRequire(import.meta.url)
27
+ ? /* @__PURE__ */ createRequire(import.meta.url)
28
28
  : require
29
29
  );
30
30
  `}}),wt=u=>({name:"create-require-insert-format",renderChunk:gu.default({[Xu]:u}).renderChunk});function K(u){const D=/^\\\\\?\\/.test(u),e=/[^\u0000-\u0080]+/.test(u);return D||e?u:u.replace(/\\/g,"/")}function $t(u,D){for(;;){const e=m.default.join(u,D);if(P.default.existsSync(e))return K(e);const t=m.default.dirname(u);if(t===u)return;u=t}}var uD=du.createRequire(typeof document=="undefined"?new(require("url")).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("cli.js",document.baseURI).href);function Ot(u,D){D===void 0&&(D=!1);var e=u.length,t=0,r="",n=0,o=16,i=0,a=0,s=0,l=0,F=0;function c(C,b){for(var w=0,y=0;w<C||!b;){var B=u.charCodeAt(t);if(B>=48&&B<=57)y=y*16+B-48;else if(B>=65&&B<=70)y=y*16+B-65+10;else if(B>=97&&B<=102)y=y*16+B-97+10;else break;t++,w++}return w<C&&(y=-1),y}function f(C){t=C,r="",n=0,o=16,F=0}function E(){var C=t;if(u.charCodeAt(t)===48)t++;else for(t++;t<u.length&&N(u.charCodeAt(t));)t++;if(t<u.length&&u.charCodeAt(t)===46)if(t++,t<u.length&&N(u.charCodeAt(t)))for(t++;t<u.length&&N(u.charCodeAt(t));)t++;else return F=3,u.substring(C,t);var b=t;if(t<u.length&&(u.charCodeAt(t)===69||u.charCodeAt(t)===101))if(t++,(t<u.length&&u.charCodeAt(t)===43||u.charCodeAt(t)===45)&&t++,t<u.length&&N(u.charCodeAt(t))){for(t++;t<u.length&&N(u.charCodeAt(t));)t++;b=t}else F=3;return u.substring(C,b)}function d(){for(var C="",b=t;;){if(t>=e){C+=u.substring(b,t),F=2;break}var w=u.charCodeAt(t);if(w===34){C+=u.substring(b,t),t++;break}if(w===92){if(C+=u.substring(b,t),t++,t>=e){F=2;break}var y=u.charCodeAt(t++);switch(y){case 34:C+='"';break;case 92:C+="\\";break;case 47:C+="/";break;case 98:C+="\b";break;case 102:C+="\f";break;case 110:C+=`
31
31
  `;break;case 114:C+="\r";break;case 116:C+=" ";break;case 117:var B=c(4,!0);B>=0?C+=String.fromCharCode(B):F=4;break;default:F=5}b=t;continue}if(w>=0&&w<=31)if(W(w)){C+=u.substring(b,t),F=2;break}else F=6;t++}return C}function A(){if(r="",F=0,n=t,a=i,l=s,t>=e)return n=e,o=17;var C=u.charCodeAt(t);if(Cu(C)){do t++,r+=String.fromCharCode(C),C=u.charCodeAt(t);while(Cu(C));return o=15}if(W(C))return t++,r+=String.fromCharCode(C),C===13&&u.charCodeAt(t)===10&&(t++,r+=`
32
32
  `),i++,s=t,o=14;switch(C){case 123:return t++,o=1;case 125:return t++,o=2;case 91:return t++,o=3;case 93:return t++,o=4;case 58:return t++,o=6;case 44:return t++,o=5;case 34:return t++,r=d(),o=10;case 47:var b=t-1;if(u.charCodeAt(t+1)===47){for(t+=2;t<e&&!W(u.charCodeAt(t));)t++;return r=u.substring(b,t),o=12}if(u.charCodeAt(t+1)===42){t+=2;for(var w=e-1,y=!1;t<w;){var B=u.charCodeAt(t);if(B===42&&u.charCodeAt(t+1)===47){t+=2,y=!0;break}t++,W(B)&&(B===13&&u.charCodeAt(t)===10&&t++,i++,s=t)}return y||(t++,F=1),r=u.substring(b,t),o=13}return r+=String.fromCharCode(C),t++,o=16;case 45:if(r+=String.fromCharCode(C),t++,t===e||!N(u.charCodeAt(t)))return o=16;case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return r+=E(),o=11;default:for(;t<e&&g(C);)t++,C=u.charCodeAt(t);if(n!==t){switch(r=u.substring(n,t),r){case"true":return o=8;case"false":return o=9;case"null":return o=7}return o=16}return r+=String.fromCharCode(C),t++,o=16}}function g(C){if(Cu(C)||W(C))return!1;switch(C){case 125:case 93:case 123:case 91:case 34:case 58:case 44:case 47:return!1}return!0}function p(){var C;do C=A();while(C>=12&&C<=15);return C}return{setPosition:f,getPosition:function(){return t},scan:D?p:A,getToken:function(){return o},getTokenValue:function(){return r},getTokenOffset:function(){return n},getTokenLength:function(){return t-n},getTokenStartLine:function(){return a},getTokenStartCharacter:function(){return n-l},getTokenError:function(){return F}}}function Cu(u){return u===32||u===9||u===11||u===12||u===160||u===5760||u>=8192&&u<=8203||u===8239||u===8287||u===12288||u===65279}function W(u){return u===10||u===13||u===8232||u===8233}function N(u){return u>=48&&u<=57}var Q;(function(u){u.DEFAULT={allowTrailingComma:!1}})(Q||(Q={}));function jt(u,D,e){D===void 0&&(D=[]),e===void 0&&(e=Q.DEFAULT);var t=null,r=[],n=[];function o(a){Array.isArray(r)?r.push(a):t!==null&&(r[t]=a)}var i={onObjectBegin:function(){var a={};o(a),n.push(r),r=a,t=null},onObjectProperty:function(a){t=a},onObjectEnd:function(){r=n.pop()},onArrayBegin:function(){var a=[];o(a),n.push(r),r=a,t=null},onArrayEnd:function(){r=n.pop()},onLiteralValue:o,onError:function(a,s,l){D.push({error:a,offset:s,length:l})}};return Pt(u,i,e),r[0]}function Pt(u,D,e){e===void 0&&(e=Q.DEFAULT);var t=Ot(u,!1);function r(h){return h?function(){return h(t.getTokenOffset(),t.getTokenLength(),t.getTokenStartLine(),t.getTokenStartCharacter())}:function(){return!0}}function n(h){return h?function($){return h($,t.getTokenOffset(),t.getTokenLength(),t.getTokenStartLine(),t.getTokenStartCharacter())}:function(){return!0}}var o=r(D.onObjectBegin),i=n(D.onObjectProperty),a=r(D.onObjectEnd),s=r(D.onArrayBegin),l=r(D.onArrayEnd),F=n(D.onLiteralValue),c=n(D.onSeparator),f=r(D.onComment),E=n(D.onError),d=e&&e.disallowComments,A=e&&e.allowTrailingComma;function g(){for(;;){var h=t.scan();switch(t.getTokenError()){case 4:p(14);break;case 5:p(15);break;case 3:p(13);break;case 1:d||p(11);break;case 2:p(12);break;case 6:p(16);break}switch(h){case 12:case 13:d?p(10):f();break;case 16:p(1);break;case 15:case 14:break;default:return h}}}function p(h,$,V){if($===void 0&&($=[]),V===void 0&&(V=[]),E(h),$.length+V.length>0)for(var z=t.getToken();z!==17;){if($.indexOf(z)!==-1){g();break}else if(V.indexOf(z)!==-1)break;z=g()}}function C(h){var $=t.getTokenValue();return h?F($):i($),g(),!0}function b(){switch(t.getToken()){case 11:var h=t.getTokenValue(),$=Number(h);isNaN($)&&(p(2),$=0),F($);break;case 7:F(null);break;case 8:F(!0);break;case 9:F(!1);break;default:return!1}return g(),!0}function w(){return t.getToken()!==10?(p(3,[],[2,5]),!1):(C(!1),t.getToken()===6?(c(":"),g(),uu()||p(4,[],[2,5])):p(5,[],[2,5]),!0)}function y(){o(),g();for(var h=!1;t.getToken()!==2&&t.getToken()!==17;){if(t.getToken()===5){if(h||p(4,[],[]),c(","),g(),t.getToken()===2&&A)break}else h&&p(6,[],[]);w()||p(4,[],[2,5]),h=!0}return a(),t.getToken()!==2?p(7,[2],[]):g(),!0}function B(){s(),g();for(var h=!1;t.getToken()!==4&&t.getToken()!==17;){if(t.getToken()===5){if(h||p(4,[],[]),c(","),g(),t.getToken()===4&&A)break}else h&&p(6,[],[]);uu()||p(4,[],[4,5]),h=!0}return l(),t.getToken()!==4?p(8,[4],[]):g(),!0}function uu(){switch(t.getToken()){case 3:return B();case 1:return y();case 10:return C(!0);default:return b()}}return g(),t.getToken()===17?e.allowEmptyContent?!0:(p(4,[],[]),!1):uu()?(t.getToken()!==17&&p(9,[],[]),!0):(p(4,[],[]),!1)}var _t=jt;const DD=u=>K(/^[./]/.test(u)?u:`./${u}`);var xt=Object.defineProperty,kt=Object.defineProperties,St=Object.getOwnPropertyDescriptors,eD=Object.getOwnPropertySymbols,Tt=Object.prototype.hasOwnProperty,Nt=Object.prototype.propertyIsEnumerable,tD=(u,D,e)=>D in u?xt(u,D,{enumerable:!0,configurable:!0,writable:!0,value:e}):u[D]=e,I=(u,D)=>{for(var e in D||(D={}))Tt.call(D,e)&&tD(u,e,D[e]);if(eD)for(var e of eD(D))Nt.call(D,e)&&tD(u,e,D[e]);return u},It=(u,D)=>kt(u,St(D));function rD(u){var D,e;const t=P.default.realpathSync(u),r=m.default.dirname(t),n=P.default.readFileSync(u,"utf8").trim();let o={};if(n&&(o=_t(n),!o||typeof o!="object"))throw new SyntaxError(`Failed to parse JSON: ${u}`);if(o.extends){let i=o.extends;try{i=uD.resolve(i,{paths:[m.default.dirname(u)]})}catch(l){if(l.code==="MODULE_NOT_FOUND")try{i=uD.resolve(m.default.join(i,"tsconfig.json"),{paths:[m.default.dirname(u)]})}catch{}}const a=rD(i);if(delete a.references,(D=a.compilerOptions)!=null&&D.baseUrl){const{compilerOptions:l}=a;l.baseUrl=m.default.relative(r,m.default.join(m.default.dirname(i),l.baseUrl))}a.files&&(a.files=a.files.map(l=>m.default.relative(r,m.default.join(m.default.dirname(i),l)))),a.include&&(a.include=a.include.map(l=>m.default.relative(r,m.default.join(m.default.dirname(i),l)))),delete o.extends;const s=It(I(I({},a),o),{compilerOptions:I(I({},a.compilerOptions),o.compilerOptions)});a.watchOptions&&(s.watchOptions=I(I({},a.watchOptions),o.watchOptions)),o=s}if((e=o.compilerOptions)!=null&&e.baseUrl){const{compilerOptions:i}=o;i.baseUrl=DD(i.baseUrl)}if(o.files&&(o.files=o.files.map(DD)),o.include&&(o.include=o.include.map(K)),o.watchOptions){const{watchOptions:i}=o;i.excludeDirectories&&(i.excludeDirectories=i.excludeDirectories.map(a=>K(m.default.resolve(r,a))))}return o}function Rt(u=process.cwd(),D="tsconfig.json"){const e=$t(u,D);if(!e)return null;const t=rD(e);return{path:e,config:t}}const nD=Rt();var Lt=Object.defineProperty,Mt=Object.defineProperties,qt=Object.getOwnPropertyDescriptors,oD=Object.getOwnPropertySymbols,Wt=Object.prototype.hasOwnProperty,Ut=Object.prototype.propertyIsEnumerable,aD=(u,D,e)=>D in u?Lt(u,D,{enumerable:!0,configurable:!0,writable:!0,value:e}):u[D]=e,iD=(u,D)=>{for(var e in D||(D={}))Wt.call(D,e)&&aD(u,e,D[e]);if(oD)for(var e of oD(D))Ut.call(D,e)&&aD(u,e,D[e]);return u},sD=(u,D)=>Mt(u,qt(D));function Vt(u){const D=_D.createFilter(/\.([cm]?ts|[jt]sx)$/);return{name:"esbuild-transform",async transform(e,t){var r;if(!D(t))return null;const n=await pu.transform(e,sD(iD({},u),{loader:"default",sourcefile:t.replace(/\.[cm]ts/,".ts"),tsconfigRaw:(r=nD)==null?void 0:r.config}));return{code:n.code,map:n.map||null}}}}const zt=u=>{if(u==="es")return"esm";if(u==="cjs"||u==="iife")return u};function Gt(u){return{name:"esbuild-minify",async renderChunk(D,e,t){const r=await pu.transform(D,sD(iD({},u),{format:zt(t.format),minify:!0}));return{code:r.code,map:r.map||null}}}}const fu=(u,D)=>u[0]-D[0]||u[1]-D[1]||u[2]-D[2],lD=({target:u})=>{const D=u.some(e=>{var t,r;if(e=e.trim(),!e.startsWith("node"))return;const n=e.slice(4).split(".").map(Number),o=[n[0],(t=n[1])!=null?t:0,(r=n[2])!=null?r:0];return!(fu(o,[12,20,0])>=0&&fu(o,[13,0,0])<0||fu(o,[14,13,1])>=0)});return{name:"externalize-node-builtins",resolveId:e=>{const t=e.startsWith("node:");if(D&&t&&(e=e.slice(5)),du.builtinModules.includes(e)||t)return{id:e,external:!0}}}},Zt=u=>({name:"patch-binary",renderChunk(D,e,t){if(!e.isEntry||!e.facadeModuleId)return;const r=t.entryFileNames,n=`./${m.default.join(t.dir,r(e))}`;if(u.includes(n)){const o=new LD.default(D);return o.prepend(`#!/usr/bin/env node
33
- `),{code:o.toString(),map:t.sourcemap?o.generateMap({hires:!0}):void 0}}},async writeBundle(D,e){const t=D.entryFileNames,r=Object.values(e).map(async n=>{const o=n;if(o.isEntry&&o.facadeModuleId){const i=m.default.join(D.dir,t(o));await P.default.promises.chmod(i,493)}});await Promise.all(r)}});function FD(){const u=/\.(?:mjs|cjs)$/,D=/\.(?:mts|cts)$/;return{name:"resolve-typescript-mjs-cjs",resolveId(e,t,r){return u.test(e)&&t&&D.test(t)?this.resolve(e.replace(/js$/,"ts"),t,r):null}}}const cD=u=>u.split("?")[0],CD={async type(u){const D=await Promise.resolve().then(function(){return require("./rollup-plugin-dts-dd6ef765.js")});return{input:[],preserveEntrySignatures:"strict",plugins:[lD(u),FD(),D.default({respectExternal:!0})],output:[],external:[]}},app(u,D,e,t){const r={target:u.target};return{input:[],preserveEntrySignatures:"strict",plugins:[lD(u),FD(),ID.default({entries:D}),SD.default({extensions:[".mjs",".js",".ts",".jsx",".tsx",".json"]}),...Object.keys(e).length>0?[gu.default({preventAssignment:!0,objectGuards:!0,values:e})]:[],TD.default(),ND.default(),Vt(r),vt(),...u.minify?[Gt(r)]:[],Zt(t)],output:[],external:[]}}};async function Yt(u,D,e,t,r,n){const o=e.filter(({exportEntry:s})=>s.isExecutable).map(({exportEntry:s})=>s.outputPath),i=Object.create(null),a=Object.fromEntries(t.env.map(({key:s,value:l})=>[`process.env.${s}`,JSON.stringify(l)]));for(const{input:s,exportEntry:l}of e){if(l.type==="types"){let d=i.type;d||(d=await CD.type(t),d.external=n,i.type=d),d.input.push(s);const A=".d.ts";d.output=[{dir:D,entryFileNames:g=>P.default.realpathSync.native(cD(g.facadeModuleId)).slice(u.length).replace(/\.\w+$/,A),exports:"auto",format:"esm"}];continue}let F=i.app;F||(F=CD.app(t,r,a,o),F.external=n,i.app=F),F.input.includes(s)||F.input.push(s);const c=F.output,f=m.default.extname(l.outputPath),E=`${l.type}-${f}`;if(!c[E]){const d={dir:D,exports:"auto",format:l.type,chunkFileNames:`[name]-[hash]${f}`,plugins:[wt(l.type==="module")],entryFileNames:A=>P.default.realpathSync.native(cD(A.facadeModuleId)).slice(u.length).replace(/\.\w+$/,f)};c.push(d),c[E]=d}}return i}let k=!0;const R=typeof self!="undefined"?self:typeof window!="undefined"?window:typeof global!="undefined"?global:{};let fD=0;if(R.process&&R.process.env&&R.process.stdout){const{FORCE_COLOR:u,NODE_DISABLE_COLORS:D,TERM:e}=R.process.env;D||u==="0"?k=!1:u==="1"?k=!0:e==="dumb"?k=!1:"CI"in R.process.env&&["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI","GITHUB_ACTIONS","BUILDKITE","DRONE"].some(t=>t in R.process.env)?k=!0:k=process.stdout.isTTY,k&&(fD=e&&e.endsWith("-256color")?2:1)}let ED={enabled:k,supportLevel:fD};function Jt(u,D,e=1){const t=`\x1B[${u}m`,r=`\x1B[${D}m`,n=new RegExp(`\\x1b\\[${D}m`,"g");return o=>ED.enabled&&ED.supportLevel>=e?t+(""+o).replace(n,t)+r:""+o}const Ht=Jt(90,39),Kt=()=>new Date().toLocaleTimeString(),X=(...u)=>console.log(`[${Ht(Kt())}]`,...u);var pD,dD;const U=rt({name:"pkgroll",flags:{src:{type:String,description:"Source directory",default:"./src"},dist:{type:String,description:"Distribution directory",default:"./dist"},minify:{type:Boolean,description:"Minify output",alias:"m",default:!1},target:{type:[String],default:[`node${process.versions.node}`],description:"Environments to support. `target` in tsconfig.json is automatically added. Defaults to the current Node.js version.",alias:"t"},watch:{type:Boolean,description:"Watch mode",alias:"w",default:!1},env:{type:[function(D){const[e,t]=D.split("=");return{key:e,value:t}}],description:"Compile-time environment variables (eg. --env.NODE_ENV=production)"}},help:{description:"Minimalistic package bundler",render(u,D){return D.flagOperator=e=>e.name==="env"?".key=":" ",D.render(u)}}}),gD=process.cwd(),hD=H(U.flags.src,!0),mD=H(U.flags.dist,!0),BD=(dD=(pD=nD)==null?void 0:pD.config.compilerOptions)==null?void 0:dD.target;BD&&U.flags.target.push(BD),(async()=>{const u=await nt(gD),D=ct(u);if(D.length===0)throw new Error("No export entries found in package.json");const e=await Promise.all(D.map(async o=>({input:await dt(o,hD,mD),exportEntry:o}))),t=Et(u,gD),r=ft(u).filter(o=>!(o in t)).flatMap(o=>[o,new RegExp(`^${o}/`)]),n=await Yt(H(P.default.realpathSync.native(hD),!0),mD,e,U.flags,t,r);U.flags.watch?(X("Watch initialized"),Object.values(n).map(async o=>{Eu.watch(o).on("event",async a=>{a.code==="BUNDLE_START"&&X("Building",...Array.isArray(a.input)?a.input:[a.input]),a.code==="BUNDLE_END"&&(await Promise.all(o.output.map(s=>a.result.write(s))),X("Built",...Array.isArray(a.input)?a.input:[a.input])),a.code==="ERROR"&&X("Error:",a.error.message)})})):await Promise.all(Object.values(n).map(async o=>{const i=await Eu.rollup(o);return Promise.all(o.output.map(a=>i.write(a)))}))})().catch(u=>{console.error("Error:",u.message),process.exit(1)});
33
+ `),{code:o.toString(),map:t.sourcemap?o.generateMap({hires:!0}):void 0}}},async writeBundle(D,e){const t=D.entryFileNames,r=Object.values(e).map(async n=>{const o=n;if(o.isEntry&&o.facadeModuleId){const i=m.default.join(D.dir,t(o));await P.default.promises.chmod(i,493)}});await Promise.all(r)}});function FD(){const u=/\.(?:mjs|cjs)$/,D=/\.(?:mts|cts)$/;return{name:"resolve-typescript-mjs-cjs",resolveId(e,t,r){return u.test(e)&&t&&D.test(t)?this.resolve(e.replace(/js$/,"ts"),t,r):null}}}const cD=u=>u.split("?")[0],CD={async type(u){const D=await Promise.resolve().then(function(){return require("./rollup-plugin-dts-10a658a8.js")});return{input:[],preserveEntrySignatures:"strict",plugins:[lD(u),FD(),D.default({respectExternal:!0})],output:[],external:[]}},app(u,D,e,t){const r={target:u.target};return{input:[],preserveEntrySignatures:"strict",plugins:[lD(u),FD(),ID.default({entries:D}),SD.default({extensions:[".mjs",".js",".ts",".jsx",".tsx",".json"],exportConditions:u.exportCondition}),...Object.keys(e).length>0?[gu.default({preventAssignment:!0,objectGuards:!0,values:e})]:[],TD.default(),ND.default(),Vt(r),vt(),...u.minify?[Gt(r)]:[],Zt(t)],output:[],external:[]}}};async function Yt(u,D,e,t,r,n){const o=e.filter(({exportEntry:s})=>s.isExecutable).map(({exportEntry:s})=>s.outputPath),i=Object.create(null),a=Object.fromEntries(t.env.map(({key:s,value:l})=>[`process.env.${s}`,JSON.stringify(l)]));for(const{input:s,exportEntry:l}of e){if(l.type==="types"){let d=i.type;d||(d=await CD.type(t),d.external=n,i.type=d),d.input.push(s);const A=".d.ts";d.output=[{dir:D,entryFileNames:g=>P.default.realpathSync.native(cD(g.facadeModuleId)).slice(u.length).replace(/\.\w+$/,A),exports:"auto",format:"esm"}];continue}let F=i.app;F||(F=CD.app(t,r,a,o),F.external=n,i.app=F),F.input.includes(s)||F.input.push(s);const c=F.output,f=m.default.extname(l.outputPath),E=`${l.type}-${f}`;if(!c[E]){const d={dir:D,exports:"auto",format:l.type,chunkFileNames:`[name]-[hash]${f}`,plugins:[wt(l.type==="module")],entryFileNames:A=>P.default.realpathSync.native(cD(A.facadeModuleId)).slice(u.length).replace(/\.\w+$/,f)};c.push(d),c[E]=d}}return i}let k=!0;const R=typeof self!="undefined"?self:typeof window!="undefined"?window:typeof global!="undefined"?global:{};let fD=0;if(R.process&&R.process.env&&R.process.stdout){const{FORCE_COLOR:u,NODE_DISABLE_COLORS:D,TERM:e}=R.process.env;D||u==="0"?k=!1:u==="1"?k=!0:e==="dumb"?k=!1:"CI"in R.process.env&&["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI","GITHUB_ACTIONS","BUILDKITE","DRONE"].some(t=>t in R.process.env)?k=!0:k=process.stdout.isTTY,k&&(fD=e&&e.endsWith("-256color")?2:1)}let ED={enabled:k,supportLevel:fD};function Jt(u,D,e=1){const t=`\x1B[${u}m`,r=`\x1B[${D}m`,n=new RegExp(`\\x1b\\[${D}m`,"g");return o=>ED.enabled&&ED.supportLevel>=e?t+(""+o).replace(n,t)+r:""+o}const Ht=Jt(90,39),Kt=()=>new Date().toLocaleTimeString(),X=(...u)=>console.log(`[${Ht(Kt())}]`,...u);var pD,dD;const U=rt({name:"pkgroll",flags:{src:{type:String,description:"Source directory",default:"./src"},dist:{type:String,description:"Distribution directory",default:"./dist"},minify:{type:Boolean,description:"Minify output",alias:"m",default:!1},target:{type:[String],default:[`node${process.versions.node}`],description:"Environments to support. `target` in tsconfig.json is automatically added. Defaults to the current Node.js version.",alias:"t"},watch:{type:Boolean,description:"Watch mode",alias:"w",default:!1},env:{type:[function(D){const[e,t]=D.split("=");return{key:e,value:t}}],description:"Compile-time environment variables (eg. --env.NODE_ENV=production)"},exportCondition:{type:[String],description:"Export conditions for resolving dependency export and import maps (eg. --export-condition=node)"}},help:{description:"Minimalistic package bundler",render(u,D){return D.flagOperator=e=>e.name==="env"?".key=":" ",D.render(u)}}}),gD=process.cwd(),hD=H(U.flags.src,!0),mD=H(U.flags.dist,!0),BD=(dD=(pD=nD)==null?void 0:pD.config.compilerOptions)==null?void 0:dD.target;BD&&U.flags.target.push(BD),(async()=>{const u=await nt(gD),D=ct(u);if(D.length===0)throw new Error("No export entries found in package.json");const e=await Promise.all(D.map(async o=>({input:await dt(o,hD,mD),exportEntry:o}))),t=Et(u,gD),r=ft(u).filter(o=>!(o in t)).flatMap(o=>[o,new RegExp(`^${o}/`)]),n=await Yt(H(P.default.realpathSync.native(hD),!0),mD,e,U.flags,t,r);U.flags.watch?(X("Watch initialized"),Object.values(n).map(async o=>{Eu.watch(o).on("event",async a=>{a.code==="BUNDLE_START"&&X("Building",...Array.isArray(a.input)?a.input:[a.input]),a.code==="BUNDLE_END"&&(await Promise.all(o.output.map(s=>a.result.write(s))),X("Built",...Array.isArray(a.input)?a.input:[a.input])),a.code==="ERROR"&&X("Error:",a.error.message)})})):await Promise.all(Object.values(n).map(async o=>{const i=await Eu.rollup(o);return Promise.all(o.output.map(a=>i.write(a)))}))})().catch(u=>{console.error(u),process.exit(1)});
@@ -1,4 +1,4 @@
1
- "use strict";var Q=Object.defineProperty,Z=Object.defineProperties;var X=Object.getOwnPropertyDescriptors;var O=Object.getOwnPropertySymbols;var ee=Object.prototype.hasOwnProperty,te=Object.prototype.propertyIsEnumerable;var V=(i,e,t)=>e in i?Q(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,I=(i,e)=>{for(var t in e||(e={}))ee.call(e,t)&&V(i,t,e[t]);if(O)for(var t of O(e))te.call(e,t)&&V(i,t,e[t]);return i},K=(i,e)=>Z(i,X(e));var re=require("module"),ne=require("path"),ie=require("magic-string");function se(i){return i&&typeof i=="object"&&"default"in i?i:{default:i}}function ae(i){if(i&&i.__esModule)return i;var e=Object.create(null);return i&&Object.keys(i).forEach(function(t){if(t!=="default"){var n=Object.getOwnPropertyDescriptor(i,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:function(){return i[t]}})}}),e.default=i,Object.freeze(e)}var T=ae(ne),oe=se(ie),M=require;function ce(){const i=process.cwd();try{return M.resolve("typescript",{paths:[i]})}catch{throw new Error(`Could not find \`typescript\` in ${i}`)}}var r=M(ce());const L=".d.ts",R={getCurrentDirectory:()=>r.sys.getCurrentDirectory(),getNewLine:()=>r.sys.newLine,getCanonicalFileName:r.sys.useCaseSensitiveFileNames?i=>i:i=>i.toLowerCase()},le={declaration:!0,noEmit:!1,emitDeclarationOnly:!0,noEmitOnError:!0,checkJs:!1,declarationMap:!1,skipLibCheck:!0,preserveSymlinks:!0,target:r.ScriptTarget.ESNext};function q(i,e){const t=I(I({},le),e);let n=T.dirname(i),s=[];const o=r.findConfigFile(n,r.sys.fileExists);if(!o)return{dtsFiles:s,dirName:n,compilerOptions:t};n=T.dirname(o);const{config:p,error:c}=r.readConfigFile(o,r.sys.readFile);if(c)return console.error(r.formatDiagnostic(c,R)),{dtsFiles:s,dirName:n,compilerOptions:t};const{fileNames:l,options:m,errors:f}=r.parseJsonConfigFileContent(p,r.sys,n);return s=l.filter(d=>d.endsWith(L)),f.length?(console.error(r.formatDiagnostics(f,R)),{dtsFiles:s,dirName:n,compilerOptions:t}):{dtsFiles:s,dirName:n,compilerOptions:I(I({},m),t)}}function pe(i,e){const{dtsFiles:t,compilerOptions:n}=q(i,e);return r.createProgram([i].concat(Array.from(t)),n,r.createCompilerHost(n,!0))}function fe(i,e){const t=[];let n=[],s=new Set,o="",p={};for(let c of i){if(c.endsWith(L))continue;c=T.resolve(c);const l=q(c,e);if(l.dtsFiles.forEach(s.add,s),!n.length){n.push(c),{dirName:o,compilerOptions:p}=l;continue}if(l.dirName===o)n.push(c);else{const m=r.createCompilerHost(p,!0),f=r.createProgram(n.concat(Array.from(s)),p,m);t.push(f),n=[c],{dirName:o,compilerOptions:p}=l}}if(n.length){const c=r.createCompilerHost(p,!0),l=r.createProgram(n.concat(Array.from(s)),p,c);t.push(l)}return t}function ue(){let i;try{return{codeFrameColumns:i}=M("@babel/code-frame"),i}catch{try{return{codeFrameColumns:i}=re.createRequire(typeof document=="undefined"?new(require("url")).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("rollup-plugin-dts-dd6ef765.js",document.baseURI).href)("@babel/code-frame"),i}catch{}}}function me(i){const e=i.getSourceFile(),t=e.getLineAndCharacterOfPosition(i.getStart()),n=e.getLineAndCharacterOfPosition(i.getEnd());return{start:{line:t.line+1,column:t.character+1},end:{line:n.line+1,column:n.character+1}}}function de(i){const e=ue(),n=i.getSourceFile().getFullText(),s=me(i);return e?`
1
+ "use strict";var Q=Object.defineProperty,Z=Object.defineProperties;var X=Object.getOwnPropertyDescriptors;var O=Object.getOwnPropertySymbols;var ee=Object.prototype.hasOwnProperty,te=Object.prototype.propertyIsEnumerable;var V=(i,e,t)=>e in i?Q(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,I=(i,e)=>{for(var t in e||(e={}))ee.call(e,t)&&V(i,t,e[t]);if(O)for(var t of O(e))te.call(e,t)&&V(i,t,e[t]);return i},K=(i,e)=>Z(i,X(e));var re=require("module"),ne=require("path"),ie=require("magic-string");function se(i){return i&&typeof i=="object"&&"default"in i?i:{default:i}}function ae(i){if(i&&i.__esModule)return i;var e=Object.create(null);return i&&Object.keys(i).forEach(function(t){if(t!=="default"){var n=Object.getOwnPropertyDescriptor(i,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:function(){return i[t]}})}}),e.default=i,Object.freeze(e)}var T=ae(ne),oe=se(ie),M=require;function ce(){const i=process.cwd();try{return M.resolve("typescript",{paths:[i]})}catch{throw new Error(`Could not find \`typescript\` in ${i}`)}}var r=M(ce());const L=".d.ts",R={getCurrentDirectory:()=>r.sys.getCurrentDirectory(),getNewLine:()=>r.sys.newLine,getCanonicalFileName:r.sys.useCaseSensitiveFileNames?i=>i:i=>i.toLowerCase()},le={declaration:!0,noEmit:!1,emitDeclarationOnly:!0,noEmitOnError:!0,checkJs:!1,declarationMap:!1,skipLibCheck:!0,preserveSymlinks:!0,target:r.ScriptTarget.ESNext};function q(i,e){const t=I(I({},le),e);let n=T.dirname(i),s=[];const o=r.findConfigFile(n,r.sys.fileExists);if(!o)return{dtsFiles:s,dirName:n,compilerOptions:t};n=T.dirname(o);const{config:p,error:c}=r.readConfigFile(o,r.sys.readFile);if(c)return console.error(r.formatDiagnostic(c,R)),{dtsFiles:s,dirName:n,compilerOptions:t};const{fileNames:l,options:m,errors:f}=r.parseJsonConfigFileContent(p,r.sys,n);return s=l.filter(d=>d.endsWith(L)),f.length?(console.error(r.formatDiagnostics(f,R)),{dtsFiles:s,dirName:n,compilerOptions:t}):{dtsFiles:s,dirName:n,compilerOptions:I(I({},m),t)}}function pe(i,e){const{dtsFiles:t,compilerOptions:n}=q(i,e);return r.createProgram([i].concat(Array.from(t)),n,r.createCompilerHost(n,!0))}function fe(i,e){const t=[];let n=[],s=new Set,o="",p={};for(let c of i){if(c.endsWith(L))continue;c=T.resolve(c);const l=q(c,e);if(l.dtsFiles.forEach(s.add,s),!n.length){n.push(c),{dirName:o,compilerOptions:p}=l;continue}if(l.dirName===o)n.push(c);else{const m=r.createCompilerHost(p,!0),f=r.createProgram(n.concat(Array.from(s)),p,m);t.push(f),n=[c],{dirName:o,compilerOptions:p}=l}}if(n.length){const c=r.createCompilerHost(p,!0),l=r.createProgram(n.concat(Array.from(s)),p,c);t.push(l)}return t}function ue(){let i;try{return{codeFrameColumns:i}=M("@babel/code-frame"),i}catch{try{return{codeFrameColumns:i}=re.createRequire(typeof document=="undefined"?new(require("url")).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("rollup-plugin-dts-10a658a8.js",document.baseURI).href)("@babel/code-frame"),i}catch{}}}function me(i){const e=i.getSourceFile(),t=e.getLineAndCharacterOfPosition(i.getStart()),n=e.getLineAndCharacterOfPosition(i.getEnd());return{start:{line:t.line+1,column:t.character+1},end:{line:n.line+1,column:n.character+1}}}function de(i){const e=ue(),n=i.getSourceFile().getFullText(),s=me(i);return e?`
2
2
  `+e(n,s,{highlightCode:!0}):`
3
3
  ${s.start.line}:${s.start.column}: \`${i.getFullText().trim()}\``}class h extends Error{constructor(e,t="Syntax not yet supported"){super(`${t}
4
4
  ${de(e)}`)}}class ye{constructor(e){this.sourceFile=e}findNamespaces(){const e=[],t={};for(const n of this.sourceFile.statements){const s={start:n.getStart(),end:n.getEnd()};if(r.isEmptyStatement(n)){e.unshift({name:"",exports:[],location:s});continue}if((r.isImportDeclaration(n)||r.isExportDeclaration(n))&&n.moduleSpecifier&&r.isStringLiteral(n.moduleSpecifier)){let{text:f}=n.moduleSpecifier;if(f.startsWith(".")&&(f.endsWith(".d.ts")||f.endsWith(".d.cts")||f.endsWith(".d.mts"))){let d=n.moduleSpecifier.getStart()+1,w=n.moduleSpecifier.getEnd()-1;e.unshift({name:"",exports:[],location:{start:d,end:w},textBeforeCodeAfter:f.replace(/\.d\.ts$/,".js").replace(/\.d\.cts$/,".cjs").replace(/\.d\.mts$/,".mjs")})}}if(r.isModuleDeclaration(n)&&n.body&&r.isModuleBlock(n.body)){for(const f of n.body.statements)if(r.isExportDeclaration(f)&&f.exportClause){if(r.isNamespaceExport(f.exportClause))continue;for(const d of f.exportClause.elements)d.propertyName&&d.propertyName.getText()==d.name.getText()&&e.unshift({name:"",exports:[],location:{start:d.propertyName.getEnd(),end:d.name.getEnd()}})}}if(r.isClassDeclaration(n)?t[n.name.getText()]={type:"class",generics:n.typeParameters}:r.isFunctionDeclaration(n)?t[n.name.getText()]={type:"function"}:r.isInterfaceDeclaration(n)?t[n.name.getText()]={type:"interface",generics:n.typeParameters}:r.isTypeAliasDeclaration(n)?t[n.name.getText()]={type:"type",generics:n.typeParameters}:r.isModuleDeclaration(n)&&r.isIdentifier(n.name)?t[n.name.getText()]={type:"namespace"}:r.isEnumDeclaration(n)&&(t[n.name.getText()]={type:"enum"}),!r.isVariableStatement(n))continue;const{declarations:o}=n.declarationList;if(o.length!==1)continue;const p=o[0],c=p.name.getText();if(!p.initializer||!r.isCallExpression(p.initializer)){t[c]={type:"var"};continue}const l=p.initializer.arguments[0];if(!p.initializer.expression.getFullText().includes("/*#__PURE__*/Object.freeze")||!r.isObjectLiteralExpression(l))continue;const m=[];for(const f of l.properties){if(!r.isPropertyAssignment(f)||!(r.isIdentifier(f.name)||r.isStringLiteral(f.name))||f.name.text!=="__proto__"&&!r.isIdentifier(f.initializer))throw new h(f,"Expected a property assignment");f.name.text!=="__proto__"&&m.push({exportedName:f.name.text,localName:f.initializer.getText()})}e.unshift({name:c,exports:m,location:s})}return{namespaces:e,itemTypes:t}}fix(){var e;let t=this.sourceFile.getFullText();const{namespaces:n,itemTypes:s}=this.findNamespaces();for(const o of n){const p=t.slice(o.location.end);t=t.slice(0,o.location.start);for(const{exportedName:c,localName:l}of o.exports)if(c===l){const{type:m,generics:f}=s[l]||{};if(m==="interface"||m==="type"){const d=U(f);t+=`type ${o.name}_${c}${d.in} = ${l}${d.out};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pkgroll",
3
- "version": "1.1.3",
3
+ "version": "1.2.2",
4
4
  "description": "Zero-config rollup bundler",
5
5
  "keywords": [
6
6
  "zero config",
@@ -66,7 +66,7 @@
66
66
  "rollup": "^2.70.2"
67
67
  },
68
68
  "devDependencies": {
69
- "@pvtnbr/eslint-config": "^0.20.0",
69
+ "@pvtnbr/eslint-config": "^0.20.1",
70
70
  "@types/node": "^17.0.30",
71
71
  "@types/rimraf": "^3.0.2",
72
72
  "cleye": "^1.2.0",