Skip to content

Commit

Permalink
feat(plugin): Allow empty properties
Browse files Browse the repository at this point in the history
  • Loading branch information
impy88 committed Jun 2, 2021
1 parent a61bc22 commit ba1e96a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rollup-plugin-auto-entry",
"version": "1.0.3",
"version": "1.0.4",
"publishConfig": {
"access": "public"
},
Expand Down
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import * as rollup from 'rollup';
import Entry from './entry';

export interface RollupPluginOptions {
include: string[]
include: string[] | undefined
}

let options: RollupPluginOptions = {
include: []
}
export default function autoEntry(opts?: RollupPluginOptions): rollup.Plugin {
let options: RollupPluginOptions = {
include: undefined
};

export default function autoEntry(opts: RollupPluginOptions): rollup.Plugin {
return {
name: "rollup-plugin-entries",

Expand All @@ -37,7 +37,7 @@ export default function autoEntry(opts: RollupPluginOptions): rollup.Plugin {
Entry.add(module.id);
}

if (!module?.isEntry && Entry.isNewEntry(id, options.include)) {
if (options.include && !module?.isEntry && Entry.isNewEntry(id, options.include)) {
this.emitFile({
type: 'chunk',
id: id,
Expand Down
20 changes: 20 additions & 0 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ test('generates correct number of bundles with single input', async (t) => {
const { output } = await bundle.generate({ format: 'esm' });

t.is(output.length, entries.length);

await bundle.close();
})

test('generates correct number of bundles with multiple input', async (t) => {
Expand All @@ -44,4 +46,22 @@ test('generates correct number of bundles with multiple input', async (t) => {
const { output } = await bundle.generate({ format: 'esm' });

t.is(output.length, entries.length);

await bundle.close();
})

test('generates correct number of bundles if no options were provided', async (t) => {
const bundle = await rollup({
input: 'test/fixtures/entry1/index.js',
cache: false,
plugins: [
nodeResolve(),
autoEntry()
]
});

const { output } = await bundle.generate({ format: 'esm' });
t.is(output.length, 1);

await bundle.close();
})

0 comments on commit ba1e96a

Please sign in to comment.