@eik/common 4.1.1 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/lib/classes/custom-error.js +8 -8
  3. package/lib/classes/eik-config.js +148 -150
  4. package/lib/classes/file-mapping.js +25 -25
  5. package/lib/classes/invalid-config-error.js +7 -7
  6. package/lib/classes/local-file-location.js +45 -52
  7. package/lib/classes/missing-config-error.js +7 -7
  8. package/lib/classes/multiple-config-sources-error.js +6 -6
  9. package/lib/classes/no-files-matched-error.js +8 -8
  10. package/lib/classes/read-file.js +25 -25
  11. package/lib/classes/remote-file-location.js +30 -30
  12. package/lib/classes/resolved-files.js +38 -46
  13. package/lib/classes/single-dest-multiple-source-error.js +9 -9
  14. package/lib/helpers/config-store.js +103 -103
  15. package/lib/helpers/get-defaults.js +24 -24
  16. package/lib/helpers/index.js +21 -21
  17. package/lib/helpers/local-assets.js +49 -49
  18. package/lib/helpers/path-slashes.js +8 -10
  19. package/lib/helpers/resolve-files.js +60 -65
  20. package/lib/helpers/type-slug.js +3 -3
  21. package/lib/helpers/type-title.js +4 -4
  22. package/lib/index.js +12 -12
  23. package/lib/schemas/assert.js +41 -41
  24. package/lib/schemas/index.js +7 -7
  25. package/lib/schemas/validate.js +64 -64
  26. package/lib/schemas/validation-error.js +11 -11
  27. package/lib/stream.js +11 -11
  28. package/lib/validators/index.js +37 -37
  29. package/package.json +14 -13
  30. package/types/classes/eik-config.d.ts +1 -1
  31. package/types/classes/file-mapping.d.ts +2 -2
  32. package/types/classes/invalid-config-error.d.ts +1 -1
  33. package/types/classes/missing-config-error.d.ts +1 -1
  34. package/types/classes/multiple-config-sources-error.d.ts +1 -1
  35. package/types/classes/no-files-matched-error.d.ts +1 -1
  36. package/types/classes/resolved-files.d.ts +1 -1
  37. package/types/classes/single-dest-multiple-source-error.d.ts +1 -1
  38. package/types/helpers/config-store.d.ts +1 -1
  39. package/types/helpers/index.d.ts +10 -10
  40. package/types/helpers/resolve-files.d.ts +1 -1
  41. package/types/index.d.ts +6 -6
  42. package/types/schemas/index.d.ts +3 -3
@@ -1,16 +1,16 @@
1
- import { readFileSync } from 'node:fs';
2
- import { join, dirname } from 'node:path';
3
- import formats from 'ajv-formats';
4
- import semver from 'semver';
5
- import npmPkg from 'validate-npm-package-name';
6
- import Ajv from 'ajv';
7
- import { fileURLToPath } from 'node:url';
1
+ import { readFileSync } from "node:fs";
2
+ import { join, dirname } from "node:path";
3
+ import formats from "ajv-formats";
4
+ import semver from "semver";
5
+ import npmPkg from "validate-npm-package-name";
6
+ import Ajv from "ajv";
7
+ import { fileURLToPath } from "node:url";
8
8
 
9
9
  const __filename = fileURLToPath(import.meta.url);
10
10
  const __dirname = dirname(__filename);
11
11
 
12
12
  const eikJSONSchema = JSON.parse(
13
- readFileSync(join(__dirname, './eikjson.schema.json'), 'utf8'),
13
+ readFileSync(join(__dirname, "./eikjson.schema.json"), "utf8"),
14
14
  );
15
15
 
16
16
  /**
@@ -32,17 +32,17 @@ const eikJSONSchema = JSON.parse(
32
32
  * @returns {SchemaValidator<T>}
33
33
  */
34
34
  const createValidator = (schema, ajvOptions) => {
35
- // @ts-ignore
36
- const ajv = new Ajv(ajvOptions);
37
- // @ts-ignore
38
- formats(ajv); // Needed to support "uri"
39
- const validate = ajv.compile(schema);
40
-
41
- return (data) => {
42
- const cloned = JSON.parse(JSON.stringify(data));
43
- const valid = validate(cloned);
44
- return { value: cloned, error: !valid && validate.errors };
45
- };
35
+ // @ts-ignore
36
+ const ajv = new Ajv(ajvOptions);
37
+ // @ts-ignore
38
+ formats(ajv); // Needed to support "uri"
39
+ const validate = ajv.compile(schema);
40
+
41
+ return (data) => {
42
+ const cloned = JSON.parse(JSON.stringify(data));
43
+ const valid = validate(cloned);
44
+ return { value: cloned, error: !valid && validate.errors };
45
+ };
46
46
  };
47
47
 
48
48
  /**
@@ -50,8 +50,8 @@ const createValidator = (schema, ajvOptions) => {
50
50
  * @type {SchemaValidator<import('../../eikjson.js').EikjsonSchema>}
51
51
  */
52
52
  const eikJSON = createValidator(eikJSONSchema, {
53
- removeAdditional: true,
54
- useDefaults: true,
53
+ removeAdditional: true,
54
+ useDefaults: true,
55
55
  });
56
56
 
57
57
  /**
@@ -59,26 +59,26 @@ const eikJSON = createValidator(eikJSONSchema, {
59
59
  * @returns {SchemaValidator<string>}
60
60
  */
61
61
  const createNameValidator = (jsonSchemaValidator) => (value) => {
62
- const result = jsonSchemaValidator(value);
63
- if (!result.error) {
64
- const pkvalid = npmPkg(value);
65
- /** @type {ErrorObject[]} */
66
- const errors = [];
67
- if (!pkvalid.validForNewPackages) {
68
- errors.push({
69
- keyword: 'validForNewPackages',
70
- instancePath: '.name',
71
- dataPath: '.name', // this was here before, but maybe replaced by instancePath?
72
- schemaPath: '',
73
- params: [],
74
- message: 'should be valid package name',
75
- });
76
- }
77
- if (errors.length) {
78
- result.error = errors;
79
- }
80
- }
81
- return result;
62
+ const result = jsonSchemaValidator(value);
63
+ if (!result.error) {
64
+ const pkvalid = npmPkg(value);
65
+ /** @type {ErrorObject[]} */
66
+ const errors = [];
67
+ if (!pkvalid.validForNewPackages) {
68
+ errors.push({
69
+ keyword: "validForNewPackages",
70
+ instancePath: ".name",
71
+ dataPath: ".name", // this was here before, but maybe replaced by instancePath?
72
+ schemaPath: "",
73
+ params: [],
74
+ message: "should be valid package name",
75
+ });
76
+ }
77
+ if (errors.length) {
78
+ result.error = errors;
79
+ }
80
+ }
81
+ return result;
82
82
  };
83
83
 
84
84
  /**
@@ -86,26 +86,26 @@ const createNameValidator = (jsonSchemaValidator) => (value) => {
86
86
  * @returns {SchemaValidator<string>}
87
87
  */
88
88
  const createVersionValidator = (jsonSchemaValidator) => (value) => {
89
- const result = jsonSchemaValidator(value);
90
- if (!result.error) {
91
- const version = semver.valid(value);
92
- /** @type {ErrorObject[]} */
93
- const errors = [];
94
- if (!version) {
95
- errors.push({
96
- keyword: 'invalidSemverRange',
97
- instancePath: '.version',
98
- dataPath: '.version',
99
- schemaPath: '',
100
- params: [],
101
- message: 'should be valid semver range for version',
102
- });
103
- }
104
- if (errors.length) {
105
- result.error = errors;
106
- }
107
- }
108
- return result;
89
+ const result = jsonSchemaValidator(value);
90
+ if (!result.error) {
91
+ const version = semver.valid(value);
92
+ /** @type {ErrorObject[]} */
93
+ const errors = [];
94
+ if (!version) {
95
+ errors.push({
96
+ keyword: "invalidSemverRange",
97
+ instancePath: ".version",
98
+ dataPath: ".version",
99
+ schemaPath: "",
100
+ params: [],
101
+ message: "should be valid semver range for version",
102
+ });
103
+ }
104
+ if (errors.length) {
105
+ result.error = errors;
106
+ }
107
+ }
108
+ return result;
109
109
  };
110
110
 
111
111
  /**
@@ -113,7 +113,7 @@ const createVersionValidator = (jsonSchemaValidator) => (value) => {
113
113
  * @type {SchemaValidator<string>}
114
114
  */
115
115
  const name = createNameValidator(
116
- createValidator(eikJSONSchema.properties.name),
116
+ createValidator(eikJSONSchema.properties.name),
117
117
  );
118
118
 
119
119
  /**
@@ -121,7 +121,7 @@ const name = createNameValidator(
121
121
  * @type {SchemaValidator<string>}
122
122
  */
123
123
  const version = createVersionValidator(
124
- createValidator(eikJSONSchema.properties.version),
124
+ createValidator(eikJSONSchema.properties.version),
125
125
  );
126
126
 
127
127
  /**
@@ -146,7 +146,7 @@ const files = createValidator(eikJSONSchema.properties.files);
146
146
  * Checks [import-map](https://eik.dev/docs/reference/eik-json#import-map)
147
147
  * @type {SchemaValidator<string | string[]>}
148
148
  */
149
- const importMap = createValidator(eikJSONSchema.properties['import-map']);
149
+ const importMap = createValidator(eikJSONSchema.properties["import-map"]);
150
150
 
151
151
  /**
152
152
  * Checks [out](https://eik.dev/docs/reference/eik-json#out)
@@ -1,16 +1,16 @@
1
1
  // @ts-check
2
2
 
3
3
  class ValidationError extends Error {
4
- /**
5
- * @param {string} message
6
- * @param {Error} err
7
- */
8
- constructor(message, err) {
9
- let m = message;
10
- if (err && err.message) m += `: ${err.message}`;
11
- super(m);
12
- this.name = this.constructor.name;
13
- Error.captureStackTrace(this, this.constructor);
14
- }
4
+ /**
5
+ * @param {string} message
6
+ * @param {Error} err
7
+ */
8
+ constructor(message, err) {
9
+ let m = message;
10
+ if (err && err.message) m += `: ${err.message}`;
11
+ super(m);
12
+ this.name = this.constructor.name;
13
+ Error.captureStackTrace(this, this.constructor);
14
+ }
15
15
  }
16
16
  export default ValidationError;
package/lib/stream.js CHANGED
@@ -4,10 +4,10 @@
4
4
  * @returns {boolean}
5
5
  */
6
6
  export const isStream = (stream) =>
7
- stream !== null &&
8
- typeof stream === 'object' &&
9
- // @ts-expect-error
10
- typeof stream.pipe === 'function';
7
+ stream !== null &&
8
+ typeof stream === "object" &&
9
+ // @ts-expect-error
10
+ typeof stream.pipe === "function";
11
11
 
12
12
  /**
13
13
  * Checks if the value is a {@link ReadableStream}
@@ -15,10 +15,10 @@ export const isStream = (stream) =>
15
15
  * @returns {boolean}
16
16
  */
17
17
  export const isReadableStream = (stream) =>
18
- isStream(stream) &&
19
- // @ts-expect-error
20
- stream.readable !== false &&
21
- // @ts-expect-error
22
- typeof stream._read === 'function' &&
23
- // @ts-expect-error
24
- typeof stream._readableState === 'object';
18
+ isStream(stream) &&
19
+ // @ts-expect-error
20
+ stream.readable !== false &&
21
+ // @ts-expect-error
22
+ typeof stream._read === "function" &&
23
+ // @ts-expect-error
24
+ typeof stream._readableState === "object";
@@ -1,5 +1,5 @@
1
- import semver from 'semver';
2
- import npmPkg from 'validate-npm-package-name';
1
+ import semver from "semver";
2
+ import npmPkg from "validate-npm-package-name";
3
3
 
4
4
  const urlIsh = /^https?:\/\/[a-zA-Z0-9-_./]+(:[0-9]+)?/;
5
5
 
@@ -10,10 +10,10 @@ const urlIsh = /^https?:\/\/[a-zA-Z0-9-_./]+(:[0-9]+)?/;
10
10
  * @throws {Error} if the parameter does not match a URL pattern
11
11
  */
12
12
  export const origin = (value) => {
13
- if (urlIsh.test(value)) {
14
- return value.toLowerCase();
15
- }
16
- throw new Error('Parameter "origin" is not valid');
13
+ if (urlIsh.test(value)) {
14
+ return value.toLowerCase();
15
+ }
16
+ throw new Error('Parameter "origin" is not valid');
17
17
  };
18
18
 
19
19
  /**
@@ -23,10 +23,10 @@ export const origin = (value) => {
23
23
  * @throws {Error} if the value is not a valid organisation name
24
24
  */
25
25
  export const org = (value) => {
26
- if (/^[a-zA-Z0-9_-]+$/.test(value)) {
27
- return value.toLowerCase();
28
- }
29
- throw new Error(`Parameter "org" is not valid - Value: ${value}`);
26
+ if (/^[a-zA-Z0-9_-]+$/.test(value)) {
27
+ return value.toLowerCase();
28
+ }
29
+ throw new Error(`Parameter "org" is not valid - Value: ${value}`);
30
30
  };
31
31
 
32
32
  /**
@@ -36,11 +36,11 @@ export const org = (value) => {
36
36
  * @throws {Error} if the value is not a valid package name
37
37
  */
38
38
  export const name = (value) => {
39
- const result = npmPkg(value);
40
- if (result.validForNewPackages || result.validForOldPackages) {
41
- return value.toLowerCase();
42
- }
43
- throw new Error(`Parameter "name" is not valid - Value: ${value}`);
39
+ const result = npmPkg(value);
40
+ if (result.validForNewPackages || result.validForOldPackages) {
41
+ return value.toLowerCase();
42
+ }
43
+ throw new Error(`Parameter "name" is not valid - Value: ${value}`);
44
44
  };
45
45
 
46
46
  /**
@@ -50,11 +50,11 @@ export const name = (value) => {
50
50
  * @throws {Error} if the value is not a valid semver version
51
51
  */
52
52
  export const version = (value) => {
53
- const result = semver.valid(value);
54
- if (result) {
55
- return result;
56
- }
57
- throw new Error(`Parameter "version" is not valid - Value: ${value}`);
53
+ const result = semver.valid(value);
54
+ if (result) {
55
+ return result;
56
+ }
57
+ throw new Error(`Parameter "version" is not valid - Value: ${value}`);
58
58
  };
59
59
 
60
60
  /**
@@ -64,10 +64,10 @@ export const version = (value) => {
64
64
  * @throws {Error} if the value is not a valid alias value
65
65
  */
66
66
  export const alias = (value) => {
67
- if (/^[0-9]+$/.test(value)) {
68
- return value;
69
- }
70
- throw new Error(`Parameter "alias" is not valid - Value: ${value}`);
67
+ if (/^[0-9]+$/.test(value)) {
68
+ return value;
69
+ }
70
+ throw new Error(`Parameter "alias" is not valid - Value: ${value}`);
71
71
  };
72
72
 
73
73
  /**
@@ -77,15 +77,15 @@ export const alias = (value) => {
77
77
  * @throws {Error} if the value is not a valid Eik package type
78
78
  */
79
79
  export const type = (value) => {
80
- if (
81
- value === 'pkg' ||
82
- value === 'map' ||
83
- value === 'npm' ||
84
- value === 'img'
85
- ) {
86
- return value;
87
- }
88
- throw new Error(`Parameter "type" is not valid - Value: ${value}`);
80
+ if (
81
+ value === "pkg" ||
82
+ value === "map" ||
83
+ value === "npm" ||
84
+ value === "img"
85
+ ) {
86
+ return value;
87
+ }
88
+ throw new Error(`Parameter "type" is not valid - Value: ${value}`);
89
89
  };
90
90
 
91
91
  /**
@@ -104,8 +104,8 @@ export const extra = (value) => value;
104
104
  * @throws {Error} if the value is not a valid semver type
105
105
  */
106
106
  export const semverType = (value) => {
107
- if (value === 'major' || value === 'minor' || value === 'patch') {
108
- return value;
109
- }
110
- throw new Error(`Parameter "semverType" is not valid - Value: ${value}`);
107
+ if (value === "major" || value === "minor" || value === "patch") {
108
+ return value;
109
+ }
110
+ throw new Error(`Parameter "semverType" is not valid - Value: ${value}`);
111
111
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eik/common",
3
- "version": "4.1.1",
3
+ "version": "5.0.0",
4
4
  "description": "Common utilities for Eik modules",
5
5
  "main": "lib/index.js",
6
6
  "types": "types/index.d.ts",
@@ -41,30 +41,31 @@
41
41
  "is-glob": "4.0.3",
42
42
  "mime-types": "2.1.35",
43
43
  "semver": "7.6.3",
44
- "validate-npm-package-name": "5.0.1"
44
+ "validate-npm-package-name": "6.0.0"
45
45
  },
46
46
  "devDependencies": {
47
- "@babel/plugin-syntax-import-assertions": "7.24.7",
48
- "@eik/eslint-config": "1.0.2",
47
+ "@babel/plugin-syntax-import-assertions": "7.26.0",
48
+ "@eik/eslint-config": "1.0.5",
49
+ "@eik/prettier-config": "1.0.1",
49
50
  "@eik/semantic-release-config": "1.0.0",
50
51
  "@eik/typescript-config": "1.0.0",
51
- "@hapi/hapi": "21.3.10",
52
+ "@hapi/hapi": "21.3.12",
52
53
  "@semantic-release/changelog": "6.0.3",
53
54
  "@semantic-release/git": "10.0.1",
54
55
  "@types/glob": "8.1.0",
55
56
  "@types/is-glob": "4.0.4",
56
57
  "@types/semver": "7.5.8",
57
58
  "@types/validate-npm-package-name": "4.0.2",
58
- "eslint": "9.8.0",
59
- "express": "4.19.2",
60
- "fastify": "4.28.1",
61
- "json-schema-to-typescript": "15.0.0",
62
- "npm-run-all": "4.1.5",
59
+ "eslint": "9.14.0",
60
+ "express": "4.21.1",
61
+ "fastify": "5.1.0",
62
+ "json-schema-to-typescript": "15.0.3",
63
+ "npm-run-all2": "7.0.1",
63
64
  "prettier": "3.3.3",
64
65
  "rimraf": "6.0.1",
65
- "semantic-release": "24.0.0",
66
+ "semantic-release": "24.2.0",
66
67
  "stoppable": "1.1.0",
67
- "tap": "21.0.0",
68
- "typescript": "5.5.4"
68
+ "tap": "21.0.1",
69
+ "typescript": "5.6.3"
69
70
  }
70
71
  }
@@ -57,7 +57,7 @@ export default class EikConfig {
57
57
  [_tokens]: Map<string, string>;
58
58
  }
59
59
  export type EikjsonSchema = import("../../eikjson.js").EikjsonSchema;
60
- import FileMapping from './file-mapping.js';
60
+ import FileMapping from "./file-mapping.js";
61
61
  declare const _config: unique symbol;
62
62
  declare const _tokens: unique symbol;
63
63
  export {};
@@ -17,5 +17,5 @@ declare class FileMapping {
17
17
  */
18
18
  destination: RemoteFileLocation;
19
19
  }
20
- import LocalFileLocation from './local-file-location.js';
21
- import RemoteFileLocation from './remote-file-location.js';
20
+ import LocalFileLocation from "./local-file-location.js";
21
+ import RemoteFileLocation from "./remote-file-location.js";
@@ -1,3 +1,3 @@
1
1
  export default class InvalidConfigError extends CustomError {
2
2
  }
3
- import CustomError from './custom-error.js';
3
+ import CustomError from "./custom-error.js";
@@ -1,3 +1,3 @@
1
1
  export default class MissingConfigError extends CustomError {
2
2
  }
3
- import CustomError from './custom-error.js';
3
+ import CustomError from "./custom-error.js";
@@ -1,4 +1,4 @@
1
1
  export default class MultipleConfigSourcesError extends CustomError {
2
2
  constructor();
3
3
  }
4
- import CustomError from './custom-error.js';
4
+ import CustomError from "./custom-error.js";
@@ -1,3 +1,3 @@
1
1
  export default class NoFilesMatchedError extends CustomError {
2
2
  }
3
- import CustomError from './custom-error.js';
3
+ import CustomError from "./custom-error.js";
@@ -16,5 +16,5 @@ declare class ResolvedFiles {
16
16
  [Symbol.iterator](): Generator<LocalFileLocation, void, unknown>;
17
17
  [originalFiles]: string[];
18
18
  }
19
- import LocalFileLocation from './local-file-location.js';
19
+ import LocalFileLocation from "./local-file-location.js";
20
20
  declare const originalFiles: unique symbol;
@@ -1,3 +1,3 @@
1
1
  export default class SingleDestMultipleSourcesError extends CustomError {
2
2
  }
3
- import CustomError from './custom-error.js';
3
+ import CustomError from "./custom-error.js";
@@ -25,4 +25,4 @@ declare namespace _default {
25
25
  function persistToDisk(config: typeof import("../classes/eik-config.js")): void;
26
26
  }
27
27
  export default _default;
28
- import EikConfig from '../classes/eik-config.js';
28
+ import EikConfig from "../classes/eik-config.js";
@@ -11,13 +11,13 @@ declare namespace _default {
11
11
  export { resolveFiles };
12
12
  }
13
13
  export default _default;
14
- import localAssets from './local-assets.js';
15
- import getDefaults from './get-defaults.js';
16
- import configStore from './config-store.js';
17
- import typeSlug from './type-slug.js';
18
- import typeTitle from './type-title.js';
19
- import { addTrailingSlash } from './path-slashes.js';
20
- import { removeTrailingSlash } from './path-slashes.js';
21
- import { addLeadingSlash } from './path-slashes.js';
22
- import { removeLeadingSlash } from './path-slashes.js';
23
- import resolveFiles from './resolve-files.js';
14
+ import localAssets from "./local-assets.js";
15
+ import getDefaults from "./get-defaults.js";
16
+ import configStore from "./config-store.js";
17
+ import typeSlug from "./type-slug.js";
18
+ import typeTitle from "./type-title.js";
19
+ import { addTrailingSlash } from "./path-slashes.js";
20
+ import { removeTrailingSlash } from "./path-slashes.js";
21
+ import { addLeadingSlash } from "./path-slashes.js";
22
+ import { removeLeadingSlash } from "./path-slashes.js";
23
+ import resolveFiles from "./resolve-files.js";
@@ -10,4 +10,4 @@ export default resolveFiles;
10
10
  declare function resolveFiles(files: {
11
11
  [k: string]: string;
12
12
  }, cwd: string): Promise<ResolvedFiles[]>;
13
- import ResolvedFiles from '../classes/resolved-files.js';
13
+ import ResolvedFiles from "../classes/resolved-files.js";
package/types/index.d.ts CHANGED
@@ -7,10 +7,10 @@ declare namespace _default {
7
7
  export { helpers };
8
8
  }
9
9
  export default _default;
10
- import * as validators from './validators/index.js';
11
- import ReadFile from './classes/read-file.js';
12
- import EikConfig from './classes/eik-config.js';
13
- import schemas from './schemas/index.js';
14
- import * as stream from './stream.js';
15
- import helpers from './helpers/index.js';
10
+ import * as validators from "./validators/index.js";
11
+ import ReadFile from "./classes/read-file.js";
12
+ import EikConfig from "./classes/eik-config.js";
13
+ import schemas from "./schemas/index.js";
14
+ import * as stream from "./stream.js";
15
+ import helpers from "./helpers/index.js";
16
16
  export { validators, ReadFile, EikConfig, schemas, stream, helpers };
@@ -6,6 +6,6 @@ declare namespace _default {
6
6
  }
7
7
  export default _default;
8
8
  declare const schema: any;
9
- import * as validate from './validate.js';
10
- import assert from './assert.js';
11
- import ValidationError from './validation-error.js';
9
+ import * as validate from "./validate.js";
10
+ import assert from "./assert.js";
11
+ import ValidationError from "./validation-error.js";