Skip to content

Commit

Permalink
Order types, interfaces, classes and object members (#2730)
Browse files Browse the repository at this point in the history
* Update changelog

* Order types, interfaces and classes

* Order object properties
  • Loading branch information
lukastaegert committed Mar 1, 2019
1 parent 73daa74 commit 2e1aa54
Show file tree
Hide file tree
Showing 109 changed files with 2,158 additions and 2,169 deletions.
62 changes: 31 additions & 31 deletions bin/src/run/batchWarnings.ts
Expand Up @@ -4,8 +4,8 @@ import relativeId from '../../../src/utils/relativeId';
import { stderr } from '../logging';

export interface BatchWarnings {
readonly count: number;
add: (warning: string | RollupWarning) => void;
readonly count: number;
flush: () => void;
}

Expand Down Expand Up @@ -117,22 +117,21 @@ const immediateHandlers: {
// TODO select sensible priorities
const deferredHandlers: {
[code: string]: {
priority: number;
fn: (warnings: RollupWarning[]) => void;
priority: number;
};
} = {
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`);
});
}
},
priority: 1
},

UNRESOLVED_IMPORT: {
priority: 1,
fn: warnings => {
title('Unresolved dependencies');
info('https://rollupjs.org/guide/en#warning-treating-module-as-external-dependency');
Expand All @@ -147,11 +146,11 @@ const deferredHandlers: {
const importers = dependencies.get(dependency);
stderr(`${tc.bold(dependency)} (imported by ${importers.join(', ')})`);
});
}
},
priority: 1
},

MISSING_EXPORT: {
priority: 1,
fn: warnings => {
title('Missing exports');
info('https://rollupjs.org/guide/en#error-name-is-not-exported-by-module-');
Expand All @@ -161,37 +160,37 @@ const deferredHandlers: {
stderr(`${warning.missing} is not exported by ${warning.exporter}`);
stderr(tc.gray(warning.frame));
});
}
},
priority: 1
},

THIS_IS_UNDEFINED: {
priority: 1,
fn: warnings => {
title('`this` has been rewritten to `undefined`');
info('https://rollupjs.org/guide/en#error-this-is-undefined');
showTruncatedWarnings(warnings);
}
},
priority: 1
},

EVAL: {
priority: 1,
fn: warnings => {
title('Use of eval is strongly discouraged');
info('https://rollupjs.org/guide/en#avoiding-eval');
showTruncatedWarnings(warnings);
}
},
priority: 1
},

NON_EXISTENT_EXPORT: {
priority: 1,
fn: warnings => {
title(`Import of non-existent ${warnings.length > 1 ? 'exports' : 'export'}`);
showTruncatedWarnings(warnings);
}
},
priority: 1
},

NAMESPACE_CONFLICT: {
priority: 1,
fn: warnings => {
title(`Conflicting re-exports`);
warnings.forEach(warning => {
Expand All @@ -203,11 +202,11 @@ const deferredHandlers: {
)} (will be ignored)`
);
});
}
},
priority: 1
},

MISSING_GLOBAL_NAME: {
priority: 1,
fn: warnings => {
title(`Missing global variable ${warnings.length > 1 ? 'names' : 'name'}`);
stderr(
Expand All @@ -216,11 +215,11 @@ const deferredHandlers: {
warnings.forEach(warning => {
stderr(`${tc.bold(warning.source)} (guessing '${warning.guess}')`);
});
}
},
priority: 1
},

SOURCEMAP_BROKEN: {
priority: 1,
fn: warnings => {
title(`Broken sourcemap`);
info('https://rollupjs.org/guide/en#warning-sourcemap-is-likely-to-be-incorrect');
Expand All @@ -230,18 +229,18 @@ const deferredHandlers: {
plugins.length === 0
? ''
: plugins.length > 1
? ` (such as ${plugins
.slice(0, -1)
.map(p => `'${p}'`)
.join(', ')} and '${plugins.slice(-1)}')`
: ` (such as '${plugins[0]}')`;
? ` (such as ${plugins
.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`);
}
},
priority: 1
},

PLUGIN_WARNING: {
priority: 1,
fn: warnings => {
const nestedByPlugin = nest(warnings, 'plugin');

Expand All @@ -266,7 +265,8 @@ const deferredHandlers: {
});
});
});
}
},
priority: 1
}
};

Expand All @@ -279,15 +279,15 @@ function info(url: string) {
}

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

array.forEach(item => {
const key = (<any>item)[prop];
if (!lookup.has(key)) {
lookup.set(key, {
key,
items: []
items: [],
key
});

nested.push(lookup.get(key));
Expand Down
2 changes: 1 addition & 1 deletion bin/src/run/index.ts
Expand Up @@ -102,8 +102,8 @@ function execute(configFile: string, configs: InputOptions[], command: any) {
promise = promise.then(() => {
const warnings = batchWarnings();
const { inputOptions, outputOptions, optionError } = mergeOptions({
config,
command,
config,
defaultOnWarnHandler: warnings.add
});

Expand Down
6 changes: 3 additions & 3 deletions bin/src/run/loadConfigFile.ts
Expand Up @@ -23,12 +23,12 @@ export default function loadConfigFile(

return rollup
.rollup({
input: configFile,
treeshake: false,
external: (id: string) => {
return (id[0] !== '.' && !path.isAbsolute(id)) || id.slice(-5, id.length) === '.json';
},
onwarn: warnings.add
input: configFile,
onwarn: warnings.add,
treeshake: false
})
.then((bundle: RollupBuild) => {
if (!silent && warnings.count > 0) {
Expand Down
14 changes: 7 additions & 7 deletions bin/src/run/watch.ts
Expand Up @@ -20,16 +20,16 @@ import { printTimings } from './timings';

interface WatchEvent {
code?: string;
duration?: number;
error?: RollupError | Error;
input?: InputOption;
output?: string[];
duration?: number;
result?: RollupBuild;
}

interface Watcher {
on: (event: string, fn: (event: WatchEvent) => void) => void;
close: () => void;
on: (event: string, fn: (event: WatchEvent) => void) => void;
}

export default function watch(
Expand Down Expand Up @@ -57,8 +57,8 @@ export default function watch(
function processConfigs(configs: RollupWatchOptions[]): RollupWatchOptions[] {
return configs.map(options => {
const merged = mergeOptions({
config: options,
command,
config: options,
defaultOnWarnHandler: warnings.add
});

Expand All @@ -71,8 +71,8 @@ export default function watch(

if (merged.optionError)
merged.inputOptions.onwarn({
message: merged.optionError,
code: 'UNKNOWN_OPTION'
code: 'UNKNOWN_OPTION',
message: merged.optionError
});

if (
Expand Down Expand Up @@ -117,8 +117,8 @@ export default function watch(
input = Array.isArray(input)
? input.join(', ')
: Object.keys(input)
.map(key => (<Record<string, string>>input)[key])
.join(', ');
.map(key => (<Record<string, string>>input)[key])
.join(', ');
}
stderr(
tc.cyan(
Expand Down

0 comments on commit 2e1aa54

Please sign in to comment.