@eik/common 4.0.0-next.4 → 4.0.0-next.7

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 (120) hide show
  1. package/.eslintignore +2 -0
  2. package/.eslintrc +34 -0
  3. package/.github/workflows/publish.yml +69 -0
  4. package/.github/workflows/test.yml +45 -0
  5. package/.prettierignore +17 -0
  6. package/.prettierrc +20 -0
  7. package/CHANGELOG.md +60 -0
  8. package/fixtures/client-with-bare-imports.js +16 -0
  9. package/fixtures/client.js +6 -0
  10. package/fixtures/client.js.map +0 -0
  11. package/fixtures/folder/client.js +6 -0
  12. package/fixtures/folder/styles.css +0 -0
  13. package/fixtures/icons/checkbox-sprite.svg +46 -0
  14. package/fixtures/nested/client.js.map +0 -0
  15. package/fixtures/nested/styles.css.map +0 -0
  16. package/fixtures/styles.css +0 -0
  17. package/fixtures/styles.css.map +0 -0
  18. package/package.json +6 -63
  19. package/packages/config-loader/.prettierignore +17 -0
  20. package/packages/config-loader/index.js +13 -0
  21. package/packages/config-loader/package.json +42 -0
  22. package/{lib → packages/config-loader/src}/classes/file-mapping.js +2 -2
  23. package/{lib → packages/config-loader/src}/classes/local-file-location.js +0 -0
  24. package/{lib → packages/config-loader/src}/classes/read-file.js +2 -1
  25. package/{lib → packages/config-loader/src}/classes/remote-file-location.js +0 -0
  26. package/{lib → packages/config-loader/src}/classes/resolved-files.js +3 -2
  27. package/{lib/helpers → packages/config-loader/src}/config-store.js +4 -4
  28. package/{lib/classes → packages/config-loader/src}/eik-config.js +14 -10
  29. package/{lib/classes → packages/config-loader/src/errors}/custom-error.js +4 -2
  30. package/{lib/classes → packages/config-loader/src/errors}/invalid-config-error.js +4 -2
  31. package/{lib/classes → packages/config-loader/src/errors}/missing-config-error.js +4 -2
  32. package/{lib/classes → packages/config-loader/src/errors}/multiple-config-sources-error.js +4 -2
  33. package/{lib/classes → packages/config-loader/src/errors}/no-files-matched-error.js +5 -3
  34. package/{lib/classes → packages/config-loader/src/errors}/single-dest-multiple-source-error.js +4 -2
  35. package/{lib/helpers → packages/config-loader/src}/get-defaults.js +7 -6
  36. package/{lib/helpers → packages/config-loader/src}/local-assets.js +2 -1
  37. package/{lib/helpers → packages/config-loader/src/utils}/resolve-files.js +3 -2
  38. package/packages/config-loader/test/assets/esm.css +0 -0
  39. package/packages/config-loader/test/assets/esm.css.map +0 -0
  40. package/packages/config-loader/test/assets/esm.js +0 -0
  41. package/packages/config-loader/test/assets/esm.js.map +0 -0
  42. package/packages/config-loader/test/config-store.test.js +231 -0
  43. package/packages/config-loader/test/eik-config/cwd.test.js +35 -0
  44. package/packages/config-loader/test/eik-config/map.test.js +31 -0
  45. package/packages/config-loader/test/eik-config/mappings.test.js +507 -0
  46. package/packages/config-loader/test/eik-config/out.test.js +54 -0
  47. package/packages/config-loader/test/eik-config/server.test.js +32 -0
  48. package/packages/config-loader/test/eik-config/toJSON.test.js +19 -0
  49. package/packages/config-loader/test/eik-config/token.test.js +49 -0
  50. package/packages/config-loader/test/eik-config/type.test.js +22 -0
  51. package/packages/config-loader/test/eik-config/validate.test.js +31 -0
  52. package/packages/config-loader/test/eik-config/version.test.js +22 -0
  53. package/packages/config-loader/test/eik.json +10 -0
  54. package/packages/config-loader/test/local-assets.test.js +125 -0
  55. package/packages/config-loader/test/local-file-location/absolute.test.js +35 -0
  56. package/packages/config-loader/test/local-file-location/contentType.test.js +55 -0
  57. package/packages/config-loader/test/local-file-location/extension.test.js +20 -0
  58. package/packages/config-loader/test/local-file-location/mimeType.test.js +43 -0
  59. package/packages/config-loader/test/read-file.test.js +60 -0
  60. package/packages/config-loader/test/resolve-files.test.js +257 -0
  61. package/packages/config-loader/test/resolved-files/iterator.test.js +17 -0
  62. package/packages/config-loader/test/tmp/.gitkeep +0 -0
  63. package/packages/schemas/.prettierignore +17 -0
  64. package/packages/schemas/eikjson.d.ts +41 -0
  65. package/packages/schemas/index.js +7 -0
  66. package/packages/schemas/package.json +40 -0
  67. package/{lib/schemas → packages/schemas/src}/assert.js +3 -2
  68. package/{lib/schemas → packages/schemas/src}/eikjson.schema.json +0 -0
  69. package/{lib/schemas → packages/schemas/src}/validate.js +12 -8
  70. package/{lib/schemas → packages/schemas/src}/validation-error.js +1 -1
  71. package/packages/schemas/test/assert.js +207 -0
  72. package/packages/schemas/test/index.js +182 -0
  73. package/packages/utils/.prettierignore +17 -0
  74. package/packages/utils/index.js +20 -0
  75. package/packages/utils/package.json +29 -0
  76. package/{lib/helpers → packages/utils/src}/path-slashes.js +0 -0
  77. package/packages/utils/src/stream.js +21 -0
  78. package/{lib/helpers → packages/utils/src}/type-slug.js +0 -0
  79. package/{lib/helpers → packages/utils/src}/type-title.js +0 -0
  80. package/packages/utils/tests/eik.json +10 -0
  81. package/packages/validators/.prettierignore +17 -0
  82. package/packages/validators/package.json +34 -0
  83. package/packages/validators/src/index.js +53 -0
  84. package/packages/validators/test/index.js +238 -0
  85. package/release/eik-common-4.0.0-next.7.tgz +0 -0
  86. package/release.config.js +27 -0
  87. package/renovate.json +6 -0
  88. package/tsconfig.json +30 -0
  89. package/lib/helpers/index.js +0 -25
  90. package/lib/index.js +0 -17
  91. package/lib/schemas/index.js +0 -8
  92. package/lib/stream.js +0 -14
  93. package/lib/validators/index.js +0 -66
  94. package/types/classes/custom-error.d.ts +0 -7
  95. package/types/classes/eik-config.d.ts +0 -57
  96. package/types/classes/file-mapping.d.ts +0 -19
  97. package/types/classes/invalid-config-error.d.ts +0 -13
  98. package/types/classes/local-file-location.d.ts +0 -36
  99. package/types/classes/missing-config-error.d.ts +0 -13
  100. package/types/classes/multiple-config-sources-error.d.ts +0 -9
  101. package/types/classes/no-files-matched-error.d.ts +0 -13
  102. package/types/classes/read-file.d.ts +0 -15
  103. package/types/classes/remote-file-location.d.ts +0 -21
  104. package/types/classes/resolved-files.d.ts +0 -19
  105. package/types/classes/single-dest-multiple-source-error.d.ts +0 -13
  106. package/types/helpers/config-store.d.ts +0 -30
  107. package/types/helpers/get-defaults.d.ts +0 -2
  108. package/types/helpers/index.d.ts +0 -15
  109. package/types/helpers/local-assets.d.ts +0 -8
  110. package/types/helpers/path-slashes.d.ts +0 -32
  111. package/types/helpers/resolve-files.d.ts +0 -12
  112. package/types/helpers/type-slug.d.ts +0 -2
  113. package/types/helpers/type-title.d.ts +0 -2
  114. package/types/index.d.ts +0 -115
  115. package/types/schemas/assert.d.ts +0 -11
  116. package/types/schemas/index.d.ts +0 -79
  117. package/types/schemas/validate.d.ts +0 -26
  118. package/types/schemas/validation-error.d.ts +0 -8
  119. package/types/stream.d.ts +0 -2
  120. package/types/validators/index.d.ts +0 -8
@@ -1,9 +1,11 @@
1
1
  const CustomError = require('./custom-error');
2
2
 
3
- module.exports = class MultipleConfigSourcesError extends CustomError {
3
+ 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');
1
+ const CustomError = require('./custom-error.js');
2
2
 
3
- module.exports = class NoFilesMatchedError extends CustomError {
3
+ class NoFilesMatchedError extends CustomError {
4
4
  /**
5
5
  * @param {string} file
6
6
  */
@@ -8,4 +8,6 @@ module.exports = class NoFilesMatchedError extends CustomError {
8
8
  const message = `No files found for path: '${file}'`;
9
9
  super(message);
10
10
  }
11
- };
11
+ }
12
+
13
+ module.exports = NoFilesMatchedError;
@@ -1,6 +1,6 @@
1
1
  const CustomError = require('./custom-error');
2
2
 
3
- module.exports = class SingleDestMultipleSourcesError extends CustomError {
3
+ class SingleDestMultipleSourcesError extends CustomError {
4
4
  /**
5
5
  * @param {string} destFilePath
6
6
  */
@@ -9,4 +9,6 @@ module.exports = class SingleDestMultipleSourcesError extends CustomError {
9
9
  `Cannot specify a single file destination for multiple source files. See '${destFilePath}'`,
10
10
  );
11
11
  }
12
- };
12
+ }
13
+
14
+ module.exports = SingleDestMultipleSourcesError;
@@ -1,18 +1,17 @@
1
1
  // @ts-check
2
2
 
3
- 'use strict';
3
+ const EikConfig = require('./eik-config.js');
4
+ const configStore = require('./config-store.js');
4
5
 
5
- const configStore = require('./config-store');
6
- const EikConfig = require('../classes/eik-config');
7
6
  /**
8
7
  * Sets up and returns an object containing a set of default values for the app context.
9
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.
10
9
  *
11
10
  * @param {string} cwd The current working directory
12
11
  *
13
- * @returns {import("../classes/eik-config")} EikConfig
12
+ * @returns {import("./eik-config.js")} EikConfig
14
13
  */
15
- module.exports = function getDefaults(cwd) {
14
+ function getDefaults(cwd) {
16
15
  try {
17
16
  return configStore.findInDirectory(cwd);
18
17
  } catch (e) {
@@ -21,4 +20,6 @@ module.exports = function getDefaults(cwd) {
21
20
  }
22
21
  throw e;
23
22
  }
24
- };
23
+ }
24
+
25
+ module.exports = getDefaults;
@@ -5,7 +5,7 @@
5
5
  */
6
6
  const assert = require('assert');
7
7
  const fs = require('fs');
8
- const configStore = require('./config-store');
8
+ const configStore = require('./config-store.js');
9
9
 
10
10
  /**
11
11
  * Sets up asset routes for local development. Mounted paths match those on Eik server and values are read from projects eik.json file.
@@ -57,4 +57,5 @@ async function localAssets(app, rootEikDirectory = process.cwd()) {
57
57
  }
58
58
  });
59
59
  }
60
+
60
61
  module.exports = localAssets;
@@ -4,12 +4,13 @@ const { promisify } = require('util');
4
4
  const { extname, join, isAbsolute, basename, sep, normalize } = require('path');
5
5
  const isGlob = require('is-glob');
6
6
  const glob = promisify(require('glob'));
7
+ // const { ResolvedFiles } = require('../index.js');
7
8
  const {
8
9
  removeTrailingSlash,
9
10
  addLeadingSlash,
10
11
  removeLeadingSlash,
11
- } = require('./path-slashes');
12
- const ResolvedFiles = require('../classes/resolved-files');
12
+ } = require('@eik/common-utils');
13
+ const ResolvedFiles = require('../classes/resolved-files.js');
13
14
 
14
15
  /**
15
16
  * Create a new path from a path string preceeding a glob or the whole path if no glob is found
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,231 @@
1
+ const { test } = require('tap');
2
+ const fs = require('fs').promises;
3
+ const { join } = require('path');
4
+ const os = require('os');
5
+
6
+ const EikConfig = require('../src/eik-config.js');
7
+ const configStore = require('../src/config-store.js');
8
+
9
+ function mkdirTempDir() {
10
+ return fs.mkdtemp(join(os.tmpdir(), 'eik-config'));
11
+ }
12
+
13
+ const mockEikJSON = (data) => ({
14
+ name: 'magarita',
15
+ server: 'http://server',
16
+ files: { '/': 'pizza' },
17
+ version: '0.0.0',
18
+ ...data,
19
+ });
20
+
21
+ const mockPackageJSON = ({
22
+ name = 'magarita',
23
+ version = '0.0.0',
24
+ other = {},
25
+ eik = {},
26
+ }) => ({
27
+ name,
28
+ version,
29
+ ...other,
30
+ eik: {
31
+ server: 'http://server',
32
+ files: { '/': 'pizza' },
33
+ ...eik,
34
+ },
35
+ });
36
+
37
+ test('loads from package.json', (t) => {
38
+ const config = configStore.findInDirectory('/pizza dir', (path) => {
39
+ if (path.includes('eik.json') || path.includes('.eikrc')) return null;
40
+ t.match(path, '/pizza dir/package.json');
41
+ return mockPackageJSON({
42
+ other: { notIncluded: 'fish' },
43
+ eik: { 'import-map': 'http://map' },
44
+ });
45
+ });
46
+ t.equal(config.name, 'magarita');
47
+ t.equal(config.version, '0.0.0');
48
+ t.equal(config.notIncluded, undefined);
49
+ t.same(config.map, ['http://map']);
50
+ t.end();
51
+ });
52
+
53
+ test('loads from eik.json', (t) => {
54
+ const config = configStore.findInDirectory('/pizza dir', (path) => {
55
+ if (path.includes('package.json') || path.includes('.eikrc'))
56
+ return null;
57
+ t.match(path, '/pizza dir/eik.json');
58
+ return mockEikJSON();
59
+ });
60
+ t.equal(config.name, 'magarita');
61
+ t.end();
62
+ });
63
+
64
+ test('loads from eik.json - invalid config', (t) => {
65
+ try {
66
+ configStore.findInDirectory('/pizza dir', (path) => {
67
+ if (path.includes('package.json') || path.includes('.eikrc'))
68
+ return null;
69
+ return {};
70
+ });
71
+ } catch (err) {
72
+ t.match(
73
+ `${err}`,
74
+ `InvalidConfigError: Eik config object was invalid: 'config.findInDirectory operation failed: Invalid eik.json schema: must have required property 'server'`,
75
+ );
76
+ }
77
+ t.end();
78
+ });
79
+
80
+ test('package.json and eik.json not being present', (t) => {
81
+ t.plan(1);
82
+ try {
83
+ configStore.findInDirectory('/pizza dir', () => null);
84
+ } catch (e) {
85
+ t.equal(
86
+ e.message,
87
+ "No package.json or eik.json file found in: '/pizza dir'",
88
+ );
89
+ }
90
+ t.end();
91
+ });
92
+
93
+ test('package.json and eik.json both have eik config', (t) => {
94
+ t.plan(1);
95
+ const jsonReaderStub = (path) => {
96
+ if (path.includes('package.json'))
97
+ return { eik: { pizza: 'magarita' } };
98
+ return {};
99
+ };
100
+ try {
101
+ configStore.findInDirectory('/pizza dir', jsonReaderStub);
102
+ } catch (e) {
103
+ t.equal(
104
+ e.message,
105
+ 'Eik configuration was defined in both in package.json and eik.json. You must specify one or the other.',
106
+ );
107
+ }
108
+
109
+ t.end();
110
+ });
111
+
112
+ test('name is pulled from package.json if not defined in eik.json', (t) => {
113
+ const jsonReaderStub = (path) => {
114
+ if (path.includes('package.json'))
115
+ return {
116
+ name: 'big pizza co',
117
+ version: '0.0.0',
118
+ eik: {
119
+ server: 'https://test',
120
+ files: {
121
+ '/': './dist/**/*.js',
122
+ },
123
+ },
124
+ };
125
+ if (path.includes('eik.json')) return null;
126
+ return {};
127
+ };
128
+ const config = configStore.findInDirectory('/pizza dir', jsonReaderStub);
129
+ t.equal(config.name, 'big pizza co');
130
+ t.equal(config.version, '0.0.0');
131
+ t.equal(config.server, 'https://test');
132
+ t.same(config.files, {
133
+ '/': './dist/**/*.js',
134
+ });
135
+ t.end();
136
+ });
137
+
138
+ test('tokens are present', (t) => {
139
+ const config = configStore.findInDirectory('/pizza dir', (path) => {
140
+ if (path.includes('eik.json')) return mockEikJSON();
141
+ if (path.includes('.eikrc'))
142
+ return { tokens: [['http://server', 'muffins']] };
143
+ return {};
144
+ });
145
+ t.equal(config.server, 'http://server');
146
+ t.equal(config.token, 'muffins');
147
+ t.end();
148
+ });
149
+
150
+ test('invalid json error', (t) => {
151
+ t.plan(1);
152
+ const jsonReaderStub = (path) => {
153
+ if (path.includes('.json')) JSON.parse('not json');
154
+ return {};
155
+ };
156
+
157
+ try {
158
+ configStore.findInDirectory('/pizza dir', jsonReaderStub);
159
+ } catch (e) {
160
+ t.equal(e.message, 'Unexpected token o in JSON at position 1');
161
+ }
162
+ t.end();
163
+ });
164
+
165
+ test('no configuration present', (t) => {
166
+ t.plan(1);
167
+ try {
168
+ configStore.findInDirectory('/pizza dir', () => {});
169
+ } catch (e) {
170
+ t.equal(
171
+ e.message,
172
+ "No package.json or eik.json file found in: '/pizza dir'",
173
+ );
174
+ }
175
+ t.end();
176
+ });
177
+
178
+ test('reading without stubbed json', (t) => {
179
+ const config = configStore.findInDirectory(__dirname);
180
+ t.equal(config.name, 'my-app');
181
+ t.end();
182
+ });
183
+
184
+ test('saves config to disk', async (t) => {
185
+ const path = await mkdirTempDir();
186
+ const config = new EikConfig(
187
+ {
188
+ name: 'magarita',
189
+ server: 'http://server',
190
+ files: { '/': 'pizza' },
191
+ version: '0.0.0',
192
+ out: './biscuits',
193
+ },
194
+ null,
195
+ path,
196
+ );
197
+
198
+ configStore.persistToDisk(config);
199
+
200
+ const persistedConfig = configStore.findInDirectory(path);
201
+ t.equal(persistedConfig.out, 'biscuits');
202
+ t.end();
203
+ });
204
+
205
+ test('saves config to disk - invalid config - passed config not a instance of EikConfig', async (t) => {
206
+ const config = {};
207
+ try {
208
+ configStore.persistToDisk(config);
209
+ } catch (err) {
210
+ t.match(
211
+ `${err}`,
212
+ `InvalidConfigError: Eik config object was invalid: 'config.persistToDisk operation failed: config.validate is not a function'`,
213
+ );
214
+ }
215
+
216
+ t.end();
217
+ });
218
+
219
+ test('saves config to disk - invalid config', async (t) => {
220
+ const config = new EikConfig(null);
221
+ try {
222
+ configStore.persistToDisk(config);
223
+ } catch (err) {
224
+ t.match(
225
+ `${err}`,
226
+ `InvalidConfigError: Eik config object was invalid: 'config.persistToDisk operation failed: Invalid eik.json schema: must have required property 'server'`,
227
+ );
228
+ }
229
+
230
+ t.end();
231
+ });
@@ -0,0 +1,35 @@
1
+ const { test } = require('tap');
2
+ const EikConfig = require('../../src/eik-config.js');
3
+
4
+ const validEikConfig = {
5
+ name: 'pizza',
6
+ server: 'http://server',
7
+ files: { '/': 'pizza' },
8
+ version: '0.0.0',
9
+ };
10
+
11
+ test('EikConfig: .cwd set to /some/path', (t) => {
12
+ const config = new EikConfig(validEikConfig, [], '/some/path');
13
+ t.equal(config.cwd, '/some/path', 'should equal the given cwd');
14
+ t.end();
15
+ });
16
+
17
+ test('EikConfig: .cwd set to /some/path/', (t) => {
18
+ const config = new EikConfig(validEikConfig, [], '/some/path/');
19
+ t.equal(config.cwd, '/some/path', 'should normalize the given cwd');
20
+ t.end();
21
+ });
22
+
23
+ test('EikConfig: .cwd set to invalid relative path some/path', (t) => {
24
+ try {
25
+ // eslint-disable-next-line no-new
26
+ new EikConfig(validEikConfig, [], 'some/path');
27
+ } catch (err) {
28
+ t.match(
29
+ err.message,
30
+ '"configRootDir" must be an absolute path:',
31
+ 'should throw expected error with message',
32
+ );
33
+ }
34
+ t.end();
35
+ });
@@ -0,0 +1,31 @@
1
+ const { test } = require('tap');
2
+ const EikConfig = require('../../src/eik-config.js');
3
+
4
+ const validEikConfig = {
5
+ name: 'pizza',
6
+ server: 'http://server',
7
+ files: { '/': 'pizza' },
8
+ version: '0.0.0',
9
+ };
10
+
11
+ test('EikConfig: .map: set to string http://map', (t) => {
12
+ const config = new EikConfig({
13
+ ...validEikConfig,
14
+ 'import-map': 'http://map',
15
+ });
16
+ t.same(config.map, ['http://map'], 'should be wrapped into an array');
17
+ t.end();
18
+ });
19
+
20
+ test('EikConfig: .map: set to an array with two values', (t) => {
21
+ const config = new EikConfig({
22
+ ...validEikConfig,
23
+ 'import-map': ['http://map', 'http://map'],
24
+ });
25
+ t.same(
26
+ config.map,
27
+ ['http://map', 'http://map'],
28
+ 'should remain the same as input',
29
+ );
30
+ t.end();
31
+ });