@visulima/packem 2.0.0-alpha.45 → 2.0.0-alpha.46
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 +29 -0
- package/README.md +42 -0
- package/dist/cli/index.js +44 -43
- package/dist/config/preset/solid.js +1 -1
- package/dist/config/utils/load-env-file.d.ts +15 -0
- package/dist/index.js +1 -1
- package/dist/packem/utils/group-by-keys.d.ts +10 -1
- package/dist/packem_shared/default-DqhL3I_M.js +1 -0
- package/dist/packem_shared/index-fGSICmM6.js +174 -0
- package/dist/packem_shared/oxcTransformPlugin-BGmQroQ4-D4RYvg8H.js +4 -0
- package/dist/rollup/plugins/oxc/oxc-transformer.js +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/utils/create-defu-with-hooks-merger.d.ts +14 -0
- package/package.json +6 -6
- package/dist/packem_shared/default-B2EOH52z.js +0 -1
- package/dist/packem_shared/index-ChtiNkgT.js +0 -174
- package/dist/packem_shared/oxcTransformPlugin-DfVQouIB-Cpfv95eA.js +0 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,32 @@
|
|
|
1
|
+
## @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
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
* add solid preset options and user babel options merging ([1b93748](https://github.com/visulima/packem/commit/1b93748f986619ed121dbc31361072421eaae74f))
|
|
6
|
+
* add support for loading environment variables from .env files ([0b041c6](https://github.com/visulima/packem/commit/0b041c62cb5457095bea5a9ea68ab8dbf8b63f53))
|
|
7
|
+
* enhance build configuration and environment handling ([78d4c32](https://github.com/visulima/packem/commit/78d4c32f5f12685bb09acc5c50c3200274765125))
|
|
8
|
+
* enhance hooks functionality and improve documentation ([dfea61d](https://github.com/visulima/packem/commit/dfea61ddd2b286327c382b2c50b1b94cceb3d3ad))
|
|
9
|
+
* enhance package.json exports and improve Solid preset handling ([ba61fb6](https://github.com/visulima/packem/commit/ba61fb6e71fbfed8ae8f66256676b5606a5dca87))
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* update export handling and improve entry inference logic ([4897f4f](https://github.com/visulima/packem/commit/4897f4f31b7d9ec87b3254391f4b11385478e2e6))
|
|
14
|
+
|
|
15
|
+
### Miscellaneous Chores
|
|
16
|
+
|
|
17
|
+
* update package dependencies and improve build configuration ([690fb64](https://github.com/visulima/packem/commit/690fb641471278110f6175e6396d5bee9352c8eb))
|
|
18
|
+
|
|
19
|
+
### Code Refactoring
|
|
20
|
+
|
|
21
|
+
* streamline environment variable handling and improve test coverage ([642c513](https://github.com/visulima/packem/commit/642c513d61fdc64069a7d7affc78b986ad29b9b1))
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### Dependencies
|
|
25
|
+
|
|
26
|
+
* **@visulima/packem-rollup:** upgraded to 1.0.0-alpha.34
|
|
27
|
+
* **@visulima/packem-share:** upgraded to 1.0.0-alpha.17
|
|
28
|
+
* **@visulima/rollup-plugin-css:** upgraded to 1.0.0-alpha.14
|
|
29
|
+
|
|
1
30
|
## @visulima/packem [2.0.0-alpha.45](https://github.com/visulima/packem/compare/@visulima/packem@2.0.0-alpha.44...@visulima/packem@2.0.0-alpha.45) (2025-12-13)
|
|
2
31
|
|
|
3
32
|
### Bug Fixes
|
package/README.md
CHANGED
|
@@ -495,6 +495,48 @@ This will replace all instances of `process.env.NODE_ENV` with `'production'` an
|
|
|
495
495
|
packem build --env.NODE_ENV=production
|
|
496
496
|
```
|
|
497
497
|
|
|
498
|
+
#### Loading from .env files
|
|
499
|
+
|
|
500
|
+
You can also load environment variables from `.env` files using the `--env-file` option:
|
|
501
|
+
|
|
502
|
+
```sh
|
|
503
|
+
# Load from .env file with default prefix (PACKEM_)
|
|
504
|
+
packem build --env-file .env
|
|
505
|
+
|
|
506
|
+
# Load from custom .env file with custom prefix
|
|
507
|
+
packem build --env-file .env.production --env-prefix BUILD_
|
|
508
|
+
|
|
509
|
+
# Combine .env file with CLI variables (CLI vars override .env vars)
|
|
510
|
+
packem build --env-file .env --env.API_URL=https://api.example.com
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
**Configuration file:**
|
|
514
|
+
|
|
515
|
+
You can also configure this in your `packem.config.ts`:
|
|
516
|
+
|
|
517
|
+
```typescript
|
|
518
|
+
export default defineConfig({
|
|
519
|
+
envFile: ".env",
|
|
520
|
+
envPrefix: "PACKEM_", // default: "PACKEM_"
|
|
521
|
+
// ...
|
|
522
|
+
});
|
|
523
|
+
```
|
|
524
|
+
|
|
525
|
+
**How it works:**
|
|
526
|
+
|
|
527
|
+
- Variables from `.env` files are loaded first
|
|
528
|
+
- CLI `--env.*` variables override `.env` file variables
|
|
529
|
+
- Only variables matching the prefix (default: `PACKEM_`) are loaded for security
|
|
530
|
+
- Variables are replaced at compile-time in your code
|
|
531
|
+
|
|
532
|
+
**Example .env file:**
|
|
533
|
+
|
|
534
|
+
```env
|
|
535
|
+
PACKEM_API_URL=https://api.example.com
|
|
536
|
+
PACKEM_VERSION=1.0.0
|
|
537
|
+
PACKEM_DEBUG=true
|
|
538
|
+
```
|
|
539
|
+
|
|
498
540
|
## Programmatic Usage
|
|
499
541
|
|
|
500
542
|
You can use Packem programmatically in your Node.js applications without the CLI:
|
package/dist/cli/index.js
CHANGED
|
@@ -1,66 +1,67 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var
|
|
2
|
+
var H=Object.defineProperty;var w=(t,s)=>H(t,"name",{value:s,configurable:!0});import{createCerebro as Y}from"@visulima/cerebro";import Q from"@visulima/cerebro/logger/pail";import{SimpleReporter as Z}from"@visulima/pail/reporter/simple";import j,{cwd as B,exit as ee}from"node:process";import{installPackage as D}from"@antfu/install-pkg";import{confirm as b,select as h,multiselect as K,spinner as L,cancel as J,intro as se,log as V,outro as te}from"@clack/prompts";import{isAccessible as ae,readFile as ie,writeFile as oe,isAccessibleSync as I,writeJsonSync as re,writeFileSync as ne}from"@visulima/fs";import{parsePackageJson as G}from"@visulima/package/package-json";import{join as S,resolve as M}from"@visulima/path";import ce from"magic-string";import{exec as le}from"tinyexec";import{t as A,E as de}from"../packem_shared/index-CUp9WuCG.js";import{createJiti as pe}from"jiti";import{c as ue,w as me,j as fe}from"../packem_shared/index-fGSICmM6.js";import{existsSync as N}from"node:fs";import{readFile as ge,writeFile as ye}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
|
|
4
|
+
var be="@visulima/packem",U="2.0.0-alpha.45";const F={version:U};var we=Object.defineProperty,he=w((t,s)=>we(t,"name",{value:s,configurable:!0}),"t");const z=he(async(t,s="")=>{let e=s;if(!e){const a=["packem.config.js","packem.config.mjs","packem.config.cjs","packem.config.ts","packem.config.cts","packem.config.mts"];for(const o of a)if(await ae(S(t,o))){e=`./${o}`;break}}if(!/\.(?:js|mjs|cjs|ts|cts|mts)$/.test(e))throw new Error("Invalid packem config file extension. Only .js, .mjs, .cjs, .ts, .cts and .mts extensions are allowed.");return e},"findPackemFile"),W={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 ke=Object.defineProperty,y=w((t,s)=>ke(t,"name",{value:s,configurable:!0}),"r$1");const Se=["typedoc","typedoc-plugin-markdown","typedoc-plugin-rename-defaults"],$e=["@babel/core","@babel/preset-react"],je=["react","react-dom"],Ce=["@babel/core","babel-preset-solid"],xe=["solid-js"],De=["unplugin-vue"],Pe=["vue"],Me=["rollup-plugin-svelte"],Oe=["svelte"],O=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"),E=y((t,s)=>{const{logger:e,magic:a,packemConfig:o}=t,n=o.match(/defineConfig\s*\(\s*\{/);if(n&&n.index!==void 0){const r=n.index+n[0].length;if(o.includes("preset:")){const i=o.match(/preset:\s*['"]([^'"]+)['"]/);if(i)a.replace(i[0],`preset: '${s}'`);else throw e.warn(`A preset already exists in the config. Please manually set it to '${s}'.`),new Error("Preset exists but is not a string")}else a.appendLeft(r,`
|
|
5
5
|
preset: '${s}',`)}else if(o.includes("transformer:"))a.replace("transformer:",`preset: '${s}',
|
|
6
|
-
transformer:`);else{const
|
|
7
|
-
preset: '${s}',`)}},"insertPreset"),
|
|
6
|
+
transformer:`);else{const r=o.indexOf("{");r!==-1&&a.appendLeft(r+1,`
|
|
7
|
+
preset: '${s}',`)}},"insertPreset"),Ee=y(async t=>{try{return((await le("git",["status","--porcelain"],{nodeOptions:{cwd:t,stdio:["pipe","pipe","pipe"]}})).stdout?.trim().length??0)>0}catch{return!1}},"checkGitDirty"),Te=y(async t=>{const s=S(t,"package.json"),e=await G(s,{resolveCatalogs:!0});return!!(e.devDependencies?.typescript??e.dependencies?.typescript)},"checkTypeScriptInstalled"),Ie=y(async t=>{const s=await Te(t),e=[...je],a=[...$e];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"),T=y(async(t,s,e)=>{const{rootDirectory:a,spinner:o}=t;o.start("Installing packages"),await D(e,{cwd:a,dev:!1,silent:!0}),await D(s,{cwd:a,dev:!0,silent:!0}),o.stop("Installed packages")},"installPackages"),Le=y(async t=>{const{logger:s,magic:e,packemConfig:a,packemConfigFormat:o,rootDirectory:n,spinner:r,transformerReplaceKey:i,transformerSearchKey:d}=t;if(a.includes("typedoc: typedocBuilder")||a.includes("@visulima/packem/builder/typedoc")){s.warn("Typedoc has already been added to the packem config.");return}o==="cjs"?e.prepend(`const typedocBuilder = require("@visulima/packem/builder/typedoc");
|
|
8
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(d,`${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
|
-
Vue preset added!`)},"addVue"),
|
|
19
|
-
Svelte preset added!`)},"addSvelte"),
|
|
20
|
-
`):e.prepend(`import ${
|
|
21
|
-
`)}const m=await
|
|
22
|
-
`):e.prepend(`import ${
|
|
23
|
-
`));const
|
|
24
|
-
css: {${
|
|
25
|
-
minifier: ${
|
|
26
|
-
loaders: [${
|
|
14
|
+
},`),s.info("Adding typedoc dependencies..."),r.start("Installing packages"),await D(Se,{cwd:n,dev:!0,silent:!0}),r.stop("Installed packages"),s.success(`
|
|
15
|
+
Typedoc added!`)},"addTypedoc"),Be=y(async t=>{const{logger:s,packemConfig:e}=t;if(O(e,"react","createReactPreset")){s.warn("React preset has already been added to the packem config.");return}E(t,"react");const{devPackages:a,packages:o}=await Ie(t.rootDirectory);s.info("Adding React dependencies..."),await T(t,a,o),s.success(`
|
|
16
|
+
React preset added!`)},"addReact"),Ne=y(async t=>{const{logger:s,packemConfig:e}=t;if(O(e,"solid","createSolidPreset")){s.warn("Solid preset has already been added to the packem config.");return}E(t,"solid"),s.info("Adding Solid dependencies..."),await T(t,Ce,xe),s.success(`
|
|
17
|
+
Solid preset added!`)},"addSolid"),Ve=y(async t=>{const{logger:s,packemConfig:e}=t;if(O(e,"vue","createVuePreset")){s.warn("Vue preset has already been added to the packem config.");return}E(t,"vue"),s.info("Adding Vue dependencies..."),await T(t,De,Pe),s.success(`
|
|
18
|
+
Vue preset added!`)},"addVue"),Ae=y(async t=>{const{logger:s,packemConfig:e}=t;if(O(e,"svelte","createSveltePreset")){s.warn("Svelte preset has already been added to the packem config.");return}E(t,"svelte"),s.info("Adding Svelte dependencies..."),await T(t,Me,Oe),s.success(`
|
|
19
|
+
Svelte preset added!`)},"addSvelte"),Fe=y(async t=>{const{logger:s,magic:e,packemConfig:a,packemConfigFormat:o,transformerReplaceKey:n,transformerSearchKey:r}=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=[],d=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(d),d!=="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 v=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"}]});v!=="sass"&&(p=p.filter(c=>c!=="sass"),p.push(v))}i.push(...p)}const l=[];for(const p of i)l.push(...W[p]);d!=="tailwindcss"&&i.push("sourceMap");for(const p of i){const v=p==="sass-embedded"||p==="node-sass"?"sass":p;o==="cjs"?e.prepend(`const ${v}Loader = require("@visulima/packem/css/loader/${v.toLowerCase()}");
|
|
20
|
+
`):e.prepend(`import ${v}Loader from "@visulima/packem/css/loader/${v.toLowerCase()}";
|
|
21
|
+
`)}const m=await b({initialValue:!1,message:"Do you want to minify your css?"});let f;m&&(f=await h({message:"Pick a css minifier",options:[{label:"CSSNano",value:"cssnano"},{label:"Lightning CSS",value:"lightningcss"}]}),i.includes("lightningcss")||l.push(f),o==="cjs"?e.prepend(`const ${f}Minifier = require("@visulima/packem/css/minifier/${f.toLowerCase()}");
|
|
22
|
+
`):e.prepend(`import ${f}Minifier from "@visulima/packem/css/minifier/${f.toLowerCase()}";
|
|
23
|
+
`));const g=i.map(p=>p==="sass-embedded"||p==="node-sass"?"sass":`${p}Loader`).join(", ");a.includes("rollup: {")?e.replace("rollup: {",`rollup: {
|
|
24
|
+
css: {${f?`
|
|
25
|
+
minifier: ${f}Minifier,`:""}
|
|
26
|
+
loaders: [${g}],
|
|
27
27
|
},
|
|
28
|
-
`):e.replace(
|
|
28
|
+
`):e.replace(r,`${n}
|
|
29
29
|
rollup: {
|
|
30
|
-
css: {${
|
|
31
|
-
minifier: ${
|
|
32
|
-
loaders: [${
|
|
30
|
+
css: {${f?`
|
|
31
|
+
minifier: ${f}Minifier,`:""}
|
|
32
|
+
loaders: [${g}],
|
|
33
33
|
},
|
|
34
|
-
},`),t.spinner.start("Installing packages"),await D(
|
|
35
|
-
CSS loaders added!`)},"addCss"),Re=y(t=>{t.addCommand({argument:{description:"Add a packem feature to your project",name:"feature",required:!0},description:"Add a optional packem feature to your project",execute:y(async({argument:s,logger:e,options:a})=>{const o=E(),r=B(L(),a.dir??".");let n;try{n=await z(r,a.config)}catch{e.error("Could not find a packem config file, please run `packem init` first.");return}if(await Me(r)&&!await w({initialValue:!1,message:"Git repository has uncommitted changes. Do you want to proceed?"})){F("Operation cancelled.");return}const i=await te(n,{buffer:!1}),l=i.includes("import")?"esm":"cjs",p=new re(i),m=" transformer,",g=i.includes(" transformer,")?" transformer,":" transformer",c={logger:e,magic:p,packemConfig:i,packemConfigFilePath:n,packemConfigFormat:l,rootDirectory:r,spinner:o,transformerReplaceKey:m,transformerSearchKey:g};s.includes("typedoc")&&await Oe(c),s.includes("react")&&await Ee(c),s.includes("solid")&&await Le(c),s.includes("vue")&&await Be(c),s.includes("svelte")&&await Ne(c),s.includes("css")&&await Ve(c),await ae(n,p.toString(),{overwrite:!0})},"execute"),name:"add",options:[{defaultValue:".",description:"The directory to build",name:"dir",type:String},{description:"Use a custom config file",name:"config",type:String}]})},"createAddCommand");var Ae=Object.defineProperty,qe=h((t,s)=>Ae(t,"name",{value:s,configurable:!0}),"e$2");const Fe=qe(async(t,s,e,a,o)=>{const r=await z(s,o);let n=await t.import(r,{default:!0,try:!0})||{};return typeof n=="function"&&(n=await n(e,a)),{config:n,path:r}},"loadPackemConfig");var Ge=Object.defineProperty,Ue=h((t,s)=>Ge(t,"name",{value:s,configurable:!0}),"e$1");const Je=Ue(async(t,s)=>{switch(t){case"none":return{};case"react":{const{createReactPreset:e}=await import("../config/preset/react.js");t=e();break}case"solid":{const{createSolidPreset:e}=await import("../config/preset/solid.js");t=e();break}case"svelte":{const{createSveltePreset:e}=await import("../config/preset/svelte.js");t=e();break}case"vue":{const{createVuePreset:e}=await import("../config/preset/vue.js");t=e();break}default:typeof t=="string"&&(t=await s.import(t)||{})}return typeof t=="function"&&(t=t()),t},"loadPreset");var ze=Object.defineProperty,C=h((t,s)=>ze(t,"name",{value:s,configurable:!0}),"r");const Ke=C(t=>{t.addCommand({description:"Demonstrate options required",execute:C(async({logger:s,options:e})=>{let a="build";e.watch?a="watch":e.jit&&(a="jit");const o={};let r;if(e.env)for(const c of e.env)c.key==="NODE_ENV"?r=c.value:o[`process.env.${c.key}`]=JSON.stringify(c.value);r===void 0&&(e.production?r=V:e.development&&(r=ce));const n=[];if(e.external)for(const c of e.external)n.push(c.split(","));const i=B(L(),e.dir??"."),l=de(i,{debug:e.debug}),{config:p,path:m}=await Fe(l,i,r,a,e.config??void 0);s.debug("Using packem config found at",m);const g=await Je(p.preset??"none",l);e.minify&&e.sourcemap===void 0&&(e.sourcemap=!0);try{await pe(i,a,r,s,e.debug,le(p,ue,g,{analyze:e.analyze,cjsInterop:e.cjsInterop,clean:e.clean,dtsOnly:e.dtsOnly,externals:n,killSignal:e.killSignal,minify:e.minify===void 0?r===V:e.minify,onSuccess:e.onSuccess,rollup:{esbuild:{target:e.target},license:{path:e.license},metafile:e.metafile,replace:{values:o},resolveExternals:e.noExternal?{builtins:!1,deps:!1,devDeps:!1,optDeps:!1,peerDeps:!1}:{}},runtime:e.runtime,sourcemap:e.metafile||e.analyze||e.sourcemap,unbundle:e.unbundle,validation:e.validation===!1?!1:{},...e.typedoc?{typedoc:{format:"html"}}:{}}),e.tsconfig??void 0)}catch(c){s.error(c),Q(1)}},"execute"),name:"build",options:[{defaultValue:".",description:"The directory to build",name:"dir",type:String},{alias:"t",description:"Environments to support. `target` in tsconfig.json is automatically added. Defaults to the current Node.js version.",name:"target"},{description:"Use a custom config file",name:"config",type:String},{description:"Path to the tsconfig.json file",name:"tsconfig",type:String},{description:"Minify the output",name:"minify",type:Boolean},{description:"Generate sourcemaps (experimental)",name:"sourcemap",type:Boolean},{conflicts:"jit",description:"Watch for changes",name:"watch",type:Boolean},{conflicts:"watch",description:"Stub the package for JIT compilation",name:"jit",type:Boolean},{description:"Compile-time environment variables (eg. --env.NODE_ENV=production)",multiple:!0,name:"env",type:C(s=>{const[e,a]=s.split("=");return{key:e,value:a}},"type")},{defaultValue:!1,description:"Generate meta file (experimental)",name:"metafile",type:Boolean},{description:"Path to the license file",name:"license",type:String},{conflicts:"watch",description:"Visualize and analyze the bundle",name:"analyze",type:Boolean},{description:"CJS interop mode, can export default and named export, (experimental).",name:"cjsInterop",type:Boolean},{conflicts:"development",description:"Run code in production environment",name:"production",type:Boolean},{conflicts:"production",description:"Run code in development environment",name:"development",type:Boolean},{description:"Do not clean the dist directory before building",name:"no-clean",type:Boolean},{description:"Only generate .d.ts files",name:"dts-only",type:Boolean},{description:"Disable the output validation",name:"no-validation",type:Boolean},{description:"Disable the cache",name:"no-cache",type:Boolean},{description:"Generate type documentation",name:"typedoc",type:Boolean},{description:"Execute command after successful build, specially useful for watch mode",name:"onSuccess",type:String},{description:'Signal to kill child process, "SIGTERM" or "SIGKILL"',name:"killSignal",type:C(s=>{if(s==="SIGTERM"||s==="SIGKILL")return s;throw new Error("Invalid kill signal. Use 'SIGTERM' or 'SIGKILL'.")},"type")},{description:"Specify an external dependency, separate by comma (eg. --external lodash,react,react-dom)",multiple:!0,name:"external",typeLabel:"string[]"},{description:"do not bundle external dependencies",name:"no-external",type:Boolean},{description:"Specify the build runtime (nodejs, browser).",name:"runtime",type:C(s=>{if(s==="node"||s==="browser")return s;throw new Error("Invalid runtime. Use 'node' or 'browser'.")},"type")},{description:"Enable unbundle mode to preserve source file structure instead of bundling into a single file",name:"unbundle",type:Boolean}]})},"createBuildCommand");var We=Object.defineProperty,x=h((t,s)=>We(t,"name",{value:s,configurable:!0}),"f");const Xe=x(t=>{t.addCommand({description:"Initialize packem configuration",execute:x(async({logger:s,options:e})=>{if(Z("Welcome to packem setup"),O(S(e.dir,"packem.config.mjs"))){s.info("Packem project already initialized, you can use `packem build` to build your project");return}const a=B(L(),e.dir??"."),o=S(a,"package.json");if(!O(o))throw new Error("No package.json found in the directory");const r=await G(o,{resolveCatalogs:!0}),n=[];r.dependencies&&n.push(...Object.keys(r.dependencies)),r.devDependencies&&n.push(...Object.keys(r.devDependencies));const i=!!(r.devDependencies?.typescript??r.dependencies?.typescript),l=[];if(e.typescript===void 0&&!i?(e.typescript=await w({message:"Do you want to install TypeScript?"}),e.typescript&&l.push("typescript@latest")):N.message(`TypeScript version ${r.devDependencies?.typescript??r.dependencies?.typescript} is already installed`),!O(S(a,"tsconfig.json"))){const d=await w({message:"Do you want to use generate a tsconfig.json?"}),u=await w({message:"Do you want to run your code in the DOM?"});if(d){const k=E();k.start("Generating tsconfig.json"),ie(S(a,"tsconfig.json"),{compilerOptions:{esModuleInterop:!0,skipLibCheck:!0,target:"es2022",allowJs:!0,resolveJsonModule:!0,moduleDetection:"force",isolatedModules:!0,verbatimModuleSyntax:!0,strict:!0,noUncheckedIndexedAccess:!0,noImplicitOverride:!0,module:"NodeNext",outDir:"dist",sourceMap:!0,declaration:!0,lib:u?["es2022","dom","dom.iterable"]:["es2022"]}}),k.stop("")}}if(e.runtime===void 0&&(e.runtime=await v({message:"Pick a build runtime",options:[{label:"Node",value:"node"},{label:"Browser",value:"browser"}]})),n.includes("esbuild")?e.transformer="esbuild":n.includes("@swc/core")?e.transformer="swc":n.includes("sucrase")&&(e.transformer="sucrase"),e.transformer===void 0?(e.transformer=await v({message:"Pick a transformer",options:[{label:"esbuild",value:"esbuild"},{label:"swc",value:"swc"},{label:"Sucrase",value:"sucrase"},{label:"OXC",value:"oxc"}]}),e.transformer&&e.transformer!=="oxc"&&!n.includes(e.transformer)&&await w({message:`Do you want to install ${e.transformer}?`})&&l.push(e.transformer==="swc"?"@swc/core":e.transformer)):N.message(`Transformer ${e.transformer} is already installed.`),e.isolatedDeclarationTransformer===void 0&&(e.isolatedDeclarationTransformer=await w({message:"Do you want to use an isolated declaration types?",initialValue:!1})),e.isolatedDeclarationTransformer===void 0&&(e.isolatedDeclarationTransformer=await v({message:"Pick a isolated declaration transformer",options:[{label:"Typescript",value:"typescript"},{label:"swc",value:"swc"},{label:"OXC",value:"oxc"},{label:"None",value:void 0}]}),e.isolatedDeclarationTransformer!==void 0)){let d;switch(e.isolatedDeclarationTransformer){case"oxc":{d="oxc-transform";break}case"swc":{d="@swc/core";break}case"typescript":{d="typescript";break}default:F("Invalid isolated declaration transformer")}d!==void 0&&!n.includes(d)&&await w({message:`Do you want to install ${d}?`})&&l.push(d)}e.css===void 0&&(e.css=await w({message:"Do you want to use css in your project?",initialValue:!1}));const p=[];if(e.css){const d=await v({message:"Pick a css loader",options:[{label:"PostCSS",value:"postcss"},{hint:"experimental",label:"Lightning CSS",value:"lightningcss"}]});p.push(d);let u=await q({message:"Pick your loaders",options:[{label:"Sass",value:"sass"},{label:"Stylus",value:"stylus"},{label:"Less",value:"less"}],required:!1});if(u.includes("sass")){const k=await v({message:"Pick a sass loader",options:[{label:"Sass embedded",value:"sass-embedded",hint:"recommended"},{label:"Sass",value:"sass"},{label:"Node Sass",value:"node-sass",hint:"legacy"}]});k!=="sass"&&(u=u.filter(W=>W!=="sass"),u.push(k))}if(p.push(...u),await w({message:`Do you want to install "${p.join('", "')}"?`}))for(const k of p)l.push(...K[k]);p.push("sourceMap")}e.cssMinifier===void 0&&(e.cssMinifier=await w({message:"Do you want to minify your css?",initialValue:!1}));let m;e.cssMinifier&&(m=await v({message:"Pick a css minifier",options:[{label:"CSSNano",value:"cssnano"},{label:"Lightning CSS",value:"lightningcss"}]}),p.includes("lightningcss")||await w({message:`Do you want to install "${m}"?`})&&l.push(m));let g="",c="";if(e.isolatedDeclarationTransformer&&(c+=`,
|
|
36
|
-
isolatedDeclarationTransformer`),(e.css||e.cssMinifier)&&(c+=`,
|
|
34
|
+
},`),t.spinner.start("Installing packages"),await D(l,{cwd:t.rootDirectory,dev:!0,silent:!0}),t.spinner.stop("Installed packages"),s.success(`
|
|
35
|
+
CSS loaders added!`)},"addCss"),Re=y(t=>{t.addCommand({argument:{description:"Add a packem feature to your project",name:"feature",required:!0},description:"Add a optional packem feature to your project",execute:y(async({argument:s,logger:e,options:a})=>{const o=L(),n=M(B(),a.dir??".");let r;try{r=await z(n,a.config)}catch{e.error("Could not find a packem config file, please run `packem init` first.");return}if(await Ee(n)&&!await b({initialValue:!1,message:"Git repository has uncommitted changes. Do you want to proceed?"})){J("Operation cancelled.");return}const i=await ie(r,{buffer:!1}),d=i.includes("import")?"esm":"cjs",l=new ce(i),m=" transformer,",f=i.includes(" transformer,")?" transformer,":" transformer",g={logger:e,magic:l,packemConfig:i,packemConfigFilePath:r,packemConfigFormat:d,rootDirectory:n,spinner:o,transformerReplaceKey:m,transformerSearchKey:f};s.includes("typedoc")&&await Le(g),s.includes("react")&&await Be(g),s.includes("solid")&&await Ne(g),s.includes("vue")&&await Ve(g),s.includes("svelte")&&await Ae(g),s.includes("css")&&await Fe(g),await oe(r,l.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 qe=Object.defineProperty,_=w((t,s)=>qe(t,"name",{value:s,configurable:!0}),"l");const Ke=_(async(t,s,e="PACKEM_")=>{const a=M(s,t);if(!N(a))return{};const o={};if(typeof process.loadEnvFile=="function")try{const n=new Set(Object.keys(process.env));process.loadEnvFile(a);for(const[r,i]of Object.entries(process.env))!n.has(r)&&(!e||r.startsWith(e))&&(o[`process.env.${r}`]=JSON.stringify(i));for(const r of Object.keys(process.env))n.has(r)||delete process.env[r]}catch{return R(a,e)}else return R(a,e);return o},"loadEnvFile"),R=_(async(t,s="PACKEM_")=>{const{readFile:e}=await import("node:fs/promises"),a=await e(t,"utf-8"),o={};for(const n of a.split(`
|
|
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)&&(g+=`,
|
|
37
38
|
rollup: {
|
|
38
|
-
css: {`),e.css){const
|
|
39
|
-
loaders: [${
|
|
40
|
-
minifier: ${m}Minifier,`),(e.css||e.cssMinifier)&&(
|
|
39
|
+
css: {`),e.css){const c=l.map(u=>((u==="sass-embedded"||u==="node-sass")&&(u="sass"),`${u}Loader`)).join(", ");g+=`
|
|
40
|
+
loaders: [${c}],`}if(e.cssMinifier&&m&&(g+=`
|
|
41
|
+
minifier: ${m}Minifier,`),(e.css||e.cssMinifier)&&(g+=`
|
|
41
42
|
}
|
|
42
|
-
}`),i||
|
|
43
|
-
`),e.css)for(let u of
|
|
44
|
-
`;e.cssMinifier&&m&&(
|
|
45
|
-
`),
|
|
43
|
+
}`),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 l)(u==="sass-embedded"||u==="node-sass")&&(u="sass"),c+=`import ${u}Loader from "@visulima/packem/css/loader/${u.toLowerCase()}";
|
|
45
|
+
`;e.cssMinifier&&m&&(c+=`import ${m}Minifier from "@visulima/packem/css/minifier/${m.toLowerCase()}";
|
|
46
|
+
`),f=`import { defineConfig } from "@visulima/packem/config";
|
|
46
47
|
import transformer from "@visulima/packem/transformer/${e.transformer}";
|
|
47
|
-
${
|
|
48
|
+
${c}
|
|
48
49
|
export default defineConfig({
|
|
49
50
|
runtime: "${e.runtime}",
|
|
50
|
-
transformer${
|
|
51
|
+
transformer${g}
|
|
51
52
|
});
|
|
52
|
-
`}else{let
|
|
53
|
-
`),e.css)for(let u of
|
|
54
|
-
`;e.cssMinifier&&m&&(
|
|
55
|
-
`),
|
|
53
|
+
`}else{let c="";if(e.isolatedDeclarationTransformer&&(c+=`const isolatedDeclarationTransformer = require("@visulima/packem/dts/isolated/transformer/${e.isolatedDeclarationTransformer}");
|
|
54
|
+
`),e.css)for(let u of l)(u==="sass-embedded"||u==="node-sass")&&(u="sass"),c+=`const ${u}Loader = require("@visulima/packem/css/loader/${u.toLowerCase()}");
|
|
55
|
+
`;e.cssMinifier&&m&&(c+=`const ${m}Minifier = require("@visulima/packem/css/minifier/${m.toLowerCase()}");
|
|
56
|
+
`),f=`const { defineConfig } = require("@visulima/packem/config");
|
|
56
57
|
const transformer = require("@visulima/packem/transformer/${e.transformer}");
|
|
57
|
-
${
|
|
58
|
+
${c}
|
|
58
59
|
module.exports = defineConfig({
|
|
59
60
|
runtime: ${e.runtime},
|
|
60
|
-
transformer${
|
|
61
|
+
transformer${g}
|
|
61
62
|
});
|
|
62
|
-
`}const
|
|
63
|
+
`}const p=L(),v=i?"ts":"js";d.length>0&&(p.start("Installing packages"),await D(d,{cwd:a,dev:!0,silent:!0}),p.stop("Installed packages")),p.start(`Creating packem.config.${v}`),ne(S(a,`packem.config.${v}`),f),p.stop(`Created packem.config.${v}`),te("Now you can run `packem build` to build your project")},"execute"),name:"init",options:[{defaultValue:".",description:"The directory to initialize",name:"dir",type:String},{description:"Choose a transformer",name:"transformer",type:x(s=>{if(typeof s=="string"&&["esbuild","sucrase","swc"].includes(s))return s;throw new Error("Invalid transformer, please choose one of 'swc', 'sucrase' or 'esbuild'")},"type")},{description:"Choose a isolated declaration transformer",name:"isolated-declaration-transformer",type:x(s=>{if(typeof s=="string"&&["none","oxc","swc","typescript"].includes(s))return s;throw new Error("Invalid isolated declaration isolated declaration, please choose one of 'none', 'oxc', 'swc' or 'typescript'")},"type")},{description:"Use CSS",name:"css",type:Boolean},{description:"Use CSS minifier",name:"css-minifier",type:Boolean},{Description:"Use TypeScript",name:"typescript",type:Boolean},{description:"Specify the build runtime (nodejs, browser).",name:"runtime",type:x(s=>{if(s==="node"||s==="browser")return s;throw new Error("Invalid runtime. Use 'node' or 'browser'.")},"type")}]})},"createInitCommand");var Ze=Object.defineProperty,$=w((t,s)=>Ze(t,"name",{value:s,configurable:!0}),"a");const es=$(async({cwd:t,dryRun:s,logger:e})=>{if(s)e.info("Dry run enabled. No changes will be made.");else{const o=ve({input:j.stdin,output:j.stdout});e.warn(`
|
|
63
64
|
|
|
64
65
|
Before proceeding, review the migration guide at https://www.visulima.com/docs/package/packem, as this process will modify your files.
|
|
65
|
-
Uncommitted changes will be lost. Use the --dry-run flag to preview changes without applying them.`);const
|
|
66
|
-
`;return t?(s.info("[dry-run] package.json changes:"),s.info("Old content:"),console.info(e),s.info("New content:"),console.info(
|
|
66
|
+
Uncommitted changes will be lost. Use the --dry-run flag to preview changes without applying them.`);const n=await o.question("Continue? (Y/n) ");if(o.close(),!(n.toLowerCase()==="y"||n==="")){e.error("Migration cancelled."),j.exitCode=1;return}}t&&j.chdir(t);let a=!1;await ts(s,e)&&(a=!0),await is(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"),q={bunchee:"@visulima/packem",tsup:"@visulima/packem","tsup-node":"@visulima/packem",unbuild:"@visulima/packem"},ss={dependencies:`^${F.version}`,devDependencies:`^${F.version}`,peerDependencies:"*"},ts=$(async(t,s)=>{if(!N("package.json"))return s.error("No package.json found"),!1;const e=await ge("package.json","utf8"),a=JSON.parse(e);let o=!1;for(const[i,d]of Object.entries(ss))for(const[l,m]of Object.entries(q))a[i]?.[l]&&(s.info(`Migrating \`${i}\` from ${l} to ${m}.`),o=!0,a[i]=os(a[i],l,m,d));if(a.scripts)for(const i of Object.keys(a.scripts)){for(const[d,l]of Object.entries(q))a.scripts[i].includes(d)&&(s.info(`Migrating \`${i}\` script from ${d} to packem`),o=!0,a.scripts[i]=a.scripts[i].replaceAll(new RegExp(String.raw`\b${d}\b`,"g"),"packem").replaceAll(new RegExp(String.raw`\b${d}-node\b`,"g"),"packem"));a.scripts[i].includes("tsup")&&(s.info(`Migrating \`${i}\` script from tsup to packem`),o=!0,a.scripts[i]=a.scripts[i].replaceAll(/\btsup(?:-node)?/g,"packem build").replaceAll(/\bbuild\b/g,"build")),a.scripts[i].includes("unbuild")&&(s.info(`Migrating \`${i}\` script from unbuild to packem`),o=!0,a.scripts[i]=a.scripts[i].replaceAll(/\bunbuild\b/g,"packem build")),a.scripts[i].includes("bunchee")&&(s.info(`Migrating \`${i}\` script from bunchee to packem`),o=!0,a.scripts[i]=a.scripts[i].replaceAll(/\bbunchee\b/g,"packem build"))}const 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(!o)return s.warn("No migratable bundler dependencies found in package.json"),!1;const r=`${JSON.stringify(a,null,e.includes(" ")?" ":2)}
|
|
67
|
+
`;return t?(s.info("[dry-run] package.json changes:"),s.info("Old content:"),console.info(e),s.info("New content:"),console.info(r)):(await ye("package.json",r),s.success("Migrated `package.json`")),!0},"migratePackageJson"),as=["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"],is=$(async(t,s)=>{let e=!1;for(const a of as)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"),os=$((t,s,e,a)=>{const o={};for(const n of Object.keys(t))n===s?o[e]=a||t[s]:o[n]=t[n];return o},"renameKey"),rs=$(t=>{t.addCommand({description:"Migrate from other bundlers (tsup, unbuild, bunchee, etc.) to packem",execute:$(async({logger:s,options:e})=>{await es({cwd:e.cwd,dryRun:e.dryRun,logger:s})},"execute"),name:"migrate",options:[{defaultValue:".",description:"The directory to migrate",name:"cwd",type:String},{description:"Preview changes without applying them",name:"dry-run",type:Boolean}]})},"createMigrateCommand");try{require("node:module")?.enableCompileCache?.()||require("v8-compile-cache")}catch{}const P=Y("packem",{logger:await Q({reporters:[new Z({error:{hideErrorCauseCodeView:!0,hideErrorCodeView:!0,hideErrorErrorsCodeView:!0}})],scope:"packem"}),packageName:be,packageVersion:U});Qe(P);He(P);Re(P);rs(P);P.run({shouldExitProcess:!1});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var j=Object.defineProperty;var g=(o,e)=>j(o,"name",{value:e,configurable:!0});var O=Object.defineProperty,a=g((o,e)=>O(o,"name",{value:e,configurable:!0}),"a");const N=a(o=>{const e={contextToCustomElements:o?.contextToCustomElements??!0,delegateEvents:o?.delegateEvents??!0,generate:o?.generate??"dom",hydratable:o?.hydratable??!1,moduleName:o?.moduleName??"solid-js/web",wrapConditionals:o?.wrapConditionals??!0};return o?.builtIns!==void 0&&(e.builtIns=o.builtIns),e},"buildSolidPresetOptions"),E=a((o,e,n,l)=>{if(!e||typeof e=="function")return o;let s=n;if(e.plugins){const i=Array.isArray(e.plugins)?e.plugins:[];s=[...n||[],...i]}let r=l;if(e.presets){const i=Array.isArray(e.presets)?e.presets:[];r=[...l||[],...i]}return{...o,...e,plugins:s&&s.length>0?s:void 0,presets:r&&r.length>0?r:void 0}},"mergeUserBabelOptions"),x=a((o={})=>{const{babel:e,plugins:n=[],presets:l=[],solidOptions:s={}}=o,r=[],i=[],m=["babel-preset-solid",N(s)];i.push(m);const u=[...r,...Array.isArray(n)?n:[]],d=[...i,...Array.isArray(l)?l:[]],b={ast:!1,babelrc:!1,configFile:!1,plugins:u.length>0?u:void 0,presets:d.length>0?d:void 0,sourceMaps:!0},f={babel:E(b,e,u,d),resolve:{exportConditions:["solid"]}};return{externals:["solid-js","solid-js/web","solid-js/store"],hooks:{"rollup:options":a((t,h)=>{const c=t.environment==="development"?"development":"production",p=c==="development",{runtime:y}=t.options,v=y==="node";t.options.rollup.replace||(t.options.rollup.replace={preventAssignment:!0,values:{}}),t.options.rollup.replace.values||(t.options.rollup.replace.values={});const S={[["import","meta","env","DEV"].join(".")]:p,[["import","meta","env","NODE_ENV"].join(".")]:JSON.stringify(c),[["import","meta","env","PROD"].join(".")]:!p,[["import","meta","env","SSR"].join(".")]:v,[["process","env","DEV"].join(".")]:JSON.stringify(String(p)),[["process","env","NODE_ENV"].join(".")]:JSON.stringify(c),[["process","env","PROD"].join(".")]:JSON.stringify(String(!p)),[["process","env","SSR"].join(".")]:JSON.stringify(String(v))};Object.assign(t.options.rollup.replace.values,S)},"rollup:options")},rollup:f,validation:{dependencies:{hoisted:{exclude:[]},unused:{exclude:["solid-js"]}}}}},"createSolidPreset");export{x as createSolidPreset};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loads environment variables from a .env file with optional prefix filtering.
|
|
3
|
+
* Uses Node.js built-in `process.loadEnvFile` to load the file, then filters variables by prefix.
|
|
4
|
+
* @param envFilePath Path to the .env file (relative to rootDirectory or absolute)
|
|
5
|
+
* @param rootDirectory Root directory for resolving relative paths
|
|
6
|
+
* @param prefix Optional prefix to filter environment variables (e.g., "PACKEM_")
|
|
7
|
+
* @returns Record of environment variables with keys formatted as "process.env.KEY"
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const envVars = await loadEnvFile(".env", "/path/to/project", "PACKEM_");
|
|
11
|
+
* // Returns: { "process.env.PACKEM_API_URL": "\"https://api.example.com\"" }
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
declare const loadEnvFile: (envFilePath: string, rootDirectory: string, prefix?: string) => Promise<Record<string, string>>;
|
|
15
|
+
export default loadEnvFile;
|
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-fGSICmM6.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,3 +1,12 @@
|
|
|
1
1
|
type Key = number | string | symbol;
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Groups an array of objects by multiple keys, creating nested objects.
|
|
4
|
+
* Supports 2 or 3 keys for grouping.
|
|
5
|
+
* @param array Array of objects to group
|
|
6
|
+
* @param key1 First key to group by
|
|
7
|
+
* @param key2 Second key to group by
|
|
8
|
+
* @param key3 Optional third key to group by
|
|
9
|
+
* @returns Nested object grouped by the specified keys
|
|
10
|
+
*/
|
|
11
|
+
declare const groupByKeys: <T extends Record<Key, unknown>>(array: T[], key1: Key, key2: Key, key3?: Key) => Record<string, Record<string, T[]>> | Record<string, Record<string, Record<string, T[]>>>;
|
|
3
12
|
export default groupByKeys;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{d as s}from"./isolatedDeclarationsOxcTransformer-WbfE6cGu-NeZOx2Y7.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};
|