fix for two file wire from within a module#262
fix for two file wire from within a module#262mrigsby wants to merge 4 commits intocoldbox-modules:developmentfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes rendering of two-file CBWire components that live inside a ColdBox module by preventing incorrect /wires/ prefixing when resolving module view paths (Issue #261).
Changes:
- Updated
RenderService.normalizeViewPath()to accept additional context and adjust whenwires/is prefixed. - Updated/added unit and integration tests to cover module-based two-file wire rendering.
- Added a new two-file wire component + view to the test-harness module.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
models/services/RenderService.cfc |
Adjusts view path normalization logic to avoid /wires/ being prepended for module-based two-file wires. |
models/Component.cfc |
Passes component _path into normalizeViewPath() when rendering templates. |
test-harness/tests/specs/unit/services/RenderServiceSpec.cfc |
Updates unit tests for the new normalizeViewPath() signature and adds a module two-file wire path test. |
test-harness/tests/specs/CBWIRESpec.cfc |
Adds integration coverage for rendering a two-file module wire via wire(). |
test-harness/modules_app/testingmodule/wires/twoFileModuleComponent.cfc |
Adds a two-file module wire component for test coverage. |
test-harness/modules_app/testingmodule/wires/twoFileModuleComponent.cfm |
Adds the paired two-file module wire view for rendering tests. |
| @@ -190,7 +190,7 @@ component accessors="true" singleton { | |||
| throw( type="CBWIREException", message="A .bxm or .cfm template could not be found for '#arguments.viewPath#'." ); | |||
| } | |||
|
|
|||
| if ( left( paths.normalizedPath, 6 ) != "wires/" ) { | |||
| if ( !find( "@", arguments.componentPath ) && left( paths.normalizedPath, 6 ) != "wires/" ) { | |||
| paths.normalizedPath = "wires/" & paths.normalizedPath; | |||
| } | |||
There was a problem hiding this comment.
The new componentPath-based check (!find( "@", componentPath )) changes normalizeViewPath() behavior for all templates rendered from module components (it will stop auto-prepending wires/ even when viewPath is a normal app wire view). Since module templates already have paths.normalizedPath starting with modules_app/ (from getTemplatePath()), consider keying the prefix decision off the normalized view path (e.g., skip prefix only when it starts with modules_app/), and/or make componentPath optional to avoid breaking callers.
There was a problem hiding this comment.
Is this taking into account also loading wires from external locations as well?
https://cbwire.ortusbooks.com/the-essentials/components#external-components
| function template( viewPath, params = {} ) { | ||
| // Normalize the view path | ||
| local.normalizedPath = variables._renderService.normalizeViewPath( arguments.viewPath ); | ||
| local.normalizedPath = variables._renderService.normalizeViewPath( arguments.viewPath, variables._path ); | ||
| // Render the view content and trim the result |
There was a problem hiding this comment.
template() now always passes variables._path into normalizeViewPath(), but _path is not initialized in onDIComplete() and can be null unless _withPath() has been called. If a component instance calls template() before _withPath(), normalizeViewPath() will receive null and can error when calling find(). Consider defaulting to an empty string when _path is null, or making the new componentPath argument optional/nullable-safe in normalizeViewPath().
| var input = "modules_app.testingModule.wires.twoFileModuleComponent"; | ||
| // simulate the components variables._path which is what is passed to the wire() method | ||
| var component_path = "twoFileModuleComponent@testingModule"; | ||
| // use full path to module wire | ||
| var bxmAbsolutePath = expandPath( "../modules_app/testingModule/wires/twoFileModuleComponent.bxm" ); | ||
| var cfmAbsolutePath = expandPath( "../modules_app/testingModule/wires/twoFileModuleComponent.cfm" ); | ||
|
|
||
| var expectedPath = "/modules_app/testingModule/wires/twoFileModuleComponent.cfm"; |
There was a problem hiding this comment.
The new module-path test uses testingModule casing in input, component_path, expandPath(), and expectedPath, but the actual test-harness module directory is modules_app/testingmodule (lowercase). On case-sensitive filesystems this will fail and also doesn't match the integration test which uses @testingmodule. Update these strings/paths to use the correct module name casing and prefer a root-based path (/modules_app/...) to mirror buildViewPaths().
| var input = "modules_app.testingModule.wires.twoFileModuleComponent"; | |
| // simulate the components variables._path which is what is passed to the wire() method | |
| var component_path = "twoFileModuleComponent@testingModule"; | |
| // use full path to module wire | |
| var bxmAbsolutePath = expandPath( "../modules_app/testingModule/wires/twoFileModuleComponent.bxm" ); | |
| var cfmAbsolutePath = expandPath( "../modules_app/testingModule/wires/twoFileModuleComponent.cfm" ); | |
| var expectedPath = "/modules_app/testingModule/wires/twoFileModuleComponent.cfm"; | |
| var input = "modules_app.testingmodule.wires.twoFileModuleComponent"; | |
| // simulate the components variables._path which is what is passed to the wire() method | |
| var component_path = "twoFileModuleComponent@testingmodule"; | |
| // use full path to module wire | |
| var bxmAbsolutePath = expandPath( "/modules_app/testingmodule/wires/twoFileModuleComponent.bxm" ); | |
| var cfmAbsolutePath = expandPath( "/modules_app/testingmodule/wires/twoFileModuleComponent.cfm" ); | |
| var expectedPath = "/modules_app/testingmodule/wires/twoFileModuleComponent.cfm"; |
test-harness/modules_app/testingmodule/wires/twoFileModuleComponent.cfm
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…onent.cfm Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Reference Issue: #261
CBWire is prepending
wire/to the view path and not taking into account if the wire is in a module. This only happens for two file wires, not single file wires.RenderService.cfcmethodnormalizeViewPath()to take a second argument. This argument is thevariables._pathvalue inComponent.cfc. This is the wire name passed to thewire()method and is used to determine if it contains an @ denoting a module wire.normalizeViewPath()tests to account for this second argumentnormalizeViewPath()to validate for a two file wire from a module pathtestingModuletestingModule