Skip to content

Commit

Permalink
Add --legacy-peer-deps option
Browse files Browse the repository at this point in the history
  • Loading branch information
ehelms committed Jun 6, 2024
1 parent 8403c0b commit f3c3caf
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
9 changes: 8 additions & 1 deletion bin/generate_npm_tarball.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

set -x

if [ $# -lt 2 ]; then
echo "usage: $0 PACKAGE[@VERSION] OUTPUT.TGZ [USE NODEJS 6] [SPECFILE_FOR_PURGE]"
exit 1
Expand All @@ -8,6 +10,7 @@ package=$1
output=$(pwd)/$2
usenodejs6=${3:-false}
specfile="$4"
legacypeerdeps=${5:-false}
wd=$(mktemp -d)
trap "rm -rf '$wd'" EXIT INT TERM

Expand All @@ -29,7 +32,11 @@ create_cache() {

(cd $wd/cache && find -type f | sort) > $wd/cache-primed

npm install --cache $wd/cache $package --no-shrinkwrap --no-optional --production --verbose
if [[ $legacypeerdeps == true ]];then
npm install --legacy-peer-deps --cache $wd/cache $package --no-shrinkwrap --no-optional --production --verbose
else
npm install --cache $wd/cache $package --no-shrinkwrap --no-optional --production --verbose
fi

(cd $wd/cache && find -type f | sort) > $wd/cache-full

Expand Down
19 changes: 12 additions & 7 deletions bin/npm2rpm.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ npm2rpm
.option('-6, --use-nodejs6 [useNodejs6]', "If wanting to generate cache tarball for NodeJS 6")
.option('-o, --output [directory]', "Directory to output files to")
.option('-c, --scl [scl]', "Adds scl prefixes to spec file")
.option('-p, --use-legacy-peer-deps [useLegacyPeerDeps]', "Adds --legacy-peer-deps during npm install")
.parse(process.argv);

// If a name is not provided, then npm2rpm.name defaults to calling 'commander' name() function
Expand Down Expand Up @@ -55,6 +56,10 @@ if (npm2rpm.scl === undefined) {
npm2rpm.scl = false;
}

if (npm2rpm.useLegacyPeerDeps === undefined) {
npm2rpm.useLegacyPeerDeps = false;
}

const url = npmUrl(npm2rpm.name, npm2rpm.version);
console.log(' - Starting npm module download: '.bold + url );
const tmpDir = createTempDir();
Expand Down Expand Up @@ -90,30 +95,30 @@ tar_stream.on('finish', () => {
// Dependencies come as name@version but sometimes as @name@version
const dependencies = deps.map(dependency => rsplit(dependency, '@'));

specfile = writeSpecFile(npm_module, files, dependencies, npm2rpm.release, npm2rpm.template, npm2rpm.output, npm2rpm.scl);
specfile = writeSpecFile(npm_module, files, dependencies, npm2rpm.release, npm2rpm.template, npm2rpm.output, npm2rpm.scl, npm2rpm.useLegacyPeerDeps);

if (dependencies.length > 0) {
console.log(' - Generating npm cache tgz... '.bold)
createNpmCacheTar(npm_module, npm2rpm.output, npm2rpm.useNodejs6, specfile);
createNpmCacheTar(npm_module, npm2rpm.output, npm2rpm.useNodejs6, specfile, npm2rpm.useLegacyPeerDeps);
}
});
} else {
writeSpecFile(npm_module, files, [], npm2rpm.release, npm2rpm.template, npm2rpm.output, npm2rpm.scl);
writeSpecFile(npm_module, files, [], npm2rpm.release, npm2rpm.template, npm2rpm.output, npm2rpm.scl, npm2rpm.useLegacyPeerDeps);
}
})

function writeSpecFile(npmModule, files, dependencies, release, template, specDir, scl) {
const content = specFileGenerator(npmModule, files, dependencies, release, template, scl);
function writeSpecFile(npmModule, files, dependencies, release, template, specDir, scl, use_legacy_peer_deps) {
const content = specFileGenerator(npmModule, files, dependencies, release, template, scl, use_legacy_peer_deps);
const filename = path.join(specDir, `${getRpmPackageName(npmModule.name)}.spec`);
fs.writeFileSync(filename, content);
return filename;
}

function createNpmCacheTar(npm_module, outputDir, useNodejs6, specfile) {
function createNpmCacheTar(npm_module, outputDir, useNodejs6, specfile, useLegacyPeerDeps) {
const command = path.join(__dirname, 'generate_npm_tarball.sh');
const pkg = `${npm_module.name}@${npm_module.version}`;
const filename = path.join(outputDir, getCacheFilename(getRpmPackageName(npm_module.name), npm_module.version));
execSync([command, pkg, filename, useNodejs6, specfile].join(' '), {stdio: [0,1,2]});
execSync([command, pkg, filename, useNodejs6, specfile, useLegacyPeerDeps].join(' '), {stdio: [0,1,2]});
}

function createTempDir() {
Expand Down
2 changes: 1 addition & 1 deletion bundle.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ done

%build
%{?scl:scl enable %{?scl_nodejs} - << \end_of_scl}
npm install --cache-min Infinity --cache %{?scl:../}%{npm_cache_dir} --no-shrinkwrap --no-optional --global-style true %{npm_name}@%{version}
npm install {{{LEGACY_PEER_DEPS}}}--cache-min Infinity --cache %{?scl:../}%{npm_cache_dir} --no-shrinkwrap --no-optional --global-style true %{npm_name}@%{version}
%{?scl:end_of_scl}

%install
Expand Down
13 changes: 11 additions & 2 deletions lib/spec_file_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,15 @@ function getLicense(npm_module) {
}
}

function generateSpecFile(npm_module, files, dependencies, release, template_name, scl) {
function getLegacyPeerDeps(use_legacy_peer_deps) {
if (use_legacy_peer_deps) {
return '--legacy-peer-deps ';
} else {
return '';
}
}

function generateSpecFile(npm_module, files, dependencies, release, template_name, scl, use_legacy_peer_deps) {
for (binary in npm_module.bin) {
npm_module.bin[binary] = npm_module.bin[binary].replace(/^\.\//, '');
}
Expand All @@ -169,7 +177,8 @@ function generateSpecFile(npm_module, files, dependencies, release, template_nam
DESCRIPTION: npm_module.description,
BINARIES: npm_module.bin,
COPYFILES: getCopyFiles(files),
DOCFILES: getDocFiles(files)
DOCFILES: getDocFiles(files),
LEGACY_PEER_DEPS: getLegacyPeerDeps(use_legacy_peer_deps),
}

if (dependencies.length !== 0) {
Expand Down

0 comments on commit f3c3caf

Please sign in to comment.