@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.
@@ -0,0 +1,144 @@
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { createHash } from 'node:crypto';
4
+ import { mkdir, mkdtemp, readFile, readdir, realpath, rmdir, unlink, writeFile } from 'node:fs/promises';
5
+ import { tmpdir } from 'node:os';
6
+ import { join } from 'node:path';
7
+ import { packageRelease } from '../bun/release.mjs';
8
+ import { preserveAssets } from '../bun/structured-publication.mjs';
9
+ import { prepareSharedFonts } from '../bun/shared-fonts.mjs';
10
+
11
+ const temporary = async () => mkdtemp(join(await realpath(tmpdir()), 'eightshift-publication-'));
12
+
13
+ async function removeFixture(directory) {
14
+ for (const item of await readdir(directory, { withFileTypes: true })) {
15
+ const path = join(directory, item.name);
16
+
17
+ if (item.isDirectory()) {
18
+ await removeFixture(path);
19
+ } else {
20
+ await unlink(path);
21
+ }
22
+ }
23
+
24
+ await rmdir(directory);
25
+ }
26
+
27
+ test('published nested stylesheets retain their relative asset URLs', async () => {
28
+ const root = await temporary();
29
+
30
+ try {
31
+ const source = join(root, 'source');
32
+ await mkdir(join(source, 'css', 'images'), { recursive: true });
33
+ await writeFile(join(source, 'app.js'), 'console.log("app");');
34
+ await writeFile(join(source, 'css', 'app.css'), '@import "./reset.css"; .logo { background: url("./images/logo.svg?v=1#icon"); }');
35
+ await writeFile(join(source, 'css', 'reset.css'), '.reset { margin: 0; }');
36
+ await writeFile(join(source, 'css', 'images', 'logo.svg'), '<svg></svg>');
37
+
38
+ const { release, manifest } = await packageRelease({
39
+ root: join(root, 'output'),
40
+ files: [
41
+ { source: join(source, 'app.js'), destination: 'app.js' },
42
+ { source: join(source, 'css'), destination: 'css' },
43
+ ],
44
+ entries: [{ name: 'app', entry: 'app.js', style: 'css/app.css', dependencies: [] }],
45
+ });
46
+ const publishedStyle = new URL(manifest['app.css'], 'https://example.test/public/');
47
+ const css = await readFile(join(release, manifest['app.css']), 'utf8');
48
+ const importUrl = new URL(css.match(/@import\s+["']([^"']+)/)[1], publishedStyle);
49
+ const imageUrl = new URL(css.match(/url\(["']?([^"')]+)/)[1], publishedStyle);
50
+
51
+ assert.equal(await readFile(join(release, importUrl.pathname.slice('/public/'.length)), 'utf8'), '.reset { margin: 0; }');
52
+ assert.equal(await readFile(join(release, imageUrl.pathname.slice('/public/'.length)), 'utf8'), '<svg></svg>');
53
+ assert.equal(imageUrl.search, '?v=1');
54
+ assert.equal(imageUrl.hash, '#icon');
55
+ } finally {
56
+ await removeFixture(root);
57
+ }
58
+ });
59
+
60
+ test('release omission cannot remove a bootstrap target', async () => {
61
+ const root = await temporary();
62
+ try {
63
+ await writeFile(join(root, 'entry.js'), 'console.log("entry");');
64
+ await writeFile(join(root, 'style.css'), '.example { color: red; }');
65
+ await writeFile(join(root, 'unused.txt'), 'unused');
66
+ const options = {
67
+ root: join(root, 'output'),
68
+ files: ['entry.js', 'style.css', 'unused.txt'].map((name) => ({ source: join(root, name), destination: name })),
69
+ entries: [{ name: 'app', entry: 'entry.js', style: 'style.css', dependencies: [] }],
70
+ };
71
+ await assert.rejects(packageRelease({ ...options, omit: ['entry.js'] }), /Cannot omit a script bootstrap target/);
72
+ const allowed = await packageRelease({ ...options, omit: ['unused.txt'] });
73
+ assert.ok((await readdir(allowed.release)).includes('entry.js'));
74
+ assert.ok(!(await readdir(allowed.release)).includes('unused.txt'));
75
+ const custom = await packageRelease({ ...options, entries: [{ ...options.entries[0], script: 'console.log("standalone");' }], omit: ['entry.js'] });
76
+ assert.ok(!(await readdir(custom.release)).includes('entry.js'));
77
+ } finally {
78
+ await removeFixture(root);
79
+ }
80
+ });
81
+
82
+ test('structured stylesheet assets retain valid relative URLs', async () => {
83
+ const root = await temporary();
84
+
85
+ try {
86
+ const output = join(root, 'output');
87
+ const nested = join(output, 'frontend', 'chunks');
88
+ await mkdir(join(nested, 'assets'), { recursive: true });
89
+ await writeFile(join(nested, 'style.css'), '.a { background: url(./assets/a.svg?size=1#icon); }');
90
+ await writeFile(join(nested, 'assets', 'a.svg'), '<svg></svg>');
91
+ const flat = join(root, 'structured');
92
+ await preserveAssets({ outdir: output, flatDir: flat, directories: ['frontend'] });
93
+ const css = await readFile(join(flat, 'frontend/chunks/style.css'), 'utf8');
94
+ const url = new URL(css.match(/url\(["']?([^"')]+)/)[1], 'https://example.test/public/frontend/chunks/style.css');
95
+
96
+ assert.equal(await readFile(join(flat, url.pathname.slice('/public/'.length)), 'utf8'), '<svg></svg>');
97
+ assert.equal(url.search, '?size=1');
98
+ assert.equal(url.hash, '#icon');
99
+ } finally {
100
+ await removeFixture(root);
101
+ }
102
+ });
103
+
104
+ test('shared font extraction preserves conditional faces in their original stylesheet', async () => {
105
+ const root = await temporary();
106
+
107
+ try {
108
+ const assets = join(root, 'node_modules', '@eightshift', 'ui-components', 'dist', 'assets');
109
+ const flat = join(root, 'build', 'flat');
110
+ await mkdir(join(assets, 'fonts'), { recursive: true });
111
+ await mkdir(flat, { recursive: true });
112
+ await writeFile(join(root, 'package.json'), '{"name":"font-fixture"}');
113
+ await writeFile(join(assets, '..', '..', 'package.json'), JSON.stringify({ name: '@eightshift/ui-components', exports: { './dist/assets/style.css': './dist/assets/style.css' } }));
114
+ await writeFile(join(assets, 'style.css'), '');
115
+ const font = Buffer.from('fixture font bytes');
116
+ const hash = createHash('sha256').update(font).digest('hex');
117
+ await writeFile(join(assets, 'fonts', 'fixture.woff2'), font);
118
+ await writeFile(join(assets, 'fonts-manifest.json'), JSON.stringify({ version: 1, fonts: [{ hash, file: 'fonts/fixture.woff2' }], css: '' }));
119
+ await writeFile(join(flat, 'font.woff2'), font);
120
+ await writeFile(join(flat, 'app.css'), '@font-face { font-family: Standard; src: url("./font.woff2"); }\n@media (prefers-color-scheme: dark) { @font-face { font-family: Conditional; src: url("./font.woff2"); } }\n@supports (display: grid) { @font-face { font-family: Supported; src: url("./font.woff2"); } }');
121
+ const lazyCss = '@font-face { font-family: Lazy; src: url("./font.woff2"); }';
122
+ await writeFile(join(flat, 'lazy.css'), lazyCss);
123
+
124
+ const retainedStyles = new Set(['lazy.css']);
125
+ await prepareSharedFonts({ root, flatDir: flat, retainedStyles });
126
+ const stylesheet = await readFile(join(flat, 'app.css'), 'utf8');
127
+ const manifest = JSON.parse(await readFile(join(root, 'build', 'shared-fonts.json'), 'utf8'));
128
+
129
+ assert.match(stylesheet, /@media\s*\(prefers-color-scheme: dark\)\s*\{\s*@font-face\s*\{[^}]*font-family:\s*Conditional/);
130
+ assert.match(stylesheet, /@supports\s*\(display: grid\)\s*\{\s*@font-face\s*\{[^}]*font-family:\s*Supported/);
131
+ assert.doesNotMatch(stylesheet, /font-family:\s*Standard/);
132
+ assert.match(manifest.css, /font-family:\s*Standard/);
133
+ assert.doesNotMatch(manifest.css, /font-family:\s*(Conditional|Supported|Lazy)/);
134
+ assert.equal(await readFile(join(flat, 'lazy.css'), 'utf8'), lazyCss);
135
+
136
+ await prepareSharedFonts({ root, flatDir: flat, retainedStyles });
137
+ const conditionalOnly = JSON.parse(await readFile(join(root, 'build', 'shared-fonts.json'), 'utf8'));
138
+ assert.equal(await readFile(join(flat, 'app.css'), 'utf8'), stylesheet);
139
+ assert.deepEqual(conditionalOnly.fonts, []);
140
+ assert.equal(conditionalOnly.css, '');
141
+ } finally {
142
+ await removeFixture(root);
143
+ }
144
+ });
@@ -0,0 +1,12 @@
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { spawnSync } from 'node:child_process';
4
+ import { resolve } from 'node:path';
5
+
6
+ test('theme builds preserve imported styles, worker URLs and isolated stable store IDs', () => {
7
+ const fixture = resolve(import.meta.dirname, 'fixtures/theme-build-regressions.mjs');
8
+ const result = spawnSync('bun', [fixture], { encoding: 'utf8', timeout: 120000 });
9
+
10
+ assert.ifError(result.error);
11
+ assert.equal(result.status, 0, `${result.stdout}\n${result.stderr}`);
12
+ });
@@ -0,0 +1,82 @@
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { spawnSync } from 'node:child_process';
4
+ import { mkdir, mkdtemp, readdir, realpath, rmdir, unlink, writeFile } from 'node:fs/promises';
5
+ import { tmpdir } from 'node:os';
6
+ import { join, resolve } from 'node:path';
7
+ import { pathToFileURL } from 'node:url';
8
+
9
+ async function removeFixture(directory) {
10
+ for (const item of await readdir(directory, { withFileTypes: true })) {
11
+ const path = join(directory, item.name);
12
+ if (item.isDirectory()) await removeFixture(path);
13
+ else await unlink(path);
14
+ }
15
+ await rmdir(directory);
16
+ }
17
+
18
+ test('WordPress side-effect scripts retain their handles without requiring globals', async () => {
19
+ const root = await mkdtemp(join(await realpath(tmpdir()), 'wordpress-side-effects-'));
20
+ try {
21
+ await mkdir(join(root, 'wp-includes/js/dist'), { recursive: true });
22
+ await mkdir(join(root, 'node_modules'));
23
+ await writeFile(join(root, 'wp-includes/js/dist/format-library.js'), '(function () { registerFormats(); })();');
24
+ await writeFile(join(root, 'wp-includes/js/dist/data.js'), 'var index_exports = {};\n__export(index_exports, {\n select: () => select\n});\nreturn __toCommonJS(index_exports);');
25
+ await writeFile(join(root, 'wp-includes/js/dist/broken.js'), 'var index_exports = {}; // unsupported export structure');
26
+ await writeFile(join(root, 'entry.js'), 'import "@wordpress/format-library"; import { select } from "@wordpress/data"; globalThis.result = select();');
27
+ for (const name of ['api-fetch', 'dom-ready', 'server-side-render', 'namespace-default']) {
28
+ const property = name.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
29
+ const unwrap = name !== 'namespace-default' ? `\nif (typeof wp.${property} === 'object' && wp.${property}.default) { wp.${property} = wp.${property}.default; }` : '';
30
+ await writeFile(join(root, `wp-includes/js/dist/${name}.js`), `var index_exports = {};\n__export(index_exports, {\n default: () => implementation,\n helper: () => helper\n});\nreturn __toCommonJS(index_exports);${unwrap}`);
31
+ }
32
+ await writeFile(join(root, 'defaults.js'), 'import apiFetch from "@wordpress/api-fetch"; import domReady from "@wordpress/dom-ready"; import render, { helper } from "@wordpress/server-side-render"; import namespaced from "@wordpress/namespace-default"; globalThis.defaults = [apiFetch(), domReady(), render(), helper(), namespaced()];');
33
+ await writeFile(join(root, 'absent.js'), 'import "@wordpress/absent";');
34
+ await writeFile(join(root, 'bundled.js'), 'import "@wordpress/icons";');
35
+ await writeFile(join(root, 'side-only.js'), 'import "@wordpress/format-library";');
36
+ await writeFile(join(root, 'invalid.js'), 'import { missing } from "@wordpress/format-library"; console.log(missing);');
37
+ await writeFile(join(root, 'broken.js'), 'import "@wordpress/broken";');
38
+ const adapter = pathToFileURL(resolve(import.meta.dirname, '../bun/wordpress.mjs')).href;
39
+ const script = `
40
+ import assert from 'node:assert/strict';
41
+ import { wordpressPlugin } from ${JSON.stringify(adapter)};
42
+ const root = ${JSON.stringify(root)};
43
+ for (const minify of [false, true]) {
44
+ const wp = wordpressPlugin({ projectRoot: root, wpRoot: root });
45
+ const result = await Bun.build({ entrypoints: [root + '/entry.js'], target: 'browser', format: 'esm', write: false, minify, metafile: true, plugins: [wp.plugin] });
46
+ assert.equal(result.success, true);
47
+ assert.deepEqual(wp.getEmittedDependencies(result.metafile), ['wp-data', 'wp-format-library']);
48
+ assert.deepEqual(wp.getEmittedDependencies({ outputs: { 'empty.js': { inputs: {} } } }), ['wp-format-library']);
49
+ globalThis.wp = { data: { select: () => 'ok' } };
50
+ const code = await result.outputs[0].text();
51
+ new Function(code)();
52
+ assert.equal(globalThis.result, 'ok');
53
+ delete globalThis.wp;
54
+ assert.throws(() => new Function(code)(), /Missing WordPress global/);
55
+ }
56
+ const only = wordpressPlugin({ projectRoot: root, wpRoot: root });
57
+ const sideOnly = await Bun.build({ entrypoints: [root + '/side-only.js'], target: 'browser', format: 'esm', minify: true, write: false, metafile: true, plugins: [only.plugin] });
58
+ assert.equal(sideOnly.success, true);
59
+ assert.deepEqual(only.getEmittedDependencies(sideOnly.metafile), ['wp-format-library']);
60
+ new Function(await sideOnly.outputs[0].text())();
61
+ const defaults = wordpressPlugin({ projectRoot: root, wpRoot: root });
62
+ const built = await Bun.build({ entrypoints: [root + '/defaults.js'], target: 'browser', format: 'esm', write: false, metafile: true, plugins: [defaults.plugin] });
63
+ assert.equal(built.success, true);
64
+ globalThis.wp = { apiFetch: () => 'api', domReady: () => 'ready', serverSideRender: Object.assign(() => 'render', { helper: () => 'helper' }), namespaceDefault: { default: () => 'namespace' } };
65
+ new Function(await built.outputs[0].text())();
66
+ assert.deepEqual(globalThis.defaults, ['api', 'ready', 'render', 'helper', 'namespace']);
67
+ assert.deepEqual(defaults.getEmittedDependencies(built.metafile), ['wp-api-fetch', 'wp-dom-ready', 'wp-namespace-default', 'wp-server-side-render']);
68
+ delete globalThis.wp;
69
+ for (const entry of ['invalid', 'broken', 'absent', 'bundled']) {
70
+ const wp = wordpressPlugin({ projectRoot: root, wpRoot: root });
71
+ let failed = false;
72
+ try { const result = await Bun.build({ entrypoints: [root + '/' + entry + '.js'], target: 'browser', format: 'esm', write: false, plugins: [wp.plugin] }); failed = !result.success; } catch { failed = true; }
73
+ assert.equal(failed, true, entry + ' must fail');
74
+ }
75
+ `;
76
+ const result = spawnSync('bun', ['--no-install', '--eval', script], { encoding: 'utf8', timeout: 30000 });
77
+ assert.ifError(result.error);
78
+ assert.equal(result.status, 0, `${result.stdout}\n${result.stderr}`);
79
+ } finally {
80
+ await removeFixture(root);
81
+ }
82
+ });