Skip to content

Commit

Permalink
fix: package build
Browse files Browse the repository at this point in the history
  • Loading branch information
07akioni committed Sep 24, 2024
1 parent d5d0134 commit e6f37c5
Showing 1 changed file with 0 additions and 50 deletions.
50 changes: 0 additions & 50 deletions scripts/post-build/complete-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit e6f37c5

Please sign in to comment.