Skip to content

Commit 6aee3b1

Browse files
alan-agius4dgp1130
authored andcommitted
fix(@angular/cli): fix package manager warnings when running temporary install
Related to: #16205 (cherry picked from commit 08f0067)
1 parent 85a017b commit 6aee3b1

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

packages/angular/cli/tasks/install-package.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import { logging } from '@angular-devkit/core';
1010
import { spawnSync } from 'child_process';
11-
import { existsSync, mkdtempSync, readFileSync, realpathSync } from 'fs';
11+
import { existsSync, mkdtempSync, readFileSync, realpathSync, writeFileSync } from 'fs';
1212
import { tmpdir } from 'os';
1313
import { join, resolve } from 'path';
1414
import * as rimraf from 'rimraf';
@@ -78,6 +78,22 @@ export function installTempPackage(
7878
} catch {}
7979
});
8080

81+
// NPM will warn when a `package.json` is not found in the install directory
82+
// Example:
83+
// npm WARN enoent ENOENT: no such file or directory, open '/tmp/.ng-temp-packages-84Qi7y/package.json'
84+
// npm WARN .ng-temp-packages-84Qi7y No description
85+
// npm WARN .ng-temp-packages-84Qi7y No repository field.
86+
// npm WARN .ng-temp-packages-84Qi7y No license field.
87+
88+
// While we can use `npm init -y` we will end up needing to update the 'package.json' anyways
89+
// because of missing fields.
90+
writeFileSync(join(tempPath, 'package.json'), JSON.stringify({
91+
name: 'temp-cli-install',
92+
description: 'temp-cli-install',
93+
repository: 'temp-cli-install',
94+
license: 'MIT',
95+
}));
96+
8197
// setup prefix/global modules path
8298
const packageManagerArgs = getPackageManagerArguments(packageManager);
8399
const tempNodeModules = join(tempPath, 'node_modules');

0 commit comments

Comments
 (0)