Skip to content

Commit

Permalink
Do not require input to be set if a dynamic entry is emitted
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Apr 23, 2019
1 parent 2b8570d commit 738d6ca
Show file tree
Hide file tree
Showing 18 changed files with 29 additions and 16 deletions.
7 changes: 3 additions & 4 deletions src/Graph.ts
Expand Up @@ -108,10 +108,6 @@ export default class Graph {

this.cacheExpiry = options.experimentalCacheExpiry;

if (!options.input) {
throw new Error('You must supply options.input to rollup');
}

this.treeshake = options.treeshake !== false;
if (this.treeshake) {
this.treeshakingOptions = options.treeshake
Expand Down Expand Up @@ -214,6 +210,9 @@ export default class Graph {
this.moduleLoader.addEntryModules(normalizeEntryModules(entryModules), true),
manualChunks && this.moduleLoader.addManualChunks(manualChunks)
]).then(([{ entryModules, manualChunkModulesByAlias }]) => {
if (entryModules.length === 0) {
throw new Error('You must supply options.input to rollup');
}
for (const entryModule of entryModules) {
if (entryModule.chunkAlias === null) {
entryModule.chunkAlias = getAliasName(entryModule.id);
Expand Down
2 changes: 1 addition & 1 deletion src/finalisers/amd.ts
Expand Up @@ -6,7 +6,7 @@ import getExportBlock from './shared/getExportBlock';
import getInteropBlock from './shared/getInteropBlock';
import warnOnBuiltins from './shared/warnOnBuiltins';

// TODO Lukas consider improved AMD relative imports:
// TODO consider using improved AMD relative imports:
// https://requirejs.org/docs/api.html#modulenotes-urls

// AMD resolution will only respect the AMD baseUrl if the .js extension is omitted.
Expand Down
2 changes: 1 addition & 1 deletion src/rollup/index.ts
Expand Up @@ -67,7 +67,7 @@ function applyOptionHook(inputOptions: InputOptions, plugin: Plugin) {
return inputOptions;
}

function getInputOptions(rawInputOptions: GenericConfigObject): any {
function getInputOptions(rawInputOptions: GenericConfigObject): InputOptions {
if (!rawInputOptions) {
throw new Error('You must supply an options object to rollup');
}
Expand Down
3 changes: 1 addition & 2 deletions src/rollup/types.d.ts
Expand Up @@ -214,7 +214,6 @@ export type ResolveAssetUrlHook = (
}
) => string | void;

// TODO Lukas do not require an input to be present if entries are created dynamically
export type ResolveFileUrlHook = (
this: PluginContext,
options: {
Expand Down Expand Up @@ -326,7 +325,7 @@ export interface InputOptions {
experimentalTopLevelAwait?: boolean;
external?: ExternalOption;
inlineDynamicImports?: boolean;
input: InputOption;
input?: InputOption;
manualChunks?: { [chunkAlias: string]: string[] };
moduleContext?: ((id: string) => string) | { [id: string]: string };
onwarn?: WarningHandler;
Expand Down
4 changes: 2 additions & 2 deletions src/utils/mergeOptions.ts
Expand Up @@ -88,7 +88,7 @@ export default function mergeOptions({
config: GenericConfigObject;
defaultOnWarnHandler?: WarningHandler;
}): {
inputOptions: any;
inputOptions: InputOptions;
optionError: string | null;
outputOptions: any;
} {
Expand Down Expand Up @@ -204,7 +204,7 @@ function getInputOptions(
experimentalTopLevelAwait: getOption('experimentalTopLevelAwait'),
external: getExternal(config, command),
inlineDynamicImports: getOption('inlineDynamicImports', false),
input: getOption('input'),
input: getOption('input', []),
manualChunks: getOption('manualChunks'),
moduleContext: config.moduleContext,
onwarn: getOnWarn(config, command, defaultOnWarnHandler),
Expand Down
14 changes: 8 additions & 6 deletions src/watch/index.ts
Expand Up @@ -9,7 +9,8 @@ import {
RollupBuild,
RollupCache,
RollupWatcher,
RollupWatchOptions
RollupWatchOptions,
WatcherOptions
} from '../rollup/types';
import mergeOptions from '../utils/mergeOptions';
import chokidar from './chokidar';
Expand All @@ -28,7 +29,7 @@ export class Watcher {
private tasks: Task[];

constructor(configs: RollupWatchOptions[]) {
this.emitter = new class extends EventEmitter implements RollupWatcher {
this.emitter = new (class extends EventEmitter implements RollupWatcher {
close: () => void;
constructor(close: () => void) {
super();
Expand All @@ -37,7 +38,7 @@ export class Watcher {
// showing the `MaxListenersExceededWarning` to the user.
this.setMaxListeners(Infinity);
}
}(this.close.bind(this));
})(this.close.bind(this));
this.tasks = (Array.isArray(configs) ? configs : configs ? [configs] : []).map(
config => new Task(this, config)
);
Expand Down Expand Up @@ -144,8 +145,9 @@ export class Task {
if (output.file || output.dir) return path.resolve(output.file || output.dir);
});

const watchOptions = inputOptions.watch || {};
if ('useChokidar' in watchOptions) watchOptions.chokidar = watchOptions.useChokidar;
const watchOptions: WatcherOptions = inputOptions.watch || {};
if ('useChokidar' in watchOptions)
(watchOptions as any).chokidar = (watchOptions as any).useChokidar;
let chokidarOptions = 'chokidar' in watchOptions ? watchOptions.chokidar : !!chokidar;
if (chokidarOptions) {
chokidarOptions = {
Expand All @@ -161,7 +163,7 @@ export class Task {
);
}

this.chokidarOptions = chokidarOptions;
this.chokidarOptions = chokidarOptions as WatchOptions;
this.chokidarOptionsHash = JSON.stringify(chokidarOptions);

this.filter = createFilter(watchOptions.include, watchOptions.exclude);
Expand Down
12 changes: 12 additions & 0 deletions test/function/samples/emit-chunk/no-input/_config.js
@@ -0,0 +1,12 @@
module.exports = {
description: 'It is not necessary to provide an input if a dynamic entry is emitted',
options: {
input: undefined,
plugins: {
name: 'test-plugin',
buildStart() {
this.emitChunk('chunk.js');
}
}
}
};
1 change: 1 addition & 0 deletions test/function/samples/emit-chunk/no-input/chunk.js
@@ -0,0 +1 @@
assert.equal(42, 42);

0 comments on commit 738d6ca

Please sign in to comment.