@nestjs/common 12.0.0-alpha.0 → 12.0.0-alpha.2
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.
|
@@ -16,11 +16,11 @@ import { isUndefined } from '../../utils/shared.utils.js';
|
|
|
16
16
|
export function Optional() {
|
|
17
17
|
return (target, key, index) => {
|
|
18
18
|
if (!isUndefined(index)) {
|
|
19
|
-
const args = Reflect.
|
|
19
|
+
const args = Reflect.getOwnMetadata(OPTIONAL_DEPS_METADATA, target) || [];
|
|
20
20
|
Reflect.defineMetadata(OPTIONAL_DEPS_METADATA, [...args, index], target);
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
|
-
const properties = Reflect.
|
|
23
|
+
const properties = Reflect.getOwnMetadata(OPTIONAL_PROPERTY_DEPS_METADATA, target.constructor) || [];
|
|
24
24
|
Reflect.defineMetadata(OPTIONAL_PROPERTY_DEPS_METADATA, [...properties, key], target.constructor);
|
|
25
25
|
};
|
|
26
26
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestjs/common",
|
|
3
|
-
"version": "12.0.0-alpha.
|
|
3
|
+
"version": "12.0.0-alpha.2",
|
|
4
4
|
"description": "Nest - modern, fast, powerful node.js web framework (@common)",
|
|
5
5
|
"author": "Kamil Mysliwiec",
|
|
6
6
|
"homepage": "https://nestjs.com",
|
|
@@ -21,34 +21,9 @@
|
|
|
21
21
|
"main": "./index.js",
|
|
22
22
|
"exports": {
|
|
23
23
|
".": "./index.js",
|
|
24
|
+
"./internal": "./internal.js",
|
|
24
25
|
"./*.js": "./*.js",
|
|
25
|
-
"./*": "./*.js"
|
|
26
|
-
"./decorators": "./decorators/index.js",
|
|
27
|
-
"./decorators/core": "./decorators/core/index.js",
|
|
28
|
-
"./decorators/http": "./decorators/http/index.js",
|
|
29
|
-
"./decorators/modules": "./decorators/modules/index.js",
|
|
30
|
-
"./enums": "./enums/index.js",
|
|
31
|
-
"./exceptions": "./exceptions/index.js",
|
|
32
|
-
"./file-stream": "./file-stream/index.js",
|
|
33
|
-
"./file-stream/interfaces": "./file-stream/interfaces/index.js",
|
|
34
|
-
"./interfaces": "./interfaces/index.js",
|
|
35
|
-
"./interfaces/controllers": "./interfaces/controllers/index.js",
|
|
36
|
-
"./interfaces/exceptions": "./interfaces/exceptions/index.js",
|
|
37
|
-
"./interfaces/hooks": "./interfaces/hooks/index.js",
|
|
38
|
-
"./interfaces/http": "./interfaces/http/index.js",
|
|
39
|
-
"./interfaces/middleware": "./interfaces/middleware/index.js",
|
|
40
|
-
"./interfaces/modules": "./interfaces/modules/index.js",
|
|
41
|
-
"./module-utils": "./module-utils/index.js",
|
|
42
|
-
"./module-utils/interfaces": "./module-utils/interfaces/index.js",
|
|
43
|
-
"./module-utils/utils": "./module-utils/utils/index.js",
|
|
44
|
-
"./pipes": "./pipes/index.js",
|
|
45
|
-
"./pipes/file": "./pipes/file/index.js",
|
|
46
|
-
"./pipes/file/interfaces": "./pipes/file/interfaces/index.js",
|
|
47
|
-
"./serializer": "./serializer/index.js",
|
|
48
|
-
"./serializer/decorators": "./serializer/decorators/index.js",
|
|
49
|
-
"./services": "./services/index.js",
|
|
50
|
-
"./services/utils": "./services/utils/index.js",
|
|
51
|
-
"./utils": "./utils/index.js"
|
|
26
|
+
"./*": "./*.js"
|
|
52
27
|
},
|
|
53
28
|
"dependencies": {
|
|
54
29
|
"file-type": "21.3.0",
|
|
@@ -71,5 +46,5 @@
|
|
|
71
46
|
"optional": true
|
|
72
47
|
}
|
|
73
48
|
},
|
|
74
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "011bff66014e24e82b25f7acf9302b9efb70b02b"
|
|
75
50
|
}
|
|
@@ -19,3 +19,11 @@ export declare function loadPackageSync(packageName: string, context: string, lo
|
|
|
19
19
|
* before calling this function (typically during `init()` or `compile()`).
|
|
20
20
|
*/
|
|
21
21
|
export declare function loadPackageCached(packageName: string): any;
|
|
22
|
+
/**
|
|
23
|
+
* Attempts to load and cache a package. Returns the loaded module on success
|
|
24
|
+
* or `null` if the package is not installed.
|
|
25
|
+
*
|
|
26
|
+
* Unlike {@link loadPackage}, this function does **not** terminate the process
|
|
27
|
+
* when the package is missing, making it suitable for optional dependencies.
|
|
28
|
+
*/
|
|
29
|
+
export declare function tryLoadPackage(packageName: string, loaderFn?: Function): Promise<any>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire } from 'module';
|
|
2
2
|
import { Logger } from '../services/logger.service.js';
|
|
3
|
-
const MISSING_REQUIRED_DEPENDENCY = (name, reason) => `The "${name}" package is missing. Please, make sure to install it to
|
|
3
|
+
const MISSING_REQUIRED_DEPENDENCY = (name, reason) => `The "${name}" package is missing. Please, make sure to install it to use ${reason}.`;
|
|
4
4
|
const logger = new Logger('PackageLoader');
|
|
5
5
|
/**
|
|
6
6
|
* Cache of already-loaded packages keyed by package name.
|
|
@@ -68,3 +68,24 @@ export function loadPackageCached(packageName) {
|
|
|
68
68
|
}
|
|
69
69
|
return cached;
|
|
70
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Attempts to load and cache a package. Returns the loaded module on success
|
|
73
|
+
* or `null` if the package is not installed.
|
|
74
|
+
*
|
|
75
|
+
* Unlike {@link loadPackage}, this function does **not** terminate the process
|
|
76
|
+
* when the package is missing, making it suitable for optional dependencies.
|
|
77
|
+
*/
|
|
78
|
+
export async function tryLoadPackage(packageName, loaderFn) {
|
|
79
|
+
const cached = packageCache.get(packageName);
|
|
80
|
+
if (cached) {
|
|
81
|
+
return cached;
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
const pkg = loaderFn ? await loaderFn() : await import(packageName);
|
|
85
|
+
packageCache.set(packageName, pkg);
|
|
86
|
+
return pkg;
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
}
|