Skip to content

Commit 4dc1b37

Browse files
committed
update to latest hyperapp and add html adapter for jsx
1 parent 12f4763 commit 4dc1b37

File tree

7 files changed

+66
-33
lines changed

7 files changed

+66
-33
lines changed

bin/index.js

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/usr/bin/env node
22

3-
const Module = require("module");
4-
53
const get = prop => value => value[prop];
64
const flatten = (others, next) => others.concat(next);
75
const getLoadersFromRules = (rules, path, loaderName) =>
@@ -25,22 +23,20 @@ if (!webpackConfig) {
2523
}
2624
const { module: { rules = [] } = {} } = webpackConfig;
2725

26+
// use for unminified prod builds
27+
// webpackConfig.optimization.minimize = false;
28+
2829
const eslintLoaders = getLoadersFromRules(rules, "use", "eslint");
2930
if (!eslintLoaders.length) {
3031
throw new Error(
3132
`missing ESLint config in webpack config: ${webpackConfigPath}`
3233
);
3334
}
3435
const eslintConfig = eslintLoaders[0].options.baseConfig;
36+
eslintConfig.settings = { react: { version: "latest" } };
3537
// override ESLint rules to allow using JSX with Hyperapp
3638
eslintConfig.rules = Object.assign(eslintConfig.rules || {}, {
37-
"react/react-in-jsx-scope": "off",
38-
"no-unused-vars": [
39-
"warn",
40-
{
41-
varsIgnorePattern: "^h$"
42-
}
43-
]
39+
"react/react-in-jsx-scope": "off"
4440
});
4541

4642
const babelLoaders = getLoadersFromRules(rules, "oneOf", "babel");
@@ -55,10 +51,11 @@ babelOptions.plugins = (babelOptions.plugins || []).concat([
5551
[
5652
"@babel/transform-react-jsx",
5753
{
58-
pragma: "h",
54+
pragma: "__hyperapp_html",
5955
useBuiltIns: true
6056
}
61-
]
57+
],
58+
require.resolve("./injectHtmlImportPlugin")
6259
]);
6360

6461
// override config in cache
@@ -76,14 +73,5 @@ require.cache[require.resolve(createJestConfigPath)].exports = (...args) => {
7673
return jestConfig;
7774
};
7875

79-
// Mock React module with dummy latest version
80-
require.cache[require.resolve("resolve")].exports.sync = require.resolve;
81-
const _resolveFilename = Module._resolveFilename;
82-
Module._resolveFilename = (request, parent) =>
83-
request === "react" ? "react" : _resolveFilename(request, parent);
84-
require.cache["react"] = {
85-
exports: { version: "999.999.999" }
86-
};
87-
8876
// call original react script
8977
require(`react-scripts/scripts/${script}.js`);

bin/injectHtmlImportPlugin.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module.exports = ({ types: t }) => ({
2+
name: "inject-hyperapp-html-import",
3+
visitor: {
4+
Program(path) {
5+
path.unshiftContainer(
6+
"body",
7+
t.importDeclaration(
8+
[
9+
t.importSpecifier(
10+
t.identifier("__hyperapp_html"),
11+
t.identifier("__hyperapp_html")
12+
)
13+
],
14+
t.stringLiteral("hyperapp-scripts")
15+
)
16+
);
17+
}
18+
}
19+
});

example/src/App.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { h } from "hyperapp";
21
import logo from "./logo.svg";
32
import "./App.css";
43

example/src/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
import { h, app } from "hyperapp";
1+
import { app } from "hyperapp";
22
import "./index.css";
33
import App from "./App";
44

5-
app({ view: () => <App />, node: document.getElementById("app") });
5+
app({
6+
init: {},
7+
view: () => <App />,
8+
node: document.getElementById("app")
9+
});

index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { h, text } from "hyperapp";
2+
3+
const mapChildren = child =>
4+
typeof child === "string" || typeof child === "number" ? text(child) : child;
5+
6+
export const __hyperapp_html = (tag, props, ...children) =>
7+
typeof tag === "function"
8+
? tag(props, children)
9+
: h(tag, props || {}, children.map(mapChildren));

package.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
{
22
"name": "hyperapp-scripts",
3-
"version": "0.4.0",
3+
"version": "0.5.0",
44
"description": "Hyperapp expansion pack for create-react-app",
55
"bin": {
66
"hyperapp-scripts": "./bin/index.js"
77
},
8+
"main": "index.js",
89
"scripts": {
9-
"clean": "npx rimraf node_modules example/{node_modules,build}",
10-
"format": "npx prettier --write bin/*.js example/src/**/*.{css,js}",
11-
"format:check": "npx prettier --list-different bin/*.js example/src/**/*.{css,js}",
10+
"clean": "npx --ignore-existing --quiet rimraf node_modules example/{node_modules,build}",
11+
"format": "npx prettier --write *.js bin/*.js example/src/**/*.{css,js}",
12+
"format:check": "npx prettier --list-different *.js bin/*.js example/src/**/*.{css,js}",
1213
"setup": "npm i && cd example && npm i",
1314
"start": "npm run setup && cd example && npm start",
14-
"test": "npm run clean && npm run setup && cd example && npm run build && cross-env CI=1 npm test",
15+
"test": "npm run setup && cd example && npm run build && cross-env CI=1 npm test",
1516
"check": "npm run format:check && npm test",
16-
"release": "node pre-flight-tests && npm run check && git tag $npm_package_version && git push && git push --tags && npm publish"
17+
"release:dry": "npm run clean && npm run check",
18+
"release": "node release"
1719
},
1820
"dependencies": {
1921
"react-scripts": "=3.0.0"
2022
},
2123
"devDependencies": {
2224
"cross-env": "=7.0.2",
23-
"hyperapp": "=2.0.4"
25+
"hyperapp": "=2.0.8"
2426
},
2527
"peerDependencies": {
2628
"hyperapp": "*"

pre-flight-tests renamed to release.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
#!/usr/bin/env node
2-
3-
// eslint-disable-next-line no-undef
41
const { execSync } = require("child_process");
2+
const { version } = require("./package");
53
const exec = command => execSync(command, { encoding: "utf8" }).trim();
64

75
const exitWithError = error => {
@@ -18,3 +16,17 @@ const workingCopyChanges = exec("git status --porcelain");
1816
if (workingCopyChanges) {
1917
exitWithError("please commit your changes before making a release!");
2018
}
19+
20+
const tagExists = exec(`git tag -l "${version}"`);
21+
if (tagExists) {
22+
exitWithError(`${version} has already been released!`);
23+
}
24+
25+
execSync(
26+
`npm run release:dry && git tag ${version} && git push && git push --tags && npm publish`,
27+
{
28+
shell: true,
29+
stdio: "inherit",
30+
cwd: __dirname
31+
}
32+
);

0 commit comments

Comments
 (0)