Skip to content

Commit 03263ec

Browse files
authored
Merge branch 'main' into pvashish/swc-703
2 parents 396c0de + 72be866 commit 03263ec

File tree

3 files changed

+204
-0
lines changed

3 files changed

+204
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
"@web/test-runner-playwright": "^0.11.0",
147147
"@web/test-runner-visual-regression": "^0.9.0",
148148
"@webcomponents/webcomponentsjs": "^2.8.0",
149+
"@yarnpkg/types": "^4.0.1",
149150
"alex": "^11.0.1",
150151
"cem-plugin-module-file-extensions": "^0.0.5",
151152
"chromatic": "^11.20.0",

yarn.config.cjs

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
/* eslint-disable @typescript-eslint/no-var-requires */
2+
/*!
3+
* Copyright 2025 Adobe. All rights reserved.
4+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License. You may obtain a copy
6+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software distributed under
9+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
10+
* OF ANY KIND, either express or implied. See the License for the specific language
11+
* governing permissions and limitations under the License.
12+
*/
13+
14+
/** @type {import('@yarnpkg/types')} */
15+
const { defineConfig } = require('@yarnpkg/types');
16+
const fg = require('fast-glob');
17+
18+
/**
19+
* The workspace object used in the constraints function
20+
* @typedef {import('@yarnpkg/types').Yarn.Constraints.Workspace} Workspace
21+
*/
22+
23+
module.exports = defineConfig({
24+
async constraints({ Yarn }) {
25+
/**
26+
* Fetch a list of all the component workspaces using a glob pattern
27+
* @type {string[]} components
28+
*/
29+
const components = fg.sync('packages/*', {
30+
cwd: __dirname,
31+
onlyDirectories: true,
32+
});
33+
34+
/**
35+
* This function checks the workspace for any local package references
36+
* and ensure that the devDependencies are up-to-date with the latest version
37+
* currently in the project
38+
* @param {Workspace} workspace
39+
* @returns {void}
40+
*/
41+
function validateLocalPackages(workspace) {
42+
// Return early if the workspace does not have any peerDependencies
43+
if (!workspace.manifest.peerDependencies) {
44+
return;
45+
}
46+
47+
// Start by filtering out the local packages from the external dependencies
48+
const localPackages = Object.keys(
49+
workspace.manifest.peerDependencies
50+
)
51+
.filter((pkg) => Yarn.workspace({ ident: pkg }))
52+
.map((pkg) => Yarn.workspace({ ident: pkg }));
53+
54+
// Iterate over the local packages and ensure that the devDependencies are up-to-date
55+
for (const localWorkspace of localPackages) {
56+
const localVersion = localWorkspace.manifest.version;
57+
workspace.set(
58+
`devDependencies.${localWorkspace.manifest.name}`,
59+
localVersion ?? 'workspace:^'
60+
);
61+
}
62+
}
63+
64+
/**
65+
* A reusable function to add keywords to ensure workspaces
66+
* include a minimal set of keywords for discoverability
67+
* with additionalKeywords as an optional parameter to add more
68+
* specific keywords that are relevant to the workspace
69+
* @param {string[]} additionalKeywords
70+
* @returns {string[]}
71+
*/
72+
function keywords(additionalKeywords = []) {
73+
return [
74+
'design-system',
75+
'spectrum',
76+
'adobe',
77+
'adobe-spectrum',
78+
'web components',
79+
'web-components',
80+
'lit-element',
81+
'lit-html',
82+
...additionalKeywords,
83+
];
84+
}
85+
86+
/**
87+
* This function rolls up all the component package.json
88+
* requirements for all workspaces into a single function
89+
* to simplify into a readable set of operations
90+
* @param {Workspace} workspace
91+
* @param {string} folderName
92+
* @returns {void}
93+
*/
94+
function validateComponentPackageJson(workspace, folderName) {
95+
// Only update the homepage if it does not already exist
96+
if (!workspace.manifest.homepage) {
97+
workspace.set(
98+
'homepage',
99+
`https://opensource.adobe.com/spectrum-web-components/components/${folderName}`
100+
);
101+
}
102+
103+
workspace.set('publishConfig.access', 'public');
104+
workspace.set('type', 'module');
105+
workspace.set('keywords', keywords(['component', 'css']));
106+
107+
// A subset of components have a different entry point than the default
108+
if (
109+
['clear-button', 'close-button', 'modal', 'opacity-checkerboard'].includes(folderName)
110+
) {
111+
workspace.set('main', `./src/${folderName}.css.js`);
112+
workspace.set('module', `./src/${folderName}.css.js`);
113+
} else {
114+
workspace.set('main', './src/index.js');
115+
workspace.set('module', './src/index.js');
116+
}
117+
}
118+
119+
/**
120+
* This function rolls up all the package.json requirements
121+
* for all workspaces into a single function to simplify
122+
* the workspace for loop into a readable set of operations
123+
* @param {Workspace} workspace
124+
* @returns {void}
125+
*/
126+
function validatePackageJson(workspace) {
127+
const isRoot = workspace.cwd === '.';
128+
const isComponent = components.includes(workspace.cwd);
129+
130+
/**
131+
* -------------- GLOBAL --------------
132+
* Global configuration for all workspaces
133+
*/
134+
if (
135+
!workspace.manifest.license ||
136+
workspace.manifest.license === ''
137+
) {
138+
workspace.set('license', 'Apache-2.0');
139+
}
140+
141+
workspace.set('author', 'Adobe');
142+
143+
workspace.set('repository.type', 'git');
144+
workspace.set(
145+
'repository.url',
146+
'https://github.com/adobe/spectrum-web-components.git'
147+
);
148+
149+
// We don't need to set the directory for the root workspace
150+
if (!isRoot) {
151+
workspace.set('repository.directory', workspace.cwd);
152+
}
153+
154+
workspace.set(
155+
'bugs.url',
156+
'https://github.com/adobe/spectrum-web-components/issues'
157+
);
158+
159+
/**
160+
* -------------- COMPONENTS --------------
161+
* Process the components workspaces with component-specific configuration
162+
*/
163+
if (isComponent) {
164+
const folderName = workspace.cwd?.split('/')?.[1];
165+
validateComponentPackageJson(workspace, folderName);
166+
validateLocalPackages(workspace);
167+
} else {
168+
/**
169+
* -------------- OTHER --------------
170+
* All other workspaces should have at least the following configuration
171+
*/
172+
if (!workspace.manifest.keywords) {
173+
workspace.set('keywords', keywords());
174+
}
175+
176+
if (!workspace.manifest.homepage) {
177+
workspace.set(
178+
'homepage',
179+
'https://opensource.adobe.com/spectrum-web-components/'
180+
);
181+
}
182+
}
183+
}
184+
185+
/**
186+
* This loop iterates over all the workspaces in the project
187+
* and updates the package.json file with the necessary
188+
*/
189+
for (const workspace of Yarn.workspaces()) {
190+
validatePackageJson(workspace);
191+
}
192+
},
193+
});

yarn.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ __metadata:
244244
"@web/test-runner-playwright": "npm:^0.11.0"
245245
"@web/test-runner-visual-regression": "npm:^0.9.0"
246246
"@webcomponents/webcomponentsjs": "npm:^2.8.0"
247+
"@yarnpkg/types": "npm:^4.0.1"
247248
alex: "npm:^11.0.1"
248249
cem-plugin-module-file-extensions: "npm:^0.0.5"
249250
chromatic: "npm:^11.20.0"
@@ -11987,6 +11988,15 @@ __metadata:
1198711988
languageName: node
1198811989
linkType: hard
1198911990

11991+
"@yarnpkg/types@npm:^4.0.1":
11992+
version: 4.0.1
11993+
resolution: "@yarnpkg/types@npm:4.0.1"
11994+
dependencies:
11995+
tslib: "npm:^2.4.0"
11996+
checksum: 10c0/90226789475680ba599833571dd76c0718dd5b4c5022481263ef309d6a628f6246671cd6ca86e49c966ddefa7aca6ccef82240dc1476d2cea702ea5bee2a6b72
11997+
languageName: node
11998+
linkType: hard
11999+
1199012000
"JSONStream@npm:^1.3.5":
1199112001
version: 1.3.5
1199212002
resolution: "JSONStream@npm:1.3.5"

0 commit comments

Comments
 (0)