Skip to content

Commit

Permalink
fix(core): parse project configs only in js (#18009)
Browse files Browse the repository at this point in the history
(cherry picked from commit c04053b)
  • Loading branch information
FrozenPandaz committed Jul 17, 2023
1 parent 9612d9b commit 2fcf807
Show file tree
Hide file tree
Showing 12 changed files with 298 additions and 377 deletions.
43 changes: 0 additions & 43 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions packages/nx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@ hashbrown = { version = "0.14.0", features = ["rayon"] }
ignore = '0.4'
ignore-files = "1.3.0"
itertools = "0.10.5"
jsonc-parser = { version = "0.21.1", features = ["serde"] }
napi = { version = '2.12.6', default-features = false, features = ['anyhow', 'napi4', 'tokio_rt'] }
napi-derive = '2.9.3'
rayon = "1.7.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
thiserror = "1.0.40"
tokio = { version = "1.28.2", features = ["fs"] }
tracing = "0.1.37"
Expand Down
30 changes: 15 additions & 15 deletions packages/nx/src/config/workspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class Workspaces {
return this.cachedProjectsConfig;
}
const nxJson = this.readNxJson();
const projectsConfigurations = buildProjectsConfigurationsFromProjectPaths(
let projectsConfigurations = buildProjectsConfigurationsFromProjectPaths(
nxJson,
globForProjectFiles(
this.root,
Expand All @@ -116,15 +116,18 @@ export class Workspaces {
opts?._includeProjectsFromAngularJson
)
) {
projectsConfigurations.projects = mergeAngularJsonAndProjects(
projectsConfigurations.projects,
projectsConfigurations = mergeAngularJsonAndProjects(
projectsConfigurations,
this.root
);
}
this.cachedProjectsConfig = this.mergeTargetDefaultsIntoProjectDescriptions(
projectsConfigurations,
nxJson
);
this.cachedProjectsConfig = {
version: 2,
projects: this.mergeTargetDefaultsIntoProjectDescriptions(
projectsConfigurations,
nxJson
),
};
return this.cachedProjectsConfig;
}

Expand All @@ -140,10 +143,10 @@ export class Workspaces {
}

private mergeTargetDefaultsIntoProjectDescriptions(
config: ProjectsConfigurations,
projects: Record<string, ProjectConfiguration>,
nxJson: NxJsonConfiguration
) {
for (const proj of Object.values(config.projects)) {
for (const proj of Object.values(projects)) {
if (proj.targets) {
for (const targetName of Object.keys(proj.targets)) {
const projectTargetDefinition = proj.targets[targetName];
Expand All @@ -163,7 +166,7 @@ export class Workspaces {
}
}
}
return config;
return projects;
}

isNxExecutor(nodeModule: string, executor: string) {
Expand Down Expand Up @@ -808,7 +811,7 @@ export function buildProjectsConfigurationsFromProjectPaths(
projectFiles: string[], // making this parameter allows devkit to pick up newly created projects
readJson: <T extends Object>(string) => T = <T extends Object>(string) =>
readJsonFile<T>(string) // making this an arg allows us to reuse in devkit
): ProjectsConfigurations {
): Record<string, ProjectConfiguration> {
const projects: Record<string, ProjectConfiguration> = {};

for (const file of projectFiles) {
Expand Down Expand Up @@ -868,10 +871,7 @@ export function buildProjectsConfigurationsFromProjectPaths(
}
}

return {
version: 2,
projects: projects,
};
return projects;
}

export function mergeTargetConfigurations(
Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/generators/utils/project-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function readAndCombineAllProjectConfigurations(tree: Tree): {
nxJson,
projectFiles,
(file) => readJson(tree, file)
).projects;
);
}

/**
Expand Down
7 changes: 3 additions & 4 deletions packages/nx/src/native/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@ export const enum WorkspaceErrors {
Generic = 'Generic'
}
/** Get workspace config files based on provided globs */
export function getConfigFiles(workspaceRoot: string, globs: Array<string>): Array<string>
export function getProjectConfigurations(workspaceRoot: string, globs: Array<string>, parseConfigurations: (arg0: Array<string>) => Record<string, object>): Record<string, object>
export interface NxWorkspaceFiles {
projectFileMap: Record<string, Array<FileData>>
globalFiles: Array<FileData>
configFiles: Array<string>
projectConfigurations: Record<string, object>
}
/** Throws exceptions */
export function getWorkspaceFilesNative(workspaceRoot: string, globs: Array<string>): NxWorkspaceFiles
export function getWorkspaceFilesNative(workspaceRoot: string, globs: Array<string>, parseConfigurations: (arg0: Array<string>) => Record<string, object>): NxWorkspaceFiles
export class Watcher {
origin: string
/**
Expand Down
4 changes: 2 additions & 2 deletions packages/nx/src/native/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ if (!nativeBinding) {
throw new Error(`Failed to load native binding`)
}

const { expandOutputs, remove, copy, hashArray, hashFile, hashFiles, hashFilesMatchingGlobs, EventType, Watcher, WorkspaceErrors, getConfigFiles, getWorkspaceFilesNative } = nativeBinding
const { expandOutputs, remove, copy, hashArray, hashFile, hashFiles, hashFilesMatchingGlobs, EventType, Watcher, WorkspaceErrors, getProjectConfigurations, getWorkspaceFilesNative } = nativeBinding

module.exports.expandOutputs = expandOutputs
module.exports.remove = remove
Expand All @@ -258,5 +258,5 @@ module.exports.hashFilesMatchingGlobs = hashFilesMatchingGlobs
module.exports.EventType = EventType
module.exports.Watcher = Watcher
module.exports.WorkspaceErrors = WorkspaceErrors
module.exports.getConfigFiles = getConfigFiles
module.exports.getProjectConfigurations = getProjectConfigurations
module.exports.getWorkspaceFilesNative = getWorkspaceFilesNative
Loading

0 comments on commit 2fcf807

Please sign in to comment.