Skip to content

fix: error while installing [email protected] 'invalid or unexpect… #4807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
"bin",
"lib",
"register.js",
"repl.js"
"repl.js",
"warning.js"
],
"scripts": {
"postinstall": "node --eval 'if (require(\"./package.json\").name === \"coffee-script\") { var red, yellow, cyan, reset; red = yellow = cyan = reset = \"\"; if (!process.env.NODE_DISABLE_COLORS) { red = \"\\x1b[31m\"; yellow = \"\\x1b[33m\"; cyan = \"\\x1b[36m\"; reset = \"\\x1b[0m\"; } console.warn(red + \"CoffeeScript has moved!\" + reset + \" Please update references to \" + yellow + \"\\\"coffee-script\\\"\" + reset + \" to use \" + yellow + \"\\\"coffeescript\\\"\" + reset + \" (no hyphen) instead.\"); console.warn(\"Also, a new major version has been released under the \" + yellow + \"coffeescript\" + reset + \" name on NPM. This new release targets modern JavaScript, with minimal breaking changes. Learn more at \" + cyan + \"http://coffeescript.org\" + reset + \".\"); console.warn(\"\"); }'",
"postinstall": "node ./warning.js",
"test": "node ./bin/cake test",
"test-harmony": "node --harmony ./bin/cake test"
},
Expand Down
54 changes: 54 additions & 0 deletions warning.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
var fs = require('fs'),
path = require('path');

function readJsonFile(filePath) {
try {
var data = fs.readFileSync(filePath, 'utf-8');
return JSON.parse(data);
} catch (error) {
return null;
}
}

var pkgCoffeeData = readJsonFile('./package.json');

// In npm when a package is installed the 'package.json' is amended and some new fields are added
// one of these fields is '_where' which indicates from where the package was installed.
// in case _where is not defined we cannot determine from where it was installed, thus show the warning.
if (pkgCoffeeData && pkgCoffeeData._where) {
if (pkgCoffeeData._where.indexOf('node_modules') !== -1) {
return;
}

var pkgData = readJsonFile(path.join(pkgCoffeeData._where, './package.json'));
if (!pkgData) {
return;
}

var hasOldCoffeeScript = (pkgData.dependencies && pkgData.dependencies['coffee-script'])
|| (pkgData.devDependencies && pkgData.devDependencies['coffee-script']);

if (!hasOldCoffeeScript) {
return;
}
}

var red,
yellow,
cyan,
reset;

red = yellow = cyan = reset = '';

if (!process.env.NODE_DISABLE_COLORS) {
red = '\x1b[31m';
yellow = '\x1b[33m';
cyan = '\x1b[36m';
reset = '\x1b[0m';
}

console.warn(red + 'CoffeeScript has moved!' + reset + ' Please update references to ' + yellow + 'coffee-script' + reset + ' to use ' + yellow +
'coffeescript' + reset + ' (no hyphen) instead.');

console.warn('Also, a new major version has been released under the ' + yellow + 'coffeescript' + reset +
' name on NPM. This new release targets modern JavaScript, with minimal breaking changes. Learn more at ' + cyan + 'http://coffeescript.org' + reset + '.\n');