@stencil/angular-output-target 1.5.2 → 1.5.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/dist/wizard.js +47 -6
- package/package.json +1 -1
package/dist/wizard.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { access, mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
2
|
-
import { join, relative, dirname } from 'node:path';
|
|
2
|
+
import { join, relative, dirname, isAbsolute } from 'node:path';
|
|
3
3
|
// ---------------------------------------------------------------------------
|
|
4
4
|
// pnpm build approval
|
|
5
5
|
// ---------------------------------------------------------------------------
|
|
@@ -77,7 +77,22 @@ function toPascalCase(s) {
|
|
|
77
77
|
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
78
78
|
.join('');
|
|
79
79
|
}
|
|
80
|
-
|
|
80
|
+
/**
|
|
81
|
+
* The module the lazy loader's `defineCustomElements()` is imported from: the `./loader` entry
|
|
82
|
+
* when the project generates an `exports` map, otherwise its place in the `loader-bundle` output.
|
|
83
|
+
*/
|
|
84
|
+
function getLoaderModule(config, corePackageName) {
|
|
85
|
+
if (config.generateExportMaps === true) {
|
|
86
|
+
return `${corePackageName}/loader`;
|
|
87
|
+
}
|
|
88
|
+
const target = config.outputTargets?.find((o) => o.type === 'loader-bundle');
|
|
89
|
+
const rawDir = target?.dir ?? 'dist/loader-bundle';
|
|
90
|
+
const dir = (isAbsolute(rawDir) ? relative(config.rootDir, rawDir) : rawDir).replace(/\\/g, '/');
|
|
91
|
+
return `${corePackageName}/${dir}/${target?.loaderPath || 'loader'}`;
|
|
92
|
+
}
|
|
93
|
+
async function scaffoldWrapperPackage(wrapperDir, packageName, corePackageName, corePkgVersion, namespace, outputType,
|
|
94
|
+
/** For the 'component' type: the module to import the loader's `defineCustomElements()` from. */
|
|
95
|
+
loaderModule) {
|
|
81
96
|
const libDir = join(wrapperDir, 'src', 'lib');
|
|
82
97
|
await mkdir(libDir, { recursive: true });
|
|
83
98
|
const className = toPascalCase(namespace);
|
|
@@ -125,12 +140,23 @@ async function scaffoldWrapperPackage(wrapperDir, packageName, corePackageName,
|
|
|
125
140
|
// NgModule file — only needed for 'component' outputType
|
|
126
141
|
let ngModuleTs;
|
|
127
142
|
if (outputType === 'component') {
|
|
143
|
+
// The 'component' type's wrappers register nothing themselves: this module does it, with the
|
|
144
|
+
// lazy loader, when the consuming app starts. It's written once and never regenerated.
|
|
128
145
|
ngModuleTs =
|
|
129
|
-
`import { NgModule } from '@angular/core';\n` +
|
|
146
|
+
`import { NgModule, provideAppInitializer } from '@angular/core';\n` +
|
|
147
|
+
`import { defineCustomElements } from '${loaderModule}';\n` +
|
|
130
148
|
`import { DIRECTIVES } from './directives.array';\n\n` +
|
|
149
|
+
`/**\n` +
|
|
150
|
+
` * Declares every component, and registers the custom elements when the app starts.\n` +
|
|
151
|
+
` *\n` +
|
|
152
|
+
` * This file is yours to edit - Stencil doesn't regenerate it. Do any setup your library\n` +
|
|
153
|
+
` * needs before the components are defined in the initializer, e.g. \`setNonce()\` or\n` +
|
|
154
|
+
` * \`setTagTransformer()\` (both exported by the loader).\n` +
|
|
155
|
+
` */\n` +
|
|
131
156
|
`@NgModule({\n` +
|
|
132
157
|
` declarations: [...DIRECTIVES],\n` +
|
|
133
158
|
` exports: [...DIRECTIVES],\n` +
|
|
159
|
+
` providers: [provideAppInitializer(() => defineCustomElements())],\n` +
|
|
134
160
|
`})\n` +
|
|
135
161
|
`export class ${className}Module {}\n`;
|
|
136
162
|
}
|
|
@@ -240,7 +266,7 @@ export const wizard = {
|
|
|
240
266
|
const corePkgVersion = supportsWorkspaceProtocol
|
|
241
267
|
? 'workspace:*'
|
|
242
268
|
: `file:${relative(wrapperDir, config.rootDir)}`;
|
|
243
|
-
await scaffoldWrapperPackage(wrapperDir, wrapperPackageName, componentCorePackage, corePkgVersion, config.fsNamespace, selectedOutputType);
|
|
269
|
+
await scaffoldWrapperPackage(wrapperDir, wrapperPackageName, componentCorePackage, corePkgVersion, config.fsNamespace, selectedOutputType, selectedOutputType === 'component' ? getLoaderModule(config, componentCorePackage) : undefined);
|
|
244
270
|
s.stop('Wrapper package scaffolded');
|
|
245
271
|
}
|
|
246
272
|
catch (e) {
|
|
@@ -263,7 +289,8 @@ export const wizard = {
|
|
|
263
289
|
// Build target config
|
|
264
290
|
const lines = [
|
|
265
291
|
`componentCorePackage: '${componentCorePackage}'`,
|
|
266
|
-
`
|
|
292
|
+
// only the types built on the `standalone` output import from it
|
|
293
|
+
...(selectedOutputType !== 'component' ? [`customElementsDir: '${customElementsDir}'`] : []),
|
|
267
294
|
`directivesProxyFile: '${directivesProxyFile}'`,
|
|
268
295
|
...(directivesArrayFile ? [`directivesArrayFile: '${directivesArrayFile}'`] : []),
|
|
269
296
|
...(selectedOutputType !== 'standalone' ? [`outputType: '${selectedOutputType}'`] : []),
|
|
@@ -276,8 +303,18 @@ export const wizard = {
|
|
|
276
303
|
editor.outputTargetsContains('type: "standalone"') ||
|
|
277
304
|
editor.outputTargetsContains("type: 'dist-custom-elements'") ||
|
|
278
305
|
editor.outputTargetsContains('type: "dist-custom-elements"');
|
|
279
|
-
|
|
306
|
+
const hasLoaderBundle = editor.outputTargetsContains("type: 'loader-bundle'") ||
|
|
307
|
+
editor.outputTargetsContains('type: "loader-bundle"') ||
|
|
308
|
+
editor.outputTargetsContains("type: 'dist'") ||
|
|
309
|
+
editor.outputTargetsContains('type: "dist"');
|
|
310
|
+
// 'component' wrappers rely on the lazy loader; the other types import from `standalone`
|
|
311
|
+
if (selectedOutputType === 'component') {
|
|
312
|
+
if (!hasLoaderBundle)
|
|
313
|
+
editor.addOutputTarget("{ type: 'loader-bundle' }");
|
|
314
|
+
}
|
|
315
|
+
else if (!hasStandalone) {
|
|
280
316
|
editor.addOutputTarget("{ type: 'standalone' }");
|
|
317
|
+
}
|
|
281
318
|
if (!editor.replaceOutputTarget('angularOutputTarget(', targetCode)) {
|
|
282
319
|
editor.addOutputTarget(targetCode);
|
|
283
320
|
}
|
|
@@ -306,6 +343,10 @@ export const wizard = {
|
|
|
306
343
|
], { cwd: wrapperDir, dev: true });
|
|
307
344
|
log.success('Angular dependencies installed');
|
|
308
345
|
}
|
|
346
|
+
if (selectedOutputType === 'component' && !shouldScaffold) {
|
|
347
|
+
log.info(`NgModule components: your Angular package's module needs to call defineCustomElements() ` +
|
|
348
|
+
`from '${getLoaderModule(config, componentCorePackage)}' when the app starts, e.g. with provideAppInitializer().`);
|
|
349
|
+
}
|
|
309
350
|
outro('Angular output target configured');
|
|
310
351
|
},
|
|
311
352
|
},
|