Giter Site home page Giter Site logo

babel-plugin-filter-imports's Introduction

babel-plugin-filter-imports

Build Status npm

This babel plugin is used to removed references to imports within a module. This can be useful for removing debugging statements when doing a production build of your code. It is often used in conjunction with other tools like Uglify that perform dead code elimination.

Installation

$ yarn add --dev babel-plugin-filter-imports

This plugin is for Babel 7. If you need to support:

  • Babel 6 use the babel6 branch
  • Babel 5 use the v0.2.x branch

Example

Given the .babelrc

{
  "plugins": [["filter-imports", {
    "imports": {
      "debugging-tools": [ "warn" ]
    }
  }]]
}

the module

import { warn } from 'debugging-tools';

function join(args, sep) {
  if (arguments.length > 2) {
    warn("join expects at most 2 arguments");
  }
  return args.join(sep);
}

will be transformed to

function join(args, sep) {
  if (arguments.length > 2) {
  }
  return args.join(sep);
}

Configuration

  • options[keepImports] [Boolean]: An flag that indicates imports removal from header.
  • options[imports] [Object]: An object whose keys are names of modules.
  • options[imports][moduleName] [String]: An array of names of imports from moduleName to be removed. You can include 'default' for default export and '*' for a namespace export.

Upgrade to 1.x/2.x

There were breaking changes in the plugin configuration, you must update it to work correctly.

Before 1.x
{
  "plugins": [["filter-imports", {
    "debugging-tools": [ "warn" ]
  }]]
}
After
{
  "plugins": [["filter-imports", {
    "imports": {
      "debugging-tools": [ "warn" ]
    }
  }]]
}

babel-plugin-filter-imports's People

Contributors

alexlafroscia avatar dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar greenkeeper[bot] avatar greenkeeperio-bot avatar layershifter avatar locks avatar mmun avatar pzuraq avatar rwjblue avatar stefanpenner avatar turbo87 avatar xtian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

babel-plugin-filter-imports's Issues

TypeError: Cannot read property 'removed' of null

Using v1.1.0 through @ember-decorators/argument I get the following error for ember-radio-button/addon/types.js when building for production:

The Broccoli Plugin: [BroccoliMergeTrees: Addon#compileAddon(ember-radio-bar) ] failed with:
TypeError: ember-radio-bar/types.js: Cannot read property 'removed' of null
    at /home/jan/github/ember-radio-bar/node_modules/babel-plugin-filter-imports/lib/removeReferences.js:36:16
    at arrayEach (/home/jan/github/ember-radio-bar/node_modules/lodash/lodash.js:537:11)
    at Function.forEach (/home/jan/github/ember-radio-bar/node_modules/lodash/lodash.js:9359:14)
    at removeReferences (/home/jan/github/ember-radio-bar/node_modules/babel-plugin-filter-imports/lib/removeReferences.js:33:20)
    at /home/jan/github/ember-radio-bar/node_modules/babel-plugin-filter-imports/lib/removeReferences.js:45:41
    at arrayEach (/home/jan/github/ember-radio-bar/node_modules/lodash/lodash.js:537:11)
    at Function.forEach (/home/jan/github/ember-radio-bar/node_modules/lodash/lodash.js:9359:14)
    at removeReferences (/home/jan/github/ember-radio-bar/node_modules/babel-plugin-filter-imports/lib/removeReferences.js:33:20)
    at /home/jan/github/ember-radio-bar/node_modules/babel-plugin-filter-imports/lib/index.js:51:49
    at arrayEach (/home/jan/github/ember-radio-bar/node_modules/lodash/lodash.js:537:11)

The broccoli plugin was instantiated at: 
    at BroccoliMergeTrees.Plugin (/home/jan/github/ember-radio-bar/node_modules/broccoli-plugin/index.js:7:31)
    at new BroccoliMergeTrees (/home/jan/github/ember-radio-bar/node_modules/broccoli-merge-trees/index.js:16:10)
    at Function.BroccoliMergeTrees [as _upstreamMergeTrees] (/home/jan/github/ember-radio-bar/node_modules/broccoli-merge-trees/index.js:10:53)
    at mergeTrees (/home/jan/github/ember-radio-bar/node_modules/ember-cli/lib/broccoli/merge-trees.js:85:33)
    at Class.compileAddon (/home/jan/github/ember-radio-bar/node_modules/ember-cli/lib/models/addon.js:1092:12)
    at Class.treeForAddon (/home/jan/github/ember-radio-bar/node_modules/ember-cli/lib/models/addon.js:746:26)
    at Class._treeFor (/home/jan/github/ember-radio-bar/node_modules/ember-cli/lib/models/addon.js:557:33)
    at Class.treeFor (/home/jan/github/ember-radio-bar/node_modules/ember-cli/lib/models/addon.js:517:21)
    at project.addons.reduce (/home/jan/github/ember-radio-bar/node_modules/ember-cli/lib/broccoli/ember-app.js:620:25)
    at Array.reduce (<anonymous>)

/cc @pzuraq

An in-range update of babel-core is breaking the build 🚨

Version 6.18.1 of babel-core just got published.

Branch Build failing 🚨
Dependency babel-core
Current Version 6.18.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As babel-core is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this 💪


Status Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details
Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Match imports with paths?

Hello!

Thank you for this useful plugin.

However, consider that I have the following imports in my source code:

import "third-party/foo";
import "third-party/bar";
import "third-party/baz/qux/quux";

How do I delete all such imports?

I've tried the following, but it didn't work:

[
  'filter-imports', {
    imports: {
      'third-party': true,
      'third-party/*': true,
      'third-party/**': true,
      'third-party/**/*': true,
    },
  },
],

Add test to confirm we only removed unneeded imports.

Given:

import { foo, bar, baz } from 'lol';

foo();
bar();
baz();

Assuming that the test setup instructs the plugin to remove foo and baz from lol module.

The output should be:

import { bar } from 'lol';

bar();

Bug: cannot find path for removal

Hi! This is a really dope plugin!!

Today I faced the following issue: Cannot find the path for removal, please open issue with code example and the stack trace on Github: https://github.com/ember-cli/babel-plugin-filter-imports

It happened with the following code:

import VueTypes from "vue-types";

const props = {
  name: VueTypes.string.isRequired
};

export default {
  name: "App",
  props,
};

The following code works:

import VueTypes from "vue-types";

let props;

props = {
  name: VueTypes.string.isRequired
};

export default {
  name: "App",
  props,
};

Repro code: https://codesandbox.io/s/rrno774wq4

Thank you!

Cannot find module package.json

I'm seeing this weird issue on v1.0.3. It's not reproducible on v0.3.1

Error: The Broccoli Plugin: [BroccoliMergeTrees: Addon#compileAddon(ember-attacher) ] failed with:
Error: Cannot find module '/project/node_modules/ember-attacher/node_modules/babel-plugin-filter-imports/lib//package.json'

The integration code is here, which looks perfectly normal to me:

https://github.com/kybishop/ember-attacher/blob/a2f1cd0850c4afc6b371cf121ff35138e4c0eca3/index.js#L35-L43

Any help would be appreciated. Thanks

An in-range update of eslint is breaking the build 🚨

Version 4.14.0 of eslint was just published.

Branch Build failing 🚨
Dependency eslint
Current Version 4.13.1
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

eslint is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details

Release Notes v4.14.0
  • be2f57e Update: support separate requires in one-var. (fixes #6175) (#9441) (薛定谔的猫)
  • 370d614 Docs: Fix typos (#9751) (Jed Fox)
  • 8196c45 Chore: Reorganize CLI options and associated docs (#9758) (Kevin Partington)
  • 75c7419 Update: Logical-and is counted in complexity rule (fixes #8535) (#9754) (Kevin Partington)
  • eb4b1e0 Docs: reintroduce misspelling in valid-typeof example (#9753) (Teddy Katz)
  • ae51eb2 New: Add allowImplicit option to array-callback-return (fixes #8539) (#9344) (James C. Davis)
  • e9d5dfd Docs: improve no-extra-parens formatting (#9747) (Rich Trott)
  • 37d066c Chore: Add unit tests for overrides glob matching. (#9744) (Robert Jackson)
  • 805a94e Chore: Fix typo in CLIEngine test name (#9741) (@scriptdaemon)
  • 1c2aafd Update: Improve parser integrations (fixes #8392) (#8755) (Toru Nagashima)
  • 4ddc131 Upgrade: debug@^3.1.0 (#9731) (Kevin Partington)
  • f252c19 Docs: Make the lint message source property a little more subtle (#9735) (Jed Fox)
  • 5a5c23c Docs: fix the link to contributing page (#9727) (Victor Hom)
  • f44ce11 Docs: change beginner to good first issue label text (#9726) (Victor Hom)
  • 14baa2e Chore: improve arrow-body-style error message (refs #5498) (#9718) (Teddy Katz)
  • f819920 Docs: fix typos (#9723) (Thomas Broadley)
  • 43d4ba8 Fix: false positive on rulelines-between-class-members (fixes #9665) (#9680) (sakabar)
Commits

The new version differs by 19 commits.

  • 8d166b4 4.14.0
  • 5a29612 Build: changelog update for 4.14.0
  • be2f57e Update: support separate requires in one-var. (fixes #6175) (#9441)
  • 370d614 Docs: Fix typos (#9751)
  • 8196c45 Chore: Reorganize CLI options and associated docs (#9758)
  • 75c7419 Update: Logical-and is counted in complexity rule (fixes #8535) (#9754)
  • eb4b1e0 Docs: reintroduce misspelling in valid-typeof example (#9753)
  • ae51eb2 New: Add allowImplicit option to array-callback-return (fixes #8539) (#9344)
  • e9d5dfd Docs: improve no-extra-parens formatting (#9747)
  • 37d066c Chore: Add unit tests for overrides glob matching. (#9744)
  • 805a94e Chore: Fix typo in CLIEngine test name (#9741)
  • 1c2aafd Update: Improve parser integrations (fixes #8392) (#8755)
  • 4ddc131 Upgrade: debug@^3.1.0 (#9731)
  • f252c19 Docs: Make the lint message source property a little more subtle (#9735)
  • 5a5c23c Docs: fix the link to contributing page (#9727)

There are 19 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of babel7 is breaking the build 🚨

There have been updates to the babel7 monorepoundefined

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

This monorepo update includes releases of one or more dependencies which all belong to the babel7 group definition.

babel7 is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Possible Feature: Optionally don't remove references

This just popped up in ember-decorators/argument#43, we have a use case for wanting to be able to just remove the imports, and keep all references.

Basically we have a shim that acts just like the global class Element in the browser (just re-exports it), but exports a shim class to make fastboot work in Node environments. When we strip all the layers of type checking away the browser code should work exactly the same as before, so there is no need to remove the references.

I'm currently adding a plugin to the library itself to do this, I'm not sure it's going to be a very common use case at all so I definitely understand not adding it upstream here, but I thought I'd bring it up.

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Added the new Node.js version to your .travis.yml

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Opposite plugin

Hello,
This plugin really works well, but I have a question about it: Is there a plugin who instead of removing, adds imports to the build.
In my project I need to add some polyfills automatically and I wanted to do it directly from Babel.
I am sorry if this is not the right way to ask it ^^

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.