Skip to content

Commit 09262b3

Browse files
authored
feat: initial schema & manifests (#20)
Adds the first few manifests along with the first cut of the JSON schema they validate to.
1 parent e834b84 commit 09262b3

14 files changed

Lines changed: 795 additions & 127 deletions

‎.github/workflows/main.yml‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Build & Test
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
node-version: [18.x, 20.x, 21.x]
14+
fail-fast: false
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
- name: Use Node v${{ matrix.node-version }}
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: ${{ matrix.node-version }}
22+
- name: Install Dependencies
23+
run: npm ci
24+
- name: Build
25+
run: npm run build
26+
- name: Validate Manifests
27+
run: npm run validate-manifests

‎.github/workflows/publish.yml‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Publish (npm)
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: actions/setup-node@v4
13+
with:
14+
node-version: 22
15+
- run: npm ci
16+
- run: npm run build
17+
- run: npm run validate-schemas
18+
19+
publish-npm:
20+
needs: build
21+
runs-on: ubuntu-latest
22+
permissions:
23+
id-token: write
24+
steps:
25+
- uses: actions/checkout@v4
26+
- uses: actions/setup-node@v4
27+
with:
28+
node-version: 22.x
29+
registry-url: 'https://registry.npmjs.org'
30+
cache: 'npm'
31+
- run: npm ci
32+
- run: npm version ${TAG_NAME} --git-tag-version=false
33+
env:
34+
TAG_NAME: ${{ github.ref_name }}
35+
- run: npm publish --provenance --access public --tag next
36+
if: "github.event.release.prerelease"
37+
env:
38+
NODE_AUTH_TOKEN: ${{ secrets.npm_secret }}
39+
- run: npm publish --provenance --access public
40+
if: "!github.event.release.prerelease"
41+
env:
42+
NODE_AUTH_TOKEN: ${{ secrets.npm_secret }}

‎README.md‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ import {NativeReplacements} from 'module-replacements';
3232
We provide three manifests:
3333

3434
- All (includes every manifest)
35-
- Native replacements (modules which can be replaced by native equivalents)
36-
- Optimisation replacements (modules which can be replaced by leaner or
37-
closer-to-the-platform equivalents)
35+
- Native replacements
36+
- Micro utility replacements
37+
- Preferred replacements
3838

3939
#### Native replacements
4040

@@ -46,19 +46,20 @@ platform features can be replaced by their platform equivalents.
4646
Similarly, features which did not exist at the time but have now existed in
4747
the platform for many years, so no longer need a dependency.
4848

49-
#### Optimisation replacements
49+
#### Micro utility replacements
5050

51-
These are modules which have more optimal replacements.
51+
This is a more opinionated list of modules considered to be 'micro utilities' -
52+
very small utilities which could possibly be replaced with native equivalents
53+
or removed entirely.
5254

53-
For example, some modules have arguably unnecessarily deep dependencies trees,
54-
or rely on functionality themselves which fit into the "Native replacements"
55-
category. These should likely be replaced by leaner alternatives.
55+
#### Preferred replacements
5656

57-
Another example - modules which are too granularly modularised, leading to
58-
unnecessarily large amounts of small dependencies (aka "micro dependencies").
57+
This is a very opinionated list of modules with preferred replacements. Often
58+
these replacements are much lighter or more modern than the modules they are
59+
replacing.
5960

60-
Due to this being a one-to-many mapping (there are often many possible
61-
replacements), this list can contain multiple replacements per module.
61+
Sometimes these may also be forks of older packages which are actively
62+
maintained (unlike the source module).
6263

6364
# Contributing
6465

‎manifest-schema.json‎

Lines changed: 106 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,118 @@
11
{
2-
"$schema": "https://json-schema.org/draft/2020-12/schema",
3-
"$id": "https://github.com/es-tooling/module-replacements/blob/main/manifest-schema.json",
4-
"title": "Module replacements manifest schema",
5-
"description": "A schema for the structure used when defining JS module replacements",
2+
"$schema": "http://json-schema.org/draft-07/schema#",
63
"type": "object",
7-
"additionalProperties": false,
84
"properties": {
9-
"modules": {
5+
"moduleReplacements": {
106
"type": "array",
117
"items": {
12-
"type": "object",
13-
"additionalProperties": false,
14-
"properties": {
15-
"id": {
16-
"type": "string"
8+
"anyOf": [
9+
{
10+
"type": "object",
11+
"properties": {
12+
"type": {
13+
"type": "string",
14+
"const": "documented"
15+
},
16+
"moduleName": {
17+
"type": "string"
18+
},
19+
"category": {
20+
"type": "string"
21+
},
22+
"docPath": {
23+
"type": "string"
24+
}
25+
},
26+
"required": [
27+
"docPath",
28+
"moduleName",
29+
"type"
30+
],
31+
"additionalProperties": false
1732
},
18-
"replacements": {
19-
"type": "array",
20-
"items": {
21-
"type": "string"
22-
}
23-
}
24-
},
25-
"required": ["id", "replacements"]
26-
}
27-
},
28-
"replacements": {
29-
"type": "array",
30-
"items": {
31-
"type": "object",
32-
"additionalProperties": false,
33-
"properties": {
34-
"id": {
35-
"type": "string"
36-
},
37-
"native": {
38-
"type": "boolean"
33+
{
34+
"type": "object",
35+
"properties": {
36+
"type": {
37+
"type": "string",
38+
"const": "native"
39+
},
40+
"moduleName": {
41+
"type": "string"
42+
},
43+
"category": {
44+
"type": "string"
45+
},
46+
"mdnPath": {
47+
"type": "string"
48+
},
49+
"nodeVersion": {
50+
"type": "string"
51+
},
52+
"replacement": {
53+
"type": "string"
54+
}
55+
},
56+
"required": [
57+
"mdnPath",
58+
"moduleName",
59+
"nodeVersion",
60+
"replacement",
61+
"type"
62+
],
63+
"additionalProperties": false
3964
},
40-
"example": {
41-
"type": "string"
65+
{
66+
"type": "object",
67+
"properties": {
68+
"type": {
69+
"type": "string",
70+
"const": "simple"
71+
},
72+
"moduleName": {
73+
"type": "string"
74+
},
75+
"category": {
76+
"type": "string"
77+
},
78+
"replacement": {
79+
"type": "string"
80+
}
81+
},
82+
"required": [
83+
"moduleName",
84+
"replacement",
85+
"type"
86+
],
87+
"additionalProperties": false
4288
},
43-
"url": {
44-
"type": "string"
89+
{
90+
"type": "object",
91+
"properties": {
92+
"type": {
93+
"type": "string",
94+
"const": "none"
95+
},
96+
"moduleName": {
97+
"type": "string"
98+
},
99+
"category": {
100+
"type": "string"
101+
}
102+
},
103+
"required": [
104+
"moduleName",
105+
"type"
106+
],
107+
"additionalProperties": false
45108
}
46-
},
47-
"required": [
48-
"id", "example", "url"
49109
]
50110
}
51111
}
52-
}
53-
}
112+
},
113+
"required": [
114+
"moduleReplacements"
115+
],
116+
"additionalProperties": false,
117+
"definitions": {}
118+
}

‎manifests/micro-utilities.json‎

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
{
2+
"moduleReplacements": [
3+
{
4+
"type": "simple",
5+
"moduleName": "is-number",
6+
"replacement": "Use typeof v === \"number\"",
7+
"category": "micro-utilities"
8+
},
9+
{
10+
"type": "simple",
11+
"moduleName": "is-plain-object",
12+
"replacement": "Use typeof v === \"object\" && v !== null && v.constructor === Object",
13+
"category": "micro-utilities"
14+
},
15+
{
16+
"type": "simple",
17+
"moduleName": "is-primitve",
18+
"replacement": "Use v === null || (typeof v !== \"function\" && typeof v !== \"object\")",
19+
"category": "micro-utilities"
20+
},
21+
{
22+
"type": "simple",
23+
"moduleName": "is-regexp",
24+
"replacement": "Use v instanceof RegExp, or if cross-realm, use Object.prototype.toString.call(v) === \"[object RegExp]\"",
25+
"category": "micro-utilities"
26+
},
27+
{
28+
"type": "simple",
29+
"moduleName": "is-travis",
30+
"replacement": "Use (\"TRAVIS\" in process.env)",
31+
"category": "micro-utilities"
32+
},
33+
{
34+
"type": "simple",
35+
"moduleName": "is-npm",
36+
"replacement": "Use process.env.npm_config_user_agent?.startsWith(\"npm\")",
37+
"category": "micro-utilities"
38+
},
39+
{
40+
"type": "simple",
41+
"moduleName": "clone-regexp",
42+
"replacement": "Use new RegExp(regexpToCopy)",
43+
"category": "micro-utilities"
44+
},
45+
{
46+
"type": "simple",
47+
"moduleName": "split-lines",
48+
"replacement": "Use str.split(/\\r?\\n/)",
49+
"category": "micro-utilities"
50+
},
51+
{
52+
"type": "simple",
53+
"moduleName": "is-windows",
54+
"replacement": "Use process.platform === \"win32\"",
55+
"category": "micro-utilities"
56+
},
57+
{
58+
"type": "simple",
59+
"moduleName": "is-whitespace",
60+
"replacement": "Use str.trim() === \"\" or /^\\s*$/.test(str)",
61+
"category": "micro-utilities"
62+
},
63+
{
64+
"type": "simple",
65+
"moduleName": "is-string",
66+
"replacement": "Use typeof str === \"string\"",
67+
"category": "micro-utilities"
68+
},
69+
{
70+
"type": "simple",
71+
"moduleName": "is-odd",
72+
"replacement": "Use (n % 2) === 1",
73+
"category": "micro-utilities"
74+
},
75+
{
76+
"type": "simple",
77+
"moduleName": "is-even",
78+
"replacement": "Use (n % 2) === 0",
79+
"category": "micro-utilities"
80+
}
81+
]
82+
}

0 commit comments

Comments
 (0)