From 3dcd0dc0c580f5228ad914cfc5156b491ca8f912 Mon Sep 17 00:00:00 2001 From: mark-tate <143323+mark-tate@users.noreply.github.com> Date: Tue, 22 Oct 2024 17:53:42 +0100 Subject: [PATCH] =?UTF-8?q?fix=20bug=20in=20cloning=20of=20repos,=20where?= =?UTF-8?q?=20worktree=20directory=20could=20not=20be=20cr=E2=80=A6=20(#67?= =?UTF-8?q?3)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- .changeset/hungry-owls-jump.md | 5 +++++ packages/plugins/src/DocumentAssetsPlugin.ts | 23 ++++++++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) create mode 100644 .changeset/hungry-owls-jump.md diff --git a/.changeset/hungry-owls-jump.md b/.changeset/hungry-owls-jump.md new file mode 100644 index 00000000..b54b1c97 --- /dev/null +++ b/.changeset/hungry-owls-jump.md @@ -0,0 +1,5 @@ +--- +'@jpmorganchase/mosaic-plugins': patch +--- + +Fix bug where `ensureDir` created a directory and broke the cloning of repos diff --git a/packages/plugins/src/DocumentAssetsPlugin.ts b/packages/plugins/src/DocumentAssetsPlugin.ts index 88a2d338..55e04d19 100644 --- a/packages/plugins/src/DocumentAssetsPlugin.ts +++ b/packages/plugins/src/DocumentAssetsPlugin.ts @@ -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 { /** @@ -84,17 +85,16 @@ const DocumentAssetsPlugin: PluginType = { 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; @@ -103,15 +103,16 @@ const DocumentAssetsPlugin: PluginType = { 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;