@eik/common 4.0.0-next.7 → 4.0.1
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 +110 -5
- package/README.md +9 -5
- package/eikjson.d.ts +1 -1
- package/{packages/config-loader/src/errors → lib/classes}/custom-error.js +1 -3
- package/{packages/config-loader/src → lib/classes}/eik-config.js +19 -17
- package/{packages/config-loader/src → lib}/classes/file-mapping.js +4 -6
- package/{packages/config-loader/src/errors → lib/classes}/invalid-config-error.js +2 -4
- package/{packages/config-loader/src → lib}/classes/local-file-location.js +5 -4
- package/{packages/config-loader/src/errors → lib/classes}/missing-config-error.js +2 -4
- package/{packages/config-loader/src/errors → lib/classes}/multiple-config-sources-error.js +2 -4
- package/{packages/config-loader/src/errors → lib/classes}/no-files-matched-error.js +2 -4
- package/{packages/config-loader/src → lib}/classes/read-file.js +4 -3
- package/{packages/config-loader/src → lib}/classes/remote-file-location.js +3 -3
- package/{packages/config-loader/src → lib}/classes/resolved-files.js +5 -6
- package/{packages/config-loader/src/errors → lib/classes}/single-dest-multiple-source-error.js +2 -4
- package/{packages/config-loader/src → lib/helpers}/config-store.js +39 -8
- package/lib/helpers/get-defaults.js +38 -0
- package/lib/helpers/index.js +25 -0
- package/{packages/config-loader/src → lib/helpers}/local-assets.js +9 -7
- package/{packages/utils/src → lib/helpers}/path-slashes.js +1 -1
- package/{packages/config-loader/src/utils → lib/helpers}/resolve-files.js +7 -11
- package/{packages/utils/src → lib/helpers}/type-slug.js +4 -1
- package/{packages/utils/src → lib/helpers}/type-title.js +4 -1
- package/lib/index.js +16 -0
- package/{packages/schemas/src → lib/schemas}/assert.js +6 -6
- package/lib/schemas/index.js +15 -0
- package/{packages/schemas/src → lib/schemas}/validate.js +18 -17
- package/{packages/schemas/src → lib/schemas}/validation-error.js +2 -2
- package/lib/stream.js +12 -0
- package/lib/validators/index.js +65 -0
- package/package.json +63 -6
- package/types/classes/custom-error.d.ts +6 -0
- package/types/classes/eik-config.d.ts +63 -0
- package/types/classes/file-mapping.d.ts +21 -0
- package/types/classes/invalid-config-error.d.ts +3 -0
- package/types/classes/local-file-location.d.ts +36 -0
- package/types/classes/missing-config-error.d.ts +3 -0
- package/types/classes/multiple-config-sources-error.d.ts +4 -0
- package/types/classes/no-files-matched-error.d.ts +3 -0
- package/types/classes/read-file.d.ts +15 -0
- package/types/classes/remote-file-location.d.ts +21 -0
- package/types/classes/resolved-files.d.ts +20 -0
- package/types/classes/single-dest-multiple-source-error.d.ts +3 -0
- package/types/helpers/config-store.d.ts +28 -0
- package/types/helpers/get-defaults.d.ts +9 -0
- package/types/helpers/index.d.ts +23 -0
- package/types/helpers/local-assets.d.ts +8 -0
- package/types/helpers/path-slashes.d.ts +32 -0
- package/types/helpers/resolve-files.d.ts +13 -0
- package/types/helpers/type-slug.d.ts +2 -0
- package/types/helpers/type-title.d.ts +2 -0
- package/types/index.d.ts +16 -0
- package/types/schemas/assert.d.ts +11 -0
- package/types/schemas/index.d.ts +11 -0
- package/types/schemas/validate.d.ts +26 -0
- package/types/schemas/validation-error.d.ts +8 -0
- package/types/stream.d.ts +2 -0
- package/types/validators/index.d.ts +8 -0
- package/.eslintignore +0 -2
- package/.eslintrc +0 -34
- package/.github/workflows/publish.yml +0 -69
- package/.github/workflows/test.yml +0 -45
- package/.prettierignore +0 -17
- package/.prettierrc +0 -20
- package/fixtures/client-with-bare-imports.js +0 -16
- package/fixtures/client.js +0 -6
- package/fixtures/client.js.map +0 -0
- package/fixtures/folder/client.js +0 -6
- package/fixtures/folder/styles.css +0 -0
- package/fixtures/icons/checkbox-sprite.svg +0 -46
- package/fixtures/nested/client.js.map +0 -0
- package/fixtures/nested/styles.css.map +0 -0
- package/fixtures/styles.css +0 -0
- package/fixtures/styles.css.map +0 -0
- package/packages/config-loader/.prettierignore +0 -17
- package/packages/config-loader/index.js +0 -13
- package/packages/config-loader/package.json +0 -42
- package/packages/config-loader/src/get-defaults.js +0 -25
- package/packages/config-loader/test/assets/esm.css +0 -0
- package/packages/config-loader/test/assets/esm.css.map +0 -0
- package/packages/config-loader/test/assets/esm.js +0 -0
- package/packages/config-loader/test/assets/esm.js.map +0 -0
- package/packages/config-loader/test/config-store.test.js +0 -231
- package/packages/config-loader/test/eik-config/cwd.test.js +0 -35
- package/packages/config-loader/test/eik-config/map.test.js +0 -31
- package/packages/config-loader/test/eik-config/mappings.test.js +0 -507
- package/packages/config-loader/test/eik-config/out.test.js +0 -54
- package/packages/config-loader/test/eik-config/server.test.js +0 -32
- package/packages/config-loader/test/eik-config/toJSON.test.js +0 -19
- package/packages/config-loader/test/eik-config/token.test.js +0 -49
- package/packages/config-loader/test/eik-config/type.test.js +0 -22
- package/packages/config-loader/test/eik-config/validate.test.js +0 -31
- package/packages/config-loader/test/eik-config/version.test.js +0 -22
- package/packages/config-loader/test/eik.json +0 -10
- package/packages/config-loader/test/local-assets.test.js +0 -125
- package/packages/config-loader/test/local-file-location/absolute.test.js +0 -35
- package/packages/config-loader/test/local-file-location/contentType.test.js +0 -55
- package/packages/config-loader/test/local-file-location/extension.test.js +0 -20
- package/packages/config-loader/test/local-file-location/mimeType.test.js +0 -43
- package/packages/config-loader/test/read-file.test.js +0 -60
- package/packages/config-loader/test/resolve-files.test.js +0 -257
- package/packages/config-loader/test/resolved-files/iterator.test.js +0 -17
- package/packages/config-loader/test/tmp/.gitkeep +0 -0
- package/packages/schemas/.prettierignore +0 -17
- package/packages/schemas/eikjson.d.ts +0 -41
- package/packages/schemas/index.js +0 -7
- package/packages/schemas/package.json +0 -40
- package/packages/schemas/test/assert.js +0 -207
- package/packages/schemas/test/index.js +0 -182
- package/packages/utils/.prettierignore +0 -17
- package/packages/utils/index.js +0 -20
- package/packages/utils/package.json +0 -29
- package/packages/utils/src/stream.js +0 -21
- package/packages/utils/tests/eik.json +0 -10
- package/packages/validators/.prettierignore +0 -17
- package/packages/validators/package.json +0 -34
- package/packages/validators/src/index.js +0 -53
- package/packages/validators/test/index.js +0 -238
- package/release/eik-common-4.0.0-next.7.tgz +0 -0
- package/release.config.js +0 -27
- package/renovate.json +0 -6
- package/tsconfig.json +0 -30
- /package/{packages/schemas/src → lib/schemas}/eikjson.schema.json +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,18 +1,123 @@
|
|
|
1
|
-
|
|
1
|
+
## [4.0.1](https://github.com/eik-lib/common/compare/v4.0.0...v4.0.1) (2024-08-06)
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
### Bug Fixes
|
|
5
5
|
|
|
6
|
-
*
|
|
6
|
+
* use correct method name for loading config file from path ([9d01ca4](https://github.com/eik-lib/common/commit/9d01ca46574ee5a9f153835f8778640a9b20625b))
|
|
7
7
|
|
|
8
|
-
# [4.0.0
|
|
8
|
+
# [4.0.0](https://github.com/eik-lib/common/compare/v3.0.1...v4.0.0) (2024-08-06)
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
### Bug Fixes
|
|
12
12
|
|
|
13
|
-
*
|
|
13
|
+
* update ajv-formats ([131dbf2](https://github.com/eik-lib/common/commit/131dbf25fcf8e2d128ac9e660076b538c441fa55))
|
|
14
|
+
* update glob to 9.0.0 ([ee132ce](https://github.com/eik-lib/common/commit/ee132ceb256244df74839dc9495c57c1e2b36af2))
|
|
15
|
+
* update glog to 11.0.0 ([ae24324](https://github.com/eik-lib/common/commit/ae2432458bd8c3ec95f7ca59d6d86ed87e1686d2))
|
|
16
|
+
* update validate-npm-package-name ([00c57e7](https://github.com/eik-lib/common/commit/00c57e7a2c6f0c2666493ebb1a6eae446582037f))
|
|
14
17
|
|
|
15
|
-
|
|
18
|
+
|
|
19
|
+
### chore
|
|
20
|
+
|
|
21
|
+
* convert codebase to ESM ([1a83a26](https://github.com/eik-lib/common/commit/1a83a261d2cc2ce2c921eaf50c843d0e8989d662))
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### Features
|
|
25
|
+
|
|
26
|
+
* add load exact method ([709c8e3](https://github.com/eik-lib/common/commit/709c8e350d6f9a24c5d41981cca27b8183bf3268))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### BREAKING CHANGES
|
|
30
|
+
|
|
31
|
+
* Codebase is now ESM only, Common JS is no longer supported.
|
|
32
|
+
|
|
33
|
+
# [4.0.0-next.5](https://github.com/eik-lib/common/compare/v4.0.0-next.4...v4.0.0-next.5) (2024-08-06)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
### Bug Fixes
|
|
37
|
+
|
|
38
|
+
* **deps:** update dependency glob to v8 ([#225](https://github.com/eik-lib/common/issues/225)) ([fd01a56](https://github.com/eik-lib/common/commit/fd01a566b404164bdc847cc7a1803b124e131e41))
|
|
39
|
+
* **deps:** update dependency validate-npm-package-name to v4 ([#222](https://github.com/eik-lib/common/issues/222)) ([c3721ab](https://github.com/eik-lib/common/commit/c3721abf058c93d4e500945c3c014c748c1f2acd))
|
|
40
|
+
* update ajv-formats ([131dbf2](https://github.com/eik-lib/common/commit/131dbf25fcf8e2d128ac9e660076b538c441fa55))
|
|
41
|
+
* update glob to 9.0.0 ([ee132ce](https://github.com/eik-lib/common/commit/ee132ceb256244df74839dc9495c57c1e2b36af2))
|
|
42
|
+
* update glog to 11.0.0 ([ae24324](https://github.com/eik-lib/common/commit/ae2432458bd8c3ec95f7ca59d6d86ed87e1686d2))
|
|
43
|
+
* update validate-npm-package-name ([00c57e7](https://github.com/eik-lib/common/commit/00c57e7a2c6f0c2666493ebb1a6eae446582037f))
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
### chore
|
|
47
|
+
|
|
48
|
+
* convert codebase to ESM ([1a83a26](https://github.com/eik-lib/common/commit/1a83a261d2cc2ce2c921eaf50c843d0e8989d662))
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
### Features
|
|
52
|
+
|
|
53
|
+
* add load exact method ([709c8e3](https://github.com/eik-lib/common/commit/709c8e350d6f9a24c5d41981cca27b8183bf3268))
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
### BREAKING CHANGES
|
|
57
|
+
|
|
58
|
+
* Codebase is now ESM only, Common JS is no longer supported.
|
|
59
|
+
|
|
60
|
+
# [4.0.0-next.5](https://github.com/eik-lib/common/compare/v4.0.0-next.4...v4.0.0-next.5) (2024-08-04)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
### Bug Fixes
|
|
64
|
+
|
|
65
|
+
* **deps:** update dependency glob to v8 ([#225](https://github.com/eik-lib/common/issues/225)) ([fd01a56](https://github.com/eik-lib/common/commit/fd01a566b404164bdc847cc7a1803b124e131e41))
|
|
66
|
+
* **deps:** update dependency validate-npm-package-name to v4 ([#222](https://github.com/eik-lib/common/issues/222)) ([c3721ab](https://github.com/eik-lib/common/commit/c3721abf058c93d4e500945c3c014c748c1f2acd))
|
|
67
|
+
* update ajv-formats ([131dbf2](https://github.com/eik-lib/common/commit/131dbf25fcf8e2d128ac9e660076b538c441fa55))
|
|
68
|
+
* update glob to 9.0.0 ([ee132ce](https://github.com/eik-lib/common/commit/ee132ceb256244df74839dc9495c57c1e2b36af2))
|
|
69
|
+
* update glog to 11.0.0 ([ae24324](https://github.com/eik-lib/common/commit/ae2432458bd8c3ec95f7ca59d6d86ed87e1686d2))
|
|
70
|
+
* update validate-npm-package-name ([00c57e7](https://github.com/eik-lib/common/commit/00c57e7a2c6f0c2666493ebb1a6eae446582037f))
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
### chore
|
|
74
|
+
|
|
75
|
+
* convert codebase to ESM ([1a83a26](https://github.com/eik-lib/common/commit/1a83a261d2cc2ce2c921eaf50c843d0e8989d662))
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
### BREAKING CHANGES
|
|
79
|
+
|
|
80
|
+
* Codebase is now ESM only, Common JS is no longer supported.
|
|
81
|
+
|
|
82
|
+
# [4.0.0-next.5](https://github.com/eik-lib/common/compare/v4.0.0-next.4...v4.0.0-next.5) (2024-08-01)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
### Bug Fixes
|
|
86
|
+
|
|
87
|
+
* **deps:** update dependency glob to v8 ([#225](https://github.com/eik-lib/common/issues/225)) ([fd01a56](https://github.com/eik-lib/common/commit/fd01a566b404164bdc847cc7a1803b124e131e41))
|
|
88
|
+
* **deps:** update dependency validate-npm-package-name to v4 ([#222](https://github.com/eik-lib/common/issues/222)) ([c3721ab](https://github.com/eik-lib/common/commit/c3721abf058c93d4e500945c3c014c748c1f2acd))
|
|
89
|
+
* update ajv-formats ([131dbf2](https://github.com/eik-lib/common/commit/131dbf25fcf8e2d128ac9e660076b538c441fa55))
|
|
90
|
+
* update validate-npm-package-name ([00c57e7](https://github.com/eik-lib/common/commit/00c57e7a2c6f0c2666493ebb1a6eae446582037f))
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
### chore
|
|
94
|
+
|
|
95
|
+
* convert codebase to ESM ([1a83a26](https://github.com/eik-lib/common/commit/1a83a261d2cc2ce2c921eaf50c843d0e8989d662))
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
### BREAKING CHANGES
|
|
99
|
+
|
|
100
|
+
* Codebase is now ESM only, Common JS is no longer supported.
|
|
101
|
+
|
|
102
|
+
# [4.0.0-next.5](https://github.com/eik-lib/common/compare/v4.0.0-next.4...v4.0.0-next.5) (2024-07-31)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
### Bug Fixes
|
|
106
|
+
|
|
107
|
+
* **deps:** update dependency glob to v8 ([#225](https://github.com/eik-lib/common/issues/225)) ([fd01a56](https://github.com/eik-lib/common/commit/fd01a566b404164bdc847cc7a1803b124e131e41))
|
|
108
|
+
* **deps:** update dependency validate-npm-package-name to v4 ([#222](https://github.com/eik-lib/common/issues/222)) ([c3721ab](https://github.com/eik-lib/common/commit/c3721abf058c93d4e500945c3c014c748c1f2acd))
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
### chore
|
|
112
|
+
|
|
113
|
+
* convert codebase to ESM ([1a83a26](https://github.com/eik-lib/common/commit/1a83a261d2cc2ce2c921eaf50c843d0e8989d662))
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
### BREAKING CHANGES
|
|
117
|
+
|
|
118
|
+
* Codebase is now ESM only, Common JS is no longer supported.
|
|
119
|
+
|
|
120
|
+
# [4.0.0-next.5](https://github.com/eik-lib/common/compare/v4.0.0-next.4...v4.0.0-next.5) (2024-07-31)
|
|
16
121
|
|
|
17
122
|
|
|
18
123
|
### Bug Fixes
|
package/README.md
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
# Eik
|
|
1
|
+
# Eik Common
|
|
2
2
|
|
|
3
3
|
This package contains common utilities and schemas
|
|
4
4
|
|
|
5
|
+
## ESM ONLY
|
|
6
|
+
|
|
7
|
+
From v4, this module is ESM only and cannot be used with Common JS.
|
|
8
|
+
|
|
5
9
|
## APIs
|
|
6
10
|
|
|
7
11
|
### schemas
|
|
@@ -11,7 +15,7 @@ This package contains common utilities and schemas
|
|
|
11
15
|
Importing schemas
|
|
12
16
|
|
|
13
17
|
```js
|
|
14
|
-
|
|
18
|
+
import { schemas, assert } from '@eik/common';
|
|
15
19
|
```
|
|
16
20
|
|
|
17
21
|
Validating an `eik.json` file
|
|
@@ -127,8 +131,8 @@ assert.out('./.eik');
|
|
|
127
131
|
A function to help development by mounting development routes to an Express.js or Fastify app based on values defined in `eik.json`
|
|
128
132
|
|
|
129
133
|
```js
|
|
130
|
-
|
|
131
|
-
|
|
134
|
+
import express from 'express';
|
|
135
|
+
import { helpers } from '@eik/common';
|
|
132
136
|
const app = express();
|
|
133
137
|
await helpers.localAssets(app);
|
|
134
138
|
```
|
|
@@ -179,7 +183,7 @@ Given the following `eik.json` file:
|
|
|
179
183
|
and the following call to packageURL
|
|
180
184
|
|
|
181
185
|
```js
|
|
182
|
-
|
|
186
|
+
import { helpers } from '@eik/common';
|
|
183
187
|
const url = await helpers.packageURL('esm.js');
|
|
184
188
|
```
|
|
185
189
|
|
package/eikjson.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class CustomError extends Error {
|
|
1
|
+
export default class CustomError extends Error {
|
|
2
2
|
/**
|
|
3
3
|
* @param {string} message
|
|
4
4
|
*/
|
|
@@ -8,5 +8,3 @@ class CustomError extends Error {
|
|
|
8
8
|
Error.captureStackTrace(this, this.constructor);
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
module.exports = CustomError;
|
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
/* eslint-disable no-continue */
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* @type {(value: unknown, message?: string) => asserts value}
|
|
5
3
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const SingleDestMultipleSourcesError = require('./errors/single-dest-multiple-source-error.js');
|
|
17
|
-
const NoFilesMatchedError = require('./errors/no-files-matched-error.js');
|
|
4
|
+
import assert from 'node:assert';
|
|
5
|
+
import { extname, join, isAbsolute } from 'node:path';
|
|
6
|
+
import NoFilesMatchedError from './no-files-matched-error.js';
|
|
7
|
+
import SingleDestMultipleSourcesError from './single-dest-multiple-source-error.js';
|
|
8
|
+
import FileMapping from './file-mapping.js';
|
|
9
|
+
import RemoteFileLocation from './remote-file-location.js';
|
|
10
|
+
import schemas from '../schemas/index.js';
|
|
11
|
+
import { removeTrailingSlash } from '../helpers/path-slashes.js';
|
|
12
|
+
import typeSlug from '../helpers/type-slug.js';
|
|
13
|
+
import resolveFiles from '../helpers/resolve-files.js';
|
|
18
14
|
|
|
19
15
|
const _config = Symbol('config');
|
|
20
16
|
const _tokens = Symbol('tokens');
|
|
@@ -33,7 +29,7 @@ const normalizeFilesDefinition = (files) =>
|
|
|
33
29
|
* @typedef {import ("../../eikjson").EikjsonSchema} EikjsonSchema
|
|
34
30
|
*/
|
|
35
31
|
|
|
36
|
-
class EikConfig {
|
|
32
|
+
export default class EikConfig {
|
|
37
33
|
/**
|
|
38
34
|
* @param {EikjsonSchema?} configHash
|
|
39
35
|
* @param {[string, string][]?} tokens
|
|
@@ -45,11 +41,14 @@ class EikConfig {
|
|
|
45
41
|
this[_tokens] = new Map(tokens);
|
|
46
42
|
|
|
47
43
|
assert(
|
|
44
|
+
// @ts-ignore
|
|
48
45
|
isAbsolute(configRootDir),
|
|
49
46
|
`"configRootDir" must be an absolute path: "${configRootDir}" given`,
|
|
50
47
|
);
|
|
48
|
+
// @ts-ignore
|
|
51
49
|
this.cwd = removeTrailingSlash(configRootDir);
|
|
52
50
|
/** @type {string[]} */
|
|
51
|
+
// @ts-ignore
|
|
53
52
|
this.map = [].concat(this[_config]['import-map'] || []);
|
|
54
53
|
}
|
|
55
54
|
|
|
@@ -70,6 +69,7 @@ class EikConfig {
|
|
|
70
69
|
|
|
71
70
|
/** @type {EikjsonSchema["type"]} */
|
|
72
71
|
get type() {
|
|
72
|
+
// @ts-ignore
|
|
73
73
|
return this[_config].type || schemas.schema.properties.type.default;
|
|
74
74
|
}
|
|
75
75
|
|
|
@@ -84,6 +84,7 @@ class EikConfig {
|
|
|
84
84
|
|
|
85
85
|
/** @type {[string, string][]} */
|
|
86
86
|
get token() {
|
|
87
|
+
// @ts-ignore
|
|
87
88
|
return this[_tokens].get(this.server);
|
|
88
89
|
}
|
|
89
90
|
|
|
@@ -135,7 +136,9 @@ class EikConfig {
|
|
|
135
136
|
const resolvedFiles = await resolveFiles(normalizedFiles, this.cwd);
|
|
136
137
|
|
|
137
138
|
return resolvedFiles.flatMap((files) => {
|
|
139
|
+
// @ts-ignore
|
|
138
140
|
const { destination, source } = files;
|
|
141
|
+
// @ts-ignore
|
|
139
142
|
const filesArray = Array.from(files);
|
|
140
143
|
if (filesArray.length === 0) {
|
|
141
144
|
throw new NoFilesMatchedError(source);
|
|
@@ -151,6 +154,7 @@ class EikConfig {
|
|
|
151
154
|
? destination
|
|
152
155
|
: join(destination, localFile.relative);
|
|
153
156
|
const packagePathname = join(
|
|
157
|
+
// @ts-ignore
|
|
154
158
|
typeSlug(this.type),
|
|
155
159
|
this.name,
|
|
156
160
|
this.version,
|
|
@@ -165,5 +169,3 @@ class EikConfig {
|
|
|
165
169
|
});
|
|
166
170
|
}
|
|
167
171
|
}
|
|
168
|
-
|
|
169
|
-
module.exports = EikConfig;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
/* eslint-disable no-unused-vars */
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* @type {(value: unknown, message?: string) => asserts value}
|
|
5
3
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
import assert from 'node:assert';
|
|
5
|
+
import LocalFileLocation from './local-file-location.js';
|
|
6
|
+
import RemoteFileLocation from './remote-file-location.js';
|
|
9
7
|
|
|
10
8
|
/**
|
|
11
9
|
* Class containing a local file system source location and remote server destination location for a file.
|
|
@@ -37,4 +35,4 @@ class FileMapping {
|
|
|
37
35
|
}
|
|
38
36
|
}
|
|
39
37
|
|
|
40
|
-
|
|
38
|
+
export default FileMapping;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import CustomError from './custom-error.js';
|
|
2
2
|
|
|
3
|
-
class InvalidConfigError extends CustomError {
|
|
3
|
+
export default class InvalidConfigError extends CustomError {
|
|
4
4
|
/**
|
|
5
5
|
* @param {string} msg
|
|
6
6
|
*/
|
|
@@ -8,5 +8,3 @@ class InvalidConfigError extends CustomError {
|
|
|
8
8
|
super(`Eik config object was invalid: '${msg}'`);
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
module.exports = InvalidConfigError;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @type {(value: unknown, message?: string) => asserts value}
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import assert from 'node:assert';
|
|
5
|
+
import { join, extname, isAbsolute } from 'node:path';
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
import mime from 'mime-types';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Class containing information about a local file
|
|
@@ -56,4 +57,4 @@ class LocalFileLocation {
|
|
|
56
57
|
}
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
|
|
60
|
+
export default LocalFileLocation;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import CustomError from './custom-error.js';
|
|
2
2
|
|
|
3
|
-
class MissingConfigError extends CustomError {
|
|
3
|
+
export default class MissingConfigError extends CustomError {
|
|
4
4
|
/**
|
|
5
5
|
* @param {string} dir
|
|
6
6
|
*/
|
|
@@ -8,5 +8,3 @@ class MissingConfigError extends CustomError {
|
|
|
8
8
|
super(`No package.json or eik.json file found in: '${dir}'`);
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
module.exports = MissingConfigError;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import CustomError from './custom-error.js';
|
|
2
2
|
|
|
3
|
-
class MultipleConfigSourcesError extends CustomError {
|
|
3
|
+
export default class MultipleConfigSourcesError extends CustomError {
|
|
4
4
|
constructor() {
|
|
5
5
|
super(
|
|
6
6
|
`Eik configuration was defined in both in package.json and eik.json. You must specify one or the other.`,
|
|
7
7
|
);
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
module.exports = MultipleConfigSourcesError;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import CustomError from './custom-error.js';
|
|
2
2
|
|
|
3
|
-
class NoFilesMatchedError extends CustomError {
|
|
3
|
+
export default class NoFilesMatchedError extends CustomError {
|
|
4
4
|
/**
|
|
5
5
|
* @param {string} file
|
|
6
6
|
*/
|
|
@@ -9,5 +9,3 @@ class NoFilesMatchedError extends CustomError {
|
|
|
9
9
|
super(message);
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
module.exports = NoFilesMatchedError;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { isReadableStream } from '../stream.js';
|
|
2
2
|
|
|
3
3
|
const ReadFile = class ReadFile {
|
|
4
4
|
constructor({ mimeType = '', etag = '' } = {}) {
|
|
5
5
|
this._mimeType = mimeType;
|
|
6
|
+
// @ts-ignore
|
|
6
7
|
this._stream = undefined;
|
|
7
8
|
this._etag = etag;
|
|
8
9
|
}
|
|
@@ -17,6 +18,7 @@ const ReadFile = class ReadFile {
|
|
|
17
18
|
this._stream = value;
|
|
18
19
|
}
|
|
19
20
|
|
|
21
|
+
// @ts-ignore
|
|
20
22
|
get stream() {
|
|
21
23
|
return this._stream;
|
|
22
24
|
}
|
|
@@ -29,5 +31,4 @@ const ReadFile = class ReadFile {
|
|
|
29
31
|
return 'ReadFile';
|
|
30
32
|
}
|
|
31
33
|
};
|
|
32
|
-
|
|
33
|
-
module.exports = ReadFile;
|
|
34
|
+
export default ReadFile;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @type {(value: unknown, message?: string) => asserts value}
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import assert from 'node:assert';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
6
|
|
|
7
7
|
class RemoteFileLocation {
|
|
8
8
|
/**
|
|
@@ -38,4 +38,4 @@ class RemoteFileLocation {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
export default RemoteFileLocation;
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @type {(value: unknown, message?: string) => asserts value}
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import assert from 'node:assert';
|
|
5
|
+
import LocalFileLocation from './local-file-location.js';
|
|
6
|
+
import {
|
|
6
7
|
removeLeadingSlash,
|
|
7
8
|
removeTrailingSlash,
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const LocalFileLocation = require('./local-file-location');
|
|
9
|
+
} from '../helpers/path-slashes.js';
|
|
11
10
|
|
|
12
11
|
const originalFiles = Symbol('files');
|
|
13
12
|
|
|
@@ -54,4 +53,4 @@ class ResolvedFiles {
|
|
|
54
53
|
}
|
|
55
54
|
}
|
|
56
55
|
|
|
57
|
-
|
|
56
|
+
export default ResolvedFiles;
|
package/{packages/config-loader/src/errors → lib/classes}/single-dest-multiple-source-error.js
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import CustomError from './custom-error.js';
|
|
2
2
|
|
|
3
|
-
class SingleDestMultipleSourcesError extends CustomError {
|
|
3
|
+
export default class SingleDestMultipleSourcesError extends CustomError {
|
|
4
4
|
/**
|
|
5
5
|
* @param {string} destFilePath
|
|
6
6
|
*/
|
|
@@ -10,5 +10,3 @@ class SingleDestMultipleSourcesError extends CustomError {
|
|
|
10
10
|
);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
module.exports = SingleDestMultipleSourcesError;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { join, dirname } from 'node:path';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import EikConfig from '../classes/eik-config.js';
|
|
5
|
+
import MissingConfigError from '../classes/missing-config-error.js';
|
|
6
|
+
import MultipleConfigSourcesError from '../classes/multiple-config-sources-error.js';
|
|
7
|
+
import InvalidConfigError from '../classes/invalid-config-error.js';
|
|
4
8
|
|
|
5
|
-
const
|
|
6
|
-
const MissingConfigError = require('./errors/missing-config-error.js');
|
|
7
|
-
const MultipleConfigSourcesError = require('./errors/multiple-config-sources-error.js');
|
|
8
|
-
const InvalidConfigError = require('./errors/invalid-config-error.js');
|
|
9
|
+
const homedir = os.homedir();
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Read a file at a given path and parse it
|
|
@@ -19,12 +20,38 @@ function readJSONFromDisk(path) {
|
|
|
19
20
|
try {
|
|
20
21
|
fileData = readFileSync(path, { encoding: 'utf8' });
|
|
21
22
|
} catch (e) {
|
|
23
|
+
// @ts-ignore
|
|
22
24
|
return null;
|
|
23
25
|
}
|
|
24
26
|
return JSON.parse(fileData);
|
|
25
27
|
}
|
|
26
28
|
|
|
27
|
-
|
|
29
|
+
export default {
|
|
30
|
+
/**
|
|
31
|
+
* Load the configuration from an exact path and return an EikConfig object
|
|
32
|
+
*
|
|
33
|
+
* @param {string} configFilePathname
|
|
34
|
+
* @param {function} loadJSONFromDisk
|
|
35
|
+
*
|
|
36
|
+
* @returns {EikConfig}
|
|
37
|
+
*/
|
|
38
|
+
loadFromPath(configFilePathname, loadJSONFromDisk = readJSONFromDisk) {
|
|
39
|
+
const eikJSON = loadJSONFromDisk(configFilePathname);
|
|
40
|
+
if (!eikJSON) {
|
|
41
|
+
throw new MissingConfigError(dirname(configFilePathname));
|
|
42
|
+
}
|
|
43
|
+
let assets = eikJSON;
|
|
44
|
+
// detect package.json
|
|
45
|
+
if (eikJSON.eik) {
|
|
46
|
+
assets = {
|
|
47
|
+
name: eikJSON.name,
|
|
48
|
+
version: eikJSON.version,
|
|
49
|
+
...eikJSON.eik,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const eikrc = loadJSONFromDisk(join(homedir, '.eikrc')) || {};
|
|
53
|
+
return new EikConfig(assets, eikrc.tokens, dirname(configFilePathname));
|
|
54
|
+
},
|
|
28
55
|
/**
|
|
29
56
|
* Tries to find the configuration for eik in the provided directory.
|
|
30
57
|
*
|
|
@@ -62,6 +89,7 @@ module.exports = {
|
|
|
62
89
|
config.validate();
|
|
63
90
|
} catch (err) {
|
|
64
91
|
throw new InvalidConfigError(
|
|
92
|
+
// @ts-ignore
|
|
65
93
|
`config.findInDirectory operation failed: ${err.message}`,
|
|
66
94
|
);
|
|
67
95
|
}
|
|
@@ -75,12 +103,15 @@ module.exports = {
|
|
|
75
103
|
*/
|
|
76
104
|
persistToDisk(config) {
|
|
77
105
|
try {
|
|
106
|
+
// @ts-ignore
|
|
78
107
|
config.validate();
|
|
79
108
|
} catch (err) {
|
|
80
109
|
throw new InvalidConfigError(
|
|
110
|
+
// @ts-ignore
|
|
81
111
|
`config.persistToDisk operation failed: ${err.message}`,
|
|
82
112
|
);
|
|
83
113
|
}
|
|
114
|
+
// @ts-ignore
|
|
84
115
|
const dest = join(config.cwd, 'eik.json');
|
|
85
116
|
writeFileSync(dest, JSON.stringify(config, null, 2));
|
|
86
117
|
},
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import configStore from './config-store.js';
|
|
5
|
+
import EikConfig from '../classes/eik-config.js';
|
|
6
|
+
/**
|
|
7
|
+
* Sets up and returns an object containing a set of default values for the app context.
|
|
8
|
+
* Default values are fetched from the app's eik.json or package.json file as well as from .eikrc, if present in the users home directory.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} directoryOrFilepath The directory to search for eik.json or package.json or an exact path to an eik.json or package.json file
|
|
11
|
+
*
|
|
12
|
+
* @returns {import("../classes/eik-config")} EikConfig
|
|
13
|
+
*/
|
|
14
|
+
export default function getDefaults(directoryOrFilepath) {
|
|
15
|
+
try {
|
|
16
|
+
const stats = fs.statSync(directoryOrFilepath);
|
|
17
|
+
if (stats.isDirectory()) {
|
|
18
|
+
// @ts-expect-error
|
|
19
|
+
return configStore.findInDirectory(directoryOrFilepath);
|
|
20
|
+
} else {
|
|
21
|
+
// @ts-expect-error
|
|
22
|
+
return configStore.loadFromPath(directoryOrFilepath);
|
|
23
|
+
}
|
|
24
|
+
} catch (error) {
|
|
25
|
+
const e = /** @type {Error} */ (error);
|
|
26
|
+
if (e.constructor.name === 'MissingConfigError') {
|
|
27
|
+
// assume directory
|
|
28
|
+
let cwd = directoryOrFilepath;
|
|
29
|
+
// detect exact file and get its directory
|
|
30
|
+
if (path.extname(directoryOrFilepath)) {
|
|
31
|
+
cwd = path.dirname(directoryOrFilepath);
|
|
32
|
+
}
|
|
33
|
+
// @ts-expect-error
|
|
34
|
+
return new EikConfig(null, [], cwd);
|
|
35
|
+
}
|
|
36
|
+
throw e;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import localAssets from './local-assets.js';
|
|
2
|
+
import getDefaults from './get-defaults.js';
|
|
3
|
+
import configStore from './config-store.js';
|
|
4
|
+
import typeSlug from './type-slug.js';
|
|
5
|
+
import typeTitle from './type-title.js';
|
|
6
|
+
import resolveFiles from './resolve-files.js';
|
|
7
|
+
import {
|
|
8
|
+
addTrailingSlash,
|
|
9
|
+
removeTrailingSlash,
|
|
10
|
+
addLeadingSlash,
|
|
11
|
+
removeLeadingSlash,
|
|
12
|
+
} from './path-slashes.js';
|
|
13
|
+
|
|
14
|
+
export default {
|
|
15
|
+
localAssets,
|
|
16
|
+
getDefaults,
|
|
17
|
+
configStore,
|
|
18
|
+
typeSlug,
|
|
19
|
+
typeTitle,
|
|
20
|
+
addTrailingSlash,
|
|
21
|
+
removeTrailingSlash,
|
|
22
|
+
addLeadingSlash,
|
|
23
|
+
removeLeadingSlash,
|
|
24
|
+
resolveFiles,
|
|
25
|
+
};
|