-
Notifications
You must be signed in to change notification settings - Fork 54
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
Build-Module can produce invalid module without raising error #101
Comments
I think those two cases should be looked at separately. For the no source files, when you build, say a MOF-based DSC resources, you do not require a PSM1/rootmodule. The second point is actually quite complex, because some errors can only be evaluated at runtime, and my be independent of the module itself (i.e. dependency missing, library failing to import, OS version, an so on...). I'll let @Jaykul share his vision for this tool, but in my opinion that should be covered by tests, and some of them are generic. |
I was debating whether I should open two threads or one. Ultimately settled on just opening one because I wasn't sure whether the maintainer of this module would even accept the premise that a module which can't even be loaded is invalid output. My scenario is that I am trying to get an efficient workflow for building & maintaining PowerShell modules. At present that seems to require multiple tools, some related and some not, along with either custom code to cobble everything together or a good memory for command lines and a healthy enjoyment of typing. Whether you are using a build script or manually executing commands for each step, it would help to know of a problem at the earliest possible step. Also, I thought that the build tool would be a logical place to detect/prevent glaring errors in build output which is why I am offering these suggestions. I don't know a ton about DSC but I looked at the PSDscResources module as an example, and that module's manifest just has RootModule commented out. This would be another good way to handle a case of no source files. However, it would surprise me if there were any situation where having a manifest that specifies RootModule to be a file which doesn't exist would be good. Regarding the errors, maybe it is a complex issue, but maybe the build tool could still help somewhat. I looked at the code for this module a bit, and I see it is already using the Parser in order to provide the "Moving Using statements" feature you mentioned. Why not at least report the other detected syntax errors? I see that conversion of line numbers from the module file to source is also already implemented so reporting the corresponding source locations would also be easy. After thinking about it more, I guess that misspelling a keyword (like |
Yeah it kinda does warn you about them IF it moved using statements. We've actually had to remove failing and warning the users because of #96 Maybe we could move that outside of
Nope, a function's parameter using a type that is not available would make that fail for instance. There are other corner cases. Just so you know, for DSC we use a template system with several tools & tests: https://github.com/gaelcolas/Sampler/tree/master/Sampler It uses ModuleBuilder, along with other things. |
Oops. My mistake. I thought it was ModuleBuilder setting that value. I forgot I had to create something to do that part. In that case you can ignore what I have said about the case with no source files. The followup question that immediately comes to my mind is why ModuleBuilder doesn't set that value when it does create a PSM1 since it is the one choosing the name of the PSM1 file. But maybe you would not be interested in that.
I think that would be helpful.
Not what I meant by command. I meant a cmdlet, alias, native command, etc.. Basically anything that would end up as a CommandAst in the syntax tree. Another way to put it would be the type of thing that Also, if I understand your example right, I don't think that would cause
Interesting. I will take a look. |
For starters, I agree with you -- building a module that won't import and then not failing or at least warning doesn't seem right. I mean, I'm always building a module so that I can run tests against it, so if it won't import, it will fail on the next step of the build anyway. It used to give up and fail if there were parse errors, but ...
Still, I'd be happier if we were sure it was going to import, so maybe we can:
So far as setting the |
I too am continually building modules in order to be able run tests, as well as in order to use platyPS. I have also begun trying to script some of this to make it quicker.
Warning if the PSM1 doesn't parse after moving using statements would catch some things and would be nice. However if you are considering actually importing the module as a test, it might be better to just do that and not bother to report the other parse errors because:
Yes, that is a concern. It one reason I didn't suggest trying to import the module. However you could try something like
Yeah, I kind of noticed some of that. That is why once I realized it wasn't ModuleBuilder setting that value in the manifest, I thought you might not be interested. In my opinion, since ModuleBuilder does not always create a .psm1 file, and since when it does it defines the file name, it would be nice if it updated |
In at least two cases, Build-Module produces a module which cannot be imported and does not generate an error:
It would be helpful if the tool responsible for building a script module could avoid producing output which cannot be imported and report an error when it is unable to do so.
If I were designing a build tool like this:
The text was updated successfully, but these errors were encountered: