arcadible 1.0.40-next.3 → 1.0.41

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.
@@ -5,8 +5,8 @@ import { join, resolve as resolvePath } from "node:path";
5
5
  // [import]
6
6
  import { pathExists } from "fs-extra";
7
7
  // [import]
8
- import { BUILT, bundle } from "../../runner/bundle.js";
9
- import { BUILD_FAILED } from "../../config/code.js";
8
+ import { BUILT, bundle, misimported } from "../../runner/bundle.js";
9
+ import { BUILD_FAILED, WARNING } from "../../config/code.js";
10
10
  import { buildCommand } from "../../util/command.js";
11
11
  import { ArcError } from "../../util/error.js";
12
12
  import { detect } from "../../util/lockfile.js";
@@ -41,11 +41,22 @@ function build(command, { cwdPath, outputPath }) {
41
41
  // [function]
42
42
  // the game's function, bundled after the project's own build, which may have
43
43
  // written the code it's made from: resolves with the bundle's path, or null
44
- // for a game with none.
45
- function buildRunner(root, main) {
44
+ // for a game with none. `onWarning` hears each package the function imports
45
+ // that's meant for a game or a server of one's own (function_import_wrong).
46
+ function buildRunner(root, main, onWarning) {
46
47
  return typeof main === "string"
47
48
  ? bundle({
48
49
  main: resolvePath(root, main),
50
+ onPackages: onWarning
51
+ ? (names) => {
52
+ misimported(names).forEach((each) => {
53
+ onWarning({
54
+ code: WARNING.FUNCTION_IMPORT_WRONG,
55
+ message: phrase.functionImportWrong(each),
56
+ });
57
+ });
58
+ }
59
+ : undefined,
49
60
  outfile: resolvePath(root, BUILT),
50
61
  })
51
62
  : Promise.resolve(null);
@@ -95,13 +106,14 @@ async function explain(ex, root) {
95
106
  // [function]
96
107
  // builds the project: its own build, then its runner, when it has one. The
97
108
  // result is the build's, with `function`, the bundle's path, beside it.
98
- export async function buildTool({ project: { function: runner, workflow }, root, }) {
109
+ // `onWarning` gets each of the bundle's warnings (function_import_wrong).
110
+ export async function buildTool({ onWarning, project: { function: runner, workflow }, root, }) {
99
111
  try {
100
112
  const artifact = await build(buildCommand(workflow.build), {
101
113
  cwdPath: root,
102
114
  outputPath: resolvePath(root, workflow.deploy_dir),
103
115
  });
104
- const bundled = await buildRunner(root, runner?.main);
116
+ const bundled = await buildRunner(root, runner?.main, onWarning);
105
117
  return bundled ? { ...artifact, function: bundled } : artifact;
106
118
  }
107
119
  catch (ex) {
@@ -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
  }
@@ -2,11 +2,8 @@
2
2
  // them, so a build can ship naming one (`[function] secrets`) with no value
3
3
  // on its channel, and its function then reads nothing for it. A direct
4
4
  // deploy can say so first, since it has the login that reads the game's
5
- // secrets; `arc deploy git` has none, and never asks.
6
- //
7
- // Nothing calls this yet: what it finds is a warning, a warning has a code,
8
- // and a code has an entry on the public Errors page, which says nothing of
9
- // functions until they ship (TODO.md, Agreed next).
5
+ // secrets; `arc deploy git` has none, and never asks. `predeployTool` warns
6
+ // of each (secret_unset).
10
7
  import { auth, gameFunctionSecrets } from "../../api.js";
11
8
  import { channel } from "../../util/links.js";
12
9
  // [function]
@@ -1,6 +1,25 @@
1
1
  // [import]
2
2
  import { ensureId, ensureUnpublished } from "./ac.js";
3
+ import { WARNING } from "../../config/code.js";
3
4
  import { releasing } from "./game.js";
5
+ import { secretUnset } from "../../phrase/index.js";
6
+ import { unset } from "./secrets.js";
7
+ // [function]
8
+ // warns of each secret the project's function declares that has no value
9
+ // on the channel the version goes to (secret_unset): never a failure, since
10
+ // a value may be set after. Asked only when it declares some.
11
+ function warnUnset(current, game, declared, handler) {
12
+ return unset(current, game, declared).then(({ channel, names }) => {
13
+ for (const name of names) {
14
+ if (handler.onWarning) {
15
+ handler.onWarning({
16
+ code: WARNING.SECRET_UNSET,
17
+ message: secretUnset({ channel, name }),
18
+ });
19
+ }
20
+ }
21
+ });
22
+ }
4
23
  // [function]
5
24
  // a direct deploy needs a login. Each lookup uses its token or not, as it
6
25
  // needs, and its answer is true when it's asked.
@@ -10,5 +29,5 @@ export function predeployTool(current, conf, { onPredeployBegin, ...handler }) {
10
29
  }
11
30
  return ensureId(current, releasing(conf.project.game), handler)
12
31
  .then((game) => ensureUnpublished(current, game))
13
- .then((game) => ({ held: game.held, to: game.version }));
32
+ .then((game) => warnUnset(current, game, conf.project.function?.secrets, handler).then(() => ({ held: game.held, to: game.version })));
14
33
  }
@@ -5,7 +5,7 @@ import { checked } from "../action/validate/checked.js";
5
5
  import { WARNING } from "../config/code.js";
6
6
  import { defineCommand } from "../cli/command.js";
7
7
  import { buildOutputMissing, buildSucceeded, nothingToDo, } from "../phrase/index.js";
8
- import { hs, nlpw, result } from "../util/log.js";
8
+ import { hs, nlpw, pw, result } from "../util/log.js";
9
9
  import { CWD, JSON_OUTPUT, QUIET } from "../cli/options.js";
10
10
  import { print, warn, warning } from "../util/output.js";
11
11
  import { SpinnerWheel } from "../util/spinner.js";
@@ -37,7 +37,21 @@ export default defineCommand({
37
37
  sw = new SpinnerWheel("Building… %s");
38
38
  aborting.sw = sw;
39
39
  sw.start(json || quiet);
40
- const artifact = await buildTool({ project: parsed, root });
40
+ // the bundle's own, printed once it's built.
41
+ const bundled = [];
42
+ const artifact = await buildTool({
43
+ onWarning({ code, message }) {
44
+ bundled.push(warning(code, message));
45
+ },
46
+ project: parsed,
47
+ root,
48
+ });
49
+ warnings = [...warnings, ...bundled];
50
+ aborting.data = { warnings };
51
+ if (!json && !quiet && bundled.length) {
52
+ sw.stop(true);
53
+ bundled.forEach((each) => pw(each.message));
54
+ }
41
55
  if (json) {
42
56
  const missing = artifact?.missing
43
57
  ? [
@@ -64,5 +78,5 @@ export default defineCommand({
64
78
  hs(nothingToDo());
65
79
  }
66
80
  },
67
- summary: "Run the project's build",
81
+ summary: "Run the project's build and bundle its function",
68
82
  });
@@ -127,7 +127,13 @@ export default defineCommand({
127
127
  const held = predeployed.held ?? false;
128
128
  sw = spinner(aborting, "Building… %s");
129
129
  sw.start(git || json || quiet);
130
- const output = git ? null : await buildTool({ project: parsed, root });
130
+ const output = git
131
+ ? null
132
+ : await buildTool({
133
+ onWarning: handler({ json, pb, quiet, sw, warnings }).onWarning,
134
+ project: parsed,
135
+ root,
136
+ });
131
137
  if (output) {
132
138
  parsed = await rebuilt(root);
133
139
  }
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"),
@@ -73,6 +73,7 @@ export const RELEASE = {
73
73
  PACKAGE_PATH_INVALID: "package_path_invalid",
74
74
  RELEASE_EXPIRED: "release_expired",
75
75
  REPO_NOT_CONNECTED: "repo_not_connected",
76
+ SERVERS_CHANGED: "servers_changed",
76
77
  VERSION_EXISTS: "version_exists",
77
78
  VERSION_MISMATCH: "version_mismatch",
78
79
  ZIP_INVALID: "zip_invalid",
@@ -122,12 +123,14 @@ export const WARNING = {
122
123
  DEPLOY_DIR_NOT_BUILT: "deploy_dir_not_built",
123
124
  FIELD_UNKNOWN: "field_unknown",
124
125
  FIELD_UNSET: "field_unset",
126
+ FUNCTION_IMPORT_WRONG: "function_import_wrong",
125
127
  GAME_HANDLE_LAPSED: "game_handle_lapsed",
126
128
  GAME_HANDLE_LIMIT_REACHED: "game_handle_limit_reached",
127
129
  PACKAGE_FILE_DEV: "package_file_dev",
128
130
  PACKAGE_FILE_PRIVATE: "package_file_private",
129
131
  SCREENSHOT_NAME_INVALID: "screenshot_name_invalid",
130
- SDK_SCRIPT_OLD: "sdk_script_old",
132
+ SDK_SCRIPT_PATH: "sdk_script_path",
133
+ SECRET_UNSET: "secret_unset",
131
134
  VERSION_UNCHECKED: "version_unchecked",
132
135
  };
133
136
  // 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}`;
@@ -109,7 +109,7 @@ export function secretSet({ channel, name, }) {
109
109
  }
110
110
  // [function]
111
111
  // a secret a build declares that has no value on the channel it goes to,
112
- // which `arc deploy` warns of (not yet: action/predeploy/secrets.ts).
112
+ // which `arc deploy` warns of (action/predeploy/secrets.ts).
113
113
  export function secretUnset({ channel, name, }) {
114
114
  return `Secret ${name} has no value on ${channel}.\nSet it with \`arc unstable function secret set ${name} --${channel}\`.`;
115
115
  }
@@ -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) {
@@ -37,10 +37,7 @@ export const WRONG = {
37
37
  //
38
38
  // `onPackages`, when given, hears the `@arcadible/` packages the bundle took
39
39
  // in, by name, each once, so a build can say when a function imports one
40
- // that isn't the Function SDK (`misimported`). Nothing passes it yet: what it
41
- // finds is a warning, a warning has a code, and a code has an entry on the
42
- // public Errors page, which says nothing of functions until they ship
43
- // (TODO.md, Agreed next).
40
+ // that isn't the Function SDK (`misimported`, function_import_wrong).
44
41
  //
45
42
  // `onInputs`, when given, hears every file the bundle was made from, each a
46
43
  // full path, so `arc serve` can run the function again when any of them
@@ -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.41"
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.41"
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.41"
70
70
  }