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

Tram-One, now with Types! Typescript! v11.0.0 #175

Merged
merged 28 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
dc2bf8c
Initial Pass at migrating to Typescript
JRJurman Oct 21, 2021
a43298e
re-add lint (placeholder)
JRJurman Oct 21, 2021
e56dc64
migrate test app to ts as well
JRJurman Oct 21, 2021
64dab27
type definitions!
JRJurman Oct 22, 2021
1b76e38
npm ci in pipeline
JRJurman Oct 22, 2021
1ca3030
11.0.0
JRJurman Oct 22, 2021
349d159
remove manual type checks
JRJurman Oct 22, 2021
839e459
add eslint typescript config
JRJurman Oct 22, 2021
029217e
fix lint, add comments to config, update test files to ts
JRJurman Oct 23, 2021
fdcadee
cleanup jsdocs, more types, add unit test for root effect
JRJurman Oct 24, 2021
30f8370
use prettier
JRJurman Oct 24, 2021
f18e844
fix docstring, update dependency name in config
JRJurman Oct 24, 2021
7e8d7fd
clean up layout for tasks test component
JRJurman Oct 24, 2021
c6842cf
Update README
JRJurman Oct 24, 2021
c8a677e
more strict typing
JRJurman Oct 25, 2021
771d55e
formatting for test app
JRJurman Oct 25, 2021
ca74d2a
Fix app by being dependent on loading
JRJurman Oct 29, 2021
31024f5
fix performance test ts
JRJurman Oct 29, 2021
8195f6b
use functions for node filter
JRJurman Oct 30, 2021
da0e1fb
typescript build config
JRJurman Nov 3, 2021
74e2788
use parcel 2.0
JRJurman Nov 3, 2021
2edd8c2
strictNullChecks, remove domino
JRJurman Nov 6, 2021
d7727f9
rearrange and expose types in main export
JRJurman Nov 8, 2021
1df7179
strict ruleset, update test files to verify type
JRJurman Nov 8, 2021
0968852
change to type module
JRJurman Nov 8, 2021
2914e36
update runkit example
JRJurman Nov 8, 2021
eb88229
update eslint, remove logs, expose TramOneElement
JRJurman Nov 10, 2021
adef448
fixes for code coverage
JRJurman Nov 10, 2021
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
fingerprints:
- "64:3e:d4:d8:4b:95:68:79:d3:3b:ab:b1:5c:fa:2d:3d"

- run: npm install
- run: npm ci
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this project originally predated npm ci, but now that it exists, we should be using that, and not regenerating the lock file on every PR.


- save_cache:
paths:
Expand Down
48 changes: 48 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
env: {
// allow document, window, etc (these are expected as a frontend-library)
browser: true,
},
plugins: ['jest', '@typescript-eslint'],
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'],
rules: {
// some of the dependencies do not support module imports... yet
'@typescript-eslint/no-var-requires': 'off',
// as a library, we have to sometimes just expect anything
'@typescript-eslint/no-explicit-any': 'off',
},
overrides: [
// allow module.exports for config, testing, and docs
{
files: [
'./*.js', // top level config
'./docs/runkit_example.js', // runkit example
'./integration-tests/broken-app/**.js', // tests that still need runtime import/export
],
env: {
commonjs: true,
},
},

// configure test files to be in the jest environment
{
files: ['integration-tests/**/*', 'performance-tests/**/*'],
env: {
jest: true,
},
rules: {
'@typescript-eslint/no-empty-function': 'off',
},
},

// local scripts are expected to run on local machines with node
{
files: ['dev-scripts/**/*.js'],
env: {
node: true,
},
},
],
};
12 changes: 0 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,8 @@ dist
# Coverage Report
coverage

# docma docs
docs/website

# Logs
logs
*.log
*.log.*

# Dependency directory
node_modules

# SSL certificates
.ssl

Comment on lines -18 to -20
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was most certainly an artifact of when we had the website hosted from this repo, since that is no longer a thing, we can remove this

# parcel test app files
dist
.parcel-cache
5 changes: 5 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
useTabs: true,
singleQuote: true,
printWidth: 120,
};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using prettier instead of xo.

The prettier config is more known to work with typescript, and xo was breaking too much.

Eventually I'd like to rip out the eslint config for tram-one projects as it is today. It really should be something that validates tram-one things (e.g., I would love to lint template spacing, and hook placement). Right now, it's just silly opinions, and that doesn't really help anyone.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This includes using semicolons (which sadly blows the number of lines changed for the project super high). ASI has burned me enough times (read, more than 0 times), and I think with the new Typescript syntax, it's easier if we are on the same standard as everyone else.

33 changes: 15 additions & 18 deletions configs/rollup.config.cjs.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
const filesize = require('rollup-plugin-filesize')
const commonjs = require('rollup-plugin-commonjs')
const pkg = require('../package.json')
import filesize from 'rollup-plugin-filesize';
import commonjs from 'rollup-plugin-commonjs';
import pkg from '../package.json';
import typescript from '@rollup/plugin-typescript';

const external = Object.keys(pkg.dependencies)
.concat([
'type/function/ensure',
'type/object/ensure',
'type/string/ensure',
'type/value/ensure'
])
const external = Object.keys(pkg.dependencies).concat([
'type/function/ensure',
'type/object/ensure',
'type/string/ensure',
'type/value/ensure',
]);

const plugins = [
commonjs(),
filesize()
]
const plugins = [typescript(), commonjs(), filesize()];

export default {
input: 'src/tram-one',
input: 'src/tram-one.ts',
external,
plugins,
output: {
file: pkg.commonjs,
exports: 'named',
format: 'cjs',
interop: false
}
}
interop: false,
},
};
32 changes: 17 additions & 15 deletions configs/rollup.config.umd.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
const builtins = require('rollup-plugin-node-builtins')
const commonjs = require('rollup-plugin-commonjs')
const filesize = require('rollup-plugin-filesize')
const globals = require('rollup-plugin-node-globals')
const resolve = require('rollup-plugin-node-resolve')
const { terser } = require('rollup-plugin-terser')
// const sizes = require('rollup-plugin-sizes')
import builtins from 'rollup-plugin-node-builtins';
import commonjs from 'rollup-plugin-commonjs';
import filesize from 'rollup-plugin-filesize';
import globals from 'rollup-plugin-node-globals';
import resolve from 'rollup-plugin-node-resolve';
import { terser } from 'rollup-plugin-terser';
import typescript from '@rollup/plugin-typescript';
// import sizes from 'rollup-plugin-sizes'

const pkg = require('../package.json')
import pkg from '../package.json';

const plugins = [
typescript(),
resolve({
preferBuiltins: true,
browser: true
browser: true,
}),
builtins(),
commonjs(),
globals(),
builtins(),
terser(),
// sizes(), // useful for finding large dependencies
filesize()
]
filesize(),
];

// domino is a package used by belit to support server side rendering,
// it does not need to be included in browser builds, which will have document
export default {
input: 'src/tram-one',
input: 'src/tram-one.ts',
external: ['domino'],
output: {
name: 'tram-one',
exports: 'named',
file: pkg.umd,
globals: { domino: 'domino' },
format: 'umd'
format: 'umd',
},
plugins
}
plugins,
};
10 changes: 5 additions & 5 deletions dev-scripts/badge.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = (label, value) => {
const labelWidth = label.length * 11
const valueWidth = 58 + (value.length * 4)
const labelOffset = 16.5
const labelWidth = label.length * 11;
const valueWidth = 58 + value.length * 4;
const labelOffset = 16.5;
return `<svg xmlns="http://www.w3.org/2000/svg" width="${valueWidth}" height="20">
<linearGradient id="b" x2="0" y2="100%">
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
Expand All @@ -22,5 +22,5 @@ module.exports = (label, value) => {
<text x="59" y="14">${value}</text>
</g>
</svg>
`
}
`;
};
40 changes: 20 additions & 20 deletions dev-scripts/build-size-badges.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
const path = require('path')
const fs = require('fs')
const badge = require('./badge')
const path = require('path');
const fs = require('fs');
const badge = require('./badge');

const buildPath = 'dist'
const destPath = 'docs/badges'
const units = ['B', 'kB', 'MB', 'GB']
const buildPath = 'dist';
const destPath = 'docs/badges';
const units = ['B', 'kB', 'MB', 'GB'];

// get filesize and transform to correct unit
const getSize = fileName => {
const bytes = fs.statSync(path.resolve(buildPath, fileName)).size
const n = Math.floor(Math.log(bytes) / Math.log(1024))
const formatted = (bytes / (1024 ** n)).toFixed(2)
return `${formatted} ${units[n]}`
}
const getSize = (fileName) => {
const bytes = fs.statSync(path.resolve(buildPath, fileName)).size;
const n = Math.floor(Math.log(bytes) / Math.log(1024));
const formatted = (bytes / 1024 ** n).toFixed(2);
return `${formatted} ${units[n]}`;
};

// generate an SVG string and write it to dest
const generateBadge = label => {
const value = getSize(`tram-one.${label}.js`)
const svg = badge(label, value)
const dest = path.resolve(destPath, `${label}.svg`)
fs.writeFile(dest, svg, err => err && process.stdout.write(err))
}
const generateBadge = (label) => {
const value = getSize(`tram-one.${label}.js`);
const svg = badge(label, value);
const dest = path.resolve(destPath, `${label}.svg`);
fs.writeFile(dest, svg, (err) => err && process.stdout.write(err));
};

generateBadge('cjs')
generateBadge('umd')
generateBadge('cjs');
generateBadge('umd');
4 changes: 2 additions & 2 deletions docs/badges/cjs.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions docs/badges/umd.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 7 additions & 7 deletions docs/runkit_example.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const { registerHtml } = require('tram-one')
const { registerHtml } = require('tram-one');

const html = registerHtml()
const html = registerHtml();
const home = () => {
return html`
<main>
<h1> Tram-One </h1>
<h2> A Modern View Framework for Vanilla Javascript </h2>
<h1>Tram-One</h1>
<h2>A Modern View Framework for Vanilla Javascript</h2>
</main>
`
}
`;
};

home().outerHTML
home().outerHTML;
13 changes: 0 additions & 13 deletions integration-tests/broken-app/broken-array.js

This file was deleted.

5 changes: 0 additions & 5 deletions integration-tests/broken-app/broken-empty.js

This file was deleted.

10 changes: 5 additions & 5 deletions integration-tests/broken-app/broken-hook.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const { registerHtml, useEffect } = require('../../src/tram-one')
const { registerHtml, useEffect } = require('../../src/tram-one');

const html = registerHtml()
const html = registerHtml();

// other hooks also generate the same error
// so we don't need to check those, just useEffect is fine
useEffect(() => {})
useEffect(() => {});

/**
* broken component misplaced hook
Expand All @@ -14,5 +14,5 @@ module.exports = () => {
<header>
<h1 class="title">Home Page</h1>
</header>
`
}
`;
};
6 changes: 0 additions & 6 deletions integration-tests/broken-app/broken-non-dom.js

This file was deleted.

Loading