Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: add glob and jest-worker * add buildBabel2 routine * cleanup * exit gracefully when CI does not have available workers * perf: less IO when dest is not entity * perf: pipe worker stdout/stderr to parent process * Update Gulpfile.mjs Co-authored-by: Brian Ng <bng412@gmail.com> Co-authored-by: Brian Ng <bng412@gmail.com>
- Loading branch information
1 parent
6c8b233
commit 69f423b
Showing
4 changed files
with
99 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const { transformSync } = require("@babel/core"); | ||
const { mkdirSync, statSync, readFileSync, writeFileSync } = require("fs"); | ||
const { dirname } = require("path"); | ||
const chalk = require("chalk"); | ||
const fancyLog = require("fancy-log"); | ||
|
||
function needCompile(src, dest) { | ||
let destStat; | ||
try { | ||
destStat = statSync(dest); | ||
} catch (err) { | ||
if (err.code === "ENOENT") { | ||
return true; | ||
} else { | ||
throw err; | ||
} | ||
} | ||
const srcStat = statSync(src); | ||
return srcStat.mtimeMs > destStat.mtimeMs; | ||
} | ||
|
||
exports.transform = function (src, dest) { | ||
mkdirSync(dirname(dest), { recursive: true }); | ||
if (!needCompile(src, dest)) { | ||
return; | ||
} | ||
fancyLog(`Compiling '${chalk.cyan(src)}'...`); | ||
const content = readFileSync(src, { encoding: "utf8" }); | ||
const { code } = transformSync(content, { | ||
filename: src, | ||
caller: { | ||
// We have wrapped packages/babel-core/src/config/files/configuration.js with feature detection | ||
supportsDynamicImport: true, | ||
name: "babel-worker", | ||
}, | ||
}); | ||
|
||
writeFileSync(dest, code, "utf8"); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters