Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ESM #46

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .c8rc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"reporter" : ["lcov", "cobertura", "text-summary"],
"extension": [".js", ".ts"],
"include": ["src/**/*.ts"],
"exclude": ["src/@types/**"]
}
27 changes: 19 additions & 8 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
root: true
parser: '@typescript-eslint/parser'
plugins:
- '@typescript-eslint'
parserOptions:
ecmaVersion: 11
sourceType: script
env:
node: true
es6: true
extends: eslint:recommended
rules:
no-unused-vars: off
project: './tsconfig.json'
sourceType: 'module'
ignorePatterns:
- 'scripts/*'
- '*.config.js'
- 'lib/*'
- 'examples/*'
- 'coverage/*'
- 'node_modules/*'
- '.yarn/*'
- '.nyc_output/*'
extends:
- 'eslint:recommended'
- 'plugin:@typescript-eslint/eslint-recommended'
- 'plugin:@typescript-eslint/recommended'
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:

strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
node-version: [18.x]

steps:
- uses: actions/checkout@v3
Expand All @@ -20,7 +20,7 @@ jobs:

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT

- uses: actions/cache@v3
id: yarn-cache
Expand All @@ -44,18 +44,18 @@ jobs:
CI: true

- name: Coveralls Parallel
uses: coverallsapp/github-action@v1.1.2
uses: coverallsapp/github-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
flag-name: node-${{ matrix.node-version }}
parallel: true

coverall:
needs: tests
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@v1.1.2
uses: coverallsapp/github-action@v1
with:
github-token: ${{ secrets.github_token }}
parallel-finished: true
parallel-finished: true
14 changes: 7 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ jobs:
strategy:
matrix:
node-version: [18.x]

if: ${{ github.actor == 'pebie' || github.actor == 'Crow-EH' || github.actor == 'fthouraud' || github.actor == 'leguellec' || github.actor == 'rande' }}

steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT

- uses: actions/cache@v3
id: yarn-cache
Expand All @@ -44,7 +44,7 @@ jobs:
- name: Bump the version using input strategy
run: yarn version --new-version ${{ github.event.inputs.strategy }} --no-git-tag-version

- name: Update changelog
- name: Update changelog
id: changelog
run: |
CHANGELOG=$(yarn conventional-changelog -p conventionalcommits -r -u 0)
Expand All @@ -53,12 +53,12 @@ jobs:
BODY="${BODY//'%'/'%25'}"
BODY="${BODY//$'\n'/'%0A'}"
BODY="${BODY//$'\r'/'%0D'}"
echo "::set-output name=body::${BODY}"
echo "{body}=${BODY}" >> $GITHUB_OUTPUT

- name: Log changes
run: |
echo "The changelog will be : ${{ steps.changelog.outputs.body }}"

- name: Get version
id: package-version
uses: martinbeentjes/[email protected]
Expand All @@ -85,7 +85,7 @@ jobs:
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'

- name: Publish to NPM
run: npm publish --access public
env:
Expand Down
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn check-fmt
yarn lint && yarn check-fmt
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18.14.0
11 changes: 11 additions & 0 deletions ava.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default {
require: ['ts-node/register'],
extensions: ['js', 'ts'],
files: ['test/**/*.test.{js,ts}'],
nodeArguments: ['--experimental-specifier-resolution=node', '--loader=ts-node/esm', '--no-warnings'],
environmentVariables: {
TS_NODE_FILES: 'true',
TS_NODE_TRANSPILE_ONLY: 'true',
TS_NODE_COMPILER_OPTIONS: '{"module":"ESNext"}',
},
}
6 changes: 3 additions & 3 deletions examples/example2.js → examples/cjs/example1.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const logger = require('../lib/index')
const logger = require('../../lib/cjs/index.js')

logger.setNamespaces('root:*')
logger.setLevel('debug')

const log = logger.createLogger('root:testing')
log.debug('ctxId', 'log with predefined context ID', {
log.debug('example1', {
foo: 'bar',
})
})
9 changes: 9 additions & 0 deletions examples/cjs/example2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const logger = require('../../lib/cjs/index.js')

logger.setNamespaces('root:*')
logger.setLevel('debug')

const log = logger.createLogger('root:testing')
log.debug('example2', 'log with predefined context ID', {
foo: 'bar',
})
8 changes: 8 additions & 0 deletions examples/cjs/example3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const logger = require('../../lib/cjs/index.js')

logger.setNamespaces('namespace:*')
logger.setLevel('debug')
//logger.setOutput(logger.outputs.json)

const log = logger.createLogger('namespace:subNamespace')
log.debug('example3', 'Will be logged', { someData: 'someValue', someData2: 'someValue' })
10 changes: 10 additions & 0 deletions examples/cjs/example_context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const logger = require('../../lib/cjs/index.js')

logger.setOutput(logger.outputs.pretty)
logger.setNamespaces('*')
logger.setLevel('info')
logger.setGlobalContext({ version: '2.0.0', env: 'dev' })

const log = logger.createLogger('namespace')

log.warn('example4', { someData: 'someValue' })
9 changes: 9 additions & 0 deletions examples/cjs/example_data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const logger = require('../../lib/cjs/index.js')

logger.setOutput(logger.outputs.pretty)
logger.setNamespaces('namespace:*')
logger.setLevel('info')

const log = logger.createLogger('namespace:subNamespace')

log.warn('example5', { someData: 'someValue' })
9 changes: 9 additions & 0 deletions examples/cjs/example_force.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const logger = require('../../lib/cjs/index.js')

logger.setOutput(logger.outputs.pretty)
logger.setNamespaces('*')
logger.setLevel('info')

const log = logger.createLogger('namespace', true)
const num = 1
log.debug('example6', { someData: 'someValue' }, num > 0)
8 changes: 8 additions & 0 deletions examples/cjs/example_pretty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const logger = require('../../lib/cjs/index.js')

logger.setNamespaces('namespace:*')
logger.setLevel('debug')
logger.setOutput(logger.outputs.pretty)

const log = logger.createLogger('namespace:subNamespace')
log.debug('example7', 'Will be logged', { someData: 'someValue', someData2: 'someValue' })
1 change: 1 addition & 0 deletions examples/cjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type": "commonjs"}
6 changes: 3 additions & 3 deletions examples/example1.js → examples/esm/example1.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const logger = require('../lib/index')
import logger from '../../lib/esm/index.js'

logger.setNamespaces('root:*')
logger.setLevel('debug')

const log = logger.createLogger('root:testing')
log.debug('sample message', {
log.debug('example1', {
foo: 'bar',
})
})
9 changes: 9 additions & 0 deletions examples/esm/example2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import logger from '../../lib/esm/index.js'

logger.setNamespaces('root:*')
logger.setLevel('debug')

const log = logger.createLogger('root:testing')
log.debug('example2', 'log with predefined context ID', {
foo: 'bar',
})
4 changes: 2 additions & 2 deletions examples/example3.js → examples/esm/example3.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const logger = require('../lib/index')
import logger from '../../lib/esm/index.js'

logger.setNamespaces('namespace:*')
logger.setLevel('debug')
//logger.setOutput(logger.outputs.json)

const log = logger.createLogger('namespace:subNamespace')
log.debug('ctxId', 'Will be logged', { someData: 'someValue', someData2: 'someValue' })
log.debug('example3', 'Will be logged', { someData: 'someValue', someData2: 'someValue' })
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const logger = require('../lib/index')
import logger from '../../lib/esm/index.js'

logger.setOutput(logger.outputs.pretty)
logger.setNamespaces('*')
Expand All @@ -7,4 +7,4 @@ logger.setGlobalContext({ version: '2.0.0', env: 'dev' })

const log = logger.createLogger('namespace')

log.warn('message', { someData: 'someValue' })
log.warn('example4', { someData: 'someValue' })
4 changes: 2 additions & 2 deletions examples/example_data.js → examples/esm/example_data.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const logger = require('../lib/index')
import logger from '../../lib/esm/index.js'

logger.setOutput(logger.outputs.pretty)
logger.setNamespaces('namespace:*')
logger.setLevel('info')

const log = logger.createLogger('namespace:subNamespace')

log.warn('message', { someData: 'someValue' })
log.warn('example5', { someData: 'someValue' })
4 changes: 2 additions & 2 deletions examples/example_force.js → examples/esm/example_force.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const logger = require('../lib/index')
import logger from '../../lib/esm/index.js'

logger.setOutput(logger.outputs.pretty)
logger.setNamespaces('*')
logger.setLevel('info')

const log = logger.createLogger('namespace', true)
const num = 1
log.debug('Will be logged', { someData: 'someValue' }, num > 0)
log.debug('example6', { someData: 'someValue' }, num > 0)
4 changes: 2 additions & 2 deletions examples/example_pretty.js → examples/esm/example_pretty.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const logger = require('../lib/index')
import logger from '../../lib/esm/index.js'

logger.setNamespaces('namespace:*')
logger.setLevel('debug')
logger.setOutput(logger.outputs.pretty)

const log = logger.createLogger('namespace:subNamespace')
log.debug('ctxId', 'Will be logged', { someData: 'someValue', someData2: 'someValue' })
log.debug('example7', 'Will be logged', { someData: 'someValue', someData2: 'someValue' })
1 change: 1 addition & 0 deletions examples/esm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type": "module"}
8 changes: 8 additions & 0 deletions examples/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env zx
import { $, chalk } from 'zx'

console.log(chalk.green('RUN ESM EXAMPLES:'))
await $`for file in examples/esm/*.js; do node "$file"; done`

console.log(chalk.green('RUN CJS EXAMPLES:'))
await $`for file in examples/cjs/*.js; do node "$file"; done`
Loading