Skip to content

Commit bea9d67

Browse files
authored
chore(release): Fix hang in the test suite (#3005)
* Check for file existence before `npm install` on deploy, this was hanging up in some test environments * Prefer absolute paths on the deploy pipeline * Fix `ng add` stalling if you don't select any options
1 parent 95edc36 commit bea9d67

File tree

5 files changed

+42
-33
lines changed

5 files changed

+42
-33
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"test:typings": "node ./tools/run-typings-test.js",
1717
"test:build": "bash ./test/ng-build/build.sh",
1818
"test:all": "npm run test:node && npm run test:chrome-headless && npm run test:typings && npm run test:build",
19-
"build": "rimraf dist && ttsc -p tsconfig.build.json && node --trace-warnings ./tools/build.js",
19+
"build": "rimraf dist && ttsc -p tsconfig.build.json && node --trace-warnings ./tools/build.js && npm pack ./dist/packages-dist",
2020
"build:jasmine": "tsc -p tsconfig.jasmine.json && cp ./dist/packages-dist/schematics/versions.json ./dist/out-tsc/jasmine/schematics",
2121
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 1"
2222
},

src/schematics/deploy/actions.jasmine.ts

+19-14
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ login.list = () => Promise.resolve([{ user: { email: '[email protected]' }}]);
2626
login.add = () => Promise.resolve([{ user: { email: '[email protected]' }}]);
2727
login.use = () => Promise.resolve('[email protected]');
2828

29+
const workspaceRoot = join('home', 'user');
30+
2931
const initMocks = () => {
3032
fsHost = {
3133
moveSync(_: string, __: string) {
@@ -37,7 +39,10 @@ const initMocks = () => {
3739
copySync(_: string, __: string) {
3840
},
3941
removeSync(_: string) {
40-
}
42+
},
43+
existsSync(_: string) {
44+
return false;
45+
},
4146
};
4247

4348
firebaseMock = {
@@ -183,7 +188,7 @@ describe('universal deployment', () => {
183188
await deployToFunction(
184189
firebaseMock,
185190
context,
186-
'/home/user',
191+
workspaceRoot,
187192
STATIC_BUILD_TARGET,
188193
SERVER_BUILD_TARGET,
189194
{ preview: false },
@@ -196,16 +201,16 @@ describe('universal deployment', () => {
196201
const packageArgs = spy.calls.argsFor(0);
197202
const functionArgs = spy.calls.argsFor(1);
198203

199-
expect(packageArgs[0]).toBe(join('dist', 'package.json'));
200-
expect(functionArgs[0]).toBe(join('dist', 'index.js'));
204+
expect(packageArgs[0]).toBe(join(workspaceRoot, 'dist', 'package.json'));
205+
expect(functionArgs[0]).toBe(join(workspaceRoot, 'dist', 'index.js'));
201206
});
202207

203208
it('should create a firebase function (new)', async () => {
204209
const spy = spyOn(fsHost, 'writeFileSync');
205210
await deployToFunction(
206211
firebaseMock,
207212
context,
208-
'/home/user',
213+
workspaceRoot,
209214
STATIC_BUILD_TARGET,
210215
SERVER_BUILD_TARGET,
211216
{ preview: false, outputPath: join('dist', 'functions') },
@@ -218,16 +223,16 @@ describe('universal deployment', () => {
218223
const packageArgs = spy.calls.argsFor(0);
219224
const functionArgs = spy.calls.argsFor(1);
220225

221-
expect(packageArgs[0]).toBe(join('dist', 'functions', 'package.json'));
222-
expect(functionArgs[0]).toBe(join('dist', 'functions', 'index.js'));
226+
expect(packageArgs[0]).toBe(join(workspaceRoot, 'dist', 'functions', 'package.json'));
227+
expect(functionArgs[0]).toBe(join(workspaceRoot, 'dist', 'functions', 'index.js'));
223228
});
224229

225230
it('should rename the index.html file in the nested dist', async () => {
226231
const spy = spyOn(fsHost, 'renameSync');
227232
await deployToFunction(
228233
firebaseMock,
229234
context,
230-
'/home/user',
235+
workspaceRoot,
231236
STATIC_BUILD_TARGET,
232237
SERVER_BUILD_TARGET,
233238
{ preview: false },
@@ -240,8 +245,8 @@ describe('universal deployment', () => {
240245
const packageArgs = spy.calls.argsFor(0);
241246

242247
expect(packageArgs).toEqual([
243-
join('dist', 'dist', 'browser', 'index.html'),
244-
join('dist', 'dist', 'browser', 'index.original.html')
248+
join(workspaceRoot, 'dist', 'dist', 'browser', 'index.html'),
249+
join(workspaceRoot, 'dist', 'dist', 'browser', 'index.original.html')
245250
]);
246251
});
247252

@@ -250,7 +255,7 @@ describe('universal deployment', () => {
250255
await deployToFunction(
251256
firebaseMock,
252257
context,
253-
'/home/user',
258+
workspaceRoot,
254259
STATIC_BUILD_TARGET,
255260
SERVER_BUILD_TARGET,
256261
{ preview: false, outputPath: join('dist', 'functions') },
@@ -263,8 +268,8 @@ describe('universal deployment', () => {
263268
const packageArgs = spy.calls.argsFor(0);
264269

265270
expect(packageArgs).toEqual([
266-
join('dist', 'functions', 'dist', 'browser', 'index.html'),
267-
join('dist', 'functions', 'dist', 'browser', 'index.original.html')
271+
join(workspaceRoot, 'dist', 'functions', 'dist', 'browser', 'index.html'),
272+
join(workspaceRoot, 'dist', 'functions', 'dist', 'browser', 'index.original.html')
268273
]);
269274
});
270275

@@ -273,7 +278,7 @@ describe('universal deployment', () => {
273278
await deployToFunction(
274279
firebaseMock,
275280
context,
276-
'/home/user',
281+
workspaceRoot,
277282
STATIC_BUILD_TARGET,
278283
SERVER_BUILD_TARGET,
279284
{ preview: false },

src/schematics/deploy/actions.ts

+19-18
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ const defaultFsHost: FSHost = {
110110
renameSync,
111111
copySync,
112112
removeSync,
113+
existsSync,
113114
};
114115

115116
const findPackageVersion = (packageManager: string, name: string) => {
@@ -176,14 +177,14 @@ export const deployToFunction = async (
176177
);
177178
}
178179

179-
const staticOut = staticBuildOptions.outputPath;
180-
const serverOut = serverBuildOptions.outputPath;
180+
const staticOut = join(workspaceRoot, staticBuildOptions.outputPath);
181+
const serverOut = join(workspaceRoot, serverBuildOptions.outputPath);
181182

182-
const functionsOut = options.outputPath || dirname(serverOut);
183+
const functionsOut = options.outputPath ? join(workspaceRoot, options.outputPath) : dirname(serverOut);
183184
const functionName = options.functionName || DEFAULT_FUNCTION_NAME;
184185

185-
const newStaticOut = join(functionsOut, staticOut);
186-
const newServerOut = join(functionsOut, serverOut);
186+
const newStaticOut = join(functionsOut, staticBuildOptions.outputPath);
187+
const newServerOut = join(functionsOut, serverBuildOptions.outputPath);
187188

188189
// New behavior vs. old
189190
if (options.outputPath) {
@@ -204,14 +205,15 @@ export const deployToFunction = async (
204205
);
205206
}
206207

208+
const functionsPackageJsonPath = join(functionsOut, 'package.json');
207209
fsHost.writeFileSync(
208-
join(functionsOut, 'package.json'),
210+
functionsPackageJsonPath,
209211
JSON.stringify(packageJson, null, 2)
210212
);
211213

212214
fsHost.writeFileSync(
213215
join(functionsOut, 'index.js'),
214-
defaultFunction(serverOut, options, functionName)
216+
defaultFunction(serverBuildOptions.outputPath, options, functionName)
215217
);
216218

217219
if (!options.prerender) {
@@ -226,10 +228,10 @@ export const deployToFunction = async (
226228
// tslint:disable-next-line:no-non-null-assertion
227229
const siteTarget = options.target ?? context.target!.project;
228230

229-
try {
230-
execSync(`npm --prefix ${functionsOut} i`);
231-
} catch (e) {
232-
console.warn(e.messsage);
231+
if (fsHost.existsSync(functionsPackageJsonPath)) {
232+
execSync(`npm --prefix ${functionsOut} install`);
233+
} else {
234+
console.error(`No package.json exists at ${functionsOut}`);
233235
}
234236

235237
if (options.preview) {
@@ -287,15 +289,14 @@ export const deployToCloudRun = async (
287289
);
288290
}
289291

290-
const staticOut = staticBuildOptions.outputPath;
291-
const serverOut = serverBuildOptions.outputPath;
292+
const staticOut = join(workspaceRoot, staticBuildOptions.outputPath);
293+
const serverOut = join(workspaceRoot, serverBuildOptions.outputPath);
292294

293-
// TODO pull these from firebase config
294-
const cloudRunOut = options.outputPath || staticBuildOptions.outputPath.replace('/browser', '/run');
295+
const cloudRunOut = options.outputPath ? join(workspaceRoot, options.outputPath) : join(dirname(serverOut), 'run');
295296
const serviceId = options.functionName || DEFAULT_FUNCTION_NAME;
296297

297-
const newStaticOut = join(cloudRunOut, staticOut);
298-
const newServerOut = join(cloudRunOut, serverOut);
298+
const newStaticOut = join(cloudRunOut, staticBuildOptions.outputPath);
299+
const newServerOut = join(cloudRunOut, serverBuildOptions.outputPath);
299300

300301
// This is needed because in the server output there's a hardcoded dependency on $cwd/dist/browser,
301302
// This assumes that we've deployed our application dist directory and we're running the server
@@ -305,7 +306,7 @@ export const deployToCloudRun = async (
305306
fsHost.copySync(staticOut, newStaticOut);
306307
fsHost.copySync(serverOut, newServerOut);
307308

308-
const packageJson = getPackageJson(context, workspaceRoot, options, join(serverOut, 'main.js'));
309+
const packageJson = getPackageJson(context, workspaceRoot, options, join(serverBuildOptions.outputPath, 'main.js'));
309310
const nodeVersion = packageJson.engines.node;
310311

311312
if (!satisfies(process.versions.node, nodeVersion.toString())) {

src/schematics/interfaces.ts

+1
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ export interface FSHost {
201201
renameSync(src: string, dest: string): void;
202202
copySync(src: string, dest: string): void;
203203
removeSync(src: string): void;
204+
existsSync(src: string): boolean;
204205
}
205206

206207
export interface WorkspaceProject {

src/schematics/setup/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ ${Object.entries(config.sdkConfig).reduce(
105105
});
106106
default: throw(new SchematicsException(`Unimplemented PROJECT_TYPE ${config.projectType}`));
107107
}
108+
} else {
109+
return Promise.resolve();
108110
}
109111
};
110112

0 commit comments

Comments
 (0)