Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev: adapt to vitest@1.2 #213

Merged
merged 6 commits into from
Feb 16, 2024
Merged

dev: adapt to vitest@1.2 #213

merged 6 commits into from
Feb 16, 2024

Conversation

keroxp
Copy link
Contributor

@keroxp keroxp commented Jan 17, 2024

This PR includes an adaption to the latest vitest distribution v1.2.2 (2024-02-16)

@keroxp keroxp changed the title [WIP] dev: adapt to vitest@1.2.0 dev: adapt to vitest@1.2.0 Jan 17, 2024
import { isDefinitelyVitestEnv, mayBeVitestEnv } from './pure/isVitestEnv'
import { getVitestCommand, getVitestVersion, isNodeAvailable } from './pure/utils'
import { log } from './log'
export const extensionId = 'zxch3n.vitest-explorer'

// Copied from https://github.com/vitest-dev/vitest/blob/main/packages/vitest/src/defaults.ts
// "import { configDefaults } from 'vitest'" throws unexpected URL error
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This statement throws "Invalid URL" error during activation (from node_modules/vite/dist/node-cjs/publicUtils.cjs. That file includes codes like below:

const { version: version$2 } = JSON.parse(fs$1.readFileSync(new URL('../../package.json', (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('node-cjs/publicUtils.cjs', document.baseURI).href)))).toString());

It won't work in the bundled dist/extension.js. I couldn't find any solution and gave up. Are anyone knows something?

Copy link
Member

Choose a reason for hiding this comment

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

I would expect Vite to not be bundled with this extension, maybe it can be externalized/tree-shaken?

Copy link
Member

@sheremet-va sheremet-va Feb 15, 2024

Choose a reason for hiding this comment

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

vitest/config doesn't actually import anything from Vite, so I'm not sure why it even gets bundled here 🤔 (Oh, now I see it re-exports mergeConfig). I think we should just update the bundler here to remove the mergeConfig API from vitest/config

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like tsup/esbuild's default tree-shaking is not doing much and keeps unused require("vite"). Actually tsup supports rollup-based tree-shaking https://tsup.egoist.dev/#tree-shaking, so this config seems to work but rebuild slows down a bit.

// tsup.config.ts
import { defineConfig } from "tsup"

export default defineConfig({
  entry: ["./src/extension.ts"],
  external: ["vscode", "vite"],
  treeshake: true,
})

Personally, just inlining defaultInclude and defaultExclude is equally fine as well.

Copy link
Member

Choose a reason for hiding this comment

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

tsup also supports plugins where we can manually remove vite import

Copy link
Member

Choose a reason for hiding this comment

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

Yes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is ideal to import the original config from vitest. I think it's problem of vitest bundle. new URL with relative path resolution won't work imported bundle. Anyway, can it be acceptable?

Copy link
Member

Choose a reason for hiding this comment

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

I think it's problem of vitest bundle

it is not the problem of Vitest bundle, Vitest doesn't use new URL, this is the code from Vite, and Vite should not be bundled for the extension. To remove vite import, you can write a small esbuild plugin that strips it out

Copy link
Member

Choose a reason for hiding this comment

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

Ok, let's keep hardcoded config for now

Copy link
Member

Choose a reason for hiding this comment

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

Also, I wonder if require would work:

require('vitest/config', { paths: [workspaceDir] })

@keroxp keroxp marked this pull request as ready for review January 17, 2024 07:20
@keroxp
Copy link
Contributor Author

keroxp commented Jan 17, 2024

@zxch3n Hi, would you have time to see this PR?

@MilanKovacic
Copy link
Collaborator

MilanKovacic commented Jan 18, 2024

I am also interested to hear if you are still interested in maintaining the project.

src/watch.ts Outdated
continue

if (type === 'test' && !(candidate instanceof TestCase))
if (task.type === 'test' && !(candidate instanceof TestCase))
Copy link
Member

Choose a reason for hiding this comment

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

What about type custom?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't understand what's type='custom'. It should be treated as which one? It seems to be newly introduced in v1.

Copy link
Member

@sheremet-va sheremet-va left a comment

Choose a reason for hiding this comment

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

Looks good! Just a few questions

@keroxp keroxp changed the title dev: adapt to vitest@1.2.0 dev: adapt to vitest@1.2 Feb 16, 2024
@sheremet-va sheremet-va merged commit b6de2b9 into vitest-dev:main Feb 16, 2024
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