Skip to content

Commit 6c86e31

Browse files
authored
feat(refactor): Unify tsup configs, gulp -> tsup (#288)
1 parent 3d0853f commit 6c86e31

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+319
-2373
lines changed

builder/src/builders/common/simpleBuild.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,11 @@ import {
1010
import { exec } from 'child_process'
1111
import { PACKAGE_OUTPUT } from 'consts'
1212
import { promises as fs } from 'fs'
13-
import type { Bundler } from 'types'
1413
import { promisify } from 'util'
1514

1615
const execPromisify = promisify(exec)
1716

18-
export const simpleBuild = async (
19-
packageName: string,
20-
{ bundler }: { bundler: Bundler | null }
21-
) => {
17+
export const simpleBuild = async (packageName: string) => {
2218
const libDirectory = gePackageDirectory(packageName)
2319
// Validate package config
2420
try {
@@ -35,8 +31,7 @@ export const simpleBuild = async (
3531
if (
3632
!(await generatePackageJson(
3733
libDirectory,
38-
`${libDirectory}/${PACKAGE_OUTPUT}`,
39-
bundler
34+
`${libDirectory}/${PACKAGE_OUTPUT}`
4035
))
4136
) {
4237
throw `Failed to generate package.json file.`

builder/src/builders/extension-assets/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const build = async () => {
5757
}
5858

5959
// Generate package.json.
60-
if (!(await generatePackageJson('.', `${PACKAGE_OUTPUT}`, null))) {
60+
if (!(await generatePackageJson('.', `${PACKAGE_OUTPUT}`))) {
6161
throw `Failed to generate package.json file.`
6262
}
6363

builder/src/builders/util.ts

Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ SPDX-License-Identifier: GPL-3.0-only */
44
import { PACKAGE_OUTPUT, TEMP_BUILD_OUTPUT } from 'consts'
55
import fs from 'fs/promises'
66
import { dirname, join } from 'path'
7-
import type { Bundler } from 'types'
87
import { fileURLToPath } from 'url'
98

109
// Gets workspace directory from the current directory
@@ -87,15 +86,7 @@ export const getTemplate = async (name: string) => {
8786
// Generate package package.json file from source package.json
8887
export const generatePackageJson = async (
8988
inputDir: string,
90-
outputDir: string,
91-
bundler: Bundler | null,
92-
additionalExports: Record<
93-
string,
94-
{
95-
import: string
96-
require: string
97-
}
98-
> = {}
89+
outputDir: string
9990
): Promise<boolean> => {
10091
try {
10192
// Read the original package.json.
@@ -120,22 +111,17 @@ export const generatePackageJson = async (
120111

121112
// Attempt to get exports and bundler info
122113
let pkgConfig
123-
let configBundler = bundler // Use the passed bundler as fallback
124114
try {
125115
pkgConfig = JSON.parse(
126116
await fs.readFile(join(inputDir, 'pkg.config.json'), 'utf8')
127117
)
128-
// If bundler info is available in config, use it (unless explicitly overridden)
129-
if ('bundler' in pkgConfig && bundler === null) {
130-
configBundler = pkgConfig.bundler
131-
}
132118
} catch (e) {
133119
// Silently fail getting exports
134120
}
135121

136122
// Construct the minimal package.json object
137123
// eslint-disable-next-line @typescript-eslint/no-explicit-any
138-
let minimalPackageJson: any = {
124+
const minimalPackageJson: any = {
139125
name: packageName,
140126
version,
141127
license,
@@ -159,33 +145,9 @@ export const generatePackageJson = async (
159145
minimalPackageJson.bugs = bugs
160146
}
161147

162-
if (configBundler === 'gulp') {
163-
minimalPackageJson = {
164-
...minimalPackageJson,
165-
exports: pkgConfig?.exports || {
166-
'.': {
167-
import: './mjs/index.js',
168-
require: './cjs/index.js',
169-
},
170-
...additionalExports,
171-
},
172-
}
173-
} else if (configBundler === 'tsup') {
174-
minimalPackageJson = {
175-
...minimalPackageJson,
176-
exports: pkgConfig?.exports || {
177-
'.': {
178-
import: './index.js',
179-
require: './index.cjs',
180-
},
181-
...additionalExports,
182-
},
183-
}
184-
} else {
185-
// For custom bundlers, null, or any other case, include exports if provided
186-
if (pkgConfig?.exports) {
187-
minimalPackageJson.exports = pkgConfig.exports
188-
}
148+
// Include package exports if provided
149+
if (pkgConfig?.exports) {
150+
minimalPackageJson.exports = pkgConfig.exports
189151
}
190152

191153
if (dependencies) {
@@ -194,6 +156,7 @@ export const generatePackageJson = async (
194156
if (peerDependencies) {
195157
minimalPackageJson['peerDependencies'] = peerDependencies
196158
}
159+
197160
if (pkgConfig?.peerDependencies) {
198161
minimalPackageJson['peerDependencies'] = {
199162
...minimalPackageJson['peerDependencies'],

builder/src/index.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const { t: task } = args
1414

1515
switch (task) {
1616
case 'crypto':
17-
await simpleBuild('crypto', { bundler: 'tsup' })
17+
await simpleBuild('crypto')
1818
break
1919

2020
case 'directory':
@@ -30,39 +30,39 @@ switch (task) {
3030
break
3131

3232
case 'factories':
33-
await simpleBuild('factories', { bundler: 'gulp' })
33+
await simpleBuild('factories')
3434
break
3535

3636
case 'hooks':
37-
await simpleBuild('hooks', { bundler: 'gulp' })
37+
await simpleBuild('hooks')
3838
break
3939

4040
case 'observables-connect':
41-
await simpleBuild('observables-connect', { bundler: 'gulp' })
41+
await simpleBuild('observables-connect')
4242
break
4343

4444
case 'react-connect-kit':
45-
await simpleBuild('react-connect-kit', { bundler: 'gulp' })
45+
await simpleBuild('react-connect-kit')
4646
break
4747

4848
case 'react-odometer':
49-
await simpleBuild('react-odometer', { bundler: 'gulp' })
49+
await simpleBuild('react-odometer')
5050
break
5151

5252
case 'react-polkicon':
53-
await simpleBuild('react-polkicon', { bundler: 'gulp' })
53+
await simpleBuild('react-polkicon')
5454
break
5555

5656
case 'types':
57-
await simpleBuild('types', { bundler: 'tsup' })
57+
await simpleBuild('types')
5858
break
5959

6060
case 'utils':
61-
await simpleBuild('utils', { bundler: 'tsup' })
61+
await simpleBuild('utils')
6262
break
6363

6464
case 'validator-assets':
65-
await simpleBuild('validator-assets', { bundler: null })
65+
await simpleBuild('validator-assets')
6666
break
6767

6868
default:

builder/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* @license Copyright 2024 w3ux authors & contributors
22
SPDX-License-Identifier: GPL-3.0-only */
33

4-
export type Bundler = 'gulp' | 'tsup' | 'module'
4+
export type Bundler = 'tsup' | 'module'
55

66
// TypeScript interfaces for package data structures
77
export interface PackageInfoYml {

library/crypto/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@w3ux/crypto-source",
33
"description": "Cryptographic utilities for Dapps",
4-
"version": "1.1.0",
4+
"version": "1.2.1",
55
"license": "GPL-3.0-only",
66
"type": "module",
77
"keywords": [
@@ -23,7 +23,7 @@
2323
},
2424
"scripts": {
2525
"clear": "rm -rf node_modules dist tsconfig.tsbuildinfo",
26-
"build": "tsup src/**/* --format esm,cjs --target es2022 --dts --no-splitting",
26+
"build": "tsup",
2727
"compile": "builder -t crypto"
2828
},
2929
"dependencies": {

library/crypto/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"extends": "../../tsconfig.base.json",
33
"compilerOptions": {
44
"baseUrl": "src",
5-
"rootDir": "src",
5+
"rootDir": ".",
66
"outDir": "dist"
77
},
88
"include": ["./**/*"],

library/crypto/tsup.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { defineConfig } from 'tsup'
55

66
export default defineConfig({
77
entry: ['src/index.ts'],
8-
splitting: false,
9-
sourcemap: false,
8+
target: 'esnext',
9+
sourcemap: true,
1010
clean: true,
1111
dts: true,
12-
format: 'esm',
12+
format: ['esm', 'cjs']
1313
})

library/extension-assets/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"compile": "builder -t extension-assets"
3131
},
3232
"peerDependencies": {
33-
"react": "^19"
33+
"react": "^19.1.0"
3434
},
3535
"devDependencies": {
3636
"@types/react": "^19.0.12",

library/factories/gulpfile.js

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)