Nx Plugin Project
Prerequisites
Install the Nx plugin package.
yarn add @nx/plugin@19.8.14 -D -W
Workspace Root Packages
In Yarn, when you're working with a monorepo setup using "workspaces," dependencies should typically be added at the workspace level (i.e., in the specific package where they're needed) rather than at the root of the project. The root is generally reserved for managing the structure or configurations common across all workspaces, such as ESLint configurations or shared build scripts.
The -W (or --ignore-workspace-root-check) flag allows you to bypass the restriction that prevents adding dependencies to the root of a workspace-managed project. By default, Yarn prevents this to encourage best practices of maintaining dependencies where they are actually used.
In the context of your command, Yarn warns you because yarn add @nx/plugin@19.8.14 -D is trying to install the dependency at the root level, which is probably not what you want unless the plugin is genuinely needed by the entire project setup and not just a specific package.
So, if you must install @nx/plugin at the root level intentionally, you can do so by adding the -W flag to your command:
yarn add @nx/plugin@19.8.14 -D -W
This tells Yarn you are sure about adding the dependency to the root, and you're consciously opting out of workspace-level enforcement.
Create a Plugin Project
To create a new plugin project, run:
yarn run nx g @nx/plugin:plugin --name=github-motion --importPath=@buildmotion/github-motion --directory=packages/github-motion --e2eTestRunner=jest --projectNameAndRootFormat=as-provided --publishable=true --verbose
Add Executor to Plugin
To add an executor to the plugin, run:
yarn run nx g @nx/plugin:executor --name=github-repository '--description=Use to retrieve details for a specified Github repository.' --directory=packages/github-motion/executors/github-repository --nameAndDirectoryFormat=as-provided
Issues
Adding missing dependencies to the plugin project.
# Add missing dependencies to the plugin project.
yarn add @types/node@22.10.2 @swc/types typescript eslint@9.17.0 typescript-eslint prettier @eslint/js @typescript-eslint/parser@8.0.0 @nx/eslint-plugin@19.8.14 -D -W
# Script for Plugin Project
yarn run nx g @nx/plugin:plugin --name=github-motion --importPath=@buildmotion/github-motion --directory=packages/github-motion --e2eTestRunner=jest --projectNameAndRootFormat=as-provided --publishable=true --verbose
# Package.json Scripts
"lint": "yarn nx run-many --target=lint --all=true --parallel=3 --fix=true",
"test": "yarn nx run-many --target=test --all=true --parallel=3"
# Add Executor to Plugin
nx g @nx/plugin:executor --name=repository-info --description="Use to retrieve Github repository information." --directory=packages/github-motion/src/repository-info --nameAndDirectoryFormat=as-provided --skipLintChecks=true
Output from Nx Plugin Generator:
yarn run v1.22.22
$ /Users/valencia/work/github/buildmotion-github-motion/node_modules/.bin/nx g @nx/plugin:plugin --name=github-motion --importPath=@buildmotion/github-motion --directory=packages/github-motion --e2eTestRunner=jest --projectNameAndRootFormat=as-provided --publishable=true --verbose
Debugger listening on ws://127.0.0.1:62789/b80d0242-143d-4fa5-a143-db9fa7790231
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
NX Generating @nx/plugin:plugin
Debugger listening on ws://127.0.0.1:62796/02320003-b78e-49d2-b8cd-1bf7ed1a38ed
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Waiting for the debugger to disconnect...
Debugger listening on ws://127.0.0.1:62799/6f2eec35-d811-4e53-98b2-0f03bd3da6f3
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Waiting for the debugger to disconnect...
Debugger listening on ws://127.0.0.1:62802/e7ea7d5a-679d-49d9-b03f-fb31cfcfef63
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Waiting for the debugger to disconnect...
Debugger listening on ws://127.0.0.1:62806/3b28fbfe-c6ad-4dc8-9a81-3183845b3680
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Waiting for the debugger to disconnect...
NX We've updated the vscode settings for this repository to ensure that plugin lint checks show up inside your IDE. This created .vscode/settings.json. To read more about this file, check vscode's documentation. It is frequently not committed, so other developers may need to add similar settings if they'd like to see the lint checks in the IDE rather than only during linting.
CREATE tsconfig.base.json
CREATE .prettierrc
CREATE .prettierignore
UPDATE .vscode/extensions.json
UPDATE package.json
CREATE packages/github-motion/tsconfig.json
CREATE packages/github-motion/src/index.ts
CREATE packages/github-motion/tsconfig.lib.json
CREATE packages/github-motion/README.md
CREATE packages/github-motion/package.json
UPDATE nx.json
CREATE packages/github-motion/project.json
CREATE .verdaccio/config.yml
CREATE project.json
CREATE eslint.config.js
CREATE packages/github-motion/eslint.config.js
CREATE jest.preset.js
CREATE jest.config.ts
CREATE packages/github-motion/jest.config.ts
CREATE packages/github-motion/tsconfig.spec.json
CREATE packages/github-motion-e2e/src/github-motion.spec.ts
CREATE packages/github-motion-e2e/tsconfig.json
CREATE packages/github-motion-e2e/project.json
CREATE packages/github-motion-e2e/jest.config.ts
CREATE packages/github-motion-e2e/tsconfig.spec.json
CREATE tools/scripts/start-local-registry.ts
CREATE tools/scripts/stop-local-registry.ts
CREATE packages/github-motion-e2e/eslint.config.js
CREATE .vscode/settings.json
Debugger listening on ws://127.0.0.1:62814/c7f7b4b3-2754-441c-9335-aa17c604e0fe
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Waiting for the debugger to disconnect...
Debugger listening on ws://127.0.0.1:62819/3523739b-71ac-40fd-b1a9-ce8e53bbcac1
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
[1/4] 🔍 Resolving packages...
error Error: https://npm.pkg.github.com/@swc-node%2fregister: npm package "register" does not exist under owner "swc-node"
at params.callback [as _callback] (/Users/valencia/.nvm/versions/node/v20.12.2/lib/node_modules/yarn/lib/cli.js:66680:18)
at self.callback (/Users/valencia/.nvm/versions/node/v20.12.2/lib/node_modules/yarn/lib/cli.js:141410:22)
at Request.emit (node:events:518:28)
at Request.<anonymous> (/Users/valencia/.nvm/versions/node/v20.12.2/lib/node_modules/yarn/lib/cli.js:142382:10)
at Request.emit (node:events:518:28)
at IncomingMessage.<anonymous> (/Users/valencia/.nvm/versions/node/v20.12.2/lib/node_modules/yarn/lib/cli.js:142304:12)
at Object.onceWrapper (node:events:632:28)
at IncomingMessage.emit (node:events:530:35)
at endReadableNT (node:internal/streams/readable:1696:12)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
Waiting for the debugger to disconnect...
NX Command failed: yarn
Error: Command failed: yarn
at genericNodeError (node:internal/errors:984:15)
at wrappedFn (node:internal/errors:538:14)
at checkExecSyncError (node:child_process:890:11)
at execSync (node:child_process:962:15)
at installPackagesTask (/Users/valencia/work/github/buildmotion-github-motion/node_modules/@nx/devkit/src/tasks/install-packages-task.js:38:38)
at /Users/valencia/work/github/buildmotion-github-motion/node_modules/@nx/devkit/src/utils/package-json.js:137:61
at /Users/valencia/work/github/buildmotion-github-motion/node_modules/@nx/js/src/generators/init/init.js:132:19
at /Users/valencia/work/github/buildmotion-github-motion/node_modules/@nx/devkit/src/generators/run-tasks-in-serial.js:12:19
at /Users/valencia/work/github/buildmotion-github-motion/node_modules/@nx/devkit/src/generators/run-tasks-in-serial.js:12:19
at /Users/valencia/work/github/buildmotion-github-motion/node_modules/nx/src/command-line/generate/generate.js:247:27
Waiting for the debugger to disconnect...
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Waiting for the debugger to disconnect...