Skip to content

Commit

Permalink
feat(core): make size optional in the FileData interface for js
Browse files Browse the repository at this point in the history
  • Loading branch information
Cammisuli committed Apr 10, 2024
1 parent 332f062 commit 4461651
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 75 deletions.
9 changes: 9 additions & 0 deletions docs/generated/devkit/FileData.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Some metadata about a file
- [deps](../../devkit/documents/FileData#deps): FileDataDependency[]
- [file](../../devkit/documents/FileData#file): string
- [hash](../../devkit/documents/FileData#hash): string
- [size](../../devkit/documents/FileData#size): number

## Properties

Expand All @@ -33,3 +34,11 @@ If the tuple has 3 elements, the first is preceded by a source.
### hash

**hash**: `string`

---

### size

`Optional` **size**: `number`

The size in bytes of this file on the file system \*
9 changes: 0 additions & 9 deletions packages/nx/src/command-line/release/config/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,28 +97,24 @@ describe('createNxReleaseConfig()', () => {
'lib-a': [
{
file: 'libs/lib-a/package.json',
size: 0,
hash: 'abc',
},
],
'lib-b': [
{
file: 'libs/lib-b/package.json',
size: 0,
hash: 'abc',
},
],
nx: [
{
file: 'packages/nx/package.json',
size: 0,
hash: 'abc',
},
],
root: [
{
file: 'package.json',
size: 0,
hash: 'abc',
},
],
Expand Down Expand Up @@ -671,15 +667,13 @@ describe('createNxReleaseConfig()', () => {
{
file: 'apps/app-1/package.json',
hash: 'abc',
size: 0,
},
];

projectFileMap['e2e-1'] = [
{
file: 'apps/e2e-1/package.json',
hash: 'abc',
size: 0,
},
];

Expand Down Expand Up @@ -870,7 +864,6 @@ describe('createNxReleaseConfig()', () => {
{
file: 'libs/lib-c/cargo.toml',
hash: 'abc',
size: 0,
},
];

Expand Down Expand Up @@ -1061,7 +1054,6 @@ describe('createNxReleaseConfig()', () => {
{
file: 'package.json',
hash: 'abc',
size: 0,
},
];

Expand Down Expand Up @@ -1260,7 +1252,6 @@ describe('createNxReleaseConfig()', () => {
{
file: 'package.json',
hash: 'abc',
size: 0,
},
];

Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/config/project-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface FileData {
file: string;
hash: string;
/** The size in bytes of this file on the file system **/
size: number;
size?: number;
/**
* An array of dependencies. If an element is just a string,
* the dependency is assumed to be a static dependency targetting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ import {
import { workspaceRoot } from '../../utils/workspace-root';
import { notifyFileWatcherSockets } from './file-watching/file-watcher-sockets';
import { serverLogger } from './logger';
import { NxWorkspaceFilesExternals } from '../../native';
import {
FileData as NativeFileData,
NxWorkspaceFilesExternals,
} from '../../native';
import { ConfigurationResult } from '../../project-graph/utils/project-configuration-utils';
import { DaemonProjectGraphError } from '../daemon-project-graph-error';
import { LoadedNxPlugin } from '../../project-graph/plugins/internal-api';
Expand Down Expand Up @@ -160,7 +163,7 @@ function computeWorkspaceConfigHash(

async function processCollectedUpdatedAndDeletedFiles(
{ projects, externalNodes, projectRootMap }: ConfigurationResult,
updatedFileHashes: FileData[],
updatedFileHashes: NativeFileData[],
deletedFiles: string[]
) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ describe('getTouchedProjectsFromLockFile', () => {
{
file: 'source.ts',
hash: 'some-hash',
size: 0,
getChanges: () => [new WholeFileChange()],
},
],
Expand All @@ -60,7 +59,6 @@ describe('getTouchedProjectsFromLockFile', () => {
{
file: lockFile,
hash: 'some-hash',
size: 0,
getChanges: () => [new WholeFileChange()],
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ describe('getTouchedNpmPackages', () => {
{
file: 'package.json',
hash: 'some-hash',
size: 0,
getChanges: () => [
{
type: JsonDiffType.Modified,
Expand Down Expand Up @@ -96,7 +95,6 @@ describe('getTouchedNpmPackages', () => {
{
file: 'package.json',
hash: 'some-hash',
size: 0,
getChanges: () => [
{
type: JsonDiffType.Modified,
Expand Down Expand Up @@ -132,7 +130,6 @@ describe('getTouchedNpmPackages', () => {
{
file: 'package.json',
hash: 'some-hash',
size: 0,
getChanges: () => [
{
type: JsonDiffType.Modified,
Expand Down Expand Up @@ -163,7 +160,6 @@ describe('getTouchedNpmPackages', () => {
{
file: 'package.json',
hash: 'some-hash',
size: 0,
getChanges: () => [
{
type: JsonDiffType.Deleted,
Expand Down Expand Up @@ -202,7 +198,6 @@ describe('getTouchedNpmPackages', () => {
{
file: 'package.json',
hash: 'some-hash',
size: 0,
getChanges: () => [
{
type: JsonDiffType.Added,
Expand Down Expand Up @@ -242,7 +237,6 @@ describe('getTouchedNpmPackages', () => {
{
file: 'package.json',
hash: 'some-hash',
size: 0,
getChanges: () => [new WholeFileChange()],
},
],
Expand All @@ -269,7 +263,6 @@ describe('getTouchedNpmPackages', () => {
{
file: 'package.json',
hash: 'some-hash',
size: 0,
getChanges: () => [
{
type: 'JsonPropertyAdded',
Expand Down Expand Up @@ -310,7 +303,6 @@ describe('getTouchedNpmPackages', () => {
{
file: 'package.json',
hash: 'some-hash',
size: 0,
getChanges: () => [
{
type: 'JsonPropertyAdded',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ describe('getTouchedProjectsFromTsConfig', () => {
{
file: 'source.ts',
hash: 'some-hash',
size: 0,
getChanges: () => [new WholeFileChange()],
},
],
Expand All @@ -69,7 +68,6 @@ describe('getTouchedProjectsFromTsConfig', () => {
{
file: tsConfig,
hash: 'some-hash',
size: 0,
getChanges: () => [new WholeFileChange()],
},
],
Expand All @@ -89,7 +87,6 @@ describe('getTouchedProjectsFromTsConfig', () => {
{
file: tsConfig,
hash: 'some-hash',
size: 0,
getChanges: () =>
jsonDiff(
{
Expand Down Expand Up @@ -121,7 +118,6 @@ describe('getTouchedProjectsFromTsConfig', () => {
{
file: tsConfig,
hash: 'some-hash',
size: 0,
getChanges: () =>
jsonDiff(
{
Expand Down Expand Up @@ -153,7 +149,6 @@ describe('getTouchedProjectsFromTsConfig', () => {
{
file: tsConfig,
hash: 'some-hash',
size: 0,
getChanges: () =>
jsonDiff(
{
Expand Down Expand Up @@ -187,7 +182,6 @@ describe('getTouchedProjectsFromTsConfig', () => {
{
file: tsConfig,
hash: 'some-hash',
size: 0,
getChanges: () =>
jsonDiff(
{
Expand Down Expand Up @@ -219,7 +213,6 @@ describe('getTouchedProjectsFromTsConfig', () => {
{
file: tsConfig,
hash: 'some-hash',
size: 0,
getChanges: () =>
jsonDiff(
{
Expand Down Expand Up @@ -256,7 +249,6 @@ describe('getTouchedProjectsFromTsConfig', () => {
{
file: tsConfig,
hash: 'some-hash',
size: 0,
getChanges: () =>
jsonDiff(
{
Expand Down Expand Up @@ -291,7 +283,6 @@ describe('getTouchedProjectsFromTsConfig', () => {
{
file: tsConfig,
hash: 'some-hash',
size: 0,
getChanges: () =>
jsonDiff(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ describe('getTouchedProjectsInWorkspaceJson', () => {
{
file: 'source.ts',
hash: 'some-hash',
size: 0,
getChanges: () => [new WholeFileChange()],
},
],
Expand All @@ -24,7 +23,6 @@ describe('getTouchedProjectsInWorkspaceJson', () => {
[
{
file: 'angular.json',
size: 0,
hash: 'some-hash',
getChanges: () => [new WholeFileChange()],
},
Expand Down Expand Up @@ -57,7 +55,6 @@ describe('getTouchedProjectsInWorkspaceJson', () => {
{
file: 'angular.json',
hash: 'some-hash',
size: 0,
getChanges: () => [
{
type: JsonDiffType.Modified,
Expand Down Expand Up @@ -98,7 +95,6 @@ describe('getTouchedProjectsInWorkspaceJson', () => {
{
file: 'angular.json',
hash: 'some-hash',
size: 0,
getChanges: () => [
{
type: JsonDiffType.Added,
Expand Down Expand Up @@ -141,7 +137,6 @@ describe('getTouchedProjectsInWorkspaceJson', () => {
[
{
file: 'angular.json',
size: 0,
hash: 'some-hash',
getChanges: () => [
{
Expand Down Expand Up @@ -185,7 +180,6 @@ describe('getTouchedProjectsInWorkspaceJson', () => {
{
file: 'angular.json',
hash: 'some-hash',
size: 0,
getChanges: () => [
{
type: JsonDiffType.Modified,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ function getFileChanges(files: string[]) {
return files.map((f) => ({
file: f,
hash: 'some-hash',
size: 0,
getChanges: () => [new WholeFileChange()],
}));
}
Expand Down
28 changes: 12 additions & 16 deletions packages/nx/src/project-graph/file-map-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,30 @@ describe('fileMapUtils', () => {
},
};
const files = [
{ file: 'apps/demo/src/main.ts', hash: 'some-hash', size: 0 },
{ file: 'apps/demo-e2e/src/main.ts', hash: 'some-hash', size: 0 },
{ file: 'libs/ui/src/index.ts', hash: 'some-hash', size: 0 },
{ file: 'tools/myfile.txt', hash: 'some-hash', size: 0 },
{ file: 'apps/demo/src/main.ts', hash: 'some-hash' },
{ file: 'apps/demo-e2e/src/main.ts', hash: 'some-hash' },
{ file: 'libs/ui/src/index.ts', hash: 'some-hash' },
{ file: 'tools/myfile.txt', hash: 'some-hash' },
];

const result = createFileMap(projectsConfigurations, files);

expect(result).toEqual({
fileMap: {
projectFileMap: {
demo: [
{ file: 'apps/demo/src/main.ts', hash: 'some-hash', size: 0 },
],
demo: [{ file: 'apps/demo/src/main.ts', hash: 'some-hash' }],
'demo-e2e': [
{ file: 'apps/demo-e2e/src/main.ts', hash: 'some-hash', size: 0 },
{ file: 'apps/demo-e2e/src/main.ts', hash: 'some-hash' },
],
ui: [{ file: 'libs/ui/src/index.ts', hash: 'some-hash', size: 0 }],
ui: [{ file: 'libs/ui/src/index.ts', hash: 'some-hash' }],
},
nonProjectFiles: [
{ file: 'tools/myfile.txt', hash: 'some-hash', size: 0 },
],
nonProjectFiles: [{ file: 'tools/myfile.txt', hash: 'some-hash' }],
},
allWorkspaceFiles: [
{ file: 'apps/demo/src/main.ts', hash: 'some-hash', size: 0 },
{ file: 'apps/demo-e2e/src/main.ts', hash: 'some-hash', size: 0 },
{ file: 'libs/ui/src/index.ts', hash: 'some-hash', size: 0 },
{ file: 'tools/myfile.txt', hash: 'some-hash', size: 0 },
{ file: 'apps/demo/src/main.ts', hash: 'some-hash' },
{ file: 'apps/demo-e2e/src/main.ts', hash: 'some-hash' },
{ file: 'libs/ui/src/index.ts', hash: 'some-hash' },
{ file: 'tools/myfile.txt', hash: 'some-hash' },
],
});
});
Expand Down
8 changes: 6 additions & 2 deletions packages/nx/src/project-graph/file-map-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import {
ProjectsConfigurations,
} from '../config/workspace-json-project-json';
import { daemonClient } from '../daemon/client/client';
import { NxWorkspaceFilesExternals } from '../native';
import {
NxWorkspaceFilesExternals,
FileData as NativeFileData,
} from '../native';

import {
getAllFileDataInContext,
updateProjectFiles,
Expand Down Expand Up @@ -86,7 +90,7 @@ export function createFileMap(
export function updateFileMap(
projectsConfigurations: Record<string, ProjectConfiguration>,
rustReferences: NxWorkspaceFilesExternals,
updatedFiles: FileData[],
updatedFiles: NativeFileData[],
deletedFiles: string[]
) {
const updates = updateProjectFiles(
Expand Down

0 comments on commit 4461651

Please sign in to comment.