@react-native-community/cli-config 7.0.1 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/build/commands/config.d.ts.map +1 -1
- package/build/commands/config.js +1 -1
- package/build/commands/config.js.map +1 -1
- package/build/loadConfig.d.ts.map +1 -1
- package/build/loadConfig.js +1 -11
- package/build/loadConfig.js.map +1 -1
- package/build/readConfigFromDisk.js +1 -4
- package/build/readConfigFromDisk.js.map +1 -1
- package/build/schema.d.ts +9 -2
- package/build/schema.d.ts.map +1 -1
- package/build/schema.js +29 -49
- package/build/schema.js.map +1 -1
- package/package.json +7 -6
- package/build/findAssets.d.ts +0 -8
- package/build/findAssets.d.ts.map +0 -1
- package/build/findAssets.js +0 -53
- package/build/findAssets.js.map +0 -1
- package/src/__tests__/__snapshots__/index-test.ts.snap +0 -185
- package/src/__tests__/findAssets-test.ts +0 -51
- package/src/__tests__/findDependencies-test.ts +0 -23
- package/src/__tests__/index-test.ts +0 -350
- package/src/assign.ts +0 -27
- package/src/commands/config.ts +0 -30
- package/src/errors.ts +0 -31
- package/src/findAssets.ts +0 -28
- package/src/findDependencies.ts +0 -24
- package/src/index.ts +0 -5
- package/src/loadConfig.ts +0 -157
- package/src/merge.ts +0 -12
- package/src/readConfigFromDisk.ts +0 -68
- package/src/resolveReactNativePath.ts +0 -25
- package/src/schema.ts +0 -201
- package/tsconfig.json +0 -8
- package/tsconfig.tsbuildinfo +0 -1957
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`should apply build types from dependency config 1`] = `
|
|
4
|
-
Object {
|
|
5
|
-
"assets": Array [],
|
|
6
|
-
"hooks": Object {},
|
|
7
|
-
"name": "react-native-test",
|
|
8
|
-
"params": Array [],
|
|
9
|
-
"platforms": Object {
|
|
10
|
-
"android": null,
|
|
11
|
-
"ios": Object {
|
|
12
|
-
"configurations": Array [
|
|
13
|
-
"debug",
|
|
14
|
-
],
|
|
15
|
-
"folder": "<<REPLACED>>/node_modules/react-native-test",
|
|
16
|
-
"libraryFolder": "Libraries",
|
|
17
|
-
"pbxprojPath": "<<REPLACED>>/node_modules/react-native-test/ios/HelloWorld.xcodeproj/project.pbxproj",
|
|
18
|
-
"plist": Array [],
|
|
19
|
-
"podfile": null,
|
|
20
|
-
"podspecPath": null,
|
|
21
|
-
"projectName": "HelloWorld.xcodeproj",
|
|
22
|
-
"projectPath": "<<REPLACED>>/node_modules/react-native-test/ios/HelloWorld.xcodeproj",
|
|
23
|
-
"scriptPhases": Array [],
|
|
24
|
-
"sharedLibraries": Array [],
|
|
25
|
-
"sourceDir": "<<REPLACED>>/node_modules/react-native-test/ios",
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
"root": "<<REPLACED>>/node_modules/react-native-test",
|
|
29
|
-
}
|
|
30
|
-
`;
|
|
31
|
-
|
|
32
|
-
exports[`should have a valid structure by default 1`] = `
|
|
33
|
-
Object {
|
|
34
|
-
"assets": Array [],
|
|
35
|
-
"commands": Array [],
|
|
36
|
-
"dependencies": Object {},
|
|
37
|
-
"healthChecks": Array [],
|
|
38
|
-
"platforms": Object {},
|
|
39
|
-
"project": Object {},
|
|
40
|
-
"reactNativePath": "<<REPLACED>>",
|
|
41
|
-
"root": "<<REPLACED>>",
|
|
42
|
-
}
|
|
43
|
-
`;
|
|
44
|
-
|
|
45
|
-
exports[`should load commands from "react-native-foo" and "react-native-bar" packages 1`] = `
|
|
46
|
-
Array [
|
|
47
|
-
Object {
|
|
48
|
-
"func": [Function],
|
|
49
|
-
"name": "foo-command",
|
|
50
|
-
},
|
|
51
|
-
Object {
|
|
52
|
-
"func": [Function],
|
|
53
|
-
"name": "bar-command",
|
|
54
|
-
},
|
|
55
|
-
]
|
|
56
|
-
`;
|
|
57
|
-
|
|
58
|
-
exports[`should merge project configuration with default values: snapshoting \`react-native-test\` config 1`] = `
|
|
59
|
-
Object {
|
|
60
|
-
"assets": Array [
|
|
61
|
-
"foo",
|
|
62
|
-
],
|
|
63
|
-
"hooks": Object {},
|
|
64
|
-
"name": "react-native-test",
|
|
65
|
-
"params": Array [],
|
|
66
|
-
"platforms": Object {
|
|
67
|
-
"android": null,
|
|
68
|
-
"ios": Object {
|
|
69
|
-
"configurations": Array [],
|
|
70
|
-
"folder": "<<REPLACED>>/node_modules/react-native-test",
|
|
71
|
-
"libraryFolder": "Libraries",
|
|
72
|
-
"pbxprojPath": "<<REPLACED>>/node_modules/react-native-test/ios/HelloWorld.xcodeproj/project.pbxproj",
|
|
73
|
-
"plist": Array [],
|
|
74
|
-
"podfile": null,
|
|
75
|
-
"podspecPath": null,
|
|
76
|
-
"projectName": "HelloWorld.xcodeproj",
|
|
77
|
-
"projectPath": "<<REPLACED>>/node_modules/react-native-test/ios/HelloWorld.xcodeproj",
|
|
78
|
-
"scriptPhases": Array [],
|
|
79
|
-
"sharedLibraries": Array [],
|
|
80
|
-
"sourceDir": "./abc",
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
"root": "<<REPLACED>>/node_modules/react-native-test",
|
|
84
|
-
}
|
|
85
|
-
`;
|
|
86
|
-
|
|
87
|
-
exports[`should read a config of a dependency and use it to load other settings 1`] = `
|
|
88
|
-
Object {
|
|
89
|
-
"assets": Array [],
|
|
90
|
-
"hooks": Object {},
|
|
91
|
-
"name": "react-native-test",
|
|
92
|
-
"params": Array [],
|
|
93
|
-
"platforms": Object {
|
|
94
|
-
"android": null,
|
|
95
|
-
"ios": Object {
|
|
96
|
-
"configurations": Array [],
|
|
97
|
-
"folder": "<<REPLACED>>/node_modules/react-native-test",
|
|
98
|
-
"libraryFolder": "Libraries",
|
|
99
|
-
"pbxprojPath": "<<REPLACED>>/node_modules/react-native-test/customLocation/customProject.xcodeproj/project.pbxproj",
|
|
100
|
-
"plist": Array [],
|
|
101
|
-
"podfile": null,
|
|
102
|
-
"podspecPath": "<<REPLACED>>/node_modules/react-native-test/ReactNativeTest.podspec",
|
|
103
|
-
"projectName": "customProject.xcodeproj",
|
|
104
|
-
"projectPath": "<<REPLACED>>/node_modules/react-native-test/customLocation/customProject.xcodeproj",
|
|
105
|
-
"scriptPhases": Array [],
|
|
106
|
-
"sharedLibraries": Array [],
|
|
107
|
-
"sourceDir": "<<REPLACED>>/node_modules/react-native-test/customLocation",
|
|
108
|
-
},
|
|
109
|
-
},
|
|
110
|
-
"root": "<<REPLACED>>/node_modules/react-native-test",
|
|
111
|
-
}
|
|
112
|
-
`;
|
|
113
|
-
|
|
114
|
-
exports[`should return dependencies from package.json 1`] = `
|
|
115
|
-
Object {
|
|
116
|
-
"react-native": Object {
|
|
117
|
-
"assets": Array [],
|
|
118
|
-
"hooks": Object {},
|
|
119
|
-
"name": "react-native",
|
|
120
|
-
"params": Array [],
|
|
121
|
-
"platforms": Object {
|
|
122
|
-
"android": null,
|
|
123
|
-
"ios": null,
|
|
124
|
-
},
|
|
125
|
-
"root": "<<REPLACED>>/node_modules/react-native",
|
|
126
|
-
},
|
|
127
|
-
"react-native-test": Object {
|
|
128
|
-
"assets": Array [],
|
|
129
|
-
"hooks": Object {},
|
|
130
|
-
"name": "react-native-test",
|
|
131
|
-
"params": Array [],
|
|
132
|
-
"platforms": Object {
|
|
133
|
-
"android": null,
|
|
134
|
-
"ios": Object {
|
|
135
|
-
"configurations": Array [],
|
|
136
|
-
"folder": "<<REPLACED>>/node_modules/react-native-test",
|
|
137
|
-
"libraryFolder": "Libraries",
|
|
138
|
-
"pbxprojPath": "<<REPLACED>>/node_modules/react-native-test/ios/HelloWorld.xcodeproj/project.pbxproj",
|
|
139
|
-
"plist": Array [],
|
|
140
|
-
"podfile": null,
|
|
141
|
-
"podspecPath": null,
|
|
142
|
-
"projectName": "HelloWorld.xcodeproj",
|
|
143
|
-
"projectPath": "<<REPLACED>>/node_modules/react-native-test/ios/HelloWorld.xcodeproj",
|
|
144
|
-
"scriptPhases": Array [],
|
|
145
|
-
"sharedLibraries": Array [],
|
|
146
|
-
"sourceDir": "<<REPLACED>>/node_modules/react-native-test/ios",
|
|
147
|
-
},
|
|
148
|
-
},
|
|
149
|
-
"root": "<<REPLACED>>/node_modules/react-native-test",
|
|
150
|
-
},
|
|
151
|
-
}
|
|
152
|
-
`;
|
|
153
|
-
|
|
154
|
-
exports[`should skip packages that have invalid configuration: dependencies config 1`] = `Object {}`;
|
|
155
|
-
|
|
156
|
-
exports[`should skip packages that have invalid configuration: logged warning 1`] = `"warn Package react-native has been ignored because it contains invalid configuration. Reason: \\"dependency.invalidProperty\\" is not allowed"`;
|
|
157
|
-
|
|
158
|
-
exports[`supports dependencies from user configuration with custom build type 1`] = `
|
|
159
|
-
Object {
|
|
160
|
-
"assets": Array [],
|
|
161
|
-
"hooks": Object {},
|
|
162
|
-
"name": "react-native-test",
|
|
163
|
-
"params": Array [],
|
|
164
|
-
"platforms": Object {
|
|
165
|
-
"android": null,
|
|
166
|
-
"ios": Object {
|
|
167
|
-
"configurations": Array [
|
|
168
|
-
"custom_build_type",
|
|
169
|
-
],
|
|
170
|
-
"folder": "<<REPLACED>>/node_modules/react-native-test",
|
|
171
|
-
"libraryFolder": "Libraries",
|
|
172
|
-
"pbxprojPath": "<<REPLACED>>/node_modules/react-native-test/ios/HelloWorld.xcodeproj/project.pbxproj",
|
|
173
|
-
"plist": Array [],
|
|
174
|
-
"podfile": null,
|
|
175
|
-
"podspecPath": null,
|
|
176
|
-
"projectName": "HelloWorld.xcodeproj",
|
|
177
|
-
"projectPath": "<<REPLACED>>/node_modules/react-native-test/ios/HelloWorld.xcodeproj",
|
|
178
|
-
"scriptPhases": Array [],
|
|
179
|
-
"sharedLibraries": Array [],
|
|
180
|
-
"sourceDir": "<<REPLACED>>/node_modules/react-native-test/ios",
|
|
181
|
-
},
|
|
182
|
-
},
|
|
183
|
-
"root": "<<REPLACED>>/node_modules/react-native-test",
|
|
184
|
-
}
|
|
185
|
-
`;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its 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
|
-
* @emails oncall+javascript_foundation
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import findAssets from '../findAssets';
|
|
12
|
-
|
|
13
|
-
jest.mock('path');
|
|
14
|
-
jest.mock('fs');
|
|
15
|
-
|
|
16
|
-
const fs = require('fs');
|
|
17
|
-
|
|
18
|
-
describe('findAssets', () => {
|
|
19
|
-
beforeEach(() => {
|
|
20
|
-
fs.__setMockFilesystem({
|
|
21
|
-
testDir: {
|
|
22
|
-
fonts: {
|
|
23
|
-
'A.ttf': '',
|
|
24
|
-
'B.ttf': '',
|
|
25
|
-
},
|
|
26
|
-
images: {
|
|
27
|
-
'C.jpg': '',
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('returns an array of all files in given folders', () => {
|
|
34
|
-
const assets = findAssets('/testDir', ['fonts', 'images']);
|
|
35
|
-
|
|
36
|
-
expect(Array.isArray(assets)).toBeTruthy();
|
|
37
|
-
expect(assets).toHaveLength(3);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('prepends assets paths with the folder path', () => {
|
|
41
|
-
const assets = findAssets('/testDir', ['fonts', 'images']);
|
|
42
|
-
|
|
43
|
-
assets.forEach((assetPath) => {
|
|
44
|
-
expect(assetPath).toContain('testDir');
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('returns an empty array if given assets are null', () => {
|
|
49
|
-
expect(findAssets('/testDir', null)).toHaveLength(0);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import findDependencies from '../findDependencies';
|
|
2
|
-
import {cleanup, writeFiles, getTempDirectory} from '../../../../jest/helpers';
|
|
3
|
-
|
|
4
|
-
beforeEach(async () => {
|
|
5
|
-
await cleanup(DIR);
|
|
6
|
-
jest.resetModules();
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
afterEach(async () => await cleanup(DIR));
|
|
10
|
-
|
|
11
|
-
const DIR = getTempDirectory('find_dependencies_test');
|
|
12
|
-
|
|
13
|
-
test('returns plugins from both dependencies and dev dependencies', () => {
|
|
14
|
-
writeFiles(DIR, {
|
|
15
|
-
'package.json': `
|
|
16
|
-
{
|
|
17
|
-
"dependencies": {"rnpm-plugin-test": "*"},
|
|
18
|
-
"devDependencies": {"rnpm-plugin-test-2": "*"}
|
|
19
|
-
}
|
|
20
|
-
`,
|
|
21
|
-
});
|
|
22
|
-
expect(findDependencies(DIR)).toHaveLength(2);
|
|
23
|
-
});
|
|
@@ -1,350 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import slash from 'slash';
|
|
3
|
-
import loadConfig from '..';
|
|
4
|
-
import {cleanup, writeFiles, getTempDirectory} from '../../../../jest/helpers';
|
|
5
|
-
|
|
6
|
-
let DIR = getTempDirectory('config_test');
|
|
7
|
-
|
|
8
|
-
jest.dontMock('@react-native-community/cli-tools');
|
|
9
|
-
|
|
10
|
-
const spy = jest.spyOn(global.console, 'warn').mockImplementation(jest.fn());
|
|
11
|
-
|
|
12
|
-
const iosPath = slash(
|
|
13
|
-
require.resolve('@react-native-community/cli-platform-ios'),
|
|
14
|
-
);
|
|
15
|
-
const androidPath = slash(
|
|
16
|
-
require.resolve('@react-native-community/cli-platform-android'),
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
const REACT_NATIVE_MOCK = {
|
|
20
|
-
'node_modules/react-native/package.json': '{}',
|
|
21
|
-
'node_modules/react-native/react-native.config.js': `
|
|
22
|
-
const ios = require("${iosPath}");
|
|
23
|
-
const android = require("${androidPath}");
|
|
24
|
-
module.exports = {
|
|
25
|
-
platforms: {
|
|
26
|
-
ios: {
|
|
27
|
-
linkConfig: ios.linkConfig,
|
|
28
|
-
projectConfig: ios.projectConfig,
|
|
29
|
-
dependencyConfig: ios.dependencyConfig,
|
|
30
|
-
},
|
|
31
|
-
android: {
|
|
32
|
-
linkConfig: android.linkConfig,
|
|
33
|
-
projectConfig: android.projectConfig,
|
|
34
|
-
dependencyConfig: android.dependencyConfig,
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
`,
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
// Removes string from all key/values within an object
|
|
42
|
-
const removeString = (config, str) =>
|
|
43
|
-
JSON.parse(
|
|
44
|
-
JSON.stringify(config, (_key, value) =>
|
|
45
|
-
// In certain cases, `str` (which is a temporary location) will be `/tmp`
|
|
46
|
-
// which is a symlink to `/private/tmp` on OS X. In this case, tests will fail.
|
|
47
|
-
// Following RegExp makes sure we strip the entire path.
|
|
48
|
-
typeof value === 'string'
|
|
49
|
-
? slash(value.replace(new RegExp(`(.*)${str}`), '<<REPLACED>>'))
|
|
50
|
-
: value,
|
|
51
|
-
),
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
beforeEach(async () => {
|
|
55
|
-
await cleanup(DIR);
|
|
56
|
-
jest.resetModules();
|
|
57
|
-
jest.clearAllMocks();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
afterEach(async () => await cleanup(DIR));
|
|
61
|
-
|
|
62
|
-
test('should have a valid structure by default', () => {
|
|
63
|
-
DIR = getTempDirectory('config_test_structure');
|
|
64
|
-
writeFiles(DIR, {
|
|
65
|
-
'react-native.config.js': `module.exports = {
|
|
66
|
-
reactNativePath: "."
|
|
67
|
-
}`,
|
|
68
|
-
});
|
|
69
|
-
const config = loadConfig(DIR);
|
|
70
|
-
expect(removeString(config, DIR)).toMatchSnapshot();
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
test('should return dependencies from package.json', () => {
|
|
74
|
-
DIR = getTempDirectory('config_test_deps');
|
|
75
|
-
writeFiles(DIR, {
|
|
76
|
-
...REACT_NATIVE_MOCK,
|
|
77
|
-
'node_modules/react-native-test/package.json': '{}',
|
|
78
|
-
'node_modules/react-native-test/ios/HelloWorld.xcodeproj/project.pbxproj':
|
|
79
|
-
'',
|
|
80
|
-
'package.json': `{
|
|
81
|
-
"dependencies": {
|
|
82
|
-
"react-native": "0.0.1",
|
|
83
|
-
"react-native-test": "0.0.1"
|
|
84
|
-
}
|
|
85
|
-
}`,
|
|
86
|
-
});
|
|
87
|
-
const {dependencies} = loadConfig(DIR);
|
|
88
|
-
expect(removeString(dependencies, DIR)).toMatchSnapshot();
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
test('should read a config of a dependency and use it to load other settings', () => {
|
|
92
|
-
DIR = getTempDirectory('config_test_settings');
|
|
93
|
-
writeFiles(DIR, {
|
|
94
|
-
...REACT_NATIVE_MOCK,
|
|
95
|
-
'node_modules/react-native-test/package.json': '{}',
|
|
96
|
-
'node_modules/react-native-test/ReactNativeTest.podspec': '',
|
|
97
|
-
'node_modules/react-native-test/react-native.config.js': `module.exports = {
|
|
98
|
-
dependency: {
|
|
99
|
-
platforms: {
|
|
100
|
-
ios: {
|
|
101
|
-
project: "./customLocation/customProject.xcodeproj"
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}`,
|
|
106
|
-
'package.json': `{
|
|
107
|
-
"dependencies": {
|
|
108
|
-
"react-native": "0.0.1",
|
|
109
|
-
"react-native-test": "0.0.1"
|
|
110
|
-
}
|
|
111
|
-
}`,
|
|
112
|
-
});
|
|
113
|
-
const {dependencies} = loadConfig(DIR);
|
|
114
|
-
expect(
|
|
115
|
-
removeString(dependencies['react-native-test'], DIR),
|
|
116
|
-
).toMatchSnapshot();
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
test('should merge project configuration with default values', () => {
|
|
120
|
-
DIR = getTempDirectory('config_test_merge');
|
|
121
|
-
writeFiles(DIR, {
|
|
122
|
-
...REACT_NATIVE_MOCK,
|
|
123
|
-
'node_modules/react-native-test/package.json': '{}',
|
|
124
|
-
'node_modules/react-native-test/react-native.config.js': `module.exports = {
|
|
125
|
-
dependency: {
|
|
126
|
-
assets: ["foo", "baz"]
|
|
127
|
-
}
|
|
128
|
-
}`,
|
|
129
|
-
'node_modules/react-native-test/ios/HelloWorld.xcodeproj/project.pbxproj':
|
|
130
|
-
'',
|
|
131
|
-
'package.json': `{
|
|
132
|
-
"dependencies": {
|
|
133
|
-
"react-native": "0.0.1",
|
|
134
|
-
"react-native-test": "0.0.1"
|
|
135
|
-
}
|
|
136
|
-
}`,
|
|
137
|
-
'react-native.config.js': `module.exports = {
|
|
138
|
-
reactNativePath: ".",
|
|
139
|
-
dependencies: {
|
|
140
|
-
"react-native-test": {
|
|
141
|
-
platforms: {
|
|
142
|
-
ios: {
|
|
143
|
-
sourceDir: "./abc"
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
assets: ["foo"]
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}`,
|
|
150
|
-
});
|
|
151
|
-
const {dependencies} = loadConfig(DIR);
|
|
152
|
-
expect(removeString(dependencies['react-native-test'], DIR)).toMatchSnapshot(
|
|
153
|
-
'snapshoting `react-native-test` config',
|
|
154
|
-
);
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
test('should load commands from "react-native-foo" and "react-native-bar" packages', () => {
|
|
158
|
-
DIR = getTempDirectory('config_test_packages');
|
|
159
|
-
writeFiles(DIR, {
|
|
160
|
-
'node_modules/react-native-foo/package.json': '{}',
|
|
161
|
-
'node_modules/react-native-foo/react-native.config.js': `module.exports = {
|
|
162
|
-
commands: [
|
|
163
|
-
{
|
|
164
|
-
name: 'foo-command',
|
|
165
|
-
func: () => console.log('foo')
|
|
166
|
-
}
|
|
167
|
-
]
|
|
168
|
-
}`,
|
|
169
|
-
'node_modules/react-native-bar/package.json': '{}',
|
|
170
|
-
'node_modules/react-native-bar/react-native.config.js': `module.exports = {
|
|
171
|
-
commands: [
|
|
172
|
-
{
|
|
173
|
-
name: 'bar-command',
|
|
174
|
-
func: () => console.log('bar')
|
|
175
|
-
}
|
|
176
|
-
]
|
|
177
|
-
}`,
|
|
178
|
-
'package.json': `{
|
|
179
|
-
"dependencies": {
|
|
180
|
-
"react-native-foo": "0.0.1",
|
|
181
|
-
"react-native-bar": "0.0.1"
|
|
182
|
-
}
|
|
183
|
-
}`,
|
|
184
|
-
});
|
|
185
|
-
const {commands} = loadConfig(DIR);
|
|
186
|
-
expect(commands).toMatchSnapshot();
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
test('should skip packages that have invalid configuration', () => {
|
|
190
|
-
process.env.FORCE_COLOR = '0'; // To disable chalk
|
|
191
|
-
DIR = getTempDirectory('config_test_skip');
|
|
192
|
-
writeFiles(DIR, {
|
|
193
|
-
'node_modules/react-native/package.json': '{}',
|
|
194
|
-
'node_modules/react-native/react-native.config.js': `module.exports = {
|
|
195
|
-
dependency: {
|
|
196
|
-
invalidProperty: 5
|
|
197
|
-
}
|
|
198
|
-
}`,
|
|
199
|
-
'package.json': `{
|
|
200
|
-
"dependencies": {
|
|
201
|
-
"react-native": "0.0.1"
|
|
202
|
-
}
|
|
203
|
-
}`,
|
|
204
|
-
});
|
|
205
|
-
const {dependencies} = loadConfig(DIR);
|
|
206
|
-
expect(dependencies).toMatchSnapshot('dependencies config');
|
|
207
|
-
expect(spy.mock.calls[0][0]).toMatchSnapshot('logged warning');
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
test('does not use restricted "react-native" key to resolve config from package.json', () => {
|
|
211
|
-
DIR = getTempDirectory('config_test_restricted');
|
|
212
|
-
writeFiles(DIR, {
|
|
213
|
-
'node_modules/react-native-netinfo/package.json': `{
|
|
214
|
-
"react-native": "src/index.js"
|
|
215
|
-
}`,
|
|
216
|
-
'package.json': `{
|
|
217
|
-
"dependencies": {
|
|
218
|
-
"react-native-netinfo": "0.0.1"
|
|
219
|
-
}
|
|
220
|
-
}`,
|
|
221
|
-
});
|
|
222
|
-
const {dependencies} = loadConfig(DIR);
|
|
223
|
-
expect(dependencies).toHaveProperty('react-native-netinfo');
|
|
224
|
-
expect(spy).not.toHaveBeenCalled();
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
test('supports dependencies from user configuration with custom root and properties', () => {
|
|
228
|
-
DIR = getTempDirectory('config_test_custom_root');
|
|
229
|
-
const escapePathSeparator = (value: string) =>
|
|
230
|
-
path.sep === '\\' ? value.replace(/(\/|\\)/g, '\\\\') : value;
|
|
231
|
-
|
|
232
|
-
writeFiles(DIR, {
|
|
233
|
-
...REACT_NATIVE_MOCK,
|
|
234
|
-
'native-libs/local-lib/ios/LocalRNLibrary.xcodeproj/project.pbxproj': '',
|
|
235
|
-
'react-native.config.js': `
|
|
236
|
-
const path = require('path');
|
|
237
|
-
const root = path.resolve('${escapePathSeparator(
|
|
238
|
-
DIR,
|
|
239
|
-
)}', 'native-libs', 'local-lib');
|
|
240
|
-
|
|
241
|
-
module.exports = {
|
|
242
|
-
dependencies: {
|
|
243
|
-
'local-lib': {
|
|
244
|
-
root,
|
|
245
|
-
platforms: {
|
|
246
|
-
ios: {
|
|
247
|
-
podspecPath: "custom-path"
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
},
|
|
251
|
-
}
|
|
252
|
-
}`,
|
|
253
|
-
'package.json': `{
|
|
254
|
-
"dependencies": {
|
|
255
|
-
"react-native": "0.0.1"
|
|
256
|
-
}
|
|
257
|
-
}`,
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
const {dependencies} = loadConfig(DIR);
|
|
261
|
-
expect(removeString(dependencies['local-lib'], DIR)).toMatchInlineSnapshot(`
|
|
262
|
-
Object {
|
|
263
|
-
"assets": Array [],
|
|
264
|
-
"hooks": Object {},
|
|
265
|
-
"name": "local-lib",
|
|
266
|
-
"params": Array [],
|
|
267
|
-
"platforms": Object {
|
|
268
|
-
"android": null,
|
|
269
|
-
"ios": Object {
|
|
270
|
-
"configurations": Array [],
|
|
271
|
-
"folder": "<<REPLACED>>/native-libs/local-lib",
|
|
272
|
-
"libraryFolder": "Libraries",
|
|
273
|
-
"pbxprojPath": "<<REPLACED>>/native-libs/local-lib/ios/LocalRNLibrary.xcodeproj/project.pbxproj",
|
|
274
|
-
"plist": Array [],
|
|
275
|
-
"podfile": null,
|
|
276
|
-
"podspecPath": "custom-path",
|
|
277
|
-
"projectName": "LocalRNLibrary.xcodeproj",
|
|
278
|
-
"projectPath": "<<REPLACED>>/native-libs/local-lib/ios/LocalRNLibrary.xcodeproj",
|
|
279
|
-
"scriptPhases": Array [],
|
|
280
|
-
"sharedLibraries": Array [],
|
|
281
|
-
"sourceDir": "<<REPLACED>>/native-libs/local-lib/ios",
|
|
282
|
-
},
|
|
283
|
-
},
|
|
284
|
-
"root": "<<REPLACED>>/native-libs/local-lib",
|
|
285
|
-
}
|
|
286
|
-
`);
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
test('should apply build types from dependency config', () => {
|
|
290
|
-
DIR = getTempDirectory('config_test_apply_dependency_config');
|
|
291
|
-
writeFiles(DIR, {
|
|
292
|
-
...REACT_NATIVE_MOCK,
|
|
293
|
-
'node_modules/react-native-test/package.json': '{}',
|
|
294
|
-
'node_modules/react-native-test/ios/HelloWorld.xcodeproj/project.pbxproj':
|
|
295
|
-
'',
|
|
296
|
-
'node_modules/react-native-test/react-native.config.js': `module.exports = {
|
|
297
|
-
dependency: {
|
|
298
|
-
platforms: {
|
|
299
|
-
ios: {
|
|
300
|
-
configurations: ["debug"]
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
}`,
|
|
305
|
-
'package.json': `{
|
|
306
|
-
"dependencies": {
|
|
307
|
-
"react-native": "0.0.1",
|
|
308
|
-
"react-native-test": "0.0.1"
|
|
309
|
-
}
|
|
310
|
-
}`,
|
|
311
|
-
});
|
|
312
|
-
const {dependencies} = loadConfig(DIR);
|
|
313
|
-
expect(
|
|
314
|
-
removeString(dependencies['react-native-test'], DIR),
|
|
315
|
-
).toMatchSnapshot();
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
test('supports dependencies from user configuration with custom build type', () => {
|
|
319
|
-
DIR = getTempDirectory('config_test_apply_custom_build_config');
|
|
320
|
-
writeFiles(DIR, {
|
|
321
|
-
...REACT_NATIVE_MOCK,
|
|
322
|
-
'react-native.config.js': `module.exports = {
|
|
323
|
-
dependencies: {
|
|
324
|
-
'react-native-test': {
|
|
325
|
-
platforms: {
|
|
326
|
-
ios: {
|
|
327
|
-
configurations: ["custom_build_type"]
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
},
|
|
331
|
-
}
|
|
332
|
-
}`,
|
|
333
|
-
'node_modules/react-native-test/package.json': '{}',
|
|
334
|
-
'node_modules/react-native-test/ios/HelloWorld.xcodeproj/project.pbxproj':
|
|
335
|
-
'',
|
|
336
|
-
'node_modules/react-native-test/react-native.config.js':
|
|
337
|
-
'module.exports = {}',
|
|
338
|
-
'package.json': `{
|
|
339
|
-
"dependencies": {
|
|
340
|
-
"react-native": "0.0.1",
|
|
341
|
-
"react-native-test": "0.0.1"
|
|
342
|
-
}
|
|
343
|
-
}`,
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
const {dependencies} = loadConfig(DIR);
|
|
347
|
-
expect(
|
|
348
|
-
removeString(dependencies['react-native-test'], DIR),
|
|
349
|
-
).toMatchSnapshot();
|
|
350
|
-
});
|
package/src/assign.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
|
|
3
|
-
*
|
|
4
|
-
* Similar to Object.assign(), but it doesn't execute getters. This allows us to have
|
|
5
|
-
* lazy properties on an object and still be able to merge them together
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
export default function assign(target: Object, ...sources: Object[]) {
|
|
9
|
-
sources.forEach((source) => {
|
|
10
|
-
let descriptors = Object.keys(source).reduce((acc, key) => {
|
|
11
|
-
const propertyDescriptor = Object.getOwnPropertyDescriptor(source, key);
|
|
12
|
-
if (propertyDescriptor !== undefined) {
|
|
13
|
-
acc[key] = propertyDescriptor;
|
|
14
|
-
}
|
|
15
|
-
return acc;
|
|
16
|
-
}, {} as PropertyDescriptorMap);
|
|
17
|
-
// by default, Object.assign copies enumerable Symbols too
|
|
18
|
-
Object.getOwnPropertySymbols(source).forEach((sym) => {
|
|
19
|
-
let descriptor = Object.getOwnPropertyDescriptor(source, sym);
|
|
20
|
-
if (descriptor && descriptor.enumerable) {
|
|
21
|
-
descriptors[sym.toString()] = descriptor;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
Object.defineProperties(target, descriptors);
|
|
25
|
-
});
|
|
26
|
-
return target;
|
|
27
|
-
}
|
package/src/commands/config.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import {Config, Dependency} from '@react-native-community/cli-types';
|
|
2
|
-
|
|
3
|
-
function isValidRNDependency(config: Dependency) {
|
|
4
|
-
return (
|
|
5
|
-
Object.keys(config.platforms).filter((key) =>
|
|
6
|
-
Boolean(config.platforms[key]),
|
|
7
|
-
).length !== 0 ||
|
|
8
|
-
(config.hooks && Object.keys(config.hooks).length !== 0) ||
|
|
9
|
-
(config.assets && config.assets.length !== 0) ||
|
|
10
|
-
(config.params && config.params.length !== 0)
|
|
11
|
-
);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function filterConfig(config: Config) {
|
|
15
|
-
const filtered = {...config};
|
|
16
|
-
Object.keys(filtered.dependencies).forEach((item) => {
|
|
17
|
-
if (!isValidRNDependency(filtered.dependencies[item])) {
|
|
18
|
-
delete filtered.dependencies[item];
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
return filtered;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export default {
|
|
25
|
-
name: 'config',
|
|
26
|
-
description: 'Print CLI configuration',
|
|
27
|
-
func: async (_argv: string[], ctx: Config) => {
|
|
28
|
-
console.log(JSON.stringify(filterConfig(ctx), null, 2));
|
|
29
|
-
},
|
|
30
|
-
};
|