Skip to content

Commit

Permalink
fix: commonjs implementation + added example for integration testing
Browse files Browse the repository at this point in the history
  • Loading branch information
kshutkin committed Dec 2, 2021
1 parent 6fcc8ba commit 0d6047d
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 74 deletions.
8 changes: 4 additions & 4 deletions draftlog-appender/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
"type": "module",
"exports": {
".": {
"require": "./dist/index.js",
"require": "./dist/index.cjs",
"default": "./dist/index.mjs"
},
"./core": {
"require": "./dist/core.js",
"require": "./dist/core.cjs",
"default": "./dist/core.mjs"
},
"./spinners": {
"require": "./spinners/dist/spinners.js",
"require": "./spinners/dist/spinners.cjs",
"default": "./spinners/dist/spinners.mjs"
}
},
"main": "./dist/index.js",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"typings": "./dist/index.d.ts",
"files": [
Expand Down
6 changes: 4 additions & 2 deletions draftlog-appender/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ export default [{
output: {
format: 'es',
dir: dest,
entryFileNames: '[name].mjs'
entryFileNames: '[name].mjs',
chunkFileNames: '[name].mjs'
},

plugins: [preprocess({ include: [ 'src/index.ts' ], context: { esm: true } }), ...plugins],
Expand All @@ -144,7 +145,8 @@ export default [{
output: {
format: 'cjs',
dir: dest,
entryFileNames: '[name].js'
entryFileNames: '[name].cjs',
chunkFileNames: '[name].cjs'
},

plugins: [preprocess({ include: [ 'src/index.ts' ], context: { cjs: true } }), ...plugins],
Expand Down
58 changes: 58 additions & 0 deletions examples/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
require("@niceties/draftlog-appender");
const { createLogger } = require("@niceties/logger");
const kleur = require("kleur");

const waitFor = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds));

const logger2 = createLogger();
const logger3 = createLogger(logger2);
const logger4 = createLogger(logger3);
const logger5 = createLogger(logger3);
const logger6 = createLogger(logger3);

Promise.resolve()
.then(() => {
const logger = createLogger();

logger.start('I am going to be freed soon');

logger(`${kleur.blue(kleur.bgWhite(kleur.bold('just a log line')))}`);
})
.then(() => waitFor(200))
.then(() => {
console.log('I am from console.log');

global.gc();
})
.then(() => waitFor(200))
.then(() => {
logger4.start('I have parent missing');
})
.then(() => waitFor(500))
.then(() => {
logger5.update('I have parent missing');
})
.then(() => waitFor(500))
.then(() => {
logger6.update('I have parent missing');
})
.then(() => waitFor(500))
.then(() => {
logger2.start('I am the another missing parent');
logger6.finish('I am finished with error', 3);
logger3.start('I am the missing parent');

logger4.start('I found the parent');
logger5.start('I found the parent');
})
.then(() => waitFor(1000))
.then(() => {
logger2.finish('Job finished');
logger3.finish('Ok');
logger4.finish('Ok !');
logger5.finish('Kind of Ok !!', 2);
})
.then(() => waitFor(500))
.then(() => {
console.log('');
});
2 changes: 1 addition & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Examples for @liceties/logger and basic integration tests",
"main": "index.js",
"scripts": {
"test": "node ./test-filter.mjs > ./result.log && node ./check-result.mjs && node --expose-gc ./index.mjs"
"test": "node ./test-filter.mjs > ./result.log && node ./check-result.mjs && node --expose-gc ./index.mjs && node --expose-gc ./index.js"
},
"author": "Konstantin Shutkin",
"license": "MIT",
Expand Down
14 changes: 7 additions & 7 deletions logger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,31 @@
"type": "module",
"exports": {
".": {
"require": "./dist/index.js",
"require": "./dist/index.cjs",
"default": "./dist/index.mjs"
},
"./default-formatting": {
"require": "./dist/default-formatting.js",
"require": "./dist/default-formatting.cjs",
"default": "./dist/default-formatting.mjs"
},
"./core": {
"require": "./dist/core.js",
"require": "./dist/core.cjs",
"default": "./dist/core.mjs"
},
"./simple": {
"require": "./dist/simple.js",
"require": "./dist/simple.cjs",
"default": "./dist/simple.mjs"
},
"./console-appender": {
"require": "./dist/console-appender.js",
"require": "./dist/console-appender.cjs",
"default": "./dist/console-appender.mjs"
},
"./format-utils": {
"require": "./dist/format-utils.js",
"require": "./dist/format-utils.cjs",
"default": "./dist/format-utils.mjs"
}
},
"main": "./dist/index.js",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"typings": "./dist/index.d.ts",
"unpkg": "./dist/simple.umd.js",
Expand Down
6 changes: 4 additions & 2 deletions logger/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ export default [{
output: {
format: 'es',
dir: dest,
entryFileNames: '[name].mjs'
entryFileNames: '[name].mjs',
chunkFileNames: '[name].mjs'
},

plugins: [preprocess({ include: [ 'src/index.ts' ], context: { esm: true } }), ...plugins],
Expand All @@ -147,7 +148,8 @@ export default [{
output: {
format: 'cjs',
dir: dest,
entryFileNames: '[name].js'
entryFileNames: '[name].cjs',
chunkFileNames: '[name].cjs'
},

plugins: [preprocess({ include: [ 'src/index.ts' ], context: { cjs: true } }), ...plugins],
Expand Down
71 changes: 13 additions & 58 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0d6047d

Please sign in to comment.