@prostojs/mate 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +39 -1
- package/dist/index.d.ts +26 -1
- package/dist/index.mjs +37 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
|
|
3
|
+
//#region src/module-identity.ts
|
|
4
|
+
const MATE_MODULE_IDENTITY_KEY = Symbol.for("prostojs:mate:module-identity");
|
|
5
|
+
function getModulePath() {
|
|
6
|
+
try {
|
|
7
|
+
return require("url").pathToFileURL(__filename).href;
|
|
8
|
+
} catch {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function formatIdentity(identity) {
|
|
13
|
+
const version = identity.version ? `v${identity.version}` : "unknown version";
|
|
14
|
+
return identity.path ? `${version} at ${identity.path}` : version;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Stamps `globalThis` with this copy's identity and warns if another
|
|
18
|
+
* copy of @prostojs/mate was already loaded.
|
|
19
|
+
*
|
|
20
|
+
* Invoked once at module scope from index.ts, so importing the package
|
|
21
|
+
* performs the check.
|
|
22
|
+
*/
|
|
23
|
+
function warnOnDuplicateMate() {
|
|
24
|
+
const g = globalThis;
|
|
25
|
+
const identity = {};
|
|
26
|
+
identity.version = "0.4.0";
|
|
27
|
+
const path = getModulePath();
|
|
28
|
+
if (path) identity.path = path;
|
|
29
|
+
const first = g[MATE_MODULE_IDENTITY_KEY];
|
|
30
|
+
if (first) console.warn(`[mate] A second copy of @prostojs/mate was loaded (${formatIdentity(first)}, now ${formatIdentity(identity)}). Decorator metadata is stored per-copy and will NOT be visible across copies. Check your bundler/dedupe settings.`);
|
|
31
|
+
else g[MATE_MODULE_IDENTITY_KEY] = identity;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
3
35
|
//#region src/utils/helpers.ts
|
|
4
36
|
function getConstructor(instance) {
|
|
5
37
|
return isConstructor(instance) ? instance : instance.constructor ? instance.constructor : Object.getPrototypeOf(instance).constructor;
|
|
@@ -199,6 +231,12 @@ var Mate = class {
|
|
|
199
231
|
const fnProto = Object.getPrototypeOf(Function);
|
|
200
232
|
|
|
201
233
|
//#endregion
|
|
234
|
+
//#region src/index.ts
|
|
235
|
+
warnOnDuplicateMate();
|
|
236
|
+
|
|
237
|
+
//#endregion
|
|
238
|
+
exports.MATE_MODULE_IDENTITY_KEY = MATE_MODULE_IDENTITY_KEY;
|
|
202
239
|
exports.Mate = Mate;
|
|
203
240
|
exports.getConstructor = getConstructor;
|
|
204
|
-
exports.isConstructor = isConstructor;
|
|
241
|
+
exports.isConstructor = isConstructor;
|
|
242
|
+
exports.warnOnDuplicateMate = warnOnDuplicateMate;
|
package/dist/index.d.ts
CHANGED
|
@@ -70,8 +70,33 @@ declare class Mate<TClass extends TObject = TMateClassMeta<TMateParamMeta>, TPro
|
|
|
70
70
|
}
|
|
71
71
|
type ArrayElementType<T> = T extends (infer E)[] ? E : never;
|
|
72
72
|
//#endregion
|
|
73
|
+
//#region dts-build/module-identity.d.ts
|
|
74
|
+
/**
|
|
75
|
+
* Duplicate-copy detection for @prostojs/mate
|
|
76
|
+
*
|
|
77
|
+
* Mate stores class metadata in WeakMaps keyed by constructor reference.
|
|
78
|
+
* If a bundler loads two copies of mate (or of a decorated class),
|
|
79
|
+
* decorators run against one copy while lookups hit the other, and
|
|
80
|
+
* metadata silently "disappears". The first loaded copy stamps
|
|
81
|
+
* `globalThis` under a global symbol; any subsequent copy finds the
|
|
82
|
+
* stamp and warns.
|
|
83
|
+
*/
|
|
84
|
+
interface TMateModuleIdentity {
|
|
85
|
+
version?: string;
|
|
86
|
+
path?: string;
|
|
87
|
+
}
|
|
88
|
+
declare const MATE_MODULE_IDENTITY_KEY: unique symbol;
|
|
89
|
+
/**
|
|
90
|
+
* Stamps `globalThis` with this copy's identity and warns if another
|
|
91
|
+
* copy of @prostojs/mate was already loaded.
|
|
92
|
+
*
|
|
93
|
+
* Invoked once at module scope from index.ts, so importing the package
|
|
94
|
+
* performs the check.
|
|
95
|
+
*/
|
|
96
|
+
declare function warnOnDuplicateMate(): void;
|
|
97
|
+
//#endregion
|
|
73
98
|
//#region dts-build/utils/helpers.d.ts
|
|
74
99
|
declare function getConstructor<T = TAny>(instance: T): TFunction;
|
|
75
100
|
declare function isConstructor<T = TAny>(v: T): v is T & TClassConstructor;
|
|
76
101
|
//#endregion
|
|
77
|
-
export { Mate, TMateClassMeta, TMateOptions, TMateParamMeta, TMatePropMeta, TMergedDecoratorArgs, getConstructor, isConstructor };
|
|
102
|
+
export { MATE_MODULE_IDENTITY_KEY, Mate, TMateClassMeta, TMateModuleIdentity, TMateOptions, TMateParamMeta, TMatePropMeta, TMergedDecoratorArgs, getConstructor, isConstructor, warnOnDuplicateMate };
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,35 @@
|
|
|
1
|
+
//#region src/module-identity.ts
|
|
2
|
+
const MATE_MODULE_IDENTITY_KEY = Symbol.for("prostojs:mate:module-identity");
|
|
3
|
+
function getModulePath() {
|
|
4
|
+
try {
|
|
5
|
+
return import.meta.url;
|
|
6
|
+
} catch {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
function formatIdentity(identity) {
|
|
11
|
+
const version = identity.version ? `v${identity.version}` : "unknown version";
|
|
12
|
+
return identity.path ? `${version} at ${identity.path}` : version;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Stamps `globalThis` with this copy's identity and warns if another
|
|
16
|
+
* copy of @prostojs/mate was already loaded.
|
|
17
|
+
*
|
|
18
|
+
* Invoked once at module scope from index.ts, so importing the package
|
|
19
|
+
* performs the check.
|
|
20
|
+
*/
|
|
21
|
+
function warnOnDuplicateMate() {
|
|
22
|
+
const g = globalThis;
|
|
23
|
+
const identity = {};
|
|
24
|
+
identity.version = "0.4.0";
|
|
25
|
+
const path = getModulePath();
|
|
26
|
+
if (path) identity.path = path;
|
|
27
|
+
const first = g[MATE_MODULE_IDENTITY_KEY];
|
|
28
|
+
if (first) console.warn(`[mate] A second copy of @prostojs/mate was loaded (${formatIdentity(first)}, now ${formatIdentity(identity)}). Decorator metadata is stored per-copy and will NOT be visible across copies. Check your bundler/dedupe settings.`);
|
|
29
|
+
else g[MATE_MODULE_IDENTITY_KEY] = identity;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
1
33
|
//#region src/utils/helpers.ts
|
|
2
34
|
function getConstructor(instance) {
|
|
3
35
|
return isConstructor(instance) ? instance : instance.constructor ? instance.constructor : Object.getPrototypeOf(instance).constructor;
|
|
@@ -197,4 +229,8 @@ var Mate = class {
|
|
|
197
229
|
const fnProto = Object.getPrototypeOf(Function);
|
|
198
230
|
|
|
199
231
|
//#endregion
|
|
200
|
-
|
|
232
|
+
//#region src/index.ts
|
|
233
|
+
warnOnDuplicateMate();
|
|
234
|
+
|
|
235
|
+
//#endregion
|
|
236
|
+
export { MATE_MODULE_IDENTITY_KEY, Mate, getConstructor, isConstructor, warnOnDuplicateMate };
|