debt - prefer lazy imports (#198668)

This commit is contained in:
Benjamin Pasero 2023-11-20 12:16:11 +01:00 committed by GitHub
parent be038181ca
commit 047cf79f5d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 11 deletions

View file

@ -99,7 +99,6 @@
"native-watchdog": "^1.4.1",
"node-pty": "1.1.0-beta5",
"tas-client-umd": "0.1.8",
"util": "^0.12.4",
"v8-inspect-profiler": "^0.1.0",
"vscode-oniguruma": "1.7.0",
"vscode-regexpp": "^3.1.0",
@ -211,6 +210,7 @@
"tsec": "0.2.7",
"typescript": "^5.4.0-dev.20231116",
"typescript-formatter": "7.1.0",
"util": "^0.12.4",
"vscode-nls-dev": "^3.3.1",
"webpack": "^5.77.0",
"webpack-cli": "^5.0.1",
@ -228,4 +228,4 @@
"optionalDependencies": {
"windows-foreground-love": "0.5.0"
}
}
}

View file

@ -11,8 +11,7 @@ import * as path from 'vs/base/common/path';
import { assertIsDefined } from 'vs/base/common/types';
import { Promises } from 'vs/base/node/pfs';
import * as nls from 'vs/nls';
import { Entry, open as _openZip, ZipFile } from 'yauzl';
import * as yazl from 'yazl';
import type { Entry, ZipFile } from 'yauzl';
export const CorruptZipMessage: string = 'end of central directory record signature not found';
const CORRUPT_ZIP_PATTERN = new RegExp(CorruptZipMessage);
@ -161,9 +160,11 @@ function extractZip(zipfile: ZipFile, targetPath: string, options: IOptions, tok
}).finally(() => listener.dispose());
}
function openZip(zipFile: string, lazy: boolean = false): Promise<ZipFile> {
async function openZip(zipFile: string, lazy: boolean = false): Promise<ZipFile> {
const { open } = await import('yauzl');
return new Promise<ZipFile>((resolve, reject) => {
_openZip(zipFile, lazy ? { lazyEntries: true } : undefined!, (error?: Error, zipfile?: ZipFile) => {
open(zipFile, lazy ? { lazyEntries: true } : undefined!, (error?: Error, zipfile?: ZipFile) => {
if (error) {
reject(toExtractError(error));
} else {
@ -191,9 +192,11 @@ export interface IFile {
localPath?: string;
}
export function zip(zipPath: string, files: IFile[]): Promise<string> {
export async function zip(zipPath: string, files: IFile[]): Promise<string> {
const { ZipFile } = await import('yazl');
return new Promise<string>((c, e) => {
const zip = new yazl.ZipFile();
const zip = new ZipFile();
files.forEach(f => {
if (f.contents) {
zip.addBuffer(typeof f.contents === 'string' ? Buffer.from(f.contents, 'utf8') : f.contents, f.path);

View file

@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as nativeKeymap from 'native-keymap';
import type * as nativeKeymap from 'native-keymap';
import * as platform from 'vs/base/common/platform';
import { Emitter } from 'vs/base/common/event';
import { Disposable } from 'vs/base/common/lifecycle';

View file

@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as spdlog from '@vscode/spdlog';
import type * as spdlog from '@vscode/spdlog';
import { ByteSize } from 'vs/platform/files/common/files';
import { AbstractMessageLogger, ILogger, LogLevel } from 'vs/platform/log/common/log';

View file

@ -6,7 +6,7 @@
import { AbstractPolicyService, IPolicyService, PolicyDefinition } from 'vs/platform/policy/common/policy';
import { IStringDictionary } from 'vs/base/common/collections';
import { Throttler } from 'vs/base/common/async';
import { createWatcher, PolicyUpdate, Watcher } from '@vscode/policy-watcher';
import type { PolicyUpdate, Watcher } from '@vscode/policy-watcher';
import { MutableDisposable } from 'vs/base/common/lifecycle';
import { ILogService } from 'vs/platform/log/common/log';
@ -25,6 +25,8 @@ export class NativePolicyService extends AbstractPolicyService implements IPolic
protected async _updatePolicyDefinitions(policyDefinitions: IStringDictionary<PolicyDefinition>): Promise<void> {
this.logService.trace(`NativePolicyService#_updatePolicyDefinitions - Found ${Object.keys(policyDefinitions).length} policy definitions`);
const { createWatcher } = await import('@vscode/policy-watcher');
await this.throttler.queue(() => new Promise<void>((c, e) => {
try {
this.watcher.value = createWatcher(this.productName, policyDefinitions, update => {