From c7767b4a2ad2a144cc97b7ef00d8bd2ce08d6cc9 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 2 Jan 2026 19:23:38 +0000 Subject: [PATCH] fix: Using .cjs extension for CommonJS check script Payload apps have "type": "module" in package.json, which treats all .js files as ES modules. The dependency check script uses CommonJS (require), causing a ReferenceError at runtime. Changes: - Rename check-deps.js to check-deps.cjs - Update all references to use .cjs extension - Update tests to expect .cjs filename This fixes the "require is not defined in ES module scope" error. --- internal/cmd/files/migration_check.go | 4 ++-- internal/cmd/files/migration_check_test.go | 10 +++++----- internal/cmd/files/package_json.go | 2 +- internal/cmd/files/package_json_test.go | 4 ++-- .../scripts/{check-deps.js => check-deps.cjs} | 0 5 files changed, 10 insertions(+), 10 deletions(-) rename internal/templates/scripts/{check-deps.js => check-deps.cjs} (100%) diff --git a/internal/cmd/files/migration_check.go b/internal/cmd/files/migration_check.go index ed0170c3..816cb022 100644 --- a/internal/cmd/files/migration_check.go +++ b/internal/cmd/files/migration_check.go @@ -22,12 +22,12 @@ func MigrationCheckScript(_ context.Context, input cmdtools.CommandInput) error payloadApps := appDef.GetAppsByType(appdef.AppTypePayload) for _, app := range payloadApps { - scriptPath := filepath.Join(app.Path, "scripts", "check-deps.js") + scriptPath := filepath.Join(app.Path, "scripts", "check-deps.cjs") // Scaffold the check script from template. err := input.Generator().CopyFromEmbed( templates.Embed, - "scripts/check-deps.js", + "scripts/check-deps.cjs", scriptPath, scaffold.WithTracking(manifest.SourceApp(app.Name)), scaffold.WithScaffoldMode(), diff --git a/internal/cmd/files/migration_check_test.go b/internal/cmd/files/migration_check_test.go index 4e263e96..c5e17732 100644 --- a/internal/cmd/files/migration_check_test.go +++ b/internal/cmd/files/migration_check_test.go @@ -42,7 +42,7 @@ func TestMigrationCheckScript(t *testing.T) { // Verify no scripts were created. for _, app := range appDef.Apps { - scriptPath := filepath.Join(app.Path, "scripts", "check-deps.js") + scriptPath := filepath.Join(app.Path, "scripts", "check-deps.cjs") exists, err := afero.Exists(input.FS, scriptPath) require.NoError(t, err) assert.False(t, exists, "expected %s not to exist", scriptPath) @@ -65,7 +65,7 @@ func TestMigrationCheckScript(t *testing.T) { require.NoError(t, err) // Verify script was created for Payload app. - cmsScriptPath := filepath.Join("./apps/cms/scripts", "check-deps.js") + cmsScriptPath := filepath.Join("./apps/cms/scripts", "check-deps.cjs") exists, err := afero.Exists(input.FS, cmsScriptPath) require.NoError(t, err) assert.True(t, exists, "expected %s to exist", cmsScriptPath) @@ -78,7 +78,7 @@ func TestMigrationCheckScript(t *testing.T) { assert.Contains(t, string(content), "Dependencies out of sync") // Verify script was not created for SvelteKit app. - webScriptPath := filepath.Join("./apps/web/scripts", "check-deps.js") + webScriptPath := filepath.Join("./apps/web/scripts", "check-deps.cjs") exists, err = afero.Exists(input.FS, webScriptPath) require.NoError(t, err) assert.False(t, exists, "expected %s not to exist", webScriptPath) @@ -101,7 +101,7 @@ func TestMigrationCheckScript(t *testing.T) { // Verify script was created for both Payload apps. for _, app := range appDef.Apps { - scriptPath := filepath.Join(app.Path, "scripts", "check-deps.js") + scriptPath := filepath.Join(app.Path, "scripts", "check-deps.cjs") exists, err := afero.Exists(input.FS, scriptPath) require.NoError(t, err) assert.True(t, exists, "expected %s to exist", scriptPath) @@ -123,7 +123,7 @@ func TestMigrationCheckScript(t *testing.T) { err := MigrationCheckScript(t.Context(), input) require.NoError(t, err) - scriptPath := filepath.Join("./apps/cms/scripts", "check-deps.js") + scriptPath := filepath.Join("./apps/cms/scripts", "check-deps.cjs") content1, err := afero.ReadFile(input.FS, scriptPath) require.NoError(t, err) diff --git a/internal/cmd/files/package_json.go b/internal/cmd/files/package_json.go index b062020f..d1bd68e5 100644 --- a/internal/cmd/files/package_json.go +++ b/internal/cmd/files/package_json.go @@ -129,7 +129,7 @@ func PackageJSONApp(_ context.Context, input cmdtools.CommandInput) error { // These scripts are injected into app package.json files based on the app type. var appTypeScripts = map[appdef.AppType]map[string]string{ appdef.AppTypePayload: { - "migrate:check": "node scripts/check-deps.js", + "migrate:check": "node scripts/check-deps.cjs", "migrate:create": "pnpm migrate:check && NODE_ENV=production payload migrate:create", "migrate:status": "NODE_ENV=production payload migrate:status", }, diff --git a/internal/cmd/files/package_json_test.go b/internal/cmd/files/package_json_test.go index 1a5ba5e6..243ba70c 100644 --- a/internal/cmd/files/package_json_test.go +++ b/internal/cmd/files/package_json_test.go @@ -527,7 +527,7 @@ func TestPackageJSONApp(t *testing.T) { scripts, ok := pkg["scripts"].(map[string]any) require.True(t, ok) - assert.Equal(t, "node scripts/check-deps.js", scripts["migrate:check"]) + assert.Equal(t, "node scripts/check-deps.cjs", scripts["migrate:check"]) assert.Equal(t, "pnpm migrate:check && NODE_ENV=production payload migrate:create", scripts["migrate:create"]) assert.Equal(t, "NODE_ENV=production payload migrate:status", scripts["migrate:status"]) } @@ -594,7 +594,7 @@ func TestGetAppTypeScripts(t *testing.T) { "Payload includes migration scripts": { input: appdef.AppTypePayload, want: map[string]string{ - "migrate:check": "node scripts/check-deps.js", + "migrate:check": "node scripts/check-deps.cjs", "migrate:create": "pnpm migrate:check && NODE_ENV=production payload migrate:create", "migrate:status": "NODE_ENV=production payload migrate:status", }, diff --git a/internal/templates/scripts/check-deps.js b/internal/templates/scripts/check-deps.cjs similarity index 100% rename from internal/templates/scripts/check-deps.js rename to internal/templates/scripts/check-deps.cjs