{"version":3,"file":"package.d.ts","sourceRoot":"","sources":["../../src/package.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;;;;AAoBpC,wBAAwB","sourcesContent":["// get the package.json data for the cwd\n\nimport { readFileSync } from 'fs'\nimport { JSONResult, parse, stringify } from 'polite-json'\nimport fail from './fail.js'\nimport { Package } from './types.js'\n\nconst isPackage = (pkg: JSONResult): pkg is Package =>\n  !!pkg && typeof pkg === 'object' && !Array.isArray(pkg)\n\nconst readPkg = (): Package & { type: 'commonjs' | 'module' } => {\n  try {\n    const res = parse(readFileSync('package.json', 'utf8'))\n    if (isPackage(res)) {\n      return Object.assign(res, {\n        type: res.type === 'commonjs' ? 'commonjs' : 'module',\n      })\n    }\n    throw new Error('Invalid package.json contents: ' + stringify(res))\n  } catch (er) {\n    fail('failed to read package.json', er as Error)\n    process.exit(1)\n  }\n}\n\nexport default readPkg()\n"]}