Skip to content

Commit

Permalink
add a new, bundled version of the docs.d.ts, use that in OT
Browse files Browse the repository at this point in the history
  • Loading branch information
alicewriteswrongs committed Jul 25, 2023
1 parent 73893ac commit bc700f6
Show file tree
Hide file tree
Showing 4 changed files with 354 additions and 258 deletions.
9 changes: 8 additions & 1 deletion scripts/bundles/internal.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs-extra';
import { join } from 'path';

import { cleanDts } from '../utils/bundle-dts';
import { bundleDts, cleanDts } from '../utils/bundle-dts';
import type { BuildOptions } from '../utils/options';
import { writePkgJson } from '../utils/write-pkg-json';
import { internalAppData } from './internal-app-data';
Expand Down Expand Up @@ -73,6 +73,13 @@ async function copyStencilInternalDts(opts: BuildOptions, outputInternalDir: str
const docsDts = cleanDts(await fs.readFile(docsDtsSrcPath, 'utf8'));
await fs.writeFile(docsDtsDestPath, docsDts);

// @stencil/core/internal/stencil-public-docs-bundled.d.ts
// this is the same types as `stencil-public-docs.d.ts` but bundled with
// dts-bundle-generator so it's self-contained and therefore portable
const bundledDocsDtsDestPath = join(outputInternalDir, 'stencil-public-docs-bundled.d.ts');
const bundledDocsDts = await bundleDts(opts, docsDtsSrcPath);
await fs.writeFile(bundledDocsDtsDestPath, bundledDocsDts);

// @stencil/core/internal/stencil-public-runtime.d.ts
const runtimeDtsSrcPath = join(declarationsInputDir, 'stencil-public-runtime.d.ts');
const runtimeDtsDestPath = join(outputInternalDir, 'stencil-public-runtime.d.ts');
Expand Down
8 changes: 6 additions & 2 deletions scripts/utils/bundle-dts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { generateDtsBundle } from 'dts-bundle-generator/dist/bundle-generator.js';
import { generateDtsBundle, EntryPointConfig } from 'dts-bundle-generator/dist/bundle-generator.js';
import fs from 'fs-extra';

import { BuildOptions } from './options';
Expand All @@ -12,9 +12,13 @@ export async function bundleDts(opts: BuildOptions, inputFile: string) {
} catch (e) {}
}

const entries = [
const entries: EntryPointConfig[] = [
{
filePath: inputFile,
output: {
noBanner: true,
exportReferencedTypes: false,
},
},
];

Expand Down
25 changes: 14 additions & 11 deletions src/compiler/docs/json/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { isOutputTargetDocsJson } from '@utils';
import { join } from 'path';
import { generateDtsBundle } from 'dts-bundle-generator/dist/bundle-generator.js';

import type * as d from '../../../declarations';

Expand All @@ -14,16 +13,20 @@ export const generateJsonDocs = async (
if (jsonOutputTargets.length === 0) {
return;
}
const docsDtsPath = join(config.sys.getCompilerExecutingPath(), '..', '..', 'internal', 'stencil-public-docs.d.ts');

const entries = [
{
filePath: docsDtsPath,
},
];
console.log('ABOUT TO GENERATE DTS BUNDLE');
let docsDts = await generateDtsBundle(entries).join('\n');
console.log(docsDts);
const docsDtsPath = join(
config.sys.getCompilerExecutingPath(),
'..',
'..',
'internal',
'stencil-public-docs-bundled.d.ts',
);
let docsDts = await compilerCtx.fs.readFile(docsDtsPath);
// this file was written by dts-bundle-generator, which uses tabs for
// indentation
docsDts = docsDts
.split('\n')
.map((line) => line.replace(/^\t/, ' '))
.join('\n');

const typesContent = `
/**
Expand Down
Loading

0 comments on commit bc700f6

Please sign in to comment.