forked from kysely-org/kysely-knex
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
21 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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": [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)), | ||
), | ||
]) | ||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters