-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
109 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/next/src/utils/map-environment-variable-names-to-record.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, {}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
}, | ||
}; | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/next/src/utils/reduce-environment-variable-names-to-record.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters