feat(create-medusa-app, medusa): check Node.js version before installation. (#8452)
Check before installation with `create-medusa-app` and `medusa new` whether the current node version is >= 20. If not, exit with an error.
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
"prepublishOnly": "cross-env NODE_ENV=production tsc --build"
|
"prepublishOnly": "cross-env NODE_ENV=production tsc --build"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@medusajs/utils": "^1.11.9",
|
||||||
"boxen": "^5",
|
"boxen": "^5",
|
||||||
"chalk": "^5.2.0",
|
"chalk": "^5.2.0",
|
||||||
"commander": "^10.0.1",
|
"commander": "^10.0.1",
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import waitOn from "wait-on"
|
|||||||
import ora, { Ora } from "ora"
|
import ora, { Ora } from "ora"
|
||||||
import fs from "fs"
|
import fs from "fs"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import isEmailImported from "validator/lib/isEmail.js"
|
|
||||||
import logMessage from "../utils/log-message.js"
|
import logMessage from "../utils/log-message.js"
|
||||||
import createAbortController, {
|
import createAbortController, {
|
||||||
isAbortError,
|
isAbortError,
|
||||||
@@ -27,6 +26,7 @@ import {
|
|||||||
installNextjsStarter,
|
installNextjsStarter,
|
||||||
startNextjsStarter,
|
startNextjsStarter,
|
||||||
} from "../utils/nextjs-utils.js"
|
} from "../utils/nextjs-utils.js"
|
||||||
|
import { getNodeVersion, MIN_SUPPORTED_NODE_VERSION } from "@medusajs/utils"
|
||||||
|
|
||||||
const slugify = slugifyType.default
|
const slugify = slugifyType.default
|
||||||
|
|
||||||
@@ -53,6 +53,13 @@ export default async ({
|
|||||||
withNextjsStarter = false,
|
withNextjsStarter = false,
|
||||||
verbose = false,
|
verbose = false,
|
||||||
}: CreateOptions) => {
|
}: CreateOptions) => {
|
||||||
|
const nodeVersion = getNodeVersion()
|
||||||
|
if (nodeVersion < MIN_SUPPORTED_NODE_VERSION) {
|
||||||
|
logMessage({
|
||||||
|
message: `Medusa requires at least v20 of Node.js. You're using v${nodeVersion}. Please install at least v20 and try again: https://nodejs.org/en/download`,
|
||||||
|
type: "error"
|
||||||
|
})
|
||||||
|
}
|
||||||
track("CREATE_CLI_CMA")
|
track("CREATE_CLI_CMA")
|
||||||
|
|
||||||
const spinner: Ora = ora()
|
const spinner: Ora = ora()
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import { getPackageManager, setPackageManager } from "../util/package-manager"
|
|||||||
import { PanicId } from "../reporter/panic-handler"
|
import { PanicId } from "../reporter/panic-handler"
|
||||||
import { clearProject } from "../util/clear-project"
|
import { clearProject } from "../util/clear-project"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
|
import { getNodeVersion, MIN_SUPPORTED_NODE_VERSION } from "@medusajs/utils"
|
||||||
|
|
||||||
const removeUndefined = (obj) => {
|
const removeUndefined = (obj) => {
|
||||||
return Object.fromEntries(
|
return Object.fromEntries(
|
||||||
@@ -512,6 +513,11 @@ const attemptSeed = async (rootPath) => {
|
|||||||
* Main function that clones or copies the starter.
|
* Main function that clones or copies the starter.
|
||||||
*/
|
*/
|
||||||
export const newStarter = async (args) => {
|
export const newStarter = async (args) => {
|
||||||
|
const nodeVersion = getNodeVersion()
|
||||||
|
if (nodeVersion < MIN_SUPPORTED_NODE_VERSION) {
|
||||||
|
reporter.error(`Medusa requires at least v20 of Node.js. You're using v${nodeVersion}. Please install at least v20 and try again: https://nodejs.org/en/download`)
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
track("CLI_NEW")
|
track("CLI_NEW")
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
export function getNodeVersion(): number {
|
||||||
|
const [major] = process.versions.node.split('.').map(Number)
|
||||||
|
|
||||||
|
return major
|
||||||
|
}
|
||||||
|
|
||||||
|
export const MIN_SUPPORTED_NODE_VERSION = 20
|
||||||
@@ -20,6 +20,7 @@ export * from "./get-caller-file-path"
|
|||||||
export * from "./get-config-file"
|
export * from "./get-config-file"
|
||||||
export * from "./get-duplicates"
|
export * from "./get-duplicates"
|
||||||
export * from "./get-iso-string-from-date"
|
export * from "./get-iso-string-from-date"
|
||||||
|
export * from "./get-node-version"
|
||||||
export * from "./get-selects-and-relations-from-object-array"
|
export * from "./get-selects-and-relations-from-object-array"
|
||||||
export * from "./get-set-difference"
|
export * from "./get-set-difference"
|
||||||
export * from "./graceful-shutdown-server"
|
export * from "./graceful-shutdown-server"
|
||||||
|
|||||||
@@ -15470,6 +15470,7 @@ __metadata:
|
|||||||
version: 0.0.0-use.local
|
version: 0.0.0-use.local
|
||||||
resolution: "create-medusa-app@workspace:packages/cli/create-medusa-app"
|
resolution: "create-medusa-app@workspace:packages/cli/create-medusa-app"
|
||||||
dependencies:
|
dependencies:
|
||||||
|
"@medusajs/utils": ^1.11.9
|
||||||
"@types/chalk": ^2.2.0
|
"@types/chalk": ^2.2.0
|
||||||
"@types/commander": ^2.12.2
|
"@types/commander": ^2.12.2
|
||||||
"@types/configstore": ^6.0.0
|
"@types/configstore": ^6.0.0
|
||||||
|
|||||||
Reference in New Issue
Block a user