@atlaspack/cli 2.14.17-dev-compiled-hash-e5f8a1735.0 → 2.14.17

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,462 +0,0 @@
1
- import {NodeFS} from '@atlaspack/fs';
2
- import logger from '@atlaspack/logger';
3
- import commander from 'commander';
4
- import path from 'path';
5
- import {normalizeOptions, Options} from './normalizeOptions';
6
- import type {CommandExt} from './normalizeOptions';
7
- import {applyOptions} from './applyOptions';
8
- import {commonOptions} from './options';
9
- import {handleUncaughtException} from './handleUncaughtException';
10
-
11
- interface ComparisonOptions extends Options {
12
- fixturesPath?: string;
13
- configPath?: string;
14
- outputDir?: string;
15
- fixtureGlob?: string;
16
- }
17
-
18
- interface TransformerResult {
19
- code: string;
20
- map?: string;
21
- styleRules?: any;
22
- assets?: any[];
23
- }
24
-
25
- interface ComparisonResult {
26
- fixture: string;
27
- atlaspack: TransformerResult | null;
28
- parcel: TransformerResult | null;
29
- match: boolean;
30
- error?: string;
31
- }
32
-
33
- export function makeCompareCompiledCommand(): commander.Command {
34
- const compareCompiled = new commander.Command('compare-compiled-css [input...]')
35
- .description('Compare Atlaspack and Parcel Compiled CSS transformers')
36
- .option(
37
- '--fixtures-path <path>',
38
- 'Path to fixtures directory',
39
- path.join(process.cwd(), 'crates/atlassian-swc-compiled-css/tests/fixtures')
40
- )
41
- .option(
42
- '--config-path <path>',
43
- 'Path to .compiledcssrc config file',
44
- './.compiledcssrc'
45
- )
46
- .option(
47
- '--output-dir <path>',
48
- 'Directory to write comparison results',
49
- './comparison-results'
50
- )
51
- .option(
52
- '--fixture-glob <pattern>',
53
- 'Glob pattern for fixture files',
54
- '**/in.jsx'
55
- )
56
- .action(async (args: string[], opts: ComparisonOptions & Options, command: CommandExt) => {
57
- try {
58
- await runCompareCompiled(args, opts, command);
59
- } catch (err: any) {
60
- handleUncaughtException(err);
61
- }
62
- });
63
-
64
- applyOptions(compareCompiled, commonOptions);
65
- return compareCompiled;
66
- }
67
-
68
- async function runCompareCompiled(args: string[], opts: ComparisonOptions & Options, command: CommandExt) {
69
- const fs = new NodeFS();
70
- Object.assign(command, opts);
71
- const options = await normalizeOptions(command, fs);
72
-
73
- // Load configuration
74
- const configPath = path.resolve(opts.configPath || './.compiledcssrc');
75
- let config = {};
76
-
77
- try {
78
- const configContent = await fs.readFile(configPath);
79
- config = JSON.parse(configContent);
80
- logger.info({
81
- message: `Loaded config from ${configPath}`,
82
- origin: '@atlaspack/cli'
83
- });
84
- } catch (err) {
85
- logger.warn({
86
- message: `Could not load config from ${configPath}, using default config`,
87
- origin: '@atlaspack/cli'
88
- });
89
- }
90
-
91
- // Find fixture files
92
- const fixturesPath = path.resolve(opts.fixturesPath ||
93
- path.join(process.cwd(), 'crates/atlassian-swc-compiled-css/tests/fixtures'));
94
- const fixtureGlob = opts.fixtureGlob || '**/in.jsx';
95
-
96
- const fixtureFiles = await findFixtureFiles(fs, fixturesPath, fixtureGlob);
97
-
98
- logger.info({
99
- message: `Found ${fixtureFiles.length} fixture files in ${fixturesPath}`,
100
- origin: '@atlaspack/cli'
101
- });
102
-
103
- if (fixtureFiles.length === 0) {
104
- logger.warn({
105
- message: `No fixture files found matching pattern ${fixtureGlob} in ${fixturesPath}`,
106
- origin: '@atlaspack/cli'
107
- });
108
- return;
109
- }
110
-
111
- // Create output directory
112
- const outputDir = path.resolve(opts.outputDir || './comparison-results');
113
- try {
114
- await fs.mkdirp(outputDir);
115
- } catch (err) {
116
- // Directory might already exist
117
- }
118
-
119
- // Initialize Atlaspack
120
- const Atlaspack = require('@atlaspack/core').default;
121
- const atlaspack = new Atlaspack({
122
- entries: ['.'],
123
- defaultConfig: require.resolve('@atlaspack/config-default', {
124
- paths: [fs.cwd(), __dirname],
125
- }),
126
- shouldPatchConsole: false,
127
- shouldBuildLazily: false,
128
- ...options,
129
- mode: 'development',
130
- env: {
131
- NODE_ENV: 'development'
132
- }
133
- });
134
-
135
- // For now, we'll focus on comparing Atlaspack output with expected output from fixtures
136
- // TODO: Add @compiled/parcel-transformer comparison when dependencies are resolved
137
-
138
- const results: ComparisonResult[] = [];
139
- let successCount = 0;
140
- let errorCount = 0;
141
-
142
- // Process each fixture
143
- for (const fixtureFile of fixtureFiles) {
144
- const relativePath = path.relative(fixturesPath, fixtureFile);
145
- const fixtureName = path.dirname(relativePath);
146
-
147
- logger.info({
148
- message: `Processing fixture: ${fixtureName}`,
149
- origin: '@atlaspack/cli'
150
- });
151
-
152
- try {
153
- // Transform with Atlaspack
154
- const atlaspackResult = await transformWithAtlaspack(atlaspack, fixtureFile, config);
155
-
156
- // Load expected output from fixture directory
157
- const expectedResult = await loadExpectedResult(fs, fixtureFile);
158
-
159
- // Compare results
160
- const match = compareResults(atlaspackResult, expectedResult);
161
-
162
- const result: ComparisonResult = {
163
- fixture: fixtureName,
164
- atlaspack: atlaspackResult,
165
- parcel: expectedResult,
166
- match
167
- };
168
-
169
- results.push(result);
170
-
171
- if (match) {
172
- successCount++;
173
- logger.info({
174
- message: `✓ ${fixtureName}: Results match`,
175
- origin: '@atlaspack/cli'
176
- });
177
- } else {
178
- errorCount++;
179
- logger.warn({
180
- message: `✗ ${fixtureName}: Results differ`,
181
- origin: '@atlaspack/cli'
182
- });
183
- }
184
-
185
- // Write individual result files
186
- await writeResultFiles(fs, outputDir, fixtureName, result);
187
-
188
- } catch (err: any) {
189
- errorCount++;
190
- const result: ComparisonResult = {
191
- fixture: fixtureName,
192
- atlaspack: null,
193
- parcel: null,
194
- match: false,
195
- error: err.message
196
- };
197
- results.push(result);
198
-
199
- logger.error({
200
- message: `✗ ${fixtureName}: Error processing fixture: ${err.message}`,
201
- origin: '@atlaspack/cli'
202
- });
203
- }
204
- }
205
-
206
- // Write summary report
207
- await writeSummaryReport(fs, outputDir, results);
208
-
209
- // Log final summary
210
- logger.info({
211
- message: `\n=== Comparison Summary ===\n` +
212
- `Total fixtures: ${results.length}\n` +
213
- `Matches: ${successCount}\n` +
214
- `Mismatches: ${errorCount}\n` +
215
- `Results written to: ${outputDir}`,
216
- origin: '@atlaspack/cli'
217
- });
218
-
219
- process.exit(errorCount > 0 ? 1 : 0);
220
- }
221
-
222
- async function transformWithAtlaspack(atlaspack: any, filePath: string, config: any): Promise<TransformerResult> {
223
- try {
224
- const assets = await atlaspack.unstable_transform({
225
- filePath,
226
- env: {
227
- NODE_ENV: 'development',
228
- context: 'browser'
229
- },
230
- config
231
- });
232
-
233
- const mainAsset = assets[0];
234
- if (!mainAsset) {
235
- throw new Error('No assets returned from transformation');
236
- }
237
-
238
- return {
239
- code: await mainAsset.getCode(),
240
- map: await mainAsset.getMapBuffer()?.toString(),
241
- styleRules: mainAsset.meta.styleRules,
242
- assets: assets.map((asset: any) => ({
243
- type: asset.type,
244
- code: asset.getCode(),
245
- meta: asset.meta
246
- }))
247
- };
248
- } catch (err: any) {
249
- throw new Error(`Atlaspack transform failed: ${err.message}`);
250
- }
251
- }
252
-
253
- async function findFixtureFiles(fs: NodeFS, fixturesPath: string, pattern: string): Promise<string[]> {
254
- try {
255
- const files: string[] = [];
256
-
257
- async function walkDir(dir: string) {
258
- const entries = await fs.readdir(dir);
259
-
260
- for (const entry of entries) {
261
- const fullPath = path.join(dir, entry);
262
- const stat = await fs.stat(fullPath);
263
-
264
- if (stat.isDirectory()) {
265
- await walkDir(fullPath);
266
- } else if (entry === 'in.jsx' || entry === 'in.js' || entry === 'in.ts' || entry === 'in.tsx') {
267
- files.push(fullPath);
268
- }
269
- }
270
- }
271
-
272
- await walkDir(fixturesPath);
273
- return files;
274
- } catch (err: any) {
275
- throw new Error(`Failed to find fixture files: ${err.message}`);
276
- }
277
- }
278
-
279
- async function loadExpectedResult(fs: NodeFS, fixtureFile: string): Promise<TransformerResult | null> {
280
- const fixtureDir = path.dirname(fixtureFile);
281
-
282
- // Try to load expected output files (out.js, actual.js, etc.)
283
- const expectedFiles = ['out.js', 'actual.js', 'expected.js'];
284
-
285
- for (const expectedFile of expectedFiles) {
286
- const expectedPath = path.join(fixtureDir, expectedFile);
287
-
288
- try {
289
- const content = await fs.readFile(expectedPath, 'utf8');
290
-
291
- // Also try to load style rules if available
292
- let styleRules = null;
293
- try {
294
- const styleRulesPath = path.join(fixtureDir, 'style-rules.json');
295
- const styleRulesContent = await fs.readFile(styleRulesPath, 'utf8');
296
- styleRules = JSON.parse(styleRulesContent);
297
- } catch {
298
- // Style rules file might not exist
299
- }
300
-
301
- return {
302
- code: content,
303
- styleRules,
304
- assets: []
305
- };
306
- } catch {
307
- // Try next expected file
308
- continue;
309
- }
310
- }
311
-
312
- return null;
313
- }
314
-
315
- function compareResults(atlaspack: TransformerResult | null, parcel: TransformerResult | null): boolean {
316
- if (!atlaspack && !parcel) return true;
317
- if (!atlaspack || !parcel) return false;
318
-
319
- // Normalize and compare code output
320
- const normalizeCode = (code: string) => {
321
- return code
322
- .replace(/\s+/g, ' ') // Normalize whitespace
323
- .replace(/;+/g, ';') // Normalize semicolons
324
- .trim();
325
- };
326
-
327
- const atlaspackCode = normalizeCode(atlaspack.code);
328
- const parcelCode = normalizeCode(parcel.code);
329
-
330
- return atlaspackCode === parcelCode;
331
- }
332
-
333
- async function writeResultFiles(fs: NodeFS, outputDir: string, fixtureName: string, result: ComparisonResult) {
334
- const fixtureDir = path.join(outputDir, fixtureName);
335
- await fs.mkdirp(fixtureDir);
336
-
337
- // Write Atlaspack result
338
- if (result.atlaspack) {
339
- await fs.writeFile(
340
- path.join(fixtureDir, 'atlaspack.js'),
341
- result.atlaspack.code
342
- );
343
- if (result.atlaspack.styleRules) {
344
- await fs.writeFile(
345
- path.join(fixtureDir, 'atlaspack.style-rules.json'),
346
- JSON.stringify(result.atlaspack.styleRules, null, 2)
347
- );
348
- }
349
- }
350
-
351
- // Write Expected result (from fixtures)
352
- if (result.parcel) {
353
- await fs.writeFile(
354
- path.join(fixtureDir, 'expected.js'),
355
- result.parcel.code
356
- );
357
- }
358
-
359
- // Write comparison result
360
- const comparisonInfo = {
361
- fixture: result.fixture,
362
- match: result.match,
363
- error: result.error,
364
- hasAtlaspack: !!result.atlaspack,
365
- hasExpected: !!result.parcel,
366
- timestamp: new Date().toISOString()
367
- };
368
-
369
- await fs.writeFile(
370
- path.join(fixtureDir, 'comparison.json'),
371
- JSON.stringify(comparisonInfo, null, 2)
372
- );
373
-
374
- // Write diff if results don't match
375
- if (result.atlaspack && result.parcel && !result.match) {
376
- const diff = createSimpleDiff(result.atlaspack.code, result.parcel.code);
377
- await fs.writeFile(
378
- path.join(fixtureDir, 'diff.txt'),
379
- diff
380
- );
381
- }
382
- }
383
-
384
- function createSimpleDiff(atlaspack: string, parcel: string): string {
385
- const atlaspackLines = atlaspack.split('\n');
386
- const parcelLines = parcel.split('\n');
387
-
388
- let diff = '--- Atlaspack Output\n+++ Parcel Output\n\n';
389
-
390
- const maxLines = Math.max(atlaspackLines.length, parcelLines.length);
391
-
392
- for (let i = 0; i < maxLines; i++) {
393
- const atlaspackLine = atlaspackLines[i] || '';
394
- const parcelLine = parcelLines[i] || '';
395
-
396
- if (atlaspackLine !== parcelLine) {
397
- if (atlaspackLine) {
398
- diff += `- ${atlaspackLine}\n`;
399
- }
400
- if (parcelLine) {
401
- diff += `+ ${parcelLine}\n`;
402
- }
403
- } else if (atlaspackLine) {
404
- diff += ` ${atlaspackLine}\n`;
405
- }
406
- }
407
-
408
- return diff;
409
- }
410
-
411
- async function writeSummaryReport(fs: NodeFS, outputDir: string, results: ComparisonResult[]) {
412
- const summary = {
413
- timestamp: new Date().toISOString(),
414
- total: results.length,
415
- matches: results.filter(r => r.match).length,
416
- mismatches: results.filter(r => !r.match).length,
417
- errors: results.filter(r => r.error).length,
418
- results: results.map(r => ({
419
- fixture: r.fixture,
420
- match: r.match,
421
- error: r.error,
422
- hasAtlaspack: !!r.atlaspack,
423
- hasExpected: !!r.parcel
424
- }))
425
- };
426
-
427
- await fs.writeFile(
428
- path.join(outputDir, 'summary.json'),
429
- JSON.stringify(summary, null, 2)
430
- );
431
-
432
- // Create markdown report
433
- let markdown = `# Compiled CSS Transformer Comparison Report\n\n`;
434
- markdown += `**Generated:** ${summary.timestamp}\n\n`;
435
- markdown += `## Summary\n\n`;
436
- markdown += `- **Total Fixtures:** ${summary.total}\n`;
437
- markdown += `- **Matches:** ${summary.matches}\n`;
438
- markdown += `- **Mismatches:** ${summary.mismatches}\n`;
439
- markdown += `- **Errors:** ${summary.errors}\n\n`;
440
-
441
- if (summary.mismatches > 0 || summary.errors > 0) {
442
- markdown += `## Issues\n\n`;
443
-
444
- for (const result of results) {
445
- if (!result.match || result.error) {
446
- markdown += `### ${result.fixture}\n\n`;
447
- if (result.error) {
448
- markdown += `**Error:** ${result.error}\n\n`;
449
- } else {
450
- markdown += `**Status:** Outputs differ\n`;
451
- markdown += `**Atlaspack:** ${result.atlaspack ? 'Success' : 'Failed'}\n`;
452
- markdown += `**Expected:** ${result.parcel ? 'Found' : 'Missing'}\n\n`;
453
- }
454
- }
455
- }
456
- }
457
-
458
- await fs.writeFile(
459
- path.join(outputDir, 'report.md'),
460
- markdown
461
- );
462
- }