@mahameru/diatrema 0.0.6 → 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.
- package/.tsbuildinfo +1 -0
- package/README.md +1 -1
- package/diatrema.d.ts +51 -4
- package/diatrema.d.ts.map +1 -0
- package/diatrema.js +53 -50
- package/diatrema.js.map +1 -1
- package/diatrema.mjs +104 -0
- package/diatrema.mjs.map +1 -0
- package/event-emitter.d.ts +4 -4
- package/event-emitter.d.ts.map +1 -0
- package/event-emitter.js +34 -10
- package/event-emitter.js.map +1 -1
- package/event-emitter.mjs +45 -0
- package/event-emitter.mjs.map +1 -0
- package/index.d.ts +7 -10
- package/index.d.ts.map +1 -0
- package/index.js +36 -10
- package/index.js.map +1 -1
- package/index.mjs +10 -0
- package/index.mjs.map +1 -0
- package/logger.d.ts +6 -7
- package/logger.d.ts.map +1 -0
- package/logger.js +38 -23
- package/logger.js.map +1 -1
- package/logger.mjs +25 -0
- package/logger.mjs.map +1 -0
- package/mahameru-plugin.d.ts +47 -4
- package/mahameru-plugin.d.ts.map +1 -0
- package/mahameru-plugin.js +32 -18
- package/mahameru-plugin.js.map +1 -1
- package/{mahameru-plugin.cjs → mahameru-plugin.mjs} +9 -44
- package/mahameru-plugin.mjs.map +1 -0
- package/package.json +5 -13
- package/diatrema-BNmte9Pf.d.cts +0 -100
- package/diatrema-CO0FOwdp.d.ts +0 -100
- package/diatrema.cjs +0 -151
- package/diatrema.cjs.map +0 -1
- package/diatrema.d.cts +0 -7
- package/event-emitter.cjs +0 -68
- package/event-emitter.cjs.map +0 -1
- package/event-emitter.d.cts +0 -11
- package/helpers.cjs +0 -77
- package/helpers.cjs.map +0 -1
- package/helpers.d.cts +0 -17
- package/helpers.d.ts +0 -17
- package/helpers.js +0 -52
- package/helpers.js.map +0 -1
- package/index.cjs +0 -52
- package/index.cjs.map +0 -1
- package/index.d.cts +0 -10
- package/logger.cjs +0 -57
- package/logger.cjs.map +0 -1
- package/logger.d.cts +0 -9
- package/mahameru-error.cjs +0 -42
- package/mahameru-error.cjs.map +0 -1
- package/mahameru-error.d.cts +0 -5
- package/mahameru-error.d.ts +0 -5
- package/mahameru-error.js +0 -19
- package/mahameru-error.js.map +0 -1
- package/mahameru-plugin.cjs.map +0 -1
- package/mahameru-plugin.d.cts +0 -4
- package/scripts/preinstall.cjs +0 -10
- package/scripts/preinstall.cjs.map +0 -1
- package/scripts/preinstall.d.cts +0 -2
- package/scripts/preinstall.d.ts +0 -2
- package/scripts/preinstall.js +0 -9
- package/scripts/preinstall.js.map +0 -1
- package/types.cjs +0 -17
- package/types.cjs.map +0 -1
- package/types.d.cts +0 -5
- package/types.d.ts +0 -5
- package/types.js +0 -1
- package/types.js.map +0 -1
package/diatrema-BNmte9Pf.d.cts
DELETED
|
@@ -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 };
|
package/diatrema-CO0FOwdp.d.ts
DELETED
|
@@ -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';\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":"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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
|
package/event-emitter.cjs.map
DELETED
|
@@ -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":[]}
|
package/event-emitter.d.cts
DELETED
|
@@ -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 };
|
package/helpers.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import { access, constants } from "node:fs/promises";
|
|
4
|
-
import { resolve, sep } from "node:path";
|
|
5
|
-
import { pathToFileURL } from "node:url";
|
|
6
|
-
const exists = /* @__PURE__ */ __name(async (target) => {
|
|
7
|
-
try {
|
|
8
|
-
await access(target, constants.R_OK);
|
|
9
|
-
return true;
|
|
10
|
-
} catch {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
}, "exists");
|
|
14
|
-
function isWithin(base, target) {
|
|
15
|
-
if (target === base)
|
|
16
|
-
return true;
|
|
17
|
-
if (target.startsWith(base)) {
|
|
18
|
-
const nextChar = target.charAt(base.length);
|
|
19
|
-
return nextChar === sep;
|
|
20
|
-
}
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
__name(isWithin, "isWithin");
|
|
24
|
-
function resolveWithinBase(base, target) {
|
|
25
|
-
const baseResolved = resolve(base);
|
|
26
|
-
const targetResolved = resolve(base, target);
|
|
27
|
-
if (isWithin(baseResolved, targetResolved))
|
|
28
|
-
return targetResolved;
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
__name(resolveWithinBase, "resolveWithinBase");
|
|
32
|
-
async function dynamicRequire(type, resolvedFilePath, noCache = false) {
|
|
33
|
-
if (!await exists(resolvedFilePath))
|
|
34
|
-
return;
|
|
35
|
-
if (type === "commonjs") {
|
|
36
|
-
if (noCache) {
|
|
37
|
-
delete require.cache[resolvedFilePath];
|
|
38
|
-
}
|
|
39
|
-
return require(resolvedFilePath);
|
|
40
|
-
}
|
|
41
|
-
let fileUrl = pathToFileURL(resolvedFilePath).href;
|
|
42
|
-
if (noCache)
|
|
43
|
-
fileUrl += `?update=${Date.now()}`;
|
|
44
|
-
return await import(fileUrl);
|
|
45
|
-
}
|
|
46
|
-
__name(dynamicRequire, "dynamicRequire");
|
|
47
|
-
export {
|
|
48
|
-
dynamicRequire,
|
|
49
|
-
exists,
|
|
50
|
-
resolveWithinBase
|
|
51
|
-
};
|
|
52
|
-
//# sourceMappingURL=helpers.js.map
|
package/helpers.js.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,SAAS,QAAQ,iBAAiB;AAClC,SAAS,SAAS,WAAW;AAC7B,SAAS,qBAAqB;AAEvB,MAAM,SAAS,8BAAO,WAAqC;AAC9D,MAAI;AACA,UAAM,OAAO,QAAQ,UAAU,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,eAAe,QAAQ,IAAI;AACjC,QAAM,iBAAiB,QAAQ,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,UAAU,cAAc,gBAAgB,EAAE;AAE9C,MAAI;AACA,eAAW,WAAW,KAAK,IAAI,CAAC;AAEpC,SAAQ,MAAM,OAAO;AACzB;AAlBsB;","names":[]}
|