* feat(product, pricing, utils): Transaction issues and reference issues * fixes decorators * cleanup * fix product module upsert * fix missing active manager * increase timeout * revert package.json * WIP * try another node version based on findings with memory issues with jest introduced after 16.11 but fixed in 21 * re add bail * fix variant options * chore: bulk create pricing * chore: workflow bulk * Create big-chefs-dream.md * fix missing update for upserty * Add integration tests for product options upsert * rm unnecessary return * fix product prices workflow issue * cleanup * fix flag * fix model --------- Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com> Co-authored-by: Carlos R. L. Rodrigues <rodrigolr@gmail.com> Co-authored-by: Riqwan Thamir <rmthamir@gmail.com>
84 lines
1.8 KiB
JavaScript
84 lines
1.8 KiB
JavaScript
const path = require("path")
|
|
const express = require("express")
|
|
const getPort = require("get-port")
|
|
const { isObject } = require("@medusajs/utils")
|
|
const { setContainer } = require("./use-container")
|
|
const { setPort, setExpressServer } = require("./use-api")
|
|
|
|
async function bootstrapApp({ cwd, env = {} } = {}) {
|
|
const app = express()
|
|
|
|
if (isObject(env)) {
|
|
Object.entries(env).forEach(([k, v]) => (process.env[k] = v))
|
|
}
|
|
|
|
const loaders = require("@medusajs/medusa/dist/loaders").default
|
|
|
|
const { container, dbConnection, pgConnection, disposeResources } =
|
|
await loaders({
|
|
directory: path.resolve(cwd || process.cwd()),
|
|
expressApp: app,
|
|
isTest: false,
|
|
})
|
|
|
|
const PORT = await getPort()
|
|
|
|
return {
|
|
disposeResources,
|
|
container,
|
|
db: dbConnection,
|
|
pgConnection,
|
|
app,
|
|
port: PORT,
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
bootstrapApp,
|
|
startBootstrapApp: async ({
|
|
cwd,
|
|
env = {},
|
|
skipExpressListen = false,
|
|
} = {}) => {
|
|
const { app, port, container, db, pgConnection } = await bootstrapApp({
|
|
cwd,
|
|
env,
|
|
})
|
|
let expressServer
|
|
|
|
setContainer(container)
|
|
|
|
if (skipExpressListen) {
|
|
return
|
|
}
|
|
|
|
const shutdown = async () => {
|
|
await Promise.all([
|
|
container.dispose(),
|
|
expressServer.close(),
|
|
db?.destroy(),
|
|
pgConnection?.context?.destroy(),
|
|
container.dispose(),
|
|
])
|
|
|
|
if (typeof global !== "undefined" && global?.gc) {
|
|
global.gc()
|
|
}
|
|
}
|
|
|
|
return await new Promise((resolve, reject) => {
|
|
expressServer = app.listen(port, async (err) => {
|
|
if (err) {
|
|
await shutdown()
|
|
return reject(err)
|
|
}
|
|
setPort(port)
|
|
process.send(port)
|
|
resolve(shutdown)
|
|
})
|
|
|
|
setExpressServer(expressServer)
|
|
})
|
|
},
|
|
}
|