Skip to content

Commit a4f4dd5

Browse files
authored
fix(tools): dev-server for 3rd party packages (#12631)
If a third-party package includes a Vite configuration file in its `config` folder, the configuration path was not being passed correctly because `process.argv` did not contain the necessary information. This PR fixes the issue by ensuring that environment variables are always treated as strings, since in some cases they were being passed in their original (non-string) types.
1 parent 72216c3 commit a4f4dd5

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

packages/tools/bin/ui5nps.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,11 @@ class Parser {
140140
process.exit(1);
141141
}
142142

143-
envs = scripts.__ui5envs;
143+
envs = JSON.parse(JSON.stringify(scripts.__ui5envs || {}));
144+
145+
Object.entries(envs).forEach(([key, value]) => {
146+
envs[key] = String(value);
147+
});
144148

145149
// Package-script should provide default export with scripts object
146150
if (envs && typeof envs !== "object") {

packages/tools/lib/dev-server/dev-server.mjs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,9 @@ import yargs from 'yargs';
44
import { hideBin } from 'yargs/helpers';
55
import { pathToFileURL } from "url";
66

7-
const argv = yargs(hideBin(process.argv))
8-
.alias("c", "config")
9-
.argv;
10-
11-
const startVite = async (port) => {
7+
const startVite = async (config, port) => {
128
const server = await createServer({
13-
configFile: argv.config,
9+
configFile: config,
1410
server: {
1511
port: port,
1612
strictPort: true,
@@ -37,15 +33,19 @@ const rmPortFile = async () => {
3733
process.on(eventType, rmPortFile);
3834
});
3935

40-
async function start() {
36+
async function start(outArgv) {
37+
const argv = yargs(hideBin(outArgv))
38+
.alias("c", "config")
39+
.argv;
40+
4141
let retries = 10;
4242
let port = 8080;
4343
while (retries--) {
4444
console.log(`taking port ${port}`);
4545
await fs.writeFile(".dev-server-port", `${port}`);
4646
try {
4747
// execSync(command, {stdio: 'pipe'});
48-
const server = await startVite(port);
48+
const server = await startVite(argv.config ?? "", port);
4949
if (server) {
5050
// server started, don't try other ports
5151
break;

0 commit comments

Comments
 (0)