@medusajs/modules-sdk
Advanced tools
Comparing version 1.8.8-snapshot-20230605131919 to 1.8.8-snapshot-20230605141535
@@ -6,3 +6,4 @@ import { ModuleDefinition } from "@medusajs/types"; | ||
INVENTORY = "inventoryService", | ||
CACHE = "cacheService" | ||
CACHE = "cacheService", | ||
PRODUCT = "productService" | ||
} | ||
@@ -9,0 +10,0 @@ export declare const ModulesDefinition: { |
@@ -11,2 +11,3 @@ "use strict"; | ||
Modules["CACHE"] = "cacheService"; | ||
Modules["PRODUCT"] = "productService"; | ||
})(Modules = exports.Modules || (exports.Modules = {})); | ||
@@ -65,2 +66,14 @@ exports.ModulesDefinition = { | ||
}, | ||
[Modules.PRODUCT]: { | ||
key: Modules.PRODUCT, | ||
registrationName: "productService", | ||
defaultPackage: false, | ||
label: "productService", | ||
isRequired: false, | ||
canOverride: true, | ||
dependencies: [], | ||
defaultModuleDeclaration: { | ||
scope: types_1.MODULE_SCOPE.EXTERNAL, | ||
}, | ||
}, | ||
}; | ||
@@ -67,0 +80,0 @@ exports.MODULE_DEFINITIONS = Object.values(exports.ModulesDefinition); |
@@ -8,4 +8,4 @@ "use strict"; | ||
const types_1 = require("@medusajs/types"); | ||
const definitions_1 = __importDefault(require("../definitions")); | ||
const resolve_cwd_1 = __importDefault(require("resolve-cwd")); | ||
const definitions_1 = __importDefault(require("../definitions")); | ||
const registerModules = (modules) => { | ||
@@ -12,0 +12,0 @@ const moduleResolutions = {}; |
@@ -30,3 +30,3 @@ "use strict"; | ||
const awilix_1 = require("awilix"); | ||
const medusa_telemetry_1 = require("medusa-telemetry"); | ||
// import { trackInstallation } from "medusa-telemetry" | ||
async function loadInternalModule(container, resolution, logger) { | ||
@@ -37,3 +37,5 @@ const registrationName = resolution.definition.registrationName; | ||
try { | ||
loadedModule = (await Promise.resolve().then(() => __importStar(require(resolution.resolutionPath)))).default; | ||
loadedModule = | ||
resolution.moduleExports ?? | ||
(await Promise.resolve().then(() => __importStar(require(resolution.resolutionPath)))).default; | ||
} | ||
@@ -103,6 +105,11 @@ catch (error) { | ||
}); | ||
(0, medusa_telemetry_1.trackInstallation)({ | ||
/* | ||
trackInstallation( | ||
{ | ||
module: resolution.definition.key, | ||
resolution: resolution.resolutionPath, | ||
}, "module"); | ||
}, | ||
"module" | ||
) | ||
*/ | ||
} | ||
@@ -109,0 +116,0 @@ exports.loadInternalModule = loadInternalModule; |
@@ -1,5 +0,5 @@ | ||
import { ExternalModuleDeclaration, InternalModuleDeclaration } from "@medusajs/types"; | ||
import { ExternalModuleDeclaration, InternalModuleDeclaration, ModuleExports } from "@medusajs/types"; | ||
export declare class MedusaModule { | ||
private static instances_; | ||
static bootstrap(moduleKey: string, defaultPath: string, declaration?: InternalModuleDeclaration | ExternalModuleDeclaration, injectedDependencies?: Record<string, any>): Promise<{ | ||
static bootstrap(moduleKey: string, defaultPath: string, declaration?: InternalModuleDeclaration | ExternalModuleDeclaration, moduleExports?: ModuleExports, injectedDependencies?: Record<string, any>): Promise<{ | ||
[key: string]: any; | ||
@@ -6,0 +6,0 @@ }>; |
@@ -16,5 +16,6 @@ "use strict"; | ||
class MedusaModule { | ||
static async bootstrap(moduleKey, defaultPath, declaration, injectedDependencies) { | ||
if (MedusaModule.instances_.has(moduleKey)) { | ||
return MedusaModule.instances_.get(moduleKey); | ||
static async bootstrap(moduleKey, defaultPath, declaration, moduleExports, injectedDependencies) { | ||
const hashKey = (0, utils_1.simpleHash)((0, utils_1.stringifyCircular)({ moduleKey, defaultPath, declaration })); | ||
if (MedusaModule.instances_.has(hashKey)) { | ||
return MedusaModule.instances_.get(hashKey); | ||
} | ||
@@ -37,3 +38,10 @@ let modDeclaration = declaration; | ||
const moduleResolutions = (0, loaders_1.registerMedusaModule)(moduleKey, modDeclaration); | ||
await (0, loaders_1.moduleLoader)({ container, moduleResolutions, logger }); | ||
if (moduleResolutions[moduleKey]) { | ||
moduleResolutions[moduleKey].moduleExports = moduleExports; | ||
} | ||
await (0, loaders_1.moduleLoader)({ | ||
container, | ||
moduleResolutions, | ||
logger, | ||
}); | ||
const services = {}; | ||
@@ -45,3 +53,3 @@ for (const resolution of Object.values(moduleResolutions)) { | ||
} | ||
MedusaModule.instances_.set(moduleKey, services); | ||
MedusaModule.instances_.set(hashKey, services); | ||
return services; | ||
@@ -48,0 +56,0 @@ } |
{ | ||
"name": "@medusajs/modules-sdk", | ||
"version": "1.8.8-snapshot-20230605131919", | ||
"version": "1.8.8-snapshot-20230605141535", | ||
"description": "SDK for medusa modules", | ||
@@ -26,7 +26,5 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@medusajs/types": "1.8.8-snapshot-20230605131919", | ||
"@medusajs/utils": "1.9.0", | ||
"@medusajs/types": "1.8.8-snapshot-20230605141535", | ||
"@medusajs/utils": "1.9.1-snapshot-20230605141535", | ||
"awilix": "^8.0.0", | ||
"glob": "7.1.6", | ||
"medusa-telemetry": "^0.0.16", | ||
"resolve-cwd": "^3.0.0" | ||
@@ -37,4 +35,5 @@ }, | ||
"build": "tsc --build", | ||
"test": "jest" | ||
"test": "jest", | ||
"watch": "tsc --build --watch" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
37057
4
554
+ Added@medusajs/types@1.8.8-snapshot-20230605141535(transitive)
+ Added@medusajs/utils@1.9.1-snapshot-20230605141535(transitive)
- Removedglob@7.1.6
- Removedmedusa-telemetry@^0.0.16
- Removed@babel/runtime@7.26.7(transitive)
- Removed@medusajs/types@1.8.8-snapshot-20230605131919(transitive)
- Removed@medusajs/utils@1.9.0(transitive)
- Removedansi-align@3.0.1(transitive)
- Removedansi-regex@5.0.1(transitive)
- Removedansi-styles@4.3.0(transitive)
- Removedaxios@0.21.4(transitive)
- Removedaxios-retry@3.9.1(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedboxen@5.1.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedcamelcase@6.3.0(transitive)
- Removedchalk@4.1.2(transitive)
- Removedci-info@3.9.0(transitive)
- Removedcli-boxes@2.2.1(transitive)
- Removedcolor-convert@2.0.1(transitive)
- Removedcolor-name@1.1.4(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedconfigstore@5.0.1(transitive)
- Removedcrypto-random-string@2.0.0(transitive)
- Removeddom-walk@0.1.2(transitive)
- Removeddot-prop@5.3.0(transitive)
- Removedemoji-regex@8.0.0(transitive)
- Removedfollow-redirects@1.15.9(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedglob@7.1.6(transitive)
- Removedglobal@4.4.0(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedhas-flag@4.0.0(transitive)
- Removedimurmurhash@0.1.4(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedis-docker@2.2.1(transitive)
- Removedis-fullwidth-code-point@3.0.0(transitive)
- Removedis-obj@2.0.0(transitive)
- Removedis-retry-allowed@2.2.0(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedmake-dir@3.1.0(transitive)
- Removedmedusa-telemetry@0.0.16(transitive)
- Removedmin-document@2.19.0(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedonce@1.4.0(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedprocess@0.11.10(transitive)
- Removedregenerator-runtime@0.14.1(transitive)
- Removedremove-trailing-slash@0.1.1(transitive)
- Removedsemver@6.3.1(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedstring-width@4.2.3(transitive)
- Removedstrip-ansi@6.0.1(transitive)
- Removedsupports-color@7.2.0(transitive)
- Removedtype-fest@0.20.2(transitive)
- Removedtypedarray-to-buffer@3.1.5(transitive)
- Removedunique-string@2.0.0(transitive)
- Removeduuid@8.3.2(transitive)
- Removedwidest-line@3.1.0(transitive)
- Removedwrap-ansi@7.0.0(transitive)
- Removedwrappy@1.0.2(transitive)
- Removedwrite-file-atomic@3.0.3(transitive)
- Removedxdg-basedir@4.0.0(transitive)