libdragon 11.2.0 → 11.3.0

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.
@@ -1,5 +1,9 @@
1
+ /// <reference path="../../globals.d.ts" />
2
+
1
3
  const fs = require('fs/promises');
4
+ const _fs = require('fs');
2
5
  const path = require('path');
6
+ const sea = require('node:sea');
3
7
 
4
8
  const chalk = require('chalk').stderr;
5
9
 
@@ -20,7 +24,6 @@ const {
20
24
  } = require('../constants');
21
25
  const {
22
26
  log,
23
- copyDirContents,
24
27
  CommandError,
25
28
  ParameterError,
26
29
  ValidationError,
@@ -29,6 +32,21 @@ const {
29
32
  getImageName,
30
33
  } = require('../helpers');
31
34
 
35
+ // TODO: use https://nodejs.org/api/single-executable-applications.html#seagetassetkey-encoding &&
36
+ // https://nodejs.org/api/single-executable-applications.html#assets instead
37
+ const main_c = sea.isSea()
38
+ ? // @ts-ignore-next-line
39
+ /** @type {string} */ (require('../../skeleton/src/main.c'))
40
+ : _fs.readFileSync(path.join(__dirname, '../../skeleton/src/main.c'), 'utf8');
41
+
42
+ const makefile = sea.isSea()
43
+ ? // @ts-ignore-next-line
44
+ /** @type {string} */ require('../../skeleton/Makefile.mk')
45
+ : _fs.readFileSync(
46
+ path.join(__dirname, '../../skeleton/Makefile.mk'),
47
+ 'utf8'
48
+ );
49
+
32
50
  /**
33
51
  * @param {import('../project-info').LibdragonInfo} info
34
52
  * @returns {Promise<"submodule" | "subtree" | undefined>}
@@ -205,6 +223,47 @@ const autoVendor = async (info) => {
205
223
  return info;
206
224
  };
207
225
 
226
+ /**
227
+ * @param {import('../project-info').LibdragonInfo} info
228
+ */
229
+ async function copyFiles(info) {
230
+ // TODO: make use of VFS, this is far from ideal
231
+ const srcPath = path.join(info.root, 'src');
232
+
233
+ const srcStat = await fs.stat(srcPath).catch((e) => {
234
+ if (e.code !== 'ENOENT') throw e;
235
+ return null;
236
+ });
237
+
238
+ if (srcStat && !srcStat.isDirectory()) {
239
+ log(`${srcPath} is not a directory, skipping.`);
240
+ return;
241
+ }
242
+
243
+ if (!srcStat) {
244
+ log(`Creating a directory at ${srcPath}.`, true);
245
+ await fs.mkdir(srcPath);
246
+ }
247
+
248
+ const makefilePath = path.join(info.root, 'Makefile');
249
+ await fs
250
+ .writeFile(makefilePath, makefile, {
251
+ flag: 'wx',
252
+ })
253
+ .catch(() => {
254
+ log(`${makefilePath} already exists, skipping.`);
255
+ });
256
+
257
+ const mainPath = path.join(info.root, 'src', 'main.c');
258
+ await fs
259
+ .writeFile(mainPath, main_c, {
260
+ flag: 'wx',
261
+ })
262
+ .catch(() => {
263
+ log(`${mainPath} already exists, skipping.`);
264
+ });
265
+ }
266
+
208
267
  /**
209
268
  * Initialize a new libdragon project in current working directory
210
269
  * Also downloads the image
@@ -313,13 +372,8 @@ async function init(info) {
313
372
  info = await autoVendor(info);
314
373
 
315
374
  log(`Preparing project files...`);
316
- const skeletonFolder = path.join(__dirname, '../../skeleton');
317
375
 
318
- await Promise.all([
319
- installDependencies(info),
320
- // node copy functions does not work with pkg
321
- copyDirContents(skeletonFolder, info.root),
322
- ]);
376
+ await Promise.all([installDependencies(info), copyFiles(info)]);
323
377
 
324
378
  log(chalk.green(`libdragon ready at \`${info.root}\`.`));
325
379
  return info;
@@ -1,6 +1,5 @@
1
1
  const path = require('path');
2
2
  const fs = require('fs/promises');
3
- const fsClassic = require('fs');
4
3
  const chalk = require('chalk').stderr;
5
4
  const { spawn } = require('child_process');
6
5
 
@@ -121,7 +120,7 @@ async function dirExists(path) {
121
120
  * inheritStdout?: boolean,
122
121
  * inheritStderr?: boolean,
123
122
  * spawnOptions?: import('child_process').SpawnOptions,
124
- * stdin?: fsClassic.ReadStream,
123
+ * stdin?: import('fs').ReadStream,
125
124
  * }} SpawnOptions
126
125
  */
127
126
 
@@ -351,60 +350,6 @@ const dockerExec = /** @type {DockerExec} */ (
351
350
  }
352
351
  );
353
352
 
354
- /**
355
- * Recursively copies directories and files
356
- * @param {string} src
357
- * @param {string} dst
358
- */
359
- async function copyDirContents(src, dst) {
360
- log(`Copying from ${src} to ${dst}`, true);
361
-
362
- const dstStat = await fs.stat(dst).catch((e) => {
363
- if (e.code !== 'ENOENT') throw e;
364
- return null;
365
- });
366
-
367
- if (dstStat && !dstStat.isDirectory()) {
368
- log(`${dst} is not a directory, skipping.`);
369
- return;
370
- }
371
-
372
- if (!dstStat) {
373
- log(`Creating a directory at ${dst}.`, true);
374
- await fs.mkdir(dst);
375
- }
376
-
377
- const files = await fs.readdir(src);
378
- return Promise.all(
379
- files.map(async (name) => {
380
- const source = path.join(src, name);
381
- const dest = path.join(dst, name);
382
- // promise version does not work on snapshot filesystem
383
- // Also see https://github.com/vercel/pkg/issues/1561
384
- const stats = await new Promise((res, rej) =>
385
- fsClassic.stat(source, (err, stats) => {
386
- if (err) return rej(err);
387
- res(stats);
388
- })
389
- );
390
- if (stats.isDirectory()) {
391
- await copyDirContents(source, dest);
392
- } else if (stats.isFile()) {
393
- const content = await fs.readFile(source);
394
- try {
395
- log(`Writing to ${dest}`, true);
396
- await fs.writeFile(dest, content, {
397
- flag: 'wx',
398
- });
399
- } catch {
400
- log(`${dest} already exists, skipping.`);
401
- return;
402
- }
403
- }
404
- })
405
- );
406
- }
407
-
408
353
  /**
409
354
  * @param {string} p
410
355
  */
@@ -446,8 +391,10 @@ function print(text) {
446
391
  */
447
392
  function log(text, verboseOnly = false) {
448
393
  if (!verboseOnly) {
394
+ // New default color for console.err is red
395
+ // Also see https://github.com/nodejs/node/issues/53661
449
396
  // eslint-disable-next-line no-console
450
- console.error(text);
397
+ console.error(chalk.white(text));
451
398
  return;
452
399
  }
453
400
  if (globals.verbose) {
@@ -491,7 +438,6 @@ module.exports = {
491
438
  assert,
492
439
  fileExists,
493
440
  dirExists,
494
- copyDirContents,
495
441
  CommandError,
496
442
  ParameterError,
497
443
  ValidationError,
@@ -1,6 +1,8 @@
1
1
  const path = require('path');
2
2
  const fsClassic = require('fs');
3
+ const fs = require('fs/promises');
3
4
 
5
+ // TODO: stop using lodash just for a simple uniq function
4
6
  const _ = require('lodash');
5
7
 
6
8
  const { dockerHostUserParams } = require('./docker-utils');
@@ -36,7 +38,9 @@ const installNPMDependencies = async (libdragonInfo) => {
36
38
  if (npmRoot) {
37
39
  const packageJsonPath = path.join(npmRoot, 'package.json');
38
40
 
39
- const { dependencies, devDependencies } = require(packageJsonPath);
41
+ const { dependencies, devDependencies } = JSON.parse(
42
+ await fs.readFile(packageJsonPath, { encoding: 'utf8' })
43
+ );
40
44
 
41
45
  const deps = await Promise.all(
42
46
  Object.keys({
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "libdragon",
3
- "version": "11.2.0",
3
+ "version": "11.3.0",
4
4
  "description": "This is a docker wrapper for libdragon",
5
5
  "main": "index.js",
6
6
  "engines": {
7
- "node": ">=18",
8
- "npm": ">=8"
7
+ "node": ">=22",
8
+ "npm": ">=10"
9
9
  },
10
10
  "bin": {
11
11
  "libdragon": "./index.js"
@@ -16,7 +16,7 @@
16
16
  "libdragon": "node index.js",
17
17
  "start": "node index.js start",
18
18
  "stop": "node index.js stop",
19
- "pack": "pkg ./",
19
+ "pack": "node pack.mjs",
20
20
  "format": "prettier **/*.js **/*.mjs **/*.cjs --write",
21
21
  "format-check": "prettier **/*.js **/*.mjs **/*.cjs --check",
22
22
  "lint": "eslint --fix modules/**/*.js *.js *.mjs *.cjs",
@@ -51,23 +51,19 @@
51
51
  "@types/lodash": "^4.14.182",
52
52
  "commitizen": "^4.2.4",
53
53
  "cz-conventional-changelog": "^3.3.0",
54
+ "esbuild": "^0.20.0",
54
55
  "ed64": "^2.0.4",
55
56
  "eslint": "^9.11.0",
56
57
  "jest": "^29.5.0",
57
- "pkg": "^5.5.2",
58
+ "postject": "^1.0.0-alpha.6",
58
59
  "prettier": "^2.4.0",
60
+ "ref-napi": "^3.0.3",
59
61
  "semantic-release": "^24.0.0",
60
- "typescript": "^4.7.4"
62
+ "typescript": "^4.7.4",
63
+ "zx": "^7.2.2"
61
64
  },
62
- "pkg": {
63
- "targets": [
64
- "node14-win-x64",
65
- "node14-linux-x64",
66
- "node14-macos-x64"
67
- ],
68
- "assets": [
69
- "skeleton/**"
70
- ]
65
+ "overrides": {
66
+ "minimist": "1.2.6"
71
67
  },
72
68
  "release": {
73
69
  "plugins": [
@@ -0,0 +1,4 @@
1
+ declare module './src/main.c' {
2
+ type tmp = string;
3
+ export = tmp;
4
+ }
File without changes