Skip to content

Commit 3c6d686

Browse files
authored
build: constraints added to linting (#3533)
- add constraints to linting - clean up and organize constraints code - add dependency alignment to constraints
1 parent 8f0bb0d commit 3c6d686

File tree

3 files changed

+62
-30
lines changed

3 files changed

+62
-30
lines changed

.changeset/config.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"linked": [],
1212
"access": "public",
1313
"baseBranch": "main",
14-
"updateInternalDependencies": "minor",
15-
"bumpVersionsWithWorkspaceProtocolOnly": true,
14+
"updateInternalDependencies": "patch",
1615
"ignore": []
1716
}

lint-staged.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ module.exports = {
66
"*.{js,json}": [
77
"eslint --fix --cache --no-error-on-unmatched-pattern --quiet"
88
],
9+
"package.json": [
10+
"yarn constraints --fix"
11+
],
912
"dist/*.css": [
1013
"prettier --no-config --no-error-on-unmatched-pattern --ignore-unknown --log-level silent --write --config .prettierrc"
1114
],

yarn.config.cjs

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ const fg = require("fast-glob");
99

1010
module.exports = defineConfig({
1111
async constraints({ Yarn }) {
12-
// Fetch a list of all the component workspaces using a glob pattern
12+
/**
13+
* Fetch a list of all the component workspaces using a glob pattern
14+
* @type {string[]} components
15+
*/
1316
const components = fg.sync("components/*", {
1417
cwd: __dirname,
1518
onlyDirectories: true,
@@ -49,7 +52,47 @@ module.exports = defineConfig({
4952
return ["design-system", "spectrum", "spectrum-css", "adobe", "adobe-spectrum", ...additionalKeywords];
5053
}
5154

52-
for (const workspace of Yarn.workspaces()) {
55+
/**
56+
* This function rolls up all the component package.json
57+
* requirements for all workspaces into a single function
58+
* to simplify into a readable set of operations
59+
* @param {Workspace} workspace
60+
* @param {string} folderName
61+
* @returns {void}
62+
*/
63+
function validateComponentPackageJson(workspace, folderName) {
64+
// Only update the homepage if it does not already exist
65+
if (!workspace.manifest.homepage) {
66+
workspace.set("homepage", `https://opensource.adobe.com/spectrum-css/?path=/docs/components-${folderName}--docs`);
67+
}
68+
69+
workspace.set("publishConfig.access", "public");
70+
workspace.set("keywords", keywords(["component", "css"]));
71+
workspace.set("main", "dist/index.css");
72+
workspace.set("exports", {
73+
".": "./dist/index.css",
74+
"./*.md": "./*.md",
75+
"./dist/*": "./dist/*",
76+
"./index-*.css": "./dist/index-*.css",
77+
"./index.css": "./dist/index.css",
78+
"./metadata.json": "./dist/metadata.json",
79+
"./package.json": "./package.json",
80+
"./stories/*": "./stories/*"
81+
});
82+
}
83+
84+
/**
85+
* This function rolls up all the package.json requirements
86+
* for all workspaces into a single function to simplify
87+
* the workspace for loop into a readable set of operations
88+
* @param {Workspace} workspace
89+
* @returns {void}
90+
*/
91+
function validatePackageJson(workspace) {
92+
const isRoot = workspace.cwd === ".";
93+
const isComponent = components.includes(workspace.cwd);
94+
const isToken = workspace.cwd === "tokens";
95+
5396
/**
5497
* -------------- GLOBAL --------------
5598
* Global configuration for all workspaces
@@ -61,45 +104,24 @@ module.exports = defineConfig({
61104
workspace.set("repository.url", "https://github.com/adobe/spectrum-css.git");
62105

63106
// We don't need to set the directory for the root workspace
64-
if (workspace.cwd !== ".") {
65-
workspace.set("repository.directory", workspace.cwd);
66-
}
107+
if (!isRoot) workspace.set("repository.directory", workspace.cwd);
67108

68109
workspace.set("bugs.url", "https://github.com/adobe/spectrum-css/issues");
69110

70111
/**
71112
* -------------- COMPONENTS --------------
72113
* Process the components workspaces with component-specific configuration
73114
*/
74-
if (components.includes(workspace.cwd)) {
115+
if (isComponent) {
75116
const folderName = workspace.cwd?.split("/")?.[1];
76-
77-
// Only update the homepage if it does not already exist
78-
if (!workspace.manifest.homepage) {
79-
workspace.set("homepage", `https://opensource.adobe.com/spectrum-css/?path=/docs/components-${folderName}--docs`);
80-
}
81-
82-
workspace.set("publishConfig.access", "public");
83-
workspace.set("keywords", keywords(["component", "css"]));
84-
workspace.set("main", "dist/index.css");
85-
workspace.set("exports", {
86-
".": "./dist/index.css",
87-
"./*.md": "./*.md",
88-
"./dist/*": "./dist/*",
89-
"./index-*.css": "./dist/index-*.css",
90-
"./index.css": "./dist/index.css",
91-
"./metadata.json": "./dist/metadata.json",
92-
"./package.json": "./package.json",
93-
"./stories/*": "./stories/*"
94-
});
95-
117+
validateComponentPackageJson(workspace, folderName);
96118
validateLocalPackages(workspace);
97119
}
98120
/**
99121
* -------------- TOKENS --------------
100122
* Process the tokens workspace with token-specific configuration
101123
*/
102-
else if (workspace.cwd === "tokens") {
124+
else if (isToken) {
103125
workspace.set("homepage", "https://opensource.adobe.com/spectrum-css");
104126
workspace.set("publishConfig.access", "public");
105127
workspace.set("keywords", keywords(["tokens", "css"]));
@@ -113,13 +135,21 @@ module.exports = defineConfig({
113135
* All other workspaces should have at least the following configuration
114136
*/
115137
if (!workspace.manifest.keywords) {
116-
workspace.set("keywords", keywords([]));
138+
workspace.set("keywords", keywords());
117139
}
118140

119141
if (!workspace.manifest.homepage) {
120142
workspace.set("homepage", "https://opensource.adobe.com/spectrum-css/");
121143
}
122144
}
123145
}
146+
147+
/**
148+
* This loop iterates over all the workspaces in the project
149+
* and updates the package.json file with the necessary
150+
*/
151+
for (const workspace of Yarn.workspaces()) {
152+
validatePackageJson(workspace);
153+
}
124154
},
125155
});

0 commit comments

Comments
 (0)