Skip to content

Commit 8f3149f

Browse files
Harminder84snyk-botdddlr
authored
[Snyk] Security upgrade webpack from 5.76.1 to 5.94.0 (#1703)
* fix: examples/webpack/package.json to reduce vulnerabilities The following vulnerabilities are fixed with an upgrade: - https://snyk.io/vuln/SNYK-JS-WEBPACK-7840298 * Fix type errors * Add changeset * Fix another type error * Fix tests failing * Try to move yarn run v1.22.21 $ jest --no-cache jest-haste-map: duplicate manual mock found: cache The following files share their name; please delete one of them: * <rootDir>/packages/babel-plugin/dist/utils/__mocks__/cache.js * <rootDir>/packages/babel-plugin/src/utils/__mocks__/cache.ts Done in 26.38s. after bundle size * Increase size limit by 2 bytes to make CI happy --------- Co-authored-by: snyk-bot <[email protected]> Co-authored-by: Grant Wong <[email protected]>
1 parent 6ddeee2 commit 8f3149f

File tree

8 files changed

+228
-195
lines changed

8 files changed

+228
-195
lines changed

.changeset/mighty-squids-turn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@compiled/webpack-loader': patch
3+
---
4+
5+
When parsing the Webpack config `rules` option, also handle the situation where a rule might be falsy (null, undefined, 0, "")

.github/workflows/test.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ jobs:
4343
- name: Validate
4444
run: yarn lint
4545

46-
- name: Run tests
47-
run: yarn test:cover --ci
48-
4946
- name: Check prettier
5047
run: yarn prettier:check
5148

@@ -60,6 +57,11 @@ jobs:
6057
- name: Build source for remainder tests
6158
run: yarn build
6259

60+
# Needs to run after `yarn build` so that `packages/webpack-loader/`
61+
# tests can resolve `@compiled/react/runtime` correctly.
62+
- name: Run tests
63+
run: yarn test:cover --ci
64+
6365
- name: Run import test
6466
run: yarn test:imports
6567

examples/webpack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"react": "^17.0.2",
2020
"react-dom": "^17.0.2",
2121
"style-loader": "^3.3.2",
22-
"webpack": "^5.76.1",
22+
"webpack": "^5.94.0",
2323
"webpack-cli": "^5.0.1"
2424
}
2525
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
},
145145
{
146146
"path": "./packages/react/dist/browser/runtime/style.js",
147-
"limit": "480B",
147+
"limit": "482B",
148148
"import": "CS",
149149
"ignore": [
150150
"react"

packages/parcel-transformer/src/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import type { ParcelTransformerOpts } from './types';
88

99
export function createDefaultResolver(config: ParcelTransformerOpts): Resolver {
1010
const resolver = ResolverFactory.createResolver({
11+
// @ts-expect-error - enhanced-resolve CachedInputFileSystem types are not
12+
// compatible with @types/node fs types
1113
fileSystem: new CachedInputFileSystem(fs, 4000),
1214
...(config.extensions && {
1315
extensions: config.extensions,

packages/webpack-loader/src/create-default-resolver.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ export function createDefaultResolver({ resolveOptions, webpackResolveOptions }:
1414
// Setup the default resolver, where webpack will merge any passed in options with the default
1515
// resolve configuration. Ideally, we use this.getResolve({ ...resolve, useSyncFileSystemCalls: true, })
1616
// However, it does not work correctly when in development mode :/
17+
18+
// @ts-expect-error - enhanced-resolve CachedInputFileSystem types are not
19+
// compatible with @types/node fs types
1720
const resolver = ResolverFactory.createResolver({
18-
// @ts-expect-error
21+
// @ts-expect-error - enhanced-resolve CachedInputFileSystem types are not
22+
// compatible with @types/node fs types
1923
fileSystem: new CachedInputFileSystem(fs, 4000),
2024
...(webpackResolveOptions ?? {}),
2125
...resolveOptions,

packages/webpack-loader/src/utils.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import type { Compilation as CompilationType, Compiler, sources, RuleSetRule } from 'webpack';
1+
import type {
2+
Compilation as CompilationType,
3+
Compiler,
4+
sources,
5+
RuleSetRule,
6+
WebpackOptionsNormalized,
7+
} from 'webpack';
28

39
/**
410
* Helper function to set plugin configured option on the @compiled/webpack-loader
@@ -13,6 +19,7 @@ const setOptionOnCompiledWebpackLoader = (use: RuleSetRule['use'], pluginName: s
1319

1420
for (const nestedUse of use) {
1521
if (
22+
nestedUse &&
1623
typeof nestedUse === 'object' &&
1724
(nestedUse.loader === '@compiled/webpack-loader' ||
1825
nestedUse.loader?.includes('/node_modules/@compiled/webpack-loader'))
@@ -34,15 +41,21 @@ const setOptionOnCompiledWebpackLoader = (use: RuleSetRule['use'], pluginName: s
3441
* @returns
3542
*/
3643
export const setPluginConfiguredOption = (
37-
rules: (RuleSetRule | '...')[],
44+
rules: WebpackOptionsNormalized['module']['rules'],
3845
pluginName: string
3946
): void => {
4047
for (const r of rules) {
48+
if (!r) {
49+
continue;
50+
}
51+
4152
const rule = r as RuleSetRule;
4253
const nestedRules = rule.oneOf ?? rule.rules;
4354
if (nestedRules) {
4455
for (const nestedRule of nestedRules) {
45-
setOptionOnCompiledWebpackLoader(nestedRule.use, pluginName);
56+
if (nestedRule) {
57+
setOptionOnCompiledWebpackLoader(nestedRule.use, pluginName);
58+
}
4659
}
4760
} else {
4861
setOptionOnCompiledWebpackLoader(rule.use, pluginName);

0 commit comments

Comments
 (0)