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

add functionality to omit scripts section in package.json #23

Closed
wants to merge 6 commits into from
Closed
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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,10 @@ excluded for PNPM.

### A Partial Workaround

If you can't use a lockfile, and you are worried about things breaking,
a partial workaround would be to declare
dependencies using exact versions in your manifest file. This doesn't prevent
your dependencies dependencies from installing newer versions, like a lockfile
If you can't use a lockfile, and you are worried about things breaking,
a partial workaround would be to declare
dependencies using exact versions in your manifest file. This doesn't prevent
your dependencies dependencies from installing newer versions, like a lockfile
would, but at least you minimize the risk of things breaking.

## Different Package Managers
Expand Down
2 changes: 2 additions & 0 deletions src/helpers/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type IsolateConfigResolved = {
workspaceRoot: string;
excludeLockfile: boolean;
avoidPnpmPack: boolean;
omitScripts?: boolean;
};

export type IsolateConfig = Partial<IsolateConfigResolved>;
Expand All @@ -29,6 +30,7 @@ const configDefaults: IsolateConfigResolved = {
workspaceRoot: "../..",
excludeLockfile: false,
avoidPnpmPack: false,
omitScripts: false,
};

/**
Expand Down
1 change: 1 addition & 0 deletions src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export * from "./find-packages-globs";
export * from "./get-build-output-dir";
export * from "./list-local-dependencies";
export * from "./manifest";
export * from "./omit-package-scripts";
export * from "./pack-dependencies";
export * from "./patch-workspace-entries";
export * from "./process-build-output-files";
Expand Down
19 changes: 19 additions & 0 deletions src/helpers/omit-package-scripts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { omit } from "lodash-es";
import path from "node:path";
import { readTypedJsonSync } from "~/utils";
import { PackageManifest } from "./create-packages-registry";
import fs from "fs-extra";

export async function omitPackageScripts(isolateDir: string) {
const isolatePackageJsonPath = path.join(isolateDir, "package.json");
const packageManifest = readTypedJsonSync<PackageManifest>(
isolatePackageJsonPath
);

const outputManifest = omit(packageManifest, ["scripts"]);

await fs.writeFile(
isolatePackageJsonPath,
JSON.stringify(outputManifest, null, 2)
);
}
15 changes: 15 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
getBuildOutputDir,
getConfig,
listLocalDependencies,
omitPackageScripts,
packDependencies,
processBuildOutputFiles,
processLockfile,
Expand Down Expand Up @@ -199,6 +200,20 @@ async function start() {
log.debug("Copied .npmrc file to the isolate output");
}

/**
* Firebase Functions relies on the build script from package.json.
* However, Cloud Build only recognizes npm, not pnpm, leading to issues with
* commands like pnpm nest build. To resolve this, the script section from package.json
* is removed, as there is no need to rerun the script commands when the file, which
* should already be built and ready for deployment, is being deployed.
*
* Ensure smooth deployments in a pnpm environment by utilizing the omitScripts option to prevent issues during deployment.
*/
if (config.omitScripts) {
await omitPackageScripts(isolateDir);
log.debug("Removed the scripts section from package.json in isolate");
}

/**
* Clean up. Only so this in the happy path, so we can look at the temp folder
* when thing go wrong.
Expand Down