Skip to content

Conversation

@jobala
Copy link
Contributor

@jobala jobala commented Nov 26, 2022

πŸŽ‰ Thanks for submitting a pull request! πŸŽ‰

Summary

Fixes #928


For us to review and ship your PR efficiently, please perform the following steps:

  • Open a bug/issue before writing your code πŸ§‘β€πŸ’». This ensures
    we can discuss the changes and get feedback from everyone that should be involved. If you`re fixing a typo or
    something that`s on fire πŸ”₯ (e.g. incident related), you can skip this step.
  • Read the contribution guidelines πŸ“–. This ensures your code follows our style guide and
    passes our tests.
  • Update or add tests (if any source code was changed or added) πŸ§ͺ
  • Update or add documentation (if features were changed or added) πŸ“
  • Make sure the status checks below are successful βœ…

A picture of a cute animal (not mandatory, but encouraged)

@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 2022

This pull request adds or modifies JavaScript (.js, .cjs, .mjs) files. Consider converting them to TypeScript.
Thank you for converting JavaScript files to TypeScript πŸŽ‰"

@jobala jobala force-pushed the chore/build-system-detection branch from 67e2a0a to 6821698 Compare December 5, 2022 13:02
@jobala jobala marked this pull request as ready for review December 6, 2022 12:25
@jobala jobala requested a review from lukasholzer December 6, 2022 12:27
@lukasholzer
Copy link
Contributor

Maybe you can add this one for the detection as well? https://moonrepo.dev/docs/setup-workspace

Copy link
Contributor

@lukasholzer lukasholzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you maybe add some test cases that would reflect a monorepo setup like:

const cwd = mockFileSystem({
  'frontend/WORKSPACE': '',
  'frontend/BUILD.bazel': '',
  'frontend/apps/my-app/BUILD.bazel': '',
})

and the baseDirectory is set to frontend/apps/my-app

like in monorepos (where build systems are used) it's mostly a baseDirectory and you don't search in the repo root. This should test the look up functionality.

Currently you only test the happy path from the workspace root. But often we don't know the workspace root as the repo root does not need to be the workspace root.

The repo root can contain no reference to JS projects at all and is somewhere in the baseDirectory.

'packages/server/server.js': '',
})

const buildSystems = await detectBuildSystems('packages/website', cwd)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the values that are passed here are absolute paths πŸ€”

Copy link
Contributor Author

@jobala jobala Dec 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What we pass as arguments here makes no difference sincegetContext resolves the absolute paths.

const { projectDir = cwd(), rootDir = '' } = config
// Get the absolute dirs for both project and root
// We resolve the projectDir from the rootDir
const absoluteProjectDir = resolve(rootDir, projectDir)
// If a relative absolute path is given we rely on cwd
const absoluteRootDir = rootDir ? resolve(cwd(), rootDir) : undefined
// We only pass through the root dir if it was provided and is actually different
// from the project dir
const validRootDir = absoluteRootDir && absoluteRootDir !== absoluteProjectDir ? absoluteRootDir : undefined

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But inside get-build-info.ts we are passing different values (so the tests are run with wrong data that is not used in production) Therefore we should change it to reflect the reality.

await detectBuildSystems(join(cwd, 'packages/website'), cwd)

'packages/server/server.js': '',
})

const buildSystems = await detectBuildSystems('packages/website', cwd)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But inside get-build-info.ts we are passing different values (so the tests are run with wrong data that is not used in production) Therefore we should change it to reflect the reality.

await detectBuildSystems(join(cwd, 'packages/website'), cwd)

@jobala
Copy link
Contributor Author

jobala commented Dec 12, 2022

so the tests are run with wrong data that is not used in production

I don't understand what you mean by wrong data here. getContext will resolve the relative baseDir to an absolute path. When you say wrong data does that mean reading a non-existent or wrong file?

@lukasholzer
Copy link
Contributor

so the tests are run with wrong data that is not used in production

I don't understand what you mean by wrong data here. getContext will resolve the relative baseDir to an absolute path. When you say wrong data does that mean reading a non-existent or wrong file?

In your test the function getting called with the following parameters:

const buildSystems = await detectBuildSystems('packages/website', cwd)
  1. Function parameter: 'package/website'
  2. Function parameter: '/some/absolute/path/to/theproject/dir'

BUT in production it get's called with different data because there it get's called with absolute paths:

CleanShot 2022-12-12 at 14 48 03

  1. Function parameter: '/some/absolute/path/to/theproject/dir/package/website'
  2. Function parameter: '/some/absolute/path/to/theproject/dir'

So your testcase does not reflect production data that's what I'm saying here

@jobala jobala requested a review from lukasholzer December 12, 2022 14:35
Copy link
Contributor

@lukasholzer lukasholzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@jobala jobala merged commit d591baf into main Dec 13, 2022
@jobala jobala deleted the chore/build-system-detection branch December 13, 2022 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants