#703 - fix pnpm support in astro script

This commit is contained in:
Elio Struyf
2023-11-09 14:15:43 -08:00
parent cef607ffc8
commit 8db76abf51
3 changed files with 25 additions and 2 deletions
+1
View File
@@ -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
+23 -1
View File
@@ -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}"`;
+1 -1
View File
@@ -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,