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
35773577
35783578<!-- YAML
35793579changes:
3580+ - version: REPLACEME
3581+ pr-url: https://github.com/nodejs/node/pull/49686
3582+ description: Runtime deprecation.
35803583 - version: v20.8.0
35813584 pr-url: https://github.com/nodejs/node/pull/49683
35823585 description: Documentation-only deprecation.
35833586-->
35843587
3585- Type: Documentation-only
3588+ Type: Runtime
35863589
35873590` F_OK ` , ` R_OK ` , ` W_OK ` and ` X_OK ` getters exposed directly on ` node:fs ` are
35883591deprecated. 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 {
8787const { toPathIfFileURL } = require ( 'internal/url' ) ;
8888const {
8989 customPromisifyArgs : kCustomPromisifyArgsSymbol ,
90+ deprecate,
9091 emitExperimentalWarning,
9192 getLazy,
9293 kEmptyObject,
@@ -3275,10 +3276,50 @@ defineLazyProperties(
32753276) ;
32763277
32773278ObjectDefineProperties ( fs , {
3278- F_OK : { __proto__ : null , enumerable : true , value : F_OK || 0 } ,
3279- R_OK : { __proto__ : null , enumerable : true , value : R_OK || 0 } ,
3280- W_OK : { __proto__ : null , enumerable : true , value : W_OK || 0 } ,
3281- X_OK : { __proto__ : null , enumerable : true , value : X_OK || 0 } ,
3279+ F_OK : {
3280+ __proto__ : null ,
3281+ enumerable : false ,
3282+ get : deprecate (
3283+ function get ( ) {
3284+ return F_OK || 0 ;
3285+ } ,
3286+ 'fs.F_OK is deprecated, use fs.constants.F_OK instead' ,
3287+ 'DEP0176' ,
3288+ ) ,
3289+ } ,
3290+ R_OK : {
3291+ __proto__ : null ,
3292+ enumerable : false ,
3293+ get : deprecate (
3294+ function get ( ) {
3295+ return R_OK || 0 ;
3296+ } ,
3297+ 'fs.R_OK is deprecated, use fs.constants.R_OK instead' ,
3298+ 'DEP0176' ,
3299+ ) ,
3300+ } ,
3301+ W_OK : {
3302+ __proto__ : null ,
3303+ enumerable : false ,
3304+ get : deprecate (
3305+ function get ( ) {
3306+ return W_OK || 0 ;
3307+ } ,
3308+ 'fs.W_OK is deprecated, use fs.constants.W_OK instead' ,
3309+ 'DEP0176' ,
3310+ ) ,
3311+ } ,
3312+ X_OK : {
3313+ __proto__ : null ,
3314+ enumerable : false ,
3315+ get : deprecate (
3316+ function get ( ) {
3317+ return X_OK || 0 ;
3318+ } ,
3319+ 'fs.X_OK is deprecated, use fs.constants.X_OK instead' ,
3320+ 'DEP0176' ,
3321+ ) ,
3322+ } ,
32823323 constants : {
32833324 __proto__ : null ,
32843325 configurable : false ,
Original file line number Diff line number Diff line change 11'use strict' ;
2- require ( '../common' ) ;
2+ const { expectWarning } = require ( '../common' ) ;
33const fs = require ( 'fs' ) ;
44const assert = require ( 'assert' ) ;
55
66// Check if the two constants accepted by chmod() on Windows are defined.
77assert . notStrictEqual ( fs . constants . S_IRUSR , undefined ) ;
88assert . 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