Skip to content

Commit

Permalink
add universal migration
Browse files Browse the repository at this point in the history
GaryB432 committed Sep 1, 2024
1 parent f56d772 commit 41f4fef
Showing 6 changed files with 97 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/svelte/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -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"
9 changes: 9 additions & 0 deletions packages/svelte/migrations.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
5 changes: 4 additions & 1 deletion packages/svelte/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
5 changes: 5 additions & 0 deletions packages/svelte/project.json
Original file line number Diff line number Diff line change
@@ -33,6 +33,11 @@
"input": "./packages/svelte",
"glob": "executors.json",
"output": "."
},
{
"input": "./packages/svelte",
"glob": "migrations.json",
"output": "."
}
]
}
Original file line number Diff line number Diff line change
@@ -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'
);
});
});
Original file line number Diff line number Diff line change
@@ -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 });
}

0 comments on commit 41f4fef

Please sign in to comment.