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

chore(qwik-insights): use clientOutDir if provided #5366

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion packages/docs/src/routes/api/qwik-optimizer/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@
}
],
"kind": "Interface",
"content": "```typescript\nexport interface QwikVitePluginApi \n```\n\n\n| Property | Modifiers | Type | Description |\n| --- | --- | --- | --- |\n| [getClientOutDir](#) | | () => string \\| null | |\n| [getClientPublicOutDir](#) | | () => string \\| null | |\n| [getInsightsManifest](#) | | () => Promise<[InsightManifest](#insightmanifest) \\| null> | |\n| [getManifest](#) | | () => [QwikManifest](#qwikmanifest) \\| null | |\n| [getOptimizer](#) | | () => [Optimizer](#optimizer) \\| null | |\n| [getOptions](#) | | () => NormalizedQwikPluginOptions | |\n| [getRootDir](#) | | () => string \\| null | |",
"content": "```typescript\nexport interface QwikVitePluginApi \n```\n\n\n| Property | Modifiers | Type | Description |\n| --- | --- | --- | --- |\n| [getClientOutDir](#) | | () => string \\| null | |\n| [getClientPublicOutDir](#) | | () => string \\| null | |\n| [getInsightsManifest](#) | | (clientOutDir?: string \\| null) => Promise<[InsightManifest](#insightmanifest) \\| null> | |\n| [getManifest](#) | | () => [QwikManifest](#qwikmanifest) \\| null | |\n| [getOptimizer](#) | | () => [Optimizer](#optimizer) \\| null | |\n| [getOptions](#) | | () => NormalizedQwikPluginOptions | |\n| [getRootDir](#) | | () => string \\| null | |",
"editUrl": "https://github.com/BuilderIO/qwik/tree/main/packages/qwik/src/optimizer/src/plugins/vite.ts",
"mdFile": "qwik.qwikvitepluginapi.md"
},
Expand Down
18 changes: 9 additions & 9 deletions packages/docs/src/routes/api/qwik-optimizer/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -515,15 +515,15 @@ export interface QwikVitePlugin
export interface QwikVitePluginApi
```

| Property | Modifiers | Type | Description |
| -------------------------- | --------- | ------------------------------------------------------------------- | ----------- |
| [getClientOutDir](#) | | () => string \| null | |
| [getClientPublicOutDir](#) | | () => string \| null | |
| [getInsightsManifest](#) | | () => Promise<[InsightManifest](#insightmanifest) \| null> | |
| [getManifest](#) | | () => [QwikManifest](#qwikmanifest) \| null | |
| [getOptimizer](#) | | () => [Optimizer](#optimizer) \| null | |
| [getOptions](#) | | () => NormalizedQwikPluginOptions | |
| [getRootDir](#) | | () => string \| null | |
| Property | Modifiers | Type | Description |
| -------------------------- | --------- | ------------------------------------------------------------------------------------------------ | ----------- |
| [getClientOutDir](#) | | () => string \| null | |
| [getClientPublicOutDir](#) | | () => string \| null | |
| [getInsightsManifest](#) | | (clientOutDir?: string \| null) => Promise<[InsightManifest](#insightmanifest) \| null> | |
| [getManifest](#) | | () => [QwikManifest](#qwikmanifest) \| null | |
| [getOptimizer](#) | | () => [Optimizer](#optimizer) \| null | |
| [getOptions](#) | | () => NormalizedQwikPluginOptions | |
| [getRootDir](#) | | () => string \| null | |

[Edit this section](https://github.com/BuilderIO/qwik/tree/main/packages/qwik/src/optimizer/src/plugins/vite.ts)

Expand Down
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
2 changes: 1 addition & 1 deletion packages/qwik/src/optimizer/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ export interface QwikVitePluginApi {
// (undocumented)
getClientPublicOutDir: () => string | null;
// (undocumented)
getInsightsManifest: () => Promise<InsightManifest | null>;
getInsightsManifest: (clientOutDir?: string | null) => Promise<InsightManifest | null>;
// (undocumented)
getManifest: () => QwikManifest | null;
// (undocumented)
Expand Down
12 changes: 7 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,9 @@ 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 +873,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
Loading