Skip to content

feat: add schematic to migrate @ngneat to @openng - #10

Open
Glassait wants to merge 3 commits into
openng-org:mainfrom
Glassait:feat/add-schematics-to-migration-to-openng
Open

feat: add schematic to migrate @ngneat to @openng#10
Glassait wants to merge 3 commits into
openng-org:mainfrom
Glassait:feat/add-schematics-to-migration-to-openng

Conversation

@Glassait

@Glassait Glassait commented Jul 10, 2026

Copy link
Copy Markdown

Description

Add a new schematic that helps dev to migrate from ngneat to openng.
Change the build from tsc to esbuild to compile in ESM.
Add Jest config in the schematics folder to allow test on schematics.
Remove old .js and .js.map from the schematics folder.
Fix the spectator:component-schema to match the Angular 22 changeDetection ("Eager", "OnPush")
Update the files of the spectator schematics to be .template.

This schematic can be taken for the other package in openng !

Related issues

None

Fixes #

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that changes the public API)
  • Documentation only
  • Refactor, test, or chore (no user-facing change)

Breaking changes

None

Test plan

  • npm run build
  • npm test
  • npm run lint
  • Verified in the demo app (if applicable)

Checklist

  • Issue discussed or bug clearly described (link issue when applicable)
  • Tests added or updated for behavioral changes
  • Documentation updated (README, JSDoc, migration notes as needed)
  • Public API changes documented; breaking changes called out
  • CHANGELOG updated (if the repository maintains one and the change is user-facing)
  • Commit messages follow Conventional Commits
  • I agree to follow the OpenNG Foundation Code of Conduct

Additional context

@dominicbachmann

Copy link
Copy Markdown
Member

Hi @Glassait thank you for the contribution! I like the idea of providing a command that users can run to replace the string occurrences.

I think we can solve this more easily by adding a section to the readme explaining which commands to run. What do you think?

e.g.

Linux/Mac:

grep -rl --exclude-dir=node_modules --exclude=package-lock.json --exclude=yarn.lock --exclude=pnpm-lock.yaml '@ngneat/spectator' . | xargs perl -pi -e 's|\@ngneat/spectator|\@openng/spectator|g'

Windows:

Get-ChildItem -Recurse -File | Where-Object { $_.FullName -notmatch 'node_modules' -and $_.Name -notin 'package-lock.json','yarn.lock','pnpm-lock.yaml' } | ForEach-Object {
    $content = Get-Content $_.FullName -Raw
    if ($content -match [regex]::Escape('@ngneat/spectator')) {
      $content -replace '@ngneat/spectator', '@openng/spectator' | Set-Content $_.FullName -NoNewline
    }
  }

@geromegrignon
geromegrignon self-requested a review July 11, 2026 05:23
@Glassait

Glassait commented Jul 11, 2026

Copy link
Copy Markdown
Author

Hi @dominicbachmann , we can use scripts if you prefer, but I think schematics are a safer choice. They integrate perfectly with Angular, whereas a script run from the wrong directory could miss files. Schematics ensure Angular targets the correct files every time.

@geromegrignon geromegrignon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Glassait, we agreed to add it.

Besides requests changes in the PR directly, i'd have two other requests:

  • rename the ngneatToOpenng folder to ngneat-to-openng, matching angular official practices on schematics.

  • add a final step to remove the @ngneat/spectator dependancy and run pnpm/npm/yanr/whatever dep installatiosn to udpate the lock file too.

import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
import path from 'path';

describe('NgNeat to Openng', () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use namespace naming ngneatand openng for consistency.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -0,0 +1,6 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "NgneatToOpenNg",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to ngneatToOpenng

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Remane the folder to ngneat-to-openng
Add .md in esbuild
Update schematic to match Angular Dodoc
Create a visite factory in the schematic to reduce congnitive complexity
The schematic now migrate /jest and /vitest
Update the test to match more case + add edge case test
@Glassait
Glassait force-pushed the feat/add-schematics-to-migration-to-openng branch from ef95789 to f167017 Compare July 12, 2026 18:19
@Glassait
Glassait force-pushed the feat/add-schematics-to-migration-to-openng branch from 05e9fff to 054637e Compare July 12, 2026 18:46
@Glassait

Glassait commented Jul 12, 2026

Copy link
Copy Markdown
Author

Hello @geromegrignon, thank you for the return. I have done a little more:
Uninstall the ngneat/spectator package
Add more tests to check if test runners are caught. The answer was no, so I fixed that. Now the schematic correctly updates all packages.
Do a little to reduce cognitive complexity.

If accepted, do you want me to do the same on the other packages of openng ?

@geromegrignon

geromegrignon commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Reviewing tomorrow @Glassait, sorry for the delay.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new Angular schematic to migrate @ngneat/spectator imports to @openng/spectator, modernizes the spectator schematics build pipeline (tsc → esbuild with ESM output), and updates spectator schematic templates/schema to align with newer Angular defaults (e.g., change detection options) and .template files.

Changes:

  • Added ngneat-to-openng schematic (+ Jest-based schematic tests) to rewrite TS import/export module specifiers and remove @ngneat/spectator from package.json.
  • Switched schematics build to an esbuild-based script and cleaned legacy generated .js/.map artifacts from the schematics sources.
  • Updated spectator schematics templates to .template, moved to applyTemplates, and adjusted component change-detection schema values/defaults.

Reviewed changes

Copilot reviewed 20 out of 25 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
yarn.lock Locks new build dependency (esbuild-plugin-tsc) and related transitive deps.
package.json Adds esbuild-based schematics build + schematics Jest test script; adds esbuild and esbuild-plugin-tsc.
projects/spectator/build-schematics.js New esbuild-based schematics build script (currently ESM/CJS execution mismatch).
projects/spectator/schematics/tsconfig.json Updated TS compilation settings for schematics (notably output path).
projects/spectator/schematics/tsconfig.spec.json New TS config for Jest schematics tests (currently has invalid exclude).
projects/spectator/schematics/jest.config.js New Jest config to run schematics unit tests.
projects/spectator/schematics/mocks/ora.js Jest mock for ESM-only ora dependency.
projects/spectator/schematics/src/collection.json Registers new ngneat-to-openng schematic + adjusts $schema path.
projects/spectator/schematics/src/ngneat-to-openng/index.ts Implements AST-based import/export rewrite + package.json dependency removal.
projects/spectator/schematics/src/ngneat-to-openng/index.spec.ts Adds schematic tests covering runners, exports, and edge cases.
projects/spectator/schematics/src/ngneat-to-openng/schema.json Adds schema definition for the new migration schematic.
projects/spectator/schematics/src/ngneat-to-openng/README.md Documents how to run the migration schematic.
projects/spectator/schematics/src/spectator/index.ts Switches from template() to applyTemplates() and passes type for .template filenames.
projects/spectator/schematics/src/spectator/component-schema.json Updates change detection enum/default to match Angular 22 changes.
projects/spectator/schematics/src/spectator/files///*.template Updates schematic template files to .template and adjusts generated spec imports/formatting.
projects/spectator/schematics/src/spectator/schema.js Removes legacy compiled JS artifact from the repo.
projects/spectator/schematics/src/spectator/schema.js.map Removes legacy sourcemap artifact from the repo.
projects/spectator/schematics/src/spectator/index.js Removes legacy compiled JS artifact from the repo.
projects/spectator/schematics/src/spectator/index.js.map Removes legacy sourcemap artifact from the repo.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1 to +9
import { build } from 'esbuild';
import esbuildPluginTsc from 'esbuild-plugin-tsc';
import { glob } from 'fs/promises';
import { rmSync } from 'fs';
import { dirname, resolve } from 'path';
import { fileURLToPath } from 'url';

const __dirname = dirname(fileURLToPath(import.meta.url));
const distPath = '../../dist/spectator/schematics';
Comment on lines +6 to +7
"include": ["src/**/*.spec.ts", "**/*.d.ts"],
"exclude": null
Comment on lines +9 to +11
"noImplicitAny": true,
"outDir": "../../../dist/schematics",
"rootDir": ".",
Comment on lines +54 to +57
// Early return if the file is in node_modules or dist directories
if (filePath.includes('node_modules') || filePath.includes('dist')) {
return;
}
Comment on lines +23 to +29
function visiteFactory(
sourceFile: SourceFile,
oldModule: string,
newModule: string,
recorder: UpdateRecorder,
state: { hasChanged: boolean },
) {
- Skips files inside `node_modules` and `dist` directories
- Replaces `from '@ngneat/spectator/<testRunner>'` with `from '@openng/spectator/<testRunner>'` in import and export declarations
- Preserves all named imports (e.g., `createComponentFactory`, `Spectator`, etc.)
- Remove `@ngneat/spectator` for the `package.json`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants