isolate-package 1.8.0 → 1.9.0-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.
package/README.md CHANGED
@@ -105,7 +105,7 @@ If you are here to simplify and improve your Firebase deployments check out the
105
105
 
106
106
  ## Troubleshooting
107
107
 
108
- If something is not working as expected, add a `isolate.config.json` file, and
108
+ If something is not working as expected, add an `isolate.config.json` file, and
109
109
  set `"logLevel"` to `"debug"`. This should give you detailed feedback in the
110
110
  console.
111
111
 
@@ -114,10 +114,7 @@ by setting `DEBUG_ISOLATE_CONFIG=true` before you execute `isolate`.
114
114
 
115
115
  When debugging Firebase deployment issues it might be convenient to trigger the
116
116
  isolate process manually with `npx isolate` and possibly
117
- `DEBUG_ISOLATE_CONFIG=true npx isolate`
118
-
119
- If you do not pass in any configuration, the function will try to read a
120
- `isolate.config.json` file from disk. You can set
117
+ `DEBUG_ISOLATE_CONFIG=true npx isolate`.
121
118
 
122
119
  ## Prerequisites
123
120
 
@@ -214,28 +211,40 @@ same location, as it uses the current working directory.
214
211
 
215
212
  Below you will find a description of every available option.
216
213
 
217
- ### buildDirName
214
+ ### logLevel
218
215
 
219
- Type: `string | undefined`, default: `undefined`
216
+ Type: `"info" | "debug" | "warn" | "error"`, default: `"info"`.
220
217
 
221
- The name of the build output directory name. When undefined it is automatically
222
- detected via `tsconfig.json`. When you are not using Typescript you can use this
223
- setting to specify where the build output files are located.
218
+ Because the configuration loader depends on this setting, its output is not
219
+ affected by this setting. If you want to debug the configuration set
220
+ `DEBUG_ISOLATE_CONFIG=true` before you run `isolate`
224
221
 
225
- ### excludeLockfile
222
+ ### useNpm
226
223
 
227
- Type: `boolean`, default: Depends on package manager.
224
+ Type: `boolean`, default: `false`
228
225
 
229
- **Deprecated** This option exists from the time that lockfiles were not
230
- supported for all package managers. You should not need this escape hatch
231
- anymore.
226
+ By default the isolate process will generate output based on the package manager
227
+ that you are using for your monorepo. But your deployment target might not be
228
+ compatible with that package manager, or it might not be the best choice given
229
+ the available tooling.
232
230
 
233
- Sets the inclusion or exclusion of the lockfile as part of the deployment.
231
+ Also, it should not really matter what package manager is used in de deployment
232
+ as long as the versions match your original lockfile.
234
233
 
235
- Isolated / pruned lockfiles are generated for NPM, PNPM and Yarn v1 (classic)
236
- based on the existing root lockfile, and they are included by default.
234
+ By setting this option to `true` you are forcing the isolate output to use NPM.
235
+ A package-lock file will be generated based on the installed node modules and
236
+ therefore should match the versions in your original lockfile.
237
237
 
238
- For more information see [lockfiles](#lockfiles).
238
+ This way you can enjoy using PNPM for your monorepo, while your deployment uses
239
+ NPM locked to the same versions.
240
+
241
+ ### buildDirName
242
+
243
+ Type: `string | undefined`, default: `undefined`
244
+
245
+ The name of the build output directory name. When undefined it is automatically
246
+ detected via `tsconfig.json`. When you are not using Typescript you can use this
247
+ setting to specify where the build output files are located.
239
248
 
240
249
  ### includeDevDependencies
241
250
 
@@ -245,19 +254,31 @@ By default devDependencies are ignored and stripped from the isolated output
245
254
  `package.json` files. If you enable this the devDependencies will be included
246
255
  and isolated just like the production dependencies.
247
256
 
248
- ### isolateDirName
257
+ ### pickFromScripts
249
258
 
250
- Type: `string`, default: `"isolate"`
259
+ Type: `string[]`, default: `undefined`
251
260
 
252
- The name of the isolate output directory.
261
+ Select which scripts to include in the output manifest `scripts` field. For
262
+ example if you want your test script included set it to `["test"]`.
253
263
 
254
- ### logLevel
264
+ By default, all scripts are omitted.
255
265
 
256
- Type: `"info" | "debug" | "warn" | "error"`, default: `"info"`.
266
+ ### omitFromScripts
257
267
 
258
- Because the configuration loader depends on this setting, its output is not
259
- affected by this setting. If you want to debug the configuration set
260
- `DEBUG_ISOLATE_CONFIG=true` before you run `isolate`
268
+ Type: `string[]`, default: `undefined`
269
+
270
+ Select which scripts to omit from the output manifest `scripts` field. For
271
+ example if you want the build script interferes with your deployment target, but
272
+ you want to preserve all of the other scripts, set it to `["build"]`.
273
+
274
+ By default, all scripts are omitted, and the [pickFromScripts](#pickfromscripts)
275
+ configuration overrules this configuration.
276
+
277
+ ### isolateDirName
278
+
279
+ Type: `string`, default: `"isolate"`
280
+
281
+ The name of the isolate output directory.
261
282
 
262
283
  ### targetPackagePath
263
284
 
@@ -323,31 +344,62 @@ When you use the `targetPackagePath` option, this setting will be ignored.
323
344
 
324
345
  ## Lockfiles
325
346
 
326
- A lockfile in a monorepo describes the dependencies of all packages, and does
327
- not translate to the isolated output without altering it.
347
+ The isolate process tries to generate an isolated / pruned lockfile for the
348
+ package manager that you use in your monorepo. If the package manager is not
349
+ supported (modern Yarn versions), it can still generate a matching NPM lockfile
350
+ based on the installed versions in node_modules.
351
+
352
+ In case your package manager is not supported by your deployment target you can
353
+ also choose NPM to be used by setting the `makeNpmLockfile` to `true` in your
354
+ configuration.
355
+
356
+ ### NPM
357
+
358
+ For NPM we use a tool called Arborist which is an integral part of the NPM
359
+ codebase. It is executed in the isolate output directory and requires the
360
+ adapted lockfile and the `node_modules` directory from the root of the
361
+ repository. As this directory is typically quite large, copying it over as part
362
+ of the isolate flow is not very desirable.
363
+
364
+ To work around this, we move it to the isolate output and then move it back
365
+ after Arborist has finished doing its thing. Luckily it doesn't take long and
366
+ hopefully this doesn't create any unwanted side effects for IDEs and other tools
367
+ that depend on the content of the directory.
368
+
369
+ When errors occur in this process, the folder should still be moved back.
328
370
 
329
- If you copying the original lockfile and deploy it with the isolated code, a CI
330
- environment will not accept the lockfile. It is also not possibly to generate a
331
- brand new lockfile from the isolated code by mimicking a fresh install, because
332
- versions would be able to diverge and thus negate the whole point of having a
333
- lockfile in the first place.
371
+ ### PNPM
334
372
 
335
- For this to work, we need to re-generate or prune the original lockfile to keep
336
- the versions of the original but only describe the dependencies of the code in
337
- the isolated output.
373
+ The PNPM lockfile format is very readable (YAML) but getting it adapted to the
374
+ isolate output was a bit of a trip.
338
375
 
339
- Since every package manager works completely different in this regard, this part
340
- of the puzzle had to be solved in a different ways for each of them, and not all
341
- are supported yet.
376
+ It turns out, at least up to v10, that the isolated output has to be formatted
377
+ as a workspace itself, otherwise dependencies of internally linked packages are
378
+ not installed by PNPM. Therefore, the output looks a bit different from other
379
+ package managers:
342
380
 
343
- At the moment lockfiles for the following package managers are supported:
381
+ - Links are preserved
382
+ - Versions specifiers like "workspace:\*" are preserved
383
+ - A pnpm-workspace.yaml file is added to the output
344
384
 
345
- - NPM
346
- - PNPM
347
- - Yarn Classic (v1)
385
+ ### Classic Yarn
348
386
 
349
- More detailed information on the implementation can be found in the
350
- [additional docs](./docs/lockfiles.md).
387
+ For Yarn v1 we can simply copy the root lockfile to the isolate output, and run
388
+ a `yarn install` to prune that lockfile. The command finds the installed node
389
+ modules in the root of the monorepo so versions are preserved.
390
+
391
+ > Note: I expect this to break down if you configure the isolate output
392
+ > directory to be located outside the monorepo tree.
393
+
394
+ ### Modern Yarn
395
+
396
+ For modern Yarn versions we fall back to using NPM for the output lockfile,
397
+ because the strategy of running `yarn install` does not seem to apply here.
398
+
399
+ Based on the installed node_modules we generate an NPM lockfile that matches the
400
+ versions in the Yarn lockfile. It should not really matter what package manager
401
+ your deployed code uses, as long as the lockfile versions match with the
402
+ original lockfile.
351
403
 
352
404
  ## API
353
405
 
@@ -365,6 +417,9 @@ await isolate({
365
417
  });
366
418
  ```
367
419
 
420
+ If no configuration is passed in, the process will try to read
421
+ `isolate.config.json` from the current working directory.
422
+
368
423
  ## The internal packages strategy
369
424
 
370
425
  An alternative approach to using internal dependencies in a Typescript monorepo
package/dist/index.d.ts CHANGED
@@ -7,8 +7,9 @@ type IsolateConfigResolved = {
7
7
  tsconfigPath: string;
8
8
  workspacePackages?: string[];
9
9
  workspaceRoot: string;
10
- excludeLockfile: boolean;
11
- avoidPnpmPack: boolean;
10
+ useNpm: boolean;
11
+ pickFromScripts?: string[];
12
+ omitFromScripts?: string[];
12
13
  };
13
14
  type IsolateConfig = Partial<IsolateConfigResolved>;
14
15