Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add __meta property to BCD build #14129

Merged
merged 11 commits into from
May 18, 2022
7 changes: 4 additions & 3 deletions scripts/release-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
const fs = require('fs').promises;
const path = require('path');

const packageJson = require('../package.json');
const stringify = require('fast-json-stable-stringify');

const directory = './build/';
Expand All @@ -15,6 +16,7 @@ const verbatimFiles = ['LICENSE', 'README.md', 'index.d.ts', 'types.d.ts'];
// Returns a string representing data ready for writing to JSON file
function createDataBundle() {
const bcd = require('../index.js');
bcd.__meta = { version: packageJson.version };
const string = stringify(bcd);
return string;
}
Expand Down Expand Up @@ -42,7 +44,6 @@ async function copyFiles() {
}

function createManifest() {
const full = require('../package.json');
const minimal = { main: 'index.js' };

const minimalKeys = [
Expand All @@ -59,8 +60,8 @@ function createManifest() {
];

for (const key of minimalKeys) {
if (key in full) {
minimal[key] = full[key];
if (key in packageJson) {
minimal[key] = packageJson[key];
} else {
throw `Could not create a complete manifest! ${key} is missing!`;
}
Expand Down
3 changes: 3 additions & 0 deletions scripts/release-build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
const assert = require('assert').strict;
const { execSync } = require('child_process');

const { version } = require('../package.json');

const prebuiltPath = '../build';

describe('release-build', () => {
it('pre-built bundles are identical to the source', () => {
execSync('npm run release-build');
const regular = require('..');
const bundled = require(prebuiltPath);
regular.__meta = { version };
assert.deepEqual(regular, bundled);
}).timeout(5000); // Timeout must be long enough for all the file I/O
});
2 changes: 1 addition & 1 deletion utils/walk.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { isBrowser, descendantKeys, joinPath } = require('./walkingUtils');
const query = require('./query');

function* lowLevelWalk(data = bcd, path, depth = Infinity) {
if (path !== undefined) {
if (path !== undefined && path !== '__meta') {
const next = {
path,
data,
Expand Down
9 changes: 7 additions & 2 deletions utils/walkingUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,21 @@ function isBrowser(obj) {
}

function descendantKeys(data) {
if (typeof data !== 'object') {
// Return if the data isn't an object
return [];
}

if (isFeature(data)) {
return Object.keys(data).filter((key) => key !== '__compat');
return Object.keys(data).filter((key) => !key.startsWith('__'));
}

if (isBrowser(data)) {
// Browsers never have independently meaningful descendants
return [];
}

return Object.keys(data);
return Object.keys(data).filter((key) => key !== '__meta');
}

module.exports = {
Expand Down