Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃憤馃徏 improve: build performance #2387

Merged
merged 3 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sources/@roots/bud-build/src/config/experiments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const experiments: Factory<`experiments`> = async ({
}) =>
hooks.filter(`build.experiments`, {
backCompat: false,
cacheUnaffected: true,
lazyCompilation: isDevelopment
? {entries: false, imports: true}
: false,
Expand Down
2 changes: 1 addition & 1 deletion sources/@roots/bud-build/src/config/optimization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const optimization: Factory<`optimization`> = async ({
),
removeEmptyChunks: filter(
`build.optimization.removeEmptyChunks`,
isProduction,
false,
),
runtimeChunk: filter(`build.optimization.runtimeChunk`, `single`),
sideEffects: filter(`build.optimization.sideEffects`, isProduction),
Expand Down
6 changes: 5 additions & 1 deletion sources/@roots/bud-build/src/config/output/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ export const output: Factory<`output`> = async ({
iife: filter(`build.output.iife`, undefined),
module: filter(`build.output.module`, false),
path: filter(`build.output.path`, path(`@dist`)),
pathinfo: filter(`build.output.pathinfo`, true),
/**
* Path info is not necessary unless the user
* really knows what's going on.
*/
pathinfo: filter(`build.output.pathinfo`, false),
publicPath: filter(`build.output.publicPath`, `auto`),
scriptType: filter(
`build.output.scriptType`,
Expand Down
51 changes: 24 additions & 27 deletions sources/@roots/bud-compiler/src/service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,32 +214,31 @@
error: StatsError,
): ErrorWithSourceFile | StatsError => {
let file: SourceFile[`file`] | undefined
let module: undefined | Webpack.StatsModule

const moduleIdent = error.moduleId ?? error.moduleName
const ident = error.moduleId ?? error.moduleName

/**
* In a perfect world webpack plugins would use the
* `nameForCondition` property to identify the module.
*/
let module = this.compilationStats.children
.flatMap(child => child?.modules)
.find(
module =>
module?.id === moduleIdent || module?.name === moduleIdent,
)

/**
* If the module is not found, we try to parse the error message
*/
if (!moduleIdent) {
const stylelintExtracted = error.message.match(
/file:\/\/(.*)\x07(.*)\x1B]8;;/,
)

if (stylelintExtracted?.[1]) {
if (ident) {
module = this.compilationStats.children
.flatMap(child => child?.modules)
.find(module => [module?.id, module?.name].includes(ident))

/**
* If the module is not found, we try to parse the error message
*/
} else {
const styleError = error.message
.split(`\n`)?.[1]
?.match(/file:\/\/(.*)\x07(.*)\x1B]8;;/)
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Show resolved Hide resolved

if (styleError?.[1]) {
module = {
name: stylelintExtracted[2] ?? stylelintExtracted[1],
nameForCondition: stylelintExtracted[1],
name: styleError[2] ?? styleError[1],
nameForCondition: styleError[1],
}
}
}
Expand All @@ -259,14 +258,16 @@
file = this.app.path(`@src`, module.name)
}

return !file
? {...error, name: module.name ?? error.name}
: {...error, file, name: module.name ?? error.name}
const name = module.name ?? error.name ?? `error`
return {...error, file, name}
}

return errors?.map(parseError).filter(Boolean)
} catch (error) {
this.logger.warn(`error parsing errors`, error)
this.logger.warn(
`Problem parsing errors. This probably won't break anything but please report it: https://github.com/roots/bud/issues/new`,
error,
)
return errors
}
}
Expand All @@ -281,16 +282,12 @@
cachedAssets: true,
cachedModules: true,
entrypoints: true,
errorDetails: false,
errors: true,
errorsCount: true,
errorStack: false,
hash: true,
modules: true,
name: true,
outputPath: true,
reasons: false,
runtime: true,
timings: true,
warnings: true,
warningsCount: true,
Expand Down
25 changes: 14 additions & 11 deletions sources/@roots/bud-framework/src/notifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import isEmpty from '@roots/bud-support/lodash/isEmpty'
import isString from '@roots/bud-support/lodash/isString'
import logger from '@roots/bud-support/logger'
import {open, openEditor} from '@roots/bud-support/open'
import chalk from 'chalk'

const notifierPath = resolve(
dirname(fileURLToPath(import.meta.url)),
Expand Down Expand Up @@ -193,21 +194,23 @@ export class Notifier {
* True if editor opening is enabled
*/
public get openEditorEnabled(): boolean {
if (!this.editor) {
const enabled =
this.app.context.editor === true || // if true, fall back to default behavior
typeof this.app.context.editor === `string` // if string, opens in that editor

if (enabled && !this.editor) {
logger
.scope(`notifier`, `editor check`)
.warn(
`Editor not set.`,
`\n\nYou should set an editor using any of the following env vars:\n`,
`\n - BUD_EDITOR (bud specific; preferred)`,
`\n - VISUAL (unix standard)`,
`\n - EDITOR (unix standard)`,
`\n\nAlternatively, use the --editor flag.`,
chalk.magenta(`\n\nEditor not defined.`),
`\n\nYou should set an editor using any of the following ENV variables:\n`,
`\n - ${chalk.blue(`BUD_EDITOR`)} (bud specific; preferred)`,
`\n - ${chalk.blue(`VISUAL`)} (unix standard)`,
`\n - ${chalk.blue(`EDITOR`)} (unix standard)`,
`\n\nAlternatively, use the ${chalk.blue(`--editor`)} flag.`,
)
}
return (
this.app.context.editor === true || // if true, fall back to default behavior
typeof this.app.context.editor === `string` // if string, opens in that editor
)

return enabled
}
}
9 changes: 9 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4688,6 +4688,7 @@ __metadata:
"@roots/bud-babel": "workspace:*"
"@roots/bud-postcss": "workspace:*"
"@roots/bud-react": "workspace:*"
preact: 10.16.0
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -8362,6 +8363,7 @@ __metadata:
open-editor: 4.0.0
parse-semver: 1.1.1
patch-console: 2.0.0
preact: 10.16.0
pretty-format: 29.6.1
react: 18.2.0
remark: 14.0.3
Expand Down Expand Up @@ -29942,6 +29944,13 @@ __metadata:
languageName: node
linkType: hard

"preact@npm:10.16.0":
version: 10.16.0
resolution: "preact@npm:10.16.0"
checksum: 47a91f47d583b68a4afe971a7f992c06547df6d637cadf56eb3b69fee1fb202659b199af37d0e1a90637385144cadd75aa40acdb4e125cc4b3155e2883c24c07
languageName: node
linkType: hard

"prebuild-install@npm:^7.1.1":
version: 7.1.1
resolution: "prebuild-install@npm:7.1.1"
Expand Down
Loading