packages/cli: mimic upcoming publishConfig behavior in prepack

This commit is contained in:
Patrik Oldsberg
2020-06-03 15:27:08 +02:00
parent c5425c5664
commit 8269b81a67
3 changed files with 18 additions and 12 deletions
+9 -6
View File
@@ -17,18 +17,21 @@
import fs from 'fs-extra';
import { paths } from '../lib/paths';
const SKIPPED_KEYS = ['access', 'registry', 'tag'];
export const pre = async () => {
const pkgPath = paths.resolveTarget('package.json');
const pkg = await fs.readJson(pkgPath);
pkg.types = 'dist/index.d.ts';
for (const key of Object.keys(pkg.publishConfig ?? {})) {
if (!SKIPPED_KEYS.includes(key)) {
pkg[key] = pkg.publishConfig[key];
}
}
await fs.writeJson(pkgPath, pkg, { encoding: 'utf8', spaces: 2 });
};
export const post = async () => {
const pkgPath = paths.resolveTarget('package.json');
const pkg = await fs.readJson(pkgPath);
pkg.types = 'src/index.ts';
await fs.writeJson(pkgPath, pkg, { encoding: 'utf8', spaces: 2 });
// postpack is a noop for now, since it's not called anyway
};
+4
View File
@@ -130,6 +130,10 @@ class PackageJsonHandler {
// Publish config can be removed the the target, skip in that case
if (!targetPublishConf) {
if (await this.prompt('Missing publishConfig, do you want to add it?')) {
this.targetPkg.publishConfig = pkgPublishConf;
await this.write();
}
return;
}
+5 -6
View File
@@ -175,7 +175,7 @@ export async function installWithLocalDeps(dir: string) {
// types to dist/index.d.ts and the main:src field is removed.
// Without this we get type checking errors in the e2e test
if (process.env.BACKSTAGE_E2E_CLI_TEST) {
Task.section('Patchling local dependencies for e2e tests');
Task.section('Patching local dependencies for e2e tests');
for (const name of PATCH_PACKAGES) {
await Task.forItem(
@@ -192,11 +192,10 @@ export async function installWithLocalDeps(dir: string) {
// We want dist to be used for e2e tests
delete depJson['main:src'];
depJson.types = 'dist/index.d.ts';
// Ugly hack until backend packages can point straight to source
if (name === 'config' || name === 'config-loader') {
depJson.main = 'dist/index.cjs.js';
for (const key of Object.keys(depJson.publishConfig)) {
if (key !== 'access') {
depJson[key] = depJson.publishConfig[key];
}
}
await fs