Skip to content

Commit fa80e06

Browse files
committed
feat: clean static method
1 parent 96650bf commit fa80e06

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
command: npm install
3636
- run:
3737
name: Run unit tests.
38-
command: npm run ci:coverage
38+
command: sudo npm run ci:coverage
3939
- run:
4040
name: Submit coverage data to codecov.
4141
command: bash <(curl -s https://codecov.io/bash)

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,24 @@ Default: `wpr`
9999

100100
Sets the name of the disk/drive/mount point for the RAMdisk. e.g. A value of `batman` would result in a disk root of `/Volumes/batman` on MacOS and `/mnt/batman` on Linux variants.
101101

102+
## API
103+
104+
### `WebpackPluginRamdisk.cleanup(diskPath)`
105+
Parameters: `diskPath``String` The mounted path of the RAMdisk to unmount and remove
106+
107+
`Static`. Provides a convenience method to unmount and remove a RAMdisk created with the plugin.
108+
109+
To remove the RAMdisk that the plugin created, first obtain the `diskPath` from the plugin:
110+
111+
```js
112+
const { WebpackPluginRamdisk } = require('webpack-plugin-ramdisk');
113+
const plugin = new WebpackPluginRamdisk(options)
114+
const { diskPath } = plugin;
115+
116+
WebpackPluginRamdisk.cleanup(diskPath);
117+
```
118+
119+
_**Use Caution** as specifying the wrong `diskPath` can have unintended consequences and cause a loss of data. The commands this method utilize can remove other drives as well._
102120

103121
### Linux Users
104122

lib/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const { join } = require('path');
1212

1313
const chalk = require('chalk');
1414

15-
const { init } = require('./ramdisk');
15+
const { cleanup, init } = require('./ramdisk');
1616
const { validate } = require('./validate');
1717

1818
const defaults = {
@@ -53,6 +53,10 @@ class WebpackPluginRamdisk {
5353

5454
info(chalk.blue(`⬡ ${key}:`), `Build being written to ${outputPath}`);
5555
}
56+
57+
static cleanup(diskPath) {
58+
return cleanup(diskPath);
59+
}
5660
}
5761

5862
module.exports = { defaults, WebpackPluginRamdisk };

lib/ramdisk.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ const mount = (options) => {
4646
};
4747

4848
module.exports = {
49+
cleanup(diskPath) {
50+
const command =
51+
process.platform === 'darwin' ? `hdiutil detach ${diskPath}` : `sudo umount ${diskPath}`;
52+
return execa.commandSync(command);
53+
},
54+
4955
init(opts) {
5056
const root = getRoot(opts.name);
5157
const blocks = opts.bytes / opts.blockSize;

test/plugin.test.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ const execa = require('execa');
66

77
const { WebpackPluginRamdisk } = require('../lib');
88

9-
const detatch = (diskPath) => {
10-
const command =
11-
process.platform === 'darwin' ? `hdiutil detach ${diskPath}` : `sudo umount ${diskPath}`;
12-
execa.commandSync(command);
13-
};
9+
const detatch = WebpackPluginRamdisk.cleanup;
1410

1511
const getSize = (diskPath) => {
1612
const { stdout } = execa.commandSync(`df -H ${diskPath}`);

0 commit comments

Comments
 (0)