Skip to content

Commit

Permalink
feat: initial release (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanhaticus authored Nov 5, 2024
1 parent a11c63b commit 357179e
Show file tree
Hide file tree
Showing 12 changed files with 4,403 additions and 0 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/test-build-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Test, Build, and Publish

on:
workflow_dispatch:
push:

permissions:
contents: write
issues: write
pull-requests: write

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 'lts/*'
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
build:
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 'lts/*'
- name: Install dependencies
run: npm ci
- name: Audit signatures
run: npm audit signatures
- name: Build library
run: npm run build
- name: Prepare artifact
run: |
mkdir -p ./lib/lib &&
find ./lib -mindepth 1 -maxdepth 1 ! -name "lib" -exec mv {} ./lib/lib/ \;
cp package.json README.md LICENSE ./lib
- uses: actions/upload-artifact@v4
with:
name: lib
path: ./lib
publish:
runs-on: ubuntu-latest
needs: build
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 'lts/*'
- uses: actions/download-artifact@v4
with:
name: lib
- name: Publish library
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
cd ./lib &&
npx semantic-release
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
lib/
coverage/
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v20.18.0
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# `Symbol.metadata` Polyfill

`@tsmetadata/polyfill` provides the necessary polyfill for legacy runtimes to properly use decorator metadata in TypeScript 5.2+.

In addition, the library provides the necessary global type declaration for `Symbol.metadata`.

- [🌱 Install](#-install)
- [⚙️ Usage](#️-usage)
- [🙏 Thanks](#-thanks)

## 🌱 Install
```bash
# `@tsmetadata/polyfill` is intended to be installed as a dev dependency.
npm install -D @tsmetadata/polyfill
```

## ⚙️ Usage
As early as possible, import the polyfill.
```typescript
import '@tsmetadata/polyfill';
```

After doing so, `Symbol.metadata` will be defined.

## 🙏 Thanks

Special thanks to Oleksandr Tarasiuk for implementing decorator metadata and to Andrew Branch for releasing an early version of this polyfill.
17 changes: 17 additions & 0 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import '../src';

describe('polyfill', () => {
describe('`Symbol.metadata`', () => {
it('should be defined', () => {
expect(Object.hasOwn(Symbol, 'metadata')).toBe(true);
});

it('should be of type symbol', () => {
expect(typeof Symbol.metadata).toBe('symbol');
});

it("should be named 'Symbol.metadata'", () => {
expect(Symbol.metadata.toString()).toBe('Symbol(Symbol.metadata)');
});
});
});
28 changes: 28 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"formatter": {
"enabled": true,
"indentStyle": "space",
"indentWidth": 2,
"lineWidth": 80,
"lineEnding": "lf"
},
"javascript": {
"formatter": {
"arrowParentheses": "always",
"bracketSameLine": true,
"bracketSpacing": true,
"quoteStyle": "single",
"quoteProperties": "asNeeded",
"semicolons": "always",
"trailingCommas": "all"
}
},
"json": {
"formatter": {
"trailingCommas": "none"
}
},
"files": {
"ignore": ["./coverage"]
}
}
24 changes: 24 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { Config } from 'jest';

const config: Config = {
preset: 'ts-jest',
testEnvironment: 'node',
coverageThreshold: {
global: {
branches: 100,
functions: 100,
lines: 100,
statements: 100,
},
},
transform: {
'^.+\\.ts?$': [
'ts-jest',
{
diagnostics: false,
},
],
},
};

export default config;
Loading

0 comments on commit 357179e

Please sign in to comment.