Skip to content

Commit

Permalink
Merge pull request #255 from yhatt/upgrade-dependencies
Browse files Browse the repository at this point in the history
Upgrade dependent packages to the latest version
  • Loading branch information
yhatt authored Dec 2, 2021
2 parents 7768b16 + 0621fd5 commit 993ad49
Show file tree
Hide file tree
Showing 10 changed files with 910 additions and 802 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
- `autoFocus` prop for supported interactive elements ([#253](https://github.com/yhatt/jsx-slack/issues/253), [#254](https://github.com/yhatt/jsx-slack/pull/254))
- Guide for setting up jsx-slack in Deno (Slack CLI) and esbuild ([#245](https://github.com/yhatt/jsx-slack/issues/245), [#252](https://github.com/yhatt/jsx-slack/pull/252))

### Changed

- Upgrade dependent packages to the latest version ([#255](https://github.com/yhatt/jsx-slack/pull/255))

## v4.4.3 - 2021-11-18

### Fixed
Expand Down
6 changes: 6 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ module.exports = {
presets: babelPresets(false),
},
],
plugins: [
[
'transform-rename-import',
{ replacements: [{ original: '^node:(.+)$', replacement: '$1' }] },
],
],
}
18 changes: 16 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
const esModules = [
'hast-util-embedded',
'hast-util-has-property',
'hast-util-is-element',
'hast-util-to-mdast',
'hast-util-to-text',
'hast-util-whitespace',
'mdast-util-phrasing',
'unist-util-parents',
'mdast-util-to-string',
'rehype-minify-whitespace',
'trim-trailing-lines',
'unist-util-find-after',
'unist-util-is',
'unist-util-parents',
'unist-util-visit',
]

Expand All @@ -12,7 +22,11 @@ module.exports = {
'src/**/*.ts',
'src/**/*.tsx',
],
coveragePathIgnorePatterns: ['/node_modules/', '.*\\.d\\.ts'],
coveragePathIgnorePatterns: [
'/node_modules/',
'.*\\.d\\.ts',
'prebundles/mocks',
],
coverageThreshold: { global: { lines: 95 } },
moduleFileExtensions: [
'js',
Expand Down
37 changes: 19 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,40 +86,41 @@
"@rollup/plugin-commonjs": "21.0.1",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.0.6",
"@types/jest": "^27.0.2",
"@typescript-eslint/eslint-plugin": "^5.4.0",
"@typescript-eslint/parser": "^5.4.0",
"codemirror": "^5.63.3",
"cssnano": "^5.0.11",
"esbuild": "^0.13.14",
"eslint": "^8.2.0",
"@types/jest": "^27.0.3",
"@typescript-eslint/eslint-plugin": "^5.5.0",
"@typescript-eslint/parser": "^5.5.0",
"babel-plugin-transform-rename-import": "^2.3.0",
"codemirror": "^5.64.0",
"cssnano": "^5.0.12",
"esbuild": "^0.14.1",
"eslint": "^8.3.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-jest": "^25.2.4",
"eslint-plugin-react": "^7.27.0",
"hast-util-to-mdast": "7.1.1",
"eslint-plugin-jest": "^25.3.0",
"eslint-plugin-react": "^7.27.1",
"hast-util-to-mdast": "8.3.0",
"he": "^1.2.0",
"htm": "^3.1.0",
"jest": "^27.3.1",
"jest": "^27.4.3",
"jest-junit": "^13.0.0",
"lodash.debounce": "^4.0.8",
"mdast-util-phrasing": "^3.0.0",
"npm-run-all": "^4.1.5",
"pako": "^2.0.4",
"postcss": "^8.3.11",
"postcss": "^8.4.4",
"postcss-import": "^14.0.2",
"prettier": "^2.4.1",
"puppeteer": "^11.0.0",
"prettier": "^2.5.0",
"puppeteer": "^12.0.1",
"rimraf": "^3.0.1",
"rollup": "^2.60.0",
"rollup": "^2.60.2",
"rollup-plugin-copy": "^3.4.0",
"rollup-plugin-esbuild": "^4.6.0",
"rollup-plugin-esbuild": "^4.7.2",
"rollup-plugin-livereload": "^2.0.5",
"rollup-plugin-postcss": "^4.0.1",
"rollup-plugin-postcss": "^4.0.2",
"rollup-plugin-serve": "^1.1.0",
"ts-jest": "^27.0.7",
"tslib": "^2.3.1",
"typescript": "^4.4.4",
"typescript": "^4.5.2",
"unist-util-parents": "^2.0.0",
"unist-util-visit": "^4.1.0"
},
Expand Down
9 changes: 7 additions & 2 deletions rollup.prebundle.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import path from 'path'
import aliasPlugin from '@rollup/plugin-alias'
import alias from '@rollup/plugin-alias'
import json from '@rollup/plugin-json'
import esbuild from 'rollup-plugin-esbuild'
import { compilerOptions } from './tsconfig.json'

export const prebundleAlias = aliasPlugin({
export const prebundleAlias = alias({
entries: [
{
find: /^.*\bprebundles\/(.+)$/,
replacement: path.resolve(__dirname, './vendor/$1.mjs'),
},
// Node's URL dependency will never use in jsx-slack
{
find: 'node:url',
replacement: path.resolve(__dirname, './src/prebundles/mocks/url.ts'),
},
],
})

Expand Down
63 changes: 45 additions & 18 deletions src/mrkdwn/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { visit } from 'unist-util-visit'
import { JSXSlack } from '../jsx'
import {
hastUtilToMdast as hast2mdast,
hastUtilToMdast,
hastUtilToMdastAll as all,
hastUtilToMdastListItem as listItem,
hastUtilToMdastRoot as root,
Expand All @@ -28,6 +28,17 @@ const list = (h, node) => {
return h(node, 'list', { ordered, orderedType, start }, children)
}

const hast2mdast: typeof hastUtilToMdast = (...args) => {
const mdast = hastUtilToMdast(...args)

// Restore text nodes
visit(mdast, (n) => {
if (n.type.startsWith('text-jsxslack-')) n.type = 'text'
})

return mdast
}

const htmlToMrkdwn = (html: string) =>
stringifier(
hast2mdast(parser(html), {
Expand All @@ -37,21 +48,37 @@ const htmlToMrkdwn = (html: string) =>
visit(node, (n) => {
if (n.type === 'text') n.value = decodeEntity(n.value)
})
return root(h, node)

const ret = root(h, node)

// Prevent merging adjacent text nodes
const preprocessRoot = (() => {
if (!ret) return { type: 'root', children: [] }
if (Array.isArray(ret)) return { type: 'root', children: ret }
return ret
})()

let i = 0
visit(preprocessRoot, 'text', (n: any) => {
n.type = 'text-jsxslack-' + i
i += 1
})

return ret
},
code: (h, node) =>
h.augment(node, {
type: 'inlineCode',
children: h.handlers.span(h, node),
}),
pre: (h, node) =>
h.augment(node, {
// Render as inline code to prevent making implied paragraphs
type: 'inlineCode',
children: h.handlers.span(h, node),
data: { codeBlock: true },
}),
time: (h, node) => ({
code: (h, node) => ({
...node,
type: 'inlineCode',
children: h.handlers.span(h, node),
}),
pre: (h, node) => ({
...node,
// Render as inline code to prevent making implied paragraphs
type: 'inlineCode',
children: h.handlers.span(h, node),
data: { codeBlock: true },
}),
time: (h, node): any => ({
...toTextNode(h, node),
data: {
time: {
Expand All @@ -63,14 +90,14 @@ const htmlToMrkdwn = (html: string) =>
ul: list,
ol: list,
li: (h, node) => {
const elm = listItem(h, node)
const elm: any = listItem(h, node)
const value = Number.parseInt(node.properties.value, 10)

if (!Number.isNaN(value)) elm.data = { value }
if (!Number.isNaN(value) && elm) elm.data = { value }

return elm
},
span: (h, node) => {
span: (h, node): any => {
if (node.properties['data-escape']) {
return {
...toTextNode(h, node),
Expand Down
2 changes: 1 addition & 1 deletion src/mrkdwn/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const html2hastLight = htm.bind<any>((tagName, props, ...children) => {
return hast
})

export default function rehypeLightParser(html: string) {
export default function rehypeLightParser(html: string): any {
const { children } = html2hastLight([`<body>${html}</body>`] as any)
return { type: 'root', children }
}
19 changes: 7 additions & 12 deletions src/prebundles/hastUtilToMdast.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import hastUtilToMdast from 'hast-util-to-mdast'
import hastUtilToMdastAll from 'hast-util-to-mdast/lib/all.js'
import hastUtilToMdastListItem from 'hast-util-to-mdast/lib/handlers/list-item.js'
import hastUtilToMdastRoot from 'hast-util-to-mdast/lib/handlers/root.js'
import hastUtilToMdastTextarea from 'hast-util-to-mdast/lib/handlers/textarea.js'

export {
hastUtilToMdast,
hastUtilToMdastAll,
hastUtilToMdastListItem,
hastUtilToMdastRoot,
hastUtilToMdastTextarea,
}
toMdast as hastUtilToMdast,
all as hastUtilToMdastAll,
} from 'hast-util-to-mdast'

export { li as hastUtilToMdastListItem } from 'hast-util-to-mdast/lib/handlers/li.js'
export { root as hastUtilToMdastRoot } from 'hast-util-to-mdast/lib/handlers/root.js'
export { textarea as hastUtilToMdastTextarea } from 'hast-util-to-mdast/lib/handlers/textarea.js'
3 changes: 3 additions & 0 deletions src/prebundles/mocks/url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function URL() {
// empty
}
Loading

0 comments on commit 993ad49

Please sign in to comment.