Skip to content

Commit

Permalink
Security fix for semver vulnerability (#7043)
Browse files Browse the repository at this point in the history
Co-authored-by: Richard Hallows <jeddy3@users.noreply.github.com>
Co-authored-by: Masafumi Koba <473530+ybiquitous@users.noreply.github.com>
  • Loading branch information
3 people committed Jul 5, 2023
1 parent a42f955 commit 56a545e
Show file tree
Hide file tree
Showing 9 changed files with 513 additions and 165 deletions.
5 changes: 5 additions & 0 deletions .changeset/twenty-camels-promise.md
@@ -0,0 +1,5 @@
---
"stylelint": patch
---

Security: fix for `semver` vulnerability
5 changes: 0 additions & 5 deletions bin/stylelint.js

This file was deleted.

5 changes: 5 additions & 0 deletions bin/stylelint.mjs
@@ -0,0 +1,5 @@
#!/usr/bin/env node

import cli from '../lib/cli.mjs';

cli(process.argv.slice(2));
4 changes: 1 addition & 3 deletions lib/__tests__/cli.test.mjs
Expand Up @@ -10,16 +10,14 @@ import stripAnsi from 'strip-ansi';
import readJSONFile from '../testUtils/readJSONFile.mjs';
import replaceBackslashes from '../testUtils/replaceBackslashes.mjs';

import cli from '../cli.js';
import cli, { buildCLI } from '../cli.mjs';

const pkg = readJSONFile(new URL('../../package.json', import.meta.url));

const fixturesPath = (...elems) =>
replaceBackslashes(path.join(fileURLToPath(new URL('./fixtures', import.meta.url)), ...elems));

describe('buildCLI', () => {
const { buildCLI } = cli;

it('flags - default', () => {
expect(buildCLI([]).flags).toEqual({
allowEmptyInput: false,
Expand Down
49 changes: 26 additions & 23 deletions lib/cli.js → lib/cli.mjs
@@ -1,23 +1,28 @@
'use strict';

const { EOL } = require('os');
const meow = require('meow');
const path = require('path');
const { red, dim } = require('picocolors');
const resolveFrom = require('resolve-from');

const { isPlainObject } = require('./utils/validateTypes');
const checkInvalidCLIOptions = require('./utils/checkInvalidCLIOptions');
const printConfig = require('./printConfig');
const standalone = require('./standalone');
const writeOutputFile = require('./writeOutputFile');
const resolveCustomFormatter = require('./resolveCustomFormatter');
const {
import picocolors from 'picocolors';
const { dim, red } = picocolors;

import { EOL } from 'os';
import meow from 'meow';
import path from 'path';
import resolveFrom from 'resolve-from';

import checkInvalidCLIOptions from './utils/checkInvalidCLIOptions.js';
import { isPlainObject } from './utils/validateTypes.js';
import printConfig from './printConfig.js';
import resolveCustomFormatter from './resolveCustomFormatter.js';
import standalone from './standalone.js';
import writeOutputFile from './writeOutputFile.js';

import {
DEFAULT_CACHE_LOCATION,
DEFAULT_IGNORE_FILENAME,
DEFAULT_FORMATTER,
DEFAULT_IGNORE_FILENAME,
EXIT_CODE_ERROR,
} = require('./constants');
} from './constants.js';

import { createRequire } from 'module';
// @ts-expect-error
const require = createRequire(import.meta.url);

/**
* @typedef {{
Expand Down Expand Up @@ -376,7 +381,7 @@ const meowOptions = {
* @param {string[]} argv
* @returns {Promise<any>}
*/
module.exports = async function main(argv) {
export default async function main(argv) {
const cli = buildCLI(argv);

const invalidOptionsMessage = checkInvalidCLIOptions(meowOptions.flags, cli.flags);
Expand Down Expand Up @@ -574,7 +579,7 @@ module.exports = async function main(argv) {
}
})
.catch(handleError);
};
}

/**
* @param {{ stack: any, code: any }} err
Expand Down Expand Up @@ -628,9 +633,7 @@ async function getStdin() {
* @param {string[]} argv
* @returns {CLIOptions}
*/
function buildCLI(argv) {
export function buildCLI(argv) {
// @ts-expect-error -- TS2322: Type 'Result<AnyFlags>' is not assignable to type 'CLIOptions'.
return meow({ ...meowOptions, argv });
return meow({ ...meowOptions, argv, importMeta: import.meta });
}

module.exports.buildCLI = buildCLI;

0 comments on commit 56a545e

Please sign in to comment.