@questwork/q-utilities 0.1.32 โ 0.1.34
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/q-utilities.cjs +4838 -11
- package/dist/q-utilities.d.ts +245 -0
- package/dist/q-utilities.esm.js +3766 -1988
- package/dist/q-utilities.iife.js +4840 -11
- package/dist/q-utilities.umd.js +4841 -10
- package/package.json +1 -1
- package/.github/workflows/publish.yml +0 -60
- package/BEST_PRACTICES.md +0 -217
- package/BUILDING_JS_TS_LIBRARY.md +0 -321
- package/dist/q-utilities.cjs.map +0 -1
- package/dist/q-utilities.esm.js.map +0 -1
- package/dist/q-utilities.iife.js.map +0 -1
- package/dist/q-utilities.umd.js.map +0 -1
- package/eslint.config.js +0 -3
- package/tests/runtime-test.js +0 -563
- package/tsconfig.json +0 -28
- package/vite.config.js +0 -73
- package/vitest.config.js +0 -9
package/eslint.config.js
DELETED
package/tests/runtime-test.js
DELETED
|
@@ -1,563 +0,0 @@
|
|
|
1
|
-
// tests/runtime-test.js
|
|
2
|
-
import { exec } from 'child_process'
|
|
3
|
-
import fs from 'fs'
|
|
4
|
-
import path from 'path'
|
|
5
|
-
import { fileURLToPath } from 'url'
|
|
6
|
-
import http from 'http'
|
|
7
|
-
import { promisify } from 'util'
|
|
8
|
-
|
|
9
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
10
|
-
const PROJECT_ROOT = path.resolve(__dirname, '..')
|
|
11
|
-
const execPromise = promisify(exec)
|
|
12
|
-
|
|
13
|
-
console.log('๐ Project root:', PROJECT_ROOT)
|
|
14
|
-
console.log('๐งช Testing @questwork/q-utilities builds\n')
|
|
15
|
-
|
|
16
|
-
// Check if build exists
|
|
17
|
-
function checkBuild() {
|
|
18
|
-
const distPath = path.join(PROJECT_ROOT, 'dist')
|
|
19
|
-
if (!fs.existsSync(distPath)) {
|
|
20
|
-
console.error('\nโ Build not found! Please run build first:')
|
|
21
|
-
console.error(' pnpm run build\n')
|
|
22
|
-
process.exit(1)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const requiredFiles = [
|
|
26
|
-
'q-utilities.esm.js',
|
|
27
|
-
'q-utilities.cjs',
|
|
28
|
-
'q-utilities.umd.js',
|
|
29
|
-
'q-utilities.iife.js'
|
|
30
|
-
]
|
|
31
|
-
|
|
32
|
-
const missing = requiredFiles.filter(file => {
|
|
33
|
-
const filePath = path.join(distPath, file)
|
|
34
|
-
return !fs.existsSync(filePath)
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
if (missing.length > 0) {
|
|
38
|
-
console.error('\nโ Missing build files:', missing.join(', '))
|
|
39
|
-
console.error(' Please run: pnpm run build\n')
|
|
40
|
-
process.exit(1)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
console.log('โ
Build files found:\n')
|
|
44
|
-
requiredFiles.forEach(file => {
|
|
45
|
-
const stats = fs.statSync(path.join(distPath, file))
|
|
46
|
-
console.log(` ๐ฆ ${file}: ${(stats.size / 1024).toFixed(2)} KB`)
|
|
47
|
-
})
|
|
48
|
-
console.log('')
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Test ESM format (import)
|
|
52
|
-
async function testESM() {
|
|
53
|
-
console.log('๐งช Testing ESM format (import)...')
|
|
54
|
-
|
|
55
|
-
const testFilePath = path.join(PROJECT_ROOT, 'test-temp-esm.mjs')
|
|
56
|
-
|
|
57
|
-
const testCode = `
|
|
58
|
-
import { fileURLToPath } from 'url'
|
|
59
|
-
import path from 'path'
|
|
60
|
-
|
|
61
|
-
const __filename = fileURLToPath(import.meta.url)
|
|
62
|
-
const __dirname = path.dirname(__filename)
|
|
63
|
-
|
|
64
|
-
try {
|
|
65
|
-
const projectRoot = ${JSON.stringify(PROJECT_ROOT)}
|
|
66
|
-
const modulePath = path.join(projectRoot, 'dist/q-utilities.esm.js')
|
|
67
|
-
console.log('๐ Loading from:', modulePath)
|
|
68
|
-
|
|
69
|
-
const module = await import(modulePath)
|
|
70
|
-
console.log('โ
ESM module loaded successfully')
|
|
71
|
-
console.log('๐ฆ Exports:', Object.keys(module))
|
|
72
|
-
|
|
73
|
-
// Test specific exports based on your library
|
|
74
|
-
if (module.default) {
|
|
75
|
-
console.log('โ
Default export exists')
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Check for common utility functions (adjust based on your actual exports)
|
|
79
|
-
const expectedExports = ['default', 'displayName', 'TrackedEntity'] // Replace with actual exports
|
|
80
|
-
expectedExports.forEach(exp => {
|
|
81
|
-
if (module[exp]) {
|
|
82
|
-
console.log(\`โ
Export "\${exp}" found\`)
|
|
83
|
-
}
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
console.log(module)
|
|
87
|
-
const { displayName, TrackedEntity } = module
|
|
88
|
-
console.log(new TrackedEntity())
|
|
89
|
-
|
|
90
|
-
process.exit(0)
|
|
91
|
-
} catch (error) {
|
|
92
|
-
console.error('โ ESM test failed:', error.message)
|
|
93
|
-
console.error(error.stack)
|
|
94
|
-
process.exit(1)
|
|
95
|
-
}
|
|
96
|
-
`
|
|
97
|
-
|
|
98
|
-
fs.writeFileSync(testFilePath, testCode)
|
|
99
|
-
|
|
100
|
-
try {
|
|
101
|
-
const { stdout, stderr } = await execPromise(`node ${testFilePath}`)
|
|
102
|
-
console.log(stdout)
|
|
103
|
-
if (stderr) console.error(stderr)
|
|
104
|
-
return true
|
|
105
|
-
} catch (error) {
|
|
106
|
-
console.error('โ ESM test execution failed:', error.message)
|
|
107
|
-
return false
|
|
108
|
-
} finally {
|
|
109
|
-
if (fs.existsSync(testFilePath)) {
|
|
110
|
-
fs.unlinkSync(testFilePath)
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// Test CJS format (require)
|
|
116
|
-
async function testCJS() {
|
|
117
|
-
console.log('\n๐งช Testing CJS format (require)...')
|
|
118
|
-
|
|
119
|
-
const testFilePath = path.join(PROJECT_ROOT, 'test-temp-cjs.cjs')
|
|
120
|
-
|
|
121
|
-
const testCode = `
|
|
122
|
-
const path = require('path')
|
|
123
|
-
|
|
124
|
-
try {
|
|
125
|
-
const projectRoot = ${JSON.stringify(PROJECT_ROOT)}
|
|
126
|
-
const modulePath = path.join(projectRoot, 'dist/q-utilities.cjs')
|
|
127
|
-
console.log('๐ Loading from:', modulePath)
|
|
128
|
-
|
|
129
|
-
const module = require(modulePath)
|
|
130
|
-
console.log('โ
CJS module loaded successfully')
|
|
131
|
-
console.log('๐ฆ Exports:', Object.keys(module))
|
|
132
|
-
|
|
133
|
-
// Test specific exports
|
|
134
|
-
if (module.default) {
|
|
135
|
-
console.log('โ
Default export exists')
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
console.log(module)
|
|
139
|
-
const { displayName, TrackedEntity } = module
|
|
140
|
-
console.log(new TrackedEntity())
|
|
141
|
-
|
|
142
|
-
process.exit(0)
|
|
143
|
-
} catch (error) {
|
|
144
|
-
console.error('โ CJS test failed:', error.message)
|
|
145
|
-
console.error(error.stack)
|
|
146
|
-
process.exit(1)
|
|
147
|
-
}
|
|
148
|
-
`
|
|
149
|
-
|
|
150
|
-
fs.writeFileSync(testFilePath, testCode)
|
|
151
|
-
|
|
152
|
-
try {
|
|
153
|
-
const { stdout, stderr } = await execPromise(`node ${testFilePath}`)
|
|
154
|
-
console.log(stdout)
|
|
155
|
-
if (stderr) console.error(stderr)
|
|
156
|
-
return true
|
|
157
|
-
} catch (error) {
|
|
158
|
-
console.error('โ CJS test execution failed:', error.message)
|
|
159
|
-
return false
|
|
160
|
-
} finally {
|
|
161
|
-
if (fs.existsSync(testFilePath)) {
|
|
162
|
-
fs.unlinkSync(testFilePath)
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// Test UMD format in Node.js (CommonJS environment)
|
|
168
|
-
async function testUMD() {
|
|
169
|
-
console.log('\n๐งช Testing UMD format (Node.js require)...')
|
|
170
|
-
|
|
171
|
-
const testFilePath = path.join(PROJECT_ROOT, 'test-temp-umd.cjs')
|
|
172
|
-
|
|
173
|
-
const testCode = `
|
|
174
|
-
const path = require('path')
|
|
175
|
-
|
|
176
|
-
try {
|
|
177
|
-
const projectRoot = ${JSON.stringify(PROJECT_ROOT)}
|
|
178
|
-
const modulePath = path.join(projectRoot, 'dist/q-utilities.umd.js')
|
|
179
|
-
console.log('๐ Loading from:', modulePath)
|
|
180
|
-
|
|
181
|
-
const module = require(modulePath)
|
|
182
|
-
console.log('โ
UMD module loaded successfully in Node.js')
|
|
183
|
-
console.log('๐ฆ Exports:', Object.keys(module))
|
|
184
|
-
|
|
185
|
-
console.log(module)
|
|
186
|
-
// const { displayName, TrackedEntity } = module
|
|
187
|
-
// console.log(new TrackedEntity())
|
|
188
|
-
|
|
189
|
-
process.exit(0)
|
|
190
|
-
} catch (error) {
|
|
191
|
-
console.error('โ UMD test failed:', error.message)
|
|
192
|
-
console.error(error.stack)
|
|
193
|
-
process.exit(1)
|
|
194
|
-
}
|
|
195
|
-
`
|
|
196
|
-
|
|
197
|
-
fs.writeFileSync(testFilePath, testCode)
|
|
198
|
-
|
|
199
|
-
try {
|
|
200
|
-
const { stdout, stderr } = await execPromise(`node ${testFilePath}`)
|
|
201
|
-
console.log(stdout)
|
|
202
|
-
if (stderr) console.error(stderr)
|
|
203
|
-
return true
|
|
204
|
-
} catch (error) {
|
|
205
|
-
console.error('โ UMD test execution failed:', error.message)
|
|
206
|
-
return false
|
|
207
|
-
} finally {
|
|
208
|
-
if (fs.existsSync(testFilePath)) {
|
|
209
|
-
fs.unlinkSync(testFilePath)
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// Test IIFE format in browser
|
|
215
|
-
async function testIIFE() {
|
|
216
|
-
console.log('\n๐งช Testing IIFE format (browser)...')
|
|
217
|
-
|
|
218
|
-
const distPath = path.join(PROJECT_ROOT, 'dist')
|
|
219
|
-
const htmlPath = path.join(PROJECT_ROOT, 'tests/test-iife.html')
|
|
220
|
-
|
|
221
|
-
// Ensure tests directory exists
|
|
222
|
-
const testsDir = path.join(PROJECT_ROOT, 'tests')
|
|
223
|
-
if (!fs.existsSync(testsDir)) {
|
|
224
|
-
fs.mkdirSync(testsDir)
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
const html = `
|
|
228
|
-
<!DOCTYPE html>
|
|
229
|
-
<html>
|
|
230
|
-
<head>
|
|
231
|
-
<title>IIFE Test - @questwork/q-utilities</title>
|
|
232
|
-
<style>
|
|
233
|
-
body {
|
|
234
|
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, monospace;
|
|
235
|
-
padding: 20px;
|
|
236
|
-
max-width: 1200px;
|
|
237
|
-
margin: 0 auto;
|
|
238
|
-
}
|
|
239
|
-
.success { color: #22c55e; font-weight: bold; }
|
|
240
|
-
.error { color: #ef4444; font-weight: bold; }
|
|
241
|
-
.info { color: #3b82f6; }
|
|
242
|
-
.warning { color: #f59e0b; }
|
|
243
|
-
pre {
|
|
244
|
-
background: #1e1e1e;
|
|
245
|
-
color: #d4d4d4;
|
|
246
|
-
padding: 15px;
|
|
247
|
-
border-radius: 8px;
|
|
248
|
-
overflow-x: auto;
|
|
249
|
-
font-size: 12px;
|
|
250
|
-
}
|
|
251
|
-
.test-card {
|
|
252
|
-
border: 1px solid #e5e7eb;
|
|
253
|
-
border-radius: 8px;
|
|
254
|
-
padding: 20px;
|
|
255
|
-
margin: 20px 0;
|
|
256
|
-
background: #f9fafb;
|
|
257
|
-
}
|
|
258
|
-
.test-card h3 {
|
|
259
|
-
margin-top: 0;
|
|
260
|
-
color: #111827;
|
|
261
|
-
}
|
|
262
|
-
.badge {
|
|
263
|
-
display: inline-block;
|
|
264
|
-
padding: 2px 8px;
|
|
265
|
-
border-radius: 4px;
|
|
266
|
-
font-size: 12px;
|
|
267
|
-
font-weight: bold;
|
|
268
|
-
margin-left: 10px;
|
|
269
|
-
}
|
|
270
|
-
.badge-esm { background: #3b82f6; color: white; }
|
|
271
|
-
.badge-cjs { background: #8b5cf6; color: white; }
|
|
272
|
-
.badge-umd { background: #ec489a; color: white; }
|
|
273
|
-
.badge-iife { background: #10b981; color: white; }
|
|
274
|
-
</style>
|
|
275
|
-
</head>
|
|
276
|
-
<body>
|
|
277
|
-
<h1>๐งช @questwork/q-utilities - IIFE Build Test</h1>
|
|
278
|
-
<p>Testing the IIFE build in browser environment</p>
|
|
279
|
-
|
|
280
|
-
<div class="test-card">
|
|
281
|
-
<h3>๐ฆ qUtilities Global Object <span class="badge badge-iife">IIFE</span></h3>
|
|
282
|
-
<div id="test-results"></div>
|
|
283
|
-
</div>
|
|
284
|
-
|
|
285
|
-
<div class="test-card">
|
|
286
|
-
<h3>๐ง Available Utilities <span class="badge badge-iife">IIFE</span></h3>
|
|
287
|
-
<div id="utilities-list"></div>
|
|
288
|
-
</div>
|
|
289
|
-
|
|
290
|
-
<!-- Load the IIFE build -->
|
|
291
|
-
<script src="../dist/q-utilities.iife.js"></script>
|
|
292
|
-
|
|
293
|
-
<script>
|
|
294
|
-
const results = document.getElementById('test-results');
|
|
295
|
-
const utilitiesList = document.getElementById('utilities-list');
|
|
296
|
-
|
|
297
|
-
function addResult(message, isError = false, isWarning = false) {
|
|
298
|
-
const div = document.createElement('div');
|
|
299
|
-
div.textContent = message;
|
|
300
|
-
div.style.margin = '8px 0';
|
|
301
|
-
div.style.padding = '8px';
|
|
302
|
-
div.style.borderRadius = '4px';
|
|
303
|
-
|
|
304
|
-
if (isError) {
|
|
305
|
-
div.style.color = '#ef4444';
|
|
306
|
-
div.style.backgroundColor = '#fef2f2';
|
|
307
|
-
div.style.borderLeft = '4px solid #ef4444';
|
|
308
|
-
} else if (isWarning) {
|
|
309
|
-
div.style.color = '#f59e0b';
|
|
310
|
-
div.style.backgroundColor = '#fffbeb';
|
|
311
|
-
div.style.borderLeft = '4px solid #f59e0b';
|
|
312
|
-
} else {
|
|
313
|
-
div.style.color = '#22c55e';
|
|
314
|
-
div.style.backgroundColor = '#f0fdf4';
|
|
315
|
-
div.style.borderLeft = '4px solid #22c55e';
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
results.appendChild(div);
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
function addUtility(name, value) {
|
|
322
|
-
const div = document.createElement('div');
|
|
323
|
-
div.style.margin = '8px 0';
|
|
324
|
-
div.style.padding = '8px';
|
|
325
|
-
div.style.backgroundColor = '#f3f4f6';
|
|
326
|
-
div.style.borderRadius = '4px';
|
|
327
|
-
div.style.fontFamily = 'monospace';
|
|
328
|
-
|
|
329
|
-
const type = typeof value;
|
|
330
|
-
const typeColor = type === 'function' ? '#3b82f6' : '#8b5cf6';
|
|
331
|
-
|
|
332
|
-
div.innerHTML = \`
|
|
333
|
-
<strong style="color: #111827;">\${name}</strong>
|
|
334
|
-
<span style="color: \${typeColor}; margin-left: 10px;">(\${type})</span>
|
|
335
|
-
<pre style="margin-top: 8px; font-size: 11px; background: white;">\${JSON.stringify(value, null, 2).substring(0, 200)}\${JSON.stringify(value, null, 2).length > 200 ? '...' : ''}</pre>
|
|
336
|
-
\`;
|
|
337
|
-
|
|
338
|
-
utilitiesList.appendChild(div);
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
try {
|
|
342
|
-
// Check if library loaded
|
|
343
|
-
if (typeof window.qUtilities !== 'undefined') {
|
|
344
|
-
const { qUtilities } = window
|
|
345
|
-
const { displayName, TrackedEntity } = qUtilities
|
|
346
|
-
console.log(new TrackedEntity(), displayName)
|
|
347
|
-
|
|
348
|
-
addResult('โ
IIFE module loaded successfully');
|
|
349
|
-
addResult('๐ฆ Global export: qUtilities found on window');
|
|
350
|
-
|
|
351
|
-
const exports = Object.keys(window.qUtilities);
|
|
352
|
-
addResult(\`๐ฆ Exports found: \${exports.length} exports\`);
|
|
353
|
-
|
|
354
|
-
// List all exports
|
|
355
|
-
if (exports.length > 0) {
|
|
356
|
-
addResult(\`๐ Available exports: \${exports.join(', ')}\`);
|
|
357
|
-
|
|
358
|
-
// Show details of each export
|
|
359
|
-
exports.forEach(exp => {
|
|
360
|
-
const value = window.qUtilities[exp];
|
|
361
|
-
addUtility(exp, value);
|
|
362
|
-
});
|
|
363
|
-
} else {
|
|
364
|
-
addResult('โ ๏ธ No exports found in qUtilities object', false, true);
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
// Check for default export
|
|
368
|
-
if (window.qUtilities.default) {
|
|
369
|
-
addResult('โ
Default export exists');
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
addResult('โจ All IIFE tests passed!');
|
|
373
|
-
} else {
|
|
374
|
-
throw new Error('qUtilities not found on window object');
|
|
375
|
-
}
|
|
376
|
-
} catch (error) {
|
|
377
|
-
addResult('โ IIFE test failed: ' + error.message, true);
|
|
378
|
-
console.error(error);
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
// Check if any other Questwork globals exist
|
|
382
|
-
const questworkGlobals = Object.keys(window).filter(key =>
|
|
383
|
-
key.toLowerCase().includes('qutil') ||
|
|
384
|
-
key.toLowerCase().includes('quest') ||
|
|
385
|
-
key === 'qUtilities'
|
|
386
|
-
);
|
|
387
|
-
|
|
388
|
-
if (questworkGlobals.length > 1) {
|
|
389
|
-
console.log('Other Questwork globals found:', questworkGlobals);
|
|
390
|
-
}
|
|
391
|
-
</script>
|
|
392
|
-
</body>
|
|
393
|
-
</html>
|
|
394
|
-
`
|
|
395
|
-
|
|
396
|
-
fs.writeFileSync(htmlPath, html)
|
|
397
|
-
|
|
398
|
-
console.log('๐ Test HTML created at:', htmlPath)
|
|
399
|
-
console.log('๐ You can open it in browser:')
|
|
400
|
-
console.log(` file://${htmlPath}\n`)
|
|
401
|
-
|
|
402
|
-
// Start a simple server for better testing
|
|
403
|
-
const server = http.createServer((req, res) => {
|
|
404
|
-
// Map requests to files
|
|
405
|
-
let filePath = req.url === '/' ? htmlPath : path.join(PROJECT_ROOT, req.url)
|
|
406
|
-
|
|
407
|
-
// Security: only serve files within project
|
|
408
|
-
if (!filePath.startsWith(PROJECT_ROOT)) {
|
|
409
|
-
res.writeHead(403)
|
|
410
|
-
res.end('Forbidden')
|
|
411
|
-
return
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
// Check if file exists
|
|
415
|
-
if (!fs.existsSync(filePath)) {
|
|
416
|
-
res.writeHead(404)
|
|
417
|
-
res.end('Not found')
|
|
418
|
-
return
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
const ext = path.extname(filePath)
|
|
422
|
-
const contentType = {
|
|
423
|
-
'.html': 'text/html',
|
|
424
|
-
'.js': 'application/javascript',
|
|
425
|
-
'.css': 'text/css',
|
|
426
|
-
'.json': 'application/json',
|
|
427
|
-
'.map': 'application/json',
|
|
428
|
-
'.cjs': 'application/javascript',
|
|
429
|
-
'.mjs': 'application/javascript'
|
|
430
|
-
}[ext] || 'text/plain'
|
|
431
|
-
|
|
432
|
-
fs.readFile(filePath, (err, data) => {
|
|
433
|
-
if (err) {
|
|
434
|
-
res.writeHead(500)
|
|
435
|
-
res.end('Server error')
|
|
436
|
-
} else {
|
|
437
|
-
res.writeHead(200, {
|
|
438
|
-
'Content-Type': contentType,
|
|
439
|
-
'Cache-Control': 'no-cache'
|
|
440
|
-
})
|
|
441
|
-
res.end(data)
|
|
442
|
-
}
|
|
443
|
-
})
|
|
444
|
-
})
|
|
445
|
-
|
|
446
|
-
server.listen(3000, () => {
|
|
447
|
-
console.log('๐ Test server running at http://localhost:3000')
|
|
448
|
-
console.log(' Open this URL to test IIFE build in browser')
|
|
449
|
-
console.log(' Press Ctrl+C to stop server when done\n')
|
|
450
|
-
})
|
|
451
|
-
|
|
452
|
-
return server
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
// Test UMD format in browser (using script tag)
|
|
456
|
-
async function testUMDInBrowser() {
|
|
457
|
-
console.log('\n๐งช Testing UMD format in browser...')
|
|
458
|
-
|
|
459
|
-
const htmlPath = path.join(PROJECT_ROOT, 'tests/test-umd.html')
|
|
460
|
-
|
|
461
|
-
const html = `
|
|
462
|
-
<!DOCTYPE html>
|
|
463
|
-
<html>
|
|
464
|
-
<head>
|
|
465
|
-
<title>UMD Test - @questwork/q-utilities</title>
|
|
466
|
-
<style>
|
|
467
|
-
body { font-family: monospace; padding: 20px; }
|
|
468
|
-
.success { color: green; }
|
|
469
|
-
.error { color: red; }
|
|
470
|
-
pre { background: #f5f5f5; padding: 10px; border-radius: 5px; }
|
|
471
|
-
</style>
|
|
472
|
-
</head>
|
|
473
|
-
<body>
|
|
474
|
-
<h1>๐งช UMD Build Test (Browser)</h1>
|
|
475
|
-
<div id="results"></div>
|
|
476
|
-
|
|
477
|
-
<!-- Load UMD build -->
|
|
478
|
-
<script src="../dist/q-utilities.umd.js"></script>
|
|
479
|
-
|
|
480
|
-
<script>
|
|
481
|
-
const results = document.getElementById('results');
|
|
482
|
-
|
|
483
|
-
function addResult(message, isError = false) {
|
|
484
|
-
const div = document.createElement('div');
|
|
485
|
-
div.textContent = message;
|
|
486
|
-
div.style.color = isError ? 'red' : 'green';
|
|
487
|
-
div.style.margin = '5px 0';
|
|
488
|
-
results.appendChild(div);
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
try {
|
|
492
|
-
if (typeof window.qUtilities !== 'undefined') {
|
|
493
|
-
const { qUtilities } = window
|
|
494
|
-
const { displayName, TrackedEntity } = qUtilities
|
|
495
|
-
console.log(new TrackedEntity(), displayName)
|
|
496
|
-
|
|
497
|
-
addResult('โ
UMD module loaded successfully');
|
|
498
|
-
addResult('๐ฆ Exports: ' + JSON.stringify(Object.keys(window.qUtilities)));
|
|
499
|
-
addResult('โจ All UMD tests passed!');
|
|
500
|
-
} else {
|
|
501
|
-
throw new Error('qUtilities not found');
|
|
502
|
-
}
|
|
503
|
-
} catch (error) {
|
|
504
|
-
addResult('โ UMD test failed: ' + error.message, true);
|
|
505
|
-
}
|
|
506
|
-
</script>
|
|
507
|
-
</body>
|
|
508
|
-
</html>
|
|
509
|
-
`
|
|
510
|
-
|
|
511
|
-
fs.writeFileSync(htmlPath, html)
|
|
512
|
-
console.log('๐ UMD test HTML created at:', htmlPath)
|
|
513
|
-
console.log(' http://localhost:3000/tests/test-umd.html')
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
// Main test runner
|
|
517
|
-
async function runTests() {
|
|
518
|
-
console.log('๐ Starting runtime tests for @questwork/q-utilities\n')
|
|
519
|
-
console.log('=' .repeat(60))
|
|
520
|
-
|
|
521
|
-
// Check build first
|
|
522
|
-
checkBuild()
|
|
523
|
-
|
|
524
|
-
// Run Node.js tests
|
|
525
|
-
const esmPassed = await testESM()
|
|
526
|
-
const cjsPassed = await testCJS()
|
|
527
|
-
const umdPassed = await testUMD()
|
|
528
|
-
|
|
529
|
-
// Display results
|
|
530
|
-
console.log('\n' + '=' .repeat(60))
|
|
531
|
-
console.log('\n๐ Test Results:\n')
|
|
532
|
-
console.log(`ESM (import): ${esmPassed ? 'โ
PASSED' : 'โ FAILED'}`)
|
|
533
|
-
console.log(`CJS (require): ${cjsPassed ? 'โ
PASSED' : 'โ FAILED'}`)
|
|
534
|
-
console.log(`UMD (require): ${umdPassed ? 'โ
PASSED' : 'โ FAILED'}`)
|
|
535
|
-
|
|
536
|
-
if (esmPassed && cjsPassed && umdPassed) {
|
|
537
|
-
console.log('\nโจ All Node.js tests passed!')
|
|
538
|
-
} else {
|
|
539
|
-
console.log('\nโ ๏ธ Some Node.js tests failed')
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
// Generate browser test files
|
|
543
|
-
await testUMDInBrowser()
|
|
544
|
-
|
|
545
|
-
// Start IIFE test server
|
|
546
|
-
const server = await testIIFE()
|
|
547
|
-
|
|
548
|
-
console.log('\n๐ Browser Test Instructions:')
|
|
549
|
-
console.log('1. Open http://localhost:3000 to test IIFE build')
|
|
550
|
-
console.log('2. Open http://localhost:3000/tests/test-umd.html to test UMD build')
|
|
551
|
-
console.log('3. Check browser console for detailed logs')
|
|
552
|
-
console.log('\nPress Ctrl+C to stop the server\n')
|
|
553
|
-
|
|
554
|
-
// Keep server running
|
|
555
|
-
process.on('SIGINT', () => {
|
|
556
|
-
console.log('\n๐ Shutting down test server...')
|
|
557
|
-
server.close()
|
|
558
|
-
process.exit(0)
|
|
559
|
-
})
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
// Run tests
|
|
563
|
-
runTests().catch(console.error)
|
package/tsconfig.json
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2020",
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"lib": ["ES2020"],
|
|
6
|
-
"allowJs": true,
|
|
7
|
-
"checkJs": false,
|
|
8
|
-
"jsx": "preserve",
|
|
9
|
-
"declaration": true,
|
|
10
|
-
"declarationMap": true,
|
|
11
|
-
"sourceMap": true,
|
|
12
|
-
"outDir": "./dist",
|
|
13
|
-
"rootDir": "./lib",
|
|
14
|
-
"strict": false,
|
|
15
|
-
"moduleResolution": "node",
|
|
16
|
-
"allowSyntheticDefaultImports": true,
|
|
17
|
-
"esModuleInterop": true,
|
|
18
|
-
"skipLibCheck": true,
|
|
19
|
-
"forceConsistentCasingInFileNames": true
|
|
20
|
-
},
|
|
21
|
-
"include": [
|
|
22
|
-
"lib/**/*"
|
|
23
|
-
],
|
|
24
|
-
"exclude": [
|
|
25
|
-
"node_modules",
|
|
26
|
-
"dist"
|
|
27
|
-
]
|
|
28
|
-
}
|
package/vite.config.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from 'vite'
|
|
2
|
-
import path from 'path'
|
|
3
|
-
import dts from 'vite-plugin-dts'
|
|
4
|
-
|
|
5
|
-
export default defineConfig({
|
|
6
|
-
plugins: [
|
|
7
|
-
dts({
|
|
8
|
-
include: ['lib/**/*.js', 'lib/**/*.ts'],
|
|
9
|
-
exclude: ['**/*.spec.js', '**/*.spec.ts'],
|
|
10
|
-
rollupTypes: true,
|
|
11
|
-
outDir: 'dist',
|
|
12
|
-
rootDir: 'lib',
|
|
13
|
-
}),
|
|
14
|
-
],
|
|
15
|
-
build: {
|
|
16
|
-
outDir: 'dist',
|
|
17
|
-
sourcemap: true,
|
|
18
|
-
lib: {
|
|
19
|
-
entry: path.resolve(__dirname, 'lib/index.ts'),
|
|
20
|
-
name: 'qUtilities', // This is the global variable name for IIFE/UMD
|
|
21
|
-
fileName: (format) => {
|
|
22
|
-
if (format === 'es') return 'q-utilities.esm.js'
|
|
23
|
-
if (format === 'cjs') return 'q-utilities.cjs'
|
|
24
|
-
if (format === 'umd') return 'q-utilities.umd.js'
|
|
25
|
-
if (format === 'iife') return 'q-utilities.iife.js'
|
|
26
|
-
return `q-utilities.${format}.js`
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
rollupOptions: {
|
|
30
|
-
external: [],
|
|
31
|
-
output: [
|
|
32
|
-
{
|
|
33
|
-
format: 'es',
|
|
34
|
-
generatedCode: 'es2015',
|
|
35
|
-
exports: 'named',
|
|
36
|
-
preserveModules: false
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
format: 'cjs',
|
|
40
|
-
exports: 'named',
|
|
41
|
-
interop: 'auto'
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
format: 'umd',
|
|
45
|
-
name: 'qUtilities',
|
|
46
|
-
exports: 'named',
|
|
47
|
-
extend: true,
|
|
48
|
-
esModule: true,
|
|
49
|
-
interop: 'auto'
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
format: 'iife',
|
|
53
|
-
name: 'qUtilities',
|
|
54
|
-
exports: 'named',
|
|
55
|
-
extend: true,
|
|
56
|
-
esModule: false,
|
|
57
|
-
interop: 'auto'
|
|
58
|
-
},
|
|
59
|
-
],
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
test: {
|
|
63
|
-
environment: 'node',
|
|
64
|
-
coverage: {
|
|
65
|
-
reporter: ['text', 'html'],
|
|
66
|
-
},
|
|
67
|
-
globals: true,
|
|
68
|
-
setupFiles: ['lib/test.setup.js', 'lib/helpers/test.setup.js'],
|
|
69
|
-
mocha: {
|
|
70
|
-
ui: 'bdd',
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
})
|
package/vitest.config.js
DELETED