Skip to content

Commit 5fa07dc

Browse files
authored
fix: misleading dual nativescript.config warning when reading plugin configs (#6122)
1 parent 9737223 commit 5fa07dc

3 files changed

Lines changed: 31 additions & 8 deletions

File tree

lib/definitions/project.d.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,15 @@ interface IProjectConfigInformation {
448448
interface IProjectConfigService {
449449
/**
450450
* read the nativescript.config.(js|ts) file
451+
* @param options.suppressWarnings pass when reading a config that is not
452+
* the user's project (e.g. a plugin package, which may legitimately ship
453+
* compiled .js artifacts next to its .ts config)
451454
* @returns {INsConfig} the parsed config data
452455
*/
453-
readConfig(projectDir?: string): INsConfig;
456+
readConfig(
457+
projectDir?: string,
458+
options?: { suppressWarnings?: boolean },
459+
): INsConfig;
454460
/**
455461
* Get value for a given config key path
456462
* @param key the property key path
@@ -479,7 +485,10 @@ interface IProjectConfigService {
479485
*/
480486
setForceUsingLegacyConfig(force: boolean): boolean;
481487

482-
detectProjectConfigs(projectDir?: string): IProjectConfigInformation;
488+
detectProjectConfigs(
489+
projectDir?: string,
490+
options?: { suppressWarnings?: boolean },
491+
): IProjectConfigInformation;
483492

484493
getDefaultTSConfig(appId: string, appPath: string): string;
485494

lib/services/ios-project-service.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1329,7 +1329,13 @@ export class IOSProjectService
13291329
constants.CONFIG_FILE_NAME_TS,
13301330
);
13311331
if (this.$fs.exists(pluginConfigPath)) {
1332-
const config = this.$projectConfigService.readConfig(plugin.fullPath);
1332+
// Plugin packages may ship compiled .js artifacts next to their
1333+
// .ts config; the dual-config warning is guidance for the user's
1334+
// own project and would be misleading here.
1335+
const config = this.$projectConfigService.readConfig(
1336+
plugin.fullPath,
1337+
{ suppressWarnings: true },
1338+
);
13331339
const packages = _.get(
13341340
config,
13351341
`${platformData.platformNameLowerCase}.SPMPackages`,

lib/services/project-config-service.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ export default {
9191
);
9292
}
9393

94-
public detectProjectConfigs(projectDir?: string): IProjectConfigInformation {
94+
public detectProjectConfigs(
95+
projectDir?: string,
96+
options?: { suppressWarnings?: boolean },
97+
): IProjectConfigInformation {
9598
// allow overriding config name with env variable or --config (or -c)
9699
let configName: string | boolean =
97100
process.env.NATIVESCRIPT_CONFIG_NAME ?? this.$options.config;
@@ -154,9 +157,11 @@ export default {
154157
const hasNSConfig = !!NSConfigPath && hasExistingConfig;
155158
const usingNSConfig = !(hasTSConfig || hasJSConfig);
156159

157-
if (hasTSConfig && hasJSConfig) {
160+
if (hasTSConfig && hasJSConfig && !options?.suppressWarnings) {
158161
this.$logger.warn(
159-
`You have both a ${CONFIG_FILE_NAME_JS} and ${CONFIG_FILE_NAME_TS} file. Defaulting to ${CONFIG_FILE_NAME_TS}.`,
162+
`You have both a ${CONFIG_FILE_NAME_JS} and ${CONFIG_FILE_NAME_TS} file in ${path.dirname(
163+
TSConfigPath,
164+
)}. Defaulting to ${CONFIG_FILE_NAME_TS}.`,
160165
);
161166
}
162167

@@ -172,8 +177,11 @@ export default {
172177
}
173178

174179
@exported("projectConfigService")
175-
public readConfig(projectDir?: string): INsConfig {
176-
const info = this.detectProjectConfigs(projectDir);
180+
public readConfig(
181+
projectDir?: string,
182+
options?: { suppressWarnings?: boolean },
183+
): INsConfig {
184+
const info = this.detectProjectConfigs(projectDir, options);
177185

178186
if (
179187
this.forceUsingLegacyConfig ||

0 commit comments

Comments
 (0)