diff --git a/packages/svelte/.eslintrc.json b/packages/svelte/.eslintrc.json index 6d51747..0642352 100644 --- a/packages/svelte/.eslintrc.json +++ b/packages/svelte/.eslintrc.json @@ -22,7 +22,7 @@ } }, { - "files": ["./package.json", "./generators.json"], + "files": ["./package.json", "./generators.json", "./migrations.json"], "parser": "jsonc-eslint-parser", "rules": { "@nx/nx-plugin-checks": "error" diff --git a/packages/svelte/migrations.json b/packages/svelte/migrations.json new file mode 100644 index 0000000..c75a747 --- /dev/null +++ b/packages/svelte/migrations.json @@ -0,0 +1,9 @@ +{ + "generators": { + "change-shared-to-universal": { + "version": "8.4.0", + "description": "Migration for v8.4.0", + "implementation": "./src/migrations/update-8.4.0/change-shared-to-universal" + } + } +} diff --git a/packages/svelte/package.json b/packages/svelte/package.json index 52ef4cb..cae4031 100644 --- a/packages/svelte/package.json +++ b/packages/svelte/package.json @@ -1,6 +1,6 @@ { "name": "@gb-nx/svelte", - "version": "8.3.2", + "version": "8.4.0", "main": "src/index.js", "repository": { "type": "git", @@ -34,5 +34,8 @@ }, "publishConfig": { "access": "public" + }, + "nx-migrations": { + "migrations": "./migrations.json" } } diff --git a/packages/svelte/project.json b/packages/svelte/project.json index 52c892d..dddbf5c 100644 --- a/packages/svelte/project.json +++ b/packages/svelte/project.json @@ -33,6 +33,11 @@ "input": "./packages/svelte", "glob": "executors.json", "output": "." + }, + { + "input": "./packages/svelte", + "glob": "migrations.json", + "output": "." } ] } diff --git a/packages/svelte/src/migrations/update-8.4.0/change-shared-to-universal.spec.ts b/packages/svelte/src/migrations/update-8.4.0/change-shared-to-universal.spec.ts new file mode 100644 index 0000000..1057ac0 --- /dev/null +++ b/packages/svelte/src/migrations/update-8.4.0/change-shared-to-universal.spec.ts @@ -0,0 +1,57 @@ +import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; +import { readNxJson, Tree, updateNxJson } from '@nx/devkit'; + +import update from './change-shared-to-universal'; + +describe('change-shared-to-universal migration', () => { + let tree: Tree; + + beforeEach(() => { + tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); + }); + + it('replaces shared load with universal', async () => { + updateNxJson(tree, { + affected: { defaultBase: 'main' }, + generators: { + '@gb-nx/svelte:route': { + project: 'web', + directory: 'components', + style: 'scss', + language: 'ts', + load: 'shared', + }, + '@nx/web:application': { + style: 'scss', + linter: 'eslint', + unitTestRunner: 'jest', + e2eTestRunner: 'none', + }, + }, + targetDefaults: { build: { cache: true }, lint: { cache: true } }, + }); + update(tree); + const config = readNxJson(tree); + expect(config!.affected).toEqual({ defaultBase: 'main' }); + expect(config!.generators!['@gb-nx/svelte:route']['load']).toEqual( + 'universal' + ); + }); + + it('does not wreck nxjson', async () => { + updateNxJson(tree, { + generators: { + '@gb-nx/svelte:route': { + load: 'server', + }, + }, + targetDefaults: { build: { cache: true }, lint: { cache: true } }, + }); + update(tree); + const config = readNxJson(tree); + expect(config!.affected).toBeUndefined(); + expect(config!.generators!['@gb-nx/svelte:route']['load']).toEqual( + 'server' + ); + }); +}); diff --git a/packages/svelte/src/migrations/update-8.4.0/change-shared-to-universal.ts b/packages/svelte/src/migrations/update-8.4.0/change-shared-to-universal.ts new file mode 100644 index 0000000..c2c3bc4 --- /dev/null +++ b/packages/svelte/src/migrations/update-8.4.0/change-shared-to-universal.ts @@ -0,0 +1,21 @@ +import { type Tree, readNxJson, updateNxJson } from '@nx/devkit'; + +export default function update(host: Tree) { + const nxConfig = readNxJson(host); + + if (!nxConfig) return; + + const { generators } = nxConfig; + + if (!generators) return; + + const routeGeneratorDefaults = generators['@gb-nx/svelte:route']; + + if (!routeGeneratorDefaults) return; + + if ((routeGeneratorDefaults.load === 'shared')) { + routeGeneratorDefaults.load = 'universal'; + } + + updateNxJson(host, { ...nxConfig, generators }); +}