Skip to content

Commit

Permalink
refactor deprecation warning. working
Browse files Browse the repository at this point in the history
  • Loading branch information
russellwheatley committed Dec 13, 2024
1 parent 4467e54 commit 9b451d4
Show file tree
Hide file tree
Showing 5 changed files with 528 additions and 411 deletions.
30 changes: 30 additions & 0 deletions packages/app/lib/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ const mapOfDeprecationReplacements = {
},
},
firestore: {
statics: {
setLogLevel: 'setLogLevel()',
Filter: 'where()',
FieldValue: 'FieldValue',
Timestamp: 'Timestamp',
GeoPoint: 'GeoPoint',
Blob: 'Bytes',
FieldPath: 'FieldPath',
},
default: {
batch: 'writeBatch()',
loadBundle: 'loadBundle()',
Expand Down Expand Up @@ -234,6 +243,10 @@ export function createMessage(
}

function getNamespace(target) {
if (target.GeoPoint) {
// target is statics. GeoPoint is a static class on Firestore
return 'firestore';
}
if (target._config && target._config.namespace) {
return target._config.namespace;
}
Expand All @@ -246,6 +259,10 @@ function getNamespace(target) {
}

function getInstanceName(target) {
if (target.GeoPoint) {
// target is statics. GeoPoint is a static class on Firestore
return 'statics';
}
if (target._config) {
// module class instance, we use default to store map of deprecated methods
return 'default';
Expand All @@ -267,6 +284,19 @@ export function createDeprecationProxy(instance) {
return target.constructor;
}

if (
prop === 'Filter' ||
prop === 'FieldValue' ||
prop === 'Timestamp' ||
prop === 'GeoPoint' ||
prop === 'Blob' ||
prop === 'FieldPath'
) {
// Firestore statics
deprecationConsoleWarning('firestore', prop, 'statics', false);
return target[prop];
}

if (typeof originalMethod === 'function') {
return function (...args) {
const isModularMethod = args.includes(MODULAR_DEPRECATION_ARG);
Expand Down
2 changes: 1 addition & 1 deletion packages/app/lib/common/unitTestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const createCheckV9Deprecation = (moduleNames: string[]): CheckV9Deprecat
consoleWarnSpy.mockRestore();
const consoleWarnSpy2 = jest.spyOn(console, 'warn').mockImplementation(warnMessage => {
const message = createMessage(moduleName, methodNameKey, instanceName, uniqueMessage);
expect(message).toMatch(warnMessage);
expect(warnMessage).toMatch(message);
});
nonModularFunction();

Expand Down
5 changes: 3 additions & 2 deletions packages/app/lib/internal/registry/namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,9 @@ function getOrCreateModuleForRoot(moduleNamespace) {
}

Object.assign(firebaseModuleWithApp, statics || {});
Object.freeze(firebaseModuleWithApp);
MODULE_GETTER_FOR_ROOT[moduleNamespace] = firebaseModuleWithApp;
// Object.freeze(firebaseModuleWithApp);
// Wrap around statics, e.g. firebase.firestore.FieldValue, removed freeze as it stops proxy working. it is deprecated anyway
MODULE_GETTER_FOR_ROOT[moduleNamespace] = createDeprecationProxy(firebaseModuleWithApp);

return MODULE_GETTER_FOR_ROOT[moduleNamespace];
}
Expand Down
Loading

0 comments on commit 9b451d4

Please sign in to comment.