| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ff7cc8f commit 4bb0bd0
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -76,6 +76,29 @@ module.exports = { | |||
| 76 | 76 | 'doc/api/packages.md/*.js', | |
| 77 | 77 | ], | |
| 78 | 78 | parserOptions: { sourceType: 'module' }, | |
| 79 | + rules: { 'no-restricted-globals': [ | ||
| 80 | + 'error', | ||
| 81 | + { | ||
| 82 | + name: '__filename', | ||
| 83 | + message: 'Use import.meta.url instead', | ||
| 84 | + }, | ||
| 85 | + { | ||
| 86 | + name: '__dirname', | ||
| 87 | + message: 'Not available in ESM', | ||
| 88 | + }, | ||
| 89 | + { | ||
| 90 | + name: 'exports', | ||
| 91 | + message: 'Not available in ESM', | ||
| 92 | + }, | ||
| 93 | + { | ||
| 94 | + name: 'module', | ||
| 95 | + message: 'Not available in ESM', | ||
| 96 | + }, | ||
| 97 | + { | ||
| 98 | + name: 'require', | ||
| 99 | + message: 'Use import instead', | ||
| 100 | + }, | ||
| 101 | + ] }, | ||
| 79 | 102 | }, | |
| 80 | 103 | ], | |
| 81 | 104 | rules: { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -373,7 +373,7 @@ analysis process. | |||
| 373 | 373 | ||
| 374 | 374 | For example, consider a CommonJS module written: | |
| 375 | 375 | ||
| 376 | - ```js | ||
| 376 | + ```cjs | ||
| 377 | 377 | // cjs.cjs | |
| 378 | 378 | exports.name = 'exported'; | |
| 379 | 379 | ``` | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -659,7 +659,7 @@ import { another } from 'a-package/m.mjs'; | |||
| 659 | 659 | Self-referencing is also available when using `require`, both in an ES module, | |
| 660 | 660 | and in a CommonJS one. For example, this code will also work: | |
| 661 | 661 | ||
| 662 | - ```js | ||
| 662 | + ```cjs | ||
| 663 | 663 | // ./a-module.js | |
| 664 | 664 | const { something } = require('a-package/foo'); // Loads from ./foo.js. | |
| 665 | 665 | ``` | |
@@ -762,7 +762,7 @@ to be treated as ES modules, just as `"type": "commonjs"` would cause them | |||
| 762 | 762 | to be treated as CommonJS. | |
| 763 | 763 | See [Enabling](#esm_enabling). | |
| 764 | 764 | ||
| 765 | - ```js | ||
| 765 | + ```cjs | ||
| 766 | 766 | // ./node_modules/pkg/index.cjs | |
| 767 | 767 | exports.name = 'value'; | |
| 768 | 768 | ``` | |
@@ -875,7 +875,7 @@ CommonJS and ES module instances of the package: | |||
| 875 | 875 | CommonJS and ES module versions of the package. For example, if the CommonJS | |
| 876 | 876 | and ES module entry points are `index.cjs` and `index.mjs`, respectively: | |
| 877 | 877 | ||
| 878 | - ```js | ||
| 878 | + ```cjs | ||
| 879 | 879 | // ./node_modules/pkg/index.cjs | |
| 880 | 880 | const state = require('./state.cjs'); | |
| 881 | 881 | module.exports.state = state; | |
@@ -989,7 +989,7 @@ The `"main"` field defines the script that is used when the [package directory | |||
| 989 | 989 | is loaded via `require()`](modules.md#modules_folders_as_modules). Its value | |
| 990 | 990 | is a path. | |
| 991 | 991 | ||
| 992 | - ```js | ||
| 992 | + ```cjs | ||
| 993 | 993 | require('./path/to/directory'); // This resolves to ./path/to/directory/main.js. | |
| 994 | 994 | ``` | |
| 995 | 995 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments