Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Include transitive deps in autolinking #2054

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f8fa089
refactor: autolink transitive dependencies
TMisiukiewicz Sep 22, 2023
0401979
collect peer deps of projects dependencies
TMisiukiewicz Sep 22, 2023
f6e09aa
ignore optional peer deps
TMisiukiewicz Sep 22, 2023
d2e43b3
support npm
TMisiukiewicz Sep 22, 2023
a52888e
remove unused code
TMisiukiewicz Sep 22, 2023
54f6223
simplify deps installation
TMisiukiewicz Sep 22, 2023
4d6f8fc
run transitive deps installation when using npm
TMisiukiewicz Sep 22, 2023
f46240e
make transitive native libs visible for autolinking with npm
TMisiukiewicz Sep 22, 2023
3007302
checking peer dependencies with yarn
TMisiukiewicz Sep 22, 2023
2d4fb4c
add `--dependency-check` flag
TMisiukiewicz Sep 22, 2023
4634491
warn if cannot find matching version for a library
TMisiukiewicz Sep 22, 2023
2cee7d9
add tests for resolving transitive deps
TMisiukiewicz Sep 22, 2023
a56b80a
force add cli-doctor
TMisiukiewicz Sep 22, 2023
f81b0bc
fix circular reference
TMisiukiewicz Sep 22, 2023
e5e05b1
add new flag to README
TMisiukiewicz Sep 22, 2023
0a46e47
add transitive deps check to buildAndroid
TMisiukiewicz Sep 22, 2023
9c38ba3
remove --dependency-check flag
TMisiukiewicz Sep 22, 2023
4a5b4b2
refactor transitive deps mechanism
TMisiukiewicz Sep 22, 2023
26f262e
use config param to autolink peer deps
TMisiukiewicz Sep 22, 2023
5f1b739
don't run check for config command
TMisiukiewicz Sep 22, 2023
9ea7ff5
update tests
TMisiukiewicz Sep 28, 2023
e5c3720
add bun support
TMisiukiewicz Sep 29, 2023
6b48cff
update tests
TMisiukiewicz Sep 29, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions __e2e__/__snapshots__/config.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ exports[`shows up current config without unnecessary output 1`] = `
},
{
"name": "build-ios",
"description": "builds your app for iOS platform",
"description": "builds your app on iOS simulator",
"examples": [
"<<REPLACED>>"
],
Expand Down Expand Up @@ -65,9 +65,7 @@ exports[`shows up current config without unnecessary output 1`] = `
"android": {
"sourceDir": "<<REPLACED_ROOT>>/TestProject/android",
"appName": "app",
"packageName": "com.testproject",
"applicationId": "com.testproject",
"mainActivity": ".MainActivity"
"packageName": "com.testproject"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Object {
],
"podspecPath": "<<REPLACED>>/node_modules/react-native-test/ReactNativeTest.podspec",
"scriptPhases": Array [],
"version": "unresolved",
"version": "0.0.1",
},
},
"root": "<<REPLACED>>/node_modules/react-native-test",
Expand Down Expand Up @@ -58,7 +58,7 @@ Object {
"path": "./phase.sh",
},
],
"version": "unresolved",
"version": "0.0.1",
},
},
"root": "<<REPLACED>>/node_modules/react-native-test",
Expand Down Expand Up @@ -109,7 +109,7 @@ Object {
"show_env_vars_in_log": false,
},
],
"version": "unresolved",
"version": "0.0.1",
},
},
"root": "<<REPLACED>>/node_modules/react-native-test",
Expand All @@ -134,7 +134,7 @@ Object {
"configurations": Array [],
"podspecPath": "<<REPLACED>>/node_modules/react-native-test/ReactNativeTest.podspec",
"scriptPhases": Array [],
"version": "unresolved",
"version": "0.0.1",
},
},
"root": "<<REPLACED>>/node_modules/react-native-test",
Expand All @@ -153,7 +153,7 @@ Object {
],
"podspecPath": "<<REPLACED>>/node_modules/react-native-test/ReactNativeTest.podspec",
"scriptPhases": Array [],
"version": "unresolved",
"version": "0.0.1",
},
},
"root": "<<REPLACED>>/node_modules/react-native-test",
Expand Down
16 changes: 15 additions & 1 deletion packages/cli-config/src/__tests__/findDependencies-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,24 @@ test('returns plugins from both dependencies and dev dependencies', () => {
writeFiles(DIR, {
'package.json': `
{
"name": "plugin",
"version": "1.0.0",
"dependencies": {"rnpm-plugin-test": "*"},
"devDependencies": {"rnpm-plugin-test-2": "*"}
}
`,
'node_modules/rnpm-plugin-test/package.json': `
{
"name": "rnpm-plugin-test",
"version": "1.0.0"

}`,
'node_modules/rnpm-plugin-test-2/package.json': `
{
"name": "rnpm-plugin-test-2",
"version": "1.0.0"
}`,
});
expect(findDependencies(DIR)).toHaveLength(2);

expect(findDependencies(DIR).size).toBe(3);
});
119 changes: 84 additions & 35 deletions packages/cli-config/src/__tests__/index-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ const androidPath = slash(
);

const REACT_NATIVE_MOCK = {
'node_modules/react-native/package.json': '{}',
'node_modules/react-native/package.json': `
{
"name": "react-native",
"version": "0.0.1"
}
`,
'node_modules/react-native/react-native.config.js': `
const ios = require("${iosPath}");
const android = require("${androidPath}");
Expand Down Expand Up @@ -59,22 +64,27 @@ beforeEach(async () => {

afterEach(async () => await cleanup(DIR));

test('should have a valid structure by default', () => {
test('should have a valid structure by default', async () => {
DIR = getTempDirectory('config_test_structure');
writeFiles(DIR, {
'react-native.config.js': `module.exports = {
reactNativePath: "."
}`,
});
const config = loadConfig(DIR);
const config = await loadConfig(DIR);
expect(removeString(config, DIR)).toMatchSnapshot();
});

test('should return dependencies from package.json', () => {
test('should return dependencies from package.json', async () => {
DIR = getTempDirectory('config_test_deps');
writeFiles(DIR, {
...REACT_NATIVE_MOCK,
'node_modules/react-native-test/package.json': '{}',
'node_modules/react-native-test/package.json': `
{
"name": "react-native-test",
"version": "0.0.1"
}
`,
'node_modules/react-native-test/ReactNativeTest.podspec': '',
'package.json': `{
"dependencies": {
Expand All @@ -83,15 +93,20 @@ test('should return dependencies from package.json', () => {
}
}`,
});
const {dependencies} = loadConfig(DIR);
const {dependencies} = await loadConfig(DIR);
expect(removeString(dependencies, DIR)).toMatchSnapshot();
});

test('should read a config of a dependency and use it to load other settings', () => {
test('should read a config of a dependency and use it to load other settings', async () => {
DIR = getTempDirectory('config_test_settings');
writeFiles(DIR, {
...REACT_NATIVE_MOCK,
'node_modules/react-native-test/package.json': '{}',
'node_modules/react-native-test/package.json': `
{
"name": "react-native-test",
"version": "0.0.1"
}
`,
'node_modules/react-native-test/ReactNativeTest.podspec': '',
'node_modules/react-native-test/react-native.config.js': `module.exports = {
dependency: {
Expand Down Expand Up @@ -122,17 +137,22 @@ test('should read a config of a dependency and use it to load other settings', (
}
}`,
});
const {dependencies} = loadConfig(DIR);
const {dependencies} = await loadConfig(DIR);
expect(
removeString(dependencies['react-native-test'], DIR),
).toMatchSnapshot();
});

test('should merge project configuration with default values', () => {
test('should merge project configuration with default values', async () => {
DIR = getTempDirectory('config_test_merge');
writeFiles(DIR, {
...REACT_NATIVE_MOCK,
'node_modules/react-native-test/package.json': '{}',
'node_modules/react-native-test/package.json': `
{
"name": "react-native-test",
"version": "0.0.1"
}
`,
'node_modules/react-native-test/ReactNativeTest.podspec': '',
'package.json': `{
"dependencies": {
Expand All @@ -153,17 +173,22 @@ test('should merge project configuration with default values', () => {
}
}`,
});
const {dependencies} = loadConfig(DIR);
const {dependencies} = await loadConfig(DIR);
expect(removeString(dependencies['react-native-test'], DIR)).toMatchSnapshot(
'snapshoting `react-native-test` config',
);
});

test('should load commands from "react-native-foo" and "react-native-bar" packages', () => {
test('should load commands from "react-native-foo" and "react-native-bar" packages', async () => {
DIR = getTempDirectory('config_test_packages');
writeFiles(DIR, {
'react-native.config.js': 'module.exports = { reactNativePath: "." }',
'node_modules/react-native-foo/package.json': '{}',
'node_modules/react-native-foo/package.json': `
{
"name": "react-native-foo",
"version": "0.0.1"
}
`,
'node_modules/react-native-foo/react-native.config.js': `module.exports = {
commands: [
{
Expand All @@ -172,7 +197,12 @@ test('should load commands from "react-native-foo" and "react-native-bar" packag
}
]
}`,
'node_modules/react-native-bar/package.json': '{}',
'node_modules/react-native-bar/package.json': `
{
"name": "react-native-bar",
"version": "0.0.1"
}
`,
'node_modules/react-native-bar/react-native.config.js': `module.exports = {
commands: [
{
Expand All @@ -188,15 +218,20 @@ test('should load commands from "react-native-foo" and "react-native-bar" packag
}
}`,
});
const {commands} = loadConfig(DIR);
const {commands} = await loadConfig(DIR);
expect(commands).toMatchSnapshot();
});

test('should not skip packages that have invalid configuration (to avoid breaking users)', () => {
test('should not skip packages that have invalid configuration (to avoid breaking users)', async () => {
process.env.FORCE_COLOR = '0'; // To disable chalk
DIR = getTempDirectory('config_test_skip');
writeFiles(DIR, {
'node_modules/react-native/package.json': '{}',
'node_modules/react-native/package.json': `
{
"name": "react-native",
"version": "0.0.1"
}
`,
'node_modules/react-native/react-native.config.js': `module.exports = {
dependency: {
invalidProperty: 5
Expand All @@ -208,18 +243,20 @@ test('should not skip packages that have invalid configuration (to avoid breakin
}
}`,
});
const {dependencies} = loadConfig(DIR);
const {dependencies} = await loadConfig(DIR);
expect(removeString(dependencies, DIR)).toMatchSnapshot(
'dependencies config',
);
expect(spy.mock.calls[0][0]).toMatchSnapshot('logged warning');
});

test('does not use restricted "react-native" key to resolve config from package.json', () => {
test('does not use restricted "react-native" key to resolve config from package.json', async () => {
DIR = getTempDirectory('config_test_restricted');
writeFiles(DIR, {
'node_modules/react-native-netinfo/package.json': `{
"react-native": "src/index.js"
"react-native": "src/index.js",
"name": "react-native-netinfo",
"version": "0.0.1"
}`,
'react-native.config.js': 'module.exports = { reactNativePath: "." }',
'package.json': `{
Expand All @@ -228,12 +265,13 @@ test('does not use restricted "react-native" key to resolve config from package.
}
}`,
});
const {dependencies} = loadConfig(DIR);
const {dependencies} = await loadConfig(DIR);

expect(dependencies).toHaveProperty('react-native-netinfo');
expect(spy).not.toHaveBeenCalled();
});

test('supports dependencies from user configuration with custom root and properties', () => {
test('supports dependencies from user configuration with custom root and properties', async () => {
DIR = getTempDirectory('config_test_custom_root');
const escapePathSeparator = (value: string) =>
path.sep === '\\' ? value.replace(/(\/|\\)/g, '\\\\') : value;
Expand Down Expand Up @@ -274,7 +312,7 @@ module.exports = {
}`,
});

const {dependencies} = loadConfig(DIR);
const {dependencies} = await loadConfig(DIR);
expect(removeString(dependencies['local-lib'], DIR)).toMatchInlineSnapshot(`
Object {
"name": "local-lib",
Expand All @@ -292,11 +330,14 @@ module.exports = {
`);
});

test('should apply build types from dependency config', () => {
test('should apply build types from dependency config', async () => {
DIR = getTempDirectory('config_test_apply_dependency_config');
writeFiles(DIR, {
...REACT_NATIVE_MOCK,
'node_modules/react-native-test/package.json': '{}',
'node_modules/react-native-test/package.json': `{
"name": "react-native-test",
"version": "0.0.1"
}`,
'node_modules/react-native-test/ReactNativeTest.podspec': '',
'node_modules/react-native-test/react-native.config.js': `module.exports = {
dependency: {
Expand All @@ -314,13 +355,13 @@ test('should apply build types from dependency config', () => {
}
}`,
});
const {dependencies} = loadConfig(DIR);
const {dependencies} = await loadConfig(DIR);
expect(
removeString(dependencies['react-native-test'], DIR),
).toMatchSnapshot();
});

test('supports dependencies from user configuration with custom build type', () => {
test('supports dependencies from user configuration with custom build type', async () => {
DIR = getTempDirectory('config_test_apply_custom_build_config');
writeFiles(DIR, {
...REACT_NATIVE_MOCK,
Expand All @@ -335,7 +376,12 @@ test('supports dependencies from user configuration with custom build type', ()
},
}
}`,
'node_modules/react-native-test/package.json': '{}',
'node_modules/react-native-test/package.json': `
{
"name": "react-native-test",
"version": "0.0.1"
}
`,
'node_modules/react-native-test/ReactNativeTest.podspec': '',
'node_modules/react-native-test/react-native.config.js':
'module.exports = {}',
Expand All @@ -347,17 +393,20 @@ test('supports dependencies from user configuration with custom build type', ()
}`,
});

const {dependencies} = loadConfig(DIR);
const {dependencies} = await loadConfig(DIR);
expect(
removeString(dependencies['react-native-test'], DIR),
).toMatchSnapshot();
});

test('supports disabling dependency for ios platform', () => {
test('supports disabling dependency for ios platform', async () => {
DIR = getTempDirectory('config_test_disable_dependency_platform');
writeFiles(DIR, {
...REACT_NATIVE_MOCK,
'node_modules/react-native-test/package.json': '{}',
'node_modules/react-native-test/package.json': `{
"name": "react-native-test",
"version": "0.0.1"
}`,
'node_modules/react-native-test/ReactNativeTest.podspec': '',
'node_modules/react-native-test/react-native.config.js': `
module.exports = {
Expand All @@ -376,13 +425,13 @@ test('supports disabling dependency for ios platform', () => {
}`,
});

const {dependencies} = loadConfig(DIR);
const {dependencies} = await loadConfig(DIR);
expect(
removeString(dependencies['react-native-test'], DIR),
).toMatchSnapshot();
});

test('should convert project sourceDir relative path to absolute', () => {
test('should convert project sourceDir relative path to absolute', async () => {
DIR = getTempDirectory('config_test_absolute_project_source_dir');
const iosProjectDir = './ios2';
const androidProjectDir = './android2';
Expand Down Expand Up @@ -441,7 +490,7 @@ test('should convert project sourceDir relative path to absolute', () => {
`,
});

const config = loadConfig(DIR);
const config = await loadConfig(DIR);

expect(config.project.ios?.sourceDir).toBe(path.join(DIR, iosProjectDir));
expect(config.project.android?.sourceDir).toBe(
Expand Down
Loading
Loading