Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions src/generators/web/generate.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

import { readFile } from 'node:fs/promises';
import { join } from 'node:path';
import { constants } from 'node:fs';
import { readFile, stat, cp, copyFile, mkdir } from 'node:fs/promises';
import { join, basename, dirname } from 'node:path';

import { processJSXEntries } from './utils/processing.mjs';
import getConfig from '../../utils/configuration/index.mjs';
Expand Down Expand Up @@ -39,6 +40,41 @@ export async function generate(input) {
}

await writeFile(join(config.output, 'styles.css'), css, 'utf-8');

if (Array.isArray(config.pathsToCopy)) {
for (const item of config.pathsToCopy) {
if (!item) {
continue;
}
const copyTasks =
typeof item === 'string'
? [{ src: item, dest: join(config.output, basename(item)) }]
: Object.entries(item).map(([src, dest]) => ({
src,
dest: join(config.output, dest.replace(/^[/\\]+/, '')),
}));
Comment thread
cursor[bot] marked this conversation as resolved.
Outdated

for (const { src, dest } of copyTasks) {
try {
const fileStats = await stat(src);

if (fileStats.isDirectory()) {
await cp(src, dest, { recursive: true, force: true });

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to check isDirectory()? Won't await cp(src, dest, { recursive: true, force: true }) work on files and folders?

@moshams272 moshams272 Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but the automated Cursor Bot previously flagged the use of cp for individual files.

#753 (comment)

} else {
await mkdir(dirname(dest), { recursive: true });
await copyFile(src, dest, constants.COPYFILE_FICLONE);
}
} catch (err) {
if (err.code !== 'ENOENT') {
console.error(
Comment thread
moshams272 marked this conversation as resolved.
Outdated
`Failed to copy asset from ${src} to ${dest}:`,
err
);
}
}
}
}
}
Comment thread
moshams272 marked this conversation as resolved.
Outdated
}

return results.map(({ html }) => ({ html: html.toString(), css }));
Expand Down
1 change: 1 addition & 0 deletions src/utils/configuration/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const getDefaultConfig = lazy(() =>
repository: 'nodejs/node',
ref: 'HEAD',
}),
pathsToCopy: ['assets', 'public', 'static'],
},

// The number of wasm memory instances is severely limited on
Expand Down
Loading