vite-plugin-symfony
Advanced tools
Comparing version 7.1.0 to 8.0.0
@@ -106,4 +106,11 @@ import { Plugin } from 'vite'; | ||
/** | ||
* path to the deepest folder that contains all your stimulus controllers | ||
* relative to vite root | ||
* @default "./assets/controllers" | ||
*/ | ||
controllersDir: string; | ||
/** | ||
* path to controllers.json relative to vite root | ||
* @default ./assets/controller.json | ||
* @default "./assets/controller.json" | ||
*/ | ||
@@ -110,0 +117,0 @@ controllersFilePath: string; |
@@ -728,3 +728,6 @@ // src/entrypoints/index.ts | ||
var stimulusEnabledRE = new RegExp(notACommentRE.source + importMetaStimulusEnabledRE.source, "m"); | ||
function parseStimulusRequest(code, moduleId, pluginOptions, viteConfig) { | ||
function extractStimulusIdentifier(code) { | ||
return (code.match(stimulusIdentifierRE) || [])[1] ?? null; | ||
} | ||
function parseStimulusRequest(srcCode, moduleId, pluginOptions, viteConfig) { | ||
let filePath; | ||
@@ -736,4 +739,4 @@ if (moduleId.endsWith("?stimulus")) { | ||
} | ||
const fetch = (code.match(stimulusFetchRE) || [])[1] ?? pluginOptions.fetchMode; | ||
let id = (code.match(stimulusIdentifierRE) || [])[1]; | ||
const fetch = (srcCode.match(stimulusFetchRE) || [])[1] ?? pluginOptions.fetchMode; | ||
let id = extractStimulusIdentifier(srcCode); | ||
if (!id) { | ||
@@ -743,24 +746,23 @@ const relativePath = relative3(viteConfig.root, filePath); | ||
} | ||
const enabled = ((code.match(stimulusEnabledRE) || [])[1] ?? "true") === "false" ? false : true; | ||
if (fetch === "eager") { | ||
return ` | ||
const enabled = ((srcCode.match(stimulusEnabledRE) || [])[1] ?? "true") === "false" ? false : true; | ||
const dstCode = fetch === "eager" ? ` | ||
import Controller from '${filePath}'; | ||
export default { | ||
enabled: ${enabled}, | ||
fetch: 'eager', | ||
identifier: '${id}', | ||
controller: Controller | ||
}`; | ||
} else { | ||
return `export default { | ||
enabled: ${enabled}, | ||
fetch: 'lazy', | ||
identifier: '${id}', | ||
controller: () => import('${filePath}') | ||
}`; | ||
} | ||
enabled: ${enabled}, | ||
fetch: 'eager', | ||
identifier: '${id}', | ||
controller: Controller | ||
}` : ` | ||
export default { | ||
enabled: ${enabled}, | ||
fetch: 'lazy', | ||
identifier: '${id}', | ||
controller: () => import('${filePath}') | ||
}`; | ||
return `${dstCode} | ||
if (import.meta.hot) { import.meta.hot.accept(); }`; | ||
} | ||
// src/stimulus/node/index.ts | ||
import { relative as relative4, resolve as resolve4 } from "node:path"; | ||
import { join as join3, relative as relative4, resolve as resolve4 } from "node:path"; | ||
@@ -788,3 +790,8 @@ // src/stimulus/node/hmr.ts | ||
} else { | ||
window.${applicationGlobalVarName}.register('${identifier}', newModule.default); | ||
if (window.${applicationGlobalVarName}.router.modulesByIdentifier.has('${identifier}') && newModule.default) { | ||
window.${applicationGlobalVarName}.register('${identifier}', newModule.default); | ||
} else { | ||
console.warn('Try to HMR not registered Stimulus controller', '${identifier}', 'full-reload'); | ||
import.meta.hot.invalidate(); | ||
} | ||
} | ||
@@ -862,13 +869,15 @@ }) | ||
} | ||
if (viteCommand === "serve") { | ||
if (viteCommand === "serve" && pluginOptions.hmr) { | ||
if (id.endsWith("bootstrap.js") || id.endsWith("bootstrap.ts")) { | ||
return addBootstrapHmrCode(code, logger); | ||
} | ||
if (isPathIncluded(viteConfig.root, id)) { | ||
const relativePath = relative4(viteConfig.root, id); | ||
const identifier = getStimulusControllerId(relativePath, pluginOptions.identifierResolutionMethod); | ||
if (identifier) { | ||
return addControllerHmrCode(code, identifier); | ||
} | ||
const isInsideControllerDir = isPathIncluded(join3(viteConfig.root, pluginOptions.controllersDir), id); | ||
if (!isInsideControllerDir) { | ||
return null; | ||
} | ||
const relativePath = relative4(viteConfig.root, id); | ||
const identifier = extractStimulusIdentifier(code) ?? getStimulusControllerId(relativePath, pluginOptions.identifierResolutionMethod); | ||
if (identifier) { | ||
return addControllerHmrCode(code, identifier); | ||
} | ||
} | ||
@@ -993,2 +1002,3 @@ return null; | ||
config = { | ||
controllersDir: "./assets/controllers", | ||
controllersFilePath: "./assets/controllers.json", | ||
@@ -1001,2 +1011,3 @@ hmr: true, | ||
config = { | ||
controllersDir: "./assets/controllers", | ||
controllersFilePath: userConfig, | ||
@@ -1009,2 +1020,3 @@ hmr: true, | ||
config = { | ||
controllersDir: userConfig.controllersDir ?? "./assets/controllers", | ||
controllersFilePath: userConfig.controllersFilePath ?? "./assets/controllers.json", | ||
@@ -1011,0 +1023,0 @@ hmr: userConfig.hmr !== false ? true : false, |
{ | ||
"name": "vite-plugin-symfony", | ||
"version": "7.1.0", | ||
"version": "8.0.0", | ||
"description": "A Vite plugin to integrate easily Vite in your Symfony application", | ||
@@ -58,18 +58,22 @@ "type": "module", | ||
"devDependencies": { | ||
"@eslint/js": "^9.20.0", | ||
"@hotwired/stimulus": "^3.2.2", | ||
"@types/node": "^22.3.0", | ||
"@types/react": "^18.3.3", | ||
"@types/react-dom": "^18.3.0", | ||
"@types/ws": "^8.5.12", | ||
"@vitest/coverage-v8": "^2.0.5", | ||
"jsdom": "^24.1.1", | ||
"prettier": "^3.3.3", | ||
"@types/node": "^22.13.1", | ||
"@types/react": "^18.3.18", | ||
"@types/react-dom": "^18.3.5", | ||
"@types/ws": "^8.5.14", | ||
"@vitest/coverage-v8": "^3.0.5", | ||
"globals": "^15.14.0", | ||
"jsdom": "^26.0.0", | ||
"prettier": "^3.4.2", | ||
"react": "^18.3.1", | ||
"react-dom": "^18.3.1", | ||
"rollup": "^4.20.0", | ||
"svelte": "^4.2.18", | ||
"tsup": "^8.2.4", | ||
"vite": "^5.4.1", | ||
"vitest": "^2.0.5", | ||
"vue": "^3.4.38" | ||
"rollup": "^4.34.6", | ||
"svelte": "^4.2.19", | ||
"tsup": "^8.3.6", | ||
"tsx": "^4.19.2", | ||
"typescript-eslint": "^8.23.0", | ||
"vite": "^6.1.0", | ||
"vitest": "^3.0.5", | ||
"vue": "^3.5.13" | ||
}, | ||
@@ -90,9 +94,9 @@ "keywords": [ | ||
"volta": { | ||
"node": "20.9.0" | ||
"node": "22.13.1" | ||
}, | ||
"dependencies": { | ||
"debug": "^4.3.6", | ||
"fast-glob": "^3.3.2", | ||
"picocolors": "^1.0.1", | ||
"sirv": "^2.0.4" | ||
"debug": "^4.4.0", | ||
"fast-glob": "^3.3.3", | ||
"picocolors": "^1.1.1", | ||
"sirv": "^3.0.0" | ||
}, | ||
@@ -124,4 +128,5 @@ "symfony": { | ||
"tsc:check": "tsc --noEmit", | ||
"lint:check": "eslint -c eslint.config.js ./src" | ||
"lint:check": "eslint -c eslint.config.js ./src", | ||
"postinstall": "tsx ./scripts/postinstall.ts" | ||
} | ||
} |
@@ -77,3 +77,3 @@ <div> | ||
"vite": "^5.0", | ||
"vite-plugin-symfony": "^7.1" | ||
"vite-plugin-symfony": "^8.0" | ||
} | ||
@@ -80,0 +80,0 @@ } |
@@ -143,7 +143,11 @@ import { Logger, ResolvedConfig } from "vite"; | ||
export const stimulusFetchRE = new RegExp(notACommentRE.source + importMetaStimulusFetchRE.source, "m"); | ||
const stimulusIdentifierRE = new RegExp(notACommentRE.source + importMetaStimulusIdentifierRE.source, "m"); | ||
export const stimulusIdentifierRE = new RegExp(notACommentRE.source + importMetaStimulusIdentifierRE.source, "m"); | ||
const stimulusEnabledRE = new RegExp(notACommentRE.source + importMetaStimulusEnabledRE.source, "m"); | ||
export function extractStimulusIdentifier(code: string): string | null { | ||
return (code.match(stimulusIdentifierRE) || [])[1] ?? null; | ||
} | ||
export function parseStimulusRequest( | ||
code: string, | ||
srcCode: string, | ||
moduleId: string, | ||
@@ -160,4 +164,4 @@ pluginOptions: VitePluginSymfonyStimulusOptions, | ||
const fetch = (code.match(stimulusFetchRE) || [])[1] ?? pluginOptions.fetchMode; | ||
let id = (code.match(stimulusIdentifierRE) || [])[1]; | ||
const fetch = (srcCode.match(stimulusFetchRE) || [])[1] ?? pluginOptions.fetchMode; | ||
let id = extractStimulusIdentifier(srcCode); | ||
if (!id) { | ||
@@ -169,21 +173,23 @@ const relativePath = relative(viteConfig.root, filePath); | ||
} | ||
const enabled = ((code.match(stimulusEnabledRE) || [])[1] ?? "true") === "false" ? false : true; | ||
const enabled = ((srcCode.match(stimulusEnabledRE) || [])[1] ?? "true") === "false" ? false : true; | ||
if (fetch === "eager") { | ||
return ` | ||
const dstCode = | ||
fetch === "eager" | ||
? ` | ||
import Controller from '${filePath}'; | ||
export default { | ||
enabled: ${enabled}, | ||
fetch: 'eager', | ||
identifier: '${id}', | ||
controller: Controller | ||
}`; | ||
} else { | ||
return `export default { | ||
enabled: ${enabled}, | ||
fetch: 'lazy', | ||
identifier: '${id}', | ||
controller: () => import('${filePath}') | ||
}`; | ||
} | ||
enabled: ${enabled}, | ||
fetch: 'eager', | ||
identifier: '${id}', | ||
controller: Controller | ||
}` | ||
: ` | ||
export default { | ||
enabled: ${enabled}, | ||
fetch: 'lazy', | ||
identifier: '${id}', | ||
controller: () => import('${filePath}') | ||
}`; | ||
return `${dstCode}\nif (import.meta.hot) { import.meta.hot.accept(); }`; | ||
} |
@@ -21,5 +21,2 @@ import { Logger } from "vite"; | ||
export function addControllerHmrCode(code: string, identifier: string) { | ||
// we don't need lazy behavior, the module is already loaded and we are in a dev environment | ||
// TODO explain comment | ||
const metaHotFooter = ` | ||
@@ -32,3 +29,8 @@ if (import.meta.hot) { | ||
} else { | ||
window.${applicationGlobalVarName}.register('${identifier}', newModule.default); | ||
if (window.${applicationGlobalVarName}.router.modulesByIdentifier.has('${identifier}') && newModule.default) { | ||
window.${applicationGlobalVarName}.register('${identifier}', newModule.default); | ||
} else { | ||
console.warn('Try to HMR not registered Stimulus controller', '${identifier}', 'full-reload'); | ||
import.meta.hot.invalidate(); | ||
} | ||
} | ||
@@ -35,0 +37,0 @@ }) |
@@ -1,3 +0,8 @@ | ||
import { createControllersModule, virtualSymfonyControllersModuleId, parseStimulusRequest } from "./bridge"; | ||
import { relative, resolve } from "node:path"; | ||
import { | ||
createControllersModule, | ||
virtualSymfonyControllersModuleId, | ||
parseStimulusRequest, | ||
extractStimulusIdentifier, | ||
} from "./bridge"; | ||
import { join, relative, resolve } from "node:path"; | ||
import { Logger, Plugin, ResolvedConfig, UserConfig } from "vite"; | ||
@@ -48,3 +53,3 @@ import { VitePluginSymfonyStimulusOptions } from "~/types"; | ||
}, | ||
resolveId(id: string) { | ||
resolveId(this: unknown, id) { | ||
if (id === virtualSymfonyControllersModuleId) { | ||
@@ -54,3 +59,3 @@ return id; | ||
}, | ||
load(id) { | ||
load(this: unknown, id) { | ||
if (id === virtualSymfonyControllersModuleId) { | ||
@@ -64,3 +69,3 @@ if (controllersJsonContent) { | ||
}, | ||
transform(code, id, options) { | ||
transform(this: unknown, code, id, options) { | ||
if ((options?.ssr && !process.env.VITEST) || id.includes("node_modules") || isVirtualRequest(id)) { | ||
@@ -74,3 +79,3 @@ return null; | ||
if (viteCommand === "serve") { | ||
if (viteCommand === "serve" && pluginOptions.hmr) { | ||
if (id.endsWith("bootstrap.js") || id.endsWith("bootstrap.ts")) { | ||
@@ -80,9 +85,17 @@ return addBootstrapHmrCode(code, logger); | ||
if (isPathIncluded(viteConfig.root, id)) { | ||
const relativePath = relative(viteConfig.root, id); | ||
const identifier = getStimulusControllerId(relativePath, pluginOptions.identifierResolutionMethod); | ||
if (identifier) { | ||
return addControllerHmrCode(code, identifier); | ||
} | ||
const isInsideControllerDir = isPathIncluded(join(viteConfig.root, pluginOptions.controllersDir), id); | ||
if (!isInsideControllerDir) { | ||
return null; | ||
} | ||
const relativePath = relative(viteConfig.root, id); | ||
const identifier = | ||
extractStimulusIdentifier(code) ?? | ||
getStimulusControllerId(relativePath, pluginOptions.identifierResolutionMethod); | ||
if (identifier) { | ||
return addControllerHmrCode(code, identifier); | ||
} | ||
} | ||
@@ -89,0 +102,0 @@ |
@@ -9,2 +9,3 @@ import { VitePluginSymfonyStimulusOptions } from "~/types"; | ||
config = { | ||
controllersDir: "./assets/controllers", | ||
controllersFilePath: "./assets/controllers.json", | ||
@@ -17,2 +18,3 @@ hmr: true, | ||
config = { | ||
controllersDir: "./assets/controllers", | ||
controllersFilePath: userConfig, | ||
@@ -25,2 +27,3 @@ hmr: true, | ||
config = { | ||
controllersDir: userConfig.controllersDir ?? "./assets/controllers", | ||
controllersFilePath: userConfig.controllersFilePath ?? "./assets/controllers.json", | ||
@@ -27,0 +30,0 @@ hmr: userConfig.hmr !== false ? true : false, |
@@ -27,3 +27,3 @@ import "rollup"; | ||
legacy: boolean; | ||
metadatas: FileMetadatas; | ||
metadatas: FilesMetadatas; | ||
version: [string, number, number, number]; | ||
@@ -218,4 +218,11 @@ viteServer: string | null; | ||
/** | ||
* path to the deepest folder that contains all your stimulus controllers | ||
* relative to vite root | ||
* @default "./assets/controllers" | ||
*/ | ||
controllersDir: string; | ||
/** | ||
* path to controllers.json relative to vite root | ||
* @default ./assets/controller.json | ||
* @default "./assets/controller.json" | ||
*/ | ||
@@ -222,0 +229,0 @@ controllersFilePath: string; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
299792
74
6746
20
1
+ Addedsirv@3.0.1(transitive)
- Removedsirv@2.0.4(transitive)
Updateddebug@^4.4.0
Updatedfast-glob@^3.3.3
Updatedpicocolors@^1.1.1
Updatedsirv@^3.0.0