docs: use node: imports for node core modules (#39681)

docs: use `node:` imports for node builtin modules
This commit is contained in:
Erick Zhao 2023-08-30 08:55:23 -07:00 committed by GitHub
parent 2182202e8e
commit b8ac798344
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 39 additions and 39 deletions

View file

@ -42,14 +42,14 @@ $ asar list /path/to/example.asar
Read a file in the ASAR archive:
```javascript
const fs = require('fs')
const fs = require('node:fs')
fs.readFileSync('/path/to/example.asar/file.txt')
```
List all files under the root of the archive:
```javascript
const fs = require('fs')
const fs = require('node:fs')
fs.readdirSync('/path/to/example.asar')
```
@ -99,7 +99,7 @@ You can also set `process.noAsar` to `true` to disable the support for `asar` in
the `fs` module:
```javascript
const fs = require('fs')
const fs = require('node:fs')
process.noAsar = true
fs.readFileSync('/path/to/example.asar')
```

View file

@ -260,7 +260,7 @@ To create a custom driver, we'll use Node.js' [`child_process`](https://nodejs.o
The test suite will spawn the Electron process, then establish a simple messaging protocol:
```js title='testDriver.js' @ts-nocheck
const childProcess = require('child_process')
const childProcess = require('node:child_process')
const electronPath = require('electron')
// spawn the process

View file

@ -136,7 +136,7 @@ Finally, the `main.js` file represents the main process and contains the actual
```js
const { app, BrowserWindow, ipcMain, nativeTheme } = require('electron')
const path = require('path')
const path = require('node:path')
const createWindow = () => {
const win = new BrowserWindow({

View file

@ -35,8 +35,8 @@ Using the [React Developer Tools][react-devtools] as an example:
```javascript
const { app, session } = require('electron')
const path = require('path')
const os = require('os')
const path = require('node:path')
const os = require('node:os')
// on macOS
const reactDevToolsPath = path.join(

View file

@ -52,7 +52,7 @@ In the main process, set an IPC listener on the `set-title` channel with the `ip
```javascript {6-10,22} title='main.js (Main Process)'
const { app, BrowserWindow, ipcMain } = require('electron')
const path = require('path')
const path = require('node:path')
// ...
@ -183,7 +183,7 @@ provided to the renderer process. Please refer to
```javascript {6-13,25} title='main.js (Main Process)'
const { app, BrowserWindow, dialog, ipcMain } = require('electron')
const path = require('path')
const path = require('node:path')
// ...
@ -378,7 +378,7 @@ target renderer.
```javascript {11-26} title='main.js (Main Process)'
const { app, BrowserWindow, Menu, ipcMain } = require('electron')
const path = require('path')
const path = require('node:path')
function createWindow () {
const mainWindow = new BrowserWindow({

View file

@ -27,7 +27,7 @@ control our application lifecycle and create a native browser window.
```javascript
const { app, BrowserWindow, shell } = require('electron')
const path = require('path')
const path = require('node:path')
```
Next, we will proceed to register our application to handle all "`electron-fiddle://`" protocols.

View file

@ -303,7 +303,7 @@ without having to step through the isolated world.
```js title='main.js (Main Process)'
const { BrowserWindow, app, MessageChannelMain } = require('electron')
const path = require('path')
const path = require('node:path')
app.whenReady().then(async () => {
// Create a BrowserWindow with contextIsolation enabled.

View file

@ -22,7 +22,7 @@ In `preload.js` use the [`contextBridge`][] to inject a method `window.electron.
```js
const { contextBridge, ipcRenderer } = require('electron')
const path = require('path')
const path = require('node:path')
contextBridge.exposeInMainWorld('electron', {
startDrag: (fileName) => {

View file

@ -41,7 +41,7 @@ To enable this mode, GPU acceleration has to be disabled by calling the
```javascript fiddle='docs/fiddles/features/offscreen-rendering'
const { app, BrowserWindow } = require('electron')
const fs = require('fs')
const fs = require('node:fs')
app.disableHardwareAcceleration()

View file

@ -174,7 +174,7 @@ equally fictitious `foo-parser` module. In traditional Node.js development,
you might write code that eagerly loads dependencies:
```js title='parser.js' @ts-expect-error=[2]
const fs = require('fs')
const fs = require('node:fs')
const fooParser = require('foo-parser')
class Parser {
@ -198,7 +198,7 @@ do this work a little later, when `getParsedFiles()` is actually called?
```js title='parser.js' @ts-expect-error=[20]
// "fs" is likely already being loaded, so the `require()` call is cheap
const fs = require('fs')
const fs = require('node:fs')
class Parser {
async getFiles () {

View file

@ -292,7 +292,7 @@ to the `webPreferences.preload` option in your existing `BrowserWindow` construc
```js
const { app, BrowserWindow } = require('electron')
// include the Node.js 'path' module at the top of your file
const path = require('path')
const path = require('node:path')
// modify your existing createWindow() function
const createWindow = () => {
@ -358,7 +358,7 @@ The full code is available below:
// Modules to control application life and create native browser window
const { app, BrowserWindow } = require('electron')
const path = require('path')
const path = require('node:path')
const createWindow = () => {
// Create the browser window.

View file

@ -26,8 +26,8 @@ the application via JumpList or dock menu, respectively.
```javascript fiddle='docs/fiddles/features/recent-documents'
const { app, BrowserWindow } = require('electron')
const fs = require('fs')
const path = require('path')
const fs = require('node:fs')
const path = require('node:path')
const createWindow = () => {
const win = new BrowserWindow({

View file

@ -29,7 +29,7 @@ To set the represented file of window, you can use the
```javascript fiddle='docs/fiddles/features/represented-file'
const { app, BrowserWindow } = require('electron')
const os = require('os')
const os = require('node:os')
const createWindow = () => {
const win = new BrowserWindow({

View file

@ -83,7 +83,7 @@ To attach this script to your renderer process, pass its path to the
```js {2,8-10} title="main.js"
const { app, BrowserWindow } = require('electron')
const path = require('path')
const path = require('node:path')
const createWindow = () => {
const win = new BrowserWindow({
@ -204,7 +204,7 @@ you send out the `invoke` call from the renderer.
```js {1,15} title="main.js"
const { app, BrowserWindow, ipcMain } = require('electron')
const path = require('path')
const path = require('node:path')
const createWindow = () => {
const win = new BrowserWindow({

View file

@ -184,7 +184,7 @@ allowing events such as `mouseleave` to be emitted:
```javascript title='main.js'
const { BrowserWindow, ipcMain } = require('electron')
const path = require('path')
const path = require('node:path')
const win = new BrowserWindow({
webPreferences: {

View file

@ -126,7 +126,7 @@ following lines:
```javascript
const { BrowserWindow, nativeImage } = require('electron')
const path = require('path')
const path = require('node:path')
const win = new BrowserWindow()