Skip to content

Commit

Permalink
Merge pull request #39 from iambumblehead/add-test-and-changes-to-sup…
Browse files Browse the repository at this point in the history
…port-import.meta.url-parent-param

add test and changes to support import.meta.url parent param
  • Loading branch information
iambumblehead committed Sep 24, 2022
2 parents 6ed49b6 + 68ccf5f commit 8fd70bc
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# changelog

* 1.0.2 _Sep.24.2022_
* add test and changes to [support import.meta.resolve](https://github.com/iambumblehead/resolvewithplus/pull/39)
* 1.0.1 _Sep.15.2022_
* reduce size of minified resolvewithplus.js file [by 50%](https://github.com/iambumblehead/resolvewithplus/pull/38)
* 1.0.0 _Aug.28.2022_
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "resolvewithplus",
"version": "1.0.1",
"version": "1.0.2",
"engines" : {
"node" : ">=12.16.0"
},
Expand Down
8 changes: 6 additions & 2 deletions resolvewithplus.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs from 'fs'
import url from 'url'
import path from 'path'
import module from 'module'

Expand All @@ -20,6 +21,7 @@ const esmStrGlobRe = /(\*)/g
const esmStrPathCharRe = /([./])/g
const rootDirSlashRe = /^\//
const protocolNode = /^node:/
const protocolFile = /^file:/
const supportedExtensions = [ '.js', '.mjs', '.ts', '.tsx', '.json', '.node' ]
const node_modules = 'node_modules'
const packagejson = 'package.json'
Expand All @@ -33,7 +35,9 @@ const cache = {}
const addprotocolnode = p => protocolNode.test(p) ? p : `node:${p}`
const addprotocolfile = p => p && ('file:///' + p.replace(rootDirSlashRe, ''))
const iscoremodule = p => isBuiltinRe.test(p)
const getasdirname = p => path.resolve(path.extname(p) ? path.dirname(p) : p)
const getaspath = p => protocolFile.test(p) ? url.fileURLToPath(p) : p
const getasdirname = p =>
path.resolve(path.extname(p) ? path.dirname(p) : p) + '/'

// ex, D:\\a\\resolvewithplus\\pathto\\testfiles\\testscript.js
// -> D:/a/resolvewithplus/pathto/testfiles/testscript.js
Expand Down Expand Up @@ -409,7 +413,7 @@ const begin = (requirepath, withpath, opts) => {
var fullpath = null

withpath = typeof withpath === 'string'
? getasdirname(decodeURI(withpath))
? getasdirname(getaspath(decodeURI(withpath)))
: process.cwd()

if (isBuiltinRe.test(requirepath)) {
Expand Down
4 changes: 4 additions & 0 deletions tests/tests-basic/tests-basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ test('should return fileurl paths, as import.meta.resolve', async () => {
assert.strictEqual( // relpath
await metaresolve(relpathtoindex, fullpathfileurl),
resolvewithplus(relpathtoindex, fullpath))

assert.strictEqual(
await metaresolve(relpathtoindex, import.meta.url),
resolvewithplus(relpathtoindex, import.meta.url))
})

test('should return a full path when given relative path to index file', () => {
Expand Down

0 comments on commit 8fd70bc

Please sign in to comment.