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

feat: Add BA support for SvelteKit #126

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

nicholas-codecov
Copy link
Collaborator

Description

This PR adds in direct support for SvelteKit apps through the introduction of a new plugin that is tailored for SvelteKit.

Closes #94

Code Example

// vite.config.ts
import { sveltekit } from "@sveltejs/kit/vite";
import { defineConfig } from "vite";
import { codecovSvelteKitPlugin } from "@codecov/sveltekit-plugin";

export default defineConfig({
  plugins: [
    sveltekit(),
    // Put the Codecov SvelteKit plugin after all other plugins
    codecovSvelteKitPlugin({
      enableBundleAnalysis: true,
      bundleName: "example-sveltekit-bundle",
      uploadToken: process.env.CODECOV_TOKEN,
    }),
  ],
});

Notable Changes

  • Add in new @codecov/sveltekit-plugin
  • Add in example SvelteKit app
  • Add in integration tests for new plugin
  • Small tweaks

Copy link

codecov bot commented May 1, 2024

Codecov Report

Attention: Patch coverage is 28.85906% with 106 lines in your changes are missing coverage. Please review.

Project coverage is 77.88%. Comparing base (ddcd055) to head (72b56fd).

✅ All tests successful. No failed tests found.

Files Patch % Lines
packages/sveltekit-plugin/src/index.ts 0.00% 72 Missing and 1 partial ⚠️
...t-bundle-analysis/sveltekitBundleAnalysisPlugin.ts 50.00% 21 Missing ⚠️
packages/rollup-plugin/src/index.ts 0.00% 4 Missing ⚠️
packages/vite-plugin/src/index.ts 0.00% 4 Missing ⚠️
packages/webpack-plugin/src/index.ts 0.00% 4 Missing ⚠️
Additional details and impacted files
Components Coverage Δ
Plugin core 97.87% <ø> (ø)
Rollup plugin 10.44% <0.00%> (-0.12%) ⬇️
Vite plugin 10.60% <0.00%> (-0.13%) ⬇️
Webpack plugin 26.20% <0.00%> (-0.24%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

codecov bot commented May 1, 2024

Bundle Report

Changes will decrease total bundle size by 27.8kB ⬇️

Bundle name Size Change
@codecov/example-next-app-client-array-push 894.72kB 446 bytes ⬆️
@codecov/sveltekit-plugin-cjs 1.3kB 1.3kB ⬆️
@codecov/example-rollup-app-iife 95.45kB 0 bytes
@codecov/sveltekit-plugin-esm 909 bytes 909 bytes ⬆️
@codecov/bundler-plugin-core-cjs 41.95kB 0 bytes
@codecov/nuxt-plugin-cjs 1.38kB 0 bytes
@codecov/nuxt-plugin-esm 855 bytes 0 bytes
@codecov/bundler-plugin-core-esm 6.56kB 31.05kB ⬇️
@codecov/rollup-plugin-cjs 2.93kB 0 bytes
@codecov/vite-plugin-cjs 2.92kB 0 bytes
@codecov/webpack-plugin-cjs 3.56kB 0 bytes
@codecov/rollup-plugin-esm 1.32kB 155 bytes ⬆️
@codecov/vite-plugin-esm 1.26kB 153 bytes ⬆️
@codecov/webpack-plugin-esm 1.44kB 156 bytes ⬆️
@codecov/example-vite-app-esm 150.61kB 0 bytes
@codecov/example-webpack-app-array-push 71.19kB 0 bytes
@codecov/example-next-app-server-cjs 325.72kB 131 bytes ⬆️
@codecov/example-next-app-edge-server-array-push 306 bytes 0 bytes

@codecov-staging
Copy link

codecov-staging bot commented May 1, 2024

Bundle Report

Changes will decrease total bundle size by 210.88kB ⬇️

Bundle name Size Change
@codecov/rollup-plugin-cjs 2.93kB 0 bytes
@codecov/rollup-plugin-esm 1.32kB 155 bytes ⬆️
@codecov/bundler-plugin-core-esm 37.6kB 31.05kB ⬆️
@codecov/webpack-plugin-cjs 3.56kB 3.56kB ⬆️
@codecov/example-next-app-client-array-push 894.72kB 446 bytes ⬆️
@codecov/example-webpack-app-array-push 71.19kB 0 bytes
@codecov/nuxt-plugin-esm 855 bytes 0 bytes
@codecov/vite-plugin-cjs 2.92kB 0 bytes
@codecov/webpack-plugin-esm 1.44kB 156 bytes ⬆️
@codecov/sveltekit-plugin-esm 909 bytes 909 bytes ⬆️
@codecov/vite-plugin-esm 1.26kB 153 bytes ⬆️
@codecov/bundler-plugin-core-cjs 41.95kB 0 bytes
@codecov/example-next-app-server-cjs 325.72kB 131 bytes ⬆️
@codecov/example-next-app-edge-server-array-push 306 bytes 0 bytes
@codecov/example-rollup-app-iife (removed) 95.45kB ⬇️
@codecov/example-vite-app-esm (removed) 150.61kB ⬇️
@codecov/nuxt-plugin-cjs (removed) 1.38kB ⬇️

@AbhiPrasad AbhiPrasad self-requested a review May 22, 2024 14:44
bundleName = `${bundleName}-${dir}`;
}

format = format === "es" ? "esm" : format;
Copy link
Collaborator

Choose a reason for hiding this comment

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

l: let's avoid rebinding passed in parameters.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done, both here and in the Nuxt plugin 🫡

@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Codecov
Copyright (c) 2024 Codecov
Copy link
Collaborator

Choose a reason for hiding this comment

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

you actually want to use a date range here (2023-2024) if you update to latest year.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ouu ty ty for the catch

import { getBundleName } from "./getBundleName";

// @ts-expect-error this value is being replaced by rollup
const PLUGIN_NAME = __PACKAGE_NAME__ as string;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's define

declare global {
    __PACKAGE_NAME__: string;
   __PACKAGE_VERSION__: string;
}

in a TS declaration file somewhere so we can remove these. Feel free to do it in a follow up PR.

export function getBundleName(
initialName = "",
initialDir = "",
format: string,
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: this can be typed as ModuleFormat from rollup. Same as other places that use this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Would it be alright to re-export this type from the Vite bundler plugin package? And then import and use it in here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah that's fine!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hrrm it actually doesn't seem like Vite re-exports these types, soooo I'd have to install Rollup as a dev dep eh?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you grab the type from UnpluginOptions? Otherwise don't worry too much, we can leave it as is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Checked the options ... and no dice with that.

@codecov-notifications
Copy link

codecov-notifications bot commented May 23, 2024

Codecov Report

Attention: Patch coverage is 28.85906% with 106 lines in your changes are missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files Patch % Lines
packages/sveltekit-plugin/src/index.ts 0.00% 72 Missing and 1 partial ⚠️
...t-bundle-analysis/sveltekitBundleAnalysisPlugin.ts 50.00% 21 Missing ⚠️
packages/rollup-plugin/src/index.ts 0.00% 4 Missing ⚠️
packages/vite-plugin/src/index.ts 0.00% 4 Missing ⚠️
packages/webpack-plugin/src/index.ts 0.00% 4 Missing ⚠️
Components Coverage Δ
Plugin core 97.87% <ø> (ø)
Rollup plugin 10.44% <0.00%> (-0.12%) ⬇️
Vite plugin 10.60% <0.00%> (-0.13%) ⬇️
Webpack plugin 26.20% <0.00%> (-0.24%) ⬇️

📢 Thoughts on this report? Let us know!

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.

Support SvelteKit
2 participants