github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/ui/bin/gen-protobuf-cli-deps.js (about) 1 #!/usr/bin/env node 2 // Copyright 2019 The Cockroach Authors. 3 // 4 // Use of this software is governed by the Business Source License 5 // included in the file licenses/BSL.txt. 6 // 7 // As of the Change Date specified in that file, in accordance with 8 // the Business Source License, use of this software will be governed 9 // by the Apache License, Version 2.0, included in the file 10 // licenses/APL.txt. 11 12 13 // ProtobufJS's CLI attempts to install its own CLI dependencies at runtime by 14 // exec'ing NPM. This is crazy. It introduces a dependency on NPM and breaks our 15 // dependency pinning and vendoring. There is an upstream issue about this [1], 16 // but it hasn't received any attention in nearly a year. 17 // 18 // As a workaround, this script figures out what NPM packages the ProtobufJS CLI 19 // would install, mirroring the logic in [0], and generates a package.json 20 // encoding those dependencies. The Makefile can then invoke `yarn install` on 21 // this synthesized package, giving us enough control over the dependency 22 // installation to pin and vendor the dependencies. The ProtobufJS CLI will not 23 // try to invoke NPM itself if its required dependencies are already installed. 24 // 25 // TODO(benesch): switch away from ProtobufJS and use protoc's support for 26 // generating JavaScript directly. 27 // 28 // [0]: https://github.com/dcodeIO/protobuf.js/blob/e8449c4/cli/util.js#L135-L157 29 // [1]: https://github.com/dcodeIO/protobuf.js/issues/716 30 31 var pbjsPkg = require("protobufjs/package"); 32 33 const pbjsCliPkg = { 34 "//": "File automatically generated by gen-protobuf-cli-deps. DO NOT EDIT!", 35 dependencies: {}, 36 }; 37 38 pbjsPkg.cliDependencies.forEach(dep => { 39 const version = pbjsPkg.dependencies[dep] || pbjsPkg.devDependencies[dep]; 40 pbjsCliPkg.dependencies[dep] = version; 41 }) 42 43 process.stdout.write(JSON.stringify(pbjsCliPkg, null, 2));