Skip to content

Commit 4d7ae94

Browse files
authored
feat: add support for ESM and Deno #95)
BREAKING CHANGE: exports maps are now used, which modifies import behavior.
1 parent e037d0b commit 4d7ae94

File tree

20 files changed

+526
-205
lines changed

20 files changed

+526
-205
lines changed

‎.eslintrc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"overrides": [
3+
{
4+
"files": "*.ts",
5+
"parser": "@typescript-eslint/parser",
6+
"rules": {
7+
"no-unused-vars": "off",
8+
"no-useless-constructor": "off",
9+
"@typescript-eslint/no-unused-vars": "error",
10+
"@typescript-eslint/no-useless-constructor": "error"
11+
}
12+
}
13+
],
14+
"parserOptions": {
15+
"ecmaVersion": 2017,
16+
"sourceType": "module"
17+
},
18+
"plugins": [
19+
"@typescript-eslint/eslint-plugin"
20+
]
21+
}

‎.github/workflows/ci.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,25 @@ jobs:
3939
- run: npm install
4040
- run: npm test
4141
- run: npm run coverage
42+
esm:
43+
runs-on: ubuntu-latest
44+
steps:
45+
- uses: actions/checkout@v2
46+
- uses: actions/setup-node@v1
47+
with:
48+
node-version: '14.x'
49+
- run: npm install
50+
- run: npm run test:esm
51+
deno:
52+
runs-on: ubuntu-latest
53+
steps:
54+
- uses: actions/checkout@v2
55+
- uses: actions/setup-node@v1
56+
with:
57+
node-version: 14
58+
- run: npm install
59+
- run: npm run compile
60+
- uses: denolib/setup-deno@v2
61+
- run: |
62+
deno --version
63+
deno test --allow-read test/deno/y18n-test.ts

‎.github/workflows/release-please.yml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,38 @@ jobs:
77
release-please:
88
runs-on: ubuntu-latest
99
steps:
10-
- uses: GoogleCloudPlatform/release-please-action@v1.6.3
10+
- uses: bcoe/release-please-action@v2.0.0
11+
id: release
1112
with:
1213
token: ${{ secrets.GITHUB_TOKEN }}
1314
release-type: node
1415
package-name: y18n
16+
- uses: actions/checkout@v2
17+
- uses: actions/setup-node@v1
18+
with:
19+
node-version: 14
20+
- run: npm install
21+
- run: npm run compile
22+
- name: push Deno release
23+
run: |
24+
git config user.name github-actions[bot]
25+
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
26+
git remote add gh-token "https://${{ secrets.GITHUB_TOKEN}}@github.com/yargs/y18n.git"
27+
git checkout -b deno
28+
git add -f build
29+
git commit -a -m 'chore: ${{ steps.release.outputs.tag_name }} release'
30+
git push origin +deno
31+
git tag -a ${{ steps.release.outputs.tag_name }}-deno -m 'chore: ${{ steps.release.outputs.tag_name }} release'
32+
git push origin ${{ steps.release.outputs.tag_name }}-deno
33+
if: ${{ steps.release.outputs.release_created }}
34+
- uses: actions/setup-node@v1
35+
with:
36+
node-version: 14
37+
registry-url: 'https://external-dot-oss-automation.appspot.com/'
38+
if: ${{ steps.release.outputs.release_created }}
39+
- run: npm install
40+
if: ${{ steps.release.outputs.release_created }}
41+
- run: npm publish
42+
env:
43+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
44+
if: ${{ steps.release.outputs.release_created }}

‎.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
.DS_Store
22
node_modules
33
.nyc_output
4+
build
45
coverage
56
package-lock.json
7+
example.*

‎.nvmrc

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,23 @@ output:
4848

4949
`2 fishes foo`
5050

51+
## Deno Example
52+
53+
As of `v5` `y18n` supports [Deno](https://github.com/denoland/deno):
54+
55+
```typescript
56+
import y18n from "https://deno.land/x/y18n/deno.ts";
57+
58+
const __ = y18n({
59+
locale: 'pirate',
60+
directory: './test/locales'
61+
}).__
62+
63+
console.info(__`Hi, ${'Ben'} ${'Coe'}!`)
64+
```
65+
66+
You will need to run with `--allow-read` to load alternative locales.
67+
5168
## JSON Language Files
5269

5370
The JSON language files should be stored in a `./locales` folder.

‎deno.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { y18n as _y18n } from './build/lib/index.js'
2+
import { Y18NOpts } from './build/lib/index.d.ts'
3+
import shim from './lib/platform-shims/deno.ts'
4+
5+
const y18n = (opts: Y18NOpts) => {
6+
return _y18n(opts, shim)
7+
}
8+
9+
export default y18n

‎index.js

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

‎index.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import shim from './build/lib/platform-shims/node.js'
2+
import { y18n as _y18n } from './build/lib/index.js'
3+
4+
const y18n = (opts) => {
5+
return _y18n(opts, shim)
6+
}
7+
8+
export default y18n

‎lib/cjs.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { y18n as _y18n, Y18NOpts } from './index.js'
2+
import nodePlatformShim from './platform-shims/node.js'
3+
4+
const y18n = (opts: Y18NOpts) => {
5+
return _y18n(opts, nodePlatformShim)
6+
}
7+
8+
export default y18n

0 commit comments

Comments
 (0)