markbind icon indicating copy to clipboard operation
markbind copied to clipboard

Add documentation about npm unlink in DG

Open yucheng11122017 opened this issue 1 year ago • 22 comments

Please confirm that you have searched existing issues in the repo

Yes, I have searched the existing issues

Any related issues?

No response

What is the area that this feature belongs to?

Documentation

Is your feature request related to a problem? Please describe.

When developing, we have to use npm link in the cli package. See instructions in DG. However, when trying to test using the released version of markbind, it is necessary to unlink (npm unlink markbind-cli)from the cli package. This step is not documented in the DG.

Describe the solution you'd like

Add instructions on unlinking from cli package when trying to use the released version of markbind.

Describe alternatives you've considered

No response

Additional context

No response

yucheng11122017 avatar Mar 17 '24 05:03 yucheng11122017

Isn't the following section in the FAQ sufficient? Uninstalling will work:

How do I move back to the released version of MarkBind?

To go back to the released version of MarkBind, run npm un -g markbind-cli, followed by npm i -g markbind-cli.

tlylt avatar Mar 17 '24 09:03 tlylt

Isn't the following section in the FAQ sufficient? Uninstalling will work:

How do I move back to the released version of MarkBind?

To go back to the released version of MarkBind, run npm un -g markbind-cli, followed by npm i -g markbind-cli.

It didn't seem to work with @LamJiuFong when we were trouble shooting for him that day. Only after he ran npm unlink did it unlink properly

yucheng11122017 avatar Mar 17 '24 09:03 yucheng11122017

Yup, it only worked after I ran npm unlink markbind-cli

However, according to https://docs.npmjs.com/cli/v8/commands/npm-uninstall#examples, unlink is just an alias for uninstall, so not sure what was the issue when running npm un -g markbind-cli

Edit: I am thinking of this potential reason: npm unlink uninstalls the local package and npm un -g uninstalls the global package but not the local package When we run a module, it will first search from the local packages (node_modules). If there exist a local package, it will use it instead of using the global package. That's why running npm un -g markbind-cli and npm i -g markbind-cli wouldn't work since the local package is not affected and still links to the local markbind-cli

LamJiuFong avatar Mar 17 '24 11:03 LamJiuFong

Yup, it only worked after I ran npm unlink markbind-cli

What worked after you ran unlink?

tlylt avatar Mar 17 '24 14:03 tlylt

Yup, it only worked after I ran npm unlink markbind-cli

What worked after you ran unlink?

The delinking - only after running npm unlink, he could use the released version of markbind

yucheng11122017 avatar Mar 17 '24 15:03 yucheng11122017

Yup, it only worked after I ran npm unlink markbind-cli

What worked after you ran unlink?

The delinking - only after running npm unlink, he could use the released version of markbind

Perhaps a detailed description of the steps taken (what commands ran and what results etc) would help debug the root cause.

tlylt avatar Mar 17 '24 23:03 tlylt

First, I run markbind init in an empty folder, there's an error (some issues in my package/cli folder), Then in the empty folder, I run npm un -g markbind-cli -> npm i -g markbind-cli -> markbind init, the error appears again Then in the empty folder, I run npm unlink markbind-cli -> npm un -g markbind-cli -> npm i -g markbind-cli -> markbind init, initialisation run successfully

LamJiuFong avatar Mar 18 '24 04:03 LamJiuFong

First, I run markbind init in an empty folder, there's an error (some issues in my package/cli folder),

Then in the empty folder, I run npm un -g markbind-cli -> npm i -g markbind-cli -> markbind init, the error appears again

Then in the empty folder, I run npm unlink markbind-cli -> npm un -g markbind-cli -> npm i -g markbind-cli -> markbind init, initialisation run successfully

Some error -> what error exactly? Any logs?

tlylt avatar Mar 18 '24 06:03 tlylt

Sorry, I forgot what was the exact error, I remember it was related to missing layouts The logs was something along the line Could not find ../Layouts

LamJiuFong avatar Mar 18 '24 06:03 LamJiuFong

Sorry, I forgot what was the exact error, I remember it was related to missing layouts The logs was something along the line Could not find ../Layouts

Yes this error came about because of some pull issue where the Layout.ts didnt get pull into the local repo. So because it wasn't unlinked properly, it resulted in this error.

yucheng11122017 avatar Mar 18 '24 07:03 yucheng11122017

Sorry, I forgot what was the exact error, I remember it was related to missing layouts

The logs was something along the line Could not find ../Layouts

Hmm sorry so this error is not reproducible? If not could you reproduce and capture the error log when convenient?

tlylt avatar Mar 18 '24 07:03 tlylt

Hmmm I just tried it and the commands in the DG npm un -g markbind-cli and then npm i -g markbind-cli seems to work for me on Windows. @LamJiuFong could you try again on your computer (Mac) and see if this is replicable? If not I will close this issue.

yucheng11122017 avatar Mar 19 '24 04:03 yucheng11122017

Running the sequence of operation suggested by @LamJiuFong , it seems like the current set of commands in DG suffice and results in no error. (macOS environment)

Tim-Siu avatar Mar 22 '24 09:03 Tim-Siu

I gave @Tim-Siu this set of instructions to try replicating the bug on his Mac:

1. remove Layout.ts in core/src/Layout
2. npm run setup
3. npm link in packages/cli

then in an empty folder:
3. npm link markbind-cli
4. marbind init (should have an error)
5. npm un -g markbind-cli
6. npm i -g markbind-cli
7. markbind init (observe if there is still any error)

Our results in Step 7 is different, @Tim-Siu's one has no error but mine still has the same error in Step 4. However, I tried another approach (adding another command npm unlink markbind-cli right before Step 5) and it doesn't work too. I think it might be my own laptop's problem

LamJiuFong avatar Mar 22 '24 09:03 LamJiuFong

  1. npm link markbind-cli

Why do you need to do this again in an empty folder ? Once you npm link and the package is available globally, the markbind init call will invoke the master branch markbind.

To get to the released version of MarkBind

  • npm un -g markbind-cli then npm i -g markbind-cli

To get to the master branch version of MarkBind

  • navigating to the cloned packages/cli folder and running npm link

tlylt avatar Mar 22 '24 23:03 tlylt

Why do you need to do this again in an empty folder ? Once you npm link and the package is available globally, the markbind init call will invoke the master branch markbind.

Sorry, I was following the instructions here: https://docs.npmjs.com/cli/v8/commands/npm-link I understand that it might be doing extra work but I am not sure how would this affect anything

LamJiuFong avatar Mar 23 '24 14:03 LamJiuFong

Sorry, I was following the instructions here: https://docs.npmjs.com/cli/v8/commands/npm-link

I see. The steps in the docs should be relevant in the case that you are working on another node/npm project that relies/imports on your npm package. In our case we are making a cli tool available globally, it's not necessary for you to make in available in the folder that you want to invoke it in order to call the markbind cli (iirc).

I understand that it might be doing extra work but I am not sure how would this affect anything

I wonder if your empty folder is not an empty one but one with a node_modules as mentioned in the docs, will the error still occur? You can populate it by running npm init -y

Also btw...you still have not posted the exact error message🙃

tlylt avatar Mar 23 '24 14:03 tlylt

Hi @tlylt , so sorry for the late reply.

I see. The steps in the docs should be relevant in the case that you are working on another node/npm project that relies/imports on your npm package. In our case we are making a cli tool available globally, it's not necessary for you to make in available in the folder that you want to invoke it in order to call the markbind cli (iirc).

Ohh I see, I agree with you that it is unnecessary to do npm link markbind-cli again in our case.

Also btw...you still have not posted the exact error message🙃

These are the exact error messages

  1. After deleting Layout.ts and run npm run setup, this error occured: Screenshot 2024-03-26 at 11 23 05 PM

  2. Running markbind init in an empty folder Screenshot 2024-03-26 at 11 27 31 PM

  3. Run npm un -g markbind-cli and npm i -g markbind-cli Screenshot 2024-03-26 at 11 29 11 PM

  4. Running markbind init again Screenshot 2024-03-26 at 11 29 59 PM

I wonder if your empty folder is not an empty one but one with a node_modules as mentioned in the docs, will the error still occur? You can populate it by running npm init -y

I tried this method in another folder after running npm init -y, and followed the workflow above. The same errors occured though (I followed the same steps 1-4)

However, after adding the Layout.ts back and running npm run setup, I ran markbind init in both folders, and there is no error: Screenshot 2024-03-26 at 11 55 58 PM

I am thinking if my laptop still links markbind-cli to my local version instead of the released version even after I reinstall it globally

LamJiuFong avatar Mar 26 '24 15:03 LamJiuFong

I am thinking if my laptop still links markbind-cli to my local version instead of the released version even after I reinstall it globally

From the logs it looks like you are. You can confirm it either by checking the npm global installation folder in your machine or make some obvious change in the markbind repo instead of removing the Layout.ts to test it (e.g. add a console log somewhere or edit the output of markbind init).

Maybe try testing after you run npm un -g markbind-cli, are you able to run markbind --version or markbind init before you even re-install it globally.

tlylt avatar Mar 27 '24 00:03 tlylt

I added a console.log in init.js Screenshot 2024-03-28 at 2 24 12 AM

Ran npm run setup and npm link

In the empty folder (without running npm init -y), I did the following:

  1. npm ls -g Screenshot 2024-03-28 at 2 25 10 AM

  2. markbind init the "hi" is printed Screenshot 2024-03-28 at 2 25 36 AM

  3. npm un -g markbind-cli followed with npm ls -g, the global package is uninstalled Screenshot 2024-03-28 at 2 26 21 AM

  4. But markbind --version and markbind init works Screenshot 2024-03-28 at 2 27 34 AM

Screenshot 2024-03-28 at 2 29 17 AM
  1. Ran npm i -g markbind-cli

  2. Ran npm ls --g and markbind init Screenshot 2024-03-28 at 2 31 37 AM

I followed the steps above in another folder (with npm init -y) and the results were the same.

LamJiuFong avatar Mar 27 '24 18:03 LamJiuFong

But markbind --version and markbind init works

@LamJiuFong Since that's the case, could you try adding a print statement to console log the location of markbind-cli files? i.e. find out where it is executing from

Could you also try double-checking the folder and verify that the markbind-cli folder is indeed deleted?

On macOS, global packages installed with npm are typically stored in the /usr/local/lib/node_modules directory. However, the exact location can depend on how Node.js and npm were installed on your system.

If you've installed Node.js using a version manager like nvm, the global packages might be stored in a directory related to nvm, usually under your home directory, like ~/.nvm/versions/node//lib/node_modules.

tlylt avatar Mar 27 '24 23:03 tlylt

@LamJiuFong any updates? If not we can close this issue.

tlylt avatar Apr 13 '24 02:04 tlylt