copy-with-symlinks

dereference symbolic links in node_modules for production release

use newer utility node-modules-prod
Last updated 2 years ago by alfalabs.net .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install copy-with-symlinks 
SYNC missed versions from official npm registry.

copy-with-symlinks

under development

this utility works as is, but does a lot of redundant copying. Please check it later.

why

If you have symbolic links in your node_modules, and run npm instal or gulp-install task, this will create new node_modules folder for production with broken symbolic links. (not tested on linux or darwin)

copy-with-symlinks utility will copy all folders from sourceRoot/dirName to destinationRoot/dirName with actual folders instead of symbolic links.

copyWithSymlinks(sourceRoot, destinationRoot, dirName, options, cb);

NOTE:
The destinationRoot/dirName folder MUST NOT exist before this operation. This folder will be created. Otherwise strange things will happen to symlinks on Windows. (not tested on linux or darwin)

Symbolic links are great for private modules, but npm should handle it for production release.

To check if you have symbolic links in node_modules, look for little link arrows on the folder icon in file explorer:

This utility will copy any folder, not only node_modules but it was specifically designed to work as a gulp task.

gulp use example

NOTE:

The copy-with-symlinks only copies existing folders form DEV node_modules to BUILD. Run npm install in DEV before, to make sure that your modules are in order.

const gulp = require('gulp');
const copyWithSymlinks = require('copy-with-symlinks');

var dest = 'BUILD';

function cb(){console.log('done.');}

gulp.task('copy-npm-modules', function(cb){

     copyWithSymlinks(
        './',                           // sourceRoot
        dest,                           // destinationRoot
        'node_modules',                 // dirName
        {
            quiet: false,               // print copied files to console
            noDevDependencies: true     // do not copy devDependencies (form package.json)
        }, 
        cb                              // callback for gulp task
    );

});

option noDevDependencies looks into package.json file and excludes modules listed in devDependencies

gulp - remove useless files and folders from node_modules

try gulp-dmn

advanced example - one task to copy and purge node_modules

const gulp = require('gulp');
const copyWithSymlinks = require('copy-with-symlinks');
const gulpDmn = require('gulp-dmn');

var dest = 'BUILD';

function cb(){console.log('done.');}

gulp.task('copy-npm-modules', function(cb){

     copyWithSymlinks('./', dest, 'node_modules', {quiet: false, noDevDependencies: true}, function(){
         gulpDmn(dest, {dryRun: false, list: false}, cb);
     });

});

requirements

tested on Win7 with NodeJS v8 and gulp v3

todo

This utility is synchronous (slow) for now. (Maybe if future I'll make it async)

Current Tags

  • 0.0.0                                ...           latest (2 years ago)

2 Versions

  • 0.0.0 [deprecated]           ...           2 years ago
  • 0.0.1 [deprecated]           ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 1
This Month 1
Last Day 1
Last Week 0
Last Month 1
Dependencies (1)
Dev Dependencies (1)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |