• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

alibaba / pipcook / 4088643824

pending completion
4088643824

Pull #951

github

GitHub
Merge 3588a38ba into c1acf7dc8
Pull Request #951: build(deps): bump http-cache-semantics from 4.1.0 to 4.1.1 in /packages/cli

436 of 530 branches covered (82.26%)

Branch coverage included in aggregate %.

692 of 736 relevant lines covered (94.02%)

4.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

63.93
/packages/cli/src/utils/plugin.ts
1
import * as fs from 'fs-extra';
9✔
2
import * as path from 'path';
9✔
3
import { ArtifactExports } from '@pipcook/core';
4
import { PipelineMeta } from '@pipcook/costa';
5
import * as constants from '../constants';
9✔
6
import { execAsync } from './';
9✔
7

8
export interface ArtifactMeta {
9
  artifactExports: ArtifactExports;
10
  options: Record<string, any>;
11
}
12

13
export interface PluginVersion {
14
  name: string,
15
  version: string
16
}
17

18
/**
19
 * extract the verison in the name expression, return empty string if no version found
20
 * @param name package name with semver
21
 */
22
export const extractVersion = (name: string): PluginVersion => {
9✔
23
  let n = name.length;
13✔
24
  while (n-- > 0) {
13✔
25
    if (name[n] === '/') {
85✔
26
      break;
1✔
27
    } else if (name[n] === '@') {
84✔
28
      return {
9✔
29
        name: name.substr(0, n),
30
        version: name.substr(n + 1)
31
      };
32
    }
33
  }
34
  return { name, version: 'latest' };
4✔
35
};
36

37
/**
38
 * install plugin
39
 * @param name package name: pipcook-ali-oss-uploader or pipcook-ali-oss-uploader@0.0.1
40
 * @param pluginHomeDir plugin home directory
41
 */
42
export const install = async (name: string, pluginHomeDir: string, npmClient: string, registry?: string): Promise<string> => {
9✔
43
  if (!await fs.pathExists(pluginHomeDir)) {
4✔
44
    await fs.mkdirp(pluginHomeDir);
1✔
45
  }
46
  const pluginVersion = extractVersion(name);
4✔
47
  const alias = `${pluginVersion.name}-${pluginVersion.version}`;
4✔
48
  const requirePath = path.join(pluginHomeDir, 'node_modules', alias);
4✔
49
  // always update plugin if version is 'beta', 'alpha' or 'latest'
50
  if ([ 'beta', 'alpha', 'latest' ].includes(pluginVersion.version) || !(await fs.pathExists(requirePath))) {
4✔
51
    await execAsync(
3✔
52
      `${npmClient} install ${alias}@npm:${name} -P --save${ registry ? ' --registry=' + registry : '' }`,
3!
53
      { cwd: pluginHomeDir }
54
    );
55
  }
56
  return requirePath;
4✔
57
};
58

59
export const prepareArtifactPlugin = async (pipelineMeta: PipelineMeta, npmClient: string, registry?: string): Promise<Array<ArtifactMeta>> => {
9✔
60
  if (
2!
61
    !pipelineMeta.artifact ||
4✔
62
    (Array.isArray(pipelineMeta.artifact) && pipelineMeta.artifact.length === 0)
63
  ) {
64
    return [];
2✔
65
  }
66
  const allPlugins: Array<ArtifactMeta> = [];
×
67
  for (const plugin of pipelineMeta.artifact) {
×
68
    const requirePath = await install(plugin.processor, constants.PIPCOOK_PLUGIN_ARTIFACT_PATH, npmClient, registry);
×
69
    let pluginExport: ArtifactExports = await import(requirePath);
×
70
    if (
×
71
      typeof pluginExport.initialize !== 'function'
×
72
      || typeof pluginExport.build !== 'function'
73
    ) {
74
      if (
×
75
        (pluginExport as any).default
×
76
        && typeof (pluginExport as any).default.initialize === 'function'
77
        && typeof (pluginExport as any).default.build === 'function'
78
      ) {
79
        pluginExport = (pluginExport as any).default;
×
80
      } else {
81
        throw new TypeError(`${plugin} is not a valid artifact plugin`);
×
82
      }
83
    }
84
    await pluginExport.initialize(plugin);
×
85
    allPlugins.push({
×
86
      artifactExports: pluginExport,
87
      options: plugin
88
    });
89
  }
90
  return allPlugins;
×
91
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc