@@ -2,6 +2,7 @@ import path from "node:path";
22import fs from "fs-extra" ;
33import type { Project } from "@turbo/workspaces" ;
44import type { NodePlopAPI , PlopGenerator } from "node-plop" ;
5+ import nodePlop from "node-plop" ;
56import { register } from "ts-node" ;
67import { Separator } from "inquirer" ;
78import { searchUp , getTurboConfigs , logger } from "@turbo/utils" ;
@@ -26,13 +27,13 @@ export type Generator = PlopGenerator & {
2627 name : string ;
2728} ;
2829
29- export async function getPlop ( {
30+ export function getPlop ( {
3031 project,
3132 configPath,
3233} : {
3334 project : Project ;
3435 configPath ?: string ;
35- } ) : Promise < NodePlopAPI | undefined > {
36+ } ) : NodePlopAPI | undefined {
3637 // init ts-node for plop to support ts configs
3738 register ( {
3839 transpileOnly : true ,
@@ -55,8 +56,7 @@ export async function getPlop({
5556 }
5657
5758 try {
58- const { default : nodePlop } = await import ( "node-plop" ) ;
59- plop = await nodePlop ( configPath , {
59+ plop = nodePlop ( configPath , {
6060 destBasePath : configPath ,
6161 force : false ,
6262 } ) ;
@@ -65,33 +65,26 @@ export async function getPlop({
6565 }
6666 } else {
6767 // look for a root config
68- const rootConfigPromises = SUPPORTED_ROOT_GENERATOR_CONFIGS . map (
69- async ( possiblePath ) => {
70- const plopFile = path . join ( project . paths . root , possiblePath ) ;
71- if ( ! fs . existsSync ( plopFile ) ) {
72- return null ;
73- }
74-
75- try {
76- const { default : nodePlop } = await import ( "node-plop" ) ;
77- return await nodePlop ( plopFile , {
78- destBasePath : project . paths . root ,
79- force : false ,
80- } ) ;
81- } catch ( e ) {
82- logger . error ( e ) ;
83- return null ;
84- }
68+ for ( const possiblePath of SUPPORTED_ROOT_GENERATOR_CONFIGS ) {
69+ const plopFile = path . join ( project . paths . root , possiblePath ) ;
70+ if ( ! fs . existsSync ( plopFile ) ) {
71+ continue ;
8572 }
86- ) ;
8773
88- const rootConfigs = await Promise . all ( rootConfigPromises ) ;
89- plop = rootConfigs . find ( ( config ) => config !== null ) || undefined ;
74+ try {
75+ plop = nodePlop ( plopFile , {
76+ destBasePath : project . paths . root ,
77+ force : false ,
78+ } ) ;
79+ break ;
80+ } catch ( e ) {
81+ logger . error ( e ) ;
82+ }
83+ }
9084
9185 if ( ! plop && workspaceConfigs . length > 0 ) {
9286 // if no root config, use the first workspace config as the entrypoint
93- const { default : nodePlop } = await import ( "node-plop" ) ;
94- plop = await nodePlop ( workspaceConfigs [ 0 ] . config , {
87+ plop = nodePlop ( workspaceConfigs [ 0 ] . config , {
9588 destBasePath : workspaceConfigs [ 0 ] . root ,
9689 force : false ,
9790 } ) ;
@@ -101,30 +94,29 @@ export async function getPlop({
10194
10295 if ( plop ) {
10396 // add in all the workspace configs
104- const loadPromises = workspaceConfigs . map ( async ( c ) => {
97+ workspaceConfigs . forEach ( ( c ) => {
10598 try {
106- await plop . load ( c . config , {
99+ plop . load ( c . config , {
107100 destBasePath : c . root ,
108101 force : false ,
109102 } ) ;
110103 } catch ( e ) {
111104 logger . error ( e ) ;
112105 }
113106 } ) ;
114- await Promise . all ( loadPromises ) ;
115107 }
116108
117109 return plop ;
118110}
119111
120- export async function getCustomGenerators ( {
112+ export function getCustomGenerators ( {
121113 project,
122114 configPath,
123115} : {
124116 project : Project ;
125117 configPath ?: string ;
126- } ) : Promise < Array < Generator | Separator > > {
127- const plop = await getPlop ( { project, configPath } ) ;
118+ } ) : Array < Generator | Separator > {
119+ const plop = getPlop ( { project, configPath } ) ;
128120
129121 if ( ! plop ) {
130122 return [ ] ;
@@ -174,16 +166,16 @@ export async function getCustomGenerators({
174166 return gensWithSeparators ;
175167}
176168
177- export async function getCustomGenerator ( {
169+ export function getCustomGenerator ( {
178170 project,
179171 generator,
180172 configPath,
181173} : {
182174 project : Project ;
183175 generator : string ;
184176 configPath ?: string ;
185- } ) : Promise < string | undefined > {
186- const plop = await getPlop ( { project, configPath } ) ;
177+ } ) : string | undefined {
178+ const plop = getPlop ( { project, configPath } ) ;
187179 if ( ! plop ) {
188180 return undefined ;
189181 }
@@ -257,7 +249,7 @@ export async function runCustomGenerator({
257249 bypassArgs ?: Array < string > ;
258250 configPath ?: string ;
259251} ) : Promise < void > {
260- const plop = await getPlop ( { project, configPath } ) ;
252+ const plop = getPlop ( { project, configPath } ) ;
261253 if ( ! plop ) {
262254 throw new GeneratorError ( "Unable to load generators" , {
263255 type : "plop_unable_to_load_config" ,
0 commit comments