nx icon indicating copy to clipboard operation
nx copied to clipboard

feat(js): standalone executor for generating package.json

Open jensbodal opened this issue 2 years ago • 7 comments

  • 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"
        }
      }
    }
  }
}

jensbodal avatar Apr 16 '23 17:04 jensbodal

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

vercel[bot] avatar Apr 16 '23 17:04 vercel[bot]

Updated everything to the new @nx scope where needed

jensbodal avatar Apr 17 '23 14:04 jensbodal

Looking forward to using this executor.

SmoshySmosh avatar Apr 22 '23 05:04 SmoshySmosh

rebased with master

jensbodal avatar May 03 '23 00:05 jensbodal

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

StringKe avatar May 25 '23 09:05 StringKe

@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.

jensbodal avatar May 26 '23 04:05 jensbodal

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 avatar Jun 20 '23 21:06 meeroslav

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?

SmoshySmosh avatar Jun 20 '23 23:06 SmoshySmosh

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[bot] avatar Jun 27 '23 00:06 github-actions[bot]

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

meeroslav avatar Aug 08 '23 09:08 meeroslav