isolate-package 1.0.0-beta.3 → 1.0.0-beta.4
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 +37 -62
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,8 +13,8 @@ a try.
|
|
|
13
13
|
|
|
14
14
|
This solution was developed out of a desire to deploy to
|
|
15
15
|
[Firebase](https://firebase.google.com/) from a monorepo without resorting to
|
|
16
|
-
hacks, shell scripts and manual tasks.
|
|
17
|
-
[here](
|
|
16
|
+
hacks, shell scripts and manual tasks. I have written an article explaining the
|
|
17
|
+
issue [here](https://medium.com/p/e685de39025e).
|
|
18
18
|
|
|
19
19
|
There is nothing Firebase specific to this solution but I am currently not aware
|
|
20
20
|
of other reasons to isolate a workspace package. If you find a different
|
|
@@ -22,12 +22,12 @@ use-case, I would love to hear about it.
|
|
|
22
22
|
|
|
23
23
|
## Features
|
|
24
24
|
|
|
25
|
-
- Zero-config for the majority of use-cases, with no manual steps involved.
|
|
25
|
+
- Zero-config for the vast majority of use-cases, with no manual steps involved.
|
|
26
26
|
- Designed to support NPM, Yarn and PNPM workspaces.
|
|
27
|
-
- Compatible with the Firebase CLI.
|
|
28
|
-
- Uses a pack/unpack approach to only
|
|
29
|
-
|
|
30
|
-
files.
|
|
27
|
+
- Compatible with the Firebase tools CLI.
|
|
28
|
+
- Uses a pack/unpack approach to isolate only those files that would have been
|
|
29
|
+
part of a published package, so the resulting output contains a minimal amount
|
|
30
|
+
of files.
|
|
31
31
|
- Isolates dependencies recursively. If package A depends on local package B
|
|
32
32
|
which depends on local package C, all of them will be isolated.
|
|
33
33
|
- Include and (in the case of PNPM) update the lockfile so the isolated
|
|
@@ -36,19 +36,20 @@ use-case, I would love to hear about it.
|
|
|
36
36
|
|
|
37
37
|
## Usage
|
|
38
38
|
|
|
39
|
-
Run `
|
|
39
|
+
Run `npm install isolate-package --dev` or do the equivalent for `yarn` or
|
|
40
|
+
`pnpm`.
|
|
40
41
|
|
|
41
42
|
This package exposes the `isolate` executable. Once installed you can run `npx
|
|
42
|
-
isolate` in any package directory _after_ you have build the source files
|
|
43
|
-
|
|
43
|
+
isolate` in any package directory _after_ you have build the source files. By
|
|
44
|
+
default this will produce a directory at `./isolate` but this can be configured.
|
|
44
45
|
|
|
45
46
|
You will probably want to add the output directory to your `.gitignore` file.
|
|
46
47
|
|
|
47
|
-
###
|
|
48
|
+
### Deploying to Firebase
|
|
48
49
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
You can deploy to Firebase from multiple packages in your monorepo, so I advise
|
|
51
|
+
you to co-locate your `firebase.json` file with the source code, and not place
|
|
52
|
+
it in the root of the monorepo.
|
|
52
53
|
|
|
53
54
|
In order to deploy to Firebase, the `functions.source` setting in
|
|
54
55
|
`firebase.json` needs to point to the isolated output folder, which would be
|
|
@@ -56,9 +57,10 @@ In order to deploy to Firebase, the `functions.source` setting in
|
|
|
56
57
|
|
|
57
58
|
The `predeploy` phase should first build and then isolate the output.
|
|
58
59
|
|
|
59
|
-
Here's an example using [Turborepo](https://turbo.build/)
|
|
60
|
+
Here's an example using [Turborepo](https://turbo.build/):
|
|
60
61
|
|
|
61
62
|
```json
|
|
63
|
+
// firebase.json
|
|
62
64
|
{
|
|
63
65
|
"functions": {
|
|
64
66
|
"source": "./isolate",
|
|
@@ -67,8 +69,8 @@ Here's an example using [Turborepo](https://turbo.build/) for the build process:
|
|
|
67
69
|
}
|
|
68
70
|
```
|
|
69
71
|
|
|
70
|
-
With this configuration you can run `firebase deploy --only functions` from
|
|
71
|
-
package
|
|
72
|
+
With this configuration you can then run `firebase deploy --only functions` from
|
|
73
|
+
the package.
|
|
72
74
|
|
|
73
75
|
If you like to deploy to Firebase Functions from multiple packages you will also
|
|
74
76
|
need to configure a unique `codebase` identifier for each of them. For more
|
|
@@ -158,56 +160,29 @@ Type: `string | undefined`, default: `undefined`
|
|
|
158
160
|
When you are not using Typescript you can use this setting to specify where the
|
|
159
161
|
build output files are located.
|
|
160
162
|
|
|
163
|
+
## Troubleshooting
|
|
164
|
+
|
|
165
|
+
If something is not working the first thing to do is add a `isolate.config.json`
|
|
166
|
+
file in the package you are trying to isolate, and set `"logLevel"` to
|
|
167
|
+
`"debug"`. This should give you detailed feedback.
|
|
168
|
+
|
|
169
|
+
In addition you can trigger the isolate manually with `npx isolate` and possibly
|
|
170
|
+
use debug the configuration by setting the env variable before running isolate:
|
|
171
|
+
`ISOLATE_CONFIG_LOG_LEVEL=debug npx isolate`
|
|
172
|
+
|
|
161
173
|
## Lockfiles
|
|
162
174
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
175
|
+
I inspected the NPM lockfiles as well as the Yarn v1 and v3 lockfiles and they
|
|
176
|
+
seem to have a flat structure unrelated to the workspace packages structure, so
|
|
177
|
+
I made the assumption that they can be copied as-is.
|
|
178
|
+
|
|
179
|
+
The PNPM lockfile clearly has a structure describing the different packages by
|
|
180
|
+
their relative paths, and so to correct the lockfile it is adapted before being
|
|
181
|
+
copied to the isolate directory.
|
|
166
182
|
|
|
167
183
|
I am not sure the Firebase deploy pipeline is actually detecting a
|
|
168
184
|
pnpm-lock.yaml file and using PNPM to install packages. This needs to be
|
|
169
|
-
verified
|
|
170
|
-
|
|
171
|
-
I looked at the NPM lockfiles as well as the Yarn v1 and v3 lockfiles and they
|
|
172
|
-
do not seem to have a flat structure unrelated to the workspace packages, so I
|
|
173
|
-
have assumed it is ok to just copy them as-is.
|
|
174
|
-
|
|
175
|
-
## The problem with Firebase in monorepos
|
|
176
|
-
|
|
177
|
-
When deploying to Firebase it expects a folder with source files together with a
|
|
178
|
-
package.json file. This folder will be zipped and uploaded after which Firebase
|
|
179
|
-
will run an npm or yarn install in the cloud as part of the deployment pipeline.
|
|
180
|
-
|
|
181
|
-
In a private monorepo your Firebase package(s) typically have one or more shared
|
|
182
|
-
local dependencies that are never published to NPM. When Firebase tries to look
|
|
183
|
-
up those dependencies from the package.json they can not be found and deployment
|
|
184
|
-
fails.
|
|
185
|
-
|
|
186
|
-
In order to solve this you could try to use a bundler like Webpack to include
|
|
187
|
-
dependencies code in the bundle and then strip those packages from the list in
|
|
188
|
-
the package.json that is sent to Firebase, so doesn't know about them, but this
|
|
189
|
-
strategy quickly falls apart. If the shared packages themselves do not bundle
|
|
190
|
-
all of their dependencies in their build output, then those dependencies will
|
|
191
|
-
still need to be installed, and Firebase wouldn't know about it.
|
|
192
|
-
|
|
193
|
-
Without Firebase natively supporting monorepos, the only solution seems to be to
|
|
194
|
-
bundle each shared workspace dependency in a way that its build output, together
|
|
195
|
-
with its package.json file, becomes part of the overall bundle that is uploaded
|
|
196
|
-
in the Firebase deployment. This way, Firebase can find each shared package
|
|
197
|
-
source code, and also know what dependencies need to be installed to make that
|
|
198
|
-
source code work.
|
|
199
|
-
|
|
200
|
-
There are many different hacks that people have come up with [discussing this
|
|
201
|
-
issue](https://github.com/firebase/firebase-tools/issues/653) but they all seem
|
|
202
|
-
to come down to this:
|
|
203
|
-
|
|
204
|
-
- Copy the shared packages to some deployment folder
|
|
205
|
-
- Create a modified package.json file for the deployment that points all local
|
|
206
|
-
dependencies to the copied files for each shared dependency.
|
|
207
|
-
- Point the Firebase deploy process to that folder
|
|
208
|
-
|
|
209
|
-
The `isolate` process from this solution takes a similar approach but is more
|
|
210
|
-
sophisticated and hides all complexity from the user.
|
|
185
|
+
verified...
|
|
211
186
|
|
|
212
187
|
## Used Terminology
|
|
213
188
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "isolate-package",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.4",
|
|
4
4
|
"description": "Isolate a monorepo package by bundling the build output with its shared workspace packages and lock file to form a self-contained directory.",
|
|
5
5
|
"author": "Thijs Koerselman",
|
|
6
6
|
"license": "MIT",
|