From 505c46904379cfd91bb0aea49d82b4a6ff5b6ccc Mon Sep 17 00:00:00 2001 From: jieey1140 Date: Tue, 15 Aug 2023 21:51:42 +0900 Subject: [PATCH 1/5] fix pack max buffer error --- src/utils/pack.ts | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/utils/pack.ts b/src/utils/pack.ts index 793d1d6..6db5b81 100644 --- a/src/utils/pack.ts +++ b/src/utils/pack.ts @@ -9,6 +9,10 @@ export async function pack( dstDir: string, usePnpmPack = false ) { + const execMaxBufferSize = { + maxBuffer: 10 * 1024 * 1024, + }; + const log = createLogger(getConfig().logLevel); const previousCwd = process.cwd(); @@ -22,6 +26,7 @@ export async function pack( ? await new Promise((resolve, reject) => { exec( `pnpm pack --pack-destination ${dstDir}`, + execMaxBufferSize, (err, stdout, stderr) => { if (err) { log.error(stderr); @@ -33,13 +38,17 @@ export async function pack( ); }) : await new Promise((resolve, reject) => { - exec(`npm pack --pack-destination ${dstDir}`, (err, stdout) => { - if (err) { - return reject(err); - } + exec( + `npm pack --pack-destination ${dstDir}`, + execMaxBufferSize, + (err, stdout) => { + if (err) { + return reject(err); + } - resolve(stdout); - }); + resolve(stdout); + } + ); }); const fileName = path.basename(stdout.trim()); From de712585a3a4d6eb957d968f616ac250fb37bdad Mon Sep 17 00:00:00 2001 From: jieey1140 Date: Tue, 15 Aug 2023 21:56:31 +0900 Subject: [PATCH 2/5] rename max buffer size option --- src/utils/pack.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/pack.ts b/src/utils/pack.ts index 6db5b81..badb30a 100644 --- a/src/utils/pack.ts +++ b/src/utils/pack.ts @@ -9,7 +9,7 @@ export async function pack( dstDir: string, usePnpmPack = false ) { - const execMaxBufferSize = { + const execOption = { maxBuffer: 10 * 1024 * 1024, }; @@ -26,7 +26,7 @@ export async function pack( ? await new Promise((resolve, reject) => { exec( `pnpm pack --pack-destination ${dstDir}`, - execMaxBufferSize, + execOption, (err, stdout, stderr) => { if (err) { log.error(stderr); @@ -40,7 +40,7 @@ export async function pack( : await new Promise((resolve, reject) => { exec( `npm pack --pack-destination ${dstDir}`, - execMaxBufferSize, + execOption, (err, stdout) => { if (err) { return reject(err); From 406552ba063f99753d65eb0c108b9dd2a7d69621 Mon Sep 17 00:00:00 2001 From: jieey1140 Date: Tue, 15 Aug 2023 23:42:10 +0900 Subject: [PATCH 3/5] fix: exec options name --- src/utils/pack.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/pack.ts b/src/utils/pack.ts index badb30a..6b77781 100644 --- a/src/utils/pack.ts +++ b/src/utils/pack.ts @@ -9,7 +9,7 @@ export async function pack( dstDir: string, usePnpmPack = false ) { - const execOption = { + const execOptions = { maxBuffer: 10 * 1024 * 1024, }; @@ -26,7 +26,7 @@ export async function pack( ? await new Promise((resolve, reject) => { exec( `pnpm pack --pack-destination ${dstDir}`, - execOption, + execOptions, (err, stdout, stderr) => { if (err) { log.error(stderr); @@ -40,7 +40,7 @@ export async function pack( : await new Promise((resolve, reject) => { exec( `npm pack --pack-destination ${dstDir}`, - execOption, + execOptions, (err, stdout) => { if (err) { return reject(err); From 58e27ef43dbfb1d1bcfff04252f39a38a79a69c0 Mon Sep 17 00:00:00 2001 From: jieey1140 Date: Fri, 13 Oct 2023 15:14:05 +0900 Subject: [PATCH 4/5] feat: add functionality to omit scripts section in package.json --- src/helpers/config.ts | 2 ++ src/helpers/index.ts | 1 + src/helpers/omit-package-scripts.ts | 19 +++++++++++++++++++ src/index.ts | 15 +++++++++++++++ 4 files changed, 37 insertions(+) create mode 100644 src/helpers/omit-package-scripts.ts diff --git a/src/helpers/config.ts b/src/helpers/config.ts index 3dbafea..6c9dc49 100644 --- a/src/helpers/config.ts +++ b/src/helpers/config.ts @@ -14,6 +14,7 @@ export type IsolateConfigResolved = { workspaceRoot: string; excludeLockfile: boolean; avoidPnpmPack: boolean; + omitScripts?: boolean; }; export type IsolateConfig = Partial; @@ -29,6 +30,7 @@ const configDefaults: IsolateConfigResolved = { workspaceRoot: "../..", excludeLockfile: false, avoidPnpmPack: false, + omitScripts: false, }; /** diff --git a/src/helpers/index.ts b/src/helpers/index.ts index a03b47c..249fb67 100644 --- a/src/helpers/index.ts +++ b/src/helpers/index.ts @@ -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"; diff --git a/src/helpers/omit-package-scripts.ts b/src/helpers/omit-package-scripts.ts new file mode 100644 index 0000000..073b332 --- /dev/null +++ b/src/helpers/omit-package-scripts.ts @@ -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( + isolatePackageJsonPath + ); + + const outputManifest = omit(packageManifest, ["scripts"]); + + await fs.writeFile( + isolatePackageJsonPath, + JSON.stringify(outputManifest, null, 2) + ); +} diff --git a/src/index.ts b/src/index.ts index 08048fb..c56c7e3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -25,6 +25,7 @@ import { getBuildOutputDir, getConfig, listLocalDependencies, + omitPackageScripts, packDependencies, processBuildOutputFiles, processLockfile, @@ -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. From 4d146ed8b850989c391c540c29e81a69958f022c Mon Sep 17 00:00:00 2001 From: jieey1140 Date: Fri, 13 Oct 2023 15:24:29 +0900 Subject: [PATCH 5/5] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d7666e9..2191bfe 100644 --- a/README.md +++ b/README.md @@ -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