1
- // ! WARNING: don't run this in the real repo dir, but in a duplicate temp dir !
1
+ // ! WARNING: don't run this in the real repo dir, but in a duplicate temp dir
2
2
3
3
import { getCurrentWorkingDirectory } from '@-xun/fs' ;
4
- import { run } from '@-xun/run' ;
4
+ import { run , runNoRejectOnBadExit } from '@-xun/run' ;
5
5
import findPackageJson from 'find-package-json' ;
6
6
import { MongoClient } from 'mongodb' ;
7
- import { createDebugLogger } from 'rejoinder' ;
7
+ import { createGenericLogger } from 'rejoinder' ;
8
8
import { satisfies as satisfiesRange , validRange } from 'semver' ;
9
9
10
- import { getNextjsReactPeerDependencies } from 'testverse:util.ts' ;
11
-
12
- import { name as packageName , version as packageVersion } from 'package.json' ;
10
+ import { name as packageName , version as packageVersion } from 'rootverse:package.json' ;
13
11
14
- // * By default, external scripts should be silent. Use the DEBUG environment
15
- // * variable to see relevant output
12
+ import { getNextjsReactPeerDependencies } from 'testverse:util.ts' ;
16
13
17
- const debug = createDebugLogger ( { namespace : ` ${ packageName } : is-next-compat` } ) ;
14
+ const log = createGenericLogger ( { namespace : ' is-next-compat' } ) ;
18
15
19
- debug ( `pkgName : "${ packageName } "`) ;
20
- debug ( `pkgVersion : "${ packageVersion } "`) ;
16
+ log ( `package name : "${ packageName } "`) ;
17
+ log ( `package version : "${ packageVersion } "`) ;
21
18
22
19
export default main ( ) . catch ( ( error : unknown ) => {
23
- debug . error ( error ) ;
20
+ log . error ( error ) ;
24
21
process . exitCode = 2 ;
25
22
} ) ;
26
23
27
- let isRunningInTestMode : boolean | undefined = undefined ;
28
-
29
24
/**
30
25
* Detect if this tool was invoked in the context of an integration test
31
26
*/
32
27
async function checkIfRunningInTestMode ( ) {
33
- try {
34
- isRunningInTestMode =
35
- isRunningInTestMode ??
36
- ( await run ( 'npm' , [ 'run' , '_is_next_compat_test_mode' ] ) ) . exitCode === 0 ;
37
- } catch { }
28
+ const isRunningInTestMode =
29
+ ( await runNoRejectOnBadExit ( 'npm' , [ 'run' , '_is_next_compat_test_mode' ] ) )
30
+ . exitCode === 0 ;
38
31
39
- debug ( `test override mode: ${ isRunningInTestMode ? 'ACTIVE' : 'inactive' } ` ) ;
40
- return ! ! isRunningInTestMode ;
32
+ log ( `test override mode: ${ isRunningInTestMode ? 'ACTIVE' : 'inactive' } ` ) ;
33
+ return isRunningInTestMode ;
41
34
}
42
35
43
36
/**
@@ -46,16 +39,16 @@ async function checkIfRunningInTestMode() {
46
39
async function setCompatFlagTo ( version : string ) {
47
40
try {
48
41
if ( await checkIfRunningInTestMode ( ) ) {
49
- debug ( 'skipped updating database (test override mode)' ) ;
42
+ log ( 'skipped updating database (test override mode)' ) ;
50
43
} else {
51
- const semverRange = process . env . NODE_TARGET_VERSION ! ;
52
- debug ( `saw potential semver range: ${ semverRange } ` ) ;
44
+ const semverRange = process . env . NODE_TARGET_VERSION ;
45
+ log ( `saw potential semver range: ${ semverRange ?? '(undefined)' } ` ) ;
53
46
54
47
if (
55
48
validRange ( semverRange ) &&
56
- ! satisfiesRange ( process . versions . node , semverRange )
49
+ ! satisfiesRange ( process . versions . node , semverRange ! )
57
50
) {
58
- debug (
51
+ log (
59
52
`skipped updating database (node version ${ process . versions . node } not in range)`
60
53
) ;
61
54
} else {
@@ -74,12 +67,12 @@ async function setCompatFlagTo(version: string) {
74
67
75
68
await client . close ( ) ;
76
69
77
- debug ( `updated database compat: "${ version } "` ) ;
78
- } else debug ( 'skipped updating database (no MONGODB_URI)' ) ;
70
+ log ( `updated database compat: "${ version } "` ) ;
71
+ } else log ( 'skipped updating database (no MONGODB_URI)' ) ;
79
72
}
80
73
}
81
74
} catch ( error ) {
82
- debug ( 'additionally, an attempt to update the database failed') ;
75
+ log . warn ( ' an attempt to update the database failed') ;
83
76
throw error ;
84
77
}
85
78
}
@@ -99,9 +92,9 @@ async function setCompatFlagTo(version: string) {
99
92
* ```
100
93
*/
101
94
async function main ( ) {
102
- debug ( 'connecting to GitHub' ) ;
95
+ log ( 'connecting to GitHub' ) ;
103
96
104
- if ( ! process . env . GH_TOKEN ) debug ( 'warning: not using a personal access token!' ) ;
97
+ if ( ! process . env . GH_TOKEN ) log ( 'warning: not using a personal access token!' ) ;
105
98
106
99
const { Octokit } = await import ( '@octokit/rest' ) ;
107
100
@@ -118,21 +111,21 @@ async function main() {
118
111
} ) ;
119
112
120
113
const latestReleaseVersion = latestVersion . replace ( / ^ v / , '' ) ;
121
- debug ( `saw latest release version "${ latestReleaseVersion } "` ) ;
114
+ log ( `saw latest release version "${ latestReleaseVersion } "` ) ;
122
115
123
116
if ( ! latestReleaseVersion ) throw new Error ( 'could not find latest Next.js version' ) ;
124
117
125
118
const { filename : path } = findPackageJson ( getCurrentWorkingDirectory ( ) ) . next ( ) ;
126
- debug ( `using path: %O` , path ) ;
119
+ log ( `using path: %O` , path ) ;
127
120
128
121
if ( ! path ) {
129
122
throw new Error ( 'could not find package.json' ) ;
130
123
}
131
124
132
125
const nextVersionUnderTestFullNameAndVersion = `next@${ latestReleaseVersion } ` ;
133
126
134
- debug ( 'installing %O for unit tests' , nextVersionUnderTestFullNameAndVersion ) ;
135
- debug ( `(integration tests use their own Next.js versions)` ) ;
127
+ log ( 'installing %O for unit tests' , nextVersionUnderTestFullNameAndVersion ) ;
128
+ log ( `(integration tests use their own Next.js versions)` ) ;
136
129
137
130
// ? Install peer deps manually for Next.js
138
131
const nextLatestReleaseVersionPeerDependencies = await getNextjsReactPeerDependencies (
@@ -147,16 +140,16 @@ async function main() {
147
140
...nextLatestReleaseVersionPeerDependencies
148
141
] ) ;
149
142
150
- debug ( 'running compatibility tests' ) ;
143
+ log ( 'running compatibility tests' ) ;
151
144
152
145
await run ( 'npm' , [ 'run' , 'test:unit' ] ) ;
153
146
await run ( 'npm' , [ 'run' , 'test:integration:client' ] ) ;
154
147
155
- debug ( 'test succeeded' ) ;
148
+ log ( 'test succeeded' ) ;
156
149
157
150
await setCompatFlagTo ( latestReleaseVersion ) ;
158
151
159
- debug ( 'execution complete' ) ;
152
+ log ( 'execution complete' ) ;
160
153
161
154
process . exitCode = 0 ;
162
155
}
0 commit comments