Skip to content

Commit d4cd48e

Browse files
committed
chore(ignore-failure): ignore copy failures
1 parent 179ca04 commit d4cd48e

File tree

2 files changed

+26
-56
lines changed

2 files changed

+26
-56
lines changed

src/generators/legacy-html/index.mjs

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
'use strict';
22

3-
import { readFile, rm, writeFile, mkdir } from 'node:fs/promises';
3+
import { cp, readFile, rm, writeFile } from 'node:fs/promises';
44
import { join } from 'node:path';
55

66
import HTMLMinifier from '@minify-html/node';
77

88
import buildContent from './utils/buildContent.mjs';
99
import dropdowns from './utils/buildDropdowns.mjs';
10-
import { safeCopy } from './utils/safeCopy.mjs';
1110
import tableOfContents from './utils/tableOfContents.mjs';
1211
import { groupNodesByModule } from '../../utils/generators.mjs';
1312
import { getRemarkRehype } from '../../utils/remark.mjs';
@@ -170,22 +169,31 @@ export default {
170169
}
171170

172171
if (output) {
173-
// Define the source folder for API docs assets
174-
const srcAssets = join(baseDir, 'assets');
175-
176-
// Define the output folder for API docs assets
177-
const assetsFolder = join(output, 'assets');
178-
179-
// Removes the current assets directory to copy the new assets
180-
// and prevent stale assets from existing in the output directory
181-
// If the path does not exists, it will simply ignore and continue
182-
await rm(assetsFolder, { recursive: true, force: true, maxRetries: 10 });
183-
184-
// Creates the assets folder if it does not exist
185-
await mkdir(assetsFolder, { recursive: true });
186-
187-
// Copy all files from assets folder to output, skipping unchanged files
188-
await safeCopy(srcAssets, assetsFolder);
172+
try {
173+
// Define the output folder for API docs assets
174+
const assetsFolder = join(output, 'assets');
175+
176+
// Removes the current assets directory to copy the new assets
177+
// and prevent stale assets from existing in the output directory
178+
// If the path does not exists, it will simply ignore and continue
179+
await rm(assetsFolder, {
180+
recursive: true,
181+
force: true,
182+
maxRetries: 10,
183+
});
184+
185+
// We copy all the other assets to the output folder at the end of the process
186+
// to ensure that all latest changes on the styles are applied to the output
187+
// Note.: This is not meant to be used for DX/developer purposes.
188+
await cp(join(baseDir, 'assets'), assetsFolder, {
189+
recursive: true,
190+
force: true,
191+
});
192+
} finally {
193+
// There's a chance that this step will fail when being run in parallel, since
194+
// the generators will all attempt to modify the same files at the same time.
195+
// In that scenario, we just want to ignore the potential failure.
196+
}
189197
}
190198

191199
return generatedValues;

src/generators/legacy-html/utils/safeCopy.mjs

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)