@traceletdev/cli 0.5.0 → 0.5.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/README.md CHANGED
@@ -131,7 +131,7 @@ Install the extension and get instant feedback on save.
131
131
  ```json
132
132
  {
133
133
  "scripts": {
134
- "postbuild": "node node_modules/@traceletdev/next/collect.js"
134
+ "postbuild": "tracelet-next collect"
135
135
  }
136
136
  }
137
137
  ```
package/bin/tracelet.js CHANGED
@@ -3,42 +3,42 @@
3
3
  'use strict';
4
4
 
5
5
  const { spawn } = require('child_process');
6
- const path = require('path');
7
6
  const fs = require('fs');
8
7
 
9
8
  // Platform detection
10
- const platform = process.platform;
11
- const arch = process.arch;
12
-
13
- // Map Node.js platform/arch to our binary names
14
- const platformMap = {
15
- 'darwin': platform === 'darwin' ? (arch === 'arm64' ? 'darwin-arm64' : 'darwin-x64') : null,
16
- 'linux': platform === 'linux' ? (arch === 'arm64' ? 'linux-arm64' : 'linux-x64') : null,
17
- 'win32': platform === 'win32' ? (arch === 'arm64' ? 'win32-arm64' : 'win32-x64') : null,
18
- };
19
-
20
- const binaryDir = platformMap[platform] || platformMap[process.platform];
21
- if (!binaryDir) {
9
+ const platform = process.platform; // 'darwin' | 'linux' | 'win32'
10
+ const arch = process.arch; // 'arm64' | 'x64'
11
+
12
+ const supportedPlatforms = new Set(['darwin', 'linux', 'win32']);
13
+ const supportedArches = new Set(['arm64', 'x64']);
14
+
15
+ if (!supportedPlatforms.has(platform) || !supportedArches.has(arch)) {
22
16
  console.error(`[tracelet] Unsupported platform: ${platform}-${arch}`);
23
17
  process.exit(1);
24
18
  }
25
19
 
26
20
  const binaryName = platform === 'win32' ? 'tracelet.exe' : 'tracelet';
27
- const binaryPath = path.join(__dirname, '..', 'binaries', binaryDir, binaryName);
28
-
29
- // Check if binary exists
30
- if (!fs.existsSync(binaryPath)) {
31
- console.error(`[tracelet] Binary not found at ${binaryPath}`);
32
- console.error(`[tracelet] Please run 'npm run postinstall' or reinstall the package`);
21
+ const packageName = `@traceletdev/cli-${platform}-${arch}`;
22
+
23
+ // The binary ships in a per-platform optionalDependency (os/cpu-gated), so npm
24
+ // only installs the one matching package. require.resolve finds it without
25
+ // needing a postinstall copy/symlink step.
26
+ let binaryPath;
27
+ try {
28
+ binaryPath = require.resolve(`${packageName}/bin/${binaryName}`);
29
+ } catch (err) {
30
+ console.error(`[tracelet] Could not find the platform binary package "${packageName}".`);
31
+ console.error(
32
+ `[tracelet] This usually means npm skipped installing it (platform mismatch) or the install failed. Try reinstalling.`
33
+ );
33
34
  process.exit(1);
34
35
  }
35
36
 
36
- // Make binary executable on Unix-like systems
37
37
  if (platform !== 'win32') {
38
38
  try {
39
- fs.chmodSync(binaryPath, '755');
39
+ fs.chmodSync(binaryPath, 0o755);
40
40
  } catch (e) {
41
- // Ignore if chmod fails
41
+ // Ignore if chmod fails — the tarball should already preserve the bit.
42
42
  }
43
43
  }
44
44
 
@@ -55,6 +55,5 @@ child.on('error', (err) => {
55
55
  });
56
56
 
57
57
  child.on('exit', (code) => {
58
- process.exit(code || 0);
58
+ process.exit(code === null ? 1 : code);
59
59
  });
60
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@traceletdev/cli",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "Performance toolkit that brings Lighthouse-level insight and ESLint-level ergonomics",
5
5
  "type": "commonjs",
6
6
  "main": "bin/tracelet.js",
@@ -10,8 +10,15 @@
10
10
  "publishConfig": {
11
11
  "access": "public"
12
12
  },
13
+ "optionalDependencies": {
14
+ "@traceletdev/cli-darwin-arm64": "0.5.1",
15
+ "@traceletdev/cli-darwin-x64": "0.5.1",
16
+ "@traceletdev/cli-linux-arm64": "0.5.1",
17
+ "@traceletdev/cli-linux-x64": "0.5.1",
18
+ "@traceletdev/cli-win32-arm64": "0.5.1",
19
+ "@traceletdev/cli-win32-x64": "0.5.1"
20
+ },
13
21
  "scripts": {
14
- "postinstall": "node scripts/postinstall.js",
15
22
  "build:bin": "echo 'Run: goreleaser release --snapshot to build binaries, or use go build'",
16
23
  "pack:bin": "node scripts/pack-binaries.js",
17
24
  "prepare:publish": "npm run pack:bin && npm run test:packages",
@@ -38,7 +45,8 @@
38
45
  "typescript-eslint": "^8.62.1"
39
46
  },
40
47
  "workspaces": [
41
- "packages/*"
48
+ "packages/*",
49
+ "!packages/cli-*"
42
50
  ],
43
51
  "keywords": [
44
52
  "performance",
@@ -57,8 +65,6 @@
57
65
  },
58
66
  "files": [
59
67
  "bin/",
60
- "binaries/",
61
- "scripts/",
62
68
  "README.md",
63
69
  "LICENSE",
64
70
  "package.json"
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -1,132 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- 'use strict';
4
-
5
- const fs = require('fs');
6
- const path = require('path');
7
-
8
- /**
9
- * Pack Go binaries into npm package structure
10
- *
11
- * Expects binaries to be built and placed in dist/ directory
12
- * (by GoReleaser or manual build)
13
- *
14
- * Structure:
15
- * dist/
16
- * tracelet_darwin_amd64/tracelet
17
- * tracelet_darwin_arm64/tracelet
18
- * tracelet_linux_amd64/tracelet
19
- * tracelet_linux_arm64/tracelet
20
- * tracelet_windows_amd64/tracelet.exe
21
- * tracelet_windows_arm64/tracelet.exe
22
- *
23
- * Output:
24
- * binaries/
25
- * darwin-x64/tracelet
26
- * darwin-arm64/tracelet
27
- * linux-x64/tracelet
28
- * linux-arm64/tracelet
29
- * win32-x64/tracelet.exe
30
- * win32-arm64/tracelet.exe
31
- */
32
-
33
- const distDir = path.join(__dirname, '..', 'dist');
34
- const binariesDir = path.join(__dirname, '..', 'binaries');
35
-
36
- // Map from GoReleaser naming to npm naming
37
- const platformMap = {
38
- darwin: {
39
- amd64: { dir: 'darwin-x64', name: 'tracelet' },
40
- arm64: { dir: 'darwin-arm64', name: 'tracelet' },
41
- },
42
- linux: {
43
- amd64: { dir: 'linux-x64', name: 'tracelet' },
44
- arm64: { dir: 'linux-arm64', name: 'tracelet' },
45
- },
46
- windows: {
47
- amd64: { dir: 'win32-x64', name: 'tracelet.exe' },
48
- arm64: { dir: 'win32-arm64', name: 'tracelet.exe' },
49
- },
50
- };
51
-
52
- function packBinaries() {
53
- if (!fs.existsSync(distDir)) {
54
- console.error('dist/ directory not found. Run GoReleaser or build binaries first.');
55
- process.exit(1);
56
- }
57
-
58
- // Create binaries directory structure
59
- if (!fs.existsSync(binariesDir)) {
60
- fs.mkdirSync(binariesDir, { recursive: true });
61
- }
62
-
63
- let packed = 0;
64
- let skipped = 0;
65
-
66
- // Find all directories in dist/
67
- const entries = fs.readdirSync(distDir, { withFileTypes: true });
68
-
69
- for (const entry of entries) {
70
- if (!entry.isDirectory()) continue;
71
-
72
- const dirName = entry.name;
73
- // Expected format: tracelet_<os>_<arch> or tracelet_<os>_<arch>v7
74
- const match = dirName.match(/^tracelet_(darwin|linux|windows)_(amd64|arm64)(?:v\d+)?$/);
75
- if (!match) {
76
- console.warn(`Skipping unknown directory: ${dirName}`);
77
- skipped++;
78
- continue;
79
- }
80
-
81
- const [, goos, goarch] = match;
82
- const mapping = platformMap[goos]?.[goarch];
83
- if (!mapping) {
84
- console.warn(`No mapping for ${goos}/${goarch}`);
85
- skipped++;
86
- continue;
87
- }
88
-
89
- const sourceDir = path.join(distDir, dirName);
90
- const sourceBinary = path.join(sourceDir, mapping.name);
91
- const targetDir = path.join(binariesDir, mapping.dir);
92
- const targetBinary = path.join(targetDir, mapping.name);
93
-
94
- if (!fs.existsSync(sourceBinary)) {
95
- console.warn(`Binary not found: ${sourceBinary}`);
96
- skipped++;
97
- continue;
98
- }
99
-
100
- // Create target directory
101
- if (!fs.existsSync(targetDir)) {
102
- fs.mkdirSync(targetDir, { recursive: true });
103
- }
104
-
105
- // Copy binary
106
- fs.copyFileSync(sourceBinary, targetBinary);
107
-
108
- // Make executable on Unix
109
- if (goos !== 'windows') {
110
- fs.chmodSync(targetBinary, '755');
111
- }
112
-
113
- console.log(`✓ Packed ${goos}/${goarch} → ${mapping.dir}/${mapping.name}`);
114
- packed++;
115
- }
116
-
117
- if (packed === 0 && skipped > 0) {
118
- console.error('No binaries were packed. Check that dist/ contains built binaries.');
119
- process.exit(1);
120
- }
121
-
122
- console.log(`\n✓ Packed ${packed} binaries to binaries/`);
123
- if (skipped > 0) {
124
- console.warn(`⚠ Skipped ${skipped} entries`);
125
- }
126
- }
127
-
128
- if (require.main === module) {
129
- packBinaries();
130
- }
131
-
132
- module.exports = packBinaries;
@@ -1,66 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- 'use strict';
4
-
5
- const fs = require('fs');
6
- const path = require('path');
7
-
8
- // Platform detection
9
- const platform = process.platform;
10
- const arch = process.arch;
11
-
12
- // Map Node.js platform/arch to our binary names
13
- let binaryDir;
14
- if (platform === 'darwin') {
15
- binaryDir = arch === 'arm64' ? 'darwin-arm64' : 'darwin-x64';
16
- } else if (platform === 'linux') {
17
- binaryDir = arch === 'arm64' ? 'linux-arm64' : 'linux-x64';
18
- } else if (platform === 'win32') {
19
- binaryDir = arch === 'arm64' ? 'win32-arm64' : 'win32-x64';
20
- } else {
21
- console.warn(`[tracelet] Unsupported platform: ${platform}-${arch}`);
22
- process.exit(0);
23
- }
24
-
25
- const binaryName = platform === 'win32' ? 'tracelet.exe' : 'tracelet';
26
- const sourcePath = path.join(__dirname, '..', 'binaries', binaryDir, binaryName);
27
- const targetPath = path.join(__dirname, '..', 'node_modules', '.bin', binaryName);
28
-
29
- // Check if source binary exists
30
- if (!fs.existsSync(sourcePath)) {
31
- console.warn(`[tracelet] Binary not found for ${platform}-${arch}, skipping postinstall`);
32
- console.warn(`[tracelet] You may need to build binaries first`);
33
- process.exit(0);
34
- }
35
-
36
- // Ensure .bin directory exists
37
- const binDir = path.dirname(targetPath);
38
- if (!fs.existsSync(binDir)) {
39
- fs.mkdirSync(binDir, { recursive: true });
40
- }
41
-
42
- // Copy or symlink binary
43
- try {
44
- // Try symlink first (works on Unix and Windows with proper permissions)
45
- if (fs.existsSync(targetPath)) {
46
- fs.unlinkSync(targetPath);
47
- }
48
-
49
- if (platform === 'win32') {
50
- // Windows: copy instead of symlink for better compatibility
51
- fs.copyFileSync(sourcePath, targetPath);
52
- } else {
53
- // Unix: use symlink
54
- fs.symlinkSync(path.relative(binDir, sourcePath), targetPath);
55
- }
56
-
57
- // Make executable on Unix
58
- if (platform !== 'win32') {
59
- fs.chmodSync(targetPath, '755');
60
- }
61
-
62
- console.log(`[tracelet] Binary linked successfully for ${platform}-${arch}`);
63
- } catch (err) {
64
- console.warn(`[tracelet] Failed to link binary:`, err.message);
65
- console.warn(`[tracelet] You can still use 'npx tracelet' or the full path`);
66
- }
@@ -1,116 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- 'use strict';
4
-
5
- /**
6
- * Publish all packages to npm
7
- *
8
- * Ensures version sync across packages and publishes:
9
- * - @traceletdev/cli (main package)
10
- * - packages/tracelet-next -> @traceletdev/next
11
- * - packages/tracelet-vite -> @traceletdev/vite
12
- * - packages/tracelet-react -> @traceletdev/react
13
- *
14
- * Usage:
15
- * node scripts/publish-all.js [version]
16
- *
17
- * If version is provided, updates all package.json files
18
- * If not, publishes current versions
19
- */
20
-
21
- const fs = require('fs');
22
- const path = require('path');
23
- const { execSync } = require('child_process');
24
-
25
- const packages = [
26
- { name: '@traceletdev/cli', path: '.' },
27
- { name: '@traceletdev/next', path: 'packages/tracelet-next' },
28
- { name: '@traceletdev/vite', path: 'packages/tracelet-vite' },
29
- { name: '@traceletdev/react', path: 'packages/tracelet-react' },
30
- ];
31
-
32
- function getVersion(pkgPath) {
33
- const pkgJsonPath = path.join(pkgPath, 'package.json');
34
- if (!fs.existsSync(pkgJsonPath)) {
35
- return null;
36
- }
37
- const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'));
38
- return pkg.version;
39
- }
40
-
41
- function setVersion(pkgPath, version) {
42
- const pkgJsonPath = path.join(pkgPath, 'package.json');
43
- const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'));
44
- pkg.version = version;
45
- fs.writeFileSync(pkgJsonPath, JSON.stringify(pkg, null, 2) + '\n');
46
- console.log(`✓ Updated ${pkg.name} to ${version}`);
47
- }
48
-
49
- function publishPackage(pkgPath, dryRun = false) {
50
- const cmd = dryRun ? 'npm publish --dry-run' : 'npm publish';
51
- console.log(`\n📦 Publishing ${path.basename(pkgPath)}...`);
52
- try {
53
- execSync(cmd, { cwd: pkgPath, stdio: 'inherit' });
54
- console.log(`✓ Published ${path.basename(pkgPath)}`);
55
- } catch (err) {
56
- console.error(`✗ Failed to publish ${path.basename(pkgPath)}`);
57
- throw err;
58
- }
59
- }
60
-
61
- function main() {
62
- const args = process.argv.slice(2);
63
- const dryRun = args.includes('--dry-run');
64
- let newVersion = args.find(arg => !arg.startsWith('--'));
65
-
66
- // Check if binaries are built
67
- const binariesDir = path.join(process.cwd(), 'binaries');
68
- if (!fs.existsSync(binariesDir)) {
69
- console.warn('⚠ binaries/ directory not found. Run "npm run pack:bin" first.');
70
- console.warn('⚠ Publishing without binaries will result in broken package.');
71
- if (!dryRun) {
72
- console.error('✗ Aborting publish. Build binaries first.');
73
- process.exit(1);
74
- }
75
- }
76
-
77
- // Get current versions
78
- const versions = packages
79
- .map(pkg => ({
80
- ...pkg,
81
- version: getVersion(pkg.path),
82
- }))
83
- .filter(pkg => pkg.version !== null);
84
-
85
- if (versions.length === 0) {
86
- console.error('No packages found with package.json');
87
- process.exit(1);
88
- }
89
-
90
- const currentVersion = versions[0].version;
91
- console.log(`Current version: ${currentVersion}`);
92
-
93
- // Update versions if new version provided
94
- if (newVersion) {
95
- if (!/^\d+\.\d+\.\d+/.test(newVersion)) {
96
- console.error('Invalid version format. Use semantic versioning (e.g., 0.5.0)');
97
- process.exit(1);
98
- }
99
- console.log(`\n📝 Updating all packages to ${newVersion}...`);
100
- versions.forEach(pkg => setVersion(pkg.path, newVersion));
101
- }
102
-
103
- // Publish packages
104
- console.log(`\n🚀 Publishing packages${dryRun ? ' (dry run)' : ''}...`);
105
- versions.forEach(pkg => {
106
- publishPackage(pkg.path, dryRun);
107
- });
108
-
109
- console.log('\n✅ All packages published successfully!');
110
- }
111
-
112
- if (require.main === module) {
113
- main();
114
- }
115
-
116
- module.exports = { getVersion, setVersion, publishPackage };