Skip to content

Commit

Permalink
Export named concurrently + fix TS errors with Node16 (#456)
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavohenke authored Feb 4, 2024
1 parent bb8436b commit feac92b
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 24 deletions.
2 changes: 1 addition & 1 deletion bin/concurrently.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';

import * as defaults from '../src/defaults';
import concurrently from '../src/index';
import { concurrently } from '../src/index';
import { epilogue } from './epilogue';

// Clean-up arguments (yargs expects only the arguments after the program name)
Expand Down
7 changes: 7 additions & 0 deletions index.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* While in local development, make sure you've run `pnpm run build` first.
*/
import { concurrently } from './dist/src/index.js';

export * from './dist/src/index.js';
export default concurrently;
11 changes: 11 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* While in local development, make sure you've run `pnpm run build` first.
*/
import { concurrently } from './dist/src/index.js';

export * from './dist/src/index.js';
// @ts-expect-error ignore the usage of `export =` along with `export default`.
// This is seemingly fine, but the file needs to be included in the TS project, which can't be done
// due to importing from `dist`. See https://stackoverflow.com/q/42609768/2083599
export = concurrently;
export default concurrently;
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const concurrently = require('./dist/src/index.js');

module.exports = exports = concurrently.default;
// For require()
module.exports = exports = concurrently.concurrently;

// For TS + import syntax; mimics `export default`
exports.default = exports;

Object.assign(exports, concurrently);
4 changes: 2 additions & 2 deletions index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* While in local development, make sure you've run `pnpm run build` first.
*/

import concurrently from './dist/src/index.js';
import { concurrently } from './dist/src/index.js';

// NOTE: the star reexport doesn't work in Node <12.20, <14.13 and <15.
export * from './dist/src/index.js';

export default concurrently.default;
export default concurrently;
16 changes: 11 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "8.2.2",
"description": "Run commands concurrently",
"main": "index.js",
"types": "dist/src/index.d.ts",
"types": "index.d.ts",
"type": "commonjs",
"bin": {
"concurrently": "./dist/bin/concurrently.js",
Expand All @@ -14,10 +14,14 @@
},
"exports": {
".": {
"types": "./dist/src/index.d.ts",
"import": "./index.mjs",
"require": "./index.js",
"default": "./index.js"
"import": {
"types": "./index.d.mts",
"default": "./index.mjs"
},
"require": {
"types": "./index.d.ts",
"default": "./index.js"
}
},
"./package.json": "./package.json"
},
Expand Down Expand Up @@ -94,7 +98,9 @@
"files": [
"dist",
"index.js",
"index.d.ts",
"index.mjs",
"index.d.mts",
"!**/fixtures",
"!**/*.spec.js",
"!**/*.spec.d.ts"
Expand Down
28 changes: 13 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Readable } from 'stream';

import { CloseEvent, Command, CommandIdentifier, TimerEvent } from './command';
import {
concurrently,
concurrently as createConcurrently,
ConcurrentlyCommandInput,
ConcurrentlyOptions as BaseConcurrentlyOptions,
ConcurrentlyResult,
Expand Down Expand Up @@ -91,10 +91,10 @@ export type ConcurrentlyOptions = BaseConcurrentlyOptions & {
additionalArguments?: string[];
};

export default (
export function concurrently(
commands: ConcurrentlyCommandInput[],
options: Partial<ConcurrentlyOptions> = {},
) => {
) {
const logger = new Logger({
hide: options.hide,
prefixFormat: options.prefix,
Expand All @@ -103,7 +103,7 @@ export default (
timestampFormat: options.timestampFormat,
});

return concurrently(commands, {
return createConcurrently(commands, {
maxProcesses: options.maxProcesses,
raw: options.raw,
successCondition: options.successCondition,
Expand Down Expand Up @@ -141,28 +141,26 @@ export default (
prefixColors: options.prefixColors || [],
additionalArguments: options.additionalArguments,
});
};
}

// Export all flow controllers, types, and the main concurrently function,
// so that 3rd-parties can use them however they want

// Main
export { ConcurrentlyCommandInput, ConcurrentlyResult, createConcurrently, Logger };

// Command specific
export { CloseEvent, Command, CommandIdentifier, TimerEvent };

// Flow controllers
export {
CloseEvent,
// Command specific
Command,
CommandIdentifier,
concurrently,
ConcurrentlyCommandInput,
ConcurrentlyResult,
// Flow controllers
FlowController,
InputHandler,
KillOnSignal,
KillOthers,
LogError,
LogExit,
Logger,
LogOutput,
LogTimings,
RestartProcess,
TimerEvent,
};

0 comments on commit feac92b

Please sign in to comment.