create-medusa-app 2.22.4 → 2.22.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/AGENTS.md +1 -1
  2. package/CHANGELOG.md +9 -0
  3. package/dist/index.js +0 -0
  4. package/package.json +4 -4
  5. package/src/utils/__tests__/prepare-project.test.ts +65 -0
  6. package/src/utils/__tests__/update-package-versions.test.ts +41 -0
  7. package/src/utils/prepare-project.ts +7 -0
  8. package/src/utils/project-creator/medusa-plugin-creator.ts +1 -0
  9. package/src/utils/update-package-versions.ts +7 -0
  10. package/dist/commands/create.js +0 -10
  11. package/dist/utils/claude-code-plugin.js +0 -76
  12. package/dist/utils/clone-repo.js +0 -77
  13. package/dist/utils/create-abort-controller.js +0 -11
  14. package/dist/utils/create-db.js +0 -188
  15. package/dist/utils/execute.js +0 -51
  16. package/dist/utils/facts.js +0 -87
  17. package/dist/utils/format-connection-string.js +0 -17
  18. package/dist/utils/get-current-os.js +0 -10
  19. package/dist/utils/log-message.js +0 -21
  20. package/dist/utils/logger.js +0 -8
  21. package/dist/utils/nextjs-utils.js +0 -55
  22. package/dist/utils/node-version.js +0 -15
  23. package/dist/utils/package-manager.js +0 -354
  24. package/dist/utils/postgres-client.js +0 -9
  25. package/dist/utils/prepare-project.js +0 -191
  26. package/dist/utils/process-manager.js +0 -50
  27. package/dist/utils/project-creator/creator.js +0 -46
  28. package/dist/utils/project-creator/index.js +0 -4
  29. package/dist/utils/project-creator/medusa-plugin-creator.js +0 -95
  30. package/dist/utils/project-creator/medusa-project-creator.js +0 -215
  31. package/dist/utils/project-creator/project-creator-factory.js +0 -83
  32. package/dist/utils/project-paths.js +0 -7
  33. package/dist/utils/start-medusa.js +0 -13
  34. package/dist/utils/update-package-versions.js +0 -29
@@ -1,87 +0,0 @@
1
- import boxen from "boxen";
2
- import chalk from "chalk";
3
- import { emojify } from "node-emoji";
4
- import terminalLink from "terminal-link";
5
- const facts = [
6
- "Specify a product's availability in one or more sales channels.",
7
- "Payment providers can be configured per region.",
8
- "Tax-inclusive pricing allows you to set prices for products and shipping options while delegating tax calculations to Medusa.",
9
- "Medusa provides multi-currency and region support, with full control over prices for each currency and region.",
10
- "Organize customers by customer groups and set special prices for them.",
11
- "Specify the inventory of products per location and sales channel.",
12
- "Publishable-API Keys allow you to send scoped requests to the server's store API routes.",
13
- "API Routes expose business logic to clients, such as storefronts and admin customizations.",
14
- "Subscribers are asynchronous functions that are executed when an event is emitted.",
15
- "Data models represent tables in the database. They are created using Medusa's Data Modeling Language (DML).",
16
- "Medusa's store API routes are prefixed by /store. The admin API routes are prefixed by /admin.",
17
- "The JS SDK allows you to send requests to the Medusa server from your storefront or admin customizations.",
18
- "Modules are reusable packages of functionalities related to a single commerce domain or integration.",
19
- "Modules have a main service that provides data-management and integration functionalities.",
20
- "Modules allow you to replace an entire functionality with your custom logic.",
21
- "Infrastructure Modules are interchangeable modules that implement features and integrations related to the Medusa server's infrastructure.",
22
- "Commerce Modules are built-in modules that provide core commerce logic specific to domains like Product, Cart and Order.",
23
- "Workflows are a series of queries and actions, called steps, that complete a task.",
24
- "A workflow's steps can be retried or rolled back in case of an error.",
25
- `Medusa provides ${terminalLink("Claude Code plugins", "https://github.com/medusajs/medusa-claude-plugins")} to facilitate your development.`,
26
- "Medusa provides an MCP server at https://docs.medusajs.com/mcp to support your learning and development experience with AI agents",
27
- `Medusa is optimized to build custom commerce software with AI agents through its MCP server and ${terminalLink("Claude Code plugins", "https://github.com/medusajs/medusa-claude-plugins")}.`,
28
- ];
29
- export const getFact = () => {
30
- const randIndex = Math.floor(Math.random() * facts.length);
31
- return facts[randIndex];
32
- };
33
- export const showFact = ({ spinner, title, verbose, }) => {
34
- const fact = getFact();
35
- if (verbose) {
36
- spinner.stopAndPersist({
37
- symbol: chalk.cyan("⠋"),
38
- text: title,
39
- });
40
- }
41
- else {
42
- spinner.text = `${title}\n${boxen(`${fact}`, {
43
- title: chalk.cyan(`${emojify(":bulb:")} Medusa Tips`),
44
- titleAlignment: "center",
45
- textAlignment: "center",
46
- padding: 1,
47
- margin: 1,
48
- })}`;
49
- }
50
- };
51
- export const createFactBox = ({ spinner, title, processManager, verbose, }) => {
52
- showFact({ spinner, title, verbose });
53
- const interval = setInterval(() => {
54
- showFact({ spinner, title, verbose });
55
- }, 10000);
56
- processManager.addInterval(interval);
57
- return interval;
58
- };
59
- export const resetFactBox = ({ interval, spinner, successMessage, processManager, newTitle, verbose, }) => {
60
- if (interval) {
61
- clearInterval(interval);
62
- }
63
- spinner.succeed(chalk.green(successMessage)).start();
64
- let newInterval = null;
65
- if (newTitle) {
66
- newInterval = createFactBox({
67
- spinner,
68
- title: newTitle,
69
- processManager,
70
- verbose,
71
- });
72
- }
73
- return newInterval;
74
- };
75
- export function displayFactBox({ interval, spinner, processManager, title = "", message = "", verbose = false, }) {
76
- if (!message) {
77
- return createFactBox({ spinner, title, processManager, verbose });
78
- }
79
- return resetFactBox({
80
- interval,
81
- spinner,
82
- successMessage: message,
83
- processManager,
84
- newTitle: title,
85
- verbose,
86
- });
87
- }
@@ -1,17 +0,0 @@
1
- export function encodeDbValue(value) {
2
- return encodeURIComponent(value);
3
- }
4
- export default ({ user, password, host, db }) => {
5
- let connection = `postgres://`;
6
- if (user) {
7
- connection += encodeDbValue(user);
8
- }
9
- if (password) {
10
- connection += `:${encodeDbValue(password)}`;
11
- }
12
- if (user || password) {
13
- connection += "@";
14
- }
15
- connection += `${host}/${db}`;
16
- return connection;
17
- };
@@ -1,10 +0,0 @@
1
- export const getCurrentOs = () => {
2
- switch (process.platform) {
3
- case "darwin":
4
- return "macos";
5
- case "linux":
6
- return "linux";
7
- default:
8
- return "windows";
9
- }
10
- };
@@ -1,21 +0,0 @@
1
- import chalk from "chalk";
2
- import { program } from "commander";
3
- import { logger } from "./logger.js";
4
- export default ({ message, type = "info", stack }) => {
5
- switch (type) {
6
- case "info":
7
- logger.info(chalk.white(message));
8
- break;
9
- case "success":
10
- logger.info(chalk.green(message));
11
- break;
12
- case "warn":
13
- logger.warn(chalk.yellow(message));
14
- break;
15
- case "verbose":
16
- logger.info(`${chalk.bgYellowBright("VERBOSE LOG:")} ${message}`);
17
- break;
18
- case "error":
19
- program.error(chalk.bold.red(message.trim() + (stack || "")));
20
- }
21
- };
@@ -1,8 +0,0 @@
1
- import winston from "winston";
2
- const consoleTransport = new winston.transports.Console({
3
- format: winston.format.printf((log) => log.message),
4
- });
5
- const options = {
6
- transports: [consoleTransport],
7
- };
8
- export const logger = winston.createLogger(options);
@@ -1,55 +0,0 @@
1
- import { exec } from "child_process";
2
- import fs from "fs";
3
- import inquirer from "inquirer";
4
- import path from "path";
5
- import { displayFactBox } from "./facts.js";
6
- import { updatePackageVersions } from "./update-package-versions.js";
7
- export async function askForNextjsStarter() {
8
- const { installNextjs } = await inquirer.prompt([
9
- {
10
- type: "confirm",
11
- name: "installNextjs",
12
- message: `Would you like to install the storefront? You can also install it later.`,
13
- default: false,
14
- },
15
- ]);
16
- return installNextjs;
17
- }
18
- export async function installNextjsStarter({ storefrontDirectory, factBoxOptions, packageManager, version, }) {
19
- factBoxOptions.interval = displayFactBox({
20
- ...factBoxOptions,
21
- title: "Setting up storefront...",
22
- });
23
- const packageJsonPath = path.join(storefrontDirectory, "package.json");
24
- let packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
25
- if (version) {
26
- packageJson = updatePackageVersions(packageJsonPath, version, {
27
- applyChanges: false,
28
- });
29
- }
30
- // Update packageManager field to match user's chosen package manager
31
- const packageManagerString = await packageManager.getPackageManagerString();
32
- if (packageManagerString) {
33
- packageJson.packageManager = packageManagerString;
34
- }
35
- fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
36
- const envTemplatePath = path.join(storefrontDirectory, ".env.template");
37
- if (fs.existsSync(envTemplatePath)) {
38
- fs.renameSync(envTemplatePath, path.join(storefrontDirectory, ".env.local"));
39
- }
40
- displayFactBox({
41
- ...factBoxOptions,
42
- message: `Storefront is set up in the ${storefrontDirectory} directory.`,
43
- });
44
- }
45
- export function startNextjsStarter({ directory, abortController, verbose = false, packageManager, }) {
46
- const command = packageManager.getCommandStr(`dev`);
47
- const childProcess = exec(command, {
48
- cwd: directory,
49
- signal: abortController?.signal,
50
- });
51
- if (verbose) {
52
- childProcess.stdout?.pipe(process.stdout);
53
- childProcess.stderr?.pipe(process.stderr);
54
- }
55
- }
@@ -1,15 +0,0 @@
1
- export const MIN_SUPPORTED_NODE_VERSION = "22.22.0";
2
- export function getNodeVersion() {
3
- return process.versions.node;
4
- }
5
- export function isNodeVersionSupported(version = getNodeVersion()) {
6
- const current = version.split(".").map(Number);
7
- const minimum = MIN_SUPPORTED_NODE_VERSION.split(".").map(Number);
8
- for (let i = 0; i < minimum.length; i++) {
9
- const part = current[i] ?? 0;
10
- if (part !== minimum[i]) {
11
- return part > minimum[i];
12
- }
13
- }
14
- return true;
15
- }
@@ -1,354 +0,0 @@
1
- import path from "path";
2
- import execute from "./execute.js";
3
- import logMessage from "./log-message.js";
4
- import { existsSync, readFileSync, rmSync, writeFileSync } from "fs";
5
- import { parse as parseYaml } from "yaml";
6
- export default class PackageManager {
7
- packageManager;
8
- packageManagerVersion;
9
- processManager;
10
- verbose;
11
- chosenPackageManager;
12
- constructor(processManager, options = {}) {
13
- this.processManager = processManager;
14
- this.verbose = options.verbose || false;
15
- if (options.useNpm) {
16
- this.chosenPackageManager = "npm";
17
- }
18
- else if (options.usePnpm) {
19
- this.chosenPackageManager = "pnpm";
20
- }
21
- else if (options.useYarn) {
22
- this.chosenPackageManager = "yarn";
23
- }
24
- }
25
- detectFromUserAgent() {
26
- const userAgent = process.env.npm_config_user_agent;
27
- if (!userAgent) {
28
- return { manager: "npm" };
29
- }
30
- // Extract package manager and version (e.g., "yarn/4.9.0" -> ["yarn", "4.9.0"])
31
- const match = userAgent.match(/(pnpm|pnpx|yarn|npm|nub)\/(\d+\.\d+\.\d+)/);
32
- if (match) {
33
- const [, manager, version] = match;
34
- if (this.verbose) {
35
- logMessage({
36
- type: "info",
37
- message: `Detected from user agent: ${manager}@${version}`,
38
- });
39
- }
40
- // pnpx is an alias for pnpm
41
- if (manager === "pnpx") {
42
- return { manager: "pnpm", version };
43
- }
44
- return { manager: manager, version };
45
- }
46
- // Fallback detection without version
47
- if (userAgent.includes("pnpm") || userAgent.includes("pnpx")) {
48
- return { manager: "pnpm" };
49
- }
50
- if (userAgent.includes("yarn")) {
51
- return { manager: "yarn" };
52
- }
53
- if (userAgent.includes("nub")) {
54
- return { manager: "nub" };
55
- }
56
- return { manager: "npm" };
57
- }
58
- async getVersion(pm, execOptions) {
59
- const commands = {
60
- yarn: "yarn -v",
61
- pnpm: "pnpm -v",
62
- npm: "npm -v",
63
- nub: "nub -v",
64
- };
65
- try {
66
- const result = await execute([commands[pm], execOptions], {
67
- verbose: false,
68
- });
69
- const version = result.stdout?.trim();
70
- if (this.verbose) {
71
- logMessage({
72
- type: "info",
73
- message: `Detected ${pm} version: ${version}`,
74
- });
75
- }
76
- return version;
77
- }
78
- catch {
79
- if (this.verbose) {
80
- logMessage({
81
- type: "info",
82
- message: `Failed to get version for package manager: ${pm}`,
83
- });
84
- }
85
- return undefined;
86
- }
87
- }
88
- async setPackageManager(execOptions) {
89
- if (this.packageManager) {
90
- return;
91
- }
92
- // check whether package manager is available and get version
93
- await this.processManager.runProcess({
94
- process: async () => {
95
- if (this.chosenPackageManager) {
96
- const version = await this.getVersion(this.chosenPackageManager, execOptions);
97
- if (version) {
98
- this.packageManager = this.chosenPackageManager;
99
- // Store version if we don't have it from user agent
100
- if (!this.packageManagerVersion) {
101
- this.packageManagerVersion = version;
102
- }
103
- return;
104
- }
105
- // Error logs exit the process, so command execution will stop here
106
- logMessage({
107
- type: "error",
108
- message: `The specified package manager "${this.chosenPackageManager}" is not available. Please install it or choose another package manager.`,
109
- });
110
- }
111
- const detectedResult = this.detectFromUserAgent();
112
- // fallback to npm if detection fails
113
- this.packageManager = detectedResult.manager || "npm";
114
- this.packageManagerVersion = detectedResult.version;
115
- if (!this.packageManagerVersion) {
116
- // get version for the detected package manager (or npm fallback)
117
- this.packageManagerVersion = await this.getVersion(this.packageManager, execOptions);
118
- if (this.verbose) {
119
- logMessage({
120
- type: "info",
121
- message: `Falling back to ${this.packageManager} as the package manager.`,
122
- });
123
- }
124
- }
125
- else {
126
- if (this.verbose) {
127
- logMessage({
128
- type: "info",
129
- message: `Using detected package manager "${this.packageManager}".`,
130
- });
131
- }
132
- }
133
- },
134
- ignoreERESOLVE: true,
135
- });
136
- }
137
- applyYarnWorkspaceChanges(directory) {
138
- writeFileSync(path.join(directory, "yarn.lock"), "");
139
- writeFileSync(path.join(directory, ".yarnrc.yml"), "nodeLinker: node-modules\n");
140
- }
141
- applyNpmWorkspaceChanges(packageJson) {
142
- // npm's flat hoisting can only keep a single ajv major at the workspace
143
- // root, but Medusa's stack needs two: the backend's migration tooling
144
- // (@mikro-orm/migrations -> umzug -> @rushstack/node-core-library ->
145
- // ajv-draft-04) does `require('ajv/dist/core')`, which only exists in ajv
146
- // v8+, while ESLint (`eslint` core and `@eslint/eslintrc`) needs ajv v6.
147
- // Both `ajv-draft-04` and `eslint` hoist to the root and resolve `ajv`
148
- // from there, so whichever major loses the root slot breaks. We pin v8 to
149
- // the root with a direct devDependency (this is what the hoisted
150
- // `ajv-draft-04` resolves against) and scope v6 back under ESLint via
151
- // overrides, which npm then nests. This lets both the backend
152
- // (`medusa db:migrate`/`build`) and the storefront (`next lint`) resolve a
153
- // compatible ajv from a single npm install.
154
- packageJson.devDependencies = {
155
- ...packageJson.devDependencies,
156
- ajv: "^8.13.0",
157
- };
158
- packageJson.overrides = {
159
- ...packageJson.overrides,
160
- eslint: {
161
- ...(packageJson.overrides?.eslint ?? {}),
162
- ajv: "^6.12.4",
163
- },
164
- "@eslint/eslintrc": {
165
- ...(packageJson.overrides?.["@eslint/eslintrc"] ?? {}),
166
- ajv: "^6.12.4",
167
- },
168
- };
169
- }
170
- async transformWorkspaceConfig(directory) {
171
- if (this.packageManager === "pnpm") {
172
- return;
173
- }
174
- const workspaceYamlPath = path.join(directory, "pnpm-workspace.yaml");
175
- if (!existsSync(workspaceYamlPath)) {
176
- return;
177
- }
178
- const yamlContent = readFileSync(workspaceYamlPath, "utf-8");
179
- const workspacePackages = parseYaml(yamlContent)?.packages ?? [];
180
- const packageJsonPath = path.join(directory, "package.json");
181
- const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
182
- packageJson.workspaces = workspacePackages;
183
- if (packageJson.scripts) {
184
- const pm = this.packageManager;
185
- packageJson.scripts = Object.fromEntries(Object.entries(packageJson.scripts).map(([key, value]) => [
186
- key,
187
- value
188
- .replace(/\bpnpm\s+-r\s+(\S+)/g, "turbo $1")
189
- .replace(/\bpnpm\b/g, pm),
190
- ]));
191
- }
192
- if (this.packageManager === "yarn") {
193
- this.applyYarnWorkspaceChanges(directory);
194
- }
195
- else if (this.packageManager === "npm") {
196
- this.applyNpmWorkspaceChanges(packageJson);
197
- }
198
- writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
199
- rmSync(workspaceYamlPath, { force: true });
200
- }
201
- async removeLockFiles(directory) {
202
- const lockFiles = {
203
- npm: ["yarn.lock", "pnpm-lock.yaml", ".yarn"],
204
- yarn: ["package-lock.json", "pnpm-lock.yaml"],
205
- pnpm: ["yarn.lock", "package-lock.json", ".yarn"],
206
- nub: ["yarn.lock", "package-lock.json", "pnpm-lock.yaml", ".yarn"],
207
- };
208
- if (!this.packageManager) {
209
- return;
210
- }
211
- const filesToRemove = lockFiles[this.packageManager] || [];
212
- for (const file of filesToRemove) {
213
- const filePath = path.join(directory, file);
214
- if (existsSync(filePath)) {
215
- rmSync(filePath, {
216
- force: true,
217
- recursive: true,
218
- });
219
- }
220
- }
221
- }
222
- async installDependencies(execOptions, installOptions) {
223
- if (!this.packageManager) {
224
- await this.setPackageManager(execOptions);
225
- }
226
- if (execOptions.cwd && typeof execOptions.cwd === "string") {
227
- await this.transformWorkspaceConfig(execOptions.cwd);
228
- await this.removeLockFiles(execOptions.cwd);
229
- }
230
- const commands = {
231
- yarn: "yarn",
232
- pnpm: "pnpm install",
233
- npm: `npm install${installOptions?.installLegacyPeerDeps ? " --legacy-peer-deps" : ""}`,
234
- nub: "nub install",
235
- };
236
- const command = commands[this.packageManager || "npm"];
237
- await this.processManager.runProcess({
238
- process: async () => {
239
- try {
240
- await execute([command, execOptions], {
241
- verbose: this.verbose,
242
- });
243
- }
244
- catch (error) {
245
- const errorStr = typeof error === "string"
246
- ? error
247
- : error?.stderr ||
248
- error?.message ||
249
- String(error);
250
- const packageManagerConflictMatch = errorStr.match(/This project is configured to use (\w+) because (.+) has a "packageManager" field/);
251
- if (this.packageManager === "pnpm" && packageManagerConflictMatch) {
252
- const conflictingFile = packageManagerConflictMatch[2];
253
- throw new Error(`Cannot install with pnpm because ${conflictingFile} has a "packageManager" field that specifies a different package manager. Consider removing that field from ${conflictingFile}, or create your Medusa project in a different directory.`);
254
- }
255
- throw error;
256
- }
257
- // For npm, run npm ci after npm install to validate installation
258
- if (this.packageManager === "npm") {
259
- try {
260
- await execute(["npm ci", execOptions], {
261
- verbose: this.verbose,
262
- });
263
- }
264
- catch (error) {
265
- // If npm ci fails, re-run npm install
266
- if (this.verbose) {
267
- logMessage({
268
- type: "info",
269
- message: "npm ci validation failed, re-running npm install...",
270
- });
271
- }
272
- await execute(["npm install", execOptions], {
273
- verbose: this.verbose,
274
- });
275
- }
276
- }
277
- },
278
- ignoreERESOLVE: true,
279
- });
280
- }
281
- async runCommand(command, execOptions, verboseOptions = {}) {
282
- if (!this.packageManager) {
283
- await this.setPackageManager(execOptions);
284
- }
285
- const commandStr = this.getCommandStr(command);
286
- return await this.processManager.runProcess({
287
- process: async () => {
288
- return await execute([commandStr, execOptions], {
289
- verbose: this.verbose,
290
- ...verboseOptions,
291
- });
292
- },
293
- ignoreERESOLVE: true,
294
- });
295
- }
296
- async runMedusaCommand(command, execOptions, verboseOptions = {}) {
297
- if (!this.packageManager) {
298
- await this.setPackageManager(execOptions);
299
- }
300
- const formats = {
301
- yarn: `yarn medusa ${command}`,
302
- pnpm: `pnpm medusa ${command}`,
303
- npm: `npx medusa ${command}`,
304
- nub: `nubx medusa ${command}`,
305
- };
306
- const commandStr = formats[this.packageManager || "npm"];
307
- return await this.processManager.runProcess({
308
- process: async () => {
309
- return await execute([commandStr, execOptions], {
310
- verbose: this.verbose,
311
- ...verboseOptions,
312
- });
313
- },
314
- ignoreERESOLVE: true,
315
- });
316
- }
317
- getCommandStr(command) {
318
- if (!this.packageManager) {
319
- throw new Error("Package manager not set");
320
- }
321
- const formats = {
322
- yarn: `yarn ${command}`,
323
- pnpm: `pnpm ${command}`,
324
- npm: `npm run ${command}`,
325
- nub: `nub run ${command}`,
326
- };
327
- return formats[this.packageManager];
328
- }
329
- getPackageManager() {
330
- return this.packageManager;
331
- }
332
- async getPackageManagerString() {
333
- if (!this.packageManager) {
334
- await this.setPackageManager({});
335
- }
336
- if (!this.packageManagerVersion) {
337
- if (this.verbose) {
338
- logMessage({
339
- type: "info",
340
- message: `No version detected for package manager: ${this.packageManager}`,
341
- });
342
- }
343
- return undefined;
344
- }
345
- const result = `${this.packageManager}@${this.packageManagerVersion}`;
346
- if (this.verbose) {
347
- logMessage({
348
- type: "info",
349
- message: `Package manager string: ${result}`,
350
- });
351
- }
352
- return result;
353
- }
354
- }
@@ -1,9 +0,0 @@
1
- import pg from "@medusajs/deps/pg";
2
- const { Client } = pg;
3
- export const DEFAULT_HOST = "localhost";
4
- export const DEFAULT_PORT = 5432;
5
- export default async (connect) => {
6
- const client = new Client(connect);
7
- await client.connect();
8
- return client;
9
- };