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

fix(type): Add missing OptimizationSplitChunksNameFunction param #8707

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Lemonexe
Copy link

Summary

Add missing argument to type declaration of OptimizationSplitChunksNameFunction.

Notes

ℹ️ I have found this only empirically while migrating a webpack project to Rspack, but I have no experience with Rspack codebase, so it'd be appreciated if reviewers verified if the type declaration is appropriate.

The following excerpt of rspack.config.ts works correctly, but yields TS error (it is used to group shared chunks, e.g. shared/main-app~subprocess-app.js):

    optimization: {
        splitChunks: {
            chunks: 'all',
            // Rspack type declaration is missing the 2nd argument
            // @ts-expect-error Target signature provides too few arguments. Expected 2 or more, but got 1.
            name: (_module, chunks: Chunk[]) => {
                return chunks.length === 1
                    ? chunks[0].name
                    : `shared/${chunks.map((item: any) => item.name.split('/').pop()).join('~')}`;
            },
        },
    },

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@CLAassistant
Copy link

CLAassistant commented Dec 13, 2024

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot added the release: bug fix release: bug related release(mr only) label Dec 13, 2024
Copy link

netlify bot commented Dec 13, 2024

Deploy Preview for rspack canceled.

Built without sensitive environment variables

Name Link
🔨 Latest commit cc847d7
🔍 Latest deploy log https://app.netlify.com/sites/rspack/deploys/6762ac37857bb80008dc9ab5

@chenjiahan chenjiahan requested a review from JSerFeng December 17, 2024 14:20
Copy link
Member

@chenjiahan chenjiahan left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution! Can you update the related files too?

Comment on lines 2061 to 2064
export type OptimizationSplitChunksNameFunction = (
module?: Module,
chunks?: Chunk[]
) => unknown;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't know why the module parameter was optional in the previous definition. We can also add the missing cacheGroupKey parameter.

Suggested change
export type OptimizationSplitChunksNameFunction = (
module?: Module,
chunks?: Chunk[]
) => unknown;
export type OptimizationSplitChunksNameFunction = (
module: Module,
chunks: Chunk[],
cacheGroupKey: string
) => string | undefined;

Copy link
Author

Choose a reason for hiding this comment

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

Done as suggested 🙂
As @chenjiahan pointed out, I also updated the zod schema, which I hadn't known about.
I ran npm run api-extractor:local, but that produced a lot of diffs, idk if that seems right.

@Lemonexe Lemonexe force-pushed the fix/type-OptimizationSplitChunksNameFunction branch from 78daf6d to cc847d7 Compare December 18, 2024 11:04
@JSerFeng
Copy link
Collaborator

please rebase main so you can escape ci issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release: bug fix release: bug related release(mr only)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants