pwd-fs 3.1.3 → 3.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/src/index.d.ts +3 -5
- package/lib/src/index.js +21 -0
- package/lib/src/powered-file-system.d.ts +2 -1
- package/lib/{powered-file-system.js → src/powered-file-system.js} +58 -54
- package/lib/{recurse-io-sync.js → src/recurse-io-sync.js} +25 -27
- package/lib/{recurse-io.js → src/recurse-io.js} +31 -33
- package/lib/test/__fmock.js +40 -0
- package/lib/test/append.spec.js +58 -0
- package/lib/test/bitmask.spec.js +26 -0
- package/lib/test/chmod.spec.js +62 -0
- package/lib/test/chown.spec.js +68 -0
- package/lib/test/constructor.spec.js +17 -0
- package/lib/test/copy.spec.js +80 -0
- package/lib/test/mkdir.spec.js +90 -0
- package/lib/test/read.spec.js +73 -0
- package/lib/test/readdir.spec.js +70 -0
- package/lib/test/remove.spec.js +63 -0
- package/lib/test/rename.spec.js +66 -0
- package/lib/test/stat.spec.js +76 -0
- package/lib/test/symlink.spec.js +74 -0
- package/lib/test/test.spec.js +60 -0
- package/lib/test/write.spec.js +82 -0
- package/package.json +7 -14
- package/readme.md +10 -8
- package/src/index.ts +4 -26
- package/src/powered-file-system.ts +22 -20
- package/{__tests__ → test}/append.spec.ts +2 -3
- package/{__tests__ → test}/chmod.spec.ts +2 -3
- package/{__tests__ → test}/chown.spec.ts +2 -4
- package/{__tests__ → test}/constructor.spec.ts +1 -1
- package/{__tests__ → test}/copy.spec.ts +2 -3
- package/{__tests__ → test}/mkdir.spec.ts +2 -1
- package/{__tests__ → test}/read.spec.ts +2 -3
- package/{__tests__ → test}/readdir.spec.ts +3 -4
- package/{__tests__ → test}/remove.spec.ts +3 -3
- package/{__tests__ → test}/rename.spec.ts +2 -2
- package/{__tests__ → test}/stat.spec.ts +2 -3
- package/{__tests__ → test}/symlink.spec.ts +3 -3
- package/{__tests__ → test}/test.spec.ts +1 -3
- package/{__tests__ → test}/write.spec.ts +2 -2
- package/tsconfig.json +5 -5
- package/jest.config.ts +0 -14
- package/lib/index.js +0 -24
- package/rollup.config.js +0 -16
- /package/lib/{__tests__ → test}/__fmock.d.ts +0 -0
- /package/lib/{__tests__ → test}/append.spec.d.ts +0 -0
- /package/lib/{__tests__ → test}/bitmask.spec.d.ts +0 -0
- /package/lib/{__tests__ → test}/chmod.spec.d.ts +0 -0
- /package/lib/{__tests__ → test}/chown.spec.d.ts +0 -0
- /package/lib/{__tests__ → test}/constructor.spec.d.ts +0 -0
- /package/lib/{__tests__ → test}/copy.spec.d.ts +0 -0
- /package/lib/{__tests__ → test}/mkdir.spec.d.ts +0 -0
- /package/lib/{__tests__ → test}/read.spec.d.ts +0 -0
- /package/lib/{__tests__ → test}/readdir.spec.d.ts +0 -0
- /package/lib/{__tests__ → test}/remove.spec.d.ts +0 -0
- /package/lib/{__tests__ → test}/rename.spec.d.ts +0 -0
- /package/lib/{__tests__ → test}/stat.spec.d.ts +0 -0
- /package/lib/{__tests__ → test}/symlink.spec.d.ts +0 -0
- /package/lib/{__tests__ → test}/test.spec.d.ts +0 -0
- /package/lib/{__tests__ → test}/write.spec.d.ts +0 -0
- /package/{__tests__ → test}/__fmock.ts +0 -0
- /package/{__tests__ → test}/bitmask.spec.ts +0 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
7
|
+
const chance_1 = __importDefault(require("chance"));
|
|
8
|
+
const expect_1 = require("expect");
|
|
9
|
+
const __fmock_1 = require("./__fmock");
|
|
10
|
+
const src_1 = require("../src");
|
|
11
|
+
describe('stat(src [, options])', () => {
|
|
12
|
+
const chance = new chance_1.default();
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
const cwd = process.cwd();
|
|
15
|
+
(0, __fmock_1.fmock)({
|
|
16
|
+
'./tmpdir/tings.txt': {
|
|
17
|
+
type: 'file',
|
|
18
|
+
data: chance.string()
|
|
19
|
+
},
|
|
20
|
+
'./tmpdir/digest/': { type: 'directory' },
|
|
21
|
+
'./tmpdir/flexapp': {
|
|
22
|
+
type: 'symlink',
|
|
23
|
+
target: `${cwd}/tmpdir/tings.txt`
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
(0, __fmock_1.restore)('./tmpdir');
|
|
29
|
+
});
|
|
30
|
+
it('Positive: Must return information a file', async () => {
|
|
31
|
+
const stats = await src_1.pfs.stat('./tmpdir/tings.txt');
|
|
32
|
+
(0, node_assert_1.default)(stats.isFile());
|
|
33
|
+
});
|
|
34
|
+
it('Positive: Must return information a directory', async () => {
|
|
35
|
+
const stats = await src_1.pfs.stat('./tmpdir/digest');
|
|
36
|
+
(0, node_assert_1.default)(stats.isDirectory());
|
|
37
|
+
});
|
|
38
|
+
it('Positive: Must return information a symlink', async () => {
|
|
39
|
+
const stats = await src_1.pfs.stat('./tmpdir/flexapp');
|
|
40
|
+
(0, node_assert_1.default)(stats.isSymbolicLink());
|
|
41
|
+
});
|
|
42
|
+
it('Negative: Throw if not exists resource', async () => {
|
|
43
|
+
const guid = chance.guid();
|
|
44
|
+
await (0, expect_1.expect)(async () => {
|
|
45
|
+
await src_1.pfs.stat(`./tmpdir/${guid}`);
|
|
46
|
+
})
|
|
47
|
+
.rejects
|
|
48
|
+
.toThrow();
|
|
49
|
+
});
|
|
50
|
+
it('[sync] Positive: Must return information a file', () => {
|
|
51
|
+
const stats = src_1.pfs.stat('./tmpdir/tings.txt', {
|
|
52
|
+
sync: true
|
|
53
|
+
});
|
|
54
|
+
(0, node_assert_1.default)(stats.isFile());
|
|
55
|
+
});
|
|
56
|
+
it('[sync] Positive: Must return information a directory in ', () => {
|
|
57
|
+
const stats = src_1.pfs.stat('./tmpdir/digest', {
|
|
58
|
+
sync: true
|
|
59
|
+
});
|
|
60
|
+
(0, node_assert_1.default)(stats.isDirectory());
|
|
61
|
+
});
|
|
62
|
+
it('[sync] Positive: Must return information a symlink', () => {
|
|
63
|
+
const stats = src_1.pfs.stat('./tmpdir/flexapp', {
|
|
64
|
+
sync: true
|
|
65
|
+
});
|
|
66
|
+
(0, node_assert_1.default)(stats.isSymbolicLink());
|
|
67
|
+
});
|
|
68
|
+
it('[sync] Negative: Throw if not exists resource', () => {
|
|
69
|
+
const guid = chance.guid();
|
|
70
|
+
node_assert_1.default.throws(() => {
|
|
71
|
+
src_1.pfs.stat(`./tmpdir/${guid}`, {
|
|
72
|
+
sync: true
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
const chance_1 = __importDefault(require("chance"));
|
|
9
|
+
const expect_1 = require("expect");
|
|
10
|
+
const __fmock_1 = require("./__fmock");
|
|
11
|
+
const src_1 = require("../src");
|
|
12
|
+
describe('symlink(src, use [, options])', () => {
|
|
13
|
+
const chance = new chance_1.default();
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
const cwd = process.cwd();
|
|
16
|
+
const frame = {
|
|
17
|
+
'./tmpdir/tings.txt': {
|
|
18
|
+
type: 'file',
|
|
19
|
+
data: chance.string()
|
|
20
|
+
},
|
|
21
|
+
'./tmpdir/digest/': { type: 'directory' },
|
|
22
|
+
'./tmpdir/flexapp': {
|
|
23
|
+
type: 'symlink',
|
|
24
|
+
target: `${cwd}/tmpdir/tings.txt`
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const counter = chance.natural({ max: 7 });
|
|
28
|
+
for (let i = 0; i < counter; i++) {
|
|
29
|
+
frame[`./tmpdir/${i}`] = { type: 'directory' };
|
|
30
|
+
}
|
|
31
|
+
(0, __fmock_1.fmock)(frame);
|
|
32
|
+
});
|
|
33
|
+
afterEach(() => {
|
|
34
|
+
(0, __fmock_1.restore)('./tmpdir');
|
|
35
|
+
});
|
|
36
|
+
it('Positive: Must be created a symbolic link', async () => {
|
|
37
|
+
await src_1.pfs.symlink('./tmpdir/tings.txt', './tmpdir/linkapp');
|
|
38
|
+
const stat = node_fs_1.default.lstatSync('./tmpdir/linkapp');
|
|
39
|
+
(0, node_assert_1.default)(stat.isSymbolicLink());
|
|
40
|
+
});
|
|
41
|
+
it('Positive: Must be created a symbolic link for directory', async () => {
|
|
42
|
+
await src_1.pfs.symlink('./tmpdir/digest', './tmpdir/linkapp');
|
|
43
|
+
const stat = node_fs_1.default.lstatSync('./tmpdir/linkapp');
|
|
44
|
+
(0, node_assert_1.default)(stat.isSymbolicLink());
|
|
45
|
+
});
|
|
46
|
+
it('Negative: Throw if destination already exists', async () => {
|
|
47
|
+
await (0, expect_1.expect)(async () => {
|
|
48
|
+
await src_1.pfs.symlink('./tmpdir/tings.txt', './tmpdir/flexapp');
|
|
49
|
+
})
|
|
50
|
+
.rejects
|
|
51
|
+
.toThrow();
|
|
52
|
+
});
|
|
53
|
+
it('[sync] Positive: Must be created a symbolic link', () => {
|
|
54
|
+
src_1.pfs.symlink('./tmpdir/tings.txt', './tmpdir/linkapp', {
|
|
55
|
+
sync: true
|
|
56
|
+
});
|
|
57
|
+
const stat = node_fs_1.default.lstatSync('./tmpdir/linkapp');
|
|
58
|
+
(0, node_assert_1.default)(stat.isSymbolicLink());
|
|
59
|
+
});
|
|
60
|
+
it('[sync] Positive: Must be created a symbolic link for directory', () => {
|
|
61
|
+
src_1.pfs.symlink('./tmpdir/digest', './tmpdir/linkapp', {
|
|
62
|
+
sync: true
|
|
63
|
+
});
|
|
64
|
+
const stat = node_fs_1.default.lstatSync('./tmpdir/linkapp');
|
|
65
|
+
(0, node_assert_1.default)(stat.isSymbolicLink());
|
|
66
|
+
});
|
|
67
|
+
it('[sync] Negative: Throw if destination already exists', () => {
|
|
68
|
+
node_assert_1.default.throws(() => {
|
|
69
|
+
src_1.pfs.symlink('./tmpdir/tings.txt', './tmpdir/flexapp', {
|
|
70
|
+
sync: true
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
7
|
+
const chance_1 = __importDefault(require("chance"));
|
|
8
|
+
const __fmock_1 = require("./__fmock");
|
|
9
|
+
const src_1 = require("../src");
|
|
10
|
+
describe('test(src[, options])', () => {
|
|
11
|
+
const chance = new chance_1.default();
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
(0, __fmock_1.fmock)({
|
|
14
|
+
'./tmpdir/tings.txt': {
|
|
15
|
+
type: 'file',
|
|
16
|
+
data: chance.string()
|
|
17
|
+
},
|
|
18
|
+
'./tmpdir/digest/': { type: 'directory' }
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
(0, __fmock_1.restore)('./tmpdir');
|
|
23
|
+
});
|
|
24
|
+
it(`Positive: Should return 'true' for current working directory`, async () => {
|
|
25
|
+
const exist = await src_1.pfs.test('.');
|
|
26
|
+
(0, node_assert_1.default)(exist);
|
|
27
|
+
});
|
|
28
|
+
it(`Positive: For existing file should return 'true'`, async () => {
|
|
29
|
+
const exist = await src_1.pfs.test('./tmpdir/tings.txt');
|
|
30
|
+
(0, node_assert_1.default)(exist);
|
|
31
|
+
});
|
|
32
|
+
it(`Positive: For existing directory should return 'true'`, async () => {
|
|
33
|
+
const exist = await src_1.pfs.test('./tmpdir/digest');
|
|
34
|
+
(0, node_assert_1.default)(exist);
|
|
35
|
+
});
|
|
36
|
+
it(`Positive: A non-existent file must return 'false'`, async () => {
|
|
37
|
+
const guid = chance.guid();
|
|
38
|
+
const exist = await src_1.pfs.test(`./tmpdir/${guid}`);
|
|
39
|
+
(0, node_assert_1.default)(exist === false);
|
|
40
|
+
});
|
|
41
|
+
it(`Positive: For existing file should return 'true'`, () => {
|
|
42
|
+
const exist = src_1.pfs.test('./tmpdir/tings.txt', {
|
|
43
|
+
sync: true
|
|
44
|
+
});
|
|
45
|
+
(0, node_assert_1.default)(exist);
|
|
46
|
+
});
|
|
47
|
+
it(`[sync] Positive: For existing directory should return 'true'`, () => {
|
|
48
|
+
const exist = src_1.pfs.test('./tmpdir/digest', {
|
|
49
|
+
sync: true
|
|
50
|
+
});
|
|
51
|
+
(0, node_assert_1.default)(exist);
|
|
52
|
+
});
|
|
53
|
+
it(`[sync] Positive: A non-existent file must return 'false'`, () => {
|
|
54
|
+
const guid = chance.guid();
|
|
55
|
+
const exist = src_1.pfs.test(`./tmpdir/${guid}`, {
|
|
56
|
+
sync: true
|
|
57
|
+
});
|
|
58
|
+
(0, node_assert_1.default)(exist === false);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
const chance_1 = __importDefault(require("chance"));
|
|
9
|
+
const expect_1 = require("expect");
|
|
10
|
+
const __fmock_1 = require("./__fmock");
|
|
11
|
+
const src_1 = require("../src");
|
|
12
|
+
describe('write(src, data[, options])', () => {
|
|
13
|
+
const chance = new chance_1.default();
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
(0, __fmock_1.fmock)({
|
|
16
|
+
'./tmpdir/tings.txt': {
|
|
17
|
+
type: 'file',
|
|
18
|
+
data: chance.string()
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
afterEach(() => {
|
|
23
|
+
(0, __fmock_1.restore)('./tmpdir');
|
|
24
|
+
});
|
|
25
|
+
it('Positive: Must write content to file', async () => {
|
|
26
|
+
const payload = chance.paragraph();
|
|
27
|
+
const guid = chance.guid();
|
|
28
|
+
await src_1.pfs.write(`./tmpdir/${guid}.txt`, payload);
|
|
29
|
+
const { size } = node_fs_1.default.lstatSync(`./tmpdir/${guid}.txt`);
|
|
30
|
+
(0, node_assert_1.default)(payload.length === size);
|
|
31
|
+
});
|
|
32
|
+
it('Positive: Must rewrite content if file already exists', async () => {
|
|
33
|
+
const payload = chance.paragraph();
|
|
34
|
+
await src_1.pfs.write('./tmpdir/tings.txt', payload);
|
|
35
|
+
const { size } = node_fs_1.default.lstatSync('./tmpdir/tings.txt');
|
|
36
|
+
(0, node_assert_1.default)(payload.length === size);
|
|
37
|
+
});
|
|
38
|
+
it('Negative: Throw if resource is directory', async () => {
|
|
39
|
+
const payload = chance.paragraph();
|
|
40
|
+
await (0, expect_1.expect)(async () => {
|
|
41
|
+
await src_1.pfs.write('./tmpdir', payload);
|
|
42
|
+
})
|
|
43
|
+
.rejects
|
|
44
|
+
.toThrow();
|
|
45
|
+
});
|
|
46
|
+
it(`Negative: Unexpected option 'flag' returns Error`, async () => {
|
|
47
|
+
const payload = chance.paragraph();
|
|
48
|
+
await (0, expect_1.expect)(async () => {
|
|
49
|
+
await src_1.pfs.write('./tmpdir/tings.txt', payload, {
|
|
50
|
+
flag: 'r'
|
|
51
|
+
});
|
|
52
|
+
})
|
|
53
|
+
.rejects
|
|
54
|
+
.toThrow();
|
|
55
|
+
});
|
|
56
|
+
it('[sync] Positive: Write contents even to a non-existent file', () => {
|
|
57
|
+
const payload = chance.paragraph();
|
|
58
|
+
const guid = chance.guid();
|
|
59
|
+
src_1.pfs.write(`./tmpdir/${guid}.txt`, payload, {
|
|
60
|
+
sync: true
|
|
61
|
+
});
|
|
62
|
+
const content = node_fs_1.default.readFileSync(`./tmpdir/${guid}.txt`, 'utf8');
|
|
63
|
+
(0, node_assert_1.default)(payload === content);
|
|
64
|
+
});
|
|
65
|
+
it('[sync] Negative: Throw if resource is directory', () => {
|
|
66
|
+
const payload = chance.paragraph();
|
|
67
|
+
node_assert_1.default.throws(() => {
|
|
68
|
+
src_1.pfs.write('./tmpdir', payload, {
|
|
69
|
+
sync: true
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
it(`[sync] Negative: Unexpected option 'flag' returns Error`, () => {
|
|
74
|
+
const payload = chance.paragraph();
|
|
75
|
+
node_assert_1.default.throws(() => {
|
|
76
|
+
src_1.pfs.write('./tmpdir/tings.txt', payload, {
|
|
77
|
+
sync: true,
|
|
78
|
+
flag: 'r'
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pwd-fs",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.4",
|
|
4
4
|
"description": "Extend the file system the capabilities of declaring the present working directory and recursive execution",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"umask",
|
|
@@ -29,25 +29,18 @@
|
|
|
29
29
|
"engines": {
|
|
30
30
|
"node": ">=13.2.0"
|
|
31
31
|
},
|
|
32
|
-
"
|
|
33
|
-
"main": "./lib/index.js",
|
|
32
|
+
"main": "./lib/src/index.js",
|
|
34
33
|
"types": "./lib/src/index.d.ts",
|
|
35
34
|
"scripts": {
|
|
36
|
-
"build": "
|
|
37
|
-
"test": "
|
|
35
|
+
"build": "tsc",
|
|
36
|
+
"test": "mocha ./lib/test"
|
|
38
37
|
},
|
|
39
38
|
"devDependencies": {
|
|
40
|
-
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
41
|
-
"@rollup/plugin-typescript": "^11.1.6",
|
|
42
39
|
"@types/chance": "^1.1.6",
|
|
43
|
-
"@types/
|
|
44
|
-
"@types/node": "^20.12.7",
|
|
40
|
+
"@types/mocha": "^10.0.6",
|
|
45
41
|
"chance": "^1.1.11",
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"ts-jest": "^29.1.2",
|
|
49
|
-
"ts-node": "^10.9.2",
|
|
50
|
-
"tslib": "^2.6.2",
|
|
42
|
+
"expect": "^29.7.0",
|
|
43
|
+
"mocha": "^10.4.0",
|
|
51
44
|
"typescript": "^5.4.5"
|
|
52
45
|
}
|
|
53
46
|
}
|
package/readme.md
CHANGED
|
@@ -19,7 +19,7 @@ To improve reliability and maintainability the code is migrated to [TypeScript](
|
|
|
19
19
|
To use `Powered File System` in your project, run:
|
|
20
20
|
|
|
21
21
|
```bash
|
|
22
|
-
npm
|
|
22
|
+
npm install pwd-fs
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
#### Table of Contents
|
|
@@ -63,19 +63,17 @@ This class implemented by following the [ECMAScript® 2018 Language Specificatio
|
|
|
63
63
|
String form paths are interpreted as UTF-8 character sequences identifying the absolute or relative filename.
|
|
64
64
|
|
|
65
65
|
```ts
|
|
66
|
-
import
|
|
66
|
+
import { pfs } from 'pwd-fs';
|
|
67
67
|
|
|
68
68
|
/**
|
|
69
69
|
* pfs.pwd === process.cwd()
|
|
70
70
|
*/
|
|
71
|
-
|
|
72
|
-
const pfs = new PoweredFileSystem();
|
|
73
71
|
```
|
|
74
72
|
|
|
75
73
|
Relative paths will be resolved relative to the current working directory as specified by `process.cwd()`:
|
|
76
74
|
|
|
77
75
|
```ts
|
|
78
|
-
import PoweredFileSystem from 'pwd-fs';
|
|
76
|
+
import { PoweredFileSystem } from 'pwd-fs';
|
|
79
77
|
|
|
80
78
|
/**
|
|
81
79
|
* pfs.pwd === `${process.cwd()}/foo/bar`
|
|
@@ -87,7 +85,7 @@ const pfs = new PoweredFileSystem('./foo/bar');
|
|
|
87
85
|
Absolute paths:
|
|
88
86
|
|
|
89
87
|
```ts
|
|
90
|
-
import PoweredFileSystem from 'pwd-fs';
|
|
88
|
+
import { PoweredFileSystem } from 'pwd-fs';
|
|
91
89
|
|
|
92
90
|
/**
|
|
93
91
|
* pfs.pwd === __dirname
|
|
@@ -141,10 +139,12 @@ These functions return information about a resource in the file system.
|
|
|
141
139
|
Asynchronously changes the permissions of a file.
|
|
142
140
|
|
|
143
141
|
```ts
|
|
142
|
+
import { bitmask } from 'pwd-fs';
|
|
143
|
+
|
|
144
144
|
await pfs.chmod('./path', 0o750);
|
|
145
145
|
const { mode } = await pfs.stat('./path');
|
|
146
146
|
|
|
147
|
-
console.log(
|
|
147
|
+
console.log(bitmask(mode) === 0o750); // true
|
|
148
148
|
```
|
|
149
149
|
|
|
150
150
|
> **Caveats:** on Windows only the write permission can be changed, and the distinction among the permissions of group, owner or others is not implemented.
|
|
@@ -194,10 +194,12 @@ See manuals [symlink(2)](http://man7.org/linux/man-pages/man2/symlink.2.html).
|
|
|
194
194
|
Asynchronously recursively copy a file or directory.
|
|
195
195
|
|
|
196
196
|
```ts
|
|
197
|
+
import { bitmask } from 'pwd-fs';
|
|
198
|
+
|
|
197
199
|
await pfs.copy('./path/file.txt', './dist');
|
|
198
200
|
const { mode } = await pfs.stat('./dist/path/file.txt');
|
|
199
201
|
|
|
200
|
-
console.log(
|
|
202
|
+
console.log(bitmask(mode) === 0o666); // true
|
|
201
203
|
```
|
|
202
204
|
|
|
203
205
|
#### pfs.rename(src, use[, options])
|
package/src/index.ts
CHANGED
|
@@ -1,29 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type Mode as TMode,
|
|
3
|
-
type Flag as TFlag,
|
|
4
|
-
type Stats as TStats,
|
|
5
|
-
PoweredFileSystem
|
|
6
|
-
} from './powered-file-system';
|
|
1
|
+
import { PoweredFileSystem } from './powered-file-system';
|
|
7
2
|
|
|
8
|
-
export
|
|
9
|
-
export type Flag = TFlag;
|
|
10
|
-
export type Stats = TStats;
|
|
3
|
+
export const pfs = new PoweredFileSystem();
|
|
11
4
|
|
|
12
|
-
|
|
5
|
+
export default PoweredFileSystem;
|
|
13
6
|
|
|
14
|
-
|
|
15
|
-
// export const stat = pfs.stat;
|
|
16
|
-
// export const chmod = pfs.chmod;
|
|
17
|
-
// export const chown = pfs.chown;
|
|
18
|
-
// export const symlink = pfs.symlink;
|
|
19
|
-
// export const copy = pfs.copy;
|
|
20
|
-
// export const rename = pfs.rename;
|
|
21
|
-
// export const remove = pfs.remove;
|
|
22
|
-
// export const read = pfs.read;
|
|
23
|
-
// export const write = pfs.write;
|
|
24
|
-
// export const append = pfs.append;
|
|
25
|
-
// export const readdir = pfs.readdir;
|
|
26
|
-
// export const mkdir = pfs.mkdir;
|
|
27
|
-
|
|
28
|
-
export const bitmask = PoweredFileSystem.bitmask;
|
|
29
|
-
export default PoweredFileSystem;
|
|
7
|
+
export * from './powered-file-system';
|
|
@@ -26,6 +26,26 @@ const permissions: number[] = [
|
|
|
26
26
|
0o001 // OTHERS_EXECUTE
|
|
27
27
|
];
|
|
28
28
|
|
|
29
|
+
export function bitmask(mode: number) {
|
|
30
|
+
const type = typeof mode;
|
|
31
|
+
|
|
32
|
+
if (type !== 'number') {
|
|
33
|
+
throw new Error(
|
|
34
|
+
`Argument of type '${type}' is not assignable to parameter of type 'number'.`
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let umask = 0o000;
|
|
39
|
+
|
|
40
|
+
for (const flag of permissions) {
|
|
41
|
+
if (mode & flag) {
|
|
42
|
+
umask += flag;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return umask;
|
|
47
|
+
}
|
|
48
|
+
|
|
29
49
|
export class PoweredFileSystem {
|
|
30
50
|
readonly pwd: string;
|
|
31
51
|
|
|
@@ -36,6 +56,8 @@ export class PoweredFileSystem {
|
|
|
36
56
|
x: fs.constants.X_OK
|
|
37
57
|
};
|
|
38
58
|
|
|
59
|
+
static bitmask = bitmask;
|
|
60
|
+
|
|
39
61
|
constructor(pwd?: string) {
|
|
40
62
|
this.pwd = pwd ? path.resolve(pwd) : process.cwd();
|
|
41
63
|
}
|
|
@@ -43,26 +65,6 @@ export class PoweredFileSystem {
|
|
|
43
65
|
private resolve(src: string) {
|
|
44
66
|
return path.resolve(this.pwd, src);
|
|
45
67
|
}
|
|
46
|
-
|
|
47
|
-
static bitmask(mode: number) {
|
|
48
|
-
const type = typeof mode;
|
|
49
|
-
|
|
50
|
-
if (type !== 'number') {
|
|
51
|
-
throw new Error(
|
|
52
|
-
`Argument of type '${type}' is not assignable to parameter of type 'number'.`
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
let umask = 0o000;
|
|
57
|
-
|
|
58
|
-
for (const flag of permissions) {
|
|
59
|
-
if (mode & flag) {
|
|
60
|
-
umask += flag;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return umask;
|
|
65
|
-
}
|
|
66
68
|
|
|
67
69
|
test(src: string, options: {
|
|
68
70
|
sync: true,
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import assert from 'node:assert';
|
|
2
|
-
import { sep } from 'node:path';
|
|
3
2
|
import fs from 'node:fs';
|
|
4
3
|
import Chance from 'chance';
|
|
4
|
+
import { expect } from 'expect';
|
|
5
5
|
import { fmock, restore } from './__fmock';
|
|
6
|
-
import
|
|
6
|
+
import { pfs } from '../src';
|
|
7
7
|
|
|
8
8
|
describe('append(src, data [, options])', () => {
|
|
9
|
-
const pfs = new PoweredFileSystem();
|
|
10
9
|
const chance = new Chance();
|
|
11
10
|
|
|
12
11
|
beforeEach(() => {
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import assert from 'node:assert';
|
|
2
|
-
import { sep } from 'node:path';
|
|
3
2
|
import fs from 'node:fs';
|
|
4
3
|
import Chance from 'chance';
|
|
4
|
+
import { expect } from 'expect';
|
|
5
5
|
import { fmock, restore } from './__fmock';
|
|
6
|
-
import
|
|
6
|
+
import { pfs, bitmask } from '../src';
|
|
7
7
|
|
|
8
8
|
describe('chmod(src, mode [, options])', () => {
|
|
9
|
-
const pfs = new PoweredFileSystem();
|
|
10
9
|
const chance = new Chance();
|
|
11
10
|
|
|
12
11
|
beforeEach(() => {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import assert from 'node:assert';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import Chance from 'chance';
|
|
4
|
+
import { expect } from 'expect';
|
|
4
5
|
import { fmock, restore } from './__fmock';
|
|
5
|
-
import
|
|
6
|
+
import { pfs } from '../src';
|
|
6
7
|
|
|
7
8
|
describe('chown(src, uid, gid [, options])', () => {
|
|
8
|
-
const pfs = new PoweredFileSystem();
|
|
9
9
|
const chance = new Chance();
|
|
10
10
|
|
|
11
11
|
beforeEach(() => {
|
|
@@ -25,7 +25,6 @@ describe('chown(src, uid, gid [, options])', () => {
|
|
|
25
25
|
|
|
26
26
|
it('Positive: Changes the permissions of a file', async () => {
|
|
27
27
|
const { uid, gid } = fs.statSync('./tmpdir/tings.txt');
|
|
28
|
-
|
|
29
28
|
await pfs.chown('./tmpdir/tings.txt', uid, gid);
|
|
30
29
|
|
|
31
30
|
assert(uid && gid);
|
|
@@ -34,7 +33,6 @@ describe('chown(src, uid, gid [, options])', () => {
|
|
|
34
33
|
|
|
35
34
|
it('Positive: Changes the permissions of a directory', async () => {
|
|
36
35
|
const { uid, gid } = fs.statSync('./tmpdir/digest');
|
|
37
|
-
|
|
38
36
|
await pfs.chown('./tmpdir/digest', uid, gid);
|
|
39
37
|
|
|
40
38
|
assert(uid && gid);
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import assert from 'node:assert';
|
|
2
|
-
import { sep } from 'node:path';
|
|
3
2
|
import fs from 'node:fs';
|
|
4
3
|
import Chance from 'chance';
|
|
4
|
+
import { expect } from 'expect';
|
|
5
5
|
import { fmock, restore } from './__fmock';
|
|
6
|
-
import
|
|
6
|
+
import { pfs } from '../src';
|
|
7
7
|
|
|
8
8
|
describe('copy(src, dir [, options])', () => {
|
|
9
|
-
const pfs = new PoweredFileSystem();
|
|
10
9
|
const chance = new Chance();
|
|
11
10
|
|
|
12
11
|
beforeEach(() => {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import assert from 'node:assert';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import Chance from 'chance';
|
|
4
|
+
import { expect } from 'expect';
|
|
4
5
|
import { fmock, restore } from './__fmock';
|
|
5
|
-
import PoweredFileSystem from '../src';
|
|
6
|
+
import { PoweredFileSystem } from '../src';
|
|
6
7
|
|
|
7
8
|
describe('mkdir(src [, options])', () => {
|
|
8
9
|
const pfs = new PoweredFileSystem();
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import assert from 'node:assert';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
2
|
import Chance from 'chance';
|
|
3
|
+
import { expect } from 'expect';
|
|
4
4
|
import { fmock, restore } from './__fmock';
|
|
5
|
-
import
|
|
5
|
+
import { pfs } from '../src';
|
|
6
6
|
|
|
7
7
|
describe('read(src [, options])', () => {
|
|
8
|
-
const pfs = new PoweredFileSystem();
|
|
9
8
|
const chance = new Chance();
|
|
10
9
|
let sentences = 0;
|
|
11
10
|
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import assert from 'node:assert';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
2
|
import Chance from 'chance';
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
3
|
+
import { expect } from 'expect';
|
|
4
|
+
import { Iframe, fmock, restore } from './__fmock';
|
|
5
|
+
import { pfs } from '../src';
|
|
6
6
|
|
|
7
7
|
describe('readdir(src[, options])', () => {
|
|
8
|
-
const pfs = new PoweredFileSystem();
|
|
9
8
|
const chance = new Chance();
|
|
10
9
|
let counter = 0;
|
|
11
10
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import assert from 'node:assert';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import Chance from 'chance';
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
4
|
+
import { expect } from 'expect';
|
|
5
|
+
import { Iframe, fmock, restore } from './__fmock';
|
|
6
|
+
import { pfs } from '../src';
|
|
6
7
|
|
|
7
8
|
describe('remove(src [, options])', () => {
|
|
8
|
-
const pfs = new PoweredFileSystem();
|
|
9
9
|
const chance = new Chance();
|
|
10
10
|
|
|
11
11
|
beforeEach(() => {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import assert from 'node:assert';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import Chance from 'chance';
|
|
4
|
+
import { expect } from 'expect';
|
|
4
5
|
import { fmock, restore } from './__fmock';
|
|
5
|
-
import
|
|
6
|
+
import {pfs } from '../src';
|
|
6
7
|
|
|
7
8
|
describe('rename(src, use [, options])', () => {
|
|
8
|
-
const pfs = new PoweredFileSystem();
|
|
9
9
|
const chance = new Chance();
|
|
10
10
|
|
|
11
11
|
beforeEach(() => {
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import assert from 'node:assert';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
2
|
import Chance from 'chance';
|
|
3
|
+
import { expect } from 'expect';
|
|
4
4
|
import { fmock, restore } from './__fmock';
|
|
5
|
-
import
|
|
5
|
+
import { pfs } from '../src';
|
|
6
6
|
|
|
7
7
|
describe('stat(src [, options])', () => {
|
|
8
|
-
const pfs = new PoweredFileSystem();
|
|
9
8
|
const chance = new Chance();
|
|
10
9
|
|
|
11
10
|
beforeEach(() => {
|