WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit d7ef354

Browse files
committed
fix: Avoid Node.js deprecation warning for fs.Stats
1 parent ad025af commit d7ef354

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

lib/dest/prepare.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ var fs = require('graceful-fs');
66
var Vinyl = require('vinyl');
77
var Transform = require('streamx').Transform;
88

9+
function newStats() {
10+
// Node.js is cruel and emits deprecation if we don't build
11+
// a `new Stats()` like this
12+
var stats = Object.create(fs.Stats.prototype);
13+
fs.Stats.prototype.constructor.call(stats);
14+
return stats;
15+
}
16+
917
function prepareWrite(folderResolver, optResolver) {
1018
if (!folderResolver) {
1119
throw new Error('Invalid output folder');
@@ -35,7 +43,7 @@ function prepareWrite(folderResolver, optResolver) {
3543
file.path = writePath;
3644
if (!file.isSymbolic()) {
3745
var mode = optResolver.resolve('mode', file);
38-
file.stat = file.stat || new fs.Stats();
46+
file.stat = file.stat || newStats();
3947
file.stat.mode = mode;
4048
}
4149

lib/symlink/prepare.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ var fs = require('graceful-fs');
66
var Vinyl = require('vinyl');
77
var Transform = require('streamx').Transform;
88

9+
function newStats() {
10+
// Node.js is cruel and emits deprecation if we don't build
11+
// a `new Stats()` like this
12+
var stats = Object.create(fs.Stats.prototype);
13+
fs.Stats.prototype.constructor.call(stats);
14+
return stats;
15+
}
16+
917
function prepareSymlink(folderResolver, optResolver) {
1018
if (!folderResolver) {
1119
throw new Error('Invalid output folder');
@@ -32,7 +40,7 @@ function prepareSymlink(folderResolver, optResolver) {
3240

3341
// Wire up new properties
3442
// Note: keep the target stats for now, we may need them in link-file
35-
file.stat = file.stat || new fs.Stats();
43+
file.stat = file.stat || newStats()
3644
file.cwd = cwd;
3745
file.base = basePath;
3846
// This is the path we are linking *TO*

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"streamx": "^2.14.0",
3737
"to-through": "^3.0.0",
3838
"value-or-function": "^4.0.0",
39-
"vinyl": "^3.0.0",
39+
"vinyl": "^3.0.1",
4040
"vinyl-sourcemap": "^2.0.0"
4141
},
4242
"devDependencies": {

0 commit comments

Comments
 (0)