2
2
3
3
const fs = require ( 'graceful-fs' )
4
4
const path = require ( 'path' )
5
+ const atLeastNode = require ( 'at-least-node' )
5
6
6
- const NODE_VERSION_MAJOR_WITH_BIGINT = 10
7
- const NODE_VERSION_MINOR_WITH_BIGINT = 5
8
- const NODE_VERSION_PATCH_WITH_BIGINT = 0
9
- const nodeVersion = process . versions . node . split ( '.' )
10
- const nodeVersionMajor = Number . parseInt ( nodeVersion [ 0 ] , 10 )
11
- const nodeVersionMinor = Number . parseInt ( nodeVersion [ 1 ] , 10 )
12
- const nodeVersionPatch = Number . parseInt ( nodeVersion [ 2 ] , 10 )
13
-
14
- function nodeSupportsBigInt ( ) {
15
- if ( nodeVersionMajor > NODE_VERSION_MAJOR_WITH_BIGINT ) {
16
- return true
17
- } else if ( nodeVersionMajor === NODE_VERSION_MAJOR_WITH_BIGINT ) {
18
- if ( nodeVersionMinor > NODE_VERSION_MINOR_WITH_BIGINT ) {
19
- return true
20
- } else if ( nodeVersionMinor === NODE_VERSION_MINOR_WITH_BIGINT ) {
21
- if ( nodeVersionPatch >= NODE_VERSION_PATCH_WITH_BIGINT ) {
22
- return true
23
- }
24
- }
25
- }
26
- return false
27
- }
7
+ const nodeSupportsBigInt = atLeastNode ( '10.5.0' )
28
8
29
9
function getStats ( src , dest , cb ) {
30
- if ( nodeSupportsBigInt ( ) ) {
10
+ if ( nodeSupportsBigInt ) {
31
11
fs . stat ( src , { bigint : true } , ( err , srcStat ) => {
32
12
if ( err ) return cb ( err )
33
13
fs . stat ( dest , { bigint : true } , ( err , destStat ) => {
@@ -54,13 +34,13 @@ function getStats (src, dest, cb) {
54
34
55
35
function getStatsSync ( src , dest ) {
56
36
let srcStat , destStat
57
- if ( nodeSupportsBigInt ( ) ) {
37
+ if ( nodeSupportsBigInt ) {
58
38
srcStat = fs . statSync ( src , { bigint : true } )
59
39
} else {
60
40
srcStat = fs . statSync ( src )
61
41
}
62
42
try {
63
- if ( nodeSupportsBigInt ( ) ) {
43
+ if ( nodeSupportsBigInt ) {
64
44
destStat = fs . statSync ( dest , { bigint : true } )
65
45
} else {
66
46
destStat = fs . statSync ( dest )
@@ -105,7 +85,7 @@ function checkParentPaths (src, srcStat, dest, funcName, cb) {
105
85
const srcParent = path . resolve ( path . dirname ( src ) )
106
86
const destParent = path . resolve ( path . dirname ( dest ) )
107
87
if ( destParent === srcParent || destParent === path . parse ( destParent ) . root ) return cb ( )
108
- if ( nodeSupportsBigInt ( ) ) {
88
+ if ( nodeSupportsBigInt ) {
109
89
fs . stat ( destParent , { bigint : true } , ( err , destStat ) => {
110
90
if ( err ) {
111
91
if ( err . code === 'ENOENT' ) return cb ( )
@@ -136,7 +116,7 @@ function checkParentPathsSync (src, srcStat, dest, funcName) {
136
116
if ( destParent === srcParent || destParent === path . parse ( destParent ) . root ) return
137
117
let destStat
138
118
try {
139
- if ( nodeSupportsBigInt ( ) ) {
119
+ if ( nodeSupportsBigInt ) {
140
120
destStat = fs . statSync ( destParent , { bigint : true } )
141
121
} else {
142
122
destStat = fs . statSync ( destParent )
@@ -153,7 +133,7 @@ function checkParentPathsSync (src, srcStat, dest, funcName) {
153
133
154
134
function areIdentical ( srcStat , destStat ) {
155
135
if ( destStat . ino && destStat . dev && destStat . ino === srcStat . ino && destStat . dev === srcStat . dev ) {
156
- if ( nodeSupportsBigInt ( ) || destStat . ino < Number . MAX_SAFE_INTEGER ) {
136
+ if ( nodeSupportsBigInt || destStat . ino < Number . MAX_SAFE_INTEGER ) {
157
137
// definitive answer
158
138
return true
159
139
}
0 commit comments