├── .circleci └── config.yml ├── .editorconfig ├── .eslintignore ├── .eslintrc.js ├── .github ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── FUNDING.yml ├── ISSUE_TEMPLATE.md ├── ISSUE_TEMPLATE │ ├── BUG.md │ ├── DOCS.md │ ├── FEATURE.md │ ├── MODIFICATION.md │ └── SUPPORT.md ├── PULL_REQUEST_TEMPLATE.md ├── labels.json └── workflows │ └── node-windows.yml ├── .gitignore ├── .nvmrc ├── .vscode ├── launch.json └── settings.json ├── CHANGELOG.md ├── LICENSE ├── README.md ├── codecov.yml ├── package-lock.json ├── package.json ├── rollup.config.mjs ├── src └── index.ts ├── test ├── fixtures │ └── batman.js ├── helpers │ └── helpers.ts ├── snapshots │ ├── sourcemaps.ts.md │ ├── sourcemaps.ts.snap │ ├── test.ts.md │ └── test.ts.snap ├── sourcemaps.ts └── test.ts ├── tsconfig.base.json ├── tsconfig.eslint.json ├── tsconfig.json └── types └── index.d.ts /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | 3 | unit_tests: &unit_tests 4 | steps: 5 | - checkout 6 | - restore_cache: 7 | key: dependency-cache-{{ checksum "package-lock.json" }} 8 | - run: 9 | name: Run unit tests. 10 | command: npm run ci:test 11 | 12 | jobs: 13 | dependency_cache: 14 | docker: 15 | - image: rollupcabal/circleci-node-base:latest 16 | steps: 17 | - checkout 18 | - restore_cache: 19 | key: dependency-cache-{{ checksum "package-lock.json" }} 20 | - run: 21 | name: Install Dependencies 22 | command: npm ci 23 | - save_cache: 24 | key: dependency-cache-{{ checksum "package-lock.json" }} 25 | paths: 26 | - ./node_modules 27 | node-v14-latest: 28 | docker: 29 | - image: rollupcabal/circleci-node-v14:latest 30 | <<: *unit_tests 31 | node-v16-latest: 32 | docker: 33 | - image: rollupcabal/circleci-node-v16:latest 34 | <<: *unit_tests 35 | node-v18-latest: 36 | docker: 37 | - image: rollupcabal/circleci-node-v18:latest 38 | steps: 39 | - checkout 40 | - restore_cache: 41 | key: dependency-cache-{{ checksum "package-lock.json" }} 42 | - run: 43 | name: Run unit tests. 44 | command: npm run ci:coverage 45 | - run: 46 | name: Submit coverage data to codecov. 47 | command: bash <(curl -s https://codecov.io/bash) 48 | when: on_success 49 | analysis: 50 | docker: 51 | - image: rollupcabal/circleci-node-base:latest 52 | steps: 53 | - checkout 54 | - restore_cache: 55 | key: dependency-cache-{{ checksum "package-lock.json" }} 56 | - run: 57 | name: Run linting. 58 | command: npm run lint 59 | - run: 60 | name: Run Security Check 61 | command: npm run security 62 | workflows: 63 | version: 2 64 | validate: 65 | jobs: 66 | - dependency_cache 67 | - node-v18-latest: 68 | requires: 69 | - dependency_cache 70 | filters: 71 | tags: 72 | only: /.*/ 73 | - analysis: 74 | requires: 75 | - dependency_cache 76 | filters: 77 | tags: 78 | only: /.*/ 79 | - node-v16-latest: 80 | requires: 81 | - dependency_cache 82 | filters: 83 | tags: 84 | only: /.*/ 85 | - node-v14-latest: 86 | requires: 87 | - dependency_cache 88 | filters: 89 | tags: 90 | only: /.*/ 91 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | end_of_line = lf 9 | insert_final_newline = true 10 | trim_trailing_whitespace = true 11 | 12 | [*.md] 13 | insert_final_newline = true 14 | trim_trailing_whitespace = false 15 | 16 | [*.yml] 17 | max_line_length = 500 18 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | !.eslintrc.js 2 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ['rollup', 'plugin:import/typescript'], 3 | overrides: [ 4 | { 5 | files: ['*.ts'], 6 | parserOptions: { 7 | project: ['./tsconfig.eslint.json', './tsconfig.json'], 8 | tsconfigRootDir: __dirname 9 | }, 10 | rules: { '@typescript-eslint/no-unnecessary-type-assertion': 'error' } 11 | } 12 | ], 13 | parser: '@typescript-eslint/parser', 14 | plugins: ['@typescript-eslint'], 15 | rules: { 16 | '@typescript-eslint/consistent-type-assertions': 'error', 17 | '@typescript-eslint/consistent-type-definitions': 'error', 18 | '@typescript-eslint/member-ordering': 'error', 19 | '@typescript-eslint/no-inferrable-types': 'error', 20 | '@typescript-eslint/no-unnecessary-type-assertion': 'off', 21 | '@typescript-eslint/no-unused-vars': [ 22 | 'error', 23 | { 24 | args: 'after-used', 25 | ignoreRestSiblings: true, 26 | vars: 'local' 27 | } 28 | ], 29 | 'import/extensions': [ 30 | 'error', 31 | 'always', 32 | { 33 | js: 'never', 34 | jsx: 'never', 35 | ts: 'never', 36 | tsx: 'never' 37 | } 38 | ], 39 | 'import/no-named-export': 'off', 40 | 'import/no-namespace': 'off', 41 | 'no-unused-vars': 'off', 42 | 'prettier/prettier': [ 43 | 'error', 44 | { 45 | arrowParens: 'always', 46 | plugins: ['prettier-plugin-package'], 47 | printWidth: 100, 48 | singleQuote: true, 49 | trailingComma: 'none' 50 | } 51 | ] 52 | } 53 | }; 54 | -------------------------------------------------------------------------------- /.github/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at TODO. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [https://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: https://contributor-covenant.org 46 | [version]: https://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contribute 2 | 3 | ## Introduction 4 | 5 | First, thank you for considering contributing to rollup! It's people like you that make the open source community such a great community! 😊 6 | 7 | We welcome any type of contribution, not only code. You can help with 8 | - **QA**: file bug reports, the more details you can give the better (i.e. [REPL](https://rollupjs.org/repl/)-links or repos that demonstrate the specific issue) 9 | - **Marketing**: writing blog posts, howto's, printing stickers, ... 10 | - **Community**: presenting the project at meetups, organizing a dedicated meetup for the local community, ... 11 | - **Code**: take a look at the [open issues](https://github.com/rollup/plugins/issues). Even if you can't write code, commenting on them, showing that you care about a given issue matters. It helps us triage them. 12 | - **Money**: we welcome financial contributions in full transparency on our [open collective](https://opencollective.com/rollup). 13 | 14 | ## Your First Contribution 15 | 16 | Working on your first Pull Request? You can learn how from this *free* series, [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github). 17 | 18 | ## Submitting code 19 | 20 | Any code change should be submitted as a pull request. The description should explain what the code does and give steps to execute it. The pull request should also contain tests. 21 | 22 | ## Code review process 23 | 24 | The bigger the pull request, the longer it will take to review and merge. Try to break down large pull requests in smaller chunks that are easier to review and merge. 25 | 26 | It is also always helpful to have some context for your pull request. What was the purpose? Why does it matter to you? Does it resolve any known Github issues? Adding a line "resolves #" (e.g. "resolves #23") to the description of your pull request or of a specific commit will automatically close this issue once the pull request is merged. 27 | 28 | ## Financial contributions 29 | 30 | We also welcome financial contributions in full transparency on our [open collective](https://opencollective.com/rollup). 31 | Anyone can file an expense. If the expense makes sense for the development of the community, it will be "merged" in the ledger of our open collective by the core contributors and the person who filed the expense will be reimbursed. 32 | 33 | ## Questions 34 | 35 | If you require technical assistance, [Stackoverflow](https://stackoverflow.com/questions/tagged/rollupjs) or [Gitter](https://gitter.im/rollup/rollup) are usually the best places to start. 36 | You can also create an [issue](issue) (protip: do a quick search first to see if someone else didn't ask the same question before!). 37 | 38 | ## Credits 39 | 40 | ### Contributors 41 | 42 | Thank you to all the people who have already contributed to rollup! 43 | 44 | 45 | ### Backers 46 | 47 | Thank you to all our backers! [[Become a backer](https://opencollective.com/rollup#backer)] 48 | 49 | 50 | 51 | 52 | ### Sponsors 53 | 54 | Thank you to all our sponsors! (please ask your company to also support this open source project by [becoming a sponsor](https://opencollective.com/rollup#sponsor)) 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | open_collective: rollup 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 18 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/BUG.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 🐞 Bug Report 3 | about: Something went awry and you'd like to tell us about it. 4 | 5 | --- 6 | 7 | 20 | 21 | - @rollup/stream Version: 22 | - Rollup Version: 23 | - Operating System (or Browser): 24 | - Node Version: 25 | 26 | ### How Do We Reproduce? 27 | 28 | 35 | 36 | 37 | ### Expected Behavior 38 | 39 | 40 | ### Actual Behavior 41 | 42 | 43 | 49 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/DOCS.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 📚 Documentation 3 | about: Are the docs lacking or missing something? Do they need some new 🔥 hotness? Tell us here. 4 | 5 | --- 6 | 7 | 20 | 21 | - @rollup/stream Version: 22 | 23 | Documentation Is: 24 | 25 | 26 | 27 | - [ ] Missing 28 | - [ ] Needed 29 | - [ ] Confusing 30 | - [ ] Not Sure? 31 | 32 | ### Please Explain in Detail... 33 | 34 | 35 | ### Your Proposal for Changes 36 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/FEATURE.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: ✨ Feature Request 3 | about: Suggest an idea for this project 4 | 5 | --- 6 | 7 | 20 | 21 | - @rollup/stream Version: 22 | 23 | ### Feature Use Case 24 | 25 | 26 | ### Feature Proposal 27 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/MODIFICATION.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 🔧 Modification Request 3 | about: Would you like something work differently? Have an alternative approach? This is the template for you. 4 | 5 | --- 6 | 7 | 20 | 21 | - @rollup/stream Version: 22 | 23 | ### Expected Behavior / Situation 24 | 25 | 26 | ### Actual Behavior / Situation 27 | 28 | 29 | ### Modification Proposal 30 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/SUPPORT.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 🆘 Support, Help, and Advice 3 | about: 👉🏽 Need help or tech support? Please don't open an issue! Head to https://gitter.im/rollup/rollup or https://stackoverflow.com/questions/tagged/rollupjs. 4 | 5 | --- 6 | 7 | Hey there! If you need help or tech support then this is not the place to 8 | ask. Please head to [the Rollup Gitter](https://gitter.im/rollup/rollup) 9 | instead or post a question to https://stackoverflow.com/questions/tagged/rollupjs. 10 | 11 | If you arrived here because you think Rollup's documentation is unclear, 12 | insufficient or wrong, please consider creating an issue for the documentation 13 | instead. 14 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 15 | 16 | This PR contains: 17 | 18 | - [ ] bugfix 19 | - [ ] feature 20 | - [ ] refactor 21 | - [ ] documentation 22 | - [ ] other 23 | 24 | Are tests included? 25 | 26 | - [ ] yes (_bugfixes and features will not be merged without tests_) 27 | - [ ] no 28 | 29 | Breaking Changes? 30 | 31 | - [ ] yes (_breaking changes will not be merged unless absolutely necessary_) 32 | - [ ] no 33 | 34 | List any relevant issue numbers: 35 | 36 | ### Description 37 | 38 | 43 | -------------------------------------------------------------------------------- /.github/labels.json: -------------------------------------------------------------------------------- 1 | [ 2 | { "name": "💩 template incomplete", "color": "#4E342E" }, 3 | { "name": "💩 template removed", "color": "#4E342E" }, 4 | 5 | { "name": "b¹ 🐞 code-splitting", "color": "#F44336" }, 6 | { "name": "b² 🐞 scope-hoisting", "color": "#F44336" }, 7 | { "name": "b³ 🐞 tree-shaking", "color": "#F44336" }, 8 | 9 | { "name": "c¹ ⋅ discussion", "color": "#1976D2" }, 10 | { "name": "c² ⋅ feedback wanted", "color": "#F9A825" }, 11 | { "name": "c³ ⋅ PR welcome", "color": "#1B5E20" }, 12 | { "name": "c⁴ ⋅ need more info", "color": "#6A1B9A" }, 13 | { "name": "c⁵ ⋅ question", "color": "#C2185B" }, 14 | { "name": "c⁶ ⋅ request for comments", "color": "#BBDEFB" }, 15 | 16 | { "name": "p¹ ⋅ browser", "color": "#B2DFDB" }, 17 | { "name": "p² ⋅ linux", "color": "#B2DFDB" }, 18 | { "name": "p³ ⋅ mac", "color": "#B2DFDB" }, 19 | { "name": "p⁴ ⋅ windows", "color": "#B2DFDB" }, 20 | 21 | { "name": "pr¹ 🔧 chore", "color": "#D7CCC8" }, 22 | { "name": "pr² 🔧 docs", "color": "#D7CCC8" }, 23 | { "name": "pr³ 🔧 feature", "color": "#D7CCC8" }, 24 | { "name": "pr⁴ 🔧 fix", "color": "#D7CCC8" }, 25 | { "name": "pr⁵ 🔧 performance", "color": "#D7CCC8" }, 26 | { "name": "pr⁶ 🔧 refactor", "color": "#D7CCC8" }, 27 | { "name": "pr⁷ 🔧 style", "color": "#D7CCC8" }, 28 | { "name": "pr⁸ 🔧 test", "color": "#D7CCC8" }, 29 | 30 | { "name": "s¹ 🔥🔥🔥 critical", "color": "#E53935" }, 31 | { "name": "s² 🔥🔥 important", "color": "#FB8C00" }, 32 | { "name": "s³ 🔥 nice to have", "color": "#FDD835" }, 33 | { "name": "s⁴ 💧 low", "color": "#039BE5" }, 34 | { "name": "s⁵ 💧💧 inconvenient", "color": "#c0e0f7" }, 35 | 36 | { "name": "t¹ 🐞 bug", "color": "#F44336" }, 37 | { "name": "t² 📚 documentation", "color": "#FDD835" }, 38 | { "name": "t³ ✨ enhancement", "color": "#03a9f4" }, 39 | { "name": "t⁴ ⋅ regression", "color": "#0052cc" }, 40 | { "name": "t⁵ ⋅ todo", "color": "#311B92" }, 41 | { "name": "t⁶ ⋅ waiting on upstream", "color": "#0D47A1" }, 42 | 43 | { "name": "v¹ ⋅ major", "color": "#CDDC39" }, 44 | { "name": "v² ⋅ minor", "color": "#FF9800" }, 45 | { "name": "v³ ⋅ minor (experimental)", "color": "#FFC107" }, 46 | 47 | { "name": "x¹ ⋅ abandoned", "color": "#CFD8DC" }, 48 | { "name": "x² ⋅ could not reproduce", "color": "#CFD8DC" }, 49 | { "name": "x³ ⋅ duplicate", "color": "#CFD8DC" }, 50 | { "name": "x⁴ ⋅ hold", "color": "#CFD8DC" }, 51 | { "name": "x⁵ ⋅ in progress", "color": "#4CAF50" }, 52 | { "name": "x⁶ ⋅ invalid", "color": "#CFD8DC" }, 53 | { "name": "x⁷ ⋅ wontfix", "color": "#CFD8DC" } 54 | ] 55 | -------------------------------------------------------------------------------- /.github/workflows/node-windows.yml: -------------------------------------------------------------------------------- 1 | name: Node 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: windows-2019 9 | 10 | strategy: 11 | matrix: 12 | node: [ '18', '16', '14' ] 13 | 14 | name: ${{ matrix.node }} (Windows) 15 | steps: 16 | - name: Configure git line-breaks 17 | run: git config --global core.autocrlf false 18 | - name: Checkout Commit 19 | uses: actions/checkout@v1 20 | - name: Setup Node 21 | uses: actions/setup-node@v1 22 | with: 23 | node-version: ${{ matrix.node }} 24 | - name: Install dependencies 25 | run: npm ci --ignore-scripts 26 | - name: Run tests 27 | run: npm test 28 | env: 29 | CI: true 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .nyc_output/ 2 | coverage/ 3 | dist/ 4 | node_modules/ 5 | output/ 6 | 7 | .DS_Store 8 | .eslintcache 9 | coverage.lcov 10 | pnpm-debug.log 11 | .idea 12 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | 12 2 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "Mocha Tests", 11 | "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha", 12 | "args": [ 13 | "-u", 14 | "tdd", 15 | "--timeout", 16 | "999999", 17 | "--colors" 18 | ], 19 | "console": "integratedTerminal" 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | // Place your settings in this file to overwrite default and user settings. 2 | { 3 | "typescript.format.insertSpaceBeforeFunctionParenthesis": true, 4 | "typescript.format.insertSpaceAfterConstructor": true, 5 | "typescript.format.enable": true 6 | } 7 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # @rollup/stream ChangeLog 2 | 3 | ## v1.1.0 4 | 5 | _2020-09-21_ 6 | 7 | ### Bugfixes 8 | 9 | - fix: prevent unnecessary warnings due to the use of build time hooks (#6) 10 | 11 | ### Updates 12 | 13 | - chore: npm audit fix, lint docs (925b6b09) 14 | - chore: remove Node 8 from CI (f83be2eb) 15 | - chore: update dependencies (4d284553) 16 | - chore: streamline CI (55ac661b) 17 | 18 | ## v1.0.0 19 | 20 | _2019-12-22_ 21 | 22 | ### Release Notes 23 | 24 | This is the initial release. 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2019 RollupJS, and Contributors (https://github.com/rollup/stream/graphs/contributors) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [cover]: https://codecov.io/gh/rollup/stream/branch/master/graph/badge.svg 2 | [cover-url]: https://codecov.io/gh/rollup/stream 3 | [tests]: https://img.shields.io/circleci/project/github/rollup/stream.svg 4 | [tests-url]: https://circleci.com/gh/rollup/stream 5 | [npm]: https://img.shields.io/npm/v/@rollup/stream 6 | [npm-url]: https://www.npmjs.com/package/@rollup/stream 7 | [size]: https://packagephobia.now.sh/badge?p=@rollup/stream 8 | [size-url]: https://packagephobia.now.sh/result?p=@rollup/stream 9 | 10 | [![tests][tests]][tests-url] 11 | [![cover][cover]][cover-url] 12 | [![npm][npm]][npm-url] 13 | [![size][size]][size-url] 14 | [![libera manifesto](https://img.shields.io/badge/libera-manifesto-lightgrey.svg)](https://liberamanifesto.com) 15 | 16 | # @rollup/stream 17 | 18 | 🍣 Stream Rollup build results 19 | 20 | This package exists to provide a streaming interface for Rollup builds. This is useful in situations where a build system is working with [vinyl files](https://github.com/gulpjs/vinyl), such as [`gulp.js`](https://gulpjs.com/). 21 | 22 | ## Requirements 23 | 24 | This plugin requires an [LTS](https://github.com/nodejs/Release) Node version (v8.0.0+) and Rollup v1.20.0+. 25 | 26 | ## Install 27 | 28 | Using npm: 29 | 30 | ```console 31 | npm install @rollup/stream --save-dev 32 | ``` 33 | 34 | ## Usage 35 | 36 | Assume a `src/index.js` file exists and contains code like the following: 37 | 38 | ```js 39 | export default 'jingle bells, batman smells'; 40 | ``` 41 | 42 | We can bundle `src/index.js` using streams such like: 43 | 44 | ```js 45 | import rollupStream from '@rollup/stream'; 46 | 47 | const { log } = console; 48 | const options = { 49 | input: 'src/index.js', 50 | output: { format: 'cjs' }, 51 | }; 52 | const stream = rollupStream(options); 53 | let bundle = ''; 54 | 55 | stream.on('data', (data) => (bundle += data)); 56 | stream.on('end', () => log(bundle)); 57 | ``` 58 | 59 | The preceding code will concatenate each chunk (or asset) and output the entire bundle's content when Rollup has completed bundling and the stream has ended. 60 | 61 | ## Options 62 | 63 | All [Rollup options](https://www.rollupjs.org/guide/en/#configuration-files) are valid to pass as options to `@rollup/stream`. 64 | 65 | ### Usage with Gulp 66 | 67 | Using Gulp requires piping. Suppose one wanted to take the bundle content and run it through a minifier, such as [`terser`](https://www.npmjs.com/package/terser): 68 | 69 | ```js 70 | import rollupStream from '@rollup/stream'; 71 | import gulp from 'gulp'; 72 | import terser from 'gulp-terser'; 73 | import source from 'vinyl-source-stream'; 74 | 75 | gulp.task('rollup', () => { 76 | const options = { input: 'src/index.js' }; 77 | return rollupStream(options) 78 | .pipe(source('bundle.js')) 79 | .pipe(terser({ keep_fnames: true, mangle: false })) 80 | .pipe(gulp.dest('dist')); 81 | }); 82 | ``` 83 | 84 | ### Using Sourcemaps 85 | 86 | Rollup can produce source maps by specifying the `sourcemap` output option. For example; to use the generated sourcemaps with Gulp and `@rollup/stream`: 87 | 88 | ```js 89 | import rollupStream from '@rollup/stream'; 90 | import buffer from 'vinyl-buffer'; 91 | import gulp from 'gulp'; 92 | import sourcemaps from 'gulp-sourcemaps'; 93 | import source from 'vinyl-source-stream'; 94 | 95 | gulp.task('rollup', () => { 96 | const options = { input: 'src/index.js', output: { sourcemap: true } }; 97 | return rollupStream(options) 98 | .pipe(source('bundle.js')) 99 | .pipe(buffer()) 100 | .pipe(sourcemaps.init({ loadMaps: true })) 101 | .pipe(sourcemaps.write('dist')) 102 | .pipe(gulp.dest('dist')); 103 | }); 104 | ``` 105 | 106 | ### Caching 107 | 108 | The ability to cache a build is already [built into Rollup](https://www.rollupjs.org/guide/en/#cache), so users of `@rollup/stream` get that for free. Caching can be useful to reduce or optimize build times, and is often used when watching files that are part of a build. For example; to utilize caching with Gulp and `@rollup/stream`: 109 | 110 | ```js 111 | import rollupStream from '@rollup/stream'; 112 | import buffer from 'vinyl-buffer'; 113 | import gulp from 'gulp'; 114 | import source from 'vinyl-source-stream'; 115 | 116 | // declare the cache variable outside of task scopes 117 | let cache; 118 | 119 | gulp.task('rollup', () => { 120 | return rollupStream({ 121 | input: 'src/index.js', 122 | // define the cache in Rollup options 123 | cache, 124 | }) 125 | .on('bundle', (bundle) => { 126 | // update the cache after every new bundle is created 127 | cache = bundle; 128 | }) 129 | .pipe(source('bundle.js')) 130 | .pipe(buffer()) 131 | .pipe(gulp.dest('dist')); 132 | }); 133 | 134 | gulp.task('watch', (done) => { 135 | gulp.watch('./src/**/*.js', gulp.series('rollup')); 136 | 137 | // or, with Gulp v3 138 | // gulp.watch('./src/**/*.js', ['rollup']); 139 | 140 | done(); 141 | }); 142 | ``` 143 | 144 | _(Example based on the [rollup-stream README](https://github.com/Permutatrix/rollup-stream#readme))_ 145 | 146 | ## Meta 147 | 148 | [CONTRIBUTING](/.github/CONTRIBUTING.md) 149 | 150 | [LICENSE (MIT)](/LICENSE) 151 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | codecov: 2 | branch: master 3 | coverage: 4 | precision: 2 5 | round: down 6 | range: 70...100 7 | status: 8 | project: 'no' 9 | patch: 'yes' 10 | comment: 'off' 11 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@rollup/stream", 3 | "version": "3.0.1", 4 | "publishConfig": { 5 | "access": "public" 6 | }, 7 | "description": "Stream Rollup build results", 8 | "license": "MIT", 9 | "repository": "rollup/stream", 10 | "author": "Andrew Powell ", 11 | "homepage": "https://github.com/rollup/stream#readme", 12 | "bugs": "https://github.com/rollup/stream/issues", 13 | "main": "dist/index.js", 14 | "module": "dist/index.es.js", 15 | "engines": { 16 | "node": ">= 14.0.0" 17 | }, 18 | "scripts": { 19 | "build": "rollup -c", 20 | "ci:coverage": "nyc npm run test && nyc report --reporter=text-lcov > coverage.lcov", 21 | "ci:lint": "npm run build && npm run lint", 22 | "ci:test": "npm run test -- --verbose", 23 | "lint": "npm run lint:js && npm run lint:docs && npm run lint:package", 24 | "lint:docs": "prettier --single-quote --write *.md", 25 | "lint:js": "eslint --fix --cache src --ext .js,.ts,.mjs", 26 | "lint:package": "prettier --write package.json --plugin=prettier-plugin-package", 27 | "prebuild": "del-cli dist", 28 | "prepublishOnly": "npm run lint && npm run build", 29 | "pretest": "npm run build -- --sourcemap", 30 | "security": "npm audit --audit-level=moderate", 31 | "test": "ava" 32 | }, 33 | "files": [ 34 | "dist", 35 | "types", 36 | "README.md", 37 | "LICENSE" 38 | ], 39 | "keywords": [ 40 | "rollup", 41 | "plugin", 42 | "utils" 43 | ], 44 | "peerDependencies": { 45 | "rollup": "^2.35.1||^3.0.0||^4.0.0" 46 | }, 47 | "devDependencies": { 48 | "@rollup/plugin-commonjs": "^23.0.0", 49 | "@rollup/plugin-node-resolve": "^15.0.0", 50 | "@rollup/plugin-typescript": "^9.0.1", 51 | "@types/node": "^14.18.32", 52 | "@typescript-eslint/eslint-plugin": "^5.40.0", 53 | "@typescript-eslint/parser": "^5.40.0", 54 | "ava": "^4.3.3", 55 | "del-cli": "^5.0.0", 56 | "eslint-config-rollup": "^3.0.0", 57 | "nyc": "^15.1.0", 58 | "prettier": "^2.7.1", 59 | "prettier-plugin-package": "^1.3.0", 60 | "rollup": "^3.2.2", 61 | "ts-node": "^10.9.1", 62 | "tsconfig-paths": "^4.1.0", 63 | "tslib": "^2.4.0", 64 | "typescript": "^4.8.4" 65 | }, 66 | "types": "types/index.d.ts", 67 | "ava": { 68 | "extensions": [ 69 | "ts" 70 | ], 71 | "require": [ 72 | "ts-node/register" 73 | ], 74 | "files": [ 75 | "!**/fixtures/**", 76 | "!**/helpers/**", 77 | "!**/recipes/**", 78 | "!**/types.ts" 79 | ] 80 | }, 81 | "nyc": { 82 | "extension": [ 83 | ".js", 84 | ".ts" 85 | ] 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /rollup.config.mjs: -------------------------------------------------------------------------------- 1 | /* eslint-disable import/no-extraneous-dependencies */ 2 | 3 | import { readFileSync } from 'fs'; 4 | 5 | import typescript from '@rollup/plugin-typescript'; 6 | import resolve from '@rollup/plugin-node-resolve'; 7 | import commonjs from '@rollup/plugin-commonjs'; 8 | 9 | const pkg = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8')); 10 | 11 | export default { 12 | external: ['path', 'rollup', 'stream'], 13 | input: 'src/index.ts', 14 | output: [ 15 | { exports: 'auto', file: pkg.main, format: 'cjs' }, 16 | { file: pkg.module, format: 'es' } 17 | ], 18 | plugins: [ 19 | resolve(), 20 | commonjs({ include: './node_modules/**' }), 21 | typescript({ include: '**/*.{ts,js}' }) 22 | ], 23 | strictDeprecations: true 24 | }; 25 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import { Readable } from 'stream'; 2 | 3 | import { rollup, OutputOptions, RollupOptions } from 'rollup'; 4 | 5 | const build = async (options: RollupOptions, stream: Readable) => { 6 | const bundle = await rollup(options); 7 | 8 | stream.emit('bundle', bundle); 9 | 10 | const { output } = await bundle.generate(options.output as OutputOptions); 11 | 12 | for (const chunk of output) { 13 | if (chunk.type === 'asset') { 14 | stream.push(chunk.source); 15 | } else { 16 | stream.push(chunk.code); 17 | 18 | if (chunk.map) { 19 | stream.push(`\n//# sourceMappingURL=${chunk.map.toUrl()}`); 20 | } 21 | } 22 | } 23 | 24 | // signal end of write 25 | stream.push(null); 26 | }; 27 | 28 | const stream = (options: RollupOptions) => { 29 | const result = new Readable({ 30 | // stub _read() as it's not available on Readable stream, needed by gulp et al 31 | read: () => {} 32 | }); 33 | 34 | build(options, result).catch((error) => { 35 | result.emit('error', error); 36 | }); 37 | 38 | return result; 39 | }; 40 | 41 | export default stream; 42 | -------------------------------------------------------------------------------- /test/fixtures/batman.js: -------------------------------------------------------------------------------- 1 | export default 'na na na na na'; 2 | -------------------------------------------------------------------------------- /test/helpers/helpers.ts: -------------------------------------------------------------------------------- 1 | import { Readable } from 'stream'; 2 | 3 | const read = (stream: Readable) => 4 | new Promise((p, f) => { 5 | let data = ''; 6 | stream.on('end', () => p(data)); 7 | stream.on('error', (err) => f(err)); 8 | stream.on('data', (chunk) => { 9 | data += chunk.toString(); 10 | }); 11 | }); 12 | 13 | const wait = (event: string, stream: Readable) => 14 | new Promise((p) => { 15 | stream.on(event, (data) => p(data)); 16 | }); 17 | 18 | export default { read, wait }; 19 | -------------------------------------------------------------------------------- /test/snapshots/sourcemaps.ts.md: -------------------------------------------------------------------------------- 1 | # Snapshot report for `test/sourcemaps.ts` 2 | 3 | The actual snapshot is saved in `sourcemaps.ts.snap`. 4 | 5 | Generated by [AVA](https://avajs.dev). 6 | 7 | ## sourcemap added 8 | 9 | > Snapshot 1 10 | 11 | `'use strict';␊ 12 | ␊ 13 | var batman = 'na na na na na';␊ 14 | ␊ 15 | module.exports = batman;␊ 16 | //# sourceMappingURL=batman.js.map␊ 17 | ␊ 18 | //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmF0bWFuLmpzIiwic291cmNlcyI6WyJ0ZXN0L2ZpeHR1cmVzL2JhdG1hbi5qcyJdLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgZGVmYXVsdCAnbmEgbmEgbmEgbmEgbmEnO1xuIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsYUFBZSxnQkFBZ0I7Ozs7In0={"version":3,"file":"batman.js","sources":["test/fixtures/batman.js"],"sourcesContent":["export default 'na na na na na';\\n"],"names":[],"mappings":";;AAAA,aAAe,gBAAgB;;;;"}` 19 | 20 | ## no sourcemap 21 | 22 | > Snapshot 1 23 | 24 | `'use strict';␊ 25 | ␊ 26 | var batman = 'na na na na na';␊ 27 | ␊ 28 | module.exports = batman;␊ 29 | ` 30 | -------------------------------------------------------------------------------- /test/snapshots/sourcemaps.ts.snap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rollup/stream/91306a4a240d3d5ec820fec94ebaf3f26108c560/test/snapshots/sourcemaps.ts.snap -------------------------------------------------------------------------------- /test/snapshots/test.ts.md: -------------------------------------------------------------------------------- 1 | # Snapshot report for `test/test.ts` 2 | 3 | The actual snapshot is saved in `test.ts.snap`. 4 | 5 | Generated by [AVA](https://avajs.dev). 6 | 7 | ## pass rollup errors 8 | 9 | > Snapshot 1 10 | 11 | Error { 12 | message: 'You must supply options.input to rollup', 13 | } 14 | 15 | ## bundle event 16 | 17 | > Snapshot 1 18 | 19 | Node { 20 | body: [ 21 | Node { 22 | declaration: Node { 23 | end: 31, 24 | raw: '\'na na na na na\'', 25 | start: 15, 26 | type: 'Literal', 27 | value: 'na na na na na', 28 | }, 29 | end: 32, 30 | start: 0, 31 | type: 'ExportDefaultDeclaration', 32 | }, 33 | ], 34 | end: 33, 35 | sourceType: 'module', 36 | start: 0, 37 | type: 'Program', 38 | } 39 | 40 | > Snapshot 2 41 | 42 | `export default 'na na na na na';␊ 43 | ` 44 | 45 | ## read content 46 | 47 | > Snapshot 1 48 | 49 | `'use strict';␊ 50 | ␊ 51 | var batman = 'na na na na na';␊ 52 | ␊ 53 | module.exports = batman;␊ 54 | ` 55 | 56 | ## plugin build no warnings 57 | 58 | > Snapshot 1 59 | 60 | true 61 | -------------------------------------------------------------------------------- /test/snapshots/test.ts.snap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rollup/stream/91306a4a240d3d5ec820fec94ebaf3f26108c560/test/snapshots/test.ts.snap -------------------------------------------------------------------------------- /test/sourcemaps.ts: -------------------------------------------------------------------------------- 1 | import { join } from 'path'; 2 | 3 | import test from 'ava'; 4 | import { OutputOptions } from 'rollup'; 5 | 6 | import rollupStream from '..'; 7 | 8 | import helpers from './helpers/helpers'; 9 | 10 | const { read } = helpers; 11 | const input = join(__dirname, 'fixtures/batman.js'); 12 | const output: OutputOptions = { format: 'cjs', sourcemap: true, exports: 'auto' }; 13 | 14 | test('sourcemap added', async (t) => { 15 | const stream = rollupStream({ input, output }); 16 | const result = await read(stream); 17 | t.snapshot(result); 18 | }); 19 | 20 | test('no sourcemap', async (t) => { 21 | const stream = rollupStream({ input, output: { format: 'cjs', exports: 'auto' } }); 22 | const result = await read(stream); 23 | t.snapshot(result); 24 | }); 25 | -------------------------------------------------------------------------------- /test/test.ts: -------------------------------------------------------------------------------- 1 | import { join } from 'path'; 2 | 3 | import test from 'ava'; 4 | 5 | import { OutputOptions, Plugin, RollupBuild } from 'rollup'; 6 | 7 | import rollupStream from '..'; 8 | 9 | import helpers from './helpers/helpers'; 10 | 11 | const { read, wait } = helpers; 12 | const input = join(__dirname, 'fixtures/batman.js'); 13 | const output: OutputOptions = { format: 'cjs', exports: 'auto' }; 14 | 15 | test('exports', async (t) => { 16 | t.truthy(rollupStream); 17 | t.is(typeof rollupStream, 'function'); 18 | }); 19 | 20 | test('return Readable', async (t) => { 21 | const stream = rollupStream({}).on('error', () => {}); 22 | t.is(stream.constructor.name, 'Readable'); 23 | }); 24 | 25 | test('pass rollup errors', async (t) => { 26 | const stream = rollupStream({}); 27 | const result = await wait('error', stream); 28 | t.truthy(result); 29 | t.truthy(result instanceof Error); 30 | t.snapshot(result); 31 | }); 32 | 33 | test('bundle event', async (t) => { 34 | const stream = rollupStream({ input, output }); 35 | const bundle = (await wait('bundle', stream)) as RollupBuild; 36 | t.truthy(bundle); 37 | const cache = bundle.cache!; 38 | t.snapshot(cache.modules[0].ast); 39 | t.snapshot(cache.modules[0].code); 40 | }); 41 | 42 | test('read content', async (t) => { 43 | const stream = rollupStream({ input, output }); 44 | const result = await read(stream); 45 | t.truthy(result); 46 | t.snapshot(result); 47 | }); 48 | 49 | test('plugin build no warnings', async (t) => { 50 | let noWarnings = true; 51 | const testPlugin: Plugin = { 52 | name: 'test-plugin', 53 | buildStart: () => {} 54 | }; 55 | const plugins = [testPlugin]; 56 | const stream = rollupStream({ 57 | input, 58 | output, 59 | plugins, 60 | onwarn: () => { 61 | noWarnings = false; 62 | } 63 | }); 64 | const result = await read(stream); 65 | t.truthy(result); 66 | t.truthy(noWarnings); 67 | t.snapshot(noWarnings); 68 | }); 69 | -------------------------------------------------------------------------------- /tsconfig.base.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "allowSyntheticDefaultImports": true, 4 | "lib": ["es2017"], 5 | "module": "commonjs", 6 | "moduleResolution": "node", 7 | "noEmitOnError": true, 8 | "noUnusedLocals": true, 9 | "noUnusedParameters": true, 10 | "pretty": true, 11 | "skipLibCheck": true, 12 | "sourceMap": true, 13 | "strict": true, 14 | "target": "es2015" 15 | }, 16 | "exclude": ["dist", "node_modules", "test/types"] 17 | } 18 | -------------------------------------------------------------------------------- /tsconfig.eslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.base.json", 3 | "include": [ 4 | "src", 5 | "test" 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.base.json", 3 | "compilerOptions": { 4 | "lib": ["es2017"], 5 | "esModuleInterop": true, 6 | "target": "es2017" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /types/index.d.ts: -------------------------------------------------------------------------------- 1 | import { Readable } from 'stream'; 2 | 3 | import { RollupOptions } from 'rollup'; 4 | 5 | export default function stream(options: RollupOptions): Readable; 6 | --------------------------------------------------------------------------------