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

feat(module): allow adding module to Nuxt config within layer #380

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/commands/module/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export default defineCommand({
type: 'boolean',
description: 'Skip nuxt.config.ts update',
},
layer: {
type: 'string',
description: 'Layer name',
},
},
async setup(ctx) {
const cwd = resolve(ctx.args.cwd || '.')
Expand Down Expand Up @@ -88,7 +92,9 @@ export default defineCommand({

// Update nuxt.config.ts
if (!ctx.args.skipConfig) {
await updateNuxtConfig(cwd, (config) => {
const rootDir = ctx.args.layer ? resolve(cwd, ctx.args.layer) : cwd
Copy link
Member

Choose a reason for hiding this comment

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

Without considering layer names, isn’t it same as —cwd ?

Copy link
Member Author

@DamianGlowala DamianGlowala Mar 30, 2024

Choose a reason for hiding this comment

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

I think setting --cwd pointing to the layer dir would affect other places as well, e.g. where module add looks for package.json or where it adds a dependency using nypm util. Correct me if I'm wrong though.

(There might be a better way to achieve it as well, let me know if you have any idea.)

Copy link
Member

@pi0 pi0 Mar 30, 2024

Choose a reason for hiding this comment

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

I think what is expected is that the module is added to the closest package.json and nuxt.config files found to the specified cwd. (ie: We need a look-up search for both). nypm should do this via package managers by default.

I think it would probably be best first action to resolve any issues that prevents this.

—-

In next steps, —layer would be also good idea but i expect that it loads nuxt.config, and tries to match a layer by its name (which used in extends key) basically as a convenient shortcut and also it should implement safety check that we don’t write to readonly (remote or dependency) layers but instead ask to directly add to the root.


await updateNuxtConfig(rootDir, (config) => {
if (!config.modules) {
config.modules = []
}
Expand Down
Loading