Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitecf1b1c

Browse files
Merge pull request#43 from mongodb-js/MONGOSH-1536-avoid-linking-compiled-mongosh-twice
2 parents16215d0 +fe03a4a commitecf1b1c

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

‎src/index.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ async function compileJSFileAsBinaryImpl (options: CompilationOptions, logger: L
271271

272272
constnodeSourcePath=awaitgetNodeSourceForVersion(
273273
options.nodeVersionRange,options.tmpdir,logger);
274+
constnodeVersion=awaitgetNodeVersionFromSourceDirectory(nodeSourcePath);
274275

275276
constrequireMappings:[RegExp,string][]=[];
276277
constextraJSSourceFiles:string[]=[];
@@ -312,7 +313,6 @@ async function compileJSFileAsBinaryImpl (options: CompilationOptions, logger: L
312313
}
313314

314315
logger.stepStarting('Inserting custom code into Node.js source');
315-
awaitfs.mkdir(path.join(nodeSourcePath,'lib',namespace),{recursive:true});
316316
letentryPointTrampolineSource=awaitfs.readFile(
317317
path.join(__dirname,'..','resources','entry-point-trampoline.js'),'utf8');
318318
entryPointTrampolineSource=entryPointTrampolineSource.replace(
@@ -321,10 +321,30 @@ async function compileJSFileAsBinaryImpl (options: CompilationOptions, logger: L
321321
requireMappings:requireMappings.map(([re,linked])=>[re.source,re.flags,linked]),
322322
enableBindingsPatch
323323
}));
324-
awaitfs.writeFile(
325-
path.join(nodeSourcePath,'lib',namespace,`${namespace}.js`),
326-
entryPointTrampolineSource);
327-
extraJSSourceFiles.push(`./lib/${namespace}/${namespace}.js`);
324+
325+
/**
326+
* Since Node 20.x, external source code linked from `lib` directory started
327+
* failing the Node.js build process because of the file being linked multiple
328+
* times which is why we do not link the external files anymore from `lib`
329+
* directory and instead from a different directory, `lib-boxednode`. This
330+
* however does not work for any node version < 20 which is why we are
331+
* conditionally generating the entry point and configure params here based on
332+
* Node version.
333+
*/
334+
const{ customCodeSource, customCodeConfigureParam, customCodeEntryPoint}=nodeVersion[0]>=20
335+
?{
336+
customCodeSource:path.join(nodeSourcePath,'lib-boxednode',`${namespace}.js`),
337+
customCodeConfigureParam:`./lib-boxednode/${namespace}.js`,
338+
customCodeEntryPoint:`lib-boxednode/${namespace}`
339+
} :{
340+
customCodeSource:path.join(nodeSourcePath,'lib',namespace,`${namespace}.js`),
341+
customCodeConfigureParam:`./lib/${namespace}/${namespace}.js`,
342+
customCodeEntryPoint:`${namespace}/${namespace}`
343+
};
344+
345+
awaitfs.mkdir(path.dirname(customCodeSource),{recursive:true});
346+
awaitfs.writeFile(customCodeSource,entryPointTrampolineSource);
347+
extraJSSourceFiles.push(customCodeConfigureParam);
328348
logger.stepCompleted();
329349

330350
logger.stepStarting('Storing executable metadata');
@@ -355,7 +375,7 @@ async function compileJSFileAsBinaryImpl (options: CompilationOptions, logger: L
355375
letmainSource=awaitfs.readFile(
356376
path.join(__dirname,'..','resources','main-template.cc'),'utf8');
357377
mainSource=mainSource.replace(/\bREPLACE_WITH_ENTRY_POINT\b/g,
358-
JSON.stringify(`${namespace}/${namespace}`));
378+
JSON.stringify(customCodeEntryPoint));
359379
mainSource=mainSource.replace(/\bREPLACE_DECLARE_LINKED_MODULES\b/g,
360380
registerFunctions.map((fn)=>`void${fn}(const void**,const void**);\n`).join(''));
361381
mainSource=mainSource.replace(/\bREPLACE_DEFINE_LINKED_MODULES\b/g,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp