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

When the build task is run it should remove imported modules #87

Open
johlju opened this issue Dec 26, 2019 · 7 comments
Open

When the build task is run it should remove imported modules #87

johlju opened this issue Dec 26, 2019 · 7 comments
Labels
enhancement The issue is an enhancement request. help wanted The issue is up for grabs for anyone in the community.

Comments

@johlju
Copy link
Collaborator

johlju commented Dec 26, 2019

When the build task is run it should remove imported modules that exist in the folder Modules. The problem is that the modules remain imported after a build and any changes to the builds are not imported. The task Clean could remove any imported modules because it is run prior to the module is built.

@gaelcolas
Copy link
Owner

When you say "any changes to the builds". Can be more specific? I'm not sure if you're talking about -force importing the current module under test, or all dependencies?
re-importing all dependencies would probably have a performance impact and I'm not sure how useful it would be to have it by default.
🤔

@johlju
Copy link
Collaborator Author

johlju commented Dec 28, 2019

My thought was that the task Clean do Remove-Module on each module under /source/Modules. If not, every resource etc. must otherwise force import a module to get any changes during development.

@gaelcolas
Copy link
Owner

Thanks for clarification.
That sounds difficult to do accurately, as there's no guarantee as to how things under Modules is organised because we don't (can't) enforce it (is there a containing folder, does the PSM1 have the same base name than its parent folder, is there a psd1, is there nested/required modules...?).

We could list the top folders and Remove-Module $_.BaseName -EA SilentlyContinue but would that be enough?
Also, maintainers should understand this is not bullet proof (but I agree is a step in a good direction).

@johlju
Copy link
Collaborator Author

johlju commented Dec 28, 2019

Let’s assume that the top level folder have the same name as the module. If a module maintainer want to have the functionality they use that pattern, or they have to build there own task. So let’s go with your suggestion as that will solve the immediate problem (my issue). :)

@johlju johlju added enhancement The issue is an enhancement request. help wanted The issue is up for grabs for anyone in the community. labels Jan 19, 2020
@ben-eddy74
Copy link

To be able to test modifications after build, I added a ReImport task to the build workflow, and added the following script block:

  ReImport: |
    {
      Import-Module MyModule -Force
    }

I couldn't find a variable instead of hard coding the module's name

@johlju
Copy link
Collaborator Author

johlju commented Aug 9, 2024

Try this:

https://github.com/viscalyx/PesterConverter/blob/dca329b731839956d78b873c37cdc0e869b8f9d3/build.yaml#L45

Have been meaning to add this as a task to Sampler. Thought it only works as long as the module does not use classes or assemblies that change between builds.

This is run before the clean meta task. It might run as part of the clean meta task when added as a task to Sampler. 🤔

@ben-eddy74
Copy link

Thanks @johlju, it works. This solution is good enough for me as I don't use classes/assemblies (yet).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement The issue is an enhancement request. help wanted The issue is up for grabs for anyone in the community.
Projects
None yet
Development

No branches or pull requests

3 participants