-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support native esm plugins (#62)
- Loading branch information
Showing
17 changed files
with
2,035 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
'remark-preset-prettier': major | ||
--- | ||
|
||
feat: support native esm plugins | ||
|
||
If you're not ready for native esm or latest `remark-lint` plugins, please use versions `<1`, see [#61](https://github.com/JounQin/remark-preset-prettier/issues/61) for more details. | ||
|
||
Or you can try something like [`yarn-deduplicate`](https://github.com/atlassian/yarn-deduplicate) with `yarn-deduplicate --strategy fewer` without guarantee. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
lib | ||
src/plugins.ts | ||
CHANGELOG.md | ||
!/.*.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
{ | ||
"extends": "@1stg" | ||
"extends": "@1stg", | ||
"rules": { | ||
"mdx/remark": 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
.type-coverage | ||
lib | ||
node_modules | ||
src/plugins.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CHANGELOG.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
Oops, something went wrong.