@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.
- package/CHANGELOG.md +108 -3
- 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.6.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
|
@@ -1,231 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,35 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,31 +0,0 @@
|
|
|
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
|
-
});
|