fix(core): make npm scope optional (#9966)

This commit is contained in:
Jason Jean 2022-04-22 18:05:43 -04:00 committed by GitHub
parent 30a3f93c0c
commit c3484c775e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 13 additions and 13 deletions

View File

@ -1,7 +1,7 @@
import { Component } from '@angular/core';
@Component({
selector: '<%= npmScope %>-<%= appName %>-entry',
selector: '<%= appName %>-entry',
template: `<div class="remote-entry"><h2><%= appName %>'s Remote Entry Component</h2></div>`,
styles: [`
.remote-entry {

View File

@ -12,7 +12,6 @@ export function addEntryModule(
appRoot: string
) {
if (mfeType === 'remote') {
const { npmScope } = readWorkspaceConfiguration(host);
generateFiles(
host,
joinPathFragments(__dirname, '../files/entry-module-files'),
@ -20,7 +19,6 @@ export function addEntryModule(
{
tmpl: '',
appName,
npmScope,
routing,
}
);

View File

@ -35,7 +35,7 @@ export interface NxJsonConfiguration<T = '*' | string[]> {
/**
* NPM Scope that the workspace uses
*/
npmScope: string;
npmScope?: string;
/**
* Default options for `nx affected`
*/

View File

@ -587,11 +587,13 @@ function buildProjectConfigurationFromPackageJson(
nxJson: NxJsonConfiguration
): ProjectConfiguration & { name: string } {
const directory = dirname(path).split('\\').join('/');
const npmPrefix = `@${nxJson.npmScope}/`;
let name = packageJson.name ?? toProjectName(directory, nxJson);
if (nxJson.npmScope) {
const npmPrefix = `@${nxJson.npmScope}/`;
if (name.startsWith(npmPrefix)) {
name = name.replace(npmPrefix, '');
}
}
return {
root: directory,
sourceRoot: directory,

View File

@ -490,7 +490,7 @@ class ProjectHasher {
res.projects ??= {};
return res;
} catch {
return { npmScope: '' };
return {};
}
}
}

View File

@ -38,7 +38,10 @@ function createPackageNameMap(w: Workspace) {
const packageJson = parseJson(
defaultFileRead(join(w.projects[projectName].root, 'package.json'))
);
res[packageJson.name || `@${w.npmScope}/${projectName}`] = projectName;
res[
packageJson.name ??
(w.npmScope ? `@${w.npmScope}/${projectName}` : projectName)
] = projectName;
} catch (e) {}
}
return res;

View File

@ -158,9 +158,6 @@ export function readNxJson(
path: string = `${workspaceRoot}/nx.json`
): NxJsonConfiguration {
let config = readJsonFile<NxJsonConfiguration>(path);
if (!config.npmScope) {
throw new Error(`nx.json must define the npmScope property.`);
}
if (config.extends) {
config = {