Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit 68fc463

Browse files
committed
fix(deep-linking): fix issue where deep link config ends up being null when full build is triggered via a change to a template file with the identical content
1 parent 033ffa3 commit 68fc463

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/deep-linking.spec.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { join } from 'path';
33
import * as deepLinking from './deep-linking';
44
import * as deeplinkUtils from './deep-linking/util';
55
import * as Constants from './util/constants';
6-
import { ChangedFile } from './util/interfaces';
6+
import { BuildState, ChangedFile } from './util/interfaces';
77
import { FileCache } from './util/file-cache';
88
import * as helpers from './util/helpers';
99

@@ -335,5 +335,26 @@ export class AppModule { }
335335
expect(spy).toHaveBeenCalledTimes(2);
336336
});
337337
});
338+
339+
describe('deepLinkingUpdate', () => {
340+
it('should clear an existing cached deep link string so it can generate a new one', () => {
341+
const context = {
342+
deepLinkState: BuildState.RequiresBuild,
343+
fileCache: new FileCache()
344+
};
345+
346+
const somePath = 'somePath';
347+
context.fileCache.set(somePath, { path: somePath, content: 'someContent'});
348+
const originalCachedDeepLinkString = 'someKnownString';
349+
deepLinking.setCachedDeepLinkString(originalCachedDeepLinkString);
350+
spyOn(helpers, helpers.getStringPropertyValue.name).and.returnValue(somePath);
351+
spyOn(deeplinkUtils, deeplinkUtils.hasExistingDeepLinkConfig.name).and.returnValue(false);
352+
const setDeeplinkConfigSpy = spyOn(helpers, helpers.setParsedDeepLinkConfig.name);
353+
return deepLinking.deepLinkingUpdate([], context).then(() => {
354+
expect(setDeeplinkConfigSpy.calls.mostRecent().args[0].length).toEqual(0);
355+
expect(deepLinking.cachedDeepLinkString).toEqual(null);
356+
});
357+
});
358+
});
338359
});
339360
});

src/deep-linking.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ export function deepLinkingWorkerImpl(context: BuildContext, changedFiles: Chang
5353
const deepLinkConfigEntries = getDeepLinkData(appNgModulePath, context.fileCache, context.runAot) || [];
5454
if (deepLinkConfigEntries.length) {
5555
const newDeepLinkString = convertDeepLinkConfigEntriesToString(deepLinkConfigEntries);
56-
5756
// 1. this is the first time running this, so update the build either way
5857
// 2. we have an existing deep link string, and we have a new one, and they're different - so go ahead and update the config
5958
// 3. the app's main ngmodule has changed, so we need to rewrite the config
@@ -104,6 +103,9 @@ export function deepLinkingUpdateImpl(changedFiles: ChangedFile[], context: Buil
104103

105104
export function deepLinkingWorkerFullUpdate(context: BuildContext) {
106105
const logger = new Logger(`deeplinks update`);
106+
// when a full build is required (when a template fails to update, etc), remove the cached deep link string to force a new one
107+
// to be inserted
108+
cachedDeepLinkString = null;
107109
return deepLinkingWorker(context).then((deepLinkConfigEntries: DeepLinkConfigEntry[]) => {
108110
setParsedDeepLinkConfig(deepLinkConfigEntries);
109111
logger.finish();
@@ -115,8 +117,12 @@ export function deepLinkingWorkerFullUpdate(context: BuildContext) {
115117
});
116118
}
117119

118-
// this is purely for testing
120+
// these functions are purely for testing
119121
export function reset() {
120122
cachedUnmodifiedAppNgModuleFileContent = null;
121123
cachedDeepLinkString = null;
122124
}
125+
126+
export function setCachedDeepLinkString(input: string) {
127+
cachedDeepLinkString = input;
128+
}

0 commit comments

Comments
 (0)