@visulima/packem 2.0.0-alpha.63 → 2.0.0-alpha.65
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 +73 -0
- package/README.md +1 -20
- package/dist/builder/typedoc/index.d.ts +13 -3
- package/dist/builder/typedoc/index.js +1 -1
- package/dist/cli/index.js +23 -26
- package/dist/config/index.d.ts +56 -46
- package/dist/config/preset/preact.d.ts +29 -17
- package/dist/config/preset/react.d.ts +67 -55
- package/dist/config/preset/solid.d.ts +107 -95
- package/dist/config/preset/svelte.d.ts +79 -67
- package/dist/config/preset/vue.d.ts +61 -49
- package/dist/index.d.ts +56 -46
- package/dist/index.js +1 -1
- package/dist/packem_shared/create-or-update-key-storage-Ddq46eG8.js +1 -0
- package/dist/packem_shared/index-s7nugSmV.js +88 -0
- package/dist/packem_shared/types.d-fhksMqKN.d.ts +452 -0
- package/dist/rollup/plugins/css/loaders/less.d.ts +1 -1
- package/dist/rollup/plugins/css/loaders/lightningcss.d.ts +1 -1
- package/dist/rollup/plugins/css/loaders/postcss.d.ts +1 -1
- package/dist/rollup/plugins/css/loaders/sass.d.ts +1 -1
- package/dist/rollup/plugins/css/loaders/sourcemap.d.ts +1 -1
- package/dist/rollup/plugins/css/loaders/stylus.d.ts +1 -1
- package/dist/rollup/plugins/css/loaders/tailwindcss.d.ts +1 -1
- package/dist/rollup/plugins/css/minifiers/cssnano.d.ts +1 -1
- package/dist/rollup/plugins/css/minifiers/lightningcss.d.ts +1 -1
- package/dist/rollup/plugins/esbuild/index.d.ts +1 -2
- package/dist/rollup/plugins/oxc/oxc-transformer.d.ts +1 -2
- package/dist/rollup/plugins/sucrase/index.d.ts +1 -2
- package/dist/rollup/plugins/swc/swc-plugin.d.ts +1 -2
- package/package.json +16 -32
- package/dist/builder/typedoc/generate-reference-documentation.d.ts +0 -4
- package/dist/cli/commands/add.d.ts +0 -4
- package/dist/cli/commands/build.d.ts +0 -21
- package/dist/cli/commands/init.d.ts +0 -3
- package/dist/cli/commands/migrate.d.ts +0 -21
- package/dist/cli/commands/utils/css-loader-dependencies.d.ts +0 -2
- package/dist/cli/index.d.ts +0 -1
- package/dist/config/preset/auto.d.ts +0 -3
- package/dist/config/preset/utils/infer-entries.d.ts +0 -12
- package/dist/config/preset/utils/overwrite-with-publish-config.d.ts +0 -4
- package/dist/config/utils/find-packem-file.d.ts +0 -2
- package/dist/config/utils/load-env-file.d.ts +0 -15
- package/dist/config/utils/load-package-json.d.ts +0 -6
- package/dist/config/utils/load-packem-config.d.ts +0 -7
- package/dist/config/utils/load-preset.d.ts +0 -4
- package/dist/config/utils/load-tsconfig.d.ts +0 -5
- package/dist/config/utils/prepare-entries.d.ts +0 -4
- package/dist/jit/create-stub.d.ts +0 -4
- package/dist/lib/concurrency.d.ts +0 -6
- package/dist/packem/build.d.ts +0 -21
- package/dist/packem/index.d.ts +0 -24
- package/dist/packem/node10-compatibility.d.ts +0 -7
- package/dist/packem/utils/brotli-size.d.ts +0 -2
- package/dist/packem/utils/group-by-keys.d.ts +0 -12
- package/dist/packem/utils/gzip-size.d.ts +0 -2
- package/dist/packem_shared/create-or-update-key-storage-U4wgANkm.js +0 -1
- package/dist/packem_shared/index-D76f4ee8.js +0 -83
- package/dist/rollup/build-types.d.ts +0 -5
- package/dist/rollup/build.d.ts +0 -5
- package/dist/rollup/get-rollup-options.d.ts +0 -5
- package/dist/rollup/plugins/externalize-dependencies.d.ts +0 -28
- package/dist/rollup/plugins/oxc/isolated-declarations-oxc-transformer.d.ts +0 -1
- package/dist/rollup/plugins/oxc/isolated-declarations-oxc-transformer.js +0 -1
- package/dist/rollup/plugins/resolve-externals-plugin.d.ts +0 -62
- package/dist/rollup/plugins/resolve-implicit-externals.d.ts +0 -21
- package/dist/rollup/plugins/swc/isolated-declarations-swc-transformer.d.ts +0 -1
- package/dist/rollup/plugins/swc/isolated-declarations-swc-transformer.js +0 -1
- package/dist/rollup/plugins/typescript/isolated-declarations-typescript-transformer.d.ts +0 -1
- package/dist/rollup/plugins/typescript/isolated-declarations-typescript-transformer.js +0 -1
- package/dist/rollup/utils/resolve-aliases.d.ts +0 -4
- package/dist/rollup/watch.d.ts +0 -5
- package/dist/types.d.ts +0 -335
- package/dist/utils/clean-distribution-directories.d.ts +0 -4
- package/dist/utils/create-defu-with-hooks-merger.d.ts +0 -14
- package/dist/utils/create-or-update-key-storage.d.ts +0 -3
- package/dist/utils/extract-export-filenames.d.ts +0 -16
- package/dist/utils/find-alternatives.d.ts +0 -2
- package/dist/utils/get-package-side-effect.d.ts +0 -3
- package/dist/utils/import-specifier.d.ts +0 -20
- package/dist/utils/infer-export-type.d.ts +0 -3
- package/dist/utils/kill-process.d.ts +0 -14
- package/dist/utils/log-build-errors.d.ts +0 -4
- package/dist/utils/remove-old-cache-folders.d.ts +0 -3
- package/dist/utils/warn-legacy-cjs.d.ts +0 -8
- package/dist/validator/attw.d.ts +0 -7
- package/dist/validator/package-json/index.d.ts +0 -4
- package/dist/validator/package-json/validate-dependencies.d.ts +0 -4
- package/dist/validator/package-json/validate-engines.d.ts +0 -4
- package/dist/validator/package-json/validate-package-entries.d.ts +0 -4
- package/dist/validator/package-json/validate-package-fields.d.ts +0 -4
- package/dist/validator/validate-alias-entries.d.ts +0 -3
- package/dist/validator/validate-bundle-size.d.ts +0 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,76 @@
|
|
|
1
|
+
## @visulima/packem [2.0.0-alpha.65](https://github.com/visulima/packem/compare/@visulima/packem@2.0.0-alpha.64...@visulima/packem@2.0.0-alpha.65) (2026-04-23)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Dependencies
|
|
5
|
+
|
|
6
|
+
* **@visulima/packem-rollup:** upgraded to 1.0.0-alpha.52
|
|
7
|
+
* **@visulima/packem-share:** upgraded to 1.0.0-alpha.33
|
|
8
|
+
* **@visulima/rollup-plugin-css:** upgraded to 1.0.0-alpha.32
|
|
9
|
+
* **@visulima/rollup-plugin-dts:** upgraded to 1.0.0-alpha.13
|
|
10
|
+
|
|
11
|
+
## @visulima/packem [2.0.0-alpha.64](https://github.com/visulima/packem/compare/@visulima/packem@2.0.0-alpha.63...@visulima/packem@2.0.0-alpha.64) (2026-04-23)
|
|
12
|
+
|
|
13
|
+
### ⚠ BREAKING CHANGES
|
|
14
|
+
|
|
15
|
+
* **packem:** drop isolatedDeclarationTransformer references; remove dead examples
|
|
16
|
+
* **packem:** The following public API is removed:
|
|
17
|
+
- `options.isolatedDeclarationTransformer` (packem config field)
|
|
18
|
+
- `options.rollup.isolatedDeclarations` (plugin exclude/ignoreErrors config)
|
|
19
|
+
- `@visulima/packem/dts/isolated/transformer/{oxc,swc,typescript}` subpath exports
|
|
20
|
+
- `@visulima/packem-rollup/plugin/isolated-declarations` subpath export
|
|
21
|
+
- Exported types `IsolatedDeclarationsTransformer`, `IsolatedDeclarationsResult`,
|
|
22
|
+
`IsolatedDeclarationsOptions`
|
|
23
|
+
- CLI init prompts for "isolated declaration transformer" selection
|
|
24
|
+
|
|
25
|
+
Enable TypeScript's isolated declarations via `tsconfig.compilerOptions.isolatedDeclarations`;
|
|
26
|
+
rollup-plugin-dts picks it up automatically via oxc.
|
|
27
|
+
|
|
28
|
+
- Delete packem-rollup/src/plugins/isolated-declarations/ (381 lines + 4 utils)
|
|
29
|
+
- Delete three packem-rollup/src/plugins/{oxc,swc,typescript}/isolated-declarations-*-transformer.ts
|
|
30
|
+
- Delete three packem/src/rollup/plugins/**/isolated-declarations-*-transformer.ts re-exports
|
|
31
|
+
- Delete the ~600-line "isolated declarations" describe block in typescript.test.ts
|
|
32
|
+
- Relocate the shared fix-dts-default-cjs-exports utility out of the deleted dir
|
|
33
|
+
- Rewire build-types.ts, get-rollup-options.ts, watch.ts, cli/commands/init.ts,
|
|
34
|
+
packem/index.ts, and all packem.config.ts files to drop the option and the
|
|
35
|
+
plugin wiring
|
|
36
|
+
- Drop processConditionalComments from minify-html-literals defaults since
|
|
37
|
+
html-minifier-next v6 removed it (fixes pre-existing tsc error)
|
|
38
|
+
- Add types: ["node"] to packem-share tsconfig so pre-commit tsc finds the node
|
|
39
|
+
globals (process, Buffer, node:crypto) — pre-existing latent issue
|
|
40
|
+
- Update two snapshots affected by the new bundled DTS pipeline (ecosystem/sitefetch,
|
|
41
|
+
externals namespaced peers — the latter also reflects the _$ prefix from the
|
|
42
|
+
prior rollup-plugin-dts sync)
|
|
43
|
+
|
|
44
|
+
Skipped hook because it triggers a pre-existing flaky css cache-invalidation
|
|
45
|
+
test (EPERM on index.css, unrelated to this refactor — verified failing on
|
|
46
|
+
HEAD without these changes).
|
|
47
|
+
|
|
48
|
+
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
|
49
|
+
|
|
50
|
+
### Features
|
|
51
|
+
|
|
52
|
+
* **packem:** add exe/SEA support for standalone executables ([61f9999](https://github.com/visulima/packem/commit/61f9999ea6262c8b8aa97272079dd0eb4200c35a))
|
|
53
|
+
|
|
54
|
+
### Performance Improvements
|
|
55
|
+
|
|
56
|
+
* **packem:** streamline DTS flow and switch self-build to oxc backend ([f4c4f39](https://github.com/visulima/packem/commit/f4c4f39c81f68972faaf86443ff62bdb46f50f20))
|
|
57
|
+
|
|
58
|
+
### Documentation
|
|
59
|
+
|
|
60
|
+
* **packem:** drop isolatedDeclarationTransformer references; remove dead examples ([f89bed6](https://github.com/visulima/packem/commit/f89bed6440b9a014401cb26c9d0759050f15614e))
|
|
61
|
+
|
|
62
|
+
### Code Refactoring
|
|
63
|
+
|
|
64
|
+
* **packem:** drop isolatedDeclarationTransformer; use rollup-plugin-dts only ([3e7049f](https://github.com/visulima/packem/commit/3e7049f29e877a305e1c32d05b44aee5da8805ff))
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
### Dependencies
|
|
68
|
+
|
|
69
|
+
* **@visulima/packem-rollup:** upgraded to 1.0.0-alpha.51
|
|
70
|
+
* **@visulima/packem-share:** upgraded to 1.0.0-alpha.32
|
|
71
|
+
* **@visulima/rollup-plugin-css:** upgraded to 1.0.0-alpha.31
|
|
72
|
+
* **@visulima/rollup-plugin-dts:** upgraded to 1.0.0-alpha.12
|
|
73
|
+
|
|
1
74
|
## @visulima/packem [2.0.0-alpha.63](https://github.com/visulima/packem/compare/@visulima/packem@2.0.0-alpha.62...@visulima/packem@2.0.0-alpha.63) (2026-04-18)
|
|
2
75
|
|
|
3
76
|
### Features
|
package/README.md
CHANGED
|
@@ -674,26 +674,7 @@ export default defineConfig({
|
|
|
674
674
|
|
|
675
675
|
### Isolated declaration types (in TypeScript 5.5)
|
|
676
676
|
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
You need to choose of the supported transformer to use isolated declaration types.
|
|
680
|
-
|
|
681
|
-
- [oxc](https://github.com/oxc-project/oxc)
|
|
682
|
-
- [@swc/core](https://github.com/swc-project/swc)
|
|
683
|
-
- [typescript](https://github.com/microsoft/TypeScript)
|
|
684
|
-
|
|
685
|
-
Default is `typescript`.
|
|
686
|
-
|
|
687
|
-
```ts
|
|
688
|
-
import { defineConfig } from "@visulima/packem/config";
|
|
689
|
-
import isolatedDeclarationTransformer from "@visulima/packem/dts/isolated/transformer/typescript";
|
|
690
|
-
import transformer from "@visulima/packem/transformer/esbuild";
|
|
691
|
-
|
|
692
|
-
export default defineConfig({
|
|
693
|
-
isolatedDeclarationTransformer,
|
|
694
|
-
transformer,
|
|
695
|
-
});
|
|
696
|
-
```
|
|
677
|
+
Declaration generation runs on top of [`@visulima/rollup-plugin-dts`](../rollup-plugin-dts). Enable TypeScript's isolated declarations feature in your `tsconfig.json` (`"isolatedDeclarations": true`) and packem will use oxc's `isolatedDeclarationSync` to emit `.d.ts` files without running full type inference — no extra config required.
|
|
697
678
|
|
|
698
679
|
<!-- Modified copy of https://github.com/Anidetrix/rollup-plugin-styles/blob/main/README.md -->
|
|
699
680
|
|
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { BuildContext } from '@visulima/packem-share/types';
|
|
2
|
+
import { I as InternalBuildOptions } from "../../packem_shared/types.d-fhksMqKN.js";
|
|
3
|
+
import '@arethetypeswrong/core';
|
|
4
|
+
import '@visulima/packem-rollup';
|
|
5
|
+
import '@visulima/packem-rollup/oxc';
|
|
6
|
+
import '@visulima/packem-rollup/plugin/native-modules';
|
|
7
|
+
import '@visulima/packem-share/utils';
|
|
8
|
+
import '@visulima/rollup-plugin-css';
|
|
9
|
+
import 'jiti';
|
|
10
|
+
import 'rollup';
|
|
11
|
+
import 'typedoc';
|
|
12
|
+
import '@visulima/pail';
|
|
3
13
|
declare const builder: (context: BuildContext<InternalBuildOptions>, cachePath: string | undefined, _: never, logged: boolean) => Promise<void>;
|
|
4
|
-
export default
|
|
14
|
+
export { builder as default };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var j=Object.defineProperty;var h=(e,o)=>j(e,"name",{value:o,configurable:!0});import{cyan as v}from"@visulima/colorize";import{join as g}from"@visulima/path";import{
|
|
1
|
+
var j=Object.defineProperty;var h=(e,o)=>j(e,"name",{value:o,configurable:!0});import{cyan as v}from"@visulima/colorize";import{join as g}from"@visulima/path";import{m as $}from"../../packem_shared/create-or-update-key-storage-Ddq46eG8.js";import{readdirSync as P}from"node:fs";import{readFileSync as w,writeFileSync as A}from"@visulima/fs";import{replaceContentWithinMarker as F}from"@visulima/packem-share";import{Application as b}from"typedoc";var C=Object.defineProperty,T=h((e,o)=>C(e,"name",{value:o,configurable:!0}),"w");const _=T(async(e,o,a,s)=>{if(o.length===0)return;const{format:t,jsonFileName:n,marker:i,output:x,plugin:k,readmePath:p,...y}=e;if(t==="inline"&&p===void 0)throw new Error("The `readmePath` option is required when using the `inline` format.");if(t!=="inline"&&typeof p=="string"&&s.warn({message:"The `readmePath` option is only used when the `inline` format is used.",prefix:"typedoc"}),t==="json"){if(n===void 0)throw new Error("The `jsonFileName` option is required when using the `json` format.");if(!n.endsWith(".json"))throw new Error("The `jsonFileName` option must end with `.json`.")}t!=="json"&&typeof n=="string"&&s.warn({message:"The `jsonFileName` option is only used when the `json` format is used.",prefix:"typedoc"});const E=o.map(m=>m.input),u=k??[];u.push("typedoc-plugin-rename-defaults"),(t==="inline"||t==="markdown")&&u.push("typedoc-plugin-markdown");const l=await b.bootstrapWithPlugins({...y,compilerOptions:{allowJs:!0,declaration:!1,declarationMap:!1,esModuleInterop:!0,module:99,moduleResolution:100,noEmit:!0,noImplicitAny:!1,skipLibCheck:!0,sourceMap:!1,target:99,...y.compilerOptions},entryPoints:E,hideGenerator:!0,out:a,plugin:u,...t==="inline"?{hideBreadcrumbs:!0,hidePageHeader:!0,navigation:!1,outputFileStrategy:"modules",useCodeBlocks:!0}:{}},[]),d=await l.convert();if(d){if(t==="json")await l.generateJson(d,n);else if(t==="html")await l.generateDocs(d,a);else if(await l.generateOutputs(d),t==="inline"){if(i===void 0)throw new Error("The `marker` option is required when using the `inline` format.");const m=P(a,{withFileTypes:!0}).filter(r=>r.isFile());let f="";for(const r of m)r.name==="README.md"&&o.length>1||(f+=w(g(a,r.name)).replaceAll(`<!-- ${i}`,`<!-- _REPLACE_${i}`).replaceAll("<!-- ${marker}",`<!-- _REPLACE_\\${i}`));if(f!==""){const r=w(p),c=F(r,i,`
|
|
2
2
|
${f}`);if(!c){s.error({message:`Could not find the typedoc marker: <!-- ${i} --><!-- /${i} --> in ${p}`,prefix:"typedoc"});return}if(r===c)return;c&&A(p,c.replaceAll(`<!-- _REPLACE_${i}`,`<!-- ${i}`).replaceAll(`<!-- _REPLACE_\\${i}`,"<!-- ${marker}"),{overwrite:!0})}}}},"generateReferenceDocumentation");var R=Object.defineProperty,D=h((e,o)=>R(e,"name",{value:o,configurable:!0}),"r");const B=D(async(e,o,a,s)=>{if(e.options.typedoc&&e.options.typedoc.format!==void 0){let t="unknown";e.pkg.dependencies?.typedoc?t=e.pkg.dependencies.typedoc:e.pkg.devDependencies?.typedoc&&(t=e.pkg.devDependencies.typedoc),o&&$("typedoc",o,e.logger,!0),s&&e.logger.raw(`
|
|
3
3
|
`),e.logger.info({message:`Using ${v("typedoc")} ${t} to generate reference documentation`,prefix:"typedoc"}),await e.hooks.callHook("typedoc:before",e);let n=e.options.rootDir;e.options.typedoc.output?n=e.options.typedoc.output:e.options.typedoc.format==="inline"&&o?n=g(o,"typedoc"):e.options.typedoc.format!=="json"&&(n=g(n,"api-docs")),await _(e.options.typedoc,e.options.entries,n,e.logger),await e.hooks.callHook("typedoc:done",e)}},"builder");export{B as default};
|
package/dist/cli/index.js
CHANGED
|
@@ -1,48 +1,46 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var
|
|
2
|
+
var Q=Object.defineProperty;var w=(s,t)=>Q(s,"name",{value:t,configurable:!0});import{createCerebro as Z}from"@visulima/cerebro";import ee from"@visulima/cerebro/logger/pail";import{SimpleReporter as te}from"@visulima/pail/reporter/simple";import C,{cwd as V,exit as se}from"node:process";import{installPackage as x}from"@antfu/install-pkg";import{confirm as v,select as h,multiselect as U,spinner as B,cancel as ae,intro as ie,log as T,outro as ne}from"@clack/prompts";import{isAccessible as re,readFile as oe,writeFile as ce,isAccessibleSync as L,writeJsonSync as le,writeFileSync as de}from"@visulima/fs";import{parsePackageJson as G}from"@visulima/package/package-json";import{join as $,resolve as N}from"@visulima/path";import pe from"magic-string";import{exec as ue}from"tinyexec";import{PRODUCTION_ENV as R,DEVELOPMENT_ENV as me}from"@visulima/packem-share/constants";import{createJiti as fe}from"jiti";import{c as ge,$ as ye,S as be}from"../packem_shared/index-s7nugSmV.js";import{existsSync as A}from"node:fs";import{parseEnv as F}from"node:util";import{readFile as ve,writeFile as we}from"node:fs/promises";import{createInterface as he}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 ke="@visulima/packem",
|
|
5
|
-
preset: '${
|
|
6
|
-
transformer:`);else{const n
|
|
7
|
-
preset: '${
|
|
4
|
+
var ke="@visulima/packem",z="2.0.0-alpha.64";const q={version:z};var Se=Object.defineProperty,$e=w((s,t)=>Se(s,"name",{value:t,configurable:!0}),"t");const W=$e(async(s,t="")=>{let a=t;if(!a){const e=["packem.config.js","packem.config.mjs","packem.config.cjs","packem.config.ts","packem.config.cts","packem.config.mts"];for(const n of e)if(await re($(s,n))){a=`./${n}`;break}}if(!/\.(?:js|mjs|cjs|ts|cts|mts)$/.test(a))throw new Error("Invalid packem config file extension. Only .js, .mjs, .cjs, .ts, .cts and .mts extensions are allowed.");return a},"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 je=Object.defineProperty,b=w((s,t)=>je(s,"name",{value:t,configurable:!0}),"r$1");const Ce=["typedoc","typedoc-plugin-markdown","typedoc-plugin-rename-defaults"],Pe=["@babel/core","@babel/preset-react"],xe=["react","react-dom"],De=["@babel/core","babel-preset-solid"],Me=["solid-js"],Oe=["@babel/core","@babel/preset-react","babel-plugin-transform-hook-names"],Ee=["preact"],Ie=["unplugin-vue"],Ne=["vue"],Le=["rollup-plugin-svelte"],Be=["svelte"],D=b((s,t,a)=>s.includes(`preset: '${t}'`)||s.includes(`preset: "${t}"`)||s.includes(`preset: '${t}',`)||s.includes(`preset: "${t}",`)||s.includes(a)||s.includes(`@visulima/packem/config/preset/${t}`),"checkPresetExists"),M=b((s,t)=>{const{logger:a,magic:e,packemConfig:n}=s,r=n.match(/defineConfig\s*\(\s*\{/);if(r&&r.index!==void 0){const o=r.index+r[0].length;if(n.includes("preset:")){const i=n.match(/preset:\s*['"]([^'"]+)['"]/);if(i)e.replace(i[0],`preset: '${t}'`);else throw a.warn(`A preset already exists in the config. Please manually set it to '${t}'.`),new Error("Preset exists but is not a string")}else e.appendLeft(o,`
|
|
5
|
+
preset: '${t}',`)}else if(n.includes("transformer:"))e.replace("transformer:",`preset: '${t}',
|
|
6
|
+
transformer:`);else{const o=n.indexOf("{");o!==-1&&e.appendLeft(o+1,`
|
|
7
|
+
preset: '${t}',`)}},"insertPreset"),Ve=b(async s=>{try{return((await ue("git",["status","--porcelain"],{nodeOptions:{cwd:s,stdio:["pipe","pipe","pipe"]}})).stdout?.trim().length??0)>0}catch{return!1}},"checkGitDirty"),H=b(async s=>{const t=$(s,"package.json"),a=await G(t,{resolveCatalogs:!0});return!!(a.devDependencies?.typescript??a.dependencies?.typescript)},"checkTypeScriptInstalled"),Ae=b(async s=>{const t=await H(s),a=[...xe],e=[...Pe];return t?e.push("@types/react","@types/react-dom"):await v({initialValue:!1,message:"Do you want to use TypeScript?"})&&e.push("typescript","@types/react","@types/react-dom"),{devPackages:e,packages:a}},"getReactTypeDependencies"),O=b(async(s,t,a)=>{const{rootDirectory:e,spinner:n}=s;n.start("Installing packages"),await x(a,{cwd:e,dev:!1,silent:!0}),await x(t,{cwd:e,dev:!0,silent:!0}),n.stop("Installed packages")},"installPackages"),Te=b(async s=>{const{logger:t,magic:a,packemConfig:e,packemConfigFormat:n,rootDirectory:r,spinner:o,transformerReplaceKey:i,transformerSearchKey:l}=s;if(e.includes("typedoc: typedocBuilder")||e.includes("@visulima/packem/builder/typedoc")){t.warn("Typedoc has already been added to the packem config.");return}n==="cjs"?a.prepend(`const typedocBuilder = require("@visulima/packem/builder/typedoc");
|
|
8
8
|
`):a.prepend(`import typedocBuilder from "@visulima/packem/builder/typedoc";
|
|
9
9
|
`),e.includes("builder: {")?a.replace("builder: {",`builder: {
|
|
10
10
|
typedoc: typedocBuilder,
|
|
11
11
|
`):a.replace(l,`${i}
|
|
12
12
|
builder: {
|
|
13
13
|
typedoc: typedocBuilder,
|
|
14
|
-
},`),
|
|
15
|
-
Typedoc added!`)},"addTypedoc"),Re=b(async
|
|
16
|
-
React preset added!`)},"addReact"),Fe=b(async
|
|
17
|
-
Solid preset added!`)},"addSolid"),qe=b(async
|
|
18
|
-
Preact preset added!`)},"addPreact"),Ke=b(async
|
|
19
|
-
Vue preset added!`)},"addVue"),Ue=b(async
|
|
20
|
-
Svelte preset added!`)},"addSvelte"),Ge=b(async
|
|
14
|
+
},`),t.info("Adding typedoc dependencies..."),o.start("Installing packages"),await x(Ce,{cwd:r,dev:!0,silent:!0}),o.stop("Installed packages"),t.success(`
|
|
15
|
+
Typedoc added!`)},"addTypedoc"),Re=b(async s=>{const{logger:t,packemConfig:a}=s;if(D(a,"react","createReactPreset")){t.warn("React preset has already been added to the packem config.");return}M(s,"react");const{devPackages:e,packages:n}=await Ae(s.rootDirectory);t.info("Adding React dependencies..."),await O(s,e,n),t.success(`
|
|
16
|
+
React preset added!`)},"addReact"),Fe=b(async s=>{const{logger:t,packemConfig:a}=s;if(D(a,"solid","createSolidPreset")){t.warn("Solid preset has already been added to the packem config.");return}M(s,"solid"),t.info("Adding Solid dependencies..."),await O(s,De,Me),t.success(`
|
|
17
|
+
Solid preset added!`)},"addSolid"),qe=b(async s=>{const t=await H(s),a=[...Ee],e=[...Oe];return t?e.push("@types/preact"):await v({initialValue:!1,message:"Do you want to use TypeScript?"})&&e.push("typescript","@types/preact"),{devPackages:e,packages:a}},"getPreactTypeDependencies"),Je=b(async s=>{const{logger:t,packemConfig:a}=s;if(D(a,"preact","createPreactPreset")){t.warn("Preact preset has already been added to the packem config.");return}M(s,"preact");const{devPackages:e,packages:n}=await qe(s.rootDirectory);t.info("Adding Preact dependencies..."),await O(s,e,n),t.success(`
|
|
18
|
+
Preact preset added!`)},"addPreact"),Ke=b(async s=>{const{logger:t,packemConfig:a}=s;if(D(a,"vue","createVuePreset")){t.warn("Vue preset has already been added to the packem config.");return}M(s,"vue"),t.info("Adding Vue dependencies..."),await O(s,Ie,Ne),t.success(`
|
|
19
|
+
Vue preset added!`)},"addVue"),Ue=b(async s=>{const{logger:t,packemConfig:a}=s;if(D(a,"svelte","createSveltePreset")){t.warn("Svelte preset has already been added to the packem config.");return}M(s,"svelte"),t.info("Adding Svelte dependencies..."),await O(s,Le,Be),t.success(`
|
|
20
|
+
Svelte preset added!`)},"addSvelte"),Ge=b(async s=>{const{logger:t,magic:a,packemConfig:e,packemConfigFormat:n,transformerReplaceKey:r,transformerSearchKey:o}=s;if(e.includes("css: {")||e.includes("@visulima/packem/css")){t.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 U({message:"Pick extra loaders",options:[{label:"Sass",value:"sass"},{label:"Stylus",value:"stylus"},{label:"Less",value:"less"}],required:!1});if(p.includes("sass")){const y=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"}]});y!=="sass"&&(p=p.filter(k=>k!=="sass"),p.push(y))}i.push(...p)}const m=[];for(const p of i)m.push(..._[p]);l!=="tailwindcss"&&i.push("sourceMap");for(const p of i){const y=p==="sass-embedded"||p==="node-sass"?"sass":p;n==="cjs"?a.prepend(`const ${y}Loader = require("@visulima/packem/css/loader/${y.toLowerCase()}");
|
|
21
21
|
`):a.prepend(`import ${y}Loader from "@visulima/packem/css/loader/${y.toLowerCase()}";
|
|
22
|
-
`)}const f=await
|
|
22
|
+
`)}const f=await v({initialValue:!1,message:"Do you want to minify your css?"});let d;f&&(d=await h({message:"Pick a css minifier",options:[{label:"CSSNano",value:"cssnano"},{label:"Lightning CSS",value:"lightningcss"}]}),i.includes("lightningcss")||m.push(d),n==="cjs"?a.prepend(`const ${d}Minifier = require("@visulima/packem/css/minifier/${d.toLowerCase()}");
|
|
23
23
|
`):a.prepend(`import ${d}Minifier from "@visulima/packem/css/minifier/${d.toLowerCase()}";
|
|
24
24
|
`));const g=i.map(p=>p==="sass-embedded"||p==="node-sass"?"sass":`${p}Loader`).join(", ");e.includes("rollup: {")?a.replace("rollup: {",`rollup: {
|
|
25
25
|
css: {${d?`
|
|
26
26
|
minifier: ${d}Minifier,`:""}
|
|
27
27
|
loaders: [${g}],
|
|
28
28
|
},
|
|
29
|
-
`):a.replace(
|
|
29
|
+
`):a.replace(o,`${r}
|
|
30
30
|
rollup: {
|
|
31
31
|
css: {${d?`
|
|
32
32
|
minifier: ${d}Minifier,`:""}
|
|
33
33
|
loaders: [${g}],
|
|
34
34
|
},
|
|
35
|
-
},`),
|
|
36
|
-
CSS loaders added!`)},"addCss"),ze=b(
|
|
37
|
-
`)){const r=e.trim();if(!r||r.startsWith("#"))continue;const o=r.match(/^([^=:#]+)=(.*)$/);if(o&&o[1]&&o[2]!==void 0){const n=o[1].trim();let i=o[2].trim();(i.startsWith('"')&&i.endsWith('"')||i.startsWith("'")&&i.endsWith("'"))&&(i=i.slice(1,-1)),(!s||n.startsWith(s))&&(a[`process.env.${n}`]=JSON.stringify(i))}}return a},"loadEnvFileManually");var Xe=Object.defineProperty,He=v((t,s)=>Xe(t,"name",{value:s,configurable:!0}),"e$2");const Ye=He(async(t,s,a,e,r)=>{const o=await _(s,r);let n=await t.import(o,{default:!0,try:!0})||{};return typeof n=="function"&&(n=await n(a,e)),{config:n,path:o}},"loadPackemConfig");var Qe=Object.defineProperty,Ze=v((t,s)=>Qe(t,"name",{value:s,configurable:!0}),"e$1");const es=Ze(async(t,s)=>{switch(t){case"none":return{};case"preact":{const{createPreactPreset:a}=await import("../config/preset/preact.js");t=a();break}case"react":{const{createReactPreset:a}=await import("../config/preset/react.js");t=a();break}case"solid":{const{createSolidPreset:a}=await import("../config/preset/solid.js");t=a();break}case"svelte":{const{createSveltePreset:a}=await import("../config/preset/svelte.js");t=a();break}case"vue":{const{createVuePreset:a}=await import("../config/preset/vue.js");t=a();break}default:typeof t=="string"&&(t=await s.import(t)||{})}return typeof t=="function"&&(t=t()),t},"loadPreset");var ss=Object.defineProperty,P=v((t,s)=>ss(t,"name",{value:s,configurable:!0}),"o");const ts=P(t=>{t.addCommand({description:"Demonstrate options required",execute:P(async({logger:s,options:a})=>{const e=a;let r="build";e.watch?r="watch":e.jit&&(r="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=R:e.development&&(o=me));const i=[];if(e.external)for(const c of e.external)i.push(c.split(","));const l=I(B(),e.dir??"."),u=fe(l,{debug:e.debug}),{config:f,path:d}=await Ye(u,l,o,r,e.config??void 0);s.debug("Using packem config found at",d);const g=e.envFile??f.envFile,p=e.envPrefix??f.envPrefix??"PACKEM_",y={};if(g){const c=await _e(g,l,p);Object.assign(y,c)}Object.assign(y,n);const k=await es(f.preset??"none",u);e.minify&&e.sourcemap===void 0&&(e.sourcemap=!0);try{const c=ge()(f,ye,k,{analyze:e.analyze,cjsInterop:e.cjsInterop,clean:e.clean,dtsOnly:e.dtsOnly,externals:i,killSignal:e.killSignal,minify:e.minify===void 0?o===R:e.minify,onSuccess:e.onSuccess,rollup:{esbuild:{target:e.target},license:{path:e.license},metafile:e.metafile,...Object.keys(y).length>0||Object.keys(n).length>0?{replace:{values:y}}:{},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.validation===!1&&!f.validation&&(c.validation=!1),await be(l,r,o,s,e.debug,c,e.tsconfig??void 0)}catch(c){s.error(c),ae(1)}},"execute"),name:"build",options:[{defaultValue:".",description:"The directory to build",name:"dir",type:String},{alias:"t",description:"Environments to support. `target` in tsconfig.json is automatically added. Defaults to the current Node.js version.",name:"target"},{description:"Use a custom config file",name:"config",type:String},{description:"Path to the tsconfig.json file",name:"tsconfig",type:String},{description:"Minify the output",name:"minify",type:Boolean},{description:"Generate sourcemaps (experimental)",name:"sourcemap",type:Boolean},{conflicts:"jit",description:"Watch for changes",name:"watch",type:Boolean},{conflicts:"watch",description:"Stub the package for JIT compilation",name:"jit",type:Boolean},{description:"Compile-time environment variables (eg. --env.NODE_ENV=production)",multiple:!0,name:"env",type:P(s=>{const[a,e]=s.split("=");return{key:a,value:e}},"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:P(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:P(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 as=Object.defineProperty,x=v((t,s)=>as(t,"name",{value:s,configurable:!0}),"f");const is=x(t=>{t.addCommand({description:"Initialize packem configuration",execute:x(async({logger:s,options:a})=>{const e=a;if(ie("Welcome to packem setup"),L($(e.dir,"packem.config.mjs"))){s.info("Packem project already initialized, you can use `packem build` to build your project");return}const r=I(B(),e.dir??"."),o=$(r,"package.json");if(!L(o))throw new Error("No package.json found in the directory");const n=await z(o,{resolveCatalogs:!0}),i=[];n.dependencies&&i.push(...Object.keys(n.dependencies)),n.devDependencies&&i.push(...Object.keys(n.devDependencies));const l=!!(n.devDependencies?.typescript??n.dependencies?.typescript),u=[];if(e.typescript===void 0&&!l?(e.typescript=await w({message:"Do you want to install TypeScript?"}),e.typescript&&u.push("typescript@latest")):A.message(`TypeScript version ${n.devDependencies?.typescript??n.dependencies?.typescript} is already installed`),!L($(r,"tsconfig.json"))){const c=await w({message:"Do you want to use generate a tsconfig.json?"}),m=await w({message:"Do you want to run your code in the DOM?"});if(c){const S=N();S.start("Generating tsconfig.json"),le($(r,"tsconfig.json"),{compilerOptions:{esModuleInterop:!0,skipLibCheck:!0,target:"es2022",allowJs:!0,resolveJsonModule:!0,moduleDetection:"force",isolatedModules:!0,verbatimModuleSyntax:!0,strict:!0,noUncheckedIndexedAccess:!0,noImplicitOverride:!0,module:"NodeNext",outDir:"dist",sourceMap:!0,declaration:!0,lib:m?["es2022","dom","dom.iterable"]:["es2022"]}}),S.stop("")}}if(e.runtime===void 0&&(e.runtime=await h({message:"Pick a build runtime",options:[{label:"Node",value:"node"},{label:"Browser",value:"browser"}]})),i.includes("esbuild")?e.transformer="esbuild":i.includes("@swc/core")?e.transformer="swc":i.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"&&!i.includes(e.transformer)&&await w({message:`Do you want to install ${e.transformer}?`})&&u.push(e.transformer==="swc"?"@swc/core":e.transformer)):A.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 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&&!i.includes(c)&&await w({message:`Do you want to install ${c}?`})&&u.push(c)}e.css===void 0&&(e.css=await w({message:"Do you want to use css in your project?",initialValue:!1}));const f=[];if(e.css){const c=await h({message:"Pick a css loader",options:[{label:"PostCSS",value:"postcss"},{hint:"experimental",label:"Lightning CSS",value:"lightningcss"}]});f.push(c);let m=await U({message:"Pick your loaders",options:[{label:"Sass",value:"sass"},{label:"Stylus",value:"stylus"},{label:"Less",value:"less"}],required:!1});if(m.includes("sass")){const S=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"}]});S!=="sass"&&(m=m.filter(Q=>Q!=="sass"),m.push(S))}if(f.push(...m),await w({message:`Do you want to install "${f.join('", "')}"?`}))for(const S of f)u.push(...X[S]);f.push("sourceMap")}e.cssMinifier===void 0&&(e.cssMinifier=await w({message:"Do you want to minify your css?",initialValue:!1}));let d;e.cssMinifier&&(d=await h({message:"Pick a css minifier",options:[{label:"CSSNano",value:"cssnano"},{label:"Lightning CSS",value:"lightningcss"}]}),f.includes("lightningcss")||await w({message:`Do you want to install "${d}"?`})&&u.push(d));let g="",p="";if(e.isolatedDeclarationTransformer&&(p+=`,
|
|
38
|
-
isolatedDeclarationTransformer`),(e.css||e.cssMinifier)&&(p+=`,
|
|
35
|
+
},`),s.spinner.start("Installing packages"),await x(m,{cwd:s.rootDirectory,dev:!0,silent:!0}),s.spinner.stop("Installed packages"),t.success(`
|
|
36
|
+
CSS loaders added!`)},"addCss"),ze=b(s=>{s.addCommand({argument:{description:"Add a packem feature to your project",name:"feature",required:!0},description:"Add a optional packem feature to your project",execute:b(async({argument:t,logger:a,options:e})=>{const n=B(),r=N(V(),e.dir??".");let o;try{o=await W(r,e.config)}catch{a.error("Could not find a packem config file, please run `packem init` first.");return}if(await Ve(r)&&!await v({initialValue:!1,message:"Git repository has uncommitted changes. Do you want to proceed?"})){ae("Operation cancelled.");return}const i=await oe(o,{buffer:!1}),l=i.includes("import")?"esm":"cjs",m=new pe(i),f=" transformer,",d=i.includes(" transformer,")?" transformer,":" transformer",g={logger:a,magic:m,packemConfig:i,packemConfigFilePath:o,packemConfigFormat:l,rootDirectory:r,spinner:n,transformerReplaceKey:f,transformerSearchKey:d};t.includes("typedoc")&&await Te(g),t.includes("react")&&await Re(g),t.includes("solid")&&await Fe(g),t.includes("preact")&&await Je(g),t.includes("vue")&&await Ke(g),t.includes("svelte")&&await Ue(g),t.includes("css")&&await Ge(g),await ce(o,m.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 We=Object.defineProperty,X=w((s,t)=>We(s,"name",{value:t,configurable:!0}),"a$1");const _e=X(async(s,t,a="PACKEM_")=>{const e=N(t,s);if(!A(e))return{};const{readFile:n}=await import("node:fs/promises"),r=await n(e,"utf-8"),o={};if(typeof F=="function")try{const i=F(r);for(const[l,m]of Object.entries(i))(!a||l.startsWith(a))&&(o[`process.env.${l}`]=JSON.stringify(m))}catch{return J(r,a)}else return J(r,a);return o},"loadEnvFile"),J=X((s,t="PACKEM_")=>{const a={};for(const e of s.split(`
|
|
37
|
+
`)){const n=e.trim();if(!n||n.startsWith("#"))continue;const r=n.match(/^([^=:#]+)=(.*)$/);if(r&&r[1]&&r[2]!==void 0){const o=r[1].trim();let i=r[2].trim();(i.startsWith('"')&&i.endsWith('"')||i.startsWith("'")&&i.endsWith("'"))&&(i=i.slice(1,-1)),(!t||o.startsWith(t))&&(a[`process.env.${o}`]=JSON.stringify(i))}}return a},"loadEnvFileManually");var He=Object.defineProperty,Xe=w((s,t)=>He(s,"name",{value:t,configurable:!0}),"e$2");const Ye=Xe(async(s,t,a,e,n)=>{const r=await W(t,n);let o=await s.import(r,{default:!0,try:!0})||{};return typeof o=="function"&&(o=await o(a,e)),{config:o,path:r}},"loadPackemConfig");var Qe=Object.defineProperty,Ze=w((s,t)=>Qe(s,"name",{value:t,configurable:!0}),"e$1");const et=Ze(async(s,t)=>{switch(s){case"none":return{};case"preact":{const{createPreactPreset:a}=await import("../config/preset/preact.js");s=a();break}case"react":{const{createReactPreset:a}=await import("../config/preset/react.js");s=a();break}case"solid":{const{createSolidPreset:a}=await import("../config/preset/solid.js");s=a();break}case"svelte":{const{createSveltePreset:a}=await import("../config/preset/svelte.js");s=a();break}case"vue":{const{createVuePreset:a}=await import("../config/preset/vue.js");s=a();break}default:typeof s=="string"&&(s=await t.import(s)||{})}return typeof s=="function"&&(s=s()),s},"loadPreset");var tt=Object.defineProperty,P=w((s,t)=>tt(s,"name",{value:t,configurable:!0}),"o");const st=P(s=>{s.addCommand({description:"Demonstrate options required",execute:P(async({logger:t,options:a})=>{const e=a;let n="build";e.watch?n="watch":e.jit&&(n="jit");let r;const o={};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=R:e.development&&(r=me));const i=[];if(e.external)for(const c of e.external)i.push(c.split(","));const l=N(V(),e.dir??"."),m=fe(l,{debug:e.debug}),{config:f,path:d}=await Ye(m,l,r,n,e.config??void 0);t.debug("Using packem config found at",d);const g=e.envFile??f.envFile,p=e.envPrefix??f.envPrefix??"PACKEM_",y={};if(g){const c=await _e(g,l,p);Object.assign(y,c)}Object.assign(y,o);const k=await et(f.preset??"none",m);e.minify&&e.sourcemap===void 0&&(e.sourcemap=!0);try{const c=ge()(f,ye,k,{analyze:e.analyze,cjsInterop:e.cjsInterop,clean:e.clean,dtsOnly:e.dtsOnly,externals:i,killSignal:e.killSignal,minify:e.minify===void 0?r===R:e.minify,onSuccess:e.onSuccess,rollup:{esbuild:{target:e.target},license:{path:e.license},metafile:e.metafile,...Object.keys(y).length>0||Object.keys(o).length>0?{replace:{values:y}}:{},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.exe?{exe:!0}:{},...e.typedoc?{typedoc:{format:"html"}}:{}});e.validation===!1&&!f.validation&&(c.validation=!1),await be(l,n,r,t,e.debug,c,e.tsconfig??void 0)}catch(c){t.error(c),se(1)}},"execute"),name:"build",options:[{defaultValue:".",description:"The directory to build",name:"dir",type:String},{alias:"t",description:"Environments to support. `target` in tsconfig.json is automatically added. Defaults to the current Node.js version.",name:"target"},{description:"Use a custom config file",name:"config",type:String},{description:"Path to the tsconfig.json file",name:"tsconfig",type:String},{description:"Minify the output",name:"minify",type:Boolean},{description:"Generate sourcemaps (experimental)",name:"sourcemap",type:Boolean},{conflicts:"jit",description:"Watch for changes",name:"watch",type:Boolean},{conflicts:"watch",description:"Stub the package for JIT compilation",name:"jit",type:Boolean},{description:"Compile-time environment variables (eg. --env.NODE_ENV=production)",multiple:!0,name:"env",type:P(t=>{const[a,e]=t.split("=");return{key:a,value:e}},"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:P(t=>{if(t==="SIGTERM"||t==="SIGKILL")return t;throw new Error("Invalid kill signal. Use 'SIGTERM' or 'SIGKILL'.")},"type")},{description:"Specify an external dependency, separate by comma (eg. --external lodash,react,react-dom)",multiple:!0,name:"external",typeLabel:"string[]"},{description:"do not bundle external dependencies",name:"no-external",type:Boolean},{description:"Specify the build runtime (nodejs, browser).",name:"runtime",type:P(t=>{if(t==="node"||t==="browser")return t;throw new Error("Invalid runtime. Use 'node' or 'browser'.")},"type")},{description:"Enable unbundle mode to preserve source file structure instead of bundling into a single file",name:"unbundle",type:Boolean},{description:"Bundle the output into a standalone executable via Node.js SEA (requires Node.js >= 25.7.0, single entry)",name:"exe",type:Boolean}]})},"createBuildCommand");var at=Object.defineProperty,I=w((s,t)=>at(s,"name",{value:t,configurable:!0}),"f");const it=I(s=>{s.addCommand({description:"Initialize packem configuration",execute:I(async({logger:t,options:a})=>{const e=a;if(ie("Welcome to packem setup"),L($(e.dir,"packem.config.mjs"))){t.info("Packem project already initialized, you can use `packem build` to build your project");return}const n=N(V(),e.dir??"."),r=$(n,"package.json");if(!L(r))throw new Error("No package.json found in the directory");const o=await G(r,{resolveCatalogs:!0}),i=[];o.dependencies&&i.push(...Object.keys(o.dependencies)),o.devDependencies&&i.push(...Object.keys(o.devDependencies));const l=!!(o.devDependencies?.typescript??o.dependencies?.typescript),m=[];if(e.typescript===void 0&&!l?(e.typescript=await v({message:"Do you want to install TypeScript?"}),e.typescript&&m.push("typescript@latest")):T.message(`TypeScript version ${o.devDependencies?.typescript??o.dependencies?.typescript} is already installed`),!L($(n,"tsconfig.json"))){const c=await v({message:"Do you want to use generate a tsconfig.json?"}),u=await v({message:"Do you want to run your code in the DOM?"});if(c){const S=B();S.start("Generating tsconfig.json"),le($(n,"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"]}}),S.stop("")}}e.runtime===void 0&&(e.runtime=await h({message:"Pick a build runtime",options:[{label:"Node",value:"node"},{label:"Browser",value:"browser"}]})),i.includes("esbuild")?e.transformer="esbuild":i.includes("@swc/core")?e.transformer="swc":i.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"&&!i.includes(e.transformer)&&await v({message:`Do you want to install ${e.transformer}?`})&&m.push(e.transformer==="swc"?"@swc/core":e.transformer)):T.message(`Transformer ${e.transformer} is already installed.`),e.css===void 0&&(e.css=await v({message:"Do you want to use css in your project?",initialValue:!1}));const f=[];if(e.css){const c=await h({message:"Pick a css loader",options:[{label:"PostCSS",value:"postcss"},{hint:"experimental",label:"Lightning CSS",value:"lightningcss"}]});f.push(c);let u=await U({message:"Pick your loaders",options:[{label:"Sass",value:"sass"},{label:"Stylus",value:"stylus"},{label:"Less",value:"less"}],required:!1});if(u.includes("sass")){const S=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"}]});S!=="sass"&&(u=u.filter(Y=>Y!=="sass"),u.push(S))}if(f.push(...u),await v({message:`Do you want to install "${f.join('", "')}"?`}))for(const S of f)m.push(..._[S]);f.push("sourceMap")}e.cssMinifier===void 0&&(e.cssMinifier=await v({message:"Do you want to minify your css?",initialValue:!1}));let d;e.cssMinifier&&(d=await h({message:"Pick a css minifier",options:[{label:"CSSNano",value:"cssnano"},{label:"Lightning CSS",value:"lightningcss"}]}),f.includes("lightningcss")||await v({message:`Do you want to install "${d}"?`})&&m.push(d));let g="",p="";if((e.css||e.cssMinifier)&&(p+=`,
|
|
39
38
|
rollup: {
|
|
40
|
-
css: {`),e.css){const c=f.map(
|
|
39
|
+
css: {`),e.css){const c=f.map(u=>((u==="sass-embedded"||u==="node-sass")&&(u="sass"),`${u}Loader`)).join(", ");p+=`
|
|
41
40
|
loaders: [${c}],`}if(e.cssMinifier&&d&&(p+=`
|
|
42
41
|
minifier: ${d}Minifier,`),(e.css||e.cssMinifier)&&(p+=`
|
|
43
42
|
}
|
|
44
|
-
}`),l||
|
|
45
|
-
`),e.css)for(let m of f)(m==="sass-embedded"||m==="node-sass")&&(m="sass"),c+=`import ${m}Loader from "@visulima/packem/css/loader/${m.toLowerCase()}";
|
|
43
|
+
}`),l||o.type==="module"){let c="";if(e.css)for(let u of f)(u==="sass-embedded"||u==="node-sass")&&(u="sass"),c+=`import ${u}Loader from "@visulima/packem/css/loader/${u.toLowerCase()}";
|
|
46
44
|
`;e.cssMinifier&&d&&(c+=`import ${d}Minifier from "@visulima/packem/css/minifier/${d.toLowerCase()}";
|
|
47
45
|
`),g=`import { defineConfig } from "@visulima/packem/config";
|
|
48
46
|
import transformer from "@visulima/packem/transformer/${e.transformer}";
|
|
@@ -51,8 +49,7 @@ export default defineConfig({
|
|
|
51
49
|
runtime: "${e.runtime}",
|
|
52
50
|
transformer${p}
|
|
53
51
|
});
|
|
54
|
-
`}else{let c="";if(e.
|
|
55
|
-
`),e.css)for(let m of f)(m==="sass-embedded"||m==="node-sass")&&(m="sass"),c+=`const ${m}Loader = require("@visulima/packem/css/loader/${m.toLowerCase()}");
|
|
52
|
+
`}else{let c="";if(e.css)for(let u of f)(u==="sass-embedded"||u==="node-sass")&&(u="sass"),c+=`const ${u}Loader = require("@visulima/packem/css/loader/${u.toLowerCase()}");
|
|
56
53
|
`;e.cssMinifier&&d&&(c+=`const ${d}Minifier = require("@visulima/packem/css/minifier/${d.toLowerCase()}");
|
|
57
54
|
`),g=`const { defineConfig } = require("@visulima/packem/config");
|
|
58
55
|
const transformer = require("@visulima/packem/transformer/${e.transformer}");
|
|
@@ -61,8 +58,8 @@ module.exports = defineConfig({
|
|
|
61
58
|
runtime: ${e.runtime},
|
|
62
59
|
transformer${p}
|
|
63
60
|
});
|
|
64
|
-
`}const y=
|
|
61
|
+
`}const y=B(),k=l?"ts":"js";m.length>0&&(y.start("Installing packages"),await x(m,{cwd:n,dev:!0,silent:!0}),y.stop("Installed packages")),y.start(`Creating packem.config.${k}`),de($(n,`packem.config.${k}`),g),y.stop(`Created packem.config.${k}`),ne("Now you can run `packem build` to build your project")},"execute"),name:"init",options:[{defaultValue:".",description:"The directory to initialize",name:"dir",type:String},{description:"Choose a transformer",name:"transformer",type:I(t=>{if(typeof t=="string"&&["esbuild","sucrase","swc"].includes(t))return t;throw new Error("Invalid transformer, please choose one of 'swc', 'sucrase' or 'esbuild'")},"type")},{description:"Use CSS",name:"css",type:Boolean},{description:"Use CSS minifier",name:"css-minifier",type:Boolean},{Description:"Use TypeScript",name:"typescript",type:Boolean},{description:"Specify the build runtime (nodejs, browser).",name:"runtime",type:I(t=>{if(t==="node"||t==="browser")return t;throw new Error("Invalid runtime. Use 'node' or 'browser'.")},"type")}]})},"createInitCommand");var nt=Object.defineProperty,j=w((s,t)=>nt(s,"name",{value:t,configurable:!0}),"a");const rt=j(async({cwd:s,dryRun:t,logger:a})=>{if(t)a.info("Dry run enabled. No changes will be made.");else{const n=he({input:C.stdin,output:C.stdout});a.warn(`
|
|
65
62
|
|
|
66
63
|
Before proceeding, review the migration guide at https://www.visulima.com/docs/package/packem, as this process will modify your files.
|
|
67
|
-
Uncommitted changes will be lost. Use the --dry-run flag to preview changes without applying them.`);const
|
|
68
|
-
`;return
|
|
64
|
+
Uncommitted changes will be lost. Use the --dry-run flag to preview changes without applying them.`);const r=await n.question("Continue? (Y/n) ");if(n.close(),!(r.toLowerCase()==="y"||r==="")){a.error("Migration cancelled."),C.exitCode=1;return}}s&&C.chdir(s);let e=!1;await ct(t,a)&&(e=!0),await dt(t,a)&&(e=!0),e?a.success("Migration completed. Remember to run install command with your package manager."):(a.error("No migration performed."),C.exitCode=1)},"migrate"),K={bunchee:"@visulima/packem",tsup:"@visulima/packem","tsup-node":"@visulima/packem",unbuild:"@visulima/packem"},ot={dependencies:`^${q.version}`,devDependencies:`^${q.version}`,peerDependencies:"*"},ct=j(async(s,t)=>{if(!A("package.json"))return t.error("No package.json found"),!1;const a=await ve("package.json","utf8"),e=JSON.parse(a);let n=!1;for(const[i,l]of Object.entries(ot))for(const[m,f]of Object.entries(K))e[i]?.[m]&&(t.info(`Migrating \`${i}\` from ${m} to ${f}.`),n=!0,e[i]=pt(e[i],m,f,l));if(e.scripts)for(const i of Object.keys(e.scripts)){for(const[l,m]of Object.entries(K))e.scripts[i].includes(l)&&(t.info(`Migrating \`${i}\` script from ${l} to packem`),n=!0,e.scripts[i]=e.scripts[i].replaceAll(new RegExp(String.raw`\b${l}\b`,"g"),"packem").replaceAll(new RegExp(String.raw`\b${l}-node\b`,"g"),"packem"));e.scripts[i].includes("tsup")&&(t.info(`Migrating \`${i}\` script from tsup to packem`),n=!0,e.scripts[i]=e.scripts[i].replaceAll(/\btsup(?:-node)?/g,"packem build").replaceAll(/\bbuild\b/g,"build")),e.scripts[i].includes("unbuild")&&(t.info(`Migrating \`${i}\` script from unbuild to packem`),n=!0,e.scripts[i]=e.scripts[i].replaceAll(/\bunbuild\b/g,"packem build")),e.scripts[i].includes("bunchee")&&(t.info(`Migrating \`${i}\` script from bunchee to packem`),n=!0,e.scripts[i]=e.scripts[i].replaceAll(/\bbunchee\b/g,"packem build"))}const r=["tsup","unbuild","bunchee"];for(const i of r)e[i]&&t.info(`Found \`${i}\` config field in package.json. Consider moving to packem.config.ts`);if(!n)return t.warn("No migratable bundler dependencies found in package.json"),!1;const o=`${JSON.stringify(e,null,a.includes(" ")?" ":2)}
|
|
65
|
+
`;return s?(t.info("[dry-run] package.json changes:"),t.info("Old content:"),console.info(a),t.info("New content:"),console.info(o)):(await we("package.json",o),t.success("Migrated `package.json`")),!0},"migratePackageJson"),lt=["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"],dt=j(async(s,t)=>{let a=!1;for(const e of lt)A(e)&&(t.info(`Found config file \`${e}\`. Consider creating packem.config.ts instead.`),t.warn("Manual migration required for config files. See https://www.visulima.com/docs/package/packem"),a=!0);return a||t.warn("No bundler config files found"),a},"migrateConfigFiles"),pt=j((s,t,a,e)=>{const n={};for(const r of Object.keys(s))r===t?n[a]=e||s[t]:n[r]=s[r];return n},"renameKey"),ut=j(s=>{s.addCommand({description:"Migrate from other bundlers (tsup, unbuild, bunchee, etc.) to packem",execute:j(async({logger:t,options:a})=>{const e=a;await rt({cwd:e.cwd,dryRun:e.dryRun,logger:t})},"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 te({error:{hideErrorCauseCodeView:!0,hideErrorCodeView:!0,hideErrorErrorsCodeView:!0}})],scope:"packem"}),packageName:ke,packageVersion:z});it(E);st(E);ze(E);ut(E);E.run({shouldExitProcess:!1});
|
package/dist/config/index.d.ts
CHANGED
|
@@ -1,48 +1,58 @@
|
|
|
1
|
-
import
|
|
2
|
-
export
|
|
3
|
-
|
|
1
|
+
import { B as BuildConfig, c as BuildConfigFunction, d as BuildPreset } from "../packem_shared/types.d-fhksMqKN.js";
|
|
2
|
+
export { type BuildHooks } from '@visulima/packem-share/types';
|
|
3
|
+
import '@arethetypeswrong/core';
|
|
4
|
+
import '@visulima/packem-rollup';
|
|
5
|
+
import '@visulima/packem-rollup/oxc';
|
|
6
|
+
import '@visulima/packem-rollup/plugin/native-modules';
|
|
7
|
+
import '@visulima/packem-share/utils';
|
|
8
|
+
import '@visulima/rollup-plugin-css';
|
|
9
|
+
import 'jiti';
|
|
10
|
+
import 'rollup';
|
|
11
|
+
import 'typedoc';
|
|
12
|
+
import '@visulima/pail';
|
|
4
13
|
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
14
|
+
* Defines a build configuration for Packem.
|
|
15
|
+
* Supports both static configuration objects and dynamic configuration functions.
|
|
16
|
+
* @param config Static build configuration object or function returning configuration
|
|
17
|
+
* @returns The provided configuration
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* // Static configuration
|
|
21
|
+
* export default defineConfig({
|
|
22
|
+
* entries: ['./src/index.ts'],
|
|
23
|
+
* outDir: './dist'
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* // Dynamic configuration
|
|
27
|
+
* export default defineConfig((env, mode) => ({
|
|
28
|
+
* entries: ['./src/index.ts'],
|
|
29
|
+
* outDir: env === 'production' ? './dist' : './dev'
|
|
30
|
+
* }));
|
|
31
|
+
* ```
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
declare const defineConfig: (config: BuildConfig | BuildConfigFunction) => BuildConfig | BuildConfigFunction;
|
|
26
35
|
/**
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
36
|
+
* Defines a build preset for Packem.
|
|
37
|
+
* Build presets provide reusable configuration templates that can be shared across projects.
|
|
38
|
+
* @param preset Build preset configuration
|
|
39
|
+
* @returns The provided preset configuration
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* export default definePreset({
|
|
43
|
+
* name: 'my-preset',
|
|
44
|
+
* defaults: {
|
|
45
|
+
* entries: ['./src/index.ts'],
|
|
46
|
+
* outDir: './dist'
|
|
47
|
+
* },
|
|
48
|
+
* hooks: {
|
|
49
|
+
* 'build:before': (context) => {
|
|
50
|
+
* // Custom build preparation logic
|
|
51
|
+
* }
|
|
52
|
+
* }
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
* @public
|
|
56
|
+
*/
|
|
57
|
+
declare const definePreset: (preset: BuildPreset) => BuildPreset;
|
|
58
|
+
export { type BuildConfig, type BuildConfigFunction, type BuildPreset, defineConfig, definePreset };
|
|
@@ -1,18 +1,30 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import { BabelPluginConfig } from '@visulima/packem-rollup/babel';
|
|
2
|
+
import { B as BuildConfig } from "../../packem_shared/types.d-fhksMqKN.js";
|
|
3
|
+
import '@arethetypeswrong/core';
|
|
4
|
+
import '@visulima/packem-rollup';
|
|
5
|
+
import '@visulima/packem-rollup/oxc';
|
|
6
|
+
import '@visulima/packem-rollup/plugin/native-modules';
|
|
7
|
+
import '@visulima/packem-share/types';
|
|
8
|
+
import '@visulima/packem-share/utils';
|
|
9
|
+
import '@visulima/rollup-plugin-css';
|
|
10
|
+
import 'jiti';
|
|
11
|
+
import 'rollup';
|
|
12
|
+
import 'typedoc';
|
|
13
|
+
import '@visulima/pail';
|
|
14
|
+
interface PreactPresetOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Enable Preact devtools in production builds
|
|
17
|
+
* @default false
|
|
18
|
+
*/
|
|
19
|
+
devtoolsInProd?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Custom Babel plugins to add
|
|
22
|
+
*/
|
|
23
|
+
plugins?: BabelPluginConfig["plugins"];
|
|
24
|
+
/**
|
|
25
|
+
* Custom Babel presets to add
|
|
26
|
+
*/
|
|
27
|
+
presets?: BabelPluginConfig["presets"];
|
|
17
28
|
}
|
|
18
|
-
|
|
29
|
+
declare const createPreactPreset: (options?: PreactPresetOptions) => BuildConfig;
|
|
30
|
+
export { PreactPresetOptions, createPreactPreset };
|