schultek / jaspr

Modern web framework for building websites in Dart. Supports SPAs, SSR and SSG.
https://jasprpad.schultek.de
MIT License
1.25k stars 76 forks source link

fix: Warn Or Enforce Supported Dart Versions For CLI Tool #312

Closed mcmah309 closed 1 week ago

mcmah309 commented 4 weeks ago

Description

When creating a new project, if you have an unsupported Dart version, commands like jaspr build may fail without warning why. The example below shows a scenario like this. The solution is to use Dart 3.5.0 but nowhere is this enforced or warned about.

Example In Dart 3.4.0 If you have

pubspec.yaml

name: voyver_website
description: A new jaspr project.
version: 0.0.1

environment:
  sdk: '>=3.0.0 <4.0.0'

dependencies:
  jaspr: ^0.15.1
  jaspr_router: ^0.5.1

dev_dependencies:
  build_runner: ^2.4.0
  jaspr_web_compilers: ^4.0.10
  jaspr_builder: ^0.15.1
  jaspr_lints: ^0.1.1
  lints: ^3.0.0

jaspr:
  mode: static

You will get

henry@nixos:~/work/voyver_website/voyver_website (jaspr)$ jaspr build --verbose
PathAccessException: Cannot open file, path = '/home/henry/.bash_profile' (OS Error: Permission denied, errno = 13)
Building jaspr for static rendering mode.
Building web assets...
[BUILDER] [ERROR] Because no versions of jaspr_lints match >0.1.1 <0.2.0 and jaspr_lints 0.1.1 depends on custom_lint_builder 0.6.5, jaspr_lints ^0.1.1 requires cus.
[BUILDER] [ERROR] And because custom_lint_builder 0.6.5 depends on analyzer ^6.6.0, jaspr_lints ^0.1.1 requires analyzer ^6.6.0.
[BUILDER] [ERROR] And because analyzer >=6.6.0 <6.9.0 depends on macros >=0.1.2-main.3 <0.1.3 and analyzer >=6.9.0 depends on macros >=0.1.3-main.0 <0.1.4, jaspr_li.
[BUILDER] [ERROR] And because macros >=0.1.3-main.0 depends on _macros 0.3.3 from sdk which doesn't match any versions, jaspr_lints ^0.1.1 requires macros >=0.1.2-m.
[BUILDER] [ERROR] And because no versions of macros match >0.1.2-main.4 <0.1.3 and macros >=0.1.2-main.2 <0.1.2-main.4 depends on _macros 0.3.1 from sdk, jaspr_lint.
[BUILDER] [ERROR] And because no versions of _macros from sdk match 0.3.1 and macros 0.1.2-main.4 depends on _macros 0.3.2 from sdk, jaspr_lints ^0.1.1 requires _ma.
[BUILDER] [ERROR] So, because no versions of _macros from sdk match 0.3.2 and voyver_website depends on jaspr_lints ^0.1.1, version solving failed.
Bad state: Unable to start build daemon.

After removing jaspr_lints

henry@nixos:~/work/voyver_website/voyver_website (jaspr)$ jaspr build --verbose
PathAccessException: Cannot open file, path = '/home/henry/.bash_profile' (OS Error: Permission denied, errno = 13)
Building jaspr for static rendering mode.
Building web assets...
[BUILDER] Generating build script...
[BUILDER] Generating build script completed, took 298ms
[BUILDER] Invalidated precompiled build script due to core package update
[BUILDER] Precompiling build script......
[BUILDER] Precompiling build script... completed, took 4.7s
[BUILDER] Starting daemon...
[BUILDER] Initializing inputs
[BUILDER] Reading cached asset graph...
[BUILDER] [WARNing] Throwing away cached asset graph because the build phases have changed. This most commonly would happen as a result of adding a new dependency o.
[BUILDER] [WARNing] Throwing away cached asset graph because the language version of some package(s) changed. This would most commonly happen when updating dependen.
[BUILDER] Cleaning up outputs from previous builds....
[BUILDER] Cleaning up outputs from previous builds. completed, took 28ms
[BUILDER] Generating build script...
[BUILDER] Generating build script completed, took 75ms
[BUILDER] Invalidated precompiled build script due to missing asset graph.
[BUILDER] Precompiling build script......
[BUILDER] Precompiling build script... completed, took 666ms
[BUILDER] Starting daemon...
[BUILDER] Initializing inputs
[BUILDER] Building new asset graph...
[BUILDER] Building new asset graph completed, took 1.2s
[BUILDER] Checking for unexpected pre-existing outputs....
[BUILDER] Checking for unexpected pre-existing outputs. completed, took 0ms
[BUILDER] [ERROR] Initializing inputs
[BUILDER] [ERROR] Building new asset graph...
[BUILDER] [ERROR] Building new asset graph completed, took 1.2s
[BUILDER] [ERROR] Checking for unexpected pre-existing outputs....
[BUILDER] [ERROR] Checking for unexpected pre-existing outputs. completed, took 0ms
[BUILDER] [ERROR] Setting up file watchers...
[BUILDER] [ERROR] Setting up file watchers completed, took 2ms
[BUILDER] About to build [web]...
[BUILDER] Running build...
[BUILDER] Generating SDK summary...
[BUILDER] 2.4s elapsed, 3708/3709 actions completed.
[BUILDER] 3.5s elapsed, 3708/3709 actions completed.
[BUILDER] Generating SDK summary completed, took 2.8s
[BUILDER] 4.7s elapsed, 3785/3795 actions completed.
[BUILDER] 5.8s elapsed, 3857/3858 actions completed.
[BUILDER] 10.2s elapsed, 3857/3858 actions completed.
[BUILDER] 11.3s elapsed, 4436/4457 actions completed.
[BUILDER] Running `dart compile js` with -Djaspr.flags.release=true -O2 --libraries-spec=/nix/store/f53nadh5zgmpgsqqbsgx97wgpkm619jj-flutter-wrapped-3.22.2-sdk-linkt
[BUILDER] Running `dart compile js` with -Djaspr.flags.release=true -O2 --libraries-spec=/nix/store/f53nadh5zgmpgsqqbsgx97wgpkm619jj-flutter-wrapped-3.22.2-sdk-linkt
[BUILDER] Running `dart compile js` with -Djaspr.flags.release=true -O2 --libraries-spec=/nix/store/f53nadh5zgmpgsqqbsgx97wgpkm619jj-flutter-wrapped-3.22.2-sdk-linkt
[BUILDER] 13.2s elapsed, 4939/4942 actions completed.
[BUILDER] Compiled 10,606,220 input bytes (5,607,931 characters source) to 141,940 characters JavaScript in 1.25 seconds using 0.000 MB of memory
[BUILDER] Compiled 10,604,708 input bytes (5,606,419 characters source) to 134,790 characters JavaScript in 2.11 seconds using 0.000 MB of memory
[BUILDER] Compiled 10,608,828 input bytes (5,610,539 characters source) to 159,518 characters JavaScript in 2.51 seconds using 0.000 MB of memory
[BUILDER] Running build completed, took 15.4s
[BUILDER] Caching finalized dependency graph...
[BUILDER] Caching finalized dependency graph completed, took 100ms
[BUILDER] Creating merged output dir `build/jaspr`...
[BUILDER] Creating merged output dir `build/jaspr` completed, took 17ms
[BUILDER] Writing asset manifest...
[BUILDER] Writing asset manifest completed, took 0ms
Completed building web assets.
Building server app...
[BUILDER] Succeeded after 15.5s with 733 outputs (7670 actions)
[SERVER] Running server app...
[SERVER] [INFO] Running server in release mode
[SERVER] Serving at http://0.0.0.0:8080
Generating routes...
Generating route "/"...
[SERVER] Hello server
Generating route "/about"...
Completed building project to /build/jaspr.

doctor for example

henry@nixos:~/work/voyver_website/voyver_website (jaspr)$ jaspr doctor
PathAccessException: Cannot open file, path = '/home/henry/.bash_profile' (OS Error: Permission denied, errno = 13)
[✓] Jaspr CLI (Version 0.15.1)
  • Dart Version 3.4.3 (stable) (Tue Jun 4 19:51:39 2024 +0000) on "linux_x64" at dart
  • Running on linux Linux 6.9.7 #1-NixOS SMP PREEMPT_DYNAMIC Thu Jun 27 11:52:32 UTC 2024 - Locale en_US.UTF-8
  • Analytics: Enabled

[✓] Current Project
  • Dependencies on core packages:
    • jaspr: ^0.15.1
    • jaspr_builder: ^0.15.1 (dev)
    • jaspr_web_compilers: ^4.0.10 (dev)
    • jaspr_router: ^0.5.1
    • jaspr_tailwind: ^0.3.0 (dev)
  • Rendering mode: static
  • Uses jaspr compilers: true
  • Uses flutter embedding: false
neoacevedo commented 2 weeks ago

Some similar started to happens in my side. When I run jaspr create project myproject I'm getting errors with flutter sdk version:

✓ Generated 25 file(s) (0.8s)
✗ [CLI] [ERROR] The current Dart SDK version is 3.3.4. (1.8s)
[CLI] [ERROR] 
[CLI] [ERROR] Because jaspr_lints >=0.1.1 depends on custom_lint_builder 0.6.5 which depends on analyzer ^6.6.0, jaspr_lints >=0.1.1 requires analyzer ^6.6.0.
[CLI] [ERROR] And because analyzer >=6.6.0 <6.9.0 depends on macros >=0.1.2-main.3 <0.1.3, jaspr_lints >=0.1.1 requires macros >=0.1.2-main.3 <0.1.3 or analyzer ^6.9.0.
[CLI] [ERROR] And because macros >=0.1.0-main.0 requires SDK version >=3.4.0-256.0.dev <4.0.0 and analyzer >=6.8.0 depends on collection ^1.19.0, jaspr_lints >=0.1.1 requires collection ^1.19.0.
[CLI] [ERROR] So, because collection >=1.19.0 requires SDK version ^3.4.0 and myproject depends on jaspr_lints ^0.1.1, version solving failed.
✗ [CLI]  (10.0s)
Shutting down...
Created project myproject! In order to get started, run the following commands:

cd myproject
jaspr serve

jaspr doctor:

[✓] Jaspr CLI (Version 0.15.1)
  • Dart Version 3.3.4 (stable) (Tue Apr 16 19:56:12 2024 +0000) on "linux_x64" at /home/nestor/bin/flutter-sdk/bin/cache/dart-sdk/bin/dart
  • Running on linux Linux 6.10.11-1-default #1 SMP PREEMPT_DYNAMIC Thu Sep 19 07:33:24 UTC 2024 (bd33620) - Locale es_CO.UTF-8
  • Analytics: Enabled

[✓] Current Project
  • Dependencies on core packages:
    • jaspr: ^0.15.1
    • jaspr_builder: ^0.15.1 (dev)
    • jaspr_web_compilers: ^4.0.10 (dev)
    • jaspr_router: ^0.5.1
  • Rendering mode: client
  • Uses jaspr compilers: true
  • Uses flutter embedding: false
schultek commented 1 week ago

I updated the sdk constraint of jaspr_lints, so you will get a better error message. This will be released with the next version.