@simondotm/nx-firebase 0.3.3 → 0.13.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/README.md +22 -65
  2. package/executors.json +2 -7
  3. package/generators.json +2 -2
  4. package/package.json +4 -9
  5. package/src/executors/build/build.d.ts +8 -15
  6. package/src/executors/build/build.js +56 -181
  7. package/src/executors/build/build.js.map +1 -1
  8. package/src/executors/build/lib/copy-dependencies.d.ts +3 -0
  9. package/src/executors/build/lib/copy-dependencies.js +53 -0
  10. package/src/executors/build/lib/copy-dependencies.js.map +1 -0
  11. package/src/executors/build/lib/firebase-build.d.ts +2 -0
  12. package/src/executors/build/lib/firebase-build.js +16 -0
  13. package/src/executors/build/lib/firebase-build.js.map +1 -0
  14. package/src/executors/build/lib/get-dependencies.d.ts +8 -0
  15. package/src/executors/build/lib/get-dependencies.js +89 -0
  16. package/src/executors/build/lib/get-dependencies.js.map +1 -0
  17. package/src/executors/build/lib/index.d.ts +1 -0
  18. package/src/executors/build/lib/index.js +5 -0
  19. package/src/executors/build/lib/index.js.map +1 -0
  20. package/src/executors/build/lib/rewrite-package.d.ts +8 -0
  21. package/src/executors/build/lib/rewrite-package.js +44 -0
  22. package/src/executors/build/lib/rewrite-package.js.map +1 -0
  23. package/src/executors/build/schema.d.ts +1 -27
  24. package/src/executors/build/schema.json +83 -36
  25. package/src/generators/application/application.d.ts +9 -24
  26. package/src/generators/application/application.js +25 -263
  27. package/src/generators/application/application.js.map +1 -1
  28. package/src/generators/application/files/database.rules.json +1 -1
  29. package/src/generators/application/files/{package.json__template__ → package.json__tmpl__} +6 -6
  30. package/src/generators/application/files/public/index.html +11 -11
  31. package/src/generators/application/files/{readme.md__template__ → readme.md__tmpl__} +1 -1
  32. package/src/generators/application/files/src/{index.ts__template__ → index.ts__tmpl__} +2 -1
  33. package/src/generators/application/files_firebase/firebase.json__tmpl__ +64 -0
  34. package/src/generators/application/files_firebaserc/{.firebaserc__template__ → .firebaserc__tmpl__} +0 -0
  35. package/src/generators/application/files_workspace/firebase.__name__.json__tmpl__ +64 -0
  36. package/src/generators/application/lib/add-project.d.ts +39 -0
  37. package/src/generators/application/lib/add-project.js +88 -0
  38. package/src/generators/application/lib/add-project.js.map +1 -0
  39. package/src/generators/application/lib/create-files.d.ts +9 -0
  40. package/src/generators/application/lib/create-files.js +62 -0
  41. package/src/generators/application/lib/create-files.js.map +1 -0
  42. package/src/generators/application/lib/delete-files.d.ts +8 -0
  43. package/src/generators/application/lib/delete-files.js +23 -0
  44. package/src/generators/application/lib/delete-files.js.map +1 -0
  45. package/src/generators/application/lib/index.d.ts +4 -0
  46. package/src/generators/application/lib/index.js +8 -0
  47. package/src/generators/application/lib/index.js.map +1 -0
  48. package/src/generators/application/lib/normalize-options.d.ts +5 -0
  49. package/src/generators/application/lib/normalize-options.js +44 -0
  50. package/src/generators/application/lib/normalize-options.js.map +1 -0
  51. package/src/generators/application/lib/update-tsconfig.d.ts +9 -0
  52. package/src/generators/application/lib/update-tsconfig.js +20 -0
  53. package/src/generators/application/lib/update-tsconfig.js.map +1 -0
  54. package/src/generators/application/schema.d.ts +23 -15
  55. package/src/generators/application/schema.json +38 -45
  56. package/src/generators/init/init.d.ts +15 -4
  57. package/src/generators/init/init.js +23 -39
  58. package/src/generators/init/init.js.map +1 -1
  59. package/src/generators/init/lib/add-dependencies.d.ts +2 -0
  60. package/src/generators/init/lib/add-dependencies.js +53 -0
  61. package/src/generators/init/lib/add-dependencies.js.map +1 -0
  62. package/src/generators/init/lib/add-git-ignore-entry.d.ts +3 -0
  63. package/src/generators/init/lib/add-git-ignore-entry.js +26 -0
  64. package/src/generators/init/lib/add-git-ignore-entry.js.map +1 -0
  65. package/src/generators/init/lib/index.d.ts +3 -0
  66. package/src/generators/init/lib/index.js +7 -0
  67. package/src/generators/init/lib/index.js.map +1 -0
  68. package/src/generators/init/lib/normalize-options.d.ts +2 -0
  69. package/src/generators/init/lib/normalize-options.js +9 -0
  70. package/src/generators/init/lib/normalize-options.js.map +1 -0
  71. package/src/generators/init/schema.d.ts +6 -4
  72. package/src/generators/init/schema.json +10 -8
  73. package/src/utils/e2ePatch.d.ts +1 -0
  74. package/src/utils/e2ePatch.js +120 -21
  75. package/src/utils/e2ePatch.js.map +1 -1
  76. package/src/utils/index.d.ts +3 -0
  77. package/src/utils/index.js +7 -0
  78. package/src/utils/index.js.map +1 -0
  79. package/src/utils/types.d.ts +1 -0
  80. package/src/{executors/build/node/package/utils/models.js → utils/types.js} +1 -1
  81. package/src/utils/types.js.map +1 -0
  82. package/src/utils/versions.d.ts +12 -0
  83. package/src/utils/versions.js +32 -0
  84. package/src/utils/versions.js.map +1 -0
  85. package/src/utils/workspace.d.ts +2 -0
  86. package/src/utils/workspace.js +32 -0
  87. package/src/utils/workspace.js.map +1 -0
  88. package/src/executors/build/build.spec.ts +0 -11
  89. package/src/executors/build/node/package/package.d.ts +0 -4
  90. package/src/executors/build/node/package/package.js +0 -37
  91. package/src/executors/build/node/package/package.js.map +0 -1
  92. package/src/executors/build/node/package/utils/cli.d.ts +0 -3
  93. package/src/executors/build/node/package/utils/cli.js +0 -19
  94. package/src/executors/build/node/package/utils/cli.js.map +0 -1
  95. package/src/executors/build/node/package/utils/compile-typescript-files.d.ts +0 -6
  96. package/src/executors/build/node/package/utils/compile-typescript-files.js +0 -22
  97. package/src/executors/build/node/package/utils/compile-typescript-files.js.map +0 -1
  98. package/src/executors/build/node/package/utils/models.d.ts +0 -20
  99. package/src/executors/build/node/package/utils/models.js.map +0 -1
  100. package/src/executors/build/node/package/utils/normalize-options.d.ts +0 -3
  101. package/src/executors/build/node/package/utils/normalize-options.js +0 -25
  102. package/src/executors/build/node/package/utils/normalize-options.js.map +0 -1
  103. package/src/executors/build/node/package/utils/update-package-json.d.ts +0 -3
  104. package/src/executors/build/node/package/utils/update-package-json.js +0 -19
  105. package/src/executors/build/node/package/utils/update-package-json.js.map +0 -1
  106. package/src/executors/firebase/firebase.d.ts +0 -12
  107. package/src/executors/firebase/firebase.js +0 -133
  108. package/src/executors/firebase/firebase.js.map +0 -1
  109. package/src/executors/firebase/firebase.spec.ts +0 -11
  110. package/src/executors/firebase/schema.d.ts +0 -4
  111. package/src/executors/firebase/schema.json +0 -24
  112. package/src/generators/application/application.spec.ts +0 -20
  113. package/src/generators/application/files/tsconfig.app.json__template__ +0 -11
  114. package/src/generators/application/files/tsconfig.json__template__ +0 -10
  115. package/src/generators/application/files_firebase/firebase.json__template__ +0 -2
  116. package/src/generators/application/files_workspace/firebase.__name__.json__template__ +0 -50
  117. package/src/generators/init/init.spec.ts +0 -40
package/README.md CHANGED
@@ -1,84 +1,41 @@
1
1
  # @simondotm/nx-firebase
2
2
 
3
- A plugin for [Nx](https://nx.dev) >= 12.1.1 that provides support for Firebase projects in an Nx monorepo workspace.
3
+ ![npm](https://img.shields.io/npm/dw/@simondotm/nx-firebase.svg)
4
4
 
5
- **This project has been renamed from `@simondotm/nxfirebase` to `@simondotm/nx-firebase`**
5
+ A plugin for [Nx](https://nx.dev) >= 12.1.1 that provides support for Firebase projects in an Nx monorepo workspace.
6
6
 
7
- See [CHANGELOG](https://github.com/simondotm/nx-firebase/blob/main/CHANGELOG.md) for more details.
7
+ See [CHANGELOG](https://github.com/simondotm/nx-firebase/blob/main/CHANGELOG.md) for release notes.
8
8
 
9
9
  ## Overview
10
10
 
11
- Nx provides a great way to manage monorepo workflows, however if you have a development setup where your Nx workspace uses one or more Firebase projects that use different combinations and configurations of Firebase features such as _hosting_, _storage_, _database rules/indexes_, and _functions_, then some extra tooling is necessary in order to maintain a familiar Firebase workflow within your monorepo.
11
+ Nx provides a great way to manage monorepo workflows and this plugin helps to integrate Firebase projects with Nx, by:
12
12
 
13
- This plugin aims to help with this by:
14
13
  1. Enabling & promoting use of shared Typescript code libraries within Firebase functions
15
14
  2. Retaining a familiar usage of all Firebase features in a way that feels integrated with Nx workflow
16
15
  3. Requiring minimal friction/setup for configuration of an Nx workspace in order to be productive with development, building & deployment of Firebase projects
16
+ 4. Supporting multiple firebase projects within an Nx workspace
17
17
 
18
- # Quick Start
19
-
20
- ## Installation
21
- **`npm install @simondotm/nx-firebase`**
22
-
23
- Installs this plugin into your Nx workspace.
24
-
25
-
26
- **`nx g @simondotm/nx-firebase:init`**
27
-
28
- Installs firebase dependencies (both for backend and frontend) to your root workspace `package.json` (or you can just `npm install` firebase dependencies manually)
29
-
30
- ## Create Firebase Application
31
-
32
- **`nx g @simondotm/nx-firebase:app <appname> [--directory dir]`**
33
-
34
- Generates a new Nx Firebase application in the workspace - `/apps/[dir]/appname`
35
-
36
- The app generator will also create a Firebase configuration file called `firebase.appname.json` in the root of your workspace (along with a default `.firebaserc` and `firebase.json` if they don't already exist)
37
-
38
- ## Build Project
39
-
40
- **`nx build appname [--with-deps]`**
41
-
42
- Compiles & builds the target Nx Firebase (functions) application to `dist/apps/[dir]/appname`. It will also auto-generate a `package.json` that is compatible with the Firebase CLI for functions deployment.
18
+ ## Nx-Firebase Features
43
19
 
44
- ## Deploy Project (Firebase functions)
45
-
46
- For inital deployment:
47
-
48
- **`firebase login`** if not already authenticated
49
-
50
- **`firebase use --add`** to add your Firebase Project(s) to the `.firebaserc` file in your workspace. This step must be completed before you can deploy anything to Firebase.
51
-
52
- Then:
53
-
54
- **`firebase deploy --only functions --config firebase.appname.json`**
55
-
56
- Or
20
+ Supports:
57
21
 
58
- **`nx deploy appname --only functions`**
22
+ - Typescript Firebase functions
23
+ - Single or multiple Firebase projects in one Nx workspace
24
+ - Firebase applications in app subdirectories
25
+ - Use of shared Nx buildable libraries in Firebase functions
26
+ - Nx provides automatic dependency checking for builds
27
+ - Building functions with `tsc` `--watch` mode
28
+ - Firebase Emulators
29
+ - Convenience Nx `getconfig` target to fetch remote firebase functions configuration variables to local `.runtimeconfig.json` file
30
+ - Convenience Nx `deploy`, `emulate`, and `serve` targets for functions
59
31
 
32
+ Additionally:
60
33
 
61
- ## Serve Project
34
+ - Auto generates Firebase functions `package.json` ready for no fuss deployment using the Firebase CLI
35
+ - Auto generates default `firebase.json` configurations, rules and indexes for each Firebase app
36
+ - Only very lightly opinionated about your Firebase configurations and workspace layouts; you can just use the Firebase CLI as usual
37
+ - Keeps all of your firebase rules and indexes within your app folder, to keep your workspace root free of clutter
62
38
 
63
- **`nx serve appname`** - will run `tsc` in watch mode on the app function code and start the Firebase emulators
39
+ ## Further Information
64
40
 
65
41
  See the full plugin [README](https://github.com/simondotm/nx-firebase/blob/main/README.md) for more details.
66
-
67
- # Nx-Firebase Features
68
-
69
- Supports:
70
- * Typescript Firebase functions
71
- * Single or multiple Firebase projects in one Nx workspace
72
- * Firebase applications in app subdirectories
73
- * Use of Nx buildable node libraries in Firebase functions
74
- * Nx dependency checking for builds
75
- * Building functions with `tsc` `--watch` mode
76
- * Firebase Emulators
77
- * Convenience Nx `getconfig` target to fetch remote firebase functions configuration variables to local `.runtimeconfig.json` file
78
- * Convenience Nx `deploy`, `emulate`, and `serve` targets for functions
79
-
80
- Additionally:
81
- * Auto generates Firebase functions `package.json` ready for no fuss deployment using the Firebase CLI
82
- * Auto generates default `firebase.json` configurations, rules and indexes for each Firebase app
83
- * Only very lightly opinionated about your Firebase configurations and workspace layouts; you can just use the Firebase CLI as usual
84
- * Keeps all of your firebase rules and indexes within your app folder, to keep your workspace root free of clutter
package/executors.json CHANGED
@@ -4,12 +4,7 @@
4
4
  "build": {
5
5
  "implementation": "./src/executors/build/build",
6
6
  "schema": "./src/executors/build/schema.json",
7
- "description": "firebase build executor"
8
- },
9
- "firebase": {
10
- "implementation": "./src/executors/firebase/firebase",
11
- "schema": "./src/executors/firebase/schema.json",
12
- "description": "firebase cli executor"
13
- }
7
+ "description": "build executor"
8
+ }
14
9
  }
15
10
  }
package/generators.json CHANGED
@@ -6,13 +6,13 @@
6
6
  "init": {
7
7
  "factory": "./src/generators/init/init",
8
8
  "schema": "./src/generators/init/schema.json",
9
- "description": "Initialize the @simondotm/nx-firebase plugin",
9
+ "description": "nx-firebase initializer",
10
10
  "hidden": true
11
11
  },
12
12
  "application": {
13
13
  "factory": "./src/generators/application/application",
14
14
  "schema": "./src/generators/application/schema.json",
15
- "description": "nxfirebase application generator",
15
+ "description": "nx-firebase application generator",
16
16
  "aliases": ["app"]
17
17
  }
18
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simondotm/nx-firebase",
3
- "version": "0.3.3",
3
+ "version": "0.13.0-beta.0",
4
4
  "description": "A Firebase plugin for Nx monorepo workspaces.",
5
5
  "author": "Simon Morris",
6
6
  "license": "MIT",
@@ -21,13 +21,8 @@
21
21
  "generators": "./generators.json",
22
22
  "executors": "./executors.json",
23
23
  "peerDependencies": {
24
- "@nrwl/devkit": ">= 12.1.1",
25
- "@nrwl/workspace": ">= 12.1.1",
26
- "@nrwl/linter": ">= 12.1.1",
27
- "@nrwl/jest": ">= 12.1.1"
24
+ "nx": ">= 13.10.6",
25
+ "@nrwl/workspace": ">= 13.10.6"
28
26
  },
29
- "typings": "./src/index.d.ts",
30
- "dependencies": {
31
- "fs-extra": "^10.0.0"
32
- }
27
+ "typings": "./src/index.d.ts"
33
28
  }
@@ -1,19 +1,12 @@
1
1
  import '../../utils/e2ePatch';
2
- import { FirebaseBuildExecutorSchema } from './schema';
3
2
  import { ExecutorContext } from '@nrwl/devkit';
3
+ import type { ExecutorOptions } from '@nrwl/js/src/utils/schema';
4
4
  /**
5
- * Custom Firebase Functions "Application" nx build exector
6
- * Based on @nrwl/node:package executor
7
- *
8
- * - Builds the current application as a Typescript package library for Firebase functions
9
- * - Copies any dependent libraries to the dist folder
10
- * - Auto generates the firebase functions package.json
11
- * - Updates the firebase functions package.json to convert library dependency references to local file references
12
- *
13
- * After building, the project can be deployed using the firebase CLI as usual
14
- *
15
- * @param options
16
- * @param context
17
- * @returns build success/failure outcome
5
+ * @simondotm/nx-firebase:build executor is a
6
+ * customized version of @nrwl/js:tsc executor
18
7
  */
19
- export default function runExecutor(options: FirebaseBuildExecutorSchema, context: ExecutorContext): Promise<any>;
8
+ export declare function runExecutor(options: ExecutorOptions, context: ExecutorContext): AsyncGenerator<{
9
+ success: boolean;
10
+ outfile: string;
11
+ }, void, unknown>;
12
+ export default runExecutor;
@@ -1,200 +1,75 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runExecutor = void 0;
3
4
  const tslib_1 = require("tslib");
4
- //SM: as of nx v12.1.1, we need this patch for ensuring the correct workspace is set in e2e runs
5
- // See: https://github.com/nrwl/nx/issues/5065
6
- require("../../utils/e2ePatch");
5
+ require("../../utils/e2ePatch"); // intentional side effects
7
6
  const devkit_1 = require("@nrwl/devkit");
8
- const project_graph_1 = require("@nrwl/workspace/src/core/project-graph");
9
- const assets_1 = require("@nrwl/workspace/src/utilities/assets");
10
- const buildable_libs_utils_1 = require("@nrwl/workspace/src/utilities/buildable-libs-utils");
11
- //SM: Much of our build executor is based on @nrwl/node:package executor
12
- const compile_typescript_files_1 = require("./node/package/utils/compile-typescript-files");
13
- const update_package_json_1 = require("./node/package/utils/update-package-json");
14
- const normalize_options_1 = require("./node/package/utils/normalize-options");
15
- const cli_1 = require("./node/package/utils/cli");
16
- const workspace_1 = require("@nrwl/workspace");
17
- const fs_extra_1 = require("fs-extra");
18
- const fileutils_1 = require("@nrwl/workspace/src/utilities/fileutils");
19
- const ENABLE_DEBUG = false;
20
- function debugLog(...args) {
21
- if (ENABLE_DEBUG) {
22
- console.log(args);
23
- }
24
- }
7
+ const tsc_impl_1 = require("@nrwl/js/src/executors/tsc/tsc.impl");
8
+ const lib_1 = require("./lib");
9
+ const utils_1 = require("../../utils");
25
10
  /**
26
- * Custom Firebase Functions "Application" nx build exector
27
- * Based on @nrwl/node:package executor
28
- *
29
- * - Builds the current application as a Typescript package library for Firebase functions
30
- * - Copies any dependent libraries to the dist folder
31
- * - Auto generates the firebase functions package.json
32
- * - Updates the firebase functions package.json to convert library dependency references to local file references
33
- *
34
- * After building, the project can be deployed using the firebase CLI as usual
35
- *
36
- * @param options
37
- * @param context
38
- * @returns build success/failure outcome
11
+ * @simondotm/nx-firebase:build executor is a
12
+ * customized version of @nrwl/js:tsc executor
39
13
  */
40
14
  function runExecutor(options, context) {
41
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
42
- debugLog("Running Executor for Firebase Build for project '" + context.projectName + "'");
43
- debugLog('options=', options);
44
- // get the project graph; returns an object containing all nodes in the workspace, files, and dependencies
45
- const projGraph = project_graph_1.createProjectGraph();
46
- // nx firebase functions are essentially @nrwl/node:package libraries, but are added to the project
47
- // as applications as they are fundamentally the deployable "application" output of a build pipeline.
48
- // Due to this, we can import standard node libraries as dependencies from within the workspace
49
- // however, they must be created as "buildable" node libraries, because we have to ensure the
50
- // firebase CLI can reference these libraries locally from within the dist folder when they are deployed.
51
- const appRoot = context.workspace.projects[context.projectName].root;
52
- const normalizedOptions = normalize_options_1.default(options, context, appRoot);
53
- //SM: note that the dependency search matches only buildable nodes in the tree
54
- // also, it matches candidate deps by targetName, so if your executor is called something other than "build" it wont find
55
- // any dependencies. Took me a few hours to figure that one out.
56
- const { target, dependencies } = buildable_libs_utils_1.calculateProjectDependencies(projGraph, context.root, context.projectName, context.targetName, context.configurationName);
57
- // ensure dependent libraries exist (ie. have been built at least once)
58
- // note that this check does not check if they are out of date. Not quite sure yet how to do that, but --with-deps will always work.
59
- const dependentsBuilt = buildable_libs_utils_1.checkDependentProjectsHaveBeenBuilt(context.root, context.projectName, context.targetName, dependencies);
60
- if (!dependentsBuilt) {
61
- throw new Error("Dependent libraries need to be built first. Try adding '--with-deps' CLI option");
62
- }
63
- // clean the output folder first
64
- // this way, if there are any issues with the compilation or dependency checks
65
- // we do not have inconsistent build output left lying around
66
- if (normalizedOptions.deleteOutputPath) {
67
- fs_extra_1.removeSync(normalizedOptions.outputPath);
15
+ return tslib_1.__asyncGenerator(this, arguments, function* runExecutor_1() {
16
+ var e_1, _a;
17
+ (0, utils_1.checkNxVersion)();
18
+ if (process.env.NX_WORKSPACE_ROOT_PATH) {
19
+ devkit_1.logger.warn(`WARNING: @simondotm/nx-firebase plugin is located outside this workspace, NX_WORKSPACE_ROOT_PATH has been set to ${process.env.NX_WORKSPACE_ROOT_PATH}`);
68
20
  }
69
- // there aren't really any assets needed for firebase functions
70
- // but left here for compatibility with node:package
71
- debugLog("- Copying functions assets");
72
- yield assets_1.copyAssetFiles(normalizedOptions.files);
73
- // ensure the output package file has typings and a correct "main" entry point
74
- update_package_json_1.default(normalizedOptions, context);
75
- // Process Firebase Functions dependencies
76
- devkit_1.logger.log("- Processing dependencies for firebase functions app '" + context.projectName + "':");
77
- debugLog("dependencies=" + JSON.stringify(dependencies, null, 3));
78
- // list npm deps first, sorted alphabetically
79
- const npmDeps = dependencies.filter((dep) => dep.node.type !== 'lib').sort((a, b) => a.name.localeCompare(b.name));
80
- for (const d of npmDeps) {
81
- const type = d.node.type;
82
- devkit_1.logger.log(" - Added '" + type + "' dependency '" + d.name + "'");
21
+ /*
22
+ // --updateBuildableProjectDepsInPackageJson is true by default for @nrwl/js:tsc
23
+ // https://nx.dev/packages/js/executors/tsc
24
+ // but we havent programmed our executor schema to match yet, so hack them in here.
25
+ const customOptions: ExecutorOptions = {
26
+ ...options,
27
+ updateBuildableProjectDepsInPackageJson: true,
28
+ clean: true,
83
29
  }
84
- // Sniff out any dependencies of this application that are
85
- // non-buildable libraries
86
- // These won't show up in `dependencies` because they don't have a `build` target
87
- //
88
- // Probably added as user error (done it myself) so better to warn here explicitly
89
- // than ignore it and allow wierd side-effects to happen if we proceed.
90
- const projectDeps = projGraph.dependencies[context.projectName].map((dep) => {
91
- const depName = dep.target;
92
- const node = projGraph.nodes[depName];
93
- return node;
94
- });
95
- const nonBuildableDeps = projectDeps.filter((dep) => {
96
- return ((dep.type === 'lib') && (dep.data.targets['build'] === undefined));
97
- });
98
- //console.log("nonBuildableDeps=", JSON.stringify(nonBuildableDeps, null, 3));
99
- // automatically add any dependencies this application has to the output "package.json"
100
- // this will include both npm imports and workspace library imports
101
- // non-buildable deps will not show up here, but we've captured them already
102
- if (dependencies.length > 0 &&
103
- options.updateBuildableProjectDepsInPackageJson) {
104
- buildable_libs_utils_1.updateBuildableProjectPackageJsonDependencies(context.root, context.projectName, context.targetName, context.configurationName, target, dependencies, normalizedOptions.buildableProjectDepsInPackageJsonType);
30
+ */
31
+ if (process.env.NX_VERBOSE_LOGGING) {
32
+ devkit_1.logger.info(`options=${JSON.stringify(options, null, 3)}`);
105
33
  }
106
- // final custom step for building firebase functions applications is to:
107
- // - identify any workspace library dependencies
108
- // - copy them to the application dist folder
109
- // - update the output "package.json" to use local file references to these libraries
110
- //
111
- // This ensures that:
112
- // - the firebase CLI deploy command will work correctly
113
- // - all code for the functions is self contained with the dist/app/<firebaseapp> folder
114
- // - all local code for the functions will be uploaded to GCP without any need to faff with private npm packages
115
- // create a list of dependencies that are nx workspace libraries, sorted alphabetically
116
- const workspaceDependencies = dependencies.filter((dep) => {
117
- return (dep.node.type === 'lib');
118
- }).sort((a, b) => a.name.localeCompare(b.name));
119
- // copy each of their build outputs in dist to a "libs" sub directory in our application dist output folder
120
- const depLibsDir = 'libs';
121
- const workspaceRoot = context.root;
122
- const localLibraries = {};
123
- for (const dep of workspaceDependencies) {
124
- const localPackageName = dep.name; // the library dependency package name
125
- const localLibraryName = dep.node.name; // the library dependency project name
126
- localLibraries[localPackageName] = dep;
127
- const srcDir = devkit_1.joinPathFragments(workspaceRoot, dep.outputs[0]);
128
- const outDir = devkit_1.joinPathFragments(workspaceRoot, normalizedOptions.outputPath, depLibsDir, localLibraryName);
129
- // we also copy libraries to node_modules in dist, because the Firebase CLI also runs the entry point script during a deploy to determine the exported functions
130
- // however, firebase does NOT upload node_modules to GCP, so we have to make two copies of each dependent local library package
131
- // see: https://firebase.google.com/docs/functions/handle-dependencies
132
- const nodeModulesDir = devkit_1.joinPathFragments(workspaceRoot, normalizedOptions.outputPath, 'node_modules', localPackageName);
133
- try {
134
- debugLog("- Copying dependent workspace library '" + dep.node.name + "' from '" + srcDir + "' to '" + outDir + "'");
135
- debugLog("- Copying dependent workspace library '" + dep.node.name + "' from '" + srcDir + "' to '" + nodeModulesDir + "'");
136
- yield fs_extra_1.copy(srcDir, outDir);
137
- yield fs_extra_1.copy(srcDir, nodeModulesDir);
138
- devkit_1.logger.log(" - Copied 'lib' dependency '" + dep.name + "'");
139
- }
140
- catch (err) {
141
- devkit_1.logger.error(err.message);
142
- }
34
+ // console.log(`NX_WORKSPACE_ROOT_PATH=${process.env.NX_WORKSPACE_ROOT_PATH}`)
35
+ // logger.info(`process.env.CI=${process.env.CI}`)
36
+ // logger.info(`process.env.NX_DAEMON=${process.env.CI}`)
37
+ // // SM: recompute the project graph on every iteration so that --watch will work,
38
+ // // since the context.projectGraph is only a snapshot
39
+ if (options.watch) {
40
+ // const projectGraph = await createProjectGraphAsync()
41
+ yield tslib_1.__await((0, devkit_1.createProjectGraphAsync)()
42
+ // logger.info(JSON.stringify(graph, null, 3))
43
+ );
44
+ // logger.info(JSON.stringify(graph, null, 3))
143
45
  }
144
- const incompatibleNestedDeps = [];
145
- // rewrite references to library packages in the functions package.json
146
- // to be local package references to the copies we made
147
- const functionsPackageFile = `${options.outputPath}/package.json`;
148
- debugLog("- functions PackageFile=" + functionsPackageFile);
149
- const functionsPackageJson = workspace_1.readJsonFile(functionsPackageFile);
150
- const functionsPackageDeps = functionsPackageJson.dependencies;
151
- if (functionsPackageDeps) {
152
- debugLog("- Updating local dependencies for Firebase functions package.json");
153
- for (const d in functionsPackageDeps) {
154
- const localDep = localLibraries[d];
155
- debugLog("- Checking dependency '" + d + "', isLocalDep=" + (localDep !== undefined));
156
- if (localDep) {
157
- const localRef = 'file:' + devkit_1.joinPathFragments('.', 'libs', localDep.node.name);
158
- debugLog(" - Replacing '" + d + "' with '" + localRef + "'");
159
- functionsPackageDeps[d] = localRef;
160
- // detect any incompatible nested libraries
161
- if (d.split('/').length > 2) {
162
- incompatibleNestedDeps.push(d);
163
- }
46
+ try {
47
+ // iterate the tscExecutor generator until it completes
48
+ // this approach allows us to add a custom post-compile process.
49
+ //
50
+ // with --watch enabled, this loop will run until the process terminates
51
+ // https://github.com/nrwl/nx/blob/8bfc0b5527e3ea3acd14e4a11254505f02046d98/packages/js/src/executors/tsc/tsc.impl.ts#L176
52
+ for (var _b = tslib_1.__asyncValues((0, tsc_impl_1.tscExecutor)(options, context)), _c; _c = yield tslib_1.__await(_b.next()), !_c.done;) {
53
+ const output = _c.value;
54
+ // logger.info(output)
55
+ if (output.success) {
56
+ // Post-process Firebase Functions dependencies if compilation succeeded
57
+ yield tslib_1.__await((0, lib_1.firebaseBuildExecutor)(context, options.outputPath));
164
58
  }
59
+ yield yield tslib_1.__await(output);
165
60
  }
166
61
  }
167
- fileutils_1.writeJsonFile(functionsPackageFile, functionsPackageJson);
168
- devkit_1.logger.log("- Updated firebase functions package.json");
169
- debugLog("functions package deps = ", JSON.stringify(functionsPackageDeps, null, 3));
170
- // Final dep check before we compile for:
171
- // 1) non-buildable libraries
172
- // 2) nested libraries generated without `--importPath`
173
- // These are both show-stoppers for successful Firebase functions compilation
174
- // If any bad dependencies were found, report and throw
175
- // Non-buildable library dependencies are a show stopper
176
- // If any bad dependencies were found, report and throw
177
- for (const dep of nonBuildableDeps) {
178
- devkit_1.logger.error("ERROR: Found non-buildable library dependency '" + dep.name + "' in Firebase Application. Imported libraries must be created with `--buildable`.");
179
- }
180
- for (const dep of incompatibleNestedDeps) {
181
- devkit_1.logger.error("ERROR: Found incompatible nested library dependency '" + dep + "' in Firebase Application. Imported nested libraries must be created with `--importPath`.");
182
- }
183
- if (nonBuildableDeps.length || incompatibleNestedDeps.length) {
184
- throw new Error("ERROR: Firebase Application contains references to non-buildable or incompatible nested libraries, please fix in order to proceed with build.");
185
- }
186
- if (options.cli) {
187
- cli_1.default(normalizedOptions, context);
62
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
63
+ finally {
64
+ try {
65
+ if (_c && !_c.done && (_a = _b.return)) yield tslib_1.__await(_a.call(_b));
66
+ }
67
+ finally { if (e_1) throw e_1.error; }
188
68
  }
189
- // Finally, compile the firebase functions Typescript application
190
- // uses the same builder logic as @nrwl/node:package
191
- // since we do not want or need to use webpack for cloud functions
192
- // So that we can support --watch (https://github.com/simondotm/nx-firebase/issues/11)
193
- // We run tsc as the last step, but we disable `deleteOutputPath` so that our previous steps are not deleted.
194
- normalizedOptions.deleteOutputPath = false;
195
- const result = yield compile_typescript_files_1.default(normalizedOptions, context, appRoot, dependencies);
196
- return Object.assign(Object.assign({}, result), { outputPath: normalizedOptions.outputPath });
197
69
  });
198
70
  }
71
+ exports.runExecutor = runExecutor;
72
+ //SM: no idea what this shenanigans is for
73
+ //export default convertNxExecutor(runExecutor);
199
74
  exports.default = runExecutor;
200
75
  //# sourceMappingURL=build.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"build.js","sourceRoot":"","sources":["../../../../../../packages/nx-firebase/src/executors/build/build.ts"],"names":[],"mappings":";;;AAAA,gGAAgG;AAChG,8CAA8C;AAC9C,gCAA6B;AAI7B,yCAA0E;AAC1E,0EAA4E;AAC5E,iEAAsE;AACtE,6FAK4D;AAC5D,wEAAwE;AACxE,4FAAmF;AACnF,kFAAyE;AACzE,8EAAsE;AACtE,kDAAqD;AACrD,+CAA8C;AAC9C,uCAA4C;AAC5C,uEAAuE;AAEvE,MAAM,YAAY,GAAG,KAAK,CAAA;AAC1B,SAAS,QAAQ,CAAC,GAAG,IAAI;IACrB,IAAI,YAAY,EAAE;QACd,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;KACpB;AACL,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,SAA8B,WAAW,CAAC,OAAoC,EAAE,OAAwB;;QACtG,QAAQ,CAAC,mDAAmD,GAAG,OAAO,CAAC,WAAW,GAAG,GAAG,CAAC,CAAC;QAC1F,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;QAE7B,0GAA0G;QAC1G,MAAM,SAAS,GAAG,k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IAAI,sBAAsB,CAAC,MAAM,EAAE;YAC1D,MAAM,IAAI,KAAK,CAAC,+IAA+I,CAAC,CAAA;SACnK;QAGD,IAAI,OAAO,CAAC,GAAG,EAAE;YACf,aAAa,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAC;SAC3C;QAED,iEAAiE;QACjE,oDAAoD;QACpD,kEAAkE;QAElE,sFAAsF;QACtF,6GAA6G;QAC7G,iBAAiB,CAAC,gBAAgB,GAAG,KAAK,CAAC;QAC3C,MAAM,MAAM,GAAG,MAAM,kCAAsB,CACzC,iBAAiB,EACjB,OAAO,EACP,OAAO,EACP,YAAY,CACb,CAAC;QAEF,uCACK,MAAM,KACT,UAAU,EAAE,iBAAiB,CAAC,UAAU,IACxC;IAGJ,CAAC;CAAA;AAlOD,8BAkOC"}
1
+ {"version":3,"file":"build.js","sourceRoot":"","sources":["../../../../../../packages/nx-firebase/src/executors/build/build.ts"],"names":[],"mappings":";;;;AAAA,gCAA6B,CAAC,2BAA2B;AACzD,yCAA+E;AAE/E,kEAAiE;AACjE,+BAA6C;AAC7C,uCAA4C;AAE5C;;;GAGG;AACH,SAAuB,WAAW,CAChC,OAAwB,EACxB,OAAwB;;;QAExB,IAAA,sBAAc,GAAE,CAAA;QAEhB,IAAI,OAAO,CAAC,GAAG,CAAC,sBAAsB,EAAE;YACtC,eAAM,CAAC,IAAI,CACT,oHAAoH,OAAO,CAAC,GAAG,CAAC,sBAAsB,EAAE,CACzJ,CAAA;SACF;QAED;;;;;;;;;UASE;QACF,IAAI,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE;YAClC,eAAM,CAAC,IAAI,CAAC,WAAW,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAA;SAC3D;QAED,8EAA8E;QAE9E,kDAAkD;QAClD,yDAAyD;QAEzD,mFAAmF;QACnF,wDAAwD;QACxD,IAAI,OAAO,CAAC,KAAK,EAAE;YACjB,uDAAuD;YACvD,sBAAM,IAAA,gCAAuB,GAAE;YAC/B,8CAA8C;aADf,CAAA;YAC/B,8CAA8C;SAC/C;;YAED,uDAAuD;YACvD,gEAAgE;YAChE,EAAE;YACF,wEAAwE;YACxE,0HAA0H;YAC1H,KAA2B,IAAA,KAAA,sBAAA,IAAA,sBAAW,EAAC,OAAO,EAAE,OAAO,CAAC,CAAA,IAAA;gBAA7C,MAAM,MAAM,WAAA,CAAA;gBACrB,sBAAsB;gBACtB,IAAI,MAAM,CAAC,OAAO,EAAE;oBAClB,wEAAwE;oBACxE,sBAAM,IAAA,2BAAqB,EAAC,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,CAAA,CAAA;iBACzD;gBACD,4BAAM,MAAM,CAAA,CAAA;aACb;;;;;;;;;IACH,CAAC;CAAA;AApDD,kCAoDC;AAED,0CAA0C;AAC1C,gDAAgD;AAChD,kBAAe,WAAW,CAAA"}
@@ -0,0 +1,3 @@
1
+ import { DependentBuildableProjectNode } from '@nrwl/workspace/src/utilities/buildable-libs-utils';
2
+ export declare const FIREBASE_DEPS_DIR = "libs";
3
+ export declare function copyFirebaseDependencies(outputPath: string, workspaceRoot: string, projectDependencies: DependentBuildableProjectNode[]): Promise<Record<string, DependentBuildableProjectNode>>;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.copyFirebaseDependencies = exports.FIREBASE_DEPS_DIR = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const devkit_1 = require("@nrwl/devkit");
6
+ const fs_extra_1 = require("fs-extra");
7
+ exports.FIREBASE_DEPS_DIR = 'libs';
8
+ function copyFirebaseDependencies(outputPath, workspaceRoot, projectDependencies) {
9
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
10
+ // final custom step for building firebase functions applications is to:
11
+ // - identify any workspace library dependencies
12
+ // - copy them to the application dist folder
13
+ // - update the output "package.json" to use local file references to these libraries
14
+ //
15
+ // This ensures that:
16
+ // - the firebase CLI deploy command will work correctly
17
+ // - all code for the functions is self contained with the dist/app/<firebaseapp> folder
18
+ // - all local code for the functions will be uploaded to GCP without any need to faff with private npm packages
19
+ // copy each of their build outputs in dist to a "libs" sub directory in our application dist output folder
20
+ const localLibraries = {};
21
+ for (const dep of projectDependencies) {
22
+ const localPackageName = dep.name; // the library dependency package name
23
+ const localLibraryName = dep.node.name; // the library dependency project name
24
+ localLibraries[localPackageName] = dep;
25
+ const srcDir = (0, devkit_1.joinPathFragments)(workspaceRoot, dep.outputs[0]);
26
+ const outDir = (0, devkit_1.joinPathFragments)(workspaceRoot, outputPath, exports.FIREBASE_DEPS_DIR, localLibraryName);
27
+ // we also copy libraries to node_modules in dist, because the Firebase CLI also runs the entry point script during a deploy to determine the exported functions
28
+ // however, firebase does NOT upload node_modules to GCP, so we have to make two copies of each dependent local library package
29
+ // see: https://firebase.google.com/docs/functions/handle-dependencies
30
+ // SM: Nov'22, this policy has changed - local libs should NOT be in the `node_modules` folder.
31
+ // https://firebase.google.com/docs/functions/handle-dependencies#including_local_nodejs_modules
32
+ // SM: Dec'22, this is not correct, we DO need to copy to `node_modules` also, because the firebase CLI script
33
+ // uses `require(distDir)` to determine the entry point, and nodeJS require has to be able to resolve our libs to the local node_modules
34
+ // however, for external deps like `firebase-functions` nodeJS will not find it here, but will move up a folder until it hits our nx root node_modules
35
+ const nodeModulesDir = (0, devkit_1.joinPathFragments)(workspaceRoot, outputPath, 'node_modules', localPackageName);
36
+ try {
37
+ if (process.env.NX_VERBOSE_LOGGING) {
38
+ devkit_1.logger.info(`- Copying dependent workspace library '${dep.node.name}' from '${srcDir}' to '${outDir}'`);
39
+ devkit_1.logger.info(`- Copying dependent workspace library '${dep.node.name}' from '${srcDir}' to '${nodeModulesDir}'`);
40
+ }
41
+ yield (0, fs_extra_1.copy)(srcDir, outDir);
42
+ yield (0, fs_extra_1.copy)(srcDir, nodeModulesDir);
43
+ devkit_1.logger.log(` - Copied 'lib' dependency '${dep.name}'`);
44
+ }
45
+ catch (err) {
46
+ devkit_1.logger.error(err.message);
47
+ }
48
+ }
49
+ return localLibraries;
50
+ });
51
+ }
52
+ exports.copyFirebaseDependencies = copyFirebaseDependencies;
53
+ //# sourceMappingURL=copy-dependencies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copy-dependencies.js","sourceRoot":"","sources":["../../../../../../../packages/nx-firebase/src/executors/build/lib/copy-dependencies.ts"],"names":[],"mappings":";;;;AAAA,yCAAwD;AAExD,uCAA+B;AAElB,QAAA,iBAAiB,GAAG,MAAM,CAAA;AAEvC,SAAsB,wBAAwB,CAC5C,UAAkB,EAClB,aAAqB,EACrB,mBAAoD;;QAEpD,wEAAwE;QACxE,gDAAgD;QAChD,6CAA6C;QAC7C,qFAAqF;QACrF,EAAE;QACF,qBAAqB;QACrB,wDAAwD;QACxD,wFAAwF;QACxF,gHAAgH;QAEhH,2GAA2G;QAC3G,MAAM,cAAc,GAAkD,EAAE,CAAA;QACxE,KAAK,MAAM,GAAG,IAAI,mBAAmB,EAAE;YACrC,MAAM,gBAAgB,GAAG,GAAG,CAAC,IAAI,CAAA,CAAC,sCAAsC;YACxE,MAAM,gBAAgB,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,CAAA,CAAC,sCAAsC;YAC7E,cAAc,CAAC,gBAAgB,CAAC,GAAG,GAAG,CAAA;YACtC,MAAM,MAAM,GAAG,IAAA,0BAAiB,EAAC,aAAa,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;YAC/D,MAAM,MAAM,GAAG,IAAA,0BAAiB,EAC9B,aAAa,EACb,UAAU,EACV,yBAAiB,EACjB,gBAAgB,CACjB,CAAA;YACD,gKAAgK;YAChK,+HAA+H;YAC/H,sEAAsE;YACtE,+FAA+F;YAC/F,gGAAgG;YAChG,8GAA8G;YAC9G,wIAAwI;YACxI,sJAAsJ;YAEtJ,MAAM,cAAc,GAAG,IAAA,0BAAiB,EACtC,aAAa,EACb,UAAU,EACV,cAAc,EACd,gBAAgB,CACjB,CAAA;YACD,IAAI;gBACF,IAAI,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE;oBAClC,eAAM,CAAC,IAAI,CACT,0CAA0C,GAAG,CAAC,IAAI,CAAC,IAAI,WAAW,MAAM,SAAS,MAAM,GAAG,CAC3F,CAAA;oBACD,eAAM,CAAC,IAAI,CACT,0CAA0C,GAAG,CAAC,IAAI,CAAC,IAAI,WAAW,MAAM,SAAS,cAAc,GAAG,CACnG,CAAA;iBACF;gBACD,MAAM,IAAA,eAAI,EAAC,MAAM,EAAE,MAAM,CAAC,CAAA;gBAC1B,MAAM,IAAA,eAAI,EAAC,MAAM,EAAE,cAAc,CAAC,CAAA;gBAClC,eAAM,CAAC,GAAG,CAAC,+BAA+B,GAAG,CAAC,IAAI,GAAG,CAAC,CAAA;aACvD;YAAC,OAAO,GAAG,EAAE;gBACZ,eAAM,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;aAC1B;SACF;QAED,OAAO,cAAc,CAAA;IACvB,CAAC;CAAA;AA7DD,4DA6DC"}
@@ -0,0 +1,2 @@
1
+ import { ExecutorContext } from '@nrwl/devkit';
2
+ export declare function firebaseBuildExecutor(context: ExecutorContext, outputPath: string): Promise<void>;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.firebaseBuildExecutor = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const copy_dependencies_1 = require("./copy-dependencies");
6
+ const get_dependencies_1 = require("./get-dependencies");
7
+ const rewrite_package_1 = require("./rewrite-package");
8
+ function firebaseBuildExecutor(context, outputPath) {
9
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
10
+ const firebaseDependencies = yield (0, get_dependencies_1.getFirebaseDependencies)(context);
11
+ const localLibraries = yield (0, copy_dependencies_1.copyFirebaseDependencies)(outputPath, context.root, firebaseDependencies.projectDependencies);
12
+ (0, rewrite_package_1.rewriteFirebasePackage)(outputPath, localLibraries);
13
+ });
14
+ }
15
+ exports.firebaseBuildExecutor = firebaseBuildExecutor;
16
+ //# sourceMappingURL=firebase-build.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"firebase-build.js","sourceRoot":"","sources":["../../../../../../../packages/nx-firebase/src/executors/build/lib/firebase-build.ts"],"names":[],"mappings":";;;;AAEA,2DAA8D;AAC9D,yDAA4D;AAC5D,uDAA0D;AAE1D,SAAsB,qBAAqB,CACzC,OAAwB,EACxB,UAAkB;;QAElB,MAAM,oBAAoB,GAAG,MAAM,IAAA,0CAAuB,EAAC,OAAO,CAAC,CAAA;QACnE,MAAM,cAAc,GAAG,MAAM,IAAA,4CAAwB,EACnD,UAAU,EACV,OAAO,CAAC,IAAI,EACZ,oBAAoB,CAAC,mBAAmB,CACzC,CAAA;QACD,IAAA,wCAAsB,EAAC,UAAU,EAAE,cAAc,CAAC,CAAA;IACpD,CAAC;CAAA;AAXD,sDAWC"}
@@ -0,0 +1,8 @@
1
+ import { ExecutorContext, ProjectGraphProjectNode } from '@nrwl/devkit';
2
+ import { DependentBuildableProjectNode } from '@nrwl/workspace/src/utilities/buildable-libs-utils';
3
+ export declare type FirebaseDependencies = {
4
+ projectDependencies: DependentBuildableProjectNode[];
5
+ npmDependencies: DependentBuildableProjectNode[];
6
+ target: ProjectGraphProjectNode<unknown>;
7
+ };
8
+ export declare function getFirebaseDependencies(context: ExecutorContext): Promise<FirebaseDependencies>;