Skip to content

Commit

Permalink
ditch legacy dist output
Browse files Browse the repository at this point in the history
  • Loading branch information
echocrow committed Apr 22, 2024
1 parent b49b001 commit a17eb63
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 65 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
"homepage": "https://github.com/kysely-org/kysely-knex",
"author": "Igal Klebanov <[email protected]>",
"license": "MIT",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"exports": {
".": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js"
"import": "./dist/index.mjs",
"require": "./dist/index.js"
},
"./migrations": {
"import": "./dist/esm/migrations.js",
"require": "./dist/cjs/migrations.js"
"import": "./dist/migrations.mjs",
"require": "./dist/migrations.js"
}
},
"files": [
Expand Down
71 changes: 14 additions & 57 deletions scripts/dist-fix.js
Original file line number Diff line number Diff line change
@@ -1,69 +1,26 @@
const {
mkdir,
readdir,
rename,
rm,
writeFile,
readFile,
unlink,
} = require('node:fs/promises')
// @ts-check
const {readdir, writeFile, readFile} = require('node:fs/promises')
const path = require('node:path')

;(async () => {
const distPath = path.join(__dirname, '../dist')
const distCjsPath = path.join(distPath, 'cjs')
const distEsmPath = path.join(distPath, 'esm')

const [dist, distEsm] = await Promise.all([
readdir(distPath),
readdir(distEsmPath),
rm(distCjsPath, {force: true, recursive: true}),
])
const dist = await readdir(distPath)

// Inject type declarations for deno.
// See https://docs.deno.com/runtime/manual/advanced/typescript/types
await Promise.all([
mkdir(distCjsPath),
writeFile(
path.join(distEsmPath, 'package.json'),
JSON.stringify({type: 'module', sideEffects: false}),
),
...dist
.filter((distFilePath) => distFilePath.match(/\.d\.mts$/))
.map((distFilePath) =>
rename(
path.join(distPath, distFilePath),
path.join(distEsmPath, distFilePath),
),
),
...distEsm
.filter((esmFilePath) => esmFilePath.match(/\.js$/))
.map(async (esmFilePath) => {
const distEsmFilePath = path.join(distEsmPath, esmFilePath)

const esmFile = await readFile(distEsmFilePath)
const esmFileContents = esmFile.toString()

const dtsFilePath = `./${esmFilePath.replace('.js', '.d.mts')}`

const denoFriendlyEsmFileContents = [
`/// <reference types="${dtsFilePath}" />`,
esmFileContents,
].join('\n')
.filter((filePath) => filePath.match(/\.m?js$/))
.filter((filePath) => !filePath.startsWith('chunk-'))
.map(async (filename) => {
const distFilePath = path.join(distPath, filename)

await unlink(distEsmFilePath)
const dtsFilePath = filename.replace(/\.(m?)js$/, '.d.$1ts')
const denoFriendlyJsFileContents =
`/// <reference types="${dtsFilePath}" />\n` +
(await readFile(distFilePath)).toString()

await writeFile(distEsmFilePath, denoFriendlyEsmFileContents)
await writeFile(distFilePath, denoFriendlyJsFileContents)
}),
])

await Promise.all([
writeFile(
path.join(distCjsPath, 'package.json'),
JSON.stringify({type: 'commonjs', sideEffects: false}),
),
...dist
.filter((filePath) => filePath.match(/\.[t|j]s(\.map)?$/))
.map((filePath) =>
rename(path.join(distPath, filePath), path.join(distCjsPath, filePath)),
),
])
})()
2 changes: 1 addition & 1 deletion tests/nodejs/fs-migration-source.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {join} from 'node:path'
import {KyselyFsMigrationSource} from '../../dist/esm/migrations'
import {KyselyFsMigrationSource} from '../../dist/migrations'
import {
CONFIGS,
SUPPORTED_DIALECTS,
Expand Down
1 change: 0 additions & 1 deletion tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export default defineConfig({
migrations: 'src/migrations/index.ts',
},
format: ['cjs', 'esm'],
legacyOutput: true,
outDir: 'dist',
sourcemap: true,
})

0 comments on commit a17eb63

Please sign in to comment.