Skip to content

Commit d9f5de1

Browse files
committed
chore: add version check code to not show warning on >=4.52
1 parent b97a62b commit d9f5de1

File tree

3 files changed

+54
-29
lines changed

3 files changed

+54
-29
lines changed

packages/qwik/src/optimizer/src/plugins/rollup.ts

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
type QwikPlugin,
1818
type QwikPluginOptions,
1919
} from './plugin';
20+
import { findDepPkgJsonPath } from './utils';
2021

2122
type QwikRollupPluginApi = {
2223
getOptimizer: () => Optimizer;
@@ -75,7 +76,7 @@ export function qwikRollup(qwikRollupOpts: QwikRollupPluginOptions = {}): any {
7576
},
7677

7778
outputOptions(rollupOutputOpts) {
78-
return normalizeRollupOutputOptionsObject(qwikPlugin, rollupOutputOpts, false);
79+
return normalizeRollupOutputOptionsObject(qwikPlugin, rollupOutputOpts, false) as any;
7980
},
8081

8182
async buildStart() {
@@ -150,11 +151,11 @@ export function normalizeRollupOutputOptions(
150151
};
151152
}
152153

153-
export function normalizeRollupOutputOptionsObject(
154+
export async function normalizeRollupOutputOptionsObject(
154155
qwikPlugin: QwikPlugin,
155156
rollupOutputOptsObj: Rollup.OutputOptions | undefined,
156157
useAssetsDir: boolean
157-
): Rollup.OutputOptions {
158+
): Promise<Rollup.OutputOptions> {
158159
const outputOpts: Rollup.OutputOptions = { ...rollupOutputOptsObj };
159160
const opts = qwikPlugin.getOptions();
160161
const optimizer = qwikPlugin.getOptimizer();
@@ -252,10 +253,32 @@ export function normalizeRollupOutputOptionsObject(
252253
*/
253254
outputOpts.hoistTransitiveImports = false;
254255

255-
outputOpts.onlyExplicitManualChunks = true;
256-
console.warn(
257-
`⚠️ For the latest and greatest, we recommend to install rollup@^4.52.0 directly in your project. It enables the new Rollup \`outputOpts.onlyExplicitManualChunks\` feature flag, which improves preloading performance and reduces cache invalidation for a snappier user experience.`
258-
);
256+
const userPkgJsonPath = await findDepPkgJsonPath(optimizer.sys, 'rollup', optimizer.sys.cwd());
257+
if (userPkgJsonPath) {
258+
try {
259+
const fs: typeof import('fs') = await optimizer.sys.dynamicImport('node:fs');
260+
const pkgJsonStr = await fs.promises.readFile(userPkgJsonPath, 'utf-8');
261+
const pkgJson = JSON.parse(pkgJsonStr);
262+
const version = String(pkgJson?.version || '');
263+
const [major, minor, patch] = version.split('.').map((n: string) => parseInt(n, 10)) as [
264+
number,
265+
number,
266+
number,
267+
];
268+
const isGte452 =
269+
Number.isFinite(major) &&
270+
(major > 4 || (major === 4 && (minor > 52 || (minor === 52 && (patch || 0) >= 0))));
271+
if (isGte452) {
272+
outputOpts.onlyExplicitManualChunks = true;
273+
} else {
274+
console.warn(
275+
`⚠️ For the latest and greatest, we recommend to install rollup@^4.52.0 directly in your project. It enables the new Rollup \`outputOpts.onlyExplicitManualChunks\` feature flag, which improves preloading performance and reduces cache invalidation for a snappier user experience.`
276+
);
277+
}
278+
} catch {
279+
// If we cannot determine the installed Rollup version, avoid warning
280+
}
281+
}
259282

260283
return outputOpts;
261284
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type { OptimizerSystem } from '../types';
2+
3+
export async function findDepPkgJsonPath(sys: OptimizerSystem, dep: string, parent: string) {
4+
const fs: typeof import('fs') = await sys.dynamicImport('node:fs');
5+
let root = parent;
6+
while (root) {
7+
const pkg = sys.path.join(root, 'node_modules', dep, 'package.json');
8+
try {
9+
await fs.promises.access(pkg);
10+
// use 'node:fs' version to match 'vite:resolve' and avoid realpath.native quirk
11+
// https://github.com/sveltejs/vite-plugin-svelte/issues/525#issuecomment-1355551264
12+
return fs.promises.realpath(pkg);
13+
} catch {
14+
//empty
15+
}
16+
const nextRoot = sys.path.dirname(root);
17+
if (nextRoot === root) {
18+
break;
19+
}
20+
root = nextRoot;
21+
}
22+
return undefined;
23+
}

packages/qwik/src/optimizer/src/plugins/vite.ts

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
import { createRollupError, normalizeRollupOutputOptions } from './rollup';
3333
import { VITE_DEV_CLIENT_QS, configureDevServer, configurePreviewServer } from './vite-dev-server';
3434
import { parseId } from './vite-utils';
35+
import { findDepPkgJsonPath } from './utils';
3536

3637
const DEDUPE = [QWIK_CORE_ID, QWIK_JSX_RUNTIME_ID, QWIK_JSX_DEV_RUNTIME_ID];
3738

@@ -752,28 +753,6 @@ export async function render(document, rootNode, opts) {
752753
}`;
753754
}
754755

755-
async function findDepPkgJsonPath(sys: OptimizerSystem, dep: string, parent: string) {
756-
const fs: typeof import('fs') = await sys.dynamicImport('node:fs');
757-
let root = parent;
758-
while (root) {
759-
const pkg = sys.path.join(root, 'node_modules', dep, 'package.json');
760-
try {
761-
await fs.promises.access(pkg);
762-
// use 'node:fs' version to match 'vite:resolve' and avoid realpath.native quirk
763-
// https://github.com/sveltejs/vite-plugin-svelte/issues/525#issuecomment-1355551264
764-
return fs.promises.realpath(pkg);
765-
} catch {
766-
//empty
767-
}
768-
const nextRoot = sys.path.dirname(root);
769-
if (nextRoot === root) {
770-
break;
771-
}
772-
root = nextRoot;
773-
}
774-
return undefined;
775-
}
776-
777756
const findQwikRoots = async (
778757
sys: OptimizerSystem,
779758
packageJsonDir: string

0 commit comments

Comments
 (0)