Skip to content
Open
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
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
"bin": {
"please": "please"
},
"//": "The ugly `bash -c` contortions in the scripts below are to work around <https://github.com/npm/cli/issues/8583>.",
"scripts": {
"0": "node ./dist/language/cli/0.js",
"1": "node ./dist/language/cli/1.js",
"2": "node ./dist/language/cli/2.js",
"0": "bash -c 'node ./dist/language/cli/0.js \"$@\"; echo' bash",
"1": "bash -c 'node ./dist/language/cli/1.js \"$@\"; echo' bash",
"2": "bash -c 'node ./dist/language/cli/2.js \"$@\"; echo' bash",
"build": "tsc --build tsconfig.app.json --force",
"build:tests": "tsc --project tsconfig.app.json --outDir dist-test --declarationDir dist && tsc --build tsconfig.test.json",
"clean": "rm -rf dist* *.tsbuildinfo",
Expand Down
14 changes: 0 additions & 14 deletions src/language/cli/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,5 @@ export const writeOutput = (
throw new Error(outputAsString.value.message)
} else {
writeStream.write(outputAsString.value)

// Writing a newline ensures that output is flushed before terminating,
// otherwise nothing may be printed to the console. See:
// - <https://github.com/nodejs/node/issues/6379>
// - <https://github.com/nodejs/node/issues/6456>
// - <https://github.com/nodejs/node/issues/2972>
// - …and many other near-duplicate issues
//
// I've tried other workarounds such as explicitly terminating via
// `process.exit`, passing a callback to `writeStream.write` (ensuring the
// returned `Promise` is not resolved until it is called), and explicitly
// calling `writeStream.end`/`writeStream.uncork` and so far this is the
// only workaround which reliably results in the desired behavior.
writeStream.write('\n')
}
}
57 changes: 29 additions & 28 deletions src/language/compiling/unparsing.test.ts

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions src/language/unparsing.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Either } from '@matt.kantor/either'
import either from '@matt.kantor/either'
import type { UnserializableValueError } from './errors.js'
import type { Atom, Molecule } from './parsing.js'
import type { Notation } from './unparsing/unparsing-utilities.js'
Expand All @@ -13,6 +14,9 @@ export const unparse = (
value: Atom | Molecule,
notation: Notation,
): Either<UnserializableValueError, string> =>
typeof value === 'object'
? notation.molecule(value, notation)
: notation.atom(value)
either.map(
typeof value === 'object'
? notation.molecule(value, notation)
: notation.atom(value),
output => output.concat(notation.suffix),
)
1 change: 1 addition & 0 deletions src/language/unparsing/inline-plz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ const unparseMolecule = moleculeUnparser(
export const inlinePlz: Notation = {
atom: unparseAtom,
molecule: unparseMolecule,
suffix: '',
}
1 change: 1 addition & 0 deletions src/language/unparsing/pretty-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ const unparseAtomOrMolecule = (value: Atom | Molecule) =>
export const prettyJson: Notation = {
atom: unparseAtom,
molecule: unparseMolecule,
suffix: '\n',
}
1 change: 1 addition & 0 deletions src/language/unparsing/pretty-plz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ const unparseMolecule = moleculeUnparser(
export const prettyPlz: Notation = {
atom: unparseAtom,
molecule: unparseMolecule,
suffix: '\n',
}
1 change: 1 addition & 0 deletions src/language/unparsing/sugar-free-pretty-plz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ const unparseAtomOrMolecule = (value: Atom | Molecule) =>
export const sugarFreePrettyPlz: Notation = {
atom: unparseAtom,
molecule: unparseMolecule,
suffix: '\n',
}
1 change: 1 addition & 0 deletions src/language/unparsing/unparsing-utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type Notation = {
value: Molecule,
notation: Notation,
) => Either<UnserializableValueError, string>
readonly suffix: string
}

export const indent = (spaces: number, textToIndent: string) => {
Expand Down