Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: constraints added to linting #3533

Merged
merged 2 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "minor",
"bumpVersionsWithWorkspaceProtocolOnly": true,
"updateInternalDependencies": "patch",
"ignore": []
}
3 changes: 3 additions & 0 deletions lint-staged.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ module.exports = {
"*.{js,json}": [
"eslint --fix --cache --no-error-on-unmatched-pattern --quiet"
],
"package.json": [
"yarn constraints --fix"
],
"dist/*.css": [
"prettier --no-config --no-error-on-unmatched-pattern --ignore-unknown --log-level silent --write --config .prettierrc"
],
Expand Down
86 changes: 58 additions & 28 deletions yarn.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ const fg = require("fast-glob");

module.exports = defineConfig({
async constraints({ Yarn }) {
// Fetch a list of all the component workspaces using a glob pattern
/**
* Fetch a list of all the component workspaces using a glob pattern
* @type {string[]} components
*/
const components = fg.sync("components/*", {
cwd: __dirname,
onlyDirectories: true,
Expand Down Expand Up @@ -49,7 +52,47 @@ module.exports = defineConfig({
return ["design-system", "spectrum", "spectrum-css", "adobe", "adobe-spectrum", ...additionalKeywords];
}

for (const workspace of Yarn.workspaces()) {
/**
* This function rolls up all the component package.json
* requirements for all workspaces into a single function
* to simplify into a readable set of operations
* @param {Workspace} workspace
* @param {string} folderName
* @returns {void}
*/
function validateComponentPackageJson(workspace, folderName) {
// Only update the homepage if it does not already exist
if (!workspace.manifest.homepage) {
workspace.set("homepage", `https://opensource.adobe.com/spectrum-css/?path=/docs/components-${folderName}--docs`);
}

workspace.set("publishConfig.access", "public");
workspace.set("keywords", keywords(["component", "css"]));
workspace.set("main", "dist/index.css");
workspace.set("exports", {
".": "./dist/index.css",
"./*.md": "./*.md",
"./dist/*": "./dist/*",
"./index-*.css": "./dist/index-*.css",
"./index.css": "./dist/index.css",
"./metadata.json": "./dist/metadata.json",
"./package.json": "./package.json",
"./stories/*": "./stories/*"
});
}

/**
* This function rolls up all the package.json requirements
* for all workspaces into a single function to simplify
* the workspace for loop into a readable set of operations
* @param {Workspace} workspace
* @returns {void}
*/
function validatePackageJson(workspace) {
const isRoot = workspace.cwd === ".";
const isComponent = components.includes(workspace.cwd);
const isToken = workspace.cwd === "tokens";

/**
* -------------- GLOBAL --------------
* Global configuration for all workspaces
Expand All @@ -61,45 +104,24 @@ module.exports = defineConfig({
workspace.set("repository.url", "https://github.com/adobe/spectrum-css.git");

// We don't need to set the directory for the root workspace
if (workspace.cwd !== ".") {
workspace.set("repository.directory", workspace.cwd);
}
if (!isRoot) workspace.set("repository.directory", workspace.cwd);

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

/**
* -------------- COMPONENTS --------------
* Process the components workspaces with component-specific configuration
*/
if (components.includes(workspace.cwd)) {
if (isComponent) {
const folderName = workspace.cwd?.split("/")?.[1];

// Only update the homepage if it does not already exist
if (!workspace.manifest.homepage) {
workspace.set("homepage", `https://opensource.adobe.com/spectrum-css/?path=/docs/components-${folderName}--docs`);
}

workspace.set("publishConfig.access", "public");
workspace.set("keywords", keywords(["component", "css"]));
workspace.set("main", "dist/index.css");
workspace.set("exports", {
".": "./dist/index.css",
"./*.md": "./*.md",
"./dist/*": "./dist/*",
"./index-*.css": "./dist/index-*.css",
"./index.css": "./dist/index.css",
"./metadata.json": "./dist/metadata.json",
"./package.json": "./package.json",
"./stories/*": "./stories/*"
});

validateComponentPackageJson(workspace, folderName);
validateLocalPackages(workspace);
}
/**
* -------------- TOKENS --------------
* Process the tokens workspace with token-specific configuration
*/
else if (workspace.cwd === "tokens") {
else if (isToken) {
workspace.set("homepage", "https://opensource.adobe.com/spectrum-css");
workspace.set("publishConfig.access", "public");
workspace.set("keywords", keywords(["tokens", "css"]));
Expand All @@ -113,13 +135,21 @@ module.exports = defineConfig({
* All other workspaces should have at least the following configuration
*/
if (!workspace.manifest.keywords) {
workspace.set("keywords", keywords([]));
workspace.set("keywords", keywords());
}

if (!workspace.manifest.homepage) {
workspace.set("homepage", "https://opensource.adobe.com/spectrum-css/");
}
}
}

/**
* This loop iterates over all the workspaces in the project
* and updates the package.json file with the necessary
*/
for (const workspace of Yarn.workspaces()) {
validatePackageJson(workspace);
}
},
});
Loading