Skip to content

Commit

Permalink
Merge pull request #514 from xmtp/rygine/rollup
Browse files Browse the repository at this point in the history
Replace `tsup` with `rollup`
  • Loading branch information
rygine authored Jan 11, 2024
2 parents 2861504 + 4b0c138 commit 94a36c2
Show file tree
Hide file tree
Showing 17 changed files with 3,031 additions and 794 deletions.
2 changes: 0 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
*.config.js
*.config.ts
*.test.js
*.test.ts
dist
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,6 @@ tmp/

# Benchmark results
bench/results

# rollup build plugin output
build/rollup-plugin-resolve-extensions/index.js
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ dist
coverage
docs
tmp
build/rollup-plugin-resolve-extensions/index.js
58 changes: 0 additions & 58 deletions build/esbuild-plugin-resolve-extensions/index.ts

This file was deleted.

43 changes: 43 additions & 0 deletions build/rollup-plugin-resolve-extensions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { basename, dirname, extname, format } from 'node:path'
import { existsSync } from 'node:fs'
import { Plugin } from 'rollup'
import { getResolvedPath, loadCompilerOptions } from '../utils'

export const resolveExtensions = (
extensions: string[] = [],
tsconfigPath?: string
): Plugin => {
const compilerOptions = loadCompilerOptions(tsconfigPath)
return {
name: 'resolve-extensions',
async resolveId(source, importer, options) {
if (extensions.length && !options.isEntry && importer) {
const resolvedPath = getResolvedPath(source, importer, compilerOptions)
let updatedSource = ''

if (resolvedPath) {
const ext = extname(resolvedPath)
const base = basename(resolvedPath, ext)
const dir = dirname(resolvedPath)
// check for extensions
extensions.some((extension) => {
const newPath = format({
dir,
name: base,
ext: `${extension}${ext}`,
})
const exists = existsSync(newPath)
if (exists) {
updatedSource = newPath
return true
}
return false
})

return updatedSource || null
}
}
return null
},
}
}
File renamed without changes.
Loading

0 comments on commit 94a36c2

Please sign in to comment.