Skip to content

Commit

Permalink
Correctly determine channel for APIs with dependencies. (#48)
Browse files Browse the repository at this point in the history
When considering dependencies, we were incorrectly choosing the
"most released" channel as the channel an API became available.
This was causing some issues as, for example, action.openPopup
is still restricted to dev but it has a dependency of the action
key in the manifest which has existed in stable for a while.

Fixing this should make the openPopup API correctly appear as
restricted to dev, and also fix some other similar issues across
the generated types.
  • Loading branch information
oliverdunk authored Mar 6, 2023
1 parent 47ad02c commit 98aee76
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
26 changes: 25 additions & 1 deletion tools/lib/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,28 @@ export function mostReleasedChannel(a, b) {
} else {
return b;
}
}
}

/**
* Finds the channel that is furthest from 'stable'. If either param is `undefined`, returns the other.
*
* @param {chromeTypes.Channel | undefined} a
* @param {chromeTypes.Channel | undefined} b
* @return {chromeTypes.Channel | undefined}
*/
export function leastReleasedChannel(a, b) {
if (!a) {
return b;
} else if (!b) {
return a;
}

const indexA = channelOrdering.indexOf(a);
const indexB = channelOrdering.indexOf(b);

if (indexA > indexB) {
return a;
} else {
return b;
}
}
4 changes: 2 additions & 2 deletions tools/override.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import * as chromeTypes from '../types/chrome.js';
import * as overrideTypes from '../types/override.js';
import { mostReleasedChannel } from './lib/channel.js';
import { leastReleasedChannel, mostReleasedChannel } from './lib/channel.js';
import { buildNamespaceAwareMarkdownRewrite } from './lib/comment.js';
import { FeatureQuery } from './lib/feature-query.js';
import { namespaceNameFromId, parentId } from './lib/traverse.js';
Expand Down Expand Up @@ -446,7 +446,7 @@ export class RenderOverride extends EmptyRenderOverride {
let bestChannel = undefined;

this.#fq.checkFeature(id, (f, otherId) => {
bestChannel = mostReleasedChannel(bestChannel, f.channel);
bestChannel = leastReleasedChannel(bestChannel, f.channel);
});

return bestChannel ?? 'stable';
Expand Down

0 comments on commit 98aee76

Please sign in to comment.