| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 17a9846 commit 00c20e6
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 | |
|---|---|---|---|
@@ -386,7 +386,7 @@ analysis process. | |||
| 386 | 386 | ||
| 387 | 387 | For example, consider a CommonJS module written: | |
| 388 | 388 | ||
| 389 | - ```js | ||
| 389 | + ```cjs | ||
| 390 | 390 | // cjs.cjs | |
| 391 | 391 | exports.name = 'exported'; | |
| 392 | 392 | ``` | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -704,7 +704,7 @@ import { another } from 'a-package/m.mjs'; | |||
| 704 | 704 | Self-referencing is also available when using `require`, both in an ES module, | |
| 705 | 705 | and in a CommonJS one. For example, this code will also work: | |
| 706 | 706 | ||
| 707 | - ```js | ||
| 707 | + ```cjs | ||
| 708 | 708 | // ./a-module.js | |
| 709 | 709 | const { something } = require('a-package/foo'); // Loads from ./foo.js. | |
| 710 | 710 | ``` | |
@@ -807,7 +807,7 @@ to be treated as ES modules, just as `"type": "commonjs"` would cause them | |||
| 807 | 807 | to be treated as CommonJS. | |
| 808 | 808 | See [Enabling](#esm_enabling). | |
| 809 | 809 | ||
| 810 | - ```js | ||
| 810 | + ```cjs | ||
| 811 | 811 | // ./node_modules/pkg/index.cjs | |
| 812 | 812 | exports.name = 'value'; | |
| 813 | 813 | ``` | |
@@ -920,7 +920,7 @@ CommonJS and ES module instances of the package: | |||
| 920 | 920 | CommonJS and ES module versions of the package. For example, if the CommonJS | |
| 921 | 921 | and ES module entry points are `index.cjs` and `index.mjs`, respectively: | |
| 922 | 922 | ||
| 923 | - ```js | ||
| 923 | + ```cjs | ||
| 924 | 924 | // ./node_modules/pkg/index.cjs | |
| 925 | 925 | const state = require('./state.cjs'); | |
| 926 | 926 | module.exports.state = state; | |
@@ -1034,7 +1034,7 @@ The `"main"` field defines the script that is used when the [package directory | |||
| 1034 | 1034 | is loaded via `require()`](modules.md#modules_folders_as_modules). Its value | |
| 1035 | 1035 | is a path. | |
| 1036 | 1036 | ||
| 1037 | - ```js | ||
| 1037 | + ```cjs | ||
| 1038 | 1038 | require('./path/to/directory'); // This resolves to ./path/to/directory/main.js. | |
| 1039 | 1039 | ``` | |
| 1040 | 1040 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments