@eightshift/frontend-libs-tailwind 3.5.0 → 4.0.0-beta.2

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/bun/media.mjs ADDED
@@ -0,0 +1,50 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { basename, dirname, resolve } from 'node:path';
3
+ import { allowPureJsxGrouping } from './plugin-capabilities.mjs';
4
+
5
+ /**
6
+ * Adapt the published UI Components smart-image worker for flat theme releases.
7
+ * Callbacks belong to one build and provide the worker to the publication step.
8
+ * Unsupported upstream worker URL forms fail rather than producing a broken URL.
9
+ */
10
+ export function editorWorkerPlugin({ setEditorWorker, getEditorWorker }) {
11
+ if (typeof setEditorWorker !== 'function' || typeof getEditorWorker !== 'function') {
12
+ throw new TypeError('Worker callbacks are required');
13
+ }
14
+
15
+ return allowPureJsxGrouping({
16
+ name: 'eightshift-editor-worker-url',
17
+ setup(builder) {
18
+ builder.onLoad({ filter: /[/\\]smart-image[/\\]smart-image\.js$/ }, async ({ path }) => {
19
+ if (!/[/\\]@eightshift[/\\]ui-components[/\\]/.test(path)) {
20
+ return;
21
+ }
22
+
23
+ const source = await readFile(path, 'utf8');
24
+
25
+ if (!source.includes('image-analysis-worker')) {
26
+ return;
27
+ }
28
+
29
+ const pattern = /new URL\("" \+ new URL\("(\.\.\/\.\.\/assets\/image-analysis-worker-[A-Za-z0-9_-]+\.js)", import\.meta\.url\)\.href \+ "", "" \+ import\.meta\.url\)/g;
30
+ const matches = [...source.matchAll(pattern)];
31
+
32
+ if (matches.length !== 1) {
33
+ throw new Error(`Unsupported smart-image worker URL in ${path}; configure media.editorWorker to override`);
34
+ }
35
+
36
+ const worker = resolve(dirname(path), matches[0][1]);
37
+ const previous = getEditorWorker();
38
+
39
+ if (previous && (basename(previous) !== basename(worker) || !(await readFile(previous)).equals(await readFile(worker)))) {
40
+ throw new Error('Conflicting smart-image workers');
41
+ }
42
+
43
+ setEditorWorker(worker);
44
+ const base = '(typeof __eightshiftEditorScriptUrl !== "undefined" ? __eightshiftEditorScriptUrl : (() => { throw new Error("Smart-image worker requires the Eightshift editor script URL; override media.editorWorker for other bundles"); })())';
45
+
46
+ return { contents: source.replace(pattern, `new URL(${JSON.stringify(`editor-assets/${basename(worker)}`)}, ${base})`), loader: 'js', resolveDir: dirname(path) };
47
+ });
48
+ },
49
+ });
50
+ }
@@ -0,0 +1,11 @@
1
+ const pureJsxCompatible = new WeakMap();
2
+
3
+ // Only audited built-ins may participate; plugin names are not a trust boundary.
4
+ export function allowPureJsxGrouping(plugin) {
5
+ pureJsxCompatible.set(plugin, plugin.setup);
6
+ return plugin;
7
+ }
8
+
9
+ export function supportsPureJsxGrouping(plugin) {
10
+ return pureJsxCompatible.has(plugin) && pureJsxCompatible.get(plugin) === plugin.setup;
11
+ }
package/bun/preset.mjs ADDED
@@ -0,0 +1,120 @@
1
+ import { isAbsolute, relative, resolve, sep } from 'node:path';
2
+ import { build } from './build.mjs';
3
+ import { processEightshiftCss } from './eightshift-css.mjs';
4
+
5
+ const checkOptions = (value, keys, label) => {
6
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
7
+ throw new TypeError(`${label} must be an object`);
8
+ }
9
+
10
+ for (const key of Object.keys(value)) {
11
+ if (!keys.includes(key)) {
12
+ throw new TypeError(`Unknown ${label} option: ${key}`);
13
+ }
14
+ }
15
+ };
16
+
17
+ const feature = (value, keys, label) => {
18
+ if (value === undefined || value === false) {
19
+ return undefined;
20
+ }
21
+
22
+ checkOptions(value, keys, label);
23
+
24
+ return { ...value };
25
+ };
26
+
27
+ /**
28
+ * Create build options for a project. No layout or entrypoints are assumed.
29
+ * discovery and responsive are disabled unless configured. CSS is disabled
30
+ * unless configured as a callback or an array of Eightshift surface options.
31
+ * Set wordpress: false to bundle dependencies instead of externalizing them.
32
+ * Configure Bun target, format, naming and splitting via buildOptions.
33
+ * Entry points, staging output and write mode are controlled by build.
34
+ * editor: { entry, filename, chunkDir, scriptUrlIdentifier, discovery, lazy, sharing, pureJsxGroups }
35
+ * builds classic registration with lazy ESM chunks by default.
36
+ * sharing: 'native' bundles lazy targets together; the default is 'independent'.
37
+ * sharing: 'unified' also moves registration to ESM and requires readiness integration.
38
+ * discovery configures eightshiftDiscovery; lazy configures editorLazyImports.
39
+ * Both are opt-in, and all filenames and discovery behavior are overridable.
40
+ */
41
+ export function createPreset(options = {}) {
42
+ checkOptions(options, ['root', 'outdir', 'entries', 'wpRoot', 'wordpress', 'discovery', 'responsive', 'css', 'editor', 'buildOptions', 'direct'], 'preset');
43
+ const { root = process.cwd(), outdir, entries, wpRoot, wordpress = true, buildOptions = {}, direct = false } = options;
44
+
45
+ if (typeof root !== 'string' || !root || typeof outdir !== 'string' || !outdir) {
46
+ throw new TypeError('root and outdir must be non-empty strings');
47
+ }
48
+
49
+ if (!entries || typeof entries !== 'object' || Array.isArray(entries) || !Object.keys(entries).length) {
50
+ throw new TypeError('entries must contain named entrypoints');
51
+ }
52
+
53
+ if (typeof wordpress !== 'boolean') {
54
+ throw new TypeError('wordpress must be a boolean');
55
+ }
56
+
57
+ if (wpRoot !== undefined && (typeof wpRoot !== 'string' || !wpRoot)) {
58
+ throw new TypeError('wpRoot must be a non-empty string');
59
+ }
60
+
61
+ if (!buildOptions || typeof buildOptions !== 'object' || Array.isArray(buildOptions)) {
62
+ throw new TypeError('buildOptions must be an object');
63
+ }
64
+
65
+ for (const key of ['entrypoints', 'outdir', 'write']) {
66
+ if (Object.hasOwn(buildOptions, key)) {
67
+ throw new TypeError(`buildOptions.${key} is controlled by build`);
68
+ }
69
+ }
70
+
71
+ const editor = feature(options.editor, ['entry', 'chunkDir', 'filename', 'scriptUrlIdentifier', 'discovery', 'lazy', 'sharing', 'pureJsxGroups'], 'editor');
72
+ const discovery = feature(options.discovery, ['output', 'definitions'], 'discovery');
73
+ const responsive = feature(options.responsive, ['breakpoints', 'manifestGlob', 'output'], 'responsive');
74
+
75
+ if (responsive?.output !== undefined) {
76
+ checkOptions(responsive.output, ['frontend', 'editor'], 'responsive.output');
77
+ }
78
+
79
+ let css;
80
+
81
+ if (options.css !== undefined && options.css !== false) {
82
+ if (typeof options.css === 'function') {
83
+ css = options.css;
84
+ } else {
85
+ if (!Array.isArray(options.css)) {
86
+ throw new TypeError('css must be false, a function, or an array of surfaces');
87
+ }
88
+
89
+ const surfaces = options.css.map((surface) => {
90
+ checkOptions(surface, ['surface', 'outputFile', 'production', 'browsers', 'blocksDir', 'manifestGlob', 'tailwindFile', 'colorThemesFile', 'applicationFile', 'groups', 'scanExclusions', 'responsiveSource', 'responsiveFile'], 'css surface');
91
+
92
+ if (!['frontend', 'editor', 'admin'].includes(surface.surface) || typeof surface.outputFile !== 'string' || !surface.outputFile || isAbsolute(surface.outputFile)) {
93
+ throw new TypeError('Each CSS surface requires a valid surface and relative outputFile');
94
+ }
95
+
96
+ return { ...surface };
97
+ });
98
+
99
+ css = async ({ root: projectDir, outdir: stage, responsive: generated }) => {
100
+ for (const { outputFile, ...surface } of surfaces) {
101
+ const output = resolve(stage, outputFile);
102
+ const location = relative(stage, output);
103
+
104
+ if (!location || location === '..' || location.startsWith(`..${sep}`) || isAbsolute(location)) {
105
+ throw new Error(`CSS output escapes staging: ${outputFile}`);
106
+ }
107
+
108
+ await processEightshiftCss({ ...surface, projectDir, outputFile: output, responsiveFile: surface.responsiveFile ?? generated?.[surface.surface] });
109
+ }
110
+ };
111
+ }
112
+ }
113
+
114
+ return { root, outdir, entries: { ...entries }, wpRoot, wordpress, discovery, responsive, css, editor, direct, buildOptions: { ...buildOptions } };
115
+ }
116
+
117
+ /** Build and atomically publish a configured preset. */
118
+ export async function buildPreset(options) {
119
+ return build(createPreset(options));
120
+ }
@@ -0,0 +1,236 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { cp, lstat, mkdir, readFile, readdir, rename, rm, unlink, writeFile } from 'node:fs/promises';
3
+ import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
4
+
5
+ const exists = async (path) => {
6
+ try {
7
+ return await lstat(path);
8
+ } catch (error) {
9
+ if (error.code === 'ENOENT') {
10
+ return null;
11
+ }
12
+
13
+ throw error;
14
+ }
15
+ };
16
+ const pathName = (value) => {
17
+ if (typeof value !== 'string' || !value || isAbsolute(value) || value.includes('\\') || value.includes('\0') || value.split('/').some((part) => !part || part === '.' || part === '..')) {
18
+ throw new Error(`Invalid manifest path: ${String(value)}`);
19
+ }
20
+
21
+ return value;
22
+ };
23
+ const inside = (parent, child) => {
24
+ const path = relative(parent, child);
25
+
26
+ return !path || (!path.startsWith(`..${sep}`) && path !== '..' && !isAbsolute(path));
27
+ };
28
+
29
+ /**
30
+ * Publish a packageRelease directory without deleting unrelated public files.
31
+ * root is the theme root; publicDir defaults to root/public. publicPrefix is
32
+ * the URL prefix including its trailing slash. manifest maps keys to paths in
33
+ * release. Existing PHP manifest cache assets are updated;
34
+ * missing caches are left alone. Returns { publicDir, manifest }.
35
+ */
36
+ export async function publishRelease({ root, release, manifest, publicDir, publicPrefix }) {
37
+ if (
38
+ typeof root !== 'string' ||
39
+ !root ||
40
+ typeof release !== 'string' ||
41
+ !release ||
42
+ !manifest ||
43
+ typeof manifest !== 'object' ||
44
+ Array.isArray(manifest) ||
45
+ typeof publicPrefix !== 'string' ||
46
+ !publicPrefix.startsWith('/') ||
47
+ publicPrefix.startsWith('//') ||
48
+ !publicPrefix.endsWith('/') ||
49
+ publicPrefix.split('/').includes('..')
50
+ ) {
51
+ throw new TypeError('Expected root, release, manifest and an absolute publicPrefix ending in /');
52
+ }
53
+
54
+ root = resolve(root);
55
+ release = resolve(release);
56
+ publicDir = resolve(root, publicDir ?? 'public');
57
+
58
+ if (inside(publicDir, release) || inside(release, publicDir) || publicDir === root || inside(publicDir, root)) {
59
+ throw new Error('Release, root and public directory must be distinct');
60
+ }
61
+
62
+ const cachePath = join(root, 'eightshift/manifests.json');
63
+
64
+ if (inside(publicDir, cachePath) || inside(release, cachePath)) {
65
+ throw new Error('Cache must be outside publication and release directories');
66
+ }
67
+
68
+ const parent = dirname(publicDir);
69
+ const stage = join(parent, `.public-stage-${randomUUID()}`);
70
+ const backup = join(parent, `.public-backup-${randomUUID()}`);
71
+ let staged = false;
72
+ let backedUp = false;
73
+ let published = false;
74
+ let cacheTemporary;
75
+
76
+ try {
77
+ await mkdir(parent, { recursive: true });
78
+ const releaseInfo = await lstat(release);
79
+
80
+ if (!releaseInfo.isDirectory() || releaseInfo.isSymbolicLink()) {
81
+ throw new Error('Release must be a directory');
82
+ }
83
+
84
+ const publicInfo = await exists(publicDir);
85
+
86
+ if (publicInfo && (!publicInfo.isDirectory() || publicInfo.isSymbolicLink())) {
87
+ throw new Error('Refusing to replace non-directory public path');
88
+ }
89
+
90
+ const publicManifest = Object.create(null);
91
+
92
+ for (const [key, value] of Object.entries(manifest)) {
93
+ pathName(key);
94
+ pathName(value);
95
+ publicManifest[key] = `${publicPrefix}${value}`;
96
+ }
97
+
98
+ // Include unaliased flat files, as the theme's legacy publisher did.
99
+ for (const name of await readdir(release)) {
100
+ const info = await lstat(join(release, name));
101
+
102
+ if (info.isSymbolicLink() || (!info.isDirectory() && !info.isFile())) {
103
+ throw new Error(`Unsupported release output: ${name}`);
104
+ }
105
+
106
+ if (info.isFile() && name !== 'manifest.json' && !Object.hasOwn(publicManifest, name)) {
107
+ publicManifest[name] = `${publicPrefix}${name}`;
108
+ }
109
+ }
110
+
111
+ for (const value of Object.values(manifest)) {
112
+ let current = release;
113
+
114
+ for (const part of value.split('/')) {
115
+ current = join(current, part);
116
+ const info = await lstat(current);
117
+
118
+ if (info.isSymbolicLink()) {
119
+ throw new Error(`Symlink in release path: ${value}`);
120
+ }
121
+ }
122
+
123
+ if (!(await lstat(current)).isFile()) {
124
+ throw new Error(`Manifest target is not a file: ${value}`);
125
+ }
126
+ }
127
+
128
+ await mkdir(stage);
129
+ staged = true;
130
+
131
+ if (publicInfo) {
132
+ await cp(publicDir, stage, { recursive: true, verbatimSymlinks: true });
133
+ }
134
+
135
+ // Never follow pre-existing symlinks when overlaying release files.
136
+ const overlay = async (source, destination) => {
137
+ for (const name of await readdir(source)) {
138
+ const from = join(source, name);
139
+ const to = join(destination, name);
140
+ const info = await lstat(from);
141
+ const old = await exists(to);
142
+
143
+ if (info.isSymbolicLink() || (!info.isDirectory() && !info.isFile())) {
144
+ throw new Error(`Unsupported release output: ${from}`);
145
+ }
146
+
147
+ if (old && (old.isSymbolicLink() || (info.isDirectory() ? !old.isDirectory() : !old.isFile()))) {
148
+ throw new Error(`Publication path conflict: ${to}`);
149
+ }
150
+
151
+ if (info.isDirectory()) {
152
+ await mkdir(to, { recursive: true });
153
+ await overlay(from, to);
154
+ } else {
155
+ await cp(from, to);
156
+ }
157
+ }
158
+ };
159
+
160
+ await overlay(release, stage);
161
+ const manifestPath = join(stage, 'manifest.json');
162
+ const manifestInfo = await exists(manifestPath);
163
+
164
+ if (manifestInfo && (!manifestInfo.isFile() || manifestInfo.isSymbolicLink())) {
165
+ throw new Error('Publication manifest path conflict');
166
+ }
167
+
168
+ await writeFile(manifestPath, `${JSON.stringify(publicManifest, null, 2)}\n`);
169
+ const cacheInfo = await exists(cachePath);
170
+ let cacheData;
171
+
172
+ if (cacheInfo) {
173
+ if (!cacheInfo.isFile() || cacheInfo.isSymbolicLink()) {
174
+ throw new Error('Manifest cache must be a regular file');
175
+ }
176
+
177
+ cacheData = JSON.parse(await readFile(cachePath, 'utf8'));
178
+
179
+ if (!cacheData?.assets || Array.isArray(cacheData.assets) || typeof cacheData.assets !== 'object' || !cacheData.assets.assets || Array.isArray(cacheData.assets.assets) || typeof cacheData.assets.assets !== 'object') {
180
+ throw new Error('Invalid manifest cache structure');
181
+ }
182
+
183
+ cacheData.assets.assets = publicManifest;
184
+ cacheTemporary = `${cachePath}.${randomUUID()}`;
185
+ await writeFile(cacheTemporary, JSON.stringify(cacheData), { flag: 'wx', mode: cacheInfo.mode });
186
+ }
187
+
188
+ if (publicInfo) {
189
+ await rename(publicDir, backup);
190
+ backedUp = true;
191
+ }
192
+
193
+ await rename(stage, publicDir);
194
+ staged = false;
195
+ published = true;
196
+
197
+ if (cacheTemporary) {
198
+ await rename(cacheTemporary, cachePath);
199
+ cacheTemporary = undefined;
200
+ }
201
+
202
+ if (backedUp) {
203
+ backedUp = false;
204
+ await rm(backup, { recursive: true }).catch((error) => {
205
+ console.error(`Could not remove publication backup ${backup}:`, error);
206
+ });
207
+ }
208
+
209
+ return { publicDir, manifest: { ...publicManifest } };
210
+ } catch (error) {
211
+ if (published && (await exists(publicDir))) {
212
+ await rename(publicDir, stage).then(() => {
213
+ staged = true;
214
+ });
215
+ }
216
+
217
+ if (backedUp) {
218
+ await rename(backup, publicDir);
219
+ backedUp = false;
220
+ }
221
+
222
+ throw error;
223
+ } finally {
224
+ if (cacheTemporary) {
225
+ await unlink(cacheTemporary).catch((error) => {
226
+ if (error.code !== 'ENOENT') {
227
+ throw error;
228
+ }
229
+ });
230
+ }
231
+
232
+ if (staged) {
233
+ await rm(stage, { recursive: true, force: true });
234
+ }
235
+ }
236
+ }
@@ -0,0 +1,207 @@
1
+ import { createHash, randomUUID } from 'node:crypto';
2
+ import { lstat, mkdir, readFile, readdir, writeFile } from 'node:fs/promises';
3
+ import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
4
+
5
+ const digest = (value) => createHash('sha256').update(value).digest('hex');
6
+
7
+ async function ensureDirectory(directory, root) {
8
+ const location = root && relative(root, directory);
9
+ const withinRoot = root && (!location || (!isAbsolute(location) && location !== '..' && !location.startsWith(`..${sep}`)));
10
+ const parent = dirname(directory);
11
+ if (parent !== directory && (!withinRoot || directory !== root)) {
12
+ await ensureDirectory(parent, root);
13
+ }
14
+
15
+ try {
16
+ await mkdir(directory, { recursive: directory === root });
17
+ } catch (error) {
18
+ if (error.code !== 'EEXIST') {
19
+ throw error;
20
+ }
21
+ }
22
+
23
+ const info = await lstat(directory);
24
+ if (!info.isDirectory() || info.isSymbolicLink()) {
25
+ throw new Error(`Release path must be a real directory: ${directory}`);
26
+ }
27
+ }
28
+
29
+ const releasePath = (value) => {
30
+ if (typeof value !== 'string' || !value || value.includes('\\') || value.includes('\0') || isAbsolute(value) || value.split('/').some((part) => !part || part === '.' || part === '..')) {
31
+ throw new Error(`Invalid release path: ${String(value)}`);
32
+ }
33
+
34
+ return value;
35
+ };
36
+
37
+ /**
38
+ * Package a WordPress release without modifying or deleting existing releases.
39
+ *
40
+ * files: [{ source, destination }] copies files or directory trees.
41
+ * entries: [{ name, entry, style, dependencies, script? }] generates the root
42
+ * scripts and WordPress asset metadata. script supplies the entry wrapper code;
43
+ * otherwise a dynamic-import bootstrap loads entry relative to the root script.
44
+ * Unified editor scripts declare format: 'module', readiness: 'eightshift-editor-v1';
45
+ * their static-import wrapper must be loaded by matching module-aware PHP integration.
46
+ * aliases maps additional flat manifest keys to packaged paths.
47
+ * Returns { release, version, manifest }. A failed staging directory is retained.
48
+ * outputDirectory writes directly to an existing directory instead of staging.
49
+ */
50
+ export async function packageRelease({ root, files, entries, aliases = {}, outputDirectory, omit = [] }) {
51
+ if (typeof root !== 'string' || !root || !Array.isArray(files) || !Array.isArray(entries) || !entries.length || !aliases || typeof aliases !== 'object' || Array.isArray(aliases)) {
52
+ throw new TypeError('Expected root, files, entries and optional aliases');
53
+ }
54
+
55
+ const contents = new Map();
56
+ const add = (path, bytes) => {
57
+ releasePath(path);
58
+
59
+ if (contents.has(path)) {
60
+ throw new Error(`Duplicate release path: ${path}`);
61
+ }
62
+
63
+ contents.set(path, bytes);
64
+ };
65
+ const collect = async (source, destination) => {
66
+ const info = await lstat(source);
67
+
68
+ if (info.isSymbolicLink()) {
69
+ throw new Error(`Symlinks are not supported: ${source}`);
70
+ }
71
+
72
+ if (info.isDirectory()) {
73
+ for (const name of (await readdir(source)).sort()) {
74
+ await collect(join(source, name), `${destination}/${name}`);
75
+ }
76
+ } else if (info.isFile()) {
77
+ const bytes = await readFile(source);
78
+
79
+ add(destination, bytes);
80
+ } else {
81
+ throw new Error(`Unsupported release file: ${source}`);
82
+ }
83
+ };
84
+
85
+ for (const file of files) {
86
+ if (!file || typeof file.source !== 'string' || !file.source) {
87
+ throw new TypeError('Each file requires a source and destination');
88
+ }
89
+
90
+ await collect(resolve(file.source), releasePath(file.destination));
91
+ }
92
+
93
+ const manifest = Object.create(null);
94
+ const setManifest = (key, value) => {
95
+ releasePath(key);
96
+ releasePath(value);
97
+
98
+ if (Object.hasOwn(manifest, key)) {
99
+ throw new Error(`Duplicate manifest key: ${key}`);
100
+ }
101
+
102
+ manifest[key] = value;
103
+ };
104
+ const scripts = new Map();
105
+
106
+ for (const entry of entries) {
107
+ if (!entry || typeof entry.name !== 'string' || !/^[A-Za-z0-9_-]+$/.test(entry.name) || !Array.isArray(entry.dependencies) || entry.dependencies.some((dependency) => typeof dependency !== 'string' || !dependency)) {
108
+ throw new TypeError('Invalid release entry');
109
+ }
110
+
111
+ const target = releasePath(entry.entry);
112
+ const style = releasePath(entry.style);
113
+
114
+ if (!contents.has(target) || !contents.has(style) || !contents.get(target).length || !contents.get(style).length) {
115
+ throw new Error(`Missing or empty entry or style for ${entry.name}`);
116
+ }
117
+
118
+ if (entry.script !== undefined && (typeof entry.script !== 'string' || !entry.script.trim())) {
119
+ throw new TypeError(`Invalid script for ${entry.name}`);
120
+ }
121
+
122
+ if (entry.format !== undefined && entry.format !== 'module') {
123
+ throw new TypeError(`Unsupported script format for ${entry.name}`);
124
+ }
125
+ if (entry.format === 'module' && (entry.readiness !== 'eightshift-editor-v1' || entry.script === undefined)) {
126
+ throw new TypeError(`Module entry ${entry.name} requires an explicit script and readiness contract`);
127
+ }
128
+ if (entry.readiness !== undefined && entry.format !== 'module') {
129
+ throw new TypeError(`Readiness requires a module entry: ${entry.name}`);
130
+ }
131
+
132
+ const script = entry.script ?? `(() => { const url = new URL(${JSON.stringify(target)}, document.currentScript.src); import(url.href).catch((error) => console.error(${JSON.stringify(`Failed to load ${entry.name}:`)}, error)); })();\n`;
133
+
134
+ if (scripts.has(entry.name)) {
135
+ throw new Error(`Duplicate entry: ${entry.name}`);
136
+ }
137
+
138
+ scripts.set(entry.name, { script, dependencies: entry.dependencies, ...(entry.format === 'module' ? { format: entry.format, readiness: entry.readiness } : {}) });
139
+ const scriptName = `${entry.name}-${digest(script)}.js`;
140
+ const styleBytes = contents.get(style);
141
+ const styleName = `${entry.name}-${digest(styleBytes)}.css`;
142
+
143
+ if (contents.has(scriptName)) {
144
+ throw new Error(`Duplicate release path: ${scriptName}`);
145
+ }
146
+
147
+ if (contents.has(styleName)) {
148
+ throw new Error(`Duplicate release path: ${styleName}`);
149
+ }
150
+
151
+ add(styleName, styleBytes);
152
+ setManifest(`${entry.name}.js`, scriptName);
153
+ setManifest(`${entry.name}.css`, styleName);
154
+ setManifest(`${entry.name}.asset.json`, `${entry.name}.asset.json`);
155
+ setManifest(`${entry.name}.json`, `${entry.name}.asset.json`);
156
+ }
157
+
158
+ for (const [key, value] of Object.entries(aliases)) {
159
+ if (!contents.has(value)) {
160
+ throw new Error(`Missing manifest target: ${value}`);
161
+ }
162
+
163
+ setManifest(key, value);
164
+ }
165
+
166
+ if (!Array.isArray(omit)) {
167
+ throw new TypeError('omit must be an array');
168
+ }
169
+ for (const path of omit) {
170
+ releasePath(path);
171
+ if (Object.values(manifest).includes(path)) {
172
+ throw new Error(`Cannot omit manifest target: ${path}`);
173
+ }
174
+ if (!contents.delete(path)) {
175
+ throw new Error(`Cannot omit missing release file: ${path}`);
176
+ }
177
+ }
178
+
179
+ const inventory = Object.fromEntries([...contents].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)).map(([path, bytes]) => [path, digest(bytes)]));
180
+ const version = digest(JSON.stringify({ format: 1, inventory, scripts: [...scripts].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)), manifest }));
181
+
182
+ for (const [name, { script, dependencies, format, readiness }] of scripts) {
183
+ add(manifest[`${name}.js`], Buffer.from(script));
184
+ add(`${name}.asset.json`, Buffer.from(`${JSON.stringify({ dependencies, version, ...(format === 'module' ? { format, readiness } : {}) }, null, 2)}\n`));
185
+ }
186
+
187
+ add('manifest.json', Buffer.from(`${JSON.stringify(manifest, null, 2)}\n`));
188
+ const parent = resolve(root);
189
+
190
+ await ensureDirectory(parent, parent);
191
+ const release = outputDirectory ? resolve(outputDirectory) : join(parent, `release-${randomUUID()}`, version);
192
+
193
+ await ensureDirectory(release, parent);
194
+
195
+ for (const [path, bytes] of contents) {
196
+ const target = resolve(release, ...path.split('/'));
197
+
198
+ if (relative(release, target).startsWith(`..${sep}`)) {
199
+ throw new Error(`Invalid release path: ${path}`);
200
+ }
201
+
202
+ await ensureDirectory(dirname(target), parent);
203
+ await writeFile(target, bytes, { flag: 'wx' });
204
+ }
205
+
206
+ return { release, version, manifest: { ...manifest } };
207
+ }