@eightshift/frontend-libs-tailwind 4.0.0-beta.4 → 4.0.0-beta.6
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 +26 -0
- package/README.md +92 -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 +131 -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/watch.mjs
CHANGED
|
@@ -20,6 +20,7 @@ export function watchBuild({ projectDir, sources, ignored = [], ignore = () => f
|
|
|
20
20
|
|
|
21
21
|
return rel === '' || (rel !== '..' && !rel.startsWith(`..${sep}`) && !isAbsolute(rel));
|
|
22
22
|
};
|
|
23
|
+
|
|
23
24
|
const paths = (items) =>
|
|
24
25
|
items.map((item) => {
|
|
25
26
|
if (typeof item !== 'string' || !item) {
|
|
@@ -64,6 +65,7 @@ export function watchBuild({ projectDir, sources, ignored = [], ignore = () => f
|
|
|
64
65
|
console.error(callbackError);
|
|
65
66
|
}
|
|
66
67
|
};
|
|
68
|
+
|
|
67
69
|
const run = () => {
|
|
68
70
|
if (stopped || running || !pending) {
|
|
69
71
|
return;
|
|
@@ -81,6 +83,7 @@ export function watchBuild({ projectDir, sources, ignored = [], ignore = () => f
|
|
|
81
83
|
}
|
|
82
84
|
});
|
|
83
85
|
};
|
|
86
|
+
|
|
84
87
|
const schedule = () => {
|
|
85
88
|
if (stopped) {
|
|
86
89
|
return;
|
|
@@ -93,14 +96,17 @@ export function watchBuild({ projectDir, sources, ignored = [], ignore = () => f
|
|
|
93
96
|
run();
|
|
94
97
|
}, debounce);
|
|
95
98
|
};
|
|
99
|
+
|
|
96
100
|
const stop = async () => {
|
|
97
101
|
if (!stopped) {
|
|
98
102
|
stopped = true;
|
|
99
103
|
pending = false;
|
|
100
104
|
clearTimeout(timer);
|
|
105
|
+
|
|
101
106
|
for (const watcher of watchers.values()) {
|
|
102
107
|
watcher.close();
|
|
103
108
|
}
|
|
109
|
+
|
|
104
110
|
watchers.clear();
|
|
105
111
|
}
|
|
106
112
|
|
|
@@ -122,6 +128,7 @@ export function watchBuild({ projectDir, sources, ignored = [], ignore = () => f
|
|
|
122
128
|
}
|
|
123
129
|
} catch (error) {
|
|
124
130
|
report(error);
|
|
131
|
+
|
|
125
132
|
return;
|
|
126
133
|
}
|
|
127
134
|
|
|
@@ -129,23 +136,29 @@ export function watchBuild({ projectDir, sources, ignored = [], ignore = () => f
|
|
|
129
136
|
schedule();
|
|
130
137
|
}
|
|
131
138
|
};
|
|
139
|
+
|
|
132
140
|
const refresh = () => {
|
|
133
141
|
if (stopped) {
|
|
134
142
|
return;
|
|
135
143
|
}
|
|
144
|
+
|
|
136
145
|
const desired = new Map();
|
|
137
146
|
const add = (directory, recursive, name) => {
|
|
138
147
|
const key = `${recursive ? 'recursive' : 'parent'}:${directory}`;
|
|
148
|
+
|
|
139
149
|
if (!desired.has(key)) {
|
|
140
150
|
desired.set(key, { directory, recursive, names: new Set() });
|
|
141
151
|
}
|
|
152
|
+
|
|
142
153
|
if (name) {
|
|
143
154
|
desired.get(key).names.add(name);
|
|
144
155
|
}
|
|
145
156
|
};
|
|
157
|
+
|
|
146
158
|
for (const input of inputs) {
|
|
147
159
|
let current = input;
|
|
148
160
|
let info;
|
|
161
|
+
|
|
149
162
|
while (true) {
|
|
150
163
|
try {
|
|
151
164
|
info = statSync(current);
|
|
@@ -154,17 +167,22 @@ export function watchBuild({ projectDir, sources, ignored = [], ignore = () => f
|
|
|
154
167
|
if (error.code !== 'ENOENT' && error.code !== 'ENOTDIR') {
|
|
155
168
|
throw error;
|
|
156
169
|
}
|
|
170
|
+
|
|
157
171
|
if (current === root) {
|
|
158
172
|
throw error;
|
|
159
173
|
}
|
|
174
|
+
|
|
160
175
|
current = dirname(current);
|
|
161
176
|
}
|
|
162
177
|
}
|
|
178
|
+
|
|
163
179
|
if (current === input && info.isDirectory()) {
|
|
164
180
|
if (filterDirectoryEvents && !directoryStamps.has(input)) {
|
|
165
181
|
directoryStamps.set(input, directoryStamp(input));
|
|
166
182
|
}
|
|
183
|
+
|
|
167
184
|
add(input, true);
|
|
185
|
+
|
|
168
186
|
if (input !== root) {
|
|
169
187
|
add(dirname(input), false, basename(input));
|
|
170
188
|
}
|
|
@@ -174,21 +192,28 @@ export function watchBuild({ projectDir, sources, ignored = [], ignore = () => f
|
|
|
174
192
|
add(directory, false, next);
|
|
175
193
|
}
|
|
176
194
|
}
|
|
195
|
+
|
|
177
196
|
for (const [key, config] of desired) {
|
|
178
197
|
const existing = watchers.get(key);
|
|
198
|
+
|
|
179
199
|
if (existing) {
|
|
180
200
|
existing.names = config.names;
|
|
181
201
|
continue;
|
|
182
202
|
}
|
|
203
|
+
|
|
183
204
|
const watcher = watch(config.directory, { recursive: config.recursive }, (_event, filename) => {
|
|
184
205
|
if (!filename || stopped) {
|
|
185
206
|
return;
|
|
186
207
|
}
|
|
208
|
+
|
|
187
209
|
const name = String(filename);
|
|
210
|
+
|
|
188
211
|
if (!config.recursive && !watcher.names.has(name)) {
|
|
189
212
|
return;
|
|
190
213
|
}
|
|
214
|
+
|
|
191
215
|
const path = resolve(config.directory, name);
|
|
216
|
+
|
|
192
217
|
try {
|
|
193
218
|
// Bun on macOS can report unchanged watched directories as changes.
|
|
194
219
|
if (filterDirectoryEvents && _event === 'change') {
|
|
@@ -203,6 +228,7 @@ export function watchBuild({ projectDir, sources, ignored = [], ignore = () => f
|
|
|
203
228
|
if (error.code !== 'ENOENT') {
|
|
204
229
|
throw error;
|
|
205
230
|
}
|
|
231
|
+
|
|
206
232
|
directory = config.directory;
|
|
207
233
|
}
|
|
208
234
|
}
|
|
@@ -213,11 +239,13 @@ export function watchBuild({ projectDir, sources, ignored = [], ignore = () => f
|
|
|
213
239
|
if (stamp && directoryStamps.get(directory) === stamp) {
|
|
214
240
|
return;
|
|
215
241
|
}
|
|
242
|
+
|
|
216
243
|
if (stamp) {
|
|
217
244
|
directoryStamps.set(directory, stamp);
|
|
218
245
|
}
|
|
219
246
|
}
|
|
220
247
|
}
|
|
248
|
+
|
|
221
249
|
if (filterDirectoryEvents && config.recursive) {
|
|
222
250
|
const stamp = directoryStamp(config.directory);
|
|
223
251
|
|
|
@@ -225,6 +253,7 @@ export function watchBuild({ projectDir, sources, ignored = [], ignore = () => f
|
|
|
225
253
|
directoryStamps.set(config.directory, stamp);
|
|
226
254
|
}
|
|
227
255
|
}
|
|
256
|
+
|
|
228
257
|
onEvent(path);
|
|
229
258
|
refresh();
|
|
230
259
|
} catch (error) {
|
|
@@ -239,6 +268,7 @@ export function watchBuild({ projectDir, sources, ignored = [], ignore = () => f
|
|
|
239
268
|
});
|
|
240
269
|
watchers.set(key, watcher);
|
|
241
270
|
}
|
|
271
|
+
|
|
242
272
|
for (const [key, watcher] of watchers) {
|
|
243
273
|
if (!desired.has(key)) {
|
|
244
274
|
watcher.close();
|
|
@@ -246,12 +276,14 @@ export function watchBuild({ projectDir, sources, ignored = [], ignore = () => f
|
|
|
246
276
|
}
|
|
247
277
|
}
|
|
248
278
|
};
|
|
279
|
+
|
|
249
280
|
try {
|
|
250
281
|
refresh();
|
|
251
282
|
} catch (error) {
|
|
252
283
|
for (const watcher of watchers.values()) {
|
|
253
284
|
watcher.close();
|
|
254
285
|
}
|
|
286
|
+
|
|
255
287
|
throw error;
|
|
256
288
|
}
|
|
257
289
|
|
package/bun/wordpress.mjs
CHANGED
|
@@ -56,10 +56,39 @@ async function coreExports(root, request) {
|
|
|
56
56
|
const script = await readFile(resolve(root, 'wp-includes/js/dist', `${name}.js`), 'utf8');
|
|
57
57
|
const matches = [...script.matchAll(/__export\(index_exports, \{([\s\S]*?)\n\s*\}\);/g)];
|
|
58
58
|
|
|
59
|
+
if (!matches.length && !/\bindex_exports\b/.test(script)) {
|
|
60
|
+
// Core's generated PEG parser uses a single CommonJS factory, not an ESM export table.
|
|
61
|
+
const commonJs = script.match(/var (require_[\w$]+) = __commonJS\(\{\s*"[^"\n]+"\(exports, module\) \{[\s\S]*?\bmodule\.exports\s*=\s*\{([^{}]*)\};\s*\}\s*\}\);\s*return \1\(\);\s*\}\)\(\);/);
|
|
62
|
+
|
|
63
|
+
if (commonJs && [...script.matchAll(/\bmodule\s*(?:\.\s*exports|\[)/g)].length === 1 && !/\bexports\s*(?:\.|\[)/.test(script.replace(/\bmodule\.exports\b/g, ''))) {
|
|
64
|
+
const names = commonJs[2]
|
|
65
|
+
.trim()
|
|
66
|
+
.replace(/,$/, '')
|
|
67
|
+
.split(',')
|
|
68
|
+
.map((entry) => entry.trim().match(/^([A-Za-z_$][\w$]*):\s*[A-Za-z_$][\w$]*$/)?.[1]);
|
|
69
|
+
|
|
70
|
+
if (names.length && names.every((name) => name && name !== '__proto__') && new Set(names).size === names.length) {
|
|
71
|
+
return { names, defaultGlobal: false };
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Only these core entry points are known to have no public exports. Unknown
|
|
76
|
+
// bundle formats must fail rather than silently erase their exported API.
|
|
77
|
+
if (['base-styles', 'format-library', 'list-reusable-blocks'].includes(name) && !/return\s+(?:__toCommonJS\(|require_[\w$]+\(\);\s*\}\)\(\);)/.test(script)) {
|
|
78
|
+
return { names: [], defaultGlobal: false };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
throw new Error(`Cannot identify WordPress core exports for ${request}`);
|
|
82
|
+
}
|
|
83
|
+
|
|
59
84
|
if (matches.length !== 1 || !script.includes('return __toCommonJS(index_exports);')) {
|
|
60
85
|
throw new Error(`Cannot identify WordPress core exports for ${request}`);
|
|
61
86
|
}
|
|
62
87
|
|
|
88
|
+
if (!matches[0][1].trim()) {
|
|
89
|
+
return { names: [], defaultGlobal: false };
|
|
90
|
+
}
|
|
91
|
+
|
|
63
92
|
const names = matches[0][1]
|
|
64
93
|
.trim()
|
|
65
94
|
.split(/,\s*\n/)
|
|
@@ -69,7 +98,10 @@ async function coreExports(root, request) {
|
|
|
69
98
|
throw new Error(`Cannot parse WordPress core exports for ${request}`);
|
|
70
99
|
}
|
|
71
100
|
|
|
72
|
-
|
|
101
|
+
const property = name.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
102
|
+
const defaultGlobal = new RegExp(`\\bwp\\.${property}\\s*=\\s*wp\\.${property}\\.default\\s*;`).test(script);
|
|
103
|
+
|
|
104
|
+
return { names, defaultGlobal };
|
|
73
105
|
}
|
|
74
106
|
|
|
75
107
|
/** Create a fresh adapter for each Bun build. Paths must be absolute. */
|
|
@@ -80,6 +112,7 @@ export function wordpressPlugin({ projectRoot = process.cwd(), wpRoot } = {}) {
|
|
|
80
112
|
|
|
81
113
|
const projectRequire = createRequire(resolve(projectRoot, 'package.json'));
|
|
82
114
|
const dependencies = new Set();
|
|
115
|
+
const sideEffectDependencies = new Set();
|
|
83
116
|
const modules = new Map();
|
|
84
117
|
const handles = new Map();
|
|
85
118
|
|
|
@@ -94,7 +127,8 @@ export function wordpressPlugin({ projectRoot = process.cwd(), wpRoot } = {}) {
|
|
|
94
127
|
return [...dependencies].sort();
|
|
95
128
|
}
|
|
96
129
|
|
|
97
|
-
|
|
130
|
+
// Empty adapters may be erased, but WordPress must still run their scripts.
|
|
131
|
+
const emitted = new Set(sideEffectDependencies);
|
|
98
132
|
|
|
99
133
|
for (const output of outputs) {
|
|
100
134
|
if (!output?.inputs || typeof output.inputs !== 'object') {
|
|
@@ -142,25 +176,7 @@ export function wordpressPlugin({ projectRoot = process.cwd(), wpRoot } = {}) {
|
|
|
142
176
|
|
|
143
177
|
const [global, handle, kind] = external;
|
|
144
178
|
const require = isAbsolute(args.importer) ? createRequire(args.importer) : projectRequire;
|
|
145
|
-
let metadata;
|
|
146
179
|
let entry;
|
|
147
|
-
let fallback = false;
|
|
148
|
-
|
|
149
|
-
if (kind === 'wordpress') {
|
|
150
|
-
try {
|
|
151
|
-
metadata = require(`${request}/package.json`);
|
|
152
|
-
} catch (error) {
|
|
153
|
-
if (error.code !== 'MODULE_NOT_FOUND' || !['@wordpress/plugins', '@wordpress/core-data'].includes(request)) {
|
|
154
|
-
throw error;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
fallback = true;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
if (!fallback && metadata.wpScript !== true) {
|
|
161
|
-
throw new Error(`Missing wpScript metadata: ${request}`);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
180
|
|
|
165
181
|
if (kind !== 'commonjs' && kind !== 'wordpress') {
|
|
166
182
|
const importer = isAbsolute(args.importer) ? args.importer : resolve(projectRoot, '__wordpress_plugin__.mjs');
|
|
@@ -168,14 +184,15 @@ export function wordpressPlugin({ projectRoot = process.cwd(), wpRoot } = {}) {
|
|
|
168
184
|
entry = kind === 'react' ? require.resolve(request) : Bun.resolveSync(request, dirname(importer));
|
|
169
185
|
}
|
|
170
186
|
|
|
171
|
-
const key = JSON.stringify([request, entry || ''
|
|
187
|
+
const key = JSON.stringify([request, entry || '']);
|
|
172
188
|
|
|
173
189
|
if (!modules.has(key)) {
|
|
174
190
|
let names = [];
|
|
191
|
+
let defaultGlobal = false;
|
|
175
192
|
|
|
176
193
|
try {
|
|
177
194
|
if (kind === 'wordpress') {
|
|
178
|
-
names = await coreExports(wpRoot, request);
|
|
195
|
+
({ names, defaultGlobal } = await coreExports(wpRoot, request));
|
|
179
196
|
} else if (kind === 'react') {
|
|
180
197
|
names = ['default', ...Object.keys(require(entry)).filter((name) => name !== 'default')];
|
|
181
198
|
} else if (kind !== 'commonjs') {
|
|
@@ -188,6 +205,15 @@ export function wordpressPlugin({ projectRoot = process.cwd(), wpRoot } = {}) {
|
|
|
188
205
|
throw new Error(`Cannot determine exports for ${request}: ${error.message}`);
|
|
189
206
|
}
|
|
190
207
|
|
|
208
|
+
if (kind === 'wordpress' && !names.length) {
|
|
209
|
+
sideEffectDependencies.add(handle);
|
|
210
|
+
modules.set(key, 'export {};');
|
|
211
|
+
dependencies.add(handle);
|
|
212
|
+
handles.set(key, handle);
|
|
213
|
+
|
|
214
|
+
return { path: key, namespace: 'wordpress-global' };
|
|
215
|
+
}
|
|
216
|
+
|
|
191
217
|
const path = Array.isArray(global) ? global : [global];
|
|
192
218
|
const lines = [`const value = ${path.reduce((expression, part) => `${expression}?.[${JSON.stringify(part)}]`, 'globalThis')};`, `if (value == null) throw new Error(${JSON.stringify(`Missing WordPress global for ${request}`)});`];
|
|
193
219
|
|
|
@@ -198,7 +224,7 @@ export function wordpressPlugin({ projectRoot = process.cwd(), wpRoot } = {}) {
|
|
|
198
224
|
} else {
|
|
199
225
|
for (const [index, name] of names.entries()) {
|
|
200
226
|
if (name === 'default') {
|
|
201
|
-
lines.push(kind === 'esm' ||
|
|
227
|
+
lines.push(kind === 'esm' || defaultGlobal ? 'export default value;' : 'export default value.default;');
|
|
202
228
|
} else {
|
|
203
229
|
lines.push(`const export${index} = value[${JSON.stringify(name)}];`, `export { export${index} as ${name} };`);
|
|
204
230
|
}
|
package/eslint.config.mjs
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
1
|
import linterConfig from './linters/base.config.mjs';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const sourceRules = linterConfig.find((config) => config.rules?.['padding-line-between-statements']).rules;
|
|
4
|
+
|
|
5
|
+
export default [
|
|
6
|
+
...linterConfig,
|
|
7
|
+
{
|
|
8
|
+
ignores: ['test/**', 'package/**'],
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
files: ['**/*.{js,jsx,mjs}'],
|
|
12
|
+
rules: {
|
|
13
|
+
curly: ['error', 'all'],
|
|
14
|
+
'padding-line-between-statements': [
|
|
15
|
+
...sourceRules['padding-line-between-statements'],
|
|
16
|
+
{
|
|
17
|
+
blankLine: 'always',
|
|
18
|
+
prev: 'block-like',
|
|
19
|
+
next: '*',
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
];
|
package/linters/base.config.mjs
CHANGED
|
@@ -68,6 +68,7 @@ function findClose(content, open) {
|
|
|
68
68
|
} else if (char === quote) {
|
|
69
69
|
quote = null;
|
|
70
70
|
}
|
|
71
|
+
|
|
71
72
|
continue;
|
|
72
73
|
}
|
|
73
74
|
|
|
@@ -255,6 +256,7 @@ function phpCommentRanges(content) {
|
|
|
255
256
|
ranges.push([i, end]);
|
|
256
257
|
i = end - 1;
|
|
257
258
|
}
|
|
259
|
+
|
|
258
260
|
continue;
|
|
259
261
|
}
|
|
260
262
|
|
|
@@ -264,6 +266,7 @@ function phpCommentRanges(content) {
|
|
|
264
266
|
} else if (char === quote) {
|
|
265
267
|
quote = null;
|
|
266
268
|
}
|
|
269
|
+
|
|
267
270
|
continue;
|
|
268
271
|
}
|
|
269
272
|
|
|
@@ -359,6 +362,7 @@ function callArgs(content, open, close) {
|
|
|
359
362
|
} else if (char === quote) {
|
|
360
363
|
quote = null;
|
|
361
364
|
}
|
|
365
|
+
|
|
362
366
|
continue;
|
|
363
367
|
}
|
|
364
368
|
|
|
@@ -399,6 +403,7 @@ function nestedParenRanges(content, from, to) {
|
|
|
399
403
|
} else if (char === quote) {
|
|
400
404
|
quote = null;
|
|
401
405
|
}
|
|
406
|
+
|
|
402
407
|
continue;
|
|
403
408
|
}
|
|
404
409
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eightshift/frontend-libs-tailwind",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.6",
|
|
4
4
|
"description": "A framework for creating modern Gutenberg themes with styling provided by Tailwind CSS.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Eightshift team",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"@tailwindcss/node": "^4.3.3",
|
|
44
44
|
"@tailwindcss/oxide": "^4.3.3",
|
|
45
45
|
"browserslist": "^4.29.3",
|
|
46
|
-
"eslint": "^
|
|
46
|
+
"eslint": "^9.39.5",
|
|
47
47
|
"eslint-config-prettier": "^10.1.8",
|
|
48
48
|
"eslint-plugin-better-tailwindcss": "^4.7.0",
|
|
49
49
|
"eslint-plugin-prettier": "^5.5.6",
|
|
@@ -64,11 +64,11 @@
|
|
|
64
64
|
"stylelint-config-standard": "^40.0.0"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"
|
|
68
|
-
"
|
|
67
|
+
"lint-staged": "^17.1.0",
|
|
68
|
+
"@eightshift/ui-components": "8.5.0-beta.1"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
|
-
"@eightshift/ui-components": "^8.0.0"
|
|
71
|
+
"@eightshift/ui-components": "^8.0.0 || 8.5.0-beta.1"
|
|
72
72
|
},
|
|
73
73
|
"sideEffects": false,
|
|
74
74
|
"lint-staged": {
|
package/scripts/editor/editor.js
CHANGED
|
@@ -375,14 +375,17 @@ export const getMergeCallback = (blockManifest) => {
|
|
|
375
375
|
outputObject[attribute] = `${receiver[attribute] ?? ''}${merger[attribute] ?? ''}`;
|
|
376
376
|
break;
|
|
377
377
|
}
|
|
378
|
+
|
|
378
379
|
case 'useDestinationAttribute': {
|
|
379
380
|
outputObject[attribute] = merger[attribute] ?? '';
|
|
380
381
|
break;
|
|
381
382
|
}
|
|
383
|
+
|
|
382
384
|
case 'addNumericIntValue': {
|
|
383
385
|
outputObject[attribute] = parseInt(receiver[attribute] ?? '0') + parseInt(merger[attribute] ?? '0');
|
|
384
386
|
break;
|
|
385
387
|
}
|
|
388
|
+
|
|
386
389
|
case 'addNumericFloatValue': {
|
|
387
390
|
outputObject[attribute] = parseFloat(receiver[attribute] ?? '0') + parseFloat(merger[attribute] ?? '0');
|
|
388
391
|
break;
|
package/scripts/editor/store.js
CHANGED
|
@@ -119,18 +119,21 @@ const reducer = (state = DEFAULT_STATE, action) => {
|
|
|
119
119
|
blocks: action.blocks,
|
|
120
120
|
};
|
|
121
121
|
}
|
|
122
|
+
|
|
122
123
|
case 'SET_COMPONENTS': {
|
|
123
124
|
return {
|
|
124
125
|
...state,
|
|
125
126
|
components: action.components,
|
|
126
127
|
};
|
|
127
128
|
}
|
|
129
|
+
|
|
128
130
|
case 'SET_VARIATIONS': {
|
|
129
131
|
return {
|
|
130
132
|
...state,
|
|
131
133
|
variations: action.variations,
|
|
132
134
|
};
|
|
133
135
|
}
|
|
136
|
+
|
|
134
137
|
case 'SET_CONFIG_USE_WRAPPER': {
|
|
135
138
|
return {
|
|
136
139
|
...state,
|
|
@@ -140,18 +143,21 @@ const reducer = (state = DEFAULT_STATE, action) => {
|
|
|
140
143
|
},
|
|
141
144
|
};
|
|
142
145
|
}
|
|
146
|
+
|
|
143
147
|
case 'SET_WRAPPER': {
|
|
144
148
|
return {
|
|
145
149
|
...state,
|
|
146
150
|
wrapper: action.wrapper,
|
|
147
151
|
};
|
|
148
152
|
}
|
|
153
|
+
|
|
149
154
|
case 'SET_SETTINGS': {
|
|
150
155
|
return {
|
|
151
156
|
...state,
|
|
152
157
|
settings: action.settings,
|
|
153
158
|
};
|
|
154
159
|
}
|
|
160
|
+
|
|
155
161
|
case 'SET_SETTINGS_GLOBAL_VARIABLES_BREAKPOINTS': {
|
|
156
162
|
return {
|
|
157
163
|
...state,
|
|
@@ -164,6 +170,7 @@ const reducer = (state = DEFAULT_STATE, action) => {
|
|
|
164
170
|
},
|
|
165
171
|
};
|
|
166
172
|
}
|
|
173
|
+
|
|
167
174
|
default: {
|
|
168
175
|
return state;
|
|
169
176
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { test } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { mkdir, mkdtemp, readFile, readdir, realpath, rmdir, unlink, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { generateDiscovery } from '../bun/discovery.mjs';
|
|
7
|
+
import { eightshiftDiscovery, editorLazyImports } from '../bun/eightshift-discovery.mjs';
|
|
8
|
+
|
|
9
|
+
async function clean(directory) {
|
|
10
|
+
for (const item of await readdir(directory, { withFileTypes: true })) {
|
|
11
|
+
const path = join(directory, item.name);
|
|
12
|
+
if (item.isDirectory()) await clean(path);
|
|
13
|
+
else await unlink(path);
|
|
14
|
+
}
|
|
15
|
+
await rmdir(directory);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
test('context names cannot shadow generated runtime constructors', async () => {
|
|
19
|
+
const root = await mkdtemp(join(await realpath(tmpdir()), 'discovery-names-'));
|
|
20
|
+
try {
|
|
21
|
+
for (const name of ['Map', 'Promise', 'Error']) {
|
|
22
|
+
await assert.rejects(generateDiscovery({ root, output: 'context.mjs', definitions: [{ name, directory: 'items', pattern: /./, mode: 'lazy' }] }), /Invalid or duplicate discovery definition/);
|
|
23
|
+
}
|
|
24
|
+
await generateDiscovery({ root, output: 'context.mjs', definitions: [{ name: 'items', directory: 'items', pattern: /./, mode: 'lazy' }] });
|
|
25
|
+
const { items } = await import(new URL(`file://${join(root, 'context.mjs')}`));
|
|
26
|
+
assert.deepEqual(items.keys(), []);
|
|
27
|
+
await assert.rejects(items('./missing.js'), { code: 'MODULE_NOT_FOUND' });
|
|
28
|
+
} finally {
|
|
29
|
+
await clean(root);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('discovery rewrites calls, preserves context bindings and ignores non-code text', async () => {
|
|
34
|
+
const root = await mkdtemp(join(await realpath(tmpdir()), 'discovery-calls-'));
|
|
35
|
+
try {
|
|
36
|
+
await mkdir(join(root, 'items'));
|
|
37
|
+
await writeFile(join(root, 'items', 'a.json'), '{"value":1}');
|
|
38
|
+
await writeFile(join(root, 'lazy.js'), 'export const value = 1;');
|
|
39
|
+
const path = join(root, 'entry.js');
|
|
40
|
+
let load;
|
|
41
|
+
eightshiftDiscovery({ root, outputDir: 'generated' }).setup({ onLoad(_options, handler) { load = handler; } });
|
|
42
|
+
const inert = `// require.context('./missing', true, /x/)
|
|
43
|
+
const text = "import('./missing.js') require.context";
|
|
44
|
+
const template = \`import('./also-missing.js')\`;
|
|
45
|
+
const regex = /import\\('missing'\\)/;
|
|
46
|
+
const jsx = <div>require.context import('./missing.js')</div>;`;
|
|
47
|
+
await writeFile(path, inert);
|
|
48
|
+
assert.equal(await load({ path }), undefined);
|
|
49
|
+
const chunks = new Map();
|
|
50
|
+
const lazy = editorLazyImports({ root, chunks });
|
|
51
|
+
assert.equal(lazy.transformSource(inert, path), inert);
|
|
52
|
+
assert.equal(chunks.size, 0);
|
|
53
|
+
await writeFile(path, `${inert}\nconst context0 = require /* gap */ . context('./items', true, /\\.json$/);\nconst context1 = 1;`);
|
|
54
|
+
const transformed = await load({ path });
|
|
55
|
+
assert.match(transformed.contents, /const context0 = context2;/);
|
|
56
|
+
assert.ok(transformed.contents.includes(inert));
|
|
57
|
+
const generated = transformed.contents.match(/^import .* from ("[^"]+");/)[1];
|
|
58
|
+
assert.match(await readFile(JSON.parse(generated), 'utf8'), /context2/);
|
|
59
|
+
const source = `${inert}\nconst value = import /* gap */ ('./lazy.js');\nconst nested = \`result: \${import('./lazy.js')}\`;`;
|
|
60
|
+
const rewritten = lazy.transformSource(source, path);
|
|
61
|
+
assert.ok(rewritten.includes(inert));
|
|
62
|
+
assert.equal(chunks.size, 1);
|
|
63
|
+
assert.equal((rewritten.match(/import\(new URL/g) ?? []).length, 2);
|
|
64
|
+
await writeFile(path, 'const value = require.context(directory, true, /x/);');
|
|
65
|
+
await assert.rejects(load({ path }), /Unsupported require.context/);
|
|
66
|
+
} finally {
|
|
67
|
+
await clean(root);
|
|
68
|
+
}
|
|
69
|
+
});
|