Skip to content

Commit

Permalink
Update plugin to Nx 16.1.1 (#112)
Browse files Browse the repository at this point in the history
* Migrate workspace to Nx 16.1.1

* deps code has moved into the `@nx/js` plugin

* Fix plugin compat for Nx 16.1.1

* e2e tests seem more stable with nx 16.1.1 so added some back

* Fix lint error

* Revert "e2e tests seem more stable with nx 16.1.1 so added some back"

This reverts commit 00e987b.

* Tests failing in CI env, see if its that stupid workspace root thing

* Revert "Tests failing in CI env, see if its that stupid workspace root thing"

This reverts commit b405a47.

* ah ok, you gotta tell createTreeWithEmptyWorkspace you need an apps-libs layout for tests

* run CI in node 16 & 18, and use v3 actions

* remove debug console

* tidy up CI action

* update changelog
  • Loading branch information
simondotm authored May 8, 2023
1 parent bfeeeea commit a0708ba
Show file tree
Hide file tree
Showing 59 changed files with 9,800 additions and 8,238 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
8 changes: 4 additions & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"root": true,
"ignorePatterns": ["**/*"],
"plugins": ["@nrwl/nx"],
"plugins": ["@nx"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {
"@nrwl/nx/enforce-module-boundaries": [
"@nx/enforce-module-boundaries": [
"error",
{
"enforceBuildableLibDependency": true,
Expand All @@ -23,12 +23,12 @@
},
{
"files": ["*.ts", "*.tsx"],
"extends": ["plugin:@nrwl/nx/typescript"],
"extends": ["plugin:@nx/typescript"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"extends": ["plugin:@nrwl/nx/javascript"],
"extends": ["plugin:@nx/javascript"],
"rules": {}
}
]
Expand Down
27 changes: 16 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ on:
# support manual trigger of this workflow
workflow_dispatch:

# run this build action for all pushes to main
push:
# only run this build action if not pushed to release or main branches
branches-ignore: ['release*'] #, 'main']
branches: ['main']

# also run for pull requests that target main
pull_request:
branches:
- main

jobs:
setup:
Expand All @@ -19,12 +24,12 @@ jobs:

strategy:
matrix:
node-version: [19.1.0]
node-version: [16,18]

steps:
# Setup steps
- uses: actions/checkout@v3
- uses: actions/setup-node@v1
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Cache node modules
Expand All @@ -46,7 +51,7 @@ jobs:

strategy:
matrix:
node-version: [19.1.0]
node-version: [16,18]

steps:
- uses: actions/checkout@v3
Expand All @@ -71,11 +76,11 @@ jobs:

strategy:
matrix:
node-version: [19.1.0]
node-version: [16,18]

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v1
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Cache node modules
Expand All @@ -96,11 +101,11 @@ jobs:

strategy:
matrix:
node-version: [19.1.0]
node-version: [16,18]

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v1
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Cache node modules
Expand All @@ -121,11 +126,11 @@ jobs:

strategy:
matrix:
node-version: [19.1.0]
node-version: [16,18]

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v1
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Cache node modules
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
All notable changes to this project will be documented in this file.

- [@simondotm/nx-firebase Changelog](#simondotmnx-firebase-changelog)
- [v1.1.0-beta.0](#v110-beta0)
- [v1.0.0](#v100)
- [v0.13.0-beta.1](#v0130-beta1)
- [v0.13.0-beta.0](#v0130-beta0)
Expand All @@ -14,6 +15,13 @@ All notable changes to this project will be documented in this file.
- [v0.2.3](#v023)
- [v0.2.2 - Initial Release](#v022---initial-release)


## v1.1.0-beta.0

Updated for Nx 16.1.1+

- You will need to migrate your workspace to Nx 16.1.1 before updating the plugin

## v1.0.0

First Major release. No change since `0.13.0-beta.1`.
Expand Down
2 changes: 1 addition & 1 deletion docs/nx-firebase-projects.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ This can be manually achieved with `nx-firebase` by adding `production` targets

```
"deploy": {
"executor": "@nrwl/workspace:run-commands",
"executor": "@nx/workspace:run-commands",
"options": {
"command": "npx firebase deploy --config firebase.json --project your-dev-firebase-project"
},
Expand Down
18 changes: 9 additions & 9 deletions docs/nx-firebase-targets.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ This document provides examples of how the firebase application `project.json` c
- [Lint, Test Targets](#lint-test-targets)
- [Project Configuration](#project-configuration)
- [Experimental](#experimental)
- [Build Target using Webpack bundler (EXPERIMENTAL)](#build-target-using-webpack-bundler-experimental)
- [Build Target using esbuild bundler (EXPERIMENTAL)](#build-target-using-esbuild-bundler-experimental)
- [Build Target using Webpack bundler (EXPERIMENTAL)](#build-target-using-webpack-bundler-experimental)
- [Build Target using esbuild bundler (EXPERIMENTAL)](#build-target-using-esbuild-bundler-experimental)
- [Firebase Projects Config](#firebase-projects-config)

## Build Target

- Builds the Firebase functions project as a `@nrwl/js:tsc` node application.
- Builds the Firebase functions project as a `@nx/js:tsc` node application.
- The `package.json` in the output directory is updated with project dependencies and local library depedencies.
- Running this build with `nx run functions:build --watch` will only watch the main application code; it **does not** detect changes to imported library projects.

Expand Down Expand Up @@ -52,7 +52,7 @@ Fetches the remote firebase project config and stores it locally in the applicat

```
"getconfig": {
"executor": "@nrwl/workspace:run-commands",
"executor": "@nx/workspace:run-commands",
"options": {
"command": "firebase functions:config:get --config firebase.functions.json --project my-project > apps/functions/.runtimeconfig.json"
}
Expand Down Expand Up @@ -87,7 +87,7 @@ Starts the firebase emulator:

```
"emulate": {
"executor": "@nrwl/workspace:run-commands",
"executor": "@nx/workspace:run-commands",
"options": {
"commands": [
"node -e \"setTimeout(()=>{},5000)\"",
Expand Down Expand Up @@ -142,7 +142,7 @@ Note that when using the Typescript builder, changes to library dependencies **w

```
"serve": {
"executor": "@nrwl/workspace:run-commands",
"executor": "@nx/workspace:run-commands",
"options": {
"commands": [
"nx run functions:build --watch",
Expand All @@ -168,7 +168,7 @@ Note that when using the Typescript builder, changes to library dependencies **w

```
"deploy": {
"executor": "@nrwl/workspace:run-commands",
"executor": "@nx/workspace:run-commands",
"options": {
"command": "firebase deploy --config firebase.functions.json --project my-project"
}
Expand Down Expand Up @@ -204,7 +204,7 @@ A sample `project.json` file for an `nx-firebase` application project looks like

### Build Target using Webpack bundler (EXPERIMENTAL)

Bundles the Firebase functions project using `@nrwl/node:webpack`. For this to work:
Bundles the Firebase functions project using `@nx/node:webpack`. For this to work:

- Make sure your project `package.json` does not have a `main` property set.
- Your project cannot use dynamic imports via `require`
Expand All @@ -213,7 +213,7 @@ Bundles the Firebase functions project using `@nrwl/node:webpack`. For this to w

```
"build": {
"executor": "@nrwl/node:webpack",
"executor": "@nx/node:webpack",
"outputs": [
"{options.outputPath}"
],
Expand Down
8 changes: 4 additions & 4 deletions docs/nx-libraries-nested.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# Using Nx Libraries within nested sub-directories

If you create Nx Libraries in subdirectories, you should use `--importPath` when generating the buildable library, because `@nrwl/node:lib` by default generates library path aliases that are incompatible with `npm` package naming and also Firebase functions deployment. See [Github discussion here](https://github.com/nrwl/nx/issues/2794).
If you create Nx Libraries in subdirectories, you should use `--importPath` when generating the buildable library, because `@nx/node:lib` by default generates library path aliases that are incompatible with `npm` package naming and also Firebase functions deployment. See [Github discussion here](https://github.com/nrwl/nx/issues/2794).

For instance:

**`nx g @nrwl/node:lib nodelib --directory subdir --buildable`**
**`nx g @nx/node:lib nodelib --directory subdir --buildable`**

will generate Typescript path alias and `package.json` name of `@myorg/subdir/nodelib` (note the extra backslash separator) which isn't compatible with how Firebase functions are deployed.

Instead, when generating sub-directory Nx libraries that will be used by Firebase functions, use the `--importPath` feature to ensure the library has a compatible package name. eg.

**`nx g @nrwl/node:lib nodelib --directory subdir --buildable --importPath='@myorg/subdir-nodelib'`**
**`nx g @nx/node:lib nodelib --directory subdir --buildable --importPath='@myorg/subdir-nodelib'`**

> _**Note:** The Nx-Firebase plugin will detect if any such libraries are imported by a firebase application, and halt compilation._
## Publishable vs Buildable Nx Node Libraries

As of Nx 12.3.4, there doesn't seem to be much difference between a `--publishable` and a `--buildable` node library. The docs _suggest_ the builder for publishable libraries [generates optimized/webpack code](https://nx.dev/latest/angular/structure/buildable-and-publishable-libraries) but this doesn't seem to be the case in practice.

Both options have `@nrwl/js:tsc` as the builder target, and both generate a `package.json` file for the library, but using `--publishable` when generating a library will require that `--importPath` is specified.
Both options have `@nx/js:tsc` as the builder target, and both generate a `package.json` file for the library, but using `--publishable` when generating a library will require that `--importPath` is specified.

Both of these library options are compatible with Nx-Firebase applications.
4 changes: 2 additions & 2 deletions docs/nx-libraries.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ Nx-Firebase supports use of Nx Libraries within functions code.

To use a shared library with an Nx Firebase Application (Functions), first create a buildable (and it must be buildable) Typescript Nx node library in your workspace:

**`nx g @nrwl/node:lib mynodelib --buildable --importPath="@myorg/mynodelib`**
**`nx g @nx/node:lib mynodelib --buildable --importPath="@myorg/mynodelib`**

> _Note: The `--importPath` option is highly recommended to ensure the correct typescript aliases and npm package configurations for your library._
As of Nx 13.8.8, you can also use:

**`nx g @nrwl/js:tsc mylib --buildable --importPath="@myorg/mylib`**
**`nx g @nx/js:tsc mylib --buildable --importPath="@myorg/mylib`**

## Importing a library

Expand Down
10 changes: 5 additions & 5 deletions docs/nx-versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The `nx-firebase` plugin does not currently have a migration script, so recommen

- Nx versions prior to 13.10.0 used `@nrwl/tao` dependency which doesn't seem to get migrated automatically, so...
- If you are using Nx version < 13.10.x, we would recommend that Nx updates are applied sequentially to ensure safe migrations using this sequence of commands for each update:
- `npx nx @nrwl/workspace@<version>`
- `npx nx @nx/workspace@<version>`
- `npm install`
- `npm install @nrwl/tao@<version>`
- `npx nx migrate --run-migrations`
Expand All @@ -19,7 +19,7 @@ Then, run this sequence for each minor release upto Nx 13.10.x, where the list o
| `12.2.0` | Same | (use same `@nrwl/tao` version unless specified otherwise) |
| `12.3.6` | Same | |
| `12.4.0` | Same | |
| `12.5.9` | Same | recommend running `nx g @nrwl/workspace:convert-to-nx-project --all` for this version |
| `12.5.9` | Same | recommend running `nx g @nx/workspace:convert-to-nx-project --all` for this version |
| | | Upgrade node to at least 14.2.0 from this version |
| `12.6.6` | Same | |
| `12.7.2` | Same | |
Expand All @@ -34,7 +34,7 @@ Then, run this sequence for each minor release upto Nx 13.10.x, where the list o
| `13.5.3` | Same | |
| `13.6.1` | Same | |
| `13.7.3` | Same | |
| `13.8.8` | Same | In this release `@nrwl/node:package` is replaced with `@nrwl/js:tsc` |
| `13.8.8` | Same | In this release `@nx/node:package` is replaced with `@nx/js:tsc` |
| `13.9.7` | n/a | In this release `@nrwl/tao` is replaced with the `nx` cli, so manual updates of `@nrwl/tao` package version are no longer necessary from hereon |
| `13.10.6` | n/a | The last minor release of Nx 13. |

Expand All @@ -58,8 +58,8 @@ Then, run this sequence for each minor release upto Nx 13.10.x, where the list o
| `14.5.5` | Jest config & tsconfig.spec updates |
| `14.5.10` | Updates `rxjs`, manally updated eslint to fix peerdeps issue, some legacy Angular libs may need updating to be compatible |
| `14.6.0` | Updates some angular packages, eslint, jest, installs an rc version of Nx which breaks the nx-firebase plugin on peer deps |
| `14.7.6` | @nrwl/node:webpack => @nrwl/webpack migration |
| `14.8.0` | Migrates from `@nrwl/workspace:run-command` to `nx:run-command` |
| `14.7.6` | @nx/node:webpack => @nrwl/webpack migration |
| `14.8.0` | Migrates from `@nx/workspace:run-command` to `nx:run-command` |

## Nx 14.8.0

Expand Down
2 changes: 1 addition & 1 deletion docs/optimizing-libraries.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ our functions code and libraries are now able to import other public API modules
>
> _Normally we'd discourage exposing the private implementations of libraries as a best practice, but for Firebase functions, cold start times are a genuine (and sometimes significant) side effect of importing unnecessary dependencies, so by directly deep importing only specific module from libraries we can improve runtime performance of our functions at the cost of exposing our private library implementations._
> Note also that the path aliases used must match the built library output directory structure in `dist`, because the `@nrwl/js:tsc` executor for buildable `@nrwl/js:lib` projects that import other buildable node libraries [generate temporary `tsconfig.generated.json` files for buildable node libraries](https://github.com/nrwl/nx/blob/d007d37fb4f625fc4854d06d2e083ed778d6a3db/packages/workspace/src/utilities/buildable-libs-utils.ts#L142) , and [automatically converts the Typescript compiler path aliases](https://github.com/nrwl/nx/blob/d007d37fb4f625fc4854d06d2e083ed778d6a3db/packages/workspace/src/utilities/buildable-libs-utils.ts#L217) in this temp config to point to the built `dist/libs/...` library output instead of the library source.
> Note also that the path aliases used must match the built library output directory structure in `dist`, because the `@nx/js:tsc` executor for buildable `@nx/js:lib` projects that import other buildable node libraries [generate temporary `tsconfig.generated.json` files for buildable node libraries](https://github.com/nrwl/nx/blob/d007d37fb4f625fc4854d06d2e083ed778d6a3db/packages/workspace/src/utilities/buildable-libs-utils.ts#L142) , and [automatically converts the Typescript compiler path aliases](https://github.com/nrwl/nx/blob/d007d37fb4f625fc4854d06d2e083ed778d6a3db/packages/workspace/src/utilities/buildable-libs-utils.ts#L217) in this temp config to point to the built `dist/libs/...` library output instead of the library source.
2 changes: 1 addition & 1 deletion docs/supporting-libraries.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Supporting Nx libraries as external packages with Firebase functions is slightly tricky. The solution the Nx-Firebase plugin uses is to use [local package references](https://firebase.google.com/docs/functions/handle-dependencies#including_local_nodejs_modules).

Nx-Firebase has a custom build executor which is based on the `@nrwl/js:tsc` executor, with a few additional build steps.
Nx-Firebase has a custom build executor which is based on the `@nx/js:tsc` executor, with a few additional build steps.

1. It compiles any node libraries that are dependents of our Firebase application
2. It compiles the Firebase application functions code as a pure buildable Typescript library package
Expand Down
16 changes: 9 additions & 7 deletions e2e/compat/jest.config.js → e2e/compat/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
module.exports = {
/* eslint-disable */
export default {
displayName: 'compat',
preset: '../../jest.preset.js',
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
},
},
globals: {},
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': 'ts-jest',
'^.+\\.[tj]s$': [
'ts-jest',
{
tsconfig: '<rootDir>/tsconfig.spec.json',
},
],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/e2e/compat',
Expand Down
19 changes: 11 additions & 8 deletions e2e/compat/project.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
{
"root": "e2e/compat",
"name": "compat",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "e2e/compat/src",
"projectType": "application",
"targets": {
"build": {
"executor": "@nrwl/node:webpack",
"executor": "@nrwl/webpack:webpack",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/e2e/compat",
"main": "e2e/compat/src/main.ts",
"tsConfig": "e2e/compat/tsconfig.app.json",
"assets": ["e2e/compat/src/assets"]
"assets": ["e2e/compat/src/assets"],
"target": "node",
"compiler": "tsc"
},
"configurations": {
"production": {
Expand All @@ -27,23 +30,23 @@
}
},
"serve": {
"executor": "@nrwl/node:node",
"executor": "@nx/node:node",
"options": {
"buildTarget": "compat:build"
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["e2e/compat/**/*.ts"]
}
},
"test": {
"executor": "@nrwl/jest:jest",
"outputs": ["coverage/e2e/compat"],
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/e2e/compat"],
"options": {
"jestConfig": "e2e/compat/jest.config.js",
"jestConfig": "e2e/compat/jest.config.ts",
"passWithNoTests": true
}
}
Expand Down
Loading

0 comments on commit a0708ba

Please sign in to comment.