@canyonjs/cli 1.0.31 → 1.0.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/canyon.js CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
2
  // * The entry point of the CLI
3
- import('../dist/index.js').then((m) => m.cli(process.argv));
3
+ import("../dist/index.js").then((m) => m.cli(process.argv));
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import node_fs from "node:fs";
4
4
  import node_path from "node:path";
5
5
  import axios from "axios";
6
6
  var package_namespaceObject = {
7
- rE: "1.0.31"
7
+ rE: "1.0.33"
8
8
  };
9
9
  function mergeNumberMaps(a = {}, b = {}) {
10
10
  const result = {
@@ -60,26 +60,26 @@ function mergeCoverageMaps(target = {}, source = {}) {
60
60
  return out;
61
61
  }
62
62
  async function mapCommand(params, options) {
63
- console.log('Current working directory:', process.cwd());
64
- const isGitHubActions = 'true' === process.env.GITHUB_ACTIONS || !!process.env.GITHUB_EVENT_PATH;
63
+ console.log("Current working directory:", process.cwd());
64
+ const isGitHubActions = "true" === process.env.GITHUB_ACTIONS || !!process.env.GITHUB_EVENT_PATH;
65
65
  let githubEvent;
66
66
  if (isGitHubActions && process.env.GITHUB_EVENT_PATH) try {
67
- if (node_fs.existsSync(process.env.GITHUB_EVENT_PATH)) githubEvent = node_fs.readFileSync(process.env.GITHUB_EVENT_PATH, 'utf8');
68
- else console.log('GITHUB_EVENT_PATH file not found:', process.env.GITHUB_EVENT_PATH);
67
+ if (node_fs.existsSync(process.env.GITHUB_EVENT_PATH)) githubEvent = node_fs.readFileSync(process.env.GITHUB_EVENT_PATH, "utf8");
68
+ else console.log("GITHUB_EVENT_PATH file not found:", process.env.GITHUB_EVENT_PATH);
69
69
  } catch (error) {
70
- console.warn('Failed to read GITHUB_EVENT_PATH:', error);
70
+ console.warn("Failed to read GITHUB_EVENT_PATH:", error);
71
71
  }
72
72
  const { dsn, repo_id: repoID, sha, provider, build_target, debug, instrument_cwd, filter, scene } = params;
73
- if (!node_fs.existsSync(node_path.resolve(process.cwd(), '.canyon_output'))) return void console.log('No .canyon_output directory found, skipping upload.');
74
- const files = node_fs.readdirSync(node_path.resolve(process.cwd(), '.canyon_output'));
73
+ if (!node_fs.existsSync(node_path.resolve(process.cwd(), ".canyon_output"))) return void console.log("No .canyon_output directory found, skipping upload.");
74
+ const files = node_fs.readdirSync(node_path.resolve(process.cwd(), ".canyon_output"));
75
75
  let data = {};
76
76
  for(let i = 0; i < files.length; i++){
77
77
  const fileName = files[i];
78
78
  const isCoverageFinalFile = /^coverage-final-.*\.json$/.test(fileName);
79
- const fileCoverageString = node_fs.readFileSync(node_path.resolve(process.cwd(), '.canyon_output', fileName), 'utf-8');
79
+ const fileCoverageString = node_fs.readFileSync(node_path.resolve(process.cwd(), ".canyon_output", fileName), "utf-8");
80
80
  const fileCoverage = JSON.parse(fileCoverageString);
81
81
  let toMerge = fileCoverage;
82
- if (filter && 'string' == typeof filter && isCoverageFinalFile) {
82
+ if (filter && "string" == typeof filter && isCoverageFinalFile) {
83
83
  const filteredEntries = Object.entries(fileCoverage).filter(([filePath])=>filePath.includes(filter));
84
84
  if (0 === filteredEntries.length) continue;
85
85
  toMerge = Object.fromEntries(filteredEntries);
@@ -88,13 +88,22 @@ async function mapCommand(params, options) {
88
88
  }
89
89
  const env_branch = process.env.CI_COMMIT_BRANCH;
90
90
  const env_buildID = process.env.CI_JOB_ID;
91
- const env_buildProvider = 'gitlab_runner';
91
+ const env_buildProvider = "gitlab_runner";
92
+ let diffData;
93
+ const diffJsonPath = node_path.resolve(process.cwd(), "diff.json");
94
+ if (node_fs.existsSync(diffJsonPath)) try {
95
+ const diffJsonContent = node_fs.readFileSync(diffJsonPath, "utf-8");
96
+ diffData = JSON.parse(diffJsonContent);
97
+ console.log(`Found diff.json file: ${diffJsonPath}`);
98
+ } catch (error) {
99
+ console.warn(`Failed to read or parse diff.json: ${error}`);
100
+ }
92
101
  let sceneMap;
93
102
  if (scene && Array.isArray(scene)) {
94
103
  sceneMap = {};
95
104
  for (const pair of scene){
96
- if ('string' != typeof pair) return void console.error(`Invalid scene parameter: ${pair}. Expected format: key=value`);
97
- const equalIndex = pair.indexOf('=');
105
+ if ("string" != typeof pair) return void console.error(`Invalid scene parameter: ${pair}. Expected format: key=value`);
106
+ const equalIndex = pair.indexOf("=");
98
107
  if (-1 === equalIndex || 0 === equalIndex) return void console.error(`Invalid scene parameter format: ${pair}. Expected format: key=value`);
99
108
  const key = pair.substring(0, equalIndex);
100
109
  const value = pair.substring(equalIndex + 1);
@@ -104,13 +113,13 @@ async function mapCommand(params, options) {
104
113
  }
105
114
  const p = {
106
115
  dsn,
107
- provider: provider || 'gitlab',
116
+ provider: provider || "gitlab",
108
117
  repoID: repoID || process.env.CI_PROJECT_ID,
109
118
  sha: sha || process.env.CI_COMMIT_SHA,
110
- instrumentCwd: instrument_cwd || process.cwd(),
111
- reportID: 'initial_coverage_data',
112
- reportProvider: 'ci',
113
- buildTarget: build_target || '',
119
+ instrumentCwd: instrument_cwd || '',
120
+ reportID: "initial_coverage_data",
121
+ reportProvider: "ci",
122
+ buildTarget: build_target || "",
114
123
  coverage: Object.keys(data),
115
124
  build: {
116
125
  provider: isGitHubActions ? "github_actions" : env_buildProvider,
@@ -120,9 +129,12 @@ async function mapCommand(params, options) {
120
129
  },
121
130
  ...sceneMap && {
122
131
  scene: sceneMap
132
+ },
133
+ ...diffData && {
134
+ diff: diffData
123
135
  }
124
136
  };
125
- if ('true' === debug) console.log(p);
137
+ if ("true" === debug) console.log(p);
126
138
  await axios.post(dsn, {
127
139
  ...p,
128
140
  coverage: data
@@ -136,17 +148,17 @@ async function mapCommand(params, options) {
136
148
  });
137
149
  }
138
150
  const accent = chalk.greenBright;
139
- const CLI_BEFORE_ALL_TXT = `canyon: The ${accent('Canyon')} CLI - Version ${package_namespaceObject.rE} (${accent('https://github.com/canyon-project/canyon')}) ${chalk.black.bold.bgYellowBright(' ALPHA ')} \n`;
140
- const CLI_AFTER_ALL_TXT = `\nFor more help, head on to ${accent('https://github.com/canyon-project/canyon')}`;
141
- program.name('canyon').version(package_namespaceObject.rE, '-v, --version', 'see the current version of canyon-uploader').usage('[options or commands] arguments').addHelpText('beforeAll', CLI_BEFORE_ALL_TXT).addHelpText('after', CLI_AFTER_ALL_TXT).configureHelp({
151
+ const CLI_BEFORE_ALL_TXT = `canyon: The ${accent("Canyon")} CLI - Version ${package_namespaceObject.rE} (${accent("https://github.com/canyon-project/canyon")}) ${chalk.black.bold.bgYellowBright(" ALPHA ")} \n`;
152
+ const CLI_AFTER_ALL_TXT = `\nFor more help, head on to ${accent("https://github.com/canyon-project/canyon")}`;
153
+ program.name("canyon").version(package_namespaceObject.rE, "-v, --version", "see the current version of canyon-uploader").usage("[options or commands] arguments").addHelpText("beforeAll", CLI_BEFORE_ALL_TXT).addHelpText("after", CLI_AFTER_ALL_TXT).configureHelp({
142
154
  optionTerm: (option)=>accent(option.flags),
143
155
  subcommandTerm: (cmd)=>accent(cmd.name(), cmd.usage()),
144
156
  argumentTerm: (arg)=>accent(arg.name())
145
157
  }).showHelpAfterError(true);
146
- program.command('upload').option('--debug <dsn>', 'debug').option('--dsn <dsn>', 'dsn of the canyon server').option('--repo_id <repo_id>', 'repo id of the canyon server').option('--filter <filter>', '仅合并路径包含该子串的文件覆盖率').option('--instrument_cwd <instrument_cwd>', 'instrument cwd of the canyon server').option('--sha <sha>', 'sha of the canyon server').option('--branch <branch>', 'branch of the canyon server').option('--provider <provider>', 'provider of the canyon server').option('--build_target <build_target>', 'build target of the canyon server').option('--coverage <coverage>', 'coverage of the canyon server').option('--scene <key=value>', 'scene key-value pair, can be used multiple times, e.g. --scene env=prod --scene type=e2e', (value, previous = [])=>{
158
+ program.command("upload").option("--debug <dsn>", "debug").option("--dsn <dsn>", "dsn of the canyon server").option("--repo_id <repo_id>", "repo id of the canyon server").option("--filter <filter>", "仅合并路径包含该子串的文件覆盖率").option("--instrument_cwd <instrument_cwd>", "instrument cwd of the canyon server").option("--sha <sha>", "sha of the canyon server").option("--branch <branch>", "branch of the canyon server").option("--provider <provider>", "provider of the canyon server").option("--build_target <build_target>", "build target of the canyon server").option("--coverage <coverage>", "coverage of the canyon server").option("--scene <key=value>", "scene key-value pair, can be used multiple times, e.g. --scene env=prod --scene type=e2e", (value, previous = [])=>{
147
159
  previous.push(value);
148
160
  return previous;
149
- }, []).allowExcessArguments(false).allowUnknownOption(false).description('modify react native project code to adapt to canyon').addHelpText('after', `\nFor help, head on to ${accent('https://github.com/canyon-project/canyon')}`).action(async (params, options)=>await mapCommand(params, options));
161
+ }, []).allowExcessArguments(false).allowUnknownOption(false).description("modify react native project code to adapt to canyon").addHelpText("after", `\nFor help, head on to ${accent("https://github.com/canyon-project/canyon")}`).action(async (params, options)=>await mapCommand(params, options));
150
162
  const cli = async (args)=>{
151
163
  try {
152
164
  await program.parseAsync(args);
package/package.json CHANGED
@@ -1,31 +1,31 @@
1
1
  {
2
2
  "name": "@canyonjs/cli",
3
- "version": "1.0.31",
3
+ "version": "1.0.33",
4
+ "bin": {
5
+ "canyon": "bin/canyon.js"
6
+ },
7
+ "files": [
8
+ "dist",
9
+ "bin"
10
+ ],
4
11
  "type": "module",
12
+ "types": "./dist/index.d.ts",
5
13
  "exports": {
6
14
  ".": {
7
15
  "types": "./dist/index.d.ts",
8
16
  "import": "./dist/index.js"
9
17
  }
10
18
  },
11
- "types": "./dist/index.d.ts",
12
- "files": [
13
- "dist",
14
- "bin"
15
- ],
16
- "bin": {
17
- "canyon": "bin/canyon.js"
19
+ "dependencies": {
20
+ "axios": "^1.12.2",
21
+ "chalk": "^5.6.2",
22
+ "commander": "^14.0.1"
18
23
  },
19
24
  "devDependencies": {
20
25
  "@rslib/core": "^0.15.1",
21
26
  "@rstest/core": "^0.5.1",
22
27
  "@types/node": "^24.10.1",
23
- "@typescript/native-preview": "7.0.0-dev.20260126.1"
24
- },
25
- "dependencies": {
26
- "axios": "^1.12.2",
27
- "chalk": "^5.6.2",
28
- "commander": "^14.0.1"
28
+ "@typescript/native-preview": "7.0.0-dev.20260223.1"
29
29
  },
30
30
  "scripts": {
31
31
  "build": "rslib build",