// All other imports are lazy so that single tasks start up fast. import { cpSync, existsSync, promises, readFileSync, readdirSync, writeFileSync, } from 'fs'; import gulp from 'gulp'; import {basename, dirname, join, resolve} from 'path'; import {gzipSync} from 'zlib'; const UTF8 = 'utf-8'; const ALL_MODULES = [ '', // 'tinybase'; store and core modules 'omni', // everything 'checkpoints', 'common', 'indexes', 'mergeable-store', 'metrics', 'middleware', 'persisters', 'persisters/persister-automerge', 'persisters/persister-better-sqlite3', 'persisters/persister-browser', 'persisters/persister-capacitor-sqlite', 'persisters/persister-durable-object-storage', 'persisters/persister-durable-object-sql-storage', 'persisters/persister-expo-sqlite', 'persisters/persister-file', 'persisters/persister-indexed-db', 'persisters/persister-libsql', 'persisters/persister-mssql', 'persisters/persister-partykit-client', 'persisters/persister-partykit-server', 'persisters/persister-pg', 'persisters/persister-pglite', 'persisters/persister-postgres', 'persisters/persister-powersync', 'persisters/persister-react-native-mmkv', 'persisters/persister-react-native-sqlite', 'persisters/persister-remote', 'persisters/persister-sqlite-bun', 'persisters/persister-sqlite-node', 'persisters/persister-sqlite-wasm', 'persisters/persister-supabase', 'persisters/persister-tinyjoin', 'persisters/persister-yjs', 'queries', 'relationships', 'schematizers', 'schematizers/schematizer-arktype', 'schematizers/schematizer-effect', 'schematizers/schematizer-typebox', 'schematizers/schematizer-valibot', 'schematizers/schematizer-yup', 'schematizers/schematizer-zod', 'store', 'synchronizers', 'synchronizers/synchronizer-broadcast-channel', 'synchronizers/synchronizer-local', 'synchronizers/synchronizer-ws-client', 'synchronizers/synchronizer-ws-server-durable-object', 'synchronizers/synchronizer-ws-server-simple', 'synchronizers/synchronizer-ws-server', 'ui-react-dom', 'ui-react-dom-charts', 'ui-react-inspector', 'ui-react', 'ui-solid-dom', 'ui-solid-inspector', 'ui-solid', 'ui-svelte-dom', 'ui-svelte-inspector', 'ui-svelte', ]; const ALL_DEFINITIONS = [ ...ALL_MODULES, '_internal/store', '_internal/queries', '_internal/ui', '_internal/ui-react', '_internal/ui-solid', ]; const DIST_DIR = 'dist'; const DOCS_DIR = 'docs'; const TMP_DIR = 'tmp'; const LINT_BLOCKS = /```[jt]sx?( [^\n]+)?(\n.*?)```/gms; const TYPES_DOC_CODE_BLOCKS = /\/\/\/\s*(\S*)(.*?)(?=(\s*\/\/)|(\n\n)|(\n$))/gs; const TYPES_DOC_BLOCKS = /(\/\*\*.*?\*\/)\s*\/\/\/\s*(\S*)/gs; const moduleIsSolid = (module) => module == 'ui-solid' || module == 'ui-solid-dom' || module == 'ui-solid-inspector'; const moduleIsSvelte = (module) => module == 'ui-svelte' || module == 'ui-svelte-dom' || module == 'ui-svelte-inspector'; const moduleIsClientOnly = (module) => module == 'ui-solid-dom' || module == 'ui-solid-inspector' || module == 'ui-svelte-dom' || module == 'ui-svelte-inspector'; const getUiModule = (module) => moduleIsSvelte(module) ? 'ui-svelte' : moduleIsSolid(module) ? 'ui-solid' : 'ui-react'; const getUiModuleReplacements = (uiModule) => ({ ['../' + uiModule + '/index.ts']: '../' + uiModule, ['../' + uiModule + '/index.tsx']: '../' + uiModule, }); const getGlobalName = (module) => 'TinyBase' + (module == '' ? '' : basename(module) .split('-') .map((part) => part[0].toUpperCase() + part.slice(1).toLowerCase()) .join('')); const getPrettierConfig = async () => ({ ...JSON.parse(await promises.readFile('.prettierrc', UTF8)), parser: 'typescript', }); const allOf = (array, cb) => Promise.all(array.map(cb)); const allModules = (cb) => allOf(ALL_MODULES, cb); const allDefinitions = (cb) => allOf(ALL_DEFINITIONS, cb); const clearDir = async (dir = DIST_DIR) => { await removeDir(dir); await makeDir(dir); }; const makeDir = (dir) => promises.mkdir(dir, {recursive: true}); const ensureDir = async (fileOrDirectory) => { await promises.mkdir(dirname(fileOrDirectory), {recursive: true}); return fileOrDirectory; }; const removeDir = (dir) => promises.rm(dir, {force: true, recursive: true}); const forEachDeepFile = (dir, callback, extension = '') => forEachDirAndFile( dir, (dir) => forEachDeepFile(dir, callback, extension), (file) => callback(file), extension, ); const forEachDirAndFile = (dir, dirCallback, fileCallback, extension = '') => readdirSync(dir, {withFileTypes: true}).forEach((entry) => { const path = resolve(join(dir, entry.name)); if (entry.isDirectory()) { dirCallback?.(path); } else if (path.endsWith(extension)) { fileCallback?.(path); } }); const copyWithReplace = async (src, replacements, dst = src) => await promises.writeFile( dst, replacements.reduce( (file, [from, to]) => file.replaceAll(from, to), await promises.readFile(src, UTF8), ), UTF8, ); const gzipFile = async (fileName) => await promises.writeFile( `${fileName}.gz`, gzipSync(await promises.readFile(fileName, UTF8), {level: 9}), ); const copyPackageFiles = async (forProd = false) => { const mins = forProd ? [null, 'min'] : [null]; const schemas = [null, 'with-schemas']; const json = JSON.parse(await promises.readFile('package.json', UTF8)); delete json.private; delete json.scripts; delete json.devEngines; delete json.devDependencies; delete json.allowScripts; json.main = './index.js'; json.types = './@types/index.d.ts'; json.typesVersions = {'*': {}}; json.exports = {}; mins.forEach((min) => { ALL_MODULES.forEach((module) => { schemas.forEach((withSchemas) => { const pathWithoutSchemas = [min, module] .filter((part) => part) .join('/'); const codePathWithoutSchemas = (pathWithoutSchemas ? '/' : '') + pathWithoutSchemas; const pathWithSchemas = [min, module, withSchemas] .filter((part) => part) .join('/'); const codePathWithSchemas = (pathWithSchemas ? '/' : '') + pathWithSchemas; const typesPath = ['.', '@types', module, withSchemas, 'index.d.'] .filter((part) => part) .join('/'); json.typesVersions['*'][pathWithSchemas ? pathWithSchemas : '.'] = [ typesPath + 'ts', ]; const types = typesPath + 'ts'; const code = '.' + codePathWithoutSchemas + '/index.js'; json.exports['.' + codePathWithSchemas] = moduleIsClientOnly(module) ? {types, browser: code} : {default: {types, default: code}}; }); }); }); await promises.writeFile( join(DIST_DIR, 'package.json'), JSON.stringify(json, undefined, 2), UTF8, ); await promises.copyFile('LICENSE', join(DIST_DIR, 'LICENSE')); await promises.copyFile('readme.md', join(DIST_DIR, 'readme.md')); await promises.copyFile('releases.md', join(DIST_DIR, 'releases.md')); await promises.copyFile('site/guides/19_agents.md', 'agents.md'); await promises.copyFile('agents.md', join(DIST_DIR, 'agents.md')); // The plugin manifest tracks the package version, so that Claude Code can // detect updates to the skills that the plugin exposes. const pluginJsonFile = join('.claude-plugin', 'plugin.json'); const pluginJson = JSON.parse(await promises.readFile(pluginJsonFile, UTF8)); pluginJson.version = json.version; await promises.writeFile( pluginJsonFile, JSON.stringify(pluginJson, undefined, 2) + '\n', UTF8, ); cpSync('skills', join(DIST_DIR, 'skills'), {recursive: true}); }; // The promise is memoized rather than the Map, since callers run concurrently // and would otherwise be handed the Map before it has been filled. let labelBlocksPromise; const getLabelBlocks = () => (labelBlocksPromise ??= (async () => { const labelBlocks = new Map(); await allModules(async (module) => { [ ...( await promises.readFile(`src/@types/${module}/docs.js`, UTF8) ).matchAll(TYPES_DOC_BLOCKS), ].forEach(([_, block, label]) => { if (labelBlocks.has(label)) { throw new Error(`Duplicate label '${label}' in ${module}`); } labelBlocks.set(label, block); }); }); return labelBlocks; })()); const copyDefinition = async (dir, module) => { const labelBlocks = await getLabelBlocks(); const {version} = JSON.parse(readFileSync('./package.json', UTF8)); const siteRoot = version.includes('beta') ? 'https://beta.tinybase.org' : 'https://tinybase.org'; // Add easier-to-read with-schemas blocks const codeBlocks = new Map(); [ ...( await promises.readFile(`src/@types/${module}/index.d.ts`, UTF8) ).matchAll(TYPES_DOC_CODE_BLOCKS), ].forEach(([_, label, code]) => { const prefix = code.match(/^\n\s*/m)?.[0]; if (prefix) { codeBlocks.set( label, code .replace(/export type \S+ =\s/, '') .replace(/export function /, '') .replaceAll(prefix, prefix + ' * '), ); } }); const absolutizeDocMedia = (block) => block.replace(/\]\((?:\s*\*\s*)?\/shots\//g, `](${siteRoot}/shots/`); const fileRewrite = (block, addOverrideSnippet) => absolutizeDocMedia( block.replace(TYPES_DOC_CODE_BLOCKS, (_, label, code) => { if (labelBlocks.has(label)) { const codeOverride = codeBlocks.get(label); let block = labelBlocks.get(label); if ( addOverrideSnippet && codeBlocks.has(label) && code.includes('<') && code.includes('Schema') && !codeOverride.endsWith('{') ) { const prefix = block.match(/^\s+\*$/m)?.[0]; if (prefix) { const line = '\n' + prefix; block = block.replace( /^\s+\*$/m, `${prefix}${line}` + ' This has schema-based typing.' + ' The following is a simplified representation:' + `${line}${line} \`\`\`ts override` + codeOverride.trimEnd() + `${line} \`\`\`${line}`, ); } code = code.replace(/^\s*?\/\/\/.*?\n/gm, ''); } return block + code; } throw `Missing docs label ${label} in ${module}`; }), ); await allOf(['', '/with-schemas'], async (extraDir) => { const definitionFile = await ensureDir( `${dir}/@types/${module}${extraDir}/index.d.ts`, ); await promises.writeFile( definitionFile, fileRewrite( await promises.readFile( `src/@types/${module}${extraDir}/index.d.ts`, UTF8, ), extraDir != '', ), UTF8, ); }); }; const copyDefinitions = async (dir) => { await allDefinitions((module) => copyDefinition(dir, module)); }; const execute = async (cmd, showOutput = false) => { const {spawn} = await import('child_process'); return new Promise((resolve, reject) => { const [command, ...args] = cmd.split(' '); const child = spawn(command, args, showOutput ? {stdio: 'inherit'} : {}); let output = ''; if (!showOutput) { child.stdout.on('data', (data) => (output += data.toString())); child.stderr.on('data', (data) => (output += data.toString())); } child.on('close', (code) => { if (code === 0) { resolve(); } else { // eslint-disable-next-line no-console console.error(`Command failed with code ${code}: ${cmd}\n${output}`); reject(); } }); }); }; const lintCheckFiles = async (dir) => { const {default: prettier} = await import('prettier'); const prettierConfig = await getPrettierConfig(); const filePaths = []; ['.ts', '.tsx', '.js', '.d.ts', '.svelte'].forEach((extension) => forEachDeepFile(dir, (filePath) => filePaths.push(filePath), extension), ); await allOf(filePaths, async (filePath) => { const fileConfig = filePath.endsWith('.svelte') ? {...prettierConfig, filepath: filePath, parser: undefined} : {...prettierConfig, filepath: filePath}; const code = await promises.readFile(filePath, UTF8); if (!(await prettier.check(code, fileConfig))) { writeFileSync(filePath, await prettier.format(code, fileConfig), UTF8); } }); const { default: {ESLint}, } = await import('eslint'); const esLint = new ESLint({}); const results = await esLint.lintFiles([dir]); if ( results.filter((result) => result.errorCount > 0 || result.warningCount > 0) .length > 0 ) { const formatter = await esLint.loadFormatter(); const errors = await formatter.format(results); throw errors; } }; const lintCheckDocs = async (dir) => { const { default: {ESLint}, } = await import('eslint'); const esLint = new ESLint({ overrideConfig: { rules: { 'import/no-unresolved': 0, 'no-console': 0, 'react/prop-types': 0, 'react-hooks/rules-of-hooks': 0, '@typescript-eslint/no-unused-expressions': 0, 'max-len': [ 2, {code: 80, ignorePattern: '^(\\s+\\* )?((im|ex)ports?|// ->)\\W.*'}, ], }, }, }); const {default: prettier} = await import('prettier'); const prettierConfig = await getPrettierConfig(); const docConfig = {...prettierConfig, printWidth: 75}; const filePaths = []; ['.js', '.d.ts'].forEach((extension) => forEachDeepFile(dir, (filePath) => filePaths.push(filePath), extension), ); await allOf(filePaths, async (filePath) => { const code = await promises.readFile(filePath, UTF8); await allOf( [...(code.matchAll(LINT_BLOCKS) ?? [])], async ([_, hint, docBlock]) => { if (hint?.trim() == 'override') { return; // can't lint orphaned TS methods } const code = docBlock.replace(/\n +\* ?/g, '\n').trimStart(); let pretty = code; if (!(await prettier.check(code, docConfig))) { pretty = await prettier.format(code, docConfig); writeFileSync( filePath, readFileSync(filePath, UTF8).replace( docBlock, '\n' + pretty .trim() .split('\n') .map((line) => (line == '' ? ' *' : ' * ' + line)) .join('\n') + '\n * ', ), UTF8, ); } const results = await esLint.lintText(pretty); if ( results.filter( (result) => result.errorCount > 0 || result.warningCount > 0, ).length > 0 ) { const formatter = await esLint.loadFormatter(); const errors = await formatter.format(results); throw `${filePath} does not lint:\n${pretty}\n\n${errors}`; } }, ); }); }; const spellCheck = (dir, deep = false) => execute(`npx cspell ${dir}/*${deep ? '*' : ''}`); const getTsOptions = async (dir) => { const {default: tsc} = await import('typescript'); return tsc.parseJsonSourceFileConfigFileContent( tsc.readJsonConfigFile(`${dir}/tsconfig.json`, tsc.sys.readFile), tsc.sys, dir, ); }; const tsCheck = async (dir) => { const path = await import('path'); const {default: tsc} = await import('typescript'); const {analyzeTsConfig} = await import('ts-unused-exports'); const {fileNames, options} = await getTsOptions(dir); const results = tsc .getPreEmitDiagnostics( tsc.createProgram( fileNames.filter( (fileName) => !fileName.startsWith('test/unit/core/types'), ), options, ), ) .filter((result) => !result.file?.fileName.includes('/node_modules/')); if (results.length > 0) { const resultText = results .map((result) => { const {file, messageText, start} = result; const {line, character} = file.getLineAndCharacterOfPosition(start); return `${file.fileName}:${line}:${character}\n${JSON.stringify( messageText, )}`; }) .join('\n\n'); throw resultText; } const unusedResults = Object.entries( analyzeTsConfig(`${path.resolve(dir)}/tsconfig.json`, [ '--excludeDeclarationFiles', '--excludePathsFromReport=' + 'build.ts;ui-react/common.ts;' + ALL_MODULES.map((module) => `${module}.ts`).join(';'), ]).unusedExports, ) .map( ([file, exps]) => `${file}: ${exps.map((exp) => exp.exportName).join(', ')}`, ) .join('\n'); if (unusedResults != '') { throw `Unused exports for ${dir} in: \n${unusedResults}`; } }; const checkExportParity = async (dir = DIST_DIR) => { const {default: tsc} = await import('typescript'); const modules = ALL_MODULES.map((module) => [ module || 'tinybase', resolve(dir, module, 'index.js'), resolve(dir, '@types', module, 'index.d.ts'), ]); const program = tsc.createProgram( modules.flatMap(([, runtime, declarations]) => [runtime, declarations]), { allowJs: true, checkJs: false, module: tsc.ModuleKind.NodeNext, moduleResolution: tsc.ModuleResolutionKind.NodeNext, skipLibCheck: true, }, ); const checker = program.getTypeChecker(); const getExports = (file, valuesOnly) => checker .getExportsOfModule( checker.getSymbolAtLocation(program.getSourceFile(file)), ) .filter((symbol) => { while (symbol.flags & tsc.SymbolFlags.Alias) { symbol = checker.getAliasedSymbol(symbol); } return !valuesOnly || symbol.flags & tsc.SymbolFlags.Value; }) .map(({name}) => name) .sort(); const differences = modules.flatMap(([module, runtime, declarations]) => { const runtimeExports = getExports(runtime); const declarationExports = getExports(declarations, true); const extra = runtimeExports.filter( (name) => !declarationExports.includes(name), ); const missing = declarationExports.filter( (name) => !runtimeExports.includes(name), ); return extra.length || missing.length ? [{module, extra, missing}] : []; }); if (differences.length) { throw `Runtime and declaration exports differ:\n${JSON.stringify( differences, undefined, 2, )}`; } }; const compileModule = async (module, dir = DIST_DIR, min = false) => { const {default: esbuild} = await import('rollup-plugin-esbuild'); const {rollup} = await import('rollup'); const {babel} = await import('@rollup/plugin-babel'); const {default: replace} = await import('@rollup/plugin-replace'); const {default: prettierPlugin} = await import('rollup-plugin-prettier'); const {default: shebang} = await import('rollup-plugin-preserve-shebang'); const {default: image} = await import('@rollup/plugin-image'); const {default: terser} = await import('@rollup/plugin-terser'); const sveltePlugin = moduleIsSvelte(module) ? (await import('rollup-plugin-svelte')).default : null; const uiModule = getUiModule(module); let inputFile = `src/${module}/index.ts`; if (!existsSync(inputFile)) { inputFile += 'x'; } const inputConfig = { external: [ 'cloudflare:workers', 'expo-sqlite', 'fs', 'fs/promises', 'path', 'prettier/standalone', 'prettier/plugins/estree', 'prettier/plugins/typescript', 'react', 'react-dom', 'react/jsx-runtime', 'solid-js', 'solid-js/web', 'solid-js/jsx-runtime', 'url', 'yjs', ...(module == 'omni' ? [] : ['tinybase/store', '../ui-react', '../ui-solid', '../' + uiModule]), ...(moduleIsSvelte(module) ? [/^svelte/] : []), ], input: inputFile, plugins: [ esbuild({ target: 'esnext', legalComments: 'inline', logOverride: {'unsupported-jsx-comment': 'silent'}, tsconfig: moduleIsSolid(module) ? false : undefined, jsx: moduleIsSolid(module) ? 'preserve' : 'automatic', }), moduleIsSolid(module) ? babel({ babelHelpers: 'bundled', extensions: ['.tsx'], include: 'src/**/*.tsx', presets: [['solid', {delegateEvents: false}]], }) : null, replace({ '/*!': '\n/*', delimiters: ['', ''], preventAssignment: true, ...(module == 'omni' ? {} : getUiModuleReplacements(uiModule)), }), shebang(), image(), min ? [terser({toplevel: true, compress: {unsafe: true, passes: 3}})] : prettierPlugin(await getPrettierConfig()), ...(sveltePlugin ? [ sveltePlugin({ extensions: ['.svelte', '.svelte.ts'], compilerOptions: {runes: true}, }), ] : []), ], onwarn: (warning, warn) => { if (warning.code !== 'MISSING_NODE_BUILTINS') { warn(warning); } }, }; const moduleDir = dirname(await ensureDir(dir + '/' + module + '/-')); const index = 'index.js'; const outputConfig = { dir: moduleDir, entryFileNames: index, format: 'esm', interop: 'default', name: getGlobalName(module), }; const bundle = await rollup(inputConfig); try { await bundle.write(outputConfig); } finally { await bundle.close(); } // kill me now const outputFile = join(moduleDir, index); const outputFiles = [outputFile]; const outputFileWithSchemas = await ensureDir( join(moduleDir, 'with-schemas', index), ); outputFiles.push(outputFileWithSchemas); await copyWithReplace( outputFile, [['../' + uiModule, '../../' + uiModule + '/with-schemas/' + index]], outputFileWithSchemas, ); await copyWithReplace( outputFile, [ ['../ui-react', '../ui-react/' + index], ['../ui-solid', '../ui-solid/' + index], ['../ui-svelte', '../ui-svelte/' + index], [/(\w+) = \$\.noop/g, '/* istanbul ignore next */ $1 = $.noop'], ], outputFile, ); if (min) { await allOf(outputFiles, (outputFile) => gzipFile(outputFile)); } }; const test = async (dirs, coverage, project) => { const {startVitest} = await import('vitest/node'); await clearDir(TMP_DIR); const vitest = await startVitest( 'test', [...dirs], { watch: false, coverage: {enabled: coverage}, ...(project ? {project} : {}), }, {}, {watch: false}, ); await vitest.close(); if ( vitest.state.getCountOfFailedTests() > 0 || vitest.state.getUnhandledErrors().length > 0 ) { await removeDir(TMP_DIR); throw 'Test failed'; } if (coverage) { await promises.writeFile( 'coverage.json', JSON.stringify({ ...JSON.parse(await promises.readFile('./tmp/counts.json')), ...JSON.parse( await promises.readFile('./tmp/coverage/coverage-summary.json'), ).total, }), UTF8, ); } }; const compileModulesForProd = async () => { await clearDir(DIST_DIR); await copyPackageFiles(true); await copyDefinitions(DIST_DIR); await allModules(async (module) => { await compileModule(module, `${DIST_DIR}/`); await compileModule(module, `${DIST_DIR}/min`, true); }); await checkExportParity(); }; const compileDocsAndAssets = async (api = true, pages = true) => { const {default: esbuild} = await import('esbuild'); if (api) { await copyDefinitions(DIST_DIR); } await makeDir(TMP_DIR); await esbuild.build({ entryPoints: ['site/build.ts'], external: ['tinydocs', 'react', '@prettier/sync', '@babel/core'], target: 'esnext', bundle: true, outfile: './tmp/build.js', format: 'esm', platform: 'node', }); const {build} = await import('./tmp/build.js'); await build(esbuild, DOCS_DIR, api, pages); await removeDir(TMP_DIR); }; const npmInstall = () => execute('npm ci --legacy-peer-deps'); const npmPublish = async () => { const {version} = JSON.parse( await promises.readFile(join(DIST_DIR, 'package.json'), UTF8), ); const tag = version.match(/^[^-+]+-([0-9A-Za-z-]+)(?:[.+]|$)/)?.[1]; await execute( `npm publish ./${DIST_DIR}` + (tag ? ` --tag ${tag}` : ''), true, ); }; const {parallel, series} = gulp; // -- export const preparePackage = copyPackageFiles; export const compileForTest = async () => { await clearDir(DIST_DIR); await copyPackageFiles(); await copyDefinitions(DIST_DIR); await allModules(async (module) => { await compileModule(module, DIST_DIR); }); await checkExportParity(); }; export const compileForTestInspectorOnly = async () => { await compileModule('ui-react', DIST_DIR); await compileModule('ui-react-dom', DIST_DIR); await compileModule('ui-react-inspector', DIST_DIR); await compileModule('ui-solid', DIST_DIR); await compileModule('ui-solid-dom', DIST_DIR); await compileModule('ui-solid-inspector', DIST_DIR); await compileModule('ui-svelte', DIST_DIR); await compileModule('ui-svelte-dom', DIST_DIR); await compileModule('ui-svelte-inspector', DIST_DIR); }; export const lintFiles = async () => { await lintCheckFiles('src'); await lintCheckFiles('test'); await lintCheckFiles('site'); }; export const lintDocs = () => lintCheckDocs('src'); export const lint = series(lintDocs, lintFiles); export const spell = async () => { await spellCheck('.'); await spellCheck('src', true); await spellCheck('test', true); await spellCheck('site', true); }; export const ts = async () => { await tsCheck('src'); await tsCheck('test'); await tsCheck('site'); await execute( 'npx svelte-check --workspace src/ui-svelte ' + '--tsconfig svelte.tsconfig.json', ); await execute( 'npx svelte-check --workspace test/unit/core/ui-svelte ' + '--tsconfig svelte.tsconfig.json', ); }; export const compileForProd = () => compileModulesForProd(); export const testUnit = async () => { await test(['test/unit'], true); }; export const compileAndTestUnit = series(compileForTest, testUnit); export const testBun = () => execute( 'bun test ' + 'test/unit/persisters/database ' + 'test/unit/documentation.test.ts', ); export const testUnitFast = async () => { await test(['test/unit/core'], true); }; // The same suite as testUnit, minus the two projects that need a local // PostgreSQL or SQL Server. Coverage is off, since leaving those out puts it // short of the 100% that testUnit reports. export const testUnitNoServers = async () => { await test(['test/unit'], false, ['!*-servers']); }; export const compileAndTestUnitFast = series(compileForTest, testUnitFast); export const testDocs = async () => { await test(['test/unit/documentation.test.ts'], true); }; export const compileAndTestDocs = series(compileForTest, testDocs); export const testPerf = async () => { await test(['test/perf']); }; export const compileAndTestPerf = series(compileForTest, testPerf); export const compileDocsPagesOnly = () => compileDocsAndAssets(false); export const compileDocsAssetsOnly = () => compileDocsAndAssets(false, false); export const compileDocs = () => compileDocsAndAssets(); export const preparePackageForProd = () => copyPackageFiles(true); export const compileForProdAndDocs = series( compileForProd, compileDocs, preparePackageForProd, ); export const testE2e = () => execute('npx playwright test', true); export const compileAndTestE2e = series(compileForProdAndDocs, testE2e); export const testProd = async () => { await execute('attw --pack dist --format table-flipped --profile esm-only'); await test(['test/prod']); }; export const compileAndTestProd = series(compileForProdAndDocs, testProd); export const serveDocs = async () => { const {createTestServer} = await import('./test/server.mjs'); createTestServer(DOCS_DIR, '8080'); }; export const preCommit = series( parallel(lint, spell, ts), compileForTest, testBun, testUnit, compileForProd, ); export const prePublishPackage = series( npmInstall, compileForTest, parallel(lint, spell, ts), testBun, testUnit, testPerf, compileForProd, compileDocs, preparePackageForProd, testProd, testE2e, ); export const prePublishPackageFast = series( npmInstall, compileForProd, compileDocs, preparePackageForProd, ); export const publishPackage = series(prePublishPackage, npmPublish);