Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 110 additions & 5 deletions CHANGELOG.md

Large diffs are not rendered by default.

41 changes: 23 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,9 @@ The `--package` flag is also available for many more commands, such as `build`,

An important property of this "monorepo setup" is that the `output` folder will be shared between all the packages: they will share the same build package set (or build plan when using the solver) and they will be all build together.

> [!NOTE]\
> Remember that you can't have multiple modules with the same name in a single project. This usually happens with the `Main` module being defined multiple times. Rename these modules to something unique.

### Polyrepo support

There might be cases where you want to have multiple loosely-connected codebases in the same repository that do _not_ necessarily build together all the time. This is sometimes called [a "polyrepo"][monorepo-tools].
Expand Down Expand Up @@ -1448,6 +1451,26 @@ package:
# see https://yaml-multiline.info/
- byPrefix: >
"Data.Map"'s `Semigroup instance`

# Specify whether to censor warnings coming from the compiler
# for files from this package's test code.
# Optional and can be one of two possible values
censorTestWarnings:
# Value 1: "all" - All warnings are censored
all

# Value 2: `NonEmptyArray (Either String { byPrefix :: String })`
# - String values:
# censor warnings if the code matches this code
# - { byPrefix } values:
# censor warnings if the warning's message
# starts with the given text
- CodeName
# Note: when using `byPrefix`, use the `>` for block-string:
# see https://yaml-multiline.info/
- byPrefix: >
"Data.Map"'s `Semigroup instance`

# Convert compiler warnings for files in this package's src code
# into errors that can fail the build.
# Optional and defaults to false
Expand Down Expand Up @@ -1498,24 +1521,6 @@ package:
# Optional boolean that defaults to `false`.
pedanticPackages: false

# Specify whether to censor warnings coming from the compiler
# for files from this package's test code.
# Optional and can be one of two possible values
censorTestWarnings:
# Value 1: "all" - All warnings are censored
all

# Value 2: `NonEmptyArray (Either String { byPrefix :: String })`
# - String values:
# censor warnings if the code matches this code
# - { byPrefix } values:
# censor warnings if the warning's message
# starts with the given text
- CodeName
# Note: when using `byPrefix`, use the `>` for block-string:
# see https://yaml-multiline.info/
- byPrefix: >
"Data.Map"'s `Semigroup instance`
# Convert compiler warnings for files from this package's test code
# into errors that can fail the build.
# Optional and defaults to false
Expand Down
4 changes: 2 additions & 2 deletions core/src/Config.purs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ type TestConfig =
{ main :: String
, execArgs :: Maybe (Array String)
, dependencies :: Dependencies
, censorTestWarnings :: Maybe CensorBuildWarnings
, strict :: Maybe Boolean
, pedanticPackages :: Maybe Boolean
}
Expand All @@ -177,7 +176,6 @@ testConfigCodec :: CJ.Codec TestConfig
testConfigCodec = CJ.named "TestConfig" $ CJS.objectStrict
$ CJS.recordProp @"main" CJ.string
$ CJS.recordPropOptional @"execArgs" (CJ.array CJ.string)
$ CJS.recordPropOptional @"censorTestWarnings" censorBuildWarningsCodec
$ CJS.recordPropOptional @"strict" CJ.boolean
$ CJS.recordPropOptional @"pedanticPackages" CJ.boolean
$ CJS.recordProp @"dependencies" dependenciesCodec
Expand All @@ -196,13 +194,15 @@ backendConfigCodec = CJ.named "BackendConfig" $ CJS.objectStrict

type PackageBuildOptionsInput =
{ censorProjectWarnings :: Maybe CensorBuildWarnings
, censorTestWarnings :: Maybe CensorBuildWarnings
, strict :: Maybe Boolean
, pedanticPackages :: Maybe Boolean
}

packageBuildOptionsCodec :: CJ.Codec PackageBuildOptionsInput
packageBuildOptionsCodec = CJ.named "PackageBuildOptionsInput" $ CJS.objectStrict
$ CJS.recordPropOptional @"censorProjectWarnings" censorBuildWarningsCodec
$ CJS.recordPropOptional @"censorTestWarnings" censorBuildWarningsCodec
$ CJS.recordPropOptional @"strict" CJ.boolean
$ CJS.recordPropOptional @"pedanticPackages" CJ.boolean
$ CJS.record
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions spago.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ package:
censorProjectWarnings:
- WildcardInferredType
- ImplicitQualifiedImportReExport
censorTestWarnings:
- ImplicitQualifiedImportReExport
- ImplicitQualifiedImport
dependencies:
- aff
- aff-promise
Expand Down Expand Up @@ -73,9 +76,6 @@ package:
- unsafe-coerce
test:
main: Test.Spago
censorTestWarnings:
- ImplicitQualifiedImportReExport
- ImplicitQualifiedImport
dependencies:
- exceptions
- quickcheck
Expand Down
10 changes: 5 additions & 5 deletions src/Spago/Command/Init.purs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ defaultConfig { name, withWorkspace, testModuleName } = do
pkg =
{ name
, dependencies: [ "effect", "console", "prelude" ]
, test: Just { moduleMain: testModuleName, strict: Nothing, censorTestWarnings: Nothing, pedanticPackages: Nothing, dependencies: Nothing }
, test: Just { moduleMain: testModuleName, strict: Nothing, pedanticPackages: Nothing, dependencies: Nothing }
, build: Nothing
}
defaultConfig' case withWorkspace of
Expand All @@ -173,14 +173,14 @@ type DefaultConfigPackageOptions =
Maybe
{ moduleMain :: String
, strict :: Maybe Boolean
, censorTestWarnings :: Maybe Config.CensorBuildWarnings
, pedanticPackages :: Maybe Boolean
, dependencies :: Maybe Config.Dependencies
}
, build ::
Maybe
{ strict :: Maybe Boolean
, censorProjectWarnings :: Maybe Config.CensorBuildWarnings
, censorTestWarnings :: Maybe Config.CensorBuildWarnings
, pedanticPackages :: Maybe Boolean
}
}
Expand Down Expand Up @@ -212,17 +212,17 @@ defaultConfig' opts =
{ name
, dependencies: Dependencies $ Map.fromFoldable $ map mkDep dependencies
, description: Nothing
, build: build <#> \{ censorProjectWarnings, strict, pedanticPackages } ->
, build: build <#> \{ censorProjectWarnings, censorTestWarnings, strict, pedanticPackages } ->
{ censorProjectWarnings
, censorTestWarnings
, strict
, pedanticPackages
}
, run: Nothing
, test: test <#> \{ moduleMain, censorTestWarnings, strict, pedanticPackages, dependencies: testDeps } ->
, test: test <#> \{ moduleMain, strict, pedanticPackages, dependencies: testDeps } ->
{ dependencies: fromMaybe (Dependencies Map.empty) testDeps
, execArgs: Nothing
, main: moduleMain
, censorTestWarnings
, strict
, pedanticPackages
}
Expand Down
30 changes: 25 additions & 5 deletions src/Spago/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@ const getOrElse = (node, key, fallback) => {
node.set(key, fallback);
}
return node.get(key);
}
};

export function addPackagesToConfigImpl(doc, isTest, newPkgs) {
const pkg = doc.get("package");

const deps = (() => {
if (isTest) {
const test = getOrElse(pkg, "test", doc.createNode({ main: "Test.Main", dependencies: [] }));
const test = getOrElse(
pkg,
"test",
doc.createNode({ main: "Test.Main", dependencies: [] }),
);
return getOrElse(test, "dependencies", doc.createNode([]));
} else {
return getOrElse(pkg, "dependencies", doc.createNode([]))
return getOrElse(pkg, "dependencies", doc.createNode([]));
}
})();

Expand Down Expand Up @@ -59,7 +63,9 @@ export function addPackagesToConfigImpl(doc, isTest, newPkgs) {
export function removePackagesFromConfigImpl(doc, isTest, shouldRemove) {
const pkg = doc.get("package");

const deps = isTest ? pkg.get("test").get("dependencies") : pkg.get("dependencies");
const deps = isTest
? pkg.get("test").get("dependencies")
: pkg.get("dependencies");
let newItems = [];
for (const el of deps.items) {
if (
Expand Down Expand Up @@ -124,8 +130,22 @@ export function migrateV1ConfigImpl(doc) {
return match.charAt(1).toUpperCase();
});
}
}

// move censorTestWarnings from test to build map
if (pair.key.value === "censorTestWarnings") {
const parent = _path.at(-2);
if (parent.key && parent.key.value === "test") {
hasChanged = true;
const root = _path.at(0);
const build = root.get("package").get("build");
build.set("censorTestWarnings", pair.value);

return Yaml.visit.REMOVE;
}
}
},
});

if (hasChanged) {
return doc;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Spago/Psa.purs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ toWorkspacePackagePathDecision { selected: { path, package }, psaCliFlags } = do
{ pathIsFromPackage: (testPath `Path.isPrefixOf` _)
, pathType: IsSrc
, strict: fromMaybe false $ psaCliFlags.strict <|> (package.test >>= _.strict)
, censorWarnings: package.test >>= _.censorTestWarnings
, censorWarnings: package.build >>= _.censorTestWarnings
}
]

Expand Down
2 changes: 1 addition & 1 deletion test-fixtures/build/migrate-config/migrated-spago.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ package:
main: Test.Main
execArgs: []
dependencies: []
censorTestWarnings: all
pedanticPackages: false
build:
censorProjectWarnings: all
pedanticPackages: false
censorTestWarnings: all
workspace:
packageSet:
registry: 50.4.0
Expand Down
90 changes: 35 additions & 55 deletions test/Prelude.purs
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,20 @@ shouldEqualStr v1 v2 =
let
renderNonPrinting =
String.replaceAll (String.Pattern "\r") (String.Replacement "␍")
>>> String.replaceAll (String.Pattern "\t") (String.Replacement "␉-->")
>>> String.replaceAll (String.Pattern "\t") (String.Replacement "␉-->")
in
when (v1 /= v2) do
fail $ Array.intercalate "\n"
[ ""
, "===== (Actual)"
, renderNonPrinting v1
, "====="
, " ≠"
, "===== (Expected)"
, renderNonPrinting v2
, "====="
, ""
]
when (v1 /= v2) do
fail $ Array.intercalate "\n"
[ ""
, "===== (Actual)"
, renderNonPrinting v1
, "====="
, " ≠"
, "===== (Expected)"
, renderNonPrinting v2
, "====="
, ""
]

checkFixture :: ∀ path. IsPath path => path -> FixturePath -> Aff Unit
checkFixture filepath fixturePath = checkFixture' filepath fixturePath (shouldEqualStr `on` String.trim)
Expand Down Expand Up @@ -325,83 +325,63 @@ configurePackageSection initialOptions = snd <<< Array.foldl (\c f -> f c)

configAddSrcStrict :: Tuple String Init.DefaultConfigPackageOptions -> Tuple String Init.DefaultConfigPackageOptions
configAddSrcStrict = map \r -> r
{ build = Just
{ strict: Just true
, censorProjectWarnings: r.build >>= _.censorProjectWarnings
, pedanticPackages: r.build >>= _.pedanticPackages
{ build = r.build <#> _
{ strict = Just true
}
}

configAddSrcPedantic :: Tuple String Init.DefaultConfigPackageOptions -> Tuple String Init.DefaultConfigPackageOptions
configAddSrcPedantic = map \r -> r
{ build = Just
{ strict: r.build >>= _.strict
, censorProjectWarnings: r.build >>= _.censorProjectWarnings
, pedanticPackages: Just true
{ build = r.build <#> _
{ pedanticPackages = Just true
}
}

configAddSrcCensor :: Config.CensorBuildWarnings -> Tuple String Init.DefaultConfigPackageOptions -> Tuple String Init.DefaultConfigPackageOptions
configAddSrcCensor censors = map \r -> r
{ build = Just
{ strict: r.build >>= _.strict
, censorProjectWarnings: Just censors
, pedanticPackages: r.build >>= _.pedanticPackages
{ build = r.build <#> _
{ censorProjectWarnings = Just censors
}
}

configAddTestMain :: Tuple String Init.DefaultConfigPackageOptions -> Tuple String Init.DefaultConfigPackageOptions
configAddTestMain (Tuple packageName r) = Tuple packageName $ r
{ test = Just
{ moduleMain: mkTestModuleName packageName
, strict: r.test >>= _.strict
, censorTestWarnings: r.test >>= _.censorTestWarnings
, pedanticPackages: r.test >>= _.pedanticPackages
, dependencies: r.test >>= _.dependencies
{ test = r.test <#> _
{ moduleMain = mkTestModuleName packageName
}
}

configAddTestStrict :: Tuple String Init.DefaultConfigPackageOptions -> Tuple String Init.DefaultConfigPackageOptions
configAddTestStrict (Tuple packageName r) = Tuple packageName $ r
{ test = Just
{ moduleMain: mkTestModuleName packageName
, strict: Just true
, censorTestWarnings: r.test >>= _.censorTestWarnings
, pedanticPackages: r.test >>= _.pedanticPackages
, dependencies: r.test >>= _.dependencies
{ test = r.test <#> _
{ moduleMain = mkTestModuleName packageName
, strict = Just true
}
}

configAddTestPedantic :: Tuple String Init.DefaultConfigPackageOptions -> Tuple String Init.DefaultConfigPackageOptions
configAddTestPedantic (Tuple packageName r) = Tuple packageName $ r
{ test = Just
{ moduleMain: mkTestModuleName packageName
, strict: r.test >>= _.strict
, censorTestWarnings: r.test >>= _.censorTestWarnings
, pedanticPackages: Just true
, dependencies: r.test >>= _.dependencies
{ test = r.test <#> _
{ moduleMain = mkTestModuleName packageName
, pedanticPackages = Just true
}
}

configAddTestCensor :: Config.CensorBuildWarnings -> Tuple String Init.DefaultConfigPackageOptions -> Tuple String Init.DefaultConfigPackageOptions
configAddTestCensor censors (Tuple packageName r) = Tuple packageName $ r
{ test = Just
{ moduleMain: mkTestModuleName packageName
, strict: r.test >>= _.strict
, censorTestWarnings: Just censors
, pedanticPackages: r.test >>= _.pedanticPackages
, dependencies: r.test >>= _.dependencies
{ test = r.test <#> _
{ moduleMain = mkTestModuleName packageName
}
, build = r.build <#> _
{ censorTestWarnings = Just censors
}
}

configAddTestDependencies :: Array String -> Tuple String Init.DefaultConfigPackageOptions -> Tuple String Init.DefaultConfigPackageOptions
configAddTestDependencies deps (Tuple packageName r) = Tuple packageName $ r
{ test = Just
{ moduleMain: mkTestModuleName packageName
, strict: r.test >>= _.strict
, censorTestWarnings: r.test >>= _.censorTestWarnings
, pedanticPackages: r.test >>= _.pedanticPackages
, dependencies: Just $ maybe (mkDependencies deps) (append (mkDependencies deps)) $ r.test >>= _.dependencies
{ test = r.test <#> _
{ moduleMain = mkTestModuleName packageName
, dependencies = Just $ maybe (mkDependencies deps) (append (mkDependencies deps)) $ r.test >>= _.dependencies
}
}

Expand Down
Loading
Loading