Ignore unnecessary build artifacts

Summary:
This allows bundles to have their `.buildignore` file. I did that first to remove some things from the `static` folder, but it turned out that those aren't just unnecessary for the bundle but completely unused in general. I still think there may be a case for allowing this on a per-package basis.

Right now it excludes `.ts` files, license files and readmes. Full list of excluded files is here: P129474747

It adds up to about 6MB in the *DEFLATE compressed* bundle.

Reviewed By: nikoant

Differential Revision: D21176143

fbshipit-source-id: a13e900152617fdf1c2dbfa6330c0a06a75e5484
This commit is contained in:
Pascal Hartig
2020-04-24 08:32:55 -07:00
committed by Facebook GitHub Bot
parent b4a5a17d49
commit 4d58563168
3 changed files with 24 additions and 4 deletions

View File

@@ -187,6 +187,7 @@
"flow-bin": "0.123.0", "flow-bin": "0.123.0",
"fs-extra": "^9.0.0", "fs-extra": "^9.0.0",
"glob": "^7.1.2", "glob": "^7.1.2",
"ignore": "^5.1.4",
"invariant": "^2.2.4", "invariant": "^2.2.4",
"jest": "^25.1.0", "jest": "^25.1.0",
"jest-environment-jsdom-sixteen": "^1.0.3", "jest-environment-jsdom-sixteen": "^1.0.3",

View File

@@ -9,6 +9,16 @@
import fs from 'fs-extra'; import fs from 'fs-extra';
import path from 'path'; import path from 'path';
import ignore from 'ignore';
const DEFAULT_BUILD_IGNORES = [
'/node_modules',
'README*',
'LICENSE*',
'*.ts',
'*.ls',
'Gruntfile*',
];
/** /**
* This function copies package into the specified target dir with all its dependencies: * This function copies package into the specified target dir with all its dependencies:
@@ -39,10 +49,18 @@ async function copyPackageWithDependenciesRecursive(
if ((await fs.stat(packageDir)).isSymbolicLink()) { if ((await fs.stat(packageDir)).isSymbolicLink()) {
packageDir = await fs.readlink(packageDir); packageDir = await fs.readlink(packageDir);
} }
const ignores = await fs
.readFile(path.join(packageDir, '.buildignore'), 'utf-8')
.then((l) => l.split('\n'))
.catch((_e) => [])
.then((l: Array<string>) => ignore().add(DEFAULT_BUILD_IGNORES.concat(l)));
await fs.copy(packageDir, targetDir, { await fs.copy(packageDir, targetDir, {
dereference: true, dereference: true,
recursive: true, recursive: true,
filter: (src) => !src.startsWith(path.join(packageDir, 'node_modules')), filter: (src) => {
const relativePath = path.relative(packageDir, src);
return relativePath === '' || !ignores.ignores(relativePath);
},
}); });
const pkg = await fs.readJson(path.join(packageDir, 'package.json')); const pkg = await fs.readJson(path.join(packageDir, 'package.json'));
const dependencies = (pkg.dependencies ?? {}) as {[key: string]: string}; const dependencies = (pkg.dependencies ?? {}) as {[key: string]: string};

View File

@@ -13,12 +13,13 @@
"flipper-pkg-lib": "0.39.0", "flipper-pkg-lib": "0.39.0",
"mem": "^6.0.0", "mem": "^6.0.0",
"mkdirp": "^1.0.0", "mkdirp": "^1.0.0",
"p-map": "^4.0.0",
"p-filter": "^2.1.0", "p-filter": "^2.1.0",
"p-map": "^4.0.0",
"recursive-readdir": "^2.2.2", "recursive-readdir": "^2.2.2",
"uuid": "^7.0.1", "uuid": "^7.0.1",
"ws": "^7.2.3",
"xdg-basedir": "^4.0.0", "xdg-basedir": "^4.0.0",
"yargs": "^15.3.1", "ignore": "^5.1.4",
"ws": "^7.2.3" "yargs": "^15.3.1"
} }
} }