Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
grabbou authored Apr 18, 2019
1 parent a0b9e31 commit 9440b15
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 7 deletions.
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

0 comments on commit 9440b15

Please sign in to comment.