From f298e948da255c33c237ab8d6de5ee73c74222b7 Mon Sep 17 00:00:00 2001 From: olivermrbl Date: Thu, 21 Dec 2023 12:12:01 +0100 Subject: [PATCH 1/3] fix --- packages/medusa/src/commands/develop.js | 13 ++------- .../src/commands/utils/resolve-admin-cli.ts | 29 ++++++++++++++----- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/packages/medusa/src/commands/develop.js b/packages/medusa/src/commands/develop.js index 48d8a15f86c47..61c985cca5f54 100644 --- a/packages/medusa/src/commands/develop.js +++ b/packages/medusa/src/commands/develop.js @@ -43,14 +43,7 @@ export default async function ({ port, directory }) { process.exit(0) }) - const babelPath = path.resolve( - require.resolve("@babel/cli"), - "../", - "bin", - "babel.js" - ) - - execSync(`"${babelPath}" src -d dist --ignore "src/admin/**"`, { + execSync(`npx --no-install babel src -d dist --ignore "src/admin/**"`, { cwd: directory, stdio: ["ignore", process.stdout, process.stderr], }) @@ -80,7 +73,7 @@ export default async function ({ port, directory }) { process.exit(1) }) - const { cli, binExists } = resolveAdminCLI() + const { cli, binExists } = resolveAdminCLI(directory) if (binExists) { const backendUrl = `http://localhost:${port}` @@ -112,7 +105,7 @@ export default async function ({ port, directory }) { child.kill("SIGINT") execSync( - `${babelPath} src -d dist --extensions ".ts,.js" --ignore "src/admin/**"`, + `npx --no-install babel src -d dist --extensions ".ts,.js" --ignore "src/admin/**"`, { cwd: directory, stdio: ["pipe", process.stdout, process.stderr], diff --git a/packages/medusa/src/commands/utils/resolve-admin-cli.ts b/packages/medusa/src/commands/utils/resolve-admin-cli.ts index daedb2eaa9a8f..b6cddadd44f20 100644 --- a/packages/medusa/src/commands/utils/resolve-admin-cli.ts +++ b/packages/medusa/src/commands/utils/resolve-admin-cli.ts @@ -1,15 +1,28 @@ import fs from "fs-extra" import path from "path" -export function resolveAdminCLI() { - const cli = path.resolve( - require.resolve("@medusajs/admin"), - "../../", - "bin", - "medusa-admin.js" - ) +export function resolveAdminCLI(directory) { + let binExists = false + let cli + try { + const pathToAdmin = require.resolve("@medusajs/admin") + cli = path.resolve(pathToAdmin, "../../", "bin", "medusa-admin.js") + } catch (error) { + const parentDir = path.resolve(directory, "..") - const binExists = fs.existsSync(cli) + // reached root directory + if (parentDir === directory) { + console.warn("Couldn't find Admin CLI executable") + return { + binExists: false, + cli: null, + } + } + + return resolveAdminCLI(parentDir) + } + + binExists = fs.existsSync(cli) return { binExists, From 0c1bca208397cd0fa0bf0b8408175d4f1cd7f083 Mon Sep 17 00:00:00 2001 From: olivermrbl Date: Thu, 21 Dec 2023 14:20:52 +0100 Subject: [PATCH 2/3] revert admin script --- packages/medusa/src/commands/develop.js | 2 +- .../src/commands/utils/resolve-admin-cli.ts | 29 +++++-------------- 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/packages/medusa/src/commands/develop.js b/packages/medusa/src/commands/develop.js index 61c985cca5f54..cbf30b19c7544 100644 --- a/packages/medusa/src/commands/develop.js +++ b/packages/medusa/src/commands/develop.js @@ -73,7 +73,7 @@ export default async function ({ port, directory }) { process.exit(1) }) - const { cli, binExists } = resolveAdminCLI(directory) + const { cli, binExists } = resolveAdminCLI() if (binExists) { const backendUrl = `http://localhost:${port}` diff --git a/packages/medusa/src/commands/utils/resolve-admin-cli.ts b/packages/medusa/src/commands/utils/resolve-admin-cli.ts index b6cddadd44f20..daedb2eaa9a8f 100644 --- a/packages/medusa/src/commands/utils/resolve-admin-cli.ts +++ b/packages/medusa/src/commands/utils/resolve-admin-cli.ts @@ -1,28 +1,15 @@ import fs from "fs-extra" import path from "path" -export function resolveAdminCLI(directory) { - let binExists = false - let cli - try { - const pathToAdmin = require.resolve("@medusajs/admin") - cli = path.resolve(pathToAdmin, "../../", "bin", "medusa-admin.js") - } catch (error) { - const parentDir = path.resolve(directory, "..") +export function resolveAdminCLI() { + const cli = path.resolve( + require.resolve("@medusajs/admin"), + "../../", + "bin", + "medusa-admin.js" + ) - // reached root directory - if (parentDir === directory) { - console.warn("Couldn't find Admin CLI executable") - return { - binExists: false, - cli: null, - } - } - - return resolveAdminCLI(parentDir) - } - - binExists = fs.existsSync(cli) + const binExists = fs.existsSync(cli) return { binExists, From a3214e3d21ee08feb2af3201dba2059d151cf76d Mon Sep 17 00:00:00 2001 From: Oli Juhl <59018053+olivermrbl@users.noreply.github.com> Date: Wed, 27 Dec 2023 13:55:24 +0100 Subject: [PATCH 3/3] Create lovely-otters-draw.md --- .changeset/lovely-otters-draw.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/lovely-otters-draw.md diff --git a/.changeset/lovely-otters-draw.md b/.changeset/lovely-otters-draw.md new file mode 100644 index 0000000000000..5787d8d4ec630 --- /dev/null +++ b/.changeset/lovely-otters-draw.md @@ -0,0 +1,5 @@ +--- +"@medusajs/medusa": patch +--- + +feat(medusa): Resolve babel executable with npx