Repository navigation
Expand file tree
/
Copy pathnode-tooling.cjs
More file actions
42 lines (37 loc) · 1.68 KB
/
Copy pathnode-tooling.cjs
File metadata and controls
42 lines (37 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'use strict';
// Resolve only this checkout's tools. Never invoke a package manager here.
const fs = require('node:fs');
const path = require('node:path');
const { spawnSync } = require('node:child_process');
const root = path.resolve(__dirname, '../..');
const manifest = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'));
function fail(message) {
console.error(`${message}\nRun ./scripts/bootstrap after installing the versions documented in CONTRIBUTING.md.`);
process.exit(1);
}
if (process.versions.node !== manifest.engines.node) {
fail(`Expected Node.js ${manifest.engines.node}, found ${process.versions.node}.`);
}
const [tool, ...args] = process.argv.slice(2);
if (tool === '--check-node') process.exit(0);
const tools = {
pyright: { package: 'pyright', entry: 'index.js' },
};
if (!Object.hasOwn(tools, tool)) fail(`Unknown repository tool: ${tool}`);
const selected = tools[tool];
const directory = path.join(root, 'node_modules', selected.package);
let installed;
try {
installed = JSON.parse(fs.readFileSync(path.join(directory, 'package.json'), 'utf8'));
} catch {
fail(`Missing local ${tool}.`);
}
if (installed.version !== manifest.devDependencies[selected.package]) {
fail(`Expected ${tool} ${manifest.devDependencies[selected.package]}, found ${installed.version}.`);
}
const entry = path.join(directory, selected.entry);
if (!fs.existsSync(entry)) fail(`Missing local ${tool} executable.`);
// Calling Node explicitly also avoids upstream 1.1.399's CRLF shebang issue.
const result = spawnSync(process.execPath, [entry, ...args], { stdio: 'inherit' });
if (result.error) fail(`Could not start ${tool}: ${result.error.message}`);
process.exit(result.status ?? 1);