https://github.com/grafana/grafana
Raw File
Tip revision: 94e257a83fc62004800145a947dbdc03dfdcf6ee authored by Esteban Beltran on 01 December 2022, 10:34:52 UTC
Build: Adds a fallback script to fix package.json main and types fields before packaging (#59628)
Tip revision: 94e257a
prepare-packagejson.js
const fs = require('fs');

const cwd = process.cwd();
const packageJson = require(`${cwd}/package.json`);

const newPackageJson = {
  ...packageJson,
  main: packageJson.publishConfig?.main ?? packageJson.main,
};

if (packageJson.publishConfig?.types) {
  newPackageJson.types = packageJson.publishConfig.types;
}

if (packageJson.publishConfig?.module) {
  newPackageJson.module = packageJson.publishConfig.module;
}

try {
  fs.writeFileSync(`${cwd}/package.json`, JSON.stringify(newPackageJson, null, 2));
} catch (e) {}
back to top