@eik/common 4.0.0-next.6 → 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.
Files changed (123) hide show
  1. package/CHANGELOG.md +108 -3
  2. package/README.md +9 -5
  3. package/eikjson.d.ts +1 -1
  4. package/{packages/config-loader/src/errors → lib/classes}/custom-error.js +1 -3
  5. package/{packages/config-loader/src → lib/classes}/eik-config.js +19 -17
  6. package/{packages/config-loader/src → lib}/classes/file-mapping.js +4 -6
  7. package/{packages/config-loader/src/errors → lib/classes}/invalid-config-error.js +2 -4
  8. package/{packages/config-loader/src → lib}/classes/local-file-location.js +5 -4
  9. package/{packages/config-loader/src/errors → lib/classes}/missing-config-error.js +2 -4
  10. package/{packages/config-loader/src/errors → lib/classes}/multiple-config-sources-error.js +2 -4
  11. package/{packages/config-loader/src/errors → lib/classes}/no-files-matched-error.js +2 -4
  12. package/{packages/config-loader/src → lib}/classes/read-file.js +4 -3
  13. package/{packages/config-loader/src → lib}/classes/remote-file-location.js +3 -3
  14. package/{packages/config-loader/src → lib}/classes/resolved-files.js +5 -6
  15. package/{packages/config-loader/src/errors → lib/classes}/single-dest-multiple-source-error.js +2 -4
  16. package/{packages/config-loader/src → lib/helpers}/config-store.js +39 -8
  17. package/lib/helpers/get-defaults.js +38 -0
  18. package/lib/helpers/index.js +25 -0
  19. package/{packages/config-loader/src → lib/helpers}/local-assets.js +9 -7
  20. package/{packages/utils/src → lib/helpers}/path-slashes.js +1 -1
  21. package/{packages/config-loader/src/utils → lib/helpers}/resolve-files.js +7 -11
  22. package/{packages/utils/src → lib/helpers}/type-slug.js +4 -1
  23. package/{packages/utils/src → lib/helpers}/type-title.js +4 -1
  24. package/lib/index.js +16 -0
  25. package/{packages/schemas/src → lib/schemas}/assert.js +6 -6
  26. package/lib/schemas/index.js +15 -0
  27. package/{packages/schemas/src → lib/schemas}/validate.js +18 -17
  28. package/{packages/schemas/src → lib/schemas}/validation-error.js +2 -2
  29. package/lib/stream.js +12 -0
  30. package/lib/validators/index.js +65 -0
  31. package/package.json +63 -6
  32. package/types/classes/custom-error.d.ts +6 -0
  33. package/types/classes/eik-config.d.ts +63 -0
  34. package/types/classes/file-mapping.d.ts +21 -0
  35. package/types/classes/invalid-config-error.d.ts +3 -0
  36. package/types/classes/local-file-location.d.ts +36 -0
  37. package/types/classes/missing-config-error.d.ts +3 -0
  38. package/types/classes/multiple-config-sources-error.d.ts +4 -0
  39. package/types/classes/no-files-matched-error.d.ts +3 -0
  40. package/types/classes/read-file.d.ts +15 -0
  41. package/types/classes/remote-file-location.d.ts +21 -0
  42. package/types/classes/resolved-files.d.ts +20 -0
  43. package/types/classes/single-dest-multiple-source-error.d.ts +3 -0
  44. package/types/helpers/config-store.d.ts +28 -0
  45. package/types/helpers/get-defaults.d.ts +9 -0
  46. package/types/helpers/index.d.ts +23 -0
  47. package/types/helpers/local-assets.d.ts +8 -0
  48. package/types/helpers/path-slashes.d.ts +32 -0
  49. package/types/helpers/resolve-files.d.ts +13 -0
  50. package/types/helpers/type-slug.d.ts +2 -0
  51. package/types/helpers/type-title.d.ts +2 -0
  52. package/types/index.d.ts +16 -0
  53. package/types/schemas/assert.d.ts +11 -0
  54. package/types/schemas/index.d.ts +11 -0
  55. package/types/schemas/validate.d.ts +26 -0
  56. package/types/schemas/validation-error.d.ts +8 -0
  57. package/types/stream.d.ts +2 -0
  58. package/types/validators/index.d.ts +8 -0
  59. package/.eslintignore +0 -2
  60. package/.eslintrc +0 -34
  61. package/.github/workflows/publish.yml +0 -69
  62. package/.github/workflows/test.yml +0 -45
  63. package/.prettierignore +0 -17
  64. package/.prettierrc +0 -20
  65. package/fixtures/client-with-bare-imports.js +0 -16
  66. package/fixtures/client.js +0 -6
  67. package/fixtures/client.js.map +0 -0
  68. package/fixtures/folder/client.js +0 -6
  69. package/fixtures/folder/styles.css +0 -0
  70. package/fixtures/icons/checkbox-sprite.svg +0 -46
  71. package/fixtures/nested/client.js.map +0 -0
  72. package/fixtures/nested/styles.css.map +0 -0
  73. package/fixtures/styles.css +0 -0
  74. package/fixtures/styles.css.map +0 -0
  75. package/packages/config-loader/.prettierignore +0 -17
  76. package/packages/config-loader/index.js +0 -13
  77. package/packages/config-loader/package.json +0 -42
  78. package/packages/config-loader/src/get-defaults.js +0 -25
  79. package/packages/config-loader/test/assets/esm.css +0 -0
  80. package/packages/config-loader/test/assets/esm.css.map +0 -0
  81. package/packages/config-loader/test/assets/esm.js +0 -0
  82. package/packages/config-loader/test/assets/esm.js.map +0 -0
  83. package/packages/config-loader/test/config-store.test.js +0 -231
  84. package/packages/config-loader/test/eik-config/cwd.test.js +0 -35
  85. package/packages/config-loader/test/eik-config/map.test.js +0 -31
  86. package/packages/config-loader/test/eik-config/mappings.test.js +0 -507
  87. package/packages/config-loader/test/eik-config/out.test.js +0 -54
  88. package/packages/config-loader/test/eik-config/server.test.js +0 -32
  89. package/packages/config-loader/test/eik-config/toJSON.test.js +0 -19
  90. package/packages/config-loader/test/eik-config/token.test.js +0 -49
  91. package/packages/config-loader/test/eik-config/type.test.js +0 -22
  92. package/packages/config-loader/test/eik-config/validate.test.js +0 -31
  93. package/packages/config-loader/test/eik-config/version.test.js +0 -22
  94. package/packages/config-loader/test/eik.json +0 -10
  95. package/packages/config-loader/test/local-assets.test.js +0 -125
  96. package/packages/config-loader/test/local-file-location/absolute.test.js +0 -35
  97. package/packages/config-loader/test/local-file-location/contentType.test.js +0 -55
  98. package/packages/config-loader/test/local-file-location/extension.test.js +0 -20
  99. package/packages/config-loader/test/local-file-location/mimeType.test.js +0 -43
  100. package/packages/config-loader/test/read-file.test.js +0 -60
  101. package/packages/config-loader/test/resolve-files.test.js +0 -257
  102. package/packages/config-loader/test/resolved-files/iterator.test.js +0 -17
  103. package/packages/config-loader/test/tmp/.gitkeep +0 -0
  104. package/packages/schemas/.prettierignore +0 -17
  105. package/packages/schemas/eikjson.d.ts +0 -41
  106. package/packages/schemas/index.js +0 -7
  107. package/packages/schemas/package.json +0 -40
  108. package/packages/schemas/test/assert.js +0 -207
  109. package/packages/schemas/test/index.js +0 -182
  110. package/packages/utils/.prettierignore +0 -17
  111. package/packages/utils/index.js +0 -20
  112. package/packages/utils/package.json +0 -29
  113. package/packages/utils/src/stream.js +0 -21
  114. package/packages/utils/tests/eik.json +0 -10
  115. package/packages/validators/.prettierignore +0 -17
  116. package/packages/validators/package.json +0 -34
  117. package/packages/validators/src/index.js +0 -53
  118. package/packages/validators/test/index.js +0 -238
  119. package/release/eik-common-4.0.0-next.6.tgz +0 -0
  120. package/release.config.js +0 -27
  121. package/renovate.json +0 -6
  122. package/tsconfig.json +0 -30
  123. /package/{packages/schemas/src → lib/schemas}/eikjson.schema.json +0 -0
package/CHANGELOG.md CHANGED
@@ -1,11 +1,116 @@
1
- # [4.0.0-next.6](https://github.com/eik-lib/common/compare/v4.0.0-next.5...v4.0.0-next.6) (2022-07-26)
1
+ # [4.0.0](https://github.com/eik-lib/common/compare/v3.0.1...v4.0.0) (2024-08-06)
2
2
 
3
3
 
4
4
  ### Bug Fixes
5
5
 
6
- * lint ([edc595f](https://github.com/eik-lib/common/commit/edc595f6f4baf465e736bed8a4cb2e0eb8efe382))
6
+ * update ajv-formats ([131dbf2](https://github.com/eik-lib/common/commit/131dbf25fcf8e2d128ac9e660076b538c441fa55))
7
+ * update glob to 9.0.0 ([ee132ce](https://github.com/eik-lib/common/commit/ee132ceb256244df74839dc9495c57c1e2b36af2))
8
+ * update glog to 11.0.0 ([ae24324](https://github.com/eik-lib/common/commit/ae2432458bd8c3ec95f7ca59d6d86ed87e1686d2))
9
+ * update validate-npm-package-name ([00c57e7](https://github.com/eik-lib/common/commit/00c57e7a2c6f0c2666493ebb1a6eae446582037f))
7
10
 
8
- # [4.0.0-next.5](https://github.com/eik-lib/common/compare/v4.0.0-next.4...v4.0.0-next.5) (2022-07-26)
11
+
12
+ ### chore
13
+
14
+ * convert codebase to ESM ([1a83a26](https://github.com/eik-lib/common/commit/1a83a261d2cc2ce2c921eaf50c843d0e8989d662))
15
+
16
+
17
+ ### Features
18
+
19
+ * add load exact method ([709c8e3](https://github.com/eik-lib/common/commit/709c8e350d6f9a24c5d41981cca27b8183bf3268))
20
+
21
+
22
+ ### BREAKING CHANGES
23
+
24
+ * Codebase is now ESM only, Common JS is no longer supported.
25
+
26
+ # [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)
27
+
28
+
29
+ ### Bug Fixes
30
+
31
+ * **deps:** update dependency glob to v8 ([#225](https://github.com/eik-lib/common/issues/225)) ([fd01a56](https://github.com/eik-lib/common/commit/fd01a566b404164bdc847cc7a1803b124e131e41))
32
+ * **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))
33
+ * update ajv-formats ([131dbf2](https://github.com/eik-lib/common/commit/131dbf25fcf8e2d128ac9e660076b538c441fa55))
34
+ * update glob to 9.0.0 ([ee132ce](https://github.com/eik-lib/common/commit/ee132ceb256244df74839dc9495c57c1e2b36af2))
35
+ * update glog to 11.0.0 ([ae24324](https://github.com/eik-lib/common/commit/ae2432458bd8c3ec95f7ca59d6d86ed87e1686d2))
36
+ * update validate-npm-package-name ([00c57e7](https://github.com/eik-lib/common/commit/00c57e7a2c6f0c2666493ebb1a6eae446582037f))
37
+
38
+
39
+ ### chore
40
+
41
+ * convert codebase to ESM ([1a83a26](https://github.com/eik-lib/common/commit/1a83a261d2cc2ce2c921eaf50c843d0e8989d662))
42
+
43
+
44
+ ### Features
45
+
46
+ * add load exact method ([709c8e3](https://github.com/eik-lib/common/commit/709c8e350d6f9a24c5d41981cca27b8183bf3268))
47
+
48
+
49
+ ### BREAKING CHANGES
50
+
51
+ * Codebase is now ESM only, Common JS is no longer supported.
52
+
53
+ # [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)
54
+
55
+
56
+ ### Bug Fixes
57
+
58
+ * **deps:** update dependency glob to v8 ([#225](https://github.com/eik-lib/common/issues/225)) ([fd01a56](https://github.com/eik-lib/common/commit/fd01a566b404164bdc847cc7a1803b124e131e41))
59
+ * **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))
60
+ * update ajv-formats ([131dbf2](https://github.com/eik-lib/common/commit/131dbf25fcf8e2d128ac9e660076b538c441fa55))
61
+ * update glob to 9.0.0 ([ee132ce](https://github.com/eik-lib/common/commit/ee132ceb256244df74839dc9495c57c1e2b36af2))
62
+ * update glog to 11.0.0 ([ae24324](https://github.com/eik-lib/common/commit/ae2432458bd8c3ec95f7ca59d6d86ed87e1686d2))
63
+ * update validate-npm-package-name ([00c57e7](https://github.com/eik-lib/common/commit/00c57e7a2c6f0c2666493ebb1a6eae446582037f))
64
+
65
+
66
+ ### chore
67
+
68
+ * convert codebase to ESM ([1a83a26](https://github.com/eik-lib/common/commit/1a83a261d2cc2ce2c921eaf50c843d0e8989d662))
69
+
70
+
71
+ ### BREAKING CHANGES
72
+
73
+ * Codebase is now ESM only, Common JS is no longer supported.
74
+
75
+ # [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)
76
+
77
+
78
+ ### Bug Fixes
79
+
80
+ * **deps:** update dependency glob to v8 ([#225](https://github.com/eik-lib/common/issues/225)) ([fd01a56](https://github.com/eik-lib/common/commit/fd01a566b404164bdc847cc7a1803b124e131e41))
81
+ * **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))
82
+ * update ajv-formats ([131dbf2](https://github.com/eik-lib/common/commit/131dbf25fcf8e2d128ac9e660076b538c441fa55))
83
+ * update validate-npm-package-name ([00c57e7](https://github.com/eik-lib/common/commit/00c57e7a2c6f0c2666493ebb1a6eae446582037f))
84
+
85
+
86
+ ### chore
87
+
88
+ * convert codebase to ESM ([1a83a26](https://github.com/eik-lib/common/commit/1a83a261d2cc2ce2c921eaf50c843d0e8989d662))
89
+
90
+
91
+ ### BREAKING CHANGES
92
+
93
+ * Codebase is now ESM only, Common JS is no longer supported.
94
+
95
+ # [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)
96
+
97
+
98
+ ### Bug Fixes
99
+
100
+ * **deps:** update dependency glob to v8 ([#225](https://github.com/eik-lib/common/issues/225)) ([fd01a56](https://github.com/eik-lib/common/commit/fd01a566b404164bdc847cc7a1803b124e131e41))
101
+ * **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))
102
+
103
+
104
+ ### chore
105
+
106
+ * convert codebase to ESM ([1a83a26](https://github.com/eik-lib/common/commit/1a83a261d2cc2ce2c921eaf50c843d0e8989d662))
107
+
108
+
109
+ ### BREAKING CHANGES
110
+
111
+ * Codebase is now ESM only, Common JS is no longer supported.
112
+
113
+ # [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)
9
114
 
10
115
 
11
116
  ### Bug Fixes
package/README.md CHANGED
@@ -1,7 +1,11 @@
1
- # Eik Commons
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
- const { schemas, assert } = require('@eik/common');
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
- const express = require('express');
131
- const { helpers } = require('@eik/common');
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
- const { helpers } = require('@eik/common');
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
- /* tslint:disable */
1
+ /* eslint-disable */
2
2
  /**
3
3
  * This file was automatically generated by json-schema-to-typescript.
4
4
  * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
@@ -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
- const assert = require('assert');
7
- const { extname, join, isAbsolute } = require('path');
8
- const { typeSlug, removeTrailingSlash } = require('@eik/common-utils');
9
-
10
- const schemas = require('@eik/common-schemas');
11
-
12
- const resolveFiles = require('./utils/resolve-files.js');
13
-
14
- const RemoteFileLocation = require('./classes/remote-file-location.js');
15
- const FileMapping = require('./classes/file-mapping.js');
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
- const assert = require('assert');
7
- const LocalFileLocation = require('./local-file-location.js');
8
- const RemoteFileLocation = require('./remote-file-location.js');
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
- module.exports = FileMapping;
38
+ export default FileMapping;
@@ -1,6 +1,6 @@
1
- const CustomError = require('./custom-error');
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
- const assert = require('assert');
5
- const { join, extname, isAbsolute } = require('path');
6
- const mime = require('mime-types');
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
- module.exports = LocalFileLocation;
60
+ export default LocalFileLocation;
@@ -1,6 +1,6 @@
1
- const CustomError = require('./custom-error');
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
- const CustomError = require('./custom-error');
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
- const CustomError = require('./custom-error.js');
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
- const { isReadableStream } = require('@eik/common-utils');
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
- const assert = require('assert');
5
- const { join } = require('path');
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
- module.exports = RemoteFileLocation;
41
+ export default RemoteFileLocation;
@@ -1,13 +1,12 @@
1
1
  /**
2
2
  * @type {(value: unknown, message?: string) => asserts value}
3
3
  */
4
- const assert = require('assert');
5
- const {
4
+ import assert from 'node:assert';
5
+ import LocalFileLocation from './local-file-location.js';
6
+ import {
6
7
  removeLeadingSlash,
7
8
  removeTrailingSlash,
8
- } = require('@eik/common-utils');
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
- module.exports = ResolvedFiles;
56
+ export default ResolvedFiles;
@@ -1,6 +1,6 @@
1
- const CustomError = require('./custom-error');
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
- const { readFileSync, writeFileSync } = require('fs');
2
- const { join } = require('path');
3
- const homedir = require('os').homedir();
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 EikConfig = require('./eik-config.js');
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
- module.exports = {
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.loadExact(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
+ };
@@ -1,11 +1,9 @@
1
- /* eslint-disable no-await-in-loop */
2
-
3
1
  /**
4
2
  * @type {(value: unknown, message?: string) => asserts value}
5
3
  */
6
- const assert = require('assert');
7
- const fs = require('fs');
8
- const configStore = require('./config-store.js');
4
+ import assert from 'node:assert';
5
+ import fs from 'node:fs';
6
+ import configStore from './config-store.js';
9
7
 
10
8
  /**
11
9
  * Sets up asset routes for local development. Mounted paths match those on Eik server and values are read from projects eik.json file.
@@ -15,6 +13,7 @@ const configStore = require('./config-store.js');
15
13
  */
16
14
  async function localAssets(app, rootEikDirectory = process.cwd()) {
17
15
  assert(
16
+ // @ts-ignore
18
17
  app.decorateReply || app.name === 'app' || app.route,
19
18
  'App must be an Express, Fastify or Hapi app instance',
20
19
  );
@@ -28,7 +27,9 @@ async function localAssets(app, rootEikDirectory = process.cwd()) {
28
27
  (await eik.mappings()).forEach((mapping) => {
29
28
  const { pathname } = mapping.destination.url;
30
29
  const { contentType, absolute: path } = mapping.source;
30
+ // @ts-ignore
31
31
  if (app.get) {
32
+ // @ts-ignore
32
33
  app.get(pathname, (req, res) => {
33
34
  if (res.set) {
34
35
  // express
@@ -44,9 +45,11 @@ async function localAssets(app, rootEikDirectory = process.cwd()) {
44
45
  });
45
46
  } else {
46
47
  // hapi
48
+ // @ts-ignore
47
49
  app.route({
48
50
  method: 'GET',
49
51
  path: pathname,
52
+ // @ts-ignore
50
53
  handler(req, h) {
51
54
  return h
52
55
  .response(fs.createReadStream(path))
@@ -57,5 +60,4 @@ async function localAssets(app, rootEikDirectory = process.cwd()) {
57
60
  }
58
61
  });
59
62
  }
60
-
61
- module.exports = localAssets;
63
+ export default localAssets;