Skip to content

Commit 673aed3

Browse files
balzssclaude
andcommitted
fix(ci): add webpack aliases for workspace packages in Cypress config
Fix Cypress component tests failing with "Cannot resolve '@instructure/ui'" errors. Issue: Cypress webpack running in its own context cannot resolve pnpm workspace packages even with hoisted node-linker, because packages aren't in node_modules in the expected locations. Solution: Dynamically generate webpack aliases that map all @instructure/* packages to their actual workspace locations in packages/*/. This allows Cypress webpack to resolve both top-level imports (@instructure/ui) and deep imports (@instructure/ui-button/src/...). Implementation: - Added getWorkspaceAliases() function that scans packages/ directory - Generates aliases for all workspace packages - Supports both package root and /src paths This is the pnpm-compatible approach to module resolution for Cypress component tests. Fixes: Cypress component tests and visual regression tests 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent d6daed4 commit 673aed3

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

cypress/webpack.config.cjs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,37 @@
11
const path = require('path')
2+
const fs = require('fs')
3+
4+
// Generate aliases for all @instructure/* workspace packages
5+
function getWorkspaceAliases() {
6+
const packagesDir = path.resolve(__dirname, '../packages')
7+
const packages = fs.readdirSync(packagesDir)
8+
const aliases = {}
9+
10+
packages.forEach(pkg => {
11+
const pkgPath = path.join(packagesDir, pkg)
12+
if (fs.statSync(pkgPath).isDirectory()) {
13+
const pkgJsonPath = path.join(pkgPath, 'package.json')
14+
if (fs.existsSync(pkgJsonPath)) {
15+
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'))
16+
const pkgName = pkgJson.name
17+
if (pkgName && pkgName.startsWith('@instructure/')) {
18+
// Alias package name to its source directory
19+
aliases[pkgName] = pkgPath
20+
// Also alias deep imports (e.g., '@instructure/ui-button/src/...')
21+
aliases[`${pkgName}/src`] = path.join(pkgPath, 'src')
22+
}
23+
}
24+
}
25+
})
26+
27+
return aliases
28+
}
229

330
module.exports = {
431
mode: 'development',
532
resolve: {
633
extensions: ['.ts', '.tsx', '.js'],
34+
alias: getWorkspaceAliases(),
735
fallback: {
836
fs: false,
937
module: false,

0 commit comments

Comments
 (0)