Skip to content

Commit

Permalink
feat(core): support projectName token in target defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed Jan 3, 2023
1 parent 355d8a0 commit b19eb6c
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions packages/nx/src/config/workspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -937,8 +937,7 @@ export function mergeTargetConfigurations(
target: string,
targetDefaults: TargetDefaults[string]
): TargetConfiguration {
const { targets, root } = projectConfiguration;
const targetConfiguration = targets?.[target];
const targetConfiguration = projectConfiguration.targets?.[target];

if (!targetConfiguration) {
throw new Error(
Expand Down Expand Up @@ -966,13 +965,13 @@ export function mergeTargetConfigurations(
result.options = mergeOptions(
defaultOptions,
targetConfiguration.options ?? {},
root,
projectConfiguration,
target
);
result.configurations = mergeConfigurations(
defaultConfigurations,
targetConfiguration.configurations,
root,
projectConfiguration,
target
);
}
Expand All @@ -982,27 +981,27 @@ export function mergeTargetConfigurations(
function mergeOptions<T extends Object>(
defaults: T,
options: T,
projectRoot: string,
project: ProjectConfiguration,
key: string
): T {
return {
...resolvePathTokensInOptions(defaults, projectRoot, key),
...resolvePathTokensInOptions(defaults, project, key),
...options,
};
}

function mergeConfigurations<T extends Object>(
defaultConfigurations: Record<string, T>,
projectDefinedConfigurations: Record<string, T>,
projectRoot: string,
project: ProjectConfiguration,
targetName: string
): Record<string, T> {
const configurations: Record<string, T> = { ...projectDefinedConfigurations };
for (const configuration in defaultConfigurations) {
configurations[configuration] = mergeOptions(
defaultConfigurations[configuration],
configurations[configuration],
projectRoot,
project,
`${targetName}.${configuration}`
);
}
Expand All @@ -1011,7 +1010,7 @@ function mergeConfigurations<T extends Object>(

function resolvePathTokensInOptions<T extends Object | Array<unknown>>(
object: T,
projectRoot: string,
project: ProjectConfiguration,
key: string
): T {
const result: T = Array.isArray(object) ? ([...object] as T) : { ...object };
Expand All @@ -1025,11 +1024,12 @@ function resolvePathTokensInOptions<T extends Object | Array<unknown>>(
`${NX_PREFIX} The {workspaceRoot} token is only valid at the beginning of an option. (${key})`
);
}
result[opt] = value.replace('{projectRoot}', projectRoot);
value = value.replace('{projectRoot}', project.root);
result[opt] = value.replace('{projectName}', project.name);
} else if (typeof value === 'object' && value) {
result[opt] = resolvePathTokensInOptions(
value,
projectRoot,
project,
[key, opt].join('.')
);
}
Expand Down

0 comments on commit b19eb6c

Please sign in to comment.