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

@ -1333,7 +1333,7 @@ application name. For example:
``` js
const { app } = require('electron')
const path = require('path')
const path = require('node:path')
const appFolder = path.dirname(process.execPath)
const updateExe = path.resolve(appFolder, '..', 'Update.exe')
@ -1404,7 +1404,7 @@ Returns `Function` - This function **must** be called once you have finished acc
```js
const { app, dialog } = require('electron')
const fs = require('fs')
const fs = require('node:fs')
let filepath
let bookmark

View file

@ -1211,7 +1211,7 @@ const win = new BrowserWindow()
const url = require('url').format({
protocol: 'file',
slashes: true,
pathname: require('path').join(__dirname, 'index.html')
pathname: require('node:path').join(__dirname, 'index.html')
})
win.loadURL(url)

View file

@ -147,7 +147,7 @@ Be very cautious about which globals and APIs you expose to untrusted remote con
```javascript
const { contextBridge } = require('electron')
const crypto = require('crypto')
const crypto = require('node:crypto')
contextBridge.exposeInMainWorld('nodeCrypto', {
sha256sum (data) {
const hash = crypto.createHash('sha256')

View file

@ -33,7 +33,7 @@ to register it to that session explicitly.
```javascript
const { app, BrowserWindow, net, protocol, session } = require('electron')
const path = require('path')
const path = require('node:path')
const url = require('url')
app.whenReady().then(() => {
@ -122,7 +122,7 @@ Example:
```js
const { app, net, protocol } = require('electron')
const { join } = require('path')
const { join } = require('node:path')
const { pathToFileURL } = require('url')
protocol.registerSchemesAsPrivileged([

View file

@ -103,7 +103,7 @@ const { session } = require('electron')
session.defaultSession.on('will-download', (event, item, webContents) => {
event.preventDefault()
require('got')(item.getURL()).then((response) => {
require('fs').writeFileSync('/somewhere', response.body)
require('node:fs').writeFileSync('/somewhere', response.body)
})
})
```
@ -1193,7 +1193,7 @@ automatically. To clear the handler, call `setBluetoothPairingHandler(null)`.
```javascript
const { app, BrowserWindow, session } = require('electron')
const path = require('path')
const path = require('node:path')
function createWindow () {
let bluetoothPinCallback = null
@ -1457,7 +1457,7 @@ extension to be loaded.
```js
const { app, session } = require('electron')
const path = require('path')
const path = require('node:path')
app.whenReady().then(async () => {
await session.defaultSession.loadExtension(
@ -1544,7 +1544,7 @@ A [`Protocol`](protocol.md) object for this session.
```javascript
const { app, session } = require('electron')
const path = require('path')
const path = require('node:path')
app.whenReady().then(() => {
const protocol = session.fromPartition('some-partition').protocol

View file

@ -1638,9 +1638,9 @@ An example of `webContents.printToPDF`:
```javascript
const { BrowserWindow } = require('electron')
const fs = require('fs')
const path = require('path')
const os = require('os')
const fs = require('node:fs')
const path = require('node:path')
const os = require('node:os')
const win = new BrowserWindow()
win.loadURL('https://github.com')