Skip to content

Commit 36ef910

Browse files
committed
build: use mkbuild to build project
- replaces `unbuild` (https://github.com/unjs/unbuild) 😌👋🏾 - https://github.com/flex-development/mkbuild Signed-off-by: Lexus Drumgold <[email protected]>
1 parent 745b3bf commit 36ef910

8 files changed

+128
-1101
lines changed

.dictionary.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ dedupe
1616
dessant
1717
dohm
1818
esbenp
19+
esbuild
1920
fbca
2021
fpnv
2122
gpgsign
@@ -26,7 +27,7 @@ keyid
2627
larsgw
2728
lcov
2829
micnncim
29-
mkdist
30+
mkbuild
3031
mlly
3132
nocheck
3233
npmrc

.eslintrc.cjs

-18
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,6 @@ const config = {
1313
extends: ['./.eslintrc.base.cjs'],
1414
overrides: [
1515
...require('./.eslintrc.base.cjs').overrides,
16-
{
17-
files: ['src/index.ts'],
18-
rules: {
19-
/**
20-
* mkdist converts `exports.default` to `module.exports = _default`.
21-
*
22-
* `exports.default` statements are only output if `export default ...`
23-
* is used for default exports.
24-
*
25-
* this means that `export { default } from '...'` should **not** be
26-
* used where default exports should be supported, as with the package
27-
* entry point.
28-
*
29-
* @see https://github.com/unjs/mkdist/blob/v0.3.13/src/loaders/js.ts#L40
30-
*/
31-
'unicorn/prefer-export-from': 0
32-
}
33-
},
3416
{
3517
files: ['src/ponyfill.ts'],
3618
rules: {

.yarn/patches/mkdist-npm-0.3.13-c41cf41c68.patch

-39
This file was deleted.

.yarn/patches/resolve-tspaths-npm-0.7.4-6fc6738fb9.patch

-29
This file was deleted.

build.config.ts

+20-128
Original file line numberDiff line numberDiff line change
@@ -1,140 +1,32 @@
11
/**
2-
* @file Unbuild Config
3-
* @module config/unbuild
4-
* @see https://github.com/unjs/unbuild#configuration
2+
* @file Build Config
3+
* @module config/build
4+
* @see https://github.com/flex-development/mkbuild#configuration
55
*/
66

7-
import { resolveId } from 'externality'
8-
import type { MkdistOptions } from 'mkdist'
9-
import { findStaticImports } from 'mlly'
10-
import fs from 'node:fs'
11-
import path from 'node:path'
12-
import { applyChanges } from 'resolve-tspaths/dist/steps/applyChanges'
13-
import { computeAliases } from 'resolve-tspaths/dist/steps/computeAliases'
14-
import { generateChanges } from 'resolve-tspaths/dist/steps/generateChanges'
15-
import { loadTSConfig } from 'resolve-tspaths/dist/steps/loadTSConfig'
16-
import type { Alias, Change } from 'resolve-tspaths/dist/types'
17-
import {
18-
defineBuildConfig,
19-
type BuildConfig,
20-
type BuildContext,
21-
type BuildOptions,
22-
type MkdistBuildEntry
23-
} from 'unbuild'
7+
import { defineBuildConfig, type Config } from '@flex-development/mkbuild'
8+
import pkg from './package.json' assert { type: 'json' }
9+
import tsconfig from './tsconfig.build.json' assert { type: 'json' }
2410

2511
/**
26-
* Build options.
12+
* Build configuration options.
2713
*
28-
* @const {BuildConfig}
14+
* @const {Config} config
2915
*/
30-
const config: BuildConfig = defineBuildConfig({
31-
declaration: true,
16+
const config: Config = defineBuildConfig({
3217
entries: [
33-
{ builder: 'mkdist', ext: 'cjs', format: 'cjs', input: 'src/' },
34-
{ builder: 'mkdist', ext: 'mjs', format: 'esm', input: 'src/' }
18+
{ ext: '.mjs', format: 'esm' },
19+
{ ext: '.cjs', format: 'cjs' }
3520
],
36-
hooks: {
37-
/**
38-
* Transforms path aliases and bare specifiers in `output.writtenFiles`.
39-
*
40-
* @param {BuildContext} ctx - Build context
41-
* @param {BuildOptions} ctx.options - Build options
42-
* @param {MkdistBuildEntry} entry - `mkdist` build entry
43-
* @param {{ writtenFiles: string[] }} results - Build results
44-
* @param {string[]} results.writtenFiles - Files created during build
45-
* @return {Promise<void>} Nothing when complete
46-
*/
47-
async 'mkdist:entry:build'(
48-
ctx: BuildContext,
49-
entry: MkdistBuildEntry,
50-
results: { writtenFiles: string[] }
51-
): Promise<void> {
52-
const { outDir, rootDir } = ctx.options
53-
const { writtenFiles } = results
54-
55-
// transform path aliases
56-
try {
57-
const { paths = {} } = loadTSConfig(`${rootDir}/tsconfig.json`).options
58-
59-
/**
60-
* Path alias objects.
61-
*
62-
* @const {Alias[]} aliases
63-
*/
64-
const aliases: Alias[] = computeAliases(rootDir, paths)
65-
66-
/**
67-
* Changes to apply to {@link writtenFiles}.
68-
*
69-
* @const {Change[]} changes
70-
*/
71-
const changes: Change[] = generateChanges(writtenFiles, aliases, {
72-
outPath: outDir,
73-
srcPath: path.resolve('src')
74-
})
75-
76-
applyChanges(changes)
77-
} catch (e: unknown) {
78-
console.error(e instanceof Error ? e.message : e)
79-
}
80-
81-
// include file extensions in import specifiers
82-
// https://nodejs.org/docs/latest-v16.x/api/esm.html#import-specifiers
83-
for (const file of writtenFiles) {
84-
try {
85-
/**
86-
* {@link file} content.
87-
*
88-
* @var {string} content
89-
*/
90-
let content: string = await fs.promises.readFile(file, 'utf8')
91-
92-
for (const { code, specifier } of findStaticImports(content)) {
93-
if (path.extname(specifier)) continue
94-
95-
if (/^(\w|@)/.test(specifier)) {
96-
const { path: id } = await resolveId(specifier, process.cwd(), {
97-
type: 'module'
98-
})
99-
100-
content = content.replace(
101-
code,
102-
code.replace(specifier, id.split('node_modules/')[1]!)
103-
)
104-
} else {
105-
content = content.replace(
106-
code,
107-
code.replace(specifier, specifier + '.' + entry.ext!)
108-
)
109-
}
110-
}
111-
112-
await fs.promises.writeFile(file, content)
113-
} catch (e: unknown) {
114-
console.error(e instanceof Error ? e.message : e)
115-
}
116-
}
117-
118-
return void 0
119-
},
120-
/**
121-
* Updates `mkdist` build options.
122-
*
123-
* @see https://github.com/unjs/mkdist#-usage
124-
*
125-
* @param {BuildContext} ctx - Build context
126-
* @param {MkdistBuildEntry} entry - `mkdist` build entry
127-
* @param {MkdistOptions} options - `mkdist` build options
128-
* @return {void} Nothing when complete
129-
*/
130-
'mkdist:entry:options'(
131-
ctx: BuildContext,
132-
entry: MkdistBuildEntry,
133-
options: MkdistOptions
134-
): void {
135-
options.pattern = ['**', '!**/{__mocks__,__snapshots__,__tests__}/**']
136-
}
137-
}
21+
minify: true,
22+
sourcemap: 'external',
23+
sourcesContent: false,
24+
target: [
25+
tsconfig.compilerOptions.target,
26+
'node' + pkg.engines.node.replace(/^\D+/, '')
27+
],
28+
treeShaking: true,
29+
tsconfig: 'tsconfig.build.json'
13830
})
13931

14032
export default config

package.json

+4-8
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
}
6565
},
6666
"scripts": {
67-
"build": "unbuild",
67+
"build": "mkbuild",
6868
"check:ci": "yarn dedupe --check && yarn check:format && yarn check:lint && yarn check:spelling && yarn check:types && yarn check:types:build && yarn test:cov && NODE_ENV=production yarn pack -o %s-%v.tgz && yarn clean:pack",
6969
"check:format": "prettier --check .",
7070
"check:lint": "eslint --exit-on-fatal-error --ext cjs,cts,gql,json,jsonc,md,mjs,ts,yml --max-warnings 0 .",
@@ -101,6 +101,7 @@
101101
"@commitlint/config-conventional": "17.1.0",
102102
"@commitlint/types": "17.0.0",
103103
"@faker-js/faker": "7.5.0",
104+
"@flex-development/mkbuild": "1.0.0-alpha.3",
104105
"@flex-development/tutils": "5.0.0",
105106
"@graphql-eslint/eslint-plugin": "3.11.2",
106107
"@types/chai": "4.3.3",
@@ -123,6 +124,7 @@
123124
"conventional-changelog-cli": "2.2.2",
124125
"conventional-recommended-bump": "6.1.0",
125126
"cspell": "6.10.1",
127+
"esbuild": "0.15.10",
126128
"eslint": "8.24.0",
127129
"eslint-config-prettier": "8.5.0",
128130
"eslint-plugin-chai-expect": "3.0.0",
@@ -136,7 +138,6 @@
136138
"eslint-plugin-promise": "6.0.1",
137139
"eslint-plugin-unicorn": "43.0.2",
138140
"eslint-plugin-yml": "1.2.0",
139-
"externality": "0.2.2",
140141
"graphql": "16.6.0",
141142
"graphql-config": "4.3.5",
142143
"growl": "1.10.5",
@@ -148,13 +149,11 @@
148149
"prettier": "2.7.1",
149150
"prettier-plugin-sh": "0.12.8",
150151
"pretty-format": "29.1.0",
151-
"resolve-tspaths": "0.7.4",
152152
"trash-cli": "5.0.0",
153153
"ts-dedent": "2.2.0",
154154
"ts-node": "10.9.1",
155155
"tsconfig-paths": "4.1.0",
156156
"typescript": "4.8.2",
157-
"unbuild": "0.8.9",
158157
"version-bump-prompt": "6.1.0",
159158
"vite": "3.1.4",
160159
"vite-tsconfig-paths": "3.5.1",
@@ -163,10 +162,7 @@
163162
"yaml-eslint-parser": "1.1.0"
164163
},
165164
"resolutions": {
166-
"@ardatan/sync-fetch": "larsgw/sync-fetch#head=worker_threads",
167-
"mkdist": "patch:mkdist@npm:0.3.13#.yarn/patches/mkdist-npm-0.3.13-c41cf41c68.patch",
168-
"mlly": "0.5.14",
169-
"resolve-tspaths": "patch:resolve-tspaths@npm%3A0.7.4#~/.yarn/patches/resolve-tspaths-npm-0.7.4-6fc6738fb9.patch"
165+
"@ardatan/sync-fetch": "larsgw/sync-fetch#head=worker_threads"
170166
},
171167
"engines": {
172168
"node": ">=14",

src/index.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,4 @@
33
* @module aggregate-error-ponyfill
44
*/
55

6-
import AggregateError from './ponyfill'
7-
8-
export default AggregateError
6+
export { default } from './ponyfill'

0 commit comments

Comments
 (0)