Skip to content

Commit a31b5ff

Browse files
committed
fix(plugin-git): make the SPA copy robust to Next export file modes
Next's static export emits entries with restrictive modes that node's cpSync inherits and then trips over (EACCES); recreate the tree with explicit directory/file permissions instead.
1 parent 174b8bc commit a31b5ff

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

plugins/git/scripts/build-spa.mjs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
1-
import { cpSync, rmSync } from 'node:fs'
1+
import { copyFileSync, mkdirSync, readdirSync, rmSync } from 'node:fs'
2+
import { join } from 'node:path'
23

34
// The Next.js static export is the plugin's iframe SPA; it ships in the
45
// lockstep `@devframes/plugin-git--assets` package, not the node package.
6+
7+
// A manual walk with explicit modes: Next's export emits entries with
8+
// restrictive modes that node's `cpSync` inherits and then trips over, so
9+
// recreate the tree with normal directory/file permissions instead.
10+
function copyTree(src, dest) {
11+
mkdirSync(dest, { recursive: true, mode: 0o755 })
12+
for (const entry of readdirSync(src, { withFileTypes: true })) {
13+
const from = join(src, entry.name)
14+
const to = join(dest, entry.name)
15+
if (entry.isDirectory())
16+
copyTree(from, to)
17+
else if (entry.isFile())
18+
copyFileSync(from, to)
19+
}
20+
}
21+
522
rmSync('assets-pkg/dist', { recursive: true, force: true })
6-
cpSync('app/out', 'assets-pkg/dist', { recursive: true })
23+
copyTree('app/out', 'assets-pkg/dist')

0 commit comments

Comments
 (0)