Skip to content

Commit

Permalink
fix bug in cloning of repos, where worktree directory could not be cr… (
Browse files Browse the repository at this point in the history
#673)

* fix bug in cloning of repos, where worktree directory could not be created

* fix: remove `fsextra.access` to avoid possible race conditions

* use `PluginError` in DocumentAssetsPlugin
  • Loading branch information
mark-tate authored Oct 22, 2024
1 parent 99eee8c commit 3dcd0dc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/hungry-owls-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@jpmorganchase/mosaic-plugins': patch
---

Fix bug where `ensureDir` created a directory and broke the cloning of repos
23 changes: 12 additions & 11 deletions packages/plugins/src/DocumentAssetsPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import remarkParse from 'remark-parse';
import remarkMdx from 'remark-mdx';
import remarkStringify from 'remark-stringify';
import { VFile } from 'vfile';
import PluginError from './utils/PluginError.js';

interface DocumentAssetsPluginOptions {
/**
Expand Down Expand Up @@ -84,17 +85,16 @@ const DocumentAssetsPlugin: PluginType<Page, DocumentAssetsPluginOptions> = {
const resolvedSrcDir = path.resolve(srcDir);
const resolvedOutputDir = path.resolve(outputDir);
if (!resolvedOutputDir.startsWith(resolvedCwd)) {
throw new Error(`outputDir must be within the current working directory: ${outputDir}`);
throw new PluginError(
'outputDir must be within the current working directory',
resolvedOutputDir
);
}
await fsExtra.ensureDir(srcDir);
await fsExtra.ensureDir(outputDir);

for (const assetSubDir of assetSubDirs) {
const resolvedAssetSubDir = path.resolve(resolvedSrcDir, assetSubDir);
if (!resolvedAssetSubDir.startsWith(resolvedSrcDir)) {
console.log('ERROR 3');

throw new Error(`Asset subdirectory must be within srcDir: ${srcDir}`);
throw new PluginError('asset subdirectory must be within srcDir', resolvedAssetSubDir);
}

let globbedImageDirs;
Expand All @@ -103,15 +103,16 @@ const DocumentAssetsPlugin: PluginType<Page, DocumentAssetsPluginOptions> = {
cwd: resolvedSrcDir,
onlyDirectories: true
});
if (globbedImageDirs.length === 0) {
console.warn(`Warning: No entries found for ${assetSubDir}. It may not exist.`);
continue;
}
} catch (err) {
console.error(`Error globbing ${assetSubDir} in ${srcDir}:`, err);
continue;
}

if (globbedImageDirs?.length === 0) {
continue;
throw new PluginError(err.message, assetSubDir);
}

await fsExtra.ensureDir(outputDir);
for (const globbedImageDir of globbedImageDirs) {
let imageFiles;
let globbedPath;
Expand Down

0 comments on commit 3dcd0dc

Please sign in to comment.