Skip to content

Commit

Permalink
Rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
msujew committed Feb 20, 2024
1 parent c7f2685 commit 7313a81
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 79 deletions.
2 changes: 2 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@types/react-dom": "^18.0.6",
"@types/route-parser": "^0.1.1",
"@types/safer-buffer": "^2.1.0",
"@types/uuid": "^9.0.8",
"@types/ws": "^8.5.5",
"@types/yargs": "^15",
"@vscode/codicons": "*",
Expand Down Expand Up @@ -68,6 +69,7 @@
"safer-buffer": "^2.1.2",
"socket.io": "^4.5.3",
"socket.io-client": "^4.5.3",
"uuid": "^9.0.1",
"vscode-languageserver-protocol": "^3.17.2",
"vscode-uri": "^2.1.1",
"ws": "^8.14.1",
Expand Down
75 changes: 4 additions & 71 deletions packages/core/src/common/uuid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,84 +21,17 @@

// based on https://github.com/microsoft/vscode/blob/1.72.2/src/vs/base/common/uuid.ts

import { v5 } from 'uuid';
import { v4, v5 } from 'uuid';

const _UUIDPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;

export function isUUID(value: string): boolean {
return _UUIDPattern.test(value);
}

declare const crypto: undefined | {
// https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues#browser_compatibility
getRandomValues?(data: Uint8Array): Uint8Array;
// https://developer.mozilla.org/en-US/docs/Web/API/Crypto/randomUUID#browser_compatibility
randomUUID?(): string;
};

export const generateUuid = (function (): () => string {

// use `randomUUID` if possible
if (typeof crypto === 'object' && typeof crypto.randomUUID === 'function') {
return crypto.randomUUID.bind(crypto);
}

// use `randomValues` if possible
let getRandomValues: (bucket: Uint8Array) => Uint8Array;
if (typeof crypto === 'object' && typeof crypto.getRandomValues === 'function') {
getRandomValues = crypto.getRandomValues.bind(crypto);

} else {
getRandomValues = function (bucket: Uint8Array): Uint8Array {
for (let i = 0; i < bucket.length; i++) {
bucket[i] = Math.floor(Math.random() * 256);
}
return bucket;
};
}

// prep-work
const _data = new Uint8Array(16);
const _hex: string[] = [];
for (let i = 0; i < 256; i++) {
_hex.push(i.toString(16).padStart(2, '0'));
}

// eslint-disable-next-line @typescript-eslint/no-shadow
return function generateUuid(): string {
// get data
getRandomValues(_data);

// set version bits
_data[6] = (_data[6] & 0x0f) | 0x40;
_data[8] = (_data[8] & 0x3f) | 0x80;

// print as string
let i = 0;
let result = '';
result += _hex[_data[i++]];
result += _hex[_data[i++]];
result += _hex[_data[i++]];
result += _hex[_data[i++]];
result += '-';
result += _hex[_data[i++]];
result += _hex[_data[i++]];
result += '-';
result += _hex[_data[i++]];
result += _hex[_data[i++]];
result += '-';
result += _hex[_data[i++]];
result += _hex[_data[i++]];
result += '-';
result += _hex[_data[i++]];
result += _hex[_data[i++]];
result += _hex[_data[i++]];
result += _hex[_data[i++]];
result += _hex[_data[i++]];
result += _hex[_data[i++]];
return result;
};
})();
export function generateUuid(): string {
return v4();
}

const NAMESPACE = '4c90ee4f-d952-44b1-83ca-f04121ab8e05';
/**
Expand Down
3 changes: 1 addition & 2 deletions packages/notebook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"@theia/editor": "1.46.0",
"@theia/filesystem": "1.46.0",
"@theia/monaco": "1.46.0",
"react-perfect-scrollbar": "^1.5.8",
"uuid": "^8.3.2"
"react-perfect-scrollbar": "^1.5.8"
},
"publishConfig": {
"access": "public"
Expand Down
3 changes: 1 addition & 2 deletions packages/plugin-ext/src/plugin/webviews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************

import { generateUuid } from '@theia/core/lib/common/uuid';
import { generateUuid, hashValue } from '@theia/core/lib/common/uuid';
import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
import { Plugin, WebviewsExt, WebviewPanelViewState, WebviewsMain, PLUGIN_RPC_CONTEXT, WebviewInitData, /* WebviewsMain, PLUGIN_RPC_CONTEXT */ } from '../common/plugin-api-rpc';
import * as theia from '@theia/plugin';
Expand All @@ -24,7 +24,6 @@ import { fromViewColumn, toViewColumn, toWebviewPanelShowOptions } from './type-
import { Disposable, WebviewPanelTargetArea, URI } from './types-impl';
import { WorkspaceExtImpl } from './workspace';
import { PluginIconPath } from './plugin-icon-path';
import { hashValue } from '@theia/core/lib/common/uuid';

@injectable()
export class WebviewsExtImpl implements WebviewsExt {
Expand Down
4 changes: 1 addition & 3 deletions packages/typehierarchy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
"description": "Theia - Type Hierarchy Extension",
"dependencies": {
"@theia/core": "1.46.0",
"@theia/editor": "1.46.0",
"@types/uuid": "^7.0.3",
"uuid": "^8.0.0"
"@theia/editor": "1.46.0"
},
"publishConfig": {
"access": "public"
Expand Down
7 changes: 6 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2272,6 +2272,11 @@
dependencies:
"@types/node" "*"

"@types/uuid@^9.0.8":
version "9.0.8"
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-9.0.8.tgz#7545ba4fc3c003d6c756f651f3bf163d8f0f29ba"
integrity sha512-jg+97EGIcY9AGHJJRaaPVgetKDsrTgbRjQ5Msgjh/DQKEFl0DtyRr/VCOyD1T2R1MNeWPK/u7JoGhlDZnKBAfA==

"@types/vscode-notebook-renderer@^1.72.0":
version "1.72.1"
resolved "https://registry.yarnpkg.com/@types/vscode-notebook-renderer/-/vscode-notebook-renderer-1.72.1.tgz#5605079fa6f0fa1dddc57ce11315eec0d1a8d869"
Expand Down Expand Up @@ -11629,7 +11634,7 @@ uuid@^8.3.2:
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==

uuid@^9.0.0:
uuid@^9.0.0, uuid@^9.0.1:
version "9.0.1"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-9.0.1.tgz#e188d4c8853cc722220392c424cd637f32293f30"
integrity sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==
Expand Down

0 comments on commit 7313a81

Please sign in to comment.