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

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