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

View File

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

View File

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

View File

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

View File

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

View File

@ -38,7 +38,10 @@ function createPackageNameMap(w: Workspace) {
const packageJson = parseJson( const packageJson = parseJson(
defaultFileRead(join(w.projects[projectName].root, 'package.json')) 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) {} } catch (e) {}
} }
return res; return res;

View File

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