Compare commits

...

6 Commits

Author SHA1 Message Date
igorklopov
a18be9a136 a comment 2021-12-01 16:59:26 +03:00
igorklopov
230280a337 lesser diff 2021-12-01 16:56:19 +03:00
igorklopov
a36e20ef30 finish the test 2021-12-01 16:32:33 +03:00
igorklopov
17208e516c the fix 2021-12-01 16:25:34 +03:00
igorklopov
b0ad28be2d loosen + new test 2021-12-01 16:00:19 +03:00
igorklopov
3e761b04d4 [build-utils] ignore symlinked directories in glob 2021-12-01 15:13:37 +03:00
6 changed files with 47 additions and 0 deletions

View File

@@ -39,9 +39,30 @@ export default async function glob(
options.symlinks = {};
options.statCache = {};
options.cache = {};
options.stat = true;
options.dot = true;
await vanillaGlob(pattern, options); // populates the caches
for (const [ abs, isSym ] of Object.entries(options.symlinks)) { // vercel/40180cd6-path0/node_modules/next-site is a symlink
if (isSym) {
const sc = options.statCache[abs]!;
if (sc && sc.isDirectory()) { // ... and also a directory
// console.log('dir+sym', abs);
const c = options.cache[abs];
if (Array.isArray(c)) {
for (const sub of c) {
// suppressing it's content entries prevents the second run of vanillaGlob from following it
options.cache[path.join(abs, sub)] = false;
}
}
}
}
}
const files = await vanillaGlob(pattern, options);
for (const relativePath of files) {

View File

@@ -0,0 +1 @@
contents

View File

@@ -0,0 +1 @@
contents

View File

@@ -0,0 +1 @@
a.txt

View File

@@ -0,0 +1 @@
../dir

View File

@@ -71,6 +71,28 @@ it('should re-create symlinks properly', async () => {
assert(aStat.isFile());
});
it('should re-create symlinks properly (**/node_modules/**)', async () => {
if (process.platform === 'win32') {
console.log('Skipping test on windows');
return;
}
const files = await glob('**/node-modules/**', path.join(__dirname, 'symlinks-node-modules'));
assert.equal(Object.keys(files).length, 2);
const outDir = path.join(__dirname, 'symlinks-out');
await fs.remove(outDir);
const files2 = await download(files, outDir);
assert.equal(Object.keys(files2).length, 2);
const [linkDirStat, bStat] = await Promise.all([
fs.lstat(path.join(outDir, 'node-modules/link-dir')),
fs.lstat(path.join(outDir, 'dir/node-modules/b.txt')),
]);
assert(linkDirStat.isSymbolicLink());
assert(bStat.isFile());
});
it('should create zip files with symlinks properly', async () => {
if (process.platform === 'win32') {
console.log('Skipping test on windows');