Skip to content

Commit

Permalink
fix: use clientOutDir if provided for qwik-insights consumption
Browse files Browse the repository at this point in the history
  • Loading branch information
intellix committed Oct 30, 2023
1 parent f1b69ec commit cd3818c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/qwik-city/buildtime/vite/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ function qwikCityPlugin(userOpts?: QwikCityVitePluginOptions): any {
if (ctx?.target === 'ssr') {
// ssr build
const manifest = qwikPlugin!.api.getManifest();
const insightsManifest = await qwikPlugin!.api.getInsightsManifest();
const clientOutDir = qwikPlugin!.api.getClientOutDir();
const insightsManifest = await qwikPlugin!.api.getInsightsManifest(clientOutDir);

if (manifest && clientOutDir) {
const basePathRelDir = api.getBasePathname().replace(/^\/|\/$/, '');
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik-labs/src-vite/insights/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function qwikInsights(qwikInsightsOpts: {
logWarn('fail to fetch manifest from Insights DB');
}
if (!existsSync(join(process.cwd(), outDir))) {
mkdirSync(join(process.cwd(), outDir));
mkdirSync(join(process.cwd(), outDir), { recursive: true });
}
await writeFile(join(process.cwd(), outDir, 'q-insights.json'), JSON.stringify(qManifest));
}
Expand Down
10 changes: 5 additions & 5 deletions packages/qwik/src/optimizer/src/plugins/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ export function qwikVite(qwikViteOpts: QwikVitePluginOptions = {}): any {
const injections: GlobalInjections[] = [];
const qwikPlugin = createPlugin(qwikViteOpts.optimizerOptions);

async function loadQwikInsights(): Promise<InsightManifest | null> {
async function loadQwikInsights(clientOutDir?: string | null): Promise<InsightManifest | null> {
const sys = qwikPlugin.getSys();
const fs: typeof import('fs') = await sys.dynamicImport('node:fs');
const path = sys.path.join(process.cwd(), 'dist', 'q-insights.json');
const path = sys.path.join(process.cwd(), clientOutDir ?? 'dist', 'q-insights.json');
if (fs.existsSync(path)) {
return JSON.parse(await fs.promises.readFile(path, 'utf-8')) as InsightManifest;
}
Expand All @@ -70,7 +70,7 @@ export function qwikVite(qwikViteOpts: QwikVitePluginOptions = {}): any {
getOptimizer: () => qwikPlugin.getOptimizer(),
getOptions: () => qwikPlugin.getOptions(),
getManifest: () => manifestInput,
getInsightsManifest: () => loadQwikInsights(),
getInsightsManifest: (clientOutDir?: string | null) => loadQwikInsights(clientOutDir),
getRootDir: () => qwikPlugin.getOptions().rootDir,
getClientOutDir: () => clientOutDir,
getClientPublicOutDir: () => clientPublicOutDir,
Expand Down Expand Up @@ -118,7 +118,7 @@ export function qwikVite(qwikViteOpts: QwikVitePluginOptions = {}): any {

if (sys.env === 'node' && !qwikViteOpts.entryStrategy) {
try {
const entryStrategy = await loadQwikInsights();
const entryStrategy = await loadQwikInsights(!qwikViteOpts.csr ? qwikViteOpts.client?.outDir : undefined);
if (entryStrategy) {
qwikViteOpts.entryStrategy = entryStrategy;
}
Expand Down Expand Up @@ -871,7 +871,7 @@ export interface QwikVitePluginApi {
getOptimizer: () => Optimizer | null;
getOptions: () => NormalizedQwikPluginOptions;
getManifest: () => QwikManifest | null;
getInsightsManifest: () => Promise<InsightManifest | null>;
getInsightsManifest: (clientOutDir?: string | null) => Promise<InsightManifest | null>;
getRootDir: () => string | null;
getClientOutDir: () => string | null;
getClientPublicOutDir: () => string | null;
Expand Down

0 comments on commit cd3818c

Please sign in to comment.