From 8e690f6e62051562a3da86075ff131fadf77b80a Mon Sep 17 00:00:00 2001 From: Sayem Chowdhury Date: Sat, 13 Jun 2026 19:34:13 +0600 Subject: [PATCH] fix(codegen): scan symlinked js source directories --- .../__tests__/combine-js-to-schema-test.js | 63 +++++++++++++++++++ .../src/cli/combine/combine-js-to-schema.js | 2 +- 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 packages/react-native-codegen/src/cli/combine/__tests__/combine-js-to-schema-test.js diff --git a/packages/react-native-codegen/src/cli/combine/__tests__/combine-js-to-schema-test.js b/packages/react-native-codegen/src/cli/combine/__tests__/combine-js-to-schema-test.js new file mode 100644 index 000000000000..ca754bbaf39e --- /dev/null +++ b/packages/react-native-codegen/src/cli/combine/__tests__/combine-js-to-schema-test.js @@ -0,0 +1,63 @@ +/** + * 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 + */ + +'use strict'; + +const { + combineSchemasInFileList, +} = require('../combine-js-to-schema'); +const fs = require('fs'); +const os = require('os'); +const path = require('path'); + +describe('combine-js-to-schema', () => { + let tmpdir; + + beforeEach(() => { + tmpdir = fs.mkdtempSync(path.join(os.tmpdir(), 'codegen-combine-')); + }); + + afterEach(() => { + fs.rmSync(tmpdir, {recursive: true, force: true}); + }); + + it('expands symlinked directories into source files', () => { + const sourceDir = path.join(tmpdir, 'source'); + const symlinkDir = path.join(tmpdir, 'symlink'); + fs.mkdirSync(sourceDir); + fs.symlinkSync( + sourceDir, + symlinkDir, + process.platform === 'win32' ? 'junction' : 'dir', + ); + + fs.writeFileSync( + path.join(sourceDir, 'NativeSample.ts'), + ` + import type {TurboModule} from 'react-native'; + import * as TurboModuleRegistry from 'TurboModuleRegistry'; + + export interface Spec extends TurboModule { + sampleMethod: () => void; + } + + export default TurboModuleRegistry.get('Sample'); + `, + ); + + const schema = combineSchemasInFileList( + [symlinkDir], + null, + null, + 'SampleSpec', + ); + + expect(Object.keys(schema.modules)).toEqual(['NativeSample']); + }); +}); diff --git a/packages/react-native-codegen/src/cli/combine/combine-js-to-schema.js b/packages/react-native-codegen/src/cli/combine/combine-js-to-schema.js index c8cec5079b0f..6f8544c2871c 100644 --- a/packages/react-native-codegen/src/cli/combine/combine-js-to-schema.js +++ b/packages/react-native-codegen/src/cli/combine/combine-js-to-schema.js @@ -63,7 +63,7 @@ function expandDirectoriesIntoFiles( ): Array { return fileList .flatMap(file => { - if (!fs.lstatSync(file).isDirectory()) { + if (!fs.statSync(file).isDirectory()) { return [file]; } return globSync('**/*{,.fb}.{js,ts,tsx}', {