Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Commit 0eab4af

Browse files
authored
refactor: reuse getProjectDir from nativescript-hook (#474)
1 parent 496fa55 commit 0eab4af

File tree

3 files changed

+9
-28
lines changed

3 files changed

+9
-28
lines changed

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"dependencies": {
6363
"global-modules-path": "2.0.0",
6464
"minimatch": "3.0.4",
65-
"nativescript-hook": "0.2.2",
65+
"nativescript-hook": "0.2.3",
6666
"proxy-lib": "0.4.0",
6767
"request": "2.83.0",
6868
"schema-utils": "0.4.3",

Diff for: postinstall.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
const { dirname } = require("path");
44
const hook = require("nativescript-hook")(__dirname);
55

6-
if (hook.findProjectDir() === __dirname) {
7-
// We are installing dev dependencies for the nativescript-dev-webpack plugin.
8-
console.log("Skipping postinstall artifacts! We assumed the nativescript-dev-webpack is installing devDependencies");
9-
} else {
6+
const { getProjectDir } = require("./projectHelpers");
7+
8+
if (getProjectDir()) {
109
hook.postinstall();
1110
const installer = require("./installer");
1211
installer.install();
12+
} else {
13+
// We are installing dev dependencies for the nativescript-dev-webpack plugin.
14+
console.log("Skipping postinstall artifacts! We assumed the nativescript-dev-webpack is installing devDependencies");
1315
}

Diff for: projectHelpers.js

+2-23
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const path = require("path");
22
const fs = require("fs");
33
const semver = require("semver");
44
const { EOL } = require("os");
5+
const hook = require("nativescript-hook")(__dirname);
56

67
const {
78
PROJECT_DATA_GETTERS,
@@ -85,29 +86,7 @@ const writePackageJson = (content, projectDir) => {
8586
const packageJsonPath = getPackageJsonPath(projectDir);
8687
fs.writeFileSync(packageJsonPath, JSON.stringify(content, null, 2))
8788
}
88-
const getProjectDir = ({ nestingLvl } = { nestingLvl: 2 }) => {
89-
// INIT_CWD is available since npm 5.4
90-
const initCwd = process.env.INIT_CWD;
91-
const shouldUseInitCwd = (() => {
92-
if (!initCwd) {
93-
return false;
94-
}
95-
96-
const installedPackage = path.resolve(initCwd, "node_modules", "nativescript-dev-webpack");
97-
if (!fs.existsSync(installedPackage)) {
98-
return false;
99-
}
100-
101-
const stat = fs.lstatSync(installedPackage);
102-
return stat.isSymbolicLink();
103-
})();
104-
105-
return shouldUseInitCwd ?
106-
initCwd :
107-
Array
108-
.from(Array(nestingLvl))
109-
.reduce(dir => path.dirname(dir), __dirname);
110-
};
89+
const getProjectDir = hook.findProjectDir;
11190

11291
const toReleaseVersion = version =>
11392
version.replace(/-.*/, "");

0 commit comments

Comments
 (0)