Skip to content

Commit

Permalink
[sknpm] Add modules instead of replacing them (#294)
Browse files Browse the repository at this point in the history
The dark magic of `sknpm` replaces the line `/*--MODULES--*/` with
several lines of `import` followed by `modules = [...];`, expecting a
pre-existing `var modules = [];`.
Linters expect this line to be `const modules = [];` because the array
doesn't seem to be changed.
Fine, let's push modules instead of replacing the contents of the array,
which was brittle if we didn't start with an empty array.
  • Loading branch information
mbouaziz authored Sep 2, 2024
2 parents 6485be1 + dde8e6b commit 7bda017
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion skmd/ts/src/skmd.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Options, run, type ToWasmManager } from "#std/sk_types";

var modules: (() => Promise<ToWasmManager>)[];
const modules: (() => Promise<ToWasmManager>)[] = [];
/*--MODULES--*/

const wasmurl = new URL("./skmd.wasm", import.meta.url);
Expand Down
2 changes: 1 addition & 1 deletion sknpm/resources/sk_tests.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { run, type ModuleInit } from "./sk_types.js";

var modules: ModuleInit[];
const modules: ModuleInit[] = [];
/*--MODULES--*/

const wasmurl = new URL("./test.wasm", import.meta.url);
Expand Down
2 changes: 1 addition & 1 deletion sknpm/src/sknpm.sk
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ fun copyAndConvertImport(
};
strModules = Vector[importLine(runtime)].concat(loaderFiles.map(importLine))
.concat(moduleFiles.map(importLine))
.concat(Vector[`modules = [${modules.join(", ")}];`])
.concat(Vector[`modules.push(${modules.join(", ")});`])
.join("\n");
res = for (fi in tmplFiles) {
inner = SKStore.newObstack();
Expand Down
2 changes: 1 addition & 1 deletion skstore/ts/src/skstore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export {
cjson,
} from "./skstore_utils.js";

var modules: ModuleInit[];
const modules: ModuleInit[] = [];
/*--MODULES--*/

async function wasmUrl(): Promise<URL> {
Expand Down
2 changes: 1 addition & 1 deletion sql/ts/src/skdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type { Environment } from "#std/sk_types.js";
export { SKDBTransaction } from "./skdb_util.js";
import { getWasmUrl } from "./skdb_wasm_locator.js";

var modules: ModuleInit[];
const modules: ModuleInit[] = [];
/*--MODULES--*/

export async function createSkdb(
Expand Down
2 changes: 1 addition & 1 deletion sql/ts/src/skdb_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { onWorkerMessage } from "#std/sk_worker.js";
import type { Creator } from "#std/sk_worker.js";
import type { SKDB } from "./skdb.js";

var modules: ModuleInit[];
const modules: ModuleInit[] = [];
/*--MODULES--*/

class DbCreator implements Creator<SKDB> {
Expand Down

0 comments on commit 7bda017

Please sign in to comment.