File tree Expand file tree Collapse file tree 1 file changed +23
-8
lines changed Expand file tree Collapse file tree 1 file changed +23
-8
lines changed Original file line number Diff line number Diff line change @@ -20,16 +20,31 @@ function* walk(json) {
20
20
const KEY = "npm_package" ;
21
21
22
22
module . exports = {
23
- name : ` plugin-env` ,
24
- factory : ( require ) => ( {
23
+ name : " plugin-envs" ,
24
+ factory : ( ) => ( {
25
25
hooks : {
26
26
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 ) ;
33
48
34
49
// Unwanted fields
35
50
delete json . author ;
You can’t perform that action at this time.
0 commit comments