Skip to content

Commit

Permalink
SDK-317: Mitigating Module not found error when building the frontend
Browse files Browse the repository at this point in the history
Created an option to add legacy-peer-deps argument to npm commands.

jira ticket: https://issues.openmrs.org/browse/SDK-317
  • Loading branch information
wikumChamith committed Jul 11, 2023
1 parent 2a0dca2 commit 3b6ab5e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ public class Setup extends AbstractServerTask {
@Parameter(property = "appShellVersion")
private String appShellVersion;

@Parameter(property = "ignorePeerDependencies", defaultValue = "false")
private boolean ignorePeerDependencies;

private ServerHelper serverHelper;

public Setup() {
Expand Down Expand Up @@ -285,7 +288,7 @@ public void setup(Server server, DistroProperties distroProperties) throws MojoE
moduleInstaller.installModulesForDistro(server, distroProperties, distroHelper);
setConfigFolder(server, distroProperties);
if (spaInstaller != null) {
spaInstaller.installFromDistroProperties(server.getServerDirectory(), distroProperties);
spaInstaller.installFromDistroProperties(server.getServerDirectory(), distroProperties, ignorePeerDependencies);
}
installOWAs(server, distroProperties);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,27 @@ public void installNodeAndNpm(String nodeVersion, String npmVersion) throws Mojo
}

public void runNpx(String arguments) throws MojoExecutionException {
String npmExec = "exec -- " + arguments;

runNpx(arguments, "");
}

public void runNpx(String arguments, String legacyPeerDeps) throws MojoExecutionException {
String npmExec = legacyPeerDeps + " exec -- " + arguments;

// it's a little weird to use a custom NPM cache for this; however, it seems to be necessary to get things working on Bamboo
// hack added in December 2021; it's use probably should be re-evaluated at some point
// additional hack: we do not use --cache on macs due to https://github.com/npm/cli/issues/3256
if (mavenProject != null && mavenProject.getBuild() != null && !SystemUtils.IS_OS_MAC_OSX) {
npmExec =
" --cache=" + tempDir.resolve("npm-cache").toAbsolutePath() + " exec -- " + arguments;
legacyPeerDeps + " --cache=" + tempDir.resolve("npm-cache").toAbsolutePath() + " exec -- " + arguments;
}

List<MojoExecutor.Element> configuration = new ArrayList<>(3);
configuration.add(element("arguments", npmExec));

if (mavenProject != null && mavenProject.getBuild() != null) {
configuration.add(element("installDirectory", tempDir.toAbsolutePath().toString()));
}

runFrontendMavenPlugin("npm", configuration);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ public SpaInstaller(DistroHelper distroHelper,
public void installFromDistroProperties(File appDataDir, DistroProperties distroProperties)
throws MojoExecutionException {

installFromDistroProperties(appDataDir, distroProperties, false);
}

public void installFromDistroProperties(File appDataDir, DistroProperties distroProperties, boolean ignorePeerDependencies)
throws MojoExecutionException {

// We find all the lines in distro properties beginning with `spa` and convert these
// into a JSON structure. This is passed to the frontend build tool.
// If no SPA elements are present in the distro properties, the SPA is not installed.
Expand Down Expand Up @@ -74,14 +80,15 @@ public void installFromDistroProperties(File appDataDir, DistroProperties distro

nodeHelper.installNodeAndNpm(nodeVersion, npmVersion);
File buildTargetDir = new File(appDataDir, BUILD_TARGET_DIR);

String program = "openmrs@" + coreVersion;
String legacyPeerDeps = ignorePeerDependencies ? "--legacy-peer-deps" : "";
// print frontend tool version number
nodeHelper.runNpx(String.format("%s --version", program));
nodeHelper.runNpx(String.format("%s --version", program), legacyPeerDeps);
nodeHelper.runNpx(
String.format("%s build --target %s --build-config %s", program, buildTargetDir, spaConfigFile));
String.format("%s build --target %s --build-config %s", program, buildTargetDir, spaConfigFile), legacyPeerDeps);
nodeHelper.runNpx(
String.format("%s assemble --target %s --mode config --config %s", program, buildTargetDir, spaConfigFile));
String.format("%s assemble --target %s --mode config --config %s", program, buildTargetDir, spaConfigFile), legacyPeerDeps);
}
}

Expand Down

0 comments on commit 3b6ab5e

Please sign in to comment.