@modern-js/plugin-koa 2.0.0-beta.3 → 2.0.0-beta.4

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/CHANGELOG.md CHANGED
@@ -1,5 +1,49 @@
1
1
  # @modern-js/plugin-koa
2
2
 
3
+ ## 2.0.0-beta.4
4
+
5
+ ### Major Changes
6
+
7
+ - dda38c9c3e: chore: v2
8
+
9
+ ### Patch Changes
10
+
11
+ - 8d24bed25b: fix: compat Hook API in /server namespace
12
+ fix: 在 @modern-js/runtime/server 命名空间下兼容 Hook API
13
+ - 3bbea92b2a: feat: support Hook、Middleware new API
14
+ feat: 支持 Hook、Middleware 的新 API
15
+ - Updated dependencies [7879e8f]
16
+ - Updated dependencies [6aca875]
17
+ - Updated dependencies [2e6031955e]
18
+ - Updated dependencies [2344eb26ed]
19
+ - Updated dependencies [a2509bfbdb]
20
+ - Updated dependencies [7b7d12c]
21
+ - Updated dependencies [92f0eade39]
22
+ - Updated dependencies [edd1cfb1af]
23
+ - Updated dependencies [cc971eabfc]
24
+ - Updated dependencies [5b9049f2e9]
25
+ - Updated dependencies [6bda14ed71]
26
+ - Updated dependencies [92004d1906]
27
+ - Updated dependencies [b8bbe036c7]
28
+ - Updated dependencies [40ed5874c6]
29
+ - Updated dependencies [87c1ff86b9]
30
+ - Updated dependencies [d5a31df781]
31
+ - Updated dependencies [dda38c9c3e]
32
+ - Updated dependencies [102d32e4ba]
33
+ - Updated dependencies [8b8e1bb571]
34
+ - Updated dependencies [3bbea92b2a]
35
+ - Updated dependencies [b710adb843]
36
+ - Updated dependencies [ea7cf06]
37
+ - Updated dependencies [bbe4c4a]
38
+ - Updated dependencies [e4558a0]
39
+ - Updated dependencies [abf3421a75]
40
+ - Updated dependencies [543be9558e]
41
+ - Updated dependencies [14b712da84]
42
+ - @modern-js/types@2.0.0-beta.4
43
+ - @modern-js/utils@2.0.0-beta.4
44
+ - @modern-js/bff-core@2.0.0-beta.4
45
+ - @modern-js/bff-runtime@2.0.0-beta.4
46
+
3
47
  ## 2.0.0-beta.3
4
48
 
5
49
  ### Major Changes
@@ -1,29 +1,31 @@
1
- import * as path from 'path';
2
- import { createRuntimeExportsUtils } from '@modern-js/utils';
3
- import { getRelativeRuntimePath } from '@modern-js/bff-core';
4
- export default (() => ({
5
- name: '@modern-js/plugin-koa',
6
- setup: api => {
1
+ import * as path from "path";
2
+ import { createRuntimeExportsUtils } from "@modern-js/utils";
3
+ import { getRelativeRuntimePath } from "@modern-js/bff-core";
4
+ var cli_default = () => ({
5
+ name: "@modern-js/plugin-koa",
6
+ setup: (api) => {
7
7
  let bffExportsUtils;
8
- const {
9
- useAppContext
10
- } = api;
11
- const runtimeModulePath = path.resolve(__dirname, '../runtime');
8
+ const { useAppContext } = api;
9
+ const runtimeModulePath = path.resolve(__dirname, "../runtime");
12
10
  return {
13
11
  config() {
14
12
  const appContext = useAppContext();
15
- const {
16
- appDirectory
17
- } = appContext;
18
- bffExportsUtils = createRuntimeExportsUtils(appContext.internalDirectory, 'server');
13
+ const { appDirectory } = appContext;
14
+ bffExportsUtils = createRuntimeExportsUtils(
15
+ appContext.internalDirectory,
16
+ "server"
17
+ );
19
18
  const serverRuntimePath = bffExportsUtils.getPath();
20
- const relativeRuntimePath = getRelativeRuntimePath(appDirectory, serverRuntimePath);
21
- if (process.env.NODE_ENV === 'production') {
19
+ const relativeRuntimePath = getRelativeRuntimePath(
20
+ appDirectory,
21
+ serverRuntimePath
22
+ );
23
+ if (process.env.NODE_ENV === "production") {
22
24
  return {
23
25
  source: {
24
26
  alias: {
25
- '@modern-js/runtime/server': relativeRuntimePath,
26
- '@modern-js/runtime/koa': relativeRuntimePath
27
+ "@modern-js/runtime/server": relativeRuntimePath,
28
+ "@modern-js/runtime/koa": relativeRuntimePath
27
29
  }
28
30
  }
29
31
  };
@@ -31,8 +33,8 @@ export default (() => ({
31
33
  return {
32
34
  source: {
33
35
  alias: {
34
- '@modern-js/runtime/server': serverRuntimePath,
35
- '@modern-js/runtime/koa': serverRuntimePath
36
+ "@modern-js/runtime/server": serverRuntimePath,
37
+ "@modern-js/runtime/koa": serverRuntimePath
36
38
  }
37
39
  }
38
40
  };
@@ -40,8 +42,14 @@ export default (() => ({
40
42
  },
41
43
  addRuntimeExports(input) {
42
44
  const currentFile = bffExportsUtils.getPath();
43
- const relativeRuntimeModulePath = path.relative(path.dirname(currentFile), runtimeModulePath);
44
- const relativeFramePath = path.relative(path.dirname(currentFile), require.resolve('koa'));
45
+ const relativeRuntimeModulePath = path.relative(
46
+ path.dirname(currentFile),
47
+ runtimeModulePath
48
+ );
49
+ const relativeFramePath = path.relative(
50
+ path.dirname(currentFile),
51
+ require.resolve("koa")
52
+ );
45
53
  bffExportsUtils.addExport(`const pluginRuntime = require('${relativeRuntimeModulePath}');
46
54
  const Koa = require('${relativeFramePath}')
47
55
  module.exports = {
@@ -53,4 +61,7 @@ export default (() => ({
53
61
  }
54
62
  };
55
63
  }
56
- }));
64
+ });
65
+ export {
66
+ cli_default as default
67
+ };
@@ -1,6 +1,6 @@
1
- import { createStorage } from '@modern-js/bff-core';
2
- const {
1
+ import { createStorage } from "@modern-js/bff-core";
2
+ const { run, useContext } = createStorage();
3
+ export {
3
4
  run,
4
5
  useContext
5
- } = createStorage();
6
- export { run, useContext };
6
+ };
@@ -1,3 +1,6 @@
1
1
  import plugin from "./plugin";
2
2
  export * from "./context";
3
- export default plugin;
3
+ var src_default = plugin;
4
+ export {
5
+ src_default as default
6
+ };
@@ -1,114 +1,124 @@
1
- import * as path from 'path';
2
- import Koa from 'koa';
3
- import Router from 'koa-router';
4
- import koaBody from 'koa-body';
5
- import { fs, compatRequire } from '@modern-js/utils';
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+ import * as path from "path";
22
+ import Koa from "koa";
23
+ import Router from "koa-router";
24
+ import koaBody from "koa-body";
25
+ import { fs, compatRequire } from "@modern-js/utils";
6
26
  import { run } from "./context";
7
27
  import registerRoutes from "./registerRoutes";
8
- const findAppModule = async apiDir => {
9
- const exts = ['.ts', '.js'];
10
- const paths = exts.map(ext => path.join(apiDir, `app${ext}`));
28
+ const findAppModule = (apiDir) => __async(void 0, null, function* () {
29
+ const exts = [".ts", ".js"];
30
+ const paths = exts.map((ext) => path.join(apiDir, `app${ext}`));
11
31
  for (const filename of paths) {
12
- if (await fs.pathExists(filename)) {
13
- // 每次获取 app.ts 的时候,避免使用缓存的 app.ts
32
+ if (yield fs.pathExists(filename)) {
14
33
  delete require.cache[filename];
15
34
  return compatRequire(filename);
16
35
  }
17
36
  }
18
37
  return null;
19
- };
38
+ });
20
39
  const initMiddlewares = (middleware, app) => {
21
- middleware.forEach(middlewareItem => {
22
- const middlewareFunc = typeof middlewareItem === 'string' ? compatRequire(middlewareItem) : middlewareItem;
40
+ middleware.forEach((middlewareItem) => {
41
+ const middlewareFunc = typeof middlewareItem === "string" ? compatRequire(middlewareItem) : middlewareItem;
23
42
  app.use(middlewareFunc);
24
43
  });
25
44
  };
26
- export default (() => ({
27
- name: '@modern-js/plugin-koa',
28
- pre: ['@modern-js/plugin-bff'],
29
- post: ['@modern-js/plugin-server'],
30
- setup: api => ({
31
- async prepareApiServer({
32
- pwd,
33
- config
34
- }) {
35
- let app;
36
- const router = new Router();
37
- const apiDir = path.join(pwd, './api');
38
- const appContext = api.useAppContext();
39
- const apiHandlerInfos = appContext.apiHandlerInfos;
40
- const mode = appContext.apiMode;
41
- if (mode === 'framework') {
42
- app = await findAppModule(apiDir);
43
- if (!(app instanceof Koa)) {
45
+ var plugin_default = () => ({
46
+ name: "@modern-js/plugin-koa",
47
+ pre: ["@modern-js/plugin-bff"],
48
+ post: ["@modern-js/plugin-server"],
49
+ setup: (api) => ({
50
+ prepareApiServer(_0) {
51
+ return __async(this, arguments, function* ({ pwd, config }) {
52
+ let app;
53
+ const router = new Router();
54
+ const apiDir = path.join(pwd, "./api");
55
+ const appContext = api.useAppContext();
56
+ const apiHandlerInfos = appContext.apiHandlerInfos;
57
+ const mode = appContext.apiMode;
58
+ if (mode === "framework") {
59
+ app = yield findAppModule(apiDir);
60
+ if (!(app instanceof Koa)) {
61
+ app = new Koa();
62
+ app.use(
63
+ koaBody({
64
+ multipart: true
65
+ })
66
+ );
67
+ }
68
+ if (config) {
69
+ const { middleware } = config;
70
+ initMiddlewares(middleware, app);
71
+ }
72
+ app.use(run);
73
+ registerRoutes(router, apiHandlerInfos);
74
+ } else if (mode === "function") {
44
75
  app = new Koa();
45
- app.use(koaBody({
46
- multipart: true
47
- }));
48
- }
49
- if (config) {
50
- const {
51
- middleware
52
- } = config;
53
- initMiddlewares(middleware, app);
54
- }
55
- app.use(run);
56
- registerRoutes(router, apiHandlerInfos);
57
- } else if (mode === 'function') {
58
- app = new Koa();
59
- app.use(koaBody({
60
- multipart: true
61
- }));
62
- if (config) {
63
- const {
64
- middleware
65
- } = config;
66
- initMiddlewares(middleware, app);
76
+ app.use(
77
+ koaBody({
78
+ multipart: true
79
+ })
80
+ );
81
+ if (config) {
82
+ const { middleware } = config;
83
+ initMiddlewares(middleware, app);
84
+ }
85
+ app.use(run);
86
+ registerRoutes(router, apiHandlerInfos);
87
+ } else {
88
+ throw new Error(`mode must be function or framework`);
67
89
  }
68
- app.use(run);
69
- registerRoutes(router, apiHandlerInfos);
70
- } else {
71
- throw new Error(`mode must be function or framework`);
72
- }
73
- app.use(router.routes());
74
- return (req, res) => {
75
- return Promise.resolve(app.callback()(req, res));
76
- };
90
+ app.use(router.routes());
91
+ return (req, res) => {
92
+ return Promise.resolve(app.callback()(req, res));
93
+ };
94
+ });
77
95
  },
78
- prepareWebServer({
79
- config
80
- }, next) {
81
- var _userConfig$server;
96
+ prepareWebServer({ config }, next) {
97
+ var _a2;
82
98
  const userConfig = api.useConfigContext();
83
- if (userConfig !== null && userConfig !== void 0 && (_userConfig$server = userConfig.server) !== null && _userConfig$server !== void 0 && _userConfig$server.disableFrameworkExt) {
99
+ if ((_a2 = userConfig == null ? void 0 : userConfig.server) == null ? void 0 : _a2.disableFrameworkExt) {
84
100
  return next();
85
101
  }
86
102
  const app = new Koa();
87
- app.use(async (ctx, next) => {
88
- await next();
103
+ app.use((ctx, next2) => __async(this, null, function* () {
104
+ yield next2();
89
105
  if (!ctx.body) {
90
- // restore statusCode
91
106
  if (ctx.res.statusCode === 404 && !ctx.response._explicitStatus) {
92
107
  ctx.res.statusCode = 200;
93
108
  }
94
109
  ctx.respond = false;
95
110
  }
96
- });
111
+ }));
97
112
  app.use(koaBody());
98
113
  if (config) {
99
- const {
100
- middleware
101
- } = config;
114
+ const { middleware } = config;
102
115
  initMiddlewares(middleware, app);
103
116
  }
104
- return ctx => {
117
+ return (ctx) => {
105
118
  const {
106
- source: {
107
- req,
108
- res
109
- }
119
+ source: { req, res }
110
120
  } = ctx;
111
- app.on('error', err => {
121
+ app.on("error", (err) => {
112
122
  if (err) {
113
123
  throw err;
114
124
  }
@@ -117,4 +127,7 @@ export default (() => ({
117
127
  };
118
128
  }
119
129
  })
120
- }));
130
+ });
131
+ export {
132
+ plugin_default as default
133
+ };
@@ -1,13 +1,12 @@
1
1
  import { createRouteHandler } from "./utils";
2
2
  const registerRoutes = (router, handlerInfos) => {
3
- handlerInfos.forEach(({
4
- routePath,
5
- handler,
6
- httpMethod
7
- }) => {
3
+ handlerInfos.forEach(({ routePath, handler, httpMethod }) => {
8
4
  const routeHandler = createRouteHandler(handler);
9
5
  const method = httpMethod.toLowerCase();
10
6
  router[method](routePath, routeHandler);
11
7
  });
12
8
  };
13
- export default registerRoutes;
9
+ var registerRoutes_default = registerRoutes;
10
+ export {
11
+ registerRoutes_default as default
12
+ };
@@ -1,3 +1,7 @@
1
- export const hook = attacher => attacher;
2
- export { useContext } from "./context";
3
- export * from '@modern-js/bff-core';
1
+ const hook = (attacher) => attacher;
2
+ import { useContext } from "./context";
3
+ export * from "@modern-js/bff-core";
4
+ export {
5
+ hook,
6
+ useContext
7
+ };
@@ -1,28 +1,55 @@
1
- import { httpMethods, isWithMetaHandler, ResponseMetaType, HttpMetadata } from '@modern-js/bff-core';
2
- import { isSchemaHandler } from '@modern-js/bff-runtime';
3
- import typeIs from 'type-is';
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+ import {
22
+ httpMethods,
23
+ isWithMetaHandler,
24
+ ResponseMetaType,
25
+ HttpMetadata
26
+ } from "@modern-js/bff-core";
27
+ import { isSchemaHandler } from "@modern-js/bff-runtime";
28
+ import typeIs from "type-is";
4
29
  const handleResponseMeta = (ctx, handler) => {
5
- const responseMeta = Reflect.getMetadata(HttpMetadata.Response, handler);
30
+ const responseMeta = Reflect.getMetadata(
31
+ HttpMetadata.Response,
32
+ handler
33
+ );
6
34
  if (Array.isArray(responseMeta)) {
7
35
  for (const meta of responseMeta) {
8
36
  const metaType = meta.type;
9
37
  const metaValue = meta.value;
10
38
  switch (metaType) {
11
39
  case ResponseMetaType.Headers:
12
- // eslint-disable-next-line @typescript-eslint/ban-types
13
40
  for (const [key, value] of Object.entries(metaValue)) {
14
- if (typeof value === 'string') {
41
+ if (typeof value === "string") {
15
42
  ctx.append(key, value);
16
43
  }
17
44
  }
18
45
  break;
19
46
  case ResponseMetaType.Redirect:
20
- if (typeof metaValue === 'string') {
47
+ if (typeof metaValue === "string") {
21
48
  ctx.redirect(metaValue);
22
49
  }
23
50
  break;
24
51
  case ResponseMetaType.StatusCode:
25
- if (typeof metaValue === 'number') {
52
+ if (typeof metaValue === "number") {
26
53
  ctx.status = metaValue;
27
54
  }
28
55
  break;
@@ -32,15 +59,14 @@ const handleResponseMeta = (ctx, handler) => {
32
59
  }
33
60
  }
34
61
  };
35
- export const createRouteHandler = handler => {
36
- // eslint-disable-next-line consistent-return
37
- const apiHandler = async ctx => {
38
- const input = await getInputFromRequest(ctx);
62
+ const createRouteHandler = (handler) => {
63
+ const apiHandler = (ctx) => __async(void 0, null, function* () {
64
+ const input = yield getInputFromRequest(ctx);
39
65
  if (isWithMetaHandler(handler)) {
40
66
  try {
41
67
  handleResponseMeta(ctx, handler);
42
- const body = await handler(input);
43
- if (typeof body !== 'undefined') {
68
+ const body = yield handler(input);
69
+ if (typeof body !== "undefined") {
44
70
  ctx.body = body;
45
71
  }
46
72
  } catch (error) {
@@ -57,9 +83,9 @@ export const createRouteHandler = handler => {
57
83
  }
58
84
  }
59
85
  } else if (isSchemaHandler(handler)) {
60
- const result = await handler(input);
61
- if (result.type !== 'HandleSuccess') {
62
- if (result.type === 'InputValidationError') {
86
+ const result = yield handler(input);
87
+ if (result.type !== "HandleSuccess") {
88
+ if (result.type === "InputValidationError") {
63
89
  ctx.status = 400;
64
90
  } else {
65
91
  ctx.status = 500;
@@ -70,31 +96,38 @@ export const createRouteHandler = handler => {
70
96
  }
71
97
  } else {
72
98
  const args = Object.values(input.params).concat(input);
73
- const body = await handler(...args);
74
- if (typeof body !== 'undefined') {
99
+ const body = yield handler(...args);
100
+ if (typeof body !== "undefined") {
75
101
  ctx.body = body;
76
102
  }
77
103
  }
78
- };
79
- Object.defineProperties(apiHandler, Object.getOwnPropertyDescriptors(handler));
104
+ });
105
+ Object.defineProperties(
106
+ apiHandler,
107
+ Object.getOwnPropertyDescriptors(handler)
108
+ );
80
109
  return apiHandler;
81
110
  };
82
- export const isNormalMethod = httpMethod => httpMethods.includes(httpMethod);
83
- const getInputFromRequest = async ctx => {
111
+ const isNormalMethod = (httpMethod) => httpMethods.includes(httpMethod);
112
+ const getInputFromRequest = (ctx) => __async(void 0, null, function* () {
84
113
  const draft = {
85
114
  params: ctx.params,
86
115
  query: ctx.query,
87
116
  headers: ctx.headers,
88
117
  cookies: ctx.headers.cookie
89
118
  };
90
- if (typeIs.is(ctx.request.type, ['application/json'])) {
119
+ if (typeIs.is(ctx.request.type, ["application/json"])) {
91
120
  draft.data = ctx.request.body;
92
- } else if (typeIs.is(ctx.request.type, ['multipart/form-data'])) {
121
+ } else if (typeIs.is(ctx.request.type, ["multipart/form-data"])) {
93
122
  draft.formData = ctx.request.files;
94
- } else if (typeIs.is(ctx.request.type, ['application/x-www-form-urlencoded'])) {
123
+ } else if (typeIs.is(ctx.request.type, ["application/x-www-form-urlencoded"])) {
95
124
  draft.formUrlencoded = ctx.request.body;
96
125
  } else {
97
126
  draft.body = ctx.request.body;
98
127
  }
99
128
  return draft;
100
- };
129
+ });
130
+ export {
131
+ createRouteHandler,
132
+ isNormalMethod
133
+ };
@@ -1,37 +1,59 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
23
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
+ var stdin_exports = {};
25
+ __export(stdin_exports, {
26
+ default: () => cli_default
5
27
  });
6
- exports.default = void 0;
7
- var path = _interopRequireWildcard(require("path"));
8
- var _utils = require("@modern-js/utils");
9
- var _bffCore = require("@modern-js/bff-core");
10
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
11
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
12
- var _default = () => ({
13
- name: '@modern-js/plugin-koa',
14
- setup: api => {
28
+ module.exports = __toCommonJS(stdin_exports);
29
+ var path = __toESM(require("path"));
30
+ var import_utils = require("@modern-js/utils");
31
+ var import_bff_core = require("@modern-js/bff-core");
32
+ var cli_default = () => ({
33
+ name: "@modern-js/plugin-koa",
34
+ setup: (api) => {
15
35
  let bffExportsUtils;
16
- const {
17
- useAppContext
18
- } = api;
19
- const runtimeModulePath = path.resolve(__dirname, '../runtime');
36
+ const { useAppContext } = api;
37
+ const runtimeModulePath = path.resolve(__dirname, "../runtime");
20
38
  return {
21
39
  config() {
22
40
  const appContext = useAppContext();
23
- const {
24
- appDirectory
25
- } = appContext;
26
- bffExportsUtils = (0, _utils.createRuntimeExportsUtils)(appContext.internalDirectory, 'server');
41
+ const { appDirectory } = appContext;
42
+ bffExportsUtils = (0, import_utils.createRuntimeExportsUtils)(
43
+ appContext.internalDirectory,
44
+ "server"
45
+ );
27
46
  const serverRuntimePath = bffExportsUtils.getPath();
28
- const relativeRuntimePath = (0, _bffCore.getRelativeRuntimePath)(appDirectory, serverRuntimePath);
29
- if (process.env.NODE_ENV === 'production') {
47
+ const relativeRuntimePath = (0, import_bff_core.getRelativeRuntimePath)(
48
+ appDirectory,
49
+ serverRuntimePath
50
+ );
51
+ if (process.env.NODE_ENV === "production") {
30
52
  return {
31
53
  source: {
32
54
  alias: {
33
- '@modern-js/runtime/server': relativeRuntimePath,
34
- '@modern-js/runtime/koa': relativeRuntimePath
55
+ "@modern-js/runtime/server": relativeRuntimePath,
56
+ "@modern-js/runtime/koa": relativeRuntimePath
35
57
  }
36
58
  }
37
59
  };
@@ -39,8 +61,8 @@ var _default = () => ({
39
61
  return {
40
62
  source: {
41
63
  alias: {
42
- '@modern-js/runtime/server': serverRuntimePath,
43
- '@modern-js/runtime/koa': serverRuntimePath
64
+ "@modern-js/runtime/server": serverRuntimePath,
65
+ "@modern-js/runtime/koa": serverRuntimePath
44
66
  }
45
67
  }
46
68
  };
@@ -48,8 +70,14 @@ var _default = () => ({
48
70
  },
49
71
  addRuntimeExports(input) {
50
72
  const currentFile = bffExportsUtils.getPath();
51
- const relativeRuntimeModulePath = path.relative(path.dirname(currentFile), runtimeModulePath);
52
- const relativeFramePath = path.relative(path.dirname(currentFile), require.resolve('koa'));
73
+ const relativeRuntimeModulePath = path.relative(
74
+ path.dirname(currentFile),
75
+ runtimeModulePath
76
+ );
77
+ const relativeFramePath = path.relative(
78
+ path.dirname(currentFile),
79
+ require.resolve("koa")
80
+ );
53
81
  bffExportsUtils.addExport(`const pluginRuntime = require('${relativeRuntimeModulePath}');
54
82
  const Koa = require('${relativeFramePath}')
55
83
  module.exports = {
@@ -62,4 +90,3 @@ var _default = () => ({
62
90
  };
63
91
  }
64
92
  });
65
- exports.default = _default;