create-stylelint 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/package.json +14 -24
  3. package/src/index.mjs +50 -20
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # create-stylelint
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/create-stylelint)](https://www.npmjs.com/package/create-stylelint)
4
- [![Testing](https://github.com/stylelint/create-stylelint/actions/workflows/testing.yml/badge.svg)](https://github.com/stylelint/create-stylelint/actions/workflows/testing.yml)
4
+ [![CI](https://github.com/stylelint/stylelint-create/actions/workflows/ci.yml/badge.svg)](https://github.com/stylelint/stylelint-create/actions/workflows/ci.yml)
5
5
 
6
6
  The [`create`](https://docs.npmjs.com/cli/commands/npm-init) script for [Stylelint](https://github.com/stylelint/stylelint).
7
7
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-stylelint",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "The npm init script for Stylelint.",
5
5
  "keywords": [
6
6
  "stylelint",
@@ -30,15 +30,15 @@
30
30
  ],
31
31
  "scripts": {
32
32
  "format": "prettier . --write --cache",
33
- "lint": "npm-run-all --parallel --continue-on-error lint:*",
33
+ "lint": "run-p --continue-on-error lint:*",
34
34
  "lint:formatting": "prettier . --check --cache",
35
35
  "lint:js": "eslint",
36
36
  "lint:md": "remark . --quiet --frail",
37
37
  "lint:packagejson": "npmPkgJsonLint .",
38
38
  "lint:types": "tsc",
39
39
  "pretest": "npm run lint",
40
- "test": "vitest run",
41
- "watch": "vitest watch"
40
+ "test": "node --test test/integration.test.js",
41
+ "watch": "node --test --watch test/integration.test.js"
42
42
  },
43
43
  "prettier": "@stylelint/prettier-config",
44
44
  "npmpackagejsonlint": {
@@ -50,32 +50,22 @@
50
50
  ]
51
51
  },
52
52
  "dependencies": {
53
- "@clack/prompts": "^1.2.0",
54
- "cosmiconfig": "^9.0.1",
55
- "execa": "^9.6.1",
56
- "picocolors": "^1.1.1",
57
- "semver": "^7.7.4",
58
- "strip-indent": "^4.1.0",
59
- "which-pm-runs": "^2.0.0"
53
+ "@clack/prompts": "^1.8.1",
54
+ "cosmiconfig": "^9.0.2",
55
+ "semver": "^7.8.5",
56
+ "tinyexec": "^1.3.1"
60
57
  },
61
58
  "devDependencies": {
62
- "@stylelint/npm-package-json-lint-config": "^5.1.0",
59
+ "@stylelint/npm-package-json-lint-config": "^6.0.0",
63
60
  "@stylelint/prettier-config": "^4.0.0",
64
61
  "@stylelint/remark-preset": "^5.1.1",
65
- "@types/node": "^25.5.0",
66
- "@types/which-pm-runs": "^1.0.2",
67
- "eslint": "^10.1.0",
62
+ "@types/node": "^26.6.3",
63
+ "eslint": "^10.11.0",
68
64
  "eslint-config-stylelint": "^27.0.0",
69
- "npm-run-all": "^4.1.5",
70
- "prettier": "^3.8.1",
65
+ "npm-run-all2": "^9.0.3",
66
+ "prettier": "^3.9.9",
71
67
  "remark-cli": "^12.0.1",
72
- "typescript": "^6.0.2",
73
- "vitest": "^4.1.1"
74
- },
75
- "optionalDependencies": {
76
- "@rollup/rollup-darwin-x64": "*",
77
- "@rollup/rollup-linux-x64-gnu": "*",
78
- "@rollup/rollup-win32-x64-msvc": "*"
68
+ "typescript": "^7.0.2"
79
69
  },
80
70
  "engines": {
81
71
  "node": ">=20.19.0"
package/src/index.mjs CHANGED
@@ -3,15 +3,11 @@
3
3
  import * as fs from 'node:fs';
4
4
  import * as path from 'node:path';
5
5
  import process from 'node:process';
6
+ import { styleText } from 'node:util'; // eslint-disable-line n/no-unsupported-features/node-builtins
6
7
 
7
8
  import { cancel, confirm, intro, isCancel, log, note, outro, spinner } from '@clack/prompts';
8
9
  import { cosmiconfig } from 'cosmiconfig';
9
- import { execa } from 'execa';
10
- import pc from 'picocolors';
11
- import stripIndent from 'strip-indent';
12
- // @ts-expect-error - TS2595: 'whichPMRuns' can only be imported by using a default import.
13
- // Need to wait for a `@types/which-pm-runs` new version.
14
- import { whichPMRuns } from 'which-pm-runs';
10
+ import { x } from 'tinyexec';
15
11
 
16
12
  const DEFAULT_CONFIG_FILE = 'stylelint.config.mjs';
17
13
  const DEFAULT_CONFIG_CONTENT = `/** @type {import("stylelint").Config} */
@@ -22,14 +18,14 @@ export default {
22
18
  const ADD_COMMAND = 'add -D stylelint stylelint-config-standard';
23
19
 
24
20
  export async function main() {
25
- const pkgManager = whichPMRuns()?.name ?? 'npm';
21
+ const pkgManager = detectPackageManager();
26
22
  const cwd = './';
27
23
 
28
- intro(pc.bgGreen(pc.white(' create-stylelint ')));
24
+ intro(styleText(['bgGreen', 'white'], ' create-stylelint '));
29
25
 
30
26
  note(
31
27
  stripIndent(`
32
- Create a ${pc.cyan(DEFAULT_CONFIG_FILE)} file containing:
28
+ Create a ${styleText('cyan', DEFAULT_CONFIG_FILE)} file containing:
33
29
 
34
30
  ${DEFAULT_CONFIG_CONTENT.split('\n').join('\n\t\t\t ')}
35
31
 
@@ -58,15 +54,15 @@ export async function main() {
58
54
  const basename = path.basename(existingConfig.filepath);
59
55
  const failureMessage =
60
56
  basename === 'package.json'
61
- ? `A ${pc.cyan('stylelint')} entry in ${pc.cyan('package.json')} already exists.`
62
- : `A ${pc.cyan(basename)} file already exists.`;
57
+ ? `A ${styleText('cyan', 'stylelint')} entry in ${styleText('cyan', 'package.json')} already exists.`
58
+ : `A ${styleText('cyan', basename)} file already exists.`;
63
59
 
64
60
  throw new Error(`${failureMessage} Remove it and then try again.`);
65
61
  }
66
62
 
67
63
  if (!directoryHasPackageJson(cwd)) {
68
64
  throw new Error(
69
- `A ${pc.cyan('package.json')} was not found. Run ${pc.cyan(`${pkgManager} init`)} and then try again.`,
65
+ `A ${styleText('cyan', 'package.json')} was not found. Run ${styleText('cyan', `${pkgManager} init`)} and then try again.`,
70
66
  );
71
67
  }
72
68
 
@@ -81,7 +77,14 @@ export async function main() {
81
77
  depsSpinner.start('Adding dependencies');
82
78
 
83
79
  try {
84
- await execa(pkgManager, [...ADD_COMMAND.split(' ')], { cwd });
80
+ const { exitCode, stderr, stdout } = await x(pkgManager, ADD_COMMAND.split(' '), {
81
+ nodeOptions: { cwd },
82
+ });
83
+
84
+ if (exitCode !== 0) {
85
+ throw new Error(stderr || stdout);
86
+ }
87
+
85
88
  depsSpinner.stop('Added dependencies');
86
89
  } catch (error) {
87
90
  handleError(depsSpinner, error);
@@ -93,25 +96,25 @@ export async function main() {
93
96
  stripIndent(`
94
97
  Lint your CSS files:
95
98
 
96
- ${pc.dim(`${getExecuteCommand(pkgManager)} stylelint "**/*.css"`)}
99
+ ${styleText('dim', `${getExecuteCommand(pkgManager)} stylelint "**/*.css"`)}
97
100
 
98
101
  Customize your config:
99
102
 
100
- - ${pc.underline(pc.cyan('https://stylelint.io/user-guide/customize'))}
103
+ - ${styleText(['underline', 'cyan'], 'https://stylelint.io/user-guide/customize')}
101
104
  `).trim(),
102
105
  'Next steps:',
103
106
  );
104
107
 
105
108
  log.message(
106
109
  stripIndent(`
107
- ${pc.dim('Support Stylelint:')}
110
+ ${styleText('dim', 'Support Stylelint:')}
108
111
 
109
- ${pc.dim(`- ${pc.underline(pc.cyan('https://github.com/sponsors/stylelint'))}`)}
110
- ${pc.dim(`- ${pc.underline(pc.cyan('https://opencollective.com/stylelint'))}`)}
112
+ ${styleText('dim', `- ${styleText(['underline', 'cyan'], 'https://github.com/sponsors/stylelint')}`)}
113
+ ${styleText('dim', `- ${styleText(['underline', 'cyan'], 'https://opencollective.com/stylelint')}`)}
111
114
  `).trim(),
112
115
  );
113
116
 
114
- outro(pc.green('Done!'));
117
+ outro(styleText('green', 'Done!'));
115
118
  }
116
119
 
117
120
  async function getExistingConfigInDirectory() {
@@ -155,6 +158,33 @@ function getExecuteCommand(pkgManager) {
155
158
  case 'yarn':
156
159
  return `${pkgManager} dlx`;
157
160
  default:
158
- throw new Error(`${pc.cyan(pkgManager)} package manager is not supported`);
161
+ throw new Error(`${styleText('cyan', pkgManager)} package manager is not supported`);
159
162
  }
160
163
  }
164
+
165
+ /**
166
+ * @param {string} string
167
+ * @return {string}
168
+ */
169
+ function stripIndent(string) {
170
+ const indents = string.match(/^[ \t]*(?=\S)/gm);
171
+
172
+ if (!indents) return string;
173
+
174
+ const commonIndent = Math.min(...indents.map((indent) => indent.length));
175
+
176
+ if (commonIndent === 0) return string;
177
+
178
+ return string.replace(new RegExp(`^[ \\t]{${commonIndent}}`, 'gm'), '');
179
+ }
180
+
181
+ function detectPackageManager() {
182
+ const userAgent = process.env.npm_config_user_agent;
183
+
184
+ if (!userAgent) return 'npm';
185
+
186
+ const [spec = ''] = userAgent.split(' ');
187
+ const name = spec.substring(0, spec.lastIndexOf('/'));
188
+
189
+ return name === 'npminstall' ? 'cnpm' : name;
190
+ }