Skip to content

Commit

Permalink
apply prettier to codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford authored and lukastaegert committed Mar 7, 2018
1 parent 785fdfc commit 2cb948f
Show file tree
Hide file tree
Showing 423 changed files with 3,951 additions and 4,348 deletions.
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"singleQuote": true,
"useTabs": true
"useTabs": true,
"printWidth": 120
}
12 changes: 5 additions & 7 deletions bin/src/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ if (!chalk.supportsColor) 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) {
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;
((<{ plugin?: string }>err).plugin
? `(${(<{ plugin?: string }>err).plugin} plugin) ${description}`
: description) || err;

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

Expand All @@ -21,11 +23,7 @@ export function handleError (err: RollupError, recover = false) {
}

if (err.loc) {
stderr(
`${relativeId(err.loc.file || err.id)} (${err.loc.line}:${
err.loc.column
})`
);
stderr(`${relativeId(err.loc.file || err.id)} (${err.loc.line}:${err.loc.column})`);
} else if (err.id) {
stderr(relativeId(err.id));
}
Expand Down
14 changes: 7 additions & 7 deletions bin/src/run/alternateScreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ const isMintty = isWindows && !!(process.env.SHELL || process.env.TERM);
const isConEmuAnsiOn = (process.env.ConEmuANSI || '').toLowerCase() === 'on';
const supportsAnsi = !isWindows || isMintty || isConEmuAnsiOn;

export default function alternateScreen (enabled: boolean) {
export default function alternateScreen(enabled: boolean) {
if (!enabled) {
let needAnnounce = true;
return {
open () { },
close () { },
reset (heading: string) {
open() {},
close() {},
reset(heading: string) {
if (needAnnounce) {
stderr(heading);
needAnnounce = false;
Expand All @@ -25,17 +25,17 @@ export default function alternateScreen (enabled: boolean) {
}

return {
open () {
open() {
if (supportsAnsi) {
process.stderr.write(SHOW_ALTERNATE_SCREEN);
}
},
close () {
close() {
if (supportsAnsi) {
process.stderr.write(HIDE_ALTERNATE_SCREEN);
}
},
reset (heading: string) {
reset(heading: string) {
stderr(`${ansiEscape.eraseScreen}${ansiEscape.cursorTo(0, 0)}${heading}`);
}
};
Expand Down
122 changes: 39 additions & 83 deletions bin/src/run/batchWarnings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ export interface BatchWarnings {
flush: () => void;
}

export default function batchWarnings () {
export default function batchWarnings() {
let allWarnings = new Map<string, RollupWarning[]>();
let count = 0;

return {
get count () {
get count() {
return count;
},

add: (warning: string | RollupWarning) => {
add: (warning: string | RollupWarning) => {
if (typeof warning === 'string') {
warning = { code: 'UNKNOWN', message: warning };
}
Expand Down Expand Up @@ -55,20 +55,14 @@ export default function batchWarnings () {
handler.fn(warnings);
} else {
warnings.forEach(warning => {
stderr(
`${chalk.bold.yellow('(!)')} ${chalk.bold.yellow(
warning.message
)}`
);
stderr(`${chalk.bold.yellow('(!)')} ${chalk.bold.yellow(warning.message)}`);

if (warning.url) info(warning.url);

const id = (warning.loc && warning.loc.file) || warning.id;
if (id) {
const loc = warning.loc
? `${relativeId(id)}: (${warning.loc.line}:${
warning.loc.column
})`
? `${relativeId(id)}: (${warning.loc.line}:${warning.loc.column})`
: relativeId(id);

stderr(chalk.bold(relativeId(loc)));
Expand All @@ -86,7 +80,7 @@ export default function batchWarnings () {
}

const immediateHandlers: {
[code: string]: (warning: RollupWarning) => void
[code: string]: (warning: RollupWarning) => void;
} = {
UNKNOWN_OPTION: warning => {
title(`You have passed an unrecognized option`);
Expand All @@ -95,9 +89,7 @@ const immediateHandlers: {

DEPRECATED_OPTIONS: warning => {
title(`Some options have been renamed`);
info(
`https://gist.github.com/Rich-Harris/d472c50732dab03efeb37472b08a3f32`
);
info(`https://gist.github.com/Rich-Harris/d472c50732dab03efeb37472b08a3f32`);
warning.deprecations.forEach(option => {
stderr(`${chalk.bold(option.old)} is now ${option.new}`);
});
Expand All @@ -110,9 +102,9 @@ const immediateHandlers: {
warning.modules.length === 1
? `'${warning.modules[0]}'`
: `${warning.modules
.slice(0, -1)
.map(name => `'${name}'`)
.join(', ')} and '${warning.modules.slice(-1)}'`;
.slice(0, -1)
.map(name => `'${name}'`)
.join(', ')} and '${warning.modules.slice(-1)}'`;
stderr(
`Creating a browser bundle that depends on ${detail}. You might need to include https://www.npmjs.com/package/rollup-plugin-node-builtins`
);
Expand All @@ -135,18 +127,14 @@ const deferredHandlers: {
[code: string]: {
priority: number;
fn: (warnings: RollupWarning[]) => void;
}
};
} = {
UNUSED_EXTERNAL_IMPORT: {
priority: 1,
fn: warnings => {
title('Unused external imports');
warnings.forEach(warning => {
stderr(
`${warning.names} imported from external module '${
warning.source
}' but never used`
);
stderr(`${warning.names} imported from external module '${warning.source}' but never used`);
});
}
},
Expand All @@ -155,22 +143,17 @@ const deferredHandlers: {
priority: 1,
fn: warnings => {
title('Unresolved dependencies');
info(
'https://github.com/rollup/rollup/wiki/Troubleshooting#treating-module-as-external-dependency'
);
info('https://github.com/rollup/rollup/wiki/Troubleshooting#treating-module-as-external-dependency');

const dependencies = new Map();
warnings.forEach(warning => {
if (!dependencies.has(warning.source))
dependencies.set(warning.source, []);
if (!dependencies.has(warning.source)) dependencies.set(warning.source, []);
dependencies.get(warning.source).push(warning.importer);
});

Array.from(dependencies.keys()).forEach(dependency => {
const importers = dependencies.get(dependency);
stderr(
`${chalk.bold(dependency)} (imported by ${importers.join(', ')})`
);
stderr(`${chalk.bold(dependency)} (imported by ${importers.join(', ')})`);
});
}
},
Expand All @@ -179,9 +162,7 @@ const deferredHandlers: {
priority: 1,
fn: warnings => {
title('Missing exports');
info(
'https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module'
);
info('https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module');

warnings.forEach(warning => {
stderr(chalk.bold(warning.importer));
Expand All @@ -195,9 +176,7 @@ const deferredHandlers: {
priority: 1,
fn: warnings => {
title('`this` has been rewritten to `undefined`');
info(
'https://github.com/rollup/rollup/wiki/Troubleshooting#this-is-undefined'
);
info('https://github.com/rollup/rollup/wiki/Troubleshooting#this-is-undefined');
showTruncatedWarnings(warnings);
}
},
Expand All @@ -206,19 +185,15 @@ const deferredHandlers: {
priority: 1,
fn: warnings => {
title('Use of eval is strongly discouraged');
info(
'https://github.com/rollup/rollup/wiki/Troubleshooting#avoiding-eval'
);
info('https://github.com/rollup/rollup/wiki/Troubleshooting#avoiding-eval');
showTruncatedWarnings(warnings);
}
},

NON_EXISTENT_EXPORT: {
priority: 1,
fn: warnings => {
title(
`Import of non-existent ${warnings.length > 1 ? 'exports' : 'export'}`
);
title(`Import of non-existent ${warnings.length > 1 ? 'exports' : 'export'}`);
showTruncatedWarnings(warnings);
}
},
Expand All @@ -229,11 +204,9 @@ const deferredHandlers: {
title(`Conflicting re-exports`);
warnings.forEach(warning => {
stderr(
`${chalk.bold(relativeId(warning.reexporter))} re-exports '${
warning.name
}' from both ${relativeId(warning.sources[0])} and ${relativeId(
warning.sources[1]
)} (will be ignored)`
`${chalk.bold(relativeId(warning.reexporter))} re-exports '${warning.name}' from both ${relativeId(
warning.sources[0]
)} and ${relativeId(warning.sources[1])} (will be ignored)`
);
});
}
Expand All @@ -242,12 +215,8 @@ const deferredHandlers: {
MISSING_GLOBAL_NAME: {
priority: 1,
fn: warnings => {
title(
`Missing global variable ${warnings.length > 1 ? 'names' : 'name'}`
);
stderr(
`Use output.globals to specify browser global variable names corresponding to external modules`
);
title(`Missing global variable ${warnings.length > 1 ? 'names' : 'name'}`);
stderr(`Use output.globals to specify browser global variable names corresponding to external modules`);
warnings.forEach(warning => {
stderr(`${chalk.bold(warning.source)} (guessing '${warning.guess}')`);
});
Expand All @@ -258,26 +227,20 @@ const deferredHandlers: {
priority: 1,
fn: warnings => {
title(`Broken sourcemap`);
info(
'https://github.com/rollup/rollup/wiki/Troubleshooting#sourcemap-is-likely-to-be-incorrect'
);
info('https://github.com/rollup/rollup/wiki/Troubleshooting#sourcemap-is-likely-to-be-incorrect');

const plugins = Array.from(
new Set(warnings.map(w => w.plugin).filter(Boolean))
);
const plugins = Array.from(new Set(warnings.map(w => w.plugin).filter(Boolean)));
const detail =
plugins.length === 0
? ''
: plugins.length > 1
? ` (such as ${plugins
.slice(0, -1)
.map(p => `'${p}'`)
.join(', ')} and '${plugins.slice(-1)}')`
.slice(0, -1)
.map(p => `'${p}'`)
.join(', ')} and '${plugins.slice(-1)}')`
: ` (such as '${plugins[0]}')`;

stderr(
`Plugins that transform code${detail} should generate accompanying sourcemaps`
);
stderr(`Plugins that transform code${detail} should generate accompanying sourcemaps`);
}
},

Expand All @@ -297,9 +260,7 @@ const deferredHandlers: {
if (warning.url !== lastUrl) info((lastUrl = warning.url));

const loc = warning.loc
? `${relativeId(warning.id)}: (${warning.loc.line}:${
warning.loc.column
})`
? `${relativeId(warning.id)}: (${warning.loc.line}:${warning.loc.column})`
: relativeId(warning.id);

stderr(chalk.bold(relativeId(loc)));
Expand All @@ -311,17 +272,17 @@ const deferredHandlers: {
}
};

function title (str: string) {
function title(str: string) {
stderr(`${chalk.bold.yellow('(!)')} ${chalk.bold.yellow(str)}`);
}

function info (url: string) {
function info(url: string) {
stderr(chalk.grey(url));
}

function nest<T> (array: T[], prop: string) {
const nested: { key: string, items: T[] }[] = [];
const lookup = new Map<string, { key: string, items: T[] }>();
function nest<T>(array: T[], prop: string) {
const nested: { key: string; items: T[] }[] = [];
const lookup = new Map<string, { key: string; items: T[] }>();

array.forEach(item => {
const key = (<any>item)[prop];
Expand All @@ -340,21 +301,16 @@ function nest<T> (array: T[], prop: string) {
return nested;
}

function showTruncatedWarnings (warnings: RollupWarning[]) {
function showTruncatedWarnings(warnings: RollupWarning[]) {
const nestedByModule = nest(warnings, 'id');

const sliced =
nestedByModule.length > 5 ? nestedByModule.slice(0, 3) : nestedByModule;
const sliced = nestedByModule.length > 5 ? nestedByModule.slice(0, 3) : nestedByModule;
sliced.forEach(({ key: id, items }) => {
stderr(chalk.bold(relativeId(id)));
stderr(chalk.grey(items[0].frame));

if (items.length > 1) {
stderr(
`...and ${items.length - 1} other ${
items.length > 2 ? 'occurrences' : 'occurrence'
}`
);
stderr(`...and ${items.length - 1} other ${items.length > 2 ? 'occurrences' : 'occurrence'}`);
}
});

Expand Down

0 comments on commit 2cb948f

Please sign in to comment.