@sapphire/plugin-hmr
Advanced tools
Comparing version 1.1.1 to 1.2.0-next.4637680.0
import { WatchOptions } from 'chokidar'; | ||
export interface HMROptions extends WatchOptions { | ||
enabled?: boolean; | ||
silent?: boolean; | ||
} | ||
@@ -15,3 +16,3 @@ /** | ||
*/ | ||
export declare function start({ enabled, ...options }?: HMROptions): void; | ||
export declare function start({ enabled, silent, ...options }?: HMROptions): void; | ||
//# sourceMappingURL=hmr.d.ts.map |
@@ -17,17 +17,16 @@ "use strict"; | ||
*/ | ||
function start({ enabled = true, ...options } = { enabled: true }) { | ||
function start({ enabled = true, silent = false, ...options } = { enabled: true }) { | ||
// Do not enable plugin when enabled is false | ||
if (!enabled) | ||
return; | ||
framework_1.container.logger.info('[HMR-Plugin]: Enabled. Watching for piece changes.'); | ||
if (!silent) | ||
framework_1.container.logger.info('[HMR-Plugin]: Enabled. Watching for piece changes.'); | ||
for (const store of framework_1.container.stores.values()) { | ||
const deleteCb = handlePiecePathDelete.bind(null, store); | ||
const updateCb = handlePiecePathUpdate.bind(null, store); | ||
(0, chokidar_1.watch)([...store.paths], options) | ||
.on('change', updateCb) | ||
.on('unlink', deleteCb); | ||
.on('change', (path) => handlePiecePathUpdate(store, path, silent)) | ||
.on('unlink', (path) => handlePiecePathDelete(store, path, silent)); | ||
} | ||
} | ||
exports.start = start; | ||
async function handlePiecePathDelete(store, path) { | ||
async function handlePiecePathDelete(store, path, silent) { | ||
if (!store.strategy.filter(path)) | ||
@@ -40,3 +39,4 @@ return; | ||
await pieceToDelete.unload(); | ||
framework_1.container.logger.info(`[HMR-Plugin]: Unloaded ${pieceToDelete.name} piece from ${pieceToDelete.store.name} store.`); | ||
if (!silent) | ||
framework_1.container.logger.info(`[HMR-Plugin]: Unloaded ${pieceToDelete.name} piece from ${pieceToDelete.store.name} store.`); | ||
}); | ||
@@ -47,3 +47,3 @@ if ((0, framework_1.isErr)(result)) { | ||
} | ||
async function handlePiecePathUpdate(store, path) { | ||
async function handlePiecePathUpdate(store, path, silent) { | ||
if (!store.strategy.filter(path)) | ||
@@ -55,3 +55,4 @@ return; | ||
await pieceToUpdate.reload(); | ||
framework_1.container.logger.info(`[HMR-Plugin]: reloaded ${pieceToUpdate.name} piece from ${pieceToUpdate.store.name} store.`); | ||
if (!silent) | ||
framework_1.container.logger.info(`[HMR-Plugin]: reloaded ${pieceToUpdate.name} piece from ${pieceToUpdate.store.name} store.`); | ||
} | ||
@@ -65,3 +66,4 @@ else { | ||
const piecesLoadedStoreNames = piecesLoaded.map((piece) => piece.store.name); | ||
framework_1.container.logger.info(`[HMR-Plugin]: Loaded ${piecesLoadedNames.join(', ')} piece(s) from ${[...new Set(piecesLoadedStoreNames)].join(', ')} store(s).`); | ||
if (!silent) | ||
framework_1.container.logger.info(`[HMR-Plugin]: Loaded ${piecesLoadedNames.join(', ')} piece(s) from ${[...new Set(piecesLoadedStoreNames)].join(', ')} store(s).`); | ||
} | ||
@@ -68,0 +70,0 @@ }); |
{ | ||
"name": "@sapphire/plugin-hmr", | ||
"version": "1.1.1", | ||
"version": "1.2.0-next.4637680.0", | ||
"description": "Plugin for @sapphire/framework for hot module reloading for pieces", | ||
@@ -68,3 +68,3 @@ "author": "@sapphire", | ||
}, | ||
"gitHead": "8efee8b0bbdbddb43bb1836346f2a91cf20f6274" | ||
"gitHead": "4637680bd5b0c431a5fa1fa2df663d785644199e" | ||
} |
@@ -166,2 +166,6 @@ <div align="center"> | ||
</tr> | ||
<tr> | ||
<td align="center"><a href="https://github.com/Suyashtnt"><img src="https://avatars.githubusercontent.com/u/45307955?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Just a Badly Drawn TABS Dude</b></sub></a><br /><a href="https://github.com/sapphiredev/plugins/commits?author=Suyashtnt" title="Code">π»</a></td> | ||
<td align="center"><a href="https://newtt.me/"><img src="https://avatars.githubusercontent.com/u/19301186?v=4?s=100" width="100px;" alt=""/><br /><sub><b>newt :D</b></sub></a><br /><a href="https://github.com/sapphiredev/plugins/commits?author=newtykins" title="Code">π»</a></td> | ||
</tr> | ||
</table> | ||
@@ -168,0 +172,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
24986
137
179
1