Skip to content

Commit

Permalink
Add postpack hook that undoes prepack
Browse files Browse the repository at this point in the history
Summary: Changelog: [General][Changed] - `eslint-plugin-specs` package has prepack hook that changes `PACKAGE_USAGE` variable of `react-native-modules.js` to `true`. This changed file is can then be published to NPM, but should not be committed to the repo.  This diff adds postpack hook that reverts the change, so we do not have to do it manually.

Reviewed By: cipolleschi

Differential Revision: D38244367

fbshipit-source-id: 818dbdea82e7e4b89094b3e27ae2d63b9e736659
  • Loading branch information
Dmitry Rykun authored and roryabraham committed Aug 17, 2022
1 parent c942e85 commit 4b158f0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/eslint-plugin-specs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"directory": "packages/eslint-plugin-specs"
},
"scripts": {
"prepack": "node prepack.js"
"prepack": "node prepack.js",
"postpack": "node postpack.js"
},
"dependencies": {
"@babel/core": "^7.14.0",
Expand Down
44 changes: 44 additions & 0 deletions packages/eslint-plugin-specs/postpack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/

const fs = require('fs');

/**
* script to prepare package for publish.
*
* Due to differences to how we consume internal packages, update a flag
*/

fs.readFile('./react-native-modules.js', 'utf8', function (readError, source) {
if (readError != null) {
return console.error(
'Failed to read react-native-modules.js for publish',
readError,
);
}

const result = source.replace(
'const PACKAGE_USAGE = true;',
'const PACKAGE_USAGE = false;',
);

fs.writeFile(
'./react-native-modules.js',
result,
'utf8',
function (writeError) {
if (writeError != null) {
return console.error(
'Failed to update react-native-modules.js for publish',
writeError,
);
}
},
);
});

0 comments on commit 4b158f0

Please sign in to comment.