alp-node 3.2.2 → 4.0.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/.eslintrc.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "root": true,
3
- "extends": ["@pob/eslint-config/root", "@pob/eslint-config-node"],
3
+ "extends": ["@pob/eslint-config/root-module"],
4
4
  "ignorePatterns": ["*.d.ts", "/dist"]
5
5
  }
package/CHANGELOG.md CHANGED
@@ -3,6 +3,28 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [4.0.0](https://github.com/christophehurpeau/alp/compare/alp-node@3.2.2...alp-node@4.0.0) (2022-01-02)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * remove findup-sync ([0f7ac09](https://github.com/christophehurpeau/alp/commit/0f7ac09d577de99eff3a559f54c0d9891c0aa265))
12
+ * update nightingale and fix tests ([3691716](https://github.com/christophehurpeau/alp/commit/36917162d0ee3dccc07384caf018b7760d98b744))
13
+
14
+
15
+ ### Features
16
+
17
+ * use ESM and drop node 12 ([f45054e](https://github.com/christophehurpeau/alp/commit/f45054e931eea88451d183722797eba057511236))
18
+
19
+
20
+ ### BREAKING CHANGES
21
+
22
+ * requires node 14 and ESM
23
+
24
+
25
+
26
+
27
+
6
28
  ## [3.2.2](https://github.com/christophehurpeau/alp/compare/alp-node@3.2.1...alp-node@3.2.2) (2021-04-10)
7
29
 
8
30
  **Note:** Version bump only for package alp-node
@@ -9,7 +9,7 @@ import translate from 'alp-translate';
9
9
  import Koa from 'koa';
10
10
  import compress from 'koa-compress';
11
11
  import serve from 'koa-static';
12
- import Logger from 'nightingale-logger';
12
+ import { Logger } from 'nightingale-logger';
13
13
 
14
14
  const logger = new Logger('alp');
15
15
  class AlpNodeApp extends Koa {
@@ -100,4 +100,4 @@ class AlpNodeApp extends Koa {
100
100
  }
101
101
 
102
102
  export { AlpNodeApp };
103
- //# sourceMappingURL=AlpNodeApp-node12.mjs.map
103
+ //# sourceMappingURL=AlpNodeApp-node14.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AlpNodeApp-node14.mjs","sources":["../src/AlpNodeApp.ts"],"sourcesContent":["import type { IncomingMessage, Server, ServerResponse } from 'http';\nimport path from 'path';\nimport { deprecate } from 'util';\nimport _listen from 'alp-listen';\nimport type { Config } from 'alp-node-config';\nimport _config from 'alp-node-config';\nimport errors from 'alp-node-errors';\nimport language from 'alp-node-language';\nimport params from 'alp-params';\nimport translate from 'alp-translate';\nimport type {\n NodeApplication,\n NodeConfig,\n Context as AlpContext,\n ContextState,\n ContextSanitizedState,\n} from 'alp-types';\nimport Koa from 'koa';\nimport type { ParameterizedContext, DefaultState } from 'koa';\nimport compress from 'koa-compress';\nimport serve from 'koa-static';\nimport { Logger } from 'nightingale-logger';\n\nconst logger = new Logger('alp');\n\nexport interface AlpNodeAppOptions {\n appDirname: string;\n packageDirname: string;\n config: Config & NodeConfig;\n certPath?: string;\n publicPath?: string;\n}\n\ndeclare module 'koa' {\n // eslint-disable-next-line @typescript-eslint/no-empty-interface, @typescript-eslint/no-shadow\n interface DefaultState extends ContextState {}\n // eslint-disable-next-line @typescript-eslint/no-empty-interface\n interface DefaultContext extends AlpContext {}\n // eslint-disable-next-line @typescript-eslint/no-empty-interface\n interface BaseContext extends AlpContext {}\n}\n\nexport class AlpNodeApp extends Koa<ContextState> implements NodeApplication {\n dirname: string;\n\n certPath: string;\n\n publicPath: string;\n\n config: NodeConfig & Config;\n\n _server?: Server;\n\n /**\n * @param {Object} [options]\n * @param {string} [options.certPath] directory of the ssl certificates\n * @param {string} [options.publicPath] directory of public files\n */\n constructor({\n appDirname,\n packageDirname,\n config,\n certPath,\n publicPath,\n }: AlpNodeAppOptions) {\n super();\n\n this.dirname = path.normalize(appDirname);\n\n Object.defineProperty(this, 'packageDirname', {\n get: deprecate(() => packageDirname, 'packageDirname'),\n configurable: false,\n enumerable: false,\n });\n\n this.certPath = certPath || `${packageDirname}/config/cert`;\n this.publicPath = publicPath || `${packageDirname}/public/`;\n\n this.config = _config(this, config);\n this.context.config = this.config;\n\n params(this);\n language(this);\n translate('locales')(this);\n\n this.use(compress());\n }\n\n existsConfigSync(name: string): ReturnType<Config['existsConfigSync']> {\n return this.config.existsConfigSync(name);\n }\n\n loadConfigSync(name: string): ReturnType<Config['loadConfigSync']> {\n return this.config.loadConfigSync(name);\n }\n\n createContext<StateT = DefaultState>(\n req: IncomingMessage,\n res: ServerResponse,\n ): ParameterizedContext<StateT> {\n const ctx = super.createContext<StateT>(req, res);\n ctx.sanitizedState = {} as ContextSanitizedState;\n return ctx;\n }\n\n servePublic(): void {\n this.use(serve(this.publicPath)); // static files\n }\n\n catchErrors(): void {\n this.use(errors);\n }\n\n listen(): Server {\n throw new Error('Use start instead');\n }\n\n /**\n * Close server and emit close event\n */\n close(): void {\n if (this._server) {\n this._server.close();\n this.emit('close');\n }\n }\n\n async start(fn: () => Promise<void> | void): Promise<Server> {\n await fn();\n try {\n const server = await _listen(this.config, this.callback(), this.certPath);\n this._server = server;\n logger.success('started');\n if (process.send) process.send('ready');\n return server;\n } catch (err: unknown) {\n logger.error('start fail', { err });\n throw err;\n }\n }\n}\n\nexport type { Context } from 'koa';\n"],"names":["logger","Logger","AlpNodeApp","Koa","constructor","appDirname","packageDirname","config","certPath","publicPath","dirname","path","normalize","Object","defineProperty","get","deprecate","configurable","enumerable","_config","context","params","language","translate","use","compress","existsConfigSync","name","loadConfigSync","createContext","req","res","ctx","sanitizedState","servePublic","serve","catchErrors","errors","listen","Error","close","_server","emit","start","fn","server","_listen","callback","success","process","send","err","error"],"mappings":";;;;;;;;;;;;;AAuBA,MAAMA,MAAM,GAAG,IAAIC,MAAJ,CAAW,KAAX,CAAf;AAmBO,MAAMC,UAAN,SAAyBC,GAAzB,CAAsE;AAW3E;AACF;AACA;AACA;AACA;AACEC,EAAAA,WAAW,CAAC;AACVC,IAAAA,U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AAAA,WAAW,GAAS;AAClB,SAAKV,GAAL,CAASW,KAAK,CAAC,KAAK1B,UAAN,CAAd,EADkB;AAEnB;;AAED2B,EAAAA,WAAW,GAAS;AAClB,SAAKZ,GAAL,CAASa,MAAT;AACD;;AAEDC,EAAAA,MAAM,GAAW;AACf,UAAM,IAAIC,KAAJ,CAAU,mBAAV,CAAN;AACD;AAED;AACF;AACA;;;AACEC,EAAAA,KAAK,GAAS;AACZ,QAAI,KAAKC,OAAT,EAAkB;AAChB,WAAKA,OAAL,CAAaD,KAAb;;AACA,WAAKE,IAAL,CAAU,OAAV;AACD;AACF;;AAEU,QAALC,KAAK,CAACC,EAAD,EAAkD;AAC3D,UAAMA,EAAE,EAAR;;AACA,QAAI;AACF,YAAMC,MAAM,GAAG,MAAMC,OAAO,CAAC,KAAKvC,MAAN,EAAc,KAAKwC,QAAL,EAAd,EAA+B,KAAKvC,QAApC,CAA5B;AACA,WAAKiC,OAAL,GAAeI,MAAf;AACA7C,MAAAA,MAAM,CAACgD,OAAP,CAAe,SAAf;AACA,UAAIC,OAAO,CAACC,IAAZ,EAAkBD,OAAO,CAACC,IAAR,CAAa,OAAb;AAClB,aAAOL,MAAP;AACD,KAND,CAME,OAAOM,GAAP,EAAqB;AACrBnD,MAAAA,MAAM,CAACoD,KAAP,CAAa,YAAb,EAA2B;AAAED,QAAAA;AAAF,OAA3B;AACA,YAAMA,GAAN;AACD;AACF;;AAjG0E;;;;"}
@@ -3,7 +3,7 @@ import type { IncomingMessage, Server, ServerResponse } from 'http';
3
3
  import type { Config } from 'alp-node-config';
4
4
  import type { NodeApplication, NodeConfig, Context as AlpContext, ContextState } from 'alp-types';
5
5
  import Koa from 'koa';
6
- import type { ParameterizedContext, DefaultState, Context } from 'koa';
6
+ import type { ParameterizedContext, DefaultState } from 'koa';
7
7
  export interface AlpNodeAppOptions {
8
8
  appDirname: string;
9
9
  packageDirname: string;
@@ -19,7 +19,6 @@ declare module 'koa' {
19
19
  interface BaseContext extends AlpContext {
20
20
  }
21
21
  }
22
- export type { Context };
23
22
  export declare class AlpNodeApp extends Koa<ContextState> implements NodeApplication {
24
23
  dirname: string;
25
24
  certPath: string;
@@ -44,4 +43,5 @@ export declare class AlpNodeApp extends Koa<ContextState> implements NodeApplica
44
43
  close(): void;
45
44
  start(fn: () => Promise<void> | void): Promise<Server>;
46
45
  }
46
+ export type { Context } from 'koa';
47
47
  //# sourceMappingURL=AlpNodeApp.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AlpNodeApp.d.ts","sourceRoot":"","sources":["../src/AlpNodeApp.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAIpE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAM9C,OAAO,KAAK,EACV,eAAe,EACf,UAAU,EACV,OAAO,IAAI,UAAU,EACrB,YAAY,EAEb,MAAM,WAAW,CAAC;AACnB,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,KAAK,EAAE,oBAAoB,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAOvE,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,OAAO,QAAQ,KAAK,CAAC;IACnB,UAAU,YAAa,SAAQ,YAAY;KAAG;IAC9C,UAAU,cAAe,SAAQ,UAAU;KAAG;IAC9C,UAAU,WAAY,SAAQ,UAAU;KAAG;CAC5C;AAED,YAAY,EAAE,OAAO,EAAE,CAAC;AAExB,qBAAa,UAAW,SAAQ,GAAG,CAAC,YAAY,CAAE,YAAW,eAAe;IAC1E,OAAO,EAAE,MAAM,CAAC;IAEhB,QAAQ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Sync } from 'fs';
2
2
  import path from 'path';
3
3
  import _config, { Config } from 'alp-node-config';
4
4
  export { Config } from 'alp-node-config';
5
- import findUp from 'findup-sync';
6
- import Logger from 'nightingale-logger';
5
+ import { Logger } from 'nightingale-logger';
7
6
  import { deprecate } from 'util';
8
7
  import _listen from 'alp-listen';
9
8
  import errors from 'alp-node-errors';
@@ -13,6 +12,7 @@ import translate from 'alp-translate';
13
12
  import Koa from 'koa';
14
13
  import compress from 'koa-compress';
15
14
  import serve from 'koa-static';
15
+ export { default as fetch } from 'node-fetch';
16
16
 
17
17
  const logger$1 = new Logger('alp');
18
18
  class AlpNodeApp extends Koa {
@@ -105,9 +105,7 @@ class AlpNodeApp extends Koa {
105
105
  const logger = new Logger('alp'); // see alp-dev
106
106
 
107
107
  const appDirname = path.resolve('build');
108
- const packagePath = findUp('package.json', {
109
- cwd: appDirname
110
- });
108
+ const packagePath = path.resolve('package.json');
111
109
 
112
110
  if (!packagePath) {
113
111
  throw new Error(`Could not find package.json: "${String(packagePath)}"`);
@@ -135,6 +133,5 @@ class App extends AlpNodeApp {
135
133
 
136
134
  }
137
135
 
138
- export default App;
139
- export { appDirname, config, packageConfig, packageDirname };
140
- //# sourceMappingURL=index-node12.mjs.map
136
+ export { appDirname, config, App as default, packageConfig, packageDirname };
137
+ //# sourceMappingURL=index-node14.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-node14.mjs","sources":["../src/AlpNodeApp.ts","../src/index.ts"],"sourcesContent":["import type { IncomingMessage, Server, ServerResponse } from 'http';\nimport path from 'path';\nimport { deprecate } from 'util';\nimport _listen from 'alp-listen';\nimport type { Config } from 'alp-node-config';\nimport _config from 'alp-node-config';\nimport errors from 'alp-node-errors';\nimport language from 'alp-node-language';\nimport params from 'alp-params';\nimport translate from 'alp-translate';\nimport type {\n NodeApplication,\n NodeConfig,\n Context as AlpContext,\n ContextState,\n ContextSanitizedState,\n} from 'alp-types';\nimport Koa from 'koa';\nimport type { ParameterizedContext, DefaultState } from 'koa';\nimport compress from 'koa-compress';\nimport serve from 'koa-static';\nimport { Logger } from 'nightingale-logger';\n\nconst logger = new Logger('alp');\n\nexport interface AlpNodeAppOptions {\n appDirname: string;\n packageDirname: string;\n config: Config & NodeConfig;\n certPath?: string;\n publicPath?: string;\n}\n\ndeclare module 'koa' {\n // eslint-disable-next-line @typescript-eslint/no-empty-interface, @typescript-eslint/no-shadow\n interface DefaultState extends ContextState {}\n // eslint-disable-next-line @typescript-eslint/no-empty-interface\n interface DefaultContext extends AlpContext {}\n // eslint-disable-next-line @typescript-eslint/no-empty-interface\n interface BaseContext extends AlpContext {}\n}\n\nexport class AlpNodeApp extends Koa<ContextState> implements NodeApplication {\n dirname: string;\n\n certPath: string;\n\n publicPath: string;\n\n config: NodeConfig & Config;\n\n _server?: Server;\n\n /**\n * @param {Object} [options]\n * @param {string} [options.certPath] directory of the ssl certificates\n * @param {string} [options.publicPath] directory of public files\n */\n constructor({\n appDirname,\n packageDirname,\n config,\n certPath,\n publicPath,\n }: AlpNodeAppOptions) {\n super();\n\n this.dirname = path.normalize(appDirname);\n\n Object.defineProperty(this, 'packageDirname', {\n get: deprecate(() => packageDirname, 'packageDirname'),\n configurable: false,\n enumerable: false,\n });\n\n this.certPath = certPath || `${packageDirname}/config/cert`;\n this.publicPath = publicPath || `${packageDirname}/public/`;\n\n this.config = _config(this, config);\n this.context.config = this.config;\n\n params(this);\n language(this);\n translate('locales')(this);\n\n this.use(compress());\n }\n\n existsConfigSync(name: string): ReturnType<Config['existsConfigSync']> {\n return this.config.existsConfigSync(name);\n }\n\n loadConfigSync(name: string): ReturnType<Config['loadConfigSync']> {\n return this.config.loadConfigSync(name);\n }\n\n createContext<StateT = DefaultState>(\n req: IncomingMessage,\n res: ServerResponse,\n ): ParameterizedContext<StateT> {\n const ctx = super.createContext<StateT>(req, res);\n ctx.sanitizedState = {} as ContextSanitizedState;\n return ctx;\n }\n\n servePublic(): void {\n this.use(serve(this.publicPath)); // static files\n }\n\n catchErrors(): void {\n this.use(errors);\n }\n\n listen(): Server {\n throw new Error('Use start instead');\n }\n\n /**\n * Close server and emit close event\n */\n close(): void {\n if (this._server) {\n this._server.close();\n this.emit('close');\n }\n }\n\n async start(fn: () => Promise<void> | void): Promise<Server> {\n await fn();\n try {\n const server = await _listen(this.config, this.callback(), this.certPath);\n this._server = server;\n logger.success('started');\n if (process.send) process.send('ready');\n return server;\n } catch (err: unknown) {\n logger.error('start fail', { err });\n throw err;\n }\n }\n}\n\nexport type { Context } from 'koa';\n","import { existsSync, readFileSync } from 'fs';\nimport path from 'path';\nimport { Config } from 'alp-node-config';\nimport { Logger } from 'nightingale-logger';\nimport type { AlpNodeAppOptions } from './AlpNodeApp';\nimport { AlpNodeApp } from './AlpNodeApp';\n\nexport { default as fetch } from 'node-fetch';\n\nexport type { Context } from './AlpNodeApp';\nexport { Config } from 'alp-node-config';\n\nconst logger = new Logger('alp');\n\n// see alp-dev\nexport const appDirname = path.resolve('build');\n\nconst packagePath = path.resolve('package.json');\nif (!packagePath) {\n throw new Error(`Could not find package.json: \"${String(packagePath)}\"`);\n}\nexport const packageDirname = path.dirname(packagePath);\n\nlogger.debug('init', { appDirname, packageDirname });\n\nexport const packageConfig: Record<string, unknown> = JSON.parse(\n readFileSync(packagePath, 'utf-8'),\n) as Record<string, unknown>;\n\nconst buildedConfigPath = `${appDirname}/build/config/`;\nconst configPath = existsSync(buildedConfigPath)\n ? buildedConfigPath\n : `${appDirname}/config/`;\n\nexport const config = new Config(configPath).loadSync({ packageConfig });\n\nexport type AppOptions = Omit<\n AlpNodeAppOptions,\n 'appDirname' | 'packageDirname' | 'config'\n>;\n\nexport default class App extends AlpNodeApp {\n constructor(options?: AppOptions) {\n super({\n ...options,\n appDirname,\n packageDirname,\n config,\n });\n }\n}\n"],"names":["logger","Logger","AlpNodeApp","Koa","constructor","appDirname","packageDirname","config","certPath","publicPath","dirname","path","normalize","Object","defineProperty","get","deprecate","configurable","enumerable","_config","context","params","language","translate","use","compress","existsConfigSync","name","loadConfigSync","createContext","req","res","ctx","sanitizedState","servePublic","serve","catchErrors","errors","listen","Error","close","_server","emit","start","fn","server","_listen","callback","success","process","send","err","error","resolve","packagePath","String","debug","packageConfig","JSON","parse","readFileSync","buildedConfigPath","configPath","existsSync","Config","loadSync","App","options"],"mappings":";;;;;;;;;;;;;;;;AAuBA,MAAMA,QAAM,GAAG,IAAIC,MAAJ,CAAW,KAAX,CAAf;AAmBO,MAAMC,UAAN,SAAyBC,GAAzB,CAAsE;AAW3E;AACF;AACA;AACA;AACA;AACEC,EAAAA,WAAW,CAAC;AACVC,IAAAA,UADU;AAEVC,IAAAA,cAFU;AAGVC,IAAAA,MAHU;AAIVC,IAAAA,QAJU;AAKVC,IAAAA;AALU,GAAD,EAMW;AACpB;AAEA,SAAKC,OAAL,GAAeC,IAAI,CAACC,SAAL,CAAeP,UAAf,CAAf;AAEAQ,IAAAA,MAAM,CAACC,cAAP,CAAsB,IAAtB,EAA4B,gBAA5B,EAA8C;AAC5CC,MAAAA,GAAG,EAAEC,SAAS,CAAC,MAAMV,cAAP,EAAuB,gBAAvB,CAD8B;AAE5CW,MAAAA,YAAY,EAAE,KAF8B;AAG5CC,MAAAA,UAAU,EAAE;AAHgC,KAA9C;AAMA,SAAKV,QAAL,GAAgBA,QAAQ,IAAK,GAAEF,cAAe,cAA9C;AACA,SAAKG,UAAL,GAAkBA,UAAU,IAAK,GAAEH,cAAe,UAAlD;AAEA,SAAKC,MAAL,GAAcY,OAAO,CAAC,IAAD,EAAOZ,MAAP,CAArB;AACA,SAAKa,OAAL,CAAab,MAAb,GAAsB,KAAKA,MAA3B;AAEAc,IAAAA,MAAM,CAAC,IAAD,CAAN;AACAC,IAAAA,QAAQ,CAAC,IAAD,CAAR;AACAC,IAAAA,SAAS,CAAC,SAAD,CAAT,CAAqB,IAArB;AAEA,SAAKC,GAAL,CAASC,QAAQ,EAAjB;AACD;;AAEDC,EAAAA,gBAAgB,CAACC,IAAD,EAAuD;AACrE,WAA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ACA,YAAMA,GAAN;AACD;AACF;;AAjG0E;;AC9B7E,MAAMnD,MAAM,GAAG,IAAIC,MAAJ,CAAW,KAAX,CAAf;;MAGaI,UAAU,GAAGM,IAAI,CAAC0C,OAAL,CAAa,OAAb;AAE1B,MAAMC,WAAW,GAAG3C,IAAI,CAAC0C,OAAL,CAAa,cAAb,CAApB;;AACA,IAAI,CAACC,WAAL,EAAkB;AAChB,QAAM,IAAIf,KAAJ,CAAW,iCAAgCgB,MAAM,CAACD,WAAD,CAAc,GAA/D,CAAN;AACD;;MACYhD,cAAc,GAAGK,IAAI,CAACD,OAAL,CAAa4C,WAAb;AAE9BtD,MAAM,CAACwD,KAAP,CAAa,MAAb,EAAqB;AAAEnD,EAAAA,UAAF;AAAcC,EAAAA;AAAd,CAArB;MAEamD,aAAsC,GAAGC,IAAI,CAACC,KAAL,CACpDC,YAAY,CAACN,WAAD,EAAc,OAAd,CADwC;AAItD,MAAMO,iBAAiB,GAAI,GAAExD,UAAW,gBAAxC;AACA,MAAMyD,UAAU,GAAGC,UAAU,CAACF,iBAAD,CAAV,GACfA,iBADe,GAEd,GAAExD,UAAW,UAFlB;MAIaE,MAAM,GAAG,IAAIyD,MAAJ,CAAWF,UAAX,EAAuBG,QAAvB,CAAgC;AAAER,EAAAA;AAAF,CAAhC;AAOP,MAAMS,GAAN,SAAkBhE,UAAlB,CAA6B;AAC1CE,EAAAA,WAAW,CAAC+D,OAAD,EAAuB;AAChC,UAAM,EACJ,GAAGA,OADC;AAEJ9D,MAAAA,UAFI;AAGJC,MAAAA,cAHI;AAIJC,MAAAA;AAJI,KAAN;AAMD;;AARyC;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { Config } from 'alp-node-config';
2
- import type { AlpNodeAppOptions, Context } from './AlpNodeApp';
2
+ import type { AlpNodeAppOptions } from './AlpNodeApp';
3
3
  import { AlpNodeApp } from './AlpNodeApp';
4
- export type { Context };
5
- export { Config };
4
+ export { default as fetch } from 'node-fetch';
5
+ export type { Context } from './AlpNodeApp';
6
+ export { Config } from 'alp-node-config';
6
7
  export declare const appDirname: string;
7
8
  export declare const packageDirname: string;
8
9
  export declare const packageConfig: Record<string, unknown>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAGzC,OAAO,KAAK,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,YAAY,EAAE,OAAO,EAAE,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,CAAC;AAKlB,eAAO,MAAM,UAAU,QAAwB,CAAC;AAMhD,eAAO,MAAM,cAAc,QAA4B,CAAC;AAIxD,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAEtB,CAAC;AAO7B,eAAO,MAAM,MAAM,yCAAqD,CAAC;AAEzE,oBAAY,UAAU,GAAG,IAAI,CAC3B,iBAAiB,EACjB,YAAY,GAAG,gBAAgB,GAAG,QAAQ,CAC3C,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,GAAI,SAAQ,UAAU;gBAC7B,OAAO,CAAC,EAAE,UAAU;CAQjC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,YAAY,CAAC;AAE9C,YAAY,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAKzC,eAAO,MAAM,UAAU,QAAwB,CAAC;AAMhD,eAAO,MAAM,cAAc,QAA4B,CAAC;AAIxD,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAEtB,CAAC;AAO7B,eAAO,MAAM,MAAM,yCAAqD,CAAC;AAEzE,oBAAY,UAAU,GAAG,IAAI,CAC3B,iBAAiB,EACjB,YAAY,GAAG,gBAAgB,GAAG,QAAQ,CAC3C,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,GAAI,SAAQ,UAAU;gBAC7B,OAAO,CAAC,EAAE,UAAU;CAQjC"}
@@ -1,3 +1,5 @@
1
1
  'use strict';
2
2
 
3
3
  global.fetch = require('node-fetch');
4
+
5
+ module.exports = global.fetch;
package/fetch.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { default } from 'node-fetch';
package/fetch.mjs CHANGED
@@ -1,3 +1,6 @@
1
1
  import fetch from 'node-fetch';
2
2
 
3
3
  global.fetch = fetch;
4
+
5
+ // eslint-disable-next-line unicorn/prefer-export-from
6
+ export default fetch;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alp-node",
3
- "version": "3.2.2",
3
+ "version": "4.0.0",
4
4
  "description": "framework based on koa 2",
5
5
  "keywords": [
6
6
  "springbokjs",
@@ -20,30 +20,29 @@
20
20
  "bugs": {
21
21
  "url": "https://github.com/alpjs/alp-node/issues"
22
22
  },
23
+ "type": "module",
23
24
  "engines": {
24
- "node": ">=12.10.0"
25
+ "node": "^14.13.1 || >=16.0.0"
25
26
  },
26
- "main": "./index.js",
27
+ "main": "./dist/index-node14.mjs",
27
28
  "types": "./dist/index.d.ts",
29
+ "typesVersions": {
30
+ ">=3.1": {
31
+ "fetch.mjs": [
32
+ "fetch.d.ts"
33
+ ]
34
+ }
35
+ },
28
36
  "exports": {
37
+ "./package.json": "./package.json",
29
38
  ".": {
30
39
  "node": {
31
- "development": {
32
- "import": "./dist/index-node12-dev.mjs",
33
- "require": "./dist/index-node12-dev.cjs.js"
34
- },
35
- "import": "./dist/index-node12.mjs",
36
- "require": "./dist/index-node12.cjs.js"
40
+ "import": "./dist/index-node14.mjs"
37
41
  }
38
42
  },
39
43
  "./AlpNodeApp": {
40
44
  "node": {
41
- "development": {
42
- "import": "./dist/AlpNodeApp-node12-dev.mjs",
43
- "require": "./dist/AlpNodeApp-node12-dev.cjs.js"
44
- },
45
- "import": "./dist/AlpNodeApp-node12.mjs",
46
- "require": "./dist/AlpNodeApp-node12.cjs.js"
45
+ "import": "./dist/AlpNodeApp-node14.mjs"
47
46
  }
48
47
  },
49
48
  "./fetch": {
@@ -51,21 +50,17 @@
51
50
  "require": "./fetch.js"
52
51
  }
53
52
  },
54
- "module:node": "./dist/index-node12.mjs",
55
- "module:node-dev": "./dist/index-node12-dev.mjs",
53
+ "module:node": "./dist/index-node14.mjs",
56
54
  "module:aliases-node": {
57
- "./AlpNodeApp.js": "./dist/AlpNodeApp-node12.es.js"
58
- },
59
- "module:aliases-node-dev": {
60
- "./AlpNodeApp.js": "./dist/AlpNodeApp-node12-dev.es.js"
55
+ "./AlpNodeApp.js": "./dist/AlpNodeApp-node14.es.js"
61
56
  },
62
57
  "sideEffects": false,
63
58
  "scripts": {
64
59
  "build": "pob-build && yarn run build:definitions",
65
60
  "build:definitions": "tsc -p tsconfig.build.json",
66
- "clean": "rm -Rf docs dist",
61
+ "clean": "rm -Rf dist",
67
62
  "lint": "yarn run lint:eslint",
68
- "lint:eslint": "yarn --cwd ../.. run eslint --ext .js,.mjs,.ts --report-unused-disable-directives --quiet packages/alp-node",
63
+ "lint:eslint": "cd ../.. && yarn run eslint --report-unused-disable-directives --resolve-plugins-relative-to . --quiet packages/alp-node",
69
64
  "watch": "pob-watch"
70
65
  },
71
66
  "prettier": {
@@ -77,9 +72,8 @@
77
72
  "babelEnvs": [
78
73
  {
79
74
  "target": "node",
80
- "version": "12",
75
+ "version": "14",
81
76
  "formats": [
82
- "cjs",
83
77
  "es"
84
78
  ]
85
79
  }
@@ -95,29 +89,26 @@
95
89
  "dependencies": {
96
90
  "@types/koa": "^2.13.1",
97
91
  "@types/node-fetch": "^2.5.8",
98
- "alp-listen": "^4.1.3",
99
- "alp-node-config": "^6.1.2",
100
- "alp-node-errors": "^5.1.2",
101
- "alp-node-language": "^4.3.1",
102
- "alp-params": "^3.2.2",
103
- "alp-translate": "^5.1.3",
92
+ "alp-listen": "5.0.0",
93
+ "alp-node-config": "7.0.0",
94
+ "alp-node-errors": "6.0.0",
95
+ "alp-node-language": "5.0.0",
96
+ "alp-params": "4.0.0",
97
+ "alp-translate": "6.0.0",
104
98
  "alp-types": "^3.0.0",
105
- "findup-sync": "^4.0.0",
106
99
  "koa": "^2.13.1",
107
100
  "koa-compress": "^5.0.0",
108
101
  "koa-static": "^5.0.0",
109
- "nightingale-logger": "^11.0.5",
102
+ "nightingale-logger": "^12.1.2",
110
103
  "node-fetch": "^2.6.1"
111
104
  },
112
105
  "devDependencies": {
113
- "@babel/core": "7.13.14",
114
- "@types/findup-sync": "2.0.2",
115
- "@types/koa-compress": "4.0.1",
116
- "@types/koa-static": "4.0.1",
117
- "@types/minimist": "1.2.1",
118
- "babel-preset-latest-node": "5.5.1",
119
- "pob-babel": "26.8.0",
120
- "rollup": "2.43.1"
106
+ "@babel/core": "7.16.7",
107
+ "@types/koa-compress": "4.0.3",
108
+ "@types/koa-static": "4.0.2",
109
+ "@types/minimist": "1.2.2",
110
+ "pob-babel": "29.6.1",
111
+ "typescript": "4.5.4"
121
112
  },
122
- "gitHead": "bf4ed59d61ee4b4ed741a9764263b1924c941546"
113
+ "gitHead": "854189ce2307f42363e81bcf7862c5f1deced54a"
123
114
  }
@@ -0,0 +1,3 @@
1
+ import createRollupConfig from 'pob-babel/createRollupConfig.js';
2
+
3
+ export default createRollupConfig({});
@@ -7,7 +7,24 @@
7
7
  "plugins": ["@typescript-eslint"],
8
8
  "extends": [
9
9
  "@pob/eslint-config-typescript",
10
- "@pob/eslint-config-typescript-node"
10
+ "@pob/eslint-config-typescript/node"
11
11
  ],
12
- "ignorePatterns": ["*.d.ts"]
12
+ "ignorePatterns": ["*.d.ts"],
13
+ "overrides": [
14
+ {
15
+ "files": ["**/*.test.ts", "__tests__/**/*.ts"],
16
+ "extends": ["@pob/eslint-config-typescript/test"],
17
+ "env": {
18
+ "jest": true
19
+ },
20
+ "rules": {
21
+ "import/no-extraneous-dependencies": [
22
+ "error",
23
+ {
24
+ "devDependencies": true
25
+ }
26
+ ]
27
+ }
28
+ }
29
+ ]
13
30
  }
package/src/AlpNodeApp.ts CHANGED
@@ -16,10 +16,10 @@ import type {
16
16
  ContextSanitizedState,
17
17
  } from 'alp-types';
18
18
  import Koa from 'koa';
19
- import type { ParameterizedContext, DefaultState, Context } from 'koa';
19
+ import type { ParameterizedContext, DefaultState } from 'koa';
20
20
  import compress from 'koa-compress';
21
21
  import serve from 'koa-static';
22
- import Logger from 'nightingale-logger';
22
+ import { Logger } from 'nightingale-logger';
23
23
 
24
24
  const logger = new Logger('alp');
25
25
 
@@ -32,13 +32,14 @@ export interface AlpNodeAppOptions {
32
32
  }
33
33
 
34
34
  declare module 'koa' {
35
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface, @typescript-eslint/no-shadow
35
36
  interface DefaultState extends ContextState {}
37
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
36
38
  interface DefaultContext extends AlpContext {}
39
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
37
40
  interface BaseContext extends AlpContext {}
38
41
  }
39
42
 
40
- export type { Context };
41
-
42
43
  export class AlpNodeApp extends Koa<ContextState> implements NodeApplication {
43
44
  dirname: string;
44
45
 
@@ -138,3 +139,5 @@ export class AlpNodeApp extends Koa<ContextState> implements NodeApplication {
138
139
  }
139
140
  }
140
141
  }
142
+
143
+ export type { Context } from 'koa';
package/src/index.ts CHANGED
@@ -1,20 +1,21 @@
1
1
  import { existsSync, readFileSync } from 'fs';
2
2
  import path from 'path';
3
3
  import { Config } from 'alp-node-config';
4
- import findUp from 'findup-sync';
5
- import Logger from 'nightingale-logger';
6
- import type { AlpNodeAppOptions, Context } from './AlpNodeApp';
4
+ import { Logger } from 'nightingale-logger';
5
+ import type { AlpNodeAppOptions } from './AlpNodeApp';
7
6
  import { AlpNodeApp } from './AlpNodeApp';
8
7
 
9
- export type { Context };
10
- export { Config };
8
+ export { default as fetch } from 'node-fetch';
9
+
10
+ export type { Context } from './AlpNodeApp';
11
+ export { Config } from 'alp-node-config';
11
12
 
12
13
  const logger = new Logger('alp');
13
14
 
14
15
  // see alp-dev
15
16
  export const appDirname = path.resolve('build');
16
17
 
17
- const packagePath = findUp('package.json', { cwd: appDirname });
18
+ const packagePath = path.resolve('package.json');
18
19
  if (!packagePath) {
19
20
  throw new Error(`Could not find package.json: "${String(packagePath)}"`);
20
21
  }
package/AlpNodeApp.js DELETED
@@ -1,8 +0,0 @@
1
- /* eslint-disable import/no-dynamic-require */
2
-
3
- 'use strict';
4
-
5
- const production = process.env.NODE_ENV === 'production';
6
- module.exports = require(`./dist/AlpNodeApp-node12${
7
- production ? '' : '-dev'
8
- }.cjs`);
@@ -1,121 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- const path = require('path');
6
- const util = require('util');
7
- const _listen = require('alp-listen');
8
- const _config = require('alp-node-config');
9
- const errors = require('alp-node-errors');
10
- const language = require('alp-node-language');
11
- const params = require('alp-params');
12
- const translate = require('alp-translate');
13
- const Koa = require('koa');
14
- const compress = require('koa-compress');
15
- const serve = require('koa-static');
16
- const Logger = require('nightingale-logger');
17
-
18
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e['default'] : e; }
19
-
20
- const path__default = /*#__PURE__*/_interopDefaultLegacy(path);
21
- const _listen__default = /*#__PURE__*/_interopDefaultLegacy(_listen);
22
- const _config__default = /*#__PURE__*/_interopDefaultLegacy(_config);
23
- const errors__default = /*#__PURE__*/_interopDefaultLegacy(errors);
24
- const language__default = /*#__PURE__*/_interopDefaultLegacy(language);
25
- const params__default = /*#__PURE__*/_interopDefaultLegacy(params);
26
- const translate__default = /*#__PURE__*/_interopDefaultLegacy(translate);
27
- const Koa__default = /*#__PURE__*/_interopDefaultLegacy(Koa);
28
- const compress__default = /*#__PURE__*/_interopDefaultLegacy(compress);
29
- const serve__default = /*#__PURE__*/_interopDefaultLegacy(serve);
30
- const Logger__default = /*#__PURE__*/_interopDefaultLegacy(Logger);
31
-
32
- const logger = new Logger__default('alp');
33
- class AlpNodeApp extends Koa__default {
34
- /**
35
- * @param {Object} [options]
36
- * @param {string} [options.certPath] directory of the ssl certificates
37
- * @param {string} [options.publicPath] directory of public files
38
- */
39
- constructor({
40
- appDirname,
41
- packageDirname,
42
- config,
43
- certPath,
44
- publicPath
45
- }) {
46
- super();
47
- this.dirname = path__default.normalize(appDirname);
48
- Object.defineProperty(this, 'packageDirname', {
49
- get: util.deprecate(() => packageDirname, 'packageDirname'),
50
- configurable: false,
51
- enumerable: false
52
- });
53
- this.certPath = certPath || `${packageDirname}/config/cert`;
54
- this.publicPath = publicPath || `${packageDirname}/public/`;
55
- this.config = _config__default(this, config);
56
- this.context.config = this.config;
57
- params__default(this);
58
- language__default(this);
59
- translate__default('locales')(this);
60
- this.use(compress__default());
61
- }
62
-
63
- existsConfigSync(name) {
64
- return this.config.existsConfigSync(name);
65
- }
66
-
67
- loadConfigSync(name) {
68
- return this.config.loadConfigSync(name);
69
- }
70
-
71
- createContext(req, res) {
72
- const ctx = super.createContext(req, res);
73
- ctx.sanitizedState = {};
74
- return ctx;
75
- }
76
-
77
- servePublic() {
78
- this.use(serve__default(this.publicPath)); // static files
79
- }
80
-
81
- catchErrors() {
82
- this.use(errors__default);
83
- }
84
-
85
- listen() {
86
- throw new Error('Use start instead');
87
- }
88
- /**
89
- * Close server and emit close event
90
- */
91
-
92
-
93
- close() {
94
- if (this._server) {
95
- this._server.close();
96
-
97
- this.emit('close');
98
- }
99
- }
100
-
101
- async start(fn) {
102
- await fn();
103
-
104
- try {
105
- const server = await _listen__default(this.config, this.callback(), this.certPath);
106
- this._server = server;
107
- logger.success('started');
108
- if (process.send) process.send('ready');
109
- return server;
110
- } catch (err) {
111
- logger.error('start fail', {
112
- err
113
- });
114
- throw err;
115
- }
116
- }
117
-
118
- }
119
-
120
- exports.AlpNodeApp = AlpNodeApp;
121
- //# sourceMappingURL=AlpNodeApp-node12-dev.cjs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AlpNodeApp-node12-dev.cjs.js","sources":["../src/AlpNodeApp.ts"],"sourcesContent":["import type { IncomingMessage, Server, ServerResponse } from 'http';\nimport path from 'path';\nimport { deprecate } from 'util';\nimport _listen from 'alp-listen';\nimport type { Config } from 'alp-node-config';\nimport _config from 'alp-node-config';\nimport errors from 'alp-node-errors';\nimport language from 'alp-node-language';\nimport params from 'alp-params';\nimport translate from 'alp-translate';\nimport type {\n NodeApplication,\n NodeConfig,\n Context as AlpContext,\n ContextState,\n ContextSanitizedState,\n} from 'alp-types';\nimport Koa from 'koa';\nimport type { ParameterizedContext, DefaultState, Context } from 'koa';\nimport compress from 'koa-compress';\nimport serve from 'koa-static';\nimport Logger from 'nightingale-logger';\n\nconst logger = new Logger('alp');\n\nexport interface AlpNodeAppOptions {\n appDirname: string;\n packageDirname: string;\n config: Config & NodeConfig;\n certPath?: string;\n publicPath?: string;\n}\n\ndeclare module 'koa' {\n interface DefaultState extends ContextState {}\n interface DefaultContext extends AlpContext {}\n interface BaseContext extends AlpContext {}\n}\n\nexport type { Context };\n\nexport class AlpNodeApp extends Koa<ContextState> implements NodeApplication {\n dirname: string;\n\n certPath: string;\n\n publicPath: string;\n\n config: NodeConfig & Config;\n\n _server?: Server;\n\n /**\n * @param {Object} [options]\n * @param {string} [options.certPath] directory of the ssl certificates\n * @param {string} [options.publicPath] directory of public files\n */\n constructor({\n appDirname,\n packageDirname,\n config,\n certPath,\n publicPath,\n }: AlpNodeAppOptions) {\n super();\n\n this.dirname = path.normalize(appDirname);\n\n Object.defineProperty(this, 'packageDirname', {\n get: deprecate(() => packageDirname, 'packageDirname'),\n configurable: false,\n enumerable: false,\n });\n\n this.certPath = certPath || `${packageDirname}/config/cert`;\n this.publicPath = publicPath || `${packageDirname}/public/`;\n\n this.config = _config(this, config);\n this.context.config = this.config;\n\n params(this);\n language(this);\n translate('locales')(this);\n\n this.use(compress());\n }\n\n existsConfigSync(name: string): ReturnType<Config['existsConfigSync']> {\n return this.config.existsConfigSync(name);\n }\n\n loadConfigSync(name: string): ReturnType<Config['loadConfigSync']> {\n return this.config.loadConfigSync(name);\n }\n\n createContext<StateT = DefaultState>(\n req: IncomingMessage,\n res: ServerResponse,\n ): ParameterizedContext<StateT> {\n const ctx = super.createContext<StateT>(req, res);\n ctx.sanitizedState = {} as ContextSanitizedState;\n return ctx;\n }\n\n servePublic(): void {\n this.use(serve(this.publicPath)); // static files\n }\n\n catchErrors(): void {\n this.use(errors);\n }\n\n listen(): Server {\n throw new Error('Use start instead');\n }\n\n /**\n * Close server and emit close event\n */\n close(): void {\n if (this._server) {\n this._server.close();\n this.emit('close');\n }\n }\n\n async start(fn: () => Promise<void> | void): Promise<Server> {\n await fn();\n try {\n const server = await _listen(this.config, this.callback(), this.certPath);\n this._server = server;\n logger.success('started');\n if (process.send) process.send('ready');\n return server;\n } catch (err: unknown) {\n logger.error('start fail', { err });\n throw err;\n }\n }\n}\n"],"names":["logger","Logger","AlpNodeApp","Koa","constructor","appDirname","packageDirname","config","certPath","publicPath","dirname","path","normalize","Object","defineProperty","get","deprecate","configurable","enumerable","_config","context","params","language","translate","use","compress","existsConfigSync","name","loadConfigSync","createContext","req","res","ctx","sanitizedState","servePublic","serve","catchErrors","errors","listen","Error","close","_server","emit","start","fn","server","_listen","callback","success","process","send","err","error"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAMA,MAAM,GAAG,IAAIC,eAAJ,CAAW,KAAX,CAAf;AAkBO,MAAMC,UAAN,SAAyBC,YAAzB,CAAsE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