Skip to content

Commit

Permalink
refactor: patch packages instead
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin committed Apr 28, 2021
1 parent 3310c72 commit 9cd59ef
Show file tree
Hide file tree
Showing 33 changed files with 925 additions and 305 deletions.
1 change: 0 additions & 1 deletion .codesandbox/ci.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"node": "14",
"buildCommand": false,
"sandboxes": []
}
10 changes: 2 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ jobs:
steps:
- name: Checkout Repo
uses: actions/checkout@master
with:
submodules: true

- name: Setup Node.js ${{ matrix.node }}
uses: actions/setup-node@master
Expand All @@ -42,17 +40,13 @@ jobs:
${{ runner.os }}-yarn-
- name: Install Dependencies
run: |
yarn --frozen-lockfile
cd markuplint
yarn --frozen-lockfile
cd ..
run: yarn --frozen-lockfile

- name: Build, Lint and test
run: |
yarn build
yarn lint
yarn test
# yarn build
env:
EFF_NO_LINK_RULES: true
PARSER_NO_WATCH: true
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ coverage
lib
node_modules
tmp*
/rules
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/markuplint/**
/rules/**
33 changes: 0 additions & 33 deletions jest.config.js

This file was deleted.

1 change: 0 additions & 1 deletion markuplint
Submodule markuplint deleted from 246d4b
44 changes: 35 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,61 @@
"author": "JounQin <admin@1stg.me>",
"license": "MIT",
"engines": {
"node": ">=4.0"
"node": ">=10"
},
"main": "lib",
"module": "lib/esm",
"module": "lib/es2015",
"es2015": "lib/es2015",
"fesm5": "lib/esm",
"types": "lib",
"files": [
"lib",
"rules",
"!*.tsbuildinfo"
],
"keywords": [],
"scripts": {
"build": "run-p build:*",
"build:r": "r -f es2015",
"build:rules": "rimraf rules && node scripts/patch-rules",
"build:ts": "tsc -P src",
"lint": "run-p lint:*",
"lint:es": "eslint . --cache -f friendly --max-warnings 10",
"prepare": "simple-git-hooks && yarn-deduplicate --strategy fewer || exit 0",
"lint:tsc": "tsc --noEmit",
"prepare": "simple-git-hooks && patch-package && yarn-deduplicate --strategy fewer || exit 0",
"prerelease": "npm run build",
"release": "clean-publish && changeset publish",
"test": "jest",
"tsconfig": "node scripts/tsconfig",
"typecov": "type-coverage"
},
"dependencies": {
"@markuplint/file-resolver": "^1.2.1",
"@markuplint/html-spec": "^1.4.2",
"@markuplint/i18n": "^1.1.0",
"@markuplint/ml-ast": "^1.3.0",
"@markuplint/ml-config": "^1.1.0",
"@markuplint/ml-core": "^1.4.1",
"@markuplint/ml-spec": "^1.3.0",
"cosmiconfig": "^7.0.0",
"glob": "^7.1.6",
"markuplint": "^1.6.1",
"os-locale": "^5.0.0",
"tslib": "^2.2.0",
"uuid": "^8.3.2"
"tslib": "^2.2.0"
},
"devDependencies": {
"@1stg/lib-config": "^1.2.10",
"@changesets/changelog-github": "^0.4.0",
"@changesets/cli": "^2.16.0",
"@markuplint/rule-textlint": "^0.0.1-alpha.46",
"@types/jest": "^26.0.22",
"@types/node": "^14.14.41",
"@types/node": "^15.0.1",
"@types/uuid": "^8.3.0",
"clean-publish": "^2.1.1",
"eslint-plugin-mdx": "https://pkg.csb.dev/mdx-js/eslint-mdx/commit/625996b8/eslint-plugin-mdx",
"fs-extra": "^9.1.0",
"npm-run-all": "^4.1.5",
"patch-package": "^6.4.7",
"remark-validate-links": "^10.0.4",
"rimraf": "^3.0.2",
"ts-expect": "^1.3.0",
"ts-jest": "^26.5.5",
"ts-node": "^9.1.1",
Expand All @@ -66,8 +81,19 @@
"coverage",
"lib",
"CHANGELOG.md",
"/markuplint"
"/rules"
],
"jest": {
"preset": "ts-jest",
"testEnvironment": "node",
"collectCoverage": true,
"coveragePathIgnorePatterns": [
"<rootDir>/rules"
],
"moduleNameMapper": {
"^markuplint-sync$": "<rootDir>/src"
}
},
"prettier": "@1stg/prettier-config",
"remarkConfig": {
"plugins": [
Expand Down
56 changes: 56 additions & 0 deletions patches/@markuplint+file-resolver+1.2.1.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
diff --git a/node_modules/@markuplint/file-resolver/lib/helper.d.ts b/node_modules/@markuplint/file-resolver/lib/helper.d.ts
index 63cb3a6..fff40c0 100644
--- a/node_modules/@markuplint/file-resolver/lib/helper.d.ts
+++ b/node_modules/@markuplint/file-resolver/lib/helper.d.ts
@@ -10,4 +10,5 @@ export declare function load<T = CosmiConfig>(filePath: string, cacheClear: bool
config: T;
} | null>;
export declare function recursiveLoad(config: Config, filePath: string, files: Set<string>, cacheClear: boolean): Promise<ConfigSet>;
+export declare function margeConfig(a: Config, b: Config): Config;
export {};
diff --git a/node_modules/@markuplint/file-resolver/lib/helper.js b/node_modules/@markuplint/file-resolver/lib/helper.js
index 6f8e576..26c902e 100644
--- a/node_modules/@markuplint/file-resolver/lib/helper.js
+++ b/node_modules/@markuplint/file-resolver/lib/helper.js
@@ -99,3 +99,4 @@ exports.recursiveLoad = recursiveLoad;
function margeConfig(a, b) {
return Object.assign(Object.assign(Object.assign({}, a), b), { rules: Object.assign(Object.assign({}, a.rules), b.rules), nodeRules: [...(a.nodeRules || []), ...(b.nodeRules || [])], childNodeRules: [...(a.childNodeRules || []), ...(b.childNodeRules || [])] });
}
+exports.margeConfig = margeConfig;
diff --git a/node_modules/@markuplint/file-resolver/lib/index.d.ts b/node_modules/@markuplint/file-resolver/lib/index.d.ts
index 41f4bda..ceb6256 100644
--- a/node_modules/@markuplint/file-resolver/lib/index.d.ts
+++ b/node_modules/@markuplint/file-resolver/lib/index.d.ts
@@ -1,7 +1,7 @@
export { getAnonymousFile } from './get-anonymous-file';
export { getFiles } from './get-files';
export { getFile } from './get-file';
-export { recursiveLoad } from './helper';
+export { recursiveLoad, margeConfig } from './helper';
export { loadConfigFile } from './load-config-file';
export { MLFile } from './ml-file';
export { searchConfigFile } from './search-config-file';
diff --git a/node_modules/@markuplint/file-resolver/lib/index.js b/node_modules/@markuplint/file-resolver/lib/index.js
index ef9b20b..6eb3adf 100644
--- a/node_modules/@markuplint/file-resolver/lib/index.js
+++ b/node_modules/@markuplint/file-resolver/lib/index.js
@@ -9,6 +9,7 @@ var get_file_1 = require("./get-file");
Object.defineProperty(exports, "getFile", { enumerable: true, get: function () { return get_file_1.getFile; } });
var helper_1 = require("./helper");
Object.defineProperty(exports, "recursiveLoad", { enumerable: true, get: function () { return helper_1.recursiveLoad; } });
+Object.defineProperty(exports, "margeConfig", { enumerable: true, get: function () { return helper_1.margeConfig; } });
var load_config_file_1 = require("./load-config-file");
Object.defineProperty(exports, "loadConfigFile", { enumerable: true, get: function () { return load_config_file_1.loadConfigFile; } });
var ml_file_1 = require("./ml-file");
diff --git a/node_modules/@markuplint/file-resolver/lib/types.d.ts b/node_modules/@markuplint/file-resolver/lib/types.d.ts
index 1203b14..215292d 100644
--- a/node_modules/@markuplint/file-resolver/lib/types.d.ts
+++ b/node_modules/@markuplint/file-resolver/lib/types.d.ts
@@ -1,5 +1,5 @@
-import { Config } from '@markuplint/ml-config/';
-export { Config } from '@markuplint/ml-config/';
+import { Config } from '@markuplint/ml-config';
+export { Config } from '@markuplint/ml-config';
export interface ConfigSet {
config: Config;
files: Set<string>;
26 changes: 26 additions & 0 deletions patches/@markuplint+i18n+1.1.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
diff --git a/node_modules/@markuplint/i18n/lib/index.d.ts b/node_modules/@markuplint/i18n/lib/index.d.ts
index f0be080..c7a3c89 100644
--- a/node_modules/@markuplint/i18n/lib/index.d.ts
+++ b/node_modules/@markuplint/i18n/lib/index.d.ts
@@ -9,7 +9,7 @@ export interface LocalesKeywords {
}
export declare class I18n {
private static _singleton;
- static create(localeSet: LocaleSet | null): Promise<I18n>;
+ static create(localeSet: LocaleSet | null): I18n;
localeSet: LocaleSet | null;
private constructor();
translator(): Translator;
diff --git a/node_modules/@markuplint/i18n/lib/index.js b/node_modules/@markuplint/i18n/lib/index.js
index 1836db6..33d11b2 100644
--- a/node_modules/@markuplint/i18n/lib/index.js
+++ b/node_modules/@markuplint/i18n/lib/index.js
@@ -5,7 +5,7 @@ class I18n {
constructor(localeSet) {
this.localeSet = localeSet;
}
- static async create(localeSet) {
+ static create(localeSet) {
if (!I18n._singleton) {
I18n._singleton = new I18n(localeSet);
}
129 changes: 129 additions & 0 deletions patches/@markuplint+ml-core+1.4.1.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
diff --git a/node_modules/@markuplint/ml-core/lib/ml-dom/document.js b/node_modules/@markuplint/ml-core/lib/ml-dom/document.js
index 14ea219..635e699 100644
--- a/node_modules/@markuplint/ml-core/lib/ml-dom/document.js
+++ b/node_modules/@markuplint/ml-core/lib/ml-dom/document.js
@@ -50,22 +50,45 @@ class MLDOMDocument {
}
return treeRoots;
}
- async walk(walker) {
- for (const node of this.nodeList) {
- await walker(node);
- }
+ walk(walker) {
+ /**
+ * The following pattern is used to ensure that all rules run sequentially,
+ * no matter it runs asynchronously or synchronously.
+ */
+ let _resolve;
+ let _reject;
+ const promise = new Promise((resolve, reject) => {
+ _resolve = resolve;
+ _reject = reject;
+ });
+ const loop = (index = 0) => {
+ if (index >= this.nodeList.length) {
+ _resolve();
+ return;
+ }
+ const node = this.nodeList[index];
+ const result = walker(node);
+ if (result instanceof Promise) {
+ result.then(() => loop(index + 1)).catch(_reject);
+ }
+ else {
+ loop(index + 1);
+ }
+ };
+ loop();
+ return promise;
}
- async walkOn(type, walker, skipWhenRuleIsDisabled = true) {
- for (const node of this.nodeList) {
+ walkOn(type, walker, skipWhenRuleIsDisabled = true) {
+ return this.walk(node => {
if (node instanceof tokens_1.MLDOMNode) {
if (skipWhenRuleIsDisabled && node.rule.disabled) {
- continue;
+ return;
}
if (node.is(type)) {
- await walker(node);
+ return walker(node);
}
}
- }
+ });
}
setRule(rule) {
this.currentRule = rule;
diff --git a/node_modules/@markuplint/ml-core/lib/ml-dom/helper/walkers.d.ts b/node_modules/@markuplint/ml-core/lib/ml-dom/helper/walkers.d.ts
index 1972a2a..d87476b 100644
--- a/node_modules/@markuplint/ml-core/lib/ml-dom/helper/walkers.d.ts
+++ b/node_modules/@markuplint/ml-core/lib/ml-dom/helper/walkers.d.ts
@@ -1,5 +1,5 @@
import { AnonymousNode } from '../types';
import { RuleConfigValue } from '@markuplint/ml-config';
-export declare type Walker<T extends RuleConfigValue, O = null, N = AnonymousNode<T, O>> = (node: N) => Promise<void>;
+export declare type Walker<T extends RuleConfigValue, O = null, N = AnonymousNode<T, O>> = (node: N) => void | Promise<void>;
export declare type SyncWalker<T extends RuleConfigValue, O = null, N = AnonymousNode<T, O>> = (node: N) => void;
export declare function syncWalk<T extends RuleConfigValue, O = null>(nodeList: AnonymousNode<T, O>[], walker: SyncWalker<T, O>): void;
diff --git a/node_modules/@markuplint/ml-core/lib/ml-rule/ml-rule.d.ts b/node_modules/@markuplint/ml-core/lib/ml-rule/ml-rule.d.ts
index e9f8442..dd4a74b 100644
--- a/node_modules/@markuplint/ml-core/lib/ml-rule/ml-rule.d.ts
+++ b/node_modules/@markuplint/ml-core/lib/ml-rule/ml-rule.d.ts
@@ -9,6 +9,16 @@ export declare class MLRule<T extends RuleConfigValue, O = null> {
readonly defaultServerity: Severity;
readonly defaultValue: T;
readonly defaultOptions: O;
+ /**
+ * The following getter is unused internally,
+ * only for extending from 3rd party library
+ */
+ private get v();
+ /**
+ * The following getter is unused internally,
+ * only for extending from 3rd party library
+ */
+ private get f();
private constructor();
verify(document: Document<T, O>, i18n: I18n, rule: RuleInfo<T, O>): Promise<VerifiedResult[]>;
fix(document: Document<T, O>, rule: RuleInfo<T, O>): Promise<void>;
diff --git a/node_modules/@markuplint/ml-core/lib/ml-rule/ml-rule.js b/node_modules/@markuplint/ml-core/lib/ml-rule/ml-rule.js
index 74086ec..7393b32 100644
--- a/node_modules/@markuplint/ml-core/lib/ml-rule/ml-rule.js
+++ b/node_modules/@markuplint/ml-core/lib/ml-rule/ml-rule.js
@@ -29,6 +29,20 @@ class MLRule {
static create(options) {
return new MLRule(options);
}
+ /**
+ * The following getter is unused internally,
+ * only for extending from 3rd party library
+ */
+ get v() {
+ return __classPrivateFieldGet(this, _v);
+ }
+ /**
+ * The following getter is unused internally,
+ * only for extending from 3rd party library
+ */
+ get f() {
+ return __classPrivateFieldGet(this, _f);
+ }
async verify(document, i18n, rule) {
if (!__classPrivateFieldGet(this, _v)) {
return [];
diff --git a/node_modules/@markuplint/ml-core/lib/ml-rule/types.d.ts b/node_modules/@markuplint/ml-core/lib/ml-rule/types.d.ts
index 6202d55..1488927 100644
--- a/node_modules/@markuplint/ml-core/lib/ml-rule/types.d.ts
+++ b/node_modules/@markuplint/ml-core/lib/ml-rule/types.d.ts
@@ -6,6 +6,6 @@ export interface MLRuleOptions<T extends RuleConfigValue, O = null> {
defaultLevel?: Severity;
defaultValue: T;
defaultOptions: O;
- verify(document: Document<T, O>, translate: Translator, globalRule: RuleInfo<T, O>): Promise<Result[]>;
- fix?(document: Document<T, O>, globalRule: RuleInfo<T, O>): Promise<void>;
+ verify(document: Document<T, O>, translate: Translator, globalRule: RuleInfo<T, O>): Result[] | Promise<Result[]>;
+ fix?(document: Document<T, O>, globalRule: RuleInfo<T, O>): void | Promise<void>;
}
Loading

0 comments on commit 9cd59ef

Please sign in to comment.