Skip to content

Commit

Permalink
watch src dir for v0.js (#32835)
Browse files Browse the repository at this point in the history
* watch src dir for v0.js

* lint

* Update lazy server, propagate a watch:false

* Update build-system/server/lazy-build.js

Co-authored-by: Raghu Simha <rsimha@amp.dev>

* lint fixes, and racey fix

Co-authored-by: Raghu Simha <rsimha@amp.dev>
  • Loading branch information
samouri and rsimha committed Feb 24, 2021
1 parent 8d7197e commit e1bfc81
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
6 changes: 4 additions & 2 deletions build-system/server/lazy-build.js
Expand Up @@ -21,7 +21,7 @@ const {
maybeInitializeExtensions,
getExtensionsToBuild,
} = require('../tasks/extension-helpers');
const {doBuildJs} = require('../tasks/helpers');
const {doBuildJs, compileCoreRuntime} = require('../tasks/helpers');
const {jsBundles} = require('../compile/bundles.config');

const extensionBundles = {};
Expand Down Expand Up @@ -131,7 +131,9 @@ async function lazyBuildJs(req, _res, next) {
* Pre-builds the core runtime and the JS files that it loads.
*/
async function preBuildRuntimeFiles() {
await build(jsBundles, 'amp.js', doBuildJs);
await build(jsBundles, 'amp.js', (_bundles, _name, options) =>
compileCoreRuntime(options)
);
await build(jsBundles, 'ww.max.js', doBuildJs);
}

Expand Down
17 changes: 16 additions & 1 deletion build-system/tasks/helpers.js
Expand Up @@ -150,7 +150,22 @@ async function bootstrapThirdPartyFrames(options) {
* @param {!Object} options
*/
async function compileCoreRuntime(options) {
await doBuildJs(jsBundles, 'amp.js', options);
async function watchFunc() {
const bundleComplete = await doBuildJs(jsBundles, 'amp.js', {
...options,
watch: false,
});
if (options.onWatchBuild) {
options.onWatchBuild(bundleComplete);
}
}

if (options.watch) {
const debouncedRebuild = debounce(watchFunc, watchDebounceDelay);
fileWatch('src/**/*.js').on('change', debouncedRebuild);
}

await doBuildJs(jsBundles, 'amp.js', {...options, watch: false});
}

/**
Expand Down

0 comments on commit e1bfc81

Please sign in to comment.