Skip to content

Commit

Permalink
add inline source maps
Browse files Browse the repository at this point in the history
  • Loading branch information
quisido committed May 23, 2024
1 parent 63bc0e0 commit cd1ab16
Show file tree
Hide file tree
Showing 15 changed files with 109 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ export default function getAccessControlAllowOrigin(): string {
* The HTTP protocol is for `serve`; the HTTPS protocol is for `dev`.
*/
const origin: string | null = request.headers.get('Origin');
if (origin === null) {
return '*';
}

if (
origin === 'http://localhost:3000' ||
origin === 'https://localhost:3000/'
origin === 'https://localhost:3000'
) {
return origin;
}
Expand Down
13 changes: 8 additions & 5 deletions packages/authn/src/features/get-usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ export default function getUsage(): (options: Options) => void {
type,
}: Options): void {
USAGE.writeDataPoint({
doubles: [type, count, per],
indexes: [
account.toString(),
Product.Authentication.toString(),
QUISIDO_AUTHENTICATION_PROJECT.toString(),
indexes: [account.toString()],

doubles: [
Product.Authentication,
QUISIDO_AUTHENTICATION_PROJECT,
type,
count,
per,
],
});
}
Expand Down
39 changes: 7 additions & 32 deletions packages/next/next.config.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,18 @@
import { type NextConfig } from 'next';
import { type ExperimentalConfig } from 'next/dist/server/config-shared.js';
import { cpus } from 'node:os';
import { join } from 'node:path';
import getCpus from './src/utils/get-cpus.js';
import getVersion from './src/utils/get-version.js';
import mapEnvironmentVariableNamesToRecord from './src/utils/map-environment-variable-names-to-record.js';
import mapNodeEnvToOnDemandEntries from './src/utils/map-node-env-to-on-demand-entries.js';
import mapNodeEnvToOutput from './src/utils/map-node-env-to-output.js';
import nextConfigWebpack from './src/utils/next-config-webpack.js';
import optional from './src/utils/optional.js';
import validateString from './src/utils/validate-string.js';
import withNextJsBundleAnalyzer from './src/utils/with-nextjs-bundle-analyzer.js';

const BASE = 10;
const CPUS_COUNT: number = cpus().length;
const cpus: number = getCpus();
const handleDemandEntries = mapNodeEnvToOnDemandEntries(process.env.NODE_ENV);

const getCpus = (): number => {
const cpus: string | undefined = process.env['CPUS'];
if (typeof cpus === 'undefined') {
return CPUS_COUNT;
}
return parseInt(cpus, BASE);
};

const reduceEnvironmentVariableNamesToRecord = (
record: Record<string, string | undefined>,
name: string,
): Record<string, string | undefined> => ({
...record,
[name]: validateString(process.env[name]),
});

const mapEnvironmentVariableNamesToRecord = (
names: readonly string[],
): Record<string, string | undefined> =>
names.reduce(reduceEnvironmentVariableNamesToRecord, {});

export default withNextJsBundleAnalyzer({
assetPrefix: '', // Same domain
basePath: '', // Deployed application pathname
Expand All @@ -47,6 +26,7 @@ export default withNextJsBundleAnalyzer({
reactStrictMode: true,
skipTrailingSlashRedirect: false,
trailingSlash: true,
webpack: nextConfigWebpack,

devIndicators: {
buildActivity: true,
Expand Down Expand Up @@ -84,7 +64,7 @@ export default withNextJsBundleAnalyzer({
* cacheMaxMemorySize: Number.POSITIVE_INFINITY,
* disablePostcssPresetEnv: true,
*/
cpus: getCpus(),
cpus,
craCompat: false,
// FallbackNodePolyfills: false,
forceSwcTransforms: true,
Expand Down Expand Up @@ -129,13 +109,8 @@ export default withNextJsBundleAnalyzer({
*/
} satisfies ExperimentalConfig,

images: {
loader: 'custom',
loaderFile: './scripts/imagekit-loader/index.js',
},

typescript: {
// TODO: 🔥🔥🔥 CHANGE ME BACK TO `false`! 🔥🔥🔥
// NextJS freezes with "Checking validity of types."
ignoreBuildErrors: true,
tsconfigPath: './tsconfig.prepack.json',
},
Expand Down
1 change: 1 addition & 0 deletions packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
"prettier": "^3.2.5",
"sass": "^1.75.0",
"serve": "^14.2.1",
"source-map": "^0.7.4",
"typescript": "^5.4.5",
"vite": "^5.2.11",
"vitest": "^1.6.0",
Expand Down
28 changes: 0 additions & 28 deletions packages/next/scripts/imagekit-loader/index.js

This file was deleted.

12 changes: 0 additions & 12 deletions packages/next/scripts/imagekit-loader/sign.js

This file was deleted.

3 changes: 3 additions & 0 deletions packages/next/src/components/preconnect.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { type ReactElement } from 'react';

interface Props {
readonly as?: string | undefined;
readonly children: string;
readonly cors?: boolean | undefined;
}

export default function Preconnect({
as,
children,
cors = false,
}: Props): ReactElement {
return (
<link
as={as}
crossOrigin={cors ? 'anonymous' : undefined}
href={children}
rel="preconnect"
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/features/preconnect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function PreconnectFeature(): ReactElement {
<Preconnect>https://dataplane.rum.us-west-2.amazonaws.com</Preconnect>
<Preconnect>https://edge.fullstory.com</Preconnect>
<Preconnect>https://fonts.googleapis.com</Preconnect>
<Preconnect cors>https://fonts.gstatic.com</Preconnect>
<Preconnect as="font" cors>https://fonts.gstatic.com</Preconnect>
<Preconnect>https://o592283.ingest.sentry.io</Preconnect>
<Preconnect>https://r.logr-ingest.com</Preconnect>
<Preconnect>https://rs.fullstory.com</Preconnect>
Expand Down
5 changes: 5 additions & 0 deletions packages/next/src/types/webpack-rule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { ModuleOptions } from "webpack";

type Item<T> = T extends readonly (infer U)[] ? U : never;

export type WebpackRule = Item<ModuleOptions['rules']>;
13 changes: 13 additions & 0 deletions packages/next/src/utils/get-cpus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { cpus } from 'node:os';

const BASE = 10;
const CPUS_COUNT: number = cpus().length;

export default function getCpus(): number {
const cpus: string | undefined = process.env['CPUS'];
if (typeof cpus === 'undefined') {
return CPUS_COUNT;
}

return parseInt(cpus, BASE);
}
9 changes: 9 additions & 0 deletions packages/next/src/utils/is-rule-set-rule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { RuleSetRule } from "webpack";
import type { WebpackRule } from "../types/webpack-rule.js";

export default function isRuleSetRule(rule: WebpackRule): rule is RuleSetRule {
return (
typeof rule === 'object' ||
rule !== null
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import reduceEnvironmentVariableNamesToRecord from "./reduce-environment-variable-names-to-record.js";

export default function mapEnvironmentVariableNamesToRecord(
names: readonly string[],
): Record<string, string | undefined> {
return names.reduce(reduceEnvironmentVariableNamesToRecord, {});
}
38 changes: 38 additions & 0 deletions packages/next/src/utils/next-config-webpack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import assert from 'node:assert';
import type { Configuration } from 'webpack';
import type { WebpackRule } from '../types/webpack-rule.js';
import isRuleSetRule from './is-rule-set-rule.js';

const mapRule = (rule: WebpackRule): WebpackRule => {
if (
!isRuleSetRule(rule) ||
rule.loader !== 'babel-loader' ||
typeof rule.options !== 'object'
) {
return rule;
}

return {
...rule,
options: {
...rule.options,
sourceMaps: true,
},
};
};

export default function nextConfigWebpack(
config: Configuration,
): Configuration {
assert('module' in config);
assert('rules' in config.module);

return {
...config,
devtool: 'source-map',
module: {
...config.module,
rules: config.module.rules.map(mapRule),
},
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import validateString from "./validate-string.js";

export default function reduceEnvironmentVariableNamesToRecord(
record: Record<string, string | undefined>,
name: string,
): Record<string, string | undefined> {
return {
...record,
[name]: validateString(process.env[name]),
};
}
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5216,6 +5216,7 @@ __metadata:
sentry-react: "workspace:^"
serve: "npm:^14.2.1"
sharp: "npm:^0.33.3"
source-map: "npm:^0.7.4"
typescript: "npm:^5.4.5"
use-force-update: "npm:^1.0.11"
use-mui: "npm:^1.0.6"
Expand Down

0 comments on commit cd1ab16

Please sign in to comment.