-
708f25e: Support ts config files
scratchpad.config.ts
import { Config } from "@heymp/scratchpad/src/config.js"; export function hi(name: string) { console.log(`Hi there ${name}`); } declare global { interface Window { hi: typeof hi; } } export default { playwright: async (args) => { const { context } = args; await context.exposeFunction("hi", hi); }, } satisfies Config;
test.ts
/// <reference path="./scratchpad.config.ts" /> window.hi('Bob');
- e628851: Fix cannot find package '@commander-js/extra-typings error.
- 556669b: Update Readme
-
4aa2817: Add
generate config
command #38npx @heymp/scratchpad generate --help Usage: scratchpad generate [options] [command] Generate files from templates. Options: -h, --help display help for command Commands: config Generates an example config file. help [command] display help for command
-
4aa2817: Add
run
commandnpx @heymp/scratchpad run --help Usage: cli run [options] <file> Execute a file in a browser. Arguments: file file to execute in the browser. Options: --headless [boolean] specify running the browser in headless mode. --devtools [boolean] open browser devtools automatically. --ts-write [boolean] write the js output of the target ts file. --url [string] specify a specific url to execute the code in. -h, --help display help for command
-
ea5b50d: Add
writeFile
,appendFile
exposed functions. (#44)[#44]await writeFile('./log.txt', 'hello'); await appendFile('./log.txt', '\n'); await appendFile('./log.txt', 'world');
Include custom exposed functions example.
import { join } from 'node:path' import fs from 'node:fs/promises'; function loadFile(path) { return fs.readFile(join(process.cwd(), path), 'utf8'); } export default /** @type {import('@heymp/scratchpad/src/config').Config} */ ({ playwright: async (args) => { const { context, page } = args; await context.exposeFunction('loadFile', loadFile) } });
-
a242c0f:
⚠️ Change config types directory.export default /** @type {import('@heymp/scratchpad/src/config').Config} */ ({});
-
c31a8f9: Expose Playwright runtime context to scratchpad.config.js #40
scratchpad.config.js
export default /** @type {import('@heymp/scratchpad/config').Config} */ ({ devtools: true, playwright: async (args) => { const { context, page } = args; // block esmodule shims await context.route(/es-module-shims\.js/, async (route) => { await route.abort(); }); await page.goto("https://ux.redhat.com"); }, });
-
f6fb1f2: Add option for writing the js output to a file based on the compiled ts target. Use
--ts-write
as a boolean flag in the cli.
-
c31a8f9: Add typings for scratchpad.config.js #37
export default /** @type {import('@heymp/scratchpad/config').Config} */ ({ devtools: true, headless: true, url: "https://google.com", });
-
2bcb56e: Add
scratchpad.config.js
file as an alternative to specifying scratchpad options using the CLI flags.export default { devtools: true, headless: false, url: "https://www.google.com", };
NOTE: CLI flags will take precidence over config file options.
- db0f2af: Open devtools automatically with cli flag. Use the
--devtools
flag to enable the devtools in the browser.
- 7b6410e: Migrate from tsc to esbuild for TS compilation
- f5c9bc4: Migrate to Playwright
- 68ec5fb: Fix bin entrypoint
- 8883144: Fix log arguments typings
-
79b0eda: Typescript Support
Compiles files ending in
.ts
using tsc.Example:
npm install @heymp/scratchpad
Recommended tsconfig.json settings.
{ "target": "esnext", "compilerOptions": { "types": ["./node_modules/@heymp/scratchpad/types.d.ts"] } }