Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
51 changes: 0 additions & 51 deletions config/plugins/rolldown/clean-stray-declarations-plugin.ts

This file was deleted.

42 changes: 0 additions & 42 deletions config/plugins/rolldown/resolveCoreImportsPlugin.ts

This file was deleted.

8 changes: 0 additions & 8 deletions config/polyfills-node.ts

This file was deleted.

221 changes: 24 additions & 197 deletions tsdown.config.mts
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
import fs from 'node:fs'
import * as path from 'node:path'
import { defineConfig, type UserConfig } from 'tsdown'
import * as glob from 'glob'
import {
getWorkerChecksum,
copyWorkerPlugin,
} from './config/plugins/rolldown/copyWorkerPlugin.ts'
import { resolveCoreImportsPlugin } from './config/plugins/rolldown/resolveCoreImportsPlugin.ts'
import { cleanStrayDeclarationsPlugin } from './config/plugins/rolldown/clean-stray-declarations-plugin.ts'

const packageJson = JSON.parse(
fs.readFileSync(new URL('./package.json', import.meta.url), 'utf8'),
) as { dependencies: Record<string, string> }

const ecosystemDependencies = /^@mswjs\/(.+)$/
const mswCore = /#core(\/.+)?$/
const mswHttp = /#http(\/.+)?$/
const mswGraphql = /#graphql(\/.+)?$/
const mswWs = /#ws(\/.+)?$/
const SERVICE_WORKER_CHECKSUM = getWorkerChecksum()

const commonConfig = {
Expand All @@ -28,200 +21,39 @@ const commonConfig = {
clean: false,
} satisfies UserConfig

const coreConfig: UserConfig = {
const esmConfig: UserConfig = {
...commonConfig,
name: 'core',
name: 'esm',
platform: 'neutral',
entry: glob.sync('./src/core/**/*.ts', {
ignore: '**/*.test.ts',
posix: true,
dotRelative: true,
}),
deps: {
neverBundle: [mswHttp, mswGraphql, mswWs, ecosystemDependencies],
onlyBundle: false,
},
format: ['esm'],
outDir: './lib/core',
unbundle: true,
sourcemap: true,
dts: true,
tsconfig: path.resolve(import.meta.dirname, 'src/tsconfig.core.build.json'),
plugins: [
resolveCoreImportsPlugin(),
cleanStrayDeclarationsPlugin(),
],
}

const graphqlConfig: UserConfig = {
...commonConfig,
name: 'graphql',
platform: 'neutral',
entry: glob.sync('./src/graphql/**/*.ts', {
ignore: '**/*.test.ts',
posix: true,
dotRelative: true,
}),
deps: {
neverBundle: [mswCore, mswHttp, mswGraphql, mswWs, ecosystemDependencies],
onlyBundle: false,
},
format: ['esm'],
outDir: './lib/graphql',
unbundle: true,
sourcemap: true,
dts: true,
tsconfig: path.resolve(import.meta.dirname, 'src/tsconfig.core.build.json'),
plugins: [
resolveCoreImportsPlugin(),
cleanStrayDeclarationsPlugin(),
],
}

const httpConfig: UserConfig = {
...commonConfig,
name: 'http',
platform: 'neutral',
entry: glob.sync('./src/http/**/*.ts', {
ignore: '**/*.test.ts',
posix: true,
dotRelative: true,
}),
deps: {
neverBundle: [mswCore, mswHttp, mswGraphql, mswWs, ecosystemDependencies],
onlyBundle: false,
entry: {
'core/index': './src/core/index.ts',
'core/experimental/index': './src/core/experimental/index.ts',
'http/index': './src/http/index.ts',
'graphql/index': './src/graphql/index.ts',
'ws/index': './src/ws/index.ts',
'node/index': './src/node/index.ts',
'native/index': './src/native/index.ts',
'browser/index': './src/browser/index.ts',
},
format: ['esm'],
outDir: './lib/http',
unbundle: true,
sourcemap: true,
dts: true,
tsconfig: path.resolve(import.meta.dirname, 'src/tsconfig.core.build.json'),
plugins: [
resolveCoreImportsPlugin(),
cleanStrayDeclarationsPlugin(),
],
}

const wsConfig: UserConfig = {
...commonConfig,
name: 'ws',
platform: 'neutral',
entry: glob.sync('./src/ws/**/*.ts', {
ignore: '**/*.test.ts',
posix: true,
dotRelative: true,
}),
deps: {
neverBundle: [mswCore, mswHttp, mswGraphql, mswWs, ecosystemDependencies],
neverBundle: ['util', 'events', /^node:/, ecosystemDependencies],
onlyBundle: false,
},
format: ['esm'],
outDir: './lib/ws',
unbundle: true,
sourcemap: true,
dts: true,
tsconfig: path.resolve(import.meta.dirname, 'src/tsconfig.core.build.json'),
plugins: [
resolveCoreImportsPlugin(),
cleanStrayDeclarationsPlugin(),
],
}

const nodeConfig: UserConfig = {
...commonConfig,
name: 'node',
platform: 'node',
entry: ['./src/node/index.ts'],
inputOptions: {
transform: {
inject: {
setTimeout: ['./config/polyfills-node.ts', 'setTimeout'],
},
},
},
deps: {
neverBundle: [mswCore, mswHttp, mswGraphql, mswWs, ecosystemDependencies],
onlyBundle: false,
},
format: ['esm'],
outDir: './lib/node',
outDir: './lib',
unbundle: false,
outputOptions: {
codeSplitting: false,
entryFileNames: '[name].js',
chunkFileNames: '_chunks/[name].js',
codeSplitting: true,
},
sourcemap: true,
dts: true,
tsconfig: path.resolve(import.meta.dirname, 'src/tsconfig.node.build.json'),
plugins: [
resolveCoreImportsPlugin(),
cleanStrayDeclarationsPlugin(),
],
}

const browserConfig: UserConfig = {
...commonConfig,
name: 'browser',
platform: 'browser',
entry: ['./src/browser/index.ts'],
deps: {
neverBundle: [mswCore, mswHttp, mswGraphql, mswWs, ecosystemDependencies],
alwaysBundle: Object.keys(packageJson.dependencies).filter(
(packageName) => {
return !ecosystemDependencies.test(packageName)
},
),
onlyBundle: false,
},
format: ['esm'],
outDir: './lib/browser',
unbundle: false,
outputOptions: {
codeSplitting: false,
},
sourcemap: true,
dts: true,
tsconfig: path.resolve(import.meta.dirname, 'src/browser/tsconfig.browser.build.json'),
tsconfig: path.resolve(import.meta.dirname, 'src/tsconfig.core.build.json'),
define: {
SERVICE_WORKER_CHECKSUM: JSON.stringify(SERVICE_WORKER_CHECKSUM),
},
plugins: [
resolveCoreImportsPlugin(),
copyWorkerPlugin(SERVICE_WORKER_CHECKSUM),
cleanStrayDeclarationsPlugin(),
],
}

const reactNativeConfig: UserConfig = {
...commonConfig,
name: 'react-native',
platform: 'node',
entry: ['./src/native/index.ts'],
deps: {
neverBundle: [
'util',
'events',
mswCore,
mswHttp,
mswGraphql,
mswWs,
ecosystemDependencies,
],
onlyBundle: false,
},
format: ['esm'],
outDir: './lib/native',
unbundle: false,
outputOptions: {
codeSplitting: false,
},
sourcemap: true,
dts: true,
tsconfig: path.resolve(import.meta.dirname, 'src/tsconfig.node.build.json'),
plugins: [
resolveCoreImportsPlugin(),
cleanStrayDeclarationsPlugin(),
],
plugins: [copyWorkerPlugin(SERVICE_WORKER_CHECKSUM)],
}

const iifeConfig: UserConfig = {
Expand Down Expand Up @@ -250,19 +82,14 @@ const iifeConfig: UserConfig = {
},
sourcemap: true,
dts: false,
tsconfig: path.resolve(import.meta.dirname, 'src/browser/tsconfig.browser.build.json'),
tsconfig: path.resolve(
import.meta.dirname,
'src/browser/tsconfig.browser.build.json',
),
define: {
SERVICE_WORKER_CHECKSUM: JSON.stringify(SERVICE_WORKER_CHECKSUM),
},
}

export default defineConfig([
coreConfig,
httpConfig,
graphqlConfig,
wsConfig,
nodeConfig,
reactNativeConfig,
browserConfig,
iifeConfig,
])
export default defineConfig([esmConfig, iifeConfig])

Loading