Skip to content

Comments

fix(vite-node): Generate sourcemap for inlined deps#6041

Closed
bgoscinski wants to merge 1 commit intovitest-dev:mainfrom
bgoscinski:main
Closed

fix(vite-node): Generate sourcemap for inlined deps#6041
bgoscinski wants to merge 1 commit intovitest-dev:mainfrom
bgoscinski:main

Conversation

@bgoscinski
Copy link
Contributor

@bgoscinski bgoscinski commented Jul 5, 2024

closes #5605

I implemented the change that allows to use the source maps but I could really use some guidance on if/how you want this tested

Description

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

@bgoscinski bgoscinski force-pushed the main branch 2 times, most recently from 1668814 to 1a24089 Compare July 5, 2024 20:16
@bgoscinski bgoscinski marked this pull request as ready for review July 5, 2024 20:37

const sourcemap = this.options.sourcemap ?? 'inline'
if (sourcemap === 'inline' && result && !id.includes('node_modules')) {
if (sourcemap === 'inline' && result && !(await this.shouldExternalize(id))) {
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't make much sense because it will alway return true - this function is not called otherwise:

const externalize = await this.shouldExternalize(filePath)
let duration: number | undefined
if (externalize) {
result = { externalize }
this.debugger?.recordExternalize(id, externalize)
}
else {
const start = performance.now()
const r = await this._transformRequest(id, filePath, transformMode)
duration = performance.now() - start
result = { code: r?.code, map: r?.map as any }
}

We don't inline source map because it's expensive to do for every file in node modules

Copy link
Contributor Author

@bgoscinski bgoscinski Jul 8, 2024

Choose a reason for hiding this comment

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

Is there a way for me as a vitest user force it to generate source maps for specific modules from node_modules? In my case I'd like to generate source maps for the deps that I inline (server.deps.inline) because of #5605

Copy link
Member

Choose a reason for hiding this comment

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

No, there is no way to do that, all node_modules files ignore stack trace. Maybe we can add another option 🤷🏻

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A new option in the config would solve my usecase 💯!

If it makes sense to allow users to generate source maps for not necessairly inlined deps then server.deps.sourcemap accepting (string | RegExp)[] seem ok, but if it makes sense only for inline deps then how about extending server.deps.inline like this

-inline: (string | RegExp)[] | true
+inline: (string | RegExp)[] | true | { match: string | RegExp, sourcemap: boolean }[]

Copy link
Member

Choose a reason for hiding this comment

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

Adding an object to inline would be a breaking change, so if you want it to be fixed that way we will need to wait until Vitest 3. I was thinking about a separate option like includeSourcemap?: string | RegExp[]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok thanks!
I'll close this PR then and see if I'll be able to implement the includeSourcemap option

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.

Source maps in inlined deps are off by a few lines in VS Code

2 participants