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

Convert .ps1 to .psm1 #16

Open
vors opened this issue Mar 4, 2015 · 13 comments
Open

Convert .ps1 to .psm1 #16

vors opened this issue Mar 4, 2015 · 13 comments

Comments

@vors
Copy link
Collaborator

vors commented Mar 4, 2015

Modules is the preferred way to distribute reusable components.

@RamblingCookieMonster
Copy link
Owner

Agreed - any issue with a mild file re-org?

  • \Invoke-Parallel\
    • \Invoke-Parallel.psm1
  • \Tests\
    • \Invoke-Parallel.Tests.ps1
    • \AppVeyor-Pester.ps1 (abstracted calls to pester to test PS2 as well, example here)
  • \appveyor.yml
  • \README.md
  • \LICENSE.md

Let me know if you see any issues with this!

@vors
Copy link
Collaborator Author

vors commented Mar 4, 2015

Looks good

@vors
Copy link
Collaborator Author

vors commented Mar 4, 2015

Also, after that's done it would make sense to add .psd1 file and publish it to PsGet gallery (and maybe PowerShellGet gallery). .psd1 file would help with versioning (it's the only option to provide a version)

@RamblingCookieMonster
Copy link
Owner

Absolutely!

Running into a strange issue in the Restructure branch. Having moved to a psm1, the ImportVariable Pester tests are now failing to find the user's variables.

Global, Script, Local, 0, 1, and 2 all do not contain variables with name 'a' and 'long'. Running the same code in the pester test works in my local session:

Successful run outside of Pester:

image

Failed run in Pester (Added temporary verbose output to illustrate what Get-Variable can see)

The Pester test fails when invoked directly on my system as well (i.e. not an issue exclusive to appveyor.pester.ps1).

Will keep tinkering.

@RamblingCookieMonster
Copy link
Owner

Yeah, I can reproduce this, https://gist.github.com/RamblingCookieMonster/05552112507db8a04246

Learned something about scope and encapsulation!

I'm assuming this might be a mutually exclusive choice between moving to a module, and allowing ImportVariables to work in all scenarios?

Ugly alternative might be to have Invoke-Parallel.psd1, Invoke-Parallel.psm1, which load up Invoke-Parallel.ps1, allowing users to dot source Invoke-Parallel.ps1 outside the module if they want to use that functionality. Would need to vary the scope for the Get-Variable call.

This was referenced Mar 4, 2015
@vors
Copy link
Collaborator Author

vors commented Mar 4, 2015

That's interesting. I don't think it's mutually exclusive. Need to dig into it.

@RamblingCookieMonster
Copy link
Owner

Sheepish... Created a branch for the changes, committed changes to master. Heading out for caffeine. If it would make sense let me know and I can revert master and roll this in with a merge.

Sorry about that!

@vors
Copy link
Collaborator Author

vors commented Mar 4, 2015

No worries, I think it's fine to make a force push to master in this case.

@davidwallis
Copy link

How far did you get with this, is there a working module that can be used for executing a script block rather than dot sourcing?

@RamblingCookieMonster
Copy link
Owner

RamblingCookieMonster commented Sep 22, 2016

Nope, unfortunately, I've sort of let this project languish given the excellent PoshRSJob module by Boe. There are a few other issues that I might tackle, but this is pretty low on the priority list given what (I assume) it will take... unless we can just use ScriptsToProcess in the manifest?

If you have any ideas on how to implement this, or code, totally open to pull requests : D

Cheers!

@ImN1
Copy link

ImN1 commented Jul 10, 2017

Import-Modue Invoke-Parallel
$filelist | Invoke-Parallel -ImportVariables -Throttle 10 -ScriptBlock {
...

Get-RunspaceData : You cannot call a method on a null-valued expression.
At C:\Users\ImN1\Documents\WindowsPowerShell\Modules\Invoke-Parallel\Invoke-Parallel.psm1:542 char:13

  •         Get-RunspaceData -wait
    
  •         ~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (:) [Write-Error], RuntimeException
    • FullyQualifiedErrorId : InvokeMethodOnNull,Get-RunspaceData

but
No error by ". \PATH\Invoke-Parallel.ps1"

@sheldonhull
Copy link

fyi. This module needs to be dot sourced I believe. I have never had an error while using . Script while you probably are running into some scope issues with trying to import.

@RamblingCookieMonster I will say I've used both your project and the PoshRSJob. I find your script to be vastly simpler to implement most times. You did a great job on this!

@Silex
Copy link

Silex commented Jan 13, 2021

What is preventing this from moving forward?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants