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

fix: read haste configuration from legacy config #336

Merged
merged 1 commit into from
Apr 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Array [
]
`;

exports[`should read \`rnpm\` config from a dependency and transform it to a new format 1`] = `
exports[`should read \`rnpm\` config from a dependency and transform it to a new format: foo config 1`] = `
Object {
"assets": Array [],
"hooks": Object {},
Expand All @@ -118,6 +118,20 @@ Object {
}
`;

exports[`should read \`rnpm\` config from a dependency and transform it to a new format: haste config 1`] = `
Object {
"platforms": Array [
"ios",
"android",
"dummy",
],
"providesModuleNodeModules": Array [
"react-native",
"react-native-dummy",
],
}
`;

exports[`should read a config of a dependency and use it to load other settings 1`] = `
Object {
"assets": Array [],
Expand Down
11 changes: 9 additions & 2 deletions packages/cli/src/tools/config/__tests__/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ test('should read `rnpm` config from a dependency and transform it to a new form
"rnpm": {
"ios": {
"project": "./customLocation/customProject.xcodeproj"
},
"haste": {
"platforms": ["dummy"],
"providesModuleNodeModules": ["react-native-dummy"]
}
}
}`,
Expand All @@ -140,8 +144,11 @@ test('should read `rnpm` config from a dependency and transform it to a new form
}
}`,
});
const {dependencies} = loadConfig(DIR);
expect(removeString(dependencies['react-native-foo'], DIR)).toMatchSnapshot();
const {dependencies, haste} = loadConfig(DIR);
expect(removeString(dependencies['react-native-foo'], DIR)).toMatchSnapshot(
'foo config',
);
expect(haste).toMatchSnapshot('haste config');
});

test('should load commands from "react-native-foo" and "react-native-bar" packages', () => {
Expand Down
20 changes: 16 additions & 4 deletions packages/cli/src/tools/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ function loadConfig(projectRoot: string = process.cwd()): ConfigT {

const isPlatform = Object.keys(config.platforms).length > 0;

/**
* Legacy `rnpm` config required `haste` to be defined. With new config,
* we do it automatically.
*
* Remove this once `rnpm` config is deprecated.
*/
const haste = config.haste || {
providesModuleNodeModules: isPlatform ? [dependencyName] : [],
platforms: Object.keys(config.platforms),
};

return assign({}, acc, {
dependencies: assign({}, acc.dependencies, {
// $FlowExpectedError: Dynamic getters are not supported
Expand Down Expand Up @@ -105,10 +116,11 @@ function loadConfig(projectRoot: string = process.cwd()): ConfigT {
...config.platforms,
},
haste: {
providesModuleNodeModules: acc.haste.providesModuleNodeModules.concat(
isPlatform ? dependencyName : [],
),
platforms: [...acc.haste.platforms, ...Object.keys(config.platforms)],
providesModuleNodeModules: [
...acc.haste.providesModuleNodeModules,
...haste.providesModuleNodeModules,
],
platforms: [...acc.haste.platforms, ...haste.platforms],
},
});
},
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/tools/config/readConfigFromDisk.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export function readLegacyDependencyConfigFromDisk(
hooks: config.commands,
params: config.params,
},
haste: config.haste,
commands: loadProjectCommands(rootFolder, config.plugin),
platforms: config.platform
? require(path.join(rootFolder, config.platform))
Expand Down
6 changes: 6 additions & 0 deletions types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ export type UserDependencyConfigT = {
platforms: {
[name: string]: any,
},

// Haste config defined by legacy `rnpm`
haste?: {
platforms: string[],
providesModuleNodeModules: string[],
},
};

/**
Expand Down