@visulima/packem 2.0.0-alpha.29 → 2.0.0-alpha.30
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/CHANGELOG.md +7 -0
- package/dist/builder/typedoc/index.js +3 -3
- package/dist/cli/index.js +24 -24
- package/dist/index.js +1 -1
- package/dist/packem_shared/default-Bi3Aj6a9.js +1 -0
- package/dist/packem_shared/{default-D78T-lZt.js → default-CTae39UA.js} +1 -1
- package/dist/packem_shared/{default-BGHvCOQE.js → default-C_x8DHoD.js} +1 -1
- package/dist/packem_shared/{default-DwVph-yx.js → default-YwldmWl4.js} +1 -1
- package/dist/packem_shared/esbuildPlugin-BrFhdKJk-C8Y7RuGP.js +3 -0
- package/dist/packem_shared/{index-8sc8c1Ye.js → index-dFhGUj4X.js} +58 -57
- package/dist/packem_shared/isolatedDeclarationsTypescriptTransformer-DkuEkofo-BCM0B079.js +3 -0
- package/dist/packem_shared/oxcResolvePlugin-BJpi-eSG-RVsiMbfI.js +1 -0
- package/dist/packem_shared/{resolveTypescriptMjsCtsPlugin-DcZrZTmM-C40Ff4h5.js → resolveTypescriptMjsCtsPlugin-DcZrZTmM-DYkwKhiN.js} +2 -2
- package/dist/rollup/plugins/esbuild/index.js +1 -1
- package/dist/rollup/plugins/sucrase/index.js +1 -1
- package/dist/rollup/plugins/typescript/isolated-declarations-typescript-transformer.js +1 -1
- package/package.json +2 -2
- package/dist/packem_shared/default-BM-KR0tJ.js +0 -1
- package/dist/packem_shared/esbuildPlugin-BrFhdKJk-BzTGlVjw.js +0 -3
- package/dist/packem_shared/isolatedDeclarationsTypescriptTransformer-DkuEkofo-CAV3IRk9.js +0 -3
- package/dist/packem_shared/oxcResolvePlugin-BJpi-eSG-D88S5wUe.js +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## @visulima/packem [2.0.0-alpha.30](https://github.com/visulima/packem/compare/@visulima/packem@2.0.0-alpha.29...@visulima/packem@2.0.0-alpha.30) (2025-10-14)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Dependencies
|
|
5
|
+
|
|
6
|
+
* **@visulima/packem-rollup:** upgraded to 1.0.0-alpha.23
|
|
7
|
+
|
|
1
8
|
## @visulima/packem [2.0.0-alpha.29](https://github.com/visulima/packem/compare/@visulima/packem@2.0.0-alpha.28...@visulima/packem@2.0.0-alpha.29) (2025-10-12)
|
|
2
9
|
|
|
3
10
|
### Bug Fixes
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var
|
|
2
|
-
${
|
|
3
|
-
`),e.logger.info({message:`Using ${
|
|
1
|
+
var v=Object.defineProperty;var f=(e,o)=>v(e,"name",{value:o,configurable:!0});import{createRequire as E}from"node:module";import{cyan as P}from"@visulima/colorize";import{join as y}from"@visulima/path";import{p as A,d as T}from"../../packem_shared/create-or-update-key-storage-GwAIWW7R.js";import{readFileSync as j,writeFileSync as R}from"@visulima/fs";import{Application as C}from"typedoc";const $=E(import.meta.url),l=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,b=f(e=>{if(typeof l<"u"&&l.versions&&l.versions.node){const[o,r]=l.versions.node.split(".").map(Number);if(o>22||o===22&&r>=3||o===20&&r>=16)return l.getBuiltinModule(e)}return $(e)},"__cjs_getBuiltinModule"),{readdirSync:F}=b("node:fs");var q=Object.defineProperty,D=f((e,o)=>q(e,"name",{value:o,configurable:!0}),"w");const M=D(async(e,o,r,a)=>{if(o.length===0)return;const{format:t,jsonFileName:n,marker:i,output:N,plugin:k,readmePath:p,...w}=e;if(t==="inline"&&p===void 0)throw new Error("The `readmePath` option is required when using the `inline` format.");if(t!=="inline"&&typeof p=="string"&&a.warn({message:"The `readmePath` option is only used when the `inline` format is used.",prefix:"typedoc"}),t==="json"){if(n===void 0)throw new Error("The `jsonFileName` option is required when using the `json` format.");if(!n.endsWith(".json"))throw new Error("The `jsonFileName` option must end with `.json`.")}t!=="json"&&typeof n=="string"&&a.warn({message:"The `jsonFileName` option is only used when the `json` format is used.",prefix:"typedoc"});const _=o.map(g=>g.input),m=k??[];m.push("typedoc-plugin-rename-defaults"),(t==="inline"||t==="markdown")&&m.push("typedoc-plugin-markdown");const d=await C.bootstrapWithPlugins({...w,compilerOptions:{allowJs:!0,declaration:!1,declarationMap:!1,esModuleInterop:!0,module:99,moduleResolution:100,noEmit:!0,noImplicitAny:!1,skipLibCheck:!0,sourceMap:!1,target:99,...w.compilerOptions},entryPoints:_,hideGenerator:!0,out:r,plugin:m,...t==="inline"?{hideBreadcrumbs:!0,hidePageHeader:!0,navigation:!1,outputFileStrategy:"modules",useCodeBlocks:!0}:{}},[]),c=await d.convert();if(c){if(t==="json")await d.generateJson(c,n);else if(t==="html")await d.generateDocs(c,r);else if(await d.generateOutputs(c),t==="inline"){if(i===void 0)throw new Error("The `marker` option is required when using the `inline` format.");const g=F(r,{withFileTypes:!0}).filter(s=>s.isFile());let h="";for(const s of g)s.name==="README.md"&&o.length>1||(h+=j(y(r,s.name)).replaceAll(`<!-- ${i}`,`<!-- _REPLACE_${i}`).replaceAll("<!-- ${marker}",`<!-- _REPLACE_\\${i}`));if(h!==""){const s=j(p),u=A(s,i,`
|
|
2
|
+
${h}`);if(!u){a.error({message:`Could not find the typedoc marker: <!-- ${i} --><!-- /${i} --> in ${p}`,prefix:"typedoc"});return}if(s===u)return;u&&R(p,u.replaceAll(`<!-- _REPLACE_${i}`,`<!-- ${i}`).replaceAll(`<!-- _REPLACE_\\${i}`,"<!-- ${marker}"),{overwrite:!0})}}}},"generateReferenceDocumentation");var x=Object.defineProperty,L=f((e,o)=>x(e,"name",{value:o,configurable:!0}),"r");const G=L(async(e,o,r,a)=>{if(e.options.typedoc&&e.options.typedoc.format!==void 0){let t="unknown";e.pkg.dependencies?.typedoc?t=e.pkg.dependencies.typedoc:e.pkg.devDependencies?.typedoc&&(t=e.pkg.devDependencies.typedoc),o&&T("typedoc",o,e.logger,!0),a&&e.logger.raw(`
|
|
3
|
+
`),e.logger.info({message:`Using ${P("typedoc")} ${t} to generate reference documentation`,prefix:"typedoc"}),await e.hooks.callHook("typedoc:before",e);let n=e.options.rootDir;e.options.typedoc.output?n=e.options.typedoc.output:e.options.typedoc.format==="inline"&&o?n=y(o,"typedoc"):e.options.typedoc.format!=="json"&&(n=y(n,"api-docs")),await M(e.options.typedoc,e.options.entries,n,e.logger),await e.hooks.callHook("typedoc:done",e)}},"builder");export{G as default};
|
package/dist/cli/index.js
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var ce=Object.defineProperty;var w=(s,t)=>ce(s,"name",{value:t,configurable:!0});import{createRequire as
|
|
2
|
+
var ce=Object.defineProperty;var w=(s,t)=>ce(s,"name",{value:t,configurable:!0});import{createRequire as pe}from"node:module";import de from"@visulima/cerebro";import{SimpleReporter as ue}from"@visulima/pail/reporter";import{installPackage as _}from"@antfu/install-pkg";import{spinner as J,select as S,multiselect as te,confirm as h,intro as fe,log as X,cancel as ye,outro as ge}from"@clack/prompts";import{isAccessible as ve,readFile as be,writeFile as we,isAccessibleSync as x,collectSync as he,writeJsonSync as $e,writeFileSync as ke}from"@visulima/fs";import{join as C,resolve as P,extname as oe,toNamespacedPath as Se}from"@visulima/path";import{t as N,E as G,e as xe,N as ie,_ as Ce,c as De}from"../packem_shared/index-CUp9WuCG.js";import{createJiti as Pe}from"jiti";import{cyan as Te,bold as V,gray as Me}from"@visulima/colorize";import{e as Ie,i as H,c as Be,x as Le}from"../packem_shared/index-dFhGUj4X.js";import{parsePackageJson as Ne}from"@visulima/package/package-json";import __cjs_mod__ from "node:module"; // -- packem CommonJS require shim --
|
|
3
3
|
const require = __cjs_mod__.createRequire(import.meta.url);
|
|
4
|
-
const
|
|
4
|
+
const U=pe(import.meta.url),E=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,se=w(s=>{if(typeof E<"u"&&E.versions&&E.versions.node){const[t,e]=E.versions.node.split(".").map(Number);if(t>22||t===22&&e>=3||t===20&&e>=16)return E.getBuiltinModule(s)}return U(s)},"__cjs_getBuiltinModule"),{cwd:z,exit:me}=E,je=U("magic-string"),{defu:Ee}=U("defu"),Oe=se("node:fs/promises"),Y=se("node:path/posix"),Ke="@visulima/packem",qe="2.0.0-alpha.29";var Ae=Object.defineProperty,Re=w((s,t)=>Ae(s,"name",{value:t,configurable:!0}),"t$2");const ne=Re(async(s,t="")=>{let e=t;if(!e){const r=["packem.config.js","packem.config.mjs","packem.config.cjs","packem.config.ts","packem.config.cts","packem.config.mts"];for(const a of r)if(await ve(C(s,a))){e=`./${a}`;break}}if(!/\.(?:js|mjs|cjs|ts|cts|mts)$/.test(e))throw new Error("Invalid packem config file extension. Only .js, .mjs, .cjs, .ts, .cts and .mts extensions are allowed.");return e},"findPackemFile"),ae={less:["less"],lightningcss:["lightningcss"],"node-sass":["node-sass"],postcss:["postcss","postcss-load-config","postcss-modules-extract-imports","postcss-modules-local-by-default","postcss-modules-scope","postcss-modules-values","postcss-value-parser","@csstools/css-parser-algorithms","@csstools/css-tokenizer","@csstools/postcss-slow-plugins","icss-utils","@visulima/css-style-inject"],sass:["sass"],"sass-embedded":["sass-embedded"],stylus:["stylus"],tailwindcss:["@tailwindcss/node","@tailwindcss/oxide","tailwindcss"]};var Ve=Object.defineProperty,Z=w((s,t)=>Ve(s,"name",{value:t,configurable:!0}),"g");const _e=["typedoc","typedoc-plugin-markdown","typedoc-plugin-rename-defaults"],Je=Z(s=>{s.addCommand({argument:{description:"Add a packem feature to your project",name:"feature",required:!0},description:"Add a optional packem feature to your project",execute:Z(async({argument:t,logger:e,options:r})=>{const a=J(),o=P(z(),r.dir??".");let p;try{p=await ne(o,r.config)}catch{e.error("Could not find a packem config file, please run `packem init` first.");return}const u=await be(p,{buffer:!1});let y="cjs";u.includes("import")&&(y="esm");const i=new je(u),m=" transformer,";let n=" transformer";if(u.includes(" transformer,")&&(n=" transformer,"),t.includes("typedoc")){if(u.includes("typedoc: typedocBuilder")||u.includes("@visulima/packem/builder/typedoc")){e.warn("Typedoc has already been added to the packem config.");return}y==="cjs"?i.prepend(`const typedocBuilder = require("@visulima/packem/builder/typedoc");
|
|
5
5
|
`):i.prepend(`import typedocBuilder from "@visulima/packem/builder/typedoc";
|
|
6
6
|
`),u.includes("builder: {")?i.replace("builder: {",`builder: {
|
|
7
7
|
typedoc: typedocBuilder,
|
|
8
8
|
`):i.replace(n,`${m}
|
|
9
9
|
builder: {
|
|
10
10
|
typedoc: typedocBuilder,
|
|
11
|
-
},`),e.info("Adding typedoc dependencies..."),a.start("Installing packages"),await
|
|
12
|
-
Typedoc added!`)}if(t.includes("css")){if(u.includes("css: {")||u.includes("@visulima/packem/css")){e.warn("Css loaders have already been added to the packem config.");return}const
|
|
11
|
+
},`),e.info("Adding typedoc dependencies..."),a.start("Installing packages"),await _(_e,{cwd:o,dev:!0,silent:!0}),a.stop("Installed packages"),e.success(`
|
|
12
|
+
Typedoc added!`)}if(t.includes("css")){if(u.includes("css: {")||u.includes("@visulima/packem/css")){e.warn("Css loaders have already been added to the packem config.");return}const c=[],g=await S({message:"Pick a css loader",options:[{label:"PostCSS",value:"postcss"},{hint:"experimental",label:"Lightning CSS",value:"lightningcss"},{hint:"Tailwind Css Oxide",label:"Tailwind CSS",value:"tailwindcss"}]});if(c.push(g),g!=="tailwindcss"){let f=await te({message:"Pick extra loaders",options:[{label:"Sass",value:"sass"},{label:"Stylus",value:"stylus"},{label:"Less",value:"less"}],required:!1});if(f.includes("sass")){const $=await S({message:"Pick a sass loader",options:[{hint:"recommended",label:"Sass embedded",value:"sass-embedded"},{label:"Sass",value:"sass"},{hint:"legacy",label:"Node Sass",value:"node-sass"}]});$!=="sass"&&(f=f.filter(D=>D!=="sass"),f.push($))}c.push(...f)}const v=[];for(const f of c)v.push(...ae[f]);g!=="tailwindcss"&&c.push("sourceMap");for(let f of c)(f==="sass-embedded"||f==="node-sass")&&(f="sass"),y==="cjs"?i.prepend(`const ${f}Loader = require("@visulima/packem/css/loader/${f.toLowerCase()}");
|
|
13
13
|
`):i.prepend(`import ${f}Loader from "@visulima/packem/css/loader/${f.toLowerCase()}";
|
|
14
|
-
`);const d=await h({initialValue:!1,message:"Do you want to minify your css?"});let
|
|
15
|
-
`):i.prepend(`import ${
|
|
16
|
-
`));const
|
|
17
|
-
css: {${
|
|
18
|
-
minifier: ${
|
|
19
|
-
loaders: [${
|
|
14
|
+
`);const d=await h({initialValue:!1,message:"Do you want to minify your css?"});let l;d&&(l=await S({message:"Pick a css minifier",options:[{label:"CSSNano",value:"cssnano"},{label:"Lightning CSS",value:"lightningcss"}]}),c.includes("lightningcss")||v.push(l),y==="cjs"?i.prepend(`const ${l}Minifier = require("@visulima/packem/css/minifier/${l.toLowerCase()}");
|
|
15
|
+
`):i.prepend(`import ${l}Minifier from "@visulima/packem/css/minifier/${l.toLowerCase()}";
|
|
16
|
+
`));const b=c.map(f=>((f==="sass-embedded"||f==="node-sass")&&(f="sass"),`${f}Loader`)).join(", ");u.includes("rollup: {")?i.replace("rollup: {",`rollup: {
|
|
17
|
+
css: {${l?`
|
|
18
|
+
minifier: ${l}Minifier,`:""}
|
|
19
|
+
loaders: [${b}],
|
|
20
20
|
},
|
|
21
21
|
`):i.replace(n,`${m}
|
|
22
22
|
rollup: {
|
|
23
|
-
css: {${
|
|
24
|
-
minifier: ${
|
|
25
|
-
loaders: [${
|
|
23
|
+
css: {${l?`
|
|
24
|
+
minifier: ${l}Minifier,`:""}
|
|
25
|
+
loaders: [${b}],
|
|
26
26
|
},
|
|
27
|
-
},`),a.start("Installing packages"),await
|
|
28
|
-
CSS loaders added!`)}await we(p,i.toString(),{overwrite:!0})},"execute"),name:"add",options:[{defaultValue:".",description:"The directory to build",name:"dir",type:String},{description:"Use a custom config file",name:"config",type:String}]})},"createAddCommand");var Ge=Object.defineProperty,Fe=w((s,t)=>Ge(s,"name",{value:t,configurable:!0}),"e$1");const Ue=Fe(async(s,t,e,r,a)=>{const o=await ie(t,a);let p=await s.import(o,{default:!0,try:!0})||{};return typeof p=="function"&&(p=await p(e,r)),{config:p,path:o}},"loadPackemConfig");var ze=Object.defineProperty,j=w((s,t)=>ze(s,"name",{value:t,configurable:!0}),"u$1");const G=new Map,We=/\.[^./]+$/,Xe=j(async s=>{try{return await Oe.readdir(s,{withFileTypes:!0})}catch(t){const{code:e}=t;if(e==="ENOENT")return[];throw t}},"safeReaddir"),ae=j(async(s,t)=>{const e=await Xe(s);return(await Promise.all(e.map(async r=>{const a=H.join(s,r.name);return r.isDirectory()?ae(a,t):r.isFile()?H.relative(t,a):[]}))).flat()},"getDirectoryFilesRecursive"),He=j(async s=>{let t=G.get(s);return t||(t=ae(s,s),G.set(s,t)),t},"getDirectoryFiles"),Ye=j((s,t)=>{const e=s.replace(We,"");if(t==="*"){const p=e.split("/");return p.length>0?[p[0]]:null}const r=t.replaceAll(/[.+?^${}()|[\]\\]/g,String.raw`\$&`).replaceAll("*","(.*)"),a=new RegExp(`^${r}$`),o=e.match(a);return o?o.slice(1):null},"matchWildcardPattern"),Ze=j((s,t)=>{let e=s;for(const r of t)e=e.replace("*",r);return e},"substituteWildcards"),Qe=j((s,t)=>s.key==="exports"&&s.subKey===O?O:s.key==="exports"&&s.subKey===J?J:t,"getEnvironment"),L=j((s,t,e,r,a,o,p)=>{const u=Qe(a,o.environment);let y=o.options.runtime;for(const n of xe)if(a.file.includes(`.${n}.`)||a.subKey===n){y=n;break}let i=s.find(n=>n.input===t&&n.environment===u&&n.runtime===y);i===void 0?i=s[s.push({environment:u,exportKey:new Set([a.exportKey].filter(Boolean)),input:t,runtime:y})-1]:i.exportKey&&a.exportKey&&i.exportKey.add(a.exportKey),p&&(i.isGlob=!0),e&&(i.outDir=r),a.isExecutable?(i.executable=!0,i.declaration=!1,a.type==="cjs"?i.cjs=!0:a.type==="esm"&&(i.esm=!0)):(/\.d\.[mc]?ts$/.test(a.file)&&o.options.declaration!==!1&&(i.declaration=o.options.declaration),a.type==="cjs"?i.cjs=!0:a.type==="esm"&&(i.esm=!0));const m=a.file.replace(te(a.file),"").replace(new RegExp(`^./${o.options.outDir.replace(/^\.\//,"")}/`),"");oe.has(a.subKey)&&!t.includes(m)&&(i.fileAlias=m)},"createOrUpdateEntry");let Z=!1;const Q=j(s=>{if(s.pkg?.dependencies?.typescript===void 0&&s.pkg?.devDependencies?.typescript===void 0)throw new Error("You tried to use a `.ts`, `.cts` or `.mts` file but `typescript` was not found in your package.json.")},"validateIfTypescriptIsInstalled"),es=j(async(s,t,e)=>{const r=s.types||s.typings;G.clear();const a=(e.options.outputExtensionMap?.cjs??"cjs").replaceAll(".",String.raw`\.`),o=(e.options.outputExtensionMap?.esm??"mjs").replaceAll(".",String.raw`\.`),p=[];t.sort((n,l)=>n.split("/").length-l.split("/").length);const u=s.type==="module"?"esm":"cjs";u==="esm"&&(e.options.emitESM=!0),u==="cjs"&&(e.options.emitCJS=!0);const y=e.options.emitCJS&&e.options.emitESM;e.options.declaration===void 0&&(e.options.declaration=y?"compatible":"node16");const i=Ie(s.exports,u,e.options.declaration,[],e.options.ignoreExportKeys).filter(n=>!n.ignored);if(s.bin){const n=(typeof s.bin=="string"?[s.bin]:Object.values(s.bin)).filter(Boolean);for(const l of n){const g=X(l);if(g&&g!==u)throw new Error(`Exported file "${l}" has an extension that does not match the package.json type "${s.type??"commonjs"}".`);i.push({file:l,isExecutable:!0,key:"bin",type:g??u})}}s.main&&i.push({file:s.main,key:"main",type:X(s.main)??u}),s.module&&i.push({file:s.module,key:"module",type:"esm"}),r&&(Q(e),(e.options.declaration===void 0||e.options.declaration==="node16")&&y&&(e.options.declaration="compatible"),i.push({file:s.types??s.typings,key:"types"}));const m=[];for await(const n of i){const l=te(n.file);if(l!==""&&!Ce.includes(l))continue;if(e.options.emitCJS===void 0&&n.type==="cjs"&&(e.options.emitCJS=!0),e.options.emitESM===void 0&&n.type==="esm"&&(e.options.emitESM=!0),e.options.declaration===void 0||e.options.declaration==="node16"){const k=e.options.emitCJS&&e.options.emitESM;e.options.declaration=k?"compatible":"node16"}const g=n.file.replace(new RegExp(String.raw`(?:\*[^/\\]|\.d\.[mc]?ts|\.\w+|${[`\\.${a}`,`\\.${o}`].join("|")})$`),""),b=g.endsWith("/");if(b&&["./","/"].includes(g))continue;const d=g.replace(new RegExp(`(./)?${e.options.outDir}`),e.options.sourceDir).replace("./",""),c="(?<=/|$)",v=b?"":String.raw`(\.d\.[cm]?ts|(\.[cm]?[tj]sx?)|${[`\\.${a}`,`\\.${o}`].join("|")})$`;if((n.file.includes("/*")||g.includes("*"))&&n.key==="exports"){Z||(e.logger.debug("Private subfolders are not supported, if you need this feature please open an issue on GitHub."),Z=!0);let k;n.exportKey?k=n.exportKey.startsWith("./")?n.exportKey.slice(2):n.exportKey:k=(n.file.startsWith("./")?n.file.slice(2):n.file).replace(/^dist\//,"");const M=n.file,K=e.options.sourceDir.replace(/^\.\//,""),z=E(e.options.rootDir,K),q=[],re=await He(z);for(const I of re){const B=Ye(I,k);if(B){const A=Ze(M,B);q.push({input:E(z,I),output:A})}}if(q.length===0){p.push(`Could not find entrypoints matching pattern \`${k}\` for output \`${M}\``);continue}for(const{input:I,output:B}of q){const A={...n,file:B};L(m,I,b,g,A,e,!0)}continue}const f=new RegExp(c+d+v);let $=t.find(k=>f.test(k));if(oe.has(n.subKey)&&$===void 0){const k=d.replace(/^(.+?)\.[^.]*$/,"$1"),M=new RegExp(c+k+v);$=t.find(K=>M.test(K))}if($===void 0){x(E(e.options.rootDir,n.file))||p.push(`Could not find entrypoint for \`${n.file}\``);continue}x($)&&/\.[cm]?tsx?$/.test($)&&Q(e);const D=Se($.replace(De,""));x(`${D}.cts`)&&x(`${D}.mts`)?(L(m,`${D}.cts`,b,g,{...n,type:"cjs"},e,!1),L(m,`${D}.mts`,b,g,{...n,type:"esm"},e,!1)):L(m,$,b,g,n,e,!1)}return{entries:m,warnings:p}},"inferEntries");var ss=Object.defineProperty,ts=w((s,t)=>ss(s,"name",{value:t,configurable:!0}),"o");const os=ts((s,t)=>{const{publishConfig:e}=s;return e&&(e.bin&&(typeof e.bin=="object"||typeof e.bin=="string")&&(s.bin=e.bin),e.type&&typeof e.type=="string"&&e.type!==""&&(s.type=e.type),e.main&&typeof e.main=="string"&&e.main!==""&&(s.main=e.main),e.module&&typeof e.module=="string"&&e.module!==""&&(s.module=e.module),t===void 0&&e.types&&typeof e.types=="string"&&e.types!==""?s.types=e.types:t===void 0&&e.typings&&typeof e.typings=="string"&&e.typings!==""&&(s.typings=e.typings),e.exports&&typeof e.exports=="object"&&(s.exports=e.exports)),s},"overwriteWithPublishConfig");var is=Object.defineProperty,ns=w((s,t)=>is(s,"name",{value:t,configurable:!0}),"t$1");const as={hooks:{"build:prepare":ns(async function(s){if(s.options.entries.length>0)return;const t=C(s.options.rootDir,s.options.sourceDir);if(!x(t))throw new Error("No 'src' directory found. Please provide entries manually.");const e=he(t,{extensions:[],includeDirs:!1,includeSymlinks:!1,skip:[/.*\/node_modules\/.*/,/.*\/dist\/.*/]});if(e.length===0)throw new Error("No source files found in 'src' directory. Please provide entries manually.");let r={...s.pkg};r.publishConfig&&(s.logger.info(`Using publishConfig found in package.json, to override the default key-value pairs of "${Object.keys(r.publishConfig).join(", ")}".`),s.logger.debug(r.publishConfig),r=os(r,s.options.declaration));const a=await es(r,e,s);for(const o of a.warnings)Be(s,o);if(s.options.entries.push(...a.entries),s.options.entries.length===0)throw new Error("No entries detected. Please provide entries manually.");s.logger.info("Automatically detected entries:",Te(s.options.entries.map(o=>o.fileAlias?`${R(o.fileAlias)} => ${R(o.input.replace(`${s.options.rootDir}/`,"").replace(/\/$/,"/*"))}`:R(o.input.replace(`${s.options.rootDir}/`,"").replace(/\/$/,"/*"))).join(", ")),Me([s.options.emitESM&&"esm",s.options.emitCJS&&"cjs",s.options.declaration&&"dts"].filter(Boolean).map(o=>`[${o}]`).join(" ")))},"build:prepare")}};var rs=Object.defineProperty,cs=w((s,t)=>rs(s,"name",{value:t,configurable:!0}),"t");const ls=cs(async(s,t)=>{if(s==="auto")s=as;else{if(s==="none")return{};typeof s=="string"&&(s=await t.import(s)||{})}return typeof s=="function"&&(s=s()),s},"loadPreset");var ps=Object.defineProperty,P=w((s,t)=>ps(s,"name",{value:t,configurable:!0}),"r");const ds=P(s=>{s.addCommand({description:"Demonstrate options required",execute:P(async({logger:t,options:e})=>{let r="build";e.watch?r="watch":e.jit&&(r="jit");const a={};let o;if(e.env)for(const l of e.env)l.key==="NODE_ENV"?o=l.value:a[`process.env.${l.key}`]=JSON.stringify(l.value);o===void 0&&(e.production?o=O:e.development&&(o=J));const p=[];if(e.external)for(const l of e.external)p.push(l.split(","));const u=E(U(),e.dir??"."),y=Pe(u,{debug:e.debug}),{config:i,path:m}=await Ue(y,u,o,r,e.config??void 0);t.debug("Using packem config found at",m);const n=await ls(i.preset??"auto",y);e.minify&&e.sourcemap===void 0&&(e.sourcemap=!0);try{await Le(u,r,o,t,e.debug,Ee(i,n,{analyze:e.analyze,cjsInterop:e.cjsInterop,clean:e.clean,dtsOnly:e.dtsOnly,externals:p,killSignal:e.killSignal,minify:e.minify===void 0?o===O:e.minify,onSuccess:e.onSuccess,rollup:{esbuild:{target:e.target},license:{path:e.license},metafile:e.metafile,replace:{values:a},resolveExternals:e.noExternal?{builtins:!1,deps:!1,devDeps:!1,optDeps:!1,peerDeps:!1}:{}},runtime:e.runtime,sourcemap:e.metafile||e.analyze||e.sourcemap,validation:e.validation===!1?!1:{},...e.typedoc?{typedoc:{format:"html"}}:{}}),e.tsconfig??void 0)}catch(l){t.error(l),me(1)}},"execute"),name:"build",options:[{defaultValue:".",description:"The directory to build",name:"dir",type:String},{alias:"t",description:"Environments to support. `target` in tsconfig.json is automatically added. Defaults to the current Node.js version.",name:"target"},{description:"Use a custom config file",name:"config",type:String},{description:"Path to the tsconfig.json file",name:"tsconfig",type:String},{description:"Minify the output",name:"minify",type:Boolean},{description:"Generate sourcemaps (experimental)",name:"sourcemap",type:Boolean},{conflicts:"jit",description:"Watch for changes",name:"watch",type:Boolean},{conflicts:"watch",description:"Stub the package for JIT compilation",name:"jit",type:Boolean},{description:"Compile-time environment variables (eg. --env.NODE_ENV=production)",multiple:!0,name:"env",type:P(t=>{const[e,r]=t.split("=");return{key:e,value:r}},"type")},{defaultValue:!1,description:"Generate meta file (experimental)",name:"metafile",type:Boolean},{description:"Path to the license file",name:"license",type:String},{conflicts:"watch",description:"Visualize and analyze the bundle",name:"analyze",type:Boolean},{description:"CJS interop mode, can export default and named export, (experimental).",name:"cjsInterop",type:Boolean},{conflicts:"development",description:"Run code in production environment",name:"production",type:Boolean},{conflicts:"production",description:"Run code in development environment",name:"development",type:Boolean},{description:"Do not clean the dist directory before building",name:"no-clean",type:Boolean},{description:"Only generate .d.ts files",name:"dts-only",type:Boolean},{description:"Disable the output validation",name:"no-validation",type:Boolean},{description:"Disable the cache",name:"no-cache",type:Boolean},{description:"Generate type documentation",name:"typedoc",type:Boolean},{description:"Execute command after successful build, specially useful for watch mode",name:"onSuccess",type:String},{description:'Signal to kill child process, "SIGTERM" or "SIGKILL"',name:"killSignal",type:P(t=>{if(t==="SIGTERM"||t==="SIGKILL")return t;throw new Error("Invalid kill signal. Use 'SIGTERM' or 'SIGKILL'.")},"type")},{description:"Specify an external dependency, separate by comma (eg. --external lodash,react,react-dom)",multiple:!0,name:"external",typeLabel:"string[]"},{description:"do not bundle external dependencies",name:"no-external",type:Boolean},{description:"Specify the build runtime (nodejs, browser).",name:"runtime",type:P(t=>{if(t==="node"||t==="browser")return t;throw new Error("Invalid runtime. Use 'node' or 'browser'.")},"type")}]})},"createBuildCommand");var us=Object.defineProperty,T=w((s,t)=>us(s,"name",{value:t,configurable:!0}),"f");const ms=T(s=>{s.addCommand({description:"Initialize packem configuration",execute:T(async({logger:t,options:e})=>{if(fe("Welcome to packem setup"),x(C(e.dir,"packem.config.mjs"))){t.info("Packem project already initialized, you can use `packem build` to build your project");return}const r=E(U(),e.dir??"."),a=C(r,"package.json");if(!x(a))throw new Error("No package.json found in the directory");const o=await Ne(a,{resolveCatalogs:!0}),p=[];o.dependencies&&p.push(...Object.keys(o.dependencies)),o.devDependencies&&p.push(...Object.keys(o.devDependencies));const u=!!(o.devDependencies?.typescript??o.dependencies?.typescript),y=[];if(e.typescript===void 0&&!u?(e.typescript=await h({message:"Do you want to install TypeScript?"}),e.typescript&&y.push("typescript@latest")):W.message(`TypeScript version ${o.devDependencies?.typescript??o.dependencies?.typescript} is already installed`),!x(C(r,"tsconfig.json"))){const d=await h({message:"Do you want to use generate a tsconfig.json?"}),c=await h({message:"Do you want to run your code in the DOM?"});if(d){const v=_();v.start("Generating tsconfig.json"),$e(C(r,"tsconfig.json"),{compilerOptions:{esModuleInterop:!0,skipLibCheck:!0,target:"es2022",allowJs:!0,resolveJsonModule:!0,moduleDetection:"force",isolatedModules:!0,verbatimModuleSyntax:!0,strict:!0,noUncheckedIndexedAccess:!0,noImplicitOverride:!0,module:"NodeNext",outDir:"dist",sourceMap:!0,declaration:!0,lib:c?["es2022","dom","dom.iterable"]:["es2022"]}}),v.stop("")}}if(e.runtime===void 0&&(e.runtime=await S({message:"Pick a build runtime",options:[{label:"Node",value:"node"},{label:"Browser",value:"browser"}]})),p.includes("esbuild")?e.transformer="esbuild":p.includes("@swc/core")?e.transformer="swc":p.includes("sucrase")&&(e.transformer="sucrase"),e.transformer===void 0?(e.transformer=await S({message:"Pick a transformer",options:[{label:"esbuild",value:"esbuild"},{label:"swc",value:"swc"},{label:"Sucrase",value:"sucrase"},{label:"OXC",value:"oxc"}]}),e.transformer&&e.transformer!=="oxc"&&!p.includes(e.transformer)&&await h({message:`Do you want to install ${e.transformer}?`})&&y.push(e.transformer==="swc"?"@swc/core":e.transformer)):W.message(`Transformer ${e.transformer} is already installed.`),e.isolatedDeclarationTransformer===void 0&&(e.isolatedDeclarationTransformer=await h({message:"Do you want to use an isolated declaration types?",initialValue:!1})),e.isolatedDeclarationTransformer===void 0&&(e.isolatedDeclarationTransformer=await S({message:"Pick a isolated declaration transformer",options:[{label:"Typescript",value:"typescript"},{label:"swc",value:"swc"},{label:"OXC",value:"oxc"},{label:"None",value:void 0}]}),e.isolatedDeclarationTransformer!==void 0)){let d;switch(e.isolatedDeclarationTransformer){case"oxc":{d="oxc-transform";break}case"swc":{d="@swc/core";break}case"typescript":{d="typescript";break}default:ye("Invalid isolated declaration transformer")}d!==void 0&&!p.includes(d)&&await h({message:`Do you want to install ${d}?`})&&y.push(d)}e.css===void 0&&(e.css=await h({message:"Do you want to use css in your project?",initialValue:!1}));const i=[];if(e.css){const d=await S({message:"Pick a css loader",options:[{label:"PostCSS",value:"postcss"},{hint:"experimental",label:"Lightning CSS",value:"lightningcss"}]});i.push(d);let c=await se({message:"Pick your loaders",options:[{label:"Sass",value:"sass"},{label:"Stylus",value:"stylus"},{label:"Less",value:"less"}],required:!1});if(c.includes("sass")){const v=await S({message:"Pick a sass loader",options:[{label:"Sass embedded",value:"sass-embedded",hint:"recommended"},{label:"Sass",value:"sass"},{label:"Node Sass",value:"node-sass",hint:"legacy"}]});v!=="sass"&&(c=c.filter(f=>f!=="sass"),c.push(v))}if(i.push(...c),await h({message:`Do you want to install "${i.join('", "')}"?`}))for(const v of i)y.push(...ne[v]);i.push("sourceMap")}e.cssMinifier===void 0&&(e.cssMinifier=await h({message:"Do you want to minify your css?",initialValue:!1}));let m;e.cssMinifier&&(m=await S({message:"Pick a css minifier",options:[{label:"CSSNano",value:"cssnano"},{label:"Lightning CSS",value:"lightningcss"}]}),i.includes("lightningcss")||await h({message:`Do you want to install "${m}"?`})&&y.push(m));let n="",l="";if(e.isolatedDeclarationTransformer&&(l+=`,
|
|
29
|
-
isolatedDeclarationTransformer`),(e.css||e.cssMinifier)&&(
|
|
27
|
+
},`),a.start("Installing packages"),await _(v,{cwd:o,dev:!0,silent:!0}),a.stop("Installed packages"),e.success(`
|
|
28
|
+
CSS loaders added!`)}await we(p,i.toString(),{overwrite:!0})},"execute"),name:"add",options:[{defaultValue:".",description:"The directory to build",name:"dir",type:String},{description:"Use a custom config file",name:"config",type:String}]})},"createAddCommand");var Ge=Object.defineProperty,Fe=w((s,t)=>Ge(s,"name",{value:t,configurable:!0}),"e$1");const Ue=Fe(async(s,t,e,r,a)=>{const o=await ne(t,a);let p=await s.import(o,{default:!0,try:!0})||{};return typeof p=="function"&&(p=await p(e,r)),{config:p,path:o}},"loadPackemConfig");var ze=Object.defineProperty,j=w((s,t)=>ze(s,"name",{value:t,configurable:!0}),"u$1");const F=new Map,We=/\.[^./]+$/,Xe=j(async s=>{try{return await Oe.readdir(s,{withFileTypes:!0})}catch(t){const{code:e}=t;if(e==="ENOENT")return[];throw t}},"safeReaddir"),re=j(async(s,t)=>{const e=await Xe(s);return(await Promise.all(e.map(async r=>{const a=Y.join(s,r.name);return r.isDirectory()?re(a,t):r.isFile()?Y.relative(t,a):[]}))).flat()},"getDirectoryFilesRecursive"),He=j(async s=>{let t=F.get(s);return t||(t=re(s,s),F.set(s,t)),t},"getDirectoryFiles"),Ye=j((s,t)=>{const e=s.replace(We,"");if(t==="*"){const p=e.split("/");return p.length>0?[p[0]]:null}const r=t.replaceAll(/[.+?^${}()|[\]\\]/g,String.raw`\$&`).replaceAll("*","(.*)"),a=new RegExp(`^${r}$`),o=e.match(a);return o?o.slice(1):null},"matchWildcardPattern"),Ze=j((s,t)=>{let e=s;for(const r of t)e=e.replace("*",r);return e},"substituteWildcards"),Qe=j((s,t)=>s.key==="exports"&&s.subKey===N?N:s.key==="exports"&&s.subKey===G?G:t,"getEnvironment"),O=j((s,t,e,r,a,o,p)=>{const u=Qe(a,o.environment);let y=o.options.runtime;for(const n of xe)if(a.file.includes(`.${n}.`)||a.subKey===n){y=n;break}let i=s.find(n=>n.input===t&&n.environment===u&&n.runtime===y);i===void 0?i=s[s.push({environment:u,exportKey:new Set([a.exportKey].filter(Boolean)),input:t,runtime:y})-1]:i.exportKey&&a.exportKey&&i.exportKey.add(a.exportKey),p&&(i.isGlob=!0),e&&(i.outDir=r),a.isExecutable?(i.executable=!0,i.declaration=!1,a.type==="cjs"?i.cjs=!0:a.type==="esm"&&(i.esm=!0)):(/\.d\.[mc]?ts$/.test(a.file)&&o.options.declaration!==!1&&(i.declaration=o.options.declaration),a.type==="cjs"?i.cjs=!0:a.type==="esm"&&(i.esm=!0));const m=a.file.replace(oe(a.file),"").replace(new RegExp(`^./${o.options.outDir.replace(/^\.\//,"")}/`),"");ie.has(a.subKey)&&!t.includes(m)&&(i.fileAlias=m)},"createOrUpdateEntry");let Q=!1;const ee=j(s=>{if(s.pkg?.dependencies?.typescript===void 0&&s.pkg?.devDependencies?.typescript===void 0)throw new Error("You tried to use a `.ts`, `.cts` or `.mts` file but `typescript` was not found in your package.json.")},"validateIfTypescriptIsInstalled"),es=j(async(s,t,e)=>{const r=s.types||s.typings;F.clear();const a=(e.options.outputExtensionMap?.cjs??"cjs").replaceAll(".",String.raw`\.`),o=(e.options.outputExtensionMap?.esm??"mjs").replaceAll(".",String.raw`\.`),p=[];t.sort((n,c)=>n.split("/").length-c.split("/").length);const u=s.type==="module"?"esm":"cjs";u==="esm"&&(e.options.emitESM=!0),u==="cjs"&&(e.options.emitCJS=!0);const y=e.options.emitCJS&&e.options.emitESM;e.options.declaration===void 0&&(e.options.declaration=y?"compatible":"node16");const i=Ie(s.exports,u,e.options.declaration,[],e.options.ignoreExportKeys).filter(n=>!n.ignored);if(s.bin){const n=(typeof s.bin=="string"?[s.bin]:Object.values(s.bin)).filter(Boolean);for(const c of n){const g=H(c);if(g&&g!==u)throw new Error(`Exported file "${c}" has an extension that does not match the package.json type "${s.type??"commonjs"}".`);i.push({file:c,isExecutable:!0,key:"bin",type:g??u})}}s.main&&i.push({file:s.main,key:"main",type:H(s.main)??u}),s.module&&i.push({file:s.module,key:"module",type:"esm"}),r&&(ee(e),(e.options.declaration===void 0||e.options.declaration==="node16")&&y&&(e.options.declaration="compatible"),i.push({file:s.types??s.typings,key:"types"}));const m=[];for await(const n of i){const c=oe(n.file);if(c!==""&&!Ce.includes(c))continue;if(e.options.emitCJS===void 0&&n.type==="cjs"&&(e.options.emitCJS=!0),e.options.emitESM===void 0&&n.type==="esm"&&(e.options.emitESM=!0),e.options.declaration===void 0||e.options.declaration==="node16"){const k=e.options.emitCJS&&e.options.emitESM;e.options.declaration=k?"compatible":"node16"}const g=n.file.replace(new RegExp(String.raw`(?:\*[^/\\]|\.d\.[mc]?ts|\.\w+|${[`\\.${a}`,`\\.${o}`].join("|")})$`),""),v=g.endsWith("/");if(v&&["./","/"].includes(g))continue;const d=g.replace(new RegExp(`(./)?${e.options.outDir}`),e.options.sourceDir).replace("./",""),l="(?<=/|$)",b=v?"":String.raw`(\.d\.[cm]?ts|(\.[cm]?[tj]sx?)|${[`\\.${a}`,`\\.${o}`].join("|")})$`;if((n.file.includes("/*")||g.includes("*"))&&n.key==="exports"){Q||(e.logger.debug("Private subfolders are not supported, if you need this feature please open an issue on GitHub."),Q=!0);let k;n.exportKey?k=n.exportKey.startsWith("./")?n.exportKey.slice(2):n.exportKey:k=(n.file.startsWith("./")?n.file.slice(2):n.file).replace(/^dist\//,"");const I=n.file,q=e.options.sourceDir.replace(/^\.\//,""),W=P(e.options.rootDir,q),A=[],le=await He(W);for(const B of le){const L=Ye(B,k);if(L){const R=Ze(I,L);A.push({input:P(W,B),output:R})}}if(A.length===0){p.push(`Could not find entrypoints matching pattern \`${k}\` for output \`${I}\``);continue}for(const{input:B,output:L}of A){const R={...n,file:L};O(m,B,v,g,R,e,!0)}continue}const f=new RegExp(l+d+b);let $=t.find(k=>f.test(k));if(ie.has(n.subKey)&&$===void 0){const k=d.replace(/^(.+?)\.[^.]*$/,"$1"),I=new RegExp(l+k+b);$=t.find(q=>I.test(q))}if($===void 0){x(P(e.options.rootDir,n.file))||p.push(`Could not find entrypoint for \`${n.file}\``);continue}x($)&&/\.[cm]?tsx?$/.test($)&&ee(e);const D=Se($.replace(De,""));x(`${D}.cts`)&&x(`${D}.mts`)?(O(m,`${D}.cts`,v,g,{...n,type:"cjs"},e,!1),O(m,`${D}.mts`,v,g,{...n,type:"esm"},e,!1)):O(m,$,v,g,n,e,!1)}return{entries:m,warnings:p}},"inferEntries");var ss=Object.defineProperty,ts=w((s,t)=>ss(s,"name",{value:t,configurable:!0}),"o");const os=ts((s,t)=>{const{publishConfig:e}=s;return e&&(e.bin&&(typeof e.bin=="object"||typeof e.bin=="string")&&(s.bin=e.bin),e.type&&typeof e.type=="string"&&e.type!==""&&(s.type=e.type),e.main&&typeof e.main=="string"&&e.main!==""&&(s.main=e.main),e.module&&typeof e.module=="string"&&e.module!==""&&(s.module=e.module),t===void 0&&e.types&&typeof e.types=="string"&&e.types!==""?s.types=e.types:t===void 0&&e.typings&&typeof e.typings=="string"&&e.typings!==""&&(s.typings=e.typings),e.exports&&typeof e.exports=="object"&&(s.exports=e.exports)),s},"overwriteWithPublishConfig");var is=Object.defineProperty,ns=w((s,t)=>is(s,"name",{value:t,configurable:!0}),"t$1");const as={hooks:{"build:prepare":ns(async function(s){if(s.options.entries.length>0)return;const t=C(s.options.rootDir,s.options.sourceDir);if(!x(t))throw new Error("No 'src' directory found. Please provide entries manually.");const e=he(t,{extensions:[],includeDirs:!1,includeSymlinks:!1,skip:[/.*\/node_modules\/.*/,/.*\/dist\/.*/]});if(e.length===0)throw new Error("No source files found in 'src' directory. Please provide entries manually.");let r={...s.pkg};r.publishConfig&&(s.logger.info(`Using publishConfig found in package.json, to override the default key-value pairs of "${Object.keys(r.publishConfig).join(", ")}".`),s.logger.debug(r.publishConfig),r=os(r,s.options.declaration));const a=await es(r,e,s);for(const o of a.warnings)Be(s,o);if(s.options.entries.push(...a.entries),s.options.entries.length===0)throw new Error("No entries detected. Please provide entries manually.");s.logger.info("Automatically detected entries:",Te(s.options.entries.map(o=>o.fileAlias?`${V(o.fileAlias)} => ${V(o.input.replace(`${s.options.rootDir}/`,"").replace(/\/$/,"/*"))}`:V(o.input.replace(`${s.options.rootDir}/`,"").replace(/\/$/,"/*"))).join(", ")),Me([s.options.emitESM&&"esm",s.options.emitCJS&&"cjs",s.options.declaration&&"dts"].filter(Boolean).map(o=>`[${o}]`).join(" ")))},"build:prepare")}};var rs=Object.defineProperty,ls=w((s,t)=>rs(s,"name",{value:t,configurable:!0}),"t");const cs=ls(async(s,t)=>{if(s==="auto")s=as;else{if(s==="none")return{};typeof s=="string"&&(s=await t.import(s)||{})}return typeof s=="function"&&(s=s()),s},"loadPreset");var ps=Object.defineProperty,T=w((s,t)=>ps(s,"name",{value:t,configurable:!0}),"r");const ds=T(s=>{s.addCommand({description:"Demonstrate options required",execute:T(async({logger:t,options:e})=>{let r="build";e.watch?r="watch":e.jit&&(r="jit");const a={};let o;if(e.env)for(const c of e.env)c.key==="NODE_ENV"?o=c.value:a[`process.env.${c.key}`]=JSON.stringify(c.value);o===void 0&&(e.production?o=N:e.development&&(o=G));const p=[];if(e.external)for(const c of e.external)p.push(c.split(","));const u=P(z(),e.dir??"."),y=Pe(u,{debug:e.debug}),{config:i,path:m}=await Ue(y,u,o,r,e.config??void 0);t.debug("Using packem config found at",m);const n=await cs(i.preset??"auto",y);e.minify&&e.sourcemap===void 0&&(e.sourcemap=!0);try{await Le(u,r,o,t,e.debug,Ee(i,n,{analyze:e.analyze,cjsInterop:e.cjsInterop,clean:e.clean,dtsOnly:e.dtsOnly,externals:p,killSignal:e.killSignal,minify:e.minify===void 0?o===N:e.minify,onSuccess:e.onSuccess,rollup:{esbuild:{target:e.target},license:{path:e.license},metafile:e.metafile,replace:{values:a},resolveExternals:e.noExternal?{builtins:!1,deps:!1,devDeps:!1,optDeps:!1,peerDeps:!1}:{}},runtime:e.runtime,sourcemap:e.metafile||e.analyze||e.sourcemap,validation:e.validation===!1?!1:{},...e.typedoc?{typedoc:{format:"html"}}:{}}),e.tsconfig??void 0)}catch(c){t.error(c),me(1)}},"execute"),name:"build",options:[{defaultValue:".",description:"The directory to build",name:"dir",type:String},{alias:"t",description:"Environments to support. `target` in tsconfig.json is automatically added. Defaults to the current Node.js version.",name:"target"},{description:"Use a custom config file",name:"config",type:String},{description:"Path to the tsconfig.json file",name:"tsconfig",type:String},{description:"Minify the output",name:"minify",type:Boolean},{description:"Generate sourcemaps (experimental)",name:"sourcemap",type:Boolean},{conflicts:"jit",description:"Watch for changes",name:"watch",type:Boolean},{conflicts:"watch",description:"Stub the package for JIT compilation",name:"jit",type:Boolean},{description:"Compile-time environment variables (eg. --env.NODE_ENV=production)",multiple:!0,name:"env",type:T(t=>{const[e,r]=t.split("=");return{key:e,value:r}},"type")},{defaultValue:!1,description:"Generate meta file (experimental)",name:"metafile",type:Boolean},{description:"Path to the license file",name:"license",type:String},{conflicts:"watch",description:"Visualize and analyze the bundle",name:"analyze",type:Boolean},{description:"CJS interop mode, can export default and named export, (experimental).",name:"cjsInterop",type:Boolean},{conflicts:"development",description:"Run code in production environment",name:"production",type:Boolean},{conflicts:"production",description:"Run code in development environment",name:"development",type:Boolean},{description:"Do not clean the dist directory before building",name:"no-clean",type:Boolean},{description:"Only generate .d.ts files",name:"dts-only",type:Boolean},{description:"Disable the output validation",name:"no-validation",type:Boolean},{description:"Disable the cache",name:"no-cache",type:Boolean},{description:"Generate type documentation",name:"typedoc",type:Boolean},{description:"Execute command after successful build, specially useful for watch mode",name:"onSuccess",type:String},{description:'Signal to kill child process, "SIGTERM" or "SIGKILL"',name:"killSignal",type:T(t=>{if(t==="SIGTERM"||t==="SIGKILL")return t;throw new Error("Invalid kill signal. Use 'SIGTERM' or 'SIGKILL'.")},"type")},{description:"Specify an external dependency, separate by comma (eg. --external lodash,react,react-dom)",multiple:!0,name:"external",typeLabel:"string[]"},{description:"do not bundle external dependencies",name:"no-external",type:Boolean},{description:"Specify the build runtime (nodejs, browser).",name:"runtime",type:T(t=>{if(t==="node"||t==="browser")return t;throw new Error("Invalid runtime. Use 'node' or 'browser'.")},"type")}]})},"createBuildCommand");var us=Object.defineProperty,M=w((s,t)=>us(s,"name",{value:t,configurable:!0}),"f");const ms=M(s=>{s.addCommand({description:"Initialize packem configuration",execute:M(async({logger:t,options:e})=>{if(fe("Welcome to packem setup"),x(C(e.dir,"packem.config.mjs"))){t.info("Packem project already initialized, you can use `packem build` to build your project");return}const r=P(z(),e.dir??"."),a=C(r,"package.json");if(!x(a))throw new Error("No package.json found in the directory");const o=await Ne(a,{resolveCatalogs:!0}),p=[];o.dependencies&&p.push(...Object.keys(o.dependencies)),o.devDependencies&&p.push(...Object.keys(o.devDependencies));const u=!!(o.devDependencies?.typescript??o.dependencies?.typescript),y=[];if(e.typescript===void 0&&!u?(e.typescript=await h({message:"Do you want to install TypeScript?"}),e.typescript&&y.push("typescript@latest")):X.message(`TypeScript version ${o.devDependencies?.typescript??o.dependencies?.typescript} is already installed`),!x(C(r,"tsconfig.json"))){const d=await h({message:"Do you want to use generate a tsconfig.json?"}),l=await h({message:"Do you want to run your code in the DOM?"});if(d){const b=J();b.start("Generating tsconfig.json"),$e(C(r,"tsconfig.json"),{compilerOptions:{esModuleInterop:!0,skipLibCheck:!0,target:"es2022",allowJs:!0,resolveJsonModule:!0,moduleDetection:"force",isolatedModules:!0,verbatimModuleSyntax:!0,strict:!0,noUncheckedIndexedAccess:!0,noImplicitOverride:!0,module:"NodeNext",outDir:"dist",sourceMap:!0,declaration:!0,lib:l?["es2022","dom","dom.iterable"]:["es2022"]}}),b.stop("")}}if(e.runtime===void 0&&(e.runtime=await S({message:"Pick a build runtime",options:[{label:"Node",value:"node"},{label:"Browser",value:"browser"}]})),p.includes("esbuild")?e.transformer="esbuild":p.includes("@swc/core")?e.transformer="swc":p.includes("sucrase")&&(e.transformer="sucrase"),e.transformer===void 0?(e.transformer=await S({message:"Pick a transformer",options:[{label:"esbuild",value:"esbuild"},{label:"swc",value:"swc"},{label:"Sucrase",value:"sucrase"},{label:"OXC",value:"oxc"}]}),e.transformer&&e.transformer!=="oxc"&&!p.includes(e.transformer)&&await h({message:`Do you want to install ${e.transformer}?`})&&y.push(e.transformer==="swc"?"@swc/core":e.transformer)):X.message(`Transformer ${e.transformer} is already installed.`),e.isolatedDeclarationTransformer===void 0&&(e.isolatedDeclarationTransformer=await h({message:"Do you want to use an isolated declaration types?",initialValue:!1})),e.isolatedDeclarationTransformer===void 0&&(e.isolatedDeclarationTransformer=await S({message:"Pick a isolated declaration transformer",options:[{label:"Typescript",value:"typescript"},{label:"swc",value:"swc"},{label:"OXC",value:"oxc"},{label:"None",value:void 0}]}),e.isolatedDeclarationTransformer!==void 0)){let d;switch(e.isolatedDeclarationTransformer){case"oxc":{d="oxc-transform";break}case"swc":{d="@swc/core";break}case"typescript":{d="typescript";break}default:ye("Invalid isolated declaration transformer")}d!==void 0&&!p.includes(d)&&await h({message:`Do you want to install ${d}?`})&&y.push(d)}e.css===void 0&&(e.css=await h({message:"Do you want to use css in your project?",initialValue:!1}));const i=[];if(e.css){const d=await S({message:"Pick a css loader",options:[{label:"PostCSS",value:"postcss"},{hint:"experimental",label:"Lightning CSS",value:"lightningcss"}]});i.push(d);let l=await te({message:"Pick your loaders",options:[{label:"Sass",value:"sass"},{label:"Stylus",value:"stylus"},{label:"Less",value:"less"}],required:!1});if(l.includes("sass")){const b=await S({message:"Pick a sass loader",options:[{label:"Sass embedded",value:"sass-embedded",hint:"recommended"},{label:"Sass",value:"sass"},{label:"Node Sass",value:"node-sass",hint:"legacy"}]});b!=="sass"&&(l=l.filter(f=>f!=="sass"),l.push(b))}if(i.push(...l),await h({message:`Do you want to install "${i.join('", "')}"?`}))for(const b of i)y.push(...ae[b]);i.push("sourceMap")}e.cssMinifier===void 0&&(e.cssMinifier=await h({message:"Do you want to minify your css?",initialValue:!1}));let m;e.cssMinifier&&(m=await S({message:"Pick a css minifier",options:[{label:"CSSNano",value:"cssnano"},{label:"Lightning CSS",value:"lightningcss"}]}),i.includes("lightningcss")||await h({message:`Do you want to install "${m}"?`})&&y.push(m));let n="",c="";if(e.isolatedDeclarationTransformer&&(c+=`,
|
|
29
|
+
isolatedDeclarationTransformer`),(e.css||e.cssMinifier)&&(c+=`,
|
|
30
30
|
rollup: {
|
|
31
|
-
css: {`),e.css){const d=i.map(
|
|
32
|
-
loaders: [${d}],`}if(e.cssMinifier&&m&&(
|
|
33
|
-
minifier: ${m}Minifier,`),(e.css||e.cssMinifier)&&(
|
|
31
|
+
css: {`),e.css){const d=i.map(l=>((l==="sass-embedded"||l==="node-sass")&&(l="sass"),`${l}Loader`)).join(", ");c+=`
|
|
32
|
+
loaders: [${d}],`}if(e.cssMinifier&&m&&(c+=`
|
|
33
|
+
minifier: ${m}Minifier,`),(e.css||e.cssMinifier)&&(c+=`
|
|
34
34
|
}
|
|
35
35
|
}`),u||o.type==="module"){let d="";if(e.isolatedDeclarationTransformer&&(d+=`import isolatedDeclarationTransformer from "@visulima/packem/dts/isolated/transformer/${e.isolatedDeclarationTransformer}";
|
|
36
|
-
`),e.css)for(let
|
|
36
|
+
`),e.css)for(let l of i)(l==="sass-embedded"||l==="node-sass")&&(l="sass"),d+=`import ${l}Loader from "@visulima/packem/css/loader/${l.toLowerCase()}";
|
|
37
37
|
`;e.cssMinifier&&m&&(d+=`import ${m}Minifier from "@visulima/packem/css/minifier/${m.toLowerCase()}";
|
|
38
38
|
`),n=`import { defineConfig } from "@visulima/packem/config";
|
|
39
39
|
import transformer from "@visulima/packem/transformer/${e.transformer}";
|
|
40
40
|
${d}
|
|
41
41
|
export default defineConfig({
|
|
42
42
|
runtime: "${e.runtime}",
|
|
43
|
-
transformer${
|
|
43
|
+
transformer${c}
|
|
44
44
|
});
|
|
45
45
|
`}else{let d="";if(e.isolatedDeclarationTransformer&&(d+=`const isolatedDeclarationTransformer = require("@visulima/packem/dts/isolated/transformer/${e.isolatedDeclarationTransformer}");
|
|
46
|
-
`),e.css)for(let
|
|
46
|
+
`),e.css)for(let l of i)(l==="sass-embedded"||l==="node-sass")&&(l="sass"),d+=`const ${l}Loader = require("@visulima/packem/css/loader/${l.toLowerCase()}");
|
|
47
47
|
`;e.cssMinifier&&m&&(d+=`const ${m}Minifier = require("@visulima/packem/css/minifier/${m.toLowerCase()}");
|
|
48
48
|
`),n=`const { defineConfig } = require("@visulima/packem/config");
|
|
49
49
|
const transformer = require("@visulima/packem/transformer/${e.transformer}");
|
|
50
50
|
${d}
|
|
51
51
|
module.exports = defineConfig({
|
|
52
52
|
runtime: ${e.runtime},
|
|
53
|
-
transformer${
|
|
53
|
+
transformer${c}
|
|
54
54
|
});
|
|
55
|
-
`}const g=
|
|
55
|
+
`}const g=J(),v=u?"ts":"js";y.length>0&&(g.start("Installing packages"),await _(y,{cwd:r,dev:!0,silent:!0}),g.stop("Installed packages")),g.start(`Creating packem.config.${v}`),ke(C(r,`packem.config.${v}`),n),g.stop(`Created packem.config.${v}`),ge("Now you can run `packem build` to build your project")},"execute"),name:"init",options:[{defaultValue:".",description:"The directory to initialize",name:"dir",type:String},{description:"Choose a transformer",name:"transformer",type:M(t=>{if(typeof t=="string"&&["esbuild","sucrase","swc"].includes(t))return t;throw new Error("Invalid transformer, please choose one of 'swc', 'sucrase' or 'esbuild'")},"type")},{description:"Choose a isolated declaration transformer",name:"isolated-declaration-transformer",type:M(t=>{if(typeof t=="string"&&["none","oxc","swc","typescript"].includes(t))return t;throw new Error("Invalid isolated declaration isolated declaration, please choose one of 'none', 'oxc', 'swc' or 'typescript'")},"type")},{description:"Use CSS",name:"css",type:Boolean},{description:"Use CSS minifier",name:"css-minifier",type:Boolean},{Description:"Use TypeScript",name:"typescript",type:Boolean},{description:"Specify the build runtime (nodejs, browser).",name:"runtime",type:M(t=>{if(t==="node"||t==="browser")return t;throw new Error("Invalid runtime. Use 'node' or 'browser'.")},"type")}]})},"createInitCommand");try{require("node:module")?.enableCompileCache?.()||require("v8-compile-cache")}catch{}const K=new de("packem",{logger:{reporters:[new ue({error:{hideErrorCauseCodeView:!0,hideErrorCodeView:!0,hideErrorErrorsCodeView:!0}})],scope:"packem"},packageName:Ke,packageVersion:qe});ms(K);ds(K);Je(K);K.run({shouldExitProcess:!1});
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var c=Object.defineProperty;var o=(e,r)=>c(e,"name",{value:r,configurable:!0});import{createPail as s}from"@visulima/pail";import{SimpleReporter as u}from"@visulima/pail/reporter";import{x as g}from"./packem_shared/index-
|
|
1
|
+
var c=Object.defineProperty;var o=(e,r)=>c(e,"name",{value:r,configurable:!0});import{createPail as s}from"@visulima/pail";import{SimpleReporter as u}from"@visulima/pail/reporter";import{x as g}from"./packem_shared/index-dFhGUj4X.js";var f=Object.defineProperty,l=o((e,r)=>f(e,"name",{value:r,configurable:!0}),"r");const C=l(async(e,r={})=>{const{debug:t,environment:i,logger:a,mode:n,tsconfigPath:m,...d}={debug:!1,environment:"production",logger:{},mode:"build",tsconfigPath:void 0,...r},p=s({reporters:[new u({error:{hideErrorCauseCodeView:!0,hideErrorCodeView:!0,hideErrorErrorsCodeView:!0}})],scope:"packem",...a});await g(e,n,i,p,t,d,m)},"packem");export{C as packem};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var l=Object.defineProperty;var o=(e,r)=>l(e,"name",{value:r,configurable:!0});import{createRequire as f}from"node:module";import{createFilter as p}from"@rollup/pluginutils";import{f as d}from"./index-CUp9WuCG.js";const m=f(import.meta.url),O=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process;const{transform:_}=m("sucrase");var b=Object.defineProperty,g=o((e,r)=>b(e,"name",{value:r,configurable:!0}),"n"),v=Object.defineProperty,j=g((e,r)=>v(e,"name",{value:r,configurable:!0}),"a"),P=Object.defineProperty,y=j((e,r)=>P(e,"name",{value:r,configurable:!0}),"n");const n=y(({exclude:e,include:r,...t})=>{const a=p(r,e??d);return{name:"packem:sucrase",async transform(c,s){if(!a(s))return;const{code:i,sourceMap:u}=_(c,{...t,filePath:s,sourceMapOptions:{compiledFilename:s}});return{code:i,map:u}}}},"sucraseTransformPlugin");n.NAME="sucrase";const x=n;export{x as sucrasePlugin};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{v as r}from"./isolatedDeclarationsTypescriptTransformer-DkuEkofo-
|
|
1
|
+
import{v as r}from"./isolatedDeclarationsTypescriptTransformer-DkuEkofo-BCM0B079.js";import{B as o,B as p,N as t,D as a,i as c}from"./resolveTypescriptMjsCtsPlugin-DcZrZTmM-DYkwKhiN.js";export{r as isolatedDeclarationsTypescriptTransformer,o as patchTypescriptTypes,p as patchTypescriptTypesPlugin,t as resolveTsconfigPathsPlugin,a as resolveTsconfigRootDirectoriesPlugin,c as resolveTypescriptMjsCtsPlugin};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as r}from"./browserslistToEsbuild-C0IWmbNe-C6xPL1oW.js";import{z as e}from"./esbuildPlugin-BrFhdKJk-
|
|
1
|
+
import{b as r}from"./browserslistToEsbuild-C0IWmbNe-C6xPL1oW.js";import{z as e}from"./esbuildPlugin-BrFhdKJk-C8Y7RuGP.js";export{r as browserslistToEsbuild,e as esbuildPlugin};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{d as a}from"./isolatedDeclarationsOxcTransformer-WbfE6cGu-NeZOx2Y7.js";import{z as s}from"./oxcResolvePlugin-BJpi-eSG-
|
|
1
|
+
import{d as a}from"./isolatedDeclarationsOxcTransformer-WbfE6cGu-NeZOx2Y7.js";import{z as s}from"./oxcResolvePlugin-BJpi-eSG-RVsiMbfI.js";import{n as x}from"./oxcTransformPlugin-DfVQouIB-Cpfv95eA.js";export{a as isolatedDeclarationsOxcTransformer,s as oxcResolvePlugin,x as oxcTransformPlugin};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
var k=Object.defineProperty;var v=(e,r)=>k(e,"name",{value:r,configurable:!0});import{createRequire as M}from"node:module";import{createFilter as P}from"@rollup/pluginutils";import{a as A}from"./index-CUp9WuCG.js";import{extname as $,join as q}from"@visulima/path";import{findCacheDirSync as T}from"@visulima/find-cache-dir";import{readFileSync as S}from"@visulima/fs";import __cjs_mod__ from "node:module"; // -- packem CommonJS require shim --
|
|
2
|
+
const require = __cjs_mod__.createRequire(import.meta.url);
|
|
3
|
+
const _=M(import.meta.url),ee=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process;const{transform:w,formatMessages:E,build:R}=_("esbuild"),h=_("rs-module-lexer"),W={...h,default:h};var B=Object.defineProperty,C=v((e,r)=>B(e,"name",{value:r,configurable:!0}),"h"),F=Object.defineProperty,f=C((e,r)=>F(e,"name",{value:r,configurable:!0}),"u"),I=Object.defineProperty,N=f((e,r)=>I(e,"name",{value:r,configurable:!0}),"n$1");const j=N(async(e,r)=>{r.length>0&&(await E(r,{color:!0,kind:"warning"})).forEach(a=>e.warn(a))},"warn");var L=Object.defineProperty,D=f((e,r)=>L(e,"name",{value:r,configurable:!0}),"t");const G=D(e=>{if(e==="es")return"esm";if(e==="cjs")return e},"getEsbuildFormat"),H=D(({sourceMap:e=!0,...r})=>async function(a,s,i){if(r.minify||r.minifyWhitespace||r.minifyIdentifiers||r.minifySyntax){const t=G(i.format),c=await w(a,{format:t,loader:"js",sourcemap:e,...r});if(await j(this,c.warnings),c.code)return{code:c.code,map:c.map||void 0}}},"getRenderChunk");var U=Object.defineProperty,z=f((e,r)=>U(e,"name",{value:r,configurable:!0}),"n");const y=z(e=>e.replaceAll("\\","/"),"slash"),{parseAsync:J}=W,K=z(async e=>{const r=T("@visulima/packem/optimize-deps",{create:!0,cwd:e.cwd});if(!r)throw new Error('[packem:optimize-deps]: failed to find or create cache directory "node_modules/.cache/packem/optimize_deps".');await R({absWorkingDir:e.cwd,bundle:!0,entryPoints:e.include,format:"esm",ignoreAnnotations:!0,metafile:!0,outdir:r,sourcemap:e.sourceMap,splitting:!0,...e.esbuildOptions,plugins:[{name:"optimize-deps",async setup(s){s.onResolve({filter:/.*/},async i=>{if(e.exclude?.includes(i.path))return{external:!0};if(!i.pluginData?.__resolving_dep_path__&&e.include.includes(i.path)){const t=await s.resolve(i.path,{kind:"import-statement",pluginData:{__resolving_dep_path__:!0},resolveDir:i.resolveDir});return t.errors.length>0||t.warnings.length>0?t:{namespace:"optimize-deps",path:i.path,pluginData:{absolute:t.path,resolveDir:i.resolveDir}}}}),s.onLoad({filter:/.*/,namespace:"optimize-deps"},async i=>{const{absolute:t,resolveDir:c}=i.pluginData,u=S(t),{output:g}=await J({input:[{code:u,filename:t}]});return{contents:(g[0]?.exports??[]).length>0?`export * from '${y(t)}'`:`module.exports = require('${y(t)}')`,resolveDir:c}})}},...e.esbuildOptions?.plugins??[]]});const a=new Map;for(const s of e.include)a.set(s,{file:q(r,`${s}.js`)});return{cacheDir:r,optimized:a}},"optimizeDeps");var Q=Object.defineProperty,V=f((e,r)=>Q(e,"name",{value:r,configurable:!0}),"g");const X=V(({exclude:e,include:r,loaders:a,logger:s,optimizeDeps:i,sourceMap:t,...c})=>{const u=A;if(a!==void 0)for(let[o,n]of Object.entries(a)){const p=o.startsWith(".")?o:`.${o}`;typeof n=="string"?u[p]=n:n||delete u[p]}const g=Object.keys(u),x=new RegExp(`\\.(${g.map(o=>o.slice(1)).join("|")})$`),O=P(r??x,e);let l,b=process.cwd();return{async buildStart(){!i||l||(l=await K({cwd:b,sourceMap:t??!1,...i}),s.debug("optimized %O",l.optimized))},name:"packem:esbuild",options({context:o}){o&&(b=o)},renderChunk:H({...c,sourceMap:t}),async resolveId(o){if(l?.optimized.has(o)){const n=l.optimized.get(o);if(n)return s.debug("resolved %s to %s",o,n.file),n.file}},async transform(o,n){if(!O(n)||l?.optimized.has(n))return;const p=$(n),d=u[p];if(s.debug("transforming %s with %s loader",n,d),!d)return;const m=await w(o,{format:["base64","binary","dataurl","text","json"].includes(d)?"esm":void 0,loader:d,sourcefile:n.replace(/\.[cm]ts/,".ts"),sourcemap:t,...c});if(await j(this,m.warnings),m.code)return{code:m.code,map:m.map||void 0}}}},"esbuildTransformer");X.NAME="esbuild";export{X as z};
|