Skip to content

Commit 7aa855f

Browse files
committed
fs: export constants from fs/promises
1 parent 40162db commit 7aa855f

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

doc/api/fs.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -789,8 +789,7 @@ with an {Error} object. The following example checks if the file
789789
`/etc/passwd` can be read and written by the current process.
790790
791791
```mjs
792-
import { access } from 'node:fs/promises';
793-
import { constants } from 'node:fs';
792+
import { access, constants } from 'node:fs/promises';
794793

795794
try {
796795
await access('/etc/passwd', constants.R_OK | constants.W_OK);
@@ -892,8 +891,7 @@ error occurs after the destination file has been opened for writing, an attempt
892891
will be made to remove the destination.
893892
894893
```mjs
895-
import { constants } from 'node:fs';
896-
import { copyFile } from 'node:fs/promises';
894+
import { copyFile, constants } from 'node:fs/promises';
897895

898896
try {
899897
await copyFile('source.txt', 'destination.txt');

lib/internal/fs/promises.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ const {
1717
Uint8Array,
1818
} = primordials;
1919

20+
const { fs: constants } = internalBinding('constants');
2021
const {
2122
F_OK,
2223
O_SYMLINK,
2324
O_WRONLY,
2425
S_IFMT,
2526
S_IFREG
26-
} = internalBinding('constants').fs;
27+
} = constants;
28+
2729
const binding = internalBinding('fs');
2830
const { Buffer } = require('buffer');
2931

@@ -899,6 +901,7 @@ module.exports = {
899901
appendFile,
900902
readFile,
901903
watch,
904+
constants,
902905
},
903906

904907
FileHandle,

test/parallel/test-fs-promises-exists.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22

33
require('../common');
44
const assert = require('assert');
5+
const fs = require('fs');
6+
const fsPromises = require('fs/promises');
57

6-
assert.strictEqual(require('fs/promises'), require('fs').promises);
8+
assert.strictEqual(fsPromises, fs.promises);
9+
assert.strictEqual(fsPromises.constants, fs.constants);

0 commit comments

Comments
 (0)