PHP 8.2.30
Preview: node_path.js Size: 2.08 KB
//proc/thread-self/root/home/byroehnu/.trash/node_modules11/resolve/test/node_path.js

var fs = require('fs');
var path = require('path');
var test = require('tape');
var resolve = require('../');

test('$NODE_PATH', function (t) {
    t.plan(8);

    var isDir = function (dir, cb) {
        if (dir === '/node_path' || dir === 'node_path/x') {
            return cb(null, true);
        }
        fs.stat(dir, function (err, stat) {
            if (!err) {
                return cb(null, stat.isDirectory());
            }
            if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false);
            return cb(err);
        });
    };

    resolve('aaa', {
        paths: [
            path.join(__dirname, '/node_path/x'),
            path.join(__dirname, '/node_path/y')
        ],
        basedir: __dirname,
        isDirectory: isDir
    }, function (err, res) {
        t.error(err);
        t.equal(res, path.join(__dirname, '/node_path/x/aaa/index.js'), 'aaa resolves');
    });

    resolve('bbb', {
        paths: [
            path.join(__dirname, '/node_path/x'),
            path.join(__dirname, '/node_path/y')
        ],
        basedir: __dirname,
        isDirectory: isDir
    }, function (err, res) {
        t.error(err);
        t.equal(res, path.join(__dirname, '/node_path/y/bbb/index.js'), 'bbb resolves');
    });

    resolve('ccc', {
        paths: [
            path.join(__dirname, '/node_path/x'),
            path.join(__dirname, '/node_path/y')
        ],
        basedir: __dirname,
        isDirectory: isDir
    }, function (err, res) {
        t.error(err);
        t.equal(res, path.join(__dirname, '/node_path/x/ccc/index.js'), 'ccc resolves');
    });

    // ensure that relative paths still resolve against the regular `node_modules` correctly
    resolve('tap', {
        paths: [
            'node_path'
        ],
        basedir: path.join(__dirname, 'node_path/x'),
        isDirectory: isDir
    }, function (err, res) {
        var root = require('tap/package.json').main; // eslint-disable-line global-require
        t.error(err);
        t.equal(res, path.resolve(__dirname, '..', 'node_modules/tap', root), 'tap resolves');
    });
});

Directory Contents

Dirs: 7 × Files: 20

Name Size Perms Modified Actions
dotdot DIR
- drwxr-xr-x 2026-02-28 00:28:58
Edit Download
- drwxr-xr-x 2026-02-28 00:29:28
Edit Download
node_path DIR
- drwxr-xr-x 2026-02-28 00:29:06
Edit Download
- drwxr-xr-x 2026-02-28 00:29:30
Edit Download
- drwxr-xr-x 2026-02-28 00:29:32
Edit Download
resolver DIR
- drwxr-xr-x 2026-02-28 00:29:58
Edit Download
- drwxr-xr-x 2026-02-28 00:29:22
Edit Download
2.99 KB lrw-r--r-- 2026-02-28 00:28:36
Edit Download
799 B lrw-r--r-- 2026-02-28 00:28:38
Edit Download
807 B lrw-r--r-- 2026-02-28 00:28:38
Edit Download
1.02 KB lrw-r--r-- 2026-02-28 00:28:42
Edit Download
1.39 KB lrw-r--r-- 2026-02-28 00:28:42
Edit Download
4.37 KB lrw-r--r-- 2026-02-28 00:28:52
Edit Download
3.71 KB lrw-r--r-- 2026-02-28 00:28:52
Edit Download
9.78 KB lrw-r--r-- 2026-02-28 00:29:36
Edit Download
5.91 KB lrw-r--r-- 2026-02-28 00:29:34
Edit Download
1.52 KB lrw-r--r-- 2026-02-28 00:29:36
Edit Download
4.98 KB lrw-r--r-- 2026-02-28 00:29:40
Edit Download
2.08 KB lrw-r--r-- 2026-02-28 00:29:38
Edit Download
182 B lrw-r--r-- 2026-02-28 00:29:40
Edit Download
2.20 KB lrw-r--r-- 2026-02-28 00:29:44
Edit Download
646 B lrw-r--r-- 2026-02-28 00:29:44
Edit Download
19.59 KB lrw-r--r-- 2026-02-28 00:29:48
Edit Download
20.46 KB lrw-r--r-- 2026-02-28 00:29:46
Edit Download
1.77 KB lrw-r--r-- 2026-02-28 00:29:48
Edit Download
353 B lrw-r--r-- 2026-02-28 00:29:50
Edit Download
6.38 KB lrw-r--r-- 2026-02-28 00:29:50
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).