sonatype-nexus-community / copy-modules-webpack-plugin

A Webpack plugin which copies module sources to a separate directory
Apache License 2.0
18 stars 7 forks source link

Check for non-existent fileDependencies to fix angular AOT #27

Closed rpokorny closed 3 years ago

rpokorny commented 3 years ago

It appears that builds which use angular AOT compilation add additional non-existent file paths to the fileDependencies collection, while still also including all real file paths. This PR simply adds a check that the file exists before calling lstat on it in order to avoid an error.

deleonio commented 3 years ago

I will try that soon. Thanks

deleonio commented 3 years ago

@rpokorny

Unfortunately, that's not enough. We have two requirements:

  1. handle the exception or is file condition
  2. copy also all renamed source files (for example: file-name.js does not exists, so we copy all file-name.* files)

Advice: The angular plugin transpile all .ts files to .js files under the hood and propergate this files in the webpack fileDependencies.

see here: https://github.com/sonatype-nexus-community/copy-modules-webpack-plugin/pull/26/files

rpokorny commented 3 years ago

@deleonio in my investigation of the issue, I found that all actual files which were included in the build were present in fileDependencies, along with the made-up ones. Are you seeing something different? Given that all of the files we need to copy are present there, there is no need to go hunting for similarly-named files as your PR does. Additionally your solution is problematic in terms of the basic purpose of this plugin: the copying of only those source files which are included in the build. Your solution has the plugin also copying nearby similarly-named files, even if they are not actually included in the build. I would consider that a bug.

deleonio commented 3 years ago

@rpokorny I understand your argumentation. Actually I does not understand why the @ngtools/webpack rename the source meta data.

In our source folder there are only TS files. And in the dependency file list are only JS files.

We will see https://github.com/angular/angular-cli/tree/master/packages/ngtools/webpack

rpokorny commented 3 years ago

In our source folder there are only TS files. And in the dependency file list are only JS files.

OK, so it sounds like you are seeing something different than what I'm seeing. In the demo project that I am tweaking to test this, there is a main.ts file (among other ts files) in the source tree which is present in the fileDependencies array. I am actually not seeing any main.js file in fileDependencies, though I am seeing various other non-existent file paths (for instance, app.component.less.shim.ngstyle.js alongside app.component.less).

What version of angular are you using? That demo project is on angular 6. It's possible the behavior is different in different versions

deleonio commented 3 years ago

I work with angular 11.1 today: Repo to reproduce - https://github.com/leanupjs/angular-and-nexus-iq

I've thought about it again and I find that this solution makes the most sense.

Because ...

But we should know, that this module does not do, what it should do - with angular 11 and a normal webpack config without angular CLI.