skuba-dive 1.1.0 β†’ 2.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/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # 🀿🌊
2
2
 
3
- ![GitHub Release](https://github.com/seek-oss/skuba-dive/workflows/Release/badge.svg?branch=master)
4
- ![GitHub Validate](https://github.com/seek-oss/skuba-dive/workflows/Validate/badge.svg?branch=master)
3
+ [![GitHub Release](https://github.com/seek-oss/skuba-dive/workflows/Release/badge.svg?branch=master)](https://github.com/seek-oss/skuba-dive/actions?query=workflow%3ARelease)
4
+ [![GitHub Validate](https://github.com/seek-oss/skuba-dive/workflows/Validate/badge.svg?branch=master)](https://github.com/seek-oss/skuba-dive/actions?query=workflow%3AValidate)
5
5
  [![Node.js version](https://img.shields.io/badge/node-%3E%3D%2012-brightgreen)](https://nodejs.org/en/)
6
6
  [![npm package](https://img.shields.io/npm/v/skuba-dive)](https://www.npmjs.com/package/skuba-dive)
7
7
  [![Powered by skuba](https://img.shields.io/badge/🀿%20skuba-powered-009DC4)](https://github.com/seek-oss/skuba)
@@ -15,7 +15,7 @@ Minimal runtime for [`skuba`](https://github.com/seek-oss/skuba).
15
15
  - [Env](#env)
16
16
  - [Register](#register)
17
17
  - [Design](#design)
18
- - [Development](#development)
18
+ - [Contributing](https://github.com/seek-oss/skuba-dive/blob/master/CONTRIBUTING.md)
19
19
 
20
20
  ## API reference
21
21
 
@@ -58,21 +58,32 @@ export const environment = Env.oneOf(ENVIRONMENTS)('ENVIRONMENT');
58
58
 
59
59
  export const port = Env.nonNegativeInteger('PORT', { default: undefined });
60
60
  // number | undefined
61
+
62
+ export const version = Env.string('VERSION', { default: 'local' });
63
+ // string | 'local'
64
+
65
+ export const flag = Env.boolean('FLAG');
66
+ // boolean
61
67
  ```
62
68
 
63
69
  Each function will throw if its environment variable is not set and `opts.default` is not provided.
64
70
 
65
71
  ### Register
66
72
 
67
- Runtime hook for:
68
-
69
- - Import paths relative to `/src`
70
- - Stack traces that map back to your `.ts` sources
73
+ Runtime hook for import paths relative to `/src`.
71
74
 
72
- Make a side-effectful import at the top of your entry point, e.g. `/src/app.ts`:
75
+ Make a side-effectful import at the top of your entry point(s):
73
76
 
74
77
  ```typescript
78
+ // /src/register.ts
79
+
75
80
  import 'skuba-dive/register';
81
+ ```
82
+
83
+ ```typescript
84
+ // /src/app.ts
85
+
86
+ import './register';
76
87
 
77
88
  import { config } from 'src/config';
78
89
 
@@ -92,36 +103,3 @@ See `skuba`'s [goals] and [non-goals] for more information.
92
103
 
93
104
  [goals]: https://github.com/seek-oss/skuba#goals
94
105
  [non-goals]: https://github.com/seek-oss/skuba#non-goals
95
-
96
- ## Development
97
-
98
- ### Prerequisites
99
-
100
- - Node.js 12+
101
- - Yarn 1.x
102
-
103
- ```shell
104
- yarn install
105
- ```
106
-
107
- ### Lint
108
-
109
- ```shell
110
- # fix
111
- yarn format
112
-
113
- # check
114
- yarn lint
115
- ```
116
-
117
- ### Test
118
-
119
- ```shell
120
- yarn test
121
- ```
122
-
123
- ### Build
124
-
125
- ```shell
126
- yarn build
127
- ```
@@ -2,6 +2,6 @@
2
2
  * Create a function that reads an environment variable and runs it through the
3
3
  * provided parsing function.
4
4
  */
5
- export declare const create: <T>(parse: (value: string) => T) => <U = T>(name: string, opts?: Readonly<{
5
+ export declare const create: <T>(parse: (value: string, name: string) => T) => <U = T>(name: string, opts?: Readonly<{
6
6
  default: U;
7
7
  }> | undefined) => T | U;
package/lib/env/create.js CHANGED
@@ -5,14 +5,15 @@ exports.create = void 0;
5
5
  * Create a function that reads an environment variable and runs it through the
6
6
  * provided parsing function.
7
7
  */
8
- exports.create = (parse) => (name, opts) => {
8
+ const create = (parse) => (name, opts) => {
9
9
  const value = process.env[name];
10
10
  if (typeof value !== 'undefined') {
11
- return parse(value);
11
+ return parse(value, name);
12
12
  }
13
13
  if (typeof opts !== 'undefined') {
14
14
  return opts.default;
15
15
  }
16
- throw Error(`process.env.${name} not set`);
16
+ throw Error(`process.env.${name} is not set`);
17
17
  };
18
+ exports.create = create;
18
19
  //# sourceMappingURL=create.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"create.js","sourceRoot":"","sources":["../../src/env/create.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACU,QAAA,MAAM,GAAG,CAAI,KAA2B,EAAE,EAAE,CAAC,CACxD,IAAY,EACZ,IAA+B,EACxB,EAAE;IACT,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAEhC,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE;QAChC,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC;KACrB;IAED,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE;QAC/B,OAAO,IAAI,CAAC,OAAO,CAAC;KACrB;IAED,MAAM,KAAK,CAAC,eAAe,IAAI,UAAU,CAAC,CAAC;AAC7C,CAAC,CAAC"}
1
+ {"version":3,"file":"create.js","sourceRoot":"","sources":["../../src/env/create.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACI,MAAM,MAAM,GACjB,CAAI,KAAyC,EAAE,EAAE,CACjD,CAAQ,IAAY,EAAE,IAA+B,EAAS,EAAE;IAC9D,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAEhC,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE;QAChC,OAAO,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;KAC3B;IAED,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE;QAC/B,OAAO,IAAI,CAAC,OAAO,CAAC;KACrB;IAED,MAAM,KAAK,CAAC,eAAe,IAAI,aAAa,CAAC,CAAC;AAChD,CAAC,CAAC;AAdS,QAAA,MAAM,UAcf"}
package/lib/env/index.js CHANGED
@@ -7,7 +7,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
7
7
  o[k2] = m[k];
8
8
  }));
9
9
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  __exportStar(require("./create"), exports);
@@ -1,3 +1,4 @@
1
- export declare const nonNegativeInteger: (input: string) => number;
2
- export declare const noop: <T>(input: T) => T;
3
- export declare const oneOf: <T>(choices: readonly T[]) => (input: unknown) => T;
1
+ export declare const nonNegativeInteger: (input: string, name: string) => number;
2
+ export declare const noop: <T>(input: T, _name: string) => T;
3
+ export declare const oneOf: <T>(choices: readonly T[]) => (input: unknown, name: string) => T;
4
+ export declare const boolean: (input: string) => boolean;
@@ -1,21 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.oneOf = exports.noop = exports.nonNegativeInteger = void 0;
4
- exports.nonNegativeInteger = (input) => {
3
+ exports.boolean = exports.oneOf = exports.noop = exports.nonNegativeInteger = void 0;
4
+ const nonNegativeInteger = (input, name) => {
5
5
  const int = parseInt(input, 10);
6
6
  if (int < 0 || !Number.isSafeInteger(int) || input !== String(int)) {
7
- throw Error(`not a non-negative integer: '${input}'`);
7
+ throw Error(`process.env.${name} is not a non-negative integer: '${input}'`);
8
8
  }
9
9
  return int;
10
10
  };
11
- exports.noop = (input) => input;
12
- exports.oneOf = (choices) => {
11
+ exports.nonNegativeInteger = nonNegativeInteger;
12
+ const noop = (input, _name) => input;
13
+ exports.noop = noop;
14
+ const oneOf = (choices) => {
13
15
  const isChoice = (value) => new Set(choices).has(value);
14
- return (input) => {
16
+ return (input, name) => {
15
17
  if (!isChoice(input)) {
16
- throw Error(`not a supported choice: '${String(input)}'`);
18
+ throw Error(`process.env.${name} is not a supported choice: '${String(input)}'. Expected one of: [${choices
19
+ .map((choice) => `'${String(choice)}'`)
20
+ .join(', ')}]`);
17
21
  }
18
22
  return input;
19
23
  };
20
24
  };
25
+ exports.oneOf = oneOf;
26
+ const falseys = ['false', 'off', 'no', 'n', '0'];
27
+ const boolean = (input) => falseys.includes(input.toLowerCase()) ? false : Boolean(input);
28
+ exports.boolean = boolean;
21
29
  //# sourceMappingURL=parsers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"parsers.js","sourceRoot":"","sources":["../../src/env/parsers.ts"],"names":[],"mappings":";;;AAAa,QAAA,kBAAkB,GAAG,CAAC,KAAa,EAAU,EAAE;IAC1D,MAAM,GAAG,GAAG,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAEhC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,KAAK,KAAK,MAAM,CAAC,GAAG,CAAC,EAAE;QAClE,MAAM,KAAK,CAAC,gCAAgC,KAAK,GAAG,CAAC,CAAC;KACvD;IAED,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAEW,QAAA,IAAI,GAAG,CAAI,KAAQ,EAAK,EAAE,CAAC,KAAK,CAAC;AAEjC,QAAA,KAAK,GAAG,CAAI,OAAqB,EAAE,EAAE;IAChD,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAmC,EAAE,CACnE,IAAI,GAAG,CAAU,OAAO,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAEvC,OAAO,CAAC,KAAc,EAA0B,EAAE;QAChD,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;YACpB,MAAM,KAAK,CAAC,4BAA4B,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;SAC3D;QAED,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;AACJ,CAAC,CAAC"}
1
+ {"version":3,"file":"parsers.js","sourceRoot":"","sources":["../../src/env/parsers.ts"],"names":[],"mappings":";;;AAAO,MAAM,kBAAkB,GAAG,CAAC,KAAa,EAAE,IAAY,EA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,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AADpD,QAAA,OAAO,WAC6C"}
@@ -19,3 +19,9 @@ export declare const oneOf: <T>(choices: readonly T[]) => <U = T>(name: string,
19
19
  export declare const string: <U = string>(name: string, opts?: Readonly<{
20
20
  default: U;
21
21
  }> | undefined) => string | U;
22
+ /**
23
+ * Read an environment variable as a boolean.
24
+ */
25
+ export declare const boolean: <U = boolean>(name: string, opts?: Readonly<{
26
+ default: U;
27
+ }> | undefined) => boolean | U;
@@ -14,12 +14,12 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
14
14
  var __importStar = (this && this.__importStar) || function (mod) {
15
15
  if (mod && mod.__esModule) return mod;
16
16
  var result = {};
17
- if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
18
  __setModuleDefault(result, mod);
19
19
  return result;
20
20
  };
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.string = exports.oneOf = exports.nonNegativeInteger = void 0;
22
+ exports.boolean = exports.string = exports.oneOf = exports.nonNegativeInteger = void 0;
23
23
  const create_1 = require("./create");
24
24
  const parsers = __importStar(require("./parsers"));
25
25
  /**
@@ -27,14 +27,19 @@ const parsers = __importStar(require("./parsers"));
27
27
  *
28
28
  * This includes (positive) zero.
29
29
  */
30
- exports.nonNegativeInteger = create_1.create(parsers.nonNegativeInteger);
30
+ exports.nonNegativeInteger = (0, create_1.create)(parsers.nonNegativeInteger);
31
31
  /**
32
32
  * Create a function that reads an environment variable and validates it against
33
33
  * the provided array of choices.
34
34
  */
35
- exports.oneOf = (choices) => create_1.create(parsers.oneOf(choices));
35
+ const oneOf = (choices) => (0, create_1.create)(parsers.oneOf(choices));
36
+ exports.oneOf = oneOf;
36
37
  /**
37
38
  * Read an environment variable as a string.
38
39
  */
39
- exports.string = create_1.create(parsers.noop);
40
+ exports.string = (0, create_1.create)(parsers.noop);
41
+ /**
42
+ * Read an environment variable as a boolean.
43
+ */
44
+ exports.boolean = (0, create_1.create)(parsers.boolean);
40
45
  //# sourceMappingURL=presets.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"presets.js","sourceRoot":"","sources":["../../src/env/presets.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAkC;AAClC,mDAAqC;AAErC;;;;GAIG;AACU,QAAA,kBAAkB,GAAG,eAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAErE;;;GAGG;AACU,QAAA,KAAK,GAAG,CAAI,OAAqB,EAAE,EAAE,CAChD,eAAM,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;AAEjC;;GAEG;AACU,QAAA,MAAM,GAAG,eAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"}
1
+ {"version":3,"file":"presets.js","sourceRoot":"","sources":["../../src/env/presets.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAkC;AAClC,mDAAqC;AAErC;;;;GAIG;AACU,QAAA,kBAAkB,GAAG,IAAA,eAAM,EAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAErE;;;GAGG;AACI,MAAM,KAAK,GAAG,CAAI,OAAqB,EAAE,EAAE,CAChD,IAAA,eAAM,EAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;AADpB,QAAA,KAAK,SACe;AAEjC;;GAEG;AACU,QAAA,MAAM,GAAG,IAAA,eAAM,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAE3C;;GAEG;AACU,QAAA,OAAO,GAAG,IAAA,eAAM,EAAC,OAAO,CAAC,OAAO,CAAC,CAAC"}
package/lib/index.js CHANGED
@@ -14,11 +14,12 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
14
14
  var __importStar = (this && this.__importStar) || function (mod) {
15
15
  if (mod && mod.__esModule) return mod;
16
16
  var result = {};
17
- if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
18
  __setModuleDefault(result, mod);
19
19
  return result;
20
20
  };
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.Env = exports.Assert = void 0;
22
23
  exports.Assert = __importStar(require("./assert"));
23
24
  exports.Env = __importStar(require("./env"));
24
25
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,mDAAmC;AACnC,6CAA6B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,mDAAmC;AACnC,6CAA6B"}
package/package.json CHANGED
@@ -1,35 +1,48 @@
1
1
  {
2
- "name": "skuba-dive",
2
+ "bugs": {
3
+ "url": "https://github.com/seek-oss/skuba-dive/issues"
4
+ },
5
+ "dependencies": {
6
+ "module-alias": "^2.2.2"
7
+ },
3
8
  "description": "Minimal runtime for skuba",
4
- "version": "1.1.0",
5
- "main": "lib",
6
- "typings": "lib/index.d.ts",
9
+ "devDependencies": {
10
+ "@types/module-alias": "2.0.1",
11
+ "skuba": "3.17.2"
12
+ },
13
+ "engines": {
14
+ "node": ">=14.18"
15
+ },
7
16
  "files": [
8
17
  "lib/**/*.d.ts",
9
18
  "lib/**/*.js",
10
19
  "lib/**/*.js.map",
11
20
  "register.js"
12
21
  ],
13
- "sideEffects": true,
22
+ "homepage": "https://github.com/seek-oss/skuba-dive#readme",
14
23
  "license": "MIT",
24
+ "main": "./lib/index.js",
25
+ "module": "./lib/index.js",
26
+ "name": "skuba-dive",
27
+ "private": false,
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git+https://github.com/seek-oss/skuba-dive.git"
31
+ },
15
32
  "scripts": {
16
33
  "build": "skuba build",
17
34
  "format": "skuba format",
18
35
  "lint": "skuba lint",
19
- "release": "yarn build && semantic-release --success false",
36
+ "release": "yarn build && skuba release",
20
37
  "test": "skuba test --coverage"
21
38
  },
22
- "repository": {
23
- "type": "git",
24
- "url": "https://github.com/seek-oss/skuba-dive.git"
25
- },
26
- "dependencies": {
27
- "module-alias": "^2.2.2",
28
- "source-map-support": "^0.5.16"
39
+ "sideEffects": true,
40
+ "skuba": {
41
+ "entryPoint": "src/index.ts",
42
+ "template": "oss-npm-package",
43
+ "type": "package",
44
+ "version": "3.7.3"
29
45
  },
30
- "devDependencies": {
31
- "@types/module-alias": "2.0.0",
32
- "semantic-release": "17.0.8",
33
- "skuba": "3.5.1"
34
- }
46
+ "types": "./lib/index.d.ts",
47
+ "version": "2.0.0"
35
48
  }
package/register.js CHANGED
@@ -1,11 +1,12 @@
1
- // istanbul ignore if
2
1
  /**
3
- * @see {@link https://github.com/kulshekhar/ts-jest/issues/727#issuecomment-422743605}
2
+ * @see {@link https://nodejs.org/api/deprecations.html#DEP0144}
4
3
  */
5
- if (typeof jest === 'undefined') {
6
- require('source-map-support/register');
7
- }
4
+ const [firstModuleParent] = Object.values(require.cache).filter((m) =>
5
+ m.children.includes(module),
6
+ );
8
7
 
9
- const { addAlias } = require('module-alias');
8
+ if (typeof firstModuleParent !== 'undefined') {
9
+ const { addAlias } = require('module-alias');
10
10
 
11
- addAlias('src', module.parent.path);
11
+ addAlias('src', firstModuleParent.path);
12
+ }