Skip to content

Commit 31a935d

Browse files
authored
Merge pull request #2 from Ayc0/Ayc0/windows-workspace
Ayc0/windows workspace
2 parents 07ac6f2 + d8fad68 commit 31a935d

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

src/index.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,31 @@ function* walk(json) {
2020
const KEY = "npm_package";
2121

2222
module.exports = {
23-
name: `plugin-env`,
24-
factory: (require) => ({
23+
name: "plugin-envs",
24+
factory: () => ({
2525
hooks: {
2626
setupScriptEnvironment(project, processEnv) {
27-
const path = require("path");
28-
const fs = require("fs");
29-
const pathToPackageJSON = path.join(project.cwd, "package.json");
30-
const json = JSON.parse(
31-
fs.readFileSync(pathToPackageJSON, { encoding: "utf-8" })
32-
);
27+
const workspacesContainingCwd = project.workspaces
28+
.filter((w) => project.configuration.startingCwd.includes(w.cwd))
29+
// if we have nested workspaces, we need to sort based on which is included within which
30+
.sort((wa, wb) => {
31+
if (wa.cwd.includes(wb.cwd)) {
32+
return -1;
33+
}
34+
if (wb.cwd.includes(wa.cwd)) {
35+
return 1;
36+
}
37+
return 0;
38+
});
39+
40+
if (workspacesContainingCwd.length === 0) {
41+
return;
42+
}
43+
44+
// the one containing all the others is the workspace matching the current cwd
45+
const workspace = workspacesContainingCwd[0];
46+
47+
const json = Object.assign({}, workspace.manifest.raw);
3348

3449
// Unwanted fields
3550
delete json.author;

0 commit comments

Comments
 (0)