0.2.0 • Published 2 years ago

analyze-require-default v0.2.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

analyze-require-default npm.io

Analyze require() statements of ES modules without .default.

JavaScript's module systems can be confusing sometimes, specifically the tiny differences in default exports/imports between ES modules (import/export) and commonjs (module.exports/require) syntax.

Such differences can be hard to find manually, and could potentially cause weird behaviours/bugs, and this is what this package is for!

Here's a quick example to demonstrate:

// a.js

module.exports = 1;
// b.js

export default 2;
// Import default from
import a from 'a'; // This is fine, even though we're mixing 2 different module systems
import b from 'b'; // This is fine, we're on the same module system

const a = require('a'); // This is fine, we're on the same module system
const b = require('b'); // This is NOT fine, we'll get "{ default: 2 }"

Installation

Install the package:

npm i -g analyze-require-default

Usage and options

analyze-require-default [root] [options]

Example

analyze-require-default ./app

Options

OptionAliasWhat it doesPositional argumentsDefault
-c--configUses a configuration file.An absolute or relative path to a configuration file.-
-d--debugOutputs extra debugging information.-false
-v--versionOutputs the current version.--
-h--helpOutput the program's usage information.--

Configuration file

Can be either a .js file or a .json file, supports the following options:

OptionWhat it doesType
rootAn absolute or relative path to the root directory.string
aliasA map of path aliases, similar to Webpack's aliasRecord<string, string \| string[]>
debugOutput extra debugging information.boolean

Example

analyze-require-default -c ./config.js
// ./config.js

const path = require('path');

module.exports = {
  root: './app',
  debug: true,
  alias: {
    Utilities: path.resolve(__dirname, 'src/utilities/'),
    Templates: path.resolve(__dirname, 'src/templates/'),
  },
};