Skip to content

Commit

Permalink
fix(core): make npm scope optional (#9966)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed Apr 22, 2022
1 parent 30a3f93 commit c3484c7
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 13 deletions.
@@ -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 {
Expand All @@ -10,4 +10,4 @@ import { Component } from '@angular/core';
padding: 5px;
}`]
})
export class RemoteEntryComponent {}
export class RemoteEntryComponent {}
Expand Up @@ -12,15 +12,13 @@ export function addEntryModule(
appRoot: string
) {
if (mfeType === 'remote') {
const { npmScope } = readWorkspaceConfiguration(host);
generateFiles(
host,
joinPathFragments(__dirname, '../files/entry-module-files'),
`${appRoot}/src/app/remote-entry`,
{
tmpl: '',
appName,
npmScope,
routing,
}
);
Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/config/nx-json.ts
Expand Up @@ -35,7 +35,7 @@ export interface NxJsonConfiguration<T = '*' | string[]> {
/**
* NPM Scope that the workspace uses
*/
npmScope: string;
npmScope?: string;
/**
* Default options for `nx affected`
*/
Expand Down
8 changes: 5 additions & 3 deletions packages/nx/src/config/workspaces.ts
Expand Up @@ -587,10 +587,12 @@ 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 (name.startsWith(npmPrefix)) {
name = name.replace(npmPrefix, '');
if (nxJson.npmScope) {
const npmPrefix = `@${nxJson.npmScope}/`;
if (name.startsWith(npmPrefix)) {
name = name.replace(npmPrefix, '');
}
}
return {
root: directory,
Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/hasher/hasher.ts
Expand Up @@ -490,7 +490,7 @@ class ProjectHasher {
res.projects ??= {};
return res;
} catch {
return { npmScope: '' };
return {};
}
}
}
Expand Up @@ -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;
Expand Down
3 changes: 0 additions & 3 deletions packages/nx/src/project-graph/file-utils.ts
Expand Up @@ -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 = {
Expand Down

0 comments on commit c3484c7

Please sign in to comment.