Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): handle complex glob patterns within rust #18242

Merged
merged 7 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 37 additions & 8 deletions Cargo.lock

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

15 changes: 15 additions & 0 deletions docs/shared/reference/project-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,21 @@ But if the above is not possible, globs (parsed by the [GlobSet](https://docs.rs
}
```

More advanced patterns can be used to exclude files and folders in a single line

```json
{
"targets": {
"build-js": {
"outputs": ["{workspaceRoot}/dist/libs/!(cache|.next)/**/*.{js,map}"]
},
"build-css": {
"outputs": ["{workspaceRoot}/dist/libs/mylib/**/!(secondary).css"]
}
}
}
```

### dependsOn

Targets can depend on other targets. This is the relevant portion of the configuration file:
Expand Down
48 changes: 36 additions & 12 deletions e2e/nx-run/src/cache.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import {
cleanupProject,
directoryExists,
listFiles,
newProject,
readFile,
rmDist,
runCLI,
tmpProjPath,
uniq,
updateFile,
updateJson,
Expand Down Expand Up @@ -157,18 +159,23 @@ describe('cache', () => {
updateProjectConfig(mylib, (c) => {
c.targets.build = {
executor: 'nx:run-commands',
outputs: ['{workspaceRoot}/dist/*.{txt,md}'],
outputs: ['{workspaceRoot}/dist/!(.next)/**/!(z|x).(txt|md)'],
options: {
commands: [
'rm -rf dist',
'mkdir dist',
'echo a > dist/a.txt',
'echo b > dist/b.txt',
'echo c > dist/c.txt',
'echo d > dist/d.txt',
'echo e > dist/e.txt',
'echo f > dist/f.md',
'echo g > dist/g.html',
'mkdir dist/apps',
'mkdir dist/.next',
'echo a > dist/apps/a.txt',
'echo b > dist/apps/b.txt',
'echo c > dist/apps/c.txt',
'echo d > dist/apps/d.txt',
'echo e > dist/apps/e.txt',
'echo f > dist/apps/f.md',
'echo g > dist/apps/g.html',
'echo h > dist/.next/h.txt',
'echo x > dist/apps/x.txt',
'echo z > dist/apps/z.md',
],
parallel: false,
},
Expand All @@ -183,29 +190,43 @@ describe('cache', () => {
// Rerun without touching anything
const rerunWithUntouchedOutputs = runCLI(`build ${mylib}`);
expect(rerunWithUntouchedOutputs).toContain('local cache');
const outputsWithUntouchedOutputs = listFiles('dist');
const outputsWithUntouchedOutputs = [
...listFiles('dist/apps'),
...listFiles('dist/.next').map((f) => `.next/${f}`),
];
expect(outputsWithUntouchedOutputs).toContain('a.txt');
expect(outputsWithUntouchedOutputs).toContain('b.txt');
expect(outputsWithUntouchedOutputs).toContain('c.txt');
expect(outputsWithUntouchedOutputs).toContain('d.txt');
expect(outputsWithUntouchedOutputs).toContain('e.txt');
expect(outputsWithUntouchedOutputs).toContain('f.md');
expect(outputsWithUntouchedOutputs).toContain('g.html');
expect(outputsWithUntouchedOutputs).toContain('.next/h.txt');
expect(outputsWithUntouchedOutputs).toContain('x.txt');
expect(outputsWithUntouchedOutputs).toContain('z.md');

// Create a file in the dist that does not match output glob
updateFile('dist/c.ts', '');
updateFile('dist/apps/c.ts', '');

// Rerun
const rerunWithNewUnrelatedFile = runCLI(`build ${mylib}`);
expect(rerunWithNewUnrelatedFile).toContain('local cache');
const outputsAfterAddingUntouchedFileAndRerunning = listFiles('dist');
const outputsAfterAddingUntouchedFileAndRerunning = [
...listFiles('dist/apps'),
...listFiles('dist/.next').map((f) => `.next/${f}`),
];
expect(outputsAfterAddingUntouchedFileAndRerunning).toContain('a.txt');
expect(outputsAfterAddingUntouchedFileAndRerunning).toContain('b.txt');
expect(outputsAfterAddingUntouchedFileAndRerunning).toContain('c.txt');
expect(outputsAfterAddingUntouchedFileAndRerunning).toContain('d.txt');
expect(outputsAfterAddingUntouchedFileAndRerunning).toContain('e.txt');
expect(outputsAfterAddingUntouchedFileAndRerunning).toContain('f.md');
expect(outputsAfterAddingUntouchedFileAndRerunning).toContain('g.html');
expect(outputsAfterAddingUntouchedFileAndRerunning).toContain(
'.next/h.txt'
);
expect(outputsAfterAddingUntouchedFileAndRerunning).toContain('x.txt');
expect(outputsAfterAddingUntouchedFileAndRerunning).toContain('z.md');
expect(outputsAfterAddingUntouchedFileAndRerunning).toContain('c.ts');

// Clear Dist
Expand All @@ -214,7 +235,8 @@ describe('cache', () => {
// Rerun
const rerunWithoutOutputs = runCLI(`build ${mylib}`);
expect(rerunWithoutOutputs).toContain('read the output from the cache');
const outputsWithoutOutputs = listFiles('dist');
const outputsWithoutOutputs = listFiles('dist/apps');
expect(directoryExists(`${tmpProjPath()}/dist/.next`)).toBe(false);
expect(outputsWithoutOutputs).toContain('a.txt');
expect(outputsWithoutOutputs).toContain('b.txt');
expect(outputsWithoutOutputs).toContain('c.txt');
Expand All @@ -223,6 +245,8 @@ describe('cache', () => {
expect(outputsWithoutOutputs).toContain('f.md');
expect(outputsWithoutOutputs).not.toContain('c.ts');
expect(outputsWithoutOutputs).not.toContain('g.html');
expect(outputsWithoutOutputs).not.toContain('x.txt');
expect(outputsWithoutOutputs).not.toContain('z.md');
});

it('should use consider filesets when hashing', async () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/nx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ hashbrown = { version = "0.14.0", features = ["rayon"] }
ignore = '0.4'
ignore-files = "1.3.0"
itertools = "0.10.5"
once_cell = "1.18.0"
napi = { version = '2.12.6', default-features = false, features = ['anyhow', 'napi4', 'tokio_rt'] }
napi-derive = '2.9.3'
regex = "1.9.1"
rayon = "1.7.0"
thiserror = "1.0.40"
tokio = { version = "1.28.2", features = ["fs"] }
Expand Down
6 changes: 0 additions & 6 deletions packages/nx/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,6 @@
"version": "16.2.0-beta.0",
"description": "Remove outputPath from run commands",
"implementation": "./src/migrations/update-16-2-0/remove-run-commands-output-path"
},
"16.5.4-update-output-globs": {
"cli": "nx",
"version": "16.5.4-beta.0",
"description": "Update outdated non-standard globs to unix standard",
"implementation": "./src/migrations/update-16-5-4/update-output-globs"
}
}
}

This file was deleted.

54 changes: 0 additions & 54 deletions packages/nx/src/migrations/update-16-5-4/update-output-globs.ts

This file was deleted.

Loading