Matt Hintzke
Matt Hintzke

Reputation: 7994

lerna publish and npm pack failing to package all the files in "dist" folder

I am trying to build my first Angular Component package using lerna and it was working pretty well until I realized I had to add "ng-packagr" to get all of the HTML bundled inline with the rest of the code. After adding that support and getting it to work now all of a sudden my files are not getting published into the tarball.

Here is my package.json

{
  "name": "@custom/core",
  "version": "0.0.7",
  "description": "Test",
  "main": "./dist/bundles/custom-core.umd.min.js",
  "module": "./dist/esm2015/custom-core.js",
  "typings": "./dist/index.d.ts",
  "$schema": "./node_modules/ng-packagr/package.schema.json",
  "ngPackage": {
    "lib": {
      "entryFile": "./src/index.ts"
    },
    "whitelistedNonPeerDependencies": [
      "."
    ]
  },
  "scripts": {
    "build": "ng-packagr -p package.json"
  },
  "files": [
    "dist"
  ],
...

My dist folder contains all kinds of folders like this:

enter image description here

But then when I run a lerna publish or npm pack this is what happens:

enter image description here

As you can see only 1 file gets added to the tarball...

Does anyone know why this is happening all of a sudden? I've tried playing around with my .gitignore thinking maybe it was forcing the packaging to ignore these other files but it wasn't that.

UPDATE

Ok so I found that the culprit is ng-packagr. When I run my npm run build which uses ng-packagr -p package.json to build the different module packages, that CLI is also generating a package.json that goes inside of my dist folder. When the npm pack or lerna publish attempt to package everything using a package.json they must be looking at the generated on in dist rather than the one in the folder above it.

I'm not sure how I should be fixing this.

Upvotes: 3

Views: 2883

Answers (1)

Justin Daniel
Justin Daniel

Reputation: 91

My solution was to abandon my plan to use the files key in the package.json file and to instead use a .npmignore file. Here is a copy of mine:

# Node generated files
node_modules
npm-debug.log
assets
package-lock.json

# aot files
aot

# OS generated files
Thumbs.db
.DS_Store

# Ignored files
*.ts
!*.d.ts
tsconfig.json
tsconfig-aot.json
tslint.json
*.tgz
config
src

Upvotes: 2

Related Questions