nx
nx copied to clipboard
feat(js): standalone executor for generating package.json
- 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
- Decomposing existing implementations to use a common method
- Other executors to more easily add the ability to include this option in their schema
- 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"
}
}
}
}
}
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 |
☁️ Nx Cloud Report
CI is running/has finished running commands for commit 633d66cad1282576b7d17d52768f6140f9daacaa. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.
📂 See all runs for this branch
✅ Successfully ran 8 targets
nx affected -t e2e-macos --parallel=1 --base=2d47f1bdbee607718be8ceac2471624bffeb23dc --head=633d66cad1282576b7d17d52768f6140f9daacaanx affected --target=e2e --base=2d47f1bdbee607718be8ceac2471624bffeb23dc --head=633d66cad1282576b7d17d52768f6140f9daacaa --parallel=1nx affected --target=test --base=2d47f1bdbee607718be8ceac2471624bffeb23dc --head=633d66cad1282576b7d17d52768f6140f9daacaa --parallel=1nx affected --target=build --base=2d47f1bdbee607718be8ceac2471624bffeb23dc --head=633d66cad1282576b7d17d52768f6140f9daacaa --parallel=3nx run-many -t check-imports check-commit check-lock-files depcheck check-codeowners documentation --parallel=1 --no-dtenx affected --target=lint --base=2d47f1bdbee607718be8ceac2471624bffeb23dc --head=633d66cad1282576b7d17d52768f6140f9daacaa --parallel=3nx-cloud record -- nx format:check --base=2d47f1bdbee607718be8ceac2471624bffeb23dc --head=633d66cad1282576b7d17d52768f6140f9daacaanx documentation --no-dte
Sent with 💌 from NxCloud.
Updated everything to the new @nx scope where needed
Looking forward to using this executor.
rebased with master
@jensbodal Is there any way I can temporarily use this PR for testing?
@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.
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
Hi @jensbodal, thank you for this PR. Unfortunately, this is not something we want to implement in nx.
The
@nx/jsexecutors already have flag--generatePackageJsonfor 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?
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.
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