-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(builtin): more idiomatic pkg_npm
- require that we know the package_name (defaults to name) - require that we know the package.json file (or generate one if not) - give a buildozer command to sync the package.json name field into the BUILd file
- Loading branch information
Alex Eagle
committed
May 17, 2020
1 parent
e8ffdbc
commit dace29a
Showing
16 changed files
with
146 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const fs = require('fs'); | ||
|
||
function main([packageJsonPath, packageName, target, output]) { | ||
const failures = [], buildozerCmds = []; | ||
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')); | ||
if (packageJson.name !== packageName) { | ||
failures.push(`attribute package_name=${packageName} does not match package.json name = "${ | ||
packageJson.name}"`); | ||
buildozerCmds.push(`set package_name "${packageJson.name}"`) | ||
} | ||
|
||
if (failures.length > 0) { | ||
console.error(`ERROR: pkg_npm rule ${ | ||
target} was configured with attributes that don't match the package.json file:`); | ||
failures.forEach(f => console.error(' - ' + f)); | ||
console.error('\nYou can automatically fix this by running:'); | ||
console.error( | ||
` npx @bazel/buildozer ${buildozerCmds.map(c => `'${c}'`).join(' ')} ${target}`); | ||
console.error('Or to suppress this error, run:'); | ||
console.error(` npx @bazel/buildozer 'set validate False' ${target}`); | ||
return 1; | ||
} | ||
|
||
// We have to write an output so that Bazel needs to execute this action. | ||
// Make the output change whenever the attributes changed. | ||
require('fs').writeFileSync( | ||
output, ` | ||
// ${process.argv[1]} checked attributes for ${target} | ||
// packageName: ${packageName} | ||
`, | ||
'utf-8'); | ||
return 0; | ||
} | ||
|
||
if (require.main === module) { | ||
try { | ||
process.exitCode = main(process.argv.slice(2)); | ||
} catch (e) { | ||
console.error(process.argv[1], e); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters