Skip to content

Commit

Permalink
Merge branch 'master' into changelog-true
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesHenry committed Nov 24, 2023
2 parents 73cdca0 + d06a5e7 commit a826f36
Show file tree
Hide file tree
Showing 16 changed files with 300 additions and 188 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,11 @@ jobs:
timeout-minutes: 45
steps:
- uses: actions/checkout@v3
if: ${{ !contains(github.ref, '-') }}
- name: Build
id: build
uses: cross-platform-actions/action@v0.21.0
if: ${{ !contains(github.ref, '-') }}
uses: cross-platform-actions/action@v0.21.1
env:
DEBUG: napi:*
RUSTUP_IO_THREADS: 1
Expand Down Expand Up @@ -197,9 +199,10 @@ jobs:
rm -rf node_modules
rm -rf dist
echo "KILL ALL NODE PROCESSES"
killall node
killall node || true
echo "COMPLETE"
- name: Upload artifact
if: ${{ !contains(github.ref, '-') }}
uses: actions/upload-artifact@v3
with:
name: bindings-freebsd
Expand Down
2 changes: 1 addition & 1 deletion packages/devkit/src/utils/convert-nx-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function convertNxExecutor(executor: Executor) {
projects: await retrieveProjectConfigurationsWithAngularProjects(
builderContext.workspaceRoot,
nxJsonConfiguration
).then((p) => (p as any).projectNodes ?? p.projects),
).then((p) => p.projectNodes),
}
: // TODO(v18): remove retrieveProjectConfigurations. This is to be backwards compatible with Nx 16.5 and below.
(workspaces as any).readProjectsConfigurations({
Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/command-line/run-many/run-many.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ describe('run-many', () => {
);
performance.mark('end');
const measure = performance.measure('projects', 'start', 'end');
expect(measure.duration).toBeLessThan(4000);
expect(measure.duration).toBeLessThan(10000);
});
});
});
Expand Down
4 changes: 2 additions & 2 deletions packages/nx/src/config/workspaces.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ describe('Workspaces', () => {
}),
});

const { projects } = await withEnvironmentVariables(
const { projectNodes } = await withEnvironmentVariables(
{
NX_WORKSPACE_ROOT: fs.tempDir,
},
() => retrieveProjectConfigurations(fs.tempDir, readNxJson(fs.tempDir))
);
expect(projects['my-package']).toEqual({
expect(projectNodes['my-package']).toEqual({
name: 'my-package',
root: 'packages/my-package',
sourceRoot: 'packages/my-package',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
readFileMapCache,
} from '../../project-graph/nx-deps-cache';
import {
RetrievedGraphNodes,
retrieveProjectConfigurations,
retrieveWorkspaceFiles,
} from '../../project-graph/utils/retrieve-workspace-files';
Expand Down Expand Up @@ -144,11 +143,10 @@ function computeWorkspaceConfigHash(
return hashArray(projectConfigurationStrings);
}

async function processCollectedUpdatedAndDeletedFiles({
projects,
externalNodes,
projectRootMap,
}: RetrievedGraphNodes) {
async function processCollectedUpdatedAndDeletedFiles(
projects: Record<string, ProjectConfiguration>,
nxJson: NxJsonConfiguration
) {
try {
performance.mark('hash-watched-changes-start');
const updatedFiles = [...collectedUpdatedFiles.values()];
Expand All @@ -172,12 +170,8 @@ async function processCollectedUpdatedAndDeletedFiles({
if (workspaceConfigHash !== storedWorkspaceConfigHash) {
storedWorkspaceConfigHash = workspaceConfigHash;

({ ...fileMapWithFiles } = await retrieveWorkspaceFiles(
workspaceRoot,
projectRootMap
));

knownExternalNodes = externalNodes;
({ externalNodes: knownExternalNodes, ...fileMapWithFiles } =
await retrieveWorkspaceFiles(workspaceRoot, nxJson));
} else {
if (fileMapWithFiles) {
fileMapWithFiles = updateFileMap(
Expand All @@ -187,10 +181,7 @@ async function processCollectedUpdatedAndDeletedFiles({
deletedFiles
);
} else {
fileMapWithFiles = await retrieveWorkspaceFiles(
workspaceRoot,
projectRootMap
);
fileMapWithFiles = await retrieveWorkspaceFiles(workspaceRoot, nxJson);
}
}

Expand Down Expand Up @@ -219,9 +210,12 @@ async function processFilesAndCreateAndSerializeProjectGraph() {
workspaceRoot,
nxJson
);
await processCollectedUpdatedAndDeletedFiles(configResult);
await processCollectedUpdatedAndDeletedFiles(
configResult.projectNodes,
nxJson
);
writeSourceMaps(configResult.sourceMaps);
return createAndSerializeProjectGraph(configResult);
return createAndSerializeProjectGraph(configResult.projectNodes);
} catch (err) {
return Promise.resolve({
error: err,
Expand Down Expand Up @@ -249,9 +243,9 @@ function copyFileMap(m: FileMap) {
return c;
}

async function createAndSerializeProjectGraph({
projects,
}: RetrievedGraphNodes): Promise<{
async function createAndSerializeProjectGraph(
projects: Record<string, ProjectConfiguration>
): Promise<{
error: string | null;
projectGraph: ProjectGraph | null;
fileMap: FileMap | null;
Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/executors/utils/convert-nx-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function convertNxExecutor(executor: Executor) {
builderContext.workspaceRoot,
nxJsonConfiguration
)
).projects,
).projectNodes,
};
const context: ExecutorContext = {
root: builderContext.workspaceRoot,
Expand Down
49 changes: 17 additions & 32 deletions packages/nx/src/hasher/native-task-hasher-impl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,16 @@ describe('native task hasher', () => {
});

it('should create a task hash', async () => {
const workspaceFiles = await retrieveWorkspaceFiles(tempFs.tempDir, {
'libs/parent': 'parent',
'libs/unrelated': 'unrelated',
'libs/tagged': 'tagged',
});
const workspaceFiles = await retrieveWorkspaceFiles(tempFs.tempDir, nxJson);
const builder = new ProjectGraphBuilder(
undefined,
workspaceFiles.fileMap.projectFileMap
);

builder.addNode({
name: 'parent',
type: 'lib',
data: {
root: 'libs/parent',
root: 'parent',
targets: {
build: {
executor: 'nx:run-commands',
Expand Down Expand Up @@ -154,9 +149,9 @@ describe('native task hasher', () => {
"AllExternalDependencies": "3244421341483603138",
"env:NONEXISTENTENV": "3244421341483603138",
"env:TESTENV": "11441948532827618368",
"parent:ProjectConfiguration": "4131510303084753861",
"parent:ProjectConfiguration": "15828052557461792163",
"parent:TsConfig": "2264969541778889434",
"parent:{projectRoot}/**/*": "15295586939211629225",
"parent:{projectRoot}/**/*": "3244421341483603138",
"runtime:echo runtime123": "29846575039086708",
"tagged:ProjectConfiguration": "1604492097835699503",
"tagged:TsConfig": "2264969541778889434",
Expand All @@ -168,17 +163,17 @@ describe('native task hasher', () => {
"{workspaceRoot}/.nxignore": "3244421341483603138",
"{workspaceRoot}/nx.json": "5219582320960288192",
},
"value": "6332317845632665670",
"value": "2902224107680327789",
},
]
`);
});

it('should hash tasks where the project has dependencies', async () => {
const workspaceFiles = await retrieveWorkspaceFiles(tempFs.tempDir, {
'libs/parent': 'parent',
'libs/child': 'child',
});
console.log('read first', await tempFs.readFile('nx.json'));
const workspaceFiles = await retrieveWorkspaceFiles(tempFs.tempDir, nxJson);
console.dir(workspaceFiles.allWorkspaceFiles);
console.log('read second', await tempFs.readFile('nx.json'));
const builder = new ProjectGraphBuilder(
undefined,
workspaceFiles.fileMap.projectFileMap
Expand Down Expand Up @@ -248,10 +243,10 @@ describe('native task hasher', () => {
} as any;
tempFs.writeFile('nx.json', JSON.stringify(nxJsonModified));

const workspaceFiles = await retrieveWorkspaceFiles(tempFs.tempDir, {
'libs/parent': 'parent',
'libs/child': 'child',
});
const workspaceFiles = await retrieveWorkspaceFiles(
tempFs.tempDir,
nxJsonModified
);

let builder = new ProjectGraphBuilder(
undefined,
Expand Down Expand Up @@ -328,9 +323,7 @@ describe('native task hasher', () => {
},
};
tempFs.writeFile('nx.json', JSON.stringify(nxJson));
const workspaceFiles = await retrieveWorkspaceFiles(tempFs.tempDir, {
'libs/parent': 'parent',
});
const workspaceFiles = await retrieveWorkspaceFiles(tempFs.tempDir, nxJson);
let builder = new ProjectGraphBuilder(
undefined,
workspaceFiles.fileMap.projectFileMap
Expand Down Expand Up @@ -410,10 +403,7 @@ describe('native task hasher', () => {
},
};
tempFs.writeFile('nx.json', JSON.stringify(nxJson));
const workspaceFiles = await retrieveWorkspaceFiles(tempFs.tempDir, {
'libs/parent': 'parent',
'libs/child': 'child',
});
const workspaceFiles = await retrieveWorkspaceFiles(tempFs.tempDir, nxJson);
const builder = new ProjectGraphBuilder(
undefined,
workspaceFiles.fileMap.projectFileMap
Expand Down Expand Up @@ -496,9 +486,7 @@ describe('native task hasher', () => {
});

it('should be able to include only a part of the base tsconfig', async () => {
let workspaceFiles = await retrieveWorkspaceFiles(tempFs.tempDir, {
'libs/parent': 'parent',
});
let workspaceFiles = await retrieveWorkspaceFiles(tempFs.tempDir, nxJson);
const builder = new ProjectGraphBuilder(
undefined,
workspaceFiles.fileMap.projectFileMap
Expand Down Expand Up @@ -551,10 +539,7 @@ describe('native task hasher', () => {
});

it('should hash tasks where the project graph has circular dependencies', async () => {
const workspaceFiles = await retrieveWorkspaceFiles(tempFs.tempDir, {
'libs/parent': 'parent',
'libs/child': 'child',
});
const workspaceFiles = await retrieveWorkspaceFiles(tempFs.tempDir, nxJson);
const builder = new ProjectGraphBuilder(
undefined,
workspaceFiles.fileMap.projectFileMap
Expand Down
3 changes: 2 additions & 1 deletion packages/nx/src/native/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,10 @@ export class Watcher {
export class WorkspaceContext {
workspaceRoot: string
constructor(workspaceRoot: string)
getWorkspaceFiles(projectRootMap: Record<string, string>): NxWorkspaceFiles
getWorkspaceFiles(globs: Array<string>, parseConfigurations: (arg0: Array<string>) => Promise<Record<string, string>>): Promise<NxWorkspaceFiles>
glob(globs: Array<string>, exclude?: Array<string> | undefined | null): Array<string>
hashFilesMatchingGlob(globs: Array<string>, exclude?: Array<string> | undefined | null): string
getProjectConfigurations(globs: Array<string>, parseConfigurations: (arg0: Array<string>) => Promise<Record<string, string>>): Promise<Record<string, string>>
incrementalUpdate(updatedFiles: Array<string>, deletedFiles: Array<string>): Record<string, string>
updateProjectFiles(projectRootMappings: ProjectRootMappings, projectFiles: ExternalObject<ProjectFiles>, globalFiles: ExternalObject<Array<FileData>>, updatedFiles: Record<string, string>, deletedFiles: Array<string>): UpdatedWorkspaceFiles
allFileData(): Array<FileData>
Expand Down
16 changes: 6 additions & 10 deletions packages/nx/src/native/tests/workspace_files.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,12 @@ describe('workspace files', () => {
'./libs/package-project/index.js': '',
'./nested/non-project/file.txt': '',
});
let globs = ['project.json', '**/project.json', 'libs/*/package.json'];

const context = new WorkspaceContext(fs.tempDir);
let { projectFileMap, globalFiles } = await context.getWorkspaceFiles(
{
'libs/project1': 'project1',
'libs/project2': 'project2',
'libs/project3': 'project3',
'libs/nested/project': 'nested-project',
'libs/package-project': 'package-project'
}
globs,
createParseConfigurationsFunction(fs.tempDir)
);

expect(projectFileMap).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -151,10 +147,10 @@ describe('workspace files', () => {

const context = new WorkspaceContext(fs.tempDir);

const globs = ['project.json', '**/project.json', '**/package.json'];
const { globalFiles, projectFileMap } = await context.getWorkspaceFiles(
{
'.': 'repo-name'
}
globs,
createParseConfigurationsFunction(fs.tempDir)
);

expect(globalFiles).toEqual([]);
Expand Down
17 changes: 17 additions & 0 deletions packages/nx/src/native/workspace/config_files.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use std::collections::HashMap;

use napi::bindgen_prelude::Promise;
use rayon::prelude::*;

use crate::native::glob::build_glob_set;
Expand Down Expand Up @@ -29,3 +32,17 @@ pub(super) fn glob_files(
.unwrap_or(is_match)
}))
}

/// Get workspace config files based on provided globs
pub(super) fn get_project_configurations<ConfigurationParser>(
globs: Vec<String>,
files: &[FileData],
parse_configurations: ConfigurationParser,
) -> napi::Result<Promise<HashMap<String, String>>>
where
ConfigurationParser: Fn(Vec<String>) -> napi::Result<Promise<HashMap<String, String>>>,
{
let files = glob_files(files, globs, None).map_err(anyhow::Error::from)?;

parse_configurations(files.map(|file| file.file.to_owned()).collect())
}

0 comments on commit a826f36

Please sign in to comment.