xz64 / license-webpack-plugin

Outputs licenses from 3rd party libraries to a file
ISC License
165 stars 51 forks source link

Symlinked node_module folder can't be resolved #49

Closed tobiasweibel closed 6 years ago

tobiasweibel commented 6 years ago

We basically have a docker container that has a node_modules directory somewhere. This directory will be sym-linked into the source directory. Processing that symlink with license-webpack-plugin doesn't work due to the following problem. At https://github.com/xz64/license-webpack-plugin/blob/f14972b343a0a2641829f786fdc90887120f94ef/src/ModuleProcessor.ts#L18-L20 the existing code simply concatenates the context path with the paths in modulesDirectories option. This will work when the modulesDirectories paths are set as relative paths. If they are absolute or symlinked then later on in this file (see findModulePrefix) the paths coming from webpack don't match with this.modulePrefixes.

My proposal to solve that issue would be:

        this.modulePrefixes = options.modulesDirectories.map(dir => {
            if (!path.isAbsolute(dir)) {
                dir = path.join(this.context, dir);
            }
            return fs.realpathSync(dir);
        });

Is that reasonable? It would solve the absolute path problem and also symlinked node_modules.

tobiasweibel commented 6 years ago

I've already created some working code. I'll publish that as soon as I get access to my company's fork.

xz64 commented 6 years ago

The change sounds reasonable. I will try it out.

xz64 commented 6 years ago

If your node_modules directory is symlinked into your source directory, couldn't you use a relative path in the modulesDirectories option instead? It might help if you can show me the layout of your project (with respect to node_modules directories) as well.

By the way, I removed this path joining logic in the next release (currently in alpha). Could you test that out for me? It should be a lot more reliable. See issue #43 for the instructions.

In the next release, I replaced the module prefix logic with a scan for a package.json file. Example: If webpack reports a file such as /path/to/node_modules/a/b/c/d.js (which belongs to module a let's say), the plugin will look for the following files to identify which package it belongs to: /path/to/node_modules/a/b/c/package.json /path/to/node_nodules/a/b/package.json /path/to/node_nodules/a/package.json

tobiasweibel commented 6 years ago

In the meantime I was able to test beta.2. It seems to work with our symlinked node_modules. I'm almost done with going through internal legal approval so that I can contribute the bugfix back to you for V1.