Skip to content

Commit 19195d8

Browse files
committed
fix global npm path
1 parent dd5c3e3 commit 19195d8

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

generators/app/index.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,41 @@
11
const Generator = require('yeoman-generator');
22
const pkg = require('../../package.json');
33

4+
const globalModules = require('global-modules');
45
const globby = require('globby');
56
const updateNotifier = require('update-notifier');
7+
const yarnModules = require('yarn-global-modules');
68
const yosay = require('yosay');
7-
const { basename, join } = require('path');
9+
const { basename, join, resolve } = require('path');
10+
const { existsSync } = require('fs');
811

912
// Is there a newer version of this generator?
1013
updateNotifier({ pkg: pkg }).notify();
1114

12-
const hljsDir = join(__dirname, '..', '..', 'node_modules', 'highlight.js');
15+
// console.log(require.resolve('highlight.js'))
16+
const hljsDir = getModuleDir();
17+
18+
function getModuleDir() {
19+
const npmDir = resolve(globalModules, 'generator-hljs/node_modules', 'highlight.js');
20+
21+
if (existsSync(npmDir)) {
22+
return npmDir;
23+
}
24+
25+
const yarnDir = resolve(yarnModules(), 'node_modules', 'highlight.js');
26+
27+
if (existsSync(yarnDir)) {
28+
return yarnDir;
29+
}
30+
31+
const localDir = resolve(__dirname, '..', '..', 'node_modules', 'highlight.js');
32+
33+
if (existsSync(localDir)) {
34+
return localDir;
35+
}
36+
37+
throw 'Error: highlight.js not found in node_modules';
38+
}
1339

1440
function getLanguages() {
1541
const languagesPath = join(hljsDir, 'src', 'languages');

0 commit comments

Comments
 (0)