isolate-package 1.1.1 → 1.2.0-rc2

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
@@ -15,23 +15,47 @@ There is nothing Firebase specific to this solution but I am currently not aware
15
15
  of other reasons to isolate a workspace package. If you find a different
16
16
  use-case, I would love to hear about it.
17
17
 
18
+ In the code and text you see the word manifest a lot, and it simply means to the
19
+ contents of a `package.json` file.
20
+
18
21
  ## Features
19
22
 
20
23
  - Zero-config for the vast majority of use-cases, with no manual steps involved.
21
- - Designed to support NPM, Yarn and PNPM workspaces.
24
+ - Support NPM, Yarn classic (v1) and current (v3) and PNPM.
22
25
  - Compatible with the Firebase tools CLI.
23
- - Uses a pack/unpack approach to isolate only those files that would have been
24
- part of a published package, so the resulting output contains a minimal amount
25
- of files.
26
- - Isolates dependencies recursively. If package A depends on local package B
27
- which depends on local package C, all of them will be isolated.
26
+ - Uses a pack/unpack approach to isolate only the files that would have been
27
+ part of a published package, so the output contains a minimal set of files.
28
+ - Isolates shared dependencies recursively. If package A depends on local
29
+ package B which depends on local package C, all of them will be isolated.
28
30
  - Include and (in the case of PNPM) update the lockfile so the isolated
29
31
  deployment should be deterministic. For PNPM see [lockfiles](#lockfiles)
30
- - Optionally choose to include dev dependencies in the isolated output.
32
+ - Optionally include devDependencies in the isolated output.
33
+
34
+ ## Quickstart
35
+
36
+ This describes the steps required for Firebase deployment in the most common
37
+ use-cases, assuming your are using a fairly typical monorepo setup, and your
38
+ `firebase.json` config lives in the package where you deploy from. If this
39
+ doesn't work for you, continue reading the [Prerequisites](#prerequisites)
40
+ section, as you might have to tweak your package.json files a bit.
41
+
42
+ 1. Install isolate-package by running `pnpm add isolate-package -D` (or the Yarn
43
+ / NPM equivalent) _from the root of the package you would like to deploy to
44
+ Firebase_.
45
+ 2. In the `firebase.json` config (assuming it lives in the package you deploy
46
+ from) set `"source"` to `"./isolate"` and `"predeploy"` to `["turbo build",
47
+ "isolate"]` or whatever fits your build tool.
48
+ 3. That's it! You should now be able to deploy with `npx firebase deploy` or
49
+ `npx firebase deploy --only functions` if your package only contains code for
50
+ functions.
51
+
52
+ I recommend keeping your `firebase.json` file inside the package (as opposed to
53
+ the monorepo root), because it keeps things clean and allows you to deploy to
54
+ firebase from multiple independent packages.
31
55
 
32
56
  ## Prerequisites
33
57
 
34
- Because historically different approaches to monorepos exist, we need to
58
+ Because historically many different approaches to monorepos exist, we need to
35
59
  establish some basic rules for the isolate process to work.
36
60
 
37
61
  ### Define shared package dependencies in the manifest
@@ -80,12 +104,19 @@ directory, for example:
80
104
  }
81
105
  ```
82
106
 
83
- Also `version` seems to be required by pack. I like setting it to `"0.0.0"` to
84
- make it clear that the version is not really being used.
107
+ The `version` field is also required for `pack` to execute. I personally always
108
+ set it to `"0.0.0"` to indicate that the version does not have a practical
109
+ function.
85
110
 
86
111
  A few additional files will be included by `pack` automatically, like the
87
112
  `package.json` and `README.md` files.
88
113
 
114
+ **Tip** If you deploy to Firebase [2nd
115
+ generation](https://firebase.google.com/docs/firestore/extend-with-functions-2nd-gen)
116
+ functions, you might want to include some .env files in the "files" list, so
117
+ they are packaged and deployed together with your build output (as 1st gen
118
+ functions config is no longer supported).
119
+
89
120
  ### Use a flat structure inside your packages folders
90
121
 
91
122
  At the moment, nesting packages inside packages is not supported.
@@ -191,6 +222,15 @@ The name of the build output directory name. When undefined it is automatically
191
222
  detected via `tsconfig.json`. When you are not using Typescript you can use this
192
223
  setting to specify where the build output files are located.
193
224
 
225
+ ### excludeLockfile
226
+
227
+ Type: `boolean`, default: Depends on package manager.
228
+
229
+ Sets the inclusion or exclusion of the lockfile as part of the deployment. For
230
+ Yarn and NPM the lockfiles are included by default, but for PNPM they are
231
+ excluded by default because they are not supported yet. For more information see
232
+ [lockfiles](#lockfiles).
233
+
194
234
  ### includeDevDependencies
195
235
 
196
236
  Type: `boolean`, default: `false`
@@ -295,25 +335,47 @@ The PNPM lockfile clearly has a structure describing the different packages by
295
335
  their relative paths, and so to correct the lockfile it is adapted before being
296
336
  stored to the isolate directory.
297
337
 
298
- There is still [an issue with the PNPM lockfile
299
- conversion](https://github.com/0x80/isolate-package/issues/5). Until that is
300
- resolved, you can choose to exclude the lockfile by setting the configuration
301
- `"excludeLockfile": true`.
338
+ However, there is still [an issue with the PNPM lockfile
339
+ conversion](https://github.com/0x80/isolate-package/issues/5) and it is unusable
340
+ at the moment. Until that is resolved, the lockfile is automatically excluded
341
+ for PNPM.
302
342
 
303
- ## Used Terminology
343
+ Personally, I don't see this as a big problem. I am declaring versions with `^`
344
+ in my manifest, which means that a missing lockfile can only ever result in
345
+ unexpected patch versions, and I am not using dependencies that are likely to
346
+ break on patch version changes.
304
347
 
305
- The various package managers, while being very similar, seem to use a different
306
- definition for the term "workspace". If you want to read the code it might be
307
- good to know that I consider the workspace to be the monorepo itself, in other
308
- words, the overall structure that holds all the packages.
348
+ ## Different Package Managers
309
349
 
310
- Also, in the code you see the word manifest a lot, and it simply means to the
311
- contents of a `package.json` file.
350
+ Isolate package has been designed to work with all package managers. Personally
351
+ I have been testing it with NPM 9, Yarn 1.22, Yarn 3.6 and PNPM 8 on a fairly
352
+ complex real-life project.
353
+
354
+ The isolate process will infer the package manager name and version from the
355
+ "packageManager" field in the manifest located in root of your monorepo. If the
356
+ field is empty it will then infer it from the type of lockfile found and the
357
+ version that the OS reports for the installed executable. This is just so we can
358
+ make some distinction in the code where needed, but until now it is hardly
359
+ necessary.
360
+
361
+ For example, the PNPM `pack` process is preferred over the default NPM `pack` if
362
+ PNPM in used, simply because it seems to be much faster.
363
+
364
+ The Firebase cloud deploy pipeline will use the package manager that matches
365
+ lockfile that was found in the deployed package.
366
+
367
+ ### Yarn v1 and v3
368
+
369
+ If you are using Yarn 3 with zero-installs, the deployed package is not aware of
370
+ that, because the `.yarnrc` file and `.yarn` folder are located in the root of
371
+ your monorepo, and the version is not recorded as part of the lockfile. Therefor
372
+ the Firebase deploy could pipeline will likely use Yarn 1 to install your
373
+ dependencies. I don't think that is an issue but it might be good to know.
312
374
 
313
375
  ## Binary as ESM module
314
376
 
315
377
  The `isolate` binary is an ES module. It is required to have the `.mjs` file
316
- extension, otherwise a non-ESM workspace will try to execute it as commonJS. For
378
+ extension, otherwise a non-ESM workspace will try to load it as commonJS. For
317
379
  details on this read [this article from Alex
318
380
  Rauschmayer](https://exploringjs.com/nodejs-shell-scripting/ch_creating-shell-scripts.html#node.js-esm-modules-as-standalone-shell-scripts-on-unix)
319
381
 
package/dist/index.mjs CHANGED
@@ -2,31 +2,13 @@
2
2
 
3
3
  // src/index.ts
4
4
  import fs13 from "fs-extra";
5
- import assert3 from "node:assert";
5
+ import assert4 from "node:assert";
6
6
  import path13 from "node:path";
7
7
  import sourceMaps from "source-map-support";
8
8
 
9
9
  // src/helpers/adapt-manifest-files.ts
10
- import fs from "fs-extra";
11
- import path from "node:path";
12
- async function adaptManifestFiles(localDependencies, packagesRegistry, isolateDir) {
13
- await Promise.all(
14
- localDependencies.map(async (packageName) => {
15
- const { manifest, rootRelativeDir } = packagesRegistry[packageName];
16
- const outputManifest = adaptManifestWorkspaceDeps(
17
- { manifest, packagesRegistry },
18
- { includeDevDependencies: getConfig().includeDevDependencies }
19
- );
20
- await fs.writeFile(
21
- path.join(isolateDir, rootRelativeDir, "package.json"),
22
- JSON.stringify(outputManifest, null, 2)
23
- );
24
- })
25
- );
26
- }
27
-
28
- // src/helpers/adapt-manifest-workspace-deps.ts
29
- import { omit } from "lodash-es";
10
+ import fs4 from "fs-extra";
11
+ import path2 from "node:path";
30
12
 
31
13
  // src/utils/filter-object-undefined.ts
32
14
  function filterObjectUndefined(object) {
@@ -69,11 +51,12 @@ function inspectValue(value) {
69
51
  }
70
52
 
71
53
  // src/utils/json.ts
72
- import fs2 from "fs-extra";
54
+ import fs from "fs-extra";
55
+ import stripJsonComments from "strip-json-comments";
73
56
  function readTypedJsonSync(filePath) {
74
57
  try {
75
- const rawContent = fs2.readFileSync(filePath, "utf-8");
76
- const data = JSON.parse(rawContent);
58
+ const rawContent = fs.readFileSync(filePath, "utf-8");
59
+ const data = JSON.parse(stripJsonComments(rawContent));
77
60
  return data;
78
61
  } catch (err) {
79
62
  throw new Error(
@@ -83,7 +66,7 @@ function readTypedJsonSync(filePath) {
83
66
  }
84
67
  async function readTypedJson(filePath) {
85
68
  try {
86
- const rawContent = await fs2.readFile(filePath, "utf-8");
69
+ const rawContent = await fs.readFile(filePath, "utf-8");
87
70
  const data = JSON.parse(rawContent);
88
71
  return data;
89
72
  } catch (err) {
@@ -120,12 +103,13 @@ function createLogger(logLevel) {
120
103
 
121
104
  // src/utils/pack.ts
122
105
  import { exec } from "node:child_process";
123
- import path2 from "node:path";
124
- async function pack(srcDir, destDir, packageManager) {
106
+ import path from "node:path";
107
+ async function pack(srcDir, destDir) {
125
108
  const log2 = createLogger(getConfig().logLevel);
126
109
  const cwd = process.cwd();
127
110
  process.chdir(srcDir);
128
- switch (packageManager) {
111
+ const { name } = usePackageManager();
112
+ switch (name) {
129
113
  case "pnpm": {
130
114
  const stdout = await new Promise((resolve, reject) => {
131
115
  exec(
@@ -157,27 +141,27 @@ async function pack(srcDir, destDir, packageManager) {
157
141
  const packedFileName = stdout.trim();
158
142
  log2.debug("Packed", packedFileName);
159
143
  process.chdir(cwd);
160
- return path2.join(destDir, packedFileName);
144
+ return path.join(destDir, packedFileName);
161
145
  }
162
146
  }
163
147
  }
164
148
 
165
149
  // src/utils/unpack.ts
166
- import fs3 from "fs-extra";
150
+ import fs2 from "fs-extra";
167
151
  import tar from "tar-fs";
168
152
  import { createGunzip } from "zlib";
169
153
  async function unpack(filePath, unpackDir) {
170
154
  await new Promise((resolve, reject) => {
171
- fs3.createReadStream(filePath).pipe(createGunzip()).pipe(tar.extract(unpackDir)).on("finish", () => resolve()).on("error", (err) => reject(err));
155
+ fs2.createReadStream(filePath).pipe(createGunzip()).pipe(tar.extract(unpackDir)).on("finish", () => resolve()).on("error", (err) => reject(err));
172
156
  });
173
157
  }
174
158
 
175
159
  // src/utils/yaml.ts
176
- import fs4 from "fs-extra";
160
+ import fs3 from "fs-extra";
177
161
  import yaml from "yaml";
178
162
  function readTypedYamlSync(filePath) {
179
163
  try {
180
- const rawContent = fs4.readFileSync(filePath, "utf-8");
164
+ const rawContent = fs3.readFileSync(filePath, "utf-8");
181
165
  const data = yaml.parse(rawContent);
182
166
  return data;
183
167
  } catch (err) {
@@ -187,19 +171,48 @@ function readTypedYamlSync(filePath) {
187
171
  }
188
172
  }
189
173
  function writeTypedYamlSync(filePath, content) {
190
- fs4.writeFileSync(filePath, yaml.stringify(content), "utf-8");
174
+ fs3.writeFileSync(filePath, yaml.stringify(content), "utf-8");
175
+ }
176
+
177
+ // src/helpers/adapt-manifest-files.ts
178
+ async function adaptManifestFiles(localDependencies, packagesRegistry, isolateDir) {
179
+ const log2 = createLogger(getConfig().logLevel);
180
+ await Promise.all(
181
+ localDependencies.map(async (packageName) => {
182
+ const { manifest, rootRelativeDir } = packagesRegistry[packageName];
183
+ log2.debug("Adapting manifest file:", packageName);
184
+ const outputManifest = adaptManifestWorkspaceDeps(
185
+ { manifest, packagesRegistry, parentRootRelativeDir: rootRelativeDir },
186
+ { includeDevDependencies: getConfig().includeDevDependencies }
187
+ );
188
+ await fs4.writeFile(
189
+ path2.join(isolateDir, rootRelativeDir, "package.json"),
190
+ JSON.stringify(outputManifest, null, 2)
191
+ );
192
+ })
193
+ );
191
194
  }
192
195
 
193
196
  // src/helpers/adapt-manifest-workspace-deps.ts
197
+ import { omit } from "lodash-es";
194
198
  function adaptManifestWorkspaceDeps({
195
199
  manifest,
196
- packagesRegistry
200
+ packagesRegistry,
201
+ parentRootRelativeDir
197
202
  }, opts = {}) {
198
203
  return Object.assign(
199
204
  omit(manifest, ["scripts", "devDependencies"]),
200
205
  filterObjectUndefined({
201
- dependencies: manifest.dependencies ? patchWorkspaceEntries(manifest.dependencies, packagesRegistry) : void 0,
202
- devDependencies: opts.includeDevDependencies && manifest.devDependencies ? patchWorkspaceEntries(manifest.devDependencies, packagesRegistry) : void 0
206
+ dependencies: manifest.dependencies ? patchWorkspaceEntries(
207
+ manifest.dependencies,
208
+ packagesRegistry,
209
+ parentRootRelativeDir
210
+ ) : void 0,
211
+ devDependencies: opts.includeDevDependencies && manifest.devDependencies ? patchWorkspaceEntries(
212
+ manifest.devDependencies,
213
+ packagesRegistry,
214
+ parentRootRelativeDir
215
+ ) : void 0
203
216
  })
204
217
  );
205
218
  }
@@ -266,45 +279,115 @@ function getConfig() {
266
279
  }
267
280
 
268
281
  // src/helpers/create-packages-registry.ts
269
- import fs8 from "fs-extra";
282
+ import fs9 from "fs-extra";
270
283
  import { globSync } from "glob";
271
284
  import { set } from "lodash-es";
272
- import path7 from "node:path";
285
+ import path8 from "node:path";
273
286
 
274
287
  // src/helpers/find-packages-globs.ts
275
- import path6 from "node:path";
288
+ import path7 from "node:path";
276
289
 
277
290
  // src/helpers/detect-package-manager.ts
291
+ import fs8 from "fs-extra";
292
+ import assert2 from "node:assert";
293
+ import { execSync } from "node:child_process";
294
+ import path6 from "node:path";
295
+
296
+ // src/helpers/process-lockfile.ts
278
297
  import fs7 from "fs-extra";
298
+ import assert from "node:assert";
279
299
  import path5 from "node:path";
280
- function detectPackageManager(workspaceRoot) {
281
- if (fs7.existsSync(path5.join(workspaceRoot, "pnpm-lock.yaml"))) {
282
- return "pnpm";
300
+ function getLockfileFileName(name) {
301
+ switch (name) {
302
+ case "pnpm":
303
+ return "pnpm-lock.yaml";
304
+ case "yarn":
305
+ return "yarn.lock";
306
+ case "npm":
307
+ return "package-lock.json";
283
308
  }
284
- if (fs7.existsSync(path5.join(workspaceRoot, "yarn.lock"))) {
285
- return "yarn";
309
+ }
310
+ function processLockfile({
311
+ workspaceRootDir,
312
+ targetPackageName,
313
+ packagesRegistry,
314
+ isolateDir
315
+ }) {
316
+ const log2 = createLogger(getConfig().logLevel);
317
+ const targetPackageRelativeDir = packagesRegistry[targetPackageName].rootRelativeDir;
318
+ const { name } = usePackageManager();
319
+ const fileName = getLockfileFileName(name);
320
+ const lockfileSrcPath = path5.join(workspaceRootDir, fileName);
321
+ const lockfileDstPath = path5.join(isolateDir, fileName);
322
+ switch (name) {
323
+ case "npm":
324
+ case "yarn": {
325
+ fs7.copyFileSync(lockfileSrcPath, lockfileDstPath);
326
+ log2.debug("Copied lockfile to", lockfileDstPath);
327
+ return;
328
+ }
329
+ case "pnpm": {
330
+ const origLockfile = readTypedYamlSync(lockfileSrcPath);
331
+ log2.debug("Read PNPM lockfile, version:", origLockfile.lockfileVersion);
332
+ const adaptedLockfile = structuredClone(origLockfile);
333
+ const targetPackageDef = adaptedLockfile.importers[targetPackageRelativeDir];
334
+ assert(
335
+ targetPackageDef,
336
+ `Failed to find target package in lockfile at importers[${targetPackageRelativeDir}]`
337
+ );
338
+ adaptedLockfile.importers["."] = targetPackageDef;
339
+ delete adaptedLockfile.importers[targetPackageRelativeDir];
340
+ writeTypedYamlSync(lockfileDstPath, adaptedLockfile);
341
+ log2.debug("Stored adapted lockfile at", lockfileDstPath);
342
+ return;
343
+ }
286
344
  }
287
- if (fs7.existsSync(path5.join(workspaceRoot, "package-lock.json"))) {
288
- return "npm";
345
+ }
346
+
347
+ // src/helpers/detect-package-manager.ts
348
+ var supportedPackageManagerNames = ["pnpm", "yarn", "npm"];
349
+ var packageManager;
350
+ function detectPackageManager(workspaceRoot) {
351
+ packageManager = inferFromFiles(workspaceRoot);
352
+ return packageManager;
353
+ }
354
+ function inferFromFiles(workspaceRoot) {
355
+ for (const name of supportedPackageManagerNames) {
356
+ const lockfileName = getLockfileFileName(name);
357
+ if (fs8.existsSync(path6.join(workspaceRoot, lockfileName))) {
358
+ return { name, version: getVersion(name) };
359
+ }
289
360
  }
290
361
  throw new Error(`Failed to detect package manager`);
291
362
  }
363
+ function getVersion(packageManagerName) {
364
+ const buffer = execSync(`${packageManagerName} --version`);
365
+ return buffer.toString().trim();
366
+ }
367
+ function usePackageManager() {
368
+ if (!packageManager) {
369
+ throw Error(
370
+ "No package manager detected. Make sure to call detectPackageManager() before usePackageManager()"
371
+ );
372
+ }
373
+ return packageManager;
374
+ }
292
375
 
293
376
  // src/helpers/find-packages-globs.ts
294
377
  function findPackagesGlobs(workspaceRootDir) {
295
378
  const log2 = createLogger(getConfig().logLevel);
296
- const packageManager = detectPackageManager(workspaceRootDir);
297
- switch (packageManager) {
379
+ const packageManager2 = usePackageManager();
380
+ switch (packageManager2.name) {
298
381
  case "pnpm": {
299
382
  const { packages: globs } = readTypedYamlSync(
300
- path6.join(workspaceRootDir, "pnpm-workspace.yaml")
383
+ path7.join(workspaceRootDir, "pnpm-workspace.yaml")
301
384
  );
302
385
  log2.debug("Detected pnpm packages globs:", inspectValue(globs));
303
386
  return globs;
304
387
  }
305
388
  case "yarn":
306
389
  case "npm": {
307
- const workspaceRootManifestPath = path6.join(
390
+ const workspaceRootManifestPath = path7.join(
308
391
  workspaceRootDir,
309
392
  "package.json"
310
393
  );
@@ -332,11 +415,11 @@ async function createPackagesRegistry(workspaceRootDir, workspacePackagesOverrid
332
415
  const packagesGlobs = workspacePackagesOverride ?? findPackagesGlobs(workspaceRootDir);
333
416
  const cwd = process.cwd();
334
417
  process.chdir(workspaceRootDir);
335
- const allPackages = packagesGlobs.flatMap((glob) => globSync(glob)).filter((dir) => fs8.lstatSync(dir).isDirectory());
418
+ const allPackages = packagesGlobs.flatMap((glob) => globSync(glob)).filter((dir) => fs9.lstatSync(dir).isDirectory());
336
419
  const registry = (await Promise.all(
337
420
  allPackages.map(async (rootRelativeDir) => {
338
- const manifestPath = path7.join(rootRelativeDir, "package.json");
339
- if (!fs8.existsSync(manifestPath)) {
421
+ const manifestPath = path8.join(rootRelativeDir, "package.json");
422
+ if (!fs9.existsSync(manifestPath)) {
340
423
  log2.warn(
341
424
  `Ignoring directory ./${rootRelativeDir} because it does not contain a package.json file`
342
425
  );
@@ -344,12 +427,12 @@ async function createPackagesRegistry(workspaceRootDir, workspacePackagesOverrid
344
427
  } else {
345
428
  log2.debug(`Registering package ./${rootRelativeDir}`);
346
429
  const manifest = await readTypedJson(
347
- path7.join(rootRelativeDir, "package.json")
430
+ path8.join(rootRelativeDir, "package.json")
348
431
  );
349
432
  return {
350
433
  manifest,
351
434
  rootRelativeDir,
352
- absoluteDir: path7.join(workspaceRootDir, rootRelativeDir)
435
+ absoluteDir: path8.join(workspaceRootDir, rootRelativeDir)
353
436
  };
354
437
  }
355
438
  })
@@ -362,23 +445,23 @@ async function createPackagesRegistry(workspaceRootDir, workspacePackagesOverrid
362
445
  }
363
446
 
364
447
  // src/helpers/get-build-output-dir.ts
365
- import fs9 from "fs-extra";
366
- import path8 from "node:path";
448
+ import fs10 from "fs-extra";
449
+ import path9 from "node:path";
367
450
  import outdent from "outdent";
368
451
  async function getBuildOutputDir(targetPackageDir) {
369
452
  const config2 = getConfig();
370
453
  const log2 = createLogger(getConfig().logLevel);
371
454
  if (config2.buildDirName) {
372
455
  log2.debug("Using buildDirName from config:", config2.buildDirName);
373
- return path8.join(targetPackageDir, config2.buildDirName);
456
+ return path9.join(targetPackageDir, config2.buildDirName);
374
457
  }
375
- const tsconfigPath = path8.join(targetPackageDir, config2.tsconfigPath);
458
+ const tsconfigPath = path9.join(targetPackageDir, config2.tsconfigPath);
376
459
  log2.debug("Looking for tsconfig at:", tsconfigPath);
377
- if (fs9.existsSync(tsconfigPath)) {
460
+ if (fs10.existsSync(tsconfigPath)) {
378
461
  const tsconfig = await readTypedJson(tsconfigPath);
379
462
  const outDir = tsconfig.compilerOptions?.outDir;
380
463
  if (outDir) {
381
- return path8.join(targetPackageDir, outDir);
464
+ return path9.join(targetPackageDir, outDir);
382
465
  } else {
383
466
  throw new Error(outdent`
384
467
  Failed to find outDir in tsconfig. If you are executing isolate from the root of a monorepo you should specify the buildDirName in isolate.config.json.
@@ -409,10 +492,10 @@ function listLocalDependencies(manifest, packagesRegistry, { includeDevDependenc
409
492
  }
410
493
 
411
494
  // src/helpers/manifest.ts
412
- import path9 from "node:path";
495
+ import path10 from "node:path";
413
496
 
414
497
  // src/helpers/pack-dependencies.ts
415
- import assert from "node:assert";
498
+ import assert3 from "node:assert";
416
499
  async function packDependencies({
417
500
  /**
418
501
  * All packages found in the monorepo by workspaces declaration
@@ -428,39 +511,37 @@ async function packDependencies({
428
511
  * default it is a subfolder in targetPackageDir called "isolate" but you can
429
512
  * configure it.
430
513
  */
431
- packDestinationDir,
432
- packageManager
514
+ packDestinationDir
433
515
  }) {
434
516
  const config2 = getConfig();
435
517
  const log2 = createLogger(config2.logLevel);
436
518
  const packedFileByName = {};
437
519
  for (const dependency of localDependencies) {
438
520
  const def = packagesRegistry[dependency];
439
- assert(dependency, `Failed to find package definition for ${dependency}`);
521
+ assert3(dependency, `Failed to find package definition for ${dependency}`);
440
522
  const { name } = def.manifest;
441
523
  if (packedFileByName[name]) {
442
524
  log2.debug(`Skipping ${name} because it has already been packed`);
443
525
  continue;
444
526
  }
445
- packedFileByName[name] = await pack(
446
- def.absoluteDir,
447
- packDestinationDir,
448
- packageManager
449
- );
527
+ packedFileByName[name] = await pack(def.absoluteDir, packDestinationDir);
450
528
  }
451
529
  return packedFileByName;
452
530
  }
453
531
 
454
532
  // src/helpers/patch-workspace-entries.ts
455
- function patchWorkspaceEntries(dependencies, packagesRegistry) {
533
+ import path11 from "node:path";
534
+ function patchWorkspaceEntries(dependencies, packagesRegistry, parentRootRelativeDir) {
456
535
  const log2 = createLogger(getConfig().logLevel);
457
536
  const allWorkspacePackageNames = Object.keys(packagesRegistry);
458
537
  return Object.fromEntries(
459
538
  Object.entries(dependencies).map(([key, value]) => {
460
539
  if (allWorkspacePackageNames.includes(key)) {
461
540
  const def = packagesRegistry[key];
462
- log2.debug(`Linking dependency ${key} to file:${def.rootRelativeDir}`);
463
- return [key, `file:${def.rootRelativeDir}`];
541
+ const relativePath = parentRootRelativeDir ? path11.relative(parentRootRelativeDir, `./${def.rootRelativeDir}`) : `./${def.rootRelativeDir}`;
542
+ const linkPath = `file:${relativePath}`;
543
+ log2.debug(`Linking dependency ${key} to ${linkPath}`);
544
+ return [key, linkPath];
464
545
  } else {
465
546
  return [key, value];
466
547
  }
@@ -469,69 +550,17 @@ function patchWorkspaceEntries(dependencies, packagesRegistry) {
469
550
  }
470
551
 
471
552
  // src/helpers/process-build-output-files.ts
472
- import fs10 from "fs-extra";
473
- import path10 from "node:path";
553
+ import fs11 from "fs-extra";
554
+ import path12 from "node:path";
474
555
  async function processBuildOutputFiles({
475
556
  targetPackageDir,
476
557
  tmpDir,
477
- packageManager,
478
558
  isolateDir
479
559
  }) {
480
- const packedFilePath = await pack(targetPackageDir, tmpDir, packageManager);
481
- const unpackDir = path10.join(tmpDir, "target");
560
+ const packedFilePath = await pack(targetPackageDir, tmpDir);
561
+ const unpackDir = path12.join(tmpDir, "target");
482
562
  await unpack(packedFilePath, unpackDir);
483
- await fs10.copy(path10.join(unpackDir, "package"), isolateDir);
484
- }
485
-
486
- // src/helpers/process-lockfile.ts
487
- import fs11 from "fs-extra";
488
- import assert2 from "node:assert";
489
- import path11 from "node:path";
490
- function getLockfileFileName(packageManager) {
491
- switch (packageManager) {
492
- case "pnpm":
493
- return "pnpm-lock.yaml";
494
- case "yarn":
495
- return "yarn.lock";
496
- case "npm":
497
- return "package-lock.json";
498
- }
499
- }
500
- function processLockfile({
501
- workspaceRootDir,
502
- targetPackageName,
503
- packagesRegistry,
504
- isolateDir,
505
- packageManager
506
- }) {
507
- const log2 = createLogger(getConfig().logLevel);
508
- const targetPackageRelativeDir = packagesRegistry[targetPackageName].rootRelativeDir;
509
- const fileName = getLockfileFileName(packageManager);
510
- const lockfileSrcPath = path11.join(workspaceRootDir, fileName);
511
- const lockfileDstPath = path11.join(isolateDir, fileName);
512
- switch (packageManager) {
513
- case "npm":
514
- case "yarn": {
515
- fs11.copyFileSync(lockfileSrcPath, lockfileDstPath);
516
- log2.debug("Copied lockfile to", lockfileDstPath);
517
- return;
518
- }
519
- case "pnpm": {
520
- const origLockfile = readTypedYamlSync(lockfileSrcPath);
521
- log2.debug("Read PNPM lockfile, version:", origLockfile.lockfileVersion);
522
- const adaptedLockfile = structuredClone(origLockfile);
523
- const targetPackageDef = adaptedLockfile.importers[targetPackageRelativeDir];
524
- assert2(
525
- targetPackageDef,
526
- `Failed to find target package in lockfile at importers[${targetPackageRelativeDir}]`
527
- );
528
- adaptedLockfile.importers["."] = targetPackageDef;
529
- delete adaptedLockfile.importers[targetPackageRelativeDir];
530
- writeTypedYamlSync(lockfileDstPath, adaptedLockfile);
531
- log2.debug("Stored adapted lockfile at", lockfileDstPath);
532
- return;
533
- }
534
- }
563
+ await fs11.copy(path12.join(unpackDir, "package"), isolateDir);
535
564
  }
536
565
 
537
566
  // src/helpers/unpack-dependencies.ts
@@ -568,7 +597,7 @@ async function start() {
568
597
  const targetPackageDir = config.targetPackagePath ? path13.join(process.cwd(), config.targetPackagePath) : process.cwd();
569
598
  const workspaceRootDir = config.targetPackagePath ? process.cwd() : path13.join(targetPackageDir, config.workspaceRoot);
570
599
  const buildOutputDir = await getBuildOutputDir(targetPackageDir);
571
- assert3(
600
+ assert4(
572
601
  fs13.existsSync(buildOutputDir),
573
602
  `Failed to find build output path at ${buildOutputDir}. Please make sure you build the source before isolating it.`
574
603
  );
@@ -577,7 +606,6 @@ async function start() {
577
606
  "Isolate target package",
578
607
  getRootRelativePath(targetPackageDir, workspaceRootDir)
579
608
  );
580
- const packageManager = detectPackageManager(workspaceRootDir);
581
609
  const isolateDir = path13.join(targetPackageDir, config.isolateDirName);
582
610
  log.debug(
583
611
  "Isolate output directory",
@@ -588,28 +616,31 @@ async function start() {
588
616
  log.debug("Cleaned the existing isolate output directory");
589
617
  }
590
618
  await fs13.ensureDir(isolateDir);
619
+ const tmpDir = path13.join(isolateDir, "__tmp");
620
+ await fs13.ensureDir(tmpDir);
621
+ const targetPackageManifest = await readTypedJson(
622
+ path13.join(targetPackageDir, "package.json")
623
+ );
624
+ const { name, version } = detectPackageManager(workspaceRootDir);
625
+ log.debug("Detected package manager", name, version);
626
+ if (name === "pnpm") {
627
+ config.excludeLockfile = true;
628
+ }
591
629
  const packagesRegistry = await createPackagesRegistry(
592
630
  workspaceRootDir,
593
631
  config.workspacePackages
594
632
  );
595
- const tmpDir = path13.join(isolateDir, "__tmp");
596
- await fs13.ensureDir(tmpDir);
597
- if (packageManager === "pnpm") {
598
- log.debug("Using pnpm to pack dependencies");
599
- } else {
600
- log.debug("Using npm to pack dependencies");
601
- }
602
- const manifest = await readTypedJson(
603
- path13.join(targetPackageDir, "package.json")
633
+ const localDependencies = listLocalDependencies(
634
+ targetPackageManifest,
635
+ packagesRegistry,
636
+ {
637
+ includeDevDependencies: config.includeDevDependencies
638
+ }
604
639
  );
605
- const localDependencies = listLocalDependencies(manifest, packagesRegistry, {
606
- includeDevDependencies: config.includeDevDependencies
607
- });
608
640
  const packedFilesByName = await packDependencies({
609
641
  localDependencies,
610
642
  packagesRegistry,
611
- packDestinationDir: tmpDir,
612
- packageManager
643
+ packDestinationDir: tmpDir
613
644
  });
614
645
  await unpackDependencies(
615
646
  packedFilesByName,
@@ -621,19 +652,21 @@ async function start() {
621
652
  await processBuildOutputFiles({
622
653
  targetPackageDir,
623
654
  tmpDir,
624
- packageManager,
625
655
  isolateDir
626
656
  });
627
- await adaptTargetPackageManifest(manifest, packagesRegistry, isolateDir);
657
+ await adaptTargetPackageManifest(
658
+ targetPackageManifest,
659
+ packagesRegistry,
660
+ isolateDir
661
+ );
628
662
  if (config.excludeLockfile) {
629
663
  log.warn("Excluding the lockfile from the isolate output");
630
664
  } else {
631
665
  await processLockfile({
632
666
  workspaceRootDir,
633
- targetPackageName: manifest.name,
667
+ targetPackageName: targetPackageManifest.name,
634
668
  isolateDir,
635
- packagesRegistry,
636
- packageManager
669
+ packagesRegistry
637
670
  });
638
671
  }
639
672
  log.debug(
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/helpers/adapt-manifest-files.ts","../src/helpers/adapt-manifest-workspace-deps.ts","../src/utils/filter-object-undefined.ts","../src/utils/get-error-message.ts","../src/utils/get-relative-path.ts","../src/utils/inspect-value.ts","../src/utils/json.ts","../src/utils/logger.ts","../src/utils/pack.ts","../src/utils/unpack.ts","../src/utils/yaml.ts","../src/helpers/adapt-target-package-manifest.ts","../src/helpers/config.ts","../src/helpers/create-packages-registry.ts","../src/helpers/find-packages-globs.ts","../src/helpers/detect-package-manager.ts","../src/helpers/get-build-output-dir.ts","../src/helpers/list-local-dependencies.ts","../src/helpers/manifest.ts","../src/helpers/pack-dependencies.ts","../src/helpers/patch-workspace-entries.ts","../src/helpers/process-build-output-files.ts","../src/helpers/process-lockfile.ts","../src/helpers/unpack-dependencies.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport fs from \"fs-extra\";\nimport assert from \"node:assert\";\nimport path from \"node:path\";\nimport sourceMaps from \"source-map-support\";\nimport {\n PackageManifestMinimum,\n adaptManifestFiles,\n adaptTargetPackageManifest,\n createPackagesRegistry,\n detectPackageManager,\n getBuildOutputDir,\n getConfig,\n listLocalDependencies,\n packDependencies,\n processBuildOutputFiles,\n processLockfile,\n unpackDependencies,\n} from \"~/helpers\";\nimport { createLogger, getRootRelativePath, readTypedJson } from \"~/utils\";\n\nconst config = getConfig();\nconst log = createLogger(config.logLevel);\n\nsourceMaps.install();\n\nasync function start() {\n /**\n * If a targetPackagePath is set, we assume the configuration lives in the\n * root of the workspace. If targetPackagePath is undefined (the default), we\n * assume that the configuration lives in the target package directory.\n */\n const targetPackageDir = config.targetPackagePath\n ? path.join(process.cwd(), config.targetPackagePath)\n : process.cwd();\n\n /**\n * We want a trailing slash here. Functionally it doesn't matter, but it makes\n * the relative paths more correct in the debug output.\n */\n const workspaceRootDir = config.targetPackagePath\n ? process.cwd()\n : path.join(targetPackageDir, config.workspaceRoot);\n\n const buildOutputDir = await getBuildOutputDir(targetPackageDir);\n\n assert(\n fs.existsSync(buildOutputDir),\n `Failed to find build output path at ${buildOutputDir}. Please make sure you build the source before isolating it.`\n );\n\n log.debug(\"Workspace root\", workspaceRootDir);\n log.debug(\n \"Isolate target package\",\n getRootRelativePath(targetPackageDir, workspaceRootDir)\n );\n\n const packageManager = detectPackageManager(workspaceRootDir);\n\n const isolateDir = path.join(targetPackageDir, config.isolateDirName);\n\n log.debug(\n \"Isolate output directory\",\n getRootRelativePath(isolateDir, workspaceRootDir)\n );\n\n if (fs.existsSync(isolateDir)) {\n await fs.remove(isolateDir);\n log.debug(\"Cleaned the existing isolate output directory\");\n }\n\n await fs.ensureDir(isolateDir);\n\n /**\n * Build a packages registry so we can find the workspace packages by name and\n * have access to their manifest files and relative paths.\n */\n const packagesRegistry = await createPackagesRegistry(\n workspaceRootDir,\n config.workspacePackages\n );\n\n const tmpDir = path.join(isolateDir, \"__tmp\");\n await fs.ensureDir(tmpDir);\n\n /**\n * PNPM pack seems to be much faster than NPM pack so we use that when PNPM is\n * detected. We log it here because the pack function will be called\n * recursively.\n */\n if (packageManager === \"pnpm\") {\n log.debug(\"Using pnpm to pack dependencies\");\n } else {\n log.debug(\"Using npm to pack dependencies\");\n }\n\n const manifest = await readTypedJson<PackageManifestMinimum>(\n path.join(targetPackageDir, \"package.json\")\n );\n\n const localDependencies = listLocalDependencies(manifest, packagesRegistry, {\n includeDevDependencies: config.includeDevDependencies,\n });\n\n const packedFilesByName = await packDependencies({\n localDependencies,\n packagesRegistry,\n packDestinationDir: tmpDir,\n packageManager,\n });\n\n await unpackDependencies(\n packedFilesByName,\n packagesRegistry,\n tmpDir,\n isolateDir\n );\n\n /**\n * Adapt the manifest files for all the unpacked local dependencies\n */\n await adaptManifestFiles(localDependencies, packagesRegistry, isolateDir);\n\n /**\n * Pack the target package directory, and unpack it in the isolate location\n */\n await processBuildOutputFiles({\n targetPackageDir,\n tmpDir,\n packageManager,\n isolateDir,\n });\n\n /**\n * Copy the target manifest file to the isolate location and adapt its\n * workspace dependencies to point to the isolated packages.\n */\n await adaptTargetPackageManifest(manifest, packagesRegistry, isolateDir);\n\n if (config.excludeLockfile) {\n log.warn(\"Excluding the lockfile from the isolate output\");\n } else {\n /**\n * Copy and adapt the lockfile\n */\n await processLockfile({\n workspaceRootDir,\n targetPackageName: manifest.name,\n isolateDir,\n packagesRegistry,\n packageManager,\n });\n }\n\n /**\n * Clean up. Only so this in the happy path, so we can look at the temp folder\n * when thing go wrong.\n */\n log.debug(\n \"Deleting temporary directory\",\n getRootRelativePath(tmpDir, workspaceRootDir)\n );\n await fs.remove(tmpDir);\n\n log.debug(\"Stored isolate output at\", isolateDir);\n\n log.info(\"Isolate completed\");\n}\n\nstart().catch((err) => {\n if (err instanceof Error) {\n log.error(err.stack);\n process.exit(1);\n } else {\n console.error(err);\n }\n});\n\nprocess.on(\"unhandledRejection\", log.error);\n","import fs from \"fs-extra\";\nimport path from \"node:path\";\nimport {\n PackagesRegistry,\n adaptManifestWorkspaceDeps,\n getConfig,\n} from \"~/helpers\";\n\nexport async function adaptManifestFiles(\n localDependencies: string[],\n packagesRegistry: PackagesRegistry,\n isolateDir: string,\n) {\n await Promise.all(\n localDependencies.map(async (packageName) => {\n const { manifest, rootRelativeDir } = packagesRegistry[packageName];\n\n const outputManifest = adaptManifestWorkspaceDeps(\n { manifest, packagesRegistry },\n { includeDevDependencies: getConfig().includeDevDependencies },\n );\n\n await fs.writeFile(\n path.join(isolateDir, rootRelativeDir, \"package.json\"),\n JSON.stringify(outputManifest, null, 2),\n );\n }),\n );\n}\n","import { omit } from \"lodash-es\";\nimport { filterObjectUndefined } from \"~/utils\";\nimport {\n PackageManifestMinimum,\n PackagesRegistry,\n patchWorkspaceEntries,\n} from \".\";\n\nexport function adaptManifestWorkspaceDeps(\n {\n manifest,\n packagesRegistry,\n }: {\n manifest: PackageManifestMinimum;\n packagesRegistry: PackagesRegistry;\n },\n opts: { includeDevDependencies?: boolean } = {},\n): PackageManifestMinimum {\n return Object.assign(\n omit(manifest, [\"scripts\", \"devDependencies\"]),\n filterObjectUndefined({\n dependencies: manifest.dependencies\n ? patchWorkspaceEntries(manifest.dependencies, packagesRegistry)\n : undefined,\n devDependencies:\n opts.includeDevDependencies && manifest.devDependencies\n ? patchWorkspaceEntries(manifest.devDependencies, packagesRegistry)\n : undefined,\n }),\n );\n}\n","export function filterObjectUndefined(object: Record<string, unknown>) {\n return Object.fromEntries(\n Object.entries(object).filter(([_, value]) => value !== undefined),\n );\n}\n","type ErrorWithMessage = {\n message: string;\n};\n\nexport function getErrorMessage(error: unknown) {\n return toErrorWithMessage(error).message;\n}\n\nfunction isErrorWithMessage(error: unknown): error is ErrorWithMessage {\n return typeof error === \"object\" && error !== null && \"message\" in error;\n}\n\nfunction toErrorWithMessage(maybeError: unknown): ErrorWithMessage {\n if (isErrorWithMessage(maybeError)) return maybeError;\n\n try {\n return new Error(JSON.stringify(maybeError));\n } catch {\n /**\n * Fallback in case there’s an error stringifying the maybeError\n * like with circular references.\n */\n return new Error(String(maybeError));\n }\n}\n","export function getRootRelativePath(path: string, rootPath: string) {\n const strippedPath = path.replace(rootPath, \"\");\n\n return strippedPath.startsWith(\"/\")\n ? `(root)${strippedPath}`\n : `(root)/${strippedPath}`;\n}\n\nexport function getIsolateRelativePath(path: string, isolatePath: string) {\n const strippedPath = path.replace(isolatePath, \"\");\n\n return strippedPath.startsWith(\"/\")\n ? `(isolate)${strippedPath}`\n : `(isolate)/${strippedPath}`;\n}\n","import { inspect } from \"node:util\";\nimport { JsonValue } from \"type-fest\";\n\nexport function inspectValue(value: JsonValue) {\n return inspect(value, false, 4, true);\n}\n","import fs from \"fs-extra\";\nimport { getErrorMessage } from \"./get-error-message\";\n\n/**\n * @TODO pass in zod schema and validate\n */\nexport function readTypedJsonSync<T>(filePath: string) {\n try {\n const rawContent = fs.readFileSync(filePath, \"utf-8\");\n const data = JSON.parse(rawContent) as T;\n return data;\n } catch (err) {\n throw new Error(\n `Failed to read JSON from ${filePath}: ${getErrorMessage(err)}`\n );\n }\n}\n\nexport async function readTypedJson<T>(filePath: string) {\n try {\n const rawContent = await fs.readFile(filePath, \"utf-8\");\n const data = JSON.parse(rawContent) as T;\n return data;\n } catch (err) {\n throw new Error(\n `Failed to read JSON from ${filePath}: ${getErrorMessage(err)}`\n );\n }\n}\n","import chalk from \"chalk\";\nimport { IsolateConfigResolved } from \"~/helpers\";\n\nexport type Logger = {\n debug(...args: any[]): void;\n info(...args: any[]): void;\n warn(...args: any[]): void;\n error(...args: any[]): void;\n};\n\nexport function createLogger(\n logLevel: IsolateConfigResolved[\"logLevel\"]\n): Logger {\n return {\n debug(...args: any[]) {\n if (logLevel === \"debug\") {\n console.log(chalk.blue(\"debug\"), ...args);\n }\n },\n info(...args: any[]) {\n if (logLevel === \"debug\" || logLevel === \"info\") {\n console.log(chalk.green(\"info\"), ...args);\n }\n },\n warn(...args: any[]) {\n if (logLevel === \"debug\" || logLevel === \"info\" || logLevel === \"warn\") {\n console.log(chalk.yellow(\"warning\"), ...args);\n }\n },\n error(...args: any[]) {\n console.log(chalk.red(\"error\"), ...args);\n },\n };\n}\n","import { exec } from \"node:child_process\";\nimport path from \"node:path\";\nimport { PackageManager, getConfig } from \"~/helpers\";\nimport { createLogger } from \"./logger\";\n\nexport async function pack(\n srcDir: string,\n destDir: string,\n packageManager: PackageManager\n) {\n const log = createLogger(getConfig().logLevel);\n const cwd = process.cwd();\n process.chdir(srcDir);\n\n /**\n * PNPM pack seems to be a lot faster than NPM pack, so when PNPM is detected\n * we use that instead.\n */\n switch (packageManager) {\n case \"pnpm\": {\n const stdout = await new Promise<string>((resolve, reject) => {\n exec(\n `pnpm pack --pack-destination ${destDir}`,\n (err, stdout, stderr) => {\n if (err) {\n log.error(stderr);\n return reject(err);\n }\n\n resolve(stdout);\n }\n );\n });\n\n /**\n * @TODO use a regex to see if the result from stdout is a valid file\n * path. It could be that other output like warnings are printed. In that\n * case we can to log the stdout.\n */\n\n /**\n * Trim newlines and whitespace\n */\n const packedFilePath = stdout.trim();\n\n // log.debug(\"Packed\", path.basename(packedFilePath));\n log.debug(\"Packed\", packedFilePath);\n\n process.chdir(cwd);\n return packedFilePath;\n }\n\n case \"yarn\":\n case \"npm\": {\n const stdout = await new Promise<string>((resolve, reject) => {\n exec(`npm pack --pack-destination ${destDir}`, (err, stdout) => {\n if (err) {\n return reject(err);\n }\n\n resolve(stdout);\n });\n });\n\n /**\n * Trim newlines and whitespace\n */\n const packedFileName = stdout.trim();\n\n log.debug(\"Packed\", packedFileName);\n\n process.chdir(cwd);\n return path.join(destDir, packedFileName);\n }\n }\n}\n","import fs from \"fs-extra\";\nimport tar from \"tar-fs\";\nimport { createGunzip } from \"zlib\";\n\nexport async function unpack(filePath: string, unpackDir: string) {\n await new Promise<void>((resolve, reject) => {\n fs.createReadStream(filePath)\n .pipe(createGunzip())\n .pipe(tar.extract(unpackDir))\n .on(\"finish\", () => resolve())\n .on(\"error\", (err) => reject(err));\n });\n}\n","import fs from \"fs-extra\";\nimport yaml from \"yaml\";\nimport { getErrorMessage } from \"./get-error-message\";\n\nexport function readTypedYamlSync<T>(filePath: string) {\n try {\n const rawContent = fs.readFileSync(filePath, \"utf-8\");\n const data = yaml.parse(rawContent);\n /**\n * @TODO add some zod validation maybe\n */\n return data as T;\n } catch (err) {\n throw new Error(\n `Failed to read YAML from ${filePath}: ${getErrorMessage(err)}`\n );\n }\n}\n\nexport function writeTypedYamlSync<T>(filePath: string, content: T) {\n /**\n * @TODO add some zod validation maybe\n */\n fs.writeFileSync(filePath, yaml.stringify(content), \"utf-8\");\n}\n","import fs from \"fs-extra\";\nimport path from \"node:path\";\nimport {\n PackageManifestMinimum,\n PackagesRegistry,\n adaptManifestWorkspaceDeps,\n getConfig,\n} from \"~/helpers\";\n\nexport async function adaptTargetPackageManifest(\n manifest: PackageManifestMinimum,\n packagesRegistry: PackagesRegistry,\n isolateDir: string,\n) {\n const outputManifest = adaptManifestWorkspaceDeps(\n {\n manifest,\n packagesRegistry,\n },\n { includeDevDependencies: getConfig().includeDevDependencies },\n );\n\n await fs.writeFile(\n path.join(isolateDir, \"package.json\"),\n JSON.stringify(outputManifest, null, 2),\n );\n}\n","import fs from \"fs-extra\";\nimport { isEmpty } from \"lodash-es\";\nimport path from \"node:path\";\nimport { createLogger, inspectValue, readTypedJsonSync } from \"~/utils\";\n\nexport type IsolateConfigResolved = {\n buildDirName?: string;\n includeDevDependencies: boolean;\n isolateDirName: string;\n logLevel: \"info\" | \"debug\" | \"warn\" | \"error\";\n targetPackagePath?: string;\n tsconfigPath: string;\n workspacePackages?: string[];\n workspaceRoot: string;\n excludeLockfile: boolean;\n};\n\nexport type IsolateConfig = Partial<IsolateConfigResolved>;\n\nconst configDefaults: IsolateConfigResolved = {\n buildDirName: undefined,\n includeDevDependencies: false,\n isolateDirName: \"isolate\",\n logLevel: \"info\",\n targetPackagePath: undefined,\n tsconfigPath: \"./tsconfig.json\",\n workspacePackages: undefined,\n workspaceRoot: \"../..\",\n excludeLockfile: false,\n};\n\n/**\n * Only initialize the configuration once, and keeping it here for subsequent\n * calls to getConfig.\n */\nlet __config: IsolateConfigResolved | undefined;\n\nconst validConfigKeys = Object.keys(configDefaults);\n\nconst CONFIG_FILE_NAME = \"isolate.config.json\";\n\ntype LogLevel = IsolateConfigResolved[\"logLevel\"];\n\nexport function getConfig(): IsolateConfigResolved {\n if (__config) {\n return __config;\n }\n\n /**\n * Since the logLevel is set via config we can't use it to determine if we\n * should output verbose logging as part of the config loading process. Using\n * the env var ISOLATE_CONFIG_LOG_LEVEL you have the option to log debug\n * output.\n */\n const log = createLogger(\n (process.env.ISOLATE_CONFIG_LOG_LEVEL as LogLevel) ?? \"warn\"\n );\n\n const configFilePath = path.join(process.cwd(), CONFIG_FILE_NAME);\n\n log.debug(`Attempting to load config from ${configFilePath}`);\n\n const configFromFile = fs.existsSync(configFilePath)\n ? readTypedJsonSync<IsolateConfig>(configFilePath)\n : {};\n\n const foreignKeys = Object.keys(configFromFile).filter(\n (key) => !validConfigKeys.includes(key)\n );\n\n if (!isEmpty(foreignKeys)) {\n log.warn(`Found invalid config settings:`, foreignKeys.join(\", \"));\n }\n\n const config = Object.assign(\n {},\n configDefaults,\n configFromFile\n ) satisfies IsolateConfigResolved;\n\n log.debug(\"Using configuration:\", inspectValue(config));\n\n __config = config;\n return config;\n}\n","import fs from \"fs-extra\";\nimport { globSync } from \"glob\";\nimport { set } from \"lodash-es\";\nimport path from \"node:path\";\nimport { createLogger, readTypedJson } from \"~/utils\";\nimport { getConfig } from \"./config\";\nimport { findPackagesGlobs } from \"./find-packages-globs\";\n\nexport type PackageManifestMinimum = {\n name: string;\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n main: string;\n module?: string;\n exports?: Record<string, { require: string; import: string }>;\n files: string[];\n version?: string;\n typings?: string;\n scripts?: Record<string, string>;\n};\n\nexport type WorkspacePackageInfo = {\n absoluteDir: string;\n /**\n * The path of the package relative to the workspace root. This is the path\n * referenced in the lock file.\n */\n rootRelativeDir: string;\n /**\n * The package.json file contents\n */\n manifest: PackageManifestMinimum;\n};\n\nexport type PackagesRegistry = Record<string, WorkspacePackageInfo>;\n\n/**\n * Build a list of all packages in the workspace, depending on the package\n * manager used, with a possible override from the config file. The list contains\n * the manifest with some directory info mapped by module name.\n */\nexport async function createPackagesRegistry(\n workspaceRootDir: string,\n workspacePackagesOverride: string[] | undefined\n): Promise<PackagesRegistry> {\n const log = createLogger(getConfig().logLevel);\n\n if (workspacePackagesOverride) {\n log.debug(\n `Override workspace packages via config: ${workspacePackagesOverride}`\n );\n }\n\n const packagesGlobs =\n workspacePackagesOverride ?? findPackagesGlobs(workspaceRootDir);\n\n const cwd = process.cwd();\n process.chdir(workspaceRootDir);\n\n const allPackages = packagesGlobs\n .flatMap((glob) => globSync(glob))\n /**\n * Make sure to filter any loose files that might hang around.\n */\n .filter((dir) => fs.lstatSync(dir).isDirectory());\n\n const registry: PackagesRegistry = (\n await Promise.all(\n allPackages.map(async (rootRelativeDir) => {\n const manifestPath = path.join(rootRelativeDir, \"package.json\");\n\n if (!fs.existsSync(manifestPath)) {\n log.warn(\n `Ignoring directory ./${rootRelativeDir} because it does not contain a package.json file`\n );\n return;\n } else {\n log.debug(`Registering package ./${rootRelativeDir}`);\n\n const manifest = await readTypedJson<PackageManifestMinimum>(\n path.join(rootRelativeDir, \"package.json\")\n );\n\n return {\n manifest,\n rootRelativeDir,\n absoluteDir: path.join(workspaceRootDir, rootRelativeDir),\n };\n }\n })\n )\n ).reduce<PackagesRegistry>(\n (acc, info) => (info ? set(acc, info.manifest.name, info) : acc),\n {}\n );\n\n process.chdir(cwd);\n\n return registry;\n}\n","import path from \"node:path\";\nimport {\n createLogger,\n inspectValue,\n readTypedJsonSync,\n readTypedYamlSync,\n} from \"~/utils\";\nimport { getConfig } from \"./config\";\nimport { detectPackageManager } from \"./detect-package-manager\";\n\n/**\n * Find the globs that define where the packages are located within the\n * monorepo. This configuration is dependent on the package manager used, and I\n * don't know if we're covering all cases yet...\n */\nexport function findPackagesGlobs(workspaceRootDir: string) {\n const log = createLogger(getConfig().logLevel);\n\n const packageManager = detectPackageManager(workspaceRootDir);\n\n switch (packageManager) {\n case \"pnpm\": {\n const { packages: globs } = readTypedYamlSync<{ packages: string[] }>(\n path.join(workspaceRootDir, \"pnpm-workspace.yaml\")\n );\n\n log.debug(\"Detected pnpm packages globs:\", inspectValue(globs));\n return globs;\n }\n case \"yarn\":\n case \"npm\": {\n const workspaceRootManifestPath = path.join(\n workspaceRootDir,\n \"package.json\"\n );\n\n const { workspaces } = readTypedJsonSync<{ workspaces: string[] }>(\n workspaceRootManifestPath\n );\n\n if (!workspaces) {\n throw new Error(\n `No workspaces field found in ${workspaceRootManifestPath}`\n );\n }\n\n return workspaces;\n }\n }\n}\n","import fs from \"fs-extra\";\nimport path from \"node:path\";\n\nexport type PackageManager = \"pnpm\" | \"yarn\" | \"npm\";\n\nexport function detectPackageManager(workspaceRoot: string): PackageManager {\n if (fs.existsSync(path.join(workspaceRoot, \"pnpm-lock.yaml\"))) {\n return \"pnpm\";\n }\n\n if (fs.existsSync(path.join(workspaceRoot, \"yarn.lock\"))) {\n return \"yarn\";\n }\n\n if (fs.existsSync(path.join(workspaceRoot, \"package-lock.json\"))) {\n return \"npm\";\n }\n\n throw new Error(`Failed to detect package manager`);\n}\n","import fs from \"fs-extra\";\nimport path from \"node:path\";\nimport outdent from \"outdent\";\nimport { getConfig } from \"~/helpers\";\nimport { createLogger, readTypedJson } from \"~/utils\";\n\nexport async function getBuildOutputDir(targetPackageDir: string) {\n const config = getConfig();\n const log = createLogger(getConfig().logLevel);\n\n if (config.buildDirName) {\n log.debug(\"Using buildDirName from config:\", config.buildDirName);\n return path.join(targetPackageDir, config.buildDirName);\n }\n\n const tsconfigPath = path.join(targetPackageDir, config.tsconfigPath);\n\n log.debug(\"Looking for tsconfig at:\", tsconfigPath);\n\n if (fs.existsSync(tsconfigPath)) {\n const tsconfig = await readTypedJson<{\n compilerOptions?: { outDir?: string };\n }>(tsconfigPath);\n\n const outDir = tsconfig.compilerOptions?.outDir;\n\n if (outDir) {\n return path.join(targetPackageDir, outDir);\n } else {\n throw new Error(outdent`\n Failed to find outDir in tsconfig. If you are executing isolate from the root of a monorepo you should specify the buildDirName in isolate.config.json.\n `);\n }\n } else {\n throw new Error(outdent`\n Failed to infer the build output directory from either the isolate config buildDirName or a Typescript config file. See the documentation on how to configure one of these options.\n `);\n }\n}\n","import {\n PackageManifestMinimum,\n PackagesRegistry,\n} from \"./create-packages-registry\";\n\n/**\n * Recursively list the packages from dependencies (and optionally\n * devDependencies) that are found in the workspace.\n *\n * Here we do not need to rely on packages being declared as \"workspace:\" in the\n * manifest. We can simply compare the package names with the list of packages\n * that were found via the workspace glob patterns and added to the registry.\n */\nexport function listLocalDependencies(\n manifest: PackageManifestMinimum,\n packagesRegistry: PackagesRegistry,\n { includeDevDependencies = false } = {},\n): string[] {\n const allWorkspacePackageNames = Object.keys(packagesRegistry);\n\n const localDependencyPackageNames = (\n includeDevDependencies\n ? [\n ...Object.keys(manifest.dependencies ?? {}),\n ...Object.keys(manifest.devDependencies ?? {}),\n ]\n : Object.keys(manifest.dependencies ?? {})\n ).filter((name) => allWorkspacePackageNames.includes(name));\n\n const nestedLocalDependencies = localDependencyPackageNames.flatMap(\n (packageName) =>\n listLocalDependencies(\n packagesRegistry[packageName].manifest,\n packagesRegistry,\n { includeDevDependencies },\n ),\n );\n\n return localDependencyPackageNames.concat(nestedLocalDependencies);\n}\n","import path from \"node:path\";\nimport { readTypedJson } from \"~/utils\";\nimport { PackageManifestMinimum } from \"./create-packages-registry\";\n\nexport async function importManifest(packageDir: string) {\n return readTypedJson<PackageManifestMinimum>(\n path.join(packageDir, \"package.json\"),\n );\n}\n","import assert from \"node:assert\";\nimport { createLogger, pack } from \"~/utils\";\nimport { getConfig } from \"./config\";\nimport { PackagesRegistry } from \"./create-packages-registry\";\nimport { PackageManager } from \"./detect-package-manager\";\n\n/**\n * Pack dependencies so that we extract only the files that are supposed to be\n * published by the packages.\n *\n * @returns A map of package names to the path of the packed file\n */\nexport async function packDependencies({\n /**\n * All packages found in the monorepo by workspaces declaration\n */\n packagesRegistry,\n /**\n * The package names that appear to be local dependencies\n */\n localDependencies,\n /**\n * The directory where the isolated package and all its dependencies will end\n * up. This is also the directory from where the package will be deployed. By\n * default it is a subfolder in targetPackageDir called \"isolate\" but you can\n * configure it.\n */\n packDestinationDir,\n\n packageManager,\n}: {\n packagesRegistry: PackagesRegistry;\n localDependencies: string[];\n packDestinationDir: string;\n packageManager: PackageManager;\n}) {\n const config = getConfig();\n const log = createLogger(config.logLevel);\n\n const packedFileByName: Record<string, string> = {};\n\n for (const dependency of localDependencies) {\n const def = packagesRegistry[dependency];\n\n assert(dependency, `Failed to find package definition for ${dependency}`);\n\n const { name } = def.manifest;\n\n /**\n * If this dependency has already been packed, we skip it. It could happen\n * because we are packing workspace dependencies recursively.\n */\n if (packedFileByName[name]) {\n log.debug(`Skipping ${name} because it has already been packed`);\n continue;\n }\n\n packedFileByName[name] = await pack(\n def.absoluteDir,\n packDestinationDir,\n packageManager,\n );\n\n /**\n * @TODO call recursively\n */\n }\n\n return packedFileByName;\n}\n","import { createLogger } from \"~/utils\";\nimport { getConfig } from \"./config\";\nimport { PackagesRegistry } from \"./create-packages-registry\";\n\nexport function patchWorkspaceEntries(\n dependencies: Record<string, string>,\n packagesRegistry: PackagesRegistry,\n) {\n const log = createLogger(getConfig().logLevel);\n const allWorkspacePackageNames = Object.keys(packagesRegistry);\n\n return Object.fromEntries(\n Object.entries(dependencies).map(([key, value]) => {\n if (allWorkspacePackageNames.includes(key)) {\n const def = packagesRegistry[key];\n\n /**\n * The rootRelativeDir is the package location in the monorepo. In the\n * isolate folder we keep the same structure so we can use the same\n * relative path.\n */\n log.debug(`Linking dependency ${key} to file:${def.rootRelativeDir}`);\n\n return [key, `file:${def.rootRelativeDir}`];\n } else {\n return [key, value];\n }\n }),\n );\n}\n","import fs from \"fs-extra\";\nimport path from \"node:path\";\nimport { PackageManager } from \"~/helpers\";\nimport { pack, unpack } from \"~/utils\";\n\nexport async function processBuildOutputFiles({\n targetPackageDir,\n tmpDir,\n packageManager,\n isolateDir,\n}: {\n targetPackageDir: string;\n tmpDir: string;\n packageManager: PackageManager;\n isolateDir: string;\n}) {\n const packedFilePath = await pack(targetPackageDir, tmpDir, packageManager);\n const unpackDir = path.join(tmpDir, \"target\");\n await unpack(packedFilePath, unpackDir);\n await fs.copy(path.join(unpackDir, \"package\"), isolateDir);\n}\n","import fs from \"fs-extra\";\nimport assert from \"node:assert\";\nimport path from \"node:path\";\nimport { createLogger, readTypedYamlSync, writeTypedYamlSync } from \"~/utils\";\nimport { getConfig } from \"./config\";\nimport { PackagesRegistry } from \"./create-packages-registry\";\nimport { PackageManager } from \"./detect-package-manager\";\n\ntype PackagePath = string;\n\ntype PnpmLockfile = {\n lockfileVersion: string;\n importers: Record<\n PackagePath,\n {\n dependencies?: Record<string, unknown>;\n devDependencies?: Record<string, unknown>;\n }\n >;\n};\n\nexport function getLockfileFileName(packageManager: PackageManager) {\n switch (packageManager) {\n case \"pnpm\":\n return \"pnpm-lock.yaml\";\n case \"yarn\":\n return \"yarn.lock\";\n case \"npm\":\n return \"package-lock.json\";\n }\n}\n\n/**\n * Adapt the lockfile and write it to the isolate directory. Because we keep the\n * structure of packages in the isolate directory the same as they were in the\n * monorepo, the lockfile is largely still correct. The only things that need to\n * be done is to remove the root dependencies and devDependencies, and rename\n * the path to the target package to act as the new root.\n */\nexport function processLockfile({\n workspaceRootDir,\n targetPackageName,\n packagesRegistry,\n isolateDir,\n packageManager,\n}: {\n workspaceRootDir: string;\n targetPackageName: string;\n packagesRegistry: PackagesRegistry;\n isolateDir: string;\n packageManager: PackageManager;\n}) {\n const log = createLogger(getConfig().logLevel);\n\n const targetPackageRelativeDir =\n packagesRegistry[targetPackageName].rootRelativeDir;\n\n const fileName = getLockfileFileName(packageManager);\n\n const lockfileSrcPath = path.join(workspaceRootDir, fileName);\n const lockfileDstPath = path.join(isolateDir, fileName);\n\n switch (packageManager) {\n /**\n * It seems that for Yarn v1 and NPM v3 lockfile the content is not\n * dependent on the workspace packages structure, so I am assuming we can\n * just copy it over.\n */\n case \"npm\":\n case \"yarn\": {\n fs.copyFileSync(lockfileSrcPath, lockfileDstPath);\n log.debug(\"Copied lockfile to\", lockfileDstPath);\n return;\n }\n case \"pnpm\": {\n const origLockfile = readTypedYamlSync<PnpmLockfile>(lockfileSrcPath);\n\n log.debug(\"Read PNPM lockfile, version:\", origLockfile.lockfileVersion);\n\n const adaptedLockfile = structuredClone(origLockfile);\n\n const targetPackageDef =\n adaptedLockfile.importers[targetPackageRelativeDir];\n\n assert(\n targetPackageDef,\n `Failed to find target package in lockfile at importers[${targetPackageRelativeDir}]`\n );\n /**\n * Overwrite the root importer with the target package importer contents\n */\n adaptedLockfile.importers[\".\"] = targetPackageDef;\n\n /**\n * Delete the target package original importer. Not really necessary.\n */\n delete adaptedLockfile.importers[targetPackageRelativeDir];\n\n writeTypedYamlSync(lockfileDstPath, adaptedLockfile);\n\n log.debug(\"Stored adapted lockfile at\", lockfileDstPath);\n\n return;\n }\n\n // case \"npm\": {\n // /**\n // * Assuming a v3 lockfile.\n // */\n // const origLockfile = readTypedJsonSync<NpmLockfile_v3>(lockfileSrcPath);\n\n // /**\n // * Overwrite the root importer with the target package importer contents\n // */\n // const adaptedLockfile = structuredClone(origLockfile);\n\n // const targetPackageDef =\n // adaptedLockfile.packages[targetPackageRelativeDir];\n\n // assert(\n // targetPackageDef,\n // `Failed to find target package in lockfile at packages[${targetPackageRelativeDir}]`\n // );\n\n // /**\n // * The root in the NPM lockfile seems to be marked by an empty string\n // */\n // adaptedLockfile.packages[\"\"] = targetPackageDef;\n\n // /**\n // * Delete the target package original importer. Not really necessary.\n // */\n // delete adaptedLockfile.packages[targetPackageRelativeDir];\n\n // writeTypedYamlSync(lockfileDstPath, adaptedLockfile);\n\n // log.debug(\"Stored adapted lockfile at\", lockfileDstPath);\n // }\n }\n}\n","import fs from \"fs-extra\";\nimport { dir } from \"node:console\";\nimport path, { join } from \"node:path\";\nimport { getIsolateRelativePath, getRootRelativePath } from \"~/utils\";\nimport { createLogger } from \"~/utils/logger\";\nimport { PackagesRegistry, getConfig } from \".\";\nimport { unpack } from \"../utils/unpack\";\n\nexport async function unpackDependencies(\n packedFilesByName: Record<string, string>,\n packagesRegistry: PackagesRegistry,\n tmpDir: string,\n isolateDir: string\n) {\n const log = createLogger(getConfig().logLevel);\n await Promise.all(\n Object.entries(packedFilesByName).map(async ([packageName, filePath]) => {\n const dir = packagesRegistry[packageName].rootRelativeDir;\n\n const unpackDir = join(tmpDir, dir);\n\n // log.debug(\"Unpacking\", path.basename(filePath));\n log.debug(\"Unpacking\", filePath);\n\n await unpack(filePath, unpackDir);\n\n const destinationDir = join(isolateDir, dir);\n\n await fs.ensureDir(destinationDir);\n\n await fs.move(join(unpackDir, \"package\"), destinationDir, {\n overwrite: true,\n });\n\n log.debug(\n `Moved package files to ${getIsolateRelativePath(\n destinationDir,\n isolateDir\n )}`\n );\n })\n );\n}\n"],"mappings":";;;AAEA,OAAOA,UAAQ;AACf,OAAOC,aAAY;AACnB,OAAOC,YAAU;AACjB,OAAO,g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A,IACrBF,OAAK,KAAK,kBAAkB,cAAc;AAAA,EAC5C;AAEA,QAAM,oBAAoB,sBAAsB,UAAU,kBAAkB;AAAA,IAC1E,wBAAwB,OAAO;AAAA,EACjC,CAAC;AAED,QAAM,oBAAoB,MAAM,iBAAiB;AAAA,IAC/C;AAAA,IACA;AAAA,IACA,oBAAoB;AAAA,IACpB;AAAA,EACF,CAAC;AAED,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAKA,QAAM,mBAAmB,mBAAmB,kBAAkB,UAAU;AAKxE,QAAM,wBAAwB;AAAA,IAC5B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAMD,QAAM,2BAA2B,UAAU,kBAAkB,UAAU;AAEvE,MAAI,OAAO,iBAAiB;AAC1B,QAAI,KAAK,gDAAgD;AAAA,EAC3D,OAAO;AAIL,UAAM,gBAAgB;AAAA,MACpB;AAAA,MACA,mBAAmB,SAAS;AAAA,MAC5B;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AAMA,MAAI;AAAA,IACF;AAAA,IACA,oBAAoB,QAAQ,gBAAgB;AAAA,EAC9C;AACA,QAAME,KAAG,OAAO,MAAM;AAEtB,MAAI,MAAM,4BAA4B,UAAU;AAEhD,MAAI,KAAK,mBAAmB;AAC9B;AAEA,MAAM,EAAE,MAAM,CAAC,QAAQ;AACrB,MAAI,eAAe,OAAO;AACxB,QAAI,MAAM,IAAI,KAAK;AACnB,YAAQ,KAAK,CAAC;AAAA,EAChB,OAAO;AACL,YAAQ,MAAM,GAAG;AAAA,EACnB;AACF,CAAC;AAED,QAAQ,GAAG,sBAAsB,IAAI,KAAK;","names":["fs","assert","path","path","fs","fs","path","log","stdout","path","fs","fs","fs","fs","path","fs","path","fs","path","log","path","fs","config","fs","path","path","fs","path","log","path","log","fs","path","fs","path","config","log","path","fs","path","config","log","log","fs","path","path","fs","fs","assert","path","log","path","fs","assert","fs","log","fs","path","assert","fs"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/helpers/adapt-manifest-files.ts","../src/utils/filter-object-undefined.ts","../src/utils/get-error-message.ts","../src/utils/get-relative-path.ts","../src/utils/inspect-value.ts","../src/utils/json.ts","../src/utils/logger.ts","../src/utils/pack.ts","../src/utils/unpack.ts","../src/utils/yaml.ts","../src/helpers/adapt-manifest-workspace-deps.ts","../src/helpers/adapt-target-package-manifest.ts","../src/helpers/config.ts","../src/helpers/create-packages-registry.ts","../src/helpers/find-packages-globs.ts","../src/helpers/detect-package-manager.ts","../src/helpers/process-lockfile.ts","../src/helpers/get-build-output-dir.ts","../src/helpers/list-local-dependencies.ts","../src/helpers/manifest.ts","../src/helpers/pack-dependencies.ts","../src/helpers/patch-workspace-entries.ts","../src/helpers/process-build-output-files.ts","../src/helpers/unpack-dependencies.ts"],"sourcesContent":["#!/usr/bin/env node\n\n/**\n * A word about used terminology:\n *\n * The various package managers, while being very similar, seem to use a\n * different definition for the term \"workspace\". If you want to read the code it\n * might be good to know that I consider the workspace to be the monorepo itself,\n * in other words, the overall structure that holds all the packages.\n */\n\nimport fs from \"fs-extra\";\nimport assert from \"node:assert\";\nimport path from \"node:path\";\nimport sourceMaps from \"source-map-support\";\nimport {\n PackageManifest,\n adaptManifestFiles,\n adaptTargetPackageManifest,\n createPackagesRegistry,\n detectPackageManager,\n getBuildOutputDir,\n getConfig,\n listLocalDependencies,\n packDependencies,\n processBuildOutputFiles,\n processLockfile,\n unpackDependencies,\n} from \"~/helpers\";\nimport { createLogger, getRootRelativePath, readTypedJson } from \"~/utils\";\n\nconst config = getConfig();\nconst log = createLogger(config.logLevel);\n\nsourceMaps.install();\n\nasync function start() {\n /**\n * If a targetPackagePath is set, we assume the configuration lives in the\n * root of the workspace. If targetPackagePath is undefined (the default), we\n * assume that the configuration lives in the target package directory.\n */\n const targetPackageDir = config.targetPackagePath\n ? path.join(process.cwd(), config.targetPackagePath)\n : process.cwd();\n\n /**\n * We want a trailing slash here. Functionally it doesn't matter, but it makes\n * the relative paths more correct in the debug output.\n */\n const workspaceRootDir = config.targetPackagePath\n ? process.cwd()\n : path.join(targetPackageDir, config.workspaceRoot);\n\n const buildOutputDir = await getBuildOutputDir(targetPackageDir);\n\n assert(\n fs.existsSync(buildOutputDir),\n `Failed to find build output path at ${buildOutputDir}. Please make sure you build the source before isolating it.`\n );\n\n log.debug(\"Workspace root\", workspaceRootDir);\n log.debug(\n \"Isolate target package\",\n getRootRelativePath(targetPackageDir, workspaceRootDir)\n );\n\n const isolateDir = path.join(targetPackageDir, config.isolateDirName);\n\n log.debug(\n \"Isolate output directory\",\n getRootRelativePath(isolateDir, workspaceRootDir)\n );\n\n if (fs.existsSync(isolateDir)) {\n await fs.remove(isolateDir);\n log.debug(\"Cleaned the existing isolate output directory\");\n }\n\n await fs.ensureDir(isolateDir);\n\n const tmpDir = path.join(isolateDir, \"__tmp\");\n await fs.ensureDir(tmpDir);\n\n const targetPackageManifest = await readTypedJson<PackageManifest>(\n path.join(targetPackageDir, \"package.json\")\n );\n\n const { name, version } = detectPackageManager(workspaceRootDir);\n\n log.debug(\"Detected package manager\", name, version);\n\n /**\n * Disable lock files for PNPM because they are not yet supported.\n */\n if (name === \"pnpm\") {\n config.excludeLockfile = true;\n }\n\n /**\n * Build a packages registry so we can find the workspace packages by name and\n * have access to their manifest files and relative paths.\n */\n const packagesRegistry = await createPackagesRegistry(\n workspaceRootDir,\n config.workspacePackages\n );\n\n const localDependencies = listLocalDependencies(\n targetPackageManifest,\n packagesRegistry,\n {\n includeDevDependencies: config.includeDevDependencies,\n }\n );\n\n const packedFilesByName = await packDependencies({\n localDependencies,\n packagesRegistry,\n packDestinationDir: tmpDir,\n });\n\n await unpackDependencies(\n packedFilesByName,\n packagesRegistry,\n tmpDir,\n isolateDir\n );\n\n /**\n * Adapt the manifest files for all the unpacked local dependencies\n */\n await adaptManifestFiles(localDependencies, packagesRegistry, isolateDir);\n\n /**\n * Pack the target package directory, and unpack it in the isolate location\n */\n await processBuildOutputFiles({\n targetPackageDir,\n tmpDir,\n isolateDir,\n });\n\n /**\n * Copy the target manifest file to the isolate location and adapt its\n * workspace dependencies to point to the isolated packages.\n */\n await adaptTargetPackageManifest(\n targetPackageManifest,\n packagesRegistry,\n isolateDir\n );\n\n if (config.excludeLockfile) {\n log.warn(\"Excluding the lockfile from the isolate output\");\n } else {\n /**\n * Copy and adapt the lockfile\n */\n await processLockfile({\n workspaceRootDir,\n targetPackageName: targetPackageManifest.name,\n isolateDir,\n packagesRegistry,\n });\n }\n\n /**\n * Clean up. Only so this in the happy path, so we can look at the temp folder\n * when thing go wrong.\n */\n log.debug(\n \"Deleting temporary directory\",\n getRootRelativePath(tmpDir, workspaceRootDir)\n );\n await fs.remove(tmpDir);\n\n log.debug(\"Stored isolate output at\", isolateDir);\n\n log.info(\"Isolate completed\");\n}\n\nstart().catch((err) => {\n if (err instanceof Error) {\n log.error(err.stack);\n process.exit(1);\n } else {\n console.error(err);\n }\n});\n\nprocess.on(\"unhandledRejection\", log.error);\n","import fs from \"fs-extra\";\nimport path from \"node:path\";\nimport {\n PackagesRegistry,\n adaptManifestWorkspaceDeps,\n getConfig,\n} from \"~/helpers\";\nimport { createLogger } from \"~/utils\";\n\nexport async function adaptManifestFiles(\n localDependencies: string[],\n packagesRegistry: PackagesRegistry,\n isolateDir: string\n) {\n const log = createLogger(getConfig().logLevel);\n\n await Promise.all(\n localDependencies.map(async (packageName) => {\n const { manifest, rootRelativeDir } = packagesRegistry[packageName];\n\n log.debug(\"Adapting manifest file:\", packageName);\n\n const outputManifest = adaptManifestWorkspaceDeps(\n { manifest, packagesRegistry, parentRootRelativeDir: rootRelativeDir },\n { includeDevDependencies: getConfig().includeDevDependencies }\n );\n\n await fs.writeFile(\n path.join(isolateDir, rootRelativeDir, \"package.json\"),\n JSON.stringify(outputManifest, null, 2)\n );\n })\n );\n}\n","export function filterObjectUndefined(object: Record<string, unknown>) {\n return Object.fromEntries(\n Object.entries(object).filter(([_, value]) => value !== undefined)\n );\n}\n","type ErrorWithMessage = {\n message: string;\n};\n\nexport function getErrorMessage(error: unknown) {\n return toErrorWithMessage(error).message;\n}\n\nfunction isErrorWithMessage(error: unknown): error is ErrorWithMessage {\n return typeof error === \"object\" && error !== null && \"message\" in error;\n}\n\nfunction toErrorWithMessage(maybeError: unknown): ErrorWithMessage {\n if (isErrorWithMessage(maybeError)) return maybeError;\n\n try {\n return new Error(JSON.stringify(maybeError));\n } catch {\n /**\n * Fallback in case there’s an error stringifying the maybeError\n * like with circular references.\n */\n return new Error(String(maybeError));\n }\n}\n","export function getRootRelativePath(path: string, rootPath: string) {\n const strippedPath = path.replace(rootPath, \"\");\n\n return strippedPath.startsWith(\"/\")\n ? `(root)${strippedPath}`\n : `(root)/${strippedPath}`;\n}\n\nexport function getIsolateRelativePath(path: string, isolatePath: string) {\n const strippedPath = path.replace(isolatePath, \"\");\n\n return strippedPath.startsWith(\"/\")\n ? `(isolate)${strippedPath}`\n : `(isolate)/${strippedPath}`;\n}\n","import { inspect } from \"node:util\";\nimport { JsonValue } from \"type-fest\";\n\nexport function inspectValue(value: JsonValue) {\n return inspect(value, false, 4, true);\n}\n","import fs from \"fs-extra\";\nimport stripJsonComments from \"strip-json-comments\";\nimport { getErrorMessage } from \"./get-error-message\";\n\n/**\n * @TODO pass in zod schema and validate\n */\nexport function readTypedJsonSync<T>(filePath: string) {\n try {\n const rawContent = fs.readFileSync(filePath, \"utf-8\");\n const data = JSON.parse(stripJsonComments(rawContent)) as T;\n return data;\n } catch (err) {\n throw new Error(\n `Failed to read JSON from ${filePath}: ${getErrorMessage(err)}`\n );\n }\n}\n\nexport async function readTypedJson<T>(filePath: string) {\n try {\n const rawContent = await fs.readFile(filePath, \"utf-8\");\n const data = JSON.parse(rawContent) as T;\n return data;\n } catch (err) {\n throw new Error(\n `Failed to read JSON from ${filePath}: ${getErrorMessage(err)}`\n );\n }\n}\n","import chalk from \"chalk\";\nimport { IsolateConfigResolved } from \"~/helpers\";\n\nexport type Logger = {\n debug(...args: any[]): void;\n info(...args: any[]): void;\n warn(...args: any[]): void;\n error(...args: any[]): void;\n};\n\nexport function createLogger(\n logLevel: IsolateConfigResolved[\"logLevel\"]\n): Logger {\n return {\n debug(...args: any[]) {\n if (logLevel === \"debug\") {\n console.log(chalk.blue(\"debug\"), ...args);\n }\n },\n info(...args: any[]) {\n if (logLevel === \"debug\" || logLevel === \"info\") {\n console.log(chalk.green(\"info\"), ...args);\n }\n },\n warn(...args: any[]) {\n if (logLevel === \"debug\" || logLevel === \"info\" || logLevel === \"warn\") {\n console.log(chalk.yellow(\"warning\"), ...args);\n }\n },\n error(...args: any[]) {\n console.log(chalk.red(\"error\"), ...args);\n },\n };\n}\n","import { exec } from \"node:child_process\";\nimport path from \"node:path\";\nimport { getConfig, usePackageManager } from \"~/helpers\";\nimport { createLogger } from \"./logger\";\n\nexport async function pack(srcDir: string, destDir: string) {\n const log = createLogger(getConfig().logLevel);\n const cwd = process.cwd();\n process.chdir(srcDir);\n\n const { name } = usePackageManager();\n\n /**\n * PNPM pack seems to be a lot faster than NPM pack, so when PNPM is detected\n * we use that instead.\n */\n switch (name) {\n case \"pnpm\": {\n const stdout = await new Promise<string>((resolve, reject) => {\n exec(\n `pnpm pack --pack-destination ${destDir}`,\n (err, stdout, stderr) => {\n if (err) {\n log.error(stderr);\n return reject(err);\n }\n\n resolve(stdout);\n }\n );\n });\n\n /**\n * @TODO use a regex to see if the result from stdout is a valid file\n * path. It could be that other output like warnings are printed. In that\n * case we can to log the stdout.\n */\n\n /**\n * Trim newlines and whitespace\n */\n const packedFilePath = stdout.trim();\n\n // log.debug(\"Packed\", path.basename(packedFilePath));\n log.debug(\"Packed\", packedFilePath);\n\n process.chdir(cwd);\n return packedFilePath;\n }\n\n case \"yarn\":\n case \"npm\": {\n const stdout = await new Promise<string>((resolve, reject) => {\n exec(`npm pack --pack-destination ${destDir}`, (err, stdout) => {\n if (err) {\n return reject(err);\n }\n\n resolve(stdout);\n });\n });\n\n /**\n * Trim newlines and whitespace\n */\n const packedFileName = stdout.trim();\n\n log.debug(\"Packed\", packedFileName);\n\n process.chdir(cwd);\n return path.join(destDir, packedFileName);\n }\n }\n}\n","import fs from \"fs-extra\";\nimport tar from \"tar-fs\";\nimport { createGunzip } from \"zlib\";\n\nexport async function unpack(filePath: string, unpackDir: string) {\n await new Promise<void>((resolve, reject) => {\n fs.createReadStream(filePath)\n .pipe(createGunzip())\n .pipe(tar.extract(unpackDir))\n .on(\"finish\", () => resolve())\n .on(\"error\", (err) => reject(err));\n });\n}\n","import fs from \"fs-extra\";\nimport yaml from \"yaml\";\nimport { getErrorMessage } from \"./get-error-message\";\n\nexport function readTypedYamlSync<T>(filePath: string) {\n try {\n const rawContent = fs.readFileSync(filePath, \"utf-8\");\n const data = yaml.parse(rawContent);\n /**\n * @TODO add some zod validation maybe\n */\n return data as T;\n } catch (err) {\n throw new Error(\n `Failed to read YAML from ${filePath}: ${getErrorMessage(err)}`\n );\n }\n}\n\nexport function writeTypedYamlSync<T>(filePath: string, content: T) {\n /**\n * @TODO add some zod validation maybe\n */\n fs.writeFileSync(filePath, yaml.stringify(content), \"utf-8\");\n}\n","import { omit } from \"lodash-es\";\nimport { filterObjectUndefined } from \"~/utils\";\nimport { PackageManifest, PackagesRegistry, patchWorkspaceEntries } from \".\";\n\nexport function adaptManifestWorkspaceDeps(\n {\n manifest,\n packagesRegistry,\n parentRootRelativeDir,\n }: {\n manifest: PackageManifest;\n packagesRegistry: PackagesRegistry;\n parentRootRelativeDir?: string;\n },\n opts: { includeDevDependencies?: boolean } = {}\n): PackageManifest {\n return Object.assign(\n omit(manifest, [\"scripts\", \"devDependencies\"]),\n filterObjectUndefined({\n dependencies: manifest.dependencies\n ? patchWorkspaceEntries(\n manifest.dependencies,\n packagesRegistry,\n parentRootRelativeDir\n )\n : undefined,\n devDependencies:\n opts.includeDevDependencies && manifest.devDependencies\n ? patchWorkspaceEntries(\n manifest.devDependencies,\n packagesRegistry,\n parentRootRelativeDir\n )\n : undefined,\n })\n );\n}\n","import fs from \"fs-extra\";\nimport path from \"node:path\";\nimport {\n PackageManifest,\n PackagesRegistry,\n adaptManifestWorkspaceDeps,\n getConfig,\n} from \"~/helpers\";\n\nexport async function adaptTargetPackageManifest(\n manifest: PackageManifest,\n packagesRegistry: PackagesRegistry,\n isolateDir: string\n) {\n const outputManifest = adaptManifestWorkspaceDeps(\n {\n manifest,\n packagesRegistry,\n },\n { includeDevDependencies: getConfig().includeDevDependencies }\n );\n\n await fs.writeFile(\n path.join(isolateDir, \"package.json\"),\n JSON.stringify(outputManifest, null, 2)\n );\n}\n","import fs from \"fs-extra\";\nimport { isEmpty } from \"lodash-es\";\nimport path from \"node:path\";\nimport { createLogger, inspectValue, readTypedJsonSync } from \"~/utils\";\n\nexport type IsolateConfigResolved = {\n buildDirName?: string;\n includeDevDependencies: boolean;\n isolateDirName: string;\n logLevel: \"info\" | \"debug\" | \"warn\" | \"error\";\n targetPackagePath?: string;\n tsconfigPath: string;\n workspacePackages?: string[];\n workspaceRoot: string;\n excludeLockfile: boolean;\n};\n\nexport type IsolateConfig = Partial<IsolateConfigResolved>;\n\nconst configDefaults: IsolateConfigResolved = {\n buildDirName: undefined,\n includeDevDependencies: false,\n isolateDirName: \"isolate\",\n logLevel: \"info\",\n targetPackagePath: undefined,\n tsconfigPath: \"./tsconfig.json\",\n workspacePackages: undefined,\n workspaceRoot: \"../..\",\n excludeLockfile: false,\n};\n\n/**\n * Only initialize the configuration once, and keeping it here for subsequent\n * calls to getConfig.\n */\nlet __config: IsolateConfigResolved | undefined;\n\nconst validConfigKeys = Object.keys(configDefaults);\n\nconst CONFIG_FILE_NAME = \"isolate.config.json\";\n\ntype LogLevel = IsolateConfigResolved[\"logLevel\"];\n\nexport function getConfig(): IsolateConfigResolved {\n if (__config) {\n return __config;\n }\n\n /**\n * Since the logLevel is set via config we can't use it to determine if we\n * should output verbose logging as part of the config loading process. Using\n * the env var ISOLATE_CONFIG_LOG_LEVEL you have the option to log debug\n * output.\n */\n const log = createLogger(\n (process.env.ISOLATE_CONFIG_LOG_LEVEL as LogLevel) ?? \"warn\"\n );\n\n const configFilePath = path.join(process.cwd(), CONFIG_FILE_NAME);\n\n log.debug(`Attempting to load config from ${configFilePath}`);\n\n const configFromFile = fs.existsSync(configFilePath)\n ? readTypedJsonSync<IsolateConfig>(configFilePath)\n : {};\n\n const foreignKeys = Object.keys(configFromFile).filter(\n (key) => !validConfigKeys.includes(key)\n );\n\n if (!isEmpty(foreignKeys)) {\n log.warn(`Found invalid config settings:`, foreignKeys.join(\", \"));\n }\n\n const config = Object.assign(\n {},\n configDefaults,\n configFromFile\n ) satisfies IsolateConfigResolved;\n\n log.debug(\"Using configuration:\", inspectValue(config));\n\n __config = config;\n return config;\n}\n","import fs from \"fs-extra\";\nimport { globSync } from \"glob\";\nimport { set } from \"lodash-es\";\nimport path from \"node:path\";\nimport { createLogger, readTypedJson } from \"~/utils\";\nimport { getConfig } from \"./config\";\nimport { findPackagesGlobs } from \"./find-packages-globs\";\n\nexport type PackageManifest = {\n name: string;\n packageManager?: string;\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n main: string;\n module?: string;\n exports?: Record<string, { require: string; import: string }>;\n files: string[];\n version?: string;\n typings?: string;\n scripts?: Record<string, string>;\n};\n\nexport type WorkspacePackageInfo = {\n absoluteDir: string;\n /**\n * The path of the package relative to the workspace root. This is the path\n * referenced in the lock file.\n */\n rootRelativeDir: string;\n /**\n * The package.json file contents\n */\n manifest: PackageManifest;\n};\n\nexport type PackagesRegistry = Record<string, WorkspacePackageInfo>;\n\n/**\n * Build a list of all packages in the workspace, depending on the package\n * manager used, with a possible override from the config file. The list contains\n * the manifest with some directory info mapped by module name.\n */\nexport async function createPackagesRegistry(\n workspaceRootDir: string,\n workspacePackagesOverride: string[] | undefined\n): Promise<PackagesRegistry> {\n const log = createLogger(getConfig().logLevel);\n\n if (workspacePackagesOverride) {\n log.debug(\n `Override workspace packages via config: ${workspacePackagesOverride}`\n );\n }\n\n const packagesGlobs =\n workspacePackagesOverride ?? findPackagesGlobs(workspaceRootDir);\n\n const cwd = process.cwd();\n process.chdir(workspaceRootDir);\n\n const allPackages = packagesGlobs\n .flatMap((glob) => globSync(glob))\n /**\n * Make sure to filter any loose files that might hang around.\n */\n .filter((dir) => fs.lstatSync(dir).isDirectory());\n\n const registry: PackagesRegistry = (\n await Promise.all(\n allPackages.map(async (rootRelativeDir) => {\n const manifestPath = path.join(rootRelativeDir, \"package.json\");\n\n if (!fs.existsSync(manifestPath)) {\n log.warn(\n `Ignoring directory ./${rootRelativeDir} because it does not contain a package.json file`\n );\n return;\n } else {\n log.debug(`Registering package ./${rootRelativeDir}`);\n\n const manifest = await readTypedJson<PackageManifest>(\n path.join(rootRelativeDir, \"package.json\")\n );\n\n return {\n manifest,\n rootRelativeDir,\n absoluteDir: path.join(workspaceRootDir, rootRelativeDir),\n };\n }\n })\n )\n ).reduce<PackagesRegistry>(\n (acc, info) => (info ? set(acc, info.manifest.name, info) : acc),\n {}\n );\n\n process.chdir(cwd);\n\n return registry;\n}\n","import path from \"node:path\";\nimport {\n createLogger,\n inspectValue,\n readTypedJsonSync,\n readTypedYamlSync,\n} from \"~/utils\";\nimport { getConfig } from \"./config\";\nimport { usePackageManager } from \"./detect-package-manager\";\n\n/**\n * Find the globs that define where the packages are located within the\n * monorepo. This configuration is dependent on the package manager used, and I\n * don't know if we're covering all cases yet...\n */\nexport function findPackagesGlobs(workspaceRootDir: string) {\n const log = createLogger(getConfig().logLevel);\n\n const packageManager = usePackageManager();\n\n switch (packageManager.name) {\n case \"pnpm\": {\n const { packages: globs } = readTypedYamlSync<{ packages: string[] }>(\n path.join(workspaceRootDir, \"pnpm-workspace.yaml\")\n );\n\n log.debug(\"Detected pnpm packages globs:\", inspectValue(globs));\n return globs;\n }\n case \"yarn\":\n case \"npm\": {\n const workspaceRootManifestPath = path.join(\n workspaceRootDir,\n \"package.json\"\n );\n\n const { workspaces } = readTypedJsonSync<{ workspaces: string[] }>(\n workspaceRootManifestPath\n );\n\n if (!workspaces) {\n throw new Error(\n `No workspaces field found in ${workspaceRootManifestPath}`\n );\n }\n\n return workspaces;\n }\n }\n}\n","import fs from \"fs-extra\";\nimport assert from \"node:assert\";\nimport { execSync } from \"node:child_process\";\nimport path from \"node:path\";\nimport { createLogger, readTypedJsonSync } from \"~/utils\";\nimport { getConfig } from \"./config\";\nimport { PackageManifest } from \"./create-packages-registry\";\nimport { getLockfileFileName } from \"./process-lockfile\";\n\nconst supportedPackageManagerNames = [\"pnpm\", \"yarn\", \"npm\"] as const;\n\nexport type PackageManagerName = (typeof supportedPackageManagerNames)[number];\n\nexport type PackageManager = {\n name: PackageManagerName;\n version: string;\n};\n\nlet packageManager: PackageManager | undefined;\n\n/**\n * First we check if the package manager is declared in the manifest. If it is,\n * we get the name and version from there. Otherwise we'll search for the\n * different lockfiles and ask the OS to report the installed version.\n */\nexport function detectPackageManager(workspaceRoot: string): PackageManager {\n /**\n * Disable infer from manifest. I doubt it is useful after all\n */\n // packageManager =\n // inferFromManifest(workspaceRoot) ?? inferFromFiles(workspaceRoot);\n\n packageManager = inferFromFiles(workspaceRoot);\n return packageManager;\n}\n\nfunction inferFromManifest(workspaceRoot: string) {\n const log = createLogger(getConfig().logLevel);\n\n const rootManifest = readTypedJsonSync<PackageManifest>(\n path.join(workspaceRoot, \"package.json\")\n );\n\n if (!rootManifest.packageManager) {\n log.debug(\"No packageManager field found in root manifest\");\n return;\n }\n\n const [name, version = \"*\"] = rootManifest.packageManager.split(\"@\") as [\n PackageManagerName,\n string,\n ];\n\n assert(\n supportedPackageManagerNames.includes(name),\n `Package manager \"${name}\" is not currently supported`\n );\n\n const lockfileName = getLockfileFileName(name);\n\n assert(\n fs.existsSync(path.join(workspaceRoot, lockfileName)),\n `Manifest declares ${name} to be the packageManager, but failed to find ${lockfileName} in workspace root`\n );\n\n return { name, version };\n}\n\nfunction inferFromFiles(workspaceRoot: string): PackageManager {\n for (const name of supportedPackageManagerNames) {\n const lockfileName = getLockfileFileName(name);\n\n if (fs.existsSync(path.join(workspaceRoot, lockfileName))) {\n return { name, version: getVersion(name) };\n }\n }\n\n throw new Error(`Failed to detect package manager`);\n}\n\nfunction getVersion(packageManagerName: PackageManagerName): string {\n const buffer = execSync(`${packageManagerName} --version`);\n return buffer.toString().trim();\n}\n\nexport function usePackageManager() {\n if (!packageManager) {\n throw Error(\n \"No package manager detected. Make sure to call detectPackageManager() before usePackageManager()\"\n );\n }\n\n return packageManager;\n}\n","import fs from \"fs-extra\";\nimport assert from \"node:assert\";\nimport path from \"node:path\";\nimport { createLogger, readTypedYamlSync, writeTypedYamlSync } from \"~/utils\";\nimport { getConfig } from \"./config\";\nimport { PackagesRegistry } from \"./create-packages-registry\";\nimport {\n PackageManagerName,\n usePackageManager,\n} from \"./detect-package-manager\";\n\ntype PackagePath = string;\n\ntype PnpmLockfile = {\n lockfileVersion: string;\n importers: Record<\n PackagePath,\n {\n dependencies?: Record<string, unknown>;\n devDependencies?: Record<string, unknown>;\n }\n >;\n};\n\nexport function getLockfileFileName(name: PackageManagerName) {\n switch (name) {\n case \"pnpm\":\n return \"pnpm-lock.yaml\";\n case \"yarn\":\n return \"yarn.lock\";\n case \"npm\":\n return \"package-lock.json\";\n }\n}\n\n/**\n * Adapt the lockfile and write it to the isolate directory. Because we keep the\n * structure of packages in the isolate directory the same as they were in the\n * monorepo, the lockfile is largely still correct. The only things that need to\n * be done is to remove the root dependencies and devDependencies, and rename\n * the path to the target package to act as the new root.\n */\nexport function processLockfile({\n workspaceRootDir,\n targetPackageName,\n packagesRegistry,\n isolateDir,\n}: {\n workspaceRootDir: string;\n targetPackageName: string;\n packagesRegistry: PackagesRegistry;\n isolateDir: string;\n}) {\n const log = createLogger(getConfig().logLevel);\n\n const targetPackageRelativeDir =\n packagesRegistry[targetPackageName].rootRelativeDir;\n\n const { name } = usePackageManager();\n\n const fileName = getLockfileFileName(name);\n\n const lockfileSrcPath = path.join(workspaceRootDir, fileName);\n const lockfileDstPath = path.join(isolateDir, fileName);\n\n switch (name) {\n /**\n * It seems that at least for Yarn v1 and NPM v3 lockfile the content is not\n * dependent on the workspace packages structure, so I am assuming we can\n * just copy it over.\n */\n case \"npm\":\n case \"yarn\": {\n fs.copyFileSync(lockfileSrcPath, lockfileDstPath);\n log.debug(\"Copied lockfile to\", lockfileDstPath);\n return;\n }\n case \"pnpm\": {\n const origLockfile = readTypedYamlSync<PnpmLockfile>(lockfileSrcPath);\n\n log.debug(\"Read PNPM lockfile, version:\", origLockfile.lockfileVersion);\n\n const adaptedLockfile = structuredClone(origLockfile);\n\n const targetPackageDef =\n adaptedLockfile.importers[targetPackageRelativeDir];\n\n assert(\n targetPackageDef,\n `Failed to find target package in lockfile at importers[${targetPackageRelativeDir}]`\n );\n /**\n * Overwrite the root importer with the target package importer contents\n */\n adaptedLockfile.importers[\".\"] = targetPackageDef;\n\n /**\n * Delete the target package original importer. Not really necessary.\n */\n delete adaptedLockfile.importers[targetPackageRelativeDir];\n\n writeTypedYamlSync(lockfileDstPath, adaptedLockfile);\n\n log.debug(\"Stored adapted lockfile at\", lockfileDstPath);\n\n return;\n }\n }\n}\n","import fs from \"fs-extra\";\nimport path from \"node:path\";\nimport outdent from \"outdent\";\nimport { getConfig } from \"~/helpers\";\nimport { createLogger, readTypedJson } from \"~/utils\";\n\nexport async function getBuildOutputDir(targetPackageDir: string) {\n const config = getConfig();\n const log = createLogger(getConfig().logLevel);\n\n if (config.buildDirName) {\n log.debug(\"Using buildDirName from config:\", config.buildDirName);\n return path.join(targetPackageDir, config.buildDirName);\n }\n\n const tsconfigPath = path.join(targetPackageDir, config.tsconfigPath);\n\n log.debug(\"Looking for tsconfig at:\", tsconfigPath);\n\n if (fs.existsSync(tsconfigPath)) {\n const tsconfig = await readTypedJson<{\n compilerOptions?: { outDir?: string };\n }>(tsconfigPath);\n\n const outDir = tsconfig.compilerOptions?.outDir;\n\n if (outDir) {\n return path.join(targetPackageDir, outDir);\n } else {\n throw new Error(outdent`\n Failed to find outDir in tsconfig. If you are executing isolate from the root of a monorepo you should specify the buildDirName in isolate.config.json.\n `);\n }\n } else {\n throw new Error(outdent`\n Failed to infer the build output directory from either the isolate config buildDirName or a Typescript config file. See the documentation on how to configure one of these options.\n `);\n }\n}\n","import { PackageManifest, PackagesRegistry } from \"./create-packages-registry\";\n\n/**\n * Recursively list the packages from dependencies (and optionally\n * devDependencies) that are found in the workspace.\n *\n * Here we do not need to rely on packages being declared as \"workspace:\" in the\n * manifest. We can simply compare the package names with the list of packages\n * that were found via the workspace glob patterns and added to the registry.\n */\nexport function listLocalDependencies(\n manifest: PackageManifest,\n packagesRegistry: PackagesRegistry,\n { includeDevDependencies = false } = {}\n): string[] {\n const allWorkspacePackageNames = Object.keys(packagesRegistry);\n\n const localDependencyPackageNames = (\n includeDevDependencies\n ? [\n ...Object.keys(manifest.dependencies ?? {}),\n ...Object.keys(manifest.devDependencies ?? {}),\n ]\n : Object.keys(manifest.dependencies ?? {})\n ).filter((name) => allWorkspacePackageNames.includes(name));\n\n const nestedLocalDependencies = localDependencyPackageNames.flatMap(\n (packageName) =>\n listLocalDependencies(\n packagesRegistry[packageName].manifest,\n packagesRegistry,\n { includeDevDependencies }\n )\n );\n\n return localDependencyPackageNames.concat(nestedLocalDependencies);\n}\n","import path from \"node:path\";\nimport { readTypedJson } from \"~/utils\";\nimport { PackageManifest } from \"./create-packages-registry\";\n\nexport async function importManifest(packageDir: string) {\n return readTypedJson<PackageManifest>(path.join(packageDir, \"package.json\"));\n}\n","import assert from \"node:assert\";\nimport { createLogger, pack } from \"~/utils\";\nimport { getConfig } from \"./config\";\nimport { PackagesRegistry } from \"./create-packages-registry\";\n\n/**\n * Pack dependencies so that we extract only the files that are supposed to be\n * published by the packages.\n *\n * @returns A map of package names to the path of the packed file\n */\nexport async function packDependencies({\n /**\n * All packages found in the monorepo by workspaces declaration\n */\n packagesRegistry,\n /**\n * The package names that appear to be local dependencies\n */\n localDependencies,\n /**\n * The directory where the isolated package and all its dependencies will end\n * up. This is also the directory from where the package will be deployed. By\n * default it is a subfolder in targetPackageDir called \"isolate\" but you can\n * configure it.\n */\n packDestinationDir,\n}: {\n packagesRegistry: PackagesRegistry;\n localDependencies: string[];\n packDestinationDir: string;\n}) {\n const config = getConfig();\n const log = createLogger(config.logLevel);\n\n const packedFileByName: Record<string, string> = {};\n\n for (const dependency of localDependencies) {\n const def = packagesRegistry[dependency];\n\n assert(dependency, `Failed to find package definition for ${dependency}`);\n\n const { name } = def.manifest;\n\n /**\n * If this dependency has already been packed, we skip it. It could happen\n * because we are packing workspace dependencies recursively.\n */\n if (packedFileByName[name]) {\n log.debug(`Skipping ${name} because it has already been packed`);\n continue;\n }\n\n packedFileByName[name] = await pack(def.absoluteDir, packDestinationDir);\n\n /**\n * @TODO call recursively\n */\n }\n\n return packedFileByName;\n}\n","import path from \"node:path\";\nimport { createLogger } from \"~/utils\";\nimport { getConfig } from \"./config\";\nimport { PackagesRegistry } from \"./create-packages-registry\";\n\nexport function patchWorkspaceEntries(\n dependencies: Record<string, string>,\n packagesRegistry: PackagesRegistry,\n parentRootRelativeDir?: string\n) {\n const log = createLogger(getConfig().logLevel);\n const allWorkspacePackageNames = Object.keys(packagesRegistry);\n\n return Object.fromEntries(\n Object.entries(dependencies).map(([key, value]) => {\n if (allWorkspacePackageNames.includes(key)) {\n const def = packagesRegistry[key];\n\n /**\n * When nested shared dependencies are used (local deps linking to other\n * local deps), the parentRootRelativeDir will be passed in, and we\n * store the relative path to the isolate/packages directory, as is\n * required by some package managers.\n */\n const relativePath = parentRootRelativeDir\n ? path.relative(parentRootRelativeDir, `./${def.rootRelativeDir}`)\n : `./${def.rootRelativeDir}`;\n\n const linkPath = `file:${relativePath}`;\n // const linkPath = `file:${def.rootRelativeDir}`;\n\n log.debug(`Linking dependency ${key} to ${linkPath}`);\n\n return [key, linkPath];\n } else {\n return [key, value];\n }\n })\n );\n}\n","import fs from \"fs-extra\";\nimport path from \"node:path\";\nimport { pack, unpack } from \"~/utils\";\n\nexport async function processBuildOutputFiles({\n targetPackageDir,\n tmpDir,\n isolateDir,\n}: {\n targetPackageDir: string;\n tmpDir: string;\n isolateDir: string;\n}) {\n const packedFilePath = await pack(targetPackageDir, tmpDir);\n const unpackDir = path.join(tmpDir, \"target\");\n await unpack(packedFilePath, unpackDir);\n await fs.copy(path.join(unpackDir, \"package\"), isolateDir);\n}\n","import fs from \"fs-extra\";\nimport { join } from \"node:path\";\nimport { getIsolateRelativePath } from \"~/utils\";\nimport { createLogger } from \"~/utils/logger\";\nimport { PackagesRegistry, getConfig } from \".\";\nimport { unpack } from \"../utils/unpack\";\n\nexport async function unpackDependencies(\n packedFilesByName: Record<string, string>,\n packagesRegistry: PackagesRegistry,\n tmpDir: string,\n isolateDir: string\n) {\n const log = createLogger(getConfig().logLevel);\n\n await Promise.all(\n Object.entries(packedFilesByName).map(async ([packageName, filePath]) => {\n const dir = packagesRegistry[packageName].rootRelativeDir;\n const unpackDir = join(tmpDir, dir);\n\n log.debug(\"Unpacking\", filePath);\n\n await unpack(filePath, unpackDir);\n\n const destinationDir = join(isolateDir, dir);\n\n await fs.ensureDir(destinationDir);\n\n await fs.move(join(unpackDir, \"package\"), destinationDir, {\n overwrite: true,\n });\n\n log.debug(\n `Moved package files to ${getIsolateRelativePath(\n destinationDir,\n isolateDir\n )}`\n );\n })\n );\n}\n"],"mappings":";;;AAWA,OAAOA,UAAQ;AACf,OAAOC,aAAY;AACnB,OAAOC,YAAU;AACjB,OAAO,gBAAgB;;;ACdvB,OAAOC,SAAQ;AACf,OAAOC,WAAU;;;ACDV,SAAS,sBAAsB,QAAiC;AACrE,SAAO,OAAO;AAAA,IACZ,OAAO,QAAQ,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,KAAK,MAAM,UAAU,MAAS;AAAA,EACnE;AACF;;;ACAO,SAAS,gBAAgB,OAAgB;AAC9C,SAAO,mBAAmB,KAAK,EAAE;AACnC;AAEA,SAAS,mBAAmB,OAA2C;AACrE,SAA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QAAI,MAAM,IAAI,KAAK;AACnB,YAAQ,KAAK,CAAC;AAAA,EAChB,OAAO;AACL,YAAQ,MAAM,GAAG;AAAA,EACnB;AACF,CAAC;AAED,QAAQ,GAAG,sBAAsB,IAAI,KAAK;","names":["fs","assert","path","fs","path","path","log","stdout","fs","fs","fs","log","fs","path","fs","path","fs","path","fs","path","log","path","fs","config","fs","path","path","fs","assert","path","fs","path","log","path","fs","fs","path","log","packageManager","path","log","fs","path","fs","path","config","log","path","fs","path","assert","config","log","assert","path","log","path","fs","path","path","fs","fs","log","fs","path","assert","fs"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isolate-package",
3
- "version": "1.1.1",
3
+ "version": "1.2.0-rc2",
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",
@@ -31,6 +31,7 @@
31
31
  "lodash-es": "^4.17.21",
32
32
  "outdent": "^0.8.0",
33
33
  "source-map-support": "^0.5.21",
34
+ "strip-json-comments": "^5.0.1",
34
35
  "tar-fs": "^2.1.1",
35
36
  "yaml": "^2.2.2"
36
37
  },
@@ -40,6 +41,7 @@
40
41
  "@types/node": "^18.16.2",
41
42
  "@types/source-map-support": "^0.5.6",
42
43
  "@types/tar-fs": "^2.0.1",
44
+ "prettier": "^3.0.0",
43
45
  "tsup": "^6.7.0",
44
46
  "type-fest": "^3.9.0",
45
47
  "typescript": "^5.0.4",
@@ -47,6 +49,10 @@
47
49
  },
48
50
  "scripts": {
49
51
  "build": "tsup-node",
50
- "test": "vitest"
52
+ "build:watch": "tsup-node --watch",
53
+ "test": "vitest",
54
+ "format": "prettier --write .",
55
+ "lint:format": "prettier --check .",
56
+ "compile:watch": "tsc --noEmit -w"
51
57
  }
52
58
  }