Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to manual publish scripts #10055

Merged
merged 4 commits into from
Feb 7, 2023
Merged
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
2 changes: 1 addition & 1 deletion DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ Experimental releases and hot-fixes do not need to be branched off of `dev`. Exp
- Make whatever changes you need and commit them: `git add . && git commit "experimental changes!"`
- Update version numbers and create a release tag: `yarn run version:experimental`
- Push to GitHub: `git push origin --follow-tags`
- Create a new release for the tag on GitHub to trigger the CI workflow that will publish the release to npm
- The CI workflow should automatically trigger from the experimental tag to publish the release to npm
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
"test:inspect": "node --inspect-brk ./node_modules/.bin/jest",
"changeset": "changeset",
"version": "changeset version",
"publish": "node scripts/publish.js",
"postversion": "node scripts/postversion.mjs",
"version:experimental": "node scripts ./scripts/version experimental",
"version:experimental": "node ./scripts/version experimental",
"watch": "rollup -c -w"
},
"jest": {
Expand Down
25 changes: 13 additions & 12 deletions scripts/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,7 @@ function getTaggedVersion() {
* @param {string|number} version
*/
async function ensureBuildVersion(packageName, version) {
let file = path.join(
rootDir,
"build",
"node_modules",
packageName,
"package.json"
);
let file = path.join(rootDir, "packages", packageName, "package.json");
let json = await jsonfile.readFile(file);
invariant(
json.version === version,
Expand All @@ -47,7 +41,7 @@ async function ensureBuildVersion(packageName, version) {
* @param {string} tag
*/
function publishBuild(packageName, tag) {
let buildDir = path.join(rootDir, "build", "node_modules", packageName);
let buildDir = path.join(rootDir, "packages", packageName);
console.log();
console.log(` npm publish ${buildDir} --tag ${tag} --access public`);
console.log();
Expand Down Expand Up @@ -75,25 +69,32 @@ async function run() {
);

// 2. Determine the appropriate npm tag to use
let tag = semver.prerelease(version) == null ? "latest" : "next";
let tag = version.includes("experimental")
? "experimental"
: semver.prerelease(version) == null
? "latest"
: "pre";
Comment on lines -78 to +76
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Introduce an experimental tag and change from next -> pre to match what we're using nowadays


console.log();
console.log(` Publishing version ${version} to npm with tag "${tag}"`);

// 3. Ensure build versions match the release version
if (version.includes("experimental")) {
// FIXME: @remix-run/router is versioned differently and is only handled
// for experimental releases here
await ensureBuildVersion("router", version);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In experimentals we can do this for router alongside since they all share a version

await ensureBuildVersion("react-router", version);
await ensureBuildVersion("react-router-dom", version);
await ensureBuildVersion("react-router-dom-v5-compat", version);
await ensureBuildVersion("react-router-native", version);
// FIXME: @remix-run/router is versioned differently and isn't being
// validated here

// 4. Publish to npm
publishBuild("router", tag);
publishBuild("react-router", tag);
publishBuild("react-router-dom", tag);
publishBuild("react-router-dom-v5-compat", tag);
publishBuild("react-router-native", tag);
publishBuild("@remix-run/router", tag);
} catch (error) {
console.log();
console.error(` ${error.message}`);
Expand Down
48 changes: 41 additions & 7 deletions scripts/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,33 +53,57 @@ async function run() {
let args = process.argv.slice(2);
let givenVersion = args[0];
let prereleaseId = args[1];
let isExperimental = givenVersion === "experimental";

// 0. Make sure the working directory is clean
ensureCleanWorkingDirectory();

// 1. Get the next version number
let currentRouterVersion = await getPackageVersion("router");
let currentVersion = await getPackageVersion("react-router");
let version = semver.valid(givenVersion);
if (version == null) {
version = getNextVersion(currentVersion, givenVersion, prereleaseId);
}

// We will only bump the router version if this is an experimental
let routerVersion = currentRouterVersion;

// 2. Confirm the next version number
let answer = await prompt(
`Are you sure you want to bump version ${currentVersion} to ${version}? [Yn] `
);

if (answer === false) return 0;

// We only handle @remix-run/router for experimental since in normal/pre
// releases it's versioned independently from the rest of the packages
if (isExperimental) {
routerVersion = version;
// 2.5. Update @remix-run/router version
await updatePackageConfig("router", (config) => {
config.version = routerVersion;
});
console.log(
chalk.green(` Updated @remix-run/router to version ${version}`)
);
}

// 3. Update react-router version
await updatePackageConfig("react-router", (config) => {
config.version = version;
if (isExperimental) {
config.dependencies["@remix-run/router"] = routerVersion;
}
});
console.log(chalk.green(` Updated react-router to version ${version}`));

// 4. Update react-router-dom version + react-router dep
await updatePackageConfig("react-router-dom", (config) => {
config.version = version;
if (isExperimental) {
config.dependencies["@remix-run/router"] = routerVersion;
}
config.dependencies["react-router"] = version;
});
console.log(
Expand Down Expand Up @@ -111,20 +135,30 @@ async function run() {
if (!stat.isDirectory()) continue;

await updateExamplesPackageConfig(example, (config) => {
config.dependencies["react-router"] = version;
config.dependencies["react-router-dom"] = version;
if (config.dependencies["@remix-run/router"]) {
config.dependencies["@remix-run/router"] = routerVersion;
}
if (config.dependencies["react-router"]) {
config.dependencies["react-router"] = version;
}
if (config.dependencies["react-router-dom"]) {
config.dependencies["react-router-dom"] = version;
}
});
}

// 7. Commit and tag
execSync(`git commit --all --message="Version ${version}"`);
execSync(`git tag -a -m "Version ${version}" v${version}`);
console.log(chalk.green(` Committed and tagged version ${version}`));
console.log(
chalk.red(
` 🚨 @remix-run/router isn't handled by this script, do it manually!`
)
);

if (givenVersion !== "experimental") {
console.log(
chalk.red(
` 🚨 @remix-run/router isn't handled by this script, do it manually!`
)
);
}
} catch (error) {
console.log();
console.error(chalk.red(` ${error.message}`));
Expand Down