Skip to content

Commit

Permalink
sample script for migrating from architecture to layer
Browse files Browse the repository at this point in the history
  • Loading branch information
perryqh committed Apr 30, 2024
1 parent c56bbf5 commit 1ccaa98
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Currently, it ships the following checkers to help improve the boundaries betwee
- A `privacy` checker that ensures other packages are using your package's public API
- A `visibility` checker that allows packages to be private except to an explicit group of other packages.
- A `folder_visibility` checker that allows packages to their sibling packs and parent pack (to be used in an application that uses folder packs)
- An `layer` (formerly `architecture`) checker that allows packages to specify their "layer" and requires that each layer only communicate with layers below it.
- A `layer` (formerly `architecture`) checker that allows packages to specify their "layer" and requires that each layer only communicate with layers below it.

## Installation

Expand Down Expand Up @@ -220,6 +220,19 @@ The "Layer Checker" was formerly named "Architecture Checker". The associated ke
- package.yml `layer` is still a valid key
- package_todo.yml - `architecture`, which is now `layer`

```bash
# script to migrate code from deprecated "architecture" violations to "layer" violations

# replace 'architecture_layers' with 'layers' in packwerk.yml
sed -i '' 's/architecture_layers/layers/g' ./packwerk.yml

# replace 'enforce_architecture' with 'enforce_layers' in package.yml files
`rg -l 'enforce_architecture' -g 'package.yml' | xargs sed -i '' 's,enforce_architecture,enforce_layers,g'`

# replace '- architecture' with '- layer' in package_todo.yml files
`rg -l 'architecture' -g 'package_todo.yml' | xargs sed -i '' 's/- architecture/- layer/g'`
```


## Contributing

Expand Down
9 changes: 7 additions & 2 deletions lib/packwerk/layer/checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def initialize

sig { override.returns(String) }
def violation_type
@violation_type ||= Config.new.violation_key
@violation_type ||= layer_config.violation_key
end

sig do
Expand All @@ -59,7 +59,7 @@ def invalid_reference?(reference)
end
def strict_mode_violation?(listed_offense)
constant_package = listed_offense.reference.package
constant_package.config['enforce_layers'] == 'strict'
constant_package.config[layer_config.enforce_key] == 'strict'
end

sig do
Expand Down Expand Up @@ -98,6 +98,11 @@ def standard_help_message(reference)
def layers
@layers ||= T.let(Layers.new, T.nilable(Packwerk::Layer::Layers))
end

sig { returns(Config) }
def layer_config
@layer_config ||= T.let(Config.new, T.nilable(Config))
end
end
end
end
8 changes: 4 additions & 4 deletions test/unit/layer/validator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@ def write_architecture_config
assert result.ok?
end

test 'call permitted keys' do
assert_equal validator.permitted_keys, ['enforce_layers', 'layer']
test 'call permitted keys' do
assert_equal validator.permitted_keys, %w[enforce_layers layer]
end

test 'call permitted keys when architecture' do
test 'call permitted keys when architecture' do
write_architecture_config
assert_equal validator.permitted_keys, ['enforce_architecture', 'layer']
assert_equal validator.permitted_keys, %w[enforce_architecture layer]
end

sig { returns(Packwerk::Layer::Validator) }
Expand Down

0 comments on commit 1ccaa98

Please sign in to comment.