这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/create-turbo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"dependencies": {
"commander": "^11.0.0",
"fs-extra": "^11.1.1",
"inquirer": "^8.0.0",
"inquirer": "^8.2.7",
"picocolors": "1.0.1",
"proxy-agent": "^6.5.0",
"semver": "^7.3.8",
Expand Down
4 changes: 2 additions & 2 deletions packages/turbo-codemod/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
"find-up": "4.1.0",
"fs-extra": "^10.0.0",
"gradient-string": "^2.0.0",
"inquirer": "^8.2.4",
"inquirer": "^8.2.7",
"inquirer-file-tree-selection-prompt": "^1.0.19",
"json5": "^2.2.3",
"is-git-clean": "^1.1.0",
"json5": "^2.2.3",
"ora": "4.1.1",
"picocolors": "1.0.1",
"semver": "^7.3.7",
Expand Down
6 changes: 3 additions & 3 deletions packages/turbo-gen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
"@turbo/workspaces": "workspace:*",
"commander": "^10.0.0",
"fs-extra": "^10.1.0",
"inquirer": "^8.2.4",
"inquirer": "^8.2.7",
"minimatch": "^9.0.0",
"node-plop": "^0.26.3",
"node-plop": "0.32.1",
"picocolors": "1.0.1",
"proxy-agent": "^6.5.0",
"ts-node": "^10.9.2",
Expand All @@ -47,8 +47,8 @@
"@types/inquirer": "^8.2.5",
"@types/node": "^18.17.2",
"@types/validate-npm-package-name": "^4.0.0",
"publint": "^0.3.12",
"jest": "^29.7.0",
"publint": "^0.3.12",
"ts-jest": "^29.2.5",
"tsup": "^6.7.0",
"typescript": "5.5.4"
Expand Down
10 changes: 8 additions & 2 deletions packages/turbo-gen/src/generators/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ export async function generate({
opts,
}: CustomGeneratorArguments) {
let isOnboarding = false;
let generators = getCustomGenerators({ project, configPath: opts.config });
let generators = await getCustomGenerators({
project,
configPath: opts.config,
});
if (!generators.length) {
logger.error(`No generators found.`);
logger.log();
Expand Down Expand Up @@ -40,7 +43,10 @@ export async function generate({
logger.log();

// fetch generators again, and continue to selection prompt
generators = getCustomGenerators({ project, configPath: opts.config });
generators = await getCustomGenerators({
project,
configPath: opts.config,
});

// something went wrong and we weren't able to find our new custom generator
if (!generators.length) {
Expand Down
64 changes: 36 additions & 28 deletions packages/turbo-gen/src/utils/plop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import path from "node:path";
import fs from "fs-extra";
import type { Project } from "@turbo/workspaces";
import type { NodePlopAPI, PlopGenerator } from "node-plop";
import nodePlop from "node-plop";
import { register } from "ts-node";
import { Separator } from "inquirer";
import { searchUp, getTurboConfigs, logger } from "@turbo/utils";
Expand All @@ -27,13 +26,13 @@ export type Generator = PlopGenerator & {
name: string;
};

export function getPlop({
export async function getPlop({
project,
configPath,
}: {
project: Project;
configPath?: string;
}): NodePlopAPI | undefined {
}): Promise<NodePlopAPI | undefined> {
// init ts-node for plop to support ts configs
register({
transpileOnly: true,
Expand All @@ -56,7 +55,8 @@ export function getPlop({
}

try {
plop = nodePlop(configPath, {
const { default: nodePlop } = await import("node-plop");
plop = await nodePlop(configPath, {
destBasePath: configPath,
force: false,
});
Expand All @@ -65,26 +65,33 @@ export function getPlop({
}
} else {
// look for a root config
for (const possiblePath of SUPPORTED_ROOT_GENERATOR_CONFIGS) {
const plopFile = path.join(project.paths.root, possiblePath);
if (!fs.existsSync(plopFile)) {
continue;
}
const rootConfigPromises = SUPPORTED_ROOT_GENERATOR_CONFIGS.map(
async (possiblePath) => {
const plopFile = path.join(project.paths.root, possiblePath);
if (!fs.existsSync(plopFile)) {
return null;
}

try {
plop = nodePlop(plopFile, {
destBasePath: project.paths.root,
force: false,
});
break;
} catch (e) {
logger.error(e);
try {
const { default: nodePlop } = await import("node-plop");
return await nodePlop(plopFile, {
destBasePath: project.paths.root,
force: false,
});
} catch (e) {
logger.error(e);
return null;
}
}
}
);

const rootConfigs = await Promise.all(rootConfigPromises);
plop = rootConfigs.find((config) => config !== null) || undefined;

if (!plop && workspaceConfigs.length > 0) {
// if no root config, use the first workspace config as the entrypoint
plop = nodePlop(workspaceConfigs[0].config, {
const { default: nodePlop } = await import("node-plop");
plop = await nodePlop(workspaceConfigs[0].config, {
destBasePath: workspaceConfigs[0].root,
force: false,
});
Expand All @@ -94,29 +101,30 @@ export function getPlop({

if (plop) {
// add in all the workspace configs
workspaceConfigs.forEach((c) => {
const loadPromises = workspaceConfigs.map(async (c) => {
try {
plop.load(c.config, {
await plop.load(c.config, {
destBasePath: c.root,
force: false,
});
} catch (e) {
logger.error(e);
}
});
await Promise.all(loadPromises);
}

return plop;
}

export function getCustomGenerators({
export async function getCustomGenerators({
project,
configPath,
}: {
project: Project;
configPath?: string;
}): Array<Generator | Separator> {
const plop = getPlop({ project, configPath });
}): Promise<Array<Generator | Separator>> {
const plop = await getPlop({ project, configPath });

if (!plop) {
return [];
Expand Down Expand Up @@ -166,16 +174,16 @@ export function getCustomGenerators({
return gensWithSeparators;
}

export function getCustomGenerator({
export async function getCustomGenerator({
project,
generator,
configPath,
}: {
project: Project;
generator: string;
configPath?: string;
}): string | undefined {
const plop = getPlop({ project, configPath });
}): Promise<string | undefined> {
const plop = await getPlop({ project, configPath });
if (!plop) {
return undefined;
}
Expand Down Expand Up @@ -249,7 +257,7 @@ export async function runCustomGenerator({
bypassArgs?: Array<string>;
configPath?: string;
}): Promise<void> {
const plop = getPlop({ project, configPath });
const plop = await getPlop({ project, configPath });
if (!plop) {
throw new GeneratorError("Unable to load generators", {
type: "plop_unable_to_load_config",
Expand Down
3 changes: 2 additions & 1 deletion packages/turbo-gen/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "@turbo/tsconfig/library.json",
"exclude": ["src/templates", "dist", "node_modules"],
"compilerOptions": {
"rootDir": "."
"rootDir": ".",
"module": "ESNext"
}
}
2 changes: 1 addition & 1 deletion packages/turbo-workspaces/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"fast-glob": "^3.2.12",
"fs-extra": "^10.1.0",
"gradient-string": "^2.0.0",
"inquirer": "^8.0.0",
"inquirer": "^8.2.7",
"js-yaml": "^4.1.0",
"ora": "4.1.1",
"picocolors": "1.0.1",
Expand Down
Loading
Loading