Skip to content

Commit

Permalink
Duplicate getPluginPath()
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Feb 13, 2022
1 parent cebd241 commit b965217
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions src/config/load/resolvers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { getPluginPath } from '../plugin/lib/import.js'
import { createRequire } from 'module'

import { wrapError } from '../../error/wrap.js'

// The `config` can be:
// - a file path
Expand Down Expand Up @@ -31,8 +33,19 @@ const isNpmResolver = function (configOpt) {

export const CONFIG_NPM_PREFIX = 'spyd-config-'

// TODO: use import.meta.resolve() when available
const resolveNpm = function (configOpt, base) {
return getPluginPath(configOpt, base)
const { resolve } = createRequire(new URL(base, import.meta.url))

try {
return resolve(configOpt)
} catch (error) {
throw wrapError(
error,
`must be a valid package name: "${configOpt}".
This Node module was not found, please ensure it is installed.\n\n`,
)
}
}

// Additional resolvers.
Expand Down
2 changes: 1 addition & 1 deletion src/config/plugin/lib/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const safeGetPluginPath = function (id, propName, modulePrefix) {
}

// TODO: use import.meta.resolve() when available
export const getPluginPath = function (moduleName, base) {
const getPluginPath = function (moduleName, base) {
const { resolve } = createRequire(new URL(base, import.meta.url))

try {
Expand Down

0 comments on commit b965217

Please sign in to comment.