@@ -7,81 +7,73 @@ const DIR = process.cwd();
77/**
88 * Build SDK, and Functions
99 */
10- export default function setup ( testRunId : string , nodeVersion : string , firebaseAdmin : string ) {
10+ export default function setup ( testRunId : string , firebaseAdmin : string ) {
1111 buildSdk ( testRunId ) ;
12- createPackageJson ( testRunId , nodeVersion , firebaseAdmin ) ;
12+ createRequirementsTxt ( testRunId , firebaseAdmin ) ;
1313 installDependencies ( ) ;
14- buildFunctions ( ) ;
1514}
1615
1716function buildSdk ( testRunId : string ) {
1817 console . log ( "Building SDK..." ) ;
1918 process . chdir ( path . join ( DIR , ".." ) ) ; // go up to root
2019
21- // remove existing firebase-functions-*.tgz files
22- const files = fs . readdirSync ( "." ) ;
23- files . forEach ( ( file ) => {
24- if ( file . match ( / ^ f i r e b a s e - f u n c t i o n s - .* \. t g z $ / ) ) {
25- fs . rmSync ( file ) ;
26- }
27- } ) ;
20+ // remove existing build
21+ fs . rmdirSync ( "dist" , { recursive : true } ) ;
22+
2823 // build the package
29- execSync ( "npm run build:pack" , { stdio : "inherit" } ) ;
24+ execSync ( "python -m pip install --upgrade build" , { stdio : "inherit" } ) ;
25+ execSync ( "python -m build -s" , { stdio : "inherit" } ) ;
3026
3127 // move the generated tarball package to functions
3228 const generatedFile = fs
33- . readdirSync ( ". " )
34- . find ( ( file ) => file . match ( / ^ f i r e b a s e - f u n c t i o n s - .* \. t g z $ / ) ) ;
29+ . readdirSync ( "dist " )
30+ . find ( ( file ) => file . match ( / ^ f i r e b a s e _ f u n c t i o n s - .* \. t a r \. g z $ / ) ) ;
3531
3632 if ( generatedFile ) {
3733 const targetPath = path . join (
38- "integration_test " ,
34+ "integration_tests " ,
3935 "functions" ,
40- `firebase-functions- ${ testRunId } .tgz `
36+ `firebase_functions_ ${ testRunId } .tar.gz `
4137 ) ;
42- fs . renameSync ( generatedFile , targetPath ) ;
38+ fs . renameSync ( path . join ( "dist" , generatedFile ) , targetPath ) ;
4339 console . log ( "SDK moved to" , targetPath ) ;
4440 }
4541
4642 process . chdir ( DIR ) ; // go back to integration_test
4743}
4844
49- function createPackageJson ( testRunId : string , nodeVersion : string , firebaseAdmin : string ) {
45+ function createRequirementsTxt ( testRunId : string , firebaseAdmin : string ) {
5046 console . log ( "Creating package.json..." ) ;
51- const packageJsonTemplatePath = `${ DIR } /package.json .template` ;
52- const packageJsonPath = `${ DIR } /functions/package.json ` ;
47+ const requirementsTemplatePath = `${ DIR } /requirements.txt .template` ;
48+ const requirementsPath = `${ DIR } /functions/requirements.txt ` ;
5349
54- fs . copyFileSync ( packageJsonTemplatePath , packageJsonPath ) ;
50+ fs . copyFileSync ( requirementsTemplatePath , requirementsPath ) ;
5551
56- let packageJsonContent = fs . readFileSync ( packageJsonPath , "utf8" ) ;
57- packageJsonContent = packageJsonContent . replace (
58- / _ _ S D K _ T A R B A L L _ _ / g,
59- `firebase-functions-${ testRunId } .tgz`
52+ let requirementsContent = fs . readFileSync ( requirementsPath , "utf8" ) ;
53+ requirementsContent = requirementsContent . replace (
54+ / _ _ L O C A L _ F I R E B A S E _ F U N C T I O N S _ _ / g,
55+ `firebase_functions_${ testRunId } .tar.gz`
56+ ) ;
57+ requirementsContent = requirementsContent . replace (
58+ / _ _ F I R E B A S E _ A D M I N _ _ / g,
59+ firebaseAdmin
6060 ) ;
61- packageJsonContent = packageJsonContent . replace ( / _ _ N O D E _ V E R S I O N _ _ / g, nodeVersion ) ;
62- packageJsonContent = packageJsonContent . replace ( / _ _ F I R E B A S E _ A D M I N _ _ / g, firebaseAdmin ) ;
6361
64- fs . writeFileSync ( packageJsonPath , packageJsonContent ) ;
62+ fs . writeFileSync ( requirementsPath , requirementsContent ) ;
6563}
6664
6765function installDependencies ( ) {
6866 console . log ( "Installing dependencies..." ) ;
6967 const functionsDir = "functions" ;
7068 process . chdir ( functionsDir ) ; // go to functions
7169
72- const modulePath = path . join ( "node_modules" , "firebase-functions ") ;
73- if ( fs . existsSync ( modulePath ) ) {
74- execSync ( `rm -rf ${ modulePath } ` , { stdio : "inherit" } ) ;
70+ const venvPath = path . join ( "venv " ) ;
71+ if ( fs . existsSync ( venvPath ) ) {
72+ execSync ( `rm -rf ${ venvPath } ` , { stdio : "inherit" } ) ;
7573 }
7674
77- execSync ( "npm install" , { stdio : "inherit" } ) ;
75+ execSync ( "python3 -m venv venv" , { stdio : "inherit" } ) ;
76+ execSync ( "source venv/bin/activate" , { stdio : "inherit" } ) ;
77+ execSync ( "python3 -m pip install -r requirements.txt" , { stdio : "inherit" } ) ;
7878 process . chdir ( "../" ) ; // go back to integration_test
7979}
80-
81- function buildFunctions ( ) {
82- console . log ( "Building functions..." ) ;
83- process . chdir ( path . join ( DIR , "functions" ) ) ; // go to functions
84-
85- execSync ( "npm run build" , { stdio : "inherit" } ) ;
86- process . chdir ( DIR ) ; // go back to integration_test
87- }
0 commit comments