@amplifyup/sdk 0.2.5 → 0.3.1-uat.104.gfd92fe0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -1
- package/dist/{AmplifyRenderer-eGtn5k9_.d.mts → AmplifyRenderer-CwAYY8K1.d.mts} +1 -1
- package/dist/{AmplifyRenderer-CTwblDs3.d.ts → AmplifyRenderer-D40crBWY.d.ts} +1 -1
- package/dist/AmplifyRenderer.d.mts +2 -2
- package/dist/AmplifyRenderer.d.ts +2 -2
- package/dist/AmplifyRenderer.js +1 -1
- package/dist/AmplifyRenderer.js.map +1 -1
- package/dist/AmplifyRenderer.mjs +1 -1
- package/dist/AmplifyRenderer.mjs.map +1 -1
- package/dist/index.d.mts +290 -4
- package/dist/index.d.ts +290 -4
- package/dist/index.js +105 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +101 -7
- package/dist/index.mjs.map +1 -1
- package/dist/next.js +100 -7
- package/dist/next.js.map +1 -1
- package/dist/next.mjs +99 -7
- package/dist/next.mjs.map +1 -1
- package/dist/{query-Bs5o-qmw.d.ts → query-BeQibYGm.d.ts} +1 -1
- package/dist/{query-CYRvyIv0.d.mts → query-CwtZtJX8.d.mts} +1 -1
- package/dist/react.d.mts +6 -6
- package/dist/react.d.ts +6 -6
- package/dist/react.js +2 -2
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +2 -2
- package/dist/react.mjs.map +1 -1
- package/dist/server.d.mts +3 -3
- package/dist/server.d.ts +3 -3
- package/dist/{types-ffQNIQCK.d.ts → types-CxucvIL6.d.mts} +1 -1
- package/dist/{types-ffQNIQCK.d.mts → types-CxucvIL6.d.ts} +1 -1
- package/package.json +8 -7
- package/dist/cli.d.mts +0 -1
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js +0 -266
- package/dist/cli.js.map +0 -1
- package/dist/cli.mjs +0 -260
- package/dist/cli.mjs.map +0 -1
package/dist/next.js
CHANGED
|
@@ -4,10 +4,12 @@ var fs = require('fs');
|
|
|
4
4
|
var path2 = require('path');
|
|
5
5
|
var jiti = require('jiti');
|
|
6
6
|
var tinyglobby = require('tinyglobby');
|
|
7
|
+
var semver = require('semver');
|
|
7
8
|
|
|
8
9
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
10
|
|
|
10
11
|
var path2__default = /*#__PURE__*/_interopDefault(path2);
|
|
12
|
+
var semver__default = /*#__PURE__*/_interopDefault(semver);
|
|
11
13
|
|
|
12
14
|
/* @amplifyup/sdk - https://amplifyup.ai */
|
|
13
15
|
|
|
@@ -44,7 +46,7 @@ var loadComponentsConfig = async (cwd) => {
|
|
|
44
46
|
// src/component-key.ts
|
|
45
47
|
var componentKey = (id) => id.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
46
48
|
|
|
47
|
-
// src/
|
|
49
|
+
// src/registry/scan-components.ts
|
|
48
50
|
var ALWAYS_EXCLUDE = [
|
|
49
51
|
"**/*.test.*",
|
|
50
52
|
"**/*.spec.*",
|
|
@@ -144,13 +146,76 @@ Rename one of them, or add it to components.exclude in amplifyup.config.ts.`
|
|
|
144
146
|
const entries = [...byKey.values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
145
147
|
return { entries, skipped, missingRoots };
|
|
146
148
|
};
|
|
149
|
+
var SDK_PACKAGE = "@amplifyup/sdk";
|
|
150
|
+
var readJson = (file) => JSON.parse(fs.readFileSync(file, "utf8"));
|
|
151
|
+
var findInstalledPackage = (cwd, name) => {
|
|
152
|
+
let dir = cwd;
|
|
153
|
+
while (true) {
|
|
154
|
+
const candidate = path2__default.default.join(dir, "node_modules", name, "package.json");
|
|
155
|
+
if (fs.existsSync(candidate)) return candidate;
|
|
156
|
+
const parent = path2__default.default.dirname(dir);
|
|
157
|
+
if (parent === dir) return null;
|
|
158
|
+
dir = parent;
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
var peerWarning = (pkg, sdkVersion) => {
|
|
162
|
+
const range = pkg.peerDependencies?.[SDK_PACKAGE];
|
|
163
|
+
if (!range || !sdkVersion) return null;
|
|
164
|
+
if (semver__default.default.satisfies(sdkVersion, range, { includePrerelease: true })) return null;
|
|
165
|
+
return `${pkg.name} expects ${SDK_PACKAGE} ${range}, but ${sdkVersion} is installed. Update one of them.`;
|
|
166
|
+
};
|
|
167
|
+
var manifestEntries = (dependency, manifestFile, warnings) => {
|
|
168
|
+
const manifest = readJson(manifestFile);
|
|
169
|
+
const entries = [];
|
|
170
|
+
for (const component of manifest.components ?? []) {
|
|
171
|
+
const { component_id: id, export_name: exportName } = component;
|
|
172
|
+
if (typeof id !== "string" || typeof exportName !== "string") {
|
|
173
|
+
warnings.push(`${dependency}: skipped a manifest component without component_id and export_name`);
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
entries.push({
|
|
177
|
+
name: id,
|
|
178
|
+
key: componentKey(id),
|
|
179
|
+
file: manifestFile,
|
|
180
|
+
exportName,
|
|
181
|
+
module: dependency
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
return entries;
|
|
185
|
+
};
|
|
186
|
+
var scanPackages = (cwd) => {
|
|
187
|
+
const siteManifest = path2__default.default.join(cwd, "package.json");
|
|
188
|
+
if (!fs.existsSync(siteManifest)) return { entries: [], warnings: [] };
|
|
189
|
+
const site = readJson(siteManifest);
|
|
190
|
+
const dependencies = Object.keys({ ...site.devDependencies, ...site.dependencies }).sort();
|
|
191
|
+
const sdkPackageFile = findInstalledPackage(cwd, SDK_PACKAGE);
|
|
192
|
+
const sdkVersion = sdkPackageFile ? readJson(sdkPackageFile).version : void 0;
|
|
193
|
+
const entries = [];
|
|
194
|
+
const warnings = [];
|
|
195
|
+
for (const dependency of dependencies) {
|
|
196
|
+
const packageFile = findInstalledPackage(cwd, dependency);
|
|
197
|
+
if (!packageFile) continue;
|
|
198
|
+
const pkg = readJson(packageFile);
|
|
199
|
+
const manifestPath = pkg.amplifyup?.manifest;
|
|
200
|
+
if (!manifestPath) continue;
|
|
201
|
+
const manifestFile = path2__default.default.resolve(path2__default.default.dirname(packageFile), manifestPath);
|
|
202
|
+
if (!fs.existsSync(manifestFile)) {
|
|
203
|
+
warnings.push(`${dependency}: component manifest not found at ${manifestPath}`);
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
const warning = peerWarning(pkg, sdkVersion);
|
|
207
|
+
if (warning) warnings.push(warning);
|
|
208
|
+
entries.push(...manifestEntries(dependency, manifestFile, warnings));
|
|
209
|
+
}
|
|
210
|
+
return { entries, warnings };
|
|
211
|
+
};
|
|
147
212
|
var importPath = (fromFile, toFile) => {
|
|
148
213
|
const withoutExt = toFile.slice(0, toFile.length - path2__default.default.extname(toFile).length);
|
|
149
214
|
const relative = path2__default.default.relative(path2__default.default.dirname(fromFile), withoutExt).split(path2__default.default.sep).join("/").replace(/\/index$/, "");
|
|
150
215
|
return relative.startsWith(".") ? relative : `./${relative}`;
|
|
151
216
|
};
|
|
152
217
|
var importLine = (entry, local, outputFile) => {
|
|
153
|
-
const from = JSON.stringify(importPath(outputFile, entry.file));
|
|
218
|
+
const from = JSON.stringify(entry.module ?? importPath(outputFile, entry.file));
|
|
154
219
|
return entry.exportName === "default" ? `import ${local} from ${from};` : `import { ${entry.exportName} as ${local} } from ${from};`;
|
|
155
220
|
};
|
|
156
221
|
var renderRegistrySource = (entries, outputFile) => {
|
|
@@ -159,8 +224,8 @@ var renderRegistrySource = (entries, outputFile) => {
|
|
|
159
224
|
return [
|
|
160
225
|
"'use client';",
|
|
161
226
|
"",
|
|
162
|
-
"// Generated by Amplify UP from your components folder
|
|
163
|
-
"// add, rename or delete component files instead.",
|
|
227
|
+
"// Generated by Amplify UP from your components folder and installed component",
|
|
228
|
+
"// packages. Do not edit \u2014 add, rename or delete component files instead.",
|
|
164
229
|
"",
|
|
165
230
|
"import { defineComponentRegistry, bindAmplifyPage } from '@amplifyup/sdk/react';",
|
|
166
231
|
...imports,
|
|
@@ -174,7 +239,7 @@ var renderRegistrySource = (entries, outputFile) => {
|
|
|
174
239
|
].join("\n");
|
|
175
240
|
};
|
|
176
241
|
|
|
177
|
-
// src/
|
|
242
|
+
// src/registry/build-registry.ts
|
|
178
243
|
var LOG_PREFIX = "[Amplify UP]";
|
|
179
244
|
var WATCH_DEBOUNCE_MS = 120;
|
|
180
245
|
var writeIfChanged = (file, content) => {
|
|
@@ -188,12 +253,37 @@ var ensureSelfIgnored = (outputFile) => {
|
|
|
188
253
|
if (path2__default.default.basename(dir) !== ".amplifyup") return;
|
|
189
254
|
writeIfChanged(path2__default.default.join(dir, ".gitignore"), "*\n");
|
|
190
255
|
};
|
|
256
|
+
var describeEntry = (entry, cwd) => entry.module ? `${entry.module} (installed package)` : path2__default.default.relative(cwd, entry.file);
|
|
257
|
+
var mergeEntries = (local, packaged, cwd) => {
|
|
258
|
+
const byKey = new Map(local.map((entry) => [entry.key, entry]));
|
|
259
|
+
for (const entry of packaged) {
|
|
260
|
+
const existing = byKey.get(entry.key);
|
|
261
|
+
if (existing) {
|
|
262
|
+
throw new ComponentRegistryError(
|
|
263
|
+
`Two components resolve to the same name "${entry.name}":
|
|
264
|
+
${describeEntry(existing, cwd)}
|
|
265
|
+
${describeEntry(entry, cwd)}
|
|
266
|
+
Rename the local component, or remove one of the packages.`
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
byKey.set(entry.key, entry);
|
|
270
|
+
}
|
|
271
|
+
return [...byKey.values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
272
|
+
};
|
|
191
273
|
var buildRegistryFromConfig = async (config) => {
|
|
192
274
|
const scan = await scanComponents(config);
|
|
193
|
-
const
|
|
275
|
+
const packages = scanPackages(config.cwd);
|
|
276
|
+
const entries = mergeEntries(scan.entries, packages.entries, config.cwd);
|
|
277
|
+
const source = renderRegistrySource(entries, config.outputFile);
|
|
194
278
|
const changed = writeIfChanged(config.outputFile, source);
|
|
195
279
|
ensureSelfIgnored(config.outputFile);
|
|
196
|
-
return {
|
|
280
|
+
return {
|
|
281
|
+
...scan,
|
|
282
|
+
entries,
|
|
283
|
+
warnings: packages.warnings,
|
|
284
|
+
outputFile: config.outputFile,
|
|
285
|
+
changed
|
|
286
|
+
};
|
|
197
287
|
};
|
|
198
288
|
var buildRegistry = async (cwd) => buildRegistryFromConfig(await loadComponentsConfig(cwd));
|
|
199
289
|
var reportRegistry = (result, cwd) => {
|
|
@@ -201,6 +291,9 @@ var reportRegistry = (result, cwd) => {
|
|
|
201
291
|
for (const root of result.missingRoots) {
|
|
202
292
|
console.warn(`${LOG_PREFIX} Components folder not found: ${rel(root)}`);
|
|
203
293
|
}
|
|
294
|
+
for (const warning of result.warnings) {
|
|
295
|
+
console.warn(`${LOG_PREFIX} ${warning}`);
|
|
296
|
+
}
|
|
204
297
|
for (const skip of result.skipped) {
|
|
205
298
|
console.warn(`${LOG_PREFIX} Skipped ${rel(skip.file)}: ${skip.reason}`);
|
|
206
299
|
}
|
package/dist/next.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cli/load-config.ts","../src/component-key.ts","../src/cli/scan-components.ts","../src/cli/render-registry.ts","../src/cli/build-registry.ts","../src/next.ts"],"names":["path","existsSync","jiti","createJiti","readFileSync","glob","mkdirSync","writeFileSync","watch"],"mappings":";;;;;;;;;;;;;AAKA,IAAM,YAAA,GAAe;AAAA,EACnB,qBAAA;AAAA,EACA,sBAAA;AAAA,EACA,sBAAA;AAAA,EACA,qBAAA;AAAA,EACA;AACF,CAAA;AAaA,IAAM,iBAAiB,CAAC,GAAA,KACtB,aAAa,GAAA,CAAI,CAAC,SAASA,sBAAA,CAAK,IAAA,CAAK,GAAA,EAAK,IAAI,CAAC,CAAA,CAAE,IAAA,CAAK,CAAC,IAAA,KAASC,aAAA,CAAW,IAAI,CAAC,CAAA;AAElF,IAAM,YAAA,GAAe,CAAC,GAAA,KACpBA,aAAA,CAAWD,uBAAK,IAAA,CAAK,GAAA,EAAK,KAAK,CAAC,CAAA,GAAI,CAAC,gB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AAA,KAAN,KAAA,CAAM,KAAA,GAAU,aAAA,CAAc,GAAG,CAAA,CAAE,IAAA,CAAK,CAAC,MAAA,KAAW,cAAA,CAAe,MAAA,EAAQ,GAAG,CAAC,CAAA,CAAA;AAC/E,EAAA,MAAM,KAAA,CAAM,KAAA;AAEZ,EAAA,IAAI,KAAA,KAAU,SAAA,IAAa,CAAC,KAAA,CAAM,QAAA,EAAU;AAC1C,IAAA,KAAA,CAAM,QAAA,GAAW,IAAA;AACjB,IAAA,MAAM,cAAc,GAAG,CAAA;AAAA,EACzB;AACF,CAAA;AAEO,IAAM,gBAAgB,CAAC,UAAA,GAA8B,EAAC,KAC3D,OAAO,OAAO,OAAA,KAAY;AACxB,EAAA,MAAM,gBAAgB,KAAK,CAAA;AAC3B,EAAA,OAAO,OAAO,UAAA,KAAe,UAAA,GAAa,UAAA,CAAW,KAAA,EAAO,OAAO,CAAA,GAAI,UAAA;AACzE","file":"next.js","sourcesContent":["import { existsSync } from 'fs';\nimport path from 'path';\nimport { createJiti } from 'jiti';\nimport type { AmplifyConfig } from '../config';\n\nconst CONFIG_FILES = [\n 'amplifyup.config.ts',\n 'amplifyup.config.mts',\n 'amplifyup.config.mjs',\n 'amplifyup.config.js',\n 'amplifyup.config.cjs',\n];\n\nexport type ResolvedComponentsConfig = {\n cwd: string;\n /** Absolute component folders. */\n roots: string[];\n exclude: string[];\n /** Absolute generated file path, extension included. */\n outputFile: string;\n /** Config file that was loaded, if any. */\n configFile?: string;\n};\n\nconst findConfigFile = (cwd: string): string | undefined =>\n CONFIG_FILES.map((name) => path.join(cwd, name)).find((file) => existsSync(file));\n\nconst defaultRoots = (cwd: string): string[] =>\n existsSync(path.join(cwd, 'src')) ? ['src/components'] : ['components'];\n\nconst defaultOutput = (firstRoot: string): string =>\n path.join(path.dirname(firstRoot), '.amplifyup', 'component-registry');\n\n/** TS projects get `.tsx`; plain JS projects get `.jsx` so Next doesn't switch them to TypeScript. */\nconst outputExtension = (cwd: string): string =>\n existsSync(path.join(cwd, 'tsconfig.json')) ? '.tsx' : '.jsx';\n\nexport const loadComponentsConfig = async (\n cwd: string\n): Promise<ResolvedComponentsConfig> => {\n const configFile = findConfigFile(cwd);\n let config: AmplifyConfig = {};\n\n if (configFile) {\n const jiti = createJiti(path.join(cwd, 'amplifyup.config.loader'));\n config = (await jiti.import<AmplifyConfig>(configFile, { default: true })) ?? {};\n }\n\n const components = config.components ?? {};\n const roots = components.roots?.length ? components.roots : defaultRoots(cwd);\n const output = components.output ?? defaultOutput(roots[0]);\n\n return {\n cwd,\n roots: roots.map((root) => path.resolve(cwd, root)),\n exclude: components.exclude ?? [],\n outputFile: path.resolve(cwd, output) + outputExtension(cwd),\n configFile,\n };\n};\n","/**\n * One matching rule for layout component IDs and component file names, so\n * `Hero`, `hero`, `HERO` and `e2e-hero` / `E2eHero` resolve to the same entry.\n */\nexport const componentKey = (id: string): string =>\n id.toLowerCase().replace(/[^a-z0-9]/g, '');\n","import { existsSync, readFileSync } from 'fs';\nimport path from 'path';\nimport { glob } from 'tinyglobby';\nimport { componentKey } from '../component-key';\nimport type { ResolvedComponentsConfig } from './load-config';\n\nconst ALWAYS_EXCLUDE = [\n '**/*.test.*',\n '**/*.spec.*',\n '**/*.stories.*',\n '**/*.d.ts',\n '**/__tests__/**',\n '**/__mocks__/**',\n];\n\nexport type RegistryEntry = {\n /** Registry name — the file (or folder, for `index` files) name. */\n name: string;\n key: string;\n /** Absolute file path. */\n file: string;\n /** `default`, or the named export that is the component. */\n exportName: string;\n};\n\nexport type SkippedFile = {\n file: string;\n reason: string;\n};\n\nexport type ScanResult = {\n entries: RegistryEntry[];\n skipped: SkippedFile[];\n missingRoots: string[];\n};\n\nexport class ComponentRegistryError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'ComponentRegistryError';\n }\n}\n\nconst NAMED_DECLARATION =\n /export\\s+(?:declare\\s+)?(?:async\\s+)?(?:const|let|var|function\\*?|class)\\s+([A-Za-z_$][\\w$]*)/g;\n\nconst EXPORT_LIST = /export\\s*\\{([^}]*)\\}/g;\n\n/** Export names a file declares, read from source (no type checking needed). */\nconst readExports = (source: string): { hasDefault: boolean; named: string[] } => {\n const named: string[] = [];\n let hasDefault = /export\\s+default\\b/.test(source);\n\n for (const match of source.matchAll(NAMED_DECLARATION)) {\n named.push(match[1]);\n }\n\n for (const match of source.matchAll(EXPORT_LIST)) {\n for (const part of match[1].split(',')) {\n const spec = part.trim();\n if (!spec || spec.startsWith('type ')) continue;\n\n const exported = spec.split(/\\s+as\\s+/).pop()!.trim();\n if (exported === 'default') {\n hasDefault = true;\n } else {\n named.push(exported);\n }\n }\n }\n\n return { hasDefault, named };\n};\n\nconst entryName = (file: string, root: string): string | null => {\n const base = path.basename(file, path.extname(file));\n if (base !== 'index') return base;\n\n // `components/index.tsx` is a barrel, not a component.\n const dir = path.dirname(file);\n return dir === root ? null : path.basename(dir);\n};\n\n/** `Hero/index.tsx` and `Hero/Hero.tsx` describe one component — keep the index. */\nconst isIndexPair = (a: RegistryEntry, b: RegistryEntry): boolean =>\n path.dirname(a.file) === path.dirname(b.file) &&\n [a, b].some((entry) => path.basename(entry.file).startsWith('index.'));\n\nconst toEntry = (\n file: string,\n root: string\n): RegistryEntry | SkippedFile | null => {\n const name = entryName(file, root);\n if (!name) return null;\n\n const key = componentKey(name);\n const { hasDefault, named } = readExports(readFileSync(file, 'utf8'));\n const exportName = hasDefault\n ? 'default'\n : named.find((exported) => componentKey(exported) === key);\n\n if (!exportName) {\n return {\n file,\n reason: `no default export or export named \"${name}\"`,\n };\n }\n\n return { name, key, file, exportName };\n};\n\nexport const scanComponents = async (\n config: ResolvedComponentsConfig\n): Promise<ScanResult> => {\n const byKey = new Map<string, RegistryEntry>();\n const skipped: SkippedFile[] = [];\n const missingRoots: string[] = [];\n\n for (const root of config.roots) {\n if (!existsSync(root)) {\n missingRoots.push(root);\n continue;\n }\n\n const files = await glob(['**/*.{tsx,jsx,js}'], {\n cwd: root,\n ignore: [...ALWAYS_EXCLUDE, ...config.exclude],\n absolute: true,\n });\n\n for (const file of files.map((f) => path.resolve(f)).sort()) {\n const result = toEntry(file, root);\n if (!result) continue;\n\n if (!('key' in result)) {\n skipped.push(result);\n continue;\n }\n\n const existing = byKey.get(result.key);\n if (!existing) {\n byKey.set(result.key, result);\n continue;\n }\n\n if (isIndexPair(existing, result)) {\n const keepResult = path.basename(result.file).startsWith('index.');\n if (keepResult) byKey.set(result.key, result);\n continue;\n }\n\n throw new ComponentRegistryError(\n `Two components resolve to the same name \"${result.name}\":\\n` +\n ` ${path.relative(config.cwd, existing.file)}\\n` +\n ` ${path.relative(config.cwd, result.file)}\\n` +\n 'Rename one of them, or add it to components.exclude in amplifyup.config.ts.'\n );\n }\n }\n\n const entries = [...byKey.values()].sort((a, b) => a.name.localeCompare(b.name));\n return { entries, skipped, missingRoots };\n};\n","import path from 'path';\nimport type { RegistryEntry } from './scan-components';\n\nconst importPath = (fromFile: string, toFile: string): string => {\n const withoutExt = toFile.slice(0, toFile.length - path.extname(toFile).length);\n const relative = path\n .relative(path.dirname(fromFile), withoutExt)\n .split(path.sep)\n .join('/')\n .replace(/\\/index$/, '');\n return relative.startsWith('.') ? relative : `./${relative}`;\n};\n\nconst importLine = (entry: RegistryEntry, local: string, outputFile: string): string => {\n const from = JSON.stringify(importPath(outputFile, entry.file));\n return entry.exportName === 'default'\n ? `import ${local} from ${from};`\n : `import { ${entry.exportName} as ${local} } from ${from};`;\n};\n\n/** Source of the generated component registry module. Stable for unchanged input. */\nexport const renderRegistrySource = (\n entries: RegistryEntry[],\n outputFile: string\n): string => {\n const imports = entries.map((entry, i) => importLine(entry, `C${i}`, outputFile));\n const members = entries.map((entry, i) => ` ${JSON.stringify(entry.name)}: C${i},`);\n\n return [\n \"'use client';\",\n '',\n '// Generated by Amplify UP from your components folder. Do not edit —',\n '// add, rename or delete component files instead.',\n '',\n \"import { defineComponentRegistry, bindAmplifyPage } from '@amplifyup/sdk/react';\",\n ...imports,\n '',\n 'export const componentRegistry = defineComponentRegistry({',\n ...members,\n '});',\n '',\n 'export const AmplifyPage = bindAmplifyPage(componentRegistry);',\n '',\n ].join('\\n');\n};\n","import { existsSync, mkdirSync, readFileSync, watch, writeFileSync, type FSWatcher } from 'fs';\nimport path from 'path';\nimport { loadComponentsConfig, type ResolvedComponentsConfig } from './load-config';\nimport { scanComponents, type ScanResult } from './scan-components';\nimport { renderRegistrySource } from './render-registry';\n\nconst LOG_PREFIX = '[Amplify UP]';\nconst WATCH_DEBOUNCE_MS = 120;\n\nexport type BuildRegistryResult = ScanResult & {\n outputFile: string;\n /** False when the file already had this content (no rewrite, no HMR churn). */\n changed: boolean;\n};\n\nconst writeIfChanged = (file: string, content: string): boolean => {\n if (existsSync(file) && readFileSync(file, 'utf8') === content) return false;\n\n mkdirSync(path.dirname(file), { recursive: true });\n writeFileSync(file, content);\n return true;\n};\n\n/** The generated folder ignores itself, so sites never commit it. */\nconst ensureSelfIgnored = (outputFile: string): void => {\n const dir = path.dirname(outputFile);\n if (path.basename(dir) !== '.amplifyup') return;\n writeIfChanged(path.join(dir, '.gitignore'), '*\\n');\n};\n\nexport const buildRegistryFromConfig = async (\n config: ResolvedComponentsConfig\n): Promise<BuildRegistryResult> => {\n const scan = await scanComponents(config);\n const source = renderRegistrySource(scan.entries, config.outputFile);\n\n const changed = writeIfChanged(config.outputFile, source);\n ensureSelfIgnored(config.outputFile);\n\n return { ...scan, outputFile: config.outputFile, changed };\n};\n\nexport const buildRegistry = async (cwd: string): Promise<BuildRegistryResult> =>\n buildRegistryFromConfig(await loadComponentsConfig(cwd));\n\nexport const reportRegistry = (result: BuildRegistryResult, cwd: string): void => {\n const rel = (file: string) => path.relative(cwd, file) || '.';\n\n for (const root of result.missingRoots) {\n console.warn(`${LOG_PREFIX} Components folder not found: ${rel(root)}`);\n }\n\n for (const skip of result.skipped) {\n console.warn(`${LOG_PREFIX} Skipped ${rel(skip.file)}: ${skip.reason}`);\n }\n\n console.log(\n `${LOG_PREFIX} Component registry: ${result.entries.length} component(s) → ${rel(result.outputFile)}`\n );\n};\n\n/** Regenerates on add/remove/rename. Returns a function that stops watching. */\nexport const watchRegistry = async (cwd: string): Promise<() => void> => {\n const config = await loadComponentsConfig(cwd);\n const watchers: FSWatcher[] = [];\n let timer: ReturnType<typeof setTimeout> | undefined;\n\n const rebuild = () => {\n clearTimeout(timer);\n timer = setTimeout(() => {\n buildRegistryFromConfig(config)\n .then((result) => {\n if (result.changed) reportRegistry(result, cwd);\n })\n .catch((error: unknown) => {\n console.error(`${LOG_PREFIX} Component registry update failed:`, error);\n });\n }, WATCH_DEBOUNCE_MS);\n };\n\n for (const root of config.roots.filter((r) => existsSync(r))) {\n watchers.push(watch(root, { recursive: true }, rebuild));\n }\n\n return () => {\n clearTimeout(timer);\n watchers.forEach((watcher) => watcher.close());\n };\n};\n","/**\n * `withAmplifyUp(nextConfig)` — builds the component registry whenever Next\n * loads its config (`next build`, `next dev`) and keeps it current during dev.\n */\nimport { buildRegistry, reportRegistry, watchRegistry } from './cli/build-registry';\n\ntype NextConfigObject = Record<string, unknown>;\n\ntype NextConfigContext = {\n defaultConfig: NextConfigObject;\n};\n\ntype NextConfigFunction = (\n phase: string,\n context: NextConfigContext\n) => NextConfigObject | Promise<NextConfigObject>;\n\ntype NextConfigInput = NextConfigObject | NextConfigFunction;\n\nconst DEV_PHASE = 'phase-development-server';\n\ntype RegistryState = {\n built?: Promise<void>;\n watching?: boolean;\n};\n\n// Next loads its config more than once per process; build and watch only once.\nconst STATE_KEY = Symbol.for('amplifyup.registryBuild');\n\nconst registryState = (): RegistryState => {\n const store = globalThis as typeof globalThis & { [STATE_KEY]?: RegistryState };\n store[STATE_KEY] ??= {};\n return store[STATE_KEY]!;\n};\n\nconst prepareRegistry = async (phase: string): Promise<void> => {\n const cwd = process.cwd();\n const state = registryState();\n\n state.built ??= buildRegistry(cwd).then((result) => reportRegistry(result, cwd));\n await state.built;\n\n if (phase === DEV_PHASE && !state.watching) {\n state.watching = true;\n await watchRegistry(cwd);\n }\n};\n\nexport const withAmplifyUp = (nextConfig: NextConfigInput = {}): NextConfigFunction =>\n async (phase, context) => {\n await prepareRegistry(phase);\n return typeof nextConfig === 'function' ? nextConfig(phase, context) : nextConfig;\n };\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/registry/load-config.ts","../src/component-key.ts","../src/registry/scan-components.ts","../src/registry/scan-packages.ts","../src/registry/render-registry.ts","../src/registry/build-registry.ts","../src/next.ts"],"names":["path","existsSync","jiti","createJiti","readFileSync","glob","semver","mkdirSync","writeFileSync","watch"],"mappings":";;;;;;;;;;;;;;;AAKA,IAAM,YAAA,GAAe;AAAA,EACnB,qBAAA;AAAA,EACA,sBAAA;AAAA,EACA,sBAAA;AAAA,EACA,qBAAA;AAAA,EACA;AACF,CAAA;AAaA,IAAM,iBAAiB,CAAC,GAAA,KACtB,aAAa,GAAA,CAAI,CAAC,SAASA,sBAAA,CAAK,IAAA,CAAK,GAAA,EAAK,IAAI,CAAC,CAAA,CAAE,IAAA,CAAK,CAAC,IAAA,KAASC,aAAA,CAAW,IAAI,CAAC,CAAA;AAElF,IAAM,YAAA,GAAe,CAAC,GAAA,KACpBA,aAAA,CAAWD,uBAAK,IAAA,CAAK,GAAA,EAAK,KAAK,CAAC,CAAA,GAAI,CAAC,gBAAgB,CAAA,GAAI,CAAC,YAAY,CAAA;AAExE,IAAM,aAAA,GAAgB,CAAC,SAAA,KACrBA,sBAAA,CAAK,IAAA,CAAKA,uBAAK,OAAA,CAAQ,SAAS,CAAA,EAAG,YAAA,EAAc,oBAAoB,CAAA;AAGvE,IAAM,eAAA,GAAkB,CAAC,GAAA,KACvBC,aAAA,CAAWD,sBAAA,CAAK,KAAK,GAAA,EAAK,eAAe,CAAC,CAAA,GAAI,MAAA,GAAS,MAAA;AAElD,IAAM,oBAAA,GAAuB,OAClC,GAAA,KACsC;AACtC,EAAA,MAAM,UAAA,GAAa,eAAe,GAAG,CAAA;AACrC,EAAA,IAAI,SAAwB,EAAC;AAE7B,EAA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from 'jiti';\nimport type { AmplifyConfig } from '../config';\n\nconst CONFIG_FILES = [\n 'amplifyup.config.ts',\n 'amplifyup.config.mts',\n 'amplifyup.config.mjs',\n 'amplifyup.config.js',\n 'amplifyup.config.cjs',\n];\n\nexport type ResolvedComponentsConfig = {\n cwd: string;\n /** Absolute component folders. */\n roots: string[];\n exclude: string[];\n /** Absolute generated file path, extension included. */\n outputFile: string;\n /** Config file that was loaded, if any. */\n configFile?: string;\n};\n\nconst findConfigFile = (cwd: string): string | undefined =>\n CONFIG_FILES.map((name) => path.join(cwd, name)).find((file) => existsSync(file));\n\nconst defaultRoots = (cwd: string): string[] =>\n existsSync(path.join(cwd, 'src')) ? ['src/components'] : ['components'];\n\nconst defaultOutput = (firstRoot: string): string =>\n path.join(path.dirname(firstRoot), '.amplifyup', 'component-registry');\n\n/** TS projects get `.tsx`; plain JS projects get `.jsx` so Next doesn't switch them to TypeScript. */\nconst outputExtension = (cwd: string): string =>\n existsSync(path.join(cwd, 'tsconfig.json')) ? '.tsx' : '.jsx';\n\nexport const loadComponentsConfig = async (\n cwd: string\n): Promise<ResolvedComponentsConfig> => {\n const configFile = findConfigFile(cwd);\n let config: AmplifyConfig = {};\n\n if (configFile) {\n const jiti = createJiti(path.join(cwd, 'amplifyup.config.loader'));\n config = (await jiti.import<AmplifyConfig>(configFile, { default: true })) ?? {};\n }\n\n const components = config.components ?? {};\n const roots = components.roots?.length ? components.roots : defaultRoots(cwd);\n const output = components.output ?? defaultOutput(roots[0]);\n\n return {\n cwd,\n roots: roots.map((root) => path.resolve(cwd, root)),\n exclude: components.exclude ?? [],\n outputFile: path.resolve(cwd, output) + outputExtension(cwd),\n configFile,\n };\n};\n","/**\n * One matching rule for layout component IDs and component file names, so\n * `Hero`, `hero`, `HERO` and `e2e-hero` / `E2eHero` resolve to the same entry.\n */\nexport const componentKey = (id: string): string =>\n id.toLowerCase().replace(/[^a-z0-9]/g, '');\n","import { existsSync, readFileSync } from 'fs';\nimport path from 'path';\nimport { glob } from 'tinyglobby';\nimport { componentKey } from '../component-key';\nimport type { ResolvedComponentsConfig } from './load-config';\n\nconst ALWAYS_EXCLUDE = [\n '**/*.test.*',\n '**/*.spec.*',\n '**/*.stories.*',\n '**/*.d.ts',\n '**/__tests__/**',\n '**/__mocks__/**',\n];\n\nexport type RegistryEntry = {\n /** Registry name — the file (or folder, for `index` files) name. */\n name: string;\n key: string;\n /** Absolute file path (the package manifest, for package components). */\n file: string;\n /** `default`, or the named export that is the component. */\n exportName: string;\n /** Package to import from, for components shipped by an installed package. */\n module?: string;\n};\n\nexport type SkippedFile = {\n file: string;\n reason: string;\n};\n\nexport type ScanResult = {\n entries: RegistryEntry[];\n skipped: SkippedFile[];\n missingRoots: string[];\n};\n\nexport class ComponentRegistryError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'ComponentRegistryError';\n }\n}\n\nconst NAMED_DECLARATION =\n /export\\s+(?:declare\\s+)?(?:async\\s+)?(?:const|let|var|function\\*?|class)\\s+([A-Za-z_$][\\w$]*)/g;\n\nconst EXPORT_LIST = /export\\s*\\{([^}]*)\\}/g;\n\n/** Export names a file declares, read from source (no type checking needed). */\nconst readExports = (source: string): { hasDefault: boolean; named: string[] } => {\n const named: string[] = [];\n let hasDefault = /export\\s+default\\b/.test(source);\n\n for (const match of source.matchAll(NAMED_DECLARATION)) {\n named.push(match[1]);\n }\n\n for (const match of source.matchAll(EXPORT_LIST)) {\n for (const part of match[1].split(',')) {\n const spec = part.trim();\n if (!spec || spec.startsWith('type ')) continue;\n\n const exported = spec.split(/\\s+as\\s+/).pop()!.trim();\n if (exported === 'default') {\n hasDefault = true;\n } else {\n named.push(exported);\n }\n }\n }\n\n return { hasDefault, named };\n};\n\nconst entryName = (file: string, root: string): string | null => {\n const base = path.basename(file, path.extname(file));\n if (base !== 'index') return base;\n\n // `components/index.tsx` is a barrel, not a component.\n const dir = path.dirname(file);\n return dir === root ? null : path.basename(dir);\n};\n\n/** `Hero/index.tsx` and `Hero/Hero.tsx` describe one component — keep the index. */\nconst isIndexPair = (a: RegistryEntry, b: RegistryEntry): boolean =>\n path.dirname(a.file) === path.dirname(b.file) &&\n [a, b].some((entry) => path.basename(entry.file).startsWith('index.'));\n\nconst toEntry = (\n file: string,\n root: string\n): RegistryEntry | SkippedFile | null => {\n const name = entryName(file, root);\n if (!name) return null;\n\n const key = componentKey(name);\n const { hasDefault, named } = readExports(readFileSync(file, 'utf8'));\n const exportName = hasDefault\n ? 'default'\n : named.find((exported) => componentKey(exported) === key);\n\n if (!exportName) {\n return {\n file,\n reason: `no default export or export named \"${name}\"`,\n };\n }\n\n return { name, key, file, exportName };\n};\n\nexport const scanComponents = async (\n config: ResolvedComponentsConfig\n): Promise<ScanResult> => {\n const byKey = new Map<string, RegistryEntry>();\n const skipped: SkippedFile[] = [];\n const missingRoots: string[] = [];\n\n for (const root of config.roots) {\n if (!existsSync(root)) {\n missingRoots.push(root);\n continue;\n }\n\n const files = await glob(['**/*.{tsx,jsx,js}'], {\n cwd: root,\n ignore: [...ALWAYS_EXCLUDE, ...config.exclude],\n absolute: true,\n });\n\n for (const file of files.map((f) => path.resolve(f)).sort()) {\n const result = toEntry(file, root);\n if (!result) continue;\n\n if (!('key' in result)) {\n skipped.push(result);\n continue;\n }\n\n const existing = byKey.get(result.key);\n if (!existing) {\n byKey.set(result.key, result);\n continue;\n }\n\n if (isIndexPair(existing, result)) {\n const keepResult = path.basename(result.file).startsWith('index.');\n if (keepResult) byKey.set(result.key, result);\n continue;\n }\n\n throw new ComponentRegistryError(\n `Two components resolve to the same name \"${result.name}\":\\n` +\n ` ${path.relative(config.cwd, existing.file)}\\n` +\n ` ${path.relative(config.cwd, result.file)}\\n` +\n 'Rename one of them, or add it to components.exclude in amplifyup.config.ts.'\n );\n }\n }\n\n const entries = [...byKey.values()].sort((a, b) => a.name.localeCompare(b.name));\n return { entries, skipped, missingRoots };\n};\n","import { existsSync, readFileSync } from 'fs';\nimport path from 'path';\nimport semver from 'semver';\nimport { componentKey } from '../component-key';\nimport type { RegistryEntry } from './scan-components';\n\nconst SDK_PACKAGE = '@amplifyup/sdk';\n\ntype PackageJson = {\n name?: string;\n version?: string;\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n peerDependencies?: Record<string, string>;\n amplifyup?: { manifest?: string };\n};\n\ntype ManifestComponent = {\n component_id?: unknown;\n export_name?: unknown;\n};\n\ntype PackageManifestFile = {\n components?: ManifestComponent[];\n};\n\nexport type PackageScanResult = {\n entries: RegistryEntry[];\n warnings: string[];\n};\n\nconst readJson = <T>(file: string): T => JSON.parse(readFileSync(file, 'utf8')) as T;\n\n/** Installed copy of a dependency, found the way Node resolves it (walking up node_modules). */\nconst findInstalledPackage = (cwd: string, name: string): string | null => {\n let dir = cwd;\n\n while (true) {\n const candidate = path.join(dir, 'node_modules', name, 'package.json');\n if (existsSync(candidate)) return candidate;\n\n const parent = path.dirname(dir);\n if (parent === dir) return null;\n dir = parent;\n }\n};\n\nconst peerWarning = (pkg: PackageJson, sdkVersion: string | undefined): string | null => {\n const range = pkg.peerDependencies?.[SDK_PACKAGE];\n if (!range || !sdkVersion) return null;\n if (semver.satisfies(sdkVersion, range, { includePrerelease: true })) return null;\n\n return `${pkg.name} expects ${SDK_PACKAGE} ${range}, but ${sdkVersion} is installed. Update one of them.`;\n};\n\nconst manifestEntries = (\n dependency: string,\n manifestFile: string,\n warnings: string[]\n): RegistryEntry[] => {\n const manifest = readJson<PackageManifestFile>(manifestFile);\n const entries: RegistryEntry[] = [];\n\n for (const component of manifest.components ?? []) {\n const { component_id: id, export_name: exportName } = component;\n if (typeof id !== 'string' || typeof exportName !== 'string') {\n warnings.push(`${dependency}: skipped a manifest component without component_id and export_name`);\n continue;\n }\n\n entries.push({\n name: id,\n key: componentKey(id),\n file: manifestFile,\n exportName,\n module: dependency,\n });\n }\n\n return entries;\n};\n\n/**\n * Components shipped by the site's direct dependencies. A package opts in with\n * `\"amplifyup\": { \"manifest\": \"./dist/amplifyup.manifest.json\" }` in its package.json.\n */\nexport const scanPackages = (cwd: string): PackageScanResult => {\n const siteManifest = path.join(cwd, 'package.json');\n if (!existsSync(siteManifest)) return { entries: [], warnings: [] };\n\n const site = readJson<PackageJson>(siteManifest);\n const dependencies = Object.keys({ ...site.devDependencies, ...site.dependencies }).sort();\n const sdkPackageFile = findInstalledPackage(cwd, SDK_PACKAGE);\n const sdkVersion = sdkPackageFile ? readJson<PackageJson>(sdkPackageFile).version : undefined;\n\n const entries: RegistryEntry[] = [];\n const warnings: string[] = [];\n\n for (const dependency of dependencies) {\n const packageFile = findInstalledPackage(cwd, dependency);\n if (!packageFile) continue;\n\n const pkg = readJson<PackageJson>(packageFile);\n const manifestPath = pkg.amplifyup?.manifest;\n if (!manifestPath) continue;\n\n const manifestFile = path.resolve(path.dirname(packageFile), manifestPath);\n if (!existsSync(manifestFile)) {\n warnings.push(`${dependency}: component manifest not found at ${manifestPath}`);\n continue;\n }\n\n const warning = peerWarning(pkg, sdkVersion);\n if (warning) warnings.push(warning);\n\n entries.push(...manifestEntries(dependency, manifestFile, warnings));\n }\n\n return { entries, warnings };\n};\n","import path from 'path';\nimport type { RegistryEntry } from './scan-components';\n\nconst importPath = (fromFile: string, toFile: string): string => {\n const withoutExt = toFile.slice(0, toFile.length - path.extname(toFile).length);\n const relative = path\n .relative(path.dirname(fromFile), withoutExt)\n .split(path.sep)\n .join('/')\n .replace(/\\/index$/, '');\n return relative.startsWith('.') ? relative : `./${relative}`;\n};\n\nconst importLine = (entry: RegistryEntry, local: string, outputFile: string): string => {\n const from = JSON.stringify(entry.module ?? importPath(outputFile, entry.file));\n return entry.exportName === 'default'\n ? `import ${local} from ${from};`\n : `import { ${entry.exportName} as ${local} } from ${from};`;\n};\n\n/** Source of the generated component registry module. Stable for unchanged input. */\nexport const renderRegistrySource = (\n entries: RegistryEntry[],\n outputFile: string\n): string => {\n const imports = entries.map((entry, i) => importLine(entry, `C${i}`, outputFile));\n const members = entries.map((entry, i) => ` ${JSON.stringify(entry.name)}: C${i},`);\n\n return [\n \"'use client';\",\n '',\n '// Generated by Amplify UP from your components folder and installed component',\n '// packages. Do not edit — add, rename or delete component files instead.',\n '',\n \"import { defineComponentRegistry, bindAmplifyPage } from '@amplifyup/sdk/react';\",\n ...imports,\n '',\n 'export const componentRegistry = defineComponentRegistry({',\n ...members,\n '});',\n '',\n 'export const AmplifyPage = bindAmplifyPage(componentRegistry);',\n '',\n ].join('\\n');\n};\n","import { existsSync, mkdirSync, readFileSync, watch, writeFileSync, type FSWatcher } from 'fs';\nimport path from 'path';\nimport { loadComponentsConfig, type ResolvedComponentsConfig } from './load-config';\nimport { ComponentRegistryError, scanComponents, type RegistryEntry, type ScanResult } from './scan-components';\nimport { scanPackages } from './scan-packages';\nimport { renderRegistrySource } from './render-registry';\n\nconst LOG_PREFIX = '[Amplify UP]';\nconst WATCH_DEBOUNCE_MS = 120;\n\nexport type BuildRegistryResult = ScanResult & {\n outputFile: string;\n /** Problems with installed component packages; the build still succeeds. */\n warnings: string[];\n /** False when the file already had this content (no rewrite, no HMR churn). */\n changed: boolean;\n};\n\nconst writeIfChanged = (file: string, content: string): boolean => {\n if (existsSync(file) && readFileSync(file, 'utf8') === content) return false;\n\n mkdirSync(path.dirname(file), { recursive: true });\n writeFileSync(file, content);\n return true;\n};\n\n/** The generated folder ignores itself, so sites never commit it. */\nconst ensureSelfIgnored = (outputFile: string): void => {\n const dir = path.dirname(outputFile);\n if (path.basename(dir) !== '.amplifyup') return;\n writeIfChanged(path.join(dir, '.gitignore'), '*\\n');\n};\n\nconst describeEntry = (entry: RegistryEntry, cwd: string): string =>\n entry.module ? `${entry.module} (installed package)` : path.relative(cwd, entry.file);\n\n/** Local components plus installed package components; one name may only resolve once. */\nconst mergeEntries = (\n local: RegistryEntry[],\n packaged: RegistryEntry[],\n cwd: string\n): RegistryEntry[] => {\n const byKey = new Map(local.map((entry) => [entry.key, entry]));\n\n for (const entry of packaged) {\n const existing = byKey.get(entry.key);\n if (existing) {\n throw new ComponentRegistryError(\n `Two components resolve to the same name \"${entry.name}\":\\n` +\n ` ${describeEntry(existing, cwd)}\\n` +\n ` ${describeEntry(entry, cwd)}\\n` +\n 'Rename the local component, or remove one of the packages.'\n );\n }\n byKey.set(entry.key, entry);\n }\n\n return [...byKey.values()].sort((a, b) => a.name.localeCompare(b.name));\n};\n\nexport const buildRegistryFromConfig = async (\n config: ResolvedComponentsConfig\n): Promise<BuildRegistryResult> => {\n const scan = await scanComponents(config);\n const packages = scanPackages(config.cwd);\n const entries = mergeEntries(scan.entries, packages.entries, config.cwd);\n const source = renderRegistrySource(entries, config.outputFile);\n\n const changed = writeIfChanged(config.outputFile, source);\n ensureSelfIgnored(config.outputFile);\n\n return {\n ...scan,\n entries,\n warnings: packages.warnings,\n outputFile: config.outputFile,\n changed,\n };\n};\n\nexport const buildRegistry = async (cwd: string): Promise<BuildRegistryResult> =>\n buildRegistryFromConfig(await loadComponentsConfig(cwd));\n\nexport const reportRegistry = (result: BuildRegistryResult, cwd: string): void => {\n const rel = (file: string) => path.relative(cwd, file) || '.';\n\n for (const root of result.missingRoots) {\n console.warn(`${LOG_PREFIX} Components folder not found: ${rel(root)}`);\n }\n\n for (const warning of result.warnings) {\n console.warn(`${LOG_PREFIX} ${warning}`);\n }\n\n for (const skip of result.skipped) {\n console.warn(`${LOG_PREFIX} Skipped ${rel(skip.file)}: ${skip.reason}`);\n }\n\n console.log(\n `${LOG_PREFIX} Component registry: ${result.entries.length} component(s) → ${rel(result.outputFile)}`\n );\n};\n\n/** Regenerates on add/remove/rename. Returns a function that stops watching. */\nexport const watchRegistry = async (cwd: string): Promise<() => void> => {\n const config = await loadComponentsConfig(cwd);\n const watchers: FSWatcher[] = [];\n let timer: ReturnType<typeof setTimeout> | undefined;\n\n const rebuild = () => {\n clearTimeout(timer);\n timer = setTimeout(() => {\n buildRegistryFromConfig(config)\n .then((result) => {\n if (result.changed) reportRegistry(result, cwd);\n })\n .catch((error: unknown) => {\n console.error(`${LOG_PREFIX} Component registry update failed:`, error);\n });\n }, WATCH_DEBOUNCE_MS);\n };\n\n for (const root of config.roots.filter((r) => existsSync(r))) {\n watchers.push(watch(root, { recursive: true }, rebuild));\n }\n\n return () => {\n clearTimeout(timer);\n watchers.forEach((watcher) => watcher.close());\n };\n};\n","/**\n * `withAmplifyUp(nextConfig)` — builds the component registry whenever Next\n * loads its config (`next build`, `next dev`) and keeps it current during dev.\n */\nimport { buildRegistry, reportRegistry, watchRegistry } from './registry/build-registry';\n\ntype NextConfigObject = Record<string, unknown>;\n\ntype NextConfigContext = {\n defaultConfig: NextConfigObject;\n};\n\ntype NextConfigFunction = (\n phase: string,\n context: NextConfigContext\n) => NextConfigObject | Promise<NextConfigObject>;\n\ntype NextConfigInput = NextConfigObject | NextConfigFunction;\n\nconst DEV_PHASE = 'phase-development-server';\n\ntype RegistryState = {\n built?: Promise<void>;\n watching?: boolean;\n};\n\n// Next loads its config more than once per process; build and watch only once.\nconst STATE_KEY = Symbol.for('amplifyup.registryBuild');\n\nconst registryState = (): RegistryState => {\n const store = globalThis as typeof globalThis & { [STATE_KEY]?: RegistryState };\n store[STATE_KEY] ??= {};\n return store[STATE_KEY]!;\n};\n\nconst prepareRegistry = async (phase: string): Promise<void> => {\n const cwd = process.cwd();\n const state = registryState();\n\n state.built ??= buildRegistry(cwd).then((result) => reportRegistry(result, cwd));\n await state.built;\n\n if (phase === DEV_PHASE && !state.watching) {\n state.watching = true;\n await watchRegistry(cwd);\n }\n};\n\nexport const withAmplifyUp = (nextConfig: NextConfigInput = {}): NextConfigFunction =>\n async (phase, context) => {\n await prepareRegistry(phase);\n return typeof nextConfig === 'function' ? nextConfig(phase, context) : nextConfig;\n };\n"]}
|
package/dist/next.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import { existsSync, watch, readFileSync, mkdirSync, writeFileSync } from 'fs';
|
|
|
2
2
|
import path2 from 'path';
|
|
3
3
|
import { createJiti } from 'jiti';
|
|
4
4
|
import { glob } from 'tinyglobby';
|
|
5
|
+
import semver from 'semver';
|
|
5
6
|
|
|
6
7
|
/* @amplifyup/sdk - https://amplifyup.ai */
|
|
7
8
|
|
|
@@ -38,7 +39,7 @@ var loadComponentsConfig = async (cwd) => {
|
|
|
38
39
|
// src/component-key.ts
|
|
39
40
|
var componentKey = (id) => id.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
40
41
|
|
|
41
|
-
// src/
|
|
42
|
+
// src/registry/scan-components.ts
|
|
42
43
|
var ALWAYS_EXCLUDE = [
|
|
43
44
|
"**/*.test.*",
|
|
44
45
|
"**/*.spec.*",
|
|
@@ -138,13 +139,76 @@ Rename one of them, or add it to components.exclude in amplifyup.config.ts.`
|
|
|
138
139
|
const entries = [...byKey.values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
139
140
|
return { entries, skipped, missingRoots };
|
|
140
141
|
};
|
|
142
|
+
var SDK_PACKAGE = "@amplifyup/sdk";
|
|
143
|
+
var readJson = (file) => JSON.parse(readFileSync(file, "utf8"));
|
|
144
|
+
var findInstalledPackage = (cwd, name) => {
|
|
145
|
+
let dir = cwd;
|
|
146
|
+
while (true) {
|
|
147
|
+
const candidate = path2.join(dir, "node_modules", name, "package.json");
|
|
148
|
+
if (existsSync(candidate)) return candidate;
|
|
149
|
+
const parent = path2.dirname(dir);
|
|
150
|
+
if (parent === dir) return null;
|
|
151
|
+
dir = parent;
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
var peerWarning = (pkg, sdkVersion) => {
|
|
155
|
+
const range = pkg.peerDependencies?.[SDK_PACKAGE];
|
|
156
|
+
if (!range || !sdkVersion) return null;
|
|
157
|
+
if (semver.satisfies(sdkVersion, range, { includePrerelease: true })) return null;
|
|
158
|
+
return `${pkg.name} expects ${SDK_PACKAGE} ${range}, but ${sdkVersion} is installed. Update one of them.`;
|
|
159
|
+
};
|
|
160
|
+
var manifestEntries = (dependency, manifestFile, warnings) => {
|
|
161
|
+
const manifest = readJson(manifestFile);
|
|
162
|
+
const entries = [];
|
|
163
|
+
for (const component of manifest.components ?? []) {
|
|
164
|
+
const { component_id: id, export_name: exportName } = component;
|
|
165
|
+
if (typeof id !== "string" || typeof exportName !== "string") {
|
|
166
|
+
warnings.push(`${dependency}: skipped a manifest component without component_id and export_name`);
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
entries.push({
|
|
170
|
+
name: id,
|
|
171
|
+
key: componentKey(id),
|
|
172
|
+
file: manifestFile,
|
|
173
|
+
exportName,
|
|
174
|
+
module: dependency
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
return entries;
|
|
178
|
+
};
|
|
179
|
+
var scanPackages = (cwd) => {
|
|
180
|
+
const siteManifest = path2.join(cwd, "package.json");
|
|
181
|
+
if (!existsSync(siteManifest)) return { entries: [], warnings: [] };
|
|
182
|
+
const site = readJson(siteManifest);
|
|
183
|
+
const dependencies = Object.keys({ ...site.devDependencies, ...site.dependencies }).sort();
|
|
184
|
+
const sdkPackageFile = findInstalledPackage(cwd, SDK_PACKAGE);
|
|
185
|
+
const sdkVersion = sdkPackageFile ? readJson(sdkPackageFile).version : void 0;
|
|
186
|
+
const entries = [];
|
|
187
|
+
const warnings = [];
|
|
188
|
+
for (const dependency of dependencies) {
|
|
189
|
+
const packageFile = findInstalledPackage(cwd, dependency);
|
|
190
|
+
if (!packageFile) continue;
|
|
191
|
+
const pkg = readJson(packageFile);
|
|
192
|
+
const manifestPath = pkg.amplifyup?.manifest;
|
|
193
|
+
if (!manifestPath) continue;
|
|
194
|
+
const manifestFile = path2.resolve(path2.dirname(packageFile), manifestPath);
|
|
195
|
+
if (!existsSync(manifestFile)) {
|
|
196
|
+
warnings.push(`${dependency}: component manifest not found at ${manifestPath}`);
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
const warning = peerWarning(pkg, sdkVersion);
|
|
200
|
+
if (warning) warnings.push(warning);
|
|
201
|
+
entries.push(...manifestEntries(dependency, manifestFile, warnings));
|
|
202
|
+
}
|
|
203
|
+
return { entries, warnings };
|
|
204
|
+
};
|
|
141
205
|
var importPath = (fromFile, toFile) => {
|
|
142
206
|
const withoutExt = toFile.slice(0, toFile.length - path2.extname(toFile).length);
|
|
143
207
|
const relative = path2.relative(path2.dirname(fromFile), withoutExt).split(path2.sep).join("/").replace(/\/index$/, "");
|
|
144
208
|
return relative.startsWith(".") ? relative : `./${relative}`;
|
|
145
209
|
};
|
|
146
210
|
var importLine = (entry, local, outputFile) => {
|
|
147
|
-
const from = JSON.stringify(importPath(outputFile, entry.file));
|
|
211
|
+
const from = JSON.stringify(entry.module ?? importPath(outputFile, entry.file));
|
|
148
212
|
return entry.exportName === "default" ? `import ${local} from ${from};` : `import { ${entry.exportName} as ${local} } from ${from};`;
|
|
149
213
|
};
|
|
150
214
|
var renderRegistrySource = (entries, outputFile) => {
|
|
@@ -153,8 +217,8 @@ var renderRegistrySource = (entries, outputFile) => {
|
|
|
153
217
|
return [
|
|
154
218
|
"'use client';",
|
|
155
219
|
"",
|
|
156
|
-
"// Generated by Amplify UP from your components folder
|
|
157
|
-
"// add, rename or delete component files instead.",
|
|
220
|
+
"// Generated by Amplify UP from your components folder and installed component",
|
|
221
|
+
"// packages. Do not edit \u2014 add, rename or delete component files instead.",
|
|
158
222
|
"",
|
|
159
223
|
"import { defineComponentRegistry, bindAmplifyPage } from '@amplifyup/sdk/react';",
|
|
160
224
|
...imports,
|
|
@@ -168,7 +232,7 @@ var renderRegistrySource = (entries, outputFile) => {
|
|
|
168
232
|
].join("\n");
|
|
169
233
|
};
|
|
170
234
|
|
|
171
|
-
// src/
|
|
235
|
+
// src/registry/build-registry.ts
|
|
172
236
|
var LOG_PREFIX = "[Amplify UP]";
|
|
173
237
|
var WATCH_DEBOUNCE_MS = 120;
|
|
174
238
|
var writeIfChanged = (file, content) => {
|
|
@@ -182,12 +246,37 @@ var ensureSelfIgnored = (outputFile) => {
|
|
|
182
246
|
if (path2.basename(dir) !== ".amplifyup") return;
|
|
183
247
|
writeIfChanged(path2.join(dir, ".gitignore"), "*\n");
|
|
184
248
|
};
|
|
249
|
+
var describeEntry = (entry, cwd) => entry.module ? `${entry.module} (installed package)` : path2.relative(cwd, entry.file);
|
|
250
|
+
var mergeEntries = (local, packaged, cwd) => {
|
|
251
|
+
const byKey = new Map(local.map((entry) => [entry.key, entry]));
|
|
252
|
+
for (const entry of packaged) {
|
|
253
|
+
const existing = byKey.get(entry.key);
|
|
254
|
+
if (existing) {
|
|
255
|
+
throw new ComponentRegistryError(
|
|
256
|
+
`Two components resolve to the same name "${entry.name}":
|
|
257
|
+
${describeEntry(existing, cwd)}
|
|
258
|
+
${describeEntry(entry, cwd)}
|
|
259
|
+
Rename the local component, or remove one of the packages.`
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
byKey.set(entry.key, entry);
|
|
263
|
+
}
|
|
264
|
+
return [...byKey.values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
265
|
+
};
|
|
185
266
|
var buildRegistryFromConfig = async (config) => {
|
|
186
267
|
const scan = await scanComponents(config);
|
|
187
|
-
const
|
|
268
|
+
const packages = scanPackages(config.cwd);
|
|
269
|
+
const entries = mergeEntries(scan.entries, packages.entries, config.cwd);
|
|
270
|
+
const source = renderRegistrySource(entries, config.outputFile);
|
|
188
271
|
const changed = writeIfChanged(config.outputFile, source);
|
|
189
272
|
ensureSelfIgnored(config.outputFile);
|
|
190
|
-
return {
|
|
273
|
+
return {
|
|
274
|
+
...scan,
|
|
275
|
+
entries,
|
|
276
|
+
warnings: packages.warnings,
|
|
277
|
+
outputFile: config.outputFile,
|
|
278
|
+
changed
|
|
279
|
+
};
|
|
191
280
|
};
|
|
192
281
|
var buildRegistry = async (cwd) => buildRegistryFromConfig(await loadComponentsConfig(cwd));
|
|
193
282
|
var reportRegistry = (result, cwd) => {
|
|
@@ -195,6 +284,9 @@ var reportRegistry = (result, cwd) => {
|
|
|
195
284
|
for (const root of result.missingRoots) {
|
|
196
285
|
console.warn(`${LOG_PREFIX} Components folder not found: ${rel(root)}`);
|
|
197
286
|
}
|
|
287
|
+
for (const warning of result.warnings) {
|
|
288
|
+
console.warn(`${LOG_PREFIX} ${warning}`);
|
|
289
|
+
}
|
|
198
290
|
for (const skip of result.skipped) {
|
|
199
291
|
console.warn(`${LOG_PREFIX} Skipped ${rel(skip.file)}: ${skip.reason}`);
|
|
200
292
|
}
|
package/dist/next.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cli/load-config.ts","../src/component-key.ts","../src/cli/scan-components.ts","../src/cli/render-registry.ts","../src/cli/build-registry.ts","../src/next.ts"],"names":["path","existsSync","readFileSync"],"mappings":";;;;;;;AAKA,IAAM,YAAA,GAAe;AAAA,EACnB,qBAAA;AAAA,EACA,sBAAA;AAAA,EACA,sBAAA;AAAA,EACA,qBAAA;AAAA,EACA;AACF,CAAA;AAaA,IAAM,iBAAiB,CAAC,GAAA,KACtB,aAAa,GAAA,CAAI,CAAC,SAASA,KAAA,CAAK,IAAA,CAAK,GAAA,EAAK,IAAI,CAAC,CAAA,CAAE,IAAA,CAAK,CAAC,IAAA,KAAS,UAAA,CAAW,IAAI,CAAC,CAAA;AAElF,IAAM,YAAA,GAAe,CAAC,GAAA,KACpB,UAAA,CAAWA,MAAK,IAAA,CAAK,GAAA,EAAK,KAAK,CAAC,CAAA,GAAI,CAAC,gBAAgB,CAAA,GAAI,CAAC,YAAY,CAAA;AAExE,IAAM,aAAA,GAAgB,CAAC,SAAA,KACrBA,KAAA,CAAK,IAAA,CAAKA,MAAK,OAAA,CAAQ,SAAS,CAAA,EAAG,YAAA,EAAc,oBAAoB,CAAA;AAGvE,IAAM,eAAA,GAAkB,CAAC,GAAA,KACvB,UAAA,CAAWA,KAAA,CAAK,KAAK,GAAA,EAAK,eAAe,CAAC,CAAA,GAAI,MAAA,GAAS,MAAA;AAElD,IAAM,oBAAA,GAAuB,OAClC,GAAA,KACsC;AACtC,EAAA,MAAM,UAAA,GAAa,eAAe,GAAG,CAAA;AACrC,EAAA,IAAI,SAAwB,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gB,KAAK,CAAA;AAC3B,EAAA,OAAO,OAAO,UAAA,KAAe,UAAA,GAAa,UAAA,CAAW,KAAA,EAAO,OAAO,CAAA,GAAI,UAAA;AACzE","file":"next.mjs","sourcesContent":["import { existsSync } from 'fs';\nimport path from 'path';\nimport { createJiti } from 'jiti';\nimport type { AmplifyConfig } from '../config';\n\nconst CONFIG_FILES = [\n 'amplifyup.config.ts',\n 'amplifyup.config.mts',\n 'amplifyup.config.mjs',\n 'amplifyup.config.js',\n 'amplifyup.config.cjs',\n];\n\nexport type ResolvedComponentsConfig = {\n cwd: string;\n /** Absolute component folders. */\n roots: string[];\n exclude: string[];\n /** Absolute generated file path, extension included. */\n outputFile: string;\n /** Config file that was loaded, if any. */\n configFile?: string;\n};\n\nconst findConfigFile = (cwd: string): string | undefined =>\n CONFIG_FILES.map((name) => path.join(cwd, name)).find((file) => existsSync(file));\n\nconst defaultRoots = (cwd: string): string[] =>\n existsSync(path.join(cwd, 'src')) ? ['src/components'] : ['components'];\n\nconst defaultOutput = (firstRoot: string): string =>\n path.join(path.dirname(firstRoot), '.amplifyup', 'component-registry');\n\n/** TS projects get `.tsx`; plain JS projects get `.jsx` so Next doesn't switch them to TypeScript. */\nconst outputExtension = (cwd: string): string =>\n existsSync(path.join(cwd, 'tsconfig.json')) ? '.tsx' : '.jsx';\n\nexport const loadComponentsConfig = async (\n cwd: string\n): Promise<ResolvedComponentsConfig> => {\n const configFile = findConfigFile(cwd);\n let config: AmplifyConfig = {};\n\n if (configFile) {\n const jiti = createJiti(path.join(cwd, 'amplifyup.config.loader'));\n config = (await jiti.import<AmplifyConfig>(configFile, { default: true })) ?? {};\n }\n\n const components = config.components ?? {};\n const roots = components.roots?.length ? components.roots : defaultRoots(cwd);\n const output = components.output ?? defaultOutput(roots[0]);\n\n return {\n cwd,\n roots: roots.map((root) => path.resolve(cwd, root)),\n exclude: components.exclude ?? [],\n outputFile: path.resolve(cwd, output) + outputExtension(cwd),\n configFile,\n };\n};\n","/**\n * One matching rule for layout component IDs and component file names, so\n * `Hero`, `hero`, `HERO` and `e2e-hero` / `E2eHero` resolve to the same entry.\n */\nexport const componentKey = (id: string): string =>\n id.toLowerCase().replace(/[^a-z0-9]/g, '');\n","import { existsSync, readFileSync } from 'fs';\nimport path from 'path';\nimport { glob } from 'tinyglobby';\nimport { componentKey } from '../component-key';\nimport type { ResolvedComponentsConfig } from './load-config';\n\nconst ALWAYS_EXCLUDE = [\n '**/*.test.*',\n '**/*.spec.*',\n '**/*.stories.*',\n '**/*.d.ts',\n '**/__tests__/**',\n '**/__mocks__/**',\n];\n\nexport type RegistryEntry = {\n /** Registry name — the file (or folder, for `index` files) name. */\n name: string;\n key: string;\n /** Absolute file path. */\n file: string;\n /** `default`, or the named export that is the component. */\n exportName: string;\n};\n\nexport type SkippedFile = {\n file: string;\n reason: string;\n};\n\nexport type ScanResult = {\n entries: RegistryEntry[];\n skipped: SkippedFile[];\n missingRoots: string[];\n};\n\nexport class ComponentRegistryError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'ComponentRegistryError';\n }\n}\n\nconst NAMED_DECLARATION =\n /export\\s+(?:declare\\s+)?(?:async\\s+)?(?:const|let|var|function\\*?|class)\\s+([A-Za-z_$][\\w$]*)/g;\n\nconst EXPORT_LIST = /export\\s*\\{([^}]*)\\}/g;\n\n/** Export names a file declares, read from source (no type checking needed). */\nconst readExports = (source: string): { hasDefault: boolean; named: string[] } => {\n const named: string[] = [];\n let hasDefault = /export\\s+default\\b/.test(source);\n\n for (const match of source.matchAll(NAMED_DECLARATION)) {\n named.push(match[1]);\n }\n\n for (const match of source.matchAll(EXPORT_LIST)) {\n for (const part of match[1].split(',')) {\n const spec = part.trim();\n if (!spec || spec.startsWith('type ')) continue;\n\n const exported = spec.split(/\\s+as\\s+/).pop()!.trim();\n if (exported === 'default') {\n hasDefault = true;\n } else {\n named.push(exported);\n }\n }\n }\n\n return { hasDefault, named };\n};\n\nconst entryName = (file: string, root: string): string | null => {\n const base = path.basename(file, path.extname(file));\n if (base !== 'index') return base;\n\n // `components/index.tsx` is a barrel, not a component.\n const dir = path.dirname(file);\n return dir === root ? null : path.basename(dir);\n};\n\n/** `Hero/index.tsx` and `Hero/Hero.tsx` describe one component — keep the index. */\nconst isIndexPair = (a: RegistryEntry, b: RegistryEntry): boolean =>\n path.dirname(a.file) === path.dirname(b.file) &&\n [a, b].some((entry) => path.basename(entry.file).startsWith('index.'));\n\nconst toEntry = (\n file: string,\n root: string\n): RegistryEntry | SkippedFile | null => {\n const name = entryName(file, root);\n if (!name) return null;\n\n const key = componentKey(name);\n const { hasDefault, named } = readExports(readFileSync(file, 'utf8'));\n const exportName = hasDefault\n ? 'default'\n : named.find((exported) => componentKey(exported) === key);\n\n if (!exportName) {\n return {\n file,\n reason: `no default export or export named \"${name}\"`,\n };\n }\n\n return { name, key, file, exportName };\n};\n\nexport const scanComponents = async (\n config: ResolvedComponentsConfig\n): Promise<ScanResult> => {\n const byKey = new Map<string, RegistryEntry>();\n const skipped: SkippedFile[] = [];\n const missingRoots: string[] = [];\n\n for (const root of config.roots) {\n if (!existsSync(root)) {\n missingRoots.push(root);\n continue;\n }\n\n const files = await glob(['**/*.{tsx,jsx,js}'], {\n cwd: root,\n ignore: [...ALWAYS_EXCLUDE, ...config.exclude],\n absolute: true,\n });\n\n for (const file of files.map((f) => path.resolve(f)).sort()) {\n const result = toEntry(file, root);\n if (!result) continue;\n\n if (!('key' in result)) {\n skipped.push(result);\n continue;\n }\n\n const existing = byKey.get(result.key);\n if (!existing) {\n byKey.set(result.key, result);\n continue;\n }\n\n if (isIndexPair(existing, result)) {\n const keepResult = path.basename(result.file).startsWith('index.');\n if (keepResult) byKey.set(result.key, result);\n continue;\n }\n\n throw new ComponentRegistryError(\n `Two components resolve to the same name \"${result.name}\":\\n` +\n ` ${path.relative(config.cwd, existing.file)}\\n` +\n ` ${path.relative(config.cwd, result.file)}\\n` +\n 'Rename one of them, or add it to components.exclude in amplifyup.config.ts.'\n );\n }\n }\n\n const entries = [...byKey.values()].sort((a, b) => a.name.localeCompare(b.name));\n return { entries, skipped, missingRoots };\n};\n","import path from 'path';\nimport type { RegistryEntry } from './scan-components';\n\nconst importPath = (fromFile: string, toFile: string): string => {\n const withoutExt = toFile.slice(0, toFile.length - path.extname(toFile).length);\n const relative = path\n .relative(path.dirname(fromFile), withoutExt)\n .split(path.sep)\n .join('/')\n .replace(/\\/index$/, '');\n return relative.startsWith('.') ? relative : `./${relative}`;\n};\n\nconst importLine = (entry: RegistryEntry, local: string, outputFile: string): string => {\n const from = JSON.stringify(importPath(outputFile, entry.file));\n return entry.exportName === 'default'\n ? `import ${local} from ${from};`\n : `import { ${entry.exportName} as ${local} } from ${from};`;\n};\n\n/** Source of the generated component registry module. Stable for unchanged input. */\nexport const renderRegistrySource = (\n entries: RegistryEntry[],\n outputFile: string\n): string => {\n const imports = entries.map((entry, i) => importLine(entry, `C${i}`, outputFile));\n const members = entries.map((entry, i) => ` ${JSON.stringify(entry.name)}: C${i},`);\n\n return [\n \"'use client';\",\n '',\n '// Generated by Amplify UP from your components folder. Do not edit —',\n '// add, rename or delete component files instead.',\n '',\n \"import { defineComponentRegistry, bindAmplifyPage } from '@amplifyup/sdk/react';\",\n ...imports,\n '',\n 'export const componentRegistry = defineComponentRegistry({',\n ...members,\n '});',\n '',\n 'export const AmplifyPage = bindAmplifyPage(componentRegistry);',\n '',\n ].join('\\n');\n};\n","import { existsSync, mkdirSync, readFileSync, watch, writeFileSync, type FSWatcher } from 'fs';\nimport path from 'path';\nimport { loadComponentsConfig, type ResolvedComponentsConfig } from './load-config';\nimport { scanComponents, type ScanResult } from './scan-components';\nimport { renderRegistrySource } from './render-registry';\n\nconst LOG_PREFIX = '[Amplify UP]';\nconst WATCH_DEBOUNCE_MS = 120;\n\nexport type BuildRegistryResult = ScanResult & {\n outputFile: string;\n /** False when the file already had this content (no rewrite, no HMR churn). */\n changed: boolean;\n};\n\nconst writeIfChanged = (file: string, content: string): boolean => {\n if (existsSync(file) && readFileSync(file, 'utf8') === content) return false;\n\n mkdirSync(path.dirname(file), { recursive: true });\n writeFileSync(file, content);\n return true;\n};\n\n/** The generated folder ignores itself, so sites never commit it. */\nconst ensureSelfIgnored = (outputFile: string): void => {\n const dir = path.dirname(outputFile);\n if (path.basename(dir) !== '.amplifyup') return;\n writeIfChanged(path.join(dir, '.gitignore'), '*\\n');\n};\n\nexport const buildRegistryFromConfig = async (\n config: ResolvedComponentsConfig\n): Promise<BuildRegistryResult> => {\n const scan = await scanComponents(config);\n const source = renderRegistrySource(scan.entries, config.outputFile);\n\n const changed = writeIfChanged(config.outputFile, source);\n ensureSelfIgnored(config.outputFile);\n\n return { ...scan, outputFile: config.outputFile, changed };\n};\n\nexport const buildRegistry = async (cwd: string): Promise<BuildRegistryResult> =>\n buildRegistryFromConfig(await loadComponentsConfig(cwd));\n\nexport const reportRegistry = (result: BuildRegistryResult, cwd: string): void => {\n const rel = (file: string) => path.relative(cwd, file) || '.';\n\n for (const root of result.missingRoots) {\n console.warn(`${LOG_PREFIX} Components folder not found: ${rel(root)}`);\n }\n\n for (const skip of result.skipped) {\n console.warn(`${LOG_PREFIX} Skipped ${rel(skip.file)}: ${skip.reason}`);\n }\n\n console.log(\n `${LOG_PREFIX} Component registry: ${result.entries.length} component(s) → ${rel(result.outputFile)}`\n );\n};\n\n/** Regenerates on add/remove/rename. Returns a function that stops watching. */\nexport const watchRegistry = async (cwd: string): Promise<() => void> => {\n const config = await loadComponentsConfig(cwd);\n const watchers: FSWatcher[] = [];\n let timer: ReturnType<typeof setTimeout> | undefined;\n\n const rebuild = () => {\n clearTimeout(timer);\n timer = setTimeout(() => {\n buildRegistryFromConfig(config)\n .then((result) => {\n if (result.changed) reportRegistry(result, cwd);\n })\n .catch((error: unknown) => {\n console.error(`${LOG_PREFIX} Component registry update failed:`, error);\n });\n }, WATCH_DEBOUNCE_MS);\n };\n\n for (const root of config.roots.filter((r) => existsSync(r))) {\n watchers.push(watch(root, { recursive: true }, rebuild));\n }\n\n return () => {\n clearTimeout(timer);\n watchers.forEach((watcher) => watcher.close());\n };\n};\n","/**\n * `withAmplifyUp(nextConfig)` — builds the component registry whenever Next\n * loads its config (`next build`, `next dev`) and keeps it current during dev.\n */\nimport { buildRegistry, reportRegistry, watchRegistry } from './cli/build-registry';\n\ntype NextConfigObject = Record<string, unknown>;\n\ntype NextConfigContext = {\n defaultConfig: NextConfigObject;\n};\n\ntype NextConfigFunction = (\n phase: string,\n context: NextConfigContext\n) => NextConfigObject | Promise<NextConfigObject>;\n\ntype NextConfigInput = NextConfigObject | NextConfigFunction;\n\nconst DEV_PHASE = 'phase-development-server';\n\ntype RegistryState = {\n built?: Promise<void>;\n watching?: boolean;\n};\n\n// Next loads its config more than once per process; build and watch only once.\nconst STATE_KEY = Symbol.for('amplifyup.registryBuild');\n\nconst registryState = (): RegistryState => {\n const store = globalThis as typeof globalThis & { [STATE_KEY]?: RegistryState };\n store[STATE_KEY] ??= {};\n return store[STATE_KEY]!;\n};\n\nconst prepareRegistry = async (phase: string): Promise<void> => {\n const cwd = process.cwd();\n const state = registryState();\n\n state.built ??= buildRegistry(cwd).then((result) => reportRegistry(result, cwd));\n await state.built;\n\n if (phase === DEV_PHASE && !state.watching) {\n state.watching = true;\n await watchRegistry(cwd);\n }\n};\n\nexport const withAmplifyUp = (nextConfig: NextConfigInput = {}): NextConfigFunction =>\n async (phase, context) => {\n await prepareRegistry(phase);\n return typeof nextConfig === 'function' ? nextConfig(phase, context) : nextConfig;\n };\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/registry/load-config.ts","../src/component-key.ts","../src/registry/scan-components.ts","../src/registry/scan-packages.ts","../src/registry/render-registry.ts","../src/registry/build-registry.ts","../src/next.ts"],"names":["path","existsSync","readFileSync"],"mappings":";;;;;;;;AAKA,IAAM,YAAA,GAAe;AAAA,EACnB,qBAAA;AAAA,EACA,sBAAA;AAAA,EACA,sBAAA;AAAA,EACA,qBAAA;AAAA,EACA;AACF,CAAA;AAaA,IAAM,iBAAiB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aAAA,EAAc;AAE5B,EAAA,KAAA,CAAM,KAAA,KAAN,KAAA,CAAM,KAAA,GAAU,aAAA,CAAc,GAAG,CAAA,CAAE,IAAA,CAAK,CAAC,MAAA,KAAW,cAAA,CAAe,MAAA,EAAQ,GAAG,CAAC,CAAA,CAAA;AAC/E,EAAA,MAAM,KAAA,CAAM,KAAA;AAEZ,EAAA,IAAI,KAAA,KAAU,SAAA,IAAa,CAAC,KAAA,CAAM,QAAA,EAAU;AAC1C,IAAA,KAAA,CAAM,QAAA,GAAW,IAAA;AACjB,IAAA,MAAM,cAAc,GAAG,CAAA;AAAA,EACzB;AACF,CAAA;AAEO,IAAM,gBAAgB,CAAC,UAAA,GAA8B,EAAC,KAC3D,OAAO,OAAO,OAAA,KAAY;AACxB,EAAA,MAAM,gBAAgB,KAAK,CAAA;AAC3B,EAAA,OAAO,OAAO,UAAA,KAAe,UAAA,GAAa,UAAA,CAAW,KAAA,EAAO,OAAO,CAAA,GAAI,UAAA;AACzE","file":"next.mjs","sourcesContent":["import { existsSync } from 'fs';\nimport path from 'path';\nimport { createJiti } from 'jiti';\nimport type { AmplifyConfig } from '../config';\n\nconst CONFIG_FILES = [\n 'amplifyup.config.ts',\n 'amplifyup.config.mts',\n 'amplifyup.config.mjs',\n 'amplifyup.config.js',\n 'amplifyup.config.cjs',\n];\n\nexport type ResolvedComponentsConfig = {\n cwd: string;\n /** Absolute component folders. */\n roots: string[];\n exclude: string[];\n /** Absolute generated file path, extension included. */\n outputFile: string;\n /** Config file that was loaded, if any. */\n configFile?: string;\n};\n\nconst findConfigFile = (cwd: string): string | undefined =>\n CONFIG_FILES.map((name) => path.join(cwd, name)).find((file) => existsSync(file));\n\nconst defaultRoots = (cwd: string): string[] =>\n existsSync(path.join(cwd, 'src')) ? ['src/components'] : ['components'];\n\nconst defaultOutput = (firstRoot: string): string =>\n path.join(path.dirname(firstRoot), '.amplifyup', 'component-registry');\n\n/** TS projects get `.tsx`; plain JS projects get `.jsx` so Next doesn't switch them to TypeScript. */\nconst outputExtension = (cwd: string): string =>\n existsSync(path.join(cwd, 'tsconfig.json')) ? '.tsx' : '.jsx';\n\nexport const loadComponentsConfig = async (\n cwd: string\n): Promise<ResolvedComponentsConfig> => {\n const configFile = findConfigFile(cwd);\n let config: AmplifyConfig = {};\n\n if (configFile) {\n const jiti = createJiti(path.join(cwd, 'amplifyup.config.loader'));\n config = (await jiti.import<AmplifyConfig>(configFile, { default: true })) ?? {};\n }\n\n const components = config.components ?? {};\n const roots = components.roots?.length ? components.roots : defaultRoots(cwd);\n const output = components.output ?? defaultOutput(roots[0]);\n\n return {\n cwd,\n roots: roots.map((root) => path.resolve(cwd, root)),\n exclude: components.exclude ?? [],\n outputFile: path.resolve(cwd, output) + outputExtension(cwd),\n configFile,\n };\n};\n","/**\n * One matching rule for layout component IDs and component file names, so\n * `Hero`, `hero`, `HERO` and `e2e-hero` / `E2eHero` resolve to the same entry.\n */\nexport const componentKey = (id: string): string =>\n id.toLowerCase().replace(/[^a-z0-9]/g, '');\n","import { existsSync, readFileSync } from 'fs';\nimport path from 'path';\nimport { glob } from 'tinyglobby';\nimport { componentKey } from '../component-key';\nimport type { ResolvedComponentsConfig } from './load-config';\n\nconst ALWAYS_EXCLUDE = [\n '**/*.test.*',\n '**/*.spec.*',\n '**/*.stories.*',\n '**/*.d.ts',\n '**/__tests__/**',\n '**/__mocks__/**',\n];\n\nexport type RegistryEntry = {\n /** Registry name — the file (or folder, for `index` files) name. */\n name: string;\n key: string;\n /** Absolute file path (the package manifest, for package components). */\n file: string;\n /** `default`, or the named export that is the component. */\n exportName: string;\n /** Package to import from, for components shipped by an installed package. */\n module?: string;\n};\n\nexport type SkippedFile = {\n file: string;\n reason: string;\n};\n\nexport type ScanResult = {\n entries: RegistryEntry[];\n skipped: SkippedFile[];\n missingRoots: string[];\n};\n\nexport class ComponentRegistryError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'ComponentRegistryError';\n }\n}\n\nconst NAMED_DECLARATION =\n /export\\s+(?:declare\\s+)?(?:async\\s+)?(?:const|let|var|function\\*?|class)\\s+([A-Za-z_$][\\w$]*)/g;\n\nconst EXPORT_LIST = /export\\s*\\{([^}]*)\\}/g;\n\n/** Export names a file declares, read from source (no type checking needed). */\nconst readExports = (source: string): { hasDefault: boolean; named: string[] } => {\n const named: string[] = [];\n let hasDefault = /export\\s+default\\b/.test(source);\n\n for (const match of source.matchAll(NAMED_DECLARATION)) {\n named.push(match[1]);\n }\n\n for (const match of source.matchAll(EXPORT_LIST)) {\n for (const part of match[1].split(',')) {\n const spec = part.trim();\n if (!spec || spec.startsWith('type ')) continue;\n\n const exported = spec.split(/\\s+as\\s+/).pop()!.trim();\n if (exported === 'default') {\n hasDefault = true;\n } else {\n named.push(exported);\n }\n }\n }\n\n return { hasDefault, named };\n};\n\nconst entryName = (file: string, root: string): string | null => {\n const base = path.basename(file, path.extname(file));\n if (base !== 'index') return base;\n\n // `components/index.tsx` is a barrel, not a component.\n const dir = path.dirname(file);\n return dir === root ? null : path.basename(dir);\n};\n\n/** `Hero/index.tsx` and `Hero/Hero.tsx` describe one component — keep the index. */\nconst isIndexPair = (a: RegistryEntry, b: RegistryEntry): boolean =>\n path.dirname(a.file) === path.dirname(b.file) &&\n [a, b].some((entry) => path.basename(entry.file).startsWith('index.'));\n\nconst toEntry = (\n file: string,\n root: string\n): RegistryEntry | SkippedFile | null => {\n const name = entryName(file, root);\n if (!name) return null;\n\n const key = componentKey(name);\n const { hasDefault, named } = readExports(readFileSync(file, 'utf8'));\n const exportName = hasDefault\n ? 'default'\n : named.find((exported) => componentKey(exported) === key);\n\n if (!exportName) {\n return {\n file,\n reason: `no default export or export named \"${name}\"`,\n };\n }\n\n return { name, key, file, exportName };\n};\n\nexport const scanComponents = async (\n config: ResolvedComponentsConfig\n): Promise<ScanResult> => {\n const byKey = new Map<string, RegistryEntry>();\n const skipped: SkippedFile[] = [];\n const missingRoots: string[] = [];\n\n for (const root of config.roots) {\n if (!existsSync(root)) {\n missingRoots.push(root);\n continue;\n }\n\n const files = await glob(['**/*.{tsx,jsx,js}'], {\n cwd: root,\n ignore: [...ALWAYS_EXCLUDE, ...config.exclude],\n absolute: true,\n });\n\n for (const file of files.map((f) => path.resolve(f)).sort()) {\n const result = toEntry(file, root);\n if (!result) continue;\n\n if (!('key' in result)) {\n skipped.push(result);\n continue;\n }\n\n const existing = byKey.get(result.key);\n if (!existing) {\n byKey.set(result.key, result);\n continue;\n }\n\n if (isIndexPair(existing, result)) {\n const keepResult = path.basename(result.file).startsWith('index.');\n if (keepResult) byKey.set(result.key, result);\n continue;\n }\n\n throw new ComponentRegistryError(\n `Two components resolve to the same name \"${result.name}\":\\n` +\n ` ${path.relative(config.cwd, existing.file)}\\n` +\n ` ${path.relative(config.cwd, result.file)}\\n` +\n 'Rename one of them, or add it to components.exclude in amplifyup.config.ts.'\n );\n }\n }\n\n const entries = [...byKey.values()].sort((a, b) => a.name.localeCompare(b.name));\n return { entries, skipped, missingRoots };\n};\n","import { existsSync, readFileSync } from 'fs';\nimport path from 'path';\nimport semver from 'semver';\nimport { componentKey } from '../component-key';\nimport type { RegistryEntry } from './scan-components';\n\nconst SDK_PACKAGE = '@amplifyup/sdk';\n\ntype PackageJson = {\n name?: string;\n version?: string;\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n peerDependencies?: Record<string, string>;\n amplifyup?: { manifest?: string };\n};\n\ntype ManifestComponent = {\n component_id?: unknown;\n export_name?: unknown;\n};\n\ntype PackageManifestFile = {\n components?: ManifestComponent[];\n};\n\nexport type PackageScanResult = {\n entries: RegistryEntry[];\n warnings: string[];\n};\n\nconst readJson = <T>(file: string): T => JSON.parse(readFileSync(file, 'utf8')) as T;\n\n/** Installed copy of a dependency, found the way Node resolves it (walking up node_modules). */\nconst findInstalledPackage = (cwd: string, name: string): string | null => {\n let dir = cwd;\n\n while (true) {\n const candidate = path.join(dir, 'node_modules', name, 'package.json');\n if (existsSync(candidate)) return candidate;\n\n const parent = path.dirname(dir);\n if (parent === dir) return null;\n dir = parent;\n }\n};\n\nconst peerWarning = (pkg: PackageJson, sdkVersion: string | undefined): string | null => {\n const range = pkg.peerDependencies?.[SDK_PACKAGE];\n if (!range || !sdkVersion) return null;\n if (semver.satisfies(sdkVersion, range, { includePrerelease: true })) return null;\n\n return `${pkg.name} expects ${SDK_PACKAGE} ${range}, but ${sdkVersion} is installed. Update one of them.`;\n};\n\nconst manifestEntries = (\n dependency: string,\n manifestFile: string,\n warnings: string[]\n): RegistryEntry[] => {\n const manifest = readJson<PackageManifestFile>(manifestFile);\n const entries: RegistryEntry[] = [];\n\n for (const component of manifest.components ?? []) {\n const { component_id: id, export_name: exportName } = component;\n if (typeof id !== 'string' || typeof exportName !== 'string') {\n warnings.push(`${dependency}: skipped a manifest component without component_id and export_name`);\n continue;\n }\n\n entries.push({\n name: id,\n key: componentKey(id),\n file: manifestFile,\n exportName,\n module: dependency,\n });\n }\n\n return entries;\n};\n\n/**\n * Components shipped by the site's direct dependencies. A package opts in with\n * `\"amplifyup\": { \"manifest\": \"./dist/amplifyup.manifest.json\" }` in its package.json.\n */\nexport const scanPackages = (cwd: string): PackageScanResult => {\n const siteManifest = path.join(cwd, 'package.json');\n if (!existsSync(siteManifest)) return { entries: [], warnings: [] };\n\n const site = readJson<PackageJson>(siteManifest);\n const dependencies = Object.keys({ ...site.devDependencies, ...site.dependencies }).sort();\n const sdkPackageFile = findInstalledPackage(cwd, SDK_PACKAGE);\n const sdkVersion = sdkPackageFile ? readJson<PackageJson>(sdkPackageFile).version : undefined;\n\n const entries: RegistryEntry[] = [];\n const warnings: string[] = [];\n\n for (const dependency of dependencies) {\n const packageFile = findInstalledPackage(cwd, dependency);\n if (!packageFile) continue;\n\n const pkg = readJson<PackageJson>(packageFile);\n const manifestPath = pkg.amplifyup?.manifest;\n if (!manifestPath) continue;\n\n const manifestFile = path.resolve(path.dirname(packageFile), manifestPath);\n if (!existsSync(manifestFile)) {\n warnings.push(`${dependency}: component manifest not found at ${manifestPath}`);\n continue;\n }\n\n const warning = peerWarning(pkg, sdkVersion);\n if (warning) warnings.push(warning);\n\n entries.push(...manifestEntries(dependency, manifestFile, warnings));\n }\n\n return { entries, warnings };\n};\n","import path from 'path';\nimport type { RegistryEntry } from './scan-components';\n\nconst importPath = (fromFile: string, toFile: string): string => {\n const withoutExt = toFile.slice(0, toFile.length - path.extname(toFile).length);\n const relative = path\n .relative(path.dirname(fromFile), withoutExt)\n .split(path.sep)\n .join('/')\n .replace(/\\/index$/, '');\n return relative.startsWith('.') ? relative : `./${relative}`;\n};\n\nconst importLine = (entry: RegistryEntry, local: string, outputFile: string): string => {\n const from = JSON.stringify(entry.module ?? importPath(outputFile, entry.file));\n return entry.exportName === 'default'\n ? `import ${local} from ${from};`\n : `import { ${entry.exportName} as ${local} } from ${from};`;\n};\n\n/** Source of the generated component registry module. Stable for unchanged input. */\nexport const renderRegistrySource = (\n entries: RegistryEntry[],\n outputFile: string\n): string => {\n const imports = entries.map((entry, i) => importLine(entry, `C${i}`, outputFile));\n const members = entries.map((entry, i) => ` ${JSON.stringify(entry.name)}: C${i},`);\n\n return [\n \"'use client';\",\n '',\n '// Generated by Amplify UP from your components folder and installed component',\n '// packages. Do not edit — add, rename or delete component files instead.',\n '',\n \"import { defineComponentRegistry, bindAmplifyPage } from '@amplifyup/sdk/react';\",\n ...imports,\n '',\n 'export const componentRegistry = defineComponentRegistry({',\n ...members,\n '});',\n '',\n 'export const AmplifyPage = bindAmplifyPage(componentRegistry);',\n '',\n ].join('\\n');\n};\n","import { existsSync, mkdirSync, readFileSync, watch, writeFileSync, type FSWatcher } from 'fs';\nimport path from 'path';\nimport { loadComponentsConfig, type ResolvedComponentsConfig } from './load-config';\nimport { ComponentRegistryError, scanComponents, type RegistryEntry, type ScanResult } from './scan-components';\nimport { scanPackages } from './scan-packages';\nimport { renderRegistrySource } from './render-registry';\n\nconst LOG_PREFIX = '[Amplify UP]';\nconst WATCH_DEBOUNCE_MS = 120;\n\nexport type BuildRegistryResult = ScanResult & {\n outputFile: string;\n /** Problems with installed component packages; the build still succeeds. */\n warnings: string[];\n /** False when the file already had this content (no rewrite, no HMR churn). */\n changed: boolean;\n};\n\nconst writeIfChanged = (file: string, content: string): boolean => {\n if (existsSync(file) && readFileSync(file, 'utf8') === content) return false;\n\n mkdirSync(path.dirname(file), { recursive: true });\n writeFileSync(file, content);\n return true;\n};\n\n/** The generated folder ignores itself, so sites never commit it. */\nconst ensureSelfIgnored = (outputFile: string): void => {\n const dir = path.dirname(outputFile);\n if (path.basename(dir) !== '.amplifyup') return;\n writeIfChanged(path.join(dir, '.gitignore'), '*\\n');\n};\n\nconst describeEntry = (entry: RegistryEntry, cwd: string): string =>\n entry.module ? `${entry.module} (installed package)` : path.relative(cwd, entry.file);\n\n/** Local components plus installed package components; one name may only resolve once. */\nconst mergeEntries = (\n local: RegistryEntry[],\n packaged: RegistryEntry[],\n cwd: string\n): RegistryEntry[] => {\n const byKey = new Map(local.map((entry) => [entry.key, entry]));\n\n for (const entry of packaged) {\n const existing = byKey.get(entry.key);\n if (existing) {\n throw new ComponentRegistryError(\n `Two components resolve to the same name \"${entry.name}\":\\n` +\n ` ${describeEntry(existing, cwd)}\\n` +\n ` ${describeEntry(entry, cwd)}\\n` +\n 'Rename the local component, or remove one of the packages.'\n );\n }\n byKey.set(entry.key, entry);\n }\n\n return [...byKey.values()].sort((a, b) => a.name.localeCompare(b.name));\n};\n\nexport const buildRegistryFromConfig = async (\n config: ResolvedComponentsConfig\n): Promise<BuildRegistryResult> => {\n const scan = await scanComponents(config);\n const packages = scanPackages(config.cwd);\n const entries = mergeEntries(scan.entries, packages.entries, config.cwd);\n const source = renderRegistrySource(entries, config.outputFile);\n\n const changed = writeIfChanged(config.outputFile, source);\n ensureSelfIgnored(config.outputFile);\n\n return {\n ...scan,\n entries,\n warnings: packages.warnings,\n outputFile: config.outputFile,\n changed,\n };\n};\n\nexport const buildRegistry = async (cwd: string): Promise<BuildRegistryResult> =>\n buildRegistryFromConfig(await loadComponentsConfig(cwd));\n\nexport const reportRegistry = (result: BuildRegistryResult, cwd: string): void => {\n const rel = (file: string) => path.relative(cwd, file) || '.';\n\n for (const root of result.missingRoots) {\n console.warn(`${LOG_PREFIX} Components folder not found: ${rel(root)}`);\n }\n\n for (const warning of result.warnings) {\n console.warn(`${LOG_PREFIX} ${warning}`);\n }\n\n for (const skip of result.skipped) {\n console.warn(`${LOG_PREFIX} Skipped ${rel(skip.file)}: ${skip.reason}`);\n }\n\n console.log(\n `${LOG_PREFIX} Component registry: ${result.entries.length} component(s) → ${rel(result.outputFile)}`\n );\n};\n\n/** Regenerates on add/remove/rename. Returns a function that stops watching. */\nexport const watchRegistry = async (cwd: string): Promise<() => void> => {\n const config = await loadComponentsConfig(cwd);\n const watchers: FSWatcher[] = [];\n let timer: ReturnType<typeof setTimeout> | undefined;\n\n const rebuild = () => {\n clearTimeout(timer);\n timer = setTimeout(() => {\n buildRegistryFromConfig(config)\n .then((result) => {\n if (result.changed) reportRegistry(result, cwd);\n })\n .catch((error: unknown) => {\n console.error(`${LOG_PREFIX} Component registry update failed:`, error);\n });\n }, WATCH_DEBOUNCE_MS);\n };\n\n for (const root of config.roots.filter((r) => existsSync(r))) {\n watchers.push(watch(root, { recursive: true }, rebuild));\n }\n\n return () => {\n clearTimeout(timer);\n watchers.forEach((watcher) => watcher.close());\n };\n};\n","/**\n * `withAmplifyUp(nextConfig)` — builds the component registry whenever Next\n * loads its config (`next build`, `next dev`) and keeps it current during dev.\n */\nimport { buildRegistry, reportRegistry, watchRegistry } from './registry/build-registry';\n\ntype NextConfigObject = Record<string, unknown>;\n\ntype NextConfigContext = {\n defaultConfig: NextConfigObject;\n};\n\ntype NextConfigFunction = (\n phase: string,\n context: NextConfigContext\n) => NextConfigObject | Promise<NextConfigObject>;\n\ntype NextConfigInput = NextConfigObject | NextConfigFunction;\n\nconst DEV_PHASE = 'phase-development-server';\n\ntype RegistryState = {\n built?: Promise<void>;\n watching?: boolean;\n};\n\n// Next loads its config more than once per process; build and watch only once.\nconst STATE_KEY = Symbol.for('amplifyup.registryBuild');\n\nconst registryState = (): RegistryState => {\n const store = globalThis as typeof globalThis & { [STATE_KEY]?: RegistryState };\n store[STATE_KEY] ??= {};\n return store[STATE_KEY]!;\n};\n\nconst prepareRegistry = async (phase: string): Promise<void> => {\n const cwd = process.cwd();\n const state = registryState();\n\n state.built ??= buildRegistry(cwd).then((result) => reportRegistry(result, cwd));\n await state.built;\n\n if (phase === DEV_PHASE && !state.watching) {\n state.watching = true;\n await watchRegistry(cwd);\n }\n};\n\nexport const withAmplifyUp = (nextConfig: NextConfigInput = {}): NextConfigFunction =>\n async (phase, context) => {\n await prepareRegistry(phase);\n return typeof nextConfig === 'function' ? nextConfig(phase, context) : nextConfig;\n };\n"]}
|