diff --git a/scripts/release/build.js b/scripts/release/build.js index b1d88e1a5390f5..3af5717b3f4ef7 100644 --- a/scripts/release/build.js +++ b/scripts/release/build.js @@ -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/'; @@ -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; } @@ -46,7 +48,6 @@ async function copyFiles() { } function createManifest() { - const full = require('../../package.json'); const minimal = { main: 'data.json', exports: { @@ -69,8 +70,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!`; } diff --git a/scripts/release/build.test.js b/scripts/release/build.test.js index d2de7180042fa7..830798a3207e43 100644 --- a/scripts/release/build.test.js +++ b/scripts/release/build.test.js @@ -6,6 +6,8 @@ const assert = require('assert').strict; const { execSync } = require('child_process'); +const { version } = require('../../package.json'); + const prebuiltPath = '../../build'; describe('release-build', () => { @@ -13,6 +15,7 @@ describe('release-build', () => { 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 }); diff --git a/utils/walk.js b/utils/walk.js index 10541f80f153fd..ca111d2ebd3cdf 100644 --- a/utils/walk.js +++ b/utils/walk.js @@ -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, diff --git a/utils/walkingUtils.js b/utils/walkingUtils.js index 4422b6c1e4accd..24c0835d147678 100644 --- a/utils/walkingUtils.js +++ b/utils/walkingUtils.js @@ -15,8 +15,13 @@ 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)) { @@ -24,7 +29,7 @@ function descendantKeys(data) { return []; } - return Object.keys(data); + return Object.keys(data).filter((key) => key !== '__meta'); } module.exports = {