mirror of
https://github.com/ershisan99/go-npm.git
synced 2025-12-16 12:33:24 +00:00
Make it windows friendly
This commit is contained in:
@@ -57,7 +57,7 @@ Here is the magic: You ask to run `go-npm install` after it completes installing
|
|||||||
|
|
||||||
Edit `package.json` file and add the following:
|
Edit `package.json` file and add the following:
|
||||||
```
|
```
|
||||||
{
|
"scripts": {
|
||||||
"postinstall": "go-npm install",
|
"postinstall": "go-npm install",
|
||||||
"preuninstall": "go-npm uninstall",
|
"preuninstall": "go-npm uninstall",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const common = require('../../src/common');
|
const common = require('../../src/common');
|
||||||
|
const path = require('path');
|
||||||
const uninstall = require('../../src/actions/uninstall');
|
const uninstall = require('../../src/actions/uninstall');
|
||||||
|
|
||||||
jest.mock('fs');
|
jest.mock('fs');
|
||||||
@@ -32,7 +33,7 @@ describe('uninstall()', () => {
|
|||||||
|
|
||||||
uninstall(callback);
|
uninstall(callback);
|
||||||
|
|
||||||
expect(fs.unlinkSync).toHaveBeenCalledWith('bin/command');
|
expect(fs.unlinkSync).toHaveBeenCalledWith(path.join('bin', 'command'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call callback on success', () => {
|
it('should call callback on success', () => {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const common = require('../../src/common');
|
const common = require('../../src/common');
|
||||||
const verifyAndPlaceBinary = require('../../src/assets/binary');
|
const verifyAndPlaceBinary = require('../../src/assets/binary');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
jest.mock('fs');
|
jest.mock('fs');
|
||||||
jest.mock('../../src/common');
|
jest.mock('../../src/common');
|
||||||
@@ -33,7 +34,7 @@ describe('verifyAndPlaceBinary()', () => {
|
|||||||
|
|
||||||
it('should call callback with null on success', () => {
|
it('should call callback with null on success', () => {
|
||||||
fs.existsSync.mockReturnValueOnce(true);
|
fs.existsSync.mockReturnValueOnce(true);
|
||||||
common.getInstallationPath.mockImplementationOnce((cb) => cb(null, '/usr/local/bin'));
|
common.getInstallationPath.mockImplementationOnce((cb) => cb(null, path.sep + path.join('usr', 'local', 'bin')));
|
||||||
|
|
||||||
verifyAndPlaceBinary('command', './bin', callback);
|
verifyAndPlaceBinary('command', './bin', callback);
|
||||||
|
|
||||||
@@ -42,10 +43,10 @@ describe('verifyAndPlaceBinary()', () => {
|
|||||||
|
|
||||||
it('should move the binary to installation directory', () => {
|
it('should move the binary to installation directory', () => {
|
||||||
fs.existsSync.mockReturnValueOnce(true);
|
fs.existsSync.mockReturnValueOnce(true);
|
||||||
common.getInstallationPath.mockImplementationOnce((cb) => cb(null, '/usr/local/bin'));
|
common.getInstallationPath.mockImplementationOnce((cb) => cb(null, path.sep + path.join('usr', 'local', 'bin')));
|
||||||
|
|
||||||
verifyAndPlaceBinary('command', './bin', callback);
|
verifyAndPlaceBinary('command', './bin', callback);
|
||||||
|
|
||||||
expect(fs.renameSync).toHaveBeenCalledWith('bin/command', '/usr/local/bin/command');
|
expect(fs.renameSync).toHaveBeenCalledWith(path.join('bin', 'command'), path.sep + path.join('usr', 'local', 'bin', 'command'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
const { EventEmitter } = require('events');
|
const { EventEmitter } = require('events');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
const move = require('../../src/assets/move');
|
const move = require('../../src/assets/move');
|
||||||
|
|
||||||
jest.mock('fs');
|
jest.mock('fs');
|
||||||
@@ -24,7 +25,7 @@ describe('move()', () => {
|
|||||||
|
|
||||||
move({ opts: { binPath: './bin', binName: 'command' }, req: { pipe }, onSuccess, onError });
|
move({ opts: { binPath: './bin', binName: 'command' }, req: { pipe }, onSuccess, onError });
|
||||||
|
|
||||||
expect(fs.createWriteStream).toHaveBeenCalledWith('bin/command');
|
expect(fs.createWriteStream).toHaveBeenCalledWith(path.join("bin", "command"));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call onSuccess on stream closed', () => {
|
it('should call onSuccess on stream closed', () => {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const childProcess = require('child_process');
|
const childProcess = require('child_process');
|
||||||
const common = require('../src/common');
|
const common = require('../src/common');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
jest.mock('fs');
|
jest.mock('fs');
|
||||||
jest.mock('child_process');
|
jest.mock('child_process');
|
||||||
@@ -21,11 +22,11 @@ describe('common', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should get binaries path from `npm bin`', () => {
|
it('should get binaries path from `npm bin`', () => {
|
||||||
childProcess.exec.mockImplementationOnce((_cmd, cb) => cb(null, '/usr/local/bin'));
|
childProcess.exec.mockImplementationOnce((_cmd, cb) => cb(null, path.sep + path.join('usr', 'local', 'bin')));
|
||||||
|
|
||||||
common.getInstallationPath(callback);
|
common.getInstallationPath(callback);
|
||||||
|
|
||||||
expect(callback).toHaveBeenCalledWith(null, '/usr/local/bin');
|
expect(callback).toHaveBeenCalledWith(null, path.sep + path.join('usr', 'local', 'bin'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should get binaries path from env', () => {
|
it('should get binaries path from env', () => {
|
||||||
@@ -35,7 +36,7 @@ describe('common', () => {
|
|||||||
|
|
||||||
common.getInstallationPath(callback);
|
common.getInstallationPath(callback);
|
||||||
|
|
||||||
expect(callback).toHaveBeenCalledWith(null, '/usr/local/bin');
|
expect(callback).toHaveBeenCalledWith(null, path.sep + path.join('usr', 'local', 'bin'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call callback with error if binaries path is not found', () => {
|
it('should call callback with error if binaries path is not found', () => {
|
||||||
|
|||||||
19463
package-lock.json
generated
Normal file
19463
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
23
package.json
23
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "go-npm",
|
"name": "@gzuidhof/go-npm",
|
||||||
"version": "0.1.8",
|
"version": "0.1.9",
|
||||||
"description": "Distribute and install Go binaries via NPM",
|
"description": "Distribute and install Go binaries via NPM",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
@@ -8,25 +8,24 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "jest",
|
"test": "jest",
|
||||||
"prepublish": "node_modules/babel-cli/bin/babel.js src --out-dir bin --presets es2015"
|
"prepublish": "node node_modules/@babel/cli/bin/babel.js src --out-dir bin --presets=@babel/preset-env"
|
||||||
},
|
},
|
||||||
"author": "Sanath Kumar Ramesh <dayanandasaraswati@gmail.com>",
|
"author": "Sanath Kumar Ramesh <dayanandasaraswati@gmail.com>",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"mkdirp": "^0.5.1",
|
"mkdirp": "^1.0.4",
|
||||||
"request": "^2.81.0",
|
"request": "^2.88.2",
|
||||||
"tar": "^2.2.2",
|
"tar": "^6.1.2",
|
||||||
"unzipper": "0.10.10"
|
"unzipper": "0.10.10"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/sanathkr/go-npm.git"
|
"url": "https://github.com/gzuidhof/go-npm.git"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/sanathkr/go-npm",
|
"homepage": "https://github.com/gzuidhof/go-npm",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babel-cli": "^6.26.0",
|
"@babel/cli": "^7.14.8",
|
||||||
"babel-core": "^6.26.0",
|
"@babel/preset-env": "^7.14.8",
|
||||||
"babel-preset-es2015": "^6.24.1",
|
|
||||||
"jest": "^24.5.0"
|
"jest": "^24.5.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -42,7 +42,8 @@ function getInstallationPath(callback) {
|
|||||||
dir = stdout.trim();
|
dir = stdout.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
dir = dir.replace(/node_modules.*\/\.bin/, 'node_modules/.bin');
|
dir = dir.replace(/node_modules.*[\/\\]\.bin/, join('node_modules', '.bin'));
|
||||||
|
|
||||||
mkdirp.sync(dir);
|
mkdirp.sync(dir);
|
||||||
|
|
||||||
callback(null, dir);
|
callback(null, dir);
|
||||||
@@ -74,25 +75,25 @@ function validateConfiguration({ version, goBinary }) {
|
|||||||
|
|
||||||
function getUrl(url, process) {
|
function getUrl(url, process) {
|
||||||
if (typeof url === 'string') {
|
if (typeof url === 'string') {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
let _url;
|
let _url;
|
||||||
|
|
||||||
if (url[PLATFORM_MAPPING[process.platform]]) {
|
if (url[PLATFORM_MAPPING[process.platform]]) {
|
||||||
_url = url[PLATFORM_MAPPING[process.platform]];
|
_url = url[PLATFORM_MAPPING[process.platform]];
|
||||||
} else {
|
} else {
|
||||||
_url = url.default;
|
_url = url.default;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof _url === 'string') {
|
if (typeof _url === 'string') {
|
||||||
return _url;
|
return _url;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_url[ARCH_MAPPING[process.arch]]) {
|
if (_url[ARCH_MAPPING[process.arch]]) {
|
||||||
_url = _url[ARCH_MAPPING[process.arch]]
|
_url = _url[ARCH_MAPPING[process.arch]]
|
||||||
} else {
|
} else {
|
||||||
_url = _url.default;
|
_url = _url.default;
|
||||||
}
|
}
|
||||||
|
|
||||||
return _url;
|
return _url;
|
||||||
|
|||||||
Reference in New Issue
Block a user