Skip to content

Commit

Permalink
Fix Grunt memory leak (#906)
Browse files Browse the repository at this point in the history
Fix the grunt memory leak by isolating the jambo and webpack build into their own process

J=SLAP-1484
TEST=manual

Run "grunt watch" and confirm the build runs when files change
  • Loading branch information
cea2aj committed Aug 5, 2021
1 parent fcb4236 commit 426c733
Showing 1 changed file with 7 additions and 25 deletions.
32 changes: 7 additions & 25 deletions static/Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const webpackConfig = require('./webpack-config');
const { exec } = require("child_process");
const { spawnSync } = require('child_process');
const jamboConfig = require('./jambo.json');

const outputDir = jamboConfig.dirs.output;
Expand All @@ -12,34 +12,16 @@ module.exports = function (grunt) {
watch: {
all: {
files: ['**', '!**/node_modules/**', `!${outputDir}/**`],
tasks: ['jambobuild', 'webpack',],
options: {
spawn: false,
},
tasks: ['build-site']
},
},
});

grunt.loadNpmTasks('grunt-webpack');
grunt.loadNpmTasks('grunt-contrib-watch');

grunt.registerTask('jambobuild', 'Jambo build.',
function() {
// Force task into async mode and grab a handle to the "done" function.
var done = this.async();
// Run some sync stuff.
grunt.log.writeln('Processing task...');
// And some async stuff.
exec('npx jambo build', (error, stdout, stderr) => {
if (error) {
console.log(error.message);
done(false);
return;
}

stderr && console.error(stderr);
stdout && console.log(stdout);
done();
grunt.registerTask('build-site', 'Builds the site.', () => {
spawnSync('npx jambo build && npx webpack --config webpack-config.js', {
shell: true,
stdio: 'inherit'
});
});
}
}

0 comments on commit 426c733

Please sign in to comment.