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
…eated
  • Loading branch information
mark-tate committed Oct 22, 2024
1 parent 99eee8c commit 37ffc62
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 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
14 changes: 9 additions & 5 deletions packages/plugins/src/DocumentAssetsPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ const DocumentAssetsPlugin: PluginType<Page, DocumentAssetsPluginOptions> = {
if (!resolvedOutputDir.startsWith(resolvedCwd)) {
throw new Error(`outputDir must be within the current working directory: ${outputDir}`);
}
await fsExtra.ensureDir(srcDir);
await fsExtra.ensureDir(outputDir);

for (const assetSubDir of assetSubDirs) {
const resolvedAssetSubDir = path.resolve(resolvedSrcDir, assetSubDir);
Expand All @@ -99,19 +97,25 @@ const DocumentAssetsPlugin: PluginType<Page, DocumentAssetsPluginOptions> = {

let globbedImageDirs;
try {
await fsExtra.access(resolvedSrcDir);
globbedImageDirs = await glob(assetSubDir, {
cwd: resolvedSrcDir,
onlyDirectories: true
});
} catch (err) {
console.error(`Error globbing ${assetSubDir} in ${srcDir}:`, err);
continue;
if (err.code === 'ENOENT') {
console.warn(`Warning: Directory ${resolvedSrcDir} does not exist.`);
} else {
console.error(`Error globbing ${assetSubDir} in ${srcDir}:`, err);
throw err;
}
}

if (globbedImageDirs?.length === 0) {
if (!globbedImageDirs || globbedImageDirs?.length === 0) {
continue;
}

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

0 comments on commit 37ffc62

Please sign in to comment.