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

"markdown-it-wikilinks" dependency is not packed #101

Closed
Lemmingh opened this issue Oct 13, 2020 · 4 comments · Fixed by #104
Closed

"markdown-it-wikilinks" dependency is not packed #101

Lemmingh opened this issue Oct 13, 2020 · 4 comments · Fixed by #104

Comments

@Lemmingh
Copy link

To Reproduce

  1. Install version 0.0.20.

  2. Restart VS Code, and open a Markdown document.

  3. See Developer Tools > Console:

    Error: Cannot find module '@thomaskoppelaar/markdown-it-wikilinks'
    

Behind the scene

Unzip vscode-markdown-notes-0.0.20.vsix.

In out/MarkdownRenderingPlugin.js, at line 50:

return require('@thomaskoppelaar/markdown-it-wikilinks')({

But node_modules/@thomaskoppelaar/markdown-it-wikilinks/ does not exist, so this statement will crash.

The reason is as follows.

By default, vsce packs production dependencies, unless you exclude them.

However, markdown-it-wikilinks is not there:

$ npm ls --production --parseable

node_modules/github-slugger
node_modules/github-slugger/node_modules/emoji-regex

It is under dev dependencies currently:

"@thomaskoppelaar/markdown-it-wikilinks": "1.3.0",

Versions

  • OS: Windows 10 Pro, Version 1909, Build 10.0.18363.1082, 64-bit
  • VS Code Version: 1.50.0
  • Extension Version: 0.0.20

Possible solution

Move @thomaskoppelaar/markdown-it-wikilinks to production dependencies:

npm install --save-prod @thomaskoppelaar/markdown-it-wikilinks
@Lemmingh
Copy link
Author

Oh, I forgot a few things.

VS Code ignores broken extensions:
https://github.com/microsoft/vscode/blob/2b7760fa1fac6902b6114e79a0873dfd6ba7ad6c/extensions/markdown-language-features/src/markdownEngine.ts#L79-L85

So, you won't see that error message, until you tweak its logic, for example:

try {
    md = (await plugin)(md);
} catch (err) {
    console.error(err);
}

Besides, VS Code's built-in Markdown preview also reveals that your markdown-it plugin contribution is not working.


Additionally, vsce ls is a good command to know what will be in your VSIX package exactly.

@kortina
Copy link
Owner

kortina commented Oct 23, 2020

Ahh, great catch. I will fix this weekend!

@kortina
Copy link
Owner

kortina commented Nov 3, 2020

Thank you for such detail on this issue, @Lemmingh -- a model citizen!

I am just reading through the rest of your thread -- re: "built-in Markdown preview also reveals that your markdown-it plugin contribution is not working" is there something else beyond packaging the dependency that you noticed? I implemented your suggested fix in #104 and it seems to render OK now, but just wanted to make sure I didn't miss something.

@Lemmingh
Copy link
Author

Lemmingh commented Nov 5, 2020

Looks good to me.

I guess there's no more to do with your extension.


wanted to make sure I didn't miss something.

Nothing critical in that comment. I was just talking about the background in different ways.

As you know, VS Code's markdown-language-features hosts its built-in Markdown preview. It renders Markdown to HTML by markdown-it, and defines a contract called extendMarkdownIt() so that extensions can contribute markdown-it plugins to enrich the preview.

Thus, to add a plugin (@thomaskoppelaar/markdown-it-wikilinks in your case), we need to ship it with the extension, and expose it through extendMarkdownIt().

To check whether it is packed, inspecting the VSIX package directly, or running vsce ls is the most precise way. However, that usually produces a very long list. So, given your project configuration, I chose npm ls --production --parseable.

Then to check whether it works, looking at the Markdown preview is often enough. But when something goes wrong, we will have to attach a debugger and look for errors.

That's all.

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 a pull request may close this issue.

2 participants