### Run Project Setup and Tests Source: https://github.com/rubyatscale/packwerk-extensions/blob/main/README.md Execute these commands to ensure the project is set up correctly and all tests pass before submitting changes. This includes installing dependencies, type checking, linting, and running tests. ```bash bundle srb tc bin/rubocop bin/rake test ``` -------------------------------- ### Install Dependencies Source: https://github.com/rubyatscale/packwerk-extensions/blob/main/AGENTS.md Run this command to install project dependencies using Bundler. ```bash bundle install ``` -------------------------------- ### Install packwerk-extensions Gem Source: https://context7.com/rubyatscale/packwerk-extensions/llms.txt Add the packwerk-extensions gem to your Gemfile to include its functionality. ```ruby gem 'packwerk-extensions' ``` -------------------------------- ### Folder Privacy Checker Access Rules Example Source: https://context7.com/rubyatscale/packwerk-extensions/llms.txt Demonstrates the access rules enforced by the folder privacy checker for a package within a nested directory structure. ```text # Directory structure and access rules for packs/b/packs/e: . # OK (parent of parent - root) packs/a # VIOLATION (different branch) packs/b # OK (direct parent) packs/b/packs/d # OK (sibling) packs/b/packs/e # Self (enforce_folder_privacy: true) packs/b/packs/e/packs/f # VIOLATION (child pack) packs/b/packs/e/packs/g # VIOLATION (child pack) packs/b/packs/h # OK (sibling) cpacks # VIOLATION (different branch) ``` -------------------------------- ### Configure Package Layer and Dependencies Source: https://context7.com/rubyatscale/packwerk-extensions/llms.txt Specify the layer for a package and its allowed dependencies. This example shows an orchestrator layer package. ```yaml # components/checkout/package.yml (orchestrator layer) enforce_layers: true layer: orchestrator # Can depend on: orchestrator, business_domain, platform, utility ``` -------------------------------- ### Configure Package Layer with Dependency Restrictions Source: https://context7.com/rubyatscale/packwerk-extensions/llms.txt Define a package's layer and explicitly list dependencies it cannot have. This example is for the business_domain layer. ```yaml # components/orders/package.yml (business_domain layer) enforce_layers: true layer: business_domain # Can depend on: business_domain, platform, utility # CANNOT depend on: orchestrator ``` -------------------------------- ### Visibility Checker Allowed and Violation Examples Source: https://context7.com/rubyatscale/packwerk-extensions/llms.txt Illustrates allowed and disallowed references based on the `visible_to` list in the visibility checker configuration. ```ruby # This reference is ALLOWED (payments is in visible_to list) # components/payments/app/services/payment_service.rb class PaymentService def process InternalUtilities::Helper.format_data(data) # OK end end # This reference is a VIOLATION (orders is NOT in visible_to list) # components/orders/app/services/order_service.rb class OrderService def process InternalUtilities::Helper.format_data(data) # Violation! end end ``` -------------------------------- ### Migrate Deprecated Architecture Checker Config Source: https://github.com/rubyatscale/packwerk-extensions/blob/main/README.md Use these sed and ripgrep commands to update Packwerk configuration files from deprecated 'architecture' keys to the new 'layer' keys. Ensure sed and ripgrep are installed. ```bash # script to migrate code from deprecated "architecture" violations to "layer" violations # sed and ripgrep required # 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'` ``` -------------------------------- ### Run All Tests Source: https://github.com/rubyatscale/packwerk-extensions/blob/main/AGENTS.md Execute all Minitest tests for the project. ```bash bundle exec rake test ``` -------------------------------- ### Run RuboCop Linter Source: https://github.com/rubyatscale/packwerk-extensions/blob/main/AGENTS.md Execute RuboCop for code linting. ```bash bundle exec rubocop ``` -------------------------------- ### Configure Platform Layer Package Source: https://context7.com/rubyatscale/packwerk-extensions/llms.txt Set up a package in the platform layer, defining its allowed and disallowed dependencies. ```yaml # components/database/package.yml (platform layer) enforce_layers: true layer: platform # Can depend on: platform, utility # CANNOT depend on: orchestrator, business_domain ``` -------------------------------- ### Run Sorbet Type Checking Source: https://github.com/rubyatscale/packwerk-extensions/blob/main/AGENTS.md Execute Sorbet for static type checking. ```bash bundle exec srb tc ``` -------------------------------- ### Run a Single Test File Source: https://github.com/rubyatscale/packwerk-extensions/blob/main/AGENTS.md Execute a specific test file using the Ruby interpreter. ```bash bundle exec ruby -Ilib -Itest test/path/to/test.rb ``` -------------------------------- ### Track Existing Violations with package_todo.yml Source: https://context7.com/rubyatscale/packwerk-extensions/llms.txt Use package_todo.yml to document existing violations, allowing for gradual migration while enforcing strict mode for new issues. ```yaml # components/orders/package_todo.yml --- "components/billing": "::Billing::InternalProcessor": violations: - privacy files: - components/orders/app/services/legacy_order_processor.rb "::Billing::Helper": violations: - layer files: - components/orders/app/models/order.rb ``` -------------------------------- ### Mark File as Public with Sigil Source: https://context7.com/rubyatscale/packwerk-extensions/llms.txt Use the `pack_public: true` sigil comment in the first 5 lines of a file to mark it as public within a private package, without moving it to the public folder. ```ruby # pack_public: true # typed: strict # frozen_string_literal: true module Billing # This class is public even though it's not in app/public/ class PublicInterface def self.process_payment(amount) # Implementation end end end ``` -------------------------------- ### Configure Utility Layer Package Source: https://context7.com/rubyatscale/packwerk-extensions/llms.txt Configure a package in the utility layer, which can only depend on itself. ```yaml # components/string_utils/package.yml (utility layer) enforce_layers: true layer: utility # Can depend on: utility only # CANNOT depend on: orchestrator, business_domain, platform ``` -------------------------------- ### Configure Packwerk Checkers Source: https://context7.com/rubyatscale/packwerk-extensions/llms.txt Configure packwerk.yml to load all checkers or individual checkers for granular control. The layer checker requires additional layer configuration. ```yaml # packwerk.yml - Load all checkers require: - packwerk-extensions # Or load individual checkers require: - packwerk/privacy/checker - packwerk/visibility/checker - packwerk/folder_privacy/checker - packwerk/layer/checker # Configure layers for the layer checker layers: - orchestrator - business_domain - platform - utility include: - "**/*.rb" ``` -------------------------------- ### Run Packwerk Checkers Source: https://context7.com/rubyatscale/packwerk-extensions/llms.txt Execute Packwerk commands to check for architectural violations, validate package configurations, or update todo files. ```bash # Check for all violations bin/packwerk check # Validate package configuration bin/packwerk validate # Update package_todo.yml files with new violations bin/packwerk update-todo ``` -------------------------------- ### Define Custom Public Folder Path Source: https://github.com/rubyatscale/packwerk-extensions/blob/main/README.md Override the default public folder (`app/public`) on a per-package basis by defining a `public_path` in your `package.yml`. ```yaml public_path: my/custom/path/ ``` -------------------------------- ### Infer Layers from Package Path Source: https://context7.com/rubyatscale/packwerk-extensions/llms.txt Configure Packwerk to automatically infer a package's layer based on its directory structure, simplifying package.yml configuration. ```yaml # packwerk.yml layers: - feature - core - utility # With this structure, layers are inferred: # feature/checkout/package.yml -> layer: feature (inferred) # core/orders/package.yml -> layer: core (inferred) # utility/helpers/package.yml -> layer: utility (inferred) ``` -------------------------------- ### Rubocop Exception with Pack Public Sigil Source: https://github.com/rubyatscale/packwerk-extensions/blob/main/README.md When using `pack_public: true`, place it first in the list of magic keywords to avoid a Rubocop exception related to `Layout/EmptyLineAfterMagicComment`. ```ruby # typed: ignore # frozen_string_literal: true # pack_public: true class Foo ... end ``` -------------------------------- ### Ideal Magic Comment Placement in Ruby Source: https://github.com/rubyatscale/packwerk-extensions/blob/main/README.md Place magic comments like `# pack_public: true` at the beginning of the file for optimal parsing by tools like Rubocop. This avoids issues with comment scanning range and reduces the need for extra empty lines. ```ruby # pack_public: true # typed: ignore # frozen_string_literal: true class Foo ... end ``` -------------------------------- ### Define Public Constants with Sigil Source: https://github.com/rubyatscale/packwerk-extensions/blob/main/README.md Mark individual files as public within a private package by including `# pack_public: true` within the first 5 lines of the `.rb` file. This makes constants within that file accessible even if the package enforces privacy. ```ruby # pack_public: true module Foo class Update end end ``` -------------------------------- ### Enable Layer Inference in Package Configuration Source: https://context7.com/rubyatscale/packwerk-extensions/llms.txt Enable layer enforcement for a package where the layer will be automatically inferred from its path. ```yaml # feature/checkout/package.yml enforce_layers: true # layer is automatically inferred as 'feature' from path ``` -------------------------------- ### Require Individual Packwerk Checkers Source: https://github.com/rubyatscale/packwerk-extensions/blob/main/README.md Alternatively, you can require individual checkers in your `packwerk.yml`. ```yaml require: - packwerk/privacy/checker - packwerk/visibility/checker - packwerk/folder_privacy/checker - packwerk/layer/checker ``` -------------------------------- ### Configuring Strict Privacy with Ignored Patterns Source: https://github.com/rubyatscale/packwerk-extensions/blob/main/README.md Use `strict_privacy_ignored_patterns` to exclude specific file paths from strict privacy checks. This allows activating 'strict' mode while deferring the resolution of certain privacy violations. ```yaml enforce_privacy: strict strict_privacy_ignored_patterns: - engines/another_engine/test/**/* ``` -------------------------------- ### Configure Folder Privacy Checker in package.yml Source: https://context7.com/rubyatscale/packwerk-extensions/llms.txt Enable the folder privacy checker in a package.yml file to enforce privacy rules based on directory structure, making packages private to their sibling and parent packs. ```yaml # packs/b/packs/e/package.yml enforce_folder_privacy: true # or 'strict' ``` -------------------------------- ### Configure Privacy Checker in package.yml Source: https://context7.com/rubyatscale/packwerk-extensions/llms.txt Enable the privacy checker in a package.yml file to enforce that only public APIs are accessed. Optionally, define a custom public path, list private constants, or ignore specific constants and patterns. ```yaml # components/billing/package.yml enforce_privacy: true # or 'strict' to disallow any existing violations # Optional: define a custom public path public_path: lib/public/ # Optional: only make specific constants private private_constants: - "::Billing::InternalProcessor" - "::Billing::SecretAlgorithm" # Optional: ignore privacy for specific constants ignored_private_constants: - "::Billing::LegacyHelper" # Optional: exclude paths from strict mode checking strict_privacy_ignored_patterns: - engines/legacy_engine/test/**/* - spec/**/* ``` -------------------------------- ### Require All Packwerk Extensions Source: https://github.com/rubyatscale/packwerk-extensions/blob/main/README.md To register all checkers included in this gem, add this to your `packwerk.yml`. ```yaml require: - packwerk-extensions ``` -------------------------------- ### Configure Visibility Checker in package.yml Source: https://context7.com/rubyatscale/packwerk-extensions/llms.txt Enable the visibility checker in a package.yml file to restrict access to a package to only explicitly listed other packages. This is useful for shared internal packages. ```yaml # components/internal_utilities/package.yml enforce_visibility: true # or 'strict' for no exceptions visible_to: - components/billing - components/payments - components/checkout ``` -------------------------------- ### Auto-correct RuboCop Violations Source: https://github.com/rubyatscale/packwerk-extensions/blob/main/AGENTS.md Run RuboCop with the auto-correct flag to fix linting issues. ```bash bundle exec rubocop -a ``` -------------------------------- ### Defining Layers for Dependency Constraints Source: https://github.com/rubyatscale/packwerk-extensions/blob/main/README.md Configure `layers` in `packwerk.yml` and set `enforce_layers: true` with a specific `layer` in `package.yml` to constrain package dependencies to packages within the same or lower layers. ```yaml layers: - feature - core - utility ``` ```yaml # components/merchandising/package.yml enforce_layers: true layer: core ``` -------------------------------- ### Enforce Privacy in Package Configuration Source: https://github.com/rubyatscale/packwerk-extensions/blob/main/README.md To enforce privacy for your package, set `enforce_privacy` to `true` or `strict` in your `package.yml`. `true` flags all references to private constants, while `strict` forbids all references, including those in `package_todo.yml`. ```yaml enforce_privacy: true ``` -------------------------------- ### Enforcing Package Visibility Source: https://github.com/rubyatscale/packwerk-extensions/blob/main/README.md Configure `enforce_visibility: true` and specify `visible_to` packages in `package.yml` to control which other packages can use your package's private implementation details. ```yaml # components/merchandising/package.yml enforce_visibility: true visible_to: - components/other_package ``` -------------------------------- ### Define Layer Hierarchy in packwerk.yml Source: https://context7.com/rubyatscale/packwerk-extensions/llms.txt Configure the hierarchical layer structure for your application. Packages can only depend on packages at the same level or below in this hierarchy. ```yaml # packwerk.yml - Define layer hierarchy (top to bottom) layers: - orchestrator # Highest layer - application orchestration - business_domain # Business logic and domain models - platform # Platform services and infrastructure - utility # Lowest layer - shared utilities ``` -------------------------------- ### Enforcing Folder Privacy Source: https://github.com/rubyatscale/packwerk-extensions/blob/main/README.md Set `enforce_folder_privacy: true` in `package.yml` to restrict a package's usage to its parent and sibling packs. Violations occur when other packages attempt to access it. ```yaml # components/merchandising/package.yml enforce_folder_privacy: true ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.