Socket
Book a DemoInstallSign in
Socket

babel-plugin-amd-checker

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-amd-checker

Module format checking plugin for Babel usable in both Node.js the web browser environments.

0.0.2
latest
Source
npmnpm
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

babel-plugin-amd-checker

Latest version Dependency status

A Babel plugin to check the format of your modules when compiling your code using Babel. This plugin allows you to abort the module transformation, if the module source complies with AMD and let the transformation apply only on ESM modules. transform the path of each source module using a custom JavaScript function.

This plugin is supposed to be used with requirejs-babel7, where the target environment is a web browser using @babel/standalone. If if detects an AMD module, it will throw an error of the class AmdDetected and abort the module transformation. The error can be caught and ignored in the build pipeline.

Table of Contents

Installation

This module can be installed in your project using NPM, PNPM or Yarn. Make sure, that you use Node.js version 6 or newer.

npm i -D babel-plugin-amd-checker
pnpm i -D babel-plugin-amd-checker
yarn add babel-plugin-amd-checker

Babel Configuration Examples

Prevent the transpiler to wrap source files that are already wrapped by define or require as AMD modules:

{
  plugins: ['amd-checker']
}

A typical configuration combined with babel-plugin-module-resolver-standalone and set within requirejs-babel7 by default:

{
  plugins: [
    'amd-checker',
    'transform-modules-amd',
    [
      'module-resolver',
      {
        resolvePath: function (sourcePath, currentFile, opts) {
          // Avoid prefixing modules handled by other plugins.
          if (sourcePath.indexOf('!') < 0) {
            return 'es6!' + sourcePath;
          }
        }
      }
    ]
  ]
}

Error handling during the transpilation in a RequireJS plugin:

var amdChecker = require('babel-plugin-amd-checker')
babel.registerPlugin('amd-checker', amdChecker);

var code;
try {
  code = babel.transform(text, options).code;
} catch (error) {
  if (!(error instanceof amdChecker.AmdDetected)) {
    return onload.error(error);
  }
  code = text;
}

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Lint and test your code.

License

Copyright (c) 2022 Ferdinand Prantl

Licensed under the MIT license.

Keywords

babel-plugin

FAQs

Package last updated on 06 Jan 2022

Did you know?

Socket

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.