Skip to content
This repository has been archived by the owner on Jul 11, 2018. It is now read-only.

Commit

Permalink
fix: fix panel changes in symlinked bundle folders not being picked up
Browse files Browse the repository at this point in the history
  • Loading branch information
from-the-river-to-the-sea committed Aug 22, 2017
1 parent ace6af3 commit 06ffb71
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 34 deletions.
22 changes: 13 additions & 9 deletions index.js
Expand Up @@ -12,7 +12,7 @@ const Promise = require('bluebird');
const semver = require('semver');

// Start up the watcher, but don't watch any files yet.
// We'll add the files we want to watch later, in the startWatching() method.
// We'll add the files we want to watch later, in the init() method.
const watcher = chokidar.watch([
'!**/*___jb_*___', // Ignore temp files created by JetBrains IDEs
'!**/node_modules/**', // Ignore node_modules folders
Expand Down Expand Up @@ -166,10 +166,17 @@ module.exports.init = function (rootPath, nodecgVersion, nodecgConfig, Logger) {

// Once all the bowerPromises have been resolved, start up the bundle watcher and emit "allLoaded"
return Promise.all(bowerPromises).then(() => {
watcher.add([
bundlesPath + '/**/dashboard/**', // Watch dashboard folders
bundlesPath + '/**/package.json' // Watch bundle package.json files
]);
// Workaround for https://github.com/paulmillr/chokidar/issues/419
// This workaround is necessary to fully support symlinks.
fs.readdirSync(bundlesPath)
.map(name => path.join(bundlesPath, name))
.filter(source => fs.statSync(source).isDirectory())
.forEach(bundlePath => {
watcher.add([
path.join(bundlePath, 'dashboard'), // Watch dashboard folders
path.join(bundlePath, '/package.json') // Watch bundle package.json files
]);
});
}).catch(
/* istanbul ignore next */
err => {
Expand Down Expand Up @@ -240,10 +247,7 @@ module.exports.remove = function (bundleName) {
* Only used by tests.
*/
module.exports._stopWatching = function () {
watcher.unwatch([
bundlesPath + '/**/dashboard/**', // Unwatch dashboard folders
bundlesPath + '/**/package.json' // Unwatch bundle package.json files
]);
watcher.close();
};

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/npm_installer.js
@@ -1,6 +1,6 @@
'use strict';

const execSync = require('child_process').execSync;
const spawn = require('cross-spawn');
const util = require('util');
const os = require('os');
const format = require('util').format;
Expand All @@ -24,7 +24,7 @@ module.exports = function (config, Logger) {
*/
try {
process.stdout.write(format('Verifying/installing npm deps for bundle %s...', bundle.name));
execSync('npm install --production', {
spawn.sync('npm', ['install', '--production'], {
cwd: bundle.dir,
stdio: ['pipe', 'pipe', 'pipe'],
env: npmEnv
Expand Down
36 changes: 14 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -44,7 +44,8 @@
"dependencies": {
"bluebird": "^3.4.6",
"bower": "^1.7.1",
"chokidar": "^1.4.1",
"chokidar": "^1.7.0",
"cross-spawn": "^5.1.0",
"extend": "^3.0.0",
"fs.extra": "^1.3.2",
"nodecg-bundle-parser": "^0.3.4",
Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/change-panel-symlink-target/dashboard/panel.html
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>

</body>
</html>
18 changes: 18 additions & 0 deletions test/fixtures/change-panel-symlink-target/package.json
@@ -0,0 +1,18 @@
{
"name": "change-panel-symlink",
"version": "0.0.1",
"homepage": "http://github.com/nodecg",
"author": "Alex Van Camp <email@alexvan.camp>",
"description": "A test bundle",
"license": "MIT",
"nodecg": {
"compatibleRange": "~0.7.0",
"dashboardPanels": [
{
"name": "panel",
"title": "Panel",
"file": "panel.html"
}
]
}
}
16 changes: 16 additions & 0 deletions test/manager.spec.js
Expand Up @@ -17,6 +17,10 @@ before(function (done) {
}

wrench.copyDirSyncRecursive('test/fixtures', '_workingTest', {forceDelete: true});
fs.symlinkSync(
path.resolve('_workingTest/change-panel-symlink-target'),
path.resolve('_workingTest/bundles/change-panel-symlink')
);

const nodecgConfig = {
bundles: {
Expand Down Expand Up @@ -98,6 +102,18 @@ describe('watcher', () => {
fs.writeFileSync(panelPath, panel);
});

it('should detect panel HTML file changes when the bundle is symlinked', function (done) {
this.bundleManager.once('bundleChanged', bundle => {
expect(bundle.name).to.equal('change-panel-symlink');
done();
});

const panelPath = '_workingTest/bundles/change-panel-symlink/dashboard/panel.html';
let panel = fs.readFileSync(panelPath);
panel += '\n';
fs.writeFileSync(panelPath, panel);
});

it('should reload the bundle\'s config when the bundle is reloaded due to a change', function (done) {
const manifest = JSON.parse(fs.readFileSync('_workingTest/bundles/change-config/package.json'));
const config = JSON.parse(fs.readFileSync('_workingTest/cfg/change-config.json'));
Expand Down

0 comments on commit 06ffb71

Please sign in to comment.