manual
manual copied to clipboard
Node Compatibility Mode seems to have been removed
In version 1.25 of deno, node compatibility mode (https://deno.land/[email protected]/node/compatibility_mode) seems to have been replace by Experimental npm support (https://deno.com/blog/v1.25#experimental-npm-support).
The manual is going through an extensive re-write, including addressing this gap.
@bartlomieju though we should have pulled the documentation from the manual when we removed the feature.
oh sh*t - so the node deno run --compat
mode got removed?
I was just about to file a bug since I can't make it work per the manual.
I was hoping to see if any baseline eslint
worked any better today, and to see if could help with a wanted jsdom
type setup for testing => https://github.com/denoland/deno-docs/issues/98
Yes it was removed, but you can run eslint like so: deno run -A --unstable npm:eslint
yes, indeed thank you!
and this is fantastic -- much better.
however, there this issue making it so various plugins -- or even any kind of config, really -- cant be used yet
https://github.com/denoland/deno/issues/15845
I've hand coded a single JS file that does this kind of thing:
#!/usr/bin/env -S deno run -A --unstable
import { ESLint } from "npm:eslint"
...
(async function main() {
// 1. Create an instance.
const eslint = new ESLint(cfg);
// 2. Lint files.
const results = await eslint.lintFiles(Deno.args);
// console.error({ results });
// 3. Format the results.
const formatter = await eslint.loadFormatter('stylish');
const resultText = formatter.format(results);
// 4. Output it.
console.log(resultText);
if (resultText)
Deno.exit(1);
})().catch((error) => {
console.error(error);
Deno.exit(1);
});
And that gets me around the "cant read eslint config files" (read perms) issue. But I can't load in any eslint plugins for similar read perms issues.
If we could get the -A
and --allow-read
portion to work and allow reading files everywhere, best i can tell everything will work.
Thanks for the comment. We'll be looking into this issue after tomorrow's release.
ok, i wont lie, i've been feverishly waiting to hear if anything coming ASAP (gave it a long shot, but... ;) )
but wait! holy sh*t twinkies!
I just got LESS => CSS compiling working via npm:less
usage for something else in our monorepo that am migrating node => deno...
... and was reviewing the release notes between v1.25, v1.26, and v1.27 (after having some minor issues w/ v1.25x)
https://deno.com/blog/v1.26#improvements-to-npm-support
ooooh snap!
I just found the --node-modules-dir
option.
So now I got eslint
and plugins and base config -- everything for us, totally working! <3 As I think you may recall from prior posts for over a year, I've been hoping for some kind of hobbled full eslint
setup (and have a bunch of workarounds now) for a 30,000+ line JS repo I moved to deno
.
I dont have to tell you -- and you can tell from my excitement ;) -- that this changes everything for us and I suspect many many more folks.
I'm sure this node compat mode was internally hugely controversial for you folks -- but for a very small number of crazy useful things we and other "cant live without"... this is so huge. 🙏
Here's the .eslintrc.cjs
we're using common to many projects, with all the base & plugins & rules we want
https://github.com/internetarchive/dyno/blob/main/.eslintrc.cjs
Here's both a eslint
CLI script (chmod 755) that we can lint itself to showcase it all working:
#!/usr/bin/env -S deno run -A --unstable --node-modules-dir
/* eslint-disable import/no-unresolved */
import 'npm:eslint-plugin-compat'
import 'npm:eslint-plugin-import'
import 'npm:eslint-config-airbnb-base'
import 'npm:eslint-plugin-no-floating-promise'
import { ESLint } from 'npm:eslint';
// eslint-disable-next-line wrap-iife
(async function main() {
// 1. Create an instance.
const eslint = new ESLint({
rulePaths: [],
extensions: null,
ignore: true,
cache: false,
fix: false,
allowInlineConfig: true,
globInputPaths: true,
})
// 2. Lint files.
const results = await eslint.lintFiles(Deno.args)
// console.error({ results })
// 3. Format the results.
const formatter = await eslint.loadFormatter('stylish')
const resultText = formatter.format(results)
// 4. Output it.
console.log(resultText)
if (resultText)
Deno.exit(1)
})().catch((error) => {
console.error(error)
Deno.exit(1)
})
copy in our .eslintrc.cjs
file into same dir as script (avoids that "read permissions" issue mentioned above):
and voila!
> ./eslint.js eslint.js
/Volumes/bff/dev/x/eslint.js
33:3 warning Unexpected console statement no-console
37:3 warning Unexpected console statement no-console
38:1 error Expected indentation of 2 spaces but found 4 indent
38:17 error Block must not be padded by blank lines padded-blocks
✖ 4 problems (2 errors, 2 warnings)
2 errors and 0 warnings potentially fixable with the `--fix` option.
🙏 🙏 🙏
Even better / simpler, we're doing this kind of setup now:
wget https://raw.githubusercontent.com/internetarchive/dyno/main/.eslintrc.cjs
echo ' console.log( " hi")' > index.js
# get all our wanted plugins
deno cache --unstable --node-modules-dir \
npm:eslint-config-airbnb-base \
npm:eslint-plugin-compat \
npm:eslint-plugin-import \
npm:eslint-plugin-no-floating-promise
deno run -A --unstable --node-modules-dir npm:eslint .
1:1 error Expected indentation of 0 spaces but found 2 indent
1:3 warning Unexpected console statement no-console
1:15 error There should be no space after this paren space-in-parens
1:16 error Strings must use singlequote quotes
✖ 4 problems (3 errors, 1 warning)
3 errors and 0 warnings potentially fixable with the `--fix` option.
Thanks for investigation @traceypooh! I'll be talking with ESLint maintainer soon and we'll see if there's something we could do to improve the situation for Deno users.
thanks!
two minor things I noticed (FWIW):
- if the
eslint
emits errors, it doesnt exit non-0 like the node CLI does. so i have to wrap w/ ascripts
call to capture the output (and nice coloring) and then check it to know if should error out (ourvelociraptor
scripts) - lots of spurious
cb
warnings at the end of the run. so i pipe all stderr to/dev/null