pwd-fs 2.4.2 → 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.
Files changed (68) hide show
  1. package/.travis.yml +2 -3
  2. package/appveyor.yml +2 -4
  3. package/lib/src/index.d.ts +4 -186
  4. package/lib/src/index.js +18 -294
  5. package/lib/src/powered-file-system.d.ts +156 -0
  6. package/lib/src/powered-file-system.js +264 -0
  7. package/lib/src/recurse-io-sync.d.ts +10 -5
  8. package/lib/src/recurse-io-sync.js +74 -69
  9. package/lib/src/recurse-io.d.ts +14 -6
  10. package/lib/src/recurse-io.js +164 -160
  11. package/lib/test/__fmock.d.ts +5 -0
  12. package/lib/test/__fmock.js +40 -0
  13. package/lib/test/append.spec.js +36 -77
  14. package/lib/test/bitmask.spec.js +14 -17
  15. package/lib/test/chmod.spec.js +42 -84
  16. package/lib/test/chown.spec.js +45 -71
  17. package/lib/test/constructor.spec.js +7 -10
  18. package/lib/test/copy.spec.js +53 -108
  19. package/lib/test/mkdir.spec.js +62 -119
  20. package/lib/test/read.spec.js +47 -78
  21. package/lib/test/readdir.spec.js +48 -90
  22. package/lib/test/remove.spec.js +44 -65
  23. package/lib/test/rename.spec.js +43 -75
  24. package/lib/test/stat.spec.js +50 -78
  25. package/lib/test/symlink.spec.js +51 -95
  26. package/lib/test/test.spec.js +37 -66
  27. package/lib/test/write.spec.js +52 -103
  28. package/package.json +8 -11
  29. package/readme.md +10 -21
  30. package/src/index.ts +4 -623
  31. package/src/powered-file-system.ts +527 -0
  32. package/src/recurse-io-sync.ts +77 -71
  33. package/src/recurse-io.ts +181 -176
  34. package/test/__fmock.ts +45 -0
  35. package/test/append.spec.ts +44 -98
  36. package/test/bitmask.spec.ts +14 -17
  37. package/test/chmod.spec.ts +45 -95
  38. package/test/chown.spec.ts +61 -93
  39. package/test/constructor.spec.ts +4 -7
  40. package/test/copy.spec.ts +72 -142
  41. package/test/mkdir.spec.ts +87 -153
  42. package/test/read.spec.ts +64 -103
  43. package/test/readdir.spec.ts +65 -113
  44. package/test/remove.spec.ts +58 -82
  45. package/test/rename.spec.ts +58 -96
  46. package/test/stat.spec.ts +68 -100
  47. package/test/symlink.spec.ts +74 -125
  48. package/test/test.spec.ts +51 -84
  49. package/test/write.spec.ts +68 -131
  50. package/tsconfig.json +14 -7
  51. package/lib/src/index.js.map +0 -1
  52. package/lib/src/recurse-io-sync.js.map +0 -1
  53. package/lib/src/recurse-io.js.map +0 -1
  54. package/lib/test/append.spec.js.map +0 -1
  55. package/lib/test/bitmask.spec.js.map +0 -1
  56. package/lib/test/chmod.spec.js.map +0 -1
  57. package/lib/test/chown.spec.js.map +0 -1
  58. package/lib/test/constructor.spec.js.map +0 -1
  59. package/lib/test/copy.spec.js.map +0 -1
  60. package/lib/test/mkdir.spec.js.map +0 -1
  61. package/lib/test/read.spec.js.map +0 -1
  62. package/lib/test/readdir.spec.js.map +0 -1
  63. package/lib/test/remove.spec.js.map +0 -1
  64. package/lib/test/rename.spec.js.map +0 -1
  65. package/lib/test/stat.spec.js.map +0 -1
  66. package/lib/test/symlink.spec.js.map +0 -1
  67. package/lib/test/test.spec.js.map +0 -1
  68. package/lib/test/write.spec.js.map +0 -1
@@ -1,127 +1,77 @@
1
- import assert from 'assert';
2
- import { sep } from 'path';
3
- import mockFs from 'mock-fs';
1
+ import assert from 'node:assert';
2
+ import fs from 'node:fs';
4
3
  import Chance from 'chance';
5
- import PoweredFileSystem from '../src';
4
+ import { expect } from 'expect';
5
+ import { fmock, restore } from './__fmock';
6
+ import { pfs, bitmask } from '../src';
6
7
 
7
8
  describe('chmod(src, mode [, options])', () => {
8
- beforeEach(() => {
9
- const chance = new Chance();
9
+ const chance = new Chance();
10
10
 
11
- mockFs({
12
- 'tmpdir': {
13
- 'binapp': chance.string(),
14
- 'libxbase': mockFs.directory()
15
- },
16
- 'flexapp': mockFs.symlink({
17
- path: 'tmpdir/binapp'
18
- })
11
+ beforeEach(() => {
12
+ fmock({
13
+ './tmpdir/tings.txt': {
14
+ type: 'file',
15
+ data: chance.string()
16
+ }
19
17
  });
20
18
  });
19
+
20
+ afterEach(() => {
21
+ restore('./tmpdir');
22
+ });
21
23
 
22
- afterEach(mockFs.restore);
23
24
 
24
25
  it('Positive: Changes directory and file permissions', async () => {
25
- const pfs = new PoweredFileSystem();
26
-
27
26
  await pfs.chmod('./tmpdir', 0o744);
28
27
 
29
- const { mode } = await pfs.stat('./tmpdir/binapp');
30
- const umask = PoweredFileSystem.bitmask(mode);
28
+ const { mode } = fs.lstatSync('./tmpdir/tings.txt');
29
+ const umask = bitmask(mode);
31
30
 
32
31
  assert(umask === 0o744);
33
32
  });
34
33
 
35
- it('Positive: Must be changes directory when path is absolute', async () => {
36
- const pfs = new PoweredFileSystem();
37
34
 
38
- const cwd = process.cwd();
39
- await pfs.chmod(`${cwd}${sep}tmpdir${sep}libxbase` , 0o744, {
40
- resolve: false
35
+ it('Negative: Throw if not exists resource', async () => {
36
+ await expect(async () => {
37
+ await pfs.chmod('./non-existent-source', 0o744);
38
+ })
39
+ .rejects
40
+ .toThrow();
41
+ });
42
+
43
+
44
+ it(`[sync] Positive: Changes permissions of directory`, () => {
45
+ pfs.chmod('./tmpdir', 0o744, {
46
+ sync: true
41
47
  });
42
48
 
43
- const { mode } = await pfs.stat('./tmpdir/libxbase');
44
- const umask = PoweredFileSystem.bitmask(mode);
49
+ const { mode } = fs.lstatSync('./tmpdir');
50
+ const umask = bitmask(mode);
45
51
 
46
52
  assert(umask === 0o744);
47
53
  });
48
54
 
49
- it('Negative: Search permission is denied on a component of the path prefix', async () => {
50
- const pfs = new PoweredFileSystem();
51
55
 
52
- try {
53
- await pfs.chmod('./tmpdir', 0);
54
- }
55
- catch (err) {
56
- assert(err.errno === -9);
57
- }
58
- });
56
+ it(`[sync] Positive: Changes file permissions`, () => {
57
+ pfs.chmod('./tmpdir', 0o744, {
58
+ sync: true
59
+ });
59
60
 
60
- it('Negative: Throw if not exists resource', async () => {
61
- const pfs = new PoweredFileSystem();
61
+ const { mode } = fs.lstatSync('./tmpdir/tings.txt');
62
+ const umask = bitmask(mode);
62
63
 
63
- try {
64
- await pfs.chmod('./non-existent-source', 0o744);
65
- }
66
- catch (err) {
67
- assert(err.errno === -2);
68
- }
64
+ assert(umask === 0o744);
69
65
  });
66
+
67
+
68
+ it('[sync] Negative: Throw if not exists resource', () => {
69
+ const guid = chance.guid();
70
70
 
71
- describe('sync mode', () => {
72
- it(`Positive: Changes directory and file permissions`, async () => {
73
- const pfs = new PoweredFileSystem();
74
-
75
- pfs.chmod('./tmpdir', 0o744, {
71
+ assert.throws(() => {
72
+ pfs.chmod(`./${guid}`, 0o744, {
76
73
  sync: true
77
74
  });
78
-
79
- const { mode } = await pfs.stat('./tmpdir/binapp');
80
- const umask = PoweredFileSystem.bitmask(mode);
81
-
82
- assert(umask === 0o744);
83
- });
84
-
85
- it('Positive: Must be changes directory when path is absolute', async () => {
86
- const pfs = new PoweredFileSystem();
87
-
88
- const cwd = process.cwd();
89
-
90
- pfs.chmod(`${cwd}${sep}tmpdir${sep}libxbase` , 0o744, {
91
- sync: true,
92
- resolve: false
93
- });
94
-
95
- const { mode } = await pfs.stat('./tmpdir/libxbase');
96
- const umask = PoweredFileSystem.bitmask(mode);
97
-
98
- assert(umask === 0o744);
99
- });
100
-
101
- it('Negative: Search permission is denied on a component of the path prefix', async () => {
102
- const pfs = new PoweredFileSystem();
103
-
104
- try {
105
- pfs.chmod('./tmpdir', 0, {
106
- sync: true
107
- });
108
- }
109
- catch (err) {
110
- assert(err.errno === -9);
111
- }
112
- });
113
-
114
- it('Negative: Throw if not exists resource', async () => {
115
- const pfs = new PoweredFileSystem();
116
-
117
- try {
118
- pfs.chmod('./non-existent-source', 0o744, {
119
- sync: true
120
- });
121
- }
122
- catch (err) {
123
- assert(err.errno === -2);
124
- }
125
75
  });
126
76
  });
127
77
  });
@@ -1,118 +1,86 @@
1
- import assert from 'assert';
2
- import { sep } from 'path';
3
- import mockFs from 'mock-fs';
1
+ import assert from 'node:assert';
2
+ import fs from 'node:fs';
4
3
  import Chance from 'chance';
5
- import PoweredFileSystem from '../src';
4
+ import { expect } from 'expect';
5
+ import { fmock, restore } from './__fmock';
6
+ import { pfs } from '../src';
6
7
 
7
8
  describe('chown(src, uid, gid [, options])', () => {
8
- beforeEach(() => {
9
- const chance = new Chance();
9
+ const chance = new Chance();
10
10
 
11
- mockFs({
12
- 'tmpdir': {
13
- 'binapp': chance.string(),
14
- 'libxbase': mockFs.directory()
11
+ beforeEach(() => {
12
+ fmock({
13
+ './tmpdir/tings.txt': {
14
+ type: 'file',
15
+ data: chance.string()
15
16
  },
16
- 'flexapp': mockFs.symlink({
17
- path: 'tmpdir/binapp'
18
- })
17
+ './tmpdir/digest/': { type: 'directory' }
19
18
  });
20
19
  });
21
-
22
- afterEach(mockFs.restore);
23
-
20
+
21
+ afterEach(() => {
22
+ restore('./tmpdir');
23
+ });
24
+
25
+
24
26
  it('Positive: Changes the permissions of a file', async () => {
25
- const pfs = new PoweredFileSystem();
27
+ const { uid, gid } = fs.statSync('./tmpdir/tings.txt');
28
+ await pfs.chown('./tmpdir/tings.txt', uid, gid);
26
29
 
27
- await pfs.chown('./tmpdir', 0, 0);
28
- const { uid, gid } = await pfs.stat('./tmpdir');
29
-
30
- assert(uid === 0 && gid === 0);
30
+ assert(uid && gid);
31
31
  });
32
-
32
+
33
+
33
34
  it('Positive: Changes the permissions of a directory', async () => {
34
- const pfs = new PoweredFileSystem();
35
+ const { uid, gid } = fs.statSync('./tmpdir/digest');
36
+ await pfs.chown('./tmpdir/digest', uid, gid);
35
37
 
36
- await pfs.chown('./tmpdir/libxbase', 0, 0);
37
- const { uid, gid } = await pfs.stat('./tmpdir/libxbase');
38
-
39
- assert(uid === 0 && gid === 0);
38
+ assert(uid && gid);
40
39
  });
41
-
42
- it('Positive: Changes the permissions of a file, when path is absolute', async () => {
43
- const pfs = new PoweredFileSystem();
44
-
45
- const cwd = process.cwd();
46
- await pfs.chown(`${cwd}${sep}tmpdir${sep}binapp`, 1, 1, {
47
- resolve: false
48
- });
49
-
50
- const { uid, gid } = await pfs.stat('./tmpdir/binapp');
51
-
52
- assert(uid === 1 && gid === 1);
53
- });
54
-
40
+
41
+
55
42
  it('Negative: To a non-existent resource to return an Error', async () => {
56
- const pfs = new PoweredFileSystem();
57
-
58
- try {
59
- await pfs.chown('./non-existent-source', 1, 1);
60
- }
61
- catch (err) {
62
- assert(err.errno === -2);
63
- }
43
+ const guid = chance.guid();
44
+ const { uid, gid } = fs.statSync('./tmpdir/tings.txt');
45
+
46
+ await expect(async () => {
47
+ await pfs.chown(`./tmpdir/${guid}`, uid, gid);
48
+ })
49
+ .rejects
50
+ .toThrow();
64
51
  });
52
+
53
+
54
+ it('[sync] Positive: Changes the permissions of a file', () => {
55
+ const { uid, gid } = fs.statSync('./tmpdir/tings.txt');
65
56
 
66
- describe('sync mode', () => {
67
- it('Positive: Changes the permissions of a file', async () => {
68
- const pfs = new PoweredFileSystem();
69
-
70
- pfs.chown('./tmpdir/binapp', 1, 1, {
71
- sync: true
72
- });
73
-
74
- const { uid, gid } = await pfs.stat('./tmpdir/binapp');
75
-
76
- assert(uid === 1 && gid === 1);
57
+ pfs.chown('./tmpdir/tings.txt', uid, gid, {
58
+ sync: true
77
59
  });
78
60
 
79
- it('Positive: Changes the permissions of a directory', async () => {
80
- const pfs = new PoweredFileSystem();
81
-
82
- pfs.chown('./tmpdir', 1, 1, {
83
- sync: true
84
- });
85
-
86
- const { uid, gid } = await pfs.stat('./tmpdir');
61
+ assert(uid && gid);
62
+ });
63
+
64
+
65
+ it('[sync] Positive: Changes the permissions of a directory', () => {
66
+ const { uid, gid } = fs.statSync('./tmpdir/digest');
87
67
 
88
- assert(uid === 1 && gid === 1);
68
+ pfs.chown('./tmpdir/digest', uid, gid, {
69
+ sync: true
89
70
  });
90
71
 
91
- it('Positive: Changes the permissions of a file, when path is absolute', async () => {
92
- const pfs = new PoweredFileSystem();
93
-
94
- const cwd = process.cwd();
95
- pfs.chown(`${cwd}${sep}tmpdir${sep}binapp`, 1, 1, {
96
- sync: true,
97
- resolve: false
72
+ assert(uid && gid);
73
+ });
74
+
75
+
76
+ it('[sync] Negative: To a non-existent resource to return an Error', () => {
77
+ const guid = chance.guid();
78
+ const { uid, gid } = fs.statSync('./tmpdir/tings.txt');
79
+
80
+ assert.throws(() => {
81
+ pfs.chown(`./tmpdir/${guid}`, uid, gid, {
82
+ sync: true
98
83
  });
99
-
100
- const { uid, gid } = await pfs.stat('./tmpdir/binapp');
101
-
102
- assert(uid === 1 && gid === 1);
103
- });
104
-
105
- it(`Negative: To a non-existent resource to return an Error`, async () => {
106
- const pfs = new PoweredFileSystem();
107
-
108
- try {
109
- pfs.chown('./non-existent-source', 1, 1, {
110
- sync: true
111
- });
112
- }
113
- catch (err) {
114
- assert(err.errno === -2);
115
- }
116
84
  });
117
85
  });
118
86
  });
@@ -1,16 +1,13 @@
1
- import assert from 'assert';
2
- import PoweredFileSystem from '../src';
3
-
4
- describe('#constructor: new PoweredFileSystem(path)', () => {
5
- it('Positive: Must be backwards compatible with #require', () => {
6
- assert(require('../src') === PoweredFileSystem);
7
- });
1
+ import assert from 'node:assert';
2
+ import { PoweredFileSystem } from '../src';
8
3
 
4
+ describe('#constructor: new PoweredFileSystem(pwd?)', () => {
9
5
  it('Positive: An empty path must match the context of the cwd', () => {
10
6
  const { pwd } = new PoweredFileSystem();
11
7
  assert(pwd === process.cwd());
12
8
  });
13
9
 
10
+
14
11
  it('Positive: Absolute path must match the context of the pwd', () => {
15
12
  const { pwd } = new PoweredFileSystem(__dirname);
16
13
  assert(pwd === __dirname);
package/test/copy.spec.ts CHANGED
@@ -1,171 +1,101 @@
1
- import assert from 'assert';
2
- import os from 'os';
3
- import { sep } from 'path';
4
- import mockFs from 'mock-fs';
1
+ import assert from 'node:assert';
2
+ import fs from 'node:fs';
5
3
  import Chance from 'chance';
6
- import PoweredFileSystem from '../src';
4
+ import { expect } from 'expect';
5
+ import { fmock, restore } from './__fmock';
6
+ import { pfs } from '../src';
7
7
 
8
8
  describe('copy(src, dir [, options])', () => {
9
+ const chance = new Chance();
10
+
9
11
  beforeEach(() => {
10
- const chance = new Chance();
11
-
12
- mockFs({
13
- 'tmpdir': {
14
- 'binapp': chance.string(),
15
- 'libxbase': mockFs.directory()
12
+ fmock({
13
+ './tmpdir/tings.txt': {
14
+ type: 'file',
15
+ data: chance.string()
16
16
  },
17
- 'flexapp': mockFs.symlink({
18
- path: 'tmpdir/binapp'
19
- })
17
+ './tmpdir/digest/': { type: 'directory' }
20
18
  });
21
19
  });
22
-
23
- afterEach(mockFs.restore);
20
+
21
+ afterEach(() => {
22
+ restore('./tmpdir');
23
+ });
24
24
 
25
25
  it('Positive: Copying a item file', async () => {
26
- const pfs = new PoweredFileSystem();
27
-
28
- const dist = os.tmpdir();
29
- await pfs.copy('./tmpdir/binapp', dist);
30
-
31
- const { mode } = await pfs.stat(`${dist}/binapp`);
32
- const umask = PoweredFileSystem.bitmask(mode);
33
-
34
- assert(umask === 0o666);
26
+ await pfs.copy('./tmpdir/tings.txt', './tmpdir/digest');
27
+ const exist = fs.existsSync(`./tmpdir/digest/tings.txt`);
28
+
29
+ assert(exist);
35
30
  });
31
+
36
32
 
37
33
  it('Positive: Recursive copying a directory', async () => {
38
- const pfs = new PoweredFileSystem();
39
-
40
- const dist = os.tmpdir();
41
- await pfs.copy('./tmpdir', dist);
42
-
43
- const { mode } = await pfs.stat(`${dist}/tmpdir/libxbase`);
44
- const umask = PoweredFileSystem.bitmask(mode);
45
-
46
- assert(umask === 0o777);
47
- });
48
-
49
- it('Positive: Recursive copying a directory. Permission check of file', async () => {
50
- const pfs = new PoweredFileSystem();
51
-
52
- const dist = os.tmpdir();
53
- await pfs.copy('./tmpdir', dist);
54
-
55
- const { mode } = await pfs.stat(`${dist}/tmpdir/binapp`);
56
- const umask = PoweredFileSystem.bitmask(mode);
57
-
58
- assert(umask === 0o666);
59
- });
60
-
61
- it('Positive: Copying a item file when path is absolute', async () => {
62
- const pfs = new PoweredFileSystem();
63
-
64
- const cwd = process.cwd();
65
- const dist = os.tmpdir();
66
-
67
- await pfs.copy(`${cwd}${sep}tmpdir`, dist, {
68
- resolve: false
69
- });
70
-
71
- const { mode } = await pfs.stat(`${dist}/tmpdir/binapp`);
72
- const umask = PoweredFileSystem.bitmask(mode);
73
-
74
- assert(umask === 0o666);
34
+ await pfs.copy('./src', './tmpdir');
35
+ const exist = fs.existsSync(`./tmpdir/src`);
36
+
37
+ assert(exist);
75
38
  });
76
39
 
40
+
77
41
  it('Negative: Throw if not exists resource', async () => {
78
- const pfs = new PoweredFileSystem();
79
-
80
- try {
81
- await pfs.copy('./non-existent', '.');
82
- }
83
- catch (err) {
84
- assert(err.errno === -2);
85
- }
42
+ const guid = chance.guid();
43
+
44
+ await expect(async () => {
45
+ await pfs.copy(`./${guid}`, '.');
46
+ })
47
+ .rejects
48
+ .toThrow();
86
49
  });
87
-
50
+
51
+
88
52
  it('Negative: An attempt to copy to an existing resource should return an Error', async () => {
89
- const pfs = new PoweredFileSystem();
90
-
91
- try {
53
+ await expect(async () => {
92
54
  await pfs.copy('./tmpdir', '.');
93
- }
94
- catch (err) {
95
- assert(err.errno === -17);
96
- }
55
+ })
56
+ .rejects
57
+ .toThrow();
97
58
  });
59
+
60
+
61
+ it('[sync] Positive: Copying a file', () => {
62
+ pfs.copy('./tmpdir/tings.txt', './tmpdir/digest', {
63
+ sync: true
64
+ });
98
65
 
99
- describe('sync mode', () => {
100
- it('Positive: Copying a file', async () => {
101
- const pfs = new PoweredFileSystem();
102
- const dist = os.tmpdir();
103
-
104
- pfs.copy('./tmpdir/binapp', dist, {
105
- sync: true
106
- });
107
-
108
- const { mode } = await pfs.stat(`${dist}/binapp`);
109
- const umask = PoweredFileSystem.bitmask(mode);
110
-
111
- assert(umask === 0o666);
66
+ const exist = fs.existsSync(`./tmpdir/digest/tings.txt`);
67
+
68
+ assert(exist);
69
+ });
70
+
71
+
72
+ it('[sync] Positive: Recursive copying a directory', () => {
73
+ pfs.copy('./src', './tmpdir', {
74
+ sync: true
112
75
  });
113
76
 
114
- it('Positive: Recursive copying a directory', async () => {
115
- const pfs = new PoweredFileSystem();
116
- const dist = os.tmpdir();
77
+ const exist = fs.existsSync(`./tmpdir/src`);
78
+
79
+ assert(exist);
80
+ });
81
+
82
+
83
+ it('[sync] Negative: Throw if not exists resource', () => {
84
+ const guid = chance.guid();
117
85
 
118
- pfs.copy('./tmpdir', dist, {
86
+ assert.throws(() => {
87
+ pfs.copy(`./${guid}`, '.', {
119
88
  sync: true
120
89
  });
121
-
122
- const { mode } = await pfs.stat(`${dist}/tmpdir/libxbase`);
123
- const umask = PoweredFileSystem.bitmask(mode);
124
-
125
- assert(umask === 0o777);
126
90
  });
127
-
128
- it('Positive: Copying a item file when path is absolute', async () => {
129
- const pfs = new PoweredFileSystem();
130
-
131
- const cwd = process.cwd();
132
- const dist = os.tmpdir();
133
-
134
- pfs.copy(`${cwd}${sep}tmpdir`, dist, {
135
- sync: true,
136
- resolve: false
91
+ });
92
+
93
+
94
+ it('[sync] Negative: An attempt to copy to an existing resource should return an Error', () => {
95
+ assert.throws(() => {
96
+ pfs.copy('./tmpdir', '.', {
97
+ sync: true
137
98
  });
138
-
139
- const { mode } = await pfs.stat(`${dist}/tmpdir/binapp`);
140
- const umask = PoweredFileSystem.bitmask(mode);
141
-
142
- assert(umask === 0o666);
143
- });
144
-
145
- it('Negative: Throw if not exists resource', async () => {
146
- const pfs = new PoweredFileSystem();
147
-
148
- try {
149
- pfs.copy('./non-existent', '.', {
150
- sync: true
151
- });
152
- }
153
- catch (err) {
154
- assert(err.errno === -2);
155
- }
156
- });
157
-
158
- it('Negative: An attempt to copy to an existing resource should return an Error', async () => {
159
- const pfs = new PoweredFileSystem();
160
-
161
- try {
162
- pfs.copy('./tmpdir', '.', {
163
- sync: true
164
- });
165
- }
166
- catch (err) {
167
- assert(err.errno === -17);
168
- }
169
99
  });
170
100
  });
171
- });
101
+ });