From 67c4b9755eef95ad502fa5ceecf6c68bc6c2f50d Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Tue, 13 Aug 2024 19:34:42 -0700 Subject: [PATCH] chore(deps): update rules_lint --- BUILD.bazel | 2 +- MODULE.bazel | 2 +- WORKSPACE.bzlmod | 8 - e2e/test/3p_deps.bats | 50 +++--- e2e/test/diagnostics.bats | 97 ++++++----- e2e/test/emit_cache.bats | 35 ++-- e2e/test/invalidation.bats | 233 +++++++++++++------------- e2e/test/isolated_modules.bats | 79 +++++---- e2e/test/source_maps.bats | 96 ++++++----- e2e/test/strategy.bats | 35 ++-- e2e/test/third_party_deps.bats | 158 +++++++++-------- e2e/test/tracing_and_performance.bats | 23 ++- tools/BUILD.bazel | 30 ---- tools/format/BUILD.bazel | 14 ++ 14 files changed, 413 insertions(+), 449 deletions(-) delete mode 100644 tools/BUILD.bazel create mode 100644 tools/format/BUILD.bazel diff --git a/BUILD.bazel b/BUILD.bazel index e58dffbe..740ab566 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -30,7 +30,7 @@ buildifier( alias( name = "format", - actual = "//tools:format", + actual = "//tools/format", ) bzl_library( diff --git a/MODULE.bazel b/MODULE.bazel index f442b77b..9d123b75 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -21,7 +21,7 @@ bazel_dep(name = "rules_proto", version = "6.0.0") ####### Dev dependencies ######## -bazel_dep(name = "aspect_rules_lint", version = "0.9.1", dev_dependency = True) +bazel_dep(name = "aspect_rules_lint", version = "1.0.0-rc8", dev_dependency = True) bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.5.0", dev_dependency = True) bazel_dep(name = "buildifier_prebuilt", version = "6.4.0", dev_dependency = True) bazel_dep(name = "gazelle", version = "0.36.0", dev_dependency = True, repo_name = "bazel_gazelle") diff --git a/WORKSPACE.bzlmod b/WORKSPACE.bzlmod index 14dafc13..cd7b79ce 100644 --- a/WORKSPACE.bzlmod +++ b/WORKSPACE.bzlmod @@ -3,14 +3,6 @@ load("//.github/workflows:deps.bzl", "aspect_workflows_github_actions_deps") aspect_workflows_github_actions_deps() -# TODO: rules_lint doesn't have a way to bring deps in under bzlmod -load( - "@aspect_rules_lint//format:repositories.bzl", - "fetch_shfmt", -) - -fetch_shfmt() - # Needed for stardoc to compile from Java sources http_jar( name = "protobuf-java", diff --git a/e2e/test/3p_deps.bats b/e2e/test/3p_deps.bats index fbb32680..ebf32d36 100644 --- a/e2e/test/3p_deps.bats +++ b/e2e/test/3p_deps.bats @@ -1,41 +1,41 @@ load "common.bats" setup() { - cd $BATS_FILE_TMPDIR + cd $BATS_FILE_TMPDIR } teardown() { - bazel shutdown - rm -rf $BATS_FILE_TMPDIR/* + bazel shutdown + rm -rf $BATS_FILE_TMPDIR/* } @test 'should handle 3p dependency upgrade and downgrade gracefully' { - run pnpm add @nestjs/core@9.2.0 @nestjs/common@9.2.0 rxjs@7.1.0 @types/node@18.11.9 --lockfile-only + run pnpm add @nestjs/core@9.2.0 @nestjs/common@9.2.0 rxjs@7.1.0 @types/node@18.11.9 --lockfile-only - workspace --npm-translate-lock - tsconfig + workspace --npm-translate-lock + tsconfig - echo 'export * as core from "@nestjs/core"' > source.ts - echo 'console.log("test")' >> source.ts + echo 'export * as core from "@nestjs/core"' >source.ts + echo 'console.log("test")' >>source.ts - ts_project -l -s "source.ts" -d ":node_modules/@types/node" -d ":node_modules/@nestjs/core" -d ":node_modules/@nestjs/common" - run bazel build :foo - assert_success - refute_output -p "error" "@nestjs/core" "@types/node" + ts_project -l -s "source.ts" -d ":node_modules/@types/node" -d ":node_modules/@nestjs/core" -d ":node_modules/@nestjs/common" + run bazel build :foo + assert_success + refute_output -p "error" "@nestjs/core" "@types/node" - # upgrade: @nestjs/core from 9.2.0 to 9.2.1 - # dowgrade: @types/node from 18.11.9 to 18.6.1 - run pnpm add @nestjs/core@9.2.1 @types/node@18.6.1 --lockfile-only + # upgrade: @nestjs/core from 9.2.0 to 9.2.1 + # dowgrade: @types/node from 18.11.9 to 18.6.1 + run pnpm add @nestjs/core@9.2.1 @types/node@18.6.1 --lockfile-only - run bazel build :foo - assert_failure - assert_output -p "error TS2403: Subsequent variable declarations must have the same type. Variable 'AbortSignal' must be of type" + run bazel build :foo + assert_failure + assert_output -p "error TS2403: Subsequent variable declarations must have the same type. Variable 'AbortSignal' must be of type" - # dowgrade: @nestjs/core from 9.2.1 to 9.2.0 - # upgrade: @types/node from 18.6.1 to 18.11.9 - run pnpm add @nestjs/core@9.2.0 @types/node@18.11.9 --lockfile-only + # dowgrade: @nestjs/core from 9.2.1 to 9.2.0 + # upgrade: @types/node from 18.6.1 to 18.11.9 + run pnpm add @nestjs/core@9.2.0 @types/node@18.11.9 --lockfile-only - run bazel build :foo - assert_success - refute_output -p "error" "@nestjs/core" "@types/node" -} \ No newline at end of file + run bazel build :foo + assert_success + refute_output -p "error" "@nestjs/core" "@types/node" +} diff --git a/e2e/test/diagnostics.bats b/e2e/test/diagnostics.bats index 53b87093..907518ae 100644 --- a/e2e/test/diagnostics.bats +++ b/e2e/test/diagnostics.bats @@ -1,70 +1,69 @@ load "common.bats" setup() { - cd $BATS_FILE_TMPDIR + cd $BATS_FILE_TMPDIR } teardown() { - bazel shutdown - rm -rf $BATS_FILE_TMPDIR/* + bazel shutdown + rm -rf $BATS_FILE_TMPDIR/* } @test 'build a target that will never succeed' { - workspace - ts_project --src "source.ts" - tsconfig - echo 'const t: string = 1' > source.ts - run bazel build :foo - assert_failure - assert_output -p "source.ts(1,7): error TS2322: Type 'number' is not assignable to type 'string'" "FAILED: Build did NOT complete successfully" + workspace + ts_project --src "source.ts" + tsconfig + echo 'const t: string = 1' >source.ts + run bazel build :foo + assert_failure + assert_output -p "source.ts(1,7): error TS2322: Type 'number' is not assignable to type 'string'" "FAILED: Build did NOT complete successfully" } - @test 'should stop reporting diagnostics' { - workspace - ts_project --src "source.ts" - tsconfig - echo 'const t: string;' > source.ts - run bazel build :foo - assert_failure - assert_output -p "source.ts(1,7): error TS1155: 'const' declarations must be initialized." + workspace + ts_project --src "source.ts" + tsconfig + echo 'const t: string;' >source.ts + run bazel build :foo + assert_failure + assert_output -p "source.ts(1,7): error TS1155: 'const' declarations must be initialized." - echo 'const t: string = "";' > source.ts - run bazel build :foo - assert_success - refute_output -p "error" + echo 'const t: string = "";' >source.ts + run bazel build :foo + assert_success + refute_output -p "error" } @test 'should stop reporting diagnostics for removed srcs' { - workspace - ts_project --src "source.ts" --src "to_be_removed.ts" - tsconfig - echo 'let t: string;' > source.ts - echo 'const t2: string;' > to_be_removed.ts - - run bazel build :foo - assert_failure - assert_output -p "to_be_removed.ts(1,7): error TS1155: 'const' declarations must be initialized." + workspace + ts_project --src "source.ts" --src "to_be_removed.ts" + tsconfig + echo 'let t: string;' >source.ts + echo 'const t2: string;' >to_be_removed.ts + + run bazel build :foo + assert_failure + assert_output -p "to_be_removed.ts(1,7): error TS1155: 'const' declarations must be initialized." - rm to_be_removed.ts - ts_project --src "source.ts" - run bazel build :foo - assert_success - refute_output -p "error" + rm to_be_removed.ts + ts_project --src "source.ts" + run bazel build :foo + assert_success + refute_output -p "error" } @test 'tsconfig changes should emit new errors' { - workspace - ts_project --src "source.ts" - tsconfig - echo 'export function t(a) { return typeof a != "string" }' > source.ts - - run bazel build :foo - assert_success - refute_output -p "error" + workspace + ts_project --src "source.ts" + tsconfig + echo 'export function t(a) { return typeof a != "string" }' >source.ts - tsconfig --no-implicit-any - run bazel build :foo - assert_failure - assert_output -p "source.ts(1,19): error TS7006: Parameter 'a' implicitly has an 'any' type." -} \ No newline at end of file + run bazel build :foo + assert_success + refute_output -p "error" + + tsconfig --no-implicit-any + run bazel build :foo + assert_failure + assert_output -p "source.ts(1,19): error TS7006: Parameter 'a' implicitly has an 'any' type." +} diff --git a/e2e/test/emit_cache.bats b/e2e/test/emit_cache.bats index 4876534d..4b952f87 100644 --- a/e2e/test/emit_cache.bats +++ b/e2e/test/emit_cache.bats @@ -1,31 +1,30 @@ load "common.bats" setup() { - cd $BATS_FILE_TMPDIR + cd $BATS_FILE_TMPDIR } teardown() { - bazel shutdown - rm -rf $BATS_FILE_TMPDIR/* + bazel shutdown + rm -rf $BATS_FILE_TMPDIR/* } - @test 'should emit .tsbuildinfo' { - workspace - mkdir ./a ./b + workspace + mkdir ./a ./b - echo "export function a(): string { return 'a'; }" > ./a/index.ts - tsconfig --path ./a --declaration --composite - ts_project --path ./a --name a --src "index.ts" --declaration --composite + echo "export function a(): string { return 'a'; }" >./a/index.ts + tsconfig --path ./a --declaration --composite + ts_project --path ./a --name a --src "index.ts" --declaration --composite - echo "export function b(): string { return 'b'; }" > ./b/index.ts - tsconfig --path ./b --declaration --composite - ts_project --path ./b --name b --src "index.ts" --declaration --composite + echo "export function b(): string { return 'b'; }" >./b/index.ts + tsconfig --path ./b --declaration --composite + ts_project --path ./b --name b --src "index.ts" --declaration --composite - echo "export * from './a'; export * from './b'" > index.ts - tsconfig --declaration --composite + echo "export * from './a'; export * from './b'" >index.ts + tsconfig --declaration --composite - ts_project --src "index.ts" --dep "//a" --dep "//b" --declaration --composite - run bazel build :foo - assert_success -} \ No newline at end of file + ts_project --src "index.ts" --dep "//a" --dep "//b" --declaration --composite + run bazel build :foo + assert_success +} diff --git a/e2e/test/invalidation.bats b/e2e/test/invalidation.bats index c66678d6..9a8a172b 100644 --- a/e2e/test/invalidation.bats +++ b/e2e/test/invalidation.bats @@ -1,143 +1,140 @@ load "common.bats" - - setup() { - cd $BATS_FILE_TMPDIR + cd $BATS_FILE_TMPDIR } teardown() { - bazel shutdown - rm -rf $BATS_FILE_TMPDIR/* + bazel shutdown + rm -rf $BATS_FILE_TMPDIR/* } # bats test_tags=synthetic_outdir @test 'should invalidate transitive sources that reside in a subpackage.' { - mkdir -p ./apps/triad/pivot - mkdir -p ./apps/triad/vibe - workspace - - # js_library pivot - echo "export declare function name(): string;" > ./apps/triad/pivot/index.d.ts - echo "module.exports = { name: function () { return 'pivot'; } };" > ./apps/triad/pivot/index.js - js_library --path ./apps/triad/pivot --name pivot --src "index.d.ts" --src "index.js" - - # ts_project vibe - echo "export function name(): string { return 'vibe'; }" > ./apps/triad/vibe/index.ts - tsconfig --path ./apps/triad/vibe --declaration - ts_project --path ./apps/triad/vibe --name vibe --declaration --src "index.ts" - - # ts_project triad - cat > ./apps/triad/main.ts <./apps/triad/pivot/index.d.ts + echo "module.exports = { name: function () { return 'pivot'; } };" >./apps/triad/pivot/index.js + js_library --path ./apps/triad/pivot --name pivot --src "index.d.ts" --src "index.js" + + # ts_project vibe + echo "export function name(): string { return 'vibe'; }" >./apps/triad/vibe/index.ts + tsconfig --path ./apps/triad/vibe --declaration + ts_project --path ./apps/triad/vibe --name vibe --declaration --src "index.ts" + + # ts_project triad + cat >./apps/triad/main.ts < ./feature1/index.ts - tsconfig --path ./feature1 --declaration - ts_project --path ./feature1 --name feature1 --declaration --src "index.ts" - - echo "export function name2(): string { return 'feature2'; }" > ./feature2/index.ts - tsconfig --path ./feature2 --declaration - ts_project --path ./feature2 --name feature2 --declaration --src "index.ts" - - echo "export * from './feature1'; export * from './feature2'" > index.ts - tsconfig - - ts_project --src "index.ts" - run bazel build :foo - assert_failure - assert_output -p "index.ts(1,15): error TS2307: Cannot find module './feature1' or its corresponding type declarations." - assert_output -p "index.ts(1,43): error TS2307: Cannot find module './feature2' or its corresponding type declarations." - - ts_project --src "index.ts" --dep "//feature1" - run bazel build :foo - assert_failure - refute_output -p "index.ts(1,15): error TS2307: Cannot find module './feature1' or its corresponding type declarations." - assert_output -p "index.ts(1,43): error TS2307: Cannot find module './feature2' or its corresponding type declarations." - - ts_project --src "index.ts" --dep "//feature2" - run bazel build :foo - assert_failure - assert_output -p "index.ts(1,15): error TS2307: Cannot find module './feature1' or its corresponding type declarations." - refute_output -p "index.ts(1,43): error TS2307: Cannot find module './feature2' or its corresponding type declarations." - - ts_project --src "index.ts" --dep "//feature1" --dep "//feature2" - - run bazel build :foo - assert_success + workspace + mkdir ./feature1 ./feature2 + + echo "export function name1(): string { return 'feature1'; }" >./feature1/index.ts + tsconfig --path ./feature1 --declaration + ts_project --path ./feature1 --name feature1 --declaration --src "index.ts" + + echo "export function name2(): string { return 'feature2'; }" >./feature2/index.ts + tsconfig --path ./feature2 --declaration + ts_project --path ./feature2 --name feature2 --declaration --src "index.ts" + + echo "export * from './feature1'; export * from './feature2'" >index.ts + tsconfig + + ts_project --src "index.ts" + run bazel build :foo + assert_failure + assert_output -p "index.ts(1,15): error TS2307: Cannot find module './feature1' or its corresponding type declarations." + assert_output -p "index.ts(1,43): error TS2307: Cannot find module './feature2' or its corresponding type declarations." + + ts_project --src "index.ts" --dep "//feature1" + run bazel build :foo + assert_failure + refute_output -p "index.ts(1,15): error TS2307: Cannot find module './feature1' or its corresponding type declarations." + assert_output -p "index.ts(1,43): error TS2307: Cannot find module './feature2' or its corresponding type declarations." + + ts_project --src "index.ts" --dep "//feature2" + run bazel build :foo + assert_failure + assert_output -p "index.ts(1,15): error TS2307: Cannot find module './feature1' or its corresponding type declarations." + refute_output -p "index.ts(1,43): error TS2307: Cannot find module './feature2' or its corresponding type declarations." + + ts_project --src "index.ts" --dep "//feature1" --dep "//feature2" + + run bazel build :foo + assert_success } @test 'should not read a file thats been removed from srcs' { - workspace - tsconfig - echo "const t = true;" > default.ts - - for i in $(seq 0 10) - do - echo "const a = $i" > "source_$i.ts" - ts_project --src default.ts --src "source_$i.ts" - run bazel build :foo - assert_success - - rm "source_$i.ts" - ts_project --src default.ts - run bazel build :foo - assert_success - done + workspace + tsconfig + echo "const t = true;" >default.ts + + for i in $(seq 0 10); do + echo "const a = $i" >"source_$i.ts" + ts_project --src default.ts --src "source_$i.ts" + run bazel build :foo + assert_success + + rm "source_$i.ts" + ts_project --src default.ts + run bazel build :foo + assert_success + done } @test 'should handle tsconfig change, file addition and removal in one batch' { - workspace - tsconfig - echo "export class T{ get t(){ return 'test' } }" > default.ts - ts_project --src default.ts - - run bazel build :foo - assert_success - run cat bazel-bin/default.js - assert_output -p "get t() { return 'test'; }" - - tsconfig --target ES5 - rm default.ts - echo "export class T{ get t(){ return 'test' } }" > new.ts - - ts_project --src new.ts - run bazel build :foo - assert_success - run cat bazel-bin/new.js - refute_output -p "get t() { return 'test'; }" 'var T = /** @class */ (function () {" "Object.defineProperty(T.prototype, "t", {' -} \ No newline at end of file + workspace + tsconfig + echo "export class T{ get t(){ return 'test' } }" >default.ts + ts_project --src default.ts + + run bazel build :foo + assert_success + run cat bazel-bin/default.js + assert_output -p "get t() { return 'test'; }" + + tsconfig --target ES5 + rm default.ts + echo "export class T{ get t(){ return 'test' } }" >new.ts + + ts_project --src new.ts + run bazel build :foo + assert_success + run cat bazel-bin/new.js + refute_output -p "get t() { return 'test'; }" 'var T = /** @class */ (function () {" "Object.defineProperty(T.prototype, "t", {' +} diff --git a/e2e/test/isolated_modules.bats b/e2e/test/isolated_modules.bats index ab10bed6..9ddc7f95 100644 --- a/e2e/test/isolated_modules.bats +++ b/e2e/test/isolated_modules.bats @@ -1,52 +1,51 @@ load "common.bats" setup() { - cd $BATS_FILE_TMPDIR + cd $BATS_FILE_TMPDIR } teardown() { - bazel shutdown - rm -rf $BATS_FILE_TMPDIR/* + bazel shutdown + rm -rf $BATS_FILE_TMPDIR/* } @test 'should report errors' { - workspace - tsconfig - - echo 'function fn() {}' > nonmodule.ts - echo 'export type test = string' > lib.ts - echo 'import {test} from "./lib"; export {test}' > source.ts - ts_project -s "source.ts" -s "lib.ts" -s "nonmodule.ts" - - run bazel build :foo - assert_success - refute_output -p "error" - - tsconfig --isolated-modules - run bazel build :foo - assert_failure - assert_output -p "nonmodule.ts(1,1): error TS1208: 'nonmodule.ts' cannot be compiled under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module." + workspace + tsconfig + + echo 'function fn() {}' >nonmodule.ts + echo 'export type test = string' >lib.ts + echo 'import {test} from "./lib"; export {test}' >source.ts + ts_project -s "source.ts" -s "lib.ts" -s "nonmodule.ts" + + run bazel build :foo + assert_success + refute_output -p "error" + + tsconfig --isolated-modules + run bazel build :foo + assert_failure + assert_output -p "nonmodule.ts(1,1): error TS1208: 'nonmodule.ts' cannot be compiled under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module." } - @test 'should report errors for 3p deps' { - run pnpm add @types/node@18.11.9 --lockfile-only - - workspace --npm-translate-lock - tsconfig --extended-diagnostics - - echo 'import {BigIntStats} from "node:fs"; export {BigIntStats}' > source.ts - ts_project -l -s "source.ts" -d ":node_modules/@types/node" - - run bazel build :foo - assert_success - refute_output -p "error" - - tsconfig --isolated-modules --extended-diagnostics - echo " " >> source.ts # TODO: figure out why the case above works but not this one. - run bazel build :foo - - assert_failure - assert_output -p "source.ts(1,46): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'." - -} \ No newline at end of file + run pnpm add @types/node@18.11.9 --lockfile-only + + workspace --npm-translate-lock + tsconfig --extended-diagnostics + + echo 'import {BigIntStats} from "node:fs"; export {BigIntStats}' >source.ts + ts_project -l -s "source.ts" -d ":node_modules/@types/node" + + run bazel build :foo + assert_success + refute_output -p "error" + + tsconfig --isolated-modules --extended-diagnostics + echo " " >>source.ts # TODO: figure out why the case above works but not this one. + run bazel build :foo + + assert_failure + assert_output -p "source.ts(1,46): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'." + +} diff --git a/e2e/test/source_maps.bats b/e2e/test/source_maps.bats index c0df6e31..2caa5d9f 100644 --- a/e2e/test/source_maps.bats +++ b/e2e/test/source_maps.bats @@ -1,71 +1,69 @@ load "common.bats" setup() { - cd $BATS_FILE_TMPDIR + cd $BATS_FILE_TMPDIR } teardown() { - bazel shutdown - rm -rf $BATS_FILE_TMPDIR/* + bazel shutdown + rm -rf $BATS_FILE_TMPDIR/* } @test 'should emit sourcemaps correctly at root package' { - workspace - tsconfig --source-map - ts_project --src "source.ts" --source-map - echo 'const t: string = "sourcemaps";' > source.ts - run bazel build :foo - assert_success - run cat bazel-bin/source.js.map - assert_success - assert_output -p '{"version":3,"file":"source.js","sourceRoot":"","sources":["source.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,GAAW,YAAY,CAAC"}' + workspace + tsconfig --source-map + ts_project --src "source.ts" --source-map + echo 'const t: string = "sourcemaps";' >source.ts + run bazel build :foo + assert_success + run cat bazel-bin/source.js.map + assert_success + assert_output -p '{"version":3,"file":"source.js","sourceRoot":"","sources":["source.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,GAAW,YAAY,CAAC"}' } @test 'should emit sourcemaps correctly in a subpackage' { - workspace - mkdir subpkg - tsconfig --path "./subpkg" --source-map - ts_project --path "./subpkg" --src "source.ts" --source-map - echo 'const t: string = "sourcemaps";' > ./subpkg/source.ts - run bazel build //subpkg:foo - assert_success - run cat bazel-bin/subpkg/source.js.map - assert_success - assert_output -p '{"version":3,"file":"source.js","sourceRoot":"","sources":["source.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,GAAW,YAAY,CAAC"}' + workspace + mkdir subpkg + tsconfig --path "./subpkg" --source-map + ts_project --path "./subpkg" --src "source.ts" --source-map + echo 'const t: string = "sourcemaps";' >./subpkg/source.ts + run bazel build //subpkg:foo + assert_success + run cat bazel-bin/subpkg/source.js.map + assert_success + assert_output -p '{"version":3,"file":"source.js","sourceRoot":"","sources":["source.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,GAAW,YAAY,CAAC"}' } @test 'should emit sourcemaps correctly with outdir' { - workspace - tsconfig --source-map - ts_project --src "source.ts" --source-map --out_dir "outdir" - echo 'const t: string = "sourcemaps";' > source.ts - run bazel build :foo - assert_success - run cat bazel-bin/outdir/source.js.map - assert_success - assert_output -p '{"version":3,"file":"source.js","sourceRoot":"","sources":["../source.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,GAAW,YAAY,CAAC"}' + workspace + tsconfig --source-map + ts_project --src "source.ts" --source-map --out_dir "outdir" + echo 'const t: string = "sourcemaps";' >source.ts + run bazel build :foo + assert_success + run cat bazel-bin/outdir/source.js.map + assert_success + assert_output -p '{"version":3,"file":"source.js","sourceRoot":"","sources":["../source.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,GAAW,YAAY,CAAC"}' } @test 'should enable source maps in warm worker' { - workspace + workspace - tsconfig - ts_project --src "sourcemap.ts" - echo 'const t: string = "sourcemaps";' > sourcemap.ts - run bazel build :foo - assert_success + tsconfig + ts_project --src "sourcemap.ts" + echo 'const t: string = "sourcemaps";' >sourcemap.ts + run bazel build :foo + assert_success - run stat bazel-bin/sourcemap.js.map - assert_failure - assert_output -p "No such file or directory" + run stat bazel-bin/sourcemap.js.map + assert_failure + assert_output -p "No such file or directory" - - tsconfig --source-map - ts_project --src "sourcemap.ts" --source-map - echo 'const t: string = "sourcemaps";' > sourcemap.ts - run bazel build :foo - assert_success - run cat bazel-bin/sourcemap.js.map - assert_output -p '{"version":3,"file":"sourcemap.js","sourceRoot":"","sources":["sourcemap.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,GAAW,YAAY,CAAC"}' + tsconfig --source-map + ts_project --src "sourcemap.ts" --source-map + echo 'const t: string = "sourcemaps";' >sourcemap.ts + run bazel build :foo + assert_success + run cat bazel-bin/sourcemap.js.map + assert_output -p '{"version":3,"file":"sourcemap.js","sourceRoot":"","sources":["sourcemap.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,GAAW,YAAY,CAAC"}' } - diff --git a/e2e/test/strategy.bats b/e2e/test/strategy.bats index 04ff285b..a59d5996 100644 --- a/e2e/test/strategy.bats +++ b/e2e/test/strategy.bats @@ -1,33 +1,32 @@ load "common.bats" setup() { - cd $BATS_FILE_TMPDIR + cd $BATS_FILE_TMPDIR } teardown() { - bazel shutdown - rm -rf $BATS_FILE_TMPDIR/* + bazel shutdown + rm -rf $BATS_FILE_TMPDIR/* } @test 'should build successfully and not print the error message with --strategy=sandboxed' { - workspace - tsconfig + workspace + tsconfig - ts_project --src "source.ts" - echo 'const t: string = "sandboxed";' > source.ts - run bazel build :foo --strategy=TsProject=sandboxed - assert_success - refute_output -p "WARNING: Running" "TsProject" "as a standalone process" "From Compiling TypeScript project" + ts_project --src "source.ts" + echo 'const t: string = "sandboxed";' >source.ts + run bazel build :foo --strategy=TsProject=sandboxed + assert_success + refute_output -p "WARNING: Running" "TsProject" "as a standalone process" "From Compiling TypeScript project" } - @test 'should build successfully and print the error message with --strategy=local' { - workspace - tsconfig + workspace + tsconfig - ts_project --src "source.ts" - echo 'const t: string = "local";' > source.ts - run bazel build :foo --strategy=TsProject=local --@aspect_rules_ts//ts:supports_workers - assert_success - assert_output -p "WARNING: Running" "TsProject" "as a standalone process" "From Compiling TypeScript project" + ts_project --src "source.ts" + echo 'const t: string = "local";' >source.ts + run bazel build :foo --strategy=TsProject=local --@aspect_rules_ts//ts:supports_workers + assert_success + assert_output -p "WARNING: Running" "TsProject" "as a standalone process" "From Compiling TypeScript project" } diff --git a/e2e/test/third_party_deps.bats b/e2e/test/third_party_deps.bats index 12468372..78394bce 100644 --- a/e2e/test/third_party_deps.bats +++ b/e2e/test/third_party_deps.bats @@ -1,101 +1,99 @@ load "common.bats" setup() { - cd $BATS_FILE_TMPDIR + cd $BATS_FILE_TMPDIR } teardown() { - bazel shutdown - rm -rf $BATS_FILE_TMPDIR/* + bazel shutdown + rm -rf $BATS_FILE_TMPDIR/* } @test 'should report missing third-party deps' { - run pnpm add @nestjs/core@9.0.8 @nestjs/common@9.0.8 rxjs@7.1.0 @types/node@18.11.9 --lockfile-only + run pnpm add @nestjs/core@9.0.8 @nestjs/common@9.0.8 rxjs@7.1.0 @types/node@18.11.9 --lockfile-only - workspace --npm-translate-lock - tsconfig + workspace --npm-translate-lock + tsconfig - echo 'export * as core from "@nestjs/core"' > source.ts + echo 'export * as core from "@nestjs/core"' >source.ts - ts_project -l -s "source.ts" -d ":node_modules/@types/node" - run bazel build :foo - assert_failure - assert_output -p "source.ts(1,23): error TS2307: Cannot find module '@nestjs/core' or its corresponding type declarations." + ts_project -l -s "source.ts" -d ":node_modules/@types/node" + run bazel build :foo + assert_failure + assert_output -p "source.ts(1,23): error TS2307: Cannot find module '@nestjs/core' or its corresponding type declarations." - ts_project -l -s "source.ts" -d ":node_modules/@nestjs/core" -d ":node_modules/@types/node" - run bazel build :foo - assert_success + ts_project -l -s "source.ts" -d ":node_modules/@nestjs/core" -d ":node_modules/@types/node" + run bazel build :foo + assert_success - ts_project -l -s "source.ts" -d ":node_modules/@nestjs/core" - run bazel build :foo - assert_failure - assert_output -p "error TS2688: Cannot find type definition file for 'node'." "error TS2503: Cannot find namespace 'NodeJS'." + ts_project -l -s "source.ts" -d ":node_modules/@nestjs/core" + run bazel build :foo + assert_failure + assert_output -p "error TS2688: Cannot find type definition file for 'node'." "error TS2503: Cannot find namespace 'NodeJS'." - ts_project -l -s "source.ts" -d ":node_modules/@nestjs/core" -d ":node_modules/@types/node" - run bazel build :foo - assert_success + ts_project -l -s "source.ts" -d ":node_modules/@nestjs/core" -d ":node_modules/@types/node" + run bazel build :foo + assert_success } @test 'should report @types/ pair errors correctly' { - run pnpm add @types/debug@4.1.7 debug@4.3.4 --lockfile-only - - workspace --npm-translate-lock - tsconfig --extended-diagnostics --trace-resolution - - echo 'import * as debug from "debug";' > source.ts - echo 'debug.log("test");' >> source.ts - - ts_project -l -s "source.ts" -d ":node_modules/@types/debug" - run bazel build :foo - assert_success - refute_output -p "Cannot find module 'debug' or its corresponding type declarations." - - ts_project -l -s "source.ts" -d ":node_modules/debug" - run bazel build :foo - assert_success - refute_output -p "Cannot find module 'debug' or its corresponding type declarations." - - # TODO: !!!!A TYPESCRIPT BUG!!!. we correctly report changes for modules but tsc doesn't calculate diagnostics for sources eventhough modules don't exist anymore. - # think this as if you'd have to do cmd+s to make tsc --watch to reconsider the decision. - echo " " >> source.ts - ts_project -l -s "source.ts" - run bazel build :foo - assert_failure - assert_output -p "source.ts(1,24): error TS2307: Cannot find module 'debug' or its corresponding type declarations." + run pnpm add @types/debug@4.1.7 debug@4.3.4 --lockfile-only + + workspace --npm-translate-lock + tsconfig --extended-diagnostics --trace-resolution + + echo 'import * as debug from "debug";' >source.ts + echo 'debug.log("test");' >>source.ts + + ts_project -l -s "source.ts" -d ":node_modules/@types/debug" + run bazel build :foo + assert_success + refute_output -p "Cannot find module 'debug' or its corresponding type declarations." + + ts_project -l -s "source.ts" -d ":node_modules/debug" + run bazel build :foo + assert_success + refute_output -p "Cannot find module 'debug' or its corresponding type declarations." + + # TODO: !!!!A TYPESCRIPT BUG!!!. we correctly report changes for modules but tsc doesn't calculate diagnostics for sources eventhough modules don't exist anymore. + # think this as if you'd have to do cmd+s to make tsc --watch to reconsider the decision. + echo " " >>source.ts + ts_project -l -s "source.ts" + run bazel build :foo + assert_failure + assert_output -p "source.ts(1,24): error TS2307: Cannot find module 'debug' or its corresponding type declarations." } - @test 'should report new transitive deps correctly and tsc should not ignore it' { - workspace --npm-translate-lock --noconvenience-symlinks # bazel- symlinks makes pnpm hang - tsconfig --extended-diagnostics --trace-resolution - - mkdir -p ./features/cool ./features/notcool - - echo "export declare function cool(): import('@feature/notcool').not" > ./features/cool/index.d.ts - js_library -l --path ./features/cool --name cool_lib --src "index.d.ts" - npm_package --path ./features/cool --name cool --src ":cool_lib" - echo '{"name": "@feature/cool"}' > ./features/cool/package.json - - echo "export declare type not = string" > ./features/notcool/index.d.ts - js_library -l --path ./features/notcool --name notcool_lib --src "index.d.ts" - npm_package --path ./features/notcool --name notcool --src ":notcool_lib" - echo '{"name": "@feature/notcool"}' > ./features/notcool/package.json - - echo '-packages: ["features/cool", "features/notcool"]' > pnpm-workspace.yaml - echo '{"dependencies":{"@feature/cool": "workspace:*", "@types/node": "*"}}' > package.json - run pnpm install --lockfile-only - assert_success - - echo "import {cool} from '@feature/cool'; export const t: number = cool()" > source.ts - ts_project -l -s "source.ts" -d ":node_modules/@feature/cool" - run bazel build :foo --@aspect_rules_ts//ts:supports_workers - assert_failure - assert_output -p "node_modules/.aspect_rules_js/@feature+cool@0.0.0/node_modules/@feature/cool/index.d.ts(1,40): error TS2307: Cannot find module '@feature/notcool' or its corresponding type declarations." - - - echo '{"dependencies":{"@feature/cool": "workspace:*", "@types/node": "*"}, "pnpm": {"packageExtensions": {"@feature/cool": {"dependencies": {"@feature/notcool": "workspace:*"}}}}}' > package.json - run pnpm install --lockfile-only - assert_success - run bazel build :foo --@aspect_rules_ts//ts:supports_workers - assert_success -} \ No newline at end of file + workspace --npm-translate-lock --noconvenience-symlinks # bazel- symlinks makes pnpm hang + tsconfig --extended-diagnostics --trace-resolution + + mkdir -p ./features/cool ./features/notcool + + echo "export declare function cool(): import('@feature/notcool').not" >./features/cool/index.d.ts + js_library -l --path ./features/cool --name cool_lib --src "index.d.ts" + npm_package --path ./features/cool --name cool --src ":cool_lib" + echo '{"name": "@feature/cool"}' >./features/cool/package.json + + echo "export declare type not = string" >./features/notcool/index.d.ts + js_library -l --path ./features/notcool --name notcool_lib --src "index.d.ts" + npm_package --path ./features/notcool --name notcool --src ":notcool_lib" + echo '{"name": "@feature/notcool"}' >./features/notcool/package.json + + echo '-packages: ["features/cool", "features/notcool"]' >pnpm-workspace.yaml + echo '{"dependencies":{"@feature/cool": "workspace:*", "@types/node": "*"}}' >package.json + run pnpm install --lockfile-only + assert_success + + echo "import {cool} from '@feature/cool'; export const t: number = cool()" >source.ts + ts_project -l -s "source.ts" -d ":node_modules/@feature/cool" + run bazel build :foo --@aspect_rules_ts//ts:supports_workers + assert_failure + assert_output -p "node_modules/.aspect_rules_js/@feature+cool@0.0.0/node_modules/@feature/cool/index.d.ts(1,40): error TS2307: Cannot find module '@feature/notcool' or its corresponding type declarations." + + echo '{"dependencies":{"@feature/cool": "workspace:*", "@types/node": "*"}, "pnpm": {"packageExtensions": {"@feature/cool": {"dependencies": {"@feature/notcool": "workspace:*"}}}}}' >package.json + run pnpm install --lockfile-only + assert_success + run bazel build :foo --@aspect_rules_ts//ts:supports_workers + assert_success +} diff --git a/e2e/test/tracing_and_performance.bats b/e2e/test/tracing_and_performance.bats index 6bc19175..a1fc9d43 100644 --- a/e2e/test/tracing_and_performance.bats +++ b/e2e/test/tracing_and_performance.bats @@ -1,22 +1,21 @@ load "common.bats" setup() { - cd $BATS_FILE_TMPDIR + cd $BATS_FILE_TMPDIR } teardown() { - bazel shutdown - rm -rf $BATS_FILE_TMPDIR/* + bazel shutdown + rm -rf $BATS_FILE_TMPDIR/* } - @test 'should print diagnostics with --worker_verbose flag' { - workspace - tsconfig - ts_project --src "source.ts" - echo "export const f = 1;" > source.ts - run bazel build :foo --@aspect_rules_ts//ts:supports_workers - assert_success - run cat $(bazel info output_base)/bazel-workers/worker-1-TsProject.log - assert_output -p "# Beginning new work" "# Finished the work" "creating a new worker with the key" + workspace + tsconfig + ts_project --src "source.ts" + echo "export const f = 1;" >source.ts + run bazel build :foo --@aspect_rules_ts//ts:supports_workers + assert_success + run cat $(bazel info output_base)/bazel-workers/worker-1-TsProject.log + assert_output -p "# Beginning new work" "# Finished the work" "creating a new worker with the key" } diff --git a/tools/BUILD.bazel b/tools/BUILD.bazel deleted file mode 100644 index 91369d89..00000000 --- a/tools/BUILD.bazel +++ /dev/null @@ -1,30 +0,0 @@ -"""BUILD definition for the formatter binary -This is in its own package because it has so many loading-time symbols, -we don't want to trigger eager fetches of these for builds that don't want to run format. -""" - -load("@aspect_rules_lint//format:defs.bzl", "multi_formatter_binary") - -package(default_visibility = ["//:__subpackages__"]) - -sh_binary( - name = "noop", - srcs = ["noop.sh"], -) - -alias( - name = "shfmt", - actual = select({ - "@bazel_tools//src/conditions:darwin_arm64": "@shfmt_darwin_aarch64//file:shfmt", - "@bazel_tools//src/conditions:darwin_x86_64": "@shfmt_darwin_x86_64//file:shfmt", - "@bazel_tools//src/conditions:linux_aarch64": "@shfmt_linux_aarch64//file:shfmt", - "@bazel_tools//src/conditions:linux_x86_64": "@shfmt_linux_x86_64//file:shfmt", - "//conditions:default": ":noop", - }), -) - -multi_formatter_binary( - name = "format", - sh = ":shfmt", - starlark = "@buildifier_prebuilt//:buildifier", -) diff --git a/tools/format/BUILD.bazel b/tools/format/BUILD.bazel new file mode 100644 index 00000000..ebcc4957 --- /dev/null +++ b/tools/format/BUILD.bazel @@ -0,0 +1,14 @@ +"""BUILD definition for the formatter binary +This is in its own package because it has so many loading-time symbols, +we don't want to trigger eager fetches of these for builds that don't want to run format. +""" + +load("@aspect_rules_lint//format:defs.bzl", "format_multirun") + +package(default_visibility = ["//:__subpackages__"]) + +format_multirun( + name = "format", + shell = "@aspect_rules_lint//format:shfmt", + starlark = "@buildifier_prebuilt//:buildifier", +)