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

Can't use the same filename twice in the project #8

Open
kehwar opened this issue Jun 21, 2023 · 1 comment
Open

Can't use the same filename twice in the project #8

kehwar opened this issue Jun 21, 2023 · 1 comment

Comments

@kehwar
Copy link
Contributor

kehwar commented Jun 21, 2023

Using the same filename twice in the project leads to this

// .nuxt/remote-handler.ts
import * as todo from '.../feature-A/todo.server'
import * as todo from '.../feature-B/todo.server'

export type RemoteFunction = {
  todo: typeof todo
  todo: typeof todo
}

export default createRemoteFnHandler({
  todo,
  todo
})

Which breaks the module

@kehwar
Copy link
Contributor Author

kehwar commented Jun 21, 2023

I propose using the full (relative) path to the file when extracting the module id

// current
expect(getModuleId('/src/feature-A/todo.server.ts')).toBe('todo')

// proposed
expect(getModuleId('/src/feature-A/todo.server.ts')).toBe('feature_A__todo')

The path would be relative the source directory: nuxt.options.srcDir
A double underscore should be enough to avoid accidental duplicates, though it could be a configuration option

Cons of this approach:

  • createClient becomes more verbose, specially with deeply nested files
  • Deeply nested files could also make really long urls
  • Exposes project structure to the frontend (probably not an issue)
  • Breaking change if createClient is already used

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

No branches or pull requests

1 participant