Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
update build tools (#409)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart authored Aug 3, 2023
1 parent 2dbbe93 commit 13481c1
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 1,004 deletions.
6 changes: 6 additions & 0 deletions .changeset/ten-crabs-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@effect/printer-ansi": patch
"@effect/printer": patch
---

update build tools
4 changes: 2 additions & 2 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = {
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@repo-tooling/dprint/recommended"
"plugin:@effect/recommended"
],
plugins: ["deprecation", "import", "sort-destructure-keys", "simple-import-sort", "codegen"],
rules: {
Expand Down Expand Up @@ -61,7 +61,7 @@ module.exports = {
"@typescript-eslint/no-array-constructor": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-namespace": "off",
"@repo-tooling/dprint/dprint": [
"@effect/dprint": [
"error",
{
config: {
Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@
"@babel/plugin-transform-modules-commonjs": "^7.22.5",
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.2",
"@effect-ts/build-utils": "0.40.7",
"@effect-ts/core": "^0.60.5",
"@effect/babel-plugin": "^0.2.0",
"@effect/build-utils": "^0.1.2",
"@effect/docgen": "^0.1.2",
"@effect/eslint-plugin": "^0.1.2",
"@effect/language-service": "0.0.19",
"@repo-tooling/eslint-plugin-dprint": "^0.0.4",
"@rollup/pluginutils": "^5.0.2",
"@types/chai": "^4.3.5",
"@types/node": "^20.4.5",
"@typescript-eslint/eslint-plugin": "^6.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/printer-ansi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"build": "pnpm build-all && pnpm build-pack",
"build-cjs": "babel build/esm --config-file ../../.babel.cjs.json --out-dir build/cjs --out-file-extension .js --source-maps",
"build-mjs": "babel build/esm --config-file ../../.babel.mjs.json --out-dir build/mjs --out-file-extension .mjs --source-maps",
"build-post": "build-utils pack-v4",
"build-post": "build-utils pack-v1",
"build-pack": "concurrently \"pnpm build-cjs\" \"pnpm build-mjs\" && pnpm build-post",
"build-all": "tsc -b tsconfig.json",
"build-watch": "tsc -b tsconfig.json --watch",
Expand Down
2 changes: 1 addition & 1 deletion packages/printer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"build": "pnpm build-all && pnpm build-pack",
"build-cjs": "babel build/esm --config-file ../../.babel.cjs.json --out-dir build/cjs --out-file-extension .js --source-maps",
"build-mjs": "babel build/esm --config-file ../../.babel.mjs.json --out-dir build/mjs --out-file-extension .mjs --source-maps",
"build-post": "build-utils pack-v4",
"build-post": "build-utils pack-v1",
"build-pack": "concurrently \"pnpm build-cjs\" \"pnpm build-mjs\" && pnpm build-post",
"build-all": "tsc -b tsconfig.json",
"build-watch": "tsc -b tsconfig.json --watch",
Expand Down
9 changes: 5 additions & 4 deletions packages/printer/src/internal/docTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,12 @@ interface DocTreeParser<S, A> {

const parserSucceed = <S, A>(value: A): DocTreeParser<S, A> => (stream) => Option.some([value, stream] as const)

const parserMap = <S, A, B>(self: DocTreeParser<S, A>, f: (a: A) => B): DocTreeParser<S, B> =>
(stream) => Option.map(self(stream), ([a, s]) => [f(a), s] as const)
const parserMap = <S, A, B>(self: DocTreeParser<S, A>, f: (a: A) => B): DocTreeParser<S, B> => (stream) =>
Option.map(self(stream), ([a, s]) => [f(a), s] as const)

const parserFlatMap = <S, A, B>(self: DocTreeParser<S, A>, f: (a: A) => DocTreeParser<S, B>): DocTreeParser<S, B> =>
(stream) => Option.flatMap(self(stream), ([a, s1]) => f(a)(s1))
const parserFlatMap =
<S, A, B>(self: DocTreeParser<S, A>, f: (a: A) => DocTreeParser<S, B>): DocTreeParser<S, B> => (stream) =>
Option.flatMap(self(stream), ([a, s1]) => f(a)(s1))

function many<S, A>(parser: DocTreeParser<S, A>): DocTreeParser<S, ReadonlyArray<A>> {
return (stream) =>
Expand Down
67 changes: 33 additions & 34 deletions packages/printer/src/internal/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,16 +236,15 @@ export const pretty = dual<
if (width._tag === "AvailablePerLine") {
return wadlerLeijen(
self,
(lineIndent, currentColumn) =>
(stream) => {
const remainingWidth = pageWidth.remainingWidth(
width.lineWidth,
width.ribbonFraction,
lineIndent,
currentColumn
)
return fitsPretty(stream, remainingWidth)
},
(lineIndent, currentColumn) => (stream) => {
const remainingWidth = pageWidth.remainingWidth(
width.lineWidth,
width.ribbonFraction,
lineIndent,
currentColumn
)
return fitsPretty(stream, remainingWidth)
},
options
)
}
Expand Down Expand Up @@ -311,32 +310,32 @@ export const smart = dual<

const fitsSmart = (lineWidth: number, ribbonFraction: number) => {
return (lineIndent: number, currentColumn: number, initialIndentY: Option.Option<number>) =>
<A>(stream: DocStream.DocStream<A>): boolean => {
const availableWidth = pageWidth.remainingWidth(
lineWidth,
ribbonFraction,
lineIndent,
currentColumn
)
let minNestingLevel: number
switch (initialIndentY._tag) {
// If `y` is `None`, then it is definitely not a hanging layout,
// so we will need to check `x` with the same minNestingLevel
// that any subsequent lines with the same indentation use
case "None": {
minNestingLevel = currentColumn
break
}
// If `y` is some, then `y` could be a (less wide) hanging layout,
// so we need to check `x` a bit more thoroughly to make sure we
// do not miss a potentially better fitting `y`
case "Some": {
minNestingLevel = Math.min(initialIndentY.value, currentColumn)
break
}
<A>(stream: DocStream.DocStream<A>): boolean => {
const availableWidth = pageWidth.remainingWidth(
lineWidth,
ribbonFraction,
lineIndent,
currentColumn
)
let minNestingLevel: number
switch (initialIndentY._tag) {
// If `y` is `None`, then it is definitely not a hanging layout,
// so we will need to check `x` with the same minNestingLevel
// that any subsequent lines with the same indentation use
case "None": {
minNestingLevel = currentColumn
break
}
// If `y` is some, then `y` could be a (less wide) hanging layout,
// so we need to check `x` a bit more thoroughly to make sure we
// do not miss a potentially better fitting `y`
case "Some": {
minNestingLevel = Math.min(initialIndentY.value, currentColumn)
break
}
return fitsSmartLoop(stream, availableWidth, minNestingLevel, lineWidth)
}
return fitsSmartLoop(stream, availableWidth, minNestingLevel, lineWidth)
}
}

const fitsSmartLoop = <A>(
Expand Down
Loading

0 comments on commit 13481c1

Please sign in to comment.