-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Actually ship the correct
package.json
files to npm
- Loading branch information
Showing
6 changed files
with
132 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@discordkit/client": patch | ||
"@discordkit/core": patch | ||
--- | ||
|
||
Added a new versioning script to workaround `@changeset/cli`'s inability to correctly run `yarn npm publish`, which accidentally leaves workspace protocol dependency versions unchanged and published to npm. Shoutout to https://github.com/PrairieLearn/PrairieLearn/pull/7533 for the fix. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Adapted from https://github.com/PrairieLearn/PrairieLearn/pull/7533 | ||
// | ||
// Changesets doesn't currently support workspace versions: | ||
// https://github.com/changesets/changesets/issues/432 | ||
// https://github.com/changesets/action/issues/246 | ||
// To work around that, we'll manually resolve any `workspace:` version ranges | ||
// with this tool prior to publishing. If/when changesets adds native support | ||
// for publishing with Yarn 3, we can remove this script. | ||
// We'll only support the `workspace:^` range, which is the only one we | ||
// generally want to use. | ||
|
||
import cp from "node:child_process"; | ||
import fs from "node:fs/promises"; | ||
import path from "node:path"; | ||
import util from "node:util"; | ||
|
||
const DEPENDENCY_TYPES = [ | ||
`dependencies`, | ||
`devDependencies`, | ||
`peerDependencies` | ||
]; | ||
|
||
const exec = util.promisify(cp.exec); | ||
|
||
const rawWorkspaces = await exec(`yarn workspaces list --json`, { | ||
encoding: `utf8` | ||
}); | ||
|
||
const workspaces = rawWorkspaces.stdout | ||
.trim() | ||
.split(`\n`) | ||
.map((line) => JSON.parse(line)) | ||
.filter((workspace) => workspace.location !== `.`); | ||
|
||
// Get the version of each workspace package. | ||
const workspaceVersions = new Map( | ||
await Promise.all( | ||
workspaces.map<Promise<[name: string, version: string]>>( | ||
async (workspace) => { | ||
const packageJsonPath = path.join(workspace.location, `package.json`); | ||
const packageJson = JSON.parse( | ||
await fs.readFile(packageJsonPath, `utf8`) | ||
); | ||
return [workspace.name, packageJson.version]; | ||
} | ||
) | ||
) | ||
); | ||
|
||
// Replace any `workspace:^` version ranges with the actual version. | ||
await Promise.all( | ||
workspaces.map(async (workspace) => { | ||
const packageJsonPath = path.join(workspace.location, `package.json`); | ||
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, `utf8`)); | ||
|
||
for (const dependencyType of DEPENDENCY_TYPES) { | ||
const dependencies = Object.keys(packageJson[dependencyType] ?? {}); | ||
for (const dependency of dependencies) { | ||
const dependencyVersion = packageJson[dependencyType][dependency]; | ||
if (dependencyVersion.startsWith(`workspace:`)) { | ||
if (!dependencyVersion.startsWith(`workspace:^`)) { | ||
throw new Error( | ||
`Unsupported workspace version range: ${dependencyVersion}` | ||
); | ||
} | ||
|
||
const realVersion = workspaceVersions.get(dependency); | ||
if (!realVersion) { | ||
throw new Error( | ||
`Could not find version for workspace ${dependency}` | ||
); | ||
} | ||
|
||
packageJson[dependencyType][dependency] = `^${realVersion}`; | ||
} | ||
} | ||
} | ||
|
||
await fs.writeFile( | ||
packageJsonPath, | ||
`${JSON.stringify(packageJson, null, 2)}\n` | ||
); | ||
}) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters