external: function (id) { if (isBuiltin(id)) { return true; } id = id.split('/').slice(0, id[0] === '@' ? 2 : 1).join('/'); return !!require('./package.json').dependencies[id]; }
function cleanDependencies(info, isRoot, reporter, warn) { // get dependency objects const depTypes = []; for (const type of dependencyKeys) { const deps = info[type]; if (!deps || typeof deps !== 'object') { continue; } depTypes.push([type, deps]); } // check root dependencies for builtin module names if (isRoot) { for (const _ref of depTypes) { var _ref2 = (0, (_slicedToArray2 || _load_slicedToArray()).default)(_ref, 2); const type = _ref2[0]; const deps = _ref2[1]; for (const name in deps) { if (isBuiltinModule(name)) { warn(reporter.lang('manifestDependencyBuiltin', name, type)); } } } } // ensure that dependencies don't have ones that can collide for (const _ref3 of depTypes) { var _ref4 = (0, (_slicedToArray2 || _load_slicedToArray()).default)(_ref3, 2); const type = _ref4[0]; const deps = _ref4[1]; for (const name in deps) { const version = deps[name]; // check collisions for (const _ref5 of depTypes) { var _ref6 = (0, (_slicedToArray2 || _load_slicedToArray()).default)(_ref5, 2); const type2 = _ref6[0]; const deps2 = _ref6[1]; const version2 = deps2[name]; if (deps === deps2 || !version2 || version2 === '*') { continue; } if (version !== version2 && isRoot) { // only throw a warning when at the root warn(reporter.lang('manifestDependencyCollision', type, name, version, type2, version2)); } delete deps2[name]; } } } }
exports.default = function (info, isRoot, reporter, warn) { if (isRoot) { for (const key in (_typos || _load_typos()).default) { if (key in info) { warn(reporter.lang('manifestPotentialType', key, (_typos || _load_typos()).default[key])); } } } // validate name const name = info.name; if (typeof name === 'string') { if (isRoot && isBuiltinModule(name)) { warn(reporter.lang('manifestBuiltinModule', name)); } // cannot start with a dot if (name[0] === '.') { throw new (_errors || _load_errors()).MessageError(reporter.lang('manifestNameDot')); } // cannot contain the following characters if (!isValidPackageName(name)) { throw new (_errors || _load_errors()).MessageError(reporter.lang('manifestNameIllegalChars')); } // cannot equal node_modules or favicon.ico const lower = name.toLowerCase(); if (lower === 'node_modules' || lower === 'favicon.ico') { throw new (_errors || _load_errors()).MessageError(reporter.lang('manifestNameBlacklisted')); } } // validate license if (isRoot && !info.private) { if (typeof info.license === 'string') { const license = info.license.replace(/\*$/g, ''); if (!(0, (_util || _load_util()).isValidLicense)(license)) { warn(reporter.lang('manifestLicenseInvalid')); } } else { warn(reporter.lang('manifestLicenseNone')); } } // validate strings for (const key of strings) { const val = info[key]; if (val && typeof val !== 'string') { throw new (_errors || _load_errors()).MessageError(reporter.lang('manifestStringExpected', key)); } } cleanDependencies(info, isRoot, reporter, warn); };
resolveId: (id, importer) => { if ( /^[\/\.]/.test(id) || isBuiltin(id) || /node_modules/.test(importer) ) { return null; } t.ok(styleSpecPackage.dependencies[id], `External dependency ${id} (imported from ${importer}) declared in style-spec's package.json`); return false; }
, fixNameField: function(data, options) { if (typeof options === "boolean") options = {strict: options} else if (typeof options === "undefined") options = {} var strict = options.strict if (!data.name && !strict) { data.name = "" return } if (typeof data.name !== "string") { throw new Error("name field must be a string.") } if (!strict) data.name = data.name.trim() ensureValidName(data.name, strict, options.allowLegacyCase) if (isBuiltinModule(data.name)) this.warn("conflictingName", data.name) }
modules = modules.filter((module) => { return !isBuiltInModule(module); });
return new Promise((resolve, reject) => { // It's a builtin module, loopup polyfill if (isBuiltinModule(depName) || (depName in builtin)) { if (depName in builtin) { const realPolyfillPath = require.resolve(builtin[depName]); const polyfillId = path.relative(__dirname, realPolyfillPath); depMap[oriDepName] = polyfillId; const xxx = path.relative(panto.file.locate('.'), realPolyfillPath); return panto.file.read(xxx).then(content => { if (/\.json$/i.test(xxx)) { content = 'module.exports=' + content; } return resolveDependencies({ filename: polyfillId, content, basedir: __dirname }, fileMap, contentCache, options); }).then(resolve, reject); } else { depMap[oriDepName] = depName; fileMap.push({ id: depName, source: '', deps: {} }); return resolve(); } } let realName = path.join(path.dirname(filename), depName); // Find in memory cache first if (contentCache.has(realName)) { depMap[oriDepName] = realName; return resolveDependencies({ filename: realName, content: contentCache.get(realName), basedir: BASE_DIR }, fileMap, contentCache, options).then(resolve, reject); } // Find in file system realName = nodeResolve.resolve(filename, depName, BASE_DIR, true); if (realName) { depMap[oriDepName] = realName; if (contentCache.has(realName)) { return resolveDependencies({ filename: realName, content: contentCache.get(realName), basedir: BASE_DIR }, fileMap, contentCache, options).then(resolve, reject); } else { const xxx = path.relative(panto.file.locate('.'), path.join(BASE_DIR, realName)); return panto.file.read(xxx).then(content => { if (/\.json$/i.test(xxx)) { content = 'module.exports=' + content; } return resolveDependencies({ filename: realName, content, basedir: BASE_DIR }, fileMap, contentCache, options); }).then(resolve, reject); } } else { // not found depMap[oriDepName] = depName; return resolve(); } });
isCoreModule(moduleName: string): boolean { return this._options.hasCoreModules && isBuiltinModule(moduleName); }