Skip to content
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

CP-1062 eslint, karma-jspm #101

Merged
merged 15 commits into from
May 17, 2016
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"rules": {
"indent": [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make this the default 4 space indent (more consistent with other OSS JS repos from our org)?

2,
4
],
"quotes": [
2,
"single"
],
"linebreak-style": [
2,
"unix"
],
"semi": [
2,
"always"
]
},
"env": {
"node": true
},
"extends": "eslint:recommended"
}
19 changes: 11 additions & 8 deletions src/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
* limitations under the License.
*/

/*global window*/

(function(karma, System) {
if (!System) {
throw new Error("SystemJS was not found. Please make sure you have " +
"initialized jspm via installing a dependency with jspm, " +
"or by running 'jspm dl-loader'.");
throw new Error('SystemJS was not found. Please make sure you have ' +
'initialized jspm via installing a dependency with jspm, ' +
'or by running \'jspm dl-loader\'.');
}

System.config({ baseURL: 'base' });
Expand All @@ -30,6 +32,7 @@

if(karma.config.jspm.paths !== undefined &&
typeof karma.config.jspm.paths === 'object') {

System.config({
paths: karma.config.jspm.paths
});
Expand All @@ -39,14 +42,14 @@
if(!karma.config.jspm.useBundles){
System.bundles = [];
}

// Load everything specified in loadFiles
for (var i = 0; i < karma.config.jspm.expandedFiles.length; i++) {
var modulePath = karma.config.jspm.expandedFiles[i];
var promise = System['import'](extractModuleName(modulePath))
['catch'](function(e) {
throw e;
});
['catch'](function(e) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this chunk still looks like 2 space indents

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me fix that

throw e;
});
promises.push(promise);
}

Expand All @@ -57,6 +60,6 @@
};

function extractModuleName(fileName) {
return fileName.replace(/\.js$/, "");
return fileName.replace(/\.js$/, '');
}
})(window.__karma__, window.System);
150 changes: 75 additions & 75 deletions src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,103 +14,103 @@
* limitations under the License.
*/

var glob = require("glob");
var path = require("path");
var fs = require("fs");
var glob = require('glob');
var path = require('path');
var fs = require('fs');


function flatten(structure) {
return [].concat.apply([], structure);
return [].concat.apply([], structure);
}

function expandGlob(file, cwd) {
return glob.sync(file.pattern || file, {cwd: cwd});
};
return glob.sync(file.pattern || file, {cwd: cwd});
}

var createPattern = function(path) {
return {pattern: path, included: true, served: true, watched: false};
return {pattern: path, included: true, served: true, watched: false};
};

var createServedPattern = function(path){
return {pattern: path, included: false, served: true, watched: true};
return {pattern: path, included: false, served: true, watched: true};
};

function getJspmPackageJson(dir) {
var pjson = {};
try {
pjson = JSON.parse(fs.readFileSync(path.resolve(dir, 'package.json')));
}
catch(e) {
pjson = {};
}
if (pjson.jspm) {
for (var p in pjson.jspm)
pjson[p] = pjson.jspm[p];
}
pjson.directories = pjson.directories || {};
if (pjson.directories.baseURL) {
if (!pjson.directories.packages)
pjson.directories.packages = path.join(pjson.directories.baseURL, 'jspm_packages');
if (!pjson.configFile)
pjson.configFile = path.join(pjson.directories.baseURL, 'config.js');
}
return pjson;
var pjson = {};
try {
pjson = JSON.parse(fs.readFileSync(path.resolve(dir, 'package.json')));
}
catch(e) {
pjson = {};
}
if (pjson.jspm) {
for (var p in pjson.jspm)
pjson[p] = pjson.jspm[p];
}
pjson.directories = pjson.directories || {};
if (pjson.directories.baseURL) {
if (!pjson.directories.packages)
pjson.directories.packages = path.join(pjson.directories.baseURL, 'jspm_packages');
if (!pjson.configFile)
pjson.configFile = path.join(pjson.directories.baseURL, 'config.js');
}
return pjson;
}

module.exports = function(files, basePath, jspm, client) {
// Initialize jspm config if it wasn't specified in karma.conf.js
if(!jspm)
jspm = {};
if(!jspm.config)
jspm.config = getJspmPackageJson(basePath).configFile || "config.js";
if(!jspm.loadFiles)
jspm.loadFiles = [];
if(!jspm.serveFiles)
jspm.serveFiles = [];
if(!jspm.packages)
jspm.packages = getJspmPackageJson(basePath).directories.packages || "jspm_packages/";
if(!client.jspm)
client.jspm = {};
if(jspm.paths !== undefined && typeof jspm.paths === 'object')
client.jspm.paths = jspm.paths;
// Initialize jspm config if it wasn't specified in karma.conf.js
if(!jspm)
jspm = {};
if(!jspm.config)
jspm.config = getJspmPackageJson(basePath).configFile || 'config.js';
if(!jspm.loadFiles)
jspm.loadFiles = [];
if(!jspm.serveFiles)
jspm.serveFiles = [];
if(!jspm.packages)
jspm.packages = getJspmPackageJson(basePath).directories.packages || 'jspm_packages/';
if(!client.jspm)
client.jspm = {};
if(jspm.paths !== undefined && typeof jspm.paths === 'object')
client.jspm.paths = jspm.paths;

// Pass on useBundles option to client
client.jspm.useBundles = jspm.useBundles;
// Pass on useBundles option to client
client.jspm.useBundles = jspm.useBundles;

var packagesPath = path.normalize(basePath + '/' + jspm.packages + '/');
var configPath = path.normalize(basePath + '/' + jspm.config);
var packagesPath = path.normalize(basePath + '/' + jspm.packages + '/');
var configPath = path.normalize(basePath + '/' + jspm.config);

// Allow Karma to serve all files within jspm_packages.
// This allows jspm/SystemJS to load them
var jspmPattern = createServedPattern(packagesPath + '**/*');
jspmPattern.watched = false;
files.unshift(jspmPattern);
// Allow Karma to serve all files within jspm_packages.
// This allows jspm/SystemJS to load them
var jspmPattern = createServedPattern(packagesPath + '**/*');
jspmPattern.watched = false;
files.unshift(jspmPattern);

// Add SystemJS loader and jspm config
function getLoaderPath(fileName){
var exists = glob.sync(packagesPath + fileName + '@*.js');
if(exists && exists.length != 0){
return packagesPath + fileName + '@*.js';
} else {
return packagesPath + fileName + '.js';
// Add SystemJS loader and jspm config
function getLoaderPath(fileName){
var exists = glob.sync(packagesPath + fileName + '@*.js');
if(exists && exists.length != 0){
return packagesPath + fileName + '@*.js';
} else {
return packagesPath + fileName + '.js';
}
}
}
files.unshift(createPattern(configPath));
files.unshift(createPattern(__dirname + '/adapter.js'));
files.unshift(createPattern(getLoaderPath('system-polyfills.src')));
files.unshift(createPattern(getLoaderPath('system.src')));
files.unshift(createPattern(configPath));
files.unshift(createPattern(__dirname + '/adapter.js'));
files.unshift(createPattern(getLoaderPath('system-polyfills.src')));
files.unshift(createPattern(getLoaderPath('system.src')));

// Loop through all of jspm.load_files and do two things
// 1. Add all the files as "served" files to the files array
// 2. Expand out and globs to end up with actual files for jspm to load.
// Store that in client.jspm.expandedFiles
client.jspm.expandedFiles = flatten(jspm.loadFiles.map(function(file){
files.push(createServedPattern(basePath + "/" + (file.pattern || file)));
return expandGlob(file, basePath);
}));
// Loop through all of jspm.load_files and do two things
// 1. Add all the files as 'served' files to the files array
// 2. Expand out and globs to end up with actual files for jspm to load.
// Store that in client.jspm.expandedFiles
client.jspm.expandedFiles = flatten(jspm.loadFiles.map(function(file){
files.push(createServedPattern(basePath + '/' + (file.pattern || file)));
return expandGlob(file, basePath);
}));

// Add served files to files array
jspm.serveFiles.map(function(file){
files.push(createServedPattern(basePath + "/" + (file.pattern || file)));
});
// Add served files to files array
jspm.serveFiles.map(function(file){
files.push(createServedPattern(basePath + '/' + (file.pattern || file)));
});
};