feat: add schematic to migrate @ngneat to @openng - #10
Conversation
|
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
}
} |
|
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
left a comment
There was a problem hiding this comment.
Hi @Glassait, we agreed to add it.
Besides requests changes in the PR directly, i'd have two other requests:
-
rename the
ngneatToOpenngfolder tongneat-to-openng, matching angular official practices on schematics. -
add a final step to remove the
@ngneat/spectatordependancy 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', () => { |
There was a problem hiding this comment.
use namespace naming ngneatand openng for consistency.
| @@ -0,0 +1,6 @@ | |||
| { | |||
| "$schema": "http://json-schema.org/draft-07/schema#", | |||
| "$id": "NgneatToOpenNg", | |||
There was a problem hiding this comment.
rename to ngneatToOpenng
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
ef95789 to
f167017
Compare
05e9fff to
054637e
Compare
|
Hello @geromegrignon, thank you for the return. I have done a little more: If accepted, do you want me to do the same on the other packages of openng ? |
|
Reviewing tomorrow @Glassait, sorry for the delay. |
There was a problem hiding this comment.
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-openngschematic (+ Jest-based schematic tests) to rewrite TS import/export module specifiers and remove@ngneat/spectatorfrompackage.json. - Switched schematics build to an esbuild-based script and cleaned legacy generated
.js/.mapartifacts from the schematics sources. - Updated spectator schematics templates to
.template, moved toapplyTemplates, 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.
| 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'; |
| "include": ["src/**/*.spec.ts", "**/*.d.ts"], | ||
| "exclude": null |
| "noImplicitAny": true, | ||
| "outDir": "../../../dist/schematics", | ||
| "rootDir": ".", |
| // Early return if the file is in node_modules or dist directories | ||
| if (filePath.includes('node_modules') || filePath.includes('dist')) { | ||
| return; | ||
| } |
| 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` |
Description
Add a new schematic that helps dev to migrate from ngneat to openng.
Change the build from
tsctoesbuildto compile in ESM.Add Jest config in the schematics folder to allow test on schematics.
Remove old
.jsand.js.mapfrom the schematics folder.Fix the
spectator:component-schemato 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
Breaking changes
None
Test plan
npm run buildnpm testnpm run lintChecklist
Additional context