diff --git a/packages/eslint-plugin-specs/package.json b/packages/eslint-plugin-specs/package.json index 4e60ce91ec3..7b6eb53772d 100644 --- a/packages/eslint-plugin-specs/package.json +++ b/packages/eslint-plugin-specs/package.json @@ -1,6 +1,6 @@ { "name": "@react-native/eslint-plugin-specs", - "version": "0.0.1", + "version": "0.0.2", "description": "ESLint rules to validate NativeModule and Component Specs", "main": "index.js", "repository": { @@ -8,6 +8,9 @@ "url": "git@github.com:facebook/react-native.git", "directory": "packages/eslint-plugin-specs" }, + "scripts": { + "prepublish": "node prepublish.js" + }, "dependencies": { "@babel/core": "^7.14.0", "@babel/plugin-transform-flow-strip-types": "^7.0.0", diff --git a/packages/eslint-plugin-specs/prepublish.js b/packages/eslint-plugin-specs/prepublish.js new file mode 100644 index 00000000000..0d4ab29f9cc --- /dev/null +++ b/packages/eslint-plugin-specs/prepublish.js @@ -0,0 +1,44 @@ +/** + * Copyright (c) Facebook, Inc. and its 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 = false;', + 'const PACKAGE_USAGE = true;', + ); + + 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, + ); + } + }, + ); +}); diff --git a/packages/eslint-plugin-specs/react-native-modules.js b/packages/eslint-plugin-specs/react-native-modules.js index c5f19fc0c30..73e7c662b41 100644 --- a/packages/eslint-plugin-specs/react-native-modules.js +++ b/packages/eslint-plugin-specs/react-native-modules.js @@ -13,6 +13,8 @@ const path = require('path'); const withBabelRegister = require('./with-babel-register'); +// We run yarn prepublish before publishing package which will set this value to true +const PACKAGE_USAGE = false; const ERRORS = { misnamedHasteModule(hasteModuleName) { return `Module ${hasteModuleName}: All files using TurboModuleRegistry must start with Native.`; @@ -24,15 +26,28 @@ let RNParserUtils; function requireModuleParser() { if (RNModuleParser == null || RNParserUtils == null) { - const config = { - only: [/react-native-codegen\/src\//], - plugins: [require('@babel/plugin-transform-flow-strip-types').default], - }; + // If using this externally, we leverage react-native-codegen as published form + if (!PACKAGE_USAGE) { + const config = { + only: [/react-native-codegen\/src\//], + plugins: [require('@babel/plugin-transform-flow-strip-types').default], + }; - withBabelRegister(config, () => { - RNModuleParser = require('react-native-codegen/src/parsers/flow/modules'); - RNParserUtils = require('react-native-codegen/src/parsers/flow/utils'); - }); + withBabelRegister(config, () => { + RNModuleParser = require('react-native-codegen/src/parsers/flow/modules'); + RNParserUtils = require('react-native-codegen/src/parsers/flow/utils'); + }); + } else { + const config = { + only: [/react-native-codegen\/lib\//], + plugins: [require('@babel/plugin-transform-flow-strip-types').default], + }; + + withBabelRegister(config, () => { + RNModuleParser = require('react-native-codegen/lib/parsers/flow/modules'); + RNParserUtils = require('react-native-codegen/lib/parsers/flow/utils'); + }); + } } return {