-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New option to install packages (#574)
* added new option to install packages * fix lint * review Co-authored-by: Victor Berchet <victor@suumit.com> * changeset & lint fix --------- Co-authored-by: Victor Berchet <victor@suumit.com>
- Loading branch information
Showing
9 changed files
with
119 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@opennextjs/aws": minor | ||
--- | ||
|
||
Add a new option to install native dependencies on every lambda |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import fs from "node:fs"; | ||
import os from "node:os"; | ||
import path from "node:path"; | ||
|
||
import { execSync } from "child_process"; | ||
import { InstallOptions } from "types/open-next"; | ||
|
||
import logger from "../logger.js"; | ||
|
||
export function installDependencies( | ||
outputDir: string, | ||
installOptions?: InstallOptions, | ||
) { | ||
try { | ||
if (!installOptions) { | ||
return; | ||
} | ||
const name = outputDir.split("/").pop(); | ||
// First we create a tempDir | ||
const tempInstallDir = fs.mkdtempSync( | ||
path.join(os.tmpdir(), `open-next-install-${name}`), | ||
); | ||
logger.info(`Installing dependencies for ${name}...`); | ||
// We then need to run install in the tempDir | ||
// We don't install in the output dir directly because it could contain a package.json, and npm would then try to reinstall not complete deps from tracing the files | ||
const installCommand = `npm install --arch=${ | ||
installOptions.arch ?? "arm64" | ||
} --platform=linux --target=${installOptions.nodeVersion ?? "18"} --libc=${ | ||
installOptions.libc ?? "glibc" | ||
} ${installOptions.packages.join(" ")}`; | ||
execSync(installCommand, { | ||
stdio: "pipe", | ||
cwd: tempInstallDir, | ||
env: { | ||
...process.env, | ||
SHARP_IGNORE_GLOBAL_LIBVIPS: "1", | ||
}, | ||
}); | ||
|
||
// Copy the node_modules to the outputDir | ||
fs.cpSync( | ||
path.join(tempInstallDir, "node_modules"), | ||
path.join(outputDir, "node_modules"), | ||
|
||
{ recursive: true, force: true, dereference: true }, | ||
); | ||
|
||
// Cleanup tempDir | ||
fs.rmSync(tempInstallDir, { recursive: true, force: true }); | ||
logger.info(`Dependencies installed for ${name}`); | ||
} catch (e: any) { | ||
logger.error(e.stdout.toString()); | ||
logger.error("Could not install dependencies"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters