Skip to content

Commit 592a0cf

Browse files
committed
gitignore .apphosting/
1 parent 84a1be5 commit 592a0cf

File tree

2 files changed

+111
-3
lines changed

2 files changed

+111
-3
lines changed

packages/@apphosting/adapter-nextjs/src/bin/build.spec.ts

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,112 @@ outputFiles:
164164
async () => await validateOutputDirectory(outputBundleOptions, path.join(tmpDir, ".next")),
165165
);
166166
});
167+
it(".apphosting gitignored correctly in a monorepo setup", async () => {
168+
const { generateBuildOutput } = await importUtils;
169+
const files = {
170+
".next/standalone/apps/next-app/standalonefile": "",
171+
".next/static/staticfile": "",
172+
};
173+
generateTestFiles(tmpDir, files);
174+
await generateBuildOutput(
175+
tmpDir,
176+
"apps/next-app",
177+
{
178+
bundleYamlPath: path.join(tmpDir, ".apphosting", "bundle.yaml"),
179+
outputDirectoryBasePath: path.join(tmpDir, ".apphosting"),
180+
outputDirectoryAppPath: path.join(tmpDir, ".next", "standalone", "apps", "next-app"),
181+
outputPublicDirectoryPath: path.join(
182+
tmpDir,
183+
".next",
184+
"standalone",
185+
"apps",
186+
"next-app",
187+
"public",
188+
),
189+
outputStaticDirectoryPath: path.join(
190+
tmpDir,
191+
".next",
192+
"standalone",
193+
"apps",
194+
"next-app",
195+
".next",
196+
"static",
197+
),
198+
serverFilePath: path.join(tmpDir, ".next", "standalone", "apps", "next-app", "server.js"),
199+
},
200+
path.join(tmpDir, ".next"),
201+
defaultNextVersion,
202+
adapterMetadata,
203+
);
204+
205+
const expectedFiles = {
206+
".gitignore": "/.apphosting/",
207+
};
208+
const expectedPartialYaml = {
209+
version: "v1",
210+
runConfig: { runCommand: "node .next/standalone/apps/next-app/server.js" },
211+
};
212+
validateTestFiles(tmpDir, expectedFiles);
213+
validatePartialYamlContents(tmpDir, ".apphosting/bundle.yaml", expectedPartialYaml);
214+
});
215+
216+
it(".apphosting gitignored without existing .gitignore file", async () => {
217+
const { generateBuildOutput, validateOutputDirectory } = await importUtils;
218+
const files = {
219+
// .next/standalone/.next/ must be created beforehand otherwise
220+
// generateBuildOutput will attempt to copy
221+
// .next/ into .next/standalone/.next
222+
".next/standalone/.next/package.json": "",
223+
".next/static/staticfile": "",
224+
};
225+
generateTestFiles(tmpDir, files);
226+
await generateBuildOutput(
227+
tmpDir,
228+
tmpDir,
229+
outputBundleOptions,
230+
path.join(tmpDir, ".next"),
231+
defaultNextVersion,
232+
{
233+
adapterPackageName: "@apphosting/adapter-nextjs",
234+
adapterVersion: "14.0.1",
235+
},
236+
);
237+
await validateOutputDirectory(outputBundleOptions, path.join(tmpDir, ".next"));
238+
239+
const expectedFiles = {
240+
".gitignore": "/.apphosting/",
241+
};
242+
validateTestFiles(tmpDir, expectedFiles);
243+
});
244+
it(".apphosting gitignored in existing .gitignore file", async () => {
245+
const { generateBuildOutput, validateOutputDirectory } = await importUtils;
246+
const files = {
247+
// .next/standalone/.next/ must be created beforehand otherwise
248+
// generateBuildOutput will attempt to copy
249+
// .next/ into .next/standalone/.next
250+
".next/standalone/.next/package.json": "",
251+
".next/static/staticfile": "",
252+
".gitignore": "/.next/",
253+
};
254+
generateTestFiles(tmpDir, files);
255+
await generateBuildOutput(
256+
tmpDir,
257+
tmpDir,
258+
outputBundleOptions,
259+
path.join(tmpDir, ".next"),
260+
defaultNextVersion,
261+
{
262+
adapterPackageName: "@apphosting/adapter-nextjs",
263+
adapterVersion: "14.0.1",
264+
},
265+
);
266+
await validateOutputDirectory(outputBundleOptions, path.join(tmpDir, ".next"));
267+
268+
const expectedFiles = {
269+
".gitignore": "/.next/\n/.apphosting/",
270+
};
271+
validateTestFiles(tmpDir, expectedFiles);
272+
});
167273
it("expects directories and other files to be copied over", async () => {
168274
const { generateBuildOutput, validateOutputDirectory } = await importUtils;
169275
const files = {

packages/@apphosting/adapter-nextjs/src/utils.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import {
1212
MiddlewareManifest,
1313
} from "./interfaces.js";
1414
import { NextConfigComplete } from "next/dist/server/config-shared.js";
15-
import { OutputBundleConfig } from "@apphosting/common";
15+
import { OutputBundleConfig, updateOrCreateGitignore } from "@apphosting/common";
1616

1717
// fs-extra is CJS, readJson can't be imported using shorthand
18-
export const { copy, exists, writeFile, readJson, readdir, readFileSync, existsSync, mkdir } =
18+
export const { copy, exists, writeFile, readJson, readdir, readFileSync, existsSync, ensureDir } =
1919
fsExtra;
2020

2121
// Loads the user's next.config.js file.
@@ -181,7 +181,7 @@ async function generateBundleYaml(
181181
nextVersion: string,
182182
adapterMetadata: AdapterMetadata,
183183
): Promise<void> {
184-
await mkdir(opts.outputDirectoryBasePath);
184+
await ensureDir(opts.outputDirectoryBasePath);
185185
const outputBundle: OutputBundleConfig = {
186186
version: "v1",
187187
runConfig: {
@@ -203,6 +203,8 @@ async function generateBundleYaml(
203203
}
204204

205205
await writeFile(opts.bundleYamlPath, yamlStringify(outputBundle));
206+
const normalizedBundleDir = normalize(relative(cwd, opts.outputDirectoryBasePath));
207+
updateOrCreateGitignore(cwd, [`/${normalizedBundleDir}/`]);
206208
return;
207209
}
208210

0 commit comments

Comments
 (0)