Typescriptify the main process code (4/N)
Summary: Skip the main process code bundling when nothing changed Reviewed By: mweststrate Differential Revision: D20030261 fbshipit-source-id: 78de87377afe7e768627059425c51081239687dd
This commit is contained in:
committed by
Facebook Github Bot
parent
89180d0b07
commit
bd0c7bb58f
@@ -108,6 +108,7 @@
|
|||||||
"jest-fetch-mock": "^3.0.0",
|
"jest-fetch-mock": "^3.0.0",
|
||||||
"prettier": "^1.19.1",
|
"prettier": "^1.19.1",
|
||||||
"react-async": "^10.0.0",
|
"react-async": "^10.0.0",
|
||||||
|
"recursive-readdir": "^2.2.2",
|
||||||
"redux-mock-store": "^1.5.3",
|
"redux-mock-store": "^1.5.3",
|
||||||
"ts-jest": "^25.1.0",
|
"ts-jest": "^25.1.0",
|
||||||
"typescript": "^3.7.2"
|
"typescript": "^3.7.2"
|
||||||
|
|||||||
@@ -9,10 +9,22 @@
|
|||||||
|
|
||||||
const Metro = require('../static/node_modules/metro');
|
const Metro = require('../static/node_modules/metro');
|
||||||
const compilePlugins = require('../static/compilePlugins');
|
const compilePlugins = require('../static/compilePlugins');
|
||||||
|
const util = require('util');
|
||||||
const tmp = require('tmp');
|
const tmp = require('tmp');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const cp = require('promisify-child-process');
|
const cp = require('promisify-child-process');
|
||||||
|
const recursiveReaddir = require('recursive-readdir');
|
||||||
|
|
||||||
|
function mostRecentlyChanged(dir, ignores) {
|
||||||
|
return util
|
||||||
|
.promisify(recursiveReaddir)(dir, ignores)
|
||||||
|
.then(files =>
|
||||||
|
files
|
||||||
|
.map(f => fs.lstatSync(f).ctime)
|
||||||
|
.reduce((a, b) => (a > b ? a : b), new Date(0)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function die(err) {
|
function die(err) {
|
||||||
console.error(err.stack);
|
console.error(err.stack);
|
||||||
@@ -81,9 +93,19 @@ function compile(buildFolder, entry) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function compileMain() {
|
async function compileMain() {
|
||||||
|
const staticDir = path.resolve(__dirname, '..', 'static');
|
||||||
|
const out = path.join(staticDir, 'main.bundle.js');
|
||||||
|
// check if main needs to be compiled
|
||||||
|
if (await fs.pathExists(out)) {
|
||||||
|
const staticDirCtime = await mostRecentlyChanged(staticDir, ['*.bundle.*']);
|
||||||
|
const bundleCtime = (await fs.lstat(out)).ctime;
|
||||||
|
if (staticDirCtime < bundleCtime) {
|
||||||
|
console.log(`🥫 Using cached version of main bundle...`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
console.log(`⚙️ Compiling main bundle...`);
|
console.log(`⚙️ Compiling main bundle...`);
|
||||||
try {
|
try {
|
||||||
const staticDir = path.resolve(__dirname, '..', 'static');
|
|
||||||
const config = Object.assign({}, await Metro.loadConfig(), {
|
const config = Object.assign({}, await Metro.loadConfig(), {
|
||||||
reporter: {update: () => {}},
|
reporter: {update: () => {}},
|
||||||
projectRoot: staticDir,
|
projectRoot: staticDir,
|
||||||
@@ -105,7 +127,7 @@ async function compileMain() {
|
|||||||
await Metro.runBuild(config, {
|
await Metro.runBuild(config, {
|
||||||
platform: 'web',
|
platform: 'web',
|
||||||
entry: path.join(staticDir, 'main.ts'),
|
entry: path.join(staticDir, 'main.ts'),
|
||||||
out: path.join(staticDir, 'main.bundle.js'),
|
out,
|
||||||
dev: false,
|
dev: false,
|
||||||
minify: false,
|
minify: false,
|
||||||
sourceMap: true,
|
sourceMap: true,
|
||||||
@@ -116,7 +138,6 @@ async function compileMain() {
|
|||||||
die(err);
|
die(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildFolder() {
|
function buildFolder() {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log('Creating build directory');
|
console.log('Creating build directory');
|
||||||
@@ -130,7 +151,6 @@ function buildFolder() {
|
|||||||
});
|
});
|
||||||
}).catch(die);
|
}).catch(die);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getVersionNumber() {
|
function getVersionNumber() {
|
||||||
let {version} = require('../package.json');
|
let {version} = require('../package.json');
|
||||||
const buildNumber = process.argv.join(' ').match(/--version=(\d+)/);
|
const buildNumber = process.argv.join(' ').match(/--version=(\d+)/);
|
||||||
@@ -139,7 +159,6 @@ function getVersionNumber() {
|
|||||||
}
|
}
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Asynchronously determine current mercurial revision as string or `null` in case of any error.
|
// Asynchronously determine current mercurial revision as string or `null` in case of any error.
|
||||||
function genMercurialRevision() {
|
function genMercurialRevision() {
|
||||||
return cp
|
return cp
|
||||||
@@ -147,7 +166,6 @@ function genMercurialRevision() {
|
|||||||
.catch(err => null)
|
.catch(err => null)
|
||||||
.then(res => (res && res.stdout) || null);
|
.then(res => (res && res.stdout) || null);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
buildFolder,
|
buildFolder,
|
||||||
compile,
|
compile,
|
||||||
|
|||||||
@@ -6441,7 +6441,7 @@ mimic-response@^1.0.0, mimic-response@^1.0.1:
|
|||||||
resolved "https://registry.yarnpkg.com/mimic-response/-/mimic-response-1.0.1.tgz#4923538878eef42063cb8a3e3b0798781487ab1b"
|
resolved "https://registry.yarnpkg.com/mimic-response/-/mimic-response-1.0.1.tgz#4923538878eef42063cb8a3e3b0798781487ab1b"
|
||||||
integrity sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==
|
integrity sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==
|
||||||
|
|
||||||
minimatch@^3.0.2, minimatch@^3.0.4:
|
minimatch@3.0.4, minimatch@^3.0.2, minimatch@^3.0.4:
|
||||||
version "3.0.4"
|
version "3.0.4"
|
||||||
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
|
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
|
||||||
integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==
|
integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==
|
||||||
@@ -7698,6 +7698,13 @@ recast@^0.16.1:
|
|||||||
private "~0.1.5"
|
private "~0.1.5"
|
||||||
source-map "~0.6.1"
|
source-map "~0.6.1"
|
||||||
|
|
||||||
|
recursive-readdir@^2.2.2:
|
||||||
|
version "2.2.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/recursive-readdir/-/recursive-readdir-2.2.2.tgz#9946fb3274e1628de6e36b2f6714953b4845094f"
|
||||||
|
integrity sha512-nRCcW9Sj7NuZwa2XvH9co8NPeXUBhZP7CRKJtU+cS6PW9FpCIFoI5ib0NT1ZrbNuPoRy0ylyCaUL8Gih4LSyFg==
|
||||||
|
dependencies:
|
||||||
|
minimatch "3.0.4"
|
||||||
|
|
||||||
redux-devtools-core@^0.2.1:
|
redux-devtools-core@^0.2.1:
|
||||||
version "0.2.1"
|
version "0.2.1"
|
||||||
resolved "https://registry.yarnpkg.com/redux-devtools-core/-/redux-devtools-core-0.2.1.tgz#4e43cbe590a1f18c13ee165d2d42e0bc77a164d8"
|
resolved "https://registry.yarnpkg.com/redux-devtools-core/-/redux-devtools-core-0.2.1.tgz#4e43cbe590a1f18c13ee165d2d42e0bc77a164d8"
|
||||||
|
|||||||
Reference in New Issue
Block a user