Skip to content

Commit

Permalink
Fix #1
Browse files Browse the repository at this point in the history
  • Loading branch information
Bnaya committed Mar 11, 2020
1 parent c4673af commit 9f4f4e1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
9 changes: 3 additions & 6 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {
WorkspaceInfo,
partitionNoneTs,
applyOnPackage,
execFile
execFile,
readWorkspaceInfoObject
} from "./helpers";
import pMap = require("p-map");
import debug = require("debug");
Expand All @@ -15,11 +16,7 @@ export async function injectRefs(
projectRoot: string,
options: { tsconfigPathInsidePackages: string; generateBuildAll: boolean }
) {
const workspaceInfoObject: WorkspaceInfo = JSON.parse(
JSON.parse(
await execFile("yarn", ["workspaces", "info", "--json"], projectRoot)
).data
);
const workspaceInfoObject = await readWorkspaceInfoObject(projectRoot);
const workspaceInfoEntries = Object.entries(workspaceInfoObject);

const [tsPackages, noneTsPackages] = await partitionNoneTs(
Expand Down
22 changes: 17 additions & 5 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,7 @@ export async function applyTransformationOnAllPackages(
packageInfo: PackageInfo
) => Promise<void>
) {
const workspaceInfoObject: WorkspaceInfo = JSON.parse(
JSON.parse(
await execFile("yarn", ["workspaces", "info", "--json"], projectRoot)
).data
);
const workspaceInfoObject = await readWorkspaceInfoObject(projectRoot);
const workspaceInfoEntries = Object.entries(workspaceInfoObject);

const [tsPackages, noneTsPackages] = await partitionNoneTs(
Expand Down Expand Up @@ -331,3 +327,19 @@ export async function applyTransformationOnAllPackages(
}
);
}

export async function readWorkspaceInfoObject(
projectRoot: string
): Promise<WorkspaceInfo> {
const r = await execFile(
"yarn",
["-s", "workspaces", "info", "--json"],
projectRoot
);

try {
return JSON.parse(JSON.parse(r).data);
} catch (e) {
return JSON.parse(r);
}
}

0 comments on commit 9f4f4e1

Please sign in to comment.