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
5 changes: 5 additions & 0 deletions .changeset/fetch-latest-pds-version.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-pds": patch
---

Fetch latest @ascorbic/pds version from npm registry when creating a new project
21 changes: 21 additions & 0 deletions packages/create-pds/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@ async function replaceInFile(
await writeFile(filePath, content);
}

async function getLatestPdsVersion(): Promise<string> {
try {
const response = await fetch(
"https://registry.npmjs.org/@ascorbic/pds/latest",
);
if (!response.ok) {
throw new Error(`Failed to fetch: ${response.status}`);
}
const data = (await response.json()) as { version: string };
return `^${data.version}`;
} catch {
// Fallback to a known version if fetch fails
return "^0.2.0";
}
}

const main = defineCommand({
meta: {
name: "create-pds",
Expand Down Expand Up @@ -225,6 +241,10 @@ const main = defineCommand({

// Copy template
const spinner = p.spinner();
spinner.start("Fetching latest @ascorbic/pds version...");
const pdsVersion = await getLatestPdsVersion();
spinner.stop(`Using @ascorbic/pds ${pdsVersion}`);

spinner.start("Copying template...");

const templateDir = join(__dirname, "..", "templates", "pds-worker");
Expand All @@ -233,6 +253,7 @@ const main = defineCommand({
// Replace placeholders in package.json
await replaceInFile(join(targetDir, "package.json"), {
name: projectName,
pdsVersion,
});

spinner.stop("Template copied");
Expand Down
2 changes: 1 addition & 1 deletion packages/create-pds/templates/pds-worker/package.json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "module",
"private": true,
"dependencies": {
"@ascorbic/pds": "^0.0.0"
"@ascorbic/pds": "{{pdsVersion}}"
},
"devDependencies": {
"@cloudflare/vite-plugin": "^1.17.0",
Expand Down