Skip to content

Commit 034be14

Browse files
committed
feat: expand deprecation warning to cover Node.js <= 18
- Change logic from checking exactly Node.js 18 to checking versions <= 18 - Update warning message to reflect 'Node.js 18 and below are deprecated' - Extract version parsing with proper error handling for null/malformed versions - Add tests for Node.js 16, 17, and 14 to verify warning appears - Improve robustness by adding null check for process.version BREAKING CHANGE: Warning now appears for Node.js 16 and 17 in addition to 18
1 parent 980ac8b commit 034be14

File tree

2 files changed

+51
-18
lines changed

2 files changed

+51
-18
lines changed

src/index.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,29 @@ export const createClient = <
4040
return new SupabaseClient<Database, SchemaName, Schema>(supabaseUrl, supabaseKey, options)
4141
}
4242

43-
// Check for Node.js 18 deprecation
43+
// Check for Node.js <= 18 deprecation
4444
function shouldShowDeprecationWarning(): boolean {
45-
return (
46-
typeof window === 'undefined' &&
47-
typeof process !== 'undefined' &&
48-
process.version !== undefined &&
49-
/^v18\./.test(process.version)
50-
)
45+
if (
46+
typeof window !== 'undefined' ||
47+
typeof process === 'undefined' ||
48+
process.version === undefined ||
49+
process.version === null
50+
) {
51+
return false
52+
}
53+
54+
const versionMatch = process.version.match(/^v(\d+)\./)
55+
if (!versionMatch) {
56+
return false
57+
}
58+
59+
const majorVersion = parseInt(versionMatch[1], 10)
60+
return majorVersion <= 18
5161
}
5262

5363
if (shouldShowDeprecationWarning()) {
5464
console.warn(
55-
`⚠️ Node.js 18 is deprecated and will no longer be supported in future versions of @supabase/supabase-js. ` +
65+
`⚠️ Node.js 18 and below are deprecated and will no longer be supported in future versions of @supabase/supabase-js. ` +
5666
`Please upgrade to Node.js 20 or later. ` +
5767
`For more information, visit: https://github.com/orgs/supabase/discussions/37217`
5868
)

test/unit/deprecation-warning.test.ts

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const originalConsoleWarn = console.warn
66
// Make this a module to fix TypeScript error
77
export {}
88

9-
describe('Node.js 18 Deprecation Warning', () => {
9+
describe('Node.js <= 18 Deprecation Warning', () => {
1010
let mockConsoleWarn: jest.SpyInstance
1111

1212
beforeEach(() => {
@@ -42,7 +42,7 @@ describe('Node.js 18 Deprecation Warning', () => {
4242
require('../../src/index')
4343

4444
expect(mockConsoleWarn).toHaveBeenCalledWith(
45-
expect.stringContaining('⚠️ Node.js 18 is deprecated')
45+
expect.stringContaining('⚠️ Node.js 18 and below are deprecated')
4646
)
4747
expect(mockConsoleWarn).toHaveBeenCalledWith(
4848
expect.stringContaining('Please upgrade to Node.js 20 or later')
@@ -100,7 +100,7 @@ describe('Node.js 18 Deprecation Warning', () => {
100100
expect(mockConsoleWarn).not.toHaveBeenCalled()
101101
})
102102

103-
test('should NOT show warning for Node.js 16.20.0', () => {
103+
test('should show warning for Node.js 16.20.0', () => {
104104
delete (global as any).window
105105
global.process = {
106106
...originalProcess,
@@ -109,7 +109,31 @@ describe('Node.js 18 Deprecation Warning', () => {
109109

110110
require('../../src/index')
111111

112-
expect(mockConsoleWarn).not.toHaveBeenCalled()
112+
expect(mockConsoleWarn).toHaveBeenCalled()
113+
})
114+
115+
test('should show warning for Node.js 17.9.1', () => {
116+
delete (global as any).window
117+
global.process = {
118+
...originalProcess,
119+
version: 'v17.9.1',
120+
} as NodeJS.Process
121+
122+
require('../../src/index')
123+
124+
expect(mockConsoleWarn).toHaveBeenCalled()
125+
})
126+
127+
test('should show warning for Node.js 14.21.3', () => {
128+
delete (global as any).window
129+
global.process = {
130+
...originalProcess,
131+
version: 'v14.21.3',
132+
} as NodeJS.Process
133+
134+
require('../../src/index')
135+
136+
expect(mockConsoleWarn).toHaveBeenCalled()
113137
})
114138

115139
test('should NOT show warning when window is defined (browser environment)', () => {
@@ -133,8 +157,7 @@ describe('Node.js 18 Deprecation Warning', () => {
133157
const shouldShow =
134158
typeof mockWindow === 'undefined' &&
135159
typeof mockProcess !== 'undefined' &&
136-
(mockProcess as any)?.version !== undefined &&
137-
/^v18\./.test((mockProcess as any)?.version || '')
160+
(mockProcess as any)?.version !== undefined
138161

139162
expect(shouldShow).toBe(false)
140163
expect(mockConsoleWarn).not.toHaveBeenCalled()
@@ -152,7 +175,7 @@ describe('Node.js 18 Deprecation Warning', () => {
152175
expect(mockConsoleWarn).not.toHaveBeenCalled()
153176
})
154177

155-
test('should NOT show warning for version string "18" without "v" prefix', () => {
178+
test('should NOT show warning for version string "18" without "v" prefix (malformed)', () => {
156179
delete (global as any).window
157180
global.process = {
158181
...originalProcess,
@@ -164,7 +187,7 @@ describe('Node.js 18 Deprecation Warning', () => {
164187
expect(mockConsoleWarn).not.toHaveBeenCalled()
165188
})
166189

167-
test('should NOT show warning for version containing "18" but not starting with "v18."', () => {
190+
test('should show warning for version v1.18.0 (major version 1)', () => {
168191
delete (global as any).window
169192
global.process = {
170193
...originalProcess,
@@ -173,7 +196,7 @@ describe('Node.js 18 Deprecation Warning', () => {
173196

174197
require('../../src/index')
175198

176-
expect(mockConsoleWarn).not.toHaveBeenCalled()
199+
expect(mockConsoleWarn).toHaveBeenCalled()
177200
})
178201
})
179202

@@ -207,7 +230,7 @@ describe('Node.js 18 Deprecation Warning', () => {
207230
expect(mockConsoleWarn).toHaveBeenCalledTimes(1)
208231

209232
const warningMessage = mockConsoleWarn.mock.calls[0][0]
210-
expect(warningMessage).toContain('⚠️ Node.js 18 is deprecated')
233+
expect(warningMessage).toContain('⚠️ Node.js 18 and below are deprecated')
211234
expect(warningMessage).toContain('will no longer be supported in future versions')
212235
expect(warningMessage).toContain('@supabase/supabase-js')
213236
expect(warningMessage).toContain('Please upgrade to Node.js 20 or later')

0 commit comments

Comments
 (0)