@visulima/packem 2.0.0-alpha.4 → 2.0.0-alpha.40
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 +449 -1
- package/LICENSE.md +5860 -963
- package/README.md +16 -12
- package/dist/builder/typedoc/generate-reference-documentation.d.ts +4 -0
- package/dist/builder/typedoc/index.d.ts +3 -26
- package/dist/cli/commands/add.d.ts +3 -0
- package/dist/cli/commands/build.d.ts +21 -0
- package/dist/cli/commands/init.d.ts +3 -0
- package/dist/cli/commands/migrate.d.ts +21 -0
- package/dist/cli/commands/utils/css-loader-dependencies.d.ts +2 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +39 -35
- package/dist/config/index.d.ts +48 -28
- package/dist/config/preset/auto.d.ts +3 -0
- package/dist/config/preset/utils/infer-entries.d.ts +12 -0
- package/dist/config/preset/utils/overwrite-with-publish-config.d.ts +4 -0
- package/dist/config/utils/find-packem-file.d.ts +2 -0
- package/dist/config/utils/load-package-json.d.ts +6 -0
- package/dist/config/utils/load-packem-config.d.ts +7 -0
- package/dist/config/utils/load-preset.d.ts +4 -0
- package/dist/config/utils/load-tsconfig.d.ts +5 -0
- package/dist/config/utils/prepare-entries.d.ts +4 -0
- package/dist/index.d.ts +45 -32
- package/dist/index.js +1 -1
- package/dist/jit/create-stub.d.ts +4 -0
- package/dist/packem/build.d.ts +21 -0
- package/dist/packem/index.d.ts +25 -0
- package/dist/packem/node10-compatibility.d.ts +7 -0
- package/dist/packem/utils/brotli-size.d.ts +2 -0
- package/dist/packem/utils/group-by-keys.d.ts +3 -0
- package/dist/packem/utils/gzip-size.d.ts +2 -0
- package/dist/packem_shared/default-B2EOH52z.js +1 -0
- package/dist/packem_shared/default-BYM_JvQL.js +1 -0
- package/dist/packem_shared/{default-DqRcOUe1.js → default-Dego_fiC.js} +1 -1
- package/dist/packem_shared/{default-B6X7-Lx3.js → default-E4TiWfSK.js} +1 -1
- package/dist/packem_shared/esbuildPlugin-DpLtQGuZ-Bny-e486.js +3 -0
- package/dist/packem_shared/index-DFigeRU2.js +174 -0
- package/dist/packem_shared/oxcResolvePlugin-Ccef6pyL-D14z9S9i.js +1 -0
- package/dist/packem_shared/{resolveTypescriptMjsCtsPlugin-DcZrZTmM-BEkYWTsH.js → resolveTypescriptMjsCtsPlugin-DcZrZTmM-3AmQC7y7.js} +4 -4
- package/dist/rollup/build-types.d.ts +5 -0
- package/dist/rollup/build.d.ts +5 -0
- package/dist/rollup/get-rollup-options.d.ts +5 -0
- package/dist/rollup/plugins/css/loaders/less.d.ts +1 -1
- package/dist/rollup/plugins/css/loaders/less.js +1 -1
- package/dist/rollup/plugins/css/loaders/lightningcss.d.ts +1 -1
- package/dist/rollup/plugins/css/loaders/lightningcss.js +1 -1
- package/dist/rollup/plugins/css/loaders/postcss.d.ts +1 -1
- package/dist/rollup/plugins/css/loaders/postcss.js +1 -1
- package/dist/rollup/plugins/css/loaders/sass.d.ts +1 -1
- package/dist/rollup/plugins/css/loaders/sass.js +1 -1
- package/dist/rollup/plugins/css/loaders/sourcemap.d.ts +1 -8
- package/dist/rollup/plugins/css/loaders/sourcemap.js +1 -1
- package/dist/rollup/plugins/css/loaders/stylus.d.ts +1 -1
- package/dist/rollup/plugins/css/loaders/stylus.js +1 -1
- package/dist/rollup/plugins/css/loaders/tailwindcss.d.ts +1 -0
- package/dist/rollup/plugins/css/loaders/tailwindcss.js +1 -0
- package/dist/rollup/plugins/css/minifiers/cssnano.d.ts +1 -1
- package/dist/rollup/plugins/css/minifiers/cssnano.js +1 -1
- package/dist/rollup/plugins/css/minifiers/lightningcss.d.ts +1 -1
- package/dist/rollup/plugins/css/minifiers/lightningcss.js +1 -1
- package/dist/rollup/plugins/esbuild/index.d.ts +2 -24
- package/dist/rollup/plugins/esbuild/index.js +1 -1
- package/dist/rollup/plugins/oxc/isolated-declarations-oxc-transformer.d.ts +1 -25
- package/dist/rollup/plugins/oxc/oxc-transformer.d.ts +2 -20
- package/dist/rollup/plugins/resolve-externals-plugin.d.ts +60 -0
- package/dist/rollup/plugins/sucrase/index.d.ts +2 -19
- package/dist/rollup/plugins/swc/isolated-declarations-swc-transformer.d.ts +1 -20
- package/dist/rollup/plugins/swc/swc-plugin.d.ts +2 -26
- package/dist/rollup/plugins/typescript/isolated-declarations-typescript-transformer.d.ts +1 -24
- package/dist/rollup/utils/resolve-aliases.d.ts +4 -0
- package/dist/rollup/watch.d.ts +5 -0
- package/dist/types.d.ts +328 -0
- package/dist/utils/clean-distribution-directories.d.ts +4 -0
- package/dist/utils/create-or-update-key-storage.d.ts +3 -0
- package/dist/utils/extract-export-filenames.d.ts +16 -0
- package/dist/utils/find-alternatives.d.ts +2 -0
- package/dist/utils/get-package-side-effect.d.ts +3 -0
- package/dist/utils/infer-export-type.d.ts +3 -0
- package/dist/utils/kill-process.d.ts +14 -0
- package/dist/utils/log-build-errors.d.ts +4 -0
- package/dist/utils/remove-old-cache-folders.d.ts +3 -0
- package/dist/utils/warn-legacy-cjs.d.ts +8 -0
- package/dist/validator/attw.d.ts +7 -0
- package/dist/validator/package-json/index.d.ts +4 -0
- package/dist/validator/package-json/validate-dependencies.d.ts +4 -0
- package/dist/validator/package-json/validate-engines.d.ts +4 -0
- package/dist/validator/package-json/validate-package-entries.d.ts +4 -0
- package/dist/validator/package-json/validate-package-fields.d.ts +4 -0
- package/dist/validator/validate-alias-entries.d.ts +3 -0
- package/dist/validator/validate-bundle-size.d.ts +4 -0
- package/files.d.ts +37 -0
- package/package.json +53 -29
- package/dist/packem_shared/default-C3sdXf4G.js +0 -1
- package/dist/packem_shared/default-DR5Fia_R.js +0 -1
- package/dist/packem_shared/esbuildPlugin-BAwyhG6L-yty60jMl.js +0 -3
- package/dist/packem_shared/index-DySckW0r.d.ts +0 -5227
- package/dist/packem_shared/index-VKZ7e6tb.js +0 -138
- package/dist/packem_shared/oxcResolvePlugin-BJpi-eSG-BsYx9cDO.js +0 -1
- package/dist/packem_shared/types-CaBbG-vU.d.ts +0 -163
package/README.md
CHANGED
|
@@ -53,7 +53,7 @@ It uses the `exports` configuration in `package.json` and recognizes entry file
|
|
|
53
53
|
- ✅ Supports react server and client components
|
|
54
54
|
- ✅ Supports shared modules
|
|
55
55
|
- ✅ Supports dynamic import
|
|
56
|
-
- ✅ Supports `tsconfig.json` paths and `package.json` imports resolution
|
|
56
|
+
- ✅ Supports `tsconfig.json` paths and `package.json`, `package.yml`, `package.yaml` and `package.json5` imports resolution
|
|
57
57
|
- ✅ ESM ⇄ CJS interoperability
|
|
58
58
|
- ✅ Supports isolated declaration types (experimental) (Typescript version 5.5 or higher)
|
|
59
59
|
- ✅ Supports wasm [WebAssembly modules](http://webassembly.org)
|
|
@@ -163,13 +163,9 @@ Enable the automatic `node 10` typesVersions generation in packem.config.js:
|
|
|
163
163
|
```js
|
|
164
164
|
export default defineConfig({
|
|
165
165
|
// ...
|
|
166
|
-
|
|
167
|
-
//
|
|
168
|
-
|
|
169
|
-
typeScriptVersion: ">=5.0", // Chose the version of TypeScript you want to support
|
|
170
|
-
writeToPackageJson: true,
|
|
171
|
-
},
|
|
172
|
-
// ...
|
|
166
|
+
node10Compatibility: {
|
|
167
|
+
typeScriptVersion: ">=5.0", // Chose the version of TypeScript you want to support
|
|
168
|
+
writeToPackageJson: true,
|
|
173
169
|
},
|
|
174
170
|
transformer,
|
|
175
171
|
});
|
|
@@ -454,13 +450,13 @@ Native Node.js import mapping supports conditional imports (eg. resolving differ
|
|
|
454
450
|
{
|
|
455
451
|
// ...
|
|
456
452
|
|
|
457
|
-
|
|
453
|
+
imports: {
|
|
458
454
|
// Mapping '~utils' to './src/utils.js'
|
|
459
455
|
"~utils": "./src/utils.js",
|
|
460
456
|
|
|
461
457
|
// Native Node.js import mapping (can't reference ./src)
|
|
462
|
-
"#internal-package": "./vendors/package/index.js"
|
|
463
|
-
}
|
|
458
|
+
"#internal-package": "./vendors/package/index.js",
|
|
459
|
+
},
|
|
464
460
|
}
|
|
465
461
|
```
|
|
466
462
|
|
|
@@ -895,7 +891,15 @@ Will look for `_custom` first (_with the appropriate extension(s)_), and then fo
|
|
|
895
891
|
styles({
|
|
896
892
|
mode: "inject", // Unnecessary, set by default
|
|
897
893
|
// ...or with custom options for injector
|
|
898
|
-
mode: [
|
|
894
|
+
mode: [
|
|
895
|
+
"inject",
|
|
896
|
+
{
|
|
897
|
+
attributes: { id: "global" },
|
|
898
|
+
container: "body",
|
|
899
|
+
prepend: true,
|
|
900
|
+
singleTag: true,
|
|
901
|
+
},
|
|
902
|
+
],
|
|
899
903
|
// ...or with custom injector
|
|
900
904
|
mode: ["inject", (varname, id) => `console.log(${varname},${JSON.stringify(id)})`],
|
|
901
905
|
});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Pail } from "@visulima/pail";
|
|
2
|
+
import type { BuildEntry, TypeDocumentOptions } from "../../types.d.ts";
|
|
3
|
+
declare const generateReferenceDocumentation: (options: TypeDocumentOptions, entries: BuildEntry[], outputDirectory: string, logger: Pail) => Promise<void>;
|
|
4
|
+
export default generateReferenceDocumentation;
|
|
@@ -1,27 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import '@rollup/plugin-alias';
|
|
4
|
-
import '@rollup/plugin-commonjs';
|
|
5
|
-
import '@rollup/plugin-json';
|
|
6
|
-
import '@rollup/plugin-node-resolve';
|
|
7
|
-
import '@rollup/plugin-replace';
|
|
8
|
-
import '@rollup/plugin-wasm';
|
|
9
|
-
import '@rollup/pluginutils';
|
|
10
|
-
import 'rollup';
|
|
11
|
-
import 'rollup-plugin-dts';
|
|
12
|
-
import 'rollup-plugin-polyfill-node';
|
|
13
|
-
import 'rollup-plugin-pure';
|
|
14
|
-
import 'rollup-plugin-visualizer';
|
|
15
|
-
import 'esbuild';
|
|
16
|
-
import '@visulima/package';
|
|
17
|
-
import '@visulima/colorize';
|
|
18
|
-
import 'oxc-resolver';
|
|
19
|
-
import 'oxc-transform';
|
|
20
|
-
import 'sucrase';
|
|
21
|
-
import '@visulima/rollup-css-plugin';
|
|
22
|
-
import 'jiti';
|
|
23
|
-
import 'typedoc';
|
|
24
|
-
|
|
1
|
+
import type { BuildContext } from "@visulima/packem-share/types";
|
|
2
|
+
import type { InternalBuildOptions } from "../../types.d.ts";
|
|
25
3
|
declare const builder: (context: BuildContext<InternalBuildOptions>, cachePath: string | undefined, _: never, logged: boolean) => Promise<void>;
|
|
26
|
-
|
|
27
|
-
export { builder as default };
|
|
4
|
+
export default builder;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Cli } from "@visulima/cerebro";
|
|
2
|
+
/**
|
|
3
|
+
* Creates and registers the build command with the CLI.
|
|
4
|
+
* Handles various build modes, environment variables, and build configurations.
|
|
5
|
+
* @param cli CLI instance to register the command with
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* // Usage from command line:
|
|
9
|
+
* // Build for production:
|
|
10
|
+
* // packem build --production
|
|
11
|
+
*
|
|
12
|
+
* // Watch mode with development environment:
|
|
13
|
+
* // packem build --watch --development
|
|
14
|
+
*
|
|
15
|
+
* // With custom environment variables:
|
|
16
|
+
* // packem build --env.API_URL=http://api.example.com
|
|
17
|
+
* ```
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
declare const createBuildCommand: (cli: Cli) => void;
|
|
21
|
+
export default createBuildCommand;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Cli } from "@visulima/cerebro";
|
|
2
|
+
/**
|
|
3
|
+
* Creates and registers the migrate command with the CLI.
|
|
4
|
+
* Handles migration from other bundlers (tsup, unbuild, bunchee, etc.) to packem.
|
|
5
|
+
* @param cli CLI instance to register the command with
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* // From command line:
|
|
9
|
+
* // Migrate from tsup to packem:
|
|
10
|
+
* // packem migrate
|
|
11
|
+
*
|
|
12
|
+
* // Dry run to preview changes:
|
|
13
|
+
* // packem migrate --dry-run
|
|
14
|
+
*
|
|
15
|
+
* // Specify custom directory:
|
|
16
|
+
* // packem migrate --cwd /path/to/project
|
|
17
|
+
* ```
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
declare const createMigrateCommand: (cli: Cli) => void;
|
|
21
|
+
export default createMigrateCommand;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/cli/index.js
CHANGED
|
@@ -1,55 +1,59 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var
|
|
2
|
+
var me=Object.defineProperty;var v=(t,s)=>me(t,"name",{value:s,configurable:!0});import{createCerebro as fe}from"@visulima/cerebro";import ge from"@visulima/cerebro/logger/pail";import{SimpleReporter as ye}from"@visulima/pail/reporter/simple";import P,{cwd as W,exit as be}from"node:process";import{installPackage as q}from"@antfu/install-pkg";import{spinner as U,select as j,multiselect as ie,confirm as h,intro as we,log as X,cancel as ve,outro as he}from"@clack/prompts";import{isAccessible as ke,readFile as $e,writeFile as je,isAccessibleSync as x,collectSync as Y,writeJsonSync as xe,writeFileSync as Se}from"@visulima/fs";import{join as C,resolve as E,extname as ne,toNamespacedPath as Ce}from"@visulima/path";import De from"magic-string";import{t as K,E as G,e as Ee,N as re,_ as Me,c as Pe}from"../packem_shared/index-CUp9WuCG.js";import{defu as Oe}from"defu";import{createJiti as Ie}from"jiti";import{cyan as Te,bold as V,gray as Ne}from"@visulima/colorize";import{e as Be,i as H,c as Le,x as Ae}from"../packem_shared/index-DFigeRU2.js";import Ke,{readFile as Fe,writeFile as Re}from"node:fs/promises";import Z from"node:path/posix";import{parsePackageJson as Je}from"@visulima/package/package-json";import{existsSync as ae}from"node:fs";import{createInterface as Ve}from"node:readline/promises";import __cjs_mod__ from "node:module"; // -- packem CommonJS require shim --
|
|
3
3
|
const require = __cjs_mod__.createRequire(import.meta.url);
|
|
4
|
-
|
|
5
|
-
`):
|
|
6
|
-
`),
|
|
4
|
+
var qe="@visulima/packem",ce="2.0.0-alpha.39";const Q={version:ce};var Ue=Object.defineProperty,Ge=v((t,s)=>Ue(t,"name",{value:s,configurable:!0}),"t$1");const le=Ge(async(t,s="")=>{let e=s;if(!e){const i=["packem.config.js","packem.config.mjs","packem.config.cjs","packem.config.ts","packem.config.cts","packem.config.mts"];for(const o of i)if(await ke(C(t,o))){e=`./${o}`;break}}if(!/\.(?:js|mjs|cjs|ts|cts|mts)$/.test(e))throw new Error("Invalid packem config file extension. Only .js, .mjs, .cjs, .ts, .cts and .mts extensions are allowed.");return e},"findPackemFile"),pe={less:["less"],lightningcss:["lightningcss"],"node-sass":["node-sass"],postcss:["postcss","postcss-load-config","postcss-modules-extract-imports","postcss-modules-local-by-default","postcss-modules-scope","postcss-modules-values","postcss-value-parser","@csstools/css-parser-algorithms","@csstools/css-tokenizer","@csstools/postcss-slow-plugins","icss-utils","@visulima/css-style-inject"],sass:["sass"],"sass-embedded":["sass-embedded"],stylus:["stylus"],tailwindcss:["@tailwindcss/node","@tailwindcss/oxide","tailwindcss"]};var ze=Object.defineProperty,ee=v((t,s)=>ze(t,"name",{value:s,configurable:!0}),"g");const We=["typedoc","typedoc-plugin-markdown","typedoc-plugin-rename-defaults"],_e=ee(t=>{t.addCommand({argument:{description:"Add a packem feature to your project",name:"feature",required:!0},description:"Add a optional packem feature to your project",execute:ee(async({argument:s,logger:e,options:i})=>{const o=U(),n=E(W(),i.dir??".");let l;try{l=await le(n,i.config)}catch{e.error("Could not find a packem config file, please run `packem init` first.");return}const r=await $e(l,{buffer:!1});let u="cjs";r.includes("import")&&(u="esm");const a=new De(r),m=" transformer,";let c=" transformer";if(r.includes(" transformer,")&&(c=" transformer,"),s.includes("typedoc")){if(r.includes("typedoc: typedocBuilder")||r.includes("@visulima/packem/builder/typedoc")){e.warn("Typedoc has already been added to the packem config.");return}u==="cjs"?a.prepend(`const typedocBuilder = require("@visulima/packem/builder/typedoc");
|
|
5
|
+
`):a.prepend(`import typedocBuilder from "@visulima/packem/builder/typedoc";
|
|
6
|
+
`),r.includes("builder: {")?a.replace("builder: {",`builder: {
|
|
7
7
|
typedoc: typedocBuilder,
|
|
8
|
-
`):
|
|
8
|
+
`):a.replace(c,`${m}
|
|
9
9
|
builder: {
|
|
10
10
|
typedoc: typedocBuilder,
|
|
11
|
-
},`),e.info("Adding typedoc dependencies..."),
|
|
12
|
-
Typedoc added!`)}if(s.includes("css")){if(
|
|
13
|
-
`):
|
|
14
|
-
`);const
|
|
15
|
-
`):
|
|
16
|
-
`));const
|
|
17
|
-
css: {${
|
|
18
|
-
minifier: ${
|
|
19
|
-
loaders: [${
|
|
11
|
+
},`),e.info("Adding typedoc dependencies..."),o.start("Installing packages"),await q(We,{cwd:n,dev:!0,silent:!0}),o.stop("Installed packages"),e.success(`
|
|
12
|
+
Typedoc added!`)}if(s.includes("css")){if(r.includes("css: {")||r.includes("@visulima/packem/css")){e.warn("Css loaders have already been added to the packem config.");return}const d=[],y=await j({message:"Pick a css loader",options:[{label:"PostCSS",value:"postcss"},{hint:"experimental",label:"Lightning CSS",value:"lightningcss"},{hint:"Tailwind Css Oxide",label:"Tailwind CSS",value:"tailwindcss"}]});if(d.push(y),y!=="tailwindcss"){let g=await ie({message:"Pick extra loaders",options:[{label:"Sass",value:"sass"},{label:"Stylus",value:"stylus"},{label:"Less",value:"less"}],required:!1});if(g.includes("sass")){const k=await j({message:"Pick a sass loader",options:[{hint:"recommended",label:"Sass embedded",value:"sass-embedded"},{label:"Sass",value:"sass"},{hint:"legacy",label:"Node Sass",value:"node-sass"}]});k!=="sass"&&(g=g.filter(D=>D!=="sass"),g.push(k))}d.push(...g)}const b=[];for(const g of d)b.push(...pe[g]);y!=="tailwindcss"&&d.push("sourceMap");for(let g of d)(g==="sass-embedded"||g==="node-sass")&&(g="sass"),u==="cjs"?a.prepend(`const ${g}Loader = require("@visulima/packem/css/loader/${g.toLowerCase()}");
|
|
13
|
+
`):a.prepend(`import ${g}Loader from "@visulima/packem/css/loader/${g.toLowerCase()}";
|
|
14
|
+
`);const f=await h({initialValue:!1,message:"Do you want to minify your css?"});let p;f&&(p=await j({message:"Pick a css minifier",options:[{label:"CSSNano",value:"cssnano"},{label:"Lightning CSS",value:"lightningcss"}]}),d.includes("lightningcss")||b.push(p),u==="cjs"?a.prepend(`const ${p}Minifier = require("@visulima/packem/css/minifier/${p.toLowerCase()}");
|
|
15
|
+
`):a.prepend(`import ${p}Minifier from "@visulima/packem/css/minifier/${p.toLowerCase()}";
|
|
16
|
+
`));const w=d.map(g=>((g==="sass-embedded"||g==="node-sass")&&(g="sass"),`${g}Loader`)).join(", ");r.includes("rollup: {")?a.replace("rollup: {",`rollup: {
|
|
17
|
+
css: {${p?`
|
|
18
|
+
minifier: ${p}Minifier,`:""}
|
|
19
|
+
loaders: [${w}],
|
|
20
20
|
},
|
|
21
|
-
`):
|
|
21
|
+
`):a.replace(c,`${m}
|
|
22
22
|
rollup: {
|
|
23
|
-
css: {${
|
|
24
|
-
minifier: ${
|
|
25
|
-
loaders: [${
|
|
23
|
+
css: {${p?`
|
|
24
|
+
minifier: ${p}Minifier,`:""}
|
|
25
|
+
loaders: [${w}],
|
|
26
26
|
},
|
|
27
|
-
},`),
|
|
28
|
-
CSS loaders added!`)}await ae(p,o.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 Ie=Object.defineProperty,Me=h((t,s)=>Ie(t,"name",{value:s,configurable:!0}),"e$1");const Te=Me(async(t,s,e,r,n)=>{const i=await _(s,n);let p=await t.import(i,{default:!0,try:!0})||{};return typeof p=="function"&&(p=await p(e,r)),{config:p,path:i}},"loadPackemConfig");var Be=Object.defineProperty,T=h((t,s)=>Be(t,"name",{value:s,configurable:!0}),"E$1");const Le=T((t,s)=>t.key==="exports"&&t.subKey===I?I:t.key==="exports"&&t.subKey===V?V:s,"getEnvironment"),P=T((t,s,e,r,n,i,p)=>{const m=Le(n,i.environment);let y=i.options.runtime;for(const c of ue)if(n.file.includes(`.${c}.`)||n.subKey===c){y=c;break}let o=t.find(c=>c.input===s&&c.environment===m&&c.runtime===y);o===void 0?o=t[t.push({environment:m,exportKey:new Set([n.exportKey].filter(Boolean)),input:s,runtime:y})-1]:o.exportKey&&n.exportKey&&o.exportKey.add(n.exportKey),p&&(o.isGlob=!0),e&&(o.outDir=r),n.isExecutable?(o.executable=!0,o.declaration=!1,n.type==="cjs"?o.cjs=!0:n.type==="esm"&&(o.esm=!0)):(/\.d\.[mc]?ts$/.test(n.file)&&i.options.declaration!==!1&&(o.declaration=i.options.declaration),n.type==="cjs"?o.cjs=!0:n.type==="esm"&&(o.esm=!0));const d=n.file.replace(W(n.file),"").replace(new RegExp(`^./${i.options.outDir.replace(/^\.\//,"")}/`),"");q.has(n.subKey)&&!s.includes(d)&&(o.fileAlias=d)},"createOrUpdateEntry");let U=!1;const z=T(t=>{if(t.pkg?.dependencies?.typescript===void 0&&t.pkg?.devDependencies?.typescript===void 0)throw new Error("You tried to use a `.ts`, `.cts` or `.mts` file but `typescript` was not found in your package.json.")},"validateIfTypescriptIsInstalled"),Oe=T((t,s,e)=>{const r=(e.options.outputExtensionMap?.cjs??"cjs").replaceAll(".",String.raw`\.`),n=(e.options.outputExtensionMap?.esm??"mjs").replaceAll(".",String.raw`\.`),i=[];s.sort((o,d)=>o.split("/").length-d.split("/").length);const p=t.type==="module"?"esm":"cjs";p==="esm"&&(e.options.emitESM=!0),p==="cjs"&&(e.options.emitCJS=!0);const m=we(t.exports,p,e.options.declaration,[],e.options.ignoreExportKeys).filter(o=>!o.ignored);if(t.bin){const o=(typeof t.bin=="string"?[t.bin]:Object.values(t.bin)).filter(Boolean);for(const d of o){const c=J(d);if(c&&c!==p)throw new Error(`Exported file "${d}" has an extension that does not match the package.json type "${t.type??"commonjs"}".`);m.push({file:d,isExecutable:!0,key:"bin",type:c??p})}}t.main&&m.push({file:t.main,key:"main",type:J(t.main)??p}),t.module&&m.push({file:t.module,key:"module",type:"esm"}),(t.types||t.typings)&&(z(e),e.options.declaration===void 0&&(e.options.declaration="compatible"),m.push({file:t.types??t.typings,key:"types"}));const y=[];for(const o of m){const d=W(o.file);if(d!==""&&!me.includes(d))continue;e.options.declaration===void 0&&(o.key==="types"||o.subKey==="types")&&(e.options.declaration=o.file.includes(".d.ts")?"compatible":!0),e.options.emitCJS===void 0&&o.type==="cjs"&&(e.options.emitCJS=!0),e.options.emitESM===void 0&&o.type==="esm"&&(e.options.emitESM=!0);const c=o.file.replace(new RegExp(String.raw`(?:\*[^/\\]|\.d\.[mc]?ts|\.\w+|${[`\\.${r}`,`\\.${n}`].join("|")})$`),""),l=c.endsWith("/");if(l&&["./","/"].includes(c))continue;const b=c.replace(new RegExp(`(./)?${e.options.outDir}`),e.options.sourceDir).replace("./",""),v="(?<=/|$)",a=l?"":String.raw`(\.d\.[cm]?ts|(\.[cm]?[tj]sx?)|${[`\\.${r}`,`\\.${n}`].join("|")})$`;if(o.file.includes("/*")&&o.key==="exports"){U||(e.logger.debug("Private subfolders are not supported, if you need this feature please open an issue on GitHub."),U=!0);const g=[],x=new RegExp(v+b.replace("*","(.*)")+a),L=b.replace(/^(.+?)\.[^.]*$/,"$1"),H=new RegExp(v+L.replace("*","(.*)")+a);for(const C of s)(x.test(C)||q.has(o.subKey)&&H.test(C))&&g.push(C);if(g.length===0){i.push(`Could not find entrypoint for \`${o.file}\``);continue}for(const C of g)P(y,C,l,c,o,e,!0);continue}const u=new RegExp(v+b+a);let f=s.find(g=>u.test(g));if(q.has(o.subKey)&&f===void 0){const g=b.replace(/^(.+?)\.[^.]*$/,"$1"),x=new RegExp(v+g+a);f=s.find(L=>x.test(L))}if(f===void 0){S(M(e.options.rootDir,o.file))||i.push(`Could not find entrypoint for \`${o.file}\``);continue}S(f)&&/\.[cm]?tsx?$/.test(f)&&z(e);const k=pe(f.replace(fe,""));S(`${k}.cts`)&&S(`${k}.mts`)?(P(y,`${k}.cts`,l,c,{...o,type:"cjs"},e,!1),P(y,`${k}.mts`,l,c,{...o,type:"esm"},e,!1)):P(y,f,l,c,o,e,!1)}return e.options.emitESM&&!e.options.emitCJS&&e.options.declaration===void 0&&(e.options.declaration="node16"),{entries:y,warnings:i}},"inferEntries");var Ne=Object.defineProperty,Ke=h((t,s)=>Ne(t,"name",{value:s,configurable:!0}),"o");const Ve=Ke((t,s)=>{const{publishConfig:e}=t;return e&&(e.bin&&(typeof e.bin=="object"||typeof e.bin=="string")&&(t.bin=e.bin),e.type&&typeof e.type=="string"&&e.type!==""&&(t.type=e.type),e.main&&typeof e.main=="string"&&e.main!==""&&(t.main=e.main),e.module&&typeof e.module=="string"&&e.module!==""&&(t.module=e.module),s===void 0&&e.types&&typeof e.types=="string"&&e.types!==""?t.types=e.types:s===void 0&&e.typings&&typeof e.typings=="string"&&e.typings!==""&&(t.typings=e.typings),e.exports&&typeof e.exports=="object"&&(t.exports=e.exports)),t},"overwriteWithPublishConfig");var qe=Object.defineProperty,Ae=h((t,s)=>qe(t,"name",{value:s,configurable:!0}),"t$1");const Ge={hooks:{"build:prepare":Ae(function(t){if(t.options.entries.length>0)return;const s=j(t.options.rootDir,t.options.sourceDir);if(!S(s))throw new Error("No 'src' directory found. Please provide entries manually.");const e=re(s,{extensions:[],includeDirs:!1,includeSymlinks:!1,skip:[/.*\/node_modules\/.*/,/.*\/dist\/.*/]});if(e.length===0)throw new Error("No source files found in 'src' directory. Please provide entries manually.");let r={...t.pkg};r.publishConfig&&(t.logger.info(`Using publishConfig found in package.json, to override the default key-value pairs of "${Object.keys(r.publishConfig).join(", ")}".`),t.logger.debug(r.publishConfig),r=Ve(r,t.options.declaration));const n=Oe(r,e,t);for(const i of n.warnings)he(t,i);if(t.options.entries.push(...n.entries),t.options.entries.length===0)throw new Error("No entries detected. Please provide entries manually.");t.logger.info("Automatically detected entries:",ve(t.options.entries.map(i=>i.fileAlias?`${O(i.fileAlias)} => ${O(i.input.replace(`${t.options.rootDir}/`,"").replace(/\/$/,"/*"))}`:O(i.input.replace(`${t.options.rootDir}/`,"").replace(/\/$/,"/*"))).join(", ")),be([t.options.emitESM&&"esm",t.options.emitCJS&&"cjs",t.options.declaration&&"dts"].filter(Boolean).map(i=>`[${i}]`).join(" ")))},"build:prepare")}};var Je=Object.defineProperty,Re=h((t,s)=>Je(t,"name",{value:s,configurable:!0}),"t");const Ue=Re(async(t,s)=>{if(t==="auto")t=Ge;else{if(t==="none")return{};typeof t=="string"&&(t=await s.import(t)||{})}return typeof t=="function"&&(t=t()),t},"loadPreset");var ze=Object.defineProperty,E=h((t,s)=>ze(t,"name",{value:s,configurable:!0}),"r");const Fe=E(t=>{t.addCommand({description:"Demonstrate options required",execute:E(async({logger:s,options:e})=>{let r="build";e.watch?r="watch":e.jit&&(r="jit");const n={};let i;if(e.env)for(const l of e.env)l.key==="NODE_ENV"?i=l.value:n[`process.env.${l.key}`]=JSON.stringify(l.value);i===void 0&&(e.production?i=I:e.development&&(i=V));const p=[];if(e.external)for(const l of e.external)p.push(l.split(","));const m=M(A(),e.dir??"."),y=ge(m,{debug:e.debug}),{config:o,path:d}=await Te(y,m,i,r,e.config??void 0);s.debug("Using packem config found at",d);const c=await Ue(o.preset??"auto",y);e.minify&&e.sourcemap===void 0&&(e.sourcemap=!0);try{await ke(m,r,i,s,e.debug,ye(o,c,{analyze:e.analyze,cjsInterop:e.cjsInterop,clean:e.clean,dtsOnly:e.dtsOnly,externals:p,killSignal:e.killSignal,minify:e.minify===void 0?i===I:e.minify,onSuccess:e.onSuccess,rollup:{esbuild:{target:e.target},license:{path:e.license},metafile:e.metafile,replace:{values:n},resolveExternals:e.noExternal?{builtins:!1,deps:!1,devDeps:!1,optDeps:!1,peerDeps:!1}:{}},runtime:e.runtime,sourcemap:e.metafile||e.analyze||e.sourcemap,validation:e.validation===!1?!1:{},...e.typedoc?{typedoc:{format:"html"}}:{}}),e.tsconfig??void 0)}catch(l){s.error(l),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:E(s=>{const[e,r]=s.split("=");return{key:e,value:r}},"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:E(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:E(s=>{if(s==="node"||s==="browser")return s;throw new Error("Invalid runtime. Use 'node' or 'browser'.")},"type")}]})},"createBuildCommand");var We=Object.defineProperty,D=h((t,s)=>We(t,"name",{value:s,configurable:!0}),"f");const _e=D(t=>{t.addCommand({description:"Initialize packem configuration",execute:D(async({logger:s,options:e})=>{if(te("Welcome to packem setup"),S(j(e.dir,"packem.config.mjs"))){s.info("Packem project already initialized, you can use `packem build` to build your project");return}const r=M(A(),e.dir??"."),n=j(r,"package.json");if(!S(n))throw new Error("No package.json found in the directory");const i=$e(n),p=[];i.dependencies&&p.push(...Object.keys(i.dependencies)),i.devDependencies&&p.push(...Object.keys(i.devDependencies));const m=!!(i.devDependencies?.typescript??i.dependencies?.typescript),y=[];if(e.typescript===void 0&&!m?(e.typescript=await w({message:"Do you want to install TypeScript?"}),e.typescript&&y.push("typescript@latest")):G.message(`TypeScript version ${i.devDependencies?.typescript??i.dependencies?.typescript} is already installed`),!S(j(r,"tsconfig.json"))){const a=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(a){const f=K();f.start("Generating tsconfig.json"),le(j(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:u?["es2022","dom","dom.iterable"]:["es2022"]}}),f.stop("")}}if(e.runtime===void 0&&(e.runtime=await $({message:"Pick a build runtime",options:[{label:"Node",value:"node"},{label:"Browser",value:"browser"}]})),p.includes("esbuild")?e.transformer="esbuild":p.includes("@swc/core")?e.transformer="swc":p.includes("sucrase")&&(e.transformer="sucrase"),e.transformer===void 0?(e.transformer=await $({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"&&!p.includes(e.transformer)&&await w({message:`Do you want to install ${e.transformer}?`})&&y.push(e.transformer==="swc"?"@swc/core":e.transformer)):G.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 $({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 a;switch(e.isolatedDeclarationTransformer){case"oxc":{a="oxc-transform";break}case"swc":{a="@swc/core";break}case"typescript":{a="typescript";break}default:se("Invalid isolated declaration transformer")}a!==void 0&&!p.includes(a)&&await w({message:`Do you want to install ${a}?`})&&y.push(a)}e.css===void 0&&(e.css=await w({message:"Do you want to use css in your project?",initialValue:!1}));const o=[];if(e.css){const a=await $({message:"Pick a css loader",options:[{label:"PostCSS",value:"postcss"},{hint:"experimental",label:"Lightning CSS",value:"lightningcss"}]});o.push(a);let u=await F({message:"Pick your loaders",options:[{label:"Sass",value:"sass"},{label:"Stylus",value:"stylus"},{label:"Less",value:"less"}],required:!1});if(u.includes("sass")){const f=await $({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"}]});f!=="sass"&&(u=u.filter(k=>k!=="sass"),u.push(f))}if(o.push(...u),await w({message:`Do you want to install "${o.join('", "')}"?`}))for(const f of o)y.push(...X[f]);o.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 $({message:"Pick a css minifier",options:[{label:"CSSNano",value:"cssnano"},{label:"Lightning CSS",value:"lightningcss"}]}),o.includes("lightningcss")||await w({message:`Do you want to install "${d}"?`})&&y.push(d));let c="",l="";if(e.isolatedDeclarationTransformer&&(l+=`,
|
|
29
|
-
isolatedDeclarationTransformer`),(e.css||e.cssMinifier)&&(
|
|
27
|
+
},`),o.start("Installing packages"),await q(b,{cwd:n,dev:!0,silent:!0}),o.stop("Installed packages"),e.success(`
|
|
28
|
+
CSS loaders added!`)}await je(l,a.toString(),{overwrite:!0})},"execute"),name:"add",options:[{defaultValue:".",description:"The directory to build",name:"dir",type:String},{description:"Use a custom config file",name:"config",type:String}]})},"createAddCommand");var Xe=Object.defineProperty,Ye=v((t,s)=>Xe(t,"name",{value:s,configurable:!0}),"e$1");const He=Ye(async(t,s,e,i,o)=>{const n=await le(s,o);let l=await t.import(n,{default:!0,try:!0})||{};return typeof l=="function"&&(l=await l(e,i)),{config:l,path:n}},"loadPackemConfig");var Ze=Object.defineProperty,S=v((t,s)=>Ze(t,"name",{value:s,configurable:!0}),"u$1");const z=new Map,Qe=/\.[^./]+$/,et=S(async t=>{try{return await Ke.readdir(t,{withFileTypes:!0})}catch(s){const{code:e}=s;if(e==="ENOENT")return[];throw s}},"safeReaddir"),de=S(async(t,s)=>{const e=await et(t);return(await Promise.all(e.map(async i=>{const o=Z.join(t,i.name);return i.isDirectory()?de(o,s):i.isFile()?Z.relative(s,o):[]}))).flat()},"getDirectoryFilesRecursive"),tt=S(async t=>{let s=z.get(t);return s||(s=de(t,t),z.set(t,s)),s},"getDirectoryFiles"),st=S((t,s)=>{const e=t.replace(Qe,"");if(s==="*"){const l=e.split("/");return l.length>0?[l[0]]:null}const i=s.replaceAll(/[.+?^${}()|[\]\\]/g,String.raw`\$&`).replaceAll("*","(.*)"),o=new RegExp(`^${i}$`),n=e.match(o);return n?n.slice(1):null},"matchWildcardPattern"),ot=S((t,s)=>{let e=t;for(const i of s)e=e.replace("*",i);return e},"substituteWildcards"),it=S((t,s)=>t.key==="exports"&&t.subKey===K?K:t.key==="exports"&&t.subKey===G?G:s,"getEnvironment"),A=S((t,s,e,i,o,n,l)=>{const r=it(o,n.environment);let u=n.options.runtime;for(const c of Ee)if(o.file.includes(`.${c}.`)||o.subKey===c){u=c;break}let a=t.find(c=>c.input===s&&c.environment===r&&c.runtime===u);a===void 0?a=t[t.push({environment:r,exportKey:new Set([o.exportKey].filter(Boolean)),input:s,runtime:u})-1]:a.exportKey&&o.exportKey&&a.exportKey.add(o.exportKey),l&&(a.isGlob=!0),e&&(a.outDir=i),o.isExecutable?(a.executable=!0,a.declaration=!1,o.type==="cjs"?a.cjs=!0:o.type==="esm"&&(a.esm=!0)):(/\.d\.[mc]?ts$/.test(o.file)&&n.options.declaration!==!1&&(a.declaration=n.options.declaration),o.type==="cjs"?a.cjs=!0:o.type==="esm"&&(a.esm=!0));const m=o.file.replace(ne(o.file),"").replace(new RegExp(`^./${n.options.outDir.replace(/^\.\//,"")}/`),"");re.has(o.subKey)&&!s.includes(m)&&(a.fileAlias=m)},"createOrUpdateEntry");let te=!1;const se=S(t=>{if(t.pkg?.dependencies?.typescript===void 0&&t.pkg?.devDependencies?.typescript===void 0)throw new Error("You tried to use a `.ts`, `.cts` or `.mts` file but `typescript` was not found in your package.json.")},"validateIfTypescriptIsInstalled"),nt=S(async(t,s,e)=>{const i=t.types||t.typings;z.clear();const o=(e.options.outputExtensionMap?.cjs??"cjs").replaceAll(".",String.raw`\.`),n=(e.options.outputExtensionMap?.esm??"mjs").replaceAll(".",String.raw`\.`),l=[];s.sort((c,d)=>c.split("/").length-d.split("/").length);const r=t.type==="module"?"esm":"cjs";r==="esm"&&(e.options.emitESM=!0),r==="cjs"&&(e.options.emitCJS=!0);const u=e.options.emitCJS&&e.options.emitESM;e.options.declaration===void 0&&(e.options.declaration=u?"compatible":"node16");const a=Be(t.exports,r,e.options.declaration,[],e.options.ignoreExportKeys).filter(c=>!c.ignored);if(t.bin){const c=(typeof t.bin=="string"?[t.bin]:Object.values(t.bin)).filter(Boolean);for(const d of c){const y=H(d);if(y&&y!==r)throw new Error(`Exported file "${d}" has an extension that does not match the package.json type "${t.type??"commonjs"}".`);a.push({file:d,isExecutable:!0,key:"bin",type:y??r})}}t.main&&a.push({file:t.main,key:"main",type:H(t.main)??r}),t.module&&a.push({file:t.module,key:"module",type:"esm"}),i&&(se(e),(e.options.declaration===void 0||e.options.declaration==="node16")&&u&&(e.options.declaration="compatible"),a.push({file:t.types??t.typings,key:"types"}));const m=[];for await(const c of a){const d=ne(c.file);if(d!==""&&!Me.includes(d))continue;if(e.options.emitCJS===void 0&&c.type==="cjs"&&(e.options.emitCJS=!0),e.options.emitESM===void 0&&c.type==="esm"&&(e.options.emitESM=!0),e.options.declaration===void 0||e.options.declaration==="node16"){const $=e.options.emitCJS&&e.options.emitESM;e.options.declaration=$?"compatible":"node16"}const y=c.file.replace(new RegExp(String.raw`(?:\*[^/\\]|\.d\.[mc]?ts|\.\w+|${[`\\.${o}`,`\\.${n}`].join("|")})$`),""),b=y.endsWith("/");if(b&&["./","/"].includes(y))continue;const f=y.replace(new RegExp(`(./)?${e.options.outDir}`),e.options.sourceDir).replace("./",""),p="(?<=/|$)",w=b?"":String.raw`(\.d\.[cm]?ts|(\.[cm]?[tj]sx?)|${[`\\.${o}`,`\\.${n}`].join("|")})$`;if((c.file.includes("/*")||y.includes("*"))&&c.key==="exports"){te||(e.logger.debug("Private subfolders are not supported, if you need this feature please open an issue on GitHub."),te=!0);let $;c.exportKey?$=c.exportKey.startsWith("./")?c.exportKey.slice(2):c.exportKey:$=(c.file.startsWith("./")?c.file.slice(2):c.file).replace(/^dist\//,"");const N=c.file,F=e.options.sourceDir.replace(/^\.\//,""),_=E(e.options.rootDir,F),R=[],ue=await tt(_);for(const B of ue){const L=st(B,$);if(L){const J=ot(N,L);R.push({input:E(_,B),output:J})}}if(R.length===0){l.push(`Could not find entrypoints matching pattern \`${$}\` for output \`${N}\``);continue}for(const{input:B,output:L}of R){const J={...c,file:L};A(m,B,b,y,J,e,!0)}continue}const g=new RegExp(p+f+w);let k=s.find($=>g.test($));if(re.has(c.subKey)&&k===void 0){const $=f.replace(/^(.+?)\.[^.]*$/,"$1"),N=new RegExp(p+$+w);k=s.find(F=>N.test(F))}if(k===void 0){x(E(e.options.rootDir,c.file))||l.push(`Could not find entrypoint for \`${c.file}\``);continue}x(k)&&/\.[cm]?tsx?$/.test(k)&&se(e);const D=Ce(k.replace(Pe,""));x(`${D}.cts`)&&x(`${D}.mts`)?(A(m,`${D}.cts`,b,y,{...c,type:"cjs"},e,!1),A(m,`${D}.mts`,b,y,{...c,type:"esm"},e,!1)):A(m,k,b,y,c,e,!1)}return{entries:m,warnings:l}},"inferEntries");var rt=Object.defineProperty,at=v((t,s)=>rt(t,"name",{value:s,configurable:!0}),"o");const ct=at((t,s)=>{const{publishConfig:e}=t;return e&&(e.bin&&(typeof e.bin=="object"||typeof e.bin=="string")&&(t.bin=e.bin),e.type&&typeof e.type=="string"&&e.type!==""&&(t.type=e.type),e.main&&typeof e.main=="string"&&e.main!==""&&(t.main=e.main),e.module&&typeof e.module=="string"&&e.module!==""&&(t.module=e.module),s===void 0&&e.types&&typeof e.types=="string"&&e.types!==""?t.types=e.types:s===void 0&&e.typings&&typeof e.typings=="string"&&e.typings!==""&&(t.typings=e.typings),e.exports&&typeof e.exports=="object"&&(t.exports=e.exports)),t},"overwriteWithPublishConfig");var lt=Object.defineProperty,pt=v((t,s)=>lt(t,"name",{value:s,configurable:!0}),"p");const dt={hooks:{"build:prepare":pt(async function(t){if(t.options.unbundle){t.options.entries.length=0;const o=C(t.options.rootDir,t.options.sourceDir);if(!x(o))throw new Error("No 'src' directory found. Please provide entries manually.");const n=Y(o,{extensions:[],includeDirs:!1,includeSymlinks:!1,skip:[/.*\/node_modules\/.*/,/.*\/dist\/.*/]}).filter(l=>/\.(ts|tsx|js|jsx|mts|cts|mjs|cjs)$/.test(l)&&!l.endsWith(".d.ts"));for(const l of n){const r=l.replace(`${o}/`,"").replace(/\.(ts|tsx|js|jsx|mts|cts|mjs|cjs)$/,"").replaceAll("/","/");t.options.entries.push({input:l,name:r})}return}if(t.options.entries.length>0)return;const s=C(t.options.rootDir,t.options.sourceDir);if(!x(s))throw new Error("No 'src' directory found. Please provide entries manually.");const e=Y(s,{extensions:[],includeDirs:!1,includeSymlinks:!1,skip:[/.*\/node_modules\/.*/,/.*\/dist\/.*/]});if(e.length===0)throw new Error("No source files found in 'src' directory. Please provide entries manually.");let i={...t.pkg};if(i.publishConfig&&(t.logger.info(`Using publishConfig found in package.json, to override the default key-value pairs of "${Object.keys(i.publishConfig).join(", ")}".`),t.logger.debug(i.publishConfig),i=ct(i,t.options.declaration)),t.options.unbundle){t.logger.info("Unbundle mode detected, creating entries for all source files");const o=e.filter(n=>/\.(ts|tsx|js|jsx|mts|cts|mjs|cjs)$/.test(n)&&!n.endsWith(".d.ts"));t.logger.info(`Found ${o.length} code files for unbundle mode`);for(const n of o){const l=n.replace(`${s}/`,"").replace(/\.(ts|tsx|js|jsx|mts|cts|mjs|cjs)$/,"").replaceAll("/","/");t.logger.info(`Adding entry: ${l} -> ${n}`),t.options.entries.push({input:n,name:l})}}else{const o=await nt(i,e,t);for(const n of o.warnings)Le(t,n);t.options.entries.push(...o.entries)}if(t.options.entries.length===0)throw new Error("No entries detected. Please provide entries manually.");t.logger.info("Automatically detected entries:",Te(t.options.entries.map(o=>o.fileAlias?`${V(o.fileAlias)} => ${V(o.input.replace(`${t.options.rootDir}/`,"").replace(/\/$/,"/*"))}`:V(o.input.replace(`${t.options.rootDir}/`,"").replace(/\/$/,"/*"))).join(", ")),Ne([t.options.emitESM&&"esm",t.options.emitCJS&&"cjs",t.options.declaration&&"dts"].filter(Boolean).map(o=>`[${o}]`).join(" ")))},"build:prepare")}};var ut=Object.defineProperty,mt=v((t,s)=>ut(t,"name",{value:s,configurable:!0}),"t");const ft=mt(async(t,s)=>{if(t==="auto")t=dt;else{if(t==="none")return{};typeof t=="string"&&(t=await s.import(t)||{})}return typeof t=="function"&&(t=t()),t},"loadPreset");var gt=Object.defineProperty,O=v((t,s)=>gt(t,"name",{value:s,configurable:!0}),"r");const yt=O(t=>{t.addCommand({description:"Demonstrate options required",execute:O(async({logger:s,options:e})=>{let i="build";e.watch?i="watch":e.jit&&(i="jit");const o={};let n;if(e.env)for(const d of e.env)d.key==="NODE_ENV"?n=d.value:o[`process.env.${d.key}`]=JSON.stringify(d.value);n===void 0&&(e.production?n=K:e.development&&(n=G));const l=[];if(e.external)for(const d of e.external)l.push(d.split(","));const r=E(W(),e.dir??"."),u=Ie(r,{debug:e.debug}),{config:a,path:m}=await He(u,r,n,i,e.config??void 0);s.debug("Using packem config found at",m);const c=await ft(a.preset??"auto",u);e.minify&&e.sourcemap===void 0&&(e.sourcemap=!0);try{await Ae(r,i,n,s,e.debug,Oe(a,c,{analyze:e.analyze,cjsInterop:e.cjsInterop,clean:e.clean,dtsOnly:e.dtsOnly,externals:l,killSignal:e.killSignal,minify:e.minify===void 0?n===K:e.minify,onSuccess:e.onSuccess,rollup:{esbuild:{target:e.target},license:{path:e.license},metafile:e.metafile,replace:{values:o},resolveExternals:e.noExternal?{builtins:!1,deps:!1,devDeps:!1,optDeps:!1,peerDeps:!1}:{}},runtime:e.runtime,sourcemap:e.metafile||e.analyze||e.sourcemap,unbundle:e.unbundle,validation:e.validation===!1?!1:{},...e.typedoc?{typedoc:{format:"html"}}:{}}),e.tsconfig??void 0)}catch(d){s.error(d),be(1)}},"execute"),name:"build",options:[{defaultValue:".",description:"The directory to build",name:"dir",type:String},{alias:"t",description:"Environments to support. `target` in tsconfig.json is automatically added. Defaults to the current Node.js version.",name:"target"},{description:"Use a custom config file",name:"config",type:String},{description:"Path to the tsconfig.json file",name:"tsconfig",type:String},{description:"Minify the output",name:"minify",type:Boolean},{description:"Generate sourcemaps (experimental)",name:"sourcemap",type:Boolean},{conflicts:"jit",description:"Watch for changes",name:"watch",type:Boolean},{conflicts:"watch",description:"Stub the package for JIT compilation",name:"jit",type:Boolean},{description:"Compile-time environment variables (eg. --env.NODE_ENV=production)",multiple:!0,name:"env",type:O(s=>{const[e,i]=s.split("=");return{key:e,value:i}},"type")},{defaultValue:!1,description:"Generate meta file (experimental)",name:"metafile",type:Boolean},{description:"Path to the license file",name:"license",type:String},{conflicts:"watch",description:"Visualize and analyze the bundle",name:"analyze",type:Boolean},{description:"CJS interop mode, can export default and named export, (experimental).",name:"cjsInterop",type:Boolean},{conflicts:"development",description:"Run code in production environment",name:"production",type:Boolean},{conflicts:"production",description:"Run code in development environment",name:"development",type:Boolean},{description:"Do not clean the dist directory before building",name:"no-clean",type:Boolean},{description:"Only generate .d.ts files",name:"dts-only",type:Boolean},{description:"Disable the output validation",name:"no-validation",type:Boolean},{description:"Disable the cache",name:"no-cache",type:Boolean},{description:"Generate type documentation",name:"typedoc",type:Boolean},{description:"Execute command after successful build, specially useful for watch mode",name:"onSuccess",type:String},{description:'Signal to kill child process, "SIGTERM" or "SIGKILL"',name:"killSignal",type:O(s=>{if(s==="SIGTERM"||s==="SIGKILL")return s;throw new Error("Invalid kill signal. Use 'SIGTERM' or 'SIGKILL'.")},"type")},{description:"Specify an external dependency, separate by comma (eg. --external lodash,react,react-dom)",multiple:!0,name:"external",typeLabel:"string[]"},{description:"do not bundle external dependencies",name:"no-external",type:Boolean},{description:"Specify the build runtime (nodejs, browser).",name:"runtime",type:O(s=>{if(s==="node"||s==="browser")return s;throw new Error("Invalid runtime. Use 'node' or 'browser'.")},"type")},{description:"Enable unbundle mode to preserve source file structure instead of bundling into a single file",name:"unbundle",type:Boolean}]})},"createBuildCommand");var bt=Object.defineProperty,I=v((t,s)=>bt(t,"name",{value:s,configurable:!0}),"f");const wt=I(t=>{t.addCommand({description:"Initialize packem configuration",execute:I(async({logger:s,options:e})=>{if(we("Welcome to packem setup"),x(C(e.dir,"packem.config.mjs"))){s.info("Packem project already initialized, you can use `packem build` to build your project");return}const i=E(W(),e.dir??"."),o=C(i,"package.json");if(!x(o))throw new Error("No package.json found in the directory");const n=await Je(o,{resolveCatalogs:!0}),l=[];n.dependencies&&l.push(...Object.keys(n.dependencies)),n.devDependencies&&l.push(...Object.keys(n.devDependencies));const r=!!(n.devDependencies?.typescript??n.dependencies?.typescript),u=[];if(e.typescript===void 0&&!r?(e.typescript=await h({message:"Do you want to install TypeScript?"}),e.typescript&&u.push("typescript@latest")):X.message(`TypeScript version ${n.devDependencies?.typescript??n.dependencies?.typescript} is already installed`),!x(C(i,"tsconfig.json"))){const f=await h({message:"Do you want to use generate a tsconfig.json?"}),p=await h({message:"Do you want to run your code in the DOM?"});if(f){const w=U();w.start("Generating tsconfig.json"),xe(C(i,"tsconfig.json"),{compilerOptions:{esModuleInterop:!0,skipLibCheck:!0,target:"es2022",allowJs:!0,resolveJsonModule:!0,moduleDetection:"force",isolatedModules:!0,verbatimModuleSyntax:!0,strict:!0,noUncheckedIndexedAccess:!0,noImplicitOverride:!0,module:"NodeNext",outDir:"dist",sourceMap:!0,declaration:!0,lib:p?["es2022","dom","dom.iterable"]:["es2022"]}}),w.stop("")}}if(e.runtime===void 0&&(e.runtime=await j({message:"Pick a build runtime",options:[{label:"Node",value:"node"},{label:"Browser",value:"browser"}]})),l.includes("esbuild")?e.transformer="esbuild":l.includes("@swc/core")?e.transformer="swc":l.includes("sucrase")&&(e.transformer="sucrase"),e.transformer===void 0?(e.transformer=await j({message:"Pick a transformer",options:[{label:"esbuild",value:"esbuild"},{label:"swc",value:"swc"},{label:"Sucrase",value:"sucrase"},{label:"OXC",value:"oxc"}]}),e.transformer&&e.transformer!=="oxc"&&!l.includes(e.transformer)&&await h({message:`Do you want to install ${e.transformer}?`})&&u.push(e.transformer==="swc"?"@swc/core":e.transformer)):X.message(`Transformer ${e.transformer} is already installed.`),e.isolatedDeclarationTransformer===void 0&&(e.isolatedDeclarationTransformer=await h({message:"Do you want to use an isolated declaration types?",initialValue:!1})),e.isolatedDeclarationTransformer===void 0&&(e.isolatedDeclarationTransformer=await j({message:"Pick a isolated declaration transformer",options:[{label:"Typescript",value:"typescript"},{label:"swc",value:"swc"},{label:"OXC",value:"oxc"},{label:"None",value:void 0}]}),e.isolatedDeclarationTransformer!==void 0)){let f;switch(e.isolatedDeclarationTransformer){case"oxc":{f="oxc-transform";break}case"swc":{f="@swc/core";break}case"typescript":{f="typescript";break}default:ve("Invalid isolated declaration transformer")}f!==void 0&&!l.includes(f)&&await h({message:`Do you want to install ${f}?`})&&u.push(f)}e.css===void 0&&(e.css=await h({message:"Do you want to use css in your project?",initialValue:!1}));const a=[];if(e.css){const f=await j({message:"Pick a css loader",options:[{label:"PostCSS",value:"postcss"},{hint:"experimental",label:"Lightning CSS",value:"lightningcss"}]});a.push(f);let p=await ie({message:"Pick your loaders",options:[{label:"Sass",value:"sass"},{label:"Stylus",value:"stylus"},{label:"Less",value:"less"}],required:!1});if(p.includes("sass")){const w=await j({message:"Pick a sass loader",options:[{label:"Sass embedded",value:"sass-embedded",hint:"recommended"},{label:"Sass",value:"sass"},{label:"Node Sass",value:"node-sass",hint:"legacy"}]});w!=="sass"&&(p=p.filter(g=>g!=="sass"),p.push(w))}if(a.push(...p),await h({message:`Do you want to install "${a.join('", "')}"?`}))for(const w of a)u.push(...pe[w]);a.push("sourceMap")}e.cssMinifier===void 0&&(e.cssMinifier=await h({message:"Do you want to minify your css?",initialValue:!1}));let m;e.cssMinifier&&(m=await j({message:"Pick a css minifier",options:[{label:"CSSNano",value:"cssnano"},{label:"Lightning CSS",value:"lightningcss"}]}),a.includes("lightningcss")||await h({message:`Do you want to install "${m}"?`})&&u.push(m));let c="",d="";if(e.isolatedDeclarationTransformer&&(d+=`,
|
|
29
|
+
isolatedDeclarationTransformer`),(e.css||e.cssMinifier)&&(d+=`,
|
|
30
30
|
rollup: {
|
|
31
|
-
css: {`),e.css){const a
|
|
32
|
-
loaders: [${
|
|
33
|
-
minifier: ${
|
|
31
|
+
css: {`),e.css){const f=a.map(p=>((p==="sass-embedded"||p==="node-sass")&&(p="sass"),`${p}Loader`)).join(", ");d+=`
|
|
32
|
+
loaders: [${f}],`}if(e.cssMinifier&&m&&(d+=`
|
|
33
|
+
minifier: ${m}Minifier,`),(e.css||e.cssMinifier)&&(d+=`
|
|
34
34
|
}
|
|
35
|
-
}`),
|
|
36
|
-
`),e.css)for(let
|
|
37
|
-
`;e.cssMinifier&&
|
|
35
|
+
}`),r||n.type==="module"){let f="";if(e.isolatedDeclarationTransformer&&(f+=`import isolatedDeclarationTransformer from "@visulima/packem/dts/isolated/transformer/${e.isolatedDeclarationTransformer}";
|
|
36
|
+
`),e.css)for(let p of a)(p==="sass-embedded"||p==="node-sass")&&(p="sass"),f+=`import ${p}Loader from "@visulima/packem/css/loader/${p.toLowerCase()}";
|
|
37
|
+
`;e.cssMinifier&&m&&(f+=`import ${m}Minifier from "@visulima/packem/css/minifier/${m.toLowerCase()}";
|
|
38
38
|
`),c=`import { defineConfig } from "@visulima/packem/config";
|
|
39
39
|
import transformer from "@visulima/packem/transformer/${e.transformer}";
|
|
40
|
-
${
|
|
40
|
+
${f}
|
|
41
41
|
export default defineConfig({
|
|
42
42
|
runtime: "${e.runtime}",
|
|
43
|
-
transformer${
|
|
43
|
+
transformer${d}
|
|
44
44
|
});
|
|
45
|
-
`}else{let
|
|
46
|
-
`),e.css)for(let
|
|
47
|
-
`;e.cssMinifier&&
|
|
45
|
+
`}else{let f="";if(e.isolatedDeclarationTransformer&&(f+=`const isolatedDeclarationTransformer = require("@visulima/packem/dts/isolated/transformer/${e.isolatedDeclarationTransformer}");
|
|
46
|
+
`),e.css)for(let p of a)(p==="sass-embedded"||p==="node-sass")&&(p="sass"),f+=`const ${p}Loader = require("@visulima/packem/css/loader/${p.toLowerCase()}");
|
|
47
|
+
`;e.cssMinifier&&m&&(f+=`const ${m}Minifier = require("@visulima/packem/css/minifier/${m.toLowerCase()}");
|
|
48
48
|
`),c=`const { defineConfig } = require("@visulima/packem/config");
|
|
49
49
|
const transformer = require("@visulima/packem/transformer/${e.transformer}");
|
|
50
|
-
${
|
|
50
|
+
${f}
|
|
51
51
|
module.exports = defineConfig({
|
|
52
52
|
runtime: ${e.runtime},
|
|
53
|
-
transformer${
|
|
53
|
+
transformer${d}
|
|
54
54
|
});
|
|
55
|
-
`}const
|
|
55
|
+
`}const y=U(),b=r?"ts":"js";u.length>0&&(y.start("Installing packages"),await q(u,{cwd:i,dev:!0,silent:!0}),y.stop("Installed packages")),y.start(`Creating packem.config.${b}`),Se(C(i,`packem.config.${b}`),c),y.stop(`Created packem.config.${b}`),he("Now you can run `packem build` to build your project")},"execute"),name:"init",options:[{defaultValue:".",description:"The directory to initialize",name:"dir",type:String},{description:"Choose a transformer",name:"transformer",type:I(s=>{if(typeof s=="string"&&["esbuild","sucrase","swc"].includes(s))return s;throw new Error("Invalid transformer, please choose one of 'swc', 'sucrase' or 'esbuild'")},"type")},{description:"Choose a isolated declaration transformer",name:"isolated-declaration-transformer",type:I(s=>{if(typeof s=="string"&&["none","oxc","swc","typescript"].includes(s))return s;throw new Error("Invalid isolated declaration isolated declaration, please choose one of 'none', 'oxc', 'swc' or 'typescript'")},"type")},{description:"Use CSS",name:"css",type:Boolean},{description:"Use CSS minifier",name:"css-minifier",type:Boolean},{Description:"Use TypeScript",name:"typescript",type:Boolean},{description:"Specify the build runtime (nodejs, browser).",name:"runtime",type:I(s=>{if(s==="node"||s==="browser")return s;throw new Error("Invalid runtime. Use 'node' or 'browser'.")},"type")}]})},"createInitCommand");var vt=Object.defineProperty,M=v((t,s)=>vt(t,"name",{value:s,configurable:!0}),"a");const ht=M(async({cwd:t,dryRun:s,logger:e})=>{if(s)e.info("Dry run enabled. No changes will be made.");else{const o=Ve({input:P.stdin,output:P.stdout});e.warn(`
|
|
56
|
+
|
|
57
|
+
Before proceeding, review the migration guide at https://www.visulima.com/docs/package/packem, as this process will modify your files.
|
|
58
|
+
Uncommitted changes will be lost. Use the --dry-run flag to preview changes without applying them.`);const n=await o.question("Continue? (Y/n) ");if(o.close(),!(n.toLowerCase()==="y"||n==="")){e.error("Migration cancelled."),P.exitCode=1;return}}t&&P.chdir(t);let i=!1;await $t(s,e)&&(i=!0),await xt(s,e)&&(i=!0),i?e.success("Migration completed. Remember to run install command with your package manager."):(e.error("No migration performed."),P.exitCode=1)},"migrate"),oe={bunchee:"@visulima/packem",tsup:"@visulima/packem","tsup-node":"@visulima/packem",unbuild:"@visulima/packem"},kt={dependencies:`^${Q.version}`,devDependencies:`^${Q.version}`,peerDependencies:"*"},$t=M(async(t,s)=>{if(!ae("package.json"))return s.error("No package.json found"),!1;const e=await Fe("package.json","utf8"),i=JSON.parse(e);let o=!1;for(const[r,u]of Object.entries(kt))for(const[a,m]of Object.entries(oe))i[r]?.[a]&&(s.info(`Migrating \`${r}\` from ${a} to ${m}.`),o=!0,i[r]=St(i[r],a,m,u));if(i.scripts)for(const r of Object.keys(i.scripts)){for(const[u,a]of Object.entries(oe))i.scripts[r].includes(u)&&(s.info(`Migrating \`${r}\` script from ${u} to packem`),o=!0,i.scripts[r]=i.scripts[r].replaceAll(new RegExp(`\\b${u}\\b`,"g"),"packem").replaceAll(new RegExp(`\\b${u}-node\\b`,"g"),"packem"));i.scripts[r].includes("tsup")&&(s.info(`Migrating \`${r}\` script from tsup to packem`),o=!0,i.scripts[r]=i.scripts[r].replaceAll(/\btsup(?:-node)?/g,"packem build").replaceAll(/\bbuild\b/g,"build")),i.scripts[r].includes("unbuild")&&(s.info(`Migrating \`${r}\` script from unbuild to packem`),o=!0,i.scripts[r]=i.scripts[r].replaceAll(/\bunbuild\b/g,"packem build")),i.scripts[r].includes("bunchee")&&(s.info(`Migrating \`${r}\` script from bunchee to packem`),o=!0,i.scripts[r]=i.scripts[r].replaceAll(/\bbunchee\b/g,"packem build"))}const n=["tsup","unbuild","bunchee"];for(const r of n)i[r]&&s.info(`Found \`${r}\` config field in package.json. Consider moving to packem.config.ts`);if(!o)return s.warn("No migratable bundler dependencies found in package.json"),!1;const l=`${JSON.stringify(i,null,e.includes(" ")?" ":2)}
|
|
59
|
+
`;return t?(s.info("[dry-run] package.json changes:"),s.info("Old content:"),console.info(e),s.info("New content:"),console.info(l)):(await Re("package.json",l),s.success("Migrated `package.json`")),!0},"migratePackageJson"),jt=["tsup.config.ts","tsup.config.cts","tsup.config.mts","tsup.config.js","tsup.config.cjs","tsup.config.mjs","tsup.config.json","build.config.ts","build.config.cts","build.config.mts","build.config.js","build.config.cjs","build.config.mjs","bunchee.config.ts","bunchee.config.cts","bunchee.config.mts","bunchee.config.js","bunchee.config.cjs","bunchee.config.mjs"],xt=M(async(t,s)=>{let e=!1;for(const i of jt)ae(i)&&(s.info(`Found config file \`${i}\`. Consider creating packem.config.ts instead.`),s.warn("Manual migration required for config files. See https://www.visulima.com/docs/package/packem"),e=!0);return e||s.warn("No bundler config files found"),e},"migrateConfigFiles"),St=M((t,s,e,i)=>{const o={};for(const n of Object.keys(t))n===s?o[e]=i||t[s]:o[n]=t[n];return o},"renameKey"),Ct=M(t=>{t.addCommand({description:"Migrate from other bundlers (tsup, unbuild, bunchee, etc.) to packem",execute:M(async({logger:s,options:e})=>{await ht({cwd:e.cwd,dryRun:e.dryRun,logger:s})},"execute"),name:"migrate",options:[{defaultValue:".",description:"The directory to migrate",name:"cwd",type:String},{description:"Preview changes without applying them",name:"dry-run",type:Boolean}]})},"createMigrateCommand");try{require("node:module")?.enableCompileCache?.()||require("v8-compile-cache")}catch{}const T=fe("packem",{logger:await ge({reporters:[new ye({error:{hideErrorCauseCodeView:!0,hideErrorCodeView:!0,hideErrorErrorsCodeView:!0}})],scope:"packem"}),packageName:qe,packageVersion:ce});wt(T);yt(T);_e(T);Ct(T);T.run({shouldExitProcess:!1});
|
package/dist/config/index.d.ts
CHANGED
|
@@ -1,28 +1,48 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
declare const defineConfig: (config: BuildConfig | BuildConfigFunction) => BuildConfig | BuildConfigFunction;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
import type { BuildConfig, BuildConfigFunction, BuildPreset } from "../types.d.ts";
|
|
2
|
+
export type { BuildConfig, BuildConfigFunction, BuildPreset } from "../types.d.ts";
|
|
3
|
+
export type { BuildHooks } from "@visulima/packem-share/types";
|
|
4
|
+
/**
|
|
5
|
+
* Defines a build configuration for Packem.
|
|
6
|
+
* Supports both static configuration objects and dynamic configuration functions.
|
|
7
|
+
* @param config Static build configuration object or function returning configuration
|
|
8
|
+
* @returns The provided configuration
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* // Static configuration
|
|
12
|
+
* export default defineConfig({
|
|
13
|
+
* entries: ['./src/index.ts'],
|
|
14
|
+
* outDir: './dist'
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* // Dynamic configuration
|
|
18
|
+
* export default defineConfig((env, mode) => ({
|
|
19
|
+
* entries: ['./src/index.ts'],
|
|
20
|
+
* outDir: env === 'production' ? './dist' : './dev'
|
|
21
|
+
* }));
|
|
22
|
+
* ```
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export declare const defineConfig: (config: BuildConfig | BuildConfigFunction) => BuildConfig | BuildConfigFunction;
|
|
26
|
+
/**
|
|
27
|
+
* Defines a build preset for Packem.
|
|
28
|
+
* Build presets provide reusable configuration templates that can be shared across projects.
|
|
29
|
+
* @param preset Build preset configuration
|
|
30
|
+
* @returns The provided preset configuration
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* export default definePreset({
|
|
34
|
+
* name: 'my-preset',
|
|
35
|
+
* defaults: {
|
|
36
|
+
* entries: ['./src/index.ts'],
|
|
37
|
+
* outDir: './dist'
|
|
38
|
+
* },
|
|
39
|
+
* hooks: {
|
|
40
|
+
* 'build:before': (context) => {
|
|
41
|
+
* // Custom build preparation logic
|
|
42
|
+
* }
|
|
43
|
+
* }
|
|
44
|
+
* });
|
|
45
|
+
* ```
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
export declare const definePreset: (preset: BuildPreset) => BuildPreset;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PackageJson } from "@visulima/package";
|
|
2
|
+
import type { BuildContext } from "@visulima/packem-share/types";
|
|
3
|
+
import type { InferEntriesResult, InternalBuildOptions } from "../../../types.d.ts";
|
|
4
|
+
/**
|
|
5
|
+
* Infer entries from package files.
|
|
6
|
+
* @param packageJson
|
|
7
|
+
* @param sourceFiles A list of source files to use for inferring entries.
|
|
8
|
+
* @param context
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
declare const inferEntries: (packageJson: PackageJson, sourceFiles: string[], context: BuildContext<InternalBuildOptions>) => Promise<InferEntriesResult>;
|
|
12
|
+
export default inferEntries;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { NormalizedPackageJson } from "@visulima/package";
|
|
2
|
+
import type { BuildConfig } from "../../../types.d.ts";
|
|
3
|
+
declare const overwriteWithPublishConfig: (packageJson: NormalizedPackageJson, declaration?: BuildConfig["declaration"]) => NormalizedPackageJson;
|
|
4
|
+
export default overwriteWithPublishConfig;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Jiti } from "jiti";
|
|
2
|
+
import type { BuildConfig, Environment, Mode } from "../../types.d.ts";
|
|
3
|
+
declare const loadPackemConfig: (jiti: Jiti, rootDirectory: string, environment: Environment, mode: Mode, configPath?: string) => Promise<{
|
|
4
|
+
config: BuildConfig;
|
|
5
|
+
path: string;
|
|
6
|
+
}>;
|
|
7
|
+
export default loadPackemConfig;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { NormalizedPackageJson } from "@visulima/package";
|
|
2
|
+
import type { Pail } from "@visulima/pail";
|
|
3
|
+
import type { TsConfigResult } from "@visulima/tsconfig";
|
|
4
|
+
declare const loadTsconfig: (rootDirectory: string, packageJson: NormalizedPackageJson, logger: Pail, tsconfigPath?: string) => Promise<TsConfigResult | undefined>;
|
|
5
|
+
export default loadTsconfig;
|