@smoothbricks/nx-plugin 0.4.4 → 0.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/package-target-policy.d.ts.map +1 -1
- package/dist/package-target-policy.js +3 -2
- package/dist/source-directories.d.ts +11 -0
- package/dist/source-directories.d.ts.map +1 -0
- package/dist/source-directories.js +19 -0
- package/package.json +1 -1
- package/src/index.ts +2 -1
- package/src/package-target-policy.test.ts +16 -0
- package/src/package-target-policy.ts +3 -2
- package/src/source-directories.ts +21 -0
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,KAAK,aAAa,EAGnB,MAAM,0BAA0B,CAAC;AAKlC,OAAO,EAGL,yBAAyB,EAQ1B,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,KAAK,aAAa,EAGnB,MAAM,0BAA0B,CAAC;AAKlC,OAAO,EAGL,yBAAyB,EAQ1B,MAAM,sBAAsB,CAAC;AAa9B,OAAO,EAAE,yBAAyB,EAAE,CAAC;AAmDrC,KAAK,gBAAgB,GAAG,OAAO,GAAG,KAAK,CAAC;AACxC,KAAK,gBAAgB,GAAG,OAAO,GAAG,OAAO,CAAC;AAE1C,UAAU,YAAY;IACpB,YAAY,EAAE,gBAAgB,CAAC;IAC/B,YAAY,EAAE,gBAAgB,CAAC;CAChC;AA0FD,UAAU,oBAAqB,SAAQ,YAAY;IACjD,UAAU,EAAE,MAAM,CAAC;CACpB;AA0CD;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,oBAAoB,GAAG,MAAM,CAEhF;AAkID,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,GAAG,aAAa,CAEvG;AAED,eAAO,MAAM,aAAa,EAAE,aAG3B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import { parse as parseToml } from 'smol-toml';
|
|
|
8
8
|
import { BOUNDED_TEST_KILL_AFTER_MS, BOUNDED_TEST_TIMEOUT_MS } from './bounded-test-policy.js';
|
|
9
9
|
import { attributeCargoWorkspacePackages, CARGO_TEST_COMPILE_TARGET, CARGO_TEST_EXCEPTIONS_SUFFIX, CARGO_TEST_TARGET, cargoPackageTestInputs, cargoTestPackageTargetName, exceptionalTestFilter, listCargoWorkspacePackages, nextestConfigRelPath, } from './cargo-workspace.js';
|
|
10
10
|
import { CARGO_CROSS_LINT_COMMAND, CARGO_CROSS_LINT_TARGET, CARGO_FETCH_COMMAND, CARGO_FETCH_TARGET, CARGO_FROZEN_PREFIX, CARGO_LINT_CLIPPY_COMMAND, cargoFrozen, } from './cross-check-policy.js';
|
|
11
|
+
import { isNonSourceDirectory } from './source-directories.js';
|
|
11
12
|
import { PLATFORM_TARGET_GLOBS } from './workspace-config-policy.js';
|
|
12
13
|
export { CARGO_TEST_COMPILE_TARGET };
|
|
13
14
|
const BUILD_OUTPUT_TARGET_PATTERN = /-(?:js|web|html|css|android|native|napi|bun|wasm)$/;
|
|
@@ -32,7 +33,7 @@ async function javaScriptSourceFiles(directory) {
|
|
|
32
33
|
const files = [];
|
|
33
34
|
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
|
34
35
|
if (entry.isDirectory()) {
|
|
35
|
-
if (entry.name
|
|
36
|
+
if (!isNonSourceDirectory(entry.name)) {
|
|
36
37
|
files.push(...(await javaScriptSourceFiles(join(directory, entry.name))));
|
|
37
38
|
}
|
|
38
39
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package-target-policy.d.ts","sourceRoot":"","sources":["../src/package-target-policy.ts"],"names":[],"mappings":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AG,IAAI,GACtB,MAAM,CAMR;AAgoBD;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,GAAE,0BAA+B,GAAG,aAAa,EAAE,CAsBlH;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,GAAE,0BAA+B,GAAG,OAAO,CA8B1G;AAwJD,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,WAAW,EAAE,MAAM,EACnB,eAAe,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,EACrC,YAAY,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,GACjC,aAAa,EAAE,CAEjB;AAED,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,WAAW,CAAC,MAAM,CAAC,EACnC,OAAO,GAAE;IAAE,eAAe,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAAC,YAAY,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;CAAO,GAC1F,OAAO,CAMT;AAED,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,0BAA+B,GAAG,aAAa,EAAE,CAoBhH;AAED,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,0BAA+B,GAAG,OAAO,CA8BxG"}
|
|
@@ -2,6 +2,7 @@ import { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { getProjects, readJson, updateJson } from 'nx/src/devkit-exports.js';
|
|
4
4
|
import { boundedTestScriptAlias } from './bounded-test-policy.js';
|
|
5
|
+
import { isNonSourceDirectory } from './source-directories.js';
|
|
5
6
|
import { BUILD_OUTPUT_DEPENDENCIES, LINUX_PLATFORM_TARGET_GLOBS, MACOS_PLATFORM_TARGET_GLOBS, } from './workspace-config-policy.js';
|
|
6
7
|
export { BUILD_OUTPUT_DEPENDENCIES, PLATFORM_TARGET_GLOBS } from './workspace-config-policy.js';
|
|
7
8
|
const workspaceDependencyFields = ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies'];
|
|
@@ -446,7 +447,7 @@ function directoryContainsTestFiles(path) {
|
|
|
446
447
|
return false;
|
|
447
448
|
}
|
|
448
449
|
for (const entry of readdirSync(path, { withFileTypes: true })) {
|
|
449
|
-
if (entry.name
|
|
450
|
+
if (isNonSourceDirectory(entry.name)) {
|
|
450
451
|
continue;
|
|
451
452
|
}
|
|
452
453
|
const entryPath = join(path, entry.name);
|
|
@@ -756,7 +757,7 @@ function directoryContainsTestFilesTree(tree, path) {
|
|
|
756
757
|
return false;
|
|
757
758
|
}
|
|
758
759
|
for (const entry of tree.children(path)) {
|
|
759
|
-
if (entry
|
|
760
|
+
if (isNonSourceDirectory(entry)) {
|
|
760
761
|
continue;
|
|
761
762
|
}
|
|
762
763
|
const entryPath = `${path}/${entry}`;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Directories no source walk descends into. Every walker in this plugin runs on
|
|
3
|
+
* project load, so descending into a build output is paid on each graph
|
|
4
|
+
* computation: a `target/` at 50k files or a `dist-test/` left by an old config
|
|
5
|
+
* dominated the load. Anything a build writes is excluded by shape rather than
|
|
6
|
+
* by an enumerated name: every `dist*` variant, cargo's `target`, and any
|
|
7
|
+
* dot-directory (`.runtime`, `.cache`, `.venv`, `.git`, tooling state) — a
|
|
8
|
+
* source tree never starts with a dot.
|
|
9
|
+
*/
|
|
10
|
+
export declare function isNonSourceDirectory(name: string): boolean;
|
|
11
|
+
//# sourceMappingURL=source-directories.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-directories.d.ts","sourceRoot":"","sources":["../src/source-directories.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAW1D"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Directories no source walk descends into. Every walker in this plugin runs on
|
|
3
|
+
* project load, so descending into a build output is paid on each graph
|
|
4
|
+
* computation: a `target/` at 50k files or a `dist-test/` left by an old config
|
|
5
|
+
* dominated the load. Anything a build writes is excluded by shape rather than
|
|
6
|
+
* by an enumerated name: every `dist*` variant, cargo's `target`, and any
|
|
7
|
+
* dot-directory (`.runtime`, `.cache`, `.venv`, `.git`, tooling state) — a
|
|
8
|
+
* source tree never starts with a dot.
|
|
9
|
+
*/
|
|
10
|
+
export function isNonSourceDirectory(name) {
|
|
11
|
+
return (name.startsWith('.') ||
|
|
12
|
+
name === 'node_modules' ||
|
|
13
|
+
name === 'target' ||
|
|
14
|
+
name === 'coverage' ||
|
|
15
|
+
name === 'build' ||
|
|
16
|
+
name === '__pycache__' ||
|
|
17
|
+
name === 'dist' ||
|
|
18
|
+
name.startsWith('dist-'));
|
|
19
|
+
}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
CARGO_LINT_CLIPPY_COMMAND,
|
|
35
35
|
cargoFrozen,
|
|
36
36
|
} from './cross-check-policy.js';
|
|
37
|
+
import { isNonSourceDirectory } from './source-directories.js';
|
|
37
38
|
import { PLATFORM_TARGET_GLOBS } from './workspace-config-policy.js';
|
|
38
39
|
|
|
39
40
|
export { CARGO_TEST_COMPILE_TARGET };
|
|
@@ -61,7 +62,7 @@ async function javaScriptSourceFiles(directory: string): Promise<string[]> {
|
|
|
61
62
|
const files: string[] = [];
|
|
62
63
|
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
|
63
64
|
if (entry.isDirectory()) {
|
|
64
|
-
if (entry.name
|
|
65
|
+
if (!isNonSourceDirectory(entry.name)) {
|
|
65
66
|
files.push(...(await javaScriptSourceFiles(join(directory, entry.name))));
|
|
66
67
|
}
|
|
67
68
|
} else if (entry.isFile() && /\.[cm]?[jt]sx?$/.test(entry.name)) {
|
|
@@ -720,6 +720,22 @@ describe('checkPackageTargetPolicyTree', () => {
|
|
|
720
720
|
expect(issues.filter((i) => i.message.includes('test files require'))).toEqual([]);
|
|
721
721
|
});
|
|
722
722
|
|
|
723
|
+
it('does not read test files out of build output or dot-directories', () => {
|
|
724
|
+
addProject(tree, 'lib', 'packages/lib');
|
|
725
|
+
writeJsonFile(tree, 'packages/lib/package.json', {
|
|
726
|
+
name: '@scope/lib',
|
|
727
|
+
nx: { name: 'lib' },
|
|
728
|
+
});
|
|
729
|
+
// Stale emit, cargo's tree and a runtime cache all carry test-shaped files; none is a
|
|
730
|
+
// source the package must wire a test target for.
|
|
731
|
+
tree.write('packages/lib/dist-test/example.test.js', 'export {};\n');
|
|
732
|
+
tree.write('packages/lib/target/debug/build/example.test.ts', 'export {};\n');
|
|
733
|
+
tree.write('packages/lib/.runtime/cache-pin/test/example.test.ts', 'export {};\n');
|
|
734
|
+
|
|
735
|
+
const issues = checkPackageTargetPolicyTree(tree);
|
|
736
|
+
expect(issues.filter((i) => i.message.includes('test files require'))).toEqual([]);
|
|
737
|
+
});
|
|
738
|
+
|
|
723
739
|
it('accepts wildcard aggregate build dependencies', () => {
|
|
724
740
|
addProject(tree, 'lib', 'packages/lib');
|
|
725
741
|
writeJsonFile(tree, 'packages/lib/package.json', {
|
|
@@ -4,6 +4,7 @@ import { join } from 'node:path';
|
|
|
4
4
|
import { getProjects, readJson, type Tree, updateJson } from 'nx/src/devkit-exports.js';
|
|
5
5
|
|
|
6
6
|
import { boundedTestScriptAlias } from './bounded-test-policy.js';
|
|
7
|
+
import { isNonSourceDirectory } from './source-directories.js';
|
|
7
8
|
import {
|
|
8
9
|
BUILD_OUTPUT_DEPENDENCIES,
|
|
9
10
|
LINUX_PLATFORM_TARGET_GLOBS,
|
|
@@ -594,7 +595,7 @@ function directoryContainsTestFiles(path: string): boolean {
|
|
|
594
595
|
return false;
|
|
595
596
|
}
|
|
596
597
|
for (const entry of readdirSync(path, { withFileTypes: true })) {
|
|
597
|
-
if (entry.name
|
|
598
|
+
if (isNonSourceDirectory(entry.name)) {
|
|
598
599
|
continue;
|
|
599
600
|
}
|
|
600
601
|
const entryPath = join(path, entry.name);
|
|
@@ -956,7 +957,7 @@ function directoryContainsTestFilesTree(tree: Tree, path: string): boolean {
|
|
|
956
957
|
return false;
|
|
957
958
|
}
|
|
958
959
|
for (const entry of tree.children(path)) {
|
|
959
|
-
if (entry
|
|
960
|
+
if (isNonSourceDirectory(entry)) {
|
|
960
961
|
continue;
|
|
961
962
|
}
|
|
962
963
|
const entryPath = `${path}/${entry}`;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Directories no source walk descends into. Every walker in this plugin runs on
|
|
3
|
+
* project load, so descending into a build output is paid on each graph
|
|
4
|
+
* computation: a `target/` at 50k files or a `dist-test/` left by an old config
|
|
5
|
+
* dominated the load. Anything a build writes is excluded by shape rather than
|
|
6
|
+
* by an enumerated name: every `dist*` variant, cargo's `target`, and any
|
|
7
|
+
* dot-directory (`.runtime`, `.cache`, `.venv`, `.git`, tooling state) — a
|
|
8
|
+
* source tree never starts with a dot.
|
|
9
|
+
*/
|
|
10
|
+
export function isNonSourceDirectory(name: string): boolean {
|
|
11
|
+
return (
|
|
12
|
+
name.startsWith('.') ||
|
|
13
|
+
name === 'node_modules' ||
|
|
14
|
+
name === 'target' ||
|
|
15
|
+
name === 'coverage' ||
|
|
16
|
+
name === 'build' ||
|
|
17
|
+
name === '__pycache__' ||
|
|
18
|
+
name === 'dist' ||
|
|
19
|
+
name.startsWith('dist-')
|
|
20
|
+
);
|
|
21
|
+
}
|