Skip to content

Commit 31e90c1

Browse files
committed
feat: add module option for attw and publint to allow passing imported modules directly
1 parent 375a51c commit 31e90c1

File tree

7 files changed

+29
-44
lines changed

7 files changed

+29
-44
lines changed

dts.snapshot.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"config-!~{00d}~.d.mts": {
2+
"config-!~{00c}~.d.mts": {
33
"defineConfig": "declare function defineConfig(_: UserConfigExport): UserConfigExport",
44
"mergeConfig": "declare function mergeConfig(_: InlineConfig, ...overrides: InlineConfig[]): InlineConfig",
55
"resolveUserConfig": "declare function resolveUserConfig(_: UserConfig, _: InlineConfig): Promise<ResolvedConfig[]>"
@@ -73,7 +73,7 @@
7373
"internal.d.mts": {
7474
"fsExists": "declare function fsExists(_: string): Promise<boolean>",
7575
"fsRemove": "declare function fsRemove(_: string): Promise<void>",
76-
"importWithError": "declare function importWithError<T>(_: string, _: string[]): Promise<T>",
76+
"importWithError": "declare function importWithError<T>(_: string): Promise<T>",
7777
"resolveComma": "declare function resolveComma<T extends string>(_: T[]): T[]",
7878
"toArray": "declare function toArray<T>(_: T | T[] | null | undefined, _: T): T[]",
7979
"#exports": [
@@ -87,7 +87,7 @@
8787
"toArray"
8888
]
8989
},
90-
"logger-!~{00b}~.d.mts": {
90+
"logger-!~{00a}~.d.mts": {
9191
"Arrayable": "type Arrayable<T> = T | T[]",
9292
"Awaitable": "type Awaitable<T> = T | Promise<T>",
9393
"globalLogger": "Logger",
@@ -113,8 +113,8 @@
113113
"run.d.mts": {
114114
"#exports": []
115115
},
116-
"types-!~{00c}~.d.mts": {
117-
"AttwOptions": "interface AttwOptions extends CheckPackageOptions {\n profile?: 'strict' | 'node16' | 'esm-only'\n level?: 'error' | 'warn'\n ignoreRules?: string[]\n}",
116+
"types-!~{00b}~.d.mts": {
117+
"AttwOptions": "interface AttwOptions extends CheckPackageOptions {\n module?: typeof _$_arethetypeswrong_core0\n profile?: 'strict' | 'node16' | 'esm-only'\n level?: 'error' | 'warn'\n ignoreRules?: string[]\n}",
118118
"BuildContext": "interface BuildContext {\n options: ResolvedConfig\n hooks: Hookable<TsdownHooks>\n}",
119119
"ChunkAddon": "type ChunkAddon = ChunkAddonObject | ChunkAddonFunction | string",
120120
"ChunkAddonFunction": "type ChunkAddonFunction = (_: { format: Format; fileName: string }) => ChunkAddonObject | string | undefined",
@@ -151,7 +151,7 @@
151151
"PackageJsonScriptWithPreAndPost": "type PackageJsonScriptWithPreAndPost<S extends string> = S | `${'pre' | 'post'}${S}`",
152152
"PackageJsonWithPath": "interface PackageJsonWithPath extends PackageJson {\n packageJsonPath: string\n}",
153153
"PackageType": "type PackageType = 'module' | 'commonjs' | undefined",
154-
"PublintOptions": "interface PublintOptions extends Omit<Options, 'pack' | 'pkgDir'> {}",
154+
"PublintOptions": "interface PublintOptions extends Omit<Options, 'pack' | 'pkgDir'> {\n module?: [typeof _$publint, typeof _$publint_utils0]\n}",
155155
"ReportOptions": "interface ReportOptions {\n gzip?: boolean\n brotli?: boolean\n maxCompressSize?: number\n}",
156156
"ReportPlugin": "declare function ReportPlugin(_: ResolvedConfig, _: boolean, _: boolean): Plugin",
157157
"ResolvedConfig": "type ResolvedConfig = Overwrite<MarkPartial<Omit<UserConfig, 'workspace' | 'fromVite' | 'publicDir' | 'bundle' | 'injectStyle' | 'removeNodeProtocol' | 'external' | 'noExternal' | 'inlineOnly' | 'skipNodeModulesBundle' | 'logLevel' | 'failOnWarn' | 'customLogger' | 'envFile' | 'envPrefix'>, 'globalName' | 'inputOptions' | 'outputOptions' | 'minify' | 'define' | 'alias' | 'onSuccess' | 'outExtensions' | 'hooks' | 'copy' | 'loader' | 'name' | 'banner' | 'footer' | 'checks' | 'css'>, { entry: Record<string, string>; rawEntry?: TsdownInputOption; nameLabel: string | undefined; format: NormalizedFormat; target?: string[]; clean: string[]; pkg?: PackageJsonWithPath; nodeProtocol: 'strip' | boolean; logger: Logger; ignoreWatch: Array<string | RegExp>; deps: ResolvedDepsConfig; root: string; dts: false | DtsOptions; report: false | ReportOptions; tsconfig: false | string; exports: false | ExportsOptions; devtools: false | DevtoolsOptions; publint: false | PublintOptions; attw: false | AttwOptions; unused: false | UnusedOptions; exe: false | ExeOptions }>",
@@ -163,7 +163,7 @@
163163
"TsdownBundle": "interface TsdownBundle extends AsyncDisposable {\n chunks: RolldownChunk[]\n config: ResolvedConfig\n inlinedDeps: Map<string, Set<string>>\n}",
164164
"TsdownHooks": "interface TsdownHooks {\n 'build:prepare': (_: BuildContext) => void | Promise<void>\n 'build:before': (_: BuildContext & RolldownContext) => void | Promise<void>\n 'build:done': (_: BuildContext & { chunks: RolldownChunk[] }) => void | Promise<void>\n}",
165165
"TsdownInputOption": "type TsdownInputOption = Arrayable<string | Record<string, Arrayable<string>>>",
166-
"UserConfig": "interface UserConfig {\n entry?: TsdownInputOption\n deps?: DepsConfig\n external?: ExternalOption\n noExternal?: Arrayable<string | RegExp> | NoExternalFn\n inlineOnly?: Arrayable<string | RegExp> | false\n skipNodeModulesBundle?: boolean\n alias?: Record<string, string>\n tsconfig?: string | boolean\n platform?: 'node' | 'neutral' | 'browser'\n target?: string | string[] | false\n env?: Record<string, any>\n envFile?: string\n envPrefix?: string | string[]\n define?: Record<string, string>\n shims?: boolean\n treeshake?: boolean | TreeshakingOptions\n loader?: ModuleTypes\n removeNodeProtocol?: boolean\n nodeProtocol?: 'strip' | boolean\n checks?: ChecksOptions & { legacyCjs?: boolean }\n plugins?: InputOptions['plugins']\n inputOptions?: InputOptions | ((_: InputOptions, _: NormalizedFormat, _: { cjsDts: boolean }) => Awaitable<InputOptions | void | null>)\n format?: Format | Format[] | Partial<Record<Format, Partial<ResolvedConfig>>>\n globalName?: string\n outDir?: string\n write?: boolean\n sourcemap?: Sourcemap\n clean?: boolean | string[]\n minify?: boolean | 'dce-only' | MinifyOptions\n footer?: ChunkAddon\n banner?: ChunkAddon\n unbundle?: boolean\n root?: string\n bundle?: boolean\n fixedExtension?: boolean\n outExtensions?: OutExtensionFactory\n hash?: boolean\n cjsDefault?: boolean\n outputOptions?: OutputOptions | ((_: OutputOptions, _: NormalizedFormat, _: { cjsDts: boolean }) => Awaitable<OutputOptions | void | null>)\n cwd?: string\n name?: string\n logLevel?: LogLevel\n failOnWarn?: boolean | CIOption\n customLogger?: Logger\n fromVite?: boolean | 'vitest'\n watch?: boolean | Arrayable<string>\n ignoreWatch?: Arrayable<string | RegExp>\n devtools?: WithEnabled<DevtoolsOptions>\n onSuccess?: string | ((_: ResolvedConfig, _: AbortSignal) => void | Promise<void>)\n dts?: WithEnabled<DtsOptions>\n unused?: WithEnabled<UnusedOptions>\n publint?: WithEnabled<PublintOptions>\n attw?: WithEnabled<AttwOptions>\n report?: WithEnabled<ReportOptions>\n globImport?: boolean\n exports?: WithEnabled<ExportsOptions>\n css?: _tsdown_css0.CssOptions\n injectStyle?: boolean\n publicDir?: CopyOptions | CopyOptionsFn\n copy?: CopyOptions | CopyOptionsFn\n hooks?: Partial<TsdownHooks> | ((_: Hookable<TsdownHooks>) => Awaitable<void>)\n exe?: WithEnabled<ExeOptions>\n workspace?: Workspace | Arrayable<string> | true\n}",
166+
"UserConfig": "interface UserConfig {\n entry?: TsdownInputOption\n deps?: DepsConfig\n external?: ExternalOption\n noExternal?: Arrayable<string | RegExp> | NoExternalFn\n inlineOnly?: Arrayable<string | RegExp> | false\n skipNodeModulesBundle?: boolean\n alias?: Record<string, string>\n tsconfig?: string | boolean\n platform?: 'node' | 'neutral' | 'browser'\n target?: string | string[] | false\n env?: Record<string, any>\n envFile?: string\n envPrefix?: string | string[]\n define?: Record<string, string>\n shims?: boolean\n treeshake?: boolean | TreeshakingOptions\n loader?: ModuleTypes\n removeNodeProtocol?: boolean\n nodeProtocol?: 'strip' | boolean\n checks?: ChecksOptions & { legacyCjs?: boolean }\n plugins?: InputOptions['plugins']\n inputOptions?: InputOptions | ((_: InputOptions, _: NormalizedFormat, _: { cjsDts: boolean }) => Awaitable<InputOptions | void | null>)\n format?: Format | Format[] | Partial<Record<Format, Partial<ResolvedConfig>>>\n globalName?: string\n outDir?: string\n write?: boolean\n sourcemap?: Sourcemap\n clean?: boolean | string[]\n minify?: boolean | 'dce-only' | MinifyOptions\n footer?: ChunkAddon\n banner?: ChunkAddon\n unbundle?: boolean\n root?: string\n bundle?: boolean\n fixedExtension?: boolean\n outExtensions?: OutExtensionFactory\n hash?: boolean\n cjsDefault?: boolean\n outputOptions?: OutputOptions | ((_: OutputOptions, _: NormalizedFormat, _: { cjsDts: boolean }) => Awaitable<OutputOptions | void | null>)\n cwd?: string\n name?: string\n logLevel?: LogLevel\n failOnWarn?: boolean | CIOption\n customLogger?: Logger\n fromVite?: boolean | 'vitest'\n watch?: boolean | Arrayable<string>\n ignoreWatch?: Arrayable<string | RegExp>\n devtools?: WithEnabled<DevtoolsOptions>\n onSuccess?: string | ((_: ResolvedConfig, _: AbortSignal) => void | Promise<void>)\n dts?: WithEnabled<DtsOptions>\n unused?: WithEnabled<UnusedOptions>\n publint?: WithEnabled<PublintOptions>\n attw?: WithEnabled<AttwOptions>\n report?: WithEnabled<ReportOptions>\n globImport?: boolean\n exports?: WithEnabled<ExportsOptions>\n css?: _$_tsdown_css0.CssOptions\n injectStyle?: boolean\n publicDir?: CopyOptions | CopyOptionsFn\n copy?: CopyOptions | CopyOptionsFn\n hooks?: Partial<TsdownHooks> | ((_: Hookable<TsdownHooks>) => Awaitable<void>)\n exe?: WithEnabled<ExeOptions>\n workspace?: Workspace | Arrayable<string> | true\n}",
167167
"UserConfigExport": "type UserConfigExport = Awaitable<Arrayable<UserConfig> | UserConfigFn>",
168168
"UserConfigFn": "type UserConfigFn = (_: InlineConfig, _: { ci: boolean; rootConfig?: UserConfig }) => Awaitable<Arrayable<UserConfig>>",
169169
"WithEnabled": "type WithEnabled<T> = boolean | undefined | CIOption | (T & { enabled?: boolean | CIOption })",

pnpm-lock.yaml

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ catalogs:
7777
picomatch: ^4.0.4
7878
postcss-load-config: ^6.0.1
7979
rolldown: 1.0.0-rc.12
80-
rolldown-plugin-dts: ^0.23.0
80+
rolldown-plugin-dts: ^0.23.1
8181
semver: ^7.7.4
8282
tinyexec: ^1.0.4
8383
tinyglobby: ^0.2.15

src/features/pkg/attw.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ const problemFlags: Record<ProblemKind, string> = {
2929
}
3030

3131
export interface AttwOptions extends CheckPackageOptions {
32-
/** @internal */
33-
resolvePaths?: string[]
32+
module?: typeof import('@arethetypeswrong/core')
3433

3534
/**
3635
* Profiles select a set of resolution modes to require/ignore. All are evaluated but failures outside
@@ -120,9 +119,11 @@ export async function attw(
120119
const t = performance.now()
121120
debug('Running attw check')
122121

123-
const attwCore = await importWithError<
124-
typeof import('@arethetypeswrong/core')
125-
>('@arethetypeswrong/core', options.attw.resolvePaths)
122+
const attwCore =
123+
options.attw.module ||
124+
(await importWithError<typeof import('@arethetypeswrong/core')>(
125+
'@arethetypeswrong/core',
126+
))
126127

127128
const pkg = attwCore.createPackageFromTarballData(tarball)
128129
const checkResult = await attwCore.checkPackage(pkg, attwOptions)

src/features/pkg/publint.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ const debug = createDebug('tsdown:publint')
99
const label = dim`[publint]`
1010

1111
export interface PublintOptions extends Omit<Options, 'pack' | 'pkgDir'> {
12-
/** @internal */
13-
resolvePaths?: string[]
12+
module?: [typeof import('publint'), typeof import('publint/utils')]
1413
}
1514

1615
export async function publint(
@@ -29,13 +28,12 @@ export async function publint(
2928
const t = performance.now()
3029
debug('Running publint')
3130

32-
const { publint } = await importWithError<typeof import('publint')>(
33-
'publint',
34-
options.publint.resolvePaths,
35-
)
36-
const { formatMessage } = await importWithError<
37-
typeof import('publint/utils')
38-
>('publint/utils', options.publint.resolvePaths)
31+
const { publint } =
32+
options.publint.module?.[0] ||
33+
(await importWithError<typeof import('publint')>('publint'))
34+
const { formatMessage } =
35+
options.publint.module?.[1] ||
36+
(await importWithError<typeof import('publint/utils')>('publint/utils'))
3937

4038
const { messages } = await publint({
4139
...options.publint,

src/utils/general.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { pathToFileURL } from 'node:url'
21
import picomatch from 'picomatch'
32

43
export function toArray<T>(
@@ -58,19 +57,9 @@ export function pkgExists(moduleName: string): boolean {
5857
return false
5958
}
6059

61-
export async function importWithError<T>(
62-
moduleName: string,
63-
resolvePaths?: string[],
64-
): Promise<T> {
65-
let resolved: string | undefined
66-
if (resolvePaths) {
67-
resolved = pathToFileURL(
68-
require.resolve(moduleName, { paths: resolvePaths }),
69-
).href
70-
}
71-
60+
export async function importWithError<T>(moduleName: string): Promise<T> {
7261
try {
73-
return (await import(resolved || moduleName)) as T
62+
return (await import(moduleName)) as T
7463
} catch (error) {
7564
const final = new Error(
7665
`Failed to import module "${moduleName}". Please ensure it is installed.`,

tsdown.config.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ export default defineConfig([
5151
transformer: [RemoveNode((node) => isCallOf(node, 'typeAssert'))],
5252
}),
5353
],
54-
onSuccess() {
55-
console.info('🙏 Build succeeded!')
56-
},
5754
},
5855
{
5956
workspace: {

0 commit comments

Comments
 (0)