From a952acd723bac2a5c76891be9119373dc1ce284f Mon Sep 17 00:00:00 2001 From: Joey Baker Date: Wed, 5 Aug 2015 11:02:12 -0700 Subject: [PATCH] fix: replace babel require hook with a build step MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The babel require hook is explicitly not suitable for libraries: https://babeljs.io/docs/usage/require/ I’ve noticed that in trying to use this module, and trying to use the babel require hook as well, babel stops working. This patch removes the require hook, adds a build process, and runs that build process before a `npm publish` and `npm test` --- .gitignore | 2 ++ .npmignore | 6 ++++++ index.js | 18 +----------------- package.json | 7 +++++-- 4 files changed, 14 insertions(+), 19 deletions(-) create mode 100644 .npmignore diff --git a/.gitignore b/.gitignore index 123ae94..5399ef3 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,5 @@ build/Release # Dependency directory # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git node_modules + +dist/ diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..e319420 --- /dev/null +++ b/.npmignore @@ -0,0 +1,6 @@ +# Generated by dmn (https://github.com/inikulin/dmn) + +.git* +.npmignore +test/ +src/ diff --git a/index.js b/index.js index 88c9ed8..a76ce5c 100644 --- a/index.js +++ b/index.js @@ -1,19 +1,3 @@ 'use strict'; -var path = require('path'); - -var escape = function (str) { - return str.replace(/[\[\]\/{}()*+?.\\^$|-]/g, '\\$&'); -}; - -var regexp = ['src', 'test'].map(function (i) { - return '^' + escape(path.join(__dirname, i) + path.sep); -}).join('|'); - -require('babel/register')({ - only: new RegExp('(' + regexp + ')'), - ignore: false, - loose: 'all' -}); - -module.exports = require('./src'); +module.exports = require('./dist'); diff --git a/package.json b/package.json index 9851671..46b112c 100644 --- a/package.json +++ b/package.json @@ -4,18 +4,21 @@ "description": "A require hook to compile CSS Modules on the fly", "main": "index.js", "dependencies": { - "babel": "^5.8.20", "postcss": "^4.1.16", "postcss-modules-extract-imports": "0.0.5", "postcss-modules-local-by-default": "0.0.9", "postcss-modules-scope": "0.0.8" }, "devDependencies": { + "babel": "^5.8.20", "css-modules-loader-core": "0.0.12", + "in-publish": "^2.0.0", "mocha": "^2.2.5" }, "scripts": { - "test": "mocha --compilers js:babel/register" + "test": "npm run -s build && mocha --compilers js:babel/register", + "build": "babel src --out-dir dist", + "prepublish": "in-publish && npm run -s build || in-install" }, "repository": { "type": "git",