Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(postinstall): remove old hooks
As in 1.0.0 and CLI 6.0 we've changed the way nativescript-dev-webpack interacts with CLI, we need to remove hooks from previous nativescript-dev-webpack versions and use new ones. Usually this should happen with preuninstall script of the old version that removes the hooks. However, our current live version does not have such logic, so implement this in the postinstall of the current version. This way we try to ensure the current plugin will work correctly.
  • Loading branch information
rosen-vladimirov committed Jul 2, 2019
commit 7acdb729f2b343b7932570e414eea89d4dafd380
38 changes: 37 additions & 1 deletion postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,52 @@ const hook = require("nativescript-hook")(__dirname);

const { compareProjectFiles } = require("./projectFilesManager");
const { getProjectDir } = require("./projectHelpers");
const path = require("path");
const fs = require("fs");

const projectDir = getProjectDir();

// This method is introduced as in version 1.0.0 of nativescript-dev-webpack (compatible and required for NativeScript 6.0.0)
// we have changed a lot of hooks and old ones are incompatible. This should be automatically handled with preuninstall script of the old version.
// However, old versions of nativescript-dev-webpack do not have such logic, so remove them manually on postinstall of the current version.
// This logic can be removed later, once most of the projects are migrated to 1.0.0 of the package or later.
// These new versions have preuninstall script that will automatically handle this case.
function removeOldHooks() {
const oldHooks = [
"before-prepareJSApp",
"before-cleanApp",
"before-watch",
"after-watch",
"before-watchPatterns",
"before-shouldPrepare",
"after-prepare",
"before-preview-sync"
];

const hooksDir = path.join(projectDir, "hooks");
const pkgName = require("./package.json").name;
const filename = `${pkgName}.js`;
oldHooks.forEach(hookName => {
const hookPath = path.join(hooksDir, hookName, filename);

try {
if (fs.existsSync(hookPath)) {
fs.unlinkSync(hookPath);
}
} catch (err) {
console.warn(`${pkgName} postinstall task: unable to delete hook ${hookPath}. Error is: ${err}`);
}
});
}

if (projectDir) {
compareProjectFiles(projectDir);

removeOldHooks();
hook.postinstall();
const installer = require("./installer");
installer.install();
} else {
// We are installing dev dependencies for the nativescript-dev-webpack plugin.
console.log("Skipping postinstall artifacts! We assumed the nativescript-dev-webpack is installing devDependencies");
}