Skip to content
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ stats.html
packages/function/dist
packages/mql/dist/index.js
packages/mql/dist/index.umd.js
packages/core/src/puppeteer-core.d.ts
6 changes: 4 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"require": "./bin/run.js",
"default": "./bin/cli.mjs"
},
"./docs": "./bin/docs.js"
"./docs": "./bin/docs.js",
"./src/puppeteer-core.d.ts": "./src/puppeteer-core.d.ts"
},
"bin": {
"microlink": "bin/index.js",
Expand Down Expand Up @@ -72,7 +73,8 @@
"src"
],
"scripts": {
"test": "ava && tsd"
"prepack": "node scripts/copy-puppeteer-dts.js",
"test": "node scripts/copy-puppeteer-dts.js && ava && tsd"
Comment thread
Kikobeats marked this conversation as resolved.
},
"preferGlobal": true,
"license": "MIT",
Expand Down
14 changes: 14 additions & 0 deletions packages/core/scripts/copy-puppeteer-dts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict'

const { createRequire } = require('node:module')
const { dirname, join } = require('node:path')
const { readFileSync, writeFileSync } = require('node:fs')

const requireFromCore = createRequire(join(__dirname, '../package.json'))
const pkgPath = requireFromCore.resolve('puppeteer-core/package.json')
const { types } = requireFromCore(pkgPath)

writeFileSync(
join(__dirname, '../src/puppeteer-core.d.ts'),
readFileSync(join(dirname(pkgPath), types), 'utf8')
)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
17 changes: 16 additions & 1 deletion packages/core/test/build.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { readFile, access, constants } from 'fs/promises'
import { readFile, access, constants, mkdtemp, readdir, rm } from 'fs/promises'
import { fileURLToPath } from 'url'
import { tmpdir } from 'os'
import $ from 'tinyspawn'
import test from 'ava'
import path from 'path'
Expand Down Expand Up @@ -89,3 +90,17 @@ test('published files include every bin entry', t => {
)
)
})

test('ships puppeteer-core types next to the package dts', async t => {
t.is(pkg.exports['./src/puppeteer-core.d.ts'], './src/puppeteer-core.d.ts')
const dts = await readFile(path.join(root, 'src/puppeteer-core.d.ts'), 'utf8')
t.true(dts.includes('export declare abstract class Page'))
t.true(dts.includes('export declare abstract class HTTPResponse'))

const dest = await mkdtemp(path.join(tmpdir(), 'microlink-pack-'))
t.teardown(() => rm(dest, { recursive: true, force: true }))
await $('pnpm', ['pack', '--pack-destination', dest], { cwd: root })
const [tarball] = (await readdir(dest)).filter(name => name.endsWith('.tgz'))
const { stdout } = await $('tar', ['-tzf', path.join(dest, tarball)])
t.true(stdout.includes('package/src/puppeteer-core.d.ts'))
})
Loading