moonscratch 0.1.0 → 0.1.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/js/vm/bindings.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  // biome-ignore lint/suspicious/noTsIgnore: we can't use ts-expect-error because states are dynamic
2
2
  // @ts-ignore
3
- import * as moonscratch from '../../_build/js/debug/build/moonscratch.js'
3
+ import * as moonscratch from '../../_build/js/release/build/moonscratch.js'
4
4
 
5
5
  export { moonscratch }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "moonscratch",
3
3
  "type": "module",
4
4
  "module": "js/index.ts",
5
- "version": "0.1.0",
5
+ "version": "0.1.1",
6
6
  "exports": {
7
7
  ".": {
8
8
  "import": "./dist/index.mjs",
package/vite.config.ts CHANGED
@@ -1,9 +1,59 @@
1
+ import { existsSync } from 'node:fs'
2
+ import { dirname, resolve } from 'node:path'
1
3
  import { defineConfig } from 'vite-plus'
2
4
 
5
+ const RELEASE_IMPORTER_PATH = '../../_build/js/release/build/moonscratch.js'
6
+ const RELEASE_BINDING_PATH = '../../_build/js/release/build/moonscratch.js'
7
+ const DEBUG_BINDING_PATH = '../../_build/js/debug/build/moonscratch.js'
8
+ const DEBUG_BUILD_PATH = './_build/js/debug/build/moonscratch.js'
9
+
10
+ const toAbsolutePath = (
11
+ importer: string | null | undefined,
12
+ importPath: string,
13
+ ) => {
14
+ const baseDir = importer ? dirname(importer) : process.cwd()
15
+ const normalizedCandidate = importPath.replace(/^\.\.\/\.\.\//, './')
16
+ const candidates = [
17
+ resolve(baseDir, importPath),
18
+ resolve(process.cwd(), importPath),
19
+ resolve(process.cwd(), normalizedCandidate),
20
+ ]
21
+ for (const candidate of candidates) {
22
+ if (existsSync(candidate)) {
23
+ return candidate
24
+ }
25
+ }
26
+ return undefined
27
+ }
28
+
29
+ const resolveBindingPath = (importer: string | null | undefined) => {
30
+ const releasePath = toAbsolutePath(importer, RELEASE_IMPORTER_PATH)
31
+ if (releasePath) {
32
+ return releasePath
33
+ }
34
+ if (existsSync(resolve(process.cwd(), DEBUG_BUILD_PATH))) {
35
+ return resolve(process.cwd(), DEBUG_BUILD_PATH)
36
+ }
37
+ const debugPath = toAbsolutePath(importer, DEBUG_BINDING_PATH)
38
+ return debugPath
39
+ }
40
+
3
41
  export default defineConfig({
4
42
  pack: {
5
43
  entry: 'js/index.ts',
6
44
  dts: true,
45
+ inlineOnly: ['sb3-types'],
46
+ external: ['sharp', 'detect-libc', 'semver', '@img/colour'],
47
+ plugins: [
48
+ {
49
+ name: 'mbt-binding',
50
+ resolveId(id, importer) {
51
+ if (id === RELEASE_BINDING_PATH) {
52
+ return resolveBindingPath(importer)
53
+ }
54
+ },
55
+ },
56
+ ],
7
57
  },
8
58
  test: {
9
59
  include: ['./js/**/*.test.ts'],
@@ -1,2 +0,0 @@
1
-
2
- $ tsgo