From 1efe0fc39b5db7e8ed7eaeabf9a781cbf4dbebf9 Mon Sep 17 00:00:00 2001 From: Ashley Gibson Date: Fri, 22 Aug 2025 13:28:54 +0100 Subject: [PATCH 1/4] Also remove JS one-liner comments for sourcemaps --- tasks/copy.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tasks/copy.js b/tasks/copy.js index e09b1a3..e318263 100644 --- a/tasks/copy.js +++ b/tasks/copy.js @@ -156,7 +156,8 @@ module.exports = (gulp, plugins, sake) => { // @link https://github.com/gulpjs/gulp/issues/2790 return gulp.src(paths, { base: sake.config.paths.src, allowEmpty: true, encoding: false }) .pipe(filter) - .pipe(plugins.replace(/\/\*# sourceMappingURL=.*?\*\/$/mg, '')) // remove source mapping references - TODO: consider skipping sourcemaps in compilers instead when running build/deploy tasks + .pipe(plugins.replace(/\/\*# sourceMappingURL=.*?\*\/$/mg, '')) // remove CSS-style source mapping references + .pipe(plugins.replace(/\/\/# sourceMappingURL=.*$/mg, '')) // remove JS-style source mapping references .pipe(plugins.replace('\n', '')) // remove an extra line added by libsass/node-sass .pipe(filter.restore) .pipe(gulp.dest(`${sake.config.paths.build}/${sake.config.plugin.id}`)) From d1a605ce6141474b9a55e0ece75fd538884d0ee4 Mon Sep 17 00:00:00 2001 From: Ashley Gibson Date: Fri, 22 Aug 2025 13:43:13 +0100 Subject: [PATCH 2/4] Skip generating sourcemaps during build process --- lib/sake.js | 10 ++++++++++ pipes/scripts.js | 17 ++++++++++++----- tasks/compile.js | 17 +++++++++-------- tasks/copy.js | 2 -- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/lib/sake.js b/lib/sake.js index 4367b84..43baf7d 100644 --- a/lib/sake.js +++ b/lib/sake.js @@ -577,5 +577,15 @@ module.exports = (config, options) => { }) } + /** + * Checks if the current CLI invocation includes the build task. + * Used to conditionally skip sourcemap generation during builds. + * + * @return boolean + */ + exports.isBuildTask = () => { + return process.argv.slice(2).includes('build') + } + return exports } diff --git a/pipes/scripts.js b/pipes/scripts.js index 9586fc4..879c591 100644 --- a/pipes/scripts.js +++ b/pipes/scripts.js @@ -3,12 +3,13 @@ const lazypipe = require('lazypipe') module.exports = (plugins, sake) => { const pipes = {} - // transpile, minify and write sourcemaps + // transpile, minify and conditionally write sourcemaps // 1. Because CoffeeScript 2 will compile to ES6, we need to use babel to transpile it to ES2015, // note that this will also enable us to use ES6 in our plain JS. // 2. When not using CoffeeScript, regular JavaScript files that may contain ES6 code will also be transpiled to ES2015 automatically. // 3. We need to tell Babel to find the preset from this project, not from the current working directory, // see https://github.com/babel/babel-loader/issues/299#issuecomment-259713477. + pipes.compileJs = lazypipe() .pipe(plugins.babel, { presets: ['@babel/preset-env', '@babel/preset-react'].map(require.resolve) }) .pipe(() => { @@ -16,10 +17,16 @@ module.exports = (plugins, sake) => { return plugins.if(sake.options.minify, plugins.uglify()) }) .pipe(plugins.rename, { suffix: '.min' }) - // ensure admin/ and frontend/ are removed from the source paths - // see https://www.npmjs.com/package/gulp-sourcemaps#alter-sources-property-on-sourcemaps - .pipe(plugins.sourcemaps.mapSources, (sourcePath) => '../' + sourcePath) - .pipe(plugins.sourcemaps.write, '.', { includeContent: false }) + .pipe(() => { + // Only generate sourcemaps if not building + // ensure admin/ and frontend/ are removed from the source paths + // see https://www.npmjs.com/package/gulp-sourcemaps#alter-sources-property-on-sourcemaps + return plugins.if(!sake.isBuildTask(), plugins.sourcemaps.mapSources((sourcePath) => '../' + sourcePath)) + }) + .pipe(() => { + // Only write sourcemaps if not building + return plugins.if(!sake.isBuildTask(), plugins.sourcemaps.write('.', { includeContent: false })) + }) return pipes } diff --git a/tasks/compile.js b/tasks/compile.js index 5d7c92a..bc4f338 100644 --- a/tasks/compile.js +++ b/tasks/compile.js @@ -34,9 +34,10 @@ module.exports = (gulp, plugins, sake) => { return Promise.resolve() } + return gulp.src(`${sake.config.paths.assetPaths.js}/**/*.coffee`) // plugins.if(() => sake.isWatching, plugins.newer({dest: sake.config.paths.assetPaths.js + '/**', ext: 'min.js'})), - .pipe(plugins.sourcemaps.init()) + .pipe(plugins.if(!sake.isBuildTask(), plugins.sourcemaps.init())) // compile coffee files to JS .pipe(plugins.coffee({ bare: false })) // transpile & minify, write sourcemaps @@ -51,9 +52,10 @@ module.exports = (gulp, plugins, sake) => { return Promise.resolve() } + return gulp.src(sake.config.paths.assetPaths.javascriptSources) // plugins.if(() => sake.isWatching, plugins.newer({dest: sake.config.paths.assetPaths.js + '/**', ext: 'min.js'})), - .pipe(plugins.sourcemaps.init()) + .pipe(plugins.if(!sake.isBuildTask(), plugins.sourcemaps.init())) // transpile & minify, write sourcemaps .pipe(pipes.compileJs()) .pipe(gulp.dest(sake.config.paths.assetPaths.js)) @@ -72,7 +74,7 @@ module.exports = (gulp, plugins, sake) => { return Promise.resolve() } else { return gulp.src(sake.config.paths.assetPaths.blockSources) - .pipe(plugins.sourcemaps.init()) + .pipe(plugins.if(!sake.isBuildTask(), plugins.sourcemaps.init())) .pipe(webpack({ mode: 'production', entry: `${blockPath}/${blockSrc[0]}`, @@ -121,18 +123,17 @@ module.exports = (gulp, plugins, sake) => { cssPlugins.push(require('cssnano')({ zindex: false })) } + return gulp.src([ `${sake.config.paths.assetPaths.css}/**/*.scss`, `!${sake.config.paths.assetPaths.css}/**/mixins.scss` // don't compile any mixins by themselves ]) - .pipe(plugins.sourcemaps.init()) + .pipe(plugins.if(!sake.isBuildTask(), plugins.sourcemaps.init())) .pipe(sass({ outputStyle: 'expanded' })) .pipe(plugins.postcss(cssPlugins)) .pipe(plugins.rename({ suffix: '.min' })) - // ensure admin/ and frontend/ are removed from the source paths - // see https://www.npmjs.com/package/gulp-sourcemaps#alter-sources-property-on-sourcemaps - .pipe(plugins.sourcemaps.mapSources((sourcePath) => '../' + sourcePath)) - .pipe(plugins.sourcemaps.write('.', { includeContent: false })) + .pipe(plugins.if(!sake.isBuildTask(), plugins.sourcemaps.mapSources((sourcePath) => '../' + sourcePath))) + .pipe(plugins.if(!sake.isBuildTask(), plugins.sourcemaps.write('.', { includeContent: false }))) .pipe(gulp.dest(`${sake.config.paths.src}/${sake.config.paths.css}`)) .pipe(plugins.if(() => sake.isWatching && sake.config.tasks.watch.useBrowserSync, plugins.browserSync.stream({match: '**/*.css'}))) }) diff --git a/tasks/copy.js b/tasks/copy.js index e318263..eb2c808 100644 --- a/tasks/copy.js +++ b/tasks/copy.js @@ -156,8 +156,6 @@ module.exports = (gulp, plugins, sake) => { // @link https://github.com/gulpjs/gulp/issues/2790 return gulp.src(paths, { base: sake.config.paths.src, allowEmpty: true, encoding: false }) .pipe(filter) - .pipe(plugins.replace(/\/\*# sourceMappingURL=.*?\*\/$/mg, '')) // remove CSS-style source mapping references - .pipe(plugins.replace(/\/\/# sourceMappingURL=.*$/mg, '')) // remove JS-style source mapping references .pipe(plugins.replace('\n', '')) // remove an extra line added by libsass/node-sass .pipe(filter.restore) .pipe(gulp.dest(`${sake.config.paths.build}/${sake.config.plugin.id}`)) From de677ba09e6160c4edab3bfc5724cc01162ef345 Mon Sep 17 00:00:00 2001 From: Ashley Gibson Date: Fri, 22 Aug 2025 13:45:00 +0100 Subject: [PATCH 3/4] Account for deployments --- lib/sake.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/sake.js b/lib/sake.js index 43baf7d..9d2e4e9 100644 --- a/lib/sake.js +++ b/lib/sake.js @@ -578,13 +578,17 @@ module.exports = (config, options) => { } /** - * Checks if the current CLI invocation includes the build task. - * Used to conditionally skip sourcemap generation during builds. + * Checks if the current CLI invocation includes the build task or deploy tasks. + * Used to conditionally skip sourcemap generation during builds and deployments. * * @return boolean */ exports.isBuildTask = () => { - return process.argv.slice(2).includes('build') + const args = process.argv.slice(2) + return args.includes('build') || + args.includes('deploy') || + args.includes('copy_to_wc_repo') || + args.includes('copy_to_wp_repo') } return exports From a296376a31d77381131da58af0d2ef234cf3780e Mon Sep 17 00:00:00 2001 From: Ashley Gibson <99189195+agibson-godaddy@users.noreply.github.com> Date: Fri, 22 Aug 2025 13:58:23 +0100 Subject: [PATCH 4/4] Simplify return statement Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- lib/sake.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sake.js b/lib/sake.js index 9d2e4e9..881dab2 100644 --- a/lib/sake.js +++ b/lib/sake.js @@ -588,7 +588,7 @@ module.exports = (config, options) => { return args.includes('build') || args.includes('deploy') || args.includes('copy_to_wc_repo') || - args.includes('copy_to_wp_repo') + return ['build', 'deploy', 'copy_to_wc_repo', 'copy_to_wp_repo'].some(task => args.includes(task)) } return exports