Skip to content

Commit 95556c4

Browse files
committed
feat: allow custom vite dist folder name
Provides ability to run multiple platforms builds in parallel.
1 parent c0a2bad commit 95556c4

2 files changed

Lines changed: 46 additions & 4 deletions

File tree

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ export class BundlerCompilerService
7878
super();
7979
}
8080

81+
private getViteDistOutputPath(projectDir: string): string {
82+
return path.join(
83+
projectDir,
84+
process.env.NS_VITE_DIST_DIR || VITE_DIST_FOLDER_NAME,
85+
);
86+
}
87+
8188
public async compileWithWatch(
8289
platformData: IPlatformData,
8390
projectData: IProjectData,
@@ -127,9 +134,8 @@ export class BundlerCompilerService
127134
}
128135

129136
// Copy Vite output files directly to platform destination
130-
const distOutput = path.join(
137+
const distOutput = this.getViteDistOutputPath(
131138
projectData.projectDir,
132-
VITE_DIST_FOLDER_NAME,
133139
);
134140
const destDir = path.join(
135141
platformData.appDestinationDirectoryPath,
@@ -395,9 +401,8 @@ export class BundlerCompilerService
395401
// launch with `Check failed: has_pending_exception()`.
396402
if (isVite) {
397403
try {
398-
const distOutput = path.join(
404+
const distOutput = this.getViteDistOutputPath(
399405
projectData.projectDir,
400-
VITE_DIST_FOLDER_NAME,
401406
);
402407
const destDir = path.join(
403408
platformData.appDestinationDirectoryPath,

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Yok } from "../../../lib/common/yok";
22
import { BundlerCompilerService } from "../../../lib/services/bundler/bundler-compiler-service";
33
import { assert } from "chai";
44
import { EventEmitter } from "events";
5+
import * as path from "path";
56
import { ErrorsStub } from "../../stubs";
67
import { IInjector } from "../../../lib/common/definitions/yok";
78
import {
@@ -215,6 +216,42 @@ describe("BundlerCompilerService", () => {
215216
});
216217
});
217218

219+
describe("getViteDistOutputPath", () => {
220+
it("uses the current default directory when NS_VITE_DIST_DIR is unset", () => {
221+
const previous = process.env.NS_VITE_DIST_DIR;
222+
try {
223+
delete process.env.NS_VITE_DIST_DIR;
224+
assert.strictEqual(
225+
(<any>bundlerCompilerService).getViteDistOutputPath("/project"),
226+
path.join("/project", ".ns-vite-build"),
227+
);
228+
} finally {
229+
if (previous === undefined) {
230+
delete process.env.NS_VITE_DIST_DIR;
231+
} else {
232+
process.env.NS_VITE_DIST_DIR = previous;
233+
}
234+
}
235+
});
236+
237+
it("uses NS_VITE_DIST_DIR for platform-isolated output", () => {
238+
const previous = process.env.NS_VITE_DIST_DIR;
239+
try {
240+
process.env.NS_VITE_DIST_DIR = ".ns-vite-build/android";
241+
assert.strictEqual(
242+
(<any>bundlerCompilerService).getViteDistOutputPath("/project"),
243+
path.join("/project", ".ns-vite-build", "android"),
244+
);
245+
} finally {
246+
if (previous === undefined) {
247+
delete process.env.NS_VITE_DIST_DIR;
248+
} else {
249+
process.env.NS_VITE_DIST_DIR = previous;
250+
}
251+
}
252+
});
253+
});
254+
218255
describe("compileWithWatch", () => {
219256
it("fails when the value set for bundlerConfigPath is not existant file", async () => {
220257
const bundlerConfigPath = "some path.js";

0 commit comments

Comments
 (0)