Skip to content

Commit 6781fd5

Browse files
farfromrefugclaude
andcommitted
fix(bundler): resolve the configured bundler package and pass buildPath
Projects overriding `webpackPackageName` (such as @akylas/nativescript-webpack) fell back to raw webpack/bin/webpack.js, which rejects the `--env.x` flags the CLI emits. Resolve the configured package so the modern bin is used instead. Restore `buildPath` in the bundler env. Without it the bundle is written outside the platform folder and the run never completes. Flag catalyst from the requested platform, since platform data reports iOS. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent e62ca02 commit 6781fd5

5 files changed

Lines changed: 44 additions & 7 deletions

File tree

lib/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export const BUNDLE_DIR = "bundle";
6666
export const RESOURCES_DIR = "res";
6767
export const CONFIG_NS_FILE_NAME = "nsconfig.json";
6868
export const CONFIG_NS_APP_RESOURCES_ENTRY = "appResourcesPath";
69+
export const CONFIG_NS_BUILD_ENTRY = "buildPath";
6970
export const CONFIG_NS_APP_ENTRY = "appPath";
7071
export const CONFIG_FILE_NAME_DISPLAY = "nativescript.config.(js|ts)";
7172
export const CONFIG_FILE_NAME_JS = "nativescript.config.js";

lib/contracts/project-data.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,6 @@ export abstract class ProjectData {
8989
abstract getAppResourcesDirectoryPath(projectDir?: string): string;
9090

9191
abstract getAppResourcesRelativeDirectoryPath(): string;
92+
93+
abstract getBuildRelativeDirectoryPath(): string;
9294
}

lib/project-data.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,14 @@ export class ProjectData implements IProjectData {
282282
return this.resolveToProjectDir(appRelativePath, projectDir);
283283
}
284284

285+
public getBuildRelativeDirectoryPath(): string {
286+
if (this.nsConfig && this.nsConfig[constants.CONFIG_NS_BUILD_ENTRY]) {
287+
return this.nsConfig[constants.CONFIG_NS_BUILD_ENTRY];
288+
}
289+
290+
return constants.PLATFORMS_DIR_NAME;
291+
}
292+
285293
public getAppDirectoryRelativePath(): string {
286294
if (this.nsConfig && this.nsConfig[constants.CONFIG_NS_APP_ENTRY]) {
287295
return this.nsConfig[constants.CONFIG_NS_APP_ENTRY];

lib/services/bundler/bundler-compiler-service.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -789,20 +789,22 @@ export class BundlerCompilerService
789789
const platformKey = platform.toLowerCase();
790790
const envData = Object.assign({}, env, { [platformKey]: true });
791791

792-
// Bundlers only know the base platforms, so Catalyst also flags ios.
793-
if (this.$mobileHelper.isCatalystPlatform(platformKey)) {
794-
envData[PlatformTypes.ios] = true;
792+
// Platform data reports iOS, so the flag comes from the request.
793+
if (this.$mobileHelper.isCatalystPlatform(prepareData.platform)) {
794+
envData[PlatformTypes.catalyst] = true;
795795
}
796796

797797
const appId = projectData.projectIdentifiers[platform];
798798
const appPath = projectData.getAppDirectoryRelativePath();
799799
const appResourcesPath = projectData.getAppResourcesRelativeDirectoryPath();
800+
const buildPath = projectData.getBuildRelativeDirectoryPath();
800801

801802
Object.assign(
802803
envData,
803804
appId && { appId },
804805
appPath && { appPath },
805806
appResourcesPath && { appResourcesPath },
807+
buildPath && { buildPath },
806808
{
807809
nativescriptLibPath: path.resolve(
808810
__dirname,
@@ -1072,7 +1074,7 @@ export class BundlerCompilerService
10721074
return path.resolve(packagePath, "bin", "vite.js");
10731075
}
10741076
} else if (this.isModernBundler(projectData)) {
1075-
const packagePath = resolvePackagePath(`@nativescript/${bundler}`, {
1077+
const packagePath = resolvePackagePath(this.getBundlerPackageName(), {
10761078
paths: [projectData.projectDir],
10771079
});
10781080

@@ -1092,15 +1094,31 @@ export class BundlerCompilerService
10921094
return path.resolve(packagePath, "bin", "webpack.js");
10931095
}
10941096

1097+
// Forks such as @akylas/nativescript-webpack replace the default package.
1098+
private getBundlerPackageName(): string {
1099+
const bundler = this.getBundler();
1100+
if (bundler !== "webpack") {
1101+
return `@nativescript/${bundler}`;
1102+
}
1103+
1104+
return this.$projectConfigService.getValue(
1105+
"webpackPackageName",
1106+
WEBPACK_PLUGIN_NAME,
1107+
);
1108+
}
1109+
10951110
private isModernBundler(projectData: IProjectData): boolean {
10961111
const bundler = this.getBundler();
10971112
switch (bundler) {
10981113
case "rspack":
10991114
return true;
11001115
default:
1101-
const packageJSONPath = resolvePackageJSONPath(WEBPACK_PLUGIN_NAME, {
1102-
paths: [projectData.projectDir],
1103-
});
1116+
const packageJSONPath = resolvePackageJSONPath(
1117+
this.getBundlerPackageName(),
1118+
{
1119+
paths: [projectData.projectDir],
1120+
},
1121+
);
11041122

11051123
if (packageJSONPath) {
11061124
const packageData = this.$fs.readJson(packageJSONPath);

test/stubs.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,14 @@ export class ProjectDataStub implements IProjectData {
720720
return "";
721721
}
722722

723+
public getBuildRelativeDirectoryPath(): string {
724+
return "platforms";
725+
}
726+
727+
public getIgnoredDependencies(platform?: string): string[] {
728+
return [];
729+
}
730+
723731
public getAppDirectoryPath(projectDir?: string): string {
724732
if (!projectDir) {
725733
projectDir = this.projectDir;

0 commit comments

Comments
 (0)