Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(optimizer): remove using resolvePackageData API from Vite #5312

Merged
merged 5 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/qwik/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"devDependencies": {
"@builder.io/qwik-dom": "workspace:*",
"image-size": "^1.0.2",
"kleur": "4.1.5"
"kleur": "4.1.5",
"vitefu": "^0.2.5"
},
"engines": {
"node": ">=16.8.0 <18.0.0 || >=18.11"
Expand Down
20 changes: 11 additions & 9 deletions packages/qwik/src/optimizer/src/plugins/vite.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { UserConfig, ViteDevServer, Plugin as VitePlugin } from 'vite';
import { findDepPkgJsonPath } from 'vitefu';
import { QWIK_LOADER_DEFAULT_DEBUG, QWIK_LOADER_DEFAULT_MINIFIED } from '../scripts';
import type {
EntryStrategy,
Expand Down Expand Up @@ -683,7 +684,6 @@ const findQwikRoots = async (
): Promise<QwikPackages[]> => {
if (sys.env === 'node') {
const fs: typeof import('fs') = await sys.dynamicImport('node:fs');
const { resolvePackageData }: typeof import('vite') = await sys.strictDynamicImport('vite');

try {
const data = await fs.promises.readFile(packageJsonPath, { encoding: 'utf-8' });
Expand All @@ -702,21 +702,23 @@ const findQwikRoots = async (
}

const basedir = sys.cwd();
const qwikDirs = packages
.map((id) => {
const pkgData = resolvePackageData(id, basedir);
if (pkgData) {
const qwikPath = pkgData.data['qwik'];
const qwikDirs = await Promise.all(
packages.map(async (id) => {
const pkgJsonPath = await findDepPkgJsonPath(id, basedir);
if (pkgJsonPath) {
const pkgJsonContent = await fs.promises.readFile(pkgJsonPath, 'utf-8');
const pkgJson = JSON.parse(pkgJsonContent);
const qwikPath = pkgJson['qwik'];
if (qwikPath) {
return {
id,
path: sys.path.resolve(pkgData.dir, qwikPath),
path: sys.path.resolve(sys.path.dirname(pkgJsonPath), qwikPath),
};
}
}
})
.filter(isNotNullable);
return qwikDirs;
);
return qwikDirs.filter(isNotNullable);
} catch (e) {
console.error(e);
}
Expand Down
11 changes: 7 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.