Skip to content

Commit

Permalink
fix(core): types path (#1715)
Browse files Browse the repository at this point in the history
Co-authored-by: Yohan Lasorsa <noda@free.fr>
  • Loading branch information
ggrossetie and sinedied committed Nov 29, 2023
1 parent efe88b3 commit 7863698
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 29 deletions.
1 change: 1 addition & 0 deletions packages/core/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/node_modules/
/dist/
npm-debug.log
/types/index.d.cts

# generated using rollup
/spec/node/asciidoctor.spec.cjs
145 changes: 129 additions & 16 deletions packages/core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 13 additions & 5 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@
"module": "dist/browser/asciidoctor.js",
"exports": {
"node": {
"import": "./dist/node/asciidoctor.js",
"require": "./dist/node/asciidoctor.cjs"
"import": {
"default": "./dist/node/asciidoctor.js",
"types": "./types/index.d.ts"
},
"require": {
"default": "./dist/node/asciidoctor.cjs",
"types": "./types/index.d.cts"
}
},
"default": "./dist/browser/asciidoctor.js"
"default": "./dist/browser/asciidoctor.js",
"types": "./types/index.d.ts"
},
"types": "types",
"types": "types/index.d.ts",
"engines": {
"node": ">=16",
"npm": ">=8"
Expand Down Expand Up @@ -108,7 +115,8 @@
"portfinder": "1.0.32",
"pug": "3.0.2",
"puppeteer": "19.11.1",
"rollup": "3.26.0",
"rollup": "~3.29",
"rollup-plugin-dts": "^6.1.0",
"sinon": "15.2.0",
"standard": "17.1.0",
"tsd": "0.28.1",
Expand Down
17 changes: 15 additions & 2 deletions packages/core/tasks/module/builder.cjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
'use strict'

const fs = require('fs')
const path = require('path')
const fs = require('node:fs')
const path = require('node:path')
const log = require('bestikk-log')
const bfs = require('bestikk-fs')
const Download = require('bestikk-download')
const download = new Download({})
const { rollup } = require('rollup')
const rollupPluginJson = require('@rollup/plugin-json')
const rollupPluginCommonJS = require('@rollup/plugin-commonjs')
const rollupPluginDts = require('rollup-plugin-dts')

const compilerModule = require('./compiler.cjs')
const uglifyModule = require('./uglify.cjs')
Expand Down Expand Up @@ -55,6 +56,17 @@ const parseTemplateData = (data, templateModel) => {
.join('\n')
}

const generateCommonJSTypes = async () => {
const bundle = await rollup({
input: 'types/index.d.ts',
plugins: [rollupPluginDts.dts()]
})
await bundle.write({
file: 'types/index.d.cts',
format: 'cjs'
})
}

const generateCommonJSSpec = async () => {
log.task('generate commonjs spec')
const bundle = await rollup({
Expand Down Expand Up @@ -231,6 +243,7 @@ module.exports = class Builder {
await rebuild(asciidoctorCoreDependency, this.environments)
await generateFlavors(this.asciidoctorCoreTarget, this.environments)
await generateCommonJSSpec()
await generateCommonJSTypes()
await uglifyModule.uglify()
if (process.env.COPY_DIST) {
this.copyToDist()
Expand Down
13 changes: 7 additions & 6 deletions packages/core/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/// <reference types="node" />
// TypeScript Version: 3.7
import Author = Document.Author;
import Title = Document.Title;
import Registry = Extensions.Registry;
import Cursor = Reader.Cursor;
type Author = Document.Author;
type Title = Document.Title;
type TitleOptions = Document.Title.Options;
type Registry = Extensions.Registry;
type Cursor = Reader.Cursor;

declare class OpalKlass<T> {
$new(...params: any[]): T;
Expand Down Expand Up @@ -1707,12 +1708,12 @@ export class Document extends AbstractBlock {
* @returns the resolved title as a {@link Document/Title} if the partition option is passed
* or a {string} if not or undefined if no value can be resolved.
*/
getDocumentTitle(options?: Title.Options): string | Title | undefined;
getDocumentTitle(options?: TitleOptions): string | Title | undefined;

/**
* @see {@link Document#getDocumentTitle}
*/
getDoctitle(options: Title.Options): string | Title;
getDoctitle(options: TitleOptions): string | Title;

/**
* Get the document catalog JSON object.
Expand Down

0 comments on commit 7863698

Please sign in to comment.