Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Installing the same plugin twice leads to a failed install. #100

Closed
ghost opened this issue Nov 1, 2018 · 15 comments · Fixed by #116
Closed

Installing the same plugin twice leads to a failed install. #100

ghost opened this issue Nov 1, 2018 · 15 comments · Fixed by #116
Labels
bug Something isn't working plugins This issue involves the Plugin Facility

Comments

@ghost
Copy link

ghost commented Nov 1, 2018

I ran a plugin install from zowe-cli using the same plugin twice.

First Run

zd plugins install @brightside/cics
Imperative CLI Framework plug-ins can gain control of your CLI application
legitimately during the execution of every command. Install 3rd party plug-ins
at your own risk. CA Technologies makes no warranties regarding the use of
3rd party plug-ins.

Imperative's plugin installation program handles peer dependencies for modules
in the @brightside namespace and missing package.json file,
so you can safely ignore NPM warnings about
missing peer dependencies related to @brightside modules and absent C:\dev\.zowe\plugins\installed\package.json file.
Registry = https://gizaartifactory.jfrog.io/gizaartifactory/api/npm/npm-release/

_______________________________________________________________
npm WARN enoent ENOENT: no such file or directory, open 'C:\dev\.zowe\plugins\installed\package.json'
npm WARN @brightside/[email protected] requires a peer of @brightside/[email protected] but none is installed. You must install peer dependencies yourself.
npm WARN @brightside/[email protected] requires a peer of @brightside/[email protected] but none is installed. You must install peer dependencies yourself.

+ @brightside/[email protected]
added 391 packages from 817 contributors in 30.952s
Installed plugin name = '@brightside/cics'

_____ Validation results for plugin '@brightside/cics' _____

*** Warning: The version value (1.x) of the plugin's '@brightside/core' property is incompatible with the version value (2.0.0-next.201810311458) of the zowe command's 'version' property.

*** Warning: The plugin's configuration does not contain an 'imperative.pluginHealthCheck' property.

This plugin has warnings, but its commands and framework overrides will still be available.

Second Run

zd plugins install @brightside/cics
Imperative CLI Framework plug-ins can gain control of your CLI application
legitimately during the execution of every command. Install 3rd party plug-ins
at your own risk. CA Technologies makes no warranties regarding the use of
3rd party plug-ins.

Imperative's plugin installation program handles peer dependencies for modules
in the @brightside namespace and missing package.json file,
so you can safely ignore NPM warnings about
missing peer dependencies related to @brightside modules and absent C:\dev\.zowe\plugins\installed\package.json file.
Registry = https://gizaartifactory.jfrog.io/gizaartifactory/api/npm/npm-release/

_______________________________________________________________
npm WARN enoent ENOENT: no such file or directory, open 'C:\dev\.zowe\plugins\installed\package.json'
npm WARN @brightside/[email protected] requires a peer of @brightside/[email protected] but none is installed. You must install peer dependencies yourself.
npm WARN @brightside/[email protected] requires a peer of @brightside/[email protected] but none is installed. You must install peer dependencies yourself.

Error: Refusing to delete C:\dev\.zowe\plugins\installed\node_modules\.bin\cics.cmd: containing path C:\dev\.zowe\plugins\installed\node_modules\@brightside\cics isn't under npm's control
    at npm.commands.install (C:\Users\XXXXXXX\Documents\GitHub\imperative\lib\imperative\src\plugins\utilities\NpmApiFunctions.js:69:35)
    at cb (C:\Users\XXXXXXX\Documents\GitHub\imperative\node_modules\npm\lib\install.js:255:18)
    at cb (C:\Users\XXXXXXX\Documents\GitHub\imperative\node_modules\npm\lib\install.js:275:12)
    at C:\Users\XXXXXXX\Documents\GitHub\imperative\node_modules\npm\lib\install.js:353:7
    at LOOP (C:\Users\XXXXXXX\Documents\GitHub\imperative\node_modules\npm\node_modules\slide\lib\chain.js:7:26)
    at C:\Users\XXXXXXX\Documents\GitHub\imperative\node_modules\npm\node_modules\slide\lib\chain.js:18:7
    at Installer.printInstalled (C:\Users\XXXXXXX\Documents\GitHub\imperative\node_modules\npm\lib\install.js:753:28)
    at Array.<anonymous> (C:\Users\XXXXXXX\Documents\GitHub\imperative\node_modules\npm\node_modules\slide\lib\bind-actor.js:15:8)
    at LOOP (C:\Users\XXXXXXX\Documents\GitHub\imperative\node_modules\npm\node_modules\slide\lib\chain.js:15:14)
    at C:\Users\XXXXXXX\Documents\GitHub\imperative\node_modules\npm\node_modules\slide\lib\chain.js:18:7
    at Installer.printWarnings (C:\Users\XXXXXXX\Documents\GitHub\imperative\node_modules\npm\lib\install.js:748:3)
    at Array.<anonymous> (C:\Users\XXXXXXX\Documents\GitHub\imperative\node_modules\npm\node_modules\slide\lib\bind-actor.js:15:8)
    at LOOP (C:\Users\XXXXXXX\Documents\GitHub\imperative\node_modules\npm\node_modules\slide\lib\chain.js:15:14)
    at C:\Users\XXXXXXX\Documents\GitHub\imperative\node_modules\npm\node_modules\slide\lib\chain.js:18:7
    at Installer.finishTracker (C:\Users\XXXXXXX\Documents\GitHub\imperative\node_modules\npm\lib\install.js:379:3)
    at Array.<anonymous> (C:\Users\WRICH04\Documents\GitHub\imperative\node_modules\npm\node_modules\slide\lib\bind-actor.js:15:8)
Command Error:
Refusing to delete C:\dev\.zowe\plugins\installed\node_modules\.bin\cics.cmd: containing path C:\dev\.zowe\plugins\installed\node_modules\@brightside\cics isn't under npm's control
Imperative encountered an unexpected exception
Error Details:
Refusing to delete C:\dev\.zowe\plugins\installed\node_modules\.bin\cics.cmd: containing path C:\dev\.zowe\plugins\installed\node_modules\@brightside\cics isn't under npm's control

As you can see, the second install failed because npm thinks that the plugin installed folder is actually a npm package. I had concerns about this message while reviewing #75, but perhaps it is crucial to remove this message in order for npm to recognize as a global package install.

npm WARN enoent ENOENT: no such file or directory, open 'C:\dev\.zowe\plugins\installed\package.json'

I had a mention of this in #99, indicating that there is a difference between doing npm i -g --prefix "~/.zowe/plugins" some-package and what we thought was the same thing using the apis.

@ghost ghost added bug Something isn't working plugins This issue involves the Plugin Facility labels Nov 1, 2018
@ghost
Copy link
Author

ghost commented Nov 1, 2018

After review, I found that doing the install from a .tgz of the cics plugin did not yield this error unless I installed cics from a registry and then installed from the tgz. If I installed the tgz and then reinstall the tgz, no error.

@nurra01
Copy link
Contributor

nurra01 commented Nov 2, 2018

I tried to fix this error but there are not much research for this. It seems it is not able to delete existing plugin because it is linked to brightside. Here is similar issue npm/npm#9680
People say that new version of npm should fix that, but it is not valid for npm APIs. I think it needs more research, because there are a lot of npm configs which do smth but it is not documented, so it will take a lot of time to resolve this. For now user should be able to update a plugin if he wants newer version.

@ghost
Copy link
Author

ghost commented Nov 2, 2018

Updating a only just does an npm install but doesn't let you specify the version or a package file. I think this behavior was different at one point in time and I think update needs reworked in plugins.

With that in mind, the only path forward for users installing plugins is to currently uninstall and then install them to get around this error. However, once we make changes to refactor uninstall to use the npm apis, I fear that you will run into the situation where npm refuses to uninstall the package since it thinks it isn't under npm's control. This means to install an update to a plugin, a user must go into the plugins folder and either delete it or specifically delete the npm node_module they are installing.

I believe this must be addressed before we can even consider releasing Imperative 2.0.0 as a supported release.

@nurra01
Copy link
Contributor

nurra01 commented Nov 2, 2018

I agree, it should be researched. Maybe @plavjanik could look at this before we go for 2.0.0 release.

@ghost
Copy link
Author

ghost commented Nov 2, 2018

I think I've cracked the case on this one, turns out we can revisit the api changes and put execSync back in kind of like this.

const npmPath = path.join(__dirname, "../../../../../../node_modules/npm");
console.log(npmPath);

const pipe = ["pipe", "pipe", process.stderr];

const installCommand = require("child_process").execSync(`"${process.execPath}" "${npmPath}" install "${npmPackage}" --prefix "${PMFConstants.instance.PLUGIN_INSTALL_LOCATION}" ` +
    `-g --registry "${registry}"`, {
    cwd: PMFConstants.instance.PMF_ROOT,
    stdio: pipe
});

console.log(installCommand);

This works for both an npm package and an executable created with pkg. More testing would have to be done on linux and mac but I believe this is the correct approach.

I also did some playing around and found that any cli that bundles us needs node-gyp stuff to be installed (at least with the current calls to the npm api, that may change). We can do this by adding this line to the package.json:

"pkg": {
    "scripts": "lib/**/*.js",
    "assets": ["node_modules/npm/node_modules/node-gyp/**/*"]
  },

So that the pkg tool can inherit the things we need. Then we could also say that an imperative cli can be packaged using pkg as the preferred tool.

@nurra01
Copy link
Contributor

nurra01 commented Nov 5, 2018

the command fails for me and it seems process.execPath is using global node from program files, is it the same for you ?

@ghost
Copy link
Author

ghost commented Nov 5, 2018

process.execPath will use the exe that spawned the process. When using a cli installed through npm, this will be the node.exe process that was used to spawn the code. When using a packaged cli it resolves to the executable package.

So if I have cli.exe, the spawn sync command would look a bit like this:

/Path/to/cli.exe /snapshot/node_modules/npm ...

So in quick research this appears to use the node executable within the packaged application. I could give my methodology a shot in an environment where node doesn't exist just to be sure.

@ghost
Copy link
Author

ghost commented Nov 5, 2018

Also note that the command might fail depending on where you put the code. This code was for the install.ts file. If placed somewhere else you may need to update the path to the node_modules folder.

@nurra01
Copy link
Contributor

nurra01 commented Nov 6, 2018

@AHumanFromCA could you please try it in environment where node doesn't exist, soon I will refactor uninstall, I would use this approach if it works. Thanks

@nurra01
Copy link
Contributor

nurra01 commented Nov 6, 2018

Also, during that refactoring I would also refactor install and update

@ghost
Copy link
Author

ghost commented Nov 6, 2018

Sounds good, I will try to do that today or tomorrow.

@ghost
Copy link
Author

ghost commented Nov 6, 2018

@nurra01 would this suffice for the test you want.

Since I need node to build everything, I plan on keeping node installed on my system. So to test, I plan to:

  1. Build both Imperative and Zowe CLI
  2. Package Zowe CLI into an executable
  3. Rename node.exe to something like my_renamed_node.exe (so I don't have to uninstall it)
  4. Execute a plugin install within the zowe.exe. This should trigger the code logic I've added above and it won't have access to a node.exe.
  5. Rename my_renamed_node.exe back to node.exe so that I can continue to work.

Would that suffice?

@nurra01
Copy link
Contributor

nurra01 commented Nov 6, 2018

@AHumanFromCA yes, this should be sufficient.

@ghost
Copy link
Author

ghost commented Nov 6, 2018

I added a line to output the command that gets executed so we can be sure.

Output for npm installed package

zd plugins install ..\zowe-cli-sample-plugin
Imperative CLI Framework plug-ins can gain control of your CLI application
legitimately during the execution of every command. Install 3rd party plug-ins
at your own risk. CA Technologies makes no warranties regarding the use of
3rd party plug-ins.

Imperative's plugin installation program handles peer dependencies for modules
in the @brightside namespace and missing package.json file,
so you can safely ignore NPM warnings about
missing peer dependencies related to @brightside modules and absent C:\dev\.zowe\plugins\installed\package.json file.
Registry = https://registry.npmjs.org/

_______________________________________________________________
C:\Users\XXXXXXX\Documents\GitHub\imperative\node_modules\npm
"C:\Program Files\nodejs\node.exe" "C:\Users\XXXXXXX\Documents\GitHub\imperative\node_modules\npm" install "C:\Users\XXXXXXX\Documents\GitHub\zowe-cli-sample-plugin" --prefix "C:\dev\.zowe\plugins\installed" -g --registry "https://registry.npmjs.org/"
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\XXXXXXX\Documents\GitHub\zowe-cli\node_modules\fsevents\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\XXXXXXX\Documents\GitHub\zowe-cli\node_modules\fsevents\node_modules\rc\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\XXXXXXX\Documents\GitHub\zowe-cli\node_modules\chokidar\node_modules\fsevents\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\XXXXXXX\Documents\GitHub\zowe-cli\node_modules\glob-watcher\node_modules\fsevents\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\XXXXXXX\Documents\GitHub\zowe-cli\node_modules\sane\node_modules\fsevents\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\XXXXXXX\Documents\GitHub\zowe-cli\node_modules\chokidar\node_modules\fsevents\node_modules\rc\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\XXXXXXX\Documents\GitHub\zowe-cli\node_modules\glob-watcher\node_modules\fsevents\node_modules\rc\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\XXXXXXX\Documents\GitHub\zowe-cli\node_modules\sane\node_modules\fsevents\node_modules\rc\package.json'
npm WARN @brightside/[email protected] requires a peer of @brightside/[email protected] but none is installed. You must install peer dependencies yourself.
npm WARN @brightside/[email protected] requires a peer of @brightside/[email protected] but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of [email protected] but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of popper.js@^1.14.3 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of popper.js@^1.14.3 but none is installed. You must install peer dependencies yourself.

<Buffer 43 3a 5c 64 65 76 5c 2e 7a 6f 77 65 5c 70 6c 75 67 69 6e 73 5c 69 6e 73 74 61 6c 6c 65 64 5c 62 70 2d 73 61 6d 70 6c 65 20 2d 3e 20 43 3a 5c 64 65 76 ... >
Installed plugin name = '@brightside/brightside-sample-plugin'

_____ Validation results for plugin '@brightside/brightside-sample-plugin' _____

*** Warning: The version value (1.x) of the plugin's '@brightside/core' property is incompatible with the version value (2.0.0-next.201811021239) of the zowe command's 'version' property.

This plugin has warnings, but its commands and framework overrides will still be available.

Output for executable (with no access to node)

$ where node
INFO: Could not find files for the given pattern(s).

$ core plugins install ..\zowe-cli-sample-plugin
Imperative CLI Framework plug-ins can gain control of your CLI application
legitimately during the execution of every command. Install 3rd party plug-ins
at your own risk. CA Technologies makes no warranties regarding the use of
3rd party plug-ins.

Imperative's plugin installation program handles peer dependencies for modules
in the @brightside namespace and missing package.json file,
so you can safely ignore NPM warnings about
missing peer dependencies related to @brightside modules and absent C:\Users\XXXXXXX\.zowe\plugins\installed\package.json file.
Registry = https://gizaartifactory.jfrog.io/gizaartifactory/api/npm/npm-release/

_______________________________________________________________
C:\snapshot\zowe-cli\node_modules\@brightside\imperative\node_modules\npm
"C:\Users\XXXXXXX\Documents\GitHub\zowe-cli\core.exe" "C:\snapshot\zowe-cli\node_modules\@brightside\imperative\node_modules\npm" install "C:\Users\XXXXXXX\Documents\GitHub\zowe-cli-sample-plugin" --prefix "C:\Users\XXXXXXX\.zowe\plugins\installed" -g --registry "https://gizaartifactory.jfrog.io/gizaartifactory/api/npm/npm-release/"
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\XXXXXXX\Documents\GitHub\zowe-cli\node_modules\fsevents\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\XXXXXXX\Documents\GitHub\zowe-cli\node_modules\fsevents\node_modules\rc\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\XXXXXXX\Documents\GitHub\zowe-cli\node_modules\chokidar\node_modules\fsevents\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\XXXXXXX\Documents\GitHub\zowe-cli\node_modules\glob-watcher\node_modules\fsevents\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\XXXXXXX\Documents\GitHub\zowe-cli\node_modules\sane\node_modules\fsevents\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\XXXXXXX\Documents\GitHub\zowe-cli\node_modules\chokidar\node_modules\fsevents\node_modules\rc\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\XXXXXXX\Documents\GitHub\zowe-cli\node_modules\glob-watcher\node_modules\fsevents\node_modules\rc\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\XXXXXXX\Documents\GitHub\zowe-cli\node_modules\sane\node_modules\fsevents\node_modules\rc\package.json'
npm WARN @brightside/[email protected] requires a peer of @brightside/[email protected] but none is installed. You must install peer dependencies yourself.
npm WARN @brightside/[email protected] requires a peer of @brightside/[email protected] but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of [email protected] but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of popper.js@^1.14.3 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of popper.js@^1.14.3 but none is installed. You must install peer dependencies yourself.

<Buffer 43 3a 5c 55 73 65 72 73 5c 57 52 49 43 48 30 34 5c 2e 7a 6f 77 65 5c 70 6c 75 67 69 6e 73 5c 69 6e 73 74 61 6c 6c 65 64 5c 62 70 2d 73 61 6d 70 6c 65 ... >
Installed plugin name = '@brightside/brightside-sample-plugin'

_____ Validation results for plugin '@brightside/brightside-sample-plugin' _____

*** Warning: The version value (1.x) of the plugin's '@brightside/core' property is incompatible with the version value (2.0.0-next.201811021239) of the zowe command's 'version' property.

This plugin has warnings, but its commands and framework overrides will still be available.

As you can see it works in both environments in exactly the same manner.

@nurra01
Copy link
Contributor

nurra01 commented Nov 6, 2018

@AHumanFromCA good, it should be much better than using api functions. I think we could try it also on empty environment, to be 100% sure, we have few virtual machines, I will try it tomorrow. Thanks

@nurra01 nurra01 mentioned this issue Nov 15, 2018
@ghost ghost closed this as completed in #116 Nov 16, 2018
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working plugins This issue involves the Plugin Facility
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant