Skip to content

Commit

Permalink
Fix cwd with originalPath
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Feb 27, 2022
1 parent 97f6e93 commit e4b4f53
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/config/normalize/cwd.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import { has } from './lib/prop_path/get.js'
// repository could be re-used for different cwd
// - user can opt-out of that behavior by using absolute file paths, for
// example using the current file's path (e.g. `import.meta.url`)
export const getPropCwd = function (configInfos, { path }) {
export const getPropCwd = function (configInfos, { originalPath }) {
const configInfo = configInfos.find(({ configContents }) =>
has(configContents, path),
has(configContents, originalPath),
)

if (configInfo !== undefined) {
Expand Down
18 changes: 8 additions & 10 deletions src/config/normalize/lib/opts.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ export const getOpts = async function ({
moves,
}) {
const path = parse(name)
const funcOpts = { name, path, config, context }
const originalName = applyMoves(moves, name)
const originalPath = parse(originalName)
const funcOpts = { name, path, originalName, originalPath, config, context }
const opts = { funcOpts, example, prefix: DEFAULT_PREFIX }
const optsA = await computeOriginalName(opts, moves, parent)
const optsA = await computeParent(opts, moves, parent)
const optsB = await computePrefix(optsA, prefix)
const optsC = await computeCwd(optsB, cwd)
return optsC
Expand All @@ -32,14 +34,10 @@ export const getOpts = async function ({
// This is in contrast to `name|path` which are the main properties, intended to
// work with everything else, including `rule.name`, `rule.rename` and
// `funcOpts.config`.
const computeOriginalName = async function (opts, moves, parent) {
const originalName = applyMoves(moves, opts.funcOpts.name)
const originalNameA = await appendParentToName(parent, originalName, opts)
const originalPath = parse(originalNameA)
return {
...opts,
funcOpts: { ...opts.funcOpts, originalName: originalNameA, originalPath },
}
const computeParent = async function (opts, moves, parent) {
const originalName = await appendParentToName({ parent, opts })
const originalPath = parse(originalName)
return { ...opts, funcOpts: { ...opts.funcOpts, originalName, originalPath } }
}

const computePrefix = async function (opts, prefix) {
Expand Down
8 changes: 7 additions & 1 deletion src/config/normalize/lib/parent.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import { callUserFunc } from './call.js'
// It is exposed as `originalName` and `originalPath`.
// It is a dot-delimited string optionally ending with `.`
// By default, there are none.
export const appendParentToName = async function (parent, originalName, opts) {
export const appendParentToName = async function ({
parent,
opts,
opts: {
funcOpts: { originalName },
},
}) {
const parentA = await getParent(parent, opts)
const dot = getDot(parentA, originalName)
return `${parentA}${dot}${originalName}`
Expand Down
4 changes: 2 additions & 2 deletions src/config/plugin/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export const normalizePluginConfig = async function ({
}

// When the value was merged due to `sharedConfig`, ensure `parent` is correct
const getParent = function (unmergedConfig, name, { path }) {
return has(unmergedConfig, path) ? name : ''
const getParent = function (unmergedConfig, name, { originalPath }) {
return has(unmergedConfig, originalPath) ? name : ''
}

const normalizeSharedConfig = async function ({
Expand Down

0 comments on commit e4b4f53

Please sign in to comment.