Skip to content

Commit 0ad7f40

Browse files
committed
#2773 fix the ng add schmematics for Angular 19 projects using esbuild
1 parent 42c52cb commit 0ad7f40

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

projects/ngx-extended-pdf-viewer/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,3 +643,4 @@
643643
- 23.3.7 #2710 simplify the build scripts (no change to the library, it's only a new version because it's impossible to revoke npm publications)
644644
- 23.3.8 #2205 stop rendering the initial page twice with different zoom settings; #2710 simplify the build scripts (no change to the library, it's only a new version because it's impossible to revoke npm publications)
645645
- 23.3.9 #2503 inform the find controller about changes of the pageViewMode
646+
- 23.3.10 #2773 fix the ng add schmematics for Angular 19 projects using esbuild

projects/ngx-extended-pdf-viewer/schematics/ng-add/index.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,28 @@ function updateAngularJson(tree: Tree, projectName: string, stable: boolean): Tr
7373
if (!json['projects'][projectName]) {
7474
throw new SchematicsException("The project isn't listed in the angular.json.");
7575
}
76-
const optionsJson = json['projects'][projectName]['architect']['build']['options'];
76+
let optionsJson;
77+
if (json['projects'][projectName]['architect']['esbuild']) {
78+
optionsJson = json['projects'][projectName]['architect']['esbuild']['options'];
79+
if (!optionsJson || !optionsJson['assets']) {
80+
optionsJson = undefined;
81+
}
82+
}
83+
if (!optionsJson) {
84+
optionsJson = json['projects'][projectName]['architect']['build']['options'];
85+
}
86+
if (!optionsJson) {
87+
console.log("Couldn't find assets in angular.json");
88+
console.log('Please add the following to your angular.json:');
89+
console.log('assets: [');
90+
console.log('{');
91+
console.log(" glob: '**/*',");
92+
console.log(" input: 'node_modules/ngx-extended-pdf-viewer/assets/',");
93+
console.log(" output: '/assets/',");
94+
console.log('}');
95+
return tree;
96+
}
97+
7798
if (!stable) {
7899
optionsJson['assets'].push({
79100
glob: '**/*',
@@ -136,7 +157,7 @@ function addDeclarationToNgModule(options: ModuleOptions): Rule {
136157
source as any,
137158
'ngx-extended-pdf-viewer',
138159
strings.classify(`NgxExtendedPdfViewerModule`),
139-
'ngx-extended-pdf-viewer'
160+
'ngx-extended-pdf-viewer',
140161
);
141162
const recorder = host.beginUpdate(modulePath);
142163
for (const change of componentChanges) {
@@ -168,7 +189,7 @@ export function findModule(host: Tree, generateDir: string, moduleExt = MODULE_E
168189
} else if (filteredMatches.length > 1) {
169190
throw new Error(
170191
'More than one module matches. Use the skip-import option to skip importing ' +
171-
'the component into the closest module or use the module option to specify a module.'
192+
'the component into the closest module or use the module option to specify a module.',
172193
);
173194
}
174195

@@ -177,7 +198,7 @@ export function findModule(host: Tree, generateDir: string, moduleExt = MODULE_E
177198

178199
console.error('');
179200
console.error(
180-
"Error: Couldn't find a module. Assuming this is a stand-alone project. You need to add these lines to the decorator of the ExamplePdfViewerComponent:"
201+
"Error: Couldn't find a module. Assuming this is a stand-alone project. You need to add these lines to the decorator of the ExamplePdfViewerComponent:",
181202
);
182203
console.error('');
183204
console.error('standalone: true,');

0 commit comments

Comments
 (0)