Skip to content

Commit b3d5c2b

Browse files

11 files changed

+148
-1074
lines changed

Diff for: .cspell.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"patches/",
2828
"yarn.lock"
2929
],
30-
"ignoreRegExpList": [],
30+
"ignoreRegExpList": ["/from\\s+(['\"]).*\\1/"],
3131
"ignoreWords": [],
3232
"language": "en-US",
3333
"patterns": [],

Diff for: .dictionary.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ larsgw
2929
lcov
3030
lintstagedrc
3131
micnncim
32-
mkdist
32+
mkbuild
3333
nocheck
3434
npmrc
3535
nums
@@ -40,7 +40,6 @@ preid
4040
safecrlf
4141
syncer
4242
tsnode
43-
tspaths
4443
vates
4544
vitest
4645
vsicons

Diff for: .eslintrc.cjs

-18
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,6 @@ const config = {
1818
rules: {
1919
'unicorn/no-process-exit': 0
2020
}
21-
},
22-
{
23-
files: ['src/index.ts'],
24-
rules: {
25-
/**
26-
* mkdist converts `exports.default` to `module.exports = _default`.
27-
*
28-
* `exports.default` statements are only output if `export default ...`
29-
* is used for default exports.
30-
*
31-
* this means that `export { default } from '...'` should **not** be
32-
* used where default exports should be supported, as with the package
33-
* entry point.
34-
*
35-
* @see https://github.com/unjs/mkdist/blob/v0.3.13/src/loaders/js.ts#L40
36-
*/
37-
'unicorn/prefer-export-from': 0
38-
}
3921
}
4022
]
4123
}

Diff for: .github/workflows/ci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ on:
1919
- main
2020
workflow_dispatch:
2121
permissions:
22+
contents: read
2223
packages: read
2324
env:
2425
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
[![conventional commits](https://img.shields.io/badge/conventional%20commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
44
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
5+
[![module type: esm](https://img.shields.io/badge/module%20type-esm-brightgreen)](https://github.com/voxpelli/badges-cjs-esm)
56
[![npm](https://img.shields.io/npm/v/@flex-development/dist-tag.svg)](https://npmjs.com/package/@flex-development/dist-tag)
67
[![license](https://img.shields.io/github/license/flex-development/dist-tag.svg)](LICENSE.md)
78
[![typescript](https://badgen.net/badge/-/typescript?color=2a72bc&icon=typescript&label)](https://typescriptlang.org)

Diff for: build.config.ts

+20-126
Original file line numberDiff line numberDiff line change
@@ -1,135 +1,29 @@
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
55
*/
66

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

24-
/** @const {BuildConfig} config - Build config */
25-
const config: BuildConfig = defineBuildConfig({
26-
devDependencies: Object.keys(pkg.devDependencies),
10+
/**
11+
* Build configuration options.
12+
*
13+
* @const {Config} config
14+
*/
15+
const config: Config = defineBuildConfig({
2716
entries: [
28-
{
29-
builder: 'mkdist',
30-
declaration: true,
31-
ext: 'cjs',
32-
format: 'cjs',
33-
input: 'src/'
34-
},
35-
{
36-
builder: 'mkdist',
37-
declaration: true,
38-
ext: 'mjs',
39-
format: 'esm',
40-
input: 'src/'
41-
},
42-
{ builder: 'mkdist', declaration: true, input: 'src/' },
43-
{ builder: 'rollup', declaration: false, input: 'src/cli' }
17+
{ declaration: true, ignore: ['cli.ts'] },
18+
{ bundle: true, minify: true, source: 'src/cli.ts' }
4419
],
45-
hooks: {
46-
/**
47-
* Transforms path aliases found in build files.
48-
*
49-
* @param {BuildContext} ctx - Build context
50-
* @param {BuildOptions} ctx.options - Build options
51-
* @return {void} Nothing when complete
52-
*/
53-
'mkdist:done'({ options }: BuildContext): void {
54-
const { outDir, rootDir } = options
55-
56-
try {
57-
const { paths = {} } = loadTSConfig(`${rootDir}/tsconfig.json`).options
58-
59-
/** @const {string[]} files - Build files to process */
60-
const files: string[] = getFilesToProcess(outDir, [
61-
'cjs',
62-
'd.cts',
63-
'd.mts',
64-
'd.ts',
65-
'mjs'
66-
])
67-
68-
/** @const {Alias[]} aliases - Path alias objects */
69-
const aliases: Alias[] = computeAliases(rootDir, paths)
70-
71-
/**
72-
* Changes to apply to build files.
73-
*
74-
* @const {Change[]} changes
75-
*/
76-
const changes: Change[] = generateChanges(files, aliases, {
77-
outPath: outDir,
78-
srcPath: path.resolve('src')
79-
}).map(({ file, text, ...rest }) => {
80-
/** @const {string} ext - {@link file} extension */
81-
const ext: string = path.extname(file)
82-
83-
/**
84-
* Text changes applied to {@link file}.
85-
*
86-
* Each change in {@link rest.changes} will be updated to include the
87-
* current file extension, {@link ext}.
88-
*
89-
* @const {TextChange[]} changes
90-
*/
91-
const changes: TextChange[] = (rest.changes ?? []).map(chg => ({
92-
...chg,
93-
modified: !/node_modules/.test(path.resolve(file, chg.modified))
94-
? chg.modified + ext
95-
: chg.modified
96-
}))
97-
98-
// make sure file extensions are included in path transformations
99-
for (const { modified } of changes) {
100-
text = text.replace(modified.replace(ext, ''), modified)
101-
}
102-
103-
return { changes, file, text }
104-
})
105-
106-
return void applyChanges(changes)
107-
} catch (e: unknown) {
108-
console.error(e instanceof Error ? e.message : e)
109-
}
110-
},
111-
/**
112-
* Updates `mkdist` build options.
113-
*
114-
* @see https://github.com/unjs/mkdist#-usage
115-
*
116-
* @param {BuildContext} _ - Build context
117-
* @param {MkdistBuildEntry} __ - `mkdist` build entry
118-
* @param {MkdistOptions} options - `mkdist` build options
119-
* @return {void} Nothing when complete
120-
*/
121-
'mkdist:entry:options'(_, __, options: MkdistOptions): void {
122-
options.pattern = ['**', '!**/{__mocks__,__snapshots__,__tests__}/**']
123-
}
124-
},
125-
rollup: {
126-
cjsBridge: true,
127-
commonjs: { extensions: ['.cjs', '.js'] },
128-
emitCJS: true,
129-
esbuild: { logLevel: 'info', minify: true, target: 'esnext' },
130-
inlineDependencies: true,
131-
json: { compact: true },
132-
resolve: {}
20+
esbuild: {
21+
platform: 'node',
22+
sourcemap: 'external',
23+
sourcesContent: false,
24+
target: [tsconfig.compilerOptions.target, 'node14'],
25+
treeShaking: true,
26+
tsconfig: 'tsconfig.build.json'
13327
}
13428
})
13529

Diff for: package.json

+15-25
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,25 @@
3030
"dist",
3131
"src"
3232
],
33-
"bin": {
34-
"dist-tag": "./dist/cli.cjs",
35-
"dist-tag-esm": "./dist/cli.mjs"
36-
},
33+
"bin": "./dist/cli.mjs",
3734
"exports": {
38-
".": {
39-
"types": "./dist/index.d.ts",
40-
"import": "./dist/index.mjs",
41-
"require": "./dist/index.cjs"
42-
},
43-
"./flags": {
44-
"types": "./dist/flags.d.ts",
45-
"import": "./dist/flags.mjs",
46-
"require": "./dist/flags.cjs"
47-
},
48-
"./options": {
49-
"types": "./dist/options.d.ts",
50-
"import": "./dist/options.mjs",
51-
"require": "./dist/options.cjs"
52-
},
35+
".": "./dist/index.mjs",
36+
"./flags": "./dist/flags.mjs",
37+
"./options": "./dist/options.mjs",
5338
"./package.json": "./package.json"
5439
},
55-
"main": "./dist/index.cjs",
5640
"module": "./dist/index.mjs",
57-
"types": "./dist/index.d.ts",
41+
"types": "./dist/index.d.mts",
42+
"typesVersions": {
43+
"*": {
44+
"*": [
45+
"./dist/*.d.mts",
46+
"./dist/index.d.mts"
47+
]
48+
}
49+
},
5850
"scripts": {
59-
"build": "unbuild",
51+
"build": "mkbuild",
6052
"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",
6153
"check:format": "prettier --check .",
6254
"check:lint": "eslint --exit-on-fatal-error --ext cjs,cts,gql,json,jsonc,md,mjs,ts,yml --max-warnings 0 .",
@@ -90,6 +82,7 @@
9082
"@commitlint/config-conventional": "17.0.3",
9183
"@commitlint/types": "17.0.0",
9284
"@faker-js/faker": "7.4.0",
85+
"@flex-development/mkbuild": "flex-development/mkbuild",
9386
"@flex-development/tutils": "5.0.0-dev.1",
9487
"@graphql-eslint/eslint-plugin": "3.10.7",
9588
"@jsdevtools/chai-exec": "2.1.1",
@@ -141,14 +134,12 @@
141134
"prettier": "2.7.1",
142135
"prettier-plugin-sh": "0.12.8",
143136
"pretty-format": "28.1.3",
144-
"resolve-tspaths": "0.7.4",
145137
"sade": "1.8.1",
146138
"trash-cli": "5.0.0",
147139
"ts-dedent": "2.2.0",
148140
"ts-node": "10.9.1",
149141
"tsconfig-paths": "4.1.0",
150142
"typescript": "4.8.2",
151-
"unbuild": "0.8.8",
152143
"version-bump-prompt": "6.1.0",
153144
"vite-tsconfig-paths": "3.5.0",
154145
"vitest": "0.21.1",
@@ -158,7 +149,6 @@
158149
"resolutions": {
159150
"@ardatan/sync-fetch": "larsgw/sync-fetch#head=worker_threads",
160151
"graphql-config": "patch:graphql-config@npm%3A4.3.5#patches/graphql-config+4.3.5.dev.patch",
161-
"mkdist": "patch:mkdist@npm:0.3.13#patches/mkdist-npm-0.3.13-c41cf41c68.patch",
162152
"typescript": "4.8.2",
163153
"vite": "3.1.3"
164154
},

Diff for: patches/mkdist-npm-0.3.13-c41cf41c68.patch

-39
This file was deleted.

Diff for: src/cli.ts

+2-33
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,13 @@
66
*/
77

88
import type mri from 'mri'
9-
import path from 'node:path'
109
import sade from 'sade'
1110
import pkg from '../package.json' assert { type: 'json' }
1211
import type Flags from './flags'
1312
import lookup from './node'
1413

15-
/* c8 ignore start */
16-
17-
/**
18-
* CLI filename.
19-
*
20-
* @const {string} filename
21-
*/
22-
const filename: string = process.argv[1] ?? ''
23-
24-
/**
25-
* CLI program name.
26-
*
27-
* @var {string} name
28-
*/
29-
let name: string = 'dist-tag'
30-
31-
// update cli program name if running esm-compatible cli
32-
if (/dist-tag-esm/.test(filename) || path.extname(filename) === '.mjs') {
33-
name = 'dist-tag-esm'
34-
}
35-
36-
/**
37-
* CLI program.
38-
*
39-
* @see https://github.com/lukeed/sade#single-command-mode
40-
*
41-
* @const {sade.Sade} program
42-
*/
43-
const program: sade.Sade = sade([name, '[target]'].join(' '))
44-
45-
program
46-
.version(pkg.version) /* c8 ignore stop */
14+
sade(`${pkg.name.replace(/.*\//, '')} [target]`)
15+
.version(pkg.version)
4716
.describe(pkg.description)
4817
.example('2.0.0')
4918
.example('2.0.0-alpha.1')

Diff for: src/index.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
* @module dist-tag
44
*/
55

6-
import lookup from './node'
7-
86
export type { default as Flags } from './flags'
7+
export { default } from './node'
98
export type { default as Options } from './options'
10-
export default lookup

0 commit comments

Comments
 (0)