Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,10 @@
const {exec} = require('child-process-promise');
const {existsSync} = require('fs');
const {join} = require('path');
const {execRead, logPromise} = require('../utils');
const {execRead} = require('../utils');
const theme = require('../theme');

const run = async ({cwd, local, packages, version}) => {
if (local) {
// Sanity test
if (!existsSync(join(cwd, 'build', 'node_modules', 'react'))) {
console.error(theme.error`No local build exists.`);
process.exit(1);
}
return;
}

const run = async (packages, versionsMap, {cwd, prerelease}) => {
if (!existsSync(join(cwd, 'build'))) {
await exec(`mkdir ./build`, {cwd});
}
Expand All @@ -31,6 +22,14 @@ const run = async ({cwd, local, packages, version}) => {
// Checkout "next" release from NPM for all local packages
for (let i = 0; i < packages.length; i++) {
const packageName = packages[i];
if (!(packageName in versionsMap)) {
throw Error(
`Package "${packageName}" has no version specified. Only ${JSON.stringify(
Object.keys(versionsMap)
)} are supported are valid package names.`
);
}
const version = versionsMap[packageName] + '-canary-' + prerelease;

// We previously used `npm install` for this,
// but in addition to checking out a lot of transient dependencies that we don't care about–
Expand All @@ -49,12 +48,12 @@ const run = async ({cwd, local, packages, version}) => {
await exec(`tar -xvzf ${filePath} -C ${nodeModulesPath}`, {cwd});
await exec(`mv ${tempPackagePath} ${packagePath}`, {cwd});
await exec(`rm ${filePath}`, {cwd});

console.log(
theme`{green ✔} NPM checkout {package ${packageName}}@{version ${version}}`
);
}
};

module.exports = async params => {
return logPromise(
run(params),
theme`Checking out "next" from NPM {version ${params.version}}`
);
};
// Run this directly because logPromise would interfere with printing package dependencies.
module.exports = run;

This file was deleted.

This file was deleted.

This file was deleted.

16 changes: 2 additions & 14 deletions scripts/release/prepare-release-from-npm-commands/parse-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ const commandLineArgs = require('command-line-args');
const {splitCommaParams} = require('../utils');

const paramDefinitions = [
{
name: 'local',
type: Boolean,
description:
'Skip NPM and use the build already present in "build/node_modules".',
defaultValue: false,
},
{
name: 'onlyPackages',
type: String,
Expand All @@ -34,15 +27,10 @@ const paramDefinitions = [
defaultValue: false,
},
{
name: 'version',
name: 'prerelease',
type: String,
description:
'Version of published "next" release (e.g. 0.0.0-0e526bcec-20210202)',
},
{
name: 'publishVersion',
type: String,
description: 'Version to publish',
'prerelease to publish (e.g. version 19.2.0-canary-86181134-20251001 has prerelease "86181134-20251001")',
},
{
name: 'ci',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const {join, relative} = require('path');
const {confirm, execRead, printDiff} = require('../utils');
const theme = require('../theme');

const run = async ({cwd, packages, version, ci}, versionsMap) => {
const run = async (packages, versions, {cwd, prerelease, ci}) => {
const nodeModulesPath = join(cwd, 'build/node_modules');

// Cache all package JSONs for easy lookup below.
Expand Down Expand Up @@ -52,10 +52,16 @@ const run = async ({cwd, packages, version, ci}, versionsMap) => {
sourceDependencyVersion ===
sourceDependencyConstraint.replace(/^[\^\~]/, '')
) {
if (!(dependencyName in versions)) {
throw new Error(
`No version found for ${dependencyName} in the release.`
);
}

targetDependencies[dependencyName] =
sourceDependencyConstraint.replace(
sourceDependencyVersion,
versionsMap.get(dependencyName)
versions[dependencyName]
);
} else {
targetDependencies[dependencyName] = sourceDependencyConstraint;
Expand All @@ -73,7 +79,10 @@ const run = async ({cwd, packages, version, ci}, versionsMap) => {
const packageName = packages[i];
const packageJSONPath = join(nodeModulesPath, packageName, 'package.json');
const packageJSON = await readJson(packageJSONPath);
packageJSON.version = versionsMap.get(packageName);
if (!(packageName in versions)) {
throw new Error(`No version found for ${packageName} in the release.`);
}
packageJSON.version = versions[packageName];

await updateDependencies(packageJSON, 'dependencies');
await updateDependencies(packageJSON, 'peerDependencies');
Expand All @@ -100,9 +109,7 @@ const run = async ({cwd, packages, version, ci}, versionsMap) => {
const packageJSONPath = join(nodeModulesPath, packageName, 'package.json');
const packageJSON = await readJson(packageJSONPath);
console.log(
theme`\n{package ${packageName}} {version ${versionsMap.get(
packageName
)}}`
theme`\n{package ${packageName}} {version ${versions[packageName]}}`
);
printDependencies(packageJSON.dependencies, 'dependency');
printDependencies(packageJSON.peerDependencies, 'peer');
Expand All @@ -113,51 +120,47 @@ const run = async ({cwd, packages, version, ci}, versionsMap) => {

clear();

if (packages.includes('react')) {
// We print the diff to the console for review,
// but it can be large so let's also write it to disk.
const diffPath = join(cwd, 'build', 'temp.diff');
let diff = '';
let numFilesModified = 0;

// Find-and-replace hardcoded version (in built JS) for renderers.
for (let i = 0; i < packages.length; i++) {
const packageName = packages[i];
const packagePath = join(nodeModulesPath, packageName);

let files = await execRead(
`find ${packagePath} -name '*.js' -exec echo {} \\;`,
{cwd}
);
files = files.split('\n');
files.forEach(path => {
const newStableVersion = versionsMap.get(packageName);
const beforeContents = readFileSync(path, 'utf8', {cwd});
let afterContents = beforeContents;
// Replace all "next" version numbers (e.g. header @license).
while (afterContents.indexOf(version) >= 0) {
afterContents = afterContents.replace(version, newStableVersion);
}
if (beforeContents !== afterContents) {
numFilesModified++;
// Using a relative path for diff helps with the snapshot test
diff += printDiff(relative(cwd, path), beforeContents, afterContents);
writeFileSync(path, afterContents, {cwd});
}
});
}
writeFileSync(diffPath, diff, {cwd});
console.log(theme.header(`\n${numFilesModified} files have been updated.`));
console.log(
theme`A full diff is available at {path ${relative(cwd, diffPath)}}.`
);
if (ci !== true) {
await confirm('Do the changes above look correct?');
// We print the diff to the console for review,
// but it can be large so let's also write it to disk.
const diffPath = join(cwd, 'build', 'temp.diff');
let diff = '';
let numFilesModified = 0;

// Find-and-replace hardcoded version (in built JS) for renderers.
for (let i = 0; i < packages.length; i++) {
const packageName = packages[i];
if (!(packageName in versions)) {
throw new Error(`No version found for ${packageName} in the release.`);
}
} else {
console.log(
theme`Skipping React renderer version update because React is not included in the release.`
const newStableVersion = versions[packageName];
// Replace all "next" version numbers (e.g. header @license).
const canaryVersion = `${newStableVersion}-canary-${prerelease}`;
const packagePath = join(nodeModulesPath, packageName);

let files = await execRead(
`find ${packagePath} -name '*.js' -exec echo {} \\;`,
{cwd}
);
files = files.split('\n');
files.forEach(path => {
const beforeContents = readFileSync(path, 'utf8', {cwd});
let afterContents = beforeContents;
afterContents = afterContents.replaceAll(canaryVersion, newStableVersion);
if (beforeContents !== afterContents) {
numFilesModified++;
// Using a relative path for diff helps with the snapshot test
diff += printDiff(relative(cwd, path), beforeContents, afterContents);
writeFileSync(path, afterContents, {cwd});
}
});
}
writeFileSync(diffPath, diff, {cwd});
console.log(theme.header(`\n${numFilesModified} files have been updated.`));
console.log(
theme`A full diff is available at {path ${relative(cwd, diffPath)}}.`
);
if (ci !== true) {
await confirm('Do the changes above look correct?');
}

clear();
Expand Down
Loading
Loading