Comments (5)
I couldn't find any API documentation for a lot of the webpack internals. I relied mostly on experimentation and looking at typescript typings files to figure it out.
If you want to detect a package, a less hacky approach I took in v2 of license-webpack-plugin is to keep scanning directories upward until you reach a package.json file. For example, if a file comes from /a/b/c/d.js
, then the plugin searches first for /a/b/c/package.json
, /a/b/package.json
until it reaches filesystem root. You wouldn't want this to happen to your project's package.json
file though, as that would not be third party code. The plugin relies on webpack's compiler.context
to detect this situation. I'm not sure if context is ever null in webpack v4 (I know it could be null in previous releases of webpack). If you find that compiler.context
is null, you could try defaulting it to process.cwd()
(which is what webpack v4 does internally) as that usually corresponds to your project's "root" directory.
Hope that helps.
from license-webpack-plugin.
My problem is that module.context
in v4 can be null
, while in v3 it always referred to the path or directory of the required/imported file before. What i could do with that is simply search this path for node_modules
strings, and then take the directory after the last node_modules
string found in the path (e.g. a file \mnt\d\projects\licensePlugin\node_modules\a\node_modules\b\c.js
belongs to module b
).
After doing that, i simply threw out duplicate modules and was basically done - having the node_modules name and path to every included module. From there i can then read the package.json
, check for /^licen[cs]e/i
files and more.
It is interesting that you did not find any good documentation as well. I'll probably link this issue and discussion to some webpack folks because i think documentation on this is really really needed.
Using the webpack typings provides a tad more info than simply logging Object.keys of compilation
, compiler
and assorted object instances - but does it really help you being absolutely sure that your plugin never misses a node_module
that is included in the build artifacts?
from license-webpack-plugin.
My question to webpack authors, contributors and maintainers would be:
What is the best hook and the simplest way with that hook to get a list of every node_module
that is at least partially compiled into the build output (regardless of webpack settings like chunking or others).
And why is this not obvious from the plugin documentation?
from license-webpack-plugin.
There is no way I can be absolutely sure that the plugin doesn't miss a node_module, as I have no official answer from the webpack team for this. I have mostly relied on bug reports / pull requests to fill in the gaps. You can see https://github.com/xz64/license-webpack-plugin/blob/master/src/WebpackModuleFileIterator.ts to see how I do it. (note: it doesn't need module.context, as it works with absolute filenames which webpack provides)
from license-webpack-plugin.
I understand - thanks for your answers & clarification! 👍
I would love to have an official opinion by the webpack team on this - OSS licensing is far too significant in todays software development to be unsure about something like this imho.
from license-webpack-plugin.
Related Issues (20)
- Does not add a banner on webpack 5 HOT 2
- when module.resource startsWith `delegated` and throw error HOT 1
- incompatible with webpack 5.47.0 HOT 3
- missing webpack-sources in dependencies HOT 3
- Add loader to load the generated licenses report HOT 1
- Improve pathExists and isDirectory performance once graceful-fs supports it HOT 1
- Support inclusion of extra licenses HOT 1
- plugin will throw error with virtual file
- Type 'LicenseWebpackPlugin' is not assignable to type 'WebpackPluginInstance'.
- Licenses of ES modules in concatenated modules are not emitted HOT 1
- [Webpack 5] Banner rendered, but license file not created
- Version 4.0.1 doesn't respect the excludedPackageTest option HOT 4
- Version 4.0.1 fails when using dynamic imports HOT 2
- make it possible to define lines in `licenseFileOverrides` HOT 2
- turn off warnings for specific packets HOT 1
- License whitelist HOT 1
- ENOENT: No such file or directory, scandir (only on windows) HOT 5
- Suggestion: adjustment for license filename match
- Packages with similar names cause `Multiple assets emit different content to the same filename` error. HOT 1
- Could not find any license file for vega-lite HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from license-webpack-plugin.