@sapphire/plugin-hmr 2.0.4-next.eccc557.0 → 3.0.0-next.d9aa006.0
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/dist/cjs/index.cjs +16 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.ts +32 -0
- package/dist/cjs/lib/hmr.cjs +63 -0
- package/dist/cjs/lib/hmr.cjs.map +1 -0
- package/dist/cjs/register.cjs +23 -0
- package/dist/cjs/register.cjs.map +1 -0
- package/dist/{register.d.ts → cjs/register.d.ts} +5 -3
- package/dist/esm/chunk-G5GHKT7C.mjs +6 -0
- package/dist/esm/chunk-G5GHKT7C.mjs.map +1 -0
- package/dist/esm/index.d.mts +32 -0
- package/dist/esm/index.mjs +8 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/lib/hmr.mjs +60 -0
- package/dist/esm/lib/hmr.mjs.map +1 -0
- package/dist/esm/register.d.mts +14 -0
- package/dist/esm/register.mjs +20 -0
- package/dist/esm/register.mjs.map +1 -0
- package/package.json +34 -18
- package/dist/index.d.ts +0 -8
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -18
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -4
- package/dist/lib/hmr.d.ts +0 -17
- package/dist/lib/hmr.d.ts.map +0 -1
- package/dist/lib/hmr.js +0 -66
- package/dist/lib/hmr.js.map +0 -1
- package/dist/register.d.ts.map +0 -1
- package/dist/register.js +0 -20
- package/dist/register.js.map +0 -1
- package/dist/register.mjs +0 -4
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var hmr_cjs = require('./lib/hmr.cjs');
|
|
4
|
+
|
|
5
|
+
// src/index.ts
|
|
6
|
+
var version = "3.0.0-next.d9aa006.0";
|
|
7
|
+
|
|
8
|
+
exports.version = version;
|
|
9
|
+
Object.keys(hmr_cjs).forEach(function (k) {
|
|
10
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () { return hmr_cjs[k]; }
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
//# sourceMappingURL=out.js.map
|
|
16
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,cAAc;AAiBP,IAAM,UAAkB","sourcesContent":["export * from './lib/hmr';\n\nimport type { HMROptions } from './lib/hmr';\n\ndeclare module 'discord.js' {\n\texport interface ClientOptions {\n\t\thmr?: HMROptions;\n\t}\n}\n\n/**\n * The [@sapphire/plugin-hmr](https://github.com/sapphiredev/plugins/blob/main/packages/hmr) version that you are currently using.\n * An example use of this is showing it of in a bot information command.\n *\n * Note to Sapphire developers: This needs to explicitly be `string` so it is not typed as the string that gets replaced by esbuild\n */\n// eslint-disable-next-line @typescript-eslint/no-inferrable-types\nexport const version: string = '3.0.0-next.d9aa006.0';\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { WatchOptions } from 'chokidar';
|
|
2
|
+
|
|
3
|
+
interface HMROptions extends WatchOptions {
|
|
4
|
+
enabled?: boolean;
|
|
5
|
+
silent?: boolean;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Starts HMR for all registered {@link Store Stores} in {@link container.stores the main container}.
|
|
9
|
+
*
|
|
10
|
+
* @param __namedParameter The {@link HMROptions}.
|
|
11
|
+
* This includes [all options from chokidar](https://github.com/paulmillr/chokidar#persistence),
|
|
12
|
+
* as well as whether the HMR should be enabled.
|
|
13
|
+
* The default options are `{ enabled: true }`,
|
|
14
|
+
* and if not provided in the object then `enabled` is also set to true.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
declare function start({ enabled, silent, ...options }?: HMROptions): void;
|
|
18
|
+
|
|
19
|
+
declare module 'discord.js' {
|
|
20
|
+
interface ClientOptions {
|
|
21
|
+
hmr?: HMROptions;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The [@sapphire/plugin-hmr](https://github.com/sapphiredev/plugins/blob/main/packages/hmr) version that you are currently using.
|
|
26
|
+
* An example use of this is showing it of in a bot information command.
|
|
27
|
+
*
|
|
28
|
+
* Note to Sapphire developers: This needs to explicitly be `string` so it is not typed as the string that gets replaced by esbuild
|
|
29
|
+
*/
|
|
30
|
+
declare const version: string;
|
|
31
|
+
|
|
32
|
+
export { type HMROptions, start, version };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var framework = require('@sapphire/framework');
|
|
4
|
+
var chokidar = require('chokidar');
|
|
5
|
+
var path = require('path');
|
|
6
|
+
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
function start({ enabled = true, silent = false, ...options } = { enabled: true }) {
|
|
10
|
+
if (!enabled)
|
|
11
|
+
return;
|
|
12
|
+
if (!silent)
|
|
13
|
+
framework.container.logger.info("[HMR-Plugin]: Enabled. Watching for piece changes.");
|
|
14
|
+
for (const store of framework.container.stores.values()) {
|
|
15
|
+
chokidar.watch([...store.paths], options).on("change", (path) => handlePiecePathUpdate(store, path, silent)).on("unlink", (path) => handlePiecePathDelete(store, path, silent));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
__name(start, "start");
|
|
19
|
+
async function handlePiecePathDelete(store, path, silent) {
|
|
20
|
+
if (!store.strategy.filter(path))
|
|
21
|
+
return;
|
|
22
|
+
const pieceToDelete = store.find((piece) => piece.location.full === path);
|
|
23
|
+
if (!pieceToDelete)
|
|
24
|
+
return;
|
|
25
|
+
const result = await framework.Result.fromAsync(async () => {
|
|
26
|
+
await pieceToDelete.unload();
|
|
27
|
+
if (!silent)
|
|
28
|
+
framework.container.logger.info(`[HMR-Plugin]: Unloaded ${pieceToDelete.name} piece from ${pieceToDelete.store.name} store.`);
|
|
29
|
+
});
|
|
30
|
+
result.inspectErr(
|
|
31
|
+
(error) => framework.container.logger.error(`[HMR-Plugin]: Failed to unload ${pieceToDelete.name} piece from ${pieceToDelete.store.name} store.`, error)
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
__name(handlePiecePathDelete, "handlePiecePathDelete");
|
|
35
|
+
async function handlePiecePathUpdate(store, path$1, silent) {
|
|
36
|
+
if (!store.strategy.filter(path$1))
|
|
37
|
+
return;
|
|
38
|
+
const pieceToUpdate = store.find((piece) => piece.location.full === path$1);
|
|
39
|
+
const result = await framework.Result.fromAsync(async () => {
|
|
40
|
+
if (pieceToUpdate) {
|
|
41
|
+
await pieceToUpdate.reload();
|
|
42
|
+
if (!silent)
|
|
43
|
+
framework.container.logger.info(`[HMR-Plugin]: reloaded ${pieceToUpdate.name} piece from ${pieceToUpdate.store.name} store.`);
|
|
44
|
+
} else {
|
|
45
|
+
const rootPath = [...store.paths].find((storePath) => path$1.startsWith(storePath));
|
|
46
|
+
if (!rootPath)
|
|
47
|
+
throw new Error(`[HMR-Plugin]: Could not find root path for ${path$1}.`);
|
|
48
|
+
const piecesLoaded = await store.load(rootPath, path.relative(rootPath, path$1));
|
|
49
|
+
const piecesLoadedNames = piecesLoaded.map((piece) => piece.name);
|
|
50
|
+
const piecesLoadedStoreNames = piecesLoaded.map((piece) => piece.store.name);
|
|
51
|
+
if (!silent)
|
|
52
|
+
framework.container.logger.info(
|
|
53
|
+
`[HMR-Plugin]: Loaded ${piecesLoadedNames.join(", ")} piece(s) from ${[...new Set(piecesLoadedStoreNames)].join(", ")} store(s).`
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
result.inspectErr((error) => framework.container.logger.error(`[HMR-Plugin]: Failed to load pieces from ${path$1}.`, error));
|
|
58
|
+
}
|
|
59
|
+
__name(handlePiecePathUpdate, "handlePiecePathUpdate");
|
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S,OAAO,IAAI;AAAG;AAElC,QAAM,gBAAgB,MAAM,KAAK,CAAC,UAAU,MAAM,SAAS,SAAS,IAAI;AAExE,QAAM,SAAS,MAAM,OAAO,UAAU,YAAY;AACjD,QAAI,eAAe;AAClB,YAAM,cAAc,OAAO;AAC3B,UAAI,CAAC;AAAQ,kBAAU,OAAO,KAAK,0BAA0B,cAAc,IAAI,eAAe,cAAc,MAAM,IAAI,SAAS;AAAA,IAChI,OAAO;AACN,YAAM,WAAW,CAAC,GAAG,MAAM,KAAK,EAAE,KAAK,CAAC,cAAc,KAAK,WAAW,SAAS,CAAC;AAChF,UAAI,CAAC;AAAU,cAAM,IAAI,MAAM,8CAA8C,IAAI,GAAG;AAEpF,YAAM,eAAe,MAAM,MAAM,KAAK,UAAU,SAAS,UAAU,IAAI,CAAC;AACxE,YAAM,oBAAoB,aAAa,IAAI,CAAC,UAAU,MAAM,IAAI;AAChE,YAAM,yBAAyB,aAAa,IAAI,CAAC,UAAU,MAAM,MAAM,IAAI;AAC3E,UAAI,CAAC;AACJ,kBAAU,OAAO;AAAA,UAChB,wBAAwB,kBAAkB,KAAK,IAAI,CAAC,kBAAkB,CAAC,GAAG,IAAI,IAAI,sBAAsB,CAAC,EAAE,KAAK,IAAI,CAAC;AAAA,QACtH;AAAA,IACF;AAAA,EACD,CAAC;AAED,SAAO,WAAW,CAAC,UAAU,UAAU,OAAO,MAAM,4CAA4C,IAAI,KAAK,KAAK,CAAC;AAChH;AAxBe","sourcesContent":["import { Piece, Result, Store, container } from '@sapphire/framework';\nimport { watch, type WatchOptions } from 'chokidar';\nimport { relative } from 'node:path';\n\nexport interface HMROptions extends WatchOptions {\n\tenabled?: boolean;\n\tsilent?: boolean;\n}\n\n/**\n * Starts HMR for all registered {@link Store Stores} in {@link container.stores the main container}.\n *\n * @param __namedParameter The {@link HMROptions}.\n * This includes [all options from chokidar](https://github.com/paulmillr/chokidar#persistence),\n * as well as whether the HMR should be enabled.\n * The default options are `{ enabled: true }`,\n * and if not provided in the object then `enabled` is also set to true.\n *\n */\nexport function start({ enabled = true, silent = false, ...options }: HMROptions = { enabled: true }) {\n\t// Do not enable plugin when enabled is false\n\tif (!enabled) return;\n\n\tif (!silent) container.logger.info('[HMR-Plugin]: Enabled. Watching for piece changes.');\n\n\tfor (const store of container.stores.values()) {\n\t\twatch([...store.paths], options)\n\t\t\t.on('change', (path) => handlePiecePathUpdate(store, path, silent))\n\t\t\t.on('unlink', (path) => handlePiecePathDelete(store, path, silent));\n\t}\n}\n\nasync function handlePiecePathDelete(store: Store<Piece>, path: string, silent: boolean) {\n\tif (!store.strategy.filter(path)) return;\n\n\tconst pieceToDelete = store.find((piece) => piece.location.full === path);\n\tif (!pieceToDelete) return;\n\n\tconst result = await Result.fromAsync(async () => {\n\t\tawait pieceToDelete.unload();\n\t\tif (!silent) container.logger.info(`[HMR-Plugin]: Unloaded ${pieceToDelete.name} piece from ${pieceToDelete.store.name} store.`);\n\t});\n\n\tresult.inspectErr((error) =>\n\t\tcontainer.logger.error(`[HMR-Plugin]: Failed to unload ${pieceToDelete.name} piece from ${pieceToDelete.store.name} store.`, error)\n\t);\n}\n\nasync function handlePiecePathUpdate(store: Store<Piece>, path: string, silent: boolean) {\n\tif (!store.strategy.filter(path)) return;\n\n\tconst pieceToUpdate = store.find((piece) => piece.location.full === path);\n\n\tconst result = await Result.fromAsync(async () => {\n\t\tif (pieceToUpdate) {\n\t\t\tawait pieceToUpdate.reload();\n\t\t\tif (!silent) container.logger.info(`[HMR-Plugin]: reloaded ${pieceToUpdate.name} piece from ${pieceToUpdate.store.name} store.`);\n\t\t} else {\n\t\t\tconst rootPath = [...store.paths].find((storePath) => path.startsWith(storePath));\n\t\t\tif (!rootPath) throw new Error(`[HMR-Plugin]: Could not find root path for ${path}.`);\n\n\t\t\tconst piecesLoaded = await store.load(rootPath, relative(rootPath, path));\n\t\t\tconst piecesLoadedNames = piecesLoaded.map((piece) => piece.name);\n\t\t\tconst piecesLoadedStoreNames = piecesLoaded.map((piece) => piece.store.name);\n\t\t\tif (!silent)\n\t\t\t\tcontainer.logger.info(\n\t\t\t\t\t`[HMR-Plugin]: Loaded ${piecesLoadedNames.join(', ')} piece(s) from ${[...new Set(piecesLoadedStoreNames)].join(', ')} store(s).`\n\t\t\t\t);\n\t\t}\n\t});\n\n\tresult.inspectErr((error) => container.logger.error(`[HMR-Plugin]: Failed to load pieces from ${path}.`, error));\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var framework = require('@sapphire/framework');
|
|
4
|
+
require('./index.cjs');
|
|
5
|
+
var hmr_cjs = require('./lib/hmr.cjs');
|
|
6
|
+
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var _HmrPlugin = class _HmrPlugin extends framework.Plugin {
|
|
10
|
+
/**
|
|
11
|
+
* @since 1.0.0
|
|
12
|
+
*/
|
|
13
|
+
static [framework.postLogin]() {
|
|
14
|
+
hmr_cjs.start(this.options.hmr);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
__name(_HmrPlugin, "HmrPlugin");
|
|
18
|
+
var HmrPlugin = _HmrPlugin;
|
|
19
|
+
framework.SapphireClient.plugins.registerPostLoginHook(HmrPlugin[framework.postLogin], "Hmr-PostLogin");
|
|
20
|
+
|
|
21
|
+
exports.HmrPlugin = HmrPlugin;
|
|
22
|
+
//# sourceMappingURL=out.js.map
|
|
23
|
+
//# sourceMappingURL=register.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/register.ts"],"names":[],"mappings":";;;;AAAA,SAAS,QAAQ,WAAW,sBAAsB;AAClD,OAAO;AACP,SAAS,aAAa;AAKf,IAAM,aAAN,MAAM,mBAAkB,OAAO;AAAA;AAAA;AAAA;AAAA,EAIrC,QAAe,SAAS,IAA8B;AACrD,UAAM,KAAK,QAAQ,GAAG;AAAA,EACvB;AACD;AAPsC;AAA/B,IAAM,YAAN;AASP,eAAe,QAAQ,sBAAsB,UAAU,SAAS,GAAG,eAAe","sourcesContent":["import { Plugin, postLogin, SapphireClient } from '@sapphire/framework';\nimport './index';\nimport { start } from './lib/hmr';\n\n/**\n * @since 1.0.0\n */\nexport class HmrPlugin extends Plugin {\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic static [postLogin](this: SapphireClient): void {\n\t\tstart(this.options.hmr);\n\t}\n}\n\nSapphireClient.plugins.registerPostLoginHook(HmrPlugin[postLogin], 'Hmr-PostLogin');\n"]}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { Plugin, postLogin, SapphireClient } from '@sapphire/framework';
|
|
2
|
-
import './index';
|
|
2
|
+
import './index.cjs';
|
|
3
|
+
|
|
3
4
|
/**
|
|
4
5
|
* @since 1.0.0
|
|
5
6
|
*/
|
|
6
|
-
|
|
7
|
+
declare class HmrPlugin extends Plugin {
|
|
7
8
|
/**
|
|
8
9
|
* @since 1.0.0
|
|
9
10
|
*/
|
|
10
11
|
static [postLogin](this: SapphireClient): void;
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
+
|
|
14
|
+
export { HmrPlugin };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { WatchOptions } from 'chokidar';
|
|
2
|
+
|
|
3
|
+
interface HMROptions extends WatchOptions {
|
|
4
|
+
enabled?: boolean;
|
|
5
|
+
silent?: boolean;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Starts HMR for all registered {@link Store Stores} in {@link container.stores the main container}.
|
|
9
|
+
*
|
|
10
|
+
* @param __namedParameter The {@link HMROptions}.
|
|
11
|
+
* This includes [all options from chokidar](https://github.com/paulmillr/chokidar#persistence),
|
|
12
|
+
* as well as whether the HMR should be enabled.
|
|
13
|
+
* The default options are `{ enabled: true }`,
|
|
14
|
+
* and if not provided in the object then `enabled` is also set to true.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
declare function start({ enabled, silent, ...options }?: HMROptions): void;
|
|
18
|
+
|
|
19
|
+
declare module 'discord.js' {
|
|
20
|
+
interface ClientOptions {
|
|
21
|
+
hmr?: HMROptions;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The [@sapphire/plugin-hmr](https://github.com/sapphiredev/plugins/blob/main/packages/hmr) version that you are currently using.
|
|
26
|
+
* An example use of this is showing it of in a bot information command.
|
|
27
|
+
*
|
|
28
|
+
* Note to Sapphire developers: This needs to explicitly be `string` so it is not typed as the string that gets replaced by esbuild
|
|
29
|
+
*/
|
|
30
|
+
declare const version: string;
|
|
31
|
+
|
|
32
|
+
export { type HMROptions, start, version };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,cAAc;AAiBP,IAAM,UAAkB","sourcesContent":["export * from './lib/hmr';\n\nimport type { HMROptions } from './lib/hmr';\n\ndeclare module 'discord.js' {\n\texport interface ClientOptions {\n\t\thmr?: HMROptions;\n\t}\n}\n\n/**\n * The [@sapphire/plugin-hmr](https://github.com/sapphiredev/plugins/blob/main/packages/hmr) version that you are currently using.\n * An example use of this is showing it of in a bot information command.\n *\n * Note to Sapphire developers: This needs to explicitly be `string` so it is not typed as the string that gets replaced by esbuild\n */\n// eslint-disable-next-line @typescript-eslint/no-inferrable-types\nexport const version: string = '3.0.0-next.d9aa006.0';\n"]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { __name } from '../chunk-G5GHKT7C.mjs';
|
|
2
|
+
import { container, Result } from '@sapphire/framework';
|
|
3
|
+
import { watch } from 'chokidar';
|
|
4
|
+
import { relative } from 'node:path';
|
|
5
|
+
|
|
6
|
+
function start({ enabled = true, silent = false, ...options } = { enabled: true }) {
|
|
7
|
+
if (!enabled)
|
|
8
|
+
return;
|
|
9
|
+
if (!silent)
|
|
10
|
+
container.logger.info("[HMR-Plugin]: Enabled. Watching for piece changes.");
|
|
11
|
+
for (const store of container.stores.values()) {
|
|
12
|
+
watch([...store.paths], options).on("change", (path) => handlePiecePathUpdate(store, path, silent)).on("unlink", (path) => handlePiecePathDelete(store, path, silent));
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
__name(start, "start");
|
|
16
|
+
async function handlePiecePathDelete(store, path, silent) {
|
|
17
|
+
if (!store.strategy.filter(path))
|
|
18
|
+
return;
|
|
19
|
+
const pieceToDelete = store.find((piece) => piece.location.full === path);
|
|
20
|
+
if (!pieceToDelete)
|
|
21
|
+
return;
|
|
22
|
+
const result = await Result.fromAsync(async () => {
|
|
23
|
+
await pieceToDelete.unload();
|
|
24
|
+
if (!silent)
|
|
25
|
+
container.logger.info(`[HMR-Plugin]: Unloaded ${pieceToDelete.name} piece from ${pieceToDelete.store.name} store.`);
|
|
26
|
+
});
|
|
27
|
+
result.inspectErr(
|
|
28
|
+
(error) => container.logger.error(`[HMR-Plugin]: Failed to unload ${pieceToDelete.name} piece from ${pieceToDelete.store.name} store.`, error)
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
__name(handlePiecePathDelete, "handlePiecePathDelete");
|
|
32
|
+
async function handlePiecePathUpdate(store, path, silent) {
|
|
33
|
+
if (!store.strategy.filter(path))
|
|
34
|
+
return;
|
|
35
|
+
const pieceToUpdate = store.find((piece) => piece.location.full === path);
|
|
36
|
+
const result = await Result.fromAsync(async () => {
|
|
37
|
+
if (pieceToUpdate) {
|
|
38
|
+
await pieceToUpdate.reload();
|
|
39
|
+
if (!silent)
|
|
40
|
+
container.logger.info(`[HMR-Plugin]: reloaded ${pieceToUpdate.name} piece from ${pieceToUpdate.store.name} store.`);
|
|
41
|
+
} else {
|
|
42
|
+
const rootPath = [...store.paths].find((storePath) => path.startsWith(storePath));
|
|
43
|
+
if (!rootPath)
|
|
44
|
+
throw new Error(`[HMR-Plugin]: Could not find root path for ${path}.`);
|
|
45
|
+
const piecesLoaded = await store.load(rootPath, relative(rootPath, path));
|
|
46
|
+
const piecesLoadedNames = piecesLoaded.map((piece) => piece.name);
|
|
47
|
+
const piecesLoadedStoreNames = piecesLoaded.map((piece) => piece.store.name);
|
|
48
|
+
if (!silent)
|
|
49
|
+
container.logger.info(
|
|
50
|
+
`[HMR-Plugin]: Loaded ${piecesLoadedNames.join(", ")} piece(s) from ${[...new Set(piecesLoadedStoreNames)].join(", ")} store(s).`
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
result.inspectErr((error) => container.logger.error(`[HMR-Plugin]: Failed to load pieces from ${path}.`, error));
|
|
55
|
+
}
|
|
56
|
+
__name(handlePiecePathUpdate, "handlePiecePathUpdate");
|
|
57
|
+
|
|
58
|
+
export { start };
|
|
59
|
+
//# sourceMappingURL=out.js.map
|
|
60
|
+
//# sourceMappingURL=hmr.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/hmr.ts"],"names":[],"mappings":";;;;;AAAA,SAAgB,QAAe,iBAAiB;AAChD,SAAS,aAAgC;AACzC,SAAS,gBAAgB;AAiBlB,SAAS,MAAM,EAAE,UAAU,MAAM,SAAS,OAAO,GAAG,QAAQ,IAAgB,EAAE,SAAS,KAAK,GAAG;AAErG,MAAI,CAAC;AAAS;AAEd,MAAI,CAAC;AAAQ,cAAU,OAAO,KAAK,oDAAoD;AAEvF,aAAW,SAAS,UAAU,OAAO,OAAO,GAAG;AAC9C,UAAM,CAAC,GAAG,MAAM,KAAK,GAAG,OAAO,EAC7B,GAAG,UAAU,CAAC,SAAS,sBAAsB,OAAO,MAAM,MAAM,CAAC,EACjE,GAAG,UAAU,CAAC,SAAS,sBAAsB,OAAO,MAAM,MAAM,CAAC;AAAA,EACpE;AACD;AAXgB;AAahB,eAAe,sBAAsB,OAAqB,MAAc,QAAiB;AACxF,MAAI,CAAC,M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AG,IAAI,IAAI,sBAAsB,CAAC,EAAE,KAAK,IAAI,CAAC;AAAA,QACtH;AAAA,IACF;AAAA,EACD,CAAC;AAED,SAAO,WAAW,CAAC,UAAU,UAAU,OAAO,MAAM,4CAA4C,IAAI,KAAK,KAAK,CAAC;AAChH;AAxBe","sourcesContent":["import { Piece, Result, Store, container } from '@sapphire/framework';\nimport { watch, type WatchOptions } from 'chokidar';\nimport { relative } from 'node:path';\n\nexport interface HMROptions extends WatchOptions {\n\tenabled?: boolean;\n\tsilent?: boolean;\n}\n\n/**\n * Starts HMR for all registered {@link Store Stores} in {@link container.stores the main container}.\n *\n * @param __namedParameter The {@link HMROptions}.\n * This includes [all options from chokidar](https://github.com/paulmillr/chokidar#persistence),\n * as well as whether the HMR should be enabled.\n * The default options are `{ enabled: true }`,\n * and if not provided in the object then `enabled` is also set to true.\n *\n */\nexport function start({ enabled = true, silent = false, ...options }: HMROptions = { enabled: true }) {\n\t// Do not enable plugin when enabled is false\n\tif (!enabled) return;\n\n\tif (!silent) container.logger.info('[HMR-Plugin]: Enabled. Watching for piece changes.');\n\n\tfor (const store of container.stores.values()) {\n\t\twatch([...store.paths], options)\n\t\t\t.on('change', (path) => handlePiecePathUpdate(store, path, silent))\n\t\t\t.on('unlink', (path) => handlePiecePathDelete(store, path, silent));\n\t}\n}\n\nasync function handlePiecePathDelete(store: Store<Piece>, path: string, silent: boolean) {\n\tif (!store.strategy.filter(path)) return;\n\n\tconst pieceToDelete = store.find((piece) => piece.location.full === path);\n\tif (!pieceToDelete) return;\n\n\tconst result = await Result.fromAsync(async () => {\n\t\tawait pieceToDelete.unload();\n\t\tif (!silent) container.logger.info(`[HMR-Plugin]: Unloaded ${pieceToDelete.name} piece from ${pieceToDelete.store.name} store.`);\n\t});\n\n\tresult.inspectErr((error) =>\n\t\tcontainer.logger.error(`[HMR-Plugin]: Failed to unload ${pieceToDelete.name} piece from ${pieceToDelete.store.name} store.`, error)\n\t);\n}\n\nasync function handlePiecePathUpdate(store: Store<Piece>, path: string, silent: boolean) {\n\tif (!store.strategy.filter(path)) return;\n\n\tconst pieceToUpdate = store.find((piece) => piece.location.full === path);\n\n\tconst result = await Result.fromAsync(async () => {\n\t\tif (pieceToUpdate) {\n\t\t\tawait pieceToUpdate.reload();\n\t\t\tif (!silent) container.logger.info(`[HMR-Plugin]: reloaded ${pieceToUpdate.name} piece from ${pieceToUpdate.store.name} store.`);\n\t\t} else {\n\t\t\tconst rootPath = [...store.paths].find((storePath) => path.startsWith(storePath));\n\t\t\tif (!rootPath) throw new Error(`[HMR-Plugin]: Could not find root path for ${path}.`);\n\n\t\t\tconst piecesLoaded = await store.load(rootPath, relative(rootPath, path));\n\t\t\tconst piecesLoadedNames = piecesLoaded.map((piece) => piece.name);\n\t\t\tconst piecesLoadedStoreNames = piecesLoaded.map((piece) => piece.store.name);\n\t\t\tif (!silent)\n\t\t\t\tcontainer.logger.info(\n\t\t\t\t\t`[HMR-Plugin]: Loaded ${piecesLoadedNames.join(', ')} piece(s) from ${[...new Set(piecesLoadedStoreNames)].join(', ')} store(s).`\n\t\t\t\t);\n\t\t}\n\t});\n\n\tresult.inspectErr((error) => container.logger.error(`[HMR-Plugin]: Failed to load pieces from ${path}.`, error));\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Plugin, postLogin, SapphireClient } from '@sapphire/framework';
|
|
2
|
+
import './index.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @since 1.0.0
|
|
6
|
+
*/
|
|
7
|
+
declare class HmrPlugin extends Plugin {
|
|
8
|
+
/**
|
|
9
|
+
* @since 1.0.0
|
|
10
|
+
*/
|
|
11
|
+
static [postLogin](this: SapphireClient): void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { HmrPlugin };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { __name } from './chunk-G5GHKT7C.mjs';
|
|
2
|
+
import { SapphireClient, postLogin, Plugin } from '@sapphire/framework';
|
|
3
|
+
import './index.mjs';
|
|
4
|
+
import { start } from './lib/hmr.mjs';
|
|
5
|
+
|
|
6
|
+
var _HmrPlugin = class _HmrPlugin extends Plugin {
|
|
7
|
+
/**
|
|
8
|
+
* @since 1.0.0
|
|
9
|
+
*/
|
|
10
|
+
static [postLogin]() {
|
|
11
|
+
start(this.options.hmr);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
__name(_HmrPlugin, "HmrPlugin");
|
|
15
|
+
var HmrPlugin = _HmrPlugin;
|
|
16
|
+
SapphireClient.plugins.registerPostLoginHook(HmrPlugin[postLogin], "Hmr-PostLogin");
|
|
17
|
+
|
|
18
|
+
export { HmrPlugin };
|
|
19
|
+
//# sourceMappingURL=out.js.map
|
|
20
|
+
//# sourceMappingURL=register.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/register.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,QAAQ,WAAW,sBAAsB;AAClD,OAAO;AACP,SAAS,aAAa;AAKf,IAAM,aAAN,MAAM,mBAAkB,OAAO;AAAA;AAAA;AAAA;AAAA,EAIrC,QAAe,SAAS,IAA8B;AACrD,UAAM,KAAK,QAAQ,GAAG;AAAA,EACvB;AACD;AAPsC;AAA/B,IAAM,YAAN;AASP,eAAe,QAAQ,sBAAsB,UAAU,SAAS,GAAG,eAAe","sourcesContent":["import { Plugin, postLogin, SapphireClient } from '@sapphire/framework';\nimport './index';\nimport { start } from './lib/hmr';\n\n/**\n * @since 1.0.0\n */\nexport class HmrPlugin extends Plugin {\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic static [postLogin](this: SapphireClient): void {\n\t\tstart(this.options.hmr);\n\t}\n}\n\nSapphireClient.plugins.registerPostLoginHook(HmrPlugin[postLogin], 'Hmr-PostLogin');\n"]}
|
package/package.json
CHANGED
|
@@ -1,34 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sapphire/plugin-hmr",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-next.d9aa006.0",
|
|
4
4
|
"description": "Plugin for @sapphire/framework for hot module reloading for pieces",
|
|
5
5
|
"author": "@sapphire",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"main": "dist/index.
|
|
8
|
-
"module": "dist/index.mjs",
|
|
9
|
-
"types": "dist/index.d.ts",
|
|
7
|
+
"main": "dist/cjs/index.cjs",
|
|
8
|
+
"module": "dist/esm/index.mjs",
|
|
9
|
+
"types": "dist/cjs/index.d.ts",
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
"import": {
|
|
13
|
+
"types": "./dist/esm/index.d.mts",
|
|
14
|
+
"default": "./dist/esm/index.mjs"
|
|
15
|
+
},
|
|
16
|
+
"require": {
|
|
17
|
+
"types": "./dist/cjs/index.d.ts",
|
|
18
|
+
"default": "./dist/cjs/index.cjs"
|
|
19
|
+
}
|
|
15
20
|
},
|
|
16
21
|
"./register": {
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
"import": {
|
|
23
|
+
"types": "./dist/esm/register.d.mts",
|
|
24
|
+
"default": "./dist/esm/register.mjs"
|
|
25
|
+
},
|
|
26
|
+
"require": {
|
|
27
|
+
"types": "./dist/cjs/register.d.ts",
|
|
28
|
+
"default": "./dist/cjs/register.cjs"
|
|
29
|
+
}
|
|
20
30
|
}
|
|
21
31
|
},
|
|
22
32
|
"sideEffects": [
|
|
23
|
-
"./dist/register.
|
|
24
|
-
"./dist/register.mjs"
|
|
33
|
+
"./dist/cjs/register.cjs",
|
|
34
|
+
"./dist/esm/register.mjs"
|
|
25
35
|
],
|
|
26
36
|
"homepage": "https://sapphirejs.dev",
|
|
27
37
|
"scripts": {
|
|
28
38
|
"lint": "eslint src --ext ts --fix",
|
|
29
|
-
"build": "
|
|
30
|
-
"
|
|
31
|
-
"
|
|
39
|
+
"build": "tsup && yarn build:types",
|
|
40
|
+
"build:types": "concurrently \"yarn:build:types:*\"",
|
|
41
|
+
"build:types:cjs": "rollup-type-bundler -d dist/cjs",
|
|
42
|
+
"build:types:esm": "rollup-type-bundler -d dist/esm -t .mts",
|
|
43
|
+
"build:types:cleanup": "tsx ../../scripts/clean-register-imports.mts",
|
|
44
|
+
"typecheck": "tsc -b src",
|
|
32
45
|
"docs": "typedoc-json-parser",
|
|
33
46
|
"prepack": "yarn build",
|
|
34
47
|
"bump": "cliff-jumper",
|
|
@@ -68,9 +81,12 @@
|
|
|
68
81
|
},
|
|
69
82
|
"devDependencies": {
|
|
70
83
|
"@favware/cliff-jumper": "^2.2.3",
|
|
71
|
-
"
|
|
72
|
-
"
|
|
84
|
+
"@favware/rollup-type-bundler": "^3.2.0",
|
|
85
|
+
"concurrently": "^8.2.2",
|
|
86
|
+
"tsup": "^8.0.1",
|
|
87
|
+
"tsx": "^4.6.2",
|
|
88
|
+
"typedoc": "^0.25.4",
|
|
73
89
|
"typedoc-json-parser": "^9.0.1",
|
|
74
|
-
"typescript": "^5.
|
|
90
|
+
"typescript": "^5.3.2"
|
|
75
91
|
}
|
|
76
92
|
}
|
package/dist/index.d.ts
DELETED
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAE1B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE5C,OAAO,QAAQ,YAAY,CAAC;IAC3B,UAAiB,aAAa;QAC7B,GAAG,CAAC,EAAE,UAAU,CAAC;KACjB;CACD"}
|
package/dist/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./lib/hmr"), exports);
|
|
18
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B"}
|
package/dist/index.mjs
DELETED
package/dist/lib/hmr.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { type WatchOptions } from 'chokidar';
|
|
2
|
-
export interface HMROptions extends WatchOptions {
|
|
3
|
-
enabled?: boolean;
|
|
4
|
-
silent?: boolean;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Starts HMR for all registered {@link Store Stores} in {@link container.stores the main container}.
|
|
8
|
-
*
|
|
9
|
-
* @param __namedParameter The {@link HMROptions}.
|
|
10
|
-
* This includes [all options from chokidar](https://github.com/paulmillr/chokidar#persistence),
|
|
11
|
-
* as well as whether the HMR should be enabled.
|
|
12
|
-
* The default options are `{ enabled: true }`,
|
|
13
|
-
* and if not provided in the object then `enabled` is also set to true.
|
|
14
|
-
*
|
|
15
|
-
*/
|
|
16
|
-
export declare function start({ enabled, silent, ...options }?: HMROptions): void;
|
|
17
|
-
//# sourceMappingURL=hmr.d.ts.map
|
package/dist/lib/hmr.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hmr.d.ts","sourceRoot":"","sources":["../../src/lib/hmr.ts"],"names":[],"mappings":"AACA,OAAO,EAAS,KAAK,YAAY,EAAE,MAAM,UAAU,CAAC;AAGpD,MAAM,WAAW,UAAW,SAAQ,YAAY;IAC/C,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;;;;;;;GASG;AACH,wBAAgB,KAAK,CAAC,EAAE,OAAc,EAAE,MAAc,EAAE,GAAG,OAAO,EAAE,GAAE,UAA8B,QAWnG"}
|
package/dist/lib/hmr.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.start = void 0;
|
|
4
|
-
const framework_1 = require("@sapphire/framework");
|
|
5
|
-
const chokidar_1 = require("chokidar");
|
|
6
|
-
const node_path_1 = require("node:path");
|
|
7
|
-
/**
|
|
8
|
-
* Starts HMR for all registered {@link Store Stores} in {@link container.stores the main container}.
|
|
9
|
-
*
|
|
10
|
-
* @param __namedParameter The {@link HMROptions}.
|
|
11
|
-
* This includes [all options from chokidar](https://github.com/paulmillr/chokidar#persistence),
|
|
12
|
-
* as well as whether the HMR should be enabled.
|
|
13
|
-
* The default options are `{ enabled: true }`,
|
|
14
|
-
* and if not provided in the object then `enabled` is also set to true.
|
|
15
|
-
*
|
|
16
|
-
*/
|
|
17
|
-
function start({ enabled = true, silent = false, ...options } = { enabled: true }) {
|
|
18
|
-
// Do not enable plugin when enabled is false
|
|
19
|
-
if (!enabled)
|
|
20
|
-
return;
|
|
21
|
-
if (!silent)
|
|
22
|
-
framework_1.container.logger.info('[HMR-Plugin]: Enabled. Watching for piece changes.');
|
|
23
|
-
for (const store of framework_1.container.stores.values()) {
|
|
24
|
-
(0, chokidar_1.watch)([...store.paths], options)
|
|
25
|
-
.on('change', (path) => handlePiecePathUpdate(store, path, silent))
|
|
26
|
-
.on('unlink', (path) => handlePiecePathDelete(store, path, silent));
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
exports.start = start;
|
|
30
|
-
async function handlePiecePathDelete(store, path, silent) {
|
|
31
|
-
if (!store.strategy.filter(path))
|
|
32
|
-
return;
|
|
33
|
-
const pieceToDelete = store.find((piece) => piece.location.full === path);
|
|
34
|
-
if (!pieceToDelete)
|
|
35
|
-
return;
|
|
36
|
-
const result = await framework_1.Result.fromAsync(async () => {
|
|
37
|
-
await pieceToDelete.unload();
|
|
38
|
-
if (!silent)
|
|
39
|
-
framework_1.container.logger.info(`[HMR-Plugin]: Unloaded ${pieceToDelete.name} piece from ${pieceToDelete.store.name} store.`);
|
|
40
|
-
});
|
|
41
|
-
result.inspectErr((error) => framework_1.container.logger.error(`[HMR-Plugin]: Failed to unload ${pieceToDelete.name} piece from ${pieceToDelete.store.name} store.`, error));
|
|
42
|
-
}
|
|
43
|
-
async function handlePiecePathUpdate(store, path, silent) {
|
|
44
|
-
if (!store.strategy.filter(path))
|
|
45
|
-
return;
|
|
46
|
-
const pieceToUpdate = store.find((piece) => piece.location.full === path);
|
|
47
|
-
const result = await framework_1.Result.fromAsync(async () => {
|
|
48
|
-
if (pieceToUpdate) {
|
|
49
|
-
await pieceToUpdate.reload();
|
|
50
|
-
if (!silent)
|
|
51
|
-
framework_1.container.logger.info(`[HMR-Plugin]: reloaded ${pieceToUpdate.name} piece from ${pieceToUpdate.store.name} store.`);
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
const rootPath = [...store.paths].find((storePath) => path.startsWith(storePath));
|
|
55
|
-
if (!rootPath)
|
|
56
|
-
throw new Error(`[HMR-Plugin]: Could not find root path for ${path}.`);
|
|
57
|
-
const piecesLoaded = await store.load(rootPath, (0, node_path_1.relative)(rootPath, path));
|
|
58
|
-
const piecesLoadedNames = piecesLoaded.map((piece) => piece.name);
|
|
59
|
-
const piecesLoadedStoreNames = piecesLoaded.map((piece) => piece.store.name);
|
|
60
|
-
if (!silent)
|
|
61
|
-
framework_1.container.logger.info(`[HMR-Plugin]: Loaded ${piecesLoadedNames.join(', ')} piece(s) from ${[...new Set(piecesLoadedStoreNames)].join(', ')} store(s).`);
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
result.inspectErr((error) => framework_1.container.logger.error(`[HMR-Plugin]: Failed to load pieces from ${path}.`, error));
|
|
65
|
-
}
|
|
66
|
-
//# sourceMappingURL=hmr.js.map
|
package/dist/lib/hmr.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hmr.js","sourceRoot":"","sources":["../../src/lib/hmr.ts"],"names":[],"mappings":";;;AAAA,mDAAsE;AACtE,uCAAoD;AACpD,yCAAqC;AAOrC;;;;;;;;;GASG;AACH,SAAgB,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI,EAAE,MAAM,GAAG,KAAK,EAAE,GAAG,OAAO,KAAiB,EAAE,OAAO,EAAE,IAAI,EAAE;IACnG,6CAA6C;IAC7C,IAAI,CAAC,OAAO;QAAE,OAAO;IAErB,IAAI,CAAC,MAAM;QAAE,qBAAS,CAAC,MAAM,CAAC,IAAI,CAAC,oDAAoD,CAAC,CAAC;IAEzF,KAAK,MAAM,KAAK,IAAI,qBAAS,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE;QAC9C,IAAA,gBAAK,EAAC,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;aAC9B,EAAE,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,qBAAqB,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;aAClE,EAAE,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,qBAAqB,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;KACrE;AACF,CAAC;AAXD,sB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
|
1
|
-
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,SAAS,CAAC;AAGjB;;GAEG;AACH,qBAAa,SAAU,SAAQ,MAAM;IACpC;;OAEG;WACW,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI;CAGrD"}
|
package/dist/register.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HmrPlugin = void 0;
|
|
4
|
-
const framework_1 = require("@sapphire/framework");
|
|
5
|
-
require("./index");
|
|
6
|
-
const hmr_1 = require("./lib/hmr");
|
|
7
|
-
/**
|
|
8
|
-
* @since 1.0.0
|
|
9
|
-
*/
|
|
10
|
-
class HmrPlugin extends framework_1.Plugin {
|
|
11
|
-
/**
|
|
12
|
-
* @since 1.0.0
|
|
13
|
-
*/
|
|
14
|
-
static [framework_1.postLogin]() {
|
|
15
|
-
(0, hmr_1.start)(this.options.hmr);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.HmrPlugin = HmrPlugin;
|
|
19
|
-
framework_1.SapphireClient.plugins.registerPostLoginHook(HmrPlugin[framework_1.postLogin], 'Hmr-PostLogin');
|
|
20
|
-
//# sourceMappingURL=register.js.map
|
package/dist/register.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"register.js","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":";;;AAAA,mDAAwE;AACxE,mBAAiB;AACjB,mCAAkC;AAElC;;GAEG;AACH,MAAa,SAAU,SAAQ,kBAAM;IACpC;;OAEG;IACI,MAAM,CAAC,CAAC,qBAAS,CAAC;QACxB,IAAA,WAAK,EAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;CACD;AAPD,8BAOC;AAED,0BAAc,CAAC,OAAO,CAAC,qBAAqB,CAAC,SAAS,CAAC,qBAAS,CAAC,EAAE,eAAe,CAAC,CAAC"}
|
package/dist/register.mjs
DELETED