@c-time/frelio-dependency-map 1.1.0 → 1.2.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/dist/index.d.ts CHANGED
@@ -1,32 +1,115 @@
1
+ export { FrelioDependencyMapSchema, dependencyMapSchema } from './schema.js';
2
+
1
3
  /**
2
- * frelio-dependency-map
4
+ * Dependency Map type definitions
3
5
  *
4
- * Type definitions and utilities for frelio dependency map files.
6
+ * A dependency map tracks which source files affect each output file,
7
+ * enabling incremental/differential builds.
8
+ */
9
+ /**
10
+ * Output path pattern (e.g., "/articles/{slug}.json", "/articles/index.json")
11
+ * Can include template variables like {slug}, {page}, etc.
12
+ */
13
+ type OutputPath = string;
14
+ /**
15
+ * Dependency path pattern
16
+ * Examples: "contents/*/article/*", "templates/article/detail.html"
17
+ * Can include glob patterns for matching multiple files.
5
18
  *
6
- * @example
7
- * ```typescript
8
- * import {
9
- * FrelioDependencyMap,
10
- * isFrelioDependencyMap,
11
- * validateFrelioDependencyMap,
12
- * findAffectedOutputs
13
- * } from 'frelio-dependency-map'
19
+ * Common prefixes:
20
+ * - content_types/ - Content type definitions
21
+ * - templates/ - Template files
22
+ * - contents/ - Content data files (often with glob patterns)
23
+ */
24
+ type DependencyPath = string;
25
+ /**
26
+ * Dependency Map
14
27
  *
15
- * // Load and validate a dependency map
16
- * const data = JSON.parse(fs.readFileSync('_dependency-map.json', 'utf-8'))
28
+ * Maps output file paths to arrays of dependency paths.
29
+ * Used by the builder for incremental builds - when any dependency changes,
30
+ * the corresponding output files need to be regenerated.
17
31
  *
18
- * if (isFrelioDependencyMap(data)) {
19
- * // Type-safe access
20
- * const affected = findAffectedOutputs(data, 'contents/published/article/my-post.json')
21
- * console.log('Affected outputs:', affected)
32
+ * Example:
33
+ * ```
34
+ * {
35
+ * "/articles/{slug}.json": [
36
+ * "content_types/article",
37
+ * "templates/article/detail.html",
38
+ * "contents/*/article/*"
39
+ * ]
22
40
  * }
23
41
  * ```
24
- *
25
- * @packageDocumentation
26
- */
27
- export type { FrelioDependencyMap, OutputPath, DependencyPath, DependencyPathPrefix, ValidationResult, ValidationError, } from './types.js';
28
- export { DEPENDENCY_PATH_PREFIXES } from './types.js';
29
- export { dependencyMapSchema } from './schema.js';
30
- export type { FrelioDependencyMapSchema } from './schema.js';
31
- export { isFrelioDependencyMap, validateFrelioDependencyMap } from './guards.js';
32
- export { getDependencyPaths, getOutputPaths, getAllDependencyPaths, mergeFrelioDependencyMaps, findAffectedOutputs, createFrelioDependencyMap, setDependencies, removeDependencies, } from './utils.js';
42
+ */
43
+ type FrelioDependencyMap = {
44
+ [outputPath: OutputPath]: DependencyPath[];
45
+ };
46
+ /**
47
+ * Common dependency path prefixes used in frelio projects
48
+ */
49
+ declare const DEPENDENCY_PATH_PREFIXES: {
50
+ /** Content type schema definitions */
51
+ readonly CONTENT_TYPES: "content_types/";
52
+ /** Template files */
53
+ readonly TEMPLATES: "templates/";
54
+ /** Content data files */
55
+ readonly CONTENTS: "contents/";
56
+ };
57
+ type DependencyPathPrefix = (typeof DEPENDENCY_PATH_PREFIXES)[keyof typeof DEPENDENCY_PATH_PREFIXES];
58
+ /**
59
+ * Result of validation operations
60
+ */
61
+ type ValidationResult = {
62
+ valid: boolean;
63
+ errors: ValidationError[];
64
+ };
65
+ type ValidationError = {
66
+ path: string;
67
+ message: string;
68
+ };
69
+
70
+ /**
71
+ * Type guard to check if a value is a valid FrelioDependencyMap
72
+ */
73
+ declare function isFrelioDependencyMap(value: unknown): value is FrelioDependencyMap;
74
+ /**
75
+ * Validates a value as a FrelioDependencyMap and returns detailed errors
76
+ */
77
+ declare function validateFrelioDependencyMap(value: unknown): ValidationResult;
78
+
79
+ /**
80
+ * Gets the dependency paths for a specific output path
81
+ * Returns an empty array if the output path is not found
82
+ */
83
+ declare function getDependencyPaths(map: FrelioDependencyMap, outputPath: OutputPath): DependencyPath[];
84
+ /**
85
+ * Gets all output paths defined in the dependency map
86
+ */
87
+ declare function getOutputPaths(map: FrelioDependencyMap): OutputPath[];
88
+ /**
89
+ * Gets all unique dependency paths across all outputs
90
+ */
91
+ declare function getAllDependencyPaths(map: FrelioDependencyMap): DependencyPath[];
92
+ /**
93
+ * Merges multiple dependency maps into one
94
+ * Later maps override earlier ones for the same output path
95
+ */
96
+ declare function mergeFrelioDependencyMaps(...maps: FrelioDependencyMap[]): FrelioDependencyMap;
97
+ /**
98
+ * Finds all output paths that depend on a given dependency path
99
+ * Supports exact match and simple glob pattern matching
100
+ */
101
+ declare function findAffectedOutputs(map: FrelioDependencyMap, changedPath: DependencyPath): OutputPath[];
102
+ /**
103
+ * Creates an empty dependency map
104
+ */
105
+ declare function createFrelioDependencyMap(): FrelioDependencyMap;
106
+ /**
107
+ * Adds or updates dependencies for an output path
108
+ */
109
+ declare function setDependencies(map: FrelioDependencyMap, outputPath: OutputPath, dependencies: DependencyPath[]): FrelioDependencyMap;
110
+ /**
111
+ * Removes an output path from the dependency map
112
+ */
113
+ declare function removeDependencies(map: FrelioDependencyMap, outputPath: OutputPath): FrelioDependencyMap;
114
+
115
+ export { DEPENDENCY_PATH_PREFIXES, type DependencyPath, type DependencyPathPrefix, type FrelioDependencyMap, type OutputPath, type ValidationError, type ValidationResult, createFrelioDependencyMap, findAffectedOutputs, getAllDependencyPaths, getDependencyPaths, getOutputPaths, isFrelioDependencyMap, mergeFrelioDependencyMaps, removeDependencies, setDependencies, validateFrelioDependencyMap };
package/dist/index.js CHANGED
@@ -1,33 +1,171 @@
1
- /**
2
- * frelio-dependency-map
3
- *
4
- * Type definitions and utilities for frelio dependency map files.
5
- *
6
- * @example
7
- * ```typescript
8
- * import {
9
- * FrelioDependencyMap,
10
- * isFrelioDependencyMap,
11
- * validateFrelioDependencyMap,
12
- * findAffectedOutputs
13
- * } from 'frelio-dependency-map'
14
- *
15
- * // Load and validate a dependency map
16
- * const data = JSON.parse(fs.readFileSync('_dependency-map.json', 'utf-8'))
17
- *
18
- * if (isFrelioDependencyMap(data)) {
19
- * // Type-safe access
20
- * const affected = findAffectedOutputs(data, 'contents/published/article/my-post.json')
21
- * console.log('Affected outputs:', affected)
22
- * }
23
- * ```
24
- *
25
- * @packageDocumentation
26
- */
27
- export { DEPENDENCY_PATH_PREFIXES } from './types.js';
28
- // Schema
29
- export { dependencyMapSchema } from './schema.js';
30
- // Type guards & validation
31
- export { isFrelioDependencyMap, validateFrelioDependencyMap } from './guards.js';
32
- // Utilities
33
- export { getDependencyPaths, getOutputPaths, getAllDependencyPaths, mergeFrelioDependencyMaps, findAffectedOutputs, createFrelioDependencyMap, setDependencies, removeDependencies, } from './utils.js';
1
+ // src/types.ts
2
+ var DEPENDENCY_PATH_PREFIXES = {
3
+ /** Content type schema definitions */
4
+ CONTENT_TYPES: "content_types/",
5
+ /** Template files */
6
+ TEMPLATES: "templates/",
7
+ /** Content data files */
8
+ CONTENTS: "contents/"
9
+ };
10
+
11
+ // src/schema.ts
12
+ var dependencyMapSchema = {
13
+ $schema: "http://json-schema.org/draft-07/schema#",
14
+ title: "FrelioDependencyMap",
15
+ description: "Maps output file paths to arrays of dependency paths for incremental builds",
16
+ type: "object",
17
+ additionalProperties: {
18
+ type: "array",
19
+ items: {
20
+ type: "string",
21
+ minLength: 1
22
+ },
23
+ description: "Array of dependency paths (glob patterns allowed)"
24
+ },
25
+ examples: [
26
+ {
27
+ "/articles/{slug}.json": [
28
+ "content_types/article",
29
+ "templates/article/detail.html",
30
+ "contents/*/article/*"
31
+ ],
32
+ "/articles/index.json": [
33
+ "content_types/article",
34
+ "templates/article/list.html",
35
+ "contents/*/article/*"
36
+ ]
37
+ }
38
+ ]
39
+ };
40
+
41
+ // src/guards.ts
42
+ function isFrelioDependencyMap(value) {
43
+ if (value === null || typeof value !== "object") {
44
+ return false;
45
+ }
46
+ const obj = value;
47
+ for (const [key, val] of Object.entries(obj)) {
48
+ if (typeof key !== "string" || key.length === 0) {
49
+ return false;
50
+ }
51
+ if (!Array.isArray(val)) {
52
+ return false;
53
+ }
54
+ for (const item of val) {
55
+ if (typeof item !== "string") {
56
+ return false;
57
+ }
58
+ }
59
+ }
60
+ return true;
61
+ }
62
+ function validateFrelioDependencyMap(value) {
63
+ const errors = [];
64
+ if (value === null) {
65
+ errors.push({ path: "", message: "Value is null" });
66
+ return { valid: false, errors };
67
+ }
68
+ if (typeof value !== "object") {
69
+ errors.push({ path: "", message: `Expected object, got ${typeof value}` });
70
+ return { valid: false, errors };
71
+ }
72
+ const obj = value;
73
+ for (const [key, val] of Object.entries(obj)) {
74
+ if (typeof key !== "string" || key.length === 0) {
75
+ errors.push({
76
+ path: key,
77
+ message: "Output path must be a non-empty string"
78
+ });
79
+ continue;
80
+ }
81
+ if (!Array.isArray(val)) {
82
+ errors.push({
83
+ path: key,
84
+ message: `Expected array of dependencies, got ${typeof val}`
85
+ });
86
+ continue;
87
+ }
88
+ for (let i = 0; i < val.length; i++) {
89
+ const item = val[i];
90
+ if (typeof item !== "string") {
91
+ errors.push({
92
+ path: `${key}[${i}]`,
93
+ message: `Expected string dependency path, got ${typeof item}`
94
+ });
95
+ } else if (item.length === 0) {
96
+ errors.push({
97
+ path: `${key}[${i}]`,
98
+ message: "Dependency path cannot be empty"
99
+ });
100
+ }
101
+ }
102
+ }
103
+ return { valid: errors.length === 0, errors };
104
+ }
105
+
106
+ // src/utils.ts
107
+ function getDependencyPaths(map, outputPath) {
108
+ return map[outputPath] ?? [];
109
+ }
110
+ function getOutputPaths(map) {
111
+ return Object.keys(map);
112
+ }
113
+ function getAllDependencyPaths(map) {
114
+ const allPaths = /* @__PURE__ */ new Set();
115
+ for (const paths of Object.values(map)) {
116
+ for (const path of paths) {
117
+ allPaths.add(path);
118
+ }
119
+ }
120
+ return Array.from(allPaths).sort();
121
+ }
122
+ function mergeFrelioDependencyMaps(...maps) {
123
+ const result = {};
124
+ for (const map of maps) {
125
+ for (const [outputPath, deps] of Object.entries(map)) {
126
+ result[outputPath] = [...deps];
127
+ }
128
+ }
129
+ return result;
130
+ }
131
+ function findAffectedOutputs(map, changedPath) {
132
+ const affected = [];
133
+ for (const [outputPath, deps] of Object.entries(map)) {
134
+ for (const dep of deps) {
135
+ if (matchesDependencyPath(dep, changedPath)) {
136
+ affected.push(outputPath);
137
+ break;
138
+ }
139
+ }
140
+ }
141
+ return affected;
142
+ }
143
+ function matchesDependencyPath(pattern, path) {
144
+ if (pattern === path) {
145
+ return true;
146
+ }
147
+ const regexPattern = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, "[^/]*");
148
+ try {
149
+ const regex = new RegExp(`^${regexPattern}$`);
150
+ return regex.test(path);
151
+ } catch {
152
+ return pattern === path;
153
+ }
154
+ }
155
+ function createFrelioDependencyMap() {
156
+ return {};
157
+ }
158
+ function setDependencies(map, outputPath, dependencies) {
159
+ return {
160
+ ...map,
161
+ [outputPath]: [...dependencies]
162
+ };
163
+ }
164
+ function removeDependencies(map, outputPath) {
165
+ const { [outputPath]: _, ...rest } = map;
166
+ return rest;
167
+ }
168
+
169
+ export { DEPENDENCY_PATH_PREFIXES, createFrelioDependencyMap, dependencyMapSchema, findAffectedOutputs, getAllDependencyPaths, getDependencyPaths, getOutputPaths, isFrelioDependencyMap, mergeFrelioDependencyMaps, removeDependencies, setDependencies, validateFrelioDependencyMap };
170
+ //# sourceMappingURL=index.js.map
171
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types.ts","../src/schema.ts","../src/guards.ts","../src/utils.ts"],"names":[],"mappings":";AAkDO,IAAM,wBAAA,GAA2B;AAAA;AAAA,EAEtC,aAAA,EAAe,gBAAA;AAAA;AAAA,EAEf,SAAA,EAAW,YAAA;AAAA;AAAA,EAEX,QAAA,EAAU;AACZ;;;ACrDO,IAAM,mBAAA,GAAsB;AAAA,EACjC,OAAA,EAAS,yCAAA;AAAA,EACT,KAAA,EAAO,qBAAA;AAAA,EACP,WAAA,EACE,6EAAA;AAAA,EACF,IAAA,EAAM,QAAA;AAAA,EACN,oBAAA,EAA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,EAAA,OAAO,IAAA;AACT","file":"index.js","sourcesContent":["/**\n * Dependency Map type definitions\n *\n * A dependency map tracks which source files affect each output file,\n * enabling incremental/differential builds.\n */\n\n/**\n * Output path pattern (e.g., \"/articles/{slug}.json\", \"/articles/index.json\")\n * Can include template variables like {slug}, {page}, etc.\n */\nexport type OutputPath = string\n\n/**\n * Dependency path pattern\n * Examples: \"contents/&#42;/article/&#42;\", \"templates/article/detail.html\"\n * Can include glob patterns for matching multiple files.\n *\n * Common prefixes:\n * - content_types/ - Content type definitions\n * - templates/ - Template files\n * - contents/ - Content data files (often with glob patterns)\n */\nexport type DependencyPath = string\n\n/**\n * Dependency Map\n *\n * Maps output file paths to arrays of dependency paths.\n * Used by the builder for incremental builds - when any dependency changes,\n * the corresponding output files need to be regenerated.\n *\n * Example:\n * ```\n * {\n * \"/articles/{slug}.json\": [\n * \"content_types/article\",\n * \"templates/article/detail.html\",\n * \"contents/&#42;/article/&#42;\"\n * ]\n * }\n * ```\n */\nexport type FrelioDependencyMap = {\n [outputPath: OutputPath]: DependencyPath[]\n}\n\n/**\n * Common dependency path prefixes used in frelio projects\n */\nexport const DEPENDENCY_PATH_PREFIXES = {\n /** Content type schema definitions */\n CONTENT_TYPES: 'content_types/',\n /** Template files */\n TEMPLATES: 'templates/',\n /** Content data files */\n CONTENTS: 'contents/',\n} as const\n\nexport type DependencyPathPrefix =\n (typeof DEPENDENCY_PATH_PREFIXES)[keyof typeof DEPENDENCY_PATH_PREFIXES]\n\n/**\n * Result of validation operations\n */\nexport type ValidationResult = {\n valid: boolean\n errors: ValidationError[]\n}\n\nexport type ValidationError = {\n path: string\n message: string\n}\n","/**\n * JSON Schema for FrelioDependencyMap validation\n */\n\nexport const dependencyMapSchema = {\n $schema: 'http://json-schema.org/draft-07/schema#',\n title: 'FrelioDependencyMap',\n description:\n 'Maps output file paths to arrays of dependency paths for incremental builds',\n type: 'object',\n additionalProperties: {\n type: 'array',\n items: {\n type: 'string',\n minLength: 1,\n },\n description: 'Array of dependency paths (glob patterns allowed)',\n },\n examples: [\n {\n '/articles/{slug}.json': [\n 'content_types/article',\n 'templates/article/detail.html',\n 'contents/*/article/*',\n ],\n '/articles/index.json': [\n 'content_types/article',\n 'templates/article/list.html',\n 'contents/*/article/*',\n ],\n },\n ],\n} as const\n\nexport type FrelioDependencyMapSchema = typeof dependencyMapSchema\n","import type { FrelioDependencyMap, ValidationResult, ValidationError } from './types.js'\n\n/**\n * Type guard to check if a value is a valid FrelioDependencyMap\n */\nexport function isFrelioDependencyMap(value: unknown): value is FrelioDependencyMap {\n if (value === null || typeof value !== 'object') {\n return false\n }\n\n const obj = value as Record<string, unknown>\n\n for (const [key, val] of Object.entries(obj)) {\n // Key must be a non-empty string\n if (typeof key !== 'string' || key.length === 0) {\n return false\n }\n\n // Value must be an array of strings\n if (!Array.isArray(val)) {\n return false\n }\n\n for (const item of val) {\n if (typeof item !== 'string') {\n return false\n }\n }\n }\n\n return true\n}\n\n/**\n * Validates a value as a FrelioDependencyMap and returns detailed errors\n */\nexport function validateFrelioDependencyMap(value: unknown): ValidationResult {\n const errors: ValidationError[] = []\n\n if (value === null) {\n errors.push({ path: '', message: 'Value is null' })\n return { valid: false, errors }\n }\n\n if (typeof value !== 'object') {\n errors.push({ path: '', message: `Expected object, got ${typeof value}` })\n return { valid: false, errors }\n }\n\n const obj = value as Record<string, unknown>\n\n for (const [key, val] of Object.entries(obj)) {\n if (typeof key !== 'string' || key.length === 0) {\n errors.push({\n path: key,\n message: 'Output path must be a non-empty string',\n })\n continue\n }\n\n if (!Array.isArray(val)) {\n errors.push({\n path: key,\n message: `Expected array of dependencies, got ${typeof val}`,\n })\n continue\n }\n\n for (let i = 0; i < val.length; i++) {\n const item = val[i]\n if (typeof item !== 'string') {\n errors.push({\n path: `${key}[${i}]`,\n message: `Expected string dependency path, got ${typeof item}`,\n })\n } else if (item.length === 0) {\n errors.push({\n path: `${key}[${i}]`,\n message: 'Dependency path cannot be empty',\n })\n }\n }\n }\n\n return { valid: errors.length === 0, errors }\n}\n","import type { FrelioDependencyMap, DependencyPath, OutputPath } from './types.js'\n\n/**\n * Gets the dependency paths for a specific output path\n * Returns an empty array if the output path is not found\n */\nexport function getDependencyPaths(\n map: FrelioDependencyMap,\n outputPath: OutputPath\n): DependencyPath[] {\n return map[outputPath] ?? []\n}\n\n/**\n * Gets all output paths defined in the dependency map\n */\nexport function getOutputPaths(map: FrelioDependencyMap): OutputPath[] {\n return Object.keys(map)\n}\n\n/**\n * Gets all unique dependency paths across all outputs\n */\nexport function getAllDependencyPaths(map: FrelioDependencyMap): DependencyPath[] {\n const allPaths = new Set<DependencyPath>()\n for (const paths of Object.values(map)) {\n for (const path of paths) {\n allPaths.add(path)\n }\n }\n return Array.from(allPaths).sort()\n}\n\n/**\n * Merges multiple dependency maps into one\n * Later maps override earlier ones for the same output path\n */\nexport function mergeFrelioDependencyMaps(...maps: FrelioDependencyMap[]): FrelioDependencyMap {\n const result: FrelioDependencyMap = {}\n for (const map of maps) {\n for (const [outputPath, deps] of Object.entries(map)) {\n result[outputPath] = [...deps]\n }\n }\n return result\n}\n\n/**\n * Finds all output paths that depend on a given dependency path\n * Supports exact match and simple glob pattern matching\n */\nexport function findAffectedOutputs(\n map: FrelioDependencyMap,\n changedPath: DependencyPath\n): OutputPath[] {\n const affected: OutputPath[] = []\n\n for (const [outputPath, deps] of Object.entries(map)) {\n for (const dep of deps) {\n if (matchesDependencyPath(dep, changedPath)) {\n affected.push(outputPath)\n break\n }\n }\n }\n\n return affected\n}\n\n/**\n * Checks if a dependency pattern matches a given path\n * Supports * as a wildcard for any single path segment\n */\nfunction matchesDependencyPath(pattern: DependencyPath, path: string): boolean {\n // Exact match\n if (pattern === path) {\n return true\n }\n\n // Convert glob pattern to regex\n // * matches any characters except /\n const regexPattern = pattern\n .replace(/[.+?^${}()|[\\]\\\\]/g, '\\\\$&') // Escape special regex chars\n .replace(/\\*/g, '[^/]*') // * matches any segment\n\n try {\n const regex = new RegExp(`^${regexPattern}$`)\n return regex.test(path)\n } catch {\n // If regex compilation fails, fall back to exact match\n return pattern === path\n }\n}\n\n/**\n * Creates an empty dependency map\n */\nexport function createFrelioDependencyMap(): FrelioDependencyMap {\n return {}\n}\n\n/**\n * Adds or updates dependencies for an output path\n */\nexport function setDependencies(\n map: FrelioDependencyMap,\n outputPath: OutputPath,\n dependencies: DependencyPath[]\n): FrelioDependencyMap {\n return {\n ...map,\n [outputPath]: [...dependencies],\n }\n}\n\n/**\n * Removes an output path from the dependency map\n */\nexport function removeDependencies(\n map: FrelioDependencyMap,\n outputPath: OutputPath\n): FrelioDependencyMap {\n const { [outputPath]: _, ...rest } = map\n return rest\n}\n"]}
package/dist/schema.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * JSON Schema for FrelioDependencyMap validation
3
3
  */
4
- export declare const dependencyMapSchema: {
4
+ declare const dependencyMapSchema: {
5
5
  readonly $schema: "http://json-schema.org/draft-07/schema#";
6
6
  readonly title: "FrelioDependencyMap";
7
7
  readonly description: "Maps output file paths to arrays of dependency paths for incremental builds";
@@ -19,4 +19,6 @@ export declare const dependencyMapSchema: {
19
19
  readonly '/articles/index.json': readonly ["content_types/article", "templates/article/list.html", "contents/*/article/*"];
20
20
  }];
21
21
  };
22
- export type FrelioDependencyMapSchema = typeof dependencyMapSchema;
22
+ type FrelioDependencyMapSchema = typeof dependencyMapSchema;
23
+
24
+ export { type FrelioDependencyMapSchema, dependencyMapSchema };
package/dist/schema.js CHANGED
@@ -1,31 +1,33 @@
1
- /**
2
- * JSON Schema for FrelioDependencyMap validation
3
- */
4
- export const dependencyMapSchema = {
5
- $schema: 'http://json-schema.org/draft-07/schema#',
6
- title: 'FrelioDependencyMap',
7
- description: 'Maps output file paths to arrays of dependency paths for incremental builds',
8
- type: 'object',
9
- additionalProperties: {
10
- type: 'array',
11
- items: {
12
- type: 'string',
13
- minLength: 1,
14
- },
15
- description: 'Array of dependency paths (glob patterns allowed)',
1
+ // src/schema.ts
2
+ var dependencyMapSchema = {
3
+ $schema: "http://json-schema.org/draft-07/schema#",
4
+ title: "FrelioDependencyMap",
5
+ description: "Maps output file paths to arrays of dependency paths for incremental builds",
6
+ type: "object",
7
+ additionalProperties: {
8
+ type: "array",
9
+ items: {
10
+ type: "string",
11
+ minLength: 1
16
12
  },
17
- examples: [
18
- {
19
- '/articles/{slug}.json': [
20
- 'content_types/article',
21
- 'templates/article/detail.html',
22
- 'contents/*/article/*',
23
- ],
24
- '/articles/index.json': [
25
- 'content_types/article',
26
- 'templates/article/list.html',
27
- 'contents/*/article/*',
28
- ],
29
- },
30
- ],
13
+ description: "Array of dependency paths (glob patterns allowed)"
14
+ },
15
+ examples: [
16
+ {
17
+ "/articles/{slug}.json": [
18
+ "content_types/article",
19
+ "templates/article/detail.html",
20
+ "contents/*/article/*"
21
+ ],
22
+ "/articles/index.json": [
23
+ "content_types/article",
24
+ "templates/article/list.html",
25
+ "contents/*/article/*"
26
+ ]
27
+ }
28
+ ]
31
29
  };
30
+
31
+ export { dependencyMapSchema };
32
+ //# sourceMappingURL=schema.js.map
33
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/schema.ts"],"names":[],"mappings":";AAIO,IAAM,mBAAA,GAAsB;AAAA,EACjC,OAAA,EAAS,yCAAA;AAAA,EACT,KAAA,EAAO,qBAAA;AAAA,EACP,WAAA,EACE,6EAAA;AAAA,EACF,IAAA,EAAM,QAAA;AAAA,EACN,oBAAA,EAAsB;AAAA,IACpB,IAAA,EAAM,OAAA;AAAA,IACN,KAAA,EAAO;AAAA,MACL,IAAA,EAAM,QAAA;AAAA,MACN,SAAA,EAAW;AAAA,KACb;AAAA,IACA,WAAA,EAAa;AAAA,GACf;AAAA,EACA,QAAA,EAAU;AAAA,IACR;AAAA,MACE,uBAAA,EAAyB;AAAA,QACvB,uBAAA;AAAA,QACA,+BAAA;AAAA,QACA;AAAA,OACF;AAAA,MACA,sBAAA,EAAwB;AAAA,QACtB,uBAAA;AAAA,QACA,6BAAA;AAAA,QACA;AAAA;AACF;AACF;AAEJ","file":"schema.js","sourcesContent":["/**\n * JSON Schema for FrelioDependencyMap validation\n */\n\nexport const dependencyMapSchema = {\n $schema: 'http://json-schema.org/draft-07/schema#',\n title: 'FrelioDependencyMap',\n description:\n 'Maps output file paths to arrays of dependency paths for incremental builds',\n type: 'object',\n additionalProperties: {\n type: 'array',\n items: {\n type: 'string',\n minLength: 1,\n },\n description: 'Array of dependency paths (glob patterns allowed)',\n },\n examples: [\n {\n '/articles/{slug}.json': [\n 'content_types/article',\n 'templates/article/detail.html',\n 'contents/*/article/*',\n ],\n '/articles/index.json': [\n 'content_types/article',\n 'templates/article/list.html',\n 'contents/*/article/*',\n ],\n },\n ],\n} as const\n\nexport type FrelioDependencyMapSchema = typeof dependencyMapSchema\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@c-time/frelio-dependency-map",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "Type definitions and utilities for frelio dependency map files",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -15,15 +15,24 @@
15
15
  "import": "./dist/schema.js"
16
16
  }
17
17
  },
18
+ "sideEffects": false,
18
19
  "files": [
19
20
  "dist",
20
21
  "README.md"
21
22
  ],
22
23
  "scripts": {
23
- "build": "tsc -p tsconfig.build.json",
24
- "dev": "tsc -p tsconfig.build.json --watch",
24
+ "build": "tsup",
25
+ "dev": "tsup --watch",
25
26
  "prepublishOnly": "npm run build"
26
27
  },
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "https://github.com/c-time/frelio.git",
34
+ "directory": "packages/dependency-map"
35
+ },
27
36
  "keywords": [
28
37
  "frelio",
29
38
  "dependency-map",
@@ -33,6 +42,7 @@
33
42
  ],
34
43
  "license": "MIT",
35
44
  "devDependencies": {
45
+ "tsup": "^8.5.0",
36
46
  "typescript": "^5.7.0"
37
47
  },
38
48
  "engines": {
package/README.md DELETED
@@ -1,101 +0,0 @@
1
- # frelio-dependency-map
2
-
3
- Type definitions and utilities for frelio dependency map files.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- npm install frelio-dependency-map
9
- ```
10
-
11
- ## Usage
12
-
13
- ### Basic Usage
14
-
15
- ```typescript
16
- import { DependencyMap, isDependencyMap } from 'frelio-dependency-map'
17
- import fs from 'fs'
18
-
19
- // Load a dependency map file
20
- const data = JSON.parse(fs.readFileSync('_dependency-map.json', 'utf-8'))
21
-
22
- // Validate the data
23
- if (isDependencyMap(data)) {
24
- // data is now typed as DependencyMap
25
- console.log('Output paths:', Object.keys(data))
26
- }
27
- ```
28
-
29
- ### Validation with Detailed Errors
30
-
31
- ```typescript
32
- import { validateDependencyMap } from 'frelio-dependency-map'
33
-
34
- const result = validateDependencyMap(data)
35
- if (!result.valid) {
36
- console.error('Validation errors:', result.errors)
37
- }
38
- ```
39
-
40
- ### Finding Affected Outputs
41
-
42
- ```typescript
43
- import { findAffectedOutputs, DependencyMap } from 'frelio-dependency-map'
44
-
45
- const map: DependencyMap = {
46
- '/articles/{slug}.json': ['content_types/article', 'contents/*/article/*'],
47
- }
48
-
49
- // Find which outputs need rebuilding when a file changes
50
- const affected = findAffectedOutputs(
51
- map,
52
- 'contents/published/article/my-post.json'
53
- )
54
- console.log(affected) // ['/articles/{slug}.json']
55
- ```
56
-
57
- ### JSON Schema Validation
58
-
59
- ```typescript
60
- import { dependencyMapSchema } from 'frelio-dependency-map/schema'
61
- import Ajv from 'ajv'
62
-
63
- const ajv = new Ajv()
64
- const validate = ajv.compile(dependencyMapSchema)
65
-
66
- if (!validate(data)) {
67
- console.error(validate.errors)
68
- }
69
- ```
70
-
71
- ## API
72
-
73
- ### Types
74
-
75
- - `DependencyMap` - Main type for dependency map objects
76
- - `OutputPath` - Type alias for output path strings
77
- - `DependencyPath` - Type alias for dependency path strings
78
- - `ValidationResult` - Result of validation operations
79
- - `ValidationError` - Individual validation error
80
-
81
- ### Functions
82
-
83
- - `isDependencyMap(value)` - Type guard for DependencyMap
84
- - `validateDependencyMap(value)` - Validates with detailed errors
85
- - `getDependencyPaths(map, outputPath)` - Get dependencies for an output
86
- - `getOutputPaths(map)` - Get all output paths
87
- - `getAllDependencyPaths(map)` - Get all unique dependency paths
88
- - `mergeDependencyMaps(...maps)` - Merge multiple maps
89
- - `findAffectedOutputs(map, changedPath)` - Find outputs affected by a change
90
- - `createDependencyMap()` - Create an empty dependency map
91
- - `setDependencies(map, outputPath, deps)` - Set dependencies for an output
92
- - `removeDependencies(map, outputPath)` - Remove an output from the map
93
-
94
- ### Constants
95
-
96
- - `DEPENDENCY_PATH_PREFIXES` - Common path prefixes
97
- - `dependencyMapSchema` - JSON Schema for validation
98
-
99
- ## License
100
-
101
- MIT
package/dist/guards.d.ts DELETED
@@ -1,9 +0,0 @@
1
- import type { FrelioDependencyMap, ValidationResult } from './types.js';
2
- /**
3
- * Type guard to check if a value is a valid FrelioDependencyMap
4
- */
5
- export declare function isFrelioDependencyMap(value: unknown): value is FrelioDependencyMap;
6
- /**
7
- * Validates a value as a FrelioDependencyMap and returns detailed errors
8
- */
9
- export declare function validateFrelioDependencyMap(value: unknown): ValidationResult;
package/dist/guards.js DELETED
@@ -1,72 +0,0 @@
1
- /**
2
- * Type guard to check if a value is a valid FrelioDependencyMap
3
- */
4
- export function isFrelioDependencyMap(value) {
5
- if (value === null || typeof value !== 'object') {
6
- return false;
7
- }
8
- const obj = value;
9
- for (const [key, val] of Object.entries(obj)) {
10
- // Key must be a non-empty string
11
- if (typeof key !== 'string' || key.length === 0) {
12
- return false;
13
- }
14
- // Value must be an array of strings
15
- if (!Array.isArray(val)) {
16
- return false;
17
- }
18
- for (const item of val) {
19
- if (typeof item !== 'string') {
20
- return false;
21
- }
22
- }
23
- }
24
- return true;
25
- }
26
- /**
27
- * Validates a value as a FrelioDependencyMap and returns detailed errors
28
- */
29
- export function validateFrelioDependencyMap(value) {
30
- const errors = [];
31
- if (value === null) {
32
- errors.push({ path: '', message: 'Value is null' });
33
- return { valid: false, errors };
34
- }
35
- if (typeof value !== 'object') {
36
- errors.push({ path: '', message: `Expected object, got ${typeof value}` });
37
- return { valid: false, errors };
38
- }
39
- const obj = value;
40
- for (const [key, val] of Object.entries(obj)) {
41
- if (typeof key !== 'string' || key.length === 0) {
42
- errors.push({
43
- path: key,
44
- message: 'Output path must be a non-empty string',
45
- });
46
- continue;
47
- }
48
- if (!Array.isArray(val)) {
49
- errors.push({
50
- path: key,
51
- message: `Expected array of dependencies, got ${typeof val}`,
52
- });
53
- continue;
54
- }
55
- for (let i = 0; i < val.length; i++) {
56
- const item = val[i];
57
- if (typeof item !== 'string') {
58
- errors.push({
59
- path: `${key}[${i}]`,
60
- message: `Expected string dependency path, got ${typeof item}`,
61
- });
62
- }
63
- else if (item.length === 0) {
64
- errors.push({
65
- path: `${key}[${i}]`,
66
- message: 'Dependency path cannot be empty',
67
- });
68
- }
69
- }
70
- }
71
- return { valid: errors.length === 0, errors };
72
- }
package/dist/types.d.ts DELETED
@@ -1,66 +0,0 @@
1
- /**
2
- * Dependency Map type definitions
3
- *
4
- * A dependency map tracks which source files affect each output file,
5
- * enabling incremental/differential builds.
6
- */
7
- /**
8
- * Output path pattern (e.g., "/articles/{slug}.json", "/articles/index.json")
9
- * Can include template variables like {slug}, {page}, etc.
10
- */
11
- export type OutputPath = string;
12
- /**
13
- * Dependency path pattern
14
- * Examples: "contents/&#42;/article/&#42;", "templates/article/detail.html"
15
- * Can include glob patterns for matching multiple files.
16
- *
17
- * Common prefixes:
18
- * - content_types/ - Content type definitions
19
- * - templates/ - Template files
20
- * - contents/ - Content data files (often with glob patterns)
21
- */
22
- export type DependencyPath = string;
23
- /**
24
- * Dependency Map
25
- *
26
- * Maps output file paths to arrays of dependency paths.
27
- * Used by the builder for incremental builds - when any dependency changes,
28
- * the corresponding output files need to be regenerated.
29
- *
30
- * Example:
31
- * ```
32
- * {
33
- * "/articles/{slug}.json": [
34
- * "content_types/article",
35
- * "templates/article/detail.html",
36
- * "contents/&#42;/article/&#42;"
37
- * ]
38
- * }
39
- * ```
40
- */
41
- export type FrelioDependencyMap = {
42
- [outputPath: OutputPath]: DependencyPath[];
43
- };
44
- /**
45
- * Common dependency path prefixes used in frelio projects
46
- */
47
- export declare const DEPENDENCY_PATH_PREFIXES: {
48
- /** Content type schema definitions */
49
- readonly CONTENT_TYPES: "content_types/";
50
- /** Template files */
51
- readonly TEMPLATES: "templates/";
52
- /** Content data files */
53
- readonly CONTENTS: "contents/";
54
- };
55
- export type DependencyPathPrefix = (typeof DEPENDENCY_PATH_PREFIXES)[keyof typeof DEPENDENCY_PATH_PREFIXES];
56
- /**
57
- * Result of validation operations
58
- */
59
- export type ValidationResult = {
60
- valid: boolean;
61
- errors: ValidationError[];
62
- };
63
- export type ValidationError = {
64
- path: string;
65
- message: string;
66
- };
package/dist/types.js DELETED
@@ -1,17 +0,0 @@
1
- /**
2
- * Dependency Map type definitions
3
- *
4
- * A dependency map tracks which source files affect each output file,
5
- * enabling incremental/differential builds.
6
- */
7
- /**
8
- * Common dependency path prefixes used in frelio projects
9
- */
10
- export const DEPENDENCY_PATH_PREFIXES = {
11
- /** Content type schema definitions */
12
- CONTENT_TYPES: 'content_types/',
13
- /** Template files */
14
- TEMPLATES: 'templates/',
15
- /** Content data files */
16
- CONTENTS: 'contents/',
17
- };
package/dist/utils.d.ts DELETED
@@ -1,36 +0,0 @@
1
- import type { FrelioDependencyMap, DependencyPath, OutputPath } from './types.js';
2
- /**
3
- * Gets the dependency paths for a specific output path
4
- * Returns an empty array if the output path is not found
5
- */
6
- export declare function getDependencyPaths(map: FrelioDependencyMap, outputPath: OutputPath): DependencyPath[];
7
- /**
8
- * Gets all output paths defined in the dependency map
9
- */
10
- export declare function getOutputPaths(map: FrelioDependencyMap): OutputPath[];
11
- /**
12
- * Gets all unique dependency paths across all outputs
13
- */
14
- export declare function getAllDependencyPaths(map: FrelioDependencyMap): DependencyPath[];
15
- /**
16
- * Merges multiple dependency maps into one
17
- * Later maps override earlier ones for the same output path
18
- */
19
- export declare function mergeFrelioDependencyMaps(...maps: FrelioDependencyMap[]): FrelioDependencyMap;
20
- /**
21
- * Finds all output paths that depend on a given dependency path
22
- * Supports exact match and simple glob pattern matching
23
- */
24
- export declare function findAffectedOutputs(map: FrelioDependencyMap, changedPath: DependencyPath): OutputPath[];
25
- /**
26
- * Creates an empty dependency map
27
- */
28
- export declare function createFrelioDependencyMap(): FrelioDependencyMap;
29
- /**
30
- * Adds or updates dependencies for an output path
31
- */
32
- export declare function setDependencies(map: FrelioDependencyMap, outputPath: OutputPath, dependencies: DependencyPath[]): FrelioDependencyMap;
33
- /**
34
- * Removes an output path from the dependency map
35
- */
36
- export declare function removeDependencies(map: FrelioDependencyMap, outputPath: OutputPath): FrelioDependencyMap;
package/dist/utils.js DELETED
@@ -1,99 +0,0 @@
1
- /**
2
- * Gets the dependency paths for a specific output path
3
- * Returns an empty array if the output path is not found
4
- */
5
- export function getDependencyPaths(map, outputPath) {
6
- return map[outputPath] ?? [];
7
- }
8
- /**
9
- * Gets all output paths defined in the dependency map
10
- */
11
- export function getOutputPaths(map) {
12
- return Object.keys(map);
13
- }
14
- /**
15
- * Gets all unique dependency paths across all outputs
16
- */
17
- export function getAllDependencyPaths(map) {
18
- const allPaths = new Set();
19
- for (const paths of Object.values(map)) {
20
- for (const path of paths) {
21
- allPaths.add(path);
22
- }
23
- }
24
- return Array.from(allPaths).sort();
25
- }
26
- /**
27
- * Merges multiple dependency maps into one
28
- * Later maps override earlier ones for the same output path
29
- */
30
- export function mergeFrelioDependencyMaps(...maps) {
31
- const result = {};
32
- for (const map of maps) {
33
- for (const [outputPath, deps] of Object.entries(map)) {
34
- result[outputPath] = [...deps];
35
- }
36
- }
37
- return result;
38
- }
39
- /**
40
- * Finds all output paths that depend on a given dependency path
41
- * Supports exact match and simple glob pattern matching
42
- */
43
- export function findAffectedOutputs(map, changedPath) {
44
- const affected = [];
45
- for (const [outputPath, deps] of Object.entries(map)) {
46
- for (const dep of deps) {
47
- if (matchesDependencyPath(dep, changedPath)) {
48
- affected.push(outputPath);
49
- break;
50
- }
51
- }
52
- }
53
- return affected;
54
- }
55
- /**
56
- * Checks if a dependency pattern matches a given path
57
- * Supports * as a wildcard for any single path segment
58
- */
59
- function matchesDependencyPath(pattern, path) {
60
- // Exact match
61
- if (pattern === path) {
62
- return true;
63
- }
64
- // Convert glob pattern to regex
65
- // * matches any characters except /
66
- const regexPattern = pattern
67
- .replace(/[.+?^${}()|[\]\\]/g, '\\$&') // Escape special regex chars
68
- .replace(/\*/g, '[^/]*'); // * matches any segment
69
- try {
70
- const regex = new RegExp(`^${regexPattern}$`);
71
- return regex.test(path);
72
- }
73
- catch {
74
- // If regex compilation fails, fall back to exact match
75
- return pattern === path;
76
- }
77
- }
78
- /**
79
- * Creates an empty dependency map
80
- */
81
- export function createFrelioDependencyMap() {
82
- return {};
83
- }
84
- /**
85
- * Adds or updates dependencies for an output path
86
- */
87
- export function setDependencies(map, outputPath, dependencies) {
88
- return {
89
- ...map,
90
- [outputPath]: [...dependencies],
91
- };
92
- }
93
- /**
94
- * Removes an output path from the dependency map
95
- */
96
- export function removeDependencies(map, outputPath) {
97
- const { [outputPath]: _, ...rest } = map;
98
- return rest;
99
- }