-
-
Notifications
You must be signed in to change notification settings - Fork 10
Support Symfony's Stimulus Bridge #431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
marcmorente
wants to merge
17
commits into
marcoroth:main
Choose a base branch
from
marcmorente:symfony-stimulus-bridge-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
4b0ba81
Recognize @symfony/stimulus-bridge as a helper package
marcmorente 8c5c275
Add support for Symfony Stimulus Bridge lazy loading
marcmorente 9cc3b9f
Add test fixtures for Symfony Stimulus Bridge
marcmorente 5bbb638
Add system test for Symfony Stimulus Bridge
marcmorente 72dce90
Clean up semicolons
marcmorente 2635993
Clean up semicolons
marcmorente aee1bf8
Refactor: rename method
marcmorente b380692
Add @symfony/stimulus-bundle to helper packages
marcmorente 1b2e738
Add isAssetMapper property to Project
marcmorente ff36ea4
Add hasStimulusBundleImport property and update isStimulusControllers…
marcmorente 11f9b74
Extend analyzeSymfonyStimulusBridge to support AssetMapper pattern
marcmorente 4759e21
Add symfony-asset-mapper test fixture
marcmorente 2296f78
Create mock @symfony/stimulus-bundle package for asset-mapper fixture
marcmorente 016e6fe
Add test case for symfony-asset-mapper fixture
marcmorente 7455df1
Fix: add guard for undefined applicationFile in hasResolvedStimulusAp…
marcmorente 76dfc79
Enhance: detect AssetMapper pattern via @symfony/stimulus-bundle import
marcmorente 72e1650
Style: remove unnecessary blank lines
marcmorente File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import { startStimulusApp } from '@symfony/stimulus-bundle' | ||
|
|
||
| const app = startStimulusApp() | ||
9 changes: 9 additions & 0 deletions
9
test/fixtures/symfony-asset-mapper/assets/controllers/hello_controller.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import { Controller } from '@hotwired/stimulus' | ||
|
|
||
| export default class extends Controller { | ||
| static targets = ['output'] | ||
|
|
||
| connect() { | ||
| console.log('Hello!') | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "name": "test-symfony-asset-mapper", | ||
| "dependencies": { | ||
| "@hotwired/stimulus": "^3.2.0" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
| # yarn lockfile v1 | ||
|
|
||
|
|
||
| "@hotwired/stimulus@^3.2.0": | ||
| version "3.2.2" | ||
| resolved "https://registry.yarnpkg.com/@hotwired/stimulus/-/stimulus-3.2.2.tgz#071aab59c600fed95b97939e605ff261a4251608" | ||
| integrity sha512-eGeIqNOQpXoPAIP7tC1+1Yc1yl1xnwYqg+3mzqxyrbE5pg5YFBZcA6YoTiByJB6DKAEsiWtl6tjTJS4IYtbB7A== |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { startStimulusApp } from '@symfony/stimulus-bridge' | ||
|
|
||
| export const app = startStimulusApp(require.context( | ||
| '@symfony/stimulus-bridge/lazy-controller-loader!./controllers', | ||
| true, | ||
| /\.[jt]sx?$/ | ||
| )) |
9 changes: 9 additions & 0 deletions
9
test/fixtures/symfony-stimulus-bridge/assets/controllers/hello-controller.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import { Controller } from '@hotwired/stimulus' | ||
|
|
||
| export default class extends Controller { | ||
| static targets = ['output'] | ||
|
|
||
| connect() { | ||
| console.log('Hello!') | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "name": "test-symfony-stimulus-bridge", | ||
| "dependencies": { | ||
| "@hotwired/stimulus": "^3.2.0", | ||
| "@symfony/stimulus-bridge": "^3.2.0" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
| # yarn lockfile v1 | ||
|
|
||
|
|
||
| "@hotwired/stimulus-webpack-helpers@^1.0.1": | ||
| version "1.0.1" | ||
| resolved "https://registry.yarnpkg.com/@hotwired/stimulus-webpack-helpers/-/stimulus-webpack-helpers-1.0.1.tgz#4cd74487adeca576c9865ac2b9fe5cb20cef16dd" | ||
| integrity sha512-wa/zupVG0eWxRYJjC1IiPBdt3Lruv0RqGN+/DTMmUWUyMAEB27KXmVY6a8YpUVTM7QwVuaLNGW4EqDgrS2upXQ== | ||
|
|
||
| "@hotwired/stimulus@^3.2.0": | ||
| version "3.2.2" | ||
| resolved "https://registry.yarnpkg.com/@hotwired/stimulus/-/stimulus-3.2.2.tgz#071aab59c600fed95b97939e605ff261a4251608" | ||
| integrity sha512-eGeIqNOQpXoPAIP7tC1+1Yc1yl1xnwYqg+3mzqxyrbE5pg5YFBZcA6YoTiByJB6DKAEsiWtl6tjTJS4IYtbB7A== | ||
|
|
||
| "@symfony/stimulus-bridge@^3.2.0": | ||
| version "3.2.3" | ||
| resolved "https://registry.yarnpkg.com/@symfony/stimulus-bridge/-/stimulus-bridge-3.2.3.tgz#1c496d4b11e24051be26a11045118f29f9c3f9b7" | ||
| integrity sha512-36rQTihQ2MGOn8EmdOYCr3DQfP3WS1CNcUUXKTPY5ghtFOeb7OVuhbc32AjRowE2/vaVDOUCPOTv3VLf5VtXBA== | ||
| dependencies: | ||
| "@hotwired/stimulus-webpack-helpers" "^1.0.1" | ||
| "@types/webpack-env" "^1.16.4" | ||
| acorn "^8.0.5" | ||
| loader-utils "^2.0.0" | ||
| schema-utils "^3.0.0" | ||
|
|
||
| "@types/json-schema@^7.0.8": | ||
| version "7.0.15" | ||
| resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.15.tgz#596a1747233694d50f6ad8a7869fcb6f56cf5841" | ||
| integrity sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA== | ||
|
|
||
| "@types/webpack-env@^1.16.4": | ||
| version "1.18.8" | ||
| resolved "https://registry.yarnpkg.com/@types/webpack-env/-/webpack-env-1.18.8.tgz#71f083718c094204d7b64443701d32f1db3989e3" | ||
| integrity sha512-G9eAoJRMLjcvN4I08wB5I7YofOb/kaJNd5uoCMX+LbKXTPCF+ZIHuqTnFaK9Jz1rgs035f9JUPUhNFtqgucy/A== | ||
|
|
||
| acorn@^8.0.5: | ||
| version "8.15.0" | ||
| resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.15.0.tgz#a360898bc415edaac46c8241f6383975b930b816" | ||
| integrity sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg== | ||
|
|
||
| ajv-keywords@^3.5.2: | ||
| version "3.5.2" | ||
| resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-3.5.2.tgz#31f29da5ab6e00d1c2d329acf7b5929614d5014d" | ||
| integrity sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ== | ||
|
|
||
| ajv@^6.12.5: | ||
| version "6.12.6" | ||
| resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.6.tgz#baf5a62e802b07d977034586f8c3baf5adf26df4" | ||
| integrity sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g== | ||
| dependencies: | ||
| fast-deep-equal "^3.1.1" | ||
| fast-json-stable-stringify "^2.0.0" | ||
| json-schema-traverse "^0.4.1" | ||
| uri-js "^4.2.2" | ||
|
|
||
| big.js@^5.2.2: | ||
| version "5.2.2" | ||
| resolved "https://registry.yarnpkg.com/big.js/-/big.js-5.2.2.tgz#65f0af382f578bcdc742bd9c281e9cb2d7768328" | ||
| integrity sha512-vyL2OymJxmarO8gxMr0mhChsO9QGwhynfuu4+MHTAW6czfq9humCB7rKpUjDd9YUiDPU4mzpyupFSvOClAwbmQ== | ||
|
|
||
| emojis-list@^3.0.0: | ||
| version "3.0.0" | ||
| resolved "https://registry.yarnpkg.com/emojis-list/-/emojis-list-3.0.0.tgz#5570662046ad29e2e916e71aae260abdff4f6a78" | ||
| integrity sha512-/kyM18EfinwXZbno9FyUGeFh87KC8HRQBQGildHZbEuRyWFOmv1U10o9BBp8XVZDVNNuQKyIGIu5ZYAAXJ0V2Q== | ||
|
|
||
| fast-deep-equal@^3.1.1: | ||
| version "3.1.3" | ||
| resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525" | ||
| integrity sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q== | ||
|
|
||
| fast-json-stable-stringify@^2.0.0: | ||
| version "2.1.0" | ||
| resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz#874bf69c6f404c2b5d99c481341399fd55892633" | ||
| integrity sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw== | ||
|
|
||
| json-schema-traverse@^0.4.1: | ||
| version "0.4.1" | ||
| resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz#69f6a87d9513ab8bb8fe63bdb0979c448e684660" | ||
| integrity sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg== | ||
|
|
||
| json5@^2.1.2: | ||
| version "2.2.3" | ||
| resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.3.tgz#78cd6f1a19bdc12b73db5ad0c61efd66c1e29283" | ||
| integrity sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg== | ||
|
|
||
| loader-utils@^2.0.0: | ||
| version "2.0.4" | ||
| resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-2.0.4.tgz#8b5cb38b5c34a9a018ee1fc0e6a066d1dfcc528c" | ||
| integrity sha512-xXqpXoINfFhgua9xiqD8fPFHgkoq1mmmpE92WlDbm9rNRd/EbRb+Gqf908T2DMfuHjjJlksiK2RbHVOdD/MqSw== | ||
| dependencies: | ||
| big.js "^5.2.2" | ||
| emojis-list "^3.0.0" | ||
| json5 "^2.1.2" | ||
|
|
||
| punycode@^2.1.0: | ||
| version "2.3.1" | ||
| resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.3.1.tgz#027422e2faec0b25e1549c3e1bd8309b9133b6e5" | ||
| integrity sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg== | ||
|
|
||
| schema-utils@^3.0.0: | ||
| version "3.3.0" | ||
| resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-3.3.0.tgz#f50a88877c3c01652a15b622ae9e9795df7a60fe" | ||
| integrity sha512-pN/yOAvcC+5rQ5nERGuwrjLlYvLTbCibnZ1I7B1LaiAz9BRBlE9GMgE/eqV30P7aJQUf7Ddimy/RsbYO/GrVGg== | ||
| dependencies: | ||
| "@types/json-schema" "^7.0.8" | ||
| ajv "^6.12.5" | ||
| ajv-keywords "^3.5.2" | ||
|
|
||
| uri-js@^4.2.2: | ||
| version "4.4.1" | ||
| resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.4.1.tgz#9b1a52595225859e55f669d928f88c6c57f2a77e" | ||
| integrity sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg== | ||
| dependencies: | ||
| punycode "^2.1.0" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import { describe, test, expect } from "vitest" | ||
| import { setupProject } from "../helpers/setup" | ||
|
|
||
| const project = setupProject("symfony-stimulus-bridge") | ||
|
|
||
| describe("System", () => { | ||
| test("symfony-stimulus-bridge", async () => { | ||
| expect(project.controllersIndexFiles.length).toEqual(0) | ||
| expect(project.applicationFile).toBeUndefined() | ||
| expect(project.registeredControllers.length).toEqual(0) | ||
|
|
||
| await project.initialize() | ||
|
|
||
| expect(project.applicationFile).toBeUndefined() | ||
| expect(project.controllersIndexFiles.length).toBeGreaterThanOrEqual(1) | ||
|
|
||
| const bootstrapFile = project.controllersIndexFiles.find((f) => | ||
| f.path.endsWith("bootstrap.js"), | ||
| ) | ||
| expect(bootstrapFile).toBeDefined() | ||
| expect(bootstrapFile?.applicationImport).toBeUndefined() | ||
|
|
||
| expect(project.registeredControllers.length).toEqual(1) | ||
| expect( | ||
| project.registeredControllers.map((controller) => [ | ||
| controller.identifier, | ||
| controller.loadMode, | ||
| ]), | ||
| ).toEqual([["hello", "stimulus-loading-lazy"]]) | ||
| expect(Array.from(project.controllerRoots).sort()).toContain( | ||
| "assets/controllers", | ||
| ) | ||
| }) | ||
|
|
||
| test("symfony-asset-mapper", async () => { | ||
| const assetMapperProject = setupProject("symfony-asset-mapper") | ||
|
|
||
| expect(assetMapperProject.controllersIndexFiles.length).toEqual(0) | ||
| expect(assetMapperProject.applicationFile).toBeUndefined() | ||
| expect(assetMapperProject.registeredControllers.length).toEqual(0) | ||
|
|
||
| await assetMapperProject.initialize() | ||
|
|
||
| expect(assetMapperProject.applicationFile).toBeUndefined() | ||
| expect(assetMapperProject.controllersIndexFiles.length).toBeGreaterThanOrEqual(1) | ||
|
|
||
| const bootstrapFile = assetMapperProject.controllersIndexFiles.find((f) => | ||
| f.path.endsWith("bootstrap.js"), | ||
| ) | ||
| expect(bootstrapFile).toBeDefined() | ||
| expect(bootstrapFile?.applicationImport).toBeUndefined() | ||
|
|
||
| expect(assetMapperProject.registeredControllers.length).toEqual(1) | ||
| expect( | ||
| assetMapperProject.registeredControllers.map((controller) => [ | ||
| controller.identifier, | ||
| controller.loadMode, | ||
| ]), | ||
| ).toEqual([["hello", "stimulus-loading-lazy"]]) | ||
| expect(Array.from(assetMapperProject.controllerRoots).sort()).toContain( | ||
| "assets/controllers", | ||
| ) | ||
| }) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / CodeQL
Unused variable, import, function or class Note test