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

Commit 7933f6e

Browse files
author
Dimitar Tachev
authored
Merge pull request #1010 from NativeScript/tachev/pick-patch-fix
fix(update-ns-webpack): skip the update of tsconfig.tns.json in shared Angular projects
2 parents 2b1bbf4 + 2ed9850 commit 7933f6e

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

Diff for: projectFilesManager.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const path = require("path");
22
const fs = require("fs");
33

4-
const { isTypeScript, isAngular, isVue } = require("./projectHelpers");
4+
const { isTypeScript, isAngular, isVue, isShared } = require("./projectHelpers");
55

66
function addProjectFiles(projectDir) {
77
const projectTemplates = getProjectTemplates(projectDir);
@@ -62,7 +62,11 @@ function getProjectTemplates(projectDir) {
6262

6363
let templates;
6464
if (isAngular({ projectDir })) {
65-
templates = getAngularTemplates(WEBPACK_CONFIG_NAME, TSCONFIG_TNS_NAME);
65+
if (isShared({ projectDir })) {
66+
templates = getSharedAngularTemplates(WEBPACK_CONFIG_NAME);
67+
} else {
68+
templates = getAngularTemplates(WEBPACK_CONFIG_NAME, TSCONFIG_TNS_NAME);
69+
}
6670
} else if (isVue({ projectDir })) {
6771
templates = getVueTemplates(WEBPACK_CONFIG_NAME);
6872
} else if (isTypeScript({ projectDir })) {
@@ -74,6 +78,12 @@ function getProjectTemplates(projectDir) {
7478
return getFullTemplatesPath(projectDir, templates);
7579
}
7680

81+
function getSharedAngularTemplates(webpackConfigName) {
82+
return {
83+
"webpack.angular.js": webpackConfigName,
84+
};
85+
}
86+
7787
function getAngularTemplates(webpackConfigName, tsconfigName) {
7888
return {
7989
"webpack.angular.js": webpackConfigName,

Diff for: projectHelpers.js

+23-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ const isTypeScript = ({ projectDir, packageJson } = {}) => {
1717
) || isAngular({ packageJson });
1818
};
1919

20+
const isShared = ({ projectDir }) => {
21+
const nsConfig = getNsConfig(projectDir);
22+
return nsConfig && !!nsConfig.shared;
23+
}
24+
2025
const isAngular = ({ projectDir, packageJson } = {}) => {
2126
packageJson = packageJson || getPackageJson(projectDir);
2227

@@ -39,9 +44,22 @@ const isVue = ({ projectDir, packageJson } = {}) => {
3944

4045
const getPackageJson = projectDir => {
4146
const packageJsonPath = getPackageJsonPath(projectDir);
47+
const result = readJsonFile(packageJsonPath);
48+
49+
return result;
50+
};
51+
52+
const getNsConfig = projectDir => {
53+
const nsConfigPath = getNsConfigPath(projectDir);
54+
const result = readJsonFile(nsConfigPath);
55+
56+
return result;
57+
};
58+
59+
const readJsonFile = filePath => {
4260
let result;
4361
try {
44-
result = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
62+
result = JSON.parse(fs.readFileSync(filePath, "utf8"));
4563
} catch (e) {
4664
result = {};
4765
}
@@ -69,6 +87,7 @@ const getIndentationCharacter = (jsonContent) => {
6987
const getProjectDir = hook.findProjectDir;
7088

7189
const getPackageJsonPath = projectDir => resolve(projectDir, "package.json");
90+
const getNsConfigPath = projectDir => resolve(projectDir, "nsconfig.json");
7291

7392
const isAndroid = platform => /android/i.test(platform);
7493
const isIos = platform => /ios/i.test(platform);
@@ -104,11 +123,13 @@ module.exports = {
104123
isAndroid,
105124
isIos,
106125
isAngular,
126+
isShared,
107127
getAngularVersion,
108128
isVue,
109129
isTypeScript,
110130
writePackageJson,
111131
convertSlashesInPath,
112132
getIndentationCharacter,
113133
safeGet,
114-
};
134+
};
135+

0 commit comments

Comments
 (0)