@justeattakeaway/pie-monorepo-utils 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "pie-assistive-text": "beta",
3
- "pie-breadcrumb": "alpha",
3
+ "pie-avatar": "alpha",
4
+ "pie-breadcrumb": "beta",
4
5
  "pie-button": "stable",
5
6
  "pie-card": "beta",
6
7
  "pie-checkbox": "beta",
@@ -11,12 +12,13 @@
11
12
  "pie-form-label": "alpha",
12
13
  "pie-icon-button": "stable",
13
14
  "pie-link": "stable",
15
+ "pie-list": "alpha",
14
16
  "pie-lottie-player": "alpha",
15
17
  "pie-modal": "stable",
16
18
  "pie-notification": "beta",
17
19
  "pie-radio": "beta",
18
20
  "pie-radio-group": "beta",
19
- "pie-select": "alpha",
21
+ "pie-select": "beta",
20
22
  "pie-spinner": "stable",
21
23
  "pie-switch": "stable",
22
24
  "pie-tag": "beta",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@justeattakeaway/pie-monorepo-utils",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Scripts and utilities used by the PIE monorepo",
5
5
  "repository": {
6
6
  "type": "git",
@@ -11,6 +11,9 @@
11
11
  "files": [
12
12
  "dist"
13
13
  ],
14
+ "bin": {
15
+ "detect-webc-major-version": "./webc-major-versioning/detect-webc-major-version.js"
16
+ },
14
17
  "scripts": {
15
18
  "generate:component-statuses": "node ./component-statuses/generate-component-statuses.js",
16
19
  "lint:scripts": "run -T eslint .",
@@ -21,5 +24,9 @@
21
24
  },
22
25
  "volta": {
23
26
  "extends": "../../../package.json"
27
+ },
28
+ "dependencies": {
29
+ "@changesets/parse": "0.4.1",
30
+ "chalk": "4.1.2"
24
31
  }
25
32
  }
@@ -0,0 +1,153 @@
1
+ #!/usr/bin/env node
2
+ // CLI tool to check for missing major bump in pie-webc after changeset creation
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const chalk = require('chalk');
6
+ const parseChangesetFile = require('@changesets/parse').default;
7
+ const { execSync } = require('child_process');
8
+ const findMonorepoRoot = require('../utils/find-monorepo-root');
9
+ const getPackageVersion = require('../utils/get-package-version');
10
+ const getChangesetFilesInCurrentBranch = require('../utils/get-changeset-files-in-current-branch');
11
+
12
+ const monorepoRoot = findMonorepoRoot();
13
+
14
+ function getWebcInternalDependencies () {
15
+ const packageJsonPath = path.join(monorepoRoot, 'packages/components/pie-webc/package.json');
16
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
17
+ const dependencies = packageJson.dependencies || {};
18
+ return Object.keys(dependencies).filter((dep) => dep.startsWith('@justeattakeaway/pie-'));
19
+ }
20
+
21
+ function getWorkspacePackages (monorepoRoot) {
22
+ try {
23
+ const output = execSync('yarn workspaces list --json', { encoding: 'utf-8', cwd: monorepoRoot });
24
+ return output.split('\n').filter(Boolean).map((line) => JSON.parse(line));
25
+ } catch (err) {
26
+ // eslint-disable-next-line no-console
27
+ console.error(chalk.red(err.message));
28
+ process.exit(1);
29
+ }
30
+ return []; // fallback for linting
31
+ }
32
+
33
+ function getDepVersionAndStatus (depName, workspacePackages) {
34
+ const dep = workspacePackages.find((pkg) => pkg.name === depName);
35
+ if (!dep) {
36
+ // eslint-disable-next-line no-console
37
+ console.error(chalk.red(`Could not find location for dependency: ${depName}`));
38
+ process.exit(1);
39
+ }
40
+ const depPkgPath = path.join(monorepoRoot, dep.location, 'package.json');
41
+ try {
42
+ const version = getPackageVersion(path.join(monorepoRoot, dep.location));
43
+ const depPkg = JSON.parse(fs.readFileSync(depPkgPath, 'utf-8'));
44
+ const status = depPkg.pieMetadata && depPkg.pieMetadata.componentStatus;
45
+ if (!status) {
46
+ // eslint-disable-next-line no-console
47
+ console.error(chalk.red(`No componentStatus found in ${depPkgPath}. Unable to determine if pie-webc needs a major bump.`));
48
+ process.exit(1);
49
+ }
50
+ return { version, status };
51
+ } catch (err) {
52
+ // eslint-disable-next-line no-console
53
+ console.error(`Could not read or parse ${depPkgPath}:`, err.message);
54
+ process.exit(1);
55
+ }
56
+ return { version: null, status: null }; // fallback for linting
57
+ }
58
+
59
+ function printWebcVersioningWarning ({ title, dependencies }) {
60
+ if (process.env.GITHUB_ACTIONS) {
61
+ const depsBlock = dependencies.length > 0
62
+ ? `**Major changes detected in PIE Webc dependencies:**\n${dependencies.map((dep) => `- ${dep}`).join('\n')}\n`
63
+ : '';
64
+ const markdown = `
65
+ ## :warning: ${title}
66
+
67
+ ${depsBlock}
68
+ You must also add a **major changeset** for \`@justeattakeaway/pie-webc\` detailing the breaking changes, and a migration path for consumers.
69
+
70
+ **To fix:**
71
+ 1. Run \`yarn changeset\` and select \`@justeattakeaway/pie-webc\` for a major bump.
72
+ 2. Commit the new changeset file.
73
+ `;
74
+ console.error(markdown.trim());
75
+ } else {
76
+ let depsBlock = '';
77
+ if (dependencies.length > 0) {
78
+ depsBlock = `🦋 Major changes detected in PIE Webc dependencies:\n${
79
+ dependencies.map((dep) => `🦋 - ${dep}`).join('\n')}\n`;
80
+ }
81
+ const terminal =
82
+ `${chalk.red.bold(`🦋 ${title}`)}\n\n${
83
+ depsBlock
84
+ }🦋 You must also add a major changeset for ${chalk.bold('@justeattakeaway/pie-webc')
85
+ } detailing the breaking changes, and a migration path for consumers\n\n` +
86
+ '🦋 To fix:\n' +
87
+ `🦋 1. Run ${chalk.cyan('yarn changeset')} and select ${chalk.bold('@justeattakeaway/pie-webc')} for a major bump.\n` +
88
+ '🦋 2. Commit the new changeset file.\n';
89
+ console.error(terminal.trim());
90
+ }
91
+ }
92
+
93
+ function checkWebcMajorVersioning () {
94
+ const webcDependencies = getWebcInternalDependencies();
95
+ const branchChangesetFiles = getChangesetFilesInCurrentBranch(monorepoRoot);
96
+ const workspacePackages = getWorkspacePackages(monorepoRoot);
97
+ let hasWebcMajorBump = false;
98
+ const webcDependenciesWithMajorBump = [];
99
+ const pieWebcMajorBumpChangesetFiles = [];
100
+
101
+ branchChangesetFiles.forEach((file) => {
102
+ try {
103
+ const content = fs.readFileSync(file, 'utf-8');
104
+ const { releases } = parseChangesetFile(content);
105
+ releases.forEach(({ name, type }) => {
106
+ if (name === '@justeattakeaway/pie-webc' && type === 'major') {
107
+ hasWebcMajorBump = true;
108
+ pieWebcMajorBumpChangesetFiles.push(file);
109
+ }
110
+
111
+ if (webcDependencies.includes(name) && type === 'major') {
112
+ const { version, status } = getDepVersionAndStatus(name, workspacePackages);
113
+
114
+ /* Ignore component status promotion.
115
+ 0.x.x -> 1.x.x is a major bump, but we don't want to require a major bump for pie-webc if the dependency is only being promoted from beta to stable.
116
+ 0.x.x with 'stable' status will only be possible before the 'Version Packages' PR is merged.
117
+ */
118
+ if (version && version.startsWith('0.') && (status === 'alpha' || status === 'beta' || status === 'stable')) {
119
+ return;
120
+ }
121
+ webcDependenciesWithMajorBump.push(name);
122
+ }
123
+ });
124
+ } catch (e) {
125
+ // eslint-disable-next-line no-console
126
+ console.error(chalk.red(`Error parsing changeset file ${file}:`, e.message));
127
+ process.exit(1);
128
+ }
129
+ });
130
+
131
+ if (webcDependenciesWithMajorBump.length > 0 && !hasWebcMajorBump) {
132
+ printWebcVersioningWarning({
133
+ title: 'PIE Webc Versioning Warning',
134
+ dependencies: webcDependenciesWithMajorBump,
135
+ });
136
+ process.exit(1);
137
+ }
138
+
139
+ if (webcDependenciesWithMajorBump.length > 0 && hasWebcMajorBump) {
140
+ // eslint-disable-next-line no-console
141
+ console.log(chalk.green('🦋 PIE Webc versioning check passed.'));
142
+ if (pieWebcMajorBumpChangesetFiles.length > 0) {
143
+ // eslint-disable-next-line no-console
144
+ console.log(chalk.green('🦋 Major bump for @justeattakeaway/pie-webc found in:'));
145
+ pieWebcMajorBumpChangesetFiles.forEach((filePath) => {
146
+ // eslint-disable-next-line no-console
147
+ console.log(chalk.green(` - ${filePath}`));
148
+ });
149
+ }
150
+ }
151
+ }
152
+
153
+ checkWebcMajorVersioning();