Skip to content

Commit 6e6c38a

Browse files
authored
feat: use new data api (#56)
1 parent 5e6a53d commit 6e6c38a

19 files changed

+116
-26603
lines changed

.github/workflows/CD.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ jobs:
2323
with:
2424
node-version: latest
2525
cache: 'pnpm'
26+
# config recommended by pnpm error
27+
- run: pnpm config set store-dir "/home/runner/setup-pnpm/node_modules/.bin/store/v3" --global
2628

27-
- name: Build library
28-
run: pnpm install && pnpm build && pnpm run version
29+
- run: pnpm install
30+
- run: pnpm build
2931

3032
- name: Create Release Pull Request or Publish to npm
3133
id: changesets

.github/workflows/CI.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ jobs:
1616
with:
1717
node-version: latest
1818
cache: 'pnpm'
19-
# comfig recommended by pnpm error
19+
# config recommended by pnpm error
2020
- run: pnpm config set store-dir "/home/runner/setup-pnpm/node_modules/.bin/store/v3" --global
21-
21+
2222
- run: pnpm install
2323
- run: pnpm build
2424
- run: pnpm lint

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ The linter config should target the server bundle, not client.
2929
npm install @menglinmaker/eslint-plugin-runtime-compat
3030
```
3131

32-
2. Add `eslint.config.mjs` to root
32+
2. Add `eslint.config.mjs` to root. This detects incompatible APIs for all runtimes in the dataset.
3333
```Bash
3434
import runtimeCompat from "@menglinmaker/eslint-plugin-runtime-compat";
3535

@@ -38,10 +38,7 @@ export default [runtimeCompat.configs.strict];
3838

3939
Alternatively, you can load a custom config:
4040
```Bash
41-
export default [runtimeCompat.configs.custom(['node', 'bun', 'deno'], {
42-
deprecated: true,
43-
experimental: true,
44-
})];
41+
export default [runtimeCompat.configs.custom(['node', 'bun', 'deno'])];
4542
```
4643

4744
## Limitations:

packages/data/preprocess.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ const mapCompatData = new Map<string, PreprocessCompatStatement>()
4747
for (const key of keys) {
4848
const subData = compatData[key]
4949
if (key === '__compat') {
50-
const finalCompatStatement = extractPreprocessCompatStatement(subData as never)
51-
mapCompatData.set(JSON.stringify(parentKeys), finalCompatStatement)
50+
const preprocessCompatStatement = extractPreprocessCompatStatement(subData as never)
51+
mapCompatData.set(JSON.stringify(parentKeys), preprocessCompatStatement)
5252
} else {
5353
// Only chain keys if "__compat" exists
5454
const nodeHasCompatData = !keys.includes('__compat')
@@ -73,37 +73,38 @@ const preprocessCompatData: PreprocessCompatData = {
7373
}
7474
{
7575
const isPascalCase = (s: string | undefined) => s?.match(/^[A-Z]+.*/)
76-
for (const [jsonKeys, finalCompatStatement] of mapCompatData.entries()) {
76+
77+
for (const [jsonKeys, preprocessCompatStatement] of mapCompatData.entries()) {
7778
const keys = JSON.parse(jsonKeys) as string[]
7879
if (keys.length === 1) {
7980
if (isPascalCase(keys[0])) {
8081
// PascalCase, hence a class
81-
preprocessCompatData.class[jsonKeys] = finalCompatStatement
82+
preprocessCompatData.class[jsonKeys] = preprocessCompatStatement
8283
} else {
8384
// camelCase, hence a variable or function
84-
preprocessCompatData.global[jsonKeys] = finalCompatStatement
85+
preprocessCompatData.global[jsonKeys] = preprocessCompatStatement
8586
}
8687
} else if (keys.length === 2) {
8788
if (keys[0] === keys[1])
8889
// Duplicate keys are class constructors
89-
preprocessCompatData.class[JSON.stringify([keys[0]])] = finalCompatStatement
90+
preprocessCompatData.class[JSON.stringify([keys[0]])] = preprocessCompatStatement
9091
else if (keys[1]?.match('_static')) {
9192
// Static methods have '_static'
9293
const newKeys = JSON.stringify([keys[0], keys[1]?.replace('_static', '')])
9394
if (isPascalCase(keys[0]))
94-
preprocessCompatData.classProperty[newKeys] = finalCompatStatement
95-
else preprocessCompatData.globalClassProperty[newKeys] = finalCompatStatement
95+
preprocessCompatData.classProperty[newKeys] = preprocessCompatStatement
96+
else preprocessCompatData.globalClassProperty[newKeys] = preprocessCompatStatement
9697
} else if (keys[1]?.match('_event')) {
9798
// Events have '_event'
9899
const newKeys = JSON.stringify([keys[0], keys[1]?.replace('_event', '')])
99-
preprocessCompatData.eventListener[newKeys] = finalCompatStatement
100+
preprocessCompatData.eventListener[newKeys] = preprocessCompatStatement
100101
} else if (!keys[1]?.match('_'))
101102
// Normal class property
102-
preprocessCompatData.classProperty[jsonKeys] = finalCompatStatement
103-
else preprocessCompatData.misc[jsonKeys] = finalCompatStatement
103+
preprocessCompatData.classProperty[jsonKeys] = preprocessCompatStatement
104+
else preprocessCompatData.misc[jsonKeys] = preprocessCompatStatement
104105
} else {
105106
// Not sure how to analyse
106-
preprocessCompatData.misc[JSON.stringify([keys[0]])] = finalCompatStatement
107+
preprocessCompatData.misc[JSON.stringify([keys[0]])] = preprocessCompatStatement
107108
}
108109
}
109110
}

packages/data/src/filterSupportCompatData.ts

Lines changed: 0 additions & 55 deletions
This file was deleted.

packages/data/src/getUnsupportedRuntimes.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

packages/data/src/index.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import type { RuntimeName } from 'runtime-compat-data'
2-
import data from 'runtime-compat-data'
3-
import { filterSupportCompatData } from './filterSupportCompatData.js'
4-
import { mapCompatData } from './mapCompatData.js'
5-
import type { ParsedCompatData, RuleConfig } from './types.js'
2+
import { filterPreprocessCompatData, preprocessCompatData } from './runtime'
63

7-
export type { RuleConfig, ParsedCompatData, RuntimeName }
8-
export { filterSupportCompatData, mapCompatData, data }
4+
export type { RuntimeName }
5+
export { filterPreprocessCompatData, preprocessCompatData }

packages/data/src/mapCompatData.ts

Lines changed: 0 additions & 46 deletions
This file was deleted.

packages/data/src/runtime.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import _preprocessCompatData from './preprocessCompatData.json'
2-
3-
import type { RuntimeName } from 'runtime-compat-data'
2+
import type { RuntimeName, StatusBlock } from 'runtime-compat-data'
43
import { objectKeys } from './objectKeys'
54
import type {
65
PreprocessCompatData,
@@ -40,6 +39,28 @@ const getUnsupportedRuntimes = (
4039
return unsupportedRuntimes
4140
}
4241

42+
/**
43+
* Generates error message from parsed compat data.
44+
* @param keys
45+
* @param url - Doc url.
46+
* @param status - status block of API.
47+
* @param unsupported - Unsupported runtimes.
48+
* @returns Error message.
49+
*/
50+
export const errorMessage = (
51+
keys: string[],
52+
url: string,
53+
status: StatusBlock,
54+
unsupported: RuntimeName[],
55+
) => {
56+
let apiStatus = status.standard_track ? 'standard' : ''
57+
apiStatus = status.deprecated ? 'deprecated' : apiStatus
58+
apiStatus = status.experimental ? 'experimental' : apiStatus
59+
60+
const docString = `Docs - ${url}`
61+
return `[${keys}] - Unsupported ${apiStatus} API for [${unsupported}]\n${docString}`
62+
}
63+
4364
/**
4465
* Clean flat compat data object, retaining only unsupported runtimes.
4566
* @param flatCompatData - Flat compat data object.
@@ -67,10 +88,17 @@ export const filterPreprocessCompatData = (
6788
filterRuntimes,
6889
)
6990
if (unsupportedRuntimes.length > 0) {
91+
const error = errorMessage(
92+
JSON.parse(jsonKeys),
93+
preprocessCompatStatement.url,
94+
preprocessCompatStatement.status,
95+
unsupportedRuntimes,
96+
)
7097
parsedCompatData[context].set(jsonKeys, {
7198
url: preprocessCompatStatement.url,
7299
status: preprocessCompatStatement.status,
73100
unsupported: unsupportedRuntimes,
101+
error,
74102
})
75103
}
76104
}

packages/data/src/tests/filterSupportCompatData.test.ts

Lines changed: 0 additions & 89 deletions
This file was deleted.

0 commit comments

Comments
 (0)