@bemedev/dev-utils 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/plugins/hmr.cjs +0 -3
- package/lib/plugins/hmr.cjs.map +1 -1
- package/lib/plugins/hmr.js +0 -3
- package/lib/plugins/hmr.js.map +1 -1
- package/package.json +1 -1
package/lib/plugins/hmr.cjs
CHANGED
|
@@ -33,9 +33,6 @@ const hmr = (props) => {
|
|
|
33
33
|
const resolvedPaths = require_utils_array.toArray(props?.paths).map((p) => (0, path.isAbsolute)(p) ? p : (0, path.resolve)(config.root, p)).map(normalizePath);
|
|
34
34
|
paths.push(...resolvedPaths);
|
|
35
35
|
},
|
|
36
|
-
configEnvironment(name) {
|
|
37
|
-
isDev = name === "dev";
|
|
38
|
-
},
|
|
39
36
|
configureServer(server) {
|
|
40
37
|
if (!isDev) return;
|
|
41
38
|
server.watcher.add(paths);
|
package/lib/plugins/hmr.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hmr.cjs","names":["path","clamp","toArray","isAbsolute","resolve"],"sources":["../../src/plugins/hmr.ts"],"sourcesContent":["import { execSync } from 'child_process';\nimport { resolve, isAbsolute } from 'path';\n\nimport { type Plugin } from 'vitest/config';\n\nimport { toArray } from '#utils/array';\nimport { clamp } from '#utils/clamp';\nimport type { SoA } from '#utils/types';\n\n/**\n * Configuration options for the HMR add-on plugin.\n */\nexport type HmrPluginProps = {\n /** Single file path or array of file paths of type {@linkcode SoA} to watch for changes. */\n paths?: SoA<string>;\n\n /** Single shell command or array of shell commands of type {@linkcode SoA} to execute when a change is detected. */\n scripts?: SoA<string>;\n\n /** Optional interval in milliseconds to wait before allowing another build. */\n debounce?: number;\n};\n\n/**\n * Normalizes backslashes in a file path to forward slashes.\n *\n * @param path - File path to normalize.\n *\n * @returns Normalized path string.\n */\nconst normalizePath = (path: string) => path.replace(/\\\\/g, '/');\n\n/**\n * Vite plugin providing Hot Module Reloading (HMR) capabilities for external\n * file paths by watching files and executing build scripts on changes.\n *\n * @param props - Configuration properties of type {@linkcode HmrPluginProps}.\n *\n * @returns A Vite plugin object of type {@linkcode Plugin}.\n */\nexport const hmr = (props?: HmrPluginProps): Plugin => {\n // Lock variable to prevent infinite build loops\n let isBuilding = false;\n const debounce = clamp(props?.debounce ?? 500, 500, 10_000);\n const paths: string[] = [];\n let isDev = false;\n\n return {\n name: 'hmr-add-on',\n\n configResolved(config) {\n isDev = !config.isProduction;\n if (!isDev) return;\n\n // Resolve relative paths based on Vite project root\n const resolvedPaths = toArray(props?.paths)\n .map(p => (isAbsolute(p) ? p : resolve(config.root, p)))\n .map(normalizePath);\n\n paths.push(...resolvedPaths);\n },\n\n
|
|
1
|
+
{"version":3,"file":"hmr.cjs","names":["path","clamp","toArray","isAbsolute","resolve"],"sources":["../../src/plugins/hmr.ts"],"sourcesContent":["import { execSync } from 'child_process';\nimport { resolve, isAbsolute } from 'path';\n\nimport { type Plugin } from 'vitest/config';\n\nimport { toArray } from '#utils/array';\nimport { clamp } from '#utils/clamp';\nimport type { SoA } from '#utils/types';\n\n/**\n * Configuration options for the HMR add-on plugin.\n */\nexport type HmrPluginProps = {\n /** Single file path or array of file paths of type {@linkcode SoA} to watch for changes. */\n paths?: SoA<string>;\n\n /** Single shell command or array of shell commands of type {@linkcode SoA} to execute when a change is detected. */\n scripts?: SoA<string>;\n\n /** Optional interval in milliseconds to wait before allowing another build. */\n debounce?: number;\n};\n\n/**\n * Normalizes backslashes in a file path to forward slashes.\n *\n * @param path - File path to normalize.\n *\n * @returns Normalized path string.\n */\nconst normalizePath = (path: string) => path.replace(/\\\\/g, '/');\n\n/**\n * Vite plugin providing Hot Module Reloading (HMR) capabilities for external\n * file paths by watching files and executing build scripts on changes.\n *\n * @param props - Configuration properties of type {@linkcode HmrPluginProps}.\n *\n * @returns A Vite plugin object of type {@linkcode Plugin}.\n */\nexport const hmr = (props?: HmrPluginProps): Plugin => {\n // Lock variable to prevent infinite build loops\n let isBuilding = false;\n const debounce = clamp(props?.debounce ?? 500, 500, 10_000);\n const paths: string[] = [];\n let isDev = false;\n\n return {\n name: 'hmr-add-on',\n\n configResolved(config) {\n isDev = !config.isProduction;\n if (!isDev) return;\n\n // Resolve relative paths based on Vite project root\n const resolvedPaths = toArray(props?.paths)\n .map(p => (isAbsolute(p) ? p : resolve(config.root, p)))\n .map(normalizePath);\n\n paths.push(...resolvedPaths);\n },\n\n configureServer(server) {\n if (!isDev) return;\n\n server.watcher.add(paths);\n },\n\n handleHotUpdate(ctx) {\n if (!isDev) return;\n\n // 1. If a build is already in progress, ignore ALL changes (prevents loops)\n if (isBuilding) return ctx.modules;\n const normalizedFile = normalizePath(ctx.file);\n const checks = paths.some(p => normalizedFile.includes(p));\n\n if (checks) {\n console.log(\n `\\n⚡ External file modified: ${ctx.file}. Starting build...`,\n );\n\n try {\n // 2. Acquire lock before starting the build\n isBuilding = true;\n const scripts = toArray(props?.scripts);\n\n scripts.forEach(script => {\n execSync(script, { stdio: 'inherit' });\n });\n\n // Invalidate module graph so Vite reads fresh built files from disk\n ctx.server.moduleGraph.invalidateAll();\n ctx.server.ws.send({ type: 'full-reload' });\n } catch (error) {\n console.error('❌ Command execution failed during HMR:', error);\n } finally {\n // 3. Once build is complete, wait for the debounce period to allow\n // Vite to ignore generated build files, then release the lock.\n setTimeout(() => {\n isBuilding = false;\n console.log(\n '✅ Build completed. Ready for subsequent changes.',\n );\n }, debounce);\n }\n }\n\n return ctx.modules;\n },\n };\n};\n"],"mappings":";;;;;;;;;;;;;AA8BA,MAAM,iBAAiB,WAAiBA,OAAK,QAAQ,OAAO,GAAG;;;;;;;;;AAU/D,MAAa,OAAO,UAAmC;CAErD,IAAI,aAAa;CACjB,MAAM,WAAWC,oBAAAA,MAAM,OAAO,YAAY,KAAK,KAAK,GAAM;CAC1D,MAAM,QAAkB,CAAC;CACzB,IAAI,QAAQ;CAEZ,OAAO;EACL,MAAM;EAEN,eAAe,QAAQ;GACrB,QAAQ,CAAC,OAAO;GAChB,IAAI,CAAC,OAAO;GAGZ,MAAM,gBAAgBC,oBAAAA,QAAQ,OAAO,KAAK,CAAC,CACxC,KAAI,OAAA,GAAMC,KAAAA,WAAAA,CAAW,CAAC,IAAI,KAAA,GAAIC,KAAAA,QAAAA,CAAQ,OAAO,MAAM,CAAC,CAAE,CAAC,CACvD,IAAI,aAAa;GAEpB,MAAM,KAAK,GAAG,aAAa;EAC7B;EAEA,gBAAgB,QAAQ;GACtB,IAAI,CAAC,OAAO;GAEZ,OAAO,QAAQ,IAAI,KAAK;EAC1B;EAEA,gBAAgB,KAAK;GACnB,IAAI,CAAC,OAAO;GAGZ,IAAI,YAAY,OAAO,IAAI;GAC3B,MAAM,iBAAiB,cAAc,IAAI,IAAI;GAG7C,IAFe,MAAM,MAAK,MAAK,eAAe,SAAS,CAAC,CAE/C,GAAG;IACV,QAAQ,IACN,+BAA+B,IAAI,KAAK,oBAC1C;IAEA,IAAI;KAEF,aAAa;KAGb,oBAFgBF,QAAQ,OAAO,OAEzB,CAAC,CAAC,SAAQ,WAAU;MACxB,CAAA,GAAA,cAAA,SAAA,CAAS,QAAQ,EAAE,OAAO,UAAU,CAAC;KACvC,CAAC;KAGD,IAAI,OAAO,YAAY,cAAc;KACrC,IAAI,OAAO,GAAG,KAAK,EAAE,MAAM,cAAc,CAAC;IAC5C,SAAS,OAAO;KACd,QAAQ,MAAM,0CAA0C,KAAK;IAC/D,UAAU;KAGR,iBAAiB;MACf,aAAa;MACb,QAAQ,IACN,kDACF;KACF,GAAG,QAAQ;IACb;GACF;GAEA,OAAO,IAAI;EACb;CACF;AACF"}
|
package/lib/plugins/hmr.js
CHANGED
|
@@ -32,9 +32,6 @@ const hmr = (props) => {
|
|
|
32
32
|
const resolvedPaths = toArray(props?.paths).map((p) => isAbsolute(p) ? p : resolve(config.root, p)).map(normalizePath);
|
|
33
33
|
paths.push(...resolvedPaths);
|
|
34
34
|
},
|
|
35
|
-
configEnvironment(name) {
|
|
36
|
-
isDev = name === "dev";
|
|
37
|
-
},
|
|
38
35
|
configureServer(server) {
|
|
39
36
|
if (!isDev) return;
|
|
40
37
|
server.watcher.add(paths);
|
package/lib/plugins/hmr.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hmr.js","names":[],"sources":["../../src/plugins/hmr.ts"],"sourcesContent":["import { execSync } from 'child_process';\nimport { resolve, isAbsolute } from 'path';\n\nimport { type Plugin } from 'vitest/config';\n\nimport { toArray } from '#utils/array';\nimport { clamp } from '#utils/clamp';\nimport type { SoA } from '#utils/types';\n\n/**\n * Configuration options for the HMR add-on plugin.\n */\nexport type HmrPluginProps = {\n /** Single file path or array of file paths of type {@linkcode SoA} to watch for changes. */\n paths?: SoA<string>;\n\n /** Single shell command or array of shell commands of type {@linkcode SoA} to execute when a change is detected. */\n scripts?: SoA<string>;\n\n /** Optional interval in milliseconds to wait before allowing another build. */\n debounce?: number;\n};\n\n/**\n * Normalizes backslashes in a file path to forward slashes.\n *\n * @param path - File path to normalize.\n *\n * @returns Normalized path string.\n */\nconst normalizePath = (path: string) => path.replace(/\\\\/g, '/');\n\n/**\n * Vite plugin providing Hot Module Reloading (HMR) capabilities for external\n * file paths by watching files and executing build scripts on changes.\n *\n * @param props - Configuration properties of type {@linkcode HmrPluginProps}.\n *\n * @returns A Vite plugin object of type {@linkcode Plugin}.\n */\nexport const hmr = (props?: HmrPluginProps): Plugin => {\n // Lock variable to prevent infinite build loops\n let isBuilding = false;\n const debounce = clamp(props?.debounce ?? 500, 500, 10_000);\n const paths: string[] = [];\n let isDev = false;\n\n return {\n name: 'hmr-add-on',\n\n configResolved(config) {\n isDev = !config.isProduction;\n if (!isDev) return;\n\n // Resolve relative paths based on Vite project root\n const resolvedPaths = toArray(props?.paths)\n .map(p => (isAbsolute(p) ? p : resolve(config.root, p)))\n .map(normalizePath);\n\n paths.push(...resolvedPaths);\n },\n\n
|
|
1
|
+
{"version":3,"file":"hmr.js","names":[],"sources":["../../src/plugins/hmr.ts"],"sourcesContent":["import { execSync } from 'child_process';\nimport { resolve, isAbsolute } from 'path';\n\nimport { type Plugin } from 'vitest/config';\n\nimport { toArray } from '#utils/array';\nimport { clamp } from '#utils/clamp';\nimport type { SoA } from '#utils/types';\n\n/**\n * Configuration options for the HMR add-on plugin.\n */\nexport type HmrPluginProps = {\n /** Single file path or array of file paths of type {@linkcode SoA} to watch for changes. */\n paths?: SoA<string>;\n\n /** Single shell command or array of shell commands of type {@linkcode SoA} to execute when a change is detected. */\n scripts?: SoA<string>;\n\n /** Optional interval in milliseconds to wait before allowing another build. */\n debounce?: number;\n};\n\n/**\n * Normalizes backslashes in a file path to forward slashes.\n *\n * @param path - File path to normalize.\n *\n * @returns Normalized path string.\n */\nconst normalizePath = (path: string) => path.replace(/\\\\/g, '/');\n\n/**\n * Vite plugin providing Hot Module Reloading (HMR) capabilities for external\n * file paths by watching files and executing build scripts on changes.\n *\n * @param props - Configuration properties of type {@linkcode HmrPluginProps}.\n *\n * @returns A Vite plugin object of type {@linkcode Plugin}.\n */\nexport const hmr = (props?: HmrPluginProps): Plugin => {\n // Lock variable to prevent infinite build loops\n let isBuilding = false;\n const debounce = clamp(props?.debounce ?? 500, 500, 10_000);\n const paths: string[] = [];\n let isDev = false;\n\n return {\n name: 'hmr-add-on',\n\n configResolved(config) {\n isDev = !config.isProduction;\n if (!isDev) return;\n\n // Resolve relative paths based on Vite project root\n const resolvedPaths = toArray(props?.paths)\n .map(p => (isAbsolute(p) ? p : resolve(config.root, p)))\n .map(normalizePath);\n\n paths.push(...resolvedPaths);\n },\n\n configureServer(server) {\n if (!isDev) return;\n\n server.watcher.add(paths);\n },\n\n handleHotUpdate(ctx) {\n if (!isDev) return;\n\n // 1. If a build is already in progress, ignore ALL changes (prevents loops)\n if (isBuilding) return ctx.modules;\n const normalizedFile = normalizePath(ctx.file);\n const checks = paths.some(p => normalizedFile.includes(p));\n\n if (checks) {\n console.log(\n `\\n⚡ External file modified: ${ctx.file}. Starting build...`,\n );\n\n try {\n // 2. Acquire lock before starting the build\n isBuilding = true;\n const scripts = toArray(props?.scripts);\n\n scripts.forEach(script => {\n execSync(script, { stdio: 'inherit' });\n });\n\n // Invalidate module graph so Vite reads fresh built files from disk\n ctx.server.moduleGraph.invalidateAll();\n ctx.server.ws.send({ type: 'full-reload' });\n } catch (error) {\n console.error('❌ Command execution failed during HMR:', error);\n } finally {\n // 3. Once build is complete, wait for the debounce period to allow\n // Vite to ignore generated build files, then release the lock.\n setTimeout(() => {\n isBuilding = false;\n console.log(\n '✅ Build completed. Ready for subsequent changes.',\n );\n }, debounce);\n }\n }\n\n return ctx.modules;\n },\n };\n};\n"],"mappings":";;;;;;;;;;;;AA8BA,MAAM,iBAAiB,SAAiB,KAAK,QAAQ,OAAO,GAAG;;;;;;;;;AAU/D,MAAa,OAAO,UAAmC;CAErD,IAAI,aAAa;CACjB,MAAM,WAAW,MAAM,OAAO,YAAY,KAAK,KAAK,GAAM;CAC1D,MAAM,QAAkB,CAAC;CACzB,IAAI,QAAQ;CAEZ,OAAO;EACL,MAAM;EAEN,eAAe,QAAQ;GACrB,QAAQ,CAAC,OAAO;GAChB,IAAI,CAAC,OAAO;GAGZ,MAAM,gBAAgB,QAAQ,OAAO,KAAK,CAAC,CACxC,KAAI,MAAM,WAAW,CAAC,IAAI,IAAI,QAAQ,OAAO,MAAM,CAAC,CAAE,CAAC,CACvD,IAAI,aAAa;GAEpB,MAAM,KAAK,GAAG,aAAa;EAC7B;EAEA,gBAAgB,QAAQ;GACtB,IAAI,CAAC,OAAO;GAEZ,OAAO,QAAQ,IAAI,KAAK;EAC1B;EAEA,gBAAgB,KAAK;GACnB,IAAI,CAAC,OAAO;GAGZ,IAAI,YAAY,OAAO,IAAI;GAC3B,MAAM,iBAAiB,cAAc,IAAI,IAAI;GAG7C,IAFe,MAAM,MAAK,MAAK,eAAe,SAAS,CAAC,CAE/C,GAAG;IACV,QAAQ,IACN,+BAA+B,IAAI,KAAK,oBAC1C;IAEA,IAAI;KAEF,aAAa;KAGb,QAFwB,OAAO,OAEzB,CAAC,CAAC,SAAQ,WAAU;MACxB,SAAS,QAAQ,EAAE,OAAO,UAAU,CAAC;KACvC,CAAC;KAGD,IAAI,OAAO,YAAY,cAAc;KACrC,IAAI,OAAO,GAAG,KAAK,EAAE,MAAM,cAAc,CAAC;IAC5C,SAAS,OAAO;KACd,QAAQ,MAAM,0CAA0C,KAAK;IAC/D,UAAU;KAGR,iBAAiB;MACf,aAAa;MACb,QAAQ,IACN,kDACF;KACF,GAAG,QAAQ;IACb;GACF;GAEA,OAAO,IAAI;EACb;CACF;AACF"}
|
package/package.json
CHANGED