@stencil/cli 5.0.0-alpha.27 → 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 -52
- 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,47 +4028,34 @@ 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
|
}
|
|
4040
|
-
const NPM_CONFIG_ENV_PATTERN = /^npm_config_/i;
|
|
4041
4044
|
/**
|
|
4042
|
-
*
|
|
4043
|
-
*
|
|
4044
|
-
*
|
|
4045
|
-
*
|
|
4046
|
-
*
|
|
4047
|
-
*
|
|
4048
|
-
* npm
|
|
4049
|
-
*
|
|
4050
|
-
*
|
|
4051
|
-
*
|
|
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.
|
|
4052
4056
|
*/
|
|
4053
|
-
|
|
4054
|
-
|
|
4055
|
-
for (const key of Object.keys(process.env)) if (NPM_CONFIG_ENV_PATTERN.test(key)) {
|
|
4056
|
-
saved[key] = process.env[key];
|
|
4057
|
-
delete process.env[key];
|
|
4058
|
-
}
|
|
4059
|
-
try {
|
|
4060
|
-
return await fn();
|
|
4061
|
-
} finally {
|
|
4062
|
-
for (const [key, value] of Object.entries(saved)) process.env[key] = value;
|
|
4063
|
-
}
|
|
4057
|
+
function clearInheritedProductionEnv() {
|
|
4058
|
+
if (process.env.NODE_ENV === "production") delete process.env.NODE_ENV;
|
|
4064
4059
|
}
|
|
4065
4060
|
function outputKeysToTargets(keys) {
|
|
4066
4061
|
const map = {
|
|
@@ -4073,6 +4068,7 @@ function outputKeysToTargets(keys) {
|
|
|
4073
4068
|
return keys.length > 0 ? keys.map((k) => ({ type: map[k] })) : [{ type: "loader-bundle" }];
|
|
4074
4069
|
}
|
|
4075
4070
|
async function taskInit(coreCompiler, strictConfig, loadProjectConfig) {
|
|
4071
|
+
clearInheritedProductionEnv();
|
|
4076
4072
|
const cwd = process.cwd();
|
|
4077
4073
|
const isExistingProject = await isExistingStencilProject(cwd);
|
|
4078
4074
|
printSplash();
|
|
@@ -4119,7 +4115,7 @@ async function taskInit(coreCompiler, strictConfig, loadProjectConfig) {
|
|
|
4119
4115
|
const coreDir = monorepo ? join(cwd, "packages", coreName) : cwd;
|
|
4120
4116
|
const s1 = p.spinner();
|
|
4121
4117
|
s1.start("Scaffolding project files");
|
|
4122
|
-
if (monorepo) await scaffoldWorkspaceRoot(cwd, projectName);
|
|
4118
|
+
if (monorepo) await scaffoldWorkspaceRoot(cwd, projectName, coreName);
|
|
4123
4119
|
await copyTemplate(coreDir, projectName, namespace, coreCompiler?.version);
|
|
4124
4120
|
await applyPackageJsonFields(coreDir, generatePackageJsonFields(outputs));
|
|
4125
4121
|
if (configSource) await writeStencilConfig(coreDir, configSource);
|
|
@@ -4133,24 +4129,22 @@ async function taskInit(coreCompiler, strictConfig, loadProjectConfig) {
|
|
|
4133
4129
|
s1.stop("Project files created");
|
|
4134
4130
|
const s2 = p.spinner();
|
|
4135
4131
|
s2.start("Installing dependencies");
|
|
4136
|
-
await
|
|
4132
|
+
await nypm.installDependencies({
|
|
4137
4133
|
cwd,
|
|
4138
4134
|
silent: true
|
|
4139
|
-
})
|
|
4135
|
+
});
|
|
4140
4136
|
s2.stop("Dependencies installed");
|
|
4141
|
-
|
|
4142
|
-
if (missingBase.length > 0) failInstallVerification(missingBase, coreDir);
|
|
4137
|
+
await verifyInstalled(coreDir, ["@stencil/core"]);
|
|
4143
4138
|
if (selectedIntegrations.length > 0) {
|
|
4144
4139
|
const s3 = p.spinner();
|
|
4145
4140
|
const pkgs = selectedIntegrations.map((i) => i.package);
|
|
4146
4141
|
s3.start(`Installing ${pkgs.join(", ")}`);
|
|
4147
|
-
await
|
|
4142
|
+
await nypm.addDevDependency(withVersionRanges(pkgs), {
|
|
4148
4143
|
cwd: coreDir,
|
|
4149
4144
|
silent: true
|
|
4150
|
-
})
|
|
4145
|
+
});
|
|
4151
4146
|
s3.stop("Integrations installed");
|
|
4152
|
-
|
|
4153
|
-
if (missingIntegrations.length > 0) failInstallVerification(missingIntegrations, coreDir);
|
|
4147
|
+
await verifyInstalled(coreDir, pkgs);
|
|
4154
4148
|
}
|
|
4155
4149
|
if (selectedIntegrations.length > 0) {
|
|
4156
4150
|
const discovered = await discoverPlugins(coreDir);
|
|
@@ -4210,13 +4204,12 @@ async function addCapabilities(cwd, strictConfig) {
|
|
|
4210
4204
|
const s = p.spinner();
|
|
4211
4205
|
const pkgs = toInstall.map((i) => i.package);
|
|
4212
4206
|
s.start(`Installing ${pkgs.join(", ")}`);
|
|
4213
|
-
await
|
|
4207
|
+
await nypm.addDevDependency(withVersionRanges(pkgs), {
|
|
4214
4208
|
cwd,
|
|
4215
4209
|
silent: true
|
|
4216
|
-
})
|
|
4210
|
+
});
|
|
4217
4211
|
s.stop("Dependencies installed");
|
|
4218
|
-
|
|
4219
|
-
if (missing.length > 0) failInstallVerification(missing, cwd);
|
|
4212
|
+
await verifyInstalled(cwd, pkgs);
|
|
4220
4213
|
}
|
|
4221
4214
|
const allDiscovered = toInstall.length > 0 ? await discoverPlugins(cwd) : discovered;
|
|
4222
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/
|
|
46
|
-
"@stencil/
|
|
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"
|