@samitouri / QOS-React-2 / commits / 8c1614a2fd

Tidy up NPM checkout process (#14631)

Brian Vaughn committed Jan 18, 2019 at 11:40 UTC 8c1614a2fdbb841f65ebf403d7ece3a518c6a984
3 files changed +19 -35
scripts/release/prepare-stable-commands/check-out-packages.js
+19 -2
@@ -5,7 +5,7 @@
5 const {exec} = require('child-process-promise');
6 const {existsSync} = require('fs');
7 const {join} = require('path');
8 -const {logPromise} = require('../utils');
8 +const {execRead, logPromise} = require('../utils');
9 const theme = require('../theme');
10
11 const run = async ({cwd, local, packages, version}) => {
@@ -31,7 +31,24 @@ const run = async ({cwd, local, packages, version}) => {
31 // Checkout canary release from NPM for all local packages
32 for (let i = 0; i < packages.length; i++) {
33 const packageName = packages[i];
34 - await exec(`npm i ${packageName}@${version}`, {cwd: nodeModulesPath});
34 +
35 + // We previously used `npm install` for this,
36 + // but in addition to checking out a lot of transient dependencies that we don't care about–
37 + // the NPM client also added a lot of registry metadata to the package JSONs,
38 + // which we had to remove as a separate step before re-publishing.
39 + // It's easier for us to just download and extract the tarball.
40 + const url = await execRead(
41 + `npm view ${packageName}@${version} dist.tarball`
42 + );
43 + const filePath = join(nodeModulesPath, `${packageName}.tgz`);
44 + const packagePath = join(nodeModulesPath, `${packageName}`);
45 + const tempPackagePath = join(nodeModulesPath, 'package');
46 +
47 + // Download packages from NPM and extract them to the expected build locations.
48 + await exec(`curl ${url} > ${filePath}`, {cwd});
49 + await exec(`tar -xvzf ${filePath} -C ${nodeModulesPath}`, {cwd});
50 + await exec(`mv ${tempPackagePath} ${packagePath}`, {cwd});
51 + await exec(`rm ${filePath}`, {cwd});
52 }
53 };
54
scripts/release/prepare-stable-commands/prune-package-registry-metadata.js deleted
-31
@@ -1,31 +0,0 @@
1 -#!/usr/bin/env node
2 -
3 -'use strict';
4 -
5 -const {logPromise} = require('../utils');
6 -const {readJson, writeJson} = require('fs-extra');
7 -const {join} = require('path');
8 -
9 -const run = async ({cwd, packages}) => {
10 - const nodeModulesPath = join(cwd, 'build/node_modules');
11 -
12 - for (let i = 0; i < packages.length; i++) {
13 - const packageName = packages[i];
14 - const packageJSONPath = join(nodeModulesPath, packageName, 'package.json');
15 - const packageJSON = await readJson(packageJSONPath);
16 -
17 - // NPM adds a lot of metadata fields on checkout.
18 - // It's nice to strip these before re-publishing the package.
19 - for (let key in packageJSON) {
20 - if (key.startsWith('_')) {
21 - delete packageJSON[key];
22 - }
23 - }
24 -
25 - await writeJson(packageJSONPath, packageJSON, {spaces: 2});
26 - }
27 -};
28 -
29 -module.exports = async params => {
30 - return logPromise(run(params), 'Pruning package registry metadata');
31 -};
scripts/release/prepare-stable.js
-2
@@ -10,7 +10,6 @@ const confirmStableVersionNumbers = require('./prepare-stable-commands/confirm-s
10 const guessStableVersionNumbers = require('./prepare-stable-commands/guess-stable-version-numbers');
11 const parseParams = require('./prepare-stable-commands/parse-params');
12 const printPrereleaseSummary = require('./shared-commands/print-prerelease-summary');
13 -const prunePackageRegistryMetadata = require('./prepare-stable-commands/prune-package-registry-metadata');
13 const testPackagingFixture = require('./shared-commands/test-packaging-fixture');
14 const testTracingFixture = require('./shared-commands/test-tracing-fixture');
15 const updateStableVersionNumbers = require('./prepare-stable-commands/update-stable-version-numbers');
@@ -29,7 +28,6 @@ const run = async () => {
28 await checkOutPackages(params);
29 await guessStableVersionNumbers(params, versionsMap);
30 await confirmStableVersionNumbers(params, versionsMap);
32 - await prunePackageRegistryMetadata(params);
31 await updateStableVersionNumbers(params, versionsMap);
32
33 if (!params.skipTests) {