Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Jun 5, 2022
1 parent 8988b9c commit f6835fc
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 31 deletions.
10 changes: 2 additions & 8 deletions src/config/normalize/lib/error.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import { createRequire } from 'module'

import { modernErrors } from '../../../error/modern/main.js'

// TODO: replace with JSON imports after dropping support for Node <16.14.0
const {
bugs: { url: bugsUrl },
} = createRequire(import.meta.url)('../../../../../package.json')
import { packageJson } from '../../../utils/package.js'

const { InputError, DefinitionError, KeywordError, onError } = modernErrors(
['InputError', 'DefinitionError', 'KeywordError'],
{ bugsUrl },
{ bugsUrl: packageJson.bugs.url },
)

export {
Expand Down
10 changes: 2 additions & 8 deletions src/config/plugin/lib/error.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import { createRequire } from 'module'

import { modernErrors } from '../../../error/modern/main.js'

// TODO: replace with JSON imports after dropping support for Node <16.14.0
const {
bugs: { url: bugsUrl },
} = createRequire(import.meta.url)('../../../../../package.json')
import { packageJson } from '../../../utils/package.js'

const { UserError, PluginError, ConsumerError, onError } = modernErrors(
['UserError', 'PluginError', 'ConsumerError'],
{ bugsUrl },
{ bugsUrl: packageJson.bugs.url },
)

export {
Expand Down
9 changes: 2 additions & 7 deletions src/error/main.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { createRequire } from 'module'
import { packageJson } from '../utils/package.js'

import { modernErrors } from './modern/main.js'

// TODO: replace with JSON imports after dropping support for Node <16.14.0
const {
bugs: { url: bugsUrl },
} = createRequire(import.meta.url)('../../../package.json')

const {
PluginError,
UserCodeError,
Expand All @@ -16,7 +11,7 @@ const {
onError,
} = modernErrors(
['PluginError', 'UserCodeError', 'UserError', 'LimitError', 'StopError'],
{ bugsUrl },
{ bugsUrl: packageJson.bugs.url },
)

export {
Expand Down
10 changes: 2 additions & 8 deletions src/runners/common/error.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { createRequire } from 'module'

import { modernErrors } from '../../error/modern/main.js'

// TODO: replace with JSON imports after dropping support for Node <16.14.0
const {
bugs: { url: bugsUrl },
} = createRequire(import.meta.url)('../../../../package.json')
import { packageJson } from '../../utils/package.js'

const {
IpcSerializationError,
Expand All @@ -22,7 +16,7 @@ const {
'TasksRunError',
'ConfigError',
],
{ bugsUrl },
{ bugsUrl: packageJson.bugs.url },
)

export {
Expand Down
6 changes: 6 additions & 0 deletions src/utils/package.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { createRequire } from 'module'

// TODO: replace with a JSON import after dropping support for Node <16.14.0
export const packageJson = createRequire(import.meta.url)(
'../../../package.json',
)

0 comments on commit f6835fc

Please sign in to comment.