Skip to content

Commit

Permalink
fix(#4251): load_plugin with extra line EOF (#4256)
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Apr 22, 2020
1 parent dd8976c commit b60f815
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/hexo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ class Hexo extends EventEmitter {
require.extensions = Module._extensions;
require.cache = Module._cache;

script = `(function(exports, require, module, __filename, __dirname, hexo){${script}});`;
script = `(function(exports, require, module, __filename, __dirname, hexo){${script}\n});`;

const fn = runInThisContext(script, path);

Expand Down
20 changes: 19 additions & 1 deletion test/scripts/hexo/load_plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ describe('Load plugins', () => {
return fs.unlink(path);
});

it('load theme scripts', async () => {
it('load theme scripts', () => {
const path = join(hexo.theme_script_dir, 'test.js');

return fs.writeFile(path, script).then(() => loadPlugins(hexo)).then(() => {
Expand All @@ -209,4 +209,22 @@ describe('Load plugins', () => {
return fs.unlink(path);
});
});

// Issue #4251
it('load scripts with sourcemap EOF', async () => {
const path = join(hexo.script_dir, 'test.js');

const script = [
'(() => {',
' hexo._script_test = true;',
'})();',
'//# sourceMappingURL=data:application/json;<redacted>'
].join('\n');

fs.writeFile(path, script);
await loadPlugins(hexo);

hexo._script_test.should.eql(true);
return fs.unlink(path);
});
});

0 comments on commit b60f815

Please sign in to comment.