pwd-fs 3.1.4 → 3.2.1

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 (52) hide show
  1. package/dist/src/bitmask.d.ts +1 -0
  2. package/dist/src/bitmask.js +18 -0
  3. package/{lib → dist}/src/powered-file-system.d.ts +20 -3
  4. package/{lib → dist}/src/powered-file-system.js +39 -41
  5. package/dist/src/recurse-io-sync.d.ts +5 -0
  6. package/{lib → dist}/src/recurse-io-sync.js +28 -23
  7. package/dist/src/recurse-io.d.ts +7 -0
  8. package/{lib → dist}/src/recurse-io.js +15 -10
  9. package/package.json +5 -5
  10. package/readme.md +4 -4
  11. package/src/bitmask.ts +20 -0
  12. package/src/powered-file-system.ts +48 -52
  13. package/src/recurse-io-sync.ts +24 -24
  14. package/src/recurse-io.ts +18 -19
  15. package/test/chown.spec.ts +16 -10
  16. package/tsconfig.json +2 -2
  17. package/lib/src/recurse-io-sync.d.ts +0 -13
  18. package/lib/src/recurse-io.d.ts +0 -17
  19. package/lib/test/__fmock.d.ts +0 -5
  20. package/lib/test/__fmock.js +0 -40
  21. package/lib/test/append.spec.d.ts +0 -1
  22. package/lib/test/append.spec.js +0 -58
  23. package/lib/test/bitmask.spec.d.ts +0 -1
  24. package/lib/test/bitmask.spec.js +0 -26
  25. package/lib/test/chmod.spec.d.ts +0 -1
  26. package/lib/test/chmod.spec.js +0 -62
  27. package/lib/test/chown.spec.d.ts +0 -1
  28. package/lib/test/chown.spec.js +0 -68
  29. package/lib/test/constructor.spec.d.ts +0 -1
  30. package/lib/test/constructor.spec.js +0 -17
  31. package/lib/test/copy.spec.d.ts +0 -1
  32. package/lib/test/copy.spec.js +0 -80
  33. package/lib/test/mkdir.spec.d.ts +0 -1
  34. package/lib/test/mkdir.spec.js +0 -90
  35. package/lib/test/read.spec.d.ts +0 -1
  36. package/lib/test/read.spec.js +0 -73
  37. package/lib/test/readdir.spec.d.ts +0 -1
  38. package/lib/test/readdir.spec.js +0 -70
  39. package/lib/test/remove.spec.d.ts +0 -1
  40. package/lib/test/remove.spec.js +0 -63
  41. package/lib/test/rename.spec.d.ts +0 -1
  42. package/lib/test/rename.spec.js +0 -66
  43. package/lib/test/stat.spec.d.ts +0 -1
  44. package/lib/test/stat.spec.js +0 -76
  45. package/lib/test/symlink.spec.d.ts +0 -1
  46. package/lib/test/symlink.spec.js +0 -74
  47. package/lib/test/test.spec.d.ts +0 -1
  48. package/lib/test/test.spec.js +0 -60
  49. package/lib/test/write.spec.d.ts +0 -1
  50. package/lib/test/write.spec.js +0 -82
  51. /package/{lib → dist}/src/index.d.ts +0 -0
  52. /package/{lib → dist}/src/index.js +0 -0
@@ -1,12 +1,15 @@
1
- import fs from 'node:fs';
1
+ import fs, { NoParamCallback } from 'node:fs';
2
2
  import path from 'node:path';
3
- import recurse, { Files, NoParamCallback } from './recurse-io';
4
- import recurseSync from './recurse-io-sync';
3
+ import { chmod, chown, copy, remove, mkdir } from './recurse-io';
4
+ import { chmodSync, chownSync, copySync, removeSync, mkdirSync } from './recurse-io-sync';
5
+ import { bitmask } from './bitmask';
5
6
 
6
7
  export type Mode = keyof IConstants;
7
8
  export type Flag = Mode | 'a';
8
9
  export type Stats = fs.Stats;
9
10
 
11
+ export * from './bitmask';
12
+
10
13
  export interface IConstants {
11
14
  e: number,
12
15
  r: number,
@@ -14,38 +17,6 @@ export interface IConstants {
14
17
  x: number
15
18
  }
16
19
 
17
- const permissions: number[] = [
18
- 0o400, // OWNER_READ
19
- 0o200, // OWNER_WRITE
20
- 0o100, // OWNER_EXECUTE
21
- 0o040, // GROUP_READ
22
- 0o020, // GROUP_WRITE
23
- 0o010, // GROUP_EXECUTE
24
- 0o004, // OTHERS_READ
25
- 0o002, // OTHERS_WRITE
26
- 0o001 // OTHERS_EXECUTE
27
- ];
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
-
49
20
  export class PoweredFileSystem {
50
21
  readonly pwd: string;
51
22
 
@@ -133,11 +104,11 @@ export class PoweredFileSystem {
133
104
  src = this.resolve(src);
134
105
 
135
106
  if (sync) {
136
- return recurseSync.chmod(src, mode);
107
+ return chmodSync(src, mode);
137
108
  }
138
109
 
139
110
  return new Promise<void>((resolve, reject) => {
140
- recurse.chmod(src, mode, (err) => {
111
+ chmod(src, mode, (err) => {
141
112
  if (err) {
142
113
  return reject(err);
143
114
  }
@@ -147,23 +118,27 @@ export class PoweredFileSystem {
147
118
  });
148
119
  }
149
120
 
150
- chown(src: string, uid: number, gid: number, options: {
151
- sync: true
121
+ chown(src: string, options: {
122
+ sync: true,
123
+ uid?: number,
124
+ gid?: number
152
125
  }): void;
153
126
 
154
- chown(src: string, uid: number, gid: number, options?: {
155
- sync?: false
127
+ chown(src: string, options?: {
128
+ sync?: false,
129
+ uid?: number,
130
+ gid?: number
156
131
  }): Promise<void>;
157
132
 
158
- chown(src: string, uid: number, gid: number, { sync = false }: { sync?: boolean } = {}) {
133
+ chown(src: string, { sync = false, uid = 0, gid = 0 }: { sync?: boolean, uid?: number, gid?: number } = {}) {
159
134
  src = this.resolve(src);
160
135
 
161
136
  if (sync) {
162
- return recurseSync.chown(src, uid, gid);
137
+ return chownSync(src, uid, gid);
163
138
  }
164
139
 
165
140
  return new Promise<void>((resolve, reject) => {
166
- recurse.chown(src, uid, gid, (err) => {
141
+ chown(src, uid, gid, (err) => {
167
142
  if (err) {
168
143
  return reject(err);
169
144
  }
@@ -218,11 +193,11 @@ export class PoweredFileSystem {
218
193
  dir = this.resolve(dir);
219
194
 
220
195
  if (sync) {
221
- return recurseSync.copy(src, dir, umask);
196
+ return copySync(src, dir, umask);
222
197
  }
223
198
 
224
199
  return new Promise<void>((resolve, reject) => {
225
- recurse.copy(src, dir, umask, (err) => {
200
+ copy(src, dir, umask, (err) => {
226
201
  if (err) {
227
202
  return reject(err);
228
203
  }
@@ -271,17 +246,23 @@ export class PoweredFileSystem {
271
246
  src = this.resolve(src);
272
247
 
273
248
  if (sync) {
274
- return recurseSync.remove(src);
249
+ removeSync(src);
275
250
  }
276
251
 
277
252
  return new Promise<void>((resolve, reject) => {
278
- recurse.remove(src, (err) => {
253
+ const callback: NoParamCallback = (err) => {
279
254
  if (err) {
280
255
  return reject(err);
281
256
  }
282
257
 
283
258
  resolve();
284
- });
259
+ };
260
+
261
+ if ('rm' in fs) {
262
+ return fs.rm(src, { recursive: true }, callback);
263
+ }
264
+
265
+ remove(src, callback);
285
266
  });
286
267
  }
287
268
 
@@ -400,6 +381,9 @@ export class PoweredFileSystem {
400
381
  });
401
382
  }
402
383
 
384
+ /**
385
+ * @deprecated The method should not be used
386
+ */
403
387
  append(src: string, data: Buffer, options: {
404
388
  sync: true,
405
389
  encoding: null,
@@ -407,6 +391,9 @@ export class PoweredFileSystem {
407
391
  flag?: Flag
408
392
  }): void;
409
393
 
394
+ /**
395
+ * @deprecated The method should not be used
396
+ */
410
397
  append(src: string, data: string, options: {
411
398
  sync: true,
412
399
  encoding?: BufferEncoding,
@@ -414,6 +401,9 @@ export class PoweredFileSystem {
414
401
  flag?: Flag
415
402
  }): void;
416
403
 
404
+ /**
405
+ * @deprecated The method should not be used
406
+ */
417
407
  append(src: string, data: Buffer, options: {
418
408
  sync?: false,
419
409
  encoding: null,
@@ -421,6 +411,9 @@ export class PoweredFileSystem {
421
411
  flag?: Flag
422
412
  }): Promise<void>;
423
413
 
414
+ /**
415
+ * @deprecated The method should not be used
416
+ */
424
417
  append(src: string, data: string, options?: {
425
418
  sync?: false,
426
419
  encoding?: BufferEncoding,
@@ -428,6 +421,9 @@ export class PoweredFileSystem {
428
421
  flag?: Flag
429
422
  }): Promise<void>;
430
423
 
424
+ /**
425
+ * @deprecated The method should not be used
426
+ */
431
427
  append(src: string, data: Buffer | string, { sync = false, encoding = 'utf8', umask = 0o000, flag = 'a' }: {
432
428
  sync?: boolean,
433
429
  encoding?: BufferEncoding | null,
@@ -511,11 +507,11 @@ export class PoweredFileSystem {
511
507
  dir = this.resolve(dir);
512
508
 
513
509
  if (sync) {
514
- return recurseSync.mkdir(dir, umask);
510
+ return mkdirSync(dir, umask);
515
511
  }
516
512
 
517
513
  return new Promise<void>((resolve, reject) => {
518
- recurse.mkdir(dir, umask, (err) => {
514
+ mkdir(dir, umask, (err) => {
519
515
  if (err) {
520
516
  return reject(err);
521
517
  }
@@ -524,4 +520,4 @@ export class PoweredFileSystem {
524
520
  });
525
521
  });
526
522
  }
527
- }
523
+ }
@@ -3,35 +3,43 @@ import path from 'node:path';
3
3
 
4
4
  const { sep } = path;
5
5
 
6
- function chmod(src: string, mode: number) {
7
- const stat = fs.statSync(src);
6
+ export function chmodSync(src: string, mode: number) {
7
+ const stats = fs.statSync(src);
8
8
 
9
- if (stat.isDirectory()) {
9
+ if (stats.isDirectory()) {
10
10
  const list = fs.readdirSync(src);
11
11
 
12
12
  for (const loc of list) {
13
- chmod(`${src}${sep}${loc}`, mode);
13
+ chmodSync(`${src}${sep}${loc}`, mode);
14
14
  }
15
15
  }
16
16
 
17
17
  fs.chmodSync(src, mode);
18
18
  }
19
19
 
20
- function chown(src: string, uid: number, gid: number) {
21
- const stat = fs.statSync(src);
20
+ export function chownSync(src: string, uid: number, gid: number) {
21
+ const stats = fs.statSync(src);
22
22
 
23
- if (stat.isDirectory()) {
23
+ if (uid === 0) {
24
+ uid = stats.uid;
25
+ }
26
+
27
+ if (gid === 0) {
28
+ gid = stats.gid;
29
+ }
30
+
31
+ if (stats.isDirectory()) {
24
32
  const list = fs.readdirSync(src);
25
33
 
26
34
  for (const loc of list) {
27
- chown(`${src}${sep}${loc}`, uid, gid);
35
+ chownSync(`${src}${sep}${loc}`, uid, gid);
28
36
  }
29
37
  }
30
38
 
31
39
  fs.chownSync(src, uid, gid);
32
40
  }
33
41
 
34
- function copy(src: string, dir: string, umask: number) {
42
+ export function copySync(src: string, dir: string, umask: number) {
35
43
  const stat = fs.statSync(src);
36
44
 
37
45
  if (stat.isDirectory()) {
@@ -45,7 +53,7 @@ function copy(src: string, dir: string, umask: number) {
45
53
  fs.mkdirSync(dir, mode);
46
54
 
47
55
  for (const loc of list) {
48
- copy(`${src}${sep}${loc}`, dir, umask);
56
+ copySync(`${src}${sep}${loc}`, dir, umask);
49
57
  }
50
58
  }
51
59
  else {
@@ -56,14 +64,14 @@ function copy(src: string, dir: string, umask: number) {
56
64
  }
57
65
  }
58
66
 
59
- function remove(src: string) {
60
- const stat = fs.statSync(src);
67
+ export function removeSync(src: string) {
68
+ const stats = fs.statSync(src);
61
69
 
62
- if (stat.isDirectory()) {
70
+ if (stats.isDirectory()) {
63
71
  const list = fs.readdirSync(src);
64
72
 
65
73
  for (const loc of list) {
66
- remove(`${src}${sep}${loc}`);
74
+ removeSync(`${src}${sep}${loc}`);
67
75
  }
68
76
 
69
77
  fs.rmdirSync(src);
@@ -73,14 +81,14 @@ function remove(src: string) {
73
81
  }
74
82
  }
75
83
 
76
- function mkdir(dir: string, umask: number) {
84
+ export function mkdirSync(dir: string, umask: number) {
77
85
  const mode = 0o777 - umask;
78
86
  const cwd = process.cwd();
79
87
  let use = '';
80
88
 
81
89
  if (dir.indexOf(cwd) === 0) {
82
90
  use = cwd;
83
- dir = dir.substr(cwd.length);
91
+ dir = dir.substring(cwd.length);
84
92
  }
85
93
 
86
94
  const ways = dir.split(sep).slice(1);
@@ -98,11 +106,3 @@ function mkdir(dir: string, umask: number) {
98
106
  }
99
107
  }
100
108
  }
101
-
102
- export default {
103
- chmod,
104
- chown,
105
- copy,
106
- remove,
107
- mkdir
108
- }
package/src/recurse-io.ts CHANGED
@@ -1,20 +1,19 @@
1
- import fs from 'node:fs';
1
+ import fs, { NoParamCallback } from 'node:fs';
2
2
  import path from 'node:path';
3
3
 
4
- export type Files = Array<string>;
5
- export type NoParamCallback = fs.NoParamCallback;
4
+ type Files = Array<string>;
6
5
 
7
6
  const { sep } = path;
8
7
 
9
- function chmod(src: string, mode: number, callback: NoParamCallback) {
8
+ export function chmod(src: string, mode: number, callback: NoParamCallback) {
10
9
  let reduce = 0;
11
10
 
12
- fs.stat(src, (err, stat) => {
11
+ fs.stat(src, (err, stats) => {
13
12
  if (err) {
14
13
  return callback(err);
15
14
  }
16
15
 
17
- if (stat.isDirectory()) {
16
+ if (stats.isDirectory()) {
18
17
  fs.readdir(src, (err, list) => {
19
18
  if (err) {
20
19
  return callback(err);
@@ -45,7 +44,7 @@ function chmod(src: string, mode: number, callback: NoParamCallback) {
45
44
  });
46
45
  }
47
46
 
48
- function chown(src: string, uid: number, gid: number, callback: NoParamCallback) {
47
+ export function chown(src: string, uid: number, gid: number, callback: NoParamCallback) {
49
48
  let reduce = 0;
50
49
 
51
50
  fs.stat(src, (err, stats) => {
@@ -53,6 +52,14 @@ function chown(src: string, uid: number, gid: number, callback: NoParamCallback)
53
52
  return callback(err);
54
53
  }
55
54
 
55
+ if (uid === 0) {
56
+ uid = stats.uid;
57
+ }
58
+
59
+ if (gid === 0) {
60
+ gid = stats.gid;
61
+ }
62
+
56
63
  if (stats.isDirectory()) {
57
64
  fs.readdir(src, (err, list) => {
58
65
  if (err) {
@@ -84,7 +91,7 @@ function chown(src: string, uid: number, gid: number, callback: NoParamCallback)
84
91
  });
85
92
  }
86
93
 
87
- function copy(src: string, dir: string, umask: number, callback: NoParamCallback) {
94
+ export function copy(src: string, dir: string, umask: number, callback: NoParamCallback) {
88
95
  let reduce = 0;
89
96
 
90
97
  fs.stat(src, (err, stat) => {
@@ -150,7 +157,7 @@ function copy(src: string, dir: string, umask: number, callback: NoParamCallback
150
157
  });
151
158
  }
152
159
 
153
- function remove(src: string, callback: NoParamCallback) {
160
+ export function remove(src: string, callback: NoParamCallback) {
154
161
  fs.stat(src, (err, stat) => {
155
162
  if (err) {
156
163
  return callback(err);
@@ -187,7 +194,7 @@ function remove(src: string, callback: NoParamCallback) {
187
194
  });
188
195
  }
189
196
 
190
- function mkdir(dir: string, umask: number, callback: NoParamCallback) {
197
+ export function mkdir(dir: string, umask: number, callback: NoParamCallback) {
191
198
  const cwd = process.cwd();
192
199
 
193
200
  if (dir === cwd) {
@@ -218,7 +225,7 @@ function mkdir(dir: string, umask: number, callback: NoParamCallback) {
218
225
 
219
226
  if (dir.indexOf(cwd) === 0) {
220
227
  use = cwd;
221
- dir = dir.substr(cwd.length);
228
+ dir = dir.substring(cwd.length);
222
229
  }
223
230
 
224
231
  const files = dir.split(sep);
@@ -229,11 +236,3 @@ function mkdir(dir: string, umask: number, callback: NoParamCallback) {
229
236
  iter.next();
230
237
  iter.next(iter);
231
238
  }
232
-
233
- export default {
234
- chmod,
235
- chown,
236
- copy,
237
- remove,
238
- mkdir
239
- }
@@ -5,7 +5,7 @@ import { expect } from 'expect';
5
5
  import { fmock, restore } from './__fmock';
6
6
  import { pfs } from '../src';
7
7
 
8
- describe('chown(src, uid, gid [, options])', () => {
8
+ describe('chown(src, [, options])', () => {
9
9
  const chance = new Chance();
10
10
 
11
11
  beforeEach(() => {
@@ -25,7 +25,7 @@ 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
- await pfs.chown('./tmpdir/tings.txt', uid, gid);
28
+ await pfs.chown('./tmpdir/tings.txt', { uid, gid });
29
29
 
30
30
  assert(uid && gid);
31
31
  });
@@ -33,7 +33,7 @@ describe('chown(src, uid, gid [, options])', () => {
33
33
 
34
34
  it('Positive: Changes the permissions of a directory', async () => {
35
35
  const { uid, gid } = fs.statSync('./tmpdir/digest');
36
- await pfs.chown('./tmpdir/digest', uid, gid);
36
+ await pfs.chown('./tmpdir/digest', { uid, gid });
37
37
 
38
38
  assert(uid && gid);
39
39
  });
@@ -44,7 +44,7 @@ describe('chown(src, uid, gid [, options])', () => {
44
44
  const { uid, gid } = fs.statSync('./tmpdir/tings.txt');
45
45
 
46
46
  await expect(async () => {
47
- await pfs.chown(`./tmpdir/${guid}`, uid, gid);
47
+ await pfs.chown(`./tmpdir/${guid}`, { uid, gid });
48
48
  })
49
49
  .rejects
50
50
  .toThrow();
@@ -54,8 +54,10 @@ describe('chown(src, uid, gid [, options])', () => {
54
54
  it('[sync] Positive: Changes the permissions of a file', () => {
55
55
  const { uid, gid } = fs.statSync('./tmpdir/tings.txt');
56
56
 
57
- pfs.chown('./tmpdir/tings.txt', uid, gid, {
58
- sync: true
57
+ pfs.chown('./tmpdir/tings.txt', {
58
+ sync: true,
59
+ uid,
60
+ gid
59
61
  });
60
62
 
61
63
  assert(uid && gid);
@@ -65,8 +67,10 @@ describe('chown(src, uid, gid [, options])', () => {
65
67
  it('[sync] Positive: Changes the permissions of a directory', () => {
66
68
  const { uid, gid } = fs.statSync('./tmpdir/digest');
67
69
 
68
- pfs.chown('./tmpdir/digest', uid, gid, {
69
- sync: true
70
+ pfs.chown('./tmpdir/digest', {
71
+ sync: true,
72
+ uid,
73
+ gid
70
74
  });
71
75
 
72
76
  assert(uid && gid);
@@ -78,8 +82,10 @@ describe('chown(src, uid, gid [, options])', () => {
78
82
  const { uid, gid } = fs.statSync('./tmpdir/tings.txt');
79
83
 
80
84
  assert.throws(() => {
81
- pfs.chown(`./tmpdir/${guid}`, uid, gid, {
82
- sync: true
85
+ pfs.chown(`./tmpdir/${guid}`, {
86
+ sync: true,
87
+ uid,
88
+ gid
83
89
  });
84
90
  });
85
91
  });
package/tsconfig.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "lib": [
4
4
  "es2022"
5
5
  ],
6
- "module": "CommonJS",
6
+ "module": "commonjs",
7
7
  "target": "es2022",
8
8
  "moduleResolution": "node",
9
9
  "resolveJsonModule": true,
@@ -14,6 +14,6 @@
14
14
  "declaration": true,
15
15
  "noEmitOnError": true,
16
16
  "noUnusedLocals": false,
17
- "outDir": "lib"
17
+ "outDir": "dist"
18
18
  }
19
19
  }
@@ -1,13 +0,0 @@
1
- declare function chmod(src: string, mode: number): void;
2
- declare function chown(src: string, uid: number, gid: number): void;
3
- declare function copy(src: string, dir: string, umask: number): void;
4
- declare function remove(src: string): void;
5
- declare function mkdir(dir: string, umask: number): void;
6
- declare const _default: {
7
- chmod: typeof chmod;
8
- chown: typeof chown;
9
- copy: typeof copy;
10
- remove: typeof remove;
11
- mkdir: typeof mkdir;
12
- };
13
- export default _default;
@@ -1,17 +0,0 @@
1
- /// <reference types="node" />
2
- import fs from 'node:fs';
3
- export type Files = Array<string>;
4
- export type NoParamCallback = fs.NoParamCallback;
5
- declare function chmod(src: string, mode: number, callback: NoParamCallback): void;
6
- declare function chown(src: string, uid: number, gid: number, callback: NoParamCallback): void;
7
- declare function copy(src: string, dir: string, umask: number, callback: NoParamCallback): void;
8
- declare function remove(src: string, callback: NoParamCallback): void;
9
- declare function mkdir(dir: string, umask: number, callback: NoParamCallback): void;
10
- declare const _default: {
11
- chmod: typeof chmod;
12
- chown: typeof chown;
13
- copy: typeof copy;
14
- remove: typeof remove;
15
- mkdir: typeof mkdir;
16
- };
17
- export default _default;
@@ -1,5 +0,0 @@
1
- export interface Iframe {
2
- [key: string]: any;
3
- }
4
- export declare function fmock(frame: Iframe): void;
5
- export declare function restore(tmpDir: string): void;
@@ -1,40 +0,0 @@
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
- exports.restore = exports.fmock = void 0;
7
- const node_fs_1 = __importDefault(require("node:fs"));
8
- const node_path_1 = __importDefault(require("node:path"));
9
- function fmock(frame) {
10
- for (const src of Object.keys(frame)) {
11
- const { dir } = node_path_1.default.parse(src);
12
- const value = frame[src];
13
- node_fs_1.default.mkdirSync(dir, { recursive: true });
14
- if (value.type === 'directory') {
15
- node_fs_1.default.mkdirSync(src);
16
- }
17
- if (value.type === 'file') {
18
- node_fs_1.default.writeFileSync(src, value.data);
19
- }
20
- if (value.type === 'symlink') {
21
- node_fs_1.default.symlinkSync(value.target, src);
22
- }
23
- }
24
- }
25
- exports.fmock = fmock;
26
- function restore(tmpDir) {
27
- const removeRecursive = (src) => {
28
- if (node_fs_1.default.existsSync(src)) {
29
- node_fs_1.default.readdirSync(src).forEach((item) => {
30
- const curl = `${src}/${item}`;
31
- node_fs_1.default.lstatSync(curl).isDirectory()
32
- ? removeRecursive(curl)
33
- : node_fs_1.default.unlinkSync(curl);
34
- });
35
- node_fs_1.default.rmdirSync(src);
36
- }
37
- };
38
- removeRecursive(tmpDir);
39
- }
40
- exports.restore = restore;
@@ -1 +0,0 @@
1
- export {};
@@ -1,58 +0,0 @@
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('append(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: 'hoodie'
19
- }
20
- });
21
- });
22
- afterEach(() => {
23
- (0, __fmock_1.restore)('./tmpdir');
24
- });
25
- it('Positive: Must append content to file', async () => {
26
- const payload = chance.paragraph();
27
- await src_1.pfs.append('./tmpdir/tings.txt', payload);
28
- const { size } = node_fs_1.default.statSync('./tmpdir/tings.txt');
29
- (0, node_assert_1.default)(payload.length + 6 === size);
30
- });
31
- it(`Negative: Unexpected option 'flag' returns Error`, async () => {
32
- const payload = chance.paragraph();
33
- await (0, expect_1.expect)(async () => {
34
- await src_1.pfs.append('./tmpdir/tings.txt', payload, {
35
- flag: 'r'
36
- });
37
- })
38
- .rejects
39
- .toThrow();
40
- });
41
- it(`[sync] Positive: Must append content to file`, () => {
42
- const payload = chance.paragraph();
43
- src_1.pfs.append('./tmpdir/tings.txt', payload, {
44
- sync: true
45
- });
46
- const { size } = node_fs_1.default.statSync('./tmpdir/tings.txt');
47
- (0, node_assert_1.default)(payload.length + 6 === size);
48
- });
49
- it(`[sync] Negative: Unexpected option 'flag' returns Error`, () => {
50
- const payload = chance.paragraph();
51
- node_assert_1.default.throws(() => {
52
- src_1.pfs.append('./tmpdir/tings.txt', payload, {
53
- sync: true,
54
- flag: 'r'
55
- });
56
- });
57
- });
58
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,26 +0,0 @@
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 src_1 = require("../src");
8
- describe('static bitmask(mode: number)', () => {
9
- it('Positive: Calculate bitmask', () => {
10
- (0, node_assert_1.default)((0, src_1.bitmask)(33024) === 0o400); // (r--------)
11
- (0, node_assert_1.default)((0, src_1.bitmask)(33152) === 0o600); // (rw-------)
12
- (0, node_assert_1.default)((0, src_1.bitmask)(33216) === 0o700); // (rwx------)
13
- (0, node_assert_1.default)((0, src_1.bitmask)(32800) === 0o040); // (---r-----)
14
- (0, node_assert_1.default)((0, src_1.bitmask)(32816) === 0o060); // (---rw----)
15
- (0, node_assert_1.default)((0, src_1.bitmask)(32824) === 0o070); // (---rwx---)
16
- (0, node_assert_1.default)((0, src_1.bitmask)(32772) === 0o004); // (------r--)
17
- (0, node_assert_1.default)((0, src_1.bitmask)(32774) === 0o006); // (------rw-)
18
- (0, node_assert_1.default)((0, src_1.bitmask)(32775) === 0o007); // (------rwx)
19
- });
20
- it(`Negative: Throw an exception if the argument is 'null' type`, () => {
21
- node_assert_1.default.throws(() => {
22
- // @ts-ignore
23
- (0, src_1.bitmask)(null);
24
- });
25
- });
26
- });
@@ -1 +0,0 @@
1
- export {};