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 special case for remark-prism #232

Merged
merged 3 commits into from
Sep 16, 2021
Merged

Add special case for remark-prism #232

merged 3 commits into from
Sep 16, 2021

Conversation

styfle
Copy link
Member

@styfle styfle commented Sep 15, 2021

This PR adds a special case since nft can't statically analyze this dynamic require.resolve():

https://github.com/sergioramos/remark-prism/blob/49f1f86d50f376c647214c02cf972ce05b0fc756/src/highlight.js#L74

  getLoader(components, languages, loaded).load((lang) => {
    if (!(lang in components.languages)) {
      console.warn('Language does not exist: ' + lang);
      return;
    }

    const filename = require.resolve(`prismjs/components/prism-${lang}`);
    runInContext(RUN(readFileSync(filename, 'utf-8')), parsingContext, {
      filename,
    });

    loadedLanguages.add(lang);
  });

@codecov
Copy link

codecov bot commented Sep 15, 2021

Codecov Report

Merging #232 (85b7608) into main (7b2a1d8) will increase coverage by 0.06%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #232      +/-   ##
==========================================
+ Coverage   80.04%   80.11%   +0.06%     
==========================================
  Files          13       13              
  Lines        1433     1438       +5     
  Branches      537      538       +1     
==========================================
+ Hits         1147     1152       +5     
  Misses        114      114              
  Partials      172      172              
Impacted Files Coverage Δ
src/utils/special-cases.ts 89.28% <100.00%> (+0.67%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7b2a1d8...85b7608. Read the comment docs.

if (id.endsWith(file)) {
try {
const prefix = id.slice(0, -file.length);
emitAsset(resolve(prefix, `prismjs/components/prism-markdown.js`));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this only be adding prism-markdown or should we be including all of the files in the components folder here since we won't know which are needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good point! Added in 43d6a45

I also added an integration test in 85b7608

@styfle styfle requested a review from ijjk September 16, 2021 13:51
@styfle styfle enabled auto-merge (squash) September 16, 2021 13:53
@styfle styfle merged commit c73e38f into main Sep 16, 2021
@styfle styfle deleted the fix-remark-prism branch September 16, 2021 14:23
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.

None yet

2 participants