Skip to content

Commit

Permalink
feat: support native esm plugins
Browse files Browse the repository at this point in the history
close #61
  • Loading branch information
JounQin committed Aug 14, 2021
1 parent c73c519 commit 45ec5d2
Show file tree
Hide file tree
Showing 15 changed files with 2,082 additions and 96 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
lib
src/plugins.ts
CHANGELOG.md
!/.*.js
5 changes: 4 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "@1stg"
"extends": "@1stg",
"rules": {
"mdx/remark": 0
}
}
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:

- name: Build, Lint and test
run: |
yarn build
# `build` is already covered by `lint`
yarn lint
yarn typecov
env:
Expand Down
10 changes: 3 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,16 @@ jobs:
${{ runner.os }}-yarn-
- name: Install Dependencies
# https://github.com/atlassian/changesets/issues/246
run: |
yarn --frozen-lockfile
rm -rf .git/hooks/commit-msg
- name: Build
run: yarn build
run: yarn --frozen-lockfile

- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@master
with:
# This expects you to have a script called release which does a build for your packages and calls changeset publish
publish: yarn release
commit: 'chore: release package(s)'
title: 'chore: release package(s)'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
1 change: 1 addition & 0 deletions .remarkignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CHANGELOG.md
5 changes: 0 additions & 5 deletions .remarkrc

This file was deleted.

9 changes: 9 additions & 0 deletions .remarkrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default {
plugins: [
'remark-lint',
'remark-preset-lint-consistent',
'remark-preset-lint-markdown-style-guide',
'remark-preset-lint-recommended',
'./lib/index.js',
],
}
49 changes: 0 additions & 49 deletions index.ts

This file was deleted.

54 changes: 51 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@
},
"types": "lib",
"files": [
"lib",
"!lib/*.tsbuildinfo"
"lib"
],
"scripts": {
"build": "run-p build:*",
"build:r": "r -f cjs -e named",
"build:ts": "tsc -b",
"build:ts": "tsc -p tsconfig.lib.json",
"dedup": "yarn-deduplicate --strategy fewer",
"lint": "run-p lint:*",
"lint:es": "eslint . --cache -f friendly",
"lint:md": "remark .",
"lint:tsc": "tsc --noEmit",
"prebuild": "node --loader ts-node/esm scripts/build.ts",
"prelint": "yarn build",
"prepare": "patch-package && simple-git-hooks && yarn-deduplicate --strategy fewer || exit 0",
"prerelease": "yarn build",
"release": "changeset publish",
Expand All @@ -35,12 +37,57 @@
"peerDependencies": {
"prettier": ">=1.0.0"
},
"dependencies": {
"remark-lint-blank-lines-1-0-2": "*",
"remark-lint-blockquote-indentation": "*",
"remark-lint-books-links": "*",
"remark-lint-checkbox-character-style": "*",
"remark-lint-code-block-style": "*",
"remark-lint-definition-case": "*",
"remark-lint-definition-spacing": "*",
"remark-lint-emphasis-marker": "*",
"remark-lint-fenced-code-marker": "*",
"remark-lint-final-newline": "*",
"remark-lint-hard-break-spaces": "*",
"remark-lint-heading-style": "*",
"remark-lint-heading-whitespace": "*",
"remark-lint-link-title-style": "*",
"remark-lint-list-item-bullet-indent": "*",
"remark-lint-list-item-content-indent": "*",
"remark-lint-list-item-indent": "*",
"remark-lint-list-item-spacing": "*",
"remark-lint-maximum-line-length": "*",
"remark-lint-no-blockquote-without-marker": "*",
"remark-lint-no-consecutive-blank-lines": "*",
"remark-lint-no-heading-content-indent": "*",
"remark-lint-no-inline-padding": "*",
"remark-lint-no-long-code": "*",
"remark-lint-no-table-indentation": "*",
"remark-lint-ordered-list-marker-style": "*",
"remark-lint-ordered-list-marker-value": "*",
"remark-lint-rule-style": "*",
"remark-lint-spaces-around-number": "*",
"remark-lint-spaces-around-word": "*",
"remark-lint-strong-marker": "*",
"remark-lint-table-cell-padding": "*",
"remark-lint-table-pipe-alignment": "*",
"remark-lint-table-pipes": "*",
"remark-lint-unordered-list-marker-style": "*"
},
"devDependencies": {
"@1stg/common-config": "^2.3.1",
"@changesets/changelog-github": "^0.4.0",
"@changesets/cli": "^2.16.0",
"@pkgr/rollup": "^2.0.0",
"@types/node": "^16.6.1",
"@types/prettier": "^2.3.2",
"patch-package": "^6.4.7",
"remark-cli": "^10.0.0",
"remark-lint": "^9.0.0",
"remark-preset-lint-consistent": "^5.0.0",
"remark-preset-lint-markdown-style-guide": "^5.0.0",
"remark-preset-lint-recommended": "^6.0.0",
"ts-node": "^10.2.0",
"type-coverage": "^2.18.0",
"typescript": "^4.3.5"
},
Expand All @@ -53,6 +100,7 @@
"ignoreFiles": [
"**/*.d.ts"
],
"showRelativePath": true,
"strict": true,
"update": true
}
Expand Down
98 changes: 98 additions & 0 deletions scripts/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import fs from 'fs'
import path from 'path'

import prettier from 'prettier'

const plugins = [
'blank-lines-1-0-2',
'blockquote-indentation',
'books-links',
'checkbox-character-style',
'code-block-style',
'definition-case',
'definition-spacing',
'emphasis-marker',
'fenced-code-marker',
'final-newline',
'hard-break-spaces',
'heading-style',
'heading-whitespace',
'link-title-style',
'list-item-bullet-indent',
'list-item-content-indent',
'list-item-indent',
'list-item-spacing',
'maximum-line-length',
'no-blockquote-without-marker',
'no-consecutive-blank-lines',
'no-heading-content-indent',
'no-inline-padding',
'no-long-code',
'no-table-indentation',
'ordered-list-marker-style',
'ordered-list-marker-value',
'rule-style',
'spaces-around-number',
'spaces-around-word',
'strong-marker',
'table-cell-padding',
'table-pipe-alignment',
'table-pipes',
'unordered-list-marker-style',
]

const camelCase = (val: string) =>
// type-coverage:ignore-next-line -- https://github.com/plantain-00/type-coverage/issues/96
val.replace(/-([\da-z])/g, ([_, $0]) => $0.toUpperCase())

const main = async () => {
const pkgPath = path.resolve('package.json')

const pkg = JSON.parse(await fs.promises.readFile(pkgPath, 'utf8')) as {
dependencies?: Record<string, string>
}

await fs.promises.writeFile(
pkgPath,
prettier.format(
JSON.stringify({
...pkg,
dependencies: {
...pkg.dependencies,
...plugins.reduce<Record<string, string>>(
(acc, plugin) =>
Object.assign(acc, {
[`remark-lint-${plugin}`]: '*',
}),
{},
),
},
}),
{
filepath: pkgPath,
},
),
)

const pluginsPath = path.resolve('src/plugins.ts')

await fs.promises.writeFile(
pluginsPath,
prettier.format(
[
'// @ts-nocheck',
...plugins.map(
plugin => `import ${camelCase(plugin)} from 'remark-lint-${plugin}'`,
),
`\nexport const plugins: Array<import('unified').Plugin> = [${plugins
.map(plugin => camelCase(plugin))
.join(',')}]`,
].join('\n'),
{
filepath: pluginsPath,
},
),
)
}

main().catch(console.error)
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { plugins as _plugins } from './plugins.js'

export const plugins = _plugins.map(plugin => [plugin, false] as const)

export default { plugins }
74 changes: 74 additions & 0 deletions src/plugins.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// @ts-nocheck
import blankLines102 from "remark-lint-blank-lines-1-0-2";
import blockquoteIndentation from "remark-lint-blockquote-indentation";
import booksLinks from "remark-lint-books-links";
import checkboxCharacterStyle from "remark-lint-checkbox-character-style";
import codeBlockStyle from "remark-lint-code-block-style";
import definitionCase from "remark-lint-definition-case";
import definitionSpacing from "remark-lint-definition-spacing";
import emphasisMarker from "remark-lint-emphasis-marker";
import fencedCodeMarker from "remark-lint-fenced-code-marker";
import finalNewline from "remark-lint-final-newline";
import hardBreakSpaces from "remark-lint-hard-break-spaces";
import headingStyle from "remark-lint-heading-style";
import headingWhitespace from "remark-lint-heading-whitespace";
import linkTitleStyle from "remark-lint-link-title-style";
import listItemBulletIndent from "remark-lint-list-item-bullet-indent";
import listItemContentIndent from "remark-lint-list-item-content-indent";
import listItemIndent from "remark-lint-list-item-indent";
import listItemSpacing from "remark-lint-list-item-spacing";
import maximumLineLength from "remark-lint-maximum-line-length";
import noBlockquoteWithoutMarker from "remark-lint-no-blockquote-without-marker";
import noConsecutiveBlankLines from "remark-lint-no-consecutive-blank-lines";
import noHeadingContentIndent from "remark-lint-no-heading-content-indent";
import noInlinePadding from "remark-lint-no-inline-padding";
import noLongCode from "remark-lint-no-long-code";
import noTableIndentation from "remark-lint-no-table-indentation";
import orderedListMarkerStyle from "remark-lint-ordered-list-marker-style";
import orderedListMarkerValue from "remark-lint-ordered-list-marker-value";
import ruleStyle from "remark-lint-rule-style";
import spacesAroundNumber from "remark-lint-spaces-around-number";
import spacesAroundWord from "remark-lint-spaces-around-word";
import strongMarker from "remark-lint-strong-marker";
import tableCellPadding from "remark-lint-table-cell-padding";
import tablePipeAlignment from "remark-lint-table-pipe-alignment";
import tablePipes from "remark-lint-table-pipes";
import unorderedListMarkerStyle from "remark-lint-unordered-list-marker-style";

export const plugins: Array<import("unified").Plugin> = [
blankLines102,
blockquoteIndentation,
booksLinks,
checkboxCharacterStyle,
codeBlockStyle,
definitionCase,
definitionSpacing,
emphasisMarker,
fencedCodeMarker,
finalNewline,
hardBreakSpaces,
headingStyle,
headingWhitespace,
linkTitleStyle,
listItemBulletIndent,
listItemContentIndent,
listItemIndent,
listItemSpacing,
maximumLineLength,
noBlockquoteWithoutMarker,
noConsecutiveBlankLines,
noHeadingContentIndent,
noInlinePadding,
noLongCode,
noTableIndentation,
orderedListMarkerStyle,
orderedListMarkerValue,
ruleStyle,
spacesAroundNumber,
spacesAroundWord,
strongMarker,
tableCellPadding,
tablePipeAlignment,
tablePipes,
unorderedListMarkerStyle,
];
5 changes: 1 addition & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"extends": "@1stg/tsconfig/lib",
"compilerOptions": {
"outDir": "lib"
}
"extends": "@1stg/tsconfig/lib"
}
8 changes: 8 additions & 0 deletions tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": ".",
"compilerOptions": {
"outDir": "lib",
"rootDir": "src"
},
"include": ["src"]
}
Loading

0 comments on commit 45ec5d2

Please sign in to comment.