diff --git a/package.json b/package.json index 1256edc3e8a4..97bba7ade95a 100644 --- a/package.json +++ b/package.json @@ -89,18 +89,18 @@ "overrides": { "@types/react": "^18", "@types/react-dom": "^18", - "@modern-js/codesmith-api-app":"0.0.0-canary-20241014021243", - "@modern-js/codesmith-api-ejs":"0.0.0-canary-20241014021243", - "@modern-js/codesmith-api-fs":"0.0.0-canary-20241014021243", - "@modern-js/codesmith-api-git":"0.0.0-canary-20241014021243", - "@modern-js/codesmith-api-handlebars":"0.0.0-canary-20241014021243", - "@modern-js/codesmith-api-json":"0.0.0-canary-20241014021243", - "@modern-js/codesmith-api-npm":"0.0.0-canary-20241014021243", - "@modern-js/codesmith-cli":"0.0.0-canary-20241014021243", - "@modern-js/codesmith-formily":"0.0.0-canary-20241014021243", - "@modern-js/codesmith":"0.0.0-canary-20241014021243", - "@modern-js/inquirer-types":"0.0.0-canary-20241014021243", - "@modern-js/codesmith-utils":"0.0.0-canary-20241014021243" + "@modern-js/codesmith-api-app":"0.0.0-canary-20241014055716", + "@modern-js/codesmith-api-ejs":"0.0.0-canary-20241014055716", + "@modern-js/codesmith-api-fs":"0.0.0-canary-20241014055716", + "@modern-js/codesmith-api-git":"0.0.0-canary-20241014055716", + "@modern-js/codesmith-api-handlebars":"0.0.0-canary-20241014055716", + "@modern-js/codesmith-api-json":"0.0.0-canary-20241014055716", + "@modern-js/codesmith-api-npm":"0.0.0-canary-20241014055716", + "@modern-js/codesmith-cli":"0.0.0-canary-20241014055716", + "@modern-js/codesmith-formily":"0.0.0-canary-20241014055716", + "@modern-js/codesmith":"0.0.0-canary-20241014055716", + "@modern-js/inquirer-types":"0.0.0-canary-20241014055716", + "@modern-js/codesmith-utils":"0.0.0-canary-20241014055716" }, "peerDependencyRules": { "allowedVersions": { diff --git a/packages/generator/generator-utils/src/index.ts b/packages/generator/generator-utils/src/index.ts index 41be12bc8209..2fb18dc1fc95 100644 --- a/packages/generator/generator-utils/src/index.ts +++ b/packages/generator/generator-utils/src/index.ts @@ -1,15 +1,12 @@ import path from 'path'; import type { GeneratorContext } from '@modern-js/codesmith'; -import { execa } from '@modern-js/codesmith-utils/execa'; +import { getNpmVersion, getPackageInfo } from '@modern-js/codesmith'; import { fs } from '@modern-js/codesmith-utils/fs-extra'; -import { canUseNpm, canUsePnpm } from '@modern-js/codesmith-utils/npm'; -import { ora } from '@modern-js/codesmith-utils/ora'; import { Solution, SolutionToolsMap } from '@modern-js/generator-common'; import { i18n, localeKeys } from './locale'; import { fileExist } from './utils/fsExist'; import { getMonorepoPackages } from './utils/monorepo'; import { getAvailableVersion, isPackageExist } from './utils/package'; -import { stripAnsi } from './utils/stripAnsi'; export * from './utils'; @@ -28,32 +25,10 @@ export { i18n } from './locale'; export async function getPackageVersion( packageName: string, - registry?: string, -) { - const spinner = ora({ - text: 'Load Generator...', - spinner: 'runner', - }).start(); - if (await canUsePnpm()) { - const args = ['info', packageName, 'version']; - if (registry) { - args.push(`--registry=${registry}`); - } - const result = await execa('pnpm', args); - spinner.stop(); - return stripAnsi(result.stdout); - } - if (await canUseNpm()) { - const args = ['view', packageName, 'version']; - if (registry) { - args.push(`--registry=${registry}`); - } - const result = await execa('npm', args); - spinner.stop(); - return stripAnsi(result.stdout); - } - spinner.stop(); - throw new Error('not found npm, please install npm before'); + registryUrl = '', +): Promise { + const { name, version } = getPackageInfo(packageName); + return getNpmVersion(name, { version, registryUrl }); } export async function getModernVersion( diff --git a/packages/generator/generators/repo-generator/src/index.ts b/packages/generator/generators/repo-generator/src/index.ts index 0c543c8bc445..e640a81c34da 100644 --- a/packages/generator/generators/repo-generator/src/index.ts +++ b/packages/generator/generators/repo-generator/src/index.ts @@ -90,6 +90,18 @@ const handlePlugin = async ( export default async (context: GeneratorContext, generator: GeneratorCore) => { process.setMaxListeners(20); + const { distTag } = context.config; + + // avoid create tools version is older + await generator.prepareGlobal(); + await generator.prepareGenerators([ + `@modern-js/repo-generator@${distTag || 'latest'}`, + `@modern-js/base-generator@${distTag || 'latest'}`, + `@modern-js/mwa-generator@${distTag || 'latest'}`, + `@modern-js/entry-generator@${distTag || 'latest'}`, + `@modern-js/module-generator@${distTag || 'latest'}`, + ]); + const appApi = new AppAPI(context, generator); const { locale } = context.config;