@blockquote/create-wc 2.8.0 → 2.8.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blockquote/create-wc",
3
- "version": "2.8.0",
3
+ "version": "2.8.2",
4
4
  "description": "Web component with Lit scaffolding - Extending Open Web Component",
5
5
  "keywords": [
6
6
  "Lit",
package/src/Generator.js CHANGED
@@ -1,26 +1,107 @@
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
84
  function _install(command = 'npm', options = {}) {
13
85
  return new Promise((resolve, reject) => {
14
- const cmdCommand = isWindows ? `${command}.cmd` : command;
86
+ let child;
87
+ try {
88
+ child = spawnCommand(command, ['install'], options);
89
+ } catch (error) {
90
+ reject(error);
91
+ return;
92
+ }
15
93
 
16
- const install = spawn(cmdCommand, ['install'], {
17
- ...options,
18
- stdio: 'inherit',
94
+ child.on('error', (error) => {
95
+ const cwd = normalizeCwd(options.cwd);
96
+ reject(new Error(`Failed to run ${command} install in ${cwd}: ${error.message}`));
19
97
  });
20
98
 
21
- install.on('close', (code) => {
22
- if (code === 0) resolve();
23
- else reject(new Error(`${command} install failed with code ${code}`));
99
+ child.on('close', (code) => {
100
+ if (code === 0) {
101
+ resolve();
102
+ } else {
103
+ reject(new Error(`${command} install failed with code ${code}`));
104
+ }
24
105
  });
25
106
  });
26
107
  }
@@ -44,8 +125,8 @@ export async function installNpm(where, command) {
44
125
  * @property {string} [tagName] the dash-case tag name
45
126
  * @property {string} [destinationPath='auto'] path to output to. default value 'auto' will output to current working directory
46
127
  * @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
128
+ * @property {'true'|'false'} [writeToDisk] whether to disk
129
+ * @property {'npm'|'pnpm'|'false'} [installDependencies] whether and with which tool to install dependencies
49
130
  */
50
131
  class Generator extends _Generator.default {
51
132
  constructor() {
@@ -85,18 +166,31 @@ class Generator extends _Generator.default {
85
166
  await installNpm(this.options.destinationPath, installDependencies);
86
167
 
87
168
  await new Promise((resolve, reject) => {
88
- const cmdInstallDependencies = isWindows
89
- ? `${installDependencies}.cmd`
90
- : installDependencies;
169
+ let child;
170
+ try {
171
+ child = spawnCommand(installDependencies, ['run', 'analyze'], {
172
+ cwd: this.options.destinationPath,
173
+ });
174
+ } catch (error) {
175
+ reject(error);
176
+ return;
177
+ }
91
178
 
92
- const install = spawn(cmdInstallDependencies, ['run', 'analyze'], {
93
- cwd: this.options.destinationPath,
94
- stdio: 'inherit',
179
+ child.on('error', (error) => {
180
+ const cwd = normalizeCwd(this.options.destinationPath);
181
+ reject(
182
+ new Error(
183
+ `Failed to run ${installDependencies} run analyze in ${cwd}: ${error.message}`
184
+ )
185
+ );
95
186
  });
96
187
 
97
- install.on('close', (code) => {
98
- if (code === 0) resolve();
99
- else reject(new Error(`${installDependencies} run analyze failed`));
188
+ child.on('close', (code) => {
189
+ if (code === 0) {
190
+ resolve();
191
+ } else {
192
+ reject(new Error(`${installDependencies} run analyze failed`));
193
+ }
100
194
  });
101
195
  });
102
196
  }
@@ -25,6 +25,7 @@ const baseConfig = [
25
25
  sourceType: 'module',
26
26
  globals: {
27
27
  ...globals.browser,
28
+ ...globals.es2023,
28
29
  ...globals.mocha,
29
30
  },
30
31
  },
@@ -9,11 +9,11 @@
9
9
  "experimentalDecorators": true,
10
10
  "forceConsistentCasingInFileNames": true,
11
11
  "lib": [
12
- "es2022",
12
+ "es2023",
13
13
  "DOM",
14
14
  "DOM.Iterable"
15
15
  ],
16
- "module": "es2022",
16
+ "module": "esnext",
17
17
  "moduleResolution": "Bundler",
18
18
  "noFallthroughCasesInSwitch": true,
19
19
  "noImplicitAny": true,
@@ -29,7 +29,7 @@
29
29
  "sourceMap": true,
30
30
  "strict": true,
31
31
  "stripInternal": true,
32
- "target": "es2022",
32
+ "target": "es2023",
33
33
  "types": [
34
34
  "mocha"
35
35
  ],