Skip to content

Commit

Permalink
drop support for node < v14
Browse files Browse the repository at this point in the history
  • Loading branch information
75lb committed Jul 6, 2021
1 parent 366ff72 commit 6fc8776
Show file tree
Hide file tree
Showing 10 changed files with 4,119 additions and 641 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x, 15.x, 16.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm test
5 changes: 0 additions & 5 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016-20 Lloyd Brookes <75pound@gmail.com>
Copyright (c) 2016-21 Lloyd Brookes <75pound@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[![view on npm](https://img.shields.io/npm/v/lws-spa.svg)](https://www.npmjs.org/package/lws-spa)
[![npm module downloads](https://img.shields.io/npm/dt/lws-spa.svg)](https://www.npmjs.org/package/lws-spa)
[![Build Status](https://travis-ci.org/lwsjs/spa.svg?branch=master)](https://travis-ci.org/lwsjs/spa)
[![Dependency Status](https://badgen.net/david/dep/lwsjs/spa)](https://david-dm.org/lwsjs/spa)
[![Coverage Status](https://coveralls.io/repos/github/lwsjs/spa/badge.svg)](https://coveralls.io/github/lwsjs/spa)
[![view on npm](https://badgen.net/npm/v/lws-spa)](https://www.npmjs.org/package/lws-spa)
[![npm module downloads](https://badgen.net/npm/dt/lws-spa)](https://www.npmjs.org/package/lws-spa)
[![Gihub repo dependents](https://badgen.net/github/dependents-repo/lwsjs/lws-spa)](https://github.com/lwsjs/lws-spa/network/dependents?dependent_type=REPOSITORY)
[![Gihub package dependents](https://badgen.net/github/dependents-pkg/lwsjs/lws-spa)](https://github.com/lwsjs/lws-spa/network/dependents?dependent_type=PACKAGE)
[![Node.js CI](https://github.com/lwsjs/lws-spa/actions/workflows/node.js.yml/badge.svg)](https://github.com/lwsjs/lws-spa/actions/workflows/node.js.yml)
[![Coverage Status](https://coveralls.io/repos/github/lwsjs/lws-spa/badge.svg)](https://coveralls.io/github/lwsjs/lws-spa)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](https://github.com/feross/standard)

# lws-spa
Expand All @@ -23,6 +24,6 @@ Adds the following options to lws.

* * *

&copy; 2016-20 Lloyd Brookes \<75pound@gmail.com\>.
&copy; 2016-21 Lloyd Brookes \<75pound@gmail.com\>.

Tested by [test-runner](https://github.com/test-runner-js/test-runner).
11 changes: 5 additions & 6 deletions index.js → index.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const EventEmitter = require('events')
import EventEmitter from 'events'
import path from 'path'
import fs from 'fs'
import send from 'koa-send'

class SPA extends EventEmitter {
description () {
Expand Down Expand Up @@ -31,7 +34,6 @@ class SPA extends EventEmitter {
middleware (options) {
const spa = options.spa
if (spa) {
const path = require('path')
const root = path.resolve(options.directory || process.cwd())
this.emit('verbose', 'middleware.spa.config', { spa, root, spaAssetTest: options.spaAssetTest, spaAssetTestFs: options.spaAssetTestFs })
return function (ctx, next) {
Expand All @@ -41,16 +43,13 @@ class SPA extends EventEmitter {
const re = new RegExp(options.spaAssetTest)
isStatic = re.test(route)
} else if (options.spaAssetTestFs && route !== '/') {
const fs = require('fs')
const URL = require('url').URL // required for node v8
const url = new URL(route, 'http://localhost')
const filePath = path.join(root, url.pathname)
isStatic = fs.existsSync(filePath)
} else {
isStatic = /\./.test(route)
}
if (ctx.accepts('text/html') && !isStatic) {
const send = require('koa-send')
return send(ctx, spa, { root })
} else {
return next()
Expand All @@ -60,4 +59,4 @@ class SPA extends EventEmitter {
}
}

module.exports = SPA
export default SPA

0 comments on commit 6fc8776

Please sign in to comment.