Skip to content

Commit

Permalink
build-system: fix unminified watch mode. (#33334)
Browse files Browse the repository at this point in the history
* build-system: fix unminified watch mode.

* nits

* address second nit
  • Loading branch information
samouri committed Mar 18, 2021
1 parent 396a6f9 commit 2de6baf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
4 changes: 2 additions & 2 deletions build-system/compile/pre-closure-babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function getBabelCacheDir() {
* so it can be retransformed during a watch build.
* @param {string} fileOrDir
*/
function removeFromBabelCache(fileOrDir) {
function removeFromClosureBabelCache(fileOrDir) {
const cachedPath = path.join(cacheDir, fileOrDir);
if (fs.existsSync(cachedPath)) {
fs.removeSync(cachedPath);
Expand Down Expand Up @@ -138,6 +138,6 @@ function handlePreClosureError(err, outputFilename, options) {

module.exports = {
getBabelCacheDir,
removeFromBabelCache,
removeFromClosureBabelCache,
preClosureBabel,
};
11 changes: 7 additions & 4 deletions build-system/tasks/extension-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const {isCiBuild} = require('../common/ci');
const {jsifyCssAsync} = require('./css/jsify-css');
const {log} = require('../common/logging');
const {maybeToEsmName, compileJs, mkdirSync} = require('./helpers');
const {removeFromBabelCache} = require('../compile/pre-closure-babel');
const {removeFromClosureBabelCache} = require('../compile/pre-closure-babel');
const {watch} = require('chokidar');

/**
Expand Down Expand Up @@ -384,8 +384,11 @@ async function doBuildExtension(extensions, extension, options) {
* @param {?Object} options
*/
function watchExtension(extDir, name, version, latestVersion, hasCss, options) {
const watchFunc = function () {
removeFromBabelCache(extDir);
function watchFunc() {
if (options.minify) {
removeFromClosureBabelCache(extDir);
}

const bundleComplete = buildExtension(
name,
version,
Expand All @@ -396,7 +399,7 @@ function watchExtension(extDir, name, version, latestVersion, hasCss, options) {
if (options.onWatchBuild) {
options.onWatchBuild(bundleComplete);
}
};
}
watch(`${extDir}/**/*`).on('change', debounce(watchFunc, watchDebounceDelay));
}

Expand Down
14 changes: 9 additions & 5 deletions build-system/tasks/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const {green, red, cyan} = require('kleur/colors');
const {isCiBuild} = require('../common/ci');
const {jsBundles} = require('../compile/bundles.config');
const {log, logLocalDev} = require('../common/logging');
const {removeFromBabelCache} = require('../compile/pre-closure-babel');
const {removeFromClosureBabelCache} = require('../compile/pre-closure-babel');
const {thirdPartyFrames} = require('../test-configs/config');
const {transpileTs} = require('../compile/typescript');
const {watch: fileWatch} = require('chokidar');
Expand Down Expand Up @@ -163,7 +163,9 @@ async function compileCoreRuntime(options) {
if (options.watch) {
/** @return {Promise<void>} */
async function watchFunc() {
removeFromBabelCache('src');
if (options.minify) {
removeFromClosureBabelCache('src');
}
const bundleComplete = await doBuildJs(jsBundles, 'amp.js', {
...options,
continueOnError: true,
Expand Down Expand Up @@ -331,13 +333,15 @@ async function compileMinifiedJs(srcDir, srcFilename, destDir, options) {
const minifiedName = maybeToEsmName(options.minifiedName);

if (options.watch) {
const watchFunc = async () => {
removeFromBabelCache(entryPoint);
async function watchFunc() {
if (options.minify) {
removeFromClosureBabelCache(entryPoint);
}
const compileDone = await doCompileMinifiedJs(/* continueOnError */ true);
if (options.onWatchBuild) {
options.onWatchBuild(compileDone);
}
};
}
fileWatch(entryPoint).on('change', debounce(watchFunc, watchDebounceDelay));
}

Expand Down

0 comments on commit 2de6baf

Please sign in to comment.