Skip to content

Commit

Permalink
feat: initial schema & manifests (#20)
Browse files Browse the repository at this point in the history
Adds the first few manifests along with the first cut of the JSON schema
they validate to.
  • Loading branch information
43081j authored Jun 5, 2024
1 parent e834b84 commit 09262b3
Show file tree
Hide file tree
Showing 14 changed files with 795 additions and 127 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Build & Test

on:
push:
branches: [master]
pull_request:

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x, 20.x, 21.x]
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Use Node v${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install Dependencies
run: npm ci
- name: Build
run: npm run build
- name: Validate Manifests
run: npm run validate-manifests
42 changes: 42 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Publish (npm)

on:
release:
types: [published]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: npm ci
- run: npm run build
- run: npm run validate-schemas

publish-npm:
needs: build
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22.x
registry-url: 'https://registry.npmjs.org'
cache: 'npm'
- run: npm ci
- run: npm version ${TAG_NAME} --git-tag-version=false
env:
TAG_NAME: ${{ github.ref_name }}
- run: npm publish --provenance --access public --tag next
if: "github.event.release.prerelease"
env:
NODE_AUTH_TOKEN: ${{ secrets.npm_secret }}
- run: npm publish --provenance --access public
if: "!github.event.release.prerelease"
env:
NODE_AUTH_TOKEN: ${{ secrets.npm_secret }}
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ import {NativeReplacements} from 'module-replacements';
We provide three manifests:

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

#### Native replacements

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

#### Optimisation replacements
#### Micro utility replacements

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

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

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

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

# Contributing

Expand Down
147 changes: 106 additions & 41 deletions manifest-schema.json
Original file line number Diff line number Diff line change
@@ -1,53 +1,118 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://github.com/es-tooling/module-replacements/blob/main/manifest-schema.json",
"title": "Module replacements manifest schema",
"description": "A schema for the structure used when defining JS module replacements",
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": false,
"properties": {
"modules": {
"moduleReplacements": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"properties": {
"id": {
"type": "string"
"anyOf": [
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "documented"
},
"moduleName": {
"type": "string"
},
"category": {
"type": "string"
},
"docPath": {
"type": "string"
}
},
"required": [
"docPath",
"moduleName",
"type"
],
"additionalProperties": false
},
"replacements": {
"type": "array",
"items": {
"type": "string"
}
}
},
"required": ["id", "replacements"]
}
},
"replacements": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"properties": {
"id": {
"type": "string"
},
"native": {
"type": "boolean"
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "native"
},
"moduleName": {
"type": "string"
},
"category": {
"type": "string"
},
"mdnPath": {
"type": "string"
},
"nodeVersion": {
"type": "string"
},
"replacement": {
"type": "string"
}
},
"required": [
"mdnPath",
"moduleName",
"nodeVersion",
"replacement",
"type"
],
"additionalProperties": false
},
"example": {
"type": "string"
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "simple"
},
"moduleName": {
"type": "string"
},
"category": {
"type": "string"
},
"replacement": {
"type": "string"
}
},
"required": [
"moduleName",
"replacement",
"type"
],
"additionalProperties": false
},
"url": {
"type": "string"
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "none"
},
"moduleName": {
"type": "string"
},
"category": {
"type": "string"
}
},
"required": [
"moduleName",
"type"
],
"additionalProperties": false
}
},
"required": [
"id", "example", "url"
]
}
}
}
}
},
"required": [
"moduleReplacements"
],
"additionalProperties": false,
"definitions": {}
}
82 changes: 82 additions & 0 deletions manifests/micro-utilities.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"moduleReplacements": [
{
"type": "simple",
"moduleName": "is-number",
"replacement": "Use typeof v === \"number\"",
"category": "micro-utilities"
},
{
"type": "simple",
"moduleName": "is-plain-object",
"replacement": "Use typeof v === \"object\" && v !== null && v.constructor === Object",
"category": "micro-utilities"
},
{
"type": "simple",
"moduleName": "is-primitve",
"replacement": "Use v === null || (typeof v !== \"function\" && typeof v !== \"object\")",
"category": "micro-utilities"
},
{
"type": "simple",
"moduleName": "is-regexp",
"replacement": "Use v instanceof RegExp, or if cross-realm, use Object.prototype.toString.call(v) === \"[object RegExp]\"",
"category": "micro-utilities"
},
{
"type": "simple",
"moduleName": "is-travis",
"replacement": "Use (\"TRAVIS\" in process.env)",
"category": "micro-utilities"
},
{
"type": "simple",
"moduleName": "is-npm",
"replacement": "Use process.env.npm_config_user_agent?.startsWith(\"npm\")",
"category": "micro-utilities"
},
{
"type": "simple",
"moduleName": "clone-regexp",
"replacement": "Use new RegExp(regexpToCopy)",
"category": "micro-utilities"
},
{
"type": "simple",
"moduleName": "split-lines",
"replacement": "Use str.split(/\\r?\\n/)",
"category": "micro-utilities"
},
{
"type": "simple",
"moduleName": "is-windows",
"replacement": "Use process.platform === \"win32\"",
"category": "micro-utilities"
},
{
"type": "simple",
"moduleName": "is-whitespace",
"replacement": "Use str.trim() === \"\" or /^\\s*$/.test(str)",
"category": "micro-utilities"
},
{
"type": "simple",
"moduleName": "is-string",
"replacement": "Use typeof str === \"string\"",
"category": "micro-utilities"
},
{
"type": "simple",
"moduleName": "is-odd",
"replacement": "Use (n % 2) === 1",
"category": "micro-utilities"
},
{
"type": "simple",
"moduleName": "is-even",
"replacement": "Use (n % 2) === 0",
"category": "micro-utilities"
}
]
}
Loading

0 comments on commit 09262b3

Please sign in to comment.