question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Secondary Entry Points Multiple Subdirectories

See original GitHub issue

Type of Issue

[ ] Bug Report
[x] Feature Request

Description

Hello everyone, I want to add secondary entry points to our library but am running into path related issues searching for public_api.ts. I want to clarify if using secondary entry points is applicable with this folder layout.

The library folder layout looks like this:

my_library
└── projects
    └── my-package
        β”œβ”€β”€ src
        |   β”œβ”€β”€ lib
        |   |   β”œβ”€β”€ modules
        |   |   |   β”œβ”€β”€ my-module-one
        |   |   |   |   β”œβ”€β”€ component
        |   |   |   |   |   └── ...
        |   |   |   |   β”œβ”€β”€ component
        |   |   |   |   |   └── ...
        |   |   |   |   β”œβ”€β”€ index.ts <--
        |   |   |   |   β”œβ”€β”€ package.json <-- want to add these
        |   |   |   |   β”œβ”€β”€ public-api.ts <--
        |   |   |   |   └── my-module-one.module.ts
        |   |   |   └── my-module-two
        |   |   |       β”œβ”€β”€ component
        |   |   |       |   └── ...
        |   |   |       β”œβ”€β”€ component
        |   |   |       |   └── ...
        |   |   |       β”œβ”€β”€ index.ts <--
        |   |   |       β”œβ”€β”€ package.json <-- to each module that contains components
        |   |   |       β”œβ”€β”€ public-api.ts <--
        |   |   |       └── my-module-two.module.ts
        |   |   β”œβ”€β”€ index.ts
        |   |   β”œβ”€β”€ package.json
        |   |   β”œβ”€β”€ public-api.ts
        |   |   β”œβ”€β”€ library.module.ts
        |   |   └── library.service.ts
        |   └── public-api.ts (exports everything)
        β”œβ”€β”€ ng-package.json (targets public-api above)
        └── tsconfig.lib.json

How To Reproduce

When building the first entry point will build with no issues (@name/my-package). Then the next entry point is @name/my-package/src/lib/modules/my-module-one on which it fails with Cannot find module './public_api.ts'

Version Information

ng-packagr: 9.0.0
@angular/*: 9.1.9
typescript: ~3.8.3
rxjs: ~6.5.4
npm: 6.11.3

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
SchnWaltercommented, Sep 22, 2020

You can have empty directories without a problem, but AFAIK this is NOT a documented feature and it’s NOT tested to prevent it from being removed in the future or to prevent regressions.

But you can always provide a minimal sub-package (or even a minimal root-package) that just exports something, you only need these files:

  • ng-package.json

    {
      "$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
      "lib": {
        "entryFile": "public-api.ts"
      }
    }
    
  • public-api.ts

    /**
     * @file This file is required for building this "empty" package.
     */
    export const EMPTY_PACKAGE: boolean = true;  // or you could export the package version.
    

Effectively making the package an β€œempty” package.

Sub-package names include the relative path to the primary package; so, one can have an empty directory as parent for sub-packages and a structure like this example here will work just fine, but AFAIK it’s NOT a documented feature:

/projects/@example/package/src/
β”œβ”€β”€ core
β”‚   β”œβ”€β”€ ng-package.json
β”‚   └── public-api.ts
β”œβ”€β”€ components
β”‚   β”œβ”€β”€ badge
β”‚   β”‚   β”œβ”€β”€ ng-package.json
β”‚   β”‚   └── public-api.ts
β”‚   β”œβ”€β”€ toggle
β”‚   β”‚   β”œβ”€β”€ testing
β”‚   β”‚   β”‚   β”œβ”€β”€ ng-package.json
β”‚   β”‚   β”‚   └── public-api.ts
β”‚   β”‚   β”œβ”€β”€ ng-package.json
β”‚   β”‚   └── public-api.ts
β”‚   └── testing
β”‚       └── integration
β”‚           β”œβ”€β”€ ng-package.json
β”‚           └── public-api.ts
β”œβ”€β”€ ng-package.json
β”œβ”€β”€ package.json
└── public-api.ts

And you will have these packages, notice the missing entries for /components and /components/testing sub-packages:

@example/package
@example/package/core
@example/package/components/badge
@example/package/components/toggle
@example/package/components/toggle/testing
@example/package/components/testing/integration

If the library maintainers would like to make this a documented feature, I can quickly extend the tests to watch for these sub-packages that contain β€œempty directories” in their name.

0reactions
github-actions[bot]commented, Feb 18, 2021

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating Secondary Entry Points for your Angular Library
In this article, we will take a look at how we can utilise ng-packagr secondary entry points to split our Angular Library even...
Read more >
Building an Angular Library with multiple entry points | Articles
Then it's time to split the library into multiple entry points (known as secondary entry points or subentry points).
Read more >
Angular library secondary entry points that depend on each ...
It happens that the secondary entry points are built BEFORE the main one, so having a shared logic, I will need to put...
Read more >
Why and how to use secondary entrypoints in your Angular ...
By adding secondary entrypoints, we basically split our Angular libraries into multiple chunks, just like Angular Material does. A Example:.
Read more >
Angular Libraries Adding Secondary EntryPoints - YouTube
This is the second part of Angular Libraries, where we add a secondary entrypoint to make Angular libraries Tree-shakable.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found