Skip to content
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions builder/src/builders/common/simpleBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,11 @@ import {
import { exec } from 'child_process'
import { PACKAGE_OUTPUT } from 'consts'
import { promises as fs } from 'fs'
import type { Bundler } from 'types'
import { promisify } from 'util'

const execPromisify = promisify(exec)

export const simpleBuild = async (
packageName: string,
{ bundler }: { bundler: Bundler | null }
) => {
export const simpleBuild = async (packageName: string) => {
const libDirectory = gePackageDirectory(packageName)
// Validate package config
try {
Expand All @@ -35,8 +31,7 @@ export const simpleBuild = async (
if (
!(await generatePackageJson(
libDirectory,
`${libDirectory}/${PACKAGE_OUTPUT}`,
bundler
`${libDirectory}/${PACKAGE_OUTPUT}`
))
) {
throw `Failed to generate package.json file.`
Expand Down
2 changes: 1 addition & 1 deletion builder/src/builders/extension-assets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const build = async () => {
}

// Generate package.json.
if (!(await generatePackageJson('.', `${PACKAGE_OUTPUT}`, null))) {
if (!(await generatePackageJson('.', `${PACKAGE_OUTPUT}`))) {
throw `Failed to generate package.json file.`
}

Expand Down
49 changes: 6 additions & 43 deletions builder/src/builders/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ SPDX-License-Identifier: GPL-3.0-only */
import { PACKAGE_OUTPUT, TEMP_BUILD_OUTPUT } from 'consts'
import fs from 'fs/promises'
import { dirname, join } from 'path'
import type { Bundler } from 'types'
import { fileURLToPath } from 'url'

// Gets workspace directory from the current directory
Expand Down Expand Up @@ -87,15 +86,7 @@ export const getTemplate = async (name: string) => {
// Generate package package.json file from source package.json
export const generatePackageJson = async (
inputDir: string,
outputDir: string,
bundler: Bundler | null,
additionalExports: Record<
string,
{
import: string
require: string
}
> = {}
outputDir: string
): Promise<boolean> => {
try {
// Read the original package.json.
Expand All @@ -120,22 +111,17 @@ export const generatePackageJson = async (

// Attempt to get exports and bundler info
let pkgConfig
let configBundler = bundler // Use the passed bundler as fallback
try {
pkgConfig = JSON.parse(
await fs.readFile(join(inputDir, 'pkg.config.json'), 'utf8')
)
// If bundler info is available in config, use it (unless explicitly overridden)
if ('bundler' in pkgConfig && bundler === null) {
configBundler = pkgConfig.bundler
}
} catch (e) {
// Silently fail getting exports
}

// Construct the minimal package.json object
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let minimalPackageJson: any = {
const minimalPackageJson: any = {
name: packageName,
version,
license,
Expand All @@ -159,33 +145,9 @@ export const generatePackageJson = async (
minimalPackageJson.bugs = bugs
}

if (configBundler === 'gulp') {
minimalPackageJson = {
...minimalPackageJson,
exports: pkgConfig?.exports || {
'.': {
import: './mjs/index.js',
require: './cjs/index.js',
},
...additionalExports,
},
}
} else if (configBundler === 'tsup') {
minimalPackageJson = {
...minimalPackageJson,
exports: pkgConfig?.exports || {
'.': {
import: './index.js',
require: './index.cjs',
},
...additionalExports,
},
}
} else {
// For custom bundlers, null, or any other case, include exports if provided
if (pkgConfig?.exports) {
minimalPackageJson.exports = pkgConfig.exports
}
// Include package exports if provided
if (pkgConfig?.exports) {
minimalPackageJson.exports = pkgConfig.exports
}

if (dependencies) {
Expand All @@ -194,6 +156,7 @@ export const generatePackageJson = async (
if (peerDependencies) {
minimalPackageJson['peerDependencies'] = peerDependencies
}

if (pkgConfig?.peerDependencies) {
minimalPackageJson['peerDependencies'] = {
...minimalPackageJson['peerDependencies'],
Expand Down
20 changes: 10 additions & 10 deletions builder/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const { t: task } = args

switch (task) {
case 'crypto':
await simpleBuild('crypto', { bundler: 'tsup' })
await simpleBuild('crypto')
break

case 'directory':
Expand All @@ -30,39 +30,39 @@ switch (task) {
break

case 'factories':
await simpleBuild('factories', { bundler: 'gulp' })
await simpleBuild('factories')
break

case 'hooks':
await simpleBuild('hooks', { bundler: 'gulp' })
await simpleBuild('hooks')
break

case 'observables-connect':
await simpleBuild('observables-connect', { bundler: 'gulp' })
await simpleBuild('observables-connect')
break

case 'react-connect-kit':
await simpleBuild('react-connect-kit', { bundler: 'gulp' })
await simpleBuild('react-connect-kit')
break

case 'react-odometer':
await simpleBuild('react-odometer', { bundler: 'gulp' })
await simpleBuild('react-odometer')
break

case 'react-polkicon':
await simpleBuild('react-polkicon', { bundler: 'gulp' })
await simpleBuild('react-polkicon')
break

case 'types':
await simpleBuild('types', { bundler: 'tsup' })
await simpleBuild('types')
break

case 'utils':
await simpleBuild('utils', { bundler: 'tsup' })
await simpleBuild('utils')
break

case 'validator-assets':
await simpleBuild('validator-assets', { bundler: null })
await simpleBuild('validator-assets')
break

default:
Expand Down
2 changes: 1 addition & 1 deletion builder/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* @license Copyright 2024 w3ux authors & contributors
SPDX-License-Identifier: GPL-3.0-only */

export type Bundler = 'gulp' | 'tsup' | 'module'
export type Bundler = 'tsup' | 'module'

// TypeScript interfaces for package data structures
export interface PackageInfoYml {
Expand Down
4 changes: 2 additions & 2 deletions library/crypto/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@w3ux/crypto-source",
"description": "Cryptographic utilities for Dapps",
"version": "1.1.0",
"version": "1.2.1",
"license": "GPL-3.0-only",
"type": "module",
"keywords": [
Expand All @@ -23,7 +23,7 @@
},
"scripts": {
"clear": "rm -rf node_modules dist tsconfig.tsbuildinfo",
"build": "tsup src/**/* --format esm,cjs --target es2022 --dts --no-splitting",
"build": "tsup",
"compile": "builder -t crypto"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion library/crypto/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"baseUrl": "src",
"rootDir": "src",
"rootDir": ".",
"outDir": "dist"
},
"include": ["./**/*"],
Expand Down
6 changes: 3 additions & 3 deletions library/crypto/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { defineConfig } from 'tsup'

export default defineConfig({
entry: ['src/index.ts'],
splitting: false,
sourcemap: false,
target: 'esnext',
sourcemap: true,
clean: true,
dts: true,
format: 'esm',
format: ['esm', 'cjs']
})
2 changes: 1 addition & 1 deletion library/extension-assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"compile": "builder -t extension-assets"
},
"peerDependencies": {
"react": "^19"
"react": "^19.1.0"
},
"devDependencies": {
"@types/react": "^19.0.12",
Expand Down
40 changes: 0 additions & 40 deletions library/factories/gulpfile.js

This file was deleted.

16 changes: 4 additions & 12 deletions library/factories/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@w3ux/factories-source",
"description": "A collection of general purpose TypeScript factories",
"version": "2.1.1",
"version": "2.2.1",
"license": "GPL-3.0-only",
"type": "module",
"keywords": [
Expand All @@ -23,22 +23,14 @@
},
"scripts": {
"clear": "rm -rf node_modules dist tsconfig.tsbuildinfo",
"build": "gulp --silent",
"build": "tsup",
"compile": "builder -t factories"
},
"peerDependencies": {
"react": "^19"
},
"devDependencies": {
"@types/react": "^19.0.12",
"@w3ux/types": "^2.3.0",
"@w3ux/types": "^2.4.1",
"builder": "workspace:*",
"gulp": "^5.0.0",
"gulp-sourcemaps": "^3.0.0",
"gulp-strip-comments": "^2.6.0",
"gulp-typescript": "6.0.0-alpha.1",
"merge-stream": "^2.0.0",
"react": "^19.1.0",
"typescript": "^5.8.2"
"tsup": "^8.4.0"
}
}
9 changes: 6 additions & 3 deletions library/factories/pkg.config.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"bundler": "gulp",
"bundler": "tsup",
"exports": {
".": {
"import": "./mjs/index.js",
"require": "./cjs/index.js"
"import": "./index.js",
"require": "./index.cjs"
}
},
"peerDependencies": {
"react": "^19.1.0"
}
}
2 changes: 1 addition & 1 deletion library/factories/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"baseUrl": "src",
"rootDir": "src",
"rootDir": ".",
"outDir": "dist"
},
"include": ["src/**/*"],
Expand Down
13 changes: 13 additions & 0 deletions library/factories/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* @license Copyright 2024 w3ux authors & contributors
SPDX-License-Identifier: GPL-3.0-only */

import { defineConfig } from 'tsup'

export default defineConfig({
entry: ['src/index.tsx'],
target: 'esnext',
sourcemap: true,
clean: true,
dts: true,
format: ['esm', 'cjs'],
})
Loading