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

fix: do not consider ancestor files when initializing a project with a specified name #1269

Merged
merged 3 commits into from
Jun 17, 2022
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
14 changes: 14 additions & 0 deletions .changeset/quiet-pigs-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
"wrangler": patch
---

fix: do not consider ancestor files when initializing a project with a specified name

When initializing a new project (via `wrangler init`) we attempt to reuse files in the current
directory, or in an ancestor directory. In particular we look up the directory tree for
package.json and tsconfig.json and use those instead of creating new ones.

Now we only do this if you do not specify a name for the new Worker. If you do specify a name,
we now only consider files in the directory where the Worker will be initialized.

Fixes #859
49 changes: 36 additions & 13 deletions packages/wrangler/src/__tests__/helpers/mock-dialogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,22 @@ export interface ConfirmExpectation {
*/
export function mockConfirm(...expectations: ConfirmExpectation[]) {
(confirm as jest.Mock).mockImplementation((text: string) => {
for (const { text: expectedText, result } of expectations) {
if (normalizeSlashes(text) === normalizeSlashes(expectedText)) {
return Promise.resolve(result);
for (const expectation of expectations) {
if (normalizeSlashes(text) === normalizeSlashes(expectation.text)) {
expectations = expectations.filter((e) => e !== expectation);
return Promise.resolve(expectation.result);
}
}
throw new Error(`Unexpected confirmation message: ${text}`);
});
return () => {
if (expectations.length > 0) {
throw new Error(
"The following expected confirmation dialogs were not used:\n" +
expectations.map((e) => `- "${e.text}"`).join("\n")
);
}
};
}

export function clearConfirmMocks() {
Expand Down Expand Up @@ -63,18 +72,23 @@ export interface PromptExpectation {
export function mockPrompt(...expectations: PromptExpectation[]) {
(prompt as jest.Mock).mockImplementation(
(text: string, type: "text" | "password") => {
for (const {
text: expectedText,
type: expectedType,
result,
} of expectations) {
if (text === expectedText && type == expectedType) {
return Promise.resolve(result);
for (const expectation of expectations) {
if (text === expectation.text && type == expectation.type) {
expectations = expectations.filter((e) => e !== expectation);
return Promise.resolve(expectation.result);
}
}
throw new Error(`Unexpected confirmation message: ${text}`);
}
);
return () => {
if (expectations.length > 0) {
throw new Error(
"The following expected prompt dialogs were not used:\n" +
expectations.map((e) => `- "${e.text}"`).join("\n")
);
}
};
}

export function clearPromptMocks() {
Expand Down Expand Up @@ -108,13 +122,22 @@ export interface SelectExpectation {
*/
export function mockSelect(...expectations: SelectExpectation[]) {
(select as jest.Mock).mockImplementation((text: string) => {
for (const { text: expectedText, result } of expectations) {
if (normalizeSlashes(text) === normalizeSlashes(expectedText)) {
return Promise.resolve(result);
for (const expectation of expectations) {
if (normalizeSlashes(text) === normalizeSlashes(expectation.text)) {
expectations = expectations.filter((e) => e !== expectation);
return Promise.resolve(expectation.result);
}
}
throw new Error(`Unexpected select message: ${text}`);
});
return () => {
if (expectations.length > 0) {
throw new Error(
"The following expected select dialogs were not used:\n" +
expectations.map((e) => `- "${e.text}"`).join("\n")
);
}
};
}

export function clearSelectMocks() {
Expand Down
Loading