@valbuild/cli 0.154.0 → 0.154.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @valbuild/cli
2
2
 
3
+ ## 0.154.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1077](https://github.com/valbuild/val/pull/1077) [`82c641c`](https://github.com/valbuild/val/commit/82c641ca00ddfe1ed5b07b9ccb5ee39b0c6f102e) Thanks [@freekh](https://github.com/freekh)! - `val publish` now typechecks the project while it builds. It uses the `node_modules` the build already reads for the dependency layer, so nothing is downloaded for the check. It is the same typecheck the Studio runs for a proposal that changes dependencies. Type errors are printed as warnings, first line each (at most 20), and do not stop the publish. `--no-typecheck` turns the check off.
8
+
9
+ Only a pnpm project with its own `pnpm-lock.yaml` is typechecked. Anything else says why it was skipped and publishes as before.
10
+
11
+ For a build on the server, `@valbuild/shared/typecheck/node` exports `typecheckInstalled({ root, files })` and `installedSources(root)`: the typecheck run against a project installed on that machine.
12
+
13
+ - Updated dependencies [[`def1434`](https://github.com/valbuild/val/commit/def1434324a0b3e26202148cb11726e02bd5bffe), [`82c641c`](https://github.com/valbuild/val/commit/82c641ca00ddfe1ed5b07b9ccb5ee39b0c6f102e)]:
14
+ - @valbuild/server@0.154.1
15
+ - @valbuild/shared@0.154.1
16
+ - @valbuild/language-server@0.154.1
17
+
3
18
  ## 0.154.0
4
19
 
5
20
  ### Patch Changes
@@ -17,6 +17,7 @@ var readline = require('readline');
17
17
  var crypto = require('crypto');
18
18
  var zlib = require('zlib');
19
19
  var os = require('os');
20
+ var node = require('@valbuild/shared/typecheck/node');
20
21
 
21
22
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
22
23
 
@@ -2594,6 +2595,8 @@ function resolveArtifactsDir(options) {
2594
2595
 
2595
2596
  /** What `val publish` hands on to the upload. */
2596
2597
 
2598
+ /** `off` when the build was asked not to typecheck (`--no-typecheck`). */
2599
+
2597
2600
  /**
2598
2601
  * The builder, loaded only when a build is asked for: it brings rolldown's
2599
2602
  * native binary with it, and `val validate` has no use for one.
@@ -2858,7 +2861,7 @@ async function buildArtifacts(options) {
2858
2861
  if (loaded.status === "error") return loaded;
2859
2862
  const {
2860
2863
  build: builder,
2861
- node
2864
+ node: node$1
2862
2865
  } = loaded;
2863
2866
  const {
2864
2867
  root,
@@ -2901,11 +2904,11 @@ async function buildArtifacts(options) {
2901
2904
  return {};
2902
2905
  }
2903
2906
  })();
2904
- const deps = node.layerDepsOf(manifest, sources);
2907
+ const deps = node$1.layerDepsOf(manifest, sources);
2905
2908
  // The files those stylesheets point at -- a font package's `.woff2`s --
2906
2909
  // published with the site under the names their `url()`s now use.
2907
2910
  const dependencyAssets = {};
2908
- const css = await node.collectDependencyCss(root, node.cssSpecifiersOf(sources), dependencyAssets);
2911
+ const css = await node$1.collectDependencyCss(root, node$1.cssSpecifiersOf(sources), dependencyAssets);
2909
2912
  /*
2910
2913
  * There is no platform checkout here, so nothing can be PINNED to the
2911
2914
  * platform's copies and no built base layer can be read. What stands in
@@ -2921,7 +2924,7 @@ async function buildArtifacts(options) {
2921
2924
  if (deps.length > 0 && !target.base.exports) {
2922
2925
  warnings.push("The platform did not say what its base layer exports, so this build " + "could not check that the project's dependencies import only what it has.");
2923
2926
  }
2924
- const layer = await node.buildVendorLayer(root, deps, css, {
2927
+ const layer = await node$1.buildVendorLayer(root, deps, css, {
2925
2928
  base: target.base,
2926
2929
  resolvePlatformModule: () => null,
2927
2930
  baseLayerDir: null
@@ -2941,16 +2944,35 @@ async function buildArtifacts(options) {
2941
2944
  } of (layer === null || layer === void 0 ? void 0 : layer.skipped) ?? []) {
2942
2945
  warnings.push(`${specifier} is not in the dependency layer: ${reason}`);
2943
2946
  }
2947
+ const fileBased = await node$1.isFileBased(root);
2948
+ const files = fileBased ? await node$1.generateRouteTree(root, sources) : sources;
2949
+
2950
+ /*
2951
+ * The typecheck, while the install is here: the one `typecheckProject` the
2952
+ * Studio and the upgrade page run, reading the declarations this layer
2953
+ * was just built from instead of fetching them. Of the files this build
2954
+ * builds -- wired, and with the generated route tree a checkout may not
2955
+ * have -- since there is no site to compare with here, and an import of a
2956
+ * file only the build makes is not an error in the project.
2957
+ */
2958
+ let typecheck = {
2959
+ status: "off"
2960
+ };
2961
+ if (options.typecheck !== false) {
2962
+ log("Typechecking");
2963
+ typecheck = await node.typecheckInstalled({
2964
+ root,
2965
+ files
2966
+ });
2967
+ }
2944
2968
  log("Building the site");
2945
- const fileBased = await node.isFileBased(root);
2946
- const files = fileBased ? await node.generateRouteTree(root, sources) : sources;
2947
2969
  /*
2948
2970
  * The project's copy of the splitter first, then the one beside this CLI
2949
2971
  * -- where a package manager puts an optional peer the project installed
2950
2972
  * but did not hoist. Neither is a build that does not split, which costs
2951
2973
  * size and not behaviour.
2952
2974
  */
2953
- const splitter = (await node.routeSplitter(root)) ?? (typeof __dirname === "string" ? await node.routeSplitter(__dirname) : null);
2975
+ const splitter = (await node$1.routeSplitter(root)) ?? (typeof __dirname === "string" ? await node$1.routeSplitter(__dirname) : null);
2954
2976
  if (splitter === null) {
2955
2977
  warnings.push("Routes are not code-split: @tanstack/router-plugin is not installed.");
2956
2978
  }
@@ -2965,7 +2987,7 @@ async function buildArtifacts(options) {
2965
2987
  // stylesheets: what the next publish -- the Studio's included -- starts
2966
2988
  // from. See `withoutStylesheets`.
2967
2989
  projectSource,
2968
- loadCssModule: node.cssModuleLoader(root),
2990
+ loadCssModule: node$1.cssModuleLoader(root),
2969
2991
  ...(splitter ? {
2970
2992
  routeSplitter: splitter
2971
2993
  } : {}),
@@ -2994,7 +3016,8 @@ async function buildArtifacts(options) {
2994
3016
  layerRev
2995
3017
  } : {}),
2996
3018
  baseRev: target.base.rev,
2997
- warnings
3019
+ warnings,
3020
+ typecheck
2998
3021
  };
2999
3022
  } catch (e) {
3000
3023
  return {
@@ -3004,10 +3027,53 @@ async function buildArtifacts(options) {
3004
3027
  }
3005
3028
  }
3006
3029
 
3030
+ /** At most this many type errors are printed; the count says how many there were. */
3031
+ const SHOWN_TYPE_ERRORS = 20;
3032
+
3033
+ /**
3034
+ * What `val publish` prints of the typecheck. Type errors are warnings: a
3035
+ * project's own CI decides whether they stop it, and a publish that has run
3036
+ * this long is not the place to find out the build is blocked.
3037
+ */
3038
+ function typecheckReport(typecheck) {
3039
+ switch (typecheck.status) {
3040
+ case "off":
3041
+ return [];
3042
+ case "skipped":
3043
+ return [`Not typechecked: ${typecheck.reason}.`];
3044
+ case "failed":
3045
+ return [`warn: the project could not be typechecked: ${typecheck.message}`];
3046
+ case "checked":
3047
+ {
3048
+ const {
3049
+ errors,
3050
+ missing
3051
+ } = typecheck.result;
3052
+ const lines = [];
3053
+ if (errors.length === 0) {
3054
+ lines.push("Typechecked: no type errors.");
3055
+ } else {
3056
+ lines.push(`warn: ${errors.length} type error${errors.length === 1 ? "" : "s"} (published anyway; --no-typecheck skips the check):`);
3057
+ for (const error of errors.slice(0, SHOWN_TYPE_ERRORS)) {
3058
+ const at = error.file === null ? error.tsconfig : `${error.file}${error.line !== null ? `:${error.line}:${error.column ?? 1}` : ""}`;
3059
+ lines.push(`warn: ${at} TS${error.code} ${error.message.split("\n")[0]}`);
3060
+ }
3061
+ if (errors.length > SHOWN_TYPE_ERRORS) {
3062
+ lines.push(`warn: and ${errors.length - SHOWN_TYPE_ERRORS} more`);
3063
+ }
3064
+ }
3065
+ if (missing.length > 0) {
3066
+ lines.push(`warn: the types of ${missing.length} package${missing.length === 1 ? " were" : "s were"} not installed, ` + `so errors about ${missing.length === 1 ? "it" : "them"} may be missing or wrong: ` + missing.map(pkg => `${pkg.name}@${pkg.version}`).join(", "));
3067
+ }
3068
+ return lines;
3069
+ }
3070
+ }
3071
+ }
3072
+
3007
3073
  var packageJson = {
3008
3074
  name: "@valbuild/cli",
3009
3075
  "private": false,
3010
- version: "0.154.0",
3076
+ version: "0.154.1",
3011
3077
  description: "Val CLI tools",
3012
3078
  repository: {
3013
3079
  type: "git",
@@ -3704,7 +3770,10 @@ async function runPublish(options) {
3704
3770
  branch: wiredBranch
3705
3771
  },
3706
3772
  env,
3707
- log
3773
+ log,
3774
+ ...(options.typecheck === false ? {
3775
+ typecheck: false
3776
+ } : {})
3708
3777
  });
3709
3778
  if (build.status === "error") {
3710
3779
  return {
@@ -3714,6 +3783,7 @@ async function runPublish(options) {
3714
3783
  }
3715
3784
  built = build;
3716
3785
  for (const warning of build.warnings) log(`warn: ${warning}`);
3786
+ for (const line of typecheckReport(build.typecheck)) log(line);
3717
3787
  const fromBuild = await collectPrebuilt(root, build.dir, log);
3718
3788
  if (fromBuild.status === "error") return fromBuild;
3719
3789
  collected = fromBuild.collected;
@@ -4298,6 +4368,9 @@ async function publish(options) {
4298
4368
  ...(options.dryRun ? {
4299
4369
  dryRun: options.dryRun
4300
4370
  } : {}),
4371
+ ...(options.typecheck === false ? {
4372
+ typecheck: false
4373
+ } : {}),
4301
4374
  log: line => console.log(pc__default["default"].dim(line))
4302
4375
  });
4303
4376
  switch (result.status) {
@@ -4585,6 +4658,9 @@ async function main() {
4585
4658
  --skip-validation Publish without running "val validate" first. It runs by
4586
4659
  default, and an error stops the publish
4587
4660
  --strict Let a validation warning stop the publish too
4661
+ --no-typecheck Build without typechecking the project. It runs by default,
4662
+ on the install the build reads, and type errors are
4663
+ printed without stopping the publish
4588
4664
 
4589
4665
  Command: check-build-tools
4590
4666
  Description: load what "val publish" builds with, and build a one-line module with
@@ -4688,6 +4764,11 @@ async function main() {
4688
4764
  strict: {
4689
4765
  type: "boolean"
4690
4766
  },
4767
+ // On unless --no-typecheck: an absent boolean is false to meow.
4768
+ typecheck: {
4769
+ type: "boolean",
4770
+ default: true
4771
+ },
4691
4772
  yes: {
4692
4773
  type: "boolean"
4693
4774
  },
@@ -4763,7 +4844,8 @@ async function main() {
4763
4844
  linksOwnCss: flags.linksOwnCss,
4764
4845
  dryRun: flags.dryRun,
4765
4846
  skipValidation: flags.skipValidation,
4766
- strict: flags.strict
4847
+ strict: flags.strict,
4848
+ typecheck: flags.typecheck
4767
4849
  });
4768
4850
  case "login":
4769
4851
  return login({
@@ -17,6 +17,7 @@ var readline = require('readline');
17
17
  var crypto = require('crypto');
18
18
  var zlib = require('zlib');
19
19
  var os = require('os');
20
+ var node = require('@valbuild/shared/typecheck/node');
20
21
 
21
22
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
22
23
 
@@ -2594,6 +2595,8 @@ function resolveArtifactsDir(options) {
2594
2595
 
2595
2596
  /** What `val publish` hands on to the upload. */
2596
2597
 
2598
+ /** `off` when the build was asked not to typecheck (`--no-typecheck`). */
2599
+
2597
2600
  /**
2598
2601
  * The builder, loaded only when a build is asked for: it brings rolldown's
2599
2602
  * native binary with it, and `val validate` has no use for one.
@@ -2858,7 +2861,7 @@ async function buildArtifacts(options) {
2858
2861
  if (loaded.status === "error") return loaded;
2859
2862
  const {
2860
2863
  build: builder,
2861
- node
2864
+ node: node$1
2862
2865
  } = loaded;
2863
2866
  const {
2864
2867
  root,
@@ -2901,11 +2904,11 @@ async function buildArtifacts(options) {
2901
2904
  return {};
2902
2905
  }
2903
2906
  })();
2904
- const deps = node.layerDepsOf(manifest, sources);
2907
+ const deps = node$1.layerDepsOf(manifest, sources);
2905
2908
  // The files those stylesheets point at -- a font package's `.woff2`s --
2906
2909
  // published with the site under the names their `url()`s now use.
2907
2910
  const dependencyAssets = {};
2908
- const css = await node.collectDependencyCss(root, node.cssSpecifiersOf(sources), dependencyAssets);
2911
+ const css = await node$1.collectDependencyCss(root, node$1.cssSpecifiersOf(sources), dependencyAssets);
2909
2912
  /*
2910
2913
  * There is no platform checkout here, so nothing can be PINNED to the
2911
2914
  * platform's copies and no built base layer can be read. What stands in
@@ -2921,7 +2924,7 @@ async function buildArtifacts(options) {
2921
2924
  if (deps.length > 0 && !target.base.exports) {
2922
2925
  warnings.push("The platform did not say what its base layer exports, so this build " + "could not check that the project's dependencies import only what it has.");
2923
2926
  }
2924
- const layer = await node.buildVendorLayer(root, deps, css, {
2927
+ const layer = await node$1.buildVendorLayer(root, deps, css, {
2925
2928
  base: target.base,
2926
2929
  resolvePlatformModule: () => null,
2927
2930
  baseLayerDir: null
@@ -2941,16 +2944,35 @@ async function buildArtifacts(options) {
2941
2944
  } of (layer === null || layer === void 0 ? void 0 : layer.skipped) ?? []) {
2942
2945
  warnings.push(`${specifier} is not in the dependency layer: ${reason}`);
2943
2946
  }
2947
+ const fileBased = await node$1.isFileBased(root);
2948
+ const files = fileBased ? await node$1.generateRouteTree(root, sources) : sources;
2949
+
2950
+ /*
2951
+ * The typecheck, while the install is here: the one `typecheckProject` the
2952
+ * Studio and the upgrade page run, reading the declarations this layer
2953
+ * was just built from instead of fetching them. Of the files this build
2954
+ * builds -- wired, and with the generated route tree a checkout may not
2955
+ * have -- since there is no site to compare with here, and an import of a
2956
+ * file only the build makes is not an error in the project.
2957
+ */
2958
+ let typecheck = {
2959
+ status: "off"
2960
+ };
2961
+ if (options.typecheck !== false) {
2962
+ log("Typechecking");
2963
+ typecheck = await node.typecheckInstalled({
2964
+ root,
2965
+ files
2966
+ });
2967
+ }
2944
2968
  log("Building the site");
2945
- const fileBased = await node.isFileBased(root);
2946
- const files = fileBased ? await node.generateRouteTree(root, sources) : sources;
2947
2969
  /*
2948
2970
  * The project's copy of the splitter first, then the one beside this CLI
2949
2971
  * -- where a package manager puts an optional peer the project installed
2950
2972
  * but did not hoist. Neither is a build that does not split, which costs
2951
2973
  * size and not behaviour.
2952
2974
  */
2953
- const splitter = (await node.routeSplitter(root)) ?? (typeof __dirname === "string" ? await node.routeSplitter(__dirname) : null);
2975
+ const splitter = (await node$1.routeSplitter(root)) ?? (typeof __dirname === "string" ? await node$1.routeSplitter(__dirname) : null);
2954
2976
  if (splitter === null) {
2955
2977
  warnings.push("Routes are not code-split: @tanstack/router-plugin is not installed.");
2956
2978
  }
@@ -2965,7 +2987,7 @@ async function buildArtifacts(options) {
2965
2987
  // stylesheets: what the next publish -- the Studio's included -- starts
2966
2988
  // from. See `withoutStylesheets`.
2967
2989
  projectSource,
2968
- loadCssModule: node.cssModuleLoader(root),
2990
+ loadCssModule: node$1.cssModuleLoader(root),
2969
2991
  ...(splitter ? {
2970
2992
  routeSplitter: splitter
2971
2993
  } : {}),
@@ -2994,7 +3016,8 @@ async function buildArtifacts(options) {
2994
3016
  layerRev
2995
3017
  } : {}),
2996
3018
  baseRev: target.base.rev,
2997
- warnings
3019
+ warnings,
3020
+ typecheck
2998
3021
  };
2999
3022
  } catch (e) {
3000
3023
  return {
@@ -3004,10 +3027,53 @@ async function buildArtifacts(options) {
3004
3027
  }
3005
3028
  }
3006
3029
 
3030
+ /** At most this many type errors are printed; the count says how many there were. */
3031
+ const SHOWN_TYPE_ERRORS = 20;
3032
+
3033
+ /**
3034
+ * What `val publish` prints of the typecheck. Type errors are warnings: a
3035
+ * project's own CI decides whether they stop it, and a publish that has run
3036
+ * this long is not the place to find out the build is blocked.
3037
+ */
3038
+ function typecheckReport(typecheck) {
3039
+ switch (typecheck.status) {
3040
+ case "off":
3041
+ return [];
3042
+ case "skipped":
3043
+ return [`Not typechecked: ${typecheck.reason}.`];
3044
+ case "failed":
3045
+ return [`warn: the project could not be typechecked: ${typecheck.message}`];
3046
+ case "checked":
3047
+ {
3048
+ const {
3049
+ errors,
3050
+ missing
3051
+ } = typecheck.result;
3052
+ const lines = [];
3053
+ if (errors.length === 0) {
3054
+ lines.push("Typechecked: no type errors.");
3055
+ } else {
3056
+ lines.push(`warn: ${errors.length} type error${errors.length === 1 ? "" : "s"} (published anyway; --no-typecheck skips the check):`);
3057
+ for (const error of errors.slice(0, SHOWN_TYPE_ERRORS)) {
3058
+ const at = error.file === null ? error.tsconfig : `${error.file}${error.line !== null ? `:${error.line}:${error.column ?? 1}` : ""}`;
3059
+ lines.push(`warn: ${at} TS${error.code} ${error.message.split("\n")[0]}`);
3060
+ }
3061
+ if (errors.length > SHOWN_TYPE_ERRORS) {
3062
+ lines.push(`warn: and ${errors.length - SHOWN_TYPE_ERRORS} more`);
3063
+ }
3064
+ }
3065
+ if (missing.length > 0) {
3066
+ lines.push(`warn: the types of ${missing.length} package${missing.length === 1 ? " were" : "s were"} not installed, ` + `so errors about ${missing.length === 1 ? "it" : "them"} may be missing or wrong: ` + missing.map(pkg => `${pkg.name}@${pkg.version}`).join(", "));
3067
+ }
3068
+ return lines;
3069
+ }
3070
+ }
3071
+ }
3072
+
3007
3073
  var packageJson = {
3008
3074
  name: "@valbuild/cli",
3009
3075
  "private": false,
3010
- version: "0.154.0",
3076
+ version: "0.154.1",
3011
3077
  description: "Val CLI tools",
3012
3078
  repository: {
3013
3079
  type: "git",
@@ -3704,7 +3770,10 @@ async function runPublish(options) {
3704
3770
  branch: wiredBranch
3705
3771
  },
3706
3772
  env,
3707
- log
3773
+ log,
3774
+ ...(options.typecheck === false ? {
3775
+ typecheck: false
3776
+ } : {})
3708
3777
  });
3709
3778
  if (build.status === "error") {
3710
3779
  return {
@@ -3714,6 +3783,7 @@ async function runPublish(options) {
3714
3783
  }
3715
3784
  built = build;
3716
3785
  for (const warning of build.warnings) log(`warn: ${warning}`);
3786
+ for (const line of typecheckReport(build.typecheck)) log(line);
3717
3787
  const fromBuild = await collectPrebuilt(root, build.dir, log);
3718
3788
  if (fromBuild.status === "error") return fromBuild;
3719
3789
  collected = fromBuild.collected;
@@ -4298,6 +4368,9 @@ async function publish(options) {
4298
4368
  ...(options.dryRun ? {
4299
4369
  dryRun: options.dryRun
4300
4370
  } : {}),
4371
+ ...(options.typecheck === false ? {
4372
+ typecheck: false
4373
+ } : {}),
4301
4374
  log: line => console.log(pc__default["default"].dim(line))
4302
4375
  });
4303
4376
  switch (result.status) {
@@ -4585,6 +4658,9 @@ async function main() {
4585
4658
  --skip-validation Publish without running "val validate" first. It runs by
4586
4659
  default, and an error stops the publish
4587
4660
  --strict Let a validation warning stop the publish too
4661
+ --no-typecheck Build without typechecking the project. It runs by default,
4662
+ on the install the build reads, and type errors are
4663
+ printed without stopping the publish
4588
4664
 
4589
4665
  Command: check-build-tools
4590
4666
  Description: load what "val publish" builds with, and build a one-line module with
@@ -4688,6 +4764,11 @@ async function main() {
4688
4764
  strict: {
4689
4765
  type: "boolean"
4690
4766
  },
4767
+ // On unless --no-typecheck: an absent boolean is false to meow.
4768
+ typecheck: {
4769
+ type: "boolean",
4770
+ default: true
4771
+ },
4691
4772
  yes: {
4692
4773
  type: "boolean"
4693
4774
  },
@@ -4763,7 +4844,8 @@ async function main() {
4763
4844
  linksOwnCss: flags.linksOwnCss,
4764
4845
  dryRun: flags.dryRun,
4765
4846
  skipValidation: flags.skipValidation,
4766
- strict: flags.strict
4847
+ strict: flags.strict,
4848
+ typecheck: flags.typecheck
4767
4849
  });
4768
4850
  case "login":
4769
4851
  return login({
@@ -15,6 +15,7 @@ import readline from 'readline';
15
15
  import crypto from 'crypto';
16
16
  import zlib from 'zlib';
17
17
  import os from 'os';
18
+ import { typecheckInstalled } from '@valbuild/shared/typecheck/node';
18
19
 
19
20
  function error(message) {
20
21
  console.error(chalk.red("❌Error: ") + message);
@@ -2559,6 +2560,8 @@ function resolveArtifactsDir(options) {
2559
2560
 
2560
2561
  /** What `val publish` hands on to the upload. */
2561
2562
 
2563
+ /** `off` when the build was asked not to typecheck (`--no-typecheck`). */
2564
+
2562
2565
  /**
2563
2566
  * The builder, loaded only when a build is asked for: it brings rolldown's
2564
2567
  * native binary with it, and `val validate` has no use for one.
@@ -2906,9 +2909,28 @@ async function buildArtifacts(options) {
2906
2909
  } of (layer === null || layer === void 0 ? void 0 : layer.skipped) ?? []) {
2907
2910
  warnings.push(`${specifier} is not in the dependency layer: ${reason}`);
2908
2911
  }
2909
- log("Building the site");
2910
2912
  const fileBased = await node.isFileBased(root);
2911
2913
  const files = fileBased ? await node.generateRouteTree(root, sources) : sources;
2914
+
2915
+ /*
2916
+ * The typecheck, while the install is here: the one `typecheckProject` the
2917
+ * Studio and the upgrade page run, reading the declarations this layer
2918
+ * was just built from instead of fetching them. Of the files this build
2919
+ * builds -- wired, and with the generated route tree a checkout may not
2920
+ * have -- since there is no site to compare with here, and an import of a
2921
+ * file only the build makes is not an error in the project.
2922
+ */
2923
+ let typecheck = {
2924
+ status: "off"
2925
+ };
2926
+ if (options.typecheck !== false) {
2927
+ log("Typechecking");
2928
+ typecheck = await typecheckInstalled({
2929
+ root,
2930
+ files
2931
+ });
2932
+ }
2933
+ log("Building the site");
2912
2934
  /*
2913
2935
  * The project's copy of the splitter first, then the one beside this CLI
2914
2936
  * -- where a package manager puts an optional peer the project installed
@@ -2959,7 +2981,8 @@ async function buildArtifacts(options) {
2959
2981
  layerRev
2960
2982
  } : {}),
2961
2983
  baseRev: target.base.rev,
2962
- warnings
2984
+ warnings,
2985
+ typecheck
2963
2986
  };
2964
2987
  } catch (e) {
2965
2988
  return {
@@ -2969,10 +2992,53 @@ async function buildArtifacts(options) {
2969
2992
  }
2970
2993
  }
2971
2994
 
2995
+ /** At most this many type errors are printed; the count says how many there were. */
2996
+ const SHOWN_TYPE_ERRORS = 20;
2997
+
2998
+ /**
2999
+ * What `val publish` prints of the typecheck. Type errors are warnings: a
3000
+ * project's own CI decides whether they stop it, and a publish that has run
3001
+ * this long is not the place to find out the build is blocked.
3002
+ */
3003
+ function typecheckReport(typecheck) {
3004
+ switch (typecheck.status) {
3005
+ case "off":
3006
+ return [];
3007
+ case "skipped":
3008
+ return [`Not typechecked: ${typecheck.reason}.`];
3009
+ case "failed":
3010
+ return [`warn: the project could not be typechecked: ${typecheck.message}`];
3011
+ case "checked":
3012
+ {
3013
+ const {
3014
+ errors,
3015
+ missing
3016
+ } = typecheck.result;
3017
+ const lines = [];
3018
+ if (errors.length === 0) {
3019
+ lines.push("Typechecked: no type errors.");
3020
+ } else {
3021
+ lines.push(`warn: ${errors.length} type error${errors.length === 1 ? "" : "s"} (published anyway; --no-typecheck skips the check):`);
3022
+ for (const error of errors.slice(0, SHOWN_TYPE_ERRORS)) {
3023
+ const at = error.file === null ? error.tsconfig : `${error.file}${error.line !== null ? `:${error.line}:${error.column ?? 1}` : ""}`;
3024
+ lines.push(`warn: ${at} TS${error.code} ${error.message.split("\n")[0]}`);
3025
+ }
3026
+ if (errors.length > SHOWN_TYPE_ERRORS) {
3027
+ lines.push(`warn: and ${errors.length - SHOWN_TYPE_ERRORS} more`);
3028
+ }
3029
+ }
3030
+ if (missing.length > 0) {
3031
+ lines.push(`warn: the types of ${missing.length} package${missing.length === 1 ? " were" : "s were"} not installed, ` + `so errors about ${missing.length === 1 ? "it" : "them"} may be missing or wrong: ` + missing.map(pkg => `${pkg.name}@${pkg.version}`).join(", "));
3032
+ }
3033
+ return lines;
3034
+ }
3035
+ }
3036
+ }
3037
+
2972
3038
  var packageJson = {
2973
3039
  name: "@valbuild/cli",
2974
3040
  "private": false,
2975
- version: "0.154.0",
3041
+ version: "0.154.1",
2976
3042
  description: "Val CLI tools",
2977
3043
  repository: {
2978
3044
  type: "git",
@@ -3669,7 +3735,10 @@ async function runPublish(options) {
3669
3735
  branch: wiredBranch
3670
3736
  },
3671
3737
  env,
3672
- log
3738
+ log,
3739
+ ...(options.typecheck === false ? {
3740
+ typecheck: false
3741
+ } : {})
3673
3742
  });
3674
3743
  if (build.status === "error") {
3675
3744
  return {
@@ -3679,6 +3748,7 @@ async function runPublish(options) {
3679
3748
  }
3680
3749
  built = build;
3681
3750
  for (const warning of build.warnings) log(`warn: ${warning}`);
3751
+ for (const line of typecheckReport(build.typecheck)) log(line);
3682
3752
  const fromBuild = await collectPrebuilt(root, build.dir, log);
3683
3753
  if (fromBuild.status === "error") return fromBuild;
3684
3754
  collected = fromBuild.collected;
@@ -4263,6 +4333,9 @@ async function publish(options) {
4263
4333
  ...(options.dryRun ? {
4264
4334
  dryRun: options.dryRun
4265
4335
  } : {}),
4336
+ ...(options.typecheck === false ? {
4337
+ typecheck: false
4338
+ } : {}),
4266
4339
  log: line => console.log(pc.dim(line))
4267
4340
  });
4268
4341
  switch (result.status) {
@@ -4550,6 +4623,9 @@ async function main() {
4550
4623
  --skip-validation Publish without running "val validate" first. It runs by
4551
4624
  default, and an error stops the publish
4552
4625
  --strict Let a validation warning stop the publish too
4626
+ --no-typecheck Build without typechecking the project. It runs by default,
4627
+ on the install the build reads, and type errors are
4628
+ printed without stopping the publish
4553
4629
 
4554
4630
  Command: check-build-tools
4555
4631
  Description: load what "val publish" builds with, and build a one-line module with
@@ -4653,6 +4729,11 @@ async function main() {
4653
4729
  strict: {
4654
4730
  type: "boolean"
4655
4731
  },
4732
+ // On unless --no-typecheck: an absent boolean is false to meow.
4733
+ typecheck: {
4734
+ type: "boolean",
4735
+ default: true
4736
+ },
4656
4737
  yes: {
4657
4738
  type: "boolean"
4658
4739
  },
@@ -4728,7 +4809,8 @@ async function main() {
4728
4809
  linksOwnCss: flags.linksOwnCss,
4729
4810
  dryRun: flags.dryRun,
4730
4811
  skipValidation: flags.skipValidation,
4731
- strict: flags.strict
4812
+ strict: flags.strict,
4813
+ typecheck: flags.typecheck
4732
4814
  });
4733
4815
  case "login":
4734
4816
  return login({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@valbuild/cli",
3
3
  "private": false,
4
- "version": "0.154.0",
4
+ "version": "0.154.1",
5
5
  "description": "Val CLI tools",
6
6
  "repository": {
7
7
  "type": "git",
@@ -27,10 +27,10 @@
27
27
  "zod": "^4.6.6",
28
28
  "zod-validation-error": "^5.0.0",
29
29
  "@valbuild/core": "0.153.5",
30
- "@valbuild/language-server": "0.154.0",
31
30
  "@valbuild/eslint-plugin": "0.150.13",
32
- "@valbuild/shared": "0.154.0",
33
- "@valbuild/server": "0.154.0"
31
+ "@valbuild/language-server": "0.154.1",
32
+ "@valbuild/server": "0.154.1",
33
+ "@valbuild/shared": "0.154.1"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "prettier": "*",
package/src/cli.ts CHANGED
@@ -98,6 +98,9 @@ async function main(): Promise<void> {
98
98
  --skip-validation Publish without running "val validate" first. It runs by
99
99
  default, and an error stops the publish
100
100
  --strict Let a validation warning stop the publish too
101
+ --no-typecheck Build without typechecking the project. It runs by default,
102
+ on the install the build reads, and type errors are
103
+ printed without stopping the publish
101
104
 
102
105
  Command: check-build-tools
103
106
  Description: load what "val publish" builds with, and build a one-line module with
@@ -202,6 +205,11 @@ async function main(): Promise<void> {
202
205
  strict: {
203
206
  type: "boolean",
204
207
  },
208
+ // On unless --no-typecheck: an absent boolean is false to meow.
209
+ typecheck: {
210
+ type: "boolean",
211
+ default: true,
212
+ },
205
213
  yes: {
206
214
  type: "boolean",
207
215
  },
@@ -284,6 +292,7 @@ async function main(): Promise<void> {
284
292
  dryRun: flags.dryRun,
285
293
  skipValidation: flags.skipValidation,
286
294
  strict: flags.strict,
295
+ typecheck: flags.typecheck,
287
296
  });
288
297
  case "login":
289
298
  return login({
@@ -108,6 +108,8 @@ type Report = {
108
108
  warnedAboutBranch: boolean;
109
109
  /** Whether it said the platform sent no pins or exports -- which it did. */
110
110
  warnedAboutPlatformFacts: boolean;
111
+ /** What it said of the typecheck. */
112
+ typecheckSaid: string[];
111
113
  };
112
114
 
113
115
  /** A 1x1 PNG: small enough to inline, so the page carries it as a data URI. */
@@ -229,6 +231,7 @@ async function publishOnce(
229
231
  warnedAboutBranch: logged.some(
230
232
  (line) => line.startsWith("warn:") && line.includes("publishes"),
231
233
  ),
234
+ typecheckSaid: logged.filter((line) => /typecheck/i.test(line)),
232
235
  };
233
236
  }
234
237
 
@@ -4,6 +4,10 @@ import path from "path";
4
4
  import zlib from "zlib";
5
5
  import type { BuildTarget, PublishArtifact } from "@valbuild/tanstack-build";
6
6
  import type { VendorLayer } from "@valbuild/tanstack-build/node";
7
+ import {
8
+ typecheckInstalled,
9
+ type InstalledTypecheck,
10
+ } from "@valbuild/shared/typecheck/node";
7
11
 
8
12
  /**
9
13
  * `val publish`'s build: the site, built from the checkout, as the artifacts
@@ -41,9 +45,14 @@ export type BuiltArtifacts =
41
45
  /** The base layer this was built against: the build target's `base.rev`. */
42
46
  baseRev: string;
43
47
  warnings: string[];
48
+ /** The project's typecheck, made on the install the layer was built from. */
49
+ typecheck: BuildTypecheck;
44
50
  }
45
51
  | { status: "error"; message: string };
46
52
 
53
+ /** `off` when the build was asked not to typecheck (`--no-typecheck`). */
54
+ export type BuildTypecheck = InstalledTypecheck | { status: "off" };
55
+
47
56
  type TanstackBuild = typeof import("@valbuild/tanstack-build");
48
57
  type TanstackBuildNode = typeof import("@valbuild/tanstack-build/node");
49
58
 
@@ -337,6 +346,12 @@ export async function buildArtifacts(options: {
337
346
  log?: (line: string) => void;
338
347
  /** Where to write; a fresh temporary directory by default. */
339
348
  outDir?: string;
349
+ /**
350
+ * Typecheck the project too, on the install the layer is built from, so
351
+ * the declarations are read from disk rather than fetched again. Reported,
352
+ * never refused on. On by default.
353
+ */
354
+ typecheck?: boolean;
340
355
  }): Promise<BuiltArtifacts> {
341
356
  const log = options.log ?? (() => {});
342
357
  const loaded = await loadBuilder();
@@ -430,11 +445,26 @@ export async function buildArtifacts(options: {
430
445
  warnings.push(`${specifier} is not in the dependency layer: ${reason}`);
431
446
  }
432
447
 
433
- log("Building the site");
434
448
  const fileBased = await node.isFileBased(root);
435
449
  const files = fileBased
436
450
  ? await node.generateRouteTree(root, sources)
437
451
  : sources;
452
+
453
+ /*
454
+ * The typecheck, while the install is here: the one `typecheckProject` the
455
+ * Studio and the upgrade page run, reading the declarations this layer
456
+ * was just built from instead of fetching them. Of the files this build
457
+ * builds -- wired, and with the generated route tree a checkout may not
458
+ * have -- since there is no site to compare with here, and an import of a
459
+ * file only the build makes is not an error in the project.
460
+ */
461
+ let typecheck: BuildTypecheck = { status: "off" };
462
+ if (options.typecheck !== false) {
463
+ log("Typechecking");
464
+ typecheck = await typecheckInstalled({ root, files });
465
+ }
466
+
467
+ log("Building the site");
438
468
  /*
439
469
  * The project's copy of the splitter first, then the one beside this CLI
440
470
  * -- where a package manager puts an optional peer the project installed
@@ -493,6 +523,7 @@ export async function buildArtifacts(options: {
493
523
  ...(layerRev !== undefined ? { layerRev } : {}),
494
524
  baseRev: target.base.rev,
495
525
  warnings,
526
+ typecheck,
496
527
  };
497
528
  } catch (e) {
498
529
  return {
@@ -503,3 +534,55 @@ export async function buildArtifacts(options: {
503
534
  };
504
535
  }
505
536
  }
537
+
538
+ /** At most this many type errors are printed; the count says how many there were. */
539
+ const SHOWN_TYPE_ERRORS = 20;
540
+
541
+ /**
542
+ * What `val publish` prints of the typecheck. Type errors are warnings: a
543
+ * project's own CI decides whether they stop it, and a publish that has run
544
+ * this long is not the place to find out the build is blocked.
545
+ */
546
+ export function typecheckReport(typecheck: BuildTypecheck): string[] {
547
+ switch (typecheck.status) {
548
+ case "off":
549
+ return [];
550
+ case "skipped":
551
+ return [`Not typechecked: ${typecheck.reason}.`];
552
+ case "failed":
553
+ return [
554
+ `warn: the project could not be typechecked: ${typecheck.message}`,
555
+ ];
556
+ case "checked": {
557
+ const { errors, missing } = typecheck.result;
558
+ const lines: string[] = [];
559
+ if (errors.length === 0) {
560
+ lines.push("Typechecked: no type errors.");
561
+ } else {
562
+ lines.push(
563
+ `warn: ${errors.length} type error${errors.length === 1 ? "" : "s"} (published anyway; --no-typecheck skips the check):`,
564
+ );
565
+ for (const error of errors.slice(0, SHOWN_TYPE_ERRORS)) {
566
+ const at =
567
+ error.file === null
568
+ ? error.tsconfig
569
+ : `${error.file}${error.line !== null ? `:${error.line}:${error.column ?? 1}` : ""}`;
570
+ lines.push(
571
+ `warn: ${at} TS${error.code} ${error.message.split("\n")[0]}`,
572
+ );
573
+ }
574
+ if (errors.length > SHOWN_TYPE_ERRORS) {
575
+ lines.push(`warn: and ${errors.length - SHOWN_TYPE_ERRORS} more`);
576
+ }
577
+ }
578
+ if (missing.length > 0) {
579
+ lines.push(
580
+ `warn: the types of ${missing.length} package${missing.length === 1 ? " were" : "s were"} not installed, ` +
581
+ `so errors about ${missing.length === 1 ? "it" : "them"} may be missing or wrong: ` +
582
+ missing.map((pkg) => `${pkg.name}@${pkg.version}`).join(", "),
583
+ );
584
+ }
585
+ return lines;
586
+ }
587
+ }
588
+ }
@@ -39,6 +39,7 @@ type Run = {
39
39
  wiredBranch: string | null;
40
40
  warnedAboutBranch: boolean;
41
41
  warnedAboutPlatformFacts: boolean;
42
+ typecheckSaid: string[];
42
43
  };
43
44
 
44
45
  let probe: { fresh: Run; held: Run; elsewhere: Run };
@@ -141,3 +142,13 @@ test("the checkout is left as it was found", () => {
141
142
  expect(probe.fresh.checkoutUntouched).toBe(true);
142
143
  expect(probe.held.checkoutUntouched).toBe(true);
143
144
  });
145
+
146
+ test("the build typechecks the project, and says why when it cannot", () => {
147
+ // The probe's project has no pnpm-lock.yaml, so there is no layout to check
148
+ // in: said, and published all the same.
149
+ expect(probe.fresh.result.status).toBe("live");
150
+ expect(probe.fresh.typecheckSaid).toEqual([
151
+ "Typechecking",
152
+ "Not typechecked: there is no pnpm-lock.yaml beside its package.json, and only a pnpm project with its own lockfile is typechecked.",
153
+ ]);
154
+ });
@@ -12,7 +12,11 @@ import {
12
12
  layerRevOf,
13
13
  resolveArtifactsDir,
14
14
  } from "./artifacts";
15
- import { BuiltArtifacts, buildArtifacts } from "./buildArtifacts";
15
+ import {
16
+ BuiltArtifacts,
17
+ buildArtifacts,
18
+ typecheckReport,
19
+ } from "./buildArtifacts";
16
20
  import {
17
21
  PublishClient,
18
22
  UploadError,
@@ -51,6 +55,11 @@ export type PublishOptions = {
51
55
  linksOwnCss?: boolean;
52
56
  /** Verify, and stop before the pointer moves. */
53
57
  dryRun?: boolean;
58
+ /**
59
+ * Typecheck the project as it is built (default true). Reported, never
60
+ * refused on: see `buildArtifacts`.
61
+ */
62
+ typecheck?: boolean;
54
63
  env?: NodeJS.ProcessEnv;
55
64
  fetchImpl?: typeof fetch;
56
65
  sleep?: (ms: number) => Promise<void>;
@@ -225,12 +234,14 @@ export async function runPublish(
225
234
  git: { commit: git.commit, branch: wiredBranch },
226
235
  env,
227
236
  log,
237
+ ...(options.typecheck === false ? { typecheck: false } : {}),
228
238
  });
229
239
  if (build.status === "error") {
230
240
  return { status: "error", message: build.message };
231
241
  }
232
242
  built = build;
233
243
  for (const warning of build.warnings) log(`warn: ${warning}`);
244
+ for (const line of typecheckReport(build.typecheck)) log(line);
234
245
  const fromBuild = await collectPrebuilt(root, build.dir, log);
235
246
  if (fromBuild.status === "error") return fromBuild;
236
247
  collected = fromBuild.collected;
@@ -0,0 +1,103 @@
1
+ import { typecheckReport } from "./buildArtifacts";
2
+ import type {
3
+ TypecheckResult,
4
+ TypeErrorEntry,
5
+ } from "@valbuild/shared/typecheck";
6
+
7
+ function checked(
8
+ errors: TypeErrorEntry[],
9
+ missing: TypecheckResult["missing"] = [],
10
+ ): Parameters<typeof typecheckReport>[0] {
11
+ return {
12
+ status: "checked",
13
+ result: {
14
+ errors,
15
+ missing,
16
+ programs: [],
17
+ typescript: { version: "6.0.3", wanted: "6.0.3", reason: "project" },
18
+ bundles: {
19
+ scanned: 0,
20
+ resolved: 0,
21
+ files: 0,
22
+ stubs: 0,
23
+ bytes: 0,
24
+ count: 0,
25
+ rounds: 0,
26
+ },
27
+ timings: {
28
+ layoutMs: 0,
29
+ compilerMs: 0,
30
+ typesMs: 0,
31
+ checkMs: 0,
32
+ totalMs: 0,
33
+ },
34
+ },
35
+ };
36
+ }
37
+
38
+ const error = (n: number): TypeErrorEntry => ({
39
+ file: "src/a.ts",
40
+ line: n,
41
+ column: 3,
42
+ code: 2322,
43
+ message: "Type 'string' is not assignable to type 'number'.\n more",
44
+ tsconfig: "tsconfig.json",
45
+ });
46
+
47
+ describe("typecheckReport", () => {
48
+ test("nothing when it was turned off", () => {
49
+ expect(typecheckReport({ status: "off" })).toEqual([]);
50
+ });
51
+
52
+ test("no errors", () => {
53
+ expect(typecheckReport(checked([]))).toEqual([
54
+ "Typechecked: no type errors.",
55
+ ]);
56
+ });
57
+
58
+ test("each error where it is, its first line, and how to skip the check", () => {
59
+ expect(
60
+ typecheckReport(
61
+ checked([
62
+ error(1),
63
+ { ...error(2), file: null, line: null, column: null },
64
+ ]),
65
+ ),
66
+ ).toEqual([
67
+ "warn: 2 type errors (published anyway; --no-typecheck skips the check):",
68
+ "warn: src/a.ts:1:3 TS2322 Type 'string' is not assignable to type 'number'.",
69
+ "warn: tsconfig.json TS2322 Type 'string' is not assignable to type 'number'.",
70
+ ]);
71
+ });
72
+
73
+ test("a long list is cut, and says how much was left out", () => {
74
+ const lines = typecheckReport(
75
+ checked(Array.from({ length: 25 }, (_, i) => error(i + 1))),
76
+ );
77
+ expect(lines).toHaveLength(22);
78
+ expect(lines.at(-1)).toBe("warn: and 5 more");
79
+ });
80
+
81
+ test("packages without types are named, since errors about them may be wrong", () => {
82
+ expect(
83
+ typecheckReport(
84
+ checked(
85
+ [],
86
+ [
87
+ {
88
+ name: "a",
89
+ version: "1.0.0",
90
+ integrity: null,
91
+ code: "not-found",
92
+ message: "a@1.0.0 is not installed here.",
93
+ retryable: false,
94
+ },
95
+ ],
96
+ ),
97
+ ),
98
+ ).toEqual([
99
+ "Typechecked: no type errors.",
100
+ "warn: the types of 1 package were not installed, so errors about it may be missing or wrong: a@1.0.0",
101
+ ]);
102
+ });
103
+ });
package/src/publish.ts CHANGED
@@ -24,6 +24,8 @@ export async function publish(options: {
24
24
  skipValidation?: boolean;
25
25
  /** Let a validation warning stop the publish too, as `val validate --strict`. */
26
26
  strict?: boolean;
27
+ /** `false` (`--no-typecheck`): build without typechecking the project. */
28
+ typecheck?: boolean;
27
29
  }): Promise<void> {
28
30
  // Content that does not validate is not published. This is the check that
29
31
  // lets the Studio trust a connected project's published content without
@@ -72,6 +74,7 @@ export async function publish(options: {
72
74
  ? {}
73
75
  : { linksOwnCss: options.linksOwnCss }),
74
76
  ...(options.dryRun ? { dryRun: options.dryRun } : {}),
77
+ ...(options.typecheck === false ? { typecheck: false } : {}),
75
78
  log: (line) => console.log(pc.dim(line)),
76
79
  });
77
80