Skip to content

Commit

Permalink
Fix Segmentation fault errors for Cosmiconfig 8.2 (#6902)
Browse files Browse the repository at this point in the history
Co-authored-by: Masafumi Koba <473530+ybiquitous@users.noreply.github.com>
  • Loading branch information
romainmenke and ybiquitous committed Jun 5, 2023
1 parent 400600f commit 83a4698
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/blue-lions-guess.md
@@ -0,0 +1,5 @@
---
"stylelint": patch
---

Fixed: Segmentation fault errors for Cosmiconfig 8.2
8 changes: 7 additions & 1 deletion lib/createStylelint.js
@@ -1,6 +1,6 @@
'use strict';

const { cosmiconfig } = require('cosmiconfig');
const { cosmiconfig, defaultLoadersSync } = require('cosmiconfig');

const augmentConfig = require('./augmentConfig');
const FileCache = require('./utils/FileCache');
Expand All @@ -19,6 +19,12 @@ module.exports = function createStylelint(options = {}) {

_extendExplorer: cosmiconfig('', {
transform: augmentConfig.augmentConfigExtended(cwd),
loaders: {
'.cjs': (cjsPath, cjsContent) =>
Promise.resolve(defaultLoadersSync['.cjs'](cjsPath, cjsContent)),

Check warning on line 24 in lib/createStylelint.js

View check run for this annotation

Codecov / codecov/patch

lib/createStylelint.js#L24

Added line #L24 was not covered by tests
'.js': (jsPath, cjsContent) =>
Promise.resolve(defaultLoadersSync['.js'](jsPath, cjsContent)),

Check warning on line 26 in lib/createStylelint.js

View check run for this annotation

Codecov / codecov/patch

lib/createStylelint.js#L26

Added line #L26 was not covered by tests
},
stopDir: STOP_DIR,
}),

Expand Down
7 changes: 6 additions & 1 deletion lib/getConfigForFile.js
Expand Up @@ -3,7 +3,7 @@
const configurationError = require('./utils/configurationError');
const path = require('path');
const { augmentConfigFull } = require('./augmentConfig');
const { cosmiconfig } = require('cosmiconfig');
const { cosmiconfig, defaultLoadersSync } = require('cosmiconfig');

const IS_TEST = process.env.NODE_ENV === 'test';
const STOP_DIR = IS_TEST ? process.cwd() : undefined;
Expand Down Expand Up @@ -49,6 +49,11 @@ module.exports = async function getConfigForFile(

const configExplorer = cosmiconfig('stylelint', {
transform: (cosmiconfigResult) => augmentConfigFull(stylelint, filePath, cosmiconfigResult),
loaders: {
'.cjs': (cjsPath, cjsContent) =>
Promise.resolve(defaultLoadersSync['.cjs'](cjsPath, cjsContent)),

Check warning on line 54 in lib/getConfigForFile.js

View check run for this annotation

Codecov / codecov/patch

lib/getConfigForFile.js#L54

Added line #L54 was not covered by tests
'.js': (jsPath, cjsContent) => Promise.resolve(defaultLoadersSync['.js'](jsPath, cjsContent)),
},
stopDir: STOP_DIR,
});

Expand Down

0 comments on commit 83a4698

Please sign in to comment.