@mahameru/diatrema 0.0.4 → 0.0.6
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/{diatrema-Fd7aehcd.d.cts → diatrema-BNmte9Pf.d.cts} +7 -2
- package/{diatrema-DBO4yaCD.d.ts → diatrema-CO0FOwdp.d.ts} +7 -2
- package/diatrema.cjs +3 -0
- package/diatrema.cjs.map +1 -1
- package/diatrema.d.cts +2 -2
- package/diatrema.d.ts +1 -1
- package/diatrema.js +3 -0
- package/diatrema.js.map +1 -1
- package/index.d.cts +2 -2
- package/index.d.ts +2 -2
- package/mahameru-plugin.cjs +12 -4
- package/mahameru-plugin.cjs.map +1 -1
- package/mahameru-plugin.d.cts +1 -1
- package/mahameru-plugin.d.ts +1 -1
- package/mahameru-plugin.js +12 -4
- package/mahameru-plugin.js.map +1 -1
- package/package.json +1 -1
|
@@ -4,6 +4,7 @@ import { Logger } from './logger.cjs';
|
|
|
4
4
|
|
|
5
5
|
interface BasePluginOptions {
|
|
6
6
|
debug?: boolean;
|
|
7
|
+
dev?: boolean;
|
|
7
8
|
}
|
|
8
9
|
declare abstract class MahameruPlugin<O extends BasePluginOptions = BasePluginOptions> {
|
|
9
10
|
abstract readonly name: string;
|
|
@@ -18,15 +19,17 @@ declare abstract class MahameruPlugin<O extends BasePluginOptions = BasePluginOp
|
|
|
18
19
|
get initialized(): boolean;
|
|
19
20
|
get options(): O;
|
|
20
21
|
get generator(): Generator<BaseGeneratorOptions> | undefined;
|
|
21
|
-
set outputTypesDirPath(outputTypesDirPath: string);
|
|
22
22
|
setDiatrema(diatrema: Diatrema): void;
|
|
23
23
|
initialize(): Promise<void>;
|
|
24
24
|
destroy(): Promise<void>;
|
|
25
|
+
onDevHRM(changedFile: string): Promise<void | undefined>;
|
|
26
|
+
protected _onDevHRM?(filePath: string): Promise<void> | void;
|
|
25
27
|
protected abstract boot(options?: Partial<O>): Promise<void> | void;
|
|
26
28
|
protected abstract terminate(): Promise<void> | void;
|
|
27
29
|
}
|
|
28
30
|
interface BaseGeneratorOptions {
|
|
29
31
|
debug?: boolean;
|
|
32
|
+
dev?: boolean;
|
|
30
33
|
}
|
|
31
34
|
declare abstract class Generator<O extends BaseGeneratorOptions = BaseGeneratorOptions> {
|
|
32
35
|
protected logger: Logger;
|
|
@@ -39,7 +42,9 @@ declare abstract class Generator<O extends BaseGeneratorOptions = BaseGeneratorO
|
|
|
39
42
|
set sourceDirPath(sourceDirPath: string);
|
|
40
43
|
set outputTypesDirPath(outputTypesDirPath: string);
|
|
41
44
|
generate(): Promise<void>;
|
|
42
|
-
|
|
45
|
+
onDevHRM(changedFile: string): Promise<void>;
|
|
46
|
+
protected _onDevHRM?(filePath: string): Promise<boolean>;
|
|
47
|
+
protected abstract _generate?(): Promise<Record<string, any>>;
|
|
43
48
|
}
|
|
44
49
|
|
|
45
50
|
type DiatremaEvents = {
|
|
@@ -4,6 +4,7 @@ import { Logger } from './logger.js';
|
|
|
4
4
|
|
|
5
5
|
interface BasePluginOptions {
|
|
6
6
|
debug?: boolean;
|
|
7
|
+
dev?: boolean;
|
|
7
8
|
}
|
|
8
9
|
declare abstract class MahameruPlugin<O extends BasePluginOptions = BasePluginOptions> {
|
|
9
10
|
abstract readonly name: string;
|
|
@@ -18,15 +19,17 @@ declare abstract class MahameruPlugin<O extends BasePluginOptions = BasePluginOp
|
|
|
18
19
|
get initialized(): boolean;
|
|
19
20
|
get options(): O;
|
|
20
21
|
get generator(): Generator<BaseGeneratorOptions> | undefined;
|
|
21
|
-
set outputTypesDirPath(outputTypesDirPath: string);
|
|
22
22
|
setDiatrema(diatrema: Diatrema): void;
|
|
23
23
|
initialize(): Promise<void>;
|
|
24
24
|
destroy(): Promise<void>;
|
|
25
|
+
onDevHRM(changedFile: string): Promise<void | undefined>;
|
|
26
|
+
protected _onDevHRM?(filePath: string): Promise<void> | void;
|
|
25
27
|
protected abstract boot(options?: Partial<O>): Promise<void> | void;
|
|
26
28
|
protected abstract terminate(): Promise<void> | void;
|
|
27
29
|
}
|
|
28
30
|
interface BaseGeneratorOptions {
|
|
29
31
|
debug?: boolean;
|
|
32
|
+
dev?: boolean;
|
|
30
33
|
}
|
|
31
34
|
declare abstract class Generator<O extends BaseGeneratorOptions = BaseGeneratorOptions> {
|
|
32
35
|
protected logger: Logger;
|
|
@@ -39,7 +42,9 @@ declare abstract class Generator<O extends BaseGeneratorOptions = BaseGeneratorO
|
|
|
39
42
|
set sourceDirPath(sourceDirPath: string);
|
|
40
43
|
set outputTypesDirPath(outputTypesDirPath: string);
|
|
41
44
|
generate(): Promise<void>;
|
|
42
|
-
|
|
45
|
+
onDevHRM(changedFile: string): Promise<void>;
|
|
46
|
+
protected _onDevHRM?(filePath: string): Promise<boolean>;
|
|
47
|
+
protected abstract _generate?(): Promise<Record<string, any>>;
|
|
43
48
|
}
|
|
44
49
|
|
|
45
50
|
type DiatremaEvents = {
|
package/diatrema.cjs
CHANGED
|
@@ -96,6 +96,9 @@ class Diatrema extends import_event_emitter.EventEmitter {
|
|
|
96
96
|
if (!this._initialized)
|
|
97
97
|
return;
|
|
98
98
|
if (changedFile) {
|
|
99
|
+
for (const [_name, plugin] of this._plugins.entries()) {
|
|
100
|
+
await plugin.onDevHRM(changedFile);
|
|
101
|
+
}
|
|
99
102
|
}
|
|
100
103
|
}
|
|
101
104
|
async shutdown() {
|
package/diatrema.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/diatrema.ts"],"sourcesContent":["import { join } from 'node:path';\n\nimport { EventEmitter } from \"./event-emitter\";\nimport { existsSync } from 'node:fs';\nimport { pathToFileURL } from 'node:url';\nimport type { InitiatorHandler, Instances } from './types';\nimport type { MahameruPlugin } from './mahameru-plugin';\nimport { createLogger, type Logger } from './logger';\n\nexport type DiatremaEvents = {\n ready: [data: { mode: \"development\" | \"production\"; port?: number; host?: string; }];\n};\n\nexport type DiatremaOptions = {\n dev: boolean;\n debug: boolean;\n rootPath: string;\n appPath: string;\n productionDir: string;\n developmentDir: string;\n initiatorFilePath?: string;\n moduleType: \"commonjs\" | \"esm\";\n}\n\nexport const diatremaDefaultConfig: DiatremaOptions = {\n dev: false,\n debug: false,\n rootPath: process.cwd(),\n get appPath(): string {\n return join(this.rootPath, this.dev ? this.developmentDir : this.productionDir);\n },\n productionDir: '.mahameru',\n developmentDir: '.mahameru',\n moduleType: 'esm'\n}\n\n/**\n * Main Diatrema class that orchestrates the application lifecycle.\n */\nexport default class Diatrema extends EventEmitter<DiatremaEvents> {\n protected _initialized = false;\n protected _isShuttingDown = false;\n protected _plugins = new Map<string, MahameruPlugin<any>>();\n protected logger: Logger;\n public instances: Instances = {};\n public readonly options: DiatremaOptions;\n\n constructor(options?: Partial<DiatremaOptions>) {\n super();\n\n this.options = { ...diatremaDefaultConfig, ...options };\n this.logger = createLogger('Diatrema', this.options.debug);\n }\n\n /**\n * Indicates whether the Mahameru server has been initialized or not.\n * @returns {boolean}\n */\n get initialized() {\n return this._initialized;\n }\n\n /**\n * Indicates whether the Mahameru server is shutting down or not.\n * @returns {boolean}\n */\n get isShuttingDown() {\n return this._isShuttingDown;\n }\n\n get plugins(): Record<string, MahameruPlugin<any>> {\n return Object.fromEntries(this._plugins);\n }\n\n public async initialize(): Promise<void> {\n try {\n if (this._initialized)\n return;\n\n await this.loadInitiator();\n\n for (const plugin of this._plugins.values()) {\n plugin.setDiatrema(this);\n\n await plugin.initialize();\n }\n } catch (error) {\n throw error;\n }\n\n this._initialized = true;\n\n this.emit('ready', { mode: this.options.dev ? 'development' : 'production' });\n }\n\n public setPlugin<T extends MahameruPlugin<any>>(pluginName: string, plugin: T) {\n this._plugins.set(pluginName, plugin);\n }\n\n public getPlugin<T extends MahameruPlugin<any>>(pluginName: string): T | undefined {\n return this._plugins.get(pluginName) as T | undefined;\n }\n\n public async devHRM(changedFile?: string) {\n if (!this._initialized)\n return\n\n if (changedFile) {\n
|
|
1
|
+
{"version":3,"sources":["../src/diatrema.ts"],"sourcesContent":["import { join } from 'node:path';\n\nimport { EventEmitter } from \"./event-emitter\";\nimport { existsSync } from 'node:fs';\nimport { pathToFileURL } from 'node:url';\nimport type { InitiatorHandler, Instances } from './types';\nimport type { MahameruPlugin } from './mahameru-plugin';\nimport { createLogger, type Logger } from './logger';\n\nexport type DiatremaEvents = {\n ready: [data: { mode: \"development\" | \"production\"; port?: number; host?: string; }];\n};\n\nexport type DiatremaOptions = {\n dev: boolean;\n debug: boolean;\n rootPath: string;\n appPath: string;\n productionDir: string;\n developmentDir: string;\n initiatorFilePath?: string;\n moduleType: \"commonjs\" | \"esm\";\n}\n\nexport const diatremaDefaultConfig: DiatremaOptions = {\n dev: false,\n debug: false,\n rootPath: process.cwd(),\n get appPath(): string {\n return join(this.rootPath, this.dev ? this.developmentDir : this.productionDir);\n },\n productionDir: '.mahameru',\n developmentDir: '.mahameru',\n moduleType: 'esm'\n}\n\n/**\n * Main Diatrema class that orchestrates the application lifecycle.\n */\nexport default class Diatrema extends EventEmitter<DiatremaEvents> {\n protected _initialized = false;\n protected _isShuttingDown = false;\n protected _plugins = new Map<string, MahameruPlugin<any>>();\n protected logger: Logger;\n public instances: Instances = {};\n public readonly options: DiatremaOptions;\n\n constructor(options?: Partial<DiatremaOptions>) {\n super();\n\n this.options = { ...diatremaDefaultConfig, ...options };\n this.logger = createLogger('Diatrema', this.options.debug);\n }\n\n /**\n * Indicates whether the Mahameru server has been initialized or not.\n * @returns {boolean}\n */\n get initialized() {\n return this._initialized;\n }\n\n /**\n * Indicates whether the Mahameru server is shutting down or not.\n * @returns {boolean}\n */\n get isShuttingDown() {\n return this._isShuttingDown;\n }\n\n get plugins(): Record<string, MahameruPlugin<any>> {\n return Object.fromEntries(this._plugins);\n }\n\n public async initialize(): Promise<void> {\n try {\n if (this._initialized)\n return;\n\n await this.loadInitiator();\n\n for (const plugin of this._plugins.values()) {\n plugin.setDiatrema(this);\n\n await plugin.initialize();\n }\n } catch (error) {\n throw error;\n }\n\n this._initialized = true;\n\n this.emit('ready', { mode: this.options.dev ? 'development' : 'production' });\n }\n\n public setPlugin<T extends MahameruPlugin<any>>(pluginName: string, plugin: T) {\n this._plugins.set(pluginName, plugin);\n }\n\n public getPlugin<T extends MahameruPlugin<any>>(pluginName: string): T | undefined {\n return this._plugins.get(pluginName) as T | undefined;\n }\n\n public async devHRM(changedFile?: string) {\n if (!this._initialized)\n return\n\n if (changedFile) {\n for (const [_name, plugin] of this._plugins.entries()) {\n await plugin.onDevHRM(changedFile);\n }\n }\n }\n\n public async shutdown(): Promise<void> {\n if (this._isShuttingDown)\n return\n\n this._isShuttingDown = true;\n\n this.logger.debug('Shutting down...');\n\n for (const plugin of this._plugins.values()) {\n await plugin.destroy();\n }\n\n this._initialized = false;\n this.logger.debug('Shutting down... Done');\n }\n\n protected async loadInitiator() {\n if (!this.options.initiatorFilePath)\n return;\n\n const result = await this.require<Record<'default', InitiatorHandler>>(this.options.moduleType, this.options.initiatorFilePath);\n\n if (result) {\n const handler = this.getDefaultExport<InitiatorHandler>(result, this.options.initiatorFilePath);\n\n this.instances = await handler();\n this.logger.debug(`Initiator loaded successfully. Found ${Object.keys(this.instances).length} instances.`);\n }\n }\n\n protected async require<T extends Record<string, unknown> = Record<string, unknown>>(type: \"commonjs\" | \"esm\", resolvedFilePath: string): Promise<T | undefined> {\n const noCache = this.options.dev;\n\n if (!existsSync(resolvedFilePath))\n return;\n\n if (type === \"commonjs\") {\n if (noCache) {\n delete require.cache[resolvedFilePath];\n }\n\n return require(resolvedFilePath) as T;\n }\n\n let fileUrl = pathToFileURL(resolvedFilePath).href;\n\n if (noCache)\n fileUrl += `?update=${Date.now()}`;\n\n return (await import(fileUrl)) as T;\n }\n\n protected getDefaultExport<T>(module: Record<string, T>, filePath: string) {\n const defaultExportName = Object.keys(module).find((key) => key === 'default');\n\n if (!defaultExportName)\n throw new Error(`Module in file '${filePath}' does not have a default export.`);\n\n return module[defaultExportName];\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA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AO,QAAQ,gBAAgB;AAAA,IACnC;AAEA,QAAI,cAAU,+BAAc,gBAAgB,EAAE;AAE9C,QAAI;AACA,iBAAW,WAAW,KAAK,IAAI,CAAC;AAEpC,WAAQ,MAAM,OAAO;AAAA,EACzB;AAAA,EAEU,iBAAoBA,SAA2B,UAAkB;AACvE,UAAM,oBAAoB,OAAO,KAAKA,OAAM,EAAE,KAAK,CAAC,QAAQ,QAAQ,SAAS;AAE7E,QAAI,CAAC;AACD,YAAM,IAAI,MAAM,mBAAmB,QAAQ,mCAAmC;AAElF,WAAOA,QAAO,iBAAiB;AAAA,EACnC;AACJ;","names":["module"]}
|
package/diatrema.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import _default from './diatrema-
|
|
1
|
+
import _default from './diatrema-BNmte9Pf.cjs';
|
|
2
2
|
import './event-emitter.cjs';
|
|
3
3
|
import './types.cjs';
|
|
4
4
|
// @ts-ignore
|
|
5
5
|
export = _default;
|
|
6
|
-
export { b as DiatremaEvents, c as DiatremaOptions, d as diatremaDefaultConfig } from './diatrema-
|
|
6
|
+
export { b as DiatremaEvents, c as DiatremaOptions, d as diatremaDefaultConfig } from './diatrema-BNmte9Pf.cjs';
|
|
7
7
|
import './logger.cjs';
|
package/diatrema.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import './event-emitter.js';
|
|
2
2
|
import './types.js';
|
|
3
|
-
export { b as DiatremaEvents, c as DiatremaOptions, D as default, d as diatremaDefaultConfig } from './diatrema-
|
|
3
|
+
export { b as DiatremaEvents, c as DiatremaOptions, D as default, d as diatremaDefaultConfig } from './diatrema-CO0FOwdp.js';
|
|
4
4
|
import './logger.js';
|
package/diatrema.js
CHANGED
package/diatrema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/diatrema.ts"],"sourcesContent":["import { join } from 'node:path';\n\nimport { EventEmitter } from \"./event-emitter\";\nimport { existsSync } from 'node:fs';\nimport { pathToFileURL } from 'node:url';\nimport type { InitiatorHandler, Instances } from './types';\nimport type { MahameruPlugin } from './mahameru-plugin';\nimport { createLogger, type Logger } from './logger';\n\nexport type DiatremaEvents = {\n ready: [data: { mode: \"development\" | \"production\"; port?: number; host?: string; }];\n};\n\nexport type DiatremaOptions = {\n dev: boolean;\n debug: boolean;\n rootPath: string;\n appPath: string;\n productionDir: string;\n developmentDir: string;\n initiatorFilePath?: string;\n moduleType: \"commonjs\" | \"esm\";\n}\n\nexport const diatremaDefaultConfig: DiatremaOptions = {\n dev: false,\n debug: false,\n rootPath: process.cwd(),\n get appPath(): string {\n return join(this.rootPath, this.dev ? this.developmentDir : this.productionDir);\n },\n productionDir: '.mahameru',\n developmentDir: '.mahameru',\n moduleType: 'esm'\n}\n\n/**\n * Main Diatrema class that orchestrates the application lifecycle.\n */\nexport default class Diatrema extends EventEmitter<DiatremaEvents> {\n protected _initialized = false;\n protected _isShuttingDown = false;\n protected _plugins = new Map<string, MahameruPlugin<any>>();\n protected logger: Logger;\n public instances: Instances = {};\n public readonly options: DiatremaOptions;\n\n constructor(options?: Partial<DiatremaOptions>) {\n super();\n\n this.options = { ...diatremaDefaultConfig, ...options };\n this.logger = createLogger('Diatrema', this.options.debug);\n }\n\n /**\n * Indicates whether the Mahameru server has been initialized or not.\n * @returns {boolean}\n */\n get initialized() {\n return this._initialized;\n }\n\n /**\n * Indicates whether the Mahameru server is shutting down or not.\n * @returns {boolean}\n */\n get isShuttingDown() {\n return this._isShuttingDown;\n }\n\n get plugins(): Record<string, MahameruPlugin<any>> {\n return Object.fromEntries(this._plugins);\n }\n\n public async initialize(): Promise<void> {\n try {\n if (this._initialized)\n return;\n\n await this.loadInitiator();\n\n for (const plugin of this._plugins.values()) {\n plugin.setDiatrema(this);\n\n await plugin.initialize();\n }\n } catch (error) {\n throw error;\n }\n\n this._initialized = true;\n\n this.emit('ready', { mode: this.options.dev ? 'development' : 'production' });\n }\n\n public setPlugin<T extends MahameruPlugin<any>>(pluginName: string, plugin: T) {\n this._plugins.set(pluginName, plugin);\n }\n\n public getPlugin<T extends MahameruPlugin<any>>(pluginName: string): T | undefined {\n return this._plugins.get(pluginName) as T | undefined;\n }\n\n public async devHRM(changedFile?: string) {\n if (!this._initialized)\n return\n\n if (changedFile) {\n
|
|
1
|
+
{"version":3,"sources":["../src/diatrema.ts"],"sourcesContent":["import { join } from 'node:path';\n\nimport { EventEmitter } from \"./event-emitter\";\nimport { existsSync } from 'node:fs';\nimport { pathToFileURL } from 'node:url';\nimport type { InitiatorHandler, Instances } from './types';\nimport type { MahameruPlugin } from './mahameru-plugin';\nimport { createLogger, type Logger } from './logger';\n\nexport type DiatremaEvents = {\n ready: [data: { mode: \"development\" | \"production\"; port?: number; host?: string; }];\n};\n\nexport type DiatremaOptions = {\n dev: boolean;\n debug: boolean;\n rootPath: string;\n appPath: string;\n productionDir: string;\n developmentDir: string;\n initiatorFilePath?: string;\n moduleType: \"commonjs\" | \"esm\";\n}\n\nexport const diatremaDefaultConfig: DiatremaOptions = {\n dev: false,\n debug: false,\n rootPath: process.cwd(),\n get appPath(): string {\n return join(this.rootPath, this.dev ? this.developmentDir : this.productionDir);\n },\n productionDir: '.mahameru',\n developmentDir: '.mahameru',\n moduleType: 'esm'\n}\n\n/**\n * Main Diatrema class that orchestrates the application lifecycle.\n */\nexport default class Diatrema extends EventEmitter<DiatremaEvents> {\n protected _initialized = false;\n protected _isShuttingDown = false;\n protected _plugins = new Map<string, MahameruPlugin<any>>();\n protected logger: Logger;\n public instances: Instances = {};\n public readonly options: DiatremaOptions;\n\n constructor(options?: Partial<DiatremaOptions>) {\n super();\n\n this.options = { ...diatremaDefaultConfig, ...options };\n this.logger = createLogger('Diatrema', this.options.debug);\n }\n\n /**\n * Indicates whether the Mahameru server has been initialized or not.\n * @returns {boolean}\n */\n get initialized() {\n return this._initialized;\n }\n\n /**\n * Indicates whether the Mahameru server is shutting down or not.\n * @returns {boolean}\n */\n get isShuttingDown() {\n return this._isShuttingDown;\n }\n\n get plugins(): Record<string, MahameruPlugin<any>> {\n return Object.fromEntries(this._plugins);\n }\n\n public async initialize(): Promise<void> {\n try {\n if (this._initialized)\n return;\n\n await this.loadInitiator();\n\n for (const plugin of this._plugins.values()) {\n plugin.setDiatrema(this);\n\n await plugin.initialize();\n }\n } catch (error) {\n throw error;\n }\n\n this._initialized = true;\n\n this.emit('ready', { mode: this.options.dev ? 'development' : 'production' });\n }\n\n public setPlugin<T extends MahameruPlugin<any>>(pluginName: string, plugin: T) {\n this._plugins.set(pluginName, plugin);\n }\n\n public getPlugin<T extends MahameruPlugin<any>>(pluginName: string): T | undefined {\n return this._plugins.get(pluginName) as T | undefined;\n }\n\n public async devHRM(changedFile?: string) {\n if (!this._initialized)\n return\n\n if (changedFile) {\n for (const [_name, plugin] of this._plugins.entries()) {\n await plugin.onDevHRM(changedFile);\n }\n }\n }\n\n public async shutdown(): Promise<void> {\n if (this._isShuttingDown)\n return\n\n this._isShuttingDown = true;\n\n this.logger.debug('Shutting down...');\n\n for (const plugin of this._plugins.values()) {\n await plugin.destroy();\n }\n\n this._initialized = false;\n this.logger.debug('Shutting down... Done');\n }\n\n protected async loadInitiator() {\n if (!this.options.initiatorFilePath)\n return;\n\n const result = await this.require<Record<'default', InitiatorHandler>>(this.options.moduleType, this.options.initiatorFilePath);\n\n if (result) {\n const handler = this.getDefaultExport<InitiatorHandler>(result, this.options.initiatorFilePath);\n\n this.instances = await handler();\n this.logger.debug(`Initiator loaded successfully. Found ${Object.keys(this.instances).length} instances.`);\n }\n }\n\n protected async require<T extends Record<string, unknown> = Record<string, unknown>>(type: \"commonjs\" | \"esm\", resolvedFilePath: string): Promise<T | undefined> {\n const noCache = this.options.dev;\n\n if (!existsSync(resolvedFilePath))\n return;\n\n if (type === \"commonjs\") {\n if (noCache) {\n delete require.cache[resolvedFilePath];\n }\n\n return require(resolvedFilePath) as T;\n }\n\n let fileUrl = pathToFileURL(resolvedFilePath).href;\n\n if (noCache)\n fileUrl += `?update=${Date.now()}`;\n\n return (await import(fileUrl)) as T;\n }\n\n protected getDefaultExport<T>(module: Record<string, T>, filePath: string) {\n const defaultExportName = Object.keys(module).find((key) => key === 'default');\n\n if (!defaultExportName)\n throw new Error(`Module in file '${filePath}' does not have a default export.`);\n\n return module[defaultExportName];\n }\n}\n"],"mappings":";;AAAA,SAAS,YAAY;AAErB,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB;AAC3B,SAAS,qBAAqB;AAG9B,SAAS,oBAAiC;AAiBnC,MAAM,wBAAyC;AAAA,EAClD,KAAK;AAAA,EACL,OAAO;AAAA,EACP,UAAU,QAAQ,IAAI;AAAA,EACtB,IAAI,UAAkB;AAClB,WAAO,KAAK,KAAK,UAAU,KAAK,MAAM,KAAK,iBAAiB,KAAK,aAAa;AAAA,EAClF;AAAA,EACA,eAAe;AAAA,EACf,gBAAgB;AAAA,EAChB,YAAY;AAChB;AAKA,MAAO,iBAA+B,aAA6B;AAAA,EAvCnE,OAuCmE;AAAA;AAAA;AAAA,EACrD,eAAe;AAAA,EACf,kBAAkB;AAAA,EAClB,WAAW,oBAAI,IAAiC;AAAA,EAChD;AAAA,EACH,YAAuB,CAAC;AAAA,EACf;AAAA,EAEhB,YAAY,SAAoC;AAC5C,UAAM;AAEN,SAAK,UAAU,EAAE,GAAG,uBAAuB,GAAG,QAAQ;AACtD,SAAK,SAAS,aAAa,YAAY,KAAK,QAAQ,KAAK;AAAA,EAC7D;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,cAAc;AACd,WAAO,KAAK;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,iBAAiB;AACjB,WAAO,KAAK;AAAA,EAChB;AAAA,EAEA,IAAI,UAA+C;AAC/C,WAAO,OAAO,YAAY,KAAK,QAAQ;AAAA,EAC3C;AAAA,EAEA,MAAa,aAA4B;AACrC,QAAI;AACA,UAAI,KAAK;AACL;AAEJ,YAAM,KAAK,cAAc;AAEzB,iBAAW,UAAU,KAAK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,MAA0B,kBAAkD;AAC7J,UAAM,UAAU,KAAK,QAAQ;AAE7B,QAAI,CAAC,WAAW,gBAAgB;AAC5B;AAEJ,QAAI,SAAS,YAAY;AACrB,UAAI,SAAS;AACT,eAAO,QAAQ,MAAM,gBAAgB;AAAA,MACzC;AAEA,aAAO,QAAQ,gBAAgB;AAAA,IACnC;AAEA,QAAI,UAAU,cAAc,gBAAgB,EAAE;AAE9C,QAAI;AACA,iBAAW,WAAW,KAAK,IAAI,CAAC;AAEpC,WAAQ,MAAM,OAAO;AAAA,EACzB;AAAA,EAEU,iBAAoB,QAA2B,UAAkB;AACvE,UAAM,oBAAoB,OAAO,KAAK,MAAM,EAAE,KAAK,CAAC,QAAQ,QAAQ,SAAS;AAE7E,QAAI,CAAC;AACD,YAAM,IAAI,MAAM,mBAAmB,QAAQ,mCAAmC;AAElF,WAAO,OAAO,iBAAiB;AAAA,EACnC;AACJ;","names":[]}
|
package/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { D as Diatrema } from './diatrema-
|
|
2
|
-
export { B as BaseGeneratorOptions, a as BasePluginOptions, b as DiatremaEvents, c as DiatremaOptions, G as Generator, M as MahameruPlugin, d as diatremaDefaultConfig } from './diatrema-
|
|
1
|
+
import { D as Diatrema } from './diatrema-BNmte9Pf.cjs';
|
|
2
|
+
export { B as BaseGeneratorOptions, a as BasePluginOptions, b as DiatremaEvents, c as DiatremaOptions, G as Generator, M as MahameruPlugin, d as diatremaDefaultConfig } from './diatrema-BNmte9Pf.cjs';
|
|
3
3
|
export { EventEmitter } from './event-emitter.cjs';
|
|
4
4
|
export { Logger, createLogger } from './logger.cjs';
|
|
5
5
|
export { MahameruError } from './mahameru-error.cjs';
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { D as Diatrema } from './diatrema-
|
|
2
|
-
export { B as BaseGeneratorOptions, a as BasePluginOptions, b as DiatremaEvents, c as DiatremaOptions, G as Generator, M as MahameruPlugin, d as diatremaDefaultConfig } from './diatrema-
|
|
1
|
+
import { D as Diatrema } from './diatrema-CO0FOwdp.js';
|
|
2
|
+
export { B as BaseGeneratorOptions, a as BasePluginOptions, b as DiatremaEvents, c as DiatremaOptions, G as Generator, M as MahameruPlugin, d as diatremaDefaultConfig } from './diatrema-CO0FOwdp.js';
|
|
3
3
|
export { EventEmitter } from './event-emitter.js';
|
|
4
4
|
export { Logger, createLogger } from './logger.js';
|
|
5
5
|
export { MahameruError } from './mahameru-error.js';
|
package/mahameru-plugin.cjs
CHANGED
|
@@ -46,10 +46,6 @@ class MahameruPlugin {
|
|
|
46
46
|
get generator() {
|
|
47
47
|
return this._generator;
|
|
48
48
|
}
|
|
49
|
-
set outputTypesDirPath(outputTypesDirPath) {
|
|
50
|
-
if (this._generator)
|
|
51
|
-
this._generator.outputTypesDirPath = outputTypesDirPath;
|
|
52
|
-
}
|
|
53
49
|
setDiatrema(diatrema) {
|
|
54
50
|
this.diatrema = diatrema;
|
|
55
51
|
}
|
|
@@ -77,6 +73,11 @@ class MahameruPlugin {
|
|
|
77
73
|
this._isShuttingDown = false;
|
|
78
74
|
this.logger.debug("Destroying... Done");
|
|
79
75
|
}
|
|
76
|
+
async onDevHRM(changedFile) {
|
|
77
|
+
if (!this._onDevHRM)
|
|
78
|
+
return void 0;
|
|
79
|
+
return await this._onDevHRM(changedFile);
|
|
80
|
+
}
|
|
80
81
|
}
|
|
81
82
|
class Generator {
|
|
82
83
|
static {
|
|
@@ -100,10 +101,17 @@ class Generator {
|
|
|
100
101
|
this._outputTypesDirPath = outputTypesDirPath;
|
|
101
102
|
}
|
|
102
103
|
async generate() {
|
|
104
|
+
if (!this._generate)
|
|
105
|
+
return;
|
|
103
106
|
this.logger.debug("Generating types...");
|
|
104
107
|
const types = await this._generate();
|
|
105
108
|
this.logger.debug("Types generated", types);
|
|
106
109
|
}
|
|
110
|
+
async onDevHRM(changedFile) {
|
|
111
|
+
if (!this._onDevHRM)
|
|
112
|
+
return;
|
|
113
|
+
await this._onDevHRM(changedFile);
|
|
114
|
+
}
|
|
107
115
|
}
|
|
108
116
|
// Annotate the CommonJS export names for ESM import in node:
|
|
109
117
|
0 && (module.exports = {
|
package/mahameru-plugin.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/mahameru-plugin.ts"],"sourcesContent":["import type Diatrema from \"./diatrema\";\r\nimport { type Logger } from \"./logger\";\r\n\r\nexport interface BasePluginOptions {\r\n debug?: boolean;\r\n}\r\n\r\nexport abstract class MahameruPlugin<O extends BasePluginOptions = BasePluginOptions> {\r\n public abstract readonly name: string;\r\n public abstract readonly slugName: string;\r\n protected logger!: Logger;\r\n protected diatrema!: Diatrema;\r\n protected _options: O;\r\n protected _initialized = false;\r\n protected _isShuttingDown = false;\r\n protected _generator?: Generator;\r\n\r\n constructor(options: Partial<O>) {\r\n this._options = options as O;\r\n }\r\n\r\n get initialized() {\r\n return this._initialized;\r\n }\r\n\r\n get options(): O {\r\n return this._options;\r\n }\r\n\r\n get generator() {\r\n return this._generator;\r\n }\r\n\r\n
|
|
1
|
+
{"version":3,"sources":["../src/mahameru-plugin.ts"],"sourcesContent":["import type Diatrema from \"./diatrema\";\r\nimport { type Logger } from \"./logger\";\r\n\r\nexport interface BasePluginOptions {\r\n debug?: boolean;\r\n dev?: boolean;\r\n}\r\n\r\nexport abstract class MahameruPlugin<O extends BasePluginOptions = BasePluginOptions> {\r\n public abstract readonly name: string;\r\n public abstract readonly slugName: string;\r\n protected logger!: Logger;\r\n protected diatrema!: Diatrema;\r\n protected _options: O;\r\n protected _initialized = false;\r\n protected _isShuttingDown = false;\r\n protected _generator?: Generator;\r\n\r\n constructor(options: Partial<O>) {\r\n this._options = options as O;\r\n }\r\n\r\n get initialized() {\r\n return this._initialized;\r\n }\r\n\r\n get options(): O {\r\n return this._options;\r\n }\r\n\r\n get generator() {\r\n return this._generator;\r\n }\r\n\r\n public setDiatrema(diatrema: Diatrema) {\r\n this.diatrema = diatrema;\r\n }\r\n\r\n public async initialize(): Promise<void> {\r\n if (!this.diatrema) {\r\n this.logger.debug('Failed to initialize. No Diatrema instance found');\r\n\r\n return;\r\n }\r\n\r\n this.logger.debug('Initializing...');\r\n\r\n if (this._initialized) {\r\n this.logger.debug('Already initialized');\r\n\r\n return;\r\n }\r\n\r\n await this.boot();\r\n\r\n this.logger.debug('Initializing... Done');\r\n\r\n this._initialized = true;\r\n }\r\n\r\n public async destroy(): Promise<void> {\r\n if (!this._initialized || this._isShuttingDown)\r\n return;\r\n\r\n this.logger.debug('Destroying...');\r\n\r\n this._isShuttingDown = true;\r\n\r\n await this.terminate();\r\n\r\n this._initialized = false;\r\n this._isShuttingDown = false;\r\n\r\n this.logger.debug('Destroying... Done');\r\n }\r\n\r\n public async onDevHRM(changedFile: string): Promise<void | undefined> {\r\n if (!this._onDevHRM)\r\n return undefined;\r\n\r\n return await this._onDevHRM(changedFile);\r\n }\r\n\r\n protected _onDevHRM?(filePath: string): Promise<void> | void;\r\n protected abstract boot(options?: Partial<O>): Promise<void> | void;\r\n protected abstract terminate(): Promise<void> | void;\r\n}\r\n\r\nexport interface BaseGeneratorOptions {\r\n debug?: boolean;\r\n dev?: boolean;\r\n}\r\n\r\nexport abstract class Generator<O extends BaseGeneratorOptions = BaseGeneratorOptions> {\r\n protected logger!: Logger;\r\n protected _diatrema!: Diatrema;\r\n protected _options: O;\r\n protected _sourceDirPath!: string;\r\n protected _outputTypesDirPath!: string;\r\n\r\n constructor(options: Partial<O>) {\r\n this._options = options as O;\r\n }\r\n\r\n set diatrema(diatrema: Diatrema) {\r\n this._diatrema = diatrema;\r\n }\r\n\r\n set sourceDirPath(sourceDirPath: string) {\r\n this._sourceDirPath = sourceDirPath;\r\n }\r\n\r\n set outputTypesDirPath(outputTypesDirPath: string) {\r\n this._outputTypesDirPath = outputTypesDirPath;\r\n }\r\n\r\n public async generate() {\r\n if (!this._generate)\r\n return;\r\n\r\n this.logger.debug('Generating types...');\r\n const types = await this._generate();\r\n this.logger.debug('Types generated', types);\r\n }\r\n\r\n public async onDevHRM(changedFile: string) {\r\n if (!this._onDevHRM)\r\n return;\r\n\r\n await this._onDevHRM(changedFile);\r\n }\r\n\r\n protected _onDevHRM?(filePath: string): Promise<boolean>;\r\n protected abstract _generate?(): Promise<Record<string, any>>;\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAA4B;AAOrB,MAAe,eAAgE;AAAA,EARtF,OAQsF;AAAA;AAAA;AAAA,EAGxE;AAAA,EACA;AAAA,EACA;AAAA,EACA,eAAe;AAAA,EACf,kBAAkB;AAAA,EAClB;AAAA,EAEV,YAAY,SAAqB;AAC7B,SAAK,WAAW;AAAA,EACpB;AAAA,EAEA,IAAI,cAAc;AACd,WAAO,KAAK;AAAA,EAChB;AAAA,EAEA,IAAI,UAAa;AACb,WAAO,KAAK;AAAA,EAChB;AAAA,EAEA,IAAI,YAAY;AACZ,WAAO,KAAK;AAAA,EAChB;AAAA,EAEO,YAAY,UAAoB;AACnC,SAAK,WAAW;AAAA,EACpB;AAAA,EAEA,MAAa,aAA4B;AACrC,QAAI,CAAC,KAAK,UAAU;AAChB,WAAK,OAAO,MAAM,kDAAkD;AAEpE;AAAA,IACJ;AAEA,SAAK,OAAO,MAAM,iBAAiB;AAEnC,QAAI,KAAK,cAAc;AACnB,WAAK,OAAO,MAAM,qBAAqB;AAEvC;AAAA,IACJ;AAEA,UAAM,KAAK,KAAK;AAEhB,SAAK,OAAO,MAAM,sBAAsB;AAExC,SAAK,eAAe;AAAA,EACxB;AAAA,EAEA,MAAa,UAAyB;AAClC,QAAI,CAAC,KAAK,gBAAgB,KAAK;AAC3B;AAEJ,SAAK,OAAO,MAAM,eAAe;AAEjC,SAAK,kBAAkB;AAEvB,UAAM,KAAK,UAAU;AAErB,SAAK,eAAe;AACpB,SAAK,kBAAkB;AAEvB,SAAK,OAAO,MAAM,oBAAoB;AAAA,EAC1C;AAAA,EAEA,MAAa,SAAS,aAAgD;AAClE,QAAI,CAAC,KAAK;AACN,aAAO;AAEX,WAAO,MAAM,KAAK,UAAU,WAAW;AAAA,EAC3C;AAKJ;AAOO,MAAe,UAAiE;AAAA,EA7FvF,OA6FuF;AAAA;AAAA;AAAA,EACzE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEV,YAAY,SAAqB;AAC7B,SAAK,WAAW;AAAA,EACpB;AAAA,EAEA,IAAI,SAAS,UAAoB;AAC7B,SAAK,YAAY;AAAA,EACrB;AAAA,EAEA,IAAI,cAAc,eAAuB;AACrC,SAAK,iBAAiB;AAAA,EAC1B;AAAA,EAEA,IAAI,mBAAmB,oBAA4B;AAC/C,SAAK,sBAAsB;AAAA,EAC/B;AAAA,EAEA,MAAa,WAAW;AACpB,QAAI,CAAC,KAAK;AACN;AAEJ,SAAK,OAAO,MAAM,qBAAqB;AACvC,UAAM,QAAQ,MAAM,KAAK,UAAU;AACnC,SAAK,OAAO,MAAM,mBAAmB,KAAK;AAAA,EAC9C;AAAA,EAEA,MAAa,SAAS,aAAqB;AACvC,QAAI,CAAC,KAAK;AACN;AAEJ,UAAM,KAAK,UAAU,WAAW;AAAA,EACpC;AAIJ;","names":[]}
|
package/mahameru-plugin.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { B as BaseGeneratorOptions, a as BasePluginOptions, G as Generator, M as MahameruPlugin } from './diatrema-
|
|
1
|
+
export { B as BaseGeneratorOptions, a as BasePluginOptions, G as Generator, M as MahameruPlugin } from './diatrema-BNmte9Pf.cjs';
|
|
2
2
|
import './logger.cjs';
|
|
3
3
|
import './event-emitter.cjs';
|
|
4
4
|
import './types.cjs';
|
package/mahameru-plugin.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { B as BaseGeneratorOptions, a as BasePluginOptions, G as Generator, M as MahameruPlugin } from './diatrema-
|
|
1
|
+
export { B as BaseGeneratorOptions, a as BasePluginOptions, G as Generator, M as MahameruPlugin } from './diatrema-CO0FOwdp.js';
|
|
2
2
|
import './logger.js';
|
|
3
3
|
import './event-emitter.js';
|
|
4
4
|
import './types.js';
|
package/mahameru-plugin.js
CHANGED
|
@@ -23,10 +23,6 @@ class MahameruPlugin {
|
|
|
23
23
|
get generator() {
|
|
24
24
|
return this._generator;
|
|
25
25
|
}
|
|
26
|
-
set outputTypesDirPath(outputTypesDirPath) {
|
|
27
|
-
if (this._generator)
|
|
28
|
-
this._generator.outputTypesDirPath = outputTypesDirPath;
|
|
29
|
-
}
|
|
30
26
|
setDiatrema(diatrema) {
|
|
31
27
|
this.diatrema = diatrema;
|
|
32
28
|
}
|
|
@@ -54,6 +50,11 @@ class MahameruPlugin {
|
|
|
54
50
|
this._isShuttingDown = false;
|
|
55
51
|
this.logger.debug("Destroying... Done");
|
|
56
52
|
}
|
|
53
|
+
async onDevHRM(changedFile) {
|
|
54
|
+
if (!this._onDevHRM)
|
|
55
|
+
return void 0;
|
|
56
|
+
return await this._onDevHRM(changedFile);
|
|
57
|
+
}
|
|
57
58
|
}
|
|
58
59
|
class Generator {
|
|
59
60
|
static {
|
|
@@ -77,10 +78,17 @@ class Generator {
|
|
|
77
78
|
this._outputTypesDirPath = outputTypesDirPath;
|
|
78
79
|
}
|
|
79
80
|
async generate() {
|
|
81
|
+
if (!this._generate)
|
|
82
|
+
return;
|
|
80
83
|
this.logger.debug("Generating types...");
|
|
81
84
|
const types = await this._generate();
|
|
82
85
|
this.logger.debug("Types generated", types);
|
|
83
86
|
}
|
|
87
|
+
async onDevHRM(changedFile) {
|
|
88
|
+
if (!this._onDevHRM)
|
|
89
|
+
return;
|
|
90
|
+
await this._onDevHRM(changedFile);
|
|
91
|
+
}
|
|
84
92
|
}
|
|
85
93
|
export {
|
|
86
94
|
Generator,
|
package/mahameru-plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/mahameru-plugin.ts"],"sourcesContent":["import type Diatrema from \"./diatrema\";\r\nimport { type Logger } from \"./logger\";\r\n\r\nexport interface BasePluginOptions {\r\n debug?: boolean;\r\n}\r\n\r\nexport abstract class MahameruPlugin<O extends BasePluginOptions = BasePluginOptions> {\r\n public abstract readonly name: string;\r\n public abstract readonly slugName: string;\r\n protected logger!: Logger;\r\n protected diatrema!: Diatrema;\r\n protected _options: O;\r\n protected _initialized = false;\r\n protected _isShuttingDown = false;\r\n protected _generator?: Generator;\r\n\r\n constructor(options: Partial<O>) {\r\n this._options = options as O;\r\n }\r\n\r\n get initialized() {\r\n return this._initialized;\r\n }\r\n\r\n get options(): O {\r\n return this._options;\r\n }\r\n\r\n get generator() {\r\n return this._generator;\r\n }\r\n\r\n
|
|
1
|
+
{"version":3,"sources":["../src/mahameru-plugin.ts"],"sourcesContent":["import type Diatrema from \"./diatrema\";\r\nimport { type Logger } from \"./logger\";\r\n\r\nexport interface BasePluginOptions {\r\n debug?: boolean;\r\n dev?: boolean;\r\n}\r\n\r\nexport abstract class MahameruPlugin<O extends BasePluginOptions = BasePluginOptions> {\r\n public abstract readonly name: string;\r\n public abstract readonly slugName: string;\r\n protected logger!: Logger;\r\n protected diatrema!: Diatrema;\r\n protected _options: O;\r\n protected _initialized = false;\r\n protected _isShuttingDown = false;\r\n protected _generator?: Generator;\r\n\r\n constructor(options: Partial<O>) {\r\n this._options = options as O;\r\n }\r\n\r\n get initialized() {\r\n return this._initialized;\r\n }\r\n\r\n get options(): O {\r\n return this._options;\r\n }\r\n\r\n get generator() {\r\n return this._generator;\r\n }\r\n\r\n public setDiatrema(diatrema: Diatrema) {\r\n this.diatrema = diatrema;\r\n }\r\n\r\n public async initialize(): Promise<void> {\r\n if (!this.diatrema) {\r\n this.logger.debug('Failed to initialize. No Diatrema instance found');\r\n\r\n return;\r\n }\r\n\r\n this.logger.debug('Initializing...');\r\n\r\n if (this._initialized) {\r\n this.logger.debug('Already initialized');\r\n\r\n return;\r\n }\r\n\r\n await this.boot();\r\n\r\n this.logger.debug('Initializing... Done');\r\n\r\n this._initialized = true;\r\n }\r\n\r\n public async destroy(): Promise<void> {\r\n if (!this._initialized || this._isShuttingDown)\r\n return;\r\n\r\n this.logger.debug('Destroying...');\r\n\r\n this._isShuttingDown = true;\r\n\r\n await this.terminate();\r\n\r\n this._initialized = false;\r\n this._isShuttingDown = false;\r\n\r\n this.logger.debug('Destroying... Done');\r\n }\r\n\r\n public async onDevHRM(changedFile: string): Promise<void | undefined> {\r\n if (!this._onDevHRM)\r\n return undefined;\r\n\r\n return await this._onDevHRM(changedFile);\r\n }\r\n\r\n protected _onDevHRM?(filePath: string): Promise<void> | void;\r\n protected abstract boot(options?: Partial<O>): Promise<void> | void;\r\n protected abstract terminate(): Promise<void> | void;\r\n}\r\n\r\nexport interface BaseGeneratorOptions {\r\n debug?: boolean;\r\n dev?: boolean;\r\n}\r\n\r\nexport abstract class Generator<O extends BaseGeneratorOptions = BaseGeneratorOptions> {\r\n protected logger!: Logger;\r\n protected _diatrema!: Diatrema;\r\n protected _options: O;\r\n protected _sourceDirPath!: string;\r\n protected _outputTypesDirPath!: string;\r\n\r\n constructor(options: Partial<O>) {\r\n this._options = options as O;\r\n }\r\n\r\n set diatrema(diatrema: Diatrema) {\r\n this._diatrema = diatrema;\r\n }\r\n\r\n set sourceDirPath(sourceDirPath: string) {\r\n this._sourceDirPath = sourceDirPath;\r\n }\r\n\r\n set outputTypesDirPath(outputTypesDirPath: string) {\r\n this._outputTypesDirPath = outputTypesDirPath;\r\n }\r\n\r\n public async generate() {\r\n if (!this._generate)\r\n return;\r\n\r\n this.logger.debug('Generating types...');\r\n const types = await this._generate();\r\n this.logger.debug('Types generated', types);\r\n }\r\n\r\n public async onDevHRM(changedFile: string) {\r\n if (!this._onDevHRM)\r\n return;\r\n\r\n await this._onDevHRM(changedFile);\r\n }\r\n\r\n protected _onDevHRM?(filePath: string): Promise<boolean>;\r\n protected abstract _generate?(): Promise<Record<string, any>>;\r\n}\r\n"],"mappings":";;AAC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AAAA,EACpB;AAAA,EAEA,IAAI,SAAS,UAAoB;AAC7B,SAAK,YAAY;AAAA,EACrB;AAAA,EAEA,IAAI,cAAc,eAAuB;AACrC,SAAK,iBAAiB;AAAA,EAC1B;AAAA,EAEA,IAAI,mBAAmB,oBAA4B;AAC/C,SAAK,sBAAsB;AAAA,EAC/B;AAAA,EAEA,MAAa,WAAW;AACpB,QAAI,CAAC,KAAK;AACN;AAEJ,SAAK,OAAO,MAAM,qBAAqB;AACvC,UAAM,QAAQ,MAAM,KAAK,UAAU;AACnC,SAAK,OAAO,MAAM,mBAAmB,KAAK;AAAA,EAC9C;AAAA,EAEA,MAAa,SAAS,aAAqB;AACvC,QAAI,CAAC,KAAK;AACN;AAEJ,UAAM,KAAK,UAAU,WAAW;AAAA,EACpC;AAIJ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mahameru/diatrema",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "The core engine of MahameruJS. Just like a volcanic diatreme, it serves as the essential conduit that powers and drives the entire framework ecosystem.",
|
|
5
5
|
"main": "./index.cjs",
|
|
6
6
|
"module": "./index.js",
|