@eightshift/frontend-libs-tailwind 4.0.0-beta.4 → 4.0.0-beta.5
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 +21 -0
- package/README.md +85 -11
- package/bin/tw-sweep.mjs +35 -14
- package/bun/browser-css.mjs +487 -0
- package/bun/build.mjs +20 -1
- package/bun/cli-supervisor.mjs +70 -14
- package/bun/cli-worker.mjs +22 -5
- package/bun/css.mjs +126 -25
- package/bun/discovery.mjs +12 -1
- package/bun/editor-native.mjs +38 -0
- package/bun/editor-pure-jsx.mjs +88 -0
- package/bun/editor.mjs +33 -0
- package/bun/eightshift-discovery.mjs +102 -26
- package/bun/flat-publication.mjs +19 -184
- package/bun/index.mjs +14 -0
- package/bun/media.mjs +16 -4
- package/bun/plugin-capabilities.mjs +1 -0
- package/bun/preset.mjs +6 -4
- package/bun/publish.mjs +7 -4
- package/bun/release.mjs +56 -4
- package/bun/shared-fonts.mjs +62 -12
- package/bun/structured-publication.mjs +66 -0
- package/bun/theme-build.mjs +119 -43
- package/bun/theme-discovery.mjs +113 -9
- package/bun/watch.mjs +32 -0
- package/bun/wordpress.mjs +49 -23
- package/eslint.config.mjs +22 -1
- package/linters/base.config.mjs +1 -0
- package/linters/tw-sweep-extract.mjs +5 -0
- package/package.json +5 -5
- package/scripts/components/link-section-editor.js +1 -0
- package/scripts/editor/editor.js +1 -0
- package/scripts/editor/registration.js +3 -0
- package/scripts/editor/store.js +7 -0
- package/test/bun-discovery.test.mjs +69 -0
- package/test/bun-publication.test.mjs +144 -0
- package/test/bun-theme-build.test.mjs +12 -0
- package/test/bun-wordpress.test.mjs +82 -0
- package/test/fixtures/theme-build-regressions.mjs +585 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Linter } from 'eslint';
|
|
1
2
|
import { createHash } from 'node:crypto';
|
|
2
3
|
import { realpathSync } from 'node:fs';
|
|
3
4
|
import { readFile } from 'node:fs/promises';
|
|
@@ -6,6 +7,51 @@ import { dirname, resolve, relative, sep } from 'node:path';
|
|
|
6
7
|
import { generateDiscovery } from './discovery.mjs';
|
|
7
8
|
import { allowPureJsxGrouping } from './plugin-capabilities.mjs';
|
|
8
9
|
|
|
10
|
+
const linter = new Linter();
|
|
11
|
+
|
|
12
|
+
function executableCalls(source, path) {
|
|
13
|
+
const contexts = [];
|
|
14
|
+
const imports = [];
|
|
15
|
+
const identifiers = new Set();
|
|
16
|
+
const messages = linter.verify(
|
|
17
|
+
source,
|
|
18
|
+
[
|
|
19
|
+
{
|
|
20
|
+
languageOptions: { ecmaVersion: 'latest', sourceType: 'module', parserOptions: { ecmaFeatures: { jsx: true } } },
|
|
21
|
+
linterOptions: { noInlineConfig: true },
|
|
22
|
+
plugins: {
|
|
23
|
+
capture: {
|
|
24
|
+
rules: {
|
|
25
|
+
calls: {
|
|
26
|
+
create: () => ({
|
|
27
|
+
Identifier: (node) => identifiers.add(node.name),
|
|
28
|
+
CallExpression: (node) => {
|
|
29
|
+
const callee = node.callee;
|
|
30
|
+
|
|
31
|
+
if (callee.type === 'MemberExpression' && !callee.computed && callee.object.type === 'Identifier' && callee.object.name === 'require' && callee.property.name === 'context') {
|
|
32
|
+
contexts.push(node);
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
ImportExpression: (node) => imports.push(node),
|
|
36
|
+
}),
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
rules: { 'capture/calls': 'error' },
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
{ filename: 'module.js' },
|
|
45
|
+
);
|
|
46
|
+
const fatal = messages.find((message) => message.fatal);
|
|
47
|
+
|
|
48
|
+
if (fatal) {
|
|
49
|
+
throw new Error(`Cannot parse ${path}: ${fatal.message}`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return { contexts: contexts.sort((a, b) => a.start - b.start), imports, identifiers };
|
|
53
|
+
}
|
|
54
|
+
|
|
9
55
|
/**
|
|
10
56
|
* Migrate literal webpack require.context calls in selected source files.
|
|
11
57
|
* Generated modules live in outputDir and must be regenerated on rebuild.
|
|
@@ -31,15 +77,14 @@ export function eightshiftDiscovery({ root, outputDir, filter = /\.[cm]?jsx?$/,
|
|
|
31
77
|
|
|
32
78
|
const source = await readFile(path, 'utf8');
|
|
33
79
|
|
|
34
|
-
if (!source.includes('require.context')) {
|
|
80
|
+
if (!source.includes('require') || !source.includes('context')) {
|
|
35
81
|
return;
|
|
36
82
|
}
|
|
37
83
|
|
|
38
|
-
const
|
|
39
|
-
const matches = [...source.matchAll(pattern)];
|
|
84
|
+
const { contexts: matches, identifiers } = executableCalls(source, path);
|
|
40
85
|
|
|
41
86
|
if (!matches.length) {
|
|
42
|
-
|
|
87
|
+
return;
|
|
43
88
|
}
|
|
44
89
|
|
|
45
90
|
const definitions = [];
|
|
@@ -47,16 +92,38 @@ export function eightshiftDiscovery({ root, outputDir, filter = /\.[cm]?jsx?$/,
|
|
|
47
92
|
let offset = 0;
|
|
48
93
|
|
|
49
94
|
for (const match of matches) {
|
|
50
|
-
const [, ,
|
|
95
|
+
const [directoryNode, recursiveNode, patternNode, modeNode] = match.arguments;
|
|
96
|
+
|
|
97
|
+
if (
|
|
98
|
+
match.optional ||
|
|
99
|
+
match.arguments.length < 3 ||
|
|
100
|
+
match.arguments.length > 4 ||
|
|
101
|
+
directoryNode?.type !== 'Literal' ||
|
|
102
|
+
typeof directoryNode.value !== 'string' ||
|
|
103
|
+
recursiveNode?.type !== 'Literal' ||
|
|
104
|
+
typeof recursiveNode.value !== 'boolean' ||
|
|
105
|
+
!patternNode?.regex ||
|
|
106
|
+
(modeNode && (modeNode.type !== 'Literal' || !['sync', 'lazy'].includes(modeNode.value)))
|
|
107
|
+
) {
|
|
108
|
+
throw new Error(`Unsupported require.context in ${path}`);
|
|
109
|
+
}
|
|
51
110
|
|
|
52
|
-
if (
|
|
111
|
+
if (!recursiveNode.value) {
|
|
53
112
|
throw new Error(`Nonrecursive require.context is unsupported in ${path}`);
|
|
54
113
|
}
|
|
55
114
|
|
|
56
|
-
const
|
|
57
|
-
const
|
|
115
|
+
const directory = directoryNode.value;
|
|
116
|
+
const context = { path, directory, pattern: new RegExp(patternNode.regex.pattern, patternNode.regex.flags), mode: modeNode?.value ?? 'sync' };
|
|
117
|
+
let index = definitions.length;
|
|
118
|
+
let name = `context${index}`;
|
|
119
|
+
|
|
120
|
+
while (identifiers.has(name)) {
|
|
121
|
+
name = `context${++index}`;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
identifiers.add(name);
|
|
58
125
|
|
|
59
|
-
contents += source.slice(offset, match.
|
|
126
|
+
contents += source.slice(offset, match.start);
|
|
60
127
|
|
|
61
128
|
if (omitContexts(context)) {
|
|
62
129
|
contents += 'Object.assign(() => ({}), { keys: () => [] })';
|
|
@@ -65,15 +132,11 @@ export function eightshiftDiscovery({ root, outputDir, filter = /\.[cm]?jsx?$/,
|
|
|
65
132
|
contents += name;
|
|
66
133
|
}
|
|
67
134
|
|
|
68
|
-
offset = match.
|
|
135
|
+
offset = match.end;
|
|
69
136
|
}
|
|
70
137
|
|
|
71
138
|
contents += source.slice(offset);
|
|
72
139
|
|
|
73
|
-
if (contents.includes('require.context')) {
|
|
74
|
-
throw new Error(`Unsupported require.context remains in ${path}`);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
140
|
if (definitions.length) {
|
|
78
141
|
const id = createHash('sha256').update(relative(root, path)).digest('hex').slice(0, 20);
|
|
79
142
|
const output = resolve(outputDir, `${id}.mjs`);
|
|
@@ -88,6 +151,7 @@ export function eightshiftDiscovery({ root, outputDir, filter = /\.[cm]?jsx?$/,
|
|
|
88
151
|
});
|
|
89
152
|
},
|
|
90
153
|
};
|
|
154
|
+
|
|
91
155
|
return transformSource ? plugin : allowPureJsxGrouping(plugin);
|
|
92
156
|
}
|
|
93
157
|
|
|
@@ -106,18 +170,30 @@ export function editorLazyImports({ root, chunks, chunkDir = 'editor-chunks', sc
|
|
|
106
170
|
|
|
107
171
|
root = realpathSync(resolve(root));
|
|
108
172
|
const require = createRequire(import.meta.url);
|
|
109
|
-
const transformSource = (source, path) =>
|
|
110
|
-
!include(path)
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
173
|
+
const transformSource = (source, path) => {
|
|
174
|
+
if (!include(path) || !source.includes('import')) {
|
|
175
|
+
return source;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const { imports } = executableCalls(source, path);
|
|
179
|
+
let contents = source;
|
|
180
|
+
|
|
181
|
+
for (const node of imports.sort((a, b) => b.start - a.start)) {
|
|
182
|
+
if (node.source.type !== 'Literal' || typeof node.source.value !== 'string' || !node.source.value.startsWith('.') || node.options) {
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const target = require.resolve(resolve(dirname(path), node.source.value));
|
|
187
|
+
const name = chunks.get(target) ?? `${createHash('sha256').update(relative(root, target)).digest('hex').slice(0, 20)}.js`;
|
|
188
|
+
chunks.set(target, name);
|
|
189
|
+
const version = versioned ? '?v=00000000000000000000' : '';
|
|
190
|
+
const replacement = `import(new URL(${JSON.stringify(`${chunkDir}/${name}${version}`)}, ${scriptUrlIdentifier}).href)`;
|
|
191
|
+
contents = contents.slice(0, node.start) + replacement + contents.slice(node.end);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return contents;
|
|
195
|
+
};
|
|
196
|
+
|
|
121
197
|
const plugin = {
|
|
122
198
|
name: 'eightshift-editor-lazy-imports',
|
|
123
199
|
setup(builder) {
|
package/bun/flat-publication.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import { chmod, lstat, mkdir, readFile, readdir, rename, rmdir, unlink, writeFile } from 'node:fs/promises';
|
|
3
|
-
import {
|
|
3
|
+
import { dirname, isAbsolute, relative, resolve, sep } from 'node:path';
|
|
4
4
|
import { packageRelease } from './release.mjs';
|
|
5
5
|
|
|
6
6
|
const pathName = (value) => {
|
|
@@ -11,203 +11,30 @@ const pathName = (value) => {
|
|
|
11
11
|
return value;
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
/**
|
|
15
|
-
|
|
16
|
-
*/
|
|
17
|
-
export async function flattenAssets({ outdir, flatDir, directories = ['frontend', 'editor', 'admin', 'css'], extraSources = {}, editorEntry, editorScript }) {
|
|
18
|
-
const sources = new Map();
|
|
19
|
-
const collect = async (directory, prefix) => {
|
|
20
|
-
for (const item of await readdir(directory, { withFileTypes: true })) {
|
|
21
|
-
const path = `${prefix}/${item.name}`;
|
|
22
|
-
|
|
23
|
-
if (path === 'editor/discovery' || (item.isFile() && !prefix.includes('/') && item.name === `${prefix}.asset.json`)) {
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (item.isDirectory()) {
|
|
28
|
-
await collect(resolve(directory, item.name), path);
|
|
29
|
-
} else if (item.isFile()) {
|
|
30
|
-
sources.set(path, resolve(directory, item.name));
|
|
31
|
-
} else {
|
|
32
|
-
throw new Error(`Unsupported build output: ${path}`);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
for (const directory of directories) {
|
|
38
|
-
await collect(resolve(outdir, pathName(directory)), directory);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
for (const [path, source] of Object.entries(extraSources)) {
|
|
42
|
-
sources.set(pathName(path), source);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const targetsByName = new Map();
|
|
46
|
-
for (const target of sources.keys()) {
|
|
47
|
-
const name = basename(target);
|
|
48
|
-
const targets = targetsByName.get(name) ?? [];
|
|
49
|
-
targets.push(target);
|
|
50
|
-
targetsByName.set(name, targets);
|
|
51
|
-
}
|
|
52
|
-
const unusualTargets = [...targetsByName].filter(([name]) => !/^[\w.@+-]+$/.test(name)).flatMap(([, targets]) => targets);
|
|
53
|
-
const rewriteLegacy = (input, path) => {
|
|
54
|
-
let source = input;
|
|
55
|
-
const candidates = new Set(unusualTargets);
|
|
56
|
-
|
|
57
|
-
for (const match of input.matchAll(/[/'"=]([\w.@+-]+)/g)) {
|
|
58
|
-
for (const target of targetsByName.get(match[1]) ?? []) {
|
|
59
|
-
candidates.add(target);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
for (const target of candidates) {
|
|
64
|
-
const reference = posix.relative(posix.dirname(path), target);
|
|
65
|
-
|
|
66
|
-
if (!reference) {
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const variants = [reference];
|
|
71
|
-
|
|
72
|
-
if (!reference.startsWith('.')) {
|
|
73
|
-
variants.push(`./${reference}`);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (target.startsWith('editor/editor-assets/') || (target.startsWith('editor/') && path.startsWith('editor/'))) {
|
|
77
|
-
variants.push(target.slice('editor/'.length));
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
for (const value of variants) {
|
|
81
|
-
for (const quote of ['"', "'"]) {
|
|
82
|
-
source = source.replaceAll(`${quote}${value}${quote}`, `${quote}./${basename(target)}${quote}`);
|
|
83
|
-
source = source.replaceAll(`${quote}${value}?`, `${quote}./${basename(target)}?`);
|
|
84
|
-
source = source.replaceAll(`${quote}${value}#`, `${quote}./${basename(target)}#`);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
source = source.replaceAll(`sourceMappingURL=${value}`, `sourceMappingURL=./${basename(target)}`);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return source;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
const referencePatterns = new Map();
|
|
95
|
-
const rewrite = (input, path) => {
|
|
96
|
-
// Keep the existing source-map comment handling for map-bearing files.
|
|
97
|
-
if (input.includes('sourceMappingURL=')) {
|
|
98
|
-
return rewriteLegacy(input, path);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const directory = posix.dirname(path);
|
|
102
|
-
const editorPath = path.startsWith('editor/');
|
|
103
|
-
const cacheKey = `${directory}:${editorPath}`;
|
|
104
|
-
let cached = referencePatterns.get(cacheKey);
|
|
105
|
-
|
|
106
|
-
if (!cached) {
|
|
107
|
-
const references = new Map();
|
|
108
|
-
|
|
109
|
-
for (const target of sources.keys()) {
|
|
110
|
-
const reference = posix.relative(directory, target);
|
|
111
|
-
if (!reference) {
|
|
112
|
-
continue;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const variants = [reference];
|
|
116
|
-
if (!reference.startsWith('.')) {
|
|
117
|
-
variants.push(`./${reference}`);
|
|
118
|
-
}
|
|
119
|
-
if (target.startsWith('editor/editor-assets/') || (target.startsWith('editor/') && editorPath)) {
|
|
120
|
-
variants.push(target.slice('editor/'.length));
|
|
121
|
-
}
|
|
122
|
-
for (const value of variants) {
|
|
123
|
-
references.set(value, `./${basename(target)}`);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const alternatives = [...references.keys()].map((value) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|');
|
|
128
|
-
let pattern;
|
|
129
|
-
let fallback = alternatives.length > 200000;
|
|
130
|
-
|
|
131
|
-
if (alternatives && !fallback) {
|
|
132
|
-
try {
|
|
133
|
-
pattern = new RegExp(`(["'])(?:${alternatives})(?=\\1|[?#])`, 'g');
|
|
134
|
-
} catch (error) {
|
|
135
|
-
if (!(error instanceof SyntaxError)) {
|
|
136
|
-
throw error;
|
|
137
|
-
}
|
|
138
|
-
fallback = true;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
cached = { references, pattern, fallback };
|
|
142
|
-
referencePatterns.set(cacheKey, cached);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if (cached.fallback) {
|
|
146
|
-
return rewriteLegacy(input, path);
|
|
147
|
-
}
|
|
148
|
-
if (!cached.pattern) {
|
|
149
|
-
return input;
|
|
150
|
-
}
|
|
151
|
-
return input.replace(cached.pattern, (match, quote) => `${quote}${cached.references.get(match.slice(1))}`);
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
const contentFor = async (path) => {
|
|
155
|
-
const content = await readFile(sources.get(path));
|
|
156
|
-
return /\.(?:js|css|map)$/.test(basename(path)) ? Buffer.from(rewrite(content.toString(), path)) : content;
|
|
157
|
-
};
|
|
158
|
-
const outputNames = new Map();
|
|
159
|
-
for (const path of sources.keys()) {
|
|
160
|
-
if (path === editorEntry) {
|
|
161
|
-
continue;
|
|
162
|
-
}
|
|
163
|
-
const name = basename(path);
|
|
164
|
-
const previous = outputNames.get(name);
|
|
165
|
-
if (previous !== undefined) {
|
|
166
|
-
if (!(await contentFor(path)).equals(await contentFor(previous))) {
|
|
167
|
-
throw new Error(`Flat output collision: ${path} and ${previous}`);
|
|
168
|
-
}
|
|
169
|
-
} else {
|
|
170
|
-
outputNames.set(name, path);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
await mkdir(flatDir);
|
|
175
|
-
|
|
176
|
-
for (const [path] of sources) {
|
|
177
|
-
const name = basename(path);
|
|
178
|
-
|
|
179
|
-
if (path === editorEntry || outputNames.get(name) !== path) {
|
|
180
|
-
continue;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
await writeFile(resolve(flatDir, name), await contentFor(path), { flag: 'wx' });
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
if (editorEntry !== undefined) {
|
|
187
|
-
await writeFile(resolve(flatDir, 'editor-entry.js'), rewrite(editorScript, editorEntry), { flag: 'wx' });
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
return { sources, rewrite };
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/** Package flattened files, optional SSR files and standalone assets. */
|
|
194
|
-
export async function packageFlatRelease({ root, flatDir, entries, ssrDir, ssrNames = [], standaloneAssets = new Map(), aliases = {}, extraFiles = [], retain = [], previousPublic, outputDirectory, removeIntermediates = false }) {
|
|
14
|
+
/** Package prepared files, optional SSR files and standalone assets. */
|
|
15
|
+
export async function packageFlatRelease({ root, flatDir, entries, ssrDir, ssrNames = [], standaloneAssets = new Map(), aliases = {}, extraFiles = [], retain = [], previousPublic, outputDirectory, removeIntermediates = false, removeUnreferencedStyles = false }) {
|
|
195
16
|
if (!Array.isArray(extraFiles) || !Array.isArray(retain) || (retain.length && !previousPublic)) {
|
|
196
17
|
throw new TypeError('extraFiles and retain must be arrays; retention requires previousPublic');
|
|
197
18
|
}
|
|
19
|
+
|
|
198
20
|
const files = [...extraFiles];
|
|
21
|
+
|
|
199
22
|
for (const name of retain) {
|
|
200
23
|
pathName(name);
|
|
201
24
|
let source = resolve(previousPublic);
|
|
25
|
+
|
|
202
26
|
for (const part of name.split('/')) {
|
|
203
27
|
source = resolve(source, part);
|
|
28
|
+
|
|
204
29
|
if ((await lstat(source)).isSymbolicLink()) {
|
|
205
30
|
throw new Error(`Symlink in retained path: ${name}`);
|
|
206
31
|
}
|
|
207
32
|
}
|
|
33
|
+
|
|
208
34
|
if (!(await lstat(source)).isFile()) {
|
|
209
35
|
throw new Error(`Retained path must be an exact file: ${name}`);
|
|
210
36
|
}
|
|
37
|
+
|
|
211
38
|
files.push({ source, destination: name });
|
|
212
39
|
}
|
|
213
40
|
|
|
@@ -235,15 +62,17 @@ export async function packageFlatRelease({ root, flatDir, entries, ssrDir, ssrNa
|
|
|
235
62
|
}
|
|
236
63
|
|
|
237
64
|
const omitted = removeIntermediates ? entries.flatMap((entry) => [entry.style, ...(entry.script !== undefined ? [entry.entry] : [])]) : [];
|
|
65
|
+
|
|
238
66
|
for (const entry of entries) {
|
|
239
67
|
if (entry.script === undefined && omitted.includes(entry.entry)) {
|
|
240
68
|
throw new Error(`Cannot omit a script bootstrap target: ${entry.entry}`);
|
|
241
69
|
}
|
|
242
70
|
}
|
|
243
|
-
|
|
71
|
+
|
|
72
|
+
return packageRelease({ root, files, entries, aliases: { ...extraAliases, ...aliases }, outputDirectory, omit: [...new Set(omitted)], removeUnreferencedStyles });
|
|
244
73
|
}
|
|
245
74
|
|
|
246
|
-
/** Publish a
|
|
75
|
+
/** Publish a prepared release and synchronize an existing PHP asset cache.
|
|
247
76
|
* Staged publication restores the previous public directory on cache failure.
|
|
248
77
|
* Direct publication writes in public and does not roll back. Missing caches are ignored.
|
|
249
78
|
*/
|
|
@@ -342,14 +171,17 @@ export async function publishFlatRelease({ root, wpRoot, release, manifest, vers
|
|
|
342
171
|
if (!direct) {
|
|
343
172
|
await rename(release, publicDir);
|
|
344
173
|
}
|
|
174
|
+
|
|
345
175
|
const cachePath = resolve(root, 'eightshift/manifests.json');
|
|
346
176
|
let cacheExists = false;
|
|
347
177
|
|
|
348
178
|
try {
|
|
349
179
|
const cacheInfo = await lstat(cachePath);
|
|
180
|
+
|
|
350
181
|
if (!cacheInfo.isFile() || cacheInfo.isSymbolicLink()) {
|
|
351
182
|
throw new Error(`Manifest cache must be a regular file: ${cachePath}`);
|
|
352
183
|
}
|
|
184
|
+
|
|
353
185
|
cacheExists = true;
|
|
354
186
|
} catch (error) {
|
|
355
187
|
if (error.code !== 'ENOENT') {
|
|
@@ -362,9 +194,11 @@ export async function publishFlatRelease({ root, wpRoot, release, manifest, vers
|
|
|
362
194
|
|
|
363
195
|
try {
|
|
364
196
|
const cacheInfo = await lstat(cachePath);
|
|
197
|
+
|
|
365
198
|
if (!cacheInfo.isFile() || cacheInfo.isSymbolicLink()) {
|
|
366
199
|
throw new Error(`Manifest cache must be a regular file: ${cachePath}`);
|
|
367
200
|
}
|
|
201
|
+
|
|
368
202
|
const data = JSON.parse(await readFile(cachePath, 'utf8'));
|
|
369
203
|
|
|
370
204
|
if (!data?.assets || Array.isArray(data.assets) || typeof data.assets !== 'object' || !data.assets.assets || Array.isArray(data.assets.assets) || typeof data.assets.assets !== 'object') {
|
|
@@ -391,6 +225,7 @@ export async function publishFlatRelease({ root, wpRoot, release, manifest, vers
|
|
|
391
225
|
if (direct) {
|
|
392
226
|
throw error;
|
|
393
227
|
}
|
|
228
|
+
|
|
394
229
|
try {
|
|
395
230
|
await rename(publicDir, release);
|
|
396
231
|
} catch (rollbackError) {
|
package/bun/index.mjs
CHANGED
|
@@ -37,6 +37,7 @@ export function defineBuild({ root = process.cwd(), preset, ssr, publish, watch
|
|
|
37
37
|
if (Object.hasOwn(options, 'timings')) {
|
|
38
38
|
throw new Error('The timings option is no longer supported');
|
|
39
39
|
}
|
|
40
|
+
|
|
40
41
|
if (options.quiet && options.verbose) {
|
|
41
42
|
throw new Error('quiet and verbose cannot be combined');
|
|
42
43
|
}
|
|
@@ -47,6 +48,7 @@ export function defineBuild({ root = process.cwd(), preset, ssr, publish, watch
|
|
|
47
48
|
const outputs = new Set();
|
|
48
49
|
const run = async (options = {}) => {
|
|
49
50
|
validateOptions(options);
|
|
51
|
+
|
|
50
52
|
if (active) {
|
|
51
53
|
throw new Error('A build is already running');
|
|
52
54
|
}
|
|
@@ -65,13 +67,17 @@ export function defineBuild({ root = process.cwd(), preset, ssr, publish, watch
|
|
|
65
67
|
const configured = typeof preset === 'function' ? await preset(context) : preset;
|
|
66
68
|
outputs.clear();
|
|
67
69
|
const output = typeof configured?.outdir === 'string' && configured.outdir ? resolve(root, configured.outdir) : undefined;
|
|
70
|
+
|
|
68
71
|
if (output) {
|
|
69
72
|
const rootFromOutput = relative(output, root);
|
|
73
|
+
|
|
70
74
|
if (!rootFromOutput || (!isAbsolute(rootFromOutput) && rootFromOutput !== '..' && !rootFromOutput.startsWith(`..${sep}`))) {
|
|
71
75
|
throw new Error('outdir must not contain the project root');
|
|
72
76
|
}
|
|
77
|
+
|
|
73
78
|
outputs.add(output);
|
|
74
79
|
}
|
|
80
|
+
|
|
75
81
|
report('Building browser assets…');
|
|
76
82
|
const result = await buildPreset({ ...configured, root });
|
|
77
83
|
const state = { ...context, result };
|
|
@@ -87,6 +93,7 @@ export function defineBuild({ root = process.cwd(), preset, ssr, publish, watch
|
|
|
87
93
|
}
|
|
88
94
|
|
|
89
95
|
report(`Build completed in ${((performance.now() - started) / 1000).toFixed(2)}s.`);
|
|
96
|
+
|
|
90
97
|
return state;
|
|
91
98
|
})();
|
|
92
99
|
|
|
@@ -101,6 +108,7 @@ export function defineBuild({ root = process.cwd(), preset, ssr, publish, watch
|
|
|
101
108
|
build: run,
|
|
102
109
|
watch: (options = {}) => {
|
|
103
110
|
validateOptions(options);
|
|
111
|
+
|
|
104
112
|
if ((ssr || publish) && watch.sources === undefined && !watch.ignored?.length) {
|
|
105
113
|
throw new Error('Watch builds with ssr or publish callbacks require explicit watch.sources or watch.ignored');
|
|
106
114
|
}
|
|
@@ -113,22 +121,28 @@ export function defineBuild({ root = process.cwd(), preset, ssr, publish, watch
|
|
|
113
121
|
if (watch.ignore?.(path)) {
|
|
114
122
|
return true;
|
|
115
123
|
}
|
|
124
|
+
|
|
116
125
|
for (const output of outputs) {
|
|
117
126
|
const location = relative(output, path);
|
|
127
|
+
|
|
118
128
|
if (!location || (!isAbsolute(location) && location !== '..' && !location.startsWith(`..${sep}`))) {
|
|
119
129
|
return true;
|
|
120
130
|
}
|
|
131
|
+
|
|
121
132
|
const sibling = relative(dirname(output), path).split(sep)[0];
|
|
133
|
+
|
|
122
134
|
if (sibling.startsWith(`.${basename(output)}-stage-`) || sibling.startsWith(`.${basename(output)}-backup-`)) {
|
|
123
135
|
return true;
|
|
124
136
|
}
|
|
125
137
|
}
|
|
138
|
+
|
|
126
139
|
return false;
|
|
127
140
|
},
|
|
128
141
|
build: async () => {
|
|
129
142
|
while (active) {
|
|
130
143
|
await active.catch(() => {});
|
|
131
144
|
}
|
|
145
|
+
|
|
132
146
|
return run(options);
|
|
133
147
|
},
|
|
134
148
|
});
|
package/bun/media.mjs
CHANGED
|
@@ -3,15 +3,23 @@ import { basename, dirname, resolve } from 'node:path';
|
|
|
3
3
|
import { allowPureJsxGrouping } from './plugin-capabilities.mjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Adapt the published UI Components smart-image worker for
|
|
6
|
+
* Adapt the published UI Components smart-image worker for structured theme releases.
|
|
7
7
|
* Callbacks belong to one build and provide the worker to the publication step.
|
|
8
8
|
* Unsupported upstream worker URL forms fail rather than producing a broken URL.
|
|
9
9
|
*/
|
|
10
|
-
export function editorWorkerPlugin({ setEditorWorker, getEditorWorker }) {
|
|
10
|
+
export function editorWorkerPlugin({ setEditorWorker, getEditorWorker, scriptUrlIdentifier = '__eightshiftEditorScriptUrl', publicPrefix }) {
|
|
11
11
|
if (typeof setEditorWorker !== 'function' || typeof getEditorWorker !== 'function') {
|
|
12
12
|
throw new TypeError('Worker callbacks are required');
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
if (typeof scriptUrlIdentifier !== 'string' || !/^[$A-Z_a-z][$\w]*$/.test(scriptUrlIdentifier)) {
|
|
16
|
+
throw new TypeError('Invalid editor script URL identifier');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (publicPrefix !== undefined && (typeof publicPrefix !== 'string' || !publicPrefix)) {
|
|
20
|
+
throw new TypeError('publicPrefix must be a non-empty string');
|
|
21
|
+
}
|
|
22
|
+
|
|
15
23
|
return allowPureJsxGrouping({
|
|
16
24
|
name: 'eightshift-editor-worker-url',
|
|
17
25
|
setup(builder) {
|
|
@@ -41,9 +49,13 @@ export function editorWorkerPlugin({ setEditorWorker, getEditorWorker }) {
|
|
|
41
49
|
}
|
|
42
50
|
|
|
43
51
|
setEditorWorker(worker);
|
|
44
|
-
const
|
|
52
|
+
const editorPath = `editor-assets/${basename(worker)}`;
|
|
53
|
+
const publicPath = `editor/${editorPath}`;
|
|
54
|
+
const url = publicPrefix
|
|
55
|
+
? `new URL(${JSON.stringify(`${publicPrefix}${publicPath}`)}, globalThis.location.href)`
|
|
56
|
+
: `(typeof ${scriptUrlIdentifier} !== "undefined" ? new URL(${JSON.stringify(editorPath)}, ${scriptUrlIdentifier}) : (() => { throw new Error("Smart-image worker requires a publicPrefix outside the editor"); })())`;
|
|
45
57
|
|
|
46
|
-
return { contents: source.replace(pattern,
|
|
58
|
+
return { contents: source.replace(pattern, url), loader: 'js', resolveDir: dirname(path) };
|
|
47
59
|
});
|
|
48
60
|
},
|
|
49
61
|
});
|
package/bun/preset.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isAbsolute, relative, resolve, sep } from 'node:path';
|
|
2
|
-
import { build } from './build.mjs';
|
|
2
|
+
import { build, validateEntryPublicPaths } from './build.mjs';
|
|
3
3
|
import { processEightshiftCss } from './eightshift-css.mjs';
|
|
4
4
|
|
|
5
5
|
const checkOptions = (value, keys, label) => {
|
|
@@ -39,8 +39,8 @@ const feature = (value, keys, label) => {
|
|
|
39
39
|
* Both are opt-in, and all filenames and discovery behavior are overridable.
|
|
40
40
|
*/
|
|
41
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;
|
|
42
|
+
checkOptions(options, ['root', 'outdir', 'entries', 'wpRoot', 'wordpress', 'discovery', 'responsive', 'css', 'editor', 'buildOptions', 'entryPublicPaths', 'direct'], 'preset');
|
|
43
|
+
const { root = process.cwd(), outdir, entries, wpRoot, wordpress = true, buildOptions = {}, entryPublicPaths = {}, direct = false } = options;
|
|
44
44
|
|
|
45
45
|
if (typeof root !== 'string' || !root || typeof outdir !== 'string' || !outdir) {
|
|
46
46
|
throw new TypeError('root and outdir must be non-empty strings');
|
|
@@ -50,6 +50,8 @@ export function createPreset(options = {}) {
|
|
|
50
50
|
throw new TypeError('entries must contain named entrypoints');
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
validateEntryPublicPaths(entryPublicPaths, entries);
|
|
54
|
+
|
|
53
55
|
if (typeof wordpress !== 'boolean') {
|
|
54
56
|
throw new TypeError('wordpress must be a boolean');
|
|
55
57
|
}
|
|
@@ -111,7 +113,7 @@ export function createPreset(options = {}) {
|
|
|
111
113
|
}
|
|
112
114
|
}
|
|
113
115
|
|
|
114
|
-
return { root, outdir, entries: { ...entries }, wpRoot, wordpress, discovery, responsive, css, editor, direct, buildOptions: { ...buildOptions } };
|
|
116
|
+
return { root, outdir, entries: { ...entries }, wpRoot, wordpress, discovery, responsive, css, editor, direct, entryPublicPaths: { ...entryPublicPaths }, buildOptions: { ...buildOptions } };
|
|
115
117
|
}
|
|
116
118
|
|
|
117
119
|
/** Build and atomically publish a configured preset. */
|
package/bun/publish.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import { cp, lstat, mkdir, readFile, readdir, rename, rm, unlink, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { chmod, cp, lstat, mkdir, readFile, readdir, rename, rm, unlink, writeFile } from 'node:fs/promises';
|
|
3
3
|
import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
4
4
|
|
|
5
5
|
const exists = async (path) => {
|
|
@@ -13,6 +13,7 @@ const exists = async (path) => {
|
|
|
13
13
|
throw error;
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
|
+
|
|
16
17
|
const pathName = (value) => {
|
|
17
18
|
if (typeof value !== 'string' || !value || isAbsolute(value) || value.includes('\\') || value.includes('\0') || value.split('/').some((part) => !part || part === '.' || part === '..')) {
|
|
18
19
|
throw new Error(`Invalid manifest path: ${String(value)}`);
|
|
@@ -20,6 +21,7 @@ const pathName = (value) => {
|
|
|
20
21
|
|
|
21
22
|
return value;
|
|
22
23
|
};
|
|
24
|
+
|
|
23
25
|
const inside = (parent, child) => {
|
|
24
26
|
const path = relative(parent, child);
|
|
25
27
|
|
|
@@ -30,8 +32,8 @@ const inside = (parent, child) => {
|
|
|
30
32
|
* Publish a packageRelease directory without deleting unrelated public files.
|
|
31
33
|
* root is the theme root; publicDir defaults to root/public. publicPrefix is
|
|
32
34
|
* 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
|
+
* release. Existing PHP manifest cache assets are updated with their permission
|
|
36
|
+
* bits preserved; missing caches are left alone. Returns { publicDir, manifest }.
|
|
35
37
|
*/
|
|
36
38
|
export async function publishRelease({ root, release, manifest, publicDir, publicPrefix }) {
|
|
37
39
|
if (
|
|
@@ -182,7 +184,8 @@ export async function publishRelease({ root, release, manifest, publicDir, publi
|
|
|
182
184
|
|
|
183
185
|
cacheData.assets.assets = publicManifest;
|
|
184
186
|
cacheTemporary = `${cachePath}.${randomUUID()}`;
|
|
185
|
-
await writeFile(cacheTemporary, JSON.stringify(cacheData), { flag: 'wx', mode: cacheInfo.mode });
|
|
187
|
+
await writeFile(cacheTemporary, JSON.stringify(cacheData), { flag: 'wx', mode: cacheInfo.mode & 0o7777 });
|
|
188
|
+
await chmod(cacheTemporary, cacheInfo.mode & 0o7777);
|
|
186
189
|
}
|
|
187
190
|
|
|
188
191
|
if (publicInfo) {
|