Skip to content

Commit

Permalink
fix(package-manager): npm and yarn source
Browse files Browse the repository at this point in the history
  • Loading branch information
cpselvis committed Feb 17, 2020
1 parent d093c19 commit 3384f8f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/feflow-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@types/mocha": "^5.2.7",
"@types/node": "^12.0.10",
"@types/osenv": "^0.1.0",
"@types/request-promise": "^4.1.45",
"@types/semver": "^6.0.1",
"@types/yeoman-environment": "^2.3.1",
"chai": "^4.2.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/feflow-cli/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export default class Feflow {
const pkg: any = JSON.parse(content);
const localVersion = pkg.version;
const registryUrl = await getRegistryUrl(packageManager);
const latestVersion = await packageJson(name, 'latest', registryUrl).catch((err) => {
const latestVersion = await packageJson(name, registryUrl).catch((err) => {
logger.debug('Check plugin update error', err);
});

Expand Down Expand Up @@ -331,7 +331,7 @@ export default class Feflow {
}
const packageManager = config.packageManager;
const registryUrl = await getRegistryUrl(packageManager);
const latestVersion: any = await packageJson('@feflow/cli', 'latest', registryUrl);
const latestVersion: any = await packageJson('@feflow/cli', registryUrl);
if (semver.gt(latestVersion, version)) {
const askIfUpdateCli = [{
type: "confirm",
Expand Down
2 changes: 1 addition & 1 deletion packages/feflow-cli/src/core/native/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = (ctx: any) => {

await Promise.all(
dependencies.map((dependency: string) => {
return packageJson(dependency, 'latest', registryUrl)
return packageJson(dependency, registryUrl)
.catch(() => {
ctx.logger.error(`${ dependency } not found on ${ packageManager }`);
process.exit(2);
Expand Down
2 changes: 1 addition & 1 deletion packages/feflow-cli/src/shared/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function getRegistryUrl(packageManager: string) {
});
return;
}
output = output.replace(/\n/, '');
output = output.replace(/\n/, '').replace(/\/$/, '');
resolve(output);
});
});
Expand Down
11 changes: 6 additions & 5 deletions packages/feflow-cli/src/shared/packageJson.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
const rp = require('request-promise');
import rp from 'request-promise';

export default function packageJson(name: string, version: string, registry: string) {
export default function packageJson(name: string, registry: string) {
return new Promise((resolve, reject) => {
const options = {
url: `${registry}${name}/${version}`,
url: `${registry}/${name}`,
method: 'GET'
};

rp(options)
.then((response: any) => {
response = JSON.parse(response);
resolve(response.version);
const data = JSON.parse(response);
const version = data['dist-tags'].latest;
resolve(version);
})
.catch((err: object) => {
reject(err);
Expand Down

0 comments on commit 3384f8f

Please sign in to comment.