瀏覽代碼

Backport PR #10828: Remove outdated `npm-cli-login` utility from buildutils (#10832)

Co-authored-by: Michał Krassowski <5832902+krassowski@users.noreply.github.com>
MeeseeksMachine 3 年之前
父節點
當前提交
106ba89def
共有 4 個文件被更改,包括 62 次插入676 次删除
  1. 0 1
      buildutils/package.json
  2. 1 1
      buildutils/src/ensure-repo.ts
  3. 43 9
      buildutils/src/local-repository.ts
  4. 18 665
      yarn.lock

+ 0 - 1
buildutils/package.json

@@ -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",

+ 1 - 1
buildutils/src/ensure-repo.ts

@@ -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'],

+ 43 - 9
buildutils/src/local-repository.ts

@@ -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);

文件差異過大導致無法顯示
+ 18 - 665
yarn.lock


部分文件因文件數量過多而無法顯示