@rollup-extras/plugin-serve 1.2.1 → 1.2.3
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 +6 -82
- package/dist/index.d.ts +2 -37
- package/dist/index.mjs +3 -79
- package/package.json +3 -3
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
|
|
9
|
-
|
|
10
|
-
|
|
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.d.ts
CHANGED
|
@@ -1,38 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Plugin } from 'rollup';
|
|
2
2
|
import { ServePluginOptions } from './types';
|
|
3
|
-
export default function (options?: ServePluginOptions):
|
|
4
|
-
outputOptions: (this: PluginContext) => null;
|
|
5
|
-
buildEnd?: ((this: PluginContext, err?: Error | undefined) => void | Promise<void>) | undefined;
|
|
6
|
-
buildStart?: ((this: PluginContext, options: NormalizedInputOptions) => void | Promise<void>) | undefined;
|
|
7
|
-
closeBundle?: ((this: PluginContext) => void | Promise<void>) | undefined;
|
|
8
|
-
closeWatcher?: ((this: PluginContext) => void | Promise<void>) | undefined;
|
|
9
|
-
load?: import("rollup").LoadHook | undefined;
|
|
10
|
-
moduleParsed?: import("rollup").ModuleParsedHook | undefined;
|
|
11
|
-
options?: ((this: import("rollup").MinimalPluginContext, options: import("rollup").InputOptions) => void | import("rollup").InputOptions | Promise<void | import("rollup").InputOptions | null> | null) | undefined;
|
|
12
|
-
resolveDynamicImport?: import("rollup").ResolveDynamicImportHook | undefined;
|
|
13
|
-
resolveId?: import("rollup").ResolveIdHook | undefined;
|
|
14
|
-
shouldTransformCachedModule?: import("rollup").ShouldTransformCachedModuleHook | undefined;
|
|
15
|
-
transform?: import("rollup").TransformHook | undefined;
|
|
16
|
-
watchChange?: import("rollup").WatchChangeHook | undefined;
|
|
17
|
-
augmentChunkHash?: ((this: PluginContext, chunk: import("rollup").PreRenderedChunk) => string | void) | undefined;
|
|
18
|
-
generateBundle?: ((this: PluginContext, options: NormalizedOutputOptions, bundle: import("rollup").OutputBundle, isWrite: boolean) => void | Promise<void>) | undefined;
|
|
19
|
-
renderChunk?: import("rollup").RenderChunkHook | undefined;
|
|
20
|
-
renderDynamicImport?: ((this: PluginContext, options: {
|
|
21
|
-
customResolution: string | null;
|
|
22
|
-
format: import("rollup").InternalModuleFormat;
|
|
23
|
-
moduleId: string;
|
|
24
|
-
targetModuleId: string | null;
|
|
25
|
-
}) => void | {
|
|
26
|
-
left: string;
|
|
27
|
-
right: string;
|
|
28
|
-
} | null) | undefined;
|
|
29
|
-
renderError?: ((this: PluginContext, err?: Error | undefined) => void | Promise<void>) | undefined;
|
|
30
|
-
renderStart?: ((this: PluginContext, outputOptions: NormalizedOutputOptions, inputOptions: NormalizedInputOptions) => void | Promise<void>) | undefined;
|
|
31
|
-
resolveAssetUrl?: import("rollup").ResolveAssetUrlHook | undefined;
|
|
32
|
-
resolveFileUrl?: import("rollup").ResolveFileUrlHook | undefined;
|
|
33
|
-
resolveImportMeta?: import("rollup").ResolveImportMetaHook | undefined;
|
|
34
|
-
writeBundle?: ((this: PluginContext, options: NormalizedOutputOptions, bundle: import("rollup").OutputBundle) => void | Promise<void>) | undefined;
|
|
35
|
-
api: {
|
|
36
|
-
addInstance(): void;
|
|
37
|
-
};
|
|
38
|
-
};
|
|
3
|
+
export default function (options?: ServePluginOptions): Plugin;
|
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 {
|
|
7
|
-
|
|
8
|
-
|
|
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.
|
|
2
|
+
"version": "1.2.3",
|
|
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.
|
|
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.
|
|
76
|
+
"@rollup-extras/utils": "^1.3.3"
|
|
77
77
|
}
|
|
78
78
|
}
|