From f726bcc1e0bbad803e30623058a27271ecdacabc Mon Sep 17 00:00:00 2001 From: Helder Oliveira Date: Tue, 13 Aug 2024 17:13:29 +0100 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20bundling=20parameter?= =?UTF-8?q?s=20(#15)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Why? Bundling parameters. ## How? - fix Bundle argument - Declare node_module paths ## Tickets? - [PLAT-1273](https://linear.app/fleekxyz/issue/PLAT-1273/bundling-parameters) ## Contribution checklist? - [x] The commit messages are detailed - [x] The `build` command runs locally - [ ] Assets or static content are linked and stored in the project - [ ] You have manually tested - [ ] You have provided tests ## Security checklist? - [ ] Sensitive data has been identified and is being protected properly - [ ] Injection has been prevented (parameterized queries, no eval or system calls) ## Preview? Optionally, provide the preview url here --- .changeset/happy-feet-divide.md | 5 +++++ package.json | 4 ++-- pnpm-lock.yaml | 4 ++-- src/commands/functions/deploy.ts | 3 ++- src/commands/functions/utils/getCodeFromPath.ts | 5 +++++ 5 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 .changeset/happy-feet-divide.md diff --git a/.changeset/happy-feet-divide.md b/.changeset/happy-feet-divide.md new file mode 100644 index 0000000..96cc8f8 --- /dev/null +++ b/.changeset/happy-feet-divide.md @@ -0,0 +1,5 @@ +--- +'@fleek-platform/cli': minor +--- + +Bundling parameter amends diff --git a/package.json b/package.json index 1b889de..841809a 100644 --- a/package.json +++ b/package.json @@ -46,11 +46,11 @@ "commander": "^9.4.1", "conf": "^10.2.0", "dotenv": "^16.4.5", - "esbuild": "^0.21.3", + "esbuild": "^0.21.4", "files-from-path": "^1.0.0", "glob": "^8.1.0", "lodash-es": "^4.17.21", - "multiformats": "9.9.0", + "multiformats": "^9.9.0", "nanoid": "^3.3.4", "ora": "^3.4.0", "press-any-key": "^0.1.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6588829..a036541 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -37,12 +37,12 @@ specifiers: concurrently: ^7.6.0 conf: ^10.2.0 dotenv: ^16.4.5 - esbuild: ^0.21.3 + esbuild: ^0.21.4 files-from-path: ^1.0.0 glob: ^8.1.0 lodash-es: ^4.17.21 mock-stdin: ^1.0.0 - multiformats: 9.9.0 + multiformats: ^9.9.0 nanoid: ^3.3.4 ora: ^3.4.0 press-any-key: ^0.1.1 diff --git a/src/commands/functions/deploy.ts b/src/commands/functions/deploy.ts index cb5c7ec..9fb5ebd 100644 --- a/src/commands/functions/deploy.ts +++ b/src/commands/functions/deploy.ts @@ -30,9 +30,10 @@ const deployAction: SdkGuardedFunction = async ({ const env = getEnvironmentVariables({ env: args.env, envFile: args.envFile }); const functionToDeploy = await getFunctionOrPrompt({ name: args.name, sdk }); const filePath = await getFunctionPathOrPrompt({ path: args.filePath }); + const bundle = !args.noBundle; const bundledFilePath = await getCodeFromPath({ filePath, - bundle: args.noBundle, + bundle, env, }); diff --git a/src/commands/functions/utils/getCodeFromPath.ts b/src/commands/functions/utils/getCodeFromPath.ts index eed283b..1bfed56 100644 --- a/src/commands/functions/utils/getCodeFromPath.ts +++ b/src/commands/functions/utils/getCodeFromPath.ts @@ -1,3 +1,4 @@ +import path from 'path'; import * as fs from 'node:fs'; import * as os from 'node:os'; @@ -105,6 +106,9 @@ const transpileCode = async (args: TranspileCodeArgs) => { ); } + const filePathWorkDir = path.dirname(filePath); + const nodeModulesPath = path.join(filePathWorkDir, 'node_modules'); + const buildOptions: BuildOptions = { entryPoints: [filePath], bundle, @@ -117,6 +121,7 @@ const transpileCode = async (args: TranspileCodeArgs) => { outfile: outFile, minify: true, plugins, + nodePaths: [nodeModulesPath], }; buildOptions.banner = {