Skip to content

Feature/fix sourcemap url#299

Merged
z0ffy merged 2 commits into
mainfrom
feature/fix-sourcemap-url
Dec 8, 2025
Merged

Feature/fix sourcemap url#299
z0ffy merged 2 commits into
mainfrom
feature/fix-sourcemap-url

Conversation

@z0ffy

@z0ffy z0ffy commented Dec 8, 2025

Copy link
Copy Markdown
Owner

Summary by Sourcery

Update source map handling to better align obfuscated bundle outputs with Vite/Rollup sourcemap configuration.

Bug Fixes:

  • Ensure generated source map file names use the bundle file's basename rather than the full path.

Enhancements:

  • Propagate Vite/Rollup sourcemapBaseUrl configuration into the obfuscator options when sourcemaps are enabled.
  • Update README logo image URL to the new path.

z0ffy added 2 commits December 9, 2025 00:41
- Add support for `sourceMapBaseUrl` in sourcemap configuration.
- Use `path.basename` for consistent source map file names across utilities.
@sourcery-ai

sourcery-ai Bot commented Dec 8, 2025

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts how sourcemap filenames and base URLs are generated for obfuscated bundles, and updates documentation branding.

Sequence diagram for updated sourcemap configuration and obfuscation

sequenceDiagram
  actor Dev
  participant Vite as ViteBuild
  participant Plugin as viteBundleObfuscator
  participant Utils as obfuscateBundle
  participant Obf as javascriptObfuscator

  Dev->>Vite: Run build with sourcemap enabled
  Vite->>Plugin: Call configResolvedHandler(resolvedConfig)
  Plugin->>Plugin: Read resolvedConfig.build.sourcemap
  Plugin->>Plugin: Read rollupOptions.output.sourcemapBaseUrl
  Plugin->>Plugin: Set finalConfig.options.sourceMap = true
  Plugin->>Plugin: Set finalConfig.options.sourceMapMode
  Plugin->>Plugin: Set finalConfig.options.sourceMapBaseUrl (if defined)

  Vite->>Plugin: Generate bundle and invoke obfuscation
  Plugin->>Utils: obfuscateBundle(finalConfig, fileName, bundleItem)
  Utils->>Utils: fileSpecificOptions = {
  Utils->>Utils:   ...finalConfig.options,
  Utils->>Utils:   inputFileName = fileName,
  Utils->>Utils:   sourceMapFileName = path.basename(fileName) + ".map"
  Utils->>Obf: obfuscate(bundleItem.code, fileSpecificOptions)
  Obf-->>Utils: obfuscated code with sourcemap
  Utils-->>Plugin: obfuscated bundle
  Plugin-->>Vite: final obfuscated assets with correct sourcemap URLs
Loading

File-Level Changes

Change Details Files
Use basename of bundle file when generating sourcemap filenames for obfuscation.
  • Replace direct use of full fileName with path.basename(fileName) when constructing sourceMapFileName in bundle obfuscation helper.
  • Apply same basename logic in the worker obfuscation path to ensure consistent sourcemap naming between main and worker flows.
src/utils/index.ts
src/worker/index.ts
Propagate Vite/Rollup sourcemapBaseUrl to the obfuscator options when sourcemaps are enabled.
  • Read rollupOptions.output from the resolved Vite config, safely handling array vs non-array outputs.
  • Extract sourcemapBaseUrl from the output config and, if present, pass it through as sourceMapBaseUrl in finalConfig.options together with sourceMap and sourceMapMode.
src/index.ts
Update README logo image URL to new path.
  • Change the logo URL in README from /images/logo.png to /logo.png to match current hosting path or branding.
README.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • In configResolvedHandler, resolvedConfig.build.rollupOptions?.output can be an array; if multiple outputs are configured, consider either handling the array case or explicitly validating/throwing so behavior is predictable rather than silently ignoring it.
  • When setting sourceMapFileName with path.basename(fileName), double-check that this matches Vite/Rollup’s final emitted filenames (especially when using hashes or custom entryFileNames patterns), otherwise sourcemap URLs might not align with the generated bundle names.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `configResolvedHandler`, `resolvedConfig.build.rollupOptions?.output` can be an array; if multiple outputs are configured, consider either handling the array case or explicitly validating/throwing so behavior is predictable rather than silently ignoring it.
- When setting `sourceMapFileName` with `path.basename(fileName)`, double-check that this matches Vite/Rollup’s final emitted filenames (especially when using hashes or custom `entryFileNames` patterns), otherwise sourcemap URLs might not align with the generated bundle names.

## Individual Comments

### Comment 1
<location> `src/index.ts:111-112` </location>
<code_context>
   const configResolvedHandler: (resolvedConfig: ResolvedConfig) => void | Promise<void> = (resolvedConfig) => {
     const sourcemap = resolvedConfig.build.sourcemap;
     if (sourcemap) {
+      const output = resolvedConfig.build.rollupOptions?.output;
+      const sourcemapBaseUrl = !isArray(output) ? output?.sourcemapBaseUrl : undefined;
       finalConfig.options = {
         ...finalConfig.options,
</code_context>

<issue_to_address>
**suggestion:** `sourcemapBaseUrl` is ignored when `rollupOptions.output` is an array, which might be surprising for multi-output builds.

Because of the `!isArray(output)` guard, `sourcemapBaseUrl` is effectively unsupported for multi-output Rollup configs, even when all outputs could share the same base URL. If multi-output builds are a target use case, consider either handling the array case (e.g., ensure all outputs have the same `sourcemapBaseUrl` and use it) or clearly documenting that this option only applies to single-output configs.
</issue_to_address>

### Comment 2
<location> `src/index.ts:112` </location>
<code_context>
      const sourcemapBaseUrl = !isArray(output) ? output?.sourcemapBaseUrl : undefined;

</code_context>

<issue_to_address>
**suggestion (code-quality):** Invert ternary operator to remove negation ([`invert-ternary`](https://docs.sourcery.ai/Reference/Rules-and-In-Line-Suggestions/TypeScript/Default-Rules/invert-ternary))

```suggestion
      const sourcemapBaseUrl = isArray(output) ? undefined : output?.sourcemapBaseUrl;
```

<br/><details><summary>Explanation</summary>Negated conditions are more difficult to read than positive ones, so it is best
to avoid them where we can. By inverting the ternary condition and swapping the
expressions we can simplify the code.
</details>
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/index.ts
Comment on lines +111 to +112
const output = resolvedConfig.build.rollupOptions?.output;
const sourcemapBaseUrl = !isArray(output) ? output?.sourcemapBaseUrl : undefined;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: sourcemapBaseUrl is ignored when rollupOptions.output is an array, which might be surprising for multi-output builds.

Because of the !isArray(output) guard, sourcemapBaseUrl is effectively unsupported for multi-output Rollup configs, even when all outputs could share the same base URL. If multi-output builds are a target use case, consider either handling the array case (e.g., ensure all outputs have the same sourcemapBaseUrl and use it) or clearly documenting that this option only applies to single-output configs.

Comment thread src/index.ts
const sourcemap = resolvedConfig.build.sourcemap;
if (sourcemap) {
const output = resolvedConfig.build.rollupOptions?.output;
const sourcemapBaseUrl = !isArray(output) ? output?.sourcemapBaseUrl : undefined;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion (code-quality): Invert ternary operator to remove negation (invert-ternary)

Suggested change
const sourcemapBaseUrl = !isArray(output) ? output?.sourcemapBaseUrl : undefined;
const sourcemapBaseUrl = isArray(output) ? undefined : output?.sourcemapBaseUrl;


ExplanationNegated conditions are more difficult to read than positive ones, so it is best
to avoid them where we can. By inverting the ternary condition and swapping the
expressions we can simplify the code.

@z0ffy z0ffy mentioned this pull request Dec 8, 2025
@z0ffy z0ffy merged commit a80c312 into main Dec 8, 2025
9 checks passed
@z0ffy z0ffy deleted the feature/fix-sourcemap-url branch December 8, 2025 16:47
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.

1 participant