@appsemble/node-utils 0.20.28 → 0.20.29
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/README.md +4 -4
- package/package.json +2 -2
- package/AppsembleError.js.map +0 -1
- package/AppsembleError.test.js.map +0 -1
- package/AppsembleError.test.ts +0 -6
- package/AppsembleError.ts +0 -16
- package/__fixtures__/hello.txt +0 -1
- package/__fixtures__/invalid-json.json +0 -3
- package/__fixtures__/json.json +0 -1
- package/__fixtures__/test/bar.txt +0 -0
- package/__fixtures__/test/foo.txt +0 -0
- package/__fixtures__/test/z/baz.txt +0 -0
- package/__fixtures__/test/z/fooz.txt +0 -0
- package/__fixtures__/yaml.yaml +0 -1
- package/basicAuth.js.map +0 -1
- package/basicAuth.test.js.map +0 -1
- package/basicAuth.test.ts +0 -6
- package/basicAuth.ts +0 -10
- package/changed/added/.gitkeep +0 -0
- package/changed/changed/.gitkeep +0 -0
- package/changed/deprecated/.gitkeep +0 -0
- package/changed/fixed/.gitkeep +0 -0
- package/changed/removed/.gitkeep +0 -0
- package/changed/security/.gitkeep +0 -0
- package/formData.js.map +0 -1
- package/formData.test.js.map +0 -1
- package/formData.test.ts +0 -113
- package/formData.ts +0 -37
- package/fs.js.map +0 -1
- package/fs.test.js.map +0 -1
- package/fs.test.ts +0 -120
- package/fs.ts +0 -147
- package/getWorkspaces.js.map +0 -1
- package/getWorkspaces.ts +0 -23
- package/handleError.js.map +0 -1
- package/handleError.test.js.map +0 -1
- package/handleError.test.ts +0 -38
- package/handleError.ts +0 -26
- package/index.js.map +0 -1
- package/index.ts +0 -11
- package/interceptors.js.map +0 -1
- package/interceptors.test.js.map +0 -1
- package/interceptors.test.ts +0 -102
- package/interceptors.ts +0 -81
- package/jest.config.js +0 -3
- package/jest.setup.js.map +0 -1
- package/jest.setup.ts +0 -7
- package/logger.js.map +0 -1
- package/logger.test.js.map +0 -1
- package/logger.test.ts +0 -43
- package/logger.ts +0 -130
- package/loggerMiddleware.js.map +0 -1
- package/loggerMiddleware.test.js.map +0 -1
- package/loggerMiddleware.test.ts +0 -179
- package/loggerMiddleware.ts +0 -93
- package/readFileOrString.js.map +0 -1
- package/readFileOrString.test.js.map +0 -1
- package/readFileOrString.test.ts +0 -12
- package/readFileOrString.ts +0 -20
- package/testFixtures.js.map +0 -1
- package/testFixtures.ts +0 -57
- package/tsconfig.json +0 -6
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
#  Appsemble Node Utilities
|
|
2
2
|
|
|
3
3
|
> NodeJS utilities used by Appsemble internally.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@appsemble/node-utils)
|
|
6
|
-
[](https://gitlab.com/appsemble/appsemble/-/releases/0.20.29)
|
|
7
|
+
[](https://codecov.io/gl/appsemble/appsemble)
|
|
8
8
|
[](https://prettier.io)
|
|
9
9
|
|
|
10
10
|
## Installation
|
|
@@ -21,5 +21,5 @@ compatibility is not guaranteed.
|
|
|
21
21
|
|
|
22
22
|
## License
|
|
23
23
|
|
|
24
|
-
[LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.20.
|
|
24
|
+
[LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.20.29/LICENSE.md) ©
|
|
25
25
|
[Appsemble](https://appsemble.com)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appsemble/node-utils",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.29",
|
|
4
4
|
"description": "NodeJS utilities used by Appsemble internally.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"app",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"test": "NODE_OPTIONS=--experimental-vm-modules jest"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@appsemble/utils": "0.20.
|
|
34
|
+
"@appsemble/utils": "0.20.29",
|
|
35
35
|
"@types/koa": "^2.0.0",
|
|
36
36
|
"axios": "^0.27.0",
|
|
37
37
|
"chalk": "^4.0.0",
|
package/AppsembleError.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AppsembleError.js","sourceRoot":"","sources":["AppsembleError.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvC;;OAEG;IACH,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IAClD,CAAC;CACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AppsembleError.test.js","sourceRoot":"","sources":["AppsembleError.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,EAAE,CAAC,0CAA0C,EAAE,GAAG,EAAE;IAClD,MAAM,KAAK,GAAG,IAAI,cAAc,CAAC,SAAS,CAAC,CAAC;IAC5C,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;AAC5C,CAAC,CAAC,CAAC"}
|
package/AppsembleError.test.ts
DELETED
package/AppsembleError.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Used for throwing known Appsemble errors.
|
|
3
|
-
*
|
|
4
|
-
* This is used when the normal control flow needs to be aborted, but for reasons known. When an
|
|
5
|
-
* instance of `AppsembleError` is thrown, the message will be logged, but not the stack trace.
|
|
6
|
-
*/
|
|
7
|
-
export class AppsembleError extends Error {
|
|
8
|
-
/**
|
|
9
|
-
* @param message The error message to show to the user.
|
|
10
|
-
*/
|
|
11
|
-
constructor(message: string) {
|
|
12
|
-
super(message);
|
|
13
|
-
this.name = 'AppsembleError';
|
|
14
|
-
Error.captureStackTrace(this, this.constructor);
|
|
15
|
-
}
|
|
16
|
-
}
|
package/__fixtures__/hello.txt
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Hello world!
|
package/__fixtures__/json.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{ "json": "json" }
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/__fixtures__/yaml.yaml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
yaml: yaml
|
package/basicAuth.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"basicAuth.js","sourceRoot":"","sources":["basicAuth.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAC,QAAgB,EAAE,QAAgB;IAC1D,OAAO,SAAS,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,IAAI,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;AAC9E,CAAC"}
|
package/basicAuth.test.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"basicAuth.test.js","sourceRoot":"","sources":["basicAuth.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,EAAE,CAAC,8BAA8B,EAAE,GAAG,EAAE;IACtC,MAAM,MAAM,GAAG,SAAS,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IAC5C,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;AAChD,CAAC,CAAC,CAAC"}
|
package/basicAuth.test.ts
DELETED
package/basicAuth.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Create a basic auth authorization header from a username and password.
|
|
3
|
-
*
|
|
4
|
-
* @param username The username to serialize.
|
|
5
|
-
* @param password The password to serialize.
|
|
6
|
-
* @returns An HTTP basic auth authorization header.
|
|
7
|
-
*/
|
|
8
|
-
export function basicAuth(username: string, password: string): string {
|
|
9
|
-
return `Basic ${Buffer.from(`${username}:${password}`).toString('base64')}`;
|
|
10
|
-
}
|
package/changed/added/.gitkeep
DELETED
|
File without changes
|
package/changed/changed/.gitkeep
DELETED
|
File without changes
|
|
File without changes
|
package/changed/fixed/.gitkeep
DELETED
|
File without changes
|
package/changed/removed/.gitkeep
DELETED
|
File without changes
|
|
File without changes
|
package/formData.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formData.js","sourceRoot":"","sources":["formData.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,OAAO,QAAQ,MAAM,WAAW,CAAC;AAEjC,SAAS,cAAc,CAAC,GAAW,EAAE,KAAU,EAAE,IAAc;IAC7D,IAAI,KAAK,KAAK,SAAS,EAAE;QACvB,OAAO;KACR;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACxB,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE;YACvB,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;SAChC;KACF;SAAM;QACL,IAAI,CAAC,MAAM,CACT,GAAG,EACH,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,YAAY,UAAU;YAChF,CAAC,CAAC,KAAK;YACP,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAC1B,CAAC;KACH;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAAC,IAAyB;IACtD,MAAM,IAAI,GAAG,IAAI,QAAQ,EAAE,CAAC;IAC5B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QAC/C,cAAc,CAAC,GAAG,EAA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AM,QAAQ,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QACpC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,IAAI,CACnC,KAAK,QAAQ;;;;IAIf,QAAQ;CACX,CACI,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yDAAyD,EAAE,GAAG,EAAE;QACjE,MAAM,IAAI,GAAG,cAAc,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;QAC/E,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QACpC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,IAAI,CACnC,KAAK,QAAQ;;;;IAIf,QAAQ;;;;IAIR,QAAQ;;;;IAIR,QAAQ;;;;IAIR,QAAQ;CACX,CACI,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/formData.test.ts
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { createFormData } from './formData.js';
|
|
2
|
-
|
|
3
|
-
describe('createFormData', () => {
|
|
4
|
-
it('should handle strings', () => {
|
|
5
|
-
const form = createFormData({ foo: 'bar' });
|
|
6
|
-
const boundary = form.getBoundary();
|
|
7
|
-
expect(String(form.getBuffer())).toBe(
|
|
8
|
-
`--${boundary}\r
|
|
9
|
-
Content-Disposition: form-data; name="foo"\r
|
|
10
|
-
\r
|
|
11
|
-
bar\r
|
|
12
|
-
--${boundary}--\r
|
|
13
|
-
`,
|
|
14
|
-
);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('should handle numbers', () => {
|
|
18
|
-
const form = createFormData({ answer: 42 });
|
|
19
|
-
const boundary = form.getBoundary();
|
|
20
|
-
expect(String(form.getBuffer())).toBe(
|
|
21
|
-
`--${boundary}\r
|
|
22
|
-
Content-Disposition: form-data; name="answer"\r
|
|
23
|
-
\r
|
|
24
|
-
42\r
|
|
25
|
-
--${boundary}--\r
|
|
26
|
-
`,
|
|
27
|
-
);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('should handle booleans', () => {
|
|
31
|
-
const form = createFormData({ really: true });
|
|
32
|
-
const boundary = form.getBoundary();
|
|
33
|
-
expect(String(form.getBuffer())).toBe(
|
|
34
|
-
`--${boundary}\r
|
|
35
|
-
Content-Disposition: form-data; name="really"\r
|
|
36
|
-
\r
|
|
37
|
-
true\r
|
|
38
|
-
--${boundary}--\r
|
|
39
|
-
`,
|
|
40
|
-
);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('should handle buffers', () => {
|
|
44
|
-
const form = createFormData({ buf: Buffer.from('fer') });
|
|
45
|
-
const boundary = form.getBoundary();
|
|
46
|
-
expect(String(form.getBuffer())).toBe(
|
|
47
|
-
`--${boundary}\r
|
|
48
|
-
Content-Disposition: form-data; name="buf"\r
|
|
49
|
-
Content-Type: application/octet-stream\r
|
|
50
|
-
\r
|
|
51
|
-
fer\r
|
|
52
|
-
--${boundary}--\r
|
|
53
|
-
`,
|
|
54
|
-
);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('should handle null', () => {
|
|
58
|
-
const form = createFormData({ really: true });
|
|
59
|
-
const boundary = form.getBoundary();
|
|
60
|
-
expect(String(form.getBuffer())).toBe(
|
|
61
|
-
`--${boundary}\r
|
|
62
|
-
Content-Disposition: form-data; name="really"\r
|
|
63
|
-
\r
|
|
64
|
-
true\r
|
|
65
|
-
--${boundary}--\r
|
|
66
|
-
`,
|
|
67
|
-
);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('should ignore undefined', () => {
|
|
71
|
-
const form = createFormData({ defined: undefined });
|
|
72
|
-
const boundary = form.getBoundary();
|
|
73
|
-
expect(String(form.getBuffer())).toBe(`--${boundary}--\r\n`);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('should convert objects to JSON', () => {
|
|
77
|
-
const form = createFormData({ deeply: { nested: 'data' } });
|
|
78
|
-
const boundary = form.getBoundary();
|
|
79
|
-
expect(String(form.getBuffer())).toBe(
|
|
80
|
-
`--${boundary}\r
|
|
81
|
-
Content-Disposition: form-data; name="deeply"\r
|
|
82
|
-
\r
|
|
83
|
-
{"nested":"data"}\r
|
|
84
|
-
--${boundary}--\r
|
|
85
|
-
`,
|
|
86
|
-
);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it('should append multiple entries if the input is an array', () => {
|
|
90
|
-
const form = createFormData({ array: [42, 'bananas', null, { fruit: true }] });
|
|
91
|
-
const boundary = form.getBoundary();
|
|
92
|
-
expect(String(form.getBuffer())).toBe(
|
|
93
|
-
`--${boundary}\r
|
|
94
|
-
Content-Disposition: form-data; name="array"\r
|
|
95
|
-
\r
|
|
96
|
-
42\r
|
|
97
|
-
--${boundary}\r
|
|
98
|
-
Content-Disposition: form-data; name="array"\r
|
|
99
|
-
\r
|
|
100
|
-
bananas\r
|
|
101
|
-
--${boundary}\r
|
|
102
|
-
Content-Disposition: form-data; name="array"\r
|
|
103
|
-
\r
|
|
104
|
-
null\r
|
|
105
|
-
--${boundary}\r
|
|
106
|
-
Content-Disposition: form-data; name="array"\r
|
|
107
|
-
\r
|
|
108
|
-
{"fruit":true}\r
|
|
109
|
-
--${boundary}--\r
|
|
110
|
-
`,
|
|
111
|
-
);
|
|
112
|
-
});
|
|
113
|
-
});
|
package/formData.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { ReadStream } from 'node:fs';
|
|
2
|
-
|
|
3
|
-
import FormData from 'form-data';
|
|
4
|
-
|
|
5
|
-
function appendFormData(key: string, value: any, form: FormData): void {
|
|
6
|
-
if (value === undefined) {
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
if (Array.isArray(value)) {
|
|
10
|
-
for (const val of value) {
|
|
11
|
-
appendFormData(key, val, form);
|
|
12
|
-
}
|
|
13
|
-
} else {
|
|
14
|
-
form.append(
|
|
15
|
-
key,
|
|
16
|
-
typeof value === 'string' || Buffer.isBuffer(value) || value instanceof ReadStream
|
|
17
|
-
? value
|
|
18
|
-
: JSON.stringify(value),
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* A convenience function for creating form data.
|
|
25
|
-
*
|
|
26
|
-
* @param data A key / value record of fields to append to the form data. Booleans, numbers,
|
|
27
|
-
* strings, and `null` will be added to the form data raw. Objects will be transformed to JSON
|
|
28
|
-
* objects. Arrays will be iterated over and every item will be appended for the given key.
|
|
29
|
-
* @returns The data represented as form data.
|
|
30
|
-
*/
|
|
31
|
-
export function createFormData(data: Record<string, any>): FormData {
|
|
32
|
-
const form = new FormData();
|
|
33
|
-
for (const [key, value] of Object.entries(data)) {
|
|
34
|
-
appendFormData(key, value, form);
|
|
35
|
-
}
|
|
36
|
-
return form;
|
|
37
|
-
}
|
package/fs.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fs.js","sourceRoot":"","sources":["fs.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEnD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,QAAQ,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAExC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C;;;;;;GAMG;AACH,MAAM,UAAU,OAAO,CAAC,KAAc,EAAE,IAAa;IACnD,IAAI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M,IAAI,GAAG,cAAc,CAAC,cAAc,CAAC,CAAC;QAC5C,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC;QACtF,MAAM,CAAC,MAAM,CAAC,CAAC,aAAa,EAAE,CAAC;IACjC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/fs.test.ts
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { AppsembleError, isErrno, opendirSafe, readData, resolveFixture } from './index.js';
|
|
2
|
-
|
|
3
|
-
describe('isErrno', () => {
|
|
4
|
-
it('should return false for null', () => {
|
|
5
|
-
expect(isErrno(null)).toBe(false);
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
it('should return false for miscellaneous objects', () => {
|
|
9
|
-
expect(isErrno({})).toBe(false);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it('should return true if the object has a string property named code', () => {
|
|
13
|
-
expect(isErrno({ code: 'foo' })).toBe(true);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('should return false if the object has a non-string property named code', () => {
|
|
17
|
-
expect(isErrno({ code: 42 })).toBe(false);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('should allow to narrow down a specific code', () => {
|
|
21
|
-
expect(isErrno({ code: 'ENOENT' }, 'ENOENT')).toBe(true);
|
|
22
|
-
expect(isErrno({ code: 'invalid' }, 'ENOENT')).toBe(false);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
describe('readData', () => {
|
|
27
|
-
it('should read and parse a JSON file', async () => {
|
|
28
|
-
const content = await readData(resolveFixture('json.json'));
|
|
29
|
-
expect(content).toStrictEqual([{ json: 'json' }, '{ "json": "json" }\n']);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('should read and parse a YAML file', async () => {
|
|
33
|
-
const content = await readData(resolveFixture('yaml.yaml'));
|
|
34
|
-
expect(content).toStrictEqual([{ yaml: 'yaml' }, 'yaml: yaml\n']);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('should throw an Appsemble error if file extension is unknown', async () => {
|
|
38
|
-
const path = resolveFixture('hello.txt');
|
|
39
|
-
await expect(readData(path)).rejects.toThrow(
|
|
40
|
-
new AppsembleError(`Unknown file extension: ${path}`),
|
|
41
|
-
);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('should throw an Appsemble error if the file can’t be read', async () => {
|
|
45
|
-
await expect(readData('non-existent.yaml')).rejects.toThrow(
|
|
46
|
-
new AppsembleError('Error reading file non-existent.yaml'),
|
|
47
|
-
);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('should throw an Appsemble error if the file can’t be parsed', async () => {
|
|
51
|
-
const path = resolveFixture('invalid-json.json');
|
|
52
|
-
await expect(readData(path)).rejects.toThrow(AppsembleError);
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
describe('opendirSafe', () => {
|
|
57
|
-
it('should read a directory', async () => {
|
|
58
|
-
const onFile = import.meta.jest.fn();
|
|
59
|
-
await opendirSafe(resolveFixture('test'), onFile);
|
|
60
|
-
expect(onFile).toHaveBeenCalledTimes(3);
|
|
61
|
-
expect(onFile).toHaveBeenCalledWith(
|
|
62
|
-
resolveFixture('test/bar.txt'),
|
|
63
|
-
expect.objectContaining({ name: 'bar.txt' }),
|
|
64
|
-
);
|
|
65
|
-
expect(onFile).toHaveBeenCalledWith(
|
|
66
|
-
resolveFixture('test/foo.txt'),
|
|
67
|
-
expect.objectContaining({ name: 'foo.txt' }),
|
|
68
|
-
);
|
|
69
|
-
expect(onFile).toHaveBeenCalledWith(
|
|
70
|
-
resolveFixture('test/z'),
|
|
71
|
-
expect.objectContaining({ name: 'z' }),
|
|
72
|
-
);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('should read a directory recursively if specified', async () => {
|
|
76
|
-
const onFile = import.meta.jest.fn();
|
|
77
|
-
await opendirSafe(resolveFixture('test'), onFile, { recursive: true });
|
|
78
|
-
expect(onFile).toHaveBeenCalledTimes(5);
|
|
79
|
-
expect(onFile).toHaveBeenCalledWith(
|
|
80
|
-
resolveFixture('test/bar.txt'),
|
|
81
|
-
expect.objectContaining({ name: 'bar.txt' }),
|
|
82
|
-
);
|
|
83
|
-
expect(onFile).toHaveBeenCalledWith(
|
|
84
|
-
resolveFixture('test/foo.txt'),
|
|
85
|
-
expect.objectContaining({ name: 'foo.txt' }),
|
|
86
|
-
);
|
|
87
|
-
expect(onFile).toHaveBeenCalledWith(
|
|
88
|
-
resolveFixture('test/z'),
|
|
89
|
-
expect.objectContaining({ name: 'z' }),
|
|
90
|
-
);
|
|
91
|
-
expect(onFile).toHaveBeenCalledWith(
|
|
92
|
-
resolveFixture('test/z/baz.txt'),
|
|
93
|
-
expect.objectContaining({ name: 'baz.txt' }),
|
|
94
|
-
);
|
|
95
|
-
expect(onFile).toHaveBeenCalledWith(
|
|
96
|
-
resolveFixture('test/z/fooz.txt'),
|
|
97
|
-
expect.objectContaining({ name: 'fooz.txt' }),
|
|
98
|
-
);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('should throw if the path is not a directory', async () => {
|
|
102
|
-
const path = resolveFixture('hello.txt');
|
|
103
|
-
await expect(opendirSafe(path, import.meta.jest.fn())).rejects.toThrow(
|
|
104
|
-
new AppsembleError(`Expected ${path} to be a directory`),
|
|
105
|
-
);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('should throw if the path doesn’t exist', async () => {
|
|
109
|
-
const path = resolveFixture('non-existent');
|
|
110
|
-
await expect(opendirSafe(path, import.meta.jest.fn())).rejects.toThrow(
|
|
111
|
-
new AppsembleError(`Expected ${path} to be a directory`),
|
|
112
|
-
);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('should not throw if the path doesn’t exist and allowMissing is true', async () => {
|
|
116
|
-
const path = resolveFixture('non-existent');
|
|
117
|
-
const result = await opendirSafe(path, import.meta.jest.fn(), { allowMissing: true });
|
|
118
|
-
expect(result).toBeUndefined();
|
|
119
|
-
});
|
|
120
|
-
});
|
package/fs.ts
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { Dirent, Stats } from 'node:fs';
|
|
2
|
-
import { mkdir, opendir, readFile, stat, writeFile } from 'node:fs/promises';
|
|
3
|
-
import { dirname, extname, join } from 'node:path';
|
|
4
|
-
|
|
5
|
-
import { compareStrings } from '@appsemble/utils';
|
|
6
|
-
import parseJson from 'parse-json';
|
|
7
|
-
import sortKeys from 'sort-keys';
|
|
8
|
-
import { Promisable } from 'type-fest';
|
|
9
|
-
import { parse, stringify } from 'yaml';
|
|
10
|
-
|
|
11
|
-
import { AppsembleError } from './index.js';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Test if the error is a NodeJS errno exception.
|
|
15
|
-
*
|
|
16
|
-
* @param error The value to check
|
|
17
|
-
* @param code If specified, check if the code matches
|
|
18
|
-
* @returns Whether or not the error is a NodeJS errno exception.
|
|
19
|
-
*/
|
|
20
|
-
export function isErrno(error: unknown, code?: string): error is NodeJS.ErrnoException {
|
|
21
|
-
if (!error || typeof error !== 'object') {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
const err = error as NodeJS.ErrnoException;
|
|
25
|
-
if (code) {
|
|
26
|
-
return err.code === code;
|
|
27
|
-
}
|
|
28
|
-
return typeof err.code === 'string';
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Read the content of a JSON or YAML file.
|
|
33
|
-
*
|
|
34
|
-
* @param path The path to the file to read.
|
|
35
|
-
* @returns A tuple of the parsed content and the content as a string.
|
|
36
|
-
*/
|
|
37
|
-
export async function readData<R>(path: URL | string): Promise<[R, string]> {
|
|
38
|
-
let content: string;
|
|
39
|
-
const ext = extname(String(path));
|
|
40
|
-
try {
|
|
41
|
-
content = await readFile(path, 'utf8');
|
|
42
|
-
} catch {
|
|
43
|
-
throw new AppsembleError(`Error reading file ${path}`);
|
|
44
|
-
}
|
|
45
|
-
if (ext !== '.yaml' && ext !== '.yml' && ext !== '.json') {
|
|
46
|
-
throw new AppsembleError(`Unknown file extension: ${path}`);
|
|
47
|
-
}
|
|
48
|
-
try {
|
|
49
|
-
return [
|
|
50
|
-
ext === '.json' ? parseJson(content) : (parse(content, { maxAliasCount: 10_000 }) as R),
|
|
51
|
-
content,
|
|
52
|
-
];
|
|
53
|
-
} catch (error: unknown) {
|
|
54
|
-
throw new AppsembleError(`Error parsing ${path}\n${(error as Error).message}`);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
interface WriteDataOptions {
|
|
59
|
-
/**
|
|
60
|
-
* If false, don’t sort the object keys.
|
|
61
|
-
*/
|
|
62
|
-
readonly sort?: boolean;
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* A comparison function to use for sorting keys.
|
|
66
|
-
*
|
|
67
|
-
* By default natural sorting will be used.
|
|
68
|
-
*/
|
|
69
|
-
readonly compare?: ((a: string, b: string) => number) | null;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Write data to a file serialized as JSON or YAML.
|
|
74
|
-
*
|
|
75
|
-
* If `prettier` is available, the content is also formatted.
|
|
76
|
-
*
|
|
77
|
-
* @param path The file path to write the data to.
|
|
78
|
-
* @param data The data to write to the file.
|
|
79
|
-
* @param options Additional options for processing the data.
|
|
80
|
-
* @returns The formatted content.
|
|
81
|
-
*/
|
|
82
|
-
export async function writeData(
|
|
83
|
-
path: string,
|
|
84
|
-
data: unknown,
|
|
85
|
-
{ compare = compareStrings, sort = true }: WriteDataOptions = {},
|
|
86
|
-
): Promise<string> {
|
|
87
|
-
const sorted = sort ? sortKeys(data, { deep: true, compare: compare || undefined }) : data;
|
|
88
|
-
let buffer: string;
|
|
89
|
-
try {
|
|
90
|
-
const { default: prettier } = await import('prettier');
|
|
91
|
-
const { inferredParser } = await prettier.getFileInfo(path, { resolveConfig: true });
|
|
92
|
-
const prettierOptions = await prettier.resolveConfig(path, { editorconfig: true });
|
|
93
|
-
prettierOptions.parser = inferredParser;
|
|
94
|
-
buffer =
|
|
95
|
-
inferredParser === 'yaml' ? stringify(sorted) : `${JSON.stringify(sorted, undefined, 2)}\n`;
|
|
96
|
-
buffer = prettier.format(buffer, prettierOptions);
|
|
97
|
-
} catch {
|
|
98
|
-
const ext = extname(path);
|
|
99
|
-
buffer =
|
|
100
|
-
ext === '.yml' || ext === '.yaml'
|
|
101
|
-
? stringify(sorted)
|
|
102
|
-
: `${JSON.stringify(sorted, undefined, 2)}\n`;
|
|
103
|
-
}
|
|
104
|
-
await mkdir(dirname(path), { recursive: true });
|
|
105
|
-
await writeFile(path, buffer);
|
|
106
|
-
return buffer;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
interface OpenDirSafeOptions {
|
|
110
|
-
allowMissing?: boolean;
|
|
111
|
-
recursive?: boolean;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Read the contents of a directory.
|
|
116
|
-
*
|
|
117
|
-
* @param directory The path of the directory to open.
|
|
118
|
-
* @param onFile A callback which will get called for every file. This will be called with the full
|
|
119
|
-
* file path as its first argument and its `Dirent` object as the second argument.
|
|
120
|
-
* @param options Additional options.
|
|
121
|
-
*/
|
|
122
|
-
export async function opendirSafe(
|
|
123
|
-
directory: string,
|
|
124
|
-
onFile: (fullpath: string, stat: Dirent) => Promisable<void>,
|
|
125
|
-
options: OpenDirSafeOptions = {},
|
|
126
|
-
): Promise<void> {
|
|
127
|
-
let stats: Stats;
|
|
128
|
-
try {
|
|
129
|
-
stats = await stat(directory);
|
|
130
|
-
} catch (err: unknown) {
|
|
131
|
-
if (options.allowMissing && isErrno(err, 'ENOENT')) {
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
throw new AppsembleError(`Expected ${directory} to be a directory`);
|
|
135
|
-
}
|
|
136
|
-
if (!stats.isDirectory()) {
|
|
137
|
-
throw new AppsembleError(`Expected ${directory} to be a directory`);
|
|
138
|
-
}
|
|
139
|
-
const dir = await opendir(directory);
|
|
140
|
-
for await (const file of dir) {
|
|
141
|
-
const fullPath = join(directory, file.name);
|
|
142
|
-
await onFile(fullPath, file);
|
|
143
|
-
if (options.recursive && file.isDirectory()) {
|
|
144
|
-
await opendirSafe(fullPath, onFile, options);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
package/getWorkspaces.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getWorkspaces.js","sourceRoot":"","sources":["getWorkspaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,MAAM,WAAW,CAAC;AAE3B;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,GAAW;IAC7C,MAAM,EAAE,UAAU,GAAG,EAAE,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;IAC1F,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,UAAU,EAAE;QAChC,GAAG;QACH,QAAQ,EAAE,IAAI;QACd,mBAAmB,EAAE,IAAI;QACzB,eAAe,EAAE,IAAI;KACtB,CAAC,CAAC;IACH,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC;AACrB,CAAC"}
|
package/getWorkspaces.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { readFile } from 'node:fs/promises';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
|
|
4
|
-
import fg from 'fast-glob';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Discover Appsemble blocks based on workspaces in a monorepo.
|
|
8
|
-
*
|
|
9
|
-
* Both Lerna and Yarn workspaces are supported.
|
|
10
|
-
*
|
|
11
|
-
* @param cwd The project root in which to find workspaces.
|
|
12
|
-
* @returns Discovered Appsemble blocks.
|
|
13
|
-
*/
|
|
14
|
-
export async function getWorkspaces(cwd: string): Promise<string[]> {
|
|
15
|
-
const { workspaces = [] } = JSON.parse(await readFile(join(cwd, 'package.json'), 'utf8'));
|
|
16
|
-
const dirs = await fg(workspaces, {
|
|
17
|
-
cwd,
|
|
18
|
-
absolute: true,
|
|
19
|
-
followSymbolicLinks: true,
|
|
20
|
-
onlyDirectories: true,
|
|
21
|
-
});
|
|
22
|
-
return dirs.sort();
|
|
23
|
-
}
|
package/handleError.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"handleError.js","sourceRoot":"","sources":["handleError.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CAAC,OAAe,EAAE,KAAY,EAAE,KAAW;IACpE,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;QAC/B,KAAK,CAAC,QAAQ,EAAE,CAAC;QACjB,sCAAsC;QACtC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;KACxB;SAAM,IAAI,KAAK,YAAY,cAAc,EAAE;QAC1C,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;KAC7B;SAAM;QACL,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;KACrB;IACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC"}
|
package/handleError.test.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"handleError.test.js","sourceRoot":"","sources":["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