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

Set initial opened file, skip deps install & do not run start scripts as options in sandbox.config.json #514

Open
1 of 4 tasks
jthegedus opened this issue Feb 8, 2018 · 30 comments

Comments

@jthegedus
Copy link

jthegedus commented Feb 8, 2018

Is there a way that the settings inference could be done without the main field in the package.json. This requirement is blocking me, as specifying a main field will conflict with other tools I use, messing up their configuration (firebase/firebase-tools#662).

With an empty main field my other tooling works as expected, but then I receive this error:

An error occured when fetching the sandbox:
Cannot find the specified entry point: 'src/index.js'. Please specify one in 'package.json#main' or create a file at the specified entry point.

Since other templates require specific dependencies, could it check if those templates apply first, then upon failing, infer that the repo being cloned is just an arbitrary folder structure?

As discussed here #43 and https://codeburst.io/github-medium-with-embedly-30d9115af585, I don't wish to execute the code from the repo in CodeSandbox, but merely use it as a way to keep blog code snippets in sync across my Medium blog (using gists for snippets in Medium is unmanagable).

Feat requests resolved

  • open specific file (specified in url)
  • do not automatically install package.json deps
  • do not automatically run scripts in package.json
  • do not require main field in package.json as it conflicts with other tools
@CompuIves
Copy link
Member

Hmm, interesting. We have a list of entry points we traverse specific per template. The package.json entry is the first one we try. Do you have a link to the sandbox? I could definitely add an override based on sandbox.config.json!

@jthegedus
Copy link
Author

jthegedus commented Feb 8, 2018

An override would be great!

This sandbox loads fine as I've got an empty file src/index.js and a main field: https://codesandbox.io/s/github/jthegedus/blog-examples/tree/master/firebase-functions-express . But this breaks the Firebase deployment as it concatenates the main field to the deployment dir. An issue I have raised with Firebase firebase/firebase-tools#662 . This is the repo - https://github.com/jthegedus/blog-examples/tree/master/firebase-functions-express .

I have noticed that it recognises this as the create-react-app template, which I assume is the template inferred by the src/index.js file.

This sandbox fails to load as there is no main field in the package.json: https://codesandbox.io/s/github/jthegedus/blog-examples/tree/master/firebase-functions-es6-babel . This is the repo structure I have which deploys to Firebase fine because the main field is empty and so does not concatenate anything to the other deploy dir definitions in the firebase.json - https://github.com/jthegedus/blog-examples/tree/master/firebase-functions-es6-babel

Sorry I can't be of more help and PR a fix myself. You've innovated so much it's beyond me where to even start a solution.

@CompuIves
Copy link
Member

@jthegedus
Copy link
Author

jthegedus commented Feb 9, 2018

That's correct.

I want to add the project to CodeSandbox without the main field being used to determine anything about the project structure. I want the folder I link on GitHub Import to be the root that CodeSandbox loads, and that's it. If main is populated, a config option to opt-out of using it to determine the project structure would mean I could use main as required by other tools.

I understand that it is common practice to use main to determine the entry point of the app, but the repo structure I have is a stripped down monorepo, without a single entry point.

The discussion here firebase/firebase-tools#662 covers how the firebase-tools CLI tool requires main for deployment. Because each tool uses main and they each require a different path/file to work they conflict.

@ameriania
Copy link

I am encountering the same problem.

In my cases,i just want to clone a repo to show in CodeSandBox,and have some editting,that's it.

But it seems not support yet.

@ryanpcmcquen
Copy link

ryanpcmcquen commented Jul 2, 2018

It would be great if CodeSandbox scanned the package.json for a codesandbox property, is this possible? Conversely, if the sandbox.config.json allowed the specification of an entry point that would also work.

@Saeris
Copy link
Contributor

Saeris commented Aug 18, 2018

Spent a good chunk of time trying to hunt down where exactly in the code CSB is reading the package.json file to get the main path and to see if I could add an override into sandbox.config.json. Couldn't find it. That code is all over the place.

I'm commenting to add another use case for having such an override. I'm trying to write a component library and I need to use the main field in package.json for NPM. Since I developed both the component library and it's demo page in CSB, I was really hoping I could support users simply importing the repo to get a live demo, but as it stands it's one or the other. The only other alternative I see is having some sort of mono-repo structure with multiple package.json files, one for the library and one for the demo page. Maybe I'd need to do that anyways since CSB doesn't seem to install all of the devDependencies either. It would be good to see an example for this use case though, as I'm sure there's a large audience of library developers who would like to use CSB to demo their code.

@eps1lon
Copy link
Contributor

eps1lon commented Aug 18, 2018

@Saeris mui-org/material-ui uses a dedicated examples directory which includes multiple examples that can be used for codesandbox like so: https://codesandbox.io/s/github/mui-org/material-ui/tree/master/examples/create-react-app

I think this approach better suited for your use case.

oliviertassinari pushed a commit to mui/material-ui that referenced this issue Aug 18, 2018
* [docs] add additional information for ts users to issue template

* [docs] fix "Could not find entry" in typescript codesandbox

https://codesandbox.io/s/react-ts uses the same workaround.

Related codesandbox issue: codesandbox/codesandbox-client#514

* [docs] fix conflicting types issue for local development of examples

Typescript pulls types from parent directories (which means types used
in core). This currently leads to a ts error along the line of
"cannot simultaneously extends types X and Y".
See also microsoft/TypeScript#11363

* Typescript -> TypeScript
@CompuIves
Copy link
Member

Oh I'm sorry for that @Saeris, the code to support the sandbox.config.js can be found here: https://github.com/CompuIves/codesandbox-client/blob/private-github/packages/common/templates/template.js#L74-L83

@jthegedus
Copy link
Author

jthegedus commented Nov 22, 2018

The material-ui method is not quite the same as it is using a pre-existing template. It somehow infers that I am using the create-react-app template 🤷‍♂️ but the fact that I can create a sandbox with my repo allows me to use Codesandbox for rendering my code snippets. I am not sure what changed over the past 5 months that now lets this work.

What would be ideal is if sandbox.config.json had a flag to completely turn off the compilation. I just want to render code snippets in my blog, but can't do so without stopping people trying to build a project I know cannot be run within Codesandbox. And by turning off the compilation I guess would make the rest of the issues I am having moot.

For reference, this is the example I wanted: https://codesandbox.io/s/github/jthegedus/firebase-gcp-examples/tree/master/firebase-functions-es6-babel

@lbogdan
Copy link
Contributor

lbogdan commented Mar 26, 2019

Also related: #1254 (that was however solved by adding the Aurelia template).

@lbogdan lbogdan changed the title Settings inference without requiring main field in package.json or src/index.js Allow setting the initial sandbox opened file in sandbox.config.json Mar 26, 2019
@smolinari
Copy link
Contributor

Has this been added? I can't find any note of it in the docs. Would be great if one could simply add an initialFilesToOpen (not just one) property with an array of file name paths in sandbox.config.json.

Scott

@ldanet
Copy link

ldanet commented Nov 4, 2019

This would be really useful to me. I keep running into this issue where I write code to demonstrate something, but I do so in a separate file to the main entry point since the entry point has distracting boilerplate code. When I give the link or open my own sandbox, it opens on the boilerplate code and it's confusing what I'm trying to demonstrate. I would like to see the relevant file with the demo when opening the sandbox, not the boilerplate.

@esr360
Copy link

esr360 commented Nov 17, 2019

Would love to be able to specify default file opened! +1

@github-actions
Copy link

github-actions bot commented Sep 4, 2020

This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made.

@github-actions github-actions bot added the stale label Sep 4, 2020
@karlhorky
Copy link

I suppose now a single opened file can be specified by the file URL parameter:

https://codesandbox.io/s/prismjs-forked-wu91d?file=/src/index.js

@jthegedus
Copy link
Author

@karlhorky It does work as you describe, this being my initial example - https://codesandbox.io/s/github/jthegedus/firebase-gcp-examples/tree/master/functions-express?file=/package.json

However, the sandbox still installs all deps, and attempts to run code in package.json. I don't require any of these things to occur when I just want to render the source code in Medium. Unless I am reading the config options incorrectly - https://codesandbox.io/docs/embedding#embed-on-medium

While the title of the Issue is addressed, I had other requests in the body of the initial issue.

@SaraVieira
Copy link
Contributor

That makes sense, can you please update the title of the issue so it's easier for us to scan through issues?

@jthegedus jthegedus changed the title Allow setting the initial sandbox opened file in sandbox.config.json Set initial opened file, skip deps install & do not run start script as options in sandbox.config.json Sep 6, 2020
@jthegedus jthegedus changed the title Set initial opened file, skip deps install & do not run start script as options in sandbox.config.json Set initial opened file, skip deps install & do not run start scripts as options in sandbox.config.json Sep 6, 2020
@sammychinedu2ky
Copy link

sammychinedu2ky commented Oct 29, 2020

I have a sandbox for a docusaurus template. I had to create a sandbox.config.json file to run yarn start but code sandbox still runs yarn serve instead of the defined yarn start.
please can you help out with that?
here is a link to my sandbox. https://codesandbox.io/s/docu-test-jv4ir

@andrasbacsai
Copy link
Contributor

@sammychinedu2ky could you please check codesandbox/codesandbox-templates#134 (comment)

@sammychinedu2ky
Copy link

thanks man I created a dev script and it worked.

@github-actions
Copy link

This issue has automatically been marked stale because there has been no activity in a while. Please leave a comment if the issue has not been resolved, or if it is not stale for any other reason. After 2 weeks, this issue will automatically be closed, unless a comment is made or the stale label is removed.

@github-actions github-actions bot added the stale label Jan 28, 2021
@karlhorky
Copy link

I guess not stale

@github-actions github-actions bot removed the stale label Jan 29, 2021
@esr360
Copy link

esr360 commented Feb 1, 2021

Can you remove the stale bot? Marking an issue as stale doesn't fix it. Either close the issue because you don't care about it, or leave it open until it's fixed, but don't let a bot determine this please.

@SaraVieira
Copy link
Contributor

I added a label that will make it not close but tbh if it wasn't for the stale bot this issue would have probably never surfaced again, so I do think it's useful, it is kinda annoying but it has brought many issues back to the surface that would in any other way just stay buried in a time where we had about 600 issues

@jthegedus
Copy link
Author

jthegedus commented Feb 3, 2021

This is my bad as this was a kitchen sink type of issue. I should have made 3 distinct issues so each could be closed instead of this lingering mess. I didn't consider the reach over the config this request would have on initial write.

Though I've been inactive on this issue I continue to not be able to use codesandbox as I would like (synced blog examples). It's hard to gauge how many people are in the same position and don't find or thumbs this issue, perhaps it's a small group 🤔

I've updated the intial request with a checklist of the 4 changes I was actually requesting. We're in your house, so if you would like each remaining requests as distinct issues just let me know :)

Thanks for your work 🙏

@github-actions
Copy link

github-actions bot commented May 5, 2021

This issue has automatically been marked stale because there has been no activity in a while. Please leave a comment if the issue has not been resolved, or if it is not stale for any other reason. After 2 weeks, this issue will automatically be closed, unless a comment is made or the stale label is removed.

@github-actions github-actions bot added the stale label May 5, 2021
@karlhorky
Copy link

not stale

@github-actions github-actions bot removed the stale label May 6, 2021
@github-actions
Copy link

github-actions bot commented Aug 4, 2021

This issue has automatically been marked stale because there has been no activity in a while. Please leave a comment if the issue has not been resolved, or if it is not stale for any other reason. After 2 weeks, this issue will automatically be closed, unless a comment is made or the stale label is removed.

@github-actions github-actions bot added the stale label Aug 4, 2021
@karlhorky
Copy link

Not stale

@github-actions github-actions bot removed the stale label Aug 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests