File tree Expand file tree Collapse file tree 3 files changed +69
-6
lines changed Expand file tree Collapse file tree 3 files changed +69
-6
lines changed Original file line number Diff line number Diff line change @@ -3577,12 +3577,15 @@ The [`util.toUSVString()`][] API is deprecated. Please use
3577
3577
3578
3578
<!-- YAML
3579
3579
changes:
3580
+ - version: REPLACEME
3581
+ pr-url: https://github.com/nodejs/node/pull/49686
3582
+ description: Runtime deprecation.
3580
3583
- version: v20.8.0
3581
3584
pr-url: https://github.com/nodejs/node/pull/49683
3582
3585
description: Documentation-only deprecation.
3583
3586
-->
3584
3587
3585
- Type: Documentation-only
3588
+ Type: Runtime
3586
3589
3587
3590
` F_OK ` , ` R_OK ` , ` W_OK ` and ` X_OK ` getters exposed directly on ` node:fs ` are
3588
3591
deprecated. Get them from ` fs.constants ` or ` fs.promises.constants ` instead.
Original file line number Diff line number Diff line change @@ -87,6 +87,7 @@ const {
87
87
const { toPathIfFileURL } = require ( 'internal/url' ) ;
88
88
const {
89
89
customPromisifyArgs : kCustomPromisifyArgsSymbol ,
90
+ deprecate,
90
91
emitExperimentalWarning,
91
92
getLazy,
92
93
kEmptyObject,
@@ -3274,10 +3275,50 @@ defineLazyProperties(
3274
3275
) ;
3275
3276
3276
3277
ObjectDefineProperties ( fs , {
3277
- F_OK : { __proto__ : null , enumerable : true , value : F_OK || 0 } ,
3278
- R_OK : { __proto__ : null , enumerable : true , value : R_OK || 0 } ,
3279
- W_OK : { __proto__ : null , enumerable : true , value : W_OK || 0 } ,
3280
- X_OK : { __proto__ : null , enumerable : true , value : X_OK || 0 } ,
3278
+ F_OK : {
3279
+ __proto__ : null ,
3280
+ enumerable : false ,
3281
+ get : deprecate (
3282
+ function get ( ) {
3283
+ return F_OK || 0 ;
3284
+ } ,
3285
+ 'fs.F_OK is deprecated, use fs.constants.F_OK instead' ,
3286
+ 'DEP0176' ,
3287
+ ) ,
3288
+ } ,
3289
+ R_OK : {
3290
+ __proto__ : null ,
3291
+ enumerable : false ,
3292
+ get : deprecate (
3293
+ function get ( ) {
3294
+ return R_OK || 0 ;
3295
+ } ,
3296
+ 'fs.R_OK is deprecated, use fs.constants.R_OK instead' ,
3297
+ 'DEP0176' ,
3298
+ ) ,
3299
+ } ,
3300
+ W_OK : {
3301
+ __proto__ : null ,
3302
+ enumerable : false ,
3303
+ get : deprecate (
3304
+ function get ( ) {
3305
+ return W_OK || 0 ;
3306
+ } ,
3307
+ 'fs.W_OK is deprecated, use fs.constants.W_OK instead' ,
3308
+ 'DEP0176' ,
3309
+ ) ,
3310
+ } ,
3311
+ X_OK : {
3312
+ __proto__ : null ,
3313
+ enumerable : false ,
3314
+ get : deprecate (
3315
+ function get ( ) {
3316
+ return X_OK || 0 ;
3317
+ } ,
3318
+ 'fs.X_OK is deprecated, use fs.constants.X_OK instead' ,
3319
+ 'DEP0176' ,
3320
+ ) ,
3321
+ } ,
3281
3322
constants : {
3282
3323
__proto__ : null ,
3283
3324
configurable : false ,
Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
- require ( '../common' ) ;
2
+ const { expectWarning } = require ( '../common' ) ;
3
3
const fs = require ( 'fs' ) ;
4
4
const assert = require ( 'assert' ) ;
5
5
6
6
// Check if the two constants accepted by chmod() on Windows are defined.
7
7
assert . notStrictEqual ( fs . constants . S_IRUSR , undefined ) ;
8
8
assert . notStrictEqual ( fs . constants . S_IWUSR , undefined ) ;
9
+
10
+ // Check for runtime deprecation warning, there should be no setter
11
+ const { F_OK , R_OK , W_OK , X_OK } = fs . constants ;
12
+
13
+ assert . throws ( ( ) => { fs . F_OK = 'overwritten' ; } , { name : 'TypeError' } ) ;
14
+ assert . throws ( ( ) => { fs . R_OK = 'overwritten' ; } , { name : 'TypeError' } ) ;
15
+ assert . throws ( ( ) => { fs . W_OK = 'overwritten' ; } , { name : 'TypeError' } ) ;
16
+ assert . throws ( ( ) => { fs . X_OK = 'overwritten' ; } , { name : 'TypeError' } ) ;
17
+
18
+ expectWarning (
19
+ 'DeprecationWarning' ,
20
+ 'fs.F_OK is deprecated, use fs.constants.F_OK instead' ,
21
+ 'DEP0176'
22
+ ) ;
23
+
24
+ assert . strictEqual ( fs . F_OK , F_OK ) ;
25
+ assert . strictEqual ( fs . R_OK , R_OK ) ;
26
+ assert . strictEqual ( fs . W_OK , W_OK ) ;
27
+ assert . strictEqual ( fs . X_OK , X_OK ) ;
You can’t perform that action at this time.
0 commit comments