@visulima/packem 2.0.0-alpha.46 → 2.0.0-alpha.48
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 +32 -0
- package/dist/cli/index.js +40 -39
- package/dist/config/preset/preact.d.ts +18 -0
- package/dist/config/preset/preact.js +2 -0
- package/dist/config/utils/load-env-file.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/packem_shared/{default-DqhL3I_M.js → default-CwY3cq0Q.js} +1 -1
- package/dist/packem_shared/index-DkaUAiHf.js +174 -0
- package/dist/packem_shared/{isolatedDeclarationsOxcTransformer-WbfE6cGu-NeZOx2Y7.js → isolatedDeclarationsOxcTransformer-nQ2h3HMz-D30o-5Rj.js} +1 -1
- package/dist/rollup/plugins/oxc/isolated-declarations-oxc-transformer.js +1 -1
- package/package.json +26 -22
- package/dist/packem_shared/index-fGSICmM6.js +0 -174
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,35 @@
|
|
|
1
|
+
## @visulima/packem [2.0.0-alpha.48](https://github.com/visulima/packem/compare/@visulima/packem@2.0.0-alpha.47...@visulima/packem@2.0.0-alpha.48) (2025-12-28)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
* **preact:** add Preact and React compatibility examples with Babel support ([0b77282](https://github.com/visulima/packem/commit/0b77282b802ed3d7c5df0733c1d7f5e2156df721))
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Dependencies
|
|
9
|
+
|
|
10
|
+
* **@visulima/packem-rollup:** upgraded to 1.0.0-alpha.36
|
|
11
|
+
* **@visulima/rollup-plugin-css:** upgraded to 1.0.0-alpha.16
|
|
12
|
+
|
|
13
|
+
## @visulima/packem [2.0.0-alpha.47](https://github.com/visulima/packem/compare/@visulima/packem@2.0.0-alpha.46...@visulima/packem@2.0.0-alpha.47) (2025-12-24)
|
|
14
|
+
|
|
15
|
+
### Miscellaneous Chores
|
|
16
|
+
|
|
17
|
+
* update dependencies and improve configuration ([aa5ea19](https://github.com/visulima/packem/commit/aa5ea194b5add7df38a8855e618736fea0ae37fe))
|
|
18
|
+
* update package dependencies and improve configuration ([a7dd729](https://github.com/visulima/packem/commit/a7dd729e75a08380ebb70bffb629ec1df3c2bb7f))
|
|
19
|
+
|
|
20
|
+
### Code Refactoring
|
|
21
|
+
|
|
22
|
+
* enhance type inference and improve test coverage ([80fbf41](https://github.com/visulima/packem/commit/80fbf41b90595fa1c95133f0f18cd5c2ca48787c))
|
|
23
|
+
* improve environment variable handling and enhance entry inference ([c21e7b9](https://github.com/visulima/packem/commit/c21e7b9537a77fe835ef25d5bc4b4d0898e89b35))
|
|
24
|
+
* simplify JSX component definitions and update test cases ([14fd836](https://github.com/visulima/packem/commit/14fd8367b5164aecff0c39d28cc096a83fb1ca78))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### Dependencies
|
|
28
|
+
|
|
29
|
+
* **@visulima/packem-rollup:** upgraded to 1.0.0-alpha.35
|
|
30
|
+
* **@visulima/packem-share:** upgraded to 1.0.0-alpha.18
|
|
31
|
+
* **@visulima/rollup-plugin-css:** upgraded to 1.0.0-alpha.15
|
|
32
|
+
|
|
1
33
|
## @visulima/packem [2.0.0-alpha.46](https://github.com/visulima/packem/compare/@visulima/packem@2.0.0-alpha.45...@visulima/packem@2.0.0-alpha.46) (2025-12-16)
|
|
2
34
|
|
|
3
35
|
### Features
|
package/dist/cli/index.js
CHANGED
|
@@ -1,67 +1,68 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var
|
|
2
|
+
var Q=Object.defineProperty;var v=(t,s)=>Q(t,"name",{value:s,configurable:!0});import{createCerebro as Z}from"@visulima/cerebro";import ee from"@visulima/cerebro/logger/pail";import{SimpleReporter as se}from"@visulima/pail/reporter/simple";import j,{cwd as B,exit as te}from"node:process";import{installPackage as x}from"@antfu/install-pkg";import{confirm as b,select as h,multiselect as K,spinner as L,cancel as G,intro as ae,log as V,outro as ie}from"@clack/prompts";import{isAccessible as re,readFile as ne,writeFile as oe,isAccessibleSync as I,writeJsonSync as ce,writeFileSync as le}from"@visulima/fs";import{parsePackageJson as U}from"@visulima/package/package-json";import{join as S,resolve as T}from"@visulima/path";import de from"magic-string";import{exec as pe}from"tinyexec";import{t as A,E as ue}from"../packem_shared/index-CUp9WuCG.js";import{createJiti as me}from"jiti";import{c as fe,w as ge,j as ye}from"../packem_shared/index-DkaUAiHf.js";import{existsSync as N}from"node:fs";import{parseEnv as R}from"node:util";import{readFile as be,writeFile as we}from"node:fs/promises";import{createInterface as ve}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
|
|
5
|
-
preset: '${s}',`)}else if(
|
|
6
|
-
transformer:`);else{const r
|
|
7
|
-
preset: '${s}',`)}},"insertPreset"),
|
|
4
|
+
var he="@visulima/packem",z="2.0.0-alpha.47";const F={version:z};var ke=Object.defineProperty,Se=v((t,s)=>ke(t,"name",{value:s,configurable:!0}),"t");const W=Se(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 r of a)if(await re(S(t,r))){e=`./${r}`;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"),_={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 $e=Object.defineProperty,y=v((t,s)=>$e(t,"name",{value:s,configurable:!0}),"r$1");const je=["typedoc","typedoc-plugin-markdown","typedoc-plugin-rename-defaults"],Ce=["@babel/core","@babel/preset-react"],Pe=["react","react-dom"],xe=["@babel/core","babel-preset-solid"],De=["solid-js"],Me=["@babel/core","@babel/preset-react","babel-plugin-transform-hook-names"],Oe=["preact"],Ee=["unplugin-vue"],Te=["vue"],Ie=["rollup-plugin-svelte"],Le=["svelte"],D=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"),M=y((t,s)=>{const{logger:e,magic:a,packemConfig:r}=t,n=r.match(/defineConfig\s*\(\s*\{/);if(n&&n.index!==void 0){const o=n.index+n[0].length;if(r.includes("preset:")){const i=r.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(o,`
|
|
5
|
+
preset: '${s}',`)}else if(r.includes("transformer:"))a.replace("transformer:",`preset: '${s}',
|
|
6
|
+
transformer:`);else{const o=r.indexOf("{");o!==-1&&a.appendLeft(o+1,`
|
|
7
|
+
preset: '${s}',`)}},"insertPreset"),Be=y(async t=>{try{return((await pe("git",["status","--porcelain"],{nodeOptions:{cwd:t,stdio:["pipe","pipe","pipe"]}})).stdout?.trim().length??0)>0}catch{return!1}},"checkGitDirty"),X=y(async t=>{const s=S(t,"package.json"),e=await U(s,{resolveCatalogs:!0});return!!(e.devDependencies?.typescript??e.dependencies?.typescript)},"checkTypeScriptInstalled"),Ne=y(async t=>{const s=await X(t),e=[...Pe],a=[...Ce];return s?a.push("@types/react","@types/react-dom"):await b({initialValue:!1,message:"Do you want to use TypeScript?"})&&a.push("typescript","@types/react","@types/react-dom"),{devPackages:a,packages:e}},"getReactTypeDependencies"),O=y(async(t,s,e)=>{const{rootDirectory:a,spinner:r}=t;r.start("Installing packages"),await x(e,{cwd:a,dev:!1,silent:!0}),await x(s,{cwd:a,dev:!0,silent:!0}),r.stop("Installed packages")},"installPackages"),Ve=y(async t=>{const{logger:s,magic:e,packemConfig:a,packemConfigFormat:r,rootDirectory:n,spinner:o,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}r==="cjs"?e.prepend(`const typedocBuilder = require("@visulima/packem/builder/typedoc");
|
|
8
8
|
`):e.prepend(`import typedocBuilder from "@visulima/packem/builder/typedoc";
|
|
9
9
|
`),a.includes("builder: {")?e.replace("builder: {",`builder: {
|
|
10
10
|
typedoc: typedocBuilder,
|
|
11
|
-
`):e.replace(
|
|
11
|
+
`):e.replace(l,`${i}
|
|
12
12
|
builder: {
|
|
13
13
|
typedoc: typedocBuilder,
|
|
14
|
-
},`),s.info("Adding typedoc dependencies..."),
|
|
15
|
-
Typedoc added!`)},"addTypedoc"),
|
|
16
|
-
React preset added!`)},"addReact"),
|
|
17
|
-
Solid preset added!`)},"addSolid"),
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
`)
|
|
22
|
-
`):e.prepend(`
|
|
23
|
-
`)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
14
|
+
},`),s.info("Adding typedoc dependencies..."),o.start("Installing packages"),await x(je,{cwd:n,dev:!0,silent:!0}),o.stop("Installed packages"),s.success(`
|
|
15
|
+
Typedoc added!`)},"addTypedoc"),Ae=y(async t=>{const{logger:s,packemConfig:e}=t;if(D(e,"react","createReactPreset")){s.warn("React preset has already been added to the packem config.");return}M(t,"react");const{devPackages:a,packages:r}=await Ne(t.rootDirectory);s.info("Adding React dependencies..."),await O(t,a,r),s.success(`
|
|
16
|
+
React preset added!`)},"addReact"),Re=y(async t=>{const{logger:s,packemConfig:e}=t;if(D(e,"solid","createSolidPreset")){s.warn("Solid preset has already been added to the packem config.");return}M(t,"solid"),s.info("Adding Solid dependencies..."),await O(t,xe,De),s.success(`
|
|
17
|
+
Solid preset added!`)},"addSolid"),Fe=y(async t=>{const s=await X(t),e=[...Oe],a=[...Me];return s?a.push("@types/preact"):await b({initialValue:!1,message:"Do you want to use TypeScript?"})&&a.push("typescript","@types/preact"),{devPackages:a,packages:e}},"getPreactTypeDependencies"),qe=y(async t=>{const{logger:s,packemConfig:e}=t;if(D(e,"preact","createPreactPreset")){s.warn("Preact preset has already been added to the packem config.");return}M(t,"preact");const{devPackages:a,packages:r}=await Fe(t.rootDirectory);s.info("Adding Preact dependencies..."),await O(t,a,r),s.success(`
|
|
18
|
+
Preact preset added!`)},"addPreact"),Je=y(async t=>{const{logger:s,packemConfig:e}=t;if(D(e,"vue","createVuePreset")){s.warn("Vue preset has already been added to the packem config.");return}M(t,"vue"),s.info("Adding Vue dependencies..."),await O(t,Ee,Te),s.success(`
|
|
19
|
+
Vue preset added!`)},"addVue"),Ke=y(async t=>{const{logger:s,packemConfig:e}=t;if(D(e,"svelte","createSveltePreset")){s.warn("Svelte preset has already been added to the packem config.");return}M(t,"svelte"),s.info("Adding Svelte dependencies..."),await O(t,Ie,Le),s.success(`
|
|
20
|
+
Svelte preset added!`)},"addSvelte"),Ge=y(async t=>{const{logger:s,magic:e,packemConfig:a,packemConfigFormat:r,transformerReplaceKey:n,transformerSearchKey:o}=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 h({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 p=await K({message:"Pick extra loaders",options:[{label:"Sass",value:"sass"},{label:"Stylus",value:"stylus"},{label:"Less",value:"less"}],required:!1});if(p.includes("sass")){const w=await h({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"}]});w!=="sass"&&(p=p.filter(c=>c!=="sass"),p.push(w))}i.push(...p)}const d=[];for(const p of i)d.push(..._[p]);l!=="tailwindcss"&&i.push("sourceMap");for(const p of i){const w=p==="sass-embedded"||p==="node-sass"?"sass":p;r==="cjs"?e.prepend(`const ${w}Loader = require("@visulima/packem/css/loader/${w.toLowerCase()}");
|
|
21
|
+
`):e.prepend(`import ${w}Loader from "@visulima/packem/css/loader/${w.toLowerCase()}";
|
|
22
|
+
`)}const m=await b({initialValue:!1,message:"Do you want to minify your css?"});let g;m&&(g=await h({message:"Pick a css minifier",options:[{label:"CSSNano",value:"cssnano"},{label:"Lightning CSS",value:"lightningcss"}]}),i.includes("lightningcss")||d.push(g),r==="cjs"?e.prepend(`const ${g}Minifier = require("@visulima/packem/css/minifier/${g.toLowerCase()}");
|
|
23
|
+
`):e.prepend(`import ${g}Minifier from "@visulima/packem/css/minifier/${g.toLowerCase()}";
|
|
24
|
+
`));const f=i.map(p=>p==="sass-embedded"||p==="node-sass"?"sass":`${p}Loader`).join(", ");a.includes("rollup: {")?e.replace("rollup: {",`rollup: {
|
|
25
|
+
css: {${g?`
|
|
26
|
+
minifier: ${g}Minifier,`:""}
|
|
27
|
+
loaders: [${f}],
|
|
27
28
|
},
|
|
28
|
-
`):e.replace(
|
|
29
|
+
`):e.replace(o,`${n}
|
|
29
30
|
rollup: {
|
|
30
|
-
css: {${
|
|
31
|
-
minifier: ${
|
|
32
|
-
loaders: [${
|
|
31
|
+
css: {${g?`
|
|
32
|
+
minifier: ${g}Minifier,`:""}
|
|
33
|
+
loaders: [${f}],
|
|
33
34
|
},
|
|
34
|
-
},`),t.spinner.start("Installing packages"),await
|
|
35
|
-
CSS loaders added!`)},"addCss"),
|
|
36
|
-
`)){const r=n.trim();if(!r||r.startsWith("#"))continue;const i=r.match(/^([^=:#]+)=(.*)$/);if(i&&i[1]&&i[2]!==void 0){const d=i[1].trim();let l=i[2].trim();(l.startsWith('"')&&l.endsWith('"')||l.startsWith("'")&&l.endsWith("'"))&&(l=l.slice(1,-1)),(!s||d.startsWith(s))&&(o[`process.env.${d}`]=JSON.stringify(l))}}return o},"loadEnvFileManually");var Je=Object.defineProperty,Ge=w((t,s)=>Je(t,"name",{value:s,configurable:!0}),"e$2");const Ue=Ge(async(t,s,e,a,o)=>{const n=await z(s,o);let r=await t.import(n,{default:!0,try:!0})||{};return typeof r=="function"&&(r=await r(e,a)),{config:r,path:n}},"loadPackemConfig");var ze=Object.defineProperty,We=w((t,s)=>ze(t,"name",{value:s,configurable:!0}),"e$1");const _e=We(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 Xe=Object.defineProperty,C=w((t,s)=>Xe(t,"name",{value:s,configurable:!0}),"a$1");const He=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");let o;const n={};if(e.env)for(const c of e.env)c.key==="NODE_ENV"?o=c.value:n[`process.env.${c.key}`]=JSON.stringify(c.value);o===void 0&&(e.production?o=A:e.development&&(o=de));const r=[];if(e.external)for(const c of e.external)r.push(c.split(","));const i=M(B(),e.dir??"."),d=pe(i,{debug:e.debug}),{config:l,path:m}=await Ue(d,i,o,a,e.config??void 0);s.debug("Using packem config found at",m);const f=e.envFile??l.envFile,g=e.envPrefix??l.envPrefix??"PACKEM_",p={};if(f){const c=await Ke(f,i,g);Object.assign(p,c)}Object.assign(p,n);const v=await _e(l.preset??"none",d);e.minify&&e.sourcemap===void 0&&(e.sourcemap=!0);try{const c=ue()(l,me,v,{analyze:e.analyze,cjsInterop:e.cjsInterop,clean:e.clean,dtsOnly:e.dtsOnly,externals:r,killSignal:e.killSignal,minify:e.minify===void 0?o===A:e.minify,onSuccess:e.onSuccess,rollup:{esbuild:{target:e.target},license:{path:e.license},metafile:e.metafile,replace:{values:p},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"}}:{}});await fe(i,a,o,s,e.debug,c,e.tsconfig??void 0)}catch(c){s.error(c),ee(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")},{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: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 Ye=Object.defineProperty,x=w((t,s)=>Ye(t,"name",{value:s,configurable:!0}),"f");const Qe=x(t=>{t.addCommand({description:"Initialize packem configuration",execute:x(async({logger:s,options:e})=>{if(se("Welcome to packem setup"),I(S(e.dir,"packem.config.mjs"))){s.info("Packem project already initialized, you can use `packem build` to build your project");return}const a=M(B(),e.dir??"."),o=S(a,"package.json");if(!I(o))throw new Error("No package.json found in the directory");const n=await G(o,{resolveCatalogs:!0}),r=[];n.dependencies&&r.push(...Object.keys(n.dependencies)),n.devDependencies&&r.push(...Object.keys(n.devDependencies));const i=!!(n.devDependencies?.typescript??n.dependencies?.typescript),d=[];if(e.typescript===void 0&&!i?(e.typescript=await b({message:"Do you want to install TypeScript?"}),e.typescript&&d.push("typescript@latest")):V.message(`TypeScript version ${n.devDependencies?.typescript??n.dependencies?.typescript} is already installed`),!I(S(a,"tsconfig.json"))){const c=await b({message:"Do you want to use generate a tsconfig.json?"}),u=await b({message:"Do you want to run your code in the DOM?"});if(c){const k=L();k.start("Generating tsconfig.json"),re(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 h({message:"Pick a build runtime",options:[{label:"Node",value:"node"},{label:"Browser",value:"browser"}]})),r.includes("esbuild")?e.transformer="esbuild":r.includes("@swc/core")?e.transformer="swc":r.includes("sucrase")&&(e.transformer="sucrase"),e.transformer===void 0?(e.transformer=await h({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"&&!r.includes(e.transformer)&&await b({message:`Do you want to install ${e.transformer}?`})&&d.push(e.transformer==="swc"?"@swc/core":e.transformer)):V.message(`Transformer ${e.transformer} is already installed.`),e.isolatedDeclarationTransformer===void 0&&(e.isolatedDeclarationTransformer=await b({message:"Do you want to use an isolated declaration types?",initialValue:!1})),e.isolatedDeclarationTransformer===void 0&&(e.isolatedDeclarationTransformer=await h({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 c;switch(e.isolatedDeclarationTransformer){case"oxc":{c="oxc-transform";break}case"swc":{c="@swc/core";break}case"typescript":{c="typescript";break}default:J("Invalid isolated declaration transformer")}c!==void 0&&!r.includes(c)&&await b({message:`Do you want to install ${c}?`})&&d.push(c)}e.css===void 0&&(e.css=await b({message:"Do you want to use css in your project?",initialValue:!1}));const l=[];if(e.css){const c=await h({message:"Pick a css loader",options:[{label:"PostCSS",value:"postcss"},{hint:"experimental",label:"Lightning CSS",value:"lightningcss"}]});l.push(c);let u=await K({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 h({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(X=>X!=="sass"),u.push(k))}if(l.push(...u),await b({message:`Do you want to install "${l.join('", "')}"?`}))for(const k of l)d.push(...W[k]);l.push("sourceMap")}e.cssMinifier===void 0&&(e.cssMinifier=await b({message:"Do you want to minify your css?",initialValue:!1}));let m;e.cssMinifier&&(m=await h({message:"Pick a css minifier",options:[{label:"CSSNano",value:"cssnano"},{label:"Lightning CSS",value:"lightningcss"}]}),l.includes("lightningcss")||await b({message:`Do you want to install "${m}"?`})&&d.push(m));let f="",g="";if(e.isolatedDeclarationTransformer&&(g+=`,
|
|
37
|
-
isolatedDeclarationTransformer`),(e.css||e.cssMinifier)&&(
|
|
35
|
+
},`),t.spinner.start("Installing packages"),await x(d,{cwd:t.rootDirectory,dev:!0,silent:!0}),t.spinner.stop("Installed packages"),s.success(`
|
|
36
|
+
CSS loaders added!`)},"addCss"),Ue=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 r=L(),n=T(B(),a.dir??".");let o;try{o=await W(n,a.config)}catch{e.error("Could not find a packem config file, please run `packem init` first.");return}if(await Be(n)&&!await b({initialValue:!1,message:"Git repository has uncommitted changes. Do you want to proceed?"})){G("Operation cancelled.");return}const i=await ne(o,{buffer:!1}),l=i.includes("import")?"esm":"cjs",d=new de(i),m=" transformer,",g=i.includes(" transformer,")?" transformer,":" transformer",f={logger:e,magic:d,packemConfig:i,packemConfigFilePath:o,packemConfigFormat:l,rootDirectory:n,spinner:r,transformerReplaceKey:m,transformerSearchKey:g};s.includes("typedoc")&&await Ve(f),s.includes("react")&&await Ae(f),s.includes("solid")&&await Re(f),s.includes("preact")&&await qe(f),s.includes("vue")&&await Je(f),s.includes("svelte")&&await Ke(f),s.includes("css")&&await Ge(f),await oe(o,d.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 ze=Object.defineProperty,H=v((t,s)=>ze(t,"name",{value:s,configurable:!0}),"a$2");const We=H(async(t,s,e="PACKEM_")=>{const a=T(s,t);if(!N(a))return{};const{readFile:r}=await import("node:fs/promises"),n=await r(a,"utf-8"),o={};if(typeof R=="function")try{const i=R(n);for(const[l,d]of Object.entries(i))(!e||l.startsWith(e))&&(o[`process.env.${l}`]=JSON.stringify(d))}catch{return q(n,e)}else return q(n,e);return o},"loadEnvFile"),q=H((t,s="PACKEM_")=>{const e={};for(const a of t.split(`
|
|
37
|
+
`)){const r=a.trim();if(!r||r.startsWith("#"))continue;const n=r.match(/^([^=:#]+)=(.*)$/);if(n&&n[1]&&n[2]!==void 0){const o=n[1].trim();let i=n[2].trim();(i.startsWith('"')&&i.endsWith('"')||i.startsWith("'")&&i.endsWith("'"))&&(i=i.slice(1,-1)),(!s||o.startsWith(s))&&(e[`process.env.${o}`]=JSON.stringify(i))}}return e},"loadEnvFileManually");var _e=Object.defineProperty,Xe=v((t,s)=>_e(t,"name",{value:s,configurable:!0}),"e$2");const He=Xe(async(t,s,e,a,r)=>{const n=await W(s,r);let o=await t.import(n,{default:!0,try:!0})||{};return typeof o=="function"&&(o=await o(e,a)),{config:o,path:n}},"loadPackemConfig");var Ye=Object.defineProperty,Qe=v((t,s)=>Ye(t,"name",{value:s,configurable:!0}),"e$1");const Ze=Qe(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"preact":{const{createPreactPreset:e}=await import("../config/preset/preact.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 es=Object.defineProperty,C=v((t,s)=>es(t,"name",{value:s,configurable:!0}),"a$1");const ss=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");let r;const n={};if(e.env)for(const c of e.env)c.key==="NODE_ENV"?r=c.value:n[`process.env.${c.key}`]=JSON.stringify(c.value);r===void 0&&(e.production?r=A:e.development&&(r=ue));const o=[];if(e.external)for(const c of e.external)o.push(c.split(","));const i=T(B(),e.dir??"."),l=me(i,{debug:e.debug}),{config:d,path:m}=await He(l,i,r,a,e.config??void 0);s.debug("Using packem config found at",m);const g=e.envFile??d.envFile,f=e.envPrefix??d.envPrefix??"PACKEM_",p={};if(g){const c=await We(g,i,f);Object.assign(p,c)}Object.assign(p,n);const w=await Ze(d.preset??"none",l);e.minify&&e.sourcemap===void 0&&(e.sourcemap=!0);try{const c=fe()(d,ge,w,{analyze:e.analyze,cjsInterop:e.cjsInterop,clean:e.clean,dtsOnly:e.dtsOnly,externals:o,killSignal:e.killSignal,minify:e.minify===void 0?r===A:e.minify,onSuccess:e.onSuccess,rollup:{esbuild:{target:e.target},license:{path:e.license},metafile:e.metafile,...Object.keys(p).length>0||Object.keys(n).length>0?{replace:{values:p}}:{},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"}}:{}});await ye(i,a,r,s,e.debug,c,e.tsconfig??void 0)}catch(c){s.error(c),te(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")},{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: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 ts=Object.defineProperty,P=v((t,s)=>ts(t,"name",{value:s,configurable:!0}),"f");const as=P(t=>{t.addCommand({description:"Initialize packem configuration",execute:P(async({logger:s,options:e})=>{if(ae("Welcome to packem setup"),I(S(e.dir,"packem.config.mjs"))){s.info("Packem project already initialized, you can use `packem build` to build your project");return}const a=T(B(),e.dir??"."),r=S(a,"package.json");if(!I(r))throw new Error("No package.json found in the directory");const n=await U(r,{resolveCatalogs:!0}),o=[];n.dependencies&&o.push(...Object.keys(n.dependencies)),n.devDependencies&&o.push(...Object.keys(n.devDependencies));const i=!!(n.devDependencies?.typescript??n.dependencies?.typescript),l=[];if(e.typescript===void 0&&!i?(e.typescript=await b({message:"Do you want to install TypeScript?"}),e.typescript&&l.push("typescript@latest")):V.message(`TypeScript version ${n.devDependencies?.typescript??n.dependencies?.typescript} is already installed`),!I(S(a,"tsconfig.json"))){const c=await b({message:"Do you want to use generate a tsconfig.json?"}),u=await b({message:"Do you want to run your code in the DOM?"});if(c){const k=L();k.start("Generating tsconfig.json"),ce(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 h({message:"Pick a build runtime",options:[{label:"Node",value:"node"},{label:"Browser",value:"browser"}]})),o.includes("esbuild")?e.transformer="esbuild":o.includes("@swc/core")?e.transformer="swc":o.includes("sucrase")&&(e.transformer="sucrase"),e.transformer===void 0?(e.transformer=await h({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"&&!o.includes(e.transformer)&&await b({message:`Do you want to install ${e.transformer}?`})&&l.push(e.transformer==="swc"?"@swc/core":e.transformer)):V.message(`Transformer ${e.transformer} is already installed.`),e.isolatedDeclarationTransformer===void 0&&(e.isolatedDeclarationTransformer=await b({message:"Do you want to use an isolated declaration types?",initialValue:!1})),e.isolatedDeclarationTransformer===void 0&&(e.isolatedDeclarationTransformer=await h({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 c;switch(e.isolatedDeclarationTransformer){case"oxc":{c="oxc-transform";break}case"swc":{c="@swc/core";break}case"typescript":{c="typescript";break}default:G("Invalid isolated declaration transformer")}c!==void 0&&!o.includes(c)&&await b({message:`Do you want to install ${c}?`})&&l.push(c)}e.css===void 0&&(e.css=await b({message:"Do you want to use css in your project?",initialValue:!1}));const d=[];if(e.css){const c=await h({message:"Pick a css loader",options:[{label:"PostCSS",value:"postcss"},{hint:"experimental",label:"Lightning CSS",value:"lightningcss"}]});d.push(c);let u=await K({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 h({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(Y=>Y!=="sass"),u.push(k))}if(d.push(...u),await b({message:`Do you want to install "${d.join('", "')}"?`}))for(const k of d)l.push(..._[k]);d.push("sourceMap")}e.cssMinifier===void 0&&(e.cssMinifier=await b({message:"Do you want to minify your css?",initialValue:!1}));let m;e.cssMinifier&&(m=await h({message:"Pick a css minifier",options:[{label:"CSSNano",value:"cssnano"},{label:"Lightning CSS",value:"lightningcss"}]}),d.includes("lightningcss")||await b({message:`Do you want to install "${m}"?`})&&l.push(m));let g="",f="";if(e.isolatedDeclarationTransformer&&(f+=`,
|
|
38
|
+
isolatedDeclarationTransformer`),(e.css||e.cssMinifier)&&(f+=`,
|
|
38
39
|
rollup: {
|
|
39
|
-
css: {`),e.css){const c=
|
|
40
|
-
loaders: [${c}],`}if(e.cssMinifier&&m&&(
|
|
41
|
-
minifier: ${m}Minifier,`),(e.css||e.cssMinifier)&&(
|
|
40
|
+
css: {`),e.css){const c=d.map(u=>((u==="sass-embedded"||u==="node-sass")&&(u="sass"),`${u}Loader`)).join(", ");f+=`
|
|
41
|
+
loaders: [${c}],`}if(e.cssMinifier&&m&&(f+=`
|
|
42
|
+
minifier: ${m}Minifier,`),(e.css||e.cssMinifier)&&(f+=`
|
|
42
43
|
}
|
|
43
44
|
}`),i||n.type==="module"){let c="";if(e.isolatedDeclarationTransformer&&(c+=`import isolatedDeclarationTransformer from "@visulima/packem/dts/isolated/transformer/${e.isolatedDeclarationTransformer}";
|
|
44
|
-
`),e.css)for(let u of
|
|
45
|
+
`),e.css)for(let u of d)(u==="sass-embedded"||u==="node-sass")&&(u="sass"),c+=`import ${u}Loader from "@visulima/packem/css/loader/${u.toLowerCase()}";
|
|
45
46
|
`;e.cssMinifier&&m&&(c+=`import ${m}Minifier from "@visulima/packem/css/minifier/${m.toLowerCase()}";
|
|
46
|
-
`),
|
|
47
|
+
`),g=`import { defineConfig } from "@visulima/packem/config";
|
|
47
48
|
import transformer from "@visulima/packem/transformer/${e.transformer}";
|
|
48
49
|
${c}
|
|
49
50
|
export default defineConfig({
|
|
50
51
|
runtime: "${e.runtime}",
|
|
51
|
-
transformer${
|
|
52
|
+
transformer${f}
|
|
52
53
|
});
|
|
53
54
|
`}else{let c="";if(e.isolatedDeclarationTransformer&&(c+=`const isolatedDeclarationTransformer = require("@visulima/packem/dts/isolated/transformer/${e.isolatedDeclarationTransformer}");
|
|
54
|
-
`),e.css)for(let u of
|
|
55
|
+
`),e.css)for(let u of d)(u==="sass-embedded"||u==="node-sass")&&(u="sass"),c+=`const ${u}Loader = require("@visulima/packem/css/loader/${u.toLowerCase()}");
|
|
55
56
|
`;e.cssMinifier&&m&&(c+=`const ${m}Minifier = require("@visulima/packem/css/minifier/${m.toLowerCase()}");
|
|
56
|
-
`),
|
|
57
|
+
`),g=`const { defineConfig } = require("@visulima/packem/config");
|
|
57
58
|
const transformer = require("@visulima/packem/transformer/${e.transformer}");
|
|
58
59
|
${c}
|
|
59
60
|
module.exports = defineConfig({
|
|
60
61
|
runtime: ${e.runtime},
|
|
61
|
-
transformer${
|
|
62
|
+
transformer${f}
|
|
62
63
|
});
|
|
63
|
-
`}const p=L(),
|
|
64
|
+
`}const p=L(),w=i?"ts":"js";l.length>0&&(p.start("Installing packages"),await x(l,{cwd:a,dev:!0,silent:!0}),p.stop("Installed packages")),p.start(`Creating packem.config.${w}`),le(S(a,`packem.config.${w}`),g),p.stop(`Created packem.config.${w}`),ie("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:P(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:P(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:P(s=>{if(s==="node"||s==="browser")return s;throw new Error("Invalid runtime. Use 'node' or 'browser'.")},"type")}]})},"createInitCommand");var is=Object.defineProperty,$=v((t,s)=>is(t,"name",{value:s,configurable:!0}),"a");const rs=$(async({cwd:t,dryRun:s,logger:e})=>{if(s)e.info("Dry run enabled. No changes will be made.");else{const r=ve({input:j.stdin,output:j.stdout});e.warn(`
|
|
64
65
|
|
|
65
66
|
Before proceeding, review the migration guide at https://www.visulima.com/docs/package/packem, as this process will modify your files.
|
|
66
|
-
Uncommitted changes will be lost. Use the --dry-run flag to preview changes without applying them.`);const n=await
|
|
67
|
-
`;return t?(s.info("[dry-run] package.json changes:"),s.info("Old content:"),console.info(e),s.info("New content:"),console.info(
|
|
67
|
+
Uncommitted changes will be lost. Use the --dry-run flag to preview changes without applying them.`);const n=await r.question("Continue? (Y/n) ");if(r.close(),!(n.toLowerCase()==="y"||n==="")){e.error("Migration cancelled."),j.exitCode=1;return}}t&&j.chdir(t);let a=!1;await os(s,e)&&(a=!0),await ls(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"),J={bunchee:"@visulima/packem",tsup:"@visulima/packem","tsup-node":"@visulima/packem",unbuild:"@visulima/packem"},ns={dependencies:`^${F.version}`,devDependencies:`^${F.version}`,peerDependencies:"*"},os=$(async(t,s)=>{if(!N("package.json"))return s.error("No package.json found"),!1;const e=await be("package.json","utf8"),a=JSON.parse(e);let r=!1;for(const[i,l]of Object.entries(ns))for(const[d,m]of Object.entries(J))a[i]?.[d]&&(s.info(`Migrating \`${i}\` from ${d} to ${m}.`),r=!0,a[i]=ds(a[i],d,m,l));if(a.scripts)for(const i of Object.keys(a.scripts)){for(const[l,d]of Object.entries(J))a.scripts[i].includes(l)&&(s.info(`Migrating \`${i}\` script from ${l} to packem`),r=!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`),r=!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`),r=!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`),r=!0,a.scripts[i]=a.scripts[i].replaceAll(/\bbunchee\b/g,"packem build"))}const n=["tsup","unbuild","bunchee"];for(const i of n)a[i]&&s.info(`Found \`${i}\` config field in package.json. Consider moving to packem.config.ts`);if(!r)return s.warn("No migratable bundler dependencies found in package.json"),!1;const o=`${JSON.stringify(a,null,e.includes(" ")?" ":2)}
|
|
68
|
+
`;return t?(s.info("[dry-run] package.json changes:"),s.info("Old content:"),console.info(e),s.info("New content:"),console.info(o)):(await we("package.json",o),s.success("Migrated `package.json`")),!0},"migratePackageJson"),cs=["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"],ls=$(async(t,s)=>{let e=!1;for(const a of cs)N(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"),ds=$((t,s,e,a)=>{const r={};for(const n of Object.keys(t))n===s?r[e]=a||t[s]:r[n]=t[n];return r},"renameKey"),ps=$(t=>{t.addCommand({description:"Migrate from other bundlers (tsup, unbuild, bunchee, etc.) to packem",execute:$(async({logger:s,options:e})=>{await rs({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 E=Z("packem",{logger:await ee({reporters:[new se({error:{hideErrorCauseCodeView:!0,hideErrorCodeView:!0,hideErrorErrorsCodeView:!0}})],scope:"packem"}),packageName:he,packageVersion:z});as(E);ss(E);Ue(E);ps(E);E.run({shouldExitProcess:!1});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { BabelPluginConfig } from "@visulima/packem-rollup/babel";
|
|
2
|
+
import type { BuildConfig } from "../../types.d.ts";
|
|
3
|
+
export interface PreactPresetOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Enable Preact devtools in production builds
|
|
6
|
+
* @default false
|
|
7
|
+
*/
|
|
8
|
+
devtoolsInProd?: boolean;
|
|
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
|
+
export declare const createPreactPreset: (options?: PreactPresetOptions) => BuildConfig;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var v=Object.defineProperty;var m=(o,a)=>v(o,"name",{value:a,configurable:!0});var y=Object.defineProperty,n=m((o,a)=>y(o,"name",{value:a,configurable:!0}),"o");const A=n(()=>({name:"packem:preact-alias-transform",transform(o,a){if(a.includes("/node_modules/"))return;let t=!1,e=o;if((e.includes('from "react"')||e.includes("from 'react'"))&&(e=e.replaceAll(/from\s+["']react["']/g,'from "preact/compat"'),t=!0),(e.includes('from "react-dom"')||e.includes("from 'react-dom'"))&&(e=e.replaceAll(/from\s+["']react-dom["']/g,'from "preact/compat"'),t=!0),(e.includes('from "react-dom/test-utils"')||e.includes("from 'react-dom/test-utils'"))&&(e=e.replaceAll(/from\s+["']react-dom\/test-utils["']/g,'from "preact/test-utils"'),t=!0),(e.includes('from "react-dom/client"')||e.includes("from 'react-dom/client'"))&&(e=e.replaceAll(/from\s+["']react-dom\/client["']/g,'from "preact/compat"'),t=!0),(e.includes('from "react/jsx-runtime"')||e.includes("from 'react/jsx-runtime'"))&&(e=e.replaceAll(/from\s+["']react\/jsx-runtime["']/g,'from "preact/jsx-runtime"'),t=!0),!!t)return{code:e,map:void 0}}}),"createPreactAliasTransformPlugin"),b=n((o,a)=>({name:"packem:preact-devtools",transform(t,e){return!this.getModuleInfo(e)?.isEntry||a&&!o||t.includes("preact/debug")||t.includes("preact/devtools")?void 0:{code:`import "${a?"preact/devtools":"preact/debug"}";
|
|
2
|
+
${t}`,map:void 0}}}),"createPreactDevtoolsPlugin"),P=n((o={})=>{const{devtoolsInProd:a=!1,plugins:t=[],presets:e=[]}=o,s=[],p=[["@babel/preset-react",{importSource:"preact",runtime:"automatic"}]];s.push("babel-plugin-transform-hook-names");const l=[...s,...Array.isArray(t)?t:[]],i=[...p,...Array.isArray(e)?e:[]];return{hooks:{"rollup:options":n((u,c)=>{if(!c.input&&!c.plugins)return;const d=u.environment==="production";Array.isArray(c.plugins)||(c.plugins=[]);const f=A();c.plugins.some(r=>typeof r=="object"&&r!==null&&"name"in r&&r.name==="packem:preact-alias-transform"||Array.isArray(r)&&r[0]&&typeof r[0]=="object"&&r[0]!==null&&"name"in r[0]&&r[0].name==="packem:preact-alias-transform")||c.plugins.unshift(f);const g=b(a,d);c.plugins.some(r=>typeof r=="object"&&r!==null&&"name"in r&&r.name==="packem:preact-devtools"||Array.isArray(r)&&r[0]&&typeof r[0]=="object"&&r[0]!==null&&"name"in r[0]&&r[0].name==="packem:preact-devtools")||c.plugins.push(g)},"rollup:options")},rollup:{alias:{entries:[{find:"react",replacement:"preact/compat"},{find:"react-dom",replacement:"preact/compat"},{find:"react-dom/test-utils",replacement:"preact/test-utils"},{find:"react/jsx-runtime",replacement:"preact/jsx-runtime"}]},babel:{plugins:l.length>0?l:void 0,presets:i.length>0?i:void 0}},validation:{dependencies:{hoisted:{exclude:["react","react-dom"]},unused:{exclude:["preact","react","react-dom"]}}}}},"createPreactPreset");export{P as createPreactPreset};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Loads environment variables from a .env file with optional prefix filtering.
|
|
3
|
-
* Uses Node.js built-in `
|
|
3
|
+
* Uses Node.js built-in `util.parseEnv` to parse the file content without modifying `process.env`.
|
|
4
4
|
* @param envFilePath Path to the .env file (relative to rootDirectory or absolute)
|
|
5
5
|
* @param rootDirectory Root directory for resolving relative paths
|
|
6
6
|
* @param prefix Optional prefix to filter environment variables (e.g., "PACKEM_")
|
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{j as g}from"./packem_shared/index-
|
|
1
|
+
var c=Object.defineProperty;var o=(e,r)=>c(e,"name",{value:r,configurable:!0});import{createPail as s}from"@visulima/pail";import{SimpleReporter as u}from"@visulima/pail/reporter";import{j as g}from"./packem_shared/index-DkaUAiHf.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 +1 @@
|
|
|
1
|
-
import{d as s}from"./isolatedDeclarationsOxcTransformer-
|
|
1
|
+
import{d as s}from"./isolatedDeclarationsOxcTransformer-nQ2h3HMz-D30o-5Rj.js";import{z as e}from"./oxcResolvePlugin-Ccef6pyL-D14z9S9i.js";import{s as f}from"./oxcTransformPlugin-BGmQroQ4-D4RYvg8H.js";export{s as isolatedDeclarationsOxcTransformer,e as oxcResolvePlugin,f as oxcTransformPlugin};
|