From d8cc0a1f1407a1b705ed8c50c89d70359dbae1d8 Mon Sep 17 00:00:00 2001 From: Thijs Koerselman Date: Sun, 17 Nov 2024 10:24:09 +0100 Subject: [PATCH] Bring back the forceNpm option (#112) --- README.md | 18 ++++++++++++++++++ package.json | 2 +- src/isolate.ts | 2 +- src/lib/lockfile/process-lockfile.ts | 14 ++++++++++++++ .../manifest/adapt-target-package-manifest.ts | 3 ++- .../adapt-internal-package-manifests.ts | 4 +++- 6 files changed, 39 insertions(+), 4 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/package.json b/package.json index 6faf3b6..bc7ea27 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "isolate-package", - "version": "1.19.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", 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.