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.18.1
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.19.0
Choose a head ref
  • 9 commits
  • 14 files changed
  • 3 contributors

Commits on Oct 25, 2020

  1. [readme] Add possible error types (#232)

    joepie91 authored and ljharb committed Oct 25, 2020
    Copy the full SHA
    02621d7 View commit details

Commits on Nov 9, 2020

  1. Copy the full SHA
    a19e3c4 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    mgaffney Michael Gaffney
    Copy the full SHA
    48c5e08 View commit details

Commits on Nov 10, 2020

  1. Verified

    This commit was signed with the committer’s verified signature.
    paskal Dmitry V
    Copy the full SHA
    d58fd30 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    paskal Dmitry V
    Copy the full SHA
    8683166 View commit details
  3. Verified

    This commit was signed with the committer’s verified signature.
    paskal Dmitry V
    Copy the full SHA
    c04d402 View commit details
  4. [Dev Deps] update aud, eslint

    ljharb committed Nov 10, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    paskal Dmitry V
    Copy the full SHA
    62d4959 View commit details
  5. [Deps] update is-core-module

    ljharb committed Nov 10, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    paskal Dmitry V
    Copy the full SHA
    1a87994 View commit details
  6. v1.19.0

     - [New] `sync`/`async`: add 'includeCoreModules' option (#233)
     - [readme] Add possible error types (#232)
     - [Deps] update `is-core-module`
     - [Dev Deps] update `aud`, `eslint`
     - [meta] add Automatic Rebase and Require Allow Edits workflows
     - [Tests] comment out node 15 in appveyor; it’s not available yet
     - [Tests] add node 15 to appveyor, fix "latest npm" logic
     - [Tests] migrate tests to Github Actions
    ljharb committed Nov 10, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    paskal Dmitry V
    Copy the full SHA
    ae1aa4f View commit details
54 changes: 54 additions & 0 deletions .github/workflows/node-4+.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: 'Tests: node.js'

on: [pull_request, push]

jobs:
matrix:
runs-on: ubuntu-latest
outputs:
latest: ${{ steps.set-matrix.outputs.requireds }}
minors: ${{ steps.set-matrix.outputs.optionals }}
steps:
- uses: ljharb/actions/node/matrix@main
id: set-matrix
with:
preset: '>=4'

latest:
needs: [matrix]
name: 'latest minors'
runs-on: ubuntu-latest

strategy:
matrix: ${{ fromJson(needs.matrix.outputs.latest) }}

steps:
- uses: actions/checkout@v2
- uses: ljharb/actions/node/run@main
name: 'npm install && npm run tests-only'
with:
node-version: ${{ matrix.node-version }}
command: 'tests-only'
minors:
needs: [matrix, latest]
name: 'non-latest minors'
continue-on-error: true
if: ${{ !github.head_ref || !startsWith(github.head_ref, 'renovate') }}
runs-on: ubuntu-latest

strategy:
matrix: ${{ fromJson(needs.matrix.outputs.minors) }}

steps:
- uses: actions/checkout@v2
- uses: ljharb/actions/node/run@main
with:
node-version: ${{ matrix.node-version }}
command: 'tests-only'

node:
name: 'node 4+'
needs: [latest, minors]
runs-on: ubuntu-latest
steps:
- run: 'echo tests completed'
55 changes: 55 additions & 0 deletions .github/workflows/node-iojs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: 'Tests: node.js (io.js)'

on: [pull_request, push]

jobs:
matrix:
runs-on: ubuntu-latest
outputs:
latest: ${{ steps.set-matrix.outputs.requireds }}
minors: ${{ steps.set-matrix.outputs.optionals }}
steps:
- uses: ljharb/actions/node/matrix@main
id: set-matrix
with:
preset: 'iojs'

latest:
needs: [matrix]
name: 'latest minors'
runs-on: ubuntu-latest

strategy:
matrix: ${{ fromJson(needs.matrix.outputs.latest) }}

steps:
- uses: actions/checkout@v2
- uses: ljharb/actions/node/run@main
name: 'npm install && npm run tests-only'
with:
node-version: ${{ matrix.node-version }}
command: 'tests-only'
minors:
needs: [matrix, latest]
name: 'non-latest minors'
continue-on-error: true
if: ${{ !github.head_ref || !startsWith(github.head_ref, 'renovate') }}
runs-on: ubuntu-latest

strategy:
matrix: ${{ fromJson(needs.matrix.outputs.minors) }}

steps:
- uses: actions/checkout@v2
- uses: ljharb/actions/node/run@main
name: 'npm install && npm run tests-only'
with:
node-version: ${{ matrix.node-version }}
command: 'tests-only'

node:
name: 'io.js'
needs: [latest, minors]
runs-on: ubuntu-latest
steps:
- run: 'echo tests completed'
27 changes: 27 additions & 0 deletions .github/workflows/node-pretest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: 'Tests: pretest/posttest'

on: [pull_request, push]

jobs:
pretest:
runs-on: ubuntu-latest


steps:
- uses: actions/checkout@v2
- uses: ljharb/actions/node/run@main
name: 'npm install && npm run pretest'
with:
node-version: 'lts/*'
command: 'pretest'

posttest:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: ljharb/actions/node/run@main
name: 'npm install && npm run posttest'
with:
node-version: 'lts/*'
command: 'posttest'
55 changes: 55 additions & 0 deletions .github/workflows/node-zero.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: 'Tests: node.js (0.x)'

on: [pull_request, push]

jobs:
matrix:
runs-on: ubuntu-latest
outputs:
stable: ${{ steps.set-matrix.outputs.requireds }}
unstable: ${{ steps.set-matrix.outputs.optionals }}
steps:
- uses: ljharb/actions/node/matrix@main
id: set-matrix
with:
preset: '0.x'

stable:
needs: [matrix]
name: 'stable minors'
runs-on: ubuntu-latest

strategy:
matrix: ${{ fromJson(needs.matrix.outputs.stable) }}

steps:
- uses: actions/checkout@v2
- uses: ljharb/actions/node/run@main
with:
node-version: ${{ matrix.node-version }}
command: 'tests-only'
cache-node-modules-key: node_modules-${{ github.workflow }}-${{ github.action }}-${{ github.run_id }}
unstable:
needs: [matrix, stable]
name: 'unstable minors'
continue-on-error: true
if: ${{ !github.head_ref || !startsWith(github.head_ref, 'renovate') }}
runs-on: ubuntu-latest

strategy:
matrix: ${{ fromJson(needs.matrix.outputs.unstable) }}

steps:
- uses: actions/checkout@v2
- uses: ljharb/actions/node/run@main
with:
node-version: ${{ matrix.node-version }}
command: 'tests-only'
cache-node-modules-key: node_modules-${{ github.workflow }}-${{ github.action }}-${{ github.run_id }}

node:
name: 'node 0.x'
needs: [stable, unstable]
runs-on: ubuntu-latest
steps:
- run: 'echo tests completed'
15 changes: 15 additions & 0 deletions .github/workflows/rebase.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Automatic Rebase

on: [pull_request_target]

jobs:
_:
name: "Automatic Rebase"

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: ljharb/rebase@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
14 changes: 14 additions & 0 deletions .github/workflows/require-allow-edits.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Require “Allow Edits”

on: [pull_request_target]

jobs:
_:
name: "Require “Allow Edits”"

runs-on: ubuntu-latest

steps:
- uses: ljharb/require-allow-edits@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8 changes: 0 additions & 8 deletions .travis.yml

This file was deleted.

42 changes: 31 additions & 11 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -4,6 +4,9 @@ build: off

environment:
matrix:
#- nodejs_version: "15"
- nodejs_version: "14"
- nodejs_version: "13"
- nodejs_version: "12"
- nodejs_version: "11"
- nodejs_version: "10"
@@ -25,6 +28,7 @@ matrix:
allow_failures:
- nodejs_version: "5" # due to windows npm bug, registry-side
- nodejs_version: "0.8"
# platform: x86 # x64 has started failing on the registry side, around early November 2020
- nodejs_version: "0.6"

platform:
@@ -33,17 +37,33 @@ platform:

# Install scripts. (runs after repo cloning)
install:
# Fix symlinks in working copy (see https://github.com/appveyor/ci/issues/650#issuecomment-186592582) / https://github.com/charleskorn/batect/commit/d08986802ec43086902958c4ee7e57ff3e71dbef
- git config core.symlinks true
- git reset --hard
# Get the latest stable version of Node.js or io.js
- ps: Install-Product node $env:nodejs_version $env:platform
- IF %nodejs_version% EQU 0.6 npm config set strict-ssl false && npm -g install npm@1.3
- IF %nodejs_version% EQU 0.8 npm config set strict-ssl false && npm -g install npm@1.4.28 && npm install -g npm@4.5
- set PATH=%APPDATA%\npm;%PATH%
#- IF %nodejs_version% NEQ 0.6 AND %nodejs_version% NEQ 0.8 npm -g install npm
# install modules
- npm install
# Fix symlinks in working copy (see https://github.com/appveyor/ci/issues/650#issuecomment-186592582) / https://github.com/charleskorn/batect/commit/d08986802ec43086902958c4ee7e57ff3e71dbef
- git config core.symlinks true
- git reset --hard
# Get the latest stable version of Node.js or io.js
- ps: if ($env:nodejs_version -ne '0.6') { Install-Product node $env:nodejs_version $env:platform }
- ps: Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version) $env:platform
- IF %nodejs_version% EQU 0.6 npm config set strict-ssl false && npm -g install npm@1.3
- IF %nodejs_version% EQU 0.8 npm config set strict-ssl false && npm -g install npm@1.4.28 && npm install -g npm@4.5
- IF %nodejs_version% EQU 1 npm -g install npm@2.9
- IF %nodejs_version% EQU 2 npm -g install npm@4
- IF %nodejs_version% EQU 3 npm -g install npm@4
- IF %nodejs_version% EQU 4 npm -g install npm@5.3
- IF %nodejs_version% EQU 5 npm -g install npm@5.3
- IF %nodejs_version% EQU 6 npm -g install npm@6.9
- IF %nodejs_version% EQU 7 npm -g install npm@6
- IF %nodejs_version% EQU 8 npm -g install npm@6
- IF %nodejs_version% EQU 9 npm -g install npm@6.9
- IF %nodejs_version% EQU 10 npm -g install npm@7
- IF %nodejs_version% EQU 11 npm -g install npm@7
- IF %nodejs_version% EQU 12 npm -g install npm@7
- IF %nodejs_version% EQU 13 npm -g install npm@7
- IF %nodejs_version% EQU 14 npm -g install npm@7
- IF %nodejs_version% EQU 15 npm -g install npm@7
- set PATH=%APPDATA%\npm;%PATH%
#- IF %nodejs_version% NEQ 0.6 AND %nodejs_version% NEQ 0.8 npm -g install npm
# install modules
- npm install

# Post-install test scripts.
test_script:
3 changes: 2 additions & 1 deletion lib/async.js
Original file line number Diff line number Diff line change
@@ -73,6 +73,7 @@ module.exports = function resolve(x, options, callback) {
var packageIterator = opts.packageIterator;

var extensions = opts.extensions || ['.js'];
var includeCoreModules = opts.includeCoreModules !== false;
var basedir = opts.basedir || path.dirname(caller());
var parent = opts.filename || basedir;

@@ -99,7 +100,7 @@ module.exports = function resolve(x, options, callback) {
if ((/\/$/).test(x) && res === basedir) {
loadAsDirectory(res, opts.package, onfile);
} else loadAsFile(res, opts.package, onfile);
} else if (isCore(x)) {
} else if (includeCoreModules && isCore(x)) {
return cb(null, x);
} else loadNodeModules(x, basedir, function (err, n, pkg) {
if (err) cb(err);
1 change: 1 addition & 0 deletions lib/core.json
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
"_debug_agent": ">= 1 && < 8",
"_debugger": "< 8",
"dgram": true,
"diagnostics_channel": ">= 15.1",
"dns": true,
"dns/promises": ">= 15",
"domain": ">= 0.7.12",
3 changes: 2 additions & 1 deletion lib/sync.js
Original file line number Diff line number Diff line change
@@ -66,6 +66,7 @@ module.exports = function resolveSync(x, options) {
var packageIterator = opts.packageIterator;

var extensions = opts.extensions || ['.js'];
var includeCoreModules = opts.includeCoreModules !== false;
var basedir = opts.basedir || path.dirname(caller());
var parent = opts.filename || basedir;

@@ -79,7 +80,7 @@ module.exports = function resolveSync(x, options) {
if (x === '.' || x === '..' || x.slice(-1) === '/') res += '/';
var m = loadAsFileSync(res) || loadAsDirectorySync(res);
if (m) return maybeRealpathSync(realpathSync, m, opts);
} else if (isCore(x)) {
} else if (includeCoreModules && isCore(x)) {
return x;
} else {
var n = loadNodeModulesSync(x, absoluteStart);
8 changes: 4 additions & 4 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.18.1",
"version": "1.19.0",
"repository": {
"type": "git",
"url": "git://github.com/browserify/resolve.git"
@@ -27,9 +27,9 @@
"devDependencies": {
"@ljharb/eslint-config": "^17.2.0",
"array.prototype.map": "^1.0.2",
"aud": "^1.1.2",
"aud": "^1.1.3",
"eclint": "^2.8.1",
"eslint": "^7.11.0",
"eslint": "^7.13.0",
"object-keys": "^1.1.1",
"safe-publish-latest": "^1.1.4",
"tap": "0.4.13",
@@ -45,7 +45,7 @@
"url": "https://github.com/sponsors/ljharb"
},
"dependencies": {
"is-core-module": "^2.0.0",
"is-core-module": "^2.1.0",
"path-parse": "^1.0.6"
}
}
12 changes: 12 additions & 0 deletions readme.markdown
Original file line number Diff line number Diff line change
@@ -43,6 +43,12 @@ $ node example/sync.js
var resolve = require('resolve');
```

For both the synchronous and asynchronous methods, errors may have any of the following `err.code` values:

- `MODULE_NOT_FOUND`: the given path string (`id`) could not be resolved to a module
- `INVALID_BASEDIR`: the specified `opts.basedir` doesn't exist, or is not a directory
- `INVALID_PACKAGE_MAIN`: a `package.json` was encountered with an invalid `main` property (eg. not a string)

## resolve(id, opts={}, cb)

Asynchronously resolve the module path string `id` into `cb(err, res [, pkg])`, where `pkg` (if defined) is the data from `package.json`.
@@ -55,6 +61,8 @@ options are:

* opts.extensions - array of file extensions to search in order

* opts.includeCoreModules - set to `false` to exclude node core modules (e.g. `fs`) from the search

* opts.readFile - how to read files asynchronously

* opts.isFile - function to asynchronously test whether a file exists
@@ -102,6 +110,7 @@ default `opts` values:
paths: [],
basedir: __dirname,
extensions: ['.js'],
includeCoreModules: true,
readFile: fs.readFile,
isFile: function isFile(file, cb) {
fs.stat(file, function (err, stat) {
@@ -144,6 +153,8 @@ options are:

* opts.extensions - array of file extensions to search in order

* opts.includeCoreModules - set to `false` to exclude node core modules (e.g. `fs`) from the search

* opts.readFile - how to read files synchronously

* opts.isFile - function to synchronously test whether a file exists
@@ -190,6 +201,7 @@ default `opts` values:
paths: [],
basedir: __dirname,
extensions: ['.js'],
includeCoreModules: true,
readFileSync: fs.readFileSync,
isFile: function isFile(file) {
try {
16 changes: 16 additions & 0 deletions test/shadowed_core.js
Original file line number Diff line number Diff line change
@@ -36,3 +36,19 @@ test('shadowed core modules return shadow when appending `/` [sync]', function (
t.equal(res, path.join(__dirname, 'shadowed_core/node_modules/util/index.js'));
});

test('shadowed core modules return shadow with `includeCoreModules: false`', function (t) {
t.plan(2);

resolve('util', { basedir: path.join(__dirname, 'shadowed_core'), includeCoreModules: false }, function (err, res) {
t.ifError(err);
t.equal(res, path.join(__dirname, 'shadowed_core/node_modules/util/index.js'));
});
});

test('shadowed core modules return shadow with `includeCoreModules: false` [sync]', function (t) {
t.plan(1);

var res = resolve.sync('util', { basedir: path.join(__dirname, 'shadowed_core'), includeCoreModules: false });

t.equal(res, path.join(__dirname, 'shadowed_core/node_modules/util/index.js'));
});