Skip to content

Commit

Permalink
error for deploy and secret
Browse files Browse the repository at this point in the history
  • Loading branch information
emily-shen committed Oct 16, 2024
1 parent 0c7b346 commit fc9abcf
Show file tree
Hide file tree
Showing 5 changed files with 1,026 additions and 40 deletions.
10 changes: 10 additions & 0 deletions packages/wrangler/src/__tests__/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,16 @@ describe("deploy", () => {
`);
});

it("should error helpfully if pages_build_output_dir is set in wrangler.toml", async () => {
writeWranglerToml({
pages_build_output_dir: "public",
name: "test-name",
});
await expect(
runWrangler("deploy")
).rejects.toThrowErrorMatchingInlineSnapshot(`[Error: This command is for Workers, for Pages please run \`wrangler pages deploy\`.]`);
});

describe("output additional script information", () => {
it("for first party workers, it should print worker information at log level", async () => {
setIsTTY(false);
Expand Down
64 changes: 64 additions & 0 deletions packages/wrangler/src/__tests__/secret.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,22 @@ describe("wrangler secret", () => {
);
}

it("should error helpfully if pages_build_output_dir is set", async () => {
fs.writeFileSync(
"wrangler.toml",
TOML.stringify({
pages_build_output_dir: "public",
name: "script-name",
}),
"utf-8"
);
await expect(
runWrangler("secret put secret-name")
).rejects.toThrowErrorMatchingInlineSnapshot(
`[Error: This command is for Workers, for Pages please run \`wrangler pages secret put\`.]`
);
});

describe("interactive", () => {
beforeEach(() => {
setIsTTY(true);
Expand Down Expand Up @@ -389,6 +405,22 @@ describe("wrangler secret", () => {
);
}

it("should error helpfully if pages_build_output_dir is set", async () => {
fs.writeFileSync(
"wrangler.toml",
TOML.stringify({
pages_build_output_dir: "public",
name: "script-name",
}),
"utf-8"
);
await expect(
runWrangler("secret delete secret-name")
).rejects.toThrowErrorMatchingInlineSnapshot(
`[Error: This command is for Workers, for Pages please run \`wrangler pages secret delete\`.]`
);
});

it("should delete a secret", async () => {
mockDeleteRequest({ scriptName: "script-name", secretName: "the-key" });
mockConfirm({
Expand Down Expand Up @@ -499,6 +531,22 @@ describe("wrangler secret", () => {
);
}

it("should error helpfully if pages_build_output_dir is set", async () => {
fs.writeFileSync(
"wrangler.toml",
TOML.stringify({
pages_build_output_dir: "public",
name: "script-name",
}),
"utf-8"
);
await expect(
runWrangler("secret list")
).rejects.toThrowErrorMatchingInlineSnapshot(
`[Error: This command is for Workers, for Pages please run \`wrangler pages secret list\`.]`
);
});

it("should list secrets", async () => {
mockListRequest({ scriptName: "script-name" });
await runWrangler("secret list --name script-name");
Expand Down Expand Up @@ -565,6 +613,22 @@ describe("wrangler secret", () => {
});

describe("bulk", () => {
it("should error helpfully if pages_build_output_dir is set", async () => {
fs.writeFileSync(
"wrangler.toml",
TOML.stringify({
pages_build_output_dir: "public",
name: "script-name",
}),
"utf-8"
);
await expect(
runWrangler("secret bulk")
).rejects.toThrowErrorMatchingInlineSnapshot(
`[Error: This command is for Workers, for Pages please run \`wrangler pages secret bulk\`.]`
);
});

it("should fail secret bulk w/ no pipe or JSON input", async () => {
vi.spyOn(readline, "createInterface").mockImplementation(
() => null as unknown as Interface
Expand Down
6 changes: 6 additions & 0 deletions packages/wrangler/src/deploy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,12 @@ export async function deployHandler(args: DeployArgs) {
args.config || (args.script && findWranglerToml(path.dirname(args.script)));
const projectRoot = configPath && path.dirname(configPath);
const config = readConfig(configPath, args);
if (config.pages_build_output_dir) {
throw new UserError(
"This command is for Workers, for Pages please run `wrangler pages deploy`."
);
}

const entry = await getEntry(args, config, "deploy");

if (args.public) {
Expand Down
20 changes: 20 additions & 0 deletions packages/wrangler/src/secret/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ export const secret = (secretYargs: CommonYargsArgv) => {
async (args) => {
await printWranglerBanner();
const config = readConfig(args.config, args);
if (config.pages_build_output_dir) {
throw new UserError(
"This command is for Workers, for Pages please run `wrangler pages secret put`."
);
}

const scriptName = getLegacyScriptName(args, config);
if (!scriptName) {
Expand Down Expand Up @@ -243,6 +248,11 @@ export const secret = (secretYargs: CommonYargsArgv) => {
},
async (args) => {
const config = readConfig(args.config, args);
if (config.pages_build_output_dir) {
throw new UserError(
"This command is for Workers, for Pages please run `wrangler pages secret delete`."
);
}

const scriptName = getLegacyScriptName(args, config);
if (!scriptName) {
Expand Down Expand Up @@ -299,6 +309,11 @@ export const secret = (secretYargs: CommonYargsArgv) => {
},
async (args) => {
const config = readConfig(args.config, args);
if (config.pages_build_output_dir) {
throw new UserError(
"This command is for Workers, for Pages please run `wrangler pages secret list`."
);
}

const scriptName = getLegacyScriptName(args, config);
if (!scriptName) {
Expand Down Expand Up @@ -360,6 +375,11 @@ type SecretBulkArgs = StrictYargsOptionsToInterface<typeof secretBulkOptions>;
export const secretBulkHandler = async (secretBulkArgs: SecretBulkArgs) => {
await printWranglerBanner();
const config = readConfig(secretBulkArgs.config, secretBulkArgs);
if (config.pages_build_output_dir) {
throw new UserError(
"This command is for Workers, for Pages please run `wrangler pages secret bulk`."
);
}

if (secretBulkArgs._.includes("secret:bulk")) {
logger.warn(
Expand Down
Loading

0 comments on commit fc9abcf

Please sign in to comment.