Skip to content

Commit

Permalink
fix(lint): webpack nmt (#5848)
Browse files Browse the repository at this point in the history
  • Loading branch information
tknickman authored Sep 1, 2023
1 parent dbc59a3 commit 3e47944
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,7 @@ jobs:

# excluded workspaces have not been fully migrated to @vercel/style-guide
- name: Lint check
run: turbo run lint --filter=!docs --filter=!cli --filter=!@vercel/devlow-bench --filter=!@vercel/experimental-nft-next-plugin --filter=!@vercel/experimental-nft-next-plugin --filter=!@vercel/webpack-nft --filter=!turbopack-bump-action --filter=!next-integration-stat
run: turbo run lint --filter=!docs --filter=!cli --filter=!@vercel/devlow-bench --filter=!@vercel/experimental-nft-next-plugin --filter=!@vercel/experimental-nft-next-plugin --filter=!turbopack-bump-action --filter=!next-integration-stat

final:
name: Ok
Expand Down
25 changes: 16 additions & 9 deletions packages/webpack-nmt/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { spawn } from "child_process";
import { join } from "path";

import { Compilation, WebpackPluginInstance, Compiler } from "webpack";
import { spawn } from "node:child_process";
import { join } from "node:path";
import type { WebpackPluginInstance, Compiler } from "webpack";
import { Compilation } from "webpack";

export interface NodeModuleTracePluginOptions {
cwd?: string;
Expand Down Expand Up @@ -45,7 +45,9 @@ export class NodeModuleTracePlugin implements WebpackPluginInstance {
name: NodeModuleTracePlugin.PluginName,
stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE,
},
() => this.createTraceAssets(compilation)
() => {
this.createTraceAssets(compilation);
}
);
}
);
Expand All @@ -55,6 +57,7 @@ export class NodeModuleTracePlugin implements WebpackPluginInstance {
}

private createTraceAssets(compilation: Compilation) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- webpack guarantees outputPath
const outputPath = compilation.outputOptions.path!;

const isTraceable = (file: string) =>
Expand Down Expand Up @@ -100,6 +103,7 @@ export class NodeModuleTracePlugin implements WebpackPluginInstance {
"@vercel/experimental-nft/package.json"
);
} catch (e) {
// eslint-disable-next-line no-console -- log feedback
console.warn(
`Could not resolve the @vercel/experimental-nft directory, turbo tracing may fail.`
);
Expand All @@ -114,6 +118,7 @@ export class NodeModuleTracePlugin implements WebpackPluginInstance {
);
turboTracingBinPath = join(turboTracingBinPackageJsonPath, "..");
} catch (e) {
// eslint-disable-next-line no-console -- log feedback
console.warn(
`Could not resolve the @vercel/experimental-nft-${process.platform}-${process.arch} directory, turbo tracing may fail.`
);
Expand All @@ -128,6 +133,7 @@ export class NodeModuleTracePlugin implements WebpackPluginInstance {
let chunks = [...this.chunksToTrace];
let restChunks = chunks.length > maxFiles ? chunks.splice(maxFiles) : [];
while (chunks.length) {
// eslint-disable-next-line no-await-in-loop -- trace chunks in sequence
await traceChunks(args, paths, chunks, cwd);
chunks = restChunks;
if (restChunks.length) {
Expand All @@ -138,9 +144,9 @@ export class NodeModuleTracePlugin implements WebpackPluginInstance {
}

function traceChunks(
args: string[],
args: Array<string>,
paths: string,
chunks: string[],
chunks: Array<string>,
cwd?: string
) {
const turboTracingProcess = spawn("node-file-trace", [...args, ...chunks], {
Expand All @@ -154,12 +160,13 @@ function traceChunks(
});
return new Promise<void>((resolve, reject) => {
turboTracingProcess.on("error", (err) => {
// eslint-disable-next-line no-console -- log error
console.error(err);
});
turboTracingProcess.stdout.on("data", (chunk) => {
turboTracingProcess.stdout.on("data", (chunk: string | Uint8Array) => {
process.stdout.write(chunk);
});
turboTracingProcess.stderr.on("data", (chunk) => {
turboTracingProcess.stderr.on("data", (chunk: string | Uint8Array) => {
process.stderr.write(chunk);
});
turboTracingProcess.once("exit", (code) => {
Expand Down

0 comments on commit 3e47944

Please sign in to comment.