isolate-package 1.9.1 → 1.9.3
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.
- package/README.md +12 -161
- package/docs/firebase.md +131 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
|
|
5
5
|
- [TLDR](#tldr)
|
|
6
6
|
- [Features](#features)
|
|
7
|
-
- [Motivation](#motivation)
|
|
8
7
|
- [Installation](#installation)
|
|
9
8
|
- [Usage](#usage)
|
|
10
9
|
- [Troubleshooting](#troubleshooting)
|
|
@@ -14,23 +13,24 @@
|
|
|
14
13
|
- [Define "files" field in each package manifest](#define-files-field-in-each-package-manifest)
|
|
15
14
|
- [Use a flat structure inside your packages folders](#use-a-flat-structure-inside-your-packages-folders)
|
|
16
15
|
- [Configuration Options](#configuration-options)
|
|
16
|
+
- [logLevel](#loglevel)
|
|
17
|
+
- [forceNpm](#forcenpm)
|
|
17
18
|
- [buildDirName](#builddirname)
|
|
18
|
-
- [excludeLockfile](#excludelockfile)
|
|
19
19
|
- [includeDevDependencies](#includedevdependencies)
|
|
20
|
+
- [pickFromScripts](#pickfromscripts)
|
|
21
|
+
- [omitFromScripts](#omitfromscripts)
|
|
20
22
|
- [isolateDirName](#isolatedirname)
|
|
21
|
-
- [logLevel](#loglevel)
|
|
22
23
|
- [targetPackagePath](#targetpackagepath)
|
|
23
24
|
- [tsconfigPath](#tsconfigpath)
|
|
24
25
|
- [workspacePackages](#workspacepackages)
|
|
25
26
|
- [workspaceRoot](#workspaceroot)
|
|
26
27
|
- [Lockfiles](#lockfiles)
|
|
28
|
+
- [NPM](#npm)
|
|
29
|
+
- [PNPM](#pnpm)
|
|
30
|
+
- [Classic Yarn](#classic-yarn)
|
|
31
|
+
- [Modern Yarn](#modern-yarn)
|
|
27
32
|
- [API](#api)
|
|
28
33
|
- [The internal packages strategy](#the-internal-packages-strategy)
|
|
29
|
-
- [Working with Firebase](#working-with-firebase)
|
|
30
|
-
- [A Quick Start](#a-quick-start)
|
|
31
|
-
- [Deploying from multiple packages](#deploying-from-multiple-packages)
|
|
32
|
-
- [Deploying from the root](#deploying-from-the-root)
|
|
33
|
-
- [Using the Firebase Functions Emulator](#using-the-firebase-functions-emulator)
|
|
34
34
|
|
|
35
35
|
<!-- /TOC -->
|
|
36
36
|
|
|
@@ -57,25 +57,8 @@ integrated, check out [mono-ts](https://github.com/0x80/mono-ts)
|
|
|
57
57
|
- Optionally include devDependencies in the isolated output
|
|
58
58
|
- Optionally pick or omit scripts from the manifest
|
|
59
59
|
- Compatible with the Firebase tools CLI, including 1st and 2nd generation
|
|
60
|
-
Firebase Functions
|
|
61
|
-
|
|
62
|
-
## Motivation
|
|
63
|
-
|
|
64
|
-
This solution was born from a desire to deploy to
|
|
65
|
-
[Firebase](https://firebase.google.com/) from a monorepo without resorting to
|
|
66
|
-
custom shell scripts and other hacks. Here is
|
|
67
|
-
[an article](https://thijs-koerselman.medium.com/deploy-to-firebase-without-the-hacks-e685de39025e)
|
|
68
|
-
explaining the issue in more detail.
|
|
69
|
-
|
|
70
|
-
There is nothing Firebase-specific to this solution and there should be other
|
|
71
|
-
use-cases for it, but that is why this documentation contains some instructions
|
|
72
|
-
related to Firebase.
|
|
73
|
-
|
|
74
|
-
> !! There is now
|
|
75
|
-
> [a fork of firebase-tools](https://github.com/0x80/firebase-tools-with-isolate),
|
|
76
|
-
> where isolate-package is integrated. This is preferred because it simplifies
|
|
77
|
-
> the setup and allows the isolation to run only as part of the deploy process,
|
|
78
|
-
> preserving live code updates when running the local Firebase emulators.
|
|
60
|
+
Firebase Functions. For more information see
|
|
61
|
+
[the Firebase instructions](./docs/firebase.md).
|
|
79
62
|
|
|
80
63
|
## Installation
|
|
81
64
|
|
|
@@ -99,8 +82,8 @@ are not using Typescript.
|
|
|
99
82
|
|
|
100
83
|
By default the isolated output will become available at `./isolate`.
|
|
101
84
|
|
|
102
|
-
If you are here to
|
|
103
|
-
[Firebase quick start guide](#a-quick-start).
|
|
85
|
+
If you are here to improve your Firebase deployments check out the
|
|
86
|
+
[Firebase quick start guide](./docs/firebase.md#a-quick-start).
|
|
104
87
|
|
|
105
88
|
## Troubleshooting
|
|
106
89
|
|
|
@@ -452,135 +435,3 @@ to the Typescript source files, but since the shared code was embedded in the
|
|
|
452
435
|
bundle, they will never be referenced via import statements. So the manifest the
|
|
453
436
|
entry declarations are never used. The reason the packages are included in the
|
|
454
437
|
isolated output is to instruct package manager to install their dependencies.
|
|
455
|
-
|
|
456
|
-
## Working with Firebase
|
|
457
|
-
|
|
458
|
-
> !! There is now
|
|
459
|
-
> [a fork of firebase-tools](https://github.com/0x80/firebase-tools-with-isolate),
|
|
460
|
-
> where isolate-package is integrated. This is preferred because it simplifies
|
|
461
|
-
> the setup and allows the isolation to run only as part of the deploy process,
|
|
462
|
-
> preserving live code updates when running the local Firebase emulators.
|
|
463
|
-
|
|
464
|
-
### A Quick Start
|
|
465
|
-
|
|
466
|
-
If you are not confident that your monorepo setup is solid, you can check out my
|
|
467
|
-
in-dept example at [mono-ts](https://github.com/0x80/mono-ts) where many
|
|
468
|
-
different aspects are discussed and `isolate-package` is used to demonstrate
|
|
469
|
-
Firebase deployments.
|
|
470
|
-
|
|
471
|
-
This section describes the steps required for Firebase deployment, assuming:
|
|
472
|
-
|
|
473
|
-
- You use a fairly typical monorepo setup
|
|
474
|
-
- Your `firebase.json` config lives in the root of the package that you like to
|
|
475
|
-
deploy to Firebase, hereafter referred to as the "target package".
|
|
476
|
-
|
|
477
|
-
If your setup diverges from a traditional one, please continue reading the
|
|
478
|
-
[Prerequisites](#prerequisites) section.
|
|
479
|
-
|
|
480
|
-
1. In the target package, install `isolate-package` and `firebase-tools` by
|
|
481
|
-
running `pnpm add isolate-package firebase-tools -D` or the Yarn / NPM
|
|
482
|
-
equivalent. I tend to install firebase-tools as a devDependency in every
|
|
483
|
-
Firebase package, but you could also use a global install if you prefer that.
|
|
484
|
-
2. In the `firebase.json` config set `"source"` to `"./isolate"` and
|
|
485
|
-
`"predeploy"` to `["turbo build", "isolate"]` or whatever suits your build
|
|
486
|
-
tool. The important part here is that isolate is being executed after the
|
|
487
|
-
build stage.
|
|
488
|
-
3. From the target package folder, you should now be able to deploy with
|
|
489
|
-
`npx firebase deploy`.
|
|
490
|
-
|
|
491
|
-
I recommend keeping a `firebase.json` file inside each Firebase package (as
|
|
492
|
-
opposed to the monorepo root), because it allows you to deploy from multiple
|
|
493
|
-
independent packages. It makes it easy to deploy 1st gen functions next to 2nd
|
|
494
|
-
gen functions, deploy different node versions, and decrease the built output
|
|
495
|
-
size and dependency lists for each package, improving deployment and cold-start
|
|
496
|
-
times.
|
|
497
|
-
|
|
498
|
-
### Deploying from multiple packages
|
|
499
|
-
|
|
500
|
-
You can deploy to Firebase from multiple packages in your monorepo, in which
|
|
501
|
-
case you co-locate your `firebase.json` file with the source code, and not in
|
|
502
|
-
the root of the monorepo. If you do want to keep the firebase config in the
|
|
503
|
-
root, read the instructions for
|
|
504
|
-
[deploying to Firebase from the root](#deploying-to-firebase-from-the-root).
|
|
505
|
-
|
|
506
|
-
In order to deploy to Firebase, the `functions.source` setting in
|
|
507
|
-
`firebase.json` needs to point to the isolated output folder, which would be
|
|
508
|
-
`./isolate` when using the default configuration.
|
|
509
|
-
|
|
510
|
-
The `predeploy` phase should first build and then isolate the output.
|
|
511
|
-
|
|
512
|
-
Here's an example using [Turborepo](https://turbo.build/):
|
|
513
|
-
|
|
514
|
-
```cjson
|
|
515
|
-
// firebase.json
|
|
516
|
-
{
|
|
517
|
-
"functions": {
|
|
518
|
-
"source": "./isolate",
|
|
519
|
-
"predeploy": ["turbo build", "isolate"]
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
```
|
|
523
|
-
|
|
524
|
-
With this configuration you can then run `npx firebase deploy --only functions`
|
|
525
|
-
from the package.
|
|
526
|
-
|
|
527
|
-
If you like to deploy to Firebase Functions from multiple packages you will also
|
|
528
|
-
need to configure a unique `codebase` identifier for each of them. For more
|
|
529
|
-
information,
|
|
530
|
-
[read this](https://firebase.google.com/docs/functions/beta/organize-functions).
|
|
531
|
-
|
|
532
|
-
Make sure your Firebase package adheres to the things mentioned in
|
|
533
|
-
[prerequisites](#prerequisites) and its package manifest contains the field
|
|
534
|
-
`"main"`, or `"module"` if you set `"type": "module"`, so Firebase knows the
|
|
535
|
-
entry point to your source code.
|
|
536
|
-
|
|
537
|
-
### Deploying from the root
|
|
538
|
-
|
|
539
|
-
If, for some reason, you choose to keep the `firebase.json` file in the root of
|
|
540
|
-
the monorepo you will have to place a configuration file called
|
|
541
|
-
`isolate.config.json` in the root with the following content:
|
|
542
|
-
|
|
543
|
-
```cjson
|
|
544
|
-
// isolate.config.json
|
|
545
|
-
{
|
|
546
|
-
"targetPackagePath": "./packages/your-firebase-package"
|
|
547
|
-
}
|
|
548
|
-
```
|
|
549
|
-
|
|
550
|
-
The Firebase configuration should then look something like this:
|
|
551
|
-
|
|
552
|
-
```cjson
|
|
553
|
-
// firebase.json
|
|
554
|
-
{
|
|
555
|
-
"functions": {
|
|
556
|
-
"source": "./packages/your-firebase-package/isolate",
|
|
557
|
-
"predeploy": ["turbo build", "isolate"]
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
```
|
|
561
|
-
|
|
562
|
-
### Using the Firebase Functions Emulator
|
|
563
|
-
|
|
564
|
-
The Firebase functions emulator runs on the code that firebase.json `source`
|
|
565
|
-
points to. Unfortunately, this is the same field as is used for declaring the
|
|
566
|
-
code for deployment, which means the emulator is looking at the isolated output.
|
|
567
|
-
|
|
568
|
-
As a result, any changes to your code have to go through the isolate process in
|
|
569
|
-
order to be picked up by the emulator. In other words, changes do not propagate
|
|
570
|
-
automatically while the emulator is running.
|
|
571
|
-
|
|
572
|
-
The workaround I use at the moment is to create a "emulate" script in the
|
|
573
|
-
package manifest which does the same as the Firebase predeploy, and then starts
|
|
574
|
-
the emulator. For example:
|
|
575
|
-
|
|
576
|
-
`turbo build && isolate && firebase emulators:start --only functions`
|
|
577
|
-
|
|
578
|
-
You will still have to stop and restart the emulator on every code change, which
|
|
579
|
-
is unfortunate of course.
|
|
580
|
-
|
|
581
|
-
A real solution to this would be to integrate isolate-package into the
|
|
582
|
-
firebase-tools `deploy` command, so it is only executed as part of the
|
|
583
|
-
deployment process and the `source` property can still point to the original
|
|
584
|
-
code.
|
|
585
|
-
|
|
586
|
-
I plan to work on this once isolate-package is bit more mature.
|
package/docs/firebase.md
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# Firebase
|
|
2
|
+
|
|
3
|
+
> !! There is
|
|
4
|
+
> [a fork of firebase-tools](https://github.com/0x80/firebase-tools-with-isolate),
|
|
5
|
+
> where isolate-package is integrated.
|
|
6
|
+
|
|
7
|
+
## Motivation
|
|
8
|
+
|
|
9
|
+
This solution was born from a desire to deploy to
|
|
10
|
+
[Firebase](https://firebase.google.com/) from a monorepo without resorting to
|
|
11
|
+
custom shell scripts and other hacks. Here is
|
|
12
|
+
[an article](https://thijs-koerselman.medium.com/deploy-to-firebase-without-the-hacks-e685de39025e)
|
|
13
|
+
explaining the issue in more detail.
|
|
14
|
+
|
|
15
|
+
There is nothing Firebase-specific to this solution and there should be other
|
|
16
|
+
use-cases for it, but that is why this documentation contains some instructions
|
|
17
|
+
related to Firebase.
|
|
18
|
+
|
|
19
|
+
## Firebase Tools With Isolate
|
|
20
|
+
|
|
21
|
+
I recommend using
|
|
22
|
+
[the fork](https://github.com/0x80/firebase-tools-with-isolate) for monorepos
|
|
23
|
+
until it is officially integrated. It not only simplifies the setup but more
|
|
24
|
+
importantly allows `isolate` to run as an integral part of the deployment
|
|
25
|
+
process, so it doesn't affect anything prior to deployment. Because of this, you
|
|
26
|
+
preserve live code updates when running the local Firebase emulators, which I
|
|
27
|
+
think is highly desirable.
|
|
28
|
+
|
|
29
|
+
The fork is almost identical, and the integration with isolate-package does not
|
|
30
|
+
affect any existing functionality, so I do not think there's reason to worry
|
|
31
|
+
about things breaking. I will sync the fork with the upstream firebase-tools on
|
|
32
|
+
a regular basis. The fork versions will match the firebase-tools versions for
|
|
33
|
+
clarity.
|
|
34
|
+
|
|
35
|
+
## A Quick Start
|
|
36
|
+
|
|
37
|
+
If you are not completely confident that your monorepo setup is solid, I advise
|
|
38
|
+
you to check out my in-dept boilerplate at
|
|
39
|
+
[mono-ts](https://github.com/0x80/mono-ts) where many different aspects are
|
|
40
|
+
discussed and `isolate-package` is used to demonstrate Firebase deployments.
|
|
41
|
+
|
|
42
|
+
This section describes the steps required for Firebase deployment, assuming:
|
|
43
|
+
|
|
44
|
+
- You use a fairly typical monorepo setup
|
|
45
|
+
- Your `firebase.json` config lives in the root of the package that you like to
|
|
46
|
+
deploy to Firebase, hereafter referred to as the "target package".
|
|
47
|
+
|
|
48
|
+
If your setup diverges from a traditional one, please continue reading the
|
|
49
|
+
[Prerequisites](#prerequisites) section.
|
|
50
|
+
|
|
51
|
+
1. In the target package, install `isolate-package` and `firebase-tools` by
|
|
52
|
+
running `pnpm add isolate-package firebase-tools -D` or the Yarn / NPM
|
|
53
|
+
equivalent. I tend to install firebase-tools as a devDependency in every
|
|
54
|
+
Firebase package, but you could also use a global install if you prefer that.
|
|
55
|
+
2. In the `firebase.json` config set `"source"` to `"./isolate"` and
|
|
56
|
+
`"predeploy"` to `["turbo build", "isolate"]` or whatever suits your build
|
|
57
|
+
tool. The important part here is that isolate is being executed after the
|
|
58
|
+
build stage.
|
|
59
|
+
3. From the target package folder, you should now be able to deploy with
|
|
60
|
+
`npx firebase deploy`.
|
|
61
|
+
|
|
62
|
+
I recommend keeping a `firebase.json` file inside each Firebase package (as
|
|
63
|
+
opposed to the monorepo root), because it allows you to deploy from multiple
|
|
64
|
+
independent packages. It makes it easy to deploy 1st gen functions next to 2nd
|
|
65
|
+
gen functions, deploy different node versions, and decrease the built output
|
|
66
|
+
size and dependency lists for each package, improving deployment and cold-start
|
|
67
|
+
times.
|
|
68
|
+
|
|
69
|
+
## Deploying from multiple packages
|
|
70
|
+
|
|
71
|
+
You can deploy to Firebase from multiple packages in your monorepo, in which
|
|
72
|
+
case you co-locate your `firebase.json` file with the source code, and not in
|
|
73
|
+
the root of the monorepo. If you do want to keep the firebase config in the
|
|
74
|
+
root, read the instructions for
|
|
75
|
+
[deploying to Firebase from the root](#deploying-to-firebase-from-the-root).
|
|
76
|
+
|
|
77
|
+
In order to deploy to Firebase, the `functions.source` setting in
|
|
78
|
+
`firebase.json` needs to point to the isolated output folder, which would be
|
|
79
|
+
`./isolate` when using the default configuration.
|
|
80
|
+
|
|
81
|
+
The `predeploy` phase should first build and then isolate the output.
|
|
82
|
+
|
|
83
|
+
Here's an example using [Turborepo](https://turbo.build/):
|
|
84
|
+
|
|
85
|
+
```cjson
|
|
86
|
+
// firebase.json
|
|
87
|
+
{
|
|
88
|
+
"functions": {
|
|
89
|
+
"source": "./isolate",
|
|
90
|
+
"predeploy": ["turbo build", "isolate"]
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
With this configuration you can then run `npx firebase deploy --only functions`
|
|
96
|
+
from the package.
|
|
97
|
+
|
|
98
|
+
If you like to deploy to Firebase Functions from multiple packages you will also
|
|
99
|
+
need to configure a unique `codebase` identifier for each of them. For more
|
|
100
|
+
information,
|
|
101
|
+
[read this](https://firebase.google.com/docs/functions/beta/organize-functions).
|
|
102
|
+
|
|
103
|
+
Make sure your Firebase package adheres to the things mentioned in
|
|
104
|
+
[prerequisites](#prerequisites) and its package manifest contains the field
|
|
105
|
+
`"main"`, or `"module"` if you set `"type": "module"`, so Firebase knows the
|
|
106
|
+
entry point to your source code.
|
|
107
|
+
|
|
108
|
+
## Deploying from the root
|
|
109
|
+
|
|
110
|
+
If, for some reason, you choose to keep the `firebase.json` file in the root of
|
|
111
|
+
the monorepo you will have to place a configuration file called
|
|
112
|
+
`isolate.config.json` in the root with the following content:
|
|
113
|
+
|
|
114
|
+
```cjson
|
|
115
|
+
// isolate.config.json
|
|
116
|
+
{
|
|
117
|
+
"targetPackagePath": "./packages/your-firebase-package"
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
The Firebase configuration should then look something like this:
|
|
122
|
+
|
|
123
|
+
```cjson
|
|
124
|
+
// firebase.json
|
|
125
|
+
{
|
|
126
|
+
"functions": {
|
|
127
|
+
"source": "./packages/your-firebase-package/isolate",
|
|
128
|
+
"predeploy": ["turbo build", "isolate"]
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "isolate-package",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.3",
|
|
4
4
|
"description": "Isolate a monorepo package with its shared dependencies to form a self-contained directory, compatible with Firebase deploy",
|
|
5
5
|
"author": "Thijs Koerselman",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
".": "./dist/index.mjs"
|
|
29
29
|
},
|
|
30
30
|
"files": [
|
|
31
|
-
"dist"
|
|
31
|
+
"dist",
|
|
32
|
+
"docs"
|
|
32
33
|
],
|
|
33
34
|
"bin": {
|
|
34
35
|
"isolate": "dist/isolate-bin.mjs"
|