mirror of
https://github.com/Microsoft/vscode
synced 2024-10-01 08:50:48 +00:00
Depend on platform implementations for common features (#165950)
* don't depend on externals * remove unneeded externals
This commit is contained in:
parent
1784a7ed34
commit
b9b93f2b45
|
@ -16,14 +16,12 @@ module.exports = withBrowserDefaults({
|
|||
entry: {
|
||||
extension: './src/extension.ts',
|
||||
},
|
||||
externals: {
|
||||
'keytar': 'commonjs keytar',
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
'node-fetch': path.resolve(__dirname, 'node_modules/node-fetch/browser.js'),
|
||||
'uuid': path.resolve(__dirname, 'node_modules/uuid/dist/esm-browser/index.js'),
|
||||
'./authServer': path.resolve(__dirname, 'src/env/browser/authServer'),
|
||||
'./node/authServer': path.resolve(__dirname, 'src/browser/authServer'),
|
||||
'./node/crypto': path.resolve(__dirname, 'src/browser/crypto'),
|
||||
'./node/fetch': path.resolve(__dirname, 'src/browser/fetch')
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -13,8 +13,5 @@ module.exports = withDefaults({
|
|||
context: __dirname,
|
||||
entry: {
|
||||
extension: './src/extension.ts',
|
||||
},
|
||||
externals: {
|
||||
'keytar': 'commonjs keytar'
|
||||
}
|
||||
});
|
||||
|
|
|
@ -66,14 +66,12 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"node-fetch": "2.6.7",
|
||||
"uuid": "8.1.0",
|
||||
"@vscode/extension-telemetry": "0.7.0-preview",
|
||||
"vscode-tas-client": "^0.1.47"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "16.x",
|
||||
"@types/node-fetch": "^2.5.7",
|
||||
"@types/uuid": "8.0.0"
|
||||
"@types/node-fetch": "^2.5.7"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
|
6
extensions/github-authentication/src/browser/crypto.ts
Normal file
6
extensions/github-authentication/src/browser/crypto.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
export const crypto = globalThis.crypto;
|
6
extensions/github-authentication/src/browser/fetch.ts
Normal file
6
extensions/github-authentication/src/browser/fetch.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
export const fetching = fetch;
|
|
@ -4,13 +4,13 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import TelemetryReporter from '@vscode/extension-telemetry';
|
||||
import { Keychain } from './common/keychain';
|
||||
import { GitHubServer, IGitHubServer } from './githubServer';
|
||||
import { arrayEquals } from './common/utils';
|
||||
import { ExperimentationTelemetry } from './experimentationService';
|
||||
import TelemetryReporter from '@vscode/extension-telemetry';
|
||||
import { ExperimentationTelemetry } from './common/experimentationService';
|
||||
import { Log } from './common/logger';
|
||||
import { crypto } from './node/crypto';
|
||||
|
||||
interface SessionData {
|
||||
id: string;
|
||||
|
@ -286,7 +286,7 @@ export class GitHubAuthenticationProvider implements vscode.AuthenticationProvid
|
|||
private async tokenToSession(token: string, scopes: string[]): Promise<vscode.AuthenticationSession> {
|
||||
const userInfo = await this._githubServer.getUserInfo(token);
|
||||
return {
|
||||
id: uuid(),
|
||||
id: crypto.getRandomValues(new Uint32Array(2)).reduce((prev, curr) => prev += curr.toString(16), ''),
|
||||
accessToken: token,
|
||||
account: { label: userInfo.accountName, id: userInfo.id },
|
||||
scopes
|
||||
|
|
|
@ -4,15 +4,15 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import fetch, { Response } from 'node-fetch';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import * as path from 'path';
|
||||
import { PromiseAdapter, promiseFromEvent } from './common/utils';
|
||||
import { ExperimentationTelemetry } from './experimentationService';
|
||||
import { ExperimentationTelemetry } from './common/experimentationService';
|
||||
import { AuthProviderType, UriEventHandler } from './github';
|
||||
import { Log } from './common/logger';
|
||||
import { isSupportedEnvironment } from './common/env';
|
||||
import { LoopbackAuthServer } from './authServer';
|
||||
import path = require('path');
|
||||
import { LoopbackAuthServer } from './node/authServer';
|
||||
import { crypto } from './node/crypto';
|
||||
import { fetching } from './node/fetch';
|
||||
|
||||
const CLIENT_ID = '01ab8ac9400c4e429b23';
|
||||
const GITHUB_TOKEN_URL = 'https://vscode.dev/codeExchangeProxyEndpoints/github/login/oauth/access_token';
|
||||
|
@ -38,7 +38,7 @@ interface IGitHubDeviceCodeResponse {
|
|||
async function getScopes(token: string, serverUri: vscode.Uri, logger: Log): Promise<string[]> {
|
||||
try {
|
||||
logger.info('Getting token scopes...');
|
||||
const result = await fetch(serverUri.toString(), {
|
||||
const result = await fetching(serverUri.toString(), {
|
||||
headers: {
|
||||
Authorization: `token ${token}`,
|
||||
'User-Agent': 'Visual-Studio-Code'
|
||||
|
@ -99,7 +99,7 @@ export class GitHubServer implements IGitHubServer {
|
|||
return this._redirectEndpoint;
|
||||
} else {
|
||||
// GHES
|
||||
const result = await fetch(this.getServerUri('/meta').toString(true));
|
||||
const result = await fetching(this.getServerUri('/meta').toString(true));
|
||||
if (result.ok) {
|
||||
try {
|
||||
const json: { installed_version: string } = await result.json();
|
||||
|
@ -151,7 +151,7 @@ export class GitHubServer implements IGitHubServer {
|
|||
}
|
||||
};
|
||||
|
||||
const nonce = uuid();
|
||||
const nonce: string = crypto.getRandomValues(new Uint32Array(2)).reduce((prev, curr) => prev += curr.toString(16), '');
|
||||
const callbackUri = await vscode.env.asExternalUri(vscode.Uri.parse(`${vscode.env.uriScheme}://vscode.github-authentication/did-authenticate?nonce=${encodeURIComponent(nonce)}`));
|
||||
|
||||
const supported = isSupportedEnvironment(callbackUri);
|
||||
|
@ -298,7 +298,7 @@ export class GitHubServer implements IGitHubServer {
|
|||
path: '/login/device/code',
|
||||
query: `client_id=${CLIENT_ID}&scope=${scopes}`
|
||||
});
|
||||
const result = await fetch(uri.toString(true), {
|
||||
const result = await fetching(uri.toString(true), {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Accept: 'application/json'
|
||||
|
@ -382,7 +382,7 @@ export class GitHubServer implements IGitHubServer {
|
|||
}
|
||||
let accessTokenResult;
|
||||
try {
|
||||
accessTokenResult = await fetch(refreshTokenUri.toString(true), {
|
||||
accessTokenResult = await fetching(refreshTokenUri.toString(true), {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Accept: 'application/json'
|
||||
|
@ -452,7 +452,7 @@ export class GitHubServer implements IGitHubServer {
|
|||
body.append('github_enterprise', this.baseUri.toString(true));
|
||||
body.append('redirect_uri', await this.getRedirectEndpoint());
|
||||
}
|
||||
const result = await fetch(endpointUrl, {
|
||||
const result = await fetching(endpointUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
|
@ -485,10 +485,10 @@ export class GitHubServer implements IGitHubServer {
|
|||
}
|
||||
|
||||
public async getUserInfo(token: string): Promise<{ id: string; accountName: string }> {
|
||||
let result: Response;
|
||||
let result;
|
||||
try {
|
||||
this._logger.info('Getting user info...');
|
||||
result = await fetch(this.getServerUri('/user').toString(), {
|
||||
result = await fetching(this.getServerUri('/user').toString(), {
|
||||
headers: {
|
||||
Authorization: `token ${token}`,
|
||||
'User-Agent': 'Visual-Studio-Code'
|
||||
|
@ -544,7 +544,7 @@ export class GitHubServer implements IGitHubServer {
|
|||
|
||||
private async checkEduDetails(token: string): Promise<void> {
|
||||
try {
|
||||
const result = await fetch('https://education.github.com/api/user', {
|
||||
const result = await fetching('https://education.github.com/api/user', {
|
||||
headers: {
|
||||
Authorization: `token ${token}`,
|
||||
'faculty-check-preview': 'true',
|
||||
|
@ -577,7 +577,7 @@ export class GitHubServer implements IGitHubServer {
|
|||
private async checkEnterpriseVersion(token: string): Promise<void> {
|
||||
try {
|
||||
|
||||
const result = await fetch(this.getServerUri('/meta').toString(), {
|
||||
const result = await fetching(this.getServerUri('/meta').toString(), {
|
||||
headers: {
|
||||
Authorization: `token ${token}`,
|
||||
'User-Agent': 'Visual-Studio-Code'
|
||||
|
|
8
extensions/github-authentication/src/node/crypto.ts
Normal file
8
extensions/github-authentication/src/node/crypto.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { webcrypto } from 'crypto';
|
||||
|
||||
export const crypto = webcrypto as any as Crypto;
|
7
extensions/github-authentication/src/node/fetch.ts
Normal file
7
extensions/github-authentication/src/node/fetch.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
export const fetching = fetch;
|
|
@ -232,11 +232,6 @@
|
|||
dependencies:
|
||||
"@types/node" "*"
|
||||
|
||||
"@types/uuid@8.0.0":
|
||||
version "8.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-8.0.0.tgz#165aae4819ad2174a17476dbe66feebd549556c0"
|
||||
integrity sha512-xSQfNcvOiE5f9dyd4Kzxbof1aTrLobL278pGLKOZI6esGfZ7ts9Ka16CzIN6Y8hFHE1C7jIBZokULhK1bOgjRw==
|
||||
|
||||
"@vscode/extension-telemetry@0.7.0-preview":
|
||||
version "0.7.0-preview"
|
||||
resolved "https://registry.yarnpkg.com/@vscode/extension-telemetry/-/extension-telemetry-0.7.0-preview.tgz#2ff53a2b0d7f698724d610803cac9c4fb0058f90"
|
||||
|
@ -470,11 +465,6 @@ url-parse@^1.5.3:
|
|||
querystringify "^2.1.1"
|
||||
requires-port "^1.0.0"
|
||||
|
||||
uuid@8.1.0:
|
||||
version "8.1.0"
|
||||
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.1.0.tgz#6f1536eb43249f473abc6bd58ff983da1ca30d8d"
|
||||
integrity sha512-CI18flHDznR0lq54xBycOVmphdCYnQLKn8abKn7PXUiKUGdEd+/l9LWNJmugXel4hXq7S+RMNl34ecyC9TntWg==
|
||||
|
||||
uuid@^8.3.0:
|
||||
version "8.3.2"
|
||||
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
|
||||
|
|
Loading…
Reference in a new issue