Skip to content

Commit

Permalink
fixed library starter wrong Qwik version
Browse files Browse the repository at this point in the history
  • Loading branch information
shairez committed Aug 2, 2024
1 parent 1c2692e commit 5d7a0cd
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .changeset/silver-readers-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-qwik': patch
---

FIX: wrong version when creating a library
18 changes: 9 additions & 9 deletions scripts/create-qwik-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
copyFile,
emptyDir,
getBanner,
getQwikVersion,
mkdir,
nodeTarget,
readdir,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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]) {
Expand All @@ -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');
Expand Down
23 changes: 15 additions & 8 deletions scripts/util.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -358,3 +359,9 @@ export const recursiveChangePrefix = <T>(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;
}
34 changes: 30 additions & 4 deletions scripts/validate-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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));
Expand All @@ -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);

Expand All @@ -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';
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 5d7a0cd

Please sign in to comment.