Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
at main 2.2 kB view raw
1import { readFileSync } from 'fs'; 2import path from 'path'; 3 4export const cwd = process.cwd(); 5export const pkg = JSON.parse( 6 readFileSync(path.resolve(cwd, './package.json'), 'utf-8') 7); 8export const types = path.resolve(cwd, 'dist/types/'); 9 10const normalize = name => 11 name 12 .replace(/[@\s\/\.]+/g, ' ') 13 .trim() 14 .replace(/\s+/, '-') 15 .toLowerCase(); 16 17export const name = normalize(pkg.name); 18 19export const sources = pkg.exports 20 ? Object.keys(pkg.exports) 21 .map(entry => { 22 if (entry === './package.json') return undefined; 23 const exports = pkg.exports[entry]; 24 const dir = normalize(entry); 25 return { 26 name: dir ? `${name}-${dir}` : name, 27 dir: dir || '.', 28 main: exports.require, 29 module: exports.import, 30 types: exports.types, 31 source: exports.source, 32 }; 33 }) 34 .filter(Boolean) 35 : [ 36 { 37 name, 38 source: pkg.source || './src/index.ts', 39 }, 40 ]; 41 42export const externalModules = ['dns', 'fs', 'path', 'url']; 43if (pkg.peerDependencies) 44 externalModules.push(...Object.keys(pkg.peerDependencies)); 45if (pkg.devDependencies) 46 externalModules.push(...Object.keys(pkg.devDependencies)); 47if (pkg.dependencies) externalModules.push(...Object.keys(pkg.dependencies)); 48if (pkg.optionalDependencies) 49 externalModules.push(...Object.keys(pkg.optionalDependencies)); 50 51const prodDependencies = new Set([ 52 ...Object.keys(pkg.peerDependencies || {}), 53 ...Object.keys(pkg.dependencies || {}), 54]); 55 56const externalPredicate = new RegExp(`^(${externalModules.join('|')})($|/)`); 57 58export const isExternal = id => { 59 if (id === 'babel-plugin-transform-async-to-promises/helpers') return false; 60 return externalPredicate.test(id); 61}; 62 63export const hasNext = prodDependencies.has('next'); 64export const hasReact = prodDependencies.has('react'); 65export const hasPreact = prodDependencies.has('preact'); 66export const hasSvelte = prodDependencies.has('svelte'); 67export const hasVue = prodDependencies.has('vue'); 68export const mayReexport = hasReact || hasPreact || hasSvelte || hasVue; 69export const isAnalyze = !!process.env.ANALYZE;