Skip to content

Commit 5d6298e

Browse files
authored
feat!: drop support for Node.js 12.x (#31)
415eea5 already dropped this from CI, so it seems reasonable to consider this unsupported either way, but this commit fully removes the code that was used for supporting it.
1 parent 8586e97 commit 5d6298e

File tree

2 files changed

+6
-32
lines changed

2 files changed

+6
-32
lines changed

resources/third_party_main.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/index.ts

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22
import { Logger, LoggerImpl } from './logger';
33
import fetch from 'node-fetch';
4-
import semver from 'semver';
54
import tar from 'tar';
65
import path from 'path';
76
import zlib from 'zlib';
@@ -17,7 +16,7 @@ import { Readable } from 'stream';
1716
import nv from '@pkgjs/nv';
1817

1918
// 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> {
2120
logger.stepStarting(`Looking for Node.js version matching ${JSON.stringify(range)}`);
2221
const ver = (await nv(range)).pop();
2322
if (!ver) {
@@ -120,7 +119,7 @@ async function getNodeSourceForVersion (range: string, dir: string, logger: Logg
120119

121120
logger.stepCompleted();
122121

123-
return [version, path.join(dir, `node-${version}`)];
122+
return path.join(dir, `node-${version}`);
124123
}
125124

126125
// Compile a Node.js build in a given directory from source
@@ -203,17 +202,16 @@ async function compileJSFileAsBinaryImpl (options: CompilationOptions, logger: L
203202
options.tmpdir = path.join(os.tmpdir(), 'boxednode', namespace);
204203
}
205204

206-
const [nodeVersion, nodeSourcePath] = await getNodeSourceForVersion(
205+
const nodeSourcePath = await getNodeSourceForVersion(
207206
options.nodeVersionRange, options.tmpdir, logger);
208207

209208
const requireMappings: [RegExp, string][] = [];
210209
const extraJSSourceFiles: string[] = [];
211210
const enableBindingsPatch = options.enableBindingsPatch ?? options.addons?.length > 0;
212211

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+
{
217215
const extraGypDependencies: string[] = [];
218216
const registerFunctions: string[] = [];
219217
for (const addon of (options.addons || [])) {
@@ -254,29 +252,6 @@ async function compileJSFileAsBinaryImpl (options: CompilationOptions, logger: L
254252
registerFunctions.map((fn) => `${fn},`).join(''));
255253
await fs.writeFile(path.join(nodeSourcePath, 'src', 'node_main.cc'), mainSource);
256254
logger.stepCompleted();
257-
} else {
258-
let tpmSource = await fs.readFile(
259-
path.join(__dirname, '..', 'resources', 'third_party_main.js'), 'utf8');
260-
tpmSource = tpmSource.replace(/\bREPLACE_WITH_ENTRY_POINT\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-
/ProcessGlobalArgs\((?:[^{};]|[\r\n])*?kDisallowedInEnvironment(?:[^{}]|[\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-
}
280255
}
281256

282257
logger.stepStarting('Inserting custom code into Node.js source');

0 commit comments

Comments
 (0)