- 
  Notifications
 
You must be signed in to change notification settings  - Fork 62
 
Enable resolving generated sandboxes.ts file for rootpath #70
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
Conversation
Could you provide more context for this PR? We look for the sourceRoot as a parameter provided in configuration, and place the sandboxes.ts file there by design. Therefore, if you specify your sourceRoot as something other than ./src, that is where the sandboxes.ts file will be placed.
It seems more intuitive for sandboxes.ts to be placed at the sourceRoot instead of the project root, since its function is to export the sandboxes from your application's components, which would also live in sourceRoot.
So here's the deal. Take a look at this line of code here:
https://github.com/SoCreate/angular-playground/blob/master/src/app/load-sandboxes.ts#L5 
. This is how the sandboxes file is loaded into angular playground.
Following the node module resolution algorithm won't find where the
sandboxes.ts file was stored so now webpack will search in places that the
angular cli has configured it to look (namely the root directory and
./src). If you project root is not ./src then webpack will fail to find the
sandboxes.ts file. Thus angular playground currently has an implicit requirement that users with non-default
directory structures must run ng eject and manage their own webpack config which is non-ideal.
My solution to this problem was to place the sandboxes.ts file at the root
of the project so that it could be located regardless of what directory
structure the project has.
Thanks for describing the problem in more detail. Can you give an example of such a non-standard directory structure? We use Playground internally with a multiple-app structure, e.g. src/app1/app, src/app2/app. Each of these "sub-apps" is outfitted with its own Playground that is configured within a single .angular-cli.json.
As long as the .angular-cli.json root property is consistent between your application and the playground application, I don't see why sandboxes.ts wouldn't resolve properly. For instance, if your non-standard directory root is somepath/other, make sure that both entries in .angular-cli.json have "root": "somepath/other".
Thanks for putting that together. I'm going to spend some time looking into this issue--the latest CLI update has caused some problems with multi-app architectures. I've created a ticket on their repo that addresses one such problem, although the error you sent is new to me.
So I've done a lot of investigation into this issue and I thought I'd provide some findings.
Angular CLI 1.5 update introduces a more strict adherence to the tsconfig.json, according to their release post. Playground uses a project's existing CLI configuration to compile sandbox chunks from the sandboxes.ts file. Therefore, it stands that the increased strictness of tsconfig.json settings along with the issue that I referenced above have led to some issues when using Playground with non-default structures.
I am investigating other solutions to this problem that don't involve moving the sandboxes.ts path. I tested it on some other application structures and it didn't resolve the error in all cases.
Yeah that is certainly a consideration. That would require modifying the node_modules output at runtime though, since the sandboxes are resolved by webpack before it hits the angular application.
Before if you specified a custom root path angular-playground would be unable to find sandboxes.ts since it required the file to be generated at the root of a workspace. Sandboxes.ts is located using a require statement
require(sandboxes)and the esnext module resolution algorithm does not look within the specified root path for the module. To circumvent this, we place sandboxes.ts at the root of the workspace.