Skip to content

Commit 9e0e8b5

Browse files
committed
fix: utility for npmScope
1 parent f84890c commit 9e0e8b5

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

packages/nx/src/utils/general.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Tree, serializeJson, readJson } from '@nx/devkit';
1+
import { Tree, serializeJson, readJson, readNxJson } from '@nx/devkit';
22
import { stringUtils as nxStringUtils } from '@nx/workspace';
33

44
export interface IPluginSettings {
@@ -33,8 +33,26 @@ let frontendFramework: FrameworkTypes;
3333
let groupByName = false;
3434
let usingXplatWorkspace = false;
3535

36-
export function getNpmScope() {
37-
return npmScope;
36+
export function getNpmScope(tree?: Tree) {
37+
if (npmScope) {
38+
return npmScope;
39+
}
40+
const nxJson = readNxJson(tree);
41+
42+
// TODO(v17): Remove reading this from nx.json
43+
if (nxJson.npmScope) {
44+
npmScope = nxJson.npmScope;
45+
return npmScope;
46+
}
47+
48+
const { name } = tree.exists('package.json')
49+
? readJson<{ name?: string }>(tree, 'package.json')
50+
: { name: null };
51+
52+
if (name?.startsWith('@')) {
53+
npmScope = name.split('/')[0].substring(1);
54+
return npmScope;
55+
}
3856
}
3957

4058
export function getPrefix() {

0 commit comments

Comments
 (0)