Conversation
- Add @kernel/* path alias to tsconfig.base.json for internal imports - Configure Jest moduleNameMapper to resolve @kernel/* in tests - Configure ESLint to recognize @kernel/* and @geekist/wp-kernel imports - Add TypeScript resolver settings for import validation - Update all relative imports to use @kernel/* aliases: - '../errors' → '@kernel/errors' - '../../types' → '@kernel/resource' - '../store/types' → '@kernel/resource/store/types' - Configure test tsconfig with composite:true and project reference - Include all source files in test tsconfig for proper resolution - Add migration script (scripts/fix-imports.sh) for bulk replacements All imports now use path aliases from root tsconfig.base.json. TypeScript compilation, ESLint, and all 195 tests pass. Fixes import clarity and maintainability as codebase grows.
There was a problem hiding this comment.
Pull Request Overview
This PR introduces internal module path aliases to improve code organization and reduce complex relative imports within the WP Kernel package. The changes focus on establishing a @kernel/* alias system for cleaner, more maintainable imports throughout the codebase.
- Adds
@kernel/*path mapping to replace deep relative imports like../../../errorswith clean aliases - Creates automation script to perform bulk import replacements across the kernel package
- Updates build and testing configurations to support the new alias system
Reviewed Changes
Copilot reviewed 13 out of 15 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tsconfig.base.json | Adds @kernel/* path mapping configuration for TypeScript module resolution |
| scripts/fix-imports.sh | Automation script to replace relative imports with @kernel/ aliases throughout the codebase |
| packages/kernel/tsconfig.tests.json | Updates test configuration to enable composite mode and broader file inclusion |
| packages/kernel/src/resource/store/types.ts | Replaces relative import with @kernel/resource alias |
| packages/kernel/src/resource/store/createStore.ts | Updates imports to use @kernel/ aliases for errors and resource types |
| packages/kernel/src/resource/store/tests/createStore.test.ts | Converts test imports to use @kernel/ aliases |
| packages/kernel/src/resource/interpolate.ts | Replaces relative error import with @kernel/errors alias |
| packages/kernel/src/resource/defineResource.ts | Updates error import to use @kernel/errors alias |
| packages/kernel/src/resource/tests/interpolate.test.ts | Converts test imports to @kernel/ aliases with multi-line formatting |
| packages/kernel/src/resource/tests/defineResource.test.ts | Updates all test imports to use @kernel/ aliases |
| package.json | Adds eslint-import-resolver-typescript dependency for proper import resolution |
| jest.config.cjs | Configures Jest module name mapping for @kernel/ aliases |
| eslint.config.js | Adds TypeScript import resolver configuration and import ordering rules |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
scripts/fix-imports.sh
Outdated
| # Go to repo root | ||
| cd "$(dirname "$0")/.." | ||
|
|
||
| # Replace ../errors with @kernel/errors | ||
| find packages/kernel/src -type f -name "*.ts" -not -path "*/node_modules/*" -exec sed -i '' "s|from '../errors'|from '@kernel/errors'|g" {} \; | ||
| find packages/kernel/src -type f -name "*.ts" -not -path "*/node_modules/*" -exec sed -i '' "s|from '../../errors'|from '@kernel/errors'|g" {} \; | ||
| find packages/kernel/src -type f -name "*.ts" -not -path "*/node_modules/*" -exec sed -i '' "s|from '../../../errors'|from '@kernel/errors'|g" {} \; | ||
|
|
||
| # Replace ../types with @kernel/resource for resource imports | ||
| find packages/kernel/src/resource/store -type f -name "*.ts" -not -path "*/node_modules/*" -exec sed -i '' "s|from '../types'|from '@kernel/resource'|g" {} \; | ||
| find packages/kernel/src/resource/store -type f -name "*.ts" -not -path "*/node_modules/*" -exec sed -i '' "s|from '../../types'|from '@kernel/resource'|g" {} \; | ||
|
|
||
| # Replace ../../errors in tests | ||
| find packages/kernel/src -type f -name "*.test.ts" -not -path "*/node_modules/*" -exec sed -i '' "s|from '../../errors'|from '@kernel/errors'|g" {} \; | ||
|
|
||
| # Replace ../types in resource tests | ||
| find packages/kernel/src/resource/__tests__ -type f -name "*.test.ts" -not -path "*/node_modules/*" -exec sed -i '' "s|from '../types'|from '@kernel/resource'|g" {} \; | ||
|
|
||
| # Replace ../store/types in resource tests | ||
| find packages/kernel/src/resource/__tests__ -type f -name "*.test.ts" -not -path "*/node_modules/*" -exec sed -i '' "s|from '../store/types'|from '@kernel/resource/store/types'|g" {} \; |
There was a problem hiding this comment.
The script uses macOS-specific sed -i '' syntax which will fail on Linux systems. Consider using a cross-platform approach or documenting the macOS requirement.
| # Go to repo root | |
| cd "$(dirname "$0")/.." | |
| # Replace ../errors with @kernel/errors | |
| find packages/kernel/src -type f -name "*.ts" -not -path "*/node_modules/*" -exec sed -i '' "s|from '../errors'|from '@kernel/errors'|g" {} \; | |
| find packages/kernel/src -type f -name "*.ts" -not -path "*/node_modules/*" -exec sed -i '' "s|from '../../errors'|from '@kernel/errors'|g" {} \; | |
| find packages/kernel/src -type f -name "*.ts" -not -path "*/node_modules/*" -exec sed -i '' "s|from '../../../errors'|from '@kernel/errors'|g" {} \; | |
| # Replace ../types with @kernel/resource for resource imports | |
| find packages/kernel/src/resource/store -type f -name "*.ts" -not -path "*/node_modules/*" -exec sed -i '' "s|from '../types'|from '@kernel/resource'|g" {} \; | |
| find packages/kernel/src/resource/store -type f -name "*.ts" -not -path "*/node_modules/*" -exec sed -i '' "s|from '../../types'|from '@kernel/resource'|g" {} \; | |
| # Replace ../../errors in tests | |
| find packages/kernel/src -type f -name "*.test.ts" -not -path "*/node_modules/*" -exec sed -i '' "s|from '../../errors'|from '@kernel/errors'|g" {} \; | |
| # Replace ../types in resource tests | |
| find packages/kernel/src/resource/__tests__ -type f -name "*.test.ts" -not -path "*/node_modules/*" -exec sed -i '' "s|from '../types'|from '@kernel/resource'|g" {} \; | |
| # Replace ../store/types in resource tests | |
| find packages/kernel/src/resource/__tests__ -type f -name "*.test.ts" -not -path "*/node_modules/*" -exec sed -i '' "s|from '../store/types'|from '@kernel/resource/store/types'|g" {} \; | |
| # Detect platform and set SED_INPLACE variable | |
| if [[ "$OSTYPE" == "darwin"* ]]; then | |
| SED_INPLACE=("sed" "-i" "") | |
| else | |
| SED_INPLACE=("sed" "-i") | |
| fi | |
| # Go to repo root | |
| cd "$(dirname "$0")/.." | |
| # Replace ../errors with @kernel/errors | |
| find packages/kernel/src -type f -name "*.ts" -not -path "*/node_modules/*" -exec "${SED_INPLACE[@]}" "s|from '../errors'|from '@kernel/errors'|g" {} \; | |
| find packages/kernel/src -type f -name "*.ts" -not -path "*/node_modules/*" -exec "${SED_INPLACE[@]}" "s|from '../../errors'|from '@kernel/errors'|g" {} \; | |
| find packages/kernel/src -type f -name "*.ts" -not -path "*/node_modules/*" -exec "${SED_INPLACE[@]}" "s|from '../../../errors'|from '@kernel/errors'|g" {} \; | |
| # Replace ../types with @kernel/resource for resource imports | |
| find packages/kernel/src/resource/store -type f -name "*.ts" -not -path "*/node_modules/*" -exec "${SED_INPLACE[@]}" "s|from '../types'|from '@kernel/resource'|g" {} \; | |
| find packages/kernel/src/resource/store -type f -name "*.ts" -not -path "*/node_modules/*" -exec "${SED_INPLACE[@]}" "s|from '../../types'|from '@kernel/resource'|g" {} \; | |
| # Replace ../../errors in tests | |
| find packages/kernel/src -type f -name "*.test.ts" -not -path "*/node_modules/*" -exec "${SED_INPLACE[@]}" "s|from '../../errors'|from '@kernel/errors'|g" {} \; | |
| # Replace ../types in resource tests | |
| find packages/kernel/src/resource/__tests__ -type f -name "*.test.ts" -not -path "*/node_modules/*" -exec "${SED_INPLACE[@]}" "s|from '../types'|from '@kernel/resource'|g" {} \; | |
| # Replace ../store/types in resource tests | |
| find packages/kernel/src/resource/__tests__ -type f -name "*.test.ts" -not -path "*/node_modules/*" -exec "${SED_INPLACE[@]}" "s|from '../store/types'|from '@kernel/resource/store/types'|g" {} \; |
scripts/fix-imports.sh
Outdated
| # Go to repo root | ||
| cd "$(dirname "$0")/.." | ||
|
|
||
| # Replace ../errors with @kernel/errors | ||
| find packages/kernel/src -type f -name "*.ts" -not -path "*/node_modules/*" -exec sed -i '' "s|from '../errors'|from '@kernel/errors'|g" {} \; | ||
| find packages/kernel/src -type f -name "*.ts" -not -path "*/node_modules/*" -exec sed -i '' "s|from '../../errors'|from '@kernel/errors'|g" {} \; | ||
| find packages/kernel/src -type f -name "*.ts" -not -path "*/node_modules/*" -exec sed -i '' "s|from '../../../errors'|from '@kernel/errors'|g" {} \; | ||
|
|
||
| # Replace ../types with @kernel/resource for resource imports | ||
| find packages/kernel/src/resource/store -type f -name "*.ts" -not -path "*/node_modules/*" -exec sed -i '' "s|from '../types'|from '@kernel/resource'|g" {} \; | ||
| find packages/kernel/src/resource/store -type f -name "*.ts" -not -path "*/node_modules/*" -exec sed -i '' "s|from '../../types'|from '@kernel/resource'|g" {} \; | ||
|
|
||
| # Replace ../../errors in tests | ||
| find packages/kernel/src -type f -name "*.test.ts" -not -path "*/node_modules/*" -exec sed -i '' "s|from '../../errors'|from '@kernel/errors'|g" {} \; | ||
|
|
||
| # Replace ../types in resource tests | ||
| find packages/kernel/src/resource/__tests__ -type f -name "*.test.ts" -not -path "*/node_modules/*" -exec sed -i '' "s|from '../types'|from '@kernel/resource'|g" {} \; | ||
|
|
||
| # Replace ../store/types in resource tests | ||
| find packages/kernel/src/resource/__tests__ -type f -name "*.test.ts" -not -path "*/node_modules/*" -exec sed -i '' "s|from '../store/types'|from '@kernel/resource/store/types'|g" {} \; |
There was a problem hiding this comment.
The script contains duplicated find command patterns. Consider extracting the common find pattern into a function to reduce repetition and improve maintainability.
| # Go to repo root | |
| cd "$(dirname "$0")/.." | |
| # Replace ../errors with @kernel/errors | |
| find packages/kernel/src -type f -name "*.ts" -not -path "*/node_modules/*" -exec sed -i '' "s|from '../errors'|from '@kernel/errors'|g" {} \; | |
| find packages/kernel/src -type f -name "*.ts" -not -path "*/node_modules/*" -exec sed -i '' "s|from '../../errors'|from '@kernel/errors'|g" {} \; | |
| find packages/kernel/src -type f -name "*.ts" -not -path "*/node_modules/*" -exec sed -i '' "s|from '../../../errors'|from '@kernel/errors'|g" {} \; | |
| # Replace ../types with @kernel/resource for resource imports | |
| find packages/kernel/src/resource/store -type f -name "*.ts" -not -path "*/node_modules/*" -exec sed -i '' "s|from '../types'|from '@kernel/resource'|g" {} \; | |
| find packages/kernel/src/resource/store -type f -name "*.ts" -not -path "*/node_modules/*" -exec sed -i '' "s|from '../../types'|from '@kernel/resource'|g" {} \; | |
| # Replace ../../errors in tests | |
| find packages/kernel/src -type f -name "*.test.ts" -not -path "*/node_modules/*" -exec sed -i '' "s|from '../../errors'|from '@kernel/errors'|g" {} \; | |
| # Replace ../types in resource tests | |
| find packages/kernel/src/resource/__tests__ -type f -name "*.test.ts" -not -path "*/node_modules/*" -exec sed -i '' "s|from '../types'|from '@kernel/resource'|g" {} \; | |
| # Replace ../store/types in resource tests | |
| find packages/kernel/src/resource/__tests__ -type f -name "*.test.ts" -not -path "*/node_modules/*" -exec sed -i '' "s|from '../store/types'|from '@kernel/resource/store/types'|g" {} \; | |
| # Function to run find+sed for import replacement | |
| run_find_sed() { | |
| local search_dir="$1" | |
| local file_pattern="$2" | |
| local sed_expr="$3" | |
| find "$search_dir" -type f -name "$file_pattern" -not -path "*/node_modules/*" -exec sed -i '' "$sed_expr" {} \; | |
| } | |
| # Go to repo root | |
| cd "$(dirname "$0")/.." | |
| # Replace ../errors with @kernel/errors | |
| run_find_sed "packages/kernel/src" "*.ts" "s|from '../errors'|from '@kernel/errors'|g" | |
| run_find_sed "packages/kernel/src" "*.ts" "s|from '../../errors'|from '@kernel/errors'|g" | |
| run_find_sed "packages/kernel/src" "*.ts" "s|from '../../../errors'|from '@kernel/errors'|g" | |
| # Replace ../types with @kernel/resource for resource imports | |
| run_find_sed "packages/kernel/src/resource/store" "*.ts" "s|from '../types'|from '@kernel/resource'|g" | |
| run_find_sed "packages/kernel/src/resource/store" "*.ts" "s|from '../../types'|from '@kernel/resource'|g" | |
| # Replace ../../errors in tests | |
| run_find_sed "packages/kernel/src" "*.test.ts" "s|from '../../errors'|from '@kernel/errors'|g" | |
| # Replace ../types in resource tests | |
| run_find_sed "packages/kernel/src/resource/__tests__" "*.test.ts" "s|from '../types'|from '@kernel/resource'|g" | |
| # Replace ../store/types in resource tests | |
| run_find_sed "packages/kernel/src/resource/__tests__" "*.test.ts" "s|from '../store/types'|from '@kernel/resource/store/types'|g" |
The fix-imports.sh script was used for one-time migration to @kernel/* aliases. No longer needed now that migration is complete.
What
Brief description of what this PR does.
Why
Problem or use case this solves. Link to related issues.
Fixes #
How
High-level overview of the implementation approach.
Testing
How to test this change:
Screenshots (if applicable)
Breaking Changes
List any breaking changes and migration steps.
Checklist
pnpm testandpnpm e2e)pnpm lint)pnpm changeset)