Skip to content

Commit

Permalink
Merge branch 'develop' into docs/generate-reference-1727914543
Browse files Browse the repository at this point in the history
  • Loading branch information
shahednasser authored Oct 3, 2024
2 parents 6eb1c39 + 225d00c commit 255bda2
Show file tree
Hide file tree
Showing 38 changed files with 337 additions and 221 deletions.
18 changes: 0 additions & 18 deletions integration-tests/http/__tests__/product/admin/product.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1277,16 +1277,10 @@ medusaIntegrationTestRunner({
expect.objectContaining({
id: expect.stringMatching(/^optval_*/),
value: "large",
option: expect.objectContaining({
title: "size",
}),
}),
expect.objectContaining({
id: expect.stringMatching(/^optval_*/),
value: "green",
option: expect.objectContaining({
title: "color",
}),
}),
]),
}),
Expand Down Expand Up @@ -1557,9 +1551,6 @@ medusaIntegrationTestRunner({
expect.objectContaining({
id: expect.stringMatching(/^optval_*/),
value: "large",
option: expect.objectContaining({
title: "size",
}),
}),
]),
origin_country: null,
Expand Down Expand Up @@ -2660,9 +2651,6 @@ medusaIntegrationTestRunner({
updatedProduct.variants.find((v) => v.id === baseVariant.id).options
).toEqual([
expect.objectContaining({
option: expect.objectContaining({
title: "size",
}),
value: "small",
}),
])
Expand Down Expand Up @@ -2692,15 +2680,9 @@ medusaIntegrationTestRunner({
expect(updatedOptions).toEqual(
expect.arrayContaining([
expect.objectContaining({
option: expect.objectContaining({
title: "size",
}),
value: "small",
}),
expect.objectContaining({
option: expect.objectContaining({
title: "color",
}),
value: "green",
}),
])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
RegionTypes,
BigNumberInput,
HttpTypes,
PricingTypes,
RegionTypes,
} from "@medusajs/framework/types"
import { MedusaError, upperCaseFirst } from "@medusajs/framework/utils"

Expand All @@ -24,7 +24,7 @@ export const normalizeForExport = (
variants.forEach((v) => {
const toPush = {
...normalizeProductForExport(product),
...normalizeVariantForExport(v, regionsMap),
...normalizeVariantForExport(v, regionsMap, product),
} as any
delete toPush["Product Variants"]

Expand Down Expand Up @@ -101,7 +101,8 @@ const normalizeVariantForExport = (
variant: HttpTypes.AdminProductVariant & {
price_set?: PricingTypes.PriceSetDTO
},
regionsMap: Map<string, RegionTypes.RegionDTO>
regionsMap: Map<string, RegionTypes.RegionDTO>,
product: HttpTypes.AdminProduct
): object => {
const flattenedPrices = variant.price_set?.prices
?.sort((a, b) => b.currency_code!.localeCompare(a.currency_code!))
Expand Down Expand Up @@ -133,9 +134,14 @@ const normalizeVariantForExport = (
return acc
}, {})

const options = product.options ?? []

const flattenedOptions = variant.options?.reduce(
(acc: Record<string, string>, option, idx) => {
acc[beautifyKey(`variant_option_${idx + 1}_name`)] = option.option?.title!
const prodOptions = options.find(
(prodOption) => prodOption.id === option.option_id
)
acc[beautifyKey(`variant_option_${idx + 1}_name`)] = prodOptions?.title!
acc[beautifyKey(`variant_option_${idx + 1}_value`)] = option.value
return acc
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const getAllProductsStep = createStep(
},
fields: data.select,
})

allProducts.push(...products)

if (products.length < pageSize) {
Expand Down
9 changes: 9 additions & 0 deletions packages/core/framework/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"!dist/**/__mocks__",
"!dist/**/__fixtures__"
],
"bin": {
"medusa-mikro-orm": "./dist/mikro-orm-cli/bin.js"
},
"exports": {
".": "./dist/index.js",
"./config": "./dist/config/index.js",
Expand Down Expand Up @@ -68,6 +71,7 @@
"vite": "^5.2.11"
},
"dependencies": {
"@jercle/yargonaut": "^1.1.5",
"@medusajs/modules-sdk": "^1.12.11",
"@medusajs/orchestration": "^0.5.7",
"@medusajs/types": "^1.11.16",
Expand All @@ -82,10 +86,12 @@
"jsonwebtoken": "^9.0.2",
"medusa-telemetry": "^0.0.17",
"morgan": "^1.9.1",
"tsconfig-paths": "^4.2.0",
"zod": "3.22.4"
},
"peerDependencies": {
"@medusajs/medusa-cli": "^1.3.22",
"@mikro-orm/cli": "5.9.7",
"@mikro-orm/core": "5.9.7",
"@mikro-orm/knex": "5.9.7",
"@mikro-orm/migrations": "5.9.7",
Expand All @@ -96,6 +102,9 @@
"vite": "^5.2.11"
},
"peerDependenciesMeta": {
"@mikro-orm/cli": {
"optional": true
},
"ioredis": {
"optional": true
},
Expand Down
61 changes: 61 additions & 0 deletions packages/core/framework/src/mikro-orm-cli/bin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* Custom wrapper on top of MikroORM CLI to override the issue
* they have when importing TypeScript files.
*
* They have hardcoded the module system of TypeScript to CommonJS
* and that makes it impossible to use any other module system
* like Node16 or NodeNext and so on.
*
* With this wrapper, we monkey patch the code responsible for register
* ts-node and then boot their CLI. Since, the code footprint is
* small, we should be okay with managing this wrapper.
*/

import { isAbsolute, join } from "path"
import { ConfigurationLoader } from "@mikro-orm/core"
import { CLIConfigurator, CLIHelper } from "@mikro-orm/cli"

/**
* Monkey patching the TSNode registration of Mikro ORM to not use
* hardcoded module system with TypeScript.
*/
ConfigurationLoader.registerTsNode = async function (
configPath = "tsconfig.json"
) {
const tsConfigPath = isAbsolute(configPath)
? configPath
: join(process.cwd(), configPath)

const tsNode = require(require.resolve("ts-node", { paths: [tsConfigPath] }))
if (!tsNode) {
return false
}

const { options } = tsNode.register({
project: tsConfigPath,
transpileOnly: true,
}).config

if (Object.entries(options?.paths ?? {}).length > 0) {
require("tsconfig-paths").register({
baseUrl: options.baseUrl ?? ".",
paths: options.paths,
})
}

return true
}

require("@jercle/yargonaut")
.style("blue")
.style("yellow", "required")
.helpStyle("green")
.errorsStyle("red")

;(async () => {
const argv = await CLIConfigurator.configure()
const args = await argv.parse(process.argv.slice(2))
if (args._.length === 0) {
CLIHelper.showHelp()
}
})()
Loading

0 comments on commit 255bda2

Please sign in to comment.