File tree Expand file tree Collapse file tree 4 files changed +18
-7
lines changed
Expand file tree Collapse file tree 4 files changed +18
-7
lines changed Original file line number Diff line number Diff line change 11// Clone cached versions to prevent mutations
22// TODO: use `structuredClone()` after dropping support for Node <17.0.0
33export const cloneCachedVersions = function ( { versions, majors } ) {
4- return { versions : [ ...versions ] , majors : majors . map ( shallowCloneObject ) }
4+ return {
5+ versions : shallowCloneObjectsArray ( versions ) ,
6+ majors : shallowCloneObjectsArray ( majors ) ,
7+ }
8+ }
9+
10+ const shallowCloneObjectsArray = function ( arrayOfObjects ) {
11+ return arrayOfObjects . map ( shallowCloneObject )
512}
613
714const shallowCloneObject = function ( object ) {
Original file line number Diff line number Diff line change 7979
8080test . serial ( `Process cached files cannot be mutated` , async ( t ) => {
8181 const { versions } = await allNodeVersions ( { fetch : false } )
82- const [ firstVersion ] = versions
82+ const [ { node : firstVersion } ] = versions
83+ // eslint-disable-next-line fp/no-mutation
84+ versions [ 0 ] . node = 'test'
8385 // eslint-disable-next-line fp/no-mutating-methods
8486 versions . reverse ( )
85- const { versions : versionsAgain } = await allNodeVersions ( { fetch : false } )
86- t . is ( versionsAgain [ 0 ] , firstVersion )
87+ const {
88+ versions : [ { node : firstVersionAgain } ] ,
89+ } = await allNodeVersions ( { fetch : false } )
90+ t . is ( firstVersionAgain , firstVersion )
8791} )
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ export const writeCacheFile = async function (oldCacheFile = false) {
1919 const cacheFile = await getCacheFile ( )
2020 const lastUpdate = oldCacheFile ? 0 : Date . now ( )
2121 const versionsInfo = {
22- versions : [ 'cached' ] ,
22+ versions : [ { node : 'cached' } ] ,
2323 majors : [ { major : 1 , latest : 'cached' } ] ,
2424 }
2525 const cacheContent = { lastUpdate, ...versionsInfo }
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import allNodeVersions from 'all-node-versions'
33// Retrieve latest Node.js version
44export const getLatestVersion = async function ( opts ) {
55 const {
6- versions : [ version ] ,
6+ versions : [ { node } ] ,
77 } = await allNodeVersions ( opts )
8- return version
8+ return node
99}
You can’t perform that action at this time.
0 commit comments