Socket
Socket
Sign inDemoInstall

definitely-loader

Package Overview
Dependencies
1
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    definitely-loader

A webpack loader which disallows importing nonexistent members from a module


Version published
Maintainers
1
Install size
20.2 kB
Created

Readme

Source

definitely-loader Build Status

A Webpack loader which renders imported modules definite, such that attempts to reference nonexistent exports thereof generate exceptions.

Installation

$ npm install --save-dev definitely-loader

Example usage

import { foo } from 'definitely!./some/module'

doSomething(foo) // throws an error if `baz` is not actually exported by `./some/module`

Rationale

For some source formats there exist Webpack loaders which can statically determine whether imported names are valid (notably for ES6 there is eslint-loader with the import plugin). For the rest, this loader offers the next best option: a runtime error.

For example, if you are using the excellent css-loader to import locally-scoped styles, you still have the problem that you might be trying to reference styles which don't exist in your .css file. For example, with this CSS module:

/* MyComponent.css */
.foo {
    background-color: red
}

and this React component adjacent to it:

// MyComponent.js

import React from 'react'

import styles from './MyComponent.css'

export default class MyComponent extends React.Component {
    render() {
        return (<div className={styles.bar} />) // silently fails!
    }
}

the reference to styles.bar in the render is a bug, because bar is not defined in our CSS, but it silently evaluates to undefined and the only evidence that anything is wrong is that things won't look as we expect. Hunting down the source of such a bug is far more laborious than it should be. Instead we can make that line generate a runtime error by adding definitely-loader to the CSS loader chain in webpack.config.js, for example:

{
    test: /\.css$/,
    loaders: [
        'definitely',
        'style',
        'css?modules'
    ]
}

Keywords

FAQs

Last updated on 02 Sep 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc