@blockquote/create-wc 2.8.1 → 2.8.3

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blockquote/create-wc",
3
- "version": "2.8.1",
3
+ "version": "2.8.3",
4
4
  "description": "Web component with Lit scaffolding - Extending Open Web Component",
5
5
  "keywords": [
6
6
  "Lit",
@@ -57,7 +57,7 @@
57
57
  "@open-wc/eslint-config": "^13.0.0",
58
58
  "eslint": "^9.39.2",
59
59
  "eslint-config-prettier": "^10.1.8",
60
- "prettier": "^3.7.4",
60
+ "prettier": "^3.8.0",
61
61
  "globals": "^17.0.0"
62
62
  },
63
63
  "engines": {
package/src/Generator.js CHANGED
@@ -1,30 +1,125 @@
1
1
  import prompts from 'prompts';
2
2
  import {spawn} from 'child_process';
3
+ import path from 'node:path';
4
+ import {fileURLToPath} from 'node:url';
3
5
  import _Generator from '@open-wc/create/dist/Generator.js';
4
6
  import {writeFilesToDisk} from '@open-wc/create/dist/core.js';
5
7
 
6
8
  const isWindows = process.platform === 'win32';
7
9
 
10
+ /**
11
+ * Normalizes cwd values to a valid absolute path.
12
+ *
13
+ * On Windows this also guards against a common ESM file-URL pitfall where
14
+ * `.pathname` yields values like `/C:/Users/...` which can become `C:\\C:\\...`
15
+ * after `path.resolve()`.
16
+ *
17
+ * @param {string | URL | undefined} maybePath
18
+ */
19
+ function normalizeCwd(maybePath) {
20
+ if (!maybePath || maybePath === 'auto') {
21
+ return process.cwd();
22
+ }
23
+
24
+ /** @type {string} */
25
+ let cwd;
26
+
27
+ if (maybePath instanceof URL) {
28
+ cwd = fileURLToPath(maybePath);
29
+ } else if (typeof maybePath === 'string' && maybePath.startsWith('file:')) {
30
+ cwd = fileURLToPath(new URL(maybePath));
31
+ } else {
32
+ cwd = String(maybePath);
33
+ }
34
+
35
+ if (isWindows) {
36
+ // Fix paths like "/C:/Users/..." or "\\C:\\Users...".
37
+ cwd = cwd.replace(/^[/\\]([A-Za-z]:[\\/])/, '$1');
38
+
39
+ // Best-effort support for MSYS-style paths like "/c/Users/...".
40
+ cwd = cwd.replace(/^\/([A-Za-z])\/(.*)/, (_, driveLetter, rest) => {
41
+ const drive = String(driveLetter).toUpperCase();
42
+ return `${drive}:\\${String(rest).replace(/\//g, '\\')}`;
43
+ });
44
+ }
45
+
46
+ return path.resolve(cwd);
47
+ }
48
+
49
+ /**
50
+ * Spawns a command in a way that works reliably on Windows.
51
+ * - On Windows we run via cmd.exe (/c) to support .cmd/.bat shims (npm, pnpm, etc)
52
+ * - We also normalize cwd when generator uses destinationPath='auto'
53
+ *
54
+ * @param {string} command
55
+ * @param {string[]} args
56
+ * @param {import('child_process').SpawnOptions} options
57
+ */
58
+ function spawnCommand(command, args, options = {}) {
59
+ const cwd = normalizeCwd(options.cwd);
60
+ const spawnOptions = {
61
+ ...options,
62
+ cwd,
63
+ stdio: 'inherit',
64
+ };
65
+
66
+ if (isWindows) {
67
+ const comspec = process.env.comspec || 'cmd.exe';
68
+ // Use windowsVerbatimArguments to prevent Node.js from escaping our already escaped command.
69
+ // Wrap command and args in an extra set of quotes for cmd.exe /c
70
+ const fullCommand = [command, ...args].join(' ');
71
+ return spawn(comspec, ['/d', '/s', '/c', `"${fullCommand}"`], {
72
+ ...spawnOptions,
73
+ windowsVerbatimArguments: true,
74
+ });
75
+ }
76
+
77
+ return spawn(command, args, spawnOptions);
78
+ }
79
+
8
80
  /**
9
81
  * @param {string} command
10
82
  * @param {object} options
11
83
  */
12
- function _install(command = 'npm', options = {}) {
84
+ /**
85
+ * @param {string} command
86
+ * @param {string[]} args
87
+ * @param {object} options
88
+ * @param {string} errorAction - description of action for error message
89
+ */
90
+ function runTask(command, args, options, errorAction) {
13
91
  return new Promise((resolve, reject) => {
14
- const cmdCommand = isWindows ? `${command}.cmd` : command;
92
+ let child;
93
+ try {
94
+ child = spawnCommand(command, args, options);
95
+ } catch (error) {
96
+ reject(error);
97
+ return;
98
+ }
15
99
 
16
- const install = spawn(cmdCommand, ['install'], {
17
- ...options,
18
- stdio: 'inherit',
100
+ child.on('error', (error) => {
101
+ const cwd = normalizeCwd(options.cwd);
102
+ reject(new Error(`Failed to ${errorAction} in ${cwd}: ${error.message}`));
19
103
  });
20
104
 
21
- install.on('close', (code) => {
22
- if (code === 0) resolve();
23
- else reject(new Error(`${command} install failed with code ${code}`));
105
+ child.on('close', (code) => {
106
+ if (code === 0) {
107
+ resolve();
108
+ } else {
109
+ reject(new Error(`${command} ${args.join(' ')} failed with code ${code}`));
110
+ }
24
111
  });
25
112
  });
26
113
  }
27
114
 
115
+ /**
116
+ * @param {string} command
117
+ * @param {object} options
118
+ */
119
+ function _install(command = 'npm', options = {}) {
120
+ return runTask(command, ['install'], options, `run ${command} install`);
121
+ }
122
+
28
123
  /**
29
124
  *
30
125
  * @param {string} where
@@ -44,8 +139,8 @@ export async function installNpm(where, command) {
44
139
  * @property {string} [tagName] the dash-case tag name
45
140
  * @property {string} [destinationPath='auto'] path to output to. default value 'auto' will output to current working directory
46
141
  * @property {'scaffold'} [type='scaffold'] path to output to. default value 'auto' will output to current working directory
47
- * @property {'true'|'false'} [writeToDisk] whether to write to disk
48
- * @property {'yarn'|'npm'|'false'} [installDependencies] whether and with which tool to install dependencies
142
+ * @property {'true'|'false'} [writeToDisk] whether to disk
143
+ * @property {'npm'|'pnpm'|'false'} [installDependencies] whether and with which tool to install dependencies
49
144
  */
50
145
  class Generator extends _Generator.default {
51
146
  constructor() {
@@ -84,21 +179,12 @@ class Generator extends _Generator.default {
84
179
  if (installDependencies === 'pnpm' || installDependencies === 'npm') {
85
180
  await installNpm(this.options.destinationPath, installDependencies);
86
181
 
87
- await new Promise((resolve, reject) => {
88
- const cmdInstallDependencies = isWindows
89
- ? `${installDependencies}.cmd`
90
- : installDependencies;
91
-
92
- const install = spawn(cmdInstallDependencies, ['run', 'analyze'], {
93
- cwd: this.options.destinationPath,
94
- stdio: 'inherit',
95
- });
96
-
97
- install.on('close', (code) => {
98
- if (code === 0) resolve();
99
- else reject(new Error(`${installDependencies} run analyze failed`));
100
- });
101
- });
182
+ await runTask(
183
+ installDependencies,
184
+ ['run', 'analyze'],
185
+ {cwd: this.options.destinationPath},
186
+ `run ${installDependencies} run analyze`
187
+ );
102
188
  }
103
189
  }
104
190
  }
@@ -69,8 +69,8 @@
69
69
  },
70
70
  "devDependencies": {
71
71
  "@eslint/js": "^9.39.2",
72
- "@html-eslint/eslint-plugin": "^0.52.1",
73
- "@html-eslint/parser": "^0.52.0",
72
+ "@html-eslint/eslint-plugin": "^0.53.0",
73
+ "@html-eslint/parser": "^0.53.0",
74
74
  "eslint": "^9.39.2",
75
75
  "eslint-config-prettier": "^10.1.8",
76
76
  "eslint-plugin-html": "^8.1.3",
@@ -78,12 +78,12 @@
78
78
  "eslint-plugin-lit": "^2.1.1",
79
79
  "eslint-plugin-lit-a11y": "^5.1.1",
80
80
  "eslint-plugin-wc": "^3.0.2",
81
- "typescript-eslint": "^8.52.0",
81
+ "typescript-eslint": "^8.53.1",
82
82
  "globals": "^17.0.0",
83
83
  "husky": "^9.1.7",
84
84
  "lint-staged": "^16.2.7",
85
- "prettier": "^3.7.4",
86
- "stylelint": "^16.26.1",
87
- "stylelint-config-standard-scss": "^16.0.0"
85
+ "prettier": "^3.8.0",
86
+ "stylelint": "^17.0.0",
87
+ "stylelint-config-standard-scss": "^17.0.0"
88
88
  }
89
89
  }
@@ -34,7 +34,7 @@
34
34
  "@open-wc/semantic-dom-diff": "^0.20.1",
35
35
  "@open-wc/testing-helpers": "^3.0.1",
36
36
  "playwright": "^1.57.0",
37
- "postcss-html": "^1.8.0",
37
+ "postcss-html": "^1.8.1",
38
38
  "postcss-lit": "^1.3.1",
39
39
  "@types/mocha": "^10.0.10",
40
40
  "rollup-plugin-copy": "^3.5.0",
@@ -43,11 +43,11 @@
43
43
  "chai-a11y-axe": "^1.5.0",
44
44
  "concurrently": "^9.2.1",
45
45
  "sort-package-json": "^3.6.0",
46
- "@vitest/browser-playwright": "^4.0.16",
47
- "@vitest/coverage-istanbul": "^4.0.16",
48
- "@vitest/coverage-v8": "^4.0.16",
49
- "@vitest/ui": "^4.0.16",
50
- "vitest": "^4.0.16",
46
+ "@vitest/browser-playwright": "^4.0.17",
47
+ "@vitest/coverage-istanbul": "^4.0.17",
48
+ "@vitest/coverage-v8": "^4.0.17",
49
+ "@vitest/ui": "^4.0.17",
50
+ "vitest": "^4.0.17",
51
51
  "vite": "^7.3.1"
52
52
  },
53
53
  "publishConfig": {