Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(wrangler): Drop worker prefix when creating KV namespaces #7759

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions .changeset/serious-teachers-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"wrangler": major
---

Remove worker name prefix from KV namespace create

BREAKING CHANGE: when running `wrangler kv namespace create <name>`, previously the name of the namespace was automatically prefixed with the worker title, or `worker-` when running outside the context of a worker.
After this change, KV namespaces will no longer get prefixed, and the name used is the name supplied, verbatim.
16 changes: 8 additions & 8 deletions packages/wrangler/src/__tests__/__snapshots__/kv.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`wrangler > kv namespace > create > wrangler.json > should create a namespace 1`] = `
"🌀 Creating namespace with title \\"worker-UnitTestNamespace\\"
"🌀 Creating namespace with title \\"UnitTestNamespace\\"
✨ Success!
Add the following to your configuration file in your kv_namespaces array:
{
Expand All @@ -15,7 +15,7 @@ Add the following to your configuration file in your kv_namespaces array:
`;

exports[`wrangler > kv namespace > create > wrangler.json > should create a namespace in an environment if configured to do so 1`] = `
"🌀 Creating namespace with title \\"worker-customEnv-UnitTestNamespace\\"
"🌀 Creating namespace with title \\"customEnv-UnitTestNamespace\\"
✨ Success!
Add the following to your configuration file in your kv_namespaces array under [env.customEnv]:
{
Expand All @@ -29,7 +29,7 @@ Add the following to your configuration file in your kv_namespaces array under [
`;

exports[`wrangler > kv namespace > create > wrangler.json > should create a namespace using configured worker name 1`] = `
"🌀 Creating namespace with title \\"other-worker-UnitTestNamespace\\"
"🌀 Creating namespace with title \\"UnitTestNamespace\\"
✨ Success!
Add the following to your configuration file in your kv_namespaces array:
{
Expand All @@ -43,7 +43,7 @@ Add the following to your configuration file in your kv_namespaces array:
`;

exports[`wrangler > kv namespace > create > wrangler.json > should create a preview namespace if configured to do so 1`] = `
"🌀 Creating namespace with title \\"worker-UnitTestNamespace_preview\\"
"🌀 Creating namespace with title \\"UnitTestNamespace_preview\\"
✨ Success!
Add the following to your configuration file in your kv_namespaces array:
{
Expand All @@ -57,7 +57,7 @@ Add the following to your configuration file in your kv_namespaces array:
`;

exports[`wrangler > kv namespace > create > wrangler.toml > should create a namespace 1`] = `
"🌀 Creating namespace with title \\"worker-UnitTestNamespace\\"
"🌀 Creating namespace with title \\"UnitTestNamespace\\"
✨ Success!
Add the following to your configuration file in your kv_namespaces array:
[[kv_namespaces]]
Expand All @@ -67,7 +67,7 @@ id = \\"some-namespace-id\\"
`;

exports[`wrangler > kv namespace > create > wrangler.toml > should create a namespace in an environment if configured to do so 1`] = `
"🌀 Creating namespace with title \\"worker-customEnv-UnitTestNamespace\\"
"🌀 Creating namespace with title \\"customEnv-UnitTestNamespace\\"
✨ Success!
Add the following to your configuration file in your kv_namespaces array under [env.customEnv]:
[[kv_namespaces]]
Expand All @@ -77,7 +77,7 @@ id = \\"some-namespace-id\\"
`;

exports[`wrangler > kv namespace > create > wrangler.toml > should create a namespace using configured worker name 1`] = `
"🌀 Creating namespace with title \\"other-worker-UnitTestNamespace\\"
"🌀 Creating namespace with title \\"UnitTestNamespace\\"
✨ Success!
Add the following to your configuration file in your kv_namespaces array:
[[kv_namespaces]]
Expand All @@ -87,7 +87,7 @@ id = \\"some-namespace-id\\"
`;

exports[`wrangler > kv namespace > create > wrangler.toml > should create a preview namespace if configured to do so 1`] = `
"🌀 Creating namespace with title \\"worker-UnitTestNamespace_preview\\"
"🌀 Creating namespace with title \\"UnitTestNamespace_preview\\"
✨ Success!
Add the following to your configuration file in your kv_namespaces array:
[[kv_namespaces]]
Expand Down
8 changes: 4 additions & 4 deletions packages/wrangler/src/__tests__/kv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,23 +189,23 @@ describe("wrangler", () => {
describe.each(["wrangler.json", "wrangler.toml"])("%s", (configPath) => {
it("should create a namespace", async () => {
writeWranglerConfig({ name: "worker" }, configPath);
mockCreateRequest("worker-UnitTestNamespace");
mockCreateRequest("UnitTestNamespace");
await runWrangler("kv namespace create UnitTestNamespace");
expect(std.out).toMatchSnapshot();
});

it("should create a preview namespace if configured to do so", async () => {
writeWranglerConfig({ name: "worker" }, configPath);

mockCreateRequest("worker-UnitTestNamespace_preview");
mockCreateRequest("UnitTestNamespace_preview");
await runWrangler("kv namespace create UnitTestNamespace --preview");
expect(std.out).toMatchSnapshot();
});

it("should create a namespace using configured worker name", async () => {
writeWranglerConfig({ name: "other-worker" }, configPath);

mockCreateRequest("other-worker-UnitTestNamespace");
mockCreateRequest("UnitTestNamespace");
await runWrangler("kv namespace create UnitTestNamespace");
expect(std.out).toMatchSnapshot();
});
Expand All @@ -223,7 +223,7 @@ describe("wrangler", () => {
configPath
);

mockCreateRequest("worker-customEnv-UnitTestNamespace");
mockCreateRequest("customEnv-UnitTestNamespace");
await runWrangler(
"kv namespace create UnitTestNamespace --env customEnv"
);
Expand Down
11 changes: 2 additions & 9 deletions packages/wrangler/src/kv/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,9 @@ defineCommand({

async handler(args) {
const config = readConfig(args.config, args);
if (!config.name) {
logger.warn(
"No configured name present, using `worker` as a prefix for the title"
);
}

const name = config.name || "worker";
const environment = args.env ? `-${args.env}` : "";
const environment = args.env ? `${args.env}-` : "";
const preview = args.preview ? "_preview" : "";
const title = `${name}${environment}-${args.namespace}${preview}`;
const title = `${environment}${args.namespace}${preview}`;

const accountId = await requireAuth(config);

Expand Down
Loading