Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: browserify/resolve
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.22.0
Choose a base ref
...
head repository: browserify/resolve
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.22.1
Choose a head ref
  • 12 commits
  • 12 files changed
  • 2 contributors

Commits on Jan 22, 2022

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    134d1fe View commit details

Commits on Feb 11, 2022

  1. Copy the full SHA
    232bff4 View commit details
  2. [Test] add some sync coverage

    ljharb committed Feb 11, 2022
    Copy the full SHA
    e9e764c View commit details
  3. Copy the full SHA
    cf1d4cc View commit details

Commits on Feb 15, 2022

  1. Copy the full SHA
    3ab1da8 View commit details

Commits on Apr 23, 2022

  1. Copy the full SHA
    761e1d6 View commit details
  2. [Deps] update is-core-module

    ljharb committed Apr 23, 2022
    Copy the full SHA
    412518e View commit details

Commits on May 23, 2022

  1. [Fix] support windows virtual drive paths

    pos777 authored and ljharb committed May 23, 2022
    Copy the full SHA
    0008477 View commit details

Commits on May 31, 2022

  1. Copy the full SHA
    d171f96 View commit details
  2. Copy the full SHA
    d06a8dc View commit details

Commits on Jun 1, 2022

  1. Copy the full SHA
    f5cf55d View commit details

Commits on Jun 17, 2022

  1. v1.22.1

     - [Fix] support windows virtual drive paths (#284)
     - [Deps] update `is-core-module`
     - [meta] use `npmignore` to autogenerate an npmignore file
     - [meta] do not publish `appveyor.yml`
     - [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `tape`
     - [Test] add tests for `"main": false`
     - [Tests] fix tests on node v12.0-12.2
     - [Test] add some `sync` coverage
     - [Test] fix incorrect `require.resolve` paths logic; enable these tests
     - [Tests] avoid tests breaking on node 11.11 - 11.13
    ljharb committed Jun 17, 2022
    Copy the full SHA
    8eea601 View commit details
Showing with 167 additions and 22 deletions.
  1. +2 −0 .gitignore
  2. +0 −13 .npmignore
  3. +5 −0 appveyor.yml
  4. +1 −1 lib/async.js
  5. +1 −0 lib/core.json
  6. +1 −1 lib/sync.js
  7. +14 −5 package.json
  8. +8 −1 test/core.js
  9. +49 −0 test/resolver.js
  10. 0 test/resolver/false_main/index.js
  11. +4 −0 test/resolver/false_main/package.json
  12. +82 −1 test/resolver_sync.js
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -9,3 +9,5 @@ yarn.lock

# symlinked file used in tests
test/resolver/symlinked/_/node_modules/package

.npmignore
13 changes: 0 additions & 13 deletions .npmignore

This file was deleted.

5 changes: 5 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -73,4 +73,9 @@ test_script:
- node --version
- npm --version
# run tests
- cd
- npm run tests-only
- 'subst X: ..'
- 'cd /d X:\resolve'
- cd
- npm run tests-only
2 changes: 1 addition & 1 deletion lib/async.js
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ var nodeModulesPaths = require('./node-modules-paths');
var normalizeOptions = require('./normalize-options');
var isCore = require('is-core-module');

var realpathFS = fs.realpath && typeof fs.realpath.native === 'function' ? fs.realpath.native : fs.realpath;
var realpathFS = process.platform !== 'win32' && fs.realpath && typeof fs.realpath.native === 'function' ? fs.realpath.native : fs.realpath;

var homedir = getHomedir();
var defaultPaths = function () {
1 change: 1 addition & 0 deletions lib/core.json
Original file line number Diff line number Diff line change
@@ -112,6 +112,7 @@
"node:string_decoder": [">= 14.18 && < 15", ">= 16"],
"sys": [">= 0.4 && < 0.7", ">= 0.8"],
"node:sys": [">= 14.18 && < 15", ">= 16"],
"node:test": ">= 18",
"timers": true,
"node:timers": [">= 14.18 && < 15", ">= 16"],
"timers/promises": ">= 15",
2 changes: 1 addition & 1 deletion lib/sync.js
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ var caller = require('./caller');
var nodeModulesPaths = require('./node-modules-paths');
var normalizeOptions = require('./normalize-options');

var realpathFS = fs.realpathSync && typeof fs.realpathSync.native === 'function' ? fs.realpathSync.native : fs.realpathSync;
var realpathFS = process.platform !== 'win32' && fs.realpathSync && typeof fs.realpathSync.native === 'function' ? fs.realpathSync.native : fs.realpathSync;

var homedir = getHomedir();
var defaultPaths = function () {
19 changes: 14 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "resolve",
"description": "resolve like require.resolve() on behalf of files asynchronously and synchronously",
"version": "1.22.0",
"version": "1.22.1",
"repository": {
"type": "git",
"url": "git://github.com/browserify/resolve.git"
@@ -17,6 +17,7 @@
"module"
],
"scripts": {
"prepack": "npmignore --auto --commentLines=autogenerated",
"prepublishOnly": "safe-publish-latest && cp node_modules/is-core-module/core.json ./lib/ ||:",
"prepublish": "not-in-publish || npm run prepublishOnly",
"prelint": "eclint check $(git ls-files | xargs find 2> /dev/null | grep -vE 'node_modules|\\.git')",
@@ -29,20 +30,22 @@
"test:multirepo": "cd ./test/resolver/multirepo && npm install && npm test"
},
"devDependencies": {
"@ljharb/eslint-config": "^20.2.0",
"@ljharb/eslint-config": "^21.0.0",
"array.prototype.map": "^1.0.4",
"aud": "^2.0.0",
"copy-dir": "^1.3.0",
"eclint": "^2.8.1",
"eslint": "^8.7.0",
"eslint": "=8.8.0",
"in-publish": "^2.0.1",
"mkdirp": "^0.5.5",
"mv": "^2.1.1",
"npmignore": "^0.3.0",
"object-keys": "^1.1.1",
"rimraf": "^2.7.1",
"safe-publish-latest": "^2.0.0",
"semver": "^6.3.0",
"tap": "0.4.13",
"tape": "^5.4.1",
"tape": "^5.5.3",
"tmp": "^0.0.31"
},
"license": "MIT",
@@ -55,8 +58,14 @@
"url": "https://github.com/sponsors/ljharb"
},
"dependencies": {
"is-core-module": "^2.8.1",
"is-core-module": "^2.9.0",
"path-parse": "^1.0.7",
"supports-preserve-symlinks-flag": "^1.0.0"
},
"publishConfig": {
"ignore": [
".github/workflows",
"appveyor.yml"
]
}
}
9 changes: 8 additions & 1 deletion test/core.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
var test = require('tape');
var keys = require('object-keys');
var semver = require('semver');

var resolve = require('../');

var brokenNode = semver.satisfies(process.version, '11.11 - 11.13');

test('core modules', function (t) {
t.test('isCore()', function (st) {
st.ok(resolve.isCore('fs'));
@@ -22,10 +26,13 @@ test('core modules', function (t) {

for (var i = 0; i < cores.length; ++i) {
var mod = cores[i];
// note: this must be require, not require.resolve, due to https://github.com/nodejs/node/issues/43274
var requireFunc = function () { require(mod); }; // eslint-disable-line no-loop-func
console.log(mod, resolve.core, resolve.core[mod]);
t.comment(mod + ': ' + resolve.core[mod]);
if (resolve.core[mod]) {
st.doesNotThrow(requireFunc, mod + ' supported; requiring does not throw');
} else if (brokenNode) {
st.ok(true, 'this version of node is broken: attempting to require things that fail to resolve breaks "home_paths" tests');
} else {
st.throws(requireFunc, mod + ' not supported; requiring throws');
}
49 changes: 49 additions & 0 deletions test/resolver.js
Original file line number Diff line number Diff line change
@@ -290,6 +290,55 @@ test('incorrect main', function (t) {
});
});

test('missing index', function (t) {
t.plan(2);

var resolverDir = path.join(__dirname, 'resolver');
resolve('./missing_index', { basedir: resolverDir }, function (err, res, pkg) {
t.ok(err instanceof Error);
t.equal(err && err.code, 'MODULE_NOT_FOUND', 'error has correct error code');
});
});

test('missing main', function (t) {
t.plan(1);

var resolverDir = path.join(__dirname, 'resolver');

resolve('./missing_main', { basedir: resolverDir }, function (err, res, pkg) {
t.equal(err && err.code, 'MODULE_NOT_FOUND', 'error has correct error code');
});
});

test('null main', function (t) {
t.plan(1);

var resolverDir = path.join(__dirname, 'resolver');

resolve('./null_main', { basedir: resolverDir }, function (err, res, pkg) {
t.equal(err && err.code, 'MODULE_NOT_FOUND', 'error has correct error code');
});
});

test('main: false', function (t) {
t.plan(2);

var basedir = path.join(__dirname, 'resolver');
var dir = path.join(basedir, 'false_main');
resolve('./false_main', { basedir: basedir }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(
res,
path.join(dir, 'index.js'),
'`"main": false`: resolves to `index.js`'
);
t.deepEqual(pkg, {
name: 'false_main',
main: false
});
});
});

test('without basedir', function (t) {
t.plan(1);

Empty file.
4 changes: 4 additions & 0 deletions test/resolver/false_main/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "false_main",
"main": false
}
83 changes: 82 additions & 1 deletion test/resolver_sync.js
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ var resolve = require('../');
var sync = require('../sync');

var requireResolveSupportsPaths = require.resolve.length > 1
&& (/^12\.[012]\./).test(process.version); // broken in v12.0-12.2, see https://github.com/nodejs/node/issues/27794
&& !(/^v12\.[012]\./).test(process.version); // broken in v12.0-12.2, see https://github.com/nodejs/node/issues/27794

test('`./sync` entry point', function (t) {
t.equal(resolve.sync, sync, '`./sync` entry point is the same as `.sync` on `main`');
@@ -309,6 +309,87 @@ test('incorrect main', function (t) {
t.end();
});

test('missing index', function (t) {
t.plan(requireResolveSupportsPaths ? 2 : 1);

var resolverDir = path.join(__dirname, 'resolver');
try {
resolve.sync('./missing_index', { basedir: resolverDir });
t.fail('did not fail');
} catch (err) {
t.equal(err && err.code, 'MODULE_NOT_FOUND', 'error has correct error code');
}
if (requireResolveSupportsPaths) {
try {
require.resolve('./missing_index', { basedir: resolverDir });
t.fail('require.resolve did not fail');
} catch (err) {
t.equal(err && err.code, 'MODULE_NOT_FOUND', 'error has correct error code');
}
}
});

test('missing main', function (t) {
var resolverDir = path.join(__dirname, 'resolver');

try {
resolve.sync('./missing_main', { basedir: resolverDir });
t.fail('require.resolve did not fail');
} catch (err) {
t.equal(err && err.code, 'MODULE_NOT_FOUND', 'error has correct error code');
}
if (requireResolveSupportsPaths) {
try {
resolve.sync('./missing_main', { basedir: resolverDir });
t.fail('require.resolve did not fail');
} catch (err) {
t.equal(err && err.code, 'MODULE_NOT_FOUND', 'error has correct error code');
}
}

t.end();
});

test('null main', function (t) {
var resolverDir = path.join(__dirname, 'resolver');

try {
resolve.sync('./null_main', { basedir: resolverDir });
t.fail('require.resolve did not fail');
} catch (err) {
t.equal(err && err.code, 'MODULE_NOT_FOUND', 'error has correct error code');
}
if (requireResolveSupportsPaths) {
try {
resolve.sync('./null_main', { basedir: resolverDir });
t.fail('require.resolve did not fail');
} catch (err) {
t.equal(err && err.code, 'MODULE_NOT_FOUND', 'error has correct error code');
}
}

t.end();
});

test('main: false', function (t) {
var basedir = path.join(__dirname, 'resolver');
var dir = path.join(basedir, 'false_main');
t.equal(
resolve.sync('./false_main', { basedir: basedir }),
path.join(dir, 'index.js'),
'`"main": false`: resolves to `index.js`'
);
if (requireResolveSupportsPaths) {
t.equal(
resolve.sync('./false_main', { basedir: basedir }),
require.resolve('./false_main', { paths: [basedir] }),
'`"main": false`: resolve.sync === require.resolve'
);
}

t.end();
});

var stubStatSync = function stubStatSync(fn) {
var statSync = fs.statSync;
try {