Skip to content

Commit

Permalink
Backport PR jupyterlab#10828: Remove outdated npm-cli-login utility…
Browse files Browse the repository at this point in the history
… from buildutils
  • Loading branch information
krassowski authored and meeseeksmachine committed Aug 13, 2021
1 parent b577dee commit 4da41da
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 2,000 deletions.
1 change: 0 additions & 1 deletion buildutils/package.json
Expand Up @@ -50,7 +50,6 @@
"glob": "~7.1.6",
"inquirer": "^7.0.0",
"minimatch": "~3.0.4",
"npm-cli-login": "^0.1.1",
"os": "~0.1.1",
"package-json": "^6.5.0",
"prettier": "~2.1.1",
Expand Down
2 changes: 1 addition & 1 deletion buildutils/src/ensure-repo.ts
Expand Up @@ -83,7 +83,7 @@ const UNUSED: Dict<string[]> = {
'webpack-cli',
'worker-loader'
],
'@jupyterlab/buildutils': ['npm-cli-login', 'verdaccio'],
'@jupyterlab/buildutils': ['verdaccio'],
'@jupyterlab/coreutils': ['path-browserify'],
'@jupyterlab/services': ['node-fetch', 'ws'],
'@jupyterlab/rendermime': ['@jupyterlab/mathjax2'],
Expand Down
52 changes: 43 additions & 9 deletions buildutils/src/local-repository.ts
Expand Up @@ -128,16 +128,50 @@ packages:
}

// Log in using cli and temp credentials
const env = {
...process.env,
NPM_USER: 'foo',
NPM_PASS: 'bar',
NPM_EMAIL: 'foo@bar.com',
NPM_REGISTRY: local_registry
};
const npm_cli_login_bin = path.join(bin_dir, 'npm-cli-login');
const user = 'foo';
const pass = 'bar';
const email = 'foo@bar.com';
console.log('Logging in');
child_process.execSync(npm_cli_login_bin, { env, stdio: 'pipe' });
const loginPs = child_process.spawn(
'npm',
`login -r ${local_registry}`.split(' ')
);

const loggedIn = new Promise<void>((accept, reject) => {
loginPs.stdout.on('data', (chunk: string) => {
const data = Buffer.from(chunk, 'utf-8').toString().trim();
console.log('stdout:', data);
switch (data) {
case 'Username:':
console.log('Passing username...');
loginPs.stdin.write(user + '\n');
break;
case 'Password:':
console.log('Passing password...');
loginPs.stdin.write(pass + '\n');
break;
case 'Email: (this IS public)':
console.log('Passing email...');
loginPs.stdin.write(email + '\n');
break;
default:
reject(`Unexpected prompt: "${data}"`);
}
if (data.indexOf('Logged in as') !== -1) {
loginPs.stdin.end();
// do not accept here yet, the token may not have been written
}
loginPs.stderr.on('data', (chunk: string) => {
const data = Buffer.from(chunk, 'utf-8').toString().trim();
console.log('stderr:', data);
});
});
loginPs.on('error', error => reject(error));
loginPs.on('close', () => accept());
});

await loggedIn;
loginPs.kill();

console.log('Running in', out_dir);
ps.exit(0);
Expand Down

0 comments on commit 4da41da

Please sign in to comment.