Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
How do I install JSLint on Ubuntu?
I downloaded the source jsl-0.3.0-src.tar.gz from http://www.javascriptlint.com/download.htm and then extracted it to a dir called jsl-0.3.0 on my Desktop. I then moved it to /usr/local/bin which I have read is my PATH. I also want to mention that I have Rhino 1.7 installed already.
When I try to run jsl from terminal I got the following message:
No command 'jsl' found, did you mean:
Command 'jls' from package 'sleuthkit' (universe)
Command 'js' from package 'rhino' (main)
Command 'sl' from package 'sl' (universe)
Command 'fsl' from package 'fsl' (multiverse)
jsl: command not found
So I how do I properly install JSLint?
How to install JSLint on Ubuntu:
Install nodejs (includes npm, the Node Package Manager):
sudo apt-get install nodejs
Install node-jslint. either globally:
sudo npm install -g jslint
or locally, and include it in $PATH:
npm install jslint
and add this line to your.bashrc (adjust version number as appropriate)
alias jslint='~/.npm/jslint/0.1.8/package/bin/jslint.js'
Here are the instructions I followed to have jslint working on Ubuntu 10.10/Vim 7.3 (and Mac OS X).
EDIT
So, I've just spotted a mistake in the given link. Here are the correct steps (assuming you have already downloaded and unpacked the archive to your desktop:
$ cd /path/to/jsl-0.3.0/src
$ make -f Makefile.ref
$ cp Linux_All_DBG.OBJ/jsl /usr/local/bin/jsl
At that point you can open a new terminal window and type $ jsl to display a quick help or invoke it from Vim or directly on a file in the terminal.
END EDIT
/usr/local/bin is not your "PATH", it's only one of the many directories that can be part your PATH environment variable. $ echo $PATH will tell you what these directories are and thus where you can put the jsl executable. You can also put it in another place and add an alias to your .bashrc.
Why do you expect to be able to run jslint from rhino?
You said you just copied the source to /usr/local/bin. You need to compile it. Follow the build instructions in the README.html
Unix
Use 'gmake -f Makefile.ref' to build. To compile optimized code, pass BUILD_OPT=1 on the gmake command line or preset it in the environment or Makefile.ref. NOTE: Do not attempt to use Makefile to build the standalone JavaScript engine. This file is used only for building the JS-engine in the Mozilla browser.
Each platform on which JS is built must have a *.mk configuration file in the js/src/config directory. The configuration file specifies the compiler/linker to be used and allows for customization of command-line options. To date, the build system has been tested on Solaris, AIX, HP/UX, OSF, IRIX, x86 Linux and Windows NT.
Most platforms will work with either the vendor compiler or gcc. (Except that HP builds only work using the native compiler. gcc won't link correctly with shared libraries on that platform. If someone knows a way to fix this, let us know.)
If you define JS_LIVECONNECT, gmake will descend into the liveconnect directory and build LiveConnect after building the JS engine.
To build a binary drop (a zip'ed up file of headers, libraries, binaries), check out mozilla/config and mozilla/nsprpub/config. Use 'gmake -f Makefile.ref nsinstall-target all export ship'
As for your question about the difference. It says on the download page that one is written in JavaScript itself.
We all stand on the shoulders of giants. I would like to especially acknowledge Douglas > Crockford's work on JSLint. This lint is itself written in JavaScript and is an
interesting and rather sophisticated script. Crockford's ideas about good coding
practices served as a springboard for many of these lint rules.
Look at your "jsl-0.3.0/src/README.html" file. This says:
1) You have a "source package". You need to "build" it (with a C compiler), then install your build.
2) This is more than just JSLint. It's an entire Javascript engine. Per the README:
This is the README file for the JavaScript Reference (JSRef, now
better known as SpiderMonkey) implementation. It consists of build
conventions and instructions, source code conventions, a design
walk-through, and a brief file-by-file description of the source.
JSRef builds a library or DLL containing the JavaScript runtime
(compiler, interpreter, decompiler, garbage collector, atom manager,
standard classes). It then compiles a small "shell" program and links
that with the library to make an interpreter that can be used
interactively and with test .js files to run scripts. The code has no
dependencies on the rest of the Mozilla codebase.
3) Here is Douglas Crockford's original JSLint page:
http://www.jslint.com/
4) And here is a a good example of how you might use JSLint locally, on your own PC:
http://code.google.com/p/js-ria-tools/wiki/JSLint
5) You say you already have Rhino - good. In Google, you'll find many obsolete links to www.jslint.com/rhino. Here's why - along with links to current Rhino-related info:
http://hustoknow.blogspot.com/2011/02/jslint-and-rhino-support.html
'Hope that helps!
Related
I tried so but I have a 'require is not defined' error. I can't find information about that, can someone enlighten the noob in me please?
It's possible, but you have to be careful. Trying to require() a package means that node will try to locate its files in your file system. A chrome extension only has access to the files you declare in the manifest, not your filesystem.
To get around this, use a module bundler like Webpack, which will generate a single javascript file containing all code for all packages included through require(). You will have to generate a separate module for each component of your chrome extension (e.g. one for the background page, one for content scripts, one for the popup) and declare each generated module in your manifest.
To avoid trying to setup your build system to make using require() possible, I suggest starting with a boilerplate project. You can check out my extension to see how I do it.
An updated answer for 2022
Short answer: yes, you can require/import packages. Rather than going through the tedious work of setting up & configuring a bundler like Webpack on your own (especially if you have no experience with them), there are now build tools you can use to create the boilerplate "scaffolding" for a Chrome extension:
Extension CLI -- this one is well-documented and you can also reference the source code of some Chrome extensions that have used this tool (READ: learn how others have set up their code).
Chrome Extension CLI
Benefits of using them:
New projects are initiated with a default project file structure. Super helpful.
They support modern Javascript (ES6, ES2021), so modules work fine.
They already have bundlers integrated and pre-configured (Webpack in both above cases I think). You therefore don't need to install and configure any on your own.
You can use npm as normal to install any packages/dependencies you need.
Then of course, let the official documentation for Chrome Extensions guide you through the rest.
It's not possible to require node modules directly within a chrome extension. However, it is possible to bundle node applications and packages into the browser for use with your extensions. See here for more: Is it possible to develop Google Chrome extensions using node.js?
Yes, It is possible with esm npm packages.
require is commonjs module loader.
Browser doesn't support commonjs modules system
so that this error showed.
Method 1:
Run npm init -y and add "type" :"module" in your package.json.
create path.js file
add this line in path.js
const fullPath = await import.meta.resolve("npm-pkg-name");
const path = fullPath?.match(/(/node_modules.*)/)[0];
console.log(path);
add this line inside package.json
"path": "node --experimental-import-meta-resolve path.js",
Copy console output text. Replace package name with this copied path.
Method 2:
Install other npm package to find and replace
npm packages' virtual path to real path so that chrome browser will find it.
Install Path-fixxer
Add this line in path.js
import setAllPkgPath from "path-fixxer";
setAllPkgPath();
then run command : npm run path.
Now open browser to test it.
I tried so but I have a 'require is not defined' error. I can't find information about that, can someone enlighten the noob in me please?
It's possible, but you have to be careful. Trying to require() a package means that node will try to locate its files in your file system. A chrome extension only has access to the files you declare in the manifest, not your filesystem.
To get around this, use a module bundler like Webpack, which will generate a single javascript file containing all code for all packages included through require(). You will have to generate a separate module for each component of your chrome extension (e.g. one for the background page, one for content scripts, one for the popup) and declare each generated module in your manifest.
To avoid trying to setup your build system to make using require() possible, I suggest starting with a boilerplate project. You can check out my extension to see how I do it.
An updated answer for 2022
Short answer: yes, you can require/import packages. Rather than going through the tedious work of setting up & configuring a bundler like Webpack on your own (especially if you have no experience with them), there are now build tools you can use to create the boilerplate "scaffolding" for a Chrome extension:
Extension CLI -- this one is well-documented and you can also reference the source code of some Chrome extensions that have used this tool (READ: learn how others have set up their code).
Chrome Extension CLI
Benefits of using them:
New projects are initiated with a default project file structure. Super helpful.
They support modern Javascript (ES6, ES2021), so modules work fine.
They already have bundlers integrated and pre-configured (Webpack in both above cases I think). You therefore don't need to install and configure any on your own.
You can use npm as normal to install any packages/dependencies you need.
Then of course, let the official documentation for Chrome Extensions guide you through the rest.
It's not possible to require node modules directly within a chrome extension. However, it is possible to bundle node applications and packages into the browser for use with your extensions. See here for more: Is it possible to develop Google Chrome extensions using node.js?
Yes, It is possible with esm npm packages.
require is commonjs module loader.
Browser doesn't support commonjs modules system
so that this error showed.
Method 1:
Run npm init -y and add "type" :"module" in your package.json.
create path.js file
add this line in path.js
const fullPath = await import.meta.resolve("npm-pkg-name");
const path = fullPath?.match(/(/node_modules.*)/)[0];
console.log(path);
add this line inside package.json
"path": "node --experimental-import-meta-resolve path.js",
Copy console output text. Replace package name with this copied path.
Method 2:
Install other npm package to find and replace
npm packages' virtual path to real path so that chrome browser will find it.
Install Path-fixxer
Add this line in path.js
import setAllPkgPath from "path-fixxer";
setAllPkgPath();
then run command : npm run path.
Now open browser to test it.
I want to embed Mozilla's SpiderMonkey in my standalone C++ program (in Visual Studio 2019). I went over all the documentation and whatnot but the problem is (or what I need is):
Execute a JavaScript script through C++. In pseudo code that'd be Value* result = SpiderMonkeyEvaluate(fileString);
And that's it. The thing is, in the documentation it says I need to build the entirety of Mozilla's Firefox browser (which is not less than a Gigabyte) and download Mercurial and open the command prompt and create directories etc. and all that disgusting stuff. I just need to be able to:
#include <jsapi.h>
And perform all the necessary C++-to-JS (and vice-versa) operations.
I do not think I need to download and build the entire FireFox browser to do this (I maybe wrong?).
If anyone is still interested the spider monkey on Windows, you would follow the build instructions here:
https://firefox-source-docs.mozilla.org/js/build.html
using the build tools here:
https://firefox-source-docs.mozilla.org/setup/windows_build.html
If you are very meticulous you don't need to download the entire FireFox code base but your life will be easier if you do. In order to only build spidermonkey only (plus js command line), be sure to activate a particular MOZCONFIG with
ac_add_options --enable-application=js
in it before calling any of the mach commands.
Note: if you plan to use the Visual C++ compiler and not clang-cl, you are limited to version 78 or you will have to figure out how to modify the header yourself.
for reference this is the config I used to successfully build spidermonkey 81.0.2 on Windows 10:
# Build only the JS shell
ac_add_options --enable-application=js
# Enable optimization for speed
ac_add_options --enable-optimize
# Enable the debugging tools: Assertions, debug only code etc.
# For performance testing you would probably want to change this
# to --disable-debug.
ac_add_options --disable-debug
ac_add_options --disable-jemalloc
ac_add_options --prefix=$MY_PREFIX
mk_add_options MOZ_MAKE_FLAGS="-j4"
# Use a separate objdir for optimized builds to allow easy
# switching between optimized and debug builds while developing.
mk_add_options MOZ_OBJDIR=#TOPSRCDIR#/obj-opt-#CONFIG_GUESS#
If you use this config, after you successfully build,
then navigate to #TOPSRCDIR#/obj-opt-#CONFIG_GUESS# and do mozmake install, it "install" all the files you need into $MY_PREFIX
UPDATE - This answer is wrong. sparse checkout actually downloads all the history. One would have to use the narrowhg ext, which isn't supported on the hg.mozilla.org repo.
the following answer is wrong.
You could use mercurial sparse checkout to just get the js/src folder.
(but with all the history of the js/src folder it will still likely be quite big)
This will just the history for js/src folder.
you need a version of mercurial which is newer then 3 years old (4.3 or newer)
mkdir spidermonkey
cd spirdermonkey
hg init
hg debugsparse --include js/src
hg pull https://hg.mozilla.org/releases/mozilla-release -u
I always see in tutorials, that they have a "special npm reference", which I have not.
All what I can see is the "normal" references (.net assemblys). I also do not find any pure "Javascript" Project type.
I am on Update 3. Do I need something special to make this work?
I have a package.json and Gulpfile.js in my project and compile LESS with it successfully, but don't see this references.
The NPM integration/JavaScript project type isn't included in the base install of Visual Studio. For these features to be available, you'll need the Node.js Tools extension - if I recall correctly, there's a shortcut to do this in the New Project wizard in recent versions of VS.
I was looking over Typescript and was a bit confused about how you could build your js files from the ts files via the command line.
It implies in the documentation that you can do it easily through nodeJS, which would be great if I wanted a dependency on nodeJS... So is there any way to compile it via the command line without having nodeJS or visual studio?
This may seem crazy to some, but I would just put a build script step to output the javascript at the end if possible then package it into my release, as I tend to do most of my javascript development with RubyMine and don't want a dependency on nodeJS or Visual Studio for my build server.
If you install the TypeScript Tools without Visual Studio installed on the machine, tsc.exe and its dependencies will still get installed.
You can also just xcopy deploy tsc.exe (I don't have a definitive list of its dependencies, but it's pretty straightforward to figure out, or just copy everything that gets installed to the SDK folder) to a build server. The only thing unexpected you would need is msvcr110.dll, which you may or may not need to copy to tsc.exe's path.
The link in Ryan's answer is now heavily outdated and if you use it will generate a TS1005 error.
Here's what you want https://www.microsoft.com/en-us/download/details.aspx?id=55258 and it is still put in the same Program files x86 / Microsoft SDKs directory, and for me at least was not added to my path.