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(js): standalone executor for generating package.json #16330

Closed

Conversation

jensbodal
Copy link
Contributor

@jensbodal jensbodal commented Apr 16, 2023

  • generates a package.json based on the project's dependencies in node_modules
  • moves getExtraDependencies helper from esbuild package to js package

Current Behavior

Currently each executor implements their own (generally similar) logic for generating a package.json. Adding this executor and function should allow for

  1. Decomposing existing implementations to use a common method
  2. Other executors to more easily add the ability to include this option in their schema
  3. Any executor that lacks this functionality to use this executor directly to "wrap" an existing executor using dependsOn

Expected Behavior

If an executor is missing the ability to generate a package.json file this executor can be called in dependsOn to provide the functionality.

Related Issue(s)

Related to #16042 which doesn't necessarily fix that issue but can allow generating a package.json by calling this executor in the depends on block.

Example

project.json:

{
  "name": "api",
  //...
  "targets": {
    "build": {
      "dependsOn": [
        { "projects": "self", "target": "build-api", "params": "forward" }
      ],
      "executor": "@nx/js:generate-package-json",
      "options": {
        "outputPath": "dist/apps/api",
        "main": "apps/api/src/main.ts",
        "tsConfig": "apps/api/tsconfig.app.json"
      }
    },
    "build-api": {
      "executor": "@nx/vite:build",
      //...
      "configurations": {
        "production": {
          "mode": "production"
        }
      }
    },
    "serve": {
      "executor": "@nx/vite:dev-server",
      //...
      "configurations": {
        "production": {
          "buildTarget": "api:build:production"
        }
      }
    }
  }
}

@vercel
Copy link

vercel bot commented Apr 16, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nx-dev ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 13, 2023 5:19am

@jensbodal jensbodal force-pushed the feat/js-generate-package-json-executor branch from 896c1ca to c200fe9 Compare April 17, 2023 09:56
@jensbodal jensbodal force-pushed the feat/js-generate-package-json-executor branch 2 times, most recently from 92a7403 to cf9f7f1 Compare April 17, 2023 13:46
@jensbodal
Copy link
Contributor Author

Updated everything to the new @nx scope where needed

@SmoshySmosh
Copy link
Contributor

Looking forward to using this executor.

@jensbodal jensbodal force-pushed the feat/js-generate-package-json-executor branch from c171f34 to 32cae5c Compare May 3, 2023 00:19
@jensbodal
Copy link
Contributor Author

rebased with master

@StringKe
Copy link

@jensbodal Is there any way I can temporarily use this PR for testing?

* generates a package.json based on the project's dependencies in node_modules
* moves getExtraDependencies helper from esbuild package to js package
@jensbodal
Copy link
Contributor Author

@jensbodal Is there any way I can temporarily use this PR for testing?

You're welcome to if you want. I just rebased with master again.

As for how the best way to do that I'm not sure since I think part of the release process creates the proper packages from the monorepo. I'm guessing you could install my fork locally then point your local install to it via a file alias.

@meeroslav
Copy link
Contributor

Hi @jensbodal, thank you for this PR. Unfortunately, this is not something we want to implement in nx.

The @nx/js executors already have flag --generatePackageJson for generating package json and lock file based on the dependencies and we are currently cleaning this up

@meeroslav meeroslav closed this Jun 20, 2023
@SmoshySmosh
Copy link
Contributor

Hi @jensbodal, thank you for this PR. Unfortunately, this is not something we want to implement in nx.

The @nx/js executors already have flag --generatePackageJson for generating package json and lock file based on the dependencies and we are currently cleaning this up

@meeroslav I must be misunderstanding here. How does the @nx/js executer help create a package.json for the other build executers? They represent two completely different build systems with two different purposes.

Is it possible that you are saying that the @nx/js executer can be used to only create the package.json file? If so, can you please provide an example so I can start using it?

@jensbodal jensbodal deleted the feat/js-generate-package-json-executor branch June 21, 2023 05:31
@github-actions
Copy link

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 27, 2023
@meeroslav
Copy link
Contributor

Sorry @SmoshySmosh, your message got somehow lost.

The package json creation logic from @nx/js is used under the hood in other executors.

You can see how to use it here: https://nx.dev/recipes/ci/ci-deployment

For libraries, we are now deprecating this functionality and suggest that you use the new linter rule - https://nx.dev/packages/eslint-plugin/documents/dependency-checks

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants