Skip to content

Commit

Permalink
refactor!: use node: protocol imports (#1435)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk authored May 19, 2022
1 parent 9e0f227 commit 397e703
Show file tree
Hide file tree
Showing 98 changed files with 197 additions and 190 deletions.
4 changes: 2 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ module.exports = {
'error',
{
name: 'Buffer',
message: "Import 'Buffer' from 'buffer' module instead",
message: "Import 'Buffer' from 'node:buffer' module instead",
},
{
name: 'process',
message: "Import 'process' from 'process' module instead",
message: "Import 'process' from 'node:process' module instead",
},
],
// we use underscores to indicate private fields in classes
Expand Down
2 changes: 1 addition & 1 deletion examples/events/http/handler.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { env } = require('process')
const { env } = require('node:process')

const { stringify } = JSON

Expand Down
2 changes: 1 addition & 1 deletion examples/lambda-invoke/handler.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { Buffer } = require('buffer')
const { Buffer } = require('node:buffer')
const { config, Lambda } = require('aws-sdk')

const { stringify } = JSON
Expand Down
2 changes: 1 addition & 1 deletion examples/tools/serverless-webpack/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { resolve } = require('path')
const { resolve } = require('node:path')
const { lib } = require('serverless-webpack')

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { env } = require('process')
const { env } = require('node:process')

module.exports = {
bail: true,
Expand Down
2 changes: 1 addition & 1 deletion src/ServerlessOffline.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import process, { env, exit } from 'process'
import process, { env, exit } from 'node:process'
import updateNotifier from 'update-notifier'
import chalk from 'chalk'
import { parse as semverParse } from 'semver'
Expand Down
2 changes: 1 addition & 1 deletion src/debugLog.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { env } from 'process'
import { env } from 'node:process'

export default typeof env.SLS_DEBUG !== 'undefined'
? console.log.bind(null, '[offline]')
Expand Down
4 changes: 2 additions & 2 deletions src/events/http/Endpoint.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { existsSync, readFileSync } from 'fs'
import { resolve } from 'path'
import { existsSync, readFileSync } from 'node:fs'
import { resolve } from 'node:path'
import OfflineEndpoint from './OfflineEndpoint.js'
import debugLog from '../../debugLog.js'

Expand Down
10 changes: 5 additions & 5 deletions src/events/http/HttpServer.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Buffer } from 'buffer'
import { readFileSync } from 'fs'
import { join, resolve } from 'path'
import process, { env, exit } from 'process'
import { Buffer } from 'node:buffer'
import { readFileSync } from 'node:fs'
import { join, resolve } from 'node:path'
import process, { env, exit } from 'node:process'
import h2o2 from '@hapi/h2o2'
import { Server } from '@hapi/hapi'
import { createRequire } from 'module'
import * as pathUtils from 'path'
import * as pathUtils from 'node:path'
import authFunctionNameExtractor from '../authFunctionNameExtractor.js'
import authJWTSettingsExtractor from './authJWTSettingsExtractor.js'
import createAuthScheme from './createAuthScheme.js'
Expand Down
2 changes: 1 addition & 1 deletion src/events/http/lambda-events/LambdaIntegrationEvent.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { env } from 'process'
import { env } from 'node:process'
import renderVelocityTemplateObject from './renderVelocityTemplateObject.js'
import VelocityContext from './VelocityContext.js'

Expand Down
4 changes: 2 additions & 2 deletions src/events/http/lambda-events/LambdaProxyIntegrationEvent.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Buffer } from 'buffer'
import { env } from 'process'
import { Buffer } from 'node:buffer'
import { env } from 'node:process'
import { decode } from 'jsonwebtoken'
import {
createUniqueId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Buffer } from 'buffer'
import { env } from 'process'
import { Buffer } from 'node:buffer'
import { env } from 'node:process'
import { decode } from 'jsonwebtoken'
import {
formatToClfTime,
Expand Down
4 changes: 2 additions & 2 deletions src/events/http/lambda-events/VelocityContext.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Buffer } from 'buffer'
import { env } from 'process'
import { Buffer } from 'node:buffer'
import { env } from 'node:process'
import jsEscapeString from 'js-string-escape'
import { decode } from 'jsonwebtoken'
import {
Expand Down
2 changes: 1 addition & 1 deletion src/events/websocket/HttpServer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { exit } from 'process'
import { exit } from 'node:process'
import { Server } from '@hapi/hapi'
import { catchAllRoute, connectionsRoutes } from './http-routes/index.js'
import serverlessLog from '../../serverlessLog.js'
Expand Down
2 changes: 1 addition & 1 deletion src/lambda/HttpServer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Server } from '@hapi/hapi'
import { exit } from 'process'
import { exit } from 'node:process'
import { invocationsRoute, invokeAsyncRoute } from './routes/index.js'
import serverlessLog from '../serverlessLog.js'
import debugLog from '../debugLog.js'
Expand Down
4 changes: 2 additions & 2 deletions src/lambda/LambdaFunction.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { dirname, join, resolve } from 'path'
import { performance } from 'perf_hooks'
import { dirname, join, resolve } from 'node:path'
import { performance } from 'node:perf_hooks'
import { emptyDir, ensureDir, readFile, remove, writeFile } from 'fs-extra'
import jszip from 'jszip'
import HandlerRunner from './handler-runner/index.js'
Expand Down
4 changes: 2 additions & 2 deletions src/lambda/__tests__/LambdaFunction.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { resolve } from 'path'
// import { performance } from 'perf_hooks'
import { resolve } from 'node:path'
// import { performance } from 'node:perf_hooks'
import LambdaFunction from '../LambdaFunction.js'
import { DEFAULT_LAMBDA_TIMEOUT } from '../../config/index.js'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { resolve } from 'path'
import { resolve } from 'node:path'
import LambdaFunction from '../../../LambdaFunction.js'

export default class LambdaFunctionThatReturnsJSONObject {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { resolve } from 'path'
import { resolve } from 'node:path'
import LambdaFunction from '../../../LambdaFunction.js'

export default class LambdaFunctionThatReturnsNativeString {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from 'path'
import path from 'node:path'
import { node } from 'execa'

const childProcessHelperPath = path.resolve(__dirname, 'childProcessHelper.js')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import process, { argv } from 'process'
import process, { argv } from 'node:process'
import InProcessRunner from '../in-process-runner/index.js'

// TODO handle this:
Expand Down
8 changes: 4 additions & 4 deletions src/lambda/handler-runner/docker-runner/DockerContainer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createHash } from 'crypto'
import { createWriteStream, unlinkSync } from 'fs'
import { platform } from 'os'
import { dirname, join, sep } from 'path'
import { createHash } from 'node:crypto'
import { createWriteStream, unlinkSync } from 'node:fs'
import { platform } from 'node:os'
import { dirname, join, sep } from 'node:path'
import { Lambda } from 'aws-sdk'
import execa from 'execa'
import { ensureDir, pathExists, readFile, writeFile } from 'fs-extra'
Expand Down
14 changes: 7 additions & 7 deletions src/lambda/handler-runner/go-runner/GoRunner.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { mkdir, readFile, rmdir, writeFile } from 'fs/promises'
import { EOL } from 'os'
import { sep, resolve, parse as pathParse } from 'path'
import process, { chdir, cwd } from 'process'
import { mkdir, readFile, rmdir, writeFile } from 'node:fs/promises'
import { EOL } from 'node:os'
import { sep, resolve, parse as pathParse } from 'node:path'
import process, { chdir, cwd } from 'node:process'
import execa, { sync } from 'execa'

const { parse, stringify } = JSON
Expand Down Expand Up @@ -89,13 +89,13 @@ export default class GoRunner {

try {
await mkdir(this.#tmpPath, { recursive: true })
} catch (e) {
} catch {
// @ignore
}

try {
await writeFile(this.#tmpFile, out, 'utf8')
} catch (e) {
} catch {
// @ignore
}

Expand Down Expand Up @@ -124,7 +124,7 @@ export default class GoRunner {
// Make sure we have the mock-lambda runner
sync('go', ['get', 'github.com/icarus-sullivan/mock-lambda@e065469'])
sync('go', ['build'])
} catch (e) {
} catch {
// @ignore
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { readdirSync } from 'fs'
import { dirname, resolve } from 'path'
import { performance } from 'perf_hooks'
import process from 'process'
import { readdirSync } from 'node:fs'
import { dirname, resolve } from 'node:path'
import { performance } from 'node:perf_hooks'
import process from 'node:process'

const { assign, keys } = Object

Expand Down
4 changes: 2 additions & 2 deletions src/lambda/handler-runner/java-runner/JavaRunner.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EOL } from 'os'
import process from 'process'
import { EOL } from 'node:os'
import process from 'node:process'
import fetch from 'node-fetch'
import { invokeJavaLocal } from 'java-invoke-local'

Expand Down
12 changes: 6 additions & 6 deletions src/lambda/handler-runner/python-runner/PythonRunner.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { spawn } from 'child_process'
import { EOL, platform } from 'os'
import { delimiter, join, relative, resolve } from 'path'
import process, { cwd } from 'process'
import readline from 'readline'
import { spawn } from 'node:child_process'
import { EOL, platform } from 'node:os'
import { delimiter, join, relative, resolve } from 'node:path'
import process, { cwd } from 'node:process'
import readline from 'node:readline'

const { parse, stringify } = JSON
const { assign } = Object
const { has } = Reflect

export default class PythonRunner {
#allowCache = false
#env = null
#handlerName = null
#handlerPath = null
#runtime = null
#allowCache = false

constructor(funOptions, env, allowCache, v3Utils) {
const { handlerName, handlerPath, runtime } = funOptions
Expand Down
6 changes: 3 additions & 3 deletions src/lambda/handler-runner/ruby-runner/RubyRunner.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EOL, platform } from 'os'
import { relative, resolve } from 'path'
import { cwd } from 'process'
import { EOL, platform } from 'node:os'
import { relative, resolve } from 'node:path'
import { cwd } from 'node:process'
import execa from 'execa'

const { parse, stringify } = JSON
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { resolve } from 'path'
import { MessageChannel, Worker } from 'worker_threads' // eslint-disable-line import/no-unresolved
import { resolve } from 'node:path'
import { MessageChannel, Worker } from 'node:worker_threads' // eslint-disable-line import/no-unresolved

const workerThreadHelperPath = resolve(__dirname, './workerThreadHelper.js')

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { env } from 'process'
import { parentPort, workerData } from 'worker_threads' // eslint-disable-line import/no-unresolved
import { env } from 'node:process'
import { parentPort, workerData } from 'node:worker_threads' // eslint-disable-line import/no-unresolved
import InProcessRunner from '../in-process-runner/index.js'

const { functionKey, handlerName, handlerPath } = workerData
Expand Down
2 changes: 1 addition & 1 deletion src/lambda/routes/invocations/invocationsRoute.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Buffer } from 'buffer'
import { Buffer } from 'node:buffer'
import { Headers } from 'node-fetch'
import InvocationsController from './InvocationsController.js'

Expand Down
2 changes: 1 addition & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// UNCOMMENT FOR DEVELOPMENT:
//
// const { resolve } = require('path')
// const { resolve } = require('node:path')
//
// // eslint-disable-next-line import/no-extraneous-dependencies
// require('@babel/register')({
Expand Down
2 changes: 1 addition & 1 deletion src/utils/createApiKey.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createHash } from 'crypto'
import { createHash } from 'node:crypto'

export default function createApiKey() {
return createHash('md5').digest('hex')
Expand Down
4 changes: 2 additions & 2 deletions tests/_setupTeardown/npmInstall.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { resolve } from 'path'
import { env } from 'process'
import { resolve } from 'node:path'
import { env } from 'node:process'
import execa from 'execa'
import promiseMap from 'p-map'
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { resolve } from 'path'
import { env } from 'process'
import { resolve } from 'node:path'
import { env } from 'node:process'
import fetch from 'node-fetch'
import {
joinUrl,
Expand Down
2 changes: 1 addition & 1 deletion tests/endToEnd/environmentVariables/handler.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { env } = require('process')
const { env } = require('node:process')

const { stringify } = JSON

Expand Down
2 changes: 1 addition & 1 deletion tests/endToEnd/optionParameters/optionParameters.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { resolve } from 'path'
import { resolve } from 'node:path'
import fetch from 'node-fetch'
import {
joinUrl,
Expand Down
2 changes: 1 addition & 1 deletion tests/endToEnd/starRoutes/starRoutes.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { resolve } from 'path'
import { resolve } from 'node:path'
import fetch from 'node-fetch'
import {
joinUrl,
Expand Down
2 changes: 1 addition & 1 deletion tests/endToEnd/starRoutesWithProperties/starRoutes.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { resolve } from 'path'
import { resolve } from 'node:path'
import fetch from 'node-fetch'
import {
joinUrl,
Expand Down
2 changes: 1 addition & 1 deletion tests/endToEnd/trailingSlash/trailingSlash.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { resolve } from 'path'
import { resolve } from 'node:path'
import fetch from 'node-fetch'
import {
joinUrl,
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/_testHelpers/compressArtifact.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { dirname, resolve } from 'path'
import { dirname, resolve } from 'node:path'
import archiver from 'archiver'
import { createWriteStream, ensureDir, stat } from 'fs-extra'

Expand Down
4 changes: 2 additions & 2 deletions tests/integration/_testHelpers/setupTeardown.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { resolve } from 'path'
import process, { env } from 'process'
import { resolve } from 'node:path'
import process, { env } from 'node:process'
import { node } from 'execa'

let serverlessProcess
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/artifact/local/localArtifact.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { resolve } from 'path'
import { resolve } from 'node:path'
import fetch from 'node-fetch'
import {
compressArtifact,
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/authorizer/authorizer.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// tests based on:
// https://dev.to/piczmar_0/serverless-authorizers---custom-rest-authorizer-16

import { resolve } from 'path'
import { resolve } from 'node:path'
import fetch from 'node-fetch'
import { joinUrl, setup, teardown } from '../_testHelpers/index.js'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fetch from 'node-fetch'
import { resolve } from 'path'
import { resolve } from 'node:path'
import { joinUrl, setup, teardown } from '../_testHelpers/index.js'

jest.setTimeout(30000)
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/docker/access-host/accessHost.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { resolve } from 'path'
import { env } from 'process'
import { resolve } from 'node:path'
import { env } from 'node:process'
import { Server } from '@hapi/hapi'
import fetch from 'node-fetch'
import { joinUrl, setup, teardown } from '../../_testHelpers/index.js'
Expand Down
Loading

0 comments on commit 397e703

Please sign in to comment.