1
1
'use strict' ;
2
2
import { Logger , LoggerImpl } from './logger' ;
3
3
import fetch from 'node-fetch' ;
4
- import semver from 'semver' ;
5
4
import tar from 'tar' ;
6
5
import path from 'path' ;
7
6
import zlib from 'zlib' ;
@@ -17,7 +16,7 @@ import { Readable } from 'stream';
17
16
import nv from '@pkgjs/nv' ;
18
17
19
18
// Download and unpack a tarball containing the code for a specific Node.js version.
20
- async function getNodeSourceForVersion ( range : string , dir : string , logger : Logger , retries = 2 ) : Promise < [ string , string ] > {
19
+ async function getNodeSourceForVersion ( range : string , dir : string , logger : Logger , retries = 2 ) : Promise < string > {
21
20
logger . stepStarting ( `Looking for Node.js version matching ${ JSON . stringify ( range ) } ` ) ;
22
21
const ver = ( await nv ( range ) ) . pop ( ) ;
23
22
if ( ! ver ) {
@@ -120,7 +119,7 @@ async function getNodeSourceForVersion (range: string, dir: string, logger: Logg
120
119
121
120
logger . stepCompleted ( ) ;
122
121
123
- return [ version , path . join ( dir , `node-${ version } ` ) ] ;
122
+ return path . join ( dir , `node-${ version } ` ) ;
124
123
}
125
124
126
125
// Compile a Node.js build in a given directory from source
@@ -203,17 +202,16 @@ async function compileJSFileAsBinaryImpl (options: CompilationOptions, logger: L
203
202
options . tmpdir = path . join ( os . tmpdir ( ) , 'boxednode' , namespace ) ;
204
203
}
205
204
206
- const [ nodeVersion , nodeSourcePath ] = await getNodeSourceForVersion (
205
+ const nodeSourcePath = await getNodeSourceForVersion (
207
206
options . nodeVersionRange , options . tmpdir , logger ) ;
208
207
209
208
const requireMappings : [ RegExp , string ] [ ] = [ ] ;
210
209
const extraJSSourceFiles : string [ ] = [ ] ;
211
210
const enableBindingsPatch = options . enableBindingsPatch ?? options . addons ?. length > 0 ;
212
211
213
- // In Node.js 12.19.0+, we use the official embedder API for stability.
214
- // In Node.js 12.18.4 and below, we use the legacy _third_party_main mechanism
215
- // that will be removed in future Node.js versions.
216
- if ( semver . gte ( nodeVersion , '12.19.0' ) ) {
212
+ // We use the official embedder API for stability, which is available in all
213
+ // supported versions of Node.js.
214
+ {
217
215
const extraGypDependencies : string [ ] = [ ] ;
218
216
const registerFunctions : string [ ] = [ ] ;
219
217
for ( const addon of ( options . addons || [ ] ) ) {
@@ -254,29 +252,6 @@ async function compileJSFileAsBinaryImpl (options: CompilationOptions, logger: L
254
252
registerFunctions . map ( ( fn ) => `${ fn } ,` ) . join ( '' ) ) ;
255
253
await fs . writeFile ( path . join ( nodeSourcePath , 'src' , 'node_main.cc' ) , mainSource ) ;
256
254
logger . stepCompleted ( ) ;
257
- } else {
258
- let tpmSource = await fs . readFile (
259
- path . join ( __dirname , '..' , 'resources' , 'third_party_main.js' ) , 'utf8' ) ;
260
- tpmSource = tpmSource . replace ( / \b R E P L A C E _ W I T H _ E N T R Y _ P O I N T \b / g,
261
- JSON . stringify ( `${ namespace } /${ namespace } ` ) ) ;
262
- await fs . writeFile ( path . join ( nodeSourcePath , 'lib' , '_third_party_main.js' ) , tpmSource ) ;
263
- extraJSSourceFiles . push ( './lib/_third_party_main.js' ) ;
264
-
265
- // This is the 'only' hack in here: We suppress Node.js options parsing so
266
- // all options end up in process.argv. For that, we remove the main call
267
- // to node::ProcessGlobalArgs().
268
- let nodeCCSource = await fs . readFile (
269
- path . join ( nodeSourcePath , 'src' , 'node.cc' ) , 'utf8' ) ;
270
- nodeCCSource = nodeCCSource . replace (
271
- / P r o c e s s G l o b a l A r g s \( (?: [ ^ { } ; ] | [ \r \n ] ) * ?k D i s a l l o w e d I n E n v i r o n m e n t (?: [ ^ { } ] | [ \r \n ] ) * ?\) / ,
272
- '0' ) ;
273
- await fs . writeFile ( path . join ( nodeSourcePath , 'src' , 'node.cc' ) , nodeCCSource ) ;
274
-
275
- if ( options . addons && options . addons . length > 0 ) {
276
- logger . stepStarting ( 'Handling linked addons' ) ;
277
- logger . stepFailed (
278
- new Error ( 'Addons are not supported on Node v12.x, ignoring...' ) ) ;
279
- }
280
255
}
281
256
282
257
logger . stepStarting ( 'Inserting custom code into Node.js source' ) ;
0 commit comments