Plugins: Force POSIX style path separators for manifest generation (#30287)

* force POSIX style path separators

* include posix style for symbolic links

* include in error string
This commit is contained in:
Will Browne
2021-01-19 15:26:50 +01:00
committed by GitHub
parent 2638a43337
commit ffd86f2a5b

View File

@@ -7,19 +7,22 @@ const MANIFEST_FILE = 'MANIFEST.txt';
async function* walk(dir: string, baseDir: string): AsyncGenerator<string, any, any> {
for await (const d of await (fs.promises as any).opendir(dir)) {
const entry = path.join(dir, d.name);
const entry = path.posix.join(dir, d.name);
if (d.isDirectory()) {
yield* await walk(entry, baseDir);
} else if (d.isFile()) {
yield path.relative(baseDir, entry);
yield path.posix.relative(baseDir, entry);
} else if (d.isSymbolicLink()) {
const realPath = fs.realpathSync(entry);
if (!realPath.startsWith(baseDir)) {
throw new Error(
`symbolic link ${path.relative(baseDir, entry)} targets a file outside of the base directory: ${baseDir}`
`symbolic link ${path.posix.relative(
baseDir,
entry
)} targets a file outside of the base directory: ${baseDir}`
);
}
yield path.relative(baseDir, entry);
yield path.posix.relative(baseDir, entry);
}
}
}