@rollup-extras/plugin-serve 1.2.1 → 1.2.2

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/dist/index.cjs CHANGED
@@ -5,97 +5,21 @@ var https = require('https');
5
5
  var Koa = require('koa');
6
6
  var koaLogger = require('koa-logger');
7
7
  var serveStatic = require('koa-static');
8
- var logger$1 = require('@niceties/logger');
9
-
10
- function getOptions(options, defaults, field, factory) {
11
- const newOptions = recursiveArrayOptions(options, field);
12
- return getOptionsObject((newOptions ? newOptions : options), defaults, factory);
13
- }
14
- function recursiveArrayOptions(options, field) {
15
- if (typeof options === 'string') {
16
- return { [field]: [options] };
17
- }
18
- else if (Array.isArray(options)) {
19
- return { [field]: options };
20
- }
21
- else if (typeof options === 'object') {
22
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
- return field in options ? Object.assign(Object.assign({}, options), recursiveArrayOptions(options[field], field)) : options;
24
- }
25
- console.warn(`cannot process options: '${options}', reverting to defaults`);
26
- return undefined;
27
- }
28
- function getOptionsObject(options, defaults, factory) {
29
- const result = Object.assign(Object.assign({}, defaults), options);
30
- if (factory) {
31
- for (const [k, v] of Object.entries(factory)) {
32
- result[k] = v(result, k);
33
- }
34
- }
35
- return result;
36
- }
37
-
38
- function logger (options) {
39
- return logger$1.createLogger(options.pluginName);
40
- }
41
-
42
- function multiConfigPluginBase(useWriteBundle, pluginName, execute, onFinalHook) {
43
- const finalHook = useWriteBundle ? 'writeBundle' : 'generateBundle';
44
- let remainingOutputsCount = 0, configsCount = 0;
45
- const configs = new Set();
46
- const instance = {
47
- name: pluginName,
48
- renderStart,
49
- [finalHook]: writeBundle,
50
- api: { addInstance }
51
- };
52
- return instance;
53
- function addInstance() {
54
- const configId = ++configsCount;
55
- configs.add(configId);
56
- return {
57
- name: `${pluginName}#${configId}`,
58
- renderStart: () => {
59
- configs.delete(configId);
60
- return renderStart();
61
- },
62
- [finalHook]: writeBundle
63
- };
64
- }
65
- function renderStart() {
66
- ++remainingOutputsCount;
67
- }
68
- async function writeBundle(options, bundle) {
69
- --remainingOutputsCount;
70
- if (onFinalHook) {
71
- await onFinalHook.call(this, options, bundle, configs.size, remainingOutputsCount);
72
- }
73
- if (configs.size === 0 && remainingOutputsCount === 0) {
74
- // do work
75
- try {
76
- await execute.call(this, options, bundle);
77
- }
78
- finally {
79
- // reset configs
80
- for (let i = configsCount; i > 0; --i) {
81
- configs.add(i);
82
- }
83
- }
84
- }
85
- }
86
- }
8
+ var options = require('@rollup-extras/utils/options');
9
+ var logger = require('@rollup-extras/utils/logger');
10
+ var mutliConfigPluginBase = require('@rollup-extras/utils/mutli-config-plugin-base');
87
11
 
88
12
  let globalServer;
89
13
  const factories = { logger };
90
- function index (options = {}) {
91
- const normalizedOptions = getOptions(options, {
14
+ function index (options$1 = {}) {
15
+ const normalizedOptions = options.getOptions(options$1, {
92
16
  pluginName: '@rollup-extras/plugin-serve',
93
17
  useWriteBundle: true,
94
18
  port: 8080,
95
19
  useKoaLogger: true
96
20
  }, 'dirs', factories);
97
21
  const { pluginName, useWriteBundle, port, host, https: https$1, useKoaLogger, customizeKoa, koaStaticOptions, onListen, logger } = normalizedOptions;
98
- const instance = multiConfigPluginBase(useWriteBundle, pluginName, serve);
22
+ const instance = mutliConfigPluginBase.multiConfigPluginBase(useWriteBundle, pluginName, serve);
99
23
  let { dirs } = normalizedOptions, collectDirs = false, started = false, watchMode = true;
100
24
  const pluginInstance = Object.assign(Object.assign({}, instance), { outputOptions });
101
25
  if (!dirs) {
package/dist/index.mjs CHANGED
@@ -3,85 +3,9 @@ import { createServer } from 'https';
3
3
  import Koa from 'koa';
4
4
  import koaLogger from 'koa-logger';
5
5
  import serveStatic from 'koa-static';
6
- import { createLogger } from '@niceties/logger';
7
-
8
- function getOptions(options, defaults, field, factory) {
9
- const newOptions = recursiveArrayOptions(options, field);
10
- return getOptionsObject((newOptions ? newOptions : options), defaults, factory);
11
- }
12
- function recursiveArrayOptions(options, field) {
13
- if (typeof options === 'string') {
14
- return { [field]: [options] };
15
- }
16
- else if (Array.isArray(options)) {
17
- return { [field]: options };
18
- }
19
- else if (typeof options === 'object') {
20
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
- return field in options ? Object.assign(Object.assign({}, options), recursiveArrayOptions(options[field], field)) : options;
22
- }
23
- console.warn(`cannot process options: '${options}', reverting to defaults`);
24
- return undefined;
25
- }
26
- function getOptionsObject(options, defaults, factory) {
27
- const result = Object.assign(Object.assign({}, defaults), options);
28
- if (factory) {
29
- for (const [k, v] of Object.entries(factory)) {
30
- result[k] = v(result, k);
31
- }
32
- }
33
- return result;
34
- }
35
-
36
- function logger (options) {
37
- return createLogger(options.pluginName);
38
- }
39
-
40
- function multiConfigPluginBase(useWriteBundle, pluginName, execute, onFinalHook) {
41
- const finalHook = useWriteBundle ? 'writeBundle' : 'generateBundle';
42
- let remainingOutputsCount = 0, configsCount = 0;
43
- const configs = new Set();
44
- const instance = {
45
- name: pluginName,
46
- renderStart,
47
- [finalHook]: writeBundle,
48
- api: { addInstance }
49
- };
50
- return instance;
51
- function addInstance() {
52
- const configId = ++configsCount;
53
- configs.add(configId);
54
- return {
55
- name: `${pluginName}#${configId}`,
56
- renderStart: () => {
57
- configs.delete(configId);
58
- return renderStart();
59
- },
60
- [finalHook]: writeBundle
61
- };
62
- }
63
- function renderStart() {
64
- ++remainingOutputsCount;
65
- }
66
- async function writeBundle(options, bundle) {
67
- --remainingOutputsCount;
68
- if (onFinalHook) {
69
- await onFinalHook.call(this, options, bundle, configs.size, remainingOutputsCount);
70
- }
71
- if (configs.size === 0 && remainingOutputsCount === 0) {
72
- // do work
73
- try {
74
- await execute.call(this, options, bundle);
75
- }
76
- finally {
77
- // reset configs
78
- for (let i = configsCount; i > 0; --i) {
79
- configs.add(i);
80
- }
81
- }
82
- }
83
- }
84
- }
6
+ import { getOptions } from '@rollup-extras/utils/options';
7
+ import logger from '@rollup-extras/utils/logger';
8
+ import { multiConfigPluginBase } from '@rollup-extras/utils/mutli-config-plugin-base';
85
9
 
86
10
  let globalServer;
87
11
  const factories = { logger };
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.2.1",
2
+ "version": "1.2.2",
3
3
  "license": "MIT",
4
4
  "name": "@rollup-extras/plugin-serve",
5
5
  "author": {
@@ -60,7 +60,7 @@
60
60
  "ts-jest": "28.0.2",
61
61
  "typescript": "4.6.x",
62
62
  "update-monorepo-package-json": "0.2.0",
63
- "pkgbld-internal": "1.0.2",
63
+ "pkgbld-internal": "1.0.3",
64
64
  "@types/koa": "^2.13.4",
65
65
  "@types/koa-logger": "^3.1.2",
66
66
  "@types/koa-static": "^4.0.2"
@@ -73,6 +73,6 @@
73
73
  "koa-static": "^5.0.0",
74
74
  "koa-logger": "^3.2.1",
75
75
  "@niceties/logger": "^1.1.4",
76
- "@rollup-extras/utils": "^1.3.1"
76
+ "@rollup-extras/utils": "^1.3.2"
77
77
  }
78
78
  }