Skip to content

disable directory submodule auto export#11157

Merged
amtoine merged 7 commits intonushell:mainfrom
amtoine:disable-directory-submodule-auto-export
Dec 15, 2023
Merged

disable directory submodule auto export#11157
amtoine merged 7 commits intonushell:mainfrom
amtoine:disable-directory-submodule-auto-export

Conversation

@amtoine
Copy link
Copy Markdown
Member

@amtoine amtoine commented Nov 26, 2023

should

Description

to allow more freedom when writing complex modules, we are disabling the auto-export of director modules.

the change was as simple as removing the crawling of files and modules next to any mod.nu and update the standard library.

User-Facing Changes

users will have to explicitely use export module <mod> to define submodules and export use <mod> <cmd> to re-export definitions, e.g.

# my-module/mod.nu
export module foo.nu     # export a submodule
export use bar.nu bar-1  # re-export an internal command

export def top [] {
    print "`top` from `mod.nu`"
}
# my-module/foo.nu
export def "foo-1" [] {
    print "`foo-1` from `lib/foo.nu`"
}

export def "foo-2" [] {
    print "`foo-2` from `lib/foo.nu`"
}
# my-module/bar.nu
export def "bar-1" [] {
    print "`bar-1` from `lib/bar.nu`"
}

Tests + Formatting

i had to add export module calls in the tests/modules/samples/spam directory module and allow the not_allowed module to not give an error, it is just empty, which is fine.

After Submitting

@amtoine amtoine added notes:breaking-changes This PR implies a change affecting users and has to be noted in the release notes A:modules Issues related to functionality of the module system. See also usage:modules labels Nov 26, 2023
@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented Nov 26, 2023

for now with

# mod.nu
export use lib/foo.nu

export def top [] {
    print "`top` from `mod.nu`"
}
# lib/foo.nu
export def "foo-1" [] {
    print "`foo-1` from `lib/foo.nu`"
}

export def "foo-2" [] {
    print "`foo-2` from `lib/foo.nu`"
}
  • use my-module will bring all the commands to scope
  • use my-module foo will run but foo foo-1 and foo foo-2 are not there

EDIT

i've added some temporary debug statements in dae78e1 and what i'm confused about for now is that the two use calls above both show

module: my-module
    sub: foo
        decl: foo-1
        decl: foo-2

as expected so i'm not sure where the issue comes from 😕

@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented Nov 26, 2023

actually i think this error does not have anything to do with the changes in this PR 🤔

i'm able to reproduce it with Nushell 0.87.1

this will bring the change made to `use foo bar baz` when `bar` is a
command of `foo` and not a submodule -> should give an error.
@kubouch
Copy link
Copy Markdown
Contributor

kubouch commented Dec 8, 2023

I see what it is. You need to use export module, not export use. There is a subtle difference. The following:

# my-module/mod.nu
export use lib/foo.nu

export def top [] {
    print "`top` from `mod.nu`"
}

will define three commands inside the module and export them: foo foo-1 and foo foo-2 coming from lib/foo.nu, and top. If you look at scope modules output, you'll see that my-module only contains these three commands. That's why use my-module foo doesn't do anything.

On the other hand:

# my-module/mod.nu
export module lib/foo.nu

export def top [] {
    print "`top` from `mod.nu`"
}

will define foo as a submodule of my-module, so you'll be able to call use my-module foo and it works as expected.

Basically, the rule of thumb is to always use export module, not export use (unless you do something specific, like re-exporting commands from somewhere else to be a part of the module).

There are two problems currently:

  1. use my-module foo should throw an error if foo isn't a valid alias/const/decl/submodule of my-module
  2. export use spam could export the spam submodule as well, so it would be the same as export module + re-exporting its commands etc. Although, the re-exporting is redundant, it's better to use export module, we might want to keep it as it is and rely on the error in 1.

@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented Dec 9, 2023

wow, thanks @kubouch, it appears to work very nice now 😮

let me fix the standard library tests 🙏

@amtoine amtoine added the notes:mention Include the release notes summary in the "Hall of Fame" section label Dec 9, 2023
@amtoine amtoine force-pushed the disable-directory-submodule-auto-export branch from d9af111 to 612ac01 Compare December 9, 2023 12:25
@amtoine amtoine marked this pull request as ready for review December 9, 2023 12:34
@amtoine amtoine requested a review from kubouch December 9, 2023 12:38
@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented Dec 10, 2023

Important
because it is quite a heavy change from the user's perspective, i think it would be better to wait for after the release to leave us the full 4 weeks to update our modules and tweaks things if necessary

@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented Dec 15, 2023

let's try this out 👍
i'll go ahead and fix the modules mentionned above today 😋

@amtoine amtoine merged commit 156232f into nushell:main Dec 15, 2023
@amtoine amtoine deleted the disable-directory-submodule-auto-export branch December 15, 2023 11:38
amtoine added a commit to amtoine/nu-git-manager that referenced this pull request Dec 15, 2023
depends on
- nushell/nushell#11157
- nushell/nupm#47
- #140
- #141

## description
as directory modules won't export the modules next to any `mod.nu`, this
PR adds `export module` calls to `nu-git-manager-sugar` and the tests,
making the source base compatible again with
nushell/nushell#11157 and
nushell/nupm#47.
@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented Dec 16, 2023

all the packages i know of have been fixed at that point 🆗

amtoine added a commit to amtoine/nu-git-manager that referenced this pull request Jan 21, 2024
depends on
- nushell/nushell#11157
- nushell/nupm#47
- #140
- #141

## description
as directory modules won't export the modules next to any `mod.nu`, this
PR adds `export module` calls to `nu-git-manager-sugar` and the tests,
making the source base compatible again with
nushell/nushell#11157 and
nushell/nupm#47.
dmatos2012 pushed a commit to dmatos2012/nushell that referenced this pull request Feb 20, 2024
should
- close nushell#11133

# Description
to allow more freedom when writing complex modules, we are disabling the
auto-export of director modules.

the change was as simple as removing the crawling of files and modules
next to any `mod.nu` and update the standard library.

# User-Facing Changes
users will have to explicitely use `export module <mod>` to define
submodules and `export use <mod> <cmd>` to re-export definitions, e.g.
```nushell
# my-module/mod.nu
export module foo.nu     # export a submodule
export use bar.nu bar-1  # re-export an internal command

export def top [] {
    print "`top` from `mod.nu`"
}
```
```nushell
# my-module/foo.nu
export def "foo-1" [] {
    print "`foo-1` from `lib/foo.nu`"
}

export def "foo-2" [] {
    print "`foo-2` from `lib/foo.nu`"
}
```
```nushell
# my-module/bar.nu
export def "bar-1" [] {
    print "`bar-1` from `lib/bar.nu`"
}
```

# Tests + Formatting
i had to add `export module` calls in the `tests/modules/samples/spam`
directory module and allow the `not_allowed` module to not give an
error, it is just empty, which is fine.

# After Submitting
- mention in the release note
- update the following repos
```
#┬─────name─────┬version┬─type─┬─────────repo─────────
0│nu-git-manager│0.4.0  │module│amtoine/nu-git-manager
1│nu-scripts    │0.1.0  │module│amtoine/scripts       
2│nu-zellij     │0.1.0  │module│amtoine/zellij-layouts
3│nu-scripts    │0.1.0  │module│nushell/nu_scripts    
4│nupm          │0.1.0  │module│nushell/nupm          
─┴──────────────┴───────┴──────┴──────────────────────
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:modules Issues related to functionality of the module system. See also usage:modules notes:breaking-changes This PR implies a change affecting users and has to be noted in the release notes notes:mention Include the release notes summary in the "Hall of Fame" section status:wait-until-after-nushell-release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

remove directory module autoexport

2 participants