22import { defineConfig } from 'astro/config' ;
33import path from 'node:path' ;
44import { fileURLToPath } from 'node:url' ;
5+ import { existsSync } from 'node:fs' ;
56
67/**
78 * Vite plugin: strip the module-level `new Sample();` (or `new ClassName();`)
@@ -95,9 +96,80 @@ function inlineSampleCss() {
9596
9697const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
9798
99+ /**
100+ * Vite plugin: resolve unscoped igniteui-* package names to their @infragistics/
101+ * scoped equivalents when the unscoped package is not installed.
102+ *
103+ * WHY a resolveId plugin instead of resolve.alias
104+ * ────────────────────────────────────────────────
105+ * Astro merges its own Vite config last and can replace resolve.alias arrays.
106+ * A resolveId hook is part of the Rollup plugin pipeline and is always called
107+ * for every import, regardless of how Astro configures the resolver.
108+ */
109+ /** @returns {import('vite').Plugin } */
110+ function resolveIgniteUiScoped ( ) {
111+ // Build a map at startup: unscoped name → scoped name, only for packages
112+ // that are absent from node_modules unscoped.
113+ /** @type {Map<string, string> } */
114+ const redirects = new Map ( ) ;
115+
116+ const plain = [
117+ 'igniteui-dockmanager' ,
118+ 'igniteui-webcomponents-core' ,
119+ 'igniteui-webcomponents-charts' ,
120+ 'igniteui-webcomponents-gauges' ,
121+ 'igniteui-webcomponents-datasources' ,
122+ 'igniteui-webcomponents-excel' ,
123+ 'igniteui-webcomponents-inputs' ,
124+ 'igniteui-webcomponents-data-grids' ,
125+ 'igniteui-webcomponents-maps' ,
126+ 'igniteui-webcomponents-spreadsheet' ,
127+ 'igniteui-webcomponents-spreadsheet-chart-adapter' ,
128+ 'igniteui-webcomponents-layouts' ,
129+ 'igniteui-webcomponents-dashboards' ,
130+ // grids is also in the subpath list below; include base name here too
131+ 'igniteui-webcomponents-grids' ,
132+ ] ;
133+
134+ for ( const pkg of plain ) {
135+ if ( ! existsSync ( path . resolve ( __dirname , 'node_modules' , pkg ) ) ) {
136+ redirects . set ( pkg , `@infragistics/${ pkg } ` ) ;
137+ }
138+ }
139+
140+ return {
141+ name : 'resolve-igniteui-scoped' ,
142+ async resolveId ( id , importer , options ) {
143+ // Exact match (e.g. 'igniteui-dockmanager')
144+ if ( redirects . has ( id ) ) {
145+ return this . resolve ( redirects . get ( id ) , importer , { ...options , skipSelf : true } ) ;
146+ }
147+ // Subpath match (e.g. 'igniteui-webcomponents-grids/grids/combined')
148+ for ( const [ unscoped , scoped ] of redirects ) {
149+ if ( id . startsWith ( `${ unscoped } /` ) ) {
150+ const newId = `${ scoped } ${ id . slice ( unscoped . length ) } ` ;
151+ return this . resolve ( newId , importer , { ...options , skipSelf : true } ) ;
152+ }
153+ }
154+ } ,
155+ } ;
156+ }
157+
98158// Set BASE_PATH env variable to deploy under a sub-path, e.g. "/webcomponents-demos"
99159const base = process . env . BASE_PATH ?? '' ;
100160
161+ /**
162+ * Returns the installed package name for a given unscoped igniteui-* id.
163+ * If the unscoped package exists in node_modules it is returned as-is;
164+ * otherwise the @infragistics/ scoped name is returned.
165+ * @param {string } pkg
166+ */
167+ function ig ( pkg ) {
168+ return existsSync ( path . resolve ( __dirname , 'node_modules' , pkg ) )
169+ ? pkg
170+ : `@infragistics/${ pkg } ` ;
171+ }
172+
101173// https://astro.build/config
102174export default defineConfig ( {
103175 // Static output — builds to dist/ as plain HTML + JS assets (ideal for IIS / Nginx / CDN)
@@ -111,7 +183,7 @@ export default defineConfig({
111183 trailingSlash : 'never' ,
112184
113185 vite : {
114- plugins : [ stripSampleInstantiation ( ) , inlineSampleCss ( ) ] ,
186+ plugins : [ resolveIgniteUiScoped ( ) , stripSampleInstantiation ( ) , inlineSampleCss ( ) ] ,
115187 // samples/ and node_modules/ are already at the repo root (__dirname),
116188 // so no extra fs.allow entries are needed.
117189 server : {
@@ -130,20 +202,20 @@ export default defineConfig({
130202 noDiscovery : true ,
131203 include : [
132204 'igniteui-webcomponents' ,
133- 'igniteui-webcomponents-core' ,
134- 'igniteui-webcomponents-charts' ,
135- 'igniteui-webcomponents-grids' ,
136- 'igniteui-webcomponents-gauges' ,
137- 'igniteui-webcomponents-inputs' ,
138- 'igniteui-webcomponents-layouts' ,
139- 'igniteui-webcomponents-maps' ,
140- 'igniteui-webcomponents-data-grids' ,
141- 'igniteui-webcomponents-datasources' ,
142- 'igniteui-webcomponents-excel' ,
143- 'igniteui-webcomponents-spreadsheet' ,
144- 'igniteui-webcomponents-spreadsheet-chart-adapter' ,
145- 'igniteui-webcomponents-dashboards' ,
146- 'igniteui-dockmanager' ,
205+ ig ( 'igniteui-webcomponents-core' ) ,
206+ ig ( 'igniteui-webcomponents-charts' ) ,
207+ ig ( 'igniteui-webcomponents-grids' ) ,
208+ ig ( 'igniteui-webcomponents-gauges' ) ,
209+ ig ( 'igniteui-webcomponents-inputs' ) ,
210+ ig ( 'igniteui-webcomponents-layouts' ) ,
211+ ig ( 'igniteui-webcomponents-maps' ) ,
212+ ig ( 'igniteui-webcomponents-data-grids' ) ,
213+ ig ( 'igniteui-webcomponents-datasources' ) ,
214+ ig ( 'igniteui-webcomponents-excel' ) ,
215+ ig ( 'igniteui-webcomponents-spreadsheet' ) ,
216+ ig ( 'igniteui-webcomponents-spreadsheet-chart-adapter' ) ,
217+ ig ( 'igniteui-webcomponents-dashboards' ) ,
218+ ig ( 'igniteui-dockmanager' ) ,
147219 'igniteui-grid-lite' ,
148220 // CJS-only packages that need pre-bundling for named-export interop
149221 'file-saver' ,
0 commit comments