Skip to content

Commit 44daec7

Browse files
Update coffee
1 parent 946bcb6 commit 44daec7

File tree

1 file changed

+55
-16
lines changed

1 file changed

+55
-16
lines changed

bin/coffee

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,64 @@
11
#!/usr/bin/env node
22

3-
try {
4-
new Function('var {a} = {a: 1}')();
5-
} catch (error) {
6-
console.error('Your JavaScript runtime does not support some features used by the coffee command. Please use Node 6 or later.');
3+
// More comprehensive ES6 feature detection
4+
const testES6Support = () => {
5+
try {
6+
// Test multiple ES6 features, not just destructuring
7+
new Function(`
8+
let [a] = [1];
9+
const {b} = {b: 2};
10+
class Test {};
11+
() => {};
12+
for (let x of [1,2,3]) {};
13+
Promise.resolve();
14+
`)();
15+
return true;
16+
} catch (e) {
17+
return false;
18+
}
19+
};
20+
21+
if (!testES6Support()) {
22+
console.error('Your JavaScript runtime does not support ES6 features required by the coffee command. Please use Node 6 or later.');
723
process.exit(1);
824
}
925

10-
var path = require('path');
11-
var fs = require('fs');
26+
const path = require('path');
27+
const fs = require('fs').promises;
1228

13-
var potentialPaths = [
14-
path.join(process.cwd(), 'node_modules/coffeescript/lib/coffeescript'),
15-
path.join(process.cwd(), 'node_modules/coffeescript/lib/coffee-script'),
16-
path.join(process.cwd(), 'node_modules/coffee-script/lib/coffee-script'),
17-
path.join(__dirname, '../lib/coffeescript')
18-
];
29+
// More comprehensive search paths including global installs
30+
const potentialPaths = [
31+
path.join(process.cwd(), 'node_modules', 'coffeescript', 'lib', 'coffeescript'),
32+
path.join(process.cwd(), 'node_modules', 'coffeescript', 'lib', 'coffee-script'),
33+
path.join(process.cwd(), 'node_modules', 'coffee-script', 'lib', 'coffee-script'),
34+
path.join(__dirname, '..', 'lib', 'coffeescript'),
35+
// Global installation paths
36+
path.join(process.env.npm_config_prefix || '', 'lib', 'node_modules', 'coffeescript', 'lib', 'coffeescript'),
37+
path.join(process.env.HOME || process.env.USERPROFILE, '.npm', 'lib', 'node_modules', 'coffeescript', 'lib', 'coffeescript'),
38+
].filter(Boolean);
1939

20-
for (var i = 0, len = potentialPaths.length; i < len; i++) {
21-
if (fs.existsSync(potentialPaths[i])) {
22-
require(potentialPaths[i] + '/command').run();
23-
break;
40+
async function findAndRunCoffee() {
41+
for (const potentialPath of potentialPaths) {
42+
try {
43+
await fs.access(potentialPath);
44+
const commandPath = path.join(potentialPath, 'command');
45+
require(commandPath).run();
46+
return; // Exit on success
47+
} catch (error) {
48+
// Continue to next path
49+
continue;
50+
}
2451
}
52+
53+
// If no path was found
54+
console.error('CoffeeScript not found. Please install it with:');
55+
console.error(' npm install -g coffeescript');
56+
console.error(' or');
57+
console.error(' npm install --save-dev coffeescript');
58+
process.exit(1);
2559
}
60+
61+
findAndRunCoffee().catch(error => {
62+
console.error('Failed to start coffee command:', error.message);
63+
process.exit(1);
64+
});

0 commit comments

Comments
 (0)