Esempio n. 1
0
        void TryToResolveFromBuildCache(TSFileAdditionalInfo itemInfo)
        {
            itemInfo.TakenFromBuildCache = false;
            var bc = _owner.ProjectOptions.BuildCache;

            if (bc.IsEnabled)
            {
                var fbc = bc.FindTSFileBuildCache(itemInfo.Owner.HashOfContent, _owner.ProjectOptions.ConfigurationBuildCacheId);
                if (fbc != null)
                {
                    if ((fbc.LocalImports?.Count ?? 0) == 0 && (fbc.ModuleImports?.Count ?? 0) == 0)
                    {
                        itemInfo.StartCompiling();
                        itemInfo.Output  = fbc.JsOutput;
                        itemInfo.MapLink = fbc.MapLink;
                        var fullPath  = PathUtils.ChangeExtension(itemInfo.Owner.FullPath, "d.ts");
                        var dirPath   = PathUtils.Parent(fullPath);
                        var fileOnly  = fullPath.Substring(dirPath.Length + 1);
                        var dc        = _owner.DiskCache.TryGetItem(dirPath) as IDirectoryCache;
                        var wasChange = dc.WriteVirtualFile(fileOnly, fbc.DtsOutput);
                        var output    = dc.TryGetChild(fileOnly) as IFileCache;
                        itemInfo.DtsLink = TSFileAdditionalInfo.Get(output, _owner.DiskCache);
                        if (wasChange)
                        {
                            ChangedDts = true;
                        }
                        itemInfo.RememberLastCompilationCacheIds();
                        itemInfo.TakenFromBuildCache = true;
                    }
                }
            }
        }
Esempio n. 2
0
        void CrawlInfo(TSFileAdditionalInfo info)
        {
            if (info.Owner.ChangeId != info.ChangeId)
            {
                info.ChangeId = info.Owner.ChangeId;
                Result.RecompiledIncrementaly.Add(info);
                var oldDependencies = new StructList <string>();
                if (_noDependencyCheck)
                {
                    oldDependencies.TransferFrom(ref info.Dependencies);
                }
                info.StartCompiling();
                switch (info.Type)
                {
                case FileCompilationType.Json:
                    info.Output     = null;
                    info.MapLink    = null;
                    info.SourceInfo = null;
                    break;

                case FileCompilationType.EsmJavaScript:
                case FileCompilationType.TypeScript:
                    info.HasError = false;
                    if (!TryToResolveFromBuildCache(info))
                    {
                        info.Output     = null;
                        info.MapLink    = null;
                        info.SourceInfo = null;
                        Transpile(info);
                    }
                    break;

                case FileCompilationType.JavaScriptAsset:
                case FileCompilationType.JavaScript:
                    info.Output  = info.Owner.Utf8Content;
                    info.MapLink = SourceMap.Identity(info.Output, info.Owner.FullPath);
                    break;

                case FileCompilationType.Resource:
                    break;

                case FileCompilationType.Css:
                case FileCompilationType.ImportedCss:
                    if (!TryToResolveFromBuildCacheCss(info))
                    {
                        var cssProcessor = BuildCtx.CompilerPool.GetCss();
                        try
                        {
                            info.Output = info.Owner.Utf8Content;
                            cssProcessor.ProcessCss(info.Owner.Utf8Content,
                                                    ((TSFileAdditionalInfo)info).Owner.FullPath, (string url, string from) =>
                            {
                                var urlJustName = url.Split('?', '#')[0];
                                info.ReportTranspilationDependency(null, urlJustName, null);
                                return(url);
                            }).Wait();
                        }
                        finally
                        {
                            BuildCtx.CompilerPool.ReleaseCss(cssProcessor);
                        }
                    }
                    ReportDependenciesFromCss(info);
                    break;
                }
                if (_noDependencyCheck)
                {
                    if (!info.Dependencies.SequenceEqual(oldDependencies))
                    {
                        if (BuildCtx.Verbose)
                        {
                            Owner.Logger.Info("Dependency change detected " + info.Owner.FullPath);
                        }
                        _noDependencyCheck = false;
                    }
                }
            }
        }