Skip to content
Merged

Next #173

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
a50cd7d
:arrow_up: Webpack v5 and fix main deprecated
GuiDevloper Dec 21, 2021
951db8c
:arrow_up: :rotating_light: Upgrade deprecated webpack plugins
GuiDevloper Dec 28, 2021
bda72bf
:triangular_flag_on_post: :bug: Improve and make cache optional on build
GuiDevloper Dec 28, 2021
754c60c
Merge branch 'next' into wp-5-upgrade
GuiDevloper Dec 28, 2021
e72fea2
Merge branch 'next' into wp-5-upgrade
GuiDevloper Jan 2, 2022
5938fec
Merge remote-tracking branch 'upstream/master' into wp-5-upgrade
GuiDevloper Jan 17, 2022
f8270fb
:bug: Support webpack 5 error handling
GuiDevloper Jan 17, 2022
f237970
:green_heart: Exit CI on build error
GuiDevloper Jan 18, 2022
6418606
:white_check_mark: Run build before running tests
GuiDevloper Jan 18, 2022
2ac50c3
:heavy_plus_sign: Unify tests processes with jest-puppeteer
GuiDevloper Jan 20, 2022
d30a389
:green_heart: Add Puppeteer CI config & teardown
GuiDevloper Jan 20, 2022
cc9684f
:green_heart: Add Github Action to test PRs
GuiDevloper Jan 20, 2022
0d77ac9
:green_heart: Remove the need for a jest-environment
GuiDevloper Jan 20, 2022
5f94cc2
:white_check_mark: Remove tests boilerplate & support CI pt1
GuiDevloper Jan 20, 2022
94e3852
:white_check_mark: Remove tests boilerplate & support CI pt2
GuiDevloper Jan 20, 2022
bad367c
:white_check_mark: Remove tests boilerplate & support CI pt3
GuiDevloper Jan 20, 2022
1b0cb8d
:bug: Replace inexistent `rmSync` with `removeSync` on builds
GuiDevloper Jan 22, 2022
8fa1b4f
Merge pull request #153 from GuiDevloper/build-error-exit
Mortaro Jan 22, 2022
6dd7dfb
Merge pull request #154 from GuiDevloper/build-before-tests
Mortaro Jan 22, 2022
d49b454
Merge pull request #156 from GuiDevloper/fix-clean-builds
Mortaro Jan 22, 2022
f4e4ef6
:white_check_mark: Replace tests use of `browser` for `context`
GuiDevloper Jan 23, 2022
b199bfd
:white_check_mark: Remove use of `Boolean` from tests
GuiDevloper Jan 24, 2022
0b188ee
:white_check_mark: Remove local `newPage` use from every test
GuiDevloper Jan 25, 2022
b52dd7b
:sparkles: launch lifecycle
Mortaro Jan 26, 2022
1bcd205
:white_check_mark: update launch tests
Mortaro Jan 28, 2022
ea7584a
:white_check_mark: improve lifecycle testing
Mortaro Jan 28, 2022
cd265d8
Merge pull request #157 from nullstack/launch-lifecycle
Mortaro Jan 29, 2022
5f4c225
Merge pull request #158 from nullstack/gui-scripts
Mortaro Jan 29, 2022
493d70c
Merge remote-tracking branch 'upstream/next' into next
GuiDevloper Jan 29, 2022
d26e75d
Merge branch 'next' into wp-5-upgrade
GuiDevloper Jan 29, 2022
e7c9378
Merge pull request #155 from GuiDevloper/tests-ci
Mortaro Jan 30, 2022
6be3da4
Merge pull request #144 from GuiDevloper/wp-5-upgrade
Mortaro Jan 30, 2022
2aca329
Merge pull request #159 from nullstack/unstable-next
Mortaro Feb 6, 2022
a0b34bd
:white_check_mark: add testcase for ternaries
Mortaro Feb 7, 2022
8c4617d
Merge pull request #160 from nullstack/component-ternary-tests
Mortaro Feb 7, 2022
83f0c17
:bug: allow anchor modifiers
Mortaro Feb 9, 2022
b813c9b
Merge pull request #162 from nullstack/anchor-modifiers
Mortaro Feb 10, 2022
35bd0fa
:wrench: copy robots.txt
Mortaro Feb 14, 2022
8777337
Merge pull request #163 from nullstack/copy-robots
Mortaro Feb 14, 2022
5166022
:adhesive_bandage: anchor html events first render
Mortaro Feb 15, 2022
1b71317
:white_check_mark: :test_tube: Add tests for html-injected links wron…
GuiDevloper Feb 15, 2022
a71c53d
Merge pull request #165 from GuiDevloper/archor-html-events
Mortaro Feb 15, 2022
1f052d0
:construction: innerhtml anchor changes
Mortaro Feb 16, 2022
9529a86
:sparkles: Add metakey on anchor html events
guilhermeborbadev Feb 17, 2022
e9f5787
Merge pull request #167 from guilhermedeborba/anchor-html-events-metakey
Mortaro Feb 17, 2022
c5b23d3
:recycle: refactor tests for cross platform
Mortaro Feb 17, 2022
990f74f
:white_check_mark: Tests for injected links not getting events
GuiDevloper Feb 18, 2022
419a64e
:bug: fix undefined event render
Mortaro Feb 19, 2022
5c9be12
:recycle: Refactor tests for html-injected links
GuiDevloper Feb 19, 2022
6220fc1
Merge pull request #169 from nullstack/undefined-events
Mortaro Feb 20, 2022
1020166
:bookmark: version 0.14
Mortaro Feb 20, 2022
b9aa877
Merge pull request #170 from nullstack/zero-fourteen
Mortaro Feb 20, 2022
af157d3
Merge pull request #164 from nullstack/anchor-html-events
Mortaro Feb 20, 2022
de205f6
Merge pull request #171 from GuiDevloper/archor-html-events
Mortaro Feb 20, 2022
6155c36
:recycle: refactor inner html tests
Mortaro Feb 20, 2022
4855655
Merge pull request #172 from nullstack/unstable-next
Mortaro Feb 20, 2022
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
51 changes: 51 additions & 0 deletions .github/workflows/pr-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Nullstack Tests

on:
pull_request:
branches: [ master, next ]

jobs:
build:

runs-on: ubuntu-latest
container: lironavon/docker-puppeteer-container:14.16.0
env:
CI: true

strategy:
matrix:
node-version: [12.20.0, 14.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v2
# cache the dependencies from any node_modules directory
- name: Cache dependencies
uses: actions/cache@v2
with:
path: |
**/node_modules
**/package-lock.json
key: node_modules-${{ matrix.node-version }}-${{ hashFiles('**/package.json') }}

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}

- name: Install and link main deps
run: |
npm install
npm link

- name: Install deps at tests folder
working-directory: ./tests
run: |
npm link nullstack
npm install

- name: Run tests
working-directory: ./tests
run: npm test
15 changes: 11 additions & 4 deletions builders/spa.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
module.exports = async function spa(folder = 'spa') {
module.exports = async function spa({ output, cache }) {
const folder = output || 'spa';
process.env.NULLSTACK_ENVIRONMENT_MODE = 'spa';

const dir = process.cwd();
const application = require(`${dir}/.production/server`).default
const { existsSync, mkdirSync, writeFileSync, copySync, rmSync } = require('fs-extra');
const { existsSync, mkdirSync, writeFileSync, copySync, removeSync } = require('fs-extra');
const path = `${dir}/${folder}`;

async function copy(url, file) {
Expand All @@ -19,7 +20,7 @@ module.exports = async function spa(folder = 'spa') {

console.log()
if (existsSync(path)) {
rmSync(path, { recursive: true });
removeSync(path);
}
mkdirSync(path)
console.log(` ⚙️ /public/`)
Expand All @@ -29,8 +30,14 @@ module.exports = async function spa(folder = 'spa') {
copySync(`${dir}/.production`, path, { filter })
await copy(`/manifest.json`)
await copy(`/service-worker.js`)
await copy('/robots.txt')
console.log()

console.log('\x1b[36m%s\x1b[0m', ` ✅️ ${application.project.name} is ready at ${folder}\n`);
process.exit()

if (cache) {
console.log('Storing cache...');
} else {
process.exit();
}
}
15 changes: 11 additions & 4 deletions builders/ssg.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
module.exports = async function ssg(folder = 'ssg') {
module.exports = async function ssg({ output, cache }) {
const folder = output || 'ssg';
process.env.NULLSTACK_ENVIRONMENT_MODE = 'ssg';

const dir = process.cwd();
const application = require(`${dir}/.production/server`).default;
const { resolve } = require('path')
const { existsSync, mkdirSync, writeFileSync, copySync, rmSync } = require('fs-extra');
const { existsSync, mkdirSync, writeFileSync, copySync, removeSync } = require('fs-extra');

function path(file = '') {
const target = file.startsWith('/') ? file.slice(1) : file;
Expand Down Expand Up @@ -85,7 +86,7 @@ module.exports = async function ssg(folder = 'ssg') {

console.log()
if (existsSync(path())) {
rmSync(path(), { recursive: true });
removeSync(path());
}
mkdirSync(path())
console.log(` ⚙️ /public/`)
Expand All @@ -97,9 +98,15 @@ module.exports = async function ssg(folder = 'ssg') {
await copyRoute(`/404`);
await copyBundle(`/manifest.json`)
await copyBundle(`/service-worker.js`)
await copyBundle('/robots.txt')
await createSitemap()
console.log()

console.log('\x1b[36m%s\x1b[0m', ` ✅️ ${application.project.name} is ready at ${folder}\n`);
process.exit()

if (cache) {
console.log('Storing cache...');
} else {
process.exit();
}
}
8 changes: 6 additions & 2 deletions builders/ssr.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
module.exports = async function ssr() {
module.exports = async function ssr({ cache }) {
const dir = process.cwd();
const application = require(`${dir}/.production/server`).default;

console.log('\x1b[36m%s\x1b[0m', `\n ✅️ ${application.project.name} is ready for production\n`);

process.exit()
if (cache) {
console.log('Storing cache...');
} else {
process.exit();
}
}
20 changes: 12 additions & 8 deletions client/anchorableNode.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import router from './router';
import router from './router'

export function anchorableElement(element) {
const links = element.querySelectorAll('a[href^="/"]:not([target])');
for(const link of links) {
link.onclick = (event) => {
event.preventDefault();
router.url = link.getAttribute('href');
};
const links = element.querySelectorAll('a[href^="/"]:not([target])')
for (const link of links) {
if (link.dataset.nullstack) return
link.dataset.nullstack = true
link.addEventListener('click', (event) => {
if (!event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey) {
event.preventDefault()
router.url = link.getAttribute('href')
}
})
}
}
}
9 changes: 5 additions & 4 deletions client/client.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import router from './router';
import rerender from './rerender';
import context, { generateContext } from './context';

import generateTree from '../shared/generateTree';
import { loadPlugins } from '../shared/plugins';
import context, { generateContext } from './context';
import rerender from './rerender';
import router from './router';


const client = {};

Expand Down Expand Up @@ -53,6 +53,7 @@ client.processLifecycleQueues = async function () {
for (const instance of initiationQueue) {
instance.initiate && await instance.initiate();
instance._self.initiated = true;
instance.launch && instance.launch()
}
if (initiationQueue.length) {
client.update();
Expand Down
56 changes: 29 additions & 27 deletions client/render.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,64 @@
import {isFalse, isText} from '../shared/nodes';
import {anchorableElement} from './anchorableNode';
import { isFalse, isText } from '../shared/nodes';
import { anchorableElement } from './anchorableNode';

export default function render(node, options) {

if(isFalse(node) || node.type === 'head') {
if (isFalse(node) || node.type === 'head') {
return document.createComment("");
}

if(isText(node)) {
if (isText(node)) {
return document.createTextNode(node);
}

const svg = (options && options.svg) || node.type === 'svg';

let element;
if(svg) {
if (svg) {
element = document.createElementNS("http://www.w3.org/2000/svg", node.type);
} else {
element = document.createElement(node.type);
}

if(node.instance) {
if (node.instance) {
node.instance._self.element = element;
}

for(let name in node.attributes) {
if(name === 'html') {
for (let name in node.attributes) {
if (name === 'html') {
element.innerHTML = node.attributes[name];
anchorableElement(element);
} else if(name.startsWith('on')) {
const eventName = name.replace('on', '');
const key = '_event.' + eventName;
node[key] = (event) => {
if(node.attributes.default !== true) {
event.preventDefault();
}
node.attributes[name]({...node.attributes, event});
};
element.addEventListener(eventName, node[key]);
} else if (name.startsWith('on')) {
if (node.attributes[name] !== undefined) {
const eventName = name.replace('on', '');
const key = '_event.' + eventName;
node[key] = (event) => {
if (node.attributes.default !== true) {
event.preventDefault();
}
node.attributes[name]({ ...node.attributes, event });
};
element.addEventListener(eventName, node[key]);
}
} else {
const type = typeof(node.attributes[name]);
if(type !== 'object' && type !== 'function') {
if(name != 'value' && node.attributes[name] === true) {
const type = typeof (node.attributes[name]);
if (type !== 'object' && type !== 'function') {
if (name != 'value' && node.attributes[name] === true) {
element.setAttribute(name, '');
} else if(name == 'value' || (node.attributes[name] !== false && node.attributes[name] !== null && node.attributes[name] !== undefined)) {
} else if (name == 'value' || (node.attributes[name] !== false && node.attributes[name] !== null && node.attributes[name] !== undefined)) {
element.setAttribute(name, node.attributes[name]);
}
}
}
}

if(!node.attributes.html) {
for(let i = 0; i < node.children.length; i++) {
const child = render(node.children[i], {svg});
if (!node.attributes.html) {
for (let i = 0; i < node.children.length; i++) {
const child = render(node.children[i], { svg });
element.appendChild(child);
}
if(node.type == 'select') {

if (node.type == 'select') {
element.value = node.attributes.value;
}
}
Expand Down
2 changes: 1 addition & 1 deletion client/rerender.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ export default function rerender(selector, current, next) {
if (name === 'html') {
if (next.attributes[name] !== current.attributes[name]) {
selector.innerHTML = next.attributes[name];
anchorableElement(selector);
}
anchorableElement(selector);
} else if (name === 'checked') {
if (next.attributes[name] !== selector.value) {
selector.checked = next.attributes[name];
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nullstack",
"version": "0.13.0",
"version": "0.14.0",
"description": "Full-stack Javascript Components for one-dev armies",
"main": "nullstack.js",
"author": "Mortaro",
Expand Down Expand Up @@ -35,17 +35,17 @@
"fs-extra": "^10.0.0",
"glob": "^7.1.7",
"ignore-loader": "^0.1.2",
"mini-css-extract-plugin": "^0.9.0",
"mini-css-extract-plugin": "^2.4.5",
"node-fetch": "3.0.0",
"nodemon-webpack-plugin": "^4.3.1",
"purgecss-webpack-plugin": "^2.2.0",
"purgecss-webpack-plugin": "^4.1.3",
"raw-loader": "^4.0.2",
"sass": "^1.32.11",
"sass-loader": "^8.0.2",
"string-replace-loader": "^2.2.0",
"terser-webpack-plugin": "^2.3.5",
"webpack": "^4.42.1",
"webpack-cli": "^3.3.11",
"string-replace-loader": "^3.1.0",
"terser-webpack-plugin": "^5.3.0",
"webpack": "^5.65.0",
"webpack-cli": "^4.9.1",
"webpack-livereload-plugin": "^2.3.0",
"ws": "^7.4.4"
}
Expand Down
25 changes: 14 additions & 11 deletions plugins/anchorable.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@ function match(node) {
)
}

function transform({node, router}) {
if(!match(node)) return;
const originalEvent = node.attributes.onclick;
node.attributes.onclick = ({event}) => {
event.preventDefault();
router.url = node.attributes.href;
if(originalEvent) {
function transform({ node, router }) {
if (!match(node)) return
const originalEvent = node.attributes.onclick
node.attributes.default = true
node.attributes.onclick = ({ event }) => {
if (!event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey) {
event.preventDefault()
router.url = node.attributes.href
}
if (originalEvent) {
setTimeout(() => {
originalEvent({...node.attributes, event});
}, 0);
originalEvent({ ...node.attributes, event })
}, 0)
}
};
}
}

export default { transform, client: true }
export default { transform, client: true }
Loading