arcadible 1.0.40-next.3 → 1.0.40

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,44 +1,93 @@
1
- // the packed pages that load the SDK's 1.5 hosted script,
2
- // /arcadible/sdk/v1.js, which stays as it was released for the builds
3
- // released with it: a fact each page's markup says, read as a browser reads
4
- // it, each `script` element's `src` by its path. A script a page adds by
5
- // code isn't seen, on purpose: that would be a guess.
1
+ // the packed pages that load a script under /arcadible/, the folder every
2
+ // build's origin keeps for Arcadible's own files, that isn't the SDK's
3
+ // hosted script: a fact each page's markup says, read as a browser reads it,
4
+ // each `script` element's `src` by the path it resolves to. A script a page
5
+ // adds by code isn't seen, on purpose: that would be a guess.
6
6
  // [import]
7
7
  import { WARNING } from "../../config/code.js";
8
- import { sdkScriptOld } from "../../phrase/index.js";
9
- import { attrsOf, childrenOf, parseDocument, tagOf, } from "../../util/tree.js";
8
+ import { handle } from "../../config/product.js";
9
+ import { ARCADIBLE_SDK_SCRIPT } from "../../config/uri.js";
10
+ import { sdkScriptPath } from "../../phrase/index.js";
11
+ import { attrsOf, childrenOf, isElement, parseDocument, tagOf, } from "../../util/tree.js";
10
12
  // [declare]
11
- // the SDK's 1.5 script, and the current SDK's.
12
- const OLD = "/arcadible/sdk/v1.js";
13
- const NOW = "/arcadible/lib/sdk.v1.js";
13
+ // the folder Arcadible keeps, in any letter case, as Arcadible serves it.
14
+ const RESERVED = handle;
15
+ // an origin a page is read as served from: only the path of what a `src`
16
+ // resolves to is compared, and only on the game's own origin.
17
+ const ORIGIN = "https://game.invalid";
14
18
  // how much is read, so a package of any size is checked quickly: the most
15
19
  // pages, and the most of one. Past them a page isn't read, so a warning can
16
20
  // be missed, never made up.
17
21
  const MAX_PAGES = 200;
18
22
  const MAX_PAGE = 1024 * 1024;
19
23
  // [function]
20
- // whether a script's `src` names the old script: its path, without its
21
- // query or fragment, ending in `/arcadible/sdk/v1.js` exactly, from the
22
- // root or from the page.
23
- function isOld(src) {
24
- const path = src.trim().split(/[?#]/u)[0] ?? "";
25
- return `/${path}`.endsWith(OLD);
26
- }
27
- // [function]
28
- // whether a document loads the old script: any `script` element's `src`,
29
- // in the head or the body. A template's content and a comment aren't
30
- // elements of the page, so they're never read.
31
- function loads(node) {
32
- if (tagOf(node) === "script" && "attrs" in node) {
33
- const src = attrsOf(node).find((attr) => attr.name === "src");
34
- if (src && isOld(src.value)) {
35
- return true;
36
- }
24
+ // the page's own URL, from its name in the package.
25
+ function urlOf(name) {
26
+ try {
27
+ const url = new URL(ORIGIN);
28
+ url.pathname = `/${name}`;
29
+ return url;
30
+ }
31
+ catch {
32
+ return null;
37
33
  }
38
- return childrenOf(node).some(loads);
39
34
  }
40
35
  // [function]
41
- // each packed page that loads the old script, by its name in the package.
36
+ // `href` resolved against `base`, or null when it isn't a URL.
37
+ function urlFrom(href, base) {
38
+ try {
39
+ return new URL(href.trim(), base);
40
+ }
41
+ catch {
42
+ return null;
43
+ }
44
+ }
45
+ // [function]
46
+ // the path `src` names on the game's origin, resolved against `base` as a
47
+ // browser resolves it, so `../arcadible/x.js` from `levels/two.html` is
48
+ // `/arcadible/x.js`; null for another origin, or one that isn't a URL.
49
+ function pathOf(src, base) {
50
+ const url = urlFrom(src, base);
51
+ return url?.origin === ORIGIN ? url.pathname : null;
52
+ }
53
+ // [function]
54
+ // whether `path` is under the reserved folder and isn't the SDK's script.
55
+ function isWrong(path) {
56
+ const [, first, ...rest] = path.split("/");
57
+ return (first?.toLowerCase() === RESERVED &&
58
+ rest.length > 0 &&
59
+ path !== ARCADIBLE_SDK_SCRIPT);
60
+ }
61
+ // [function]
62
+ // every element of `tag` in the document, in order. A template's content and
63
+ // a comment aren't elements of the page, so they're never read.
64
+ function elementsOf(node, tag) {
65
+ const own = isElement(node) && tagOf(node) === tag ? [node] : [];
66
+ return [...own, ...childrenOf(node).flatMap((n) => elementsOf(n, tag))];
67
+ }
68
+ // [function]
69
+ // an element's attribute, or undefined.
70
+ function attrOf(node, name) {
71
+ return attrsOf(node).find((attr) => attr.name === name)?.value;
72
+ }
73
+ // [function]
74
+ // the paths under /arcadible/ the document's scripts load that aren't the
75
+ // SDK's, each once: any `script` element's `src`, in the head or the body,
76
+ // resolved against the page, or its first `<base href>`, as a browser does.
77
+ function wrongPaths(document, page) {
78
+ const href = elementsOf(document, "base")
79
+ .map((node) => attrOf(node, "href"))
80
+ .find((value) => value !== undefined);
81
+ const base = href === undefined ? page : (urlFrom(href, page) ?? page);
82
+ const paths = elementsOf(document, "script")
83
+ .map((node) => attrOf(node, "src"))
84
+ .flatMap((src) => (src === undefined ? [] : [pathOf(src, base)]))
85
+ .filter((path) => path !== null && isWrong(path));
86
+ return [...new Set(paths)];
87
+ }
88
+ // [function]
89
+ // each packed page's scripts under /arcadible/ that aren't the SDK's, by the
90
+ // page's name in the package and the path it loads.
42
91
  export function hosted(zip) {
43
92
  const pages = zip
44
93
  .entries()
@@ -46,13 +95,13 @@ export function hosted(zip) {
46
95
  .slice(0, MAX_PAGES);
47
96
  return pages.flatMap((page) => {
48
97
  const html = zip.read(page.name)?.toString("utf8");
49
- return html !== undefined && loads(parseDocument(html))
50
- ? [
51
- {
52
- code: WARNING.SDK_SCRIPT_OLD,
53
- message: sdkScriptOld(page.name, OLD, NOW),
54
- },
55
- ]
56
- : [];
98
+ const url = urlOf(page.name);
99
+ if (html === undefined || url === null) {
100
+ return [];
101
+ }
102
+ return wrongPaths(parseDocument(html), url).map((path) => ({
103
+ code: WARNING.SDK_SCRIPT_PATH,
104
+ message: sdkScriptPath(page.name, path, ARCADIBLE_SDK_SCRIPT),
105
+ }));
57
106
  });
58
107
  }
@@ -64,5 +64,5 @@ export default defineCommand({
64
64
  hs(nothingToDo());
65
65
  }
66
66
  },
67
- summary: "Run the project's build",
67
+ summary: "Run the project's build and bundle its function",
68
68
  });
package/dist/commands.js CHANGED
@@ -30,7 +30,7 @@ export const COMMANDS = [
30
30
  {
31
31
  load: () => import("./command/build.js"),
32
32
  name: "build",
33
- summary: "Run the project's build",
33
+ summary: "Run the project's build and bundle its function",
34
34
  },
35
35
  {
36
36
  load: () => import("./command/pack.js"),
@@ -127,7 +127,7 @@ export const WARNING = {
127
127
  PACKAGE_FILE_DEV: "package_file_dev",
128
128
  PACKAGE_FILE_PRIVATE: "package_file_private",
129
129
  SCREENSHOT_NAME_INVALID: "screenshot_name_invalid",
130
- SDK_SCRIPT_OLD: "sdk_script_old",
130
+ SDK_SCRIPT_PATH: "sdk_script_path",
131
131
  VERSION_UNCHECKED: "version_unchecked",
132
132
  };
133
133
  // every error code, for checking one exists.
@@ -9,6 +9,10 @@ const PROTOCOL = protocol;
9
9
  // 1.5's at /arcadible/sdk/. The play
10
10
  // page's host comes from the play site, HOST_HTTP_PLAY.
11
11
  export const ARCADIBLE_SDK = `https://sdk.${handle}.io`;
12
+ // the SDK's hosted script, on every game's origin, the one a page loads:
13
+ // the only script under /arcadible/ a game should name (arc pack's
14
+ // sdk_script_path).
15
+ export const ARCADIBLE_SDK_SCRIPT = `/${handle}/lib/sdk.v1.js`;
12
16
  export const HOST_APP_PLAY = `${PROTOCOL}://play`;
13
17
  export const HOST_APP_STORE = `${PROTOCOL}://store`;
14
18
  export const HOST_HTTP_ACCOUNT = `https://account.${DOMAIN}`;
@@ -11,8 +11,8 @@ export function packageFileDev(dir) {
11
11
  return `Packing ${dir}, a project's installed packages.\nSet deploy_dir to the folder your build writes.`;
12
12
  }
13
13
  // [function]
14
- export function sdkScriptOld(page, old, now) {
15
- return `${page} loads ${old}, which gets no new calls.\nLoad ${now} instead, for the current SDK.`;
14
+ export function sdkScriptPath(page, path, sdk) {
15
+ return `${page} loads ${path}; the Arcadible SDK's script is ${sdk}.`;
16
16
  }
17
17
  // [function]
18
18
  export function packageFilePrivate(file) {
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "license": "Apache-2.0",
44
44
  "name": "arcadible",
45
- "version": "1.0.40-next.3"
45
+ "version": "1.0.40"
46
46
  },
47
47
  "node_modules/@cacheable/memory": {
48
48
  "dependencies": {
@@ -2433,5 +2433,5 @@
2433
2433
  }
2434
2434
  },
2435
2435
  "requires": true,
2436
- "version": "1.0.40-next.3"
2436
+ "version": "1.0.40"
2437
2437
  }
package/package.json CHANGED
@@ -66,5 +66,5 @@
66
66
  "test": "tsc && npm run lint && node --test \"test/**/*.test.js\" \"test/**/*.test.mjs\""
67
67
  },
68
68
  "type": "module",
69
- "version": "1.0.40-next.3"
69
+ "version": "1.0.40"
70
70
  }