-
Notifications
You must be signed in to change notification settings - Fork 342
feat!: move package to ESM only #1078
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
988967b
edb07a4
6c6c831
f69dcb0
aed7f91
7bd44b3
fd1c924
14ab05a
a161641
be6d967
779a6a9
5c6d957
757ff79
e8e2237
824e294
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// only for build, excluded from the package | ||
declare module '@nuxt/schema' { | ||
import type { InlinePreset, UnimportOptions } from 'unimport' | ||
export type HookResult = Promise<void> | void | ||
export interface ImportPresetWithDeprecation extends InlinePreset { | ||
} | ||
export interface ImportsOptions extends UnimportOptions {} | ||
export interface Component { | ||
pascalName: string; | ||
kebabName: string; | ||
export: string; | ||
filePath: string; | ||
shortPath: string; | ||
chunkName: string; | ||
prefetch: boolean; | ||
preload: boolean; | ||
global?: boolean; | ||
island?: boolean; | ||
mode?: 'client' | 'server' | 'all'; | ||
/** | ||
* This number allows configuring the behavior of overriding Nuxt components. | ||
* If multiple components are provided with the same name, then higher priority | ||
* components will be used instead of lower priority components. | ||
*/ | ||
priority?: number; | ||
} | ||
export interface NuxtHooks { | ||
'imports:sources': (presets: ImportPresetWithDeprecation[]) => HookResult | ||
'components:extend': (components: Component[]) => HookResult | ||
} | ||
export interface Nuxt { | ||
options: { | ||
build: { | ||
transpile: string[] | ||
} | ||
css: string[] | ||
imports: ImportsOptions | ||
} | ||
hook: <H extends keyof NuxtHooks>(hook: H, callback: NuxtHooks[H]) => void | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { defineNuxtModule } from '@nuxt/kit' | ||
import type { FloatingVueDirectivesOptions } from 'floating-vue/directives' | ||
import type { FloatingVueComponentsOptions } from 'floating-vue/components' | ||
|
||
export interface FloatingVueNuxtOptions { | ||
directives?: FloatingVueDirectivesOptions | ||
components?: FloatingVueComponentsOptions | ||
} | ||
|
||
const _default: ReturnType<typeof defineNuxtModule> | ||
|
||
export default _default |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { defineNuxtModule } from '@nuxt/kit' | ||
import type { FloatingVueDirectivesOptions } from 'floating-vue/directives' | ||
import type { FloatingVueComponentsOptions } from 'floating-vue/components' | ||
|
||
export interface FloatingVueNuxtOptions { | ||
directives?: FloatingVueDirectivesOptions | ||
components?: FloatingVueComponentsOptions | ||
} | ||
|
||
const _default: ReturnType<typeof defineNuxtModule> | ||
|
||
export default _default |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,48 @@ | ||
export default async function (_, _nuxt) { | ||
import { | ||
FloatingVueDirectives, | ||
enableDirectives, | ||
prepareFloatingVueComponents, | ||
} from 'floating-vue/unimport-presets' | ||
|
||
/** | ||
* Nuxt module implementation. | ||
* @param options {import('./nuxt').FloatingVueNuxtOptions} | ||
* @param _nuxt {import('@nuxt/schema').Nuxt} | ||
* @returns {Promise<void>} | ||
*/ | ||
export default async function (options = {}, _nuxt) { | ||
const { addPluginTemplate } = await import('@nuxt/kit') | ||
|
||
/** @type {import('@nuxt/schema').Nuxt} */ | ||
const nuxt = (this && this.nuxt) || _nuxt | ||
|
||
const imports = nuxt.options.imports | ||
imports.addons = enableDirectives(imports.addons) | ||
|
||
nuxt.hook('imports:sources', (sources) => { | ||
sources.push( | ||
FloatingVueDirectives(options.directives), | ||
) | ||
}) | ||
|
||
nuxt.hook('components:extend', async (registry) => { | ||
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. Remove async 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. I guess we don't need the plugin using Nuxt auto-import stuff: just register the plugin if imports is disabled. We should add a new option to the module to use auto-import or global registration. |
||
const c = prepareFloatingVueComponents(options.components) | ||
for (const component of c) { | ||
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. Move prepare to the for loop |
||
registry.push({ | ||
pascalName: component.pascalName, | ||
kebabName: component.kebabName, | ||
export: component.export, | ||
filePath: component.filePath, | ||
shortPath: component.filePath, | ||
chunkName: component.kebabName, | ||
prefetch: false, | ||
preload: false, | ||
global: false, | ||
mode: 'all', | ||
}) | ||
} | ||
}) | ||
|
||
nuxt.options.css.push('floating-vue/dist/style.css') | ||
|
||
addPluginTemplate({ | ||
|
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.
review this, I guess we should add a
nuxt.ts
and generate the module properly...