gulpjs / vinyl-fs

Vinyl adapter for the file system.
MIT License
971 stars 156 forks source link

[DEP0180] DeprecationWarning: fs.Stats constructor is deprecated. #356

Open kashav opened 3 months ago

kashav commented 3 months ago

Before you open this issue, please complete the following tasks:

What were you expecting to happen?

No deprecation warning.

What actually happened?

Deprecation warning for the fs.Stats constructor.

Please give us a sample of your gulpfile

// src/zip.js
import gulp from 'gulp'
import zip from 'gulp-zip'
import { createRequire } from 'module'
const require = createRequire(import.meta.url)
const manifest = require('../build/manifest.json')

gulp
  .src('build/**')
  .pipe(zip(`${manifest.name.replaceAll(' ', '-')}-${manifest.version}.zip`))
  .pipe(gulp.dest('package'))

Terminal output / screenshots

$ node --trace-deprecation src/zip.js
(node:59666) [DEP0180] DeprecationWarning: fs.Stats constructor is deprecated.
    at Transform.normalize [as _transform] (/node_modules/vinyl-fs/lib/dest/prepare.js:38:32)
    at Transform._write (/node_modules/streamx/index.js:981:12)
    at WritableState.update (/node_modules/streamx/index.js:187:16)
    at WritableState.updateWriteNT (/node_modules/streamx/index.js:550:10)
    at process.processTicksAndRejections (node:internal/process/task_queues:77:11)

Please provide the following information:

Additional information

API was deprecated in Node v22.0.0 - https://nodejs.org/api/deprecations.html#DEP0180:

Calling fs.Stats class directly with Stats() or new Stats() is deprecated due to being internals, not intended for public use.

Docs also mention:

Stat objects are not to be created directly using the new keyword.

Not sure what the alternative is here. Maybe just use fs.statSync() or return an empty object if the file doesn't exist?

phated commented 3 months ago

This library currently supports node 10+. This cannot be resolved until older node support is dropped.