1- import { join } from 'path' ;
1+ import { join , dirname } from 'path' ;
22import {
33 Rule ,
44 SchematicContext ,
@@ -22,6 +22,8 @@ import { getJsonFile, getFileContents, getPackageJson, overwritePackageJson } fr
2222import { getAngularProjectSettings , AngularProjectSettings } from '../angular-project-parser' ;
2323import { Extensions } from '../generate/utils' ;
2424
25+ import { Schema as ConvertRelativeImportsSchema } from '../convert-relative-imports/schema' ;
26+
2527let extensions : Extensions ;
2628let projectSettings : AngularProjectSettings ;
2729
@@ -46,14 +48,17 @@ export default function (options: MigrationOptions): Rule {
4648 mergeGitIgnore ,
4749 addRunScriptsToPackageJson ,
4850 addNativeScriptProjectId ,
49- excludeNsFilesFromTsconfig ,
51+
52+ modifyWebTsconfig ,
5053
5154 options . skipAutoGeneratedComponent ?
5255 noop ( ) :
5356 addSampleComponent ( options . nsExtension , options . webExtension , options . project ) ,
5457
5558 addDependencies ( ) ,
5659
60+ schematic < ConvertRelativeImportsSchema > ( 'convert-relative-imports' , options ) ,
61+
5762 options . skipInstall ?
5863 noop ( ) :
5964 ( _tree : Tree , context : SchematicContext ) => {
@@ -211,6 +216,7 @@ const mergeGitIgnore = (tree: Tree, context: SchematicContext) => {
211216 */
212217const addRunScriptsToPackageJson = ( tree : Tree , context : SchematicContext ) => {
213218 context . logger . info ( 'Adding NativeScript run scripts to package.json' ) ;
219+
214220 const packageJson = getPackageJson ( tree ) ;
215221
216222 const scriptsToAdd = {
@@ -237,26 +243,57 @@ const addNativeScriptProjectId = (tree: Tree, context: SchematicContext) => {
237243}
238244
239245/**
240- * Adds {N}-specific extensions
241- * to the list with excluded files
242- * in the web TypeScript configuration
246+ * Add web-specific path mappings and files
243247 */
244- const excludeNsFilesFromTsconfig = ( tree : Tree , context : SchematicContext ) => {
245- context . logger . info ( 'Excluding NativeScript files from web tsconfig' ) ;
246-
247- const nsExtensions = [
248- `**/*${ extensions . ns } .ts` ,
249- '**/*.android.ts' ,
250- '**/*.ios.ts' ,
251- ] ;
248+ const modifyWebTsconfig = ( tree : Tree , context : SchematicContext ) => {
249+ context . logger . info ( 'Modifying web tsconfig' ) ;
252250
253251 const tsConfigPath = projectSettings . tsConfig ;
254252 const tsConfig : any = getJsonFile ( tree , tsConfigPath ) ;
255253
256- tsConfig . exclude = tsConfig . exclude || [ ] ;
257- tsConfig . exclude = [ ...tsConfig . exclude , ...nsExtensions ] ;
254+ // files
255+ const defaultFiles = [ "main.ts" , "polyfills.ts" ] ;
256+ tsConfig . files = tsConfig . files || [ ] ;
257+ tsConfig . files . push ( ...defaultFiles ) ;
258+
259+ // paths
260+ const srcDir = projectSettings . sourceRoot ;
261+ const webPaths = {
262+ "@src/*" : [
263+ `${ srcDir } /*.web` ,
264+ `${ srcDir } /*` ]
265+ } ;
266+ tsConfig . compilerOptions = tsConfig . compilerOptions || { } ;
267+ tsConfig . compilerOptions . paths = {
268+ ...tsConfig . compilerOptions . paths ,
269+ ...webPaths
270+ }
258271
259272 tree . overwrite ( tsConfigPath , JSON . stringify ( tsConfig , null , 2 ) ) ;
273+
274+ if ( ! tsConfig . extends ) {
275+ return
276+ }
277+
278+ const baseTsConfigPath = join ( dirname ( tsConfigPath ) , tsConfig . extends ) ;
279+ const baseTsConfig : any = getJsonFile ( tree , baseTsConfigPath ) ;
280+
281+ const basePaths = {
282+ "@src/*" : [
283+ `${ srcDir } /*.android.ts` ,
284+ `${ srcDir } /*.ios.ts` ,
285+ `${ srcDir } /*.tns.ts` ,
286+ `${ srcDir } /*.web.ts` ,
287+ `${ srcDir } /*` ]
288+ } ;
289+
290+ baseTsConfig . compilerOptions = baseTsConfig . compilerOptions || { } ;
291+ baseTsConfig . compilerOptions . paths = {
292+ ...baseTsConfig . compilerOptions . paths ,
293+ ...basePaths
294+ }
295+
296+ tree . overwrite ( baseTsConfigPath , JSON . stringify ( baseTsConfig , null , 2 ) ) ;
260297}
261298
262299const addDependencies = ( ) => ( tree : Tree , context : SchematicContext ) => {
0 commit comments