diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 729e8482d7..f31e5f7122 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -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 diff --git a/package.json b/package.json index 978f9c9542..d2cf1bd74a 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/scripts/publish.js b/scripts/publish.js index 91c638cd8a..fc998b9088 100644 --- a/scripts/publish.js +++ b/scripts/publish.js @@ -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, @@ -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(); @@ -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"; 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); + } 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}`); diff --git a/scripts/version.js b/scripts/version.js index 0895516c89..30497c5c17 100644 --- a/scripts/version.js +++ b/scripts/version.js @@ -53,17 +53,22 @@ 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] ` @@ -71,15 +76,34 @@ async function run() { 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( @@ -111,8 +135,15 @@ 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; + } }); } @@ -120,11 +151,14 @@ async function run() { 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}`));