Skip to content

Feature/bug : Relative path incorrect for import statements outside of the current project #400

Closed
@mattxo

Description

@mattxo

In 0.0.30, one cannot create a project within a project (ng new says no), nor it seems, can one have a project take a dependency on another project.

For example, on the command line

md MyAwesomeGamesSite
cd MyAwesomeGamesSite
ng new core
ng new game1
ng new game2

Creates

MyAwesomeGamesSite/core #angular2 library of shared classes, components, w/ tests/coverage etc
MyAwesomeGamesSite/game1 # should depend on core
MyAwesomeGamesSite/game2 # should depend on core

Referencing core components from typescript in game1 looks like

import * as CoreStuff from './../../../../core/src/client/app/core/core.service; // 4 directories up./../../../..

However, the output into (for example) game1/tmp/broccoli_type_script_compiler-input_base_path7Z0eLNNd.tmp does not align the import statements correctly

broccoli_type_script_compiler-input_base_path7Z0eLNNd.tmp needs to be

import * as CoreStuff from './../../../../../core/src/client/app/core/core.service; // 5 directories up

Resulting in the following error message from ng serve

The Broccoli Plugin: [BroccoliTypeScriptCompiler] failed with: Error: Typescript found the following errors:
C:/src/[...]/tmp/broccoli_type_script_compiler-input_base_path7Z0eLNNd.tmp/0/src/client/app/test.ts (4, 28): Cannot find module './../../../../core/src/client/app/core/core.service

node_modules\angular-cli\addon\ng2\utilities\dynamicpathparser.js might also be an issue here..

  if (outputPath.indexOf(rootPath) < 0) {
    throw `Invalid path: "${entityName}" cannot be ` +
        `above the "${path.join('src', 'app')}" directory`;
  }

If one could have sub-projects and build these seperately that would be awesome too :)

eg.

core // create with ng new core
  /lib
    /core.service.ts
  /games
    /game1 // need to build/deploy this without game 2 assets
    /game2 // need to build/deploy this without game 1 assets 

EDIT: Perhaps being able to do

ng serve arbitrary-component
ng build arbitrary-component

Would do the job too.

Cheers,
Matt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions