From 8441c4a6f7bfeda73f89f076fe7d8d1132e4b9be Mon Sep 17 00:00:00 2001 From: Lorenzo Sciandra Date: Tue, 26 Jul 2022 06:47:51 -0700 Subject: [PATCH] fix npm lifecycle hook (#34273) Summary: In `0.70-stable` we started seeing `yarn run lint` fail; turns out, this is happening because the latest release of `react-native/eslint-plugin-specs` 0.0.4 (from https://github.com/facebook/react-native/commit/ea8d8e2f49ea3ce15faeab500b661a1cacacf8a8) is faulty: the underlying reason is that since 0.0.2 there was this local workaround in place https://github.com/facebook/react-native/commit/2d06e6a4c9261bb7790cf217b66145415301bc54 (that changes a flag from false to true) but in NPM 8 the lifecycle hook `prepublish` has [been deprecated](https://docs.npmjs.com/cli/v8/using-npm/scripts#life-cycle-scripts) so this pre publishing script to change the flag was not run (you can easily verify by checking the node_module and see `react-native-modules.js` the flag on L17 is set to false). This PR addresses it by moving to the new lifecycle hook `prepack` (and modifies the other files accordingly). After this PR is merged, we'll need to cherry pick it into 0.70 and do both a new release from the 0.70 branch and one from the main branch to have new versions of this module with the flag set correctly. ## Changelog [General] [Fixed] - Fix eslint-plugin-specs prepack npm lifecycle hook now that we use npm 8 Pull Request resolved: https://github.com/facebook/react-native/pull/34273 Test Plan: Go in the `eslint-plugin-specs` folder, run `npm pack`, unzip the generated tar file, go into `package`, verify that L17 of `react-native-modules.js` is correctly changed to `const PACKAGE_USAGE = true;` (instead of false - which is what happen without this fix). Reviewed By: GijsWeterings Differential Revision: D38151433 Pulled By: dmitryrykun fbshipit-source-id: 7c4f13dae70eb731d57cbafa90f7be05c9bb8576 --- packages/eslint-plugin-specs/package.json | 2 +- packages/eslint-plugin-specs/{prepublish.js => prepack.js} | 0 packages/eslint-plugin-specs/react-native-modules.js | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename packages/eslint-plugin-specs/{prepublish.js => prepack.js} (100%) diff --git a/packages/eslint-plugin-specs/package.json b/packages/eslint-plugin-specs/package.json index 8339cd008eea5e..0b404bee8c3425 100644 --- a/packages/eslint-plugin-specs/package.json +++ b/packages/eslint-plugin-specs/package.json @@ -9,7 +9,7 @@ "directory": "packages/eslint-plugin-specs" }, "scripts": { - "prepublish": "node prepublish.js" + "prepack": "node prepack.js" }, "dependencies": { "@babel/core": "^7.14.0", diff --git a/packages/eslint-plugin-specs/prepublish.js b/packages/eslint-plugin-specs/prepack.js similarity index 100% rename from packages/eslint-plugin-specs/prepublish.js rename to packages/eslint-plugin-specs/prepack.js diff --git a/packages/eslint-plugin-specs/react-native-modules.js b/packages/eslint-plugin-specs/react-native-modules.js index ae0041b0484452..d0b5aab0ac4cea 100644 --- a/packages/eslint-plugin-specs/react-native-modules.js +++ b/packages/eslint-plugin-specs/react-native-modules.js @@ -13,7 +13,7 @@ const path = require('path'); const withBabelRegister = require('./with-babel-register'); -// We run yarn prepublish before publishing package which will set this value to true +// We use the prepack hook before publishing package to set this value to true const PACKAGE_USAGE = false; const ERRORS = { misnamedHasteModule(hasteModuleName) {