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

fix: fix node v12 #2109

Merged
merged 1 commit into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
if: "!contains(github.event.head_commit.message, '[skip ci]')"
strategy:
matrix:
node_version: ['lts/*', 'node']
node_version: [12, 'lts/*', 'node']
runs-on: ubuntu-latest
steps:
- name: Checkout Code
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@
"preversion": "npm run build && (git diff --quiet || git commit -am build)"
},
"engines": {
"node": ">= 8.16.2"
"node": ">= 12"
Copy link
Contributor

Choose a reason for hiding this comment

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

It's one thing to ensure support in CI but it's another thing to change support in a minor version. I understand that only LTS/latest node versions are supported but real functional changes should only happen during a major version, otherwise it's going to break a lot of people.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, left this a while back but forgot to submit...

Copy link
Member Author

@UziTech UziTech Jun 16, 2021

Choose a reason for hiding this comment

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

If jsdoc wants to support node v8 they could import the es5 version of marked

const marked = require('marked/lib/marked.js');

That should support node v4.

This is why the engines field is misleading and I suggested removing it altogether in #1938 (review)

Copy link
Member Author

Choose a reason for hiding this comment

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

For the record according to jsdoc engines field it only supports >=v14.17.1

Copy link
Contributor

Choose a reason for hiding this comment

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

That's good to know that there's an alternative (i missed seeing it in the docs), but the point still kinda stands about the default import potentially breaking over time.

FYI the engines field you linked is on master (jsdoc 4.x prerelease), the current 3.x version is >=8.15.0)

Copy link

Choose a reason for hiding this comment

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

This change is breaking our CI build now. We use this through Typedoc, with that and our lib using Node >= 10.18.0. It would be great if you could revert this change. This is a breaking change as per semantic versioning. I'd recommend you do this in a v3.x release and have a deprecation period to allow dependents to update their packages or find some other mitigation.

error marked@2.1.1: The engine "node" is incompatible with this module. Expected version ">= 12". Got "10.18.0"
error Found incompatible module.

Copy link
Member

Choose a reason for hiding this comment

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

@Fleker Node.js 10 reached end of life in April and is no longer supported https://nodejs.org/en/about/releases/

You can probably disable that error if you really need to with yarn install --ignore-engines

}
}
10 changes: 6 additions & 4 deletions src/Lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ module.exports = class Lexer {
let token, i, l, lastToken, cutSrc, lastParagraphClipped;

while (src) {
if (this.options?.extensions?.block
if (this.options.extensions
&& this.options.extensions.block
&& this.options.extensions.block.some((extTokenizer) => {
if (token = extTokenizer.call(this, src, tokens)) {
src = src.substring(token.raw.length);
Expand Down Expand Up @@ -244,7 +245,7 @@ module.exports = class Lexer {
// top-level paragraph
// prevent paragraph consuming extensions by clipping 'src' to extension start
cutSrc = src;
if (this.options.extensions?.startBlock) {
if (this.options.extensions && this.options.extensions.startBlock) {
let startIndex = Infinity;
const tempSrc = src.slice(1);
let tempStart;
Expand Down Expand Up @@ -400,7 +401,8 @@ module.exports = class Lexer {
keepPrevChar = false;

// extensions
if (this.options?.extensions?.inline
if (this.options.extensions
&& this.options.extensions.inline
&& this.options.extensions.inline.some((extTokenizer) => {
if (token = extTokenizer.call(this, src, tokens)) {
src = src.substring(token.raw.length);
Expand Down Expand Up @@ -507,7 +509,7 @@ module.exports = class Lexer {
// text
// prevent inlineText consuming extensions by clipping 'src' to extension start
cutSrc = src;
if (this.options.extensions?.startInline) {
if (this.options.extensions && this.options.extensions.startInline) {
let startIndex = Infinity;
const tempSrc = src.slice(1);
let tempStart;
Expand Down
4 changes: 2 additions & 2 deletions src/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ module.exports = class Parser {
token = tokens[i];

// Run any renderer extensions
if (this.options.extensions?.renderers?.[token.type]) {
if (this.options.extensions && this.options.extensions.renderers && this.options.extensions.renderers[token.type]) {
ret = this.options.extensions.renderers[token.type].call(this, token);
if (ret !== false || !['space', 'hr', 'heading', 'code', 'table', 'blockquote', 'list', 'html', 'paragraph', 'text'].includes(token.type)) {
out += ret || '';
Expand Down Expand Up @@ -221,7 +221,7 @@ module.exports = class Parser {
token = tokens[i];

// Run any renderer extensions
if (this.options.extensions?.renderers?.[token.type]) {
if (this.options.extensions && this.options.extensions.renderers && this.options.extensions.renderers[token.type]) {
ret = this.options.extensions.renderers[token.type].call(this, token);
if (ret !== false || !['escape', 'html', 'link', 'image', 'strong', 'em', 'codespan', 'br', 'del', 'text'].includes(token.type)) {
out += ret || '';
Expand Down
9 changes: 4 additions & 5 deletions src/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ marked.use = function(...args) {
throw new Error('extension name required');
}
if (ext.renderer) { // Renderer extensions
const prevRenderer = extensions.renderers?.[ext.name];
const prevRenderer = extensions.renderers ? extensions.renderers[ext.name] : null;
if (prevRenderer) {
// Replace extension with func to run new extension but fall back if false
extensions.renderers[ext.name] = function(...args) {
Expand Down Expand Up @@ -275,12 +275,11 @@ marked.walkTokens = function(tokens, callback) {
break;
}
default: {
if (marked.defaults?.extensions?.childTokens?.[token.type]) { // Walk any extensions
marked.defaults?.extensions.childTokens[token.type].forEach(function(childTokens) {
if (marked.defaults.extensions && marked.defaults.extensions.childTokens && marked.defaults.extensions.childTokens[token.type]) { // Walk any extensions
marked.defaults.extensions.childTokens[token.type].forEach(function(childTokens) {
marked.walkTokens(token[childTokens], callback);
});
}
if (token.tokens && !marked.defaults?.extensions?.childTokens[token.type]) {
} else if (token.tokens) {
marked.walkTokens(token.tokens, callback);
}
}
Expand Down
24 changes: 17 additions & 7 deletions test/unit/marked-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ describe('use extension', () => {
extensions: [{
name: 'underline',
level: 'block',
start(src) { return src.match(/:/)?.index; },
start(src) { return src.indexOf(':'); },
tokenizer(src) {
const rule = /^:([^\n]*):(?:\n|$)/;
const match = rule.exec(src);
Expand All @@ -195,7 +195,7 @@ describe('use extension', () => {
const underline = {
name: 'underline',
level: 'inline',
start(src) { return src.match(/=/)?.index; },
start(src) { return src.indexOf('='); },
tokenizer(src) {
const rule = /^=([^=]+)=/;
const match = rule.exec(src);
Expand All @@ -220,7 +220,12 @@ describe('use extension', () => {
const descriptionlist = {
name: 'descriptionList',
level: 'block',
start(src) { return src.match(/:[^:\n]/)?.index; },
start(src) {
const match = src.match(/:[^:\n]/);
if (match) {
return match.index;
}
},
tokenizer(src, tokens) {
const rule = /^(?::[^:\n]+:[^:\n]*(?:\n|$))+/;
const match = rule.exec(src);
Expand All @@ -241,7 +246,7 @@ describe('use extension', () => {
const description = {
name: 'description',
level: 'inline',
start(src) { return src.match(/:/)?.index; },
start(src) { return src.indexOf(':'); },
tokenizer(src, tokens) {
const rule = /^:([^:\n]+):([^:\n]*)(?:\n|$)/;
const match = rule.exec(src);
Expand Down Expand Up @@ -415,7 +420,7 @@ describe('use extension', () => {
extensions: [{
name: 'walkableDescription',
level: 'inline',
start(src) { return src.match(/:/)?.index; },
start(src) { return src.indexOf(':'); },
tokenizer(src, tokens) {
const rule = /^:([^:\n]+):([^:\n]*)(?:\n|$)/;
const match = rule.exec(src);
Expand Down Expand Up @@ -601,7 +606,12 @@ used extension2 walked</p>
extensions: [{
name: 'inlineStyleTag',
level: 'inline',
start(src) { return src.match(/ *{[^\{]/)?.index; },
start(src) {
const match = src.match(/ *{[^\{]/);
if (match) {
return match.index;
}
},
tokenizer(src, tokens) {
const rule = /^ *{([^\{\}\n]+)}$/;
const match = rule.exec(src);
Expand Down Expand Up @@ -629,7 +639,7 @@ used extension2 walked</p>
walkTokens(token) {
if (token.tokens) {
const finalChildToken = token.tokens[token.tokens.length - 1];
if (finalChildToken?.type === 'inlineStyleTag') {
if (finalChildToken && finalChildToken.type === 'inlineStyleTag') {
token.originalType = token.type;
token.type = 'styled';
token.style = `style="color:${finalChildToken.text};"`;
Expand Down