feat(js): remove options to update package.json dependencies and peerDependencies (#19543)
This commit is contained in:
parent
14643b68b5
commit
76a7506074
@ -36,19 +36,6 @@
|
||||
"description": "Whether to run a build when any file changes.",
|
||||
"default": false
|
||||
},
|
||||
"updateBuildableProjectDepsInPackageJson": {
|
||||
"type": "boolean",
|
||||
"description": "Whether to update the buildable project dependencies in the build output package.json.",
|
||||
"default": false,
|
||||
"x-deprecated": "Configure the project to use the '@nx/dependency-checks' ESLint rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks). It will be removed in v17."
|
||||
},
|
||||
"buildableProjectDepsInPackageJsonType": {
|
||||
"type": "string",
|
||||
"description": "When `updateBuildableProjectDepsInPackageJson` is `true`, this adds dependencies to either `peerDependencies` or `dependencies`.",
|
||||
"enum": ["dependencies", "peerDependencies"],
|
||||
"default": "peerDependencies",
|
||||
"x-deprecated": "Configure the '@nx/dependency-checks' ESLint rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks). It will be removed in v17."
|
||||
},
|
||||
"tailwindConfig": {
|
||||
"type": "string",
|
||||
"description": "The full path for the Tailwind configuration file, relative to the workspace root. If not provided and a `tailwind.config.js` file exists in the project or workspace root, it will be used. Otherwise, Tailwind will not be configured."
|
||||
|
||||
@ -41,22 +41,6 @@
|
||||
"description": "Whether to run a build when any file changes.",
|
||||
"default": false
|
||||
},
|
||||
"updateBuildableProjectDepsInPackageJson": {
|
||||
"type": "boolean",
|
||||
"description": "Whether to update the buildable project dependencies in the build output package.json.",
|
||||
"default": false,
|
||||
"x-deprecated": "Configure the project to use the '@nx/dependency-checks' ESLint rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks). It will be removed in v17."
|
||||
},
|
||||
"buildableProjectDepsInPackageJsonType": {
|
||||
"type": "string",
|
||||
"description": "When `updateBuildableProjectDepsInPackageJson` is `true`, this adds dependencies to either `peerDependencies` or `dependencies`.",
|
||||
"enum": [
|
||||
"dependencies",
|
||||
"peerDependencies"
|
||||
],
|
||||
"default": "peerDependencies",
|
||||
"x-deprecated": "Configure the project to use the '@nx/dependency-checks' ESLint rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks). It will be removed in v17."
|
||||
},
|
||||
"tailwindConfig": {
|
||||
"type": "string",
|
||||
"description": "The full path for the Tailwind configuration file, relative to the workspace root. If not provided and a `tailwind.config.js` file exists in the project or workspace root, it will be used. Otherwise, Tailwind will not be configured.",
|
||||
|
||||
@ -111,19 +111,6 @@
|
||||
],
|
||||
"hidden": true
|
||||
},
|
||||
"updateBuildableProjectDepsInPackageJson": {
|
||||
"type": "boolean",
|
||||
"description": "Whether to update the buildable project dependencies in the build output package.json.",
|
||||
"default": false,
|
||||
"x-deprecated": "Configure the project to use the '@nx/dependency-checks' ESLint rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks). It will be removed in v17."
|
||||
},
|
||||
"buildableProjectDepsInPackageJsonType": {
|
||||
"type": "string",
|
||||
"description": "When `updateBuildableProjectDepsInPackageJson` is `true`, this adds dependencies to either `peerDependencies` or `dependencies`.",
|
||||
"enum": ["dependencies", "peerDependencies"],
|
||||
"default": "peerDependencies",
|
||||
"x-deprecated": "Configure the project to use the '@nx/dependency-checks' ESLint rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks). It will be removed in v17."
|
||||
},
|
||||
"external": {
|
||||
"description": "A list projects to be treated as external. This feature is experimental",
|
||||
"oneOf": [
|
||||
|
||||
@ -111,19 +111,6 @@
|
||||
},
|
||||
"x-priority": "important"
|
||||
},
|
||||
"updateBuildableProjectDepsInPackageJson": {
|
||||
"type": "boolean",
|
||||
"description": "Whether to update the buildable project dependencies in the build output package.json.",
|
||||
"default": false,
|
||||
"x-deprecated": "Configure the project to use the '@nx/dependency-checks' ESLint rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks). It will be removed in v17."
|
||||
},
|
||||
"buildableProjectDepsInPackageJsonType": {
|
||||
"type": "string",
|
||||
"description": "When `updateBuildableProjectDepsInPackageJson` is `true`, this adds dependencies to either `peerDependencies` or `dependencies`.",
|
||||
"enum": ["dependencies", "peerDependencies"],
|
||||
"default": "peerDependencies",
|
||||
"x-deprecated": "Configure the project to use the '@nx/dependency-checks' ESLint rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks). It will be removed in v17."
|
||||
},
|
||||
"external": {
|
||||
"description": "A list projects to be treated as external. This feature is experimental",
|
||||
"oneOf": [
|
||||
|
||||
@ -68,19 +68,6 @@
|
||||
"description": "Enable re-building when files change.",
|
||||
"default": false
|
||||
},
|
||||
"updateBuildableProjectDepsInPackageJson": {
|
||||
"type": "boolean",
|
||||
"description": "Update buildable project dependencies in `package.json`.",
|
||||
"default": false,
|
||||
"x-deprecated": "Configure the project to use the '@nx/dependency-checks' ESLint rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks). It will be removed in v17."
|
||||
},
|
||||
"buildableProjectDepsInPackageJsonType": {
|
||||
"type": "string",
|
||||
"description": "When `updateBuildableProjectDepsInPackageJson` is `true`, this adds dependencies to either `peerDependencies` or `dependencies`.",
|
||||
"enum": ["dependencies", "peerDependencies"],
|
||||
"default": "peerDependencies",
|
||||
"x-deprecated": "Configure the project to use the '@nx/dependency-checks' ESLint rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks). It will be removed in v17."
|
||||
},
|
||||
"rollupConfig": {
|
||||
"oneOf": [
|
||||
{
|
||||
@ -200,7 +187,7 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"examplesFile": "{% tabs %}\n{% tab label=\"Including Dependencies\" %}\nTo include dependencies in the output `package.json`, the dependencies must be installed as a **dependencies** in the root `package.json`\n\n```json {% fileName=\"package.json\" %}\n{\n \"dependencies\": {\n \"some-dependency\": \"^1.0.0\"\n }\n}\n```\n\nTo have dependencies in the be listed in the final `package.json` of your project, set the `updateBuildableProjectDepsInPackageJson` option to `true`. After than dependencies will be added to the `peerDependencies` field of the output `package.json`. You can use `buildableProjectDepsInPackageJsonType` option to change which field the dependencies are output to.\n\n```json {% fileName=\"project.json\" %}\n{\n \"targets\": {\n \"build\": {\n \"executor\": \"@nx/rollup:rollup\",\n \"options\": {\n \"buildableProjectDepsInPackageJsonType\": \"dependencies\",\n \"updateBuildableProjectDepsInPackageJson\": true\n }\n }\n }\n}\n```\n\n{% /tab %}\n\n{% tab label=\"Using `babelUpwardRootMode`\" %}\n\nCopying from the [Babel documentation](https://babeljs.io/docs/config-files#root-babelconfigjson-file):\n\n> [...] if you are running your Babel compilation process from within a subpackage, you need to tell Babel where to look for the config. There are a few ways to do that, but the recommended way is the \"rootMode\" option with \"upward\", which will make Babel search from the working directory upward looking for your babel.config.json file, and will use its location as the \"root\" value.\n\nSetting `babelUpwardRootMode` to `true` in your `project.json` will set `rootMode` option to `upward` in the Babel config. You may want the `upward` mode in a monorepo when projects must apply their individual `.babelrc` file. We recommend that you don't set it at all, so it will use the default to `false` as the `upward` mode brings additional complexity to the build process.\n\n```json\n//...\n\"my-app\": {\n \"targets\": {\n \"build\": {\n \"executor\": \"@nx/rollup:rollup\",\n \"options\": {\n \"babelUpwardRootMode\": true,\n //...\n },\n //...\n },\n //...\n },\n //...\n}\n```\n\nWhen `babelUpwardRootMode` is `true`, Babel will look for a root `babel.config.json` at the root of the workspace, which should look something like this to include all packages:\n\n```json\n{ \"babelrcRoots\": [\"*\"] }\n```\n\nThen for each package, you must have a `.babelrc` file that will be applied to that package. For example:\n\n```json\n{\n \"presets\": [\"@babel/preset-env\", \"@babel/preset-typescript\"]\n}\n```\n\nAll packages will use its own `.babelrc` file, thus you must ensure the right presets and plugins are set in each config file. This behavior can lead to build discrepancies between packages, so we recommend that you don't set `babelUpwardRootMode` at all.\n\n```treeview\n├── packages\n│ ├── a\n│ │ └── .babelrc\n│ └── b\n│ └── .babelrc\n└── babel.config.json\n```\n\nIn workspace above, if `a` imports `b`, it will apply the config `packages/b/.babelrc` and not apply its own `packages/a/.babelrc` to `b`. Anything in `babel.config.json` will apply to all packages.\n\n{% /tab %}\n\n{% /tabs %}\n",
|
||||
"examplesFile": "{% tabs %}\n{% tab label=\"Including Dependencies\" %}\nTo include dependencies in the output `package.json`, the dependencies must be installed as a **dependencies** in the root `package.json`\n\n```json {% fileName=\"package.json\" %}\n{\n \"dependencies\": {\n \"some-dependency\": \"^1.0.0\"\n }\n}\n```\n\n{% /tab %}\n\n{% tab label=\"Using `babelUpwardRootMode`\" %}\n\nCopying from the [Babel documentation](https://babeljs.io/docs/config-files#root-babelconfigjson-file):\n\n> [...] if you are running your Babel compilation process from within a subpackage, you need to tell Babel where to look for the config. There are a few ways to do that, but the recommended way is the \"rootMode\" option with \"upward\", which will make Babel search from the working directory upward looking for your babel.config.json file, and will use its location as the \"root\" value.\n\nSetting `babelUpwardRootMode` to `true` in your `project.json` will set `rootMode` option to `upward` in the Babel config. You may want the `upward` mode in a monorepo when projects must apply their individual `.babelrc` file. We recommend that you don't set it at all, so it will use the default to `false` as the `upward` mode brings additional complexity to the build process.\n\n```json\n//...\n\"my-app\": {\n \"targets\": {\n \"build\": {\n \"executor\": \"@nx/rollup:rollup\",\n \"options\": {\n \"babelUpwardRootMode\": true,\n //...\n },\n //...\n },\n //...\n },\n //...\n}\n```\n\nWhen `babelUpwardRootMode` is `true`, Babel will look for a root `babel.config.json` at the root of the workspace, which should look something like this to include all packages:\n\n```json\n{ \"babelrcRoots\": [\"*\"] }\n```\n\nThen for each package, you must have a `.babelrc` file that will be applied to that package. For example:\n\n```json\n{\n \"presets\": [\"@babel/preset-env\", \"@babel/preset-typescript\"]\n}\n```\n\nAll packages will use its own `.babelrc` file, thus you must ensure the right presets and plugins are set in each config file. This behavior can lead to build discrepancies between packages, so we recommend that you don't set `babelUpwardRootMode` at all.\n\n```treeview\n├── packages\n│ ├── a\n│ │ └── .babelrc\n│ └── b\n│ └── .babelrc\n└── babel.config.json\n```\n\nIn workspace above, if `a` imports `b`, it will apply the config `packages/b/.babelrc` and not apply its own `packages/a/.babelrc` to `b`. Anything in `babel.config.json` will apply to all packages.\n\n{% /tab %}\n\n{% /tabs %}\n",
|
||||
"presets": []
|
||||
},
|
||||
"description": "Bundle a package using Rollup.",
|
||||
|
||||
@ -439,7 +439,6 @@
|
||||
"outputPath": "build/packages/create-nx-workspace",
|
||||
"tsConfig": "packages/create-nx-workspace/tsconfig.lib.json",
|
||||
"main": "packages/create-nx-workspace/bin/create-nx-workspace.ts",
|
||||
"updateBuildableProjectDepsInPackageJson": false,
|
||||
"assets": [
|
||||
{
|
||||
"input": "packages/create-nx-workspace",
|
||||
@ -800,7 +799,6 @@
|
||||
"outputPath": "build/packages/create-nx-plugin",
|
||||
"tsConfig": "packages/create-nx-plugin/tsconfig.lib.json",
|
||||
"main": "packages/create-nx-plugin/bin/create-nx-plugin.ts",
|
||||
"updateBuildableProjectDepsInPackageJson": false,
|
||||
"assets": [
|
||||
{
|
||||
"input": "packages/create-nx-plugin",
|
||||
@ -1072,7 +1070,6 @@
|
||||
"outputPath": "build/packages/eslint-plugin-nx",
|
||||
"tsConfig": "packages/eslint-plugin-nx/tsconfig.lib.json",
|
||||
"main": "packages/eslint-plugin-nx/src/index.ts",
|
||||
"updateBuildableProjectDepsInPackageJson": false,
|
||||
"assets": [
|
||||
{
|
||||
"input": "packages/eslint-plugin-nx",
|
||||
@ -3020,7 +3017,6 @@
|
||||
"outputPath": "build/packages/react-native",
|
||||
"tsConfig": "packages/react-native/tsconfig.lib.json",
|
||||
"main": "packages/react-native/index.ts",
|
||||
"updateBuildableProjectDepsInPackageJson": false,
|
||||
"assets": [
|
||||
"packages/react-native/*.md",
|
||||
{
|
||||
@ -3946,7 +3942,6 @@
|
||||
"outputPath": "build/packages/nx-plugin",
|
||||
"tsConfig": "packages/nx-plugin/tsconfig.lib.json",
|
||||
"main": "packages/nx-plugin/index.ts",
|
||||
"updateBuildableProjectDepsInPackageJson": false,
|
||||
"assets": [
|
||||
{
|
||||
"input": "packages/nx-plugin",
|
||||
@ -4525,7 +4520,6 @@
|
||||
"outputPath": "build/packages/storybook",
|
||||
"tsConfig": "packages/storybook/tsconfig.lib.json",
|
||||
"main": "packages/storybook/index.ts",
|
||||
"updateBuildableProjectDepsInPackageJson": false,
|
||||
"assets": [
|
||||
{
|
||||
"input": "packages/storybook",
|
||||
@ -5936,7 +5930,6 @@
|
||||
"tsConfig": "packages/workspace/tsconfig.lib.json",
|
||||
"packageJson": "packages/workspace/package.json",
|
||||
"main": "packages/workspace/index.ts",
|
||||
"updateBuildableProjectDepsInPackageJson": false,
|
||||
"assets": [
|
||||
{
|
||||
"input": "packages/workspace",
|
||||
@ -10422,7 +10415,6 @@
|
||||
"outputPath": "build/packages/angular",
|
||||
"tsConfig": "packages/angular/tsconfig.lib.json",
|
||||
"main": "packages/angular/index.ts",
|
||||
"updateBuildableProjectDepsInPackageJson": false,
|
||||
"assets": [
|
||||
{
|
||||
"input": "packages/angular",
|
||||
@ -10968,7 +10960,6 @@
|
||||
"outputPath": "build/packages/cypress",
|
||||
"tsConfig": "packages/cypress/tsconfig.lib.json",
|
||||
"main": "packages/cypress/index.ts",
|
||||
"updateBuildableProjectDepsInPackageJson": false,
|
||||
"assets": [
|
||||
{
|
||||
"input": "packages/cypress",
|
||||
@ -11243,7 +11234,6 @@
|
||||
"outputPath": "build/packages/esbuild",
|
||||
"tsConfig": "packages/esbuild/tsconfig.lib.json",
|
||||
"main": "packages/esbuild/index.ts",
|
||||
"updateBuildableProjectDepsInPackageJson": false,
|
||||
"assets": [
|
||||
{
|
||||
"input": "packages/esbuild",
|
||||
@ -11444,7 +11434,6 @@
|
||||
"outputPath": "build/packages/express",
|
||||
"tsConfig": "packages/express/tsconfig.lib.json",
|
||||
"main": "packages/express/index.ts",
|
||||
"updateBuildableProjectDepsInPackageJson": false,
|
||||
"assets": [
|
||||
{
|
||||
"input": "packages/express",
|
||||
@ -11980,7 +11969,6 @@
|
||||
"outputPath": "build/packages/webpack",
|
||||
"tsConfig": "packages/webpack/tsconfig.lib.json",
|
||||
"main": "packages/webpack/index.ts",
|
||||
"updateBuildableProjectDepsInPackageJson": false,
|
||||
"assets": [
|
||||
{
|
||||
"input": "packages/webpack",
|
||||
@ -12513,7 +12501,6 @@
|
||||
"outputPath": "build/packages/devkit",
|
||||
"tsConfig": "packages/devkit/tsconfig.lib.json",
|
||||
"main": "packages/devkit/index.ts",
|
||||
"updateBuildableProjectDepsInPackageJson": false,
|
||||
"assets": [
|
||||
{
|
||||
"input": "packages/devkit",
|
||||
@ -12922,7 +12909,6 @@
|
||||
"outputPath": "build/packages/linter",
|
||||
"tsConfig": "packages/linter/tsconfig.lib.json",
|
||||
"main": "packages/linter/index.ts",
|
||||
"updateBuildableProjectDepsInPackageJson": false,
|
||||
"assets": [
|
||||
{
|
||||
"input": "packages/linter",
|
||||
@ -13246,7 +13232,6 @@
|
||||
"outputPath": "build/packages/rollup",
|
||||
"tsConfig": "packages/rollup/tsconfig.lib.json",
|
||||
"main": "packages/rollup/index.ts",
|
||||
"updateBuildableProjectDepsInPackageJson": false,
|
||||
"assets": [
|
||||
{
|
||||
"input": "packages/rollup",
|
||||
@ -14048,7 +14033,6 @@
|
||||
"outputPath": "build/packages/detox",
|
||||
"tsConfig": "packages/detox/tsconfig.lib.json",
|
||||
"main": "packages/detox/index.ts",
|
||||
"updateBuildableProjectDepsInPackageJson": false,
|
||||
"assets": [
|
||||
{
|
||||
"input": "packages/detox",
|
||||
@ -15326,7 +15310,6 @@
|
||||
"outputPath": "build/packages/react",
|
||||
"tsConfig": "packages/react/tsconfig.lib.json",
|
||||
"main": "packages/react/index.ts",
|
||||
"updateBuildableProjectDepsInPackageJson": false,
|
||||
"assets": [
|
||||
{
|
||||
"input": "packages/react",
|
||||
@ -17268,7 +17251,6 @@
|
||||
"tsConfig": "packages/expo/tsconfig.lib.json",
|
||||
"packageJson": "packages/expo/package.json",
|
||||
"main": "packages/expo/index.ts",
|
||||
"updateBuildableProjectDepsInPackageJson": false,
|
||||
"assets": [
|
||||
"packages/expo/*.md",
|
||||
{
|
||||
@ -17756,7 +17738,6 @@
|
||||
"outputPath": "build/packages/jest",
|
||||
"tsConfig": "packages/jest/tsconfig.lib.json",
|
||||
"main": "packages/jest/index.ts",
|
||||
"updateBuildableProjectDepsInPackageJson": false,
|
||||
"assets": [
|
||||
{
|
||||
"input": "packages/jest",
|
||||
@ -18339,7 +18320,6 @@
|
||||
"outputPath": "build/packages/nest",
|
||||
"tsConfig": "packages/nest/tsconfig.lib.json",
|
||||
"main": "packages/nest/index.ts",
|
||||
"updateBuildableProjectDepsInPackageJson": false,
|
||||
"assets": [
|
||||
{
|
||||
"input": "packages/nest",
|
||||
@ -19029,7 +19009,6 @@
|
||||
"outputPath": "build/packages/next",
|
||||
"tsConfig": "packages/next/tsconfig.lib.json",
|
||||
"main": "packages/next/index.ts",
|
||||
"updateBuildableProjectDepsInPackageJson": false,
|
||||
"assets": [
|
||||
{
|
||||
"input": "packages/next",
|
||||
@ -19399,7 +19378,6 @@
|
||||
"outputPath": "build/packages/node",
|
||||
"tsConfig": "packages/node/tsconfig.lib.json",
|
||||
"main": "packages/node/index.ts",
|
||||
"updateBuildableProjectDepsInPackageJson": false,
|
||||
"assets": [
|
||||
{
|
||||
"input": "packages/node",
|
||||
@ -19773,7 +19751,6 @@
|
||||
"outputPath": "build/packages/vite",
|
||||
"tsConfig": "packages/vite/tsconfig.lib.json",
|
||||
"main": "packages/vite/index.ts",
|
||||
"updateBuildableProjectDepsInPackageJson": false,
|
||||
"assets": [
|
||||
{
|
||||
"input": "packages/vite",
|
||||
@ -20740,7 +20717,6 @@
|
||||
"outputPath": "build/packages/cli",
|
||||
"tsConfig": "packages/cli/tsconfig.lib.json",
|
||||
"main": "packages/cli/bin/nx.ts",
|
||||
"updateBuildableProjectDepsInPackageJson": false,
|
||||
"assets": [
|
||||
{
|
||||
"input": "packages/cli",
|
||||
@ -20931,7 +20907,6 @@
|
||||
"outputPath": "build/packages/tao",
|
||||
"tsConfig": "packages/tao/tsconfig.lib.json",
|
||||
"main": "packages/tao/index.ts",
|
||||
"updateBuildableProjectDepsInPackageJson": false,
|
||||
"assets": [
|
||||
{
|
||||
"input": "packages/tao",
|
||||
@ -21470,7 +21445,6 @@
|
||||
"outputPath": "build/packages/web",
|
||||
"tsConfig": "packages/web/tsconfig.lib.json",
|
||||
"main": "packages/web/index.ts",
|
||||
"updateBuildableProjectDepsInPackageJson": false,
|
||||
"assets": [
|
||||
{
|
||||
"input": "packages/web",
|
||||
@ -22426,7 +22400,6 @@
|
||||
"outputPath": "build/packages/js",
|
||||
"tsConfig": "packages/js/tsconfig.lib.json",
|
||||
"main": "packages/js/src/index.ts",
|
||||
"updateBuildableProjectDepsInPackageJson": false,
|
||||
"assets": [
|
||||
{
|
||||
"input": "packages/js",
|
||||
@ -23825,7 +23798,6 @@
|
||||
"tsConfig": "packages/nx/tsconfig.lib.json",
|
||||
"packageJson": "packages/nx/package.json",
|
||||
"main": "packages/nx/bin/nx.ts",
|
||||
"updateBuildableProjectDepsInPackageJson": false,
|
||||
"assets": [
|
||||
{
|
||||
"input": "packages/nx",
|
||||
|
||||
@ -17,7 +17,7 @@ One typical scenario for this may be that you use Nx to develop your organizatio
|
||||
|
||||
A normal Nx library - let’s call it "workspace library" - is not made for building or publishing. Rather it only includes common lint and test targets in its `project.json` file. These libraries are directly referenced from one of the monorepo’s applications and built together with them.
|
||||
|
||||
Keep in mind that the `--publishable` flag does not enable automatic publishing. Rather it adds to your Nx workspace library a builder target that **compiles** and **bundles** your app. The resulting artifact will be ready to be published to some registry (e.g. [npm](https://npmjs.com/)). By having that builder, you can invoke the build via a command like: `nx build mylib` (where "mylib" is the name of the lib) which will then produce an optimized bundle in the `dist/mylib` folder. Nx [also analyzes](/nx-api/angular/executors/package#updatebuildableprojectdepsinpackagejson) the library’s dependencies and automatically compiles the dependencies in the resulting `package.json` file.
|
||||
Keep in mind that the `--publishable` flag does not enable automatic publishing. Rather it adds to your Nx workspace library a builder target that **compiles** and **bundles** your app. The resulting artifact will be ready to be published to some registry (e.g. [npm](https://npmjs.com/)). By having that builder, you can invoke the build via a command like: `nx build mylib` (where "mylib" is the name of the lib) which will then produce an optimized bundle in the `dist/mylib` folder.
|
||||
|
||||
One particularity when generating a library with `--publishable` is that it requires you to also provide an `--importPath`. Your import path is the actual scope of your distributable package (e.g.: `@myorg/mylib`) - which needs to be a [valid npm package name](https://docs.npmjs.com/files/package.json#name).
|
||||
|
||||
|
||||
@ -156,13 +156,6 @@ describe('EsBuild Plugin', () => {
|
||||
// Bundle only child lib
|
||||
runCLI(`build ${parentLib} --third-party=false`);
|
||||
|
||||
expect(
|
||||
readJson(`dist/libs/${parentLib}/package.json`).dependencies
|
||||
).toEqual({
|
||||
// Don't care about the versions, just that they exist
|
||||
rambda: expect.any(String),
|
||||
lodash: expect.any(String),
|
||||
});
|
||||
runResult = runCommand(`node dist/libs/${parentLib}/index.cjs`);
|
||||
expect(runResult).toMatch(/Hello world/);
|
||||
expect(runResult).toMatch(/Hello from child lib/);
|
||||
|
||||
@ -46,38 +46,6 @@ describe('js:swc executor', () => {
|
||||
expect(tsconfig.compilerOptions.paths).toEqual({
|
||||
[`@${scope}/${lib}`]: [`libs/${lib}/src/index.ts`],
|
||||
});
|
||||
|
||||
// Legacy behavior (updateBuildableProjectDepsInPackageJson): add @swc/helpers if externalHelpers is true
|
||||
// TODO(v17): Remove this test
|
||||
updateJson(`libs/${lib}/package.json`, (json) => {
|
||||
delete json.dependencies['@swc/helpers'];
|
||||
return json;
|
||||
});
|
||||
runCLI(
|
||||
`build ${lib} --generateLockfile=true --updateBuildableProjectDepsInPackageJson`
|
||||
);
|
||||
checkFilesExist(
|
||||
`dist/libs/${lib}/package.json`,
|
||||
`dist/libs/${lib}/${
|
||||
packageManagerLockFile[detectPackageManager(tmpProjPath())]
|
||||
}`
|
||||
);
|
||||
expect(readJson(`dist/libs/${lib}/package.json`)).toHaveProperty(
|
||||
'peerDependencies.@swc/helpers'
|
||||
);
|
||||
|
||||
// Legacy behavior (updateBuildableProjectDepsInPackageJson): don't add @swc/helpers if externalHelpers is false
|
||||
// TODO(v17): Remove this test
|
||||
updateJson(`libs/${lib}/.swcrc`, (json) => {
|
||||
json.jsc.externalHelpers = false;
|
||||
return json;
|
||||
});
|
||||
|
||||
runCLI(`build ${lib}`);
|
||||
|
||||
expect(readJson(`dist/libs/${lib}/package.json`)).not.toHaveProperty(
|
||||
'peerDependencies.@swc/helpers'
|
||||
);
|
||||
}, 240_000);
|
||||
|
||||
it('should handle swcrc path mappings', async () => {
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import { satisfies } from 'semver';
|
||||
import {
|
||||
checkFilesDoNotExist,
|
||||
checkFilesExist,
|
||||
@ -151,23 +150,6 @@ describe('js:tsc executor', () => {
|
||||
return json;
|
||||
});
|
||||
|
||||
runCLI(`build ${lib} --updateBuildableProjectDepsInPackageJson`);
|
||||
|
||||
expect(readJson(`dist/libs/${lib}/package.json`)).toHaveProperty(
|
||||
'peerDependencies.tslib'
|
||||
);
|
||||
|
||||
updateJson(`libs/${lib}/tsconfig.json`, (json) => {
|
||||
json.compilerOptions = { ...json.compilerOptions, importHelpers: false };
|
||||
return json;
|
||||
});
|
||||
|
||||
runCLI(`build ${lib}`);
|
||||
|
||||
expect(readJson(`dist/libs/${lib}/package.json`)).not.toHaveProperty(
|
||||
'peerDependencies.tslib'
|
||||
);
|
||||
|
||||
// check batch build
|
||||
rmDist();
|
||||
const batchBuildOutput = runCLI(`build ${parentLib} --skip-nx-cache`, {
|
||||
@ -295,22 +277,5 @@ export function ${lib}Wildcard() {
|
||||
${content};
|
||||
`;
|
||||
});
|
||||
|
||||
updateJson(`libs/${lib}/package.json`, (json) => {
|
||||
// Delete automatically generated helper dependency to test legacy behavior.
|
||||
delete json.dependencies.tslib;
|
||||
return json;
|
||||
});
|
||||
|
||||
runCLI(`build ${lib} --updateBuildableProjectDepsInPackageJson`);
|
||||
|
||||
// Check that only 'react' exists, don't care about version
|
||||
expect(readJson(`dist/libs/${lib}/package.json`).dependencies).toEqual({
|
||||
react: expect.any(String),
|
||||
});
|
||||
expect(readJson(`dist/libs/${lib}/package.json`).peerDependencies).toEqual({
|
||||
tslib: expect.any(String),
|
||||
});
|
||||
checkFilesDoNotExist(`dist/libs/${lib}/${packageManagerLockFile['npm']}`);
|
||||
}, 240_000);
|
||||
});
|
||||
|
||||
@ -127,22 +127,7 @@ describe('Build React libraries and apps', () => {
|
||||
checkFilesExist(`dist/libs/${childLib2}/README.md`);
|
||||
|
||||
/*
|
||||
* 2. With dependencies
|
||||
*/
|
||||
runCLI(`build ${parentLib} --updateBuildableProjectDepsInPackageJson`);
|
||||
|
||||
checkFilesExist(`dist/libs/${parentLib}/index.esm.js`);
|
||||
|
||||
const jsonFile = readJson(`dist/libs/${parentLib}/package.json`);
|
||||
expect(jsonFile.peerDependencies).toEqual(
|
||||
expect.objectContaining({
|
||||
[`@${proj}/${childLib}`]: '0.0.1',
|
||||
[`@${proj}/${childLib2}`]: '0.0.1',
|
||||
})
|
||||
);
|
||||
|
||||
/*
|
||||
* 3. With dependencies without existing dist
|
||||
* 2. With dependencies without existing dist
|
||||
*/
|
||||
rmDist();
|
||||
|
||||
|
||||
3
nx.json
3
nx.json
@ -98,8 +98,7 @@
|
||||
"options": {
|
||||
"outputPath": "build/{projectRoot}",
|
||||
"tsConfig": "{projectRoot}/tsconfig.lib.json",
|
||||
"main": "{projectRoot}/index.ts",
|
||||
"updateBuildableProjectDepsInPackageJson": false
|
||||
"main": "{projectRoot}/index.ts"
|
||||
},
|
||||
"outputs": ["{options.outputPath}"]
|
||||
},
|
||||
|
||||
@ -33,19 +33,6 @@
|
||||
"description": "Whether to run a build when any file changes.",
|
||||
"default": false
|
||||
},
|
||||
"updateBuildableProjectDepsInPackageJson": {
|
||||
"type": "boolean",
|
||||
"description": "Whether to update the buildable project dependencies in the build output package.json.",
|
||||
"default": false,
|
||||
"x-deprecated": "Configure the project to use the '@nx/dependency-checks' ESLint rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks). It will be removed in v17."
|
||||
},
|
||||
"buildableProjectDepsInPackageJsonType": {
|
||||
"type": "string",
|
||||
"description": "When `updateBuildableProjectDepsInPackageJson` is `true`, this adds dependencies to either `peerDependencies` or `dependencies`.",
|
||||
"enum": ["dependencies", "peerDependencies"],
|
||||
"default": "peerDependencies",
|
||||
"x-deprecated": "Configure the '@nx/dependency-checks' ESLint rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks). It will be removed in v17."
|
||||
},
|
||||
"tailwindConfig": {
|
||||
"type": "string",
|
||||
"description": "The full path for the Tailwind configuration file, relative to the workspace root. If not provided and a `tailwind.config.js` file exists in the project or workspace root, it will be used. Otherwise, Tailwind will not be configured."
|
||||
|
||||
@ -5,7 +5,6 @@ import {
|
||||
checkDependentProjectsHaveBeenBuilt,
|
||||
createTmpTsConfig,
|
||||
DependentBuildableProjectNode,
|
||||
updateBuildableProjectPackageJsonDependencies,
|
||||
} from '@nx/js/src/utils/buildable-libs-utils';
|
||||
import type { NgPackagr } from 'ng-packagr';
|
||||
import { resolve } from 'path';
|
||||
@ -91,28 +90,10 @@ export function createLibraryExecutor(
|
||||
return Promise.resolve({ success: false });
|
||||
}
|
||||
|
||||
function updatePackageJson(): void {
|
||||
if (
|
||||
topLevelDependencies.length > 0 &&
|
||||
options.updateBuildableProjectDepsInPackageJson
|
||||
) {
|
||||
updateBuildableProjectPackageJsonDependencies(
|
||||
context.root,
|
||||
context.projectName,
|
||||
context.targetName,
|
||||
context.configurationName,
|
||||
target,
|
||||
topLevelDependencies,
|
||||
options.buildableProjectDepsInPackageJsonType
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (options.watch) {
|
||||
return yield* eachValueFrom(
|
||||
from(initializeNgPackagr(options, context, dependencies)).pipe(
|
||||
switchMap((packagr) => packagr.watch()),
|
||||
tap(() => updatePackageJson()),
|
||||
mapTo({ success: true })
|
||||
)
|
||||
);
|
||||
@ -121,7 +102,6 @@ export function createLibraryExecutor(
|
||||
return from(initializeNgPackagr(options, context, dependencies))
|
||||
.pipe(
|
||||
switchMap((packagr) => packagr.build()),
|
||||
tap(() => updatePackageJson()),
|
||||
mapTo({ success: true })
|
||||
)
|
||||
.toPromise();
|
||||
|
||||
@ -1,18 +1,6 @@
|
||||
export interface BuildAngularLibraryExecutorOptions {
|
||||
project: string;
|
||||
/**
|
||||
* @deprecated Configure the project to use the `@nx/dependency-checks` ESLint
|
||||
* rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks).
|
||||
* It will be removed in v17.
|
||||
*/
|
||||
buildableProjectDepsInPackageJsonType?: 'dependencies' | 'peerDependencies';
|
||||
tailwindConfig?: string;
|
||||
tsConfig?: string;
|
||||
/**
|
||||
* @deprecated Configure the project to use the `@nx/dependency-checks` ESLint
|
||||
* rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks).
|
||||
* It will be removed in v17.
|
||||
*/
|
||||
updateBuildableProjectDepsInPackageJson?: boolean;
|
||||
watch?: boolean;
|
||||
}
|
||||
|
||||
@ -33,19 +33,6 @@
|
||||
"description": "Whether to run a build when any file changes.",
|
||||
"default": false
|
||||
},
|
||||
"updateBuildableProjectDepsInPackageJson": {
|
||||
"type": "boolean",
|
||||
"description": "Whether to update the buildable project dependencies in the build output package.json.",
|
||||
"default": false,
|
||||
"x-deprecated": "Configure the project to use the '@nx/dependency-checks' ESLint rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks). It will be removed in v17."
|
||||
},
|
||||
"buildableProjectDepsInPackageJsonType": {
|
||||
"type": "string",
|
||||
"description": "When `updateBuildableProjectDepsInPackageJson` is `true`, this adds dependencies to either `peerDependencies` or `dependencies`.",
|
||||
"enum": ["dependencies", "peerDependencies"],
|
||||
"default": "peerDependencies",
|
||||
"x-deprecated": "Configure the project to use the '@nx/dependency-checks' ESLint rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks). It will be removed in v17."
|
||||
},
|
||||
"tailwindConfig": {
|
||||
"type": "string",
|
||||
"description": "The full path for the Tailwind configuration file, relative to the workspace root. If not provided and a `tailwind.config.js` file exists in the project or workspace root, it will be used. Otherwise, Tailwind will not be configured.",
|
||||
|
||||
@ -87,7 +87,6 @@ export async function* esbuildExecutor(
|
||||
generateLockfile: true,
|
||||
outputFileExtensionForCjs: getOutExtension('cjs', options),
|
||||
excludeLibsInPackageJson: !options.thirdParty,
|
||||
updateBuildableProjectDepsInPackageJson: externalDependencies.length > 0,
|
||||
};
|
||||
|
||||
// If we're bundling third-party packages, then any extra deps from external should be the only deps in package.json
|
||||
|
||||
@ -6,7 +6,6 @@ type Compiler = 'babel' | 'swc';
|
||||
export interface EsBuildExecutorOptions {
|
||||
additionalEntryPoints?: string[];
|
||||
assets: (AssetGlob | string)[];
|
||||
buildableProjectDepsInPackageJsonType?: 'dependencies' | 'peerDependencies';
|
||||
bundle?: boolean;
|
||||
deleteOutputPath?: boolean;
|
||||
dependenciesFieldType?: boolean;
|
||||
|
||||
@ -84,19 +84,6 @@
|
||||
],
|
||||
"hidden": true
|
||||
},
|
||||
"updateBuildableProjectDepsInPackageJson": {
|
||||
"type": "boolean",
|
||||
"description": "Whether to update the buildable project dependencies in the build output package.json.",
|
||||
"default": false,
|
||||
"x-deprecated": "Configure the project to use the '@nx/dependency-checks' ESLint rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks). It will be removed in v17."
|
||||
},
|
||||
"buildableProjectDepsInPackageJsonType": {
|
||||
"type": "string",
|
||||
"description": "When `updateBuildableProjectDepsInPackageJson` is `true`, this adds dependencies to either `peerDependencies` or `dependencies`.",
|
||||
"enum": ["dependencies", "peerDependencies"],
|
||||
"default": "peerDependencies",
|
||||
"x-deprecated": "Configure the project to use the '@nx/dependency-checks' ESLint rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks). It will be removed in v17."
|
||||
},
|
||||
"external": {
|
||||
"description": "A list projects to be treated as external. This feature is experimental",
|
||||
"oneOf": [
|
||||
|
||||
@ -72,19 +72,6 @@
|
||||
},
|
||||
"x-priority": "important"
|
||||
},
|
||||
"updateBuildableProjectDepsInPackageJson": {
|
||||
"type": "boolean",
|
||||
"description": "Whether to update the buildable project dependencies in the build output package.json.",
|
||||
"default": false,
|
||||
"x-deprecated": "Configure the project to use the '@nx/dependency-checks' ESLint rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks). It will be removed in v17."
|
||||
},
|
||||
"buildableProjectDepsInPackageJsonType": {
|
||||
"type": "string",
|
||||
"description": "When `updateBuildableProjectDepsInPackageJson` is `true`, this adds dependencies to either `peerDependencies` or `dependencies`.",
|
||||
"enum": ["dependencies", "peerDependencies"],
|
||||
"default": "peerDependencies",
|
||||
"x-deprecated": "Configure the project to use the '@nx/dependency-checks' ESLint rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks). It will be removed in v17."
|
||||
},
|
||||
"external": {
|
||||
"description": "A list projects to be treated as external. This feature is experimental",
|
||||
"oneOf": [
|
||||
|
||||
@ -0,0 +1,89 @@
|
||||
import {
|
||||
addProjectConfiguration,
|
||||
readProjectConfiguration,
|
||||
Tree,
|
||||
} from '@nx/devkit';
|
||||
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
||||
import migration from './remove-deprecated-build-options';
|
||||
|
||||
describe('remove-deprecated-build-options', () => {
|
||||
let tree: Tree;
|
||||
|
||||
beforeEach(() => {
|
||||
tree = createTreeWithEmptyWorkspace();
|
||||
});
|
||||
|
||||
it('should remove updateBuildableProjectDepsInPackageJson and buildableProjectDepsInPackageJsonType options from @nx/* executors', async () => {
|
||||
addProjectConfiguration(tree, 'proj', {
|
||||
root: 'proj',
|
||||
targets: {
|
||||
build: {
|
||||
executor: '@nx/js:tsc',
|
||||
options: {
|
||||
main: 'proj/main.ts',
|
||||
tsConfig: 'proj/tsconfig.json',
|
||||
outputPath: 'dist/proj',
|
||||
updateBuildableProjectDepsInPackageJson: true,
|
||||
buildableProjectDepsInPackageJsonType: 'peerDependencies',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await migration(tree);
|
||||
|
||||
const updatedConfig = readProjectConfiguration(tree, 'proj');
|
||||
expect(updatedConfig.targets).toEqual({
|
||||
build: {
|
||||
executor: '@nx/js:tsc',
|
||||
options: {
|
||||
main: 'proj/main.ts',
|
||||
tsConfig: 'proj/tsconfig.json',
|
||||
outputPath: 'dist/proj',
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should work if targets are undefined', async () => {
|
||||
addProjectConfiguration(tree, 'proj', {
|
||||
root: 'proj',
|
||||
});
|
||||
|
||||
await expect(migration(tree)).resolves.not.toThrow();
|
||||
});
|
||||
|
||||
it('should not update community executors', async () => {
|
||||
addProjectConfiguration(tree, 'proj', {
|
||||
root: 'proj',
|
||||
targets: {
|
||||
build: {
|
||||
executor: '@acme/js:tsc',
|
||||
options: {
|
||||
main: 'proj/main.ts',
|
||||
tsConfig: 'proj/tsconfig.json',
|
||||
outputPath: 'dist/proj',
|
||||
updateBuildableProjectDepsInPackageJson: true,
|
||||
buildableProjectDepsInPackageJsonType: 'peerDependencies',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await migration(tree);
|
||||
|
||||
const updatedConfig = readProjectConfiguration(tree, 'proj');
|
||||
expect(updatedConfig.targets).toEqual({
|
||||
build: {
|
||||
executor: '@acme/js:tsc',
|
||||
options: {
|
||||
main: 'proj/main.ts',
|
||||
tsConfig: 'proj/tsconfig.json',
|
||||
outputPath: 'dist/proj',
|
||||
updateBuildableProjectDepsInPackageJson: true,
|
||||
buildableProjectDepsInPackageJsonType: 'peerDependencies',
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,38 @@
|
||||
import {
|
||||
formatFiles,
|
||||
getProjects,
|
||||
Tree,
|
||||
updateProjectConfiguration,
|
||||
} from '@nx/devkit';
|
||||
|
||||
/**
|
||||
* Removes deprecated
|
||||
* @param tree
|
||||
*/
|
||||
export default async function (tree: Tree) {
|
||||
const projects = getProjects(tree);
|
||||
|
||||
for (const [projectName, projectConfig] of projects) {
|
||||
let shouldUpdate = false;
|
||||
|
||||
if (!projectConfig.targets) continue;
|
||||
|
||||
for (const target of Object.values(projectConfig.targets)) {
|
||||
if (
|
||||
target.executor.startsWith('@nx/') &&
|
||||
('buildableProjectDepsInPackageJsonType' in target.options ||
|
||||
'updateBuildableProjectDepsInPackageJson' in target.options)
|
||||
) {
|
||||
delete target.options['buildableProjectDepsInPackageJsonType'];
|
||||
delete target.options['updateBuildableProjectDepsInPackageJson'];
|
||||
shouldUpdate = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldUpdate) {
|
||||
updateProjectConfiguration(tree, projectName, projectConfig);
|
||||
}
|
||||
}
|
||||
|
||||
await formatFiles(tree);
|
||||
}
|
||||
16
packages/js/src/utils/schema.d.ts
vendored
16
packages/js/src/utils/schema.d.ts
vendored
@ -1,8 +1,8 @@
|
||||
import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
|
||||
// nx-ignore-next-line
|
||||
const { Linter } = require('@nx/linter'); // use require to import to avoid circular dependency
|
||||
import type { AssetGlob, FileInputOutput } from './assets/assets';
|
||||
import { TransformerEntry } from './typescript/types';
|
||||
// nx-ignore-next-line
|
||||
const { Linter } = require('@nx/linter'); // use require to import to avoid circular dependency
|
||||
|
||||
export type Compiler = 'tsc' | 'swc';
|
||||
export type Bundler = 'swc' | 'tsc' | 'rollup' | 'vite' | 'esbuild' | 'none';
|
||||
@ -46,18 +46,6 @@ export interface ExecutorOptions {
|
||||
watch: boolean;
|
||||
clean?: boolean;
|
||||
transformers: TransformerEntry[];
|
||||
/**
|
||||
* @deprecated Configure the project to use the `@nx/dependency-checks` ESLint
|
||||
* rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks).
|
||||
* It will be removed in v17.
|
||||
*/
|
||||
updateBuildableProjectDepsInPackageJson?: boolean;
|
||||
/**
|
||||
* @deprecated Configure the project to use the `@nx/dependency-checks` ESLint
|
||||
* rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks).
|
||||
* It will be removed in v17.
|
||||
*/
|
||||
buildableProjectDepsInPackageJsonType?: 'dependencies' | 'peerDependencies';
|
||||
external?: 'all' | 'none' | string[];
|
||||
externalBuildTargets?: string[];
|
||||
generateLockfile?: boolean;
|
||||
|
||||
@ -54,7 +54,6 @@ describe('NxPlugin Create Package Generator', () => {
|
||||
tsConfig: 'libs/create-a-workspace/tsconfig.lib.json',
|
||||
main: 'libs/create-a-workspace/bin/index.ts',
|
||||
assets: ['libs/create-a-workspace/*.md'],
|
||||
updateBuildableProjectDepsInPackageJson: false,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,19 +1,17 @@
|
||||
import {
|
||||
addDependenciesToPackageJson,
|
||||
readProjectConfiguration,
|
||||
Tree,
|
||||
generateFiles,
|
||||
readJson,
|
||||
convertNxGenerator,
|
||||
formatFiles,
|
||||
updateProjectConfiguration,
|
||||
updateJson,
|
||||
generateFiles,
|
||||
GeneratorCallback,
|
||||
runTasksInSerial,
|
||||
joinPathFragments,
|
||||
getProjects,
|
||||
detectPackageManager,
|
||||
getPackageManagerCommand,
|
||||
joinPathFragments,
|
||||
readJson,
|
||||
readProjectConfiguration,
|
||||
runTasksInSerial,
|
||||
Tree,
|
||||
updateJson,
|
||||
updateProjectConfiguration,
|
||||
} from '@nx/devkit';
|
||||
import { libraryGenerator as jsLibraryGenerator } from '@nx/js';
|
||||
import { nxVersion } from 'nx/src/utils/versions';
|
||||
@ -132,8 +130,6 @@ async function createCliPackage(
|
||||
options.projectRoot,
|
||||
'bin/index.ts'
|
||||
);
|
||||
projectConfiguration.targets.build.options.updateBuildableProjectDepsInPackageJson =
|
||||
false;
|
||||
projectConfiguration.implicitDependencies = [options.project];
|
||||
updateProjectConfiguration(host, options.projectName, projectConfiguration);
|
||||
|
||||
|
||||
@ -10,22 +10,6 @@ To include dependencies in the output `package.json`, the dependencies must be i
|
||||
}
|
||||
```
|
||||
|
||||
To have dependencies in the be listed in the final `package.json` of your project, set the `updateBuildableProjectDepsInPackageJson` option to `true`. After than dependencies will be added to the `peerDependencies` field of the output `package.json`. You can use `buildableProjectDepsInPackageJsonType` option to change which field the dependencies are output to.
|
||||
|
||||
```json {% fileName="project.json" %}
|
||||
{
|
||||
"targets": {
|
||||
"build": {
|
||||
"executor": "@nx/rollup:rollup",
|
||||
"options": {
|
||||
"buildableProjectDepsInPackageJsonType": "dependencies",
|
||||
"updateBuildableProjectDepsInPackageJson": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
{% /tab %}
|
||||
|
||||
{% tab label="Using `babelUpwardRootMode`" %}
|
||||
|
||||
@ -27,10 +27,6 @@ export function normalizeRollupExecutorOptions(
|
||||
const projectRoot = dirname(project);
|
||||
const outputPath = `${root}/${options.outputPath}`;
|
||||
|
||||
if (options.buildableProjectDepsInPackageJsonType == undefined) {
|
||||
options.buildableProjectDepsInPackageJsonType = 'peerDependencies';
|
||||
}
|
||||
|
||||
return {
|
||||
...options,
|
||||
// de-dupe formats
|
||||
|
||||
@ -14,15 +14,6 @@ describe('updatePackageJson', () => {
|
||||
rollupConfig: [],
|
||||
};
|
||||
|
||||
const sharedContext = {
|
||||
isVerbose: false,
|
||||
projectsConfigurations: { version: 2, projects: {} },
|
||||
nxJsonConfiguration: {},
|
||||
root: '',
|
||||
cwd: '',
|
||||
};
|
||||
|
||||
// TODO(jack): In Nx 15 we want this field to always generate.
|
||||
describe('generateExportsField: true', () => {
|
||||
it('should support ESM', () => {
|
||||
const spy = jest.spyOn(utils, 'writeJsonFile');
|
||||
@ -33,9 +24,6 @@ describe('updatePackageJson', () => {
|
||||
generateExportsField: true,
|
||||
format: ['esm'],
|
||||
},
|
||||
sharedContext,
|
||||
{ type: 'app', name: 'test', data: {} as any },
|
||||
[],
|
||||
{} as unknown as PackageJson
|
||||
);
|
||||
|
||||
@ -61,9 +49,6 @@ describe('updatePackageJson', () => {
|
||||
generateExportsField: true,
|
||||
format: ['cjs'],
|
||||
},
|
||||
sharedContext,
|
||||
{ type: 'app', name: 'test', data: {} as any },
|
||||
[],
|
||||
{} as unknown as PackageJson
|
||||
);
|
||||
|
||||
@ -88,9 +73,6 @@ describe('updatePackageJson', () => {
|
||||
generateExportsField: true,
|
||||
format: ['esm', 'cjs'],
|
||||
},
|
||||
sharedContext,
|
||||
{ type: 'app', name: 'test', data: {} as any },
|
||||
[],
|
||||
{} as unknown as PackageJson
|
||||
);
|
||||
|
||||
@ -119,9 +101,6 @@ describe('updatePackageJson', () => {
|
||||
generateExportsField: true,
|
||||
format: ['esm'],
|
||||
},
|
||||
sharedContext,
|
||||
{ type: 'app', name: 'test', data: {} as any },
|
||||
[],
|
||||
{
|
||||
exports: {
|
||||
'./foo': './foo.esm.js',
|
||||
@ -154,9 +133,6 @@ describe('updatePackageJson', () => {
|
||||
...commonOptions,
|
||||
format: ['esm'],
|
||||
},
|
||||
sharedContext,
|
||||
{ type: 'app', name: 'test', data: {} as any },
|
||||
[],
|
||||
{} as unknown as PackageJson
|
||||
);
|
||||
|
||||
@ -177,9 +153,6 @@ describe('updatePackageJson', () => {
|
||||
...commonOptions,
|
||||
format: ['cjs'],
|
||||
},
|
||||
sharedContext,
|
||||
{ type: 'app', name: 'test', data: {} as any },
|
||||
[],
|
||||
{} as unknown as PackageJson
|
||||
);
|
||||
|
||||
@ -199,9 +172,6 @@ describe('updatePackageJson', () => {
|
||||
...commonOptions,
|
||||
format: ['esm', 'cjs'],
|
||||
},
|
||||
sharedContext,
|
||||
{ type: 'app', name: 'test', data: {} as any },
|
||||
[],
|
||||
{} as unknown as PackageJson
|
||||
);
|
||||
|
||||
@ -221,9 +191,6 @@ describe('updatePackageJson', () => {
|
||||
...commonOptions,
|
||||
format: ['esm'],
|
||||
},
|
||||
sharedContext,
|
||||
{ type: 'app', name: 'test', data: {} as any },
|
||||
[],
|
||||
{
|
||||
exports: {
|
||||
'./foo': './foo.esm.js',
|
||||
|
||||
@ -1,10 +1,4 @@
|
||||
import { basename, join, parse } from 'path';
|
||||
import { ExecutorContext } from 'nx/src/config/misc-interfaces';
|
||||
import { ProjectGraphProjectNode } from 'nx/src/config/project-graph';
|
||||
import {
|
||||
DependentBuildableProjectNode,
|
||||
updateBuildableProjectPackageJsonDependencies,
|
||||
} from '@nx/js/src/utils/buildable-libs-utils';
|
||||
import { writeJsonFile } from 'nx/src/utils/fileutils';
|
||||
import { writeFileSync } from 'fs';
|
||||
import { PackageJson } from 'nx/src/utils/package-json';
|
||||
@ -14,9 +8,6 @@ import { stripIndents } from '@nx/devkit';
|
||||
// TODO(jack): Use updatePackageJson from @nx/js instead.
|
||||
export function updatePackageJson(
|
||||
options: NormalizedRollupExecutorOptions,
|
||||
context: ExecutorContext,
|
||||
target: ProjectGraphProjectNode,
|
||||
dependencies: DependentBuildableProjectNode[],
|
||||
packageJson: PackageJson
|
||||
) {
|
||||
const hasEsmFormat = options.format.includes('esm');
|
||||
@ -105,21 +96,6 @@ export function updatePackageJson(
|
||||
}
|
||||
|
||||
writeJsonFile(`${options.outputPath}/package.json`, packageJson);
|
||||
|
||||
if (
|
||||
dependencies.length > 0 &&
|
||||
options.updateBuildableProjectDepsInPackageJson
|
||||
) {
|
||||
updateBuildableProjectPackageJsonDependencies(
|
||||
context.root,
|
||||
context.projectName,
|
||||
context.targetName,
|
||||
context.configurationName,
|
||||
target,
|
||||
dependencies,
|
||||
options.buildableProjectDepsInPackageJsonType
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
interface Exports {
|
||||
|
||||
@ -92,13 +92,7 @@ export async function* rollupExecutor(
|
||||
if (data.code === 'START') {
|
||||
logger.info(`Bundling ${context.projectName}...`);
|
||||
} else if (data.code === 'END') {
|
||||
updatePackageJson(
|
||||
options,
|
||||
context,
|
||||
target,
|
||||
dependencies,
|
||||
packageJson
|
||||
);
|
||||
updatePackageJson(options, packageJson);
|
||||
logger.info('Bundle complete. Watching for file changes...');
|
||||
obs.next({ success: true, outfile });
|
||||
} else if (data.code === 'ERROR') {
|
||||
@ -146,13 +140,7 @@ export async function* rollupExecutor(
|
||||
2
|
||||
)}s`;
|
||||
|
||||
updatePackageJson(
|
||||
options,
|
||||
context,
|
||||
target,
|
||||
dependencies,
|
||||
packageJson
|
||||
);
|
||||
updatePackageJson(options, packageJson);
|
||||
logger.info(`⚡ Done in ${duration}`);
|
||||
} else {
|
||||
logger.error(`Bundle failed: ${context.projectName}`);
|
||||
|
||||
12
packages/rollup/src/executors/rollup/schema.d.ts
vendored
12
packages/rollup/src/executors/rollup/schema.d.ts
vendored
@ -24,18 +24,6 @@ export interface RollupExecutorOptions {
|
||||
rollupConfig?: string | string[];
|
||||
watch?: boolean;
|
||||
assets?: any[];
|
||||
/**
|
||||
* @deprecated Configure the project to use the `@nx/dependency-checks` ESLint
|
||||
* rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks).
|
||||
* It will be removed in v17.
|
||||
*/
|
||||
updateBuildableProjectDepsInPackageJson?: boolean;
|
||||
/**
|
||||
* @deprecated Configure the project to use the `@nx/dependency-checks` ESLint
|
||||
* rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks).
|
||||
* It will be removed in v17.
|
||||
*/
|
||||
buildableProjectDepsInPackageJsonType?: 'dependencies' | 'peerDependencies';
|
||||
deleteOutputPath?: boolean;
|
||||
format?: ('cjs' | 'esm')[];
|
||||
compiler?: 'babel' | 'tsc' | 'swc';
|
||||
|
||||
@ -76,19 +76,6 @@
|
||||
"description": "Enable re-building when files change.",
|
||||
"default": false
|
||||
},
|
||||
"updateBuildableProjectDepsInPackageJson": {
|
||||
"type": "boolean",
|
||||
"description": "Update buildable project dependencies in `package.json`.",
|
||||
"default": false,
|
||||
"x-deprecated": "Configure the project to use the '@nx/dependency-checks' ESLint rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks). It will be removed in v17."
|
||||
},
|
||||
"buildableProjectDepsInPackageJsonType": {
|
||||
"type": "string",
|
||||
"description": "When `updateBuildableProjectDepsInPackageJson` is `true`, this adds dependencies to either `peerDependencies` or `dependencies`.",
|
||||
"enum": ["dependencies", "peerDependencies"],
|
||||
"default": "peerDependencies",
|
||||
"x-deprecated": "Configure the project to use the '@nx/dependency-checks' ESLint rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks). It will be removed in v17."
|
||||
},
|
||||
"rollupConfig": {
|
||||
"oneOf": [
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user