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

Nx 18, 'project crystal' and Inferred Tasks #192

Open
simondotm opened this issue Mar 24, 2024 · 4 comments
Open

Nx 18, 'project crystal' and Inferred Tasks #192

simondotm opened this issue Mar 24, 2024 · 4 comments
Labels
question Further information is requested

Comments

@simondotm
Copy link
Owner

simondotm commented Mar 24, 2024

Just opening this topic for thoughts.

https://nx.dev/concepts/inferred-tasks
https://blog.nrwl.io/what-if-nx-plugins-were-more-like-vscode-extensions-dcdad140ae09

Looks like Nx version 18 is bringing some big changes with inferred tasks for project configurations.

Since nx-firebase uses @nx/node and @nx/esbuild plugins, this is likely to need some support.

@simondotm
Copy link
Owner Author

simondotm commented Mar 29, 2024

Oof, seems like this change is getting some feedback, and quite a few new issues in the Nx repo related to this new inferred magic.

I've joined a conversation on one issue, where another developer has questioned why inferred tasks were set as the new default behaviour, when many of us were quite happy having project configurations right in the project.json file. We were happy with that and didnt need it to be optimised, and now it is (possibly) going to change everyone's workspace.

I've not been looking into it too deeply yet, but I do have concerns. Mainly that this new Nx release will lead to user workspaces having different types of project configurations (inferred/explicit) and development of this plugin is going to give me a headache in terms of support & maintenance. It's already non-trivial with all the different Nx releases & API changes going on.

We'll see. 👀 😅

@simondotm simondotm changed the title Nx 18 and Inferred Tasks Nx 18, 'project crystal' and Inferred Tasks Mar 29, 2024
@simondotm
Copy link
Owner Author

simondotm commented Mar 29, 2024

@jaytavares since you mentioned Nx 18 in a PR comment, if you are willing/able or get a chance, please do share here with us any experience you get from using it with this plugin, if indeed you update your workspace to 18. Would be interesting to hear back if it works ok or not.

@simondotm
Copy link
Owner Author

simondotm commented Mar 29, 2024

fwiw, I have added 18.0.7 and 18.1.2 to my simple compat test suite and it passed my very basic compat tests, so that's mildly encouraging.

The nx.json config for 18.1.2 looks like this:

{
  "$schema": "./node_modules/nx/schemas/nx-schema.json",
  "namedInputs": {
    "default": ["{projectRoot}/**/*", "sharedGlobals"],
    "production": [
      "default",
      "!{projectRoot}/.eslintrc.json",
      "!{projectRoot}/eslint.config.js",
      "!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)",
      "!{projectRoot}/tsconfig.spec.json",
      "!{projectRoot}/jest.config.[jt]s",
      "!{projectRoot}/src/test-setup.[jt]s",
      "!{projectRoot}/test-setup.[jt]s"
    ],
    "sharedGlobals": []
  },
  "targetDefaults": {
    "@nx/esbuild:esbuild": {
      "cache": true,
      "dependsOn": ["^build"],
      "inputs": ["production", "^production"]
    },
    "@nx/eslint:lint": {
      "cache": true,
      "inputs": [
        "default",
        "{workspaceRoot}/.eslintrc.json",
        "{workspaceRoot}/.eslintignore",
        "{workspaceRoot}/eslint.config.js"
      ]
    },
    "@nx/jest:jest": {
      "cache": true,
      "inputs": ["default", "^production", "{workspaceRoot}/jest.preset.js"],
      "options": {
        "passWithNoTests": true
      },
      "configurations": {
        "ci": {
          "ci": true,
          "codeCoverage": true
        }
      }
    },
    "@nx/js:tsc": {
      "cache": true,
      "dependsOn": ["^build"],
      "inputs": ["production", "^production"]
    }
  },
  "plugins": [
    {
      "plugin": "@nx/eslint/plugin",
      "options": {
        "targetName": "lint"
      }
    }
  ]
}

and the project.json for a function app generated by the plugin is the same as normal, so nothing inferred going on here yet:

{
  "name": "functions",
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
  "sourceRoot": "apps/functions/src",
  "projectType": "application",
  "targets": {
    "build": {
      "executor": "@nx/esbuild:esbuild",
      "outputs": ["{options.outputPath}"],
      "options": {
        "outputPath": "dist/apps/functions",
        "main": "apps/functions/src/main.ts",
        "tsConfig": "apps/functions/tsconfig.app.json",
        "assets": [
          "apps/functions/src/assets",
          {
            "glob": "**/*",
            "input": "apps/firebase/environment",
            "output": "."
          }
        ],
        "generatePackageJson": true,
        "platform": "node",
        "bundle": true,
        "thirdParty": false,
        "dependenciesFieldType": "dependencies",
        "target": "node16",
        "format": ["esm"],
        "esbuildOptions": {
          "logLevel": "info"
        }
      }
    },
    "lint": {
      "executor": "@nx/eslint:lint"
    },
    "test": {
      "executor": "@nx/jest:jest",
      "outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
      "options": {
        "jestConfig": "apps/functions/jest.config.ts"
      }
    },
    "deploy": {
      "executor": "nx:run-commands",
      "options": {
        "command": "nx run firebase:deploy --only functions:functions"
      },
      "dependsOn": ["build"]
    }
  },
  "tags": [
    "firebase:function",
    "firebase:name:functions",
    "firebase:dep:firebase"
  ]
}

@jaytavares
Copy link
Contributor

jaytavares commented Mar 30, 2024

We are on 18 already and it's working. It's worth noting that if you migrate to Nx 18 rather than create a new workspace, the inferred tasks behavior will be disabled via the NX_ADD_PLUGINS environment variable. That's our current situation.

@simondotm simondotm added the question Further information is requested label Apr 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants