Skip to content

Commit 8e690f6

Browse files
committed
fix(codegen): scan symlinked js source directories
1 parent 066c0d8 commit 8e690f6

2 files changed

Lines changed: 64 additions & 1 deletion

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
*/
9+
10+
'use strict';
11+
12+
const {
13+
combineSchemasInFileList,
14+
} = require('../combine-js-to-schema');
15+
const fs = require('fs');
16+
const os = require('os');
17+
const path = require('path');
18+
19+
describe('combine-js-to-schema', () => {
20+
let tmpdir;
21+
22+
beforeEach(() => {
23+
tmpdir = fs.mkdtempSync(path.join(os.tmpdir(), 'codegen-combine-'));
24+
});
25+
26+
afterEach(() => {
27+
fs.rmSync(tmpdir, {recursive: true, force: true});
28+
});
29+
30+
it('expands symlinked directories into source files', () => {
31+
const sourceDir = path.join(tmpdir, 'source');
32+
const symlinkDir = path.join(tmpdir, 'symlink');
33+
fs.mkdirSync(sourceDir);
34+
fs.symlinkSync(
35+
sourceDir,
36+
symlinkDir,
37+
process.platform === 'win32' ? 'junction' : 'dir',
38+
);
39+
40+
fs.writeFileSync(
41+
path.join(sourceDir, 'NativeSample.ts'),
42+
`
43+
import type {TurboModule} from 'react-native';
44+
import * as TurboModuleRegistry from 'TurboModuleRegistry';
45+
46+
export interface Spec extends TurboModule {
47+
sampleMethod: () => void;
48+
}
49+
50+
export default TurboModuleRegistry.get<Spec>('Sample');
51+
`,
52+
);
53+
54+
const schema = combineSchemasInFileList(
55+
[symlinkDir],
56+
null,
57+
null,
58+
'SampleSpec',
59+
);
60+
61+
expect(Object.keys(schema.modules)).toEqual(['NativeSample']);
62+
});
63+
});

packages/react-native-codegen/src/cli/combine/combine-js-to-schema.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function expandDirectoriesIntoFiles(
6363
): Array<string> {
6464
return fileList
6565
.flatMap(file => {
66-
if (!fs.lstatSync(file).isDirectory()) {
66+
if (!fs.statSync(file).isDirectory()) {
6767
return [file];
6868
}
6969
return globSync('**/*{,.fb}.{js,ts,tsx}', {

0 commit comments

Comments
 (0)