open-index/open-npm huggingface dataset:
npm package: @shelter/babel-plugin-codemod-script-to-module
Description: A babel codemod to transform a script to a module with equivalent behaviour
Author: Cameron Martin
Latest version: 0.0.4

# babel-plugin-codemod-script-to-module

A babel codemod to transform an [ECMAScript script](https://tc39.github.io/ecma262/#sec-scripts) to a [ECMAScript module](https://tc39.github.io/ecma262/#sec-modules) while preserving behaviour.
This is useful for integrating legacy code with your module bundler.

## Usage

This is designed to be used alongside [babel-codemod].

```sh
yarn add -D @shelter/babel-plugin-codemod-script-to-module babel-codemod

codemod --plugin @shelter/babel-plugin-codemod-script-to-module --source-type script path/to/file.js
```

After you have finished using the codemod, you can remove the related packages:

```sh
yarn remove @shelter/babel-plugin-codemod-script-to-module babel-codemod
```

## Testing

Most testing is done by using the fixtures in the `__fixtures__` directory. Their purpose is two-fold. Firstly, we check that `input.js` compiles to `output.js`. Secondly, these files contain assertions, and we check that the assertions pass in both the input when interpreted as a _script_ and the output when interpreted as a _module_. These assertions help ensure that behaviour is preserved during transformation.

[babel-codemod]: https://github.com/square/babel-codemod