@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
|
@@ -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: .validate(): no config given', (t) => {
|
|
12
|
-
t.plan(1);
|
|
13
|
-
try {
|
|
14
|
-
const config = new EikConfig(null);
|
|
15
|
-
config.validate();
|
|
16
|
-
} catch (err) {
|
|
17
|
-
t.match(
|
|
18
|
-
err.message,
|
|
19
|
-
'Invalid eik.json schema',
|
|
20
|
-
'should throw for invalid config',
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
t.end();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test('EikConfig: .validate(): no config given', (t) => {
|
|
27
|
-
const config = new EikConfig(validEikConfig);
|
|
28
|
-
config.validate();
|
|
29
|
-
t.ok(true, 'should not throw when valid config is given');
|
|
30
|
-
t.end();
|
|
31
|
-
});
|
|
@@ -1,22 +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: .version: accessing the property', (t) => {
|
|
12
|
-
const config = new EikConfig(validEikConfig);
|
|
13
|
-
t.equal(config.version, '0.0.0', 'should return the given value');
|
|
14
|
-
t.end();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
test('EikConfig: .version: setting the property value', (t) => {
|
|
18
|
-
const config = new EikConfig(validEikConfig);
|
|
19
|
-
config.version = '1.0.1';
|
|
20
|
-
t.equal(config.version, '1.0.1', 'should return the given value');
|
|
21
|
-
t.end();
|
|
22
|
-
});
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
const express = require('express');
|
|
2
|
-
const fastify = require('fastify');
|
|
3
|
-
const Hapi = require('@hapi/hapi');
|
|
4
|
-
const { test } = require('tap');
|
|
5
|
-
const fetch = require('node-fetch');
|
|
6
|
-
const stoppable = require('stoppable');
|
|
7
|
-
const localAssets = require('../src/local-assets.js');
|
|
8
|
-
|
|
9
|
-
class Server {
|
|
10
|
-
constructor() {
|
|
11
|
-
this.app = express();
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
start() {
|
|
15
|
-
return new Promise((resolve, reject) => {
|
|
16
|
-
try {
|
|
17
|
-
this.server = this.app.listen(0, () => {
|
|
18
|
-
this.port = this.server.address().port;
|
|
19
|
-
resolve();
|
|
20
|
-
});
|
|
21
|
-
stoppable(this.server);
|
|
22
|
-
} catch (err) {
|
|
23
|
-
reject(err);
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
stop() {
|
|
29
|
-
return new Promise((resolve, reject) => {
|
|
30
|
-
try {
|
|
31
|
-
this.server.stop(resolve);
|
|
32
|
-
} catch (err) {
|
|
33
|
-
reject(err);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
test('Setup development routes for express', async (t) => {
|
|
40
|
-
const server = new Server();
|
|
41
|
-
await localAssets(server.app, __dirname);
|
|
42
|
-
await server.start();
|
|
43
|
-
|
|
44
|
-
const res1 = await fetch(
|
|
45
|
-
new URL('/pkg/my-app/1.0.0/esm.js', `http://localhost:${server.port}`),
|
|
46
|
-
);
|
|
47
|
-
const res2 = await fetch(
|
|
48
|
-
new URL('/pkg/my-app/1.0.0/esm.css', `http://localhost:${server.port}`),
|
|
49
|
-
);
|
|
50
|
-
const res3 = await fetch(
|
|
51
|
-
new URL(
|
|
52
|
-
'/pkg/my-app/1.0.0/assets/esm.css.map',
|
|
53
|
-
`http://localhost:${server.port}`,
|
|
54
|
-
),
|
|
55
|
-
);
|
|
56
|
-
const res4 = await fetch(
|
|
57
|
-
new URL(
|
|
58
|
-
'/pkg/my-app/1.0.0/assets/esm.js.map',
|
|
59
|
-
`http://localhost:${server.port}`,
|
|
60
|
-
),
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
t.equal(res1.status, 200);
|
|
64
|
-
t.equal(res2.status, 200);
|
|
65
|
-
t.equal(res3.status, 200);
|
|
66
|
-
t.equal(res4.status, 200);
|
|
67
|
-
await server.stop();
|
|
68
|
-
t.end();
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test('Setup development routes for fastify', async (t) => {
|
|
72
|
-
const server = fastify();
|
|
73
|
-
await localAssets(server, __dirname);
|
|
74
|
-
const address = await server.listen();
|
|
75
|
-
|
|
76
|
-
const res1 = await fetch(new URL('/pkg/my-app/1.0.0/esm.js', address));
|
|
77
|
-
const res2 = await fetch(new URL('/pkg/my-app/1.0.0/esm.css', address));
|
|
78
|
-
const res3 = await fetch(
|
|
79
|
-
new URL('/pkg/my-app/1.0.0/assets/esm.css.map', address),
|
|
80
|
-
);
|
|
81
|
-
const res4 = await fetch(
|
|
82
|
-
new URL('/pkg/my-app/1.0.0/assets/esm.js.map', address),
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
t.equal(res1.status, 200);
|
|
86
|
-
t.equal(res2.status, 200);
|
|
87
|
-
t.equal(res3.status, 200);
|
|
88
|
-
t.equal(res4.status, 200);
|
|
89
|
-
await server.close();
|
|
90
|
-
t.end();
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
test('Setup development routes for hapi', async (t) => {
|
|
94
|
-
const server = new Hapi.Server();
|
|
95
|
-
await localAssets(server, __dirname);
|
|
96
|
-
await server.start();
|
|
97
|
-
const address = server.info.uri;
|
|
98
|
-
|
|
99
|
-
const res1 = await fetch(new URL('/pkg/my-app/1.0.0/esm.js', address));
|
|
100
|
-
const res2 = await fetch(new URL('/pkg/my-app/1.0.0/esm.css', address));
|
|
101
|
-
const res3 = await fetch(
|
|
102
|
-
new URL('/pkg/my-app/1.0.0/assets/esm.css.map', address),
|
|
103
|
-
);
|
|
104
|
-
const res4 = await fetch(
|
|
105
|
-
new URL('/pkg/my-app/1.0.0/assets/esm.js.map', address),
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
t.equal(res1.status, 200);
|
|
109
|
-
t.equal(res2.status, 200);
|
|
110
|
-
t.equal(res3.status, 200);
|
|
111
|
-
t.equal(res4.status, 200);
|
|
112
|
-
await server.stop();
|
|
113
|
-
t.end();
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
test('Invalid app instance', async (t) => {
|
|
117
|
-
t.rejects(localAssets({}, __dirname));
|
|
118
|
-
t.end();
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
test('Invalid eik.json string', async (t) => {
|
|
122
|
-
const server = fastify();
|
|
123
|
-
t.rejects(localAssets(server, ''));
|
|
124
|
-
t.end();
|
|
125
|
-
});
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
const tap = require('tap');
|
|
2
|
-
const LocalFileLocation = require('../../src/classes/local-file-location.js');
|
|
3
|
-
|
|
4
|
-
tap.test('LocalFileLocation: .absolute for ./my/file.json', (t) => {
|
|
5
|
-
const subject = new LocalFileLocation('./my/file.json', '/base/path');
|
|
6
|
-
t.equal(
|
|
7
|
-
subject.absolute,
|
|
8
|
-
'/base/path/my/file.json',
|
|
9
|
-
'should result in a valid absolute path',
|
|
10
|
-
);
|
|
11
|
-
t.end();
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
tap.test('LocalFileLocation: .absolute for my/file.json', (t) => {
|
|
15
|
-
const subject = new LocalFileLocation('my/file.json', '/base/path');
|
|
16
|
-
t.equal(
|
|
17
|
-
subject.absolute,
|
|
18
|
-
'/base/path/my/file.json',
|
|
19
|
-
'should result in a valid absolute path',
|
|
20
|
-
);
|
|
21
|
-
t.end();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
tap.test(
|
|
25
|
-
'LocalFileLocation: .absolute for my/file.json: base path has trailing slash',
|
|
26
|
-
(t) => {
|
|
27
|
-
const subject = new LocalFileLocation('my/file.json', '/base/path/');
|
|
28
|
-
t.equal(
|
|
29
|
-
subject.absolute,
|
|
30
|
-
'/base/path/my/file.json',
|
|
31
|
-
'should result in a valid absolute path',
|
|
32
|
-
);
|
|
33
|
-
t.end();
|
|
34
|
-
},
|
|
35
|
-
);
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
const tap = require('tap');
|
|
2
|
-
const LocalFileLocation = require('../../src/classes/local-file-location.js');
|
|
3
|
-
|
|
4
|
-
tap.test('LocalFileLocation: .contentType for ./my/file.json', (t) => {
|
|
5
|
-
const subject = new LocalFileLocation('./my/file.json', __dirname);
|
|
6
|
-
t.equal(
|
|
7
|
-
subject.contentType,
|
|
8
|
-
'application/json; charset=utf-8',
|
|
9
|
-
'should be treated as JSON',
|
|
10
|
-
);
|
|
11
|
-
t.end();
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
tap.test('LocalFileLocation: .contentType for ./my/file.js', (t) => {
|
|
15
|
-
const subject = new LocalFileLocation('./my/file.js', __dirname);
|
|
16
|
-
t.equal(
|
|
17
|
-
subject.contentType,
|
|
18
|
-
'application/javascript; charset=utf-8',
|
|
19
|
-
'should be treated as JavaScript',
|
|
20
|
-
);
|
|
21
|
-
t.end();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
tap.test('LocalFileLocation: .contentType for file.css', (t) => {
|
|
25
|
-
const subject = new LocalFileLocation('./my/file.css', __dirname);
|
|
26
|
-
t.equal(
|
|
27
|
-
subject.contentType,
|
|
28
|
-
'text/css; charset=utf-8',
|
|
29
|
-
'should be treated as CSS',
|
|
30
|
-
);
|
|
31
|
-
t.end();
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
tap.test('LocalFileLocation: .contentType for file.jpg', (t) => {
|
|
35
|
-
const subject = new LocalFileLocation('./my/file.jpg', __dirname);
|
|
36
|
-
t.equal(
|
|
37
|
-
subject.contentType,
|
|
38
|
-
'image/jpeg',
|
|
39
|
-
'should be treated as jpeg image',
|
|
40
|
-
);
|
|
41
|
-
t.end();
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
tap.test(
|
|
45
|
-
'LocalFileLocation: .contentType should fallback for unknown file extension',
|
|
46
|
-
(t) => {
|
|
47
|
-
const subject = new LocalFileLocation('./my/file.unknown', __dirname);
|
|
48
|
-
t.equal(
|
|
49
|
-
subject.contentType,
|
|
50
|
-
'application/octet-stream',
|
|
51
|
-
'should be treated as application/octet-stream',
|
|
52
|
-
);
|
|
53
|
-
t.end();
|
|
54
|
-
},
|
|
55
|
-
);
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const tap = require('tap');
|
|
2
|
-
const LocalFileLocation = require('../../src/classes/local-file-location.js');
|
|
3
|
-
|
|
4
|
-
tap.test('LocalFileLocation: .extension for ./my/file.json', (t) => {
|
|
5
|
-
const subject = new LocalFileLocation('./my/file.json', __dirname);
|
|
6
|
-
t.equal(subject.extension, '.json', 'should be treated as JSON');
|
|
7
|
-
t.end();
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
tap.test('LocalFileLocation: .extension for ./my/file.js', (t) => {
|
|
11
|
-
const subject = new LocalFileLocation('./my/file.js', __dirname);
|
|
12
|
-
t.equal(subject.extension, '.js', 'should be treated as JavaScript');
|
|
13
|
-
t.end();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
tap.test('LocalFileLocation: .extension for file.css', (t) => {
|
|
17
|
-
const subject = new LocalFileLocation('./my/file.css', __dirname);
|
|
18
|
-
t.equal(subject.extension, '.css', 'should be treated as CSS');
|
|
19
|
-
t.end();
|
|
20
|
-
});
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
const tap = require('tap');
|
|
2
|
-
const LocalFileLocation = require('../../src/classes/local-file-location.js');
|
|
3
|
-
|
|
4
|
-
tap.test('LocalFileLocation: .mimeType for ./my/file.json', (t) => {
|
|
5
|
-
const subject = new LocalFileLocation('./my/file.json', __dirname);
|
|
6
|
-
t.equal(subject.mimeType, 'application/json', 'should be treated as JSON');
|
|
7
|
-
t.end();
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
tap.test('LocalFileLocation: .mimeType for ./my/file.js', (t) => {
|
|
11
|
-
const subject = new LocalFileLocation('./my/file.js', __dirname);
|
|
12
|
-
t.equal(
|
|
13
|
-
subject.mimeType,
|
|
14
|
-
'application/javascript',
|
|
15
|
-
'should be treated as JavaScript',
|
|
16
|
-
);
|
|
17
|
-
t.end();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
tap.test('LocalFileLocation: .mimeType for file.css', (t) => {
|
|
21
|
-
const subject = new LocalFileLocation('./my/file.css', __dirname);
|
|
22
|
-
t.equal(subject.mimeType, 'text/css', 'should be treated as CSS');
|
|
23
|
-
t.end();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
tap.test('LocalFileLocation: .mimeType for file.jpg', (t) => {
|
|
27
|
-
const subject = new LocalFileLocation('./my/file.jpg', __dirname);
|
|
28
|
-
t.equal(subject.mimeType, 'image/jpeg', 'should be treated as jpeg image');
|
|
29
|
-
t.end();
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
tap.test(
|
|
33
|
-
'LocalFileLocation: .mimeType should fallback for unknown file extension',
|
|
34
|
-
(t) => {
|
|
35
|
-
const subject = new LocalFileLocation('./my/file.unknown', __dirname);
|
|
36
|
-
t.equal(
|
|
37
|
-
subject.mimeType,
|
|
38
|
-
'application/octet-stream',
|
|
39
|
-
'should be treated as application/octet-stream',
|
|
40
|
-
);
|
|
41
|
-
t.end();
|
|
42
|
-
},
|
|
43
|
-
);
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
const { Readable } = require('stream');
|
|
2
|
-
const { test } = require('tap');
|
|
3
|
-
const ReadFile = require('../src/classes/read-file.js');
|
|
4
|
-
|
|
5
|
-
test('ReadFile() - Object type', (t) => {
|
|
6
|
-
const obj = new ReadFile();
|
|
7
|
-
t.equal(
|
|
8
|
-
Object.prototype.toString.call(obj),
|
|
9
|
-
'[object ReadFile]',
|
|
10
|
-
'should be ReadFile',
|
|
11
|
-
);
|
|
12
|
-
t.end();
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
test('ReadFile() - Default property values', (t) => {
|
|
16
|
-
const obj = new ReadFile();
|
|
17
|
-
t.equal(obj.mimeType, '', '.mimeType should be empty String');
|
|
18
|
-
t.equal(obj.stream, undefined, '.stream should be "undefined"');
|
|
19
|
-
t.equal(obj.etag, '', '.etag should be empty String');
|
|
20
|
-
t.end();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
test('ReadFile() - Set a value on the "mimeType" argument on the constructor', (t) => {
|
|
24
|
-
const obj = new ReadFile({ mimeType: 'foo' });
|
|
25
|
-
t.equal(
|
|
26
|
-
obj.mimeType,
|
|
27
|
-
'foo',
|
|
28
|
-
'.mimeType should be value set on constructor',
|
|
29
|
-
);
|
|
30
|
-
t.end();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
test('ReadFile() - Set a value on the "etag" argument on the constructor', (t) => {
|
|
34
|
-
const obj = new ReadFile({ etag: 'foo' });
|
|
35
|
-
t.equal(obj.etag, 'foo', '.etag should be value set on constructor');
|
|
36
|
-
t.end();
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test('ReadFile() - Set a Readable stream as value on the .stream property', (t) => {
|
|
40
|
-
const obj = new ReadFile();
|
|
41
|
-
obj.stream = new Readable();
|
|
42
|
-
t.ok(
|
|
43
|
-
obj.stream instanceof Readable,
|
|
44
|
-
'.stream should be value set on .stream',
|
|
45
|
-
);
|
|
46
|
-
t.end();
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
test('ReadFile() - Set a non Readable stream as value on the .stream property', (t) => {
|
|
50
|
-
t.plan(1);
|
|
51
|
-
t.throws(
|
|
52
|
-
() => {
|
|
53
|
-
const obj = new ReadFile();
|
|
54
|
-
obj.stream = 'foo';
|
|
55
|
-
},
|
|
56
|
-
/Value is not a Readable stream/,
|
|
57
|
-
'Should throw',
|
|
58
|
-
);
|
|
59
|
-
t.end();
|
|
60
|
-
});
|
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const os = require('os');
|
|
3
|
-
const { join, basename } = require('path');
|
|
4
|
-
const tap = require('tap');
|
|
5
|
-
const resolveFiles = require('../src/utils/resolve-files.js');
|
|
6
|
-
|
|
7
|
-
// then integrate the resolve-files function into eik-config.
|
|
8
|
-
|
|
9
|
-
// fix all tests
|
|
10
|
-
|
|
11
|
-
// then publish a PR and integrate into cli
|
|
12
|
-
|
|
13
|
-
const fixturesPath = join(__dirname, '../../../fixtures');
|
|
14
|
-
|
|
15
|
-
tap.test('when source is a relative folder', async (t) => {
|
|
16
|
-
const resolved = await resolveFiles({ '/': './folder' }, fixturesPath);
|
|
17
|
-
t.equal(resolved[0].destination, '/', 'destination should be unchanged');
|
|
18
|
-
t.equal(resolved[0].source, './folder', 'source should be unchanged');
|
|
19
|
-
t.match(
|
|
20
|
-
resolved[0].basePath,
|
|
21
|
-
'fixtures/folder',
|
|
22
|
-
'basePath should exclude glob',
|
|
23
|
-
);
|
|
24
|
-
t.equal(resolved[0].pattern, '**/*', 'pattern should exclude basePath');
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
tap.test(
|
|
28
|
-
'when source is a relative folder and files iterator is accessed',
|
|
29
|
-
async (t) => {
|
|
30
|
-
t.plan(6);
|
|
31
|
-
const resolved = await resolveFiles(
|
|
32
|
-
{ '/': 'folder/**/*' },
|
|
33
|
-
fixturesPath,
|
|
34
|
-
);
|
|
35
|
-
for (const file of resolved[0]) {
|
|
36
|
-
t.equal(
|
|
37
|
-
file.constructor.name,
|
|
38
|
-
'LocalFileLocation',
|
|
39
|
-
`${file.relative} wrapped in LocalFileLocation object`,
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
const asArray = Array.from(resolved[0]);
|
|
43
|
-
const { relative, absolute, basePath } = asArray[0];
|
|
44
|
-
t.equal(
|
|
45
|
-
relative,
|
|
46
|
-
'client.js',
|
|
47
|
-
'.relative should not include .basePath',
|
|
48
|
-
);
|
|
49
|
-
t.equal(
|
|
50
|
-
absolute,
|
|
51
|
-
join(basePath, relative),
|
|
52
|
-
'.absolute should include .basePath and .relative',
|
|
53
|
-
);
|
|
54
|
-
t.match(
|
|
55
|
-
basePath,
|
|
56
|
-
'fixtures/folder',
|
|
57
|
-
'.basePath should include everything except .relative',
|
|
58
|
-
);
|
|
59
|
-
t.notMatch(
|
|
60
|
-
basePath,
|
|
61
|
-
'client.js',
|
|
62
|
-
'.basePath should include everything except .relative',
|
|
63
|
-
);
|
|
64
|
-
},
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
tap.test('when source is a relative file', async (t) => {
|
|
68
|
-
const resolved = await resolveFiles(
|
|
69
|
-
{ '/': './folder/client.js' },
|
|
70
|
-
fixturesPath,
|
|
71
|
-
);
|
|
72
|
-
t.match(
|
|
73
|
-
resolved[0].basePath,
|
|
74
|
-
'fixtures/folder',
|
|
75
|
-
'basePath should exclude glob',
|
|
76
|
-
);
|
|
77
|
-
t.equal(
|
|
78
|
-
resolved[0].pattern,
|
|
79
|
-
'client.js',
|
|
80
|
-
'pattern should exclude basePath',
|
|
81
|
-
);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
tap.test('when source is a relative folder with glob', async (t) => {
|
|
85
|
-
const resolved = await resolveFiles({ '/': './folder/**/*' }, fixturesPath);
|
|
86
|
-
t.match(
|
|
87
|
-
resolved[0].basePath,
|
|
88
|
-
'fixtures/folder',
|
|
89
|
-
'basePath should exclude glob',
|
|
90
|
-
);
|
|
91
|
-
t.equal(resolved[0].pattern, '**/*', 'pattern should exclude basePath');
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
tap.test(
|
|
95
|
-
'when source is a relative folder with glob and nested files',
|
|
96
|
-
async (t) => {
|
|
97
|
-
const resolved = await resolveFiles({ '/': './**/*.js' }, fixturesPath);
|
|
98
|
-
t.match(
|
|
99
|
-
resolved[0].basePath,
|
|
100
|
-
'fixtures',
|
|
101
|
-
'basePath should exclude glob',
|
|
102
|
-
);
|
|
103
|
-
t.equal(
|
|
104
|
-
resolved[0].pattern,
|
|
105
|
-
'**/*.js',
|
|
106
|
-
'pattern should exclude basePath',
|
|
107
|
-
);
|
|
108
|
-
t.equal(Array.from(resolved[0])[2].relative, 'folder/client.js');
|
|
109
|
-
},
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
tap.test('when source is an absolute folder', async (t) => {
|
|
113
|
-
const resolved = await resolveFiles(
|
|
114
|
-
{ '/': join(fixturesPath, 'folder') },
|
|
115
|
-
fixturesPath,
|
|
116
|
-
);
|
|
117
|
-
t.match(
|
|
118
|
-
resolved[0].basePath,
|
|
119
|
-
'fixtures/folder',
|
|
120
|
-
'basePath should exclude glob',
|
|
121
|
-
);
|
|
122
|
-
t.equal(resolved[0].pattern, '**/*', 'pattern should exclude basePath');
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
tap.test('when source is an absolute file', async (t) => {
|
|
126
|
-
const resolved = await resolveFiles(
|
|
127
|
-
{ '/': join(fixturesPath, 'folder/client.js') },
|
|
128
|
-
fixturesPath,
|
|
129
|
-
);
|
|
130
|
-
t.match(
|
|
131
|
-
resolved[0].basePath,
|
|
132
|
-
'fixtures/folder',
|
|
133
|
-
'basePath should exclude glob',
|
|
134
|
-
);
|
|
135
|
-
t.match(
|
|
136
|
-
resolved[0].pattern,
|
|
137
|
-
'client.js',
|
|
138
|
-
'pattern should exclude basePath',
|
|
139
|
-
);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
tap.test('when source is an absolute folder with glob', async (t) => {
|
|
143
|
-
const resolved = await resolveFiles(
|
|
144
|
-
{ '/': join(fixturesPath, 'folder/**/*') },
|
|
145
|
-
fixturesPath,
|
|
146
|
-
);
|
|
147
|
-
t.match(
|
|
148
|
-
resolved[0].basePath,
|
|
149
|
-
'fixtures/folder',
|
|
150
|
-
'basePath should exclude glob',
|
|
151
|
-
);
|
|
152
|
-
t.equal(resolved[0].pattern, '**/*', 'pattern should exclude basePath');
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
tap.test(
|
|
156
|
-
'when source is an absolute folder and cwd is a different directory entirely',
|
|
157
|
-
async (t) => {
|
|
158
|
-
const cwd = await fs.mkdtempSync(
|
|
159
|
-
join(os.tmpdir(), basename(__filename)),
|
|
160
|
-
);
|
|
161
|
-
const resolved = await resolveFiles(
|
|
162
|
-
{ '/': join(fixturesPath, 'folder') },
|
|
163
|
-
cwd,
|
|
164
|
-
);
|
|
165
|
-
t.match(
|
|
166
|
-
resolved[0].basePath,
|
|
167
|
-
'fixtures/folder',
|
|
168
|
-
'basePath should exclude glob',
|
|
169
|
-
);
|
|
170
|
-
t.equal(resolved[0].pattern, '**/*', 'pattern should exclude basePath');
|
|
171
|
-
},
|
|
172
|
-
);
|
|
173
|
-
|
|
174
|
-
tap.test(
|
|
175
|
-
'when source is an absolute folder and files iterator is accessed',
|
|
176
|
-
async (t) => {
|
|
177
|
-
t.plan(6);
|
|
178
|
-
const bPath = await fs.mkdtempSync(
|
|
179
|
-
join(os.tmpdir(), basename(__filename)),
|
|
180
|
-
);
|
|
181
|
-
const resolved = await resolveFiles(
|
|
182
|
-
{ '/': join(fixturesPath, 'folder') },
|
|
183
|
-
bPath,
|
|
184
|
-
);
|
|
185
|
-
for (const file of resolved[0]) {
|
|
186
|
-
t.equal(
|
|
187
|
-
file.constructor.name,
|
|
188
|
-
'LocalFileLocation',
|
|
189
|
-
`${file.relative} wrapped in LocalFileLocation object`,
|
|
190
|
-
);
|
|
191
|
-
}
|
|
192
|
-
const asArray = Array.from(resolved[0]);
|
|
193
|
-
const { relative, absolute, basePath } = asArray[0];
|
|
194
|
-
t.equal(
|
|
195
|
-
relative,
|
|
196
|
-
'client.js',
|
|
197
|
-
'.relative should not include .basePath',
|
|
198
|
-
);
|
|
199
|
-
t.equal(
|
|
200
|
-
absolute,
|
|
201
|
-
join(basePath, relative),
|
|
202
|
-
'.absolute should include .basePath and .relative',
|
|
203
|
-
);
|
|
204
|
-
t.match(
|
|
205
|
-
basePath,
|
|
206
|
-
'fixtures/folder',
|
|
207
|
-
'.basePath should include everything except .relative',
|
|
208
|
-
);
|
|
209
|
-
t.notMatch(
|
|
210
|
-
basePath,
|
|
211
|
-
'client.js',
|
|
212
|
-
'.basePath should include everything except .relative',
|
|
213
|
-
);
|
|
214
|
-
},
|
|
215
|
-
);
|
|
216
|
-
|
|
217
|
-
tap.test(
|
|
218
|
-
'when source is an absolute file and cwd is a different directory entirely',
|
|
219
|
-
async (t) => {
|
|
220
|
-
const cwd = await fs.mkdtempSync(
|
|
221
|
-
join(os.tmpdir(), basename(__filename)),
|
|
222
|
-
);
|
|
223
|
-
const resolved = await resolveFiles(
|
|
224
|
-
{ '/': join(fixturesPath, 'folder/client.js') },
|
|
225
|
-
cwd,
|
|
226
|
-
);
|
|
227
|
-
t.match(
|
|
228
|
-
resolved[0].basePath,
|
|
229
|
-
'fixtures/folder',
|
|
230
|
-
'basePath should exclude glob',
|
|
231
|
-
);
|
|
232
|
-
t.equal(
|
|
233
|
-
resolved[0].pattern,
|
|
234
|
-
'client.js',
|
|
235
|
-
'pattern should exclude basePath',
|
|
236
|
-
);
|
|
237
|
-
},
|
|
238
|
-
);
|
|
239
|
-
|
|
240
|
-
tap.test(
|
|
241
|
-
'when source is an absolute folder with glob and cwd is a different directory entirely',
|
|
242
|
-
async (t) => {
|
|
243
|
-
const cwd = await fs.mkdtempSync(
|
|
244
|
-
join(os.tmpdir(), basename(__filename)),
|
|
245
|
-
);
|
|
246
|
-
const resolved = await resolveFiles(
|
|
247
|
-
{ '/': join(fixturesPath, 'folder/**/*') },
|
|
248
|
-
cwd,
|
|
249
|
-
);
|
|
250
|
-
t.match(
|
|
251
|
-
resolved[0].basePath,
|
|
252
|
-
'fixtures/folder',
|
|
253
|
-
'basePath should exclude glob',
|
|
254
|
-
);
|
|
255
|
-
t.equal(resolved[0].pattern, '**/*', 'pattern should exclude basePath');
|
|
256
|
-
},
|
|
257
|
-
);
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const tap = require('tap');
|
|
2
|
-
const ResolvedFiles = require('../../src/classes/resolved-files.js');
|
|
3
|
-
|
|
4
|
-
tap.test('ResolvedFiles: iterator for ./my/file.js', (t) => {
|
|
5
|
-
const subject = new ResolvedFiles(['./my/file.js', './my/file.css'], {
|
|
6
|
-
basePath: '/base/path',
|
|
7
|
-
definition: ['dest', 'src'],
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
const files = Array.from(subject);
|
|
11
|
-
t.equal(
|
|
12
|
-
files[0].relative,
|
|
13
|
-
'./my/file.js',
|
|
14
|
-
'should result in a valid absolute path',
|
|
15
|
-
);
|
|
16
|
-
t.end();
|
|
17
|
-
});
|
|
File without changes
|