diff options
author | Leo Kettmeir <crowlkats@toaxl.com> | 2023-02-07 20:22:46 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-07 20:22:46 +0100 |
commit | b4aa1530970f7b9cc4e6f2f27e077852c4e178d3 (patch) | |
tree | 3d008912affe8550692183bd2697a386db5e3c79 /runtime/js/90_deno_ns.js | |
parent | 65500f36e870b4ada3996b06aa287e30177d21a3 (diff) |
refactor: Use ES modules for internal runtime code (#17648)
This PR refactors all internal js files (except core) to be written as
ES modules.
`__bootstrap`has been mostly replaced with static imports in form in
`internal:[path to file from repo root]`.
To specify if files are ESM, an `esm` method has been added to
`Extension`, similar to the `js` method.
A new ModuleLoader called `InternalModuleLoader` has been added to
enable the loading of internal specifiers, which is used in all
situations except when a snapshot is only loaded, and not a new one is
created from it.
---------
Co-authored-by: Bartek IwaĆczuk <biwanczuk@gmail.com>
Diffstat (limited to 'runtime/js/90_deno_ns.js')
-rw-r--r-- | runtime/js/90_deno_ns.js | 327 |
1 files changed, 177 insertions, 150 deletions
diff --git a/runtime/js/90_deno_ns.js b/runtime/js/90_deno_ns.js index d2c76e003..7b791017b 100644 --- a/runtime/js/90_deno_ns.js +++ b/runtime/js/90_deno_ns.js @@ -1,154 +1,181 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -"use strict"; -((window) => { - const core = window.Deno.core; - const __bootstrap = window.__bootstrap; +const core = globalThis.Deno.core; +const ops = core.ops; +import * as timers from "internal:ext/web/02_timers.js"; +import * as httpClient from "internal:ext/fetch/22_http_client.js"; +import * as console from "internal:ext/console/02_console.js"; +import * as ffi from "internal:ext/ffi/00_ffi.js"; +import * as net from "internal:ext/net/01_net.js"; +import * as tls from "internal:ext/net/02_tls.js"; +import * as http from "internal:ext/http/01_http.js"; +import * as flash from "internal:ext/flash/01_http.js"; +import * as build from "internal:runtime/js/01_build.js"; +import * as errors from "internal:runtime/js/01_errors.js"; +import * as version from "internal:runtime/js/01_version.js"; +import * as permissions from "internal:runtime/js/10_permissions.js"; +import * as io from "internal:runtime/js/12_io.js"; +import * as buffer from "internal:runtime/js/13_buffer.js"; +import * as fs from "internal:runtime/js/30_fs.js"; +import * as os from "internal:runtime/js/30_os.js"; +import * as diagnostics from "internal:runtime/js/40_diagnostics.js"; +import * as files from "internal:runtime/js/40_files.js"; +import * as fsEvents from "internal:runtime/js/40_fs_events.js"; +import * as process from "internal:runtime/js/40_process.js"; +import * as readFile from "internal:runtime/js/40_read_file.js"; +import * as signals from "internal:runtime/js/40_signals.js"; +import * as tty from "internal:runtime/js/40_tty.js"; +import * as writeFile from "internal:runtime/js/40_write_file.js"; +import * as spawn from "internal:runtime/js/40_spawn.js"; +// TODO(bartlomieju): this is funky we have two `http` imports +import * as httpRuntime from "internal:runtime/js/40_http.js"; - __bootstrap.denoNs = { - metrics: core.metrics, - Process: __bootstrap.process.Process, - run: __bootstrap.process.run, - isatty: __bootstrap.tty.isatty, - writeFileSync: __bootstrap.writeFile.writeFileSync, - writeFile: __bootstrap.writeFile.writeFile, - writeTextFileSync: __bootstrap.writeFile.writeTextFileSync, - writeTextFile: __bootstrap.writeFile.writeTextFile, - readTextFile: __bootstrap.readFile.readTextFile, - readTextFileSync: __bootstrap.readFile.readTextFileSync, - readFile: __bootstrap.readFile.readFile, - readFileSync: __bootstrap.readFile.readFileSync, - watchFs: __bootstrap.fsEvents.watchFs, - chmodSync: __bootstrap.fs.chmodSync, - chmod: __bootstrap.fs.chmod, - chown: __bootstrap.fs.chown, - chownSync: __bootstrap.fs.chownSync, - copyFileSync: __bootstrap.fs.copyFileSync, - cwd: __bootstrap.fs.cwd, - makeTempDirSync: __bootstrap.fs.makeTempDirSync, - makeTempDir: __bootstrap.fs.makeTempDir, - makeTempFileSync: __bootstrap.fs.makeTempFileSync, - makeTempFile: __bootstrap.fs.makeTempFile, - memoryUsage: () => core.ops.op_runtime_memory_usage(), - mkdirSync: __bootstrap.fs.mkdirSync, - mkdir: __bootstrap.fs.mkdir, - chdir: __bootstrap.fs.chdir, - copyFile: __bootstrap.fs.copyFile, - readDirSync: __bootstrap.fs.readDirSync, - readDir: __bootstrap.fs.readDir, - readLinkSync: __bootstrap.fs.readLinkSync, - readLink: __bootstrap.fs.readLink, - realPathSync: __bootstrap.fs.realPathSync, - realPath: __bootstrap.fs.realPath, - removeSync: __bootstrap.fs.removeSync, - remove: __bootstrap.fs.remove, - renameSync: __bootstrap.fs.renameSync, - rename: __bootstrap.fs.rename, - version: __bootstrap.version.version, - build: __bootstrap.build.build, - statSync: __bootstrap.fs.statSync, - lstatSync: __bootstrap.fs.lstatSync, - stat: __bootstrap.fs.stat, - lstat: __bootstrap.fs.lstat, - truncateSync: __bootstrap.fs.truncateSync, - truncate: __bootstrap.fs.truncate, - ftruncateSync: __bootstrap.fs.ftruncateSync, - ftruncate: __bootstrap.fs.ftruncate, - futime: __bootstrap.fs.futime, - futimeSync: __bootstrap.fs.futimeSync, - errors: __bootstrap.errors.errors, - // TODO(kt3k): Remove this export at v2 - // See https://github.com/denoland/deno/issues/9294 - customInspect: __bootstrap.console.customInspect, - inspect: __bootstrap.console.inspect, - env: __bootstrap.os.env, - exit: __bootstrap.os.exit, - execPath: __bootstrap.os.execPath, - Buffer: __bootstrap.buffer.Buffer, - readAll: __bootstrap.buffer.readAll, - readAllSync: __bootstrap.buffer.readAllSync, - writeAll: __bootstrap.buffer.writeAll, - writeAllSync: __bootstrap.buffer.writeAllSync, - copy: __bootstrap.io.copy, - iter: __bootstrap.io.iter, - iterSync: __bootstrap.io.iterSync, - SeekMode: __bootstrap.io.SeekMode, - read: __bootstrap.io.read, - readSync: __bootstrap.io.readSync, - write: __bootstrap.io.write, - writeSync: __bootstrap.io.writeSync, - File: __bootstrap.files.File, - FsFile: __bootstrap.files.FsFile, - open: __bootstrap.files.open, - openSync: __bootstrap.files.openSync, - create: __bootstrap.files.create, - createSync: __bootstrap.files.createSync, - stdin: __bootstrap.files.stdin, - stdout: __bootstrap.files.stdout, - stderr: __bootstrap.files.stderr, - seek: __bootstrap.files.seek, - seekSync: __bootstrap.files.seekSync, - connect: __bootstrap.net.connect, - listen: __bootstrap.net.listen, - loadavg: __bootstrap.os.loadavg, - connectTls: __bootstrap.tls.connectTls, - listenTls: __bootstrap.tls.listenTls, - startTls: __bootstrap.tls.startTls, - shutdown: __bootstrap.net.shutdown, - fstatSync: __bootstrap.fs.fstatSync, - fstat: __bootstrap.fs.fstat, - fsyncSync: __bootstrap.fs.fsyncSync, - fsync: __bootstrap.fs.fsync, - fdatasyncSync: __bootstrap.fs.fdatasyncSync, - fdatasync: __bootstrap.fs.fdatasync, - symlink: __bootstrap.fs.symlink, - symlinkSync: __bootstrap.fs.symlinkSync, - link: __bootstrap.fs.link, - linkSync: __bootstrap.fs.linkSync, - permissions: __bootstrap.permissions.permissions, - Permissions: __bootstrap.permissions.Permissions, - PermissionStatus: __bootstrap.permissions.PermissionStatus, - serveHttp: __bootstrap.http.serveHttp, - resolveDns: __bootstrap.net.resolveDns, - upgradeWebSocket: __bootstrap.http.upgradeWebSocket, - utime: __bootstrap.fs.utime, - utimeSync: __bootstrap.fs.utimeSync, - kill: __bootstrap.process.kill, - addSignalListener: __bootstrap.signals.addSignalListener, - removeSignalListener: __bootstrap.signals.removeSignalListener, - refTimer: __bootstrap.timers.refTimer, - unrefTimer: __bootstrap.timers.unrefTimer, - osRelease: __bootstrap.os.osRelease, - osUptime: __bootstrap.os.osUptime, - hostname: __bootstrap.os.hostname, - systemMemoryInfo: __bootstrap.os.systemMemoryInfo, - networkInterfaces: __bootstrap.os.networkInterfaces, - consoleSize: __bootstrap.tty.consoleSize, - gid: __bootstrap.os.gid, - uid: __bootstrap.os.uid, - }; +const denoNs = { + metrics: core.metrics, + Process: process.Process, + run: process.run, + isatty: tty.isatty, + writeFileSync: writeFile.writeFileSync, + writeFile: writeFile.writeFile, + writeTextFileSync: writeFile.writeTextFileSync, + writeTextFile: writeFile.writeTextFile, + readTextFile: readFile.readTextFile, + readTextFileSync: readFile.readTextFileSync, + readFile: readFile.readFile, + readFileSync: readFile.readFileSync, + watchFs: fsEvents.watchFs, + chmodSync: fs.chmodSync, + chmod: fs.chmod, + chown: fs.chown, + chownSync: fs.chownSync, + copyFileSync: fs.copyFileSync, + cwd: fs.cwd, + makeTempDirSync: fs.makeTempDirSync, + makeTempDir: fs.makeTempDir, + makeTempFileSync: fs.makeTempFileSync, + makeTempFile: fs.makeTempFile, + memoryUsage: () => ops.op_runtime_memory_usage(), + mkdirSync: fs.mkdirSync, + mkdir: fs.mkdir, + chdir: fs.chdir, + copyFile: fs.copyFile, + readDirSync: fs.readDirSync, + readDir: fs.readDir, + readLinkSync: fs.readLinkSync, + readLink: fs.readLink, + realPathSync: fs.realPathSync, + realPath: fs.realPath, + removeSync: fs.removeSync, + remove: fs.remove, + renameSync: fs.renameSync, + rename: fs.rename, + version: version.version, + build: build.build, + statSync: fs.statSync, + lstatSync: fs.lstatSync, + stat: fs.stat, + lstat: fs.lstat, + truncateSync: fs.truncateSync, + truncate: fs.truncate, + ftruncateSync: fs.ftruncateSync, + ftruncate: fs.ftruncate, + futime: fs.futime, + futimeSync: fs.futimeSync, + errors: errors.errors, + // TODO(kt3k): Remove this export at v2 + // See https://github.com/denoland/deno/issues/9294 + customInspect: console.customInspect, + inspect: console.inspect, + env: os.env, + exit: os.exit, + execPath: os.execPath, + Buffer: buffer.Buffer, + readAll: buffer.readAll, + readAllSync: buffer.readAllSync, + writeAll: buffer.writeAll, + writeAllSync: buffer.writeAllSync, + copy: io.copy, + iter: io.iter, + iterSync: io.iterSync, + SeekMode: io.SeekMode, + read: io.read, + readSync: io.readSync, + write: io.write, + writeSync: io.writeSync, + File: files.File, + FsFile: files.FsFile, + open: files.open, + openSync: files.openSync, + create: files.create, + createSync: files.createSync, + stdin: files.stdin, + stdout: files.stdout, + stderr: files.stderr, + seek: files.seek, + seekSync: files.seekSync, + connect: net.connect, + listen: net.listen, + loadavg: os.loadavg, + connectTls: tls.connectTls, + listenTls: tls.listenTls, + startTls: tls.startTls, + shutdown: net.shutdown, + fstatSync: fs.fstatSync, + fstat: fs.fstat, + fsyncSync: fs.fsyncSync, + fsync: fs.fsync, + fdatasyncSync: fs.fdatasyncSync, + fdatasync: fs.fdatasync, + symlink: fs.symlink, + symlinkSync: fs.symlinkSync, + link: fs.link, + linkSync: fs.linkSync, + permissions: permissions.permissions, + Permissions: permissions.Permissions, + PermissionStatus: permissions.PermissionStatus, + // TODO(bartlomieju): why is this not in one of extensions? + serveHttp: httpRuntime.serveHttp, + resolveDns: net.resolveDns, + upgradeWebSocket: http.upgradeWebSocket, + utime: fs.utime, + utimeSync: fs.utimeSync, + kill: process.kill, + addSignalListener: signals.addSignalListener, + removeSignalListener: signals.removeSignalListener, + refTimer: timers.refTimer, + unrefTimer: timers.unrefTimer, + osRelease: os.osRelease, + osUptime: os.osUptime, + hostname: os.hostname, + systemMemoryInfo: os.systemMemoryInfo, + networkInterfaces: os.networkInterfaces, + consoleSize: tty.consoleSize, + gid: os.gid, + uid: os.uid, +}; - __bootstrap.denoNsUnstable = { - DiagnosticCategory: __bootstrap.diagnostics.DiagnosticCategory, - listenDatagram: __bootstrap.net.listenDatagram, - umask: __bootstrap.fs.umask, - HttpClient: __bootstrap.fetch.HttpClient, - createHttpClient: __bootstrap.fetch.createHttpClient, - http: __bootstrap.http, - dlopen: __bootstrap.ffi.dlopen, - UnsafeCallback: __bootstrap.ffi.UnsafeCallback, - UnsafePointer: __bootstrap.ffi.UnsafePointer, - UnsafePointerView: __bootstrap.ffi.UnsafePointerView, - UnsafeFnPointer: __bootstrap.ffi.UnsafeFnPointer, - flock: __bootstrap.fs.flock, - flockSync: __bootstrap.fs.flockSync, - funlock: __bootstrap.fs.funlock, - funlockSync: __bootstrap.fs.funlockSync, - Child: __bootstrap.spawn.Child, - ChildProcess: __bootstrap.spawn.ChildProcess, - Command: __bootstrap.spawn.Command, - serve: __bootstrap.flash.serve, - upgradeHttp: __bootstrap.http.upgradeHttp, - upgradeHttpRaw: __bootstrap.flash.upgradeHttpRaw, - }; -})(this); +const denoNsUnstable = { + DiagnosticCategory: diagnostics.DiagnosticCategory, + listenDatagram: net.listenDatagram, + umask: fs.umask, + HttpClient: httpClient.HttpClient, + createHttpClient: httpClient.createHttpClient, + // TODO(bartlomieju): why is it needed? + http, + dlopen: ffi.dlopen, + UnsafeCallback: ffi.UnsafeCallback, + UnsafePointer: ffi.UnsafePointer, + UnsafePointerView: ffi.UnsafePointerView, + UnsafeFnPointer: ffi.UnsafeFnPointer, + flock: fs.flock, + flockSync: fs.flockSync, + funlock: fs.funlock, + funlockSync: fs.funlockSync, + Child: spawn.Child, + ChildProcess: spawn.ChildProcess, + Command: spawn.Command, + upgradeHttp: http.upgradeHttp, + upgradeHttpRaw: flash.upgradeHttpRaw, +}; + +export { denoNs, denoNsUnstable }; |