Skip to content

Commit

Permalink
feat: add support for ESM and Deno #95)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: exports maps are now used, which modifies import behavior.
  • Loading branch information
bcoe authored Sep 5, 2020
1 parent e037d0b commit 4d7ae94
Show file tree
Hide file tree
Showing 20 changed files with 526 additions and 205 deletions.
21 changes: 21 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"overrides": [
{
"files": "*.ts",
"parser": "@typescript-eslint/parser",
"rules": {
"no-unused-vars": "off",
"no-useless-constructor": "off",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/no-useless-constructor": "error"
}
}
],
"parserOptions": {
"ecmaVersion": 2017,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint/eslint-plugin"
]
}
22 changes: 22 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,25 @@ jobs:
- run: npm install
- run: npm test
- run: npm run coverage
esm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '14.x'
- run: npm install
- run: npm run test:esm
deno:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14
- run: npm install
- run: npm run compile
- uses: denolib/setup-deno@v2
- run: |
deno --version
deno test --allow-read test/deno/y18n-test.ts
32 changes: 31 additions & 1 deletion .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,38 @@ jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: GoogleCloudPlatform/release-please-action@v1.6.3
- uses: bcoe/release-please-action@v2.0.0
id: release
with:
token: ${{ secrets.GITHUB_TOKEN }}
release-type: node
package-name: y18n
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14
- run: npm install
- run: npm run compile
- name: push Deno release
run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
git remote add gh-token "https://${{ secrets.GITHUB_TOKEN}}@github.com/yargs/y18n.git"
git checkout -b deno
git add -f build
git commit -a -m 'chore: ${{ steps.release.outputs.tag_name }} release'
git push origin +deno
git tag -a ${{ steps.release.outputs.tag_name }}-deno -m 'chore: ${{ steps.release.outputs.tag_name }} release'
git push origin ${{ steps.release.outputs.tag_name }}-deno
if: ${{ steps.release.outputs.release_created }}
- uses: actions/setup-node@v1
with:
node-version: 14
registry-url: 'https://external-dot-oss-automation.appspot.com/'
if: ${{ steps.release.outputs.release_created }}
- run: npm install
if: ${{ steps.release.outputs.release_created }}
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
if: ${{ steps.release.outputs.release_created }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.DS_Store
node_modules
.nyc_output
build
coverage
package-lock.json
example.*
1 change: 0 additions & 1 deletion .nvmrc

This file was deleted.

17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@ output:

`2 fishes foo`

## Deno Example

As of `v5` `y18n` supports [Deno](https://github.com/denoland/deno):

```typescript
import y18n from "https://deno.land/x/y18n/deno.ts";

const __ = y18n({
locale: 'pirate',
directory: './test/locales'
}).__

console.info(__`Hi, ${'Ben'} ${'Coe'}!`)
```

You will need to run with `--allow-read` to load alternative locales.

## JSON Language Files

The JSON language files should be stored in a `./locales` folder.
Expand Down
9 changes: 9 additions & 0 deletions deno.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { y18n as _y18n } from './build/lib/index.js'
import { Y18NOpts } from './build/lib/index.d.ts'
import shim from './lib/platform-shims/deno.ts'

const y18n = (opts: Y18NOpts) => {
return _y18n(opts, shim)
}

export default y18n
188 changes: 0 additions & 188 deletions index.js

This file was deleted.

8 changes: 8 additions & 0 deletions index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import shim from './build/lib/platform-shims/node.js'
import { y18n as _y18n } from './build/lib/index.js'

const y18n = (opts) => {
return _y18n(opts, shim)
}

export default y18n
8 changes: 8 additions & 0 deletions lib/cjs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { y18n as _y18n, Y18NOpts } from './index.js'
import nodePlatformShim from './platform-shims/node.js'

const y18n = (opts: Y18NOpts) => {
return _y18n(opts, nodePlatformShim)
}

export default y18n
Loading

0 comments on commit 4d7ae94

Please sign in to comment.