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

Add support for npm and pnpm #36

Merged
merged 10 commits into from
Sep 17, 2022

Conversation

NullVoxPopuli
Copy link
Collaborator

@NullVoxPopuli NullVoxPopuli commented Jul 4, 2022

The current released version of the addon-blueprint only provides yarn.

This PR:

  • adds the ability to use npm workspaces
  • adds the ability to pnpm workspaces
  • adds tests for npm, pnpm, and yarn
  • keeps scripts commands/behavior between the 3 package managers the same

Closes: #35

index.js Show resolved Hide resolved
@NullVoxPopuli NullVoxPopuli changed the title Support workspaces for npm, yarn, and pnpm Support workspaces for npm, yarn Aug 8, 2022
@NullVoxPopuli NullVoxPopuli changed the title Support workspaces for npm, yarn Support workspaces for npm, yarn, pnpm Aug 11, 2022
@NullVoxPopuli NullVoxPopuli marked this pull request as ready for review August 21, 2022 15:53
@NullVoxPopuli NullVoxPopuli changed the title Support workspaces for npm, yarn, pnpm Add support for npm, and pnpm -- add tests for npm, yarn, and pnpm Aug 21, 2022
@@ -42,6 +42,7 @@
"eslint-plugin-ember": "^10.5.8",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.0.0",
"prettier": "^2.5.1",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

eslint-plugin/config-prettier declare a prettier peer

@NullVoxPopuli NullVoxPopuli changed the title Add support for npm, and pnpm -- add tests for npm, yarn, and pnpm Add support for npm, and pnpm Aug 21, 2022
@NullVoxPopuli NullVoxPopuli requested a review from ef4 August 21, 2022 16:00
@NullVoxPopuli NullVoxPopuli added the enhancement New feature or request label Aug 21, 2022
@NullVoxPopuli NullVoxPopuli changed the title Add support for npm, and pnpm Add support for npm and pnpm Aug 21, 2022
Copy link
Collaborator

@simonihmig simonihmig left a comment

Choose a reason for hiding this comment

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

Thanks for working on this! Would love to land this asap, however I think I found a major bug that needs to get fixed...

tests/utils.ts Outdated
Comment on lines 25 to 30
if (packageManager === 'pnpm') {
console.info('An error occurred. Are there still upstream issues to resolve?');
console.error(e);

return;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems to me this special handling of pnpm here was probably mostly useful during development. Do we still need this, or can we just remove the catch-block?

Also, even if we want some special error message for pnpm, shouldn't this still throw? This is now returning "successfully" even when execa throws.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We do need this, because the app-blueprint is not peer-ily correct. The start of resolving that is here:

emberjs/ember-cli-babel#452

Copy link
Contributor

Choose a reason for hiding this comment

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

Both pnpm and npm support disabling the strict peer dep checking via .npmrc. If that is the reason for your special error handling, we should just use that setting instead.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

given our discussion about doing some more involved maintenance on ember-cli-babel, and doing a major over there, I went ahead and did the very specific error catching in this PR so we don't over-catch errors

index.js Outdated Show resolved Hide resolved
src/root-package-json.js Show resolved Hide resolved
let packageJson = path.join(options.target, 'package.json');
let json = await fs.readJSON(packageJson);

json.scripts = scripts(options);
Copy link
Collaborator

Choose a reason for hiding this comment

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

We are overriding the "template-based" scripts section now AFAICT? So the actual lint scripts like lint:js and lint:hbs are missing now, aren't they?

I think we have to decide if we want to split defining the scripts setup using both this programmatic approach and the blueprint "template", or just the former. In the first case, we would need to merge them here (and probably sort by key), in the latter we need to define all scripts in the root-package-json.js helper and remove them from the template (they are still in there, albeit unused).

Given tests are passing here, it also shows our testing approach is not complete yet. Beside these "smoke tests" we currently have (which run e.g. the lint script, which is now passing without actually linting anything), we probably need also some more traditional unit/integration like tests similar to what other blueprints do, testing the output against expected fixtures. Not in this PR of course, just mentioning here...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So the actual lint scripts like lint:js and lint:hbs are missing now, aren't they?

these already don't exist in the root package.json -- I'm matching pairity with the existing files/package.json: https://github.com/embroider-build/addon-blueprint/blob/main/files/package.json#L16

, it also shows our testing approach is not complete yet.

yup! lots more to do

testing the output against expected fixtures. Not in this PR of course, just mentioning here...

yeah, I can look in to doing this in a followup -- these are "snapshot tests with extra steps", which help catch accidental / unexpected changes -- which I think we're now ready for testing against

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ah also, until package.json .. or node in general supports jsonc, the templating we use in blueprints will not-so-great at documenting our context / thoughts / "why" / etc in the blueprint files.

@ef4
Copy link
Contributor

ef4 commented Aug 31, 2022

I agree with @simonihmig that the pnpm error handling should change before this can merge.

Instead of ignoring exceptions there is a precise way to disable the strict peer dep checking.

@NullVoxPopuli
Copy link
Collaborator Author

except we don't want to disable strict peer dep checking, so that's not exactly a solution. We want strict peer dep checking. The only problem is the @babel/core thing, which I have a PR here (from 3 weeks ago): emberjs/ember-cli-babel#452
Once the @babel/core issue is resolved in ember-cli-babel, the will be no issue for pnpm to throw an error for, and the exception handling can be removed.

@ef4
Copy link
Contributor

ef4 commented Aug 31, 2022

I agree. But the current exception-trapping approach already ignores strict peer dep failures.

My suggestion is to only ignore strict peer dep failures while allowing any other pnpm error to propagate.

When the underlying blueprint is corrected we would remove the setting, same as what you're suggesting with removing the exception trap.

@NullVoxPopuli
Copy link
Collaborator Author

I've updated the PR to do specific error-catching, rather than over-error catching.

ready for re-review, @simonihmig and @ef4 <3

@ef4 ef4 merged commit 1206d88 into embroider-build:main Sep 17, 2022
@NullVoxPopuli NullVoxPopuli deleted the workspaces-support branch September 17, 2022 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Planning --pnpm support, questions about yarn / npm workspaces
3 participants