Skip to content

Commit

Permalink
test: force resolveRoot to return relative paths for machine-agnostic…
Browse files Browse the repository at this point in the history
… snapshots
  • Loading branch information
apaleslimghost committed Nov 11, 2024
1 parent c83d778 commit ae6b2f2
Show file tree
Hide file tree
Showing 4 changed files with 376 additions and 365 deletions.
12 changes: 1 addition & 11 deletions core/cli/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { styles as s } from '@dotcom-tool-kit/logger'
import { CURRENT_RC_FILE_VERSION, type Plugin } from '@dotcom-tool-kit/plugin'
import type { RawConfig, ValidPluginsConfig } from '@dotcom-tool-kit/config'
import { invalid, reduceValidated, valid, Validated } from '@dotcom-tool-kit/validated'
import * as path from 'path'
import type { Logger } from 'winston'
import { loadToolKitRC } from './rc-file'
import { indentReasons } from './messages'
Expand All @@ -12,16 +11,7 @@ import { mergeCommands } from './plugin/merge-commands'
import { mergePluginOptions } from './plugin/merge-plugin-options'
import { mergeInits } from './plugin/merge-inits'
import { mergeTaskOptions } from './plugin/merge-task-options'

function resolveRoot(id: string, root: string): string {
const isPath = id.startsWith('.') || id.startsWith('/')
// resolve the package.json of a plugin as many plugins don't have valid
// entrypoints now that we're intending their tasks/hooks to be loaded via
// entrypoints defined in config
const modulePath = isPath ? id : path.join(id, 'package.json')
const resolvedPath = require.resolve(modulePath, { paths: [root] })
return path.dirname(resolvedPath)
}
import { resolveRoot } from './plugin/resolve-root'

export async function loadPlugin(
id: string,
Expand Down
11 changes: 11 additions & 0 deletions core/cli/src/plugin/resolve-root.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import path from "path"

export function resolveRoot(id: string, root: string): string {
const isPath = id.startsWith('.') || id.startsWith('/')
// resolve the package.json of a plugin as many plugins don't have valid
// entrypoints now that we're intending their tasks/hooks to be loaded via
// entrypoints defined in config
const modulePath = isPath ? id : path.join(id, 'package.json')
const resolvedPath = require.resolve(modulePath, { paths: [root] })
return path.dirname(resolvedPath)
}
Loading

0 comments on commit ae6b2f2

Please sign in to comment.