refactor(ngcc): move sourcemaps into ngtsc (#37114)
				
					
				
			The `SourceFile` and associated code is general and reusable in other projects (such as `@angular/localize`). Moving it to `ngtsc` makes it more easily shared. PR Close #37114
This commit is contained in:
		
							parent
							
								
									6de5a12a9d
								
							
						
					
					
						commit
						2b53b07c70
					
				| @ -25,6 +25,7 @@ ts_library( | ||||
|         "//packages/compiler-cli/src/ngtsc/perf", | ||||
|         "//packages/compiler-cli/src/ngtsc/reflection", | ||||
|         "//packages/compiler-cli/src/ngtsc/scope", | ||||
|         "//packages/compiler-cli/src/ngtsc/sourcemaps", | ||||
|         "//packages/compiler-cli/src/ngtsc/transform", | ||||
|         "//packages/compiler-cli/src/ngtsc/translator", | ||||
|         "//packages/compiler-cli/src/ngtsc/util", | ||||
| @ -36,8 +37,6 @@ ts_library( | ||||
|         "@npm//dependency-graph", | ||||
|         "@npm//magic-string", | ||||
|         "@npm//semver", | ||||
|         "@npm//source-map", | ||||
|         "@npm//sourcemap-codec", | ||||
|         "@npm//typescript", | ||||
|     ], | ||||
| ) | ||||
|  | ||||
| @ -11,8 +11,7 @@ import * as ts from 'typescript'; | ||||
| 
 | ||||
| import {absoluteFrom, absoluteFromSourceFile, basename, FileSystem} from '../../../src/ngtsc/file_system'; | ||||
| import {Logger} from '../../../src/ngtsc/logging'; | ||||
| import {RawSourceMap} from '../sourcemaps/raw_source_map'; | ||||
| import {SourceFileLoader} from '../sourcemaps/source_file_loader'; | ||||
| import {RawSourceMap, SourceFileLoader} from '../../../src/ngtsc/sourcemaps'; | ||||
| 
 | ||||
| import {FileToWrite} from './utils'; | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										18
									
								
								packages/compiler-cli/src/ngtsc/sourcemaps/BUILD.bazel
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								packages/compiler-cli/src/ngtsc/sourcemaps/BUILD.bazel
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,18 @@ | ||||
| load("//tools:defaults.bzl", "ts_library") | ||||
| 
 | ||||
| package(default_visibility = ["//visibility:public"]) | ||||
| 
 | ||||
| ts_library( | ||||
|     name = "sourcemaps", | ||||
|     srcs = ["index.ts"] + glob([ | ||||
|         "src/**/*.ts", | ||||
|     ]), | ||||
|     deps = [ | ||||
|         "//packages/compiler-cli/src/ngtsc/file_system", | ||||
|         "//packages/compiler-cli/src/ngtsc/logging", | ||||
|         "@npm//@types/convert-source-map", | ||||
|         "@npm//@types/node", | ||||
|         "@npm//source-map", | ||||
|         "@npm//sourcemap-codec", | ||||
|     ], | ||||
| ) | ||||
							
								
								
									
										3
									
								
								packages/compiler-cli/src/ngtsc/sourcemaps/README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								packages/compiler-cli/src/ngtsc/sourcemaps/README.md
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,3 @@ | ||||
| # Source-map handling | ||||
| 
 | ||||
| Here there are classes for loading and merging source-maps. | ||||
							
								
								
									
										10
									
								
								packages/compiler-cli/src/ngtsc/sourcemaps/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								packages/compiler-cli/src/ngtsc/sourcemaps/index.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,10 @@ | ||||
| /** | ||||
|  * @license | ||||
|  * Copyright Google LLC All Rights Reserved. | ||||
|  * | ||||
|  * Use of this source code is governed by an MIT-style license that can be | ||||
|  * found in the LICENSE file at https://angular.io/license
 | ||||
|  */ | ||||
| export {RawSourceMap} from './src/raw_source_map'; | ||||
| export {Mapping, SourceFile} from './src/source_file'; | ||||
| export {SourceFileLoader} from './src/source_file_loader'; | ||||
| @ -8,7 +8,7 @@ | ||||
| import {removeComments, removeMapFileComments} from 'convert-source-map'; | ||||
| import {decode, encode, SourceMapMappings, SourceMapSegment} from 'sourcemap-codec'; | ||||
| 
 | ||||
| import {AbsoluteFsPath, dirname, relative} from '../../../src/ngtsc/file_system'; | ||||
| import {AbsoluteFsPath, dirname, relative} from '../../file_system'; | ||||
| 
 | ||||
| import {RawSourceMap} from './raw_source_map'; | ||||
| import {compareSegments, offsetSegment, SegmentMarker} from './segment_marker'; | ||||
| @ -7,8 +7,8 @@ | ||||
|  */ | ||||
| import {commentRegex, fromComment, mapFileCommentRegex} from 'convert-source-map'; | ||||
| 
 | ||||
| import {absoluteFrom, AbsoluteFsPath, FileSystem} from '../../../src/ngtsc/file_system'; | ||||
| import {Logger} from '../../../src/ngtsc/logging'; | ||||
| import {absoluteFrom, AbsoluteFsPath, FileSystem} from '../../file_system'; | ||||
| import {Logger} from '../../logging'; | ||||
| 
 | ||||
| import {RawSourceMap} from './raw_source_map'; | ||||
| import {SourceFile} from './source_file'; | ||||
							
								
								
									
										28
									
								
								packages/compiler-cli/src/ngtsc/sourcemaps/test/BUILD.bazel
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								packages/compiler-cli/src/ngtsc/sourcemaps/test/BUILD.bazel
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,28 @@ | ||||
| load("//tools:defaults.bzl", "jasmine_node_test", "ts_library") | ||||
| 
 | ||||
| package(default_visibility = ["//visibility:public"]) | ||||
| 
 | ||||
| ts_library( | ||||
|     name = "test_lib", | ||||
|     testonly = True, | ||||
|     srcs = glob([ | ||||
|         "**/*.ts", | ||||
|     ]), | ||||
|     deps = [ | ||||
|         "//packages/compiler-cli/src/ngtsc/file_system", | ||||
|         "//packages/compiler-cli/src/ngtsc/file_system/testing", | ||||
|         "//packages/compiler-cli/src/ngtsc/logging/testing", | ||||
|         "//packages/compiler-cli/src/ngtsc/sourcemaps", | ||||
|         "@npm//@types/convert-source-map", | ||||
|         "@npm//convert-source-map", | ||||
|         "@npm//sourcemap-codec", | ||||
|     ], | ||||
| ) | ||||
| 
 | ||||
| jasmine_node_test( | ||||
|     name = "test", | ||||
|     bootstrap = ["//tools/testing:node_no_angular_es5"], | ||||
|     deps = [ | ||||
|         ":test_lib", | ||||
|     ], | ||||
| ) | ||||
| @ -5,8 +5,8 @@ | ||||
|  * Use of this source code is governed by an MIT-style license that can be | ||||
|  * found in the LICENSE file at https://angular.io/license
 | ||||
|  */ | ||||
| import {compareSegments, offsetSegment} from '../../src/sourcemaps/segment_marker'; | ||||
| import {computeStartOfLinePositions} from '../../src/sourcemaps/source_file'; | ||||
| import {compareSegments, offsetSegment} from '../src/segment_marker'; | ||||
| import {computeStartOfLinePositions} from '../src/source_file'; | ||||
| 
 | ||||
| describe('SegmentMarker utils', () => { | ||||
|   describe('compareSegments()', () => { | ||||
| @ -5,13 +5,13 @@ | ||||
|  * Use of this source code is governed by an MIT-style license that can be | ||||
|  * found in the LICENSE file at https://angular.io/license
 | ||||
|  */ | ||||
| import {absoluteFrom, FileSystem, getFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; | ||||
| import {fromObject} from 'convert-source-map'; | ||||
| 
 | ||||
| import {runInEachFileSystem} from '../../../src/ngtsc/file_system/testing'; | ||||
| import {MockLogger} from '../../../src/ngtsc/logging/testing'; | ||||
| import {RawSourceMap} from '../../src/sourcemaps/raw_source_map'; | ||||
| import {SourceFileLoader as SourceFileLoader} from '../../src/sourcemaps/source_file_loader'; | ||||
| import {absoluteFrom, FileSystem, getFileSystem} from '../../file_system'; | ||||
| import {runInEachFileSystem} from '../../file_system/testing'; | ||||
| import {MockLogger} from '../../logging/testing'; | ||||
| import {RawSourceMap} from '../src/raw_source_map'; | ||||
| import {SourceFileLoader as SourceFileLoader} from '../src/source_file_loader'; | ||||
| 
 | ||||
| runInEachFileSystem(() => { | ||||
|   describe('SourceFileLoader', () => { | ||||
| @ -7,11 +7,11 @@ | ||||
|  */ | ||||
| import {encode} from 'sourcemap-codec'; | ||||
| 
 | ||||
| import {absoluteFrom} from '../../../src/ngtsc/file_system'; | ||||
| import {runInEachFileSystem} from '../../../src/ngtsc/file_system/testing'; | ||||
| import {RawSourceMap} from '../../src/sourcemaps/raw_source_map'; | ||||
| import {SegmentMarker} from '../../src/sourcemaps/segment_marker'; | ||||
| import {computeStartOfLinePositions, ensureOriginalSegmentLinks, extractOriginalSegments, findLastMappingIndexBefore, Mapping, parseMappings, SourceFile} from '../../src/sourcemaps/source_file'; | ||||
| import {absoluteFrom} from '../../file_system'; | ||||
| import {runInEachFileSystem} from '../../file_system/testing'; | ||||
| import {RawSourceMap} from '../src/raw_source_map'; | ||||
| import {SegmentMarker} from '../src/segment_marker'; | ||||
| import {computeStartOfLinePositions, ensureOriginalSegmentLinks, extractOriginalSegments, findLastMappingIndexBefore, Mapping, parseMappings, SourceFile} from '../src/source_file'; | ||||
| 
 | ||||
| runInEachFileSystem(() => { | ||||
|   describe('SourceFile and utilities', () => { | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user