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

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/watch.mjs ADDED
@@ -0,0 +1,211 @@
1
+ import { statSync, watch } from 'node:fs';
2
+ import { basename, dirname, isAbsolute, relative, resolve, sep } from 'node:path';
3
+
4
+ /**
5
+ * Watch source paths under projectDir and run build serially after changes settle.
6
+ * Paths in sources and ignored are relative to projectDir unless absolute.
7
+ * Ignored paths exclude themselves and their descendants, including outputs.
8
+ * `ignore` optionally filters absolute event paths in addition to ignored paths.
9
+ * Returns { stop }, whose promise settles after any running build finishes.
10
+ * Build and watcher errors are passed to onError; watcher errors stop watching.
11
+ */
12
+ export function watchBuild({ projectDir, sources, ignored = [], ignore = () => false, build, debounce = 200, initial = true, onError = console.error }) {
13
+ if (!projectDir || !Array.isArray(sources) || sources.length === 0 || !Array.isArray(ignored) || typeof ignore !== 'function' || typeof build !== 'function' || typeof onError !== 'function' || !Number.isFinite(debounce) || debounce < 0) {
14
+ throw new TypeError('watchBuild requires projectDir, sources, a build function, and a non-negative debounce.');
15
+ }
16
+
17
+ const root = resolve(projectDir);
18
+ const within = (parent, path) => {
19
+ const rel = relative(parent, path);
20
+
21
+ return rel === '' || (rel !== '..' && !rel.startsWith(`..${sep}`) && !isAbsolute(rel));
22
+ };
23
+ const paths = (items) =>
24
+ items.map((item) => {
25
+ if (typeof item !== 'string' || !item) {
26
+ throw new TypeError('Watch paths must be non-empty strings.');
27
+ }
28
+
29
+ const path = resolve(root, item);
30
+
31
+ if (!within(root, path)) {
32
+ throw new TypeError('Watch paths must be inside projectDir.');
33
+ }
34
+
35
+ return path;
36
+ });
37
+ const inputs = paths(sources);
38
+ const exclusions = paths(ignored);
39
+ let timer;
40
+ let running;
41
+ let pending = false;
42
+ let stopped = false;
43
+ const watchers = new Map();
44
+
45
+ const report = (error) => {
46
+ try {
47
+ onError(error);
48
+ } catch (callbackError) {
49
+ console.error(callbackError);
50
+ }
51
+ };
52
+ const run = () => {
53
+ if (stopped || running || !pending) {
54
+ return;
55
+ }
56
+
57
+ pending = false;
58
+ running = Promise.resolve()
59
+ .then(build)
60
+ .catch(report)
61
+ .finally(() => {
62
+ running = undefined;
63
+
64
+ if (!timer) {
65
+ run();
66
+ }
67
+ });
68
+ };
69
+ const schedule = () => {
70
+ if (stopped) {
71
+ return;
72
+ }
73
+
74
+ pending = true;
75
+ clearTimeout(timer);
76
+ timer = setTimeout(() => {
77
+ timer = undefined;
78
+ run();
79
+ }, debounce);
80
+ };
81
+ const stop = async () => {
82
+ if (!stopped) {
83
+ stopped = true;
84
+ pending = false;
85
+ clearTimeout(timer);
86
+ for (const watcher of watchers.values()) {
87
+ watcher.close();
88
+ }
89
+ watchers.clear();
90
+ }
91
+
92
+ await running;
93
+ };
94
+
95
+ const onEvent = (path) => {
96
+ if (stopped) {
97
+ return;
98
+ }
99
+
100
+ if (!within(root, path) || exclusions.some((item) => within(item, path))) {
101
+ return;
102
+ }
103
+
104
+ try {
105
+ if (ignore(path)) {
106
+ return;
107
+ }
108
+ } catch (error) {
109
+ report(error);
110
+ return;
111
+ }
112
+
113
+ if (inputs.some((item) => within(item, path) || within(path, item))) {
114
+ schedule();
115
+ }
116
+ };
117
+ const refresh = () => {
118
+ if (stopped) {
119
+ return;
120
+ }
121
+ const desired = new Map();
122
+ const add = (directory, recursive, name) => {
123
+ const key = `${recursive ? 'recursive' : 'parent'}:${directory}`;
124
+ if (!desired.has(key)) {
125
+ desired.set(key, { directory, recursive, names: new Set() });
126
+ }
127
+ if (name) {
128
+ desired.get(key).names.add(name);
129
+ }
130
+ };
131
+ for (const input of inputs) {
132
+ let current = input;
133
+ let info;
134
+ while (true) {
135
+ try {
136
+ info = statSync(current);
137
+ break;
138
+ } catch (error) {
139
+ if (error.code !== 'ENOENT' && error.code !== 'ENOTDIR') {
140
+ throw error;
141
+ }
142
+ if (current === root) {
143
+ throw error;
144
+ }
145
+ current = dirname(current);
146
+ }
147
+ }
148
+ if (current === input && info.isDirectory()) {
149
+ add(input, true);
150
+ if (input !== root) {
151
+ add(dirname(input), false, basename(input));
152
+ }
153
+ } else {
154
+ const directory = current === input ? dirname(input) : current;
155
+ const next = relative(directory, input).split(sep)[0];
156
+ add(directory, false, next);
157
+ }
158
+ }
159
+ for (const [key, config] of desired) {
160
+ const existing = watchers.get(key);
161
+ if (existing) {
162
+ existing.names = config.names;
163
+ continue;
164
+ }
165
+ const watcher = watch(config.directory, { recursive: config.recursive }, (_event, filename) => {
166
+ if (!filename || stopped) {
167
+ return;
168
+ }
169
+ const name = String(filename);
170
+ if (!config.recursive && !watcher.names.has(name)) {
171
+ return;
172
+ }
173
+ const path = resolve(config.directory, name);
174
+ onEvent(path);
175
+ try {
176
+ refresh();
177
+ } catch (error) {
178
+ report(error);
179
+ void stop();
180
+ }
181
+ });
182
+ watcher.names = config.names;
183
+ watcher.on('error', (error) => {
184
+ report(error);
185
+ void stop();
186
+ });
187
+ watchers.set(key, watcher);
188
+ }
189
+ for (const [key, watcher] of watchers) {
190
+ if (!desired.has(key)) {
191
+ watcher.close();
192
+ watchers.delete(key);
193
+ }
194
+ }
195
+ };
196
+ try {
197
+ refresh();
198
+ } catch (error) {
199
+ for (const watcher of watchers.values()) {
200
+ watcher.close();
201
+ }
202
+ throw error;
203
+ }
204
+
205
+ if (initial) {
206
+ pending = true;
207
+ run();
208
+ }
209
+
210
+ return { stop };
211
+ }
@@ -0,0 +1,173 @@
1
+ import { createRequire } from 'node:module';
2
+ import { dirname, isAbsolute, resolve } from 'node:path';
3
+ import { readFile } from 'node:fs/promises';
4
+ import { promisify } from 'node:util';
5
+ import { execFile } from 'node:child_process';
6
+
7
+ const execFileAsync = promisify(execFile);
8
+ const externals = {
9
+ moment: ['moment', 'moment', 'commonjs'],
10
+ jquery: ['jQuery', 'jquery', 'commonjs'],
11
+ lodash: ['lodash', 'lodash', 'commonjs'],
12
+ 'lodash-es': ['lodash', 'lodash', 'esm'],
13
+ '@babel/runtime/regenerator': ['regeneratorRuntime', 'regenerator-runtime', 'commonjs'],
14
+ react: ['React', 'react', 'react'],
15
+ 'react-dom': ['ReactDOM', 'react-dom', 'react'],
16
+ 'react-dom/client': ['ReactDOM', 'react-dom', 'react'],
17
+ 'react/jsx-runtime': ['ReactJSXRuntime', 'react-jsx-runtime', 'react'],
18
+ 'react/jsx-dev-runtime': ['ReactJSXRuntime', 'react-jsx-runtime', 'react'],
19
+ };
20
+
21
+ const bundledWordPressPackages = new Set(['admin-ui', 'dataviews', 'dataviews/wp', 'fields', 'global-styles-engine', 'global-styles-ui', 'grid', 'icons', 'interface', 'kebab-case', 'react-inert-value', 'style-runtime', 'sync', 'ui', 'undo-manager', 'views']);
22
+
23
+ function externalFor(request) {
24
+ if (Object.hasOwn(externals, request)) {
25
+ return externals[request];
26
+ }
27
+
28
+ if (/^(?:react|react-dom)\//.test(request) || request.includes('react-refresh/runtime')) {
29
+ throw new Error(`Unsupported React external: ${request}`);
30
+ }
31
+
32
+ if (!request.startsWith('@wordpress/')) {
33
+ return;
34
+ }
35
+
36
+ const name = request.slice('@wordpress/'.length);
37
+
38
+ if (bundledWordPressPackages.has(name)) {
39
+ return;
40
+ }
41
+
42
+ if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(name)) {
43
+ throw new Error(`Unsupported WordPress external: ${request}`);
44
+ }
45
+
46
+ return [['wp', name.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase())], `wp-${name}`, 'wordpress'];
47
+ }
48
+
49
+ async function coreExports(root, request) {
50
+ if (!root) {
51
+ throw new Error(`WordPress root is required to discover exports for ${request}`);
52
+ }
53
+
54
+ const name = request.slice('@wordpress/'.length);
55
+ const script = await readFile(resolve(root, 'wp-includes/js/dist', `${name}.js`), 'utf8');
56
+ const matches = [...script.matchAll(/__export\(index_exports, \{([\s\S]*?)\n\s*\}\);/g)];
57
+
58
+ if (matches.length !== 1 || !script.includes('return __toCommonJS(index_exports);')) {
59
+ throw new Error(`Cannot identify WordPress core exports for ${request}`);
60
+ }
61
+
62
+ const names = matches[0][1]
63
+ .trim()
64
+ .split(/,\s*\n/)
65
+ .map((entry) => entry.trim().match(/^([A-Za-z_$][\w$]*):\s*\(\)\s*=>\s*[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*$/)?.[1]);
66
+
67
+ if (!names.length || names.some((name) => !name) || new Set(names).size !== names.length) {
68
+ throw new Error(`Cannot parse WordPress core exports for ${request}`);
69
+ }
70
+
71
+ return names;
72
+ }
73
+
74
+ /** Create a fresh adapter for each Bun build. Paths must be absolute. */
75
+ export function wordpressPlugin({ projectRoot = process.cwd(), wpRoot } = {}) {
76
+ if (!isAbsolute(projectRoot) || (wpRoot !== undefined && !isAbsolute(wpRoot))) {
77
+ throw new Error('projectRoot and wpRoot must be absolute paths');
78
+ }
79
+
80
+ const projectRequire = createRequire(resolve(projectRoot, 'package.json'));
81
+ const dependencies = new Set();
82
+ const modules = new Map();
83
+
84
+ return {
85
+ dependencies,
86
+ plugin: {
87
+ name: 'wordpress-globals',
88
+ setup(build) {
89
+ build.onResolve({ filter: /.*/ }, async (args) => {
90
+ const request = args.path;
91
+ const external = externalFor(request);
92
+
93
+ if (!external) {
94
+ return;
95
+ }
96
+
97
+ const [global, handle, kind] = external;
98
+ const require = isAbsolute(args.importer) ? createRequire(args.importer) : projectRequire;
99
+ let metadata;
100
+ let entry;
101
+ let fallback = false;
102
+
103
+ if (kind === 'wordpress') {
104
+ try {
105
+ metadata = require(`${request}/package.json`);
106
+ } catch (error) {
107
+ if (error.code !== 'MODULE_NOT_FOUND' || !['@wordpress/plugins', '@wordpress/core-data'].includes(request)) {
108
+ throw error;
109
+ }
110
+
111
+ fallback = true;
112
+ }
113
+
114
+ if (!fallback && metadata.wpScript !== true) {
115
+ throw new Error(`Missing wpScript metadata: ${request}`);
116
+ }
117
+ }
118
+
119
+ if (kind !== 'commonjs' && kind !== 'wordpress') {
120
+ const importer = isAbsolute(args.importer) ? args.importer : resolve(projectRoot, '__wordpress_plugin__.mjs');
121
+
122
+ entry = kind === 'react' ? require.resolve(request) : Bun.resolveSync(request, dirname(importer));
123
+ }
124
+
125
+ const key = JSON.stringify([request, entry || '', fallback]);
126
+
127
+ if (!modules.has(key)) {
128
+ let names = [];
129
+
130
+ try {
131
+ if (kind === 'wordpress') {
132
+ names = await coreExports(wpRoot, request);
133
+ } else if (kind === 'react') {
134
+ names = ['default', ...Object.keys(require(entry)).filter((name) => name !== 'default')];
135
+ } else if (kind !== 'commonjs') {
136
+ const script = `const r = await Bun.build({ entrypoints: [process.argv[1]], target: 'browser', format: 'esm', write: false }); if (!r.success || r.outputs.length !== 1) { console.error(r.logs.join('\\n')); process.exit(1); } console.log(JSON.stringify(new Bun.Transpiler().scan(await r.outputs[0].text()).exports));`;
137
+ const result = await execFileAsync(process.execPath, ['-e', script, entry], { cwd: projectRoot, maxBuffer: 1024 * 1024 });
138
+
139
+ names = JSON.parse(result.stdout);
140
+ }
141
+ } catch (error) {
142
+ throw new Error(`Cannot determine exports for ${request}: ${error.message}`);
143
+ }
144
+
145
+ const path = Array.isArray(global) ? global : [global];
146
+ 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}`)});`];
147
+
148
+ if (request === 'react/jsx-dev-runtime') {
149
+ lines.push("if (typeof value.jsx !== 'function') throw new Error('Missing ReactJSXRuntime.jsx');", 'module.exports = { Fragment: value.Fragment, jsxDEV: (type, props, key) => value.jsx(type, props, key) };');
150
+ } else if (kind === 'commonjs' || kind === 'react') {
151
+ lines.push('module.exports = value;');
152
+ } else {
153
+ for (const [index, name] of names.entries()) {
154
+ if (name === 'default') {
155
+ lines.push(kind === 'esm' || metadata?.wpScriptDefaultExport === true ? 'export default value;' : 'export default value.default;');
156
+ } else {
157
+ lines.push(`const export${index} = value[${JSON.stringify(name)}];`, `export { export${index} as ${name} };`);
158
+ }
159
+ }
160
+ }
161
+
162
+ modules.set(key, lines.join('\n'));
163
+ }
164
+
165
+ dependencies.add(handle);
166
+
167
+ return { path: key, namespace: 'wordpress-global' };
168
+ });
169
+ build.onLoad({ filter: /.*/, namespace: 'wordpress-global' }, (args) => ({ contents: modules.get(args.path), loader: 'js' }));
170
+ },
171
+ },
172
+ };
173
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eightshift/frontend-libs-tailwind",
3
- "version": "3.5.0",
3
+ "version": "4.0.0-beta.1",
4
4
  "description": "A framework for creating modern Gutenberg themes with styling provided by Tailwind CSS.",
5
5
  "author": {
6
6
  "name": "Eightshift team",
@@ -32,20 +32,17 @@
32
32
  "prepare": "husky"
33
33
  },
34
34
  "bin": {
35
- "tw-sweep": "bin/tw-sweep.mjs"
35
+ "tw-sweep": "bin/tw-sweep.mjs",
36
+ "eightshift-build": "bun/cli.mjs"
36
37
  },
37
38
  "homepage": "https://github.com/infinum/eightshift-frontend-libs-tailwind#readme",
38
39
  "license": "MIT",
39
40
  "dependencies": {
40
41
  "@stylistic/eslint-plugin": "^5.10.0",
41
42
  "@stylistic/stylelint-plugin": "^5.2.1",
42
- "@swc/core": "^1.15.43",
43
43
  "@tailwindcss/node": "^4.3.3",
44
- "@tailwindcss/webpack": "^4.3.3",
45
- "@wordpress/dependency-extraction-webpack-plugin": "^6.51.0",
46
- "browserslist": "^4.28.6",
47
- "css-loader": "^7.1.4",
48
- "css-minimizer-webpack-plugin": "^8.0.0",
44
+ "@tailwindcss/oxide": "^4.3.3",
45
+ "browserslist": "^4.29.3",
49
46
  "eslint": "^10.7.0",
50
47
  "eslint-config-prettier": "^10.1.8",
51
48
  "eslint-plugin-better-tailwindcss": "^4.7.0",
@@ -56,20 +53,15 @@
56
53
  "glob": "^13.0.6",
57
54
  "globals": "^17.7.0",
58
55
  "husky": "^9.1.7",
59
- "lightningcss": "^1.32.0",
60
- "mini-css-extract-plugin": "^2.10.2",
56
+ "lightningcss": "^1.33.0",
61
57
  "oxlint": "^1.82.0",
58
+ "postcss": "^8.5.30",
59
+ "postcss-value-parser": "^4.2.0",
62
60
  "prettier": "^3.9.5",
63
61
  "prettier-plugin-tailwindcss": "^0.8.1",
64
62
  "sonner": "^2.0.7",
65
63
  "stylelint": "^17.14.0",
66
- "stylelint-config-standard": "^40.0.0",
67
- "swc-loader": "^0.2.7",
68
- "terser-webpack-plugin": "^5.6.1",
69
- "webpack": "^5.108.4",
70
- "webpack-cli": "^7.2.1",
71
- "webpack-manifest-plugin": "^6.0.1",
72
- "webpack-merge": "^6.0.1"
64
+ "stylelint-config-standard": "^40.0.0"
73
65
  },
74
66
  "devDependencies": {
75
67
  "@wordpress/api-fetch": "^7.51.0",