Skip to content
Open
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
13 changes: 11 additions & 2 deletions lib/definitions/project.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,15 @@ interface IProjectConfigInformation {
interface IProjectConfigService {
/**
* read the nativescript.config.(js|ts) file
* @param options.suppressWarnings pass when reading a config that is not
* the user's project (e.g. a plugin package, which may legitimately ship
* compiled .js artifacts next to its .ts config)
* @returns {INsConfig} the parsed config data
*/
readConfig(projectDir?: string): INsConfig;
readConfig(
projectDir?: string,
options?: { suppressWarnings?: boolean },
): INsConfig;
/**
* Get value for a given config key path
* @param key the property key path
Expand Down Expand Up @@ -479,7 +485,10 @@ interface IProjectConfigService {
*/
setForceUsingLegacyConfig(force: boolean): boolean;

detectProjectConfigs(projectDir?: string): IProjectConfigInformation;
detectProjectConfigs(
projectDir?: string,
options?: { suppressWarnings?: boolean },
): IProjectConfigInformation;

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

Expand Down
8 changes: 7 additions & 1 deletion lib/services/ios-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,13 @@ export class IOSProjectService
constants.CONFIG_FILE_NAME_TS,
);
if (this.$fs.exists(pluginConfigPath)) {
const config = this.$projectConfigService.readConfig(plugin.fullPath);
// Plugin packages may ship compiled .js artifacts next to their
// .ts config; the dual-config warning is guidance for the user's
// own project and would be misleading here.
const config = this.$projectConfigService.readConfig(
plugin.fullPath,
{ suppressWarnings: true },
);
const packages = _.get(
config,
`${platformData.platformNameLowerCase}.SPMPackages`,
Expand Down
18 changes: 13 additions & 5 deletions lib/services/project-config-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ export default {
);
}

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

if (hasTSConfig && hasJSConfig) {
if (hasTSConfig && hasJSConfig && !options?.suppressWarnings) {
this.$logger.warn(
`You have both a ${CONFIG_FILE_NAME_JS} and ${CONFIG_FILE_NAME_TS} file. Defaulting to ${CONFIG_FILE_NAME_TS}.`,
`You have both a ${CONFIG_FILE_NAME_JS} and ${CONFIG_FILE_NAME_TS} file in ${path.dirname(
TSConfigPath,
)}. Defaulting to ${CONFIG_FILE_NAME_TS}.`,
Comment on lines +160 to +164

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Report the detected configuration paths.

possibleConfigPaths can combine a custom --config or NATIVESCRIPT_CONFIG_NAME path with the default paths. Therefore, TSConfigPath and JSConfigPath are not guaranteed to have the same parent directory. This message can claim that both files are in path.dirname(TSConfigPath) when the JavaScript file is elsewhere. It also names the default files when custom names were detected.

Build the warning from JSConfigPath and TSConfigPath, or use the directory form only when both parent directories match.

Proposed fix
 			this.$logger.warn(
-				`You have both a ${CONFIG_FILE_NAME_JS} and ${CONFIG_FILE_NAME_TS} file in ${path.dirname(
-					TSConfigPath,
-				)}. Defaulting to ${CONFIG_FILE_NAME_TS}.`,
+				`You have both ${JSConfigPath} and ${TSConfigPath}. Defaulting to ${TSConfigPath}.`,
 			);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (hasTSConfig && hasJSConfig && !options?.suppressWarnings) {
this.$logger.warn(
`You have both a ${CONFIG_FILE_NAME_JS} and ${CONFIG_FILE_NAME_TS} file. Defaulting to ${CONFIG_FILE_NAME_TS}.`,
`You have both a ${CONFIG_FILE_NAME_JS} and ${CONFIG_FILE_NAME_TS} file in ${path.dirname(
TSConfigPath,
)}. Defaulting to ${CONFIG_FILE_NAME_TS}.`,
if (hasTSConfig && hasJSConfig && !options?.suppressWarnings) {
this.$logger.warn(
`You have both ${JSConfigPath} and ${TSConfigPath}. Defaulting to ${TSConfigPath}.`,
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/services/project-config-service.ts` around lines 160 - 164, Update the
warning in the configuration-detection branch of the project config service to
report the actual detected JSConfigPath and TSConfigPath values, rather than
hardcoded default names and only TSConfigPath’s directory. Preserve the
warning’s statement that TypeScript configuration is selected, and ensure any
directory-based wording is used only when both paths share the same parent
directory.

);
}

Expand All @@ -172,8 +177,11 @@ export default {
}

@exported("projectConfigService")
public readConfig(projectDir?: string): INsConfig {
const info = this.detectProjectConfigs(projectDir);
public readConfig(
projectDir?: string,
options?: { suppressWarnings?: boolean },
): INsConfig {
const info = this.detectProjectConfigs(projectDir, options);

if (
this.forceUsingLegacyConfig ||
Expand Down