Skip to content

Commit

Permalink
complete
Browse files Browse the repository at this point in the history
  • Loading branch information
aeschli committed Sep 4, 2024
1 parent 6d6c02a commit bcc4d0d
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 76 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/out/index.js",
"program": "${workspaceFolder}/out/server/index.js",
"args": [
"--browserType=chromium",
"--extensionDevelopmentPath=${workspaceFolder}/sample",
Expand All @@ -58,7 +58,7 @@
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/out/index.js",
"program": "${workspaceFolder}/out/server/index.js",
"args": [
"--browserType=chromium",
"--extensionDevelopmentPath=${workspaceFolder}/sample",
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"version": "0.0.57",
"scripts": {
"install-extensions": "npm i --prefix=fs-provider && npm i --prefix=sample",
"compile": "tsc -p ./ && npm run compile-fs-provider",
"watch": "tsc -w -p ./",
"compile": "tsc -b ./ && npm run compile-fs-provider",
"watch": "tsc -b -w ./",
"prepack": "npm run compile",
"test": "eslint src && tsc --noEmit",
"preversion": "npm test",
Expand All @@ -15,9 +15,9 @@
"sample-tests": "npm run compile && npm run compile-sample && node . --extensionDevelopmentPath=sample --extensionTestsPath=sample/dist/web/test/suite/index.js --headless=true sample/test-workspace",
"empty": "npm run compile && node ."
},
"main": "./out/index.js",
"main": "./out/server/index.js",
"bin": {
"vscode-test-web": "./out/index.js"
"vscode-test-web": "./out/server/index.js"
},
"engines": {
"node": ">=16"
Expand Down
3 changes: 2 additions & 1 deletion src/browser/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
///<amd-module name='vscode-browser-main'/>

import { create, IWorkspaceProvider, IWorkbenchConstructionOptions, UriComponents, IWorkspace, URI, IURLCallbackProvider, Emitter, IDisposable} from "./workbench.api";
import { create, IWorkspaceProvider, IWorkbenchConstructionOptions, UriComponents, IWorkspace, URI, IURLCallbackProvider, Emitter, IDisposable} from './workbench.api';

class WorkspaceProvider implements IWorkspaceProvider {

Expand Down
22 changes: 22 additions & 0 deletions src/browser/tsconfig-amd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "AMD",
"lib": [
"ES2022",
"DOM",
],
"outDir": "../../out/browser/amd",
"declaration": true,
"strict": true,
"noImplicitAny": false,
"noImplicitThis": true,
"noUnusedLocals": true,
"alwaysStrict": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"sourceMap": false,
"newLine": "lf",
"removeComments": true
}
}
22 changes: 22 additions & 0 deletions src/browser/tsconfig-esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "ES2022",
"lib": [
"ES2022",
"DOM",
],
"outDir": "../../out/browser/esm",
"declaration": true,
"strict": true,
"noImplicitAny": false,
"noImplicitThis": true,
"noUnusedLocals": true,
"alwaysStrict": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"sourceMap": false,
"newLine": "lf",
"removeComments": true
}
}
7 changes: 6 additions & 1 deletion src/server/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export async function downloadAndUnzipVSCode(vscodeTestDir: string, quality: 'st
}

if (existsSync(vscodeTestDir)) {
await fs.rmdir(vscodeTestDir, { recursive: true, maxRetries: 5 });
await fs.rm(vscodeTestDir, { recursive: true, maxRetries: 5 });
}

await fs.mkdir(vscodeTestDir, { recursive: true });
Expand Down Expand Up @@ -196,3 +196,8 @@ export async function fileExists(path: string): Promise<boolean> {
return false;
}
}

export async function readFileInRepo(pathInRepo: string): Promise<string> {
return (await fs.readFile(path.resolve(__dirname, '../..', pathInRepo))).toString()
}

6 changes: 3 additions & 3 deletions src/index.ts → src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { IConfig, runServer, Static, Sources } from './server/main';
import { downloadAndUnzipVSCode, directoryExists, fileExists } from './server/download';
import { IConfig, runServer, Static, Sources } from './main';
import { downloadAndUnzipVSCode, directoryExists, fileExists, readFileInRepo } from './download';

import * as playwright from 'playwright';
import * as minimist from 'minimist';
Expand Down Expand Up @@ -609,7 +609,7 @@ async function cliMain(): Promise<void> {

/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/no-require-imports */
const manifest = require('../package.json');
const manifest = JSON.parse(await readFileInRepo('package.json'));
console.log(`${manifest.name}: ${manifest.version}`);

const options: minimist.Opts = {
Expand Down
7 changes: 3 additions & 4 deletions src/browser/tsconfig.json → src/server/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "ES2022",
"module": "commonjs",
"lib": [
"ES2022",
"DOM",
"ES2022"
],
"outDir": "../../out/browser",
"outDir": "../../out/server",
"declaration": true,
"strict": true,
"noImplicitAny": false,
Expand Down
83 changes: 49 additions & 34 deletions src/server/workbench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as Router from '@koa/router';
import { GalleryExtensionInfo, IConfig } from './main';
import { getScannedBuiltinExtensions, IScannedBuiltinExtension, scanForExtensions, URIComponents } from './extensions';
import { fsProviderExtensionPrefix, fsProviderFolderUri } from './mounts';
import { readFileInRepo } from './download';

interface IDevelopmentOptions {
extensionTestsPath?: URIComponents;
Expand Down Expand Up @@ -43,55 +44,69 @@ class Workbench {
WORKBENCH_AUTH_SESSION: '',
WORKBENCH_WEB_BASE_URL: this.baseUrl,
WORKBENCH_BUILTIN_EXTENSIONS: asJSON(this.builtInExtensions),
WORKBENCH_MAIN: this.getMain()
WORKBENCH_MAIN: await this.getMain()
};

try {
const workbenchTemplate = (await fs.readFile(path.resolve(__dirname, `../../views/workbench${this.esm ? '-esm' : ''}.html`))).toString();
const workbenchTemplate = await readFileInRepo(`views/workbench${this.esm ? '-esm' : ''}.html`);
return workbenchTemplate.replace(/\{\{([^}]+)\}\}/g, (_, key) => values[key] ?? 'undefined');
} catch (e) {
return String(e);
}
}

getMain() {
async getMain() {
const lines: string[] = [];
if (this.esm) {
const lines = this.devCSSModules.length > 0 ? [
"<script>",
`globalThis._VSCODE_CSS_MODULES = ${JSON.stringify(this.devCSSModules)};`,
"</script>",
"<script>",
"const sheet = document.getElementById('vscode-css-modules').sheet;",
"globalThis._VSCODE_CSS_LOAD = function (url) { sheet.insertRule(`@import url(${url});`); };",
"",
"const importMap = { imports: {} };",
"for (const cssModule of globalThis._VSCODE_CSS_MODULES) {",
" const cssUrl = new URL(cssModule, globalThis._VSCODE_FILE_ROOT).href;",
" const jsSrc = `globalThis._VSCODE_CSS_LOAD('${cssUrl}');\\n`;",
" const blob = new Blob([jsSrc], { type: 'application/javascript' });",
" importMap.imports[cssUrl] = URL.createObjectURL(blob);",
"}",
"const importMapElement = document.createElement('script');",
"importMapElement.type = 'importmap';",
"importMapElement.setAttribute('nonce', '1nline-m4p');",
"importMapElement.textContent = JSON.stringify(importMap, undefined, 2);",
"document.head.appendChild(importMapElement);",
"</script>"
] : [];
lines.push(`<script type="module" src="${this.baseUrl}/out/vs/code/browser/workbench/workbench.js"></script>`);
let workbenchMain = await readFileInRepo(`out/browser/esm/main.js`);
if (this.dev) {
lines.push(
"<script>",
`globalThis._VSCODE_CSS_MODULES = ${JSON.stringify(this.devCSSModules)};`,
"</script>",
"<script>",
"const sheet = document.getElementById('vscode-css-modules').sheet;",
"globalThis._VSCODE_CSS_LOAD = function (url) { sheet.insertRule(`@import url(${url});`); };",
"",
"const importMap = { imports: {} };",
"for (const cssModule of globalThis._VSCODE_CSS_MODULES) {",
" const cssUrl = new URL(cssModule, globalThis._VSCODE_FILE_ROOT).href;",
" const jsSrc = `globalThis._VSCODE_CSS_LOAD('${cssUrl}');\\n`;",
" const blob = new Blob([jsSrc], { type: 'application/javascript' });",
" importMap.imports[cssUrl] = URL.createObjectURL(blob);",
"}",
"const importMapElement = document.createElement('script');",
"importMapElement.type = 'importmap';",
"importMapElement.setAttribute('nonce', '1nline-m4p');",
"importMapElement.textContent = JSON.stringify(importMap, undefined, 2);",
"document.head.appendChild(importMapElement);",
"</script>");
workbenchMain = workbenchMain.replace('./workbench.api', `${this.baseUrl}/out/vs/workbench/workbench.web.main.js`);
lines.push(`<script type="module">${workbenchMain}</script>`);
} else {
workbenchMain = workbenchMain.replace('./workbench.api', `${this.baseUrl}/out/vs/workbench/workbench.web.main.internal.js`);
lines.push(`<script src="${this.baseUrl}/out/nls.messages.js"></script>`);
lines.push(`<script type="module">${workbenchMain}</script>`);
}
return lines.join('\n');
} else {
let workbenchMain = await readFileInRepo(`out/browser/amd/main.js`); // defines a AMD module `vscode-browser-main`
workbenchMain = workbenchMain.replace('./workbench.api', `vs/workbench/workbench.web.main`);
workbenchMain = workbenchMain + '\nrequire(["vscode-browser-main"], function() { });';
if (this.dev) {

} else {
lines.push(`<script src="${this.baseUrl}/out/nls.messages.js"></script>`);
lines.push(`<script src="${this.baseUrl}/out/vs/workbench/workbench.web.main.nls.js"></script>`);
lines.push(`<script src="${this.baseUrl}/out/vs/workbench/workbench.web.main.js"></script>`);
}
lines.push(`<script>${workbenchMain}</script>`);
}
if (this.dev) {
return `<script> require(['vs/code/browser/workbench/workbench'], function() {}); </script>`;
}
return `<script src="${this.baseUrl}/out/nls.messages.js"></script>`
+ `<script src="${this.baseUrl}/out/vs/workbench/workbench.web.main.nls.js"></script>`
+ `<script src="${this.baseUrl}/out/vs/workbench/workbench.web.main.js"></script>`
+ `<script src="${this.baseUrl}/out/vs/code/browser/workbench/workbench.js"></script>`;
return lines.join('\n');
}

async renderCallback(): Promise<string> {
return (await fs.readFile(path.resolve(__dirname, `../../views/callback.html`))).toString();
return await readFileInRepo(`views/callback.html`);
}
}

Expand Down
40 changes: 16 additions & 24 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"lib": [
"ES2020"
],
"outDir": "out",
"declaration": true,
"strict": true,
"noImplicitAny": false,
"noImplicitThis": true,
"noUnusedLocals": true,
"alwaysStrict": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"sourceMap": false,
"newLine": "lf"
},
"include": [
"src"
],
"exclude": [
"node_modules"
]
"compilerOptions": {
"incremental": true,
"composite": true
},
"files": [],
"references": [
{
"path": "./src/server/tsconfig.json"
},
{
"path": "./src/browser/tsconfig-esm.json"
},
{
"path": "./src/browser/tsconfig-amd.json"
}
]
}
1 change: 1 addition & 0 deletions views/workbench-esm.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<link rel="icon" href="{{WORKBENCH_WEB_BASE_URL}}/favicon.ico" type="image/x-icon" />
<link rel="manifest" href="{{WORKBENCH_WEB_BASE_URL}}/manifest.json">

<link data-name="vs/workbench/workbench.web.main" rel="stylesheet" href="{{WORKBENCH_WEB_BASE_URL}}/out/vs/workbench/workbench.web.main.css" />
<style id="vscode-css-modules" type="text/css" media="screen"></style>
</head>

Expand Down
10 changes: 7 additions & 3 deletions views/workbench.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@
<script src="{{WORKBENCH_WEB_BASE_URL}}/out/vs/webPackagePaths.js"></script>
<script>
let baseUrl = '{{WORKBENCH_WEB_BASE_URL}}';
Object.keys(self.webPackagePaths).map(function (key, index) {
self.webPackagePaths[key] = `${baseUrl}/node_modules/${key}/${self.webPackagePaths[key]}`;
});
if (!self.webPackagePaths) {
self.webPackagePaths = {};
} else {
Object.keys(self.webPackagePaths).forEach(function (key, index) {
self.webPackagePaths[key] = `${baseUrl}/node_modules/${key}/${self.webPackagePaths[key]}`;
});
}
require.config({
baseUrl: `${baseUrl}/out`,
recordStats: true,
Expand Down

0 comments on commit bcc4d0d

Please sign in to comment.