@rollup-extras/plugin-serve 1.2.5 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 Konstantin Shutkin
3
+ Copyright (c) 2023 Konstantin Shutkin
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -137,4 +137,4 @@ type ServePluginOptions = {
137
137
 
138
138
  # License
139
139
 
140
- [MIT](./LICENSE)
140
+ [MIT](https://github.com/kshutkin/rollup-extras/blob/main/LICENSE)
package/dist/index.cjs CHANGED
@@ -9,88 +9,91 @@ var options = require('@rollup-extras/utils/options');
9
9
  var logger = require('@rollup-extras/utils/logger');
10
10
  var mutliConfigPluginBase = require('@rollup-extras/utils/mutli-config-plugin-base');
11
11
 
12
- let globalServer;
13
- const factories = { logger };
14
- function index (options$1 = {}) {
15
- const normalizedOptions = options.getOptions(options$1, {
16
- pluginName: '@rollup-extras/plugin-serve',
17
- useWriteBundle: true,
18
- port: 8080,
19
- useKoaLogger: true
20
- }, 'dirs', factories);
21
- const { pluginName, useWriteBundle, port, host, https: https$1, useKoaLogger, customizeKoa, koaStaticOptions, onListen, logger } = normalizedOptions;
22
- const instance = mutliConfigPluginBase.multiConfigPluginBase(useWriteBundle, pluginName, serve);
23
- let { dirs } = normalizedOptions, collectDirs = false, started = false, watchMode = true;
24
- const pluginInstance = Object.assign(Object.assign({}, instance), { outputOptions });
25
- if (!dirs) {
26
- dirs = [];
27
- collectDirs = true;
28
- pluginInstance.renderStart = renderStart;
29
- }
30
- return pluginInstance;
31
- function renderStart(outputOptions, inputOptions) {
32
- instance.renderStart.call(this, outputOptions, inputOptions);
33
- if (collectDirs) {
34
- if (outputOptions.dir) {
35
- dirs.push(outputOptions.dir);
36
- }
37
- }
38
- }
39
- function outputOptions() {
40
- watchMode = this.meta.watchMode;
41
- return null;
42
- }
43
- async function serve() {
44
- if (!started && watchMode) {
45
- started = true;
46
- if (globalServer) {
47
- await new Promise(resolve => globalServer.close(resolve));
48
- globalServer = undefined;
49
- }
50
- const app = new Koa();
51
- if (customizeKoa) {
52
- customizeKoa(app);
53
- }
54
- if (useKoaLogger) {
55
- app.use(koaLogger());
56
- }
57
- for (const dir of dirs) {
58
- app.use(serveStatic(dir, koaStaticOptions));
59
- }
60
- const server = globalServer = https$1 ? https.createServer(https$1, app.callback()) : http.createServer(app.callback());
61
- const listenCb = () => internalOnListen(server);
62
- if (host) {
63
- server.listen(port, host, listenCb);
64
- }
65
- else {
66
- server.listen(port, listenCb);
67
- }
68
- server.on('error', (e) => {
69
- if (e.code === 'EADDRINUSE') {
70
- logger.finish('address in use, please try another port', 3 /* LogLevel.error */);
71
- }
72
- else {
73
- throw e;
74
- }
75
- });
76
- }
77
- }
78
- function internalOnListen(server) {
79
- if (!onListen || !onListen(server)) {
80
- logger.finish(`listening on ${linkFromAddress(server.address(), !!https$1)}`, 1 /* LogLevel.info */);
81
- }
82
- }
83
- }
84
- function linkFromAddress(address, https) {
85
- if (address && typeof address !== 'string') {
86
- return linkFromAddressInfo(address, https);
87
- }
88
- return `${address}`;
89
- }
90
- function linkFromAddressInfo({ address, port, family }, https) {
91
- const serverName = family === 'IPv6' ? `[${address}]` : address;
92
- const protocol = `http${https ? 's' : ''}://`;
93
- return `${protocol}${serverName}:${port}`;
12
+ let globalServer;
13
+ const factories = { logger };
14
+ function index (options$1 = {}) {
15
+ const normalizedOptions = options.getOptions(options$1, {
16
+ pluginName: '@rollup-extras/plugin-serve',
17
+ useWriteBundle: true,
18
+ port: 8080,
19
+ useKoaLogger: true
20
+ }, 'dirs', factories);
21
+ const { pluginName, useWriteBundle, port, host, https: https$1, useKoaLogger, customizeKoa, koaStaticOptions, onListen, logger } = normalizedOptions;
22
+ const instance = mutliConfigPluginBase.multiConfigPluginBase(useWriteBundle, pluginName, serve);
23
+ let { dirs } = normalizedOptions, collectDirs = false, started = false, watchMode = true;
24
+ const pluginInstance = { ...instance, outputOptions };
25
+ if (!dirs) {
26
+ dirs = [];
27
+ collectDirs = true;
28
+ pluginInstance.renderStart = renderStart;
29
+ }
30
+ return pluginInstance;
31
+ function renderStart(outputOptions, inputOptions) {
32
+ instance.renderStart.call(this, outputOptions, inputOptions);
33
+ if (collectDirs) {
34
+ if (outputOptions.dir) {
35
+ dirs.push(outputOptions.dir);
36
+ }
37
+ }
38
+ }
39
+ function outputOptions() {
40
+ watchMode = this.meta.watchMode;
41
+ return null;
42
+ }
43
+ async function serve() {
44
+ if (!started && watchMode) {
45
+ started = true;
46
+ if (globalServer) {
47
+ await new Promise(resolve => globalServer.close(resolve));
48
+ globalServer = undefined;
49
+ }
50
+ const app = new Koa();
51
+ if (customizeKoa) {
52
+ customizeKoa(app);
53
+ }
54
+ if (useKoaLogger) {
55
+ app.use(koaLogger());
56
+ }
57
+ for (const dir of dirs) {
58
+ app.use(serveStatic(dir, koaStaticOptions));
59
+ }
60
+ const server = globalServer = https$1 ? https.createServer(https$1, app.callback()) : http.createServer(app.callback());
61
+ const listenCb = () => internalOnListen(server);
62
+ if (host) {
63
+ server.listen(port, host, listenCb);
64
+ }
65
+ else {
66
+ server.listen(port, listenCb);
67
+ }
68
+ server.on('error', (e) => {
69
+ if (e.code === 'EADDRINUSE') {
70
+ logger.finish('address in use, please try another port', 3 /* LogLevel.error */);
71
+ }
72
+ else {
73
+ throw e;
74
+ }
75
+ });
76
+ }
77
+ }
78
+ function internalOnListen(server) {
79
+ if (!onListen || !onListen(server)) {
80
+ logger.finish(`listening on ${linkFromAddress(server.address(), !!https$1)}`, 1 /* LogLevel.info */);
81
+ }
82
+ }
83
+ }
84
+ function linkFromAddress(address, https) {
85
+ if (address && typeof address !== 'string') {
86
+ return linkFromAddressInfo(address, https);
87
+ }
88
+ return `${address}`;
89
+ }
90
+ function linkFromAddressInfo({ address, port, family }, https) {
91
+ let serverName = family === 'IPv6' ? `[${address}]` : address;
92
+ if (serverName === '[::]') {
93
+ serverName = 'localhost';
94
+ }
95
+ const protocol = `http${https ? 's' : ''}://`;
96
+ return `${protocol}${serverName}:${port}`;
94
97
  }
95
98
 
96
99
  module.exports = index;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { Plugin } from 'rollup';
2
- import { ServePluginOptions } from './types';
3
- export default function (options?: ServePluginOptions): Plugin;
1
+ import { Plugin } from 'rollup';
2
+ import { ServePluginOptions } from './types';
3
+ export default function (options?: ServePluginOptions): Plugin;
package/dist/index.mjs CHANGED
@@ -7,88 +7,91 @@ import { getOptions } from '@rollup-extras/utils/options';
7
7
  import logger from '@rollup-extras/utils/logger';
8
8
  import { multiConfigPluginBase } from '@rollup-extras/utils/mutli-config-plugin-base';
9
9
 
10
- let globalServer;
11
- const factories = { logger };
12
- function index (options = {}) {
13
- const normalizedOptions = getOptions(options, {
14
- pluginName: '@rollup-extras/plugin-serve',
15
- useWriteBundle: true,
16
- port: 8080,
17
- useKoaLogger: true
18
- }, 'dirs', factories);
19
- const { pluginName, useWriteBundle, port, host, https, useKoaLogger, customizeKoa, koaStaticOptions, onListen, logger } = normalizedOptions;
20
- const instance = multiConfigPluginBase(useWriteBundle, pluginName, serve);
21
- let { dirs } = normalizedOptions, collectDirs = false, started = false, watchMode = true;
22
- const pluginInstance = Object.assign(Object.assign({}, instance), { outputOptions });
23
- if (!dirs) {
24
- dirs = [];
25
- collectDirs = true;
26
- pluginInstance.renderStart = renderStart;
27
- }
28
- return pluginInstance;
29
- function renderStart(outputOptions, inputOptions) {
30
- instance.renderStart.call(this, outputOptions, inputOptions);
31
- if (collectDirs) {
32
- if (outputOptions.dir) {
33
- dirs.push(outputOptions.dir);
34
- }
35
- }
36
- }
37
- function outputOptions() {
38
- watchMode = this.meta.watchMode;
39
- return null;
40
- }
41
- async function serve() {
42
- if (!started && watchMode) {
43
- started = true;
44
- if (globalServer) {
45
- await new Promise(resolve => globalServer.close(resolve));
46
- globalServer = undefined;
47
- }
48
- const app = new Koa();
49
- if (customizeKoa) {
50
- customizeKoa(app);
51
- }
52
- if (useKoaLogger) {
53
- app.use(koaLogger());
54
- }
55
- for (const dir of dirs) {
56
- app.use(serveStatic(dir, koaStaticOptions));
57
- }
58
- const server = globalServer = https ? createServer(https, app.callback()) : createServer$1(app.callback());
59
- const listenCb = () => internalOnListen(server);
60
- if (host) {
61
- server.listen(port, host, listenCb);
62
- }
63
- else {
64
- server.listen(port, listenCb);
65
- }
66
- server.on('error', (e) => {
67
- if (e.code === 'EADDRINUSE') {
68
- logger.finish('address in use, please try another port', 3 /* LogLevel.error */);
69
- }
70
- else {
71
- throw e;
72
- }
73
- });
74
- }
75
- }
76
- function internalOnListen(server) {
77
- if (!onListen || !onListen(server)) {
78
- logger.finish(`listening on ${linkFromAddress(server.address(), !!https)}`, 1 /* LogLevel.info */);
79
- }
80
- }
81
- }
82
- function linkFromAddress(address, https) {
83
- if (address && typeof address !== 'string') {
84
- return linkFromAddressInfo(address, https);
85
- }
86
- return `${address}`;
87
- }
88
- function linkFromAddressInfo({ address, port, family }, https) {
89
- const serverName = family === 'IPv6' ? `[${address}]` : address;
90
- const protocol = `http${https ? 's' : ''}://`;
91
- return `${protocol}${serverName}:${port}`;
10
+ let globalServer;
11
+ const factories = { logger };
12
+ function index (options = {}) {
13
+ const normalizedOptions = getOptions(options, {
14
+ pluginName: '@rollup-extras/plugin-serve',
15
+ useWriteBundle: true,
16
+ port: 8080,
17
+ useKoaLogger: true
18
+ }, 'dirs', factories);
19
+ const { pluginName, useWriteBundle, port, host, https, useKoaLogger, customizeKoa, koaStaticOptions, onListen, logger } = normalizedOptions;
20
+ const instance = multiConfigPluginBase(useWriteBundle, pluginName, serve);
21
+ let { dirs } = normalizedOptions, collectDirs = false, started = false, watchMode = true;
22
+ const pluginInstance = { ...instance, outputOptions };
23
+ if (!dirs) {
24
+ dirs = [];
25
+ collectDirs = true;
26
+ pluginInstance.renderStart = renderStart;
27
+ }
28
+ return pluginInstance;
29
+ function renderStart(outputOptions, inputOptions) {
30
+ instance.renderStart.call(this, outputOptions, inputOptions);
31
+ if (collectDirs) {
32
+ if (outputOptions.dir) {
33
+ dirs.push(outputOptions.dir);
34
+ }
35
+ }
36
+ }
37
+ function outputOptions() {
38
+ watchMode = this.meta.watchMode;
39
+ return null;
40
+ }
41
+ async function serve() {
42
+ if (!started && watchMode) {
43
+ started = true;
44
+ if (globalServer) {
45
+ await new Promise(resolve => globalServer.close(resolve));
46
+ globalServer = undefined;
47
+ }
48
+ const app = new Koa();
49
+ if (customizeKoa) {
50
+ customizeKoa(app);
51
+ }
52
+ if (useKoaLogger) {
53
+ app.use(koaLogger());
54
+ }
55
+ for (const dir of dirs) {
56
+ app.use(serveStatic(dir, koaStaticOptions));
57
+ }
58
+ const server = globalServer = https ? createServer(https, app.callback()) : createServer$1(app.callback());
59
+ const listenCb = () => internalOnListen(server);
60
+ if (host) {
61
+ server.listen(port, host, listenCb);
62
+ }
63
+ else {
64
+ server.listen(port, listenCb);
65
+ }
66
+ server.on('error', (e) => {
67
+ if (e.code === 'EADDRINUSE') {
68
+ logger.finish('address in use, please try another port', 3 /* LogLevel.error */);
69
+ }
70
+ else {
71
+ throw e;
72
+ }
73
+ });
74
+ }
75
+ }
76
+ function internalOnListen(server) {
77
+ if (!onListen || !onListen(server)) {
78
+ logger.finish(`listening on ${linkFromAddress(server.address(), !!https)}`, 1 /* LogLevel.info */);
79
+ }
80
+ }
81
+ }
82
+ function linkFromAddress(address, https) {
83
+ if (address && typeof address !== 'string') {
84
+ return linkFromAddressInfo(address, https);
85
+ }
86
+ return `${address}`;
87
+ }
88
+ function linkFromAddressInfo({ address, port, family }, https) {
89
+ let serverName = family === 'IPv6' ? `[${address}]` : address;
90
+ if (serverName === '[::]') {
91
+ serverName = 'localhost';
92
+ }
93
+ const protocol = `http${https ? 's' : ''}://`;
94
+ return `${protocol}${serverName}:${port}`;
92
95
  }
93
96
 
94
97
  export { index as default };
package/dist/types.d.ts CHANGED
@@ -1,20 +1,20 @@
1
- /// <reference types="node" />
2
- import Koa from 'koa';
3
- import serve from 'koa-static';
4
- import { Server } from 'http';
5
- export declare type ServePluginOptions = {
6
- pluginName?: string;
7
- useWriteBundle?: boolean;
8
- dirs?: string | string[];
9
- port?: number;
10
- useKoaLogger?: boolean;
11
- koaStaticOptions?: serve.Options;
12
- host?: string;
13
- https?: {
14
- cert: string;
15
- key: string;
16
- ca?: string;
17
- };
18
- customizeKoa?: (koa: Koa) => void;
19
- onListen?: (server: Server) => void | true;
20
- } | string | string[];
1
+ /// <reference types="node" />
2
+ import Koa from 'koa';
3
+ import serve from 'koa-static';
4
+ import { Server } from 'http';
5
+ export type ServePluginOptions = {
6
+ pluginName?: string;
7
+ useWriteBundle?: boolean;
8
+ dirs?: string | string[];
9
+ port?: number;
10
+ useKoaLogger?: boolean;
11
+ koaStaticOptions?: serve.Options;
12
+ host?: string;
13
+ https?: {
14
+ cert: string;
15
+ key: string;
16
+ ca?: string;
17
+ };
18
+ customizeKoa?: (koa: Koa) => void;
19
+ onListen?: (server: Server) => void | true;
20
+ } | string | string[];
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.2.5",
2
+ "version": "1.3.0",
3
3
  "license": "MIT",
4
4
  "name": "@rollup-extras/plugin-serve",
5
5
  "author": {
@@ -38,30 +38,7 @@
38
38
  "server",
39
39
  "serve"
40
40
  ],
41
- "scripts": {
42
- "build": "pkgbld-internal",
43
- "test": "jest --collectCoverage",
44
- "lint": "eslint ./src",
45
- "semantic-release": "npx semantic-release"
46
- },
47
41
  "devDependencies": {
48
- "@semantic-release/changelog": "6.0.1",
49
- "@semantic-release/commit-analyzer": "9.0.2",
50
- "@semantic-release/git": "10.0.1",
51
- "@semantic-release/npm": "9.0.1",
52
- "@semantic-release/release-notes-generator": "10.0.3",
53
- "@types/jest": "27.5.1",
54
- "@typescript-eslint/eslint-plugin": "5.24.0",
55
- "@typescript-eslint/parser": "5.24.0",
56
- "conventional-changelog-angular": "5.0.13",
57
- "eslint": "8.15.0",
58
- "jest": "28.1.0",
59
- "semantic-release": "19.0.3",
60
- "semantic-release-monorepo": "7.0.5",
61
- "ts-jest": "28.0.2",
62
- "typescript": "4.6.x",
63
- "update-monorepo-package-json": "0.2.0",
64
- "pkgbld-internal": "1.0.3",
65
42
  "@types/koa": "^2.13.4",
66
43
  "@types/koa-logger": "^3.1.2",
67
44
  "@types/koa-static": "^4.0.2"
@@ -70,10 +47,15 @@
70
47
  "rollup": "^2.60.1 || ^3.0.0"
71
48
  },
72
49
  "dependencies": {
73
- "koa": "^2.14.0",
50
+ "koa": "^2.14.1",
74
51
  "koa-static": "^5.0.0",
75
52
  "koa-logger": "^3.2.1",
76
53
  "@niceties/logger": "^1.1.4",
77
54
  "@rollup-extras/utils": "^1.3.5"
55
+ },
56
+ "scripts": {
57
+ "build": "pkgbld-internal",
58
+ "test": "jest --collectCoverage",
59
+ "lint": "eslint ./src"
78
60
  }
79
- }
61
+ }