@visulima/packem 2.0.0-alpha.83 → 2.0.0-alpha.84

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 CHANGED
@@ -1,3 +1,16 @@
1
+ ## @visulima/packem [2.0.0-alpha.84](https://github.com/visulima/packem/compare/@visulima/packem@2.0.0-alpha.83...@visulima/packem@2.0.0-alpha.84) (2026-06-03)
2
+
3
+ ### Bug Fixes
4
+
5
+ * **packem:** replace node-resolve with oxc resolver & isolate DTS cache per entry-set ([#206](https://github.com/visulima/packem/issues/206)) ([b2eb482](https://github.com/visulima/packem/commit/b2eb4822b44393add900d1d2272bc886b13ce738))
6
+
7
+
8
+ ### Dependencies
9
+
10
+ * **@visulima/rollup-plugin-css:** upgraded to 1.0.0-alpha.51
11
+ * **@visulima/rollup-plugin-dts:** upgraded to 1.0.0-alpha.32
12
+ * **@visulima/packem-rollup:** upgraded to 1.0.0-alpha.71
13
+
1
14
  ## @visulima/packem [2.0.0-alpha.83](https://github.com/visulima/packem/compare/@visulima/packem@2.0.0-alpha.82...@visulima/packem@2.0.0-alpha.83) (2026-06-03)
2
15
 
3
16
  ### Bug Fixes
@@ -1,5 +1,5 @@
1
1
  import { BuildContext } from '@visulima/packem-share/types';
2
- import { I as InternalBuildOptions } from "../../packem_shared/types.d-Cm6dnCyD.js";
2
+ import { I as InternalBuildOptions } from "../../packem_shared/types.d-DOt53hsx.js";
3
3
  import '@arethetypeswrong/core';
4
4
  import '@visulima/packem-plugins';
5
5
  import '@visulima/packem-plugins/oxc';
@@ -1,3 +1,3 @@
1
- var $=Object.defineProperty;var m=(e,t)=>$(e,"name",{value:t,configurable:!0});import{$ as y,B as j,m as E,q as P}from"../../packem_shared/create-or-update-key-storage-DUTe5Prf.js";import{readdirSync as A}from"node:fs";import{replaceContentWithinMarker as _}from"@visulima/packem-share";import{Application as b}from"typedoc";import{_ as f}from"../../packem_shared/utils-nmTpa3um.js";var C=Object.defineProperty,h=m((e,t)=>C(e,"name",{value:t,configurable:!0}),"d");const F=h((e,t,o,i,n)=>{const a=A(e,{withFileTypes:!0}).filter(s=>s.isFile());let r="";for(const s of a)s.name==="README.md"&&t>1||(r+=y(f(e,s.name)).replaceAll(`<!-- ${o}`,`<!-- _REPLACE_${o}`).replaceAll("<!-- ${marker}",`<!-- _REPLACE_\\${o}`));if(r==="")return;const c=y(i),p=_(c,o,`
1
+ var $=Object.defineProperty;var m=(e,t)=>$(e,"name",{value:t,configurable:!0});import{$ as y,B as j,m as E,q as P}from"../../packem_shared/create-or-update-key-storage-Cp_qI2Lt.js";import{_ as f}from"../../packem_shared/utils-nmTpa3um.js";import{readdirSync as A}from"node:fs";import{replaceContentWithinMarker as _}from"@visulima/packem-share";import{Application as b}from"typedoc";var C=Object.defineProperty,h=m((e,t)=>C(e,"name",{value:t,configurable:!0}),"d");const F=h((e,t,o,i,n)=>{const a=A(e,{withFileTypes:!0}).filter(s=>s.isFile());let r="";for(const s of a)s.name==="README.md"&&t>1||(r+=y(f(e,s.name)).replaceAll(`<!-- ${o}`,`<!-- _REPLACE_${o}`).replaceAll("<!-- ${marker}",`<!-- _REPLACE_\\${o}`));if(r==="")return;const c=y(i),p=_(c,o,`
2
2
  ${r}`);if(!p){n.error({message:`Could not find the typedoc marker: <!-- ${o} --><!-- /${o} --> in ${i}`,prefix:"typedoc"});return}c!==p&&j(i,p.replaceAll(`<!-- _REPLACE_${o}`,`<!-- ${o}`).replaceAll(`<!-- _REPLACE_\\${o}`,"<!-- ${marker}"),{overwrite:!0})},"inlineMarkdownIntoReadme"),R=h((e,t,o,i)=>{if(e==="inline"&&o===void 0)throw new Error("The `readmePath` option is required when using the `inline` format.");if(e!=="inline"&&typeof o=="string"&&i.warn({message:"The `readmePath` option is only used when the `inline` format is used.",prefix:"typedoc"}),e==="json"&&!t?.endsWith(".json"))throw new Error(t===void 0?"The `jsonFileName` option is required when using the `json` format.":"The `jsonFileName` option must end with `.json`.");e!=="json"&&typeof t=="string"&&i.warn({message:"The `jsonFileName` option is only used when the `json` format is used.",prefix:"typedoc"})},"validateFormatOptions"),T=h(async(e,t,o,i)=>{if(t.length===0)return;const{format:n,jsonFileName:a,marker:r,output:c,plugin:p,readmePath:s,...g}=e;R(n,a,s,i);const k=t.map(v=>v.input),u=p??[];u.push("typedoc-plugin-rename-defaults"),(n==="inline"||n==="markdown")&&u.push("typedoc-plugin-markdown");const l=await b.bootstrapWithPlugins({...g,compilerOptions:{allowJs:!0,declaration:!1,declarationMap:!1,esModuleInterop:!0,module:99,moduleResolution:100,noEmit:!0,noImplicitAny:!1,skipLibCheck:!0,sourceMap:!1,target:99,...g.compilerOptions},entryPoints:k,hideGenerator:!0,out:o,plugin:u,...n==="inline"?{hideBreadcrumbs:!0,hidePageHeader:!0,navigation:!1,outputFileStrategy:"modules",useCodeBlocks:!0}:{}},[]),d=await l.convert();if(d){if(n==="json")await l.generateJson(d,a);else if(n==="html")await l.generateDocs(d,o);else if(await l.generateOutputs(d),n==="inline"){if(r===void 0)throw new Error("The `marker` option is required when using the `inline` format.");F(o,t.length,r,s,i)}}},"generateReferenceDocumentation");var D=Object.defineProperty,w=m((e,t)=>D(e,"name",{value:t,configurable:!0}),"p");const L=w(e=>e.logger,"getLogger"),H=w(async(e,t,o,i)=>{if(e.options.typedoc&&e.options.typedoc.format!==void 0){const n=L(e);let a="unknown";e.pkg.dependencies?.typedoc?a=e.pkg.dependencies.typedoc:e.pkg.devDependencies?.typedoc&&(a=e.pkg.devDependencies.typedoc),t&&E("typedoc",t,n,!0),i&&n.raw(`
3
3
  `),n.info({message:`Using ${P("typedoc")} ${a} to generate reference documentation`,prefix:"typedoc"}),await e.hooks.callHook("typedoc:before",e);let r=e.options.rootDir;e.options.typedoc.output?r=e.options.typedoc.output:e.options.typedoc.format==="inline"&&t?r=f(t,"typedoc"):e.options.typedoc.format!=="json"&&(r=f(r,"api-docs")),await T(e.options.typedoc,e.options.entries,r,n),await e.hooks.callHook("typedoc:done",e)}},"builder");export{H as default};
package/dist/cli/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env node
2
- var re=Object.defineProperty;var h=(t,e)=>re(t,"name",{value:e,configurable:!0});import{createCerebro as ie}from"@visulima/cerebro";import oe from"@visulima/cerebro/logger/pail";import{N as z,m as U,B as ce,M as le,l as de,c as ue,d as pe,f as me,g as fe,T as ge,i as G,k as ye,n as we,h as be}from"../packem_shared/index-BcKJ8RJU.js";import j,{cwd as A,exit as ve}from"node:process";import{installPackage as C}from"@antfu/install-pkg";import{confirm as w,select as v,multiselect as J,spinner as I,cancel as F,isCancel as _,intro as H,log as N,outro as Y}from"@clack/prompts";import he from"magic-string";import{exec as ke}from"tinyexec";import{_ as S,L as T}from"../packem_shared/utils-nmTpa3um.js";import{PRODUCTION_ENV as X,DEVELOPMENT_ENV as $e}from"@visulima/packem-share/constants";import{createJiti as Se}from"jiti";import{writeFile as Q,readFile as Ce}from"node:fs/promises";import{q as je,w as Pe,i as R,B as xe}from"../packem_shared/create-or-update-key-storage-DUTe5Prf.js";import{existsSync as q}from"node:fs";import{parseEnv as K}from"node:util";import{createInterface as Ee}from"node:readline/promises";import __cjs_mod__ from "node:module"; // -- packem CommonJS require shim --
2
+ var re=Object.defineProperty;var h=(t,e)=>re(t,"name",{value:e,configurable:!0});import{createCerebro as ie}from"@visulima/cerebro";import oe from"@visulima/cerebro/logger/pail";import{N as z,m as U,l as ce,c as le,T as de,d as ue,f as pe,I as me,g as G,i as fe,n as ge,h as ye}from"../packem_shared/index-C1JIQmoZ.js";import j,{cwd as A,exit as we}from"node:process";import{installPackage as C}from"@antfu/install-pkg";import{confirm as w,select as v,multiselect as J,spinner as N,cancel as F,isCancel as _,intro as H,log as I,outro as Y}from"@clack/prompts";import{a as be,M as ve,q as he,w as ke,i as R,B as $e}from"../packem_shared/create-or-update-key-storage-Cp_qI2Lt.js";import{_ as S,L as T}from"../packem_shared/utils-nmTpa3um.js";import Se from"magic-string";import{exec as Ce}from"tinyexec";import{PRODUCTION_ENV as X,DEVELOPMENT_ENV as je}from"@visulima/packem-share/constants";import{createJiti as Pe}from"jiti";import{writeFile as Q,readFile as xe}from"node:fs/promises";import{existsSync as q}from"node:fs";import{parseEnv as K}from"node:util";import{createInterface as Ee}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
- const Z={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 De=Object.defineProperty,u=h((t,e)=>De(t,"name",{value:e,configurable:!0}),"i");const Me=/defineConfig\s*\(\s*\{/,Le=/preset:\s*['"][^'"]+['"]/,Oe=["typedoc","typedoc-plugin-markdown","typedoc-plugin-rename-defaults"],Ne=["@babel/core","@babel/preset-react"],Ie=["react","react-dom"],Te=["@babel/core","babel-preset-solid"],Be=["solid-js"],Ve=["@babel/core","@babel/preset-react","babel-plugin-transform-hook-names"],Re=["preact"],Ae=["unplugin-vue"],Fe=["vue"],qe=["rollup-plugin-svelte"],Ge=["svelte"],P=u((t,e,a)=>t.includes(`preset: '${e}'`)||t.includes(`preset: "${e}"`)||t.includes(`preset: '${e}',`)||t.includes(`preset: "${e}",`)||t.includes(a)||t.includes(`@visulima/packem/config/preset/${e}`),"checkPresetExists"),x=u((t,e)=>{const{logger:a,magic:s,packemConfig:n}=t,r=Me.exec(n);if(r?.index!==void 0){const o=r.index+r[0].length;if(n.includes("preset:")){const i=Le.exec(n);if(i)s.replace(i[0],`preset: '${e}'`);else throw a.warn(`A preset already exists in the config. Please manually set it to '${e}'.`),new Error("Preset exists but is not a string")}else s.appendLeft(o,`
4
+ const Z={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 De=Object.defineProperty,u=h((t,e)=>De(t,"name",{value:e,configurable:!0}),"i");const Me=/defineConfig\s*\(\s*\{/,Le=/preset:\s*['"][^'"]+['"]/,Oe=["typedoc","typedoc-plugin-markdown","typedoc-plugin-rename-defaults"],Ie=["@babel/core","@babel/preset-react"],Ne=["react","react-dom"],Te=["@babel/core","babel-preset-solid"],Be=["solid-js"],Ve=["@babel/core","@babel/preset-react","babel-plugin-transform-hook-names"],Re=["preact"],Ae=["unplugin-vue"],Fe=["vue"],qe=["rollup-plugin-svelte"],Ge=["svelte"],P=u((t,e,a)=>t.includes(`preset: '${e}'`)||t.includes(`preset: "${e}"`)||t.includes(`preset: '${e}',`)||t.includes(`preset: "${e}",`)||t.includes(a)||t.includes(`@visulima/packem/config/preset/${e}`),"checkPresetExists"),x=u((t,e)=>{const{logger:a,magic:s,packemConfig:n}=t,r=Me.exec(n);if(r?.index!==void 0){const o=r.index+r[0].length;if(n.includes("preset:")){const i=Le.exec(n);if(i)s.replace(i[0],`preset: '${e}'`);else throw a.warn(`A preset already exists in the config. Please manually set it to '${e}'.`),new Error("Preset exists but is not a string")}else s.appendLeft(o,`
5
5
  preset: '${e}',`)}else if(n.includes("transformer:"))s.replace("transformer:",`preset: '${e}',
6
6
  transformer:`);else{const o=n.indexOf("{");o!==-1&&s.appendLeft(o+1,`
7
- preset: '${e}',`)}},"insertPreset"),Ke=u(async t=>{try{return((await ke("git",["status","--porcelain"],{nodeOptions:{cwd:t,stdio:["pipe","pipe","pipe"]}})).stdout?.trim().length??0)>0}catch{return!1}},"checkGitDirty"),ee=u(async t=>{const e=S(t,"package.json"),a=await z(e,{resolveCatalogs:!0});return!!(a.devDependencies?.typescript??a.dependencies?.typescript)},"checkTypeScriptInstalled"),We=u(async t=>{const e=await ee(t),a=[...Ie],s=[...Ne];return e?s.push("@types/react","@types/react-dom"):await w({initialValue:!1,message:"Do you want to use TypeScript?"})&&s.push("typescript","@types/react","@types/react-dom"),{devPackages:s,packages:a}},"getReactTypeDependencies"),E=u(async(t,e,a)=>{const{rootDirectory:s,spinner:n}=t;n.start("Installing packages"),await C(a,{cwd:s,dev:!1,silent:!0}),await C(e,{cwd:s,dev:!0,silent:!0}),n.stop("Installed packages")},"installPackages"),ze=u(async t=>{const{logger:e,magic:a,packemConfig:s,packemConfigFormat:n,rootDirectory:r,spinner:o,transformerReplaceKey:i,transformerSearchKey:c}=t;if(s.includes("typedoc: typedocBuilder")||s.includes("@visulima/packem/builder/typedoc")){e.warn("Typedoc has already been added to the packem config.");return}n==="cjs"?a.prepend(`const typedocBuilder = require("@visulima/packem/builder/typedoc");
7
+ preset: '${e}',`)}},"insertPreset"),Ke=u(async t=>{try{return((await Ce("git",["status","--porcelain"],{nodeOptions:{cwd:t,stdio:["pipe","pipe","pipe"]}})).stdout?.trim().length??0)>0}catch{return!1}},"checkGitDirty"),ee=u(async t=>{const e=S(t,"package.json"),a=await z(e,{resolveCatalogs:!0});return!!(a.devDependencies?.typescript??a.dependencies?.typescript)},"checkTypeScriptInstalled"),We=u(async t=>{const e=await ee(t),a=[...Ne],s=[...Ie];return e?s.push("@types/react","@types/react-dom"):await w({initialValue:!1,message:"Do you want to use TypeScript?"})&&s.push("typescript","@types/react","@types/react-dom"),{devPackages:s,packages:a}},"getReactTypeDependencies"),E=u(async(t,e,a)=>{const{rootDirectory:s,spinner:n}=t;n.start("Installing packages"),await C(a,{cwd:s,dev:!1,silent:!0}),await C(e,{cwd:s,dev:!0,silent:!0}),n.stop("Installed packages")},"installPackages"),ze=u(async t=>{const{logger:e,magic:a,packemConfig:s,packemConfigFormat:n,rootDirectory:r,spinner:o,transformerReplaceKey:i,transformerSearchKey:c}=t;if(s.includes("typedoc: typedocBuilder")||s.includes("@visulima/packem/builder/typedoc")){e.warn("Typedoc has already been added to the packem config.");return}n==="cjs"?a.prepend(`const typedocBuilder = require("@visulima/packem/builder/typedoc");
8
8
  `):a.prepend(`import typedocBuilder from "@visulima/packem/builder/typedoc";
9
9
  `),s.includes("builder: {")?a.replace("builder: {",`builder: {
10
10
  typedoc: typedocBuilder,
@@ -33,7 +33,7 @@ Svelte preset added!`)},"addSvelte"),Qe=u(async()=>{const t=[],e=await v({messag
33
33
  loaders: [${g}],
34
34
  },
35
35
  },`),t.spinner.start("Installing packages"),await C(l,{cwd:t.rootDirectory,dev:!0,silent:!0}),t.spinner.stop("Installed packages"),e.success(`
36
- CSS loaders added!`)},"addCss"),tt=u(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:u(async({argument:e,logger:a,options:s})=>{const n=a,r=I(),o=T(A(),typeof s.dir=="string"?s.dir:".");let i;try{i=await U(o,s.config)}catch{n.error("Could not find a packem config file, please run `packem init` first.");return}if(await Ke(o)&&!await w({initialValue:!1,message:"Git repository has uncommitted changes. Do you want to proceed?"})){F("Operation cancelled.");return}const c=await ce(i,{buffer:!1}),l=c.includes("import")?"esm":"cjs",p=new he(c),g=" transformer,",m=c.includes(" transformer,")?" transformer,":" transformer",d={logger:n,magic:p,packemConfig:c,packemConfigFilePath:i,packemConfigFormat:l,rootDirectory:o,spinner:r,transformerReplaceKey:g,transformerSearchKey:m};e.includes("typedoc")&&await ze(d),e.includes("react")&&await Ue(d),e.includes("solid")&&await Je(d),e.includes("preact")&&await He(d),e.includes("vue")&&await Ye(d),e.includes("svelte")&&await Xe(d),e.includes("css")&&await et(d),await le(i,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 st=Object.defineProperty,D=h((t,e)=>st(t,"name",{value:e,configurable:!0}),"n");const at=D((t,e)=>{if(t==="rolldown")return`// Generated by \`packem\` first-run setup. See https://packem.dev for full options.
36
+ CSS loaders added!`)},"addCss"),tt=u(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:u(async({argument:e,logger:a,options:s})=>{const n=a,r=N(),o=T(A(),typeof s.dir=="string"?s.dir:".");let i;try{i=await U(o,s.config)}catch{n.error("Could not find a packem config file, please run `packem init` first.");return}if(await Ke(o)&&!await w({initialValue:!1,message:"Git repository has uncommitted changes. Do you want to proceed?"})){F("Operation cancelled.");return}const c=await be(i,{buffer:!1}),l=c.includes("import")?"esm":"cjs",p=new Se(c),g=" transformer,",m=c.includes(" transformer,")?" transformer,":" transformer",d={logger:n,magic:p,packemConfig:c,packemConfigFilePath:i,packemConfigFormat:l,rootDirectory:o,spinner:r,transformerReplaceKey:g,transformerSearchKey:m};e.includes("typedoc")&&await ze(d),e.includes("react")&&await Ue(d),e.includes("solid")&&await Je(d),e.includes("preact")&&await He(d),e.includes("vue")&&await Ye(d),e.includes("svelte")&&await Xe(d),e.includes("css")&&await et(d),await ve(i,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 st=Object.defineProperty,D=h((t,e)=>st(t,"name",{value:e,configurable:!0}),"n");const at=D((t,e)=>{if(t==="rolldown")return`// Generated by \`packem\` first-run setup. See https://packem.dev for full options.
37
37
  import { defineConfig } from "@visulima/packem/config";
38
38
 
39
39
  export default defineConfig({
@@ -49,10 +49,10 @@ export default defineConfig({
49
49
  declaration: true,
50
50
  transformer,
51
51
  });
52
- `},"generatePackemConfig"),nt=D(async()=>{const t=await v({initialValue:"rollup",message:"Which bundler do you want to use?",options:[{hint:"stable, full feature set, supports DTS",label:"rollup",value:"rollup"},{hint:"experimental, fast — falls back to rollup for DTS",label:"rolldown",value:"rolldown"}]});if(_(t))throw F("Setup cancelled."),new Error("Packem setup was cancelled.");return t},"promptBundler"),rt=D(async()=>{const t=await v({initialValue:"esbuild",message:"Which transformer do you want to use?",options:[{hint:"fast, widely used",label:"esbuild",value:"esbuild"},{hint:"fastest, Rust-based",label:"oxc",value:"oxc"},{hint:"TypeScript-aware, Rust-based",label:"swc",value:"swc"},{hint:"minimal, JS-based",label:"sucrase",value:"sucrase"}]});if(_(t))throw F("Setup cancelled."),new Error("Packem setup was cancelled.");return t},"promptTransformer"),it=D(async(t,e)=>{if(t.length===0)return;const a=I();a.start(`Installing ${t.join(", ")}`);try{await C(t,{cwd:e,dev:!0,silent:!0}),a.stop(`Installed ${t.join(", ")}`)}catch(s){throw a.stop(`Failed to install ${t.join(", ")}`),s}},"installPackagesWithSpinner"),ot=D(async t=>{if(await de(t))return;if(!(process.stdout.isTTY&&!process.env.CI)){const r=await ue(["rollup","esbuild"],t);throw new Error(`No packem.config found. Run packem in an interactive terminal to generate one, or install the defaults manually:
52
+ `},"generatePackemConfig"),nt=D(async()=>{const t=await v({initialValue:"rollup",message:"Which bundler do you want to use?",options:[{hint:"stable, full feature set, supports DTS",label:"rollup",value:"rollup"},{hint:"experimental, fast — falls back to rollup for DTS",label:"rolldown",value:"rolldown"}]});if(_(t))throw F("Setup cancelled."),new Error("Packem setup was cancelled.");return t},"promptBundler"),rt=D(async()=>{const t=await v({initialValue:"esbuild",message:"Which transformer do you want to use?",options:[{hint:"fast, widely used",label:"esbuild",value:"esbuild"},{hint:"fastest, Rust-based",label:"oxc",value:"oxc"},{hint:"TypeScript-aware, Rust-based",label:"swc",value:"swc"},{hint:"minimal, JS-based",label:"sucrase",value:"sucrase"}]});if(_(t))throw F("Setup cancelled."),new Error("Packem setup was cancelled.");return t},"promptTransformer"),it=D(async(t,e)=>{if(t.length===0)return;const a=N();a.start(`Installing ${t.join(", ")}`);try{await C(t,{cwd:e,dev:!0,silent:!0}),a.stop(`Installed ${t.join(", ")}`)}catch(s){throw a.stop(`Failed to install ${t.join(", ")}`),s}},"installPackagesWithSpinner"),ot=D(async t=>{if(await ce(t))return;if(!(process.stdout.isTTY&&!process.env.CI)){const r=await le(["rollup","esbuild"],t);throw new Error(`No packem.config found. Run packem in an interactive terminal to generate one, or install the defaults manually:
53
53
  ${r}
54
- and create a packem.config.ts.`)}H(je("Packem first-run setup")),N.info("No packem.config found — let's create one.");const e=await nt(),a=e==="rolldown"?void 0:await rt(),s=[e];e==="rolldown"&&s.push("rollup"),a&&s.push(pe[a]),await it(s,t);const n=S(t,"packem.config.ts");await Q(n,at(e,a),"utf8"),N.success(`Created ${n}`),Y("Setup complete — continuing with build.")},"runFirstRunWizard");var ct=Object.defineProperty,te=h((t,e)=>ct(t,"name",{value:e,configurable:!0}),"a$1");const lt=/^([^#:=]+)=(.*)$/,W=te((t,e="PACKEM_")=>{const a={};for(const s of t.split(`
55
- `)){const n=s.trim();if(!n||n.startsWith("#"))continue;const r=lt.exec(n);if(r?.[1]){const o=r[1].trim();let i=r[2].trim();(i.startsWith('"')&&i.endsWith('"')||i.startsWith("'")&&i.endsWith("'"))&&(i=i.slice(1,-1)),(!e||o.startsWith(e))&&(a[`process.env.${o}`]=JSON.stringify(i))}}return a},"loadEnvFileManually"),dt=te(async(t,e,a="PACKEM_")=>{const s=T(e,t);if(!q(s))return{};const{readFile:n}=await import("node:fs/promises"),r=await n(s,"utf8"),o={};if(typeof K=="function")try{const i=K(r);for(const[c,l]of Object.entries(i))(!a||c.startsWith(a))&&(o[`process.env.${c}`]=JSON.stringify(l))}catch{return W(r,a)}else return W(r,a);return o},"loadEnvFile");var ut=Object.defineProperty,pt=h((t,e)=>ut(t,"name",{value:e,configurable:!0}),"e$2");const mt=pt(async(t,e,a,s,n)=>{const r=await U(e,n),o=await t.import(r,{default:!0,try:!0})??{};return{config:typeof o=="function"?await o(a,s):o,path:r}},"loadPackemConfig");var ft=Object.defineProperty,gt=h((t,e)=>ft(t,"name",{value:e,configurable:!0}),"e$1");const yt=gt(async(t,e)=>{switch(t){case"none":return{};case"preact":{const{createPreactPreset:a}=await import("../config/preset/preact.js");t=a();break}case"react":{const{createReactPreset:a}=await import("../config/preset/react.js");t=a();break}case"solid":{const{createSolidPreset:a}=await import("../config/preset/solid.js");t=a();break}case"svelte":{const{createSveltePreset:a}=await import("../config/preset/svelte.js");t=a();break}case"vue":{const{createVuePreset:a}=await import("../config/preset/vue.js");t=a();break}default:typeof t=="string"&&(t=await e.import(t)||{})}return typeof t=="function"&&(t=t()),t},"loadPreset");var wt=Object.defineProperty,b=h((t,e)=>wt(t,"name",{value:e,configurable:!0}),"o");const bt=b(t=>t.watch?"watch":t.jit?"jit":"build","resolveMode"),vt=b(t=>{let e;const a={};if(t.env)for(const s of t.env)s.key==="NODE_ENV"?e=s.value:a[`process.env.${s.key}`]=JSON.stringify(s.value);return{cliEnvVariables:a,nodeEnvironment:e}},"parseCliEnvVariables"),ht=b((t,e)=>{if(e!==void 0)return e;if(t.production)return X;if(t.development)return $e},"resolveNodeEnvironment"),kt=b(t=>{const e=[];if(t.external)for(const a of t.external)e.push(a.split(","));return e},"collectExternals"),$t=b(t=>{t.addCommand({description:"Demonstrate options required",execute:b(async({logger:e,options:a})=>{const s=a,n=bt(s),{cliEnvVariables:r,nodeEnvironment:o}=vt(s),i=ht(s,o),c=kt(s),l=T(A(),s.dir??".");await ot(l);const p=Se(l,{debug:s.debug}),{config:g,path:m}=await mt(p,l,i,n,s.config??void 0);e.debug("Using packem config found at",m);const d=s.envFile??g.envFile,L=s.envPrefix??g.envPrefix??"PACKEM_",$={};if(d){const k=await dt(d,l,L);Object.assign($,k)}Object.assign($,r);const B=await yt(g.preset??"none",p);s.minify&&s.sourcemap===void 0&&(s.sourcemap=!0);try{const k=me()(g,fe,B,{analyze:s.analyze,bundler:s.bundler,cjsInterop:s.cjsInterop,clean:s.clean,dtsOnly:s.dtsOnly,externals:c,killSignal:s.killSignal,minify:s.minify??i===X,onSuccess:s.onSuccess,rollup:{esbuild:{target:s.target},license:{path:s.license},metafile:s.metafile,...Object.keys($).length>0||Object.keys(r).length>0?{replace:{values:$}}:{},resolveExternals:s.noExternal?{builtins:!1,deps:!1,devDeps:!1,optDeps:!1,peerDeps:!1}:{}},runtime:s.runtime,sourcemap:s.metafile||s.analyze||s.sourcemap,unbundle:s.unbundle,validation:s.validation===!1?!1:{},...s.exe?{exe:!0}:{},...s.typedoc?{typedoc:{format:"html"}}:{}});s.validation===!1&&!g.validation&&(k.validation=!1),await ge(l,n,i,e,s.debug??!1,k,s.tsconfig??void 0)}catch(k){e.error(k),ve(1)}},"execute"),name:"build",options:[{description:"Specify the bundler to use (rollup or rolldown)",name:"bundler",type:b(e=>{if(e==="rollup"||e==="rolldown")return e;throw new Error("Invalid bundler. Use 'rollup' or 'rolldown'.")},"type")},{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:b(e=>{const[a,s]=e.split("=");return{key:a,value:s}},"type")},{description:"Path to the .env file to load environment variables from",name:"env-file",type:String},{description:"Prefix for environment variables to load from .env file (default: PACKEM_)",name:"env-prefix",type:String},{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:b(e=>{if(e==="SIGTERM"||e==="SIGKILL")return e;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:b(e=>{if(e==="node"||e==="browser")return e;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},{description:"Bundle the output into a standalone executable via Node.js SEA (requires Node.js >= 25.7.0, single entry)",name:"exe",type:Boolean}]})},"createBuildCommand");var St=Object.defineProperty,f=h((t,e)=>St(t,"name",{value:e,configurable:!0}),"t");const se=f(t=>t==="sass-embedded"||t==="node-sass"?"sass":t,"normalizeCssLoaderName"),Ct=f((t,e)=>{Pe(S(t,"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:e?["es2022","dom","dom.iterable"]:["es2022"]}})},"writeTsconfig"),jt=f((t,e,a,s,n)=>{let r="";if(t)for(const o of e){const i=se(o);r+=n?`import ${i}Loader from "@visulima/packem/css/loader/${i.toLowerCase()}";
54
+ and create a packem.config.ts.`)}H(he("Packem first-run setup")),I.info("No packem.config found — let's create one.");const e=await nt(),a=e==="rolldown"?void 0:await rt(),s=[e];e==="rolldown"&&s.push("rollup"),a&&s.push(de[a]),await it(s,t);const n=S(t,"packem.config.ts");await Q(n,at(e,a),"utf8"),I.success(`Created ${n}`),Y("Setup complete — continuing with build.")},"runFirstRunWizard");var ct=Object.defineProperty,te=h((t,e)=>ct(t,"name",{value:e,configurable:!0}),"a$1");const lt=/^([^#:=]+)=(.*)$/,W=te((t,e="PACKEM_")=>{const a={};for(const s of t.split(`
55
+ `)){const n=s.trim();if(!n||n.startsWith("#"))continue;const r=lt.exec(n);if(r?.[1]){const o=r[1].trim();let i=r[2].trim();(i.startsWith('"')&&i.endsWith('"')||i.startsWith("'")&&i.endsWith("'"))&&(i=i.slice(1,-1)),(!e||o.startsWith(e))&&(a[`process.env.${o}`]=JSON.stringify(i))}}return a},"loadEnvFileManually"),dt=te(async(t,e,a="PACKEM_")=>{const s=T(e,t);if(!q(s))return{};const{readFile:n}=await import("node:fs/promises"),r=await n(s,"utf8"),o={};if(typeof K=="function")try{const i=K(r);for(const[c,l]of Object.entries(i))(!a||c.startsWith(a))&&(o[`process.env.${c}`]=JSON.stringify(l))}catch{return W(r,a)}else return W(r,a);return o},"loadEnvFile");var ut=Object.defineProperty,pt=h((t,e)=>ut(t,"name",{value:e,configurable:!0}),"e$2");const mt=pt(async(t,e,a,s,n)=>{const r=await U(e,n),o=await t.import(r,{default:!0,try:!0})??{};return{config:typeof o=="function"?await o(a,s):o,path:r}},"loadPackemConfig");var ft=Object.defineProperty,gt=h((t,e)=>ft(t,"name",{value:e,configurable:!0}),"e$1");const yt=gt(async(t,e)=>{switch(t){case"none":return{};case"preact":{const{createPreactPreset:a}=await import("../config/preset/preact.js");t=a();break}case"react":{const{createReactPreset:a}=await import("../config/preset/react.js");t=a();break}case"solid":{const{createSolidPreset:a}=await import("../config/preset/solid.js");t=a();break}case"svelte":{const{createSveltePreset:a}=await import("../config/preset/svelte.js");t=a();break}case"vue":{const{createVuePreset:a}=await import("../config/preset/vue.js");t=a();break}default:typeof t=="string"&&(t=await e.import(t)||{})}return typeof t=="function"&&(t=t()),t},"loadPreset");var wt=Object.defineProperty,b=h((t,e)=>wt(t,"name",{value:e,configurable:!0}),"o");const bt=b(t=>t.watch?"watch":t.jit?"jit":"build","resolveMode"),vt=b(t=>{let e;const a={};if(t.env)for(const s of t.env)s.key==="NODE_ENV"?e=s.value:a[`process.env.${s.key}`]=JSON.stringify(s.value);return{cliEnvVariables:a,nodeEnvironment:e}},"parseCliEnvVariables"),ht=b((t,e)=>{if(e!==void 0)return e;if(t.production)return X;if(t.development)return je},"resolveNodeEnvironment"),kt=b(t=>{const e=[];if(t.external)for(const a of t.external)e.push(a.split(","));return e},"collectExternals"),$t=b(t=>{t.addCommand({description:"Demonstrate options required",execute:b(async({logger:e,options:a})=>{const s=a,n=bt(s),{cliEnvVariables:r,nodeEnvironment:o}=vt(s),i=ht(s,o),c=kt(s),l=T(A(),s.dir??".");await ot(l);const p=Pe(l,{debug:s.debug}),{config:g,path:m}=await mt(p,l,i,n,s.config??void 0);e.debug("Using packem config found at",m);const d=s.envFile??g.envFile,L=s.envPrefix??g.envPrefix??"PACKEM_",$={};if(d){const k=await dt(d,l,L);Object.assign($,k)}Object.assign($,r);const B=await yt(g.preset??"none",p);s.minify&&s.sourcemap===void 0&&(s.sourcemap=!0);try{const k=ue()(g,pe,B,{analyze:s.analyze,bundler:s.bundler,cjsInterop:s.cjsInterop,clean:s.clean,dtsOnly:s.dtsOnly,externals:c,killSignal:s.killSignal,minify:s.minify??i===X,onSuccess:s.onSuccess,rollup:{esbuild:{target:s.target},license:{path:s.license},metafile:s.metafile,...Object.keys($).length>0||Object.keys(r).length>0?{replace:{values:$}}:{},resolveExternals:s.noExternal?{builtins:!1,deps:!1,devDeps:!1,optDeps:!1,peerDeps:!1}:{}},runtime:s.runtime,sourcemap:s.metafile||s.analyze||s.sourcemap,unbundle:s.unbundle,validation:s.validation===!1?!1:{},...s.exe?{exe:!0}:{},...s.typedoc?{typedoc:{format:"html"}}:{}});s.validation===!1&&!g.validation&&(k.validation=!1),await me(l,n,i,e,s.debug??!1,k,s.tsconfig??void 0)}catch(k){e.error(k),we(1)}},"execute"),name:"build",options:[{description:"Specify the bundler to use (rollup or rolldown)",name:"bundler",type:b(e=>{if(e==="rollup"||e==="rolldown")return e;throw new Error("Invalid bundler. Use 'rollup' or 'rolldown'.")},"type")},{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:b(e=>{const[a,s]=e.split("=");return{key:a,value:s}},"type")},{description:"Path to the .env file to load environment variables from",name:"env-file",type:String},{description:"Prefix for environment variables to load from .env file (default: PACKEM_)",name:"env-prefix",type:String},{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:b(e=>{if(e==="SIGTERM"||e==="SIGKILL")return e;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:b(e=>{if(e==="node"||e==="browser")return e;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},{description:"Bundle the output into a standalone executable via Node.js SEA (requires Node.js >= 25.7.0, single entry)",name:"exe",type:Boolean}]})},"createBuildCommand");var St=Object.defineProperty,f=h((t,e)=>St(t,"name",{value:e,configurable:!0}),"t");const se=f(t=>t==="sass-embedded"||t==="node-sass"?"sass":t,"normalizeCssLoaderName"),Ct=f((t,e)=>{ke(S(t,"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:e?["es2022","dom","dom.iterable"]:["es2022"]}})},"writeTsconfig"),jt=f((t,e,a,s,n)=>{let r="";if(t)for(const o of e){const i=se(o);r+=n?`import ${i}Loader from "@visulima/packem/css/loader/${i.toLowerCase()}";
56
56
  `:`const ${i}Loader = require("@visulima/packem/css/loader/${i.toLowerCase()}");
57
57
  `}return s&&a&&(r+=n?`import ${a}Minifier from "@visulima/packem/css/minifier/${a.toLowerCase()}";
58
58
  `:`const ${a}Minifier = require("@visulima/packem/css/minifier/${a.toLowerCase()}");
@@ -76,8 +76,8 @@ module.exports = defineConfig({
76
76
  runtime: ${a},
77
77
  transformer${n}
78
78
  });
79
- `,"buildConfigTemplate"),Et=f(t=>{const e=[];return t.dependencies&&e.push(...Object.keys(t.dependencies)),t.devDependencies&&e.push(...Object.keys(t.devDependencies)),e},"collectPackageNames"),Dt=f(async(t,e,a,s)=>{if(t===void 0&&!e){const r=await w({message:"Do you want to install TypeScript?"});return r&&s.push("typescript@latest"),r}const n=a.devDependencies?.typescript??a.dependencies?.typescript??"unknown";return N.message(`TypeScript version ${n} is already installed`),t},"setupTypescript"),Mt=f(async(t,e,a)=>{let s=t;return e.includes("esbuild")?s="esbuild":e.includes("@swc/core")?s="swc":e.includes("sucrase")&&(s="sucrase"),s!==void 0?(N.message(`Transformer ${s} is already installed.`),s):(s=await v({message:"Pick a transformer",options:[{label:"esbuild",value:"esbuild"},{label:"swc",value:"swc"},{label:"Sucrase",value:"sucrase"},{label:"OXC",value:"oxc"}]}),s&&s!=="oxc"&&!e.includes(s)&&await w({message:`Do you want to install ${s}?`})&&a.push(s==="swc"?"@swc/core":s),s)},"resolveTransformer"),Lt=f(async t=>{if(R(S(t,"tsconfig.json")))return;const e=await w({message:"Do you want to use generate a tsconfig.json?"}),a=await w({message:"Do you want to run your code in the DOM?"});if(e){const s=I();s.start("Generating tsconfig.json"),Ct(t,!!a),s.stop("")}},"maybeGenerateTsconfig"),Ot=f(async t=>{if(!t.includes("sass"))return t;const e=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"}]});return e==="sass"?t:[...t.filter(a=>a!=="sass"),e]},"resolveSassLoader"),Nt=f(async t=>{const e=[],a=await v({message:"Pick a css loader",options:[{label:"PostCSS",value:"postcss"},{hint:"experimental",label:"Lightning CSS",value:"lightningcss"}]});e.push(a);const s=await J({message:"Pick your loaders",options:[{label:"Sass",value:"sass"},{label:"Stylus",value:"stylus"},{label:"Less",value:"less"}],required:!1}),n=await Ot(s);if(e.push(...n),await w({message:`Do you want to install "${e.join('", "')}"?`}))for(const r of e)t.push(...Z[r]);return e.push("sourceMap"),e},"selectCssLoaders"),It=f(async(t,e)=>{const a=await v({message:"Pick a css minifier",options:[{label:"CSSNano",value:"cssnano"},{label:"Lightning CSS",value:"lightningcss"}]});return t.includes("lightningcss")||await w({message:`Do you want to install "${a}"?`})&&e.push(a),a},"selectCssMinifier"),Tt=f(t=>{t.addCommand({description:"Initialize packem configuration",execute:f(async({logger:e,options:a})=>{const s=a,n=e;if(H("Welcome to packem setup"),R(S(s.dir??".","packem.config.ts"))){n.info("Packem project already initialized, you can use `packem build` to build your project");return}const r=T(A(),s.dir??"."),o=S(r,"package.json");if(!R(o))throw new Error("No package.json found in the directory");const i=await z(o,{resolveCatalogs:!0}),c=Et(i),l=!!(i.devDependencies?.typescript??i.dependencies?.typescript),p=[];s.typescript=await Dt(s.typescript,l,i,p),await Lt(r),s.runtime??=await v({message:"Pick a build runtime",options:[{label:"Node",value:"node"},{label:"Browser",value:"browser"}]}),s.transformer=await Mt(s.transformer,c,p),s.css??=await w({initialValue:!1,message:"Do you want to use css in your project?"});const g=s.css?await Nt(p):[];s.cssMinifier??=await w({initialValue:!1,message:"Do you want to minify your css?"});const m=s.cssMinifier?await It(g,p):void 0,d=s.css??!1,L=s.cssMinifier??!1,$=l||i.type==="module",B=Pt(d,m,L,g),k=jt(d,g,m,L,$),ne=xt($,s.transformer??"",s.runtime??"",k,B),O=I(),V=l?"ts":"js";p.length>0&&(O.start("Installing packages"),await C(p,{cwd:r,dev:!0,silent:!0}),O.stop("Installed packages")),O.start(`Creating packem.config.${V}`),xe(S(r,`packem.config.${V}`),ne),O.stop(`Created packem.config.${V}`),Y("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:f(e=>{if(typeof e=="string"&&["esbuild","sucrase","swc"].includes(e))return e;throw new Error("Invalid transformer, please choose one of 'swc', 'sucrase' or 'esbuild'")},"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:f(e=>{if(e==="node"||e==="browser")return e;throw new Error("Invalid runtime. Use 'node' or 'browser'.")},"type")}]})},"createInitCommand");var Bt=Object.defineProperty,y=h((t,e)=>Bt(t,"name",{value:e,configurable:!0}),"r");const ae={bunchee:"@visulima/packem",tsup:"@visulima/packem","tsup-node":"@visulima/packem",unbuild:"@visulima/packem"},Vt={dependencies:`^${G.version}`,devDependencies:`^${G.version}`,peerDependencies:"*"},Rt=y((t,e,a,s)=>{const n={};for(const r of Object.keys(t))r===e?n[a]=s??t[e]:n[r]=t[r];return n},"renameKey"),At=/\bunbuild\b/g,Ft=/\bbunchee\b/g,qt=/\btsup(?:-node)?/g,Gt=/\bbuild\b/g,Kt=[{from:"tsup",rewrite:y(t=>t.replaceAll(qt,"packem build").replaceAll(Gt,"build"),"rewrite")},{from:"unbuild",rewrite:y(t=>t.replaceAll(At,"packem build"),"rewrite")},{from:"bunchee",rewrite:y(t=>t.replaceAll(Ft,"packem build"),"rewrite")}],Wt=y((t,e,a)=>{let s=e,n=!1;for(const r of Object.keys(ae))s.includes(r)&&(a.info(`Migrating \`${t}\` script from ${r} to packem`),n=!0,s=s.replaceAll(new RegExp(String.raw`\b${r}\b`,"g"),"packem").replaceAll(new RegExp(String.raw`\b${r}-node\b`,"g"),"packem"));for(const{from:r,rewrite:o}of Kt)s.includes(r)&&(a.info(`Migrating \`${t}\` script from ${r} to packem`),n=!0,s=o(s));return n?s:void 0},"migrateScript"),zt=y((t,e)=>{const a={...t};let s=!1;for(const n of Object.keys(a)){const r=Wt(n,a[n],e);r!==void 0&&(a[n]=r,s=!0)}return{found:s,scripts:a}},"migrateScripts"),Ut=y((t,e)=>{const a={...t};let s=!1;for(const[n,r]of Object.entries(Vt)){let o=a[n];for(const[i,c]of Object.entries(ae))o?.[i]&&(e.info(`Migrating \`${n}\` from ${i} to ${c}.`),s=!0,o=Rt(o,i,c,r),a[n]=o)}return{found:s,pkg:a}},"migrateDependencies"),Jt=y((t,e)=>{const a=["tsup","unbuild","bunchee"];for(const s of a)t[s]&&e.info(`Found \`${s}\` config field in package.json. Consider moving to packem.config.ts`)},"warnInlineConfigFields"),_t=y(async(t,e)=>{if(!q("package.json"))return e.error("No package.json found"),!1;const a=await Ce("package.json","utf8"),s=JSON.parse(a),{found:n,pkg:r}=Ut(s,e);let o=n;if(r.scripts){const{found:c,scripts:l}=zt(r.scripts,e);c&&(r.scripts=l,o=!0)}if(Jt(r,e),!o)return e.warn("No migratable bundler dependencies found in package.json"),!1;const i=`${JSON.stringify(r,void 0,a.includes(" ")?" ":2)}
79
+ `,"buildConfigTemplate"),Et=f(t=>{const e=[];return t.dependencies&&e.push(...Object.keys(t.dependencies)),t.devDependencies&&e.push(...Object.keys(t.devDependencies)),e},"collectPackageNames"),Dt=f(async(t,e,a,s)=>{if(t===void 0&&!e){const r=await w({message:"Do you want to install TypeScript?"});return r&&s.push("typescript@latest"),r}const n=a.devDependencies?.typescript??a.dependencies?.typescript??"unknown";return I.message(`TypeScript version ${n} is already installed`),t},"setupTypescript"),Mt=f(async(t,e,a)=>{let s=t;return e.includes("esbuild")?s="esbuild":e.includes("@swc/core")?s="swc":e.includes("sucrase")&&(s="sucrase"),s!==void 0?(I.message(`Transformer ${s} is already installed.`),s):(s=await v({message:"Pick a transformer",options:[{label:"esbuild",value:"esbuild"},{label:"swc",value:"swc"},{label:"Sucrase",value:"sucrase"},{label:"OXC",value:"oxc"}]}),s&&s!=="oxc"&&!e.includes(s)&&await w({message:`Do you want to install ${s}?`})&&a.push(s==="swc"?"@swc/core":s),s)},"resolveTransformer"),Lt=f(async t=>{if(R(S(t,"tsconfig.json")))return;const e=await w({message:"Do you want to use generate a tsconfig.json?"}),a=await w({message:"Do you want to run your code in the DOM?"});if(e){const s=N();s.start("Generating tsconfig.json"),Ct(t,!!a),s.stop("")}},"maybeGenerateTsconfig"),Ot=f(async t=>{if(!t.includes("sass"))return t;const e=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"}]});return e==="sass"?t:[...t.filter(a=>a!=="sass"),e]},"resolveSassLoader"),It=f(async t=>{const e=[],a=await v({message:"Pick a css loader",options:[{label:"PostCSS",value:"postcss"},{hint:"experimental",label:"Lightning CSS",value:"lightningcss"}]});e.push(a);const s=await J({message:"Pick your loaders",options:[{label:"Sass",value:"sass"},{label:"Stylus",value:"stylus"},{label:"Less",value:"less"}],required:!1}),n=await Ot(s);if(e.push(...n),await w({message:`Do you want to install "${e.join('", "')}"?`}))for(const r of e)t.push(...Z[r]);return e.push("sourceMap"),e},"selectCssLoaders"),Nt=f(async(t,e)=>{const a=await v({message:"Pick a css minifier",options:[{label:"CSSNano",value:"cssnano"},{label:"Lightning CSS",value:"lightningcss"}]});return t.includes("lightningcss")||await w({message:`Do you want to install "${a}"?`})&&e.push(a),a},"selectCssMinifier"),Tt=f(t=>{t.addCommand({description:"Initialize packem configuration",execute:f(async({logger:e,options:a})=>{const s=a,n=e;if(H("Welcome to packem setup"),R(S(s.dir??".","packem.config.ts"))){n.info("Packem project already initialized, you can use `packem build` to build your project");return}const r=T(A(),s.dir??"."),o=S(r,"package.json");if(!R(o))throw new Error("No package.json found in the directory");const i=await z(o,{resolveCatalogs:!0}),c=Et(i),l=!!(i.devDependencies?.typescript??i.dependencies?.typescript),p=[];s.typescript=await Dt(s.typescript,l,i,p),await Lt(r),s.runtime??=await v({message:"Pick a build runtime",options:[{label:"Node",value:"node"},{label:"Browser",value:"browser"}]}),s.transformer=await Mt(s.transformer,c,p),s.css??=await w({initialValue:!1,message:"Do you want to use css in your project?"});const g=s.css?await It(p):[];s.cssMinifier??=await w({initialValue:!1,message:"Do you want to minify your css?"});const m=s.cssMinifier?await Nt(g,p):void 0,d=s.css??!1,L=s.cssMinifier??!1,$=l||i.type==="module",B=Pt(d,m,L,g),k=jt(d,g,m,L,$),ne=xt($,s.transformer??"",s.runtime??"",k,B),O=N(),V=l?"ts":"js";p.length>0&&(O.start("Installing packages"),await C(p,{cwd:r,dev:!0,silent:!0}),O.stop("Installed packages")),O.start(`Creating packem.config.${V}`),$e(S(r,`packem.config.${V}`),ne),O.stop(`Created packem.config.${V}`),Y("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:f(e=>{if(typeof e=="string"&&["esbuild","sucrase","swc"].includes(e))return e;throw new Error("Invalid transformer, please choose one of 'swc', 'sucrase' or 'esbuild'")},"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:f(e=>{if(e==="node"||e==="browser")return e;throw new Error("Invalid runtime. Use 'node' or 'browser'.")},"type")}]})},"createInitCommand");var Bt=Object.defineProperty,y=h((t,e)=>Bt(t,"name",{value:e,configurable:!0}),"r");const ae={bunchee:"@visulima/packem",tsup:"@visulima/packem","tsup-node":"@visulima/packem",unbuild:"@visulima/packem"},Vt={dependencies:`^${G.version}`,devDependencies:`^${G.version}`,peerDependencies:"*"},Rt=y((t,e,a,s)=>{const n={};for(const r of Object.keys(t))r===e?n[a]=s??t[e]:n[r]=t[r];return n},"renameKey"),At=/\bunbuild\b/g,Ft=/\bbunchee\b/g,qt=/\btsup(?:-node)?/g,Gt=/\bbuild\b/g,Kt=[{from:"tsup",rewrite:y(t=>t.replaceAll(qt,"packem build").replaceAll(Gt,"build"),"rewrite")},{from:"unbuild",rewrite:y(t=>t.replaceAll(At,"packem build"),"rewrite")},{from:"bunchee",rewrite:y(t=>t.replaceAll(Ft,"packem build"),"rewrite")}],Wt=y((t,e,a)=>{let s=e,n=!1;for(const r of Object.keys(ae))s.includes(r)&&(a.info(`Migrating \`${t}\` script from ${r} to packem`),n=!0,s=s.replaceAll(new RegExp(String.raw`\b${r}\b`,"g"),"packem").replaceAll(new RegExp(String.raw`\b${r}-node\b`,"g"),"packem"));for(const{from:r,rewrite:o}of Kt)s.includes(r)&&(a.info(`Migrating \`${t}\` script from ${r} to packem`),n=!0,s=o(s));return n?s:void 0},"migrateScript"),zt=y((t,e)=>{const a={...t};let s=!1;for(const n of Object.keys(a)){const r=Wt(n,a[n],e);r!==void 0&&(a[n]=r,s=!0)}return{found:s,scripts:a}},"migrateScripts"),Ut=y((t,e)=>{const a={...t};let s=!1;for(const[n,r]of Object.entries(Vt)){let o=a[n];for(const[i,c]of Object.entries(ae))o?.[i]&&(e.info(`Migrating \`${n}\` from ${i} to ${c}.`),s=!0,o=Rt(o,i,c,r),a[n]=o)}return{found:s,pkg:a}},"migrateDependencies"),Jt=y((t,e)=>{const a=["tsup","unbuild","bunchee"];for(const s of a)t[s]&&e.info(`Found \`${s}\` config field in package.json. Consider moving to packem.config.ts`)},"warnInlineConfigFields"),_t=y(async(t,e)=>{if(!q("package.json"))return e.error("No package.json found"),!1;const a=await xe("package.json","utf8"),s=JSON.parse(a),{found:n,pkg:r}=Ut(s,e);let o=n;if(r.scripts){const{found:c,scripts:l}=zt(r.scripts,e);c&&(r.scripts=l,o=!0)}if(Jt(r,e),!o)return e.warn("No migratable bundler dependencies found in package.json"),!1;const i=`${JSON.stringify(r,void 0,a.includes(" ")?" ":2)}
80
80
  `;return t?(e.info("[dry-run] package.json changes:"),e.info("Old content:"),console.info(a),e.info("New content:"),console.info(i)):(await Q("package.json",i),e.success("Migrated `package.json`")),!0},"migratePackageJson"),Ht=["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"],Yt=y(t=>{let e=!1;for(const a of Ht)q(a)&&(t.info(`Found config file \`${a}\`. Consider creating packem.config.ts instead.`),t.warn("Manual migration required for config files. See https://www.visulima.com/docs/package/packem"),e=!0);return e||t.warn("No bundler config files found"),e},"migrateConfigFiles"),Xt=y(async({cwd:t,dryRun:e,logger:a})=>{if(e)a.info("Dry run enabled. No changes will be made.");else{const n=Ee({input:j.stdin,output:j.stdout});a.warn(`
81
81
 
82
82
  Before proceeding, review the migration guide at https://www.visulima.com/docs/package/packem, as this process will modify your files.
83
- Uncommitted changes will be lost. Use the --dry-run flag to preview changes without applying them.`);const r=await n.question("Continue? (Y/n) ");if(n.close(),!(r.toLowerCase()==="y"||r==="")){a.error("Migration cancelled."),j.exitCode=1;return}}t&&j.chdir(t);let s=!1;await _t(e,a)&&(s=!0),Yt(a)&&(s=!0),s?a.success("Migration completed. Remember to run install command with your package manager."):(a.error("No migration performed."),j.exitCode=1)},"migrate"),Qt=y(t=>{t.addCommand({description:"Migrate from other bundlers (tsup, unbuild, bunchee, etc.) to packem",execute:y(async({logger:e,options:a})=>{const s=a;await Xt({cwd:s.cwd,dryRun:s.dryRun,logger:e})},"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 M=ie("packem",{logger:oe({reporters:[new be({error:{hideErrorCauseCodeView:!0,hideErrorCodeView:!0,hideErrorErrorsCodeView:!0}})],scope:"packem"}),packageName:we,packageVersion:ye});Tt(M);$t(M);tt(M);Qt(M);M.run({shouldExitProcess:!1});
83
+ Uncommitted changes will be lost. Use the --dry-run flag to preview changes without applying them.`);const r=await n.question("Continue? (Y/n) ");if(n.close(),!(r.toLowerCase()==="y"||r==="")){a.error("Migration cancelled."),j.exitCode=1;return}}t&&j.chdir(t);let s=!1;await _t(e,a)&&(s=!0),Yt(a)&&(s=!0),s?a.success("Migration completed. Remember to run install command with your package manager."):(a.error("No migration performed."),j.exitCode=1)},"migrate"),Qt=y(t=>{t.addCommand({description:"Migrate from other bundlers (tsup, unbuild, bunchee, etc.) to packem",execute:y(async({logger:e,options:a})=>{const s=a;await Xt({cwd:s.cwd,dryRun:s.dryRun,logger:e})},"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 M=ie("packem",{logger:oe({reporters:[new ye({error:{hideErrorCauseCodeView:!0,hideErrorCodeView:!0,hideErrorErrorsCodeView:!0}})],scope:"packem"}),packageName:ge,packageVersion:fe});Tt(M);$t(M);tt(M);Qt(M);M.run({shouldExitProcess:!1});
@@ -1,4 +1,4 @@
1
- import { B as BuildConfig, a as BuildConfigFunction, b as BuildPreset } from "../packem_shared/types.d-Cm6dnCyD.js";
1
+ import { B as BuildConfig, a as BuildConfigFunction, b as BuildPreset } from "../packem_shared/types.d-DOt53hsx.js";
2
2
  export type { BuildHooks } from '@visulima/packem-share/types';
3
3
  import '@arethetypeswrong/core';
4
4
  import '@visulima/packem-plugins';
@@ -1,5 +1,5 @@
1
1
  import { BabelPluginConfig } from '@visulima/packem-plugins/babel';
2
- import { B as BuildConfig } from "../../packem_shared/types.d-Cm6dnCyD.js";
2
+ import { B as BuildConfig } from "../../packem_shared/types.d-DOt53hsx.js";
3
3
  import '@arethetypeswrong/core';
4
4
  import '@visulima/packem-plugins';
5
5
  import '@visulima/packem-plugins/oxc';
@@ -1,5 +1,5 @@
1
1
  import { BabelPluginConfig } from '@visulima/packem-plugins/babel';
2
- import { B as BuildConfig } from "../../packem_shared/types.d-Cm6dnCyD.js";
2
+ import { B as BuildConfig } from "../../packem_shared/types.d-DOt53hsx.js";
3
3
  import '@arethetypeswrong/core';
4
4
  import '@visulima/packem-plugins';
5
5
  import '@visulima/packem-plugins/oxc';
@@ -1,5 +1,5 @@
1
1
  import { BabelPluginConfig } from '@visulima/packem-plugins/babel';
2
- import { B as BuildConfig } from "../../packem_shared/types.d-Cm6dnCyD.js";
2
+ import { B as BuildConfig } from "../../packem_shared/types.d-DOt53hsx.js";
3
3
  import '@arethetypeswrong/core';
4
4
  import '@visulima/packem-plugins';
5
5
  import '@visulima/packem-plugins/oxc';
@@ -1,4 +1,4 @@
1
- import { B as BuildConfig } from "../../packem_shared/types.d-Cm6dnCyD.js";
1
+ import { B as BuildConfig } from "../../packem_shared/types.d-DOt53hsx.js";
2
2
  import '@arethetypeswrong/core';
3
3
  import '@visulima/packem-plugins';
4
4
  import '@visulima/packem-plugins/oxc';
@@ -1,4 +1,4 @@
1
- import { B as BuildConfig } from "../../packem_shared/types.d-Cm6dnCyD.js";
1
+ import { B as BuildConfig } from "../../packem_shared/types.d-DOt53hsx.js";
2
2
  import '@arethetypeswrong/core';
3
3
  import '@visulima/packem-plugins';
4
4
  import '@visulima/packem-plugins/oxc';
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ConstructorOptions } from '@visulima/pail';
2
- import { B as BuildConfig } from "./packem_shared/types.d-Cm6dnCyD.js";
3
- export type { c as BuildEntry, d as BuildOptions, R as RollupBuildOptions } from "./packem_shared/types.d-Cm6dnCyD.js";
2
+ import { B as BuildConfig } from "./packem_shared/types.d-DOt53hsx.js";
3
+ export type { c as BuildEntry, d as BuildOptions, R as RollupBuildOptions } from "./packem_shared/types.d-DOt53hsx.js";
4
4
  export type { TransformerFn, TransformerName } from '@visulima/packem-plugins';
5
5
  import { Environment, Mode } from '@visulima/packem-share/types';
6
6
  export type { BuildContext, BuildContextBuildAssetAndChunk, BuildContextBuildEntry, BuildHooks, Environment, Mode, Runtime } from '@visulima/packem-share/types';