14
14
15
15
import { exec as execCallback , spawn as spawnCallback , ExecOptions , SpawnOptionsWithoutStdio , spawnSync } from 'child_process' ;
16
16
import { dirname , join , relative , resolve , sep } from 'path' ;
17
- import { exit } from 'process' ;
18
17
import { lt } from 'semver' ;
19
18
import { MIN_FIREBASE_SDK_FOR_AUTH } from './constants' ;
20
19
@@ -79,16 +78,9 @@ export const findDependency = (name: string, cwd=process.cwd()) => {
79
78
return search ( name , json . dependencies ) ;
80
79
}
81
80
82
- export const getWebpackPlugin = ( cwd : string ) => {
83
- let webpack : typeof import ( 'webpack' ) ;
84
- try {
85
- webpack = require ( 'webpack' ) ;
86
- } catch ( e ) {
87
- console . error ( 'Webpack is required for auth-context awareness in SSR, npm i --save-dev webpack.' ) ;
88
- exit ( 1 ) ;
89
- }
81
+ export const getWebpackPlugin = ( webpack : typeof import ( 'webpack' ) , cwd : string ) => {
90
82
const { NormalModuleReplacementPlugin } = webpack ;
91
- new NormalModuleReplacementPlugin ( / ^ f i r e b a s e \/ ( a u t h ) $ / , ( resource : any ) => {
83
+ return new NormalModuleReplacementPlugin ( / ^ f i r e b a s e \/ ( a u t h ) $ / , ( resource : any ) => {
92
84
// Don't allow firebase-frameworks to recurse
93
85
const frameworksRoot = resolve ( `${ dirname ( require . resolve ( '.' ) ) } ${ sep } ..` ) ;
94
86
if ( resource . context . startsWith ( frameworksRoot ) ) return ;
@@ -100,6 +92,7 @@ export const getWebpackPlugin = (cwd: string) => {
100
92
if ( client === 'auth' && lt ( firebaseDependency . version , MIN_FIREBASE_SDK_FOR_AUTH ) ) return ;
101
93
// TODO log to the firebase.log
102
94
console . log ( `Substituting import of '${ resource . request } ' with 'firebase-frameworks/client/${ client } ' in ${ relative ( cwd , resource . context ) } .` ) ;
103
- resource . request = require . resolve ( `./client/${ client } ` ) ;
95
+ console . log ( require . resolve ( `firebase-frameworks/client/${ client } ` ) ) ;
96
+ resource . request = require . resolve ( `firebase-frameworks/client/${ client } ` ) ;
104
97
} )
105
98
} ;
0 commit comments