@mnci/cli 4.12.0 → 4.12.2

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/README.md CHANGED
@@ -1457,7 +1457,10 @@ extension:
1457
1457
  `engines.vscode` pinned to the installed `@types/vscode` (`vsce` refuses types
1458
1458
  newer than the engine range), `main: ./dist/main.js`, empty `activationEvents`
1459
1459
  (VS Code activates on a contributed command by itself since 1.74) and one sample
1460
- command. Tagged `type:vscode-extension`.
1460
+ command. Tagged `type:vscode-extension`, and `nx.name` pins the Nx project name
1461
+ to the folder, so `name` (the Marketplace id is `<publisher>.<name>`) and
1462
+ `displayName` are yours to change: packages stay `<project>[-<target>].vsix`
1463
+ and every script, task and launch entry keeps working.
1461
1464
  - **`src/main.ts`**, not `extension.ts`: the slice rules allow only `index` and
1462
1465
  `main` at the root of `src`.
1463
1466
  - **Unit tests run against a stub of `vscode`**, `test/vscode.stub.ts`, mapped by
package/dist/cli.js CHANGED
@@ -2331,6 +2331,7 @@ const VERSION_TAG = /<Version>([^<]*)<\\/Version>/
2331
2331
  */
2332
2332
  function findCsproj (tree, root) {
2333
2333
  const name = tree.children(root).find((entry) => entry.endsWith('.csproj'))
2334
+
2334
2335
  return name ? posix.join(root, name) : null
2335
2336
  }
2336
2337
 
@@ -3815,6 +3816,9 @@ var VSCODE_SIDECAR_TARGETS = {
3815
3816
  "darwin-x64": "darwin-amd64",
3816
3817
  "darwin-arm64": "darwin-arm64"
3817
3818
  };
3819
+ function scriptObjectLiteral(map) {
3820
+ return `{ ${Object.entries(map).map(([key, value]) => `'${key}': '${value}'`).join(", ")} }`;
3821
+ }
3818
3822
  var VSCODE_EXTENSION_SCRIPT = String.raw`#!/usr/bin/env node
3819
3823
  // Written by mnci: 'mnci add vscode-extension' creates it and 'mnci upgrade'
3820
3824
  // rewrites it, so local edits do not survive an upgrade.
@@ -3822,15 +3826,15 @@ var VSCODE_EXTENSION_SCRIPT = String.raw`#!/usr/bin/env node
3822
3826
  // Packages and publishes a VS Code extension project. Its Nx targets call it:
3823
3827
  // node tools/vscode-extension.cjs package apps/<name> [--sidecar <go-app>]
3824
3828
  // node tools/vscode-extension.cjs publish apps/<name> [--sidecar <go-app>]
3825
- // Without --sidecar: one universal dist/drop/<name>.vsix.
3826
- // With --sidecar: one dist/drop/<name>-<target>.vsix per Marketplace target, each
3829
+ // Without --sidecar: one universal dist/drop/<project>.vsix.
3830
+ // With --sidecar: one dist/drop/<project>-<target>.vsix per Marketplace target, each
3827
3831
  // carrying that platform's binary from the Go app's build-all in bin/.
3828
3832
  'use strict'
3829
3833
  const { spawnSync } = require('node:child_process')
3830
3834
  const { cpSync, existsSync, mkdirSync, readFileSync, rmSync } = require('node:fs')
3831
- const { dirname, join, resolve } = require('node:path')
3835
+ const { basename, dirname, join, resolve } = require('node:path')
3832
3836
 
3833
- const TARGETS = ${JSON.stringify(VSCODE_SIDECAR_TARGETS)}
3837
+ const TARGETS = ${scriptObjectLiteral(VSCODE_SIDECAR_TARGETS)}
3834
3838
  const DROP = resolve('dist/drop')
3835
3839
  const VSCE_FLAGS = ['--no-dependencies', '--skip-license', '--allow-missing-repository']
3836
3840
 
@@ -3861,7 +3865,7 @@ function vsixFiles (name, sidecar) {
3861
3865
  function packageExtension (projectRoot, manifest, sidecar) {
3862
3866
  mkdirSync(DROP, { recursive: true })
3863
3867
  if (!sidecar) {
3864
- run('@vscode/vsce', 'vsce', ['package', ...VSCE_FLAGS, '--out', vsixFiles(manifest.name)[0]], { cwd: projectRoot })
3868
+ run('@vscode/vsce', 'vsce', ['package', ...VSCE_FLAGS, '--out', vsixFiles(project)[0]], { cwd: projectRoot })
3865
3869
 
3866
3870
  return
3867
3871
  }
@@ -3873,7 +3877,7 @@ function packageExtension (projectRoot, manifest, sidecar) {
3873
3877
  if (!existsSync(source)) fail('No ' + platform + ' build of ' + sidecar + ' at ' + source + ' - its build-all target did not write one.')
3874
3878
  rmSync(staging, { recursive: true, force: true })
3875
3879
  cpSync(source, staging, { recursive: true })
3876
- run('@vscode/vsce', 'vsce', ['package', '--target', target, ...VSCE_FLAGS, '--out', join(DROP, manifest.name + '-' + target + '.vsix')], { cwd: projectRoot })
3880
+ run('@vscode/vsce', 'vsce', ['package', '--target', target, ...VSCE_FLAGS, '--out', join(DROP, project + '-' + target + '.vsix')], { cwd: projectRoot })
3877
3881
  }
3878
3882
  } finally {
3879
3883
  rmSync(staging, { recursive: true, force: true })
@@ -3882,7 +3886,7 @@ function packageExtension (projectRoot, manifest, sidecar) {
3882
3886
 
3883
3887
  function publishExtension (manifest, sidecar, dryRun) {
3884
3888
  if (dryRun) {
3885
- console.log('Dry run - would publish ' + vsixFiles(manifest.name, sidecar).join(', ') + ' to the Marketplace.')
3889
+ console.log('Dry run - would publish ' + vsixFiles(project, sidecar).join(', ') + ' to the Marketplace.')
3886
3890
 
3887
3891
  return
3888
3892
  }
@@ -3892,7 +3896,7 @@ function publishExtension (manifest, sidecar, dryRun) {
3892
3896
 
3893
3897
  return
3894
3898
  }
3895
- const files = vsixFiles(manifest.name, sidecar)
3899
+ const files = vsixFiles(project, sidecar)
3896
3900
  const missing = files.filter(file => !existsSync(file))
3897
3901
  if (missing.length > 0) fail('Nothing to publish: ' + missing.join(', ') + ' not found - run the package target first.')
3898
3902
  run('@vscode/vsce', 'vsce', ['publish', '--packagePath', ...files, '--skip-duplicate'])
@@ -3903,9 +3907,12 @@ const sidecarIndex = rest.indexOf('--sidecar')
3903
3907
  const sidecar = sidecarIndex === -1 ? undefined : rest[sidecarIndex + 1]
3904
3908
  if (!projectRoot || !existsSync(join(projectRoot, 'package.json'))) fail('Usage: node tools/vscode-extension.cjs package|publish <project root> [--sidecar <go-app>]')
3905
3909
  const manifest = JSON.parse(readFileSync(join(projectRoot, 'package.json'), 'utf8'))
3910
+ // Packages are named after the project folder, never the manifest name, which is
3911
+ // free to change (the Marketplace id need not match the folder).
3912
+ const project = basename(resolve(projectRoot))
3906
3913
  // nx release --dry-run hands the publish target --dryRun=true and sets NX_DRY_RUN
3907
3914
  // (measured on Nx 23), so a dry run never reaches the Marketplace, token or not.
3908
- const dryRun = rest.some(argument => /^--dry-?run(=true)?$/i.test(argument)) || process.env.NX_DRY_RUN === 'true'
3915
+ const dryRun = rest.some(argument => /^--dry-?run(?:=true)?$/i.test(argument)) || process.env.NX_DRY_RUN === 'true'
3909
3916
  if (command === 'package') packageExtension(projectRoot, manifest, sidecar)
3910
3917
  else if (command === 'publish') publishExtension(manifest, sidecar, dryRun)
3911
3918
  else fail('Unknown command ' + command + ' - expected package or publish.')
@@ -4036,7 +4043,7 @@ function reshapeManifest(projectRoot, name, publisher, typesVersion) {
4036
4043
  main: "./dist/main.js",
4037
4044
  activationEvents: [],
4038
4045
  contributes: { commands: [{ command: `${name}.hello`, title: `${name}: Hello` }] },
4039
- nx: { ...nx, tags: [.../* @__PURE__ */ new Set([...nx.tags ?? [], VSCODE_EXTENSION_TAG])], targets }
4046
+ nx: { ...nx, name, tags: [.../* @__PURE__ */ new Set([...nx.tags ?? [], VSCODE_EXTENSION_TAG])], targets }
4040
4047
  })
4041
4048
  );
4042
4049
  }
@@ -4128,6 +4135,29 @@ function refreshVscodeExtensionScript(workspaceRoot) {
4128
4135
  writeFileEnsured(path, VSCODE_EXTENSION_SCRIPT);
4129
4136
  return true;
4130
4137
  }
4138
+ function pinVscodeExtensionProjectNames(workspaceRoot) {
4139
+ const apps = (0, import_node_path15.join)(workspaceRoot, "apps");
4140
+ let entries;
4141
+ try {
4142
+ entries = (0, import_node_fs11.readdirSync)(apps);
4143
+ } catch {
4144
+ return [];
4145
+ }
4146
+ const updated = [];
4147
+ for (const entry of entries) {
4148
+ const manifestPath = (0, import_node_path15.join)(apps, entry, "package.json");
4149
+ if (!fileExists(manifestPath)) {
4150
+ continue;
4151
+ }
4152
+ const manifest = readJson(manifestPath);
4153
+ if (!manifest.nx?.tags?.includes(VSCODE_EXTENSION_TAG) || manifest.nx.name !== void 0 || manifest.name === void 0) {
4154
+ continue;
4155
+ }
4156
+ writeFileEnsured(manifestPath, toJson({ ...manifest, nx: { ...manifest.nx, name: manifest.name } }));
4157
+ updated.push(`apps/${entry}/package.json`);
4158
+ }
4159
+ return updated;
4160
+ }
4131
4161
  function addVscodeExtension(workspaceRoot, name, stack, options = {}) {
4132
4162
  const { sidecar } = options;
4133
4163
  if (sidecar !== void 0 && !fileExists((0, import_node_path15.join)(workspaceRoot, "apps", sidecar, "project.json"))) {
@@ -6105,6 +6135,13 @@ function runUpgrade(workspaceRoot, options) {
6105
6135
  logger.detail(`updated ${path}`);
6106
6136
  }
6107
6137
  }
6138
+ const pinnedExtensions = pinVscodeExtensionProjectNames(workspaceRoot);
6139
+ if (pinnedExtensions.length > 0) {
6140
+ logger.step("Pinning the Nx project name of VS Code extensions (nx.name)");
6141
+ for (const path of pinnedExtensions) {
6142
+ logger.detail(`updated ${path}`);
6143
+ }
6144
+ }
6108
6145
  if (refreshVscodeExtensionScript(workspaceRoot)) {
6109
6146
  logger.step("Updating the VS Code extension packaging script");
6110
6147
  logger.detail(`updated ${VSCODE_EXTENSION_SCRIPT_PATH}`);