diff --git a/build.config.ts b/build.config.ts index 9f691e7d..d3af402e 100644 --- a/build.config.ts +++ b/build.config.ts @@ -6,6 +6,7 @@ export default { 'src/cli' ], dependencies: [ - 'esbuild' + 'esbuild', + 'typescript' ] } diff --git a/src/build.ts b/src/build.ts index cc6a4367..4acdd997 100644 --- a/src/build.ts +++ b/src/build.ts @@ -37,6 +37,7 @@ export async function build (rootDir: string, stub: boolean) { outDir: 'dist', genDir: '.gen', untyped: undefined, + declaration: undefined, clean: true, stub, buildEntries: [], @@ -57,6 +58,9 @@ export async function build (rootDir: string, stub: boolean) { if (!entry.builder) { entry.builder = entry.input.endsWith('/') ? 'mkdist' : 'rollup' } + if (ctx.declaration !== undefined && entry.declaration === undefined) { + entry.declaration = ctx.declaration + } } // Add dependencies from package.json as externals diff --git a/src/builder/mkdist.ts b/src/builder/mkdist.ts index dd78b1c3..d85b6522 100644 --- a/src/builder/mkdist.ts +++ b/src/builder/mkdist.ts @@ -16,7 +16,7 @@ export async function mkdistBuild (ctx: BuildContext) { distDir: join(ctx.outDir, entry.name), format: entry.format, cleanDist: false, - declaration: true + declaration: entry.declaration }) ctx.buildEntries.push({ path: join(ctx.outDir, entry.name), diff --git a/src/builder/rollup.ts b/src/builder/rollup.ts index 3cdd681c..fe4eb478 100644 --- a/src/builder/rollup.ts +++ b/src/builder/rollup.ts @@ -45,15 +45,17 @@ export async function rollupBuild (ctx: BuildContext) { } // Types - rollupOptions.plugins = rollupOptions.plugins || [] - rollupOptions.plugins.push(dts({ - respectExternal: true - })) - const typesBuild = await rollup(rollupOptions) - await typesBuild.write({ - dir: resolve(ctx.rootDir, ctx.outDir), - format: 'esm' - }) + if (ctx.declaration) { + rollupOptions.plugins = rollupOptions.plugins || [] + rollupOptions.plugins.push(dts({ + respectExternal: true + })) + const typesBuild = await rollup(rollupOptions) + await typesBuild.write({ + dir: resolve(ctx.rootDir, ctx.outDir), + format: 'esm' + }) + } } export function getRollupOptions (ctx: BuildContext): RollupOptions { @@ -103,8 +105,9 @@ export function getRollupOptions (ctx: BuildContext): RollupOptions { }, plugins: [ - // TODO - alias({}), + alias({ + [ctx.pkg.name]: ctx.rootDir + }), nodeResolve({ extensions diff --git a/src/builder/untyped.ts b/src/builder/untyped.ts index 41d9d01c..8dfe8969 100644 --- a/src/builder/untyped.ts +++ b/src/builder/untyped.ts @@ -30,6 +30,8 @@ export async function typesBuild (ctx: BuildContext) { await writeFile(resolve(genDir, `${entry.name}.md`), generateMarkdown(schema)) await writeFile(resolve(genDir, `${entry.name}.schema.json`), JSON.stringify(schema, null, 2)) await writeFile(resolve(genDir, `${entry.name}.defaults.json`), JSON.stringify(defaults, null, 2)) - await writeFile(resolve(genDir, `${entry.name}.d.ts`), 'export ' + generateTypes(schema, pascalCase(entry.name + '-schema'))) + if (entry.declaration) { + await writeFile(resolve(genDir, `${entry.name}.d.ts`), 'export ' + generateTypes(schema, pascalCase(entry.name + '-schema'))) + } } } diff --git a/src/types.ts b/src/types.ts index f4ab57ef..a0007c91 100644 --- a/src/types.ts +++ b/src/types.ts @@ -4,11 +4,13 @@ export interface BuildEntry { builder?: 'rollup' | 'mkdist' | 'untyped' format?: 'esm' | 'cjs' defaults?: Record + declaration?: boolean } export interface BuildOptions { pkg: any, rootDir: string + declaration?: boolean entries: BuildEntry[], clean: boolean outDir: string