Skip to content

Commit

Permalink
feat: get react-native package name from package.json in codegen scri…
Browse files Browse the repository at this point in the history
…pt (#46604)

Summary:
This PR fixes the retrieval of react native package name to retrieve it from package.json.

This fixes the annoying message in codegen that poped up when installing pods:

```
[Codegen] Found react-native-macos
[Codegen] CodegenConfig Deprecated Setup for react-native-macos.
    The configuration file still contains the codegen in the libraries array.
    If possible, replace it with a single object.

BEFORE:
    {
      // ...
      "codegenConfig": {
        "libraries": [
          {
            "name": "libName1",
            "type": "all|components|modules",
            "jsSrcsRoot": "libName1/js"
          },
          {
            "name": "libName2",
            "type": "all|components|modules",
            "jsSrcsRoot": "libName2/src"
          }
        ]
      }
    }

    AFTER:
    {
      "codegenConfig": {
        "name": "libraries",
        "type": "all",
        "jsSrcsRoot": "."
      }
    }
```

## Changelog:

[GENERAL] [CHANGED] - get react-native package name from package.json in codegen script

Pull Request resolved: #46604

Test Plan: Install pods

Reviewed By: cortinico

Differential Revision: D63335543

Pulled By: arushikesarwani94

fbshipit-source-id: 0470e54f0fc7aa962918c889855c52648d11e32d
  • Loading branch information
okwasniewski authored and facebook-github-bot committed Sep 25, 2024
1 parent 68a6b69 commit 65575e8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ const path = require('path');

const rootPath = path.join(__dirname, '../../..');

const packageJson = JSON.stringify({
name: 'react-native',
});

describe('extractLibrariesFromJSON', () => {
it('extracts a single dependency when config has no libraries', () => {
let configFile = fixtures.noLibrariesConfigFile;
Expand Down Expand Up @@ -153,6 +157,7 @@ describe('delete empty files and folders', () => {
rmdirSync: filepath => {
rmdirSyncInvocationCount += 1;
},
readFileSync: () => packageJson,
}));

underTest._cleanupEmptyFilesAndFolders(targetFilepath);
Expand Down Expand Up @@ -186,6 +191,7 @@ describe('delete empty files and folders', () => {
rmdirSync: filepath => {
rmdirSyncInvocationCount += 1;
},
readFileSync: () => packageJson,
}));

underTest._cleanupEmptyFilesAndFolders(targetFilepath);
Expand Down Expand Up @@ -224,6 +230,7 @@ describe('delete empty files and folders', () => {
readdirInvocationCount += 1;
return content;
},
readFileSync: () => packageJson,
}));

underTest._cleanupEmptyFilesAndFolders(targetFolder);
Expand Down Expand Up @@ -273,6 +280,7 @@ describe('delete empty files and folders', () => {
readdirInvocation.push(filepath);
return filepath === targetFolder ? content : emptyContent;
},
readFileSync: () => packageJson,
}));

underTest._cleanupEmptyFilesAndFolders(targetFolder);
Expand Down Expand Up @@ -327,6 +335,7 @@ describe('delete empty files and folders', () => {
)
: emptyContent;
},
readFileSync: () => packageJson,
}));

underTest._cleanupEmptyFilesAndFolders(targetFolder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@ const CORE_LIBRARIES_WITH_OUTPUT_FOLDER = {
),
},
};
const REACT_NATIVE = 'react-native';

const packageJsonPath = path.join(
REACT_NATIVE_PACKAGE_ROOT_FOLDER,
'package.json',
);
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath));
const REACT_NATIVE = packageJson.name;

const MODULES_PROTOCOLS_H_TEMPLATE_PATH = path.join(
REACT_NATIVE_PACKAGE_ROOT_FOLDER,
Expand Down

0 comments on commit 65575e8

Please # to comment.