@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
package/bun/release.mjs
CHANGED
|
@@ -8,6 +8,7 @@ async function ensureDirectory(directory, root) {
|
|
|
8
8
|
const location = root && relative(root, directory);
|
|
9
9
|
const withinRoot = root && (!location || (!isAbsolute(location) && location !== '..' && !location.startsWith(`..${sep}`)));
|
|
10
10
|
const parent = dirname(directory);
|
|
11
|
+
|
|
11
12
|
if (parent !== directory && (!withinRoot || directory !== root)) {
|
|
12
13
|
await ensureDirectory(parent, root);
|
|
13
14
|
}
|
|
@@ -21,6 +22,7 @@ async function ensureDirectory(directory, root) {
|
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
const info = await lstat(directory);
|
|
25
|
+
|
|
24
26
|
if (!info.isDirectory() || info.isSymbolicLink()) {
|
|
25
27
|
throw new Error(`Release path must be a real directory: ${directory}`);
|
|
26
28
|
}
|
|
@@ -47,7 +49,7 @@ const releasePath = (value) => {
|
|
|
47
49
|
* Returns { release, version, manifest }. A failed staging directory is retained.
|
|
48
50
|
* outputDirectory writes directly to an existing directory instead of staging.
|
|
49
51
|
*/
|
|
50
|
-
export async function packageRelease({ root, files, entries, aliases = {}, outputDirectory, omit = [] }) {
|
|
52
|
+
export async function packageRelease({ root, files, entries, aliases = {}, outputDirectory, omit = [], removeUnreferencedStyles = false }) {
|
|
51
53
|
if (typeof root !== 'string' || !root || !Array.isArray(files) || !Array.isArray(entries) || !entries.length || !aliases || typeof aliases !== 'object' || Array.isArray(aliases)) {
|
|
52
54
|
throw new TypeError('Expected root, files, entries and optional aliases');
|
|
53
55
|
}
|
|
@@ -62,6 +64,7 @@ export async function packageRelease({ root, files, entries, aliases = {}, outpu
|
|
|
62
64
|
|
|
63
65
|
contents.set(path, bytes);
|
|
64
66
|
};
|
|
67
|
+
|
|
65
68
|
const collect = async (source, destination) => {
|
|
66
69
|
const info = await lstat(source);
|
|
67
70
|
|
|
@@ -101,6 +104,7 @@ export async function packageRelease({ root, files, entries, aliases = {}, outpu
|
|
|
101
104
|
|
|
102
105
|
manifest[key] = value;
|
|
103
106
|
};
|
|
107
|
+
|
|
104
108
|
const scripts = new Map();
|
|
105
109
|
|
|
106
110
|
for (const entry of entries) {
|
|
@@ -111,8 +115,12 @@ export async function packageRelease({ root, files, entries, aliases = {}, outpu
|
|
|
111
115
|
const target = releasePath(entry.entry);
|
|
112
116
|
const style = releasePath(entry.style);
|
|
113
117
|
|
|
114
|
-
if (!contents.has(target) || !contents.
|
|
115
|
-
throw new Error(`Missing or empty entry
|
|
118
|
+
if (!contents.has(target) || !contents.get(target).length) {
|
|
119
|
+
throw new Error(`Missing or empty entry for ${entry.name}`);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (!contents.has(style)) {
|
|
123
|
+
throw new Error(`Missing style for ${entry.name}`);
|
|
116
124
|
}
|
|
117
125
|
|
|
118
126
|
if (entry.script !== undefined && (typeof entry.script !== 'string' || !entry.script.trim())) {
|
|
@@ -122,9 +130,11 @@ export async function packageRelease({ root, files, entries, aliases = {}, outpu
|
|
|
122
130
|
if (entry.format !== undefined && entry.format !== 'module') {
|
|
123
131
|
throw new TypeError(`Unsupported script format for ${entry.name}`);
|
|
124
132
|
}
|
|
133
|
+
|
|
125
134
|
if (entry.format === 'module' && (entry.readiness !== 'eightshift-editor-v1' || entry.script === undefined)) {
|
|
126
135
|
throw new TypeError(`Module entry ${entry.name} requires an explicit script and readiness contract`);
|
|
127
136
|
}
|
|
137
|
+
|
|
128
138
|
if (entry.readiness !== undefined && entry.format !== 'module') {
|
|
129
139
|
throw new TypeError(`Readiness requires a module entry: ${entry.name}`);
|
|
130
140
|
}
|
|
@@ -138,7 +148,9 @@ export async function packageRelease({ root, files, entries, aliases = {}, outpu
|
|
|
138
148
|
scripts.set(entry.name, { script, dependencies: entry.dependencies, ...(entry.format === 'module' ? { format: entry.format, readiness: entry.readiness } : {}) });
|
|
139
149
|
const scriptName = `${entry.name}-${digest(script)}.js`;
|
|
140
150
|
const styleBytes = contents.get(style);
|
|
141
|
-
|
|
151
|
+
// Preserve the stylesheet's base directory for relative URLs and imports.
|
|
152
|
+
const styleDirectory = style.slice(0, style.lastIndexOf('/') + 1);
|
|
153
|
+
const styleName = `${styleDirectory}${entry.name}-${digest(styleBytes)}.css`;
|
|
142
154
|
|
|
143
155
|
if (contents.has(scriptName)) {
|
|
144
156
|
throw new Error(`Duplicate release path: ${scriptName}`);
|
|
@@ -166,16 +178,56 @@ export async function packageRelease({ root, files, entries, aliases = {}, outpu
|
|
|
166
178
|
if (!Array.isArray(omit)) {
|
|
167
179
|
throw new TypeError('omit must be an array');
|
|
168
180
|
}
|
|
181
|
+
|
|
169
182
|
for (const path of omit) {
|
|
170
183
|
releasePath(path);
|
|
184
|
+
|
|
185
|
+
if (entries.some((entry) => entry.script === undefined && entry.entry === path)) {
|
|
186
|
+
throw new Error(`Cannot omit a script bootstrap target: ${path}`);
|
|
187
|
+
}
|
|
188
|
+
|
|
171
189
|
if (Object.values(manifest).includes(path)) {
|
|
172
190
|
throw new Error(`Cannot omit manifest target: ${path}`);
|
|
173
191
|
}
|
|
192
|
+
|
|
174
193
|
if (!contents.delete(path)) {
|
|
175
194
|
throw new Error(`Cannot omit missing release file: ${path}`);
|
|
176
195
|
}
|
|
177
196
|
}
|
|
178
197
|
|
|
198
|
+
if (typeof removeUnreferencedStyles !== 'boolean') {
|
|
199
|
+
throw new TypeError('removeUnreferencedStyles must be a boolean');
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (removeUnreferencedStyles) {
|
|
203
|
+
// Only entry styles have a generated, same-directory hashed replacement.
|
|
204
|
+
// Conservative name matching also retains ambiguous and absolute references.
|
|
205
|
+
const referenceText = (bytes) =>
|
|
206
|
+
bytes
|
|
207
|
+
.toString()
|
|
208
|
+
.replace(/\\(?:u\{([\da-f]+)\}|u([\da-f]{4})|x([\da-f]{2}))/gi, (match, point, unicode, hex) => {
|
|
209
|
+
const code = Number.parseInt(point ?? unicode ?? hex, 16);
|
|
210
|
+
|
|
211
|
+
return code <= 0x10ffff ? String.fromCodePoint(code) : match;
|
|
212
|
+
})
|
|
213
|
+
.replace(/\\([\da-f]{1,6})[ \t\r\n\f]?/gi, (match, hex) => {
|
|
214
|
+
const code = Number.parseInt(hex, 16);
|
|
215
|
+
|
|
216
|
+
return code > 0 && code <= 0x10ffff ? String.fromCodePoint(code) : match;
|
|
217
|
+
})
|
|
218
|
+
.replace(/\\([^\r\n])/g, '$1')
|
|
219
|
+
.replace(/%([\da-f]{2})/gi, (_match, hex) => String.fromCharCode(Number.parseInt(hex, 16)));
|
|
220
|
+
const texts = [...contents.values(), ...[...scripts.values()].map(({ script }) => script)].map(referenceText);
|
|
221
|
+
|
|
222
|
+
for (const { style } of entries) {
|
|
223
|
+
const name = style.slice(style.lastIndexOf('/') + 1);
|
|
224
|
+
|
|
225
|
+
if (!Object.values(manifest).includes(style) && !texts.some((text) => text.includes(name))) {
|
|
226
|
+
contents.delete(style);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
179
231
|
const inventory = Object.fromEntries([...contents].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)).map(([path, bytes]) => [path, digest(bytes)]));
|
|
180
232
|
const version = digest(JSON.stringify({ format: 1, inventory, scripts: [...scripts].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)), manifest }));
|
|
181
233
|
|
package/bun/shared-fonts.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import postcss from 'postcss';
|
|
|
6
6
|
import valueParser from 'postcss-value-parser';
|
|
7
7
|
|
|
8
8
|
/** Extract verified UI Components font faces before stylesheet hashes are calculated. */
|
|
9
|
-
export async function prepareSharedFonts({ root, flatDir }) {
|
|
9
|
+
export async function prepareSharedFonts({ root, flatDir, retainedStyles = new Set() }) {
|
|
10
10
|
const require = createRequire(resolve(root, 'package.json'));
|
|
11
11
|
const assets = dirname(require.resolve('@eightshift/ui-components/dist/assets/style.css'));
|
|
12
12
|
const manifest = JSON.parse(await readFile(resolve(assets, 'fonts-manifest.json'), 'utf8'));
|
|
@@ -16,25 +16,33 @@ export async function prepareSharedFonts({ root, flatDir }) {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
const hashes = new Set();
|
|
19
|
+
|
|
19
20
|
for (const font of manifest.fonts) {
|
|
20
21
|
if (!font || !/^[a-f0-9]{64}$/.test(font.hash) || typeof font.file !== 'string' || !/^fonts\/[\w.-]+\.woff2$/.test(font.file)) {
|
|
21
22
|
throw new Error('Invalid shared font asset descriptor.');
|
|
22
23
|
}
|
|
24
|
+
|
|
23
25
|
const bytes = await readFile(resolve(assets, font.file));
|
|
26
|
+
|
|
24
27
|
if (createHash('sha256').update(bytes).digest('hex') !== font.hash) {
|
|
25
28
|
throw new Error(`Shared font integrity mismatch: ${font.file}`);
|
|
26
29
|
}
|
|
30
|
+
|
|
27
31
|
hashes.add(font.hash);
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
const faces = new Set();
|
|
35
|
+
let matched = false;
|
|
31
36
|
const fonts = new Map();
|
|
32
37
|
const updated = [];
|
|
33
|
-
|
|
38
|
+
|
|
39
|
+
for (const name of (await readdir(flatDir, { recursive: true })).filter((name) => name.endsWith('.css')).sort()) {
|
|
34
40
|
const file = resolve(flatDir, name);
|
|
35
41
|
const tree = postcss.parse(await readFile(file, 'utf8'), { from: file });
|
|
36
42
|
const candidates = [];
|
|
43
|
+
let changed = false;
|
|
37
44
|
tree.walkAtRules('font-face', (face) => candidates.push(face));
|
|
45
|
+
|
|
38
46
|
for (const face of candidates) {
|
|
39
47
|
const sources = [];
|
|
40
48
|
face.walkDecls('src', (decl) => {
|
|
@@ -53,36 +61,78 @@ export async function prepareSharedFonts({ root, flatDir }) {
|
|
|
53
61
|
}
|
|
54
62
|
});
|
|
55
63
|
});
|
|
56
|
-
|
|
64
|
+
|
|
65
|
+
if (!sources.length) {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
|
|
57
69
|
const resolved = [];
|
|
70
|
+
|
|
58
71
|
for (const source of sources) {
|
|
59
|
-
if (/^(?:[a-z][a-z\d+.-]*:|\/|#)/i.test(source.url) || /[?#]/.test(source.url))
|
|
60
|
-
|
|
72
|
+
if (/^(?:[a-z][a-z\d+.-]*:|\/|#)/i.test(source.url) || /[?#]/.test(source.url)) {
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const path = resolve(dirname(file), source.url);
|
|
61
77
|
const rel = relative(flatDir, path);
|
|
62
|
-
|
|
78
|
+
|
|
79
|
+
if (isAbsolute(rel) || rel.startsWith('..') || !/\.woff2$/.test(path)) {
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
|
|
63
83
|
const hash = createHash('sha256')
|
|
64
84
|
.update(await readFile(path))
|
|
65
85
|
.digest('hex');
|
|
66
|
-
|
|
86
|
+
|
|
87
|
+
if (!hashes.has(hash)) {
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
|
|
67
91
|
resolved.push({ ...source, path, hash, file: `fonts/${hash}${extname(path)}` });
|
|
68
92
|
}
|
|
93
|
+
|
|
69
94
|
// Leave mixed or unrelated font declarations entirely unchanged.
|
|
70
|
-
if (resolved.length !== sources.length)
|
|
95
|
+
if (resolved.length !== sources.length) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
matched = true;
|
|
100
|
+
|
|
101
|
+
// PHP accepts only plain font-face rules; retain all nested contexts.
|
|
102
|
+
if (face.parent !== tree || retainedStyles.has(name) || retainedStyles.has(basename(name))) {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
|
|
71
106
|
for (const source of resolved) {
|
|
72
107
|
source.node.nodes = [{ type: 'string', quote: '"', value: `./${source.file}` }];
|
|
73
108
|
fonts.set(source.file, { hash: source.hash, file: source.file, source: source.path });
|
|
74
109
|
}
|
|
75
|
-
|
|
110
|
+
|
|
111
|
+
for (const source of resolved) {
|
|
112
|
+
source.decl.value = source.parsed.toString();
|
|
113
|
+
}
|
|
114
|
+
|
|
76
115
|
faces.add(face.toString());
|
|
77
116
|
face.remove();
|
|
117
|
+
changed = true;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (changed) {
|
|
121
|
+
updated.push([file, tree.toString()]);
|
|
78
122
|
}
|
|
79
|
-
updated.push([file, tree.toString()]);
|
|
80
123
|
}
|
|
81
124
|
|
|
82
|
-
if (!
|
|
125
|
+
if (!matched) {
|
|
126
|
+
throw new Error('Shared fonts enabled but no verified UI Components font faces were found.');
|
|
127
|
+
}
|
|
128
|
+
|
|
83
129
|
const output = resolve(flatDir, '../shared-fonts.json');
|
|
84
130
|
await writeFile(output, JSON.stringify({ version: 1, fonts: [...fonts.values()].map(({ hash, file }) => ({ hash, file })), css: [...faces].join('\n') }, null, 2));
|
|
85
|
-
|
|
131
|
+
|
|
132
|
+
for (const [file, css] of updated) {
|
|
133
|
+
await writeFile(file, css);
|
|
134
|
+
}
|
|
135
|
+
|
|
86
136
|
return {
|
|
87
137
|
extraFiles: [{ source: output, destination: basename(output) }, ...[...fonts.values()].map(({ source, file }) => ({ source, destination: file }))],
|
|
88
138
|
aliases: { 'shared-fonts.json': 'shared-fonts.json' },
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { lstat, mkdir, readdir, copyFile } from 'node:fs/promises';
|
|
2
|
+
import { resolve, dirname } from 'node:path';
|
|
3
|
+
|
|
4
|
+
// Only compiler-owned output surfaces are eligible; discovery and metadata stay private.
|
|
5
|
+
export async function preserveAssets({ outdir, flatDir, directories = ['frontend', 'editor', 'admin', 'css'], extraSources = {} }) {
|
|
6
|
+
const sources = new Map();
|
|
7
|
+
const valid = (path) => {
|
|
8
|
+
if (typeof path !== 'string' || !path || path.includes('\\') || path.includes('\0') || path.split('/').some((p) => !p || p === '.' || p === '..')) {
|
|
9
|
+
throw new Error(`Invalid output path: ${path}`);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return path;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const collect = async (directory, prefix) => {
|
|
16
|
+
for (const item of await readdir(directory, { withFileTypes: true })) {
|
|
17
|
+
const path = valid(`${prefix}/${item.name}`);
|
|
18
|
+
|
|
19
|
+
if (path === 'editor/discovery' || (!prefix.includes('/') && item.name === `${prefix}.asset.json`)) {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (item.isDirectory()) {
|
|
24
|
+
await collect(resolve(directory, item.name), path);
|
|
25
|
+
} else if (item.isFile()) {
|
|
26
|
+
sources.set(path, resolve(directory, item.name));
|
|
27
|
+
} else {
|
|
28
|
+
throw new Error(`Unsupported output: ${path}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
for (const directory of directories) {
|
|
34
|
+
const source = resolve(outdir, valid(directory));
|
|
35
|
+
|
|
36
|
+
if (!(await lstat(source)).isDirectory()) {
|
|
37
|
+
throw new Error(`Invalid output directory: ${directory}`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
await collect(source, directory);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
for (const [path, source] of Object.entries(extraSources)) {
|
|
44
|
+
valid(path);
|
|
45
|
+
|
|
46
|
+
if (sources.has(path)) {
|
|
47
|
+
throw new Error(`Duplicate output: ${path}`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (!(await lstat(source)).isFile()) {
|
|
51
|
+
throw new Error(`Invalid extra source: ${path}`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
sources.set(path, source);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
await mkdir(flatDir);
|
|
58
|
+
|
|
59
|
+
for (const [path, source] of sources) {
|
|
60
|
+
const target = resolve(flatDir, path);
|
|
61
|
+
await mkdir(dirname(target), { recursive: true });
|
|
62
|
+
await copyFile(source, target, 1);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return { sources };
|
|
66
|
+
}
|