Skip to content

Commit

Permalink
cleanup & prepare 0.0.58
Browse files Browse the repository at this point in the history
  • Loading branch information
aeschli committed Sep 4, 2024
1 parent ed9ff7a commit c47dadc
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 90 deletions.
94 changes: 47 additions & 47 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vscode/test-web",
"version": "0.0.57",
"version": "0.0.58",
"scripts": {
"install-extensions": "npm i --prefix=fs-provider && npm i --prefix=sample",
"compile": "tsc -b ./ && npm run compile-fs-provider",
Expand Down Expand Up @@ -51,8 +51,8 @@
"@types/minimist": "^1.2.5",
"@types/node": "^20.14.9",
"@types/tar-fs": "^2.0.4",
"@typescript-eslint/eslint-plugin": "^8.3.0",
"@typescript-eslint/parser": "^8.3.0",
"@typescript-eslint/eslint-plugin": "^8.4.0",
"@typescript-eslint/parser": "^8.4.0",
"eslint": "^9.9.1",
"@tony.ganchev/eslint-plugin-header": "^3.1.2",
"typescript": "^5.5.4"
Expand Down
12 changes: 6 additions & 6 deletions src/browser/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,20 @@ class WorkspaceProvider implements IWorkspaceProvider {
}

if ('folderUri' in workspaceA && 'folderUri' in workspaceB) {
return isEqual(workspaceA.folderUri, workspaceB.folderUri); // same workspace
return this.isEqualURI(workspaceA.folderUri, workspaceB.folderUri); // same workspace
}

if ('workspaceUri' in workspaceA && 'workspaceUri' in workspaceB) {
return isEqual(workspaceA.workspaceUri, workspaceB.workspaceUri); // same workspace
return this.isEqualURI(workspaceA.workspaceUri, workspaceB.workspaceUri); // same workspace
}

return false;
}

private isEqualURI(a: UriComponents, b: UriComponents): boolean {
return a.scheme === b.scheme && a.authority === b.authority && a.path === b.path;
}

}

class LocalStorageURLCallbackProvider implements IURLCallbackProvider, IDisposable {
Expand Down Expand Up @@ -251,10 +255,6 @@ class LocalStorageURLCallbackProvider implements IURLCallbackProvider, IDisposab
}
}

function isEqual(a: UriComponents, b: UriComponents): boolean {
return a.scheme === b.scheme && a.authority === b.authority && a.path === b.path;
}

(function () {
const configElement = window.document.getElementById('vscode-workbench-web-configuration');
const configElementAttribute = configElement ? configElement.getAttribute('data-settings') : undefined;
Expand Down
61 changes: 34 additions & 27 deletions src/server/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,25 @@ interface DownloadInfo {
version: string;
}

async function getDownloadInfo(quality: 'stable' | 'insider', commit: string | undefined): Promise<DownloadInfo> {
if (commit) {
const url = await getRedirect(`https://update.code.visualstudio.com/commit:${commit}/web-standalone/${quality}`);
if (!url) {
throw new Error('Failed to download URL for commit ' + commit + '. Is it valid?');
}
return { url, version: commit };
}
async function getLatestBuild(quality: 'stable' | 'insider'): Promise<DownloadInfo> {
return await fetchJSON(`https://update.code.visualstudio.com/api/update/web-standalone/${quality}/latest`);
}

export async function getDownloadURL(quality: 'stable' | 'insider', commit: string): Promise<string | undefined> {
return new Promise((resolve, reject) => {
const url = `https://update.code.visualstudio.com/commit:${commit}/web-standalone/${quality}`;
const httpLibrary = url.startsWith('https') ? https : http;
httpLibrary.get(url, { method: 'HEAD', ...getAgent(url) }, res => {
console.log(res.statusCode, res.headers.location);
if ((res.statusCode === 301 || res.statusCode === 302 || res.statusCode === 307) && res.headers.location) {
resolve(res.headers.location);
} else {
resolve(undefined);
}
});
});
}

const reset = '\x1b[G\x1b[0K';

async function downloadAndUntar(downloadUrl: string, destination: string, message: string): Promise<void> {
Expand Down Expand Up @@ -80,13 +88,24 @@ async function downloadAndUntar(downloadUrl: string, destination: string, messag


export async function downloadAndUnzipVSCode(vscodeTestDir: string, quality: 'stable' | 'insider', commit: string | undefined): Promise<Static> {
const info = await getDownloadInfo(quality, commit);

const folderName = `vscode-web-${quality}-${info.version}`;
let downloadURL: string | undefined;
if (!commit) {
const info = await getLatestBuild(quality);
commit = info.version;
downloadURL = info.url;
}

const folderName = `vscode-web-${quality}-${commit}`;
const downloadedPath = path.resolve(vscodeTestDir, folderName);
if (existsSync(downloadedPath) && existsSync(path.join(downloadedPath, 'version'))) {
return { type: 'static', location: downloadedPath, quality, version: info.version };
return { type: 'static', location: downloadedPath, quality, version: commit };
}

if (!downloadURL) {
downloadURL = await getDownloadURL(quality, commit);
if (!downloadURL) {
throw Error(`Failed to find a download for ${quality} and ${commit}`);
}
}

if (existsSync(vscodeTestDir)) {
Expand All @@ -98,13 +117,13 @@ export async function downloadAndUnzipVSCode(vscodeTestDir: string, quality: 'st
const productName = `VS Code ${quality === 'stable' ? 'Stable' : 'Insiders'}`;

try {
await downloadAndUntar(info.url, downloadedPath, `Downloading ${productName}`);
await downloadAndUntar(downloadURL, downloadedPath, `Downloading ${productName}`);
await fs.writeFile(path.join(downloadedPath, 'version'), folderName);
} catch (err) {
console.error(err);
throw Error(`Failed to download and unpack ${productName}.${commit ? ' Did you specify a valid commit?' : ''}`);
}
return { type: 'static', location: downloadedPath, quality, version: info.version };
return { type: 'static', location: downloadedPath, quality, version: commit };
}

export async function fetch(api: string): Promise<string> {
Expand All @@ -131,19 +150,7 @@ export async function fetch(api: string): Promise<string> {
});
});
}
export async function getRedirect(api: string): Promise<string | undefined> {
return new Promise((resolve, reject) => {
const httpLibrary = api.startsWith('https') ? https : http;
httpLibrary.get(api, { method: 'HEAD', ...getAgent(api) }, res => {
console.log(res.statusCode, res.headers.location);
if (res.statusCode === 301 || res.statusCode === 302 || res.statusCode === 307) {
resolve(res.headers.location);
} else {
resolve(undefined);
}
});
});
}


export async function fetchJSON<T>(api: string): Promise<T> {
const data = await fetch(api);
Expand Down
1 change: 0 additions & 1 deletion src/server/workbench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class Workbench {
}
const values: { [key: string]: string } = {
WORKBENCH_WEB_CONFIGURATION: asJSON(workbenchWebConfiguration),
WORKBENCH_AUTH_SESSION: '',
WORKBENCH_WEB_BASE_URL: this.baseUrl,
WORKBENCH_BUILTIN_EXTENSIONS: asJSON(this.builtInExtensions),
WORKBENCH_MAIN: await this.getMain()
Expand Down
3 changes: 0 additions & 3 deletions views/workbench-esm.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
<!-- Workbench Configuration -->
<meta id="vscode-workbench-web-configuration" data-settings="{{WORKBENCH_WEB_CONFIGURATION}}">

<!-- Workbench Auth Session -->
<meta id="vscode-workbench-auth-session" data-settings="{{WORKBENCH_AUTH_SESSION}}">

<!-- Builtin Extensions (running out of sources) -->
<meta id="vscode-workbench-builtin-extensions" data-settings="{{WORKBENCH_BUILTIN_EXTENSIONS}}">

Expand Down
3 changes: 0 additions & 3 deletions views/workbench.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
<!-- Workbench Configuration -->
<meta id="vscode-workbench-web-configuration" data-settings="{{WORKBENCH_WEB_CONFIGURATION}}">

<!-- Workbench Auth Session -->
<meta id="vscode-workbench-auth-session" data-settings="{{WORKBENCH_AUTH_SESSION}}">

<!-- Builtin Extensions (running out of sources) -->
<meta id="vscode-workbench-builtin-extensions" data-settings="{{WORKBENCH_BUILTIN_EXTENSIONS}}">

Expand Down

0 comments on commit c47dadc

Please sign in to comment.