Skip to content

Commit 36cb1d2

Browse files
committed
feat: update package to support esm
1 parent 0a47c4d commit 36cb1d2

File tree

7 files changed

+18
-15
lines changed

7 files changed

+18
-15
lines changed

index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable import/export */
2+
13
export * from './src/Contracts/FileContract'
24
export * from './src/Contracts/PaginationContract'
35
export * from './src/Contracts/DBUrlParserContract'

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "@secjs/utils",
3-
"version": "1.8.0",
3+
"version": "1.8.1",
4+
"type": "module",
45
"description": "",
56
"license": "MIT",
67
"author": "João Lenon <lenonSec7@gmail.com>",

src/Helpers/Config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class Config {
3535
Config.configs.clear()
3636
}
3737

38-
safeLoad(path: string) {
38+
async safeLoad(path: string) {
3939
const { name } = parse(path)
4040

4141
if (Config.configs.has(name)) {
@@ -45,7 +45,7 @@ export class Config {
4545
return this.load(path)
4646
}
4747

48-
load(path: string, callNumber = 0) {
48+
async load(path: string, callNumber = 0) {
4949
const { dir, name, base } = parse(path)
5050

5151
if (callNumber > 500) {
@@ -82,11 +82,11 @@ export class Config {
8282
// If configuration already exists continue the loop
8383
if (Config.configs.has(fileName)) continue
8484

85-
this.load(filePath, callNumber + 1)
85+
await this.load(filePath, callNumber + 1)
8686
}
8787
}
8888

8989
Config.debug.log(`Loading ${name} configuration file`)
90-
Config.configs.set(name, require(file.path).default)
90+
Config.configs.set(name, (await import(file.path)).default)
9191
}
9292
}

src/Utils/getBranch.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { promisify } from 'util'
2+
import { exec as ChildProcessExec } from 'child_process'
23

3-
// eslint-disable-next-line @typescript-eslint/no-var-requires
4-
const exec = promisify(require('child_process').exec)
4+
const exec = promisify(ChildProcessExec)
55

66
/**
77
* Get the actual branch HEAD from the repository

src/Utils/getCommitId.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { promisify } from 'util'
2+
import { exec as ChildProcessExec } from 'child_process'
23

3-
// eslint-disable-next-line @typescript-eslint/no-var-requires
4-
const exec = promisify(require('child_process').exec)
4+
const exec = promisify(ChildProcessExec)
55

66
/**
77
* Get the actual commit HEAD from the repository

tests/Helpers/config.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('\n Config Class', () => {
1515
const config = new Config()
1616

1717
config.clear()
18-
config.load(Path.tests('stubs/test.ts'))
18+
await config.load(Path.tests('stubs/test.ts'))
1919
})
2020

2121
it('should be able to get configurations values from Config class', async () => {
@@ -27,7 +27,7 @@ describe('\n Config Class', () => {
2727
it('should be able to create a load chain when a configuration uses other configuration', async () => {
2828
const config = new Config()
2929

30-
config.load(Path.tests('stubs/test-ondemand.ts'))
30+
await config.load(Path.tests('stubs/test-ondemand.ts'))
3131

3232
expect(Config.get('sub-test.sub')).toBe(true)
3333
expect(Config.get('test-ondemand.hello')).toBe(true)
@@ -36,14 +36,14 @@ describe('\n Config Class', () => {
3636
it('should be able to load configuration file without extension', async () => {
3737
const config = new Config()
3838

39-
config.load(Path.tests('stubs/no-extension'))
39+
await config.load(Path.tests('stubs/no-extension'))
4040

4141
expect(Config.get('no-extension.extension')).toBe(false)
4242
})
4343

4444
it('should throw an error when file is trying to use Config.get() to get information from other config file but this config file is trying to use Config.get() to this same file', async () => {
4545
try {
46-
new Config().load(Path.tests('stubs/infinite-callA.ts'))
46+
await new Config().load(Path.tests('stubs/infinite-callA.ts'))
4747
} catch (err) {
4848
expect(err.name).toBe('RecursiveConfigException')
4949
expect(err.status).toBe(500)
@@ -55,7 +55,7 @@ describe('\n Config Class', () => {
5555

5656
it('should throw an error when trying to load a file that is not normalized', async () => {
5757
try {
58-
new Config().load(Path.tests('stubs/test-error.ts'))
58+
await new Config().load(Path.tests('stubs/test-error.ts'))
5959
} catch (err) {
6060
expect(err.name).toBe('ConfigFileNotNormalizedException')
6161
expect(err.status).toBe(500)

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"compilerOptions": {
33
"baseUrl": ".",
44
"esModuleInterop": true,
5-
"module": "commonjs",
5+
"module": "esnext",
66
"moduleResolution": "Node",
77
"declaration": true,
88
"noImplicitAny": false,

0 commit comments

Comments
 (0)