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:
Pete Bacon Darwin 2020-05-14 21:12:35 +01:00 committed by Misko Hevery
parent 6de5a12a9d
commit 2b53b07c70
13 changed files with 76 additions and 19 deletions

View File

@ -25,6 +25,7 @@ ts_library(
"//packages/compiler-cli/src/ngtsc/perf", "//packages/compiler-cli/src/ngtsc/perf",
"//packages/compiler-cli/src/ngtsc/reflection", "//packages/compiler-cli/src/ngtsc/reflection",
"//packages/compiler-cli/src/ngtsc/scope", "//packages/compiler-cli/src/ngtsc/scope",
"//packages/compiler-cli/src/ngtsc/sourcemaps",
"//packages/compiler-cli/src/ngtsc/transform", "//packages/compiler-cli/src/ngtsc/transform",
"//packages/compiler-cli/src/ngtsc/translator", "//packages/compiler-cli/src/ngtsc/translator",
"//packages/compiler-cli/src/ngtsc/util", "//packages/compiler-cli/src/ngtsc/util",
@ -36,8 +37,6 @@ ts_library(
"@npm//dependency-graph", "@npm//dependency-graph",
"@npm//magic-string", "@npm//magic-string",
"@npm//semver", "@npm//semver",
"@npm//source-map",
"@npm//sourcemap-codec",
"@npm//typescript", "@npm//typescript",
], ],
) )

View File

@ -11,8 +11,7 @@ import * as ts from 'typescript';
import {absoluteFrom, absoluteFromSourceFile, basename, FileSystem} from '../../../src/ngtsc/file_system'; import {absoluteFrom, absoluteFromSourceFile, basename, FileSystem} from '../../../src/ngtsc/file_system';
import {Logger} from '../../../src/ngtsc/logging'; import {Logger} from '../../../src/ngtsc/logging';
import {RawSourceMap} from '../sourcemaps/raw_source_map'; import {RawSourceMap, SourceFileLoader} from '../../../src/ngtsc/sourcemaps';
import {SourceFileLoader} from '../sourcemaps/source_file_loader';
import {FileToWrite} from './utils'; import {FileToWrite} from './utils';

View 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",
],
)

View File

@ -0,0 +1,3 @@
# Source-map handling
Here there are classes for loading and merging source-maps.

View 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';

View File

@ -8,7 +8,7 @@
import {removeComments, removeMapFileComments} from 'convert-source-map'; import {removeComments, removeMapFileComments} from 'convert-source-map';
import {decode, encode, SourceMapMappings, SourceMapSegment} from 'sourcemap-codec'; 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 {RawSourceMap} from './raw_source_map';
import {compareSegments, offsetSegment, SegmentMarker} from './segment_marker'; import {compareSegments, offsetSegment, SegmentMarker} from './segment_marker';

View File

@ -7,8 +7,8 @@
*/ */
import {commentRegex, fromComment, mapFileCommentRegex} from 'convert-source-map'; import {commentRegex, fromComment, mapFileCommentRegex} from 'convert-source-map';
import {absoluteFrom, AbsoluteFsPath, FileSystem} from '../../../src/ngtsc/file_system'; import {absoluteFrom, AbsoluteFsPath, FileSystem} from '../../file_system';
import {Logger} from '../../../src/ngtsc/logging'; import {Logger} from '../../logging';
import {RawSourceMap} from './raw_source_map'; import {RawSourceMap} from './raw_source_map';
import {SourceFile} from './source_file'; import {SourceFile} from './source_file';

View 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",
],
)

View File

@ -5,8 +5,8 @@
* Use of this source code is governed by an MIT-style license that can be * 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 * found in the LICENSE file at https://angular.io/license
*/ */
import {compareSegments, offsetSegment} from '../../src/sourcemaps/segment_marker'; import {compareSegments, offsetSegment} from '../src/segment_marker';
import {computeStartOfLinePositions} from '../../src/sourcemaps/source_file'; import {computeStartOfLinePositions} from '../src/source_file';
describe('SegmentMarker utils', () => { describe('SegmentMarker utils', () => {
describe('compareSegments()', () => { describe('compareSegments()', () => {

View File

@ -5,13 +5,13 @@
* Use of this source code is governed by an MIT-style license that can be * 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 * 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 {fromObject} from 'convert-source-map';
import {runInEachFileSystem} from '../../../src/ngtsc/file_system/testing'; import {absoluteFrom, FileSystem, getFileSystem} from '../../file_system';
import {MockLogger} from '../../../src/ngtsc/logging/testing'; import {runInEachFileSystem} from '../../file_system/testing';
import {RawSourceMap} from '../../src/sourcemaps/raw_source_map'; import {MockLogger} from '../../logging/testing';
import {SourceFileLoader as SourceFileLoader} from '../../src/sourcemaps/source_file_loader'; import {RawSourceMap} from '../src/raw_source_map';
import {SourceFileLoader as SourceFileLoader} from '../src/source_file_loader';
runInEachFileSystem(() => { runInEachFileSystem(() => {
describe('SourceFileLoader', () => { describe('SourceFileLoader', () => {

View File

@ -7,11 +7,11 @@
*/ */
import {encode} from 'sourcemap-codec'; import {encode} from 'sourcemap-codec';
import {absoluteFrom} from '../../../src/ngtsc/file_system'; import {absoluteFrom} from '../../file_system';
import {runInEachFileSystem} from '../../../src/ngtsc/file_system/testing'; import {runInEachFileSystem} from '../../file_system/testing';
import {RawSourceMap} from '../../src/sourcemaps/raw_source_map'; import {RawSourceMap} from '../src/raw_source_map';
import {SegmentMarker} from '../../src/sourcemaps/segment_marker'; import {SegmentMarker} from '../src/segment_marker';
import {computeStartOfLinePositions, ensureOriginalSegmentLinks, extractOriginalSegments, findLastMappingIndexBefore, Mapping, parseMappings, SourceFile} from '../../src/sourcemaps/source_file'; import {computeStartOfLinePositions, ensureOriginalSegmentLinks, extractOriginalSegments, findLastMappingIndexBefore, Mapping, parseMappings, SourceFile} from '../src/source_file';
runInEachFileSystem(() => { runInEachFileSystem(() => {
describe('SourceFile and utilities', () => { describe('SourceFile and utilities', () => {