Skip to content

Commit

Permalink
Make sure it also works when included as an npm module
Browse files Browse the repository at this point in the history
When I uploaded the package to npm, the index.js in the package was
itself placed under node_modules, which made the exclude-node-modules
feature not work at all (so 'use strict' would be applied to all files.

Now we use a substring of __dirname up to the first occurrence of the
string 'node_modules' as the base directory name.
  • Loading branch information
torarvid committed Jun 15, 2017
1 parent 0269650 commit e04aed8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ var module = require('module')
var compile = module.prototype._compile
var path = require('path')

var index = __dirname.indexOf('node_modules')
var baseDirectory = (index < 1) ? __dirname : __dirname.substr(0, index - 1)

module.prototype._compile = function (content, filename) {
var isThirdParty = filename.startsWith(path.join(__dirname, 'node_modules'))
var isThirdParty = filename.startsWith(path.join(baseDirectory, 'node_modules'))
if (!isThirdParty) {
content = "'use strict';" + content
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "auto-strict",
"version": "0.0.1",
"version": "0.0.2",
"description": "Add 'use strict'; to all code not in node_modules",
"main": "index.js",
"author": "Tor Arvid Lund <[email protected]>",
Expand Down

0 comments on commit e04aed8

Please sign in to comment.