resolvewithplus
Advanced tools
Comparing version 0.1.2 to 0.2.0
{ | ||
"name": "resolvewithplus", | ||
"version": "0.1.2", | ||
"version": "0.2.0", | ||
"license": "MIT", | ||
@@ -21,9 +21,9 @@ "main": "src/resolvewithplus", | ||
"devDependencies": { | ||
"jasmine": "2.5.3", | ||
"jasmine-spec-reporter": "3.2.0", | ||
"ava": "4.0.0-alpha.2", | ||
"koa": "^2.13.1", | ||
"optfn": "~0.0.x" | ||
}, | ||
"scripts": { | ||
"test": "jasmine --verbose" | ||
"test": "ava" | ||
} | ||
} |
@@ -13,5 +13,10 @@ resolvewithplus | ||
``` | ||
_resolvewithplus_, however, is a new version of [resolvewith][1] behaviour with additional non-standard behaviour included. It recognizes .ts, .tsx, and .mjs files as well as the [browser property][4] in a package.json (or bower.json) to define browser-specific entry files. | ||
Recent support is added for esm module resolution. Note, the ESM resolution spec is not fully implemented, | ||
```javascript | ||
resolvewithplus('koa', '/Users/bumble/resolvewith/test/', { esm : true }); | ||
// '/Users/bumble/resolvewith/node_modules/koa/dist/koa.mjs' | ||
resolvewithplus('koa', '/Users/bumble/resolvewith/test/'); | ||
// '/Users/bumble/resolvewith/node_modules/koa/lib/application.js' | ||
resolvewithplus('bowermodule', '/Users/bumble/resolvewith/test/', { browser : true }); | ||
@@ -18,0 +23,0 @@ // '/Users/bumble/resolvewith/bower_components/bowermodule/build/bowermoduleweb.js' |
@@ -5,110 +5,95 @@ // Filename: resolvewithplus.spec.js | ||
var resolvewithplus = require('../src/resolvewithplus'), | ||
resolvewith = resolvewithplus, | ||
path = require('path'); | ||
// | ||
// should pass resolve with tests as well | ||
// | ||
const test = require('ava'); | ||
const resolvewithplus = require('../src/resolvewithplus'); | ||
const path = require('path'); | ||
test("should return a core module reference as require.resolve id", t => { | ||
t.is( resolvewithplus('path'), require.resolve('path') ); | ||
}); | ||
test("should return a full path when given the relative path to an index file", t => { | ||
const fullpath = path.resolve('./spec/testfiles/'); | ||
describe("resolvewith", function () { | ||
it("should return a core module reference as require.resolve id", function () { | ||
expect( | ||
resolvewith('path') | ||
).toBe( | ||
require.resolve('path') | ||
); | ||
}); | ||
it("should return a full path when given the relative path to an index file", function () { | ||
var fullpath = path.resolve('./spec/testfiles/'); | ||
t.is( | ||
resolvewithplus('./path/to/indexfile', fullpath), | ||
path.resolve('./spec/testfiles/path/to/indexfile/index.js') | ||
); | ||
expect( | ||
resolvewith('./path/to/indexfile', fullpath) | ||
).toBe( | ||
path.resolve('./spec/testfiles/path/to/indexfile/index.js') | ||
); | ||
t.is( | ||
resolvewithplus('../testfiles/path/to/indexfile', fullpath), | ||
path.resolve('./spec/testfiles/path/to/indexfile/index.js') | ||
); | ||
expect( | ||
resolvewith('../testfiles/path/to/indexfile', fullpath) | ||
).toBe( | ||
path.resolve('./spec/testfiles/path/to/indexfile/index.js') | ||
); | ||
t.is( | ||
resolvewithplus('./path/to/indexfile/index', fullpath), | ||
path.resolve('./spec/testfiles/path/to/indexfile/index.js') | ||
); | ||
expect( | ||
resolvewith('./path/to/indexfile/index', fullpath) | ||
).toBe( | ||
path.resolve('./spec/testfiles/path/to/indexfile/index.js') | ||
); | ||
t.is( | ||
resolvewithplus('./path/to/indexfile/index.js', fullpath), | ||
path.resolve('./spec/testfiles/path/to/indexfile/index.js') | ||
); | ||
}); | ||
expect( | ||
resolvewith('./path/to/indexfile/index.js', fullpath) | ||
).toBe( | ||
path.resolve('./spec/testfiles/path/to/indexfile/index.js') | ||
); | ||
test("should use the process path as a default 'with' path (second parameter)", t => { | ||
t.is( | ||
resolvewithplus('./path/to/indexfile'), | ||
null | ||
); | ||
}); | ||
t.is( | ||
resolvewithplus('./spec/testfiles/path/to/indexfile'), | ||
path.resolve('./spec/testfiles/path/to/indexfile/index.js') | ||
); | ||
}); | ||
it("should use the process path as a default 'with' path (second parameter)", function () { | ||
expect( | ||
resolvewith('./path/to/indexfile') | ||
).toBe( | ||
null | ||
); | ||
test("should return null if a path does not exist", t => { | ||
t.is( | ||
resolvewithplus('./path/does/not/exist'), | ||
null | ||
); | ||
}); | ||
expect( | ||
resolvewith('./spec/testfiles/path/to/indexfile') | ||
).toBe( | ||
path.resolve('./spec/testfiles/path/to/indexfile/index.js') | ||
); | ||
}); | ||
test("should return a full path when given the id to a module", t => { | ||
const fullpath = path.resolve('./spec/testfiles/'); | ||
it("should return null if a path does not exist", function () { | ||
expect( | ||
resolvewith('./path/does/not/exist') | ||
).toBe( | ||
null | ||
); | ||
}); | ||
t.is( | ||
resolvewithplus('optfn', fullpath), | ||
path.resolve('./node_modules/optfn/optfn.js') | ||
); | ||
}); | ||
it("should return a full path when given the id to a module", function () { | ||
var fullpath = path.resolve('./spec/testfiles/'); | ||
test("should return a null when given the id to a module inaccessible from withpath", t => { | ||
const fullpath = path.resolve('./spec/testfiles/'); | ||
t.is( | ||
resolvewithplus('notamodulename', path.join(fullpath + '/path/to/indexfile')), | ||
null | ||
); | ||
}); | ||
expect( | ||
resolvewith('optfn', fullpath) | ||
).toBe( | ||
path.resolve('./node_modules/optfn/optfn.js') | ||
); | ||
}); | ||
test("should follow the behaviour of require.resolve", t => { | ||
t.is( | ||
require.resolve('../src/resolvewithplus'), | ||
resolvewithplus('../src/resolvewithplus', path.resolve('../resolvewithplus/spec/')) | ||
); | ||
it("should return a null when given the id to a module inaccessible from withpath", function () { | ||
var fullpath = path.resolve('./spec/testfiles/'); | ||
expect( | ||
resolvewith('notamodulename', path.join(fullpath + '/path/to/indexfile')) | ||
).toBe( | ||
null | ||
); | ||
}); | ||
t.is( | ||
require.resolve('./testfiles/testscript.js'), | ||
resolvewithplus('./testfiles/testscript.js', path.resolve('../resolvewithplus/spec/')) | ||
); | ||
it("should follow the behaviour of require.resolve", function () { | ||
expect( | ||
require.resolve('../src/resolvewithplus') | ||
).toBe( | ||
resolvewith('../src/resolvewithplus', path.resolve('../resolvewithplus/spec/')) | ||
); | ||
t.is( | ||
require.resolve('path'), | ||
resolvewithplus('path', path.resolve('../resolvewithplus/spec/')) | ||
); | ||
}); | ||
expect( | ||
require.resolve('./testfiles/testscript.js') | ||
).toBe( | ||
resolvewith('./testfiles/testscript.js', path.resolve('../resolvewithplus/spec/')) | ||
); | ||
expect( | ||
require.resolve('path') | ||
).toBe( | ||
resolvewith('path', path.resolve('../resolvewithplus/spec/')) | ||
); | ||
}); | ||
test("should handle package.json 'exports' field", t => { | ||
const fullpath = path.resolve('./spec/testfiles/'); | ||
t.is( | ||
resolvewithplus('koa', fullpath, { esm: true }), | ||
path.resolve('./node_modules/koa/dist/koa.mjs') | ||
); | ||
}); |
@@ -82,2 +82,3 @@ // Filename: resolvewithplus.js | ||
browserobj = moduleobj || opts && opts.browser && packagejson.browser, | ||
esmexportsobj = opts.esm && packagejson.exports, | ||
indexprop, | ||
@@ -97,8 +98,14 @@ indexval; | ||
if (esmexportsobj && esmexportsobj['.']) { | ||
if (typeof esmexportsobj['.'].import === 'string') { | ||
indexval = esmexportsobj['.'].import; | ||
} | ||
} | ||
return indexval; | ||
}; | ||
o.getpackagepath = (jsonfile, opts) => | ||
o.getpackagepath = (jsonfile, opts) => ( | ||
o.isfilesync(jsonfile) && (jsonfile = require(jsonfile)) && | ||
(o.getbrowserindex(jsonfile, opts) || jsonfile.main); | ||
(o.getbrowserindex(jsonfile, opts) || jsonfile.main) ); | ||
@@ -105,0 +112,0 @@ // https://nodejs.org/api/modules.html#modules_module_require_id |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
42
14081
6
314