Skip to content

Commit ca39a11

Browse files
dmytrorykunfacebook-github-bot
authored andcommitted
Refactor generate-artifacts-executor.js: delete handleLibrariesFromReactNativeConfig (#41654)
Summary: Pull Request resolved: #41654 This diff removes support for defining external codegen targets in `react-native.config.js` for iOS. Now you can simply add your external dependency to the project's `package.json` and it will be resolved as a normal Node packages. ## Motivation The need for defining external codegen targets in `react-native.config.js` historically appeared due to limitations of how codegen searched for external dependencies. Basically we performed search only in the project directory. External dependency paths had to be listed in `react-native.config.js`. After D51303793 has landed we don't need this any longer. We can simply rely on Node resolution to find those external dependencies. Changelog: [iOS][Breaking] - Defining external codegen targets in `react-native.config.js` is not supported anymore. Define them as normal dependencies in `package.json`. Reviewed By: cipolleschi Differential Revision: D51308595 fbshipit-source-id: 97841a3a8c295aa717c577bb188d48373b04ba38
1 parent ef9c164 commit ca39a11

File tree

2 files changed

+0
-115
lines changed

2 files changed

+0
-115
lines changed

packages/react-native/scripts/codegen/__tests__/generate-artifacts-executor-test.js

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -118,76 +118,6 @@ describe('extractLibrariesFromJSON', () => {
118118
});
119119
});
120120

121-
describe('findCodegenEnabledLibraries', () => {
122-
const mock = require('mock-fs');
123-
const {
124-
_findCodegenEnabledLibraries: findCodegenEnabledLibraries,
125-
} = require('../generate-artifacts-executor');
126-
127-
afterEach(() => {
128-
mock.restore();
129-
});
130-
131-
it('returns libraries defined in react-native.config.js', () => {
132-
const projectDir = path.join(__dirname, '../../../../test-project');
133-
const baseCodegenConfigFileDir = path.join(__dirname, '../../..');
134-
const baseCodegenConfigFilePath = path.join(
135-
baseCodegenConfigFileDir,
136-
'package.json',
137-
);
138-
139-
mock({
140-
[baseCodegenConfigFilePath]: `
141-
{
142-
"codegenConfig": {}
143-
}
144-
`,
145-
[projectDir]: {
146-
app: {
147-
'package.json': `{
148-
"name": "my-app"
149-
}`,
150-
'react-native.config.js': '',
151-
},
152-
'library-foo': {
153-
'package.json': `{
154-
"name": "react-native-foo",
155-
"codegenConfig": {
156-
"name": "RNFooSpec",
157-
"type": "modules",
158-
"jsSrcsDir": "src"
159-
}
160-
}`,
161-
},
162-
},
163-
});
164-
165-
jest.mock(path.join(projectDir, 'app', 'react-native.config.js'), () => ({
166-
dependencies: {
167-
'react-native-foo': {
168-
root: path.join(projectDir, 'library-foo'),
169-
},
170-
'react-native-bar': {
171-
root: path.join(projectDir, 'library-bar'),
172-
},
173-
},
174-
}));
175-
176-
const libraries = findCodegenEnabledLibraries(`${projectDir}/app`);
177-
178-
expect(libraries).toEqual([
179-
{
180-
config: {},
181-
libraryPath: baseCodegenConfigFileDir,
182-
},
183-
{
184-
config: {name: 'RNFooSpec', type: 'modules', jsSrcsDir: 'src'},
185-
libraryPath: path.join(projectDir, 'library-foo'),
186-
},
187-
]);
188-
});
189-
});
190-
191121
describe('delete empty files and folders', () => {
192122
beforeEach(() => {
193123
jest.resetModules();

packages/react-native/scripts/codegen/generate-artifacts-executor.js

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -180,48 +180,6 @@ function handleThirdPartyLibraries(pkgJson) {
180180
});
181181
}
182182

183-
function handleLibrariesFromReactNativeConfig(appRootDir) {
184-
const rnConfigFileName = 'react-native.config.js';
185-
186-
console.log(
187-
`\n\n[Codegen] >>>>> Searching for codegen-enabled libraries in ${rnConfigFileName}`,
188-
);
189-
190-
const rnConfigFilePath = path.resolve(appRootDir, rnConfigFileName);
191-
192-
if (!fs.existsSync(rnConfigFilePath)) {
193-
return [];
194-
}
195-
const rnConfig = require(rnConfigFilePath);
196-
197-
if (rnConfig.dependencies == null) {
198-
return [];
199-
}
200-
return Object.keys(rnConfig.dependencies).flatMap(name => {
201-
const dependencyConfig = rnConfig.dependencies[name];
202-
203-
if (!dependencyConfig.root) {
204-
return [];
205-
}
206-
const codegenConfigFileDir = path.resolve(
207-
appRootDir,
208-
dependencyConfig.root,
209-
);
210-
let configFile;
211-
try {
212-
configFile = readPkgJsonInDirectory(codegenConfigFileDir);
213-
} catch {
214-
return [];
215-
}
216-
217-
return extractLibrariesFromJSON(
218-
configFile,
219-
configFile.name,
220-
codegenConfigFileDir,
221-
);
222-
});
223-
}
224-
225183
function handleInAppLibraries(pkgJson, appRootDir) {
226184
console.log(
227185
'\n\n[Codegen] >>>>> Searching for codegen-enabled libraries in the app',
@@ -343,7 +301,6 @@ function findCodegenEnabledLibraries(appRootDir) {
343301
return [
344302
...handleReactNativeCoreLibraries(),
345303
...handleThirdPartyLibraries(pkgJson),
346-
...handleLibrariesFromReactNativeConfig(appRootDir),
347304
...handleInAppLibraries(pkgJson, appRootDir),
348305
];
349306
}
@@ -434,7 +391,5 @@ module.exports = {
434391
execute: execute,
435392
// exported for testing purposes only:
436393
_extractLibrariesFromJSON: extractLibrariesFromJSON,
437-
_findCodegenEnabledLibraries: findCodegenEnabledLibraries,
438-
_generateCode: generateCode,
439394
_cleanupEmptyFilesAndFolders: cleanupEmptyFilesAndFolders,
440395
};

0 commit comments

Comments
 (0)