Skip to content

Commit

Permalink
Replace deprecated rmdir -> rm (#572)
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheeguerin authored Jun 1, 2022
1 parent 24ed544 commit c19689f
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 16 deletions.
10 changes: 10 additions & 0 deletions common/changes/@cadl-lang/compiler/fix-rmdir_2022-06-01-17-51.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cadl-lang/compiler",
"comment": "",
"type": "none"
}
],
"packageName": "@cadl-lang/compiler"
}
4 changes: 2 additions & 2 deletions packages/compiler/core/cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-console */
import { spawnSync, SpawnSyncOptionsWithStringEncoding } from "child_process";
import { mkdtemp, readdir, rmdir } from "fs/promises";
import { mkdtemp, readdir, rm } from "fs/promises";
import mkdirp from "mkdirp";
import watch from "node-watch";
import os from "os";
Expand Down Expand Up @@ -421,7 +421,7 @@ async function installVsix(pkg: string, install: (vsixPaths: string[]) => void,
install(vsixPaths);

// delete temporary directory
await rmdir(temp, { recursive: true });
await rm(temp, { recursive: true });
}

function runCode(codeArgs: string[], insiders: boolean, debug: boolean) {
Expand Down
6 changes: 3 additions & 3 deletions packages/compiler/core/node-host.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { readdir, readFile, realpath, rmdir, stat, writeFile } from "fs/promises";
import { readdir, readFile, realpath, rm, stat, writeFile } from "fs/promises";
import mkdirp from "mkdirp";
import fetch from "node-fetch";
import { fileURLToPath, pathToFileURL } from "url";
import { createSourceFile } from "./diagnostics.js";
import { createConsoleSink } from "./logger/index.js";
import { joinPaths, resolvePath } from "./path-utils.js";
import { CompilerHost, RemoveDirOptions } from "./types";
import { CompilerHost, RmOptions } from "./types";
import { getSourceFileKindFromExt } from "./util.js";

/**
Expand All @@ -21,7 +21,7 @@ export const NodeHost: CompilerHost = {
readFile: async (path: string) => createSourceFile(await readFile(path, "utf-8"), path),
writeFile: (path: string, content: string) => writeFile(path, content, { encoding: "utf-8" }),
readDir: (path: string) => readdir(path),
removeDir: (path: string, options: RemoveDirOptions) => rmdir(path, options),
rm: (path: string, options: RmOptions) => rm(path, options),
getExecutionRoot: () => resolvePath(fileURLToPath(import.meta.url), "../../../"),
getJsImport: (path: string) => import(pathToFileURL(path).href),
getLibDirs() {
Expand Down
8 changes: 4 additions & 4 deletions packages/compiler/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,7 @@ export interface Dirent {
isDirectory(): boolean;
}

export interface RemoveDirOptions {
export interface RmOptions {
/**
* If `true`, perform a recursive directory removal. In
* recursive mode, errors are not reported if `path` does not exist, and
Expand Down Expand Up @@ -1142,10 +1142,10 @@ export interface CompilerHost {
readDir(dir: string): Promise<string[]>;

/**
* Deletes the directory.
* @param path Path to the directory.
* Deletes a directory or file.
* @param path Path to the directory or file.
*/
removeDir(dir: string, options?: RemoveDirOptions): Promise<void>;
rm(path: string, options?: RmOptions): Promise<void>;

/**
* create directory recursively.
Expand Down
13 changes: 9 additions & 4 deletions packages/compiler/testing/test-host.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import assert from "assert";
import { RmOptions } from "fs";
import { readFile } from "fs/promises";
import { globby } from "globby";
import { fileURLToPath, pathToFileURL } from "url";
Expand Down Expand Up @@ -60,13 +61,17 @@ function createTestCompilerHost(
.map((x) => x.replace(`${path}/`, ""));
},

async removeDir(path: string) {
async rm(path: string, options: RmOptions) {
path = resolveVirtualPath(path);

for (const key of virtualFs.keys()) {
if (key.startsWith(`${path}/`)) {
virtualFs.delete(key);
if (options.recursive && !virtualFs.has(path)) {
for (const key of virtualFs.keys()) {
if (key.startsWith(`${path}/`)) {
virtualFs.delete(key);
}
}
} else {
virtualFs.delete(path);
}
},

Expand Down
2 changes: 1 addition & 1 deletion packages/playground/src/browserHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export async function createBrowserHost(): Promise<BrowserHost> {
.map((x) => x.replace(`${path}/`, ""));
},

async removeDir(path: string) {
async rm(path: string) {
path = resolveVirtualPath(path);

for (const key of virtualFs.keys()) {
Expand Down
4 changes: 2 additions & 2 deletions packages/samples/scripts/regen-samples.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node
// @ts-check
import { run } from "@cadl-lang/internal-build-utils";
import { readdirSync, rmdirSync } from "fs";
import { readdirSync, rmSync } from "fs";
import mkdirp from "mkdirp";
import { dirname, join, normalize, resolve } from "path";
import { fileURLToPath } from "url";
Expand Down Expand Up @@ -30,7 +30,7 @@ async function main() {
// clear any previous output as otherwise failing to emit anything could
// escape PR validation. Also ensures we delete output for samples that
// no longer exist.
rmdirSync(rootOutputPath, { recursive: true });
rmSync(rootOutputPath, { recursive: true });

for (const folderName of getSampleFolders()) {
const inputPath = join(rootInputPath, folderName);
Expand Down

0 comments on commit c19689f

Please sign in to comment.