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 May 1, 2024
1 parent a42f7e9 commit a6a594c
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 94 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 @@ -28,7 +28,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 { LoadedNxPlugin } from '../../project-graph/plugins/internal-api';
import { getPlugins } from './plugins';
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
33 changes: 14 additions & 19 deletions packages/nx/src/native/tasks/hashers/hash_project_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,22 @@ mod tests {
let tsfile_1 = FileData {
file: "test/root/test1.ts".into(),
hash: Default::default(),
size: 0
size: 0,
};
let testfile_1 = FileData {
file: "test/root/test.spec.ts".into(),
hash: Default::default(),
size: 0
size: 0,
};
let tsfile_2 = FileData {
file: "test/root/src/module/test3.ts".into(),
hash: Default::default(),
size: 0
size: 0,
};
let testfile_2 = FileData {
file: "test/root/test.spec.tsx.snap".into(),
hash: Default::default(),
size: 0
size: 0,
};
file_map.insert(
String::from(proj_name),
Expand Down Expand Up @@ -125,36 +125,35 @@ mod tests {
}

#[test]

fn should_hash_deterministically() {
let proj_name = "test_project";
let proj_root = "test/root";
let file_sets = &[
"!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)".to_string(),

"{projectRoot}/**/*".to_string(),
];
let mut file_map = HashMap::new();
let file_data1 = FileData {
file: "test/root/test1.ts".into(),

hash: "file_data1".into(),
size: 0
size: 0,
};
let file_data2 = FileData {
file: "test/root/test.spec.ts".into(),
hash: "file_data2".into(),
size: 0
size: 0,
};
let file_data3 = FileData {
file: "test/root/test3.ts".into(),
hash: "file_data3".into(),
size: 0
size: 0,
};
let file_data4 = FileData {
file: "test/root/test.spec.tsx.snap".into(),
hash: "file_data4".into(),
size: 0
size: 0,
};
file_map.insert(
String::from(proj_name),
Expand Down Expand Up @@ -185,26 +184,22 @@ mod tests {
let file_data1 = FileData {
file: "test/root/test1.ts".into(),
hash: "file_data1".into(),
size: 0

size: 0,
};
let file_data2 = FileData {
file: "test/root/test.spec.ts".into(),
hash: "file_data2".into(),
size: 0

size: 0,
};
let file_data3 = FileData {
file: "test/root/test3.ts".into(),
hash: "file_data3".into(),
size: 0

size: 0,
};
let file_data4 = FileData {
file: "test/root/test.spec.tsx.snap".into(),
hash: "file_data4".into(),
size: 0

size: 0,
};
file_map.insert(
String::from(proj_name),
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

0 comments on commit a6a594c

Please sign in to comment.