Skip to content

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

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

Conversation

userquin
Copy link

@userquin userquin commented May 11, 2025

This PR doesn't include type module, we can do it later.

This PR includes:

  • move the package to ESM-only: all CJS stuff removed
  • add unimport-presets subpackage export for directives: I will also include a new preset to use Nuxt components loaders and some utilities here => this subpackage export can be used also with unplugin-auto-import, check the demo playground
  • add directives subpackage export
  • add components subpackage export
  • add utils subpackage export
  • add script to patch the build:
    • remove static css imports from index.d.ts
    • add d.mts variants for modules and vue components
    • fix d.mts files with correct .mjs imports (static and dynamic imports)

Later I will add also a new unplugin-vue-components-resolvers subpackage export to allow use directives and components via unplugin-vue-components: 2 new resolvers for directives and components.

For context, check my unvuetify monorepo.

TODO:

  • remove components from index module
  • include vue files in the dist/components (copy them): right now we're "exporting" the components twice
  • move repo to ESM-only (add type module to all package.json)
  • add unplugin-vue-components-resolvers
  • add unimport presets for utils (composables)
  • add Nuxt components utils to enable directives and register components
  • review root components stuff, maybe we only want to export VDropdown, VTooltip and VMenu components (right now exporting everything).
  • configure the repo correctly, running the demo without some changes doesn't work: include tsconfig.json at root with all the subpackage exports and try to figureout how can we remove the resolve.alias from the playground (check feat!: move package to ESM only #1078 (comment))
  • remove deprecated entries: directives and components in the index.ts module
  • include logic to register directives and component in Nuxt module
  • include all issue about directives, with current unimport preset VSCode and any JetBrains IDE should suggest them
  • add migration guide, should be easy: add also new features to the docs somewhere
  • try using new resolvers and presets in the docs and the playground
Migration if using imports:
import {
  // Directives
  vTooltip,
  vClosePopper,
  // Components
  VDropdown,
  VTooltip,
  VMenu,
  // Utitlities
  SHOW_EVENT_MAP,
  placements
} from 'floating-vue'

to

// Directives
import { vTooltip, vClosePopper } from 'floating-vue/directives'
// Components
import { VDropdown, VTooltip, VMenu } from 'floating-vue/components'
// Utilities
import { SHOW_EVENT_MAP, placements } from 'floating-vue/utils'

image

Copy link

netlify bot commented May 11, 2025

Deploy Preview for v-tooltip ready!

Name Link
🔨 Latest commit 824e294
🔍 Latest deploy log https://app.netlify.com/sites/v-tooltip/deploys/682120547edce00008d6b196
😎 Deploy Preview https://deploy-preview-1078--v-tooltip.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Hello @userquin, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request migrates the floating-vue package to be an ESM-only module. This involves removing CJS artifacts, and introducing subpackage exports for directives, unimport presets, components, and utils. A patching script is added to handle post-build adjustments, including removing static CSS imports from index.d.ts, adding .d.mts variants, and fixing .mjs imports in declaration files. The demo application is also updated to reflect these changes, including adding unplugin-auto-import to showcase the new unimport presets.

Highlights

  • ESM-only Migration: The package is now ESM-only, with all CJS-related code removed.
  • Subpackage Exports: New subpackage exports are added for directives, unimport presets, components, and utils.
  • Build Patching: A script is introduced to patch the build, handling tasks like CSS import removal and .d.mts file generation.
  • Demo Updates: The demo application is updated to use the new ESM modules and unplugin-auto-import.

Changelog

Click here to see the changelog
  • demo/package.json
    • Added @tsconfig/node22 and @vue/tsconfig as dev dependencies.
    • Added unplugin-auto-import and unimport as dev dependencies.
    • Added vue-tsc and typescript as dev dependencies.
  • demo/src/views/directive/VTooltipDemo1.vue
    • Added a <script lang="ts"> block to the component.
  • demo/tsconfig.app.json
    • Added composite and tsBuildInfoFile compiler options.
    • Added baseUrl and paths compiler options to map floating-vue and floating-vue/directives to their source files.
  • demo/tsconfig.json
    • Added references to tsconfig.node.json and tsconfig.app.json.
  • demo/tsconfig.node.json
    • Added composite and tsBuildInfoFile compiler options.
    • Set module to ESNext and moduleResolution to Bundler.
    • Added paths compiler options to map floating-vue and floating-vue/directives to their source files.
    • Set noEmit to true.
  • demo/vite.config.ts
    • Imported AutoImport from unplugin-auto-import/vite and FloatingVueDirectives from floating-vue/unimport-presets.
    • Added resolve aliases for floating-vue modules.
    • Added VERSION define.
    • Added AutoImport plugin with FloatingVueDirectives.
  • package.json
    • Moved floating-vue from devDependencies to dependencies.
    • Added @types/node as a dev dependency.
    • Added unimport and unplugin-vue-components as dev dependencies.
  • packages/floating-vue/components.d.mts
    • Created a new file to export component definitions with .mjs extensions.
  • packages/floating-vue/components.d.ts
    • Created a new file to export component definitions.
  • packages/floating-vue/components.js
    • Created a new file to export components with .js extensions.
  • packages/floating-vue/components.mjs
    • Created a new file to export components with .mjs extensions.
  • packages/floating-vue/directives.d.ts
    • Created a new file to export directive definitions.
  • packages/floating-vue/package.json
    • Updated main, module, types, and exports fields to reflect ESM-only structure.
    • Added new exports for components, directives, utils, and unimport-presets.
    • Added new files to the files array.
    • Added unimport and unplugin-vue-components as peer dependencies.
    • Added unimport and unplugin-vue-components to peerDependenciesMeta.
  • packages/floating-vue/scripts/patch-build.mjs
    • Created a new file containing a script to patch the build output, including removing CSS imports and creating .d.mts files.
  • packages/floating-vue/src/components.ts
    • Created a new file to export components.
  • packages/floating-vue/src/components/PopperWrapper.vue
    • Updated import path for Placement type from ../util/popper.js to ../utils.
  • packages/floating-vue/src/directives.ts
    • Created a new file to export directives.
  • packages/floating-vue/src/index.ts
    • Replaced exports from ./util/events and ./util/popper with exports from ./utils.
  • packages/floating-vue/src/node/types.ts
    • Created a new file to define types for directives and unimport presets.
  • packages/floating-vue/src/unimport-presets.ts
    • Created a new file to define unimport presets for directives.
  • packages/floating-vue/src/utils.ts
    • Created a new file to export utility functions.
  • packages/floating-vue/tsconfig.json
    • Excluded src/node/** from compilation.
  • packages/floating-vue/unimport-presets.d.ts
    • Created a new file to export unimport presets definitions.
  • packages/floating-vue/utils.d.ts
    • Created a new file to export utils definitions.
  • packages/floating-vue/vite.config.ts
    • Updated lib.entry to include multiple entry points.
    • Added unimport and floating-vue/directives to rollupOptions.external.
  • pnpm-lock.yaml
    • Updated dependencies and devDependencies to reflect the changes in package.json files.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


To ESM we stride,
CJS fades into the night,
Modern modules rise.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request migrates the floating-vue package to ESM-only, which is a significant change. It also introduces new subpackage exports and build script modifications. The changes seem well-structured, but let's examine a few areas for potential improvements and clarifications.

Summary of Findings

  • Missing JSDoc comments: Several functions in packages/floating-vue/scripts/patch-build.mjs lack JSDoc comments, which could hinder maintainability and understanding of the code.
  • Inconsistent import patching: The patchFileImports and patchFile functions in packages/floating-vue/scripts/patch-build.mjs appear to perform similar tasks but use different approaches. Consider consolidating them for better consistency.
  • Hardcoded paths in vite.config.ts: The resolve function in demo/vite.config.ts uses hardcoded paths, which might not be portable across different environments. Consider using relative paths or environment variables.

Merge Readiness

The pull request introduces significant changes and requires careful review. While the overall structure seems sound, addressing the identified issues and ensuring thorough testing are crucial before merging. I am unable to directly approve this pull request, and recommend that others review and approve this code before merging. At a minimum, the high severity issues should be addressed before merging.

@userquin userquin marked this pull request as draft May 11, 2025 17:43
@userquin userquin marked this pull request as ready for review May 11, 2025 19:11
@userquin
Copy link
Author

userquin commented May 11, 2025

/gemini review

@userquin
Copy link
Author

userquin commented May 11, 2025

I still need to do some more checks and change the build to use only ESM format in vite rollup options, some steps in the patch script won't be required.

I'm going to check also using unbuild/tsdown to generate the dist.

)
})

nuxt.hook('components:extend', async (registry) => {
Copy link
Author

Choose a reason for hiding this comment

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

Remove async

Copy link
Author

@userquin userquin May 12, 2025

Choose a reason for hiding this comment

The 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.


nuxt.hook('components:extend', async (registry) => {
const c = prepareFloatingVueComponents(options.components)
for (const component of c) {
Copy link
Author

@userquin userquin May 11, 2025

Choose a reason for hiding this comment

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

Move prepare to the for loop

"types": ["node"],
"paths": {
"floating-vue/directives": ["../packages/floating-vue/src/directives.ts"],
"floating-vue": ["../packages/floating-vue/src/index.ts"]
Copy link
Author

Choose a reason for hiding this comment

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

we need to add tsc-alias as dev dependency, unbuild or tsdown will resolve these entries, vite requires resolve.alias

Copy link
Author

Choose a reason for hiding this comment

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

tsdown doesn't support stubbing yet...

components?: FloatingVueComponentsOptions
}

const _default: ReturnType<typeof defineNuxtModule>
Copy link
Author

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...

@Mister-Hope
Copy link

Mister-Hope commented May 25, 2025

Could you release a forked version of this and maintain this project?

For me, the project doesn't seem to be active maintained, the last release was already years ago, downstream VitePress and VuePress are suffering with some a11y issues and SSR mismatches with some bugs. I was just planning to create a fork on VuePress org (e.g.: vuepress/ecosystem#477) then I saw this, and this could be the hugest refactor among all PRs, so it could be great if you are interested in maintaining a forked edition and cherry pick some existing PRs with new version being released.

Looking forward with your reply, if you are not interested, then I will release a fork of this soon with our bugs fixed.

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.

2 participants