-
Notifications
You must be signed in to change notification settings - Fork 160
rolldown-vite -> vite8 #2687
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
Merged
Merged
rolldown-vite -> vite8 #2687
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
132e94f
wip: rolldown-vite -> vite8
NullVoxPopuli cc71e61
The rollup PluginContext type is no longer valid
NullVoxPopuli ab74837
Use rolldown types instead of rollup
NullVoxPopuli a95dc9c
lint:fix
NullVoxPopuli c74d6be
Missed one vite-rolldown -> vite-8
NullVoxPopuli faeb4e1
Bring back PluginContext in the hbs plugin
NullVoxPopuli 698f6ca
Refactor rolldownOptions and rollupOptions input handling
NullVoxPopuli 0e6f242
Refactor rolldownOptions and rollupOptions input handling
NullVoxPopuli d8c20eb
lint:fix
NullVoxPopuli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,11 @@ | ||
| import { existsSync } from 'fs'; | ||
| import { templateTag } from './template-tag.js'; | ||
| import { resolver } from './resolver.js'; | ||
| import type { UserConfig as ViteUserConfig, ConfigEnv, Plugin } from 'vite'; | ||
| import type { UserConfig as RolldownUserConfig } from 'rolldown-vite'; | ||
| import type { ConfigEnv, Plugin } from 'vite'; | ||
|
|
||
| import { esBuildResolver } from './esbuild-resolver.js'; | ||
| import { warnRootUrl } from './warn-root-url.js'; | ||
| import type { ViteUserConfig as UserConfig, Vite8UserConfig } from './types.js'; | ||
|
|
||
| export let extensions = ['.mjs', '.gjs', '.js', '.mts', '.gts', '.ts', '.hbs', '.hbs.js', '.json']; | ||
|
|
||
|
|
@@ -16,8 +16,9 @@ export const defaultRolldownSharedPlugins = [ | |
| 'babel', | ||
| ]; | ||
|
|
||
| // We support a range of vite versions with different types here | ||
| type UserConfig = ViteUserConfig & RolldownUserConfig; | ||
| function hasRolldown(pluginContext: any, _config: unknown): _config is Vite8UserConfig { | ||
| return Boolean(pluginContext?.meta?.rolldownVersion); | ||
| } | ||
|
|
||
| export function ember(params?: { | ||
| /** | ||
|
|
@@ -37,107 +38,99 @@ export function ember(params?: { | |
| async config(config: UserConfig, env: ConfigEnv) { | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. some of this was reorganized so I had an easier time narrowing types with the above hasRolldown fn |
||
| // Default vite resolve extensions, which the user can completely | ||
| // override if they want | ||
| if (!config.resolve) { | ||
| config.resolve = {}; | ||
| } | ||
| config.resolve ||= {}; | ||
| config.build ||= {}; | ||
| config.server ||= {}; | ||
| config.optimizeDeps ||= {}; | ||
| config.optimizeDeps.exclude ||= []; | ||
| config.optimizeDeps.extensions ||= []; | ||
|
|
||
| if (!config.resolve.extensions) { | ||
| config.resolve.extensions = extensions; | ||
| } | ||
|
|
||
| // Our esbuild integration only works if these extensions are | ||
| // configured, so we force them in | ||
| if (!config.optimizeDeps) { | ||
| config.optimizeDeps = {}; | ||
| } | ||
| if (!config.optimizeDeps.extensions) { | ||
| config.optimizeDeps.extensions = []; | ||
| } | ||
| for (let requiredExt of ['.hbs', '.gjs', '.gts']) { | ||
| if (!config.optimizeDeps.extensions.includes(requiredExt)) { | ||
| config.optimizeDeps.extensions.push(requiredExt); | ||
| } | ||
| } | ||
|
|
||
| // @embroider/macros needs to not go through dep optimization | ||
| if (config.optimizeDeps.exclude) { | ||
| config.optimizeDeps.exclude.push('@embroider/macros'); | ||
| } else { | ||
| config.optimizeDeps.exclude = ['@embroider/macros']; | ||
| } | ||
|
|
||
| // @ts-expect-error the types aren't finished yet it would seem | ||
| if (this?.meta?.rolldownVersion) { | ||
| // configure our embroider resolver for optimize deps | ||
| if (!config.optimizeDeps.rollupOptions) { | ||
| config.optimizeDeps.rollupOptions = {}; | ||
| } | ||
|
|
||
| const emberRollupPlugins = sharedRolldownPlugins( | ||
| params?.rolldownSharedPlugins ?? defaultRolldownSharedPlugins, | ||
| config.plugins | ||
| ); | ||
|
|
||
| if (config.optimizeDeps.rollupOptions.plugins) { | ||
| if (Array.isArray(config.optimizeDeps.rollupOptions.plugins)) { | ||
| config.optimizeDeps.rollupOptions.plugins.push(...emberRollupPlugins); | ||
| } else { | ||
| throw new Error('Could not automatically configure the Ember plugin for optimizeDeps'); | ||
| } | ||
| } else { | ||
| config.optimizeDeps.rollupOptions.plugins = emberRollupPlugins; | ||
| config.optimizeDeps.exclude.push('@embroider/macros'); | ||
|
|
||
| const emberRollupPlugins = sharedRolldownPlugins( | ||
| params?.rolldownSharedPlugins ?? defaultRolldownSharedPlugins, | ||
| config.plugins | ||
| ); | ||
|
|
||
| if (hasRolldown(this, config)) { | ||
| /** | ||
| * Vite 8 and higher | ||
| */ | ||
| config.optimizeDeps.rolldownOptions ||= {}; | ||
| config.optimizeDeps.rolldownOptions.plugins ||= []; | ||
| if (!Array.isArray(config.optimizeDeps.rolldownOptions.plugins)) { | ||
| throw new Error( | ||
| 'Could not automatically configure the Ember plugin for optimizeDeps. optimizeDeps.rolldownOptions.plugins must be an array.' | ||
| ); | ||
| } | ||
| config.optimizeDeps.rolldownOptions.plugins.push(...emberRollupPlugins); | ||
|
|
||
| if (!config.optimizeDeps.rollupOptions.resolve) { | ||
| config.optimizeDeps.rollupOptions.resolve = {}; | ||
| } | ||
| config.optimizeDeps.rollupOptions.resolve.extensions = extensions; | ||
| config.optimizeDeps.rolldownOptions.resolve ||= {}; | ||
| config.optimizeDeps.rolldownOptions.resolve.extensions = extensions; | ||
| } else { | ||
| // configure out esbuild resolver | ||
| if (!config.optimizeDeps.esbuildOptions) { | ||
| config.optimizeDeps.esbuildOptions = {}; | ||
| } | ||
|
|
||
| if (config.optimizeDeps.esbuildOptions.plugins) { | ||
| config.optimizeDeps.esbuildOptions.plugins.push(esBuildResolver()); | ||
| } else { | ||
| config.optimizeDeps.esbuildOptions.plugins = [esBuildResolver()]; | ||
| } | ||
| } | ||
|
|
||
| if (!config.build) { | ||
| config.build = {}; | ||
| } | ||
|
|
||
| if (!config.build.rollupOptions) { | ||
| config.build.rollupOptions = {}; | ||
| /** | ||
| * Vite 7 and lower | ||
| */ | ||
| config.optimizeDeps.esbuildOptions ||= {}; | ||
| config.optimizeDeps.esbuildOptions.plugins ||= []; | ||
| config.optimizeDeps.esbuildOptions.plugins.push(esBuildResolver()); | ||
| } | ||
|
|
||
| // we provide a default build.rollupOptions.input that builds index.html | ||
| // and, in non-production or when forcing tests, tests/index.html. But | ||
| // the user may choose to take charge of input entirely. | ||
| if (!config.build.rollupOptions.input) { | ||
| let hasRootEntry = existsSync('index.html'); | ||
| let hasTestsEntry = existsSync('tests/index.html'); | ||
| let hasRootEntry = existsSync('index.html'); | ||
| let hasTestsEntry = existsSync('tests/index.html'); | ||
|
|
||
| config.build.rollupOptions.input = {}; | ||
| if (!config.build.rolldownOptions?.input) { | ||
| if (hasRolldown(this, config)) { | ||
| config.build.rolldownOptions ||= {}; | ||
|
|
||
| if (hasRootEntry) { | ||
| Object.assign(config.build.rollupOptions.input, { | ||
| main: 'index.html', | ||
| }); | ||
| } | ||
| if (hasRootEntry) { | ||
| config.build.rolldownOptions.input ||= {}; | ||
| Object.assign(config.build.rolldownOptions.input, { | ||
| main: 'index.html', | ||
| }); | ||
| } | ||
|
|
||
| if (hasTestsEntry) { | ||
| if (shouldBuildTests(env.mode)) { | ||
| config.build.rolldownOptions.input ||= {}; | ||
| Object.assign(config.build.rolldownOptions.input, { | ||
| tests: 'tests/index.html', | ||
| }); | ||
| } | ||
| } | ||
| } else { | ||
| config.build.rollupOptions ||= {}; | ||
|
|
||
| if (hasTestsEntry) { | ||
| if (shouldBuildTests(env.mode)) { | ||
| if (hasRootEntry) { | ||
| config.build.rollupOptions.input ||= {}; | ||
| Object.assign(config.build.rollupOptions.input, { | ||
| tests: 'tests/index.html', | ||
| main: 'index.html', | ||
| }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (!config.server) { | ||
| config.server = {}; | ||
| if (hasTestsEntry) { | ||
| if (shouldBuildTests(env.mode)) { | ||
| config.build.rollupOptions.input ||= {}; | ||
| Object.assign(config.build.rollupOptions.input, { | ||
| tests: 'tests/index.html', | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Traditional ember development port as default. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
void-mAlex marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import type { UserConfig as ActualViteUserConfig } from 'vite'; | ||
|
|
||
| /** | ||
| * We support a range of vite versions with different types here | ||
| * | ||
| * These subconfigs are minimally what we use, as we don't want to maintain | ||
| * types for someone else's package. | ||
| * | ||
| * This exists at all because we support vite 5 through vite 8 (as of 2025-03-17) | ||
| * and there isn't a package with these types available for us. | ||
| * The types are internal only, and we *should* have enough testing where if we mess | ||
| * something up, runtime catches us. | ||
| */ | ||
| export type ViteUserConfig = (ActualViteUserConfig & Vite8UserConfig) | (ActualViteUserConfig & Vite7UserConfig); | ||
|
|
||
| /** | ||
| * The sub-types for things we configure in src/ember.ts | ||
| * | ||
| * I expect htis sort of plucking types to be sufficient for our use case, | ||
| * because Vite's configure only renamed and moved a couple things we're using, | ||
| * and they are roughly (or exactly) the same shape of things | ||
| */ | ||
| type RolldownOptions = NonNullable<NonNullable<ActualViteUserConfig['optimizeDeps']>['rolldownOptions']>; | ||
| type Resolve = RolldownOptions['resolve']; | ||
| type Plugins = RolldownOptions['plugins']; | ||
|
|
||
| /** | ||
| * Subset of: | ||
| * https://npmx.dev/package-code/vite/v/8.0.0/dist%2Fnode%2Findex.d.ts | ||
| * | ||
| * (but since the current version *is* 8, we only need the brand type here) | ||
| */ | ||
| export interface Vite8UserConfig { | ||
| // Private brand type | ||
| __vite8__: true; | ||
| } | ||
|
|
||
| /** | ||
| * Subset of: | ||
| * https://npmx.dev/package-code/vite/v/7.3.1/dist%2Fnode%2Findex.d.ts | ||
| */ | ||
| interface Vite7UserConfig { | ||
| optimizeDeps?: { | ||
| esbuildOptions?: { | ||
| resolve?: Resolve; | ||
| plugins?: Plugins; | ||
| }; | ||
| }; | ||
| // Private brand type | ||
| __vite7__: true; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kinda silly this is the latest release, but we're just using it for types