@10up/wp-vite-plugins 1.0.0-alpha.3 → 1.0.0-alpha.4

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/dist/index.d.ts CHANGED
@@ -1,201 +1,246 @@
1
- import { Plugin } from 'vite';
2
-
1
+ import { Plugin } from "vite";
3
2
  /**
4
- * Enables generation of the `@wordpress/build`-style PHP layer next to the
5
- * built modules — `build.php`, `constants.php`, `pages.php`,
6
- * `pages/<slug>/page{,-wp-admin}.php`, `routes.php` and
7
- * `routes/registry.php`. A consuming plugin then needs no hand-written PHP
8
- * beyond `require_once __DIR__ . '/dist/build.php';`.
3
+ * Name of the PHP bridge's bootstrap, relative to the resolved `build.outDir`.
4
+ *
5
+ * Written by *both* halves of this module: `wpDevServerPhp` emits it into every
6
+ * build so a consumer's `require_once` is never a dead path, and `wpDevServer`
7
+ * writes the identical bytes on server start so a `dist/` that has never been
8
+ * built still bridges.
9
+ */
10
+ export declare const DEV_SERVER_PHP_NAME = "dev-server.php";
11
+ /**
12
+ * Enables the `@wordpress/build`-style PHP layer next to the built modules:
13
+ * `build.php` (the pages as data) and the `wp-boot/` classes it
14
+ * loads. A consuming plugin then needs no hand-written PHP beyond
15
+ * `require_once __DIR__ . '/dist/build.php';`.
9
16
  */
10
17
  interface WpAdminPagesPhpOptions {
11
- /**
12
- * Identifier prefix for every generated function, global and hook.
13
- * Default: `wpPlugin.name` from the consumer's package.json, else its
14
- * (de-scoped) package name. Dashes are underscored for PHP identifiers;
15
- * the result must be a valid PHP identifier fragment.
16
- */
17
- prefix?: string;
18
- /**
19
- * Script Module id prefix — route modules are registered as
20
- * `<handlePrefix>/routes/<page>/<route>/{content,route}`.
21
- * Default: `wpPlugin.handlePrefix`, else `prefix`.
22
- */
23
- handlePrefix?: string;
24
- /**
25
- * Raw PHP expression for the URL of the build directory, interpolated
26
- * into `constants.php` verbatim. Default `plugin_dir_url( __FILE__ )`
27
- * (`build.php` and friends live in the build directory itself).
28
- */
29
- baseUrl?: string;
30
- /** Text domain for the generated `__()` calls. Default `'default'`. */
31
- textdomain?: string;
18
+ /**
19
+ * Project prefix: names the generated functions and the PHP namespace.
20
+ * Default: `wpPlugin.name` from the consumer's package.json, else its
21
+ * (de-scoped) package name. Dashes are underscored for PHP identifiers;
22
+ * the result must be a valid PHP identifier fragment.
23
+ */
24
+ prefix?: string;
25
+ /**
26
+ * Script Module id prefix — route modules are registered as
27
+ * `<handlePrefix>/routes/<page>/<route>/{content,route}`.
28
+ * Default: `wpPlugin.handlePrefix`, else `prefix`.
29
+ */
30
+ handlePrefix?: string;
31
+ /**
32
+ * Raw PHP expression for the URL of the build directory, interpolated
33
+ * into `build.php` verbatim and evaluated on first use. Default
34
+ * `plugin_dir_url( __FILE__ )` (`build.php` lives in the build directory).
35
+ */
36
+ baseUrl?: string;
37
+ /** Text domain for the menu title's `__()` call. Default `'default'`. */
38
+ textdomain?: string;
32
39
  }
33
40
  interface WpAdminPagesOptions {
34
- /**
35
- * Directory whose immediate subdirectories are pages. A subdirectory is
36
- * a page when it contains a `content.{tsx,ts,jsx,js}` entry; a sibling
37
- * `route.{tsx,ts,jsx,js}` is picked up when present, as are additional
38
- * routes under `<page>/routes/<name>/`.
39
- */
40
- adminPagesDir: string;
41
- /**
42
- * Admin pages are Script Modules, so they only build in the module pass.
43
- * In `'script'` mode (the default, matching the other plugins) this
44
- * plugin contributes nothing.
45
- */
46
- buildType?: 'script' | 'module';
47
- /**
48
- * Generate the PHP registration layer. Presence enables it; every key
49
- * is optional.
50
- */
51
- php?: WpAdminPagesPhpOptions;
52
- /**
53
- * Root whose `package.json` supplies the generated `version` and the
54
- * `wpPlugin.name` / `wpPlugin.handlePrefix` defaults. Defaults to Vite's
55
- * `root`, else `process.cwd()`.
56
- */
57
- projectRoot?: string;
41
+ /**
42
+ * Directory whose immediate subdirectories are pages. A subdirectory is
43
+ * a page when it contains a `content.{tsx,ts,jsx,js}` entry; a sibling
44
+ * `route.{tsx,ts,jsx,js}` is picked up when present, as are additional
45
+ * routes under `<page>/routes/<name>/`.
46
+ */
47
+ adminPagesDir: string;
48
+ /**
49
+ * Generate the PHP registration layer. Presence enables it; every key
50
+ * is optional.
51
+ */
52
+ php?: WpAdminPagesPhpOptions;
53
+ /**
54
+ * Root whose `package.json` supplies the `wpPlugin.name` /
55
+ * `wpPlugin.handlePrefix` defaults. Defaults to Vite's `root`, else
56
+ * `process.cwd()`.
57
+ */
58
+ projectRoot?: string;
59
+ }
60
+ /**
61
+ * Admin pages are Script Modules: they build in the `modules` environment
62
+ * (see `wpEnvironments`) and contribute nothing to `client`.
63
+ */
64
+ export declare function wpAdminPages(options: WpAdminPagesOptions): Plugin;
65
+ /** The build environment for classic scripts — Vite's default one. */
66
+ export declare const SCRIPT_ENVIRONMENT = "client";
67
+ /** The build environment for Script Modules. */
68
+ export declare const MODULE_ENVIRONMENT = "modules";
69
+ interface WpEnvironmentsOptions {
70
+ /**
71
+ * Substring matchers for entry source paths that are Script Modules — the
72
+ * same array `wpExternals` takes. An entry of `build.rollupOptions.input`
73
+ * whose (absolute) source path matches one builds in the `modules`
74
+ * environment; every other entry builds as a classic script.
75
+ *
76
+ * Example: `['/assets/js/modules/']`
77
+ */
78
+ moduleEntryMatchers?: string[];
58
79
  }
59
- declare function wpAdminPages(options: WpAdminPagesOptions): Plugin;
60
-
80
+ export declare function wpEnvironments(options?: WpEnvironmentsOptions): Plugin;
61
81
  interface WpBlocksOptions {
62
- blocksDir: string;
63
- buildType?: 'script' | 'module';
64
- /**
65
- * Emit `blocks-manifest.php` (returns one PHP array of all block.json
66
- * contents). Lets PHP use `wp_register_block_types_from_metadata_collection`
67
- * (WP 6.7+) instead of N filesystem reads + JSON parses on every request.
68
- * Default: `true`.
69
- */
70
- emitManifest?: boolean;
71
- /**
72
- * Block directory names (relative to `blocksDir`) to skip entirely —
73
- * neither discovered as entries nor included in the manifest.
74
- */
75
- skip?: string[];
82
+ blocksDir: string;
83
+ /**
84
+ * Emit `blocks-manifest.php` (returns one PHP array of all block.json
85
+ * contents). Lets PHP use `wp_register_block_types_from_metadata_collection`
86
+ * (WP 6.7+) instead of N filesystem reads + JSON parses on every request.
87
+ * Default: `true`.
88
+ */
89
+ emitManifest?: boolean;
90
+ /**
91
+ * Block directory names (relative to `blocksDir`) to skip entirely —
92
+ * neither discovered as entries, copied, nor included in the manifest.
93
+ */
94
+ skip?: string[];
76
95
  }
77
- declare function wpBlocks(options: WpBlocksOptions): Plugin;
78
-
96
+ /**
97
+ * Each block asset becomes an entry of the environment that builds its kind:
98
+ * `editorScript`/`script`/`viewScript` and the styles in `client`,
99
+ * `scriptModule`/`viewScriptModule` in `modules` (see `wpEnvironments`). The
100
+ * `block.json` copies and the manifest are emitted once, by `client`.
101
+ */
102
+ export declare function wpBlocks(options: WpBlocksOptions): Plugin;
79
103
  interface WpBlockStylesOptions {
80
- blocksStylesDir: string;
104
+ blocksStylesDir: string;
105
+ /**
106
+ * Output directory, relative to `outDir`, that every stylesheet lands
107
+ * under. Default: `'autoenqueue'` (`dist/autoenqueue/core/group.css`).
108
+ * `10up-toolkit` projects used `'blocks/autoenqueue'`; pass that to keep
109
+ * their PHP enqueue paths unchanged.
110
+ */
111
+ outputPrefix?: string;
81
112
  }
82
- declare function wpBlockStyles(options: WpBlockStylesOptions): Plugin;
83
-
113
+ export declare function wpBlockStyles(options: WpBlockStylesOptions): Plugin;
84
114
  interface WpCopyAssetsOptions {
85
- /** Source directory (default: `./assets`). */
86
- copyAssetsDir: string;
87
- /** Override the glob pattern (relative to `copyAssetsDir`). */
88
- pattern?: string;
89
- /** Only run during the script pass — module pass would emit duplicates. */
90
- buildType?: 'script' | 'module';
115
+ /** Source directory, e.g. `./assets`. */
116
+ copyAssetsDir: string;
117
+ /** Override the glob pattern (relative to `copyAssetsDir`). */
118
+ pattern?: string;
91
119
  }
92
- declare function wpCopyAssets(options: WpCopyAssetsOptions): Plugin;
93
-
120
+ export declare function wpCopyAssets(options: WpCopyAssetsOptions): Plugin;
94
121
  interface ExternalNamespace {
95
- /** Window global path, e.g. `wp` for `@wordpress/*`, `woo` for `@woo/*`. */
96
- global: string;
97
- /** Script-handle prefix used in `.asset.php`. `wp` → `wp-block-editor`. */
98
- handlePrefix: string;
122
+ /** Window global path, e.g. `wp` for `@wordpress/*`, `woo` for `@woo/*`. */
123
+ global: string;
124
+ /** Script-handle prefix used in `.asset.php`. `wp` → `wp-block-editor`. */
125
+ handlePrefix: string;
99
126
  }
100
127
  interface WpExternalsOptions {
101
- /**
102
- * Project root used to resolve `@wordpress/*` (and other) package.jsons.
103
- * Defaults to `process.cwd()`. Pass the absolute project root for
104
- * deterministic resolution in monorepos / weird CWDs.
105
- */
106
- projectRoot?: string;
107
- /**
108
- * Additional namespaces to externalize. The metadata-driven path covers
109
- * `@wordpress/*` automatically; this lets you add `woo`, `acme`, etc.
110
- * as classic-script externals (no metadata read — global/handle config
111
- * only).
112
- */
113
- externalNamespaces?: Record<string, ExternalNamespace>;
114
- /**
115
- * Non-scoped vendor externals (`react`, `jquery`, etc.). These don't
116
- * carry WP metadata so we keep the hardcoded mapping. Pass `{}` to
117
- * disable.
118
- */
119
- additionalExternals?: Record<string, {
120
- global: string;
121
- handle: string | null;
122
- }>;
123
- /**
124
- * 'script' (default) rewrites `import { x } from '@wordpress/y'` into
125
- * `const { x } = window.wp.y;` so the resulting bundle works as a
126
- * classic <script>. `.asset.php` lists `wp-y`-style handles for
127
- * `wp_register_script`.
128
- *
129
- * 'module' leaves ESM imports of Script-Module-eligible packages intact
130
- * (resolved at runtime by WP's import map) for use with
131
- * `wp_register_script_module` — required for the Interactivity API and
132
- * Script Modules generally. `.asset.php` lists those specifiers under
133
- * `module_dependencies` and includes `'type' => 'module'`. Script-only
134
- * packages (`wpScript`, vendor globals) have no module form, so they're
135
- * still rewritten to their `window.*` global with the classic handle
136
- * recorded in `dependencies`.
137
- */
138
- buildType?: 'script' | 'module';
139
- /**
140
- * Substring matchers for file paths that should *always* be treated as
141
- * `module`-mode regardless of the plugin-level `buildType`. Lets a
142
- * single Vite dev server (which can only run one global mode at a time)
143
- * still serve Script Module entries with their ESM imports intact.
144
- *
145
- * Example: `['/view.ts', '/view-module.ts', '/view-module.js']`
146
- */
147
- moduleEntryMatchers?: string[];
148
- /**
149
- * Substring matchers for entry *source* paths (the entry chunk's
150
- * `facadeModuleId`) whose `.asset.php` should use the
151
- * `@wordpress/build` shape:
152
- *
153
- * 'dependencies' => classic script handles
154
- * 'module_dependencies' => array( 'id' => …, 'import' => 'static'|'dynamic' )
155
- *
156
- * Entries that don't match keep the shape WordPress core reads when it
157
- * registers a Script Module from `block.json`
158
- * (`register_block_script_module_id()` passes `dependencies` straight
159
- * into `wp_register_script_module()`), so module specifiers stay in
160
- * `dependencies` there.
161
- *
162
- * `wp()` wires this automatically for `adminPagesDir`. Set it yourself
163
- * when composing plugins by hand.
164
- *
165
- * Example: `['/assets/js/admin-pages/']`
166
- */
167
- wpBuildAssetMatchers?: string[];
168
- /**
169
- * Plugin-local Script Module namespaces — exact names or `prefix-*` globs.
170
- * Imports matching `@<ns>/<anything>` are externalized as Script Modules:
171
- * the ESM import is preserved (no global rewrite) and the specifier is
172
- * recorded in the `.asset.php` dependency list.
173
- *
174
- * Example: `['ignite-wp-navigation', 'ignite-*']`
175
- */
176
- scriptModuleNamespaces?: string[];
177
- /**
178
- * Populated during the build with specifier → window global for every
179
- * script-eligible external. `wpScriptIife` uses it to build a `require`
180
- * shim for CJS deps, which Rolldown resolves at runtime rather than
181
- * through the import rewrite.
182
- */
183
- globalsSink?: Map<string, string>;
184
- /**
185
- * Bare package names to **force-bundle**: their externalization is
186
- * suppressed and their imports are rewritten to resolve against the
187
- * installed package's ESM entry instead.
188
- *
189
- * The escape hatch for packages whose WP metadata does not match what
190
- * WordPress core actually registers. Merges with (never replaces)
191
- * `DEFAULT_BUNDLED_PACKAGES`.
192
- *
193
- * Bare names only — `@wordpress/dataviews/wp` and other subpath entries
194
- * throw at config time, because force-bundling is a whole-package verdict.
195
- *
196
- * Example: `['@wordpress/icons', 'some-lying-package']`
197
- */
198
- bundle?: string[];
128
+ /**
129
+ * Project root used to resolve `@wordpress/*` (and other) package.jsons.
130
+ * Defaults to `process.cwd()`. Pass the absolute project root for
131
+ * deterministic resolution in monorepos / weird CWDs.
132
+ */
133
+ projectRoot?: string;
134
+ /**
135
+ * Additional namespaces to externalize. The metadata-driven path covers
136
+ * `@wordpress/*` automatically; this lets you add `woo`, `acme`, etc.
137
+ * as classic-script externals (no metadata read — global/handle config
138
+ * only).
139
+ */
140
+ externalNamespaces?: Record<string, ExternalNamespace>;
141
+ /**
142
+ * Non-scoped vendor externals (`react`, `jquery`, etc.). These don't
143
+ * carry WP metadata so we keep the hardcoded mapping. Pass `{}` to
144
+ * disable.
145
+ */
146
+ additionalExternals?: Record<string, {
147
+ global: string;
148
+ handle: string | null;
149
+ }>;
150
+ /**
151
+ * Source paths (substring matchers) of Script Module entries.
152
+ *
153
+ * The mode a file is transformed in normally follows the build
154
+ * environment (see `wpEnvironments`):
155
+ *
156
+ * - `client` rewrites `import { x } from '@wordpress/y'` into
157
+ * `const { x } = window.wp.y;` so the bundle works as a classic
158
+ * <script>. `.asset.php` lists `wp-y`-style handles for
159
+ * `wp_register_script`.
160
+ * - `modules` leaves ESM imports of Script-Module-eligible packages
161
+ * intact (resolved at runtime by WP's import map) for
162
+ * `wp_register_script_module` — required for the Interactivity API and
163
+ * Script Modules generally. `.asset.php` lists those specifiers and
164
+ * includes `'type' => 'module'`. Script-only packages (`wpScript`,
165
+ * vendor globals) have no module form, so they're still rewritten to
166
+ * their `window.*` global with the classic handle recorded.
167
+ *
168
+ * In a build, `wp()` uses these matchers to send the matching entries of
169
+ * `build.rollupOptions.input` to the `modules` environment. The dev server
170
+ * is one environment serving both kinds, so there a file matching one is
171
+ * transformed in module mode and everything else in script mode;
172
+ * `wpDevServer` adds every block and admin-page Script Module it
173
+ * discovers.
174
+ *
175
+ * Example: `['/assets/js/modules/', '/view-module.ts']`
176
+ */
177
+ moduleEntryMatchers?: string[];
178
+ /**
179
+ * Substring matchers for entry *source* paths (the entry chunk's
180
+ * `facadeModuleId`) whose `.asset.php` should use the
181
+ * `@wordpress/build` shape:
182
+ *
183
+ * 'dependencies' => classic script handles
184
+ * 'module_dependencies' => array( 'id' => …, 'import' => 'static'|'dynamic' )
185
+ *
186
+ * Entries that don't match keep the shape WordPress core reads when it
187
+ * registers a Script Module from `block.json`
188
+ * (`register_block_script_module_id()` passes `dependencies` straight
189
+ * into `wp_register_script_module()`), so module specifiers stay in
190
+ * `dependencies` there.
191
+ *
192
+ * `wp()` wires this automatically for `adminPagesDir`. Set it yourself
193
+ * when composing plugins by hand.
194
+ *
195
+ * Example: `['/assets/js/admin-pages/']`
196
+ */
197
+ wpBuildAssetMatchers?: string[];
198
+ /**
199
+ * Plugin-local Script Module namespaces — exact names or `prefix-*` globs.
200
+ * Imports matching `@<ns>/<anything>` are externalized as Script Modules:
201
+ * the ESM import is preserved (no global rewrite) and the specifier is
202
+ * recorded in the `.asset.php` dependency list.
203
+ *
204
+ * Example: `['acme-navigation', 'acme-*']`
205
+ */
206
+ scriptModuleNamespaces?: string[];
207
+ /**
208
+ * What to do with a `@wordpress/*` import whose package is not installed,
209
+ * so there is no metadata to read.
210
+ *
211
+ * - `'bundle'` (default): leave it to Vite, which bundles it or fails
212
+ * with a missing-module error. Install the packages you import.
213
+ * - `'external'`: assume WordPress core provides it, the way
214
+ * `@wordpress/dependency-extraction-webpack-plugin` (and so
215
+ * `10up-toolkit` up to v7) always did. `@wordpress/interactivity` and
216
+ * `@wordpress/interactivity-router` become Script Module imports;
217
+ * every other package becomes `window.wp.<name>` with a `wp-<name>`
218
+ * handle. Packages WordPress does not register, such as
219
+ * `@wordpress/icons` and `@wordpress/dataviews`, are never assumed.
220
+ */
221
+ uninstalledWordPressPackages?: 'bundle' | 'external';
222
+ /**
223
+ * Populated during the build with specifier → window global for every
224
+ * script-eligible external. `wpScriptIife` uses it to build a `require`
225
+ * shim for CJS deps, which Rolldown resolves at runtime rather than
226
+ * through the import rewrite.
227
+ */
228
+ globalsSink?: Map<string, string>;
229
+ /**
230
+ * Bare package names to **force-bundle**: their externalization is
231
+ * suppressed and their imports are rewritten to resolve against the
232
+ * installed package's ESM entry instead.
233
+ *
234
+ * The escape hatch for packages whose WP metadata does not match what
235
+ * WordPress core actually registers. Merges with (never replaces)
236
+ * `DEFAULT_BUNDLED_PACKAGES`.
237
+ *
238
+ * Bare names only — `@wordpress/dataviews/wp` and other subpath entries
239
+ * throw at config time, because force-bundling is a whole-package verdict.
240
+ *
241
+ * Example: `['@wordpress/icons', 'some-lying-package']`
242
+ */
243
+ bundle?: string[];
199
244
  }
200
245
  /**
201
246
  * Packages that claim externalizability they don't have. Same rationale as
@@ -210,7 +255,7 @@ interface WpExternalsOptions {
210
255
  * enqueue the script at all. (`@wordpress/icons@11.x` dropped `wpScript`, so
211
256
  * without this list the behavior depends on which copy the resolver hoists.)
212
257
  */
213
- declare const DEFAULT_BUNDLED_PACKAGES: string[];
258
+ export declare const DEFAULT_BUNDLED_PACKAGES: string[];
214
259
  /**
215
260
  * Config `resolveExternal` needs to make its verdict, extracted so the
216
261
  * resolver can be reused outside `wpExternals()` itself (e.g. a dev server
@@ -218,215 +263,204 @@ declare const DEFAULT_BUNDLED_PACKAGES: string[];
218
263
  * option defaults.
219
264
  */
220
265
  interface ResolveExternalOptions {
221
- /** Project root used to resolve `@wordpress/*` package.jsons. */
222
- projectRoot: string;
223
- /** Vendor external map (`react`, `jquery`, …). Defaults to `DEFAULT_VENDOR`. */
224
- vendorExternals?: Record<string, {
225
- global: string;
226
- handle: string | null;
227
- }>;
228
- /** Config-driven classic-script namespaces (`@woo/*`, etc.). */
229
- externalNamespaces?: Record<string, ExternalNamespace>;
230
- /** Script Module namespaces — exact names or `prefix-*` globs. */
231
- scriptModuleNamespaces?: string[];
232
- /** Bare package names to force-bundle (never externalized). */
233
- bundledPackages?: ReadonlySet<string> | string[];
266
+ /** Project root used to resolve `@wordpress/*` package.jsons. */
267
+ projectRoot: string;
268
+ /** Vendor external map (`react`, `jquery`, …). Defaults to `DEFAULT_VENDOR`. */
269
+ vendorExternals?: Record<string, {
270
+ global: string;
271
+ handle: string | null;
272
+ }>;
273
+ /** Config-driven classic-script namespaces (`@woo/*`, etc.). */
274
+ externalNamespaces?: Record<string, ExternalNamespace>;
275
+ /** Script Module namespaces — exact names or `prefix-*` globs. */
276
+ scriptModuleNamespaces?: string[];
277
+ /** Bare package names to force-bundle (never externalized). */
278
+ bundledPackages?: ReadonlySet<string> | string[];
279
+ /** See `WpExternalsOptions.uninstalledWordPressPackages`. Default: `'bundle'`. */
280
+ uninstalledWordPressPackages?: 'bundle' | 'external';
281
+ }
282
+ export declare function wpExternals(options?: WpExternalsOptions): Plugin[];
283
+ interface WpCssOptions {
284
+ /**
285
+ * Globs, relative to the Vite root, of the files whose `@custom-media`,
286
+ * `@custom-selector` and `@define-mixin` definitions every stylesheet can
287
+ * use. 10up-toolkit read `assets/css/globals/` and `assets/css/mixins/`.
288
+ */
289
+ globals?: string[];
290
+ /**
291
+ * Mixins defined in JS: name → declarations. `@mixin <name>;` inserts them.
292
+ * A function is called again whenever the globals are reread.
293
+ */
294
+ mixins?: MixinMap | (() => MixinMap);
295
+ /**
296
+ * Browserslist query for the compile targets. Default: the project's own
297
+ * browserslist config, or browserslist's `defaults`.
298
+ */
299
+ browserslist?: string | string[];
300
+ /**
301
+ * The directory whose files are copied into the output directory, keeping
302
+ * their paths (`wp()`'s `copyAssetsDir`). On the dev server, a relative
303
+ * `url()` that points at `<outDir>/images/logo.svg` is served from
304
+ * `<assetsDir>/images/logo.svg`. `wp()` sets it.
305
+ */
306
+ assetsDir?: string;
234
307
  }
235
- declare function wpExternals(options?: WpExternalsOptions): Plugin[];
236
-
308
+ type MixinMap = Record<string, Record<string, string | number>>;
309
+ export declare function wpCss(options?: WpCssOptions): Plugin[];
237
310
  /**
238
311
  * Name of the hot file, relative to the resolved `build.outDir`.
239
312
  *
240
313
  * Exported because the generated PHP bridge has to spell the same name, and a
241
314
  * drifting constant here is a silently dead dev server there.
242
315
  */
243
- declare const HOT_FILE_NAME = ".wp-vite-dev.json";
244
- /**
245
- * Name of the generated PHP bridge, relative to the resolved `build.outDir`.
246
- *
247
- * Written by *both* halves of this module: `wpDevServerPhp` emits it into every
248
- * build so a consumer's `require_once` is never a dead path, and `wpDevServer`
249
- * writes the identical bytes on server start so a `dist/` that has never been
250
- * built still bridges.
251
- */
252
- declare const DEV_SERVER_PHP_NAME = "dev-server.php";
316
+ export declare const HOT_FILE_NAME = ".wp-vite-dev.json";
253
317
  interface WpDevServerOptions {
254
- /** Blocks directory — same value `wpBlocks` gets. Enables block discovery. */
255
- blocksDir?: string;
256
- /** Per-block stylesheet directory — same value `wpBlockStyles` gets. */
257
- blocksStylesDir?: string;
258
- /** Admin pages directory — same value `wpAdminPages` gets. */
259
- adminPagesDir?: string;
260
- /** Block directory names to skip, mirroring `wpBlocks`' `skip`. */
261
- skip?: string[];
262
- /**
263
- * The mode this server's config maps to — the same `buildType` the build
264
- * plugins get. Only the entries declared in `build.rollupOptions.input`
265
- * need it; blocks and admin pages carry their own verdict from discovery.
266
- * Default: `'script'`, which is what a dual-pass consumer's serve-mode
267
- * config resolves to.
268
- */
269
- buildType?: 'script' | 'module';
270
- /** Write `blocks-manifest.php` into `outDir`. Default: `true`. */
271
- emitManifest?: boolean;
272
- /**
273
- * Root used to resolve `@wordpress/*` package.jsons during the dependency
274
- * scan. Must match `wpExternals`' `projectRoot` or the two disagree about
275
- * what is external. Defaults to `process.cwd()`.
276
- */
277
- projectRoot?: string;
278
- /**
279
- * The rest of `wpExternals`' externalization config, so the dev scan
280
- * reaches the same verdicts the build does. `wp()` forwards these.
281
- */
282
- externalNamespaces?: ResolveExternalOptions['externalNamespaces'];
283
- additionalExternals?: ResolveExternalOptions['vendorExternals'];
284
- scriptModuleNamespaces?: string[];
285
- bundledPackages?: string[];
286
- /**
287
- * Live array shared with `wpExternals`' `moduleEntryMatchers`. The plugin
288
- * *pushes* every discovered module-pass entry path into it during
289
- * `configResolved`, which is what makes one dev server serve both passes
290
- * correctly — see the note on `syncModuleEntryMatchers()`.
291
- */
292
- moduleEntryMatchers?: string[];
293
- /**
294
- * Entry source paths whose sidecar uses the `@wordpress/build` shape,
295
- * mirroring `wpExternals`' option of the same name. `wp()` wires
296
- * `adminPagesDir` in automatically.
297
- */
298
- wpBuildAssetMatchers?: string[];
299
- /** Depth limit for the static import walk. Default: 24. */
300
- maxScanDepth?: number;
301
- /**
302
- * Identifier prefix for `dev-server.php`'s functions and script handles.
303
- * Defaults to `wpPlugin.name`, else the de-scoped `name`, from the
304
- * package.json at Vite's `root` — else `'wp-vite'`.
305
- */
306
- phpPrefix?: string;
318
+ /** Blocks directory — same value `wpBlocks` gets. Enables block discovery. */
319
+ blocksDir?: string;
320
+ /** Per-block stylesheet directory — same value `wpBlockStyles` gets. */
321
+ blocksStylesDir?: string;
322
+ /** Per-block stylesheet output prefix — same value `wpBlockStyles` gets. */
323
+ blockStylesPrefix?: string;
324
+ /** Admin pages directory — same value `wpAdminPages` gets. */
325
+ adminPagesDir?: string;
326
+ /** Block directory names to skip, mirroring `wpBlocks`' `skip`. */
327
+ skip?: string[];
328
+ /** Write `blocks-manifest.php` into `outDir`. Default: `true`. */
329
+ emitManifest?: boolean;
330
+ /**
331
+ * Root used to resolve `@wordpress/*` package.jsons during the dependency
332
+ * scan. Must match `wpExternals`' `projectRoot` or the two disagree about
333
+ * what is external. Defaults to `process.cwd()`.
334
+ */
335
+ projectRoot?: string;
336
+ /**
337
+ * The rest of `wpExternals`' externalization config, so the dev scan
338
+ * reaches the same verdicts the build does. `wp()` forwards these.
339
+ */
340
+ externalNamespaces?: ResolveExternalOptions['externalNamespaces'];
341
+ additionalExternals?: ResolveExternalOptions['vendorExternals'];
342
+ scriptModuleNamespaces?: string[];
343
+ bundledPackages?: string[];
344
+ uninstalledWordPressPackages?: ResolveExternalOptions['uninstalledWordPressPackages'];
345
+ /**
346
+ * Live array shared with `wpExternals`' `moduleEntryMatchers`. An entry of
347
+ * `build.rollupOptions.input` matching one is served as a Script Module,
348
+ * as it builds in the `modules` environment. The plugin also *pushes*
349
+ * every Script Module entry it discovers into it during `configResolved`,
350
+ * which is what makes one dev server serve both kinds of entry correctly —
351
+ * see the note on `syncModuleEntryMatchers()`.
352
+ */
353
+ moduleEntryMatchers?: string[];
354
+ /**
355
+ * Entry source paths whose sidecar uses the `@wordpress/build` shape,
356
+ * mirroring `wpExternals`' option of the same name. `wp()` wires
357
+ * `adminPagesDir` in automatically.
358
+ */
359
+ wpBuildAssetMatchers?: string[];
360
+ /** Depth limit for the static import walk. Default: 24. */
361
+ maxScanDepth?: number;
362
+ /**
363
+ * Project prefix for `dev-server.php`: its PHP namespace, script handle,
364
+ * constant and filter.
365
+ * Defaults to `wpPlugin.name`, else the de-scoped `name`, from the
366
+ * package.json at Vite's `root` — else `'wp-vite'`.
367
+ */
368
+ phpPrefix?: string;
307
369
  }
308
370
  /** `wpDevServerPhp`'s options — the build-side half of the bridge. */
309
371
  interface WpDevServerPhpOptions {
310
- /** Identifier prefix. Same default as `wpDevServer`'s option of the same name. */
311
- phpPrefix?: string;
312
- /** Root whose package.json supplies the prefix default. Defaults to Vite's `root`. */
313
- projectRoot?: string;
372
+ /** Identifier prefix. Same default as `wpDevServer`'s option of the same name. */
373
+ phpPrefix?: string;
374
+ /** Root whose package.json supplies the prefix default. Defaults to Vite's `root`. */
375
+ projectRoot?: string;
314
376
  }
315
377
  /** What the hot file contains. Consumed by the generated PHP bridge. */
316
378
  interface WpDevServerHotFile {
317
- /** Scheme + host + port the browser should fetch assets from. No trailing slash. */
318
- origin: string;
319
- /** Vite's `base`, with its leading and trailing slash intact (`/` by default). */
320
- base: string;
321
- /** Names of the plugins in the resolved config that PHP has to react to. */
322
- plugins: string[];
379
+ /** Scheme + host + port the browser should fetch assets from. No trailing slash. */
380
+ origin: string;
381
+ /** Vite's `base`, with its leading and trailing slash intact (`/` by default). */
382
+ base: string;
383
+ /** Names of the plugins in the resolved config that PHP has to react to. */
384
+ plugins: string[];
323
385
  }
324
- declare function wpDevServer(options?: WpDevServerOptions): Plugin;
386
+ export declare function wpDevServer(options?: WpDevServerOptions): Plugin;
325
387
  /**
326
- * Emit `dist/dev-server.php` — the build-side half of the bridge.
388
+ * Emit `dist/dev-server.php` and its classes — the build-side half of the bridge.
327
389
  *
328
390
  * Its own plugin, `apply: 'build'`, for one reason: the consumer's PHP holds a
329
391
  * single unconditional `require_once __DIR__ . '/dist/dev-server.php'`, and
330
392
  * that line has to be true of *every* build — a block plugin with no admin
331
- * pages, a theme with nothing but a stylesheet entry, the module pass of a
332
- * dual-pass build. Hanging the emission off `wpAdminPages` (which owns the rest
393
+ * pages, a theme with nothing but a stylesheet entry, a plugin with nothing
394
+ * but Script Modules. Emitted by the `client` environment only, which every
395
+ * build has (see `wpEnvironments`). Hanging the emission off `wpAdminPages` (which owns the rest
333
396
  * of the generated PHP) or off `wpExternals` (which owns the sidecars the
334
397
  * bridge reads) would have made it conditional on something unrelated.
335
398
  *
336
399
  * The file itself is inert in a built site: nothing writes a hot file next to
337
400
  * it, so it returns after one `file_exists()`.
338
401
  */
339
- declare function wpDevServerPhp(options?: WpDevServerPhpOptions): Plugin;
340
-
402
+ export declare function wpDevServerPhp(options?: WpDevServerPhpOptions): Plugin;
341
403
  interface WpOptions {
342
- /** Build mode for sub-plugins. Default: `'script'`. */
343
- buildType?: 'script' | 'module';
344
- blocksDir?: string;
345
- blocksStylesDir?: string;
346
- copyAssetsDir?: string;
347
- adminPagesDir?: string;
348
- /**
349
- * Per-plugin escape hatches. Pass `false` to disable; pass an object
350
- * to merge extra options into the sub-plugin. Nested wins on conflict.
351
- */
352
- blocks?: Partial<WpBlocksOptions> | false;
353
- blockStyles?: Partial<WpBlockStylesOptions> | false;
354
- copyAssets?: Partial<WpCopyAssetsOptions> | false;
355
- adminPages?: Partial<WpAdminPagesOptions> | false;
356
- externals?: WpExternalsOptions | false;
357
- /**
358
- * The `apply: 'serve'` dev-server bridge — hot file, dev `.asset.php`
359
- * sidecars, blocks metadata, and the bare-specifier escape that keeps
360
- * Script Module entries servable. Included by default and completely inert
361
- * in a build; pass `false` to leave dev alone, or an object to override its
362
- * options (the directories and externals config are wired from the
363
- * top-level keys automatically).
364
- */
365
- devServer?: WpDevServerOptions | false;
366
- /** Disable the auto-included script-IIFE helper. Default: enabled in script mode. */
367
- iife?: false;
368
- /**
369
- * Disable the auto-included per-entry module duplication. Default: enabled
370
- * in script mode. Without it, a module two script entries share becomes a
371
- * shared chunk each entry `import`s — invalid as a classic script.
372
- */
373
- scriptDedupe?: false;
374
- /** Disable the auto-included CSS-only-chunk cleanup. Default: always enabled. */
375
- cleanCssChunks?: false;
376
- /** Disable the auto-included CSS-only-entry `.asset.php` sidecars. Default: always enabled. */
377
- cssAssetInfo?: false;
404
+ blocksDir?: string;
405
+ blocksStylesDir?: string;
406
+ copyAssetsDir?: string;
407
+ adminPagesDir?: string;
408
+ /**
409
+ * Per-plugin escape hatches. Pass `false` to disable; pass an object
410
+ * to merge extra options into the sub-plugin. Nested wins on conflict.
411
+ */
412
+ blocks?: Partial<WpBlocksOptions> | false;
413
+ blockStyles?: Partial<WpBlockStylesOptions> | false;
414
+ copyAssets?: Partial<WpCopyAssetsOptions> | false;
415
+ adminPages?: Partial<WpAdminPagesOptions> | false;
416
+ externals?: WpExternalsOptions | false;
417
+ /**
418
+ * The `apply: 'serve'` dev-server bridge — hot file, dev `.asset.php`
419
+ * sidecars, blocks metadata, and the bare-specifier escape that keeps
420
+ * Script Module entries servable. Included by default and completely inert
421
+ * in a build; pass `false` to leave dev alone, or an object to override its
422
+ * options (the directories and externals config are wired from the
423
+ * top-level keys automatically).
424
+ */
425
+ devServer?: WpDevServerOptions | false;
426
+ /**
427
+ * Compile CSS with Lightning CSS instead of PostCSS, with project-wide
428
+ * globals (custom media, custom selectors, mixins) every stylesheet can use
429
+ * without importing them. Off unless set; see `wpCss`.
430
+ */
431
+ css?: WpCssOptions;
432
+ /** Disable the auto-included script-IIFE helper (classic scripts only). Default: enabled. */
433
+ iife?: false;
434
+ /**
435
+ * Disable the auto-included per-entry module duplication (classic scripts
436
+ * only). Default: enabled. Without it, a module two script entries share becomes a
437
+ * shared chunk each entry `import`s — invalid as a classic script.
438
+ */
439
+ scriptDedupe?: false;
440
+ /** Disable the auto-included CSS-only-chunk cleanup. Default: always enabled. */
441
+ cleanCssChunks?: false;
442
+ /** Disable the auto-included CSS-only-entry `.asset.php` sidecars. Default: always enabled. */
443
+ cssAssetInfo?: false;
444
+ /**
445
+ * Disable the auto-included guard that keeps byte-identical CSS entries
446
+ * from collapsing into one emitted file. Default: always enabled.
447
+ */
448
+ cssEntryGuard?: false;
378
449
  }
379
- declare function wp(options?: WpOptions): Plugin[];
380
-
381
- declare function wpScriptDedupe(): Plugin;
382
-
383
- /**
384
- * vite-plugin-wp-script-iife
385
- *
386
- * Wraps each script-mode entry chunk in an IIFE post-write — esbuild/oxc's
387
- * minifier would otherwise inline a plain intro/outro IIFE for var-heavy
388
- * bodies, defeating the global-scope isolation needed when WP enqueues
389
- * these as classic <script> tags.
390
- *
391
- * It is also the gate that guarantees the output *is* a valid classic script:
392
- * every chunk is parsed before it's wrapped, and one that doesn't compile fails
393
- * the build instead of shipping a file the browser cannot load. The two causes
394
- * worth diagnosing by name are a live `import`/`export` statement (a shared
395
- * chunk Rolldown refused to duplicate) and an `import.meta` reference (Vite's
396
- * dynamic-import preload helper). The `import.meta` members that helper touches
397
- * are rewritten to classic-script-safe expressions through an injected
398
- * `define`, so the failure only fires for cases the define can't reach.
399
- *
400
- * Only run this in script mode. Module-mode entries (`wp_register_script_module`)
401
- * must stay as bare ESM for WP's import map to resolve them at runtime.
402
- */
403
-
450
+ export declare function wp(options?: WpOptions): Plugin[];
451
+ export declare function wpScriptDedupe(): Plugin;
404
452
  interface WpScriptIifeOptions {
405
- /**
406
- * Specifier → window global, used to shim `require()` for CJS dependencies
407
- * whose `require` Rolldown resolves at runtime rather than through
408
- * `wpExternals`' import rewrite.
409
- *
410
- * `wp()` passes `wpExternals`' `globalsSink` automatically.
411
- */
412
- globals?: Map<string, string>;
453
+ /**
454
+ * Specifier → window global, used to shim `require()` for CJS dependencies
455
+ * whose `require` Rolldown resolves at runtime rather than through
456
+ * `wpExternals`' import rewrite.
457
+ *
458
+ * `wp()` passes `wpExternals`' `globalsSink` automatically.
459
+ */
460
+ globals?: Map<string, string>;
413
461
  }
414
- declare function wpScriptIife(options?: WpScriptIifeOptions): Plugin;
415
-
416
- /**
417
- * vite-plugin-wp-clean-css-chunks
418
- *
419
- * Deletes the empty `.js` shim Vite leaves next to a CSS-only entry.
420
- *
421
- * Vite's Rollup-driven model treats every entry as a JS module that may
422
- * pull in CSS via side-effect imports. For an entry whose source IS a CSS
423
- * file (e.g. each per-block stylesheet produced by wpBlockStyles), Vite
424
- * still emits a tiny empty `.js` chunk that just imports the `.css`.
425
- * Useless for WP enqueueing.
426
- */
427
-
428
- declare function wpCleanCssChunks(): Plugin;
429
-
430
- declare function wpCssAssetInfo(): Plugin;
431
-
432
- export { DEFAULT_BUNDLED_PACKAGES, DEV_SERVER_PHP_NAME, type ExternalNamespace, HOT_FILE_NAME, type WpAdminPagesOptions, type WpAdminPagesPhpOptions, type WpBlockStylesOptions, type WpBlocksOptions, type WpCopyAssetsOptions, type WpDevServerHotFile, type WpDevServerOptions, type WpDevServerPhpOptions, type WpExternalsOptions, type WpOptions, type WpScriptIifeOptions, wp, wpAdminPages, wpBlockStyles, wpBlocks, wpCleanCssChunks, wpCopyAssets, wpCssAssetInfo, wpDevServer, wpDevServerPhp, wpExternals, wpScriptDedupe, wpScriptIife };
462
+ export declare function wpScriptIife(options?: WpScriptIifeOptions): Plugin;
463
+ export declare function wpCleanCssChunks(): Plugin;
464
+ export declare function wpCssAssetInfo(): Plugin;
465
+ export declare function wpCssEntryGuard(): Plugin;
466
+ export type { ExternalNamespace, MixinMap, WpAdminPagesOptions, WpAdminPagesPhpOptions, WpBlockStylesOptions, WpBlocksOptions, WpCopyAssetsOptions, WpCssOptions, WpDevServerHotFile, WpDevServerOptions, WpDevServerPhpOptions, WpEnvironmentsOptions, WpExternalsOptions, WpOptions, WpScriptIifeOptions };