Skip to content

Commit

Permalink
chore(release): 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Feb 25, 2019
1 parent b1421fd commit ffc16ff
Show file tree
Hide file tree
Showing 13 changed files with 5,025 additions and 5,599 deletions.
71 changes: 71 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"use strict";

const presets = require("eslint-plugin-itgalaxy");

module.exports = {
extends: [
"plugin:itgalaxy/jest",
"plugin:itgalaxy/esnext",
"plugin:itgalaxy/node",
"plugin:itgalaxy/markdown"
],
overrides: [
// Jest
{
env: {
browser: true,
node: true
},
files: ["**/__tests__/**/*"],
parserOptions: {
sourceType: "module"
},
rules: {
// Allow to use `console` (example - `mocking`)
"no-console": "off",
// Allow all `es` features in tests, because we use `babel`
"node/no-unsupported-features/es-syntax": "off"
}
},

// Configurations and node stuff
{
env: {
browser: false,
node: true
},
excludedFiles: ["src/**/*", "**/__tests__/**/*"],
files: [".*.*", "**/*"],
parserOptions: {
sourceType: "script"
},
rules: {
"no-console": "off",
"node/shebang": "off"
}
},

// Markdown
{
env: {
browser: true,
node: true
},
files: ["**/*.md"],
parserOptions: {
ecmaFeatures: {
impliedStrict: true
}
},
rules: {
"import/no-unresolved": "off",
"no-console": "off",
"no-undef": "off",
"no-unused-vars": "off",
"node/no-unpublished-require": "off",
strict: "off"
}
}
],
root: true
};
5 changes: 5 additions & 0 deletions .remarkrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";

module.exports = {
plugins: ["remark-preset-lint-itgalaxy"]
};
28 changes: 16 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
sudo: false

git:
depth: 1
depth: 10

branches:
only:
- master
- next
- /^greenkeeper/.*$/

language: node_js

# cache node modules
cache:
directories:
- $HOME/.npm
Expand All @@ -19,22 +19,26 @@ cache:
matrix:
fast_finish: true
include:
- node_js: '10'
script: npm run $JOB_PART
- node_js: '11'
env: JOB_PART=pretest
- node_js: '10'
script: npm run $JOB_PART
- node_js: '6'
env: JOB_PART=test-only
- node_js: '8'
script: npm run $JOB_PART
env: JOB_PART=test-only
- node_js: '6'
script: npm run $JOB_PART
- node_js: '10'
env: JOB_PART=test-only
- node_js: '11'
env: JOB_PART=test-only
sudo: required

before_install:
- npm i -g npm@latest
- nvm --version
- npm install -g npm@latest

install:
- npm ci

before_script:
- node --version
- npm --version

script:
- npm run $JOB_PART
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ All notable changes to this project will be documented in this file.

This project adheres to [Semantic Versioning](http://semver.org).

## 3.0.0 - 2019-02-25

- Changed: revert support for `koa` in favor `express` (due `webpack` organization problems around `webpack-dev-server`).

## 2.0.0 - 2018-05-11

* Changed: drop support `express` (includes `webpack-dev-server`) in favor `koa` (includes `webpack-serve`).
- Changed: drop support `express` (includes `webpack-dev-server`) in favor `koa` (includes `webpack-serve`).

## 1.0.0 - 2017-12-20

* Chore: public initial release.
- Chore: public initial release.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017-2018 itgalaxy inc.
Copyright (c) 2017-present itgalaxy inc.

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
41 changes: 16 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ Returns Express middleware that serves a service worker that resets any previous
npm i -D noop-service-worker-middleware
```

**NOTE:**
`noop-service-worker-middleware@1` support only `express` (includes `webpack-dev-server`).
`noop-service-worker-middleware@2` support only `koa` (includes `webpack-serve`).

## API

```js
Expand All @@ -40,39 +36,30 @@ app.use(noopServiceWorkerMiddleware("/custom-service-worker.js"));

## Examples

Simple app:
### Simple

```js
const Koa = require("koa");
const Router = require("koa-router");
const noopServiceWorkerMiddleware = require("..");
const express = require("express");
const noopServiceWorkerMiddleware = require("noop-service-worker-middleware");

const app = new Koa();
const router = new Router();
const app = express();

app.use(noopServiceWorkerMiddleware());
app.use(noopServiceWorkerMiddleware("/custom-service-worker.js"));

router.get("/", (ctx, next) => {
ctx.body = "Hello World!";

return next();
app.get("/", (req, res) => {
res.send("hello, world!");
});

app.use(router.routes()).listen(8080);

module.exports = app;
```

[webpack-serve](https://github.com/webpack-contrib/webpack-serve):
### Webpack Dev Server

```js
const noopServiceWorkerMiddleware = require("noop-service-worker-middleware");

module.exports = {
// ...
serve: {
add(app) {
devServer: {
before(app, server) {
app.use(noopServiceWorkerMiddleware());
}
// ...
Expand All @@ -83,8 +70,12 @@ module.exports = {

## Thanks

* [create-react-app](https://github.com/facebookincubator/create-react-app) - inspiration.
- [create-react-app](https://github.com/facebookincubator/create-react-app) - inspiration.

## Changelog

[Changelog](CHANGELOG.md)

## [Changelog](CHANGELOG.md)
## License

## [License](LICENSE)
[MIT](./LICENSE)
14 changes: 4 additions & 10 deletions __tests__/app.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
const Koa = require("koa");
const Router = require("koa-router");
const express = require("express");
const noopServiceWorkerMiddleware = require("..");

const app = new Koa();
const router = new Router();
const app = express();

app.use(noopServiceWorkerMiddleware());
app.use(noopServiceWorkerMiddleware("/custom-service-worker.js"));

router.get("/", (ctx, next) => {
ctx.body = "Hello World!";

return next();
app.get("/", (req, res) => {
res.status(200).send("Hello World!");
});

app.use(router.routes());

module.exports = app;
67 changes: 67 additions & 0 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const got = require("got");
const app = require("./app");

const port = 3100;

jest.setTimeout(100000);

describe("basic", () => {
let server = null;

beforeAll(
() =>
new Promise((resolve, reject) => {
server = app.listen(port, error => {
if (error) {
return reject(error);
}

return resolve();
});
})
);

afterAll(() => server && server.close());

it("should responses with code 200", () => {
expect.assertions(3);

return got(`http://localhost:${port}`).then(response => {
expect(response.headers["content-type"]).toBe("text/html; charset=utf-8");
expect(response.statusCode).toBe(200);
expect(response.body).toBe("Hello World!");

return Promise.resolve();
});
});

it("should responses with code 200 and return service worker noop code", () => {
expect.assertions(3);

return got(`http://127.0.0.1:${port}/service-worker.js`).then(response => {
expect(response.headers["content-type"]).toBe(
"text/javascript; charset=utf-8"
);
expect(response.statusCode).toBe(200);
expect(response.body).not.toHaveLength(0);

return Promise.resolve();
});
});

it("should responses with code 200 and return service worker noop code (custom name)", () => {
expect.assertions(3);

return got(`http://127.0.0.1:${port}/custom-service-worker.js`).then(
response => {
expect(response.headers["content-type"]).toBe(
"text/javascript; charset=utf-8"
);
expect(response.statusCode).toBe(200);
expect(response.body).not.toHaveLength(0);

return Promise.resolve();
}
);
});
});
40 changes: 0 additions & 40 deletions __tests__/integration.test.js

This file was deleted.

7 changes: 7 additions & 0 deletions husky.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"use strict";

module.exports = {
hooks: {
"pre-commit": "lint-staged"
}
};
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ module.exports = function createNoopServiceWorkerMiddleware(
path = "/service-worker.js"
) {
// eslint-disable-next-line consistent-return
return function noopServiceWorkerMiddleware(context, next) {
if (context.request && context.request.url === path) {
context.set("Content-Type", "text/javascript");
context.body = `// This service worker file is effectively a 'no-op' that will reset any
return function noopServiceWorkerMiddleware(req, res, next) {
if (req.url === path) {
res.setHeader("Content-Type", "text/javascript");
res.send(`// This service worker file is effectively a 'no-op' that will reset any
// previous service worker registered for the same host:port combination.
// In the production build, this file is replaced with an actual service worker
// file that will precache your site's local assets.
Expand All @@ -23,7 +23,7 @@ self.addEventListener('activate', () => {
}
});
});
`;
`);
} else {
return next();
}
Expand Down
Loading

0 comments on commit ffc16ff

Please sign in to comment.