From 515051d8170f3cc7b87873ef832120f8f184c7ed Mon Sep 17 00:00:00 2001 From: Berkeley Martinez Date: Tue, 31 May 2016 15:26:24 -0700 Subject: [PATCH] Fix lint errors Remove commonFramework build from gulpfile --- client/iFrameScripts.js | 70 ------------- client/plugin.js | 97 ------------------- client/sagas/execute-challenge-saga.js | 8 +- client/sagas/frame-saga.js | 4 +- common/app/redux/actions.js | 2 +- common/app/redux/fetch-user-saga.js | 9 +- common/app/routes/Hikes/redux/answer-saga.js | 18 ++-- .../routes/Hikes/redux/fetch-hikes-saga.js | 11 +-- gulpfile.js | 71 +------------- package.json | 1 - server/server.js | 2 +- 11 files changed, 19 insertions(+), 274 deletions(-) delete mode 100644 client/iFrameScripts.js delete mode 100644 client/plugin.js diff --git a/client/iFrameScripts.js b/client/iFrameScripts.js deleted file mode 100644 index 7d399590cd..0000000000 --- a/client/iFrameScripts.js +++ /dev/null @@ -1,70 +0,0 @@ -document.addEventListener('DOMContentLoaded', function() { - var common = parent.__common; - var Rx = parent.Rx; - - common.getJsOutput = function evalJs(source = '') { - if (window.__err || !common.shouldRun()) { - return window.__err || 'source disabled'; - } - let output; - try { - /* eslint-disable no-eval */ - output = eval(source); - /* eslint-enable no-eval */ - } catch (e) { - window.__err = e; - } - return output; - }; - - common.runTests$ = function runTests$({ tests = [], source }) { - const editor = { getValue() { return source; } }; - if (window.__err) { - return Rx.Observable.throw(window.__err); - } - - // Iterate through the test one at a time - // on new stacks - return Rx.Observable.from(tests, null, null, Rx.Scheduler.default) - // add delay here for firefox to catch up - .delay(100) - .map(({ text, testString }) => { - const newTest = { text, testString }; - let test; - try { - /* eslint-disable no-eval */ - test = eval(testString); - /* eslint-enable no-eval */ - if (typeof test === 'function') { - // maybe sync/promise/observable - if (test.length === 0) { - test(); - } - // callback test - if (test.length === 1) { - console.log('callback test'); - } - } - } catch (e) { - newTest.err = e.message.split(':').shift(); - } - return newTest; - }) - // gather tests back into an array - .toArray(); - }; - - // used when updating preview without running tests - common.checkPreview$ = function checkPreview$(args) { - if (window.__err) { - return Rx.Observable.throw(window.__err); - } - return Rx.Observable.just(args); - }; - - // now that the runPreviewTest$ is defined - // we set the subject to true - // this will let the updatePreview - // script now that we are ready. - common.testFrameReady$.onNext(true); -}); diff --git a/client/plugin.js b/client/plugin.js deleted file mode 100644 index c6fd8f793a..0000000000 --- a/client/plugin.js +++ /dev/null @@ -1,97 +0,0 @@ -/* eslint-disable no-eval */ -/* global importScripts, application */ -// executes the given code and handles the result - -function importScript(url, error) { - try { - importScripts(url); - } catch (e) { - error = e; - } - return error; -} - -function run(code, cb) { - var err = null; - var result = {}; - - try { - var codeExec = runHidden(code); - result.type = typeof codeExec; - result.output = stringify(codeExec); - } catch (e) { - err = e.message; - } - - if (err) { - cb(err, null); - } else { - cb(null, result); - } - - self.close(); -} - - -// protects even the worker scope from being accessed -function runHidden(code) { - - /* eslint-disable no-unused-vars */ - var indexedDB = null; - var location = null; - var navigator = null; - var onerror = null; - var onmessage = null; - var performance = null; - var self = null; - var webkitIndexedDB = null; - var postMessage = null; - var close = null; - var openDatabase = null; - var openDatabaseSync = null; - var webkitRequestFileSystem = null; - var webkitRequestFileSystemSync = null; - var webkitResolveLocalFileSystemSyncURL = null; - var webkitResolveLocalFileSystemURL = null; - var addEventListener = null; - var dispatchEvent = null; - var removeEventListener = null; - var dump = null; - var onoffline = null; - var ononline = null; - /* eslint-enable no-unused-vars */ - - var error = null; - error = importScript( - 'https://cdnjs.cloudflare.com/ajax/libs/chai/2.2.0/chai.min.js' - ); - - - /* eslint-disable*/ - var assert = chai.assert; - /* eslint-enable */ - - if (error) { - return error; - } - - return eval(code); -} - - -// converts the output into a string -function stringify(output) { - var result; - - if (typeof output === 'undefined') { - result = 'undefined'; - } else if (output === null) { - result = 'null'; - } else { - result = JSON.stringify(output) || output.toString(); - } - - return result; -} - -application.setInterface({ run: run }); diff --git a/client/sagas/execute-challenge-saga.js b/client/sagas/execute-challenge-saga.js index 60e27c06c9..867556ba46 100644 --- a/client/sagas/execute-challenge-saga.js +++ b/client/sagas/execute-challenge-saga.js @@ -4,6 +4,7 @@ import { ajax$ } from '../../common/utils/ajax-stream'; import throwers from '../rechallenge/throwers'; import transformers from '../rechallenge/transformers'; import types from '../../common/app/routes/challenges/redux/types'; +import { createErrorObservable } from '../../common/app/redux/actions'; import { frameMain, frameTests, @@ -43,7 +44,7 @@ function cacheScript({ src } = {}) { }) .map(({ response }) => response) .map(script => ``) - .catch(e => (console.error(e), Observable.just(''))) + .catch(createErrorObservable) .shareReplay(); scriptCache.set(src, script$); @@ -126,9 +127,6 @@ export default function executeChallengeSaga(action$, getState) { initOutput('// running test') : null )) - .catch(error => Observable.just({ - type: 'app.error', - error - })); + .catch(createErrorObservable); }); } diff --git a/client/sagas/frame-saga.js b/client/sagas/frame-saga.js index 89b2b4197e..e35d28b15b 100644 --- a/client/sagas/frame-saga.js +++ b/client/sagas/frame-saga.js @@ -101,9 +101,7 @@ export default function frameSaga(actions$, getState, { window, document }) { }); return Observable.merge( - proxyLogger$.map(args => { - return updateOutput(args); - }), + proxyLogger$.map(updateOutput), runTests$.flatMap(() => { const { frame } = getFrameDocument(document, testId); const { tests } = getState().challengesApp; diff --git a/common/app/redux/actions.js b/common/app/redux/actions.js index 7cdde164cd..badd86be67 100644 --- a/common/app/redux/actions.js +++ b/common/app/redux/actions.js @@ -42,7 +42,7 @@ export const updateChallengesData = createAction(types.updateChallengesData); export const updateJobsData = createAction(types.updateJobsData); export const updateHikesData = createAction(types.updateHikesData); -export const createErrorObserable = error => Observable.just({ +export const createErrorObservable = error => Observable.just({ type: types.handleError, error }); diff --git a/common/app/redux/fetch-user-saga.js b/common/app/redux/fetch-user-saga.js index ac85e0bb87..874ee4ff78 100644 --- a/common/app/redux/fetch-user-saga.js +++ b/common/app/redux/fetch-user-saga.js @@ -1,5 +1,5 @@ -import { Observable } from 'rx'; -import { handleError, setUser, fetchUser } from './types'; +import { setUser, fetchUser } from './types'; +import { createErrorObservable } from './actions'; export default function getUserSaga(action$, getState, { services }) { return action$ @@ -12,9 +12,6 @@ export default function getUserSaga(action$, getState, { services }) { payload: user }; }) - .catch(error => Observable.just({ - type: handleError, - error - })); + .catch(createErrorObservable); }); } diff --git a/common/app/routes/Hikes/redux/answer-saga.js b/common/app/routes/Hikes/redux/answer-saga.js index be179f5e2c..b80ccf67fe 100644 --- a/common/app/routes/Hikes/redux/answer-saga.js +++ b/common/app/routes/Hikes/redux/answer-saga.js @@ -4,7 +4,11 @@ import { push } from 'react-router-redux'; import types from './types'; import { getMouse } from './utils'; -import { makeToast, updatePoints } from '../../../redux/actions'; +import { + createErrorObservable, + makeToast, + updatePoints +} from '../../../redux/actions'; import { hikeCompleted, goToNextHike } from './actions'; import { postJSON$ } from '../../../../utils/ajax-stream'; import { getCurrentHike } from './selectors'; @@ -91,12 +95,7 @@ function handleAnswer(action, getState) { updatePoints(points), ); }) - .catch(error => { - return Observable.just({ - type: 'app.error', - error - }); - }); + .catch(createErrorObservable); } else { updateUser$ = Observable.empty(); } @@ -113,10 +112,7 @@ function handleAnswer(action, getState) { return Observable.merge(challengeCompleted$, updateUser$) .delay(300) .startWith(hikeCompleted(finalAnswer)) - .catch(error => Observable.just({ - type: 'error', - error - })) + .catch(createErrorObservable) // end with action so we know it is ok to transition .concat(Observable.just({ type: types.transitionHike })); } diff --git a/common/app/routes/Hikes/redux/fetch-hikes-saga.js b/common/app/routes/Hikes/redux/fetch-hikes-saga.js index f60f440b33..748f8c2961 100644 --- a/common/app/routes/Hikes/redux/fetch-hikes-saga.js +++ b/common/app/routes/Hikes/redux/fetch-hikes-saga.js @@ -1,10 +1,8 @@ -import { Observable } from 'rx'; import { normalize, Schema, arrayOf } from 'normalizr'; -// import debug from 'debug'; import types from './types'; import { fetchHikesCompleted } from './actions'; -import { handleError } from '../../../redux/types'; +import { createErrorObserable } from '../../../redux/actions'; import { findCurrentHike } from './utils'; @@ -25,11 +23,6 @@ export default function fetchHikesSaga(action$, getState, { services }) { const currentHike = findCurrentHike(result.hikes, dashedName); return fetchHikesCompleted(entities, result.hikes, currentHike); }) - .catch(error => { - return Observable.just({ - type: handleError, - error - }); - }); + .catch(createErrorObserable); }); } diff --git a/gulpfile.js b/gulpfile.js index 3ec3598856..a4eb1c69c8 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -37,7 +37,6 @@ var Rx = require('rx'), // rev rev = require('gulp-rev'), - revReplace = require('gulp-rev-replace'), revDel = require('rev-del'), // lint @@ -112,33 +111,10 @@ var paths = { js: [ 'client/main.js', - 'client/iFrameScripts.js', 'client/frame-runner.js', 'client/plugin.js' ], - commonFramework: [ - 'init', - 'bindings', - 'add-test-to-string', - 'code-storage', - 'code-uri', - 'add-loop-protect', - 'get-iframe', - 'update-preview', - 'create-editor', - 'detect-unsafe-code-stream', - 'display-test-results', - 'execute-challenge-stream', - 'output-display', - 'phone-scroll-lock', - 'report-issue', - 'run-tests-stream', - 'show-completion', - 'step-challenge', - 'end' - ], - less: './client/less/main.less', lessFiles: './client/less/**/*.less', @@ -162,12 +138,6 @@ var webpackOptions = { devtool: 'inline-source-map' }; -function formatCommonFrameworkPaths() { - return this.map(function(script) { - return 'client/commonFramework/' + script + '.js'; - }); -} - function errorHandler() { var args = Array.prototype.slice.call(arguments); @@ -431,38 +401,6 @@ gulp.task('js', function() { .pipe(__DEV__ ? gutil.noop() : gulp.dest(paths.manifest)); }); -// commonFramework depend on iFrameScripts -// and faux.js -gulp.task('dependents', ['js'], function() { - var manifestName = 'dependents-manifest.json'; - var dest = paths.publicJs; - - var manifest = gulp.src( - path.join(__dirname, paths.manifest, 'js-manifest.json') - ); - - return gulp.src(formatCommonFrameworkPaths.call(paths.commonFramework)) - .pipe(plumber({ errorHandler: errorHandler })) - .pipe(babel()) - .pipe(__DEV__ ? sourcemaps.init() : gutil.noop()) - .pipe(concat('commonFramework.js')) - .pipe( - __DEV__ ? - sourcemaps.write({ sourceRoot: '/commonFramework' }) : - gutil.noop() - ) - .pipe(__DEV__ ? gutil.noop() : uglify()) - .pipe(__DEV__ ? gutil.noop() : revReplace({ manifest: manifest })) - .pipe(gulp.dest(dest)) - .pipe(__DEV__ ? gutil.noop() : rev()) - .pipe(__DEV__ ? gutil.noop() : gulp.dest(dest)) - .pipe(__DEV__ ? gutil.noop() : rev.manifest(manifestName)) - .pipe(__DEV__ ? gutil.noop() : delRev( - dest, - manifestName - )) - .pipe(__DEV__ ? gutil.noop() : gulp.dest(paths.manifest)); -}); function collector(file, memo) { return Object.assign({}, JSON.parse(file.contents), memo); @@ -475,7 +413,6 @@ function done(manifest) { var buildDependents = [ 'less', 'js', - 'dependents', 'pack-client', 'move-webpack-manifest' ]; @@ -489,7 +426,6 @@ gulp.task('build-manifest', buildDependents, function() { gulp.task('build', [ 'less', 'js', - 'dependents', 'pack-client', 'move-webpack-manifest', 'clean-webpack-manifest', @@ -499,7 +435,6 @@ gulp.task('build', [ var watchDependents = [ 'less', 'js', - 'dependents', 'serve', 'sync' ]; @@ -513,11 +448,7 @@ gulp.task('watch', watchDependents, function() { gulp.watch(paths.lessFiles, ['less']); gulp.watch(paths.js.concat(paths.vendorChallenges), ['js']); gulp.watch(paths.challenges, ['test-challenges', 'reload']); - gulp.watch(paths.js, ['js', 'dependents']); - gulp.watch( - formatCommonFrameworkPaths.call(paths.commonFramework), - ['dependents'] - ); + gulp.watch(paths.js, ['js']); }); gulp.task('default', [ diff --git a/package.json b/package.json index 0164ba5433..6b28695da3 100644 --- a/package.json +++ b/package.json @@ -138,7 +138,6 @@ "gulp-plumber": "^1.0.1", "gulp-reduce-file": "0.0.1", "gulp-rev": "^7.0.0", - "gulp-rev-replace": "~0.4.2", "gulp-sourcemaps": "^1.6.0", "gulp-tape": "0.0.9", "gulp-uglify": "^1.5.1", diff --git a/server/server.js b/server/server.js index 99d5cf3db5..33ea75461a 100755 --- a/server/server.js +++ b/server/server.js @@ -16,7 +16,7 @@ if (!requireProto.hasOwnProperty('ensure')) { Object.defineProperties( requireProto, { - 'ensure': { + ensure: { value: function ensure(modules, callback) { callback(this); },