Latest regexp features in atom package


#1

Heya,
I am developing a package for atom.
I have faced an issue with regexps.
I would like to use latest regexp features like s flag, or named groups etc. Currently, electron is using a bit old chromium version

$ npm i -D electron@latest
Electron 2.0.5
Node 8.9.3
Chromium 61.0.3163.100

After electron v3 release new regexp features will work. But I need to get them work now.
How can I add babel-plugin-transform-modern-regexp

Can anyone help me with this?
Thanks in advance!


#2

You need to compile your package’s code using Babel. I guess your .babelrc would look something like the following – I haven’t tested this!

{
    "presets": [
        [
            "env", {
                "targets": {
                    "electron": "2.0.0",
                },
                "useBuiltIns": true,
            }
        ]
    ],
    "plugins": [
        "transform-modern-regexp"
    ]
}

This config is based on @jneuendorf’s post.

You can use Node scripts in your package manifest to compile your source.

Example:

"scripts": {
    "build": "babel src -d lib"
},
"devDependencies": {
    "babel-cli": "^6.0.0",
    "babel-plugin-transform-modern-regexp": "^0.0.5"
}

Note: You can compile your code whenever a user installs your package (see postinstall in the scripts documentation), but that has one major drawback: you cannot use devDependencies.


#3

many thanks for your help! I will try that. Thank you!


#4

You can also transpile your code before publishing the package using prepublish and friends. Thus your dev code would then live in your repo and the transpiled/bundled code in the apm registry.