diff --git a/lib/constants.ts b/lib/constants.ts index 729d257ccf..7420893fab 100644 --- a/lib/constants.ts +++ b/lib/constants.ts @@ -67,6 +67,7 @@ export const BUNDLE_DIR = "bundle"; export const RESOURCES_DIR = "res"; export const CONFIG_NS_FILE_NAME = "nsconfig.json"; export const CONFIG_NS_APP_RESOURCES_ENTRY = "appResourcesPath"; +export const CONFIG_NS_BUILD_ENTRY = "buildPath"; export const CONFIG_NS_APP_ENTRY = "appPath"; export const CONFIG_FILE_NAME_DISPLAY = "nativescript.config.(js|ts)"; export const CONFIG_FILE_NAME_JS = "nativescript.config.js"; diff --git a/lib/contracts/project-data.ts b/lib/contracts/project-data.ts index aea166166e..976d8a0ec6 100644 --- a/lib/contracts/project-data.ts +++ b/lib/contracts/project-data.ts @@ -89,4 +89,6 @@ export abstract class ProjectData { abstract getAppResourcesDirectoryPath(projectDir?: string): string; abstract getAppResourcesRelativeDirectoryPath(): string; + + abstract getBuildRelativeDirectoryPath(): string; } diff --git a/lib/project-data.ts b/lib/project-data.ts index 277dbf32d1..2e9884a68b 100644 --- a/lib/project-data.ts +++ b/lib/project-data.ts @@ -282,6 +282,14 @@ export class ProjectData implements IProjectData { return this.resolveToProjectDir(appRelativePath, projectDir); } + public getBuildRelativeDirectoryPath(): string { + if (this.nsConfig && this.nsConfig[constants.CONFIG_NS_BUILD_ENTRY]) { + return this.nsConfig[constants.CONFIG_NS_BUILD_ENTRY]; + } + + return constants.PLATFORMS_DIR_NAME; + } + public getAppDirectoryRelativePath(): string { if (this.nsConfig && this.nsConfig[constants.CONFIG_NS_APP_ENTRY]) { return this.nsConfig[constants.CONFIG_NS_APP_ENTRY]; diff --git a/lib/services/bundler/bundler-compiler-service.ts b/lib/services/bundler/bundler-compiler-service.ts index fb3d345d81..1470a2e3ab 100644 --- a/lib/services/bundler/bundler-compiler-service.ts +++ b/lib/services/bundler/bundler-compiler-service.ts @@ -822,12 +822,14 @@ export class BundlerCompilerService const appId = projectData.projectIdentifiers[platform]; const appPath = projectData.getAppDirectoryRelativePath(); const appResourcesPath = projectData.getAppResourcesRelativeDirectoryPath(); + const buildPath = projectData.getBuildRelativeDirectoryPath(); Object.assign( envData, appId && { appId }, appPath && { appPath }, appResourcesPath && { appResourcesPath }, + buildPath && { buildPath }, { nativescriptLibPath: path.resolve( __dirname, @@ -1097,7 +1099,7 @@ export class BundlerCompilerService return path.resolve(packagePath, "bin", "vite.js"); } } else if (this.isModernBundler(projectData)) { - const packagePath = resolvePackagePath(`@nativescript/${bundler}`, { + const packagePath = resolvePackagePath(this.getBundlerPackageName(), { paths: [projectData.projectDir], }); @@ -1117,15 +1119,31 @@ export class BundlerCompilerService return path.resolve(packagePath, "bin", "webpack.js"); } + // Forks such as @akylas/nativescript-webpack replace the default package. + private getBundlerPackageName(): string { + const bundler = this.getBundler(); + if (bundler !== "webpack") { + return `@nativescript/${bundler}`; + } + + return this.$projectConfigService.getValue( + "webpackPackageName", + WEBPACK_PLUGIN_NAME, + ); + } + private isModernBundler(projectData: IProjectData): boolean { const bundler = this.getBundler(); switch (bundler) { case "rspack": return true; default: - const packageJSONPath = resolvePackageJSONPath(WEBPACK_PLUGIN_NAME, { - paths: [projectData.projectDir], - }); + const packageJSONPath = resolvePackageJSONPath( + this.getBundlerPackageName(), + { + paths: [projectData.projectDir], + }, + ); if (packageJSONPath) { const packageData = this.$fs.readJson(packageJSONPath); diff --git a/test/stubs.ts b/test/stubs.ts index 96bc5e2a33..9a945d659c 100644 --- a/test/stubs.ts +++ b/test/stubs.ts @@ -720,6 +720,10 @@ export class ProjectDataStub implements IProjectData { return ""; } + public getBuildRelativeDirectoryPath(): string { + return "platforms"; + } + public getAppDirectoryPath(projectDir?: string): string { if (!projectDir) { projectDir = this.projectDir;