Skip to content

Commit

Permalink
v0.8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
stylemistake committed Aug 12, 2021
1 parent f03a171 commit bd9dc67
Show file tree
Hide file tree
Showing 7 changed files with 262 additions and 236 deletions.
420 changes: 213 additions & 207 deletions .yarn/juke/index.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## [Unreleased]

## [0.8.1] - 2021-08-12

### Fixed

- Juke will properly exit with a non-zero exit code if any target has failed. As before, this is overridable via `Juke.setup().then((code) => ...)`.

## [0.8.0] - 2021-08-11

### Added
Expand Down
13 changes: 9 additions & 4 deletions build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,16 @@ export const BundleTarget = new Juke.Target({
entryPoints: ['src/index.ts'],
outfile: 'dist/index.js',
});
if (String.prototype.replaceAll) {
const content = fs.readFileSync('dist/index.js', 'utf-8')
.replaceAll(process.cwd() + '/.yarn/cache/', '');
fs.writeFileSync('dist/index.js', content);
// A very crude implementation of replaceAll
let content = fs.readFileSync('dist/index.js', 'utf-8');
while (true) {
const nextContent = content.replace(process.cwd() + '/.yarn/cache/', '');
if (content === nextContent) {
break;
}
content = nextContent;
}
fs.writeFileSync('dist/index.js', content);
},
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "juke-build",
"version": "0.8.0",
"version": "0.8.1",
"description": "The AKE-less Build System for JavaScript and Node.js.",
"keywords": [
"build",
Expand Down
23 changes: 2 additions & 21 deletions src/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { resolve as resolvePath } from 'path';

const children = new Set<ChildProcess>();

const killChildren = () => {
export const killChildren = () => {
for (const child of children) {
child.kill('SIGTERM');
children.delete(child);
Expand All @@ -15,7 +15,7 @@ const killChildren = () => {

type SignalHandler = (signal: string) => void;

const trap = (signals: string[], handler: SignalHandler) => {
export const trap = (signals: string[], handler: SignalHandler) => {
let readline;
if (process.platform === 'win32') {
readline = require('readline').createInterface({
Expand All @@ -36,25 +36,6 @@ const trap = (signals: string[], handler: SignalHandler) => {
}
};

trap(['EXIT', 'BREAK', 'HUP', 'INT', 'TERM'], (signal) => {
if (signal !== 'EXIT') {
console.log('Received', signal);
}
killChildren();
if (signal !== 'EXIT') {
process.exit(1);
}
});

const exceptionHandler = (err: unknown) => {
console.log(err);
killChildren();
process.exit(1);
};

process.on('unhandledRejection', exceptionHandler);
process.on('uncaughtException', exceptionHandler);

export class ExitCode extends Error {
code: number | null = null;
signal: string | null = null;
Expand Down
32 changes: 30 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import _chalk from 'chalk';
import { createRequire } from 'module';
import { version } from '../package.json';
import { chdir } from './chdir';
import { killChildren, trap } from './exec';
import { logger } from './logger';
import { createParameter, Parameter } from './parameter';
import { runner } from './runner';
Expand All @@ -22,6 +23,8 @@ export {

export const chalk = _chalk;

let lastExitCode: number | null = null;

type SetupConfig = {
file: string;
/**
Expand All @@ -37,7 +40,7 @@ type SetupConfig = {
* @param config Juke Build configuration.
* @returns Exit code of the whole runner process.
*/
export const setup = async (config: SetupConfig) => {
export const setup = async (config: SetupConfig): Promise<number> => {
logger.info(`Juke Build version ${version}`)
if (!config.file) {
logger.error(`Field 'file' is required in Juke.setup()`);
Expand Down Expand Up @@ -89,9 +92,34 @@ export const setup = async (config: SetupConfig) => {
default: DefaultTarget,
singleTarget: config.singleTarget,
});
return runner.start();
return runner.start().then((code) => {
lastExitCode = code;
return code;
});
};

export const sleep = (time: number) => (
new Promise((resolve) => setTimeout(resolve, time))
);

trap(['EXIT', 'BREAK', 'HUP', 'INT', 'TERM'], (signal) => {
if (signal !== 'EXIT') {
console.log('Received', signal);
}
killChildren();
if (signal !== 'EXIT') {
process.exit(1);
}
else if (lastExitCode !== null) {
process.exit(lastExitCode);
}
});

const exceptionHandler = (err: unknown) => {
console.log(err);
killChildren();
process.exit(1);
};

process.on('unhandledRejection', exceptionHandler);
process.on('uncaughtException', exceptionHandler);
2 changes: 1 addition & 1 deletion tools/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fi

if [[ ${from_git} == "0" ]]; then
echo "=> Starting versioning tool"
yarn release-tool version
yarn release-tool version --yes
fi

echo "=> Pushing to git"
Expand Down

0 comments on commit bd9dc67

Please sign in to comment.