├── .gitignore ├── test ├── fixtures │ ├── 2.js │ ├── 0.js │ └── 1.js ├── mocha.opts └── test.js ├── .npmrc ├── .prettierrc ├── .lintstagedrc ├── commitlint.config.js ├── .huskyrc ├── .babelrc ├── .flowconfig ├── .travis.yml ├── script ├── prettier-check └── lint-commits ├── rollup.config.js ├── package.json ├── src └── index.js └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | dist 2 | node_modules 3 | -------------------------------------------------------------------------------- /test/fixtures/2.js: -------------------------------------------------------------------------------- 1 | console.log('Hello, 2'); -------------------------------------------------------------------------------- /test/fixtures/0.js: -------------------------------------------------------------------------------- 1 | export const zero = 0; 2 | -------------------------------------------------------------------------------- /test/fixtures/1.js: -------------------------------------------------------------------------------- 1 | export const one = 1; 2 | -------------------------------------------------------------------------------- /test/mocha.opts: -------------------------------------------------------------------------------- 1 | --require @babel/register 2 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | registry = "https://registry.npmjs.org/" 2 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true 3 | } 4 | -------------------------------------------------------------------------------- /.lintstagedrc: -------------------------------------------------------------------------------- 1 | { 2 | "*.js": [ 3 | "prettier --write", 4 | "git add" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /commitlint.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ['@commitlint/config-conventional'] 3 | }; 4 | -------------------------------------------------------------------------------- /.huskyrc: -------------------------------------------------------------------------------- 1 | { 2 | "hooks": { 3 | "commit-msg": "commitlint -e $GIT_PARAMS", 4 | "pre-commit": "lint-staged" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["@babel/env", { "targets": { "node": "current" } }] 4 | ], 5 | "plugins": [ 6 | "@babel/transform-flow-strip-types" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | /node_modules/config-chain/.* 3 | /node_modules/npmconf/.* 4 | /node_modules/semantic-release/.* 5 | 6 | [include] 7 | 8 | [libs] 9 | 10 | [options] 11 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - '10' 5 | - '8' 6 | - '6' 7 | script: 8 | - ./script/lint-commits 9 | - ./script/prettier-check 10 | - npm test 11 | branches: 12 | except: 13 | - /^v\d+\.\d+\.\d+$/ 14 | jobs: 15 | include: 16 | - stage: npm release 17 | node_js: '8' 18 | script: 19 | - echo "Deploying to npm…" 20 | - npx semantic-release 21 | -------------------------------------------------------------------------------- /script/prettier-check: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | 'use strict'; 4 | 5 | const globby = require('globby'); 6 | const join = require('path').join; 7 | const check = require('prettier-check'); 8 | 9 | let pathsPromise = globby( 10 | ['src/**/*.js', 'test/**/*.js', '!test/fixtures/**/*.js'], 11 | { 12 | cwd: join(__dirname, '..'), 13 | gitignore: true 14 | } 15 | ); 16 | 17 | pathsPromise 18 | .then(paths => check(paths)) 19 | .then(status => process.exit(status)) 20 | .catch(error => { 21 | console.error(error.stack); 22 | process.exit(1); 23 | }); 24 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import babel from 'rollup-plugin-babel'; 2 | 3 | var pkg = require('./package.json'); 4 | 5 | export default { 6 | input: 'src/index.js', 7 | plugins: [ 8 | babel({ 9 | presets: [['@babel/env', { targets: { node: '4' }, modules: false }]], 10 | plugins: ['@babel/transform-flow-strip-types'], 11 | babelrc: false 12 | }) 13 | ], 14 | external: Object.keys(pkg['dependencies']), 15 | output: [ 16 | { 17 | format: 'cjs', 18 | file: pkg['main'] 19 | }, 20 | { 21 | format: 'es', 22 | file: pkg['jsnext:main'] 23 | } 24 | ] 25 | }; 26 | -------------------------------------------------------------------------------- /script/lint-commits: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Based on http://marionebl.github.io/commitlint/#/guides-ci-setup 4 | 5 | set -e 6 | set -u 7 | 8 | IS_SHALLOW_REPOSITORY="$(git rev-parse --is-shallow-repository)" 9 | 10 | case "$IS_SHALLOW_REPOSITORY" in 11 | false) 12 | # nothing to do 13 | ;; 14 | 15 | true) 16 | git fetch --unshallow 17 | ;; 18 | 19 | *) 20 | echo "$(git --version) does not understand 'git rev-parse --is-shallow-repository', got '$IS_SHALLOW_REPOSITORY'" >&2 21 | exit 1 22 | ;; 23 | esac 24 | 25 | if [[ "$TRAVIS_PULL_REQUEST_SLUG" != "" && "$TRAVIS_PULL_REQUEST_SLUG" != "$TRAVIS_REPO_SLUG" ]]; then 26 | # This is a Pull Request from a different slug, hence a forked repository 27 | git remote add "$TRAVIS_PULL_REQUEST_SLUG" "https://github.com/$TRAVIS_PULL_REQUEST_SLUG.git" 28 | git fetch "$TRAVIS_PULL_REQUEST_SLUG" 29 | 30 | # Use the fetched remote pointing to the source clone for comparison 31 | TO="$TRAVIS_PULL_REQUEST_SLUG/$TRAVIS_PULL_REQUEST_BRANCH" 32 | else 33 | # This is a Pull Request from the same remote, no clone repository 34 | TO=$TRAVIS_COMMIT 35 | fi 36 | 37 | # Lint all commits in the PR 38 | # - Covers fork pull requests (when TO=slug/branch) 39 | # - Covers branch pull requests (when TO=branch) 40 | ./node_modules/.bin/commitlint --from="$TRAVIS_BRANCH" --to="$TO" 41 | 42 | # Always lint the triggering commit 43 | # - Covers direct commits 44 | ./node_modules/.bin/commitlint --from="$TRAVIS_COMMIT" 45 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.0.0-development", 3 | "name": "rollup-plugin-multi-entry", 4 | "description": "Allows specifying multiple entry points with rollup.", 5 | "main": "dist/rollup-plugin-multi-entry.js", 6 | "jsnext:main": "dist/rollup-plugin-multi-entry.mjs", 7 | "scripts": { 8 | "flow": "flow check", 9 | "build": "rm -rf dist && rollup -c", 10 | "pretest": "npm run flow && npm run build", 11 | "test": "mocha", 12 | "prepare": "npm run build", 13 | "prepublishOnly": "npm test" 14 | }, 15 | "repository": { 16 | "type": "git", 17 | "url": "https://github.com/rollup/rollup-plugin-multi-entry.git" 18 | }, 19 | "keywords": [ 20 | "rollup-plugin" 21 | ], 22 | "files": [ 23 | "dist" 24 | ], 25 | "author": "Brian Donovan ", 26 | "license": "MIT", 27 | "bugs": { 28 | "url": "https://github.com/rollup/rollup-plugin-multi-entry/issues" 29 | }, 30 | "homepage": "https://github.com/rollup/rollup-plugin-multi-entry#readme", 31 | "dependencies": { 32 | "matched": "^1.0.2" 33 | }, 34 | "devDependencies": { 35 | "@babel/core": "^7.2.0", 36 | "@babel/plugin-transform-flow-strip-types": "^7.2.0", 37 | "@babel/preset-env": "^7.2.0", 38 | "@babel/register": "^7.0.0", 39 | "@commitlint/config-conventional": "^8.0.0", 40 | "commitlint": "^8.0.0", 41 | "flow-bin": "^0.101.0", 42 | "globby": "^9.2.0", 43 | "husky": "^2.4.1", 44 | "lint-staged": "^8.1.0", 45 | "mocha": "^6.1.4", 46 | "prettier": "^1.9.2", 47 | "prettier-check": "^2.0.0", 48 | "rollup": "^1.15.1", 49 | "rollup-plugin-babel": "^4.0.3" 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | type Config = 4 | | string 5 | | Array 6 | | { include?: Array, exclude?: Array, exports?: boolean }; 7 | 8 | import { promise as matched } from 'matched'; 9 | 10 | const entry = '\0rollup-plugin-multi-entry:entry-point'; 11 | 12 | export default function multiEntry(config: ?Config = null) { 13 | let include = []; 14 | let exclude = []; 15 | let exporter = path => `export * from ${JSON.stringify(path)};`; 16 | 17 | function configure(config: Config) { 18 | if (typeof config === 'string') { 19 | include = [config]; 20 | } else if (Array.isArray(config)) { 21 | include = config; 22 | } else { 23 | include = config.include || []; 24 | exclude = config.exclude || []; 25 | if (config.exports === false) { 26 | exporter = path => `import ${JSON.stringify(path)};`; 27 | } 28 | } 29 | } 30 | 31 | if (config) { 32 | configure(config); 33 | } 34 | 35 | return { 36 | options(options: { input: ?string }) { 37 | if (options.input && options.input !== entry) { 38 | configure(options.input); 39 | } 40 | options.input = entry; 41 | }, 42 | 43 | resolveId(id: string): ?string { 44 | if (id === entry) { 45 | return entry; 46 | } 47 | }, 48 | 49 | load(id: string): ?Promise { 50 | if (id === entry) { 51 | if (!include.length) { 52 | return Promise.resolve(''); 53 | } 54 | const patterns = include.concat(exclude.map(pattern => '!' + pattern)); 55 | return matched(patterns, { realpath: true }).then(paths => 56 | paths.map(exporter).join('\n') 57 | ); 58 | } 59 | } 60 | }; 61 | } 62 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | import { ok } from 'assert'; 2 | import { rollup } from 'rollup'; 3 | import multiEntry from '../'; 4 | 5 | function includes(string, substring) { 6 | if (string.indexOf(substring) === -1) { 7 | ok( 8 | false, 9 | `expected ${JSON.stringify(string)} to include ${JSON.stringify( 10 | substring 11 | )}` 12 | ); 13 | } 14 | } 15 | 16 | function doesNotInclude(string, substring) { 17 | if (string.indexOf(substring) !== -1) { 18 | ok( 19 | false, 20 | `expected ${JSON.stringify(string)} not to include ${JSON.stringify( 21 | substring 22 | )}` 23 | ); 24 | } 25 | } 26 | 27 | function getCodeFromBundle(entries) { 28 | return rollup({ input: entries, plugins: [multiEntry()] }) 29 | .then(bundle => bundle.generate({ format: 'cjs' })) 30 | .then(generated => 31 | generated.output ? generated.output[0].code : generated.code 32 | ); 33 | } 34 | 35 | describe('rollup-plugin-multi-entry', () => { 36 | it('takes a single file as input', () => 37 | getCodeFromBundle('test/fixtures/0.js').then(code => 38 | includes(code, 'exports.zero = zero;') 39 | )); 40 | 41 | it('takes an array of files as input', () => 42 | getCodeFromBundle(['test/fixtures/0.js', 'test/fixtures/1.js']).then( 43 | code => { 44 | includes(code, 'exports.zero = zero;'); 45 | includes(code, 'exports.one = one;'); 46 | } 47 | )); 48 | 49 | it('allows an empty array as input', () => 50 | getCodeFromBundle([]).then(code => doesNotInclude(code, 'exports'))); 51 | 52 | it('takes a glob as input', () => 53 | getCodeFromBundle('test/fixtures/{0,1}.js').then(code => { 54 | includes(code, 'exports.zero = zero;'); 55 | includes(code, 'exports.one = one;'); 56 | })); 57 | 58 | it('takes an array of globs as input', () => 59 | getCodeFromBundle(['test/fixtures/{0,}.js', 'test/fixtures/{1,}.js']).then( 60 | code => { 61 | includes(code, 'exports.zero = zero;'); 62 | includes(code, 'exports.one = one;'); 63 | } 64 | )); 65 | 66 | it('takes an {include,exclude} object as input', () => 67 | getCodeFromBundle({ 68 | include: ['test/fixtures/*.js'], 69 | exclude: ['test/fixtures/1.js'] 70 | }).then(code => { 71 | includes(code, 'exports.zero = zero;'); 72 | doesNotInclude(code, 'exports.one = one;'); 73 | })); 74 | 75 | it('allows to prevent exporting', () => 76 | getCodeFromBundle({ 77 | include: ['test/fixtures/*.js'], 78 | exports: false 79 | }).then(code => { 80 | includes(code, `console.log('Hello, 2');`); 81 | doesNotInclude(code, 'zero'); 82 | doesNotInclude(code, 'one'); 83 | })); 84 | }); 85 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Moved 2 | 3 | This module has moved and is now available at [@rollup/plugin-multi-entry](https://github.com/rollup/plugins). Please update your dependencies. This repository is no longer maintained. 4 | 5 | 6 | # rollup-plugin-multi-entry 7 | 8 | Use multiple entry points in your [rollup](https://github.com/rollup/rollup) 9 | bundle. This is particularly useful for tests, but can also be used to package 10 | a library. The exports from all the entry points will be combined, e.g. 11 | 12 | ```js 13 | // a.js 14 | export const a = 1; 15 | 16 | // b.js 17 | export const b = 2; 18 | 19 | // c.js 20 | export const c = 3; 21 | ``` 22 | 23 | Using all three files above as entry points will yield a bundle with exports for 24 | `a`, `b`, and `c`. 25 | 26 | > _Note_: Default exports like `export default class Foo {...}` will not be exported, only named exports are allowed. 27 | 28 | ## Install 29 | 30 | ```shell 31 | # Install via npm: 32 | $ npm install [--save-dev] rollup-plugin-multi-entry 33 | # Or use yarn: 34 | $ yarn add [--dev] rollup-plugin-multi-entry 35 | ``` 36 | 37 | ## Usage 38 | 39 | This plugin requires at least v0.48.0 of rollup. In `rollup.config.js`: 40 | 41 | ```js 42 | import multiEntry from "rollup-plugin-multi-entry"; 43 | 44 | export default { 45 | input: "test/**/*.js", 46 | plugins: [multiEntry()] 47 | }; 48 | ``` 49 | 50 | The `entry` above is the simplest form which simply takes a glob string. If you 51 | wish, you may pass an array of glob strings or, for finer control, an object 52 | with `include` and `exclude` properties each taking an array of glob strings, 53 | e.g. 54 | 55 | ```js 56 | // The usual rollup entry configuration works. 57 | export default { 58 | input: 'just/one/file.js', 59 | plugins: [multiEntry()] 60 | // ... 61 | }; 62 | 63 | // As does a glob of files. 64 | export default { 65 | input: 'a/glob/of/files/**/*.js', 66 | plugins: [multiEntry()] 67 | // ... 68 | }; 69 | 70 | // Or an array of files and globs. 71 | export default { 72 | input: ['an/array.js', 'of/files.js', 'or/globs/**/*.js'], 73 | plugins: [multiEntry()] 74 | // ... 75 | }; 76 | 77 | // For maximum control, arrays of globs to include and exclude. 78 | export default { 79 | input: { 80 | include: ['files.js', 'and/globs/**/*.js', 'to/include.js'], 81 | exclude: ['those/files.js', 'and/globs/*.to.be.excluded.js'] 82 | }, 83 | plugins: [multiEntry()] 84 | // ... 85 | }; 86 | ``` 87 | 88 | Sometimes you may not want to export anything from the rolled-up bundle. In 89 | such cases, use the `exports: false` option like so: 90 | 91 | ```js 92 | export default { 93 | input: "src/*.js", 94 | plugins: [multiEntry({ exports: false })] 95 | }; 96 | ``` 97 | 98 | ## License 99 | 100 | MIT 101 | --------------------------------------------------------------------------------