@stencil/cli 5.0.0-beta.9 → 5.0.0-rc.0
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/README.md +1 -1
- package/dist/index.d.mts +34 -4
- package/dist/index.mjs +467 -803
- package/package.json +8 -5
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LOG_LEVELS } from "@stencil/core/compiler";
|
|
2
|
-
import { buildError, catchError, hasError, isFunction, isOutputTargetDistLazy, isOutputTargetDocs,
|
|
2
|
+
import { buildError, catchError, hasError, isFunction, isOutputTargetDistLazy, isOutputTargetDocs, isOutputTargetStandalone, isOutputTargetWww, isString, normalizePath, readOnlyArrayHasStringMember, result, shouldIgnoreError, toCamelCase, validateComponentTag } from "@stencil/core/compiler/utils";
|
|
3
3
|
import { basename, dirname, join, parse, relative, resolve } from "node:path";
|
|
4
4
|
import { mkdir, readFile, readdir, writeFile } from "node:fs/promises";
|
|
5
5
|
import * as p from "@clack/prompts";
|
|
@@ -13,19 +13,17 @@ import { getPackageInfo } from "local-pkg";
|
|
|
13
13
|
import { existsSync } from "node:fs";
|
|
14
14
|
import { homedir } from "node:os";
|
|
15
15
|
import { dirname as dirname$1, isAbsolute, join as join$1, relative as relative$1 } from "path";
|
|
16
|
-
import { generateIndexHtml, generatePackageJsonFields, generateStencilConfig, getComponentBoilerplate, getPreviewHtmlBoilerplate, getStyleBoilerplate, getTemplatePath, getUsageExampleBoilerplate, toPascalCase } from "@stencil/templates";
|
|
16
|
+
import { generateIndexHtml, generatePackageJsonFields, generateStencilConfig, getComponentBoilerplate, getCssOnlyComponentBoilerplate, getPreviewHtmlBoilerplate, getStyleBoilerplate, getTemplatePath, getUsageExampleBoilerplate, toPascalCase } from "@stencil/templates";
|
|
17
17
|
import { start } from "@stencil/dev-server";
|
|
18
18
|
//#region src/config-flags.ts
|
|
19
19
|
/**
|
|
20
20
|
* All the Boolean options supported by the Stencil CLI
|
|
21
21
|
*/
|
|
22
22
|
const BOOLEAN_CLI_FLAGS = [
|
|
23
|
-
"build",
|
|
24
23
|
"cache",
|
|
25
24
|
"ci",
|
|
26
25
|
"debug",
|
|
27
26
|
"dev",
|
|
28
|
-
"docs",
|
|
29
27
|
"dryRun",
|
|
30
28
|
"help",
|
|
31
29
|
"log",
|
|
@@ -588,7 +586,6 @@ const mergeFlags = (config, flags) => {
|
|
|
588
586
|
if (flags.debug === true || flags.verbose === true) merged.logLevel = "debug";
|
|
589
587
|
else if (flags.logLevel) merged.logLevel = flags.logLevel;
|
|
590
588
|
if (typeof flags.watch === "boolean") merged.watch = flags.watch;
|
|
591
|
-
if (flags.docs === true) merged._docsFlag = true;
|
|
592
589
|
if (typeof flags.profile === "boolean") merged.profile = flags.profile;
|
|
593
590
|
if (typeof flags.log === "boolean") merged.writeLog = flags.log;
|
|
594
591
|
if (typeof flags.cache === "boolean") merged.enableCache = flags.cache;
|
|
@@ -609,155 +606,164 @@ const mergeFlags = (config, flags) => {
|
|
|
609
606
|
async function openStencilConfig(configPath) {
|
|
610
607
|
let text = await readFile(configPath, "utf8");
|
|
611
608
|
const parse = () => ts.createSourceFile(configPath, text, ts.ScriptTarget.Latest, true);
|
|
612
|
-
|
|
609
|
+
const nodeText = (node) => text.slice(node.getStart(), node.getEnd());
|
|
610
|
+
const splice = (start, end, replacement) => {
|
|
611
|
+
text = text.slice(0, start) + replacement + text.slice(end);
|
|
612
|
+
};
|
|
613
|
+
const indentAt = (pos) => {
|
|
614
|
+
const lineStart = text.lastIndexOf("\n", pos - 1) + 1;
|
|
615
|
+
return text.slice(lineStart, pos).match(/^\s*/)?.[0] ?? "";
|
|
616
|
+
};
|
|
617
|
+
const reindent = (code, indent) => code.replace(/\n/g, `\n${indent}`);
|
|
618
|
+
const listItems = (list) => ts.isArrayLiteralExpression(list) ? list.elements : list.properties;
|
|
619
|
+
const isMultiLine = (list) => {
|
|
620
|
+
const [first] = listItems(list);
|
|
621
|
+
return !!first && text.slice(list.getStart(), first.getStart()).includes("\n");
|
|
622
|
+
};
|
|
623
|
+
const findProp = (obj, name) => obj.properties.find((p) => ts.isPropertyAssignment(p) && ts.isIdentifier(p.name) && p.name.text === name);
|
|
624
|
+
function findConfigObject(sf) {
|
|
625
|
+
for (const stmt of sf.statements) if (ts.isVariableStatement(stmt)) {
|
|
626
|
+
for (const decl of stmt.declarationList.declarations) if (ts.isIdentifier(decl.name) && decl.name.text === "config" && decl.initializer && ts.isObjectLiteralExpression(decl.initializer)) return decl.initializer;
|
|
627
|
+
}
|
|
613
628
|
let found;
|
|
614
629
|
const visit = (node) => {
|
|
615
|
-
if (
|
|
616
|
-
|
|
630
|
+
if (found) return;
|
|
631
|
+
if (ts.isObjectLiteralExpression(node) && findProp(node, "namespace")) {
|
|
632
|
+
found = node;
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
ts.forEachChild(node, visit);
|
|
617
636
|
};
|
|
618
637
|
visit(sf);
|
|
619
638
|
return found;
|
|
620
639
|
}
|
|
621
|
-
function
|
|
622
|
-
|
|
623
|
-
|
|
640
|
+
function requireConfigObject() {
|
|
641
|
+
const configObj = findConfigObject(parse());
|
|
642
|
+
if (!configObj) throw new Error("Could not find Stencil config object in stencil.config.ts");
|
|
643
|
+
return configObj;
|
|
644
|
+
}
|
|
645
|
+
function findArray(propName) {
|
|
646
|
+
const sf = parse();
|
|
647
|
+
const configObj = findConfigObject(sf);
|
|
648
|
+
if (configObj) {
|
|
649
|
+
const init = findProp(configObj, propName)?.initializer;
|
|
650
|
+
return init && ts.isArrayLiteralExpression(init) ? init : void 0;
|
|
624
651
|
}
|
|
625
652
|
let found;
|
|
626
653
|
const visit = (node) => {
|
|
627
654
|
if (found) return;
|
|
628
|
-
if (ts.
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
return;
|
|
632
|
-
}
|
|
655
|
+
if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name) && node.name.text === propName && ts.isArrayLiteralExpression(node.initializer)) {
|
|
656
|
+
found = node.initializer;
|
|
657
|
+
return;
|
|
633
658
|
}
|
|
634
659
|
ts.forEachChild(node, visit);
|
|
635
660
|
};
|
|
636
661
|
visit(sf);
|
|
637
662
|
return found;
|
|
638
663
|
}
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
const
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
text = text.slice(0, lineStart) + text.slice(end);
|
|
659
|
-
} else {
|
|
660
|
-
let start = element.getStart();
|
|
661
|
-
let end = element.getEnd();
|
|
662
|
-
if (idx < arr.elements.length - 1) {
|
|
663
|
-
const trailingMatch = text.slice(end).match(/^,\s*/);
|
|
664
|
-
if (trailingMatch) end += trailingMatch[0].length;
|
|
665
|
-
} else if (idx > 0) {
|
|
666
|
-
const precedingMatch = text.slice(0, start).match(/,\s*$/);
|
|
667
|
-
if (precedingMatch) start -= precedingMatch[0].length;
|
|
668
|
-
}
|
|
669
|
-
text = text.slice(0, start) + text.slice(end);
|
|
664
|
+
/**
|
|
665
|
+
* Insert `code` as a new item of an array / object literal, matching the list's own layout
|
|
666
|
+
* (one item per line, or all on one line).
|
|
667
|
+
* @param list - The array or object literal to insert into.
|
|
668
|
+
* @param code - Source of the new item, indented relative to its own start.
|
|
669
|
+
* @param anchor - Item to insert after. Defaults to the last one.
|
|
670
|
+
*/
|
|
671
|
+
function insertItem(list, code, anchor) {
|
|
672
|
+
const items = listItems(list);
|
|
673
|
+
const [open, close] = ts.isArrayLiteralExpression(list) ? "[]" : "{}";
|
|
674
|
+
const multiLine = isMultiLine(list);
|
|
675
|
+
if (!multiLine && (code.includes("\n") || items.length === 0 && ts.isObjectLiteralExpression(list))) {
|
|
676
|
+
const baseIndent = indentAt(list.getStart());
|
|
677
|
+
const indent = baseIndent + " ";
|
|
678
|
+
const lines = items.map(nodeText);
|
|
679
|
+
const at = anchor ? items.indexOf(anchor) + 1 : lines.length;
|
|
680
|
+
lines.splice(at, 0, reindent(code, indent));
|
|
681
|
+
splice(list.getStart(), list.getEnd(), `${open}\n${indent}${lines.join(`,\n${indent}`)},\n${baseIndent}${close}`);
|
|
682
|
+
return;
|
|
670
683
|
}
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
function appendToArray(arr, code) {
|
|
674
|
-
if (arr.elements.length === 0) {
|
|
675
|
-
const insertPos = arr.getEnd() - 1;
|
|
676
|
-
text = text.slice(0, insertPos) + code + text.slice(insertPos);
|
|
684
|
+
if (items.length === 0) {
|
|
685
|
+
splice(list.getEnd() - 1, list.getEnd() - 1, code);
|
|
677
686
|
return;
|
|
678
687
|
}
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
const
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
const indent =
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
} else text = `${text.slice(0, insertPos)}${separator} ${code}${text.slice(insertPos)}`;
|
|
688
|
+
anchor ??= items[items.length - 1];
|
|
689
|
+
let pos = anchor.getEnd();
|
|
690
|
+
const trailingComma = text.slice(pos).match(/^\s*,/);
|
|
691
|
+
if (trailingComma) pos += trailingComma[0].length;
|
|
692
|
+
const before = trailingComma ? "" : ",";
|
|
693
|
+
const after = trailingComma ? "," : "";
|
|
694
|
+
if (multiLine) {
|
|
695
|
+
const indent = indentAt(items[0].getStart());
|
|
696
|
+
splice(pos, pos, `${before}\n${indent}${reindent(code, indent)}${after}`);
|
|
697
|
+
} else splice(pos, pos, `${before} ${code}${after}`);
|
|
690
698
|
}
|
|
691
|
-
function
|
|
692
|
-
const
|
|
693
|
-
|
|
694
|
-
let
|
|
695
|
-
if (
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
699
|
+
function removeItem(arr, element) {
|
|
700
|
+
const idx = arr.elements.indexOf(element);
|
|
701
|
+
let start = element.getStart();
|
|
702
|
+
let end = element.getEnd();
|
|
703
|
+
if (isMultiLine(arr)) {
|
|
704
|
+
start = text.lastIndexOf("\n", start);
|
|
705
|
+
end += text.slice(end).match(/^\s*,/)?.[0].length ?? 0;
|
|
706
|
+
} else if (idx < arr.elements.length - 1) end += text.slice(end).match(/^,\s*/)?.[0].length ?? 0;
|
|
707
|
+
else if (idx > 0) start -= text.slice(0, start).match(/,\s*$/)?.[0].length ?? 0;
|
|
708
|
+
splice(start, end, "");
|
|
709
|
+
}
|
|
710
|
+
function hasImport(moduleSpecifier) {
|
|
711
|
+
return parse().statements.some((s) => ts.isImportDeclaration(s) && ts.isStringLiteral(s.moduleSpecifier) && s.moduleSpecifier.text === moduleSpecifier);
|
|
712
|
+
}
|
|
713
|
+
function arrayProp(propName) {
|
|
714
|
+
const findElement = (arr, substring) => arr?.elements.find((element) => nodeText(element).includes(substring));
|
|
715
|
+
return {
|
|
716
|
+
contains(substring) {
|
|
717
|
+
const arr = findArray(propName);
|
|
718
|
+
return arr ? nodeText(arr).includes(substring) : false;
|
|
719
|
+
},
|
|
720
|
+
add(expression) {
|
|
721
|
+
const arr = findArray(propName);
|
|
722
|
+
if (arr) insertItem(arr, expression);
|
|
723
|
+
else insertItem(requireConfigObject(), `${propName}: [\n ${reindent(expression, " ")},\n]`);
|
|
724
|
+
},
|
|
725
|
+
replace(substring, expression) {
|
|
726
|
+
const element = findElement(findArray(propName), substring);
|
|
727
|
+
if (!element) return false;
|
|
728
|
+
splice(element.getStart(), element.getEnd(), reindent(expression, indentAt(element.getStart())));
|
|
729
|
+
return true;
|
|
730
|
+
},
|
|
731
|
+
remove(substring) {
|
|
732
|
+
const arr = findArray(propName);
|
|
733
|
+
const element = findElement(arr, substring);
|
|
734
|
+
if (!arr || !element) return false;
|
|
735
|
+
removeItem(arr, element);
|
|
736
|
+
return true;
|
|
737
|
+
}
|
|
738
|
+
};
|
|
713
739
|
}
|
|
740
|
+
const outputTargets = arrayProp("outputTargets");
|
|
741
|
+
const plugins = arrayProp("plugins");
|
|
714
742
|
return {
|
|
715
|
-
hasImport
|
|
716
|
-
return parse().statements.some((s) => ts.isImportDeclaration(s) && ts.isStringLiteral(s.moduleSpecifier) && s.moduleSpecifier.text === moduleSpecifier);
|
|
717
|
-
},
|
|
743
|
+
hasImport,
|
|
718
744
|
addImport(moduleSpecifier, namedImports) {
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
text = insertPos > 0 ? text.slice(0, insertPos) + decl + text.slice(insertPos) : decl + "\n" + text;
|
|
725
|
-
},
|
|
726
|
-
outputTargetsContains(substring) {
|
|
727
|
-
const arr = findArray(parse(), "outputTargets");
|
|
728
|
-
return arr ? text.slice(arr.getStart(), arr.getEnd()).includes(substring) : false;
|
|
729
|
-
},
|
|
730
|
-
addOutputTarget(expression) {
|
|
731
|
-
const sf = parse();
|
|
732
|
-
const arr = findArray(sf, "outputTargets");
|
|
733
|
-
if (arr) appendToArray(arr, expression);
|
|
734
|
-
else addArrayProp(sf, "outputTargets", expression);
|
|
735
|
-
},
|
|
736
|
-
replaceOutputTarget(substring, expression) {
|
|
737
|
-
const arr = findArray(parse(), "outputTargets");
|
|
738
|
-
return arr ? replaceInArray(arr, substring, expression) : false;
|
|
739
|
-
},
|
|
740
|
-
removeOutputTarget(substring) {
|
|
741
|
-
const arr = findArray(parse(), "outputTargets");
|
|
742
|
-
return arr ? removeFromArray(arr, substring) : false;
|
|
745
|
+
if (hasImport(moduleSpecifier)) return;
|
|
746
|
+
const lastImport = parse().statements.filter(ts.isImportDeclaration).pop();
|
|
747
|
+
const decl = `import { ${namedImports.join(", ")} } from '${moduleSpecifier}';`;
|
|
748
|
+
if (lastImport) splice(lastImport.getEnd(), lastImport.getEnd(), `\n${decl}`);
|
|
749
|
+
else text = `\n${decl}\n${text}`;
|
|
743
750
|
},
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
return arr ? removeFromArray(arr, substring) : false;
|
|
751
|
+
outputTargetsContains: outputTargets.contains,
|
|
752
|
+
addOutputTarget: outputTargets.add,
|
|
753
|
+
replaceOutputTarget: outputTargets.replace,
|
|
754
|
+
removeOutputTarget: outputTargets.remove,
|
|
755
|
+
pluginsContains: plugins.contains,
|
|
756
|
+
addPlugin: plugins.add,
|
|
757
|
+
replacePlugin: plugins.replace,
|
|
758
|
+
removePlugin: plugins.remove,
|
|
759
|
+
setProperty(name, expression) {
|
|
760
|
+
const configObj = requireConfigObject();
|
|
761
|
+
const existing = findProp(configObj, name);
|
|
762
|
+
if (existing) {
|
|
763
|
+
splice(existing.initializer.getStart(), existing.initializer.getEnd(), expression);
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
766
|
+
insertItem(configObj, `${name}: ${expression}`, findProp(configObj, "namespace"));
|
|
761
767
|
},
|
|
762
768
|
async save() {
|
|
763
769
|
await writeFile(configPath, text, "utf8");
|
|
@@ -769,7 +775,7 @@ async function openStencilConfig(configPath) {
|
|
|
769
775
|
function toStringRecord(val) {
|
|
770
776
|
return val !== null && typeof val === "object" ? val : {};
|
|
771
777
|
}
|
|
772
|
-
async function readJson
|
|
778
|
+
async function readJson(filePath) {
|
|
773
779
|
try {
|
|
774
780
|
return JSON.parse(await readFile(filePath, "utf8"));
|
|
775
781
|
} catch {
|
|
@@ -809,7 +815,7 @@ async function loadOne(rootDir, packageName, loader) {
|
|
|
809
815
|
* @returns Array of successfully loaded plugins, in dependency declaration order.
|
|
810
816
|
*/
|
|
811
817
|
async function discoverPlugins(rootDir, loader = (url) => import(url)) {
|
|
812
|
-
const pkg = await readJson
|
|
818
|
+
const pkg = await readJson(join(rootDir, "package.json"));
|
|
813
819
|
if (!pkg) return [];
|
|
814
820
|
const depNames = [.../* @__PURE__ */ new Set([...Object.keys(toStringRecord(pkg.dependencies)), ...Object.keys(toStringRecord(pkg.devDependencies))])];
|
|
815
821
|
const plugins = (await Promise.allSettled(depNames.map((name) => loadOne(rootDir, name, loader)))).filter((r) => r.status === "fulfilled" && r.value !== null).map((r) => r.value);
|
|
@@ -830,7 +836,7 @@ async function discoverPlugins(rootDir, loader = (url) => import(url)) {
|
|
|
830
836
|
async function findDevPackageName(wizardPath) {
|
|
831
837
|
const dir = dirname(wizardPath);
|
|
832
838
|
for (const candidate of [dir, resolve(dir, "..")]) {
|
|
833
|
-
const pkg = await readJson
|
|
839
|
+
const pkg = await readJson(join(candidate, "package.json"));
|
|
834
840
|
if (typeof pkg?.name === "string") return pkg.name;
|
|
835
841
|
}
|
|
836
842
|
return basename(dir);
|
|
@@ -973,6 +979,7 @@ async function promptOutputs() {
|
|
|
973
979
|
hint: "app mode with dev server and optional PWA support"
|
|
974
980
|
}
|
|
975
981
|
],
|
|
982
|
+
initialValues: ["loader"],
|
|
976
983
|
required: false
|
|
977
984
|
});
|
|
978
985
|
cancelIfAborted(picks);
|
|
@@ -987,6 +994,11 @@ async function promptFeatures() {
|
|
|
987
994
|
label: "Signals",
|
|
988
995
|
hint: "signal-backed @Prop/@State for cross-framework reactive interop"
|
|
989
996
|
},
|
|
997
|
+
{
|
|
998
|
+
value: "exportMaps",
|
|
999
|
+
label: "Export maps",
|
|
1000
|
+
hint: "keep package.json \"exports\" in sync with your outputs and components on each build"
|
|
1001
|
+
},
|
|
990
1002
|
{
|
|
991
1003
|
value: "globalStyle",
|
|
992
1004
|
label: "Global style",
|
|
@@ -1004,6 +1016,7 @@ async function promptFeatures() {
|
|
|
1004
1016
|
const set = new Set(picks);
|
|
1005
1017
|
return {
|
|
1006
1018
|
signals: set.has("signals"),
|
|
1019
|
+
exportMaps: set.has("exportMaps"),
|
|
1007
1020
|
globalStyle: set.has("globalStyle"),
|
|
1008
1021
|
globalScript: set.has("globalScript")
|
|
1009
1022
|
};
|
|
@@ -1133,6 +1146,35 @@ async function promptAddCapabilities(installable, configurable) {
|
|
|
1133
1146
|
}
|
|
1134
1147
|
//#endregion
|
|
1135
1148
|
//#region src/wizard/project.ts
|
|
1149
|
+
const PACKAGE_MANAGERS = [
|
|
1150
|
+
"npm",
|
|
1151
|
+
"pnpm",
|
|
1152
|
+
"yarn",
|
|
1153
|
+
"bun"
|
|
1154
|
+
];
|
|
1155
|
+
/**
|
|
1156
|
+
* Resolve the package manager for `cwd`: a `packageManager` field / lockfile in the project
|
|
1157
|
+
* or its workspace wins, then whichever package manager launched this process, then npm.
|
|
1158
|
+
* @param cwd The directory to detect from. Parent directories are searched up to, but not
|
|
1159
|
+
* including, the home directory - a lockfile there doesn't describe this project.
|
|
1160
|
+
* @returns The package manager name.
|
|
1161
|
+
*/
|
|
1162
|
+
async function detectPackageManager$1(cwd) {
|
|
1163
|
+
const home = homedir();
|
|
1164
|
+
let dir = cwd;
|
|
1165
|
+
while (true) {
|
|
1166
|
+
const fromProject = await detectPackageManager(dir, {
|
|
1167
|
+
ignoreArgv: true,
|
|
1168
|
+
includeParentDirs: false
|
|
1169
|
+
});
|
|
1170
|
+
if (fromProject) return fromProject.name;
|
|
1171
|
+
const parent = dirname(dir);
|
|
1172
|
+
if (parent === dir || parent === home) break;
|
|
1173
|
+
dir = parent;
|
|
1174
|
+
}
|
|
1175
|
+
const invoker = process.env.npm_config_user_agent?.split("/")[0];
|
|
1176
|
+
return PACKAGE_MANAGERS.find((name) => name === invoker) ?? "npm";
|
|
1177
|
+
}
|
|
1136
1178
|
/**
|
|
1137
1179
|
* Extracts the stable, plugin-relevant fields from a fully-resolved compiler config.
|
|
1138
1180
|
* @param validated The fully-resolved compiler config.
|
|
@@ -1149,7 +1191,8 @@ function toProjectConfig(validated) {
|
|
|
1149
1191
|
globalScript: validated.globalScript,
|
|
1150
1192
|
globalStyle: validated.globalStyle,
|
|
1151
1193
|
compat: validated.compat,
|
|
1152
|
-
signalBacking: validated.signalBacking
|
|
1194
|
+
signalBacking: validated.signalBacking,
|
|
1195
|
+
generateExportMaps: validated.generateExportMaps
|
|
1153
1196
|
};
|
|
1154
1197
|
}
|
|
1155
1198
|
/**
|
|
@@ -1208,9 +1251,19 @@ async function isExistingStencilProject(dir) {
|
|
|
1208
1251
|
return false;
|
|
1209
1252
|
}
|
|
1210
1253
|
}
|
|
1254
|
+
/**
|
|
1255
|
+
* npm silently omits devDependencies when this CLI is itself running as a nested child
|
|
1256
|
+
* process (e.g. via `npx create-stencil` / `npm init stencil`). Root cause: npm/exec only
|
|
1257
|
+
* needs @stencil/cli's own regular dependencies to resolve+run it, so that install computes
|
|
1258
|
+
* `omit: ['dev']` - and per npm's own config flattening
|
|
1259
|
+
* (@npmcli/config/lib/definitions/definitions.js). Causing NODE_ENV === 'production'.
|
|
1260
|
+
*/
|
|
1261
|
+
function clearInheritedProductionEnv() {
|
|
1262
|
+
if (process.env.NODE_ENV === "production") delete process.env.NODE_ENV;
|
|
1263
|
+
}
|
|
1211
1264
|
//#endregion
|
|
1212
1265
|
//#region src/wizard/splash.ts
|
|
1213
|
-
const CLI_VERSION = "5.0.0-
|
|
1266
|
+
const CLI_VERSION = "5.0.0-rc.0";
|
|
1214
1267
|
const isTTY = process.stdout.isTTY;
|
|
1215
1268
|
const noColor = !isTTY || "NO_COLOR" in process.env;
|
|
1216
1269
|
const RESET = noColor ? "" : "\x1B[0m";
|
|
@@ -1299,6 +1352,7 @@ async function taskAdd(packages, strictConfig) {
|
|
|
1299
1352
|
p.log.warn("Running in CI - non-interactive mode is not yet supported for `stencil add`.");
|
|
1300
1353
|
process.exit(1);
|
|
1301
1354
|
}
|
|
1355
|
+
clearInheritedProductionEnv();
|
|
1302
1356
|
let packagesToInstall = packages;
|
|
1303
1357
|
let pluginsToReconfigure = [];
|
|
1304
1358
|
if (packages.length === 0) ({packagesToInstall, pluginsToReconfigure} = await selectInteractive(cwd));
|
|
@@ -1344,10 +1398,10 @@ async function taskAdd(packages, strictConfig) {
|
|
|
1344
1398
|
* @param config the Stencil configuration associated with the currently compiled project
|
|
1345
1399
|
* @param currentVersion the Stencil compiler's version string
|
|
1346
1400
|
* @param flags the CLI flags (owned by CLI, not part of core config)
|
|
1347
|
-
* @returns a reference to `checkVersion`, or `null` if
|
|
1401
|
+
* @returns a reference to `checkVersion`, or `null` if the check is skipped
|
|
1348
1402
|
*/
|
|
1349
1403
|
const startCheckVersion = async (config, currentVersion, flags) => {
|
|
1350
|
-
if (config.devMode && !flags.ci && !currentVersion.includes("-dev.")
|
|
1404
|
+
if (config.devMode && !flags.ci && !currentVersion.includes("-dev.")) return config.sys.checkVersion(config.logger, currentVersion);
|
|
1351
1405
|
return null;
|
|
1352
1406
|
};
|
|
1353
1407
|
/**
|
|
@@ -1966,11 +2020,23 @@ const formAssociatedRule = {
|
|
|
1966
2020
|
* Migration mapping:
|
|
1967
2021
|
* - `addGlobalStyleToComponents: true` → `inject: 'all'`
|
|
1968
2022
|
* - `addGlobalStyleToComponents: 'client'` → `inject: 'client'`
|
|
1969
|
-
* - `addGlobalStyleToComponents: false` →
|
|
2023
|
+
* - `addGlobalStyleToComponents: false` → `inject: 'none'` (a stylesheet from `globalStyle` defaults
|
|
2024
|
+
* to `'client'`, so omitting it would start injecting)
|
|
2025
|
+
*
|
|
2026
|
+
* The top-level `globalStyle` option moves into the new output target as well, so the config
|
|
2027
|
+
* isn't left describing one stylesheet in two places:
|
|
1970
2028
|
*
|
|
1971
|
-
*
|
|
1972
|
-
*
|
|
1973
|
-
*
|
|
2029
|
+
* ```ts
|
|
2030
|
+
* { type: 'global-style', input: 'src/global/app.css', fileName: 'my-lib.css', inject: 'none', copyToLoaderBrowser: true }
|
|
2031
|
+
* ```
|
|
2032
|
+
*
|
|
2033
|
+
* `fileName` is written (from `namespace`) because a target with an explicit `input` otherwise
|
|
2034
|
+
* names its output after the input file, where `globalStyle` used `{namespace}.css`.
|
|
2035
|
+
* When `globalStyle` isn't a string literal in the config (e.g. the stylesheet is auto-detected
|
|
2036
|
+
* from `src/global.*`), only `{ type: 'global-style', inject }` is written.
|
|
2037
|
+
*
|
|
2038
|
+
* Note: This migration only acts on explicitly set `addGlobalStyleToComponents`. A config
|
|
2039
|
+
* without it keeps `globalStyle` as it is, which still injects on the client as v4 did.
|
|
1974
2040
|
*/
|
|
1975
2041
|
const globalStyleInjectRule = {
|
|
1976
2042
|
id: "global-style-inject",
|
|
@@ -2002,79 +2068,97 @@ const globalStyleInjectRule = {
|
|
|
2002
2068
|
return matches;
|
|
2003
2069
|
},
|
|
2004
2070
|
transform(sourceFile, matches) {
|
|
2005
|
-
|
|
2006
|
-
|
|
2071
|
+
const original = sourceFile.getFullText();
|
|
2072
|
+
if (matches.length === 0) return original;
|
|
2007
2073
|
const matchNode = matches[0].node;
|
|
2008
|
-
if (!ts.isPropertyAssignment(matchNode)) return
|
|
2074
|
+
if (!ts.isPropertyAssignment(matchNode)) return original;
|
|
2009
2075
|
let injectValue = null;
|
|
2010
2076
|
if (matchNode.initializer.kind === ts.SyntaxKind.TrueKeyword) injectValue = "all";
|
|
2011
2077
|
else if (ts.isStringLiteral(matchNode.initializer) && matchNode.initializer.text === "client") injectValue = "client";
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
}
|
|
2025
|
-
const afterProp = text.slice(end).match(/^\s*,/);
|
|
2026
|
-
if (afterProp) end = end + afterProp[0].length;
|
|
2027
|
-
else {
|
|
2028
|
-
const beforeProp = text.slice(0, start).match(/,\s*$/);
|
|
2029
|
-
if (beforeProp) {
|
|
2030
|
-
text = text.slice(0, start - beforeProp[0].length) + text.slice(end);
|
|
2031
|
-
end = -1;
|
|
2078
|
+
else if (matchNode.initializer.kind === ts.SyntaxKind.FalseKeyword) injectValue = "none";
|
|
2079
|
+
const edits = [removalOf(original, matchNode)];
|
|
2080
|
+
const outputTargets = findTopLevelProperty(sourceFile, "outputTargets");
|
|
2081
|
+
const hasGlobalStyleTarget = original.includes("type: 'global-style'");
|
|
2082
|
+
if (injectValue && !hasGlobalStyleTarget && outputTargets && ts.isArrayLiteralExpression(outputTargets.initializer)) {
|
|
2083
|
+
const globalStyle = findTopLevelProperty(sourceFile, "globalStyle");
|
|
2084
|
+
const namespace = findTopLevelProperty(sourceFile, "namespace");
|
|
2085
|
+
const props = [`type: 'global-style'`];
|
|
2086
|
+
if (globalStyle && ts.isStringLiteralLike(globalStyle.initializer)) {
|
|
2087
|
+
props.push(`input: ${globalStyle.initializer.getText()}`);
|
|
2088
|
+
if (namespace && ts.isStringLiteralLike(namespace.initializer)) props.push(`fileName: '${namespace.initializer.text.toLowerCase().trim()}.css'`);
|
|
2089
|
+
edits.push(removalOf(original, globalStyle));
|
|
2032
2090
|
}
|
|
2091
|
+
props.push(`inject: '${injectValue}'`);
|
|
2092
|
+
if (props.length > 2) props.push(`copyToLoaderBrowser: true`);
|
|
2093
|
+
edits.push(insertionOfOutputTarget(original, outputTargets.initializer, props));
|
|
2033
2094
|
}
|
|
2034
|
-
|
|
2035
|
-
text =
|
|
2036
|
-
return text;
|
|
2095
|
+
let text = original;
|
|
2096
|
+
for (const edit of edits.sort((a, b) => b.start - a.start)) text = text.slice(0, edit.start) + edit.text + text.slice(edit.end);
|
|
2097
|
+
return cleanupEmptyExtras$1(text);
|
|
2037
2098
|
}
|
|
2038
2099
|
};
|
|
2039
2100
|
/**
|
|
2040
|
-
* Find
|
|
2101
|
+
* Find a property of the exported config object, e.g. `globalStyle` or `outputTargets`.
|
|
2041
2102
|
* @param sourceFile The source file to search
|
|
2042
|
-
* @
|
|
2103
|
+
* @param name The property name
|
|
2104
|
+
* @returns The property assignment, or null if the config has no such top-level property
|
|
2043
2105
|
*/
|
|
2044
|
-
function
|
|
2045
|
-
let
|
|
2046
|
-
const visit = (node) => {
|
|
2047
|
-
if (
|
|
2048
|
-
ts.
|
|
2106
|
+
function findTopLevelProperty(sourceFile, name) {
|
|
2107
|
+
let found = null;
|
|
2108
|
+
const visit = (node, depth) => {
|
|
2109
|
+
if (found) return;
|
|
2110
|
+
if (ts.isObjectLiteralExpression(node)) {
|
|
2111
|
+
if (depth > 0) return;
|
|
2112
|
+
for (const prop of node.properties) if (ts.isPropertyAssignment(prop) && ts.isIdentifier(prop.name) && prop.name.text === name) {
|
|
2113
|
+
found = prop;
|
|
2114
|
+
return;
|
|
2115
|
+
}
|
|
2116
|
+
return;
|
|
2117
|
+
}
|
|
2118
|
+
ts.forEachChild(node, (child) => visit(child, depth));
|
|
2049
2119
|
};
|
|
2050
|
-
visit(sourceFile);
|
|
2051
|
-
return
|
|
2120
|
+
visit(sourceFile, 0);
|
|
2121
|
+
return found;
|
|
2052
2122
|
}
|
|
2053
2123
|
/**
|
|
2054
|
-
*
|
|
2055
|
-
* @param text The source text
|
|
2056
|
-
* @
|
|
2124
|
+
* Build the edit that removes a property, together with its trailing comma and its own line.
|
|
2125
|
+
* @param text The original source text
|
|
2126
|
+
* @param node The property to remove
|
|
2127
|
+
* @returns The edit
|
|
2057
2128
|
*/
|
|
2058
|
-
function
|
|
2059
|
-
|
|
2129
|
+
function removalOf(text, node) {
|
|
2130
|
+
let start = node.getStart();
|
|
2131
|
+
let end = node.getEnd();
|
|
2132
|
+
const trailingComma = text.slice(end).match(/^\s*,/);
|
|
2133
|
+
if (trailingComma) end += trailingComma[0].length;
|
|
2134
|
+
else {
|
|
2135
|
+
const leadingComma = text.slice(0, start).match(/,\s*$/);
|
|
2136
|
+
if (leadingComma) return {
|
|
2137
|
+
start: start - leadingComma[0].length,
|
|
2138
|
+
end,
|
|
2139
|
+
text: ""
|
|
2140
|
+
};
|
|
2141
|
+
}
|
|
2142
|
+
const lineStart = text.lastIndexOf("\n", start - 1) + 1;
|
|
2143
|
+
const restOfLine = text.slice(end).match(/^[ \t]*\n/);
|
|
2144
|
+
if (/^[ \t]*$/.test(text.slice(lineStart, start)) && restOfLine) {
|
|
2145
|
+
start = lineStart;
|
|
2146
|
+
end += restOfLine[0].length;
|
|
2147
|
+
}
|
|
2148
|
+
return {
|
|
2149
|
+
start,
|
|
2150
|
+
end,
|
|
2151
|
+
text: ""
|
|
2152
|
+
};
|
|
2060
2153
|
}
|
|
2061
2154
|
/**
|
|
2062
|
-
*
|
|
2063
|
-
* @param text The source text
|
|
2064
|
-
* @param
|
|
2065
|
-
* @param
|
|
2066
|
-
* @returns The
|
|
2155
|
+
* Build the edit that appends a `global-style` output target to the `outputTargets` array.
|
|
2156
|
+
* @param text The original source text
|
|
2157
|
+
* @param array The `outputTargets` array
|
|
2158
|
+
* @param props The new output target's properties, as source text
|
|
2159
|
+
* @returns The edit
|
|
2067
2160
|
*/
|
|
2068
|
-
function
|
|
2069
|
-
if (text.includes("type: 'global-style'")) return text;
|
|
2070
|
-
let outputTargetsArray = null;
|
|
2071
|
-
const findOutputTargets = (node) => {
|
|
2072
|
-
if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name) && node.name.text === "outputTargets" && ts.isArrayLiteralExpression(node.initializer)) outputTargetsArray = node.initializer;
|
|
2073
|
-
ts.forEachChild(node, findOutputTargets);
|
|
2074
|
-
};
|
|
2075
|
-
findOutputTargets(sourceFile);
|
|
2076
|
-
if (!outputTargetsArray) return text;
|
|
2077
|
-
const array = outputTargetsArray;
|
|
2161
|
+
function insertionOfOutputTarget(text, array, props) {
|
|
2078
2162
|
let indent = " ";
|
|
2079
2163
|
if (array.elements.length > 0) {
|
|
2080
2164
|
const elemStart = array.elements[0].getStart();
|
|
@@ -2082,19 +2166,33 @@ function addGlobalStyleOutputTarget(text, sourceFile, injectValue) {
|
|
|
2082
2166
|
const leadingWhitespace = text.slice(lineStart, elemStart);
|
|
2083
2167
|
if (/^\s+$/.test(leadingWhitespace)) indent = leadingWhitespace;
|
|
2084
2168
|
}
|
|
2169
|
+
const newTarget = `{\n${props.map((prop) => `${indent} ${prop},\n`).join("")}${indent}}`;
|
|
2085
2170
|
const lastElement = array.elements[array.elements.length - 1];
|
|
2086
2171
|
if (!lastElement) {
|
|
2087
2172
|
const arrayStart = array.getStart() + 1;
|
|
2088
|
-
|
|
2089
|
-
|
|
2173
|
+
return {
|
|
2174
|
+
start: arrayStart,
|
|
2175
|
+
end: arrayStart,
|
|
2176
|
+
text: `\n${indent}${newTarget}\n${indent.slice(2)}`
|
|
2177
|
+
};
|
|
2090
2178
|
}
|
|
2091
2179
|
let insertPos = lastElement.getEnd();
|
|
2092
2180
|
const afterLastElement = text.slice(insertPos).match(/^(\s*,)?/);
|
|
2093
2181
|
const hasTrailingComma = afterLastElement && afterLastElement[1];
|
|
2094
2182
|
if (hasTrailingComma) insertPos += afterLastElement[0].length;
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2183
|
+
return {
|
|
2184
|
+
start: insertPos,
|
|
2185
|
+
end: insertPos,
|
|
2186
|
+
text: (hasTrailingComma ? "" : ",") + "\n" + indent + newTarget
|
|
2187
|
+
};
|
|
2188
|
+
}
|
|
2189
|
+
/**
|
|
2190
|
+
* Clean up empty extras object after removing addGlobalStyleToComponents.
|
|
2191
|
+
* @param text The source text to clean up
|
|
2192
|
+
* @returns The cleaned up text with empty extras removed
|
|
2193
|
+
*/
|
|
2194
|
+
function cleanupEmptyExtras$1(text) {
|
|
2195
|
+
return text.replace(/,?\s*extras\s*:\s*\{\s*\},?/g, "");
|
|
2098
2196
|
}
|
|
2099
2197
|
//#endregion
|
|
2100
2198
|
//#region src/migrations/rules/hash-file-names.ts
|
|
@@ -3143,7 +3241,6 @@ const taskWatch = async (coreCompiler, config, flags) => {
|
|
|
3143
3241
|
const versionChecker = startCheckVersion(config, coreCompiler.version, flags);
|
|
3144
3242
|
const compiler = await coreCompiler.createCompiler(config);
|
|
3145
3243
|
const watcher = await compiler.createWatcher();
|
|
3146
|
-
if (!config.sys.onProcessInterrupt) throw new Error(`Environment doesn't provide required function: onProcessInterrupt`);
|
|
3147
3244
|
if (flags.serve) {
|
|
3148
3245
|
const { start } = await import("@stencil/dev-server");
|
|
3149
3246
|
devServer = await start(config.devServer, config.logger, watcher);
|
|
@@ -3173,475 +3270,9 @@ const taskWatch = async (coreCompiler, config, flags) => {
|
|
|
3173
3270
|
if (exitCode > 0) return config.sys.exit(exitCode);
|
|
3174
3271
|
};
|
|
3175
3272
|
//#endregion
|
|
3176
|
-
//#region src/telemetry/helpers.ts
|
|
3177
|
-
const tryFn = async (fn, ...args) => {
|
|
3178
|
-
try {
|
|
3179
|
-
return await fn(...args);
|
|
3180
|
-
} catch {}
|
|
3181
|
-
return null;
|
|
3182
|
-
};
|
|
3183
|
-
const isInteractive = (sys, flags, object) => {
|
|
3184
|
-
const terminalInfo = object || Object.freeze({
|
|
3185
|
-
tty: sys.isTTY(),
|
|
3186
|
-
ci: [
|
|
3187
|
-
"CI",
|
|
3188
|
-
"BUILD_ID",
|
|
3189
|
-
"BUILD_NUMBER",
|
|
3190
|
-
"BITBUCKET_COMMIT",
|
|
3191
|
-
"CODEBUILD_BUILD_ARN"
|
|
3192
|
-
].filter((v) => !!sys.getEnvironmentVar?.(v)).length > 0 || !!flags.ci
|
|
3193
|
-
});
|
|
3194
|
-
return terminalInfo.tty && !terminalInfo.ci;
|
|
3195
|
-
};
|
|
3196
|
-
const UUID_REGEX = /* @__PURE__ */ new RegExp(/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i);
|
|
3197
|
-
function uuidv4() {
|
|
3198
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
3199
|
-
const r = Math.random() * 16 | 0;
|
|
3200
|
-
return (c == "x" ? r : r & 3 | 8).toString(16);
|
|
3201
|
-
});
|
|
3202
|
-
}
|
|
3203
|
-
/**
|
|
3204
|
-
* Reads and parses a JSON file from the given `path`
|
|
3205
|
-
* @param sys The system where the command is invoked
|
|
3206
|
-
* @param path the path on the file system to read and parse
|
|
3207
|
-
* @returns the parsed JSON
|
|
3208
|
-
*/
|
|
3209
|
-
async function readJson(sys, path) {
|
|
3210
|
-
const file = await sys.readFile(path);
|
|
3211
|
-
return file ? JSON.parse(file) : null;
|
|
3212
|
-
}
|
|
3213
|
-
/**
|
|
3214
|
-
* Does the command have the debug flag?
|
|
3215
|
-
* @param flags The configuration flags passed into the Stencil command
|
|
3216
|
-
* @returns true if --debug has been passed, otherwise false
|
|
3217
|
-
*/
|
|
3218
|
-
function hasDebug(flags) {
|
|
3219
|
-
return !!flags.debug;
|
|
3220
|
-
}
|
|
3221
|
-
/**
|
|
3222
|
-
* Does the command have the verbose and debug flags?
|
|
3223
|
-
* @param flags The configuration flags passed into the Stencil command
|
|
3224
|
-
* @returns true if both --debug and --verbose have been passed, otherwise false
|
|
3225
|
-
*/
|
|
3226
|
-
function hasVerbose(flags) {
|
|
3227
|
-
return !!flags.verbose && hasDebug(flags);
|
|
3228
|
-
}
|
|
3229
|
-
//#endregion
|
|
3230
|
-
//#region src/ionic-config.ts
|
|
3231
|
-
const isTest = () => process.env.JEST_WORKER_ID !== void 0;
|
|
3232
|
-
const defaultConfig = (sys) => sys.resolvePath(`${sys.homeDir()}/.ionic/${isTest() ? "tmp-config.json" : "config.json"}`);
|
|
3233
|
-
const defaultConfigDirectory = (sys) => sys.resolvePath(`${sys.homeDir()}/.ionic`);
|
|
3234
|
-
/**
|
|
3235
|
-
* Reads an Ionic configuration file from disk, parses it, and performs any necessary corrections to it if certain
|
|
3236
|
-
* values are deemed to be malformed
|
|
3237
|
-
* @param sys The system where the command is invoked
|
|
3238
|
-
* @returns the config read from disk that has been potentially been updated
|
|
3239
|
-
*/
|
|
3240
|
-
async function readConfig(sys) {
|
|
3241
|
-
let config = await readJson(sys, defaultConfig(sys));
|
|
3242
|
-
if (!config) {
|
|
3243
|
-
config = {
|
|
3244
|
-
"tokens.telemetry": uuidv4(),
|
|
3245
|
-
"telemetry.stencil": true
|
|
3246
|
-
};
|
|
3247
|
-
await writeConfig(sys, config);
|
|
3248
|
-
} else if (!config["tokens.telemetry"] || !UUID_REGEX.test(config["tokens.telemetry"])) {
|
|
3249
|
-
const newUuid = uuidv4();
|
|
3250
|
-
await writeConfig(sys, {
|
|
3251
|
-
...config,
|
|
3252
|
-
"tokens.telemetry": newUuid
|
|
3253
|
-
});
|
|
3254
|
-
config["tokens.telemetry"] = newUuid;
|
|
3255
|
-
}
|
|
3256
|
-
return config;
|
|
3257
|
-
}
|
|
3258
|
-
/**
|
|
3259
|
-
* Writes an Ionic configuration file to disk.
|
|
3260
|
-
* @param sys The system where the command is invoked
|
|
3261
|
-
* @param config The config passed into the Stencil command
|
|
3262
|
-
* @returns boolean If the command was successful
|
|
3263
|
-
*/
|
|
3264
|
-
async function writeConfig(sys, config) {
|
|
3265
|
-
let result = false;
|
|
3266
|
-
try {
|
|
3267
|
-
await sys.createDir(defaultConfigDirectory(sys), { recursive: true });
|
|
3268
|
-
await sys.writeFile(defaultConfig(sys), JSON.stringify(config, null, 2));
|
|
3269
|
-
result = true;
|
|
3270
|
-
} catch (error) {
|
|
3271
|
-
console.error(`Stencil Telemetry: couldn't write configuration file to ${defaultConfig(sys)} - ${error}.`);
|
|
3272
|
-
}
|
|
3273
|
-
return result;
|
|
3274
|
-
}
|
|
3275
|
-
/**
|
|
3276
|
-
* Update a subset of the Ionic config.
|
|
3277
|
-
* @param sys The system where the command is invoked
|
|
3278
|
-
* @param newOptions The new options to save
|
|
3279
|
-
* @returns boolean If the command was successful
|
|
3280
|
-
*/
|
|
3281
|
-
async function updateConfig(sys, newOptions) {
|
|
3282
|
-
const config = await readConfig(sys);
|
|
3283
|
-
return await writeConfig(sys, Object.assign(config, newOptions));
|
|
3284
|
-
}
|
|
3285
|
-
//#endregion
|
|
3286
|
-
//#region src/telemetry/shouldTrack.ts
|
|
3287
|
-
/**
|
|
3288
|
-
* Used to determine if tracking should occur.
|
|
3289
|
-
* @param sys The system where the command is invoked
|
|
3290
|
-
* @param flags The CLI flags (owned by CLI, not part of core config)
|
|
3291
|
-
* @param ci whether or not the process is running in a Continuous Integration (CI) environment
|
|
3292
|
-
* @returns true if telemetry should be sent, false otherwise
|
|
3293
|
-
*/
|
|
3294
|
-
async function shouldTrack(sys, flags, ci) {
|
|
3295
|
-
return !ci && isInteractive(sys, flags) && await checkTelemetry(sys);
|
|
3296
|
-
}
|
|
3297
|
-
//#endregion
|
|
3298
|
-
//#region src/telemetry/telemetry.ts
|
|
3299
|
-
/**
|
|
3300
|
-
* Used to within taskBuild to provide the component_count property.
|
|
3301
|
-
*
|
|
3302
|
-
* @param sys The system where the command is invoked
|
|
3303
|
-
* @param config The config passed into the Stencil command
|
|
3304
|
-
* @param coreCompiler The compiler used to do builds
|
|
3305
|
-
* @param result The results of a compiler build.
|
|
3306
|
-
* @param flags The CLI flags (owned by CLI, not part of core config)
|
|
3307
|
-
*/
|
|
3308
|
-
async function telemetryBuildFinishedAction(sys, config, coreCompiler, result, flags) {
|
|
3309
|
-
if (!await shouldTrack(sys, flags, !!flags.ci)) return;
|
|
3310
|
-
const component_count = result.componentGraph ? Object.keys(result.componentGraph).length : void 0;
|
|
3311
|
-
const data = await prepareData(coreCompiler, config, sys, flags, result.duration, component_count);
|
|
3312
|
-
await sendMetric(sys, flags, "stencil_cli_command", data);
|
|
3313
|
-
config.logger.debug(`${config.logger.blue("Telemetry")}: ${config.logger.gray(JSON.stringify(data))}`);
|
|
3314
|
-
}
|
|
3315
|
-
/**
|
|
3316
|
-
* A function to wrap a compiler task function around. Will send telemetry if, and only if, the machine allows.
|
|
3317
|
-
*
|
|
3318
|
-
* @param sys The system where the command is invoked
|
|
3319
|
-
* @param config The config passed into the Stencil command
|
|
3320
|
-
* @param coreCompiler The compiler used to do builds
|
|
3321
|
-
* @param flags The CLI flags (owned by CLI, not part of core config)
|
|
3322
|
-
* @param action A Promise-based function to call in order to get the duration of any given command.
|
|
3323
|
-
* @returns void
|
|
3324
|
-
*/
|
|
3325
|
-
async function telemetryAction(sys, config, coreCompiler, flags, action) {
|
|
3326
|
-
const tracking = await shouldTrack(sys, flags, !!flags.ci);
|
|
3327
|
-
let duration = void 0;
|
|
3328
|
-
let error;
|
|
3329
|
-
if (action) {
|
|
3330
|
-
const start = /* @__PURE__ */ new Date();
|
|
3331
|
-
try {
|
|
3332
|
-
await action();
|
|
3333
|
-
} catch (e) {
|
|
3334
|
-
error = e;
|
|
3335
|
-
}
|
|
3336
|
-
duration = (/* @__PURE__ */ new Date()).getTime() - start.getTime();
|
|
3337
|
-
}
|
|
3338
|
-
if (!tracking || flags.task == "build" && !flags.args.includes("--watch")) return;
|
|
3339
|
-
const data = await prepareData(coreCompiler, config, sys, flags, duration);
|
|
3340
|
-
await sendMetric(sys, flags, "stencil_cli_command", data);
|
|
3341
|
-
config.logger.debug(`${config.logger.blue("Telemetry")}: ${config.logger.gray(JSON.stringify(data))}`);
|
|
3342
|
-
if (error) throw error;
|
|
3343
|
-
}
|
|
3344
|
-
/**
|
|
3345
|
-
* Helper function to determine if a Stencil configuration builds an application.
|
|
3346
|
-
*
|
|
3347
|
-
* This function is a rough approximation whether an application is generated as a part of a Stencil build, based on
|
|
3348
|
-
* contents of the project's `stencil.config.ts` file.
|
|
3349
|
-
*
|
|
3350
|
-
* @param config the configuration used by the Stencil project
|
|
3351
|
-
* @returns true if we believe the project generates an application, false otherwise
|
|
3352
|
-
*/
|
|
3353
|
-
function hasAppTarget(config) {
|
|
3354
|
-
return config.outputTargets.some((target) => isOutputTargetWww(target) && (!!target.serviceWorker || !!target.baseUrl && target.baseUrl !== "/"));
|
|
3355
|
-
}
|
|
3356
|
-
function isUsingYarn(sys) {
|
|
3357
|
-
return sys.getEnvironmentVar?.("npm_execpath")?.includes("yarn") || false;
|
|
3358
|
-
}
|
|
3359
|
-
/**
|
|
3360
|
-
* Build a list of the different types of output targets used in a Stencil configuration.
|
|
3361
|
-
*
|
|
3362
|
-
* Duplicate entries will not be returned from the list
|
|
3363
|
-
*
|
|
3364
|
-
* @param config the configuration used by the Stencil project
|
|
3365
|
-
* @returns a unique list of output target types found in the Stencil configuration
|
|
3366
|
-
*/
|
|
3367
|
-
function getActiveTargets(config) {
|
|
3368
|
-
const result = config.outputTargets.map((t) => t.type);
|
|
3369
|
-
return Array.from(new Set(result));
|
|
3370
|
-
}
|
|
3371
|
-
/**
|
|
3372
|
-
* Prepare data for telemetry
|
|
3373
|
-
*
|
|
3374
|
-
* @param coreCompiler the core compiler
|
|
3375
|
-
* @param config the current Stencil config
|
|
3376
|
-
* @param sys the compiler system instance in use
|
|
3377
|
-
* @param flags the CLI flags (owned by CLI, not part of core config)
|
|
3378
|
-
* @param duration_ms the duration of the action being tracked
|
|
3379
|
-
* @param component_count the number of components being built (optional)
|
|
3380
|
-
* @returns a Promise wrapping data for the telemetry endpoint
|
|
3381
|
-
*/
|
|
3382
|
-
const prepareData = async (coreCompiler, config, sys, flags, duration_ms, component_count = void 0) => {
|
|
3383
|
-
const { typescript, rolldown } = coreCompiler.versions || {
|
|
3384
|
-
typescript: "unknown",
|
|
3385
|
-
rolldown: "unknown"
|
|
3386
|
-
};
|
|
3387
|
-
const { packages, packagesNoVersions } = await getInstalledPackages(sys, flags);
|
|
3388
|
-
const targets = getActiveTargets(config);
|
|
3389
|
-
const yarn = isUsingYarn(sys);
|
|
3390
|
-
const stencil = coreCompiler.version || "unknown";
|
|
3391
|
-
const system = `${sys.name} ${sys.version}`;
|
|
3392
|
-
const os_name = sys.details?.platform;
|
|
3393
|
-
const os_version = sys.details?.release;
|
|
3394
|
-
const cpu_model = sys.details?.cpuModel;
|
|
3395
|
-
const build = coreCompiler.buildId || "unknown";
|
|
3396
|
-
const has_app_pwa_config = hasAppTarget(config);
|
|
3397
|
-
const anonymizedConfig = anonymizeConfigForTelemetry(config);
|
|
3398
|
-
return {
|
|
3399
|
-
arguments: flags.args,
|
|
3400
|
-
build,
|
|
3401
|
-
component_count,
|
|
3402
|
-
config: anonymizedConfig,
|
|
3403
|
-
cpu_model,
|
|
3404
|
-
duration_ms,
|
|
3405
|
-
has_app_pwa_config,
|
|
3406
|
-
os_name,
|
|
3407
|
-
os_version,
|
|
3408
|
-
packages,
|
|
3409
|
-
packages_no_versions: packagesNoVersions,
|
|
3410
|
-
rolldown,
|
|
3411
|
-
stencil,
|
|
3412
|
-
system,
|
|
3413
|
-
system_major: getMajorVersion(system),
|
|
3414
|
-
targets,
|
|
3415
|
-
task: flags.task,
|
|
3416
|
-
typescript,
|
|
3417
|
-
yarn
|
|
3418
|
-
};
|
|
3419
|
-
};
|
|
3420
|
-
const OUTPUT_TARGET_KEYS_TO_KEEP = ["type"];
|
|
3421
|
-
const CONFIG_PROPS_TO_ANONYMIZE = [
|
|
3422
|
-
"rootDir",
|
|
3423
|
-
"fsNamespace",
|
|
3424
|
-
"packageJsonFilePath",
|
|
3425
|
-
"namespace",
|
|
3426
|
-
"srcDir",
|
|
3427
|
-
"srcIndexHtml",
|
|
3428
|
-
"buildLogFilePath",
|
|
3429
|
-
"cacheDir",
|
|
3430
|
-
"configPath",
|
|
3431
|
-
"tsconfig"
|
|
3432
|
-
];
|
|
3433
|
-
const CONFIG_PROPS_TO_DELETE = [
|
|
3434
|
-
"devServer",
|
|
3435
|
-
"env",
|
|
3436
|
-
"logger",
|
|
3437
|
-
"rolldownConfig",
|
|
3438
|
-
"sys",
|
|
3439
|
-
"tsCompilerOptions"
|
|
3440
|
-
];
|
|
3441
|
-
/**
|
|
3442
|
-
* Anonymize the config for telemetry, replacing potentially revealing config props
|
|
3443
|
-
* with a placeholder string if they are present (this lets us still track how frequently
|
|
3444
|
-
* these config options are being used)
|
|
3445
|
-
*
|
|
3446
|
-
* @param config the config to anonymize
|
|
3447
|
-
* @returns an anonymized copy of the same config
|
|
3448
|
-
*/
|
|
3449
|
-
const anonymizeConfigForTelemetry = (config) => {
|
|
3450
|
-
const anonymizedConfig = { ...config };
|
|
3451
|
-
for (const prop of CONFIG_PROPS_TO_ANONYMIZE) if (anonymizedConfig[prop] !== void 0) anonymizedConfig[prop] = "omitted";
|
|
3452
|
-
anonymizedConfig.outputTargets = config.outputTargets.map((target) => {
|
|
3453
|
-
const anonymizedOT = JSON.parse(JSON.stringify(target, (key, value) => {
|
|
3454
|
-
if (!(typeof value === "string")) return value;
|
|
3455
|
-
if (OUTPUT_TARGET_KEYS_TO_KEEP.includes(key)) return value;
|
|
3456
|
-
return "omitted";
|
|
3457
|
-
}));
|
|
3458
|
-
if (isOutputTargetSsr(target) && target.external) anonymizedOT["external"] = target.external.concat();
|
|
3459
|
-
return anonymizedOT;
|
|
3460
|
-
});
|
|
3461
|
-
for (const prop of CONFIG_PROPS_TO_DELETE) delete anonymizedConfig[prop];
|
|
3462
|
-
return anonymizedConfig;
|
|
3463
|
-
};
|
|
3464
|
-
/**
|
|
3465
|
-
* Reads package-lock.json, yarn.lock, and package.json files in order to cross-reference
|
|
3466
|
-
* the dependencies and devDependencies properties. Pulls up the current installed version
|
|
3467
|
-
* of each package under the @stencil, @ionic, and @capacitor scopes.
|
|
3468
|
-
*
|
|
3469
|
-
* @param sys the system instance where telemetry is invoked
|
|
3470
|
-
* @param flags the CLI flags (owned by CLI, not part of core config)
|
|
3471
|
-
* @returns an object listing all dev and production dependencies under the aforementioned scopes
|
|
3472
|
-
*/
|
|
3473
|
-
async function getInstalledPackages(sys, flags) {
|
|
3474
|
-
let packages = [];
|
|
3475
|
-
let packagesNoVersions = [];
|
|
3476
|
-
const yarn = isUsingYarn(sys);
|
|
3477
|
-
try {
|
|
3478
|
-
const appRootDir = sys.getCurrentDirectory();
|
|
3479
|
-
const packageJson = await tryFn(readJson, sys, sys.resolvePath(appRootDir + "/package.json"));
|
|
3480
|
-
if (!packageJson) return {
|
|
3481
|
-
packages,
|
|
3482
|
-
packagesNoVersions
|
|
3483
|
-
};
|
|
3484
|
-
const ionicPackages = Object.entries({
|
|
3485
|
-
...packageJson.devDependencies,
|
|
3486
|
-
...packageJson.dependencies
|
|
3487
|
-
}).filter(([k]) => k.startsWith("@stencil/") || k.startsWith("@ionic/") || k.startsWith("@capacitor/"));
|
|
3488
|
-
try {
|
|
3489
|
-
packages = yarn ? await yarnPackages(sys, ionicPackages) : await npmPackages(sys, ionicPackages);
|
|
3490
|
-
} catch {
|
|
3491
|
-
packages = ionicPackages.map(([k, v]) => `${k}@${v.replace("^", "")}`);
|
|
3492
|
-
}
|
|
3493
|
-
packagesNoVersions = ionicPackages.map(([k]) => `${k}`);
|
|
3494
|
-
return {
|
|
3495
|
-
packages,
|
|
3496
|
-
packagesNoVersions
|
|
3497
|
-
};
|
|
3498
|
-
} catch (err) {
|
|
3499
|
-
if (hasDebug(flags)) console.error(err);
|
|
3500
|
-
return {
|
|
3501
|
-
packages,
|
|
3502
|
-
packagesNoVersions
|
|
3503
|
-
};
|
|
3504
|
-
}
|
|
3505
|
-
}
|
|
3506
|
-
/**
|
|
3507
|
-
* Visits the npm lock file to find the exact versions that are installed
|
|
3508
|
-
* @param sys The system where the command is invoked
|
|
3509
|
-
* @param ionicPackages a list of the found packages matching `@stencil`, `@capacitor`, or `@ionic` from the package.json file.
|
|
3510
|
-
* @returns an array of strings of all the packages and their versions.
|
|
3511
|
-
*/
|
|
3512
|
-
async function npmPackages(sys, ionicPackages) {
|
|
3513
|
-
const appRootDir = sys.getCurrentDirectory();
|
|
3514
|
-
const packageLockJson = await tryFn(readJson, sys, sys.resolvePath(appRootDir + "/package-lock.json"));
|
|
3515
|
-
return ionicPackages.map(([k, v]) => {
|
|
3516
|
-
let version = packageLockJson?.dependencies[k]?.version ?? packageLockJson?.devDependencies[k]?.version ?? v;
|
|
3517
|
-
version = version.includes("file:") ? sanitizeDeclaredVersion(v) : version;
|
|
3518
|
-
return `${k}@${version}`;
|
|
3519
|
-
});
|
|
3520
|
-
}
|
|
3521
|
-
/**
|
|
3522
|
-
* Visits the yarn lock file to find the exact versions that are installed
|
|
3523
|
-
* @param sys The system where the command is invoked
|
|
3524
|
-
* @param ionicPackages a list of the found packages matching `@stencil`, `@capacitor`, or `@ionic` from the package.json file.
|
|
3525
|
-
* @returns an array of strings of all the packages and their versions.
|
|
3526
|
-
*/
|
|
3527
|
-
async function yarnPackages(sys, ionicPackages) {
|
|
3528
|
-
const appRootDir = sys.getCurrentDirectory();
|
|
3529
|
-
const yarnLock = sys.readFileSync(sys.resolvePath(appRootDir + "/yarn.lock"));
|
|
3530
|
-
const yarnLockYml = sys.parseYarnLockFile?.(yarnLock);
|
|
3531
|
-
return ionicPackages.map(([k, v]) => {
|
|
3532
|
-
const identifiedVersion = `${k}@${v}`;
|
|
3533
|
-
let version = yarnLockYml?.object[identifiedVersion]?.version;
|
|
3534
|
-
version = version && version.includes("undefined") ? sanitizeDeclaredVersion(identifiedVersion) : version;
|
|
3535
|
-
return `${k}@${version}`;
|
|
3536
|
-
});
|
|
3537
|
-
}
|
|
3538
|
-
/**
|
|
3539
|
-
* This function is used for fallback purposes, where an npm or yarn lock file doesn't exist in the consumers directory.
|
|
3540
|
-
* This will strip away '*', '^' and '~' from the declared package versions in a package.json.
|
|
3541
|
-
* @param version the raw semver pattern identifier version string
|
|
3542
|
-
* @returns a cleaned up representation without any qualifiers
|
|
3543
|
-
*/
|
|
3544
|
-
function sanitizeDeclaredVersion(version) {
|
|
3545
|
-
return version.replace(/[*^~]/g, "");
|
|
3546
|
-
}
|
|
3547
|
-
/**
|
|
3548
|
-
* If telemetry is enabled, send a metric to an external data store
|
|
3549
|
-
*
|
|
3550
|
-
* @param sys the system instance where telemetry is invoked
|
|
3551
|
-
* @param flags the CLI flags (owned by CLI, not part of core config)
|
|
3552
|
-
* @param name the name of a trackable metric. Note this name is not necessarily a scalar value to track, like
|
|
3553
|
-
* "Stencil Version". For example, "stencil_cli_command" is a name that is used to track all CLI command information.
|
|
3554
|
-
* @param value the data to send to the external data store under the provided name argument
|
|
3555
|
-
*/
|
|
3556
|
-
async function sendMetric(sys, flags, name, value) {
|
|
3557
|
-
const session_id = await getTelemetryToken(sys);
|
|
3558
|
-
await sendTelemetry(sys, flags, {
|
|
3559
|
-
name,
|
|
3560
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3561
|
-
source: "stencil_cli",
|
|
3562
|
-
value,
|
|
3563
|
-
session_id
|
|
3564
|
-
});
|
|
3565
|
-
}
|
|
3566
|
-
/**
|
|
3567
|
-
* Used to read the config file's tokens.telemetry property.
|
|
3568
|
-
*
|
|
3569
|
-
* @param sys The system where the command is invoked
|
|
3570
|
-
* @returns string
|
|
3571
|
-
*/
|
|
3572
|
-
async function getTelemetryToken(sys) {
|
|
3573
|
-
const config = await readConfig(sys);
|
|
3574
|
-
if (config["tokens.telemetry"] === void 0) {
|
|
3575
|
-
config["tokens.telemetry"] = uuidv4();
|
|
3576
|
-
await writeConfig(sys, config);
|
|
3577
|
-
}
|
|
3578
|
-
return config["tokens.telemetry"];
|
|
3579
|
-
}
|
|
3580
|
-
/**
|
|
3581
|
-
* Issues a request to the telemetry server.
|
|
3582
|
-
* @param sys The system where the command is invoked
|
|
3583
|
-
* @param flags The CLI flags (owned by CLI, not part of core config)
|
|
3584
|
-
* @param data Data to be tracked
|
|
3585
|
-
*/
|
|
3586
|
-
async function sendTelemetry(sys, flags, data) {
|
|
3587
|
-
try {
|
|
3588
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3589
|
-
const body = {
|
|
3590
|
-
metrics: [data],
|
|
3591
|
-
sent_at: now
|
|
3592
|
-
};
|
|
3593
|
-
if (!sys.fetch) throw new Error("No fetch implementation available");
|
|
3594
|
-
const response = await sys.fetch("https://api.ionicjs.com/events/metrics", {
|
|
3595
|
-
method: "POST",
|
|
3596
|
-
headers: { "Content-Type": "application/json" },
|
|
3597
|
-
body: JSON.stringify(body)
|
|
3598
|
-
});
|
|
3599
|
-
if (hasVerbose(flags)) console.debug("\nSent %O metric to events service (status: %O)", data.name, response.status, "\n");
|
|
3600
|
-
if (response.status !== 204 && hasVerbose(flags)) console.debug("\nBad response from events service. Request body: %O", response.body.toString(), "\n");
|
|
3601
|
-
} catch (e) {
|
|
3602
|
-
if (hasVerbose(flags)) console.debug("Telemetry request failed:", e);
|
|
3603
|
-
}
|
|
3604
|
-
}
|
|
3605
|
-
/**
|
|
3606
|
-
* Checks if telemetry is enabled on this machine
|
|
3607
|
-
* @param sys The system where the command is invoked
|
|
3608
|
-
* @returns true if telemetry is enabled, false otherwise
|
|
3609
|
-
*/
|
|
3610
|
-
async function checkTelemetry(sys) {
|
|
3611
|
-
const config = await readConfig(sys);
|
|
3612
|
-
if (config["telemetry.stencil"] === void 0) {
|
|
3613
|
-
config["telemetry.stencil"] = true;
|
|
3614
|
-
await writeConfig(sys, config);
|
|
3615
|
-
}
|
|
3616
|
-
return config["telemetry.stencil"];
|
|
3617
|
-
}
|
|
3618
|
-
/**
|
|
3619
|
-
* Writes to the config file, enabling telemetry for this machine.
|
|
3620
|
-
* @param sys The system where the command is invoked
|
|
3621
|
-
* @returns true if writing the file was successful, false otherwise
|
|
3622
|
-
*/
|
|
3623
|
-
async function enableTelemetry(sys) {
|
|
3624
|
-
return await updateConfig(sys, { "telemetry.stencil": true });
|
|
3625
|
-
}
|
|
3626
|
-
/**
|
|
3627
|
-
* Writes to the config file, disabling telemetry for this machine.
|
|
3628
|
-
* @param sys The system where the command is invoked
|
|
3629
|
-
* @returns true if writing the file was successful, false otherwise
|
|
3630
|
-
*/
|
|
3631
|
-
async function disableTelemetry(sys) {
|
|
3632
|
-
return await updateConfig(sys, { "telemetry.stencil": false });
|
|
3633
|
-
}
|
|
3634
|
-
/**
|
|
3635
|
-
* Takes in a semver string in order to return the major version.
|
|
3636
|
-
* @param version The fully qualified semver version
|
|
3637
|
-
* @returns a string of the major version
|
|
3638
|
-
*/
|
|
3639
|
-
function getMajorVersion(version) {
|
|
3640
|
-
return version.split(".")[0];
|
|
3641
|
-
}
|
|
3642
|
-
//#endregion
|
|
3643
3273
|
//#region src/task-build.ts
|
|
3644
3274
|
const taskBuild = async (coreCompiler, config, flags) => {
|
|
3275
|
+
if (flags.unknownArgs?.includes("--docs")) config.logger.warn(`The --docs flag has been removed. To generate docs in a dev build, set "skipInDev: false" on the docs output targets, or run "stencil docs" (optionally with --watch).`);
|
|
3645
3276
|
if (flags.watch) {
|
|
3646
3277
|
await taskWatch(coreCompiler, config, flags);
|
|
3647
3278
|
return;
|
|
@@ -3669,7 +3300,6 @@ const taskBuild = async (coreCompiler, config, flags) => {
|
|
|
3669
3300
|
const versionChecker = startCheckVersion(config, coreCompiler.version, flags);
|
|
3670
3301
|
const compiler = await coreCompiler.createCompiler(config);
|
|
3671
3302
|
const results = await compiler.build();
|
|
3672
|
-
await telemetryBuildFinishedAction(config.sys, config, coreCompiler, results, flags);
|
|
3673
3303
|
await compiler.destroy();
|
|
3674
3304
|
if (results.hasError) {
|
|
3675
3305
|
const migrationResult = await detectMigrations(coreCompiler, config);
|
|
@@ -3715,6 +3345,10 @@ const taskBuild = async (coreCompiler, config, flags) => {
|
|
|
3715
3345
|
/**
|
|
3716
3346
|
* Prompt the user about available migrations.
|
|
3717
3347
|
* Shows what migrations are available and lets them choose to run them.
|
|
3348
|
+
*
|
|
3349
|
+
* Without someone to answer (in CI, or when stdin isn't a terminal) it doesn't prompt: it says
|
|
3350
|
+
* how to apply the migrations and returns `'exit'`, so the build fails instead of waiting
|
|
3351
|
+
* forever on a prompt, or ending with exit code 0 when stdin closes.
|
|
3718
3352
|
* @param config the Stencil config
|
|
3719
3353
|
* @param migrationResult the result of migration detection with available migrations
|
|
3720
3354
|
* @param context whether this is a pre-build check or post-error check
|
|
@@ -3733,6 +3367,10 @@ async function promptForMigration(config, migrationResult, context) {
|
|
|
3733
3367
|
logger.info("");
|
|
3734
3368
|
if (context === "pre-build") logger.info("Your config contains deprecated options that must be migrated before building.");
|
|
3735
3369
|
else logger.info("These migrations may help resolve the build errors above.");
|
|
3370
|
+
if (isCI || !process.stdin.isTTY) {
|
|
3371
|
+
logger.info(`Run ${logger.cyan("stencil migrate")} to apply them (or ${logger.cyan("stencil migrate --dry-run")} to preview the changes), then build again.`);
|
|
3372
|
+
return "exit";
|
|
3373
|
+
}
|
|
3736
3374
|
const action = await select({
|
|
3737
3375
|
message: "What would you like to do?",
|
|
3738
3376
|
options: [
|
|
@@ -3758,14 +3396,27 @@ async function promptForMigration(config, migrationResult, context) {
|
|
|
3758
3396
|
}
|
|
3759
3397
|
//#endregion
|
|
3760
3398
|
//#region src/task-docs.ts
|
|
3761
|
-
const taskDocs = async (coreCompiler, config) => {
|
|
3399
|
+
const taskDocs = async (coreCompiler, config, flags) => {
|
|
3762
3400
|
config.devServer = {};
|
|
3763
3401
|
config.outputTargets = config.outputTargets.filter(isOutputTargetDocs);
|
|
3764
3402
|
config.devMode = true;
|
|
3403
|
+
config.outputTargets.forEach((o) => o.skipInDev = false);
|
|
3404
|
+
if (config.outputTargets.length === 0) {
|
|
3405
|
+
config.logger.warn(`No docs output targets are configured, so there is nothing to generate. Add one to "outputTargets" (e.g. { type: 'docs-readme' }) or use --docsJson <path>.`);
|
|
3406
|
+
return;
|
|
3407
|
+
}
|
|
3408
|
+
if (flags.watch) {
|
|
3409
|
+
await taskWatch(coreCompiler, config, {
|
|
3410
|
+
...flags,
|
|
3411
|
+
serve: false
|
|
3412
|
+
});
|
|
3413
|
+
return;
|
|
3414
|
+
}
|
|
3765
3415
|
startupCompilerLog(coreCompiler, config);
|
|
3766
3416
|
const compiler = await coreCompiler.createCompiler(config);
|
|
3767
|
-
await compiler.build();
|
|
3417
|
+
const results = await compiler.build();
|
|
3768
3418
|
await compiler.destroy();
|
|
3419
|
+
if (results.hasError) return config.sys.exit(1);
|
|
3769
3420
|
};
|
|
3770
3421
|
//#endregion
|
|
3771
3422
|
//#region src/resolve-entry-script.ts
|
|
@@ -3841,26 +3492,74 @@ const taskGenerate = async (config, flags) => {
|
|
|
3841
3492
|
config.logger.error(tagError);
|
|
3842
3493
|
return config.sys.exit(1);
|
|
3843
3494
|
}
|
|
3844
|
-
const
|
|
3845
|
-
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
label: "None"
|
|
3856
|
-
}
|
|
3857
|
-
];
|
|
3858
|
-
const stylePick = await p.select({
|
|
3859
|
-
message: "Stylesheet format:",
|
|
3860
|
-
options: styleOptions
|
|
3495
|
+
const componentType = await p.select({
|
|
3496
|
+
message: "Component type:",
|
|
3497
|
+
options: [{
|
|
3498
|
+
value: "component",
|
|
3499
|
+
label: "Component",
|
|
3500
|
+
hint: "@Component decorator, TSX"
|
|
3501
|
+
}, {
|
|
3502
|
+
value: "css-only",
|
|
3503
|
+
label: "CSS-only component",
|
|
3504
|
+
hint: "pure CSS, no JS class or runtime"
|
|
3505
|
+
}]
|
|
3861
3506
|
});
|
|
3862
|
-
cancelIfAborted(
|
|
3863
|
-
const
|
|
3507
|
+
cancelIfAborted(componentType);
|
|
3508
|
+
const isCssOnly = componentType === "css-only";
|
|
3509
|
+
if (isCssOnly && config.enableCssOnlyComponents === false) p.note("`enableCssOnlyComponents` is disabled in your stencil.config - this component will not be discovered until it is re-enabled.", "Warning");
|
|
3510
|
+
let encapsulation = "none";
|
|
3511
|
+
if (!isCssOnly) {
|
|
3512
|
+
const encapsulationPick = await p.select({
|
|
3513
|
+
message: "Encapsulation:",
|
|
3514
|
+
initialValue: "none",
|
|
3515
|
+
options: [
|
|
3516
|
+
{
|
|
3517
|
+
value: "none",
|
|
3518
|
+
label: "None",
|
|
3519
|
+
hint: "light DOM, global styles"
|
|
3520
|
+
},
|
|
3521
|
+
{
|
|
3522
|
+
value: "scoped",
|
|
3523
|
+
label: "Scoped",
|
|
3524
|
+
hint: "light DOM, styles scoped via generated classes"
|
|
3525
|
+
},
|
|
3526
|
+
{
|
|
3527
|
+
value: "shadow",
|
|
3528
|
+
label: "Shadow",
|
|
3529
|
+
hint: "shadow DOM"
|
|
3530
|
+
}
|
|
3531
|
+
]
|
|
3532
|
+
});
|
|
3533
|
+
cancelIfAborted(encapsulationPick);
|
|
3534
|
+
encapsulation = encapsulationPick;
|
|
3535
|
+
}
|
|
3536
|
+
const styleExtOptions = [{
|
|
3537
|
+
value: "css",
|
|
3538
|
+
label: "CSS (.css)"
|
|
3539
|
+
}, ...[...new Set(generateContribs.flatMap((c) => c.styleExtensions ?? []))].map((ext) => ({
|
|
3540
|
+
value: ext,
|
|
3541
|
+
label: `${ext.toUpperCase()} (.${ext})`
|
|
3542
|
+
}))];
|
|
3543
|
+
let styleExtension;
|
|
3544
|
+
let cssOnlyExtension = "css";
|
|
3545
|
+
if (isCssOnly) {
|
|
3546
|
+
const stylePick = await p.select({
|
|
3547
|
+
message: "Stylesheet format:",
|
|
3548
|
+
options: styleExtOptions
|
|
3549
|
+
});
|
|
3550
|
+
cancelIfAborted(stylePick);
|
|
3551
|
+
cssOnlyExtension = stylePick;
|
|
3552
|
+
} else {
|
|
3553
|
+
const stylePick = await p.select({
|
|
3554
|
+
message: "Stylesheet format:",
|
|
3555
|
+
options: [...styleExtOptions, {
|
|
3556
|
+
value: "",
|
|
3557
|
+
label: "None"
|
|
3558
|
+
}]
|
|
3559
|
+
});
|
|
3560
|
+
cancelIfAborted(stylePick);
|
|
3561
|
+
styleExtension = stylePick || void 0;
|
|
3562
|
+
}
|
|
3864
3563
|
const demoPick = await p.select({
|
|
3865
3564
|
message: "Demo:",
|
|
3866
3565
|
options: [
|
|
@@ -3883,6 +3582,7 @@ const taskGenerate = async (config, flags) => {
|
|
|
3883
3582
|
cancelIfAborted(demoPick);
|
|
3884
3583
|
const generateCtx = {
|
|
3885
3584
|
tagName: componentName,
|
|
3585
|
+
cssOnly: isCssOnly,
|
|
3886
3586
|
config: toProjectConfig(config),
|
|
3887
3587
|
prompts: p,
|
|
3888
3588
|
nypm
|
|
@@ -3906,20 +3606,29 @@ const taskGenerate = async (config, flags) => {
|
|
|
3906
3606
|
const outDir = join(srcDir, "components", dir, componentName);
|
|
3907
3607
|
const className = toPascalCase(componentName);
|
|
3908
3608
|
const filesToWrite = [];
|
|
3909
|
-
filesToWrite.push({
|
|
3910
|
-
absPath: normalizePath(join(outDir, `${componentName}
|
|
3911
|
-
content:
|
|
3912
|
-
});
|
|
3913
|
-
if (styleExtension) filesToWrite.push({
|
|
3914
|
-
absPath: normalizePath(join(outDir, `${componentName}.${styleExtension}`)),
|
|
3915
|
-
content: getStyleBoilerplate(styleExtension)
|
|
3609
|
+
if (isCssOnly) filesToWrite.push({
|
|
3610
|
+
absPath: normalizePath(join(outDir, `${componentName}.${cssOnlyExtension}`)),
|
|
3611
|
+
content: getCssOnlyComponentBoilerplate(componentName, cssOnlyExtension)
|
|
3916
3612
|
});
|
|
3613
|
+
else {
|
|
3614
|
+
filesToWrite.push({
|
|
3615
|
+
absPath: normalizePath(join(outDir, `${componentName}.tsx`)),
|
|
3616
|
+
content: getComponentBoilerplate(componentName, {
|
|
3617
|
+
styleExtension,
|
|
3618
|
+
encapsulation
|
|
3619
|
+
})
|
|
3620
|
+
});
|
|
3621
|
+
if (styleExtension) filesToWrite.push({
|
|
3622
|
+
absPath: normalizePath(join(outDir, `${componentName}.${styleExtension}`)),
|
|
3623
|
+
content: getStyleBoilerplate(componentName, styleExtension, encapsulation)
|
|
3624
|
+
});
|
|
3625
|
+
}
|
|
3917
3626
|
for (const ext of pickedExtensions) {
|
|
3918
3627
|
const tmpl = allFileTemplates.find((ft) => ft.extension === ext);
|
|
3919
3628
|
const absPath = normalizePath(join(outDir, tmpl.subdirectory ?? "", `${componentName}.${ext}`));
|
|
3920
3629
|
filesToWrite.push({
|
|
3921
3630
|
absPath,
|
|
3922
|
-
content: tmpl.template(componentName, className)
|
|
3631
|
+
content: tmpl.template(componentName, className, { cssOnly: isCssOnly })
|
|
3923
3632
|
});
|
|
3924
3633
|
}
|
|
3925
3634
|
if (demoPick === "usage") filesToWrite.push({
|
|
@@ -3943,50 +3652,13 @@ const taskGenerate = async (config, flags) => {
|
|
|
3943
3652
|
p.outro(`stencil generate ${input}`);
|
|
3944
3653
|
};
|
|
3945
3654
|
//#endregion
|
|
3946
|
-
//#region src/task-telemetry.ts
|
|
3947
|
-
/**
|
|
3948
|
-
* Entrypoint for the Telemetry task
|
|
3949
|
-
* @param flags configuration flags provided to Stencil when a task was called (either this task or a task that invokes
|
|
3950
|
-
* telemetry)
|
|
3951
|
-
* @param sys the abstraction for interfacing with the operating system
|
|
3952
|
-
* @param logger a logging implementation to log the results out to the user
|
|
3953
|
-
*/
|
|
3954
|
-
const taskTelemetry = async (flags, sys, logger) => {
|
|
3955
|
-
const prompt = logger.dim(sys.details?.platform === "windows" ? ">" : "$");
|
|
3956
|
-
const isEnabling = flags.args.includes("on");
|
|
3957
|
-
const isDisabling = flags.args.includes("off");
|
|
3958
|
-
const INFORMATION = `Opt in or out of telemetry. Information about the data we collect is available on our website: ${logger.bold("https://stenciljs.com/telemetry")}`;
|
|
3959
|
-
const ENABLED_MESSAGE = `${logger.green("Enabled")}. Thank you for helping to make Stencil better! 💖\n\n`;
|
|
3960
|
-
const DISABLED_MESSAGE = `${logger.red("Disabled")}\n\n`;
|
|
3961
|
-
const hasTelemetry = await checkTelemetry(sys);
|
|
3962
|
-
if (isEnabling) {
|
|
3963
|
-
if (await enableTelemetry(sys)) console.log(`\n ${logger.bold("Telemetry is now ") + ENABLED_MESSAGE}`);
|
|
3964
|
-
else console.log(`Something went wrong when enabling Telemetry.`);
|
|
3965
|
-
return;
|
|
3966
|
-
}
|
|
3967
|
-
if (isDisabling) {
|
|
3968
|
-
if (await disableTelemetry(sys)) console.log(`\n ${logger.bold("Telemetry is now ") + DISABLED_MESSAGE}`);
|
|
3969
|
-
else console.log(`Something went wrong when disabling Telemetry.`);
|
|
3970
|
-
return;
|
|
3971
|
-
}
|
|
3972
|
-
console.log(` ${logger.bold("Telemetry:")} ${logger.dim(INFORMATION)}`);
|
|
3973
|
-
console.log(`\n ${logger.bold("Status")}: ${hasTelemetry ? ENABLED_MESSAGE : DISABLED_MESSAGE}`);
|
|
3974
|
-
console.log(` ${prompt} ${logger.green("stencil telemetry [off|on]")}
|
|
3975
|
-
|
|
3976
|
-
${logger.cyan("off")} ${logger.dim(".............")} Disable sharing anonymous usage data
|
|
3977
|
-
${logger.cyan("on")} ${logger.dim("..............")} Enable sharing anonymous usage data
|
|
3978
|
-
`);
|
|
3979
|
-
};
|
|
3980
|
-
//#endregion
|
|
3981
3655
|
//#region src/task-help.ts
|
|
3982
3656
|
/**
|
|
3983
3657
|
* Entrypoint for the Help task, providing Stencil usage context to the user
|
|
3984
|
-
* @param flags configuration flags provided to Stencil when a task was call (either this task or a task that invokes
|
|
3985
|
-
* telemetry)
|
|
3986
3658
|
* @param logger a logging implementation to log the results out to the user
|
|
3987
3659
|
* @param sys the abstraction for interfacing with the operating system
|
|
3988
3660
|
*/
|
|
3989
|
-
const taskHelp = async (
|
|
3661
|
+
const taskHelp = async (logger, sys) => {
|
|
3990
3662
|
const prompt = logger.dim(sys.details?.platform === "windows" ? ">" : "$");
|
|
3991
3663
|
console.log(`
|
|
3992
3664
|
${logger.bold("Init:")} ${logger.dim("Scaffold a new project, or add capabilities to an existing one.")}
|
|
@@ -4012,12 +3684,12 @@ const taskHelp = async (flags, logger, sys) => {
|
|
|
4012
3684
|
${logger.cyan("--watch")} ${logger.dim("...........")} Rebuild when files update
|
|
4013
3685
|
${logger.cyan("--serve")} ${logger.dim("...........")} Start the dev-server (requires --watch)
|
|
4014
3686
|
${logger.cyan("--prerender")} ${logger.dim(".......")} Prerender the application
|
|
4015
|
-
${logger.cyan("--docs")} ${logger.dim("............")} Generate component readme.md docs
|
|
4016
3687
|
${logger.cyan("--ssr")} ${logger.dim(".............")} Build a server-side-rendering bundle
|
|
4017
3688
|
${logger.cyan("--config")} ${logger.dim("..........")} Set stencil config file
|
|
4018
|
-
${logger.cyan("--maxWorkers")} ${logger.dim("......")} Max number of workers, e.g. --maxWorkers 4
|
|
3689
|
+
${logger.cyan("--maxWorkers")} ${logger.dim("......")} Max number of workers, e.g. --maxWorkers 4
|
|
4019
3690
|
${logger.cyan("--no-cache")} ${logger.dim("........")} Disable the build cache
|
|
4020
3691
|
${logger.cyan("--stats")} ${logger.dim("...........")} Write stats, optional file path (default: stencil-stats.json)
|
|
3692
|
+
${logger.cyan("--docsJson")} ${logger.dim("........")} Also write a docs.json file to the given path
|
|
4021
3693
|
${logger.cyan("--log")} ${logger.dim(".............")} Write stencil-build.log file
|
|
4022
3694
|
${logger.cyan("--ci")} ${logger.dim("..............")} Run in CI mode (disables colors, version checks)
|
|
4023
3695
|
${logger.cyan("--debug")} ${logger.dim("...........")} Set the log level to debug
|
|
@@ -4025,22 +3697,24 @@ const taskHelp = async (flags, logger, sys) => {
|
|
|
4025
3697
|
|
|
4026
3698
|
${logger.bold("Serve:")} ${logger.dim("Start the dev-server without building or watching.")}
|
|
4027
3699
|
|
|
4028
|
-
${prompt} ${logger.green("stencil serve [--root] [--
|
|
3700
|
+
${prompt} ${logger.green("stencil serve [--root] [--port] [--open]")}
|
|
4029
3701
|
|
|
4030
3702
|
${logger.cyan("--root")} ${logger.dim("............")} Directory to serve (default: current directory)
|
|
4031
|
-
${logger.cyan("--
|
|
3703
|
+
${logger.cyan("--port")} ${logger.dim("............")} Port to listen on
|
|
3704
|
+
${logger.cyan("--open")} ${logger.dim("............")} Open the browser
|
|
4032
3705
|
|
|
4033
3706
|
|
|
4034
|
-
${logger.bold("Docs:")} ${logger.dim("Generate
|
|
3707
|
+
${logger.bold("Docs:")} ${logger.dim("Generate only the docs output targets (a production build already includes them).")}
|
|
4035
3708
|
|
|
4036
|
-
${prompt} ${logger.green("stencil docs [--docsJson]")}
|
|
3709
|
+
${prompt} ${logger.green("stencil docs [--watch] [--docsJson]")}
|
|
4037
3710
|
|
|
3711
|
+
${logger.cyan("--watch")} ${logger.dim("...........")} Regenerate when files update
|
|
4038
3712
|
${logger.cyan("--docsJson")} ${logger.dim("........")} Write a docs.json file to the given path
|
|
4039
3713
|
|
|
4040
3714
|
|
|
4041
|
-
${logger.bold("Prerender:")} ${logger.dim("Prerender
|
|
3715
|
+
${logger.bold("Prerender:")} ${logger.dim("Prerender with an already-built ssr script, against the source index.html.")}
|
|
4042
3716
|
|
|
4043
|
-
${prompt} ${logger.green("stencil prerender <
|
|
3717
|
+
${prompt} ${logger.green("stencil prerender <ssr-script-path>")}
|
|
4044
3718
|
|
|
4045
3719
|
|
|
4046
3720
|
${logger.bold("Migrate:")} ${logger.dim("Codemod a project for the latest major version breaking changes.")}
|
|
@@ -4060,7 +3734,6 @@ const taskHelp = async (flags, logger, sys) => {
|
|
|
4060
3734
|
${prompt} ${logger.green("stencil version")} or ${logger.green("stencil --version")}
|
|
4061
3735
|
|
|
4062
3736
|
`);
|
|
4063
|
-
await taskTelemetry(flags, sys, logger);
|
|
4064
3737
|
console.log(`
|
|
4065
3738
|
${logger.bold("Examples:")}
|
|
4066
3739
|
|
|
@@ -4070,7 +3743,6 @@ const taskHelp = async (flags, logger, sys) => {
|
|
|
4070
3743
|
${prompt} ${logger.green("stencil build --prerender")}
|
|
4071
3744
|
${prompt} ${logger.green("stencil serve --root www")}
|
|
4072
3745
|
${prompt} ${logger.green("stencil migrate --dry-run")}
|
|
4073
|
-
${prompt} ${logger.green("stencil telemetry on")}
|
|
4074
3746
|
`);
|
|
4075
3747
|
};
|
|
4076
3748
|
//#endregion
|
|
@@ -4234,7 +3906,7 @@ async function writeStencilConfig(rootDir, content) {
|
|
|
4234
3906
|
async function writeGlobalStyle(rootDir) {
|
|
4235
3907
|
const path = join(rootDir, "src", "global.css");
|
|
4236
3908
|
await mkdir(dirname(path), { recursive: true });
|
|
4237
|
-
await writeIfAbsent(path, `@import "stencil-globals";\n@import "stencil-hydrate";\n`);
|
|
3909
|
+
await writeIfAbsent(path, `@import "stencil-component-globals";\n@import "stencil-hydrate";\n`);
|
|
4238
3910
|
}
|
|
4239
3911
|
async function writeGlobalScript(rootDir) {
|
|
4240
3912
|
const path = join(rootDir, "src", "global.ts");
|
|
@@ -4265,8 +3937,8 @@ function workspaceBuildScript(pm, coreName) {
|
|
|
4265
3937
|
*/
|
|
4266
3938
|
async function scaffoldWorkspaceRoot(cwd, projectName, coreName) {
|
|
4267
3939
|
await mkdir(join(cwd, "packages"), { recursive: true });
|
|
4268
|
-
const pm = await detectPackageManager(cwd);
|
|
4269
|
-
const usePnpmYaml = pm
|
|
3940
|
+
const pm = await detectPackageManager$1(cwd);
|
|
3941
|
+
const usePnpmYaml = pm === "pnpm";
|
|
4270
3942
|
const pkgPath = join(cwd, "package.json");
|
|
4271
3943
|
let pkg;
|
|
4272
3944
|
try {
|
|
@@ -4278,7 +3950,7 @@ async function scaffoldWorkspaceRoot(cwd, projectName, coreName) {
|
|
|
4278
3950
|
pkg.version ??= "0.0.1";
|
|
4279
3951
|
pkg.private = true;
|
|
4280
3952
|
pkg.scripts = {
|
|
4281
|
-
build: workspaceBuildScript(pm
|
|
3953
|
+
build: workspaceBuildScript(pm, coreName),
|
|
4282
3954
|
...pkg.scripts
|
|
4283
3955
|
};
|
|
4284
3956
|
if (!usePnpmYaml) pkg.workspaces = ["packages/*"];
|
|
@@ -4318,31 +3990,24 @@ async function verifyInstalled(rootDir, packageNames) {
|
|
|
4318
3990
|
p.log.error(`Install reported success but ${missing.join(", ")} could not be found in ${rootDir}. Your package manager may have silently failed to write to node_modules - check its logs and try again.`);
|
|
4319
3991
|
process.exit(1);
|
|
4320
3992
|
}
|
|
3993
|
+
const OUTPUT_TYPES = {
|
|
3994
|
+
loader: "loader-bundle",
|
|
3995
|
+
standalone: "standalone",
|
|
3996
|
+
ssr: "ssr",
|
|
3997
|
+
"ssr-wasm": "ssr-wasm",
|
|
3998
|
+
www: "www"
|
|
3999
|
+
};
|
|
4000
|
+
function outputKeysToTargets(keys) {
|
|
4001
|
+
return keys.length > 0 ? keys.map((k) => ({ type: OUTPUT_TYPES[k] })) : [{ type: "loader-bundle" }];
|
|
4002
|
+
}
|
|
4321
4003
|
/**
|
|
4322
|
-
*
|
|
4323
|
-
*
|
|
4324
|
-
*
|
|
4325
|
-
* `omit: ['dev']` - and per npm's own config flattening
|
|
4326
|
-
* (@npmcli/config/lib/definitions/definitions.js), whenever `omit` includes 'dev' npm sets
|
|
4327
|
-
* `process.env.NODE_ENV = 'production'` on itself. We inherit that env var from the outer
|
|
4328
|
-
* npm/npx process, and every child process we (or a wizard plugin) spawn from here would
|
|
4329
|
-
* inherit it right back, causing nested `npm install`s to also compute `omit: ['dev']` and
|
|
4330
|
-
* silently drop (or, worse, actively remove) every devDependency in the scaffolded project.
|
|
4331
|
-
* Clearing it once, up front, fixes every install call transitively - ours and every wizard
|
|
4332
|
-
* plugin's - without needing to special-case npm invocations one by one.
|
|
4004
|
+
* Reads which outputs a config file declares.
|
|
4005
|
+
* @param configPath Absolute path to the `stencil.config.ts`.
|
|
4006
|
+
* @returns The output keys present in its `outputTargets` array.
|
|
4333
4007
|
*/
|
|
4334
|
-
function
|
|
4335
|
-
|
|
4336
|
-
}
|
|
4337
|
-
function outputKeysToTargets(keys) {
|
|
4338
|
-
const map = {
|
|
4339
|
-
loader: "loader-bundle",
|
|
4340
|
-
standalone: "standalone",
|
|
4341
|
-
ssr: "ssr",
|
|
4342
|
-
"ssr-wasm": "ssr-wasm",
|
|
4343
|
-
www: "www"
|
|
4344
|
-
};
|
|
4345
|
-
return keys.length > 0 ? keys.map((k) => ({ type: map[k] })) : [{ type: "loader-bundle" }];
|
|
4008
|
+
async function readConfigOutputKeys(configPath) {
|
|
4009
|
+
const editor = await openStencilConfig(configPath);
|
|
4010
|
+
return Object.keys(OUTPUT_TYPES).filter((key) => [`'`, `"`].some((q) => editor.outputTargetsContains(`type: ${q}${OUTPUT_TYPES[key]}${q}`)));
|
|
4346
4011
|
}
|
|
4347
4012
|
async function taskInit(coreCompiler, strictConfig, loadProjectConfig) {
|
|
4348
4013
|
clearInheritedProductionEnv();
|
|
@@ -4375,8 +4040,9 @@ async function taskInit(coreCompiler, strictConfig, loadProjectConfig) {
|
|
|
4375
4040
|
namespace,
|
|
4376
4041
|
outputs,
|
|
4377
4042
|
signals: features.signals,
|
|
4043
|
+
exportMaps: features.exportMaps,
|
|
4378
4044
|
docs
|
|
4379
|
-
}) ?? (needsStencilConfig(selectedIntegrations) ? `import { Config } from '@stencil/core';\n\nexport const config: Config = {\n namespace: '${namespace}',\n
|
|
4045
|
+
}) ?? (needsStencilConfig(selectedIntegrations) ? `import type { Config } from '@stencil/core';\n\nexport const config: Config = {\n namespace: '${namespace}',\n};\n` : null);
|
|
4380
4046
|
const summaryLines = [
|
|
4381
4047
|
`Template: component-starter`,
|
|
4382
4048
|
`Name: ${projectName}`,
|
|
@@ -4390,6 +4056,7 @@ async function taskInit(coreCompiler, strictConfig, loadProjectConfig) {
|
|
|
4390
4056
|
if (selectedIntegrations.length > 0) summaryLines.push(`Add: ${selectedIntegrations.map((i) => i.displayName).join(", ")}`);
|
|
4391
4057
|
p.note(summaryLines.join("\n"), "Summary");
|
|
4392
4058
|
const coreDir = monorepo ? join(cwd, "packages", coreName) : cwd;
|
|
4059
|
+
const pm = await detectPackageManager$1(cwd);
|
|
4393
4060
|
const s1 = p.spinner();
|
|
4394
4061
|
s1.start("Scaffolding project files");
|
|
4395
4062
|
if (monorepo) await scaffoldWorkspaceRoot(cwd, projectName, coreName);
|
|
@@ -4408,7 +4075,8 @@ async function taskInit(coreCompiler, strictConfig, loadProjectConfig) {
|
|
|
4408
4075
|
s2.start("Installing dependencies");
|
|
4409
4076
|
await nypm.installDependencies({
|
|
4410
4077
|
cwd,
|
|
4411
|
-
silent: true
|
|
4078
|
+
silent: true,
|
|
4079
|
+
packageManager: pm
|
|
4412
4080
|
});
|
|
4413
4081
|
s2.stop("Dependencies installed");
|
|
4414
4082
|
await verifyInstalled(coreDir, ["@stencil/core"]);
|
|
@@ -4435,17 +4103,24 @@ async function taskInit(coreCompiler, strictConfig, loadProjectConfig) {
|
|
|
4435
4103
|
...toProjectConfig(resolvedValidated),
|
|
4436
4104
|
rootDir: coreDir
|
|
4437
4105
|
} : defaultProjectConfig(coreDir, { namespace });
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
|
|
4441
|
-
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
|
|
4445
|
-
|
|
4446
|
-
|
|
4106
|
+
let ranWizard = false;
|
|
4107
|
+
for (const d of discovered) if (selectedPkgs.has(d.packageName) && d.plugin.init?.run) {
|
|
4108
|
+
ranWizard = true;
|
|
4109
|
+
await d.plugin.init.run({
|
|
4110
|
+
isNewProject: true,
|
|
4111
|
+
prompts: p,
|
|
4112
|
+
nypm,
|
|
4113
|
+
config: projectConfig,
|
|
4114
|
+
workspaceRoot: monorepo ? cwd : void 0,
|
|
4115
|
+
ts,
|
|
4116
|
+
openStencilConfig: () => openStencilConfig(join(projectConfig.rootDir, "stencil.config.ts"))
|
|
4117
|
+
});
|
|
4118
|
+
}
|
|
4119
|
+
if (ranWizard && configSource) {
|
|
4120
|
+
const finalOutputs = await readConfigOutputKeys(join(coreDir, "stencil.config.ts"));
|
|
4121
|
+
await applyPackageJsonFields(coreDir, generatePackageJsonFields(finalOutputs));
|
|
4122
|
+
}
|
|
4447
4123
|
}
|
|
4448
|
-
const pm = (await nypm.detectPackageManager(cwd))?.name ?? "npm";
|
|
4449
4124
|
const devDir = monorepo ? `packages/${coreName}` : null;
|
|
4450
4125
|
const devCmd = `${pm} run dev`;
|
|
4451
4126
|
p.outro(devDir ? `Your project is ready!\n cd ${devDir}\n ${devCmd}` : `Your project is ready! Run: ${devCmd}`);
|
|
@@ -4501,7 +4176,7 @@ async function addCapabilities(cwd, strictConfig) {
|
|
|
4501
4176
|
ts,
|
|
4502
4177
|
openStencilConfig: () => openStencilConfig(join(projectConfig.rootDir, "stencil.config.ts"))
|
|
4503
4178
|
});
|
|
4504
|
-
p.outro(
|
|
4179
|
+
p.outro(`Done! Run ${await detectPackageManager$1(cwd)} run dev to continue.`);
|
|
4505
4180
|
}
|
|
4506
4181
|
function toNamespace(name) {
|
|
4507
4182
|
const base = name.replace(/^@[^/]+\//, "");
|
|
@@ -4517,7 +4192,6 @@ const taskServe = async (config, flags) => {
|
|
|
4517
4192
|
config.devServer.websocket = false;
|
|
4518
4193
|
config.maxConcurrentWorkers = 1;
|
|
4519
4194
|
config.devServer.root = isString(flags.root) ? flags.root : config.sys.getCurrentDirectory();
|
|
4520
|
-
if (!config.sys.onProcessInterrupt) throw new Error(`Environment doesn't provide required function: onProcessInterrupt`);
|
|
4521
4195
|
const devServer = await start(config.devServer, config.logger);
|
|
4522
4196
|
console.log(`${config.logger.cyan(" Root:")} ${devServer.root}`);
|
|
4523
4197
|
console.log(`${config.logger.cyan(" Address:")} ${devServer.address}`);
|
|
@@ -4550,17 +4224,13 @@ const run = async (init) => {
|
|
|
4550
4224
|
const task = flags.task;
|
|
4551
4225
|
if (flags.debug || flags.verbose) logger.setLevel("debug");
|
|
4552
4226
|
if (flags.ci) logger.enableColors(false);
|
|
4553
|
-
if (isFunction(sys.applyGlobalPatch)) sys.applyGlobalPatch(sys.getCurrentDirectory());
|
|
4554
4227
|
if (task && task === "version" || flags.version) {
|
|
4555
4228
|
const coreCompiler = await loadCoreCompiler(sys);
|
|
4556
4229
|
console.log(coreCompiler.version);
|
|
4557
4230
|
return;
|
|
4558
4231
|
}
|
|
4559
4232
|
if (!task || task === "help" || flags.help) {
|
|
4560
|
-
await taskHelp(
|
|
4561
|
-
task: "help",
|
|
4562
|
-
args
|
|
4563
|
-
}), logger, sys);
|
|
4233
|
+
await taskHelp(logger, sys);
|
|
4564
4234
|
return;
|
|
4565
4235
|
}
|
|
4566
4236
|
if (task === "test") {
|
|
@@ -4630,10 +4300,7 @@ const run = async (init) => {
|
|
|
4630
4300
|
logger.printDiagnostics(validated.diagnostics);
|
|
4631
4301
|
if (hasError(validated.diagnostics)) return sys.exit(1);
|
|
4632
4302
|
}
|
|
4633
|
-
|
|
4634
|
-
await telemetryAction(sys, validated.config, coreCompiler, flags, async () => {
|
|
4635
|
-
await runTask(coreCompiler, validated.config, task, sys, flags);
|
|
4636
|
-
});
|
|
4303
|
+
await runTask(coreCompiler, validated.config, task, sys, flags);
|
|
4637
4304
|
} catch (e) {
|
|
4638
4305
|
if (!shouldIgnoreError(e)) {
|
|
4639
4306
|
const details = `${logger.getLevel() === "debug" && e instanceof Error ? e.stack : ""}`;
|
|
@@ -4666,14 +4333,14 @@ const runTask = async (coreCompiler, config, task, sys, flags) => {
|
|
|
4666
4333
|
await taskBuild(coreCompiler, strictConfig, resolvedFlags);
|
|
4667
4334
|
break;
|
|
4668
4335
|
case "docs":
|
|
4669
|
-
await taskDocs(coreCompiler, strictConfig);
|
|
4336
|
+
await taskDocs(coreCompiler, strictConfig, resolvedFlags);
|
|
4670
4337
|
break;
|
|
4671
4338
|
case "generate":
|
|
4672
4339
|
case "g":
|
|
4673
4340
|
await taskGenerate(strictConfig, resolvedFlags);
|
|
4674
4341
|
break;
|
|
4675
4342
|
case "help":
|
|
4676
|
-
await taskHelp(
|
|
4343
|
+
await taskHelp(strictConfig.logger, sys);
|
|
4677
4344
|
break;
|
|
4678
4345
|
case "init":
|
|
4679
4346
|
await taskInit(coreCompiler, strictConfig);
|
|
@@ -4687,15 +4354,12 @@ const runTask = async (coreCompiler, config, task, sys, flags) => {
|
|
|
4687
4354
|
case "serve":
|
|
4688
4355
|
await taskServe(strictConfig, resolvedFlags);
|
|
4689
4356
|
break;
|
|
4690
|
-
case "telemetry":
|
|
4691
|
-
await taskTelemetry(resolvedFlags, sys, strictConfig.logger);
|
|
4692
|
-
break;
|
|
4693
4357
|
case "version":
|
|
4694
4358
|
console.log(coreCompiler.version);
|
|
4695
4359
|
break;
|
|
4696
4360
|
default:
|
|
4697
4361
|
strictConfig.logger.error(`${strictConfig.logger.emoji("❌ ")}Invalid stencil command, please see the options below:`);
|
|
4698
|
-
await taskHelp(
|
|
4362
|
+
await taskHelp(strictConfig.logger, sys);
|
|
4699
4363
|
return configWithFlags.sys.exit(1);
|
|
4700
4364
|
}
|
|
4701
4365
|
};
|