Skip to content

Commit

Permalink
Merge pull request #543 from oclif/mdonnalley/workspace-root
Browse files Browse the repository at this point in the history
fix: use require.cache to resolve root
  • Loading branch information
mdonnalley committed May 2, 2024
2 parents 82a8830 + 7eb1051 commit ad0ef17
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@oclif/test",
"description": "test helpers for oclif components",
"version": "3.2.11",
"version": "3.2.12-dev.0",
"author": "Salesforce",
"bugs": "https://github.com/oclif/test/issues",
"dependencies": {
Expand Down
12 changes: 7 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ function traverseFilePathUntil(filename: string, predicate: (filename: string) =
return current
}

// Update to path.dirname(url.fileURLToPath(import.meta.url)) whenever we migrate to ESM
/* eslint-disable unicorn/prefer-module */
loadConfig.root = traverseFilePathUntil(
require.main?.path ?? module.path,
(p) => !(p.includes('node_modules') || p.includes('.pnpm') || p.includes('.yarn')),
)
loadConfig.root =
process.env.OCLIF_TEST_ROOT ??
Object.values(require.cache).find((m) => m?.children.includes(module))?.filename ??
traverseFilePathUntil(
require.main?.path ?? module.path,
(p) => !(p.includes('node_modules') || p.includes('.pnpm') || p.includes('.yarn')),
)
/* eslint-enable unicorn/prefer-module */

// Using a named export to import fancy causes this issue: https://github.com/oclif/test/issues/516
Expand Down

0 comments on commit ad0ef17

Please sign in to comment.