chore: replace url-join module with native module

url-join
Romain 6 months ago
parent a5add4d8c7
commit 8572448a10

11
package-lock.json generated

@ -35,7 +35,6 @@
"slugify": "^1.6.6",
"through2": "^4.0.2",
"thumbsup-downsize": "^2.5.1",
"url-join": "^4.0.1",
"yargs": "^17.7.2",
"zen-observable": "^0.10.0"
},
@ -6655,11 +6654,6 @@
"punycode": "^2.1.0"
}
},
"node_modules/url-join": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/url-join/-/url-join-4.0.1.tgz",
"integrity": "sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA=="
},
"node_modules/util-deprecate": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
@ -12054,11 +12048,6 @@
"punycode": "^2.1.0"
}
},
"url-join": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/url-join/-/url-join-4.0.1.tgz",
"integrity": "sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA=="
},
"util-deprecate": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",

@ -58,7 +58,6 @@
"slugify": "^1.6.6",
"through2": "^4.0.2",
"thumbsup-downsize": "^2.5.1",
"url-join": "^4.0.1",
"yargs": "^17.7.2",
"zen-observable": "^0.10.0"
},

@ -1,5 +1,5 @@
const path = require('path')
const urljoin = require('url-join')
const URL = require('url').URL
const url = require('./url')
const BROWSER_SUPPORTED_EXT = /(jpg|jpeg|png|gif)$/i
@ -53,7 +53,8 @@ function photoExtension (filepath) {
function join (prefix, filepath) {
if (prefix.match(/^(http|https|file):\/\//)) {
return urljoin(prefix, url.fromPath(filepath))
const safePrefix = prefix.endsWith('/') ? prefix : (prefix + '/')
return new URL(url.fromPath(filepath), safePrefix).href
} else {
return path.join(prefix, filepath)
}

@ -76,6 +76,11 @@ describe('Structure', () => {
should(res).eql(ospath('../../holidays/IMG_0001.jpg'))
})
it('can use a relative file system link ending with a slash', () => {
const res = folders('holidays/IMG_0001.jpg', 'fs:link', { linkPrefix: '../../' })
should(res).eql(ospath('../../holidays/IMG_0001.jpg'))
})
itLinux('can use an absolute file system link', () => {
const res = folders('holidays/IMG_0001.jpg', 'fs:link', { linkPrefix: '/media' })
should(res).eql('/media/holidays/IMG_0001.jpg')
@ -91,6 +96,11 @@ describe('Structure', () => {
should(res).eql('C:\\media\\holidays\\IMG_0001.jpg')
})
itWindows('can use an absolute file system link ending with a backslash', () => {
const res = folders('holidays/IMG_0001.jpg', 'fs:link', { linkPrefix: 'C:\\media\\' })
should(res).eql('C:\\media\\holidays\\IMG_0001.jpg')
})
itWindows('can use a file:// system link', () => {
const res = folders('holidays/IMG_0001.jpg', 'fs:link', { linkPrefix: 'file://C:/media' })
should(res).eql('file://C:/media/holidays/IMG_0001.jpg')
@ -100,6 +110,16 @@ describe('Structure', () => {
const res = folders('holidays/IMG_0001.jpg', 'fs:link', { linkPrefix: 'http://test.com' })
should(res).eql('http://test.com/holidays/IMG_0001.jpg')
})
it('can use a remote HTTP link with a subfolder', () => {
const res = folders('holidays/IMG_0001.jpg', 'fs:link', { linkPrefix: 'http://test.com/folder' })
should(res).eql('http://test.com/folder/holidays/IMG_0001.jpg')
})
it('can use a remote HTTP link ending with a slash', () => {
const res = folders('holidays/IMG_0001.jpg', 'fs:link', { linkPrefix: 'http://test.com/folder/' })
should(res).eql('http://test.com/folder/holidays/IMG_0001.jpg')
})
})
describe('suffix', () => {

Loading…
Cancel
Save