# @thyself/nx-serverless

> A full Serverless framework support, both executor & generator, for the NX environment.

Latest version **1.2.1** (published 2024-02-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install @thyself/nx-serverless
pnpm add @thyself/nx-serverless
yarn add @thyself/nx-serverless
bun add @thyself/nx-serverless
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.1 |
| Published | 2024-02-17 |
| First published | 2024-02-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 13 |
| Unpacked size | 199.4 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Ofri Peretz |
| Maintainers | the_offricial |
| Keywords | thyself, nx, serverless, nx-serverless |

## Links

- npm: https://www.npmjs.com/package/@thyself/nx-serverless
- Repository: https://github.com/theoffricial/thyself
- Homepage: https://github.com/theoffricial/thyself/tree/main/packages/nx-serverless
- Issues: https://github.com/theoffricial/thyself/issues
- npm.io page: https://npm.io/package/@thyself/nx-serverless

## Dependencies (13)

- [nx](https://npm.io/package/nx.md) ^18.0.4
- [util](https://npm.io/package/util.md) 0.12.5
- [chalk](https://npm.io/package/chalk.md) ^4.1.2
- [tslib](https://npm.io/package/tslib.md) ^2.3.0
- [semver](https://npm.io/package/semver.md) ^7.5.4
- [@nx/jest](https://npm.io/package/@nx/jest.md) ^18.0.4
- [date-fns](https://npm.io/package/date-fns.md) ^3.3.1
- [@nx/devkit](https://npm.io/package/@nx/devkit.md) ^18.0.4
- [@nx/eslint](https://npm.io/package/@nx/eslint.md) 18.0.4
- [prettyjson](https://npm.io/package/prettyjson.md) ^1.2.5
- [serverless](https://npm.io/package/serverless.md) ^3.38.0
- [strip-ansi](https://npm.io/package/strip-ansi.md) ^6.0.1
- [@thyself/clean-empty-values](https://npm.io/package/@thyself/clean-empty-values.md) ^1.1.0

## Recent versions

- 1.2.1 (latest) — 2024-02-17
- 1.2.0 — 2024-02-16
- 1.1.0 — 2024-02-16
- 1.0.0 — 2024-02-10
- 0.1.0 — 2024-02-06

## README

# NX Serverless

A full Serverless framework support, both executor & generator, for the NX environment.


![NPM Downloads](https://img.shields.io/npm/dy/%40thyself%2Fnx-serverless)
![Dependents (via libraries.io)](https://img.shields.io/librariesio/dependents/npm/%40thyself%2Fnx-serverless)
![npm bundle size (scoped)](https://img.shields.io/bundlephobia/min/%40thyself/nx-serverless)
![npm bundle size (scoped)](https://img.shields.io/bundlephobia/minzip/%40thyself/nx-serverless)

## Features

* NX executor with a full support of the Serverless CLI.
* NX generator to generate new serverless stacks (projects) out-of-the-box
    * Support `npm`, `yarn` and `pnpm` environments.
    * Support of `serverless-esbuild`, `serverless-webpack`, `serverless-plugin-typescript`.
* Cold-start optimized setup using the Serverless & AWS best-practices.
* Advanced setup & Fully documented serverless setup when using `esbuild` or `webpack` that optimized for both the local environment and cloud environments.

## Install

```bash
// npm
npm i -D @thyself/nx-serverless
// yarn
yarn add @thyself/nx-serverless -D
// pnpm
pnpm add @thyself/nx-serverless -D -w
```

## Usage

### Generator

#### Generating a new stack

Currently the generator supports the `stack` option.
Then you will need to choose package manager and bundler.

* package managers - Support all top package managers
    * Available package managers: `pnpm`, `npm`, `yarn`
* bundler - Supports state-of-the-art fully configured serverless bundlers optimized for coldstart.
    * Available stack bundlers: `webpack (serverless-webpack)`, `esbuild (serverless-esbuild)`, `tsc (serverless-plugin-typescript)`

![Generating new template GIF](./assets/generator-usage-example.gif)



#### Templates

According to the `package manager` and `bundler` you chose the template will be generated.

![Alt Text](./assets/template-overview.gif)

### Executor

The `@thyself/nx-serverless` fully supports all _[Serverless Framework CLI commands and options](https://www.serverless.com/framework/docs/providers/aws/cli-reference)_.
The templates (project.json) by default generated with `start-offline`, `package`, `deploy`, `print`, and `remove` commands.

#### Configuring commands

If a commands in serverless CLI compounds from several arguments, concat them with dashes `-`, for example: `serverless deploy list functions`, for the executor is: `deploy-list-functions`

```json
// project.json
// ...
targets: {
    // ...more targets
    "<target-name>": {
      "executor": "@thyself/nx-serverless:<serverless-cli-command>",
      "options": {
        "cwd": "<appsDir>/<stack-dir-name>",
        // ...more options
      }
    },
    // serverless deploy list functions
    "list-deployed-functions": {
      "executor": "@thyself/nx-serverless:deploy-list-functions",
      "options": {
        // Common appsDir is "stacks"
        "cwd": "<your-nx-workspaceLayout-appsDir>/<stack-dir-name>",
        // ...more options
      }
    },
    // ...more targets
}
```

#### Example #1: serverless offline start 

![Alt Text](./assets/executor-start-example.gif)

#### Example #2: serverless package 

![Alt Text](./assets/executor-package-example.gif)

## VScode Debug (launch.json) Setup for NX

The setup can be configured both on the user's level launch settings or in the project's settings.

Recommended to installing `nx` and `serverless` globally.

```json
// User's settings.json
// ...more options
    "launch": {
        "inputs": [
            {
                "id": "nx-project-name",
                "description": "Enter NX project from workspace. e.g. my-package",
                "default": "my-app",
                "type": "promptString",
            },
            {
                "id": "nx-project-command",
                "description": "Enter project command from project.json. e.g. test/lint/build/etc.",
                "default": "my-command",
                "type": "promptString",
            },
            {
                "id": "command-flags",
                "description": "Enter flags to be attached to your command",
                "default": "",
                "type": "promptString",
            }
        ],
        "version": "0.2.0",
        "configurations": [
            {       
                "name": "Nx Debug", // check: https://stackoverflow.com/questions/48273346/vscode-command-for-user-input-in-debug-launch-config
                "type": "node",
                "request": "launch",
                "runtimeExecutable": "nx",
                "args": [
                    "run",
                    "--project",
                    "${input:nx-project-name}",
                    "${input:nx-project-command}",
                    // "--",
                    // "${input:command-flags}",
                ],
                "runtimeArgs": [
                ],
                "env": {
                    "SLS_DEBUG": "*",
                },
                "skipFiles": [
                    "<node_internals>/**",
                ],
                "restart": true,
                "outFiles": [
                    "${workspaceFolder}/**/.esbuild/**/*.js",
                    "${workspaceFolder}/**/.webpack/**/*.js",
                    "${workspaceFolder}/**/.build/**/*.js",
                ],
                "outputCapture": "std",
                "sourceMaps": true,
	            "smartStep": true,
                "resolveSourceMapLocations": [
                    "${workspaceFolder}/**",
                    "${workspaceFolder}/**/.esbuild/**/*.js.map",
                    "!**/node_modules/**"
                ],
                "pauseForSourceMap": true,
                "internalConsoleOptions": "neverOpen"
            }
        ]
    }
```




## Backwards Compatibility & Legacy Serverless versions

The entire plugin developed on newest versions of both `nx@17` and `serverless@3`,
and not tested on legacy environments, so it can't be guaranteed.

---
_Source: https://npm.io/package/@thyself/nx-serverless · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
