Skip to content

Commit 865faf0

Browse files
fix/reset_overrides_on_bootstrap
1 parent 221d076 commit 865faf0

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

buildHooks/src/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { comparePluginTemplates } from './comparePluginTemplates';
22
import { comparePluginOverrides } from './comparePluginOverrides';
3-
3+
import { resetOverrides } from './resetOverrides';
44
import { prePublish } from './prePublish';
55
import { gitCommit, gitCommitAndTag, gitTag } from '@rnv/build-hooks-git';
66
import { generateSchema } from '@rnv/build-hooks-schema';
@@ -13,6 +13,7 @@ const hooks = {
1313
gitCommit,
1414
gitTag,
1515
generateSchema,
16+
resetOverrides,
1617
};
1718

1819
const pipes = {};

buildHooks/src/resetOverrides.ts

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// npx rnv hooks run -x resetOverrides
2+
import {
3+
RnvFileName,
4+
fsExistsSync,
5+
fsReadFileSync,
6+
logSuccess,
7+
removeDirSync,
8+
revertOverrideToOriginal,
9+
} from '@rnv/core';
10+
import path from 'path';
11+
12+
export const resetOverrides = async () => {
13+
const overrideDir = path.join(process.cwd(), '.rnv', 'overrides');
14+
15+
const appliedOverrideFilePath = path.join(overrideDir, RnvFileName.appliedOverride);
16+
17+
if (fsExistsSync(appliedOverrideFilePath)) {
18+
const appliedOverrides = JSON.parse(fsReadFileSync(appliedOverrideFilePath).toString());
19+
20+
Object.keys(appliedOverrides).forEach((moduleName) => {
21+
const appliedVersion = appliedOverrides[moduleName].version;
22+
const packageJsonPath = path.join(process.cwd(), 'node_modules', moduleName, RnvFileName.package);
23+
24+
if (fsExistsSync(packageJsonPath)) {
25+
const packageContent = JSON.parse(fsReadFileSync(packageJsonPath).toString());
26+
const currentVersion = packageContent.version;
27+
28+
if (currentVersion === appliedVersion) {
29+
const packageOverrides = appliedOverrides[moduleName];
30+
Object.keys(packageOverrides).forEach((filePath) => {
31+
if (filePath !== 'version') {
32+
const backupPath = path.join(overrideDir, moduleName, filePath);
33+
const destinationPath = path.join(process.cwd(), 'node_modules', moduleName, filePath);
34+
35+
revertOverrideToOriginal(destinationPath, backupPath);
36+
}
37+
});
38+
}
39+
}
40+
});
41+
removeDirSync(overrideDir);
42+
return logSuccess('Plugin overrides have been reverted successfully');
43+
}
44+
return logSuccess(`Plugin overrides have not been applied yet`);
45+
};

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"url": "git://github.com/flexn-io/renative.git"
5757
},
5858
"scripts": {
59-
"bootstrap": "npx lerna@6 bootstrap && yarn build && yarn link:rnv && yarn generateSchema",
59+
"bootstrap": "npx lerna@6 bootstrap && yarn build && yarn link:rnv && yarn generateSchema && yarn resetOverrides",
6060
"bootstrap-clean": "yarn clean-gitignore && yarn bootstrap",
6161
"build": "lerna run build",
6262
"clean-gitignore": "git clean -f -d -i -X",
@@ -66,9 +66,10 @@
6666
"deploy:next": "yarn pre-publish && npx lerna publish from-package --dist-tag next && git push --tags origin HEAD",
6767
"deploy:prod": "yarn pre-publish && npx lerna publish from-package && git push --tags origin HEAD",
6868
"generateSchema": "npx rnv hooks run -x generateSchema",
69+
"resetOverrides": "npx rnv hooks run -x resetOverrides",
6970
"link:rnv": "npm r rnv -g && cd packages/rnv && npm link",
7071
"lint": "npx eslint ./packages",
71-
"postinstall": "npx lerna link --force-local && npx jetify && npx husky install ",
72+
"postinstall": "npx lerna link --force-local && npx jetify && npx husky install",
7273
"pre-publish": "yarn build && yarn link:rnv && yarn lint && yarn test && rnv hooks run -x prePublish && rnv hooks run -x gitCommitAndTag && yarn generateSchema",
7374
"prettier-write-all": "npx prettier '**/*.{js,jsx,ts,tsx,mjs,cjs,json,md}' --write --config .prettierrc.js",
7475
"prettier-write-json": "npx prettier '**/{package.json,renative.plugins.json,renative.json,renative.templates.json,renative.template.json,renative.plugin.json,renative.engine.json,rnv.json}' --write --config .prettierrc.js",

0 commit comments

Comments
 (0)