Skip to content

Commit 3191f30

Browse files
cjihrigMylesBorins
authored andcommitted
fs: move fs/promises to fs.promises
PR-URL: #20504 Refs: nodejs/TSC#389 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Shingo Inoue <leko.noor@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
1 parent bc4d4f0 commit 3191f30

25 files changed

Lines changed: 50 additions & 37 deletions

‎benchmark/fs/bench-stat-promise.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
constcommon=require('../common');
4-
constfsPromises=require('fs/promises');
4+
constfsPromises=require('fs').promises;
55

66
constbench=common.createBenchmark(main,{
77
n: [20e4],

‎doc/api/fs.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3382,9 +3382,9 @@ Synchronous versions of [`fs.write()`][]. Returns the number of bytes written.
33823382

33833383
> Stability: 1 - Experimental
33843384
3385-
The `fs/promises` API provides an alternative set of asynchronous file system
3385+
The `fs.promises` API provides an alternative set of asynchronous file system
33863386
methods that return `Promise` objects rather than using callbacks. The
3387-
API is accessible via `require('fs/promises')`.
3387+
API is accessible via `require('fs').promises`.
33883388

33893389
### class: FileHandle
33903390
<!-- YAML

‎lib/fs.js‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ const { Readable, Writable } = require('stream');
4545
constEventEmitter=require('events');
4646
const{ FSReqWrap, statValues, kFsStatsFieldsLength }=binding;
4747
const{ FSEvent }=process.binding('fs_event_wrap');
48-
constinternalFS=require('internal/fs');
48+
constpromises=require('internal/fs/promises');
49+
constinternalFS=require('internal/fs/utils');
4950
const{ getPathFromURL }=require('internal/url');
5051
constinternalUtil=require('internal/util');
5152
const{
@@ -72,6 +73,21 @@ const {
7273
CHAR_BACKWARD_SLASH,
7374
}=require('internal/constants');
7475

76+
letwarn=true;
77+
78+
Object.defineProperty(fs,'promises',{
79+
configurable: true,
80+
enumerable: true,
81+
get(){
82+
if(warn){
83+
warn=false;
84+
process.emitWarning('The fs.promises API is experimental',
85+
'ExperimentalWarning');
86+
}
87+
returnpromises;
88+
}
89+
});
90+
7591
Object.defineProperty(exports,'constants',{
7692
configurable: false,
7793
enumerable: true,
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
'use strict';
22

3-
process.emitWarning('The fs/promises API is experimental',
4-
'ExperimentalWarning');
5-
63
const{
74
F_OK,
85
O_SYMLINK,
@@ -37,7 +34,7 @@ const {
3734
validateOffsetLengthWrite,
3835
validatePath,
3936
validateUint32
40-
}=require('internal/fs');
37+
}=require('internal/fs/utils');
4138
constpathModule=require('path');
4239

4340
constkHandle=Symbol('handle');

‎lib/internal/modules/cjs/loader.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const { getURLFromFilePath } = require('internal/url');
2828
constvm=require('vm');
2929
constassert=require('assert').ok;
3030
constfs=require('fs');
31-
constinternalFS=require('internal/fs');
31+
constinternalFS=require('internal/fs/utils');
3232
constpath=require('path');
3333
const{
3434
internalModuleReadJSON,

‎lib/internal/modules/esm/default_resolve.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const{URL}=require('url');
44
constCJSmodule=require('internal/modules/cjs/loader');
5-
constinternalFS=require('internal/fs');
5+
constinternalFS=require('internal/fs/utils');
66
const{ NativeModule, internalBinding }=require('internal/bootstrap/loaders');
77
const{ extname }=require('path');
88
const{ realpathSync }=require('fs');

‎lib/internal/process/stdio.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ function createWritableStdioStream(fd) {
158158
break;
159159

160160
case'FILE':
161-
varfs=require('internal/fs');
161+
varfs=require('internal/fs/utils');
162162
stream=newfs.SyncWriteStream(fd,{autoClose: false});
163163
stream._type='fs';
164164
break;

‎node.gyp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
'lib/domain.js',
4040
'lib/events.js',
4141
'lib/fs.js',
42-
'lib/fs/promises.js',
4342
'lib/http.js',
4443
'lib/http2.js',
4544
'lib/_http_agent.js',
@@ -103,7 +102,8 @@
103102
'lib/internal/errors.js',
104103
'lib/internal/fixed_queue.js',
105104
'lib/internal/freelist.js',
106-
'lib/internal/fs.js',
105+
'lib/internal/fs/promises.js',
106+
'lib/internal/fs/utils.js',
107107
'lib/internal/http.js',
108108
'lib/internal/inspector_async_hook.js',
109109
'lib/internal/linkedlist.js',

‎test/parallel/test-fs-filehandle.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const common = require('../common');
55
constassert=require('assert');
66
constpath=require('path');
77
constfs=process.binding('fs');
8-
const{ stringToFlags }=require('internal/fs');
8+
const{ stringToFlags }=require('internal/fs/utils');
99

1010
// Verifies that the FileHandle object is garbage collected and that a
1111
// warning is emitted if it is not closed.

0 commit comments

Comments
 (0)