@neon-rs/cli 0.0.77 → 0.0.79

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.
Files changed (2) hide show
  1. package/index.js +56 -9
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -15113,7 +15113,8 @@ const mktemp = temp.track().mkdir;
15113
15113
  const pack_build_OPTIONS = [
15114
15114
  { name: 'file', alias: 'f', type: String, defaultValue: 'index.node' },
15115
15115
  { name: 'target', alias: 't', type: String, defaultValue: null },
15116
- { name: 'out-dir', alias: 'd', type: String, defaultValue: null }
15116
+ { name: 'in-dir', alias: 'i', type: String, defaultValue: null },
15117
+ { name: 'out-dir', alias: 'o', type: String, defaultValue: null }
15117
15118
  ];
15118
15119
 
15119
15120
  function isRustTarget(x) {
@@ -15136,8 +15137,9 @@ class PackBuild {
15136
15137
  static options() {
15137
15138
  return [
15138
15139
  { name: '-f, --file <addon>', summary: 'Prebuilt .node file to pack. (Default: index.node)' },
15139
- { name: '-t, --target <target>', summary: 'Rust target triple the addon was built for. (Default: rustc default host)' },
15140
- { name: '-d, --out-dir <path>', summary: 'Output directory, recursively created if needed. (Default: ./dist)' }
15140
+ { name: '-t, --target <target>', summary: 'Rust target triple the addon was built for. (Default: in-dir manifest target or else rustc default host)' },
15141
+ { name: '-i, --in-dir <path>', summary: 'Input directory with package manifest, created automatically by default. (Default: temp dir)' },
15142
+ { name: '-o, --out-dir <path>', summary: 'Output directory, recursively created if needed. (Default: ./dist)' }
15141
15143
  ];
15142
15144
  }
15143
15145
  static seeAlso() {
@@ -15149,11 +15151,13 @@ class PackBuild {
15149
15151
  }
15150
15152
  _target;
15151
15153
  _addon;
15154
+ _inDir;
15152
15155
  _outDir;
15153
15156
  constructor(argv) {
15154
15157
  const options = dist_default()(pack_build_OPTIONS, { argv });
15155
15158
  this._target = options.target || null;
15156
15159
  this._addon = options.file;
15160
+ this._inDir = options['in-dir'] || null;
15157
15161
  this._outDir = options['out-dir'] || external_node_path_namespaceObject.join(process.cwd(), 'dist');
15158
15162
  }
15159
15163
  async currentTarget() {
@@ -15167,9 +15171,7 @@ class PackBuild {
15167
15171
  }
15168
15172
  return hostLine.replace(/^host:\s+/, '');
15169
15173
  }
15170
- async run() {
15171
- await promises_namespaceObject.mkdir(this._outDir, { recursive: true });
15172
- const manifest = JSON.parse(await promises_namespaceObject.readFile('package.json', { encoding: 'utf8' }));
15174
+ async createTempDir(manifest) {
15173
15175
  const version = manifest.version;
15174
15176
  const targets = manifest.neon.targets;
15175
15177
  const target = this._target || await this.currentTarget();
@@ -15189,7 +15191,16 @@ class PackBuild {
15189
15191
  os: [targetInfo.platform],
15190
15192
  cpu: [targetInfo.arch],
15191
15193
  main: "index.node",
15192
- files: ["index.node"]
15194
+ files: ["index.node"],
15195
+ neon: {
15196
+ binary: {
15197
+ rust: target,
15198
+ node: targetInfo.node,
15199
+ platform: targetInfo.platform,
15200
+ arch: targetInfo.arch,
15201
+ abi: targetInfo.abi
15202
+ }
15203
+ }
15193
15204
  };
15194
15205
  const OPTIONAL_KEYS = [
15195
15206
  'author', 'repository', 'keywords', 'bugs', 'homepage', 'license', 'engines'
@@ -15203,9 +15214,45 @@ class PackBuild {
15203
15214
  await promises_namespaceObject.writeFile(external_node_path_namespaceObject.join(tmpdir, "package.json"), JSON.stringify(prebuildManifest, null, 2));
15204
15215
  await promises_namespaceObject.copyFile(this._addon, external_node_path_namespaceObject.join(tmpdir, "index.node"));
15205
15216
  await promises_namespaceObject.writeFile(external_node_path_namespaceObject.join(tmpdir, "README.md"), `# \`${name}\`\n\n${description}\n`);
15217
+ return tmpdir;
15218
+ }
15219
+ async prepareInDir(manifest) {
15220
+ if (!this._inDir) {
15221
+ return await this.createTempDir(manifest);
15222
+ }
15223
+ const version = manifest.version;
15224
+ const binaryManifest = JSON.parse(await promises_namespaceObject.readFile(external_node_path_namespaceObject.join(this._inDir, 'package.json'), { encoding: 'utf8' }));
15225
+ const binaryTarget = binaryManifest.neon.binary.rust || null;
15226
+ if (binaryTarget && this._target && (binaryTarget !== this._target)) {
15227
+ throw new Error(`Specified target ${this._target} does not match target ${binaryTarget} in ${this._inDir}`);
15228
+ }
15229
+ const target = binaryTarget || this._target || await this.currentTarget();
15230
+ if (!isRustTarget(target)) {
15231
+ throw new Error(`Rust target ${target} not supported.`);
15232
+ }
15233
+ const descriptor = lookup(target);
15234
+ binaryManifest.neon = binaryManifest.neon || {};
15235
+ binaryManifest.neon.binary = {
15236
+ rust: target,
15237
+ node: descriptor.node,
15238
+ platform: descriptor.platform,
15239
+ arch: descriptor.arch,
15240
+ abi: descriptor.abi
15241
+ };
15242
+ // FIXME: make it possible to disable this
15243
+ binaryManifest.version = version;
15244
+ await promises_namespaceObject.writeFile(external_node_path_namespaceObject.join(this._inDir, 'package.json'), JSON.stringify(binaryManifest, null, 2), { encoding: 'utf8' });
15245
+ // FIXME: make this path configurable
15246
+ await promises_namespaceObject.copyFile(this._addon, external_node_path_namespaceObject.join(this._inDir, "index.node"));
15247
+ return this._inDir;
15248
+ }
15249
+ async run() {
15250
+ await promises_namespaceObject.mkdir(this._outDir, { recursive: true });
15251
+ const manifest = JSON.parse(await promises_namespaceObject.readFile('package.json', { encoding: 'utf8' }));
15252
+ const inDir = await this.prepareInDir(manifest);
15206
15253
  const result = await execa("npm", ["pack", "--json"], {
15207
15254
  shell: true,
15208
- cwd: tmpdir,
15255
+ cwd: inDir,
15209
15256
  stdio: ['pipe', 'pipe', 'inherit']
15210
15257
  });
15211
15258
  if (result.exitCode !== 0) {
@@ -15216,7 +15263,7 @@ class PackBuild {
15216
15263
  const dest = external_node_path_namespaceObject.join(this._outDir, tarball);
15217
15264
  // Copy instead of move since e.g. GitHub Actions Windows runners host temp directories
15218
15265
  // on a different device (which causes fs.renameSync to fail).
15219
- await promises_namespaceObject.copyFile(external_node_path_namespaceObject.join(tmpdir, tarball), dest);
15266
+ await promises_namespaceObject.copyFile(external_node_path_namespaceObject.join(inDir, tarball), dest);
15220
15267
  console.log(dest);
15221
15268
  }
15222
15269
  ;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neon-rs/cli",
3
- "version": "0.0.77",
3
+ "version": "0.0.79",
4
4
  "description": "Command-line build tool for Neon modules.",
5
5
  "type": "module",
6
6
  "exports": "./index.js",