Skip to content

Ensure source maps are not included in built plugins#100

Merged
agibson-godaddy merged 6 commits intomasterfrom
mwc-18446
Jan 27, 2026
Merged

Ensure source maps are not included in built plugins#100
agibson-godaddy merged 6 commits intomasterfrom
mwc-18446

Conversation

@agibson-godaddy
Copy link
Copy Markdown
Contributor

@agibson-godaddy agibson-godaddy commented Aug 22, 2025

Issue: https://godaddy-corp.atlassian.net/browse/MWC-18446

Summary

Our intention has always been to not ship sourcemap files in production code, and as part of that we attempt to strip the sourcemap comments from minified files.

At some point the comment style must have changed and it was no longer getting stripped. I think they went from /* style comments to // style in JS, and that accounts for the change.

Rather than accounting for the new comment format I opted to implement the TODO method of not generating them at all if we're in the build or deploy tasks.

QA

  1. Use this PR as a development version of Sake
  2. Work in a repo that contains both SASS and JS files. I'm using https://github.com/gdcorp-partners/woocommerce-customer-order-csv-export
  3. Run sake compile
  4. Inspect a compiled CSS file
    • It contains a sourcemap comment at the end like this: /*# sourceMappingURL=wc-customer-order-csv-export-admin.min.css.map */
  5. Inspect a minified JS file
    • It contains a sourcemap comment at the end like this: //# sourceMappingURL=wc-customer-order-csv-export-admin.min.js.map
  6. Run sake build
  7. Inspect the same compiled CSS file but inside the build/ directory
    • It does NOT contain a sourcemap comment
  8. Inspect the same compiled JS file but inside the build/ directory
    • It does NOT contain a sourcemap comment

@agibson-godaddy agibson-godaddy marked this pull request as ready for review August 22, 2025 12:51
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses an issue where source maps were still being included in production builds despite attempts to strip them. Instead of fixing the regex pattern that strips sourcemap comments, the implementation now prevents sourcemap generation entirely during build and deploy tasks.

  • Removes the regex-based sourcemap comment stripping from the copy task
  • Conditionally generates sourcemaps only when not running build/deploy tasks
  • Adds a new isBuildTask() helper method to detect build-related CLI invocations

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
tasks/copy.js Removes the regex pattern that was attempting to strip sourcemap comments
tasks/compile.js Conditionally wraps sourcemap generation with isBuildTask() checks for all asset types
pipes/scripts.js Updates the JavaScript compilation pipeline to conditionally generate sourcemaps
lib/sake.js Adds the isBuildTask() helper method to detect build-related CLI arguments

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread lib/sake.js Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@unfulvio
Copy link
Copy Markdown
Contributor

hey there! 👋

any ETA when this could be merged? looks good to me

@agibson-godaddy
Copy link
Copy Markdown
Contributor Author

hey there! 👋

any ETA when this could be merged? looks good to me

I need an approval. 😅 I'll chase it up! 👋

@unfulvio
Copy link
Copy Markdown
Contributor

hey @agibson-godaddy! thank you that would really hep! say hi to the team from me

Copy link
Copy Markdown
Contributor

@ajaynes-godaddy ajaynes-godaddy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a comment with one fix, otherwise QA checks out!

One thing I noticed is that when running sake build, the sourcemap comment(s) are removed from the plugin's minified CSS and JS (unexpected?) as well as the copies in the build directory (expected).

I'm guessing that's a side effect of the build process, i.e. 1. remove the sourcemaps, 2. copy the files to the build directory. Question is: is the sourcemaps being removed in both sets of files expected and/or acceptable?

p.s. Hiiii @unfulvio!

Comment thread lib/sake.js Outdated
Co-authored-by: Drew Jaynes <113622064+ajaynes-godaddy@users.noreply.github.com>
@agibson-godaddy
Copy link
Copy Markdown
Contributor Author

One thing I noticed is that when running sake build, the sourcemap comment(s) are removed from the plugin's minified CSS and JS (unexpected?) as well as the copies in the build directory (expected).

I'm guessing that's a side effect of the build process, i.e. 1. remove the sourcemaps, 2. copy the files to the build directory. Question is: is the sourcemaps being removed in both sets of files expected and/or acceptable?

Yeah that's expected because we just don't generate them at all anymore. (So they're not being removed exactly, just never created to begin with.)

We also don't commit minified CSS or sourcemaps so there's no risk of accidentally overwriting committed data in the repo.

If someone wants the sourcemaps for development they can just run npx sake compile again to get them back.

Thanks for the review!!

@agibson-godaddy agibson-godaddy merged commit fb73c88 into master Jan 27, 2026
@agibson-godaddy agibson-godaddy deleted the mwc-18446 branch January 27, 2026 07:59
@unfulvio
Copy link
Copy Markdown
Contributor

thank you! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants