Skip to content

Commit

Permalink
Fix lockfile not updating when a local package set changed on disk (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
f-f authored Mar 13, 2024
1 parent 29ac481 commit e4c8dcd
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 37 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1231,11 +1231,9 @@ workspace:
registry: 11.10.0
# Or it could just point to a URL of a custom package set
# See the "Custom package sets" section for more info on making one.
# The `hash` field is actually optional and you should not add it.
# It will be tacked on by Spago, to not download the set over and over.
# Remove this field if you'd like Spago to fetch from the remote again.
url: https://raw.githubusercontent.com/purescript/package-sets/psc-0.15.7-20230207/packages.json
hash: sha256-UZaygzoqEhhYh2lzUqbiNfOR9J+WNRc9SkQPmoo90jM=
# It is also possible to point to a local package set instead:
path: ./my-custom-package-set.json

# This section defines any other packages that you'd like to include
# in the build. It's optional, in case you just want to use the ones
Expand Down
6 changes: 6 additions & 0 deletions src/Spago/Config.purs
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,12 @@ shouldComputeNewLockfile { workspace, workspacePackages } workspaceLock =
|| (fromMaybe Map.empty workspace.extra_packages /= workspaceLock.extra_packages)
-- and the package set address needs to match - we have no way to match the package set contents at this point, so we let it be
|| (workspace.package_set /= map _.address workspaceLock.package_set)
-- and the package set is not a local file - if it is then we always recompute the lockfile because we have no way to check if it's changed
||
( case workspace.package_set of
Just (Core.SetFromPath _) -> true
_ -> false
)

getPackageLocation :: PackageName -> Package -> FilePath
getPackageLocation name = Paths.mkRelative <<< case _ of
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compiler": "0.15.10",
"published": "2023-09-30",
"version": "1.0.0",
"packages": {
"prelude": "6.0.1",
"console": "6.1.0",
"effect": "4.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compiler": "0.15.10",
"published": "2023-09-30",
"version": "1.0.0",
"packages": {
"prelude": "6.0.1",
"typelevel-prelude": "7.0.0",
"console": "6.1.0",
"effect": "4.0.0"
}
}
42 changes: 42 additions & 0 deletions test-fixtures/build/local-package-set-lockfile/spago.lock.new
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
workspace:
packages:
local-package-set-lockfile:
path: ./
dependencies:
- console
- effect
- prelude
test_dependencies: []
build_plan:
- console
- effect
- prelude
package_set:
address:
path: ./local-package-set.json
compiler: ">=0.15.10 <0.16.0"
content:
console: 6.1.0
effect: 4.0.0
prelude: 6.0.1
typelevel-prelude: 7.0.0
extra_packages: {}
packages:
console:
type: registry
version: 6.1.0
integrity: sha256-CxmAzjgyuGDmt9FZW51VhV6rBPwR6o0YeKUzA9rSzcM=
dependencies:
- effect
- prelude
effect:
type: registry
version: 4.0.0
integrity: sha256-eBtZu+HZcMa5HilvI6kaDyVX3ji8p0W9MGKy2K4T6+M=
dependencies:
- prelude
prelude:
type: registry
version: 6.0.1
integrity: sha256-o8p6SLYmVPqzXZhQFd2hGAWEwBoXl1swxLG/scpJ0V0=
dependencies: []
41 changes: 41 additions & 0 deletions test-fixtures/build/local-package-set-lockfile/spago.lock.old
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
workspace:
packages:
local-package-set-lockfile:
path: ./
dependencies:
- console
- effect
- prelude
test_dependencies: []
build_plan:
- console
- effect
- prelude
package_set:
address:
path: ./local-package-set.json
compiler: ">=0.15.10 <0.16.0"
content:
console: 6.1.0
effect: 4.0.0
prelude: 6.0.1
extra_packages: {}
packages:
console:
type: registry
version: 6.1.0
integrity: sha256-CxmAzjgyuGDmt9FZW51VhV6rBPwR6o0YeKUzA9rSzcM=
dependencies:
- effect
- prelude
effect:
type: registry
version: 4.0.0
integrity: sha256-eBtZu+HZcMa5HilvI6kaDyVX3ji8p0W9MGKy2K4T6+M=
dependencies:
- prelude
prelude:
type: registry
version: 6.0.1
integrity: sha256-o8p6SLYmVPqzXZhQFd2hGAWEwBoXl1swxLG/scpJ0V0=
dependencies: []
10 changes: 10 additions & 0 deletions test-fixtures/build/local-package-set-lockfile/spago.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package:
name: local-package-set-lockfile
dependencies:
- console
- effect
- prelude
workspace:
package_set:
path: ./local-package-set.json
extra_packages: {}
76 changes: 43 additions & 33 deletions test/Spago/Build.purs
Original file line number Diff line number Diff line change
Expand Up @@ -101,35 +101,45 @@ spec = Spec.around withTempDir do
}
spago [ "build" ] >>= shouldBeFailure

Spec.it "building with a lockfile doesn't need the Registry repo" \{ spago, fixture } -> do
spago [ "init", "--name", "aaa", "--package-set", "33.0.0" ] >>= shouldBeSuccess
spago [ "build" ] >>= shouldBeSuccess
-- Check that we have written the lockfile
checkFixture "spago.lock" (fixture "spago.lock")
-- Then remove the registry repo
FSA.rm' Paths.registryPath { force: true, recursive: true, retryDelay: 0, maxRetries: 0 }
-- And check that we can still build
spago [ "build" ] >>= shouldBeSuccess
-- And that we still don't have the registry
FS.exists Paths.registryPath `Assert.shouldReturn` false

Spec.it "using the --pure flag does not refresh the lockfile" \{ spago, fixture } -> do
spago [ "init", "--name", "aaa", "--package-set", "33.0.0" ] >>= shouldBeSuccess
spago [ "build" ] >>= shouldBeSuccess
-- Check that we have written the lockfile
checkFixture "spago.lock" (fixture "spago.lock")
-- Update the config
let
conf = Init.defaultConfig
{ name: mkPackageName "aaa"
, testModuleName: "Test.Main"
, withWorkspace: Just { setVersion: Just $ mkVersion "33.0.0" }
}
FS.writeYamlFile Config.configCodec "spago.yaml"
(conf { package = conf.package # map (\pkg -> pkg { dependencies = pkg.dependencies <> mkDependencies [ "maybe" ] }) })
-- Check that building with --pure does not refresh the lockfile
spago [ "build", "--pure" ] >>= shouldBeSuccess
checkFixture "spago.lock" (fixture "spago.lock")
Spec.describe "lockfile" do
Spec.it "building with a lockfile doesn't need the Registry repo" \{ spago, fixture } -> do
spago [ "init", "--name", "aaa", "--package-set", "33.0.0" ] >>= shouldBeSuccess
spago [ "build" ] >>= shouldBeSuccess
-- Check that we have written the lockfile
checkFixture "spago.lock" (fixture "spago.lock")
-- Then remove the registry repo
FSA.rm' Paths.registryPath { force: true, recursive: true, retryDelay: 0, maxRetries: 0 }
-- And check that we can still build
spago [ "build" ] >>= shouldBeSuccess
-- And that we still don't have the registry
FS.exists Paths.registryPath `Assert.shouldReturn` false

Spec.it "using the --pure flag does not refresh the lockfile" \{ spago, fixture } -> do
spago [ "init", "--name", "aaa", "--package-set", "33.0.0" ] >>= shouldBeSuccess
spago [ "build" ] >>= shouldBeSuccess
-- Check that we have written the lockfile
checkFixture "spago.lock" (fixture "spago.lock")
-- Update the config
let
conf = Init.defaultConfig
{ name: mkPackageName "aaa"
, testModuleName: "Test.Main"
, withWorkspace: Just { setVersion: Just $ mkVersion "33.0.0" }
}
FS.writeYamlFile Config.configCodec "spago.yaml"
(conf { package = conf.package # map (\pkg -> pkg { dependencies = pkg.dependencies <> mkDependencies [ "maybe" ] }) })
-- Check that building with --pure does not refresh the lockfile
spago [ "build", "--pure" ] >>= shouldBeSuccess
checkFixture "spago.lock" (fixture "spago.lock")

Spec.it "lockfile is refreshed when the local package set changes" \{ spago, fixture } -> do
FS.copyTree { src: fixture "build/local-package-set-lockfile", dst: "." }
spago [ "build" ] >>= shouldBeSuccess
checkFixture "spago.lock" (fixture "build/local-package-set-lockfile/spago.lock.old")
FS.moveSync { src: "local-package-set.json", dst: "old-package-set.json" }
FS.moveSync { src: "new-package-set.json", dst: "local-package-set.json" }
spago [ "build" ] >>= shouldBeSuccess
checkFixture "spago.lock" (fixture "build/local-package-set-lockfile/spago.lock.new")

Spec.it "compiles with the specified backend" \{ spago, fixture } -> do
spago [ "init" ] >>= shouldBeSuccess
Expand Down Expand Up @@ -164,10 +174,10 @@ spec = Spec.around withTempDir do

Spec.it "failed build with many warnings and --json-errors does not truncate output" \{ spago, fixture } -> do
FS.copyTree { src: fixture "build/json-truncated-many-warnings", dst: "." }
spago [ "build", "--json-errors" ] >>= shouldBeFailureOutput case Process.platform of
Just Platform.Win32 -> fixture "build/json-truncated-many-warnings/warnings-windows.json"
_ -> fixture "build/json-truncated-many-warnings/warnings.json"
spago [ "build", "--json-errors" ] >>= shouldBeFailureOutput case Process.platform of
Just Platform.Win32 -> fixture "build/json-truncated-many-warnings/warnings-windows.json"
_ -> fixture "build/json-truncated-many-warnings/warnings.json"

Pedantic.spec

Monorepo.spec
Expand Down

0 comments on commit e4c8dcd

Please sign in to comment.