How to use the sync function from rimraf

Find comprehensive JavaScript rimraf.sync code examples handpicked from public code repositorys.

rimraf.sync is a Node.js package that allows you to delete files and directories recursively without throwing errors on failure.

43
44
45
46
47
48
49
50
51
52
  await promisified(server.port);
  console.log(`Server listening on port ${server.port}!`);
});

beforeEach(() => {
  rimraf.sync(server.repository);
});

after(() => {
  rimraf.sync(server.repository);
fork icon250
star icon553
watch icon31

+ 7 other calls in file

25
26
27
28
29
30
31
32
33
34
});
// Remove the older files...
var items = 0;
for (
    var i = 0; i < files.length - options.staticCacheMaxVersions + 1; i++) {
    rimraf.sync(files[i]);
    items++;
}

console.info(`Removed ${items} items from cache because of staticCacheMaxVersions`)
fork icon56
star icon583
watch icon19

+ 3 other calls in file

How does rimraf.sync work?

rimraf.sync is a function in the Rimraf module for Node.js that synchronously removes files and directories recursively by using the operating system's file system API to perform the removal operation. It is a convenience wrapper around the fs module's recursive removal functions that provides a simple and consistent API for removing files and directories.

4
5
6
7
8
9
10
11
12
13
var os = require('os');
var spawnSync = require('child_process').spawnSync;

/*// Let's not use newrepo
if (fs.existsSync(path.join(__dirname, '.haxelib'))) {
    rimraf.sync(path.join(__dirname, '.haxelib'));
}*/

// Setup haxelib repository (if needed)
/*var haxelibRepo = (''+spawnSync('./haxelib', ['config'], { cwd: __dirname }).stdout).trim();
fork icon16
star icon185
watch icon20

53
54
55
56
57
58
59
60
61
62
function typings() {
  const tmpDir = './typings/tmp';

  // Clean directory if exists.
  if (fs.existsSync(tmpDir)) {
    rimraf.sync(tmpDir);
  }
  fs.mkdirSync(tmpDir);

  const excludePaths = [
fork icon71
star icon160
watch icon24

+ 3 other calls in file

Ai Example

1
2
3
4
const rimraf = require("rimraf");

// Delete the directory "my-directory" and all its contents
rimraf.sync("my-directory");

In this example, the rimraf.sync function is called with the path to the directory that we want to delete. The function will synchronously remove the directory and all of its contents.

21
22
23
24
25
26
27
28
29
const getTempFile = (name) => path.join(__dirname, 'temp', 'windows', name);

const extract = async (from, name) => {
  const to = getTempFile(name);
  fs.mkdirSync(path.join(to, '..'), {recursive: true});
  rimraf.sync(to);
  await extractZip(from, {dir: to});
  return to;
};
fork icon72
star icon135
watch icon15

94
95
96
97
98
99
100
101
102
  totalSize += byte
  spinner.succeed(chalk.green('Success: ') + chalk.yellow(`${name} `) + sizeFilter(byte)).stop()
}

async function run() {
  rimraf.sync(outDirPath)

  while (dependencies.length) {
    const describe = dependencies.shift()
fork icon12
star icon137
watch icon15

+ 3 other calls in file

175
176
177
178
179
180
181
182
183
184
        console.log("Diagram was successfully generated and saved to " + outputFile);
        return [3 /*break*/, 20];
    case 19:
        for (_i = 0, tempFilesAndFolders_1 = tempFilesAndFolders; _i < tempFilesAndFolders_1.length; _i++) {
            tempFolder = tempFilesAndFolders_1[_i];
            rimraf.sync(tempFolder);
        }
        return [7 /*endfinally*/];
    case 20: return [2 /*return*/];
}
fork icon4
star icon43
watch icon1

35
36
37
38
39
40
41
42
43
44
const spawn = ChildProcess.prototype.spawn
const spawnSync = spawnSyncBinding.spawn

function unwrap() {
  if (doSetup && !IS_DEBUG) {
    rimraf.sync(workingDir)
  }
  ChildProcess.prototype.spawn = spawn
  spawnSyncBinding.spawn = spawnSync
}
fork icon18
star icon36
watch icon7

+ 3 other calls in file

147
148
149
150
151
152
153
154
155
156

/**
 * Update the stylesheets
 */
case 'css':
        rm.sync(`${BUILD_DIR}/*.css`);
        walk(path.resolve(__dirname,  './styles')).forEach(file => fs.copyFileSync(file.path, `${BUILD_DIR}/${basename(file.path)}-${TIMESTAMP}.css`));
        break;

/**
fork icon3
star icon45
watch icon4

+ 3 other calls in file

12
13
14
15
16
17
18
19
20
21
22
23
  if ((/license/i).test(path.basename(filename))) {
    return;
  }


  console.log('  removing %s', filename.replace(process.cwd() + '/', ''));
  rimraf.sync(filename);
};


var onIgnore = function(ignore) {
  if (!ignore) {
fork icon1
star icon5
watch icon2

+ 2 other calls in file

101
102
103
104
105
106
107
108
109
110
111
112
};


const createCompiler = (config, onBuild = undefined, onPostBuild = undefined, showNotifications = true, analyzeSpeed = false) => {
  if (config.output.clean) {
    // NOTE(krishan711): this shouldn't be needed but if its removed the assets plugin doesn't work
    rimraf.sync(config.output.path);
  }


  if (analyzeSpeed) {
    const speedMeasurePlugin = new SpeedMeasurePlugin();
fork icon1
star icon2
watch icon2

+ 10 other calls in file

321
322
323
324
325
326
327
328
329
330
331
 * @return {Promise} Asynchronous result.
 */
async function generators() {
  return runTestTask('generators', async () => {
    // Clean up.
    rimraf.sync(OUTPUT_DIR);
    fs.mkdirSync(OUTPUT_DIR);


    await runGeneratorsInBrowser(OUTPUT_DIR);

fork icon0
star icon1
watch icon1

+ 11 other calls in file

210
211
212
213
214
215
216
217
218
219
220
          .src("Build/createThirdPartyNpm/**")
          .pipe(gulp.dest("Source/ThirdParty"))
      );
    })
    .then(function () {
      rimraf.sync("Build/createThirdPartyNpm");
    });
}


gulp.task("build", async function () {
fork icon0
star icon1
watch icon1

+ 43 other calls in file

196
197
198
199
200
201
202
203
204
205
    }))

    console.log('> running cleanup for a folder:', settings.workpath)

    /* run recursive rmdir */
    rimraf.sync(settings.workpath)

    console.log('> cleanup done')
    process.exit();
}
fork icon295
star icon0
watch icon55

17
18
19
20
21
22
23
24
25
26
    fs.mkdirSync(path.join(__dirname, 'output'));
  }
});

afterEach(function() {
  rimraf.sync(path.join(__dirname, 'output'));
});

describe('#fileToBase64()', function() {
  it('should return the content of a file encoded in base64', function(done) {
fork icon9
star icon36
watch icon2

+ 4 other calls in file

206
207
208
209
210
211
212
213
214
215
  "test",
  "Generated",
  "UNIT_TEST",
  "LocalCopyOfVocab"
);
rimraf.sync(testLocalCopyDirectory);

const dataset = rdf
  .dataset()
  .addAll(vocabMetadata)
fork icon3
star icon8
watch icon12

+ 3 other calls in file

178
179
180
181
182
183
184
185
186
187
  const rootDir = path.join(
    this.artifactData.outputDirectory,
    getArtifactDirectoryRoot(this.artifactData)
  );

  rimraf.sync(rootDir);
}

async generateNecessaryVocabs() {
  this.artifactData.generated = true;
fork icon3
star icon8
watch icon12

+ 3 other calls in file

71
72
73
74
75
76
77
78
79
80
    height,
    thumbnailsExtension,
  };
} catch (error1) {
  try {
    rimraf.sync(thumbnailsPath);
  } catch (error2) {
    console.warn(error2.stack); // eslint-disable-line no-console
  }
}
fork icon0
star icon1
watch icon1

135
136
137
138
139
140
141
142
143
144
  // create the output folder if it doesn't exist
  // just for convenience
  if (!fs.existsSync(outputFolder)) {
    fs.mkdirSync(outputFolder)
  }
  rimraf.sync(outputFolder + '/' + spec.clearBeforeBuild)
} else {
  rimraf.sync(outputFolder)
  fs.mkdirSync(outputFolder)
}
fork icon136
star icon0
watch icon59

+ 7 other calls in file

17
18
19
20
21
22
23
  return ! (isNative || mappedNative)
}


fs.readdirSync(base)
  .filter(isNative)
  .forEach(it => rimraf.sync(path.resolve(path.join(base, it))))
fork icon129
star icon96
watch icon0