Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 04432dd

Browse files
committed
show an example that works without deasync (run with node --experimental-specifier-resolution=node .eslintrc.cjs)
1 parent 74ed14d commit 04432dd

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

.eslintrc.cjs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
const deasync = require('deasync'); // powerful magic
1+
main();
22

3-
const promiseSync = deasync((promise, cb) => {
4-
console.log('wait for promise, before');
5-
promise
3+
async function main() {
4+
5+
const importSync = name =>
6+
// promiseSync(
7+
import(name)
68
.then(result => {
79
console.log('promise resolved');
8-
cb(null, result);
10+
return result;
911
})
1012
.catch(error => {
1113
console.log('promise error');
12-
cb(error);
1314
});
14-
});
15-
16-
const importSync = name => promiseSync(import(name));
15+
// );
1716

1817
// Look, no await needed here!
1918
console.log('import sync before');
20-
const jestConfig = importSync('./jest.config.js').default;
19+
const jestConfig = (await importSync('./jest.config')).default;
2120
console.log('import sync after');
2221

2322
const testGlobals = {};
@@ -102,3 +101,5 @@ module.exports = {
102101
},
103102
],
104103
};
104+
105+
}

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import path from 'path';
2-
import server from './test/config/server.js';
2+
import server from './test/config/server';
33

44
console.log('jest.config');
55

0 commit comments

Comments
 (0)