chore(framework): Allow multiple source dir for subcribers loader (#8407)
* chore(framework): Allow multiple source dir for subcribers loader * re add log * add logs
This commit is contained in:
committed by
GitHub
parent
afa740606f
commit
e44332ba62
@@ -129,6 +129,7 @@ export class JobLoader {
|
||||
try {
|
||||
await access(sourcePath)
|
||||
} catch {
|
||||
logger.info(`No job to load from ${sourcePath}. skipped.`)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ export class LinkLoader {
|
||||
try {
|
||||
await access(sourcePath)
|
||||
} catch {
|
||||
logger.info(`No link to load from ${sourcePath}. skipped.`)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ export class SubscriberLoader {
|
||||
* The base directory from which to scan for the subscribers
|
||||
* @private
|
||||
*/
|
||||
#sourceDir: string
|
||||
#sourceDir: string | string[]
|
||||
|
||||
/**
|
||||
* The list of file names to exclude from the subscriber scan
|
||||
@@ -46,7 +46,10 @@ export class SubscriberLoader {
|
||||
*/
|
||||
#subscriberDescriptors: Map<string, SubscriberModule<any>> = new Map()
|
||||
|
||||
constructor(sourceDir: string, options: Record<string, unknown> = {}) {
|
||||
constructor(
|
||||
sourceDir: string | string[],
|
||||
options: Record<string, unknown> = {}
|
||||
) {
|
||||
this.#sourceDir = sourceDir
|
||||
this.#pluginOptions = options
|
||||
}
|
||||
@@ -213,20 +216,21 @@ export class SubscriberLoader {
|
||||
}
|
||||
|
||||
async load() {
|
||||
let hasSubscriberDir = false
|
||||
const normalizeSourcePaths = Array.isArray(this.#sourceDir)
|
||||
? this.#sourceDir
|
||||
: [this.#sourceDir]
|
||||
const promises = normalizeSourcePaths.map(async (sourcePath) => {
|
||||
try {
|
||||
await access(sourcePath)
|
||||
} catch {
|
||||
logger.info(`No subscribers to load from ${sourcePath}. skipped.`)
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await access(this.#sourceDir)
|
||||
hasSubscriberDir = true
|
||||
} catch (err) {
|
||||
logger.debug(`No subscriber directory found in ${this.#sourceDir}`)
|
||||
}
|
||||
return await this.createMap(sourcePath)
|
||||
})
|
||||
|
||||
if (!hasSubscriberDir) {
|
||||
return
|
||||
}
|
||||
|
||||
await this.createMap(this.#sourceDir)
|
||||
await promiseAll(promises)
|
||||
|
||||
for (const [
|
||||
fileName,
|
||||
|
||||
@@ -39,6 +39,7 @@ export class WorkflowLoader {
|
||||
try {
|
||||
await access(sourcePath)
|
||||
} catch {
|
||||
logger.info(`No workflow to load from ${sourcePath}. skipped.`)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -40,23 +40,15 @@ const shouldLoadBackgroundProcessors = (configModule) => {
|
||||
}
|
||||
|
||||
async function subscribersLoader(plugins: PluginDetails[]) {
|
||||
/**
|
||||
* Load subscribers from the medusa/medusa package
|
||||
*/
|
||||
await new SubscriberLoader(join(__dirname, "../subscribers")).load()
|
||||
const pluginSubscribersSourcePaths = [
|
||||
/**
|
||||
* Load subscribers from the medusa/medusa package. Remove once the medusa core is converted to a plugin
|
||||
*/
|
||||
join(__dirname, "../subscribers"),
|
||||
].concat(plugins.map((plugin) => join(plugin.resolve, "subscribers")))
|
||||
|
||||
// TODO: make it the same as the other loaders, taking an array of paths to load from
|
||||
/**
|
||||
* Load subscribers from all the plugins.
|
||||
*/
|
||||
await Promise.all(
|
||||
plugins.map(async (pluginDetails) => {
|
||||
await new SubscriberLoader(
|
||||
join(pluginDetails.resolve, "subscribers"),
|
||||
pluginDetails.options
|
||||
).load()
|
||||
})
|
||||
)
|
||||
const subscriberLoader = new SubscriberLoader(pluginSubscribersSourcePaths)
|
||||
await subscriberLoader.load()
|
||||
}
|
||||
|
||||
async function jobsLoader(plugins: PluginDetails[]) {
|
||||
|
||||
Reference in New Issue
Block a user