@openelement/create 1.0.0-alpha.14 → 1.0.0-alpha.15

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.
Files changed (34) hide show
  1. package/README.md +49 -19
  2. package/package.json +1 -1
  3. package/src/cli.js +159 -76
  4. package/src/node-version.js +102 -0
  5. package/src/pm.js +143 -9
  6. package/src/template-builder.js +58 -7
  7. package/src/version.js +2 -10
  8. package/templates/.node-version +1 -0
  9. package/templates/AGENTS.md.tmpl +44 -0
  10. package/templates/README.tmpl +137 -96
  11. package/templates/app/components/page-404.css +2 -18
  12. package/templates/app/components/page-404.tsx.tmpl +10 -11
  13. package/templates/app/components/page-about.css +2 -69
  14. package/templates/app/components/page-about.tsx.tmpl +68 -48
  15. package/templates/app/components/page-home.css +2 -132
  16. package/templates/app/components/page-home.tsx.tmpl +106 -67
  17. package/templates/app/components/site-chrome.css +2 -65
  18. package/templates/app/head.tsx.tmpl +11 -26
  19. package/templates/app/islands/live-timer.css +2 -20
  20. package/templates/app/islands/live-timer.tsx.tmpl +25 -15
  21. package/templates/app/islands/my-counter.css +2 -29
  22. package/templates/app/islands/my-counter.tsx.tmpl +17 -8
  23. package/templates/app/layout.tsx.tmpl +68 -0
  24. package/templates/app/routes/404.tsx.tmpl +3 -6
  25. package/templates/app/routes/api/ping.ts.tmpl +2 -3
  26. package/templates/app/styles/theme.css +62 -77
  27. package/templates/openelement.config.ts.tmpl +16 -28
  28. package/templates/package.json.tmpl +8 -6
  29. package/templates/tsconfig.json.tmpl +1 -1
  30. package/templates/vite.config.ts.tmpl +7 -14
  31. package/templates/app/components/badges.css +0 -24
  32. package/templates/app/islands/app-shell.tsx.tmpl +0 -54
  33. package/templates/app/styles/recipes.css +0 -43
  34. package/templates/pnpm-workspace.yaml.tmpl +0 -29
package/src/pm.js CHANGED
@@ -7,8 +7,52 @@ import process from "node:process";
7
7
  * A separate module (not cli.ts): the module is imported by the tests, and
8
8
  * cli.ts executes the CLI at import time (top-level main), so anything the
9
9
  * tests need to call must live beside it, not inside it.
10
+ *
11
+ * Manager-neutral since alpha.15. The scaffold used to pin pnpm through a
12
+ * `catalog:` specifier in its own pnpm-workspace.yaml, and `catalog:` is a
13
+ * pnpm-only protocol — npm rejects the manifest with EUNSUPPORTEDPROTOCOL —
14
+ * so the probe had exactly one answer and a missing pnpm failed the run with
15
+ * a requirement. The template now ships explicit version pins, no
16
+ * `packageManager` field, and no workspace file, so any of the four common
17
+ * managers installs it unchanged.
18
+ *
19
+ * Detection has TWO sources, in order (TPL-02):
20
+ *
21
+ * 1. the INVOKING manager — the wrapper this run was started through. A
22
+ * packed `npm create @openelement` run used to print (and drive) `pnpm`
23
+ * whenever pnpm merely sat on PATH, which is surprising at best and
24
+ * wrong when the user's workflow is npm: the next-steps box must spell
25
+ * the manager the user actually chose. The signals are the ones every
26
+ * manager exports to its child (`npm_config_user_agent`, then
27
+ * `npm_execpath`, then the argv[1] runner name);
28
+ * 2. the PATH probe, in preference order pnpm, npm, yarn, bun — the
29
+ * fallback for a DIRECT `node`/`openelement-create` run, where no
30
+ * wrapper named itself.
31
+ *
32
+ * Only a PATH with none of the four AND no invoking manager fails.
33
+ *
34
+ * The module also owns the two lifecycle COMMAND spellings the CLI prints and
35
+ * every documented quickstart repeats (install dependencies, run dev): one
36
+ * builder each, so the handoff box and the guides cannot drift apart on
37
+ * package-manager spelling. With no manager named they fall back to the
38
+ * universal `npm` spelling — every one of the four runs the same scripts.
10
39
  */
11
- /** One package-manager probe: spawn `<pm> --version` off-PATH failures give ENOENT. */
40
+ /** The managers the install step can drive, in detection order. */
41
+ const PACKAGE_MANAGERS = [
42
+ "pnpm",
43
+ "npm",
44
+ "yarn",
45
+ "bun"
46
+ ];
47
+ /** `<pm> install` — the command a consumer runs when the scaffold skipped it. */
48
+ function installDependenciesCommand(pm = null) {
49
+ return `${pm ?? "npm"} install`;
50
+ }
51
+ /** `<pm> run dev` — the command every documented quickstart spells. */
52
+ function devCommand(pm = null) {
53
+ return `${pm ?? "npm"} run dev`;
54
+ }
55
+ /** Probe `<pm> --version`; an off-PATH binary gives ENOENT. */
12
56
  function packageManagerAvailable(pm) {
13
57
  const probe = spawnSync(pm, ["--version"], {
14
58
  stdio: "ignore",
@@ -17,14 +61,104 @@ function packageManagerAvailable(pm) {
17
61
  return probe.error === void 0 && probe.status === 0;
18
62
  }
19
63
  /**
20
- * Package-manager detection (pnpm wins, npm is the floor). Both ship with
21
- * Node-adjacent toolchains; the first probe that answers --version wins.
22
- * Never returns: with no manager the CLI fails with the manual-install path.
64
+ * The first available manager in {@link PACKAGE_MANAGERS} order, or `null`
65
+ * when none of the four is on PATH. The probe is injectable so the order (and
66
+ * the total miss) can be pinned without rewriting PATH.
67
+ */
68
+ function detectPackageManager(probe = packageManagerAvailable) {
69
+ for (const pm of PACKAGE_MANAGERS) if (probe(pm)) return pm;
70
+ return null;
71
+ }
72
+ /** The set form of {@link PACKAGE_MANAGERS}, for name lookups. */
73
+ const PACKAGE_MANAGER_NAMES = new Set(PACKAGE_MANAGERS);
74
+ /** One manager name from a signal, or `null` when the name is not one of ours. */
75
+ function managerNamed(name) {
76
+ const candidate = name?.trim().toLowerCase();
77
+ if (candidate === void 0 || candidate === "" || !PACKAGE_MANAGER_NAMES.has(candidate)) return null;
78
+ return candidate;
79
+ }
80
+ /**
81
+ * The runner file names that map to a manager. `npx`/`pnpm dlx`/`bunx` are
82
+ * runners of their manager, and `npm create` executes through npm's own
83
+ * `npm-cli.js`; `corepack` is deliberately absent — it is a shim over another
84
+ * manager, not a manager to spell commands for.
85
+ */
86
+ const RUNNER_MANAGERS = {
87
+ npm: "npm",
88
+ "npm-cli.js": "npm",
89
+ npx: "npm",
90
+ "npx-cli.js": "npm",
91
+ pnpm: "pnpm",
92
+ "pnpm.cjs": "pnpm",
93
+ "pnpm.js": "pnpm",
94
+ pnpx: "pnpm",
95
+ yarn: "yarn",
96
+ "yarn.js": "yarn",
97
+ "yarn.cjs": "yarn",
98
+ yarnpkg: "yarn",
99
+ bun: "bun",
100
+ bunx: "bun"
101
+ };
102
+ /** The last path segment of a POSIX or Windows path. */
103
+ function lastPathSegment(path) {
104
+ const normalized = path.replace(/\\+/g, "/");
105
+ return normalized.slice(normalized.lastIndexOf("/") + 1);
106
+ }
107
+ /**
108
+ * The manager named by `npm_config_user_agent` — the signal every one of the
109
+ * four exports to its children, shaped `<name>/<version> <rest>` (npm's own
110
+ * agent, for example, is `npm/11.6.0 node/v24.18.0 darwin arm64 workspaces/false`).
111
+ */
112
+ function invokingManagerFromUserAgent(userAgent) {
113
+ if (userAgent === void 0 || userAgent.trim() === "") return null;
114
+ return managerNamed(userAgent.trim().split(/[\s/]/, 1)[0]);
115
+ }
116
+ /**
117
+ * The manager named by `npm_execpath` — the absolute path of the manager's
118
+ * own entry script (`…/npm/bin/npm-cli.js`, `…/pnpm/bin/pnpm.cjs`,
119
+ * `…/yarn/bin/yarn.js`, `…/bun`). Matched on the basename with the manager
120
+ * names checked before npm's, because `pnpm` contains `npm`.
121
+ */
122
+ function invokingManagerFromExecPath(execPath) {
123
+ if (execPath === void 0 || execPath === "") return null;
124
+ const file = lastPathSegment(execPath).toLowerCase();
125
+ if (file.includes("pnpm")) return "pnpm";
126
+ if (file.includes("yarn")) return "yarn";
127
+ if (file.includes("bun")) return "bun";
128
+ if (file.includes("npm") || file.includes("npx")) return "npm";
129
+ return null;
130
+ }
131
+ /**
132
+ * The manager named by `process.argv[1]` — the runner script itself when the
133
+ * CLI is executed through a manager binary rather than through its own node
134
+ * entry. A direct `node …/cli.ts` run names the CLI file, which matches
135
+ * nothing by construction.
136
+ */
137
+ function invokingManagerFromArgv1(argv) {
138
+ const runner = argv[1];
139
+ if (runner === void 0 || runner === "") return null;
140
+ return RUNNER_MANAGERS[lastPathSegment(runner).toLowerCase()] ?? null;
141
+ }
142
+ /**
143
+ * The manager this run was INVOKED through, or `null` when no wrapper named
144
+ * itself (a direct `node` execution). Signals are read in the order every
145
+ * manager's environment makes reliable: the user agent first (it names the
146
+ * wrapper unambiguously), then the exec path, then the argv[1] runner name.
147
+ * Both inputs are injectable, so the precedence is pinned without touching
148
+ * the host's real environment or argv.
149
+ */
150
+ function detectInvokingPackageManager(env = process.env, argv = process.argv) {
151
+ return invokingManagerFromUserAgent(env.npm_config_user_agent) ?? invokingManagerFromExecPath(env.npm_execpath) ?? invokingManagerFromArgv1(argv);
152
+ }
153
+ /**
154
+ * The manager a run should use, in the two-source order the module header
155
+ * documents: the INVOKING manager when one named itself, otherwise the first
156
+ * of the four on PATH. `null` means "neither a wrapper nor a PATH" — the one
157
+ * case the CLI reports as a failure (or falls back to npm's universal spelling
158
+ * for, in a --no-install handoff).
23
159
  */
24
- function detectPackageManager() {
25
- for (const pm of ["pnpm", "npm"]) if (packageManagerAvailable(pm)) return pm;
26
- console.error("error: No package manager found (probed pnpm, then npm). Install one of them, then run the install step manually inside the project directory.");
27
- process.exit(1);
160
+ function resolvePackageManager(options = {}) {
161
+ return detectInvokingPackageManager(options.env ?? process.env, options.argv ?? process.argv) ?? detectPackageManager(options.probe);
28
162
  }
29
163
  //#endregion
30
- export { detectPackageManager };
164
+ export { PACKAGE_MANAGERS, detectInvokingPackageManager, detectPackageManager, devCommand, installDependenciesCommand, packageManagerAvailable, resolvePackageManager };
@@ -1,4 +1,4 @@
1
- import { CREATE_VERSION, VITE_STARTER_PIN } from "./version.js";
1
+ import { CREATE_VERSION } from "./version.js";
2
2
  import { readFile } from "node:fs/promises";
3
3
  //#region src/template-builder.ts
4
4
  const MAX_PROJECT_NAME_LENGTH = 214;
@@ -17,6 +17,59 @@ function validateProjectName(name) {
17
17
  return null;
18
18
  }
19
19
  /**
20
+ * The project name for an in-place scaffold (`npm create @openelement .`),
21
+ * derived from the directory's own name and lowered into the package-name
22
+ * grammar {@linkcode validateProjectName} enforces: a host directory called
23
+ * `My App` still generates a legal `my-app` manifest. The result is always a
24
+ * valid name, so the in-place path never fails on the host's directory name;
25
+ * a directory with no usable characters at all (a filesystem root) falls back
26
+ * to `app`.
27
+ */
28
+ function inPlaceProjectName(directory) {
29
+ let normalized = "";
30
+ for (const char of directory) {
31
+ const mapped = char === "\\" ? "/" : char;
32
+ if (mapped === "/" && normalized.endsWith("/")) continue;
33
+ normalized += mapped;
34
+ }
35
+ let normalizedEnd = normalized.length;
36
+ while (normalizedEnd > 0 && normalized[normalizedEnd - 1] === "/") normalizedEnd -= 1;
37
+ const trimmed = normalized.slice(0, normalizedEnd);
38
+ const base = trimmed.slice(trimmed.lastIndexOf("/") + 1);
39
+ let slug = "";
40
+ let inIllegalRun = false;
41
+ for (const char of base.toLowerCase()) if (char >= "a" && char <= "z" || char >= "0" && char <= "9" || char === "." || char === "_" || char === "-") {
42
+ slug += char;
43
+ inIllegalRun = false;
44
+ } else if (!inIllegalRun) {
45
+ slug += "-";
46
+ inIllegalRun = true;
47
+ }
48
+ let dedotted = "";
49
+ let dots = 0;
50
+ for (const char of slug) {
51
+ if (char === ".") {
52
+ dots += 1;
53
+ if (dots > 1) continue;
54
+ } else dots = 0;
55
+ dedotted += char;
56
+ }
57
+ let start = 0;
58
+ while (start < dedotted.length) {
59
+ const char = dedotted[start];
60
+ if (char >= "a" && char <= "z" || char >= "0" && char <= "9") break;
61
+ start += 1;
62
+ }
63
+ let end = dedotted.length;
64
+ while (end > start) {
65
+ const char = dedotted[end - 1];
66
+ if (char === "-" || char === "." || char === "_") end -= 1;
67
+ else break;
68
+ }
69
+ const cleaned = dedotted.slice(start, end).slice(0, MAX_PROJECT_NAME_LENGTH);
70
+ return cleaned === "" ? "app" : cleaned;
71
+ }
72
+ /**
20
73
  * The published starter relies on the support-package same-version release
21
74
  * invariant. Package-graph and release-prepare gates verify that invariant;
22
75
  * Create deliberately has no runtime registry fallback or mixed-version mode.
@@ -35,20 +88,19 @@ function assertUnifiedProductVersions(versions) {
35
88
  }
36
89
  const TEMPLATE_FILES = [
37
90
  ["gitignore.tmpl", ".gitignore"],
91
+ [".node-version", ".node-version"],
38
92
  ["README.tmpl", "README.md"],
93
+ ["AGENTS.md.tmpl", "AGENTS.md"],
39
94
  ["public/openelement-mark.svg", "public/openelement-mark.svg"],
40
95
  ["package.json.tmpl", "package.json"],
41
96
  ["tsconfig.json.tmpl", "tsconfig.json"],
42
97
  ["vite.config.ts.tmpl", "vite.config.ts"],
43
- ["pnpm-workspace.yaml.tmpl", "pnpm-workspace.yaml"],
44
98
  ["openelement.config.ts.tmpl", "openelement.config.ts"],
45
99
  ["app/styles/theme.css", "app/styles/theme.css"],
46
- ["app/styles/recipes.css", "app/styles/recipes.css"],
47
100
  ["app/head.tsx.tmpl", "app/head.tsx"],
48
101
  ["app/components/page-home.css", "app/components/page-home.css"],
49
102
  ["app/components/page-about.css", "app/components/page-about.css"],
50
103
  ["app/components/page-404.css", "app/components/page-404.css"],
51
- ["app/components/badges.css", "app/components/badges.css"],
52
104
  ["app/components/site-chrome.css", "app/components/site-chrome.css"],
53
105
  ["app/components/page-home.tsx.tmpl", "app/components/page-home.tsx"],
54
106
  ["app/components/page-about.tsx.tmpl", "app/components/page-about.tsx"],
@@ -61,7 +113,7 @@ const TEMPLATE_FILES = [
61
113
  ["app/islands/my-counter.css", "app/islands/my-counter.css"],
62
114
  ["app/islands/live-timer.tsx.tmpl", "app/islands/live-timer.tsx"],
63
115
  ["app/islands/live-timer.css", "app/islands/live-timer.css"],
64
- ["app/islands/app-shell.tsx.tmpl", "app/islands/app-shell.tsx"]
116
+ ["app/layout.tsx.tmpl", "app/layout.tsx"]
65
117
  ];
66
118
  function versionTokens(v) {
67
119
  return {
@@ -76,7 +128,6 @@ async function buildTemplates(v, projectName) {
76
128
  const templatesBase = new URL("../templates/", import.meta.url);
77
129
  const tokens = {
78
130
  ...versionTokens(v),
79
- ["${v.vite}"]: VITE_STARTER_PIN,
80
131
  ["${name}"]: projectName
81
132
  };
82
133
  const entries = await Promise.all(TEMPLATE_FILES.map(async ([source, target]) => {
@@ -89,4 +140,4 @@ async function buildTemplates(v, projectName) {
89
140
  return Object.fromEntries(Object.entries(out).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0));
90
141
  }
91
142
  //#endregion
92
- export { assertUnifiedProductVersions, buildTemplates, resolveVersions, validateProjectName };
143
+ export { TEMPLATE_FILES, assertUnifiedProductVersions, buildTemplates, inPlaceProjectName, resolveVersions, validateProjectName };
package/src/version.js CHANGED
@@ -1,13 +1,5 @@
1
1
  //#region src/version.ts
2
2
  /** The published CLI version, embedded so packed npm installs are self-contained. */
3
- const CREATE_VERSION = "1.0.0-alpha.14";
4
- /**
5
- * The Vite release pinned into the generated starter's package.json (the
6
- * `${v.vite}` scaffold token in the npm/pnpm starter). Embedded for the same
7
- * reason as CREATE_VERSION (packed npm installs are self-contained); the
8
- * repository's Vite-pin check (deps:vite-check in the repo tooling package) anchors this copy
9
- * to the canonical dev pin.
10
- */
11
- const VITE_STARTER_PIN = "8.0.16";
3
+ const CREATE_VERSION = "1.0.0-alpha.15";
12
4
  //#endregion
13
- export { CREATE_VERSION, VITE_STARTER_PIN };
5
+ export { CREATE_VERSION };
@@ -0,0 +1 @@
1
+ 24.18.0
@@ -0,0 +1,44 @@
1
+ # AGENTS.md
2
+
3
+ An openElement application. This file is the entry pointer for AI coding agents
4
+ working in this project.
5
+
6
+ ## Start here
7
+
8
+ - Agent and consumer index: <https://openelement.org/llms.txt>
9
+ - Getting started: <https://openelement.org/guide/getting-started>
10
+ - API reference (packages, exports, custom elements, config): <https://openelement.org/reference>
11
+ - Diagnostics (the `OEC` codes the compiler and runtime emit): <https://openelement.org/errors>
12
+
13
+ ## Commands
14
+
15
+ ```sh
16
+ npm run dev # dev server with HMR
17
+ npm run build # production build into dist/
18
+ npm run start # serve the built output (and request-time routes)
19
+ npm run typecheck # tsc --noEmit
20
+ npm run lint # oxlint
21
+ npm run test # node --test
22
+ npm run fmt # oxfmt
23
+ ```
24
+
25
+ ## Project layout
26
+
27
+ - `app/routes/` — pages (default export) and form actions.
28
+ - `app/islands/` — interactive islands; each one hydrates with its declared strategy.
29
+ - `app/components/` — presentational components and their root CSS.
30
+ - `app/layout.tsx` — the shared document chrome every page renders inside.
31
+ - `app/head.tsx` — document head entries a config URL list cannot express.
32
+ - `openelement.config.ts` — framework options (head, i18n, middleware, ...).
33
+ - `public/` — copied verbatim into `dist/`.
34
+
35
+ ## Rules
36
+
37
+ - Never edit `dist/` by hand: it is build output.
38
+ - Islands run in the browser. Importing `node:*` from an island fails the build
39
+ by design — server-only code belongs in route loaders and actions.
40
+ - A page that mounts no island ships no island JavaScript; keep static surfaces
41
+ static instead of widening the island graph.
42
+ - `dist/server/` is private server code; never publish it as a static asset.
43
+ - Keep `npm run typecheck`, `npm run lint`, `npm run test` and `npm run build`
44
+ green after a change; `npm run check` is not a script in this scaffold.