From b42c6aa13d7320a47f7434f816eb9460ddb0d1ac Mon Sep 17 00:00:00 2001 From: James Daniels Date: Fri, 8 Oct 2021 12:16:10 -0400 Subject: [PATCH 1/4] Builds are stalling, this was a change try this fix --- package.json | 2 +- src/schematics/deploy/actions.ts | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 0ae9619d4..6fe4ad705 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "test:typings": "node ./tools/run-typings-test.js", "test:build": "bash ./test/ng-build/build.sh", "test:all": "npm run test:node && npm run test:chrome-headless && npm run test:typings && npm run test:build", - "build": "rimraf dist && ttsc -p tsconfig.build.json && node --trace-warnings ./tools/build.js", + "build": "rimraf dist && ttsc -p tsconfig.build.json && node --trace-warnings ./tools/build.js && npm pack ./dist/packages-dist", "build:jasmine": "tsc -p tsconfig.jasmine.json && cp ./dist/packages-dist/schematics/versions.json ./dist/out-tsc/jasmine/schematics", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 1" }, diff --git a/src/schematics/deploy/actions.ts b/src/schematics/deploy/actions.ts index e4e50e4e8..b08065b20 100644 --- a/src/schematics/deploy/actions.ts +++ b/src/schematics/deploy/actions.ts @@ -226,10 +226,13 @@ export const deployToFunction = async ( // tslint:disable-next-line:no-non-null-assertion const siteTarget = options.target ?? context.target!.project; - try { - execSync(`npm --prefix ${functionsOut} i`); - } catch (e) { - console.warn(e.messsage); + const functionsAbsolutePath = join(workspaceRoot, functionsOut); + if (existsSync(join(functionsAbsolutePath, 'package.json'))) { + try { + execSync(`npm --prefix ${functionsOut} install`); + } catch (e) { + console.warn(e.messsage); + } } if (options.preview) { From 2e134a109e9f072f76a8a29690e1ce8a65f515b9 Mon Sep 17 00:00:00 2001 From: James Daniels Date: Fri, 8 Oct 2021 12:42:00 -0400 Subject: [PATCH 2/4] Use absolute paths for ng deploy --- src/schematics/deploy/actions.jasmine.ts | 33 ++++++++++++++---------- src/schematics/deploy/actions.ts | 25 +++++++++--------- src/schematics/interfaces.ts | 1 + 3 files changed, 32 insertions(+), 27 deletions(-) diff --git a/src/schematics/deploy/actions.jasmine.ts b/src/schematics/deploy/actions.jasmine.ts index 80a88fee9..170ff79f0 100644 --- a/src/schematics/deploy/actions.jasmine.ts +++ b/src/schematics/deploy/actions.jasmine.ts @@ -26,6 +26,8 @@ login.list = () => Promise.resolve([{ user: { email: 'foo@bar.baz' }}]); login.add = () => Promise.resolve([{ user: { email: 'foo@bar.baz' }}]); login.use = () => Promise.resolve('foo@bar.baz'); +const workspaceRoot = join('home', 'user'); + const initMocks = () => { fsHost = { moveSync(_: string, __: string) { @@ -37,7 +39,10 @@ const initMocks = () => { copySync(_: string, __: string) { }, removeSync(_: string) { - } + }, + existsSync(_: string) { + return false; + }, }; firebaseMock = { @@ -183,7 +188,7 @@ describe('universal deployment', () => { await deployToFunction( firebaseMock, context, - '/home/user', + workspaceRoot, STATIC_BUILD_TARGET, SERVER_BUILD_TARGET, { preview: false }, @@ -196,8 +201,8 @@ describe('universal deployment', () => { const packageArgs = spy.calls.argsFor(0); const functionArgs = spy.calls.argsFor(1); - expect(packageArgs[0]).toBe(join('dist', 'package.json')); - expect(functionArgs[0]).toBe(join('dist', 'index.js')); + expect(packageArgs[0]).toBe(join(workspaceRoot, 'dist', 'package.json')); + expect(functionArgs[0]).toBe(join(workspaceRoot, 'dist', 'index.js')); }); it('should create a firebase function (new)', async () => { @@ -205,7 +210,7 @@ describe('universal deployment', () => { await deployToFunction( firebaseMock, context, - '/home/user', + workspaceRoot, STATIC_BUILD_TARGET, SERVER_BUILD_TARGET, { preview: false, outputPath: join('dist', 'functions') }, @@ -218,8 +223,8 @@ describe('universal deployment', () => { const packageArgs = spy.calls.argsFor(0); const functionArgs = spy.calls.argsFor(1); - expect(packageArgs[0]).toBe(join('dist', 'functions', 'package.json')); - expect(functionArgs[0]).toBe(join('dist', 'functions', 'index.js')); + expect(packageArgs[0]).toBe(join(workspaceRoot, 'dist', 'functions', 'package.json')); + expect(functionArgs[0]).toBe(join(workspaceRoot, 'dist', 'functions', 'index.js')); }); it('should rename the index.html file in the nested dist', async () => { @@ -227,7 +232,7 @@ describe('universal deployment', () => { await deployToFunction( firebaseMock, context, - '/home/user', + workspaceRoot, STATIC_BUILD_TARGET, SERVER_BUILD_TARGET, { preview: false }, @@ -240,8 +245,8 @@ describe('universal deployment', () => { const packageArgs = spy.calls.argsFor(0); expect(packageArgs).toEqual([ - join('dist', 'dist', 'browser', 'index.html'), - join('dist', 'dist', 'browser', 'index.original.html') + join(workspaceRoot, 'dist', 'dist', 'browser', 'index.html'), + join(workspaceRoot, 'dist', 'dist', 'browser', 'index.original.html') ]); }); @@ -250,7 +255,7 @@ describe('universal deployment', () => { await deployToFunction( firebaseMock, context, - '/home/user', + workspaceRoot, STATIC_BUILD_TARGET, SERVER_BUILD_TARGET, { preview: false, outputPath: join('dist', 'functions') }, @@ -263,8 +268,8 @@ describe('universal deployment', () => { const packageArgs = spy.calls.argsFor(0); expect(packageArgs).toEqual([ - join('dist', 'functions', 'dist', 'browser', 'index.html'), - join('dist', 'functions', 'dist', 'browser', 'index.original.html') + join(workspaceRoot, 'dist', 'functions', 'dist', 'browser', 'index.html'), + join(workspaceRoot, 'dist', 'functions', 'dist', 'browser', 'index.original.html') ]); }); @@ -273,7 +278,7 @@ describe('universal deployment', () => { await deployToFunction( firebaseMock, context, - '/home/user', + workspaceRoot, STATIC_BUILD_TARGET, SERVER_BUILD_TARGET, { preview: false }, diff --git a/src/schematics/deploy/actions.ts b/src/schematics/deploy/actions.ts index b08065b20..be2d4b4bf 100644 --- a/src/schematics/deploy/actions.ts +++ b/src/schematics/deploy/actions.ts @@ -110,6 +110,7 @@ const defaultFsHost: FSHost = { renameSync, copySync, removeSync, + existsSync, }; const findPackageVersion = (packageManager: string, name: string) => { @@ -176,14 +177,14 @@ export const deployToFunction = async ( ); } - const staticOut = staticBuildOptions.outputPath; - const serverOut = serverBuildOptions.outputPath; + const staticOut = join(workspaceRoot, staticBuildOptions.outputPath); + const serverOut = join(workspaceRoot, serverBuildOptions.outputPath); - const functionsOut = options.outputPath || dirname(serverOut); + const functionsOut = options.outputPath ? join(workspaceRoot, options.outputPath) : dirname(serverOut); const functionName = options.functionName || DEFAULT_FUNCTION_NAME; - const newStaticOut = join(functionsOut, staticOut); - const newServerOut = join(functionsOut, serverOut); + const newStaticOut = join(functionsOut, staticBuildOptions.outputPath); + const newServerOut = join(functionsOut, serverBuildOptions.outputPath); // New behavior vs. old if (options.outputPath) { @@ -204,8 +205,9 @@ export const deployToFunction = async ( ); } + const functionsPackageJsonPath = join(functionsOut, 'package.json'); fsHost.writeFileSync( - join(functionsOut, 'package.json'), + functionsPackageJsonPath, JSON.stringify(packageJson, null, 2) ); @@ -226,13 +228,10 @@ export const deployToFunction = async ( // tslint:disable-next-line:no-non-null-assertion const siteTarget = options.target ?? context.target!.project; - const functionsAbsolutePath = join(workspaceRoot, functionsOut); - if (existsSync(join(functionsAbsolutePath, 'package.json'))) { - try { - execSync(`npm --prefix ${functionsOut} install`); - } catch (e) { - console.warn(e.messsage); - } + if (fsHost.existsSync(functionsPackageJsonPath)) { + execSync(`npm --prefix ${functionsOut} install`); + } else { + console.error(`No package.json exists at ${functionsOut}`); } if (options.preview) { diff --git a/src/schematics/interfaces.ts b/src/schematics/interfaces.ts index 448f0eafd..e3e02c0a2 100644 --- a/src/schematics/interfaces.ts +++ b/src/schematics/interfaces.ts @@ -201,6 +201,7 @@ export interface FSHost { renameSync(src: string, dest: string): void; copySync(src: string, dest: string): void; removeSync(src: string): void; + existsSync(src: string): boolean; } export interface WorkspaceProject { From fda7ec13debddd774359c83445f6a7771c6432fb Mon Sep 17 00:00:00 2001 From: James Daniels Date: Fri, 8 Oct 2021 13:10:00 -0400 Subject: [PATCH 3/4] Fix for ng add no features, absolute paths on Cloud Run --- src/schematics/deploy/actions.ts | 15 +++++++-------- src/schematics/deploy/functions-templates.ts | 2 +- src/schematics/setup/index.ts | 2 ++ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/schematics/deploy/actions.ts b/src/schematics/deploy/actions.ts index be2d4b4bf..dc400133f 100644 --- a/src/schematics/deploy/actions.ts +++ b/src/schematics/deploy/actions.ts @@ -213,7 +213,7 @@ export const deployToFunction = async ( fsHost.writeFileSync( join(functionsOut, 'index.js'), - defaultFunction(serverOut, options, functionName) + defaultFunction(serverBuildOptions.outputPath, options, functionName) ); if (!options.prerender) { @@ -289,15 +289,14 @@ export const deployToCloudRun = async ( ); } - const staticOut = staticBuildOptions.outputPath; - const serverOut = serverBuildOptions.outputPath; + const staticOut = join(workspaceRoot, staticBuildOptions.outputPath); + const serverOut = join(workspaceRoot, serverBuildOptions.outputPath); - // TODO pull these from firebase config - const cloudRunOut = options.outputPath || staticBuildOptions.outputPath.replace('/browser', '/run'); + const cloudRunOut = options.outputPath ? join(workspaceRoot, options.outputPath) : join(dirname(serverOut), 'run'); const serviceId = options.functionName || DEFAULT_FUNCTION_NAME; - const newStaticOut = join(cloudRunOut, staticOut); - const newServerOut = join(cloudRunOut, serverOut); + const newStaticOut = join(cloudRunOut, staticBuildOptions.outputPath); + const newServerOut = join(cloudRunOut, serverBuildOptions.outputPath); // This is needed because in the server output there's a hardcoded dependency on $cwd/dist/browser, // This assumes that we've deployed our application dist directory and we're running the server @@ -307,7 +306,7 @@ export const deployToCloudRun = async ( fsHost.copySync(staticOut, newStaticOut); fsHost.copySync(serverOut, newServerOut); - const packageJson = getPackageJson(context, workspaceRoot, options, join(serverOut, 'main.js')); + const packageJson = getPackageJson(context, workspaceRoot, options, join(serverBuildOptions.outputPath, 'main.js')); const nodeVersion = packageJson.engines.node; if (!satisfies(process.versions.node, nodeVersion.toString())) { diff --git a/src/schematics/deploy/functions-templates.ts b/src/schematics/deploy/functions-templates.ts index 207212b43..39a530d90 100644 --- a/src/schematics/deploy/functions-templates.ts +++ b/src/schematics/deploy/functions-templates.ts @@ -20,7 +20,7 @@ export const defaultPackage = ( description: 'Angular Universal Application', main: main ?? 'index.js', scripts: { - start: main ? `node ${main}` : 'firebase functions:shell', + start: main ? `node ./${main}` : 'firebase functions:shell', }, engines: { node: (options.functionsNodeVersion || DEFAULT_NODE_VERSION).toString() diff --git a/src/schematics/setup/index.ts b/src/schematics/setup/index.ts index 43b95fd9f..3f7341e34 100644 --- a/src/schematics/setup/index.ts +++ b/src/schematics/setup/index.ts @@ -105,6 +105,8 @@ ${Object.entries(config.sdkConfig).reduce( }); default: throw(new SchematicsException(`Unimplemented PROJECT_TYPE ${config.projectType}`)); } + } else { + return Promise.resolve(); } }; From 98804b0ba7505c28e8d85d4ac268c19706b9c4fa Mon Sep 17 00:00:00 2001 From: James Daniels Date: Fri, 8 Oct 2021 13:12:20 -0400 Subject: [PATCH 4/4] Dont dot slash --- src/schematics/deploy/functions-templates.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/schematics/deploy/functions-templates.ts b/src/schematics/deploy/functions-templates.ts index 39a530d90..207212b43 100644 --- a/src/schematics/deploy/functions-templates.ts +++ b/src/schematics/deploy/functions-templates.ts @@ -20,7 +20,7 @@ export const defaultPackage = ( description: 'Angular Universal Application', main: main ?? 'index.js', scripts: { - start: main ? `node ./${main}` : 'firebase functions:shell', + start: main ? `node ${main}` : 'firebase functions:shell', }, engines: { node: (options.functionsNodeVersion || DEFAULT_NODE_VERSION).toString()