Skip to content

Commit

Permalink
Changed next.config to be a typescript file
Browse files Browse the repository at this point in the history
  • Loading branch information
tkmcmaster committed Nov 22, 2024
1 parent b90d83a commit b3fbb05
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 43 deletions.
78 changes: 36 additions & 42 deletions controller/next.config.js → controller/next.config.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
// @ts-check
// These environment variables are exported to the client-side code. Do not put any variables with secure information here.

const { access, symlink } = require('fs/promises');
const { join } = require('path');
const CopyPlugin = require("copy-webpack-plugin");
const { platform } = require('os');
import { access, symlink } from "fs/promises";
import CopyPlugin from "copy-webpack-plugin";
import type { NextConfig } from "next";
import { join } from "path";
import { platform } from "os";

if (process.env.BASE_PATH && !process.env.BASE_PATH.startsWith("/")) {
const errorMessage = "process.env.BASE_PATH must start with a '/' found " + process.env.BASE_PATH;
// eslint-disable-next-line no-console
console.error(errorMessage);
throw new Error(errorMessage);
}
/** @type {import('next').NextConfig} */
const nextConfig = {
const nextConfig: NextConfig = {
eslint: {
// Warning: This allows production builds to successfully complete even if
// your project has ESLint errors.
ignoreDuringBuilds: true,
ignoreDuringBuilds: true
},
swcMinify: true,
// swcMinify: true,
// Base path doesn't work because it changes the path on the local server. We actually are running via a proxy base path
// https://nextjs.org/docs/api-reference/next.config.js/basepath
// https://stackoverflow.com/questions/60452054/nextjs-deploy-to-a-specific-url-path
Expand All @@ -29,32 +28,32 @@ const nextConfig = {
compiler: {
styledComponents: {
displayName: true,
ssr: true,
ssr: true
// ["styled-components", { "ssr": true, "displayName": true, "preprocess": false } ]
}
},
experimental: {
typedRoutes: true,
typedRoutes: true
// instrumentationHook: true,
},
webpack: (config, { isServer, dir: optionsDir }) => {
const wasmExtensionRegExp = /\.wasm$/;

config.resolve.extensions.push(".wasm");
config.module.rules.forEach(rule => {
(rule.oneOf || []).forEach(oneOf => {

config.module.rules.forEach((rule: any) => {
(rule.oneOf || []).forEach((oneOf: any) => {
if (oneOf.loader && oneOf.loader.indexOf("file-loader") >= 0) {
// Make file-loader ignore WASM files
oneOf.exclude.push(wasmExtensionRegExp);
}
});
});

config.output.webassemblyModuleFilename = 'static/wasm/[modulehash].wasm'
config.output.webassemblyModuleFilename = "static/wasm/[modulehash].wasm";
if (!config.experiments) { config.experiments = {}; }
config.experiments.asyncWebAssembly = true;

// https://github.com/vercel/next.js/issues/25852
// Compiling we run into an issue where it can't find the config wasm.
// On Linux the workaround is to create a symlink to the correct location
Expand All @@ -64,41 +63,45 @@ const nextConfig = {
// https://github.com/vercel/next.js/issues/25852#issuecomment-1727385542
? new CopyPlugin({
patterns: [
{ from: "../lib/config-wasm/pkg/config_wasm_bg.wasm", to: "./" },
],
{ from: "../lib/config-wasm/pkg/config_wasm_bg.wasm", to: "./" }
]
})
// https://github.com/vercel/next.js/issues/25852#issuecomment-1057059000
: new (class {
apply(compiler) {
apply (compiler: any) {
compiler.hooks.afterEmit.tapPromise(
'SymlinkWebpackPlugin',
async (compiler) => {
"SymlinkWebpackPlugin",
// eslint-disable-next-line @typescript-eslint/no-shadow
async (compiler: any) => {
if (isServer) {
const from = join(compiler.options.output.path, 'config_wasm_bg.wasm');
const to = join(optionsDir, '../lib/config-wasm/pkg/config_wasm_bg.wasm');
const from = join(compiler.options.output.path, "config_wasm_bg.wasm");
const to = join(optionsDir, "../lib/config-wasm/pkg/config_wasm_bg.wasm");
// options.dir /.../pewpew/controller
// console.log(`from/to: ${from} -> ${to}`);

try {
await access(from);
// eslint-disable-next-line no-console
console.log(`${from} already exists`);
return;
} catch (error) {
if (error.code === 'ENOENT') {
} catch (error: any) {
if (error?.code === "ENOENT") {
// No link exists
} else {
// eslint-disable-next-line no-console
console.error(`access ${from} error ${error}`, error);
throw error;
}
}

await symlink(to, from, 'junction');

await symlink(to, from, "junction");
// eslint-disable-next-line no-console
console.log(`created symlink ${from} -> ${to}`);
}
},
}
);
}
})(),
})()
);

return config;
Expand Down Expand Up @@ -131,29 +134,20 @@ const nextConfig = {
AUTH_HEADER_NAME: process.env.AUTH_HEADER_NAME,
COOKIE_DURATION_DAYS: process.env.COOKIE_DURATION_DAYS,
REFRESH_COOKIE_DURATION_DAYS: process.env.REFRESH_COOKIE_DURATION_DAYS,
HIDE_ENVIRONMENT: process.env.HIDE_ENVIRONMENT,
HIDE_ENVIRONMENT: process.env.HIDE_ENVIRONMENT
},
// https://github.com/vercel/next.js/discussions/11493#discussioncomment-14606
env: { // These are sent to the client and the server and are set at build time for static pages
LOGGING_LEVEL: process.env.LOGGING_LEVEL || process.env.LoggingLevel || "", // Only checks if debug
// @ts-ignore
APPLICATION_NAME: process.env.APPLICATION_NAME,
// @ts-ignore
SYSTEM_NAME: process.env.SYSTEM_NAME,
// @ts-ignore
FS_SITE: process.env.FS_SITE, // Used by auth client/Layout
// @ts-ignore
BASE_PATH: process.env.BASE_PATH, // client utils/Layout
// @ts-ignore
ASSET_PREFIX: process.env.ASSET_PREFIX, // client utils/Layout
// @ts-ignore
HIDE_ENVIRONMENT: process.env.HIDE_ENVIRONMENT, // Used by Layout
// @ts-ignore
AUTH_MODE: process.env.AUTH_MODE, // Used by auth client/Layout
// @ts-ignore
AUTH_COOKIE_NAME: process.env.AUTH_COOKIE_NAME, // Used by auth client/Layout
// @ts-ignore
AUTH_HEADER_NAME: process.env.AUTH_HEADER_NAME, // Used by auth client/Layout
AUTH_HEADER_NAME: process.env.AUTH_HEADER_NAME // Used by auth client/Layout
}
};

Expand Down
1 change: 0 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export default [{
"target/**",
"tests/**",
"next-env.d.ts",
"next.config.js",
"common/lib",
"controller/lib",
"controller/storybook-static",
Expand Down

0 comments on commit b3fbb05

Please sign in to comment.