isolate-package 1.27.0 → 1.28.1
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 +20 -420
- package/dist/index.d.mts +13 -5
- package/dist/index.mjs +21 -2
- package/dist/index.mjs.map +1 -0
- package/dist/{isolate-B11ztsrI.mjs → isolate-D-Qd5BJJ.mjs} +114 -25
- package/dist/isolate-D-Qd5BJJ.mjs.map +1 -0
- package/dist/isolate-bin.mjs +1 -1
- package/dist/isolate-bin.mjs.map +1 -1
- package/package.json +37 -32
- package/src/get-internal-package-names.test.ts +213 -0
- package/src/get-internal-package-names.ts +38 -0
- package/src/index.ts +3 -5
- package/src/isolate-bin.ts +1 -1
- package/src/isolate.ts +21 -31
- package/src/lib/cli.test.ts +3 -3
- package/src/lib/cli.ts +4 -4
- package/src/lib/config.test.ts +163 -0
- package/src/lib/config.ts +134 -8
- package/src/lib/lockfile/helpers/generate-pnpm-lockfile.ts +6 -6
- package/src/lib/lockfile/helpers/pnpm-map-importer.ts +5 -5
- package/src/lib/lockfile/process-lockfile.ts +3 -3
- package/src/lib/manifest/adapt-target-package-manifest.ts +2 -2
- package/src/lib/manifest/helpers/adapt-internal-package-manifests.ts +3 -3
- package/src/lib/manifest/helpers/adapt-manifest-internal-deps.ts +2 -2
- package/src/lib/manifest/helpers/adopt-pnpm-fields-from-root.test.ts +1 -1
- package/src/lib/manifest/helpers/adopt-pnpm-fields-from-root.ts +2 -2
- package/src/lib/manifest/helpers/patch-internal-entries.ts +2 -2
- package/src/lib/manifest/helpers/resolve-catalog-dependencies.ts +3 -3
- package/src/lib/manifest/io.ts +2 -2
- package/src/lib/manifest/validate-manifest.test.ts +10 -10
- package/src/lib/manifest/validate-manifest.ts +1 -1
- package/src/lib/output/unpack-dependencies.ts +4 -4
- package/src/lib/package-manager/helpers/infer-from-files.ts +1 -1
- package/src/lib/package-manager/helpers/infer-from-manifest.ts +3 -3
- package/src/lib/package-manager/index.ts +2 -2
- package/src/lib/patches/copy-patches.test.ts +7 -7
- package/src/lib/patches/copy-patches.ts +5 -5
- package/src/lib/registry/create-packages-registry.ts +12 -14
- package/src/lib/registry/helpers/find-packages-globs.ts +7 -7
- package/src/lib/registry/list-internal-packages.test.ts +291 -0
- package/src/lib/registry/list-internal-packages.ts +70 -18
- package/src/lib/utils/filter-object-undefined.test.ts +1 -1
- package/src/lib/utils/filter-object-undefined.ts +1 -1
- package/src/lib/utils/filter-patched-dependencies.ts +2 -2
- package/src/lib/utils/json.ts +4 -4
- package/src/lib/utils/pack.ts +3 -3
- package/src/lib/utils/yaml.ts +1 -1
- package/dist/isolate-B11ztsrI.mjs.map +0 -1
- package/docs/firebase.md +0 -144
package/README.md
CHANGED
|
@@ -1,433 +1,33 @@
|
|
|
1
1
|
# Isolate Package
|
|
2
2
|
|
|
3
|
-
-
|
|
4
|
-
|
|
5
|
-
- [Installation](#installation)
|
|
6
|
-
- [Usage](#usage)
|
|
7
|
-
- [Troubleshooting](#troubleshooting)
|
|
8
|
-
- [Prerequisites](#prerequisites)
|
|
9
|
-
- [CLI Flags](#cli-flags)
|
|
10
|
-
- [Configuration Options](#configuration-options)
|
|
11
|
-
- [PNPM Patched Dependencies](#pnpm-patched-dependencies)
|
|
12
|
-
- [API](#api)
|
|
13
|
-
- [The internal packages strategy](#the-internal-packages-strategy)
|
|
14
|
-
- [Firebase](#firebase)
|
|
15
|
-
|
|
16
|
-
## Quickstart
|
|
17
|
-
|
|
18
|
-
Run `npx isolate-package isolate` from the monorepo package you would like to
|
|
19
|
-
isolate.
|
|
20
|
-
|
|
21
|
-
If you would like to see an example of a modern monorepo with this tool
|
|
22
|
-
integrated, check out [mono-ts](https://github.com/0x80/mono-ts)
|
|
3
|
+
Isolate a monorepo workspace package into a self-contained directory with all
|
|
4
|
+
internal dependencies and an adapted lockfile.
|
|
23
5
|
|
|
24
6
|
## Features
|
|
25
7
|
|
|
26
|
-
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
-
|
|
30
|
-
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
- Zero-config for the vast majority of use-cases
|
|
34
|
-
- Isolates dependencies recursively. If package A depends on internal package B
|
|
35
|
-
which depends on internal package C, all of them will be included
|
|
36
|
-
- Optionally force output to use NPM with matching versions
|
|
37
|
-
- Optionally include devDependencies in the isolated output
|
|
38
|
-
- Optionally pick or omit scripts from the manifest
|
|
39
|
-
- Automatically copies PNPM patched dependencies to the isolated output
|
|
40
|
-
- Compatible with the Firebase tools CLI, including 1st and 2nd generation
|
|
41
|
-
Firebase Functions. For more information see
|
|
42
|
-
[the Firebase instructions](./docs/firebase.md).
|
|
43
|
-
- Available in a
|
|
44
|
-
[forked version of firebase-tools](https://github.com/0x80/firebase-tools-with-isolate)
|
|
45
|
-
to preserve live code updates when running the emulators
|
|
46
|
-
|
|
47
|
-
## Installation
|
|
48
|
-
|
|
49
|
-
Run `pnpm install isolate-package -D` or the equivalent for `npm` or `yarn`.
|
|
50
|
-
|
|
51
|
-
I recommended using `pnpm` over `npm` or `yarn`. Besides being fast and
|
|
52
|
-
efficient, PNPM has better support for monorepos.
|
|
53
|
-
|
|
54
|
-
## Usage
|
|
55
|
-
|
|
56
|
-
> !! If you plan use this for Firebase deployments, and you want to preserve
|
|
57
|
-
> live code updates when running the local emulators, you will want to use
|
|
58
|
-
> [firebase-tools-with-isolate](https://github.com/0x80/firebase-tools-with-isolate)
|
|
59
|
-
> instead.
|
|
60
|
-
|
|
61
|
-
This package exposes a binary called `isolate`.
|
|
62
|
-
|
|
63
|
-
Run `npx isolate` from the root of the package you want to isolate. Make sure
|
|
64
|
-
you build the package first.
|
|
65
|
-
|
|
66
|
-
The `isolate` binary will try to infer your build output location from a
|
|
67
|
-
`tsconfig` file, but see the [buildDirName configuration](#builddirname) if you
|
|
68
|
-
are not using Typescript.
|
|
69
|
-
|
|
70
|
-
By default the isolated output will become available at `./isolate`.
|
|
71
|
-
|
|
72
|
-
All [configuration options](#configuration-options) can also be set via
|
|
73
|
-
[CLI flags](#cli-flags), which take precedence over the config file.
|
|
74
|
-
|
|
75
|
-
If you are here to improve your Firebase deployments check out the
|
|
76
|
-
[Firebase quick start guide](./docs/firebase.md#a-quick-start).
|
|
77
|
-
|
|
78
|
-
## Troubleshooting
|
|
79
|
-
|
|
80
|
-
If something is not working as expected, run `npx isolate --log-level debug` or
|
|
81
|
-
add an `isolate.config.json` file with `"logLevel"` set to `"debug"`. This
|
|
82
|
-
should give you detailed feedback in the console.
|
|
83
|
-
|
|
84
|
-
In addition define an environment variable to debug the configuration being used
|
|
85
|
-
by setting `DEBUG_ISOLATE_CONFIG=true` before you execute `isolate`.
|
|
86
|
-
|
|
87
|
-
When debugging Firebase deployment issues it might be convenient to trigger the
|
|
88
|
-
isolate process manually with `npx isolate` and possibly
|
|
89
|
-
`DEBUG_ISOLATE_CONFIG=true npx isolate`.
|
|
90
|
-
|
|
91
|
-
## Prerequisites
|
|
92
|
-
|
|
93
|
-
Because historically many different approaches to monorepos exist, we need to
|
|
94
|
-
establish some basic rules for the isolate process to work.
|
|
95
|
-
|
|
96
|
-
### Define shared dependencies in the package manifest
|
|
97
|
-
|
|
98
|
-
This one might sound obvious, but if the `package.json` from the package you are
|
|
99
|
-
targeting does not list the other monorepo packages it depends on, in either the
|
|
100
|
-
`dependencies` or `devDependencies` list, then the isolate process will not
|
|
101
|
-
include them in the output.
|
|
102
|
-
|
|
103
|
-
How dependencies are listed with regards to versioning is not important, because
|
|
104
|
-
packages are matched based on their name. For example the following flavors all
|
|
105
|
-
work (some depending on your package manager):
|
|
106
|
-
|
|
107
|
-
```cjson
|
|
108
|
-
// package.json
|
|
109
|
-
{
|
|
110
|
-
"dependencies": {
|
|
111
|
-
"shared-package": "0.0.0"
|
|
112
|
-
"shared-package": "*",
|
|
113
|
-
"shared-package": "workspace:*",
|
|
114
|
-
"shared-package": "../shared-package",
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
So if the a package name can be found as part of the workspace definition, it
|
|
120
|
-
will be processed regardless of its version specifier.
|
|
121
|
-
|
|
122
|
-
### Define "version" field in each package manifest
|
|
123
|
-
|
|
124
|
-
The `version` field is required for `pack` to execute, because it is use to
|
|
125
|
-
generate part of the packed filename. A personal preference is to set it to
|
|
126
|
-
`"0.0.0"` to indicate that the version does not have any real meaning.
|
|
127
|
-
|
|
128
|
-
### Define "files" field in each package manifest
|
|
129
|
-
|
|
130
|
-
> NOTE: This step is not required if you use the
|
|
131
|
-
> [internal packages strategy](#the-internal-packages-strategy) but you could
|
|
132
|
-
> set it to `["src"]` instead of `["dist"]`.
|
|
133
|
-
>
|
|
134
|
-
> When using `includeDevDependencies`, packages that are only dev dependencies
|
|
135
|
-
> (like ESLint configs or other build tools) don't require a `files` field since
|
|
136
|
-
> they are not packed for deployment.
|
|
137
|
-
|
|
138
|
-
The isolate process uses (p)npm `pack` to extract files from package
|
|
139
|
-
directories, just like publishing a package would.
|
|
140
|
-
|
|
141
|
-
For production dependencies, it is required that you define the `files` property
|
|
142
|
-
in each package manifest, as it declares what files should be included in the
|
|
143
|
-
published output.
|
|
144
|
-
|
|
145
|
-
Typically, the value contains an array with only the name of the build output
|
|
146
|
-
directory. For example:
|
|
147
|
-
|
|
148
|
-
```cjson
|
|
149
|
-
// package.json
|
|
150
|
-
{
|
|
151
|
-
"files": ["dist"]
|
|
152
|
-
}
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
A few additional files from the root of your package will be included
|
|
156
|
-
automatically, like the `package.json`, `LICENSE` and `README` files.
|
|
157
|
-
|
|
158
|
-
**Tip** If you deploy to Firebase
|
|
159
|
-
[2nd generation](https://firebase.google.com/docs/firestore/extend-with-functions-2nd-gen)
|
|
160
|
-
functions, you might want to include some env files in the `files` list, so they
|
|
161
|
-
are packaged and deployed together with your build output (as 1st gen functions
|
|
162
|
-
config is no longer supported).
|
|
163
|
-
|
|
164
|
-
### Use a flat structure inside your packages folders
|
|
165
|
-
|
|
166
|
-
At the moment, nesting packages inside packages is not supported.
|
|
167
|
-
|
|
168
|
-
When building the registry of all internal packages, `isolate` doesn't drill
|
|
169
|
-
down into the folders. So if you declare your packages to live in `packages/*`
|
|
170
|
-
it will only find the packages directly in that folder and not at
|
|
171
|
-
`packages/nested/more-packages`.
|
|
172
|
-
|
|
173
|
-
You can, however, declare multiple workspace packages directories. Personally, I
|
|
174
|
-
prefer to use `["packages/*", "apps/*", "services/*"]`. It is only the structure
|
|
175
|
-
inside them that should be flat.
|
|
176
|
-
|
|
177
|
-
## CLI Flags
|
|
178
|
-
|
|
179
|
-
All configuration options can be passed as CLI flags, which take precedence over
|
|
180
|
-
values in `isolate.config.json`. Run `npx isolate --help` for the full list.
|
|
181
|
-
|
|
182
|
-
| Flag | Short | Type | Config Key |
|
|
183
|
-
| ------------------------------ | ----- | -------- | ------------------------ |
|
|
184
|
-
| `--build-dir-name <name>` | `-b` | string | `buildDirName` |
|
|
185
|
-
| `--include-dev-dependencies` | `-d` | boolean | `includeDevDependencies` |
|
|
186
|
-
| `--isolate-dir-name <name>` | `-o` | string | `isolateDirName` |
|
|
187
|
-
| `--log-level <level>` | `-l` | string | `logLevel` |
|
|
188
|
-
| `--target-package-path <path>` | `-t` | string | `targetPackagePath` |
|
|
189
|
-
| `--tsconfig-path <path>` | `-c` | string | `tsconfigPath` |
|
|
190
|
-
| `--workspace-packages <glob>` | `-w` | string[] | `workspacePackages` |
|
|
191
|
-
| `--workspace-root <path>` | `-r` | string | `workspaceRoot` |
|
|
192
|
-
| `--force-npm` | | boolean | `forceNpm` |
|
|
193
|
-
| `--pick-from-scripts <name>` | `-p` | string[] | `pickFromScripts` |
|
|
194
|
-
| `--omit-from-scripts <name>` | | string[] | `omitFromScripts` |
|
|
195
|
-
| `--omit-package-manager` | | boolean | `omitPackageManager` |
|
|
196
|
-
|
|
197
|
-
Array flags are repeatable, for example:
|
|
198
|
-
`npx isolate --pick-from-scripts build --pick-from-scripts start`
|
|
199
|
-
|
|
200
|
-
Boolean flags support `--no-` negation, for example: `--no-force-npm`.
|
|
201
|
-
|
|
202
|
-
## Configuration Options
|
|
203
|
-
|
|
204
|
-
For most users no configuration should be necessary.
|
|
205
|
-
|
|
206
|
-
You can configure the isolate process by placing a `isolate.config.json` file in
|
|
207
|
-
the package that you want to isolate, except when you're
|
|
208
|
-
[deploying to Firebase from the root of the workspace](#deploying-firebase-from-the-root).
|
|
209
|
-
Alternatively, all options can be set via [CLI flags](#cli-flags).
|
|
210
|
-
|
|
211
|
-
For the config file to be picked up, you will have to execute `isolate` from the
|
|
212
|
-
same location, as it uses the current working directory.
|
|
213
|
-
|
|
214
|
-
Below you will find a description of every available option.
|
|
215
|
-
|
|
216
|
-
### logLevel
|
|
217
|
-
|
|
218
|
-
Type: `"info" | "debug" | "warn" | "error"`, default: `"info"`.
|
|
219
|
-
|
|
220
|
-
Because the configuration loader depends on this setting, its output is not
|
|
221
|
-
affected by this setting. If you want to debug the configuration set
|
|
222
|
-
`DEBUG_ISOLATE_CONFIG=true` before you run `isolate`
|
|
223
|
-
|
|
224
|
-
### forceNpm
|
|
225
|
-
|
|
226
|
-
Type: `boolean`, default: `false`
|
|
8
|
+
- Self-contained output with all internal dependencies included
|
|
9
|
+
- Deterministic lockfile generation for the isolated package
|
|
10
|
+
- Works with NPM, PNPM, Yarn (classic and modern), and partial Bun support
|
|
11
|
+
- Zero-config for the vast majority of use cases
|
|
12
|
+
- Recursive dependency resolution
|
|
13
|
+
- Compatible with Firebase Functions (1st and 2nd generation)
|
|
14
|
+
- Automatic PNPM patched dependencies support
|
|
227
15
|
|
|
228
|
-
|
|
229
|
-
that you are using for your monorepo, but your deployment target might not be
|
|
230
|
-
compatible with that package manager.
|
|
16
|
+
## Quick Start
|
|
231
17
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
By setting this option to `true` you are forcing the isolate output to use NPM.
|
|
236
|
-
A package-lock file will be generated based on the contents of node_modules and
|
|
237
|
-
therefore should match the versions in your original lockfile.
|
|
238
|
-
|
|
239
|
-
This way you can enjoy using PNPM or Yarn for your monorepo, while your
|
|
240
|
-
deployment requires NPM.
|
|
241
|
-
|
|
242
|
-
### buildDirName
|
|
243
|
-
|
|
244
|
-
Type: `string | undefined`, default: `undefined`
|
|
245
|
-
|
|
246
|
-
The name of the build output directory name. When undefined it is automatically
|
|
247
|
-
detected via `tsconfig.json`. When you are not using Typescript you can use this
|
|
248
|
-
setting to specify where the build output files are located.
|
|
249
|
-
|
|
250
|
-
### includeDevDependencies
|
|
251
|
-
|
|
252
|
-
Type: `boolean`, default: `false`
|
|
253
|
-
|
|
254
|
-
By default devDependencies are ignored and stripped from the isolated output
|
|
255
|
-
`package.json` files. If you enable this the devDependencies will be included
|
|
256
|
-
and isolated just like the production dependencies.
|
|
257
|
-
|
|
258
|
-
Note: Dev-only internal packages (like ESLint configs) that are included through
|
|
259
|
-
this option don't require a `files` field in their package.json, only a
|
|
260
|
-
`version` field. Production dependencies always require both `version` and
|
|
261
|
-
`files` fields.
|
|
262
|
-
|
|
263
|
-
### pickFromScripts
|
|
264
|
-
|
|
265
|
-
Type: `string[]`, default: `undefined`
|
|
266
|
-
|
|
267
|
-
Select which scripts to include in the output manifest `scripts` field. For
|
|
268
|
-
example if you want your test script included set it to `["test"]`.
|
|
269
|
-
|
|
270
|
-
By default, all scripts are omitted.
|
|
271
|
-
|
|
272
|
-
### omitFromScripts
|
|
273
|
-
|
|
274
|
-
Type: `string[]`, default: `undefined`
|
|
275
|
-
|
|
276
|
-
Select which scripts to omit from the output manifest `scripts` field. For
|
|
277
|
-
example if you want the build script interferes with your deployment target, but
|
|
278
|
-
you want to preserve all of the other scripts, set it to `["build"]`.
|
|
279
|
-
|
|
280
|
-
By default, all scripts are omitted, and the [pickFromScripts](#pickfromscripts)
|
|
281
|
-
configuration overrules this configuration.
|
|
282
|
-
|
|
283
|
-
### omitPackageManager
|
|
284
|
-
|
|
285
|
-
Type: `boolean`, default: `false`
|
|
286
|
-
|
|
287
|
-
By default the packageManager field from the root manifest is copied to the
|
|
288
|
-
target manifest. I have found that some platforms (Cloud Run, April 2024) can
|
|
289
|
-
fail on this for some reason. This option allows you to omit the field from the
|
|
290
|
-
isolated package manifest.
|
|
291
|
-
|
|
292
|
-
### isolateDirName
|
|
293
|
-
|
|
294
|
-
Type: `string`, default: `"isolate"`
|
|
295
|
-
|
|
296
|
-
The name of the isolate output directory.
|
|
297
|
-
|
|
298
|
-
### targetPackagePath
|
|
299
|
-
|
|
300
|
-
Type: `string`, default: `undefined`
|
|
301
|
-
|
|
302
|
-
Only when you decide to place the isolate configuration in the root of the
|
|
303
|
-
monorepo, you use this setting to point it to the target you want to isolate,
|
|
304
|
-
e.g. `./packages/my-firebase-package`.
|
|
305
|
-
|
|
306
|
-
If this option is used the `workspaceRoot` setting will be ignored and assumed
|
|
307
|
-
to be the current working directory.
|
|
308
|
-
|
|
309
|
-
### tsconfigPath
|
|
310
|
-
|
|
311
|
-
Type: `string`, default: `"./tsconfig.json"`
|
|
312
|
-
|
|
313
|
-
The path to the `tsconfig.json` file relative to the package you want to
|
|
314
|
-
isolate. The tsconfig is only used for reading the `compilerOptions.outDir`
|
|
315
|
-
setting. If no tsconfig is found, possibly because you are not using Typescript
|
|
316
|
-
in your project, the process will fall back to the `buildDirName` setting.
|
|
317
|
-
|
|
318
|
-
### workspacePackages
|
|
319
|
-
|
|
320
|
-
Type: `string[] | undefined`, default: `undefined`
|
|
321
|
-
|
|
322
|
-
When workspacePackages is not defined, `isolate` will try to find the packages
|
|
323
|
-
in the workspace by looking up the settings in `pnpm-workspace.yaml` or
|
|
324
|
-
`package.json` files depending on the detected package manager.
|
|
325
|
-
|
|
326
|
-
In case this fails, you can override this process by specifying globs manually.
|
|
327
|
-
For example `"workspacePackages": ["packages/*", "apps/*"]`. Paths are relative
|
|
328
|
-
from the root of the workspace.
|
|
329
|
-
|
|
330
|
-
### workspaceRoot
|
|
331
|
-
|
|
332
|
-
Type: `string`, default: `"../.."`
|
|
333
|
-
|
|
334
|
-
The relative path to the root of the workspace / monorepo. In a typical setup
|
|
335
|
-
you will have a `packages` directory and possibly also an `apps` and a
|
|
336
|
-
`services` directory, all of which contain packages. So any package you would
|
|
337
|
-
want to isolate is located 2 levels up from the root.
|
|
338
|
-
|
|
339
|
-
For example
|
|
340
|
-
|
|
341
|
-
```
|
|
342
|
-
packages
|
|
343
|
-
├─ backend
|
|
344
|
-
│ └─ package.json
|
|
345
|
-
└─ ui
|
|
346
|
-
└─ package.json
|
|
347
|
-
apps
|
|
348
|
-
├─ admin
|
|
349
|
-
│ └─ package.json
|
|
350
|
-
└─ web
|
|
351
|
-
└─ package.json
|
|
352
|
-
services
|
|
353
|
-
└─ api
|
|
354
|
-
└─ package.json
|
|
355
|
-
|
|
356
|
-
```
|
|
357
|
-
|
|
358
|
-
When you use the `targetPackagePath` option, this setting will be ignored.
|
|
359
|
-
|
|
360
|
-
## PNPM Patched Dependencies
|
|
361
|
-
|
|
362
|
-
If your workspace uses PNPM's [patched dependencies](https://pnpm.io/cli/patch)
|
|
363
|
-
feature, `isolate` will automatically copy the relevant patch files to the
|
|
364
|
-
isolated output.
|
|
365
|
-
|
|
366
|
-
Patches are filtered based on the target package's dependencies:
|
|
367
|
-
|
|
368
|
-
- Patches for production dependencies are always included
|
|
369
|
-
- Patches for dev dependencies are only included when `includeDevDependencies`
|
|
370
|
-
is enabled
|
|
371
|
-
- Patches for packages not in the target's dependency tree are excluded
|
|
372
|
-
|
|
373
|
-
The patch files are copied to the isolated output, preserving their original
|
|
374
|
-
directory structure. Both the `package.json` and `pnpm-lock.yaml` are updated
|
|
375
|
-
with the correct paths.
|
|
376
|
-
|
|
377
|
-
## API
|
|
378
|
-
|
|
379
|
-
Alternatively, `isolate` can be integrated in other programs by importing it as
|
|
380
|
-
a function. You optionally pass it a some user configuration and possibly a
|
|
381
|
-
logger to handle any output messages should you need to write them to a
|
|
382
|
-
different location as the standard `node:console`.
|
|
383
|
-
|
|
384
|
-
```ts
|
|
385
|
-
import { isolate } from "isolate-package";
|
|
386
|
-
|
|
387
|
-
await isolate({
|
|
388
|
-
config: { logLevel: "debug" },
|
|
389
|
-
logger: customLogger,
|
|
390
|
-
});
|
|
18
|
+
```sh
|
|
19
|
+
npx isolate-package isolate
|
|
391
20
|
```
|
|
392
21
|
|
|
393
|
-
|
|
394
|
-
`isolate.config.json` from the current working directory.
|
|
395
|
-
|
|
396
|
-
## The internal packages strategy
|
|
397
|
-
|
|
398
|
-
An alternative approach to using internal dependencies in a Typescript monorepo
|
|
399
|
-
is
|
|
400
|
-
[the internal packages strategy](https://turbo.build/blog/you-might-not-need-typescript-project-references),
|
|
401
|
-
in which the package manifest entries point directly to Typescript source files,
|
|
402
|
-
to omit intermediate build steps. The approach is compatible with
|
|
403
|
-
isolate-package and showcased in
|
|
404
|
-
[my example monorepo setup](https://github.com/0x80/mono-ts)
|
|
405
|
-
|
|
406
|
-
In summary this is how it works:
|
|
407
|
-
|
|
408
|
-
1. The package to be deployed lists its internal dependencies as usual, but the
|
|
409
|
-
package manifests of those dependencies point directly to the Typescript
|
|
410
|
-
source (and types).
|
|
411
|
-
2. You configure the bundler of your target package to include the source code
|
|
412
|
-
for those internal packages in its output bundle. In the case of TSUP for the
|
|
413
|
-
[API service in the mono-ts](https://github.com/0x80/mono-ts/blob/main/services/api/tsup.config.ts)
|
|
414
|
-
that configuration is: `noExternal: ["@mono/common"]`
|
|
415
|
-
3. When `isolate` runs, it does the same thing as always. It detects the
|
|
416
|
-
internal packages, copies them to the isolate output folder and adjusts any
|
|
417
|
-
links.
|
|
418
|
-
4. When deploying to Firebase, the cloud pipeline will treat the package
|
|
419
|
-
manifest as usual, which installs the listed dependencies and any
|
|
420
|
-
dependencies listed in the linked internal package manifests.
|
|
22
|
+
Run the command from the monorepo package you would like to isolate.
|
|
421
23
|
|
|
422
|
-
|
|
24
|
+
## Documentation
|
|
423
25
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
isolated output is to instruct package manager to install their dependencies.
|
|
26
|
+
For full documentation visit
|
|
27
|
+
[isolate-package.codecompose.dev](https://isolate-package.codecompose.dev/). See
|
|
28
|
+
also:
|
|
29
|
+
[Comparison with pnpm deploy](https://isolate-package.codecompose.dev/comparison).
|
|
429
30
|
|
|
430
|
-
##
|
|
31
|
+
## License
|
|
431
32
|
|
|
432
|
-
|
|
433
|
-
Firebase [see this documentation](./docs/firebase.md#firebase)
|
|
33
|
+
MIT
|
package/dist/index.d.mts
CHANGED
|
@@ -27,15 +27,23 @@ type IsolateConfigResolved = {
|
|
|
27
27
|
omitPackageManager?: boolean;
|
|
28
28
|
};
|
|
29
29
|
type IsolateConfig = Partial<IsolateConfigResolved>;
|
|
30
|
+
/** Helper for type-safe configuration in isolate.config.ts files. */
|
|
31
|
+
declare function defineConfig(config: IsolateConfig): IsolateConfig;
|
|
30
32
|
//#endregion
|
|
31
33
|
//#region src/isolate.d.ts
|
|
32
34
|
/** Keep the original function for backward compatibility */
|
|
33
35
|
declare function isolate(config?: IsolateConfig): Promise<string>;
|
|
34
36
|
//#endregion
|
|
35
|
-
//#region src/
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
//#region src/get-internal-package-names.d.ts
|
|
38
|
+
/**
|
|
39
|
+
* Get the names of all internal workspace packages that the target package
|
|
40
|
+
* depends on. This is useful for tools like tsup that need a list of internal
|
|
41
|
+
* packages to include in `noExternal`.
|
|
42
|
+
*
|
|
43
|
+
* If no config is passed, it reads from `isolate.config.{ts,js,json}` in the
|
|
44
|
+
* current working directory.
|
|
45
|
+
*/
|
|
46
|
+
declare function getInternalPackageNames(config?: IsolateConfig): Promise<string[]>;
|
|
39
47
|
//#endregion
|
|
40
|
-
export {
|
|
48
|
+
export { type IsolateConfig, type Logger, defineConfig, getInternalPackageNames, isolate };
|
|
41
49
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
-
import { t as isolate } from "./isolate-
|
|
1
|
+
import { c as detectPackageManager, i as defineConfig, l as readTypedJson, n as listInternalPackages, o as resolveConfig, r as createPackagesRegistry, s as resolveWorkspacePaths, t as isolate } from "./isolate-D-Qd5BJJ.mjs";
|
|
2
|
+
import path from "node:path";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
//#region src/get-internal-package-names.ts
|
|
5
|
+
/**
|
|
6
|
+
* Get the names of all internal workspace packages that the target package
|
|
7
|
+
* depends on. This is useful for tools like tsup that need a list of internal
|
|
8
|
+
* packages to include in `noExternal`.
|
|
9
|
+
*
|
|
10
|
+
* If no config is passed, it reads from `isolate.config.{ts,js,json}` in the
|
|
11
|
+
* current working directory.
|
|
12
|
+
*/
|
|
13
|
+
async function getInternalPackageNames(config) {
|
|
14
|
+
const resolvedConfig = resolveConfig(config);
|
|
15
|
+
const { targetPackageDir, workspaceRootDir } = resolveWorkspacePaths(resolvedConfig);
|
|
16
|
+
detectPackageManager(workspaceRootDir);
|
|
17
|
+
return listInternalPackages(await readTypedJson(path.join(targetPackageDir, "package.json")), await createPackagesRegistry(workspaceRootDir, resolvedConfig.workspacePackages), { includeDevDependencies: resolvedConfig.includeDevDependencies });
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
export { defineConfig, getInternalPackageNames, isolate };
|
|
22
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/get-internal-package-names.ts"],"sourcesContent":["import path from \"node:path\";\nimport type { IsolateConfig } from \"./lib/config\";\nimport { resolveConfig, resolveWorkspacePaths } from \"./lib/config\";\nimport { detectPackageManager } from \"./lib/package-manager\";\nimport { createPackagesRegistry, listInternalPackages } from \"./lib/registry\";\nimport type { PackageManifest } from \"./lib/types\";\nimport { readTypedJson } from \"./lib/utils\";\n\n/**\n * Get the names of all internal workspace packages that the target package\n * depends on. This is useful for tools like tsup that need a list of internal\n * packages to include in `noExternal`.\n *\n * If no config is passed, it reads from `isolate.config.{ts,js,json}` in the\n * current working directory.\n */\nexport async function getInternalPackageNames(\n config?: IsolateConfig,\n): Promise<string[]> {\n const resolvedConfig = resolveConfig(config);\n const { targetPackageDir, workspaceRootDir } =\n resolveWorkspacePaths(resolvedConfig);\n\n detectPackageManager(workspaceRootDir);\n\n const targetPackageManifest = await readTypedJson<PackageManifest>(\n path.join(targetPackageDir, \"package.json\"),\n );\n\n const packagesRegistry = await createPackagesRegistry(\n workspaceRootDir,\n resolvedConfig.workspacePackages,\n );\n\n return listInternalPackages(targetPackageManifest, packagesRegistry, {\n includeDevDependencies: resolvedConfig.includeDevDependencies,\n });\n}\n"],"mappings":";;;;;;;;;;;;AAgBA,eAAsB,wBACpB,QACmB;CACnB,MAAM,iBAAiB,cAAc,OAAO;CAC5C,MAAM,EAAE,kBAAkB,qBACxB,sBAAsB,eAAe;AAEvC,sBAAqB,iBAAiB;AAWtC,QAAO,qBATuB,MAAM,cAClC,KAAK,KAAK,kBAAkB,eAAe,CAC5C,EAEwB,MAAM,uBAC7B,kBACA,eAAe,kBAChB,EAEoE,EACnE,wBAAwB,eAAe,wBACxC,CAAC"}
|