mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2025-04-06 14:30:46 +08:00
fix: package build
This commit is contained in:
parent
d5d0134c09
commit
e6f37c5a95
@ -105,20 +105,6 @@ module.exports.completePath = async (formats) => {
|
||||
)
|
||||
}
|
||||
|
||||
const splitSource = (() => {
|
||||
const splitRegex = /^([\w-]+|@[\w-]+\/[\w-]+)(?:\/(.*))?$/
|
||||
/**
|
||||
* @param {string} source
|
||||
* @return {[string, string] | null}
|
||||
*/
|
||||
return (source) => {
|
||||
const matched = splitRegex.exec(source)
|
||||
if (!matched)
|
||||
return null
|
||||
return matched.slice(1)
|
||||
}
|
||||
})()
|
||||
|
||||
/**
|
||||
* @param {string} source
|
||||
* @param {string} currentDir
|
||||
@ -134,47 +120,11 @@ function parseSource(source, currentDir, suffix) {
|
||||
: joinPath(source, `index${suffix}`)
|
||||
: source + suffix
|
||||
}
|
||||
else if (
|
||||
source.includes('date-fns')
|
||||
&& source !== 'date-fns-tz/formatInTimeZone'
|
||||
) {
|
||||
// Xxxx date-fns for its poor compatibility
|
||||
const [pkgName, subpath] = splitSource(source) || []
|
||||
return pkgName === null || subpath === null
|
||||
? null
|
||||
: guessFullPath(pkgName, subpath)
|
||||
}
|
||||
else {
|
||||
return source
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} pkgName
|
||||
* @param {string} subpath
|
||||
* @return {string | null}
|
||||
*/
|
||||
function guessFullPath(pkgName, subpath) {
|
||||
const pkgPath = require.resolve(path.posix.join(pkgName, 'package.json'))
|
||||
const pkgRootPath = path.dirname(pkgPath)
|
||||
|
||||
let parsedSource = null
|
||||
const sourcePath = path.join(pkgRootPath, subpath)
|
||||
if (fs.existsSync(`${sourcePath}.js`)) {
|
||||
parsedSource = joinPath(pkgName, `${subpath}.js`)
|
||||
}
|
||||
else if (fs.existsSync(`${sourcePath}.mjs`)) {
|
||||
parsedSource = joinPath(pkgName, `${subpath}.mjs`)
|
||||
}
|
||||
else if (fs.existsSync(path.join(sourcePath, 'index.js'))) {
|
||||
parsedSource = joinPath(pkgName, subpath, 'index.js')
|
||||
}
|
||||
else if (fs.existsSync(path.join(sourcePath, 'index.mjs'))) {
|
||||
parsedSource = joinPath(pkgName, subpath, 'index.mjs')
|
||||
}
|
||||
return parsedSource
|
||||
}
|
||||
|
||||
function replaceExtname(filePath, ext) {
|
||||
const oldExt = path.extname(filePath)
|
||||
if (!oldExt)
|
||||
|
Loading…
x
Reference in New Issue
Block a user