Skip to content
This repository was archived by the owner on Aug 18, 2021. It is now read-only.

Commit 4327cc8

Browse files
committed
Remove unused .gitmodules (#457)
1 parent a750684 commit 4327cc8

File tree

2 files changed

+33
-49
lines changed

2 files changed

+33
-49
lines changed

.gitmodules

-3
This file was deleted.

index.js

+33-46
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,10 @@ var codeFrame = require("babel-code-frame");
1010
var hasPatched = false;
1111
var eslintOptions = {};
1212

13-
function createModule(filename) {
14-
var mod = new Module(filename);
15-
mod.filename = filename;
16-
mod.paths = Module._nodeModulePaths(path.dirname(filename));
17-
return mod;
18-
}
19-
20-
function monkeypatch() {
21-
if (hasPatched) return;
22-
hasPatched = true;
23-
24-
var eslintLoc;
13+
function getModules() {
2514
try {
2615
// avoid importing a local copy of eslint, try to find a peer dependency
27-
eslintLoc = Module._resolveFilename("eslint", module.parent);
16+
var eslintLoc = Module._resolveFilename("eslint", module.parent);
2817
} catch (err) {
2918
try {
3019
// avoids breaking in jest where module.parent is undefined
@@ -35,18 +24,35 @@ function monkeypatch() {
3524
}
3625

3726
// get modules relative to what eslint will load
38-
var eslintMod = createModule(eslintLoc);
39-
// ESLint v1.9.0 uses estraverse directly to work around https://github.com/npm/npm/issues/9663
27+
var eslintMod = new Module(eslintLoc);
28+
eslintMod.filename = eslintLoc;
29+
eslintMod.paths = Module._nodeModulePaths(path.dirname(eslintLoc));
30+
31+
var Definition = eslintMod.require("escope/lib/definition").Definition;
32+
var escope = eslintMod.require("escope");
4033
var estraverse = eslintMod.require("estraverse");
34+
var referencer = eslintMod.require("escope/lib/referencer");
35+
36+
if (referencer.__esModule) referencer = referencer.default;
37+
38+
return {
39+
Definition,
40+
escope,
41+
estraverse,
42+
referencer,
43+
};
44+
}
45+
46+
function monkeypatch(modules) {
47+
var Definition = modules.Definition;
48+
var escope = modules.escope;
49+
var estraverse = modules.estraverse;
50+
var referencer = modules.referencer;
4151

4252
Object.assign(estraverse.VisitorKeys, t.VISITOR_KEYS);
4353
estraverse.VisitorKeys.MethodDefinition.push("decorators");
4454
estraverse.VisitorKeys.Property.push("decorators");
4555

46-
// monkeypatch escope
47-
var escopeLoc = Module._resolveFilename("escope", eslintMod);
48-
var escopeMod = createModule(escopeLoc);
49-
var escope = require(escopeLoc);
5056
var analyze = escope.analyze;
5157
escope.analyze = function (ast, opts) {
5258
opts.ecmaVersion = eslintOptions.ecmaVersion;
@@ -59,28 +65,6 @@ function monkeypatch() {
5965
return results;
6066
};
6167

62-
// monkeypatch escope/referencer
63-
var referencerLoc;
64-
try {
65-
referencerLoc = Module._resolveFilename("./referencer", escopeMod);
66-
} catch (err) {
67-
throw new ReferenceError("couldn't resolve escope/referencer");
68-
}
69-
var referencerMod = createModule(referencerLoc);
70-
var referencer = require(referencerLoc);
71-
if (referencer.__esModule) {
72-
referencer = referencer.default;
73-
}
74-
75-
// reference Definition
76-
var definitionLoc;
77-
try {
78-
definitionLoc = Module._resolveFilename("./definition", referencerMod);
79-
} catch (err) {
80-
throw new ReferenceError("couldn't resolve escope/definition");
81-
}
82-
var Definition = require(definitionLoc).Definition;
83-
8468
// if there are decorators, then visit each
8569
function visitDecorators(node) {
8670
if (!node.decorators) {
@@ -368,11 +352,14 @@ exports.parse = function (code, options) {
368352
delete eslintOptions.globalReturn;
369353
}
370354

371-
try {
372-
monkeypatch();
373-
} catch (err) {
374-
console.error(err.stack);
375-
process.exit(1);
355+
if (!hasPatched) {
356+
hasPatched = true;
357+
try {
358+
monkeypatch(getModules());
359+
} catch (err) {
360+
console.error(err.stack);
361+
process.exit(1);
362+
}
376363
}
377364

378365
return exports.parseNoPatch(code, options);

0 commit comments

Comments
 (0)