Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite project to make it smaller, faster and more understandable #72

Merged
merged 15 commits into from
Jun 18, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 0 additions & 15 deletions .babelrc

This file was deleted.

6 changes: 6 additions & 0 deletions .size-limit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = [
{
path: 'dist/adoptedStyleSheets.js',
limit: '2 kB',
},
];
85 changes: 58 additions & 27 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// Karma configuration
// Generated on Sun Jan 20 2019 23:06:22 GMT-0600 (CST)
const {readFileSync} = require('fs');
const {resolve} = require('path');
const rollupCommonjs = require('@rollup/plugin-commonjs');
const rollupNodeResolve = require('@rollup/plugin-node-resolve').default;
const rollupPluginBabel = require('@rollup/plugin-babel').default;
const rollupPluginTypescript = require('@rollup/plugin-typescript');

const isCI = !!process.env.CI;
const watch = !!process.argv.find(arg => arg.includes('watch')) && !isCI;
const coverage = !!process.argv.find(arg => arg.includes('--coverage'));
const watch = !!process.argv.find((arg) => arg.includes('watch')) && !isCI;
const coverage = !!process.argv.find((arg) => arg.includes('--coverage'));

const babelrc = JSON.parse(
readFileSync(resolve(process.cwd(), '.babelrc'), 'utf8'),
);
const extensions = ['.ts', '.js'];

module.exports = config => {
module.exports = (config) => {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
Expand All @@ -38,17 +38,16 @@ module.exports = config => {
frameworks: ['jasmine', 'detectBrowsers'],
client: {
jasmine: {
random: false
}
random: false,
},
},

// list of files / patterns to load in the browser
files: [
{pattern: 'test/polyfills.js', watched: false},
{pattern: 'src/index.js', watched: false},
{pattern: 'src/index.ts', watched: false},
{pattern: 'test/init-while-loading.js', watched: false},
{pattern: 'test/polyfill.test.js', watched: false},
{pattern: 'test/closed-root.test.js', watched: false}
{pattern: 'test/polyfill.test.ts', watched: false},
],

// list of files / patterns to exclude
Expand All @@ -58,8 +57,8 @@ module.exports = config => {
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'test/polyfills.js': ['rollup'],
'src/index.js': ['sourceRollup'],
'test/polyfill.test.js': ['rollup'],
'src/index.ts': ['sourceRollup'],
'test/polyfill.test.ts': ['rollup'],
},

// test results reporter to use
Expand Down Expand Up @@ -101,21 +100,45 @@ module.exports = config => {
usePhantomJS: false,
preferHeadless: true,
postDetection(availableBrowsers) {
return availableBrowsers.filter(browser => browser !== 'SafariTechPreview');
}
return availableBrowsers.filter(
(browser) => browser !== 'SafariTechPreview' && browser !== 'Edge',
);
},
},

rollupPreprocessor: {
plugins: [
require('rollup-plugin-commonjs')({
rollupCommonjs({
include: 'node_modules/**',
exclude: 'node_modules/@open-wc/**',
}),
require('rollup-plugin-node-resolve')(),
require('rollup-plugin-babel')({
rollupNodeResolve({
extensions,
}),
rollupPluginBabel({
babelHelpers: 'bundled',
babelrc: false,
include: ['node_modules/@open-wc/**', 'test/**'],
...babelrc,
extensions,
include: [
'node_modules/@open-wc/**',
'node_modules/lit-element/**',
'node_modules/lit-html/**',
'test/**',
],
presets: [
'@babel/preset-typescript',
[
'@babel/preset-env',
{
loose: true,
targets: {
browsers: ['last 2 versions', 'IE 11'],
},
shippedProposals: true,
useBuiltIns: false,
},
],
],
plugins: [
'@babel/plugin-transform-instanceof',
'babel-plugin-transform-async-to-promises',
Expand All @@ -126,29 +149,37 @@ module.exports = config => {
format: 'iife',
name: 'tests',
},
treeshake: true,
},

customPreprocessors: {
sourceRollup: {
base: 'rollup',
options: {
plugins: [
require('rollup-plugin-node-resolve')(),
require('rollup-plugin-babel')({
rollupNodeResolve({
extensions,
}),
rollupPluginTypescript({
isolatedModules: true,
tsconfig: require.resolve('./tsconfig.build.json'),
}),
rollupPluginBabel({
babelHelpers: 'bundled',
babelrc: false,
...babelrc,
extensions,
plugins: [coverage && 'babel-plugin-istanbul'].filter(Boolean),
}),
require('./plugins/rollup-plugin-inject-code')({
'index.js': {
line: 3,
code: " if ('adoptedStyleSheets' in document) { return; }\n",
code: " if ('adoptedStyleSheets' in document) { return; }\n",
},
}),
],
output: {
format: 'iife',
name: 'tests',
name: 'source',
},
treeshake: false,
},
Expand Down