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

add uninstall hooks #57 #58

Merged
merged 1 commit into from
Sep 4, 2019
Merged

add uninstall hooks #57 #58

merged 1 commit into from
Sep 4, 2019

Conversation

js-spider
Copy link
Contributor

支持 卸载时 删除nrm 的配置信息 默认 不删除 当使用 npm uninstall nrm -C/ --clean 时 清除

@EmilyMew EmilyMew merged commit 87b5c4e into Pana:master Sep 4, 2019
@GreenMashimaro
Copy link

GreenMashimaro commented May 3, 2020

Hello, I can't find the official documentation for npm hooks.js.
Please send the official instructions corresponding to hooks.js, thank you very much.

I added a console.log('nrm hooks init') to hooks.js under the nrm repository, and then execute npm link, execute npm link nrm in the B repository, then execute npm uninstall nrm -C in the B repository, and no hooks are triggered.

#!/usr/bin/env node

const { cleanRegistry }  = require('./cli')

function preuninstall(){
  if(ifNeedClean()){
    console.log('preuninstall run success : clean .nrmrc info')
    return cleanRegistry();
  };
  console.log('preuninstall run success : keep .nrmrc info')
  process.exit();
}

function ifNeedClean(){
  if(process.env.npm_config_clean){
    return true
  }else{
    const envArgv = process.env.npm_config_argv || '{"original":[]}';
    const envOriginal = JSON.parse(envArgv).original;
    return envOriginal.includes('-C')
  }
}

function isLocalDebug(argv){
  let debugTarget = null;
  argv.forEach(item=>{
    // use node hooks.js --LocalDebugging=preuninstall
    if(item.startsWith('--LocalDebugging=')){
      debugTarget = item.split('=')[1]
    }
  })
  return debugTarget;
}


function run (argv) {
  const target = isLocalDebug(argv) || process.env.npm_lifecycle_event;
  switch(target){
    case 'preuninstall':
        preuninstall(argv);break;
    default: process.exit(0)
  }
}

run(process.argv.slice(2));  

console.log('nrm hooks init')

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

Successfully merging this pull request may close these issues.

3 participants