@gameslate/sdk 0.3.0 → 0.3.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.
@@ -1,6 +1,7 @@
1
1
  import * as esbuild from 'esbuild';
2
2
  import { createHash } from 'node:crypto';
3
3
  import fs from 'node:fs';
4
+ import { createRequire } from 'node:module';
4
5
  import path from 'node:path';
5
6
 
6
7
  /*
@@ -16,6 +17,27 @@ const LIVE_FILE = 'live.js';
16
17
  const ASSETS_FILE = 'assets.js';
17
18
  const EXTRACT_FILE = 'extract.mjs';
18
19
 
20
+ /*
21
+ * Resolves bare imports (`@gameslate/sdk`, `earcut`) the way Node does, from the importing file's
22
+ * folder. esbuild otherwise obeys any Yarn Plug'n'Play manifest it finds in a parent directory,
23
+ * even one that has nothing to do with the plugin, and then refuses the plugin's own packages.
24
+ */
25
+ const nodeResolution = {
26
+ name: 'gameslate-node-resolution',
27
+ setup(build) {
28
+ build.onResolve({ filter: /^[^./]/ }, args => {
29
+ if (args.path.startsWith('node:') || !args.resolveDir) return undefined;
30
+ try {
31
+ const resolve = createRequire(path.join(args.resolveDir, 'noop.js')).resolve;
32
+ return { path: resolve(args.path) };
33
+ } catch {
34
+ /* not resolvable this way (an alias, or an import-only package): esbuild decides */
35
+ return undefined;
36
+ }
37
+ });
38
+ },
39
+ };
40
+
19
41
  const hashOf = file => createHash('sha256').update(fs.readFileSync(file)).digest('hex');
20
42
 
21
43
  /* a sandbox script: `entry`'s default export handed to the sdk's `expose` function */
@@ -40,6 +62,7 @@ async function buildSandboxed({ srcDir, entry, expose, outfile, alias }) {
40
62
  format: 'iife',
41
63
  target: 'es2022',
42
64
  alias,
65
+ plugins: Object.keys(alias).length ? [] : [nodeResolution],
43
66
  logLevel: 'warning',
44
67
  });
45
68
  }
@@ -54,6 +77,7 @@ async function buildNode(srcDir, entry, outfile, alias) {
54
77
  target: 'node20',
55
78
  format: 'esm',
56
79
  alias,
80
+ plugins: Object.keys(alias).length ? [] : [nodeResolution],
57
81
  banner: {
58
82
  js: [
59
83
  "import { createRequire as __gsCreateRequire } from 'node:module';",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gameslate/sdk",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Build plugins for GameSlate, the second-screen companion for PC games: the plugin contract, game-state and catalogue schemas, and the plugin builder.",
5
5
  "license": "MIT",
6
6
  "type": "module",