@stencil/cli 5.0.0-alpha.26 → 5.0.0-alpha.28
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/index.mjs +45 -27
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { mkdir, readFile, readdir, writeFile } from "node:fs/promises";
|
|
|
5
5
|
import * as p from "@clack/prompts";
|
|
6
6
|
import { cancel, isCancel, select } from "@clack/prompts";
|
|
7
7
|
import * as nypm from "nypm";
|
|
8
|
-
import { addDevDependency, detectPackageManager
|
|
8
|
+
import { addDevDependency, detectPackageManager } from "nypm";
|
|
9
9
|
import { isCI } from "std-env";
|
|
10
10
|
import ts from "typescript";
|
|
11
11
|
import { pathToFileURL } from "node:url";
|
|
@@ -636,7 +636,10 @@ async function openStencilConfig(configPath) {
|
|
|
636
636
|
}
|
|
637
637
|
function replaceInArray(arr, substring, expression) {
|
|
638
638
|
for (const element of arr.elements) if (text.slice(element.getStart(), element.getEnd()).includes(substring)) {
|
|
639
|
-
|
|
639
|
+
const lineStart = text.lastIndexOf("\n", element.getStart()) + 1;
|
|
640
|
+
const indent = text.slice(lineStart, element.getStart()).match(/^\s+/)?.[0] ?? "";
|
|
641
|
+
const indentedExpression = indent ? expression.replace(/\n/g, `\n${indent}`) : expression;
|
|
642
|
+
text = text.slice(0, element.getStart()) + indentedExpression + text.slice(element.getEnd());
|
|
640
643
|
return true;
|
|
641
644
|
}
|
|
642
645
|
return false;
|
|
@@ -674,12 +677,14 @@ async function openStencilConfig(configPath) {
|
|
|
674
677
|
let insertPos = arr.elements[arr.elements.length - 1].getEnd();
|
|
675
678
|
const trailingComma = text.slice(insertPos).match(/^\s*,/);
|
|
676
679
|
if (trailingComma) insertPos += trailingComma[0].length;
|
|
680
|
+
const separator = trailingComma ? "" : ",";
|
|
677
681
|
const firstElemStart = arr.elements[0].getStart();
|
|
678
682
|
if (text.slice(arr.getStart(), firstElemStart).includes("\n")) {
|
|
679
683
|
const lineStart = text.lastIndexOf("\n", firstElemStart) + 1;
|
|
680
684
|
const indent = text.slice(lineStart, firstElemStart).match(/^\s+/)?.[0] ?? " ";
|
|
681
|
-
|
|
682
|
-
|
|
685
|
+
const indentedCode = code.replace(/\n/g, `\n${indent}`);
|
|
686
|
+
text = `${text.slice(0, insertPos)}${separator}\n${indent}${indentedCode}${text.slice(insertPos)}`;
|
|
687
|
+
} else text = `${text.slice(0, insertPos)}${separator} ${code}${text.slice(insertPos)}`;
|
|
683
688
|
}
|
|
684
689
|
function addArrayProp(sf, propName, code) {
|
|
685
690
|
const configObj = findConfigObject(sf);
|
|
@@ -690,7 +695,8 @@ async function openStencilConfig(configPath) {
|
|
|
690
695
|
const lineStart = text.lastIndexOf("\n", firstPropStart) + 1;
|
|
691
696
|
propIndent = text.slice(lineStart, firstPropStart).match(/^\s+/)?.[0] ?? " ";
|
|
692
697
|
}
|
|
693
|
-
const
|
|
698
|
+
const elemIndent = propIndent + " ";
|
|
699
|
+
const newProp = `${propName}: [\n${elemIndent}${code.replace(/\n/g, `\n${elemIndent}`)},\n${propIndent}]`;
|
|
694
700
|
const lastProp = configObj.properties[configObj.properties.length - 1];
|
|
695
701
|
if (lastProp) {
|
|
696
702
|
let insertPos = lastProp.getEnd();
|
|
@@ -1197,7 +1203,7 @@ async function isExistingStencilProject(dir) {
|
|
|
1197
1203
|
}
|
|
1198
1204
|
//#endregion
|
|
1199
1205
|
//#region src/wizard/splash.ts
|
|
1200
|
-
const CLI_VERSION = "5.0.0-alpha.
|
|
1206
|
+
const CLI_VERSION = "5.0.0-alpha.28";
|
|
1201
1207
|
const isTTY = process.stdout.isTTY;
|
|
1202
1208
|
const noColor = !isTTY || "NO_COLOR" in process.env;
|
|
1203
1209
|
const RESET = noColor ? "" : "\x1B[0m";
|
|
@@ -3835,7 +3841,8 @@ async function copyTemplate(rootDir, projectName, namespace, stencilVersion) {
|
|
|
3835
3841
|
for (const entry of entries) {
|
|
3836
3842
|
if (!entry.isFile()) continue;
|
|
3837
3843
|
const srcPath = join(entry.parentPath, entry.name);
|
|
3838
|
-
|
|
3844
|
+
let relPath = relative(templateDir, srcPath);
|
|
3845
|
+
if (relPath === "_gitignore") relPath = ".gitignore";
|
|
3839
3846
|
const destPath = join(rootDir, relPath);
|
|
3840
3847
|
await mkdir(dirname(destPath), { recursive: true });
|
|
3841
3848
|
const content = (await readFile(srcPath, "utf8")).replace(/\{\{PROJECT_NAME\}\}/g, projectName).replace(/\{\{NAMESPACE\}\}/g, namespace).replace(/\{\{STENCIL_VERSION\}\}/g, resolvedStencilVersion);
|
|
@@ -3962,12 +3969,12 @@ async function writeIndexHtml(rootDir, content) {
|
|
|
3962
3969
|
await mkdir(dirname(path), { recursive: true });
|
|
3963
3970
|
await writeIfAbsent(path, content);
|
|
3964
3971
|
}
|
|
3965
|
-
function workspaceBuildScript(pm) {
|
|
3972
|
+
function workspaceBuildScript(pm, coreName) {
|
|
3966
3973
|
switch (pm) {
|
|
3967
3974
|
case "pnpm": return "pnpm -r build";
|
|
3968
3975
|
case "yarn": return "yarn workspaces run build";
|
|
3969
3976
|
case "bun": return "bun run --filter \"*\" build";
|
|
3970
|
-
default: return
|
|
3977
|
+
default: return `npm run build -w packages/${coreName} && npm run build --workspaces --if-present`;
|
|
3971
3978
|
}
|
|
3972
3979
|
}
|
|
3973
3980
|
/**
|
|
@@ -3976,9 +3983,10 @@ function workspaceBuildScript(pm) {
|
|
|
3976
3983
|
* `package.json` for npm / yarn / bun), and ensures a root `package.json` exists.
|
|
3977
3984
|
* @param cwd - Absolute path to the workspace root (where `package.json` will be created).
|
|
3978
3985
|
* @param projectName - Name to use for the root package.json (typically the project name).
|
|
3986
|
+
* @param coreName - Directory name of the core package under `packages/` (e.g. `core`).
|
|
3979
3987
|
* @returns A promise that resolves when the workspace root has been scaffolded.
|
|
3980
3988
|
*/
|
|
3981
|
-
async function scaffoldWorkspaceRoot(cwd, projectName) {
|
|
3989
|
+
async function scaffoldWorkspaceRoot(cwd, projectName, coreName) {
|
|
3982
3990
|
await mkdir(join(cwd, "packages"), { recursive: true });
|
|
3983
3991
|
const pm = await detectPackageManager(cwd);
|
|
3984
3992
|
const usePnpmYaml = pm?.name === "pnpm";
|
|
@@ -3993,7 +4001,7 @@ async function scaffoldWorkspaceRoot(cwd, projectName) {
|
|
|
3993
4001
|
pkg.version ??= "0.0.1";
|
|
3994
4002
|
pkg.private = true;
|
|
3995
4003
|
pkg.scripts = {
|
|
3996
|
-
build: workspaceBuildScript(pm?.name),
|
|
4004
|
+
build: workspaceBuildScript(pm?.name, coreName),
|
|
3997
4005
|
...pkg.scripts
|
|
3998
4006
|
};
|
|
3999
4007
|
if (!usePnpmYaml) pkg.workspaces = ["packages/*"];
|
|
@@ -4020,23 +4028,35 @@ async function applyPackageJsonFields(rootDir, fields) {
|
|
|
4020
4028
|
//#endregion
|
|
4021
4029
|
//#region src/task-init.ts
|
|
4022
4030
|
/**
|
|
4023
|
-
* Package managers can report success while silently failing to write to node_modules
|
|
4024
|
-
* (observed with npm computing a resolved lockfile but reifying zero filesystem changes).
|
|
4031
|
+
* Package managers can report success while silently failing to write to node_modules.
|
|
4025
4032
|
* Confirms packages actually landed on disk instead of trusting the install call's exit code.
|
|
4026
4033
|
*
|
|
4027
4034
|
* @param rootDir - directory to resolve packages from.
|
|
4028
4035
|
* @param packageNames - packages that were just supposed to be installed.
|
|
4029
|
-
* @returns names that failed to resolve; empty when everything installed correctly.
|
|
4030
4036
|
*/
|
|
4031
4037
|
async function verifyInstalled(rootDir, packageNames) {
|
|
4032
4038
|
const missing = [];
|
|
4033
4039
|
for (const name of packageNames) if (!await getPackageInfo(name, { paths: [rootDir] })) missing.push(name);
|
|
4034
|
-
|
|
4035
|
-
}
|
|
4036
|
-
function failInstallVerification(missing, rootDir) {
|
|
4040
|
+
if (missing.length === 0) return;
|
|
4037
4041
|
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.`);
|
|
4038
4042
|
process.exit(1);
|
|
4039
4043
|
}
|
|
4044
|
+
/**
|
|
4045
|
+
* npm silently omits devDependencies when this CLI is itself running as a nested child
|
|
4046
|
+
* process (e.g. via `npx create-stencil` / `npm init stencil`). Root cause: npm/exec only
|
|
4047
|
+
* needs @stencil/cli's own regular dependencies to resolve+run it, so that install computes
|
|
4048
|
+
* `omit: ['dev']` - and per npm's own config flattening
|
|
4049
|
+
* (@npmcli/config/lib/definitions/definitions.js), whenever `omit` includes 'dev' npm sets
|
|
4050
|
+
* `process.env.NODE_ENV = 'production'` on itself. We inherit that env var from the outer
|
|
4051
|
+
* npm/npx process, and every child process we (or a wizard plugin) spawn from here would
|
|
4052
|
+
* inherit it right back, causing nested `npm install`s to also compute `omit: ['dev']` and
|
|
4053
|
+
* silently drop (or, worse, actively remove) every devDependency in the scaffolded project.
|
|
4054
|
+
* Clearing it once, up front, fixes every install call transitively - ours and every wizard
|
|
4055
|
+
* plugin's - without needing to special-case npm invocations one by one.
|
|
4056
|
+
*/
|
|
4057
|
+
function clearInheritedProductionEnv() {
|
|
4058
|
+
if (process.env.NODE_ENV === "production") delete process.env.NODE_ENV;
|
|
4059
|
+
}
|
|
4040
4060
|
function outputKeysToTargets(keys) {
|
|
4041
4061
|
const map = {
|
|
4042
4062
|
loader: "loader-bundle",
|
|
@@ -4048,6 +4068,7 @@ function outputKeysToTargets(keys) {
|
|
|
4048
4068
|
return keys.length > 0 ? keys.map((k) => ({ type: map[k] })) : [{ type: "loader-bundle" }];
|
|
4049
4069
|
}
|
|
4050
4070
|
async function taskInit(coreCompiler, strictConfig, loadProjectConfig) {
|
|
4071
|
+
clearInheritedProductionEnv();
|
|
4051
4072
|
const cwd = process.cwd();
|
|
4052
4073
|
const isExistingProject = await isExistingStencilProject(cwd);
|
|
4053
4074
|
printSplash();
|
|
@@ -4094,7 +4115,7 @@ async function taskInit(coreCompiler, strictConfig, loadProjectConfig) {
|
|
|
4094
4115
|
const coreDir = monorepo ? join(cwd, "packages", coreName) : cwd;
|
|
4095
4116
|
const s1 = p.spinner();
|
|
4096
4117
|
s1.start("Scaffolding project files");
|
|
4097
|
-
if (monorepo) await scaffoldWorkspaceRoot(cwd, projectName);
|
|
4118
|
+
if (monorepo) await scaffoldWorkspaceRoot(cwd, projectName, coreName);
|
|
4098
4119
|
await copyTemplate(coreDir, projectName, namespace, coreCompiler?.version);
|
|
4099
4120
|
await applyPackageJsonFields(coreDir, generatePackageJsonFields(outputs));
|
|
4100
4121
|
if (configSource) await writeStencilConfig(coreDir, configSource);
|
|
@@ -4108,24 +4129,22 @@ async function taskInit(coreCompiler, strictConfig, loadProjectConfig) {
|
|
|
4108
4129
|
s1.stop("Project files created");
|
|
4109
4130
|
const s2 = p.spinner();
|
|
4110
4131
|
s2.start("Installing dependencies");
|
|
4111
|
-
await installDependencies({
|
|
4132
|
+
await nypm.installDependencies({
|
|
4112
4133
|
cwd,
|
|
4113
4134
|
silent: true
|
|
4114
4135
|
});
|
|
4115
4136
|
s2.stop("Dependencies installed");
|
|
4116
|
-
|
|
4117
|
-
if (missingBase.length > 0) failInstallVerification(missingBase, coreDir);
|
|
4137
|
+
await verifyInstalled(coreDir, ["@stencil/core"]);
|
|
4118
4138
|
if (selectedIntegrations.length > 0) {
|
|
4119
4139
|
const s3 = p.spinner();
|
|
4120
4140
|
const pkgs = selectedIntegrations.map((i) => i.package);
|
|
4121
4141
|
s3.start(`Installing ${pkgs.join(", ")}`);
|
|
4122
|
-
await addDevDependency(withVersionRanges(pkgs), {
|
|
4142
|
+
await nypm.addDevDependency(withVersionRanges(pkgs), {
|
|
4123
4143
|
cwd: coreDir,
|
|
4124
4144
|
silent: true
|
|
4125
4145
|
});
|
|
4126
4146
|
s3.stop("Integrations installed");
|
|
4127
|
-
|
|
4128
|
-
if (missingIntegrations.length > 0) failInstallVerification(missingIntegrations, coreDir);
|
|
4147
|
+
await verifyInstalled(coreDir, pkgs);
|
|
4129
4148
|
}
|
|
4130
4149
|
if (selectedIntegrations.length > 0) {
|
|
4131
4150
|
const discovered = await discoverPlugins(coreDir);
|
|
@@ -4185,13 +4204,12 @@ async function addCapabilities(cwd, strictConfig) {
|
|
|
4185
4204
|
const s = p.spinner();
|
|
4186
4205
|
const pkgs = toInstall.map((i) => i.package);
|
|
4187
4206
|
s.start(`Installing ${pkgs.join(", ")}`);
|
|
4188
|
-
await addDevDependency(withVersionRanges(pkgs), {
|
|
4207
|
+
await nypm.addDevDependency(withVersionRanges(pkgs), {
|
|
4189
4208
|
cwd,
|
|
4190
4209
|
silent: true
|
|
4191
4210
|
});
|
|
4192
4211
|
s.stop("Dependencies installed");
|
|
4193
|
-
|
|
4194
|
-
if (missing.length > 0) failInstallVerification(missing, cwd);
|
|
4212
|
+
await verifyInstalled(cwd, pkgs);
|
|
4195
4213
|
}
|
|
4196
4214
|
const allDiscovered = toInstall.length > 0 ? await discoverPlugins(cwd) : discovered;
|
|
4197
4215
|
const newlyInstalledPkgs = new Set(toInstall.map((i) => i.package));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stencil/cli",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.28",
|
|
4
4
|
"description": "CLI for Stencil - Web component compiler",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"components",
|
|
@@ -42,16 +42,16 @@
|
|
|
42
42
|
"nypm": "^0.3.12",
|
|
43
43
|
"std-env": "^3.8.0",
|
|
44
44
|
"typescript": ">4.0.0 <7.0.0",
|
|
45
|
-
"@stencil/dev-server": "5.0.0-alpha.
|
|
46
|
-
"@stencil/templates": "5.0.0-alpha.
|
|
45
|
+
"@stencil/dev-server": "5.0.0-alpha.28",
|
|
46
|
+
"@stencil/templates": "5.0.0-alpha.28"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"tsdown": ">=0.21.0 <1.0.0",
|
|
50
50
|
"vitest": "^4.1.7",
|
|
51
|
-
"@stencil/core": "5.0.0-alpha.
|
|
51
|
+
"@stencil/core": "5.0.0-alpha.28"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"@stencil/core": "^5.0.0 || 5.0.0-alpha.
|
|
54
|
+
"@stencil/core": "^5.0.0 || 5.0.0-alpha.28"
|
|
55
55
|
},
|
|
56
56
|
"volta": {
|
|
57
57
|
"extends": "../../package.json"
|