Skip to content

Commit

Permalink
feat: remove global flag
Browse files Browse the repository at this point in the history
  • Loading branch information
septs committed Aug 23, 2021
1 parent d78b9a4 commit e9b57dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
3 changes: 0 additions & 3 deletions dist/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ inputs:
registry:
description: Automatically set the registry
required: false
global:
description: Global
required: false

runs:
using: node12
Expand Down
23 changes: 9 additions & 14 deletions src/npmrc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { execFile as _execFile } from 'child_process';
import { execFile } from 'child_process';
import { promisify } from 'util';

interface Options {
Expand All @@ -8,29 +8,24 @@ interface Options {
}

export async function configure(options: Options): Promise<void> {
await setToken(options.token, options.global);
await setToken(options.token);
if (options.registry) {
await setRepistry(options.global);
await setRepistry();
}
}

async function setToken(token: string, global: boolean) {
await push('//npm.pkg.github.com/:_authToken', token, global);
async function setToken(token: string) {
await push('//npm.pkg.github.com/:_authToken', token);
}

async function setRepistry(global: boolean) {
async function setRepistry() {
const repository = process.env.GITHUB_REPOSITORY ?? '';
const index = repository.indexOf('/');
const name = repository.slice(0, index);
const registry = `@${name.toLowerCase()}:registry`;
await push(registry, `https://npm.pkg.github.com/${name}`, global);
await push(registry, `https://npm.pkg.github.com/${name}`);
}

function push(key: string, value: string, global: boolean) {
const execFile = promisify(_execFile);
const argv = ['config', 'set', `${key}=${value}`];
if (global) {
argv.push('--global');
}
return execFile('npm', argv);
function push(key: string, value: string) {
return promisify(execFile)('npm', ['config', 'set', key, value]);
}

0 comments on commit e9b57dc

Please sign in to comment.