File tree Expand file tree Collapse file tree 1 file changed +7
-14
lines changed
Expand file tree Collapse file tree 1 file changed +7
-14
lines changed Original file line number Diff line number Diff line change 11import path from 'node:path'
2+ import { X509Certificate } from 'node:crypto'
23import { promises as fsp } from 'node:fs'
34import type { Plugin } from 'vite'
45
5- // @ts -ignore
6- import forge from 'node-forge/lib/forge'
7- import 'node-forge/lib/pki'
8-
96const defaultCacheDir = 'node_modules/.vite'
107
118interface Options {
@@ -46,17 +43,13 @@ export async function getCertificate(
4643
4744 try {
4845 const content = await fsp . readFile ( cachePath , 'utf8' )
49- const certContent = content . match (
50- / - - - - - B E G I N C E R T I F I C A T E - - - - - [ \s \S ] + - - - - - E N D C E R T I F I C A T E - - - - - / ,
51- )
52- if ( ! certContent ) {
53- throw new Error ( 'certificate not detected.' )
54- }
55-
56- const cert = forge . pki . certificateFromPem ( certContent [ 0 ] )
46+ const cert = new X509Certificate ( content ) ;
5747
58- if ( new Date ( ) > cert . validity . notAfter ) {
59- throw new Error ( 'cache is outdated.' )
48+ // validTo is a nonstandard format, but it successfully parses. validToDate
49+ // is not available until node 22
50+ // https://github.com/nodejs/node/issues/52931
51+ if ( Date . now ( ) > Date . parse ( cert . validTo ) ) {
52+ throw new Error ( 'cache is outdated.' ) ;
6053 }
6154
6255 return content
You can’t perform that action at this time.
0 commit comments