• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import {
17  ARK_COMPILER_META_INFO,
18  ESMODULE,
19  IS_CACHE_INVALID
20} from './common/ark_define';
21
22let disableCache: boolean = false;
23export function checkArkCompilerCacheInfo(rollupObject: any): void {
24  disableCache = false;
25  const metaInfo: string = getMetaInfo(rollupObject.share.projectConfig);
26  const lastMetaInfo: string = rollupObject.cache.get(ARK_COMPILER_META_INFO);
27  if (!lastMetaInfo || metaInfo !== lastMetaInfo) {
28    rollupObject.cache.set(IS_CACHE_INVALID, true);
29    disableCache = true;
30  }
31  rollupObject.cache.set(ARK_COMPILER_META_INFO, metaInfo);
32}
33
34function getMetaInfo(projectConfig: any): string {
35  let metaInfoArr: string[] = [];
36  // user selects the compiled API version information
37  const compileSdkVersion: string = projectConfig.compileSdkVersion ?
38    projectConfig.compileSdkVersion : 'null_compileSdkVersion';
39  // user selects the compatible API version information
40  const compatibleSdkVersion: string = projectConfig.compatibleSdkVersion ?
41    projectConfig.compatibleSdkVersion : 'null_compatibleSdkVersion';
42  const runtimeOS: string = projectConfig.runtimeOS ? projectConfig.runtimeOS : 'null_runtimeOS';
43  const sdkPath: string = projectConfig.etsLoaderPath ?
44    projectConfig.etsLoaderPath : 'null_sdkPath';
45  // version information for loading SDKs in the IDE
46  const sdkVersion: string = projectConfig.etsLoaderVersion ?
47    projectConfig.etsLoaderVersion : 'null_sdkVersion';
48  const sdkReleaseType: string = projectConfig.etsLoaderReleaseType ?
49    projectConfig.etsLoaderReleaseType : 'null_sdkReleaseType';
50  metaInfoArr.push(compileSdkVersion, compatibleSdkVersion, runtimeOS, sdkPath, sdkVersion, sdkReleaseType);
51
52  if (projectConfig.compileMode === ESMODULE) {
53    const bundleName: string = projectConfig.bundleName ? projectConfig.bundleName : 'null_bundleName';
54    const allModuleNameHash: string = projectConfig.allModuleNameHash ? projectConfig.allModuleNameHash :
55      'null_allModuleNameHash';
56    const aotCompileMode: string = projectConfig.aotCompileMode ? projectConfig.aotCompileMode : 'null_aotCompileMode';
57    const apPath: string = projectConfig.apPath ? projectConfig.apPath : 'null_apPath';
58    metaInfoArr.push(bundleName, allModuleNameHash, aotCompileMode, apPath);
59  }
60
61  return metaInfoArr.join(':');
62}
63
64/**
65 * rollup shouldInvalidCache hook
66 * @param {rollup OutputOptions} options
67 */
68export function shouldInvalidCache(): boolean {
69  return disableCache;
70}
71