Skip to content

Commit

Permalink
Merge pull request #1806 from rollup/ts-refactoring
Browse files Browse the repository at this point in the history
[Finished] TypeScript conversion
  • Loading branch information
lukastaegert committed Dec 23, 2017
2 parents 3d80c06 + ad8484b commit d94db0f
Show file tree
Hide file tree
Showing 310 changed files with 10,315 additions and 7,164 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# editorconfig.org
root = true

[*.ts]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab
indent_size = 2

[*.md]
trim_trailing_whitespace = false
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Place your settings in this file to overwrite default and user settings.
{
"typescript.format.insertSpaceBeforeFunctionParenthesis": true,
"typescript.format.insertSpaceAfterConstructor": true,
"typescript.format.enable": true
}
6 changes: 6 additions & 0 deletions bin/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
declare module 'minimist';
declare module 'help.md' {
let str: string;
export default str;
}
declare module 'package.json';
44 changes: 0 additions & 44 deletions bin/src/index.js

This file was deleted.

42 changes: 42 additions & 0 deletions bin/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/// <reference path="./index.d.ts" />

import minimist from 'minimist';
import help from 'help.md';
import { version } from 'package.json';
import run from './run/index.js';

const command = minimist(process.argv.slice(2), {
alias: {
// Aliases
strict: 'useStrict',

// Short options
c: 'config',
d: 'indent',
e: 'external',
f: 'output.format',
g: 'globals',
h: 'help',
i: 'input',
l: 'legacy',
m: 'sourcemap',
n: 'name',
o: 'output.file',
v: 'version',
w: 'watch'
}
});

if (command.help || (process.argv.length <= 2 && process.stdin.isTTY)) {
console.log(`\n${help.replace('__VERSION__', version)}\n`); // eslint-disable-line no-console
} else if (command.version) {
console.log(`rollup version ${version}`); // eslint-disable-line no-console
} else {
try {
require('source-map-support').install();
} catch (err) {
// do nothing
}

run(command);
}
36 changes: 0 additions & 36 deletions bin/src/logging.js

This file was deleted.

42 changes: 42 additions & 0 deletions bin/src/logging.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import chalk from 'chalk';
import relativeId from '../../src/utils/relativeId.js';
import { RollupError } from '../../src/utils/error';

if (!process.stderr.isTTY) chalk.enabled = false;

// log to stderr to keep `rollup main.js > bundle.js` from breaking
export const stderr = console.error.bind(console); // eslint-disable-line no-console

export function handleError (err: RollupError, recover = false) {
let description = err.message || err;
if (err.name) description = `${err.name}: ${description}`;
const message =
((<{ plugin?: string }>err).plugin ? `(${(<{ plugin?: string }>err).plugin} plugin) ${description}` : description) || err;

stderr(chalk.bold.red(`[!] ${chalk.bold(message.toString())}`));

// TODO should this be "err.url || (err.file && err.loc.file) || err.id"?
if (err.url) {
stderr(chalk.cyan(err.url));
}

if (err.loc) {
stderr(
`${relativeId(err.loc.file || err.id)} (${err.loc.line}:${
err.loc.column
})`
);
} else if (err.id) {
stderr(relativeId(err.id));
}

if (err.frame) {
stderr(chalk.dim(err.frame));
} else if (err.stack) {
stderr(chalk.dim(err.stack));
}

stderr('');

if (!recover) process.exit(1);
}
1 change: 1 addition & 0 deletions bin/src/run/alternateScreen.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module "ansi-escapes";
22 changes: 12 additions & 10 deletions bin/src/run/alternateScreen.js → bin/src/run/alternateScreen.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
/// <reference path="./alternateScreen.d.ts" />

import ansiEscape from 'ansi-escapes';
import { stderr } from '../logging.js';

const SHOW_ALTERNATE_SCREEN = '\u001B[?1049h';
const HIDE_ALTERNATE_SCREEN = '\u001B[?1049l';

export default function alternateScreen ( enabled ) {
export default function alternateScreen (enabled: boolean) {
if (!enabled) {
let needAnnounce = true;
return {
open() {},
close() {},
reset( heading ) {
if ( needAnnounce ) {
stderr( heading );
open () { },
close () { },
reset (heading: string) {
if (needAnnounce) {
stderr(heading);
needAnnounce = false;
}
}
};
}

return {
open() {
open () {
process.stderr.write(SHOW_ALTERNATE_SCREEN);
},
close() {
close () {
process.stderr.write(HIDE_ALTERNATE_SCREEN);
},
reset( heading ) {
stderr( `${ansiEscape.eraseScreen}${ansiEscape.cursorTo(0, 0)}${heading}` );
reset (heading: string) {
stderr(`${ansiEscape.eraseScreen}${ansiEscape.cursorTo(0, 0)}${heading}`);
}
};
}

0 comments on commit d94db0f

Please sign in to comment.