chore: added missing withTransacton, create-variant using TO (#3047)
Create variant integrated with Inventory modules
This commit is contained in:
committed by
GitHub
parent
150696de99
commit
aa54d902e5
@@ -1,53 +1,68 @@
|
||||
if (process.env.NODE_ENV !== "development") {
|
||||
return
|
||||
}
|
||||
|
||||
const path = require("path")
|
||||
|
||||
const Module = require("module")
|
||||
const originalRequire = Module.prototype.require
|
||||
const medusaCore = path.resolve(path.join(__dirname, "../../packages"))
|
||||
|
||||
function replacePath(requirePath, package, concatPackage = true) {
|
||||
const idx = requirePath.indexOf(package)
|
||||
const packPath = requirePath.substring(idx + package.length)
|
||||
function replacePath(requirePath, pack, concatPackage = true) {
|
||||
const idx = requirePath.indexOf(pack)
|
||||
const packPath = requirePath.substring(idx + pack.length).replace(/\\/g, "/")
|
||||
|
||||
let newPath =
|
||||
medusaCore +
|
||||
"/" +
|
||||
(concatPackage ? package + "/" : "") +
|
||||
(concatPackage ? pack + "/" : "") +
|
||||
packPath.replace("/dist", "/src").replace(".js", "")
|
||||
|
||||
if (!newPath.includes("/src")) {
|
||||
newPath += "/src"
|
||||
}
|
||||
|
||||
return path.resolve(newPath)
|
||||
}
|
||||
|
||||
Module.prototype.require = function (...args) {
|
||||
function checkAndReplacePaths(path) {
|
||||
const interfaces = "medusa-interfaces"
|
||||
const utils = "medusa-core-utils"
|
||||
const base = "@medusajs"
|
||||
|
||||
if (args[0].includes(base)) {
|
||||
args[0] = replacePath(args[0], base, false)
|
||||
} else if (args[0].includes(interfaces)) {
|
||||
args[0] = replacePath(args[0], interfaces)
|
||||
} else if (args[0].includes(utils)) {
|
||||
args[0] = replacePath(args[0], utils)
|
||||
if (path.includes(base)) {
|
||||
path = replacePath(path, base, false)
|
||||
} else if (path.includes(interfaces)) {
|
||||
path = replacePath(path, interfaces)
|
||||
} else if (path.includes(utils)) {
|
||||
path = replacePath(path, utils)
|
||||
}
|
||||
|
||||
return path
|
||||
}
|
||||
|
||||
Module.prototype.require = function (...args) {
|
||||
args[0] = checkAndReplacePaths(args[0])
|
||||
|
||||
if (args[0] === "glob") {
|
||||
const glob = originalRequire.apply(this, args)
|
||||
const originalGlobSync = glob.sync
|
||||
glob.GlobSync = glob.sync = (pattern, options) => {
|
||||
if (pattern.endsWith(".js") || pattern.endsWith(".ts")) {
|
||||
pattern = checkAndReplacePaths(pattern)
|
||||
pattern = pattern.replace(".js", ".{j,t}s").replace("/dist/", "/src/")
|
||||
}
|
||||
|
||||
return originalGlobSync.apply(this, [pattern, options])
|
||||
}
|
||||
return glob
|
||||
} else if (args[0] === "resolve-cwd") {
|
||||
const resolveCwd = originalRequire.apply(this, args)
|
||||
const newResolveCwd = (pattern) => {
|
||||
pattern = checkAndReplacePaths(pattern)
|
||||
|
||||
return resolveCwd.apply(this, [pattern])
|
||||
}
|
||||
return newResolveCwd
|
||||
}
|
||||
|
||||
return originalRequire.apply(this, args)
|
||||
|
||||
Reference in New Issue
Block a user