Skip to content

Commit

Permalink
Merge pull request #97 from DataDog/hardy.jones/uiapps-104/link-ui-ex…
Browse files Browse the repository at this point in the history
…tensions-packages

UIAPPS-104 Link UI Extensions packages
  • Loading branch information
joneshf-dd authored Jan 19, 2022
2 parents c91bf71 + e634583 commit abbb7fb
Show file tree
Hide file tree
Showing 10 changed files with 236 additions and 10 deletions.
14 changes: 14 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,17 @@ We try to clarify the configuration that might not be immediately straight-forwa
We're setting this to all of the examples so we don't end up trying to bump their versions.
It seems like that's not the proper way to use this configuration,
but it doesn't look like there's another way to get the behavior we want.

### `linked`

We're linking the `@datadog/ui-extensions-*` packages together because we want them to all have the same version.
This is only part of the story.
`linked` does keep the versions the same,
but only if every package has a changeset.
The other part of the story is the [check fixed packages script][].
This script makes sure we should always have a changeset for all of the `@datadog/ui-extensions-*` packages if any of them changes.

If `changesets` gets a feature to have actually "fixed" packages,
we can move to using that instead of this.

[check fixed packages script]: ../scripts/check-fixed-packages-ui-extensions.js
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"changelog": "@changesets/cli/changelog",
"commit": false,
"ignore": ["datadog-app-example-*"],
"linked": [],
"linked": [["@datadog/ui-extensions-*"]],
"updateInternalDependencies": "minor"
}
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ module.exports = {
'**/*.config.js',
'**/test-helpers.*',
'**/*.test-helpers.*',
'**/*test.utils.*'
'**/*test.utils.*',
'scripts/*'
]
}
],
Expand Down
15 changes: 15 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ We use [`changesets`][] to help with normal package releases.
When a normal PR is merged, [`changsets`][] will keep track of any [changeset][]s in this long-running PR.
When we're ready to release some number of packages, we can merge this long-running PR and [`changesets`][] will release all packages with a [changeset][].

## `@datadog/ui-extensions-*` packages

These packages are all released at the same version.
The intention is to make it so App Developers have an easier time with updates.
If we say,
"Check out this wonderful feature in 0.36.0!"
App Developers should be able to update whatever `@datadog/ui-extensions-*` packages they have to 0.36.0 and be on their way.

The alternative would be to allow different versions for each package.
That allows more flexibility and lower version churn at the expense of confusion with version updates.
A similar example to the above might be worded like,
"Check out this wonderful feature in 0.36.0 of `@datadog/ui-extensions-sdk`, 2.3.0 of `@datadog/ui-extensions-react`, 1.46.0 of `@datadog/ui-extensions-vue`, etc."
While that's a model that many other groups of packages follow,
we're opting for keeping all the versions the same.

[`auto`]: https://intuit.github.io/auto/
[`changesets`]: https://github.com/changesets/changesets
[changeset]: https://github.com/changesets/changesets/blob/main/docs/detailed-explanation.md
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"lint:check": "eslint '**/*.{ts,js}'",
"lint:fix": "yarn run lint:check --fix",
"lint": "yarn run lint:check && prettier --check .",
"postinstall": "patch-package",
"prepare": "yarn workspaces run prepare",
"release:canary": "auto shipit",
"release:packages": "changeset publish",
Expand All @@ -21,7 +22,9 @@
"test:example-packages:ui-extensions-sdk-version": "./scripts/check-example-packages-ui-extensions-sdk-version.js",
"test:example-packages:version": "./scripts/check-example-packages-version.js",
"test:example-packages": "yarn test:example-packages:name && yarn test:example-packages:private && yarn test:example-packages:ui-extensions-sdk-version && yarn test:example-packages:version",
"test": "yarn test:example-packages && yarn workspaces run test"
"test:fixed-packages:ui-extensions": "./scripts/check-fixed-packages-ui-extensions.js",
"test:fixed-packages": "yarn test:fixed-packages:ui-extensions",
"test": "yarn test:example-packages && yarn test:fixed-packages && yarn workspaces run test"
},
"license": "Apache-2.0",
"private": true,
Expand All @@ -32,10 +35,12 @@
],
"devDependencies": {
"@changesets/cli": "2.18.1",
"@changesets/get-release-plan": "3.0.4",
"@typescript-eslint/eslint-plugin": "4.22.0",
"@typescript-eslint/parser": "4.22.0",
"auto": "10.32.5",
"babel-eslint": "10.1.0",
"eslint": "7.25.0",
"eslint-config-airbnb-base": "14.2.1",
"eslint-config-prettier": "8.3.0",
"eslint-config-react-app": "6.0.0",
Expand All @@ -48,11 +53,12 @@
"eslint-plugin-jsx-a11y": "6.4.1",
"eslint-plugin-no-storage": "1.0.2",
"eslint-plugin-prettier": "3.4.0",
"eslint-plugin-react-hooks": "4.2.0",
"eslint-plugin-react": "7.24.0",
"eslint-plugin-react-hooks": "4.2.0",
"eslint-plugin-testing-library": "3.10.2",
"eslint": "7.25.0",
"lerna": "4.0.0",
"patch-package": "6.4.7",
"postinstall-postinstall": "2.1.0",
"prettier": "2.1.2",
"typedoc": "0.22.10",
"typescript": "4.5.4"
Expand Down
16 changes: 16 additions & 0 deletions patches/@changesets+assemble-release-plan+5.0.3.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
diff --git a/node_modules/@changesets/assemble-release-plan/dist/assemble-release-plan.cjs.dev.js b/node_modules/@changesets/assemble-release-plan/dist/assemble-release-plan.cjs.dev.js
index 20a16c8..cf83233 100644
--- a/node_modules/@changesets/assemble-release-plan/dist/assemble-release-plan.cjs.dev.js
+++ b/node_modules/@changesets/assemble-release-plan/dist/assemble-release-plan.cjs.dev.js
@@ -243,6 +243,11 @@ function shouldBumpMajor({
preInfo,
onlyUpdatePeerDependentsWhenOutOfRange
}) {
+ // Don't force a major bump if the dependent is a peer deependency and it's an exact version.
+ if (depType === "peerDependencies" && versionRange === nextRelease.oldVersion) {
+ return false;
+ }
+
// we check if it is a peerDependency because if it is, our dependent bump type might need to be major.
return depType === "peerDependencies" && nextRelease.type !== "none" && nextRelease.type !== "patch" && ( // 1. If onlyUpdatePeerDependentsWhenOutOfRange set to true, bump major if the version is leaving the range.
// 2. If onlyUpdatePeerDependentsWhenOutOfRange set to false, bump major regardless whether or not the version is leaving the range.
17 changes: 17 additions & 0 deletions patches/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# `npm` patches

This directory holds patches for `npm` dependencies.

## `@changesets/assemble-release-plan`

This patch makes it so peer dependencies that are exact don't force a major bump in `changesets`.
We should still be able to make major bumps,
but they shouldn't happen due to exact peer dependencies.

This only really works for packages that are "linked."
We should probably add a check for that in the same logic,
but we should really raise the issue upstream and see if there's a fix for it.

It's not clear whether or not this will go away when ["fixed" packages][] are implemented.

["fixed" packages]: https://github.com/changesets/changesets/pull/690
59 changes: 59 additions & 0 deletions scripts/check-fixed-packages-ui-extensions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env node
const getReleasePlan = require('@changesets/get-release-plan').default;

const packageInfo = require('./package-info');

/**
* Checks that if any `@datadog/ui-extensions-*` package is getting a release,
* all `@datadog/ui-extensions-*` packages are getting a release.
*
* While `changesets` does have support for "linked" packages:
* https://github.com/changesets/changesets/blob/main/docs/linked-packages.md,
* it's not exactly what we want.
* The way "linked" packages work,
* we can still leave out packages that we want to be on the same version.
*
* We do still want "linked" packages in our `.changeset/config.json`,
* since it means we'll always get everything on the same version.
* To that end,
* this check doesn't need to actually look at specific version numbers.
* We just have to catch packages that might be missed.
*
* The behavior we want is actually what's being proposed as "fixed" packages:
* https://github.com/changesets/changesets/pull/690.
* Until that feature is released,
* we have this check to make sure we release packages in lock-step.
*/
async function main() {
const errors = [];

const releasePlan = await getReleasePlan('.');
const releases = releasePlan.changesets.flatMap(changeset => {
return changeset.releases;
});
const packageNames = releases.map(release => {
return release.name;
});
const hasUIExtensionsPackages = packageNames.some(packageName => {
return packageName.startsWith('@datadog/ui-extensions-');
});

if (!hasUIExtensionsPackages) {
return;
}

const uiExtensionsPackages = packageInfo.getUIExtensionsPackages();
for (const uiExtensionsPackage of uiExtensionsPackages) {
if (packageNames.includes(uiExtensionsPackage.packageJSON.name)) {
continue;
}

errors.push(
`${uiExtensionsPackage.filename}: please use "yarn changeset add" to add a changeset for "${uiExtensionsPackage.packageJSON.name}".`
);
}

packageInfo.handleErrors(errors);
}

main();
20 changes: 17 additions & 3 deletions scripts/package-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ const fs = require('fs');
const os = require('os');
const path = require('path');

const exampleDir = 'examples';
const packageJSONPattern = path.join(exampleDir, '*', 'package.json');

function getPackageJSONInfo(filename) {
const buffer = fs.readFileSync(filename);
const packageJSON = JSON.parse(buffer.toString());
Expand All @@ -17,6 +14,12 @@ function getPackageJSONInfo(filename) {
}

function getExamples() {
const packageJSONPattern = path.join('examples', '*', 'package.json');

return getPackages(packageJSONPattern);
}

function getPackages(packageJSONPattern) {
const gitLSFiles = child_process.execSync(
`git ls-files '${packageJSONPattern}'`
);
Expand All @@ -31,6 +34,16 @@ function getExamples() {
return packageJSONs;
}

function getUIExtensionsPackages() {
const packageJSONPattern = path.join(
'packages',
'ui-extensions-*',
'package.json'
);

return getPackages(packageJSONPattern);
}

function getUIExtensionsSDK() {
return getPackageJSONInfo('packages/ui-extensions-sdk/package.json');
}
Expand All @@ -47,6 +60,7 @@ function handleErrors(errors) {

module.exports = {
getExamples,
getUIExtensionsPackages,
getUIExtensionsSDK,
handleErrors
};
Loading

0 comments on commit abbb7fb

Please sign in to comment.