Skip to content

Commit

Permalink
Merge branch 'open-cli-tools:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
odeadglaz committed Feb 27, 2024
2 parents bfd2094 + fd21485 commit 6992c26
Show file tree
Hide file tree
Showing 22 changed files with 397 additions and 32 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/test.yml
Expand Up @@ -55,9 +55,13 @@ jobs:
- name: Install dependencies
run: pnpm install && pnpm add --global concurrently

- name: Build & Test
- name: Build & Unit Test
run: concurrently --prefix none --group "pnpm:build" "pnpm:test"

- name: Smoke Test
# Don't collect coverage here as it overrides the unit test's coverage
run: pnpm test:smoke --coverage=false

- name: Submit coverage
uses: coverallsapp/github-action@master
continue-on-error: true
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,5 +1,5 @@
# Outputs
/dist
dist

# Logs
*.log
Expand Down
2 changes: 1 addition & 1 deletion bin/concurrently.ts
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
@@ -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
@@ -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
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
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;
29 changes: 24 additions & 5 deletions jest.config.js
@@ -1,11 +1,30 @@
/** @type {import('@jest/types').Config.InitialOptions} */
const config = {
// Need to extend from a base config because projects don't inherit configurations as documented
// https://github.com/jestjs/jest/issues/11411
/** @type {import('@jest/types').Config.InitialProjectOptions} */
const baseConfig = {
transform: {
'^.+\\.(t|j)sx?$': ['@swc/jest'],
'.*': ['@swc/jest'],
},
collectCoverage: true,
collectCoverageFrom: ['src/**/*.ts', '!src/index.ts'],
testPathIgnorePatterns: ['/node_modules/', '/dist'],
};

/** @type {import('@jest/types').Config.InitialOptions} */
const config = {
collectCoverage: true,
projects: [
{
...baseConfig,
displayName: 'unit',
collectCoverageFrom: ['src/**/*.ts', '!src/index.ts'],
// (src|bin) doesn't seem to work on Windows
testMatch: ['src', 'bin'].map((dir) => `<rootDir>/${dir}/**/*.spec.ts`),
},
{
...baseConfig,
displayName: 'smoke',
testMatch: ['<rootDir>/tests/**/*.spec.ts'],
},
],
};

module.exports = config;
19 changes: 13 additions & 6 deletions package.json
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 All @@ -31,7 +35,8 @@
"lint:fix": "pnpm run lint --fix",
"prepublishOnly": "safe-publish-latest && pnpm run build",
"report-coverage": "cat coverage/lcov.info | coveralls",
"test": "jest",
"test": "jest --selectProjects unit",
"test:smoke": "jest --selectProjects smoke",
"prepare": "husky install"
},
"repository": {
Expand Down Expand Up @@ -94,7 +99,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
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,
};
3 changes: 3 additions & 0 deletions tests/cjs-import/package.json
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
15 changes: 15 additions & 0 deletions tests/cjs-import/smoke-test.ts
@@ -0,0 +1,15 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import type { ConcurrentlyResult } from 'concurrently';
import concurrently, { concurrently as concurrently2, createConcurrently } from 'concurrently';

const result: ConcurrentlyResult = concurrently(['ls'], {
raw: true,
});

const result2: ConcurrentlyResult = concurrently2(['ls'], {
killOthers: ['failure'],
});

const result3: ConcurrentlyResult = createConcurrently(['ls'], {
successCondition: 'all',
});
8 changes: 8 additions & 0 deletions tests/cjs-import/tsconfig.json
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"outDir": "dist",
"module": "CommonJS",
"moduleResolution": "Node",
"skipLibCheck": true
}
}
3 changes: 3 additions & 0 deletions tests/cjs-require/package.json
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
17 changes: 17 additions & 0 deletions tests/cjs-require/smoke-test.ts
@@ -0,0 +1,17 @@
/* eslint-disable @typescript-eslint/no-unused-vars */

import concurrently = require('concurrently');

const { concurrently: concurrently2, createConcurrently } = concurrently;

const result: concurrently.ConcurrentlyResult = concurrently(['ls'], {
raw: true,
});

const result2: concurrently.ConcurrentlyResult = concurrently2(['ls'], {
killOthers: ['failure'],
});

const result3: concurrently.ConcurrentlyResult = createConcurrently(['ls'], {
successCondition: 'all',
});
8 changes: 8 additions & 0 deletions tests/cjs-require/tsconfig.json
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"outDir": "dist",
"module": "CommonJS",
"moduleResolution": "Node",
"skipLibCheck": true
}
}
3 changes: 3 additions & 0 deletions tests/esm/package.json
@@ -0,0 +1,3 @@
{
"type": "module"
}
15 changes: 15 additions & 0 deletions tests/esm/smoke-test.ts
@@ -0,0 +1,15 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import type { ConcurrentlyResult } from 'concurrently';
import concurrently, { concurrently as concurrently2, createConcurrently } from 'concurrently';

const result: ConcurrentlyResult = concurrently(['ls'], {
raw: true,
});

const result2: ConcurrentlyResult = concurrently2(['ls'], {
killOthers: ['failure'],
});

const result3: ConcurrentlyResult = createConcurrently(['ls'], {
successCondition: 'all',
});
7 changes: 7 additions & 0 deletions tests/esm/tsconfig.json
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"outDir": "dist",
"module": "Node16",
"moduleResolution": "Node16"
}
}
8 changes: 8 additions & 0 deletions tests/package.json
@@ -0,0 +1,8 @@
{
"dependencies": {
"concurrently": "file:.."
},
"scripts": {
"test": "pnpm --prefix .. test -- --selectProjects smoke"
}
}

0 comments on commit 6992c26

Please sign in to comment.