@visulima/packem 2.0.0-alpha.40 → 2.0.0-alpha.44

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.
@@ -1,3 +1,3 @@
1
- var j=Object.defineProperty;var g=(e,o)=>j(e,"name",{value:o,configurable:!0});import{cyan as v}from"@visulima/colorize";import{join as h}from"@visulima/path";import{p as $,d as P}from"../../packem_shared/create-or-update-key-storage-GwAIWW7R.js";import{readdirSync as A}from"node:fs";import{readFileSync as w,writeFileSync as F}from"@visulima/fs";import{Application as b}from"typedoc";var T=Object.defineProperty,_=g((e,o)=>T(e,"name",{value:o,configurable:!0}),"w");const C=_(async(e,o,a,s)=>{if(o.length===0)return;const{format:t,jsonFileName:n,marker:i,output:x,plugin:k,readmePath:p,...y}=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"&&s.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"&&s.warn({message:"The `jsonFileName` option is only used when the `json` format is used.",prefix:"typedoc"});const E=o.map(m=>m.input),u=k??[];u.push("typedoc-plugin-rename-defaults"),(t==="inline"||t==="markdown")&&u.push("typedoc-plugin-markdown");const l=await b.bootstrapWithPlugins({...y,compilerOptions:{allowJs:!0,declaration:!1,declarationMap:!1,esModuleInterop:!0,module:99,moduleResolution:100,noEmit:!0,noImplicitAny:!1,skipLibCheck:!0,sourceMap:!1,target:99,...y.compilerOptions},entryPoints:E,hideGenerator:!0,out:a,plugin:u,...t==="inline"?{hideBreadcrumbs:!0,hidePageHeader:!0,navigation:!1,outputFileStrategy:"modules",useCodeBlocks:!0}:{}},[]),d=await l.convert();if(d){if(t==="json")await l.generateJson(d,n);else if(t==="html")await l.generateDocs(d,a);else if(await l.generateOutputs(d),t==="inline"){if(i===void 0)throw new Error("The `marker` option is required when using the `inline` format.");const m=A(a,{withFileTypes:!0}).filter(r=>r.isFile());let f="";for(const r of m)r.name==="README.md"&&o.length>1||(f+=w(h(a,r.name)).replaceAll(`<!-- ${i}`,`<!-- _REPLACE_${i}`).replaceAll("<!-- ${marker}",`<!-- _REPLACE_\\${i}`));if(f!==""){const r=w(p),c=$(r,i,`
1
+ var j=Object.defineProperty;var g=(e,o)=>j(e,"name",{value:o,configurable:!0});import{cyan as v}from"@visulima/colorize";import{join as h}from"@visulima/path";import{g as $,d as P}from"../../packem_shared/create-or-update-key-storage-C0tWtgSr.js";import{readdirSync as A}from"node:fs";import{readFileSync as w,writeFileSync as F}from"@visulima/fs";import{Application as b}from"typedoc";var T=Object.defineProperty,_=g((e,o)=>T(e,"name",{value:o,configurable:!0}),"w");const C=_(async(e,o,a,s)=>{if(o.length===0)return;const{format:t,jsonFileName:n,marker:i,output:x,plugin:k,readmePath:p,...y}=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"&&s.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"&&s.warn({message:"The `jsonFileName` option is only used when the `json` format is used.",prefix:"typedoc"});const E=o.map(m=>m.input),u=k??[];u.push("typedoc-plugin-rename-defaults"),(t==="inline"||t==="markdown")&&u.push("typedoc-plugin-markdown");const l=await b.bootstrapWithPlugins({...y,compilerOptions:{allowJs:!0,declaration:!1,declarationMap:!1,esModuleInterop:!0,module:99,moduleResolution:100,noEmit:!0,noImplicitAny:!1,skipLibCheck:!0,sourceMap:!1,target:99,...y.compilerOptions},entryPoints:E,hideGenerator:!0,out:a,plugin:u,...t==="inline"?{hideBreadcrumbs:!0,hidePageHeader:!0,navigation:!1,outputFileStrategy:"modules",useCodeBlocks:!0}:{}},[]),d=await l.convert();if(d){if(t==="json")await l.generateJson(d,n);else if(t==="html")await l.generateDocs(d,a);else if(await l.generateOutputs(d),t==="inline"){if(i===void 0)throw new Error("The `marker` option is required when using the `inline` format.");const m=A(a,{withFileTypes:!0}).filter(r=>r.isFile());let f="";for(const r of m)r.name==="README.md"&&o.length>1||(f+=w(h(a,r.name)).replaceAll(`<!-- ${i}`,`<!-- _REPLACE_${i}`).replaceAll("<!-- ${marker}",`<!-- _REPLACE_\\${i}`));if(f!==""){const r=w(p),c=$(r,i,`
2
2
  ${f}`);if(!c){s.error({message:`Could not find the typedoc marker: <!-- ${i} --><!-- /${i} --> in ${p}`,prefix:"typedoc"});return}if(r===c)return;c&&F(p,c.replaceAll(`<!-- _REPLACE_${i}`,`<!-- ${i}`).replaceAll(`<!-- _REPLACE_\\${i}`,"<!-- ${marker}"),{overwrite:!0})}}}},"generateReferenceDocumentation");var R=Object.defineProperty,D=g((e,o)=>R(e,"name",{value:o,configurable:!0}),"r");const B=D(async(e,o,a,s)=>{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&&P("typedoc",o,e.logger,!0),s&&e.logger.raw(`
3
3
  `),e.logger.info({message:`Using ${v("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=h(o,"typedoc"):e.options.typedoc.format!=="json"&&(n=h(n,"api-docs")),await C(e.options.typedoc,e.options.entries,n,e.logger),await e.hooks.callHook("typedoc:done",e)}},"builder");export{B as default};
@@ -1,3 +1,4 @@
1
1
  import type { Cli } from "@visulima/cerebro";
2
- declare const createAddCommand: (cli: Cli) => void;
2
+ import type { Pail } from "@visulima/pail";
3
+ declare const createAddCommand: (cli: Cli<Pail>) => void;
3
4
  export default createAddCommand;
package/dist/cli/index.js CHANGED
@@ -1,59 +1,66 @@
1
1
  #!/usr/bin/env node
2
- var me=Object.defineProperty;var v=(t,s)=>me(t,"name",{value:s,configurable:!0});import{createCerebro as fe}from"@visulima/cerebro";import ge from"@visulima/cerebro/logger/pail";import{SimpleReporter as ye}from"@visulima/pail/reporter/simple";import P,{cwd as W,exit as be}from"node:process";import{installPackage as q}from"@antfu/install-pkg";import{spinner as U,select as j,multiselect as ie,confirm as h,intro as we,log as X,cancel as ve,outro as he}from"@clack/prompts";import{isAccessible as ke,readFile as $e,writeFile as je,isAccessibleSync as x,collectSync as Y,writeJsonSync as xe,writeFileSync as Se}from"@visulima/fs";import{join as C,resolve as E,extname as ne,toNamespacedPath as Ce}from"@visulima/path";import De from"magic-string";import{t as K,E as G,e as Ee,N as re,_ as Me,c as Pe}from"../packem_shared/index-CUp9WuCG.js";import{defu as Oe}from"defu";import{createJiti as Ie}from"jiti";import{cyan as Te,bold as V,gray as Ne}from"@visulima/colorize";import{e as Be,i as H,c as Le,x as Ae}from"../packem_shared/index-DFigeRU2.js";import Ke,{readFile as Fe,writeFile as Re}from"node:fs/promises";import Z from"node:path/posix";import{parsePackageJson as Je}from"@visulima/package/package-json";import{existsSync as ae}from"node:fs";import{createInterface as Ve}from"node:readline/promises";import __cjs_mod__ from "node:module"; // -- packem CommonJS require shim --
2
+ var X=Object.defineProperty;var h=(t,s)=>X(t,"name",{value:s,configurable:!0});import{createCerebro as _}from"@visulima/cerebro";import Y from"@visulima/cerebro/logger/pail";import{SimpleReporter as H}from"@visulima/pail/reporter/simple";import j,{cwd as L,exit as Q}from"node:process";import{installPackage as D}from"@antfu/install-pkg";import{confirm as w,select as v,multiselect as q,spinner as E,cancel as F,intro as Z,log as N,outro as ee}from"@clack/prompts";import{isAccessible as se,readFile as te,writeFile as ae,isAccessibleSync as O,writeJsonSync as ie,writeFileSync as oe}from"@visulima/fs";import{parsePackageJson as G}from"@visulima/package/package-json";import{join as S,resolve as B}from"@visulima/path";import re from"magic-string";import{exec as ne}from"tinyexec";import{t as V,E as ce}from"../packem_shared/index-CUp9WuCG.js";import{defu as le}from"defu";import{createJiti as de}from"jiti";import{j as pe,w as ue}from"../packem_shared/index-ChtiNkgT.js";import{existsSync as U}from"node:fs";import{readFile as me,writeFile as fe}from"node:fs/promises";import{createInterface as ge}from"node:readline/promises";import __cjs_mod__ from "node:module"; // -- packem CommonJS require shim --
3
3
  const require = __cjs_mod__.createRequire(import.meta.url);
4
- var qe="@visulima/packem",ce="2.0.0-alpha.39";const Q={version:ce};var Ue=Object.defineProperty,Ge=v((t,s)=>Ue(t,"name",{value:s,configurable:!0}),"t$1");const le=Ge(async(t,s="")=>{let e=s;if(!e){const i=["packem.config.js","packem.config.mjs","packem.config.cjs","packem.config.ts","packem.config.cts","packem.config.mts"];for(const o of i)if(await ke(C(t,o))){e=`./${o}`;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"),pe={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 ze=Object.defineProperty,ee=v((t,s)=>ze(t,"name",{value:s,configurable:!0}),"g");const We=["typedoc","typedoc-plugin-markdown","typedoc-plugin-rename-defaults"],_e=ee(t=>{t.addCommand({argument:{description:"Add a packem feature to your project",name:"feature",required:!0},description:"Add a optional packem feature to your project",execute:ee(async({argument:s,logger:e,options:i})=>{const o=U(),n=E(W(),i.dir??".");let l;try{l=await le(n,i.config)}catch{e.error("Could not find a packem config file, please run `packem init` first.");return}const r=await $e(l,{buffer:!1});let u="cjs";r.includes("import")&&(u="esm");const a=new De(r),m=" transformer,";let c=" transformer";if(r.includes(" transformer,")&&(c=" transformer,"),s.includes("typedoc")){if(r.includes("typedoc: typedocBuilder")||r.includes("@visulima/packem/builder/typedoc")){e.warn("Typedoc has already been added to the packem config.");return}u==="cjs"?a.prepend(`const typedocBuilder = require("@visulima/packem/builder/typedoc");
5
- `):a.prepend(`import typedocBuilder from "@visulima/packem/builder/typedoc";
6
- `),r.includes("builder: {")?a.replace("builder: {",`builder: {
4
+ var ye="@visulima/packem",J="2.0.0-alpha.43";const R={version:J};var we=Object.defineProperty,be=h((t,s)=>we(t,"name",{value:s,configurable:!0}),"t");const z=be(async(t,s="")=>{let e=s;if(!e){const a=["packem.config.js","packem.config.mjs","packem.config.cjs","packem.config.ts","packem.config.cts","packem.config.mts"];for(const o of a)if(await se(S(t,o))){e=`./${o}`;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"),K={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,y=h((t,s)=>ve(t,"name",{value:s,configurable:!0}),"r$2");const he=["typedoc","typedoc-plugin-markdown","typedoc-plugin-rename-defaults"],ke=["@babel/core","@babel/preset-react"],Se=["react","react-dom"],$e=["@babel/core","babel-preset-solid"],je=["solid-js"],Ce=["unplugin-vue"],xe=["vue"],De=["rollup-plugin-svelte"],Pe=["svelte"],M=y((t,s,e)=>t.includes(`preset: '${s}'`)||t.includes(`preset: "${s}"`)||t.includes(`preset: '${s}',`)||t.includes(`preset: "${s}",`)||t.includes(e)||t.includes(`@visulima/packem/config/preset/${s}`),"checkPresetExists"),T=y((t,s)=>{const{logger:e,magic:a,packemConfig:o}=t,r=o.match(/defineConfig\s*\(\s*\{/);if(r&&r.index!==void 0){const n=r.index+r[0].length;if(o.includes("preset:")){const i=o.match(/preset:\s*['"]([^'"]+)['"]/);if(i)a.replace(i[0],`preset: '${s}'`);else throw e.warn(`A preset already exists in the config. Please manually set it to '${s}'.`),new Error("Preset exists but is not a string")}else a.appendLeft(n,`
5
+ preset: '${s}',`)}else if(o.includes("transformer:"))a.replace("transformer:",`preset: '${s}',
6
+ transformer:`);else{const n=o.indexOf("{");n!==-1&&a.appendLeft(n+1,`
7
+ preset: '${s}',`)}},"insertPreset"),Me=y(async t=>{try{return((await ne("git",["status","--porcelain"],{nodeOptions:{cwd:t,stdio:["pipe","pipe","pipe"]}})).stdout?.trim().length??0)>0}catch{return!1}},"checkGitDirty"),Te=y(async t=>{const s=S(t,"package.json"),e=await G(s,{resolveCatalogs:!0});return!!(e.devDependencies?.typescript??e.dependencies?.typescript)},"checkTypeScriptInstalled"),Ie=y(async t=>{const s=await Te(t),e=[...Se],a=[...ke];return s?a.push("@types/react","@types/react-dom"):await w({initialValue:!1,message:"Do you want to use TypeScript?"})&&a.push("typescript","@types/react","@types/react-dom"),{devPackages:a,packages:e}},"getReactTypeDependencies"),I=y(async(t,s,e)=>{const{rootDirectory:a,spinner:o}=t;o.start("Installing packages"),await D(e,{cwd:a,dev:!1,silent:!0}),await D(s,{cwd:a,dev:!0,silent:!0}),o.stop("Installed packages")},"installPackages"),Oe=y(async t=>{const{logger:s,magic:e,packemConfig:a,packemConfigFormat:o,rootDirectory:r,spinner:n,transformerReplaceKey:i,transformerSearchKey:l}=t;if(a.includes("typedoc: typedocBuilder")||a.includes("@visulima/packem/builder/typedoc")){s.warn("Typedoc has already been added to the packem config.");return}o==="cjs"?e.prepend(`const typedocBuilder = require("@visulima/packem/builder/typedoc");
8
+ `):e.prepend(`import typedocBuilder from "@visulima/packem/builder/typedoc";
9
+ `),a.includes("builder: {")?e.replace("builder: {",`builder: {
7
10
  typedoc: typedocBuilder,
8
- `):a.replace(c,`${m}
11
+ `):e.replace(l,`${i}
9
12
  builder: {
10
13
  typedoc: typedocBuilder,
11
- },`),e.info("Adding typedoc dependencies..."),o.start("Installing packages"),await q(We,{cwd:n,dev:!0,silent:!0}),o.stop("Installed packages"),e.success(`
12
- Typedoc added!`)}if(s.includes("css")){if(r.includes("css: {")||r.includes("@visulima/packem/css")){e.warn("Css loaders have already been added to the packem config.");return}const d=[],y=await j({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(d.push(y),y!=="tailwindcss"){let g=await ie({message:"Pick extra loaders",options:[{label:"Sass",value:"sass"},{label:"Stylus",value:"stylus"},{label:"Less",value:"less"}],required:!1});if(g.includes("sass")){const k=await j({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"}]});k!=="sass"&&(g=g.filter(D=>D!=="sass"),g.push(k))}d.push(...g)}const b=[];for(const g of d)b.push(...pe[g]);y!=="tailwindcss"&&d.push("sourceMap");for(let g of d)(g==="sass-embedded"||g==="node-sass")&&(g="sass"),u==="cjs"?a.prepend(`const ${g}Loader = require("@visulima/packem/css/loader/${g.toLowerCase()}");
13
- `):a.prepend(`import ${g}Loader from "@visulima/packem/css/loader/${g.toLowerCase()}";
14
- `);const f=await h({initialValue:!1,message:"Do you want to minify your css?"});let p;f&&(p=await j({message:"Pick a css minifier",options:[{label:"CSSNano",value:"cssnano"},{label:"Lightning CSS",value:"lightningcss"}]}),d.includes("lightningcss")||b.push(p),u==="cjs"?a.prepend(`const ${p}Minifier = require("@visulima/packem/css/minifier/${p.toLowerCase()}");
15
- `):a.prepend(`import ${p}Minifier from "@visulima/packem/css/minifier/${p.toLowerCase()}";
16
- `));const w=d.map(g=>((g==="sass-embedded"||g==="node-sass")&&(g="sass"),`${g}Loader`)).join(", ");r.includes("rollup: {")?a.replace("rollup: {",`rollup: {
17
- css: {${p?`
18
- minifier: ${p}Minifier,`:""}
19
- loaders: [${w}],
14
+ },`),s.info("Adding typedoc dependencies..."),n.start("Installing packages"),await D(he,{cwd:r,dev:!0,silent:!0}),n.stop("Installed packages"),s.success(`
15
+ Typedoc added!`)},"addTypedoc"),Ee=y(async t=>{const{logger:s,packemConfig:e}=t;if(M(e,"react","createReactPreset")){s.warn("React preset has already been added to the packem config.");return}T(t,"react");const{devPackages:a,packages:o}=await Ie(t.rootDirectory);s.info("Adding React dependencies..."),await I(t,a,o),s.success(`
16
+ React preset added!`)},"addReact"),Le=y(async t=>{const{logger:s,packemConfig:e}=t;if(M(e,"solid","createSolidPreset")){s.warn("Solid preset has already been added to the packem config.");return}T(t,"solid"),s.info("Adding Solid dependencies..."),await I(t,$e,je),s.success(`
17
+ Solid preset added!`)},"addSolid"),Be=y(async t=>{const{logger:s,packemConfig:e}=t;if(M(e,"vue","createVuePreset")){s.warn("Vue preset has already been added to the packem config.");return}T(t,"vue"),s.info("Adding Vue dependencies..."),await I(t,Ce,xe),s.success(`
18
+ Vue preset added!`)},"addVue"),Ne=y(async t=>{const{logger:s,packemConfig:e}=t;if(M(e,"svelte","createSveltePreset")){s.warn("Svelte preset has already been added to the packem config.");return}T(t,"svelte"),s.info("Adding Svelte dependencies..."),await I(t,De,Pe),s.success(`
19
+ Svelte preset added!`)},"addSvelte"),Ve=y(async t=>{const{logger:s,magic:e,packemConfig:a,packemConfigFormat:o,transformerReplaceKey:r,transformerSearchKey:n}=t;if(a.includes("css: {")||a.includes("@visulima/packem/css")){s.warn("Css loaders have already been added to the packem config.");return}const i=[],l=await v({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(i.push(l),l!=="tailwindcss"){let f=await q({message:"Pick extra loaders",options:[{label:"Sass",value:"sass"},{label:"Stylus",value:"stylus"},{label:"Less",value:"less"}],required:!1});if(f.includes("sass")){const b=await v({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"}]});b!=="sass"&&(f=f.filter(d=>d!=="sass"),f.push(b))}i.push(...f)}const p=[];for(const f of i)p.push(...K[f]);l!=="tailwindcss"&&i.push("sourceMap");for(const f of i){const b=f==="sass-embedded"||f==="node-sass"?"sass":f;o==="cjs"?e.prepend(`const ${b}Loader = require("@visulima/packem/css/loader/${b.toLowerCase()}");
20
+ `):e.prepend(`import ${b}Loader from "@visulima/packem/css/loader/${b.toLowerCase()}";
21
+ `)}const m=await w({initialValue:!1,message:"Do you want to minify your css?"});let g;m&&(g=await v({message:"Pick a css minifier",options:[{label:"CSSNano",value:"cssnano"},{label:"Lightning CSS",value:"lightningcss"}]}),i.includes("lightningcss")||p.push(g),o==="cjs"?e.prepend(`const ${g}Minifier = require("@visulima/packem/css/minifier/${g.toLowerCase()}");
22
+ `):e.prepend(`import ${g}Minifier from "@visulima/packem/css/minifier/${g.toLowerCase()}";
23
+ `));const c=i.map(f=>f==="sass-embedded"||f==="node-sass"?"sass":`${f}Loader`).join(", ");a.includes("rollup: {")?e.replace("rollup: {",`rollup: {
24
+ css: {${g?`
25
+ minifier: ${g}Minifier,`:""}
26
+ loaders: [${c}],
20
27
  },
21
- `):a.replace(c,`${m}
28
+ `):e.replace(n,`${r}
22
29
  rollup: {
23
- css: {${p?`
24
- minifier: ${p}Minifier,`:""}
25
- loaders: [${w}],
30
+ css: {${g?`
31
+ minifier: ${g}Minifier,`:""}
32
+ loaders: [${c}],
26
33
  },
27
- },`),o.start("Installing packages"),await q(b,{cwd:n,dev:!0,silent:!0}),o.stop("Installed packages"),e.success(`
28
- CSS loaders added!`)}await je(l,a.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 Xe=Object.defineProperty,Ye=v((t,s)=>Xe(t,"name",{value:s,configurable:!0}),"e$1");const He=Ye(async(t,s,e,i,o)=>{const n=await le(s,o);let l=await t.import(n,{default:!0,try:!0})||{};return typeof l=="function"&&(l=await l(e,i)),{config:l,path:n}},"loadPackemConfig");var Ze=Object.defineProperty,S=v((t,s)=>Ze(t,"name",{value:s,configurable:!0}),"u$1");const z=new Map,Qe=/\.[^./]+$/,et=S(async t=>{try{return await Ke.readdir(t,{withFileTypes:!0})}catch(s){const{code:e}=s;if(e==="ENOENT")return[];throw s}},"safeReaddir"),de=S(async(t,s)=>{const e=await et(t);return(await Promise.all(e.map(async i=>{const o=Z.join(t,i.name);return i.isDirectory()?de(o,s):i.isFile()?Z.relative(s,o):[]}))).flat()},"getDirectoryFilesRecursive"),tt=S(async t=>{let s=z.get(t);return s||(s=de(t,t),z.set(t,s)),s},"getDirectoryFiles"),st=S((t,s)=>{const e=t.replace(Qe,"");if(s==="*"){const l=e.split("/");return l.length>0?[l[0]]:null}const i=s.replaceAll(/[.+?^${}()|[\]\\]/g,String.raw`\$&`).replaceAll("*","(.*)"),o=new RegExp(`^${i}$`),n=e.match(o);return n?n.slice(1):null},"matchWildcardPattern"),ot=S((t,s)=>{let e=t;for(const i of s)e=e.replace("*",i);return e},"substituteWildcards"),it=S((t,s)=>t.key==="exports"&&t.subKey===K?K:t.key==="exports"&&t.subKey===G?G:s,"getEnvironment"),A=S((t,s,e,i,o,n,l)=>{const r=it(o,n.environment);let u=n.options.runtime;for(const c of Ee)if(o.file.includes(`.${c}.`)||o.subKey===c){u=c;break}let a=t.find(c=>c.input===s&&c.environment===r&&c.runtime===u);a===void 0?a=t[t.push({environment:r,exportKey:new Set([o.exportKey].filter(Boolean)),input:s,runtime:u})-1]:a.exportKey&&o.exportKey&&a.exportKey.add(o.exportKey),l&&(a.isGlob=!0),e&&(a.outDir=i),o.isExecutable?(a.executable=!0,a.declaration=!1,o.type==="cjs"?a.cjs=!0:o.type==="esm"&&(a.esm=!0)):(/\.d\.[mc]?ts$/.test(o.file)&&n.options.declaration!==!1&&(a.declaration=n.options.declaration),o.type==="cjs"?a.cjs=!0:o.type==="esm"&&(a.esm=!0));const m=o.file.replace(ne(o.file),"").replace(new RegExp(`^./${n.options.outDir.replace(/^\.\//,"")}/`),"");re.has(o.subKey)&&!s.includes(m)&&(a.fileAlias=m)},"createOrUpdateEntry");let te=!1;const se=S(t=>{if(t.pkg?.dependencies?.typescript===void 0&&t.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"),nt=S(async(t,s,e)=>{const i=t.types||t.typings;z.clear();const o=(e.options.outputExtensionMap?.cjs??"cjs").replaceAll(".",String.raw`\.`),n=(e.options.outputExtensionMap?.esm??"mjs").replaceAll(".",String.raw`\.`),l=[];s.sort((c,d)=>c.split("/").length-d.split("/").length);const r=t.type==="module"?"esm":"cjs";r==="esm"&&(e.options.emitESM=!0),r==="cjs"&&(e.options.emitCJS=!0);const u=e.options.emitCJS&&e.options.emitESM;e.options.declaration===void 0&&(e.options.declaration=u?"compatible":"node16");const a=Be(t.exports,r,e.options.declaration,[],e.options.ignoreExportKeys).filter(c=>!c.ignored);if(t.bin){const c=(typeof t.bin=="string"?[t.bin]:Object.values(t.bin)).filter(Boolean);for(const d of c){const y=H(d);if(y&&y!==r)throw new Error(`Exported file "${d}" has an extension that does not match the package.json type "${t.type??"commonjs"}".`);a.push({file:d,isExecutable:!0,key:"bin",type:y??r})}}t.main&&a.push({file:t.main,key:"main",type:H(t.main)??r}),t.module&&a.push({file:t.module,key:"module",type:"esm"}),i&&(se(e),(e.options.declaration===void 0||e.options.declaration==="node16")&&u&&(e.options.declaration="compatible"),a.push({file:t.types??t.typings,key:"types"}));const m=[];for await(const c of a){const d=ne(c.file);if(d!==""&&!Me.includes(d))continue;if(e.options.emitCJS===void 0&&c.type==="cjs"&&(e.options.emitCJS=!0),e.options.emitESM===void 0&&c.type==="esm"&&(e.options.emitESM=!0),e.options.declaration===void 0||e.options.declaration==="node16"){const $=e.options.emitCJS&&e.options.emitESM;e.options.declaration=$?"compatible":"node16"}const y=c.file.replace(new RegExp(String.raw`(?:\*[^/\\]|\.d\.[mc]?ts|\.\w+|${[`\\.${o}`,`\\.${n}`].join("|")})$`),""),b=y.endsWith("/");if(b&&["./","/"].includes(y))continue;const f=y.replace(new RegExp(`(./)?${e.options.outDir}`),e.options.sourceDir).replace("./",""),p="(?<=/|$)",w=b?"":String.raw`(\.d\.[cm]?ts|(\.[cm]?[tj]sx?)|${[`\\.${o}`,`\\.${n}`].join("|")})$`;if((c.file.includes("/*")||y.includes("*"))&&c.key==="exports"){te||(e.logger.debug("Private subfolders are not supported, if you need this feature please open an issue on GitHub."),te=!0);let $;c.exportKey?$=c.exportKey.startsWith("./")?c.exportKey.slice(2):c.exportKey:$=(c.file.startsWith("./")?c.file.slice(2):c.file).replace(/^dist\//,"");const N=c.file,F=e.options.sourceDir.replace(/^\.\//,""),_=E(e.options.rootDir,F),R=[],ue=await tt(_);for(const B of ue){const L=st(B,$);if(L){const J=ot(N,L);R.push({input:E(_,B),output:J})}}if(R.length===0){l.push(`Could not find entrypoints matching pattern \`${$}\` for output \`${N}\``);continue}for(const{input:B,output:L}of R){const J={...c,file:L};A(m,B,b,y,J,e,!0)}continue}const g=new RegExp(p+f+w);let k=s.find($=>g.test($));if(re.has(c.subKey)&&k===void 0){const $=f.replace(/^(.+?)\.[^.]*$/,"$1"),N=new RegExp(p+$+w);k=s.find(F=>N.test(F))}if(k===void 0){x(E(e.options.rootDir,c.file))||l.push(`Could not find entrypoint for \`${c.file}\``);continue}x(k)&&/\.[cm]?tsx?$/.test(k)&&se(e);const D=Ce(k.replace(Pe,""));x(`${D}.cts`)&&x(`${D}.mts`)?(A(m,`${D}.cts`,b,y,{...c,type:"cjs"},e,!1),A(m,`${D}.mts`,b,y,{...c,type:"esm"},e,!1)):A(m,k,b,y,c,e,!1)}return{entries:m,warnings:l}},"inferEntries");var rt=Object.defineProperty,at=v((t,s)=>rt(t,"name",{value:s,configurable:!0}),"o");const ct=at((t,s)=>{const{publishConfig:e}=t;return e&&(e.bin&&(typeof e.bin=="object"||typeof e.bin=="string")&&(t.bin=e.bin),e.type&&typeof e.type=="string"&&e.type!==""&&(t.type=e.type),e.main&&typeof e.main=="string"&&e.main!==""&&(t.main=e.main),e.module&&typeof e.module=="string"&&e.module!==""&&(t.module=e.module),s===void 0&&e.types&&typeof e.types=="string"&&e.types!==""?t.types=e.types:s===void 0&&e.typings&&typeof e.typings=="string"&&e.typings!==""&&(t.typings=e.typings),e.exports&&typeof e.exports=="object"&&(t.exports=e.exports)),t},"overwriteWithPublishConfig");var lt=Object.defineProperty,pt=v((t,s)=>lt(t,"name",{value:s,configurable:!0}),"p");const dt={hooks:{"build:prepare":pt(async function(t){if(t.options.unbundle){t.options.entries.length=0;const o=C(t.options.rootDir,t.options.sourceDir);if(!x(o))throw new Error("No 'src' directory found. Please provide entries manually.");const n=Y(o,{extensions:[],includeDirs:!1,includeSymlinks:!1,skip:[/.*\/node_modules\/.*/,/.*\/dist\/.*/]}).filter(l=>/\.(ts|tsx|js|jsx|mts|cts|mjs|cjs)$/.test(l)&&!l.endsWith(".d.ts"));for(const l of n){const r=l.replace(`${o}/`,"").replace(/\.(ts|tsx|js|jsx|mts|cts|mjs|cjs)$/,"").replaceAll("/","/");t.options.entries.push({input:l,name:r})}return}if(t.options.entries.length>0)return;const s=C(t.options.rootDir,t.options.sourceDir);if(!x(s))throw new Error("No 'src' directory found. Please provide entries manually.");const e=Y(s,{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 i={...t.pkg};if(i.publishConfig&&(t.logger.info(`Using publishConfig found in package.json, to override the default key-value pairs of "${Object.keys(i.publishConfig).join(", ")}".`),t.logger.debug(i.publishConfig),i=ct(i,t.options.declaration)),t.options.unbundle){t.logger.info("Unbundle mode detected, creating entries for all source files");const o=e.filter(n=>/\.(ts|tsx|js|jsx|mts|cts|mjs|cjs)$/.test(n)&&!n.endsWith(".d.ts"));t.logger.info(`Found ${o.length} code files for unbundle mode`);for(const n of o){const l=n.replace(`${s}/`,"").replace(/\.(ts|tsx|js|jsx|mts|cts|mjs|cjs)$/,"").replaceAll("/","/");t.logger.info(`Adding entry: ${l} -> ${n}`),t.options.entries.push({input:n,name:l})}}else{const o=await nt(i,e,t);for(const n of o.warnings)Le(t,n);t.options.entries.push(...o.entries)}if(t.options.entries.length===0)throw new Error("No entries detected. Please provide entries manually.");t.logger.info("Automatically detected entries:",Te(t.options.entries.map(o=>o.fileAlias?`${V(o.fileAlias)} => ${V(o.input.replace(`${t.options.rootDir}/`,"").replace(/\/$/,"/*"))}`:V(o.input.replace(`${t.options.rootDir}/`,"").replace(/\/$/,"/*"))).join(", ")),Ne([t.options.emitESM&&"esm",t.options.emitCJS&&"cjs",t.options.declaration&&"dts"].filter(Boolean).map(o=>`[${o}]`).join(" ")))},"build:prepare")}};var ut=Object.defineProperty,mt=v((t,s)=>ut(t,"name",{value:s,configurable:!0}),"t");const ft=mt(async(t,s)=>{if(t==="auto")t=dt;else{if(t==="none")return{};typeof t=="string"&&(t=await s.import(t)||{})}return typeof t=="function"&&(t=t()),t},"loadPreset");var gt=Object.defineProperty,O=v((t,s)=>gt(t,"name",{value:s,configurable:!0}),"r");const yt=O(t=>{t.addCommand({description:"Demonstrate options required",execute:O(async({logger:s,options:e})=>{let i="build";e.watch?i="watch":e.jit&&(i="jit");const o={};let n;if(e.env)for(const d of e.env)d.key==="NODE_ENV"?n=d.value:o[`process.env.${d.key}`]=JSON.stringify(d.value);n===void 0&&(e.production?n=K:e.development&&(n=G));const l=[];if(e.external)for(const d of e.external)l.push(d.split(","));const r=E(W(),e.dir??"."),u=Ie(r,{debug:e.debug}),{config:a,path:m}=await He(u,r,n,i,e.config??void 0);s.debug("Using packem config found at",m);const c=await ft(a.preset??"auto",u);e.minify&&e.sourcemap===void 0&&(e.sourcemap=!0);try{await Ae(r,i,n,s,e.debug,Oe(a,c,{analyze:e.analyze,cjsInterop:e.cjsInterop,clean:e.clean,dtsOnly:e.dtsOnly,externals:l,killSignal:e.killSignal,minify:e.minify===void 0?n===K:e.minify,onSuccess:e.onSuccess,rollup:{esbuild:{target:e.target},license:{path:e.license},metafile:e.metafile,replace:{values:o},resolveExternals:e.noExternal?{builtins:!1,deps:!1,devDeps:!1,optDeps:!1,peerDeps:!1}:{}},runtime:e.runtime,sourcemap:e.metafile||e.analyze||e.sourcemap,unbundle:e.unbundle,validation:e.validation===!1?!1:{},...e.typedoc?{typedoc:{format:"html"}}:{}}),e.tsconfig??void 0)}catch(d){s.error(d),be(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:O(s=>{const[e,i]=s.split("=");return{key:e,value:i}},"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:O(s=>{if(s==="SIGTERM"||s==="SIGKILL")return s;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:O(s=>{if(s==="node"||s==="browser")return s;throw new Error("Invalid runtime. Use 'node' or 'browser'.")},"type")},{description:"Enable unbundle mode to preserve source file structure instead of bundling into a single file",name:"unbundle",type:Boolean}]})},"createBuildCommand");var bt=Object.defineProperty,I=v((t,s)=>bt(t,"name",{value:s,configurable:!0}),"f");const wt=I(t=>{t.addCommand({description:"Initialize packem configuration",execute:I(async({logger:s,options:e})=>{if(we("Welcome to packem setup"),x(C(e.dir,"packem.config.mjs"))){s.info("Packem project already initialized, you can use `packem build` to build your project");return}const i=E(W(),e.dir??"."),o=C(i,"package.json");if(!x(o))throw new Error("No package.json found in the directory");const n=await Je(o,{resolveCatalogs:!0}),l=[];n.dependencies&&l.push(...Object.keys(n.dependencies)),n.devDependencies&&l.push(...Object.keys(n.devDependencies));const r=!!(n.devDependencies?.typescript??n.dependencies?.typescript),u=[];if(e.typescript===void 0&&!r?(e.typescript=await h({message:"Do you want to install TypeScript?"}),e.typescript&&u.push("typescript@latest")):X.message(`TypeScript version ${n.devDependencies?.typescript??n.dependencies?.typescript} is already installed`),!x(C(i,"tsconfig.json"))){const f=await h({message:"Do you want to use generate a tsconfig.json?"}),p=await h({message:"Do you want to run your code in the DOM?"});if(f){const w=U();w.start("Generating tsconfig.json"),xe(C(i,"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:p?["es2022","dom","dom.iterable"]:["es2022"]}}),w.stop("")}}if(e.runtime===void 0&&(e.runtime=await j({message:"Pick a build runtime",options:[{label:"Node",value:"node"},{label:"Browser",value:"browser"}]})),l.includes("esbuild")?e.transformer="esbuild":l.includes("@swc/core")?e.transformer="swc":l.includes("sucrase")&&(e.transformer="sucrase"),e.transformer===void 0?(e.transformer=await j({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"&&!l.includes(e.transformer)&&await h({message:`Do you want to install ${e.transformer}?`})&&u.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 j({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 f;switch(e.isolatedDeclarationTransformer){case"oxc":{f="oxc-transform";break}case"swc":{f="@swc/core";break}case"typescript":{f="typescript";break}default:ve("Invalid isolated declaration transformer")}f!==void 0&&!l.includes(f)&&await h({message:`Do you want to install ${f}?`})&&u.push(f)}e.css===void 0&&(e.css=await h({message:"Do you want to use css in your project?",initialValue:!1}));const a=[];if(e.css){const f=await j({message:"Pick a css loader",options:[{label:"PostCSS",value:"postcss"},{hint:"experimental",label:"Lightning CSS",value:"lightningcss"}]});a.push(f);let p=await ie({message:"Pick your loaders",options:[{label:"Sass",value:"sass"},{label:"Stylus",value:"stylus"},{label:"Less",value:"less"}],required:!1});if(p.includes("sass")){const w=await j({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"}]});w!=="sass"&&(p=p.filter(g=>g!=="sass"),p.push(w))}if(a.push(...p),await h({message:`Do you want to install "${a.join('", "')}"?`}))for(const w of a)u.push(...pe[w]);a.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 j({message:"Pick a css minifier",options:[{label:"CSSNano",value:"cssnano"},{label:"Lightning CSS",value:"lightningcss"}]}),a.includes("lightningcss")||await h({message:`Do you want to install "${m}"?`})&&u.push(m));let c="",d="";if(e.isolatedDeclarationTransformer&&(d+=`,
29
- isolatedDeclarationTransformer`),(e.css||e.cssMinifier)&&(d+=`,
34
+ },`),t.spinner.start("Installing packages"),await D(p,{cwd:t.rootDirectory,dev:!0,silent:!0}),t.spinner.stop("Installed packages"),s.success(`
35
+ CSS loaders added!`)},"addCss"),Re=y(t=>{t.addCommand({argument:{description:"Add a packem feature to your project",name:"feature",required:!0},description:"Add a optional packem feature to your project",execute:y(async({argument:s,logger:e,options:a})=>{const o=E(),r=B(L(),a.dir??".");let n;try{n=await z(r,a.config)}catch{e.error("Could not find a packem config file, please run `packem init` first.");return}if(await Me(r)&&!await w({initialValue:!1,message:"Git repository has uncommitted changes. Do you want to proceed?"})){F("Operation cancelled.");return}const i=await te(n,{buffer:!1}),l=i.includes("import")?"esm":"cjs",p=new re(i),m=" transformer,",g=i.includes(" transformer,")?" transformer,":" transformer",c={logger:e,magic:p,packemConfig:i,packemConfigFilePath:n,packemConfigFormat:l,rootDirectory:r,spinner:o,transformerReplaceKey:m,transformerSearchKey:g};s.includes("typedoc")&&await Oe(c),s.includes("react")&&await Ee(c),s.includes("solid")&&await Le(c),s.includes("vue")&&await Be(c),s.includes("svelte")&&await Ne(c),s.includes("css")&&await Ve(c),await ae(n,p.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 Ae=Object.defineProperty,qe=h((t,s)=>Ae(t,"name",{value:s,configurable:!0}),"e$2");const Fe=qe(async(t,s,e,a,o)=>{const r=await z(s,o);let n=await t.import(r,{default:!0,try:!0})||{};return typeof n=="function"&&(n=await n(e,a)),{config:n,path:r}},"loadPackemConfig");var Ge=Object.defineProperty,Ue=h((t,s)=>Ge(t,"name",{value:s,configurable:!0}),"e$1");const Je=Ue(async(t,s)=>{switch(t){case"none":return{};case"react":{const{createReactPreset:e}=await import("../config/preset/react.js");t=e();break}case"solid":{const{createSolidPreset:e}=await import("../config/preset/solid.js");t=e();break}case"svelte":{const{createSveltePreset:e}=await import("../config/preset/svelte.js");t=e();break}case"vue":{const{createVuePreset:e}=await import("../config/preset/vue.js");t=e();break}default:typeof t=="string"&&(t=await s.import(t)||{})}return typeof t=="function"&&(t=t()),t},"loadPreset");var ze=Object.defineProperty,C=h((t,s)=>ze(t,"name",{value:s,configurable:!0}),"r");const Ke=C(t=>{t.addCommand({description:"Demonstrate options required",execute:C(async({logger:s,options:e})=>{let a="build";e.watch?a="watch":e.jit&&(a="jit");const o={};let r;if(e.env)for(const c of e.env)c.key==="NODE_ENV"?r=c.value:o[`process.env.${c.key}`]=JSON.stringify(c.value);r===void 0&&(e.production?r=V:e.development&&(r=ce));const n=[];if(e.external)for(const c of e.external)n.push(c.split(","));const i=B(L(),e.dir??"."),l=de(i,{debug:e.debug}),{config:p,path:m}=await Fe(l,i,r,a,e.config??void 0);s.debug("Using packem config found at",m);const g=await Je(p.preset??"none",l);e.minify&&e.sourcemap===void 0&&(e.sourcemap=!0);try{await pe(i,a,r,s,e.debug,le(p,ue,g,{analyze:e.analyze,cjsInterop:e.cjsInterop,clean:e.clean,dtsOnly:e.dtsOnly,externals:n,killSignal:e.killSignal,minify:e.minify===void 0?r===V:e.minify,onSuccess:e.onSuccess,rollup:{esbuild:{target:e.target},license:{path:e.license},metafile:e.metafile,replace:{values:o},resolveExternals:e.noExternal?{builtins:!1,deps:!1,devDeps:!1,optDeps:!1,peerDeps:!1}:{}},runtime:e.runtime,sourcemap:e.metafile||e.analyze||e.sourcemap,unbundle:e.unbundle,validation:e.validation===!1?!1:{},...e.typedoc?{typedoc:{format:"html"}}:{}}),e.tsconfig??void 0)}catch(c){s.error(c),Q(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:C(s=>{const[e,a]=s.split("=");return{key:e,value:a}},"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:C(s=>{if(s==="SIGTERM"||s==="SIGKILL")return s;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:C(s=>{if(s==="node"||s==="browser")return s;throw new Error("Invalid runtime. Use 'node' or 'browser'.")},"type")},{description:"Enable unbundle mode to preserve source file structure instead of bundling into a single file",name:"unbundle",type:Boolean}]})},"createBuildCommand");var We=Object.defineProperty,x=h((t,s)=>We(t,"name",{value:s,configurable:!0}),"f");const Xe=x(t=>{t.addCommand({description:"Initialize packem configuration",execute:x(async({logger:s,options:e})=>{if(Z("Welcome to packem setup"),O(S(e.dir,"packem.config.mjs"))){s.info("Packem project already initialized, you can use `packem build` to build your project");return}const a=B(L(),e.dir??"."),o=S(a,"package.json");if(!O(o))throw new Error("No package.json found in the directory");const r=await G(o,{resolveCatalogs:!0}),n=[];r.dependencies&&n.push(...Object.keys(r.dependencies)),r.devDependencies&&n.push(...Object.keys(r.devDependencies));const i=!!(r.devDependencies?.typescript??r.dependencies?.typescript),l=[];if(e.typescript===void 0&&!i?(e.typescript=await w({message:"Do you want to install TypeScript?"}),e.typescript&&l.push("typescript@latest")):N.message(`TypeScript version ${r.devDependencies?.typescript??r.dependencies?.typescript} is already installed`),!O(S(a,"tsconfig.json"))){const d=await w({message:"Do you want to use generate a tsconfig.json?"}),u=await w({message:"Do you want to run your code in the DOM?"});if(d){const k=E();k.start("Generating tsconfig.json"),ie(S(a,"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:u?["es2022","dom","dom.iterable"]:["es2022"]}}),k.stop("")}}if(e.runtime===void 0&&(e.runtime=await v({message:"Pick a build runtime",options:[{label:"Node",value:"node"},{label:"Browser",value:"browser"}]})),n.includes("esbuild")?e.transformer="esbuild":n.includes("@swc/core")?e.transformer="swc":n.includes("sucrase")&&(e.transformer="sucrase"),e.transformer===void 0?(e.transformer=await v({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"&&!n.includes(e.transformer)&&await w({message:`Do you want to install ${e.transformer}?`})&&l.push(e.transformer==="swc"?"@swc/core":e.transformer)):N.message(`Transformer ${e.transformer} is already installed.`),e.isolatedDeclarationTransformer===void 0&&(e.isolatedDeclarationTransformer=await w({message:"Do you want to use an isolated declaration types?",initialValue:!1})),e.isolatedDeclarationTransformer===void 0&&(e.isolatedDeclarationTransformer=await v({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:F("Invalid isolated declaration transformer")}d!==void 0&&!n.includes(d)&&await w({message:`Do you want to install ${d}?`})&&l.push(d)}e.css===void 0&&(e.css=await w({message:"Do you want to use css in your project?",initialValue:!1}));const p=[];if(e.css){const d=await v({message:"Pick a css loader",options:[{label:"PostCSS",value:"postcss"},{hint:"experimental",label:"Lightning CSS",value:"lightningcss"}]});p.push(d);let u=await q({message:"Pick your loaders",options:[{label:"Sass",value:"sass"},{label:"Stylus",value:"stylus"},{label:"Less",value:"less"}],required:!1});if(u.includes("sass")){const k=await v({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"}]});k!=="sass"&&(u=u.filter(W=>W!=="sass"),u.push(k))}if(p.push(...u),await w({message:`Do you want to install "${p.join('", "')}"?`}))for(const k of p)l.push(...K[k]);p.push("sourceMap")}e.cssMinifier===void 0&&(e.cssMinifier=await w({message:"Do you want to minify your css?",initialValue:!1}));let m;e.cssMinifier&&(m=await v({message:"Pick a css minifier",options:[{label:"CSSNano",value:"cssnano"},{label:"Lightning CSS",value:"lightningcss"}]}),p.includes("lightningcss")||await w({message:`Do you want to install "${m}"?`})&&l.push(m));let g="",c="";if(e.isolatedDeclarationTransformer&&(c+=`,
36
+ isolatedDeclarationTransformer`),(e.css||e.cssMinifier)&&(c+=`,
30
37
  rollup: {
31
- css: {`),e.css){const f=a.map(p=>((p==="sass-embedded"||p==="node-sass")&&(p="sass"),`${p}Loader`)).join(", ");d+=`
32
- loaders: [${f}],`}if(e.cssMinifier&&m&&(d+=`
33
- minifier: ${m}Minifier,`),(e.css||e.cssMinifier)&&(d+=`
38
+ css: {`),e.css){const d=p.map(u=>((u==="sass-embedded"||u==="node-sass")&&(u="sass"),`${u}Loader`)).join(", ");c+=`
39
+ loaders: [${d}],`}if(e.cssMinifier&&m&&(c+=`
40
+ minifier: ${m}Minifier,`),(e.css||e.cssMinifier)&&(c+=`
34
41
  }
35
- }`),r||n.type==="module"){let f="";if(e.isolatedDeclarationTransformer&&(f+=`import isolatedDeclarationTransformer from "@visulima/packem/dts/isolated/transformer/${e.isolatedDeclarationTransformer}";
36
- `),e.css)for(let p of a)(p==="sass-embedded"||p==="node-sass")&&(p="sass"),f+=`import ${p}Loader from "@visulima/packem/css/loader/${p.toLowerCase()}";
37
- `;e.cssMinifier&&m&&(f+=`import ${m}Minifier from "@visulima/packem/css/minifier/${m.toLowerCase()}";
38
- `),c=`import { defineConfig } from "@visulima/packem/config";
42
+ }`),i||r.type==="module"){let d="";if(e.isolatedDeclarationTransformer&&(d+=`import isolatedDeclarationTransformer from "@visulima/packem/dts/isolated/transformer/${e.isolatedDeclarationTransformer}";
43
+ `),e.css)for(let u of p)(u==="sass-embedded"||u==="node-sass")&&(u="sass"),d+=`import ${u}Loader from "@visulima/packem/css/loader/${u.toLowerCase()}";
44
+ `;e.cssMinifier&&m&&(d+=`import ${m}Minifier from "@visulima/packem/css/minifier/${m.toLowerCase()}";
45
+ `),g=`import { defineConfig } from "@visulima/packem/config";
39
46
  import transformer from "@visulima/packem/transformer/${e.transformer}";
40
- ${f}
47
+ ${d}
41
48
  export default defineConfig({
42
49
  runtime: "${e.runtime}",
43
- transformer${d}
50
+ transformer${c}
44
51
  });
45
- `}else{let f="";if(e.isolatedDeclarationTransformer&&(f+=`const isolatedDeclarationTransformer = require("@visulima/packem/dts/isolated/transformer/${e.isolatedDeclarationTransformer}");
46
- `),e.css)for(let p of a)(p==="sass-embedded"||p==="node-sass")&&(p="sass"),f+=`const ${p}Loader = require("@visulima/packem/css/loader/${p.toLowerCase()}");
47
- `;e.cssMinifier&&m&&(f+=`const ${m}Minifier = require("@visulima/packem/css/minifier/${m.toLowerCase()}");
48
- `),c=`const { defineConfig } = require("@visulima/packem/config");
52
+ `}else{let d="";if(e.isolatedDeclarationTransformer&&(d+=`const isolatedDeclarationTransformer = require("@visulima/packem/dts/isolated/transformer/${e.isolatedDeclarationTransformer}");
53
+ `),e.css)for(let u of p)(u==="sass-embedded"||u==="node-sass")&&(u="sass"),d+=`const ${u}Loader = require("@visulima/packem/css/loader/${u.toLowerCase()}");
54
+ `;e.cssMinifier&&m&&(d+=`const ${m}Minifier = require("@visulima/packem/css/minifier/${m.toLowerCase()}");
55
+ `),g=`const { defineConfig } = require("@visulima/packem/config");
49
56
  const transformer = require("@visulima/packem/transformer/${e.transformer}");
50
- ${f}
57
+ ${d}
51
58
  module.exports = defineConfig({
52
59
  runtime: ${e.runtime},
53
- transformer${d}
60
+ transformer${c}
54
61
  });
55
- `}const y=U(),b=r?"ts":"js";u.length>0&&(y.start("Installing packages"),await q(u,{cwd:i,dev:!0,silent:!0}),y.stop("Installed packages")),y.start(`Creating packem.config.${b}`),Se(C(i,`packem.config.${b}`),c),y.stop(`Created packem.config.${b}`),he("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:I(s=>{if(typeof s=="string"&&["esbuild","sucrase","swc"].includes(s))return s;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:I(s=>{if(typeof s=="string"&&["none","oxc","swc","typescript"].includes(s))return s;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:I(s=>{if(s==="node"||s==="browser")return s;throw new Error("Invalid runtime. Use 'node' or 'browser'.")},"type")}]})},"createInitCommand");var vt=Object.defineProperty,M=v((t,s)=>vt(t,"name",{value:s,configurable:!0}),"a");const ht=M(async({cwd:t,dryRun:s,logger:e})=>{if(s)e.info("Dry run enabled. No changes will be made.");else{const o=Ve({input:P.stdin,output:P.stdout});e.warn(`
62
+ `}const f=E(),b=i?"ts":"js";l.length>0&&(f.start("Installing packages"),await D(l,{cwd:a,dev:!0,silent:!0}),f.stop("Installed packages")),f.start(`Creating packem.config.${b}`),oe(S(a,`packem.config.${b}`),g),f.stop(`Created packem.config.${b}`),ee("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:x(s=>{if(typeof s=="string"&&["esbuild","sucrase","swc"].includes(s))return s;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:x(s=>{if(typeof s=="string"&&["none","oxc","swc","typescript"].includes(s))return s;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:x(s=>{if(s==="node"||s==="browser")return s;throw new Error("Invalid runtime. Use 'node' or 'browser'.")},"type")}]})},"createInitCommand");var _e=Object.defineProperty,$=h((t,s)=>_e(t,"name",{value:s,configurable:!0}),"a");const Ye=$(async({cwd:t,dryRun:s,logger:e})=>{if(s)e.info("Dry run enabled. No changes will be made.");else{const o=ge({input:j.stdin,output:j.stdout});e.warn(`
56
63
 
57
64
  Before proceeding, review the migration guide at https://www.visulima.com/docs/package/packem, as this process will modify your files.
58
- Uncommitted changes will be lost. Use the --dry-run flag to preview changes without applying them.`);const n=await o.question("Continue? (Y/n) ");if(o.close(),!(n.toLowerCase()==="y"||n==="")){e.error("Migration cancelled."),P.exitCode=1;return}}t&&P.chdir(t);let i=!1;await $t(s,e)&&(i=!0),await xt(s,e)&&(i=!0),i?e.success("Migration completed. Remember to run install command with your package manager."):(e.error("No migration performed."),P.exitCode=1)},"migrate"),oe={bunchee:"@visulima/packem",tsup:"@visulima/packem","tsup-node":"@visulima/packem",unbuild:"@visulima/packem"},kt={dependencies:`^${Q.version}`,devDependencies:`^${Q.version}`,peerDependencies:"*"},$t=M(async(t,s)=>{if(!ae("package.json"))return s.error("No package.json found"),!1;const e=await Fe("package.json","utf8"),i=JSON.parse(e);let o=!1;for(const[r,u]of Object.entries(kt))for(const[a,m]of Object.entries(oe))i[r]?.[a]&&(s.info(`Migrating \`${r}\` from ${a} to ${m}.`),o=!0,i[r]=St(i[r],a,m,u));if(i.scripts)for(const r of Object.keys(i.scripts)){for(const[u,a]of Object.entries(oe))i.scripts[r].includes(u)&&(s.info(`Migrating \`${r}\` script from ${u} to packem`),o=!0,i.scripts[r]=i.scripts[r].replaceAll(new RegExp(`\\b${u}\\b`,"g"),"packem").replaceAll(new RegExp(`\\b${u}-node\\b`,"g"),"packem"));i.scripts[r].includes("tsup")&&(s.info(`Migrating \`${r}\` script from tsup to packem`),o=!0,i.scripts[r]=i.scripts[r].replaceAll(/\btsup(?:-node)?/g,"packem build").replaceAll(/\bbuild\b/g,"build")),i.scripts[r].includes("unbuild")&&(s.info(`Migrating \`${r}\` script from unbuild to packem`),o=!0,i.scripts[r]=i.scripts[r].replaceAll(/\bunbuild\b/g,"packem build")),i.scripts[r].includes("bunchee")&&(s.info(`Migrating \`${r}\` script from bunchee to packem`),o=!0,i.scripts[r]=i.scripts[r].replaceAll(/\bbunchee\b/g,"packem build"))}const n=["tsup","unbuild","bunchee"];for(const r of n)i[r]&&s.info(`Found \`${r}\` config field in package.json. Consider moving to packem.config.ts`);if(!o)return s.warn("No migratable bundler dependencies found in package.json"),!1;const l=`${JSON.stringify(i,null,e.includes(" ")?" ":2)}
59
- `;return t?(s.info("[dry-run] package.json changes:"),s.info("Old content:"),console.info(e),s.info("New content:"),console.info(l)):(await Re("package.json",l),s.success("Migrated `package.json`")),!0},"migratePackageJson"),jt=["tsup.config.ts","tsup.config.cts","tsup.config.mts","tsup.config.js","tsup.config.cjs","tsup.config.mjs","tsup.config.json","build.config.ts","build.config.cts","build.config.mts","build.config.js","build.config.cjs","build.config.mjs","bunchee.config.ts","bunchee.config.cts","bunchee.config.mts","bunchee.config.js","bunchee.config.cjs","bunchee.config.mjs"],xt=M(async(t,s)=>{let e=!1;for(const i of jt)ae(i)&&(s.info(`Found config file \`${i}\`. Consider creating packem.config.ts instead.`),s.warn("Manual migration required for config files. See https://www.visulima.com/docs/package/packem"),e=!0);return e||s.warn("No bundler config files found"),e},"migrateConfigFiles"),St=M((t,s,e,i)=>{const o={};for(const n of Object.keys(t))n===s?o[e]=i||t[s]:o[n]=t[n];return o},"renameKey"),Ct=M(t=>{t.addCommand({description:"Migrate from other bundlers (tsup, unbuild, bunchee, etc.) to packem",execute:M(async({logger:s,options:e})=>{await ht({cwd:e.cwd,dryRun:e.dryRun,logger:s})},"execute"),name:"migrate",options:[{defaultValue:".",description:"The directory to migrate",name:"cwd",type:String},{description:"Preview changes without applying them",name:"dry-run",type:Boolean}]})},"createMigrateCommand");try{require("node:module")?.enableCompileCache?.()||require("v8-compile-cache")}catch{}const T=fe("packem",{logger:await ge({reporters:[new ye({error:{hideErrorCauseCodeView:!0,hideErrorCodeView:!0,hideErrorErrorsCodeView:!0}})],scope:"packem"}),packageName:qe,packageVersion:ce});wt(T);yt(T);_e(T);Ct(T);T.run({shouldExitProcess:!1});
65
+ Uncommitted changes will be lost. Use the --dry-run flag to preview changes without applying them.`);const r=await o.question("Continue? (Y/n) ");if(o.close(),!(r.toLowerCase()==="y"||r==="")){e.error("Migration cancelled."),j.exitCode=1;return}}t&&j.chdir(t);let a=!1;await Qe(s,e)&&(a=!0),await es(s,e)&&(a=!0),a?e.success("Migration completed. Remember to run install command with your package manager."):(e.error("No migration performed."),j.exitCode=1)},"migrate"),A={bunchee:"@visulima/packem",tsup:"@visulima/packem","tsup-node":"@visulima/packem",unbuild:"@visulima/packem"},He={dependencies:`^${R.version}`,devDependencies:`^${R.version}`,peerDependencies:"*"},Qe=$(async(t,s)=>{if(!U("package.json"))return s.error("No package.json found"),!1;const e=await me("package.json","utf8"),a=JSON.parse(e);let o=!1;for(const[i,l]of Object.entries(He))for(const[p,m]of Object.entries(A))a[i]?.[p]&&(s.info(`Migrating \`${i}\` from ${p} to ${m}.`),o=!0,a[i]=ss(a[i],p,m,l));if(a.scripts)for(const i of Object.keys(a.scripts)){for(const[l,p]of Object.entries(A))a.scripts[i].includes(l)&&(s.info(`Migrating \`${i}\` script from ${l} to packem`),o=!0,a.scripts[i]=a.scripts[i].replaceAll(new RegExp(String.raw`\b${l}\b`,"g"),"packem").replaceAll(new RegExp(String.raw`\b${l}-node\b`,"g"),"packem"));a.scripts[i].includes("tsup")&&(s.info(`Migrating \`${i}\` script from tsup to packem`),o=!0,a.scripts[i]=a.scripts[i].replaceAll(/\btsup(?:-node)?/g,"packem build").replaceAll(/\bbuild\b/g,"build")),a.scripts[i].includes("unbuild")&&(s.info(`Migrating \`${i}\` script from unbuild to packem`),o=!0,a.scripts[i]=a.scripts[i].replaceAll(/\bunbuild\b/g,"packem build")),a.scripts[i].includes("bunchee")&&(s.info(`Migrating \`${i}\` script from bunchee to packem`),o=!0,a.scripts[i]=a.scripts[i].replaceAll(/\bbunchee\b/g,"packem build"))}const r=["tsup","unbuild","bunchee"];for(const i of r)a[i]&&s.info(`Found \`${i}\` config field in package.json. Consider moving to packem.config.ts`);if(!o)return s.warn("No migratable bundler dependencies found in package.json"),!1;const n=`${JSON.stringify(a,null,e.includes(" ")?" ":2)}
66
+ `;return t?(s.info("[dry-run] package.json changes:"),s.info("Old content:"),console.info(e),s.info("New content:"),console.info(n)):(await fe("package.json",n),s.success("Migrated `package.json`")),!0},"migratePackageJson"),Ze=["tsup.config.ts","tsup.config.cts","tsup.config.mts","tsup.config.js","tsup.config.cjs","tsup.config.mjs","tsup.config.json","build.config.ts","build.config.cts","build.config.mts","build.config.js","build.config.cjs","build.config.mjs","bunchee.config.ts","bunchee.config.cts","bunchee.config.mts","bunchee.config.js","bunchee.config.cjs","bunchee.config.mjs"],es=$(async(t,s)=>{let e=!1;for(const a of Ze)U(a)&&(s.info(`Found config file \`${a}\`. Consider creating packem.config.ts instead.`),s.warn("Manual migration required for config files. See https://www.visulima.com/docs/package/packem"),e=!0);return e||s.warn("No bundler config files found"),e},"migrateConfigFiles"),ss=$((t,s,e,a)=>{const o={};for(const r of Object.keys(t))r===s?o[e]=a||t[s]:o[r]=t[r];return o},"renameKey"),ts=$(t=>{t.addCommand({description:"Migrate from other bundlers (tsup, unbuild, bunchee, etc.) to packem",execute:$(async({logger:s,options:e})=>{await Ye({cwd:e.cwd,dryRun:e.dryRun,logger:s})},"execute"),name:"migrate",options:[{defaultValue:".",description:"The directory to migrate",name:"cwd",type:String},{description:"Preview changes without applying them",name:"dry-run",type:Boolean}]})},"createMigrateCommand");try{require("node:module")?.enableCompileCache?.()||require("v8-compile-cache")}catch{}const P=_("packem",{logger:await Y({reporters:[new H({error:{hideErrorCauseCodeView:!0,hideErrorCodeView:!0,hideErrorErrorsCodeView:!0}})],scope:"packem"}),packageName:ye,packageVersion:J});Xe(P);Ke(P);Re(P);ts(P);P.run({shouldExitProcess:!1});
@@ -1,3 +1,3 @@
1
- import type { BuildPreset } from "../../types.d.ts";
2
- declare const autoPreset: BuildPreset;
1
+ import type { BuildConfig } from "../../types.d.ts";
2
+ declare const autoPreset: BuildConfig;
3
3
  export default autoPreset;
@@ -0,0 +1,59 @@
1
+ import type { BabelPluginConfig } from "@visulima/packem-rollup/babel";
2
+ import type { BuildConfig } from "../../types.d.ts";
3
+ export interface ReactPresetOptions {
4
+ /**
5
+ * Enable React Compiler optimization
6
+ * @default false
7
+ */
8
+ compiler?: boolean | {
9
+ /**
10
+ * React Compiler compilation mode
11
+ * @default "infer"
12
+ */
13
+ compilationMode?: "infer" | "annotation";
14
+ /**
15
+ * React Compiler panic threshold
16
+ * @default "critical_errors"
17
+ */
18
+ panicThreshold?: "critical_errors" | "all_errors";
19
+ };
20
+ /**
21
+ * Custom Babel plugins to add
22
+ */
23
+ plugins?: BabelPluginConfig["plugins"];
24
+ /**
25
+ * Custom Babel presets to add
26
+ */
27
+ presets?: BabelPluginConfig["presets"];
28
+ }
29
+ /**
30
+ * React preset for Packem. Configures Babel with React presets and optionally React Compiler.
31
+ * @description This preset configures Babel to run before your main transformer (esbuild/SWC/etc.).
32
+ * Babel handles JSX transformation, while TypeScript is handled by the transformer via parser plugins.
33
+ * This matches the approach used by @vitejs/plugin-react.
34
+ * @example
35
+ * ```typescript
36
+ * // Basic usage
37
+ * export default defineConfig({
38
+ * preset: "react"
39
+ * });
40
+ *
41
+ * // With React Compiler
42
+ * import { createReactPreset } from "@visulima/packem/config/preset/react";
43
+ * export default defineConfig({
44
+ * preset: createReactPreset({
45
+ * compiler: true
46
+ * })
47
+ * });
48
+ *
49
+ * // With custom options
50
+ * export default defineConfig({
51
+ * preset: createReactPreset({
52
+ * compiler: {
53
+ * compilationMode: "annotation"
54
+ * }
55
+ * })
56
+ * });
57
+ * ```
58
+ */
59
+ export declare const createReactPreset: (options?: ReactPresetOptions) => BuildConfig;
@@ -0,0 +1 @@
1
+ var p=Object.defineProperty;var n=(r,e)=>p(r,"name",{value:e,configurable:!0});var u=Object.defineProperty,d=n((r,e)=>u(r,"name",{value:e,configurable:!0}),"p");const h=d((r={})=>{const{compiler:e=!1,plugins:t=[],presets:a=[]}=r,c=[],o=[];if(e){const l=typeof e=="object"?e:{};c.push(["babel-plugin-react-compiler",{compilationMode:l.compilationMode??"infer",panicThreshold:l.panicThreshold??"critical_errors"}])}o.push(["@babel/preset-react",{runtime:"automatic"}]);const i=[...c,...Array.isArray(t)?t:[]],s=[...o,...Array.isArray(a)?a:[]];return{rollup:{babel:{plugins:i.length>0?i:void 0,presets:s.length>0?s:void 0}},validation:{dependencies:{hoisted:{exclude:[]},unused:{exclude:["react","react-dom"]}}}}},"createReactPreset");export{h as createReactPreset};
@@ -0,0 +1,101 @@
1
+ import type { BabelPluginConfig } from "@visulima/packem-rollup/babel";
2
+ import type { BuildConfig } from "../../types.d.ts";
3
+ export interface SolidPresetOptions {
4
+ /**
5
+ * Pass any additional babel transform options. They will be merged with
6
+ * the transformations required by Solid.
7
+ */
8
+ babel?: BabelPluginConfig | ((source: string, id: string) => BabelPluginConfig | Promise<BabelPluginConfig>);
9
+ /**
10
+ * Custom Babel plugins to add
11
+ */
12
+ plugins?: BabelPluginConfig["plugins"];
13
+ /**
14
+ * Custom Babel presets to add
15
+ */
16
+ presets?: BabelPluginConfig["presets"];
17
+ /**
18
+ * SolidJS-specific options for babel-preset-solid
19
+ */
20
+ solidOptions?: {
21
+ /**
22
+ * Array of Component exports from module, that aren't included by default with the library.
23
+ * This plugin will automatically import them if it comes across them in the JSX.
24
+ * @default ["For","Show","Switch","Match","Suspense","SuspenseList","Portal","Index","Dynamic","ErrorBoundary"]
25
+ */
26
+ builtIns?: string[];
27
+ /**
28
+ * Boolean indicates whether to set current render context on Custom Elements and slots.
29
+ * Useful for seemless Context API with Web Components.
30
+ * @default true
31
+ */
32
+ contextToCustomElements?: boolean;
33
+ /**
34
+ * Boolean to indicate whether to enable automatic event delegation on camelCase.
35
+ * @default true
36
+ */
37
+ delegateEvents?: boolean;
38
+ /**
39
+ * The output mode of the compiler.
40
+ * Can be:
41
+ * - "dom" is standard output
42
+ * - "ssr" is for server side rendering of strings.
43
+ * - "universal" is for using custom renderers from solid-js/universal
44
+ * @default "dom"
45
+ */
46
+ generate?: "ssr" | "dom" | "universal";
47
+ /**
48
+ * Indicate whether the output should contain hydratable markers.
49
+ * @default false
50
+ */
51
+ hydratable?: boolean;
52
+ /**
53
+ * The name of the runtime module to import the methods from.
54
+ * @default "solid-js/web"
55
+ */
56
+ moduleName?: string;
57
+ /**
58
+ * Boolean indicates whether smart conditional detection should be used.
59
+ * This optimizes simple boolean expressions and ternaries in JSX.
60
+ * @default true
61
+ */
62
+ wrapConditionals?: boolean;
63
+ };
64
+ }
65
+ /**
66
+ * SolidJS preset for Packem. Configures Babel with babel-preset-solid.
67
+ * @description This preset configures Babel to run before your main transformer (esbuild/SWC/etc.).
68
+ * Babel handles JSX transformation for SolidJS using babel-preset-solid. TypeScript is handled
69
+ * automatically via parser plugins based on file extensions (no preset needed).
70
+ * @example
71
+ * ```typescript
72
+ * // Basic usage
73
+ * export default defineConfig({
74
+ * preset: "solid"
75
+ * });
76
+ *
77
+ * // With custom Solid options
78
+ * import { createSolidPreset } from "@visulima/packem/config/preset/solid";
79
+ * export default defineConfig({
80
+ * preset: createSolidPreset({
81
+ * solidOptions: {
82
+ * generate: "ssr",
83
+ * hydratable: true
84
+ * }
85
+ * })
86
+ * });
87
+ *
88
+ * // With custom Babel options
89
+ * export default defineConfig({
90
+ * preset: createSolidPreset({
91
+ * solidOptions: {
92
+ * moduleName: "solid-js/web"
93
+ * },
94
+ * babel: {
95
+ * // Additional babel options
96
+ * }
97
+ * })
98
+ * });
99
+ * ```
100
+ */
101
+ export declare const createSolidPreset: (options?: SolidPresetOptions) => BuildConfig;
@@ -0,0 +1 @@
1
+ var g=Object.defineProperty;var u=(s,e)=>g(s,"name",{value:e,configurable:!0});var f=Object.defineProperty,d=u((s,e)=>f(s,"name",{value:e,configurable:!0}),"o");const y=d(s=>{const e={contextToCustomElements:s?.contextToCustomElements??!0,delegateEvents:s?.delegateEvents??!0,generate:s?.generate??"dom",hydratable:s?.hydratable??!1,moduleName:s?.moduleName??"solid-js/web",wrapConditionals:s?.wrapConditionals??!0};return s?.builtIns!==void 0&&(e.builtIns=s.builtIns),e},"buildSolidPresetOptions"),m=d((s,e,o,i)=>{if(!e||typeof e=="function")return s;let t=o;if(e.plugins){const l=Array.isArray(e.plugins)?e.plugins:[];t=[...o||[],...l]}let r=i;if(e.presets){const l=Array.isArray(e.presets)?e.presets:[];r=[...i||[],...l]}return{...s,...e,plugins:t&&t.length>0?t:void 0,presets:r&&r.length>0?r:void 0}},"mergeUserBabelOptions"),h=d((s={})=>{const{babel:e,plugins:o=[],presets:i=[],solidOptions:t={}}=s,r=[],l=[],p=["babel-preset-solid",y(t)];l.push(p);const a=[...r,...Array.isArray(o)?o:[]],n=[...l,...Array.isArray(i)?i:[]],c={ast:!1,babelrc:!1,configFile:!1,plugins:a.length>0?a:void 0,presets:n.length>0?n:void 0,sourceMaps:!0},b=m(c,e,a,n);return{externals:["solid-js","solid-js/web","solid-js/store"],rollup:{babel:b},validation:{dependencies:{hoisted:{exclude:[]},unused:{exclude:["solid-js"]}}}}},"createSolidPreset");export{h as createSolidPreset};
@@ -0,0 +1,71 @@
1
+ import type { BuildConfig } from "../../types.d.ts";
2
+ export interface SveltePresetOptions {
3
+ /**
4
+ * Svelte plugin options
5
+ */
6
+ pluginOptions?: {
7
+ /**
8
+ * Svelte compiler options
9
+ */
10
+ compilerOptions?: {
11
+ [key: string]: unknown;
12
+ /**
13
+ * Custom element mode
14
+ * @default false
15
+ */
16
+ customElement?: boolean;
17
+ /**
18
+ * Enable dev mode
19
+ * @default false
20
+ */
21
+ dev?: boolean;
22
+ /**
23
+ * Generate mode: "client" for client-side rendering, "server" for SSR
24
+ * @default "client"
25
+ */
26
+ generate?: "client" | "server" | false;
27
+ /**
28
+ * Enable hydratable output
29
+ * @default false
30
+ */
31
+ hydratable?: boolean;
32
+ };
33
+ /**
34
+ * Exclude patterns for Svelte files
35
+ */
36
+ exclude?: RegExp | RegExp[];
37
+ /**
38
+ * Include patterns for Svelte files
39
+ * @default [/\.svelte$/]
40
+ */
41
+ include?: RegExp | RegExp[];
42
+ /**
43
+ * Preprocessor options
44
+ */
45
+ preprocess?: unknown;
46
+ };
47
+ }
48
+ /**
49
+ * Svelte preset for Packem. Configures Rollup with rollup-plugin-svelte.
50
+ * @description This preset configures the Svelte plugin to handle .svelte file compilation.
51
+ * @example
52
+ * ```typescript
53
+ * // Basic usage
54
+ * export default defineConfig({
55
+ * preset: "svelte"
56
+ * });
57
+ *
58
+ * // With custom options
59
+ * import { createSveltePreset } from "@visulima/packem/config/preset/svelte";
60
+ * export default defineConfig({
61
+ * preset: createSveltePreset({
62
+ * pluginOptions: {
63
+ * compilerOptions: {
64
+ * hydratable: true
65
+ * }
66
+ * }
67
+ * })
68
+ * });
69
+ * ```
70
+ */
71
+ export declare const createSveltePreset: (options?: SveltePresetOptions) => BuildConfig;
@@ -0,0 +1 @@
1
+ var s=Object.defineProperty;var t=(r,e)=>s(r,"name",{value:e,configurable:!0});import{_ as n}from"../../packem_shared/index-CUp9WuCG.js";import o from"rollup-plugin-svelte";var l=Object.defineProperty,i=t((r,e)=>l(r,"name",{value:e,configurable:!0}),"n");const d=i((r={})=>{const{pluginOptions:e={}}=r;return{rollup:{plugins:[{enforce:"pre",plugin:o({compilerOptions:{generate:"client",runes:!0,...e.compilerOptions},emitCss:!1,exclude:e.exclude,extensions:[".svelte"],include:e.include??[/\.svelte$/],preprocess:e.preprocess})}],resolve:{browser:!0,exportConditions:["svelte"],extensions:[...n,".svelte"]}},validation:{dependencies:{hoisted:{exclude:[]},unused:{exclude:["svelte"]}}}}},"createSveltePreset");export{d as createSveltePreset};
@@ -0,0 +1,53 @@
1
+ import type { BuildConfig } from "../../types.d.ts";
2
+ export interface VuePresetOptions {
3
+ /**
4
+ * Vue plugin options
5
+ */
6
+ pluginOptions?: {
7
+ /**
8
+ * Enable custom elements mode
9
+ * @default false
10
+ */
11
+ customElement?: boolean;
12
+ /**
13
+ * Exclude patterns for Vue files
14
+ */
15
+ exclude?: RegExp | RegExp[];
16
+ /**
17
+ * Include patterns for Vue files
18
+ * @default [/\.vue$/]
19
+ */
20
+ include?: RegExp | RegExp[];
21
+ /**
22
+ * Template compiler options
23
+ */
24
+ template?: {
25
+ compilerOptions?: {
26
+ [key: string]: unknown;
27
+ isCustomElement?: (tag: string) => boolean;
28
+ };
29
+ };
30
+ };
31
+ }
32
+ /**
33
+ * Vue preset for Packem. Configures Rollup with unplugin-vue.
34
+ * @description This preset configures the Vue plugin to handle .vue file compilation.
35
+ * @example
36
+ * ```typescript
37
+ * // Basic usage
38
+ * export default defineConfig({
39
+ * preset: "vue"
40
+ * });
41
+ *
42
+ * // With custom options
43
+ * import { createVuePreset } from "@visulima/packem/config/preset/vue";
44
+ * export default defineConfig({
45
+ * preset: createVuePreset({
46
+ * pluginOptions: {
47
+ * customElement: true
48
+ * }
49
+ * })
50
+ * });
51
+ * ```
52
+ */
53
+ export declare const createVuePreset: (options?: VuePresetOptions) => BuildConfig;
@@ -0,0 +1 @@
1
+ var l=Object.defineProperty;var u=(t,e)=>l(t,"name",{value:e,configurable:!0});import n from"unplugin-vue/rollup";var r=Object.defineProperty,o=u((t,e)=>r(t,"name",{value:e,configurable:!0}),"n");const a=o((t={})=>{const{pluginOptions:e={}}=t;return{rollup:{plugins:[{enforce:"pre",plugin:n({customElement:e.customElement??!1,exclude:e.exclude,exportMode:"default",include:e.include??[/\.vue$/],template:e.template})}]},validation:{dependencies:{hoisted:{exclude:[]},unused:{exclude:["vue"]}}}}},"createVuePreset");export{a as createVuePreset};
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-DFigeRU2.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};
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{j as g}from"./packem_shared/index-ChtiNkgT.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,3 @@
1
+ var i=Object.defineProperty;var c=(e,r)=>i(e,"name",{value:r,configurable:!0});import{isAccessibleSync as s,readJsonSync as u,writeJsonSync as f}from"@visulima/fs";import{join as g}from"@visulima/path";var l=Object.defineProperty,p=c((e,r)=>l(e,"name",{value:r,configurable:!0}),"a$1"),v=Object.defineProperty,y=p((e,r)=>v(e,"name",{value:r,configurable:!0}),"a"),b=Object.defineProperty,m=y((e,r)=>b(e,"name",{value:r,configurable:!0}),"t");const w=m((e,r,n)=>{const a=new RegExp(String.raw`(<!-- ${r} -->)[\s\S]*?(<!-- /${r} -->)`,"g");if(a.test(e))return e.replace(a,`$1
2
+ ${n}
3
+ $2`)},"replaceContentWithinMarker");var d=Object.defineProperty,S=c((e,r)=>d(e,"name",{value:r,configurable:!0}),"i");const x=S((e,r,n,a)=>{try{let t={};const o=g(r,"keystore.json");a&&s(o)&&(t=u(o)),t[e]===void 0&&(t[e]=new Date().toISOString()),f(o,t,{overwrite:!0})}catch(t){n.debug({context:[t],message:t.message,prefix:"cache-key-store"})}},"createOrUpdateKeyStorage");export{x as d,w as g};