nx icon indicating copy to clipboard operation
nx copied to clipboard

Library multiple entry points

Open liverant opened this issue 3 years ago โ€ข 35 comments

Exactly the same as that issue that was closed by the bot but without any solution.

Description

I want to have the option to publish a library with two endpoints. i.e.

@my-scope/testing/e2e
@my-scope/testing/unit-tests

Where in the e2e I want to include Cypress utils (with Cypress dependency) and in unit-tests I want to include Jasmine utils (with Jasmine dependency)

Motivation

Currently, I can't do the above as both Cypress & Jasmine have an expect global method, so when I import @my-scope/testing it imports both dependencies.

And tree-shaking in general.

  • worth mentioning - I'm using NX to generate libraries monorepo, and I'm using the libraries in external projects (not inside the monorepo, that's why I can't start it as an Angular-monorepo and only use the basic Node approach).

Suggested Implementation

Same as ng-packager: create a package.json (name, dependencies) under the needed library with index.ts as an entry-point.

liverant avatar Jan 20 '22 09:01 liverant

Not sure if it exactly what you're looking for, but I made this a while ago: https://github.com/zwarag/nx-poc

In the lib folder I might have what you're looking for.

zwarag avatar Jan 20 '22 09:01 zwarag

Not sure if it exactly what you're looking for, but I made this a while ago: https://github.com/zwarag/nx-poc

In the lib folder I might have what you're looking for.

@zwarag seems like you talking about Angular libraries? I want the same solution without Angular builder, if possible.

liverant avatar Jan 20 '22 09:01 liverant

What is the issue that you are seeing? We do the same within Nx for @nrwl/workspace/generators: https://github.com/nrwl/nx/blob/master/packages/workspace/generators.ts

FrozenPandaz avatar Jan 29 '22 01:01 FrozenPandaz

What is the issue that you are seeing? We do the same within Nx for @nrwl/workspace/generators: https://github.com/nrwl/nx/blob/master/packages/workspace/generators.ts

Im not seeing any issue, I just don't know how to do this with NX (without Angular preset). Sorry I didn't understand how you create 2 end points with nx-generators?

liverant avatar Jan 30 '22 07:01 liverant

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! ๐Ÿ™

github-actions[bot] avatar Feb 14 '22 00:02 github-actions[bot]

Not stale ๐ŸŽˆ

fguitton avatar Feb 14 '22 09:02 fguitton

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! ๐Ÿ™

github-actions[bot] avatar Mar 01 '22 00:03 github-actions[bot]

Not stale...

liverant avatar Mar 01 '22 07:03 liverant

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! ๐Ÿ™

github-actions[bot] avatar Mar 17 '22 00:03 github-actions[bot]

Not stale ๐ŸŽˆ

fguitton avatar Mar 17 '22 00:03 fguitton

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! ๐Ÿ™

github-actions[bot] avatar Apr 02 '22 00:04 github-actions[bot]

No no no ... not stale ! ๐Ÿคก

fguitton avatar Apr 02 '22 09:04 fguitton

Managed to workaround it by doing this:

under my lib directory i created a rollup config that extends nx one

const nrwlConfig = require('@nrwl/react/plugins/bundle-rollup');

module.exports = config => {
  const nxConfig = nrwlConfig(config);
  
  if (nxConfig.output.format === 'esm') {
    nxConfig.input = {
      index: nxConfig.input,
      utils: join(__dirname, './src/utils/index.ts'),
    };
  }

  return nxConfig;
};

i do this only for esm as i don't need it for the umd build

in libs/mylib/package.json i added

"exports": {
  ".": "./index.esm.js",
  "./utils": "./utils/utils.esm.js"
},
"typesVersions": {
  "*": {
    "utils": [
      "utils/index"
    ]
  }
}

and in workspace.json under the lib build script:

"build": {
  "executor": "@nrwl/web:rollup",
  "options": {
    "rollupConfig": "libs/mylib/rollup.config.js",
  }
},

and in order for it to work in the workspace as well, add in tsconfig.base.json

{
  "compilerOptions": {
    "paths": {      
      "@my-scope/mylib/utils": ["libs/mylib/src/utils/index.ts"],
    }
  },
}

Hope it helps ๐Ÿ™

EladBezalel avatar Apr 03 '22 15:04 EladBezalel

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! ๐Ÿ™

github-actions[bot] avatar Apr 18 '22 00:04 github-actions[bot]

Not stale :)

EladBezalel avatar Apr 18 '22 05:04 EladBezalel

I'm using rollup to bundle some libraries to be published with esm and cjs entrypoints. I need the @nrwl/web:rollup executor to be able to compile to a file for a third entrypoint for bin (one library has cli functionality). Am I at the right issue?

AndyClausen avatar Apr 25 '22 14:04 AndyClausen

Cli is not an entry point (not consumable)

The way I usually do it is - having a bin file direct to a cli.ts file In this file I import my main entry point api and wrap it with cli capabilities (usually with caporal)

EladBezalel avatar Apr 25 '22 21:04 EladBezalel

But you'd still want that as separate compilation output to not expose it to anything but the bin file, right?

AndyClausen avatar Apr 26 '22 00:04 AndyClausen

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! ๐Ÿ™

github-actions[bot] avatar May 10 '22 00:05 github-actions[bot]

Not stale

EladBezalel avatar May 10 '22 04:05 EladBezalel

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! ๐Ÿ™

github-actions[bot] avatar May 25 '22 00:05 github-actions[bot]

Not stale ๐Ÿ™

liverant avatar May 25 '22 06:05 liverant

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! ๐Ÿ™

github-actions[bot] avatar Jun 10 '22 00:06 github-actions[bot]

Not stale :balloon:

fguitton avatar Jun 10 '22 05:06 fguitton

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! ๐Ÿ™

github-actions[bot] avatar Jun 25 '22 00:06 github-actions[bot]

Not stale ๐ŸŒด

fguitton avatar Jun 25 '22 18:06 fguitton

My use case is to build multiple files in a handlers folder like so:

apps/lambda-service-a/handlers
  +--> function1.ts
  +--> function2.ts
  +--> functionN.ts

So, I have an 'application' for a service composed of multiple related lambdas, and I want each of those lambda entry points to compile independently of one another.

This issue looks like is related to my use case, but I'm not sure if I'm missing anything obvious

alfaproject avatar Jul 03 '22 14:07 alfaproject

this is my project's directory

.
โ”œโ”€โ”€ models
โ”‚ย ย  โ”œโ”€โ”€ README.md
โ”‚ย ย  โ”œโ”€โ”€ application
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ README.md
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ application.model.ts
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ index.ts
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ ng-package.json
โ”‚ย ย  โ”œโ”€โ”€ application-core
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ README.md
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ index.ts
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ ng-package.json
โ”‚ย ย  โ”œโ”€โ”€ common
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ README.md
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ common.model.ts
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ index.ts
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ ng-package.json
โ”‚ย ย  โ”œโ”€โ”€ common-core
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ README.md
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ common.enum.ts
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ common.type.ts
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ constant.ts
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ index.ts
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ ng-package.json
โ”‚ย ย  โ”œโ”€โ”€ index.ts
โ”‚ย ย  โ”œโ”€โ”€ jest.config.js
โ”‚ย ย  โ”œโ”€โ”€ ng-package.json
โ”‚ย ย  โ”œโ”€โ”€ package.json
โ”‚ย ย  โ”œโ”€โ”€ project.json
โ”‚ย ย  โ”œโ”€โ”€ tsconfig.json
โ”‚ย ย  โ”œโ”€โ”€ tsconfig.lib.json
โ”‚ย ย  โ”œโ”€โ”€ tsconfig.lib.prod.json
โ”‚ย ย  โ”œโ”€โ”€ tsconfig.spec.json
โ”‚ย ย  โ””โ”€โ”€ user
โ”‚ย ย      โ”œโ”€โ”€ README.md
โ”‚ย ย      โ”œโ”€โ”€ index.ts
โ”‚ย ย      โ”œโ”€โ”€ ng-package.json
โ”‚ย ย      โ””โ”€โ”€ user.model.ts
โ”‚ย ย  โ”œโ”€โ”€ project.json
โ”‚ย ย  โ”œโ”€โ”€ test-setup.ts
โ”‚ย ย  โ”œโ”€โ”€ tsconfig.json
โ”‚ย ย  โ”œโ”€โ”€ tsconfig.lib.json
โ”‚ย ย  โ”œโ”€โ”€ tsconfig.lib.prod.json
โ”‚ย ย  โ””โ”€โ”€ tsconfig.spec.json

just care about models/ng-package.json

{
  "$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
  "dest": "../../dist/packages/models",
  "lib": {
    "entryFile": "index.ts"
  }
}

index.ts

declare const _default: undefined
export default _default;

then sub-lib models/common/ng-package.json

{
  "lib": {
    "entryFile": "index.ts" // it only export 1 files( who care , just example :)
  }
}

then build

.
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ application
โ”‚ย ย  โ”œโ”€โ”€ README.md
โ”‚ย ย  โ”œโ”€โ”€ application.model.d.ts
โ”‚ย ย  โ”œโ”€โ”€ fone-models-application.d.ts
โ”‚ย ย  โ”œโ”€โ”€ index.d.ts
โ”‚ย ย  โ””โ”€โ”€ package.json
โ”œโ”€โ”€ application-core
โ”‚ย ย  โ”œโ”€โ”€ README.md
โ”‚ย ย  โ”œโ”€โ”€ fone-models-application-core.d.ts
โ”‚ย ย  โ”œโ”€โ”€ index.d.ts
โ”‚ย ย  โ””โ”€โ”€ package.json
โ”œโ”€โ”€ common
โ”‚ย ย  โ”œโ”€โ”€ README.md
โ”‚ย ย  โ”œโ”€โ”€ common.model.d.ts
โ”‚ย ย  โ”œโ”€โ”€ fone-models-common.d.ts
โ”‚ย ย  โ”œโ”€โ”€ index.d.ts
โ”‚ย ย  โ””โ”€โ”€ package.json
โ”œโ”€โ”€ common-core
โ”‚ย ย  โ”œโ”€โ”€ README.md
โ”‚ย ย  โ”œโ”€โ”€ common.enum.d.ts
โ”‚ย ย  โ”œโ”€โ”€ common.type.d.ts
โ”‚ย ย  โ”œโ”€โ”€ constant.d.ts
โ”‚ย ย  โ”œโ”€โ”€ fone-models-common-core.d.ts
โ”‚ย ย  โ”œโ”€โ”€ index.d.ts
โ”‚ย ย  โ””โ”€โ”€ package.json
โ”œโ”€โ”€ esm2020
โ”‚ย ย  โ”œโ”€โ”€ application
โ”‚ย ย  โ”œโ”€โ”€ ...
โ”‚ย ย  โ”œโ”€โ”€ index.mjs
โ”‚ย ย  โ””โ”€โ”€ user
โ”œโ”€โ”€ fesm2015
โ”‚ย ย  โ”œโ”€โ”€ fone-models-application-core.mjs
โ”‚ย ย  โ”œโ”€โ”€ ...
โ”‚ย ย  โ””โ”€โ”€ fone-models.mjs.map
โ”œโ”€โ”€ fesm2020
โ”‚ย ย  โ”œโ”€โ”€ fone-models-application-core.mjs
โ”‚ย ย  โ”œโ”€โ”€ ...
โ”‚ย ย  โ””โ”€โ”€ fone-models.mjs.map
โ”œโ”€โ”€ fone-models.d.ts
โ”œโ”€โ”€ homepage
โ”‚ย ย  โ”œโ”€โ”€ README.md
โ”‚ย ย  โ”œโ”€โ”€ fone-models-homepage.d.ts
โ”‚ย ย  โ”œโ”€โ”€ homepage.model.d.ts
โ”‚ย ย  โ”œโ”€โ”€ index.d.ts
โ”‚ย ย  โ””โ”€โ”€ package.json
โ”œโ”€โ”€ homepage-core
โ”‚ย ย  โ”œโ”€โ”€ README.md
โ”‚ย ย  โ”œโ”€โ”€ fone-models-homepage-core.d.ts
โ”‚ย ย  โ”œโ”€โ”€ homepage.enum.d.ts
โ”‚ย ย  โ”œโ”€โ”€ homepage.type.d.ts
โ”‚ย ย  โ”œโ”€โ”€ index.d.ts
โ”‚ย ย  โ””โ”€โ”€ package.json
โ”œโ”€โ”€ index.d.ts
โ”œโ”€โ”€ package.json

caoxicheng avatar Jul 06 '22 06:07 caoxicheng

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! ๐Ÿ™

github-actions[bot] avatar Jul 21 '22 00:07 github-actions[bot]

I'd still like to build multiple entry points for a single project, instead of splitting it into different projects

alfaproject avatar Jul 21 '22 05:07 alfaproject