@mahameru/diatrema 0.0.7 → 0.0.8

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.
Files changed (73) hide show
  1. package/.tsbuildinfo +1 -0
  2. package/README.md +1 -1
  3. package/diatrema.d.ts +51 -4
  4. package/diatrema.d.ts.map +1 -0
  5. package/diatrema.js +53 -50
  6. package/diatrema.js.map +1 -1
  7. package/diatrema.mjs +104 -0
  8. package/diatrema.mjs.map +1 -0
  9. package/event-emitter.d.ts +4 -4
  10. package/event-emitter.d.ts.map +1 -0
  11. package/event-emitter.js +34 -10
  12. package/event-emitter.js.map +1 -1
  13. package/event-emitter.mjs +45 -0
  14. package/event-emitter.mjs.map +1 -0
  15. package/index.d.ts +7 -10
  16. package/index.d.ts.map +1 -0
  17. package/index.js +36 -10
  18. package/index.js.map +1 -1
  19. package/index.mjs +10 -0
  20. package/index.mjs.map +1 -0
  21. package/logger.d.ts +6 -7
  22. package/logger.d.ts.map +1 -0
  23. package/logger.js +36 -15
  24. package/logger.js.map +1 -1
  25. package/logger.mjs +25 -0
  26. package/logger.mjs.map +1 -0
  27. package/mahameru-plugin.d.ts +47 -4
  28. package/mahameru-plugin.d.ts.map +1 -0
  29. package/mahameru-plugin.js +32 -18
  30. package/mahameru-plugin.js.map +1 -1
  31. package/{mahameru-plugin.cjs → mahameru-plugin.mjs} +9 -44
  32. package/mahameru-plugin.mjs.map +1 -0
  33. package/package.json +5 -13
  34. package/diatrema-BNmte9Pf.d.cts +0 -100
  35. package/diatrema-CO0FOwdp.d.ts +0 -100
  36. package/diatrema.cjs +0 -151
  37. package/diatrema.cjs.map +0 -1
  38. package/diatrema.d.cts +0 -7
  39. package/event-emitter.cjs +0 -68
  40. package/event-emitter.cjs.map +0 -1
  41. package/event-emitter.d.cts +0 -11
  42. package/helpers.cjs +0 -77
  43. package/helpers.cjs.map +0 -1
  44. package/helpers.d.cts +0 -17
  45. package/helpers.d.ts +0 -17
  46. package/helpers.js +0 -52
  47. package/helpers.js.map +0 -1
  48. package/index.cjs +0 -52
  49. package/index.cjs.map +0 -1
  50. package/index.d.cts +0 -10
  51. package/logger.cjs +0 -51
  52. package/logger.cjs.map +0 -1
  53. package/logger.d.cts +0 -9
  54. package/mahameru-error.cjs +0 -42
  55. package/mahameru-error.cjs.map +0 -1
  56. package/mahameru-error.d.cts +0 -5
  57. package/mahameru-error.d.ts +0 -5
  58. package/mahameru-error.js +0 -19
  59. package/mahameru-error.js.map +0 -1
  60. package/mahameru-plugin.cjs.map +0 -1
  61. package/mahameru-plugin.d.cts +0 -4
  62. package/scripts/preinstall.cjs +0 -10
  63. package/scripts/preinstall.cjs.map +0 -1
  64. package/scripts/preinstall.d.cts +0 -2
  65. package/scripts/preinstall.d.ts +0 -2
  66. package/scripts/preinstall.js +0 -9
  67. package/scripts/preinstall.js.map +0 -1
  68. package/types.cjs +0 -17
  69. package/types.cjs.map +0 -1
  70. package/types.d.cts +0 -5
  71. package/types.d.ts +0 -5
  72. package/types.js +0 -1
  73. package/types.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/mahameru-plugin.ts"],"sourcesContent":["import { type Diatrema } from './diatrema';\nimport { type Logger } from './logger';\n\nexport interface BasePluginOptions {\n debug?: boolean;\n dev?: boolean;\n}\n\nexport abstract class MahameruPlugin<O extends BasePluginOptions = BasePluginOptions> {\n public abstract readonly name: string;\n public abstract readonly slugName: string;\n protected logger!: Logger;\n protected diatrema!: Diatrema;\n protected _options: O;\n protected _initialized = false;\n protected _isShuttingDown = false;\n protected _generator?: Generator;\n\n constructor(options: Partial<O>) {\n this._options = options as O;\n }\n\n get initialized() {\n return this._initialized;\n }\n\n get options(): O {\n return this._options;\n }\n\n get generator() {\n return this._generator;\n }\n\n public setDiatrema(diatrema: Diatrema) {\n this.diatrema = diatrema;\n }\n\n public async initialize(): Promise<void> {\n if (!this.diatrema) {\n this.logger.debug('Failed to initialize. No Diatrema instance found');\n\n return;\n }\n\n this.logger.debug('Initializing...');\n\n if (this._initialized) {\n this.logger.debug('Already initialized');\n\n return;\n }\n\n await this.boot();\n\n this.logger.debug('Initializing... Done');\n\n this._initialized = true;\n }\n\n public async destroy(): Promise<void> {\n if (!this._initialized || this._isShuttingDown) return;\n\n this.logger.debug('Destroying...');\n\n this._isShuttingDown = true;\n\n await this.terminate();\n\n this._initialized = false;\n this._isShuttingDown = false;\n\n this.logger.debug('Destroying... Done');\n }\n\n public async onDevHRM(changedFile: string): Promise<void | undefined> {\n if (!this._onDevHRM) return undefined;\n\n return await this._onDevHRM(changedFile);\n }\n\n protected _onDevHRM?(filePath: string): Promise<void> | void;\n protected abstract boot(options?: Partial<O>): Promise<void> | void;\n protected abstract terminate(): Promise<void> | void;\n}\n\nexport interface BaseGeneratorOptions {\n debug?: boolean;\n dev?: boolean;\n}\n\nexport abstract class Generator<O extends BaseGeneratorOptions = BaseGeneratorOptions> {\n protected logger!: Logger;\n protected _diatrema!: Diatrema;\n protected _options: O;\n protected _sourceDirPath!: string;\n protected _outputTypesDirPath!: string;\n\n constructor(options: Partial<O>) {\n this._options = options as O;\n }\n\n set diatrema(diatrema: Diatrema) {\n this._diatrema = diatrema;\n }\n\n set sourceDirPath(sourceDirPath: string) {\n this._sourceDirPath = sourceDirPath;\n }\n\n set outputTypesDirPath(outputTypesDirPath: string) {\n this._outputTypesDirPath = outputTypesDirPath;\n }\n\n public async generate() {\n if (!this._generate) return;\n\n this.logger.debug('Generating types...');\n const types = await this._generate();\n this.logger.debug('Types generated', types);\n }\n\n public async onDevHRM(changedFile: string) {\n if (!this._onDevHRM) return;\n\n await this._onDevHRM(changedFile);\n }\n\n protected _onDevHRM?(filePath: string): Promise<boolean>;\n protected abstract _generate?(): Promise<Record<string, unknown>>;\n}\n"],"mappings":"AAAA,eAA8B;AAC9B,eAA4B;AAOrB,MAAe,eAAgE;AAAA,EAG1E;AAAA,EACA;AAAA,EACA;AAAA,EACA,eAAe;AAAA,EACf,kBAAkB;AAAA,EAClB;AAAA,EAEV,YAAY,SAAqB;AAC/B,SAAK,WAAW;AAAA,EAClB;AAAA,EAEA,IAAI,cAAc;AAChB,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,UAAa;AACf,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,YAAY;AACd,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,YAAY,UAAoB;AACrC,SAAK,WAAW;AAAA,EAClB;AAAA,EAEA,MAAa,aAA4B;AACvC,QAAI,CAAC,KAAK,UAAU;AAClB,WAAK,OAAO,MAAM,kDAAkD;AAEpE;AAAA,IACF;AAEA,SAAK,OAAO,MAAM,iBAAiB;AAEnC,QAAI,KAAK,cAAc;AACrB,WAAK,OAAO,MAAM,qBAAqB;AAEvC;AAAA,IACF;AAEA,UAAM,KAAK,KAAK;AAEhB,SAAK,OAAO,MAAM,sBAAsB;AAExC,SAAK,eAAe;AAAA,EACtB;AAAA,EAEA,MAAa,UAAyB;AACpC,QAAI,CAAC,KAAK,gBAAgB,KAAK,gBAAiB;AAEhD,SAAK,OAAO,MAAM,eAAe;AAEjC,SAAK,kBAAkB;AAEvB,UAAM,KAAK,UAAU;AAErB,SAAK,eAAe;AACpB,SAAK,kBAAkB;AAEvB,SAAK,OAAO,MAAM,oBAAoB;AAAA,EACxC;AAAA,EAEA,MAAa,SAAS,aAAgD;AACpE,QAAI,CAAC,KAAK,UAAW,QAAO;AAE5B,WAAO,MAAM,KAAK,UAAU,WAAW;AAAA,EACzC;AAKF;AAOO,MAAe,UAAiE;AAAA,EAC3E;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEV,YAAY,SAAqB;AAC/B,SAAK,WAAW;AAAA,EAClB;AAAA,EAEA,IAAI,SAAS,UAAoB;AAC/B,SAAK,YAAY;AAAA,EACnB;AAAA,EAEA,IAAI,cAAc,eAAuB;AACvC,SAAK,iBAAiB;AAAA,EACxB;AAAA,EAEA,IAAI,mBAAmB,oBAA4B;AACjD,SAAK,sBAAsB;AAAA,EAC7B;AAAA,EAEA,MAAa,WAAW;AACtB,QAAI,CAAC,KAAK,UAAW;AAErB,SAAK,OAAO,MAAM,qBAAqB;AACvC,UAAM,QAAQ,MAAM,KAAK,UAAU;AACnC,SAAK,OAAO,MAAM,mBAAmB,KAAK;AAAA,EAC5C;AAAA,EAEA,MAAa,SAAS,aAAqB;AACzC,QAAI,CAAC,KAAK,UAAW;AAErB,UAAM,KAAK,UAAU,WAAW;AAAA,EAClC;AAIF;","names":[]}
package/package.json CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "@mahameru/diatrema",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
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",
7
7
  "types": "./index.d.ts",
8
- "type": "module",
9
8
  "exports": {
10
9
  ".": {
11
10
  "types": "./index.d.ts",
@@ -13,12 +12,6 @@
13
12
  "require": "./index.cjs"
14
13
  }
15
14
  },
16
- "scripts": {
17
- "typecheck": "tsc --noEmit --project tsconfig.json",
18
- "build": "tsup --config tsup.config.ts && node ./scripts/postbuild.js",
19
- "dev": "cross-env NODE_ENV=development tsup --config tsup.config.ts && node ./scripts/postbuild.js",
20
- "preinstall": "node ./scripts/preinstall.js"
21
- },
22
15
  "keywords": [
23
16
  "node",
24
17
  "framework",
@@ -30,12 +23,11 @@
30
23
  ],
31
24
  "author": "Bintan <hello@bintvn.co>",
32
25
  "license": "ISC",
26
+ "engines": {
27
+ "node": ">=20.6.0"
28
+ },
33
29
  "devDependencies": {
34
30
  "@types/node": "^26.1.0",
35
- "cross-env": "^10.1.0",
36
- "esbuild-fix-imports-plugin": "^1.0.23",
37
- "tsup": "^8.5.1",
38
- "type-fest": "^5.8.0",
39
- "typescript": "^6.0.3"
31
+ "type-fest": "^5.8.0"
40
32
  }
41
33
  }
@@ -1,100 +0,0 @@
1
- import { EventEmitter } from './event-emitter.cjs';
2
- import { Instances } from './types.cjs';
3
- import { Logger } from './logger.cjs';
4
-
5
- interface BasePluginOptions {
6
- debug?: boolean;
7
- dev?: boolean;
8
- }
9
- declare abstract class MahameruPlugin<O extends BasePluginOptions = BasePluginOptions> {
10
- abstract readonly name: string;
11
- abstract readonly slugName: string;
12
- protected logger: Logger;
13
- protected diatrema: Diatrema;
14
- protected _options: O;
15
- protected _initialized: boolean;
16
- protected _isShuttingDown: boolean;
17
- protected _generator?: Generator;
18
- constructor(options: Partial<O>);
19
- get initialized(): boolean;
20
- get options(): O;
21
- get generator(): Generator<BaseGeneratorOptions> | undefined;
22
- setDiatrema(diatrema: Diatrema): void;
23
- initialize(): Promise<void>;
24
- destroy(): Promise<void>;
25
- onDevHRM(changedFile: string): Promise<void | undefined>;
26
- protected _onDevHRM?(filePath: string): Promise<void> | void;
27
- protected abstract boot(options?: Partial<O>): Promise<void> | void;
28
- protected abstract terminate(): Promise<void> | void;
29
- }
30
- interface BaseGeneratorOptions {
31
- debug?: boolean;
32
- dev?: boolean;
33
- }
34
- declare abstract class Generator<O extends BaseGeneratorOptions = BaseGeneratorOptions> {
35
- protected logger: Logger;
36
- protected _diatrema: Diatrema;
37
- protected _options: O;
38
- protected _sourceDirPath: string;
39
- protected _outputTypesDirPath: string;
40
- constructor(options: Partial<O>);
41
- set diatrema(diatrema: Diatrema);
42
- set sourceDirPath(sourceDirPath: string);
43
- set outputTypesDirPath(outputTypesDirPath: string);
44
- generate(): Promise<void>;
45
- onDevHRM(changedFile: string): Promise<void>;
46
- protected _onDevHRM?(filePath: string): Promise<boolean>;
47
- protected abstract _generate?(): Promise<Record<string, any>>;
48
- }
49
-
50
- type DiatremaEvents = {
51
- ready: [data: {
52
- mode: "development" | "production";
53
- port?: number;
54
- host?: string;
55
- }];
56
- };
57
- type DiatremaOptions = {
58
- dev: boolean;
59
- debug: boolean;
60
- rootPath: string;
61
- appPath: string;
62
- productionDir: string;
63
- developmentDir: string;
64
- initiatorFilePath?: string;
65
- moduleType: "commonjs" | "esm";
66
- };
67
- declare const diatremaDefaultConfig: DiatremaOptions;
68
- /**
69
- * Main Diatrema class that orchestrates the application lifecycle.
70
- */
71
- declare class Diatrema extends EventEmitter<DiatremaEvents> {
72
- protected _initialized: boolean;
73
- protected _isShuttingDown: boolean;
74
- protected _plugins: Map<string, MahameruPlugin<any>>;
75
- protected logger: Logger;
76
- instances: Instances;
77
- readonly options: DiatremaOptions;
78
- constructor(options?: Partial<DiatremaOptions>);
79
- /**
80
- * Indicates whether the Mahameru server has been initialized or not.
81
- * @returns {boolean}
82
- */
83
- get initialized(): boolean;
84
- /**
85
- * Indicates whether the Mahameru server is shutting down or not.
86
- * @returns {boolean}
87
- */
88
- get isShuttingDown(): boolean;
89
- get plugins(): Record<string, MahameruPlugin<any>>;
90
- initialize(): Promise<void>;
91
- setPlugin<T extends MahameruPlugin<any>>(pluginName: string, plugin: T): void;
92
- getPlugin<T extends MahameruPlugin<any>>(pluginName: string): T | undefined;
93
- devHRM(changedFile?: string): Promise<void>;
94
- shutdown(): Promise<void>;
95
- protected loadInitiator(): Promise<void>;
96
- protected require<T extends Record<string, unknown> = Record<string, unknown>>(type: "commonjs" | "esm", resolvedFilePath: string): Promise<T | undefined>;
97
- protected getDefaultExport<T>(module: Record<string, T>, filePath: string): T;
98
- }
99
-
100
- export { type BaseGeneratorOptions as B, Diatrema as D, Generator as G, MahameruPlugin as M, type BasePluginOptions as a, type DiatremaEvents as b, type DiatremaOptions as c, diatremaDefaultConfig as d };
@@ -1,100 +0,0 @@
1
- import { EventEmitter } from './event-emitter.js';
2
- import { Instances } from './types.js';
3
- import { Logger } from './logger.js';
4
-
5
- interface BasePluginOptions {
6
- debug?: boolean;
7
- dev?: boolean;
8
- }
9
- declare abstract class MahameruPlugin<O extends BasePluginOptions = BasePluginOptions> {
10
- abstract readonly name: string;
11
- abstract readonly slugName: string;
12
- protected logger: Logger;
13
- protected diatrema: Diatrema;
14
- protected _options: O;
15
- protected _initialized: boolean;
16
- protected _isShuttingDown: boolean;
17
- protected _generator?: Generator;
18
- constructor(options: Partial<O>);
19
- get initialized(): boolean;
20
- get options(): O;
21
- get generator(): Generator<BaseGeneratorOptions> | undefined;
22
- setDiatrema(diatrema: Diatrema): void;
23
- initialize(): Promise<void>;
24
- destroy(): Promise<void>;
25
- onDevHRM(changedFile: string): Promise<void | undefined>;
26
- protected _onDevHRM?(filePath: string): Promise<void> | void;
27
- protected abstract boot(options?: Partial<O>): Promise<void> | void;
28
- protected abstract terminate(): Promise<void> | void;
29
- }
30
- interface BaseGeneratorOptions {
31
- debug?: boolean;
32
- dev?: boolean;
33
- }
34
- declare abstract class Generator<O extends BaseGeneratorOptions = BaseGeneratorOptions> {
35
- protected logger: Logger;
36
- protected _diatrema: Diatrema;
37
- protected _options: O;
38
- protected _sourceDirPath: string;
39
- protected _outputTypesDirPath: string;
40
- constructor(options: Partial<O>);
41
- set diatrema(diatrema: Diatrema);
42
- set sourceDirPath(sourceDirPath: string);
43
- set outputTypesDirPath(outputTypesDirPath: string);
44
- generate(): Promise<void>;
45
- onDevHRM(changedFile: string): Promise<void>;
46
- protected _onDevHRM?(filePath: string): Promise<boolean>;
47
- protected abstract _generate?(): Promise<Record<string, any>>;
48
- }
49
-
50
- type DiatremaEvents = {
51
- ready: [data: {
52
- mode: "development" | "production";
53
- port?: number;
54
- host?: string;
55
- }];
56
- };
57
- type DiatremaOptions = {
58
- dev: boolean;
59
- debug: boolean;
60
- rootPath: string;
61
- appPath: string;
62
- productionDir: string;
63
- developmentDir: string;
64
- initiatorFilePath?: string;
65
- moduleType: "commonjs" | "esm";
66
- };
67
- declare const diatremaDefaultConfig: DiatremaOptions;
68
- /**
69
- * Main Diatrema class that orchestrates the application lifecycle.
70
- */
71
- declare class Diatrema extends EventEmitter<DiatremaEvents> {
72
- protected _initialized: boolean;
73
- protected _isShuttingDown: boolean;
74
- protected _plugins: Map<string, MahameruPlugin<any>>;
75
- protected logger: Logger;
76
- instances: Instances;
77
- readonly options: DiatremaOptions;
78
- constructor(options?: Partial<DiatremaOptions>);
79
- /**
80
- * Indicates whether the Mahameru server has been initialized or not.
81
- * @returns {boolean}
82
- */
83
- get initialized(): boolean;
84
- /**
85
- * Indicates whether the Mahameru server is shutting down or not.
86
- * @returns {boolean}
87
- */
88
- get isShuttingDown(): boolean;
89
- get plugins(): Record<string, MahameruPlugin<any>>;
90
- initialize(): Promise<void>;
91
- setPlugin<T extends MahameruPlugin<any>>(pluginName: string, plugin: T): void;
92
- getPlugin<T extends MahameruPlugin<any>>(pluginName: string): T | undefined;
93
- devHRM(changedFile?: string): Promise<void>;
94
- shutdown(): Promise<void>;
95
- protected loadInitiator(): Promise<void>;
96
- protected require<T extends Record<string, unknown> = Record<string, unknown>>(type: "commonjs" | "esm", resolvedFilePath: string): Promise<T | undefined>;
97
- protected getDefaultExport<T>(module: Record<string, T>, filePath: string): T;
98
- }
99
-
100
- export { type BaseGeneratorOptions as B, Diatrema as D, Generator as G, MahameruPlugin as M, type BasePluginOptions as a, type DiatremaEvents as b, type DiatremaOptions as c, diatremaDefaultConfig as d };
package/diatrema.cjs DELETED
@@ -1,151 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
- var diatrema_exports = {};
21
- __export(diatrema_exports, {
22
- default: () => Diatrema,
23
- diatremaDefaultConfig: () => diatremaDefaultConfig
24
- });
25
- module.exports = __toCommonJS(diatrema_exports);
26
- var import_node_path = require("node:path");
27
- var import_event_emitter = require('./event-emitter.cjs');
28
- var import_node_fs = require("node:fs");
29
- var import_node_url = require("node:url");
30
- var import_logger = require('./logger.cjs');
31
- const diatremaDefaultConfig = {
32
- dev: false,
33
- debug: false,
34
- rootPath: process.cwd(),
35
- get appPath() {
36
- return (0, import_node_path.join)(this.rootPath, this.dev ? this.developmentDir : this.productionDir);
37
- },
38
- productionDir: ".mahameru",
39
- developmentDir: ".mahameru",
40
- moduleType: "esm"
41
- };
42
- class Diatrema extends import_event_emitter.EventEmitter {
43
- static {
44
- __name(this, "Diatrema");
45
- }
46
- _initialized = false;
47
- _isShuttingDown = false;
48
- _plugins = /* @__PURE__ */ new Map();
49
- logger;
50
- instances = {};
51
- options;
52
- constructor(options) {
53
- super();
54
- this.options = { ...diatremaDefaultConfig, ...options };
55
- this.logger = (0, import_logger.createLogger)("Diatrema", this.options.debug);
56
- }
57
- /**
58
- * Indicates whether the Mahameru server has been initialized or not.
59
- * @returns {boolean}
60
- */
61
- get initialized() {
62
- return this._initialized;
63
- }
64
- /**
65
- * Indicates whether the Mahameru server is shutting down or not.
66
- * @returns {boolean}
67
- */
68
- get isShuttingDown() {
69
- return this._isShuttingDown;
70
- }
71
- get plugins() {
72
- return Object.fromEntries(this._plugins);
73
- }
74
- async initialize() {
75
- try {
76
- if (this._initialized)
77
- return;
78
- await this.loadInitiator();
79
- for (const plugin of this._plugins.values()) {
80
- plugin.setDiatrema(this);
81
- await plugin.initialize();
82
- }
83
- } catch (error) {
84
- throw error;
85
- }
86
- this._initialized = true;
87
- this.emit("ready", { mode: this.options.dev ? "development" : "production" });
88
- }
89
- setPlugin(pluginName, plugin) {
90
- this._plugins.set(pluginName, plugin);
91
- }
92
- getPlugin(pluginName) {
93
- return this._plugins.get(pluginName);
94
- }
95
- async devHRM(changedFile) {
96
- if (!this._initialized)
97
- return;
98
- if (changedFile) {
99
- for (const [_name, plugin] of this._plugins.entries()) {
100
- await plugin.onDevHRM(changedFile);
101
- }
102
- }
103
- }
104
- async shutdown() {
105
- if (this._isShuttingDown)
106
- return;
107
- this._isShuttingDown = true;
108
- this.logger.debug("Shutting down...");
109
- for (const plugin of this._plugins.values()) {
110
- await plugin.destroy();
111
- }
112
- this._initialized = false;
113
- this.logger.debug("Shutting down... Done");
114
- }
115
- async loadInitiator() {
116
- if (!this.options.initiatorFilePath)
117
- return;
118
- const result = await this.require(this.options.moduleType, this.options.initiatorFilePath);
119
- if (result) {
120
- const handler = this.getDefaultExport(result, this.options.initiatorFilePath);
121
- this.instances = await handler();
122
- this.logger.debug(`Initiator loaded successfully. Found ${Object.keys(this.instances).length} instances.`);
123
- }
124
- }
125
- async require(type, resolvedFilePath) {
126
- const noCache = this.options.dev;
127
- if (!(0, import_node_fs.existsSync)(resolvedFilePath))
128
- return;
129
- if (type === "commonjs") {
130
- if (noCache) {
131
- delete require.cache[resolvedFilePath];
132
- }
133
- return require(resolvedFilePath);
134
- }
135
- let fileUrl = (0, import_node_url.pathToFileURL)(resolvedFilePath).href;
136
- if (noCache)
137
- fileUrl += `?update=${Date.now()}`;
138
- return await import(fileUrl);
139
- }
140
- getDefaultExport(module2, filePath) {
141
- const defaultExportName = Object.keys(module2).find((key) => key === "default");
142
- if (!defaultExportName)
143
- throw new Error(`Module in file '${filePath}' does not have a default export.`);
144
- return module2[defaultExportName];
145
- }
146
- }
147
- // Annotate the CommonJS export names for ESM import in node:
148
- 0 && (module.exports = {
149
- diatremaDefaultConfig
150
- });
151
- //# sourceMappingURL=diatrema.cjs.map
package/diatrema.cjs.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/diatrema.ts"],"sourcesContent":["import { join } from 'node:path';\r\n\r\nimport { EventEmitter } from \"./event-emitter\";\r\nimport { existsSync } from 'node:fs';\r\nimport { pathToFileURL } from 'node:url';\r\nimport type { InitiatorHandler, Instances } from './types';\r\nimport type { MahameruPlugin } from './mahameru-plugin';\r\nimport { createLogger, type Logger } from './logger';\r\n\r\nexport type DiatremaEvents = {\r\n ready: [data: { mode: \"development\" | \"production\"; port?: number; host?: string; }];\r\n};\r\n\r\nexport type DiatremaOptions = {\r\n dev: boolean;\r\n debug: boolean;\r\n rootPath: string;\r\n appPath: string;\r\n productionDir: string;\r\n developmentDir: string;\r\n initiatorFilePath?: string;\r\n moduleType: \"commonjs\" | \"esm\";\r\n}\r\n\r\nexport const diatremaDefaultConfig: DiatremaOptions = {\r\n dev: false,\r\n debug: false,\r\n rootPath: process.cwd(),\r\n get appPath(): string {\r\n return join(this.rootPath, this.dev ? this.developmentDir : this.productionDir);\r\n },\r\n productionDir: '.mahameru',\r\n developmentDir: '.mahameru',\r\n moduleType: 'esm'\r\n}\r\n\r\n/**\r\n * Main Diatrema class that orchestrates the application lifecycle.\r\n */\r\nexport default class Diatrema extends EventEmitter<DiatremaEvents> {\r\n protected _initialized = false;\r\n protected _isShuttingDown = false;\r\n protected _plugins = new Map<string, MahameruPlugin<any>>();\r\n protected logger: Logger;\r\n public instances: Instances = {};\r\n public readonly options: DiatremaOptions;\r\n\r\n constructor(options?: Partial<DiatremaOptions>) {\r\n super();\r\n\r\n this.options = { ...diatremaDefaultConfig, ...options };\r\n this.logger = createLogger('Diatrema', this.options.debug);\r\n }\r\n\r\n /**\r\n * Indicates whether the Mahameru server has been initialized or not.\r\n * @returns {boolean}\r\n */\r\n get initialized() {\r\n return this._initialized;\r\n }\r\n\r\n /**\r\n * Indicates whether the Mahameru server is shutting down or not.\r\n * @returns {boolean}\r\n */\r\n get isShuttingDown() {\r\n return this._isShuttingDown;\r\n }\r\n\r\n get plugins(): Record<string, MahameruPlugin<any>> {\r\n return Object.fromEntries(this._plugins);\r\n }\r\n\r\n public async initialize(): Promise<void> {\r\n try {\r\n if (this._initialized)\r\n return;\r\n\r\n await this.loadInitiator();\r\n\r\n for (const plugin of this._plugins.values()) {\r\n plugin.setDiatrema(this);\r\n\r\n await plugin.initialize();\r\n }\r\n } catch (error) {\r\n throw error;\r\n }\r\n\r\n this._initialized = true;\r\n\r\n this.emit('ready', { mode: this.options.dev ? 'development' : 'production' });\r\n }\r\n\r\n public setPlugin<T extends MahameruPlugin<any>>(pluginName: string, plugin: T) {\r\n this._plugins.set(pluginName, plugin);\r\n }\r\n\r\n public getPlugin<T extends MahameruPlugin<any>>(pluginName: string): T | undefined {\r\n return this._plugins.get(pluginName) as T | undefined;\r\n }\r\n\r\n public async devHRM(changedFile?: string) {\r\n if (!this._initialized)\r\n return\r\n\r\n if (changedFile) {\r\n for (const [_name, plugin] of this._plugins.entries()) {\r\n await plugin.onDevHRM(changedFile);\r\n }\r\n }\r\n }\r\n\r\n public async shutdown(): Promise<void> {\r\n if (this._isShuttingDown)\r\n return\r\n\r\n this._isShuttingDown = true;\r\n\r\n this.logger.debug('Shutting down...');\r\n\r\n for (const plugin of this._plugins.values()) {\r\n await plugin.destroy();\r\n }\r\n\r\n this._initialized = false;\r\n this.logger.debug('Shutting down... Done');\r\n }\r\n\r\n protected async loadInitiator() {\r\n if (!this.options.initiatorFilePath)\r\n return;\r\n\r\n const result = await this.require<Record<'default', InitiatorHandler>>(this.options.moduleType, this.options.initiatorFilePath);\r\n\r\n if (result) {\r\n const handler = this.getDefaultExport<InitiatorHandler>(result, this.options.initiatorFilePath);\r\n\r\n this.instances = await handler();\r\n this.logger.debug(`Initiator loaded successfully. Found ${Object.keys(this.instances).length} instances.`);\r\n }\r\n }\r\n\r\n protected async require<T extends Record<string, unknown> = Record<string, unknown>>(type: \"commonjs\" | \"esm\", resolvedFilePath: string): Promise<T | undefined> {\r\n const noCache = this.options.dev;\r\n\r\n if (!existsSync(resolvedFilePath))\r\n return;\r\n\r\n if (type === \"commonjs\") {\r\n if (noCache) {\r\n delete require.cache[resolvedFilePath];\r\n }\r\n\r\n return require(resolvedFilePath) as T;\r\n }\r\n\r\n let fileUrl = pathToFileURL(resolvedFilePath).href;\r\n\r\n if (noCache)\r\n fileUrl += `?update=${Date.now()}`;\r\n\r\n return (await import(fileUrl)) as T;\r\n }\r\n\r\n protected getDefaultExport<T>(module: Record<string, T>, filePath: string) {\r\n const defaultExportName = Object.keys(module).find((key) => key === 'default');\r\n\r\n if (!defaultExportName)\r\n throw new Error(`Module in file '${filePath}' does not have a default export.`);\r\n\r\n return module[defaultExportName];\r\n }\r\n}\r\n"],"mappings":"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","names":["module"]}
package/diatrema.d.cts DELETED
@@ -1,7 +0,0 @@
1
- import _default from './diatrema-BNmte9Pf.cjs';
2
- import './event-emitter.cjs';
3
- import './types.cjs';
4
- // @ts-ignore
5
- export = _default;
6
- export { b as DiatremaEvents, c as DiatremaOptions, d as diatremaDefaultConfig } from './diatrema-BNmte9Pf.cjs';
7
- import './logger.cjs';
package/event-emitter.cjs DELETED
@@ -1,68 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
- var event_emitter_exports = {};
21
- __export(event_emitter_exports, {
22
- EventEmitter: () => EventEmitter
23
- });
24
- module.exports = __toCommonJS(event_emitter_exports);
25
- class EventEmitter {
26
- static {
27
- __name(this, "EventEmitter");
28
- }
29
- listeners = /* @__PURE__ */ new Map();
30
- on(event, listener) {
31
- if (!this.listeners.has(event)) this.listeners.set(event, []);
32
- this.listeners.get(event).push(listener);
33
- }
34
- off(event, listener) {
35
- const list = this.listeners.get(event);
36
- if (!list) return;
37
- const index = list.findIndex(
38
- (l) => l === listener || l.original === listener
39
- );
40
- if (index !== -1) list.splice(index, 1);
41
- }
42
- emit(event, ...args) {
43
- const list = this.listeners.get(event);
44
- if (list) {
45
- [...list].forEach((listener) => listener(...args));
46
- }
47
- }
48
- once(event, listener) {
49
- const onceListener = /* @__PURE__ */ __name((...args) => {
50
- listener(...args);
51
- this.off(event, onceListener);
52
- }, "onceListener");
53
- onceListener.original = listener;
54
- this.on(event, onceListener);
55
- }
56
- removeAllListeners(event) {
57
- if (event) {
58
- this.listeners.delete(event);
59
- } else {
60
- this.listeners.clear();
61
- }
62
- }
63
- }
64
- // Annotate the CommonJS export names for ESM import in node:
65
- 0 && (module.exports = {
66
- EventEmitter
67
- });
68
- //# sourceMappingURL=event-emitter.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/event-emitter.ts"],"sourcesContent":["type Listener<T extends any[]> = (...args: T) => void;\r\n\r\nexport class EventEmitter<Events extends Record<string, any[]>> {\r\n private listeners = new Map<keyof Events, Listener<any[]>[]>();\r\n\r\n on<K extends keyof Events>(event: K, listener: Listener<Events[K]>): void {\r\n if (!this.listeners.has(event)) this.listeners.set(event, []);\r\n this.listeners.get(event)!.push(listener as Listener<any[]>);\r\n }\r\n\r\n off<K extends keyof Events>(event: K, listener: Listener<Events[K]>): void {\r\n const list = this.listeners.get(event);\r\n\r\n if (!list) return;\r\n\r\n const index = list.findIndex(\r\n (l) => l === listener || (l as any).original === listener\r\n );\r\n\r\n if (index !== -1) list.splice(index, 1);\r\n }\r\n\r\n emit<K extends keyof Events>(event: K, ...args: Events[K]): void {\r\n const list = this.listeners.get(event);\r\n\r\n if (list) {\r\n [...list].forEach((listener) => listener(...args));\r\n }\r\n }\r\n\r\n once<K extends keyof Events>(event: K, listener: Listener<Events[K]>): void {\r\n const onceListener = (...args: Events[K]) => {\r\n listener(...args);\r\n\r\n this.off(event, onceListener as any);\r\n };\r\n\r\n onceListener.original = listener;\r\n\r\n this.on(event, onceListener as any);\r\n }\r\n\r\n removeAllListeners<K extends keyof Events>(event?: K): void {\r\n if (event) {\r\n this.listeners.delete(event);\r\n } else {\r\n this.listeners.clear();\r\n }\r\n }\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,MAAM,aAAmD;AAAA,EAFhE,OAEgE;AAAA;AAAA;AAAA,EACpD,YAAY,oBAAI,IAAqC;AAAA,EAE7D,GAA2B,OAAU,UAAqC;AACtE,QAAI,CAAC,KAAK,UAAU,IAAI,KAAK,EAAG,MAAK,UAAU,IAAI,OAAO,CAAC,CAAC;AAC5D,SAAK,UAAU,IAAI,KAAK,EAAG,KAAK,QAA2B;AAAA,EAC/D;AAAA,EAEA,IAA4B,OAAU,UAAqC;AACvE,UAAM,OAAO,KAAK,UAAU,IAAI,KAAK;AAErC,QAAI,CAAC,KAAM;AAEX,UAAM,QAAQ,KAAK;AAAA,MACf,CAAC,MAAM,MAAM,YAAa,EAAU,aAAa;AAAA,IACrD;AAEA,QAAI,UAAU,GAAI,MAAK,OAAO,OAAO,CAAC;AAAA,EAC1C;AAAA,EAEA,KAA6B,UAAa,MAAuB;AAC7D,UAAM,OAAO,KAAK,UAAU,IAAI,KAAK;AAErC,QAAI,MAAM;AACN,OAAC,GAAG,IAAI,EAAE,QAAQ,CAAC,aAAa,SAAS,GAAG,IAAI,CAAC;AAAA,IACrD;AAAA,EACJ;AAAA,EAEA,KAA6B,OAAU,UAAqC;AACxE,UAAM,eAAe,2BAAI,SAAoB;AACzC,eAAS,GAAG,IAAI;AAEhB,WAAK,IAAI,OAAO,YAAmB;AAAA,IACvC,GAJqB;AAMrB,iBAAa,WAAW;AAExB,SAAK,GAAG,OAAO,YAAmB;AAAA,EACtC;AAAA,EAEA,mBAA2C,OAAiB;AACxD,QAAI,OAAO;AACP,WAAK,UAAU,OAAO,KAAK;AAAA,IAC/B,OAAO;AACH,WAAK,UAAU,MAAM;AAAA,IACzB;AAAA,EACJ;AACJ;","names":[]}
@@ -1,11 +0,0 @@
1
- type Listener<T extends any[]> = (...args: T) => void;
2
- declare class EventEmitter<Events extends Record<string, any[]>> {
3
- private listeners;
4
- on<K extends keyof Events>(event: K, listener: Listener<Events[K]>): void;
5
- off<K extends keyof Events>(event: K, listener: Listener<Events[K]>): void;
6
- emit<K extends keyof Events>(event: K, ...args: Events[K]): void;
7
- once<K extends keyof Events>(event: K, listener: Listener<Events[K]>): void;
8
- removeAllListeners<K extends keyof Events>(event?: K): void;
9
- }
10
-
11
- export { EventEmitter };
package/helpers.cjs DELETED
@@ -1,77 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
- var helpers_exports = {};
21
- __export(helpers_exports, {
22
- dynamicRequire: () => dynamicRequire,
23
- exists: () => exists,
24
- resolveWithinBase: () => resolveWithinBase
25
- });
26
- module.exports = __toCommonJS(helpers_exports);
27
- var import_promises = require("node:fs/promises");
28
- var import_node_path = require("node:path");
29
- var import_node_url = require("node:url");
30
- const exists = /* @__PURE__ */ __name(async (target) => {
31
- try {
32
- await (0, import_promises.access)(target, import_promises.constants.R_OK);
33
- return true;
34
- } catch {
35
- return false;
36
- }
37
- }, "exists");
38
- function isWithin(base, target) {
39
- if (target === base)
40
- return true;
41
- if (target.startsWith(base)) {
42
- const nextChar = target.charAt(base.length);
43
- return nextChar === import_node_path.sep;
44
- }
45
- return false;
46
- }
47
- __name(isWithin, "isWithin");
48
- function resolveWithinBase(base, target) {
49
- const baseResolved = (0, import_node_path.resolve)(base);
50
- const targetResolved = (0, import_node_path.resolve)(base, target);
51
- if (isWithin(baseResolved, targetResolved))
52
- return targetResolved;
53
- return null;
54
- }
55
- __name(resolveWithinBase, "resolveWithinBase");
56
- async function dynamicRequire(type, resolvedFilePath, noCache = false) {
57
- if (!await exists(resolvedFilePath))
58
- return;
59
- if (type === "commonjs") {
60
- if (noCache) {
61
- delete require.cache[resolvedFilePath];
62
- }
63
- return require(resolvedFilePath);
64
- }
65
- let fileUrl = (0, import_node_url.pathToFileURL)(resolvedFilePath).href;
66
- if (noCache)
67
- fileUrl += `?update=${Date.now()}`;
68
- return await import(fileUrl);
69
- }
70
- __name(dynamicRequire, "dynamicRequire");
71
- // Annotate the CommonJS export names for ESM import in node:
72
- 0 && (module.exports = {
73
- dynamicRequire,
74
- exists,
75
- resolveWithinBase
76
- });
77
- //# sourceMappingURL=helpers.cjs.map
package/helpers.cjs.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/helpers.ts"],"sourcesContent":["import { access, constants } from \"node:fs/promises\";\nimport { resolve, sep } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\n\nexport const exists = async (target: string): Promise<boolean> => {\n try {\n await access(target, constants.R_OK);\n return true;\n } catch {\n return false;\n }\n};\n\n/**\n * Checks if the target path is within the base path.\n * @param base The base directory (absolute path)\n * @param target The target path (absolute path) to check\n * @returns true if target is within base, false otherwise\n */\nfunction isWithin(base: string, target: string): boolean {\n if (target === base)\n return true;\n\n if (target.startsWith(base)) {\n const nextChar = target.charAt(base.length);\n\n return nextChar === sep;\n }\n\n return false;\n}\n\n/**\n * Resolves a target path relative to a base directory, ensuring the result is within the base.\n * Returns null if the resolved path would be outside the base.\n * @param base The base directory (absolute path)\n * @param target The target path (relative to base) to resolve\n * @returns The resolved absolute path if within base, null otherwise\n */\nexport function resolveWithinBase(base: string, target: string): string | null {\n const baseResolved = resolve(base);\n const targetResolved = resolve(base, target);\n\n if (isWithin(baseResolved, targetResolved))\n return targetResolved;\n\n return null;\n}\n\n/**\n * \n * @param type \"commonjs\" | \"esm\"\n * @param filePath string - path to resolved file: require.resolve(\"./path/to/file\")\n */\nexport async function dynamicRequire<T extends Record<string, unknown> = Record<string, unknown>>(type: \"commonjs\" | \"esm\", resolvedFilePath: string, noCache: boolean = false): Promise<T | undefined> {\n if (!(await exists(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"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAkC;AAClC,uBAA6B;AAC7B,sBAA8B;AAEvB,MAAM,SAAS,8BAAO,WAAqC;AAC9D,MAAI;AACA,cAAM,wBAAO,QAAQ,0BAAU,IAAI;AACnC,WAAO;AAAA,EACX,QAAQ;AACJ,WAAO;AAAA,EACX;AACJ,GAPsB;AAetB,SAAS,SAAS,MAAc,QAAyB;AACrD,MAAI,WAAW;AACX,WAAO;AAEX,MAAI,OAAO,WAAW,IAAI,GAAG;AACzB,UAAM,WAAW,OAAO,OAAO,KAAK,MAAM;AAE1C,WAAO,aAAa;AAAA,EACxB;AAEA,SAAO;AACX;AAXS;AAoBF,SAAS,kBAAkB,MAAc,QAA+B;AAC3E,QAAM,mBAAe,0BAAQ,IAAI;AACjC,QAAM,qBAAiB,0BAAQ,MAAM,MAAM;AAE3C,MAAI,SAAS,cAAc,cAAc;AACrC,WAAO;AAEX,SAAO;AACX;AARgB;AAehB,eAAsB,eAA4E,MAA0B,kBAA0B,UAAmB,OAA+B;AACpM,MAAI,CAAE,MAAM,OAAO,gBAAgB;AAC/B;AAEJ,MAAI,SAAS,YAAY;AACrB,QAAI,SAAS;AACT,aAAO,QAAQ,MAAM,gBAAgB;AAAA,IACzC;AAEA,WAAO,QAAQ,gBAAgB;AAAA,EACnC;AAEA,MAAI,cAAU,+BAAc,gBAAgB,EAAE;AAE9C,MAAI;AACA,eAAW,WAAW,KAAK,IAAI,CAAC;AAEpC,SAAQ,MAAM,OAAO;AACzB;AAlBsB;","names":[]}
package/helpers.d.cts DELETED
@@ -1,17 +0,0 @@
1
- declare const exists: (target: string) => Promise<boolean>;
2
- /**
3
- * Resolves a target path relative to a base directory, ensuring the result is within the base.
4
- * Returns null if the resolved path would be outside the base.
5
- * @param base The base directory (absolute path)
6
- * @param target The target path (relative to base) to resolve
7
- * @returns The resolved absolute path if within base, null otherwise
8
- */
9
- declare function resolveWithinBase(base: string, target: string): string | null;
10
- /**
11
- *
12
- * @param type "commonjs" | "esm"
13
- * @param filePath string - path to resolved file: require.resolve("./path/to/file")
14
- */
15
- declare function dynamicRequire<T extends Record<string, unknown> = Record<string, unknown>>(type: "commonjs" | "esm", resolvedFilePath: string, noCache?: boolean): Promise<T | undefined>;
16
-
17
- export { dynamicRequire, exists, resolveWithinBase };
package/helpers.d.ts DELETED
@@ -1,17 +0,0 @@
1
- declare const exists: (target: string) => Promise<boolean>;
2
- /**
3
- * Resolves a target path relative to a base directory, ensuring the result is within the base.
4
- * Returns null if the resolved path would be outside the base.
5
- * @param base The base directory (absolute path)
6
- * @param target The target path (relative to base) to resolve
7
- * @returns The resolved absolute path if within base, null otherwise
8
- */
9
- declare function resolveWithinBase(base: string, target: string): string | null;
10
- /**
11
- *
12
- * @param type "commonjs" | "esm"
13
- * @param filePath string - path to resolved file: require.resolve("./path/to/file")
14
- */
15
- declare function dynamicRequire<T extends Record<string, unknown> = Record<string, unknown>>(type: "commonjs" | "esm", resolvedFilePath: string, noCache?: boolean): Promise<T | undefined>;
16
-
17
- export { dynamicRequire, exists, resolveWithinBase };