diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e0074e5..6b3b258e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ - [#694](https://github.com/estruyf/vscode-front-matter/issues/694): Start terminal session from the folder where the `frontmatter.json` file is located - [#696](https://github.com/estruyf/vscode-front-matter/issues/696): Close the local server terminal on restart - [#699](https://github.com/estruyf/vscode-front-matter/issues/699): Changing border theme variable for the dashboard header +- [#703](https://github.com/estruyf/vscode-front-matter/issues/703): Fix retrieval of Astro Collections for `pnpm` projects ## [9.3.1] - 2023-10-27 diff --git a/src/listeners/dashboard/SsgListener.ts b/src/listeners/dashboard/SsgListener.ts index 3460c386..29a3ce1a 100644 --- a/src/listeners/dashboard/SsgListener.ts +++ b/src/listeners/dashboard/SsgListener.ts @@ -9,6 +9,7 @@ import { SETTING_TAXONOMY_CONTENT_TYPES, SsgScripts } from '../../constants'; import { SettingsListener } from './SettingsListener'; import { Terminal } from '../../services'; import { existsAsync, readFileAsync } from '../../utils'; +import { join } from 'path'; export class SsgListener extends BaseListener { /** @@ -133,7 +134,28 @@ export class SsgListener extends BaseListener { const tempLocation = Uri.joinPath(wsFolder, '/.frontmatter/temp'); const tempScriptPath = Uri.joinPath(tempLocation, SsgScripts.astroContentCollectionScript); await workspace.fs.createDirectory(tempLocation); - workspace.fs.copy(scriptPath, tempScriptPath, { overwrite: true }); + + // Check if the workspace uses pnpm + if (await existsAsync(Uri.joinPath(wsFolder, 'node_modules/.pnpm').fsPath)) { + const vitePackageFiles = await workspace.findFiles( + `**/node_modules/.pnpm/vite@*/node_modules/vite/package.json` + ); + if (vitePackageFiles.length > 0) { + const vitePackageFile = vitePackageFiles[0]; + const vitePackage = JSON.parse(await readFileAsync(vitePackageFile.fsPath, 'utf8')) as { + main: string; + }; + const viteFolder = vitePackageFile.fsPath.replace('/package.json', ''); + const vitePath = join(viteFolder, vitePackage.main).replace(wsFolder.fsPath, '../..'); + + // Update the vite reference, as it is not a direct dependency of the project + let scriptContents = await readFileAsync(scriptPath.fsPath, 'utf8'); + scriptContents = scriptContents.replace(`"vite"`, `"${vitePath}"`); + await workspace.fs.writeFile(tempScriptPath, Buffer.from(scriptContents, 'utf8')); + } + } else { + workspace.fs.copy(scriptPath, tempScriptPath, { overwrite: true }); + } const fullScript = `node "${tempScriptPath.fsPath}" "${contentConfigFile.fsPath}"`; diff --git a/ssg-scripts/astro.collections.mjs b/ssg-scripts/astro.collections.mjs index 7603d2f8..f3ee8970 100644 --- a/ssg-scripts/astro.collections.mjs +++ b/ssg-scripts/astro.collections.mjs @@ -1,7 +1,7 @@ import { writeFileSync } from "fs"; import { join } from "path"; import { createServer } from "vite"; -import zod from "zod"; +import zod from "astro/zod"; const { ZodDefault,