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

feat(nextjs-component): add deploy input which can be set to false to skip deployment #691

Merged
merged 1 commit into from
Oct 18, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -982,4 +982,33 @@ describe("Custom inputs", () => {
});
});
});

describe("Skip deployment after build", () => {
const fixturePath = path.join(__dirname, "./fixtures/simple-app");
let tmpCwd: string;

beforeEach(async () => {
tmpCwd = process.cwd();
process.chdir(fixturePath);

mockServerlessComponentDependencies({ expectedDomain: undefined });
});

afterEach(() => {
process.chdir(tmpCwd);
return cleanupFixtureDirectory(fixturePath);
});

it("builds but skips deployment", async () => {
const result = await createNextComponent().default({
deploy: false
});

expect(result).toEqual({
appUrl: "SKIPPED_DEPLOY",
bucketName: "SKIPPED_DEPLOY",
distributionId: "SKIPPED_DEPLOY"
});
});
});
});
13 changes: 13 additions & 0 deletions packages/serverless-components/nextjs-component/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import type {
LambdaInput
} from "../types";

// Message when deployment is explicitly skipped
const SKIPPED_DEPLOY = "SKIPPED_DEPLOY";

export type DeploymentResult = {
appUrl: string;
bucketName: string;
Expand Down Expand Up @@ -206,6 +209,16 @@ class NextjsComponent extends Component {
async deploy(
inputs: ServerlessComponentInputs = {}
): Promise<DeploymentResult> {
// Skip deployment if user explicitly set deploy input to false.
// Useful when they just want the build outputs to deploy themselves.
if (inputs.deploy === false) {
return {
appUrl: SKIPPED_DEPLOY,
bucketName: SKIPPED_DEPLOY,
distributionId: SKIPPED_DEPLOY
};
}

const nextConfigPath = inputs.nextConfigDir
? resolve(inputs.nextConfigDir)
: process.cwd();
Expand Down
1 change: 1 addition & 0 deletions packages/serverless-components/nextjs-component/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type ServerlessComponentInputs = {
cloudfront?: CloudfrontOptions;
minifyHandlers?: boolean;
uploadStaticAssetsFromBuild?: boolean;
deploy?: boolean;
};

type CloudfrontOptions = Record<string, any>;
Expand Down