From 379bcefd0712ade526d44d5bf9dfeb2f620dfd5a Mon Sep 17 00:00:00 2001 From: Thijs Koerselman Date: Thu, 10 Oct 2024 17:20:53 +0200 Subject: [PATCH 1/3] Bring back the forceNpm option --- README.md | 18 ++++++++++++++++++ src/isolate.ts | 2 +- src/lib/lockfile/process-lockfile.ts | 14 ++++++++++++++ .../manifest/adapt-target-package-manifest.ts | 3 ++- .../adapt-internal-package-manifests.ts | 4 +++- 5 files changed, 38 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6b19320..a40274e 100644 --- a/README.md +++ b/README.md @@ -185,6 +185,24 @@ Because the configuration loader depends on this setting, its output is not affected by this setting. If you want to debug the configuration set `DEBUG_ISOLATE_CONFIG=true` before you run `isolate` +### forceNpm + +Type: `boolean`, default: `false` + +By default the isolate process will generate output based on the package manager +that you are using for your monorepo, but your deployment target might not be +compatible with that package manager. + +It should not really matter what package manager is used in de deployment as +long as the versions match your original lockfile. + +By setting this option to `true` you are forcing the isolate output to use NPM. +A package-lock file will be generated based on the contents of node_modules and +therefore should match the versions in your original lockfile. + +This way you can enjoy using PNPM or Yarn for your monorepo, while your +deployment requires NPM. + ### buildDirName Type: `string | undefined`, default: `undefined` diff --git a/src/isolate.ts b/src/isolate.ts index 451c100..920ae5f 100644 --- a/src/isolate.ts +++ b/src/isolate.ts @@ -195,7 +195,7 @@ export async function isolate( await writeManifest(isolateDir, manifest); } - if (packageManager.name === "pnpm") { + if (packageManager.name === "pnpm" && !config.forceNpm) { /** * PNPM doesn't install dependencies of packages that are linked via link: * or file: specifiers. It requires the directory to be configured as a diff --git a/src/lib/lockfile/process-lockfile.ts b/src/lib/lockfile/process-lockfile.ts index 8db9472..4aa80d4 100644 --- a/src/lib/lockfile/process-lockfile.ts +++ b/src/lib/lockfile/process-lockfile.ts @@ -1,3 +1,4 @@ +import { useConfig } from "../config"; import { useLogger } from "../logger"; import { usePackageManager } from "../package-manager"; import type { PackageManifest, PackagesRegistry } from "../types"; @@ -32,6 +33,19 @@ export async function processLockfile({ }) { const log = useLogger(); + const { forceNpm } = useConfig(); + + if (forceNpm) { + log.info("Forcing to use NPM for isolate output"); + + await generateNpmLockfile({ + workspaceRootDir, + isolateDir, + }); + + return true; + } + const { name, majorVersion } = usePackageManager(); let usedFallbackToNpm = false; diff --git a/src/lib/manifest/adapt-target-package-manifest.ts b/src/lib/manifest/adapt-target-package-manifest.ts index 659328d..aa05f61 100644 --- a/src/lib/manifest/adapt-target-package-manifest.ts +++ b/src/lib/manifest/adapt-target-package-manifest.ts @@ -26,6 +26,7 @@ export async function adaptTargetPackageManifest({ pickFromScripts, omitFromScripts, omitPackageManager, + forceNpm, } = useConfig(); /** Dev dependencies are omitted by default */ @@ -34,7 +35,7 @@ export async function adaptTargetPackageManifest({ : omit(manifest, ["devDependencies"]); const adaptedManifest = - packageManager.name === "pnpm" + packageManager.name === "pnpm" && !forceNpm ? /** * For PNPM the output itself is a workspace so we can preserve the specifiers * with "workspace:*" in the output manifest, but we do want to adopt the diff --git a/src/lib/manifest/helpers/adapt-internal-package-manifests.ts b/src/lib/manifest/helpers/adapt-internal-package-manifests.ts index 480c6a0..5b5dcef 100644 --- a/src/lib/manifest/helpers/adapt-internal-package-manifests.ts +++ b/src/lib/manifest/helpers/adapt-internal-package-manifests.ts @@ -1,5 +1,6 @@ import path from "node:path"; import { omit } from "remeda"; +import { useConfig } from "~/lib/config"; import { usePackageManager } from "~/lib/package-manager"; import type { PackagesRegistry } from "~/lib/types"; import { writeManifest } from "../io"; @@ -16,6 +17,7 @@ export async function adaptInternalPackageManifests( isolateDir: string ) { const packageManager = usePackageManager(); + const { forceNpm } = useConfig(); await Promise.all( internalPackageNames.map(async (packageName) => { @@ -25,7 +27,7 @@ export async function adaptInternalPackageManifests( const strippedManifest = omit(manifest, ["scripts", "devDependencies"]); const outputManifest = - packageManager.name === "pnpm" + packageManager.name === "pnpm" && !forceNpm ? /** * For PNPM the output itself is a workspace so we can preserve the specifiers * with "workspace:*" in the output manifest. From 8b3b3b9e4078bdc1c16e1e2a7e6c4d1db0f239fd Mon Sep 17 00:00:00 2001 From: Thijs Koerselman Date: Thu, 10 Oct 2024 17:21:48 +0200 Subject: [PATCH 2/3] 1.20.0-0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cc81b6a..0d80431 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "isolate-package", - "version": "1.19.0", + "version": "1.20.0-0", "description": "Isolate a monorepo package with its shared dependencies to form a self-contained directory, compatible with Firebase deploy", "author": "Thijs Koerselman", "license": "MIT", From dcf9abfcb9f0d616cb065b77e2368bfbfa4f6c71 Mon Sep 17 00:00:00 2001 From: Thijs Koerselman Date: Thu, 10 Oct 2024 17:22:00 +0200 Subject: [PATCH 3/3] 1.20.0-1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0d80431..92b5e84 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "isolate-package", - "version": "1.20.0-0", + "version": "1.20.0-1", "description": "Isolate a monorepo package with its shared dependencies to form a self-contained directory, compatible with Firebase deploy", "author": "Thijs Koerselman", "license": "MIT",