Skip to content

Commit feac92b

Browse files
authored
Export named concurrently + fix TS errors with Node16 (#456)
1 parent bb8436b commit feac92b

7 files changed

Lines changed: 51 additions & 24 deletions

File tree

bin/concurrently.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import yargs from 'yargs';
33
import { hideBin } from 'yargs/helpers';
44

55
import * as defaults from '../src/defaults';
6-
import concurrently from '../src/index';
6+
import { concurrently } from '../src/index';
77
import { epilogue } from './epilogue';
88

99
// Clean-up arguments (yargs expects only the arguments after the program name)

index.d.mts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*
2+
* While in local development, make sure you've run `pnpm run build` first.
3+
*/
4+
import { concurrently } from './dist/src/index.js';
5+
6+
export * from './dist/src/index.js';
7+
export default concurrently;

index.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* While in local development, make sure you've run `pnpm run build` first.
3+
*/
4+
import { concurrently } from './dist/src/index.js';
5+
6+
export * from './dist/src/index.js';
7+
// @ts-expect-error ignore the usage of `export =` along with `export default`.
8+
// This is seemingly fine, but the file needs to be included in the TS project, which can't be done
9+
// due to importing from `dist`. See https://stackoverflow.com/q/42609768/2083599
10+
export = concurrently;
11+
export default concurrently;

index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,10 @@
55
// eslint-disable-next-line @typescript-eslint/no-var-requires
66
const concurrently = require('./dist/src/index.js');
77

8-
module.exports = exports = concurrently.default;
8+
// For require()
9+
module.exports = exports = concurrently.concurrently;
10+
11+
// For TS + import syntax; mimics `export default`
12+
exports.default = exports;
13+
914
Object.assign(exports, concurrently);

index.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
* While in local development, make sure you've run `pnpm run build` first.
33
*/
44

5-
import concurrently from './dist/src/index.js';
5+
import { concurrently } from './dist/src/index.js';
66

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

10-
export default concurrently.default;
10+
export default concurrently;

package.json

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "8.2.2",
44
"description": "Run commands concurrently",
55
"main": "index.js",
6-
"types": "dist/src/index.d.ts",
6+
"types": "index.d.ts",
77
"type": "commonjs",
88
"bin": {
99
"concurrently": "./dist/bin/concurrently.js",
@@ -14,10 +14,14 @@
1414
},
1515
"exports": {
1616
".": {
17-
"types": "./dist/src/index.d.ts",
18-
"import": "./index.mjs",
19-
"require": "./index.js",
20-
"default": "./index.js"
17+
"import": {
18+
"types": "./index.d.mts",
19+
"default": "./index.mjs"
20+
},
21+
"require": {
22+
"types": "./index.d.ts",
23+
"default": "./index.js"
24+
}
2125
},
2226
"./package.json": "./package.json"
2327
},
@@ -94,7 +98,9 @@
9498
"files": [
9599
"dist",
96100
"index.js",
101+
"index.d.ts",
97102
"index.mjs",
103+
"index.d.mts",
98104
"!**/fixtures",
99105
"!**/*.spec.js",
100106
"!**/*.spec.d.ts"

src/index.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Readable } from 'stream';
22

33
import { CloseEvent, Command, CommandIdentifier, TimerEvent } from './command';
44
import {
5-
concurrently,
5+
concurrently as createConcurrently,
66
ConcurrentlyCommandInput,
77
ConcurrentlyOptions as BaseConcurrentlyOptions,
88
ConcurrentlyResult,
@@ -91,10 +91,10 @@ export type ConcurrentlyOptions = BaseConcurrentlyOptions & {
9191
additionalArguments?: string[];
9292
};
9393

94-
export default (
94+
export function concurrently(
9595
commands: ConcurrentlyCommandInput[],
9696
options: Partial<ConcurrentlyOptions> = {},
97-
) => {
97+
) {
9898
const logger = new Logger({
9999
hide: options.hide,
100100
prefixFormat: options.prefix,
@@ -103,7 +103,7 @@ export default (
103103
timestampFormat: options.timestampFormat,
104104
});
105105

106-
return concurrently(commands, {
106+
return createConcurrently(commands, {
107107
maxProcesses: options.maxProcesses,
108108
raw: options.raw,
109109
successCondition: options.successCondition,
@@ -141,28 +141,26 @@ export default (
141141
prefixColors: options.prefixColors || [],
142142
additionalArguments: options.additionalArguments,
143143
});
144-
};
144+
}
145145

146146
// Export all flow controllers, types, and the main concurrently function,
147147
// so that 3rd-parties can use them however they want
148+
149+
// Main
150+
export { ConcurrentlyCommandInput, ConcurrentlyResult, createConcurrently, Logger };
151+
152+
// Command specific
153+
export { CloseEvent, Command, CommandIdentifier, TimerEvent };
154+
155+
// Flow controllers
148156
export {
149-
CloseEvent,
150-
// Command specific
151-
Command,
152-
CommandIdentifier,
153-
concurrently,
154-
ConcurrentlyCommandInput,
155-
ConcurrentlyResult,
156-
// Flow controllers
157157
FlowController,
158158
InputHandler,
159159
KillOnSignal,
160160
KillOthers,
161161
LogError,
162162
LogExit,
163-
Logger,
164163
LogOutput,
165164
LogTimings,
166165
RestartProcess,
167-
TimerEvent,
168166
};

0 commit comments

Comments
 (0)