Skip to content

Commit

Permalink
set line length to 100
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Mar 6, 2018
1 parent 6db7530 commit 6c15302
Show file tree
Hide file tree
Showing 104 changed files with 1,245 additions and 485 deletions.
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"singleQuote": true,
"useTabs": true,
"printWidth": 120
"printWidth": 100
}
20 changes: 14 additions & 6 deletions bin/src/run/batchWarnings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ 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 => {
Expand Down Expand Up @@ -204,9 +206,11 @@ 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 @@ -216,7 +220,9 @@ const deferredHandlers: {
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`);
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 @@ -227,7 +233,9 @@ 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 detail =
Expand Down
13 changes: 10 additions & 3 deletions bin/src/run/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export default function build(
silent = false
) {
const useStdout =
outputOptions.length === 1 && !outputOptions[0].file && inputOptions.input instanceof Array === false;
outputOptions.length === 1 &&
!outputOptions[0].file &&
inputOptions.input instanceof Array === false;

const start = Date.now();
const files = useStdout ? ['stdout'] : outputOptions.map(t => relativeId(t.file || t.dir));
Expand All @@ -39,7 +41,8 @@ export default function build(
if (output.sourcemap && output.sourcemap !== 'inline') {
handleError({
code: 'MISSING_OUTPUT_OPTION',
message: 'You must specify an --output (-o) option when creating a file with a sourcemap'
message:
'You must specify an --output (-o) option when creating a file with a sourcemap'
});
}

Expand All @@ -59,7 +62,11 @@ export default function build(
.then(() => {
warnings.flush();
if (!silent)
stderr(chalk.green(`created ${chalk.bold(files.join(', '))} in ${chalk.bold(ms(Date.now() - start))}`));
stderr(
chalk.green(
`created ${chalk.bold(files.join(', '))} in ${chalk.bold(ms(Date.now() - start))}`
)
);
})
.catch(handleError);
}
4 changes: 3 additions & 1 deletion bin/src/run/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export default function runRollup(command: any) {
}

if (command.environment) {
const environment = Array.isArray(command.environment) ? command.environment : [command.environment];
const environment = Array.isArray(command.environment)
? command.environment
: [command.environment];

environment.forEach((arg: string) => {
arg.split(',').forEach((pair: string) => {
Expand Down
5 changes: 4 additions & 1 deletion bin/src/run/loadConfigFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import relativeId from '../../../src/utils/relativeId';
import { handleError, stderr } from '../logging';
import { InputOptions, OutputChunk } from '../../../src/rollup/index';

export default function loadConfigFile(configFile: string, silent = false): Promise<InputOptions[]> {
export default function loadConfigFile(
configFile: string,
silent = false
): Promise<InputOptions[]> {
const warnings = batchWarnings();

return rollup
Expand Down
11 changes: 9 additions & 2 deletions bin/src/run/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ interface Watcher {
close: () => void;
}

export default function watch(configFile: string, configs: RollupWatchOptions[], command: any, silent = false) {
export default function watch(
configFile: string,
configs: RollupWatchOptions[],
command: any,
silent = false
) {
const isTTY = Boolean(process.stderr.isTTY);

const screen = alternateScreen(isTTY);
Expand Down Expand Up @@ -108,7 +113,9 @@ export default function watch(configFile: string, configs: RollupWatchOptions[],
if (!silent)
stderr(
chalk.green(
`created ${chalk.bold(event.output.map(relativeId).join(', '))} in ${chalk.bold(ms(event.duration))}`
`created ${chalk.bold(event.output.map(relativeId).join(', '))} in ${chalk.bold(
ms(event.duration)
)}`
)
);
break;
Expand Down
119 changes: 76 additions & 43 deletions src/Chunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ export default class Chunk {
tracedName = traced.name;
} else {
// if we exposed an export in another module ensure it is exported there
tracedName = (<Module>traced.module).chunk.ensureExport(traced.module, variable, traced.name);
tracedName = (<Module>traced.module).chunk.ensureExport(
traced.module,
variable,
traced.name
);
}
this.exports[exportName] = {
module: traced.module,
Expand Down Expand Up @@ -236,7 +240,10 @@ export default class Chunk {
});
}

populateImport(variable: Variable, tracedExport: { name: string; module: Module | ExternalModule }) {
populateImport(
variable: Variable,
tracedExport: { name: string; module: Module | ExternalModule }
) {
if (!variable.included) {
return;
}
Expand All @@ -246,7 +253,11 @@ export default class Chunk {
// ensure that the variable is exported by the other chunk to this one
if (tracedExport.module instanceof Module) {
importModule = tracedExport.module.chunk;
exportName = tracedExport.module.chunk.ensureExport(tracedExport.module, variable, tracedExport.name);
exportName = tracedExport.module.chunk.ensureExport(
tracedExport.module,
variable,
tracedExport.name
);
} else {
importModule = tracedExport.module;
exportName = variable.name;
Expand Down Expand Up @@ -293,16 +304,16 @@ export default class Chunk {

// namespace variable can indicate multiple imports
if (tracedExport.name === '*') {
Object.keys((<NamespaceVariable>variable).originals || (<ExternalVariable>variable).module.declarations).forEach(
importName => {
const original = ((<NamespaceVariable>variable).originals ||
(<ExternalVariable>variable).module.declarations)[importName];
this.populateImport(original, {
name: importName,
module: tracedExport.module
});
}
);
Object.keys(
(<NamespaceVariable>variable).originals || (<ExternalVariable>variable).module.declarations
).forEach(importName => {
const original = ((<NamespaceVariable>variable).originals ||
(<ExternalVariable>variable).module.declarations)[importName];
this.populateImport(original, {
name: importName,
module: tracedExport.module
});
});
return tracedExport;
}

Expand All @@ -312,7 +323,10 @@ export default class Chunk {

// trace a module export to its exposed chunk module export
// either in this chunk or in another
traceExport(module: Module | ExternalModule, name: string): { name: string; module: Module | ExternalModule } {
traceExport(
module: Module | ExternalModule,
name: string
): { name: string; module: Module | ExternalModule } {
if (name === '*') {
return { name, module };
}
Expand All @@ -333,7 +347,8 @@ export default class Chunk {
if (exportDeclaration) {
// if export binding is itself an import binding then continue tracing
const importDeclaration = module.imports[exportDeclaration.localName];
if (importDeclaration) return this.traceImport(importDeclaration.module, importDeclaration.name);
if (importDeclaration)
return this.traceImport(importDeclaration.module, importDeclaration.name);
return { name, module };
}

Expand Down Expand Up @@ -361,9 +376,18 @@ export default class Chunk {
}
}

collectAddon(initialAddon: string, addonName: 'banner' | 'footer' | 'intro' | 'outro', sep: string = '\n') {
collectAddon(
initialAddon: string,
addonName: 'banner' | 'footer' | 'intro' | 'outro',
sep: string = '\n'
) {
return runSequence(
[{ pluginName: 'rollup', source: initialAddon } as { pluginName: string; source: string | (() => string) }]
[
{ pluginName: 'rollup', source: initialAddon } as {
pluginName: string;
source: string | (() => string);
}
]
.concat(
this.graph.plugins.map((plugin, idx) => {
return {
Expand Down Expand Up @@ -703,7 +727,9 @@ export default class Chunk {
if (!finalise) {
error({
code: 'INVALID_OPTION',
message: `Invalid format: ${options.format} - valid options are ${Object.keys(finalisers).join(', ')}`
message: `Invalid format: ${options.format} - valid options are ${Object.keys(
finalisers
).join(', ')}`
});
}

Expand Down Expand Up @@ -737,45 +763,52 @@ export default class Chunk {
let map: RawSourceMap = null;
const bundleSourcemapChain: RawSourceMap[] = [];

return transformBundle(prevCode, this.graph.plugins, bundleSourcemapChain, options).then((code: string) => {
if (options.sourcemap) {
timeStart('sourcemap');
return transformBundle(prevCode, this.graph.plugins, bundleSourcemapChain, options).then(
(code: string) => {
if (options.sourcemap) {
timeStart('sourcemap');

let file = options.file ? options.sourcemapFile || options.file : this.id;
if (file) file = resolve(typeof process !== 'undefined' ? process.cwd() : '', file);

if (
this.graph.hasLoaders ||
this.graph.plugins.find(plugin =>
Boolean(plugin.transform || plugin.transformBundle)
)
) {
map = <any>magicString.generateMap({}); // TODO TypeScript: Awaiting missing version in SourceMap type
if (typeof map.mappings === 'string') {
map.mappings = decode(map.mappings);
}
map = collapseSourcemaps(this, file, map, usedModules, bundleSourcemapChain);
} else {
map = <any>magicString.generateMap({ file, includeContent: true }); // TODO TypeScript: Awaiting missing version in SourceMap type
}

let file = options.file ? options.sourcemapFile || options.file : this.id;
if (file) file = resolve(typeof process !== 'undefined' ? process.cwd() : '', file);
map.sources = map.sources.map(normalize);

if (
this.graph.hasLoaders ||
this.graph.plugins.find(plugin => Boolean(plugin.transform || plugin.transformBundle))
) {
map = <any>magicString.generateMap({}); // TODO TypeScript: Awaiting missing version in SourceMap type
if (typeof map.mappings === 'string') {
map.mappings = decode(map.mappings);
}
map = collapseSourcemaps(this, file, map, usedModules, bundleSourcemapChain);
} else {
map = <any>magicString.generateMap({ file, includeContent: true }); // TODO TypeScript: Awaiting missing version in SourceMap type
timeEnd('sourcemap');
}

map.sources = map.sources.map(normalize);

timeEnd('sourcemap');
if (code[code.length - 1] !== '\n') code += '\n';
return { code, map } as { code: string; map: any }; // TODO TypeScript: Awaiting missing version in SourceMap type
}

if (code[code.length - 1] !== '\n') code += '\n';
return { code, map } as { code: string; map: any }; // TODO TypeScript: Awaiting missing version in SourceMap type
});
);
});
}

private createGetPath(options: OutputOptions) {
const optionsPaths = options.paths;
const getPath =
typeof optionsPaths === 'function'
? (id: string) => optionsPaths(id, this.id) || this.graph.getPathRelativeToBaseDirname(id, this.id)
? (id: string) =>
optionsPaths(id, this.id) || this.graph.getPathRelativeToBaseDirname(id, this.id)
: optionsPaths
? (id: string) =>
optionsPaths.hasOwnProperty(id) ? optionsPaths[id] : this.graph.getPathRelativeToBaseDirname(id, this.id)
optionsPaths.hasOwnProperty(id)
? optionsPaths[id]
: this.graph.getPathRelativeToBaseDirname(id, this.id)
: (id: string) => this.graph.getPathRelativeToBaseDirname(id, this.id);
return getPath;
}
Expand Down

0 comments on commit 6c15302

Please sign in to comment.