@eightshift/frontend-libs-tailwind 4.0.0-beta.2 → 4.0.0-beta.3
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 +11 -11
- package/README.md +45 -4
- package/bun/build.mjs +7 -1
- package/bun/cli.mjs +14 -1
- package/bun/flat-publication.mjs +25 -4
- package/bun/index.mjs +24 -0
- package/bun/theme-build.mjs +34 -14
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -10,19 +10,19 @@ This projects adheres to [Semantic Versioning](https://semver.org/) and [Keep a
|
|
|
10
10
|
|
|
11
11
|
### Changed
|
|
12
12
|
|
|
13
|
+
- Show build/watch progress and total duration by default, with `--quiet` and `--verbose` output modes.
|
|
14
|
+
- Stage theme releases before replacing public assets, preserving the previous release on build or cache failures.
|
|
15
|
+
- Support extra publication files, manifest aliases and explicit file retention through the shared publisher.
|
|
16
|
+
|
|
13
17
|
- **Breaking:** the conventional theme build requires a stable WordPress 7.0 or newer installation.
|
|
14
18
|
- **Breaking:** removed the Webpack configuration, `webpack/*` API and its build dependencies. Migrate project build scripts to Bun or another independently configured build pipeline.
|
|
15
|
-
- Bun build helpers
|
|
16
|
-
-
|
|
17
|
-
- Improved
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
- Added
|
|
22
|
-
|
|
23
|
-
- Added experimental `editor.sharing: 'unified'` for one registration/lazy ESM graph with module metadata and an explicit readiness completion signal. Requires matching PHP integration; classic defaults and native-lazy sharing remain unchanged.
|
|
24
|
-
- Added opt-in `editor.pureJsxGroups: { maxBytes: 4096 }` for unified production builds: bounded, AST-proven dependency definitions share native chunks without co-loading application initialization. Custom transforms and source-map builds conservatively retain ungrouped output with a warning; default builds remain unchanged.
|
|
25
|
-
- Isolated native editor compilation in private staging so Bun versions ignoring `write: false` cannot publish discarded first-pass chunks; selected artifacts and source maps are materialized before cleanup.
|
|
19
|
+
- Added Bun build helpers with a conventional theme preset, CSS processing and watch support. These are not a drop-in replacement for Webpack; project configuration and WordPress asset integration must be migrated.
|
|
20
|
+
- Enabled import optimization for `@eightshift/ui-components` by default in conventional theme builds.
|
|
21
|
+
- Improved browser bundle tree-shaking and WordPress dependency metadata.
|
|
22
|
+
- Prevented unnecessary watch rebuilds on macOS.
|
|
23
|
+
- Removed the experimental `editor.sharedPackages` option. Existing configurations must remove it or migrate to a supported sharing mode.
|
|
24
|
+
- Added opt-in editor sharing modes: `native` shares lazy-loaded modules while preserving synchronous registration; `unified` also shares registration code and requires matching PHP module-readiness integration. Independent builds remain the default.
|
|
25
|
+
- Added opt-in `editor.pureJsxGroups` to reduce chunk requests in unified production builds. Unsupported configurations, including source-map builds, fall back to ungrouped output.
|
|
26
26
|
|
|
27
27
|
## [3.5.0]
|
|
28
28
|
|
package/README.md
CHANGED
|
@@ -45,14 +45,14 @@ The conventional theme build requires a stable WordPress 7.0 or newer installati
|
|
|
45
45
|
}
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
-
4. Run `bun run build` and compare the generated assets and site behavior with the previous build. Use `bun run start` for an initial build and subsequent rebuilds, or `bun run build:sourcemaps` for external source maps. The CLI accepts `--config path` to select another configuration. It is `eightshift-build`, not `bun build`: the library orchestrates CSS, discovery, WordPress dependencies and publication around Bun's bundler.
|
|
48
|
+
4. Run `bun run build` and compare the generated assets and site behavior with the previous build. Use `bun run start` for an initial build and subsequent rebuilds, or `bun run build:sourcemaps` for external source maps. The CLI accepts `--config path` to select another configuration. By default, builds log a short start message and total elapsed seconds on success. Use `--quiet` to suppress informational output while retaining warnings and errors, or `--verbose` for build stages and theme entry/dependency details. These flags are mutually exclusive. The obsolete `--timings` flag is rejected. Both modes work with `build` and `watch`; each rebuild gets its own timer. Completion is reported only after configured SSR and publication callbacks succeed, including staged theme publication. The theme publisher may also build SSR during its publication stage. Use `eightshift-build --help` for CLI options. Programmatic `defineBuild` and theme definitions accept `{ quiet: true }` or `{ verbose: true }` in `.build()` and `.watch()`; combining them or providing the removed `timings` option throws. Custom callbacks should use the invocation context’s `quiet` and `verbose` fields to control their own informational logging. It is `eightshift-build`, not `bun build`: the library orchestrates CSS, discovery, WordPress dependencies and publication around Bun's bundler.
|
|
49
49
|
5. Update CI and deployment to use Bun and the new scripts. Only remove Webpack dependencies and configuration after verifying the new build. Ensure the deployment environment has access to WordPress and its compatible script metadata for dependency extraction.
|
|
50
50
|
|
|
51
|
-
The default preset discovers conventional block and component assets, builds frontend, editor and admin scripts and styles, and builds conventional SSR entries when present. SVG imports in frontend and admin scripts emit files referenced by root-relative public URLs; editor SVG imports produce SVG text instead. The default build
|
|
51
|
+
The default preset discovers conventional block and component assets, builds frontend, editor and admin scripts and styles, and builds conventional SSR entries when present. SVG imports in frontend and admin scripts emit files referenced by root-relative public URLs; editor SVG imports produce SVG text instead. The default build stages intermediate assets in `.bun-pilot/theme-build`, including SSR output in `.bun-pilot/theme-build/ssr/production`, and replaces `public/` with the packaged assets and manifest only after packaging succeeds. Build or packaging failures preserve the existing public assets. Successful builds remove the staging directory. Only custom or disabled publication uses `public/.build`; the project owns its publication and cleanup. Do not keep manually maintained files in `public/`. Frontend and admin use classic-script bootstraps that dynamically import their bundled modules; the editor is packaged separately. Preserve the generated chunks alongside the entry scripts. The default preset always produces production-optimized assets, including in watch mode; watch does not provide hot reload. With `--sourcemaps`, external maps are generated for the editor entry and its lazy chunks as well as the browser bundles. SSR execution may still require Node in the project's PHP integration.
|
|
52
52
|
|
|
53
53
|
The manifest maps the conventional `applicationBlocksFrontend`, `applicationBlocksEditor` and `applicationAdmin` script and style keys to their generated files. Each entry also has `.asset.json` metadata containing WordPress dependency handles and a release version; the manifest maps its legacy `.json` key to that metadata as well. Browser entry metadata includes handles used by any emitted chunk, including lazy chunks. If Bun's build metadata is unavailable or cannot be read, the build conservatively includes all resolved handles instead; the editor also retains all resolved handles across its independently compiled chunks. **The build does not enqueue assets:** confirm that your installed PHP integration reads the generated metadata and merges its dependencies with the registered handles. Existing PHP/library versions may not support this; update or adapt them before switching, and check that the frontend, editor and admin load without missing globals. Do not assume Bun's `external` option supplies WordPress global mappings.
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
Successful default publication replaces the previous `public/` contents. Run only one build or publication per theme at a time; output directories are not locked against concurrent builds. The PHP manifest cache update is not coordinated with PHP cache rebuilds: if they overlap, stale asset URLs can remain until the next successful build or cache reset. Account for cached pages that may still request files removed by successful publication; retain old releases externally if needed. Verify block registration, editor controls and save/reload behavior, frontend styles and lazy assets, representative admin screens, script dependencies, browser console and asset URLs. Keep the previous Webpack build available for rollback until the new build is verified.
|
|
56
56
|
|
|
57
57
|
### Lower-level build API
|
|
58
58
|
|
|
@@ -179,6 +179,47 @@ For `defineBuild` watch configurations with `ssr` or `publish` callbacks, explic
|
|
|
179
179
|
|
|
180
180
|
`defineThemeBuild` from `bun/theme-build.mjs` supplies the conventional theme layout and flat publication. `entries` replaces the complete entry map; `editor` replaces the editor preset or may be `false`. `responsive` accepts the preset's options or `false`. `css` accepts an async callback receiving `{ root, outdir, stage, responsive, require }` or `false`; `extraCss` still runs afterwards. `discovery` accepts a plugin factory receiving `{ root, setEditorWorker, getEditorWorker }` (also async) or `false`; with either override, callers must provide discovery compatible with their entry sources. `frontendStyles` applies only to default discovery. The built-in editor worker plugin runs before plugins returned by `createPlugins`; replace it via `media.editorWorker` when custom handling is needed. The returned plugin array is not modified. `ssr` replaces `buildSsr` or can be `false`; do not specify both. `publish` replaces the flat publisher with an async callback receiving the build state, or `false` leaves the intermediate build unpublished in `public/.build`. With custom or disabled publication, the SSR callback runs after the browser build and receives the build state and `mode: 'production'`.
|
|
181
181
|
|
|
182
|
+
### Staged theme publication
|
|
183
|
+
|
|
184
|
+
Default theme builds now prepare assets outside `public`, then swap the validated
|
|
185
|
+
release into place. Build/package failures preserve the previous release; cache
|
|
186
|
+
update failures roll publication back. Custom `publish` hooks remain responsible
|
|
187
|
+
for their own publication and rollback.
|
|
188
|
+
|
|
189
|
+
Use `publication` to supply additional already-built files (for example Infobip
|
|
190
|
+
UTM scripts/fonts or Forms custom entry bundles) without replacing the publisher:
|
|
191
|
+
|
|
192
|
+
```js
|
|
193
|
+
import { resolve } from 'node:path';
|
|
194
|
+
import { defineThemeBuild } from '@eightshift/frontend-libs-tailwind/bun/theme-build.mjs';
|
|
195
|
+
|
|
196
|
+
export default defineThemeBuild({
|
|
197
|
+
root: import.meta.dirname,
|
|
198
|
+
publication: async ({ root }) => ({
|
|
199
|
+
extraFiles: [
|
|
200
|
+
{ source: resolve(root, 'build/utm.js'), destination: 'utm.js' },
|
|
201
|
+
{ source: resolve(root, 'build/fonts'), destination: 'fonts' },
|
|
202
|
+
{ source: resolve(root, 'build/forms.js'), destination: 'forms.js' },
|
|
203
|
+
],
|
|
204
|
+
aliases: { 'utm.js': 'utm.js', 'forms.js': 'forms.js', 'font.woff2': 'fonts/font.woff2' },
|
|
205
|
+
retain: [],
|
|
206
|
+
}),
|
|
207
|
+
});
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
Sources must exist before packaging; the hook can build them into `outdir`.
|
|
211
|
+
The hook may return `undefined` for no additions, or a non-array object. When
|
|
212
|
+
provided, `aliases` must be a non-null, non-array object and `extraFiles` must be
|
|
213
|
+
an array; invalid results throw a `TypeError` before packaging.
|
|
214
|
+
Paths are release-relative destinations; duplicate destinations fail rather than
|
|
215
|
+
silently overwrite. `packageFlatRelease` also accepts `extraFiles`, `retain` and
|
|
216
|
+
`previousPublic`. Retention is opt-in and names exact existing files, not globs or
|
|
217
|
+
filename heuristics. Retained files cannot collide with new outputs. Fixed names
|
|
218
|
+
are replaced on successful publication: they cannot preserve old browser sessions
|
|
219
|
+
like content-hashed filenames. Additional manifest generation and automatic
|
|
220
|
+
multi-release retention are not provided. Aliases join the primary manifest and
|
|
221
|
+
PHP asset cache; consumers needing separate manifests must use custom publication.
|
|
222
|
+
|
|
182
223
|
### Optimizing package imports
|
|
183
224
|
|
|
184
225
|
`optimizeImports` is an array of package names passed to Bun's [barrel import optimization](https://bun.com/docs/bundler#optimizeimports) for frontend, editor (including lazy chunks), and admin JavaScript. It also applies in watch and source-map builds, but not to SSR or CSS processing. The conventional theme build defaults to `['@eightshift/ui-components']`. Supply an array to replace the default, or `[]` to disable the preset's explicit optimization:
|
|
@@ -221,7 +262,7 @@ The default flat publisher includes generated stylesheets in `public/` and its m
|
|
|
221
262
|
|
|
222
263
|
The build regenerates discovery and CSS on each rebuild. Watch monitors the configured project paths, not `node_modules` or arbitrary external files by default; customize `watch.sources` for additional inputs. Default theme builds use production CSS processing, including Lightning CSS minification and its browser targets, even in watch mode. `extraCss` may also be an async hook receiving `{ root, stage, require }`, or `false` to disable it. Hooks are responsible for their own filenames and loading behavior. `frontendStyles` separately attaches existing URLs to keys; both automatic mechanisms require default discovery.
|
|
223
264
|
|
|
224
|
-
Default flat publication requires frontend, admin and editor entries, an editor build, and CSS at the conventional filenames. It scans the conventional SSR source glob and expects matching outputs in
|
|
265
|
+
Default flat publication requires frontend, admin and editor entries, an editor build, and CSS at the conventional filenames. It scans the conventional SSR source glob and expects matching outputs in `.bun-pilot/theme-build/ssr/production`. With default publication, custom `ssr` (or legacy `buildSsr`) callbacks receive `{ root, mode: 'production', outdir }`, where `outdir` is the absolute path to that SSR output directory. Callbacks must finish writing `<name>.js` files there before resolving, where `<name>` is the directory containing each conventional `assets-ssr` directory; `packageFlatRelease` reads those files from the same directory. Use `ssr: false` to omit SSR or supply custom publication for a different layout. Disabling responsive generation requires custom or disabled CSS. Custom publication is required when disabling CSS or the editor, or changing the entry set. With custom or disabled publication, intermediate output remains in `public/.build`; the project owns its publication and cleanup.
|
|
225
266
|
|
|
226
267
|
WordPress externalization is enabled by default. Set `wpRoot` to the WordPress installation when using externalized `@wordpress/*` imports; export discovery reads its core scripts and requires compatible installed package metadata. The adapter also maps React and selected common dependencies to WordPress globals. Those globals and script handles must be available at runtime. Set `wordpress: false` to disable this adapter. For direct Bun integration, `wordpressPlugin({ projectRoot, wpRoot })` returns `{ plugin, dependencies, getEmittedDependencies }`; use a fresh adapter for each build and absolute paths. `dependencies` contains all resolved handles. Request a Bun metafile and pass it to `getEmittedDependencies(metafile)` to derive handles from every emitted output; invalid metadata falls back to all resolved handles. Some Bun versions can throw when reading `result.metafile` itself, so catch that access and fall back to `dependencies` too.
|
|
227
268
|
|
package/bun/build.mjs
CHANGED
|
@@ -349,7 +349,13 @@ export async function build({ root = process.cwd(), outdir, entries, wpRoot, wor
|
|
|
349
349
|
return { outdir, entries: manifest };
|
|
350
350
|
} finally {
|
|
351
351
|
if (!published) {
|
|
352
|
-
|
|
352
|
+
try {
|
|
353
|
+
await removeTree(stage);
|
|
354
|
+
} catch (error) {
|
|
355
|
+
if (error.code !== 'ENOENT') {
|
|
356
|
+
console.warn(`Build staging cleanup failed at ${stage}:`, error);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
353
359
|
}
|
|
354
360
|
}
|
|
355
361
|
}
|
package/bun/cli.mjs
CHANGED
|
@@ -26,8 +26,15 @@ if (!(process.env.NODE_PATH ?? '').split(delimiter).includes(projectModules)) {
|
|
|
26
26
|
const args = process.argv.slice(2);
|
|
27
27
|
const command = args.shift();
|
|
28
28
|
|
|
29
|
+
const usage = 'Usage: eightshift-build <build|watch> [--config path] [--sourcemaps] [--quiet | --verbose]';
|
|
30
|
+
|
|
31
|
+
if (command === '--help' || command === '-h' || args.includes('--help') || args.includes('-h')) {
|
|
32
|
+
console.log(`${usage}\n --quiet Suppress informational output (warnings/errors remain).\n --verbose Show build stages and entry/dependency details.`);
|
|
33
|
+
process.exit(0);
|
|
34
|
+
}
|
|
35
|
+
|
|
29
36
|
if (!['build', 'watch'].includes(command)) {
|
|
30
|
-
throw new Error(
|
|
37
|
+
throw new Error(usage);
|
|
31
38
|
}
|
|
32
39
|
|
|
33
40
|
let config = 'eightshift.build.mjs';
|
|
@@ -42,6 +49,8 @@ while (args.length) {
|
|
|
42
49
|
if (!config || config.startsWith('--')) {
|
|
43
50
|
throw new Error('--config requires a path');
|
|
44
51
|
}
|
|
52
|
+
} else if (arg === '--verbose' || arg === '--quiet') {
|
|
53
|
+
options[arg.slice(2)] = true;
|
|
45
54
|
} else if (arg === '--sourcemaps') {
|
|
46
55
|
options.sourcemaps = true;
|
|
47
56
|
} else {
|
|
@@ -49,6 +58,10 @@ while (args.length) {
|
|
|
49
58
|
}
|
|
50
59
|
}
|
|
51
60
|
|
|
61
|
+
if (options.quiet && options.verbose) {
|
|
62
|
+
throw new Error('--quiet and --verbose cannot be combined');
|
|
63
|
+
}
|
|
64
|
+
|
|
52
65
|
const { default: definition } = await import(pathToFileURL(resolve(config)).href);
|
|
53
66
|
|
|
54
67
|
if (!definition || typeof definition.build !== 'function' || typeof definition.watch !== 'function') {
|
package/bun/flat-publication.mjs
CHANGED
|
@@ -191,8 +191,25 @@ export async function flattenAssets({ outdir, flatDir, directories = ['frontend'
|
|
|
191
191
|
}
|
|
192
192
|
|
|
193
193
|
/** Package flattened files, optional SSR files and standalone assets. */
|
|
194
|
-
export async function packageFlatRelease({ root, flatDir, entries, ssrDir, ssrNames = [], standaloneAssets = new Map(), aliases = {}, outputDirectory, removeIntermediates = false }) {
|
|
195
|
-
|
|
194
|
+
export async function packageFlatRelease({ root, flatDir, entries, ssrDir, ssrNames = [], standaloneAssets = new Map(), aliases = {}, extraFiles = [], retain = [], previousPublic, outputDirectory, removeIntermediates = false }) {
|
|
195
|
+
if (!Array.isArray(extraFiles) || !Array.isArray(retain) || (retain.length && !previousPublic)) {
|
|
196
|
+
throw new TypeError('extraFiles and retain must be arrays; retention requires previousPublic');
|
|
197
|
+
}
|
|
198
|
+
const files = [...extraFiles];
|
|
199
|
+
for (const name of retain) {
|
|
200
|
+
pathName(name);
|
|
201
|
+
let source = resolve(previousPublic);
|
|
202
|
+
for (const part of name.split('/')) {
|
|
203
|
+
source = resolve(source, part);
|
|
204
|
+
if ((await lstat(source)).isSymbolicLink()) {
|
|
205
|
+
throw new Error(`Symlink in retained path: ${name}`);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
if (!(await lstat(source)).isFile()) {
|
|
209
|
+
throw new Error(`Retained path must be an exact file: ${name}`);
|
|
210
|
+
}
|
|
211
|
+
files.push({ source, destination: name });
|
|
212
|
+
}
|
|
196
213
|
|
|
197
214
|
for (const name of await readdir(flatDir)) {
|
|
198
215
|
files.push({ source: resolve(flatDir, name), destination: name });
|
|
@@ -293,7 +310,7 @@ export async function publishFlatRelease({ root, wpRoot, release, manifest, vers
|
|
|
293
310
|
throw new Error(`Unsupported release output: ${name}`);
|
|
294
311
|
}
|
|
295
312
|
|
|
296
|
-
if (name !== 'manifest.json' && name !== 'ssr' && !(direct && name === '.build') && !Object.hasOwn(result, name)) {
|
|
313
|
+
if (entry.isFile() && name !== 'manifest.json' && name !== 'ssr' && !(direct && name === '.build') && !Object.hasOwn(result, name)) {
|
|
297
314
|
result[name] = name;
|
|
298
315
|
}
|
|
299
316
|
}
|
|
@@ -404,7 +421,11 @@ export async function publishFlatRelease({ root, wpRoot, release, manifest, vers
|
|
|
404
421
|
};
|
|
405
422
|
|
|
406
423
|
if (hadPublic) {
|
|
407
|
-
|
|
424
|
+
try {
|
|
425
|
+
await removeTree(backup);
|
|
426
|
+
} catch (error) {
|
|
427
|
+
console.warn(`Build published, but backup cleanup failed at ${backup}:`, error);
|
|
428
|
+
}
|
|
408
429
|
}
|
|
409
430
|
|
|
410
431
|
return { publicDir, manifest: publicManifest, version };
|
package/bun/index.mjs
CHANGED
|
@@ -33,15 +33,34 @@ export function defineBuild({ root = process.cwd(), preset, ssr, publish, watch
|
|
|
33
33
|
throw new TypeError('watch.ignore must be a function');
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
const validateOptions = (options) => {
|
|
37
|
+
if (Object.hasOwn(options, 'timings')) {
|
|
38
|
+
throw new Error('The timings option is no longer supported');
|
|
39
|
+
}
|
|
40
|
+
if (options.quiet && options.verbose) {
|
|
41
|
+
throw new Error('quiet and verbose cannot be combined');
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
36
45
|
root = resolve(root);
|
|
37
46
|
let active;
|
|
38
47
|
const outputs = new Set();
|
|
39
48
|
const run = async (options = {}) => {
|
|
49
|
+
validateOptions(options);
|
|
40
50
|
if (active) {
|
|
41
51
|
throw new Error('A build is already running');
|
|
42
52
|
}
|
|
43
53
|
|
|
54
|
+
const started = performance.now();
|
|
55
|
+
const report = (message, detail = false) => {
|
|
56
|
+
if (!options.quiet && (!detail || options.verbose)) {
|
|
57
|
+
console.log(`[eightshift-build] ${message}`);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
44
61
|
active = (async () => {
|
|
62
|
+
report('Starting build…');
|
|
63
|
+
report('Preparing build…', true);
|
|
45
64
|
const context = { ...options, root };
|
|
46
65
|
const configured = typeof preset === 'function' ? await preset(context) : preset;
|
|
47
66
|
outputs.clear();
|
|
@@ -53,17 +72,21 @@ export function defineBuild({ root = process.cwd(), preset, ssr, publish, watch
|
|
|
53
72
|
}
|
|
54
73
|
outputs.add(output);
|
|
55
74
|
}
|
|
75
|
+
report('Building browser assets…');
|
|
56
76
|
const result = await buildPreset({ ...configured, root });
|
|
57
77
|
const state = { ...context, result };
|
|
58
78
|
|
|
59
79
|
if (ssr) {
|
|
80
|
+
report('Building SSR assets…');
|
|
60
81
|
state.ssr = await ssr(state);
|
|
61
82
|
}
|
|
62
83
|
|
|
63
84
|
if (publish) {
|
|
85
|
+
report('Running publication…');
|
|
64
86
|
state.publication = await publish(state);
|
|
65
87
|
}
|
|
66
88
|
|
|
89
|
+
report(`Build completed in ${((performance.now() - started) / 1000).toFixed(2)}s.`);
|
|
67
90
|
return state;
|
|
68
91
|
})();
|
|
69
92
|
|
|
@@ -77,6 +100,7 @@ export function defineBuild({ root = process.cwd(), preset, ssr, publish, watch
|
|
|
77
100
|
return {
|
|
78
101
|
build: run,
|
|
79
102
|
watch: (options = {}) => {
|
|
103
|
+
validateOptions(options);
|
|
80
104
|
if ((ssr || publish) && watch.sources === undefined && !watch.ignored?.length) {
|
|
81
105
|
throw new Error('Watch builds with ssr or publish callbacks require explicit watch.sources or watch.ignored');
|
|
82
106
|
}
|
package/bun/theme-build.mjs
CHANGED
|
@@ -30,6 +30,7 @@ export function defineThemeBuild({
|
|
|
30
30
|
optimizeImports = ['@eightshift/ui-components'],
|
|
31
31
|
extraCss = async () => {},
|
|
32
32
|
aliases = {},
|
|
33
|
+
publication = async () => ({}),
|
|
33
34
|
requireEditorWorker = false,
|
|
34
35
|
media = {},
|
|
35
36
|
watch = {},
|
|
@@ -180,13 +181,8 @@ export function defineThemeBuild({
|
|
|
180
181
|
|
|
181
182
|
editorWorker = undefined;
|
|
182
183
|
const publicDir = resolve(root, 'public');
|
|
183
|
-
outdir = resolve(publicDir, '.build');
|
|
184
|
-
|
|
185
|
-
await clearBuildDirectory(publicDir, root);
|
|
186
|
-
await mkdir(publicDir, { recursive: true });
|
|
187
|
-
} else {
|
|
188
|
-
await clearBuildDirectory(outdir, root);
|
|
189
|
-
}
|
|
184
|
+
outdir = publish === undefined ? resolve(root, '.bun-pilot/theme-build') : resolve(publicDir, '.build');
|
|
185
|
+
await clearBuildDirectory(outdir, root);
|
|
190
186
|
const require = createRequire(resolve(root, 'package.json'));
|
|
191
187
|
const names = ['componentManifests', 'customManifests', 'customBlocks', 'customHooks', 'customTransforms', 'customDeprecations', 'customOverrides', 'variationManifests', 'customVariationManifests', 'variationOverrides', 'componentAdminAssets', 'customAdminAssets'];
|
|
192
188
|
const specs = [
|
|
@@ -364,7 +360,7 @@ export function defineThemeBuild({
|
|
|
364
360
|
},
|
|
365
361
|
};
|
|
366
362
|
};
|
|
367
|
-
const defaultPublish = async ({ result }) => {
|
|
363
|
+
const defaultPublish = async ({ result, verbose, quiet }) => {
|
|
368
364
|
const editorScript = await readFile(resolve(outdir, result.entries.editor.entry), 'utf8');
|
|
369
365
|
|
|
370
366
|
if (requireEditorWorker && !editorWorker) {
|
|
@@ -376,7 +372,7 @@ export function defineThemeBuild({
|
|
|
376
372
|
|
|
377
373
|
if (ssr !== false) {
|
|
378
374
|
if (ssr || buildSsr) {
|
|
379
|
-
await (ssr ?? buildSsr)({ root, mode: 'production' });
|
|
375
|
+
await (ssr ?? buildSsr)({ root, mode: 'production', outdir: ssrDir });
|
|
380
376
|
}
|
|
381
377
|
|
|
382
378
|
for await (const file of new Bun.Glob('src/**/assets-ssr/ssr.{js,mjs}').scan({ cwd: root })) {
|
|
@@ -424,7 +420,9 @@ export function defineThemeBuild({
|
|
|
424
420
|
const entry = result.entries[surface];
|
|
425
421
|
const script = surface === 'editor' ? rewrite(editorScript, entry.entry) : undefined;
|
|
426
422
|
|
|
427
|
-
|
|
423
|
+
if (verbose && !quiet) {
|
|
424
|
+
console.log(`${surface}: ${entry.entry}; dependencies: ${entry.dependencies.join(', ') || 'none'}`);
|
|
425
|
+
}
|
|
428
426
|
|
|
429
427
|
return {
|
|
430
428
|
name,
|
|
@@ -435,19 +433,41 @@ export function defineThemeBuild({
|
|
|
435
433
|
...(entry.format === 'module' ? { format: entry.format, readiness: entry.readiness } : {}),
|
|
436
434
|
};
|
|
437
435
|
});
|
|
436
|
+
const publicationResult = await publication({ root, outdir, result });
|
|
437
|
+
const additions = publicationResult === undefined ? {} : publicationResult;
|
|
438
|
+
|
|
439
|
+
if (!additions || typeof additions !== 'object' || Array.isArray(additions)) {
|
|
440
|
+
throw new TypeError('publication must return an object or undefined');
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
if (additions.aliases !== undefined && (!additions.aliases || typeof additions.aliases !== 'object' || Array.isArray(additions.aliases))) {
|
|
444
|
+
throw new TypeError('publication aliases must be a non-array object');
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
if (additions.extraFiles !== undefined && !Array.isArray(additions.extraFiles)) {
|
|
448
|
+
throw new TypeError('publication extraFiles must be an array');
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
for (const key of Object.keys(additions.aliases ?? {})) {
|
|
452
|
+
if (Object.hasOwn(aliases, key)) {
|
|
453
|
+
throw new Error(`Duplicate publication alias: ${key}`);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
438
456
|
const { release, version, manifest } = await packageFlatRelease({
|
|
439
|
-
|
|
440
|
-
|
|
457
|
+
extraFiles: additions.extraFiles,
|
|
458
|
+
retain: additions.retain,
|
|
459
|
+
previousPublic: resolve(root, 'public'),
|
|
460
|
+
root: outdir,
|
|
441
461
|
removeIntermediates: true,
|
|
442
462
|
flatDir,
|
|
443
463
|
entries,
|
|
444
464
|
ssrDir,
|
|
445
465
|
ssrNames,
|
|
446
466
|
standaloneAssets,
|
|
447
|
-
aliases,
|
|
467
|
+
aliases: { ...aliases, ...additions.aliases },
|
|
448
468
|
});
|
|
449
469
|
|
|
450
|
-
await publishFlatRelease({ root, wpRoot, release, manifest, version,
|
|
470
|
+
await publishFlatRelease({ root, wpRoot, release, manifest, version, publicPrefix: publicPath });
|
|
451
471
|
await clearBuildDirectory(outdir, root);
|
|
452
472
|
};
|
|
453
473
|
const defaultSsr = ({ root, mode }) => buildDefaultSsr({ root, mode, outdir: resolve(outdir, 'ssr', mode) });
|
package/package.json
CHANGED