chore: Start cleaning up medusa-core-utils (#7450)

**What**
- remove medusa-core-utils
- dispatch the utils where they belongs
- update usage

**NOTE**
I have been wondering if the graceful class should go into the utils package or medusa package, I ve put it in the medusa package as it seems to be the best place I can see for now and is tight to the server as well. Also, I wanted to avoid the utils package to depends on http and net dependencies, happy to change that if you feel like it
This commit is contained in:
Adrien de Peretti authored and GitHub committed 2024-05-27 08:00:15 +00:00
1 parent 28a3f9a3df
commit b8bc3ed16f
69 files changed
+61 -1384

No files matched your search

+1 -1
View File
@@ -1,5 +1,5 @@
import { ConfigModule } from "@medusajs/types"
import { getConfigFile, isDefined } from "medusa-core-utils"
import { getConfigFile, isDefined } from "@medusajs/utils"
import logger from "./logger"
const isProduction = ["production", "prod"].includes(process.env.NODE_ENV || "")
@@ -5,7 +5,7 @@ import {
objectFromStringPath,
} from "@medusajs/utils"
import glob from "glob"
import { isDefined } from "medusa-core-utils"
import { isDefined } from "@medusajs/utils"
import { trackFeatureFlag } from "medusa-telemetry"
import path from "path"
import { FlagSettings } from "../../types/feature-flags"
@@ -2,7 +2,6 @@ import { ConfigModule, PluginDetails } from "@medusajs/types"
import { isString } from "@medusajs/utils"
import fs from "fs"
import { sync as existsSync } from "fs-exists-cached"
import { createRequireFromPath } from "medusa-core-utils"
import path from "path"
export const MEDUSA_PROJECT_NAME = "project-plugin"
@@ -57,23 +56,14 @@ function resolvePlugin(pluginName: string): {
}
}
const rootDir = path.resolve(".")
/**
* Here we have an absolute path to an internal plugin, or a name of a module
* which should be located in node_modules.
*/
try {
const requireSource =
rootDir !== null
? createRequireFromPath(`${rootDir}/:internal:`)
: require
// If the path is absolute, resolve the directory of the internal plugin,
// otherwise resolve the directory containing the package.json
const resolvedPath = path.dirname(
requireSource.resolve(`${pluginName}/package.json`)
)
const resolvedPath = require.resolve(pluginName)
const packageJSON = JSON.parse(
fs.readFileSync(`${resolvedPath}/package.json`, `utf-8`)
@@ -1,5 +1,5 @@
import { Request, Response } from "express"
import { MedusaError } from "medusa-core-utils"
import { MedusaError } from "@medusajs/utils"
export const GET = async (req: Request, res: Response) => {
throw new MedusaError(MedusaError.Types.NOT_ALLOWED, "Not allowed")
@@ -10,7 +10,6 @@ import {
import { asValue } from "awilix"
import express from "express"
import jwt from "jsonwebtoken"
import { MockManager } from "medusa-test-utils"
import querystring from "querystring"
import supertest from "supertest"
import apiLoader from "../../../../api"
@@ -70,7 +69,7 @@ export const createServer = async (rootDir) => {
logger: asValue({
error: () => {},
}),
manager: asValue(MockManager),
manager: asValue({}),
})
app.set("trust proxy", 1)
@@ -1,5 +1,4 @@
import express from "express"
import { IdMap } from "medusa-test-utils"
import { resolve } from "path"
import {
config,
@@ -32,7 +31,7 @@ describe("RoutesLoader", function () {
const res = await request("GET", "/admin/orders/1000", {
adminSession: {
jwt: {
userId: IdMap.getId("admin_user"),
userId: "admin_user",
},
},
})
@@ -45,7 +44,7 @@ describe("RoutesLoader", function () {
const res = await request("POST", "/admin/orders/1000", {
adminSession: {
jwt: {
userId: IdMap.getId("admin_user"),
userId: "admin_user",
},
},
})
@@ -132,7 +131,7 @@ describe("RoutesLoader", function () {
const res = await request("GET", "/admin/protected", {
adminSession: {
jwt: {
userId: IdMap.getId("admin_user"),
userId: "admin_user",
},
},
})
@@ -159,7 +158,7 @@ describe("RoutesLoader", function () {
const res = await request("GET", "/store/me/protected", {
clientSession: {
jwt: {
customer_id: IdMap.getId("lebron"),
customer_id: "lebron",
},
},
})
@@ -1,9 +1,8 @@
import { ConfigModule } from "@medusajs/types"
import { promiseAll, wrapHandler } from "@medusajs/utils"
import { parseCorsOrigins, promiseAll, wrapHandler } from "@medusajs/utils"
import cors from "cors"
import { Router, json, text, urlencoded, type Express } from "express"
import { type Express, json, Router, text, urlencoded } from "express"
import { readdir } from "fs/promises"
import { parseCorsOrigins } from "medusa-core-utils"
import { extname, join, sep } from "path"
import { MedusaRequest, MedusaResponse } from "../../../types/routing"
import { errorHandler } from "../../../utils/middlewares"
@@ -13,8 +12,8 @@ import {
GlobalMiddlewareDescriptor,
HTTP_METHODS,
MiddlewareRoute,
MiddlewareVerb,
MiddlewaresConfig,
MiddlewareVerb,
ParserConfigArgs,
RouteConfig,
RouteDescriptor,
+1 -1
View File
@@ -4,7 +4,7 @@ import { ContainerRegistrationKeys, promiseAll } from "@medusajs/utils"
import { asValue } from "awilix"
import { Express, NextFunction, Request, Response } from "express"
import glob from "glob"
import { createMedusaContainer } from "medusa-core-utils"
import { createMedusaContainer } from "@medusajs/utils"
import path from "path"
import requestIp from "request-ip"
import { v4 } from "uuid"