From abbbc69e64048c5f4121f6d13082651adfab3843 Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Wed, 22 May 2019 15:01:33 +0100 Subject: [PATCH] test(ivy): ngcc - remove use of mock-fs in tests (#30591) Now that ngcc uses a `FileSystem` throughout we no longer need to rely upon mocking out the real file-system with mock-fs. PR Close #30591 --- package.json | 2 -- packages/compiler-cli/ngcc/src/main.ts | 37 +++++++++++++++----------- tools/defaults.bzl | 1 - yarn.lock | 12 --------- 4 files changed, 21 insertions(+), 31 deletions(-) diff --git a/package.json b/package.json index 56762964f7..dc4db79c5a 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,6 @@ "@types/jasmine": "^2.8.8", "@types/jasminewd2": "^2.0.6", "@types/minimist": "^1.2.0", - "@types/mock-fs": "^3.6.30", "@types/node": "^10.9.4", "@types/selenium-webdriver": "3.0.7", "@types/shelljs": "^0.7.8", @@ -90,7 +89,6 @@ "magic-string": "^0.25.0", "materialize-css": "1.0.0", "minimist": "1.2.0", - "mock-fs": "^4.10.1", "node-uuid": "1.4.8", "nodejs-websocket": "^1.7.2", "protractor": "^5.4.2", diff --git a/packages/compiler-cli/ngcc/src/main.ts b/packages/compiler-cli/ngcc/src/main.ts index d7d3a0ec95..32c4614b1b 100644 --- a/packages/compiler-cli/ngcc/src/main.ts +++ b/packages/compiler-cli/ngcc/src/main.ts @@ -60,6 +60,10 @@ export interface NgccOptions { * These are used to resolve paths to locally built Angular libraries. */ pathMappings?: PathMappings; + /** + * Provide a file-system service that will be used by ngcc for all file interactions. + */ + fileSystem?: FileSystem; } const SUPPORTED_FORMATS: EntryPointFormat[] = ['esm5', 'esm2015', 'umd', 'commonjs']; @@ -76,27 +80,27 @@ export function mainNgcc( {basePath, targetEntryPointPath, propertiesToConsider = SUPPORTED_FORMAT_PROPERTIES, compileAllFormats = true, createNewEntryPointFormats = false, logger = new ConsoleLogger(LogLevel.info), pathMappings}: NgccOptions): void { - const fs = getFileSystem(); - const transformer = new Transformer(fs, logger); - const moduleResolver = new ModuleResolver(fs, pathMappings); - const esmDependencyHost = new EsmDependencyHost(fs, moduleResolver); - const umdDependencyHost = new UmdDependencyHost(fs, moduleResolver); - const commonJsDependencyHost = new CommonJsDependencyHost(fs, moduleResolver); - const resolver = new DependencyResolver(fs, logger, { + const fileSystem = getFileSystem(); + const transformer = new Transformer(fileSystem, logger); + const moduleResolver = new ModuleResolver(fileSystem, pathMappings); + const esmDependencyHost = new EsmDependencyHost(fileSystem, moduleResolver); + const umdDependencyHost = new UmdDependencyHost(fileSystem, moduleResolver); + const commonJsDependencyHost = new CommonJsDependencyHost(fileSystem, moduleResolver); + const resolver = new DependencyResolver(fileSystem, logger, { esm5: esmDependencyHost, esm2015: esmDependencyHost, umd: umdDependencyHost, commonjs: commonJsDependencyHost }); - const finder = new EntryPointFinder(fs, logger, resolver); - const fileWriter = getFileWriter(fs, createNewEntryPointFormats); + const finder = new EntryPointFinder(fileSystem, logger, resolver); + const fileWriter = getFileWriter(fileSystem, createNewEntryPointFormats); const absoluteTargetEntryPointPath = targetEntryPointPath ? resolve(basePath, targetEntryPointPath) : undefined; if (absoluteTargetEntryPointPath && hasProcessedTargetEntryPoint( - fs, absoluteTargetEntryPointPath, propertiesToConsider, compileAllFormats)) { + fileSystem, absoluteTargetEntryPointPath, propertiesToConsider, compileAllFormats)) { logger.debug('The target entry-point has already been processed'); return; } @@ -112,7 +116,8 @@ export function mainNgcc( }); if (absoluteTargetEntryPointPath && entryPoints.length === 0) { - markNonAngularPackageAsProcessed(fs, absoluteTargetEntryPointPath, propertiesToConsider); + markNonAngularPackageAsProcessed( + fileSystem, absoluteTargetEntryPointPath, propertiesToConsider); return; } @@ -122,14 +127,14 @@ export function mainNgcc( const compiledFormats = new Set(); const entryPointPackageJson = entryPoint.packageJson; - const entryPointPackageJsonPath = fs.resolve(entryPoint.path, 'package.json'); + const entryPointPackageJsonPath = fileSystem.resolve(entryPoint.path, 'package.json'); const hasProcessedDts = hasBeenProcessed(entryPointPackageJson, 'typings'); for (let i = 0; i < propertiesToConsider.length; i++) { const property = propertiesToConsider[i] as EntryPointJsonProperty; const formatPath = entryPointPackageJson[property]; - const format = getEntryPointFormat(fs, entryPoint, property); + const format = getEntryPointFormat(fileSystem, entryPoint, property); // No format then this property is not supposed to be compiled. if (!formatPath || !format || SUPPORTED_FORMATS.indexOf(format) === -1) continue; @@ -147,7 +152,7 @@ export function mainNgcc( // the property as processed even if its underlying format has been built already. if (!compiledFormats.has(formatPath) && (compileAllFormats || isFirstFormat)) { const bundle = makeEntryPointBundle( - fs, entryPoint.path, formatPath, entryPoint.typings, isCore, property, format, + fileSystem, entryPoint.path, formatPath, entryPoint.typings, isCore, property, format, processDts, pathMappings); if (bundle) { logger.info(`Compiling ${entryPoint.name} : ${property} as ${format}`); @@ -165,9 +170,9 @@ export function mainNgcc( // Either this format was just compiled or its underlying format was compiled because of a // previous property. if (compiledFormats.has(formatPath)) { - markAsProcessed(fs, entryPointPackageJson, entryPointPackageJsonPath, property); + markAsProcessed(fileSystem, entryPointPackageJson, entryPointPackageJsonPath, property); if (processDts) { - markAsProcessed(fs, entryPointPackageJson, entryPointPackageJsonPath, 'typings'); + markAsProcessed(fileSystem, entryPointPackageJson, entryPointPackageJsonPath, 'typings'); } } } diff --git a/tools/defaults.bzl b/tools/defaults.bzl index c3ad35e90d..79aa7d1c1d 100644 --- a/tools/defaults.bzl +++ b/tools/defaults.bzl @@ -271,7 +271,6 @@ def jasmine_node_test(deps = [], **kwargs): "@npm//chokidar", "@npm//domino", "@npm//jasmine-core", - "@npm//mock-fs", "@npm//reflect-metadata", "@npm//source-map-support", "@npm//tslib", diff --git a/yarn.lock b/yarn.lock index fc41ceec39..a4bb03d8f9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -538,13 +538,6 @@ resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.0.tgz#69a23a3ad29caf0097f06eda59b361ee2f0639f6" integrity sha1-aaI6OtKcrwCX8G7aWbNh7i8GOfY= -"@types/mock-fs@^3.6.30": - version "3.6.30" - resolved "https://registry.yarnpkg.com/@types/mock-fs/-/mock-fs-3.6.30.tgz#4d812541e87b23577261a5aa95f704dd3d01e410" - integrity sha1-TYElQeh7I1dyYaWqlfcE3T0B5BA= - dependencies: - "@types/node" "*" - "@types/node@*": version "10.5.2" resolved "https://registry.yarnpkg.com/@types/node/-/node-10.5.2.tgz#f19f05314d5421fe37e74153254201a7bf00a707" @@ -7554,11 +7547,6 @@ mkpath@^0.1.0: resolved "https://registry.yarnpkg.com/mkpath/-/mkpath-0.1.0.tgz#7554a6f8d871834cc97b5462b122c4c124d6de91" integrity sha1-dVSm+Nhxg0zJe1RisSLEwSTW3pE= -mock-fs@^4.10.1: - version "4.10.1" - resolved "https://registry.yarnpkg.com/mock-fs/-/mock-fs-4.10.1.tgz#50a07a20114a6cdb119f35762f61f46266a1e323" - integrity sha512-w22rOL5ZYu6HbUehB5deurghGM0hS/xBVyHMGKOuQctkk93J9z9VEOhDsiWrXOprVNQpP9uzGKdl8v9mFspKuw== - modelo@^4.2.0: version "4.2.3" resolved "https://registry.yarnpkg.com/modelo/-/modelo-4.2.3.tgz#b278588a4db87fc1e5107ae3a277c0876f38d894"