From 63073c972b03e63148c8ae94696453d9fd427601 Mon Sep 17 00:00:00 2001 From: Osvaldo Ortega Date: Mon, 2 Mar 2026 20:14:34 -0800 Subject: [PATCH] Refactor: update CSS module collection to use tinyglobby and add fallback for recursive file search --- scripts/code-sessions-web.js | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/scripts/code-sessions-web.js b/scripts/code-sessions-web.js index e776faf7d9c..79409d9be66 100644 --- a/scripts/code-sessions-web.js +++ b/scripts/code-sessions-web.js @@ -32,14 +32,17 @@ async function main() { const HOST = args['host'] ?? 'localhost'; const PORT = parseInt(args['port'] ?? '8081', 10); - // Read CSS modules list for dev mode (same as code-web does) + // Collect CSS module paths from the compiled output (same as @vscode/test-web does). + // These are turned into an import map so the browser can load `import './foo.css'` + // statements as JavaScript shims that inject the CSS via `_VSCODE_CSS_LOAD`. let cssModules = []; try { - const cssModulesPath = path.join(APP_ROOT, '.build', 'cssDevModules.json'); - if (fs.existsSync(cssModulesPath)) { - cssModules = JSON.parse(fs.readFileSync(cssModulesPath, 'utf-8')); - } - } catch { /* ignore */ } + const { glob } = require('tinyglobby'); + cssModules = await glob('**/*.css', { cwd: path.join(APP_ROOT, 'out') }); + } catch { + // tinyglobby may not be installed; fall back to a recursive fs walk + cssModules = collectCssFiles(path.join(APP_ROOT, 'out'), ''); + } const server = http.createServer((req, res) => { const url = new URL(req.url, `http://${HOST}:${PORT}`); @@ -139,5 +142,19 @@ function getSessionsHTML(host, port, cssModules) { `; } +/** Recursively collect *.css paths relative to `dir`. */ +function collectCssFiles(dir, prefix) { + let results = []; + for (const entry of fs.readdirSync(dir, { withFileTypes: true })) { + const rel = prefix ? prefix + '/' + entry.name : entry.name; + if (entry.isDirectory()) { + results = results.concat(collectCssFiles(path.join(dir, entry.name), rel)); + } else if (entry.name.endsWith('.css')) { + results.push(rel); + } + } + return results; +} + main();