react / wstein / node_modules / jest-cli / node_modules / node-haste / lib / loader / ProjectConfigurationLoader.js
80668 views/**1* Copyright 2013 Facebook, Inc.2*3* Licensed under the Apache License, Version 2.0 (the "License");4* you may not use this file except in compliance with the License.5* You may obtain a copy of the License at6*7* http://www.apache.org/licenses/LICENSE-2.08*9* Unless required by applicable law or agreed to in writing, software10* distributed under the License is distributed on an "AS IS" BASIS,11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12* See the License for the specific language governing permissions and13* limitations under the License.14*/1516var inherits = require('util').inherits;17var path = require('path');18var ProjectConfiguration = require('../resource/ProjectConfiguration');19var ResourceLoader = require('./ResourceLoader');2021/**22* @class Loads and parses package.json files23*24* @extends {ResourceLoader}25*/26function ProjectConfigurationLoader() {27ResourceLoader.call(this);28}29inherits(ProjectConfigurationLoader, ResourceLoader);30ProjectConfigurationLoader.prototype.path = __filename;3132ProjectConfigurationLoader.prototype.isConfiguration = true;333435ProjectConfigurationLoader.prototype.getResourceTypes = function() {36return [ProjectConfiguration];37};3839ProjectConfigurationLoader.prototype.getExtensions = function() {40return ['.json'];41};424344/**45* Initialize a resource with the source code and configuration46* Loader can parse, gzip, minify the source code to build the resulting47* Resource value object48*49* @protected50* @param {String} path resource being built51* @param {ProjectConfiguration} configuration configuration for the path52* @param {String} sourceCode53* @param {Function} callback54*/55ProjectConfigurationLoader.prototype.loadFromSource =56function(path, configuration, sourceCode, messages, callback) {57var config = new ProjectConfiguration(path);58config.id = path;59try {60config.data = sourceCode !== '' ? JSON.parse(sourceCode) : {};61} catch (e) {62console.error("Error parsing `" + path + "`!");63throw e;64}65callback(messages, config);66};6768/**69* Only match package.json files70* @static71* @param {String} filePath72* @return {Boolean}73*/74ProjectConfigurationLoader.prototype.matchPath = function(filePath) {75return path.basename(filePath) === 'package.json';76};777879module.exports = ProjectConfigurationLoader;808182