Skip to content

Commit

Permalink
Remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmarti committed Nov 15, 2023
1 parent bd19f61 commit 2d24543
Show file tree
Hide file tree
Showing 14 changed files with 4 additions and 241 deletions.
3 changes: 0 additions & 3 deletions src/spec-common/commonUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ export function equalPaths(platform: NodeJS.Platform, a: string, b: string) {
return a.toLowerCase() === b.toLowerCase();
}

export const tsnode = path.join(__dirname, '..', '..', 'node_modules', '.bin', 'ts-node');
export const isTsnode = path.basename(process.argv[0]) === 'ts-node' || process.argv.indexOf('ts-node/register') !== -1;

export async function runCommandNoPty(options: {
exec: ExecFunction;
cmd: string;
Expand Down
9 changes: 0 additions & 9 deletions src/spec-common/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,3 @@ export async function findGitRootFolder(cliHost: FileHost | CLIHost, folderPath:
return undefined;
}
}

export interface GitCloneOptions {
url: string;
tokenEnvVar?: string;
branch?: string;
recurseSubmodules?: boolean;
env?: NodeJS.ProcessEnv;
fullClone?: boolean;
}
2 changes: 1 addition & 1 deletion src/spec-configuration/configurationCommonUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { URI } from 'vscode-uri';
import { CLIHostDocuments } from './editableFiles';
import { FileHost } from '../spec-utils/pfs';

export { FileHost, FileTypeBitmask } from '../spec-utils/pfs';
export { FileHost } from '../spec-utils/pfs';

const enum CharCode {
Slash = 47,
Expand Down
16 changes: 0 additions & 16 deletions src/spec-configuration/containerFeaturesConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,6 @@ export interface GithubSourceInformation extends BaseSourceInformation {
userFeatureIdWithoutVersion: string;
}

export interface GithubSourceInformationInput {
owner: string;
repo: string;
ref?: string;
sha?: string;
tag?: string;
}


export interface FeatureSet {
features: Feature[];
internalVersion?: string;
Expand Down Expand Up @@ -193,13 +184,6 @@ export interface GithubApiReleaseAsset {
updated_at: string;
}

// Supports the `node` layer by collapsing all the individual features into a single `features` array.
// Regardless of their origin.
// Information is lost, but for the node layer we need not care about which set a given feature came from.
export interface CollapsedFeaturesConfig {
allFeatures: Feature[];
}

export interface ContainerFeatureInternalParams {
extensionPath: string;
cacheFolder: string;
Expand Down
18 changes: 0 additions & 18 deletions src/spec-configuration/editableFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,21 +161,3 @@ export function createDocuments(fileHost: FileHost, shellServer?: ShellServer):
export interface ShellServer {
exec(cmd: string, options?: { logOutput?: boolean; stdin?: Buffer }): Promise<{ stdout: string; stderr: string }>;
}

const editQueues = new Map<string, (() => Promise<void>)[]>();

export async function runEdit(uri: URI, edit: () => Promise<void>) {
const uriString = uri.toString();
let queue = editQueues.get(uriString);
if (!queue) {
editQueues.set(uriString, queue = []);
}
queue.push(edit);
if (queue.length === 1) {
while (queue.length) {
await queue[0]();
queue.shift();
}
editQueues.delete(uriString);
}
}
4 changes: 2 additions & 2 deletions src/spec-node/configContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as jsonc from 'jsonc-parser';

import { openDockerfileDevContainer } from './singleContainer';
import { openDockerComposeDevContainer } from './dockerCompose';
import { ResolverResult, DockerResolverParameters, isDockerFileConfig, runInitializeCommand, createDocuments, getWorkspaceConfiguration, BindMountConsistency, uriToFsPath, DevContainerAuthority, isDevContainerAuthority, SubstituteConfig, SubstitutedConfig, addSubstitution, envListToObj, findContainerAndIdLabels } from './utils';
import { ResolverResult, DockerResolverParameters, isDockerFileConfig, runInitializeCommand, getWorkspaceConfiguration, BindMountConsistency, uriToFsPath, DevContainerAuthority, isDevContainerAuthority, SubstituteConfig, SubstitutedConfig, addSubstitution, envListToObj, findContainerAndIdLabels } from './utils';
import { beforeContainerSubstitute, substitute } from '../spec-common/variableSubstitution';
import { ContainerError } from '../spec-common/errors';
import { Workspace, workspaceFromPath, isWorkspacePath } from '../spec-utils/workspaces';
Expand All @@ -20,8 +20,8 @@ import { getDefaultDevContainerConfigPath, getDevContainerConfigPathIn } from '.
import { DevContainerConfig, DevContainerFromDockerComposeConfig, DevContainerFromDockerfileConfig, DevContainerFromImageConfig, updateFromOldProperties } from '../spec-configuration/configuration';
import { ensureNoDisallowedFeatures } from './disallowedFeatures';
import { DockerCLIParameters } from '../spec-shutdown/dockerUtils';
import { createDocuments } from '../spec-configuration/editableFiles';

export { getWellKnownDevContainerPaths as getPossibleDevContainerPaths } from '../spec-configuration/configurationCommonUtils';

export async function resolve(params: DockerResolverParameters, configFile: URI | undefined, overrideConfigFile: URI | undefined, providedIdLabels: string[] | undefined, additionalFeatures: Record<string, string | boolean | Record<string, string | boolean>>): Promise<ResolverResult> {
if (configFile && !/\/\.?devcontainer\.json$/.test(configFile.path)) {
Expand Down
4 changes: 0 additions & 4 deletions src/spec-node/dockerfileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
import * as semver from 'semver';
import { Mount } from '../spec-configuration/containerFeaturesConfiguration';

export { getConfigFilePath, getDockerfilePath, isDockerFileConfig, resolveConfigFilePath } from '../spec-configuration/configuration';
export { uriToFsPath, parentURI } from '../spec-configuration/configurationCommonUtils';
export { CLIHostDocuments, Documents, createDocuments, Edit, fileDocuments, RemoteDocuments } from '../spec-configuration/editableFiles';


const findFromLines = new RegExp(/^(?<line>\s*FROM.*)/, 'gmi');
const parseFromLine = /FROM\s+(?<platform>--platform=\S+\s+)?(?<image>"?[^\s]+"?)(\s+AS\s+(?<label>[^\s]+))?/i;
Expand Down
3 changes: 1 addition & 2 deletions src/spec-node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ import { getImageIndexEntryForPlatform, getManifest, getRef } from '../spec-conf
import { requestEnsureAuthenticated } from '../spec-configuration/httpOCIRegistry';
import { configFileLabel, findDevContainer, hostFolderLabel } from './singleContainer';

export { getConfigFilePath, getDockerfilePath, isDockerFileConfig, resolveConfigFilePath } from '../spec-configuration/configuration';
export { getConfigFilePath, getDockerfilePath, isDockerFileConfig } from '../spec-configuration/configuration';
export { uriToFsPath, parentURI } from '../spec-configuration/configurationCommonUtils';
export { CLIHostDocuments, Documents, createDocuments, Edit, fileDocuments, RemoteDocuments } from '../spec-configuration/editableFiles';


export type BindMountConsistency = 'consistent' | 'cached' | 'delegated' | undefined;
Expand Down
52 changes: 0 additions & 52 deletions src/spec-shutdown/dockerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,6 @@ export async function inspectImage(params: DockerCLIParameters | PartialExecPara
return (await inspect<ImageDetails>(params, 'image', [id]))[0];
}

export interface VolumeDetails {
Name: string;
CreatedAt: string;
Labels: Record<string, string> | null;
}

export async function inspectVolume(params: DockerCLIParameters | PartialExecParameters | DockerResolverParameters, name: string): Promise<VolumeDetails> {
return (await inspect<VolumeDetails>(params, 'volume', [name]))[0];
}

export async function inspectVolumes(params: DockerCLIParameters | PartialExecParameters | DockerResolverParameters, names: string[]): Promise<VolumeDetails[]> {
return inspect<VolumeDetails>(params, 'volume', names);
}

async function inspect<T>(params: DockerCLIParameters | PartialExecParameters | DockerResolverParameters, type: 'container' | 'image' | 'volume', ids: string[]): Promise<T[]> {
if (!ids.length) {
return [];
Expand Down Expand Up @@ -177,26 +163,6 @@ export async function listContainers(params: DockerCLIParameters | PartialExecPa
.filter(s => !!s);
}

export async function listVolumes(params: DockerCLIParameters | PartialExecParameters | DockerResolverParameters, labels: string[] = []) {
const filterArgs = [];
for (const label of labels) {
filterArgs.push('--filter', `label=${label}`);
}
const result = await dockerCLI(params, 'volume', 'ls', '-q', ...filterArgs);
return result.stdout
.toString()
.split(/\r?\n/)
.filter(s => !!s);
}

export async function createVolume(params: DockerCLIParameters | PartialExecParameters | DockerResolverParameters, name: string, labels: string[]) {
const labelArgs: string[] = [];
for (const label of labels) {
labelArgs.push('--label', label);
}
await dockerCLI(params, 'volume', 'create', ...labelArgs, name);
}

export async function getEvents(params: DockerCLIParameters | DockerResolverParameters, filters?: Record<string, string[]>) {
const { exec, cmd, args, env, output } = toExecParameters(params);
const filterArgs = [];
Expand Down Expand Up @@ -257,24 +223,6 @@ export async function dockerCLI(params: DockerCLIParameters | PartialExecParamet
});
}

export async function dockerContext(params: DockerCLIParameters) {
try {
// 'docker context show' is only available as an addon from the 'compose-cli'. 'docker context inspect' connects to the daemon making it slow. Using 'docker context ls' instead.
const { stdout } = await dockerCLI(params, 'context', 'ls', '--format', '{{json .}}');
const json = `[${stdout.toString()
.trim()
.split(/\r?\n/)
.join(',')
}]`;
const contexts = JSON.parse(json) as { Current: boolean; Name: string }[];
const current = contexts.find(c => c.Current)?.Name;
return current;
} catch {
// Docker is not installed or Podman does not have contexts.
return undefined;
}
}

export async function isPodman(params: DockerCLIParameters | DockerResolverParameters) {
const cliHost = 'cliHost' in params ? params.cliHost : params.common.cliHost;
if (cliHost.platform !== 'linux') {
Expand Down
16 changes: 0 additions & 16 deletions src/spec-shutdown/shutdownUtils.ts

This file was deleted.

31 changes: 0 additions & 31 deletions src/spec-utils/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,37 +37,6 @@ export class NodeEventEmitter<T> {
}
}

export interface ResultEvent<E, R> {
(listener: (e: E) => R): Disposable;
}

export class ResultEventEmitter<E, R> {

private nodeEmitter = new EventEmitter();

event: ResultEvent<E, R> = (listener: (e: E) => R): Disposable => {
const wrapper = (e: { data: E; results: R[] }) => e.results.push(listener(e.data));
this.nodeEmitter.on('event', wrapper);
return {
dispose: () => {
this.nodeEmitter.off('event', wrapper);
}
};
};

fire(data: E) {
const results: R[] = [];
this.nodeEmitter.emit('event', {
data,
results,
});
return results;
}
dispose() {
this.nodeEmitter.removeAllListeners();
}
}

export interface Disposable {
dispose(): void;
}
10 changes: 0 additions & 10 deletions src/spec-utils/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,10 @@ const logLevelMap = {

type logLevelString = keyof typeof logLevelMap;

const logLevelReverseMap = (Object.keys(logLevelMap) as logLevelString[])
.reduce((arr, cur) => {
arr[logLevelMap[cur]] = cur;
return arr;
}, [] as logLevelString[]);

export function mapLogLevel(text: logLevelString) {
return logLevelMap[text] || LogLevel.Info;
}

export function reverseMapLogLevel(level: LogLevel) {
return logLevelReverseMap[level] || LogLevel.Info;
}

export type LogEvent = {
type: 'text' | 'raw' | 'start' | 'stop' | 'progress';
channel?: string;
Expand Down
6 changes: 0 additions & 6 deletions src/spec-utils/types.ts

This file was deleted.

71 changes: 0 additions & 71 deletions src/spec-utils/workspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@

import * as path from 'path';

import { parse } from 'jsonc-parser';
import { URI } from 'vscode-uri'; // avoid vscode.Uri reference for tests

export interface Workspace {
readonly isWorkspaceFile: boolean;
readonly workspaceOrFolderPath: string;
Expand Down Expand Up @@ -36,71 +33,3 @@ export function workspaceFromPath(path_: typeof path.posix | typeof path.win32,
export function isWorkspacePath(workspaceOrFolderPath: string) {
return path.extname(workspaceOrFolderPath) === '.code-workspace'; // TODO: Remove VS Code specific code.
}

export async function canUseWorkspacePathInRemote(cliHost: { platform: NodeJS.Platform; path: typeof path.posix | typeof path.win32; readFile(filepath: string): Promise<Buffer> }, workspace: Workspace): Promise<string | undefined> {
if (!workspace.isWorkspaceFile) {
return undefined;
}
try {
const rootFolder = workspace.rootFolderPath;
const workspaceFileContent = (await cliHost.readFile(workspace.workspaceOrFolderPath)).toString();
const workspaceFile = parse(workspaceFileContent);
const folders = workspaceFile['folders'];
if (folders && folders.length > 0) {
for (const folder of folders) {
const folderPath = folder['path'];
let fullPath;
if (!folderPath) {
const folderURI = folder['uri'];
if (!folderURI) {
return `Workspace contains a folder that defines neither a path nor a URI.`;
}
const uri = URI.parse(folderURI);
if (uri.scheme !== 'file') {
return `Workspace contains folder '${folderURI}' not on the local file system.`;
}
return `Workspace contains an absolute folder path '${folderURI}'.`;
} else {
if (cliHost.path.isAbsolute(folderPath)) {
return `Workspace contains an absolute folder path '${folderPath}'.`;
}
fullPath = cliHost.path.resolve(rootFolder, folderPath);
}
if (!isEqualOrParent(cliHost, fullPath, rootFolder)) {
return `Folder '${fullPath}' is not a subfolder of shared root folder '${rootFolder}'.`;
}
}
return;
}
return `Workspace does not define any folders`;
} catch (e) {
return `Problems loading workspace file ${workspace.workspaceOrFolderPath}: ${e && (e.message || e.toString())}`;
}
}

export function isEqualOrParent(cliHost: { platform: NodeJS.Platform; path: typeof path.posix | typeof path.win32 }, c: string, parent: string): boolean {
if (c === parent) {
return true;
}

if (!c || !parent) {
return false;
}

if (parent.length > c.length) {
return false;
}

if (c.length > parent.length && c.charAt(parent.length) !== cliHost.path.sep) {
return false;
}

return equalPaths(cliHost.platform, parent, c.substr(0, parent.length));
}

function equalPaths(platform: NodeJS.Platform, a: string, b: string) {
if (platform === 'linux') {
return a === b;
}
return a.toLowerCase() === b.toLowerCase();
}

0 comments on commit 2d24543

Please sign in to comment.