diff --git a/package-lock.json b/package-lock.json index 94db2755..00c3be98 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25520,7 +25520,7 @@ } }, "packages/@apphosting/adapter-angular": { - "version": "17.2.15", + "version": "17.2.16", "license": "Apache-2.0", "dependencies": { "@apphosting/common": "*", @@ -25618,7 +25618,7 @@ } }, "packages/@apphosting/adapter-nextjs": { - "version": "14.0.17", + "version": "14.0.18", "license": "Apache-2.0", "dependencies": { "@apphosting/common": "*", @@ -25662,10 +25662,22 @@ "ts-node": "^10.9.1" }, "bin": { + "apphosting-local-build": "dist/bin/localbuild.js", "build": "dist/bin/build.js" }, "devDependencies": { - "@types/commander": "*" + "@types/commander": "*", + "@types/fs-extra": "*", + "@types/mocha": "*", + "@types/tmp": "*", + "mocha": "*", + "next": "~14.0.0", + "semver": "*", + "tmp": "*", + "ts-mocha": "*", + "ts-node": "*", + "typescript": "*", + "verdaccio": "^5.30.3" } }, "packages/@apphosting/build/node_modules/hosted-git-info": { @@ -25724,7 +25736,7 @@ } }, "packages/@apphosting/common": { - "version": "0.0.5", + "version": "0.0.7", "license": "Apache-2.0" }, "packages/@apphosting/create": { diff --git a/packages/@apphosting/build/package.json b/packages/@apphosting/build/package.json index db02593b..babd8c4a 100644 --- a/packages/@apphosting/build/package.json +++ b/packages/@apphosting/build/package.json @@ -1,6 +1,6 @@ { "name": "@apphosting/build", - "version": "0.1.0", + "version": "0.1.1", "main": "dist/index.js", "description": "Experimental addon to the Firebase CLI to add web framework support", "repository": { @@ -8,7 +8,8 @@ "url": "git+https://github.com/FirebaseExtended/firebase-framework-tools.git" }, "bin": { - "build": "dist/bin/build.js" + "build": "dist/bin/build.js", + "apphosting-local-build": "dist/bin/localbuild.js" }, "author": { "name": "Firebase", @@ -20,7 +21,7 @@ "type": "module", "sideEffects": false, "scripts": { - "build": "rm -rf dist && tsc && chmod +x ./dist/bin/*" + "build": "rm -rf dist && tsc && chmod +x ./dist/bin/*" }, "exports": { ".": { @@ -40,6 +41,6 @@ "ts-node": "^10.9.1" }, "devDependencies": { - "@types/commander": "*" + "@types/commander": "*" } } diff --git a/packages/@apphosting/build/src/bin/localbuild.ts b/packages/@apphosting/build/src/bin/localbuild.ts new file mode 100644 index 00000000..ed284df9 --- /dev/null +++ b/packages/@apphosting/build/src/bin/localbuild.ts @@ -0,0 +1,46 @@ +#! /usr/bin/env node +import { spawn } from "child_process"; +import { program } from "commander"; +import { yellow, bgRed, bold } from "colorette"; + +// TODO(#382): add framework option later or incorporate micro-discovery. +// TODO(#382): parse apphosting.yaml for environment variables / secrets. +// TODO(#382): parse apphosting.yaml for runConfig and include in buildSchema +// TODO(#382): Support custom build and run commands (parse and pass run command to build schema). +program + .argument("", "path to the project's root directory") + .action(async (projectRoot: string) => { + const framework = "nextjs"; + // TODO(#382): We are using the latest framework adapter versions, but in the future + // we should parse the framework version and use the matching adapter version. + const adapterName = `@apphosting/adapter-nextjs`; + const packumentResponse = await fetch(`https://registry.npmjs.org/${adapterName}`); + if (!packumentResponse.ok) throw new Error(`Something went wrong fetching ${adapterName}`); + const packument = await packumentResponse.json(); + const adapterVersion = packument?.["dist-tags"]?.["latest"]; + if (!adapterVersion) { + throw new Error(`Could not find 'latest' dist-tag for ${adapterName}`); + } + // TODO(#382): should check for existence of adapter in app's package.json and use that version instead. + + console.log(" 🔥", bgRed(` ${adapterName}@${yellow(bold(adapterVersion))} `), "\n"); + + const buildCommand = `apphosting-adapter-${framework}-build`; + await new Promise((resolve, reject) => { + const child = spawn("npx", ["-y", "-p", `${adapterName}@${adapterVersion}`, buildCommand], { + cwd: projectRoot, + shell: true, + stdio: "inherit", + }); + + child.on("exit", (code) => { + if (code !== 0) { + reject(new Error(`framework adapter build failed with error code ${code}.`)); + } + resolve(); + }); + }); + // TODO(#382): parse bundle.yaml and apphosting.yaml and output a buildschema somewhere. + }); + +program.parse(); diff --git a/packages/@apphosting/build/tsconfig.json b/packages/@apphosting/build/tsconfig.json index 38e4cb58..3041a86e 100644 --- a/packages/@apphosting/build/tsconfig.json +++ b/packages/@apphosting/build/tsconfig.json @@ -2,10 +2,15 @@ "extends": "../../../tsconfig.json", "compilerOptions": { "noEmit": false, - "outDir": "dist" + "outDir": "dist", + "rootDir": "src" + }, "include": [ "src/index.ts", "src/bin/*.ts", - ] + ], + "exclude": [ + "src/*.spec.ts" + ] }