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

🐛 BUG: wrangler init foo should stop looking for tsconfig.json and package.json at ./foo #859

Closed
petebacondarwin opened this issue Apr 29, 2022 · 3 comments · Fixed by #1269 or #1284
Assignees
Labels
bug Something that isn't working

Comments

@petebacondarwin
Copy link
Contributor

What version of Wrangler are you using?

0.027

What operating system are you using?

Mac

Describe the Bug

If you run wrangler init foo inside a directory that contains a tsconfig.json, then Wrangler automatically assumes you are in a TypeScript project. I would argue that if you have specified a new directory (e.g. foo) for this Worker, then we should not treat it as part of a wider project.

@threepointone
Copy link
Contributor

Yeah I can agree with this. Especially because:

  • we usually need to setup workers-types anyway
  • or we need to extend from a higher tsconfig

Both scenarios require a new tsconfig file. And it's easier to delete/modify a generated tsconfig than it is to create one.

@petebacondarwin petebacondarwin added this to the 2.1 milestone May 12, 2022
@petebacondarwin petebacondarwin moved this to Must-have in workers-sdk May 12, 2022
@petebacondarwin petebacondarwin modified the milestones: Selected for development, Backlog May 15, 2022
@petebacondarwin petebacondarwin moved this to Backlog in workers-sdk May 15, 2022
@petebacondarwin petebacondarwin removed this from the Backlog milestone May 15, 2022
@petebacondarwin petebacondarwin added bug Something that isn't working and removed type: bug labels May 16, 2022
@petebacondarwin petebacondarwin moved this from Backlog to Selected for development in workers-sdk May 16, 2022
@rozenmd rozenmd self-assigned this Jun 3, 2022
@rozenmd rozenmd moved this from Selected for development to In Progress in workers-sdk Jun 3, 2022
@rozenmd
Copy link
Contributor

rozenmd commented Jun 3, 2022

I think this might be two issues:

  1. Should we always create a package.json in the directory specified by --name, even if one exists in a higher directory
  2. Should we always create a tsconfig.json in the directory specified by --name, even if one exists in a higher directory

I would argue (at least for my own uses, maybe I'm the edge case?) in both cases, we should completely ignore what's in the current directory or higher up in a parent directory - if I run wrangler init newWorkerPls in projectRoot/ I expect /projectRoot/newWorkerPls/ to be a self-contained worker with a package.json, and if I asked for typescript, I'd like a tsconfig.json too

@petebacondarwin
Copy link
Contributor Author

I agree that if you specify a path in the init command, then we should be assuming that the new directory is self contained and do not look up the tree for package.json or tsconfig.json.

If you do not specify a path then Wrangler defaults to initialising the current directory. In this case then I think we should be willing to look up the directory-tree for package.json and tsconfig.json.

@rozenmd rozenmd moved this from In Progress to Selected for development in workers-sdk Jun 8, 2022
@rozenmd rozenmd removed their assignment Jun 8, 2022
@petebacondarwin petebacondarwin self-assigned this Jun 9, 2022
@petebacondarwin petebacondarwin moved this from Selected for development to In Progress in workers-sdk Jun 9, 2022
petebacondarwin added a commit to petebacondarwin/wrangler2 that referenced this issue Jun 15, 2022
…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 cloudflare#859
@petebacondarwin petebacondarwin moved this from In Progress to In Review in workers-sdk Jun 15, 2022
petebacondarwin added a commit that referenced this issue Jun 17, 2022
…a specified name (#1269)

* test: add checks for unused mock dialogs in tests

* test: refactor init tests to use file-system helpers

* 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
Repository owner moved this from In Review to Done in workers-sdk Jun 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that isn't working
Projects
None yet
3 participants