Skip to content

Commit 0349e93

Browse files
committed
feat(create): use degit to download vite:library template from GitHub
Replace `create-tsdown@latest` with degit-based template download from `sxzz/tsdown-templates/vite-plus` for the vite:library template. This avoids npm registry dependency and GitHub API rate limit issues. Closes #910
1 parent f9c5cfb commit 0349e93

3 files changed

Lines changed: 24 additions & 14 deletions

File tree

packages/cli/src/create/templates/builtin.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import path from 'node:path';
33

44
import type { WorkspaceInfo } from '../../types/index.js';
55
import type { ExecutionResult } from '../command.js';
6+
import { discoverTemplate } from '../discovery.js';
67
import { setPackageName } from '../utils.js';
78
import { executeGeneratorScaffold } from './generator.js';
89
import { runRemoteTemplateCommand } from './remote.js';
9-
import { BuiltinTemplate, type BuiltinTemplateInfo } from './types.js';
10+
import { BuiltinTemplate, type BuiltinTemplateInfo, LibraryTemplateRepo } from './types.js';
1011

1112
export async function executeBuiltinTemplate(
1213
workspaceInfo: WorkspaceInfo,
@@ -25,19 +26,26 @@ export async function executeBuiltinTemplate(
2526
if (!templateInfo.interactive) {
2627
templateInfo.args.push('--no-interactive');
2728
}
29+
templateInfo.args.unshift(templateInfo.targetDir);
2830
} else if (templateInfo.command === BuiltinTemplate.library) {
29-
templateInfo.command = 'create-tsdown@latest';
30-
// create-tsdown doesn't support non-interactive mode;
31-
// add default template when running silently to prevent hang on piped stdin
32-
if (!templateInfo.interactive || options?.silent) {
33-
if (!templateInfo.args.some((arg) => arg.startsWith('--template') || arg.startsWith('-t'))) {
34-
templateInfo.args.push('--template', 'default');
35-
}
36-
}
31+
// Use degit to download the template directly from GitHub
32+
const libraryTemplateInfo = discoverTemplate(
33+
LibraryTemplateRepo,
34+
[templateInfo.targetDir],
35+
workspaceInfo,
36+
);
37+
const result = await runRemoteTemplateCommand(
38+
workspaceInfo,
39+
workspaceInfo.rootDir,
40+
libraryTemplateInfo,
41+
false,
42+
options?.silent ?? false,
43+
);
44+
const fullPath = path.join(workspaceInfo.rootDir, templateInfo.targetDir);
45+
setPackageName(fullPath, templateInfo.packageName);
46+
return { ...result, projectDir: templateInfo.targetDir };
3747
}
3848

39-
templateInfo.args.unshift(templateInfo.targetDir);
40-
4149
// Handle remote/external templates with fspy monitoring
4250
const result = await runRemoteTemplateCommand(
4351
workspaceInfo,

packages/cli/src/create/templates/monorepo.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type { ExecutionResult } from '../command.js';
1313
import { discoverTemplate } from '../discovery.js';
1414
import { copyDir, formatDisplayTargetDir, setPackageName } from '../utils.js';
1515
import { runRemoteTemplateCommand } from './remote.js';
16-
import { type BuiltinTemplateInfo } from './types.js';
16+
import { type BuiltinTemplateInfo, LibraryTemplateRepo } from './types.js';
1717

1818
export const InitialMonorepoAppDir = 'apps/website';
1919

@@ -169,8 +169,8 @@ export async function executeMonorepoTemplate(
169169
}
170170
const libraryDir = 'packages/utils';
171171
const libraryTemplateInfo = discoverTemplate(
172-
'create-tsdown@latest',
173-
[libraryDir, '--template', 'default'],
172+
LibraryTemplateRepo,
173+
[libraryDir],
174174
workspaceInfo,
175175
);
176176
const libraryResult = await runRemoteTemplateCommand(

packages/cli/src/create/templates/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export const LibraryTemplateRepo = 'github:sxzz/tsdown-templates/vite-plus';
2+
13
export const BuiltinTemplate = {
24
generator: 'vite:generator',
35
monorepo: 'vite:monorepo',

0 commit comments

Comments
 (0)