Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring back the forceNpm option #112

Merged
merged 3 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/isolate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions src/lib/lockfile/process-lockfile.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useConfig } from "../config";
import { useLogger } from "../logger";
import { usePackageManager } from "../package-manager";
import type { PackageManifest, PackagesRegistry } from "../types";
Expand Down Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion src/lib/manifest/adapt-target-package-manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export async function adaptTargetPackageManifest({
pickFromScripts,
omitFromScripts,
omitPackageManager,
forceNpm,
} = useConfig();

/** Dev dependencies are omitted by default */
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/lib/manifest/helpers/adapt-internal-package-manifests.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -16,6 +17,7 @@ export async function adaptInternalPackageManifests(
isolateDir: string
) {
const packageManager = usePackageManager();
const { forceNpm } = useConfig();

await Promise.all(
internalPackageNames.map(async (packageName) => {
Expand All @@ -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.
Expand Down