Browse Source

fix(ui-devkit): Fix baseHref setting when using npm

Fixes #916, #993
Michael Bromley 4 years ago
parent
commit
511c2ed82b
1 changed files with 12 additions and 10 deletions
  1. 12 10
      packages/ui-devkit/src/compiler/compile.ts

+ 12 - 10
packages/ui-devkit/src/compiler/compile.ts

@@ -40,21 +40,23 @@ export function compileUiExtensions(
 }
 }
 
 
 function runCompileMode(outputPath: string, baseHref: string, extensions: Extension[]): AdminUiAppConfig {
 function runCompileMode(outputPath: string, baseHref: string, extensions: Extension[]): AdminUiAppConfig {
-    const cmd = shouldUseYarn() ? 'yarn' : 'npm';
+    const usingYarn = shouldUseYarn();
+    const cmd = usingYarn ? 'yarn' : 'npm';
     const distPath = path.join(outputPath, 'dist');
     const distPath = path.join(outputPath, 'dist');
 
 
     const compile = () =>
     const compile = () =>
         new Promise<void>(async (resolve, reject) => {
         new Promise<void>(async (resolve, reject) => {
             await setupScaffold(outputPath, extensions);
             await setupScaffold(outputPath, extensions);
-            const buildProcess = spawn(
-                cmd,
-                ['run', 'build', `--outputPath=${distPath}`, `--base-href=${baseHref}`],
-                {
-                    cwd: outputPath,
-                    shell: true,
-                    stdio: 'inherit',
-                },
-            );
+            const commandArgs = ['run', 'build', `--outputPath=${distPath}`, `--base-href=${baseHref}`];
+            if (!usingYarn) {
+                // npm requires `--` before any command line args being passed to a script
+                commandArgs.splice(2, 0, '--');
+            }
+            const buildProcess = spawn(cmd, commandArgs, {
+                cwd: outputPath,
+                shell: true,
+                stdio: 'inherit',
+            });
 
 
             buildProcess.on('close', code => {
             buildProcess.on('close', code => {
                 if (code !== 0) {
                 if (code !== 0) {