util.d.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import { SpawnOptions } from 'child_process';
  2. import * as https from 'https';
  3. import { DownloadOptions, DownloadPlatform } from './download';
  4. import { TestOptions } from './runTest';
  5. import { ProgressReporter } from './progress';
  6. export declare let systemDefaultPlatform: DownloadPlatform;
  7. export declare const isPlatformWindows: (platform: string) => boolean;
  8. export declare const isPlatformDarwin: (platform: string) => boolean;
  9. export declare const isPlatformLinux: (platform: string) => boolean;
  10. export declare const isPlatformServer: (platform: string) => boolean;
  11. export declare const isPlatformCLI: (platform: string) => boolean;
  12. export declare class Version {
  13. readonly id: string;
  14. readonly isReleased: boolean;
  15. static parse(version: string): Version;
  16. constructor(id: string, isReleased?: boolean);
  17. get isCommit(): boolean;
  18. get isInsiders(): boolean;
  19. get isStable(): boolean;
  20. toString(): string;
  21. }
  22. export declare function getVSCodeDownloadUrl(version: Version, platform: string): string;
  23. export declare function urlToOptions(url: string): https.RequestOptions;
  24. export declare function downloadDirToExecutablePath(dir: string, platform: DownloadPlatform): string;
  25. export declare function insidersDownloadDirToExecutablePath(dir: string, platform: DownloadPlatform): string;
  26. export declare function insidersDownloadDirMetadata(dir: string, platform: DownloadPlatform, reporter: ProgressReporter): {
  27. version: any;
  28. date: Date;
  29. };
  30. export interface IUpdateMetadata {
  31. url: string;
  32. name: string;
  33. version: string;
  34. productVersion: string;
  35. hash: string;
  36. timestamp: number;
  37. sha256hash: string;
  38. supportsFastUpdate: boolean;
  39. }
  40. export declare function getInsidersVersionMetadata(platform: string, version: string, released: boolean): Promise<IUpdateMetadata>;
  41. export declare function getLatestInsidersMetadata(platform: string, released: boolean): Promise<IUpdateMetadata>;
  42. /**
  43. * Resolve the VS Code cli path from executable path returned from `downloadAndUnzipVSCode`.
  44. * Usually you will want {@link resolveCliArgsFromVSCodeExecutablePath} instead.
  45. */
  46. export declare function resolveCliPathFromVSCodeExecutablePath(vscodeExecutablePath: string, platform?: DownloadPlatform): string;
  47. /**
  48. * Resolve the VS Code cli arguments from executable path returned from `downloadAndUnzipVSCode`.
  49. * You can use this path to spawn processes for extension management. For example:
  50. *
  51. * ```ts
  52. * const cp = require('child_process');
  53. * const { downloadAndUnzipVSCode, resolveCliArgsFromVSCodeExecutablePath } = require('@vscode/test-electron')
  54. * const vscodeExecutablePath = await downloadAndUnzipVSCode('1.36.0');
  55. * const [cli, ...args] = resolveCliArgsFromVSCodeExecutablePath(vscodeExecutablePath);
  56. *
  57. * cp.spawnSync(cli, [...args, '--install-extension', '<EXTENSION-ID-OR-PATH-TO-VSIX>'], {
  58. * encoding: 'utf-8',
  59. * stdio: 'inherit'
  60. * shell: process.platform === 'win32',
  61. * });
  62. * ```
  63. *
  64. * @param vscodeExecutablePath The `vscodeExecutablePath` from `downloadAndUnzipVSCode`.
  65. */
  66. export declare function resolveCliArgsFromVSCodeExecutablePath(vscodeExecutablePath: string, options?: Pick<TestOptions, 'reuseMachineInstall' | 'platform'>): string[];
  67. export interface RunVSCodeCommandOptions extends Partial<DownloadOptions> {
  68. /**
  69. * Additional options to pass to `child_process.spawn`
  70. */
  71. spawn?: SpawnOptions;
  72. /**
  73. * Whether VS Code should be launched using default settings and extensions
  74. * installed on this machine. If `false`, then separate directories will be
  75. * used inside the `.vscode-test` folder within the project.
  76. *
  77. * Defaults to `false`.
  78. */
  79. reuseMachineInstall?: boolean;
  80. }
  81. /** Adds the extensions and user data dir to the arguments for the VS Code CLI */
  82. export declare function getProfileArguments(args: readonly string[]): string[];
  83. export declare function hasArg(argName: string, argList: readonly string[]): boolean;
  84. export declare class VSCodeCommandError extends Error {
  85. readonly exitCode: number | null;
  86. readonly stderr: string;
  87. stdout: string;
  88. constructor(args: string[], exitCode: number | null, stderr: string, stdout: string);
  89. }
  90. /**
  91. * Runs a VS Code command, and returns its output.
  92. *
  93. * @throws a {@link VSCodeCommandError} if the command fails
  94. */
  95. export declare function runVSCodeCommand(_args: readonly string[], options?: RunVSCodeCommandOptions): Promise<{
  96. stdout: string;
  97. stderr: string;
  98. }>;
  99. /** Predicates whether arg is undefined or null */
  100. export declare function isDefined<T>(arg: T | undefined | null): arg is T;
  101. /**
  102. * Validates the stream data matches the given length and checksum, if any.
  103. *
  104. * Note: md5 is not ideal, but it's what we get from the CDN, and for the
  105. * purposes of self-reported content verification is sufficient.
  106. */
  107. export declare function validateStream(readable: NodeJS.ReadableStream, length: number, sha256?: string): Promise<void>;
  108. /** Gets a Buffer from a Node.js stream */
  109. export declare function streamToBuffer(readable: NodeJS.ReadableStream): Promise<Buffer>;
  110. /** Gets whether child is a subdirectory of the parent */
  111. export declare function isSubdirectory(parent: string, child: string): boolean;
  112. /**
  113. * Wraps a function so that it's called once, and never again, memoizing
  114. * the result unless it rejects.
  115. */
  116. export declare function onceWithoutRejections<T, Args extends unknown[]>(fn: (...args: Args) => Promise<T>): (...args: Args) => Promise<T>;
  117. export declare function killTree(processId: number, force: boolean): Promise<void>;