diff --git a/.changeset/silver-readers-appear.md b/.changeset/silver-readers-appear.md new file mode 100644 index 00000000000..c5dbf44f1d7 --- /dev/null +++ b/.changeset/silver-readers-appear.md @@ -0,0 +1,5 @@ +--- +'create-qwik': patch +--- + +FIX: wrong version when creating a library diff --git a/scripts/create-qwik-cli.ts b/scripts/create-qwik-cli.ts index fc6623cbae6..b002a3c40c0 100644 --- a/scripts/create-qwik-cli.ts +++ b/scripts/create-qwik-cli.ts @@ -8,6 +8,7 @@ import { copyFile, emptyDir, getBanner, + getQwikVersion, mkdir, nodeTarget, readdir, @@ -91,10 +92,9 @@ export async function publishCreateQwikCli( } async function syncBaseStarterVersionsFromQwik(config: BuildConfig) { - const qwikDir = join(config.packagesDir, 'qwik'); - const distPkg = await readPackageJson(qwikDir); + const qwikVersion = await getQwikVersion(config); - await updateBaseVersions(config, distPkg.version); + await updateBaseVersions(config, qwikVersion); } async function updateBaseVersions(config: BuildConfig, version: string) { @@ -190,6 +190,7 @@ async function copyDir(config: BuildConfig, srcDir: string, destDir: string) { async function updatePackageJson(config: BuildConfig, destDir: string) { const rootPkg = await readPackageJson(config.rootDir); const pkgJson = await readPackageJson(destDir); + const qwikVersion = await getQwikVersion(config); const setVersionFromRoot = (pkgName: string) => { if (pkgJson.devDependencies && pkgJson.devDependencies[pkgName]) { @@ -205,12 +206,11 @@ async function updatePackageJson(config: BuildConfig, destDir: string) { }; if (pkgJson.devDependencies && pkgJson.devDependencies['@builder.io/qwik']) { - if ( - pkgJson.devDependencies['@builder.io/qwik'] !== 'next' && - pkgJson.devDependencies['@builder.io/qwik'] !== 'dev' - ) { - pkgJson.devDependencies['@builder.io/qwik'] = rootPkg.version; - } + pkgJson.devDependencies['@builder.io/qwik'] = qwikVersion; + } + + if (pkgJson.devDependencies && pkgJson.devDependencies['eslint-plugin-qwik']) { + pkgJson.devDependencies['eslint-plugin-qwik'] = qwikVersion; } setVersionFromRoot('@types/eslint'); diff --git a/scripts/util.ts b/scripts/util.ts index 06de37c6dbb..a06732c1718 100644 --- a/scripts/util.ts +++ b/scripts/util.ts @@ -1,23 +1,24 @@ import type { Plugin } from 'esbuild'; -import { join } from 'node:path'; +import { execa, type Options } from 'execa'; import mri from 'mri'; import { access as fsAccess, copyFile as fsCopyFile, - mkdirSync, + mkdir as fsMkdir, readdir as fsReaddir, readFile as fsReadFile, - rmSync, stat as fsStat, unlink as fsUnlink, writeFile as fsWriteFile, - mkdir as fsMkdir, + mkdirSync, + rmSync, } from 'node:fs'; -import { promisify } from 'util'; -import { minify, type MinifyOptions } from 'terser'; -import type { Plugin as RollupPlugin } from 'rollup'; -import { execa, type Options } from 'execa'; +import { join } from 'node:path'; import { fileURLToPath } from 'node:url'; +import type { Plugin as RollupPlugin } from 'rollup'; +import { minify, type MinifyOptions } from 'terser'; +import { promisify } from 'util'; +import { readPackageJson } from './package-json'; const stringOptions = [ 'distBindingsDir', @@ -358,3 +359,9 @@ export const recursiveChangePrefix = (obj: T, prefix: string, replace: string } return obj; }; + +export async function getQwikVersion(config: BuildConfig) { + const qwikDir = join(config.packagesDir, 'qwik'); + const qwikPkgJson = await readPackageJson(qwikDir); + return qwikPkgJson.version; +} diff --git a/scripts/validate-cli.ts b/scripts/validate-cli.ts index 117cae55b3c..29a7f0851de 100644 --- a/scripts/validate-cli.ts +++ b/scripts/validate-cli.ts @@ -30,6 +30,7 @@ async function validateCreateQwikCli() { const cliPkgJsonPath = join(cliDir, 'package.json'); const cliPkgJson = JSON.parse(readFileSync(cliPkgJsonPath, 'utf-8')); assert.strictEqual(cliPkgJson.name, 'create-qwik'); + const qwikVersion = cliPkgJson.version; const startersDir = join(cliDir, 'dist', 'starters'); accessSync(startersDir); @@ -44,9 +45,9 @@ async function validateCreateQwikCli() { const tmpDir = join(__dirname, '..', 'dist-dev'); await Promise.all([ - validateStarter(api, tmpDir, 'playground', true, `👻`), - validateStarter(api, tmpDir, 'empty', true, `🫙`), - validateStarter(api, tmpDir, 'library', false, `📚`), + validateStarter(api, tmpDir, 'playground', true, `👻`, qwikVersion), + validateStarter(api, tmpDir, 'empty', true, `🫙`, qwikVersion), + validateStarter(api, tmpDir, 'library', false, `📚`, qwikVersion), ]).catch((e) => { console.error(e); panic(String(e)); @@ -60,7 +61,8 @@ async function validateStarter( distDir: string, starterId: string, app: boolean, - emoji: string + emoji: string, + qwikVersion: string ) { const appDir = join(distDir, 'e2e-' + starterId); @@ -80,6 +82,8 @@ async function validateStarter( const appPkgJsonPath = join(result.outDir, 'package.json'); const appPkgJson = JSON.parse(readFileSync(appPkgJsonPath, 'utf-8')); + assertRightQwikDepsVersions(appPkgJson, qwikVersion, starterId); + // Ensure that npm will use an existing version appPkgJson.devDependencies['@builder.io/qwik'] = 'latest'; appPkgJson.devDependencies['@builder.io/qwik-city'] = 'latest'; @@ -143,6 +147,28 @@ async function validateStarter( console.log(`${emoji} ${starterId} validated\n`); } +function assertRightQwikDepsVersions(appPkgJson: any, qwikVersion: string, starterType: string) { + assert.strictEqual( + appPkgJson.devDependencies['@builder.io/qwik'].includes(qwikVersion), + true, + `Qwik version mismatch for "${starterType}" starter` + ); + if (appPkgJson.devDependencies.hasOwnProperty('@builder.io/qwik-city')) { + assert.strictEqual( + appPkgJson.devDependencies['@builder.io/qwik-city'].includes(qwikVersion), + true, + `Qwik City version mismatch for "${starterType}" starter` + ); + } + if (appPkgJson.devDependencies.hasOwnProperty('eslint-plugin-qwik')) { + assert.strictEqual( + appPkgJson.devDependencies['eslint-plugin-qwik'].includes(qwikVersion), + true, + `ESlint plugin version mismatch for "${starterType}" starter` + ); + } +} + function cpSync(src: string, dest: string) { // cpSync() not available until Node v16.7.0 try {