GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — vscode/scripts/code-sessions-web.js at main · microsoft/vscode Expand file tree/ Copy pathcode-sessions-web.jsMore file actions executable file ·183 lines (162 loc) · 6.63 KB / Copy pathcode-sessions-web.jsFile metadata and controlsexecutable file ·183 lines (162 loc) · 6.63 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ // @ts-check const http = require('http'); const fs = require('fs'); const path = require('path'); const open = require('open'); const minimist = require('minimist'); const APP_ROOT = path.join(__dirname, '..'); async function main() { const args = minimist(process.argv.slice(2), { boolean: ['help', 'no-open', 'skip-welcome', 'mock', 'mobile'], string: ['host', 'port'], }); if (args.help) { console.log( './scripts/code-sessions-web.sh [options]\n' + ' --host <host> Host to bind to (default: localhost)\n' + ' --port <port> Port to bind to (default: 8081)\n' + ' --no-open Do not open browser automatically\n' + ' --skip-welcome Skip the sessions welcome overlay\n' + ' --mock Load mock extension for E2E testing\n' + ' --mobile Serve the mobile (phone) workbench entry point\n' ); return; } const HOST = args['host'] ?? 'localhost'; const PORT = parseInt(args['port'] ?? '8081', 10); const server = http.createServer((req, res) => { const url = new URL(req.url, `http://${HOST}:${PORT}`); // Serve the sessions workbench HTML at the root if (url.pathname === '/' || url.pathname === '/index.html') { // Refresh the import map on each page load to include newly compiled stylesheets. const cssModules = collectCssFiles(path.join(APP_ROOT, 'out'), ''); res.writeHead(200, { 'Content-Type': 'text/html' }); res.end(getSessionsHTML(HOST, PORT, cssModules, args['mock'], args['mobile'])); return; } // Serve static files from the repo root (out/, src/, node_modules/, etc.) const filePath = path.join(APP_ROOT, url.pathname); if (fs.existsSync(filePath) && fs.statSync(filePath).isFile()) { const ext = path.extname(filePath); const contentType = { '.js': 'application/javascript', '.mjs': 'application/javascript', '.css': 'text/css', '.html': 'text/html', '.json': 'application/json', '.svg': 'image/svg+xml', '.png': 'image/png', '.ttf': 'font/ttf', '.woff': 'font/woff', '.woff2': 'font/woff2', }[ext] || 'application/octet-stream'; res.writeHead(200, { 'Content-Type': contentType, 'Access-Control-Allow-Origin': '*', }); fs.createReadStream(filePath).pipe(res); return; } res.writeHead(404); res.end('Not found'); }); server.listen(PORT, HOST, () => { console.log(`\n Sessions Web${args['mobile'] ? ' (mobile)' : ''} running at: http://${HOST}:${PORT}/\n`); if (!args['no-open'] && args.open !== false) { const query = args['skip-welcome'] ? '?skip-sessions-welcome' : ''; open.default(`http://${HOST}:${PORT}/${query}`); } }); process.on('SIGINT', () => { server.close(); process.exit(0); }); process.on('SIGTERM', () => { server.close(); process.exit(0); }); } function getSessionsHTML(host, port, cssModules, useMock, useMobile) { const baseUrl = `http://${host}:${port}`; const fileRoot = `${baseUrl}/out`; // Build the import map server-side. Each CSS file gets mapped to a // data: URI containing a JS module that injects the stylesheet via // a global helper function. This must be a static <script type="importmap"> // declared before any <script type="module"> tags. const imports = {}; for (const cssModule of cssModules) { const cssUrl = `${fileRoot}/${cssModule}`; const jsSrc = `globalThis._VSCODE_CSS_LOAD('${cssUrl}');\n`; const encoded = Buffer.from(jsSrc).toString('base64'); imports[cssUrl] = `data:application/javascript;base64,${encoded}`; } const importMapJson = JSON.stringify({ imports }, null, 2); // When --mock is passed, load the E2E mock extension const additionalBuiltinExtensions = useMock ? `additionalBuiltinExtensions: [{ scheme: 'http', authority: '${host}:${port}', path: '/src/vs/sessions/test/e2e/extensions/sessions-e2e-mock' }],` : ''; // The mobile entry point is a separate, allow-listed bundle with its own // workbench. The mock variant swaps in the same mock services as desktop. const entryModule = useMobile ? (useMock ? 'test/agents.web.mobile.test.internal' : 'agents.web.mobile.main.internal') : (useMock ? 'test/sessions.web.test.internal' : 'sessions.web.main.internal'); // Expose safe-area insets without disabling browser zoom. const viewportMeta = useMobile ? `<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" /> <meta name="apple-mobile-web-app-capable" content="yes" /> <meta name="mobile-web-app-capable" content="yes" /> <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />` : `<meta name="viewport" content="width=device-width, initial-scale=1" />`; return `<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> ${viewportMeta} <title>${useMobile ? 'Agents' : 'Sessions'}</title> <style id="vscode-css-modules"></style> <script> globalThis._VSCODE_FILE_ROOT = '${fileRoot}'; const sheet = document.getElementById('vscode-css-modules').sheet; // Append so the cascade follows load order (later stylesheet wins), matching // the bundled build and the Electron dev loader. The default index prepends // and inverts precedence, which makes dev styling diverge from production. globalThis._VSCODE_CSS_LOAD = function (url) { sheet.insertRule(\`@import url(\${url});\`, sheet.cssRules.length); }; </script> <script type="importmap"> ${importMapJson} </script> </head> <body aria-label=""> <script type="module"> import { create, URI } from '${fileRoot}/vs/sessions/${entryModule}.js'; create(document.body, { productConfiguration: { nameShort: '${useMobile ? 'Agents' : 'Sessions (Web)'}', nameLong: '${useMobile ? 'Agents' : 'Sessions (Web)'}', enableTelemetry: false, }, ${additionalBuiltinExtensions} workspaceProvider: { workspace: ${useMock ? `{ folderUri: URI.parse('mock-fs://mock-repo/mock-repo') }` : 'undefined'}, open: async () => false, payload: [['isSessionsWindow', 'true']], }, }); </script> </body> </html>`; } /** 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(); |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |