Skip to content

Commit

Permalink
style: Lint fixes (#221)
Browse files Browse the repository at this point in the history
* nx format:write --all

* lint fixes

* Add eslint-unused-imports plugin

* Fix lint warnings

* Tighten up lint rules

* async await lint fixes

* duplicate import lint fixes

* init generator async fixes + add skipFormat option
  • Loading branch information
simondotm authored Apr 3, 2024
1 parent b528b0a commit ff32512
Show file tree
Hide file tree
Showing 61 changed files with 1,596 additions and 1,488 deletions.
35 changes: 32 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"root": true,
"ignorePatterns": ["**/*"],
"plugins": ["@nx", "prettier"],
"plugins": ["@nx", "prettier", "unused-imports"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
Expand All @@ -24,14 +24,43 @@
{
"files": ["*.ts", "*.tsx"],
"extends": ["plugin:@nx/typescript"],
"rules": {}
"rules": {
"@typescript-eslint/ban-types": "warn",
"@typescript-eslint/no-var-requires": "warn",
"@typescript-eslint/no-inferrable-types": "warn",
"@typescript-eslint/no-empty-interface": "warn",
"@typescript-eslint/no-empty-function": "warn",
"no-prototype-builtins": "warn",
"no-useless-escape": "warn",
"no-inner-declarations": "off",
"no-fallthrough": "warn",
"no-irregular-whitespace": "warn",
"no-constant-condition": "warn",
"@typescript-eslint/require-await": "warn",
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/no-namespace": "warn",
"@typescript-eslint/no-this-alias": "warn",
"@typescript-eslint/no-duplicate-imports": "error",
"@typescript-eslint/no-unused-vars": "off",
"unused-imports/no-unused-imports": "warn",
"unused-imports/no-unused-vars": [
"warn",
{
"vars": "all",
"varsIgnorePattern": "^_",
"args": "after-used",
"argsIgnorePattern": "^_"
}
]
}
},
{
"files": ["*.ts", "*.tsx"],
"extends": ["plugin:prettier/recommended"],
"rules": {
"prettier/prettier": "warn"
}
}
},
{
"files": ["*.js", "*.jsx"],
Expand Down
4 changes: 2 additions & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"endOfLine": "auto",
"useTabs": false,
"quoteProps": "as-needed",
"tabWidth": 2
}
"tabWidth": 2
}
49 changes: 24 additions & 25 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,40 +27,39 @@ This plugin was completely rewritten since V2.x to use esbuild for bundling clou

## v2.2.0

* Fix package dependencies for `@nx/node`, plugin init generator now adds this if/when needed
* This prevents scenarios where incorrect Nx plugin versions could be added to the user workspace
* It may also fix an issue with `@nx/esbuild` plugin version being out of sync and bundling external dependencies incorrectly

- Fix package dependencies for `@nx/node`, plugin init generator now adds this if/when needed
- This prevents scenarios where incorrect Nx plugin versions could be added to the user workspace
- It may also fix an issue with `@nx/esbuild` plugin version being out of sync and bundling external dependencies incorrectly

## v2.1.2

* Include `@nx/devkit` as a peer dependency for the package
* Listing in the [Nx plugin registry](https://nx.dev/plugin-registry)
- Include `@nx/devkit` as a peer dependency for the package
- Listing in the [Nx plugin registry](https://nx.dev/plugin-registry)

## v2.1.1

* Fix issues in the v2.1.0 release
- Fix issues in the v2.1.0 release

## v2.1.0

* Added support for [environment variables](docs/nx-firebase-functions-environment.md)
* Added support for [secrets](docs/nx-firebase-functions-environment.md#environment-file-types)
* Added a custom `serve` executor that exits the Firebase Emulator suite properly
* Fixes to `sync` generator to update firebase app and firebase function project targets when they are renamed
* Added a custom `migrate` generator to ensure workspace configurations match the latest plugin version schemas
* Updated plugin to be built against Nx 16.6.0
- Added support for [environment variables](docs/nx-firebase-functions-environment.md)
- Added support for [secrets](docs/nx-firebase-functions-environment.md#environment-file-types)
- Added a custom `serve` executor that exits the Firebase Emulator suite properly
- Fixes to `sync` generator to update firebase app and firebase function project targets when they are renamed
- Added a custom `migrate` generator to ensure workspace configurations match the latest plugin version schemas
- Updated plugin to be built against Nx 16.6.0

## v2.0.0

Official v2 release

* Updated default function template to match firebase CLI
- Updated default function template to match firebase CLI

## v2.0.0-beta.1

* Fixed issue with dependencies
* Sort codebases
* Updated documents
- Fixed issue with dependencies
- Sort codebases
- Updated documents

## v2.0.0-beta.0

Expand All @@ -72,14 +71,14 @@ Users of earlier plugin versions must read [here for plugin v1 -> v2 migration i
**Changes**

* Plugin is completely rewritten
* Added `@simondotm/nx-firebase:function` generator
* Firebase functions are now separate application nx projects
* Now uses `esbuild` to compile & bundle firebase functions
* Firebase functions no longer require Nx libraries to be buildable
* Added `@simondotm/nx-firebase:sync` generator to manage Firebase workspaces
* Minimum Nx version is now 16.1.1
* Watch mode build of function code & libraries is now fully supported when running Firebase emulator
- Plugin is completely rewritten
- Added `@simondotm/nx-firebase:function` generator
- Firebase functions are now separate application nx projects
- Now uses `esbuild` to compile & bundle firebase functions
- Firebase functions no longer require Nx libraries to be buildable
- Added `@simondotm/nx-firebase:sync` generator to manage Firebase workspaces
- Minimum Nx version is now 16.1.1
- Watch mode build of function code & libraries is now fully supported when running Firebase emulator

## v1.1.0

Expand Down
33 changes: 16 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,27 @@ Nx provides a great way to manage monorepo workflows and this plugin helps make

### Features

* **Firebase Apps**
* Generates Firebase application projects, with default `firebase.json` configurations, rules and indexes for each Firebase app
* **Firebase Functions**
* Generates Firebase function apps based on Typescript Nx node applications
* Bundling of Firebase functions using `esbuild` for extremely fast compilation & tree-shaking for optimal function cold starts
* Easily import Typescript Nx libraries from your Nx workspace into your Firebase functions for code sharing across projects
* Supports function environment variables and secrets
* **Firebase Features**
* Use the Firebase Emulator suite whilst developing locally - all functions are watched and updated live while you work
* Use Firebase hosting with Nx to easily build & deploy web apps
* **Workspace Management**
* Nx's automatic dependency checking for no-fuss builds, and per-project or per-function deployments
* Supports single or multiple firebase projects/apps within an Nx workspace
* Nx workspace management with the `sync` generator keeps your project & `firebase.json` configs automatically updated when renaming or deleting Firebase apps & functions
* Only very lightly opinionated about your Firebase configurations and workspace layouts; you can use Nx or the Firebase CLI
- **Firebase Apps**
- Generates Firebase application projects, with default `firebase.json` configurations, rules and indexes for each Firebase app
- **Firebase Functions**
- Generates Firebase function apps based on Typescript Nx node applications
- Bundling of Firebase functions using `esbuild` for extremely fast compilation & tree-shaking for optimal function cold starts
- Easily import Typescript Nx libraries from your Nx workspace into your Firebase functions for code sharing across projects
- Supports function environment variables and secrets
- **Firebase Features**
- Use the Firebase Emulator suite whilst developing locally - all functions are watched and updated live while you work
- Use Firebase hosting with Nx to easily build & deploy web apps
- **Workspace Management**
- Nx's automatic dependency checking for no-fuss builds, and per-project or per-function deployments
- Supports single or multiple firebase projects/apps within an Nx workspace
- Nx workspace management with the `sync` generator keeps your project & `firebase.json` configs automatically updated when renaming or deleting Firebase apps & functions
- Only very lightly opinionated about your Firebase configurations and workspace layouts; you can use Nx or the Firebase CLI

# User Guide

- **[Quick Start](docs/quick-start.md)**
- [Migrating to new plugin versions](docs/nx-firebase-migrations.md)

**Nx Firebase Generators**

- [Firebase Applications](docs/nx-firebase-applications.md)
Expand All @@ -51,7 +51,6 @@ Nx provides a great way to manage monorepo workflows and this plugin helps make
- [Nx-Firebase Sync](docs/nx-firebase-sync.md)
- [Nx-Firebase Project Schemas](docs/nx-firebase-project-structure.md)


**Nx Workspace**

- [Nx Workspace Layout Ideas](docs/nx-workspace-layout.md)
Expand Down
1 change: 0 additions & 1 deletion docs/firebase-versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,3 @@ New applications generated in new Nx workspaces by `@simondotm/nx-firebase` will
- `firebase-admin` version 11.x

V2.x of the plugin uses `esbuild` to bundle functions, and **_always_** outputs `esm` format code, so the minimum node runtime requirement is 16.

15 changes: 6 additions & 9 deletions docs/nx-firebase-applications.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@ Generate a new Firebase application using:

**`nx g @simondotm/nx-firebase:application`**

OR
OR

**`nx g @simondotm/nx-firebase:app`**

| Options | Type | Description |
|---|---|--|
| `name` | required | the project name for your firebase app |
| `--directory=dir` | optional | the directory this app will be located in |
| `--project=proj` | optional | the `--project` option that will be used for firebase CLI commands |


| Options | Type | Description |
| ----------------- | -------- | ------------------------------------------------------------------ |
| `name` | required | the project name for your firebase app |
| `--directory=dir` | optional | the directory this app will be located in |
| `--project=proj` | optional | the `--project` option that will be used for firebase CLI commands |

## About Firebase Apps

Expand Down Expand Up @@ -58,4 +56,3 @@ These targets will be generated in `project.json` for your new Firebase applicat
- `test` - Run Jest unit tests for all Firebase function applications linked to this Firebase application
- `getconfig` - Fetch the firebase remote config
- `firebase` - Run the firebase CLI with the appropriate firebase `--config` and firebase `--project` parameters automatically provided

17 changes: 4 additions & 13 deletions docs/nx-firebase-emulators.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,32 @@ This will launch the Firebase emulators using the app's firebase configuration

It will also build all functions attached to this app in watch mode, so that any changes you make to your function code will be automatically be rebuilt and reloaded by the emulator.


## Nx Issue with Firebase Emulator

Due to a bug in Nx, which does not correctly pass process termination signals to child processes, CTRL+C after `serve` does not shutdown the emulator properly.

For this reason, `serve` uses the `kill-port` npm package to ensure the emulator is properly shutdown before re-running `serve`.

Unfortunately this means the emulator will not properly export data on exit either.

Unfortunately this means the emulator will not properly export data on exit either.

The Nx issue is discussed [here](https://github.com/simondotm/nx-firebase/issues/40).

Hopefully Nx will address this issue in future releases.


## Emulator workaround

Until Nx fix this problem, we are using an experimental executor in the plugin as a interim workaround:


The `serve` target in Firebase app `project.json` configurations is using:

* `@simondotm/nx-firebase:serve`
- `@simondotm/nx-firebase:serve`

instead of

* `nx:run-commands`

- `nx:run-commands`

This custom executor handles CTRL+C in a way that ensures the Firebase Emulator shuts down cleanly.

With this executor you can pass extra CLI parameters for example:

* `nx serve myfirebaseapp --only functions` - only serve functions in the Emulator




- `nx serve myfirebaseapp --only functions` - only serve functions in the Emulator
25 changes: 9 additions & 16 deletions docs/nx-firebase-functions-environment.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Firebase Function Environment Variables

## Overview

Firebase functions can make use of environment variables in their runtime.

The Nx-firebase [application generator](./nx-firebase-applications.md) will automatically create default function environment files for you to use:
Expand All @@ -11,27 +12,24 @@ The Nx-firebase [application generator](./nx-firebase-applications.md) will auto

If you run the `getconfig` target, it will place `.runtimeconfig.json` file in the `environment` folder also.

These environment files are considered common to all of your functions by nx-firebase, and are copied from your firebase app's `environment` folder to your function's `dist` folder when the function is built.
These environment files are considered common to all of your functions by nx-firebase, and are copied from your firebase app's `environment` folder to your function's `dist` folder when the function is built.

This ensures they are available for deployment and emulation.

All functions share the same environment variable files.


## Environment file types

| File | Description | Git Ignored | Deployed |
| --- | --- | --- | --- |
| `.env` | [General environment variables for functions](https://firebase.google.com/docs/functions/config-env?gen=2nd#env-variables) | - | Yes |
| `.env.local` | [Environment variable overrides for function emulation](https://firebase.google.com/docs/functions/config-env?gen=2nd#emulator_support) | - | - |
| `.env.<project-alias>` | [Environment variable overrides for specific deployment targets (eg. dev/prod)](https://firebase.google.com/docs/functions/config-env?gen=2nd#deploying_multiple_sets_of_environment_variables) | - | Yes |
| `.secret.local` | [Secrets only for function emulation](https://firebase.google.com/docs/functions/config-env?gen=2nd#secrets_and_credentials_in_the_emulator) | Yes | - |
| `.runtimeconfig.json` | [Function configurations](https://firebase.google.com/docs/cli#functions-commands) | Yes | - |
| File | Description | Git Ignored | Deployed |
| ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- | -------- |
| `.env` | [General environment variables for functions](https://firebase.google.com/docs/functions/config-env?gen=2nd#env-variables) | - | Yes |
| `.env.local` | [Environment variable overrides for function emulation](https://firebase.google.com/docs/functions/config-env?gen=2nd#emulator_support) | - | - |
| `.env.<project-alias>` | [Environment variable overrides for specific deployment targets (eg. dev/prod)](https://firebase.google.com/docs/functions/config-env?gen=2nd#deploying_multiple_sets_of_environment_variables) | - | Yes |
| `.secret.local` | [Secrets only for function emulation](https://firebase.google.com/docs/functions/config-env?gen=2nd#secrets_and_credentials_in_the_emulator) | Yes | - |
| `.runtimeconfig.json` | [Function configurations](https://firebase.google.com/docs/cli#functions-commands) | Yes | - |

> _Note that the Firebase team appear to be deprecating the use of `.runtimeconfig.json` function configs and recommending migration to dotenv environment variables._


## Deployed Files

The firebase CLI will deploy `.env` and/or `.env.<project-id>` files along with function code, and they can be version controlled.
Expand All @@ -45,8 +43,3 @@ The firebase CLI will deploy `.env` and/or `.env.<project-id>` files along with
`.secret.local` and `.env.local` are only used by the Firebase emulator suite.

`.secret.local` and `.runtimeconfig.json` should not be version controlled, and are both git ignored, but included in Nx dependency graph using a `.nxignore` override.





Loading

0 comments on commit ff32512

Please sign in to comment.