@medusajs/modules-sdk
Advanced tools
Comparing version 1.8.8-snapshot-20230606085136 to 1.8.8-snapshot-20230606091839
@@ -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); |
@@ -30,3 +30,3 @@ "use strict"; | ||
} | ||
if (!resolution.resolutionPath) { | ||
if (resolution.resolutionPath === false) { | ||
container.register({ | ||
@@ -33,0 +33,0 @@ [registrationName]: (0, awilix_1.asValue)(undefined), |
@@ -1,3 +0,3 @@ | ||
import { ExternalModuleDeclaration, InternalModuleDeclaration, ModuleResolution } from "@medusajs/types"; | ||
import { ExternalModuleDeclaration, InternalModuleDeclaration, ModuleExports, ModuleResolution } from "@medusajs/types"; | ||
export declare const registerModules: (modules?: Record<string, false | string | Partial<InternalModuleDeclaration | ExternalModuleDeclaration>>) => Record<string, ModuleResolution>; | ||
export declare const registerMedusaModule: (moduleKey: string, moduleDeclaration: InternalModuleDeclaration | ExternalModuleDeclaration) => Record<string, ModuleResolution>; | ||
export declare const registerMedusaModule: (moduleKey: string, moduleDeclaration: InternalModuleDeclaration | ExternalModuleDeclaration, moduleExports?: ModuleExports) => Record<string, ModuleResolution>; |
@@ -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) => { | ||
@@ -26,3 +26,3 @@ const moduleResolutions = {}; | ||
exports.registerModules = registerModules; | ||
const registerMedusaModule = (moduleKey, moduleDeclaration) => { | ||
const registerMedusaModule = (moduleKey, moduleDeclaration, moduleExports) => { | ||
const moduleResolutions = {}; | ||
@@ -37,3 +37,3 @@ for (const definition of definitions_1.default) { | ||
} | ||
moduleResolutions[definition.key] = getInternalModuleResolution(definition, moduleDeclaration); | ||
moduleResolutions[definition.key] = getInternalModuleResolution(definition, moduleDeclaration, moduleExports); | ||
} | ||
@@ -43,3 +43,3 @@ return moduleResolutions; | ||
exports.registerMedusaModule = registerMedusaModule; | ||
function getInternalModuleResolution(definition, moduleConfig) { | ||
function getInternalModuleResolution(definition, moduleConfig, moduleExports) { | ||
if (typeof moduleConfig === "boolean") { | ||
@@ -63,3 +63,7 @@ if (!moduleConfig && definition.isRequired) { | ||
if (definition.canOverride && (isString || (isObj && moduleConfig.resolve))) { | ||
resolutionPath = (0, resolve_cwd_1.default)(isString ? moduleConfig : moduleConfig.resolve); | ||
resolutionPath = !moduleExports | ||
? (0, resolve_cwd_1.default)(isString ? moduleConfig : moduleConfig.resolve) | ||
: // Explicitly assign an empty string, later, we will check if the value is exactly false. | ||
// This allows to continue the module loading while using the module exports instead of re importing the module itself during the process. | ||
""; | ||
} | ||
@@ -78,2 +82,3 @@ const moduleDeclaration = isObj ? moduleConfig : {}; | ||
}, | ||
moduleExports, | ||
options: isObj ? moduleConfig.options ?? {} : {}, | ||
@@ -80,0 +85,0 @@ }; |
@@ -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); | ||
} | ||
@@ -36,4 +37,8 @@ let modDeclaration = declaration; | ||
} | ||
const moduleResolutions = (0, loaders_1.registerMedusaModule)(moduleKey, modDeclaration); | ||
await (0, loaders_1.moduleLoader)({ container, moduleResolutions, logger }); | ||
const moduleResolutions = (0, loaders_1.registerMedusaModule)(moduleKey, modDeclaration, moduleExports); | ||
await (0, loaders_1.moduleLoader)({ | ||
container, | ||
moduleResolutions, | ||
logger, | ||
}); | ||
const services = {}; | ||
@@ -45,3 +50,3 @@ for (const resolution of Object.values(moduleResolutions)) { | ||
} | ||
MedusaModule.instances_.set(moduleKey, services); | ||
MedusaModule.instances_.set(hashKey, services); | ||
return services; | ||
@@ -48,0 +53,0 @@ } |
{ | ||
"name": "@medusajs/modules-sdk", | ||
"version": "1.8.8-snapshot-20230606085136", | ||
"version": "1.8.8-snapshot-20230606091839", | ||
"description": "SDK for medusa modules", | ||
@@ -26,7 +26,5 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@medusajs/types": "1.8.8-snapshot-20230606085136", | ||
"@medusajs/utils": "1.9.0", | ||
"@medusajs/types": "1.8.8-snapshot-20230606091839", | ||
"@medusajs/utils": "1.9.1-snapshot-20230606091839", | ||
"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
Sorry, the diff of this file is not supported yet
37411
4
556
+ Added@medusajs/types@1.8.8-snapshot-20230606091839(transitive)
+ Added@medusajs/utils@1.9.1-snapshot-20230606091839(transitive)
- Removedglob@7.1.6
- Removedmedusa-telemetry@^0.0.16
- Removed@babel/runtime@7.26.7(transitive)
- Removed@medusajs/types@1.8.8-snapshot-20230606085136(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)