Skip to content

Commit d3dc39b

Browse files
committed
Initial outline
1 parent fc2717e commit d3dc39b

File tree

5 files changed

+115
-2
lines changed

5 files changed

+115
-2
lines changed

README.md

+28-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,28 @@
1-
# check-vc-redistributable
2-
An npm package to easily show a warning if the Microsoft Visual C++ Redistributable is not installed on Windows
1+
# Check-MSVC-Runtime
2+
3+
> _Part of [HTTP Toolkit](https://httptoolkit.com/): powerful tools for building, testing & debugging HTTP_
4+
5+
An npm package to easily show a warning if the Microsoft Visual C++ (MSVC) Redistributable is not installed on Windows.
6+
7+
Many Windows binaries won't run without the MSVC runtime installed, so this can cause problems, but those applications often don't provide a clear error. This makes it easy to end up with a hard-to-set up npm project. To handle that, this package makes it easy to cleanly detect and warn whenever this happens, so developers can easily resolve it themselves.
8+
9+
To use this:
10+
11+
* `npm install check-msvc-runtime`
12+
* Add `"preinstall": "check-msvc-runtime"` to your package.json scripts
13+
14+
Now, any time you `npm install` in your repo on Windows, if the MSVC runtime isn't installed it'll fail and show:
15+
16+
```bash
17+
> [email protected] preinstall
18+
> ./bin.js
19+
20+
***********************
21+
The Microsoft Visual C++ Runtime is not installed, and is required to set up this project on Windows.
22+
Install it from https://learn.microsoft.com/cpp/windows/latest-supported-vc-redist
23+
***********************
24+
25+
npm ERR! code 1
26+
npm ERR! path .../check-msvc-runtime
27+
npm ERR! command failed
28+
```

bin.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env node
2+
3+
const { isMsvcRuntimeInstalled } = require('./check');
4+
5+
isMsvcRuntimeInstalled().then((installed) => {
6+
if (process.platform !== 'win32') {
7+
// We only check on Windows - not relevant elsewhere
8+
// process.exit(0);
9+
}
10+
11+
if (installed) {
12+
console.log('Visual C++ Redistributable is installed.');
13+
process.exit(0);
14+
} else {
15+
console.error(
16+
'\n***********************\n' +
17+
'The Microsoft Visual C++ Runtime is not installed, and is required to set up this project on Windows.\n' +
18+
'Install it from https://learn.microsoft.com/cpp/windows/latest-supported-vc-redist\n' +
19+
'***********************\n'
20+
);
21+
process.exit(1);
22+
}
23+
});

check.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const { exec } = require('child_process');
2+
const { promisify } = require('util');
3+
4+
const execAsync = promisify(exec);
5+
6+
exports.isMsvcRuntimeInstalled = async function () {
7+
if (process.platform !== 'win32') return false;
8+
9+
try {
10+
await execAsync('where vcruntime140.dll');
11+
console.log('Visual C++ Redistributable is installed.');
12+
return true;
13+
} catch (error) {
14+
console.error('Visual C++ Redistributable is not installed. Please install it from https://aka.ms/vs/16/release/vc_redist.x64.exe');
15+
return false;
16+
}
17+
};

package-lock.json

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "check-msvc-runtime",
3+
"version": "0.0.0",
4+
"description": "Easily show a warning if the Microsoft Visual C++ Redistributable is not installed on Windows ",
5+
"main": "check.js",
6+
"bin": {
7+
"check-msvc-runtime": "bin.js"
8+
},
9+
"scripts": {
10+
"preinstall": "./bin.js"
11+
},
12+
"repository": {
13+
"type": "git",
14+
"url": "git+https://github.com/httptoolkit/check-msvc-runtime.git"
15+
},
16+
"keywords": [
17+
"msvc",
18+
"visual",
19+
"c++",
20+
"redistributable",
21+
"redist",
22+
"microsoft"
23+
],
24+
"author": "Tim Perry <[email protected]>",
25+
"license": "Apache-2.0",
26+
"bugs": {
27+
"url": "https://github.com/httptoolkit/check-msvc-runtime/issues"
28+
},
29+
"homepage": "https://github.com/httptoolkit/check-msvc-runtime#readme"
30+
}

0 commit comments

Comments
 (0)