Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: add packageManger information + make jsWorkspace packagePaths relative #4643

Merged
merged 10 commits into from
Oct 27, 2022

Conversation

lukasholzer
Copy link
Contributor

@lukasholzer lukasholzer commented Oct 19, 2022

🎉 Thanks for submitting a pull request! 🎉

Summary

This is needed for https://github.com/netlify/pillar-workflow/issues/895

This is a breaking change as we changed the jsWorkspace paths to be relatives than absolute ones.

The breaking change won't have an influence in buildbots usage as we just check if the property is present. There are no other users of @netlify/build-info at the moment in our organization:

CleanShot 2022-10-21 at 11 41 48


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)

@lukasholzer lukasholzer requested review from kitop, danez and jobala October 19, 2022 15:32
@lukasholzer lukasholzer force-pushed the feat/add-new-print-workspaces-command branch 3 times, most recently from 5b91787 to 8185a24 Compare October 20, 2022 10:56
@lukasholzer lukasholzer changed the title feat: add new print-workspaces command feat: add package manager detection Oct 20, 2022
@lukasholzer lukasholzer force-pushed the feat/add-new-print-workspaces-command branch 2 times, most recently from 9a340ae to b8112d9 Compare October 20, 2022 16:00
@lukasholzer lukasholzer marked this pull request as draft October 21, 2022 08:29
@lukasholzer lukasholzer force-pushed the feat/add-new-print-workspaces-command branch from b8112d9 to 5f7629c Compare October 21, 2022 09:25
@lukasholzer lukasholzer changed the title feat: add package manager detection feat!: add packageManger information + make jsWorkspace packagePaths relative Oct 21, 2022
@lukasholzer lukasholzer force-pushed the feat/add-new-print-workspaces-command branch 2 times, most recently from 5f3f37c to b9befb8 Compare October 21, 2022 09:34
"main": "./lib/main.js",
"types": "./lib/main.d.ts",
"exports": {
".": "./lib/index.js"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

restrict subpath imports (this should help to not introduce breaking changes that easily)

Only functions that are exported from lib/index.js are public api surface

import { exit, argv } from 'process'

import yargs, { Arguments } from 'yargs'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the entrypoint you should use with ESModules according to the documentation:

CleanShot 2022-10-21 at 11 34 02

Which has a slightly different api on the .command https://github.com/yargs/yargs

@@ -23,7 +23,7 @@ export type ContextOptions = {

export type Context = {
projectDir: string
rootDir: string
rootDir?: string
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The root dir must not be set (could be only projectDir as well in the regular case of being not a mono repository)

@@ -0,0 +1 @@
export { getBuildInfo } from './get-build-info.js'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is now the only public API surface we expose every change to this function signature is considered breaking.

All other functions are not on the API surface (except the behaviour is changed)

@lukasholzer lukasholzer marked this pull request as ready for review October 21, 2022 09:38
@lukasholzer lukasholzer force-pushed the feat/add-new-print-workspaces-command branch from 558415b to f85cd7c Compare October 24, 2022 13:08
jobala
jobala previously approved these changes Oct 24, 2022
@jobala jobala dismissed their stale review October 25, 2022 06:40

Approved by accident.

@jobala
Copy link
Contributor

jobala commented Oct 25, 2022

Assuming a user specifies the NETLIFY_USE_YARN env variable but then specifes pnpm in package.json's packageManager field. What happens then? My guess is that we will try to yarn install which will fail with a This project is configured to use pnpm error.

@lukasholzer
Copy link
Contributor Author

@lukasholzer
Copy link
Contributor Author

Assuming a user specifies the NETLIFY_USE_YARN env variable but then specifes pnpm in package.json's packageManager field. What happens then? My guess is that we will try to yarn install which will fail with a This project is configured to use pnpm error.

Yea but we cannot do better there the env variable needs to override (to not break excisting behaviours) but corepack only respects that.

Once this is out we don't need the environment variables anymore.

or what would be your suggestion

@github-actions
Copy link
Contributor

This pull request adds or modifies JavaScript (.js, .cjs, .mjs) files.
Consider converting them to TypeScript.

@jobala
Copy link
Contributor

jobala commented Oct 25, 2022

or what would be your suggestion

We have enough information to detect the clash between the environment variable and the packageManager field. We could either

  1. Let the user know there's a clash and fail the build
  2. Let the user know there's a clash and that we are defaulting to the what is specified in the packageManager field.

@lukasholzer
Copy link
Contributor Author

We have enough information to detect the clash between the environment variable and the packageManager field. We could either

  1. Let the user know there's a clash and fail the build
  2. Let the user know there's a clash and that we are defaulting to the what is specified in the packageManager field.

Would love to get @JGAntunes ideas here as we cannot log here to the user (currently) The log output is used to print just the json out.

We have multiple options:

  1. Option Add a --outfile=your.json to the command and redirect the stdout to the user. Additionally provide a --fileDescriptor flag which can be used to log debugging and humio information that is not visible to the customer.

  2. Option. Do the detection logic inside buildbot and not here (my preferred one):

like

if os.Getenv("NETLIFY_USE_PNPM") == "true" && info.PackageManager.Name != "pnpm" {
  b.ClientLog.Errorf("We've detected that you are setting the NETLIFY_USE_PNPM environment variable but you are not using pnpm instead you are using %s", info.PackageManager.Name)
}

Inside buildbot we can still control which package manager needs to be used

@jobala
Copy link
Contributor

jobala commented Oct 25, 2022

Do the detection logic inside buildbot and not here (my preferred one)

This is what I was thinking as well.

@lukasholzer
Copy link
Contributor Author

lukasholzer commented Oct 25, 2022

@jobala But then this PR should be good to go?

@JGAntunes
Copy link
Contributor

Would love to get @JGAntunes ideas here as we cannot log here to the user (currently) The log output is used to print just the json out.

We could also have this module return an array of detected package managers which could work based on precedence? (Similar to framework-info - https://github.com/netlify/framework-info)

Buildbot could then act based on that output (say, if we've detected you have packageManager set to something but you're forcing something else via env vars)

@jobala
Copy link
Contributor

jobala commented Oct 25, 2022

Created 2332 to track the issue ⬆️

Copy link
Contributor

@JGAntunes JGAntunes left a comment

Choose a reason for hiding this comment

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

Left a comment/question. Not a blocker at all 👍

}

// find the correct lock file the tree up
const lockFilePath = await findUp(Object.keys(lockFileMap), { cwd })
Copy link
Contributor

Choose a reason for hiding this comment

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

We have access to the repo's root. If provided shall we stop searching at that level?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point will adapt 👍

@lukasholzer lukasholzer merged commit 1b4eed8 into main Oct 27, 2022
@lukasholzer lukasholzer deleted the feat/add-new-print-workspaces-command branch October 27, 2022 13:18
JGAntunes pushed a commit that referenced this pull request Oct 31, 2022
…relative (#4643)

* feat!: add packageManger information + make jsWorkspace packagePaths relative

* chore: add further tests

* chore: fix typo

* chore: updates

* chore: latest discussions

* chore: fix tests on windows and old node

* chore: add stopAt parameter for look up

* chore: clean up
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants