-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Major fixes for External URL option. #1500
Conversation
Update from original.
scripts/tags/exturl.js
Outdated
@@ -4,8 +4,9 @@ | |||
|
|||
'use strict'; | |||
|
|||
var util = require('hexo-util'); | |||
var util = require(hexo.base_dir + 'node_modules/hexo/node_modules/hexo-util'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Identifier 'base_dir' is not in camel case.
exturl
option.
exturl
option.
Thanks. 👍 |
@@ -4,8 +4,11 @@ | |||
|
|||
'use strict'; | |||
|
|||
var util = require('hexo-util'); | |||
/*jshint camelcase: false */ | |||
var util = require(hexo.base_dir + 'node_modules/hexo/node_modules/hexo-util'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it var util = require(hexo.base_dir + 'node_modules/hexo-util');
?
My local environment information:
hexo: 3.2.2
hexo-cli: 1.0.2
os: Darwin 16.4.0 darwin x64
http_parser: 2.7.0
node: 7.6.0
v8: 5.5.372.40
uv: 1.11.0
zlib: 1.2.11
ares: 1.10.1-DEV
modules: 51
openssl: 1.0.2k
icu: 58.2
unicode: 9.0
cldr: 30.0.3
tz: 2016j
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's path to the hexo-util
, on clean install all work.
- If we will install clean hexo, in
node_modules
will nothexo-ulil
. Buthexo-util
will be inhexo
subdir. - If we will install
hexo-util
with cusom command, module will be innode_modules
, not inhexo
node-modules.
I don't undestand why Tommy do that, but there is 2 different path on same hexo-util
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the algorithm of installing a package with npm, hexo-util
should be installed in the site's node_modules
instead of Hexo's. In this case, it should be OK to use require('hexo-util')
in tag scripts directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, it should be OK to use require('hexo-util')
Yes, it is. But, if hexo-util
is standart hexo module in hexo
subdir, why need to separate this to external module?
Anyway, u tested it? All should be worked fine on clean install.
If user will install hexo-util
as external moduke, no matter, tag will use internal hexo-util
.
What the question, VI? I don't understand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please take a look at npm v3 Dependency Resolution. For this case, hexo-util
is a dependency of Hexo, but is will be installed in node_module
just alone with hexo
module (not in the sub-directory of hexo
module).
I tested it with latest stable Node.js and NPM and the issue reporter has tested it as well.
So the question is that users who use npm lower than version 3 will encounter the error hexo-util
module not found.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My version at test it:
hexo-cli: 1.0.2
os: Linux 2.6.32-642.4.2.el6.x86_64 linux x64
http_parser: 1.2
node: 0.10.48
v8: 3.14.5.11
ares: 1.9.0-DEV
uv: 0.10.34
zlib: 1.2.3
modules: 11
openssl: 1.0.1e-fips
And hexo-util
was not found, yes. But if was defined only variable (was in 1st my version, before this fix).
In this fix, there is:
hexo.base_dir
- global hexo variable with ABSOLUTE path to root dir (where is source, public, node_modules, etc).- 'node_modules/hexo/node_modules/hexo-util' - is second path of string to enforce use internal
hexo-util
directory with all needed modules into this.
If Hexo in root dir in linux, for example, expected path something like this:
/root/hexo/node_modules/hexo/node_modules/hexo-util
- this will be used, not /root/hexo/node_modules/hexo-util
.
U can test it by uncomment //console.log(util);
string at scripts/tags/exturl.js
file.
npm lower than version 3 will encounter the error hexo-util module not found.
hexo-util module is present in internal Hexo folder anyway, no matter what version NPM u have. So, with that fix module will use path to the internal module and will work on all versions and all platforms, i think.
For those who also encounter this issue, please check your NPM version.
3: Still not work. Please remove node_modules directory and reinstall using npm install.
< 3: Please add hexo-util explicitly via npm install --save-dev hexo-util to you site package deps.
No, this not need to reccomend. I repeat, in standart hexo repository always
will be hexo-util internal module. So, i just point absolute path with location to him.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. hexo-util
module would not exist in the hexo/node_modules/
directory if using NPM whose version is above 3 to install hexo.
Please see the following testing result:
You could see that, hexo-util
module does not exist in the hexo/node_modules
directory when installed with NPM 3. So the solution for this issue is that we could just use require('hexo-util')
in the tag scripts and inform users to upgrade their NPM or install missing modules (hexo-util
in this case) if errors occur to simplify the process.
For your information, the following is what I did in this testing:
mkdir test-with-npm2 && cd test-with-npm2
nvm use v0.10.48
npm init
npm install --save-dev hexo
./info.sh
mkdir test-with-npm3 && cd test-with-npm3
nvm use v7.6.0
npm init
npm install --save-dev hexo
./info.sh
The content of info.sh
file is:
#!/bin/bash
printf 'Node.js version: %s\n' $(node -v)
printf 'NPM version: %s\n' $(npm -v)
printf 'hexo-util module in hexo sub-direcotry: \n'
printf ' ' && ls -ld node_modules/hexo/node_modules/hexo-util
printf 'hexo-util nodele in root sub-directory: \n'
printf ' ' && ls -ld node_modules/hexo-util
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to reproducte it:
npm -v
1.3.6
cd /tmp
mkdir hexo-test
cd hexo-test
nano info.sh
chmod 755 info.sh
And install under the following guide: https://hexo.io/
npm install hexo-cli -g
hexo init blog
[root@almostover hexo-test]# ./info.sh
Node.js version: v0.10.48
NPM version: 1.3.6
hexo-util module in hexo sub-direcotry:
ls: cannot access node_modules/hexo/node_modules/hexo-util: No such file or directory
hexo-util nodele in root sub-directory:
ls: cannot access node_modules/hexo-util: No such file or directory
[root@almostover hexo-test]# cd blog
[root@almostover blog]# .././info.sh
Node.js version: v0.10.48
NPM version: 1.3.6
hexo-util module in hexo sub-direcotry:
drwxr-xr-x 5 root root 4096 Mar 16 00:11 node_modules/hexo/node_modules/hexo-util
hexo-util nodele in root sub-directory:
ls: cannot access node_modules/hexo-util: No such file or directory
mv ../info.sh info.sh
[root@almostover blog]# ./info.sh
Node.js version: v0.10.48
NPM version: 1.3.6
hexo-util module in hexo sub-direcotry:
drwxr-xr-x 5 root root 4096 Mar 16 00:11 node_modules/hexo/node_modules/hexo-util
hexo-util nodele in root sub-directory:
ls: cannot access node_modules/hexo-util: No such file or directory
[root@almostover blog]# hexo -v
hexo: 3.2.2
hexo-cli: 1.0.2
os: Linux 2.6.32-642.4.2.el6.x86_64 linux x64
http_parser: 1.2
node: 0.10.48
v8: 3.14.5.11
ares: 1.9.0-DEV
uv: 0.10.34
zlib: 1.2.3
modules: 11
openssl: 1.0.1e-fips
Yep, that's right. So, we stay this update for
require(hexo.base_dir + 'node_modules/hexo/node_modules/hexo-util');
Or we rollback to the
require('hexo-util');
?
Major fixes for External URL option.
Global fixes and additions of
exturl
option for #1438.