Skip to content
Merged
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: 0 additions & 7 deletions .flowconfig

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ jobs:
- name: elm-tooling install
run: npx --no-install elm-tooling install

- name: Flow
run: npx --no-install flow check
- name: TypeScript
run: npx --no-install tsc

- name: ESLint
run: npx --no-install eslint --report-unused-disable-directives .
Expand Down
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ export default [
'**/elm-stuff',
'**/fixtures',
'**/templates',
'**/flow-typed',
],
},
{
rules: {
...js.configs.recommended.rules,
'no-fallthrough': 'off', // Caught by TypeScript instead.
'no-inner-declarations': 'off',
'no-prototype-builtins': 'off',
'no-unused-vars': ['error', { caughtErrorsIgnorePattern: '^_' }],
Expand Down
66 changes: 39 additions & 27 deletions lib/Compile.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
//@flow

const { supportsColor } = require('./chalk');
const spawn = require('cross-spawn');
const ElmCompiler = require('./ElmCompiler');
const Report = require('./Report');

function compile(
cwd /*: string */,
testFile /*: string */,
dest /*: string */,
pathToElmBinary /*: string */,
report /*: typeof Report.Report */
) /*: Promise<void> */ {
/**
* @param { string } cwd
* @param { string } testFile
* @param { string } dest
* @param { string } pathToElmBinary
* @param { import('./Report').Report } report
* @returns { Promise<void> }
*/
function compile(cwd, testFile, dest, pathToElmBinary, report) {
return new Promise((resolve, reject) => {
const compileProcess = ElmCompiler.compile([testFile], {
output: dest,
Expand All @@ -30,21 +30,26 @@ function compile(
});
}

/**
* @param { Array<string> } testFilePaths
* @param { string } projectRootDir
* @param { string } pathToElmBinary
* @param { import('./Report').Report } report
* @returns { Promise<void> }
*/
function compileSources(
testFilePaths /*: Array<string> */,
projectRootDir /*: string */,
pathToElmBinary /*: string */,
report /*: typeof Report.Report */
) /*: Promise<void> */ {
testFilePaths,
projectRootDir,
pathToElmBinary,
report
) {
return new Promise((resolve, reject) => {
const compilerReport = report === 'json' ? report : undefined;

const compileProcess = ElmCompiler.compile(testFilePaths, {
output: '/dev/null',
cwd: projectRootDir,
spawn: spawnCompiler({ ignoreStdout: false, cwd: projectRootDir }),
pathToElm: pathToElmBinary,
report: compilerReport,
reportJson: report === 'json',
processOpts: processOptsForReporter(report),
});

Expand All @@ -58,12 +63,16 @@ function compileSources(
});
}

/**
* @param { { ignoreStdout: boolean, cwd: string } } options
* @returns { (
pathToElm: string,
processArgs: Array<string>,
processOpts: import('child_process').SpawnOptions
) => import('child_process').ChildProcess }
*/
function spawnCompiler({ ignoreStdout, cwd }) {
return (
pathToElm /*: string */,
processArgs /*: Array<string> */,
processOpts /*: child_process$spawnOpts */
) => {
return (pathToElm, processArgs, processOpts) => {
// It might seem useless to specify 'pipe' and then just write all data to
// `process.stdout`/`process.stderr`, but it does make a difference: The Elm
// compiler turns off colors when it’s used in a pipe. In summary:
Expand All @@ -73,6 +82,7 @@ function spawnCompiler({ ignoreStdout, cwd }) {
const stdout = ignoreStdout ? 'ignore' : supportsColor ? 'inherit' : 'pipe';
const stderr = supportsColor ? 'inherit' : 'pipe';

/** @type { import('child_process').SpawnOptions } */
const finalOpts = {
env: process.env,
...processOpts,
Expand All @@ -82,21 +92,23 @@ function spawnCompiler({ ignoreStdout, cwd }) {

const child = spawn(pathToElm, processArgs, finalOpts);

if (stdout === 'pipe') {
if (stdout === 'pipe' && child.stdout !== null) {
child.stdout.on('data', (data) => process.stdout.write(data));
}

if (stderr === 'pipe') {
if (stderr === 'pipe' && child.stderr !== null) {
child.stderr.on('data', (data) => process.stderr.write(data));
}

return child;
};
}

function processOptsForReporter(
report /*: typeof Report.Report */
) /*: child_process$spawnOpts */ {
/**
* @param { import('./Report').Report } report
* @returns { import('child_process').SpawnOptions }
*/
function processOptsForReporter(report) {
if (Report.isMachineReadable(report)) {
return { env: process.env, stdio: ['ignore', 'ignore', process.stderr] };
} else {
Expand Down
Loading
Loading