') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); Hoist markbind package dependencies by ang-zeyu · Pull Request #1253 · MarkBind/markbind · GitHub
Skip to content

Hoist markbind package dependencies - #1253

Merged
ang-zeyu merged 5 commits into
MarkBind:masterfrom
ang-zeyu:hoist-dependencies
Jun 28, 2020
Merged

Hoist markbind package dependencies#1253
ang-zeyu merged 5 commits into
MarkBind:masterfrom
ang-zeyu:hoist-dependencies

Conversation

@ang-zeyu

Copy link
Copy Markdown
Contributor

What is the purpose of this pull request? (put "X" next to an item, remove the rest)

• [x] Other, please explain: Dependency maintainability

What is the rationale for this request?

  • Reduce dependency management overhead in managing the duplicated dependencies in both packages, many of which markbind-cli does not use as well.
  • Update all relative markbind imports to use the markbind package import instead to discourage writing long relative imports

What changes did you make? (Give an overview)

  • removed all dependencies which are being used in markbind but not markbind-cli, then running a `npm install && npm install src\lib\markbind
  • added a missing markdown-it dependency for markbind
  • use the patched version of markdown from the markbind package for one of the tests instead of markdown-it to remove the markdown-it dependency; We have quite a few patches / added plugins for the behaviour in markdown-it which may interfere with the the plugin being tested itself as well.
  • use package imports for markbind-cli

Proposed commit message: (wrap lines at 72 characters)
Hoist markbind core package dependencies

Markbind-cli lists many packages under as its dependencies which are
used by the core markbind package but not markbind-cli.
Importing files from markbind from markbind-cli also requires writing
long relative imports.

Let's use npm install instead to hoist these packages to
markbind-cli's node_modules.
Let's also use package imports for importing the core markbind library
files.

@ang-zeyu
ang-zeyuforce-pushed the hoist-dependencies branch 2 times, most recently from 928e2d2 to 596fdd5CompareJune 16, 2020 11:24
Comment thread.eslintignore
@@ -1,4 +1,5 @@
*.min.*
node_modules

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

added this as there are still some unhoisted dependencies (moment) that will be installed in markbind (lib)

*/
fs.readJsonSync = filePath => JSON.parse(fs.readFileSync(filePath, 'utf8'));


Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

these occur due to dependency upgrades of eslint

@ang-zeyu
ang-zeyuforce-pushed the hoist-dependencies branch 3 times, most recently from e07e7e6 to 55718c5CompareJune 26, 2020 14:00
@ang-zeyuang-zeyu reopened this Jun 26, 2020
@ang-zeyu
ang-zeyuforce-pushed the hoist-dependencies branch from 55718c5 to 7075664CompareJune 26, 2020 14:08

@ang-zeyuang-zeyu left a comment

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

@acjh what do you think of this?
The downside is that you'd have to run npm install src/lib/markbind (provided as npm run install:markbind) when upgrading the core package's dependencies, something obscure (as opposed to cd src/lib/markbind && npm install) I noted in the devGuide.


I noticed node's hoisting feature does not hoist devDependencies as well, which is somewhat of a bummer for deduplicating markbind-cli - frontend/components dev dependencies later on (in another PR).

Comment threadpackage.json
"install:all": "npm install && npm run install:components",
"install:all": "npm install && npm run install:markbind && npm run install:components",
"install:components": "cd frontend/components && npm install",
"install:markbind": "npm install src/lib/markbind",

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

hence, for example if you only updated the markbind core package's dependencies, simply run install:markbind.
If multiple packages had their dependencies upgraded, run install:all instead. (documented under workflow under dev guide)

Comment threaddocs/devGuide/workflow.md Outdated
Comment threaddocs/devGuide/workflow.md
Comment threaddocs/devGuide/workflow.md Outdated
Comment threaddocs/devGuide/workflow.md
Comment threadsrc/Page.js Outdated
Comment threadsrc/Page.js
Comment threadtest/unit/markdown-it-icons.test.js Outdated
Comment threadsrc/Site.js
Comment threadsrc/plugins/default/markbind-plugin-footnotes-popovers.js Outdated
Comment threadtest/unit/parser.test.js Outdated
@ang-zeyu

Copy link
Copy Markdown
ContributorAuthor

Thanks for the review @acjh! Pushed the relevant fixups

"markdown-it-emoji": "^1.4.0",
"markdown-it-imsize": "^2.0.1",
"markdown-it-ins": "^2.0.0",
"markdown-it-linkify-images": "^1.1.1",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shall we adjust the order of the sections in both package.json in this PR?
Or will it significantly mess up the diff since we're modifying packages too?

Ref: #1248 (comment)

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Hmm perhaps the one that would move src/lib/markbind into packages/markbind? Would be more suitable relevant I think
The diffs wouldn't be too big if we do it here either though

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm ok with either, if it doesn't significantly mess up the diff in this PR.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

👍 I'll give it a try, will stash it if it's too much

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

The diffs seem ok (Fixup hoist markbind core package dependencies commit); I extracted out the jest config into a separate file for consistency as well

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

4da36b4 should be its own commit instead of a fixup.
Otherwise it messes up the diff since it's no longer obvious that we removed several packages.

@ang-zeyu
ang-zeyuforce-pushed the hoist-dependencies branch from 37b17d3 to 32c0940CompareJune 28, 2020 02:43
Comment threadjest.config.js Outdated
Comment threadsrc/lib/markbind/package.json
"markdown-it-emoji": "^1.4.0",
"markdown-it-imsize": "^2.0.1",
"markdown-it-ins": "^2.0.0",
"markdown-it-linkify-images": "^1.1.1",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

4da36b4 should be its own commit instead of a fixup.
Otherwise it messes up the diff since it's no longer obvious that we removed several packages.

Markbind-cli lists many packages under as its dependencies which are
used by markbind but not markbind-cli.
Let's use npm install <folder> instead to hoist these packages to
markbind-cli's node_modules.
The package.json files of the various packages are not standardised in
their ordering and content.
Let's add and reorder the appropriate fields to do so.
Fix up use package imports for markbind core library
Fix up use package import for markbind
In hoisting markbind dependencies, npm install also caused some of
eslint's dependencies' versions in package-lock.json to increase.
Let's update the source files affected by npm run lintfix.
Fix up add updating dependencies section to devGuide
@ang-zeyu
ang-zeyuforce-pushed the hoist-dependencies branch from 32c0940 to 6c734d7CompareJune 28, 2020 04:33
@ang-zeyu

Copy link
Copy Markdown
ContributorAuthor

4da36b4 should be its own commit instead of a fixup.

Done, the new order:

Untitled

@ang-zeyu

ang-zeyu commented Jun 28, 2020

Copy link
Copy Markdown
ContributorAuthor

Thanks again for the review @acjh! 😄

Will be dealing with the packages/markbind next, on that note, should we:

  1. move frontend/components into packages/components as well?
  2. improve markbind/markbind-cli separation by moving assets into the markbind core package packages/markbind

an alternative to (2) being to create another package for assets, but it seems a little awkward having a package just for that

@ang-zeyuang-zeyu added this to the v2.15.0 milestone Jun 28, 2020
@ang-zeyu
ang-zeyu merged commit a13810c into MarkBind:masterJun 28, 2020
@acjh

acjh commented Jun 28, 2020

Copy link
Copy Markdown
Contributor

Will be dealing with the packages/markbind next, on that note, should we:

  1. move frontend/components into packages/components as well?

Sounds good.

Alternatives for the record:

  • src/lib/markbindpackages/markbind or packages/core
  • frontend/componentspackages/components or packages/vue-components
  1. improve markbind/markbind-cli separation by moving assets into the markbind core package packages/markbind

an alternative to (2) being to create another package for assets, but it seems a little awkward having a package just for that

Looks like asset/ is only used by Site.js, which is currently in markbind-cli?

@ang-zeyu

Copy link
Copy Markdown
ContributorAuthor

Alternatives for the record:

I'll go with the latter options, they look more semantic 😁

Looks like asset/ is only used by Site.js, which is currently in markbind-cli?

yup, with the eventual goal being to move Site/Page.js + all other non-cli functionality into packages/markbind or packages/core. We could deal with this in one go in a later PR though, suggesting it now since we're touching on "frontend"

@acjh

acjh commented Jun 28, 2020

Copy link
Copy Markdown
Contributor

Looks like asset/ is only used by Site.js, which is currently in markbind-cli?

yup, with the eventual goal being to move Site/Page.js + all other non-cli functionality into packages/markbind or packages/core. We could deal with this in one go in a later PR though, suggesting it now since we're touching on "frontend"

Let's do it in a later PR.

@ang-zeyuang-zeyu mentioned this pull request Jun 28, 2020
@ang-zeyuang-zeyu mentioned this pull request Jun 28, 2020
Sign up for freeto 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.

2 participants

@ang-zeyu@acjh