Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,21 @@ describe("runtimeVersion 1", () => {
expect(output).toMatchSnapshot()
})

it("removes `node:` import prefixes", async (ctx) => {
const input = dedent`
import crypto from "node:crypto"

var hash = crypto.createHash("sha1")
hash.update("data")
hash.digest("base64")
`
const result = await buildFile(ctx, input)

const output = getOutput(result)
expect(output).not.toContain("node:")
expect(output).toContain('from "crypto"')
})

it("minification does not rename handler function", async (ctx) => {
const input = dedent`
function handler(event: Record<string, unknkown>) {
Expand Down Expand Up @@ -672,6 +687,22 @@ describe("runtimeVersion 2", () => {
const output = getOutput(result)
expect(output).toMatchSnapshot()
})

it("removes `node:` import prefixes", async (ctx) => {
const input = dedent`
import crypto from "node:crypto"

var hash = crypto.createHash("sha1")
hash.update("data")
hash.digest("base64")
`
const result = await buildFile(ctx, input)

const output = getOutput(result)
expect(output).not.toContain("node:")
expect(output).toContain('from "crypto"')
})

it("minification does not rename handler function", async (ctx) => {
const input = dedent`
function handler(event: Record<string, unknkown>) {
Expand Down
3 changes: 3 additions & 0 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const supportedV1 = {
"rest-argument": true,
// ES 9 named capture groups are supported.
"regexp-named-capture-groups": true,
// Cannot use `node:` prefixes
"node-colon-prefix-import": false,
"node-colon-prefix-require": false,
}

const supportedV2 = {
Expand Down
Loading