Skip to content

Commit 16c36da

Browse files
authored
fix(cli): library starter wrong Qwik version (#6757)
1 parent 1c2692e commit 16c36da

File tree

4 files changed

+59
-21
lines changed

4 files changed

+59
-21
lines changed

.changeset/silver-readers-appear.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'create-qwik': patch
3+
---
4+
5+
FIX: wrong version when creating a library

scripts/create-qwik-cli.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
copyFile,
99
emptyDir,
1010
getBanner,
11+
getQwikVersion,
1112
mkdir,
1213
nodeTarget,
1314
readdir,
@@ -91,10 +92,9 @@ export async function publishCreateQwikCli(
9192
}
9293

9394
async function syncBaseStarterVersionsFromQwik(config: BuildConfig) {
94-
const qwikDir = join(config.packagesDir, 'qwik');
95-
const distPkg = await readPackageJson(qwikDir);
95+
const qwikVersion = await getQwikVersion(config);
9696

97-
await updateBaseVersions(config, distPkg.version);
97+
await updateBaseVersions(config, qwikVersion);
9898
}
9999

100100
async function updateBaseVersions(config: BuildConfig, version: string) {
@@ -190,6 +190,7 @@ async function copyDir(config: BuildConfig, srcDir: string, destDir: string) {
190190
async function updatePackageJson(config: BuildConfig, destDir: string) {
191191
const rootPkg = await readPackageJson(config.rootDir);
192192
const pkgJson = await readPackageJson(destDir);
193+
const qwikVersion = await getQwikVersion(config);
193194

194195
const setVersionFromRoot = (pkgName: string) => {
195196
if (pkgJson.devDependencies && pkgJson.devDependencies[pkgName]) {
@@ -205,12 +206,11 @@ async function updatePackageJson(config: BuildConfig, destDir: string) {
205206
};
206207

207208
if (pkgJson.devDependencies && pkgJson.devDependencies['@builder.io/qwik']) {
208-
if (
209-
pkgJson.devDependencies['@builder.io/qwik'] !== 'next' &&
210-
pkgJson.devDependencies['@builder.io/qwik'] !== 'dev'
211-
) {
212-
pkgJson.devDependencies['@builder.io/qwik'] = rootPkg.version;
213-
}
209+
pkgJson.devDependencies['@builder.io/qwik'] = qwikVersion;
210+
}
211+
212+
if (pkgJson.devDependencies && pkgJson.devDependencies['eslint-plugin-qwik']) {
213+
pkgJson.devDependencies['eslint-plugin-qwik'] = qwikVersion;
214214
}
215215

216216
setVersionFromRoot('@types/eslint');

scripts/util.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
import type { Plugin } from 'esbuild';
2-
import { join } from 'node:path';
2+
import { execa, type Options } from 'execa';
33
import mri from 'mri';
44
import {
55
access as fsAccess,
66
copyFile as fsCopyFile,
7-
mkdirSync,
7+
mkdir as fsMkdir,
88
readdir as fsReaddir,
99
readFile as fsReadFile,
10-
rmSync,
1110
stat as fsStat,
1211
unlink as fsUnlink,
1312
writeFile as fsWriteFile,
14-
mkdir as fsMkdir,
13+
mkdirSync,
14+
rmSync,
1515
} from 'node:fs';
16-
import { promisify } from 'util';
17-
import { minify, type MinifyOptions } from 'terser';
18-
import type { Plugin as RollupPlugin } from 'rollup';
19-
import { execa, type Options } from 'execa';
16+
import { join } from 'node:path';
2017
import { fileURLToPath } from 'node:url';
18+
import type { Plugin as RollupPlugin } from 'rollup';
19+
import { minify, type MinifyOptions } from 'terser';
20+
import { promisify } from 'util';
21+
import { readPackageJson } from './package-json';
2122

2223
const stringOptions = [
2324
'distBindingsDir',
@@ -358,3 +359,9 @@ export const recursiveChangePrefix = <T>(obj: T, prefix: string, replace: string
358359
}
359360
return obj;
360361
};
362+
363+
export async function getQwikVersion(config: BuildConfig) {
364+
const qwikDir = join(config.packagesDir, 'qwik');
365+
const qwikPkgJson = await readPackageJson(qwikDir);
366+
return qwikPkgJson.version;
367+
}

scripts/validate-cli.ts

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ async function validateCreateQwikCli() {
3030
const cliPkgJsonPath = join(cliDir, 'package.json');
3131
const cliPkgJson = JSON.parse(readFileSync(cliPkgJsonPath, 'utf-8'));
3232
assert.strictEqual(cliPkgJson.name, 'create-qwik');
33+
const qwikVersion = cliPkgJson.version;
3334

3435
const startersDir = join(cliDir, 'dist', 'starters');
3536
accessSync(startersDir);
@@ -44,9 +45,9 @@ async function validateCreateQwikCli() {
4445
const tmpDir = join(__dirname, '..', 'dist-dev');
4546

4647
await Promise.all([
47-
validateStarter(api, tmpDir, 'playground', true, `👻`),
48-
validateStarter(api, tmpDir, 'empty', true, `🫙`),
49-
validateStarter(api, tmpDir, 'library', false, `📚`),
48+
validateStarter(api, tmpDir, 'playground', true, `👻`, qwikVersion),
49+
validateStarter(api, tmpDir, 'empty', true, `🫙`, qwikVersion),
50+
validateStarter(api, tmpDir, 'library', false, `📚`, qwikVersion),
5051
]).catch((e) => {
5152
console.error(e);
5253
panic(String(e));
@@ -60,7 +61,8 @@ async function validateStarter(
6061
distDir: string,
6162
starterId: string,
6263
app: boolean,
63-
emoji: string
64+
emoji: string,
65+
qwikVersion: string
6466
) {
6567
const appDir = join(distDir, 'e2e-' + starterId);
6668

@@ -80,6 +82,8 @@ async function validateStarter(
8082
const appPkgJsonPath = join(result.outDir, 'package.json');
8183
const appPkgJson = JSON.parse(readFileSync(appPkgJsonPath, 'utf-8'));
8284

85+
assertRightQwikDepsVersions(appPkgJson, qwikVersion, starterId);
86+
8387
// Ensure that npm will use an existing version
8488
appPkgJson.devDependencies['@builder.io/qwik'] = 'latest';
8589
appPkgJson.devDependencies['@builder.io/qwik-city'] = 'latest';
@@ -143,6 +147,28 @@ async function validateStarter(
143147
console.log(`${emoji} ${starterId} validated\n`);
144148
}
145149

150+
function assertRightQwikDepsVersions(appPkgJson: any, qwikVersion: string, starterType: string) {
151+
assert.strictEqual(
152+
appPkgJson.devDependencies['@builder.io/qwik'].includes(qwikVersion),
153+
true,
154+
`Qwik version mismatch for "${starterType}" starter`
155+
);
156+
if (appPkgJson.devDependencies.hasOwnProperty('@builder.io/qwik-city')) {
157+
assert.strictEqual(
158+
appPkgJson.devDependencies['@builder.io/qwik-city'].includes(qwikVersion),
159+
true,
160+
`Qwik City version mismatch for "${starterType}" starter`
161+
);
162+
}
163+
if (appPkgJson.devDependencies.hasOwnProperty('eslint-plugin-qwik')) {
164+
assert.strictEqual(
165+
appPkgJson.devDependencies['eslint-plugin-qwik'].includes(qwikVersion),
166+
true,
167+
`ESlint plugin version mismatch for "${starterType}" starter`
168+
);
169+
}
170+
}
171+
146172
function cpSync(src: string, dest: string) {
147173
// cpSync() not available until Node v16.7.0
148174
try {

0 commit comments

Comments
 (0)