Skip to content

Commit

Permalink
Merge pull request #21 from nfroidure/refactor/esm_resolve
Browse files Browse the repository at this point in the history
feat(esm): full esm support
  • Loading branch information
nfroidure authored Feb 27, 2024
2 parents e87d100 + 5380d51 commit 30883f7
Show file tree
Hide file tree
Showing 19 changed files with 497 additions and 148 deletions.
3 changes: 2 additions & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This file is automatically generated by a `metapak`
# module. Do not change it elsewhere, changes would
# module. Do not change it here, your changes would
# be overridden.

engines:
eslint:
enabled: true
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ I'm a gentledev I:
```
<paste here>
```
If the result is lower than 18.16.0, there is
If the result is lower than 20.11.1, there is
poor chances I even have a look to it. Please,
use the last [NodeJS LTS version](https://nodejs.org/en/).

Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# This file is automatically generated by a `metapak`
# module. Do not change it here, your changes would
# be overridden.

name: Node.js CI

on:
Expand All @@ -12,12 +16,12 @@ jobs:

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

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
Expand Down
136 changes: 108 additions & 28 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
<dt><a href="#initRandom">initRandom(services)</a> ⇒ <code>Promise.&lt;function()&gt;</code></dt>
<dd><p>Instantiate the random service</p>
</dd>
<dt><a href="#initResolve">initResolve(path)</a> ⇒ <code>Promise.&lt;string&gt;</code></dt>
<dt><a href="#initResolve">initResolve(services)</a> ⇒ <code>Promise.&lt;function()&gt;</code></dt>
<dd><p>Instantiate the <code>resolve</code> service</p>
</dd>
<dt><a href="#resolve">resolve(path)</a> ⇒ <code>Promise.&lt;string&gt;</code></dt>
<dd><p>Allow to resolve a path with the module system.</p>
</dd>
<dt><a href="#initTime">initTime(services)</a> ⇒ <code>Promise.&lt;function()&gt;</code></dt>
Expand All @@ -47,10 +50,18 @@ Instantiate the codeGenerator service

**Example**
```js
import initCodeGenerator from 'common-services/dist/codeGenerator';
import {
DEFAULT_LOGGER,
initCodeGenerator,
initLog,
} from 'common-services';

const log = await initLog({
logger: DEFAULT_LOGGER,
});

const codeGenerator = await initCodeGenerator({
log: console.log.bind(console),
log,
});
```
<a name="initCodeGenerator..codeGenerator"></a>
Expand Down Expand Up @@ -90,11 +101,18 @@ Instantiate the counter service

**Example**
```js
import initCounter from 'common-services/dist/counter';
import {
initCounter,
initLog,
} from 'common-services';

const log = await initLog({
logger: DEFAULT_LOGGER
});

const counter = await initCounter({
COUNTER: { firstCount: 1 },
log: console.log.bind(console),
log,
});
```
<a name="initCounter..counter"></a>
Expand Down Expand Up @@ -128,10 +146,18 @@ Instantiate the delay service

**Example**
```js
import initDelay from 'common-services/dist/delay';
import {
DEFAULT_LOGGER,
initDelay,
initLog,
} from 'common-services';

const log = await initLog({
logger: DEFAULT_LOGGER
});

const delay = await initDelay({
log: console.log.bind(console)
log,
});
```

Expand Down Expand Up @@ -213,19 +239,23 @@ Instantiate the lock service

**Example**
```js
import initLog from 'common-services/dist/log';
import initDelayService from 'common-services/dist/delay';
import initLock from 'common-services/dist/lock';
import {
DEFAULT_LOGGER,
initLog,
initDelay,
initLock
} from 'common-services';
import ms from 'ms';
import winston from 'winston';
import debug from 'debug';

const log = await initLogService({
logger: winston,
debug: debug('myapp'),
const log = await initLog({
logger: DEFAULT_LOGGER
});
const delay = await initDelay({ log });
const lock = await initLock({
LOCK_TIMEOUT: ms('5s'),
delay,
log,
});
const delay = await initDelayService({ log });
const lock = await initLock ({ LOCK_TIMEOUT: ms('5s'), delay, log });


run();
Expand Down Expand Up @@ -289,14 +319,14 @@ Instantiate the logging service
**Example**
```js
import initLog from 'common-services/dist/log';
import debug from 'debug';
import winston from 'winston';
import {
DEFAULT_LOGGER,
initLog,
} from 'common-services';

const log = await initLog({
logger: winston,
debug: debug('myapp'),
});
logger: DEFAULT_LOGGER,
});
```
<a name="initLog..log"></a>
Expand Down Expand Up @@ -329,10 +359,18 @@ Instantiate the random service
**Example**
```js
import initRandom from 'common-services/dist/random';
import {
DEFAULT_LOGGER,
initLog,
initRandom
} from 'common-services';

const log = await initLog({
logger: DEFAULT_LOGGER,
});

const random = await initRandom({
log: console.log.bind(console),
log,
});
```
<a name="initRandom..random"></a>
Expand All @@ -349,7 +387,41 @@ random()
```
<a name="initResolve"></a>
## initResolve(path) ⇒ <code>Promise.&lt;string&gt;</code>
## initResolve(services) ⇒ <code>Promise.&lt;function()&gt;</code>
Instantiate the `resolve` service
**Kind**: global function
**Returns**: <code>Promise.&lt;function()&gt;</code> - A promise of the `resolve` service
| Param | Type | Description |
| --- | --- | --- |
| services | <code>Object</code> | The services to inject |
| services.MAIN_FILE_URL | <code>String</code> | An URL pointing to the main file run |
| [services.log] | <code>function</code> | A logging function |
**Example**
```js
import {
DEFAULT_LOGGER,
initLog,
initResolve,
} from 'common-services';

const log = await initLog({
logger: DEFAULT_LOGGER,
});

const resolve = initResolve({
MAIN_FILE_URL: import.meta.url,
log,
});

resolve('./myfile.ts');
}
```
<a name="resolve"></a>
## resolve(path) ⇒ <code>Promise.&lt;string&gt;</code>
Allow to resolve a path with the module system.
**Kind**: global function
Expand All @@ -374,10 +446,18 @@ Instantiate the time service
**Example**
```js
import initTime from 'common-services/dist/time';
import {
DEFAULT_LOGGER,
initLog,
initTime,
} from 'common-services';

const log = await initLog({
logger: DEFAULT_LOGGER,
});

const time = await initTime({
log: console.log.bind(console),
log,
});
```
<a name="initTime..time"></a>
Expand Down
2 changes: 1 addition & 1 deletion ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ I prefer using a unique function with the `log` type
If provided, I route debug messages to the `debug`
node module.

[See in context](./src/services/log.ts#L53-L63)
[See in context](./src/services/log.ts#L56-L66)



Expand Down
Loading

0 comments on commit 30883f7

Please sign in to comment.