create-nextly-app 0.0.2-alpha.72 → 0.0.2-alpha.73
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/cli.cjs +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/{create-nextly-CyI8XgVc.mjs → create-nextly-CuWn_ITx.mjs} +807 -466
- package/dist/create-nextly-CuWn_ITx.mjs.map +1 -0
- package/dist/{create-nextly-BGu1tXYs.cjs → create-nextly-Q62KZJib.cjs} +807 -466
- package/dist/create-nextly-Q62KZJib.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +5 -5
- package/skills/nextly-authentication/SKILL.md +1 -1
- package/skills/nextly-collections/SKILL.md +10 -4
- package/skills/nextly-deploy/SKILL.md +5 -3
- package/skills/nextly-install/SKILL.md +5 -4
- package/templates/base/src/app/admin/[[...params]]/layout.tsx +15 -1
- package/templates/base/src/app/globals.css +13 -2
- package/templates/blank/src/app/(frontend)/page.tsx +43 -21
- package/templates/blank/src/instrumentation.ts +3 -2
- package/templates/plugin/dev/next.config.ts +8 -2
- package/templates/plugin/dev/src/app/admin/[[...params]]/layout.tsx +24 -0
- package/templates/plugin/dev/src/instrumentation.ts +3 -2
- package/dist/create-nextly-BGu1tXYs.cjs.map +0 -1
- package/dist/create-nextly-CyI8XgVc.mjs.map +0 -1
|
@@ -22842,6 +22842,7 @@ function nextlySource(options) {
|
|
|
22842
22842
|
function isNextlyPackage(name) {
|
|
22843
22843
|
return name === "nextly" || name.startsWith("@nextlyhq/");
|
|
22844
22844
|
}
|
|
22845
|
+
/** The package.json fields that declare a dependency, in the order read. */
|
|
22845
22846
|
const DEPENDENCY_FIELDS$1 = [
|
|
22846
22847
|
"dependencies",
|
|
22847
22848
|
"devDependencies",
|
|
@@ -22917,6 +22918,10 @@ const EXACT_FLAG = {
|
|
|
22917
22918
|
yarn: "--exact",
|
|
22918
22919
|
bun: "--exact"
|
|
22919
22920
|
};
|
|
22921
|
+
/**
|
|
22922
|
+
* How each package manager adds a dependency. Exported so every message that
|
|
22923
|
+
* tells the person what to install spells the command the same way.
|
|
22924
|
+
*/
|
|
22920
22925
|
const ADD_COMMAND = {
|
|
22921
22926
|
npm: "npm install",
|
|
22922
22927
|
pnpm: "pnpm add",
|
|
@@ -42486,8 +42491,8 @@ var import_lib = (/* @__PURE__ */ __commonJSMin$1(((exports) => {
|
|
|
42486
42491
|
exports.parse = parse;
|
|
42487
42492
|
})))();
|
|
42488
42493
|
/**
|
|
42489
|
-
* Where Nextly explains
|
|
42490
|
-
*
|
|
42494
|
+
* Where Nextly explains the Cache Components settings every app it makes or
|
|
42495
|
+
* joins carries, and why each one is there.
|
|
42491
42496
|
*/
|
|
42492
42497
|
const CACHE_COMPONENTS_DOCS_URL = "https://nextlyhq.com/docs/getting-started/installation#cache-components";
|
|
42493
42498
|
/**
|
|
@@ -42525,13 +42530,42 @@ function packageListLiteral(database) {
|
|
|
42525
42530
|
return JSON.stringify(getServerExternalPackages(database), null, 2).replace(/\n/g, "\n ");
|
|
42526
42531
|
}
|
|
42527
42532
|
/**
|
|
42528
|
-
*
|
|
42529
|
-
*
|
|
42533
|
+
* Nextly's cache handlers, as the settings that install them. Under Cache
|
|
42534
|
+
* Components, Next.js's default cache serves a page's previous shell once
|
|
42535
|
+
* after a write expires its tags; these expire it at once.
|
|
42536
|
+
*/
|
|
42537
|
+
const HANDLER_SETTINGS = [
|
|
42538
|
+
"cacheHandler",
|
|
42539
|
+
"cacheMaxMemorySize",
|
|
42540
|
+
"cacheHandlers"
|
|
42541
|
+
];
|
|
42542
|
+
const HANDLER_PROPERTIES = [
|
|
42543
|
+
"cacheHandler: require.resolve(\"nextly/cache-handler\")",
|
|
42544
|
+
"cacheMaxMemorySize: 0",
|
|
42545
|
+
"cacheHandlers: { default: require.resolve(\"nextly/cache-handlers\") }"
|
|
42546
|
+
];
|
|
42547
|
+
const ON_OPTIONS = ["cacheComponents", "partialPrefetching"];
|
|
42548
|
+
/** Every setting Nextly needs, as lines of a config object. */
|
|
42549
|
+
const ON_LINES = [...ON_OPTIONS.map((option) => `${option}: true`), ...HANDLER_PROPERTIES].map((property) => ` ${property},`);
|
|
42550
|
+
/**
|
|
42551
|
+
* The settings every config this writes carries, with their reason in the
|
|
42552
|
+
* file: the developer who finds them is the one deciding whether to change
|
|
42553
|
+
* them.
|
|
42530
42554
|
*/
|
|
42531
|
-
const
|
|
42532
|
-
//
|
|
42555
|
+
const CACHE_COMPONENTS_ON = ` // Nextly runs with Cache Components and Partial Prefetching on. Its cache
|
|
42556
|
+
// handlers make the first read after a write show the new version, where
|
|
42557
|
+
// Next.js's default cache would serve the previous page once more:
|
|
42533
42558
|
// ${CACHE_COMPONENTS_DOCS_URL}
|
|
42534
|
-
|
|
42559
|
+
${ON_LINES.join("\n")}`;
|
|
42560
|
+
/**
|
|
42561
|
+
* How an ES module config gets `require`, which Node defines only in
|
|
42562
|
+
* CommonJS, to resolve the handlers from the app's own node_modules.
|
|
42563
|
+
*/
|
|
42564
|
+
const REQUIRE_IMPORT = "import { createRequire } from \"node:module\";";
|
|
42565
|
+
/** The declaration, calling `createRequire` by the name the file has it under. */
|
|
42566
|
+
const requireDeclaration = (createRequireName) => `// Resolves Nextly's cache handlers from this app's node_modules.
|
|
42567
|
+
const require = ${createRequireName}(import.meta.url);`;
|
|
42568
|
+
const REQUIRE_DECLARATION = requireDeclaration("createRequire");
|
|
42535
42569
|
/**
|
|
42536
42570
|
* Render a complete next.config.ts file for the selected database.
|
|
42537
42571
|
*/
|
|
@@ -42539,7 +42573,7 @@ function buildNextConfigTemplate(database) {
|
|
|
42539
42573
|
return `import type { NextConfig } from "next";
|
|
42540
42574
|
|
|
42541
42575
|
const nextConfig: NextConfig = {
|
|
42542
|
-
${
|
|
42576
|
+
${CACHE_COMPONENTS_ON}
|
|
42543
42577
|
serverExternalPackages: ${packageListLiteral(database)},
|
|
42544
42578
|
};
|
|
42545
42579
|
|
|
@@ -42548,9 +42582,13 @@ export default nextConfig;
|
|
|
42548
42582
|
}
|
|
42549
42583
|
/** The same config as a JavaScript module, for an app without TypeScript. */
|
|
42550
42584
|
function buildNextConfigModule(database) {
|
|
42551
|
-
return
|
|
42585
|
+
return `${REQUIRE_IMPORT}
|
|
42586
|
+
|
|
42587
|
+
${REQUIRE_DECLARATION}
|
|
42588
|
+
|
|
42589
|
+
/** @type {import("next").NextConfig} */
|
|
42552
42590
|
const nextConfig = {
|
|
42553
|
-
${
|
|
42591
|
+
${CACHE_COMPONENTS_ON}
|
|
42554
42592
|
serverExternalPackages: ${packageListLiteral(database)},
|
|
42555
42593
|
};
|
|
42556
42594
|
|
|
@@ -42568,9 +42606,19 @@ const CONFIG_FILES = [
|
|
|
42568
42606
|
"next.config.ts",
|
|
42569
42607
|
"next.config.mts"
|
|
42570
42608
|
];
|
|
42571
|
-
/** The first Next.js major whose option is the top-level `serverExternalPackages`. */
|
|
42572
|
-
const FIRST_TOP_LEVEL_MAJOR = 15;
|
|
42573
42609
|
const PROPERTY = "serverExternalPackages";
|
|
42610
|
+
/**
|
|
42611
|
+
* The deprecated spelling of the list, under `experimental`. Supported
|
|
42612
|
+
* releases still read it, by copying it over the top-level list, so an app
|
|
42613
|
+
* that has it would lose the packages this adds there.
|
|
42614
|
+
*/
|
|
42615
|
+
const LEGACY_PROPERTY = "serverComponentsExternalPackages";
|
|
42616
|
+
/**
|
|
42617
|
+
* Why a config with the deprecated list is left alone. Named, so the advice
|
|
42618
|
+
* printed for it can say what to do with that list rather than the advice
|
|
42619
|
+
* for every other refusal, which says to keep the experimental keys there.
|
|
42620
|
+
*/
|
|
42621
|
+
const LEGACY_LIST_REASON = `it lists packages under experimental.${LEGACY_PROPERTY}, which Next.js copies over ${PROPERTY}, replacing the packages added there`;
|
|
42574
42622
|
/** Where the line holding `offset` starts. */
|
|
42575
42623
|
const lineStart = (source, offset) => source.lastIndexOf("\n", offset - 1) + 1;
|
|
42576
42624
|
/** The whitespace a line opens with, for the line holding `offset`. */
|
|
@@ -42751,7 +42799,7 @@ const TOP_LEVEL_SETTINGS = [
|
|
|
42751
42799
|
"transpilePackages",
|
|
42752
42800
|
"experimental"
|
|
42753
42801
|
];
|
|
42754
|
-
const EXPERIMENTAL_SETTINGS = ["optimizePackageImports",
|
|
42802
|
+
const EXPERIMENTAL_SETTINGS = ["optimizePackageImports", LEGACY_PROPERTY];
|
|
42755
42803
|
/** Why an object might set one of `names` where this cannot read it, or null. */
|
|
42756
42804
|
function hiddenSettings(object, names, where) {
|
|
42757
42805
|
return object.properties.some((property) => mayHide(property, names)) ? `${where} spreads another object or has a computed or accessor property, which may set ${names.join(", ")}` : null;
|
|
@@ -42809,41 +42857,43 @@ function fillEmptyList(source, array, entries) {
|
|
|
42809
42857
|
* so the app's own properties keep their order and their comments.
|
|
42810
42858
|
*/
|
|
42811
42859
|
function addListProperty(source, object, entries) {
|
|
42860
|
+
return appendProperties(source, object, (indent, ownLines) => [ownLines ? `${PROPERTY}: [\n${entries.map((entry) => `${indent} ${entry},\n`).join("")}${indent}]` : `${PROPERTY}: [${entries.join(", ")}]`]);
|
|
42861
|
+
}
|
|
42862
|
+
/**
|
|
42863
|
+
* Add properties after an object's last one, in the object's layout: on one
|
|
42864
|
+
* line, as `{ a: 1, b: 2 }`, when it is written that way, and otherwise one
|
|
42865
|
+
* per line at the indentation its properties use, before the closing brace,
|
|
42866
|
+
* with a comma put after the last property first when it has none.
|
|
42867
|
+
* `properties` gets that indentation, and whether each property has a line
|
|
42868
|
+
* of its own, so a property spanning lines can follow the same layout.
|
|
42869
|
+
*/
|
|
42870
|
+
function appendProperties(source, object, properties) {
|
|
42812
42871
|
const open = (object.start ?? 0) + 1;
|
|
42813
42872
|
const close = (object.end ?? 0) - 1;
|
|
42814
|
-
|
|
42873
|
+
if (!spansLines(source, open, close)) return [appendOnTheSameLine(object, properties("", false).join(", "))];
|
|
42874
|
+
const last = object.properties.at(-1);
|
|
42875
|
+
const indent = last ? indentAt(source, last.start ?? 0) : `${indentAt(source, close)} `;
|
|
42876
|
+
const lines = properties(indent, true).map((property) => `${indent}${property},\n`).join("");
|
|
42877
|
+
return [...last !== void 0 && !/^\s*,/.test(source.slice(last.end ?? 0, close)) ? [{
|
|
42878
|
+
at: last.end ?? 0,
|
|
42879
|
+
remove: 0,
|
|
42880
|
+
text: ","
|
|
42881
|
+
}] : [], beforeClosingBrace(source, close, lines)];
|
|
42815
42882
|
}
|
|
42816
|
-
/**
|
|
42817
|
-
function
|
|
42818
|
-
const property = `${PROPERTY}: [${entries.join(", ")}]`;
|
|
42883
|
+
/** Properties added to an object written on one line, as `{ a: 1, b: 2 }`. */
|
|
42884
|
+
function appendOnTheSameLine(object, text) {
|
|
42819
42885
|
const last = object.properties.at(-1);
|
|
42820
42886
|
const open = (object.start ?? 0) + 1;
|
|
42821
42887
|
return last ? {
|
|
42822
42888
|
at: last.end ?? 0,
|
|
42823
42889
|
remove: 0,
|
|
42824
|
-
text: `, ${
|
|
42890
|
+
text: `, ${text}`
|
|
42825
42891
|
} : {
|
|
42826
42892
|
at: open,
|
|
42827
42893
|
remove: (object.end ?? 0) - 1 - open,
|
|
42828
|
-
text: ` ${
|
|
42894
|
+
text: ` ${text} `
|
|
42829
42895
|
};
|
|
42830
42896
|
}
|
|
42831
|
-
/**
|
|
42832
|
-
* The list added as the last property of an object written over several
|
|
42833
|
-
* lines, one entry per line at the indentation the object's properties use.
|
|
42834
|
-
* A comma goes after the last property first when it has none.
|
|
42835
|
-
*/
|
|
42836
|
-
function listOnItsOwnLines(source, object, entries) {
|
|
42837
|
-
const close = (object.end ?? 0) - 1;
|
|
42838
|
-
const last = object.properties.at(-1);
|
|
42839
|
-
const indent = last ? indentAt(source, last.start ?? 0) : `${indentAt(source, close)} `;
|
|
42840
|
-
const list = `${indent}${PROPERTY}: [\n${entries.map((entry) => `${indent} ${entry},\n`).join("")}${indent}],\n`;
|
|
42841
|
-
return [...last !== void 0 && !/^\s*,/.test(source.slice(last.end ?? 0, close)) ? [{
|
|
42842
|
-
at: last.end ?? 0,
|
|
42843
|
-
remove: 0,
|
|
42844
|
-
text: ","
|
|
42845
|
-
}] : [], beforeClosingBrace(source, close, list)];
|
|
42846
|
-
}
|
|
42847
42897
|
/** Text put before an object's closing brace: on the line above it when the brace has a line of its own. */
|
|
42848
42898
|
function beforeClosingBrace(source, close, text) {
|
|
42849
42899
|
const closeLine = lineStart(source, close);
|
|
@@ -42931,7 +42981,7 @@ function conflictOf(object, required) {
|
|
|
42931
42981
|
}
|
|
42932
42982
|
/** Why the config's lists clash, given an `experimental` object it can read. */
|
|
42933
42983
|
function experimentalConflict(object, experimental, required) {
|
|
42934
|
-
if (propertyValue(experimental,
|
|
42984
|
+
if (propertyValue(experimental, LEGACY_PROPERTY)) return LEGACY_LIST_REASON;
|
|
42935
42985
|
return clashReason("transpilePackages", object, "transpilePackages", required) ?? clashReason("experimental.optimizePackageImports", experimental, "optimizePackageImports", required);
|
|
42936
42986
|
}
|
|
42937
42987
|
/** The object literal the file exports as its config, or why there is none to edit. */
|
|
@@ -43001,58 +43051,6 @@ function editConfig(source, file, required) {
|
|
|
43001
43051
|
added: plan.added
|
|
43002
43052
|
};
|
|
43003
43053
|
}
|
|
43004
|
-
/** The string at `keys` inside a parsed JSON file, or null. */
|
|
43005
|
-
function stringAt(json, keys) {
|
|
43006
|
-
let value = json;
|
|
43007
|
-
for (const key of keys) {
|
|
43008
|
-
if (typeof value !== "object" || value === null || !(key in value)) return null;
|
|
43009
|
-
value = value[key];
|
|
43010
|
-
}
|
|
43011
|
-
return typeof value === "string" ? value : null;
|
|
43012
|
-
}
|
|
43013
|
-
/** A JSON file of the app's, or null when it is missing or does not parse. */
|
|
43014
|
-
async function readJsonOrNull(file) {
|
|
43015
|
-
try {
|
|
43016
|
-
return await import_lib$1.default.readJson(file);
|
|
43017
|
-
} catch {
|
|
43018
|
-
return null;
|
|
43019
|
-
}
|
|
43020
|
-
}
|
|
43021
|
-
/**
|
|
43022
|
-
* A version range that admits one major only, such as `^15.1.0`, `~16.0`,
|
|
43023
|
-
* `15.x` or `16.0.0-canary.3`, with the major it admits. A range such as
|
|
43024
|
-
* `>=14`, `14 || 15` or `latest` admits several, or names none.
|
|
43025
|
-
*/
|
|
43026
|
-
const SINGLE_MAJOR = /^[\^~]?(\d+)(?:\.(?:\d+|[xX*])){0,2}(?:-[\w.]+)?$/;
|
|
43027
|
-
/**
|
|
43028
|
-
* The major version of the app's Next.js: the installed one, read from its
|
|
43029
|
-
* own `node_modules`, or else the one its package.json range admits when
|
|
43030
|
-
* that range admits a single major. Null when neither tells, as when
|
|
43031
|
-
* dependencies are not installed yet and the range is `latest`.
|
|
43032
|
-
*/
|
|
43033
|
-
async function nextMajor(cwd) {
|
|
43034
|
-
const installed = stringAt(await readJsonOrNull(path.join(cwd, "node_modules", "next", "package.json")), ["version"]);
|
|
43035
|
-
const manifest = await readJsonOrNull(path.join(cwd, "package.json"));
|
|
43036
|
-
const range = stringAt(manifest, ["dependencies", "next"]) ?? stringAt(manifest, ["devDependencies", "next"]);
|
|
43037
|
-
const match = SINGLE_MAJOR.exec((installed ?? range ?? "").trim());
|
|
43038
|
-
return match ? Number(match[1]) : null;
|
|
43039
|
-
}
|
|
43040
|
-
/**
|
|
43041
|
-
* Why the option cannot be written for the app's Next.js, and which spelling
|
|
43042
|
-
* to print instead, or null when it can. Next.js 14 reads the list under
|
|
43043
|
-
* another name, and an unknown version may be 14: writing the top-level list
|
|
43044
|
-
* there would report success and externalise nothing.
|
|
43045
|
-
*/
|
|
43046
|
-
function versionBlock(major) {
|
|
43047
|
-
if (major === null) return {
|
|
43048
|
-
reason: "the version of Next.js the app uses could not be read",
|
|
43049
|
-
spelling: "either"
|
|
43050
|
-
};
|
|
43051
|
-
return major < FIRST_TOP_LEVEL_MAJOR ? {
|
|
43052
|
-
reason: `the app runs Next.js ${major}, which reads the list as experimental.serverComponentsExternalPackages and runs instrumentation.ts only with experimental.instrumentationHook`,
|
|
43053
|
-
spelling: "legacy"
|
|
43054
|
-
} : null;
|
|
43055
|
-
}
|
|
43056
43054
|
/**
|
|
43057
43055
|
* The Next config file any advice about the app's config names: the one it
|
|
43058
43056
|
* has, or, when it has none, the one to create. `.mjs` is ESM whatever the
|
|
@@ -43104,14 +43102,6 @@ async function createNextConfig(cwd, database) {
|
|
|
43104
43102
|
async function patchNextConfig(cwd, database) {
|
|
43105
43103
|
const file = await findConfigFile(cwd);
|
|
43106
43104
|
const required = getServerExternalPackages(database);
|
|
43107
|
-
const blocked = versionBlock(await nextMajor(cwd));
|
|
43108
|
-
if (blocked) return {
|
|
43109
|
-
kind: "manual",
|
|
43110
|
-
file: file ?? await nextConfigFileToChange(cwd),
|
|
43111
|
-
packages: required,
|
|
43112
|
-
...blocked,
|
|
43113
|
-
...file ? {} : { create: true }
|
|
43114
|
-
};
|
|
43115
43105
|
if (!file) return createNextConfig(cwd, database);
|
|
43116
43106
|
const edited = editConfig(await import_lib$1.default.readFile(path.join(cwd, file), "utf-8"), file, required);
|
|
43117
43107
|
if ("reason" in edited) return {
|
|
@@ -43131,119 +43121,281 @@ async function patchNextConfig(cwd, database) {
|
|
|
43131
43121
|
added: edited.added
|
|
43132
43122
|
};
|
|
43133
43123
|
}
|
|
43134
|
-
/** The setting Nextly needs off, and the one Next.js accepts only with it on. */
|
|
43135
|
-
const CACHE_COMPONENTS = "cacheComponents";
|
|
43136
|
-
const PARTIAL_PREFETCHING = "partialPrefetching";
|
|
43137
43124
|
/**
|
|
43138
|
-
*
|
|
43139
|
-
*
|
|
43140
|
-
*
|
|
43125
|
+
* The exported config object, when every setting this edits can be read in
|
|
43126
|
+
* it; else why not. Not through a wrapper call: Next.js receives what the
|
|
43127
|
+
* wrapper returns, which may set an option again, so the literal passed in
|
|
43128
|
+
* says nothing final.
|
|
43141
43129
|
*/
|
|
43142
|
-
function
|
|
43143
|
-
const
|
|
43144
|
-
|
|
43145
|
-
|
|
43146
|
-
|
|
43147
|
-
|
|
43148
|
-
|
|
43149
|
-
|
|
43150
|
-
|
|
43151
|
-
|
|
43152
|
-
|
|
43153
|
-
|
|
43154
|
-
}
|
|
43155
|
-
|
|
43156
|
-
if (
|
|
43157
|
-
|
|
43158
|
-
|
|
43159
|
-
|
|
43160
|
-
|
|
43161
|
-
|
|
43162
|
-
|
|
43130
|
+
function cacheComponentsObject(body) {
|
|
43131
|
+
const object = exportedConfig(body, false);
|
|
43132
|
+
if (typeof object === "string") return object;
|
|
43133
|
+
return hiddenSettings(object, [...ON_OPTIONS, ...HANDLER_SETTINGS], "it") ?? object;
|
|
43134
|
+
}
|
|
43135
|
+
/**
|
|
43136
|
+
* How to turn one option on: the `false` to flip, the property to add when the
|
|
43137
|
+
* config does not set it, nothing when it is on, or why the value cannot be
|
|
43138
|
+
* read.
|
|
43139
|
+
*/
|
|
43140
|
+
function optionStep(object, name) {
|
|
43141
|
+
const value = propertyValue(object, name);
|
|
43142
|
+
if (!value) return { add: `${name}: true` };
|
|
43143
|
+
if (value.type !== "BooleanLiteral") return `its ${name} is not true or false written in place`;
|
|
43144
|
+
if (value.value) return {};
|
|
43145
|
+
return { flip: {
|
|
43146
|
+
at: value.start ?? 0,
|
|
43147
|
+
remove: (value.end ?? 0) - (value.start ?? 0),
|
|
43148
|
+
text: "true"
|
|
43149
|
+
} };
|
|
43150
|
+
}
|
|
43151
|
+
/**
|
|
43152
|
+
* Whether Node loads the config as an ES module, where `require` is not
|
|
43153
|
+
* defined: `.mjs` and `.mts` always, and `.js` when it imports or exports,
|
|
43154
|
+
* which a config in a package of `"type": "module"` must, and which Node
|
|
43155
|
+
* detects in any other. Next.js compiles `next.config.ts` to CommonJS.
|
|
43156
|
+
*/
|
|
43157
|
+
function loadsAsModule(file, body) {
|
|
43158
|
+
if (/\.m[jt]s$/.test(file)) return true;
|
|
43159
|
+
return file.endsWith(".js") && body.some((statement) => statement.type === "ImportDeclaration" || statement.type === "ExportDefaultDeclaration" || statement.type === "ExportNamedDeclaration" || statement.type === "ExportAllDeclaration");
|
|
43160
|
+
}
|
|
43161
|
+
/**
|
|
43162
|
+
* The name an ES module config imports `createRequire` under from
|
|
43163
|
+
* `node:module`, whatever it renamed it to, or null when it imports none.
|
|
43164
|
+
*/
|
|
43165
|
+
function createRequireImport(body) {
|
|
43166
|
+
return body.flatMap((statement) => statement.type === "ImportDeclaration" && (statement.source.value === "node:module" || statement.source.value === "module") ? statement.specifiers : []).find((item) => item.type === "ImportSpecifier" && importedName(item) === "createRequire")?.local.name ?? null;
|
|
43167
|
+
}
|
|
43168
|
+
/** The name an import specifier takes from its module, written plain or quoted. */
|
|
43169
|
+
function importedName(specifier) {
|
|
43170
|
+
const { imported } = specifier;
|
|
43171
|
+
return imported.type === "Identifier" ? imported.name : imported.value;
|
|
43172
|
+
}
|
|
43173
|
+
/** Whether the file binds `require` at its top level, by a declaration or an import. */
|
|
43174
|
+
function declaresRequire(body) {
|
|
43175
|
+
return body.some((statement) => importsRequire(statement) || declaresRequireVariable(statement));
|
|
43176
|
+
}
|
|
43177
|
+
/** Whether `statement` imports a binding named `require`: hoisted, so bound anywhere. */
|
|
43178
|
+
function importsRequire(statement) {
|
|
43179
|
+
return statement.type === "ImportDeclaration" && statement.specifiers.some((specifier) => isNamed(specifier.local, "require"));
|
|
43180
|
+
}
|
|
43181
|
+
/** The declarators in `statement` that name a variable `require`, exported or not. */
|
|
43182
|
+
function requireDeclarators(statement) {
|
|
43183
|
+
const declaration = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
|
|
43184
|
+
return declaration?.type === "VariableDeclaration" ? declaration.declarations.filter((declarator) => isNamed(declarator.id, "require")) : [];
|
|
43185
|
+
}
|
|
43186
|
+
/** Whether `statement` declares a variable named `require`, exported or not. */
|
|
43187
|
+
function declaresRequireVariable(statement) {
|
|
43188
|
+
return requireDeclarators(statement).length > 0;
|
|
43189
|
+
}
|
|
43190
|
+
/**
|
|
43191
|
+
* Whether the file binds `require` only by a variable declared after `at`,
|
|
43192
|
+
* where the config object starts. The object's `require.resolve` runs when
|
|
43193
|
+
* the object is evaluated, while that declaration is still in its temporal dead
|
|
43194
|
+
* zone, so it would throw: the lines are printed rather than written.
|
|
43195
|
+
*/
|
|
43196
|
+
function declaresRequireAfter(body, at) {
|
|
43197
|
+
if (body.some(importsRequire)) return false;
|
|
43198
|
+
const declarators = body.flatMap(requireDeclarators);
|
|
43199
|
+
return declarators.length > 0 && declarators.every((declarator) => (declarator.start ?? 0) >= at);
|
|
43200
|
+
}
|
|
43201
|
+
/**
|
|
43202
|
+
* What an ES module config needs at its top for the handlers' `require`:
|
|
43203
|
+
* nothing when it binds `require` already, the declaration alone, calling its
|
|
43204
|
+
* own `createRequire` by its name, when it imports one, and otherwise the
|
|
43205
|
+
* import and the declaration.
|
|
43206
|
+
*/
|
|
43207
|
+
function requireSetupFor(body) {
|
|
43208
|
+
if (declaresRequire(body)) return null;
|
|
43209
|
+
const imported = createRequireImport(body);
|
|
43210
|
+
return imported ? requireDeclaration(imported) : `${REQUIRE_IMPORT}\n\n${REQUIRE_DECLARATION}`;
|
|
43211
|
+
}
|
|
43212
|
+
/**
|
|
43213
|
+
* The edit that gives an ES module config `require`, before the first
|
|
43214
|
+
* statement that runs, and before the comments that lead it, such as a
|
|
43215
|
+
* `@type` annotation. Imports are hoisted, so one written further down still
|
|
43216
|
+
* loads first; the declaration is not, and a `require.resolve` evaluated
|
|
43217
|
+
* above it would throw.
|
|
43218
|
+
*/
|
|
43219
|
+
function requireEdit(source, body, setup) {
|
|
43220
|
+
const first = body.find((statement) => statement.type !== "ImportDeclaration");
|
|
43163
43221
|
return {
|
|
43164
|
-
at:
|
|
43165
|
-
remove:
|
|
43166
|
-
text:
|
|
43222
|
+
at: lineStart(source, first?.leadingComments?.[0]?.start ?? first?.start ?? 0),
|
|
43223
|
+
remove: 0,
|
|
43224
|
+
text: `${setup}\n\n`
|
|
43167
43225
|
};
|
|
43168
43226
|
}
|
|
43169
|
-
/**
|
|
43170
|
-
function
|
|
43171
|
-
|
|
43172
|
-
|
|
43173
|
-
const
|
|
43174
|
-
|
|
43175
|
-
return hiddenSettings(object, [CACHE_COMPONENTS, PARTIAL_PREFETCHING], "it") ?? object;
|
|
43227
|
+
/** Whether `node` is `require.resolve("<specifier>")`. */
|
|
43228
|
+
function resolvesTo(node, specifier) {
|
|
43229
|
+
if (node?.type !== "CallExpression") return false;
|
|
43230
|
+
const { callee, arguments: args } = node;
|
|
43231
|
+
const [only] = args;
|
|
43232
|
+
return callee.type === "MemberExpression" && isNamed(callee.object, "require") && isNamed(callee.property, "resolve") && args.length === 1 && only?.type === "StringLiteral" && only.value === specifier;
|
|
43176
43233
|
}
|
|
43177
|
-
/**
|
|
43178
|
-
function
|
|
43179
|
-
const
|
|
43180
|
-
|
|
43181
|
-
|
|
43182
|
-
return value.value ? value : null;
|
|
43234
|
+
/** Whether the config's cache settings are Nextly's handlers, as this writes them. */
|
|
43235
|
+
function hasNextlysHandlers(object) {
|
|
43236
|
+
const handlers = propertyValue(object, "cacheHandlers");
|
|
43237
|
+
const memory = propertyValue(object, "cacheMaxMemorySize");
|
|
43238
|
+
return resolvesTo(propertyValue(object, "cacheHandler"), "nextly/cache-handler") && handlers?.type === "ObjectExpression" && resolvesTo(propertyValue(handlers, "default"), "nextly/cache-handlers") && memory?.type === "NumericLiteral" && memory.value === 0;
|
|
43183
43239
|
}
|
|
43184
|
-
/** The
|
|
43185
|
-
|
|
43186
|
-
|
|
43187
|
-
|
|
43188
|
-
const value =
|
|
43189
|
-
|
|
43190
|
-
|
|
43240
|
+
/** The settings that make a cache of the app's own: a handler for either cache. */
|
|
43241
|
+
const OWN_CACHE_SETTINGS = ["cacheHandler", "cacheHandlers"];
|
|
43242
|
+
/** Whether the config gives `name` a value: written, and not `undefined`. */
|
|
43243
|
+
function setsValue(object, name) {
|
|
43244
|
+
const value = propertyValue(object, name);
|
|
43245
|
+
return value !== void 0 && !isNamed(value, "undefined");
|
|
43246
|
+
}
|
|
43247
|
+
/**
|
|
43248
|
+
* Why Nextly's handlers cannot go into this config as it stands, or null when
|
|
43249
|
+
* they can. A setting written as `undefined` is a placeholder to fill, not a
|
|
43250
|
+
* value; a handler of the app's own is not replaced; and `cacheMaxMemorySize`
|
|
43251
|
+
* must be 0, so Next.js keeps no second copy of the handlers' entries.
|
|
43252
|
+
*/
|
|
43253
|
+
function handlerConflict(object) {
|
|
43254
|
+
const placeholders = HANDLER_SETTINGS.filter((name) => propertyValue(object, name) !== void 0 && !setsValue(object, name));
|
|
43255
|
+
if (placeholders.length > 0) return `it sets ${placeholders.join(", ")} to undefined`;
|
|
43256
|
+
const own = OWN_CACHE_SETTINGS.filter((name) => setsValue(object, name));
|
|
43257
|
+
if (own.length > 0) return `it has cache handlers of its own (${own.join(", ")}), which were kept`;
|
|
43258
|
+
const memory = propertyValue(object, "cacheMaxMemorySize");
|
|
43259
|
+
return memory && !(memory.type === "NumericLiteral" && memory.value === 0) ? "it sets cacheMaxMemorySize to a value other than 0, which Nextly's handlers need so that Next.js keeps no second copy of their entries" : null;
|
|
43260
|
+
}
|
|
43261
|
+
/**
|
|
43262
|
+
* How to install Nextly's cache handlers: the properties to add and any edit
|
|
43263
|
+
* that gives the file `require`, or why they are left out, with the lines to
|
|
43264
|
+
* put in place of the config's own settings.
|
|
43265
|
+
*/
|
|
43266
|
+
function handlerStep(source, object, body, esm) {
|
|
43267
|
+
const none = {
|
|
43268
|
+
add: [],
|
|
43269
|
+
edits: []
|
|
43270
|
+
};
|
|
43271
|
+
if (hasNextlysHandlers(object)) return {
|
|
43272
|
+
...none,
|
|
43273
|
+
outcome: "present"
|
|
43274
|
+
};
|
|
43275
|
+
const setup = esm ? requireSetupFor(body) : null;
|
|
43276
|
+
const conflict = esm && declaresRequireAfter(body, object.start ?? 0) ? "it declares require after its config object, so the handlers' require.resolve would run before require exists; move that declaration above the object" : handlerConflict(object);
|
|
43277
|
+
if (conflict) return {
|
|
43278
|
+
...none,
|
|
43279
|
+
outcome: {
|
|
43280
|
+
skipped: conflict,
|
|
43281
|
+
lines: HANDLER_PROPERTIES,
|
|
43282
|
+
requireSetup: setup
|
|
43283
|
+
}
|
|
43284
|
+
};
|
|
43285
|
+
const memorySet = propertyValue(object, "cacheMaxMemorySize") !== void 0;
|
|
43286
|
+
const add = HANDLER_PROPERTIES.filter((property) => !(memorySet && property.startsWith("cacheMaxMemorySize")));
|
|
43287
|
+
if (setup === null) return {
|
|
43288
|
+
add,
|
|
43191
43289
|
edits: [],
|
|
43192
|
-
|
|
43290
|
+
outcome: "added"
|
|
43193
43291
|
};
|
|
43194
|
-
|
|
43195
|
-
|
|
43196
|
-
|
|
43197
|
-
|
|
43292
|
+
if (referenceCount("require", body) > 0 || createRequireImport(body) === null && referenceCount("createRequire", body) > 0) return {
|
|
43293
|
+
...none,
|
|
43294
|
+
outcome: {
|
|
43295
|
+
skipped: "it is an ES module that uses require, or a createRequire not imported from node:module, without binding require, so the lines that define it could clash",
|
|
43296
|
+
lines: add,
|
|
43297
|
+
requireSetup: setup
|
|
43298
|
+
}
|
|
43299
|
+
};
|
|
43300
|
+
return {
|
|
43301
|
+
add,
|
|
43302
|
+
edits: [requireEdit(source, body, setup)],
|
|
43303
|
+
outcome: "added"
|
|
43198
43304
|
};
|
|
43199
|
-
|
|
43305
|
+
}
|
|
43306
|
+
/** The edits that turn Cache Components on in a config, or why it cannot be changed. */
|
|
43307
|
+
function cacheComponentsPlan(source, file, esm) {
|
|
43308
|
+
const body = parseBody(source, file);
|
|
43309
|
+
if (!body) return { reason: "it could not be parsed" };
|
|
43310
|
+
const object = cacheComponentsObject(body);
|
|
43311
|
+
if (typeof object === "string") return { reason: object };
|
|
43312
|
+
const options = optionsPlan(object);
|
|
43313
|
+
if ("reason" in options) return options;
|
|
43314
|
+
const handlers = handlerStep(source, object, body, esm);
|
|
43315
|
+
const add = [...options.add, ...handlers.add];
|
|
43316
|
+
const edits = [...options.flips, ...handlers.edits];
|
|
43317
|
+
if (add.length > 0) edits.push(...appendProperties(source, object, () => add));
|
|
43200
43318
|
return {
|
|
43201
|
-
edits
|
|
43202
|
-
|
|
43319
|
+
edits,
|
|
43320
|
+
turnedOn: options.turnedOn,
|
|
43321
|
+
handlers: handlers.outcome
|
|
43203
43322
|
};
|
|
43204
43323
|
}
|
|
43205
|
-
/**
|
|
43206
|
-
function
|
|
43207
|
-
const
|
|
43208
|
-
|
|
43324
|
+
/** How to turn both options on: the values to flip, the properties to add, and which options change. */
|
|
43325
|
+
function optionsPlan(object) {
|
|
43326
|
+
const plan = {
|
|
43327
|
+
flips: [],
|
|
43328
|
+
add: [],
|
|
43329
|
+
turnedOn: []
|
|
43330
|
+
};
|
|
43331
|
+
for (const option of ON_OPTIONS) {
|
|
43332
|
+
const step = optionStep(object, option);
|
|
43333
|
+
if (typeof step === "string") return { reason: step };
|
|
43334
|
+
if (step.flip) plan.flips.push(step.flip);
|
|
43335
|
+
if (step.add) plan.add.push(step.add);
|
|
43336
|
+
if (step.flip || step.add) plan.turnedOn.push(option);
|
|
43337
|
+
}
|
|
43338
|
+
return plan;
|
|
43209
43339
|
}
|
|
43210
43340
|
/**
|
|
43211
|
-
* Turn Next.js Cache Components
|
|
43212
|
-
*
|
|
43341
|
+
* Turn Next.js Cache Components and Partial Prefetching on in an existing
|
|
43342
|
+
* app's config, with Nextly's cache handlers: Nextly runs with both on.
|
|
43343
|
+
* Apps that an earlier Nextly release turned off are turned on again.
|
|
43213
43344
|
*
|
|
43214
|
-
* Only
|
|
43215
|
-
*
|
|
43216
|
-
*
|
|
43217
|
-
* and reads as off; anything else is left as it was, with what to change.
|
|
43345
|
+
* Only settings written in place as `true` or `false`, or absent, are
|
|
43346
|
+
* changed; a value this cannot read leaves the file as it was, with what to
|
|
43347
|
+
* add. The edit is trusted only once the result parses and reads as on.
|
|
43218
43348
|
*/
|
|
43219
|
-
async function
|
|
43220
|
-
const file = await
|
|
43221
|
-
|
|
43222
|
-
|
|
43223
|
-
|
|
43349
|
+
async function turnOnCacheComponents(cwd) {
|
|
43350
|
+
const file = await nextConfigFileToChange(cwd);
|
|
43351
|
+
const source = await import_lib$1.default.readFile(path.join(cwd, file), "utf-8").catch(() => null);
|
|
43352
|
+
if (source === null) return {
|
|
43353
|
+
kind: "manual",
|
|
43354
|
+
file,
|
|
43355
|
+
reason: "the app has no Next config",
|
|
43356
|
+
requireSetup: loadsAsModule(file, []) ? requireSetupFor([]) : null
|
|
43357
|
+
};
|
|
43358
|
+
const body = parseBody(source, file);
|
|
43359
|
+
if (!body) return {
|
|
43360
|
+
kind: "manual",
|
|
43361
|
+
file,
|
|
43362
|
+
reason: "it could not be parsed",
|
|
43363
|
+
requireSetup: loadsAsModule(file, []) ? requireSetupFor([]) : null
|
|
43364
|
+
};
|
|
43365
|
+
const esm = loadsAsModule(file, body);
|
|
43366
|
+
const requireSetup = esm ? requireSetupFor(body) : null;
|
|
43367
|
+
const plan = cacheComponentsPlan(source, file, esm);
|
|
43224
43368
|
if ("reason" in plan) return {
|
|
43225
43369
|
kind: "manual",
|
|
43226
43370
|
file,
|
|
43227
|
-
reason: plan.reason
|
|
43371
|
+
reason: plan.reason,
|
|
43372
|
+
requireSetup
|
|
43373
|
+
};
|
|
43374
|
+
if (plan.edits.length === 0) return {
|
|
43375
|
+
kind: "unchanged",
|
|
43376
|
+
file,
|
|
43377
|
+
handlers: plan.handlers
|
|
43228
43378
|
};
|
|
43229
|
-
if (plan.edits.length === 0) return { kind: "unchanged" };
|
|
43230
43379
|
const text = applyEdits(source, plan.edits);
|
|
43231
|
-
const recheck = cacheComponentsPlan(text, file);
|
|
43232
|
-
if ("reason" in recheck || recheck.edits.length > 0
|
|
43380
|
+
const recheck = cacheComponentsPlan(text, file, esm);
|
|
43381
|
+
if ("reason" in recheck || recheck.edits.length > 0) return {
|
|
43233
43382
|
kind: "manual",
|
|
43234
43383
|
file,
|
|
43235
|
-
reason: "the edit could not be confirmed"
|
|
43384
|
+
reason: "the edit could not be confirmed",
|
|
43385
|
+
requireSetup
|
|
43236
43386
|
};
|
|
43237
43387
|
await import_lib$1.default.writeFile(path.join(cwd, file), text, "utf-8");
|
|
43238
43388
|
return {
|
|
43239
|
-
kind: "turned-
|
|
43389
|
+
kind: "turned-on",
|
|
43240
43390
|
file,
|
|
43241
|
-
|
|
43391
|
+
turnedOn: plan.turnedOn,
|
|
43392
|
+
handlers: plan.handlers
|
|
43242
43393
|
};
|
|
43243
43394
|
}
|
|
43244
43395
|
/**
|
|
43245
|
-
* What turning Cache Components
|
|
43246
|
-
* a notice saying why, or, for a config it could not change,
|
|
43396
|
+
* What turning Cache Components on did, for the run's report: each change and
|
|
43397
|
+
* a notice saying why, or, for a config it could not change, the exact lines
|
|
43398
|
+
* to add.
|
|
43247
43399
|
*/
|
|
43248
43400
|
function cacheComponentsFiles(patch) {
|
|
43249
43401
|
const files = {
|
|
@@ -43251,43 +43403,42 @@ function cacheComponentsFiles(patch) {
|
|
|
43251
43403
|
changed: [],
|
|
43252
43404
|
skipped: []
|
|
43253
43405
|
};
|
|
43254
|
-
if (patch.kind === "
|
|
43406
|
+
if (patch.kind === "manual") {
|
|
43407
|
+
files.skipped.push({
|
|
43408
|
+
path: patch.file,
|
|
43409
|
+
why: `Cache Components was not turned on: ${patch.reason}. Nextly runs with Cache Components and Partial Prefetching on, with its cache handlers (${CACHE_COMPONENTS_DOCS_URL}); add these to the config object Next.js receives, in place of any value of theirs`,
|
|
43410
|
+
toAdd: linesToAdd$1(ON_LINES, patch.requireSetup)
|
|
43411
|
+
});
|
|
43412
|
+
return files;
|
|
43413
|
+
}
|
|
43414
|
+
const handlersAdded = patch.handlers === "added";
|
|
43415
|
+
if (patch.kind === "turned-on") {
|
|
43255
43416
|
files.changed.push({
|
|
43256
43417
|
path: patch.file,
|
|
43257
|
-
added: [`${
|
|
43418
|
+
added: [...patch.turnedOn.map((option) => `${option}: true`), ...handlersAdded ? [...HANDLER_SETTINGS] : []]
|
|
43258
43419
|
});
|
|
43259
|
-
const
|
|
43260
|
-
files.notices = [`
|
|
43261
|
-
}
|
|
43420
|
+
const done = [...patch.turnedOn.length > 0 ? [`turned ${patch.turnedOn.join(" and ")} on`] : [], ...handlersAdded ? ["installed Nextly's cache handlers"] : []].join(" and ");
|
|
43421
|
+
files.notices = [`In ${patch.file}, ${done}: Nextly runs with Cache Components and Partial Prefetching on. What each setting does: ${CACHE_COMPONENTS_DOCS_URL}`];
|
|
43422
|
+
}
|
|
43423
|
+
if (typeof patch.handlers === "object") files.skipped.push({
|
|
43262
43424
|
path: patch.file,
|
|
43263
|
-
why: `Nextly
|
|
43264
|
-
toAdd: ` ${
|
|
43425
|
+
why: `Nextly's cache handlers were not added: ${patch.handlers.skipped}. Without them a page read right after a write can show the previous version once, and in production every cached public read refreshes within a minute of a visit, since a write from another instance, the CLI or a job reaches no other cache (${CACHE_COMPONENTS_DOCS_URL}); to use them, put these in place of the config's own cache settings`,
|
|
43426
|
+
toAdd: linesToAdd$1(patch.handlers.lines.map((property) => ` ${property},`), patch.handlers.requireSetup)
|
|
43265
43427
|
});
|
|
43266
43428
|
return files;
|
|
43267
43429
|
}
|
|
43268
43430
|
/**
|
|
43269
|
-
*
|
|
43270
|
-
*
|
|
43271
|
-
* On Next.js 14 the package list and the instrumentation opt-in are keys of
|
|
43272
|
-
* one `experimental` object, so they are given as one: two `experimental`
|
|
43273
|
-
* properties, pasted as given, leave only the second. The instrumentation
|
|
43274
|
-
* hook Nextly starts from needs the opt-in there, and no other step says so.
|
|
43275
|
-
* `wrap` turns each spelling into what to paste: the key itself, or a whole
|
|
43276
|
-
* config file when the app has none.
|
|
43277
|
-
*/
|
|
43278
|
-
function optionText(packages, spelling, wrap = (option) => option) {
|
|
43279
|
-
const list = packages.map((name) => JSON.stringify(name)).join(", ");
|
|
43280
|
-
const current = wrap(` ${PROPERTY}: [${list}],`);
|
|
43281
|
-
const legacy = wrap(` experimental: { instrumentationHook: true, serverComponentsExternalPackages: [${list}] },`);
|
|
43282
|
-
if (spelling === "legacy") return legacy;
|
|
43283
|
-
return spelling === "either" ? `On Next.js 15 or later:\n\n${current}\n\nOn Next.js 14:\n\n${legacy}` : current;
|
|
43284
|
-
}
|
|
43285
|
-
/**
|
|
43286
|
-
* A whole config holding `option`, for an app that has none. ESM in `.mjs`,
|
|
43287
|
-
* which loads whatever the package's own "type" says.
|
|
43431
|
+
* The config lines to add by hand. An ES module config with no `require`
|
|
43432
|
+
* also gets the lines that define it for the handlers, at the top of the file.
|
|
43288
43433
|
*/
|
|
43289
|
-
function
|
|
43290
|
-
|
|
43434
|
+
function linesToAdd$1(lines, requireSetup) {
|
|
43435
|
+
const config = lines.join("\n");
|
|
43436
|
+
return requireSetup ? `// At the top of the file:\n${requireSetup.replace("\n\n", "\n")}\n\n// In the config object:\n${config}` : config;
|
|
43437
|
+
}
|
|
43438
|
+
/** What to add by hand: the list, as the config's top-level option. */
|
|
43439
|
+
function optionText(packages) {
|
|
43440
|
+
const list = packages.map((name) => JSON.stringify(name)).join(", ");
|
|
43441
|
+
return ` ${PROPERTY}: [${list}],`;
|
|
43291
43442
|
}
|
|
43292
43443
|
/**
|
|
43293
43444
|
* What a patch did, in the shape every existing-app step reports in: the
|
|
@@ -43311,109 +43462,14 @@ function nextConfigFiles(patch) {
|
|
|
43311
43462
|
files.written.push(patch.file);
|
|
43312
43463
|
break;
|
|
43313
43464
|
case "unchanged": break;
|
|
43314
|
-
case "manual": files.skipped.push(
|
|
43465
|
+
case "manual": files.skipped.push({
|
|
43315
43466
|
path: patch.file,
|
|
43316
|
-
why: `Nextly's packages were not added: ${patch.reason}, and the
|
|
43317
|
-
toAdd: optionText(patch.packages
|
|
43318
|
-
} : {
|
|
43319
|
-
path: patch.file,
|
|
43320
|
-
why: `Nextly's packages were not added: ${patch.reason}. Add them to the config object it exports, keeping any packages and experimental keys already there`,
|
|
43321
|
-
toAdd: optionText(patch.packages, patch.spelling)
|
|
43467
|
+
why: patch.reason === LEGACY_LIST_REASON ? `Nextly's packages were not added: ${patch.reason}. Move the packages under experimental.${LEGACY_PROPERTY} into a top-level ${PROPERTY} list, add Nextly's to it, and delete experimental.${LEGACY_PROPERTY}, keeping the config's other experimental keys` : `Nextly's packages were not added: ${patch.reason}. Add them to the config object it exports, keeping any packages and experimental keys already there`,
|
|
43468
|
+
toAdd: optionText(patch.packages)
|
|
43322
43469
|
});
|
|
43323
43470
|
}
|
|
43324
43471
|
return files;
|
|
43325
43472
|
}
|
|
43326
|
-
// src/generators/page-extensions.ts
|
|
43327
|
-
/**
|
|
43328
|
-
* The page extension to name a new module file with, a hook or a route: a
|
|
43329
|
-
* TypeScript one first, since Nextly's files are TypeScript, then a
|
|
43330
|
-
* JavaScript one; never a content extension such as `mdx`, which Next.js
|
|
43331
|
-
* would compile as content, and never `cjs`, since the files are ES modules
|
|
43332
|
-
* and a `.cjs` file cannot hold one. Null when the list holds no extension a
|
|
43333
|
-
* module can be written in.
|
|
43334
|
-
*/
|
|
43335
|
-
function moduleExtension(extensions) {
|
|
43336
|
-
const usable = writable(extensions);
|
|
43337
|
-
return usable.find((extension) => /(^|\.)tsx?$/.test(extension)) ?? usable.find((extension) => /(^|\.)(js|jsx|mjs)$/.test(extension)) ?? null;
|
|
43338
|
-
}
|
|
43339
|
-
/**
|
|
43340
|
-
* The extensions a file with code in it can be written under: not a
|
|
43341
|
-
* declaration file's (`d.ts`, `d.mts`, `d.cts`), which TypeScript reads as
|
|
43342
|
-
* types only and refuses code in.
|
|
43343
|
-
*/
|
|
43344
|
-
function writable(extensions) {
|
|
43345
|
-
return extensions.filter((extension) => !/(^|\.)d\.[cm]?tsx?$/.test(extension));
|
|
43346
|
-
}
|
|
43347
|
-
/**
|
|
43348
|
-
* The `pageExtensions` the app's Next.js config sets, as every existing-app
|
|
43349
|
-
* step that names a file Next.js routes reads it: the list; `"absent"` when
|
|
43350
|
-
* the config sets none, or there is no config; or null when it is set in a
|
|
43351
|
-
* way that cannot be read. Read from the config the app exports, as the Next
|
|
43352
|
-
* config step reads it, so a commented-out or nested `pageExtensions` sets
|
|
43353
|
-
* nothing. `configName` is the file it was read from, for the report.
|
|
43354
|
-
*/
|
|
43355
|
-
async function appPageExtensions(cwd) {
|
|
43356
|
-
const nextConfig = await readNextConfig(cwd);
|
|
43357
|
-
return {
|
|
43358
|
-
configName: nextConfig?.name ?? "The Next.js config",
|
|
43359
|
-
extensions: nextConfig ? configStringList(nextConfig.text, nextConfig.name, "pageExtensions") : "absent"
|
|
43360
|
-
};
|
|
43361
|
-
}
|
|
43362
|
-
/**
|
|
43363
|
-
* The text of the app's Next.js config, or null when it has none, from the
|
|
43364
|
-
* file the Next config step reads and extends ({@link findConfigFile}).
|
|
43365
|
-
*/
|
|
43366
|
-
async function readNextConfig(cwd) {
|
|
43367
|
-
const name = await findConfigFile(cwd);
|
|
43368
|
-
return name === null ? null : {
|
|
43369
|
-
name,
|
|
43370
|
-
text: await import_lib$1.default.readFile(path.join(cwd, name), "utf-8")
|
|
43371
|
-
};
|
|
43372
|
-
}
|
|
43373
|
-
/**
|
|
43374
|
-
* The page extension for a file of TypeScript with JSX, such as a page or a
|
|
43375
|
-
* layout: one ending in `tsx`. Null when the list holds none.
|
|
43376
|
-
*/
|
|
43377
|
-
function tsxExtension(extensions) {
|
|
43378
|
-
return writable(extensions).find((extension) => /(^|\.)tsx$/.test(extension)) ?? null;
|
|
43379
|
-
}
|
|
43380
|
-
/** A JavaScript or TypeScript module without JSX, such as a route. */
|
|
43381
|
-
const MODULE_FILE = {
|
|
43382
|
-
pick: moduleExtension,
|
|
43383
|
-
holds: "a JavaScript or TypeScript extension"
|
|
43384
|
-
};
|
|
43385
|
-
/** TypeScript with JSX, such as a page or a layout. */
|
|
43386
|
-
const TSX_FILE = {
|
|
43387
|
-
pick: tsxExtension,
|
|
43388
|
-
holds: "an extension ending in tsx"
|
|
43389
|
-
};
|
|
43390
|
-
/**
|
|
43391
|
-
* The report for a file an app that sets `pageExtensions` gets in place of
|
|
43392
|
-
* the file: the name to create it under and its content. Next.js routes a
|
|
43393
|
-
* file there only under a name with one of the app's extensions, and the app
|
|
43394
|
-
* may already have the file under such a name, which the existing-app steps
|
|
43395
|
-
* do not look for, so nothing is written. A list that cannot be read, or that
|
|
43396
|
-
* holds no extension the content needs, gives a placeholder name and says
|
|
43397
|
-
* which.
|
|
43398
|
-
*
|
|
43399
|
-
* @param base the file's path without its extension, as reported, such as
|
|
43400
|
-
* `app/admin/[[...params]]/page`
|
|
43401
|
-
*/
|
|
43402
|
-
function pageExtensionsSkip(base, text, pages, need) {
|
|
43403
|
-
const { configName, extensions } = pages;
|
|
43404
|
-
const extension = extensions === null ? null : need.pick(extensions);
|
|
43405
|
-
const sets = `${configName} sets pageExtensions, and Next.js routes a file there only under a name with one of them, so none was written`;
|
|
43406
|
-
if (extensions !== null && extension === null) return {
|
|
43407
|
-
path: `${base}.<${need.holds} added to pageExtensions>`,
|
|
43408
|
-
why: `${sets}, and none of them (${extensions.join(", ")}) is ${need.holds}; add one to pageExtensions, then, unless the app already has this file, create it under that name with this content`,
|
|
43409
|
-
toAdd: text
|
|
43410
|
-
};
|
|
43411
|
-
return {
|
|
43412
|
-
path: `${base}.${extension ?? "<one of your pageExtensions>"}`,
|
|
43413
|
-
why: `${sets}; unless the app already has this file, create it under that name with this content`,
|
|
43414
|
-
toAdd: text
|
|
43415
|
-
};
|
|
43416
|
-
}
|
|
43417
43473
|
// src/utils/detect-pm-from-user-agent.ts
|
|
43418
43474
|
/**
|
|
43419
43475
|
* Detect the package manager that invoked `create-nextly-app` by reading
|
|
@@ -45644,6 +45700,45 @@ function getDefaultApproach(name) {
|
|
|
45644
45700
|
function shouldUseBundledTemplate(projectType, options) {
|
|
45645
45701
|
return BUNDLED_TEMPLATES.some((name) => name === projectType) && !options.localTemplatePath && !options.useYalc && options.branch === void 0;
|
|
45646
45702
|
}
|
|
45703
|
+
// src/supported-versions.ts
|
|
45704
|
+
/**
|
|
45705
|
+
* The Next.js and React this release of Nextly supports, in one place.
|
|
45706
|
+
*
|
|
45707
|
+
* Two facts, deliberately kept apart:
|
|
45708
|
+
*
|
|
45709
|
+
* - `REVIEWED_VERSIONS` is the newest release of each package this Nextly
|
|
45710
|
+
* release was reviewed against. A new app declares it as a `~` range
|
|
45711
|
+
* ({@link scaffoldRange}): patch releases of that minor, never a newer minor
|
|
45712
|
+
* or major that nobody has checked, and never whatever npm's `latest` names
|
|
45713
|
+
* on the day of the scaffold.
|
|
45714
|
+
* - `SUPPORTED_RANGES` is every release Nextly works with: the `nextly`
|
|
45715
|
+
* package's own peer ranges, inlined at build, so they are declared once.
|
|
45716
|
+
* Every other package declares the same as its peers. Adding Nextly to an
|
|
45717
|
+
* existing app refuses one whose Next.js, React or React DOM falls outside
|
|
45718
|
+
* them, and a scaffolded plugin declares them as its own peers.
|
|
45719
|
+
*
|
|
45720
|
+
* Only a release review moves either: a newer Next.js or React is supported
|
|
45721
|
+
* once a Nextly release has been checked against it, not before.
|
|
45722
|
+
*/
|
|
45723
|
+
const REVIEWED_VERSIONS = {
|
|
45724
|
+
next: "16.4.2",
|
|
45725
|
+
"eslint-config-next": "16.4.2",
|
|
45726
|
+
react: "19.3.1",
|
|
45727
|
+
"react-dom": "19.3.1"
|
|
45728
|
+
};
|
|
45729
|
+
const SUPPORTED_RANGES = {
|
|
45730
|
+
"next": "^16.4.1",
|
|
45731
|
+
"react": "^19.3.0",
|
|
45732
|
+
"react-dom": "^19.3.0"
|
|
45733
|
+
};
|
|
45734
|
+
/**
|
|
45735
|
+
* The range a new project declares for `pkg`: patch releases of the reviewed
|
|
45736
|
+
* minor only. Derived here rather than written out, so the reviewed version is
|
|
45737
|
+
* the one thing a release review edits.
|
|
45738
|
+
*/
|
|
45739
|
+
function scaffoldRange(pkg) {
|
|
45740
|
+
return `~${REVIEWED_VERSIONS[pkg]}`;
|
|
45741
|
+
}
|
|
45647
45742
|
// src/utils/package-manager-commands.ts
|
|
45648
45743
|
/**
|
|
45649
45744
|
* The prefix that runs a package.json script.
|
|
@@ -45671,37 +45766,35 @@ function binaryRunner(packageManager) {
|
|
|
45671
45766
|
case "bun": return "bunx";
|
|
45672
45767
|
}
|
|
45673
45768
|
}
|
|
45674
|
-
// src/utils/
|
|
45675
|
-
/**
|
|
45676
|
-
* The Node versions a scaffolded plugin supports, and the check that refuses
|
|
45677
|
-
* to scaffold one on a Node it cannot build on.
|
|
45678
|
-
*
|
|
45679
|
-
* A plugin builds with tsdown and tests with Vitest, and each declares the
|
|
45680
|
-
* Node it runs on; the plugin's floor is where both agree. The repository's
|
|
45681
|
-
* packages have a lower floor, because only a plugin author runs these tools.
|
|
45682
|
-
* `scaffold-plugin.test.ts` derives this range from the installed tools' own
|
|
45683
|
-
* `engines`, so a version bump that moves either one fails there.
|
|
45684
|
-
*/
|
|
45685
|
-
const PLUGIN_NODE_ENGINES = "^22.18.0 || ^24.11.0 || >=26.0.0";
|
|
45769
|
+
// src/utils/version-range.ts
|
|
45686
45770
|
function parseVersion$1(text) {
|
|
45687
|
-
const match = /^v?(\d+)\.(\d+)\.(\d+)
|
|
45688
|
-
if (!match) throw new Error(`not a
|
|
45689
|
-
return [
|
|
45771
|
+
const match = /^v?(\d+)\.(\d+)\.(\d+)(-[0-9A-Za-z.-]+)?/.exec(text.trim());
|
|
45772
|
+
if (!match) throw new Error(`not a version: ${text}`);
|
|
45773
|
+
return Object.assign([
|
|
45690
45774
|
Number(match[1]),
|
|
45691
45775
|
Number(match[2]),
|
|
45692
45776
|
Number(match[3])
|
|
45693
|
-
];
|
|
45777
|
+
], { prerelease: match[4] !== void 0 });
|
|
45694
45778
|
}
|
|
45779
|
+
/** Older first; of two with the same numbers, a prerelease comes before its release, as in semver. */
|
|
45695
45780
|
function compare(a, b) {
|
|
45696
|
-
return a[0] - b[0] || a[1] - b[1] || a[2] - b[2];
|
|
45781
|
+
return a[0] - b[0] || a[1] - b[1] || a[2] - b[2] || Number(Boolean(b.prerelease)) - Number(Boolean(a.prerelease));
|
|
45697
45782
|
}
|
|
45698
45783
|
/**
|
|
45699
|
-
*
|
|
45700
|
-
*
|
|
45701
|
-
|
|
45784
|
+
* Negative when `a` is older than `b`, positive when newer, 0 when equal.
|
|
45785
|
+
* A prerelease is older than its release: `16.4.1-canary.1` is below `16.4.1`.
|
|
45786
|
+
*/
|
|
45787
|
+
function compareVersions(a, b) {
|
|
45788
|
+
return compare(parseVersion$1(a), parseVersion$1(b));
|
|
45789
|
+
}
|
|
45790
|
+
/**
|
|
45791
|
+
* Whether `version` satisfies one comparator. Only the two forms this CLI
|
|
45792
|
+
* writes are understood, `^X.Y.Z` and `>=X.Y.Z`; any other is refused rather
|
|
45793
|
+
* than read approximately, so a range that starts using another form fails
|
|
45702
45794
|
* the test that reads it.
|
|
45703
45795
|
*/
|
|
45704
45796
|
function satisfiesComparator(version, comparator) {
|
|
45797
|
+
if (version.prerelease) return false;
|
|
45705
45798
|
const caret = /^\^(\d+\.\d+\.\d+)$/.exec(comparator);
|
|
45706
45799
|
if (caret) {
|
|
45707
45800
|
const floor = parseVersion$1(caret[1]);
|
|
@@ -45709,21 +45802,83 @@ function satisfiesComparator(version, comparator) {
|
|
|
45709
45802
|
}
|
|
45710
45803
|
const atLeast = /^>=(\d+\.\d+\.\d+)$/.exec(comparator);
|
|
45711
45804
|
if (atLeast) return compare(version, parseVersion$1(atLeast[1])) >= 0;
|
|
45712
|
-
throw new Error(`unsupported
|
|
45805
|
+
throw new Error(`unsupported range comparator: ${comparator}`);
|
|
45713
45806
|
}
|
|
45714
45807
|
/** Whether `version` satisfies a `||` list of `^X.Y.Z` / `>=X.Y.Z` comparators. */
|
|
45715
|
-
function
|
|
45808
|
+
function satisfiesRange(version, range) {
|
|
45716
45809
|
const parsed = parseVersion$1(version);
|
|
45717
45810
|
return range.split("||").map((part) => part.trim()).some((comparator) => satisfiesComparator(parsed, comparator));
|
|
45718
45811
|
}
|
|
45719
45812
|
/**
|
|
45720
|
-
*
|
|
45721
|
-
* `undefined` when
|
|
45722
|
-
*
|
|
45813
|
+
* The lowest version a package.json dependency spec admits, as `X.Y.Z`, or
|
|
45814
|
+
* `undefined` when the spec names no lower bound this can read: a dist-tag
|
|
45815
|
+
* (`latest`, `canary`), a protocol (`workspace:*`, `file:`, a URL), `*`, or an
|
|
45816
|
+
* upper bound alone (`<17`). An exact version is its own lowest; `^`, `~`, `=`
|
|
45817
|
+
* and `>=` start at the version they name; a missing or wildcard minor or
|
|
45818
|
+
* patch (`15`, `15.x`) counts as 0; across `||` the lowest alternative wins.
|
|
45723
45819
|
*/
|
|
45724
|
-
function
|
|
45725
|
-
|
|
45726
|
-
|
|
45820
|
+
function lowestVersionIn(spec) {
|
|
45821
|
+
let lowest;
|
|
45822
|
+
for (const part of spec.split("||")) {
|
|
45823
|
+
const match = /^\s*(?:\^|~|>=|=)?\s*v?(\d+)(?:\.(\d+|[xX*]))?(?:\.(\d+|[xX*]))?/.exec(part);
|
|
45824
|
+
if (!match) continue;
|
|
45825
|
+
const number = (text) => text === void 0 || !/^\d+$/.test(text) ? 0 : Number(text);
|
|
45826
|
+
const found = [
|
|
45827
|
+
Number(match[1]),
|
|
45828
|
+
number(match[2]),
|
|
45829
|
+
number(match[3])
|
|
45830
|
+
];
|
|
45831
|
+
if (!lowest || compare(found, lowest) < 0) lowest = found;
|
|
45832
|
+
}
|
|
45833
|
+
return lowest ? lowest.join(".") : void 0;
|
|
45834
|
+
}
|
|
45835
|
+
/**
|
|
45836
|
+
* The highest major a package.json dependency spec admits, `Infinity` when it
|
|
45837
|
+
* has no upper bound (`>=16.4.1`, `*`, `x`), or `undefined` when no
|
|
45838
|
+
* alternative names one this can read (a dist-tag, a protocol). Across `||`
|
|
45839
|
+
* the highest alternative wins, since an install resolves the newest version
|
|
45840
|
+
* any of them admits. Within one alternative an upper bound (`<17`, `<=17.2`)
|
|
45841
|
+
* decides; otherwise the version a `^`, `~`, `=` or bare spec names.
|
|
45842
|
+
*/
|
|
45843
|
+
function highestMajorIn(spec) {
|
|
45844
|
+
let highest;
|
|
45845
|
+
for (const part of spec.split("||")) {
|
|
45846
|
+
const found = majorReachedBy(part.trim());
|
|
45847
|
+
if (found !== void 0 && (highest === void 0 || found > highest)) highest = found;
|
|
45848
|
+
}
|
|
45849
|
+
return highest;
|
|
45850
|
+
}
|
|
45851
|
+
/** The highest major one `||` alternative reaches, as `highestMajorIn` reads it. */
|
|
45852
|
+
function majorReachedBy(part) {
|
|
45853
|
+
const upper = /<(=)?\s*v?(\d+)(?:\.(\d+))?(?:\.(\d+))?/.exec(part);
|
|
45854
|
+
if (upper) {
|
|
45855
|
+
const [, inclusive, major, minor, patch] = upper;
|
|
45856
|
+
return inclusive !== void 0 || Number(minor ?? 0) > 0 || Number(patch ?? 0) > 0 ? Number(major) : Number(major) - 1;
|
|
45857
|
+
}
|
|
45858
|
+
if (part === "" || /^(\*|[xX])$/.test(part) || part.startsWith(">")) return Infinity;
|
|
45859
|
+
const named = /^(?:\^|~|=)?\s*v?(\d+)/.exec(part);
|
|
45860
|
+
return named ? Number(named[1]) : void 0;
|
|
45861
|
+
}
|
|
45862
|
+
// src/utils/plugin-node.ts
|
|
45863
|
+
/**
|
|
45864
|
+
* The Node versions a scaffolded plugin supports, and the check that refuses
|
|
45865
|
+
* to scaffold one on a Node it cannot build on.
|
|
45866
|
+
*
|
|
45867
|
+
* A plugin builds with tsdown and tests with Vitest, and each declares the
|
|
45868
|
+
* Node it runs on; the plugin's floor is where both agree. The repository's
|
|
45869
|
+
* packages have a lower floor, because only a plugin author runs these tools.
|
|
45870
|
+
* `scaffold-plugin.test.ts` derives this range from the installed tools' own
|
|
45871
|
+
* `engines`, so a version bump that moves either one fails there.
|
|
45872
|
+
*/
|
|
45873
|
+
const PLUGIN_NODE_ENGINES = "^22.18.0 || ^24.11.0 || >=26.0.0";
|
|
45874
|
+
/**
|
|
45875
|
+
* Why the plugin template cannot be scaffolded on `nodeVersion`, or
|
|
45876
|
+
* `undefined` when it can. Checked before anything is written, since a plugin
|
|
45877
|
+
* scaffolded on an older Node would install and then fail its first build.
|
|
45878
|
+
*/
|
|
45879
|
+
function pluginNodeRefusal(nodeVersion) {
|
|
45880
|
+
if (satisfiesRange(nodeVersion, "^22.18.0 || ^24.11.0 || >=26.0.0")) return void 0;
|
|
45881
|
+
return `The plugin template builds with tools that need Node ${PLUGIN_NODE_ENGINES}, and this is Node ${nodeVersion}. Install a supported Node (for example \`nvm install 24\`) and run create-nextly-app again.`;
|
|
45727
45882
|
}
|
|
45728
45883
|
// src/utils/template.ts
|
|
45729
45884
|
/**
|
|
@@ -46367,14 +46522,12 @@ async function replacePlaceholders(dir, placeholders, skip = /* @__PURE__ */ new
|
|
|
46367
46522
|
/**
|
|
46368
46523
|
* Pinned dependency versions for generated projects.
|
|
46369
46524
|
*
|
|
46370
|
-
* `next
|
|
46371
|
-
*
|
|
46372
|
-
*
|
|
46373
|
-
* wide semver ranges that rarely need updating.
|
|
46525
|
+
* `next`, `eslint-config-next`, `react` and `react-dom` are not here: they
|
|
46526
|
+
* come from `supported-versions`, the reviewed release of each, so a project
|
|
46527
|
+
* never declares a Next.js or React no Nextly release was checked against.
|
|
46528
|
+
* The remaining versions use wide semver ranges that rarely need updating.
|
|
46374
46529
|
*/
|
|
46375
46530
|
const PINNED_VERSIONS = {
|
|
46376
|
-
react: "^19.3.1",
|
|
46377
|
-
"react-dom": "^19.3.1",
|
|
46378
46531
|
typescript: "^5",
|
|
46379
46532
|
"@types/node": "^22",
|
|
46380
46533
|
"@types/react": "^19",
|
|
@@ -46392,11 +46545,6 @@ const PINNED_VERSIONS = {
|
|
|
46392
46545
|
*/
|
|
46393
46546
|
const CONFIG_TOOLING_DEV_DEPENDENCIES = [`esbuild@${PINNED_VERSIONS.esbuild}`];
|
|
46394
46547
|
/**
|
|
46395
|
-
* Packages whose latest version is fetched from the npm registry at
|
|
46396
|
-
* runtime so the CLI always scaffolds with the newest release.
|
|
46397
|
-
*/
|
|
46398
|
-
const RUNTIME_RESOLVED_PACKAGES = ["next", "eslint-config-next"];
|
|
46399
|
-
/**
|
|
46400
46548
|
* @nextlyhq packages whose latest version is fetched from npm at runtime.
|
|
46401
46549
|
* This avoids having to republish create-nextly-app every time a
|
|
46402
46550
|
* dependency package is updated.
|
|
@@ -46420,9 +46568,10 @@ const resolvedNextlyVersions = /* @__PURE__ */ new Map();
|
|
|
46420
46568
|
* On any failure (non-OK response, timeout, missing tag, thrown error) it
|
|
46421
46569
|
* returns the requested dist-tag NAME itself (e.g. "alpha") — a valid npm
|
|
46422
46570
|
* install spec — so a project on the alpha line never silently drops to
|
|
46423
|
-
* `latest`.
|
|
46571
|
+
* `latest`. The channel has no default: only the Nextly packages are read
|
|
46572
|
+
* from the registry, always on a tag their caller names.
|
|
46424
46573
|
*/
|
|
46425
|
-
async function fetchLatestVersion(pkg, channel
|
|
46574
|
+
async function fetchLatestVersion(pkg, channel) {
|
|
46426
46575
|
try {
|
|
46427
46576
|
const res = await fetch(`https://registry.npmjs.org/-/package/${encodeURIComponent(pkg)}/dist-tags`, { signal: AbortSignal.timeout(5e3) });
|
|
46428
46577
|
if (!res.ok) return channel;
|
|
@@ -46456,26 +46605,6 @@ async function nextlyVersions(source) {
|
|
|
46456
46605
|
if (source.kind === "release") return Object.fromEntries(NEXTLY_PACKAGES.map((pkg) => [pkg, source.cliVersion]));
|
|
46457
46606
|
return resolveNextlyVersions("alpha");
|
|
46458
46607
|
}
|
|
46459
|
-
/** Cache for runtime-resolved package versions (next, eslint-config-next). */
|
|
46460
|
-
let resolvedRuntimeVersions = null;
|
|
46461
|
-
/**
|
|
46462
|
-
* Resolve latest versions for Next.js ecosystem packages in parallel.
|
|
46463
|
-
* Falls back to a safe semver range if the registry is unreachable.
|
|
46464
|
-
*/
|
|
46465
|
-
async function resolveRuntimeVersions() {
|
|
46466
|
-
if (resolvedRuntimeVersions) return resolvedRuntimeVersions;
|
|
46467
|
-
const NEXT_FLOOR = "^16.4.1";
|
|
46468
|
-
const FALLBACKS = {
|
|
46469
|
-
next: NEXT_FLOOR,
|
|
46470
|
-
"eslint-config-next": NEXT_FLOOR
|
|
46471
|
-
};
|
|
46472
|
-
const entries = await Promise.all(RUNTIME_RESOLVED_PACKAGES.map(async (pkg) => {
|
|
46473
|
-
const version = await fetchLatestVersion(pkg);
|
|
46474
|
-
return [pkg, version === "latest" ? FALLBACKS[pkg] : version];
|
|
46475
|
-
}));
|
|
46476
|
-
resolvedRuntimeVersions = Object.fromEntries(entries);
|
|
46477
|
-
return resolvedRuntimeVersions;
|
|
46478
|
-
}
|
|
46479
46608
|
/**
|
|
46480
46609
|
* Generate a `package.json` string for a fresh Nextly project.
|
|
46481
46610
|
*
|
|
@@ -46494,11 +46623,10 @@ async function resolveRuntimeVersions() {
|
|
|
46494
46623
|
*/
|
|
46495
46624
|
async function generatePackageJson(projectName, database, source = nextlySource({ cliVersion: packageVersion() }), projectType = "blank", templateDirs = [], targetDir) {
|
|
46496
46625
|
if (projectType === "plugin") return generatePluginPackageJson(projectName, source);
|
|
46497
|
-
const runtimeVersions = await resolveRuntimeVersions();
|
|
46498
46626
|
const dependencies = {
|
|
46499
|
-
next:
|
|
46500
|
-
react:
|
|
46501
|
-
"react-dom":
|
|
46627
|
+
next: scaffoldRange("next"),
|
|
46628
|
+
react: scaffoldRange("react"),
|
|
46629
|
+
"react-dom": scaffoldRange("react-dom")
|
|
46502
46630
|
};
|
|
46503
46631
|
dependencies["@tanstack/react-query"] = "^5.62.0";
|
|
46504
46632
|
dependencies["lucide-react"] = "^0.544.0";
|
|
@@ -46522,7 +46650,7 @@ async function generatePackageJson(projectName, database, source = nextlySource(
|
|
|
46522
46650
|
"@tailwindcss/postcss": PINNED_VERSIONS["@tailwindcss/postcss"],
|
|
46523
46651
|
tailwindcss: PINNED_VERSIONS.tailwindcss,
|
|
46524
46652
|
eslint: PINNED_VERSIONS.eslint,
|
|
46525
|
-
"eslint-config-next":
|
|
46653
|
+
"eslint-config-next": scaffoldRange("eslint-config-next"),
|
|
46526
46654
|
esbuild: PINNED_VERSIONS.esbuild
|
|
46527
46655
|
};
|
|
46528
46656
|
const shipsSearchIndex = targetDir ? await projectHasSearchIndexScript(targetDir) : false;
|
|
@@ -46598,7 +46726,6 @@ async function resolvePluginNextlyRange(source) {
|
|
|
46598
46726
|
*/
|
|
46599
46727
|
async function generatePluginPackageJson(projectName, source) {
|
|
46600
46728
|
const versions = await nextlyVersions(source);
|
|
46601
|
-
const runtimeVersions = await resolveRuntimeVersions();
|
|
46602
46729
|
const range = (pkg) => versions[pkg] ?? "alpha";
|
|
46603
46730
|
const peerRange = (pkg) => pluginPeerRange(range(pkg), source.cliVersion);
|
|
46604
46731
|
const peerDependencies = {
|
|
@@ -46606,8 +46733,8 @@ async function generatePluginPackageJson(projectName, source) {
|
|
|
46606
46733
|
"@nextlyhq/admin": peerRange("@nextlyhq/admin"),
|
|
46607
46734
|
"@nextlyhq/plugin-sdk": peerRange("@nextlyhq/plugin-sdk"),
|
|
46608
46735
|
"@nextlyhq/ui": peerRange("@nextlyhq/ui"),
|
|
46609
|
-
react:
|
|
46610
|
-
"react-dom":
|
|
46736
|
+
react: SUPPORTED_RANGES.react,
|
|
46737
|
+
"react-dom": SUPPORTED_RANGES["react-dom"]
|
|
46611
46738
|
};
|
|
46612
46739
|
const devDependencies = {
|
|
46613
46740
|
nextly: range("nextly"),
|
|
@@ -46616,9 +46743,9 @@ async function generatePluginPackageJson(projectName, source) {
|
|
|
46616
46743
|
"@nextlyhq/plugin-sdk": range("@nextlyhq/plugin-sdk"),
|
|
46617
46744
|
"@nextlyhq/adapter-drizzle": range("@nextlyhq/adapter-drizzle"),
|
|
46618
46745
|
"@nextlyhq/adapter-sqlite": range("@nextlyhq/adapter-sqlite"),
|
|
46619
|
-
next:
|
|
46620
|
-
react:
|
|
46621
|
-
"react-dom":
|
|
46746
|
+
next: scaffoldRange("next"),
|
|
46747
|
+
react: scaffoldRange("react"),
|
|
46748
|
+
"react-dom": scaffoldRange("react-dom"),
|
|
46622
46749
|
"better-sqlite3": "^12.0.0",
|
|
46623
46750
|
"@types/node": PINNED_VERSIONS["@types/node"],
|
|
46624
46751
|
"@types/react": PINNED_VERSIONS["@types/react"],
|
|
@@ -46936,6 +47063,143 @@ async function copyPluginTemplate(opts) {
|
|
|
46936
47063
|
await writeScaffoldNpmrc(targetDir, packageManager);
|
|
46937
47064
|
await replacePlaceholders(targetDir, placeholders, alreadyRendered);
|
|
46938
47065
|
}
|
|
47066
|
+
// src/generators/page-extensions.ts
|
|
47067
|
+
/**
|
|
47068
|
+
* The page extension to name a new module file with, a hook or a route: a
|
|
47069
|
+
* TypeScript one first, since Nextly's files are TypeScript, then a
|
|
47070
|
+
* JavaScript one; never a content extension such as `mdx`, which Next.js
|
|
47071
|
+
* would compile as content, and never `cjs`, since the files are ES modules
|
|
47072
|
+
* and a `.cjs` file cannot hold one. Null when the list holds no extension a
|
|
47073
|
+
* module can be written in.
|
|
47074
|
+
*/
|
|
47075
|
+
function moduleExtension(extensions) {
|
|
47076
|
+
const usable = writable(extensions);
|
|
47077
|
+
return usable.find((extension) => /(^|\.)tsx?$/.test(extension)) ?? usable.find((extension) => /(^|\.)(js|jsx|mjs)$/.test(extension)) ?? null;
|
|
47078
|
+
}
|
|
47079
|
+
/**
|
|
47080
|
+
* The extensions a file with code in it can be written under: not a
|
|
47081
|
+
* declaration file's (`d.ts`, `d.mts`, `d.cts`), which TypeScript reads as
|
|
47082
|
+
* types only and refuses code in.
|
|
47083
|
+
*/
|
|
47084
|
+
function writable(extensions) {
|
|
47085
|
+
return extensions.filter((extension) => !/(^|\.)d\.[cm]?tsx?$/.test(extension));
|
|
47086
|
+
}
|
|
47087
|
+
/**
|
|
47088
|
+
* The `pageExtensions` the app's Next.js config sets, as every existing-app
|
|
47089
|
+
* step that names a file Next.js routes reads it: the list; `"absent"` when
|
|
47090
|
+
* the config sets none, or there is no config; or null when it is set in a
|
|
47091
|
+
* way that cannot be read. Read from the config the app exports, as the Next
|
|
47092
|
+
* config step reads it, so a commented-out or nested `pageExtensions` sets
|
|
47093
|
+
* nothing. `configName` is the file it was read from, for the report.
|
|
47094
|
+
*/
|
|
47095
|
+
async function appPageExtensions(cwd) {
|
|
47096
|
+
const nextConfig = await readNextConfig(cwd);
|
|
47097
|
+
return {
|
|
47098
|
+
configName: nextConfig?.name ?? "The Next.js config",
|
|
47099
|
+
extensions: nextConfig ? configStringList(nextConfig.text, nextConfig.name, "pageExtensions") : "absent"
|
|
47100
|
+
};
|
|
47101
|
+
}
|
|
47102
|
+
/**
|
|
47103
|
+
* The text of the app's Next.js config, or null when it has none, from the
|
|
47104
|
+
* file the Next config step reads and extends ({@link findConfigFile}).
|
|
47105
|
+
*/
|
|
47106
|
+
async function readNextConfig(cwd) {
|
|
47107
|
+
const name = await findConfigFile(cwd);
|
|
47108
|
+
return name === null ? null : {
|
|
47109
|
+
name,
|
|
47110
|
+
text: await import_lib$1.default.readFile(path.join(cwd, name), "utf-8")
|
|
47111
|
+
};
|
|
47112
|
+
}
|
|
47113
|
+
/**
|
|
47114
|
+
* The page extension for a file of TypeScript with JSX, such as a page or a
|
|
47115
|
+
* layout: one ending in `tsx`. Null when the list holds none.
|
|
47116
|
+
*/
|
|
47117
|
+
function tsxExtension(extensions) {
|
|
47118
|
+
return writable(extensions).find((extension) => /(^|\.)tsx$/.test(extension)) ?? null;
|
|
47119
|
+
}
|
|
47120
|
+
/** A JavaScript or TypeScript module without JSX, such as a route. */
|
|
47121
|
+
const MODULE_FILE = {
|
|
47122
|
+
pick: moduleExtension,
|
|
47123
|
+
holds: "a JavaScript or TypeScript extension"
|
|
47124
|
+
};
|
|
47125
|
+
/** TypeScript with JSX, such as a page or a layout. */
|
|
47126
|
+
const TSX_FILE = {
|
|
47127
|
+
pick: tsxExtension,
|
|
47128
|
+
holds: "an extension ending in tsx"
|
|
47129
|
+
};
|
|
47130
|
+
/**
|
|
47131
|
+
* The report for a file an app that sets `pageExtensions` gets in place of
|
|
47132
|
+
* the file: the name to create it under and its content. Next.js routes a
|
|
47133
|
+
* file there only under a name with one of the app's extensions, and the app
|
|
47134
|
+
* may already have the file under such a name, which the existing-app steps
|
|
47135
|
+
* do not look for, so nothing is written. A list that cannot be read, or that
|
|
47136
|
+
* holds no extension the content needs, gives a placeholder name and says
|
|
47137
|
+
* which.
|
|
47138
|
+
*
|
|
47139
|
+
* @param base the file's path without its extension, as reported, such as
|
|
47140
|
+
* `app/admin/[[...params]]/page`
|
|
47141
|
+
*/
|
|
47142
|
+
function pageExtensionsSkip(base, text, pages, need) {
|
|
47143
|
+
const { configName, extensions } = pages;
|
|
47144
|
+
const extension = extensions === null ? null : need.pick(extensions);
|
|
47145
|
+
const sets = `${configName} sets pageExtensions, and Next.js routes a file there only under a name with one of them, so none was written`;
|
|
47146
|
+
if (extensions !== null && extension === null) return {
|
|
47147
|
+
path: `${base}.<${need.holds} added to pageExtensions>`,
|
|
47148
|
+
why: `${sets}, and none of them (${extensions.join(", ")}) is ${need.holds}; add one to pageExtensions, then, unless the app already has this file, create it under that name with this content`,
|
|
47149
|
+
toAdd: text
|
|
47150
|
+
};
|
|
47151
|
+
return {
|
|
47152
|
+
path: `${base}.${extension ?? "<one of your pageExtensions>"}`,
|
|
47153
|
+
why: `${sets}; unless the app already has this file, create it under that name with this content`,
|
|
47154
|
+
toAdd: text
|
|
47155
|
+
};
|
|
47156
|
+
}
|
|
47157
|
+
// src/generators/write-new.ts
|
|
47158
|
+
/**
|
|
47159
|
+
* Writes `text` to `relative` (a project-relative path, written with `/`)
|
|
47160
|
+
* only where nothing is, and records which it was.
|
|
47161
|
+
*
|
|
47162
|
+
* The file is created exclusively (`wx`), so a file the app already has, a
|
|
47163
|
+
* link included, is never replaced, whatever appeared since any earlier
|
|
47164
|
+
* check. One that is there is reported as skipped, with why and, when given,
|
|
47165
|
+
* what to add to it by hand. `wx` guards only the file's own name, so a
|
|
47166
|
+
* folder on its path that is a symbolic link, which would take the write
|
|
47167
|
+
* wherever it points, is found first, as the media routes find it, and
|
|
47168
|
+
* nothing is written through it.
|
|
47169
|
+
*/
|
|
47170
|
+
async function writeNew(cwd, relative, text, files, ifThere) {
|
|
47171
|
+
const file = path.join(cwd, ...relative.split("/"));
|
|
47172
|
+
const link = await linkedFolder(cwd, file);
|
|
47173
|
+
if (link !== null) {
|
|
47174
|
+
const folder = path.relative(cwd, link.folder).split(path.sep).join("/");
|
|
47175
|
+
files.skipped.push({
|
|
47176
|
+
path: relative,
|
|
47177
|
+
why: link.unreadable ? `${folder} cannot be read, so whether a folder in it is a symbolic link is unknown; nothing was written there` : `${folder} ${THROUGH_A_LINK}`,
|
|
47178
|
+
toAdd: ifThere.toAdd
|
|
47179
|
+
});
|
|
47180
|
+
return;
|
|
47181
|
+
}
|
|
47182
|
+
await import_lib$1.default.ensureDir(path.dirname(file));
|
|
47183
|
+
try {
|
|
47184
|
+
await import_lib$1.default.writeFile(file, text, {
|
|
47185
|
+
encoding: "utf-8",
|
|
47186
|
+
flag: "wx"
|
|
47187
|
+
});
|
|
47188
|
+
files.written.push(relative);
|
|
47189
|
+
} catch (error) {
|
|
47190
|
+
if (error.code !== "EEXIST") throw error;
|
|
47191
|
+
files.skipped.push({
|
|
47192
|
+
path: relative,
|
|
47193
|
+
...ifThere
|
|
47194
|
+
});
|
|
47195
|
+
}
|
|
47196
|
+
}
|
|
47197
|
+
/** A step's report before it has done anything. */
|
|
47198
|
+
const nothingYet = () => ({
|
|
47199
|
+
written: [],
|
|
47200
|
+
changed: [],
|
|
47201
|
+
skipped: []
|
|
47202
|
+
});
|
|
46939
47203
|
// src/generators/routes.ts
|
|
46940
47204
|
const API_ROUTE_TEMPLATE = `// Imported from \`nextly/runtime\` (not the package root) so the
|
|
46941
47205
|
// Next.js-coupled handler factory stays out of Node-only code paths
|
|
@@ -47046,8 +47310,22 @@ const UPLOADS_ROUTE = {
|
|
|
47046
47310
|
importsConfig: true,
|
|
47047
47311
|
role: (file) => `Nextly's uploads route at ${file} serves files stored on local disk at /uploads, which a production server otherwise answers 404 for until it restarts`
|
|
47048
47312
|
};
|
|
47049
|
-
/**
|
|
47050
|
-
|
|
47313
|
+
/**
|
|
47314
|
+
* The admin's layout, which `generateAdminPage` writes beside the admin page.
|
|
47315
|
+
* Read with the routes, from the template a new project gets, so an app Nextly
|
|
47316
|
+
* is added to renders its admin the same way: its shell prerendered, and its
|
|
47317
|
+
* request work beneath a Suspense boundary.
|
|
47318
|
+
*/
|
|
47319
|
+
const ADMIN_LAYOUT = {
|
|
47320
|
+
path: "admin/[[...params]]/layout.tsx",
|
|
47321
|
+
importsConfig: true
|
|
47322
|
+
};
|
|
47323
|
+
/** Every file the existing-app path writes from the templates, read together. */
|
|
47324
|
+
const ALL_ROUTES = [
|
|
47325
|
+
...ROUTES,
|
|
47326
|
+
UPLOADS_ROUTE,
|
|
47327
|
+
ADMIN_LAYOUT
|
|
47328
|
+
];
|
|
47051
47329
|
/**
|
|
47052
47330
|
* The import that brings in the Nextly config: the template spells it through
|
|
47053
47331
|
* the `@nextly-config` alias or a path relative to its own layout, neither of
|
|
@@ -47597,52 +47875,6 @@ function skipped(cwd, left, target, text, role, reason) {
|
|
|
47597
47875
|
function toPosix(p) {
|
|
47598
47876
|
return p.split(path.sep).join("/");
|
|
47599
47877
|
}
|
|
47600
|
-
// src/generators/write-new.ts
|
|
47601
|
-
/**
|
|
47602
|
-
* Writes `text` to `relative` (a project-relative path, written with `/`)
|
|
47603
|
-
* only where nothing is, and records which it was.
|
|
47604
|
-
*
|
|
47605
|
-
* The file is created exclusively (`wx`), so a file the app already has, a
|
|
47606
|
-
* link included, is never replaced, whatever appeared since any earlier
|
|
47607
|
-
* check. One that is there is reported as skipped, with why and, when given,
|
|
47608
|
-
* what to add to it by hand. `wx` guards only the file's own name, so a
|
|
47609
|
-
* folder on its path that is a symbolic link, which would take the write
|
|
47610
|
-
* wherever it points, is found first, as the media routes find it, and
|
|
47611
|
-
* nothing is written through it.
|
|
47612
|
-
*/
|
|
47613
|
-
async function writeNew(cwd, relative, text, files, ifThere) {
|
|
47614
|
-
const file = path.join(cwd, ...relative.split("/"));
|
|
47615
|
-
const link = await linkedFolder(cwd, file);
|
|
47616
|
-
if (link !== null) {
|
|
47617
|
-
const folder = path.relative(cwd, link.folder).split(path.sep).join("/");
|
|
47618
|
-
files.skipped.push({
|
|
47619
|
-
path: relative,
|
|
47620
|
-
why: link.unreadable ? `${folder} cannot be read, so whether a folder in it is a symbolic link is unknown; nothing was written there` : `${folder} ${THROUGH_A_LINK}`,
|
|
47621
|
-
toAdd: ifThere.toAdd
|
|
47622
|
-
});
|
|
47623
|
-
return;
|
|
47624
|
-
}
|
|
47625
|
-
await import_lib$1.default.ensureDir(path.dirname(file));
|
|
47626
|
-
try {
|
|
47627
|
-
await import_lib$1.default.writeFile(file, text, {
|
|
47628
|
-
encoding: "utf-8",
|
|
47629
|
-
flag: "wx"
|
|
47630
|
-
});
|
|
47631
|
-
files.written.push(relative);
|
|
47632
|
-
} catch (error) {
|
|
47633
|
-
if (error.code !== "EEXIST") throw error;
|
|
47634
|
-
files.skipped.push({
|
|
47635
|
-
path: relative,
|
|
47636
|
-
...ifThere
|
|
47637
|
-
});
|
|
47638
|
-
}
|
|
47639
|
-
}
|
|
47640
|
-
/** A step's report before it has done anything. */
|
|
47641
|
-
const nothingYet = () => ({
|
|
47642
|
-
written: [],
|
|
47643
|
-
changed: [],
|
|
47644
|
-
skipped: []
|
|
47645
|
-
});
|
|
47646
47878
|
// src/generators/admin.ts
|
|
47647
47879
|
const ADMIN_PAGE_TEMPLATE = `"use client";
|
|
47648
47880
|
|
|
@@ -47664,43 +47896,24 @@ export default function AdminPage() {
|
|
|
47664
47896
|
}
|
|
47665
47897
|
`;
|
|
47666
47898
|
/**
|
|
47667
|
-
*
|
|
47668
|
-
*
|
|
47669
|
-
*
|
|
47670
|
-
*
|
|
47671
|
-
* Without src: app/admin/[[...params]]/layout.tsx → ../../../nextly.config
|
|
47899
|
+
* The admin layout, as the base template holds it, with its config import
|
|
47900
|
+
* pointing at the project's `nextly.config` from where the layout is written.
|
|
47901
|
+
* One source with a new project's layout, so an app Nextly is added to gets
|
|
47902
|
+
* the same per-request admin.
|
|
47672
47903
|
*/
|
|
47673
|
-
function
|
|
47674
|
-
|
|
47675
|
-
|
|
47676
|
-
|
|
47677
|
-
|
|
47678
|
-
const brandingCss = getBrandingCss(config.admin?.branding);
|
|
47679
|
-
|
|
47680
|
-
export default function AdminLayout({
|
|
47681
|
-
children,
|
|
47682
|
-
}: {
|
|
47683
|
-
children: React.ReactNode;
|
|
47684
|
-
}) {
|
|
47685
|
-
return (
|
|
47686
|
-
<>
|
|
47687
|
-
{brandingCss && (
|
|
47688
|
-
<style dangerouslySetInnerHTML={{ __html: brandingCss }} />
|
|
47689
|
-
)}
|
|
47690
|
-
{children}
|
|
47691
|
-
</>
|
|
47692
|
-
);
|
|
47693
|
-
}
|
|
47694
|
-
`;
|
|
47904
|
+
function adminLayout(cwd, adminDir, templates) {
|
|
47905
|
+
const text = templates.get(ADMIN_LAYOUT.path);
|
|
47906
|
+
if (text === void 0) throw new Error(`The templates read for this app hold no ${ADMIN_LAYOUT.path}, so Nextly's admin layout cannot be written.`);
|
|
47907
|
+
return withRelativeConfigImport(text, cwd, path.join(cwd, adminDir, "layout.tsx"), ADMIN_LAYOUT.path);
|
|
47695
47908
|
}
|
|
47696
47909
|
/**
|
|
47697
47910
|
* Generate the admin panel page and layout.
|
|
47698
47911
|
* Uses [[...params]] to match the expected route pattern.
|
|
47699
47912
|
*/
|
|
47700
|
-
async function generateAdminPage(cwd, projectInfo) {
|
|
47913
|
+
async function generateAdminPage(cwd, projectInfo, templates) {
|
|
47701
47914
|
const files = nothingYet();
|
|
47702
47915
|
const adminDir = `${projectInfo.appDir}/admin/[[...params]]`;
|
|
47703
|
-
const layout =
|
|
47916
|
+
const layout = adminLayout(cwd, adminDir, templates);
|
|
47704
47917
|
const pages = await appPageExtensions(cwd);
|
|
47705
47918
|
if (pages.extensions !== "absent") {
|
|
47706
47919
|
const { configName, extensions } = pages;
|
|
@@ -47830,8 +48043,9 @@ function startNextly(configImport) {
|
|
|
47830
48043
|
const { createRegister } = await import("nextly");
|
|
47831
48044
|
const { default: config } = await import("${configImport}");
|
|
47832
48045
|
// Next.js writes its Cache Components setting into this file as it builds
|
|
47833
|
-
// it. Nextly, loaded from node_modules, cannot read that for itself
|
|
47834
|
-
// warns
|
|
48046
|
+
// it. Nextly, loaded from node_modules, cannot read that for itself. With
|
|
48047
|
+
// it off, Nextly warns at start; with it on, a cached read that finds no
|
|
48048
|
+
// "use cache" read function says so.
|
|
47835
48049
|
await createRegister(config, {
|
|
47836
48050
|
cacheComponents: process.env.__NEXT_CACHE_COMPONENTS,
|
|
47837
48051
|
})();`;
|
|
@@ -47929,10 +48143,7 @@ function pageExtensionsAdvice(dir, configImport, configName, extensions) {
|
|
|
47929
48143
|
* never rewritten; it is reported as skipped with what to add. So is the case
|
|
47930
48144
|
* where the app sets \`pageExtensions\`: Next.js then reads the hook only under a
|
|
47931
48145
|
* name with one of those extensions, which this does not guess. The config file
|
|
47932
|
-
* itself is never edited here.
|
|
47933
|
-
* `experimental.instrumentationHook`, which the Next config step gives in the
|
|
47934
|
-
* same `experimental` object as Nextly's packages (`patchNextConfig`), so two
|
|
47935
|
-
* steps never hand the developer two objects for one key.
|
|
48146
|
+
* itself is never edited here.
|
|
47936
48147
|
*/
|
|
47937
48148
|
async function generateInstrumentation(cwd, projectInfo) {
|
|
47938
48149
|
const dir = projectInfo.srcDir ? "src" : "";
|
|
@@ -47980,13 +48191,13 @@ async function generateIntoExistingApp(cwd, projectType, projectInfo, database,
|
|
|
47980
48191
|
return [
|
|
47981
48192
|
await generateConfig(cwd, projectType, projectInfo),
|
|
47982
48193
|
await generateRoutes(cwd, projectInfo),
|
|
47983
|
-
await generateAdminPage(cwd, projectInfo),
|
|
48194
|
+
await generateAdminPage(cwd, projectInfo, templates),
|
|
47984
48195
|
await generateMediaRoutes(cwd, projectInfo, templates),
|
|
47985
48196
|
await generateUploadsRoute(cwd, projectInfo, templates),
|
|
47986
48197
|
await generateInstrumentation(cwd, projectInfo),
|
|
47987
48198
|
await generateTypesDirectory(cwd, projectInfo),
|
|
47988
48199
|
nextConfigFiles(await patchNextConfig(cwd, database)),
|
|
47989
|
-
cacheComponentsFiles(await
|
|
48200
|
+
cacheComponentsFiles(await turnOnCacheComponents(cwd))
|
|
47990
48201
|
];
|
|
47991
48202
|
}
|
|
47992
48203
|
// src/generators/report.ts
|
|
@@ -50643,7 +50854,7 @@ var hr = Symbol("entry");
|
|
|
50643
50854
|
var cs = Symbol("entryOpt");
|
|
50644
50855
|
var ui = Symbol("writeEntryClass");
|
|
50645
50856
|
var lr = Symbol("write");
|
|
50646
|
-
var fs$
|
|
50857
|
+
var fs$7 = Symbol("ondrain");
|
|
50647
50858
|
var wt = class extends A {
|
|
50648
50859
|
sync = !1;
|
|
50649
50860
|
opt;
|
|
@@ -50677,8 +50888,8 @@ var wt = class extends A {
|
|
|
50677
50888
|
if ((t.gzip ? 1 : 0) + (t.brotli ? 1 : 0) + (t.zstd ? 1 : 0) > 1) throw new TypeError("gzip, brotli, zstd are mutually exclusive");
|
|
50678
50889
|
if (t.gzip && (typeof t.gzip != "object" && (t.gzip = {}), this.portable && (t.gzip.portable = !0), this.zip = new ze(t.gzip)), t.brotli && (typeof t.brotli != "object" && (t.brotli = {}), this.zip = new We(t.brotli)), t.zstd && (typeof t.zstd != "object" && (t.zstd = {}), this.zip = new Ye(t.zstd)), !this.zip) throw new Error("impossible");
|
|
50679
50890
|
let e = this.zip;
|
|
50680
|
-
e.on("data", (i) => super.write(i)), e.on("end", () => super.end()), e.on("drain", () => this[fs$
|
|
50681
|
-
} else this.on("drain", this[fs$
|
|
50891
|
+
e.on("data", (i) => super.write(i)), e.on("end", () => super.end()), e.on("drain", () => this[fs$7]()), this.on("resume", () => e.resume());
|
|
50892
|
+
} else this.on("drain", this[fs$7]);
|
|
50682
50893
|
this.noDirRecurse = !!t.noDirRecurse, this.follow = !!t.follow, this.noMtime = !!t.noMtime, t.mtime && (this.mtime = t.mtime), this.filter = typeof t.filter == "function" ? t.filter : () => !0, this[W] = new hi(), this[G] = 0, this.jobs = Number(t.jobs) || 4, this[Ee] = !1, this[me] = !1;
|
|
50683
50894
|
}
|
|
50684
50895
|
[lr](t) {
|
|
@@ -50806,7 +51017,7 @@ var wt = class extends A {
|
|
|
50806
51017
|
this.emit("error", e);
|
|
50807
51018
|
}
|
|
50808
51019
|
}
|
|
50809
|
-
[fs$
|
|
51020
|
+
[fs$7]() {
|
|
50810
51021
|
this[Et] && this[Et].entry && this[Et].entry.resume();
|
|
50811
51022
|
}
|
|
50812
51023
|
[di](t) {
|
|
@@ -51873,6 +52084,126 @@ async function cleanupDownload(source) {
|
|
|
51873
52084
|
await import_lib$1.default.remove(extractionRoot).catch(() => {});
|
|
51874
52085
|
}
|
|
51875
52086
|
}
|
|
52087
|
+
// src/lib/framework-versions.ts
|
|
52088
|
+
/**
|
|
52089
|
+
* Whether an existing app's Next.js, React and React DOM are ones this
|
|
52090
|
+
* release of Nextly supports, and what to change when they are not.
|
|
52091
|
+
*
|
|
52092
|
+
* Nextly is reviewed against one Next.js major and one React major
|
|
52093
|
+
* (`SUPPORTED_RANGES`). An app below the floor or on a newer major would
|
|
52094
|
+
* install Nextly and then fail at build or at run time, so adding Nextly to
|
|
52095
|
+
* it stops before anything is written, saying what was found and the way on.
|
|
52096
|
+
*/
|
|
52097
|
+
/** The first spec the app's package.json gives `name`, in field order. */
|
|
52098
|
+
function declaredSpec(manifest, name) {
|
|
52099
|
+
const fields = ["optionalDependencies", ...DEPENDENCY_FIELDS$1.filter((field) => field !== "optionalDependencies")];
|
|
52100
|
+
for (const field of fields) {
|
|
52101
|
+
const deps = manifest[field];
|
|
52102
|
+
if (!deps || typeof deps !== "object") continue;
|
|
52103
|
+
const spec = deps[name];
|
|
52104
|
+
if (typeof spec === "string") return spec;
|
|
52105
|
+
}
|
|
52106
|
+
}
|
|
52107
|
+
/**
|
|
52108
|
+
* The version an app is headed for, the one judged against the range: the
|
|
52109
|
+
* installed copy, unless the app's declaration points past it.
|
|
52110
|
+
*/
|
|
52111
|
+
function judgedVersion(installed, declared, supported) {
|
|
52112
|
+
const lowestDeclared = declared !== void 0 ? lowestVersionIn(declared) : void 0;
|
|
52113
|
+
const floor = lowestVersionIn(supported);
|
|
52114
|
+
if (floor === void 0) return installed ?? lowestDeclared;
|
|
52115
|
+
if (lowestDeclared !== void 0 && compareVersions(lowestDeclared, floor) > 0 && !satisfiesRange(lowestDeclared, supported)) return lowestDeclared;
|
|
52116
|
+
const highest = declared !== void 0 ? highestMajorIn(declared) : void 0;
|
|
52117
|
+
if (installed === void 0 && highest !== void 0 && highest > major(floor)) return `${major(floor) + 1}.0.0`;
|
|
52118
|
+
return installed ?? lowestDeclared;
|
|
52119
|
+
}
|
|
52120
|
+
/**
|
|
52121
|
+
* Too new only on a later major than the range covers; anything else outside
|
|
52122
|
+
* it (below the floor, or a prerelease within the major) needs a supported
|
|
52123
|
+
* release of the same major. A range without a floor leaves nothing to
|
|
52124
|
+
* compare, and the version is then reported as too new.
|
|
52125
|
+
*/
|
|
52126
|
+
function directionOf(judged, supported) {
|
|
52127
|
+
const floor = lowestVersionIn(supported);
|
|
52128
|
+
return floor === void 0 || major(judged) > major(floor) ? "too-new" : "too-old";
|
|
52129
|
+
}
|
|
52130
|
+
/**
|
|
52131
|
+
* Every supported framework package the app at `cwd` has outside its range.
|
|
52132
|
+
*
|
|
52133
|
+
* The version judged is the one the app is headed for (`judgedVersion`): the
|
|
52134
|
+
* installed copy, read from the `node_modules` Node would load it from,
|
|
52135
|
+
* unless the app's package.json declaration points past it; with none
|
|
52136
|
+
* installed, what an install of that declaration could resolve to. A package
|
|
52137
|
+
* the app neither has installed nor declares in a form that names a version
|
|
52138
|
+
* (a dist-tag, `workspace:*`) is not judged.
|
|
52139
|
+
*/
|
|
52140
|
+
async function frameworkVersionProblems(cwd) {
|
|
52141
|
+
const manifest = await import_lib$1.default.readJson(path.join(cwd, "package.json")).catch(() => ({}));
|
|
52142
|
+
const problems = [];
|
|
52143
|
+
for (const name of Object.keys(SUPPORTED_RANGES)) {
|
|
52144
|
+
const supported = SUPPORTED_RANGES[name];
|
|
52145
|
+
const installed = await installedVersion(cwd, name);
|
|
52146
|
+
const declared = declaredSpec(manifest, name);
|
|
52147
|
+
const judged = judgedVersion(installed, declared, supported);
|
|
52148
|
+
if (judged === void 0 || satisfiesRange(judged, supported)) continue;
|
|
52149
|
+
const direction = directionOf(judged, supported);
|
|
52150
|
+
problems.push({
|
|
52151
|
+
name,
|
|
52152
|
+
installed,
|
|
52153
|
+
declared,
|
|
52154
|
+
supported,
|
|
52155
|
+
judged,
|
|
52156
|
+
direction
|
|
52157
|
+
});
|
|
52158
|
+
}
|
|
52159
|
+
return problems;
|
|
52160
|
+
}
|
|
52161
|
+
const LABEL = {
|
|
52162
|
+
next: "Next.js",
|
|
52163
|
+
react: "React",
|
|
52164
|
+
"react-dom": "React"
|
|
52165
|
+
};
|
|
52166
|
+
const major = (version) => Number(version.split(".")[0]);
|
|
52167
|
+
/** What `fix` reads from a problem: the supported major and the version found. */
|
|
52168
|
+
function majorsOf(problem) {
|
|
52169
|
+
const floor = lowestVersionIn(problem.supported) ?? problem.supported;
|
|
52170
|
+
return {
|
|
52171
|
+
supportedMajor: major(floor),
|
|
52172
|
+
foundMajor: major(problem.judged)
|
|
52173
|
+
};
|
|
52174
|
+
}
|
|
52175
|
+
/** A version past the supported major: install that major, or wait for Nextly. */
|
|
52176
|
+
function tooNewFix(problem, add) {
|
|
52177
|
+
const { supportedMajor, foundMajor } = majorsOf(problem);
|
|
52178
|
+
const label = LABEL[problem.name];
|
|
52179
|
+
return `This release of Nextly supports ${label} up to the ${supportedMajor}.x line. Install ${label} ${supportedMajor}, or wait for a Nextly release that supports ${label} ${foundMajor}:\n ${add} ${problem.name === "next" ? `next@${supportedMajor}` : `react@${supportedMajor} react-dom@${supportedMajor}`}`;
|
|
52180
|
+
}
|
|
52181
|
+
/** A version below the supported floor: the codemod across a Next.js major, an install otherwise. */
|
|
52182
|
+
function tooOldFix(problem, add) {
|
|
52183
|
+
const { supportedMajor, foundMajor } = majorsOf(problem);
|
|
52184
|
+
if (problem.name === "next" && foundMajor < supportedMajor) return `Upgrade Next.js to ${REVIEWED_VERSIONS.next} with its codemod:\n npx @next/codemod@latest upgrade ${REVIEWED_VERSIONS.next}`;
|
|
52185
|
+
const install = problem.name === "next" ? `next@${problem.supported}` : `react@${SUPPORTED_RANGES.react} react-dom@${SUPPORTED_RANGES["react-dom"]}`;
|
|
52186
|
+
return `Upgrade ${LABEL[problem.name]} to ${problem.supported}:\n ${add} ${install}`;
|
|
52187
|
+
}
|
|
52188
|
+
/** The one step that brings `problem` into range, as a sentence and a command. */
|
|
52189
|
+
function fix(problem, pm) {
|
|
52190
|
+
const add = ADD_COMMAND[pm];
|
|
52191
|
+
return problem.direction === "too-new" ? tooNewFix(problem, add) : tooOldFix(problem, add);
|
|
52192
|
+
}
|
|
52193
|
+
/**
|
|
52194
|
+
* Why the run stopped: each package found, the range it falls outside, and
|
|
52195
|
+
* the change that brings it in. React and React DOM move together, so a
|
|
52196
|
+
* problem with both gives one command.
|
|
52197
|
+
*/
|
|
52198
|
+
function frameworkVersionMessage(problems, pm) {
|
|
52199
|
+
const lines = problems.map(({ name, installed, declared, supported }) => {
|
|
52200
|
+
return ` ${name}: ${[installed !== void 0 ? `installed ${installed}` : void 0, declared !== void 0 ? `declared ${declared}` : void 0].filter(Boolean).join(", ")}; supported ${supported}`;
|
|
52201
|
+
});
|
|
52202
|
+
const fixes = [...new Set(problems.map((problem) => fix(problem, pm)))];
|
|
52203
|
+
return `This app's Next.js or React is outside what this release of Nextly supports:
|
|
52204
|
+
${lines.join("\n")}\n\nNothing was changed. Change the app as follows, then run create-nextly-app again:
|
|
52205
|
+
` + fixes.map((line) => ` ${line}`).join("\n");
|
|
52206
|
+
}
|
|
51876
52207
|
// src/prompts/approach.ts
|
|
51877
52208
|
/**
|
|
51878
52209
|
* Labels shown in the CLI select prompt for each approach.
|
|
@@ -52313,6 +52644,16 @@ async function createNextly(options = {}) {
|
|
|
52313
52644
|
const existingProject = options.projectType !== "plugin" && await isExistingNextProject(cwd);
|
|
52314
52645
|
if (existingProject) {
|
|
52315
52646
|
R.success(`${import_picocolors.default.green("Next.js")} project detected`);
|
|
52647
|
+
const frameworkProblems = await frameworkVersionProblems(cwd);
|
|
52648
|
+
if (frameworkProblems.length > 0) {
|
|
52649
|
+
capture("scaffold_failed", {
|
|
52650
|
+
stage: "detect",
|
|
52651
|
+
error_code: "unknown",
|
|
52652
|
+
duration_ms: Date.now() - overallStartedAt
|
|
52653
|
+
});
|
|
52654
|
+
Nt$1(frameworkVersionMessage(frameworkProblems, await detectAppPackageManager(cwd)));
|
|
52655
|
+
process.exit(1);
|
|
52656
|
+
}
|
|
52316
52657
|
if (!defaults) {
|
|
52317
52658
|
const shouldInstall = await Rt$1({
|
|
52318
52659
|
message: "Install Nextly in this project?",
|
|
@@ -52655,4 +52996,4 @@ async function createNextly(options = {}) {
|
|
|
52655
52996
|
}
|
|
52656
52997
|
export { getAvailableTemplateNames as a, init as c, __require as d, __toESM$1 as f, validateTemplateName as i, shutdown as l, resolveProjectArg as n, packageVersion as o, validateProjectName as r, capture as s, createNextly as t, __commonJSMin$1 as u };
|
|
52657
52998
|
|
|
52658
|
-
//# sourceMappingURL=create-nextly-
|
|
52999
|
+
//# sourceMappingURL=create-nextly-CuWn_ITx.mjs.map
|