Skip to content
Permalink
Browse files
feat: add support for ESM and Deno #95)
BREAKING CHANGE: exports maps are now used, which modifies import behavior.
  • Loading branch information
bcoe committed Sep 5, 2020
1 parent e037d0b commit 4d7ae94bcb42e84164e2180366474b1cd321ed94
@@ -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"
]
}
@@ -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
@@ -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 }}
@@ -1,5 +1,7 @@
.DS_Store
node_modules
.nyc_output
build
coverage
package-lock.json
example.*
1 .nvmrc

This file was deleted.

@@ -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.
@@ -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 index.js

This file was deleted.

@@ -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
@@ -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

0 comments on commit 4d7ae94

Please sign in to comment.