Skip to content

Commit

Permalink
Merge branch 'master' into format-doc-with-prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
prakashsvmx authored Jun 24, 2023
2 parents a6b8519 + d8a6f82 commit 27a27bc
Show file tree
Hide file tree
Showing 14 changed files with 449 additions and 415 deletions.
34 changes: 19 additions & 15 deletions build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const extMap = { cjs: '.js', esm: '.mjs' }
async function buildFiles({ files, module, outDir }) {
console.log(`building for ${module}`)
await promisify(exec)(`npx tsc --outDir ${outDir}`, { stdio: 'inherit' })
const ext = extMap[module]

const opt = options(module)
for (const file of files) {
Expand All @@ -69,7 +70,7 @@ async function buildFiles({ files, module, outDir }) {
const outDirPath = path.dirname(outFilePath)

await fsp.mkdir(outDirPath, { recursive: true })
const distCodePath = outFilePath.replace(/\.[tj]s$/g, extMap[module])
const distCodePath = outFilePath.replace(/\.[tj]s$/g, ext)

if (file.path.endsWith('.d.ts')) {
await fsp.copyFile(file.path, outFilePath)
Expand All @@ -88,19 +89,8 @@ async function buildFiles({ files, module, outDir }) {
throw e
}
}
}

async function main() {
await fsp.rm('dist', { recursive: true, force: true })

const entries = fsWalk.walkSync('src/')

await Promise.all([
buildFiles({ files: entries, module: 'cjs', outDir: './dist/main/' }),
buildFiles({ files: entries, module: 'esm', outDir: './dist/esm/' }),
])

for (const file of fsWalk.walkSync('dist/esm/')) {
for (const file of fsWalk.walkSync(outDir)) {
if (file.dirent.isDirectory()) {
continue
}
Expand All @@ -114,14 +104,28 @@ async function main() {
const mts = babel.transformSync(fileContent, {
filename: file.path,
sourceMaps: true,
plugins: [['@babel/plugin-syntax-typescript'], ['replace-import-extension', { extMapping: { '.ts': '.mjs' } }]],
plugins: [['@babel/plugin-syntax-typescript'], ['replace-import-extension', { extMapping: { '.ts': ext } }]],
})

await fsp.unlink(file.path)

const outFilePath = file.path.slice(0, file.path.length - '.d.ts'.length) + '.d.mts'
let outFilePath = file.path.slice(0, file.path.length - '.d.ts'.length) + '.d.ts'
if (module === 'esm') {
outFilePath = file.path.slice(0, file.path.length - '.d.ts'.length) + '.d.mts'
}
await fsp.writeFile(outFilePath, mts.code)
}
}

async function main() {
await fsp.rm('dist', { recursive: true, force: true })

const entries = fsWalk.walkSync('src/')

await Promise.all([
buildFiles({ files: entries, module: 'cjs', outDir: './dist/main/' }),
buildFiles({ files: entries, module: 'esm', outDir: './dist/esm/' }),
])
}

await main()
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"description": "S3 Compatible Cloud Storage client",
"main": "./dist/main/minio.js",
"module": "./dist/esm/minio.mjs",
"types": "./dist/main/minio.d.ts",
"scripts": {
"prepare": "husky install",
"tsc": "tsc",
Expand All @@ -21,19 +20,16 @@
},
"exports": {
".": {
"types": "./dist/main/minio.d.ts",
"require": "./dist/main/minio.js",
"default": "./dist/esm/minio.mjs"
},
"./dist/main/internal/*": null,
"./dist/main/*": {
"types": "./dist/main/*",
"require": "./dist/main/*",
"default": null
},
"./dist/esm/internal/*": null,
"./dist/esm/*": {
"types": "./dist/esm/*",
"import": "./dist/esm/*",
"default": null
},
Expand Down
185 changes: 0 additions & 185 deletions src/extensions.js

This file was deleted.

Loading

0 comments on commit 27a27bc

Please sign in to comment.