@pixelated-tech/components 3.7.1 → 3.7.3

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.
@@ -1,8 +1,11 @@
1
- /* eslint-disable @typescript-eslint/no-require-imports */
2
- const fs = require('fs');
3
- const path = require('path');
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { fileURLToPath } from 'url';
4
4
 
5
- const publicDir = path.join(__dirname, '..', 'public');
5
+ const __filename = fileURLToPath(import.meta.url);
6
+ const __dirname = path.dirname(__filename);
7
+
8
+ const publicDir = path.join(process.cwd(), 'public');
6
9
  const outFile = path.join(publicDir, 'site-images.json');
7
10
 
8
11
  function listFiles(dir, exts = ['.jpg','.jpeg','.png','.webp','.avif','.gif']) {
@@ -0,0 +1,280 @@
1
+ import fs from 'fs';
2
+ import glob from 'glob';
3
+ import { CLIENT_ONLY_PATTERNS, TS_FILE_IGNORE_PATTERNS, TSX_FILE_IGNORE_PATTERNS, SERVER_ONLY_PATTERNS } from '../components/utilities/functions.js';
4
+
5
+ console.log('🔍 Validating exports...\n');
6
+
7
+ // Find all .ts files (excluding .d.ts, test files, stories, examples, types.ts)
8
+ const tsFiles = glob.sync('src/components/**/*.ts', {
9
+ ignore: TS_FILE_IGNORE_PATTERNS
10
+ });
11
+
12
+ // Find all .tsx files (excluding test files, stories, examples)
13
+ const tsxFiles = glob.sync('src/components/**/*.tsx', {
14
+ ignore: TSX_FILE_IGNORE_PATTERNS
15
+ });
16
+
17
+ // Combine all component files
18
+ const allComponentFiles = [...tsFiles, ...tsxFiles];
19
+
20
+ // Analyze each component file to determine if it's client-required or server-safe
21
+ function analyzeComponentFile(filePath) {
22
+ const content = fs.readFileSync(filePath, 'utf8');
23
+
24
+ // Server-only patterns that indicate this should only be on server (not client)
25
+ // (Imported from shared utilities)
26
+
27
+ // Client-only patterns that require the component to run on client
28
+ // (Imported from shared utilities)
29
+
30
+ // Check if file contains any server-only patterns
31
+ const isServerOnly = SERVER_ONLY_PATTERNS.some(pattern => pattern.test(content));
32
+
33
+ // Check if file contains any client-only patterns
34
+ const isClientOnly = CLIENT_ONLY_PATTERNS.some(pattern => pattern.test(content));
35
+
36
+ return {
37
+ filePath,
38
+ isClientOnly,
39
+ isServerOnly,
40
+ exportPath: filePath.replace('src/', './').replace(/\.tsx?$/, '')
41
+ };
42
+ }
43
+
44
+ // Analyze all component files
45
+ const analyzedComponents = allComponentFiles.map(analyzeComponentFile);
46
+
47
+ // Special handling for utilities/functions.ts - it's safe for both client and server despite containing pattern definitions
48
+ analyzedComponents.forEach(comp => {
49
+ if (comp.exportPath === './components/utilities/functions') {
50
+ comp.isClientOnly = false;
51
+ comp.isServerOnly = false;
52
+ }
53
+ });
54
+
55
+ // Separate admin and non-admin components
56
+ const adminComponents = analyzedComponents.filter(comp => comp.exportPath.startsWith('./components/admin/'));
57
+ const nonAdminComponents = analyzedComponents.filter(comp => !comp.exportPath.startsWith('./components/admin/'));
58
+
59
+ // Create arrays of components for each bundle (non-admin only)
60
+ // If a component has server-only patterns, it's server-only; if client-only and not server-only, client-only; else safe
61
+ const serverOnlyComponents = nonAdminComponents.filter(comp => comp.isServerOnly);
62
+ const clientOnlyComponents = nonAdminComponents.filter(comp => comp.isClientOnly && !comp.isServerOnly);
63
+ const clientAndServerSafeComponents = nonAdminComponents.filter(comp => !comp.isClientOnly && !comp.isServerOnly);
64
+
65
+ // Read index files
66
+ const indexServer = fs.readFileSync('src/index.server.js', 'utf8');
67
+ const indexClient = fs.readFileSync('src/index.js', 'utf8');
68
+ const indexAdminServer = fs.readFileSync('src/index.adminserver.js', 'utf8');
69
+ const indexAdminClient = fs.readFileSync('src/index.adminclient.js', 'utf8');
70
+
71
+ // Helper function to extract exports from index file
72
+ function extractExports(content) {
73
+ // Remove comments
74
+ content = content.replace(/\/\*[\s\S]*?\*\//g, '');
75
+ content = content.replace(/\/\/.*$/gm, '');
76
+
77
+ const exports = [];
78
+
79
+ // Handle export * from './path' syntax
80
+ const exportAllRegex = /export\s+\*\s+from\s+['"]([^'"]+)['"]/g;
81
+ let match;
82
+
83
+ while ((match = exportAllRegex.exec(content)) !== null) {
84
+ exports.push(match[1]);
85
+ }
86
+
87
+ // Handle export { ... } from './path' syntax
88
+ const exportRegex = /export\s+{\s*([^}]+)\s*}\s+from\s+['"]([^'"]+)['"]/g;
89
+ while ((match = exportRegex.exec(content)) !== null) {
90
+ const exportList = match[1];
91
+ const exportItems = exportList.split(',').map(item => item.trim());
92
+ exports.push(...exportItems.map(item => match[2])); // Use the from path
93
+ }
94
+
95
+ return exports;
96
+ }
97
+
98
+ // Extract exports from all index files
99
+ const serverExports = extractExports(indexServer);
100
+ const clientExports = extractExports(indexClient);
101
+ const adminServerExports = extractExports(indexAdminServer);
102
+ const adminClientExports = extractExports(indexAdminClient);
103
+
104
+ const missing = {
105
+ server: [],
106
+ client: [],
107
+ adminServer: [],
108
+ adminClient: [],
109
+ files: [] // New: exported paths that don't correspond to existing files
110
+ };
111
+
112
+ const bundleErrors = {
113
+ server: [], // Client-only components incorrectly in server bundle
114
+ client: [], // Server-only components incorrectly in client bundle
115
+ adminServer: [], // Client-only components incorrectly in admin server bundle
116
+ adminClient: [] // Server-only components incorrectly in admin client bundle
117
+ };
118
+
119
+ // Check if exported paths correspond to existing files
120
+ function checkExportPathsExist(exports, bundleName) {
121
+ exports.forEach(exportPath => {
122
+ // Convert export path to file path (./components/... -> src/components/...)
123
+ const filePathBase = exportPath.replace('./', 'src/');
124
+ const tsFile = `${filePathBase}.ts`;
125
+ const tsxFile = `${filePathBase}.tsx`;
126
+
127
+ const tsExists = fs.existsSync(tsFile);
128
+ const tsxExists = fs.existsSync(tsxFile);
129
+
130
+ if (!tsExists && !tsxExists) {
131
+ missing.files.push(`${bundleName}: ${exportPath} (.ts/.tsx files not found)`);
132
+ }
133
+ });
134
+ }
135
+
136
+ checkExportPathsExist(serverExports, 'server bundle');
137
+ checkExportPathsExist(clientExports, 'client bundle');
138
+ checkExportPathsExist(adminServerExports, 'admin server bundle');
139
+ checkExportPathsExist(adminClientExports, 'admin client bundle');
140
+
141
+ // Check for missing exports
142
+ clientAndServerSafeComponents.forEach(comp => {
143
+ if (!serverExports.includes(comp.exportPath)) {
144
+ missing.server.push(comp.exportPath);
145
+ }
146
+ });
147
+
148
+ serverOnlyComponents.forEach(comp => {
149
+ if (!serverExports.includes(comp.exportPath)) {
150
+ missing.server.push(comp.exportPath);
151
+ }
152
+ });
153
+
154
+ clientOnlyComponents.forEach(comp => {
155
+ if (!clientExports.includes(comp.exportPath)) {
156
+ missing.client.push(comp.exportPath);
157
+ }
158
+ });
159
+
160
+ clientAndServerSafeComponents.forEach(comp => {
161
+ if (!clientExports.includes(comp.exportPath)) {
162
+ missing.client.push(comp.exportPath);
163
+ }
164
+ });
165
+
166
+ // Check admin components - separate server and client bundles
167
+ const serverRelevantAdmin = adminComponents.filter(comp => comp.isServerOnly || !comp.isClientOnly);
168
+ const clientRelevantAdmin = adminComponents.filter(comp => comp.isClientOnly || !comp.isServerOnly);
169
+
170
+ serverRelevantAdmin.forEach(comp => {
171
+ if (!adminServerExports.includes(comp.exportPath)) {
172
+ missing.adminServer.push(comp.exportPath);
173
+ }
174
+ if (serverExports.includes(comp.exportPath) && !comp.isServerOnly) {
175
+ bundleErrors.server.push(comp.exportPath + ' (admin component in server bundle)');
176
+ }
177
+ if (clientExports.includes(comp.exportPath) && !comp.isServerOnly) {
178
+ bundleErrors.client.push(comp.exportPath + ' (admin component in client bundle)');
179
+ }
180
+ });
181
+
182
+ clientRelevantAdmin.forEach(comp => {
183
+ if (!adminClientExports.includes(comp.exportPath)) {
184
+ missing.adminClient.push(comp.exportPath);
185
+ }
186
+ if (serverExports.includes(comp.exportPath) && comp.isClientOnly) {
187
+ bundleErrors.server.push(comp.exportPath + ' (client-only admin component in server bundle)');
188
+ }
189
+ // Allow client-only components in adminserver if they are also server-only (both)
190
+ if (adminServerExports.includes(comp.exportPath) && comp.isClientOnly && !comp.isServerOnly) {
191
+ bundleErrors.adminServer.push(comp.exportPath + ' (client-only admin component in admin server bundle)');
192
+ }
193
+ });
194
+
195
+ // Check for bundle contamination errors
196
+ clientOnlyComponents.forEach(comp => {
197
+ if (serverExports.includes(comp.exportPath)) {
198
+ bundleErrors.server.push(comp.exportPath);
199
+ }
200
+ });
201
+
202
+ serverOnlyComponents.forEach(comp => {
203
+ if (clientExports.includes(comp.exportPath)) {
204
+ bundleErrors.client.push(comp.exportPath + ' (server-only component in client bundle)');
205
+ }
206
+ });
207
+
208
+ // Report results
209
+ console.log('📊 Analysis Results:');
210
+ console.log(` Found ${allComponentFiles.length} component files`);
211
+ console.log(` ${clientOnlyComponents.length} client-only components`);
212
+ console.log(` ${clientAndServerSafeComponents.length} client-and-server-safe components`);
213
+ console.log(` ${serverOnlyComponents.length} server-only components`);
214
+ console.log(` ${adminComponents.length} admin components`);
215
+ if (missing.server.length > 0) {
216
+ console.log('❌ Missing from server bundle (index.server.js):');
217
+ missing.server.forEach(path => console.log(` - ${path}`));
218
+ console.log('');
219
+ }
220
+
221
+ if (missing.client.length > 0) {
222
+ console.log('❌ Missing from client bundle (index.js):');
223
+ missing.client.forEach(path => console.log(` - ${path}`));
224
+ console.log('');
225
+ }
226
+
227
+ if (missing.adminServer.length > 0) {
228
+ console.log('❌ Missing from admin server bundle (index.adminserver.js):');
229
+ missing.adminServer.forEach(path => console.log(` - ${path}`));
230
+ console.log('');
231
+ }
232
+
233
+ if (missing.adminClient.length > 0) {
234
+ console.log('❌ Missing from admin client bundle (index.adminclient.js):');
235
+ missing.adminClient.forEach(path => console.log(` - ${path}`));
236
+ console.log('');
237
+ }
238
+
239
+ if (bundleErrors.server.length > 0) {
240
+ console.log('🚨 Bundle contamination errors:');
241
+ console.log(' Client-required components incorrectly exported from server bundle:');
242
+ bundleErrors.server.forEach(path => console.log(` - ${path}`));
243
+ console.log('');
244
+ }
245
+
246
+ if (bundleErrors.client.length > 0) {
247
+ console.log('🚨 Bundle contamination errors:');
248
+ console.log(' Server-required components incorrectly exported from client bundle:');
249
+ bundleErrors.client.forEach(path => console.log(` - ${path}`));
250
+ console.log('');
251
+ }
252
+
253
+ if (bundleErrors.adminServer.length > 0) {
254
+ console.log('🚨 Bundle contamination errors:');
255
+ console.log(' Client-required components incorrectly exported from admin server bundle:');
256
+ bundleErrors.adminServer.forEach(path => console.log(` - ${path}`));
257
+ console.log('');
258
+ }
259
+
260
+ if (bundleErrors.adminClient.length > 0) {
261
+ console.log('🚨 Bundle contamination errors:');
262
+ console.log(' Server-only components incorrectly exported from admin client bundle:');
263
+ bundleErrors.adminClient.forEach(path => console.log(` - ${path}`));
264
+ console.log('');
265
+ }
266
+
267
+ if (missing.files.length > 0) {
268
+ console.log('❌ Exported paths that don\'t exist:');
269
+ missing.files.forEach(path => console.log(` - ${path}`));
270
+ console.log('');
271
+ }
272
+
273
+ const hasErrors = missing.server.length > 0 || missing.client.length > 0 || missing.adminServer.length > 0 || missing.adminClient.length > 0 || bundleErrors.server.length > 0 || bundleErrors.client.length > 0 || bundleErrors.adminServer.length > 0 || bundleErrors.adminClient.length > 0 || missing.files.length > 0;
274
+
275
+ if (hasErrors) {
276
+ console.log('❌ Validation failed!');
277
+ process.exit(1);
278
+ } else {
279
+ console.log('✅ All exports validated successfully!');
280
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=validate-exports.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-exports.d.cts","sourceRoot":"","sources":["../../../src/scripts/validate-exports.cjs"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pixelated-tech/components",
3
- "version": "3.7.1",
3
+ "version": "3.7.3",
4
4
  "private": false,
5
5
  "author": {
6
6
  "name": "Pixelated Technologies",
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,206 +0,0 @@
1
- import { http, HttpResponse } from 'msw';
2
- console.log('MSW handlers loaded');
3
- // Mock data for Axe Core accessibility
4
- const mockAxeData = {
5
- success: true,
6
- data: {
7
- site: 'example.com',
8
- url: 'https://example.com',
9
- violations: [
10
- {
11
- id: 'color-contrast',
12
- impact: 'serious',
13
- description: 'Elements must have sufficient color contrast',
14
- help: 'Ensure text has enough contrast against background',
15
- helpUrl: 'https://dequeuniversity.com/rules/axe/4.8/color-contrast',
16
- nodes: [
17
- {
18
- target: ['.header h1'],
19
- html: '<h1>Welcome</h1>',
20
- failureSummary: 'Fix any of the following: Element has insufficient color contrast of 2.5:1'
21
- }
22
- ]
23
- },
24
- {
25
- id: 'image-alt',
26
- impact: 'critical',
27
- description: 'Images must have alternate text',
28
- help: 'Provide alternative text for images',
29
- helpUrl: 'https://dequeuniversity.com/rules/axe/4.8/image-alt',
30
- nodes: [
31
- {
32
- target: ['img[alt=""]'],
33
- html: '<img src="logo.png" alt="">',
34
- failureSummary: 'Fix any of the following: aria-label attribute does not exist or is empty'
35
- }
36
- ]
37
- }
38
- ],
39
- passes: 45,
40
- incomplete: 2,
41
- inapplicable: 12
42
- }
43
- };
44
- // Mock data for Core Web Vitals
45
- const mockCoreWebVitalsData = {
46
- success: true,
47
- data: {
48
- site: 'pixelated.tech',
49
- url: 'https://pixelated.tech',
50
- metrics: {
51
- cls: 0.05,
52
- fid: 85,
53
- lcp: 1200,
54
- fcp: 800,
55
- ttfb: 150,
56
- speedIndex: 1100,
57
- interactive: 1300,
58
- totalBlockingTime: 50,
59
- firstMeaningfulPaint: 900
60
- },
61
- scores: {
62
- performance: 85,
63
- accessibility: 90,
64
- bestPractices: 95,
65
- seo: 88,
66
- pwa: 75
67
- },
68
- categories: {
69
- performance: { score: 85, displayValue: 'Good' },
70
- accessibility: { score: 90, displayValue: 'Good' },
71
- bestPractices: { score: 95, displayValue: 'Good' },
72
- seo: { score: 88, displayValue: 'Good' },
73
- pwa: { score: 75, displayValue: 'Good' }
74
- }
75
- }
76
- };
77
- // Mock data for Google Analytics
78
- const mockGoogleAnalyticsData = {
79
- success: true,
80
- data: {
81
- site: 'pixelated.tech',
82
- dateRange: {
83
- start: '2024-01-01',
84
- end: '2024-01-06'
85
- },
86
- metrics: {
87
- users: 1250,
88
- sessions: 1800,
89
- pageviews: 3200,
90
- bounceRate: 0.45,
91
- avgSessionDuration: 180,
92
- newUsers: 890
93
- },
94
- chartData: [
95
- { date: '2024-01-01', users: 120, sessions: 150, pageviews: 280 },
96
- { date: '2024-01-02', users: 135, sessions: 165, pageviews: 310 },
97
- { date: '2024-01-03', users: 142, sessions: 178, pageviews: 325 },
98
- { date: '2024-01-04', users: 158, sessions: 192, pageviews: 345 },
99
- { date: '2024-01-05', users: 165, sessions: 198, pageviews: 365 },
100
- { date: '2024-01-06', users: 172, sessions: 205, pageviews: 380 }
101
- ]
102
- }
103
- };
104
- // Mock data for Google Search Console
105
- const mockGoogleSearchConsoleData = {
106
- success: true,
107
- data: {
108
- site: 'pixelated.tech',
109
- dateRange: {
110
- start: '2024-01-01',
111
- end: '2024-01-06'
112
- },
113
- metrics: {
114
- clicks: 1250,
115
- impressions: 15000,
116
- ctr: 0.083,
117
- position: 12.5
118
- },
119
- chartData: [
120
- { date: '2024-01-01', clicks: 85, impressions: 1200, ctr: 0.071, position: 14.2 },
121
- { date: '2024-01-02', clicks: 92, impressions: 1350, ctr: 0.068, position: 13.8 },
122
- { date: '2024-01-03', clicks: 98, impressions: 1420, ctr: 0.069, position: 13.5 },
123
- { date: '2024-01-04', clicks: 105, impressions: 1480, ctr: 0.071, position: 13.2 },
124
- { date: '2024-01-05', clicks: 112, impressions: 1520, ctr: 0.074, position: 12.8 },
125
- { date: '2024-01-06', clicks: 118, impressions: 1580, ctr: 0.075, position: 12.5 }
126
- ]
127
- }
128
- };
129
- // Mock data for CloudWatch uptime
130
- const mockCloudWatchData = {
131
- success: true,
132
- data: {
133
- site: 'pixelated.tech',
134
- uptime: 99.8,
135
- responseTime: 245,
136
- status: 'operational',
137
- incidents: [],
138
- chartData: [
139
- { timestamp: '2024-01-01T00:00:00Z', uptime: 100, responseTime: 220 },
140
- { timestamp: '2024-01-02T00:00:00Z', uptime: 99.5, responseTime: 280 },
141
- { timestamp: '2024-01-03T00:00:00Z', uptime: 100, responseTime: 210 },
142
- { timestamp: '2024-01-04T00:00:00Z', uptime: 100, responseTime: 235 },
143
- { timestamp: '2024-01-05T00:00:00Z', uptime: 99.9, responseTime: 250 },
144
- { timestamp: '2024-01-06T00:00:00Z', uptime: 100, responseTime: 225 }
145
- ]
146
- }
147
- };
148
- export const handlers = [
149
- // API endpoints using relative paths (MSW v2 matches these regardless of origin)
150
- http.get('/api/site-health/axe-core', () => {
151
- console.log('MSW: Intercepting axe-core request');
152
- return HttpResponse.json(mockAxeData);
153
- }),
154
- http.get('/api/site-health/core-web-vitals', () => {
155
- console.log('MSW: Intercepting core-web-vitals request');
156
- return HttpResponse.json(mockCoreWebVitalsData);
157
- }),
158
- http.get('/api/site-health/google-analytics', () => {
159
- console.log('MSW: Intercepting google-analytics request');
160
- return HttpResponse.json(mockGoogleAnalyticsData);
161
- }),
162
- http.get('/api/site-health/google-search-console', () => {
163
- console.log('MSW: Intercepting google-search-console request');
164
- return HttpResponse.json(mockGoogleSearchConsoleData);
165
- }),
166
- http.get('/api/site-health/cloudwatch', () => {
167
- console.log('MSW: Intercepting cloudwatch request');
168
- return HttpResponse.json(mockCloudWatchData);
169
- }),
170
- // External URLs used by some stories
171
- http.get('https://api.pixelated.tech/axe-core', () => {
172
- console.log('MSW: Intercepting external axe-core request');
173
- return HttpResponse.json(mockAxeData);
174
- }),
175
- http.get('https://api.pixelated.tech/core-web-vitals', () => {
176
- console.log('MSW: Intercepting external core-web-vitals request');
177
- return HttpResponse.json(mockCoreWebVitalsData);
178
- }),
179
- http.get('https://api.pixelated.tech/google-analytics', () => {
180
- console.log('MSW: Intercepting external google-analytics request');
181
- return HttpResponse.json(mockGoogleAnalyticsData);
182
- }),
183
- http.get('https://api.pixelated.tech/google-search-console', () => {
184
- console.log('MSW: Intercepting external google-search-console request');
185
- return HttpResponse.json(mockGoogleSearchConsoleData);
186
- }),
187
- http.get('https://api.pixelated.tech/cloudwatch', () => {
188
- console.log('MSW: Intercepting external cloudwatch request');
189
- return HttpResponse.json(mockCloudWatchData);
190
- }),
191
- http.get('https://api.pixelated.tech/template-data', () => {
192
- console.log('MSW: Intercepting template-data request');
193
- return HttpResponse.json({
194
- success: true,
195
- data: { message: 'Mock template data' }
196
- });
197
- }),
198
- // Generic fallback for any other site health endpoints
199
- http.get('/api/site-health/*', () => {
200
- console.log('MSW: Intercepting generic site-health request');
201
- return HttpResponse.json({
202
- success: true,
203
- data: { message: 'Mock data for site health endpoint' }
204
- });
205
- })
206
- ];
@@ -1 +0,0 @@
1
- "use strict";
@@ -1 +0,0 @@
1
- //# sourceMappingURL=browser.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../../src/mocks/browser.js"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export const handlers: any[];
2
- //# sourceMappingURL=handlers.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../../src/mocks/handlers.js"],"names":[],"mappings":"AA0JA,6BAqEE"}
@@ -1 +0,0 @@
1
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/mocks/index.js"],"names":[],"mappings":""}