Skip to content

Commit

Permalink
Fix windows installation (#1098)
Browse files Browse the repository at this point in the history
Fixes #1050. Previously, it was not possible to install src-cli via npm
on Windows. It was also not possible to publish the npm package on
Windows. This PR fixes both problems. The second problem had to be
solved so I could manually test the fix for this PR.:
  • Loading branch information
olafurpg authored Jul 3, 2024
1 parent dcc02b2 commit 1a44832
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions npm-distribution/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
src
LICENSE
README.md
8 changes: 8 additions & 0 deletions npm-distribution/copy-files.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const fs = require('fs')
const path = require('path')

const licensePath = path.join(__dirname, '..', 'LICENSE')
const readmePath = path.join(__dirname, '..', 'README.md')

fs.copyFileSync(licensePath, path.join(__dirname, 'LICENSE'))
fs.copyFileSync(readmePath, path.join(__dirname, 'README.md'))
9 changes: 6 additions & 3 deletions npm-distribution/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ get(assetURL, (response) => {
}
response
.pipe(zlib.createGunzip())
.pipe(tar.x({ filter: (x) => x === "src" }))
.addListener("close", () => fs.chmodSync(executableName, "755"));
});
.pipe(tar.x({ filter: (x) => x === executableName }))
.addListener("close", () => {
if (process.platform !== 'win32') {
fs.chmodSync(executableName, "755");
}
});});

// Follow redirects.
function get(url, callback) {
Expand Down
2 changes: 1 addition & 1 deletion npm-distribution/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "Apache-2.0",
"scripts": {
"install": "node install.js",
"prepack": "cp ../LICENSE . && cp ../README.md ."
"prepack": "node copy-files.js"
},
"main": "src.js",
"bin": {
Expand Down

0 comments on commit 1a44832

Please sign in to comment.