@eightshift/frontend-libs-tailwind 4.0.0-beta.3 → 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 +30 -1
- package/README.md +149 -12
- 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 +171 -0
- package/bun/cli-worker.mjs +57 -0
- package/bun/cli.mjs +3 -49
- 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 +17 -5
- 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 +140 -0
- package/bun/ssr.mjs +26 -12
- package/bun/structured-publication.mjs +66 -0
- package/bun/theme-build.mjs +130 -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
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { delimiter, resolve } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
|
|
5
|
+
export async function supervise(invocation) {
|
|
6
|
+
const watching = invocation.command === 'watch';
|
|
7
|
+
const inputs = [invocation.config, ...['package.json', 'bun.lock', 'bun.lockb'].map((name) => resolve(name))];
|
|
8
|
+
const snapshot = () =>
|
|
9
|
+
JSON.stringify(
|
|
10
|
+
inputs.map((path) => {
|
|
11
|
+
try {
|
|
12
|
+
return readFileSync(path).toString('base64');
|
|
13
|
+
} catch (error) {
|
|
14
|
+
if (error.code === 'ENOENT') {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
}),
|
|
21
|
+
);
|
|
22
|
+
let observed = watching ? snapshot() : '';
|
|
23
|
+
let child,
|
|
24
|
+
ready,
|
|
25
|
+
resolveReady,
|
|
26
|
+
timer,
|
|
27
|
+
changedAt = 0,
|
|
28
|
+
pending = false,
|
|
29
|
+
closing = false,
|
|
30
|
+
busy = false,
|
|
31
|
+
failure = 0;
|
|
32
|
+
let draining;
|
|
33
|
+
const drain = () => {
|
|
34
|
+
if (!child) {
|
|
35
|
+
return Promise.resolve();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!draining) {
|
|
39
|
+
const current = child;
|
|
40
|
+
draining = (async () => {
|
|
41
|
+
await Promise.race([ready, current.exited]);
|
|
42
|
+
|
|
43
|
+
if (current.exitCode === null) {
|
|
44
|
+
current.send('stop');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
await current.exited;
|
|
48
|
+
|
|
49
|
+
if (child === current) {
|
|
50
|
+
child = undefined;
|
|
51
|
+
}
|
|
52
|
+
})();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return draining;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const launch = () => {
|
|
59
|
+
draining = undefined;
|
|
60
|
+
ready = new Promise((done) => {
|
|
61
|
+
resolveReady = done;
|
|
62
|
+
});
|
|
63
|
+
child = Bun.spawn([process.execPath, fileURLToPath(new URL('./cli-worker.mjs', import.meta.url)), JSON.stringify(invocation)], {
|
|
64
|
+
cwd: process.cwd(),
|
|
65
|
+
env: { ...process.env, NODE_PATH: [resolve('node_modules'), process.env.NODE_PATH].filter(Boolean).join(delimiter) },
|
|
66
|
+
stdin: 'inherit',
|
|
67
|
+
stdout: 'inherit',
|
|
68
|
+
stderr: 'inherit',
|
|
69
|
+
ipc(message) {
|
|
70
|
+
if (message === 'ready') {
|
|
71
|
+
resolveReady();
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
const current = child;
|
|
76
|
+
void current.exited.then((code) => {
|
|
77
|
+
if (child === current && !busy && !closing) {
|
|
78
|
+
failure = code || failure;
|
|
79
|
+
|
|
80
|
+
if (watching) {
|
|
81
|
+
console.error(`[eightshift-build] Worker exited (${code}); waiting for a restart input change.`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const stop = async () => {
|
|
88
|
+
if (closing) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
closing = true;
|
|
93
|
+
|
|
94
|
+
if (!watching) {
|
|
95
|
+
failure ||= 1;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
clearInterval(timer);
|
|
99
|
+
|
|
100
|
+
while (busy) {
|
|
101
|
+
await Bun.sleep(20);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
await drain();
|
|
105
|
+
process.exitCode = failure;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
process.on('SIGINT', stop);
|
|
109
|
+
process.on('SIGTERM', stop);
|
|
110
|
+
|
|
111
|
+
try {
|
|
112
|
+
launch();
|
|
113
|
+
|
|
114
|
+
if (!watching) {
|
|
115
|
+
failure = (await child.exited) || failure;
|
|
116
|
+
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
timer = setInterval(async () => {
|
|
121
|
+
if (closing || busy) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
try {
|
|
126
|
+
const next = snapshot();
|
|
127
|
+
|
|
128
|
+
if (next !== observed) {
|
|
129
|
+
observed = next;
|
|
130
|
+
changedAt = Date.now();
|
|
131
|
+
pending = true;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (!pending || Date.now() - changedAt < 200) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
busy = true;
|
|
139
|
+
await drain();
|
|
140
|
+
observed = snapshot();
|
|
141
|
+
pending = false;
|
|
142
|
+
|
|
143
|
+
if (!closing) {
|
|
144
|
+
launch();
|
|
145
|
+
}
|
|
146
|
+
} catch (error) {
|
|
147
|
+
console.error(error);
|
|
148
|
+
failure = 1;
|
|
149
|
+
pending = false;
|
|
150
|
+
} finally {
|
|
151
|
+
busy = false;
|
|
152
|
+
}
|
|
153
|
+
}, 100);
|
|
154
|
+
|
|
155
|
+
while (!closing) {
|
|
156
|
+
await Bun.sleep(100);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
await stop();
|
|
160
|
+
} finally {
|
|
161
|
+
while (busy) {
|
|
162
|
+
await Bun.sleep(20);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
await drain();
|
|
166
|
+
clearInterval(timer);
|
|
167
|
+
process.removeListener('SIGINT', stop);
|
|
168
|
+
process.removeListener('SIGTERM', stop);
|
|
169
|
+
process.exitCode = failure;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { pathToFileURL } from 'node:url';
|
|
2
|
+
|
|
3
|
+
let stopping = false;
|
|
4
|
+
let watcher;
|
|
5
|
+
let drain;
|
|
6
|
+
const stop = () => {
|
|
7
|
+
stopping = true;
|
|
8
|
+
|
|
9
|
+
if (watcher && !drain) {
|
|
10
|
+
drain = Promise.resolve()
|
|
11
|
+
.then(() => watcher.stop())
|
|
12
|
+
.catch((error) => {
|
|
13
|
+
console.error(error);
|
|
14
|
+
process.exitCode = 1;
|
|
15
|
+
})
|
|
16
|
+
.finally(() => process.disconnect?.());
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
process.on('SIGINT', stop);
|
|
21
|
+
process.on('SIGTERM', stop);
|
|
22
|
+
process.on('message', (message) => {
|
|
23
|
+
if (message === 'stop') {
|
|
24
|
+
stop();
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
process.send('ready');
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
const { command, config, options } = JSON.parse(process.argv[2]);
|
|
31
|
+
const { default: definition } = await import(pathToFileURL(config).href);
|
|
32
|
+
|
|
33
|
+
if (!definition || typeof definition.build !== 'function' || typeof definition.watch !== 'function') {
|
|
34
|
+
throw new TypeError('Config default export must be a defineBuild result');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (!stopping) {
|
|
38
|
+
if (command === 'build') {
|
|
39
|
+
await definition.build(options);
|
|
40
|
+
} else {
|
|
41
|
+
watcher = definition.watch(options);
|
|
42
|
+
}
|
|
43
|
+
} else if (command === 'build') {
|
|
44
|
+
process.exitCode = 1;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (stopping) {
|
|
48
|
+
stop();
|
|
49
|
+
}
|
|
50
|
+
} catch (error) {
|
|
51
|
+
console.error(error);
|
|
52
|
+
process.exitCode = 1;
|
|
53
|
+
} finally {
|
|
54
|
+
if (!watcher) {
|
|
55
|
+
process.disconnect?.();
|
|
56
|
+
}
|
|
57
|
+
}
|
package/bun/cli.mjs
CHANGED
|
@@ -1,27 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
-
import {
|
|
3
|
-
import { pathToFileURL } from 'node:url';
|
|
4
|
-
|
|
5
|
-
const projectModules = resolve('node_modules');
|
|
6
|
-
|
|
7
|
-
if (!(process.env.NODE_PATH ?? '').split(delimiter).includes(projectModules)) {
|
|
8
|
-
const child = Bun.spawn([process.execPath, ...process.argv.slice(1)], {
|
|
9
|
-
cwd: process.cwd(),
|
|
10
|
-
env: { ...process.env, NODE_PATH: [projectModules, process.env.NODE_PATH].filter(Boolean).join(delimiter) },
|
|
11
|
-
stdin: 'inherit',
|
|
12
|
-
stdout: 'inherit',
|
|
13
|
-
stderr: 'inherit',
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
const forwardInt = () => child.kill('SIGINT');
|
|
17
|
-
const forwardTerm = () => child.kill('SIGTERM');
|
|
18
|
-
process.on('SIGINT', forwardInt);
|
|
19
|
-
process.on('SIGTERM', forwardTerm);
|
|
20
|
-
const exitCode = await child.exited;
|
|
21
|
-
process.removeListener('SIGINT', forwardInt);
|
|
22
|
-
process.removeListener('SIGTERM', forwardTerm);
|
|
23
|
-
process.exit(exitCode);
|
|
24
|
-
}
|
|
2
|
+
import { resolve } from 'node:path';
|
|
25
3
|
|
|
26
4
|
const args = process.argv.slice(2);
|
|
27
5
|
const command = args.shift();
|
|
@@ -62,29 +40,5 @@ if (options.quiet && options.verbose) {
|
|
|
62
40
|
throw new Error('--quiet and --verbose cannot be combined');
|
|
63
41
|
}
|
|
64
42
|
|
|
65
|
-
const {
|
|
66
|
-
|
|
67
|
-
if (!definition || typeof definition.build !== 'function' || typeof definition.watch !== 'function') {
|
|
68
|
-
throw new TypeError('Config default export must be a defineBuild result');
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (command === 'build') {
|
|
72
|
-
await definition.build(options);
|
|
73
|
-
} else {
|
|
74
|
-
const watcher = definition.watch(options);
|
|
75
|
-
let stopping;
|
|
76
|
-
const stop = () => {
|
|
77
|
-
if (!stopping) {
|
|
78
|
-
stopping = Promise.resolve()
|
|
79
|
-
.then(() => watcher.stop())
|
|
80
|
-
.finally(() => {
|
|
81
|
-
process.removeListener('SIGINT', stop);
|
|
82
|
-
process.removeListener('SIGTERM', stop);
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
return stopping;
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
process.on('SIGINT', stop);
|
|
89
|
-
process.on('SIGTERM', stop);
|
|
90
|
-
}
|
|
43
|
+
const { supervise } = await import('./cli-supervisor.mjs');
|
|
44
|
+
await supervise({ command, config: resolve(config), options });
|
package/bun/css.mjs
CHANGED
|
@@ -1,22 +1,29 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Features, loadModule, Polyfills } from '@tailwindcss/node';
|
|
2
|
+
import fs from 'node:fs';
|
|
2
3
|
import { Scanner } from '@tailwindcss/oxide';
|
|
3
|
-
import { createHash } from 'node:crypto';
|
|
4
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
4
5
|
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
5
6
|
import { createRequire } from 'node:module';
|
|
6
|
-
import { dirname, extname, relative, resolve } from 'node:path';
|
|
7
|
+
import { delimiter, dirname, extname, relative, resolve } from 'node:path';
|
|
7
8
|
import browserslist from 'browserslist';
|
|
8
9
|
import { browserslistToTargets, transform } from 'lightningcss';
|
|
9
10
|
import postcss from 'postcss';
|
|
10
11
|
import valueParser from 'postcss-value-parser';
|
|
11
12
|
|
|
12
13
|
const require = createRequire(import.meta.url);
|
|
14
|
+
// Use the compiler and CSS resolver shipped with our Tailwind Node adapter.
|
|
15
|
+
const tailwindRequire = createRequire(require.resolve('@tailwindcss/node'));
|
|
16
|
+
const { compile } = tailwindRequire('tailwindcss');
|
|
17
|
+
const { CachedInputFileSystem, ResolverFactory } = tailwindRequire('enhanced-resolve');
|
|
13
18
|
|
|
14
19
|
/**
|
|
15
20
|
* Compile ordered stylesheets to one CSS file.
|
|
16
21
|
* Paths are relative to projectDir unless absolute. Each files entry is a path
|
|
17
|
-
* or { file, scan, sources, scanFiles, removeSources };
|
|
18
|
-
*
|
|
19
|
-
*
|
|
22
|
+
* or { file, content, scan, sources, scanFiles, removeSources }; content can
|
|
23
|
+
* replace the source text, while file remains the base for relative imports.
|
|
24
|
+
* scan enables candidate scanning, or 'auto' scans only when utilities are requested.
|
|
25
|
+
* sources extends detected sources, scanFiles adds explicit candidate files,
|
|
26
|
+
* and removeSources removes exact @source rules.
|
|
20
27
|
* Assets are copied beside outputFile with content-hashed names.
|
|
21
28
|
*/
|
|
22
29
|
export async function processCss({ projectDir, outputFile, files, production = false, browsers = '>= 0.25%' }) {
|
|
@@ -30,7 +37,9 @@ export async function processCss({ projectDir, outputFile, files, production = f
|
|
|
30
37
|
|
|
31
38
|
await mkdir(outdir, { recursive: true });
|
|
32
39
|
|
|
33
|
-
const
|
|
40
|
+
const assetReferences = new Map();
|
|
41
|
+
const assetPrefix = `eightshift-asset:${randomUUID()}:`;
|
|
42
|
+
const rewriteAssets = async (css, base, compiled = false) => {
|
|
34
43
|
const tree = postcss.parse(css);
|
|
35
44
|
const pending = [];
|
|
36
45
|
|
|
@@ -38,26 +47,37 @@ export async function processCss({ projectDir, outputFile, files, production = f
|
|
|
38
47
|
const value = valueParser(declaration.value);
|
|
39
48
|
const assets = [];
|
|
40
49
|
|
|
41
|
-
|
|
42
|
-
|
|
50
|
+
const rewriteUrl = (node) => {
|
|
51
|
+
const reference = compiled ? assetReferences.get(node.value) : undefined;
|
|
52
|
+
const url = reference?.url ?? node.value;
|
|
53
|
+
const assetBase = reference?.base ?? base;
|
|
54
|
+
|
|
55
|
+
if (!url || /^(?:[a-z][a-z\d+.-]*:|\/|#)/i.test(url)) {
|
|
43
56
|
return;
|
|
44
57
|
}
|
|
45
58
|
|
|
46
|
-
|
|
47
|
-
.
|
|
48
|
-
.
|
|
49
|
-
.
|
|
59
|
+
if (!compiled) {
|
|
60
|
+
const token = `${assetPrefix}${assetReferences.size}`;
|
|
61
|
+
assetReferences.set(token, { url, base });
|
|
62
|
+
node.value = token;
|
|
50
63
|
|
|
51
|
-
if (!url || /^(?:[a-z][a-z\d+.-]*:|\/|#)/i.test(url)) {
|
|
52
64
|
return;
|
|
53
65
|
}
|
|
54
66
|
|
|
55
67
|
assets.push(
|
|
56
68
|
(async () => {
|
|
57
69
|
const suffixIndex = url.search(/[?#]/);
|
|
58
|
-
const
|
|
70
|
+
const encodedPathname = suffixIndex < 0 ? url : url.slice(0, suffixIndex);
|
|
59
71
|
const suffix = suffixIndex < 0 ? '' : url.slice(suffixIndex);
|
|
60
|
-
let
|
|
72
|
+
let pathname;
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
pathname = decodeURIComponent(encodedPathname);
|
|
76
|
+
} catch (cause) {
|
|
77
|
+
throw new Error(`Invalid percent encoding in CSS asset URL ${JSON.stringify(url)} relative to ${assetBase}`, { cause });
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
let asset = resolve(assetBase, pathname);
|
|
61
81
|
let content;
|
|
62
82
|
|
|
63
83
|
try {
|
|
@@ -67,16 +87,42 @@ export async function processCss({ projectDir, outputFile, files, production = f
|
|
|
67
87
|
throw error;
|
|
68
88
|
}
|
|
69
89
|
|
|
70
|
-
asset = require.resolve(pathname, { paths: [
|
|
90
|
+
asset = require.resolve(pathname, { paths: [assetBase] });
|
|
71
91
|
content = await readFile(asset);
|
|
72
92
|
}
|
|
73
93
|
|
|
74
94
|
const name = `${createHash('sha256').update(content).digest('hex').slice(0, 20)}${extname(asset)}`;
|
|
75
95
|
|
|
76
96
|
await writeFile(resolve(outdir, name), content);
|
|
77
|
-
node.
|
|
97
|
+
node.type = 'string';
|
|
98
|
+
node.quote ??= '"';
|
|
99
|
+
node.value = `./${name}${suffix}`;
|
|
100
|
+
dependencies.add(asset);
|
|
78
101
|
})(),
|
|
79
102
|
);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
value.walk((node) => {
|
|
106
|
+
if (node.type !== 'function') {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const name = node.value.toLowerCase();
|
|
111
|
+
|
|
112
|
+
if (name === 'url') {
|
|
113
|
+
const url = node.nodes.filter((child) => child.type !== 'space' && child.type !== 'comment');
|
|
114
|
+
|
|
115
|
+
if (url.length === 1 && (url[0].type === 'string' || url[0].type === 'word')) {
|
|
116
|
+
rewriteUrl(url[0]);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (name === 'image-set' || name === '-webkit-image-set') {
|
|
123
|
+
// Only direct strings are images; nested type("image/avif") is a descriptor.
|
|
124
|
+
node.nodes.filter((child) => child.type === 'string').forEach((child) => rewriteUrl(child));
|
|
125
|
+
}
|
|
80
126
|
});
|
|
81
127
|
pending.push(
|
|
82
128
|
Promise.all(assets).then(() => {
|
|
@@ -91,6 +137,30 @@ export async function processCss({ projectDir, outputFile, files, production = f
|
|
|
91
137
|
|
|
92
138
|
const parts = [];
|
|
93
139
|
const dependencies = new Set();
|
|
140
|
+
const cssResolver = ResolverFactory.createResolver({
|
|
141
|
+
fileSystem: new CachedInputFileSystem(fs, 4000),
|
|
142
|
+
extensions: ['.css'],
|
|
143
|
+
mainFields: ['style'],
|
|
144
|
+
conditionNames: ['style'],
|
|
145
|
+
modules: ['node_modules', ...(process.env.NODE_PATH ? process.env.NODE_PATH.split(delimiter) : [])],
|
|
146
|
+
});
|
|
147
|
+
const loadStylesheet = async (id, base) => {
|
|
148
|
+
const path = await new Promise((accept, reject) => {
|
|
149
|
+
cssResolver.resolve({}, base, id, {}, (error, result) => {
|
|
150
|
+
if (error) {
|
|
151
|
+
reject(error);
|
|
152
|
+
} else if (!result) {
|
|
153
|
+
reject(new Error(`Could not resolve '${id}' from '${base}'`));
|
|
154
|
+
} else {
|
|
155
|
+
accept(result);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
dependencies.add(path);
|
|
160
|
+
|
|
161
|
+
// Retain each URL's source base through compilation; copy only emitted assets.
|
|
162
|
+
return { path, base: dirname(path), content: await rewriteAssets(await readFile(path, 'utf8'), dirname(path)) };
|
|
163
|
+
};
|
|
94
164
|
|
|
95
165
|
for (const entry of files) {
|
|
96
166
|
const options = typeof entry === 'string' ? { file: entry } : entry;
|
|
@@ -99,8 +169,12 @@ export async function processCss({ projectDir, outputFile, files, production = f
|
|
|
99
169
|
throw new Error('Each CSS entry requires a file path.');
|
|
100
170
|
}
|
|
101
171
|
|
|
172
|
+
if (options.content !== undefined && typeof options.content !== 'string') {
|
|
173
|
+
throw new TypeError('CSS entry content must be a string.');
|
|
174
|
+
}
|
|
175
|
+
|
|
102
176
|
const file = resolve(root, options.file);
|
|
103
|
-
let input = await readFile(file, 'utf8');
|
|
177
|
+
let input = options.content ?? (await readFile(file, 'utf8'));
|
|
104
178
|
|
|
105
179
|
dependencies.add(file);
|
|
106
180
|
|
|
@@ -112,16 +186,40 @@ export async function processCss({ projectDir, outputFile, files, production = f
|
|
|
112
186
|
input = input.replace(source, '');
|
|
113
187
|
}
|
|
114
188
|
|
|
115
|
-
const compiler = await compile(input, {
|
|
189
|
+
const compiler = await compile(await rewriteAssets(input, dirname(file)), {
|
|
116
190
|
base: dirname(file),
|
|
117
191
|
from: file,
|
|
118
|
-
shouldRewriteUrls: true,
|
|
119
192
|
polyfills: Polyfills.All,
|
|
120
|
-
|
|
193
|
+
loadStylesheet,
|
|
194
|
+
loadModule: (id, base) => loadModule(id, base, (dependency) => dependencies.add(dependency)),
|
|
121
195
|
});
|
|
196
|
+
|
|
197
|
+
if (compiler.root && compiler.root !== 'none') {
|
|
198
|
+
const directoryParts = [];
|
|
199
|
+
|
|
200
|
+
for (const part of compiler.root.pattern.split('/')) {
|
|
201
|
+
if (/[*{]/.test(part)) {
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
directoryParts.push(part);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const directory = directoryParts.join('/');
|
|
209
|
+
|
|
210
|
+
if (
|
|
211
|
+
!(await fs.promises
|
|
212
|
+
.stat(resolve(compiler.root.base, directory))
|
|
213
|
+
.then((stat) => stat.isDirectory())
|
|
214
|
+
.catch(() => false))
|
|
215
|
+
) {
|
|
216
|
+
throw new Error(`The \`source(${compiler.root.pattern})\` does not exist or is not a directory.`);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
122
220
|
let candidates = [];
|
|
123
221
|
|
|
124
|
-
if (options.scan) {
|
|
222
|
+
if (options.scan && (options.scan !== 'auto' || compiler.features & Features.Utilities)) {
|
|
125
223
|
const sources = (compiler.root === 'none' ? [] : compiler.root === null ? [{ base: root, pattern: '**/*', negated: false }] : [{ ...compiler.root, negated: false }]).concat(
|
|
126
224
|
compiler.sources,
|
|
127
225
|
(options.sources ?? []).map((source) => ({ ...source, base: resolve(root, source.base ?? '.') })),
|
|
@@ -130,10 +228,13 @@ export async function processCss({ projectDir, outputFile, files, production = f
|
|
|
130
228
|
const explicit = (options.scanFiles ?? []).map((item) => (typeof item === 'string' ? { file: resolve(root, item), extension: extname(item).slice(1) } : { ...item, file: resolve(root, item.file) }));
|
|
131
229
|
|
|
132
230
|
explicit.forEach(({ file: candidateFile }) => dependencies.add(candidateFile));
|
|
133
|
-
|
|
231
|
+
const explicitContents = await Promise.all(explicit.map(async ({ file: candidateFile, extension }) => ({ content: await readFile(candidateFile, 'utf8'), extension })));
|
|
232
|
+
const explicitCandidates = explicitContents.length ? new Scanner({ sources: [] }).scanFiles(explicitContents) : [];
|
|
233
|
+
candidates = [...new Set([...scanner.scan(), ...explicitCandidates])];
|
|
134
234
|
}
|
|
135
235
|
|
|
136
|
-
|
|
236
|
+
const compiled = compiler.build(candidates);
|
|
237
|
+
parts.push(`/* ${relative(root, file)} */\n${await rewriteAssets(compiled, dirname(file), true)}`);
|
|
137
238
|
}
|
|
138
239
|
|
|
139
240
|
const css = parts.join('\n');
|
package/bun/discovery.mjs
CHANGED
|
@@ -12,6 +12,7 @@ import { dirname, relative, resolve, sep } from 'node:path';
|
|
|
12
12
|
* to an empty object. JSON contexts return parsed values; other synchronous
|
|
13
13
|
* imports return module namespaces. Regenerate after changing source files.
|
|
14
14
|
* Symlinks are skipped. Missing directories are treated as empty contexts.
|
|
15
|
+
* Names cannot shadow the generated helpers or Map, Promise and Error.
|
|
15
16
|
*/
|
|
16
17
|
export async function generateDiscovery({ root, output, definitions }) {
|
|
17
18
|
if (typeof root !== 'string' || typeof output !== 'string' || !Array.isArray(definitions)) {
|
|
@@ -29,7 +30,17 @@ export async function generateDiscovery({ root, output, definitions }) {
|
|
|
29
30
|
for (const definition of definitions) {
|
|
30
31
|
const { name, directory, pattern, mode = 'sync' } = definition;
|
|
31
32
|
|
|
32
|
-
if (
|
|
33
|
+
if (
|
|
34
|
+
typeof name !== 'string' ||
|
|
35
|
+
!/^[$A-Z_a-z][$\w]*$/.test(name) ||
|
|
36
|
+
!isValidExportName(name) ||
|
|
37
|
+
['createContext', 'Map', 'Promise', 'Error'].includes(name) ||
|
|
38
|
+
/^module\d+$/.test(name) ||
|
|
39
|
+
names.has(name) ||
|
|
40
|
+
typeof directory !== 'string' ||
|
|
41
|
+
!(pattern instanceof RegExp) ||
|
|
42
|
+
!['sync', 'lazy'].includes(mode)
|
|
43
|
+
) {
|
|
33
44
|
throw new TypeError('Invalid or duplicate discovery definition');
|
|
34
45
|
}
|
|
35
46
|
|