Skip to content
This repository has been archived by the owner on Mar 20, 2024. It is now read-only.

Cannot import with module_name only with path #478

Closed
herman-rogers opened this issue Jul 15, 2019 · 1 comment
Closed

Cannot import with module_name only with path #478

herman-rogers opened this issue Jul 15, 2019 · 1 comment

Comments

@herman-rogers
Copy link

herman-rogers commented Jul 15, 2019

In this repo there's the ability to import the example library shorten with @bazel/shorten. Starting with a greenfield repo I'm adding similar examples (literally copy/paste from the shorten example). However, I'm unable to import it directly with @bazel/sample-lib but I'm able to have a relative import ../lib/sample-lib/shorten (as long as the shorten path is added to the ng_module deps). Has the API changed since that doesn't allow this?

What my shorten sample looks like:

load("@npm_bazel_typescript//:defs.bzl", "ts_library")

package(default_visibility = ["//:__subpackages__"])

ts_library(
    name = "sample-lib",
    srcs = ["shorten.ts"],
    module_name = "@bazel/sample-lib",
    module_root = "",
    deps = [
        "@npm//@types",
    ]
)

on a side note I'm not able to use module_root as it duplicates the path as shorten/shorten and hence cannot find the correct files.

My app's structure is slightly different than this repo but it's fairly similar; it looks like this

src/
  sample-app/BUILD.bazel
  lib/sample-lib/BUILD.bazel

Thus, I don't have a BUILD.bazel in the src root folder and I'm starting to think that this is what's missing. However, I'd like to not have a BUILD.bazel in the root if that file is going to compile everything in the directory and bloat the builds of the smaller apps.

Ideally we can have small individual builds amongst 5 or 6 independent apps running under the src/ folder each with their own dependencies/requirements. So something like this:

src/
  lib/<assorted libraries>
  sample-app/<angular app>
  sample2-app/<angular app>
  ...

At the moment this is technically working and it's fine but it would be nice to just have our own package name imports to make life a bit easier. I'm also happy to add in a BUILD file in the root to expose the libs as long as we're not pulling in extraneous code from other apps.

package.json:

    "@angular-devkit/build-angular": "~0.800.0",
    "@angular/bazel": "~8.0.1",
    "@angular/cli": "~8.0.3",
    "@angular/compiler-cli": "~8.0.1",
    "@angular/language-service": "~8.0.1",
    "@bazel/bazel": "^0.26.0",
    "@bazel/ibazel": "^0.10.2",
    "@bazel/karma": "0.31.1",
    "@bazel/typescript": "0.31.1",
@alexeagle
Copy link
Contributor

I think module_root="" is a strange thing to write. "duplicates the path as shorten/shorten and hence cannot find the correct files." sounds like you're using a structure we don't support, but it's hard to say without a small repro.

Also you misunderstand - a Bazel package is all the files under the nearest ancestor BUILD.bazel file. Thus the files in src/subdirectory aren't part of the src package if a src/subdirectory/BUILD.bazel file exists, so no, having a BUILD.bazel file in the root doesn't bloat anything.

Sorry you didn't get a reply, we haven't been good about watching this repo for issues. The example is moving to bazelbuild/rules_nodejs which my team does triage.
Please open a new issue there, ideally with a repro

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants