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/reset_overrides_on_bootstrap #1796

Merged
merged 1 commit into from
Nov 25, 2024
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
3 changes: 2 additions & 1 deletion buildHooks/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { comparePluginTemplates } from './comparePluginTemplates';
import { comparePluginOverrides } from './comparePluginOverrides';

import { resetOverrides } from './resetOverrides';
import { prePublish } from './prePublish';
import { gitCommit, gitCommitAndTag, gitTag } from '@rnv/build-hooks-git';
import { generateSchema } from '@rnv/build-hooks-schema';
Expand All @@ -13,6 +13,7 @@ const hooks = {
gitCommit,
gitTag,
generateSchema,
resetOverrides,
};

const pipes = {};
Expand Down
45 changes: 45 additions & 0 deletions buildHooks/src/resetOverrides.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// npx rnv hooks run -x resetOverrides
import {
RnvFileName,
fsExistsSync,
fsReadFileSync,
logSuccess,
removeDirSync,
revertOverrideToOriginal,
} from '@rnv/core';
import path from 'path';

export const resetOverrides = async () => {
const overrideDir = path.join(process.cwd(), '.rnv', 'overrides');

const appliedOverrideFilePath = path.join(overrideDir, RnvFileName.appliedOverride);

if (fsExistsSync(appliedOverrideFilePath)) {
const appliedOverrides = JSON.parse(fsReadFileSync(appliedOverrideFilePath).toString());

Object.keys(appliedOverrides).forEach((moduleName) => {
const appliedVersion = appliedOverrides[moduleName].version;
const packageJsonPath = path.join(process.cwd(), 'node_modules', moduleName, RnvFileName.package);

if (fsExistsSync(packageJsonPath)) {
const packageContent = JSON.parse(fsReadFileSync(packageJsonPath).toString());
const currentVersion = packageContent.version;

if (currentVersion === appliedVersion) {
const packageOverrides = appliedOverrides[moduleName];
Object.keys(packageOverrides).forEach((filePath) => {
if (filePath !== 'version') {
const backupPath = path.join(overrideDir, moduleName, filePath);
const destinationPath = path.join(process.cwd(), 'node_modules', moduleName, filePath);

revertOverrideToOriginal(destinationPath, backupPath);
}
});
}
}
});
removeDirSync(overrideDir);
return logSuccess('Plugin overrides have been reverted successfully');
}
return logSuccess(`Plugin overrides have not been applied yet`);
};
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"url": "git://github.com/flexn-io/renative.git"
},
"scripts": {
"bootstrap": "npx lerna@6 bootstrap && yarn build && yarn link:rnv && yarn generateSchema",
"bootstrap": "npx lerna@6 bootstrap && yarn build && yarn link:rnv && yarn generateSchema && yarn resetOverrides",
"bootstrap-clean": "yarn clean-gitignore && yarn bootstrap",
"build": "lerna run build",
"clean-gitignore": "git clean -f -d -i -X",
Expand All @@ -66,9 +66,10 @@
"deploy:next": "yarn pre-publish && npx lerna publish from-package --dist-tag next && git push --tags origin HEAD",
"deploy:prod": "yarn pre-publish && npx lerna publish from-package && git push --tags origin HEAD",
"generateSchema": "npx rnv hooks run -x generateSchema",
"resetOverrides": "npx rnv hooks run -x resetOverrides",
"link:rnv": "npm r rnv -g && cd packages/rnv && npm link",
"lint": "npx eslint ./packages",
"postinstall": "npx lerna link --force-local && npx jetify && npx husky install ",
"postinstall": "npx lerna link --force-local && npx jetify && npx husky install",
"pre-publish": "yarn build && yarn link:rnv && yarn lint && yarn test && rnv hooks run -x prePublish && rnv hooks run -x gitCommitAndTag && yarn generateSchema",
"prettier-write-all": "npx prettier '**/*.{js,jsx,ts,tsx,mjs,cjs,json,md}' --write --config .prettierrc.js",
"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",
Expand Down
Loading