Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.

Commit d7efc6c

Browse files
authored
fix(nextjs-component): do not allow same name to be specified across all lambdas(#1569)
1 parent 515c0a0 commit d7efc6c

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ The fourth cache behaviour handles next API requests `api/*`.
520520
| tags | `object` | `undefined` | Tags to assign to a Lambda. If undefined, the component will not update any tags. If set to an empty object, it will remove all tags. |
521521
| timeout | `number\|object` | `10` | Same as above |
522522
| handler | `string` | `index.handler` | When assigned a value, overrides the default function handler to allow for configuration. Copies `handler.js` in route into the Lambda folders. Your handler MUST still call the `default-handler` afterwards or your function won't work with Next.JS |
523-
| name | `string\|object` | / | When assigned a string, both the default and api lambdas will assigned name of that value. When assigned to an object, values for the default and api lambdas can be separately defined |
523+
| name | `object` | / | Names for all lambdas can be explicitly defined |
524524
| build | `boolean\|object` | `true` | When true builds and deploys app, when false assume the app has been built and uses the `.next` `.serverless_nextjs` directories in `nextConfigDir` to deploy. If an object is passed `build` allows for overriding what script gets called and with what arguments. |
525525
| build.cmd | `string` | `node_modules/.bin/next` | Build command, you may pass a no-op command (e.g `true` or `:` in Unix-based systems) which will then skip the Next.js build |
526526
| build.args | `Array\|string` | `['build']` | Arguments to pass to the build |

packages/serverless-components/nextjs-component/__tests__/custom-inputs.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,6 @@ describe("Custom inputs", () => {
576576
inputName | expectedName
577577
${undefined} | ${{ defaultName: undefined, apiName: undefined }}
578578
${{}} | ${{ defaultName: undefined, apiName: undefined }}
579-
${"fooFunction"} | ${{ defaultName: "fooFunction", apiName: "fooFunction" }}
580579
${{ defaultLambda: "fooFunction" }} | ${{ defaultName: "fooFunction", apiName: undefined }}
581580
${{ apiLambda: "fooFunction" }} | ${{ defaultName: undefined, apiName: "fooFunction" }}
582581
${{ defaultLambda: "fooFunction", apiLambda: "barFunction" }} | ${{ defaultName: "fooFunction", apiName: "barFunction" }}
@@ -606,7 +605,8 @@ describe("Custom inputs", () => {
606605
const { defaultName, apiName } = expectedName;
607606

608607
const expectedDefaultObject = {
609-
code: path.join(fixturePath, DEFAULT_LAMBDA_CODE_DIR)
608+
code: path.join(fixturePath, DEFAULT_LAMBDA_CODE_DIR),
609+
name: undefined
610610
};
611611
if (defaultName) expectedDefaultObject.name = defaultName;
612612

@@ -615,7 +615,8 @@ describe("Custom inputs", () => {
615615
);
616616

617617
const expectedApiObject = {
618-
code: path.join(fixturePath, API_LAMBDA_CODE_DIR)
618+
code: path.join(fixturePath, API_LAMBDA_CODE_DIR),
619+
name: undefined
619620
};
620621
if (apiName) expectedApiObject.name = apiName;
621622

packages/serverless-components/nextjs-component/src/component.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,13 @@ class NextjsComponent extends Component {
467467
const inputValue = inputs[inputKey];
468468

469469
if (typeof inputValue === "string" || typeof inputValue === "number") {
470+
// For lambda name, we should not allow same name to be specified across all lambdas, as this can cause conflicts
471+
if (inputKey === "name") {
472+
throw new Error(
473+
"Name cannot be specified across all Lambdas as it will cause conflicts."
474+
);
475+
}
476+
470477
return inputValue;
471478
}
472479

0 commit comments

Comments
 (0)