Skip to content
Merged
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
1 change: 1 addition & 0 deletions lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 2 additions & 0 deletions lib/contracts/project-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,6 @@ export abstract class ProjectData {
abstract getAppResourcesDirectoryPath(projectDir?: string): string;

abstract getAppResourcesRelativeDirectoryPath(): string;

abstract getBuildRelativeDirectoryPath(): string;
}
8 changes: 8 additions & 0 deletions lib/project-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
26 changes: 22 additions & 4 deletions lib/services/bundler/bundler-compiler-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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],
});

Expand All @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions test/stubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down