@mnci/cli 4.12.0 → 4.12.1

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
@@ -3822,13 +3822,13 @@ var VSCODE_EXTENSION_SCRIPT = String.raw`#!/usr/bin/env node
3822
3822
  // Packages and publishes a VS Code extension project. Its Nx targets call it:
3823
3823
  // node tools/vscode-extension.cjs package apps/<name> [--sidecar <go-app>]
3824
3824
  // 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
3825
+ // Without --sidecar: one universal dist/drop/<project>.vsix.
3826
+ // With --sidecar: one dist/drop/<project>-<target>.vsix per Marketplace target, each
3827
3827
  // carrying that platform's binary from the Go app's build-all in bin/.
3828
3828
  'use strict'
3829
3829
  const { spawnSync } = require('node:child_process')
3830
3830
  const { cpSync, existsSync, mkdirSync, readFileSync, rmSync } = require('node:fs')
3831
- const { dirname, join, resolve } = require('node:path')
3831
+ const { basename, dirname, join, resolve } = require('node:path')
3832
3832
 
3833
3833
  const TARGETS = ${JSON.stringify(VSCODE_SIDECAR_TARGETS)}
3834
3834
  const DROP = resolve('dist/drop')
@@ -3861,7 +3861,7 @@ function vsixFiles (name, sidecar) {
3861
3861
  function packageExtension (projectRoot, manifest, sidecar) {
3862
3862
  mkdirSync(DROP, { recursive: true })
3863
3863
  if (!sidecar) {
3864
- run('@vscode/vsce', 'vsce', ['package', ...VSCE_FLAGS, '--out', vsixFiles(manifest.name)[0]], { cwd: projectRoot })
3864
+ run('@vscode/vsce', 'vsce', ['package', ...VSCE_FLAGS, '--out', vsixFiles(project)[0]], { cwd: projectRoot })
3865
3865
 
3866
3866
  return
3867
3867
  }
@@ -3873,7 +3873,7 @@ function packageExtension (projectRoot, manifest, sidecar) {
3873
3873
  if (!existsSync(source)) fail('No ' + platform + ' build of ' + sidecar + ' at ' + source + ' - its build-all target did not write one.')
3874
3874
  rmSync(staging, { recursive: true, force: true })
3875
3875
  cpSync(source, staging, { recursive: true })
3876
- run('@vscode/vsce', 'vsce', ['package', '--target', target, ...VSCE_FLAGS, '--out', join(DROP, manifest.name + '-' + target + '.vsix')], { cwd: projectRoot })
3876
+ run('@vscode/vsce', 'vsce', ['package', '--target', target, ...VSCE_FLAGS, '--out', join(DROP, project + '-' + target + '.vsix')], { cwd: projectRoot })
3877
3877
  }
3878
3878
  } finally {
3879
3879
  rmSync(staging, { recursive: true, force: true })
@@ -3882,7 +3882,7 @@ function packageExtension (projectRoot, manifest, sidecar) {
3882
3882
 
3883
3883
  function publishExtension (manifest, sidecar, dryRun) {
3884
3884
  if (dryRun) {
3885
- console.log('Dry run - would publish ' + vsixFiles(manifest.name, sidecar).join(', ') + ' to the Marketplace.')
3885
+ console.log('Dry run - would publish ' + vsixFiles(project, sidecar).join(', ') + ' to the Marketplace.')
3886
3886
 
3887
3887
  return
3888
3888
  }
@@ -3892,7 +3892,7 @@ function publishExtension (manifest, sidecar, dryRun) {
3892
3892
 
3893
3893
  return
3894
3894
  }
3895
- const files = vsixFiles(manifest.name, sidecar)
3895
+ const files = vsixFiles(project, sidecar)
3896
3896
  const missing = files.filter(file => !existsSync(file))
3897
3897
  if (missing.length > 0) fail('Nothing to publish: ' + missing.join(', ') + ' not found - run the package target first.')
3898
3898
  run('@vscode/vsce', 'vsce', ['publish', '--packagePath', ...files, '--skip-duplicate'])
@@ -3903,6 +3903,9 @@ const sidecarIndex = rest.indexOf('--sidecar')
3903
3903
  const sidecar = sidecarIndex === -1 ? undefined : rest[sidecarIndex + 1]
3904
3904
  if (!projectRoot || !existsSync(join(projectRoot, 'package.json'))) fail('Usage: node tools/vscode-extension.cjs package|publish <project root> [--sidecar <go-app>]')
3905
3905
  const manifest = JSON.parse(readFileSync(join(projectRoot, 'package.json'), 'utf8'))
3906
+ // Packages are named after the project folder, never the manifest name, which is
3907
+ // free to change (the Marketplace id need not match the folder).
3908
+ const project = basename(resolve(projectRoot))
3906
3909
  // nx release --dry-run hands the publish target --dryRun=true and sets NX_DRY_RUN
3907
3910
  // (measured on Nx 23), so a dry run never reaches the Marketplace, token or not.
3908
3911
  const dryRun = rest.some(argument => /^--dry-?run(=true)?$/i.test(argument)) || process.env.NX_DRY_RUN === 'true'
@@ -4036,7 +4039,7 @@ function reshapeManifest(projectRoot, name, publisher, typesVersion) {
4036
4039
  main: "./dist/main.js",
4037
4040
  activationEvents: [],
4038
4041
  contributes: { commands: [{ command: `${name}.hello`, title: `${name}: Hello` }] },
4039
- nx: { ...nx, tags: [.../* @__PURE__ */ new Set([...nx.tags ?? [], VSCODE_EXTENSION_TAG])], targets }
4042
+ nx: { ...nx, name, tags: [.../* @__PURE__ */ new Set([...nx.tags ?? [], VSCODE_EXTENSION_TAG])], targets }
4040
4043
  })
4041
4044
  );
4042
4045
  }
@@ -4128,6 +4131,29 @@ function refreshVscodeExtensionScript(workspaceRoot) {
4128
4131
  writeFileEnsured(path, VSCODE_EXTENSION_SCRIPT);
4129
4132
  return true;
4130
4133
  }
4134
+ function pinVscodeExtensionProjectNames(workspaceRoot) {
4135
+ const apps = (0, import_node_path15.join)(workspaceRoot, "apps");
4136
+ let entries;
4137
+ try {
4138
+ entries = (0, import_node_fs11.readdirSync)(apps);
4139
+ } catch {
4140
+ return [];
4141
+ }
4142
+ const updated = [];
4143
+ for (const entry of entries) {
4144
+ const manifestPath = (0, import_node_path15.join)(apps, entry, "package.json");
4145
+ if (!fileExists(manifestPath)) {
4146
+ continue;
4147
+ }
4148
+ const manifest = readJson(manifestPath);
4149
+ if (!manifest.nx?.tags?.includes(VSCODE_EXTENSION_TAG) || manifest.nx.name !== void 0 || manifest.name === void 0) {
4150
+ continue;
4151
+ }
4152
+ writeFileEnsured(manifestPath, toJson({ ...manifest, nx: { ...manifest.nx, name: manifest.name } }));
4153
+ updated.push(`apps/${entry}/package.json`);
4154
+ }
4155
+ return updated;
4156
+ }
4131
4157
  function addVscodeExtension(workspaceRoot, name, stack, options = {}) {
4132
4158
  const { sidecar } = options;
4133
4159
  if (sidecar !== void 0 && !fileExists((0, import_node_path15.join)(workspaceRoot, "apps", sidecar, "project.json"))) {
@@ -6105,6 +6131,13 @@ function runUpgrade(workspaceRoot, options) {
6105
6131
  logger.detail(`updated ${path}`);
6106
6132
  }
6107
6133
  }
6134
+ const pinnedExtensions = pinVscodeExtensionProjectNames(workspaceRoot);
6135
+ if (pinnedExtensions.length > 0) {
6136
+ logger.step("Pinning the Nx project name of VS Code extensions (nx.name)");
6137
+ for (const path of pinnedExtensions) {
6138
+ logger.detail(`updated ${path}`);
6139
+ }
6140
+ }
6108
6141
  if (refreshVscodeExtensionScript(workspaceRoot)) {
6109
6142
  logger.step("Updating the VS Code extension packaging script");
6110
6143
  logger.detail(`updated ${VSCODE_EXTENSION_SCRIPT_PATH}`);