angular/aio/tools/transforms/angular-base-package/services/bazelStampedProperties.js
Derek Cormier 92d18bbac0 build(bazel): use workspace status command for AIO version stamping
Fixes a bug where the navigation map did not have the correct SHAs.
2022-11-22 13:51:16 -07:00

24 lines
No EOL
677 B
JavaScript

'use strict';
const fs = require('fs');
/**
* Provide stamped Bazel variables from the workspace status command.
*
* (see https://bazel.build/docs/user-manual#workspace-status)
*
* @returns a map of key-value pairs
*/
module.exports = function bazelStampedProperties() {
const volatileStatus = fs.readFileSync(process.env.BAZEL_VERSION_FILE, 'utf8');
const properties = {};
for (const match of `\n${volatileStatus}`.matchAll(/^([^\s]+)\s+(.*)/gm)) {
// Lines which go unmatched define an index value of `0` and should be skipped.
if (match.index === 0) {
continue;
}
properties[match[1]] = match[2];
}
return properties;
};