arifsetiawan / flatten Goto Github PK
View Code? Open in Web Editor NEWflatten packages in node_modules
License: MIT License
flatten packages in node_modules
License: MIT License
It would be good to have a functionality to ignore flattening some packages. Like using a .flattenignore file or thorugh cli options.
This is a use case where we use the same module built both for nw-gyp and node-gyp (ie., two copies of same module exists).
Thanks
I'm new to flatten-packages
and have a few questions. Looking forward to your kind reply. Thanks.
flat
) already flat the packages maximally. Do I still need to use flatten-packages
?flatten-packages
and npm dedupe
?
npm dedup
: The deduplication algorithm walks the tree, moving each dependency as far up in the tree as possible, even if duplicates are not found. This will result in both a flat and deduplicated tree.
I think npm dedupe
is doing the same thing? How does flatten-packages
handle conflict packages?
I get more files in my node_modules folder after flattening than before.
Intuitively it should be the opposite as some dependencies are merged and node_modules directories are removed.
Is it a bug or am I missing something ?
Before:
2.599 Files
666 Folders
14.863.707 Bytes
After:
3.312 Files (27% more)
668 Folders
17.719.802 Bytes (19% more)
I tried with several dependencies setup, with common modules (connect, fs-extra, chokidar, ...) and starting with a clean env (empty node_modules dir). I get no error and sub node_modules directory are successfully removed by the command.
Trying to use this package on Linux, I have a weird error :
$ flatten-packages
: No such file or directory
Looks like the main script has DOS encoding.
Is it working anywhere other than Windows/Cygwin?
I'm using flatten-packages
inside of a gulp
task:
gulp.task('flatten', function (next) {
flatten(dist, {}, next)
})
and I would like to have an ability to disable all flatten-packages
output, e.g.:
gulp.task('flatten', function (next) {
flatten(dist, { silent: true }, next)
})
Right not it's not even possible to turn verbose
mode of, because you're overwriting options.verbose
with true
.
For now I'm using a dirty hack with Object.defineProperty to turn verbose
mode off, but I'm still getting a lot of annoying console output.
Thanx!
{
...
"dependencies": {
"local_module":"file:/path/to/local/module"
}
}
I guess It should don't touch local modules.
Just a info about Automatic deployment, you can edit readme if you want.
In package.json, you can define this package install in "preinstall" and package run in "postinstall":
"scripts": {
"preinstall": "npm i -g flatten-packages",
"postinstall": "flatten-packages"
},
Then, when you call npm install
the npm itself will install flatten-packages and will run it after install process.
Using node version v0.10.26 and [email protected], when you execute "flatten-packages" you get the following error:
"env: node\r: No such file or directory"
flatten-packages -p
should print new (not already on top level node_modules directory) packages on a peerDependencies
entry. See https://docs.npmjs.com/files/package.json#peerdependencies
flatten-packages should be able de process (through options?) dependencies alone (excluding devDependencies).
Also flatten-packages -p
should print them into the correct key (dev/not-dev) especially when both are processed.
It would be nve to pass command of NPM Colors to not output colors in console using --no-color as documented in https://www.npmjs.com/package/colors
Hi,
after using flatten-packages, uglify (grunt-contrib-uglify) gives me the following message:
"Warning: An error occurred while processing a template (undefined is not a function). Use --force to continue."
but other tasks are working fine (like cssmin and compass).
I really appreciate your help.
...
duplicate: enhanced-resolve 0.4.12 existing version: 0.9.1
[SyntaxError: /Users/Donovan/code/lendinghome-monolith/ops/node_modules/enhanced-require/node_modules/enhanced-resolve/test/fixtures/node_modules/invalidPackageJson/package.json: Unexpected end of input]
moving directory c:\Users\Administrator\projects\fireball-x\fireball\dist\resources\app\node_modules\chalk\node_modules\has-ansi\node_modules\get-stdin to c:\Users\Administrator\projects\fireball-x\fireball\dist\resources\app\node_modules\get-stdin
{ [Error: ENOENT, no such file or directory 'c:\Users\Administrator\projects\fireball-x\fireball\dist\resources\app\node_modules\chalk\node_modules\has-ansi\node_modules\get-stdin']
errno: -4058,
code: 'ENOENT',
path: 'c:\\Users\\Administrator\\projects\\fireball-x\\fireball\\dist\\resources\\app\\node_modules\\chalk\\node_modules\\has-ansi\\node_modules\\get-stdin',
syscall: 'stat' }
When this error occurs, I checked and the source folder c:\Users\Administrator\projects\fireball-x\fireball\dist\resources\app\node_modules\chalk\node_modules\has-ansi\node_modules\get-stdin
does exists.
My project's node_modules iteration info:
node_modules iteration complete
there are 512 unique packages
962 duplicate packages
there are 41 packages in node_modules level 1
219 packages in node_modules level 2
420 packages in node_modules level 3
374 packages in node_modules level 4
240 packages in node_modules level 5
124 packages in node_modules level 6
38 packages in node_modules level 7
17 packages in node_modules level 8
1 packages in node_modules level 9
I encountered invalid package that crashed flatten-packages
.
https://github.com/substack/node-browserify/blob/master/test/field/node_modules/z-miss/package.json
Here is a tiny fix:
try {
var packageJson = require(modules[i]);
currentData.name = packageJson.name;
currentData.version = packageJson.version;
if(typeof(currentData.name) === 'undefined')
continue;
//throw 'Name is not specified in ' + modules[i];
if(typeof(currentData.version) === 'undefined')
continue;
//throw 'Version is not specified in ' + modules[i];
}
catch(err) {
return callback(err);
}
I prefer to ignory error and moving forward.
BTW: Thanks for flatten-packages
.
I know this project isn't maintained any more, but in case others are seeing messages like this:
npm WARN deprecated [email protected]: wrench.js is deprecated! You should check out fs-extra (https://github.com/jprichardson/node-fs-extra) for any operations you were using wrench for. Thanks for all the usage over the years.
It may be coming from this
Hi arifsetiawan,
using your module, in the flatten.js file. The error is shown in the title. It's called when the code request:
options.verbose
Because there is no options defined. Where am I wrong?
I'm using the module because is require in the node-zendesk module.
Thanks!
When I ran flatten-packages
in an already flattened directory, I got the following error:
PS D:\Project> flatten-packages
processing directory D:\Project
there are 210 total packages
C:\Users\teltploek\AppData\Roaming\npm\node_modules\flatten-packages\lib\flatten.js:89
ole.log(' duplicate:'.magenta, currentData.name, currentData.version.cyan, 'ex
^
TypeError: Cannot read property 'cyan' of undefined
at C:\Users\teltploek\AppData\Roaming\npm\node_modules\flatten-packages\lib\flatten.js:89:89
at C:\Users\teltploek\AppData\Roaming\npm\node_modules\flatten-packages\lib\flatten.js:198:31
at C:\Users\teltploek\AppData\Roaming\npm\node_modules\flatten-packages\lib\flatten.js:198:31
at C:\Users\teltploek\AppData\Roaming\npm\node_modules\flatten-packages\lib\flatten.js:198:31
at C:\Users\teltploek\AppData\Roaming\npm\node_modules\flatten-packages\lib\flatten.js:198:31
at C:\Users\teltploek\AppData\Roaming\npm\node_modules\flatten-packages\lib\flatten.js:198:31
at C:\Users\teltploek\AppData\Roaming\npm\node_modules\flatten-packages\lib\flatten.js:198:31
at C:\Users\teltploek\AppData\Roaming\npm\node_modules\flatten-packages\lib\flatten.js:198:31
at C:\Users\teltploek\AppData\Roaming\npm\node_modules\flatten-packages\lib\flatten.js:198:31
at C:\Users\teltploek\AppData\Roaming\npm\node_modules\flatten-packages\lib\flatten.js:214:27
The reason for the error is, that a package has no version information in its package.json. The package garply has a package.json containing:
{
"main" : "./lib"
}
I'll submit a pull request to correct this in a short while.
Example: don't replace node_modules which has strict dependency version on package.json to avoid new module breaking changes
My proposal is to put such module in its original location (don't move to first level or delete it)
I just run flatten-packages in order to prevent too long path and my gulp script stop working. There are commands to reproduce this case:
yo gulp-angular // keep default options
gulp build // all works properly
flatten-packages
gulp build // node print some error
While running gulp second time I receive the following error:
E:\projects\a2\node_modules\karma\lib\middleware\runner.js:11
var json = require('connect').json();
^
TypeError: undefined is not a function
at Object.<anonymous> (E:\projects\a2\node_modules\karma\lib\middleware\runner.js:11:31)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (E:\projects\a2\node_modules\karma\lib\web-server.js:7:24)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
Currently when flattened, all the .bin files (coffeescript for example) are not copied to the .bin directory of the parent.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.