Skip to content

Commit

Permalink
imporve build system
Browse files Browse the repository at this point in the history
  • Loading branch information
KingSora committed Aug 27, 2024
1 parent b11536b commit 5c3242c
Show file tree
Hide file tree
Showing 20 changed files with 4,963 additions and 53 deletions.
2,127 changes: 2,127 additions & 0 deletions local/playwright-tooling/package-lock.json

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions local/playwright-tooling/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
"bin": {
"playwright-merge-coverage": "./bin/mergeCoverage.js"
},
"dependencies": {
"@rollup/plugin-html": "^1.0.3",
"istanbul-lib-instrument": "^5.2.0",
"rollup-plugin-livereload": "^2.0.0",
"rollup-plugin-serve": "^2.0.0",
"rollup-plugin-styles": "^4.0.0"
},
"types": "index.d.ts",
"version": "0.0.0"
}
4 changes: 2 additions & 2 deletions local/playwright-tooling/src/playwrightRollup.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { dirname } from 'node:path';
import { watch as rollupWatch } from 'rollup';
import { test } from '@playwright/test';
import createPlaywrightRollupConfig from '@~local/rollup/playwright';
import { rollupPlaywrightConfig } from './rollup/rollupPlaywrightConfig.js';
import collectCoverage from './collectCoverage.js';

const createRollupBundle = async (testDir, useEsbuild, dev) => {
const [config, getServer] = await createPlaywrightRollupConfig(testDir, useEsbuild, dev);
const [config, getServer] = rollupPlaywrightConfig(testDir, useEsbuild, dev);
const watcher = rollupWatch(config);

const outputPath = await new Promise((resolve) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import fs from 'node:fs';

export const rollupPlaywrightAdditionalWatchFilesPlugin = (files) => ({
buildStart() {
if (files) {
files.forEach((file) => {
if (fs.existsSync(file)) {
this.addWatchFile(file);
}
});
}
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import rollupPluginStyles from 'rollup-plugin-styles';
import rollupPluginServe from 'rollup-plugin-serve';
import rollupPluginLivereload from 'rollup-plugin-livereload';
import resolve from '@~local/config/resolve' with { type: 'json' };
import rollupPluginHtml from '../plugins/html.js';
import rollupAdditionalWatchFiles from '../plugins/additionalWatchFiles.js';
import rollupIstanbul from '../plugins/istanbul.js';
import createRollupConfig from '../createRollupConfig.js';
import createRollupConfig from '@~local/rollup';
import { rollupPlaywrightHtmlPlugin } from './rollupPlaywrightHtmlPlugin.js';
import { rollupPlaywrightAdditionalWatchFilesPlugin } from './rollupPlaywrightAdditionalWatchFilesPlugin.js';
import { rollupPlaywrightIstanbulPlugin } from './rollupPlaywrightIstanbulPlugin.js';

const portRange = {
min: 20000,
Expand All @@ -18,11 +18,11 @@ const portRange = {

const paths = {
outDir: './.build',
input: './index.browser',
input: './index.browser.ts',
html: './index.html',
};

export default (testDir, useEsbuild, dev) => {
export const rollupPlaywrightConfig = (testDir, useEsbuild, dev) => {
const testPaths = Object.keys(paths).reduce((obj, key) => {
obj[key] = path.resolve(testDir, paths[key]);
return obj;
Expand Down Expand Up @@ -59,7 +59,7 @@ export default (testDir, useEsbuild, dev) => {
},
plugins: [
rollupPluginStyles(),
rollupPluginHtml(`Playwright: ${name}`, htmlName, () =>
rollupPlaywrightHtmlPlugin(`Playwright: ${name}`, htmlName, () =>
fs.existsSync(htmlPath) ? fs.readFileSync(htmlPath, 'utf8') : null
),
rollupPluginServe({
Expand All @@ -72,15 +72,15 @@ export default (testDir, useEsbuild, dev) => {
server = srv;
},
}),
isDev && rollupAdditionalWatchFiles([htmlPath]),
isDev && rollupPlaywrightAdditionalWatchFilesPlugin([htmlPath]),
isDev &&
rollupPluginLivereload({
watch: outDir,
port: port - 1,
verbose: false,
}),
!isDev &&
rollupIstanbul({
rollupPlaywrightIstanbulPlugin({
include: resolve.extensions.map((extension) => `/**/*${extension}`).flat(),
exclude: ['**/node_modules/**', `**/${path.relative(process.cwd(), testDir)}/**`],
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const genHtmlTemplateFunc =
</html>`;
};

export default (title, fileName, getHtmlContent) =>
export const rollupPlaywrightHtmlPlugin = (title, fileName, getHtmlContent) =>
rollupPluginHtml({
title,
fileName,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createFilter } from '@rollup/pluginutils';
import istanbul from 'istanbul-lib-instrument';

export default (options = {}) => {
export const rollupPlaywrightIstanbulPlugin = (options = {}) => {
const filter = createFilter(options.include, options.exclude);

return {
Expand Down
Loading

0 comments on commit 5c3242c

Please sign in to comment.