Skip to content

Commit 6a64f44

Browse files
authored
chore: adjust webpack config to allow node: protocol imports (#344)
required in order to use the latest version of `ts-morph` over in #152
1 parent 1d09da2 commit 6a64f44

File tree

12 files changed

+32
-32
lines changed

12 files changed

+32
-32
lines changed

packages/documentation/next.config.mjs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,27 @@ const nextConfig = {
99
images: {
1010
unoptimized: true,
1111
},
12-
webpack: (config, {buildId, dev, isServer, defaultLoaders, webpack}) => {
12+
webpack: (config) => {
1313
config.experiments = {...config.experiments, syncWebAssembly: true}
14-
config.plugins.push(new NodePolyfillPlugin())
15-
config.module.rules.push({
16-
test: /node:.+/i,
17-
use: "null-loader",
14+
15+
/**
16+
* Webpack doesn't support `node:` prefixed imports, so rewrite them to be
17+
* plain imports, allowing the NodePolyfillPlugin to do its job correctly.
18+
*/
19+
config.plugins.push({
20+
apply(compiler) {
21+
compiler.hooks.normalModuleFactory.tap("RewriteNodeProtocol", (nmf) => {
22+
nmf.hooks.beforeResolve.tap("RewriteNodeProtocol", (result) => {
23+
if (result?.request?.startsWith("node:")) {
24+
result.request = result.request.replace(/^node:/, "")
25+
}
26+
})
27+
})
28+
},
1829
})
30+
31+
config.plugins.push(new NodePolyfillPlugin())
32+
1933
config.module.rules.push({
2034
test: /@biomejs\/wasm-nodejs/i,
2135
use: "null-loader",

packages/openapi-code-generator/src/core/file-system/node-fs-adaptor.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
// TODO: webpack shouldn't be including this file?
2-
// biome-ignore lint/style/useNodejsImportProtocol: keep webpack happy
3-
import {existsSync} from "fs"
1+
import {existsSync} from "node:fs"
42

5-
// biome-ignore lint/style/useNodejsImportProtocol: keep webpack happy
6-
import fs from "fs/promises"
3+
import fs from "node:fs/promises"
74
import type {IFsAdaptor} from "./fs-adaptor"
85

96
export class NodeFsAdaptor implements IFsAdaptor {

packages/openapi-code-generator/src/core/loaders/generic.loader.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// biome-ignore lint/style/useNodejsImportProtocol: webpack doesn't like `node:` prefix
2-
import path from "path"
1+
import path from "node:path"
32
import yaml from "js-yaml"
43
import json5 from "json5"
54
import type {IFsAdaptor} from "../file-system/fs-adaptor"

packages/openapi-code-generator/src/core/loaders/tsconfig.loader.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// biome-ignore lint/style/useNodejsImportProtocol: keep webpack happy
2-
import path from "path"
1+
import path from "node:path"
32
import json5 from "json5"
43
import ts from "typescript"
54
import type {IFsAdaptor} from "../file-system/fs-adaptor"

packages/openapi-code-generator/src/core/loaders/typescript-formatter-config.loader.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// biome-ignore lint/style/useNodejsImportProtocol: <explanation>
2-
import path from "path"
1+
import path from "node:path"
32
import stripJsonComments from "strip-json-comments"
43
import type {IFsAdaptor} from "../file-system/fs-adaptor"
54
import {logger} from "../logger"

packages/openapi-code-generator/src/core/logger.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// biome-ignore lint/style/useNodejsImportProtocol: keep webpack happy
2-
import util from "util"
1+
import util from "node:util"
32

43
export type LoggerMeta = Record<string, unknown>
54

packages/openapi-code-generator/src/core/openapi-loader.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
// biome-ignore lint/style/useNodejsImportProtocol: keep webpack happy
2-
import path from "path"
3-
// biome-ignore lint/style/useNodejsImportProtocol: keep webpack happy
4-
import util from "util"
1+
import path from "node:path"
2+
import util from "node:util"
53

64
import * as console from "node:console"
75
import {load} from "js-yaml"

packages/openapi-code-generator/src/core/utils.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// biome-ignore lint/style/useNodejsImportProtocol: webpack doesn't like node: prefix
2-
import path from "path"
1+
import path from "node:path"
32
import _ from "lodash"
43

54
export function isDefined<T>(it: T | undefined): it is T {

packages/openapi-code-generator/src/typescript/common/import-builder.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// biome-ignore lint/style/useNodejsImportProtocol: keep webpack happy
2-
import path from "path"
1+
import path from "node:path"
32

43
export class ImportBuilder {
54
private readonly imports: Record<string, Set<string>> = {}

packages/openapi-code-generator/src/typescript/common/typescript-emitter.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// biome-ignore lint/style/useNodejsImportProtocol: webpack doesn't like node: prefix
2-
import path from "path"
1+
import path from "node:path"
32
import type {IFsAdaptor} from "../../core/file-system/fs-adaptor"
43
import type {IFormatter} from "../../core/interfaces"
54
import {logger} from "../../core/logger"

0 commit comments

Comments
 (0)