@stencil/angular-output-target 1.4.0 → 1.4.1

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/dist/wizard.d.ts CHANGED
@@ -4,6 +4,6 @@ export declare const wizard: {
4
4
  id: string;
5
5
  displayName: string;
6
6
  description: string;
7
- run({ config, workspaceRoot, prompts, nypm }: WizardContext): Promise<void>;
7
+ run({ config, workspaceRoot, prompts, nypm, openStencilConfig }: WizardContext): Promise<void>;
8
8
  };
9
9
  };
package/dist/wizard.js CHANGED
@@ -1,54 +1,6 @@
1
- import { Project, SyntaxKind } from 'ts-morph';
2
1
  import { access, mkdir, readFile, writeFile } from 'node:fs/promises';
3
2
  import { join, relative, dirname } from 'node:path';
4
3
  // ---------------------------------------------------------------------------
5
- // ts-morph helpers
6
- // ---------------------------------------------------------------------------
7
- function amendStencilConfig(configPath, targetCode) {
8
- const project = new Project({ skipAddingFilesFromTsConfig: true });
9
- const src = project.addSourceFileAtPath(configPath);
10
- if (!src.getImportDeclaration('@stencil/angular-output-target')) {
11
- src.addImportDeclaration({
12
- moduleSpecifier: '@stencil/angular-output-target',
13
- namedImports: ['angularOutputTarget'],
14
- });
15
- }
16
- const existingProp = src
17
- .getDescendantsOfKind(SyntaxKind.PropertyAssignment)
18
- .find((p) => p.getName() === 'outputTargets');
19
- if (!existingProp) {
20
- const configObj = src.getVariableDeclaration('config')?.getInitializerIfKind(SyntaxKind.ObjectLiteralExpression) ??
21
- src
22
- .getDescendantsOfKind(SyntaxKind.ObjectLiteralExpression)
23
- .find((obj) => obj.getProperty('namespace') !== undefined);
24
- if (!configObj)
25
- throw new Error('Could not find Stencil config object in stencil.config.ts');
26
- configObj.addPropertyAssignment({ name: 'outputTargets', initializer: '[]' });
27
- }
28
- const prop = src.getDescendantsOfKind(SyntaxKind.PropertyAssignment).find((p) => p.getName() === 'outputTargets');
29
- const arr = prop.getInitializerIfKind(SyntaxKind.ArrayLiteralExpression);
30
- if (!arr)
31
- throw new Error('outputTargets is not an array literal in stencil.config.ts');
32
- const existing = arr.getText();
33
- const alreadyAdded = existing.includes('angularOutputTarget(');
34
- // Filter out any existing angularOutputTarget call so it can be replaced cleanly
35
- const elements = arr
36
- .getElements()
37
- .map((e) => e.getText().trim())
38
- .filter((e) => !e.includes('angularOutputTarget('));
39
- const hasStandalone = existing.includes("type: 'standalone'") ||
40
- existing.includes('type: "standalone"') ||
41
- existing.includes("type: 'dist-custom-elements'") ||
42
- existing.includes('type: "dist-custom-elements"');
43
- if (!hasStandalone)
44
- elements.push("{ type: 'standalone' }");
45
- elements.push(targetCode);
46
- prop.setInitializer(`[\n${elements.map((e) => ` ${e}`).join(',\n')},\n]`);
47
- src.formatText();
48
- src.saveSync();
49
- return !alreadyAdded;
50
- }
51
- // ---------------------------------------------------------------------------
52
4
  // pnpm build approval
53
5
  // ---------------------------------------------------------------------------
54
6
  async function allowPnpmBuild(pkg, rootDir, workspaceRoot) {
@@ -194,19 +146,12 @@ export const wizard = {
194
146
  id: '@stencil/angular-output-target',
195
147
  displayName: 'Angular',
196
148
  description: 'Angular component wrappers for your Stencil components',
197
- async run({ config, workspaceRoot, prompts, nypm }) {
149
+ async run({ config, workspaceRoot, prompts, nypm, openStencilConfig }) {
198
150
  const { intro, outro, text, select, confirm, spinner, isCancel, cancel, log } = prompts;
199
151
  intro('Angular output target');
200
- const stencilConfigPath = join(config.rootDir, 'stencil.config.ts');
201
152
  // Guard: already configured?
202
- const guardProject = new Project({ skipAddingFilesFromTsConfig: true });
203
- const alreadyConfigured = guardProject
204
- .addSourceFileAtPath(stencilConfigPath)
205
- .getDescendantsOfKind(SyntaxKind.PropertyAssignment)
206
- .find((p) => p.getName() === 'outputTargets')
207
- ?.getInitializerIfKind(SyntaxKind.ArrayLiteralExpression)
208
- ?.getText()
209
- .includes('angularOutputTarget(');
153
+ const editor = await openStencilConfig();
154
+ const alreadyConfigured = editor.outputTargetsContains('angularOutputTarget(');
210
155
  if (alreadyConfigured) {
211
156
  const redo = await confirm({
212
157
  message: 'angularOutputTarget is already in stencil.config.ts — reconfigure?',
@@ -219,18 +164,21 @@ export const wizard = {
219
164
  }
220
165
  // Where should the wrapper package live?
221
166
  let wrapperDir;
222
- const defaultName = `${config.fsNamespace}-angular`;
167
+ let wrapperPackageName = `${config.fsNamespace}-angular`;
223
168
  if (workspaceRoot) {
224
169
  const rawName = await text({
225
170
  message: 'Wrapper package name?',
226
- placeholder: defaultName,
227
- defaultValue: defaultName,
171
+ placeholder: wrapperPackageName,
172
+ defaultValue: wrapperPackageName,
228
173
  });
229
174
  if (isCancel(rawName)) {
230
175
  cancel('Setup cancelled.');
231
176
  return;
232
177
  }
233
- wrapperDir = join(dirname(config.rootDir), rawName);
178
+ wrapperPackageName = rawName;
179
+ // Directory is already namespaced by living under packages/, so keep it
180
+ // short rather than repeating the fsNamespace prefix from the package name.
181
+ wrapperDir = join(dirname(config.rootDir), 'angular');
234
182
  }
235
183
  else {
236
184
  const defaultRel = `../${config.fsNamespace}-angular`;
@@ -271,8 +219,15 @@ export const wizard = {
271
219
  const s = spinner();
272
220
  s.start(`Scaffolding wrapper package at ${relative(workspaceRoot ?? config.rootDir, wrapperDir)}`);
273
221
  try {
274
- const corePkgVersion = workspaceRoot ? 'workspace:*' : `file:${relative(wrapperDir, config.rootDir)}`;
275
- await scaffoldWrapperPackage(wrapperDir, `${config.fsNamespace}-angular`, componentCorePackage, corePkgVersion, config.fsNamespace, selectedOutputType);
222
+ // workspace:* only resolves under pnpm/yarn-berry/bun — npm and yarn classic reject
223
+ // the protocol outright (even for devDependencies that are never installed), so only
224
+ // use it when the detected package manager actually understands it.
225
+ const pm = workspaceRoot ? await nypm.detectPackageManager(workspaceRoot) : undefined;
226
+ const supportsWorkspaceProtocol = pm?.name === 'pnpm' || pm?.name === 'bun' || (pm?.name === 'yarn' && pm.majorVersion !== '1');
227
+ const corePkgVersion = supportsWorkspaceProtocol
228
+ ? 'workspace:*'
229
+ : `file:${relative(wrapperDir, config.rootDir)}`;
230
+ await scaffoldWrapperPackage(wrapperDir, wrapperPackageName, componentCorePackage, corePkgVersion, config.fsNamespace, selectedOutputType);
276
231
  s.stop('Wrapper package scaffolded');
277
232
  }
278
233
  catch (e) {
@@ -301,10 +256,20 @@ export const wizard = {
301
256
  ...(selectedOutputType !== 'standalone' ? [`outputType: '${selectedOutputType}'`] : []),
302
257
  ];
303
258
  const targetCode = `angularOutputTarget({\n ${lines.join(',\n ')},\n})`;
304
- // Amend stencil.config.ts in one pass so formatText() sees the final array
259
+ // Amend stencil.config.ts
305
260
  try {
306
- const added = amendStencilConfig(stencilConfigPath, targetCode);
307
- log.success(added ? 'stencil.config.ts updated' : 'angularOutputTarget already present — no changes made');
261
+ editor.addImport('@stencil/angular-output-target', ['angularOutputTarget']);
262
+ const hasStandalone = editor.outputTargetsContains("type: 'standalone'") ||
263
+ editor.outputTargetsContains('type: "standalone"') ||
264
+ editor.outputTargetsContains("type: 'dist-custom-elements'") ||
265
+ editor.outputTargetsContains('type: "dist-custom-elements"');
266
+ if (!hasStandalone)
267
+ editor.addOutputTarget("{ type: 'standalone' }");
268
+ if (!editor.replaceOutputTarget('angularOutputTarget(', targetCode)) {
269
+ editor.addOutputTarget(targetCode);
270
+ }
271
+ await editor.save();
272
+ log.success('stencil.config.ts updated');
308
273
  }
309
274
  catch (e) {
310
275
  log.warn(`Could not automatically update stencil.config.ts (${e}). Add manually:\n\n` +
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stencil/angular-output-target",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "description": "Angular output target for @stencil/core components.",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",
@@ -55,23 +55,21 @@
55
55
  "bugs": {
56
56
  "url": "https://github.com/stenciljs/output-targets/issues"
57
57
  },
58
- "dependencies": {
59
- "ts-morph": "^28.0.0"
60
- },
61
58
  "devDependencies": {
62
- "@stencil/cli": "^5.0.0 || >=5.0.0-alpha.0 <5.0.0-next.0",
63
59
  "@angular/core": "8.2.14",
64
60
  "@angular/forms": "8.2.14",
61
+ "@stencil/cli": "^5.0.0 || >=5.0.0-alpha.17 <5.0.0-next.0",
65
62
  "@stencil/core": "4.41.0",
66
- "@types/node": "^18.0.0",
67
- "npm-run-all2": "^6.2.4",
68
- "rimraf": "^5.0.0",
69
- "rollup": "^2.23.1",
70
- "typescript": "~5.7.0",
71
- "vitest": "^2.1.4"
63
+ "@types/node": "^18.19.130",
64
+ "npm-run-all2": "^6.2.6",
65
+ "rimraf": "^5.0.10",
66
+ "rollup": "^2.80.0",
67
+ "stencil-output-targets-shared": "workspace:*",
68
+ "typescript": "~5.7.3",
69
+ "vitest": "^2.1.9"
72
70
  },
73
71
  "peerDependencies": {
74
- "@stencil/core": ">=2.0.0 || >=3 || >=4.0.0 || ^5.0.0 || >=5.0.0-alpha.0 <5.0.0-next.0"
72
+ "@stencil/core": ">=2.0.0 || >=3 || >=4.0.0 || ^5.0.0 || >=5.0.0-alpha.17 <5.0.0-next.0"
75
73
  },
76
74
  "gitHead": "a3588e905186a0e86e7f88418fd5b2f9531b55e0"
77
75
  }