Skip to content
Closed
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
47 changes: 40 additions & 7 deletions local-cli/link/android/patches/makePackagePatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,46 @@
* LICENSE file in the root directory of this source tree.
*/

const applyParams = require('./applyParams');

module.exports = function makePackagePatch(packageInstance, params, prefix) {
const processedInstance = applyParams(packageInstance, params, prefix);
const fs = require("fs")
const log = require('npmlog')
const applyParams = require("./applyParams")

function getPatchAndPattern(patch) {
return {
pattern: 'new MainReactPackage()',
patch: ',\n ' + processedInstance,
};
pattern: "new MainReactPackage()",
patch
}
}

function applyPackagePatch(
packageInstance,
params,
prefix) {
const processedInstance = applyParams(packageInstance, params, prefix)
return getPatchAndPattern(',\n ' + processedInstance)
}

function revokePackagePatch(file,
packageInstance,
params,
prefix) {
let processedInstance = applyParams(packageInstance, params, prefix).replace(
/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,
"\\$&"
)
let fileStream = fs.readFileSync(file, "utf8")

return getPatchAndPattern(
fileStream.match(
new RegExp(
`(,\\s*${processedInstance}|${processedInstance}\\s*,|\\s*${processedInstance}\\s*)`,
"g"
)
) || ""
)
}

module.exports = {
applyPackagePatch,
revokePackagePatch
};
4 changes: 2 additions & 2 deletions local-cli/link/android/registerNativeModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const makeStringsPatch = require('./patches/makeStringsPatch');
const makeSettingsPatch = require('./patches/makeSettingsPatch');
const makeBuildPatch = require('./patches/makeBuildPatch');
const makeImportPatch = require('./patches/makeImportPatch');
const makePackagePatch = require('./patches/makePackagePatch');
const { applyPackagePatch } = require('./patches/makePackagePatch');

module.exports = function registerNativeAndroidModule(
name,
Expand All @@ -30,7 +30,7 @@ module.exports = function registerNativeAndroidModule(

applyPatch(
projectConfig.mainFilePath,
makePackagePatch(androidConfig.packageInstance, params, name)
applyPackagePatch(androidConfig.packageInstance, params, name)
);

applyPatch(
Expand Down
4 changes: 2 additions & 2 deletions local-cli/link/android/unregisterNativeModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const makeSettingsPatch = require('./patches/makeSettingsPatch');
const makeBuildPatch = require('./patches/makeBuildPatch');
const makeStringsPatch = require('./patches/makeStringsPatch');
const makeImportPatch = require('./patches/makeImportPatch');
const makePackagePatch = require('./patches/makePackagePatch');
const { revokePackagePatch } = require('./patches/makePackagePatch');

module.exports = function unregisterNativeAndroidModule(
name,
Expand Down Expand Up @@ -41,7 +41,7 @@ module.exports = function unregisterNativeAndroidModule(

revokePatch(
projectConfig.mainFilePath,
makePackagePatch(androidConfig.packageInstance, params, name)
revokePackagePatch(projectConfig.mainFilePath, androidConfig.packageInstance, params, name)
);

revokePatch(
Expand Down
3 changes: 2 additions & 1 deletion local-cli/link/unlink.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/**
* Copyright (c) 2015-present, Facebook, Inc.
*
Expand Down Expand Up @@ -48,7 +49,7 @@ const unlinkDependency = (platforms, project, dependency, packageName, otherDepe
otherDependencies
);

log.info(`Platform '${platform}' module ${dependency.name} has been successfully unlinked`);
log.info(`Platform '${platform}' module ${packageName} has been successfully unlinked`);
});
};

Expand Down